/*==========================================
* Player request leaving a given guild_id
*----------------------------------------*/
int guild_leave(struct map_session_data* sd, int guild_id, int account_id, int char_id, const char* mes)
{
struct guild *g;
int i, j=0;
int list[MAX_INVENTORY];
nullpo_ret(sd);
g = sd->guild;
if(g==NULL)
return 0;
if(sd->status.account_id!=account_id ||
sd->status.char_id!=char_id || sd->status.guild_id!=guild_id ||
((agit_flag || agit2_flag) && map[sd->bl.m].flag.gvg_castle))
return 0;
//Guild bound item check
for(i=0;i<MAX_INVENTORY;i++){
if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].amount > 0 && sd->status.inventory[i].bound == 2) {
list[j] = i;
j++;
}
}
if(j) {
struct guild_storage* stor = guild2storage(sd->status.guild_id);
for(i=0;i<j;i++) {
guild_storage_additem(sd,stor,&sd->status.inventory[list[i]],sd->status.inventory[list[i]].amount);
pc_delitem(sd,list[i],sd->status.inventory[list[i]].amount,0,4,LOG_TYPE_GSTORAGE);
}
storage_guild_storageclose(sd);
}
intif_guild_leave(sd->status.guild_id, sd->status.account_id, sd->status.char_id,0,mes);
return 0;
}