From b9b32ac7609e33c21b488d722103cc0eea16b12c Mon Sep 17 00:00:00 2001 From: shennetsind Date: Thu, 7 Nov 2013 16:04:51 -0200 Subject: Item Bound Fixes/Adjustments/Improvements Special Thanks to Haruna Signed-off-by: shennetsind --- src/map/pc.c | 92 ++++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 61 insertions(+), 31 deletions(-) (limited to 'src/map/pc.c') diff --git a/src/map/pc.c b/src/map/pc.c index 31a38372a..752151888 100644 --- a/src/map/pc.c +++ b/src/map/pc.c @@ -573,7 +573,7 @@ bool pc_can_give_items(struct map_session_data *sd) */ bool pc_can_give_bounded_items(struct map_session_data *sd) { - return pc->has_permission(sd, PC_PERM_TRADE_BOUNDED); + return pc->has_permission(sd, PC_PERM_TRADE_BOUND); } /*========================================== @@ -999,10 +999,6 @@ int pc_isequip(struct map_session_data *sd,int n) *------------------------------------------*/ bool pc_authok(struct map_session_data *sd, int login_id2, time_t expiration_time, int group_id, struct mmo_charstatus *st, bool changing_mapservers) { int i; -#ifdef BOUND_ITEMS - int j; - int idxlist[MAX_INVENTORY]; -#endif int64 tick = timer->gettick(); uint32 ip = session[sd->fd]->client_addr; @@ -1203,12 +1199,9 @@ bool pc_authok(struct map_session_data *sd, int login_id2, time_t expiration_tim **/ pc->itemcd_do(sd,true); -#ifdef BOUND_ITEMS - // Party bound item check - if(sd->status.party_id == 0 && (j = pc->bound_chk(sd,3,idxlist))) { // Party was deleted while character offline - for(i=0;idelitem(sd,idxlist[i],sd->status.inventory[idxlist[i]].amount,0,1,LOG_TYPE_OTHER); - } +#ifdef GP_BOUND_ITEMS + if( sd->status.party_id == 0 ) + pc->bound_clear(sd,IBT_PARTY); #endif /* [Ind/Hercules] */ @@ -3962,6 +3955,28 @@ int pc_additem(struct map_session_data *sd,struct item *item_data,int amount,e_l if(sd->weight + w > sd->max_weight) return 2; + if( item_data->bound ) { + switch( (enum e_item_bound_type)item_data->bound ) { + case IBT_CHARACTER: + case IBT_ACCOUNT: + break; /* no restrictions */ + case IBT_PARTY: + if( !sd->status.party_id ) { + ShowError("pc_additem: can't add party_bound item to character without party!\n"); + ShowError("pc_additem: %s - x%d %s (%d)\n",sd->status.name,amount,data->jname,data->nameid); + return 7;/* need proper code? */ + } + break; + case IBT_GUILD: + if( !sd->status.guild_id ) { + ShowError("pc_additem: can't add guild_bound item to character without guild!\n"); + ShowError("pc_additem: %s - x%d %s (%d)\n",sd->status.name,amount,data->jname,data->nameid); + return 7;/* need proper code? */ + } + break; + } + } + i = MAX_INVENTORY; if( itemdb->isstackable2(data) && item_data->expire_time == 0 ) @@ -3969,7 +3984,7 @@ int pc_additem(struct map_session_data *sd,struct item *item_data,int amount,e_l for( i = 0; i < MAX_INVENTORY; i++ ) { if( sd->status.inventory[i].nameid == item_data->nameid && sd->status.inventory[i].bound == item_data->bound && memcmp(&sd->status.inventory[i].card, &item_data->card, sizeof(item_data->card)) == 0 ) - { + { if( amount > MAX_AMOUNT - sd->status.inventory[i].amount || ( data->stack.inventory && amount > data->stack.amount - sd->status.inventory[i].amount ) ) return 5; sd->status.inventory[i].amount += amount; @@ -4520,7 +4535,7 @@ int pc_cart_additem(struct map_session_data *sd,struct item *item_data,int amoun return 1; } - if( !itemdb_cancartstore(item_data, pc->get_group_level(sd)) || (item_data->bound > 1 && !pc->can_give_bounded_items(sd))) + if( !itemdb_cancartstore(item_data, pc->get_group_level(sd)) || (item_data->bound > IBT_ACCOUNT && !pc->can_give_bounded_items(sd))) { // Check item trade restrictions [Skotlex] clif->message (sd->fd, msg_txt(264)); return 1;/* TODO: there is no official response to this? */ @@ -4667,24 +4682,38 @@ int pc_getitemfromcart(struct map_session_data *sd,int idx,int amount) return flag; } - /*========================================== - * Bound Item Check - * Type: - * 1 Account Bound - * 2 Guild Bound - * 3 Party Bound - * 4 Character Bound - *------------------------------------------*/ -int pc_bound_chk(TBL_PC *sd,int type,int *idxlist) -{ - int i=0, j=0; - for(i=0;istatus.inventory[i].nameid > 0 && sd->status.inventory[i].amount > 0 && sd->status.inventory[i].bound == type) { - idxlist[j] = i; - j++; - } +void pc_bound_clear(struct map_session_data *sd, enum e_item_bound_type type) { + int i; + + switch( type ) { + /* both restricted to inventory */ + case IBT_PARTY: + case IBT_CHARACTER: + for( i = 0; i < MAX_INVENTORY; i++ ){ + if( sd->status.inventory[i].bound == type ) { + pc->delitem(sd,i,sd->status.inventory[i].amount,0,1,LOG_TYPE_OTHER); + } + } + break; + case IBT_ACCOUNT: + ShowError("Helllo! You reached pc_bound_clear for IBT_ACCOUNT, unfortunately no scenario was expected for this!\n"); + break; + case IBT_GUILD: { + struct guild_storage *gstor = gstorage->id2storage(sd->status.guild_id); + + for( i = 0; i < MAX_INVENTORY; i++ ){ + if(sd->status.inventory[i].bound == type) { + if( gstor ) + gstorage->additem(sd,gstor,&sd->status.inventory[i],sd->status.inventory[i].amount); + pc->delitem(sd,i,sd->status.inventory[i].amount,0,1,gstor?LOG_TYPE_GSTORAGE:LOG_TYPE_OTHER); + } + } + if( gstor ) + gstorage->close(sd); + } + break; } - return j; + } /*========================================== * Display item stolen msg to player sd @@ -10366,7 +10395,6 @@ void pc_defaults(void) { pc->class2idx = pc_class2idx; pc->get_group_level = pc_get_group_level; pc->can_give_items = pc_can_give_items; - pc->bound_chk = pc_bound_chk; pc->can_give_bounded_items = pc_can_give_bounded_items; pc->can_use_command = pc_can_use_command; @@ -10600,4 +10628,6 @@ void pc_defaults(void) { pc->rental_expire = pc_rental_expire; pc->scdata_received = pc_scdata_received; + + pc->bound_clear = pc_bound_clear; } -- cgit v1.2.3-70-g09d2