diff --git a/data/ExpeditionReward.json b/data/ExpeditionReward.json new file mode 100644 index 000000000..90d9378b6 --- /dev/null +++ b/data/ExpeditionReward.json @@ -0,0 +1,112 @@ +[ + { + "expId": 301, + "expeditionRewardDataList": [ + { + "hourTime": 4, + "expeditionRewardData": [ + { + "itemId": 202, + "minCount": 625, + "maxCount": 625 + } + ] + }, + { + "hourTime": 8, + "expeditionRewardData": [ + { + "itemId": 202, + "minCount": 1575, + "maxCount": 1575 + } + ] + }, + { + "hourTime": 12, + "expeditionRewardData": [ + { + "itemId": 202, + "minCount": 2500, + "maxCount": 2500 + } + ] + }, + { + "hourTime": 20, + "expeditionRewardData": [ + { + "itemId": 202, + "minCount": 5000, + "maxCount": 5000 + } + ] + } + ] + }, + { + "expId": 305, + "expeditionRewardDataList": [ + { + "hourTime": 4, + "rewardMora": 0, + "expeditionRewardData": [ + { + "itemId": 100064, + "minCount": 1, + "maxCount": 1 + }, { + "itemId": 101210, + "minCount": 1, + "maxCount": 1 + } + ] + }, + { + "hourTime": 8, + "rewardMora": 0, + "expeditionRewardData": [ + { + "itemId": 100064, + "minCount": 2, + "maxCount": 4 + }, { + "itemId": 101210, + "minCount": 2, + "maxCount": 4 + } + ] + }, + { + "hourTime": 12, + "rewardMora": 0, + "expeditionRewardData": [ + { + "itemId": 100064, + "minCount": 4, + "maxCount": 6 + }, { + "itemId": 101210, + "minCount": 4, + "maxCount": 6 + } + ] + }, + { + "hourTime": 20, + "rewardMora": 0, + "expeditionRewardData": [ + { + "itemId": 100064, + "minCount": 8, + "maxCount": 12 + }, { + "itemId": 101210, + "minCount": 8, + "maxCount": 12 + } + ] + } + ] + } +] \ No newline at end of file diff --git a/src/main/java/emu/grasscutter/game/expedition/ExpeditionInfo.java b/src/main/java/emu/grasscutter/game/expedition/ExpeditionInfo.java new file mode 100644 index 000000000..867d692cf --- /dev/null +++ b/src/main/java/emu/grasscutter/game/expedition/ExpeditionInfo.java @@ -0,0 +1,44 @@ +package emu.grasscutter.game.expedition; + +import dev.morphia.annotations.Entity; + +@Entity +public class ExpeditionInfo { + + public int getState() { + return state; + } + + public void setState(int state) { + this.state = state; + } + + public int getExpId() { + return expId; + } + + public void setExpId(int expId) { + this.expId = expId; + } + + public int getHourTime() { + return hourTime; + } + + public void setHourTime(int hourTime) { + this.hourTime = hourTime; + } + + public int getStartTime() { + return startTime; + } + + public void setStartTime(int startTime) { + this.startTime = startTime; + } + + private int state; + private int expId; + private int hourTime; + private int startTime; +} diff --git a/src/main/java/emu/grasscutter/game/expedition/ExpeditionManager.java b/src/main/java/emu/grasscutter/game/expedition/ExpeditionManager.java new file mode 100644 index 000000000..5d1b652e1 --- /dev/null +++ b/src/main/java/emu/grasscutter/game/expedition/ExpeditionManager.java @@ -0,0 +1,46 @@ +package emu.grasscutter.game.expedition; + +import com.google.gson.reflect.TypeToken; +import emu.grasscutter.Grasscutter; +import emu.grasscutter.server.game.GameServer; +import it.unimi.dsi.fastutil.ints.Int2ObjectMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; + +import java.io.FileReader; +import java.util.Collection; +import java.util.List; + +public class ExpeditionManager { + public GameServer getGameServer() { + return gameServer; + } + + private final GameServer gameServer; + + public Int2ObjectMap> getExpeditionRewardDataList() { return expeditionRewardData; } + + private final Int2ObjectMap> expeditionRewardData; + + public ExpeditionManager(GameServer gameServer) { + this.gameServer = gameServer; + this.expeditionRewardData = new Int2ObjectOpenHashMap<>(); + this.load(); + } + + public synchronized void load() { + try (FileReader fileReader = new FileReader(Grasscutter.getConfig().DATA_FOLDER + "ExpeditionReward.json")) { + getExpeditionRewardDataList().clear(); + List banners = Grasscutter.getGsonFactory().fromJson(fileReader, TypeToken.getParameterized(Collection.class, ExpeditionRewardInfo.class).getType()); + if(banners.size() > 0) { + for (ExpeditionRewardInfo di : banners) { + getExpeditionRewardDataList().put(di.getExpId(), di.getExpeditionRewardDataList()); + } + Grasscutter.getLogger().info("Expedition reward successfully loaded."); + } else { + Grasscutter.getLogger().error("Unable to load expedition reward. Expedition reward size is 0."); + } + } catch (Exception e) { + Grasscutter.getLogger().error("Unable to load expedition reward.", e); + } + } +} diff --git a/src/main/java/emu/grasscutter/game/expedition/ExpeditionRewardData.java b/src/main/java/emu/grasscutter/game/expedition/ExpeditionRewardData.java new file mode 100644 index 000000000..ded817a3e --- /dev/null +++ b/src/main/java/emu/grasscutter/game/expedition/ExpeditionRewardData.java @@ -0,0 +1,18 @@ +package emu.grasscutter.game.expedition; + +public class ExpeditionRewardData { + private int itemId; + private int minCount; + private int maxCount; + + public int getItemId() { + return itemId; + } + + public int getMinCount() { return minCount; } + + public int getMaxCount() { + return maxCount; + } + +} diff --git a/src/main/java/emu/grasscutter/game/expedition/ExpeditionRewardDataList.java b/src/main/java/emu/grasscutter/game/expedition/ExpeditionRewardDataList.java new file mode 100644 index 000000000..27a7534e2 --- /dev/null +++ b/src/main/java/emu/grasscutter/game/expedition/ExpeditionRewardDataList.java @@ -0,0 +1,15 @@ +package emu.grasscutter.game.expedition; + +import java.util.List; + +public class ExpeditionRewardDataList { + public int getHourTime() { + return hourTime; + } + public List getExpeditionRewardData() { + return expeditionRewardData; + } + + private int hourTime; + private List expeditionRewardData; +} diff --git a/src/main/java/emu/grasscutter/game/expedition/ExpeditionRewardInfo.java b/src/main/java/emu/grasscutter/game/expedition/ExpeditionRewardInfo.java new file mode 100644 index 000000000..4e0039ff9 --- /dev/null +++ b/src/main/java/emu/grasscutter/game/expedition/ExpeditionRewardInfo.java @@ -0,0 +1,16 @@ +package emu.grasscutter.game.expedition; + +import java.util.List; + +public class ExpeditionRewardInfo { + public int getExpId() { + return expId; + } + + public List getExpeditionRewardDataList() { + return expeditionRewardDataList; + } + + private int expId; + private List expeditionRewardDataList; +} diff --git a/src/main/java/emu/grasscutter/game/player/Player.java b/src/main/java/emu/grasscutter/game/player/Player.java index b93baccf8..6b01c18f6 100644 --- a/src/main/java/emu/grasscutter/game/player/Player.java +++ b/src/main/java/emu/grasscutter/game/player/Player.java @@ -14,6 +14,7 @@ import emu.grasscutter.game.avatar.AvatarStorage; import emu.grasscutter.game.entity.EntityGadget; import emu.grasscutter.game.entity.EntityItem; import emu.grasscutter.game.entity.GameEntity; +import emu.grasscutter.game.expedition.ExpeditionInfo; import emu.grasscutter.game.friends.FriendsList; import emu.grasscutter.game.friends.PlayerProfile; import emu.grasscutter.game.gacha.PlayerGachaInfo; @@ -50,6 +51,7 @@ import emu.grasscutter.server.packet.send.*; import emu.grasscutter.utils.DateHelper; import emu.grasscutter.utils.Position; import emu.grasscutter.utils.MessageHandler; +import emu.grasscutter.utils.Utils; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; @@ -101,6 +103,7 @@ public class Player { private ArrayList shownAvatars; private Set rewardedLevels; private ArrayList shopLimit; + private Map expeditionInfo; private int sceneId; private int regionId; @@ -170,6 +173,7 @@ public class Player { this.moonCardGetTimes = new HashSet<>(); this.shopLimit = new ArrayList<>(); + this.expeditionInfo = new HashMap<>(); this.messageHandler = null; this.mapMarksManager = new MapMarksManager(); this.movementManager = new MovementManager(this); @@ -673,6 +677,28 @@ public class Player { session.send(new PacketCardProductRewardNotify(getMoonCardRemainDays())); } + public Map getExpeditionInfo() { + return expeditionInfo; + } + + public void addExpeditionInfo(long avaterGuid, int expId, int hourTime, int startTime){ + ExpeditionInfo exp = new ExpeditionInfo(); + exp.setExpId(expId); + exp.setHourTime(hourTime); + exp.setState(1); + exp.setStartTime(startTime); + expeditionInfo.put(avaterGuid, exp); + } + + public void removeExpeditionInfo(long avaterGuid){ + expeditionInfo.remove(avaterGuid); + } + + public ExpeditionInfo getExpeditionInfo(long avaterGuid){ + return expeditionInfo.get(avaterGuid); + } + + public List getShopLimit() { return shopLimit; } @@ -1029,6 +1055,22 @@ public class Player { this.resetSendPlayerLocTime(); } } + // Expedition + var timeNow = Utils.getCurrentSeconds(); + var needNotify = false; + for (Long key : expeditionInfo.keySet()) { + ExpeditionInfo e = expeditionInfo.get(key); + if(e.getState() == 1){ + if(timeNow - e.getStartTime() >= e.getHourTime() * 60 * 60){ + e.setState(2); + needNotify = true; + } + } + } + if(needNotify){ + this.save(); + this.sendPacket(new PacketAvatarExpeditionDataNotify(this)); + } } diff --git a/src/main/java/emu/grasscutter/server/game/GameServer.java b/src/main/java/emu/grasscutter/server/game/GameServer.java index db4a8c32b..3b5d91837 100644 --- a/src/main/java/emu/grasscutter/server/game/GameServer.java +++ b/src/main/java/emu/grasscutter/server/game/GameServer.java @@ -8,6 +8,7 @@ import emu.grasscutter.game.Account; import emu.grasscutter.game.combine.CombineManger; import emu.grasscutter.game.drop.DropManager; import emu.grasscutter.game.dungeons.DungeonManager; +import emu.grasscutter.game.expedition.ExpeditionManager; import emu.grasscutter.game.gacha.GachaManager; import emu.grasscutter.game.managers.ChatManager; import emu.grasscutter.game.managers.InventoryManager; @@ -42,6 +43,7 @@ public final class GameServer extends KcpServer { private final ShopManager shopManager; private final MultiplayerManager multiplayerManager; private final DungeonManager dungeonManager; + private final ExpeditionManager expeditionManager; private final CommandMap commandMap; private final TaskMap taskMap; private final DropManager dropManager; @@ -66,6 +68,7 @@ public final class GameServer extends KcpServer { this.commandMap = new CommandMap(true); this.taskMap = new TaskMap(true); this.dropManager = new DropManager(this); + this.expeditionManager = new ExpeditionManager(this); this.combineManger = new CombineManger(this); // Schedule game loop. @@ -124,7 +127,11 @@ public final class GameServer extends KcpServer { public DungeonManager getDungeonManager() { return dungeonManager; } - + + public ExpeditionManager getExpeditionManager() { + return expeditionManager; + } + public CommandMap getCommandMap() { return this.commandMap; } @@ -132,6 +139,7 @@ public final class GameServer extends KcpServer { public CombineManger getCombineManger(){ return this.combineManger; } + public TaskMap getTaskMap() { return this.taskMap; } diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarExpeditionAllDataReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarExpeditionAllDataReq.java new file mode 100644 index 000000000..f1a30ab0d --- /dev/null +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarExpeditionAllDataReq.java @@ -0,0 +1,15 @@ +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketAvatarExpeditionAllDataRsp; + +@Opcodes(PacketOpcodes.AvatarExpeditionAllDataReq) +public class HandlerAvatarExpeditionAllDataReq extends PacketHandler { + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + session.send(new PacketAvatarExpeditionAllDataRsp(session.getPlayer())); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarExpeditionCallBackReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarExpeditionCallBackReq.java new file mode 100644 index 000000000..0ac05ed0b --- /dev/null +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarExpeditionCallBackReq.java @@ -0,0 +1,25 @@ +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AvatarExpeditionCallBackReqOuterClass.AvatarExpeditionCallBackReq; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketAvatarExpeditionCallBackRsp; +import emu.grasscutter.server.packet.send.PacketAvatarExpeditionStartRsp; +import emu.grasscutter.utils.Utils; + +@Opcodes(PacketOpcodes.AvatarExpeditionCallBackReq) +public class HandlerAvatarExpeditionCallBackReq extends PacketHandler { + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + AvatarExpeditionCallBackReq req = AvatarExpeditionCallBackReq.parseFrom(payload); + + for (int i = 0; i < req.getAvatarGuidCount(); i++) { + session.getPlayer().removeExpeditionInfo(req.getAvatarGuid(i)); + } + + session.getPlayer().save(); + session.send(new PacketAvatarExpeditionCallBackRsp(session.getPlayer())); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarExpeditionGetRewardReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarExpeditionGetRewardReq.java new file mode 100644 index 000000000..3e3bed9f1 --- /dev/null +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarExpeditionGetRewardReq.java @@ -0,0 +1,61 @@ +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.Grasscutter; +import emu.grasscutter.game.drop.DropData; +import emu.grasscutter.game.expedition.ExpeditionInfo; +import emu.grasscutter.game.expedition.ExpeditionRewardData; +import emu.grasscutter.game.expedition.ExpeditionRewardDataList; +import emu.grasscutter.game.inventory.GameItem; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.game.props.ActionReason; +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AvatarExpeditionGetRewardReqOuterClass.AvatarExpeditionGetRewardReq; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketAvatarExpeditionCallBackRsp; +import emu.grasscutter.server.packet.send.PacketAvatarExpeditionGetRewardRsp; +import emu.grasscutter.server.packet.send.PacketGadgetInteractRsp; +import emu.grasscutter.server.packet.send.PacketItemAddHintNotify; +import emu.grasscutter.utils.Utils; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.LinkedList; +import java.util.List; + +@Opcodes(PacketOpcodes.AvatarExpeditionGetRewardReq) +public class HandlerAvatarExpeditionGetRewardReq extends PacketHandler { + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + AvatarExpeditionGetRewardReq req = AvatarExpeditionGetRewardReq.parseFrom(payload); + + ExpeditionInfo expInfo = session.getPlayer().getExpeditionInfo(req.getAvatarGuid()); + + List items = new LinkedList<>(); + + if (session.getServer().getExpeditionManager().getExpeditionRewardDataList().containsKey(expInfo.getExpId())) { + for (ExpeditionRewardDataList RewardDataList : session.getServer().getExpeditionManager().getExpeditionRewardDataList().get(expInfo.getExpId())) { + if(RewardDataList.getHourTime() == expInfo.getHourTime()){ + if(!RewardDataList.getExpeditionRewardData().isEmpty()){ + for (ExpeditionRewardData RewardData :RewardDataList.getExpeditionRewardData()) { + int num = RewardData.getMinCount(); + if(RewardData.getMinCount() != RewardData.getMaxCount()){ + num = Utils.randomRange(RewardData.getMinCount(), RewardData.getMaxCount()); + } + items.add(new GameItem(RewardData.getItemId(), num)); + } + } + } + } + } + + session.getPlayer().getInventory().addItems(items); + session.getPlayer().sendPacket(new PacketItemAddHintNotify(items, ActionReason.ExpeditionReward)); + + session.getPlayer().removeExpeditionInfo(req.getAvatarGuid()); + session.getPlayer().save(); + session.send(new PacketAvatarExpeditionGetRewardRsp(session.getPlayer(), items)); + } +} + diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarExpeditionStartReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarExpeditionStartReq.java new file mode 100644 index 000000000..74395e30c --- /dev/null +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarExpeditionStartReq.java @@ -0,0 +1,23 @@ +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.Grasscutter; +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AvatarExpeditionStartReqOuterClass.AvatarExpeditionStartReq; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketAvatarExpeditionStartRsp; +import emu.grasscutter.utils.Utils; + +@Opcodes(PacketOpcodes.AvatarExpeditionStartReq) +public class HandlerAvatarExpeditionStartReq extends PacketHandler { + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + AvatarExpeditionStartReq req = AvatarExpeditionStartReq.parseFrom(payload); + + int startTime = Utils.getCurrentSeconds(); + session.getPlayer().addExpeditionInfo(req.getAvatarGuid(), req.getExpId(), req.getHourTime(), startTime); + session.getPlayer().save(); + session.send(new PacketAvatarExpeditionStartRsp(session.getPlayer())); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarExpeditionAllDataRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarExpeditionAllDataRsp.java new file mode 100644 index 000000000..e6772f928 --- /dev/null +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarExpeditionAllDataRsp.java @@ -0,0 +1,33 @@ +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.Grasscutter; +import emu.grasscutter.game.expedition.ExpeditionInfo; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AvatarExpeditionAllDataRspOuterClass.AvatarExpeditionAllDataRsp; +import emu.grasscutter.net.proto.AvatarExpeditionInfoOuterClass.AvatarExpeditionInfo; + +import java.util.*; + +public class PacketAvatarExpeditionAllDataRsp extends BasePacket { + public PacketAvatarExpeditionAllDataRsp(Player player) { + super(PacketOpcodes.AvatarExpeditionAllDataRsp); + + List openExpeditionList = new ArrayList<>(List.of(306,305,304,303,302,301,206,105,204,104,203,103,202,101,102,201,106,205)); + Map avatarExpeditionInfoList = new HashMap(); + + var expeditionInfo = player.getExpeditionInfo(); + for (Long key : player.getExpeditionInfo().keySet()) { + ExpeditionInfo e = expeditionInfo.get(key); + avatarExpeditionInfoList.put(key, AvatarExpeditionInfo.newBuilder().setStateValue(e.getState()).setExpId(e.getExpId()).setHourTime(e.getHourTime()).setStartTime(e.getStartTime()).build()); + }; + + AvatarExpeditionAllDataRsp.Builder proto = AvatarExpeditionAllDataRsp.newBuilder() + .addAllOpenExpeditionList(openExpeditionList) + .setExpeditionCountLimit(5) + .putAllExpeditionInfoMap(avatarExpeditionInfoList); + + this.setData(proto.build()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarExpeditionCallBackRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarExpeditionCallBackRsp.java new file mode 100644 index 000000000..30c927bc9 --- /dev/null +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarExpeditionCallBackRsp.java @@ -0,0 +1,23 @@ +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.expedition.ExpeditionInfo; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AvatarExpeditionCallBackRspOuterClass.AvatarExpeditionCallBackRsp; +import emu.grasscutter.net.proto.AvatarExpeditionInfoOuterClass.AvatarExpeditionInfo; + +public class PacketAvatarExpeditionCallBackRsp extends BasePacket { + public PacketAvatarExpeditionCallBackRsp(Player player) { + super(PacketOpcodes.AvatarExpeditionCallBackRsp); + + AvatarExpeditionCallBackRsp.Builder proto = AvatarExpeditionCallBackRsp.newBuilder(); + var expeditionInfo = player.getExpeditionInfo(); + for (Long key : player.getExpeditionInfo().keySet()) { + ExpeditionInfo e = expeditionInfo.get(key); + proto.putExpeditionInfoMap(key, AvatarExpeditionInfo.newBuilder().setStateValue(e.getState()).setExpId(e.getExpId()).setHourTime(e.getHourTime()).setStartTime(e.getStartTime()).build()); + }; + + this.setData(proto.build()); + } +} \ No newline at end of file diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarExpeditionDataNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarExpeditionDataNotify.java new file mode 100644 index 000000000..1fe6bbee0 --- /dev/null +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarExpeditionDataNotify.java @@ -0,0 +1,29 @@ +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.expedition.ExpeditionInfo; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AvatarExpeditionDataNotifyOuterClass.AvatarExpeditionDataNotify; +import emu.grasscutter.net.proto.AvatarExpeditionInfoOuterClass.AvatarExpeditionInfo; + +import java.util.*; + +public class PacketAvatarExpeditionDataNotify extends BasePacket { + public PacketAvatarExpeditionDataNotify(Player player) { + super(PacketOpcodes.AvatarExpeditionDataNotify); + + Map avatarExpeditionInfoList = new HashMap(); + + var expeditionInfo = player.getExpeditionInfo(); + for (Long key : player.getExpeditionInfo().keySet()) { + ExpeditionInfo e = expeditionInfo.get(key); + avatarExpeditionInfoList.put(key, AvatarExpeditionInfo.newBuilder().setStateValue(e.getState()).setExpId(e.getExpId()).setHourTime(e.getHourTime()).setStartTime(e.getStartTime()).build()); + }; + + AvatarExpeditionDataNotify.Builder proto = AvatarExpeditionDataNotify.newBuilder() + .putAllExpeditionInfoMap(avatarExpeditionInfoList); + + this.setData(proto.build()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarExpeditionGetRewardRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarExpeditionGetRewardRsp.java new file mode 100644 index 000000000..34f0ea115 --- /dev/null +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarExpeditionGetRewardRsp.java @@ -0,0 +1,30 @@ +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.expedition.ExpeditionInfo; +import emu.grasscutter.game.inventory.GameItem; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AvatarExpeditionGetRewardRspOuterClass.AvatarExpeditionGetRewardRsp; +import emu.grasscutter.net.proto.AvatarExpeditionInfoOuterClass.AvatarExpeditionInfo; + +import java.util.Collection; + +public class PacketAvatarExpeditionGetRewardRsp extends BasePacket { + public PacketAvatarExpeditionGetRewardRsp(Player player, Collection items) { + super(PacketOpcodes.AvatarExpeditionGetRewardRsp); + + AvatarExpeditionGetRewardRsp.Builder proto = AvatarExpeditionGetRewardRsp.newBuilder(); + var expeditionInfo = player.getExpeditionInfo(); + for (Long key : player.getExpeditionInfo().keySet()) { + ExpeditionInfo e = expeditionInfo.get(key); + proto.putExpeditionInfoMap(key, AvatarExpeditionInfo.newBuilder().setStateValue(e.getState()).setExpId(e.getExpId()).setHourTime(e.getHourTime()).setStartTime(e.getStartTime()).build()); + }; + + for (GameItem item : items) { + proto.addItemList(item.toItemParam()); + } + + this.setData(proto.build()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarExpeditionStartRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarExpeditionStartRsp.java new file mode 100644 index 000000000..9a279124d --- /dev/null +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarExpeditionStartRsp.java @@ -0,0 +1,23 @@ +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.expedition.ExpeditionInfo; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AvatarExpeditionInfoOuterClass.AvatarExpeditionInfo; +import emu.grasscutter.net.proto.AvatarExpeditionStartRspOuterClass.AvatarExpeditionStartRsp; + +public class PacketAvatarExpeditionStartRsp extends BasePacket { + public PacketAvatarExpeditionStartRsp(Player player) { + super(PacketOpcodes.AvatarExpeditionStartRsp); + + AvatarExpeditionStartRsp.Builder proto = AvatarExpeditionStartRsp.newBuilder(); + var expeditionInfo = player.getExpeditionInfo(); + for (Long key : player.getExpeditionInfo().keySet()) { + ExpeditionInfo e = expeditionInfo.get(key); + proto.putExpeditionInfoMap(key, AvatarExpeditionInfo.newBuilder().setStateValue(e.getState()).setExpId(e.getExpId()).setHourTime(e.getHourTime()).setStartTime(e.getStartTime()).build()); + }; + + this.setData(proto.build()); + } +}