}
battleManager.addRecentlyLeftBattle(c);
}
-
+
+ private void setDecisionState()
+ {
+ for(Combatant c : sideA.values())
+ {
+ c.decision = Decision.UNDECIDED;
+ }
+ for(Combatant c : sideB.values())
+ {
+ c.decision = Decision.UNDECIDED;
+ }
+ state = State.DECISION;
+ undecidedCount.set(players.size());
+ }
+
/**
* @return True if battle has ended
*/
long nextInstant = System.nanoTime();
long dt = nextInstant - lastInstant;
lastInstant = nextInstant;
- return update(dt);
+ try
+ {
+ return update(dt);
+ } catch (Throwable t)
+ {
+ TurnBasedMinecraftMod.logger.error("Update: ", t);
+ setDecisionState();
+ boolean changed = false;
+ if(healthCheck())
+ {
+ changed = true;
+ }
+ if(isCreativeCheck())
+ {
+ changed = true;
+ }
+ sendMessageToAllPlayers(PacketBattleMessage.MessageType.TURN_END, 0, 0, 1);
+ if(changed)
+ {
+ notifyPlayersBattleInfo();
+ }
+ return battleEnded;
+ }
}
private boolean update(final long dt)
debugLog = next.entity.getName();
next.remainingDefenses = 0;
+
+ Decision decision = next.decision;
+ next.decision = Decision.UNDECIDED;
- switch(next.decision)
+ switch(decision)
{
case UNDECIDED:
debugLog += " undecided";
debugLog += " to random other side";
if(next.isSideA)
{
- int randomTargetIndex = random.nextInt(sideB.size());
- for(Combatant c : sideB.values())
+ if(sideB.size() > 0)
{
- if(randomTargetIndex-- == 0)
+ int randomTargetIndex = random.nextInt(sideB.size());
+ for(Combatant c : sideB.values())
{
- target = c;
- break;
+ if(randomTargetIndex-- == 0)
+ {
+ target = c;
+ break;
+ }
}
}
}
else
{
- int randomTargetIndex = random.nextInt(sideA.size());
- for(Combatant c : sideA.values())
+ if(sideA.size() > 0)
{
- if(randomTargetIndex-- == 0)
+ int randomTargetIndex = random.nextInt(sideA.size());
+ for(Combatant c : sideA.values())
{
- target = c;
- break;
+ if(randomTargetIndex-- == 0)
+ {
+ target = c;
+ break;
+ }
}
}
}
}
}
debugLog = "Actions almost end";
- for(Combatant c : sideA.values())
- {
- c.decision = Decision.UNDECIDED;
- }
- for(Combatant c : sideB.values())
- {
- c.decision = Decision.UNDECIDED;
- }
- state = State.DECISION;
- undecidedCount.set(players.size());
+ setDecisionState();
if(healthCheck())
{
combatantsChanged = true;
if(!updateRunnable.isFinished())
{
TurnBasedMinecraftMod.logger.warn("Battle (" + entry.getValue().getId() + "; " + entry.getValue().debugLog + ") update hanged for 4 seconds!");
- try { updateThread.join(4000); } catch(InterruptedException e){ /* exception ignored */ }
+ try { updateThread.join(2000); } catch(InterruptedException e){ /* exception ignored */ }
if(!updateRunnable.isFinished())
{
- // TODO this is an ugly fix to a still-not-found freeze bug in Battle.update()
- TurnBasedMinecraftMod.logger.error("Battle (" + entry.getValue().getId() + "; " + entry.getValue().debugLog + ") update timed out!");
- updateThread.stop();
+ TurnBasedMinecraftMod.logger.error("Battle (" + entry.getValue().getId() + "; " + entry.getValue().debugLog + ") update timed out (6 seconds)!");
+ updateThread.interrupt();
+ try { updateThread.join(2000); } catch(InterruptedException e){ /* exception ignored */ }
+ if(!updateRunnable.isFinished())
+ {
+ // TODO this is an ugly fix to a still-not-found freeze bug in Battle.update()
+ TurnBasedMinecraftMod.logger.error("Battle update will not stop, forcing it to stop (8 seconds)!");
+ updateThread.stop();
+ }
}
}
}