Grasscutter/src/main/java/emu/grasscutter/server/packet/send/PacketGetMailItemRsp.java

56 lines
2.3 KiB
Java
Raw Normal View History

package emu.grasscutter.server.packet.send;
2022-04-25 05:51:19 +00:00
import emu.grasscutter.data.GenshinData;
import emu.grasscutter.game.GenshinPlayer;
2022-04-25 05:51:19 +00:00
import emu.grasscutter.game.Mail;
import emu.grasscutter.game.inventory.GenshinItem;
import emu.grasscutter.game.props.ActionReason;
import emu.grasscutter.net.packet.GenshinPacket;
import emu.grasscutter.net.packet.PacketOpcodes;
2022-04-25 05:51:19 +00:00
import emu.grasscutter.net.proto.EquipParamOuterClass;
import emu.grasscutter.net.proto.GetMailItemRspOuterClass.GetMailItemRsp;
2022-04-25 05:51:19 +00:00
import java.util.ArrayList;
import java.util.List;
2022-04-25 05:51:19 +00:00
import java.util.stream.Collectors;
public class PacketGetMailItemRsp extends GenshinPacket {
public PacketGetMailItemRsp(GenshinPlayer player, List<Integer> mailList) {
super(PacketOpcodes.GetMailItemRsp);
2022-04-25 05:51:19 +00:00
List<Mail> claimedMessages = new ArrayList<>();
List<EquipParamOuterClass.EquipParam> claimedItems = new ArrayList<>();
2022-04-25 05:51:19 +00:00
GetMailItemRsp.Builder proto = GetMailItemRsp.newBuilder();
2022-04-25 05:51:19 +00:00
for (int mailId : mailList) {
Mail message = player.getMailById(mailId);
int messageIndex = player.getMailIndex(message);
2022-04-25 05:51:19 +00:00
for(Mail.MailItem mailItem : message.itemList) {
EquipParamOuterClass.EquipParam.Builder item = EquipParamOuterClass.EquipParam.newBuilder();
item.setItemId(mailItem.itemId);
item.setItemNum(mailItem.itemCount);
claimedItems.add(item.build());
GenshinItem genshinItem = new GenshinItem(GenshinData.getItemDataMap().get(mailItem.itemId));
genshinItem.setCount(mailItem.itemCount);
player.getInventory().addItem(genshinItem);
player.sendPacket(new PacketItemAddHintNotify(genshinItem, ActionReason.MailAttachment));
}
2022-04-25 06:30:56 +00:00
message.isAttachmentGot = true;
claimedMessages.add(message);
player.replaceMailByIndex(messageIndex, message);
2022-04-25 05:51:19 +00:00
}
proto.addAllMailIdList(claimedMessages.stream().map(Mail::getId).collect(Collectors.toList()));
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
}
}