Skip to content

Commit

Permalink
NPC Shop fixes:
Browse files Browse the repository at this point in the history
* Follow up 40c63f4: Fixed #368, warning fixes
* Fixed `pointshop` failed to get temporary player's variable (`@`) as currency.

Signed-off-by: Cydh Ramdh <house.bad@gmail.com>
  • Loading branch information
cydh committed Mar 29, 2015
1 parent 3c92075 commit cbdc012
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
17 changes: 10 additions & 7 deletions src/map/npc.c
Expand Up @@ -1679,6 +1679,8 @@ uint8 npc_buylist(struct map_session_data* sd, uint16 n, struct s_npc_buy_list *
count = pc_readaccountreg(sd, nd->u.shop.pointshop_str);
break;
case '@':
count = pc_readreg(sd, add_str(nd->u.shop.pointshop_str));
break;
default:
count = pc_readglobalreg(sd, nd->u.shop.pointshop_str);
break;
Expand Down Expand Up @@ -2539,19 +2541,13 @@ static const char* npc_parse_shop(char* w1, char* w2, char* w3, char* w4, const
nd->u.shop.count = 0;
while ( p ) {
unsigned short nameid2, qty = 0;
int value, i = 0;
int value;
struct item_data* id;
bool skip = false;

if( p == NULL )
break;
switch(type) {
case NPCTYPE_SHOP:
if (sscanf(p, ",%hu:%d", &nameid2, &value) != 2) {
ShowError("npc_parse_shop: (SHOP) Invalid item definition in file '%s', line '%d'. Ignoring the rest of the line...\n * w1=%s\n * w2=%s\n * w3=%s\n * w4=%s\n", filepath, strline(buffer, start - buffer), w1, w2, w3, w4);
skip = true;
}
break;
case NPCTYPE_MARKETSHOP:
#if PACKETVER >= 20131223
if (sscanf(p, ",%hu:%d:%hu", &nameid2, &value, &qty) != 3) {
Expand All @@ -2560,6 +2556,12 @@ static const char* npc_parse_shop(char* w1, char* w2, char* w3, char* w4, const
}
#endif
break;
default:
if (sscanf(p, ",%hu:%d", &nameid2, &value) != 2) {
ShowError("npc_parse_shop: Invalid item definition in file '%s', line '%d'. Ignoring the rest of the line...\n * w1=%s\n * w2=%s\n * w3=%s\n * w4=%s\n", filepath, strline(buffer, start - buffer), w1, w2, w3, w4);
skip = true;
}
break;
}

if (skip)
Expand Down Expand Up @@ -2593,6 +2595,7 @@ static const char* npc_parse_shop(char* w1, char* w2, char* w3, char* w4, const

#if PACKETVER >= 20131223
if (nd->u.shop.count && type == NPCTYPE_MARKETSHOP) {
uint16 i;
// Duplicate entry? Replace the value
ARR_FIND(0, nd->u.shop.count, i, nd->u.shop.shop_item[i].nameid == nameid);
if (i != nd->u.shop.count) {
Expand Down
14 changes: 4 additions & 10 deletions src/map/script.c
Expand Up @@ -16500,7 +16500,7 @@ BUILDIN_FUNC(setunitdata)
TBL_PET* pd = NULL;
TBL_ELEM* ed = NULL;
TBL_NPC* nd = NULL;
int type, value;
int type, value = 0;

bl = map_id2bl(script_getnum(st, 2));

Expand Down Expand Up @@ -19878,7 +19878,9 @@ BUILDIN_FUNC(npcshopupdate) {
struct npc_data* nd = npc_name2id(npcname);
uint16 nameid = script_getnum(st, 3);
int price = script_getnum(st, 4);
uint16 stock = 0;
#if PACKETVER >= 20131223
uint16 stock = script_hasdata(st,5) ? script_getnum(st,5) : 0;
#endif
int i;

if( !nd || ( nd->subtype != NPCTYPE_SHOP && nd->subtype != NPCTYPE_CASHSHOP && nd->subtype != NPCTYPE_ITEMSHOP && nd->subtype != NPCTYPE_POINTSHOP && nd->subtype != NPCTYPE_MARKETSHOP ) ) { // Not found.
Expand All @@ -19892,14 +19894,6 @@ BUILDIN_FUNC(npcshopupdate) {
return SCRIPT_CMD_FAILURE;
}

if (nd->subtype == NPCTYPE_MARKETSHOP) {
FETCH(5, stock);
}
else if ((price = cap_value(price, 0, INT_MAX)) == 0) { // Nothing to do here...
script_pushint(st,1);
return SCRIPT_CMD_SUCCESS;
}

for (i = 0; i < nd->u.shop.count; i++) {
if (nd->u.shop.shop_item[i].nameid == nameid) {

Expand Down

4 comments on commit cbdc012

@julia40124009
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks fix ~

@cydh
Copy link
Contributor Author

@cydh cydh commented on cbdc012 Mar 30, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

welcome

@hnomkeng
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you

@RagnarokNova
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm only able to buy 7 items per purchase. Is this intended?

Please sign in to comment.