diff options
Diffstat (limited to 'src/main/java/kr/syeyoung')
7 files changed, 359 insertions, 1 deletions
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/features/impl/dungeon/FeatureDungeonScore.java b/src/main/java/kr/syeyoung/dungeonsguide/features/impl/dungeon/FeatureDungeonScore.java index e121b660..6bf0b279 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/features/impl/dungeon/FeatureDungeonScore.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/features/impl/dungeon/FeatureDungeonScore.java @@ -157,7 +157,7 @@ public class FeatureDungeonScore extends GuiFeature { } else { timeModifier = Math.max(0, FeatureRegistry.DUNGEON_SBTIME.getTimeElapsed() / 1000 - 1200); } - time = (int) Math.floor(100 - 2.2 * timeModifier); + time = MathHelper.clamp_int((int) Math.floor(100 - 2.2 * timeModifier), 0, 100); } int bonus = 0; int tombs; diff --git a/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/bombdefuse/RoomProcessorBombDefuseSolver.java b/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/bombdefuse/RoomProcessorBombDefuseSolver.java new file mode 100644 index 00000000..1cc9a744 --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/bombdefuse/RoomProcessorBombDefuseSolver.java @@ -0,0 +1,233 @@ +package kr.syeyoung.dungeonsguide.roomprocessor.bombdefuse; + +import com.google.common.io.ByteArrayDataOutput; +import com.google.common.io.ByteStreams; +import com.sun.org.apache.xerces.internal.impl.dv.util.Base64; +import kr.syeyoung.dungeonsguide.dungeon.data.OffsetPointSet; +import kr.syeyoung.dungeonsguide.dungeon.roomfinder.DungeonRoom; +import kr.syeyoung.dungeonsguide.e; +import kr.syeyoung.dungeonsguide.roomprocessor.GeneralRoomProcessor; +import kr.syeyoung.dungeonsguide.roomprocessor.bombdefuse.chambers.BDChamber; +import kr.syeyoung.dungeonsguide.roomprocessor.bombdefuse.chambers.BombDefuseChamberGenerator; +import kr.syeyoung.dungeonsguide.roomprocessor.bombdefuse.chambers.DummyDefuseChamberProcessor; +import kr.syeyoung.dungeonsguide.utils.TextUtils; +import lombok.AllArgsConstructor; +import lombok.Data; +import net.minecraft.client.Minecraft; +import net.minecraft.nbt.CompressedStreamTools; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.BlockPos; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.IChatComponent; +import net.minecraftforge.client.event.GuiScreenEvent; +import net.minecraftforge.event.entity.living.LivingEvent; + +import java.awt.*; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +public class RoomProcessorBombDefuseSolver extends GeneralRoomProcessor { + + private List<ChamberSet> chambers = new ArrayList<ChamberSet>(); + private OffsetPointSet doors; + + private static final List<BombDefuseChamberGenerator> chamberGenerators = new ArrayList<BombDefuseChamberGenerator>(); + { + + } + + private boolean bugged = false; + + public RoomProcessorBombDefuseSolver(DungeonRoom dungeonRoom) { + super(dungeonRoom); + chambers.add(new ChamberSet( + buildChamber((OffsetPointSet) dungeonRoom.getDungeonRoomInfo().getProperties().get("L1"), 1, true), + buildChamber((OffsetPointSet) dungeonRoom.getDungeonRoomInfo().getProperties().get("R1"), 1, true), null + )); + chambers.add(new ChamberSet( + buildChamber((OffsetPointSet) dungeonRoom.getDungeonRoomInfo().getProperties().get("L2"), 2, true), + buildChamber((OffsetPointSet) dungeonRoom.getDungeonRoomInfo().getProperties().get("R2"), 2, true), null + )); + chambers.add(new ChamberSet( + buildChamber((OffsetPointSet) dungeonRoom.getDungeonRoomInfo().getProperties().get("L3"), 3, true), + buildChamber((OffsetPointSet) dungeonRoom.getDungeonRoomInfo().getProperties().get("R3"), 3, true), null + )); + chambers.add(new ChamberSet( + buildChamber((OffsetPointSet) dungeonRoom.getDungeonRoomInfo().getProperties().get("L4"), 4, true), + buildChamber((OffsetPointSet) dungeonRoom.getDungeonRoomInfo().getProperties().get("R4"), 4, true), null + )); + doors = (OffsetPointSet) dungeonRoom.getDungeonRoomInfo().getProperties().get("Door"); + if (doors == null) {bugged = true; return;} + for (ChamberSet set:chambers) { + if (set.getLeft().getChamberBlocks() == null) { + bugged = true; + return; + } + if (set.getRight().getChamberBlocks() == null) { + bugged = true; + return; + } + } + + for (ChamberSet set:chambers) { + if (set.getLeft().getChamberBlocks() == null) { + bugged = true; + return; + } + if (set.getRight().getChamberBlocks() == null) { + bugged = true; + return; + } + } + + for (ChamberSet set:chambers) { + for (BombDefuseChamberGenerator bdcg:chamberGenerators) { + if (bdcg.match(set.getLeft(), set.getRight())) { + set.setChamberGen(bdcg); + set.getLeft().setProcessor(bdcg.createLeft(set.getLeft())); + set.getRight().setProcessor(bdcg.createLeft(set.getRight())); + break; + } + } + if (set.getChamberGen() == null) { + set.setChamberGen(null); + set.getLeft().setProcessor(new DummyDefuseChamberProcessor()); + set.getRight().setProcessor(new DummyDefuseChamberProcessor()); + } + } + } + + public BDChamber buildChamber(OffsetPointSet ops, int level, boolean left) { + return new BDChamber(getDungeonRoom(), ops, left, level, null); + } + + + public void communicate(NBTTagCompound compound) { + if (bugged) return; + try { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + DataOutputStream w = new DataOutputStream(baos); + CompressedStreamTools.write(compound, w); + w.flush(); + byte[] bytes = baos.toByteArray(); + String str = Base64.encode(bytes); + Minecraft.getMinecraft().thePlayer.sendChatMessage("/pc " +str); + } catch (IOException e2) { + e2.printStackTrace(); + e.sendDebugChat(new ChatComponentText("Failed to send Bomb Defuse Chat")); + } + } + + @Override + public void chatReceived(IChatComponent component) { + super.chatReceived(component); + if (bugged) return; + + if (component.getFormattedText().contains("$DG-BD")) { + try { + String data = component.getFormattedText().substring(component.getFormattedText().indexOf("$DG-BD")); + String actual = TextUtils.stripColor(data); + byte[] data2 = Base64.decode(actual); + NBTTagCompound compound = CompressedStreamTools.readCompressed(new ByteArrayInputStream(data2)); + + for (ChamberSet ch:chambers) { + if (ch.getLeft() != null && ch.getLeft().getProcessor() != null) + ch.getLeft().getProcessor().onDataRecieve(compound); + if (ch.getRight() != null && ch.getRight().getProcessor() != null) + ch.getRight().getProcessor().onDataRecieve(compound); + } + } catch (Throwable t) { + t.printStackTrace(); + e.sendDebugChat(new ChatComponentText("Failed to analyze Bomb Defuse Chat")); + } + } + } + + + @Override + public void tick() { + super.tick(); + } + + @Override + public void drawScreen(float partialTicks) { + super.drawScreen(partialTicks); + + if (bugged) return; + + for (ChamberSet ch:chambers) { + if (ch.getLeft() != null && ch.getLeft().getProcessor() != null) + ch.getLeft().getProcessor().drawScreen(partialTicks); + if (ch.getRight() != null && ch.getRight().getProcessor() != null) + ch.getRight().getProcessor().drawScreen(partialTicks); + } + } + + @Override + public void drawWorld(float partialTicks) { + super.drawWorld(partialTicks); + if (bugged) return; + + for (ChamberSet ch:chambers) { + if (ch.getLeft() != null && ch.getLeft().getProcessor() != null) + ch.getLeft().getProcessor().drawWorld(partialTicks); + if (ch.getRight() != null && ch.getRight().getProcessor() != null) + ch.getRight().getProcessor().drawWorld(partialTicks); + } + } + + @Override + public void actionbarReceived(IChatComponent chat) { + super.actionbarReceived(chat); + if (bugged) return; + + for (ChamberSet ch:chambers) { + if (ch.getLeft() != null && ch.getLeft().getProcessor() != null) + ch.getLeft().getProcessor().actionbarReceived(chat); + if (ch.getRight() != null && ch.getRight().getProcessor() != null) + ch.getRight().getProcessor().actionbarReceived(chat); + } + } + + @Override + public void onPostGuiRender(GuiScreenEvent.DrawScreenEvent.Post event) { + super.onPostGuiRender(event); + if (bugged) return; + + for (ChamberSet ch:chambers) { + if (ch.getLeft() != null && ch.getLeft().getProcessor() != null) + ch.getLeft().getProcessor().onPostGuiRender(event); + if (ch.getRight() != null && ch.getRight().getProcessor() != null) + ch.getRight().getProcessor().onPostGuiRender(event); + } + } + + @Override + public void onEntitySpawn(LivingEvent.LivingUpdateEvent updateEvent) { + super.onEntitySpawn(updateEvent); + if (bugged) return; + + for (ChamberSet ch:chambers) { + if (ch.getLeft() != null && ch.getLeft().getProcessor() != null) + ch.getLeft().getProcessor().onEntitySpawn(updateEvent); + if (ch.getRight() != null && ch.getRight().getProcessor() != null) + ch.getRight().getProcessor().onEntitySpawn(updateEvent); + } + } + + + + @Override public boolean readGlobalChat() { return true; } + + @Data + @AllArgsConstructor + public static class ChamberSet { + private BDChamber left; + private BDChamber right; + private BombDefuseChamberGenerator chamberGen; + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/bombdefuse/chambers/BDChamber.java b/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/bombdefuse/chambers/BDChamber.java new file mode 100644 index 00000000..06e2e707 --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/bombdefuse/chambers/BDChamber.java @@ -0,0 +1,43 @@ +package kr.syeyoung.dungeonsguide.roomprocessor.bombdefuse.chambers; + +import kr.syeyoung.dungeonsguide.dungeon.data.OffsetPoint; +import kr.syeyoung.dungeonsguide.dungeon.data.OffsetPointSet; +import kr.syeyoung.dungeonsguide.dungeon.roomfinder.DungeonRoom; +import lombok.AllArgsConstructor; +import lombok.Data; +import net.minecraft.block.state.IBlockState; +import net.minecraft.util.BlockPos; + +@AllArgsConstructor +@Data +public class BDChamber { + private DungeonRoom room; + private OffsetPointSet chamberBlocks; + + private boolean isLeft; + private int level; + + private ChamberProcessor processor; + + // for whatever's sake, 6: z, 9: x. Starts from botoom right, left, then up + + public OffsetPoint getOffsetPoint(int x, int z) { + return chamberBlocks.getOffsetPointList().get(z * 9 + x); + } + + public BlockPos getBlockPos(int x, int y, int z) { + return getOffsetPoint(x,z).getBlockPos(room).add(0,y,0); + } + + public IBlockState getBlock(int x, int y, int z) { + BlockPos pos = getBlockPos(x,y,z); + return room.getContext().getWorld().getBlockState(pos); + } + + public boolean isWithinAbsolute(int x, int y, int z) { + return isWithinAbsolute(new BlockPos(x,y,z)); + } + public boolean isWithinAbsolute(BlockPos pos) { + return chamberBlocks.getOffsetPointList().contains(new OffsetPoint(room, pos)); + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/bombdefuse/chambers/BombDefuseChamberGenerator.java b/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/bombdefuse/chambers/BombDefuseChamberGenerator.java new file mode 100644 index 00000000..92b294ac --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/bombdefuse/chambers/BombDefuseChamberGenerator.java @@ -0,0 +1,10 @@ +package kr.syeyoung.dungeonsguide.roomprocessor.bombdefuse.chambers; + +public interface BombDefuseChamberGenerator { + public boolean match(BDChamber left, BDChamber right); + + public String getName(); + + public ChamberProcessor createLeft(BDChamber left); + public ChamberProcessor createRight(BDChamber right); +}
\ No newline at end of file diff --git a/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/bombdefuse/chambers/ChamberProcessor.java b/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/bombdefuse/chambers/ChamberProcessor.java new file mode 100644 index 00000000..fc661cd3 --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/bombdefuse/chambers/ChamberProcessor.java @@ -0,0 +1,9 @@ +package kr.syeyoung.dungeonsguide.roomprocessor.bombdefuse.chambers; + +import kr.syeyoung.dungeonsguide.roomprocessor.RoomProcessor; +import net.minecraft.nbt.NBTTagCompound; + +public interface ChamberProcessor extends RoomProcessor { + public void onDataRecieve(NBTTagCompound compound); + public String getName(); +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/bombdefuse/chambers/DummyDefuseChamberProcessor.java b/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/bombdefuse/chambers/DummyDefuseChamberProcessor.java new file mode 100644 index 00000000..313f79b4 --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/bombdefuse/chambers/DummyDefuseChamberProcessor.java @@ -0,0 +1,10 @@ +package kr.syeyoung.dungeonsguide.roomprocessor.bombdefuse.chambers; + +import kr.syeyoung.dungeonsguide.roomprocessor.GeneralRoomProcessor; + +public class DummyDefuseChamberProcessor extends GeneralDefuseChamberProcessor { + @Override + public String getName() { + return "dummy"; + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/bombdefuse/chambers/GeneralDefuseChamberProcessor.java b/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/bombdefuse/chambers/GeneralDefuseChamberProcessor.java new file mode 100644 index 00000000..85314d75 --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/bombdefuse/chambers/GeneralDefuseChamberProcessor.java @@ -0,0 +1,53 @@ +package kr.syeyoung.dungeonsguide.roomprocessor.bombdefuse.chambers; + +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.IChatComponent; +import net.minecraftforge.client.event.GuiScreenEvent; +import net.minecraftforge.event.entity.living.LivingEvent; + +public abstract class GeneralDefuseChamberProcessor implements ChamberProcessor{ + @Override + public void onDataRecieve(NBTTagCompound compound) { + + } + + @Override + public void tick() { + + } + + @Override + public void drawScreen(float partialTicks) { + + } + + @Override + public void drawWorld(float partialTicks) { + + } + + @Override + public void chatReceived(IChatComponent chat) { + + } + + @Override + public void actionbarReceived(IChatComponent chat) { + + } + + @Override + public boolean readGlobalChat() { + return false; + } + + @Override + public void onPostGuiRender(GuiScreenEvent.DrawScreenEvent.Post event) { + + } + + @Override + public void onEntitySpawn(LivingEvent.LivingUpdateEvent updateEvent) { + + } +} |