diff options
author | gumi <git@gumi.ca> | 2020-08-14 08:55:37 -0400 |
---|---|---|
committer | gumi <git@gumi.ca> | 2020-08-14 08:55:37 -0400 |
commit | ad236eedb24396e5620f9c28a264126979532200 (patch) | |
tree | ddb5016ba8e19d62502ef5fde8fc26d51a1d620f | |
parent | 0f3d3493e5442728b42a27b89150c7aaa5c7e884 (diff) | |
download | evol-hercules-ad236eedb24396e5620f9c28a264126979532200.tar.gz evol-hercules-ad236eedb24396e5620f9c28a264126979532200.tar.bz2 evol-hercules-ad236eedb24396e5620f9c28a264126979532200.tar.xz evol-hercules-ad236eedb24396e5620f9c28a264126979532200.zip |
add a script command to get craft recipe ingredients
-rw-r--r-- | src/emap/init.c | 1 | ||||
-rw-r--r-- | src/emap/script_buildins.c | 89 | ||||
-rw-r--r-- | src/emap/script_buildins.h | 1 |
3 files changed, 79 insertions, 12 deletions
diff --git a/src/emap/init.c b/src/emap/init.c index 05ba6fa..19eaea5 100644 --- a/src/emap/init.c +++ b/src/emap/init.c @@ -146,6 +146,7 @@ HPExport void plugin_init (void) addScriptCommand("getcraftslotid", "ii", getCraftSlotId); addScriptCommand("getcraftslotamount", "ii", getCraftSlotAmount); addScriptCommand("validatecraft", "i", validateCraft); + addScriptCommand("getcraftrecipe", "iirr", getCraftRecipe); addScriptCommand("getq", "i", getq); addScriptCommand("getq1", "i", getq); addScriptCommand("getq2", "i", getq2); diff --git a/src/emap/script_buildins.c b/src/emap/script_buildins.c index 86cf32f..3e7227f 100644 --- a/src/emap/script_buildins.c +++ b/src/emap/script_buildins.c @@ -24,6 +24,7 @@ #include "emap/clif.h" #include "emap/craft.h" +#include "emap/craftconf.h" #include "emap/lang.h" #include "emap/map.h" #include "emap/hashtable.h" @@ -1727,6 +1728,70 @@ BUILDIN(findCraftEntry) return true; } +BUILDIN(getCraftRecipe) +{ + // arg 0: recipe id + // arg 1: inventory id + // arg 2: qty array + // arg 3: item array + // returns size + + struct script_data *data4 = script_getdata(st, 4); + struct script_data *data5 = script_getdata(st, 5); + + if (!data_isreference(data4) || reference_toconstant(data4) + || !data_isreference(data5) || reference_toconstant(data5)) { + ShowError("script:getcraftrecipe: 3rd and 4th arguments must be variables\n"); + st->state = END; + return false; + } + + int recipe_id = script_getnum(st, 2); + struct craft_db_entry *entry = idb_get(craftconf_db, recipe_id); + + if (!entry) { + // recipe does not exist + script_pushint(st, -1); + return true; + } + + int inventory_id = script_getnum(st, 3); + int inv_count = VECTOR_LENGTH(entry->inventories); + + if (inventory_id >= inv_count) { + // inventory does not exist + script_pushint(st, -2); + return true; + } + + struct craft_db_inventory *entry_inventory = &VECTOR_INDEX(entry->inventories, inventory_id); + + int32 id4 = reference_getid(data4); + uint32 start4 = reference_getindex(data4); + const char *name4 = reference_getname(data4); + struct reg_db *ref4 = reference_getref(data4); + int32 id5 = reference_getid(data5); + uint32 start5 = reference_getindex(data5); + const char *name5 = reference_getname(data5); + struct reg_db *ref5 = reference_getref(data5); + + size_t size = 0; + + for (int i = 0; i < craft_inventory_size; i++) { + struct item_pair *entryItem = &entry_inventory->items[i]; + + int index4 = start4 + size; + int index5 = start5 + size; + + script->set_reg(st, NULL, reference_uid(id4, index4), name4, (const void *)h64BPTRSIZE(entryItem->amount), ref4); + script->set_reg(st, NULL, reference_uid(id5, index5), name5, (const void *)h64BPTRSIZE(entryItem->index), ref5); + size++; + } + + script_pushint(st, size); + return true; +} + BUILDIN(useCraft) { getSD() @@ -1805,9 +1870,9 @@ BUILDIN(getInvIndexLink) } /*========================================== - * Shows an emoticon on top of the player/npc - * emotion emotion#, <target: 0 - NPC, 1 - PC>, <NPC/PC name> - *------------------------------------------*/ +* Shows an emoticon on top of the player/npc +* emotion emotion#, <target: 0 - NPC, 1 - PC>, <NPC/PC name> +*------------------------------------------*/ //Optional second parameter added by [Skotlex] BUILDIN(emotion) { @@ -2376,15 +2441,15 @@ BUILDIN(getNpcSubtype) } /*========================================== - * return the battle stats of a structure - * Supported values are most of UDT_* ones - * Not all values are supported; Only those without - * another assessor are (eg. MaxHP vs UDT_MAXHP) - * - * From 1 onwards: Str, Agi, Vit, Int, Dex, Luck - * From 7 onwards: AtkMin, AtkMax, Def, MDef, Hit, Flee - * From 13 onwards: MAtkMin, MatkMax - *------------------------------------------*/ +* return the battle stats of a structure +* Supported values are most of UDT_* ones +* Not all values are supported; Only those without +* another assessor are (eg. MaxHP vs UDT_MAXHP) +* +* From 1 onwards: Str, Agi, Vit, Int, Dex, Luck +* From 7 onwards: AtkMin, AtkMax, Def, MDef, Hit, Flee +* From 13 onwards: MAtkMin, MatkMax +*------------------------------------------*/ BUILDIN(readBattleParam) { struct map_session_data *sd; diff --git a/src/emap/script_buildins.h b/src/emap/script_buildins.h index 01c6b65..5a653d7 100644 --- a/src/emap/script_buildins.h +++ b/src/emap/script_buildins.h @@ -104,5 +104,6 @@ BUILDIN(InstanceOwner); BUILDIN(aggravate); BUILDIN(getNpcSubtype); BUILDIN(kick); +BUILDIN(getCraftRecipe); #endif // EVOL_MAP_SCRIPT_BUILDINS |