diff options
author | Andrei Karas <akaras@inbox.ru> | 2016-01-12 19:09:32 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2016-01-12 19:09:32 +0300 |
commit | 3c03c2587d97513a95de0f31c6d7970cbe3b99b3 (patch) | |
tree | d6ca57656cfd49df93a35245accf05f6ea7b08df /src/emap/craft.c | |
parent | 4e441e9826be68d8329fd54e4b5e7878f511d91a (diff) | |
download | evol-hercules-3c03c2587d97513a95de0f31c6d7970cbe3b99b3.tar.gz evol-hercules-3c03c2587d97513a95de0f31c6d7970cbe3b99b3.tar.bz2 evol-hercules-3c03c2587d97513a95de0f31c6d7970cbe3b99b3.tar.xz evol-hercules-3c03c2587d97513a95de0f31c6d7970cbe3b99b3.zip |
Add script command for validate craft object after some time it was created.
New script command: validatecraft id
Diffstat (limited to 'src/emap/craft.c')
-rw-r--r-- | src/emap/craft.c | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/src/emap/craft.c b/src/emap/craft.c index 331d415..5e0abe3 100644 --- a/src/emap/craft.c +++ b/src/emap/craft.c @@ -189,7 +189,8 @@ struct craft_vardata *craft_str_to_craft(const char *craftstr) index = atoi(itemstr); amount = 1; } - if (index < 0 || index >= MAX_INVENTORY) + if (index < 0 || + index >= MAX_INVENTORY) { // wrong item index strutil_free(slotdata); strutil_free(craftdata); @@ -300,3 +301,51 @@ struct craft_slot *craft_get_slot(const int id, const int slot) } return &craft->slots[slot]; } + +bool craft_validate(TBL_PC *sd, const int id) +{ + struct craft_vardata *craft = idb_get(craftvar_db, id); + if (!craft) + { + ShowError("Craft object with id %d not exists.\n", id); + return false; + } + int amounts[MAX_INVENTORY]; + int f; + + for (f = 0; f < MAX_INVENTORY; f ++) + amounts[f] = 0; + + int index; + for (index = 0; index < craft_inventory_size; index ++) + { + struct craft_slot *crslot = &craft->slots[index]; + const int len = VECTOR_LENGTH(crslot->items); + int slot; + for (slot = 0; slot < len; slot ++) + { + struct item_pair *pair = &VECTOR_INDEX(crslot->items, slot); + const int invIndex = pair->index; + if (invIndex < 0 || + invIndex >= MAX_INVENTORY || + !sd->status.inventory[invIndex].nameid || + !sd->status.inventory[invIndex].amount) + { + return false; + } + amounts[invIndex] += pair->amount; + } + } + for (f = 0; f < MAX_INVENTORY; f ++) + { + const int amount = amounts[f]; + if (!amount) + continue; + if(sd->status.inventory[f].nameid == 0 || + sd->status.inventory[f].amount < amount) + { + return false; + } + } + return true; +} |