Implement those compass puzzles

This commit is contained in:
Melledy
2023-10-07 08:38:34 -07:00
parent 571148d7d4
commit 380ec3dbc7
10 changed files with 103 additions and 8 deletions

View File

@@ -7,6 +7,7 @@ import com.google.gson.annotations.SerializedName;
import emu.lunarcore.game.enums.PropState; import emu.lunarcore.game.enums.PropState;
import emu.lunarcore.game.scene.triggers.TriggerOpenTreasureWhenMonsterDie; 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.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
@@ -68,6 +69,8 @@ public class FloorInfo {
// Hacky way to setup prop triggers // Hacky way to setup prop triggers
if (json.contains("Maze_GroupProp_OpenTreasure_WhenMonsterDie")) { if (json.contains("Maze_GroupProp_OpenTreasure_WhenMonsterDie")) {
prop.setTrigger(new TriggerOpenTreasureWhenMonsterDie(group.getId())); prop.setTrigger(new TriggerOpenTreasureWhenMonsterDie(group.getId()));
} else if (json.contains("Maze_Chap02_X201_Event_PuzzleCompass_WayPoint_Controller_01")) {
prop.setTrigger(new TriggerPuzzleCompassWayPointController(prop.getSharedValueByKey("PuzzleCompass_Prop"), prop.getSharedValueByKey("PuzzleChest_Prop")));
} }
prop.setInitLevelGraph(null); prop.setInitLevelGraph(null);

View File

@@ -1,5 +1,7 @@
package emu.lunarcore.data.config; package emu.lunarcore.data.config;
import java.util.List;
import emu.lunarcore.game.enums.PropState; import emu.lunarcore.game.enums.PropState;
import emu.lunarcore.game.scene.triggers.PropTrigger; import emu.lunarcore.game.scene.triggers.PropTrigger;
import lombok.Getter; import lombok.Getter;
@@ -16,10 +18,33 @@ public class PropInfo extends ObjectInfo {
private int EventID; private int EventID;
private int CocoonID; private int CocoonID;
private int FarmElementID; private int FarmElementID;
private int ChestID; private PropValueSource ValueSource;
@Setter private String InitLevelGraph; @Setter private String InitLevelGraph;
@Setter private PropState State = PropState.Closed; @Setter private PropState State = PropState.Closed;
@Setter private transient PropTrigger trigger; @Setter private transient PropTrigger trigger;
public String getSharedValueByKey(String key) {
if (this.getValueSource() == null) return null;
var value = getValueSource().getValues().stream().filter(v -> key.equals(v.Key)).findFirst().orElse(null);
if (value != null) {
return value.getValue();
}
return null;
}
@Getter
public static class PropValueSource {
private List<PropSharedValue> Values;
}
@Getter
public static class PropSharedValue {
private String Key;
private String Value;
}
} }

View File

@@ -28,6 +28,7 @@ import emu.lunarcore.game.inventory.Inventory;
import emu.lunarcore.game.scene.Scene; import emu.lunarcore.game.scene.Scene;
import emu.lunarcore.game.scene.entity.EntityProp; import emu.lunarcore.game.scene.entity.EntityProp;
import emu.lunarcore.game.scene.entity.GameEntity; import emu.lunarcore.game.scene.entity.GameEntity;
import emu.lunarcore.game.scene.triggers.PropTriggerType;
import emu.lunarcore.proto.BoardDataSyncOuterClass.BoardDataSync; import emu.lunarcore.proto.BoardDataSyncOuterClass.BoardDataSync;
import emu.lunarcore.proto.HeadIconOuterClass.HeadIcon; import emu.lunarcore.proto.HeadIconOuterClass.HeadIcon;
import emu.lunarcore.proto.PlayerBasicInfoOuterClass.PlayerBasicInfo; import emu.lunarcore.proto.PlayerBasicInfoOuterClass.PlayerBasicInfo;
@@ -332,6 +333,8 @@ public class Player {
EntityProp prop = null; EntityProp prop = null;
if (entity instanceof EntityProp) { if (entity instanceof EntityProp) {
prop = (EntityProp) entity; prop = (EntityProp) entity;
} else {
return null;
} }
// Handle prop interaction action // Handle prop interaction action
@@ -346,6 +349,14 @@ public class Player {
return null; return null;
} }
} }
case PROP_MAZE_PUZZLE -> {
// Finish puzzle
prop.setState(PropState.Locked);
// Trigger event
this.getScene().fireTrigger(PropTriggerType.PUZZLE_FINISH, prop.getGroupId(), prop.getInstId());
//
return prop;
}
default -> { default -> {
return null; return null;
} }

