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.
{
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;
}
{
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;
}
@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);
+ }
}
}
package com.seodisparate.TurnBasedMinecraft.client;
import com.seodisparate.TurnBasedMinecraft.common.CommonProxy;
+import com.seodisparate.TurnBasedMinecraft.common.TurnBasedMinecraftMod;
import net.minecraft.client.Minecraft;
{
battleGui.turnEnd();
}
+
+ @Override
+ public void battleEnded()
+ {
+ TurnBasedMinecraftMod.currentBattle = null;
+ Minecraft.getMinecraft().addScheduledTask(() -> {
+ Minecraft.getMinecraft().displayGuiScreen(null);
+ Minecraft.getMinecraft().setIngameFocus();
+ });
+ }
}
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);
+ }
+ }
}
}
return timer / 1000000000;
}
+ public int getSize()
+ {
+ return sideA.size() + sideB.size();
+ }
+
protected void notifyPlayersBattleInfo()
{
if(!isServer)
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
*/
else
{
healthCheck();
+ isCreativeCheck();
}
break;
case ACTION:
state = State.DECISION;
undecidedCount.set(players.size());
healthCheck();
+ isCreativeCheck();
sendMessageToAllPlayers(PacketBattleMessage.MessageType.TURN_END, 0, 0, 0);
break;
} // case ACTION
}
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);
public void battleGuiTurnBegin() {}
public void battleGuiTurnEnd() {}
+
+ public void battleEnded() {}
}
private int fleeGoodProbability = 90;
private int fleeBadProbability = 40;
private int minimumHitPercentage = 1;
+ private int maxInBattle = 8;
public Config(Logger logger)
{
{
continue;
}
+ else if(xmlReader.getLocalName().equals("MaxInBattle"))
+ {
+ maxInBattle = Integer.parseInt(xmlReader.getElementText());
+ }
else if(xmlReader.getLocalName().equals("IgnoreBattleTypes"))
{
do
{
return minimumHitPercentage;
}
+
+ public int getMaxInBattle()
+ {
+ return maxInBattle;
+ }
}
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>();
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(
{
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:
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;
}
<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>