From: Stephen Seo Date: Fri, 14 Sep 2018 03:44:45 +0000 (+0900) Subject: Fixes, improvements X-Git-Tag: 1.0~25 X-Git-Url: https://git.seodisparate.com/gitweb?a=commitdiff_plain;h=5f702539555af4a7c83161d4bca283cb5ab09e84;p=TurnBasedMinecraftMod Fixes, improvements BattleGui now displays health of all combatants. Players can leave battle by entering creative mode (set by server). Added battle size limit (default 8) can be set in config. --- diff --git a/src/main/java/com/seodisparate/TurnBasedMinecraft/client/BattleGui.java b/src/main/java/com/seodisparate/TurnBasedMinecraft/client/BattleGui.java index 5948705..8ba8051 100644 --- a/src/main/java/com/seodisparate/TurnBasedMinecraft/client/BattleGui.java +++ b/src/main/java/com/seodisparate/TurnBasedMinecraft/client/BattleGui.java @@ -165,11 +165,11 @@ public class BattleGui extends GuiScreen { if(e.getValue().entity != null) { - buttonList.add(new EntitySelectionButton(ButtonAction.ATTACK_TARGET.getValue(), width/4 - 60, y, 120, 20, e.getValue().entity.getName(), e.getKey())); + buttonList.add(new EntitySelectionButton(ButtonAction.ATTACK_TARGET.getValue(), width/4 - 60, y, 120, 20, e.getValue().entity.getName(), e.getKey(), true)); } else { - buttonList.add(new EntitySelectionButton(ButtonAction.ATTACK_TARGET.getValue(), width/4 - 60, y, 120, 20, "Unknown", e.getKey())); + buttonList.add(new EntitySelectionButton(ButtonAction.ATTACK_TARGET.getValue(), width/4 - 60, y, 120, 20, "Unknown", e.getKey(), true)); } y += 20; } @@ -178,11 +178,11 @@ public class BattleGui extends GuiScreen { if(e.getValue().entity != null) { - buttonList.add(new EntitySelectionButton(ButtonAction.ATTACK_TARGET.getValue(), width*3/4 - 60, y, 120, 20, e.getValue().entity.getName(), e.getKey())); + buttonList.add(new EntitySelectionButton(ButtonAction.ATTACK_TARGET.getValue(), width*3/4 - 60, y, 120, 20, e.getValue().entity.getName(), e.getKey(), false)); } else { - buttonList.add(new EntitySelectionButton(ButtonAction.ATTACK_TARGET.getValue(), width*3/4 - 60, y, 120, 20, "Unknown", e.getKey())); + buttonList.add(new EntitySelectionButton(ButtonAction.ATTACK_TARGET.getValue(), width*3/4 - 60, y, 120, 20, "Unknown", e.getKey(), false)); } y += 20; } @@ -350,6 +350,9 @@ public class BattleGui extends GuiScreen @Override protected void keyTyped(char typedChar, int keyCode) throws IOException { - // left blank to prevent the player from exiting the gui + if(Minecraft.getMinecraft().player.isCreative()) + { + super.keyTyped(typedChar, keyCode); + } } } diff --git a/src/main/java/com/seodisparate/TurnBasedMinecraft/client/ClientProxy.java b/src/main/java/com/seodisparate/TurnBasedMinecraft/client/ClientProxy.java index baed4f4..05583a8 100644 --- a/src/main/java/com/seodisparate/TurnBasedMinecraft/client/ClientProxy.java +++ b/src/main/java/com/seodisparate/TurnBasedMinecraft/client/ClientProxy.java @@ -1,6 +1,7 @@ package com.seodisparate.TurnBasedMinecraft.client; import com.seodisparate.TurnBasedMinecraft.common.CommonProxy; +import com.seodisparate.TurnBasedMinecraft.common.TurnBasedMinecraftMod; import net.minecraft.client.Minecraft; @@ -49,4 +50,14 @@ public class ClientProxy extends CommonProxy { battleGui.turnEnd(); } + + @Override + public void battleEnded() + { + TurnBasedMinecraftMod.currentBattle = null; + Minecraft.getMinecraft().addScheduledTask(() -> { + Minecraft.getMinecraft().displayGuiScreen(null); + Minecraft.getMinecraft().setIngameFocus(); + }); + } } diff --git a/src/main/java/com/seodisparate/TurnBasedMinecraft/client/EntitySelectionButton.java b/src/main/java/com/seodisparate/TurnBasedMinecraft/client/EntitySelectionButton.java index d63476b..8b07fc5 100644 --- a/src/main/java/com/seodisparate/TurnBasedMinecraft/client/EntitySelectionButton.java +++ b/src/main/java/com/seodisparate/TurnBasedMinecraft/client/EntitySelectionButton.java @@ -1,19 +1,93 @@ package com.seodisparate.TurnBasedMinecraft.client; +import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; public class EntitySelectionButton extends GuiButton { public int entityID; - public EntitySelectionButton(int buttonId, int x, int y, String buttonText, int entityID) + private boolean isSideA; + public EntitySelectionButton(int buttonId, int x, int y, String buttonText, int entityID, boolean isSideA) { super(buttonId, x, y, buttonText); this.entityID = entityID; + this.isSideA = isSideA; } - public EntitySelectionButton(int buttonId, int x, int y, int widthIn, int heightIn, String buttonText, int entityID) + public EntitySelectionButton(int buttonId, int x, int y, int widthIn, int heightIn, String buttonText, int entityID, boolean isSideA) { super(buttonId, x, y, widthIn, heightIn, buttonText); this.entityID = entityID; + this.isSideA = isSideA; + } + + @Override + public void drawButton(Minecraft mc, int mouseX, int mouseY, float partialTicks) + { + super.drawButton(mc, mouseX, mouseY, partialTicks); + Entity e = Minecraft.getMinecraft().world.getEntityByID(entityID); + if(e != null && e instanceof EntityLivingBase && ((EntityLivingBase)e).isEntityAlive()) + { + int health = (int)(((EntityLivingBase)e).getHealth() + 0.5f); + int xpos = x; + int xoffset; + if(isSideA) + { + xpos += width + 4; + xoffset = 4; + } + else + { + xpos -= 6; + xoffset = -4; + } + if(health > 200) + { + drawRect(xpos, y + height * 4 / 5, xpos + 2, y + height , 0xFFFF0000); + drawRect(xpos, y + height * 3 / 5, xpos + 2, y + height * 4 / 5, 0xFFFFFF00); + drawRect(xpos, y + height * 2 / 5, xpos + 2, y + height * 3 / 5, 0xFF00FF00); + drawRect(xpos, y + height / 5, xpos + 2, y + height * 2 / 5, 0xFF00FFFF); + drawRect(xpos, y , xpos + 2, y + height / 5, 0xFF0000FF); + int healthHeight = ((health - 200) * height / 100); + drawRect(xpos + xoffset, y + height - healthHeight, xpos + xoffset + 2, y + height, 0xFFFFFFFF); + } + else if(health > 100) + { + drawRect(xpos, y + height * 4 / 5, xpos + 2, y + height , 0xFFFF0000); + drawRect(xpos, y + height * 3 / 5, xpos + 2, y + height * 4 / 5, 0xFFFFFF00); + drawRect(xpos, y + height * 2 / 5, xpos + 2, y + height * 3 / 5, 0xFF00FF00); + drawRect(xpos, y + height / 5, xpos + 2, y + height * 2 / 5, 0xFF00FFFF); + int healthHeight = ((health - 100) * height / 100); + drawRect(xpos + xoffset, y + height - healthHeight, xpos + xoffset + 2, y + height, 0xFF0000FF); + } + else if(health > 50) + { + drawRect(xpos, y + height * 4 / 5, xpos + 2, y + height , 0xFFFF0000); + drawRect(xpos, y + height * 3 / 5, xpos + 2, y + height * 4 / 5, 0xFFFFFF00); + drawRect(xpos, y + height * 2 / 5, xpos + 2, y + height * 3 / 5, 0xFF00FF00); + int healthHeight = ((health - 50) * height / 50); + drawRect(xpos + xoffset, y + height - healthHeight, xpos + xoffset + 2, y + height, 0xFF00FFFF); + } + else if(health > 20) + { + drawRect(xpos, y + height * 4 / 5, xpos + 2, y + height , 0xFFFF0000); + drawRect(xpos, y + height * 3 / 5, xpos + 2, y + height * 4 / 5, 0xFFFFFF00); + int healthHeight = ((health - 20) * height / 30); + drawRect(xpos + xoffset, y + height - healthHeight, xpos + xoffset + 2, y + height, 0xFF00FF00); + } + else if(health > 10) + { + drawRect(xpos, y + height * 4 / 5, xpos + 2, y + height, 0xFFFF0000); + int healthHeight = ((health - 10) * height / 10); + drawRect(xpos + xoffset, y + height - healthHeight, xpos + xoffset + 2, y + height, 0xFFFFFF00); + } + else + { + int healthHeight = (health * height / 10); + drawRect(xpos + xoffset, y + height - healthHeight, xpos + xoffset + 2, y + height, 0xFFFF0000); + } + } } } diff --git a/src/main/java/com/seodisparate/TurnBasedMinecraft/common/Battle.java b/src/main/java/com/seodisparate/TurnBasedMinecraft/common/Battle.java index 19380dc..97367d1 100644 --- a/src/main/java/com/seodisparate/TurnBasedMinecraft/common/Battle.java +++ b/src/main/java/com/seodisparate/TurnBasedMinecraft/common/Battle.java @@ -357,6 +357,11 @@ public class Battle return timer / 1000000000; } + public int getSize() + { + return sideA.size() + sideB.size(); + } + protected void notifyPlayersBattleInfo() { if(!isServer) @@ -455,6 +460,28 @@ public class Battle return didRemove; } + private void isCreativeCheck() + { + Queue removeQueue = new ArrayDeque(); + for(Combatant c : players.values()) + { + if(c.entity != null && ((EntityPlayer)c.entity).isCreative()) + { + TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketBattleMessage(PacketBattleMessage.MessageType.ENDED, c.entity.getEntityId(), 0, 0), (EntityPlayerMP)c.entity); + removeQueue.add(c.entity.getEntityId()); + } + } + Integer toRemove = removeQueue.poll(); + while(toRemove != null) + { + sideA.remove(toRemove); + sideB.remove(toRemove); + players.remove(toRemove); + playerCount.decrementAndGet(); + sendMessageToAllPlayers(PacketBattleMessage.MessageType.BECAME_CREATIVE, toRemove, 0, 0); + } + } + /** * @return True if battle has ended */ @@ -538,6 +565,7 @@ public class Battle else { healthCheck(); + isCreativeCheck(); } break; case ACTION: @@ -872,6 +900,7 @@ public class Battle state = State.DECISION; undecidedCount.set(players.size()); healthCheck(); + isCreativeCheck(); sendMessageToAllPlayers(PacketBattleMessage.MessageType.TURN_END, 0, 0, 0); break; } // case ACTION diff --git a/src/main/java/com/seodisparate/TurnBasedMinecraft/common/BattleManager.java b/src/main/java/com/seodisparate/TurnBasedMinecraft/common/BattleManager.java index 5679e78..faae46b 100644 --- a/src/main/java/com/seodisparate/TurnBasedMinecraft/common/BattleManager.java +++ b/src/main/java/com/seodisparate/TurnBasedMinecraft/common/BattleManager.java @@ -133,8 +133,13 @@ public class BattleManager } return false; } - + // at this point only one entity is in battle, so add entity to other side + if(battle.getSize() >= TurnBasedMinecraftMod.config.getMaxInBattle()) + { + // battle limit reached, cannot add to battle + return true; + } if(battle.hasCombatantInSideA(inBattle.getEntityId())) { battle.addCombatantToSideB(notInBattle); diff --git a/src/main/java/com/seodisparate/TurnBasedMinecraft/common/CommonProxy.java b/src/main/java/com/seodisparate/TurnBasedMinecraft/common/CommonProxy.java index 6cd8421..f966911 100644 --- a/src/main/java/com/seodisparate/TurnBasedMinecraft/common/CommonProxy.java +++ b/src/main/java/com/seodisparate/TurnBasedMinecraft/common/CommonProxy.java @@ -11,4 +11,6 @@ public class CommonProxy public void battleGuiTurnBegin() {} public void battleGuiTurnEnd() {} + + public void battleEnded() {} } diff --git a/src/main/java/com/seodisparate/TurnBasedMinecraft/common/Config.java b/src/main/java/com/seodisparate/TurnBasedMinecraft/common/Config.java index a3d146f..50c4b94 100644 --- a/src/main/java/com/seodisparate/TurnBasedMinecraft/common/Config.java +++ b/src/main/java/com/seodisparate/TurnBasedMinecraft/common/Config.java @@ -34,6 +34,7 @@ public class Config private int fleeGoodProbability = 90; private int fleeBadProbability = 40; private int minimumHitPercentage = 1; + private int maxInBattle = 8; public Config(Logger logger) { @@ -154,6 +155,10 @@ public class Config { continue; } + else if(xmlReader.getLocalName().equals("MaxInBattle")) + { + maxInBattle = Integer.parseInt(xmlReader.getElementText()); + } else if(xmlReader.getLocalName().equals("IgnoreBattleTypes")) { do @@ -444,4 +449,9 @@ public class Config { return minimumHitPercentage; } + + public int getMaxInBattle() + { + return maxInBattle; + } } diff --git a/src/main/java/com/seodisparate/TurnBasedMinecraft/common/networking/PacketBattleMessage.java b/src/main/java/com/seodisparate/TurnBasedMinecraft/common/networking/PacketBattleMessage.java index 0a776f1..3c46888 100644 --- a/src/main/java/com/seodisparate/TurnBasedMinecraft/common/networking/PacketBattleMessage.java +++ b/src/main/java/com/seodisparate/TurnBasedMinecraft/common/networking/PacketBattleMessage.java @@ -35,7 +35,8 @@ public class PacketBattleMessage implements IMessage TURN_BEGIN(11), TURN_END(12), SWITCHED_ITEM(13), - WAS_AFFECTED(14); + WAS_AFFECTED(14), + BECAME_CREATIVE(15); private int value; private static Map map = new HashMap(); @@ -252,10 +253,7 @@ public class PacketBattleMessage implements IMessage case ENDED: Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(new TextComponentString( "Battle has ended!")); - TurnBasedMinecraftMod.currentBattle = null; - Minecraft.getMinecraft().addScheduledTask(() -> { - Minecraft.getMinecraft().setIngameFocus(); - }); + TurnBasedMinecraftMod.commonProxy.battleEnded(); break; case ATTACK: Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(new TextComponentString( @@ -286,33 +284,33 @@ public class PacketBattleMessage implements IMessage { case USED_NOTHING: Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(new TextComponentString( - from + " tried to use nothing!")); + from + " tried to use nothing!")); break; case USED_INVALID: if(message.custom.length() > 0) { Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(new TextComponentString( - from + " tried to consume " + message.custom + " and failed!")); + from + " tried to consume " + message.custom + " and failed!")); } else { Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(new TextComponentString( - from + " tried to consume an invalid item and failed!")); + from + " tried to consume an invalid item and failed!")); } break; case USED_FOOD: Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(new TextComponentString( - from + " ate a " + message.custom + "!")); + from + " ate a " + message.custom + "!")); break; case USED_POTION: Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(new TextComponentString( - from + " drank a " + message.custom + "!")); + from + " drank a " + message.custom + "!")); break; } break; case TURN_BEGIN: Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(new TextComponentString( - "The turn begins!")); + "The turn begins!")); TurnBasedMinecraftMod.commonProxy.battleGuiTurnBegin(); break; case TURN_END: @@ -327,18 +325,22 @@ public class PacketBattleMessage implements IMessage if(message.amount != 0) { Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(new TextComponentString( - from + " switched to a different item!")); + from + " switched to a different item!")); } else { Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(new TextComponentString( - from + " switched to a different item but failed because it was invalid!")); + from + " switched to a different item but failed because it was invalid!")); } break; case WAS_AFFECTED: Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(new TextComponentString( to + " was " + message.custom + " by " + from + "!")); break; + case BECAME_CREATIVE: + Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(new TextComponentString( + from + " entered creative mode and left battle!")); + break; } return null; } diff --git a/src/main/resources/assets/TurnBasedMinecraft/TBM_Config.xml b/src/main/resources/assets/TurnBasedMinecraft/TBM_Config.xml index 5194493..1983454 100644 --- a/src/main/resources/assets/TurnBasedMinecraft/TBM_Config.xml +++ b/src/main/resources/assets/TurnBasedMinecraft/TBM_Config.xml @@ -1,11 +1,13 @@ 2 + + 8 - - + + 50