diff options
author | Haru <haru@dotalux.com> | 2020-03-09 00:24:18 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-09 00:24:18 +0100 |
commit | f80d9a72ae9e266d123d5f12ea751645691887ce (patch) | |
tree | 24277ab07dee5cb8d5403a6927f17857d6d102bf /src/map/clif.c | |
parent | 6c21a46c4f9a1773e68cbe003a805e14482493fe (diff) | |
parent | 67aae9fc205354640191de271f0201ab64e0d9fc (diff) | |
download | hercules-f80d9a72ae9e266d123d5f12ea751645691887ce.tar.gz hercules-f80d9a72ae9e266d123d5f12ea751645691887ce.tar.bz2 hercules-f80d9a72ae9e266d123d5f12ea751645691887ce.tar.xz hercules-f80d9a72ae9e266d123d5f12ea751645691887ce.zip |
Merge pull request #2642 from Kenpachi2k13/zone_disabled_items_fix
Fix (un)equip script execution for map zone restrcited items
Diffstat (limited to 'src/map/clif.c')
-rw-r--r-- | src/map/clif.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/map/clif.c b/src/map/clif.c index a8b6ea768..9fc6fae9a 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -10585,6 +10585,65 @@ static void clif_parse_LoadEndAck(int fd, struct map_session_data *sd) clif->updatestatus(sd, SP_CARTINFO); } + /** + * In official servers, an item's unequip script is executed when entering a zone where the item is restricted, + * even if the item won't be unequipped. + * + **/ + if (map->list[sd->bl.m].zone != NULL && map->list[sd->bl.m].zone->disabled_items_count != 0) { + struct map_zone_data *zone = map->list[sd->bl.m].zone; + int dis_items_cnt = zone->disabled_items_count; + int handled_equip = 0x00000000; + + for (int i = 0; i < EQI_MAX; i++) { + if (sd->equip_index[i] == INDEX_NOT_FOUND) + continue; + + int inv_idx = sd->equip_index[i]; + struct item_data *equip_data = sd->inventory_data[inv_idx]; + + if (equip_data == NULL) + continue; + + if ((handled_equip & equip_data->equip) != 0) + continue; // Equipment takes multiple slots and was already handled. + + handled_equip |= equip_data->equip; + + if (equip_data->unequip_script != NULL) { + int idx; + + ARR_FIND(0, dis_items_cnt, idx, zone->disabled_items[idx] == equip_data->nameid); + + if (idx < dis_items_cnt) + script->run_item_unequip_script(sd, equip_data, npc->fake_nd->bl.id); + } + + if (inv_idx != sd->equip_index[i]) + continue; // Unequip script execution corrupted the inventory index. + + struct item *equip = &sd->status.inventory[inv_idx]; + + if (equip != NULL && !itemdb_isspecial(equip->card[0])) { + for (int slot = 0; slot < equip_data->slot; slot++) { + if (equip->card[slot] == 0) + continue; + + struct item_data *card_data = itemdb->exists(equip->card[slot]); + + if (card_data != NULL && card_data->unequip_script != NULL) { + int idx; + + ARR_FIND(0, dis_items_cnt, idx, zone->disabled_items[idx] == card_data->nameid); + + if (idx < dis_items_cnt) + script->run_item_unequip_script(sd, card_data, npc->fake_nd->bl.id); + } + } + } + } + } + // Check for and delete unavailable/disabled items. pc->checkitem(sd); |