Forráskód Böngészése

Item Shop Trade Restriction adjustment (#2517)

* Item Shop Trade Restriction adjustment
* Fixes #2503.
* Added a config to allow usage of sell-restricted items as currency in Item Shops.
Thanks to @Mickosis!

* Cleaned up some final things
* Fixed some typos in the configuration file.
* Resolved the shop ID not being stored at the time of checking the currency.
* Optimized the inventory check.
Aleos 7 éve
szülő
commit
5208d16995
6 módosított fájl, 29 hozzáadás és 15 törlés
  1. 5 4
      conf/battle/items.conf
  2. 1 1
      src/map/battle.c
  3. 3 2
      src/map/clif.cpp
  4. 8 0
      src/map/itemdb.h
  5. 1 3
      src/map/npc.c
  6. 11 5
      src/map/pc.c

+ 5 - 4
conf/battle/items.conf

@@ -106,10 +106,11 @@ item_flooritem_check: yes
 // 4 - Character
 default_bind_on_equip: 4
 
-// Allow selling of bound items as Itemshop currency?
-// no = Bound items are unable to be sold at Itemshops
-// yes = Bound items are able to be sold at Itemshops
-allow_bound_sell: no
+// Allow selling of bound/sell restricted items as Itemshop currency? (Note 3)
+// 0x0 = Bound/sell restricted items are unable to be sold at Itemshops
+// 0x1 = Bound items are able to be sold at Itemshops
+// 0x2 = Sell restricted items are able to be sold at Itemshops
+allow_bound_sell: 0x0
 
 // Turn on event refine chance (see db/{pre-}re/refine_db.yml)
 // no = normal refine chances in effect (official/default value)

+ 1 - 1
src/map/battle.c

@@ -8441,7 +8441,7 @@ static const struct _battle_data {
 	{ "guild_leaderchange_woe",				&battle_config.guild_leaderchange_woe,			0,		0,		1,				},
 	{ "guild_alliance_onlygm",              &battle_config.guild_alliance_onlygm,           0,      0,      1, },
 	{ "feature.achievement",                &battle_config.feature_achievement,             1,      0,      1,              },
-	{ "allow_bound_sell",                   &battle_config.allow_bound_sell,                1,      0,      1,              },
+	{ "allow_bound_sell",                   &battle_config.allow_bound_sell,                0,      0,      0x3,            },
 	{ "event_refine_chance",                &battle_config.event_refine_chance,             0,      0,      1,              },
 
 #include "../custom/battle_config_init.inc"

+ 3 - 2
src/map/clif.cpp

@@ -16238,10 +16238,11 @@ void clif_cashshop_show(struct map_session_data *sd, struct npc_data *nd)
 	nullpo_retv(sd);
 	nullpo_retv(nd);
 
-	npc_shop_currency_type(sd, nd, cost, true);
-
 	fd = sd->fd;
 	sd->npc_shopid = nd->bl.id;
+
+	npc_shop_currency_type(sd, nd, cost, true);
+
 	WFIFOHEAD(fd,offset+nd->u.shop.count*11);
 	WFIFOW(fd,0) = 0x287;
 	WFIFOW(fd,2) = offset+nd->u.shop.count*11;

+ 8 - 0
src/map/itemdb.h

@@ -737,6 +737,14 @@ enum e_random_item_group {
 	IG_SANTA_GIFT,
 };
 
+/// Enum for bound/sell restricted selling
+enum e_itemshop_restrictions {
+	ISR_NONE = 0x0,
+	ISR_BOUND = 0x1,
+	ISR_SELLABLE = 0x2,
+	ISR_ALL = 0x3,
+};
+
 ///Item combo struct
 struct item_combo
 {

+ 1 - 3
src/map/npc.c

@@ -1580,10 +1580,8 @@ void npc_shop_currency_type(struct map_session_data *sd, struct npc_data *nd, in
 				}
 
 				for (i = 0; i < MAX_INVENTORY; i++) {
-					if (sd->inventory.u.items_inventory[i].nameid == id->nameid &&
-					    pc_can_sell_item(sd, &sd->inventory.u.items_inventory[i])) {
+					if (sd->inventory.u.items_inventory[i].amount > 0 && sd->inventory.u.items_inventory[i].nameid == id->nameid && pc_can_sell_item(sd, &sd->inventory.u.items_inventory[i]))
 						total += sd->inventory.u.items_inventory[i].amount;
-					}
 				}
 			}
 

+ 11 - 5
src/map/pc.c

@@ -594,17 +594,23 @@ bool pc_can_sell_item(struct map_session_data *sd, struct item *item) {
 
 	nd = map_id2nd(sd->npc_shopid);
 
-	if (!itemdb_cansell(item, pc_get_group_level(sd)))
-		return false;
-
 	if (battle_config.hide_fav_sell && item->favorite)
 		return false; //Cannot sell favs (optional config)
 
 	if (item->expire_time)
 		return false; // Cannot Sell Rental Items
 
-	if (nd && nd->subtype == NPCTYPE_ITEMSHOP && item->bound && battle_config.allow_bound_sell)
-		return true; // NPCTYPE_ITEMSHOP and bound item config is sellable
+	if (nd && nd->subtype == NPCTYPE_ITEMSHOP) {
+		struct item_data *itd;
+
+		if (item->bound && battle_config.allow_bound_sell&ISR_BOUND)
+			return true; // NPCTYPE_ITEMSHOP and bound item config is sellable
+		if ((itd = itemdb_search(item->nameid)) && itd->flag.trade_restriction&8 && battle_config.allow_bound_sell&ISR_SELLABLE)
+			return true; // NPCTYPE_ITEMSHOP and sell restricted item config is sellable
+	}
+
+	if (!itemdb_cansell(item, pc_get_group_level(sd)))
+		return false;
 
 	if (item->bound && !pc_can_give_bounded_items(sd))
 		return false; // Don't allow sale of bound items