From b0ac1717f23aacda0af40a3a849923f69c535501 Mon Sep 17 00:00:00 2001 From: Lemongrass3110 Date: Fri, 7 Feb 2020 00:29:33 +0100 Subject: [PATCH] Added an option to block discount in shop (#4606) This is required for the correct implementation of #4387 --- doc/script_commands.txt | 6 ++++-- src/map/clif.cpp | 2 +- src/map/npc.cpp | 46 ++++++++++++++++++++++++++++------------- src/map/npc.hpp | 2 +- 4 files changed, 38 insertions(+), 18 deletions(-) diff --git a/doc/script_commands.txt b/doc/script_commands.txt index ba014be835..b31bad361f 100644 --- a/doc/script_commands.txt +++ b/doc/script_commands.txt @@ -277,8 +277,8 @@ these floating NPC objects are for. More on that below. ** Define a shop/cashshop/itemshop/pointshop NPC. --%TAB%shop%TAB%%TAB%,:{,:...} -,,,%TAB%shop%TAB%%TAB%,:{,:...} +-%TAB%shop%TAB%%TAB%{,discount},:{,:...} +,,,%TAB%shop%TAB%%TAB%{,discount},:{,:...} -%TAB%cashshop%TAB%%TAB%,:{,:...} ,,,%TAB%cashshop%TAB%%TAB%,:{,:...} @@ -301,6 +301,8 @@ to -1, the 'buy price' given in the item database will be used. Otherwise, the price you gave will be used for this item, which is how you create differing prices for items in different shops. +Optionally you can specify the discount option and set it to "yes" or "no", to enable or disable discounting. + There are other types of shops available: cashshop - use "cashshop" in place of "shop" to use the Cash Shop interface, allowing you to buy items with special points that are stored as account variables diff --git a/src/map/clif.cpp b/src/map/clif.cpp index 68adcb723e..fad7eede6b 100644 --- a/src/map/clif.cpp +++ b/src/map/clif.cpp @@ -1964,7 +1964,7 @@ void clif_buylist(struct map_session_data *sd, struct npc_data *nd) WFIFOW(fd,0) = 0xc6; c = 0; - discount = npc_shop_discount(nd->subtype,nd->u.shop.discount); + discount = npc_shop_discount(nd); for( i = 0; i < nd->u.shop.count; i++ ) { struct item_data* id = itemdb_exists(nd->u.shop.shop_item[i].nameid); diff --git a/src/map/npc.cpp b/src/map/npc.cpp index 0b66869789..36b597828c 100644 --- a/src/map/npc.cpp +++ b/src/map/npc.cpp @@ -1916,7 +1916,7 @@ uint8 npc_buylist(struct map_session_data* sd, uint16 n, struct s_npc_buy_list * return 2; } - if (npc_shop_discount(nd->subtype,nd->u.shop.discount)) + if (npc_shop_discount(nd)) value = pc_modifybuyvalue(sd,value); z += (double)value * amount; @@ -2827,7 +2827,20 @@ static const char* npc_parse_shop(char* w1, char* w2, char* w3, char* w4, const break; #endif default: - is_discount = 1; + if( sscanf( p, ",%32[^,:]:%11d,", point_str, &is_discount ) == 2 ){ + is_discount = 1; + }else{ + if( !strcasecmp( point_str, "yes" ) ){ + is_discount = 1; + }else if( !strcasecmp( point_str, "no" ) ){ + is_discount = 0; + }else{ + ShowError( "npc_parse_shop: unknown discount setting %s\n", point_str ); + return strchr( start, '\n' ); // skip and continue + } + + p = strchr( p + 1, ',' ); + } break; } @@ -2919,12 +2932,16 @@ static const char* npc_parse_shop(char* w1, char* w2, char* w3, char* w4, const return strchr(start,'\n');// continue } - if (type != NPCTYPE_SHOP) { - if (type == NPCTYPE_ITEMSHOP) nd->u.shop.itemshop_nameid = nameid; // Item shop currency - else if (type == NPCTYPE_POINTSHOP) safestrncpy(nd->u.shop.pointshop_str,point_str,strlen(point_str)+1); // Point shop currency - nd->u.shop.discount = is_discount > 0; + if( type == NPCTYPE_ITEMSHOP ){ + // Item shop currency + nd->u.shop.itemshop_nameid = nameid; + }else if( type == NPCTYPE_POINTSHOP ){ + // Point shop currency + safestrncpy( nd->u.shop.pointshop_str, point_str, strlen( point_str ) + 1 ); } + nd->u.shop.discount = is_discount > 0; + npc_parsename(nd, w3, start, buffer, filepath); nd->class_ = m == -1 ? JT_FAKENPC : npc_parseview(w4, start, buffer, filepath); nd->speed = 200; @@ -2967,14 +2984,15 @@ static const char* npc_parse_shop(char* w1, char* w2, char* w3, char* w4, const * @param discount Discount flag of NPC shop * @return bool 'true' is discountable, 'false' otherwise */ -bool npc_shop_discount(enum npc_subtype type, bool discount) { - if (type == NPCTYPE_SHOP || (type != NPCTYPE_SHOP && discount)) - return true; - - if( (type == NPCTYPE_ITEMSHOP && battle_config.discount_item_point_shop&1) || - (type == NPCTYPE_POINTSHOP && battle_config.discount_item_point_shop&2) ) - return true; - return false; +bool npc_shop_discount( struct npc_data* nd ){ + switch( nd->subtype ){ + case NPCTYPE_ITEMSHOP: + return nd->u.shop.discount || ( battle_config.discount_item_point_shop&1 ); + case NPCTYPE_POINTSHOP: + return nd->u.shop.discount || ( battle_config.discount_item_point_shop&2 ); + default: + return nd->u.shop.discount; + } } /** diff --git a/src/map/npc.hpp b/src/map/npc.hpp index e00fa759e7..2d9cf04e10 100644 --- a/src/map/npc.hpp +++ b/src/map/npc.hpp @@ -1266,7 +1266,7 @@ void npc_shop_currency_type(struct map_session_data *sd, struct npc_data *nd, in extern struct npc_data* fake_nd; int npc_cashshop_buylist(struct map_session_data *sd, int points, int count, unsigned short* item_list); -bool npc_shop_discount(enum npc_subtype type, bool discount); +bool npc_shop_discount(struct npc_data* nd); #if PACKETVER >= 20131223 void npc_market_tosql(const char *exname, struct npc_item_list *list);