From 35d1c082365b061d147b23b534f54a3a84904f7b Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 13 Apr 2019 03:17:10 +0300 Subject: Improve get items from rodex --- src/map/rodex.c | 58 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 30 insertions(+), 28 deletions(-) (limited to 'src/map/rodex.c') diff --git a/src/map/rodex.c b/src/map/rodex.c index 2b8ac7757..766fdc5ea 100644 --- a/src/map/rodex.c +++ b/src/map/rodex.c @@ -457,7 +457,6 @@ static void rodex_getZenyAck(struct map_session_data *sd, int64 mail_id, int8 op /// @param mail_id : Mail ID that we're getting zeny from static void rodex_get_zeny(struct map_session_data *sd, int8 opentype, int64 mail_id) { - nullpo_retv(sd); struct rodex_message *msg = rodex->get_mail(sd, mail_id); @@ -477,19 +476,39 @@ static void rodex_get_zeny(struct map_session_data *sd, int8 opentype, int64 mai intif->rodex_updatemail(sd, mail_id, opentype, 1); } +// give requested items from message to player +static void rodex_getItemsAck(struct map_session_data *sd, int64 mail_id, int8 opentype, int count, const struct rodex_item *items) +{ + nullpo_retv(sd); + nullpo_retv(items); + + for (int i = 0; i < count; ++i) { + const struct item *it = &items[i].item; + + if (it->nameid == 0) { + continue; + } + + if (pc->additem(sd, it, it->amount, LOG_TYPE_MAIL) != 0) { + clif->rodex_request_items(sd, opentype, mail_id, RODEX_GET_ITEM_FULL_ERROR); + return; + } + } + + clif->rodex_request_items(sd, opentype, mail_id, RODEX_GET_ITEMS_SUCCESS); +} + /// Gets attached item /// @param sd : Who's getting /// @param mail_id : Mail ID that we're getting items from static void rodex_get_items(struct map_session_data *sd, int8 opentype, int64 mail_id) { - struct rodex_message *msg; - int weight = 0; - int empty_slots = 0, required_slots; - int i; - nullpo_retv(sd); - msg = rodex->get_mail(sd, mail_id); + int weight = 0; + int empty_slots = 0; + + struct rodex_message *msg = rodex->get_mail(sd, mail_id); if (msg == NULL) { clif->rodex_request_items(sd, opentype, mail_id, RODEX_GET_ITEM_FATAL_ERROR); @@ -501,7 +520,7 @@ static void rodex_get_items(struct map_session_data *sd, int8 opentype, int64 ma return; } - for (i = 0; i < RODEX_MAX_ITEM; ++i) { + for (int i = 0; i < RODEX_MAX_ITEM; ++i) { if (msg->items[i].item.nameid != 0) { weight += itemdb->search(msg->items[i].item.nameid)->weight * msg->items[i].item.amount; } @@ -512,8 +531,8 @@ static void rodex_get_items(struct map_session_data *sd, int8 opentype, int64 ma return; } - required_slots = msg->items_count; - for (i = 0; i < sd->status.inventorySize; ++i) { + int required_slots = msg->items_count; + for (int i = 0; i < sd->status.inventorySize; ++i) { if (sd->status.inventory[i].nameid == 0) { empty_slots++; } else if (itemdb->isstackable(sd->status.inventory[i].nameid) == 1) { @@ -538,27 +557,9 @@ static void rodex_get_items(struct map_session_data *sd, int8 opentype, int64 ma return; } - for (i = 0; i < RODEX_MAX_ITEM; ++i) { - struct item *it = &msg->items[i].item; - - if (it->nameid == 0) { - continue; - } - - if (pc->additem(sd, it, it->amount, LOG_TYPE_MAIL) != 0) { - clif->rodex_request_items(sd, opentype, mail_id, RODEX_GET_ITEM_FULL_ERROR); - intif->rodex_updatemail(sd, mail_id, opentype, 2); - return; - } else { - memset(it, 0x0, sizeof(*it)); - } - } - msg->type &= ~MAIL_TYPE_ITEM; msg->items_count = 0; intif->rodex_updatemail(sd, mail_id, opentype, 2); - - clif->rodex_request_items(sd, opentype, mail_id, RODEX_GET_ITEMS_SUCCESS); } /// Cleans user's RoDEX related data @@ -678,4 +679,5 @@ void rodex_defaults(void) rodex->get_items = rodex_get_items; rodex->clean = rodex_clean; rodex->getZenyAck = rodex_getZenyAck; + rodex->getItemsAck = rodex_getItemsAck; } -- cgit v1.2.3-70-g09d2