Added an option to block discount in shop (#4606)

This is required for the correct implementation of #4387
This commit is contained in:
Lemongrass3110 2020-02-07 00:29:33 +01:00 committed by GitHub
parent 83da86c301
commit b0ac1717f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 38 additions and 18 deletions

View File

@ -277,8 +277,8 @@ these floating NPC objects are for. More on that below.
** Define a shop/cashshop/itemshop/pointshop NPC.
-%TAB%shop%TAB%<NPC Name>%TAB%<sprite id>,<itemid>:<price>{,<itemid>:<price>...}
<map name>,<x>,<y>,<facing>%TAB%shop%TAB%<NPC Name>%TAB%<sprite id>,<itemid>:<price>{,<itemid>:<price>...}
-%TAB%shop%TAB%<NPC Name>%TAB%<sprite id>{,discount},<itemid>:<price>{,<itemid>:<price>...}
<map name>,<x>,<y>,<facing>%TAB%shop%TAB%<NPC Name>%TAB%<sprite id>{,discount},<itemid>:<price>{,<itemid>:<price>...}
-%TAB%cashshop%TAB%<NPC Name>%TAB%<sprite id>,<itemid>:<price>{,<itemid>:<price>...}
<map name>,<x>,<y>,<facing>%TAB%cashshop%TAB%<NPC Name>%TAB%<sprite id>,<itemid>:<price>{,<itemid>:<price>...}
@ -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

View File

@ -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);

View File

@ -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;
}
}
/**

View File

@ -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);