summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2019-07-01 01:46:51 +0200
committerGitHub <noreply@github.com>2019-07-01 01:46:51 +0200
commit3fe9300612136c75678f55fd699f2f0b75899e11 (patch)
tree660dbb77e3a9255abef686c6e0aec7f04eb49964
parent33b0658e174fdd50e513daa807a8824f959ded44 (diff)
parentb20054a678fc5a2786819e879f085e5dcf02c052 (diff)
downloadhercules-3fe9300612136c75678f55fd699f2f0b75899e11.tar.gz
hercules-3fe9300612136c75678f55fd699f2f0b75899e11.tar.bz2
hercules-3fe9300612136c75678f55fd699f2f0b75899e11.tar.xz
hercules-3fe9300612136c75678f55fd699f2f0b75899e11.zip
Merge pull request #2487 from guilherme-gm/201906-1-identify
Add identify/identifyidx script commands and identifyall atcommand
-rw-r--r--doc/atcommands.txt6
-rw-r--r--doc/script_commands.txt18
-rw-r--r--src/map/atcommand.c28
-rw-r--r--src/map/script.c72
4 files changed, 116 insertions, 8 deletions
diff --git a/doc/atcommands.txt b/doc/atcommands.txt
index 4acc30ae6..c909440a7 100644
--- a/doc/atcommands.txt
+++ b/doc/atcommands.txt
@@ -584,6 +584,12 @@ Opens the Identification window if any unappraised items are in your inventory.
---------------------------------------
+@identifyall
+
+Identifies all unappraised items in your inventory.
+
+---------------------------------------
+
@trade <player name>
Opens the trade window with the specified player.
diff --git a/doc/script_commands.txt b/doc/script_commands.txt
index 5cc3ea186..567d0ad56 100644
--- a/doc/script_commands.txt
+++ b/doc/script_commands.txt
@@ -3369,6 +3369,24 @@ This will set a Hat Effect onto the player. The state field allows you to
enable (true) or disable (false) the effect on the player.
---------------------------------------
+
+*identify(<Item ID>)
+
+This function identifies the first <Item ID> item in attached player's inventory.
+
+Returns -2 if an error happens, -1 if no unidentified <Item ID> was found.
+Otherwise, returns the idx of the identified item.
+
+---------------------------------------
+
+*identifyidx(<Inventory Index>)
+
+This will identify item at attached player's <Inventory Index> inventory index.
+
+Returns true if the item was identified, false otherwise.
+Note: If the item was already identified, it returns false.
+
+---------------------------------------
//=====================================
2.1 - End of Item-Related Commands
//=====================================
diff --git a/src/map/atcommand.c b/src/map/atcommand.c
index 3c454011f..a2db15f6c 100644
--- a/src/map/atcommand.c
+++ b/src/map/atcommand.c
@@ -6769,23 +6769,34 @@ ACMD(refreshall)
}
/*==========================================
- * @identify
+ * @identify / @identifyall
* => GM's magnifier.
*------------------------------------------*/
ACMD(identify)
{
int num = 0;
+ bool identifyall = (strcmpi(info->command, "identifyall") == 0);
- for (int i = 0; i < sd->status.inventorySize; i++) {
- if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].identify!=1){
- num++;
+ if (!identifyall) {
+ for (int i = 0; i < sd->status.inventorySize; i++) {
+ if (sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].identify != 1) {
+ num++;
+ }
}
- }
- if (num > 0) {
- clif->item_identify_list(sd);
} else {
- clif->message(fd,msg_fd(fd,1238)); // There are no items to appraise.
+ for (int i = 0; i < sd->status.inventorySize; i++) {
+ if (sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].identify != 1) {
+ skill->identify(sd, i);
+ num++;
+ }
+ }
}
+
+ if (num == 0)
+ clif->message(fd,msg_fd(fd,1238)); // There are no items to appraise.
+ else if (!identifyall)
+ clif->item_identify_list(sd);
+
return true;
}
@@ -10061,6 +10072,7 @@ static void atcommand_basecommands(void)
ACMD_DEF(refresh),
ACMD_DEF(refreshall),
ACMD_DEF(identify),
+ ACMD_DEF2("identifyall", identify),
ACMD_DEF(misceffect),
ACMD_DEF(mobsearch),
ACMD_DEF(cleanmap),
diff --git a/src/map/script.c b/src/map/script.c
index 35217a4d7..c1e210d27 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -25516,6 +25516,75 @@ static BUILDIN(openrefineryui)
}
/**
+ * identify(<item id>)
+ * Identifies the first unidentified <item id> item on player's inventory.
+ * Returns -2 on error, -1 if no item to identify was found, identified idx otherwise.
+ */
+static BUILDIN(identify)
+{
+ struct map_session_data *sd = script_rid2sd(st);
+
+ if (sd == NULL) {
+ script_pushint(st, -2);
+ return true;
+ }
+
+ int itemid = script_getnum(st, 2);
+ if (itemdb->exists(itemid) == NULL) {
+ ShowError("buildin_identify: Invalid item ID (%d)\n", itemid);
+ script_pushint(st, -2);
+ return true;
+ }
+
+ int idx = -1;
+ ARR_FIND(0, sd->status.inventorySize, idx, (sd->status.inventory[idx].nameid == itemid && sd->status.inventory[idx].identify == 0));
+
+ if (idx < 0 || idx >= sd->status.inventorySize) {
+ script_pushint(st, -1);
+ return true;
+ }
+
+ sd->status.inventory[idx].identify = 1;
+ clif->item_identified(sd, idx, 0);
+ script_pushint(st, idx);
+
+ return true;
+}
+
+/**
+ * identifyidx(idx)
+ * Identifies item at idx.
+ * Returns true if item is identified, false otherwise.
+ */
+static BUILDIN(identifyidx)
+{
+ struct map_session_data *sd = script_rid2sd(st);
+
+ if (sd == NULL) {
+ script_pushint(st, false);
+ return true;
+ }
+
+ int idx = script_getnum(st, 2);
+ if (idx < 0 || idx >= sd->status.inventorySize) {
+ ShowError("buildin_identifyidx: Invalid inventory index (%d), expected a value between 0 and %d\n", idx, sd->status.inventorySize);
+ script_pushint(st, false);
+ return true;
+ }
+
+ if (sd->status.inventory[idx].nameid <= 0 || sd->status.inventory[idx].identify != 0) {
+ script_pushint(st, false);
+ return true;
+ }
+
+ sd->status.inventory[idx].identify = 1;
+ clif->item_identified(sd, idx, 0);
+ script_pushint(st, true);
+
+ return true;
+}
+
+/**
* Adds a built-in script function.
*
* @param buildin Script function data
@@ -26275,6 +26344,9 @@ static void script_parse_builtin(void)
BUILDIN_DEF(openrefineryui, ""),
BUILDIN_DEF(setfavoriteitemidx, "ii"),
BUILDIN_DEF(autofavoriteitem, "ii"),
+
+ BUILDIN_DEF(identify, "i"),
+ BUILDIN_DEF(identifyidx, "i"),
};
int i, len = ARRAYLENGTH(BUILDIN);
RECREATE(script->buildin, char *, script->buildin_count + len); // Pre-alloc to speed up