diff options
-rw-r--r-- | src/map/clif.c | 56 | ||||
-rw-r--r-- | src/map/pc.c | 98 | ||||
-rw-r--r-- | src/map/pc.h | 2 | ||||
-rw-r--r-- | src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc | 8 | ||||
-rw-r--r-- | src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc | 2 | ||||
-rw-r--r-- | src/plugins/HPMHooking/HPMHooking_map.Hooks.inc | 54 |
6 files changed, 150 insertions, 70 deletions
diff --git a/src/map/clif.c b/src/map/clif.c index 5617c318b..cc517c24f 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -5715,54 +5715,30 @@ void clif_solved_charname(int fd, int charid, const char* name) /// 017b <packet len>.W { <name id>.W }* void clif_use_card(struct map_session_data *sd,int idx) { - int i,c,ep; - int fd=sd->fd; + int i, c; + int fd; nullpo_retv(sd); - if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets. + fd = sd->fd; + if (sd->state.trading != 0) + return; + if (!pc->can_insert_card(sd, idx)) return; - if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD) - return; //Avoid parsing invalid item indexes (no card/no item) - - ep=sd->inventory_data[idx]->equip; - WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4); - WFIFOW(fd,0)=0x17b; - - for(i=c=0;i<MAX_INVENTORY;i++){ - int j; - - if(sd->inventory_data[i] == NULL) - continue; - if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR) - continue; - if(itemdb_isspecial(sd->status.inventory[i].card[0])) //Can't slot it - continue; - - if (sd->status.inventory[i].identify == 0) //Not identified - continue; - - if ((sd->inventory_data[i]->equip&ep) == 0) //Not equippable on this part. - continue; - - if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_SHIELD) //Shield card won't go on left weapon. - continue; - - ARR_FIND( 0, sd->inventory_data[i]->slot, j, sd->status.inventory[i].card[j] == 0 ); - if (j == sd->inventory_data[i]->slot) // No room - continue; + WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4); + WFIFOW(fd, 0) = 0x17b; - if( sd->status.inventory[i].equip > 0 ) // Do not check items that are already equipped + for (i = c = 0; i < MAX_INVENTORY; i++) { + if (!pc->can_insert_card_into(sd, idx, i)) continue; - - WFIFOW(fd,4+c*2)=i+2; + WFIFOW(fd, 4 + c * 2) = i + 2; c++; } - if( !c ) return; // no item is available for card insertion + if (!c) return; // no item is available for card insertion - WFIFOW(fd,2)=4+c*2; - WFIFOSET(fd,WFIFOW(fd,2)); + WFIFOW(fd, 2) = 4 + c * 2; + WFIFOSET(fd, WFIFOW(fd, 2)); } @@ -11394,8 +11370,6 @@ void clif_parse_AutoSpell(int fd,struct map_session_data *sd) /// 017a <card index>.W void clif_parse_UseCard(int fd,struct map_session_data *sd) { - if (sd->state.trading != 0) - return; clif->use_card(sd,RFIFOW(fd,2)-2); } @@ -11404,8 +11378,6 @@ void clif_parse_UseCard(int fd,struct map_session_data *sd) /// 017c <card index>.W <equip index>.W void clif_parse_InsertCard(int fd,struct map_session_data *sd) { - if (sd->state.trading != 0) - return; pc->insert_card(sd,RFIFOW(fd,2)-2,RFIFOW(fd,4)-2); } diff --git a/src/map/pc.c b/src/map/pc.c index 4dac559e2..b9ef479dc 100644 --- a/src/map/pc.c +++ b/src/map/pc.c @@ -4059,42 +4059,78 @@ int pc_skill(TBL_PC* sd, int id, int level, int flag) } return 1; } + +/** + * Checks if the given card can be inserted into the given equipment piece. + * + * @param sd The current character. + * @param idx_card The card's inventory index (note: it must be a valid index and can be checked by pc_can_insert_card) + * @param idx_equip The target equipment's inventory index. + * @retval true if the card can be inserted. + */ +bool pc_can_insert_card_into(struct map_session_data* sd, int idx_card, int idx_equip) +{ + int i; + + nullpo_ret(sd); + + if (idx_equip < 0 || idx_equip >= MAX_INVENTORY || sd->inventory_data[idx_equip] == NULL) + return false; //Invalid item index. + if (sd->status.inventory[idx_equip].nameid <= 0 || sd->status.inventory[idx_equip].amount < 1) + return false; // target item missing + if (sd->inventory_data[idx_equip]->type != IT_WEAPON && sd->inventory_data[idx_equip]->type != IT_ARMOR) + return false; // only weapons and armor are allowed + if (sd->status.inventory[idx_equip].identify == 0) + return false; // target must be identified + if (itemdb_isspecial(sd->status.inventory[idx_equip].card[0])) + return false; // card slots reserved for other purposes + if (sd->status.inventory[idx_equip].equip != 0) + return false; // item must be unequipped + if ((sd->inventory_data[idx_equip]->equip & sd->inventory_data[idx_card]->equip) == 0) + return false; // card cannot be compounded on this item type + if (sd->inventory_data[idx_equip]->type == IT_WEAPON && sd->inventory_data[idx_card]->equip == EQP_SHIELD) + return false; // attempted to place shield card on left-hand weapon. + + ARR_FIND( 0, sd->inventory_data[idx_equip]->slot, i, sd->status.inventory[idx_equip].card[i] == 0); + if (i == sd->inventory_data[idx_equip]->slot) + return false; // no free slots + return true; +} + +/** + * Checks if the given item is card and it can be inserted into some equipment. + * + * @param sd The current character. + * @param idx_card The card's inventory index. + * @retval true if the card can be inserted. + */ +bool pc_can_insert_card(struct map_session_data* sd, int idx_card) +{ + nullpo_ret(sd); + + if (idx_card < 0 || idx_card >= MAX_INVENTORY || sd->inventory_data[idx_card] == NULL) + return false; //Invalid card index. + if (sd->status.inventory[idx_card].nameid <= 0 || sd->status.inventory[idx_card].amount < 1) + return false; // target card missing + if (sd->inventory_data[idx_card]->type != IT_CARD) + return false; // must be a card + return true; +} + /*========================================== * Append a card to an item ? *------------------------------------------*/ int pc_insert_card(struct map_session_data* sd, int idx_card, int idx_equip) { - int i; int nameid; nullpo_ret(sd); - if( idx_equip < 0 || idx_equip >= MAX_INVENTORY || sd->inventory_data[idx_equip] == NULL ) - return 0; //Invalid item index. - if( idx_card < 0 || idx_card >= MAX_INVENTORY || sd->inventory_data[idx_card] == NULL ) - return 0; //Invalid card index. - if( sd->status.inventory[idx_equip].nameid <= 0 || sd->status.inventory[idx_equip].amount < 1 ) - return 0; // target item missing - if( sd->status.inventory[idx_card].nameid <= 0 || sd->status.inventory[idx_card].amount < 1 ) - return 0; // target card missing - if( sd->inventory_data[idx_equip]->type != IT_WEAPON && sd->inventory_data[idx_equip]->type != IT_ARMOR ) - return 0; // only weapons and armor are allowed - if( sd->inventory_data[idx_card]->type != IT_CARD ) - return 0; // must be a card - if( sd->status.inventory[idx_equip].identify == 0 ) - return 0; // target must be identified - if( itemdb_isspecial(sd->status.inventory[idx_equip].card[0]) ) - return 0; // card slots reserved for other purposes - if( (sd->inventory_data[idx_equip]->equip & sd->inventory_data[idx_card]->equip) == 0 ) - return 0; // card cannot be compounded on this item type - if( sd->inventory_data[idx_equip]->type == IT_WEAPON && sd->inventory_data[idx_card]->equip == EQP_SHIELD ) - return 0; // attempted to place shield card on left-hand weapon. - if( sd->status.inventory[idx_equip].equip != 0 ) - return 0; // item must be unequipped - - ARR_FIND( 0, sd->inventory_data[idx_equip]->slot, i, sd->status.inventory[idx_equip].card[i] == 0 ); - if( i == sd->inventory_data[idx_equip]->slot ) - return 0; // no free slots + if (sd->state.trading != 0) + return 0; + + if (!pc->can_insert_card(sd, idx_card) || !pc->can_insert_card_into(sd, idx_card, idx_equip)) + return 0; // remember the card id to insert nameid = sd->status.inventory[idx_card].nameid; @@ -4105,6 +4141,10 @@ int pc_insert_card(struct map_session_data* sd, int idx_card, int idx_equip) } else {// success + int i; + ARR_FIND( 0, sd->inventory_data[idx_equip]->slot, i, sd->status.inventory[idx_equip].card[i] == 0); + if (i == sd->inventory_data[idx_equip]->slot) + return 0; // no free slots logs->pick_pc(sd, LOG_TYPE_OTHER, -1, &sd->status.inventory[idx_equip],sd->inventory_data[idx_equip]); sd->status.inventory[idx_equip].card[i] = nameid; logs->pick_pc(sd, LOG_TYPE_OTHER, 1, &sd->status.inventory[idx_equip],sd->inventory_data[idx_equip]); @@ -11497,7 +11537,9 @@ void pc_defaults(void) { pc->skill = pc_skill; pc->insert_card = pc_insert_card; - + pc->can_insert_card = pc_can_insert_card; + pc->can_insert_card_into = pc_can_insert_card_into; + pc->steal_item = pc_steal_item; pc->steal_coin = pc_steal_coin; diff --git a/src/map/pc.h b/src/map/pc.h index 4dea27693..c370f9956 100644 --- a/src/map/pc.h +++ b/src/map/pc.h @@ -880,6 +880,8 @@ END_ZEROED_BLOCK; /* End */ int (*skill) (struct map_session_data *sd, int id, int level, int flag); int (*insert_card) (struct map_session_data *sd,int idx_card,int idx_equip); + bool (*can_insert_card) (struct map_session_data* sd, int idx_card); + bool (*can_insert_card_into) (struct map_session_data* sd, int idx_card, int idx_equip); int (*steal_item) (struct map_session_data *sd,struct block_list *bl, uint16 skill_lv); int (*steal_coin) (struct map_session_data *sd,struct block_list *bl); diff --git a/src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc b/src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc index e35a4c81c..f3e3711c1 100644 --- a/src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc +++ b/src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc @@ -3697,6 +3697,10 @@ struct { struct HPMHookPoint *HP_pc_skill_post; struct HPMHookPoint *HP_pc_insert_card_pre; struct HPMHookPoint *HP_pc_insert_card_post; + struct HPMHookPoint *HP_pc_can_insert_card_pre; + struct HPMHookPoint *HP_pc_can_insert_card_post; + struct HPMHookPoint *HP_pc_can_insert_card_into_pre; + struct HPMHookPoint *HP_pc_can_insert_card_into_post; struct HPMHookPoint *HP_pc_steal_item_pre; struct HPMHookPoint *HP_pc_steal_item_post; struct HPMHookPoint *HP_pc_steal_coin_pre; @@ -8912,6 +8916,10 @@ struct { int HP_pc_skill_post; int HP_pc_insert_card_pre; int HP_pc_insert_card_post; + int HP_pc_can_insert_card_pre; + int HP_pc_can_insert_card_post; + int HP_pc_can_insert_card_into_pre; + int HP_pc_can_insert_card_into_post; int HP_pc_steal_item_pre; int HP_pc_steal_item_post; int HP_pc_steal_coin_pre; diff --git a/src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc b/src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc index 6501c0943..4e23425ec 100644 --- a/src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc +++ b/src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc @@ -1880,6 +1880,8 @@ struct HookingPointData HookingPoints[] = { { HP_POP(pc->bonus5, HP_pc_bonus5) }, { HP_POP(pc->skill, HP_pc_skill) }, { HP_POP(pc->insert_card, HP_pc_insert_card) }, + { HP_POP(pc->can_insert_card, HP_pc_can_insert_card) }, + { HP_POP(pc->can_insert_card_into, HP_pc_can_insert_card_into) }, { HP_POP(pc->steal_item, HP_pc_steal_item) }, { HP_POP(pc->steal_coin, HP_pc_steal_coin) }, { HP_POP(pc->modifybuyvalue, HP_pc_modifybuyvalue) }, diff --git a/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc b/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc index 04f31aea5..85f477bec 100644 --- a/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc +++ b/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc @@ -49461,6 +49461,60 @@ int HP_pc_insert_card(struct map_session_data *sd, int idx_card, int idx_equip) } return retVal___; } +bool HP_pc_can_insert_card(struct map_session_data *sd, int idx_card) { + int hIndex = 0; + bool retVal___ = false; + if( HPMHooks.count.HP_pc_can_insert_card_pre ) { + bool (*preHookFunc) (struct map_session_data *sd, int *idx_card); + *HPMforce_return = false; + for(hIndex = 0; hIndex < HPMHooks.count.HP_pc_can_insert_card_pre; hIndex++ ) { + preHookFunc = HPMHooks.list.HP_pc_can_insert_card_pre[hIndex].func; + retVal___ = preHookFunc(sd, &idx_card); + } + if( *HPMforce_return ) { + *HPMforce_return = false; + return retVal___; + } + } + { + retVal___ = HPMHooks.source.pc.can_insert_card(sd, idx_card); + } + if( HPMHooks.count.HP_pc_can_insert_card_post ) { + bool (*postHookFunc) (bool retVal___, struct map_session_data *sd, int *idx_card); + for(hIndex = 0; hIndex < HPMHooks.count.HP_pc_can_insert_card_post; hIndex++ ) { + postHookFunc = HPMHooks.list.HP_pc_can_insert_card_post[hIndex].func; + retVal___ = postHookFunc(retVal___, sd, &idx_card); + } + } + return retVal___; +} +bool HP_pc_can_insert_card_into(struct map_session_data *sd, int idx_card, int idx_equip) { + int hIndex = 0; + bool retVal___ = false; + if( HPMHooks.count.HP_pc_can_insert_card_into_pre ) { + bool (*preHookFunc) (struct map_session_data *sd, int *idx_card, int *idx_equip); + *HPMforce_return = false; + for(hIndex = 0; hIndex < HPMHooks.count.HP_pc_can_insert_card_into_pre; hIndex++ ) { + preHookFunc = HPMHooks.list.HP_pc_can_insert_card_into_pre[hIndex].func; + retVal___ = preHookFunc(sd, &idx_card, &idx_equip); + } + if( *HPMforce_return ) { + *HPMforce_return = false; + return retVal___; + } + } + { + retVal___ = HPMHooks.source.pc.can_insert_card_into(sd, idx_card, idx_equip); + } + if( HPMHooks.count.HP_pc_can_insert_card_into_post ) { + bool (*postHookFunc) (bool retVal___, struct map_session_data *sd, int *idx_card, int *idx_equip); + for(hIndex = 0; hIndex < HPMHooks.count.HP_pc_can_insert_card_into_post; hIndex++ ) { + postHookFunc = HPMHooks.list.HP_pc_can_insert_card_into_post[hIndex].func; + retVal___ = postHookFunc(retVal___, sd, &idx_card, &idx_equip); + } + } + return retVal___; +} int HP_pc_steal_item(struct map_session_data *sd, struct block_list *bl, uint16 skill_lv) { int hIndex = 0; int retVal___ = 0; |