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.
This commit is contained in:
Stephen Seo 2018-09-14 12:44:45 +09:00
parent 6a97a90d68
commit 5f70253955
9 changed files with 161 additions and 23 deletions

View file

@ -165,11 +165,11 @@ public class BattleGui extends GuiScreen
{ {
if(e.getValue().entity != null) 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 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; y += 20;
} }
@ -178,11 +178,11 @@ public class BattleGui extends GuiScreen
{ {
if(e.getValue().entity != null) 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 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; y += 20;
} }
@ -350,6 +350,9 @@ public class BattleGui extends GuiScreen
@Override @Override
protected void keyTyped(char typedChar, int keyCode) throws IOException 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);
}
} }
} }

View file

@ -1,6 +1,7 @@
package com.seodisparate.TurnBasedMinecraft.client; package com.seodisparate.TurnBasedMinecraft.client;
import com.seodisparate.TurnBasedMinecraft.common.CommonProxy; import com.seodisparate.TurnBasedMinecraft.common.CommonProxy;
import com.seodisparate.TurnBasedMinecraft.common.TurnBasedMinecraftMod;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
@ -49,4 +50,14 @@ public class ClientProxy extends CommonProxy
{ {
battleGui.turnEnd(); battleGui.turnEnd();
} }
@Override
public void battleEnded()
{
TurnBasedMinecraftMod.currentBattle = null;
Minecraft.getMinecraft().addScheduledTask(() -> {
Minecraft.getMinecraft().displayGuiScreen(null);
Minecraft.getMinecraft().setIngameFocus();
});
}
} }

View file

@ -1,19 +1,93 @@
package com.seodisparate.TurnBasedMinecraft.client; package com.seodisparate.TurnBasedMinecraft.client;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiButton;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
public class EntitySelectionButton extends GuiButton public class EntitySelectionButton extends GuiButton
{ {
public int entityID; 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); super(buttonId, x, y, buttonText);
this.entityID = entityID; 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); super(buttonId, x, y, widthIn, heightIn, buttonText);
this.entityID = entityID; 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);
}
}
} }
} }

View file

@ -357,6 +357,11 @@ public class Battle
return timer / 1000000000; return timer / 1000000000;
} }
public int getSize()
{
return sideA.size() + sideB.size();
}
protected void notifyPlayersBattleInfo() protected void notifyPlayersBattleInfo()
{ {
if(!isServer) if(!isServer)
@ -455,6 +460,28 @@ public class Battle
return didRemove; 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 * @return True if battle has ended
*/ */
@ -538,6 +565,7 @@ public class Battle
else else
{ {
healthCheck(); healthCheck();
isCreativeCheck();
} }
break; break;
case ACTION: case ACTION:
@ -872,6 +900,7 @@ public class Battle
state = State.DECISION; state = State.DECISION;
undecidedCount.set(players.size()); undecidedCount.set(players.size());
healthCheck(); healthCheck();
isCreativeCheck();
sendMessageToAllPlayers(PacketBattleMessage.MessageType.TURN_END, 0, 0, 0); sendMessageToAllPlayers(PacketBattleMessage.MessageType.TURN_END, 0, 0, 0);
break; break;
} // case ACTION } // case ACTION

View file

@ -135,6 +135,11 @@ public class BattleManager
} }
// at this point only one entity is in battle, so add entity to other side // 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())) if(battle.hasCombatantInSideA(inBattle.getEntityId()))
{ {
battle.addCombatantToSideB(notInBattle); battle.addCombatantToSideB(notInBattle);

View file

@ -11,4 +11,6 @@ public class CommonProxy
public void battleGuiTurnBegin() {} public void battleGuiTurnBegin() {}
public void battleGuiTurnEnd() {} public void battleGuiTurnEnd() {}
public void battleEnded() {}
} }

View file

