Version 1.5, minor fixes

Food and potion consumption in battle is now handled more properly.
This commit is contained in:
Stephen Seo 2018-10-19 17:18:02 +09:00
parent 54207c6e80
commit bd7d7e16f3
5 changed files with 45 additions and 6 deletions

View file

@ -1,3 +1,10 @@
# Version 1.5
Fix proper consumption of food/potion items in battle.
Added some debug output on internal freeze occurrence (investigation of the
freeze bug is still ongoing).
# Version 1.4 # Version 1.4
Fix duplicate "... entered battle" messages. Fix duplicate "... entered battle" messages.

View file

@ -10,7 +10,7 @@ buildscript {
apply plugin: 'net.minecraftforge.gradle.forge' apply plugin: 'net.minecraftforge.gradle.forge'
//Only edit below this line, the above code adds and enables the necessary things for Forge to be setup. //Only edit below this line, the above code adds and enables the necessary things for Forge to be setup.
version = "1.4" version = "1.5"
group = "com.seodisparate.TurnBasedMinecraft" // http://maven.apache.org/guides/mini/guide-naming-conventions.html group = "com.seodisparate.TurnBasedMinecraft" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "TurnBasedMinecraft" archivesBaseName = "TurnBasedMinecraft"

View file

@ -52,6 +52,8 @@ public class Battle
private BattleManager battleManager; private BattleManager battleManager;
public String debugLog; // TODO remove after freeze bug has been found
public enum State public enum State
{ {
DECISION(0), DECISION(0),
@ -828,17 +830,22 @@ public class Battle
continue; continue;
} }
debugLog = next.entity.getName();
next.remainingDefenses = 0; next.remainingDefenses = 0;
switch(next.decision) switch(next.decision)
{ {
case UNDECIDED: case UNDECIDED:
debugLog += " undecided";
sendMessageToAllPlayers(PacketBattleMessage.MessageType.DID_NOTHING, next.entity.getEntityId(), 0, 0); sendMessageToAllPlayers(PacketBattleMessage.MessageType.DID_NOTHING, next.entity.getEntityId(), 0, 0);
break; break;
case ATTACK: case ATTACK:
debugLog += " attack";
Combatant target = null; Combatant target = null;
if(next.entity instanceof EntityPlayer) if(next.entity instanceof EntityPlayer)
{ {
debugLog += " as player";
target = sideA.get(next.targetEntityID); target = sideA.get(next.targetEntityID);
if(target == null) if(target == null)
{ {
@ -851,6 +858,7 @@ public class Battle
ItemStack heldItemStack = ((EntityPlayer)next.entity).getHeldItemMainhand(); ItemStack heldItemStack = ((EntityPlayer)next.entity).getHeldItemMainhand();
if(heldItemStack.getItem() instanceof ItemBow) if(heldItemStack.getItem() instanceof ItemBow)
{ {
debugLog += " with bow";
if(Utility.doesPlayerHaveArrows((EntityPlayer)next.entity)) if(Utility.doesPlayerHaveArrows((EntityPlayer)next.entity))
{ {
final Entity nextEntity = next.entity; final Entity nextEntity = next.entity;
@ -880,6 +888,7 @@ public class Battle
} }
continue; continue;
} }
debugLog += " without bow";
int hitChance = TurnBasedMinecraftMod.proxy.getConfig().getPlayerAttackProbability(); int hitChance = TurnBasedMinecraftMod.proxy.getConfig().getPlayerAttackProbability();
if(target.entity instanceof EntityPlayer) if(target.entity instanceof EntityPlayer)
{ {
@ -897,6 +906,7 @@ public class Battle
{ {
if(target.remainingDefenses <= 0) if(target.remainingDefenses <= 0)
{ {
debugLog += " hit success";
// attack // attack
final Entity nextEntity = next.entity; final Entity nextEntity = next.entity;
final Entity targetEntity = target.entity; final Entity targetEntity = target.entity;
@ -932,6 +942,7 @@ public class Battle
} }
else else
{ {
debugLog += " hit blocked";
// blocked // blocked
--target.remainingDefenses; --target.remainingDefenses;
sendMessageToAllPlayers(PacketBattleMessage.MessageType.DEFEND, target.entity.getEntityId(), next.entity.getEntityId(), 0); sendMessageToAllPlayers(PacketBattleMessage.MessageType.DEFEND, target.entity.getEntityId(), next.entity.getEntityId(), 0);
@ -939,19 +950,23 @@ public class Battle
} }
else else
{ {
debugLog += " hit missed";
// miss // miss
sendMessageToAllPlayers(PacketBattleMessage.MessageType.MISS, next.entity.getEntityId(), target.entity.getEntityId(), 0); sendMessageToAllPlayers(PacketBattleMessage.MessageType.MISS, next.entity.getEntityId(), target.entity.getEntityId(), 0);
} }
} }
else else
{ {
debugLog += " as mob";
EntityLivingBase attackTarget = ((EntityLiving)next.entity).getAttackTarget(); EntityLivingBase attackTarget = ((EntityLiving)next.entity).getAttackTarget();
if(attackTarget != null && hasCombatant(attackTarget.getEntityId())) if(attackTarget != null && hasCombatant(attackTarget.getEntityId()))
{ {
debugLog += " to targeted";
target = getCombatantByID(attackTarget.getEntityId()); target = getCombatantByID(attackTarget.getEntityId());
} }
else else
{ {
debugLog += " to random other side";
if(next.isSideA) if(next.isSideA)
{ {
int randomTargetIndex = (int)(Math.random() * sideB.size()); int randomTargetIndex = (int)(Math.random() * sideB.size());
@ -998,6 +1013,7 @@ public class Battle
{ {
if(target.remainingDefenses <= 0) if(target.remainingDefenses <= 0)
{ {
debugLog += " hit success";
DamageSource damageSource = DamageSource.causeMobDamage((EntityLivingBase)next.entity); DamageSource damageSource = DamageSource.causeMobDamage((EntityLivingBase)next.entity);
int damageAmount = next.entityInfo.attackPower; int damageAmount = next.entityInfo.attackPower;
if(next.entityInfo.attackVariance > 0) if(next.entityInfo.attackVariance > 0)
@ -1010,6 +1026,7 @@ public class Battle
final Entity targetEntity = target.entity; final Entity targetEntity = target.entity;
final EntityInfo targetEntityInfo = target.entityInfo; final EntityInfo targetEntityInfo = target.entityInfo;
final int finalDamageAmount = damageAmount; final int finalDamageAmount = damageAmount;
debugLog += " adding task...";
next.entity.getServer().addScheduledTask(() -> { next.entity.getServer().addScheduledTask(() -> {
TurnBasedMinecraftMod.proxy.setAttackingEntity(nextEntity); TurnBasedMinecraftMod.proxy.setAttackingEntity(nextEntity);
targetEntity.attackEntityFrom(damageSource, finalDamageAmount); targetEntity.attackEntityFrom(damageSource, finalDamageAmount);
@ -1038,9 +1055,11 @@ public class Battle
} }
} }
}); });
debugLog += "...task added";
} }
else else
{ {
debugLog += " hit blocked";
// blocked // blocked
--target.remainingDefenses; --target.remainingDefenses;
sendMessageToAllPlayers(PacketBattleMessage.MessageType.DEFEND, target.entity.getEntityId(), next.entity.getEntityId(), 0); sendMessageToAllPlayers(PacketBattleMessage.MessageType.DEFEND, target.entity.getEntityId(), next.entity.getEntityId(), 0);
@ -1048,16 +1067,19 @@ public class Battle
} }
else else
{ {
debugLog += " hit missed";
// miss // miss
sendMessageToAllPlayers(PacketBattleMessage.MessageType.MISS, next.entity.getEntityId(), target.entity.getEntityId(), 0); sendMessageToAllPlayers(PacketBattleMessage.MessageType.MISS, next.entity.getEntityId(), target.entity.getEntityId(), 0);
} }
} }
break; break;
case DEFEND: case DEFEND:
debugLog += " defend";
next.remainingDefenses = TurnBasedMinecraftMod.proxy.getConfig().getDefenseDuration(); next.remainingDefenses = TurnBasedMinecraftMod.proxy.getConfig().getDefenseDuration();
sendMessageToAllPlayers(PacketBattleMessage.MessageType.DEFENDING, next.entity.getEntityId(), 0, 0); sendMessageToAllPlayers(PacketBattleMessage.MessageType.DEFENDING, next.entity.getEntityId(), 0, 0);
break; break;
case FLEE: case FLEE:
debugLog += " flee";
int fastestEnemySpeed = 0; int fastestEnemySpeed = 0;
if(next.isSideA) if(next.isSideA)
{ {
@ -1124,6 +1146,7 @@ public class Battle
} }
if((int)(Math.random() * 100) < fleeProbability) if((int)(Math.random() * 100) < fleeProbability)
{ {
debugLog += " success";
// flee success // flee success
combatantsChanged = true; combatantsChanged = true;
String fleeingCategory = new String(); String fleeingCategory = new String();
@ -1140,13 +1163,16 @@ public class Battle
} }
else else
{ {
debugLog += " fail";
// flee fail // flee fail
sendMessageToAllPlayers(PacketBattleMessage.MessageType.FLEE, next.entity.getEntityId(), 0, 0); sendMessageToAllPlayers(PacketBattleMessage.MessageType.FLEE, next.entity.getEntityId(), 0, 0);
} }
break; break;
case USE_ITEM: case USE_ITEM:
debugLog += " use item";
if(next.itemToUse < 0 || next.itemToUse > 8) if(next.itemToUse < 0 || next.itemToUse > 8)
{ {
debugLog += " invalid";
sendMessageToAllPlayers(PacketBattleMessage.MessageType.USED_ITEM, next.entity.getEntityId(), 0, PacketBattleMessage.UsedItemAction.USED_INVALID.getValue()); sendMessageToAllPlayers(PacketBattleMessage.MessageType.USED_ITEM, next.entity.getEntityId(), 0, PacketBattleMessage.UsedItemAction.USED_INVALID.getValue());
break; break;
} }
@ -1154,33 +1180,38 @@ public class Battle
Item targetItem = targetItemStack.getItem(); Item targetItem = targetItemStack.getItem();
if(targetItem == null) if(targetItem == null)
{ {
debugLog += " null";
sendMessageToAllPlayers(PacketBattleMessage.MessageType.USED_ITEM, next.entity.getEntityId(), 0, PacketBattleMessage.UsedItemAction.USED_NOTHING.getValue()); sendMessageToAllPlayers(PacketBattleMessage.MessageType.USED_ITEM, next.entity.getEntityId(), 0, PacketBattleMessage.UsedItemAction.USED_NOTHING.getValue());
break; break;
} }
if(targetItem instanceof ItemFood) if(targetItem instanceof ItemFood)
{ {
debugLog += " food";
sendMessageToAllPlayers(PacketBattleMessage.MessageType.USED_ITEM, next.entity.getEntityId(), 0, PacketBattleMessage.UsedItemAction.USED_FOOD.getValue(), targetItemStack.getDisplayName()); sendMessageToAllPlayers(PacketBattleMessage.MessageType.USED_ITEM, next.entity.getEntityId(), 0, PacketBattleMessage.UsedItemAction.USED_FOOD.getValue(), targetItemStack.getDisplayName());
final Entity nextEntity = next.entity; final Entity nextEntity = next.entity;
final int nextItemToUse = next.itemToUse;
next.entity.getServer().addScheduledTask(() -> { next.entity.getServer().addScheduledTask(() -> {
((ItemFood)targetItem).onItemUseFinish(targetItemStack, nextEntity.world, (EntityLivingBase)nextEntity); ((EntityPlayer)nextEntity).inventory.setInventorySlotContents(nextItemToUse, targetItem.onItemUseFinish(targetItemStack, nextEntity.world, (EntityLivingBase)nextEntity));
}); });
} }
else if(targetItem instanceof ItemPotion && !(targetItem instanceof ItemSplashPotion) && !(targetItem instanceof ItemLingeringPotion)) else if(targetItem instanceof ItemPotion && !(targetItem instanceof ItemSplashPotion) && !(targetItem instanceof ItemLingeringPotion))
{ {
debugLog += " potion";
sendMessageToAllPlayers(PacketBattleMessage.MessageType.USED_ITEM, next.entity.getEntityId(), 0, PacketBattleMessage.UsedItemAction.USED_POTION.getValue(), targetItemStack.getDisplayName()); sendMessageToAllPlayers(PacketBattleMessage.MessageType.USED_ITEM, next.entity.getEntityId(), 0, PacketBattleMessage.UsedItemAction.USED_POTION.getValue(), targetItemStack.getDisplayName());
final Entity nextEntity = next.entity; final Entity nextEntity = next.entity;
final int nextItemToUse = next.itemToUse; final int nextItemToUse = next.itemToUse;
next.entity.getServer().addScheduledTask(() -> { next.entity.getServer().addScheduledTask(() -> {
((ItemPotion)targetItem).onItemUseFinish(targetItemStack, nextEntity.world, (EntityLivingBase)nextEntity); ((EntityPlayer)nextEntity).inventory.setInventorySlotContents(nextItemToUse, targetItem.onItemUseFinish(targetItemStack, nextEntity.world, (EntityLivingBase)nextEntity));
((EntityPlayer)nextEntity).inventory.setInventorySlotContents(nextItemToUse, new ItemStack(Items.GLASS_BOTTLE));
}); });
} }
else else
{ {
debugLog += " non-consumable";
sendMessageToAllPlayers(PacketBattleMessage.MessageType.USED_ITEM, next.entity.getEntityId(), 0, PacketBattleMessage.UsedItemAction.USED_INVALID.getValue(), targetItemStack.getDisplayName()); sendMessageToAllPlayers(PacketBattleMessage.MessageType.USED_ITEM, next.entity.getEntityId(), 0, PacketBattleMessage.UsedItemAction.USED_INVALID.getValue(), targetItemStack.getDisplayName());
} }
break; break;
case SWITCH_ITEM: case SWITCH_ITEM:
debugLog += " switch item";
if(next.itemToUse < 0 || next.itemToUse > 8) if(next.itemToUse < 0 || next.itemToUse > 8)
{ {
sendMessageToAllPlayers(PacketBattleMessage.MessageType.SWITCHED_ITEM, next.entity.getEntityId(), 0, 0); sendMessageToAllPlayers(PacketBattleMessage.MessageType.SWITCHED_ITEM, next.entity.getEntityId(), 0, 0);
@ -1195,6 +1226,7 @@ public class Battle
break; break;
} }
} }
debugLog = "Actions end";
for(Combatant c : sideA.values()) for(Combatant c : sideA.values())
{ {
c.decision = Decision.UNDECIDED; c.decision = Decision.UNDECIDED;

View file

@ -64,7 +64,7 @@ public class BattleUpdater implements Runnable
if(!updateRunnable.isFinished()) if(!updateRunnable.isFinished())
{ {
// TODO this is an ugly fix to a still-not-found freeze bug in Battle.update() // TODO this is an ugly fix to a still-not-found freeze bug in Battle.update()
TurnBasedMinecraftMod.logger.error("Battle (" + entry.getValue().getId() + ") update timed out!"); TurnBasedMinecraftMod.logger.error("Battle (" + entry.getValue().getId() + "; " + entry.getValue().debugLog + ") update timed out!");
updateThread.stop(); updateThread.stop();
} }
else if(updateRunnable.isBattleFinished()) else if(updateRunnable.isBattleFinished())

View file

@ -26,7 +26,7 @@ public class TurnBasedMinecraftMod
{ {
public static final String MODID = "com.seodisparate.turnbasedminecraft"; public static final String MODID = "com.seodisparate.turnbasedminecraft";
public static final String NAME = "Turn Based Minecraft Mod"; public static final String NAME = "Turn Based Minecraft Mod";
public static final String VERSION = "1.4"; public static final String VERSION = "1.5";
public static final String CONFIG_FILENAME = "TBM_Config.xml"; public static final String CONFIG_FILENAME = "TBM_Config.xml";
public static final String CONFIG_DIRECTORY = "config/TurnBasedMinecraft/"; public static final String CONFIG_DIRECTORY = "config/TurnBasedMinecraft/";
public static final String CONFIG_FILE_PATH = CONFIG_DIRECTORY + CONFIG_FILENAME; public static final String CONFIG_FILE_PATH = CONFIG_DIRECTORY + CONFIG_FILENAME;