Move probability logic to BattleUpdate thread
This commit is contained in:
parent
044ee7d860
commit
83711ed7e3
1 changed files with 45 additions and 17 deletions
|
@ -1050,15 +1050,48 @@ public class Battle
|
|||
final Entity targetEntity = target.entity;
|
||||
final EntityInfo targetEntityInfo = target.entityInfo;
|
||||
final int finalDamageAmount = damageAmount;
|
||||
final boolean defenseDamageTriggered;
|
||||
final boolean attackEffectTriggered;
|
||||
|
||||
if(!(targetEntity instanceof EntityPlayer) && targetEntityInfo.defenseDamage > 0)
|
||||
{
|
||||
if((int)(Math.random() * 100) < targetEntityInfo.defenseDamageProbability)
|
||||
{
|
||||
defenseDamageTriggered = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
defenseDamageTriggered = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
defenseDamageTriggered = false;
|
||||
}
|
||||
|
||||
if(nextEntityInfo.attackEffect != EntityInfo.Effect.UNKNOWN && nextEntityInfo.attackEffectProbability > 0)
|
||||
{
|
||||
if((int)(Math.random() * 100) < nextEntityInfo.attackEffectProbability)
|
||||
{
|
||||
attackEffectTriggered = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
attackEffectTriggered = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
attackEffectTriggered = false;
|
||||
}
|
||||
|
||||
debugLog += " adding task...";
|
||||
next.entity.getServer().addScheduledTask(() -> {
|
||||
TurnBasedMinecraftMod.proxy.setAttackingEntity(nextEntity);
|
||||
targetEntity.attackEntityFrom(damageSource, finalDamageAmount);
|
||||
TurnBasedMinecraftMod.proxy.setAttackingEntity(null);
|
||||
sendMessageToAllPlayers(PacketBattleMessage.MessageType.ATTACK, nextEntity.getEntityId(), targetEntity.getEntityId(), finalDamageAmount);
|
||||
if(!(targetEntity instanceof EntityPlayer) && targetEntityInfo.defenseDamage > 0)
|
||||
{
|
||||
if((int)(Math.random() * 100) < targetEntityInfo.defenseDamageProbability)
|
||||
if(defenseDamageTriggered)
|
||||
{
|
||||
// defense damage
|
||||
DamageSource defenseDamageSource = DamageSource.causeMobDamage((EntityLivingBase)targetEntity);
|
||||
|
@ -1067,17 +1100,12 @@ public class Battle
|
|||
TurnBasedMinecraftMod.proxy.setAttackingEntity(null);
|
||||
sendMessageToAllPlayers(PacketBattleMessage.MessageType.DEFENSE_DAMAGE, targetEntity.getEntityId(), nextEntity.getEntityId(), targetEntityInfo.defenseDamage);
|
||||
}
|
||||
}
|
||||
// attack effect
|
||||
if(nextEntityInfo.attackEffect != EntityInfo.Effect.UNKNOWN && nextEntityInfo.attackEffectProbability > 0)
|
||||
{
|
||||
int effectChance = (int)(Math.random() * 100);
|
||||
if(effectChance < nextEntityInfo.attackEffectProbability)
|
||||
if(attackEffectTriggered)
|
||||
{
|
||||
nextEntityInfo.attackEffect.applyEffectToEntity((EntityLivingBase)targetEntity);
|
||||
sendMessageToAllPlayers(PacketBattleMessage.MessageType.WAS_AFFECTED, nextEntity.getEntityId(), targetEntity.getEntityId(), 0, nextEntityInfo.attackEffect.getAffectedString());
|
||||
}
|
||||
}
|
||||
});
|
||||
debugLog += "...task added";
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue