From 4f289db303d4e68e68789767b91e3106ff1866d7 Mon Sep 17 00:00:00 2001 From: syeyoung Date: Mon, 22 Feb 2021 01:09:29 +0900 Subject: events --- .../dungeonsguide/dungeon/DungeonContext.java | 44 ++++++++++++++++++++-- .../dungeonsguide/dungeon/MapProcessor.java | 6 +++ .../dungeon/events/DungeonCryptBrokenEvent.java | 19 ++++++++++ .../dungeon/events/DungeonDeathEvent.java | 20 ++++++++++ .../dungeonsguide/dungeon/events/DungeonEvent.java | 21 +++++++++++ .../dungeon/events/DungeonEventData.java | 5 +++ .../dungeon/events/DungeonMapUpdateEvent.java | 15 ++++++++ .../dungeon/events/DungeonNodataEvent.java | 10 +++++ .../dungeon/events/DungeonPuzzleFailureEvent.java | 15 ++++++++ .../dungeon/events/DungeonRoomDiscoverEvent.java | 26 +++++++++++++ .../events/DungeonSecretCountChangeEvent.java | 21 +++++++++++ .../dungeon/events/DungeonStateChangeEvent.java | 23 +++++++++++ .../dungeon/roomfinder/DungeonRoom.java | 7 +++- 13 files changed, 227 insertions(+), 5 deletions(-) create mode 100644 src/main/java/kr/syeyoung/dungeonsguide/dungeon/events/DungeonCryptBrokenEvent.java create mode 100644 src/main/java/kr/syeyoung/dungeonsguide/dungeon/events/DungeonDeathEvent.java create mode 100644 src/main/java/kr/syeyoung/dungeonsguide/dungeon/events/DungeonEvent.java create mode 100644 src/main/java/kr/syeyoung/dungeonsguide/dungeon/events/DungeonEventData.java create mode 100644 src/main/java/kr/syeyoung/dungeonsguide/dungeon/events/DungeonMapUpdateEvent.java create mode 100644 src/main/java/kr/syeyoung/dungeonsguide/dungeon/events/DungeonNodataEvent.java create mode 100644 src/main/java/kr/syeyoung/dungeonsguide/dungeon/events/DungeonPuzzleFailureEvent.java create mode 100644 src/main/java/kr/syeyoung/dungeonsguide/dungeon/events/DungeonRoomDiscoverEvent.java create mode 100644 src/main/java/kr/syeyoung/dungeonsguide/dungeon/events/DungeonSecretCountChangeEvent.java create mode 100644 src/main/java/kr/syeyoung/dungeonsguide/dungeon/events/DungeonStateChangeEvent.java (limited to 'src/main/java/kr/syeyoung/dungeonsguide/dungeon') diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/DungeonContext.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/DungeonContext.java index 6f162a5c..49d3da4e 100755 --- a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/DungeonContext.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/DungeonContext.java @@ -3,6 +3,7 @@ package kr.syeyoung.dungeonsguide.dungeon; import kr.syeyoung.dungeonsguide.SkyblockStatus; import kr.syeyoung.dungeonsguide.dungeon.doorfinder.DungeonSpecificDataProvider; import kr.syeyoung.dungeonsguide.dungeon.doorfinder.DungeonSpecificDataProviderRegistry; +import kr.syeyoung.dungeonsguide.dungeon.events.*; import kr.syeyoung.dungeonsguide.dungeon.roomfinder.DungeonRoom; import kr.syeyoung.dungeonsguide.e; import kr.syeyoung.dungeonsguide.events.BossroomEnterEvent; @@ -61,9 +62,17 @@ public class DungeonContext { private boolean trapRoomGen = false; @Getter - @Setter private boolean gotMimic = false; + private int latestSecretCnt = 0; + private int latestTotalSecret = 0; + private int latestCrypts = 0; + + public void setGotMimic(boolean gotMimic) { + this.gotMimic = gotMimic; + createEvent(new DungeonNodataEvent("MIMIC_KILLED")); + } + @Getter @Setter private BossfightProcessor bossfightProcessor; @@ -71,12 +80,18 @@ public class DungeonContext { @Getter private Set players = new HashSet(); + private List events = new ArrayList(); + public DungeonContext(World world) { this.world = world; + createEvent(new DungeonNodataEvent("DUNGEON_CONTEXT_CREATION")); mapProcessor = new MapProcessor(this); DungeonSpecificDataProvider doorFinder = DungeonSpecificDataProviderRegistry.getDoorFinder(((SkyblockStatus) e.getDungeonsGuide().getSkyblockStatus()).getDungeonName()); trapRoomGen = doorFinder.isTrapSpawn(e.getDungeonsGuide().getSkyblockStatus().getDungeonName()); + } + public void createEvent(DungeonEventData eventData) { + events.add(new DungeonEvent(eventData)); } @@ -89,6 +104,7 @@ public class DungeonContext { BossRoomEnterSeconds = FeatureRegistry.DUNGEON_SBTIME.getTimeElapsed() / 1000; bossroomSpawnPos = Minecraft.getMinecraft().thePlayer.getPosition(); MinecraftForge.EVENT_BUS.post(new BossroomEnterEvent()); + createEvent(new DungeonNodataEvent("BOSSROOM_ENTER")); DungeonSpecificDataProvider doorFinder = DungeonSpecificDataProviderRegistry.getDoorFinder(((SkyblockStatus) e.getDungeonsGuide().getSkyblockStatus()).getDungeonName()); if (doorFinder != null) { bossfightProcessor = doorFinder.createBossfightProcessor(world, e.getDungeonsGuide().getSkyblockStatus().getDungeonName()); @@ -105,11 +121,27 @@ public class DungeonContext { players.add(TextUtils.stripColor(name).trim().split(" ")[0]); } } catch (Exception e) {} + + if (latestSecretCnt != FeatureRegistry.DUNGEON_SECRETS.getSecretsFound()) { + int newSecretCnt = FeatureRegistry.DUNGEON_SECRETS.getSecretsFound(); + createEvent(new DungeonSecretCountChangeEvent(latestSecretCnt, newSecretCnt, latestTotalSecret, FeatureRegistry.DUNGEON_SECRETS.sureOfTotalSecrets())); + latestSecretCnt = newSecretCnt; + } + if (latestTotalSecret != FeatureRegistry.DUNGEON_SECRETS.getTotalSecretsInt()) { + latestTotalSecret = FeatureRegistry.DUNGEON_SECRETS.getTotalSecretsInt(); + createEvent(new DungeonSecretCountChangeEvent(latestSecretCnt, latestSecretCnt, latestTotalSecret, FeatureRegistry.DUNGEON_SECRETS.sureOfTotalSecrets())); + } + if (latestCrypts != FeatureRegistry.DUNGEON_TOMBS.getTombsFound()) { + int newlatestCrypts = FeatureRegistry.DUNGEON_TOMBS.getTombsFound(); + createEvent(new DungeonCryptBrokenEvent(latestCrypts, newlatestCrypts)); + this.latestCrypts = newlatestCrypts; + } } public void onChat(ClientChatReceivedEvent event) { IChatComponent component = event.message; - if (component.getFormattedText().contains("$DG-Comm")) { + String formatted = component.getFormattedText(); + if (formatted.contains("$DG-Comm")) { event.setCanceled(true); String data = component.getFormattedText().substring(component.getFormattedText().indexOf("$DG-Comm")); String actual = TextUtils.stripColor(data); @@ -124,8 +156,12 @@ public class DungeonContext { if (dr != null) { dr.setTotalSecrets(secrets2); } - } else if (component.getFormattedText().contains("$DG-Mimic")) { - gotMimic = true; + } else if (formatted.contains("$DG-Mimic")) { + setGotMimic(true); + } else if (formatted.startsWith("§r§c§lPUZZLE FAIL! ") && formatted.endsWith(" §r§4Y§r§ci§r§6k§r§ee§r§as§r§2!§r")) { + createEvent(new DungeonPuzzleFailureEvent(TextUtils.stripColor(formatted.split(" ")[2]), formatted)); + } else if (formatted.contains("§6> §e§lEXTRA STATS §6<")) { + createEvent(new DungeonNodataEvent("DUNGEON_END")); } } } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/MapProcessor.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/MapProcessor.java index 2515698f..ad8de026 100755 --- a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/MapProcessor.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/MapProcessor.java @@ -4,6 +4,9 @@ import com.google.common.collect.BiMap; import com.google.common.collect.EnumHashBiMap; import com.google.common.collect.HashBiMap; import com.google.common.collect.Sets; +import kr.syeyoung.dungeonsguide.dungeon.events.DungeonMapUpdateEvent; +import kr.syeyoung.dungeonsguide.dungeon.events.DungeonNodataEvent; +import kr.syeyoung.dungeonsguide.dungeon.events.DungeonRoomDiscoverEvent; import kr.syeyoung.dungeonsguide.e; import kr.syeyoung.dungeonsguide.SkyblockStatus; import kr.syeyoung.dungeonsguide.dungeon.roomfinder.DungeonRoom; @@ -157,6 +160,7 @@ public class MapProcessor { e.sendDebugChat(new ChatComponentText("Dimension:"+unitRoomDimension)); e.sendDebugChat(new ChatComponentText("top Left:"+topLeftMapPoint)); e.sendDebugChat(new ChatComponentText("door dimension:"+doorDimension)); + context.createEvent(new DungeonNodataEvent("MAP_PROCESSOR_INIT")); initialized = true; MinecraftForge.EVENT_BUS.post(new DungeonContextInitializationEvent()); } @@ -225,6 +229,7 @@ public class MapProcessor { MapUtils.record(mapData, mapPoint.x, mapPoint.y, new Color(0,255,255,80)); DungeonRoom rooms = buildRoom(mapData, new Point(x,y)); if (rooms == null) continue; + context.createEvent(new DungeonRoomDiscoverEvent(rooms.getUnitPoints().get(0), rooms.getRoomMatcher().getRotation(), rooms.getMin(), rooms.getShape(),rooms.getColor(), rooms.getDungeonRoomInfo().getUuid(), rooms.getDungeonRoomInfo().getName(), rooms.getDungeonRoomInfo().getProcessorId())); e.sendDebugChat(new ChatComponentText("New Map discovered! shape: "+rooms.getShape()+ " color: "+rooms.getColor()+" unitPos: "+x+","+y)); e.sendDebugChat(new ChatComponentText("New Map discovered! mapMin: "+rooms.getMin() + " mapMx: "+rooms.getMax())); StringBuilder builder = new StringBuilder(); @@ -342,6 +347,7 @@ public class MapProcessor { if (isThereDifference(lastMapData, mapData)) { stabilizationTick =0; + context.createEvent(new DungeonMapUpdateEvent(mapData)); } else { stabilizationTick++; } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/events/DungeonCryptBrokenEvent.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/events/DungeonCryptBrokenEvent.java new file mode 100644 index 00000000..53f833df --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/events/DungeonCryptBrokenEvent.java @@ -0,0 +1,19 @@ +package kr.syeyoung.dungeonsguide.dungeon.events; + +import kr.syeyoung.dungeonsguide.dungeon.roomfinder.DungeonRoom; +import lombok.AllArgsConstructor; +import lombok.Data; + +import java.awt.*; + +@Data +@AllArgsConstructor +public class DungeonCryptBrokenEvent implements DungeonEventData { + private int prevCrypts; + private int newCrypts; + + @Override + public String getEventName() { + return "CRYPTS_CHANGE"; + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/events/DungeonDeathEvent.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/events/DungeonDeathEvent.java new file mode 100644 index 00000000..dfbfa0d3 --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/events/DungeonDeathEvent.java @@ -0,0 +1,20 @@ +package kr.syeyoung.dungeonsguide.dungeon.events; + +import kr.syeyoung.dungeonsguide.dungeon.roomfinder.DungeonRoom; +import lombok.AllArgsConstructor; +import lombok.Data; + +import java.awt.*; + +@Data +@AllArgsConstructor +public class DungeonDeathEvent implements DungeonEventData { + private String playerName; + private String message; + private int cnt; + + @Override + public String getEventName() { + return "PLAYER_DEATH"; + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/events/DungeonEvent.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/events/DungeonEvent.java new file mode 100644 index 00000000..cb2b3f57 --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/events/DungeonEvent.java @@ -0,0 +1,21 @@ +package kr.syeyoung.dungeonsguide.dungeon.events; + +import kr.syeyoung.dungeonsguide.features.FeatureRegistry; +import lombok.Data; + +@Data +public class DungeonEvent { + private long UTCTime = System.currentTimeMillis(); + private long realTimeElapsed; + private long skyblockTimeElapsed; + + private String eventName; + private DungeonEventData data; + + public DungeonEvent(DungeonEventData eventData){ + this.data = eventData; + this.realTimeElapsed = FeatureRegistry.DUNGEON_REALTIME.getTimeElapsed(); + this.skyblockTimeElapsed = FeatureRegistry.DUNGEON_SBTIME.getTimeElapsed(); + this.eventName = eventData.getEventName(); + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/events/DungeonEventData.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/events/DungeonEventData.java new file mode 100644 index 00000000..2aa5ff68 --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/events/DungeonEventData.java @@ -0,0 +1,5 @@ +package kr.syeyoung.dungeonsguide.dungeon.events; + +public interface DungeonEventData { + String getEventName(); +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/events/DungeonMapUpdateEvent.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/events/DungeonMapUpdateEvent.java new file mode 100644 index 00000000..39e6382b --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/events/DungeonMapUpdateEvent.java @@ -0,0 +1,15 @@ +package kr.syeyoung.dungeonsguide.dungeon.events; + +import lombok.AllArgsConstructor; +import lombok.Data; + +@Data +@AllArgsConstructor +public class DungeonMapUpdateEvent implements DungeonEventData { + private byte[] map; + + @Override + public String getEventName() { + return "MAP_UPDATE"; + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/events/DungeonNodataEvent.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/events/DungeonNodataEvent.java new file mode 100644 index 00000000..9820627d --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/events/DungeonNodataEvent.java @@ -0,0 +1,10 @@ +package kr.syeyoung.dungeonsguide.dungeon.events; + +import lombok.AllArgsConstructor; +import lombok.Data; + +@Data +@AllArgsConstructor +public class DungeonNodataEvent implements DungeonEventData { + private String eventName; +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/events/DungeonPuzzleFailureEvent.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/events/DungeonPuzzleFailureEvent.java new file mode 100644 index 00000000..49ef1cfa --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/events/DungeonPuzzleFailureEvent.java @@ -0,0 +1,15 @@ +package kr.syeyoung.dungeonsguide.dungeon.events; + +import lombok.AllArgsConstructor; +import lombok.Data; + +@Data +@AllArgsConstructor +public class DungeonPuzzleFailureEvent implements DungeonEventData { + private String playerName; + private String message; + @Override + public String getEventName() { + return "PUZZLE_FAILURE"; + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/events/DungeonRoomDiscoverEvent.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/events/DungeonRoomDiscoverEvent.java new file mode 100644 index 00000000..44f3713f --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/events/DungeonRoomDiscoverEvent.java @@ -0,0 +1,26 @@ +package kr.syeyoung.dungeonsguide.dungeon.events; + +import lombok.AllArgsConstructor; +import lombok.Data; +import net.minecraft.util.BlockPos; + +import java.awt.*; +import java.util.UUID; + +@Data +@AllArgsConstructor +public class DungeonRoomDiscoverEvent implements DungeonEventData { + private Point unitPt; + private int rotation; + private BlockPos min; + private int shape; + private int color; + private UUID roomUID; + private String roomName; + private String roomProc; + + @Override + public String getEventName() { + return "ROOM_DISCOVER"; + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/events/DungeonSecretCountChangeEvent.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/events/DungeonSecretCountChangeEvent.java new file mode 100644 index 00000000..e25b8dc0 --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/events/DungeonSecretCountChangeEvent.java @@ -0,0 +1,21 @@ +package kr.syeyoung.dungeonsguide.dungeon.events; + +import kr.syeyoung.dungeonsguide.dungeon.roomfinder.DungeonRoom; +import lombok.AllArgsConstructor; +import lombok.Data; + +import java.awt.*; + +@Data +@AllArgsConstructor +public class DungeonSecretCountChangeEvent implements DungeonEventData { + private int prevCount; + private int newCount; + private int totalSecret; + private boolean sureTotalSecret; + + @Override + public String getEventName() { + return "SECRET_CNT_CHANGE"; + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/events/DungeonStateChangeEvent.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/events/DungeonStateChangeEvent.java new file mode 100644 index 00000000..cc895b49 --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/events/DungeonStateChangeEvent.java @@ -0,0 +1,23 @@ +package kr.syeyoung.dungeonsguide.dungeon.events; + +import kr.syeyoung.dungeonsguide.dungeon.roomfinder.DungeonRoom; +import lombok.AllArgsConstructor; +import lombok.Data; +import net.minecraft.util.BlockPos; + +import java.awt.*; +import java.util.UUID; + +@Data +@AllArgsConstructor +public class DungeonStateChangeEvent implements DungeonEventData { + private Point unitPt; + private String roomName; + private DungeonRoom.RoomState from; + private DungeonRoom.RoomState to; + + @Override + public String getEventName() { + return "ROOM_STATE_CHANGE"; + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/roomfinder/DungeonRoom.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/roomfinder/DungeonRoom.java index 691926f7..9a3c42bc 100755 --- a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/roomfinder/DungeonRoom.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/roomfinder/DungeonRoom.java @@ -5,6 +5,7 @@ import kr.syeyoung.dungeonsguide.dungeon.DungeonContext; import kr.syeyoung.dungeonsguide.dungeon.MapProcessor; import kr.syeyoung.dungeonsguide.dungeon.data.DungeonRoomInfo; import kr.syeyoung.dungeonsguide.dungeon.doorfinder.DungeonDoor; +import kr.syeyoung.dungeonsguide.dungeon.events.DungeonStateChangeEvent; import kr.syeyoung.dungeonsguide.pathfinding.NodeProcessorDungeonRoom; import kr.syeyoung.dungeonsguide.roomprocessor.ProcessorFactory; import kr.syeyoung.dungeonsguide.roomprocessor.RoomProcessor; @@ -42,9 +43,13 @@ public class DungeonRoom { @Setter private int totalSecrets = -1; - @Setter private RoomState currentState = RoomState.DISCOVERED; + public void setCurrentState(RoomState currentState) { + context.createEvent(new DungeonStateChangeEvent(unitPoints.get(0), dungeonRoomInfo.getName(), this.currentState, currentState)); + this.currentState = currentState; + } + @Getter private PathFinder pathFinder; @Getter -- cgit