diff options
author | Andrei Karas <akaras@inbox.ru> | 2015-08-17 19:09:04 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2015-08-17 19:09:04 +0300 |
commit | 333c908061a1871a73a8562f0095bb15c3ddb740 (patch) | |
tree | 546c909b53960ca30b9512c27dd91d76bc701ed3 /src/emap/pc.c | |
parent | 45e89b39985270e12d5f8eb19c666c8fd0562661 (diff) | |
download | evol-hercules-333c908061a1871a73a8562f0095bb15c3ddb740.tar.gz evol-hercules-333c908061a1871a73a8562f0095bb15c3ddb740.tar.bz2 evol-hercules-333c908061a1871a73a8562f0095bb15c3ddb740.tar.xz evol-hercules-333c908061a1871a73a8562f0095bb15c3ddb740.zip |
Add support for card limits.
Into item db to item need add AllowCards group. In format id: amount
If AllowCards not present, all cards allowed.
Example:
AllowCards: {
id5001: 2
id5002: 1
}
Diffstat (limited to 'src/emap/pc.c')
-rw-r--r-- | src/emap/pc.c | 37 |
1 files changed, 37 insertions, 0 deletions
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; +} + |