package kr.syeyoung.dungeonsguide.dungeon.mechanics; import com.google.common.collect.Sets; import kr.syeyoung.dungeonsguide.dungeon.actions.*; import kr.syeyoung.dungeonsguide.dungeon.data.OffsetPoint; import kr.syeyoung.dungeonsguide.dungeon.roomfinder.DungeonRoom; import kr.syeyoung.dungeonsguide.utils.RenderUtils; import lombok.Data; import net.minecraft.util.BlockPos; import java.awt.*; import java.util.*; import java.util.List; @Data public class DungeonPressurePlate implements DungeonMechanic { private static final long serialVersionUID = 7450034718355390645L; private OffsetPoint platePoint = new OffsetPoint(0,0,0); private List preRequisite = new ArrayList(); private String triggering = ""; @Override public Set getAction(String state, DungeonRoom dungeonRoom) { if (state.equals(getCurrentState(dungeonRoom))) return Collections.emptySet(); if (state.equalsIgnoreCase("navigate")) { Set base; Set preRequisites = base = new HashSet(); ActionMoveNearestAir actionMove = new ActionMoveNearestAir(getRepresentingPoint(dungeonRoom)); preRequisites.add(actionMove); preRequisites = actionMove.getPreRequisite(); for (String str : preRequisite) { if (str.isEmpty()) continue; ActionChangeState actionChangeState = new ActionChangeState(str.split(":")[0], str.split(":")[1]); preRequisites.add(actionChangeState); } return base; } if (!("triggered".equalsIgnoreCase(state) || "untriggered".equalsIgnoreCase(state))) throw new IllegalArgumentException(state+" is not valid state for secret"); if (state.equalsIgnoreCase(getCurrentState(dungeonRoom))) return Collections.emptySet(); Set base; Set preRequisites = base = new HashSet(); if ("triggered".equalsIgnoreCase(state)) { ActionDropItem actionClick; preRequisites.add(actionClick = new ActionDropItem(platePoint)); preRequisites = actionClick.getPreRequisite(); } { ActionMove actionMove = new ActionMove(platePoint); preRequisites.add(actionMove); preRequisites = actionMove.getPreRequisite(); } { for (String str : preRequisite) { if (str.isEmpty()) continue; ActionChangeState actionChangeState = new ActionChangeState(str.split(":")[0], str.split(":")[1]); preRequisites.add(actionChangeState); } } return base; } @Override public void highlight(Color color, String name, DungeonRoom dungeonRoom, float partialTicks) { BlockPos pos = getPlatePoint().getBlockPos(dungeonRoom); RenderUtils.highlightBlock(pos, color,partialTicks); RenderUtils.drawTextAtWorld(name, pos.getX() +0.5f, pos.getY()+0.75f, pos.getZ()+0.5f, 0xFFFFFFFF, 0.03f, false, true, partialTicks); RenderUtils.drawTextAtWorld(getCurrentState(dungeonRoom), pos.getX() +0.5f, pos.getY()+0.25f, pos.getZ()+0.5f, 0xFFFFFFFF, 0.03f, false, true, partialTicks); } public DungeonPressurePlate clone() throws CloneNotSupportedException { DungeonPressurePlate dungeonSecret = new DungeonPressurePlate(); dungeonSecret.platePoint = (OffsetPoint) platePoint.clone(); dungeonSecret.triggering = triggering; dungeonSecret.preRequisite = new ArrayList(preRequisite); return dungeonSecret; } @Override public String getCurrentState(DungeonRoom dungeonRoom) { if (triggering == null) triggering = "null"; DungeonMechanic mechanic = dungeonRoom.getMechanics().get(triggering); if (mechanic == null) { return "undeterminable"; } else { String state = mechanic.getCurrentState(dungeonRoom); if ("open".equalsIgnoreCase(state)) { return "triggered"; } else { return "untriggered"; } } } @Override public Set getPossibleStates(DungeonRoom dungeonRoom) { String currentStatus = getCurrentState(dungeonRoom); if (currentStatus.equalsIgnoreCase("triggered")) return Sets.newHashSet("navigate", "untriggered"); else if (currentStatus.equalsIgnoreCase("untriggered")) return Sets.newHashSet("navigate", "triggered"); return Sets.newHashSet("navigate"); } @Override public Set getTotalPossibleStates(DungeonRoom dungeonRoom) { return Sets.newHashSet("triggered", "untriggered"); } @Override public OffsetPoint getRepresentingPoint(DungeonRoom dungeonRoom) { return platePoint; } }