Commit dc9cef8a authored by Luke H-W's avatar Luke H-W Committed by GitHub
Browse files

Refactoring (#1660)



* Refactor a couple of iterators

* Use side-effect instead of second iterator

* Make World::onTick return shouldDelete instead of success

* Replace Shop iterator with side effects

* Scene

* Clean up Expeditions

* Refactor Expeditions

* Clean up Expeditions, Player

* Limit Expeditions by AR

* Lombokify props
Co-authored-by: default avatarAnimeGitB <AnimeGitB@bigblueball.in>
parent bccf516c
......@@ -2,32 +2,20 @@ package emu.grasscutter.data.excels;
import emu.grasscutter.data.GameResource;
import emu.grasscutter.data.ResourceType;
import lombok.Getter;
@ResourceType(name = "PlayerLevelExcelConfigData.json")
@Getter
public class PlayerLevelData extends GameResource {
private int level;
private int exp;
private int rewardId;
private int expeditionLimitAdd = 0;
private int unlockWorldLevel;
private long unlockDescTextMapHash;
@Override
public int getId() {
return this.level;
}
public int getLevel() {
return level;
}
public int getExp() {
return exp;
}
public int getRewardId() {
return rewardId;
}
public int getUnlockWorldLevel() {
return unlockWorldLevel;
}
}
package emu.grasscutter.game.expedition;
import dev.morphia.annotations.Entity;
import emu.grasscutter.net.proto.AvatarExpeditionInfoOuterClass.AvatarExpeditionInfo;
import lombok.Getter;
import lombok.Setter;
@Entity
@Getter @Setter
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;
public AvatarExpeditionInfo toProto() {
return AvatarExpeditionInfo.newBuilder()
.setStateValue(this.getState())
.setExpId(this.getExpId())
.setHourTime(this.getHourTime())
.setStartTime(this.getStartTime())
.build();
}
}
package emu.grasscutter.game.expedition;
public class ExpeditionRewardData {
private int itemId;
private int minCount;
private int maxCount;
public int getItemId() {
return itemId;
}
import emu.grasscutter.game.inventory.GameItem;
import emu.grasscutter.utils.Utils;
import lombok.Getter;
public int getMinCount() { return minCount; }
public class ExpeditionRewardData {
@Getter private int itemId;
@Getter private int minCount;
@Getter private int maxCount;
public int getMaxCount() {
return maxCount;
public GameItem getReward() {
return new GameItem(itemId, Utils.randomRange(minCount, maxCount));
}
}
package emu.grasscutter.game.expedition;
import java.util.ArrayList;
import java.util.List;
import emu.grasscutter.game.inventory.GameItem;
import lombok.Getter;
public class ExpeditionRewardDataList {
public int getHourTime() {
return hourTime;
}
public List<ExpeditionRewardData> getExpeditionRewardData() {
return expeditionRewardData;
}
@Getter private int hourTime;
@Getter private List<ExpeditionRewardData> expeditionRewardData;
private int hourTime;
private List<ExpeditionRewardData> expeditionRewardData;
public List<GameItem> getRewards() {
List<GameItem> rewards = new ArrayList<>();
if (expeditionRewardData != null) {
expeditionRewardData.forEach(data -> rewards.add(data.getReward()));
}
return rewards;
}
}
......@@ -2,15 +2,9 @@ package emu.grasscutter.game.expedition;
import java.util.List;
public class ExpeditionRewardInfo {
public int getExpId() {
return expId;
}
public List<ExpeditionRewardDataList> getExpeditionRewardDataList() {
return expeditionRewardDataList;
}
import lombok.Getter;
private int expId;
private List<ExpeditionRewardDataList> expeditionRewardDataList;
public class ExpeditionRewardInfo {
@Getter private int expId;
@Getter private List<ExpeditionRewardDataList> expeditionRewardDataList;
}
......@@ -4,6 +4,7 @@ import java.util.stream.Stream;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import lombok.Getter;
public enum PlayerProperty {
PROP_NONE (0),
......@@ -53,8 +54,8 @@ public enum PlayerProperty {
PROP_PLAYER_WAIT_SUB_HOME_COIN (10043);
private static final int inf = Integer.MAX_VALUE; // Maybe this should be something else?
private final int id, min, max;
private final boolean dynamicRange;
@Getter private final int id, min, max;
@Getter private final boolean dynamicRange;
private static final Int2ObjectMap<PlayerProperty> map = new Int2ObjectOpenHashMap<>();
static {
......@@ -84,22 +85,6 @@ public enum PlayerProperty {
this(id, Integer.MIN_VALUE, inf, dynamicRange);
}
public int getId() {
return this.id;
}
public int getMin() {
return this.min;
}
public int getMax() {
return this.max;
}
public boolean getDynamicRange() {
return dynamicRange;
}
public static PlayerProperty getPropById(int value) {
return map.getOrDefault(value, null);
}
......
......@@ -2,26 +2,28 @@ package emu.grasscutter.game.shop;
import emu.grasscutter.data.common.ItemParamData;
import emu.grasscutter.data.excels.ShopGoodsData;
import lombok.Getter;
import lombok.Setter;
import java.util.ArrayList;
import java.util.List;
public class ShopInfo {
private int goodsId = 0;
private ItemParamData goodsItem;
private int scoin = 0;
private List<ItemParamData> costItemList;
private int boughtNum = 0;
private int buyLimit = 0;
private int beginTime = 0;
private int endTime = 1924992000;
private int minLevel = 0;
private int maxLevel = 61;
private List<Integer> preGoodsIdList = new ArrayList<>();
private int mcoin = 0;
private int hcoin = 0;
private int disableType = 0;
private int secondarySheetId = 0;
@Getter @Setter private int goodsId = 0;
@Getter @Setter private ItemParamData goodsItem;
@Getter @Setter private int scoin = 0;
@Getter @Setter private List<ItemParamData> costItemList;
@Getter @Setter private int boughtNum = 0;
@Getter @Setter private int buyLimit = 0;
@Getter @Setter private int beginTime = 0;
@Getter @Setter private int endTime = 1924992000;
@Getter @Setter private int minLevel = 0;
@Getter @Setter private int maxLevel = 61;
@Getter @Setter private List<Integer> preGoodsIdList = new ArrayList<>();
@Getter @Setter private int mcoin = 0;
@Getter @Setter private int hcoin = 0;
@Getter @Setter private int disableType = 0;
@Getter @Setter private int secondarySheetId = 0;
private String refreshType;
......@@ -41,8 +43,8 @@ public class ShopInfo {
}
}
private transient ShopRefreshType shopRefreshType;
private int shopRefreshParam;
@Setter private transient ShopRefreshType shopRefreshType;
@Getter @Setter private int shopRefreshParam;
public ShopInfo(ShopGoodsData sgd) {
this.goodsId = sgd.getGoodsId();
......@@ -60,126 +62,6 @@ public class ShopInfo {
this.shopRefreshParam = sgd.getRefreshParam();
}
public int getHcoin() {
return hcoin;
}
public void setHcoin(int hcoin) {
this.hcoin = hcoin;
}
public List<Integer> getPreGoodsIdList() {
return preGoodsIdList;
}
public void setPreGoodsIdList(List<Integer> preGoodsIdList) {
this.preGoodsIdList = preGoodsIdList;
}
public int getMcoin() {
return mcoin;
}
public void setMcoin(int mcoin) {
this.mcoin = mcoin;
}
public int getDisableType() {
return disableType;
}
public void setDisableType(int disableType) {
this.disableType = disableType;
}
public int getSecondarySheetId() {
return secondarySheetId;
}
public void setSecondarySheetId(int secondarySheetId) {
this.secondarySheetId = secondarySheetId;
}
public int getGoodsId() {
return goodsId;
}
public void setGoodsId(int goodsId) {
this.goodsId = goodsId;
}
public ItemParamData getGoodsItem() {
return goodsItem;
}
public void setGoodsItem(ItemParamData goodsItem) {
this.goodsItem = goodsItem;
}
public int getScoin() {
return scoin;
}
public void setScoin(int scoin) {
this.scoin = scoin;
}
public List<ItemParamData> getCostItemList() {
return costItemList;
}
public void setCostItemList(List<ItemParamData> costItemList) {
this.costItemList = costItemList;
}
public int getBoughtNum() {
return boughtNum;
}
public void setBoughtNum(int boughtNum) {
this.boughtNum = boughtNum;
}
public int getBuyLimit() {
return buyLimit;
}
public void setBuyLimit(int buyLimit) {
this.buyLimit = buyLimit;
}
public int getBeginTime() {
return beginTime;
}
public void setBeginTime(int beginTime) {
this.beginTime = beginTime;
}
public int getEndTime() {
return endTime;
}
public void setEndTime(int endTime) {
this.endTime = endTime;
}
public int getMinLevel() {
return minLevel;
}
public void setMinLevel(int minLevel) {
this.minLevel = minLevel;
}
public int getMaxLevel() {
return maxLevel;
}
public void setMaxLevel(int maxLevel) {
this.maxLevel = maxLevel;
}
public ShopRefreshType getShopRefreshType() {
if (refreshType == null)
return ShopRefreshType.NONE;
......@@ -191,15 +73,16 @@ public class ShopInfo {
};
}
public void setShopRefreshType(ShopRefreshType shopRefreshType) {
this.shopRefreshType = shopRefreshType;
}
public int getShopRefreshParam() {
return shopRefreshParam;
private boolean evaluateVirtualCost(ItemParamData item) {
return switch (item.getId()) {
case 201 -> {this.hcoin += item.getCount(); yield true;}
case 203 -> {this.mcoin += item.getCount(); yield true;}
default -> false;
};
}
public void setShopRefreshParam(int shopRefreshParam) {
this.shopRefreshParam = shopRefreshParam;
public void removeVirtualCosts() {
if (this.costItemList != null)
this.costItemList.removeIf(item -> evaluateVirtualCost(item));
}
}
......@@ -3,7 +3,6 @@ package emu.grasscutter.game.shop;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.data.DataLoader;
import emu.grasscutter.data.GameData;
import emu.grasscutter.data.common.ItemParamData;
import emu.grasscutter.data.excels.ShopGoodsData;
import emu.grasscutter.server.game.BaseGameSystem;
import emu.grasscutter.server.game.GameServer;
......@@ -14,7 +13,6 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import static emu.grasscutter.config.Configuration.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class ShopSystem extends BaseGameSystem {
......@@ -60,22 +58,7 @@ public class ShopSystem extends BaseGameSystem {
List<ShopTable> banners = DataLoader.loadList("Shop.json", ShopTable.class);
if (banners.size() > 0) {
for (ShopTable shopTable : banners) {
for (ShopInfo cost : shopTable.getItems()) {
if (cost.getCostItemList() != null) {
Iterator<ItemParamData> iterator = cost.getCostItemList().iterator();
while (iterator.hasNext()) {
ItemParamData ipd = iterator.next();
if (ipd.getId() == 201) {
cost.setHcoin(cost.getHcoin() + ipd.getCount());
iterator.remove();
}
if (ipd.getId() == 203) {
cost.setMcoin(cost.getMcoin() + ipd.getCount());
iterator.remove();
}
}
}
}
shopTable.getItems().forEach(ShopInfo::removeVirtualCosts);
getShopData().put(shopTable.getShopId(), shopTable.getItems());
}
Grasscutter.getLogger().debug("Shop data successfully loaded.");
......
......@@ -28,6 +28,7 @@ import emu.grasscutter.utils.Position;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.stream.Collectors;
public class Scene {
private final World world;
......@@ -261,12 +262,11 @@ public class Scene {
}
}
private void removePlayerAvatars(Player player) {
Iterator<EntityAvatar> it = player.getTeamManager().getActiveTeam().iterator();
while (it.hasNext()) {
this.removeEntity(it.next(), VisionType.VISION_TYPE_REMOVE);
it.remove();
}
private synchronized void removePlayerAvatars(Player player) {
var team = player.getTeamManager().getActiveTeam();
// removeEntities(team, VisionType.VISION_TYPE_REMOVE); // List<SubType> isn't cool apparently :(
team.forEach(e -> removeEntity(e, VisionType.VISION_TYPE_REMOVE));
team.clear();
}
public void spawnPlayer(Player player) {
......@@ -567,40 +567,40 @@ public class Scene {
return SceneIndexManager.queryNeighbors(getScriptManager().getBlocksIndex(),
player.getPosition().toXZDoubleArray(), Grasscutter.getConfig().server.game.loadEntitiesForPlayerRange);
}
public void checkBlocks() {
Set<SceneBlock> visible = new HashSet<>();
for (Player player : this.getPlayers()) {
var blocks = getPlayerActiveBlocks(player);
visible.addAll(blocks);
}
Iterator<SceneBlock> it = this.getLoadedBlocks().iterator();
while (it.hasNext()) {
SceneBlock block = it.next();
private boolean unloadBlockIfNotVisible(Collection<SceneBlock> visible, SceneBlock block) {
if (visible.contains(block)) return false;
this.onUnloadBlock(block);
return true;
}
if (!visible.contains(block)) {
it.remove();
private synchronized boolean loadBlock(SceneBlock block) {
if (this.loadedBlocks.contains(block)) return false;
this.onLoadBlock(block, this.players);
this.loadedBlocks.add(block);
return true;
}
onUnloadBlock(block);
}
}
public synchronized void checkBlocks() {
Set<SceneBlock> visible = this.players.stream()
.map(player -> this.getPlayerActiveBlocks(player))
.flatMap(Collection::stream)
.collect(Collectors.toSet());
for (var block : visible) {
if (!this.getLoadedBlocks().contains(block)) {
this.onLoadBlock(block, this.getPlayers());
this.getLoadedBlocks().add(block);
}else {
this.loadedBlocks.removeIf(block -> unloadBlockIfNotVisible(visible, block));
visible.stream()
.filter(block -> !this.loadBlock(block))
.forEach(block -> {
// dynamic load the groups for players in a loaded block
var toLoad = this.getPlayers().stream()
.filter(p -> block.contains(p.getPosition()))
.map(p -> playerMeetGroups(p, block))
.flatMap(Collection::stream)
.toList();
onLoadGroup(toLoad);
}
}
var toLoad = this.players.stream()
.filter(p -> block.contains(p.getPosition()))
.map(p -> this.playerMeetGroups(p, block))
.flatMap(Collection::stream)
.toList();
this.onLoadGroup(toLoad);
});
}
public List<SceneGroup> playerMeetGroups(Player player, SceneBlock block) {
List<SceneGroup> sceneGroups = SceneIndexManager.queryNeighbors(block.sceneGroupIndex, player.getPosition().toDoubleArray(),
Grasscutter.getConfig().server.game.loadEntitiesForPlayerRange);
......
......@@ -330,10 +330,11 @@ public class World implements Iterable<Player> {
}
}
public void onTick() {
for (Scene scene : this.getScenes().values()) {
scene.onTick();
}
// Returns true if the world should be deleted
public boolean onTick() {
if (this.getPlayerCount() == 0) return true;
this.scenes.forEach((k, scene) -> scene.onTick());
return false;
}
public void close() {
......
......@@ -218,21 +218,10 @@ public final class GameServer extends KcpServer {
var tickStart = Instant.now();
// Tick worlds.
Iterator<World> it = this.getWorlds().iterator();
while (it.hasNext()) {
World world = it.next();
if (world.getPlayerCount() == 0) {
it.remove();
}
world.onTick();
}
this.worlds.removeIf(World::onTick);
// Tick players.
for (Player player : this.getPlayers().values()) {
player.onTick();
}
this.players.values().forEach(Player::onTick);
// Tick scheduler.
this.getScheduler().runTasks();
......
......@@ -10,6 +10,7 @@ import emu.grasscutter.server.packet.send.PacketAvatarExpeditionAllDataRsp;
public class HandlerAvatarExpeditionAllDataReq extends PacketHandler {
@Override
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
session.send(new PacketAvatarExpeditionAllDataRsp(session.getPlayer()));
var player = session.getPlayer();
session.send(new PacketAvatarExpeditionAllDataRsp(player.getExpeditionInfo(), player.getExpeditionLimit()));
}
}
......@@ -6,20 +6,19 @@ 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);
var player = session.getPlayer();
for (int i = 0; i < req.getAvatarGuidCount(); i++) {
session.getPlayer().removeExpeditionInfo(req.getAvatarGuid(i));
player.removeExpeditionInfo(req.getAvatarGuid(i));
}
session.getPlayer().save();
session.send(new PacketAvatarExpeditionCallBackRsp(session.getPlayer()));
player.save();
session.send(new PacketAvatarExpeditionCallBackRsp(player.getExpeditionInfo()));
}
}
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)
......@@ -29,33 +20,25 @@ public class HandlerAvatarExpeditionGetRewardReq extends PacketHandler {
@Override
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
AvatarExpeditionGetRewardReq req = AvatarExpeditionGetRewardReq.parseFrom(payload);
var player = session.getPlayer();
ExpeditionInfo expInfo = session.getPlayer().getExpeditionInfo(req.getAvatarGuid());
List<GameItem> items = new LinkedList<>();
if (session.getServer().getExpeditionSystem().getExpeditionRewardDataList().containsKey(expInfo.getExpId())) {
for (ExpeditionRewardDataList RewardDataList : session.getServer().getExpeditionSystem().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));
}
}
}
}
ExpeditionInfo expInfo = player.getExpeditionInfo(req.getAvatarGuid());
List<GameItem> items = new ArrayList<>();
List<ExpeditionRewardDataList> expeditionRewardDataLists = session.getServer().getExpeditionSystem().getExpeditionRewardDataList().get(expInfo.getExpId());
if (expeditionRewardDataLists != null) {
expeditionRewardDataLists.stream()
.filter(r -> r.getHourTime() == expInfo.getHourTime())
.map(ExpeditionRewardDataList::getRewards)
.forEach(items::addAll);
}
session.getPlayer().getInventory().addItems(items);
session.getPlayer().sendPacket(new PacketItemAddHintNotify(items, ActionReason.ExpeditionReward));
player.getInventory().addItems(items);
player.sendPacket(new PacketItemAddHintNotify(items, ActionReason.ExpeditionReward));
session.getPlayer().removeExpeditionInfo(req.getAvatarGuid());
session.getPlayer().save();
session.send(new PacketAvatarExpeditionGetRewardRsp(session.getPlayer(), items));
player.removeExpeditionInfo(req.getAvatarGuid());
player.save();
session.send(new PacketAvatarExpeditionGetRewardRsp(player.getExpeditionInfo(), items));
}
}
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;
......@@ -14,10 +13,11 @@ public class HandlerAvatarExpeditionStartReq extends PacketHandler {
@Override
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
AvatarExpeditionStartReq req = AvatarExpeditionStartReq.parseFrom(payload);
var player = session.getPlayer();
int startTime = Utils.getCurrentSeconds();
session.getPlayer().addExpeditionInfo(req.getAvatarGuid(), req.getExpId(), req.getHourTime(), startTime);
session.getPlayer().save();
session.send(new PacketAvatarExpeditionStartRsp(session.getPlayer()));
player.addExpeditionInfo(req.getAvatarGuid(), req.getExpId(), req.getHourTime(), startTime);
player.save();
session.send(new PacketAvatarExpeditionStartRsp(player.getExpeditionInfo()));
}
}
......@@ -33,7 +33,7 @@ public class PacketAllWidgetDataNotify extends BasePacket {
// Good luck, my boy.
.addAllNormalCoolDownDataList(List.of());
if (player.getWidgetId() == null) {
if (player.getWidgetId() == 0) { // TODO: check this logic later, it was null-checking an int before which made it dead code
proto.addAllSlotList(List.of());
} else {
proto.addSlotList(
......
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.*;
import java.util.stream.Collectors;
public class PacketAvatarExpeditionAllDataRsp extends BasePacket {
public PacketAvatarExpeditionAllDataRsp(Player player) {
public PacketAvatarExpeditionAllDataRsp(Map<Long, ExpeditionInfo> expeditionInfo, int expeditionCountLimit) {
super(PacketOpcodes.AvatarExpeditionAllDataRsp);
List<Integer> openExpeditionList = new ArrayList<>(List.of(306,305,304,303,302,301,206,105,204,104,203,103,202,101,102,201,106,205));
Map<Long, AvatarExpeditionInfo> avatarExpeditionInfoList = new HashMap<Long, AvatarExpeditionInfo>();
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());
this.setData(AvatarExpeditionAllDataRsp.newBuilder()
.addAllOpenExpeditionList(openExpeditionList)
.setExpeditionCountLimit(expeditionCountLimit)
.putAllExpeditionInfoMap(
expeditionInfo.entrySet().stream()
.collect(Collectors.toMap(
e -> e.getKey(),
e -> e.getValue().toProto())))
.build());
}
}
package emu.grasscutter.server.packet.send;
import java.util.Map;
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) {
public PacketAvatarExpeditionCallBackRsp(Map<Long, ExpeditionInfo> expeditionInfo) {
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());
};
expeditionInfo.forEach((key, e) -> proto.putExpeditionInfoMap(key, e.toProto()));
this.setData(proto.build());
}
......
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.*;
import java.util.stream.Collectors;
public class PacketAvatarExpeditionDataNotify extends BasePacket {
public PacketAvatarExpeditionDataNotify(Player player) {
public PacketAvatarExpeditionDataNotify(Map<Long, ExpeditionInfo> expeditionInfo) {
super(PacketOpcodes.AvatarExpeditionDataNotify);
Map<Long, AvatarExpeditionInfo> avatarExpeditionInfoList = new HashMap<Long, AvatarExpeditionInfo>();
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());
this.setData(AvatarExpeditionDataNotify.newBuilder()
.putAllExpeditionInfoMap(
expeditionInfo.entrySet().stream()
.collect(Collectors.toMap(
e -> e.getKey(),
e -> e.getValue().toProto())))
.build()
);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment