Fixed item removal in RODEX (#4332)

Fixes #4317

Thanks to @voyfmyuh
This commit is contained in:
Lemongrass3110
2019-09-05 23:26:36 +02:00
committed by GitHub
parent 9c05cb8b6f
commit 4664e88b91
2 changed files with 31 additions and 12 deletions

View File

@@ -15874,7 +15874,17 @@ void clif_mail_removeitem( struct map_session_data* sd, bool success, int index,
WFIFOB(fd, 2) = success; WFIFOB(fd, 2) = success;
WFIFOW(fd, 3) = index; WFIFOW(fd, 3) = index;
WFIFOW(fd, 5) = amount; 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); WFIFOSET(fd, 9);
} }

View File

@@ -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); pc_delitem(sd, idx, amount, 0, 0, LOG_TYPE_MAIL);
#endif #endif
}else{ }else{
for( ; i < MAIL_MAX_ITEM-1; i++ ){ sd->mail.item[i].amount -= amount;
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;
}
for( ; i < MAIL_MAX_ITEM; i++ ){ // Item was removed completely
sd->mail.item[i].index = 0; if( sd->mail.item[i].amount <= 0 ){
sd->mail.item[i].nameid = 0; // Move the rest of the array forward
sd->mail.item[i].amount = 0; 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;
}
// 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 #if PACKETVER < 20150513