mirror of
https://github.com/Melledy/LunarCore.git
synced 2025-12-13 13:54:37 +01:00
Implement those compass puzzles
This commit is contained in:
@@ -7,6 +7,7 @@ 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;
|
||||
|
||||
@@ -68,6 +69,8 @@ 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_01")) {
|
||||
prop.setTrigger(new TriggerPuzzleCompassWayPointController(prop.getSharedValueByKey("PuzzleCompass_Prop"), prop.getSharedValueByKey("PuzzleChest_Prop")));
|
||||
}
|
||||
|
||||
prop.setInitLevelGraph(null);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package emu.lunarcore.data.config;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import emu.lunarcore.game.enums.PropState;
|
||||
import emu.lunarcore.game.scene.triggers.PropTrigger;
|
||||
import lombok.Getter;
|
||||
@@ -16,10 +18,33 @@ public class PropInfo extends ObjectInfo {
|
||||
private int EventID;
|
||||
private int CocoonID;
|
||||
private int FarmElementID;
|
||||
private int ChestID;
|
||||
private PropValueSource ValueSource;
|
||||
|
||||
@Setter private String InitLevelGraph;
|
||||
@Setter private PropState State = PropState.Closed;
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import emu.lunarcore.game.inventory.Inventory;
|
||||
import emu.lunarcore.game.scene.Scene;
|
||||
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.HeadIconOuterClass.HeadIcon;
|
||||
import emu.lunarcore.proto.PlayerBasicInfoOuterClass.PlayerBasicInfo;
|
||||
@@ -332,6 +333,8 @@ public class Player {
|
||||
EntityProp prop = null;
|
||||
if (entity instanceof EntityProp) {
|
||||
prop = (EntityProp) entity;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Handle prop interaction action
|
||||
@@ -346,6 +349,14 @@ public class Player {
|
||||
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 -> {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -253,9 +253,9 @@ public class Scene {
|
||||
}
|
||||
|
||||
// TODO
|
||||
public void fireTrigger(PropTriggerType type, int param) {
|
||||
public void fireTrigger(PropTriggerType type, int param1, int param2) {
|
||||
for (PropTrigger trigger : this.getTriggers()) {
|
||||
if (trigger.shouldRun(param)) {
|
||||
if (trigger.shouldRun(param1, param2)) {
|
||||
trigger.run(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ public class EntityMonster implements GameEntity {
|
||||
@Override
|
||||
public void onRemove() {
|
||||
// Try to fire any triggers
|
||||
getScene().fireTrigger(PropTriggerType.MONSTER_DIE, this.getGroupId());
|
||||
getScene().fireTrigger(PropTriggerType.MONSTER_DIE, this.getGroupId(), this.getInstId());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -69,4 +69,8 @@ public class EntityProp implements GameEntity {
|
||||
return proto;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Prop: " + this.getEntityId() + ", Group: " + this.groupId + ", Inst: " + this.getInstId();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ public abstract class PropTrigger {
|
||||
|
||||
public abstract PropTriggerType getType();
|
||||
|
||||
public abstract boolean shouldRun(int param);
|
||||
public abstract boolean shouldRun(int groupId, int instId);
|
||||
|
||||
public abstract void run(Scene scene);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
package emu.lunarcore.game.scene.triggers;
|
||||
|
||||
public enum PropTriggerType {
|
||||
MONSTER_DIE;
|
||||
MONSTER_DIE, PUZZLE_FINISH;
|
||||
}
|
||||
|
||||
@@ -21,8 +21,8 @@ public class TriggerOpenTreasureWhenMonsterDie extends PropTrigger {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldRun(int param) {
|
||||
return this.groupId == param;
|
||||
public boolean shouldRun(int groupId, int instId) {
|
||||
return this.groupId == groupId;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user