summaryrefslogtreecommitdiff
path: root/src/map/clif.c
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2016-02-22 03:53:36 +0100
committerHaru <haru@dotalux.com>2016-02-24 21:02:21 +0100
commit3b9c0daf1bc4d4c8d4c39f3e5e4e25d103ed9b3a (patch)
tree15db076f3c6027de5a04055e02f2979b18e045d0 /src/map/clif.c
parent23f1ef310719081c79aebf3f8921240773f5a507 (diff)
downloadhercules-3b9c0daf1bc4d4c8d4c39f3e5e4e25d103ed9b3a.tar.gz
hercules-3b9c0daf1bc4d4c8d4c39f3e5e4e25d103ed9b3a.tar.bz2
hercules-3b9c0daf1bc4d4c8d4c39f3e5e4e25d103ed9b3a.tar.xz
hercules-3b9c0daf1bc4d4c8d4c39f3e5e4e25d103ed9b3a.zip
Edited npc->market_buylist() to use the new struct itemlist
- The npc-side code no longer depends on the client data layout. Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src/map/clif.c')
-rw-r--r--src/map/clif.c51
1 files changed, 30 insertions, 21 deletions
diff --git a/src/map/clif.c b/src/map/clif.c
index 9dc42bb07..eb67723e2 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -18193,33 +18193,30 @@ void clif_parse_NPCMarketClosed(int fd, struct map_session_data *sd) {
sd->npc_shopid = 0;
}
-void clif_npc_market_purchase_ack(struct map_session_data *sd, const struct packet_npc_market_purchase *req, unsigned char response)
+void clif_npc_market_purchase_ack(struct map_session_data *sd, const struct itemlist *item_list, unsigned char response)
{
#if PACKETVER >= 20131223
unsigned short c = 0;
nullpo_retv(sd);
- nullpo_retv(req);
+ nullpo_retv(item_list);
npcmarket_result.PacketType = npcmarketresultackType;
npcmarket_result.result = response == 0 ? 1 : 0;/* find other values */
- if( npcmarket_result.result ) {
- unsigned short i, list_size = (req->PacketLength - 4) / sizeof(req->list[0]), j;
- struct npc_data* nd;
- struct npc_item_list *shop = NULL;
- unsigned short shop_size = 0;
-
- nd = map->id2nd(sd->npc_shopid);
-
- shop = nd->u.scr.shop->item;
- shop_size = nd->u.scr.shop->items;
+ if (npcmarket_result.result) {
+ struct npc_data *nd = map->id2nd(sd->npc_shopid);
+ struct npc_item_list *shop = nd->u.scr.shop->item;
+ unsigned short shop_size = nd->u.scr.shop->items;
+ int i;
- for(i = 0; i < list_size; i++) {
+ for (i = 0; i < VECTOR_LENGTH(*item_list); i++) {
+ const struct itemlist_entry *entry = &VECTOR_INDEX(*item_list, i);
+ int j;
- npcmarket_result.list[i].ITID = req->list[i].ITID;
- npcmarket_result.list[i].qty = req->list[i].qty;
+ npcmarket_result.list[i].ITID = entry->id;
+ npcmarket_result.list[i].qty = entry->amount;
- ARR_FIND( 0, shop_size, j, req->list[i].ITID == shop[j].nameid );
+ ARR_FIND( 0, shop_size, j, entry->id == shop[j].nameid);
npcmarket_result.list[i].price = (j != shop_size) ? shop[j].value : 0;
@@ -18238,16 +18235,28 @@ void clif_parse_NPCMarketPurchase(int fd, struct map_session_data *sd)
{
#if PACKETVER >= 20131223
const struct packet_npc_market_purchase *p = RP2PTR(fd);
- struct packet_npc_market_purchase pcopy;
- int response = 0;
+ int response = 0, i;
int count = (p->PacketLength - 4) / sizeof p->list[0];
+ struct itemlist item_list;
Assert_retv(count >= 0 && count <= MAX_INVENTORY);
- memcpy(&pcopy, p, p->PacketLength); // FIXME: Temporary hack (until changed to a flexible array)
+ VECTOR_INIT(item_list);
+ VECTOR_ENSURE(item_list, count, 1);
+
+ for (i = 0; i < count; i++) {
+ struct itemlist_entry entry = { 0 };
+
+ entry.id = p->list[i].ITID;
+ entry.amount = p->list[i].qty;
- response = npc->market_buylist(sd, count, &pcopy);
- clif->npc_market_purchase_ack(sd, &pcopy, response);
+ VECTOR_PUSH(item_list, entry);
+ }
+
+ response = npc->market_buylist(sd, &item_list);
+ clif->npc_market_purchase_ack(sd, &item_list, response);
+
+ VECTOR_CLEAR(item_list);
#endif
}