Skip to content
Permalink
Browse files

Fixed item removal in RODEX (#4332)

Fixes #4317

Thanks to @voyfmyuh
  • Loading branch information...
Lemongrass3110 committed Sep 5, 2019
1 parent 9c05cb8 commit 4664e88b91d49faa90e09d7bbb2df2b8bbb1862e
Showing with 31 additions and 12 deletions.
  1. +11 −1 src/map/clif.cpp
  2. +20 −11 src/map/mail.cpp
@@ -15874,7 +15874,17 @@ void clif_mail_removeitem( struct map_session_data* sd, bool success, int index,
WFIFOB(fd, 2) = success;
WFIFOW(fd, 3) = index;
WFIFOW(fd, 5) = amount;
WFIFOW(fd, 7) = 0; // TODO: which weight? item weight? removed weight? remaining weight?

int total = 0;
for( int i = 0; i < MAIL_MAX_ITEM; i++ ){
if( sd->mail.item[i].nameid == 0 ){
break;
}

total += sd->mail.item[i].amount * ( sd->inventory_data[sd->mail.item[i].index]->weight / 10 );
}

WFIFOW(fd, 7) = total;
WFIFOSET(fd, 9);
}

@@ -65,18 +65,27 @@ int mail_removeitem(struct map_session_data *sd, short flag, int idx, int amount
pc_delitem(sd, idx, amount, 0, 0, LOG_TYPE_MAIL);
#endif
}else{
for( ; i < MAIL_MAX_ITEM-1; i++ ){
if (sd->mail.item[i + 1].nameid == 0)
break;
sd->mail.item[i].index = sd->mail.item[i+1].index;
sd->mail.item[i].nameid = sd->mail.item[i+1].nameid;
sd->mail.item[i].amount = sd->mail.item[i+1].amount;
}
sd->mail.item[i].amount -= amount;

// Item was removed completely
if( sd->mail.item[i].amount <= 0 ){
// Move the rest of the array forward
for( ; i < MAIL_MAX_ITEM - 1; i++ ){
if ( sd->mail.item[i + 1].nameid == 0 ){
break;
}

for( ; i < MAIL_MAX_ITEM; i++ ){
sd->mail.item[i].index = 0;
sd->mail.item[i].nameid = 0;
sd->mail.item[i].amount = 0;
sd->mail.item[i].index = sd->mail.item[i+1].index;
sd->mail.item[i].nameid = sd->mail.item[i+1].nameid;
sd->mail.item[i].amount = sd->mail.item[i+1].amount;
}

// Zero the rest
for( ; i < MAIL_MAX_ITEM; i++ ){
sd->mail.item[i].index = 0;
sd->mail.item[i].nameid = 0;
sd->mail.item[i].amount = 0;
}
}

#if PACKETVER < 20150513

0 comments on commit 4664e88

Please sign in to comment.
You can’t perform that action at this time.