From f77cb8a37ba4441742b6097d7b778df05851a619 Mon Sep 17 00:00:00 2001 From: Lemongrass3110 Date: Sun, 11 Apr 2021 02:27:17 +0200 Subject: [PATCH] Fixed RODEX's retrieve all feature (#5842) Thanks to @limitro --- src/map/clif.cpp | 10 ++++++++-- src/map/mail.cpp | 49 ++++++++++++++++++++++++++++++++++++------------ src/map/pc.cpp | 2 ++ src/map/pc.hpp | 2 ++ 4 files changed, 49 insertions(+), 14 deletions(-) diff --git a/src/map/clif.cpp b/src/map/clif.cpp index 79a3144f84..6d017f99eb 100644 --- a/src/map/clif.cpp +++ b/src/map/clif.cpp @@ -16091,10 +16091,13 @@ void clif_parse_Mail_getattach( int fd, struct map_session_data *sd ){ } if( attachment&MAIL_ATT_ZENY ){ - if( msg->zeny + sd->status.zeny > MAX_ZENY ){ + if( ( msg->zeny + sd->status.zeny + sd->mail.pending_zeny ) > MAX_ZENY ){ clif_mail_getattachment(sd, msg, 1, MAIL_ATT_ZENY); //too many zeny return; }else{ + // Store the pending zeny (required for the "retrieve all" feature) + sd->mail.pending_zeny += msg->zeny; + // To make sure another request fails msg->zeny = 0; } @@ -16125,7 +16128,7 @@ void clif_parse_Mail_getattach( int fd, struct map_session_data *sd ){ } } - if( ( totalweight + sd->weight ) > sd->max_weight ){ + if( ( totalweight + sd->weight + sd->mail.pending_weight ) > sd->max_weight ){ clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM); return; }else if( pc_inventoryblank(sd) < new_ ){ @@ -16135,6 +16138,9 @@ void clif_parse_Mail_getattach( int fd, struct map_session_data *sd ){ // To make sure another request fails memset(msg->item, 0, MAIL_MAX_ITEM*sizeof(struct item)); + + // Store the pending weight (required for the "retrieve all" feature) + sd->mail.pending_weight += totalweight; } intif_mail_getattach(sd,msg, (enum mail_attachment_type)attachment); diff --git a/src/map/mail.cpp b/src/map/mail.cpp index 9148a6a7b8..bec6eca4ad 100644 --- a/src/map/mail.cpp +++ b/src/map/mail.cpp @@ -290,23 +290,44 @@ void mail_getattachment(struct map_session_data* sd, struct mail_message* msg, i for( i = 0; i < MAIL_MAX_ITEM; i++ ){ if( item->nameid > 0 && item->amount > 0 ){ - // If no card or special card id is set - if( item[i].card[0] == 0 ){ - // Check if it is a pet egg - std::shared_ptr pet = pet_db_search( item[i].nameid, PET_EGG ); + struct item_data* id = itemdb_search( item->nameid ); - // If it is a pet egg and the card data does not contain a pet id (see if clause above) - if( pet != nullptr ){ - // Create a new pet - pet_create_egg( sd, item[i].nameid ); + // Item does not exist (anymore?) + if( id == nullptr ){ + continue; + } + + // Reduce the pending weight + sd->mail.pending_weight -= ( id->weight * item[i].amount ); + + // Check if it is a pet egg + std::shared_ptr pet = pet_db_search( item[i].nameid, PET_EGG ); + + // If it is a pet egg and the card data does not contain a pet id or other special ids are set + if( pet != nullptr && item[i].card[0] == 0 ){ + // Create a new pet + if( pet_create_egg( sd, item[i].nameid ) ){ item_received = true; - continue; + }else{ + // Do not send receive packet so that the mail is still displayed with item attachment + item_received = false; + // Additionally stop the processing + break; + } + }else{ + // Add the item normally + if( pc_additem( sd, &item[i], item[i].amount, LOG_TYPE_MAIL ) == ADDITEM_SUCCESS ){ + item_received = true; + }else{ + // Do not send receive packet so that the mail is still displayed with item attachment + item_received = false; + // Additionally stop the processing + break; } } - // Add the item normally - pc_additem( sd, &item[i], item[i].amount, LOG_TYPE_MAIL ); - item_received = true; + // Make sure no requests are possible anymore + item->amount = 0; } } @@ -316,6 +337,10 @@ void mail_getattachment(struct map_session_data* sd, struct mail_message* msg, i // Zeny receive if( zeny > 0 ){ + // Reduce the pending zeny + sd->mail.pending_zeny -= zeny; + + // Add the zeny pc_getzeny(sd, zeny,LOG_TYPE_MAIL, NULL); clif_mail_getattachment( sd, msg, 0, MAIL_ATT_ZENY ); } diff --git a/src/map/pc.cpp b/src/map/pc.cpp index b8dcc65b52..2918a84ec6 100755 --- a/src/map/pc.cpp +++ b/src/map/pc.cpp @@ -1683,6 +1683,8 @@ bool pc_authok(struct map_session_data *sd, uint32 login_id2, time_t expiration_ sd->avail_quests = 0; sd->save_quest = false; sd->count_rewarp = 0; + sd->mail.pending_weight = 0; + sd->mail.pending_zeny = 0; sd->regs.vars = i64db_alloc(DB_OPT_BASE); sd->regs.arrays = NULL; diff --git a/src/map/pc.hpp b/src/map/pc.hpp index 30427ebcfd..a8b56a142b 100644 --- a/src/map/pc.hpp +++ b/src/map/pc.hpp @@ -662,6 +662,8 @@ struct map_session_data { int zeny; struct mail_data inbox; bool changed; // if true, should sync with charserver on next mailbox request + uint32 pending_weight; + uint32 pending_zeny; } mail; //Quest log system