View File

@@ -253,9 +253,9 @@ public class Scene {
} }
// TODO // TODO
public void fireTrigger(PropTriggerType type, int param) { public void fireTrigger(PropTriggerType type, int param1, int param2) {
for (PropTrigger trigger : this.getTriggers()) { for (PropTrigger trigger : this.getTriggers()) {
if (trigger.shouldRun(param)) { if (trigger.shouldRun(param1, param2)) {
trigger.run(this); trigger.run(this);
} }
} }

View File

@@ -44,7 +44,7 @@ public class EntityMonster implements GameEntity {
@Override @Override
public void onRemove() { public void onRemove() {
// Try to fire any triggers // Try to fire any triggers
getScene().fireTrigger(PropTriggerType.MONSTER_DIE, this.getGroupId()); getScene().fireTrigger(PropTriggerType.MONSTER_DIE, this.getGroupId(), this.getInstId());
} }
@Override @Override

View File

@@ -69,4 +69,8 @@ public class EntityProp implements GameEntity {
return proto; return proto;
} }
@Override
public String toString() {
return "Prop: " + this.getEntityId() + ", Group: " + this.groupId + ", Inst: " + this.getInstId();
}
} }

View File

@@ -6,7 +6,7 @@ public abstract class PropTrigger {
public abstract PropTriggerType getType(); public abstract PropTriggerType getType();
public abstract boolean shouldRun(int param); public abstract boolean shouldRun(int groupId, int instId);
public abstract void run(Scene scene); public abstract void run(Scene scene);

View File

@@ -1,5 +1,5 @@
package emu.lunarcore.game.scene.triggers; package emu.lunarcore.game.scene.triggers;
public enum PropTriggerType { public enum PropTriggerType {
MONSTER_DIE; MONSTER_DIE, PUZZLE_FINISH;
} }

View File

@@ -21,8 +21,8 @@ public class TriggerOpenTreasureWhenMonsterDie extends PropTrigger {
} }
@Override @Override
public boolean shouldRun(int param) { public boolean shouldRun(int groupId, int instId) {
return this.groupId == param; return this.groupId == groupId;
} }
@Override @Override

View File

@@ -0,0 +1,52 @@
package emu.lunarcore.game.scene.triggers;
import emu.lunarcore.game.enums.PropState;
import emu.lunarcore.game.enums.PropType;
import emu.lunarcore.game.scene.Scene;
import emu.lunarcore.game.scene.entity.EntityProp;
import emu.lunarcore.game.scene.entity.GameEntity;
import emu.lunarcore.util.Utils;
import lombok.Getter;
@Getter
public class TriggerPuzzleCompassWayPointController extends PropTrigger {
private int groupId;
private int puzzleInstId;
private int chestInstId;
public TriggerPuzzleCompassWayPointController(String compassKey, String chestKey) {
String[] compass = compassKey.split(",");
String[] chest = chestKey.split(",");
this.groupId = Utils.parseSafeInt(compass[0]);
this.puzzleInstId = Utils.parseSafeInt(compass[1]);
this.chestInstId = Utils.parseSafeInt(chest[1]);
}
@Override
public PropTriggerType getType() {
return PropTriggerType.PUZZLE_FINISH;
}
@Override
public boolean shouldRun(int groupId, int instId) {
return this.groupId == groupId && this.puzzleInstId == instId;
}
@Override
public void run(Scene scene) {
synchronized (scene) {
for (GameEntity entity : scene.getEntities().values()) {
if (entity.getGroupId() != this.groupId) {
continue;
}
if (entity instanceof EntityProp prop) {
if (prop.getInstId() == chestInstId) {
prop.setState(PropState.ChestClosed);
}
}
}
}
}
}