Skip to content

Commit

Permalink
Add *setfavoriteitemidx & *autofavoriteitem script command.
Browse files Browse the repository at this point in the history
- set an item as favorite item or not based inventory
index.
- if an item is set to favorite item, it will be moved into favorite
tab, else move out from favorite tab.
- only non-equipped item can adjust the favorite item state.
  • Loading branch information
Emistry committed Jun 2, 2019
1 parent e7d0f06 commit d20cbae
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 1 deletion.
24 changes: 24 additions & 0 deletions doc/script_commands.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3192,6 +3192,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
Expand Down
3 changes: 2 additions & 1 deletion src/map/itemdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions src/map/pc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
45 changes: 45 additions & 0 deletions src/map/script.c
Original file line number Diff line number Diff line change
Expand Up @@ -24681,6 +24681,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(_)
{
Expand Down Expand Up @@ -26059,6 +26102,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
Expand Down

0 comments on commit d20cbae

Please sign in to comment.