Browse Source

Fixed item removal in RODEX (#4332)

Fixes #4317

Thanks to @voyfmyuh
Lemongrass3110 5 năm trước cách đây
mục cha
commit
4664e88b91
2 tập tin đã thay đổi với 31 bổ sung12 xóa
  1. 11 1
      src/map/clif.cpp
  2. 20 11
      src/map/mail.cpp

+ 11 - 1
src/map/clif.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);
 }
 

+ 20 - 11
src/map/mail.cpp

@@ -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