diff options
Diffstat (limited to 'src/emap')
-rw-r--r-- | src/emap/data/itemd.h | 2 | ||||
-rw-r--r-- | src/emap/init.c | 1 | ||||
-rw-r--r-- | src/emap/pc.c | 37 | ||||
-rw-r--r-- | src/emap/pc.h | 2 |
4 files changed, 40 insertions, 2 deletions
diff --git a/src/emap/data/itemd.h b/src/emap/data/itemd.h index d3c529b..6fef034 100644 --- a/src/emap/data/itemd.h +++ b/src/emap/data/itemd.h @@ -4,8 +4,6 @@ #ifndef EVOL_MAP_ITEMD #define EVOL_MAP_ITEMD -struct ItemdExt; - struct ItemdExt *itemd_get_by_item(struct item *item); struct ItemdExt *itemd_get(struct item_data *item); struct ItemdExt *itemd_create(void); diff --git a/src/emap/init.c b/src/emap/init.c index f4c60b1..255eeb4 100644 --- a/src/emap/init.c +++ b/src/emap/init.c @@ -181,6 +181,7 @@ HPExport void plugin_init (void) addHookPost("pc->unequipitem", epc_unequipitem_post); addHookPost("pc->setnewpc", epc_setnewpc); addHookPost("pc->delitem", epc_delitem_post); + addHookPost("pc->can_insert_card_into", epc_can_insert_card_into_post); langScriptId = script->add_str("Lang"); } diff --git a/src/emap/pc.c b/src/emap/pc.c index 15742c2..db78d6a 100644 --- a/src/emap/pc.c +++ b/src/emap/pc.c @@ -419,3 +419,40 @@ int epc_delitem_post(int retVal, calcPc = false; return retVal; } + +bool epc_can_insert_card_into_post(bool retVal, struct map_session_data* sd, + int *idx_card, int *idx_equip) +{ + if (retVal) + { + struct ItemdExt *data = itemd_get(sd->inventory_data[*idx_equip]); + if (!data || !data->allowedCards[0].id) // allow cards if AllowedCards list is empty + return retVal; + + const int newCardId = sd->status.inventory[*idx_card].nameid; + int cardAmountLimit = 0; + + for (int f = 0; f < 100 && data->allowedCards[f].id; f ++) + { + if (data->allowedCards[f].id == newCardId) + { + cardAmountLimit = data->allowedCards[f].amount; + break; + } + } + if (!cardAmountLimit) + return retVal; + + int cardsAmount = 0; + const int slots = sd->inventory_data[*idx_equip]->slot; + for (int f = 0; f < slots; f ++) + { + const int cardId = sd->status.inventory[*idx_equip].card[f]; + if (cardId == newCardId) + cardsAmount ++; + } + return cardAmountLimit > cardsAmount; + } + return retVal; +} + diff --git a/src/emap/pc.h b/src/emap/pc.h index 7250de6..bce3187 100644 --- a/src/emap/pc.h +++ b/src/emap/pc.h @@ -50,5 +50,7 @@ int epc_delitem_pre(struct map_session_data *sd, int *nPtr, int *amountPtr, int epc_delitem_post(int retVal, struct map_session_data *sd, int *nPtr, int *amountPtr, int *typePtr, short *reasonPtr, e_log_pick_type *log_type); +bool epc_can_insert_card_into_post(bool retVal, struct map_session_data* sd, + int *idx_card, int *idx_equip); #endif // EVOL_MAP_PC |