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,28 +2,20 @@ 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;
import java.util.Map;
public class PacketAvatarExpeditionGetRewardRsp extends BasePacket {
public PacketAvatarExpeditionGetRewardRsp(Player player, Collection<GameItem> items) {
public PacketAvatarExpeditionGetRewardRsp(Map<Long, ExpeditionInfo> expeditionInfo, Collection<GameItem> 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());
}
expeditionInfo.forEach((key, e) -> proto.putExpeditionInfoMap(key, e.toProto()));
items.forEach(item -> proto.addItemList(item.toItemParam()));
this.setData(proto.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.AvatarExpeditionInfoOuterClass.AvatarExpeditionInfo;
import emu.grasscutter.net.proto.AvatarExpeditionStartRspOuterClass.AvatarExpeditionStartRsp;
public class PacketAvatarExpeditionStartRsp extends BasePacket {
public PacketAvatarExpeditionStartRsp(Player player) {
public PacketAvatarExpeditionStartRsp(Map<Long, ExpeditionInfo> expeditionInfo) {
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());
};
expeditionInfo.forEach((key, e) -> proto.putExpeditionInfoMap(key, e.toProto()));
this.setData(proto.build());
}
......
......@@ -17,7 +17,7 @@ public class PacketGetWidgetSlotRsp extends BasePacket {
GetWidgetSlotRspOuterClass.GetWidgetSlotRsp.Builder proto =
GetWidgetSlotRspOuterClass.GetWidgetSlotRsp.newBuilder();
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(
......
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