@ -34,6 +34,7 @@ public class Config
private int fleeGoodProbability = 90; private int fleeGoodProbability = 90;
private int fleeBadProbability = 40; private int fleeBadProbability = 40;
private int minimumHitPercentage = 1; private int minimumHitPercentage = 1;
private int maxInBattle = 8;
public Config(Logger logger) public Config(Logger logger)
{ {
@ -154,6 +155,10 @@ public class Config
{ {
continue; continue;
} }
else if(xmlReader.getLocalName().equals("MaxInBattle"))
{
maxInBattle = Integer.parseInt(xmlReader.getElementText());
}
else if(xmlReader.getLocalName().equals("IgnoreBattleTypes")) else if(xmlReader.getLocalName().equals("IgnoreBattleTypes"))
{ {
do do
@ -444,4 +449,9 @@ public class Config
{ {
return minimumHitPercentage; return minimumHitPercentage;
} }
public int getMaxInBattle()
{
return maxInBattle;
}
} }

View file

@ -35,7 +35,8 @@ public class PacketBattleMessage implements IMessage
TURN_BEGIN(11), TURN_BEGIN(11),
TURN_END(12), TURN_END(12),
SWITCHED_ITEM(13), SWITCHED_ITEM(13),
WAS_AFFECTED(14); WAS_AFFECTED(14),
BECAME_CREATIVE(15);
private int value; private int value;
private static Map<Integer, MessageType> map = new HashMap<Integer, MessageType>(); private static Map<Integer, MessageType> map = new HashMap<Integer, MessageType>();
@ -252,10 +253,7 @@ public class PacketBattleMessage implements IMessage
case ENDED: case ENDED:
Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(new TextComponentString( Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(new TextComponentString(
"Battle has ended!")); "Battle has ended!"));
TurnBasedMinecraftMod.currentBattle = null; TurnBasedMinecraftMod.commonProxy.battleEnded();
Minecraft.getMinecraft().addScheduledTask(() -> {
Minecraft.getMinecraft().setIngameFocus();
});
break; break;
case ATTACK: case ATTACK:
Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(new TextComponentString( Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(new TextComponentString(
@ -286,33 +284,33 @@ public class PacketBattleMessage implements IMessage
{ {
case USED_NOTHING: case USED_NOTHING:
Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(new TextComponentString( Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(new TextComponentString(
from + " tried to use nothing!")); from + " tried to use nothing!"));
break; break;
case USED_INVALID: case USED_INVALID:
if(message.custom.length() > 0) if(message.custom.length() > 0)
{ {
Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(new TextComponentString( Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(new TextComponentString(
from + " tried to consume " + message.custom + " and failed!")); from + " tried to consume " + message.custom + " and failed!"));
} }
else else
{ {
Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(new TextComponentString( 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; break;
case USED_FOOD: case USED_FOOD:
Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(new TextComponentString( Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(new TextComponentString(
from + " ate a " + message.custom + "!")); from + " ate a " + message.custom + "!"));
break; break;
case USED_POTION: case USED_POTION:
Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(new TextComponentString( Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(new TextComponentString(
from + " drank a " + message.custom + "!")); from + " drank a " + message.custom + "!"));
break; break;
} }
break; break;
case TURN_BEGIN: case TURN_BEGIN:
Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(new TextComponentString( Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(new TextComponentString(
"The turn begins!")); "The turn begins!"));
TurnBasedMinecraftMod.commonProxy.battleGuiTurnBegin(); TurnBasedMinecraftMod.commonProxy.battleGuiTurnBegin();
break; break;
case TURN_END: case TURN_END:
@ -327,18 +325,22 @@ public class PacketBattleMessage implements IMessage
if(message.amount != 0) if(message.amount != 0)
{ {
Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(new TextComponentString( Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(new TextComponentString(
from + " switched to a different item!")); from + " switched to a different item!"));
} }
else else
{ {
Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(new TextComponentString( 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; break;
case WAS_AFFECTED: case WAS_AFFECTED:
Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(new TextComponentString( Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(new TextComponentString(
to + " was " + message.custom + " by " + from + "!")); to + " was " + message.custom + " by " + from + "!"));
break; break;
case BECAME_CREATIVE:
Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(new TextComponentString(
from + " entered creative mode and left battle!"));
break;
} }
return null; return null;
} }

View file

@ -1,11 +1,13 @@
<TurnBasedMinecraftConfig> <TurnBasedMinecraftConfig>
<!-- If the mod has a newer version config, it will rename the existing config and place the new config --> <!-- If the mod has a newer version config, it will rename the existing config and place the new config -->
<Version>2</Version> <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. <!-- 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. --> Note that items listed in "IgnoreBattleTypes" and "Category" are converted to lowercase before being compared. -->
<IgnoreBattleTypes> <IgnoreBattleTypes>
<Passive></Passive> <passive></passive>
<Boss></Boss> <boss></boss>
</IgnoreBattleTypes> </IgnoreBattleTypes>
<PlayerStats> <PlayerStats>
<Speed>50</Speed> <Speed>50</Speed>