From c4448fea149d2638f126813deba6406a7a15d67d Mon Sep 17 00:00:00 2001 From: syeyoung <42869671+cyoung06@users.noreply.github.com> Date: Tue, 15 Dec 2020 01:23:36 +0900 Subject: predicate equals and more edits --- .../dungeon/actions/ActionChangeState.java | 7 +++++-- .../dungeonsguide/dungeon/actions/ActionClick.java | 2 +- .../dungeon/actions/ActionClickSet.java | 2 +- .../dungeon/actions/ActionDropItem.java | 2 +- .../dungeonsguide/dungeon/actions/ActionKill.java | 2 +- .../dungeonsguide/dungeon/actions/ActionMove.java | 2 +- .../dungeon/actions/ActionMoveNearestAir.java | 2 +- .../dungeon/actions/tree/ActionTree.java | 6 ++++++ .../dungeon/mechanics/DungeonBreakableWall.java | 1 + .../dungeon/mechanics/DungeonDoor.java | 21 ++++++++++++++++----- .../dungeon/mechanics/DungeonLever.java | 1 + .../dungeon/mechanics/DungeonOnewayDoor.java | 1 + .../dungeon/mechanics/DungeonOnewayLever.java | 3 ++- .../dungeon/mechanics/DungeonPressurePlate.java | 1 + .../dungeon/mechanics/DungeonSecret.java | 1 + .../dungeon/mechanics/DungeonTomb.java | 1 + .../dungeon/mechanics/predicates/PredicateBat.java | 5 +++++ .../mechanics/predicates/PredicateSuperBoom.java | 5 +++++ 18 files changed, 51 insertions(+), 14 deletions(-) (limited to 'src/main/java/kr/syeyoung/dungeonsguide/dungeon') diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/actions/ActionChangeState.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/actions/ActionChangeState.java index b17625d7..9aeac9e8 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/actions/ActionChangeState.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/actions/ActionChangeState.java @@ -1,5 +1,6 @@ package kr.syeyoung.dungeonsguide.dungeon.actions; +import kr.syeyoung.dungeonsguide.dungeon.mechanics.DungeonMechanic; import kr.syeyoung.dungeonsguide.dungeon.roomfinder.DungeonRoom; import lombok.Data; @@ -22,11 +23,13 @@ public class ActionChangeState implements Action{ public Set getPreRequisites(DungeonRoom dungeonRoom) { Set set = new HashSet(); set.addAll(preRequisite2); - set.addAll(dungeonRoom.getDungeonRoomInfo().getMechanics().get(mechanicName).getAction(state, dungeonRoom)); + DungeonMechanic mechanic = dungeonRoom.getDungeonRoomInfo().getMechanics().get(mechanicName); + if (mechanic!= null) + set.addAll(mechanic.getAction(state, dungeonRoom)); return set; } @Override public String toString() { - return "ChangeState\n\ttarget: "+mechanicName+"\n\tstate: "+state; + return "ChangeState\n- target: "+mechanicName+"\n- state: "+state; } } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/actions/ActionClick.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/actions/ActionClick.java index 13e4ee76..b3a4cc92 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/actions/ActionClick.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/actions/ActionClick.java @@ -27,6 +27,6 @@ public class ActionClick implements Action { @Override public String toString() { - return "Click\n\ttarget: "+target.toString()+"\n\tpredicate: "+predicate.getClass().getSimpleName(); + return "Click\n- target: "+target.toString()+"\n- predicate: "+predicate.getClass().getSimpleName(); } } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/actions/ActionClickSet.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/actions/ActionClickSet.java index 454bfad3..595e66c7 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/actions/ActionClickSet.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/actions/ActionClickSet.java @@ -27,6 +27,6 @@ public class ActionClickSet implements Action { @Override public String toString() { - return "ClickSet\n\ttargets size: "+target.getOffsetPointList().size()+"\n\tpredicate: "+predicate.getClass().getSimpleName(); + return "ClickSet\n- targets size: "+target.getOffsetPointList().size()+"\n- predicate: "+predicate.getClass().getSimpleName(); } } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/actions/ActionDropItem.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/actions/ActionDropItem.java index ad2eb5e2..151fe96c 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/actions/ActionDropItem.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/actions/ActionDropItem.java @@ -27,6 +27,6 @@ public class ActionDropItem implements Action { @Override public String toString() { - return "DropItem\n\ttarget: "+target.toString()+"\n\tpredicate: "+predicate.getClass().getSimpleName(); + return "DropItem\n- target: "+target.toString()+"\n- predicate: "+predicate.getClass().getSimpleName(); } } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/actions/ActionKill.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/actions/ActionKill.java index 162d0345..e1eba8b7 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/actions/ActionKill.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/actions/ActionKill.java @@ -27,6 +27,6 @@ public class ActionKill implements Action { @Override public String toString() { - return "KillEntity\n\ttarget: "+target.toString()+"\n\tradius: "+radius+"\n\tpredicate: "+(predicate == null ? "null" : predicate.getClass().getSimpleName()); + return "KillEntity\n- target: "+target.toString()+"\n- radius: "+radius+"\n- predicate: "+(predicate == null ? "null" : predicate.getClass().getSimpleName()); } } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/actions/ActionMove.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/actions/ActionMove.java index 15bc9814..a2aee8da 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/actions/ActionMove.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/actions/ActionMove.java @@ -24,6 +24,6 @@ public class ActionMove implements Action { @Override public String toString() { - return "Move\n\ttarget: "+target.toString(); + return "Move\n- target: "+target.toString(); } } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/actions/ActionMoveNearestAir.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/actions/ActionMoveNearestAir.java index 3e3f3016..91bd79e7 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/actions/ActionMoveNearestAir.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/actions/ActionMoveNearestAir.java @@ -23,6 +23,6 @@ public class ActionMoveNearestAir implements Action { @Override public String toString() { - return "MoveNearestAir\n\ttarget: "+target.toString(); + return "MoveNearestAir\n- target: "+target.toString(); } } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/actions/tree/ActionTree.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/actions/tree/ActionTree.java index 1db6767c..334f7c2b 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/actions/tree/ActionTree.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/actions/tree/ActionTree.java @@ -4,6 +4,7 @@ import kr.syeyoung.dungeonsguide.dungeon.actions.Action; import kr.syeyoung.dungeonsguide.dungeon.actions.ActionRoot; import kr.syeyoung.dungeonsguide.dungeon.roomfinder.DungeonRoom; import lombok.Data; +import lombok.EqualsAndHashCode; import java.util.HashMap; import java.util.HashSet; @@ -12,10 +13,14 @@ import java.util.Set; @Data public class ActionTree { + @EqualsAndHashCode.Exclude private ActionTree parent; private Action current; private Set children; + @Override + public int hashCode() { return current == null ? 0 : current.hashCode(); } + public static ActionTree buildActionTree(Set actions, DungeonRoom dungeonRoom) { ActionRoot root = new ActionRoot(); @@ -31,6 +36,7 @@ public class ActionTree { return tree; } + private static ActionTree buildActionTree(ActionTree parent, Action action, DungeonRoom dungeonRoom, Map alreadyBuilt) { if (action == null) return null; if (alreadyBuilt.containsKey(action)) return alreadyBuilt.get(action); diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/mechanics/DungeonBreakableWall.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/mechanics/DungeonBreakableWall.java index fe89b7cb..701f9a4a 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/mechanics/DungeonBreakableWall.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/mechanics/DungeonBreakableWall.java @@ -45,6 +45,7 @@ public class DungeonBreakableWall implements DungeonMechanic, RouteBlocker { } { for (String str : preRequisite) { + if (str.isEmpty()) continue; ActionChangeState actionChangeState = new ActionChangeState(str.split(":")[0], str.split(":")[1]); preRequisites.add(actionChangeState); } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/mechanics/DungeonDoor.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/mechanics/DungeonDoor.java index cbf7520f..d496b450 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/mechanics/DungeonDoor.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/mechanics/DungeonDoor.java @@ -20,7 +20,8 @@ import java.util.*; @Data public class DungeonDoor implements DungeonMechanic, RouteBlocker { private OffsetPointSet secretPoint = new OffsetPointSet(); - private List preRequisite = new ArrayList(); + private List openPreRequisite = new ArrayList(); + private List closePreRequisite = new ArrayList(); @Override @@ -43,9 +44,18 @@ public class DungeonDoor implements DungeonMechanic, RouteBlocker { preRequisites = actionMove.getPreRequisite(); } { - for (String str : preRequisite) { - ActionChangeState actionChangeState = new ActionChangeState(str.split(":")[0], str.split(":")[1]); - preRequisites.add(actionChangeState); + if (state.equalsIgnoreCase("open")) { + for (String str : openPreRequisite) { + if (str.isEmpty()) continue; + ActionChangeState actionChangeState = new ActionChangeState(str.split(":")[0], str.split(":")[1]); + preRequisites.add(actionChangeState); + } + } else { + for (String str : closePreRequisite) { + if (str.isEmpty()) continue; + ActionChangeState actionChangeState = new ActionChangeState(str.split(":")[0], str.split(":")[1]); + preRequisites.add(actionChangeState); + } } } return base; @@ -75,7 +85,8 @@ public class DungeonDoor implements DungeonMechanic, RouteBlocker { public DungeonDoor clone() throws CloneNotSupportedException { DungeonDoor dungeonSecret = new DungeonDoor(); dungeonSecret.secretPoint = (OffsetPointSet) secretPoint.clone(); - dungeonSecret.preRequisite = new ArrayList(preRequisite); + dungeonSecret.openPreRequisite = new ArrayList(openPreRequisite); + dungeonSecret.closePreRequisite = new ArrayList(closePreRequisite); return dungeonSecret; } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/mechanics/DungeonLever.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/mechanics/DungeonLever.java index 9fe0165f..01b3323e 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/mechanics/DungeonLever.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/mechanics/DungeonLever.java @@ -37,6 +37,7 @@ public class DungeonLever implements DungeonMechanic { } { for (String str : preRequisite) { + if (str.isEmpty()) continue; ActionChangeState actionChangeState = new ActionChangeState(str.split(":")[0], str.split(":")[1]); preRequisites.add(actionChangeState); } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/mechanics/DungeonOnewayDoor.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/mechanics/DungeonOnewayDoor.java index 3ee41f1b..9027f0dc 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/mechanics/DungeonOnewayDoor.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/mechanics/DungeonOnewayDoor.java @@ -44,6 +44,7 @@ public class DungeonOnewayDoor implements DungeonMechanic, RouteBlocker { } { for (String str : preRequisite) { + if (str.isEmpty()) continue; ActionChangeState actionChangeState = new ActionChangeState(str.split(":")[0], str.split(":")[1]); preRequisites.add(actionChangeState); } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/mechanics/DungeonOnewayLever.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/mechanics/DungeonOnewayLever.java index d9b396f0..a1500fa7 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/mechanics/DungeonOnewayLever.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/mechanics/DungeonOnewayLever.java @@ -22,7 +22,7 @@ public class DungeonOnewayLever implements DungeonMechanic { @Override public Set getAction(String state, DungeonRoom dungeonRoom) { - if (!("triggered".equalsIgnoreCase(state) || "untriggered".equalsIgnoreCase(state))) throw new IllegalArgumentException(state+" is not valid state for secret"); + if (!("triggered".equalsIgnoreCase(state))) throw new IllegalArgumentException(state+" is not valid state for secret"); Set base; Set preRequisites = base = new HashSet(); { @@ -37,6 +37,7 @@ public class DungeonOnewayLever implements DungeonMechanic { } { for (String str : preRequisite) { + if (str.isEmpty()) continue; ActionChangeState actionChangeState = new ActionChangeState(str.split(":")[0], str.split(":")[1]); preRequisites.add(actionChangeState); } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/mechanics/DungeonPressurePlate.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/mechanics/DungeonPressurePlate.java index da126215..ab33a5db 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/mechanics/DungeonPressurePlate.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/mechanics/DungeonPressurePlate.java @@ -39,6 +39,7 @@ public class DungeonPressurePlate implements DungeonMechanic { } { for (String str : preRequisite) { + if (str.isEmpty()) continue; ActionChangeState actionChangeState = new ActionChangeState(str.split(":")[0], str.split(":")[1]); preRequisites.add(actionChangeState); } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/mechanics/DungeonSecret.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/mechanics/DungeonSecret.java index e5b8d54a..91ede235 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/mechanics/DungeonSecret.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/mechanics/DungeonSecret.java @@ -64,6 +64,7 @@ public class DungeonSecret implements DungeonMechanic { } { for (String str : preRequisite) { + if (str.isEmpty()) continue; ActionChangeState actionChangeState = new ActionChangeState(str.split(":")[0], str.split(":")[1]); preRequisites.add(actionChangeState); } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/mechanics/DungeonTomb.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/mechanics/DungeonTomb.java index ce74e955..86c6a818 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/mechanics/DungeonTomb.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/mechanics/DungeonTomb.java @@ -45,6 +45,7 @@ public class DungeonTomb implements DungeonMechanic, RouteBlocker { } { for (String str : preRequisite) { + if (str.isEmpty()) continue; ActionChangeState actionChangeState = new ActionChangeState(str.split(":")[0], str.split(":")[1]); preRequisites.add(actionChangeState); } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/mechanics/predicates/PredicateBat.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/mechanics/predicates/PredicateBat.java index 136efd0e..5eb38597 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/mechanics/predicates/PredicateBat.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/mechanics/predicates/PredicateBat.java @@ -14,4 +14,9 @@ public class PredicateBat implements Predicate { public boolean apply(@Nullable Entity input) { return input instanceof EntityBat; } + + @Override + public boolean equals(Object o) { + return o == this || o != null && (o.getClass() == this.getClass()); + } } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/mechanics/predicates/PredicateSuperBoom.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/mechanics/predicates/PredicateSuperBoom.java index ccc1b017..6054c268 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/mechanics/predicates/PredicateSuperBoom.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/mechanics/predicates/PredicateSuperBoom.java @@ -12,4 +12,9 @@ public class PredicateSuperBoom implements Predicate { public boolean apply(@Nullable ItemStack input) { return false; } + + @Override + public boolean equals(Object o) { + return o == this || o != null && (o.getClass() == this.getClass()); + } } -- cgit