2022-04-22 11:02:05 +00:00
|
|
|
package emu.grasscutter.server.packet.send;
|
|
|
|
|
2022-04-27 04:21:57 +00:00
|
|
|
import emu.grasscutter.data.GameData;
|
|
|
|
import emu.grasscutter.game.inventory.GameItem;
|
2022-04-27 04:24:25 +00:00
|
|
|
import emu.grasscutter.game.mail.Mail;
|
|
|
|
import emu.grasscutter.game.player.Player;
|
2022-04-25 05:51:19 +00:00
|
|
|
import emu.grasscutter.game.props.ActionReason;
|
2022-04-27 04:21:57 +00:00
|
|
|
import emu.grasscutter.net.packet.BasePacket;
|
2022-04-22 11:02:05 +00:00
|
|
|
import emu.grasscutter.net.packet.PacketOpcodes;
|
2022-04-25 05:51:19 +00:00
|
|
|
import emu.grasscutter.net.proto.EquipParamOuterClass;
|
2022-04-22 11:02:05 +00:00
|
|
|
import emu.grasscutter.net.proto.GetMailItemRspOuterClass.GetMailItemRsp;
|
|
|
|
|
2022-04-25 05:51:19 +00:00
|
|
|
import java.util.ArrayList;
|
2022-04-22 11:02:05 +00:00
|
|
|
import java.util.List;
|
2022-04-25 05:51:19 +00:00
|
|
|
import java.util.stream.Collectors;
|
2022-04-22 11:02:05 +00:00
|
|
|
|
2022-04-27 04:21:57 +00:00
|
|
|
public class PacketGetMailItemRsp extends BasePacket {
|
2022-04-22 11:02:05 +00:00
|
|
|
|
2022-04-27 04:21:57 +00:00
|
|
|
public PacketGetMailItemRsp(Player player, List<Integer> mailList) {
|
2022-04-22 11:02:05 +00:00
|
|
|
super(PacketOpcodes.GetMailItemRsp);
|
|
|
|
|
2022-04-25 05:51:19 +00:00
|
|
|
List<Mail> claimedMessages = new ArrayList<>();
|
|
|
|
List<EquipParamOuterClass.EquipParam> claimedItems = new ArrayList<>();
|
2022-04-22 11:02:05 +00:00
|
|
|
|
2022-04-25 05:51:19 +00:00
|
|
|
GetMailItemRsp.Builder proto = GetMailItemRsp.newBuilder();
|
2022-04-22 11:02:05 +00:00
|
|
|
|
2022-04-25 05:51:19 +00:00
|
|
|
for (int mailId : mailList) {
|
2022-04-26 03:57:55 +00:00
|
|
|
Mail message = player.getMail(mailId);
|
2022-04-22 11:02:05 +00:00
|
|
|
|
2022-04-25 05:51:19 +00:00
|
|
|
for(Mail.MailItem mailItem : message.itemList) {
|
|
|
|
EquipParamOuterClass.EquipParam.Builder item = EquipParamOuterClass.EquipParam.newBuilder();
|
2022-04-25 08:42:56 +00:00
|
|
|
int promoteLevel = 0;
|
|
|
|
if (mailItem.itemLevel > 20) { // 20/40
|
|
|
|
promoteLevel = 1;
|
|
|
|
} else if (mailItem.itemLevel > 40) { // 40/50
|
|
|
|
promoteLevel = 2;
|
|
|
|
} else if (mailItem.itemLevel > 50) { // 50/60
|
|
|
|
promoteLevel = 3;
|
|
|
|
} else if (mailItem.itemLevel > 60) { // 60/70
|
|
|
|
promoteLevel = 4;
|
|
|
|
} else if (mailItem.itemLevel > 70) { // 70/80
|
|
|
|
promoteLevel = 5;
|
|
|
|
} else if (mailItem.itemLevel > 80) { // 80/90
|
|
|
|
promoteLevel = 6;
|
|
|
|
}
|
|
|
|
|
2022-04-25 05:51:19 +00:00
|
|
|
item.setItemId(mailItem.itemId);
|
|
|
|
item.setItemNum(mailItem.itemCount);
|
2022-04-25 08:42:56 +00:00
|
|
|
item.setItemLevel(mailItem.itemLevel);
|
|
|
|
item.setPromoteLevel(promoteLevel);
|
2022-04-25 05:51:19 +00:00
|
|
|
claimedItems.add(item.build());
|
|
|
|
|
2022-04-27 04:21:57 +00:00
|
|
|
GameItem gameItem = new GameItem(GameData.getItemDataMap().get(mailItem.itemId));
|
|
|
|
gameItem.setCount(mailItem.itemCount);
|
|
|
|
gameItem.setLevel(mailItem.itemLevel);
|
|
|
|
gameItem.setPromoteLevel(promoteLevel);
|
|
|
|
player.getInventory().addItem(gameItem, ActionReason.MailAttachment);
|
2022-04-25 05:51:19 +00:00
|
|
|
}
|
2022-04-25 06:30:56 +00:00
|
|
|
|
|
|
|
message.isAttachmentGot = true;
|
|
|
|
claimedMessages.add(message);
|
|
|
|
|
2022-04-26 03:57:55 +00:00
|
|
|
player.replaceMailByIndex(mailId, message);
|
2022-04-25 05:51:19 +00:00
|
|
|
}
|
|
|
|
|
2022-04-26 03:57:55 +00:00
|
|
|
proto.addAllMailIdList(claimedMessages.stream().map(message -> player.getMailId(message)).collect(Collectors.toList()));
|
2022-04-25 05:51:19 +00:00
|
|
|
proto.addAllItemList(claimedItems);
|
|
|
|
|
|
|
|
this.setData(proto.build());
|
2022-04-25 06:30:56 +00:00
|
|
|
player.getSession().send(new PacketMailChangeNotify(player, claimedMessages)); // For some reason you have to also send the MailChangeNotify packet
|
2022-04-22 11:02:05 +00:00
|
|
|
}
|
|
|
|
}
|