mirror of
https://github.com/Melledy/LunarCore.git
synced 2025-12-23 10:44:36 +01:00
General refactoring
This commit is contained in:
@@ -71,8 +71,8 @@ public class CommandArgs {
|
||||
if (this.flags == null) this.flags = new ObjectOpenHashSet<>();
|
||||
this.flags.add(arg);
|
||||
it.remove();
|
||||
} else if (arg.contains(":")) {
|
||||
String[] split = arg.split(":");
|
||||
} else if (arg.contains(":") || arg.contains(",")) {
|
||||
String[] split = arg.split("[:,]");
|
||||
if (split.length >= 2) {
|
||||
int key = Integer.parseInt(split[0]);
|
||||
int value = Integer.parseInt(split[1]);
|
||||
|
||||
@@ -7,7 +7,6 @@ import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import emu.lunarcore.game.enums.PropState;
|
||||
import emu.lunarcore.game.scene.triggers.TriggerOpenTreasureWhenMonsterDie;
|
||||
import emu.lunarcore.game.scene.triggers.TriggerPuzzleCompassWayPointController;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
|
||||
@@ -72,8 +71,6 @@ public class FloorInfo {
|
||||
// Hacky way to setup prop triggers
|
||||
if (json.contains("Maze_GroupProp_OpenTreasure_WhenMonsterDie")) {
|
||||
prop.setTrigger(new TriggerOpenTreasureWhenMonsterDie(group.getId()));
|
||||
} else if (json.contains("Maze_Chap02_X201_Event_PuzzleCompass_WayPoint_Controller")) {
|
||||
prop.setTrigger(new TriggerPuzzleCompassWayPointController(group.getId()));
|
||||
}
|
||||
|
||||
// Clear for garbage collection
|
||||
|
||||
@@ -22,6 +22,10 @@ public class CocoonExcel extends GameResource {
|
||||
public int getId() {
|
||||
return (ID << 8) + WorldLevel;
|
||||
}
|
||||
|
||||
public int getCocoonId() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
public int getRandomStage() {
|
||||
return Utils.randomElement(StageIDList);
|
||||
|
||||
@@ -3,6 +3,7 @@ package emu.lunarcore.game.battle;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import emu.lunarcore.GameConstants;
|
||||
import emu.lunarcore.data.GameData;
|
||||
@@ -12,7 +13,9 @@ import emu.lunarcore.game.inventory.GameItem;
|
||||
import emu.lunarcore.game.player.Player;
|
||||
import emu.lunarcore.game.player.lineup.PlayerLineup;
|
||||
import emu.lunarcore.game.scene.entity.EntityMonster;
|
||||
import emu.lunarcore.proto.BattleEndStatusOuterClass.BattleEndStatus;
|
||||
import emu.lunarcore.proto.BattleEventBattleInfoOuterClass.BattleEventBattleInfo;
|
||||
import emu.lunarcore.proto.BattleStatisticsOuterClass.BattleStatistics;
|
||||
import emu.lunarcore.proto.SceneBattleInfoOuterClass.SceneBattleInfo;
|
||||
import emu.lunarcore.util.Utils;
|
||||
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||
@@ -32,8 +35,10 @@ public class Battle {
|
||||
private final long timestamp;
|
||||
|
||||
private StageExcel stage; // Main battle stage
|
||||
private IntList turnSnapshotList; // TODO maybe turn it into a map?
|
||||
private IntList battleEvents; // TODO maybe turn it into a map?
|
||||
|
||||
// Internal battle data
|
||||
@Setter private BattleEndStatus result;
|
||||
@Setter private int staminaCost;
|
||||
@Setter private int roundsLimit;
|
||||
|
||||
@@ -42,6 +47,9 @@ public class Battle {
|
||||
@Setter private int worldLevel;
|
||||
@Setter private int cocoonWave;
|
||||
|
||||
// OnFinish Callback
|
||||
@Setter private Consumer<BattleStatistics> onFinish;
|
||||
|
||||
private Battle(Player player, PlayerLineup lineup) {
|
||||
this.id = player.getNextBattleId();
|
||||
this.player = player;
|
||||
@@ -54,9 +62,16 @@ public class Battle {
|
||||
}
|
||||
|
||||
public Battle(Player player, PlayerLineup lineup, StageExcel stage) {
|
||||
this(player, lineup, stage, true);
|
||||
}
|
||||
|
||||
public Battle(Player player, PlayerLineup lineup, StageExcel stage, boolean loadStage) {
|
||||
this(player, lineup);
|
||||
this.stage = stage;
|
||||
this.loadStage(stage);
|
||||
|
||||
if (loadStage) {
|
||||
this.loadStage(stage);
|
||||
}
|
||||
}
|
||||
|
||||
public Battle(Player player, PlayerLineup lineup, List<StageExcel> stages) {
|
||||
@@ -122,11 +137,11 @@ public class Battle {
|
||||
}
|
||||
}
|
||||
|
||||
public IntList getTurnSnapshotList() {
|
||||
if (this.turnSnapshotList == null) {
|
||||
this.turnSnapshotList = new IntArrayList();
|
||||
public IntList getBattleEvents() {
|
||||
if (this.battleEvents == null) {
|
||||
this.battleEvents = new IntArrayList();
|
||||
}
|
||||
return this.turnSnapshotList;
|
||||
return this.battleEvents;
|
||||
}
|
||||
|
||||
public void setCustomLevel(int level) {
|
||||
@@ -216,8 +231,8 @@ public class Battle {
|
||||
}
|
||||
|
||||
// Client turn snapshots
|
||||
if (this.turnSnapshotList != null) {
|
||||
for (int id : this.turnSnapshotList) {
|
||||
if (this.battleEvents != null) {
|
||||
for (int id : this.battleEvents) {
|
||||
var event = BattleEventBattleInfo.newInstance()
|
||||
.setBattleEventId(id);
|
||||
|
||||
|
||||
@@ -225,6 +225,7 @@ public class BattleService extends BaseGameService {
|
||||
|
||||
// Get battle object and setup variables
|
||||
Battle battle = player.getBattle();
|
||||
battle.setResult(result);
|
||||
int minimumHp = 0;
|
||||
|
||||
boolean updateStatus = true;
|
||||
@@ -311,6 +312,11 @@ public class BattleService extends BaseGameService {
|
||||
player.getRogueInstance().onBattleFinish(battle, result, stats);
|
||||
}
|
||||
|
||||
// Battle callback
|
||||
if (battle.getOnFinish() != null) {
|
||||
battle.getOnFinish().accept(stats);
|
||||
}
|
||||
|
||||
// Done - Clear battle object from player
|
||||
player.setBattle(null);
|
||||
return battle;
|
||||
|
||||
@@ -29,6 +29,7 @@ import emu.lunarcore.game.chat.ChatManager;
|
||||
import emu.lunarcore.game.chat.ChatMessage;
|
||||
import emu.lunarcore.game.enums.PlaneType;
|
||||
import emu.lunarcore.game.enums.PropState;
|
||||
import emu.lunarcore.game.enums.PropType;
|
||||
import emu.lunarcore.game.friends.FriendList;
|
||||
import emu.lunarcore.game.friends.Friendship;
|
||||
import emu.lunarcore.game.gacha.PlayerGachaInfo;
|
||||
@@ -46,7 +47,6 @@ import emu.lunarcore.game.scene.Scene;
|
||||
import emu.lunarcore.game.scene.SceneBuff;
|
||||
import emu.lunarcore.game.scene.entity.EntityProp;
|
||||
import emu.lunarcore.game.scene.entity.GameEntity;
|
||||
import emu.lunarcore.game.scene.triggers.PropTriggerType;
|
||||
import emu.lunarcore.proto.BoardDataSyncOuterClass.BoardDataSync;
|
||||
import emu.lunarcore.proto.FriendOnlineStatusOuterClass.FriendOnlineStatus;
|
||||
import emu.lunarcore.proto.HeadIconOuterClass.HeadIcon;
|
||||
@@ -606,15 +606,16 @@ public class Player implements Tickable {
|
||||
|
||||
// Save old state
|
||||
PropState oldState = prop.getState();
|
||||
PropState newState = interactExcel.getTargetState();
|
||||
|
||||
// Set group and prop state
|
||||
this.sendPacket(new PacketGroupStateChangeScNotify(getEntryId(), prop.getGroupId(), interactExcel.getTargetState()));
|
||||
prop.setState(interactExcel.getTargetState());
|
||||
this.sendPacket(new PacketGroupStateChangeScNotify(getEntryId(), prop.getGroupId(), newState));
|
||||
prop.setState(newState);
|
||||
|
||||
// Handle any extra interaction actions
|
||||
switch (prop.getExcel().getPropType()) {
|
||||
case PROP_TREASURE_CHEST -> {
|
||||
if (oldState == PropState.ChestClosed && prop.getState() == PropState.ChestUsed) {
|
||||
if (oldState == PropState.ChestClosed && newState == PropState.ChestUsed) {
|
||||
// Handle drops
|
||||
var drops = this.getServer().getDropService().calculateDropsFromProp(prop.getPropId());
|
||||
this.getInventory().addItems(drops, true);
|
||||
@@ -622,10 +623,21 @@ public class Player implements Tickable {
|
||||
}
|
||||
case PROP_MAZE_PUZZLE -> {
|
||||
// Trigger event
|
||||
this.getScene().invokePropTrigger(PropTriggerType.PUZZLE_FINISH, prop.getGroupId(), prop.getInstId());
|
||||
if (newState == PropState.Open || newState == PropState.Closed) {
|
||||
// Unlock everything in the prop's group
|
||||
for (var p : getScene().getEntitiesByGroup(EntityProp.class, prop.getGroupId())) {
|
||||
if (p.getPropType() == PropType.PROP_TREASURE_CHEST) {
|
||||
p.setState(PropState.ChestClosed);
|
||||
} else if (p.getPropType() == PropType.PROP_MAZE_PUZZLE) {
|
||||
// Skip
|
||||
} else {
|
||||
p.setState(PropState.Open);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
default -> {
|
||||
|
||||
// Skip
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package emu.lunarcore.game.player.lineup;
|
||||
|
||||
import emu.lunarcore.game.player.Player;
|
||||
|
||||
public class PlayerTempLineup extends PlayerExtraLineup {
|
||||
|
||||
public PlayerTempLineup(Player player) {
|
||||
super(player, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
// Ignored
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete() {
|
||||
// Ignored
|
||||
}
|
||||
}
|
||||
@@ -325,7 +325,7 @@ public class RogueInstance {
|
||||
if (buff.getExcel().getBattleEventBuffType() == RogueBuffAeonType.BattleEventBuff) {
|
||||
RogueBuffType type = RogueBuffType.getById(getAeonBuffType());
|
||||
if (type != null && type.getBattleEventSkill() != 0) {
|
||||
battle.getTurnSnapshotList().add(type.getBattleEventSkill());
|
||||
battle.getBattleEvents().add(type.getBattleEventSkill());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import emu.lunarcore.data.config.GroupInfo;
|
||||
import emu.lunarcore.data.config.PropInfo;
|
||||
import emu.lunarcore.data.excel.PropExcel;
|
||||
import emu.lunarcore.game.enums.PropState;
|
||||
import emu.lunarcore.game.enums.PropType;
|
||||
import emu.lunarcore.game.scene.Scene;
|
||||
import emu.lunarcore.game.scene.entity.extra.PropRogueData;
|
||||
import emu.lunarcore.proto.MotionInfoOuterClass.MotionInfo;
|
||||
@@ -54,6 +55,10 @@ public class EntityProp implements GameEntity {
|
||||
return excel.getId();
|
||||
}
|
||||
|
||||
public PropType getPropType() {
|
||||
return getExcel().getPropType();
|
||||
}
|
||||
|
||||
public boolean setState(PropState state) {
|
||||
return this.setState(state, this.getScene().isLoaded());
|
||||
}
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
package emu.lunarcore.game.scene.triggers;
|
||||
|
||||
import emu.lunarcore.game.enums.PropState;
|
||||
import emu.lunarcore.game.scene.Scene;
|
||||
import emu.lunarcore.game.scene.entity.EntityProp;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public class TriggerPuzzleCompassWayPointController extends PropTrigger {
|
||||
private int groupId;
|
||||
|
||||
public TriggerPuzzleCompassWayPointController(int groupId) {
|
||||
this.groupId = groupId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PropTriggerType getType() {
|
||||
return PropTriggerType.PUZZLE_FINISH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldRun(int groupId, int instId) {
|
||||
return this.groupId == groupId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(Scene scene) {
|
||||
for (var prop : scene.getEntitiesByGroup(EntityProp.class, groupId)) {
|
||||
prop.setState(PropState.Open);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,10 +14,10 @@ public class HandlerGroupStateChangeCsReq extends PacketHandler {
|
||||
@Override
|
||||
public void handle(GameSession session, byte[] data) throws Exception {
|
||||
var req = GroupStateChangeCsReq.parseFrom(data);
|
||||
var groupInfo = req.getMutableGroupInfo();
|
||||
var groupStateInfo = req.getMutableGroupStateInfo();
|
||||
|
||||
session.send(new PacketGroupStateChangeScNotify(groupInfo));
|
||||
session.send(new PacketGroupStateChangeScRsp(groupInfo));
|
||||
session.send(new PacketGroupStateChangeScNotify(groupStateInfo));
|
||||
session.send(new PacketGroupStateChangeScRsp(groupStateInfo));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ public class PacketGroupStateChangeScNotify extends BasePacket {
|
||||
super(CmdId.GroupStateChangeScNotify);
|
||||
|
||||
var data = GroupStateChangeScNotify.newInstance();
|
||||
data.setGroupInfo(groupInfo);
|
||||
data.setGroupStateInfo(groupInfo);
|
||||
|
||||
this.setData(data);
|
||||
}
|
||||
@@ -22,7 +22,7 @@ public class PacketGroupStateChangeScNotify extends BasePacket {
|
||||
|
||||
var data = GroupStateChangeScNotify.newInstance();
|
||||
|
||||
data.getMutableGroupInfo()
|
||||
data.getMutableGroupStateInfo()
|
||||
.setEntryId(entryId)
|
||||
.setGroupId(groupId)
|
||||
.setGroupState(state.getVal());
|
||||
|
||||
@@ -11,7 +11,7 @@ public class PacketGroupStateChangeScRsp extends BasePacket {
|
||||
super(CmdId.GroupStateChangeScRsp);
|
||||
|
||||
var data = GroupStateChangeScNotify.newInstance();
|
||||
data.setGroupInfo(groupInfo);
|
||||
data.setGroupStateInfo(groupInfo);
|
||||
|
||||
this.setData(data);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user