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 Entity targetEntity = target.entity;
|
||||||
final EntityInfo targetEntityInfo = target.entityInfo;
|
final EntityInfo targetEntityInfo = target.entityInfo;
|
||||||
final int finalDamageAmount = damageAmount;
|
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...";
|
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);
|
||||||
TurnBasedMinecraftMod.proxy.setAttackingEntity(null);
|
TurnBasedMinecraftMod.proxy.setAttackingEntity(null);
|
||||||
sendMessageToAllPlayers(PacketBattleMessage.MessageType.ATTACK, nextEntity.getEntityId(), targetEntity.getEntityId(), finalDamageAmount);
|
sendMessageToAllPlayers(PacketBattleMessage.MessageType.ATTACK, nextEntity.getEntityId(), targetEntity.getEntityId(), finalDamageAmount);
|
||||||
if(!(targetEntity instanceof EntityPlayer) && targetEntityInfo.defenseDamage > 0)
|
if(defenseDamageTriggered)
|
||||||
{
|
|
||||||
if((int)(Math.random() * 100) < targetEntityInfo.defenseDamageProbability)
|
|
||||||
{
|
{
|
||||||
// defense damage
|
// defense damage
|
||||||
DamageSource defenseDamageSource = DamageSource.causeMobDamage((EntityLivingBase)targetEntity);
|
DamageSource defenseDamageSource = DamageSource.causeMobDamage((EntityLivingBase)targetEntity);
|
||||||
|
@ -1067,17 +1100,12 @@ public class Battle
|
||||||
TurnBasedMinecraftMod.proxy.setAttackingEntity(null);
|
TurnBasedMinecraftMod.proxy.setAttackingEntity(null);
|
||||||
sendMessageToAllPlayers(PacketBattleMessage.MessageType.DEFENSE_DAMAGE, targetEntity.getEntityId(), nextEntity.getEntityId(), targetEntityInfo.defenseDamage);
|
sendMessageToAllPlayers(PacketBattleMessage.MessageType.DEFENSE_DAMAGE, targetEntity.getEntityId(), nextEntity.getEntityId(), targetEntityInfo.defenseDamage);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// attack effect
|
// attack effect
|
||||||
if(nextEntityInfo.attackEffect != EntityInfo.Effect.UNKNOWN && nextEntityInfo.attackEffectProbability > 0)
|
if(attackEffectTriggered)
|
||||||
{
|
|
||||||
int effectChance = (int)(Math.random() * 100);
|
|
||||||
if(effectChance < nextEntityInfo.attackEffectProbability)
|
|
||||||
{
|
{
|
||||||
nextEntityInfo.attackEffect.applyEffectToEntity((EntityLivingBase)targetEntity);
|
nextEntityInfo.attackEffect.applyEffectToEntity((EntityLivingBase)targetEntity);
|
||||||
sendMessageToAllPlayers(PacketBattleMessage.MessageType.WAS_AFFECTED, nextEntity.getEntityId(), targetEntity.getEntityId(), 0, nextEntityInfo.attackEffect.getAffectedString());
|
sendMessageToAllPlayers(PacketBattleMessage.MessageType.WAS_AFFECTED, nextEntity.getEntityId(), targetEntity.getEntityId(), 0, nextEntityInfo.attackEffect.getAffectedString());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
debugLog += "...task added";
|
debugLog += "...task added";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue