]> git.seodisparate.com - TurnBasedMinecraftMod/commitdiff
Fixes, improvements
authorStephen Seo <seo.disparate@gmail.com>
Fri, 14 Sep 2018 03:44:45 +0000 (12:44 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Fri, 14 Sep 2018 03:44:45 +0000 (12:44 +0900)
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.

src/main/java/com/seodisparate/TurnBasedMinecraft/client/BattleGui.java
src/main/java/com/seodisparate/TurnBasedMinecraft/client/ClientProxy.java
src/main/java/com/seodisparate/TurnBasedMinecraft/client/EntitySelectionButton.java
src/main/java/com/seodisparate/TurnBasedMinecraft/common/Battle.java
src/main/java/com/seodisparate/TurnBasedMinecraft/common/BattleManager.java
src/main/java/com/seodisparate/TurnBasedMinecraft/common/CommonProxy.java
src/main/java/com/seodisparate/TurnBasedMinecraft/common/Config.java
src/main/java/com/seodisparate/TurnBasedMinecraft/common/networking/PacketBattleMessage.java
src/main/resources/assets/TurnBasedMinecraft/TBM_Config.xml

index 5948705032ac7b103062bc92a914fc9eae67adef..8ba80517529e4cfe7642ad6f1984f9d6695ea3f7 100644 (file)
@@ -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);
+        }
     }
 }
index baed4f4ed00821d42ada66965e40b20d7abe574e..05583a85adac0b042002adea0c084b248674521c 100644 (file)
@@ -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();
+        });
+    }
 }
index d63476b969cb55880e51a50c8ac6f3788461d2ae..8b07fc58f2d257ef23122dfdf81b477b93af25f8 100644 (file)
@@ -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);
+            }
+        }
     }
 }
index 19380dca3ad070383425cb91240f2e1cccaf2355..97367d17ed7e2f1eac36db95ab1bf7808ee2cdc3 100644 (file)
@@ -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<Integer> removeQueue = new ArrayDeque<Integer>();
+        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
index 5679e78befb66eac3927f2c29d83c7885ef7cfe2..faae46bae207b7f871c3be5c1010e11312c1f3ef 100644 (file)
@@ -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);
index 6cd8421e5c18571feed27289f328b1f4585c8afe..f9669110c6831268e4fc2510156a92138d6f1d99 100644 (file)
@@ -11,4 +11,6 @@ public class CommonProxy
     public void battleGuiTurnBegin() {}
     
     public void battleGuiTurnEnd() {}
+    
+    public void battleEnded() {}
 }
index a3d146f88245f8f5c927c4c3b676f7cd5d7d8c56..50c4b94f1da14b2d7909141c1bf196d2e4d0f385 100644 (file)
@@ -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;
+    }
 }
index 0a776f16c858bb043c2cf29c30fc10cc6a1fc519..3c46888189babcc40f938246c5ac25b30f33401b 100644 (file)
@@ -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<Integer, MessageType> map = new HashMap<Integer, MessageType>();
@@ -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;
         }
index 519449365997dba82c1cd0bee3dad6dfaf25a1d9..19834545866c0326b7388d0c65c461951b66e284 100644 (file)
@@ -1,11 +1,13 @@
 <TurnBasedMinecraftConfig>
        <!-- If the mod has a newer version config, it will rename the existing config and place the new config -->
        <Version>2</Version>
+       <!-- If there are "MaxInBattle" amount of entities in battle, other entities cannot join until combatants leave battle. -->
+       <MaxInBattle>8</MaxInBattle>
        <!-- Types that will not initiate battle with player. They are listed as "Category" per EntiytStats entity.
                 Note that items listed in "IgnoreBattleTypes" and "Category" are converted to lowercase before being compared. -->
        <IgnoreBattleTypes>
-               <Passive></Passive>
-               <Boss></Boss>
+               <passive></passive>
+               <boss></boss>
        </IgnoreBattleTypes>
        <PlayerStats>
                <Speed>50</Speed>