From 55ca79961da77d1ba6c244393de0101709e7bc0d Mon Sep 17 00:00:00 2001 From: Lemongrass3110 Date: Thu, 15 Apr 2021 01:34:39 +0200 Subject: [PATCH] Follow up to f77cb8a Added a check for required inventory slots. Additionally fixed some checks that have been wrong for years. --- src/map/clif.cpp | 8 +++++--- src/map/mail.cpp | 8 ++++++-- src/map/pc.cpp | 1 + src/map/pc.hpp | 1 + 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/map/clif.cpp b/src/map/clif.cpp index 25d3d6f52e..22f81500f1 100644 --- a/src/map/clif.cpp +++ b/src/map/clif.cpp @@ -16104,7 +16104,7 @@ void clif_parse_Mail_getattach( int fd, struct map_session_data *sd ){ } if( attachment&MAIL_ATT_ITEM ){ - int new_ = 0, totalweight = 0; + int slots = 0, totalweight = 0; for( i = 0; i < MAIL_MAX_ITEM; i++ ){ struct item* item = &msg->item[i]; @@ -16117,7 +16117,7 @@ void clif_parse_Mail_getattach( int fd, struct map_session_data *sd ){ switch( pc_checkadditem(sd, item->nameid, item->amount) ){ case CHKADDITEM_NEW: - new_++; + slots += data->inventorySlotNeeded( item->amount ); break; case CHKADDITEM_OVERAMOUNT: clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM); @@ -16131,7 +16131,7 @@ void clif_parse_Mail_getattach( int fd, struct map_session_data *sd ){ 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_ ){ + }else if( pc_inventoryblank(sd) < ( slots + sd->mail.pending_slots ) ){ clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM); return; } @@ -16141,6 +16141,8 @@ void clif_parse_Mail_getattach( int fd, struct map_session_data *sd ){ // Store the pending weight (required for the "retrieve all" feature) sd->mail.pending_weight += totalweight; + // Store the pending slots (required for the "retrieve all" feature) + sd->mail.pending_slots += slots; } intif_mail_getattach(sd,msg, (enum mail_attachment_type)attachment); diff --git a/src/map/mail.cpp b/src/map/mail.cpp index bec6eca4ad..fee0d82aef 100644 --- a/src/map/mail.cpp +++ b/src/map/mail.cpp @@ -289,7 +289,7 @@ void mail_getattachment(struct map_session_data* sd, struct mail_message* msg, i bool item_received = false; for( i = 0; i < MAIL_MAX_ITEM; i++ ){ - if( item->nameid > 0 && item->amount > 0 ){ + if( item[i].nameid > 0 && item[i].amount > 0 ){ struct item_data* id = itemdb_search( item->nameid ); // Item does not exist (anymore?) @@ -307,6 +307,7 @@ void mail_getattachment(struct map_session_data* sd, struct mail_message* msg, i if( pet != nullptr && item[i].card[0] == 0 ){ // Create a new pet if( pet_create_egg( sd, item[i].nameid ) ){ + sd->mail.pending_slots--; item_received = true; }else{ // Do not send receive packet so that the mail is still displayed with item attachment @@ -315,9 +316,12 @@ void mail_getattachment(struct map_session_data* sd, struct mail_message* msg, i break; } }else{ + int slots = id->inventorySlotNeeded( item[i].amount ); + // Add the item normally if( pc_additem( sd, &item[i], item[i].amount, LOG_TYPE_MAIL ) == ADDITEM_SUCCESS ){ item_received = true; + sd->mail.pending_slots -= slots; }else{ // Do not send receive packet so that the mail is still displayed with item attachment item_received = false; @@ -327,7 +331,7 @@ void mail_getattachment(struct map_session_data* sd, struct mail_message* msg, i } // Make sure no requests are possible anymore - item->amount = 0; + item[i].amount = 0; } } diff --git a/src/map/pc.cpp b/src/map/pc.cpp index 2918a84ec6..4e343f6383 100755 --- a/src/map/pc.cpp +++ b/src/map/pc.cpp @@ -1685,6 +1685,7 @@ bool pc_authok(struct map_session_data *sd, uint32 login_id2, time_t expiration_ sd->count_rewarp = 0; sd->mail.pending_weight = 0; sd->mail.pending_zeny = 0; + sd->mail.pending_slots = 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 a8b56a142b..25bbb57ce1 100644 --- a/src/map/pc.hpp +++ b/src/map/pc.hpp @@ -664,6 +664,7 @@ struct map_session_data { bool changed; // if true, should sync with charserver on next mailbox request uint32 pending_weight; uint32 pending_zeny; + uint16 pending_slots; } mail; //Quest log system