summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2019-06-30 21:03:47 +0200
committerGitHub <noreply@github.com>2019-06-30 21:03:47 +0200
commit60cbf12662c9cb481c6b93cec8778e93fa8f8d3d (patch)
tree9b75e97b6cb788959a9d4bc2c237ac8409d9e705
parent238cfaa6b6496da1a8569ad0a6f50d2c722c7d54 (diff)
parentd20cbae7763546555c4c9c8aa53266c40b31a2b1 (diff)
downloadhercules-60cbf12662c9cb481c6b93cec8778e93fa8f8d3d.tar.gz
hercules-60cbf12662c9cb481c6b93cec8778e93fa8f8d3d.tar.bz2
hercules-60cbf12662c9cb481c6b93cec8778e93fa8f8d3d.tar.xz
hercules-60cbf12662c9cb481c6b93cec8778e93fa8f8d3d.zip
Merge pull request #2427 from Emistry/scriptcommand_setfavoriteitem
Add *setfavoriteitemidx & *autofavoriteitem script commands - alter item favorite state
-rw-r--r--doc/script_commands.txt24
-rw-r--r--src/map/itemdb.h3
-rw-r--r--src/map/pc.c7
-rw-r--r--src/map/script.c45
4 files changed, 78 insertions, 1 deletions
diff --git a/doc/script_commands.txt b/doc/script_commands.txt
index a08d8a71c..5cc3ea186 100644
--- a/doc/script_commands.txt
+++ b/doc/script_commands.txt
@@ -3207,6 +3207,30 @@ runs of getcartinventorylist().
---------------------------------------
+*setfavoriteitemidx(<idx>, <flag>)
+
+This function will set an item in inventory as favorite or not.
+If its favorite item, it will be moved to favorite tab, else move out from favorite tab.
+Note: Cant change favorite flag of an equipped item.
+
+Valid Parameters:
+ <idx> - inventory index, refer *getinventorylist()
+ <flag> - true/false (true = favorite item, false = otherwise)
+
+---------------------------------------
+
+*autofavoriteitem(<item_id>, <flag>)
+
+This function will auto set an item as favorite when <item_id> is obtained.
+If its favorite item, it will be auto moved to favorite tab, else move out from favorite tab.
+This setting affect not only attached player, but also everyone player globally.
+
+Valid Parameters:
+ <item_id> - item ID
+ <flag> - true/false (true = favorite item, false = otherwise)
+
+---------------------------------------
+
*cardscnt()
This function will return the number of cards inserted into the weapon
diff --git a/src/map/itemdb.h b/src/map/itemdb.h
index e032def0c..f66abe066 100644
--- a/src/map/itemdb.h
+++ b/src/map/itemdb.h
@@ -521,7 +521,8 @@ struct item_data {
unsigned no_refine : 1; // [celest]
unsigned delay_consume : 1; ///< Signifies items that are not consumed immediately upon double-click [Skotlex]
unsigned trade_restriction : 9; ///< Item trade restrictions mask (@see enum ItemTradeRestrictions)
- unsigned autoequip: 1;
+ unsigned autoequip : 1;
+ unsigned auto_favorite : 1;
unsigned buyingstore : 1;
unsigned bindonequip : 1;
unsigned keepafteruse : 1;
diff --git a/src/map/pc.c b/src/map/pc.c
index 5416fbec2..fb023b2a4 100644
--- a/src/map/pc.c
+++ b/src/map/pc.c
@@ -4778,6 +4778,13 @@ static int pc_additem(struct map_session_data *sd, const struct item *item_data,
sd->weight += w;
clif->updatestatus(sd,SP_WEIGHT);
+
+ // auto-favorite
+ if (data->flag.auto_favorite > 0) {
+ sd->status.inventory[i].favorite = 1;
+ clif->favorite_item(sd, i);
+ }
+
//Auto-equip
if(data->flag.autoequip)
pc->equipitem(sd, i, data->equip);
diff --git a/src/map/script.c b/src/map/script.c
index c6f1c9a12..35217a4d7 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -24848,6 +24848,49 @@ static BUILDIN(consolemes)
return true;
}
+static BUILDIN(setfavoriteitemidx)
+{
+ struct map_session_data *sd = script_rid2sd(st);
+ int idx = script_getnum(st, 2);
+ int value = script_getnum(st, 3);
+
+ if (sd == NULL) {
+ ShowError("buildin_setfavoriteitemidx: No player attached.\n");
+ return false;
+ }
+
+ if (idx < 0 || idx >= sd->status.inventorySize) {
+ ShowError("buildin_setfavoriteitemidx: Invalid inventory index %d (min: %d, max: %d).\n", idx, 0, (sd->status.inventorySize - 1));
+ return false;
+ } else if (sd->inventory_data[idx] == NULL || sd->inventory_data[idx]->nameid <= 0) {
+ ShowWarning("buildin_setfavoriteitemidx: Current inventory index %d has no data.\n", idx);
+ return false;
+ } else if (sd->status.inventory[idx].equip > 0) {
+ ShowWarning("buildin_setfavoriteitemidx: Cant change favorite flag of an equipped item.\n");
+ return false;
+ } else {
+ sd->status.inventory[idx].favorite = cap_value(value, 0, 1);
+ clif->favorite_item(sd, idx);
+ }
+
+ return true;
+}
+
+static BUILDIN(autofavoriteitem)
+{
+ int nameid = script_getnum(st, 2);
+ int flag = script_getnum(st, 3);
+ struct item_data *item_data;
+
+ if ((item_data = itemdb->exists(nameid)) == NULL) {
+ ShowError("buildin_autofavoriteitem: Invalid item '%d'.\n", nameid);
+ return false;
+ }
+
+ item_data->flag.auto_favorite = cap_value(flag, 0, 1);
+ return true;
+}
+
/** place holder for the translation macro **/
static BUILDIN(_)
{
@@ -26230,6 +26273,8 @@ static void script_parse_builtin(void)
BUILDIN_DEF(closeroulette, ""),
BUILDIN_DEF(openrefineryui, ""),
+ BUILDIN_DEF(setfavoriteitemidx, "ii"),
+ BUILDIN_DEF(autofavoriteitem, "ii"),
};
int i, len = ARRAYLENGTH(BUILDIN);
RECREATE(script->buildin, char *, script->buildin_count + len); // Pre-alloc to speed up