From 6475f9aaef5e6affe3565c80e416e4b4e9cde043 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 21 Jun 2018 00:14:04 +0300 Subject: Fix packet 836 (search in stores). Added item options fields into this packet. Updated other things for support for report item options in vending. Buying store not supported for now. --- src/common/mmo.h | 13 +++++++------ src/map/buyingstore.c | 6 ++++-- src/map/buyingstore.h | 1 + src/map/clif.c | 12 ++++++++++-- src/map/itemdb.c | 14 +++++++------- src/map/itemdb.h | 8 ++++---- src/map/pc.c | 2 +- src/map/script.c | 2 +- src/map/searchstore.c | 3 ++- src/map/searchstore.h | 3 ++- src/map/status.c | 2 +- src/map/vending.c | 2 +- 12 files changed, 41 insertions(+), 27 deletions(-) diff --git a/src/common/mmo.h b/src/common/mmo.h index 0b4ba4a45..4a79245a1 100644 --- a/src/common/mmo.h +++ b/src/common/mmo.h @@ -363,6 +363,12 @@ enum attribute_flag { ATTR_BROKEN = 1, }; +struct item_option { + int16 index; + int16 value; + uint8 param; +}; + struct item { int id; short nameid; @@ -376,12 +382,7 @@ struct item { char favorite; unsigned char bound; uint64 unique_id; - - struct { - int16 index; - int16 value; - uint8 param; - } option[MAX_ITEM_OPTIONS]; + struct item_option option[MAX_ITEM_OPTIONS]; }; //Equip position constants diff --git a/src/map/buyingstore.c b/src/map/buyingstore.c index 8f8e8da9c..16c35ff2a 100644 --- a/src/map/buyingstore.c +++ b/src/map/buyingstore.c @@ -475,7 +475,8 @@ bool buyingstore_searchall(struct map_session_data* sd, const struct s_search_st ; } - if( !searchstore->result(s->search_sd, sd->buyer_id, sd->status.account_id, sd->message, it->nameid, it->amount, it->price, buyingstore->blankslots, 0) ) + // TODO: add support for cards and options + if (!searchstore->result(s->search_sd, sd->buyer_id, sd->status.account_id, sd->message, it->nameid, it->amount, it->price, buyingstore->blankslots, 0, buyingstore->blankoptions)) {// result set full return false; } @@ -487,7 +488,8 @@ void buyingstore_defaults(void) { buyingstore = &buyingstore_s; buyingstore->nextid = 0; - memset(buyingstore->blankslots,0,sizeof(buyingstore->blankslots)); + memset(buyingstore->blankslots, 0, sizeof(buyingstore->blankslots)); + memset(buyingstore->blankoptions, 0, sizeof(buyingstore->blankoptions)); /* */ buyingstore->setup = buyingstore_setup; buyingstore->create = buyingstore_create; diff --git a/src/map/buyingstore.h b/src/map/buyingstore.h index ee0163a03..408678e8e 100644 --- a/src/map/buyingstore.h +++ b/src/map/buyingstore.h @@ -76,6 +76,7 @@ struct s_buyingstore { struct buyingstore_interface { unsigned int nextid; short blankslots[MAX_SLOTS]; // used when checking whether or not an item's card slots are blank + struct item_option blankoptions[MAX_ITEM_OPTIONS]; // used for search result temporary. /* */ bool (*setup) (struct map_session_data* sd, unsigned char slots); void (*create) (struct map_session_data* sd, int zenylimit, unsigned char result, const char* storename, const uint8* itemlist, unsigned int count); diff --git a/src/map/clif.c b/src/map/clif.c index ce963f5ae..23eb3ee52 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -17760,7 +17760,11 @@ void clif_parse_SearchStoreInfo(int fd, struct map_session_data* sd) { /// 1 = "next" label to retrieve more results void clif_search_store_info_ack(struct map_session_data* sd) { - const unsigned int blocksize = MESSAGE_SIZE+26; +#if PACKETVER >= 20150226 + const unsigned int blocksize = MESSAGE_SIZE + 26 + 5 * MAX_ITEM_OPTIONS; +#else + const unsigned int blocksize = MESSAGE_SIZE + 26; +#endif int fd; unsigned int i, start, end; @@ -17795,7 +17799,11 @@ void clif_search_store_info_ack(struct map_session_data* sd) it.nameid = ssitem->nameid; it.amount = ssitem->amount; - clif->addcards(WFIFOP(fd,i*blocksize+25+MESSAGE_SIZE), &it); + clif->addcards(WFIFOP(fd, i * blocksize + 25 + MESSAGE_SIZE), &it); +#if PACKETVER >= 20150226 + memcpy(&it.option, &ssitem->option, sizeof(it.option)); + clif->add_item_options(WFIFOP(fd, i * blocksize + 33 + MESSAGE_SIZE), &it); +#endif } WFIFOSET(fd,WFIFOW(fd,2)); diff --git a/src/map/itemdb.c b/src/map/itemdb.c index d958d03d2..f2fd2ac80 100644 --- a/src/map/itemdb.c +++ b/src/map/itemdb.c @@ -324,11 +324,11 @@ struct item_data* itemdb_exists(int nameid) /** * Searches for the item_option data. * @param option_index as the index of the item option (client side). - * @return pointer to struct item_option data or NULL. + * @return pointer to struct itemdb_option data or NULL. */ -struct item_option *itemdb_option_exists(int idx) +struct itemdb_option *itemdb_option_exists(int idx) { - return (struct item_option *)idb_get(itemdb->options, idx); + return (struct itemdb_option *)idb_get(itemdb->options, idx); } /// Returns human readable name for given item type. @@ -1318,7 +1318,7 @@ void itemdb_read_packages(void) { * @param[in] source Source of the entry (file name), to be displayed in * case of validation errors. */ -void itemdb_readdb_options_additional_fields(struct item_option *ito, struct config_setting_t *t, const char *source) +void itemdb_readdb_options_additional_fields(struct itemdb_option *ito, struct config_setting_t *t, const char *source) { // do nothing. plugins can do their own work } @@ -1352,7 +1352,7 @@ void itemdb_read_options(void) VECTOR_ENSURE(duplicate_id, libconfig->setting_length(ito), 1); while ((conf = libconfig->setting_get_elem(ito, index++))) { - struct item_option t_opt = { 0 }, *s_opt = NULL; + struct itemdb_option t_opt = { 0 }, *s_opt = NULL; const char *str = NULL; int i = 0; @@ -1407,7 +1407,7 @@ void itemdb_read_options(void) itemdb->readdb_options_additional_fields(&t_opt, ito, filepath); /* Allocate memory and copy contents */ - CREATE(s_opt, struct item_option, 1); + CREATE(s_opt, struct itemdb_option, 1); *s_opt = t_opt; @@ -2458,7 +2458,7 @@ int itemdb_final_sub(union DBKey key, struct DBData *data, va_list ap) int itemdb_options_final_sub(union DBKey key, struct DBData *data, va_list ap) { - struct item_option *ito = DB->data2ptr(data); + struct itemdb_option *ito = DB->data2ptr(data); if (ito->script != NULL) script->free_code(ito->script); diff --git a/src/map/itemdb.h b/src/map/itemdb.h index ad237f7ce..efe3d0a3a 100644 --- a/src/map/itemdb.h +++ b/src/map/itemdb.h @@ -448,7 +448,7 @@ struct item_package { unsigned short must_qty; }; -struct item_option { +struct itemdb_option { int16 index; struct script_code *script; }; @@ -590,7 +590,7 @@ struct itemdb_interface { /* */ struct item_data *array[MAX_ITEMDB]; struct DBMap *other;// int nameid -> struct item_data* - struct DBMap *options; // int opt_id -> struct item_option* + struct DBMap *options; // int opt_id -> struct itemdb_option* struct item_data dummy; //This is the default dummy item used for non-existant items. [Skotlex] /* */ void (*read_groups) (void); @@ -607,7 +607,7 @@ struct itemdb_interface { struct item_data* (*load)(int nameid); struct item_data* (*search)(int nameid); struct item_data* (*exists) (int nameid); - struct item_option* (*option_exists) (int idx); + struct itemdb_option* (*option_exists) (int idx); bool (*in_group) (struct item_group *group, int nameid); int (*group_item) (struct item_group *group); int (*chain_item) (unsigned short chain_id, int *rate); @@ -640,7 +640,7 @@ struct itemdb_interface { void (*read_combos) (void); int (*gendercheck) (struct item_data *id); int (*validate_entry) (struct item_data *entry, int n, const char *source); - void (*readdb_options_additional_fields) (struct item_option *ito, struct config_setting_t *t, const char *source); + void (*readdb_options_additional_fields) (struct itemdb_option *ito, struct config_setting_t *t, const char *source); void (*readdb_additional_fields) (int itemid, struct config_setting_t *it, int n, const char *source); void (*readdb_job_sub) (struct item_data *id, struct config_setting_t *t); int (*readdb_libconfig_sub) (struct config_setting_t *it, int n, const char *source); diff --git a/src/map/pc.c b/src/map/pc.c index 922a39c5e..ebc66fc9f 100644 --- a/src/map/pc.c +++ b/src/map/pc.c @@ -10334,7 +10334,7 @@ int pc_unequipitem(struct map_session_data *sd,int n,int flag) } /* Item Options checking */ for (i = 0; i < MAX_ITEM_OPTIONS; i++) { - struct item_option *ito = NULL; + struct itemdb_option *ito = NULL; int16 item_option = sd->status.inventory[n].option[i].index; if (item_option <= 0) diff --git a/src/map/script.c b/src/map/script.c index 952496486..5252c0ff0 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -14394,7 +14394,7 @@ BUILDIN(setequipoption) int i = -1; struct map_session_data *sd = script->rid2sd(st); - struct item_option *ito = NULL; + struct itemdb_option *ito = NULL; if (sd == NULL) { script_pushint(st, 0); diff --git a/src/map/searchstore.c b/src/map/searchstore.c index f1ee33b3f..c80f2f575 100644 --- a/src/map/searchstore.c +++ b/src/map/searchstore.c @@ -340,7 +340,7 @@ void searchstore_clearremote(struct map_session_data* sd) { } /// receives results from a store-specific callback -bool searchstore_result(struct map_session_data* sd, unsigned int store_id, int account_id, const char* store_name, unsigned short nameid, unsigned short amount, unsigned int price, const short* card, unsigned char refine) +bool searchstore_result(struct map_session_data* sd, unsigned int store_id, int account_id, const char* store_name, unsigned short nameid, unsigned short amount, unsigned int price, const short* card, unsigned char refine, const struct item_option *option) { struct s_search_store_info_item* ssitem; @@ -360,6 +360,7 @@ bool searchstore_result(struct map_session_data* sd, unsigned int store_id, int ssitem->price = price; memcpy(ssitem->card, card, sizeof(ssitem->card)); ssitem->refine = refine; + memcpy(ssitem->option, option, sizeof(ssitem->option)); return true; } diff --git a/src/map/searchstore.h b/src/map/searchstore.h index 60ae8fca8..634486258 100644 --- a/src/map/searchstore.h +++ b/src/map/searchstore.h @@ -77,6 +77,7 @@ struct s_search_store_info_item { unsigned int price; short card[MAX_SLOTS]; unsigned char refine; + struct item_option option[MAX_ITEM_OPTIONS]; }; struct s_search_store_info { @@ -108,7 +109,7 @@ struct searchstore_interface { void (*click) (struct map_session_data* sd, int account_id, int store_id, unsigned short nameid); bool (*queryremote) (struct map_session_data* sd, int account_id); void (*clearremote) (struct map_session_data* sd); - bool (*result) (struct map_session_data* sd, unsigned int store_id, int account_id, const char* store_name, unsigned short nameid, unsigned short amount, unsigned int price, const short* card, unsigned char refine); + bool (*result) (struct map_session_data* sd, unsigned int store_id, int account_id, const char* store_name, unsigned short nameid, unsigned short amount, unsigned int price, const short* card, unsigned char refine, const struct item_option *option); }; #ifdef HERCULES_CORE diff --git a/src/map/status.c b/src/map/status.c index a4856f4da..f2275e47b 100644 --- a/src/map/status.c +++ b/src/map/status.c @@ -2694,7 +2694,7 @@ int status_calc_pc_(struct map_session_data* sd, enum e_status_calc_opt opt) int j = 0; for (j = 0; j < MAX_ITEM_OPTIONS; j++) { int16 option_index = sd->status.inventory[index].option[j].index; - struct item_option *ito = NULL; + struct itemdb_option *ito = NULL; if (option_index == 0 || (ito = itemdb->option_exists(option_index)) == NULL || ito->script == NULL) continue; diff --git a/src/map/vending.c b/src/map/vending.c index 8fba260f3..9a35bdccb 100644 --- a/src/map/vending.c +++ b/src/map/vending.c @@ -380,7 +380,7 @@ bool vending_searchall(struct map_session_data* sd, const struct s_search_store_ } } - if( !searchstore->result(s->search_sd, sd->vender_id, sd->status.account_id, sd->message, it->nameid, sd->vending[i].amount, sd->vending[i].value, it->card, it->refine) ) + if (!searchstore->result(s->search_sd, sd->vender_id, sd->status.account_id, sd->message, it->nameid, sd->vending[i].amount, sd->vending[i].value, it->card, it->refine, it->option)) {// result set full return false; } -- cgit v1.2.3-60-g2f50