summaryrefslogtreecommitdiff
path: root/src/emap
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-04-19 22:50:55 +0300
committerAndrei Karas <akaras@inbox.ru>2017-04-19 22:50:55 +0300
commit1e1398a0c731dab75d5ca5d7077af68cc6104769 (patch)
tree87fafbcd6a086f4586b53e1c46d680e684521779 /src/emap
parent095588880ef3c2577fc9e6a81da20479c56f5bf7 (diff)
downloadevol-hercules-1e1398a0c731dab75d5ca5d7077af68cc6104769.tar.gz
evol-hercules-1e1398a0c731dab75d5ca5d7077af68cc6104769.tar.bz2
evol-hercules-1e1398a0c731dab75d5ca5d7077af68cc6104769.tar.xz
evol-hercules-1e1398a0c731dab75d5ca5d7077af68cc6104769.zip
Add script functions for manipulate item options.
New functions: getitemoptionidbyindex getitemoptionvaluebyindex getitemoptionparambyindex setitemoptionbyindex
Diffstat (limited to 'src/emap')
-rw-r--r--src/emap/init.c4
-rw-r--r--src/emap/script_buildins.c124
-rw-r--r--src/emap/script_buildins.h4
3 files changed, 132 insertions, 0 deletions
diff --git a/src/emap/init.c b/src/emap/init.c
index 341f9dd..ee03f84 100644
--- a/src/emap/init.c
+++ b/src/emap/init.c
@@ -190,6 +190,10 @@ HPExport void plugin_init (void)
addScriptCommand("tolabel", "i", toLabel);
addScriptCommand("input", "r??", input);
addScriptCommand("slide", "ii", slide);
+ addScriptCommand("getitemoptionidbyindex", "ii", getItemOptionIdByIndex);
+ addScriptCommand("getitemoptionvaluebyindex", "ii", getItemOptionValueByIndex);
+ addScriptCommand("getitemoptionparambyindex", "ii", getItemOptionParamByIndex);
+ addScriptCommand("setitemoptionbyindex", "iii*", setItemOptionByIndex);
do_init_langs();
diff --git a/src/emap/script_buildins.c b/src/emap/script_buildins.c
index a50caf7..2e47c77 100644
--- a/src/emap/script_buildins.c
+++ b/src/emap/script_buildins.c
@@ -2267,3 +2267,127 @@ BUILDIN(slide)
unit->movepos(&sd->bl, x, y, 1, 0);
return true;
}
+
+BUILDIN(getItemOptionIdByIndex)
+{
+ getSD()
+ getInventoryIndex(2)
+
+ if (sd->status.inventory[n].nameid <= 0 || sd->status.inventory[n].amount <= 0)
+ {
+ script_pushint(st, 0);
+ return false;
+ }
+
+ const int optIndex = script_getnum(st, 3);
+ if (optIndex < 0 || optIndex >= MAX_ITEM_OPTIONS)
+ {
+ script_pushint(st, 0);
+ return false;
+ }
+
+ const int optType = sd->status.inventory[n].option[optIndex].index;
+ script_pushint(st, optType);
+
+ return true;
+}
+
+BUILDIN(getItemOptionValueByIndex)
+{
+ getSD()
+ getInventoryIndex(2)
+
+ if (sd->status.inventory[n].nameid <= 0 || sd->status.inventory[n].amount <= 0)
+ {
+ script_pushint(st, 0);
+ return false;
+ }
+
+ const int optIndex = script_getnum(st, 3);
+ if (optIndex < 0 || optIndex >= MAX_ITEM_OPTIONS)
+ {
+ script_pushint(st, 0);
+ return false;
+ }
+
+ const int optValue = sd->status.inventory[n].option[optIndex].value;
+ script_pushint(st, optValue);
+
+ return true;
+}
+
+BUILDIN(getItemOptionParamByIndex)
+{
+ getSD()
+ getInventoryIndex(2)
+
+ if (sd->status.inventory[n].nameid <= 0 || sd->status.inventory[n].amount <= 0)
+ {
+ script_pushint(st, 0);
+ return false;
+ }
+
+ const int optIndex = script_getnum(st, 3);
+ if (optIndex < 0 || optIndex >= MAX_ITEM_OPTIONS)
+ {
+ script_pushint(st, 0);
+ return false;
+ }
+
+ const int optParam = sd->status.inventory[n].option[optIndex].param;
+ script_pushint(st, optParam);
+
+ return true;
+}
+
+BUILDIN(setItemOptionByIndex)
+{
+ getSD()
+ getInventoryIndex(2)
+
+ if (sd->status.inventory[n].nameid <= 0 || sd->status.inventory[n].amount <= 0)
+ return false;
+
+ if (itemdb->isstackable2(sd->inventory_data[n]))
+ return false;
+
+ // not allow change equipped items
+ if (sd->status.inventory[n].equip != 0)
+ return false;
+
+ const int optIndex = script_getnum(st, 3);
+ if (optIndex < 0 || optIndex >= MAX_ITEM_OPTIONS)
+ {
+ ShowError("Wrong optIndex in setitemoptionbyindex\n");
+ return false;
+ }
+ int optType = 0;
+ int optValue = 0;
+ if (script_hasdata(st, 5))
+ {
+ optType = script_getnum(st, 4);
+ optValue = script_getnum(st, 5);
+ }
+ else
+ {
+ optType = sd->status.inventory[n].option[optIndex].index;
+ optValue = script_getnum(st, 4);
+ }
+
+ if (optType != 0 && itemdb->option_exists(optType) == NULL)
+ {
+ ShowError("Wrong optType in setitemoptionbyindex\n");
+ return false;
+ }
+
+ clif->delitem(sd, n, 1, DELITEM_MATERIALCHANGE);
+ logs->pick_pc(sd, LOG_TYPE_SCRIPT, -1, &sd->status.inventory[n], sd->inventory_data[n]);
+
+ sd->status.inventory[n].option[optIndex].index = optType;
+ sd->status.inventory[n].option[optIndex].value = optValue;
+
+ clif->additem(sd, n, 1, 0);
+ logs->pick_pc(sd, LOG_TYPE_SCRIPT, 1, &sd->status.inventory[n], sd->inventory_data[n]);
+
+ return true;
+}
diff --git a/src/emap/script_buildins.h b/src/emap/script_buildins.h
index 7291709..96c9bf2 100644
--- a/src/emap/script_buildins.h
+++ b/src/emap/script_buildins.h
@@ -92,5 +92,9 @@ BUILDIN(getLabel);
BUILDIN(toLabel);
BUILDIN(input);
BUILDIN(slide);
+BUILDIN(getItemOptionIdByIndex);
+BUILDIN(getItemOptionValueByIndex);
+BUILDIN(getItemOptionParamByIndex);
+BUILDIN(setItemOptionByIndex);
#endif // EVOL_MAP_SCRIPT_BUILDINS