2018-08-29 06:09:44 +00:00
|
|
|
package com.seodisparate.TurnBasedMinecraft.common;
|
|
|
|
|
2018-09-04 06:21:49 +00:00
|
|
|
import java.util.Comparator;
|
|
|
|
|
2018-08-29 06:09:44 +00:00
|
|
|
import net.minecraft.entity.Entity;
|
2018-09-04 06:21:49 +00:00
|
|
|
import net.minecraft.entity.EntityLivingBase;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.init.MobEffects;
|
|
|
|
import net.minecraft.potion.PotionEffect;
|
2018-08-29 06:09:44 +00:00
|
|
|
|
|
|
|
public class Combatant
|
|
|
|
{
|
|
|
|
public Entity entity;
|
|
|
|
public Battle.Decision decision;
|
|
|
|
public int itemToUse;
|
2018-09-04 06:21:49 +00:00
|
|
|
public EntityInfo entityInfo;
|
|
|
|
public boolean recalcSpeedOnCompare;
|
|
|
|
public int targetEntityID;
|
2018-09-05 06:54:06 +00:00
|
|
|
public boolean isSideA;
|
|
|
|
public int remainingDefenses;
|
2018-09-17 06:49:10 +00:00
|
|
|
public int battleID;
|
2018-09-18 06:56:06 +00:00
|
|
|
public double x;
|
2018-09-25 06:16:35 +00:00
|
|
|
//public double y; // y is ignored to prevent perpetual fall damage when FreezeBattleCombatants is enabled
|
2018-09-18 06:56:06 +00:00
|
|
|
public double z;
|
|
|
|
public float yaw;
|
|
|
|
public float pitch;
|
2018-08-29 06:09:44 +00:00
|
|
|
|
|
|
|
public Combatant()
|
|
|
|
{
|
|
|
|
decision = Battle.Decision.UNDECIDED;
|
2018-09-04 06:21:49 +00:00
|
|
|
recalcSpeedOnCompare = false;
|
2018-09-05 06:54:06 +00:00
|
|
|
remainingDefenses = 0;
|
2018-08-29 06:09:44 +00:00
|
|
|
}
|
|
|
|
|
2018-09-04 06:21:49 +00:00
|
|
|
public Combatant(Entity e, EntityInfo entityInfo)
|
2018-08-29 06:09:44 +00:00
|
|
|
{
|
|
|
|
entity = e;
|
|
|
|
decision = Battle.Decision.UNDECIDED;
|
2018-09-04 06:21:49 +00:00
|
|
|
this.entityInfo = entityInfo;
|
|
|
|
recalcSpeedOnCompare = false;
|
2018-09-05 06:54:06 +00:00
|
|
|
remainingDefenses = 0;
|
2018-08-29 06:09:44 +00:00
|
|
|
}
|
|
|
|
|
2018-09-04 06:21:49 +00:00
|
|
|
/**
|
|
|
|
* Provided in reverse order of speed because PriorityQueue has least first.
|
|
|
|
*/
|
|
|
|
public static class CombatantComparator implements Comparator<Combatant>
|
2018-08-29 06:09:44 +00:00
|
|
|
{
|
2018-09-04 06:21:49 +00:00
|
|
|
@Override
|
|
|
|
public int compare(Combatant c0, Combatant c1)
|
|
|
|
{
|
|
|
|
if(c0.entity instanceof EntityPlayer && c0.recalcSpeedOnCompare)
|
|
|
|
{
|
|
|
|
EntityLivingBase c0Entity = (EntityLivingBase)c0.entity;
|
|
|
|
boolean isHaste = false;
|
|
|
|
boolean isSlow = false;
|
|
|
|
for(PotionEffect e : c0Entity.getActivePotionEffects())
|
|
|
|
{
|
2018-09-13 05:12:04 +00:00
|
|
|
if(e.getEffectName().equals(MobEffects.HASTE.getName()) || e.getEffectName().equals(MobEffects.SPEED.getName()))
|
2018-09-04 06:21:49 +00:00
|
|
|
{
|
|
|
|
isHaste = true;
|
|
|
|
}
|
|
|
|
else if(e.getEffectName().equals(MobEffects.SLOWNESS.getName()))
|
|
|
|
{
|
|
|
|
isSlow = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(c0.entityInfo == null)
|
|
|
|
{
|
|
|
|
c0.entityInfo = new EntityInfo();
|
|
|
|
}
|
|
|
|
if(isHaste && !isSlow)
|
|
|
|
{
|
|
|
|
c0.entityInfo.speed = TurnBasedMinecraftMod.config.getPlayerHasteSpeed();
|
|
|
|
}
|
|
|
|
else if(isSlow && !isHaste)
|
|
|
|
{
|
|
|
|
c0.entityInfo.speed = TurnBasedMinecraftMod.config.getPlayerSlowSpeed();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
c0.entityInfo.speed = TurnBasedMinecraftMod.config.getPlayerSpeed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(c1.entity instanceof EntityPlayer && c1.recalcSpeedOnCompare)
|
|
|
|
{
|
|
|
|
EntityLivingBase c1Entity = (EntityLivingBase)c1.entity;
|
|
|
|
boolean isHaste = false;
|
|
|
|
boolean isSlow = false;
|
|
|
|
for(PotionEffect e : c1Entity.getActivePotionEffects())
|
|
|
|
{
|
|
|
|
if(e.getEffectName().equals(MobEffects.HASTE.getName()))
|
|
|
|
{
|
|
|
|
isHaste = true;
|
|
|
|
}
|
|
|
|
else if(e.getEffectName().equals(MobEffects.SLOWNESS.getName()))
|
|
|
|
{
|
|
|
|
isSlow = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(c1.entityInfo == null)
|
|
|
|
{
|
|
|
|
c1.entityInfo = new EntityInfo();
|
|
|
|
}
|
|
|
|
if(isHaste && !isSlow)
|
|
|
|
{
|
|
|
|
c1.entityInfo.speed = TurnBasedMinecraftMod.config.getPlayerHasteSpeed();
|
|
|
|
}
|
|
|
|
else if(isSlow && !isHaste)
|
|
|
|
{
|
|
|
|
c1.entityInfo.speed = TurnBasedMinecraftMod.config.getPlayerSlowSpeed();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
c1.entityInfo.speed = TurnBasedMinecraftMod.config.getPlayerSpeed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(c0.entityInfo.speed > c1.entityInfo.speed)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
else if(c0.entityInfo.speed < c1.entityInfo.speed)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2018-08-29 06:09:44 +00:00
|
|
|
}
|
|
|
|
}
|