Create Combat Handler to help Ai to help manage which player should be at tacked

This commit is contained in:
Kam committed 2024-01-23 23:16:42 -05:00
1 parent 97d3df9f38
commit ebffc0e80e
7 files changed
+253 -69

No files matched your search

@@ -66,7 +66,7 @@ import noppes.npcs.util.GameProfileAlt;
import java.io.IOException;
import java.util.*;
public abstract class EntityNPCInterface extends EntityCreature implements IEntityAdditionalSpawnData, ICommandSender, IRangedAttackMob, IBossDisplayData{
public abstract class EntityNPCInterface extends EntityCreature implements IEntityAdditionalSpawnData, ICommandSender, IRangedAttackMob, IBossDisplayData {
public ICustomNpc wrappedNPC;
public static final GameProfileAlt chateventProfile = new GameProfileAlt();
@@ -80,6 +80,8 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
public DataTransform transform;
public DataTimers timers;
public CombatHandler combatHandler = new CombatHandler(this);
public String linkedName = "";
public long linkedLast = 0;
public LinkedData linkedData;
@@ -295,10 +297,10 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
updateTasks();
updateHitbox();
}
setBoolFlag(this.getAttackTarget() != null, 4);
// setBoolFlag(this.getAttackTarget() != null, 4);
setBoolFlag(!getNavigator().noPath(), 1);
setBoolFlag(isInteracting(), 2);
combatHandler.update();
onCollide();
}
@@ -334,6 +336,12 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
}
}
@Override
protected void damageEntity(DamageSource damageSrc, float damageAmount){
super.damageEntity(damageSrc, damageAmount);
combatHandler.damage(damageSrc, damageAmount);
}
public void updateClient() {
NBTTagCompound compound = writeSpawnData();
compound.setInteger("EntityId", getEntityId());
@@ -661,19 +669,21 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
removeTask(aiRange);
aiLeap = aiAttackTarget = aiResponse = aiSprint = aiRange = null;
if (this.ai.canSprint)
this.tasks.addTask(this.taskCount++, new EntityAISprintToTarget(this));
if (this.ai.onAttack == 1)
this.tasks.addTask(this.taskCount++, aiResponse = new EntityAIPanic(this, 1.2F));
else if (this.ai.onAttack == 2) {
this.tasks.addTask(this.taskCount++, aiResponse = new EntityAIAvoidTarget(this));
this.setCanSprint();
}
else if (this.ai.onAttack == 0) {
this.setCanLeap();
this.setCanSprint();
if (this.inventory.getProjectile() == null || this.ai.useRangeMelee == 2)
{
System.out.println("checking this stuff");
switch(this.ai.tacticalVariant)
{
case Dodge : this.tasks.addTask(this.taskCount++, aiResponse = new EntityAIZigZagTarget(this, 1.0D, this.ai.tacticalRadius)); break;
@@ -759,15 +769,7 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
*/
public void setCanLeap() {
if (this.ai.canLeap)
this.tasks.addTask(this.taskCount++, aiLeap = new EntityAILeapAtTarget(this, 0.4F));
}
/*
* Branch task function for sprinting
*/
public void setCanSprint() {
if (this.ai.canSprint)
this.tasks.addTask(this.taskCount++, aiSprint = new EntityAISprintToTarget(this));
this.tasks.addTask(this.taskCount++, aiLeap = new EntityAIPounceTarget(this));
}
/*
@@ -1063,6 +1065,8 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
setHealth(getMaxHealth());
dataWatcher.updateObject(14, 0); // animation Normal
dataWatcher.updateObject(15, 0);
combatHandler.reset();
this.setAttackTarget(null);
this.setRevengeTarget(null);
this.deathTime = 0;
@@ -1462,6 +1466,7 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
this.motionY = 0.4000000059604645D;
}
}
@Override
public void addVelocity(double p_70024_1_, double p_70024_3_, double p_70024_5_) {
if (this.attackingPlayer != null) {
@@ -1667,12 +1672,26 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
super.setInWeb();
}
public boolean isInRange(Entity entity, double range){
return this.isInRange(entity.posX, entity.posY, entity.posZ, range);
}
public boolean isInRange(double posX, double posY, double posZ, double range){
double y = Math.abs(this.posY - posY);
if(posY >= 0 && y > range)
return false;
double x = Math.abs(this.posX - posX);
double z = Math.abs(this.posZ - posZ);
return x <= range && z <= range;
}
@Override
public boolean canBeCollidedWith(){
return !isKilled();
}
// obviously we dont want this
@Override
public boolean canBePushed() {
return this.display.collidesWith == 0;