Upload from upload_mods.ps1
This commit is contained in:
533
Scripts/EAI/EAIApproachAndAttackTargetFatZombieRebirth.cs
Normal file
533
Scripts/EAI/EAIApproachAndAttackTargetFatZombieRebirth.cs
Normal file
@@ -0,0 +1,533 @@
|
||||
using GamePath;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
|
||||
public class EAIApproachAndAttackTargetFatZombieRebirth : EAIBase
|
||||
{
|
||||
public override void Init(EntityAlive _theEntity)
|
||||
{
|
||||
base.Init(_theEntity);
|
||||
this.MutexBits = 3;
|
||||
this.executeDelay = 0.1f;
|
||||
}
|
||||
|
||||
public override void SetData(DictionarySave<string, string> data)
|
||||
{
|
||||
base.SetData(data);
|
||||
this.targetClasses = new List<EAIApproachAndAttackTargetFatZombieRebirth.TargetClass>();
|
||||
string text;
|
||||
if (data.TryGetValue("class", out text))
|
||||
{
|
||||
string[] array = text.Split(new char[]
|
||||
{
|
||||
','
|
||||
});
|
||||
for (int i = 0; i < array.Length; i += 2)
|
||||
{
|
||||
EAIApproachAndAttackTargetFatZombieRebirth.TargetClass item = default(EAIApproachAndAttackTargetFatZombieRebirth.TargetClass);
|
||||
item.type = EntityFactory.GetEntityType(array[i]);
|
||||
item.maxChaseTime = 0f;
|
||||
if (i + 1 < array.Length)
|
||||
{
|
||||
item.maxChaseTime = StringParsers.ParseFloat(array[i + 1], 0, -1, NumberStyles.Any);
|
||||
}
|
||||
this.targetClasses.Add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override bool CanExecute()
|
||||
{
|
||||
if (RebirthUtilities.canAttack(theEntity))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-CanExecute 1");
|
||||
return false;
|
||||
}
|
||||
this.entityTarget = this.theEntity.GetAttackTarget();
|
||||
if (this.entityTarget == null)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-CanExecute 2");
|
||||
return false;
|
||||
}
|
||||
Type type = this.entityTarget.GetType();
|
||||
for (int i = 0; i < this.targetClasses.Count; i++)
|
||||
{
|
||||
EAIApproachAndAttackTargetFatZombieRebirth.TargetClass targetClass = this.targetClasses[i];
|
||||
if (targetClass.type != null && targetClass.type.IsAssignableFrom(type))
|
||||
{
|
||||
this.maxChaseTime = targetClass.maxChaseTime;
|
||||
//Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-CanExecute 3");
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-CanExecute 4");
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void Start()
|
||||
{
|
||||
this.entityTargetPos = this.entityTarget.position;
|
||||
this.entityTargetVel = Vector3.zero;
|
||||
this.isTargetToEat = this.entityTarget.IsDead() && !(this.entityTarget is EntityZombie);
|
||||
this.isEating = false;
|
||||
this.theEntity.IsEating = false;
|
||||
this.homeTimeout = (this.theEntity.IsSleeper ? 90f : this.maxChaseTime);
|
||||
|
||||
//Log.Out("Start, homeTimeout" + homeTimeout);
|
||||
|
||||
ulong worldTime = GameManager.Instance.World.worldTime;
|
||||
ValueTuple<int, int, int> valueTuple = GameUtils.WorldTimeToElements(worldTime);
|
||||
int numDay = valueTuple.Item1;
|
||||
homeTimeout = numDay + 100;
|
||||
|
||||
if (homeTimeout > 200)
|
||||
{
|
||||
homeTimeout = 200;
|
||||
}
|
||||
|
||||
////Log.Out("Start, homeTimeout" + homeTimeout);
|
||||
|
||||
this.hasHome = (this.homeTimeout > 0f);
|
||||
this.isGoingHome = false;
|
||||
if (this.theEntity.ChaseReturnLocation == Vector3.zero)
|
||||
{
|
||||
this.theEntity.ChaseReturnLocation = (this.theEntity.IsSleeper ? this.theEntity.SleeperSpawnPosition : this.theEntity.position);
|
||||
}
|
||||
this.pathCounter = 0;
|
||||
this.relocateTicks = 0;
|
||||
if (this.isTargetToEat)
|
||||
{
|
||||
Vector3 moveToLocation = this.GetMoveToLocation(0f);
|
||||
this.theEntity.FindPath(moveToLocation, this.theEntity.GetMoveSpeedAggro(), true, this);
|
||||
}
|
||||
this.attackTimeout = 5;
|
||||
}
|
||||
|
||||
public override bool Continue()
|
||||
{
|
||||
if (RebirthUtilities.canAttack(theEntity))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
EntityAlive attackTarget = this.theEntity.GetAttackTarget();
|
||||
if (this.isGoingHome)
|
||||
{
|
||||
return !attackTarget && this.theEntity.ChaseReturnLocation != Vector3.zero;
|
||||
}
|
||||
return attackTarget && !(attackTarget != this.entityTarget) && attackTarget.IsDead() == this.isTargetToEat;
|
||||
}
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
this.theEntity.IsEating = false;
|
||||
this.theEntity.navigator.clearPath();
|
||||
if (this.blockTargetTask != null)
|
||||
{
|
||||
this.blockTargetTask.canExecute = false;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update START");
|
||||
if (this.hasHome && !this.isTargetToEat)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 1");
|
||||
if (this.isGoingHome)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 2");
|
||||
Vector3 vector = this.theEntity.ChaseReturnLocation - this.theEntity.position;
|
||||
float y = vector.y;
|
||||
vector.y = 0f;
|
||||
if (vector.sqrMagnitude <= 0.16000001f && Utils.FastAbs(y) < 2f)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 3");
|
||||
Vector3 chaseReturnLocation = this.theEntity.ChaseReturnLocation;
|
||||
chaseReturnLocation.y = this.theEntity.position.y;
|
||||
this.theEntity.SetPosition(chaseReturnLocation, true);
|
||||
this.theEntity.ChaseReturnLocation = Vector3.zero;
|
||||
if (this.theEntity.IsSleeper)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 4");
|
||||
this.theEntity.ResumeSleeperPose();
|
||||
}
|
||||
return;
|
||||
}
|
||||
int num = this.pathCounter - 1;
|
||||
this.pathCounter = num;
|
||||
if (num <= 0 && !PathFinderThread.Instance.IsCalculatingPath(this.theEntity.entityId))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 5");
|
||||
this.pathCounter = 60;
|
||||
float moveSpeed = this.theEntity.GetMoveSpeedAggro() * 0.8f;
|
||||
this.theEntity.FindPath(this.theEntity.ChaseReturnLocation, moveSpeed, true, this);
|
||||
}
|
||||
//Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 6");
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 7");
|
||||
this.homeTimeout -= 0.05f;
|
||||
if (this.homeTimeout <= 0f)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 8");
|
||||
if (this.blockTargetTask == null)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 9");
|
||||
List<EAIBlockingTargetTask> targetTasks = this.manager.GetTargetTasks<EAIBlockingTargetTask>();
|
||||
if (targetTasks != null)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 10");
|
||||
this.blockTargetTask = targetTasks[0];
|
||||
}
|
||||
}
|
||||
if (this.blockTargetTask != null)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 11");
|
||||
this.blockTargetTask.canExecute = true;
|
||||
}
|
||||
this.theEntity.attackTarget = (EntityAlive) null;
|
||||
this.theEntity.SetLookPosition(Vector3.zero);
|
||||
this.theEntity.PlayGiveUpSound();
|
||||
this.pathCounter = 0;
|
||||
this.isGoingHome = true;
|
||||
//Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 12");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.entityTarget == null)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 13");
|
||||
return;
|
||||
}
|
||||
if (this.relocateTicks > 0)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 14");
|
||||
if (!this.theEntity.navigator.noPathAndNotPlanningOne())
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 15");
|
||||
this.relocateTicks--;
|
||||
this.theEntity.moveHelper.SetFocusPos(this.entityTarget.position);
|
||||
return;
|
||||
}
|
||||
this.relocateTicks = 0;
|
||||
}
|
||||
Vector3 position = this.entityTarget.position;
|
||||
Vector3 a = position - this.entityTargetPos;
|
||||
if (a.sqrMagnitude < 1f)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 16");
|
||||
this.entityTargetVel = this.entityTargetVel * 0.7f + a * 0.3f;
|
||||
}
|
||||
this.entityTargetPos = position;
|
||||
this.attackTimeout--;
|
||||
if (this.isEating)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 17");
|
||||
if (this.theEntity.bodyDamage.HasLimbs)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 18");
|
||||
this.theEntity.RotateTo(position.x, position.y, position.z, 30f, 30f);
|
||||
}
|
||||
if (this.attackTimeout <= 0)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 19");
|
||||
this.theEntity.PlayOneShot("eat_player", false);
|
||||
this.attackTimeout = 60 + base.GetRandom(20);
|
||||
}
|
||||
return;
|
||||
}
|
||||
this.theEntity.moveHelper.CalcIfUnreachablePos();
|
||||
ItemAction itemAction = this.theEntity.inventory.holdingItem.Actions[0];
|
||||
float num2 = 1.095f;
|
||||
if (!this.isTargetToEat)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 20");
|
||||
num2 = ((itemAction != null) ? Utils.FastMax(0.5f, itemAction.Range - 0.35f) : 0.5f);
|
||||
}
|
||||
float num3 = num2 * num2;
|
||||
float estimatedTicks = 1f + base.RandomFloat * 10f;
|
||||
float targetXZDistanceSq = this.GetTargetXZDistanceSq(estimatedTicks);
|
||||
float num4 = position.y - this.theEntity.position.y;
|
||||
float num5 = Utils.FastAbs(num4);
|
||||
bool flag = targetXZDistanceSq <= num3 && num5 < 1f;
|
||||
if (!flag && !this.isTargetToEat)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 21");
|
||||
if (num5 < 3f && !PathFinderThread.Instance.IsCalculatingPath(this.theEntity.entityId))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 22");
|
||||
PathEntity path = this.theEntity.navigator.getPath();
|
||||
if (path != null && path.NodeCountRemaining() <= 2)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 23");
|
||||
this.pathCounter = 0;
|
||||
}
|
||||
}
|
||||
int num = this.pathCounter - 1;
|
||||
this.pathCounter = num;
|
||||
if (num <= 0 && !PathFinderThread.Instance.IsCalculatingPath(this.theEntity.entityId))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 24");
|
||||
this.pathCounter = 6 + base.GetRandom(10);
|
||||
Vector3 moveToLocation = this.GetMoveToLocation(num2);
|
||||
if (moveToLocation.y - this.theEntity.position.y < -8f)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 25");
|
||||
this.pathCounter += 40;
|
||||
if (base.RandomFloat < 0.2f)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 26");
|
||||
this.seekPosOffset.x = this.seekPosOffset.x + (base.RandomFloat * 0.6f - 0.3f);
|
||||
this.seekPosOffset.y = this.seekPosOffset.y + (base.RandomFloat * 0.6f - 0.3f);
|
||||
}
|
||||
moveToLocation.x += this.seekPosOffset.x;
|
||||
moveToLocation.z += this.seekPosOffset.y;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 27");
|
||||
float num6 = (moveToLocation - this.theEntity.position).magnitude - 5f;
|
||||
if (num6 > 0f)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 28");
|
||||
if (num6 > 60f)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 29");
|
||||
num6 = 60f;
|
||||
}
|
||||
this.pathCounter += (int)(num6 / 20f * 20f);
|
||||
}
|
||||
}
|
||||
this.theEntity.FindPath(moveToLocation, this.theEntity.GetMoveSpeedAggro(), true, this);
|
||||
}
|
||||
}
|
||||
if (this.theEntity.Climbing)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 30");
|
||||
return;
|
||||
}
|
||||
bool flag2 = this.theEntity.CanSee(this.entityTarget);
|
||||
this.theEntity.SetLookPosition((flag2 && !this.theEntity.IsBreakingBlocks) ? this.entityTarget.getHeadPosition() : Vector3.zero);
|
||||
if (!flag)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 31");
|
||||
if (this.theEntity.navigator.noPathAndNotPlanningOne() && num4 < 2.1f)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 32");
|
||||
Vector3 moveToLocation2 = this.GetMoveToLocation(num2);
|
||||
this.theEntity.moveHelper.SetMoveTo(moveToLocation2, true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 33");
|
||||
this.theEntity.navigator.clearPath();
|
||||
this.theEntity.moveHelper.Stop();
|
||||
this.pathCounter = 0;
|
||||
}
|
||||
float num7 = this.isTargetToEat ? 1.095f : ((itemAction != null) ? (itemAction.Range - 0.1f) : 0f);
|
||||
float num8 = num7 * num7;
|
||||
if (targetXZDistanceSq > num8 || num5 >= 1.25f)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 34");
|
||||
return;
|
||||
}
|
||||
this.theEntity.IsBreakingBlocks = false;
|
||||
this.theEntity.IsBreakingDoors = false;
|
||||
if (this.theEntity.bodyDamage.HasLimbs)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 35");
|
||||
this.theEntity.RotateTo(position.x, position.y, position.z, 30f, 30f);
|
||||
}
|
||||
if (this.isTargetToEat)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 36");
|
||||
this.isEating = true;
|
||||
this.theEntity.IsEating = true;
|
||||
this.attackTimeout = 0;
|
||||
return;
|
||||
}
|
||||
if (this.theEntity.GetDamagedTarget() == this.entityTarget || (this.entityTarget != null && this.entityTarget.GetDamagedTarget() == this.theEntity))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 37");
|
||||
this.homeTimeout = (this.theEntity.IsSleeper ? 90f : this.maxChaseTime);
|
||||
//Log.Out("Update A, homeTimeout" + homeTimeout);
|
||||
if (this.blockTargetTask != null)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 38");
|
||||
this.blockTargetTask.canExecute = false;
|
||||
}
|
||||
this.theEntity.ClearDamagedTarget();
|
||||
if (this.entityTarget)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 39");
|
||||
this.entityTarget.ClearDamagedTarget();
|
||||
}
|
||||
}
|
||||
if (this.attackTimeout > 0 && !(this.entityTarget is EntityVehicle && !(this.entityTarget is EntityBicycle)) && !(this.entityTarget.Health == 0))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 40");
|
||||
return;
|
||||
}
|
||||
if (this.manager.groupCircle > 0f)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 41");
|
||||
Entity targetIfAttackedNow = this.theEntity.GetTargetIfAttackedNow();
|
||||
if (targetIfAttackedNow != this.entityTarget && (!this.entityTarget.AttachedToEntity || this.entityTarget.AttachedToEntity != targetIfAttackedNow))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 42");
|
||||
if (targetIfAttackedNow != null)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 43");
|
||||
this.relocateTicks = 46;
|
||||
Vector3 vector2 = (this.theEntity.position - position).normalized * (num7 + 1.1f);
|
||||
float num9 = base.RandomFloat * 28f + 18f;
|
||||
if (base.RandomFloat < 0.5f)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 44");
|
||||
num9 = -num9;
|
||||
}
|
||||
vector2 = Quaternion.Euler(0f, num9, 0f) * vector2;
|
||||
Vector3 targetPos = position + vector2;
|
||||
this.theEntity.FindPath(targetPos, this.theEntity.GetMoveSpeedAggro(), true, this);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
this.theEntity.SleeperSupressLivingSounds = false;
|
||||
|
||||
if (this.entityTarget is EntityVehicle)
|
||||
{
|
||||
EntityZombieSDX entityZombieSDX = (EntityZombieSDX)this.theEntity;
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 45");
|
||||
//Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update entityZombieSDX.bLastAttackReleased: " + entityZombieSDX.bLastAttackReleased);
|
||||
|
||||
itemAction.ExecuteAction(this.theEntity.inventory.holdingItemData.actionData[1], !entityZombieSDX.bLastAttackReleased);
|
||||
|
||||
entityZombieSDX.bLastAttackReleased = !entityZombieSDX.bLastAttackReleased;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.theEntity.Attack(false))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 46");
|
||||
this.attackTimeout = this.theEntity.GetAttackTimeoutTicks();
|
||||
this.theEntity.Attack(true);
|
||||
}
|
||||
}
|
||||
|
||||
private float GetTargetXZDistanceSq(float estimatedTicks)
|
||||
{
|
||||
Vector3 vector = this.entityTarget.position;
|
||||
vector += this.entityTargetVel * estimatedTicks;
|
||||
if (this.isTargetToEat)
|
||||
{
|
||||
EModelBase emodel = this.entityTarget.emodel;
|
||||
if (emodel && emodel.bipedPelvisTransform)
|
||||
{
|
||||
vector = emodel.bipedPelvisTransform.position + Origin.position;
|
||||
}
|
||||
}
|
||||
Vector3 vector2 = this.theEntity.position + this.theEntity.motion * estimatedTicks - vector;
|
||||
vector2.y = 0f;
|
||||
return vector2.sqrMagnitude;
|
||||
}
|
||||
|
||||
private Vector3 GetMoveToLocation(float maxDist)
|
||||
{
|
||||
Vector3 vector = this.entityTarget.position;
|
||||
vector += this.entityTargetVel * 6f;
|
||||
vector = this.entityTarget.world.FindSupportingBlockPos(vector);
|
||||
if (maxDist > 0f)
|
||||
{
|
||||
Vector3 vector2 = new Vector3(this.theEntity.position.x, vector.y, this.theEntity.position.z);
|
||||
Vector3 vector3 = vector - vector2;
|
||||
float magnitude = vector3.magnitude;
|
||||
if (magnitude < 3f)
|
||||
{
|
||||
if (magnitude <= maxDist)
|
||||
{
|
||||
float num = vector.y - this.theEntity.position.y;
|
||||
if (num < -3f || num > 1.5f)
|
||||
{
|
||||
return vector;
|
||||
}
|
||||
return vector2;
|
||||
}
|
||||
else
|
||||
{
|
||||
vector3 *= maxDist / magnitude;
|
||||
Vector3 vector4 = vector - vector3;
|
||||
vector4.y += 0.51f;
|
||||
Vector3i pos = World.worldToBlockPos(vector4);
|
||||
BlockValue block = this.entityTarget.world.GetBlock(pos);
|
||||
Block block2 = block.Block;
|
||||
if (block2.PathType <= 0)
|
||||
{
|
||||
RaycastHit raycastHit;
|
||||
if (Physics.Raycast(vector4 - Origin.position, Vector3.down, out raycastHit, 1.02f, 1082195968))
|
||||
{
|
||||
vector4.y = raycastHit.point.y + Origin.position.y;
|
||||
return vector4;
|
||||
}
|
||||
if (block2.IsElevator((int)block.rotation))
|
||||
{
|
||||
vector4.y = vector.y;
|
||||
return vector4;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return vector;
|
||||
}
|
||||
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
ItemAction itemAction = this.theEntity.inventory.holdingItem.Actions[0];
|
||||
float value = (itemAction != null) ? (itemAction.Range - 0.1f) : 0f;
|
||||
float targetXZDistanceSq = this.GetTargetXZDistanceSq(0f);
|
||||
return string.Format("{0}, {1}{2}{3}{4}{5} dist {6} rng {7} timeout {8}", new object[]
|
||||
{
|
||||
base.ToString(),
|
||||
this.entityTarget ? this.entityTarget.EntityName : "",
|
||||
this.theEntity.CanSee(this.entityTarget) ? "(see)" : "",
|
||||
this.theEntity.navigator.noPathAndNotPlanningOne() ? "(-path)" : (this.theEntity.navigator.noPath() ? "(!path)" : ""),
|
||||
this.isTargetToEat ? "(eat)" : "",
|
||||
this.isGoingHome ? "(home)" : "",
|
||||
Mathf.Sqrt(targetXZDistanceSq).ToCultureInvariantString("0.000"),
|
||||
value.ToCultureInvariantString("0.000"),
|
||||
this.homeTimeout.ToCultureInvariantString("0.00")
|
||||
});
|
||||
}
|
||||
|
||||
private const float cSleeperChaseTime = 90f;
|
||||
private List<EAIApproachAndAttackTargetFatZombieRebirth.TargetClass> targetClasses;
|
||||
private float maxChaseTime;
|
||||
private bool hasHome;
|
||||
private bool isGoingHome;
|
||||
private float homeTimeout;
|
||||
private EntityAlive entityTarget;
|
||||
private Vector3 entityTargetPos;
|
||||
private Vector3 entityTargetVel;
|
||||
private int attackTimeout;
|
||||
private int pathCounter;
|
||||
private Vector2 seekPosOffset;
|
||||
private bool isTargetToEat;
|
||||
private bool isEating;
|
||||
private EAIBlockingTargetTask blockTargetTask;
|
||||
private int relocateTicks;
|
||||
private struct TargetClass
|
||||
{
|
||||
public Type type;
|
||||
public float maxChaseTime;
|
||||
}
|
||||
}
|
||||
507
Scripts/EAI/EAIApproachAndAttackTargetHostileAnimalRebirth.cs
Normal file
507
Scripts/EAI/EAIApproachAndAttackTargetHostileAnimalRebirth.cs
Normal file
@@ -0,0 +1,507 @@
|
||||
using GamePath;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
|
||||
public class EAIApproachAndAttackTargetHostileAnimalRebirth : EAIBase
|
||||
{
|
||||
public override void Init(EntityAlive _theEntity)
|
||||
{
|
||||
base.Init(_theEntity);
|
||||
this.MutexBits = 3;
|
||||
this.executeDelay = 0.1f;
|
||||
}
|
||||
|
||||
public override void SetData(DictionarySave<string, string> data)
|
||||
{
|
||||
base.SetData(data);
|
||||
this.targetClasses = new List<EAIApproachAndAttackTargetHostileAnimalRebirth.TargetClass>();
|
||||
string text;
|
||||
if (data.TryGetValue("class", out text))
|
||||
{
|
||||
string[] array = text.Split(new char[]
|
||||
{
|
||||
','
|
||||
});
|
||||
for (int i = 0; i < array.Length; i += 2)
|
||||
{
|
||||
EAIApproachAndAttackTargetHostileAnimalRebirth.TargetClass item = default(EAIApproachAndAttackTargetHostileAnimalRebirth.TargetClass);
|
||||
item.type = EntityFactory.GetEntityType(array[i]);
|
||||
item.maxChaseTime = 0f;
|
||||
if (i + 1 < array.Length)
|
||||
{
|
||||
item.maxChaseTime = StringParsers.ParseFloat(array[i + 1], 0, -1, NumberStyles.Any);
|
||||
}
|
||||
this.targetClasses.Add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override bool CanExecute()
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetHostileAnimalRebirth-CanExecute START");
|
||||
if (RebirthUtilities.canAttack(theEntity))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetHostileAnimalRebirth-CanExecute 1");
|
||||
return false;
|
||||
}
|
||||
this.entityTarget = this.theEntity.GetAttackTarget();
|
||||
if (this.entityTarget == null)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetHostileAnimalRebirth-CanExecute 2");
|
||||
return false;
|
||||
}
|
||||
Type type = this.entityTarget.GetType();
|
||||
for (int i = 0; i < this.targetClasses.Count; i++)
|
||||
{
|
||||
EAIApproachAndAttackTargetHostileAnimalRebirth.TargetClass targetClass = this.targetClasses[i];
|
||||
if (targetClass.type != null && targetClass.type.IsAssignableFrom(type))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetHostileAnimalRebirth-CanExecute 3");
|
||||
this.maxChaseTime = targetClass.maxChaseTime;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
//Log.Out("EAIApproachAndAttackTargetHostileAnimalRebirth-CanExecute 4");
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void Start()
|
||||
{
|
||||
this.entityTargetPos = this.entityTarget.position;
|
||||
this.entityTargetVel = Vector3.zero;
|
||||
this.isTargetToEat = this.entityTarget.IsDead();
|
||||
this.isEating = false;
|
||||
this.theEntity.IsEating = false;
|
||||
this.homeTimeout = (this.theEntity.IsSleeper ? 90f : this.maxChaseTime);
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetHostileAnimalRebirth-Start, homeTimeout: " + homeTimeout);
|
||||
this.hasHome = (this.homeTimeout > 0f);
|
||||
this.isGoingHome = false;
|
||||
if (this.theEntity.ChaseReturnLocation == Vector3.zero)
|
||||
{
|
||||
this.theEntity.ChaseReturnLocation = (this.theEntity.IsSleeper ? this.theEntity.SleeperSpawnPosition : this.theEntity.position);
|
||||
}
|
||||
this.pathCounter = 0;
|
||||
this.relocateTicks = 0;
|
||||
if (this.isTargetToEat)
|
||||
{
|
||||
Vector3 moveToLocation = this.GetMoveToLocation(0f);
|
||||
this.theEntity.FindPath(moveToLocation, this.theEntity.GetMoveSpeedAggro(), true, this);
|
||||
}
|
||||
this.attackTimeout = 5;
|
||||
}
|
||||
|
||||
public override bool Continue()
|
||||
{
|
||||
//Log.Out($"EAIApproachAndAttackTargetHostileAnimalRebirth-Continue this: {theEntity}, attackTarget: {theEntity.attackTarget}");
|
||||
if (RebirthUtilities.canAttack(theEntity))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
EntityAlive attackTarget = this.theEntity.GetAttackTarget();
|
||||
if (this.isGoingHome)
|
||||
{
|
||||
return !attackTarget && this.theEntity.ChaseReturnLocation != Vector3.zero;
|
||||
}
|
||||
return attackTarget && !(attackTarget != this.entityTarget) && attackTarget.IsDead() == this.isTargetToEat;
|
||||
}
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
this.theEntity.IsEating = false;
|
||||
this.theEntity.navigator.clearPath();
|
||||
if (this.blockTargetTask != null)
|
||||
{
|
||||
this.blockTargetTask.canExecute = false;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetHostileAnimalRebirth-Update START");
|
||||
if (this.hasHome && !this.isTargetToEat)
|
||||
{
|
||||
//Log.Out("Update 1");
|
||||
if (this.isGoingHome)
|
||||
{
|
||||
//Log.Out("Update 2");
|
||||
Vector3 vector = this.theEntity.ChaseReturnLocation - this.theEntity.position;
|
||||
float y = vector.y;
|
||||
vector.y = 0f;
|
||||
if (vector.sqrMagnitude <= 0.16000001f && Utils.FastAbs(y) < 2f)
|
||||
{
|
||||
//Log.Out("Update 3");
|
||||
Vector3 chaseReturnLocation = this.theEntity.ChaseReturnLocation;
|
||||
chaseReturnLocation.y = this.theEntity.position.y;
|
||||
this.theEntity.SetPosition(chaseReturnLocation, true);
|
||||
this.theEntity.ChaseReturnLocation = Vector3.zero;
|
||||
if (this.theEntity.IsSleeper)
|
||||
{
|
||||
//Log.Out("Update 4");
|
||||
this.theEntity.ResumeSleeperPose();
|
||||
}
|
||||
return;
|
||||
}
|
||||
int num = this.pathCounter - 1;
|
||||
this.pathCounter = num;
|
||||
if (num <= 0 && !PathFinderThread.Instance.IsCalculatingPath(this.theEntity.entityId))
|
||||
{
|
||||
//Log.Out("Update 5");
|
||||
this.pathCounter = 60;
|
||||
float moveSpeed = this.theEntity.GetMoveSpeedAggro() * 0.8f;
|
||||
this.theEntity.FindPath(this.theEntity.ChaseReturnLocation, moveSpeed, true, this);
|
||||
}
|
||||
//Log.Out("Update 6");
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("Update 7, homeTimeout" + homeTimeout);
|
||||
this.homeTimeout -= 0.05f;
|
||||
//Log.Out("Update 7a, homeTimeout" + homeTimeout);
|
||||
if (this.homeTimeout <= 0f)
|
||||
{
|
||||
//Log.Out("Update 8");
|
||||
if (this.blockTargetTask == null)
|
||||
{
|
||||
//Log.Out("Update 9");
|
||||
List<EAIBlockingTargetTask> targetTasks = this.manager.GetTargetTasks<EAIBlockingTargetTask>();
|
||||
if (targetTasks != null)
|
||||
{
|
||||
//Log.Out("Update 10");
|
||||
this.blockTargetTask = targetTasks[0];
|
||||
}
|
||||
}
|
||||
if (this.blockTargetTask != null)
|
||||
{
|
||||
//Log.Out("Update 11");
|
||||
this.blockTargetTask.canExecute = true;
|
||||
}
|
||||
this.theEntity.attackTarget = (EntityAlive) null;
|
||||
this.theEntity.SetLookPosition(Vector3.zero);
|
||||
this.theEntity.PlayGiveUpSound();
|
||||
this.pathCounter = 0;
|
||||
this.isGoingHome = true;
|
||||
//Log.Out("Update 12");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.entityTarget == null)
|
||||
{
|
||||
//Log.Out("Update 13");
|
||||
return;
|
||||
}
|
||||
if (this.relocateTicks > 0)
|
||||
{
|
||||
//Log.Out("Update 14");
|
||||
if (!this.theEntity.navigator.noPathAndNotPlanningOne())
|
||||
{
|
||||
//Log.Out("Update 15");
|
||||
this.relocateTicks--;
|
||||
this.theEntity.moveHelper.SetFocusPos(this.entityTarget.position);
|
||||
return;
|
||||
}
|
||||
this.relocateTicks = 0;
|
||||
}
|
||||
Vector3 position = this.entityTarget.position;
|
||||
Vector3 a = position - this.entityTargetPos;
|
||||
if (a.sqrMagnitude < 1f)
|
||||
{
|
||||
//Log.Out("Update 16");
|
||||
this.entityTargetVel = this.entityTargetVel * 0.7f + a * 0.3f;
|
||||
}
|
||||
this.entityTargetPos = position;
|
||||
this.attackTimeout--;
|
||||
if (this.isEating)
|
||||
{
|
||||
//Log.Out("Update 17");
|
||||
if (this.theEntity.bodyDamage.HasLimbs)
|
||||
{
|
||||
//Log.Out("Update 18");
|
||||
this.theEntity.RotateTo(position.x, position.y, position.z, 30f, 30f);
|
||||
}
|
||||
if (this.attackTimeout <= 0)
|
||||
{
|
||||
//Log.Out("Update 19");
|
||||
this.theEntity.PlayOneShot("eat_player", false);
|
||||
this.attackTimeout = 60 + base.GetRandom(20);
|
||||
}
|
||||
return;
|
||||
}
|
||||
this.theEntity.moveHelper.CalcIfUnreachablePos();
|
||||
ItemAction itemAction = this.theEntity.inventory.holdingItem.Actions[0];
|
||||
float num2 = 1.095f;
|
||||
if (!this.isTargetToEat)
|
||||
{
|
||||
//Log.Out("Update 20");
|
||||
num2 = ((itemAction != null) ? Utils.FastMax(0.5f, itemAction.Range - 0.35f) : 0.5f);
|
||||
}
|
||||
float num3 = num2 * num2;
|
||||
float estimatedTicks = 1f + base.RandomFloat * 10f;
|
||||
float targetXZDistanceSq = this.GetTargetXZDistanceSq(estimatedTicks);
|
||||
float num4 = position.y - this.theEntity.position.y;
|
||||
float num5 = Utils.FastAbs(num4);
|
||||
bool flag = targetXZDistanceSq <= num3 && num5 < 1f;
|
||||
if (!flag && !this.isTargetToEat)
|
||||
{
|
||||
//Log.Out("Update 21");
|
||||
if (num5 < 3f && !PathFinderThread.Instance.IsCalculatingPath(this.theEntity.entityId))
|
||||
{
|
||||
//Log.Out("Update 22");
|
||||
PathEntity path = this.theEntity.navigator.getPath();
|
||||
if (path != null && path.NodeCountRemaining() <= 2)
|
||||
{
|
||||
//Log.Out("Update 23");
|
||||
this.pathCounter = 0;
|
||||
}
|
||||
}
|
||||
int num = this.pathCounter - 1;
|
||||
this.pathCounter = num;
|
||||
if (num <= 0 && !PathFinderThread.Instance.IsCalculatingPath(this.theEntity.entityId))
|
||||
{
|
||||
//Log.Out("Update 24");
|
||||
this.pathCounter = 6 + base.GetRandom(10);
|
||||
Vector3 moveToLocation = this.GetMoveToLocation(num2);
|
||||
if (moveToLocation.y - this.theEntity.position.y < -8f)
|
||||
{
|
||||
//Log.Out("Update 25");
|
||||
this.pathCounter += 40;
|
||||
if (base.RandomFloat < 0.2f)
|
||||
{
|
||||
//Log.Out("Update 26");
|
||||
this.seekPosOffset.x = this.seekPosOffset.x + (base.RandomFloat * 0.6f - 0.3f);
|
||||
this.seekPosOffset.y = this.seekPosOffset.y + (base.RandomFloat * 0.6f - 0.3f);
|
||||
}
|
||||
moveToLocation.x += this.seekPosOffset.x;
|
||||
moveToLocation.z += this.seekPosOffset.y;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("Update 27");
|
||||
float num6 = (moveToLocation - this.theEntity.position).magnitude - 5f;
|
||||
if (num6 > 0f)
|
||||
{
|
||||
//Log.Out("Update 28");
|
||||
if (num6 > 60f)
|
||||
{
|
||||
//Log.Out("Update 29");
|
||||
num6 = 60f;
|
||||
}
|
||||
this.pathCounter += (int)(num6 / 20f * 20f);
|
||||
}
|
||||
}
|
||||
this.theEntity.FindPath(moveToLocation, this.theEntity.GetMoveSpeedAggro(), true, this);
|
||||
}
|
||||
}
|
||||
if (this.theEntity.Climbing)
|
||||
{
|
||||
//Log.Out("Update 30");
|
||||
return;
|
||||
}
|
||||
bool flag2 = this.theEntity.CanSee(this.entityTarget);
|
||||
this.theEntity.SetLookPosition((flag2 && !this.theEntity.IsBreakingBlocks) ? this.entityTarget.getHeadPosition() : Vector3.zero);
|
||||
if (!flag)
|
||||
{
|
||||
//Log.Out("Update 31");
|
||||
if (this.theEntity.navigator.noPathAndNotPlanningOne() && num4 < 2.1f)
|
||||
{
|
||||
//Log.Out("Update 32");
|
||||
Vector3 moveToLocation2 = this.GetMoveToLocation(num2);
|
||||
this.theEntity.moveHelper.SetMoveTo(moveToLocation2, true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("Update 33");
|
||||
this.theEntity.navigator.clearPath();
|
||||
this.theEntity.moveHelper.Stop();
|
||||
this.pathCounter = 0;
|
||||
}
|
||||
float num7 = this.isTargetToEat ? 1.095f : ((itemAction != null) ? (itemAction.Range - 0.1f) : 0f);
|
||||
float num8 = num7 * num7;
|
||||
if (targetXZDistanceSq > num8 || num5 >= 1.25f)
|
||||
{
|
||||
//Log.Out("Update 34");
|
||||
return;
|
||||
}
|
||||
this.theEntity.IsBreakingBlocks = false;
|
||||
this.theEntity.IsBreakingDoors = false;
|
||||
if (this.theEntity.bodyDamage.HasLimbs)
|
||||
{
|
||||
//Log.Out("Update 35");
|
||||
this.theEntity.RotateTo(position.x, position.y, position.z, 30f, 30f);
|
||||
}
|
||||
if (this.isTargetToEat)
|
||||
{
|
||||
//Log.Out("Update 36");
|
||||
this.isEating = true;
|
||||
this.theEntity.IsEating = true;
|
||||
this.attackTimeout = 0;
|
||||
return;
|
||||
}
|
||||
if (this.theEntity.GetDamagedTarget() == this.entityTarget || (this.entityTarget != null && this.entityTarget.GetDamagedTarget() == this.theEntity))
|
||||
{
|
||||
//Log.Out("Update 37");
|
||||
this.homeTimeout = (this.theEntity.IsSleeper ? 90f : this.maxChaseTime);
|
||||
//Log.Out("Update A, homeTimeout" + homeTimeout);
|
||||
if (this.blockTargetTask != null)
|
||||
{
|
||||
//Log.Out("Update 38");
|
||||
this.blockTargetTask.canExecute = false;
|
||||
}
|
||||
this.theEntity.ClearDamagedTarget();
|
||||
if (this.entityTarget)
|
||||
{
|
||||
//Log.Out("Update 39");
|
||||
this.entityTarget.ClearDamagedTarget();
|
||||
}
|
||||
}
|
||||
if (this.attackTimeout > 0)
|
||||
{
|
||||
//Log.Out("Update 40");
|
||||
return;
|
||||
}
|
||||
if (this.manager.groupCircle > 0f)
|
||||
{
|
||||
//Log.Out("Update 41");
|
||||
Entity targetIfAttackedNow = this.theEntity.GetTargetIfAttackedNow();
|
||||
if (targetIfAttackedNow != this.entityTarget && (!this.entityTarget.AttachedToEntity || this.entityTarget.AttachedToEntity != targetIfAttackedNow))
|
||||
{
|
||||
//Log.Out("Update 42");
|
||||
if (targetIfAttackedNow != null)
|
||||
{
|
||||
//Log.Out("Update 43");
|
||||
this.relocateTicks = 46;
|
||||
Vector3 vector2 = (this.theEntity.position - position).normalized * (num7 + 1.1f);
|
||||
float num9 = base.RandomFloat * 28f + 18f;
|
||||
if (base.RandomFloat < 0.5f)
|
||||
{
|
||||
//Log.Out("Update 44");
|
||||
num9 = -num9;
|
||||
}
|
||||
vector2 = Quaternion.Euler(0f, num9, 0f) * vector2;
|
||||
Vector3 targetPos = position + vector2;
|
||||
this.theEntity.FindPath(targetPos, this.theEntity.GetMoveSpeedAggro(), true, this);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
this.theEntity.SleeperSupressLivingSounds = false;
|
||||
if (this.theEntity.Attack(false))
|
||||
{
|
||||
//Log.Out("Update 45");
|
||||
this.attackTimeout = this.theEntity.GetAttackTimeoutTicks();
|
||||
this.theEntity.Attack(true);
|
||||
}
|
||||
}
|
||||
|
||||
private float GetTargetXZDistanceSq(float estimatedTicks)
|
||||
{
|
||||
Vector3 vector = this.entityTarget.position;
|
||||
vector += this.entityTargetVel * estimatedTicks;
|
||||
if (this.isTargetToEat)
|
||||
{
|
||||
EModelBase emodel = this.entityTarget.emodel;
|
||||
if (emodel && emodel.bipedPelvisTransform)
|
||||
{
|
||||
vector = emodel.bipedPelvisTransform.position + Origin.position;
|
||||
}
|
||||
}
|
||||
Vector3 vector2 = this.theEntity.position + this.theEntity.motion * estimatedTicks - vector;
|
||||
vector2.y = 0f;
|
||||
return vector2.sqrMagnitude;
|
||||
}
|
||||
|
||||
private Vector3 GetMoveToLocation(float maxDist)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetHostileAnimalRebirth-GetMoveToLocation START");
|
||||
Vector3 vector = this.entityTarget.position;
|
||||
vector += this.entityTargetVel * 6f;
|
||||
vector = this.entityTarget.world.FindSupportingBlockPos(vector);
|
||||
if (maxDist > 0f)
|
||||
{
|
||||
Vector3 vector2 = new Vector3(this.theEntity.position.x, vector.y, this.theEntity.position.z);
|
||||
Vector3 vector3 = vector - vector2;
|
||||
float magnitude = vector3.magnitude;
|
||||
if (magnitude < 3f)
|
||||
{
|
||||
if (magnitude <= maxDist)
|
||||
{
|
||||
float num = vector.y - this.theEntity.position.y;
|
||||
if (num < -3f || num > 1.5f)
|
||||
{
|
||||
return vector;
|
||||
}
|
||||
return vector2;
|
||||
}
|
||||
else
|
||||
{
|
||||
vector3 *= maxDist / magnitude;
|
||||
Vector3 vector4 = vector - vector3;
|
||||
vector4.y += 0.51f;
|
||||
Vector3i pos = World.worldToBlockPos(vector4);
|
||||
BlockValue block = this.entityTarget.world.GetBlock(pos);
|
||||
Block block2 = block.Block;
|
||||
if (block2.PathType <= 0)
|
||||
{
|
||||
RaycastHit raycastHit;
|
||||
if (Physics.Raycast(vector4 - Origin.position, Vector3.down, out raycastHit, 1.02f, 1082195968))
|
||||
{
|
||||
vector4.y = raycastHit.point.y + Origin.position.y;
|
||||
return vector4;
|
||||
}
|
||||
if (block2.IsElevator((int)block.rotation))
|
||||
{
|
||||
vector4.y = vector.y;
|
||||
return vector4;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return vector;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
ItemAction itemAction = this.theEntity.inventory.holdingItem.Actions[0];
|
||||
float value = (itemAction != null) ? (itemAction.Range - 0.1f) : 0f;
|
||||
float targetXZDistanceSq = this.GetTargetXZDistanceSq(0f);
|
||||
return string.Format("{0}, {1}{2}{3}{4}{5} dist {6} rng {7} timeout {8}", new object[]
|
||||
{
|
||||
base.ToString(),
|
||||
this.entityTarget ? this.entityTarget.EntityName : "",
|
||||
this.theEntity.CanSee(this.entityTarget) ? "(see)" : "",
|
||||
this.theEntity.navigator.noPathAndNotPlanningOne() ? "(-path)" : (this.theEntity.navigator.noPath() ? "(!path)" : ""),
|
||||
this.isTargetToEat ? "(eat)" : "",
|
||||
this.isGoingHome ? "(home)" : "",
|
||||
Mathf.Sqrt(targetXZDistanceSq).ToCultureInvariantString("0.000"),
|
||||
value.ToCultureInvariantString("0.000"),
|
||||
this.homeTimeout.ToCultureInvariantString("0.00")
|
||||
});
|
||||
}
|
||||
|
||||
private const float cSleeperChaseTime = 90f;
|
||||
private List<EAIApproachAndAttackTargetHostileAnimalRebirth.TargetClass> targetClasses;
|
||||
private float maxChaseTime;
|
||||
private bool hasHome;
|
||||
private bool isGoingHome;
|
||||
private float homeTimeout;
|
||||
private EntityAlive entityTarget;
|
||||
private Vector3 entityTargetPos;
|
||||
private Vector3 entityTargetVel;
|
||||
private int attackTimeout;
|
||||
private int pathCounter;
|
||||
private Vector2 seekPosOffset;
|
||||
private bool isTargetToEat;
|
||||
private bool isEating;
|
||||
private EAIBlockingTargetTask blockTargetTask;
|
||||
private int relocateTicks;
|
||||
private struct TargetClass
|
||||
{
|
||||
public Type type;
|
||||
public float maxChaseTime;
|
||||
}
|
||||
}
|
||||
530
Scripts/EAI/EAIApproachAndAttackTargetSDX.cs
Normal file
530
Scripts/EAI/EAIApproachAndAttackTargetSDX.cs
Normal file
@@ -0,0 +1,530 @@
|
||||
using GamePath;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
|
||||
public class EAIApproachAndAttackTargetSDX : EAIApproachAndAttackTarget
|
||||
{
|
||||
public override void Init(EntityAlive _theEntity)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetSDX-Init START");
|
||||
base.Init(_theEntity);
|
||||
this.MutexBits = 3;
|
||||
this.executeDelay = 0.1f;
|
||||
}
|
||||
|
||||
public override void SetData(DictionarySave<string, string> data)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetSDX-SetData START");
|
||||
base.SetData(data);
|
||||
this.targetClasses = new List<EAIApproachAndAttackTargetSDX.TargetClass>();
|
||||
string text;
|
||||
if (data.TryGetValue("class", out text))
|
||||
{
|
||||
string[] array = text.Split(new char[]
|
||||
{
|
||||
','
|
||||
});
|
||||
for (int i = 0; i < array.Length; i += 2)
|
||||
{
|
||||
EAIApproachAndAttackTargetSDX.TargetClass item = default(EAIApproachAndAttackTargetSDX.TargetClass);
|
||||
item.type = EntityFactory.GetEntityType(array[i]);
|
||||
item.maxChaseTime = 0f;
|
||||
if (i + 1 < array.Length)
|
||||
{
|
||||
item.maxChaseTime = StringParsers.ParseFloat(array[i + 1], 0, -1, NumberStyles.Any);
|
||||
}
|
||||
this.targetClasses.Add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override bool CanExecute()
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetSDX-CanExecute START");
|
||||
|
||||
if (RebirthUtilities.canAttack(theEntity))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!this.theEntity.GetRevengeTarget())
|
||||
{
|
||||
EntityPlayer closestPlayer = null;
|
||||
float num = 200 * 200;
|
||||
float num2 = float.MaxValue;
|
||||
for (int i = this.theEntity.world.Players.list.Count - 1; i >= 0; i--)
|
||||
{
|
||||
EntityPlayer entityPlayer = this.theEntity.world.Players.list[i];
|
||||
if (!entityPlayer.IsDead() && entityPlayer.Spawned && !entityPlayer.IsSpectator)
|
||||
{
|
||||
//Log.Out("FOUND PLAYER: " + entityPlayer.EntityName);
|
||||
float distanceSq = entityPlayer.GetDistanceSq(this.theEntity.position);
|
||||
if (distanceSq < num2 && distanceSq <= num)
|
||||
{
|
||||
num2 = distanceSq;
|
||||
closestPlayer = entityPlayer;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (closestPlayer != null)
|
||||
{
|
||||
this.theEntity.SetAttackTarget(closestPlayer, 200);
|
||||
this.entityTarget = closestPlayer;
|
||||
//Log.Out("CanExecute GOT CLOSEST PLAYER");
|
||||
}
|
||||
else
|
||||
{
|
||||
this.entityTarget = this.theEntity.GetAttackTarget();
|
||||
//Log.Out("CanExecute NO CLOSEST PLAYER");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.entityTarget = this.theEntity.GetRevengeTarget();
|
||||
}
|
||||
if (this.entityTarget == null)
|
||||
{
|
||||
//Log.Out("CanExecute NO TARGET");
|
||||
return false;
|
||||
}
|
||||
Type type = this.entityTarget.GetType();
|
||||
for (int i = 0; i < this.targetClasses.Count; i++)
|
||||
{
|
||||
EAIApproachAndAttackTargetSDX.TargetClass targetClass = this.targetClasses[i];
|
||||
if (targetClass.type != null && targetClass.type.IsAssignableFrom(type))
|
||||
{
|
||||
this.maxChaseTime = targetClass.maxChaseTime;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void Start()
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetSDX-Start START");
|
||||
this.entityTargetPos = this.entityTarget.position;
|
||||
this.entityTargetVel = Vector3.zero;
|
||||
this.isTargetToEat = this.entityTarget.IsDead() && !(this.entityTarget is EntityZombie);
|
||||
this.isEating = false;
|
||||
this.theEntity.IsEating = false;
|
||||
this.homeTimeout = (this.theEntity.IsSleeper ? 90f : this.maxChaseTime);
|
||||
this.hasHome = (this.homeTimeout > 0f);
|
||||
this.isGoingHome = false;
|
||||
if (this.theEntity.ChaseReturnLocation == Vector3.zero)
|
||||
{
|
||||
this.theEntity.ChaseReturnLocation = (this.theEntity.IsSleeper ? this.theEntity.SleeperSpawnPosition : this.theEntity.position);
|
||||
}
|
||||
this.pathCounter = 0;
|
||||
this.relocateTicks = 0;
|
||||
if (this.isTargetToEat)
|
||||
{
|
||||
Vector3 moveToLocation = this.GetMoveToLocation(0f);
|
||||
this.theEntity.FindPath(moveToLocation, this.theEntity.GetMoveSpeedAggro(), true, this);
|
||||
}
|
||||
this.attackTimeout = 5;
|
||||
}
|
||||
|
||||
public override bool Continue()
|
||||
{
|
||||
//Log.Out($"EAIApproachAndAttackTargetSDX-Continue START this {theEntity}, attackTarget: {theEntity.attackTarget}");
|
||||
if (RebirthUtilities.canAttack(theEntity))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
EntityAlive attackTarget = this.theEntity.GetAttackTarget();
|
||||
if (this.isGoingHome)
|
||||
{
|
||||
return !attackTarget && this.theEntity.ChaseReturnLocation != Vector3.zero;
|
||||
}
|
||||
return attackTarget && !(attackTarget != this.entityTarget) && attackTarget.IsDead() == this.isTargetToEat;
|
||||
}
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetSDX-Reset START");
|
||||
this.theEntity.IsEating = false;
|
||||
this.theEntity.navigator.clearPath();
|
||||
if (this.blockTargetTask != null)
|
||||
{
|
||||
this.blockTargetTask.canExecute = false;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetSDX-Update START");
|
||||
|
||||
if (this.hasHome && !this.isTargetToEat)
|
||||
{
|
||||
if (this.isGoingHome)
|
||||
{
|
||||
Vector3 vector = this.theEntity.ChaseReturnLocation - this.theEntity.position;
|
||||
float y = vector.y;
|
||||
vector.y = 0f;
|
||||
if (vector.sqrMagnitude <= 0.16000001f && Utils.FastAbs(y) < 2f)
|
||||
{
|
||||
Vector3 chaseReturnLocation = this.theEntity.ChaseReturnLocation;
|
||||
chaseReturnLocation.y = this.theEntity.position.y;
|
||||
this.theEntity.SetPosition(chaseReturnLocation, true);
|
||||
this.theEntity.ChaseReturnLocation = Vector3.zero;
|
||||
if (this.theEntity.IsSleeper)
|
||||
{
|
||||
this.theEntity.ResumeSleeperPose();
|
||||
}
|
||||
return;
|
||||
}
|
||||
int num = this.pathCounter - 1;
|
||||
this.pathCounter = num;
|
||||
if (num <= 0 && !PathFinderThread.Instance.IsCalculatingPath(this.theEntity.entityId))
|
||||
{
|
||||
this.pathCounter = 60;
|
||||
float moveSpeed = this.theEntity.GetMoveSpeedAggro() * 0.8f;
|
||||
this.theEntity.FindPath(this.theEntity.ChaseReturnLocation, moveSpeed, true, this);
|
||||
}
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.homeTimeout -= 0.05f;
|
||||
if (this.homeTimeout <= 0f)
|
||||
{
|
||||
if (this.blockTargetTask == null)
|
||||
{
|
||||
List<EAIBlockingTargetTask> targetTasks = this.manager.GetTargetTasks<EAIBlockingTargetTask>();
|
||||
if (targetTasks != null)
|
||||
{
|
||||
this.blockTargetTask = targetTasks[0];
|
||||
}
|
||||
}
|
||||
if (this.blockTargetTask != null)
|
||||
{
|
||||
this.blockTargetTask.canExecute = true;
|
||||
}
|
||||
this.theEntity.attackTarget = (EntityAlive) null;
|
||||
this.theEntity.SetLookPosition(Vector3.zero);
|
||||
this.theEntity.PlayGiveUpSound();
|
||||
this.pathCounter = 0;
|
||||
this.isGoingHome = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.entityTarget == null)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetSDX-Update 1");
|
||||
//Log.Out("Update NO TARGET");
|
||||
|
||||
EntityPlayer closestPlayer = null;
|
||||
float numTarget = 200 * 200;
|
||||
float numTarget2 = float.MaxValue;
|
||||
//Log.Out("EAIApproachAndAttackTargetSDX-Update 1ba");
|
||||
for (int i = this.theEntity.world.Players.list.Count - 1; i >= 0; i--)
|
||||
{
|
||||
EntityPlayer entityPlayer = this.theEntity.world.Players.list[i];
|
||||
if (!entityPlayer.IsDead() && entityPlayer.Spawned)
|
||||
{
|
||||
//Log.Out("FOUND PLAYER: " + entityPlayer.EntityName);
|
||||
float distanceSq = entityPlayer.GetDistanceSq(this.theEntity.position);
|
||||
if (distanceSq < numTarget2 && distanceSq <= numTarget)
|
||||
{
|
||||
numTarget2 = distanceSq;
|
||||
closestPlayer = entityPlayer;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (closestPlayer != null)
|
||||
{
|
||||
this.theEntity.SetAttackTarget(closestPlayer, 120);
|
||||
this.entityTarget = closestPlayer;
|
||||
//Log.Out("Update GOT PLAYER TARGET: " + closestPlayer.EntityName);
|
||||
}
|
||||
|
||||
if (this.entityTarget == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("UPDATE-EntityTarget Name: " + this.entityTarget.EntityName);
|
||||
}
|
||||
if (this.relocateTicks > 0)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetSDX-Update 2");
|
||||
if (!this.theEntity.navigator.noPathAndNotPlanningOne())
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetSDX-Update 3");
|
||||
this.relocateTicks--;
|
||||
this.theEntity.moveHelper.SetFocusPos(this.entityTarget.position);
|
||||
return;
|
||||
}
|
||||
this.relocateTicks = 0;
|
||||
}
|
||||
Vector3 position = this.entityTarget.position;
|
||||
Vector3 vector2 = position - this.entityTargetPos;
|
||||
if (vector2.sqrMagnitude < 1f)
|
||||
{
|
||||
this.entityTargetVel = this.entityTargetVel * 0.7f + vector2 * 0.3f;
|
||||
}
|
||||
this.entityTargetPos = position;
|
||||
this.attackTimeout--;
|
||||
if (this.isEating)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetSDX-Update 4");
|
||||
if (this.theEntity.bodyDamage.HasLimbs)
|
||||
{
|
||||
this.theEntity.RotateTo(position.x, position.y, position.z, 30f, 30f);
|
||||
}
|
||||
if (this.attackTimeout <= 0)
|
||||
{
|
||||
this.theEntity.PlayOneShot("eat_player", false);
|
||||
this.attackTimeout = 60 + base.GetRandom(20);
|
||||
}
|
||||
return;
|
||||
}
|
||||
this.theEntity.moveHelper.CalcIfUnreachablePos();
|
||||
ItemAction itemAction = this.theEntity.inventory.holdingItem.Actions[0];
|
||||
float num2 = 1.095f;
|
||||
if (!this.isTargetToEat)
|
||||
{
|
||||
num2 = ((itemAction != null) ? Utils.FastMax(0.5f, itemAction.Range - 0.35f) : 0.5f);
|
||||
}
|
||||
float num3 = num2 * num2;
|
||||
float estimatedTicks = 1f + base.RandomFloat * 10f;
|
||||
float targetXZDistanceSq = this.GetTargetXZDistanceSq(estimatedTicks);
|
||||
float num4 = position.y - this.theEntity.position.y;
|
||||
float num5 = Utils.FastAbs(num4);
|
||||
bool flag = targetXZDistanceSq <= num3 && num5 < 1f;
|
||||
if (!flag && !this.isTargetToEat)
|
||||
{
|
||||
if (!PathFinderThread.Instance.IsCalculatingPath(this.theEntity.entityId))
|
||||
{
|
||||
PathEntity path = this.theEntity.navigator.getPath();
|
||||
if (path != null && path.NodeCountRemaining() <= 2)
|
||||
{
|
||||
this.pathCounter = 0;
|
||||
}
|
||||
}
|
||||
int num = this.pathCounter - 1;
|
||||
this.pathCounter = num;
|
||||
if (num <= 0 && !PathFinderThread.Instance.IsCalculatingPath(this.theEntity.entityId))
|
||||
{
|
||||
this.pathCounter = 6 + base.GetRandom(10);
|
||||
Vector3 moveToLocation = this.GetMoveToLocation(num2);
|
||||
this.theEntity.FindPath(moveToLocation, this.theEntity.GetMoveSpeedAggro(), true, this);
|
||||
}
|
||||
}
|
||||
if (this.theEntity.Climbing)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetSDX-Update 5");
|
||||
return;
|
||||
}
|
||||
bool flag2 = this.theEntity.CanSee(this.entityTarget);
|
||||
if (!flag2)
|
||||
{
|
||||
//Log.Out("Update - CANNOT SEE TARGET");
|
||||
}
|
||||
this.theEntity.SetLookPosition((!this.theEntity.IsBreakingBlocks) ? this.entityTarget.getHeadPosition() : Vector3.zero);
|
||||
if (!flag)
|
||||
{
|
||||
if (this.theEntity.navigator.noPathAndNotPlanningOne() && num4 < 2.1f)
|
||||
{
|
||||
Vector3 moveToLocation2 = this.GetMoveToLocation(num2);
|
||||
this.theEntity.moveHelper.SetMoveTo(moveToLocation2, true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.theEntity.navigator.clearPath();
|
||||
this.theEntity.moveHelper.Stop();
|
||||
this.pathCounter = 0;
|
||||
}
|
||||
float num6 = this.isTargetToEat ? 1.095f : ((itemAction != null) ? (itemAction.Range - 0.1f) : 0f);
|
||||
float num7 = num6 * num6;
|
||||
if (targetXZDistanceSq > num7 || num5 >= 1.25f)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetSDX-Update 6");
|
||||
return;
|
||||
}
|
||||
this.theEntity.IsBreakingBlocks = false;
|
||||
this.theEntity.IsBreakingDoors = false;
|
||||
if (this.theEntity.bodyDamage.HasLimbs)
|
||||
{
|
||||
this.theEntity.RotateTo(position.x, position.y, position.z, 30f, 30f);
|
||||
}
|
||||
if (this.isTargetToEat)
|
||||
{
|
||||
this.isEating = true;
|
||||
this.theEntity.IsEating = true;
|
||||
this.attackTimeout = 0;
|
||||
//Log.Out("EAIApproachAndAttackTargetSDX-Update 6a");
|
||||
return;
|
||||
}
|
||||
if (this.theEntity.GetDamagedTarget() == this.entityTarget || (this.entityTarget != null && this.entityTarget.GetDamagedTarget() == this.theEntity))
|
||||
{
|
||||
this.homeTimeout = (this.theEntity.IsSleeper ? 90f : this.maxChaseTime);
|
||||
if (this.blockTargetTask != null)
|
||||
{
|
||||
this.blockTargetTask.canExecute = false;
|
||||
}
|
||||
this.theEntity.ClearDamagedTarget();
|
||||
if (this.entityTarget)
|
||||
{
|
||||
this.entityTarget.ClearDamagedTarget();
|
||||
}
|
||||
}
|
||||
if (this.attackTimeout > 0)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetSDX-Update 7");
|
||||
return;
|
||||
}
|
||||
if (this.manager.groupCircle > 0f)
|
||||
{
|
||||
Entity targetIfAttackedNow = this.theEntity.GetTargetIfAttackedNow();
|
||||
if (targetIfAttackedNow != this.entityTarget && (!this.entityTarget.AttachedToEntity || this.entityTarget.AttachedToEntity != targetIfAttackedNow))
|
||||
{
|
||||
if (targetIfAttackedNow != null)
|
||||
{
|
||||
this.relocateTicks = 46;
|
||||
Vector3 vector3 = (this.theEntity.position - position).normalized * (num6 + 1.1f);
|
||||
float num8 = base.RandomFloat * 28f + 18f;
|
||||
if (base.RandomFloat < 0.5f)
|
||||
{
|
||||
num8 = -num8;
|
||||
}
|
||||
vector3 = Quaternion.Euler(0f, num8, 0f) * vector3;
|
||||
Vector3 targetPos = position + vector3;
|
||||
this.theEntity.FindPath(targetPos, this.theEntity.GetMoveSpeedAggro(), true, this);
|
||||
}
|
||||
//Log.Out("EAIApproachAndAttackTargetSDX-Update 8");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetSDX-Update 9");
|
||||
|
||||
this.theEntity.SleeperSupressLivingSounds = false;
|
||||
if (this.theEntity.Attack(false))
|
||||
{
|
||||
this.attackTimeout = this.theEntity.GetAttackTimeoutTicks();
|
||||
this.theEntity.Attack(true);
|
||||
}
|
||||
}
|
||||
|
||||
private float GetTargetXZDistanceSq(float estimatedTicks)
|
||||
{
|
||||
Vector3 vector = this.entityTarget.position;
|
||||
vector += this.entityTargetVel * estimatedTicks;
|
||||
if (this.isTargetToEat)
|
||||
{
|
||||
EModelBase emodel = this.entityTarget.emodel;
|
||||
if (emodel && emodel.bipedPelvisTransform)
|
||||
{
|
||||
vector = emodel.bipedPelvisTransform.position + Origin.position;
|
||||
}
|
||||
}
|
||||
Vector3 vector2 = this.theEntity.position + this.theEntity.motion * estimatedTicks - vector;
|
||||
vector2.y = 0f;
|
||||
return vector2.sqrMagnitude;
|
||||
}
|
||||
|
||||
private Vector3 GetMoveToLocation(float maxDist)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetSDX-GetMoveToLocation START");
|
||||
Vector3 vector = this.entityTarget.position;
|
||||
vector += this.entityTargetVel * 6f;
|
||||
if (this.isTargetToEat)
|
||||
{
|
||||
EModelBase emodel = this.entityTarget.emodel;
|
||||
if (emodel && emodel.bipedPelvisTransform)
|
||||
{
|
||||
vector = emodel.bipedPelvisTransform.position + Origin.position;
|
||||
}
|
||||
}
|
||||
vector = this.entityTarget.world.FindSupportingBlockPos(vector);
|
||||
if (maxDist > 0f)
|
||||
{
|
||||
Vector3 vector2 = new Vector3(this.theEntity.position.x, vector.y, this.theEntity.position.z);
|
||||
Vector3 vector3 = vector - vector2;
|
||||
float magnitude = vector3.magnitude;
|
||||
if (magnitude < 3f)
|
||||
{
|
||||
if (magnitude <= maxDist)
|
||||
{
|
||||
float num = vector.y - this.theEntity.position.y;
|
||||
if (num < -3f || num > 1.5f)
|
||||
{
|
||||
return vector;
|
||||
}
|
||||
return vector2;
|
||||
}
|
||||
else
|
||||
{
|
||||
vector3 *= maxDist / magnitude;
|
||||
Vector3 vector4 = vector - vector3;
|
||||
vector4.y += 0.51f;
|
||||
Vector3i pos = World.worldToBlockPos(vector4);
|
||||
BlockValue block = this.entityTarget.world.GetBlock(pos);
|
||||
Block block2 = block.Block;
|
||||
if (block2.PathType <= 0)
|
||||
{
|
||||
RaycastHit raycastHit;
|
||||
if (Physics.Raycast(vector4 - Origin.position, Vector3.down, out raycastHit, 1.02f, 1082195968))
|
||||
{
|
||||
vector4.y = raycastHit.point.y + Origin.position.y;
|
||||
return vector4;
|
||||
}
|
||||
if (block2.IsElevator((int)block.rotation))
|
||||
{
|
||||
vector4.y = vector.y;
|
||||
return vector4;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return vector;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
ItemAction itemAction = this.theEntity.inventory.holdingItem.Actions[0];
|
||||
float value = (itemAction != null) ? (itemAction.Range - 0.1f) : 0f;
|
||||
float targetXZDistanceSq = this.GetTargetXZDistanceSq(0f);
|
||||
return string.Format("{0}, {1}{2}{3}{4}{5} dist {6} rng {7} timeout {8}", new object[]
|
||||
{
|
||||
base.ToString(),
|
||||
this.entityTarget ? this.entityTarget.EntityName : "",
|
||||
this.theEntity.CanSee(this.entityTarget) ? "(see)" : "",
|
||||
this.theEntity.navigator.noPathAndNotPlanningOne() ? "(-path)" : (this.theEntity.navigator.noPath() ? "(!path)" : ""),
|
||||
this.isTargetToEat ? "(eat)" : "",
|
||||
this.isGoingHome ? "(home)" : "",
|
||||
Mathf.Sqrt(targetXZDistanceSq).ToCultureInvariantString("0.000"),
|
||||
value.ToCultureInvariantString("0.000"),
|
||||
this.homeTimeout.ToCultureInvariantString("0.00")
|
||||
});
|
||||
}
|
||||
|
||||
private const float cSleeperChaseTime = 90f;
|
||||
private List<EAIApproachAndAttackTargetSDX.TargetClass> targetClasses;
|
||||
private float maxChaseTime;
|
||||
private bool hasHome;
|
||||
private bool isGoingHome;
|
||||
private float homeTimeout;
|
||||
private EntityAlive entityTarget;
|
||||
private Vector3 entityTargetPos;
|
||||
private Vector3 entityTargetVel;
|
||||
private int attackTimeout;
|
||||
private int pathCounter;
|
||||
private bool isTargetToEat;
|
||||
private bool isEating;
|
||||
private EAIBlockingTargetTask blockTargetTask;
|
||||
private int relocateTicks;
|
||||
private struct TargetClass
|
||||
{
|
||||
public Type type;
|
||||
public float maxChaseTime;
|
||||
}
|
||||
}
|
||||
948
Scripts/EAI/EAIApproachAndAttackTargetZombieRebirth.cs
Normal file
948
Scripts/EAI/EAIApproachAndAttackTargetZombieRebirth.cs
Normal file
@@ -0,0 +1,948 @@
|
||||
using GamePath;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class EAIApproachAndAttackTargetZombieRebirth : EAIBase
|
||||
{
|
||||
public struct TargetClass
|
||||
{
|
||||
public Type type;
|
||||
public float chaseTimeMax;
|
||||
}
|
||||
|
||||
public const float cSleeperChaseTime = 90f;
|
||||
public List<EAIApproachAndAttackTargetZombieRebirth.TargetClass> targetClasses;
|
||||
public float chaseTimeMax;
|
||||
public bool hasHome;
|
||||
public bool isGoingHome;
|
||||
public float homeTimeout;
|
||||
public EntityAlive entityTarget;
|
||||
public Vector3 entityTargetPos;
|
||||
public Vector3 entityTargetVel;
|
||||
public int attackTimeout;
|
||||
public int pathCounter;
|
||||
public Vector2 seekPosOffset;
|
||||
public bool isTargetToEat;
|
||||
public bool isEating;
|
||||
public EAIBlockingTargetTask blockTargetTask;
|
||||
public int relocateTicks;
|
||||
public int eatCount;
|
||||
|
||||
public override void Init(EntityAlive _theEntity)
|
||||
{
|
||||
base.Init(_theEntity);
|
||||
MutexBits = 3;
|
||||
executeDelay = 0.1f;
|
||||
}
|
||||
|
||||
public override void SetData(DictionarySave<string, string> data)
|
||||
{
|
||||
base.SetData(data);
|
||||
targetClasses = new List<EAIApproachAndAttackTargetZombieRebirth.TargetClass>();
|
||||
string str;
|
||||
if (!data.TryGetValue("class", out str))
|
||||
return;
|
||||
string[] strArray = str.Split(',', StringSplitOptions.None);
|
||||
for (int index = 0; index < strArray.Length; index += 2)
|
||||
{
|
||||
EAIApproachAndAttackTargetZombieRebirth.TargetClass targetClass = new EAIApproachAndAttackTargetZombieRebirth.TargetClass();
|
||||
targetClass.type = EntityFactory.GetEntityType(strArray[index]);
|
||||
targetClass.chaseTimeMax = 0.0f;
|
||||
if (index + 1 < strArray.Length)
|
||||
targetClass.chaseTimeMax = StringParsers.ParseFloat(strArray[index + 1]);
|
||||
targetClasses.Add(targetClass);
|
||||
if (targetClass.type == typeof(EntityEnemyAnimal))
|
||||
{
|
||||
targetClass.type = typeof(EntityAnimalSnake);
|
||||
targetClasses.Add(targetClass);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SetTargetOnlyPlayers()
|
||||
{
|
||||
targetClasses.Clear();
|
||||
targetClasses.Add(new EAIApproachAndAttackTargetZombieRebirth.TargetClass()
|
||||
{
|
||||
type = typeof(EntityPlayer)
|
||||
});
|
||||
}
|
||||
|
||||
public override bool CanExecute()
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetZombieRebirth-CanExecute START");
|
||||
|
||||
if (RebirthUtilities.canAttack(theEntity))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetZombieRebirth-CanExecute 1");
|
||||
return false;
|
||||
}
|
||||
|
||||
//if (entityTarget != null)
|
||||
//{
|
||||
//Log.Out("EAIApproachAndAttackTargetZombieRebirth-CanExecute BEFORE entityTarget: " + entityTarget.EntityClass.entityClassName);
|
||||
//Log.Out("EAIApproachAndAttackTargetZombieRebirth-CanExecute BEFORE theEntity.GetAttackTarget(): " + theEntity.GetAttackTarget());
|
||||
//Log.Out("EAIApproachAndAttackTargetZombieRebirth-CanExecute BEFORE theEntity.GetRevengeTarget(): " + theEntity.GetRevengeTarget());
|
||||
//}
|
||||
|
||||
entityTarget = theEntity.GetAttackTarget();
|
||||
if (entityTarget == null)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetZombieRebirth-CanExecute 2");
|
||||
return false;
|
||||
}
|
||||
//else
|
||||
//{
|
||||
//Log.Out("EAIApproachAndAttackTargetZombieRebirth-CanExecute AFTER entityTarget: " + entityTarget.EntityClass.entityClassName);
|
||||
//Log.Out("EAIApproachAndAttackTargetZombieRebirth-CanExecute AFTER theEntity.GetAttackTarget(): " + theEntity.GetAttackTarget());
|
||||
//Log.Out("EAIApproachAndAttackTargetZombieRebirth-CanExecute AFTER theEntity.GetRevengeTarget(): " + theEntity.GetRevengeTarget());
|
||||
//}
|
||||
|
||||
bool bMindControlled = theEntity.Buffs.HasBuff("FuriousRamsayRangedMindControlBuffTier1") || theEntity.Buffs.HasBuff("FuriousRamsayRangedMindControlBuffTier2") || theEntity.Buffs.HasBuff("FuriousRamsayRangedMindControlBuffTier3");
|
||||
|
||||
if (bMindControlled)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetZombieRebirth-CanExecute 3");
|
||||
if (entityTarget != null)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetZombieRebirth-CanExecute 4");
|
||||
if (entityTarget is EntityPlayer || (entityTarget is EntityNPCRebirth && (entityTarget.HasAnyTags(FastTags<TagGroup.Global>.Parse("survivor")) || entityTarget.HasAnyTags(FastTags<TagGroup.Global>.Parse("ally")))))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetZombieRebirth-CanExecute 5");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
string rebirthFeralSense = RebirthVariables.customFeralSense;
|
||||
int currentDay = GameUtils.WorldTimeToDays(GameManager.Instance.World.worldTime);
|
||||
|
||||
bool randomValid = rebirthFeralSense == "random" &&
|
||||
currentDay == RebirthManager.nextFeralSenseDay;
|
||||
|
||||
if (randomValid && GameManager.Instance.World.IsDaytime() && RebirthManager.nextFeralSensePeriod == 1)
|
||||
{
|
||||
randomValid = false;
|
||||
}
|
||||
if (randomValid && !GameManager.Instance.World.IsDaytime() && RebirthManager.nextFeralSensePeriod == 2)
|
||||
{
|
||||
randomValid = false;
|
||||
}
|
||||
|
||||
bool isValidFeralSense = (rebirthFeralSense == "always") ||
|
||||
(GameManager.Instance.World.IsDaytime() && rebirthFeralSense == "dayonly") ||
|
||||
(!GameManager.Instance.World.IsDaytime() && rebirthFeralSense == "nightonly") ||
|
||||
randomValid;
|
||||
|
||||
string rebirthPOISense = RebirthVariables.customPOISense;
|
||||
bool POISense = (rebirthPOISense == "always") ||
|
||||
(GameManager.Instance.World.IsDaytime() && rebirthPOISense == "dayonly") ||
|
||||
(!GameManager.Instance.World.IsDaytime() && rebirthPOISense == "nightonly");
|
||||
|
||||
bool persist = theEntity.HasAnyTags(FastTags<TagGroup.Global>.Parse("event")) || isValidFeralSense || (theEntity.IsSleeper && POISense);
|
||||
|
||||
if (persist && !bMindControlled)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetZombieRebirth-CanExecute 6");
|
||||
if (!theEntity.GetRevengeTarget())
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetZombieRebirth-CanExecute 7");
|
||||
EntityPlayer closestPlayer = null;
|
||||
float num = 200 * 200;
|
||||
float num2 = float.MaxValue;
|
||||
for (int i = theEntity.world.Players.list.Count - 1; i >= 0; i--)
|
||||
{
|
||||
EntityPlayer entityPlayer = theEntity.world.Players.list[i];
|
||||
if (!entityPlayer.IsDead() && entityPlayer.Spawned && !entityPlayer.IsSpectator)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetZombieRebirth-CanExecute 8");
|
||||
//Log.Out("FOUND PLAYER: " + entityPlayer.EntityName);
|
||||
float distanceSq = entityPlayer.GetDistanceSq(theEntity.position);
|
||||
if (distanceSq < num2 && distanceSq <= num)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetZombieRebirth-CanExecute 9");
|
||||
num2 = distanceSq;
|
||||
closestPlayer = entityPlayer;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (closestPlayer != null)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetZombieRebirth-CanExecute 10");
|
||||
theEntity.SetAttackTarget(closestPlayer, 200);
|
||||
entityTarget = closestPlayer;
|
||||
//Log.Out("CanExecute GOT CLOSEST PLAYER");
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetZombieRebirth-CanExecute 11");
|
||||
entityTarget = theEntity.GetAttackTarget();
|
||||
//Log.Out("CanExecute NO CLOSEST PLAYER");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetZombieRebirth-CanExecute 12");
|
||||
entityTarget = theEntity.GetRevengeTarget();
|
||||
}
|
||||
}
|
||||
|
||||
Type type = entityTarget.GetType();
|
||||
for (int i = 0; i < targetClasses.Count; i++)
|
||||
{
|
||||
EAIApproachAndAttackTargetZombieRebirth.TargetClass targetClass = targetClasses[i];
|
||||
if (targetClass.type != null && targetClass.type.IsAssignableFrom(type))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetZombieRebirth-CanExecute 13");
|
||||
chaseTimeMax = targetClass.chaseTimeMax;
|
||||
|
||||
if (persist)
|
||||
{
|
||||
chaseTimeMax = 1000;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void Start()
|
||||
{
|
||||
entityTargetPos = entityTarget.position;
|
||||
entityTargetVel = Vector3.zero;
|
||||
isTargetToEat = entityTarget.IsDead() && !(entityTarget is EntityZombie);
|
||||
isEating = false;
|
||||
theEntity.IsEating = false;
|
||||
homeTimeout = (theEntity.IsSleeper ? cSleeperChaseTime : 0f);
|
||||
|
||||
//Log.Out("Start, homeTimeout" + homeTimeout);
|
||||
|
||||
hasHome = (homeTimeout > 0f);
|
||||
isGoingHome = false;
|
||||
if (theEntity.ChaseReturnLocation == Vector3.zero)
|
||||
{
|
||||
theEntity.ChaseReturnLocation = (theEntity.IsSleeper ? theEntity.SleeperSpawnPosition : theEntity.position);
|
||||
}
|
||||
pathCounter = 0;
|
||||
relocateTicks = 0;
|
||||
attackTimeout = 5;
|
||||
}
|
||||
|
||||
public override bool Continue()
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetZombieRebirth-Continue START");
|
||||
if (RebirthUtilities.canAttack(theEntity))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
EntityAlive attackTarget = theEntity.GetAttackTarget();
|
||||
if (isGoingHome)
|
||||
{
|
||||
return !attackTarget && theEntity.ChaseReturnLocation != Vector3.zero;
|
||||
}
|
||||
return attackTarget && !(attackTarget != entityTarget) && attackTarget.IsDead() == isTargetToEat;
|
||||
}
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
theEntity.IsEating = false;
|
||||
theEntity.moveHelper.Stop();
|
||||
if (blockTargetTask != null)
|
||||
{
|
||||
blockTargetTask.canExecute = false;
|
||||
}
|
||||
}
|
||||
|
||||
/*public override void Update()
|
||||
{
|
||||
if (hasHome && !isTargetToEat)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetZombieRebirth-Update 1");
|
||||
if (isGoingHome)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetZombieRebirth-Update 2");
|
||||
Vector3 vector = theEntity.ChaseReturnLocation - theEntity.position;
|
||||
float y = vector.y;
|
||||
vector.y = 0f;
|
||||
if (vector.sqrMagnitude <= 0.16000001132488251 && Utils.FastAbs(y) < 2f)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetZombieRebirth-Update 3");
|
||||
Vector3 chaseReturnLocation = theEntity.ChaseReturnLocation;
|
||||
chaseReturnLocation.y = theEntity.position.y;
|
||||
theEntity.SetPosition(chaseReturnLocation, true);
|
||||
theEntity.ChaseReturnLocation = Vector3.zero;
|
||||
if (theEntity.IsSleeper)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetZombieRebirth-Update 4");
|
||||
theEntity.ResumeSleeperPose();
|
||||
}
|
||||
return;
|
||||
}
|
||||
int num = pathCounter - 1;
|
||||
pathCounter = num;
|
||||
if (num <= 0 && !PathFinderThread.Instance.IsCalculatingPath(theEntity.entityId))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetZombieRebirth-Update 5");
|
||||
pathCounter = 60;
|
||||
float moveSpeed = theEntity.GetMoveSpeedAggro() * 0.8f;
|
||||
theEntity.FindPath(theEntity.ChaseReturnLocation, moveSpeed, false, this);
|
||||
}
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetZombieRebirth-Update 6");
|
||||
homeTimeout -= 0.05f;
|
||||
if (homeTimeout <= 0f)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetZombieRebirth-Update 7");
|
||||
if (blockTargetTask == null)
|
||||
{
|
||||
List<EAIBlockingTargetTask> targetTasks = manager.GetTargetTasks<EAIBlockingTargetTask>();
|
||||
if (targetTasks != null)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetZombieRebirth-Update 8");
|
||||
blockTargetTask = targetTasks[0];
|
||||
}
|
||||
}
|
||||
if (blockTargetTask != null)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetZombieRebirth-Update 9");
|
||||
blockTargetTask.canExecute = true;
|
||||
}
|
||||
////Log.Out("EAIApproachAndAttackTargetZombieRebirth-Update REMOVE ATTACK TARGET");
|
||||
theEntity.attackTarget = (EntityAlive) null;
|
||||
theEntity.SetLookPosition(Vector3.zero);
|
||||
theEntity.PlayGiveUpSound();
|
||||
pathCounter = 0;
|
||||
isGoingHome = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (entityTarget == null)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetZombieRebirth-Update 10");
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetZombieRebirth-Update entityTarget: " + entityTarget.EntityClass.entityClassName);
|
||||
}
|
||||
if (relocateTicks > 0)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetZombieRebirth-Update 11");
|
||||
if (!theEntity.navigator.noPathAndNotPlanningOne())
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetZombieRebirth-Update 12");
|
||||
relocateTicks--;
|
||||
theEntity.moveHelper.SetFocusPos(entityTarget.position);
|
||||
return;
|
||||
}
|
||||
relocateTicks = 0;
|
||||
}
|
||||
Vector3 vector2 = entityTarget.position;
|
||||
if (isTargetToEat)
|
||||
{
|
||||
vector2 = entityTarget.getBellyPosition();
|
||||
}
|
||||
Vector3 a = vector2 - entityTargetPos;
|
||||
if (a.sqrMagnitude < 1f)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetZombieRebirth-Update 13");
|
||||
entityTargetVel = entityTargetVel * 0.7f + a * 0.3f;
|
||||
}
|
||||
entityTargetPos = vector2;
|
||||
attackTimeout--;
|
||||
if (isEating)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetZombieRebirth-Update 14");
|
||||
if (theEntity.bodyDamage.HasLimbs)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetZombieRebirth-Update 15");
|
||||
theEntity.RotateTo(vector2.x, vector2.y, vector2.z, 30f, 30f);
|
||||
}
|
||||
if (attackTimeout <= 0)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetZombieRebirth-Update 16");
|
||||
attackTimeout = 25 + base.GetRandom(10);
|
||||
if ((eatCount & 1) == 0)
|
||||
{
|
||||
theEntity.PlayOneShot("eat_player", false);
|
||||
entityTarget.DamageEntity(DamageSource.eat, 35, false, 1f);
|
||||
}
|
||||
Vector3 pos = new Vector3(0f, 0.04f, 0.08f);
|
||||
ParticleEffect pe = new ParticleEffect("blood_eat", pos, 1f, Color.white, null, theEntity.entityId, ParticleEffect.Attachment.Head);
|
||||
GameManager.Instance.SpawnParticleEffectServer(pe, theEntity.entityId, false, false);
|
||||
eatCount++;
|
||||
}
|
||||
return;
|
||||
}
|
||||
theEntity.moveHelper.CalcIfUnreachablePos();
|
||||
float num2;
|
||||
float num3;
|
||||
if (!isTargetToEat)
|
||||
{
|
||||
ItemValue holdingItemItemValue = theEntity.inventory.holdingItemItemValue;
|
||||
int holdingItemIdx = theEntity.inventory.holdingItemIdx;
|
||||
ItemAction itemAction = holdingItemItemValue.ItemClass.Actions[holdingItemIdx];
|
||||
num2 = 1.095f;
|
||||
if (itemAction != null)
|
||||
{
|
||||
num2 = itemAction.Range;
|
||||
if (num2 == 0f)
|
||||
{
|
||||
num2 = EffectManager.GetItemValue(PassiveEffects.MaxRange, holdingItemItemValue, 0f);
|
||||
}
|
||||
}
|
||||
num3 = Utils.FastMax(0.7f, num2 - 0.35f);
|
||||
}
|
||||
else
|
||||
{
|
||||
num2 = theEntity.GetHeight() * 0.9f;
|
||||
num3 = num2 - 0.05f;
|
||||
}
|
||||
float num4 = num3 * num3;
|
||||
float num5 = 4f;
|
||||
if (theEntity.IsFeral)
|
||||
{
|
||||
num5 = 8f;
|
||||
}
|
||||
num5 = base.RandomFloat * num5;
|
||||
float targetXZDistanceSq = GetTargetXZDistanceSq(num5);
|
||||
float num6 = vector2.y - theEntity.position.y;
|
||||
float num7 = Utils.FastAbs(num6);
|
||||
bool flag = targetXZDistanceSq <= num4 && num7 < 1f;
|
||||
if (!flag)
|
||||
{
|
||||
if (num7 < 3f && !PathFinderThread.Instance.IsCalculatingPath(theEntity.entityId))
|
||||
{
|
||||
PathEntity path = theEntity.navigator.getPath();
|
||||
if (path != null && path.NodeCountRemaining() <= 2)
|
||||
{
|
||||
pathCounter = 0;
|
||||
}
|
||||
}
|
||||
int num = pathCounter - 1;
|
||||
pathCounter = num;
|
||||
if (num <= 0 && theEntity.CanNavigatePath() && !PathFinderThread.Instance.IsCalculatingPath(theEntity.entityId))
|
||||
{
|
||||
pathCounter = 6 + base.GetRandom(10);
|
||||
Vector3 moveToLocation = GetMoveToLocation(num3);
|
||||
if (moveToLocation.y - theEntity.position.y < -8f)
|
||||
{
|
||||
pathCounter += 40;
|
||||
if (base.RandomFloat < 0.2f)
|
||||
{
|
||||
seekPosOffset.x = seekPosOffset.x + (base.RandomFloat * 0.6f - 0.3f);
|
||||
seekPosOffset.y = seekPosOffset.y + (base.RandomFloat * 0.6f - 0.3f);
|
||||
}
|
||||
moveToLocation.x += seekPosOffset.x;
|
||||
moveToLocation.z += seekPosOffset.y;
|
||||
}
|
||||
else
|
||||
{
|
||||
float numDistance = 0;
|
||||
try
|
||||
{
|
||||
numDistance = Mathf.Abs(theEntity.inventory.GetBareHandItem().Actions[0].Range - entityTarget.inventory.GetBareHandItem().Actions[0].Range);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//Log.Out("============================ ERROR ==================================");
|
||||
//Log.Out("EAIApproachAndAttackTargetZombieRebirth-Update ENTITY NAME: " + theEntity.EntityClass.entityClassName);
|
||||
//Log.Out("============================ ERROR ==================================");
|
||||
}
|
||||
|
||||
float num8 = (moveToLocation - theEntity.position).magnitude - 5f;
|
||||
|
||||
float numDifference = num8 - numDistance;
|
||||
|
||||
if (numDistance <= 0)
|
||||
{
|
||||
num8 = 0;
|
||||
}
|
||||
|
||||
if (num8 > 0f)
|
||||
{
|
||||
if (num8 > 60f)
|
||||
{
|
||||
num8 = 60f;
|
||||
}
|
||||
pathCounter += (int)(num8 / 20f * 20f);
|
||||
}
|
||||
}
|
||||
theEntity.FindPath(moveToLocation, theEntity.GetMoveSpeedAggro(), false, this);
|
||||
}
|
||||
}
|
||||
if (theEntity.Climbing)
|
||||
{
|
||||
return;
|
||||
}
|
||||
bool flag2 = theEntity.CanSee(entityTarget);
|
||||
theEntity.SetLookPosition((flag2 && !theEntity.IsBreakingBlocks) ? entityTarget.getHeadPosition() : Vector3.zero);
|
||||
if (!flag)
|
||||
{
|
||||
if (theEntity.navigator.noPathAndNotPlanningOne() && pathCounter > 0 && num6 < 2.1f)
|
||||
{
|
||||
Vector3 moveToLocation2 = GetMoveToLocation(num3);
|
||||
theEntity.moveHelper.SetMoveTo(moveToLocation2, true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
theEntity.moveHelper.Stop();
|
||||
pathCounter = 0;
|
||||
}
|
||||
float num9 = isTargetToEat ? num2 : (num2 - 0.1f);
|
||||
float num10 = num9 * num9;
|
||||
if (targetXZDistanceSq > num10 || num7 >= 1.25f)
|
||||
{
|
||||
return;
|
||||
}
|
||||
theEntity.IsBreakingBlocks = false;
|
||||
theEntity.IsBreakingDoors = false;
|
||||
if (theEntity.bodyDamage.HasLimbs && !theEntity.Electrocuted)
|
||||
{
|
||||
theEntity.RotateTo(vector2.x, vector2.y, vector2.z, 30f, 30f);
|
||||
}
|
||||
if (isTargetToEat)
|
||||
{
|
||||
isEating = true;
|
||||
theEntity.IsEating = true;
|
||||
attackTimeout = 20;
|
||||
eatCount = 0;
|
||||
return;
|
||||
}
|
||||
if (theEntity.GetDamagedTarget() == entityTarget || (entityTarget != null && entityTarget.GetDamagedTarget() == theEntity))
|
||||
{
|
||||
homeTimeout = (theEntity.IsSleeper ? 90f : chaseTimeMax);
|
||||
if (blockTargetTask != null)
|
||||
{
|
||||
blockTargetTask.canExecute = false;
|
||||
}
|
||||
theEntity.ClearDamagedTarget();
|
||||
if (entityTarget)
|
||||
{
|
||||
entityTarget.ClearDamagedTarget();
|
||||
}
|
||||
}
|
||||
if (attackTimeout > 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (manager.groupCircle > 0f)
|
||||
{
|
||||
Entity targetIfAttackedNow = theEntity.GetTargetIfAttackedNow();
|
||||
if (targetIfAttackedNow != entityTarget && (!entityTarget.AttachedToEntity || entityTarget.AttachedToEntity != targetIfAttackedNow))
|
||||
{
|
||||
if (targetIfAttackedNow != null)
|
||||
{
|
||||
relocateTicks = 46;
|
||||
Vector3 vector3 = (theEntity.position - vector2).normalized * (num9 + 1.1f);
|
||||
float num11 = base.RandomFloat * 28f + 18f;
|
||||
if (base.RandomFloat < 0.5f)
|
||||
{
|
||||
num11 = -num11;
|
||||
}
|
||||
vector3 = Quaternion.Euler(0f, num11, 0f) * vector3;
|
||||
Vector3 targetPos = vector2 + vector3;
|
||||
theEntity.FindPath(targetPos, theEntity.GetMoveSpeedAggro(), false, this);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
theEntity.SleeperSupressLivingSounds = false;
|
||||
if (theEntity.Attack(false))
|
||||
{
|
||||
attackTimeout = theEntity.GetAttackTimeoutTicks();
|
||||
theEntity.Attack(true);
|
||||
}
|
||||
}*/
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetZombieRebirth-Update START");
|
||||
|
||||
if (hasHome && !isTargetToEat)
|
||||
{
|
||||
if (isGoingHome)
|
||||
{
|
||||
Vector3 vector3 = theEntity.ChaseReturnLocation - theEntity.position;
|
||||
float y = vector3.y;
|
||||
vector3.y = 0.0f;
|
||||
if (vector3.sqrMagnitude <= 0.16000001f && Utils.FastAbs(y) < 2.0f)
|
||||
{
|
||||
Vector3 chaseReturnLocation = theEntity.ChaseReturnLocation;
|
||||
chaseReturnLocation.y = theEntity.position.y;
|
||||
theEntity.SetPosition(chaseReturnLocation);
|
||||
theEntity.ChaseReturnLocation = Vector3.zero;
|
||||
if (theEntity.IsSleeper)
|
||||
theEntity.ResumeSleeperPose();
|
||||
}
|
||||
else if (--pathCounter <= 0 || !PathFinderThread.Instance.IsCalculatingPath(theEntity.entityId))
|
||||
{
|
||||
pathCounter = 60;
|
||||
theEntity.FindPath(theEntity.ChaseReturnLocation, theEntity.GetMoveSpeedAggro() * 0.8f, false, this);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
homeTimeout -= 0.05f;
|
||||
if (homeTimeout <= 0.0f && hasHome)
|
||||
{
|
||||
if (blockTargetTask == null)
|
||||
{
|
||||
List<EAIBlockingTargetTask> targetTasks = manager.GetTargetTasks<EAIBlockingTargetTask>();
|
||||
if (targetTasks != null)
|
||||
blockTargetTask = targetTasks[0];
|
||||
}
|
||||
if (blockTargetTask != null)
|
||||
blockTargetTask.canExecute = true;
|
||||
theEntity.SetAttackTarget((EntityAlive)null, 0);
|
||||
theEntity.SetLookPosition(Vector3.zero);
|
||||
theEntity.PlayGiveUpSound();
|
||||
pathCounter = 0;
|
||||
isGoingHome = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// NEW CODE - in the event they were attacking a turned zombie that turned back
|
||||
bool shouldAttack = RebirthUtilities.VerifyFactionStanding(theEntity, entityTarget);
|
||||
|
||||
if (!shouldAttack)
|
||||
{
|
||||
theEntity.attackTarget = (EntityAlive) null;
|
||||
theEntity.SetRevengeTarget((EntityAlive) null);
|
||||
return;
|
||||
}
|
||||
// NEW CODE
|
||||
|
||||
if (entityTarget == null)
|
||||
return;
|
||||
if (relocateTicks > 0)
|
||||
{
|
||||
if (theEntity.navigator.noPathAndNotPlanningOne())
|
||||
{
|
||||
relocateTicks = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
--relocateTicks;
|
||||
theEntity.moveHelper.SetFocusPos(entityTarget.position);
|
||||
return;
|
||||
}
|
||||
}
|
||||
Vector3 vector3_1 = entityTarget.position;
|
||||
if (isTargetToEat)
|
||||
vector3_1 = entityTarget.getBellyPosition();
|
||||
Vector3 vector3_2 = vector3_1 - entityTargetPos;
|
||||
if (vector3_2.sqrMagnitude < 1.0f)
|
||||
entityTargetVel = entityTargetVel * 0.7f + vector3_2 * 0.3f;
|
||||
entityTargetPos = vector3_1;
|
||||
--attackTimeout;
|
||||
if (isEating)
|
||||
{
|
||||
if (theEntity.bodyDamage.HasLimbs)
|
||||
theEntity.RotateTo(vector3_1.x, vector3_1.y, vector3_1.z, 8f, 5f);
|
||||
if (attackTimeout > 0)
|
||||
return;
|
||||
attackTimeout = 25 + GetRandom(10);
|
||||
if ((eatCount & 1) == 0)
|
||||
{
|
||||
theEntity.PlayOneShot("eat_player");
|
||||
entityTarget.DamageEntity(DamageSource.eat, 35, false, 1f);
|
||||
}
|
||||
ParticleEffect _pe = new ParticleEffect("blood_eat", new Vector3(0.0f, 0.04f, 0.08f), 1f, Color.white, string.Empty, theEntity.entityId, ParticleEffect.Attachment.Head);
|
||||
GameManager.Instance.SpawnParticleEffectServer(_pe, theEntity.entityId, false, false);
|
||||
++eatCount;
|
||||
}
|
||||
else
|
||||
{
|
||||
theEntity.moveHelper.CalcIfUnreachablePos();
|
||||
float num1;
|
||||
float maxDist;
|
||||
if (!isTargetToEat)
|
||||
{
|
||||
ItemValue holdingItemItemValue = theEntity.inventory.holdingItemItemValue;
|
||||
int holdingItemIdx = theEntity.inventory.holdingItemIdx;
|
||||
ItemAction action = holdingItemItemValue.ItemClass.Actions[holdingItemIdx];
|
||||
num1 = 1.095f;
|
||||
if (action != null)
|
||||
{
|
||||
num1 = action.Range;
|
||||
if (num1 == 0.0f)
|
||||
num1 = EffectManager.GetItemValue(PassiveEffects.MaxRange, holdingItemItemValue);
|
||||
}
|
||||
maxDist = Utils.FastMax(0.7f, num1 - 0.35f);
|
||||
}
|
||||
else
|
||||
{
|
||||
num1 = theEntity.GetHeight() * 0.9f;
|
||||
maxDist = num1 - 0.05f;
|
||||
}
|
||||
float num2 = maxDist * maxDist;
|
||||
float num3 = 4f;
|
||||
if (theEntity.IsFeral)
|
||||
num3 = 8f;
|
||||
float targetXzDistanceSq = GetTargetXZDistanceSq(RandomFloat * num3);
|
||||
float _x = vector3_1.y - theEntity.position.y;
|
||||
float num4 = Utils.FastAbs(_x);
|
||||
bool flag = targetXzDistanceSq <= num2 && num4 < 1.0f;
|
||||
if (!flag)
|
||||
{
|
||||
if (num4 < 3.0f && !PathFinderThread.Instance.IsCalculatingPath(theEntity.entityId))
|
||||
{
|
||||
PathEntity path = theEntity.navigator.getPath();
|
||||
if (path != null && path.NodeCountRemaining() <= 2)
|
||||
pathCounter = 0;
|
||||
}
|
||||
if (--pathCounter <= 0 && theEntity.CanNavigatePath() && !PathFinderThread.Instance.IsCalculatingPath(theEntity.entityId))
|
||||
{
|
||||
pathCounter = 6 + GetRandom(10);
|
||||
Vector3 moveToLocation = GetMoveToLocation(maxDist);
|
||||
if (moveToLocation.y - theEntity.position.y < -8.0f)
|
||||
{
|
||||
pathCounter += 40;
|
||||
if (RandomFloat < 0.2f)
|
||||
{
|
||||
seekPosOffset.x += RandomFloat * 0.6f - 0.3f;
|
||||
seekPosOffset.y += RandomFloat * 0.6f - 0.3f;
|
||||
}
|
||||
moveToLocation.x += seekPosOffset.x;
|
||||
moveToLocation.z += seekPosOffset.y;
|
||||
}
|
||||
else
|
||||
{
|
||||
float num5 = (moveToLocation - theEntity.position).magnitude - 5f;
|
||||
if (num5 > 0.0f)
|
||||
{
|
||||
if (num5 > 60.0f)
|
||||
num5 = 60f;
|
||||
pathCounter += (int)(num5 / 20.0f * 20.0f);
|
||||
}
|
||||
}
|
||||
theEntity.FindPath(moveToLocation, theEntity.GetMoveSpeedAggro(), true, this);
|
||||
}
|
||||
}
|
||||
if (theEntity.Climbing)
|
||||
return;
|
||||
theEntity.SetLookPosition(!theEntity.CanSee(entityTarget) || theEntity.IsBreakingBlocks ? Vector3.zero : entityTarget.getHeadPosition());
|
||||
if (!flag)
|
||||
{
|
||||
if (theEntity.navigator.noPathAndNotPlanningOne() && pathCounter > 0 && _x < 2.1f)
|
||||
theEntity.moveHelper.SetMoveTo(GetMoveToLocation(maxDist), true);
|
||||
}
|
||||
else
|
||||
{
|
||||
theEntity.moveHelper.Stop();
|
||||
pathCounter = 0;
|
||||
}
|
||||
float num6 = isTargetToEat ? num1 : num1 - 0.1f;
|
||||
float num7 = num6 * num6;
|
||||
if ((targetXzDistanceSq > num7 ? 0 : (num4 < 1.25f ? 1 : 0)) == 0)
|
||||
{
|
||||
RebirthUtilities.CheckForOpenDoor(theEntity);
|
||||
return;
|
||||
}
|
||||
theEntity.IsBreakingBlocks = false;
|
||||
theEntity.IsBreakingDoors = false;
|
||||
if (theEntity.bodyDamage.HasLimbs && !theEntity.Electrocuted)
|
||||
theEntity.RotateTo(vector3_1.x, vector3_1.y, vector3_1.z, 30f, 30f);
|
||||
if (isTargetToEat)
|
||||
{
|
||||
isEating = true;
|
||||
theEntity.IsEating = true;
|
||||
attackTimeout = 20;
|
||||
eatCount = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((theEntity.GetDamagedTarget() == entityTarget ? 1 : (!(entityTarget != null) ? 0 : (entityTarget.GetDamagedTarget() == theEntity ? 1 : 0))) != 0)
|
||||
{
|
||||
homeTimeout = theEntity.IsSleeper ? cSleeperChaseTime : 0;// chaseTimeMax;
|
||||
if (blockTargetTask != null)
|
||||
blockTargetTask.canExecute = false;
|
||||
theEntity.ClearDamagedTarget();
|
||||
if (entityTarget)
|
||||
entityTarget.ClearDamagedTarget();
|
||||
}
|
||||
if (attackTimeout > 0)
|
||||
return;
|
||||
if (manager.groupCircle > 0.0f)
|
||||
{
|
||||
Entity targetIfAttackedNow = theEntity.GetTargetIfAttackedNow();
|
||||
if (targetIfAttackedNow != entityTarget && (!(bool)entityTarget.AttachedToEntity || entityTarget.AttachedToEntity != targetIfAttackedNow))
|
||||
{
|
||||
if (!(targetIfAttackedNow != null))
|
||||
return;
|
||||
relocateTicks = 46;
|
||||
Vector3 vector3_3 = (theEntity.position - vector3_1).normalized * (num6 + 1.1f);
|
||||
float y = RandomFloat * 28.0f + 18.0f;
|
||||
if (RandomFloat < 0.5f)
|
||||
y = -y;
|
||||
Vector3 vector3_4 = Quaternion.Euler(0.0f, y, 0.0f) * vector3_3;
|
||||
theEntity.FindPath(vector3_1 + vector3_4, theEntity.GetMoveSpeedAggro(), true, (EAIBase)this);
|
||||
return;
|
||||
}
|
||||
}
|
||||
theEntity.SleeperSupressLivingSounds = false;
|
||||
if (!theEntity.Attack(false))
|
||||
return;
|
||||
attackTimeout = theEntity.GetAttackTimeoutTicks();
|
||||
theEntity.Attack(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private float GetTargetXZDistanceSq(float estimatedTicks)
|
||||
{
|
||||
Vector3 vector = entityTarget.position;
|
||||
vector += entityTargetVel * estimatedTicks;
|
||||
if (isTargetToEat)
|
||||
{
|
||||
vector = entityTarget.getBellyPosition();
|
||||
}
|
||||
Vector3 vector2 = theEntity.position + theEntity.motion * estimatedTicks - vector;
|
||||
vector2.y = 0f;
|
||||
return vector2.sqrMagnitude;
|
||||
}
|
||||
|
||||
/*private Vector3 GetMoveToLocation(float maxDist)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetZombieRebirth-GetMoveToLocation entityTarget: " + entityTarget.EntityClass.entityClassName);
|
||||
Vector3 vector = entityTarget.position;
|
||||
|
||||
vector += entityTargetVel * 6f;
|
||||
if (isTargetToEat)
|
||||
{
|
||||
vector = entityTarget.getBellyPosition();
|
||||
}
|
||||
vector = entityTarget.world.FindSupportingBlockPos(vector);
|
||||
if (maxDist > 0f)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetZombieRebirth-GetMoveToLocation 1");
|
||||
Vector3 vector2 = new Vector3(theEntity.position.x, vector.y, theEntity.position.z);
|
||||
Vector3 vector3 = vector - vector2;
|
||||
float magnitude = vector3.magnitude;
|
||||
if (magnitude < 3f)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetZombieRebirth-GetMoveToLocation 2");
|
||||
if (magnitude <= maxDist)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetZombieRebirth-GetMoveToLocation 3");
|
||||
float num = vector.y - theEntity.position.y;
|
||||
if (num < -3f || num > 1.5f)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetZombieRebirth-GetMoveToLocation 4");
|
||||
return vector;
|
||||
}
|
||||
return vector2;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetZombieRebirth-GetMoveToLocation 5");
|
||||
vector3 *= maxDist / magnitude;
|
||||
Vector3 vector4 = vector - vector3;
|
||||
vector4.y += 0.51f;
|
||||
Vector3i pos = World.worldToBlockPos(vector4);
|
||||
BlockValue block = entityTarget.world.GetBlock(pos);
|
||||
Block block2 = block.Block;
|
||||
if (block2.PathType <= 0)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetZombieRebirth-GetMoveToLocation 6");
|
||||
RaycastHit raycastHit;
|
||||
if (Physics.Raycast(vector4 - Origin.position, Vector3.down, out raycastHit, 1.02f, 1082195968))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetZombieRebirth-GetMoveToLocation 7");
|
||||
vector4.y = raycastHit.point.y + Origin.position.y;
|
||||
return vector4;
|
||||
}
|
||||
if (block2.IsElevator((int)block.rotation))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetZombieRebirth-GetMoveToLocation 8");
|
||||
vector4.y = vector.y;
|
||||
return vector4;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//Log.Out("EAIApproachAndAttackTargetZombieRebirth-GetMoveToLocation 9");
|
||||
return vector;
|
||||
}*/
|
||||
|
||||
public Vector3 GetMoveToLocation(float maxDist)
|
||||
{
|
||||
Vector3 pos = entityTarget.position + entityTargetVel * 6f;
|
||||
if (isTargetToEat)
|
||||
pos = entityTarget.getBellyPosition();
|
||||
Vector3 supportingBlockPos = entityTarget.world.FindSupportingBlockPos(pos);
|
||||
if (maxDist > 0.0f)
|
||||
{
|
||||
Vector3 vector3_1 = new Vector3(theEntity.position.x, supportingBlockPos.y, theEntity.position.z);
|
||||
Vector3 vector3_2 = supportingBlockPos - vector3_1;
|
||||
float magnitude = vector3_2.magnitude;
|
||||
if (magnitude < 3.0f)
|
||||
{
|
||||
if (magnitude <= maxDist)
|
||||
{
|
||||
float num = supportingBlockPos.y - theEntity.position.y;
|
||||
return num < -3.0f || num > 1.5f ? supportingBlockPos : vector3_1;
|
||||
}
|
||||
Vector3 vector3_3 = vector3_2 * (maxDist / magnitude);
|
||||
Vector3 _worldPos = supportingBlockPos - vector3_3;
|
||||
_worldPos.y += 0.51f;
|
||||
BlockValue block1 = entityTarget.world.GetBlock(World.worldToBlockPos(_worldPos));
|
||||
Block block2 = block1.Block;
|
||||
if (block2.PathType <= 0)
|
||||
{
|
||||
RaycastHit hitInfo;
|
||||
if (Physics.Raycast(_worldPos - Origin.position, Vector3.down, out hitInfo, 1.02f, 1082195968))
|
||||
{
|
||||
_worldPos.y = hitInfo.point.y + Origin.position.y;
|
||||
return _worldPos;
|
||||
}
|
||||
if (block2.IsElevator((int)block1.rotation))
|
||||
{
|
||||
_worldPos.y = supportingBlockPos.y;
|
||||
return _worldPos;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return supportingBlockPos;
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
ItemValue holdingItemItemValue = theEntity.inventory.holdingItemItemValue;
|
||||
int holdingItemIdx = theEntity.inventory.holdingItemIdx;
|
||||
ItemAction itemAction = holdingItemItemValue.ItemClass.Actions[holdingItemIdx];
|
||||
float num = 1.095f;
|
||||
if (!isTargetToEat && itemAction != null)
|
||||
{
|
||||
num = itemAction.Range;
|
||||
if (num == 0f)
|
||||
{
|
||||
num = EffectManager.GetItemValue(PassiveEffects.MaxRange, holdingItemItemValue, 0f);
|
||||
}
|
||||
}
|
||||
float value = isTargetToEat ? num : (num - 0.1f);
|
||||
float targetXZDistanceSq = GetTargetXZDistanceSq(0f);
|
||||
return string.Format("{0}, {1}{2}{3}{4}{5} dist {6} rng {7} timeout {8}", new object[]
|
||||
{
|
||||
base.ToString(),
|
||||
entityTarget ? entityTarget.EntityName : "",
|
||||
theEntity.CanSee(entityTarget) ? "(see)" : "",
|
||||
theEntity.navigator.noPathAndNotPlanningOne() ? "(-path)" : (theEntity.navigator.noPath() ? "(!path)" : ""),
|
||||
isTargetToEat ? "(eat)" : "",
|
||||
isGoingHome ? "(Going home)" : "",
|
||||
Mathf.Sqrt(targetXZDistanceSq).ToCultureInvariantString("0.000"),
|
||||
value.ToCultureInvariantString("0.000"),
|
||||
homeTimeout.ToCultureInvariantString("0.00")
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
180
Scripts/EAI/EAIBreakBlockRebirth.cs
Normal file
180
Scripts/EAI/EAIBreakBlockRebirth.cs
Normal file
@@ -0,0 +1,180 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class EAIBreakBlockRebirth : EAIBase
|
||||
{
|
||||
public override void Init(EntityAlive _theEntity)
|
||||
{
|
||||
base.Init(_theEntity);
|
||||
this.MutexBits = 8;
|
||||
this.executeDelay = 0.15f;
|
||||
}
|
||||
|
||||
public bool NPCEAICanProceed()
|
||||
{
|
||||
bool result = true;
|
||||
|
||||
OwnerID = (int)this.theEntity.Buffs.GetCustomVar("$Leader");
|
||||
|
||||
if (this.theEntity.Buffs.GetCustomVar("onMission") == 1f ||
|
||||
this.theEntity.Buffs.GetCustomVar("$FR_NPC_Respawn") == 1f ||
|
||||
this.theEntity.Buffs.GetCustomVar("$FR_NPC_Hidden") == 1f
|
||||
)
|
||||
{
|
||||
//Log.Out("EAIBreakBlockRebirth-NPCEAICanProceed 1");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.emodel.IsRagdollActive)
|
||||
{
|
||||
//Log.Out("EAIBreakBlockRebirth-NPCEAICanProceed 3");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.sleepingOrWakingUp || this.theEntity.bodyDamage.CurrentStun != EnumEntityStunType.None || (this.theEntity.Jumping && !this.theEntity.isSwimming))
|
||||
{
|
||||
//Log.Out("EAIBreakBlockRebirth-NPCEAICanProceed 4");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (OwnerID > 0 &&
|
||||
this.theEntity.Buffs.GetCustomVar("CurrentOrder") != (int)EntityUtilities.Orders.Stay &&
|
||||
this.theEntity.Buffs.GetCustomVar("CurrentOrder") != (int)EntityUtilities.Orders.TempStay
|
||||
)
|
||||
{
|
||||
//Log.Out("EAIBreakBlockRebirth-CanExecute IS NOT FOLLOWING");
|
||||
return false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public override bool CanExecute()
|
||||
{
|
||||
if (!NPCEAICanProceed())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//Log.Out("EAIBreakBlockRebirth-CanExecute START");
|
||||
EntityMoveHelper moveHelper = this.theEntity.moveHelper;
|
||||
if ((this.theEntity.Jumping && !moveHelper.IsDestroyArea) || this.theEntity.bodyDamage.CurrentStun != EnumEntityStunType.None)
|
||||
{
|
||||
//Log.Out("EAIBreakBlockRebirth-CanExecute 1");
|
||||
return false;
|
||||
}
|
||||
//Log.Out("EAIBreakBlockRebirth-CanExecute moveHelper.BlockedTime: " + moveHelper.BlockedTime);
|
||||
//Log.Out("EAIBreakBlockRebirth-CanExecute moveHelper.CanBreakBlocks: " + moveHelper.CanBreakBlocks);
|
||||
if (moveHelper.BlockedTime > 0.35f && moveHelper.CanBreakBlocks)
|
||||
{
|
||||
//Log.Out("EAIBreakBlockRebirth-CanExecute 2");
|
||||
RebirthUtilities.CheckForOpenDoor(this.theEntity);
|
||||
|
||||
float num = moveHelper.CalcBlockedDistanceSq();
|
||||
float num2 = this.theEntity.m_characterController.GetRadius() + 0.6f;
|
||||
if (num <= num2 * num2)
|
||||
{
|
||||
//Log.Out("EAIBreakBlockRebirth-CanExecute 8");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
//Log.Out("EAIBreakBlockRebirth-CanExecute END");
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void Start()
|
||||
{
|
||||
//Log.Out("EAIBreakBlockRebirth-Start START");
|
||||
this.attackDelay = 1;
|
||||
Vector3i blockPos = this.theEntity.moveHelper.HitInfo.hit.blockPos;
|
||||
Block block = this.theEntity.world.GetBlock(blockPos).Block;
|
||||
if (block.HasTag(BlockTags.Door) || block.HasTag(BlockTags.ClosetDoor))
|
||||
{
|
||||
this.theEntity.IsBreakingDoors = true;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Continue()
|
||||
{
|
||||
if (!NPCEAICanProceed())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return this.theEntity.bodyDamage.CurrentStun == EnumEntityStunType.None && this.theEntity.onGround && this.CanExecute();
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
//Log.Out("EAIBreakBlockRebirth-Update START");
|
||||
if (!NPCEAICanProceed())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
EntityMoveHelper moveHelper = this.theEntity.moveHelper;
|
||||
//Log.Out("EAIBreakBlockRebirth-Update attackDelay: " + this.attackDelay);
|
||||
if (this.attackDelay > 0)
|
||||
{
|
||||
this.attackDelay--;
|
||||
}
|
||||
if (this.attackDelay <= 0)
|
||||
{
|
||||
this.AttackBlock();
|
||||
}
|
||||
}
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
//Log.Out("EAIBreakBlockRebirth-Reset START");
|
||||
this.theEntity.IsBreakingBlocks = false;
|
||||
this.theEntity.IsBreakingDoors = false;
|
||||
}
|
||||
|
||||
private void AttackBlock()
|
||||
{
|
||||
this.theEntity.SetLookPosition(Vector3.zero);
|
||||
ItemActionAttackData itemActionAttackData = this.theEntity.inventory.holdingItemData.actionData[0] as ItemActionAttackData;
|
||||
if (itemActionAttackData == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
this.damageBoostPercent = 0f;
|
||||
Bounds bb;
|
||||
bb = new Bounds(this.theEntity.position, new Vector3(1.7f, 1.5f, 1.7f));
|
||||
this.theEntity.world.GetEntitiesInBounds(typeof(EntityZombie), bb, this.allies);
|
||||
for (int i = this.allies.Count - 1; i >= 0; i--)
|
||||
{
|
||||
if ((EntityZombie)this.allies[i] != this.theEntity)
|
||||
{
|
||||
this.damageBoostPercent += 0.2f;
|
||||
}
|
||||
}
|
||||
this.allies.Clear();
|
||||
if (this.theEntity.Attack(false))
|
||||
{
|
||||
this.theEntity.IsBreakingBlocks = true;
|
||||
float num = 0.25f + base.RandomFloat * 0.8f;
|
||||
if (this.theEntity.moveHelper.IsUnreachableAbove)
|
||||
{
|
||||
num *= 0.5f;
|
||||
}
|
||||
this.attackDelay = (int)((num + 0.75f) * 20f);
|
||||
itemActionAttackData.hitDelegate = new ItemActionAttackData.HitDelegate(this.GetHitInfo);
|
||||
this.theEntity.Attack(true);
|
||||
}
|
||||
}
|
||||
|
||||
private WorldRayHitInfo GetHitInfo(out float damageScale)
|
||||
{
|
||||
EntityMoveHelper moveHelper = this.theEntity.moveHelper;
|
||||
damageScale = moveHelper.DamageScale + this.damageBoostPercent;
|
||||
return moveHelper.HitInfo;
|
||||
}
|
||||
|
||||
private const float cDamageBoostPerAlly = 0.2f;
|
||||
private int OwnerID = 0;
|
||||
private int attackDelay;
|
||||
private float damageBoostPercent;
|
||||
private List<Entity> allies = new List<Entity>();
|
||||
}
|
||||
182
Scripts/EAI/EAIBreakBlockZombieRebirth.cs
Normal file
182
Scripts/EAI/EAIBreakBlockZombieRebirth.cs
Normal file
@@ -0,0 +1,182 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
public class EAIBreakBlockZombieRebirth : EAIBase
|
||||
{
|
||||
public override void Init(EntityAlive _theEntity)
|
||||
{
|
||||
base.Init(_theEntity);
|
||||
this.MutexBits = 8;
|
||||
this.executeDelay = 0.15f;
|
||||
}
|
||||
|
||||
public override bool CanExecute()
|
||||
{
|
||||
//Log.Out("EAIBreakBlockZombieRebirth-CanExecute START");
|
||||
EntityMoveHelper moveHelper = this.theEntity.moveHelper;
|
||||
if ((this.theEntity.Jumping && !moveHelper.IsDestroyArea) || this.theEntity.bodyDamage.CurrentStun != EnumEntityStunType.None)
|
||||
{
|
||||
//Log.Out("EAIBreakBlockZombieRebirth-CanExecute 1");
|
||||
return false;
|
||||
}
|
||||
if (moveHelper.BlockedTime > 0.35f && moveHelper.CanBreakBlocks)
|
||||
{
|
||||
//Log.Out("EAIBreakBlockZombieRebirth-CanExecute 2");
|
||||
if (moveHelper.HitInfo != null)
|
||||
{
|
||||
//Log.Out("EAIBreakBlockZombieRebirth-CanExecute 3");
|
||||
Vector3i blockPos = moveHelper.HitInfo.hit.blockPos;
|
||||
if (this.theEntity.world.GetBlock(blockPos).isair)
|
||||
{
|
||||
//Log.Out("EAIBreakBlockZombieRebirth-CanExecute 4");
|
||||
return false;
|
||||
}
|
||||
|
||||
var block = GameManager.Instance.World.GetBlock(blockPos);
|
||||
|
||||
bool bHasTags = Block.list[block.type].HasTag(BlockTags.Door);
|
||||
bool bIsOpen = !BlockDoor.IsDoorOpen(block.meta);
|
||||
|
||||
/*Log.Out("EAIBreakBlockZombieRebirth-CanExecute block.meta: " + block.meta);
|
||||
Log.Out("EAIBreakBlockZombieRebirth-CanExecute bHasTags: " + bHasTags);
|
||||
Log.Out("EAIBreakBlockZombieRebirth-CanExecute bIsOpen: " + bIsOpen);*/
|
||||
|
||||
bool isHatch = block.Block.GetBlockName().Contains("Hatch");
|
||||
bool isDoorOpen = BlockDoor.IsDoorOpen(block.meta);
|
||||
|
||||
if (Block.list[block.type].HasTag(BlockTags.Door) &&
|
||||
(!isDoorOpen || (isHatch && isDoorOpen))
|
||||
)
|
||||
{
|
||||
/*Log.Out("EAIBreakBlockZombieRebirth-CanExecute rotation.x: " + block.Block.shape.GetRotation(block).x);
|
||||
Log.Out("EAIBreakBlockZombieRebirth-CanExecute rotation.y: " + block.Block.shape.GetRotation(block).y);
|
||||
Log.Out("EAIBreakBlockZombieRebirth-CanExecute rotation.z: " + block.Block.shape.GetRotation(block).z);*/
|
||||
|
||||
//Log.Out("EAIBreakBlockZombieRebirth-CanExecute IS DOOR AND IS CLOSED");
|
||||
if (GameManager.Instance.World.GetTileEntity(0, blockPos) is TileEntitySecureDoor tileEntitySecureDoor)
|
||||
{
|
||||
//Log.Out("EAIBreakBlockZombieRebirth-CanExecute 5");
|
||||
if (!tileEntitySecureDoor.IsLocked())
|
||||
{
|
||||
//Log.Out("EAIBreakBlockZombieRebirth-CanExecute DOOR IS NOT LOCKED");
|
||||
var chunk = this.theEntity.world.GetChunkFromWorldPos(blockPos) as Chunk;
|
||||
if (tileEntitySecureDoor != null)
|
||||
{
|
||||
//Log.Out("EAIBreakBlockZombieRebirth-CanExecute 6");
|
||||
|
||||
float flCanOpenDoors = this.theEntity.Buffs.GetCustomVar("$varFuriousRamsayOpenDoors");
|
||||
|
||||
if (flCanOpenDoors == 1)
|
||||
{
|
||||
if ((isHatch && isDoorOpen) || (!isHatch && !isDoorOpen))
|
||||
{
|
||||
//Log.Out("EAIBreakBlockZombieRebirth-CanExecute 7");
|
||||
tileEntitySecureDoor.SetLocked(false);
|
||||
/*
|
||||
todo fix
|
||||
block.Block.OnBlockActivated(this.theEntity.world, chunk.ClrIdx, blockPos, block, theEntity);
|
||||
*/
|
||||
Task task = Task.Delay(2000);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
float num = moveHelper.CalcBlockedDistanceSq();
|
||||
float num2 = this.theEntity.m_characterController.GetRadius() + 0.6f;
|
||||
if (num <= num2 * num2)
|
||||
{
|
||||
//Log.Out("EAIBreakBlockZombieRebirth-CanExecute 8");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
//Log.Out("EAIBreakBlockZombieRebirth-CanExecute END");
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void Start()
|
||||
{
|
||||
this.attackDelay = 1;
|
||||
Vector3i blockPos = this.theEntity.moveHelper.HitInfo.hit.blockPos;
|
||||
Block block = this.theEntity.world.GetBlock(blockPos).Block;
|
||||
if (block.HasTag(BlockTags.Door) || block.HasTag(BlockTags.ClosetDoor))
|
||||
{
|
||||
this.theEntity.IsBreakingDoors = true;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Continue()
|
||||
{
|
||||
return this.theEntity.bodyDamage.CurrentStun == EnumEntityStunType.None && this.theEntity.onGround && this.CanExecute();
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
EntityMoveHelper moveHelper = this.theEntity.moveHelper;
|
||||
if (this.attackDelay > 0)
|
||||
{
|
||||
this.attackDelay--;
|
||||
}
|
||||
if (this.attackDelay <= 0)
|
||||
{
|
||||
this.AttackBlock();
|
||||
}
|
||||
}
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
this.theEntity.IsBreakingBlocks = false;
|
||||
this.theEntity.IsBreakingDoors = false;
|
||||
}
|
||||
|
||||
private void AttackBlock()
|
||||
{
|
||||
this.theEntity.SetLookPosition(Vector3.zero);
|
||||
ItemActionAttackData itemActionAttackData = this.theEntity.inventory.holdingItemData.actionData[0] as ItemActionAttackData;
|
||||
if (itemActionAttackData == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
this.damageBoostPercent = 0f;
|
||||
Bounds bb;
|
||||
bb = new Bounds(this.theEntity.position, new Vector3(1.7f, 1.5f, 1.7f));
|
||||
this.theEntity.world.GetEntitiesInBounds(typeof(EntityZombie), bb, this.allies);
|
||||
for (int i = this.allies.Count - 1; i >= 0; i--)
|
||||
{
|
||||
if ((EntityZombie)this.allies[i] != this.theEntity)
|
||||
{
|
||||
this.damageBoostPercent += 0.2f;
|
||||
}
|
||||
}
|
||||
this.allies.Clear();
|
||||
if (this.theEntity.Attack(false))
|
||||
{
|
||||
this.theEntity.IsBreakingBlocks = true;
|
||||
float num = 0.25f + base.RandomFloat * 0.8f;
|
||||
if (this.theEntity.moveHelper.IsUnreachableAbove)
|
||||
{
|
||||
num *= 0.5f;
|
||||
}
|
||||
this.attackDelay = (int)((num + 0.75f) * 20f);
|
||||
itemActionAttackData.hitDelegate = new ItemActionAttackData.HitDelegate(this.GetHitInfo);
|
||||
this.theEntity.Attack(true);
|
||||
}
|
||||
}
|
||||
|
||||
private WorldRayHitInfo GetHitInfo(out float damageScale)
|
||||
{
|
||||
EntityMoveHelper moveHelper = this.theEntity.moveHelper;
|
||||
damageScale = moveHelper.DamageScale + this.damageBoostPercent;
|
||||
return moveHelper.HitInfo;
|
||||
}
|
||||
|
||||
private const float cDamageBoostPerAlly = 0.2f;
|
||||
private int attackDelay;
|
||||
private float damageBoostPercent;
|
||||
private List<Entity> allies = new List<Entity>();
|
||||
}
|
||||
203
Scripts/EAI/EAILeapRebirth.cs
Normal file
203
Scripts/EAI/EAILeapRebirth.cs
Normal file
@@ -0,0 +1,203 @@
|
||||
using GamePath;
|
||||
|
||||
public class EAILeapRebirth : EAIBase
|
||||
{
|
||||
public override void Init(EntityAlive _theEntity)
|
||||
{
|
||||
base.Init(_theEntity);
|
||||
this.MutexBits = 3;
|
||||
this.executeDelay = 1f + base.RandomFloat;
|
||||
}
|
||||
|
||||
public override void SetData(DictionarySave<string, string> data)
|
||||
{
|
||||
base.SetData(data);
|
||||
base.GetData(data, "legs", ref this.legCount);
|
||||
}
|
||||
|
||||
public override bool CanExecute()
|
||||
{
|
||||
//Log.Out("EAILeapRebirth-CanExecute START");
|
||||
|
||||
//Log.Out("EAILeapRebirth-CanExecute RebirthUtilities.IsHordeNight(): " + RebirthUtilities.IsHordeNight());
|
||||
|
||||
if (!RebirthUtilities.IsHordeNight())
|
||||
{
|
||||
//Log.Out("EAILeapRebirth-CanExecute IS NOT HORDE NIGHT");
|
||||
if (!this.theEntity.EntityClass.entityClassName.ToLower().Contains("zombiespider"))
|
||||
{
|
||||
//Log.Out("EAILeapRebirth-CanExecute entityClassName: " + this.theEntity.EntityClass.entityClassName.ToLower());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.theEntity.IsDancing)
|
||||
{
|
||||
//Log.Out("EAILeapRebirth-CanExecute 1");
|
||||
return false;
|
||||
}
|
||||
if (!this.theEntity.GetAttackTarget())
|
||||
{
|
||||
//Log.Out("EAILeapRebirth-CanExecute 2");
|
||||
return false;
|
||||
}
|
||||
if (this.theEntity.Jumping)
|
||||
{
|
||||
//Log.Out("EAILeapRebirth-CanExecute IS JUMPING");
|
||||
return false;
|
||||
}
|
||||
if (this.theEntity.Climbing || this.theEntity.IsInElevator())
|
||||
{
|
||||
//Log.Out("EAILeapRebirth-CanExecute IS CLIMBING / IN ELEVATOR");
|
||||
if (!this.theEntity.EntityClass.entityClassName.ToLower().Contains("zombiespider"))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if ((this.legCount <= 2) ? this.theEntity.bodyDamage.IsAnyLegMissing : this.theEntity.bodyDamage.IsAnyArmOrLegMissing)
|
||||
{
|
||||
//Log.Out("EAILeapRebirth-CanExecute 4");
|
||||
return false;
|
||||
}
|
||||
if (this.theEntity.moveHelper.IsBlocked)
|
||||
{
|
||||
//Log.Out("EAILeapRebirth-CanExecute 5");
|
||||
return false;
|
||||
}
|
||||
|
||||
PathEntity path = this.theEntity.navigator.getPath();
|
||||
if (path == null)
|
||||
{
|
||||
//Log.Out("EAILeapRebirth-CanExecute 6");
|
||||
return false;
|
||||
}
|
||||
|
||||
float terrainHeight = this.theEntity.world.GetTerrainHeight((int)path.GetEndPos().x, (int)path.GetEndPos().z);
|
||||
|
||||
if (this.theEntity.position.y < terrainHeight + 2 ||
|
||||
this.theEntity.position.y < terrainHeight - 2
|
||||
)
|
||||
{
|
||||
//Log.Out("EAILeapRebirth-CanExecute terrainHeight: " + terrainHeight);
|
||||
//Log.Out("EAILeapRebirth-CanExecute this.theEntity.position.y: " + this.theEntity.position.y);
|
||||
if (!this.theEntity.EntityClass.entityClassName.ToLower().Contains("zombiespider"))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
float jumpMaxDistance = this.theEntity.jumpMaxDistance;
|
||||
this.leapV = path.GetEndPos() - this.theEntity.position;
|
||||
|
||||
//if (this.leapV.y < -5f || this.leapV.y > 15f)
|
||||
if (this.leapV.y < -5f || this.leapV.y > 0.5f + jumpMaxDistance * 0.5f)
|
||||
{
|
||||
//Log.Out("EAILeapRebirth-CanExecute 7 jumpMaxDistance: " + jumpMaxDistance);
|
||||
//Log.Out("EAILeapRebirth-CanExecute 7 this.leapV.y: " + this.leapV.y);
|
||||
//Log.Out("EAILeapRebirth-CanExecute 7 0.5f + jumpMaxDistance * 0.5f: " + (0.5f + jumpMaxDistance));
|
||||
|
||||
//Log.Out("EAILeapRebirth-CanExecute 7 this.leapV.y < -5f: " + (this.leapV.y < -5f));
|
||||
//Log.Out("EAILeapRebirth-CanExecute 7 this.leapV.y > 0.5f + jumpMaxDistance: " + (this.leapV.y > 0.5f + jumpMaxDistance));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
this.leapDist = Mathf.Sqrt(this.leapV.x * this.leapV.x + this.leapV.z * this.leapV.z);
|
||||
if (this.leapDist < 2.8f || this.leapDist > jumpMaxDistance)
|
||||
{
|
||||
//Log.Out("EAILeapRebirth-CanExecute 8 this.leapDist: " + this.leapDist);
|
||||
//Log.Out("EAILeapRebirth-CanExecute 8 jumpMaxDistance: " + jumpMaxDistance);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity is EntityZombieSDX)
|
||||
{
|
||||
EntityZombieSDX myEntity = (EntityZombieSDX)this.theEntity;
|
||||
if (this.leapDist < myEntity.flLeapMaxDistance || this.leapDist > jumpMaxDistance)
|
||||
{
|
||||
//Log.Out("EAILeapRebirth-CanExecute 9");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//Log.Out("EAILeapRebirth-CanExecute PROCEED terrainHeight: " + terrainHeight);
|
||||
//Log.Out("EAILeapRebirth-CanExecute PROCEED this.theEntity.position.y: " + this.theEntity.position.y);
|
||||
|
||||
Vector3 position = this.theEntity.position;
|
||||
position.y += 1.5f;
|
||||
RaycastHit raycastHit;
|
||||
return !Physics.Raycast(position - Origin.position, this.leapV, out raycastHit, this.leapDist - 0.5f, 1082195968);
|
||||
}
|
||||
|
||||
public override void Start()
|
||||
{
|
||||
this.abortTime = 5f;
|
||||
this.theEntity.navigator.clearPath();
|
||||
this.theEntity.moveHelper.Stop();
|
||||
this.leapYaw = Mathf.Atan2(this.leapV.x, this.leapV.z) * 57.29578f;
|
||||
}
|
||||
|
||||
public override bool Continue()
|
||||
{
|
||||
//Log.Out("EAILeapRebirth-CanExecute START");
|
||||
|
||||
if (this.theEntity.bodyDamage.CurrentStun != EnumEntityStunType.None)
|
||||
{
|
||||
//Log.Out("EAILeapRebirth-Continue 1");
|
||||
return false;
|
||||
}
|
||||
if (this.abortTime <= 0f)
|
||||
{
|
||||
//Log.Out("EAILeapRebirth-Continue 2");
|
||||
return false;
|
||||
}
|
||||
EntityMoveHelper moveHelper = this.theEntity.moveHelper;
|
||||
this.theEntity.SeekYaw(this.leapYaw, 0f, 10f);
|
||||
//Log.Out("EAILeapRebirth-Continue this.leapYaw: " + this.leapYaw);
|
||||
//Log.Out("EAILeapRebirth-Continue Utils.FastAbs(Mathf.DeltaAngle(this.theEntity.rotation.y, this.leapYaw)): " + Utils.FastAbs(Mathf.DeltaAngle(this.theEntity.rotation.y, this.leapYaw)));
|
||||
//if (Utils.FastAbs(Mathf.DeltaAngle(this.theEntity.rotation.y, this.leapYaw)) < 1f)
|
||||
{
|
||||
//Log.Out("EAILeapRebirth-Continue this.leapDist: " + this.leapDist);
|
||||
//Log.Out("EAILeapRebirth-Continue this.leapV.y: " + this.leapV.y);
|
||||
|
||||
//moveHelper.CalcIfUnreachablePos();
|
||||
|
||||
//Log.Out("EAILeapRebirth-Continue IsUnreachableSideJump: " + moveHelper.IsUnreachableSideJump);
|
||||
//Log.Out("EAILeapRebirth-Continue IsUnreachableAbove: " + moveHelper.IsUnreachableAbove);
|
||||
//Log.Out("EAILeapRebirth-Continue UnreachablePos: " + moveHelper.UnreachablePos);
|
||||
|
||||
/*this.theEntity.motion = Vector3.zero;
|
||||
this.theEntity.navigator?.clearPath();
|
||||
this.theEntity.moveHelper?.Stop();
|
||||
this.theEntity.speedForward = 0;
|
||||
this.theEntity.speedStrafe = 0;*/
|
||||
|
||||
if (this.theEntity.GetAttackTarget() != null && this.theEntity.CanSee(this.theEntity.GetAttackTarget()))
|
||||
{
|
||||
//Log.Out("EAILeapRebirth-Continue ROTATE TO PLAYER");
|
||||
moveHelper.moveToPos = this.theEntity.GetAttackTarget().position;
|
||||
this.theEntity.RotateTo(moveHelper.moveToPos.x, moveHelper.moveToPos.y, moveHelper.moveToPos.z, 360f, 360f);
|
||||
}
|
||||
|
||||
moveHelper.StartJump(false, this.leapDist, this.leapV.y);
|
||||
return false;
|
||||
}
|
||||
//return true;
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
this.abortTime -= 0.05f;
|
||||
}
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
}
|
||||
|
||||
private const int cCollisionMask = 1082195968;
|
||||
private int legCount = 2;
|
||||
private Vector3 leapV;
|
||||
private float leapDist;
|
||||
private float leapYaw;
|
||||
private float abortTime;
|
||||
}
|
||||
133
Scripts/EAI/EAIRangedAttackTargetRebirth.cs
Normal file
133
Scripts/EAI/EAIRangedAttackTargetRebirth.cs
Normal file
@@ -0,0 +1,133 @@
|
||||
public class EAIRangedAttackTargetRebirth : EAIBase
|
||||
{
|
||||
public override void Init(EntityAlive _theEntity)
|
||||
{
|
||||
base.Init(_theEntity);
|
||||
this.MutexBits = 11;
|
||||
this.cooldown = 3f;
|
||||
this.attackDuration = 20f;
|
||||
}
|
||||
|
||||
public override void SetData(DictionarySave<string, string> data)
|
||||
{
|
||||
base.SetData(data);
|
||||
base.GetData(data, "itemType", ref this.itemActionType);
|
||||
base.GetData(data, "cooldown", ref this.baseCooldown);
|
||||
base.GetData(data, "duration", ref this.attackDuration);
|
||||
base.GetData(data, "minRange", ref this.minRange);
|
||||
base.GetData(data, "maxRange", ref this.maxRange);
|
||||
base.GetData(data, "unreachableRange", ref this.unreachableRange);
|
||||
}
|
||||
|
||||
public override bool CanExecute()
|
||||
{
|
||||
if (this.theEntity.IsDancing)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (this.cooldown > 0f)
|
||||
{
|
||||
this.cooldown -= this.executeWaitTime;
|
||||
return false;
|
||||
}
|
||||
if (!this.theEntity.IsAttackValid())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
this.entityTarget = this.theEntity.GetAttackTarget();
|
||||
|
||||
bool canSeeTarget = this.theEntity.CanSee(this.entityTarget);
|
||||
|
||||
bool optionCustomXRayDetection = RebirthVariables.customXRayDetection;
|
||||
|
||||
if (optionCustomXRayDetection)
|
||||
{
|
||||
canSeeTarget = true;
|
||||
}
|
||||
|
||||
return !(this.entityTarget == null) && this.InRange() && canSeeTarget;
|
||||
}
|
||||
|
||||
public override void Start()
|
||||
{
|
||||
this.attackTime = 0f;
|
||||
}
|
||||
|
||||
public override bool Continue()
|
||||
{
|
||||
return this.entityTarget && this.entityTarget.IsAlive() && this.attackTime < this.attackDuration && this.theEntity.hasBeenAttackedTime <= 0;
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
this.attackTime += 0.05f;
|
||||
if (this.attackTime < this.attackDuration * 0.5f)
|
||||
{
|
||||
Vector3 headPosition = this.entityTarget.getHeadPosition();
|
||||
if (this.theEntity.IsInFrontOfMe(headPosition))
|
||||
{
|
||||
this.theEntity.SetLookPosition(headPosition);
|
||||
}
|
||||
}
|
||||
this.Attack(false);
|
||||
ItemActionVomit.ItemActionDataVomit itemActionDataVomit = this.theEntity.inventory.holdingItemData.actionData[this.itemActionType] as ItemActionVomit.ItemActionDataVomit;
|
||||
if (itemActionDataVomit != null && itemActionDataVomit.isDone)
|
||||
{
|
||||
this.attackTime = this.attackDuration;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
this.Attack(true);
|
||||
this.theEntity.SetLookPosition(Vector3.zero);
|
||||
this.entityTarget = null;
|
||||
this.cooldown = this.baseCooldown + this.baseCooldown * 0.5f * base.RandomFloat;
|
||||
}
|
||||
|
||||
private void Attack(bool isAttackReleased)
|
||||
{
|
||||
if (this.itemActionType == 0)
|
||||
{
|
||||
this.theEntity.Attack(isAttackReleased);
|
||||
return;
|
||||
}
|
||||
this.theEntity.Use(isAttackReleased);
|
||||
}
|
||||
|
||||
private bool InRange()
|
||||
{
|
||||
float distanceSq = this.entityTarget.GetDistanceSq(this.theEntity);
|
||||
if (this.unreachableRange > 0f)
|
||||
{
|
||||
EntityMoveHelper moveHelper = this.theEntity.moveHelper;
|
||||
if (moveHelper.IsUnreachableAbove || moveHelper.IsUnreachableSide)
|
||||
{
|
||||
return distanceSq <= this.unreachableRange * this.unreachableRange;
|
||||
}
|
||||
}
|
||||
return distanceSq >= this.minRange * this.minRange && distanceSq <= this.maxRange * this.maxRange;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
bool flag = this.entityTarget && this.InRange();
|
||||
return string.Format("{0} {1}, inRange{2}, Time {3}", new object[]
|
||||
{
|
||||
base.ToString(),
|
||||
this.entityTarget ? this.entityTarget.EntityName : "",
|
||||
flag,
|
||||
this.attackTime.ToCultureInvariantString("0.00")
|
||||
});
|
||||
}
|
||||
|
||||
private int itemActionType;
|
||||
private float baseCooldown;
|
||||
private float cooldown;
|
||||
private EntityAlive entityTarget;
|
||||
private float attackTime;
|
||||
private float attackDuration;
|
||||
private float minRange = 4f;
|
||||
private float maxRange = 25f;
|
||||
private float unreachableRange;
|
||||
}
|
||||
87
Scripts/EAI/EAISetAsTargetIfHurtRebirth.cs
Normal file
87
Scripts/EAI/EAISetAsTargetIfHurtRebirth.cs
Normal file
@@ -0,0 +1,87 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class EAISetAsTargetIfHurtRebirth : EAISetAsTargetIfHurt
|
||||
{
|
||||
public override bool CanExecute()
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtRebirth-CanExecute START, source: " + this.theEntity.EntityName);
|
||||
EntityAlive revengeTarget = this.theEntity.GetRevengeTarget();
|
||||
|
||||
bool bIsValidTarget = true;
|
||||
|
||||
if (revengeTarget)
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtRebirth-CanExecute revengeTarget.EntityName: " + revengeTarget.EntityName);
|
||||
//Log.Out("EAISetAsTargetIfHurtRebirth-CanExecute revengeTarget.entityType: " + revengeTarget.entityType);
|
||||
//Log.Out("EAISetAsTargetIfHurtRebirth-CanExecute this.theEntity.entityType: " + this.theEntity.entityType);
|
||||
|
||||
bIsValidTarget = RebirthUtilities.VerifyFactionStanding(this.theEntity, revengeTarget, true); //revengeTarget.entityType != this.theEntity.entityType;
|
||||
|
||||
//Log.Out("EAISetAsTargetIfHurtRebirth-CanExecute bIsValidTarget: " + bIsValidTarget);
|
||||
}
|
||||
|
||||
if (revengeTarget && revengeTarget != this.theEntity.GetAttackTarget() && bIsValidTarget)
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtRebirth-CanExecute 1");
|
||||
if (this.targetClasses != null)
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtRebirth-CanExecute 2");
|
||||
bool flag = false;
|
||||
Type type = revengeTarget.GetType();
|
||||
for (int i = 0; i < this.targetClasses.Count; i++)
|
||||
{
|
||||
EAISetAsTargetIfHurtRebirth.TargetClass targetClass = this.targetClasses[i];
|
||||
if (targetClass.type != null && targetClass.type.IsAssignableFrom(type))
|
||||
{
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!flag)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (this.theEntity.GetAttackTarget() != null && base.GetRandom(3) != 0)
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtRebirth-CanExecute 3");
|
||||
this.theEntity.SetRevengeTarget((EntityAlive) null);
|
||||
return false;
|
||||
}
|
||||
if (base.check(revengeTarget))
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtRebirth-CanExecute 4");
|
||||
return true;
|
||||
}
|
||||
Vector3 vector = this.theEntity.position - revengeTarget.position;
|
||||
float searchRadius = EntityClass.list[this.theEntity.entityClass].SearchRadius;
|
||||
vector = revengeTarget.position + vector.normalized * (searchRadius * 0.35f);
|
||||
Vector3 vector2 = this.manager.random.RandomOnUnitSphere * searchRadius;
|
||||
vector.x += vector2.x;
|
||||
vector.z += vector2.z;
|
||||
Vector3i vector3i = World.worldToBlockPos(vector);
|
||||
int height = (int)this.theEntity.world.GetHeight(vector3i.x, vector3i.z);
|
||||
if (height > 0)
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtRebirth-CanExecute 5");
|
||||
vector.y = (float)height;
|
||||
}
|
||||
int num2 = this.theEntity.CalcInvestigateTicks(1200, revengeTarget);
|
||||
this.theEntity.SetInvestigatePosition(vector, num2, true);
|
||||
if (this.theEntity.entityType == EntityType.Zombie)
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtRebirth-CanExecute 6");
|
||||
num2 /= 6;
|
||||
}
|
||||
this.theEntity.SetAlertTicks(num2);
|
||||
this.theEntity.SetRevengeTarget((EntityAlive) null);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private List<EAISetAsTargetIfHurtRebirth.TargetClass> targetClasses;
|
||||
private struct TargetClass
|
||||
{
|
||||
public Type type;
|
||||
}
|
||||
}
|
||||
190
Scripts/EAI/EAISetAsTargetIfHurtZombieRebirth.cs
Normal file
190
Scripts/EAI/EAISetAsTargetIfHurtZombieRebirth.cs
Normal file
@@ -0,0 +1,190 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class EAISetAsTargetIfHurtZombieRebirth : EAITarget
|
||||
{
|
||||
public override void Init(EntityAlive _theEntity)
|
||||
{
|
||||
base.Init(_theEntity, 0f, false);
|
||||
this.MutexBits = 1;
|
||||
}
|
||||
|
||||
public override void SetData(DictionarySave<string, string> data)
|
||||
{
|
||||
base.SetData(data);
|
||||
this.targetClasses = new List<EAISetAsTargetIfHurtZombieRebirth.TargetClass>();
|
||||
string text;
|
||||
if (data.TryGetValue("class", out text))
|
||||
{
|
||||
string[] array = text.Split(new char[]
|
||||
{
|
||||
','
|
||||
});
|
||||
for (int i = 0; i < array.Length; i++)
|
||||
{
|
||||
EAISetAsTargetIfHurtZombieRebirth.TargetClass item = default(EAISetAsTargetIfHurtZombieRebirth.TargetClass);
|
||||
item.type = EntityFactory.GetEntityType(array[i]);
|
||||
this.targetClasses.Add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override bool CanExecute()
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtZombieRebirth-CanExecute START");
|
||||
EntityAlive revengeTarget = this.theEntity.GetRevengeTarget();
|
||||
|
||||
bool bIsValidTarget = true;
|
||||
|
||||
if (revengeTarget)
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtZombieRebirth-CanExecute revengeTarget.EntityName: " + revengeTarget.EntityName);
|
||||
//Log.Out("EAISetAsTargetIfHurtZombieRebirth-CanExecute revengeTarget.entityType: " + revengeTarget.entityType);
|
||||
//Log.Out("EAISetAsTargetIfHurtZombieRebirth-CanExecute this.theEntity.entityType: " + this.theEntity.entityType);
|
||||
|
||||
bIsValidTarget = RebirthUtilities.VerifyFactionStanding(this.theEntity, revengeTarget); //revengeTarget.entityType != this.theEntity.entityType;
|
||||
|
||||
|
||||
//Log.Out("EAISetAsTargetIfHurtZombieRebirth-CanExecute bIsValidTarget: " + bIsValidTarget);
|
||||
|
||||
if (!bIsValidTarget)
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtZombieRebirth-CanExecute 0a");
|
||||
bool bMindControlled = revengeTarget.Buffs.HasBuff("FuriousRamsayRangedMindControlBuffTier1") ||
|
||||
revengeTarget.Buffs.HasBuff("FuriousRamsayRangedMindControlBuffTier2") ||
|
||||
revengeTarget.Buffs.HasBuff("FuriousRamsayRangedMindControlBuffTier3");
|
||||
|
||||
//Log.Out("EAISetAsTargetIfHurtZombieRebirth-CanExecute FuriousRamsayRangedMindControlBuffTier1: " + revengeTarget.Buffs.HasBuff("FuriousRamsayRangedMindControlBuffTier1"));
|
||||
//Log.Out("EAISetAsTargetIfHurtZombieRebirth-CanExecute FuriousRamsayRangedMindControlBuffTier2: " + revengeTarget.Buffs.HasBuff("FuriousRamsayRangedMindControlBuffTier2"));
|
||||
//Log.Out("EAISetAsTargetIfHurtZombieRebirth-CanExecute FuriousRamsayRangedMindControlBuffTier3: " + revengeTarget.Buffs.HasBuff("FuriousRamsayRangedMindControlBuffTier3"));
|
||||
|
||||
//Log.Out("EAISetAsTargetIfHurtZombieRebirth-CanExecute bMindControlled: " + bMindControlled);
|
||||
|
||||
if (!bMindControlled)
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtZombieRebirth-CanExecute 0b");
|
||||
this.theEntity.SetRevengeTarget((EntityAlive) null);
|
||||
revengeTarget = null;
|
||||
this.theEntity.attackTarget = (EntityAlive) null;
|
||||
this.theEntity.ClearInvestigatePosition();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.theEntity.SetAttackTarget(revengeTarget, 60);
|
||||
//Log.Out("EAISetAsTargetIfHurtZombieRebirth-CanExecute 0c");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtZombieRebirth-CanExecute 0d");
|
||||
}
|
||||
}
|
||||
|
||||
if (revengeTarget && revengeTarget != this.theEntity.GetAttackTarget() && bIsValidTarget)
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtZombieRebirth-CanExecute 1");
|
||||
if (this.targetClasses != null)
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtZombieRebirth-CanExecute 2");
|
||||
bool flag = false;
|
||||
Type type = revengeTarget.GetType();
|
||||
for (int i = 0; i < this.targetClasses.Count; i++)
|
||||
{
|
||||
EAISetAsTargetIfHurtZombieRebirth.TargetClass targetClass = this.targetClasses[i];
|
||||
if (targetClass.type != null && targetClass.type.IsAssignableFrom(type))
|
||||
{
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!flag)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (this.theEntity.GetAttackTarget() != null && base.GetRandom(3) != 0)
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtZombieRebirth-CanExecute 3");
|
||||
this.theEntity.SetRevengeTarget((EntityAlive) null);
|
||||
return false;
|
||||
}
|
||||
if (base.check(revengeTarget))
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtZombieRebirth-CanExecute 4");
|
||||
return true;
|
||||
}
|
||||
Vector3 vector = this.theEntity.position - revengeTarget.position;
|
||||
float searchRadius = EntityClass.list[this.theEntity.entityClass].SearchRadius;
|
||||
vector = revengeTarget.position + vector.normalized * (searchRadius * 0.35f);
|
||||
Vector3 vector2 = this.manager.random.RandomOnUnitSphere * searchRadius;
|
||||
vector.x += vector2.x;
|
||||
vector.z += vector2.z;
|
||||
Vector3i vector3i = World.worldToBlockPos(vector);
|
||||
int height = (int)this.theEntity.world.GetHeight(vector3i.x, vector3i.z);
|
||||
if (height > 0)
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtZombieRebirth-CanExecute 5");
|
||||
vector.y = (float)height;
|
||||
}
|
||||
int num2 = this.theEntity.CalcInvestigateTicks(1200, revengeTarget);
|
||||
this.theEntity.SetInvestigatePosition(vector, num2, true);
|
||||
if (this.theEntity.entityType == EntityType.Zombie)
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtZombieRebirth-CanExecute 6");
|
||||
num2 /= 6;
|
||||
}
|
||||
this.theEntity.SetAlertTicks(num2);
|
||||
this.theEntity.SetRevengeTarget((EntityAlive) null);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void Start()
|
||||
{
|
||||
this.theEntity.SetAttackTarget(this.theEntity.GetRevengeTarget(), 400);
|
||||
this.viewAngleSave = this.theEntity.GetMaxViewAngle();
|
||||
this.theEntity.SetMaxViewAngle(270f);
|
||||
this.viewAngleRestoreCounter = 100;
|
||||
base.Start();
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
if (this.viewAngleRestoreCounter > 0)
|
||||
{
|
||||
this.viewAngleRestoreCounter--;
|
||||
if (this.viewAngleRestoreCounter == 0)
|
||||
{
|
||||
this.restoreViewAngle();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Continue()
|
||||
{
|
||||
return (!(this.theEntity.GetRevengeTarget() != null) || !(this.theEntity.GetAttackTarget() != this.theEntity.GetRevengeTarget())) && base.Continue();
|
||||
}
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
base.Reset();
|
||||
this.restoreViewAngle();
|
||||
}
|
||||
|
||||
private void restoreViewAngle()
|
||||
{
|
||||
if (this.viewAngleSave > 0f)
|
||||
{
|
||||
this.theEntity.SetMaxViewAngle(this.viewAngleSave);
|
||||
this.viewAngleSave = 0f;
|
||||
this.viewAngleRestoreCounter = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private List<EAISetAsTargetIfHurtZombieRebirth.TargetClass> targetClasses;
|
||||
private float viewAngleSave;
|
||||
private int viewAngleRestoreCounter;
|
||||
private struct TargetClass
|
||||
{
|
||||
public Type type;
|
||||
}
|
||||
}
|
||||
413
Scripts/EAI/EAISetNearestEntityAsTargetFatZombieRebirth.cs
Normal file
413
Scripts/EAI/EAISetNearestEntityAsTargetFatZombieRebirth.cs
Normal file
@@ -0,0 +1,413 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
|
||||
public class EAISetNearestEntityAsTargetFatZombieRebirth : EAITarget
|
||||
{
|
||||
public override void Init(EntityAlive _theEntity)
|
||||
{
|
||||
base.Init(_theEntity, 25f, true);
|
||||
this.MutexBits = 1;
|
||||
this.sorter = new EAISetNearestEntityAsTargetSorter(_theEntity);
|
||||
}
|
||||
|
||||
public override void SetData(DictionarySave<string, string> data)
|
||||
{
|
||||
base.SetData(data);
|
||||
this.targetClasses = new List<EAISetNearestEntityAsTargetFatZombieRebirth.TargetClass>();
|
||||
string text;
|
||||
if (data.TryGetValue("class", out text))
|
||||
{
|
||||
string[] array = text.Split(new char[]
|
||||
{
|
||||
','
|
||||
});
|
||||
for (int i = 0; i < array.Length; i += 3)
|
||||
{
|
||||
EAISetNearestEntityAsTargetFatZombieRebirth.TargetClass targetClass;
|
||||
targetClass.type = EntityFactory.GetEntityType(array[i]);
|
||||
targetClass.hearDistMax = 0f;
|
||||
if (i + 1 < array.Length)
|
||||
{
|
||||
targetClass.hearDistMax = StringParsers.ParseFloat(array[i + 1], 0, -1, NumberStyles.Any);
|
||||
}
|
||||
targetClass.seeDistMax = 0f;
|
||||
if (i + 2 < array.Length)
|
||||
{
|
||||
targetClass.seeDistMax = StringParsers.ParseFloat(array[i + 2], 0, -1, NumberStyles.Any);
|
||||
}
|
||||
if (targetClass.type == typeof(EntityPlayer))
|
||||
{
|
||||
this.playerTargetClassIndex = this.targetClasses.Count;
|
||||
}
|
||||
this.targetClasses.Add(targetClass);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override bool CanExecute()
|
||||
{
|
||||
if (this.theEntity.distraction != null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
this.FindTarget();
|
||||
|
||||
if (!this.closeTargetEntity)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
this.targetEntity = this.closeTargetEntity;
|
||||
this.targetPlayer = (this.closeTargetEntity as EntityPlayer);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void FindTarget()
|
||||
{
|
||||
this.closeTargetDist = float.MaxValue;
|
||||
this.closeTargetEntity = null;
|
||||
float seeDistance = this.theEntity.GetSeeDistance();
|
||||
for (int i = 0; i < this.targetClasses.Count; i++)
|
||||
{
|
||||
EAISetNearestEntityAsTargetFatZombieRebirth.TargetClass targetClass = this.targetClasses[i];
|
||||
float num = seeDistance;
|
||||
if (targetClass.seeDistMax > 0f)
|
||||
{
|
||||
num = Utils.FastMin(num, targetClass.seeDistMax * this.theEntity.senseScale);
|
||||
}
|
||||
//Log.Out("FindTarget Distance1: " + num);
|
||||
|
||||
ulong worldTime = GameManager.Instance.World.worldTime;
|
||||
ValueTuple<int, int, int> valueTuple = GameUtils.WorldTimeToElements(worldTime);
|
||||
|
||||
num = (int)(valueTuple.Item1 * 1.5) + 20;
|
||||
//Log.Out("FindTarget Distance2: " + num);
|
||||
|
||||
if (targetClass.type == typeof(EntityVehicle) && !RebirthUtilities.IsHordeNight())
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetFatZombieRebirth-FindTarget EntityVehicle");
|
||||
this.theEntity.world.GetEntitiesInBounds(targetClass.type, BoundsUtils.ExpandBounds(this.theEntity.boundingBox, num, 4f, num), EAISetNearestEntityAsTargetFatZombieRebirth.list);
|
||||
EAISetNearestEntityAsTargetFatZombieRebirth.list.Sort(this.sorter);
|
||||
int j = 0;
|
||||
while (j < EAISetNearestEntityAsTargetFatZombieRebirth.list.Count)
|
||||
{
|
||||
EntityAlive entityAlive = (EntityAlive)EAISetNearestEntityAsTargetFatZombieRebirth.list[j];
|
||||
|
||||
if (entityAlive.EntityName == "vehicleBicycle" || entityAlive.EntityClass.entityClassName == "vehicleBicycle" || entityAlive.Health == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
//Log.Out("EAISetNearestEntityAsTargetFatZombieRebirth-FindTarget entityAlive: " + entityAlive.EntityName);
|
||||
|
||||
float distance = this.theEntity.GetDistance(entityAlive);
|
||||
if (distance < this.closeTargetDist)
|
||||
{
|
||||
// Log.Out("EAISetNearestEntityAsTargetFatZombieRebirth-FindTarget EntityVehicle 1");
|
||||
this.closeTargetDist = distance;
|
||||
this.closeTargetEntity = entityAlive;
|
||||
this.lastSeenPos = entityAlive.position;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
EAISetNearestEntityAsTargetFatZombieRebirth.list.Clear();
|
||||
}
|
||||
else if (targetClass.type == typeof(EntityPlayer))
|
||||
{
|
||||
this.FindTargetPlayer(num);
|
||||
if (this.theEntity.noisePlayer && this.theEntity.noisePlayer != this.closeTargetEntity)
|
||||
{
|
||||
if (this.closeTargetEntity)
|
||||
{
|
||||
if (this.theEntity.noisePlayerVolume >= this.theEntity.noiseWake)
|
||||
{
|
||||
Vector3 position = this.theEntity.noisePlayer.position;
|
||||
float magnitude = (this.theEntity.position - position).magnitude;
|
||||
if (magnitude < this.closeTargetDist)
|
||||
{
|
||||
this.closeTargetDist = magnitude;
|
||||
this.closeTargetEntity = this.theEntity.noisePlayer;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (!this.theEntity.IsSleeping)
|
||||
{
|
||||
this.SeekNoise(this.theEntity.noisePlayer);
|
||||
}
|
||||
}
|
||||
if (this.closeTargetEntity && base.check(this.closeTargetEntity))
|
||||
{
|
||||
EntityPlayer entityPlayer = (EntityPlayer)this.closeTargetEntity;
|
||||
if (entityPlayer.IsBloodMoonDead && entityPlayer.currentLife >= 0.5f)
|
||||
{
|
||||
Log.Out("Player {0}, living {1}, lost BM immunity", new object[]
|
||||
{
|
||||
entityPlayer.GetDebugName(),
|
||||
entityPlayer.currentLife * 60f
|
||||
});
|
||||
entityPlayer.IsBloodMoonDead = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (!this.theEntity.IsSleeping && !this.theEntity.HasInvestigatePosition)
|
||||
{
|
||||
this.theEntity.world.GetEntitiesInBounds(targetClass.type, BoundsUtils.ExpandBounds(this.theEntity.boundingBox, num, 4f, num), EAISetNearestEntityAsTargetFatZombieRebirth.list);
|
||||
EAISetNearestEntityAsTargetFatZombieRebirth.list.Sort(this.sorter);
|
||||
int j = 0;
|
||||
while (j < EAISetNearestEntityAsTargetFatZombieRebirth.list.Count)
|
||||
{
|
||||
EntityAlive entityAlive = (EntityAlive)EAISetNearestEntityAsTargetFatZombieRebirth.list[j];
|
||||
if (!(entityAlive is EntityDrone) && base.check(entityAlive))
|
||||
{
|
||||
float distance = this.theEntity.GetDistance(entityAlive);
|
||||
if (distance < this.closeTargetDist)
|
||||
{
|
||||
this.closeTargetDist = distance;
|
||||
this.closeTargetEntity = entityAlive;
|
||||
this.lastSeenPos = entityAlive.position;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
j++;
|
||||
}
|
||||
}
|
||||
EAISetNearestEntityAsTargetFatZombieRebirth.list.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SeekNoise(EntityPlayer player)
|
||||
{
|
||||
float num = (player.position - this.theEntity.position).magnitude;
|
||||
if (this.playerTargetClassIndex >= 0)
|
||||
{
|
||||
float num2 = this.targetClasses[this.playerTargetClassIndex].hearDistMax;
|
||||
if (num2 > 0f)
|
||||
{
|
||||
num2 *= this.theEntity.senseScale;
|
||||
if (num > num2)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
num *= 0.9f;
|
||||
if (num > this.manager.noiseSeekDist)
|
||||
{
|
||||
num = this.manager.noiseSeekDist;
|
||||
}
|
||||
if (this.theEntity.IsBloodMoon)
|
||||
{
|
||||
num = this.manager.noiseSeekDist * 0.25f;
|
||||
}
|
||||
Vector3 breadcrumbPos = player.GetBreadcrumbPos(num * base.RandomFloat);
|
||||
int ticks = this.theEntity.CalcInvestigateTicks((int)(30f + base.RandomFloat * 30f) * 20, player);
|
||||
this.theEntity.SetInvestigatePosition(breadcrumbPos, ticks, true);
|
||||
float time = Time.time;
|
||||
if (this.senseSoundTime - time < 0f)
|
||||
{
|
||||
this.senseSoundTime = time + 10f + base.RandomFloat * 10f;
|
||||
this.theEntity.PlayOneShot(this.theEntity.soundSense, false);
|
||||
}
|
||||
}
|
||||
|
||||
private void FindTargetPlayer(float seeDist)
|
||||
{
|
||||
if (this.theEntity.IsSleeperPassive)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
string rebirthFeralSense = RebirthVariables.customFeralSense;
|
||||
int currentDay = GameUtils.WorldTimeToDays(GameManager.Instance.World.worldTime);
|
||||
|
||||
bool randomValid = rebirthFeralSense == "random" &&
|
||||
currentDay == RebirthManager.nextFeralSenseDay;
|
||||
|
||||
if (randomValid && GameManager.Instance.World.IsDaytime() && RebirthManager.nextFeralSensePeriod == 1)
|
||||
{
|
||||
randomValid = false;
|
||||
}
|
||||
if (randomValid && !GameManager.Instance.World.IsDaytime() && RebirthManager.nextFeralSensePeriod == 2)
|
||||
{
|
||||
randomValid = false;
|
||||
}
|
||||
|
||||
bool isValidFeralSense = (rebirthFeralSense == "always") ||
|
||||
(GameManager.Instance.World.IsDaytime() && rebirthFeralSense == "dayonly") ||
|
||||
(!GameManager.Instance.World.IsDaytime() && rebirthFeralSense == "nightonly") ||
|
||||
randomValid;
|
||||
|
||||
string rebirthPOISense = RebirthVariables.customPOISense;
|
||||
bool POISense = (rebirthPOISense == "always") ||
|
||||
(GameManager.Instance.World.IsDaytime() && rebirthPOISense == "dayonly") ||
|
||||
(!GameManager.Instance.World.IsDaytime() && rebirthPOISense == "nightonly");
|
||||
|
||||
if (isValidFeralSense || (this.theEntity.IsSleeper && POISense))
|
||||
{
|
||||
seeDist = 200;
|
||||
this.theEntity.SetMaxViewAngle(360);
|
||||
}
|
||||
|
||||
this.theEntity.world.GetEntitiesInBounds(typeof(EntityPlayer), BoundsUtils.ExpandBounds(this.theEntity.boundingBox, seeDist, seeDist, seeDist), EAISetNearestEntityAsTargetFatZombieRebirth.list);
|
||||
if (!this.theEntity.IsSleeping)
|
||||
{
|
||||
for (int i = 0; i < EAISetNearestEntityAsTargetFatZombieRebirth.list.Count; i++)
|
||||
{
|
||||
EntityPlayer entityPlayer = (EntityPlayer)EAISetNearestEntityAsTargetFatZombieRebirth.list[i];
|
||||
if (entityPlayer.IsAlive() && !entityPlayer.IsIgnoredByAI())
|
||||
{
|
||||
float distance = this.theEntity.GetDistance(entityPlayer);
|
||||
if (distance < this.closeTargetDist && this.theEntity.CanSee(entityPlayer) && this.theEntity.CanSeeStealth(distance, entityPlayer.Stealth.lightLevel))
|
||||
{
|
||||
this.closeTargetDist = distance;
|
||||
this.closeTargetEntity = entityPlayer;
|
||||
}
|
||||
}
|
||||
}
|
||||
EAISetNearestEntityAsTargetFatZombieRebirth.list.Clear();
|
||||
return;
|
||||
}
|
||||
|
||||
EAISetNearestEntityAsTargetFatZombieRebirth.list.Sort(this.sorter);
|
||||
EntityPlayer x = null;
|
||||
float num = float.MaxValue;
|
||||
bool flag = false;
|
||||
if (this.theEntity.noisePlayer != null)
|
||||
{
|
||||
if (this.theEntity.noisePlayerVolume >= this.theEntity.noiseWake)
|
||||
{
|
||||
x = this.theEntity.noisePlayer;
|
||||
num = this.theEntity.noisePlayerDistance;
|
||||
}
|
||||
else if (this.theEntity.noisePlayerVolume >= this.theEntity.noiseGroan)
|
||||
{
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
for (int j = 0; j < EAISetNearestEntityAsTargetFatZombieRebirth.list.Count; j++)
|
||||
{
|
||||
EntityPlayer entityPlayer2 = (EntityPlayer)EAISetNearestEntityAsTargetFatZombieRebirth.list[j];
|
||||
if (this.theEntity.CanSee(entityPlayer2) && !entityPlayer2.IsIgnoredByAI())
|
||||
{
|
||||
float distance2 = this.theEntity.GetDistance(entityPlayer2);
|
||||
int sleeperDisturbedLevel = this.theEntity.GetSleeperDisturbedLevel(distance2, entityPlayer2.Stealth.lightLevel);
|
||||
if (sleeperDisturbedLevel >= 2)
|
||||
{
|
||||
if (distance2 < num)
|
||||
{
|
||||
x = entityPlayer2;
|
||||
num = distance2;
|
||||
}
|
||||
}
|
||||
else if (sleeperDisturbedLevel >= 1)
|
||||
{
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
EAISetNearestEntityAsTargetFatZombieRebirth.list.Clear();
|
||||
if (x != null)
|
||||
{
|
||||
this.closeTargetDist = num;
|
||||
this.closeTargetEntity = x;
|
||||
return;
|
||||
}
|
||||
if (flag)
|
||||
{
|
||||
this.theEntity.Groan();
|
||||
return;
|
||||
}
|
||||
this.theEntity.Snore();
|
||||
}
|
||||
|
||||
public override void Start()
|
||||
{
|
||||
this.theEntity.SetAttackTarget(this.targetEntity, 200);
|
||||
this.theEntity.ConditionalTriggerSleeperWakeUp();
|
||||
base.Start();
|
||||
}
|
||||
|
||||
public override bool Continue()
|
||||
{
|
||||
if (this.targetEntity.IsDead() || this.theEntity.distraction != null)
|
||||
{
|
||||
if (this.theEntity.GetAttackTarget() == this.targetEntity)
|
||||
{
|
||||
this.theEntity.attackTarget = (EntityAlive) null;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
this.findTime += 0.05f;
|
||||
if (this.findTime > 2f)
|
||||
{
|
||||
this.findTime = 0f;
|
||||
this.FindTarget();
|
||||
if (this.closeTargetEntity && this.closeTargetEntity != this.targetEntity)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (this.theEntity.GetAttackTarget() != this.targetEntity)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (base.check(targetEntity) && (this.targetPlayer == null || this.theEntity.CanSeeStealth(this.theEntity.GetDistance(this.targetEntity), this.targetPlayer.Stealth.lightLevel)))
|
||||
{
|
||||
this.theEntity.SetAttackTarget(this.targetEntity, 600);
|
||||
this.lastSeenPos = this.targetEntity.position;
|
||||
return true;
|
||||
}
|
||||
if (this.theEntity.GetDistanceSq(this.lastSeenPos) < 2.25f)
|
||||
{
|
||||
this.lastSeenPos = Vector3.zero;
|
||||
}
|
||||
this.theEntity.attackTarget = (EntityAlive) null;
|
||||
int num = this.theEntity.CalcInvestigateTicks(Constants.cEnemySenseMemory * 20, this.targetEntity);
|
||||
if (this.lastSeenPos != Vector3.zero)
|
||||
{
|
||||
this.theEntity.SetInvestigatePosition(this.lastSeenPos, num, true);
|
||||
}
|
||||
if (this.targetPlayer)
|
||||
{
|
||||
if (this.theEntity.entityType == EntityType.Zombie)
|
||||
{
|
||||
num /= 6;
|
||||
}
|
||||
this.theEntity.SetAlertTicks(num);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
this.targetEntity = null;
|
||||
this.targetPlayer = null;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Format("{0}, {1}", base.ToString(), this.targetEntity ? this.targetEntity.EntityName : "");
|
||||
}
|
||||
|
||||
private List<EAISetNearestEntityAsTargetFatZombieRebirth.TargetClass> targetClasses;
|
||||
private int playerTargetClassIndex = -1;
|
||||
private float closeTargetDist;
|
||||
private EntityAlive closeTargetEntity;
|
||||
private EntityAlive targetEntity;
|
||||
private EntityPlayer targetPlayer;
|
||||
private Vector3 lastSeenPos;
|
||||
private float findTime;
|
||||
private float senseSoundTime;
|
||||
private EAISetNearestEntityAsTargetSorter sorter;
|
||||
private static List<Entity> list = new List<Entity>();
|
||||
|
||||
private struct TargetClass
|
||||
{
|
||||
public Type type;
|
||||
public float hearDistMax;
|
||||
public float seeDistMax;
|
||||
}
|
||||
}
|
||||
232
Scripts/EAI/EAISetNearestEntityAsTargetSDX.cs
Normal file
232
Scripts/EAI/EAISetNearestEntityAsTargetSDX.cs
Normal file
@@ -0,0 +1,232 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class EAISetNearestEntityAsTargetSDX : EAISetNearestEntityAsTarget
|
||||
{
|
||||
private void SeekNoise(EntityPlayer player)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetSDX-SeekNoise START");
|
||||
float num = (player.position - this.theEntity.position).magnitude;
|
||||
if (this.playerTargetClassIndex >= 0)
|
||||
{
|
||||
float num2 = this.targetClasses[this.playerTargetClassIndex].hearDistMax;
|
||||
if (num2 > 0f)
|
||||
{
|
||||
num2 *= this.theEntity.senseScale;
|
||||
if (num > num2)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
num *= 0.9f;
|
||||
if (num > this.manager.noiseSeekDist)
|
||||
{
|
||||
num = this.manager.noiseSeekDist;
|
||||
}
|
||||
if (this.theEntity.IsBloodMoon)
|
||||
{
|
||||
num = this.manager.noiseSeekDist * 0.25f;
|
||||
}
|
||||
Vector3 breadcrumbPos = player.GetBreadcrumbPos(num * base.RandomFloat);
|
||||
int ticks = this.theEntity.CalcInvestigateTicks((int)(30f + base.RandomFloat * 30f) * 20, player);
|
||||
this.theEntity.SetInvestigatePosition(breadcrumbPos, ticks, true);
|
||||
float time = Time.time;
|
||||
if (this.senseSoundTime - time < 0f)
|
||||
{
|
||||
this.senseSoundTime = time + 10f + base.RandomFloat * 10f;
|
||||
this.theEntity.PlayOneShot(this.theEntity.soundSense, false);
|
||||
}
|
||||
}
|
||||
|
||||
private void FindTarget()
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetSDX-FindTarget START");
|
||||
this.closeTargetDist = float.MaxValue;
|
||||
this.closeTargetEntity = null;
|
||||
|
||||
float seeDistance = this.theEntity.GetSeeDistance();
|
||||
|
||||
for (int i = 0; i < this.targetClasses.Count; i++)
|
||||
{
|
||||
EAISetNearestEntityAsTargetSDX.TargetClass targetClass = this.targetClasses[i];
|
||||
float num = seeDistance;
|
||||
if (targetClass.seeDistMax > 0f)
|
||||
{
|
||||
num = Utils.FastMin(num, targetClass.seeDistMax * this.theEntity.senseScale);
|
||||
}
|
||||
|
||||
bool bMindControlled = this.theEntity.Buffs.HasBuff("FuriousRamsayRangedMindControlBuffTier1") || this.theEntity.Buffs.HasBuff("FuriousRamsayRangedMindControlBuffTier2") || this.theEntity.Buffs.HasBuff("FuriousRamsayRangedMindControlBuffTier3");
|
||||
|
||||
if (bMindControlled)
|
||||
{
|
||||
this.theEntity.SetMaxViewAngle(360);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.theEntity.SetMaxViewAngle(180);
|
||||
}
|
||||
|
||||
if (targetClass.type == typeof(EntityPlayer) && !bMindControlled)
|
||||
{
|
||||
this.FindTargetPlayer(num);
|
||||
if (this.theEntity.noisePlayer && this.theEntity.noisePlayer != this.closeTargetEntity)
|
||||
{
|
||||
if (this.closeTargetEntity)
|
||||
{
|
||||
if (this.theEntity.noisePlayerVolume >= this.theEntity.noiseWake)
|
||||
{
|
||||
Vector3 position = this.theEntity.noisePlayer.position;
|
||||
float magnitude = (this.theEntity.position - position).magnitude;
|
||||
if (magnitude < this.closeTargetDist)
|
||||
{
|
||||
this.closeTargetDist = magnitude;
|
||||
this.closeTargetEntity = this.theEntity.noisePlayer;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (!this.theEntity.IsSleeping)
|
||||
{
|
||||
this.SeekNoise(this.theEntity.noisePlayer);
|
||||
}
|
||||
}
|
||||
if (this.closeTargetEntity)
|
||||
{
|
||||
EntityPlayer entityPlayer = (EntityPlayer)this.closeTargetEntity;
|
||||
if (entityPlayer.IsBloodMoonDead && entityPlayer.currentLife >= 0.5f)
|
||||
{
|
||||
Log.Out("Player {0}, living {1}, lost BM immunity", new object[]
|
||||
{
|
||||
entityPlayer.GetDebugName(),
|
||||
entityPlayer.currentLife * 60f
|
||||
});
|
||||
entityPlayer.IsBloodMoonDead = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (!this.theEntity.IsSleeping && !this.theEntity.HasInvestigatePosition)
|
||||
{
|
||||
EAISetNearestEntityAsTargetSDX.list = this.theEntity.world.GetEntitiesInBounds(targetClass.type, BoundsUtils.ExpandBounds(this.theEntity.boundingBox, num, 4f, num), EAISetNearestEntityAsTargetSDX.list);
|
||||
EAISetNearestEntityAsTargetSDX.list.Sort(this.sorter);
|
||||
int j = 0;
|
||||
while (j < EAISetNearestEntityAsTargetSDX.list.Count)
|
||||
{
|
||||
EntityAlive entityAlive = (EntityAlive)EAISetNearestEntityAsTargetSDX.list[j];
|
||||
if (!(entityAlive is EntityDrone) && base.check(entityAlive))
|
||||
{
|
||||
float distance = this.theEntity.GetDistance(entityAlive);
|
||||
if (distance < this.closeTargetDist)
|
||||
{
|
||||
this.closeTargetDist = distance;
|
||||
this.closeTargetEntity = entityAlive;
|
||||
this.lastSeenPos = entityAlive.position;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
j++;
|
||||
}
|
||||
}
|
||||
EAISetNearestEntityAsTargetSDX.list.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void FindTargetPlayer(float seeDist)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetSDX-FindTargetPlayer START");
|
||||
if (this.theEntity.IsSleeperPassive)
|
||||
{
|
||||
return;
|
||||
}
|
||||
this.theEntity.world.GetEntitiesInBounds(typeof(EntityPlayer), BoundsUtils.ExpandBounds(this.theEntity.boundingBox, seeDist, seeDist, seeDist), EAISetNearestEntityAsTargetSDX.list);
|
||||
if (!this.theEntity.IsSleeping)
|
||||
{
|
||||
for (int i = 0; i < EAISetNearestEntityAsTargetSDX.list.Count; i++)
|
||||
{
|
||||
EntityPlayer entityPlayer = (EntityPlayer)EAISetNearestEntityAsTargetSDX.list[i];
|
||||
if (entityPlayer.IsAlive() && !entityPlayer.IsIgnoredByAI() && !entityPlayer.IsSpectator)
|
||||
{
|
||||
float distance = this.theEntity.GetDistance(entityPlayer);
|
||||
if (distance < this.closeTargetDist)
|
||||
{
|
||||
this.closeTargetDist = distance;
|
||||
this.closeTargetEntity = entityPlayer;
|
||||
}
|
||||
}
|
||||
}
|
||||
EAISetNearestEntityAsTargetSDX.list.Clear();
|
||||
return;
|
||||
}
|
||||
|
||||
EAISetNearestEntityAsTargetSDX.list.Sort(this.sorter);
|
||||
EntityPlayer entityPlayer2 = null;
|
||||
float num = float.MaxValue;
|
||||
bool flag = false;
|
||||
if (this.theEntity.noisePlayer != null)
|
||||
{
|
||||
if (this.theEntity.noisePlayerVolume >= this.theEntity.noiseWake)
|
||||
{
|
||||
entityPlayer2 = this.theEntity.noisePlayer;
|
||||
num = this.theEntity.noisePlayerDistance;
|
||||
}
|
||||
else if (this.theEntity.noisePlayerVolume >= this.theEntity.noiseGroan)
|
||||
{
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
for (int j = 0; j < EAISetNearestEntityAsTargetSDX.list.Count; j++)
|
||||
{
|
||||
EntityPlayer entityPlayer3 = (EntityPlayer)EAISetNearestEntityAsTargetSDX.list[j];
|
||||
if (!entityPlayer3.IsIgnoredByAI())
|
||||
{
|
||||
float distance2 = this.theEntity.GetDistance(entityPlayer3);
|
||||
int sleeperDisturbedLevel = this.theEntity.GetSleeperDisturbedLevel(distance2, entityPlayer3.Stealth.lightLevel);
|
||||
if (sleeperDisturbedLevel >= 2)
|
||||
{
|
||||
if (distance2 < num)
|
||||
{
|
||||
entityPlayer2 = entityPlayer3;
|
||||
num = distance2;
|
||||
}
|
||||
}
|
||||
else if (sleeperDisturbedLevel >= 1)
|
||||
{
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
EAISetNearestEntityAsTargetSDX.list.Clear();
|
||||
if (entityPlayer2 != null)
|
||||
{
|
||||
this.closeTargetDist = num;
|
||||
this.closeTargetEntity = entityPlayer2;
|
||||
return;
|
||||
}
|
||||
if (flag)
|
||||
{
|
||||
this.theEntity.Groan();
|
||||
return;
|
||||
}
|
||||
this.theEntity.Snore();
|
||||
}
|
||||
|
||||
private List<EAISetNearestEntityAsTargetSDX.TargetClass> targetClasses;
|
||||
private int playerTargetClassIndex = -1;
|
||||
private float closeTargetDist;
|
||||
private EntityAlive closeTargetEntity;
|
||||
private EntityAlive targetEntity;
|
||||
private EntityPlayer targetPlayer;
|
||||
private Vector3 lastSeenPos;
|
||||
private float findTime;
|
||||
private float senseSoundTime;
|
||||
private EAISetNearestEntityAsTargetSorter sorter;
|
||||
private static List<Entity> list = new List<Entity>();
|
||||
private struct TargetClass
|
||||
{
|
||||
public Type type;
|
||||
public float hearDistMax;
|
||||
public float seeDistMax;
|
||||
}
|
||||
}
|
||||
680
Scripts/EAI/EAISetNearestEntityAsTargetZombieRebirth.cs
Normal file
680
Scripts/EAI/EAISetNearestEntityAsTargetZombieRebirth.cs
Normal file
@@ -0,0 +1,680 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
|
||||
public class EAISetNearestEntityAsTargetZombieRebirth : EAITarget
|
||||
{
|
||||
public override void Init(EntityAlive _theEntity)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-Init START");
|
||||
base.Init(_theEntity, 25f, true);
|
||||
this.MutexBits = 1;
|
||||
this.sorter = new EAISetNearestEntityAsTargetSorter(_theEntity);
|
||||
}
|
||||
|
||||
private bool bNeedToSee;
|
||||
|
||||
public override void SetData(DictionarySave<string, string> data)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-SetData START");
|
||||
base.SetData(data);
|
||||
this.targetClasses = new List<EAISetNearestEntityAsTargetZombieRebirth.TargetClass>();
|
||||
string text;
|
||||
if (data.TryGetValue("class", out text))
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-SetData text: " + this.theEntity.EntityClass.entityClassName);
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-SetData text: " + text);
|
||||
|
||||
string[] array = text.Split(',', (char)StringSplitOptions.None);
|
||||
for (int i = 0; i < array.Length; i += 3)
|
||||
{
|
||||
EAISetNearestEntityAsTargetZombieRebirth.TargetClass targetClass;
|
||||
targetClass.type = EntityFactory.GetEntityType(array[i]);
|
||||
targetClass.hearDistMax = 0f;
|
||||
if (i + 1 < array.Length)
|
||||
{
|
||||
targetClass.hearDistMax = StringParsers.ParseFloat(array[i + 1], 0, -1, NumberStyles.Any);
|
||||
}
|
||||
if (targetClass.hearDistMax == 0f)
|
||||
{
|
||||
targetClass.hearDistMax = 50f;
|
||||
}
|
||||
targetClass.seeDistMax = 0f;
|
||||
if (i + 2 < array.Length)
|
||||
{
|
||||
targetClass.seeDistMax = StringParsers.ParseFloat(array[i + 2], 0, -1, NumberStyles.Any);
|
||||
}
|
||||
if (targetClass.type == typeof(EntityPlayer))
|
||||
{
|
||||
this.playerTargetClassIndex = this.targetClasses.Count;
|
||||
}
|
||||
this.targetClasses.Add(targetClass);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override bool CanExecute()
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-CanExecute START");
|
||||
if (this.theEntity.distraction != null)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-CanExecute 1");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.Buffs.GetCustomVar("$eventSpawn") == 1f)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-CanExecute EVENT SPAWN");
|
||||
if (this.theEntity.GetAttackTarget() != null)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-CanExecute ALREADY HAS A TARGET");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
this.foundDecoy = false;
|
||||
|
||||
if (!this.closeTargetEntity)
|
||||
{
|
||||
this.FindTarget();
|
||||
}
|
||||
|
||||
if (!this.closeTargetEntity)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-CanExecute 2");
|
||||
return false;
|
||||
}
|
||||
|
||||
this.targetEntity = this.closeTargetEntity;
|
||||
this.targetPlayer = (this.closeTargetEntity as EntityPlayer);
|
||||
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-CanExecute this.targetEntity: " + this.targetEntity.EntityClass.entityClassName);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void FindTarget()
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-FindTarget START");
|
||||
this.closeTargetDist = float.MaxValue;
|
||||
this.closeTargetEntity = null;
|
||||
|
||||
float seeDistance = this.theEntity.GetSeeDistance();
|
||||
|
||||
for (int i = 0; i < this.targetClasses.Count; i++)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-FindTarget this.targetClasses[" + i + "]: " + this.targetClasses[i].type);
|
||||
EAISetNearestEntityAsTargetZombieRebirth.TargetClass targetClass = this.targetClasses[i];
|
||||
|
||||
float num = seeDistance;
|
||||
if (targetClass.seeDistMax > 0f)
|
||||
{
|
||||
num = Utils.FastMin(num, targetClass.seeDistMax * this.theEntity.senseScale);
|
||||
}
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-FindTarget Distance1: " + num);
|
||||
|
||||
ulong worldTime = GameManager.Instance.World.worldTime;
|
||||
ValueTuple<int, int, int> valueTuple = GameUtils.WorldTimeToElements(worldTime);
|
||||
|
||||
num = (int)(valueTuple.Item1 * 1.5) + 20;
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-FindTarget Distance2: " + num);
|
||||
|
||||
if (this.theEntity.HasAnyTags(FastTags<TagGroup.Global>.Parse("event")))
|
||||
{
|
||||
num = 200;
|
||||
}
|
||||
|
||||
bool bMindControlled = this.theEntity.Buffs.HasBuff("FuriousRamsayRangedMindControlBuffTier1") || this.theEntity.Buffs.HasBuff("FuriousRamsayRangedMindControlBuffTier2") || this.theEntity.Buffs.HasBuff("FuriousRamsayRangedMindControlBuffTier3");
|
||||
|
||||
if (bMindControlled || this.theEntity.Buffs.GetCustomVar("$eventSpawn") == 1f)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-FindTarget 1");
|
||||
num = 200;
|
||||
this.theEntity.SetMaxViewAngle(360);
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-FindTarget 2");
|
||||
num = 50;
|
||||
this.theEntity.SetMaxViewAngle(180);
|
||||
}
|
||||
|
||||
string rebirthFeralSense = RebirthVariables.customFeralSense;
|
||||
int currentDay = GameUtils.WorldTimeToDays(GameManager.Instance.World.worldTime);
|
||||
|
||||
bool randomValid = rebirthFeralSense == "random" &&
|
||||
currentDay == RebirthManager.nextFeralSenseDay;
|
||||
|
||||
if (randomValid && GameManager.Instance.World.IsDaytime() && RebirthManager.nextFeralSensePeriod == 1)
|
||||
{
|
||||
randomValid = false;
|
||||
}
|
||||
if (randomValid && !GameManager.Instance.World.IsDaytime() && RebirthManager.nextFeralSensePeriod == 2)
|
||||
{
|
||||
randomValid = false;
|
||||
}
|
||||
|
||||
bool isValidFeralSense = (rebirthFeralSense == "always") ||
|
||||
(GameManager.Instance.World.IsDaytime() && rebirthFeralSense == "dayonly") ||
|
||||
(!GameManager.Instance.World.IsDaytime() && rebirthFeralSense == "nightonly") ||
|
||||
randomValid;
|
||||
|
||||
string rebirthPOISense = RebirthVariables.customPOISense;
|
||||
bool POISense = (rebirthPOISense == "always") ||
|
||||
(GameManager.Instance.World.IsDaytime() && rebirthPOISense == "dayonly") ||
|
||||
(!GameManager.Instance.World.IsDaytime() && rebirthPOISense == "nightonly");
|
||||
|
||||
if (isValidFeralSense || (this.theEntity.IsSleeper && POISense))
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-checkEntity FERAL SENSE ON");
|
||||
num = 200;
|
||||
this.theEntity.SetMaxViewAngle(360);
|
||||
}
|
||||
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-FindTarget bMindControlled: " + bMindControlled);
|
||||
|
||||
if (!foundDecoy && targetClass.type == typeof(EntityPlayer) && !bMindControlled)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-FindTarget 3");
|
||||
this.FindTargetPlayer(num);
|
||||
if (this.theEntity.noisePlayer && this.theEntity.noisePlayer != this.closeTargetEntity)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-FindTarget 4");
|
||||
if (this.closeTargetEntity)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-FindTarget 5");
|
||||
if (this.theEntity.noisePlayerVolume >= this.theEntity.noiseWake)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-FindTarget 6");
|
||||
Vector3 position = this.theEntity.noisePlayer.position;
|
||||
float magnitude = (this.theEntity.position - position).magnitude;
|
||||
if (magnitude < this.closeTargetDist)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-FindTarget 7");
|
||||
this.closeTargetDist = magnitude;
|
||||
this.closeTargetEntity = this.theEntity.noisePlayer;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (!this.theEntity.IsSleeping)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-FindTarget 8");
|
||||
this.SeekNoise(this.theEntity.noisePlayer);
|
||||
}
|
||||
}
|
||||
if (this.closeTargetEntity is EntityPlayer)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-FindTarget 9");
|
||||
EntityPlayer entityPlayer = (EntityPlayer)this.closeTargetEntity;
|
||||
if (entityPlayer.IsBloodMoonDead && entityPlayer.currentLife >= 0.5f)
|
||||
{
|
||||
Log.Out("Player {0}, living {1}, lost BM immunity", new object[]
|
||||
{
|
||||
entityPlayer.GetDebugName(),
|
||||
entityPlayer.currentLife * 60f
|
||||
});
|
||||
entityPlayer.IsBloodMoonDead = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-FindTarget this.theEntity.IsSleeping: " + this.theEntity.IsSleeping);
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-FindTarget this.theEntity.HasInvestigatePosition: " + this.theEntity.HasInvestigatePosition);
|
||||
|
||||
if (!this.theEntity.IsSleeping && !this.theEntity.HasInvestigatePosition)
|
||||
//if (!this.theEntity.IsSleeping)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-FindTarget 10");
|
||||
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-FindTarget targetClass: " + targetClass);
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-FindTarget targetClass.type: " + targetClass.type);
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-FindTarget this.theEntity.boundingBox: " + this.theEntity.boundingBox);
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-FindTarget BoundsUtils.ExpandBounds(this.theEntity.boundingBox, num, 4f, num): " + BoundsUtils.ExpandBounds(this.theEntity.boundingBox, num, 4f, num));
|
||||
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-FindTarget EAISetNearestEntityAsTargetZombieRebirth.list.Count: " + EAISetNearestEntityAsTargetZombieRebirth.list.Count);
|
||||
|
||||
bool foundTarget = false;
|
||||
|
||||
if (!bMindControlled)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-FindTarget 10A");
|
||||
this.theEntity.world.GetEntitiesInBounds(typeof(EntitySurvivor), BoundsUtils.ExpandBounds(this.theEntity.boundingBox, num, 4f, num), EAISetNearestEntityAsTargetZombieRebirth.list);
|
||||
EAISetNearestEntityAsTargetZombieRebirth.list.Sort(this.sorter);
|
||||
int j = 0;
|
||||
while (j < EAISetNearestEntityAsTargetZombieRebirth.list.Count)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-FindTarget 10B, j: " + j);
|
||||
EntityAlive entityAlive = (EntityAlive)EAISetNearestEntityAsTargetZombieRebirth.list[j];
|
||||
|
||||
bool isValid = true;
|
||||
|
||||
if (!entityAlive.IsAlive())
|
||||
{
|
||||
isValid = false;
|
||||
}
|
||||
else if (!RebirthUtilities.VerifyFactionStanding(this.theEntity, entityAlive))
|
||||
{
|
||||
if (RebirthVariables.noHit && this.theEntity != entityAlive)
|
||||
{
|
||||
Log.Out($"EAISetNearestEntityAsTargetZombieRebirth-FindTarget NO HIT, should attack is false source: {this.theEntity}, target {entityAlive}");
|
||||
}
|
||||
isValid = false;
|
||||
}
|
||||
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-FindTarget 10C, isValid: " + isValid);
|
||||
|
||||
//if (isValid && !(entityAlive is EntityDrone) && base.check(entityAlive))
|
||||
if (isValid && !(entityAlive is EntityDrone) && (base.check(entityAlive) || entityAlive.CanSee(this.theEntity)))
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-FindTarget 10D");
|
||||
float distance = this.theEntity.GetDistance(entityAlive);
|
||||
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-FindTarget 10D, distance: " + distance);
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-FindTarget 10D, this.closeTargetDist: " + this.closeTargetDist);
|
||||
|
||||
/*if (this.closeTargetEntity != null)
|
||||
{
|
||||
Log.Out("EAISetNearestEntityAsTargetZombieRebirth-FindTarget this.closeTargetEntity: " + this.closeTargetEntity.EntityName);
|
||||
}*/
|
||||
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-FindTarget this.closeTargetEntity is EntityPlayer: " + (this.closeTargetEntity is EntityPlayer));
|
||||
|
||||
if (distance < this.closeTargetDist || this.closeTargetEntity is EntityPlayer)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-FindTarget 10E");
|
||||
this.closeTargetDist = distance;
|
||||
this.closeTargetEntity = entityAlive;
|
||||
this.lastSeenPos = entityAlive.position;
|
||||
foundTarget = true;
|
||||
foundDecoy = true;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-FindTarget 10F: " + entityAlive.EntityClass.entityClassName);
|
||||
j++;
|
||||
}
|
||||
}
|
||||
EAISetNearestEntityAsTargetZombieRebirth.list.Clear();
|
||||
}
|
||||
|
||||
if (!foundTarget && !foundDecoy)
|
||||
{
|
||||
|
||||
|
||||
this.theEntity.world.GetEntitiesInBounds(targetClass.type, BoundsUtils.ExpandBounds(this.theEntity.boundingBox, num, 4f, num), EAISetNearestEntityAsTargetZombieRebirth.list);
|
||||
EAISetNearestEntityAsTargetZombieRebirth.list.Sort(this.sorter);
|
||||
int j = 0;
|
||||
while (j < EAISetNearestEntityAsTargetZombieRebirth.list.Count)
|
||||
{
|
||||
EntityAlive entityAlive = (EntityAlive)EAISetNearestEntityAsTargetZombieRebirth.list[j];
|
||||
|
||||
bool isValid = true;
|
||||
|
||||
if (bMindControlled)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-FindTarget 11a");
|
||||
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-FindTarget entityAlive is entityAlive: " + entityAlive.EntityClass.entityClassName);
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-FindTarget entityAlive is EntityPlayer: " + (entityAlive is EntityPlayer));
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-FindTarget entityAlive is EntityAliveSDXExtended: " + (entityAlive is EntityAliveSDXExtended));
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-FindTarget entityAlive.HasAnyTags(FastTags<TagGroup.Global>.Parse(survivor)): " + (entityAlive.HasAnyTags(FastTags<TagGroup.Global>.Parse("survivor"))));
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-FindTarget entityAlive.HasAnyTags(FastTags<TagGroup.Global>.Parse(allyanimal)): " + (entityAlive.HasAnyTags(FastTags<TagGroup.Global>.Parse("allyanimal"))));
|
||||
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-FindTarget VERIFY: " + (entityAlive is EntityPlayer || (entityAlive is EntityAliveSDXExtended && (entityAlive.HasAnyTags(FastTags<TagGroup.Global>.Parse("survivor")) || entityAlive.HasAnyTags(FastTags<TagGroup.Global>.Parse("ally"))))));
|
||||
|
||||
if (entityAlive is EntityPlayer || entityAlive is EntitySurvivor ||
|
||||
(entityAlive is EntityNPCRebirth && (entityAlive.HasAnyTags(FastTags<TagGroup.Global>.Parse("survivor")) || entityAlive.HasAnyTags(FastTags<TagGroup.Global>.Parse("ally")))))
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-FindTarget entity: " + entityAlive.EntityClass.entityClassName);
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-FindTarget 11b");
|
||||
isValid = false;
|
||||
this.theEntity.attackTarget = (EntityAlive) null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!RebirthUtilities.VerifyFactionStanding(this.theEntity, entityAlive))
|
||||
{
|
||||
if (RebirthVariables.noHit && this.theEntity != entityAlive)
|
||||
{
|
||||
Log.Out($"EAISetNearestEntityAsTargetZombieRebirth-FindTarget NO HIT, should attack is false source: {this.theEntity}, target {entityAlive}");
|
||||
}
|
||||
isValid = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (RebirthVariables.noHit && this.theEntity != entityAlive)
|
||||
{
|
||||
Log.Out("EAISetNearestEntityAsTargetZombieRebirth-FindTarget target: " + entityAlive.EntityClass.entityClassName);
|
||||
Log.Out("EAISetNearestEntityAsTargetZombieRebirth-FindTarget isValid: " + isValid);
|
||||
Log.Out("EAISetNearestEntityAsTargetZombieRebirth-FindTarget base.check(entityAlive): " + base.check(entityAlive));
|
||||
Log.Out("EAISetNearestEntityAsTargetZombieRebirth-FindTarget should attack: " + RebirthUtilities.VerifyFactionStanding(this.theEntity, entityAlive));
|
||||
}
|
||||
|
||||
if (isValid && !(entityAlive is EntityDrone) && base.check(entityAlive))
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-FindTarget 11d");
|
||||
float distance = this.theEntity.GetDistance(entityAlive);
|
||||
if (distance < this.closeTargetDist)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-FindTarget 12");
|
||||
this.closeTargetDist = distance;
|
||||
this.closeTargetEntity = entityAlive;
|
||||
this.lastSeenPos = entityAlive.position;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-FindTarget 13: " + entityAlive.EntityClass.entityClassName);
|
||||
j++;
|
||||
}
|
||||
}
|
||||
EAISetNearestEntityAsTargetZombieRebirth.list.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SeekNoise(EntityPlayer player)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-SeekNoise START");
|
||||
float num = (player.position - this.theEntity.position).magnitude;
|
||||
if (this.playerTargetClassIndex >= 0)
|
||||
{
|
||||
float num2 = this.targetClasses[this.playerTargetClassIndex].hearDistMax;
|
||||
num2 *= this.theEntity.senseScale;
|
||||
num2 *= player.DetectUsScale(this.theEntity);
|
||||
if (num > num2)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
num *= 0.9f;
|
||||
if (num > this.manager.noiseSeekDist)
|
||||
{
|
||||
num = this.manager.noiseSeekDist;
|
||||
}
|
||||
if (this.theEntity.IsBloodMoon)
|
||||
{
|
||||
num = this.manager.noiseSeekDist * 0.25f;
|
||||
}
|
||||
|
||||
string rebirthFeralSense = RebirthVariables.customFeralSense;
|
||||
int currentDay = GameUtils.WorldTimeToDays(GameManager.Instance.World.worldTime);
|
||||
|
||||
bool randomValid = rebirthFeralSense == "random" &&
|
||||
currentDay == RebirthManager.nextFeralSenseDay;
|
||||
|
||||
if (randomValid && GameManager.Instance.World.IsDaytime() && RebirthManager.nextFeralSensePeriod == 1)
|
||||
{
|
||||
randomValid = false;
|
||||
}
|
||||
if (randomValid && !GameManager.Instance.World.IsDaytime() && RebirthManager.nextFeralSensePeriod == 2)
|
||||
{
|
||||
randomValid = false;
|
||||
}
|
||||
|
||||
bool isValidFeralSense = (rebirthFeralSense == "always") ||
|
||||
(GameManager.Instance.World.IsDaytime() && rebirthFeralSense == "dayonly") ||
|
||||
(!GameManager.Instance.World.IsDaytime() && rebirthFeralSense == "nightonly") ||
|
||||
randomValid;
|
||||
|
||||
string rebirthPOISense = RebirthVariables.customPOISense;
|
||||
bool POISense = (rebirthPOISense == "always") ||
|
||||
(GameManager.Instance.World.IsDaytime() && rebirthPOISense == "dayonly") ||
|
||||
(!GameManager.Instance.World.IsDaytime() && rebirthPOISense == "nightonly");
|
||||
|
||||
if (isValidFeralSense || (this.theEntity.IsSleeper && POISense))
|
||||
{
|
||||
num = 200;
|
||||
}
|
||||
|
||||
Vector3 breadcrumbPos = player.GetBreadcrumbPos(num * base.RandomFloat);
|
||||
int ticks = this.theEntity.CalcInvestigateTicks((int)(30f + base.RandomFloat * 30f) * 20, player);
|
||||
this.theEntity.SetInvestigatePosition(breadcrumbPos, ticks, true);
|
||||
float time = Time.time;
|
||||
if (this.senseSoundTime - time < 0f)
|
||||
{
|
||||
this.senseSoundTime = time + 10f + base.RandomFloat * 10f;
|
||||
this.theEntity.PlayOneShot(this.theEntity.soundSense, false);
|
||||
}
|
||||
}
|
||||
|
||||
private void FindTargetPlayer(float seeDist)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-FindTargetPlayer START");
|
||||
if (this.theEntity.IsSleeperPassive)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-FindTargetPlayer this.theEntity.IsSleeperPassive: " + this.theEntity.IsSleeperPassive);
|
||||
return;
|
||||
}
|
||||
|
||||
string rebirthFeralSense = RebirthVariables.customFeralSense;
|
||||
int currentDay = GameUtils.WorldTimeToDays(GameManager.Instance.World.worldTime);
|
||||
|
||||
bool randomValid = rebirthFeralSense == "random" &&
|
||||
currentDay == RebirthManager.nextFeralSenseDay;
|
||||
|
||||
if (randomValid && GameManager.Instance.World.IsDaytime() && RebirthManager.nextFeralSensePeriod == 1)
|
||||
{
|
||||
randomValid = false;
|
||||
}
|
||||
if (randomValid && !GameManager.Instance.World.IsDaytime() && RebirthManager.nextFeralSensePeriod == 2)
|
||||
{
|
||||
randomValid = false;
|
||||
}
|
||||
|
||||
bool isValidFeralSense = (rebirthFeralSense == "always") ||
|
||||
(GameManager.Instance.World.IsDaytime() && rebirthFeralSense == "dayonly") ||
|
||||
(!GameManager.Instance.World.IsDaytime() && rebirthFeralSense == "nightonly") ||
|
||||
randomValid;
|
||||
|
||||
string rebirthPOISense = RebirthVariables.customPOISense;
|
||||
bool POISense = (rebirthPOISense == "always") ||
|
||||
(GameManager.Instance.World.IsDaytime() && rebirthPOISense == "dayonly") ||
|
||||
(!GameManager.Instance.World.IsDaytime() && rebirthPOISense == "nightonly");
|
||||
|
||||
if (isValidFeralSense || this.theEntity.Buffs.GetCustomVar("$eventSpawn") == 1f || (this.theEntity.IsSleeper && POISense))
|
||||
{
|
||||
seeDist = 200;
|
||||
this.theEntity.SetMaxViewAngle(360);
|
||||
}
|
||||
|
||||
this.theEntity.world.GetEntitiesInBounds(typeof(EntityPlayer), BoundsUtils.ExpandBounds(this.theEntity.boundingBox, seeDist, seeDist, seeDist), EAISetNearestEntityAsTargetZombieRebirth.list);
|
||||
if (!this.theEntity.IsSleeping)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-FindTargetPlayer 1");
|
||||
for (int i = 0; i < EAISetNearestEntityAsTargetZombieRebirth.list.Count; i++)
|
||||
{
|
||||
Entity target = EAISetNearestEntityAsTargetZombieRebirth.list[i];
|
||||
|
||||
if (target is EntityPlayer)
|
||||
{
|
||||
EntityPlayer entityPlayer = (EntityPlayer)EAISetNearestEntityAsTargetZombieRebirth.list[i];
|
||||
if (entityPlayer.IsAlive() && !entityPlayer.IsIgnoredByAI() && !entityPlayer.IsSpectator)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-FindTargetPlayer 2");
|
||||
float distance = this.theEntity.GetDistance(entityPlayer);
|
||||
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-FindTargetPlayer distance: " + distance);
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-FindTargetPlayer this.theEntity.CanSee(entityPlayer): " + this.theEntity.CanSee(entityPlayer));
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-FindTargetPlayer this.theEntity.CanSeeStealth(distance, entityPlayer.Stealth.lightLevel): " + this.theEntity.CanSeeStealth(distance, entityPlayer.Stealth.lightLevel));
|
||||
|
||||
if (distance < this.closeTargetDist && this.theEntity.CanSee(entityPlayer) && this.theEntity.CanSeeStealth(distance, entityPlayer.Stealth.lightLevel))
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-FindTargetPlayer 3");
|
||||
this.closeTargetDist = distance;
|
||||
this.closeTargetEntity = entityPlayer;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
EAISetNearestEntityAsTargetZombieRebirth.list.Clear();
|
||||
return;
|
||||
}
|
||||
|
||||
EAISetNearestEntityAsTargetZombieRebirth.list.Sort(this.sorter);
|
||||
EntityPlayer x = null;
|
||||
float num = float.MaxValue;
|
||||
bool flag = false;
|
||||
if (this.theEntity.noisePlayer != null)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-FindTargetPlayer 5");
|
||||
if (this.theEntity.noisePlayerVolume >= this.theEntity.noiseWake)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-FindTargetPlayer 6");
|
||||
x = this.theEntity.noisePlayer;
|
||||
num = this.theEntity.noisePlayerDistance;
|
||||
}
|
||||
else if (this.theEntity.noisePlayerVolume >= this.theEntity.noiseGroan)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-FindTargetPlayer 7");
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
for (int j = 0; j < EAISetNearestEntityAsTargetZombieRebirth.list.Count; j++)
|
||||
{
|
||||
Entity target = EAISetNearestEntityAsTargetZombieRebirth.list[j];
|
||||
|
||||
if (target is EntityPlayer)
|
||||
{
|
||||
EntityPlayer entityPlayer2 = (EntityPlayer)EAISetNearestEntityAsTargetZombieRebirth.list[j];
|
||||
if (this.theEntity.CanSee(entityPlayer2) && !entityPlayer2.IsIgnoredByAI())
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-FindTargetPlayer 8");
|
||||
float distance2 = this.theEntity.GetDistance(entityPlayer2);
|
||||
int sleeperDisturbedLevel = this.theEntity.GetSleeperDisturbedLevel(distance2, entityPlayer2.Stealth.lightLevel);
|
||||
if (sleeperDisturbedLevel >= 2)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-FindTargetPlayer 9");
|
||||
if (distance2 < num)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-FindTargetPlayer 10");
|
||||
x = entityPlayer2;
|
||||
num = distance2;
|
||||
}
|
||||
}
|
||||
else if (sleeperDisturbedLevel >= 1)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-FindTargetPlayer 11");
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
EAISetNearestEntityAsTargetZombieRebirth.list.Clear();
|
||||
if (x != null)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-FindTargetPlayer 12");
|
||||
this.closeTargetDist = num;
|
||||
this.closeTargetEntity = x;
|
||||
return;
|
||||
}
|
||||
if (flag)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-FindTargetPlayer 13");
|
||||
this.theEntity.Groan();
|
||||
return;
|
||||
}
|
||||
this.theEntity.Snore();
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-FindTargetPlayer END");
|
||||
}
|
||||
|
||||
public override void Start()
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-Start START");
|
||||
this.theEntity.SetAttackTarget(this.targetEntity, 200);
|
||||
this.theEntity.ConditionalTriggerSleeperWakeUp();
|
||||
base.Start();
|
||||
}
|
||||
|
||||
public override bool Continue()
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-Continue START");
|
||||
if (this.targetEntity.IsDead() || this.theEntity.distraction != null)
|
||||
{
|
||||
if (this.theEntity.GetAttackTarget() == this.targetEntity)
|
||||
{
|
||||
this.theEntity.attackTarget = (EntityAlive) null;
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-Continue REMOVE ATTACK TARGET 1");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
this.findTime += 0.05f;
|
||||
if (this.findTime > 2f)
|
||||
{
|
||||
this.findTime = 0f;
|
||||
this.FindTarget();
|
||||
if (this.closeTargetEntity && this.closeTargetEntity != this.targetEntity)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (this.theEntity.GetAttackTarget() != this.targetEntity)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (base.check(targetEntity) && (this.targetPlayer == null || this.theEntity.CanSeeStealth(this.theEntity.GetDistance(this.targetEntity), this.targetPlayer.Stealth.lightLevel)))
|
||||
{
|
||||
this.theEntity.SetAttackTarget(this.targetEntity, 600);
|
||||
this.lastSeenPos = this.targetEntity.position;
|
||||
return true;
|
||||
}
|
||||
if (this.theEntity.GetDistanceSq(this.lastSeenPos) < 2.25f)
|
||||
{
|
||||
this.lastSeenPos = Vector3.zero;
|
||||
}
|
||||
this.theEntity.attackTarget = (EntityAlive) null;
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-Continue REMOVE ATTACK TARGET 2");
|
||||
int num = this.theEntity.CalcInvestigateTicks(Constants.cEnemySenseMemory * 20, this.targetEntity);
|
||||
if (this.lastSeenPos != Vector3.zero)
|
||||
{
|
||||
this.theEntity.SetInvestigatePosition(this.lastSeenPos, num, true);
|
||||
}
|
||||
if (this.targetPlayer)
|
||||
{
|
||||
if (this.theEntity.entityType == EntityType.Zombie)
|
||||
{
|
||||
num /= 6;
|
||||
}
|
||||
this.theEntity.SetAlertTicks(num);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetZombieRebirth-Reset START");
|
||||
this.targetEntity = null;
|
||||
this.targetPlayer = null;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Format("{0}, {1}", base.ToString(), this.targetEntity ? this.targetEntity.EntityName : "");
|
||||
}
|
||||
|
||||
private List<EAISetNearestEntityAsTargetZombieRebirth.TargetClass> targetClasses;
|
||||
private int playerTargetClassIndex = -1;
|
||||
private float closeTargetDist;
|
||||
private EntityAlive closeTargetEntity;
|
||||
private EntityAlive targetEntity;
|
||||
private EntityPlayer targetPlayer;
|
||||
private Vector3 lastSeenPos;
|
||||
private float findTime;
|
||||
private float senseSoundTime;
|
||||
private EAISetNearestEntityAsTargetSorter sorter;
|
||||
private static List<Entity> list = new List<Entity>();
|
||||
private bool foundDecoy = false;
|
||||
|
||||
private struct TargetClass
|
||||
{
|
||||
public Type type;
|
||||
public float hearDistMax;
|
||||
public float seeDistMax;
|
||||
}
|
||||
}
|
||||
134
Scripts/EAI/Inactive/EAIFollowPlayer.cs
Normal file
134
Scripts/EAI/Inactive/EAIFollowPlayer.cs
Normal file
@@ -0,0 +1,134 @@
|
||||
using GamePath;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.Remoting.Messaging;
|
||||
using UnityEngine;
|
||||
|
||||
public class EAIFollowPlayer : EAIApproachAndAttackTarget
|
||||
{
|
||||
private readonly List<Entity> NearbyEntities = new List<Entity>();
|
||||
private EntityAlive entityTarget;
|
||||
private Vector3 entityTargetPos;
|
||||
private Vector3 entityTargetVel;
|
||||
|
||||
public bool isTargetToEat;
|
||||
private bool isEating;
|
||||
private float homeTimeout;
|
||||
private bool hasHome;
|
||||
private bool isGoingHome;
|
||||
private int pathCounter;
|
||||
private float chaseTimeMax;
|
||||
private int relocateTicks;
|
||||
private int attackTimeout;
|
||||
|
||||
public override bool CanExecute()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void Start()
|
||||
{
|
||||
if (entityTarget != null)
|
||||
{
|
||||
this.entityTargetPos = this.entityTarget.position;
|
||||
this.isTargetToEat = this.entityTarget.IsDead();
|
||||
}
|
||||
this.entityTargetVel = Vector3.zero;
|
||||
this.isEating = false;
|
||||
this.theEntity.IsEating = false;
|
||||
this.homeTimeout = (this.theEntity.IsSleeper ? 90f : this.chaseTimeMax);
|
||||
this.hasHome = (this.homeTimeout > 0f);
|
||||
this.isGoingHome = false;
|
||||
if (this.theEntity.ChaseReturnLocation == Vector3.zero)
|
||||
{
|
||||
this.theEntity.ChaseReturnLocation = (this.theEntity.IsSleeper ? this.theEntity.SleeperSpawnPosition : this.theEntity.position);
|
||||
}
|
||||
this.pathCounter = 0;
|
||||
this.relocateTicks = 0;
|
||||
this.attackTimeout = 5;
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
//Log.Out("EAIFollowPlayer-Update START");
|
||||
// No entity, so no need to do anything.
|
||||
if (entityTarget == null)
|
||||
{
|
||||
Log.Out("EAIFollowPlayer-Update entityTarget == null");
|
||||
EntityPlayer closestPlayer = null;
|
||||
float num = 200 * 200;
|
||||
float num2 = float.MaxValue;
|
||||
for (int i = this.theEntity.world.Players.list.Count - 1; i >= 0; i--)
|
||||
{
|
||||
EntityPlayer entityPlayer = this.theEntity.world.Players.list[i];
|
||||
if (!entityPlayer.IsDead() && entityPlayer.Spawned)
|
||||
{
|
||||
//Log.Out("FOUND PLAYER: " + entityPlayer.EntityName);
|
||||
float distanceSq = entityPlayer.GetDistanceSq(this.theEntity.position);
|
||||
if (distanceSq < num2 && distanceSq <= num)
|
||||
{
|
||||
num2 = distanceSq;
|
||||
closestPlayer = entityPlayer;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (closestPlayer != null)
|
||||
{
|
||||
entityTarget = closestPlayer;
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
entityTargetPos = entityTarget.position;
|
||||
}
|
||||
|
||||
// Let the entity keep looking at you, otherwise it may just sping around.
|
||||
theEntity.SetLookPosition(entityTargetPos);
|
||||
theEntity.RotateTo(entityTargetPos.x, entityTargetPos.y + 2, entityTargetPos.z, 8f, 8f);
|
||||
|
||||
//Log.Out("EAIFollowPlayer-Update entityTargetPos: " + entityTargetPos);
|
||||
|
||||
var a = theEntity.position - entityTargetPos;
|
||||
if (a.sqrMagnitude < 20f)
|
||||
{
|
||||
//Log.Out("EAIFollowPlayer-Update Entity is too close. Ending pathing.");
|
||||
//DisplayLog("Entity is too close. Ending pathing.");
|
||||
pathCounter = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
theEntity.moveHelper.CalcIfUnreachablePos();
|
||||
|
||||
// if the entity is not calculating a path, check how many nodes are left, and reset the path counter if its too low.
|
||||
if (!PathFinderThread.Instance.IsCalculatingPath(theEntity.entityId))
|
||||
{
|
||||
var path = theEntity.navigator.getPath();
|
||||
if (path != null && path.NodeCountRemaining() <= 2)
|
||||
pathCounter = 0;
|
||||
}
|
||||
|
||||
if (--pathCounter <= 0 && !PathFinderThread.Instance.IsCalculatingPath(theEntity.entityId))
|
||||
{
|
||||
//DisplayLog(" Path Counter is 0: Finding new path to " + entityTargetPos);
|
||||
// If its still not calculating a path, find a new path to the leader
|
||||
pathCounter = 6 + theEntity.rand.RandomRange(10);
|
||||
PathFinderThread.Instance.FindPath(theEntity, entityTarget.position, theEntity.GetMoveSpeedAggro(), true, this);
|
||||
}
|
||||
|
||||
if (theEntity.Climbing)
|
||||
{
|
||||
//Log.Out("EAIFollowPlayer-Update Entity is climbing");
|
||||
return;
|
||||
}
|
||||
|
||||
// If there's no path, calculate one.
|
||||
if (theEntity.navigator.noPathAndNotPlanningOne())
|
||||
{
|
||||
//DisplayLog("No Path and Not Planning One. Searching for new path to : " + entityTargetPos);
|
||||
PathFinderThread.Instance.FindPath(theEntity, entityTarget.position, theEntity.GetMoveSpeedAggro(), true, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
110
Scripts/EAI/Inactive/EAILookCompanion.cs
Normal file
110
Scripts/EAI/Inactive/EAILookCompanion.cs
Normal file
@@ -0,0 +1,110 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Scripting;
|
||||
|
||||
[Preserve]
|
||||
public class EAILookCompanion : EAIBase
|
||||
{
|
||||
public EAILookCompanion()
|
||||
{
|
||||
this.MutexBits = 1;
|
||||
}
|
||||
|
||||
public override bool CanExecute()
|
||||
{
|
||||
if (this.theEntity.Buffs.GetCustomVar("onMission") == 1f)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//Log.Out("EAILookCompanion-CanExecute START");
|
||||
|
||||
if (this.theEntity.Buffs.GetCustomVar("$Leader") == 0f)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool stopAttacking = this.theEntity.Buffs.HasBuff("buffNPCModStopAttacking") ||
|
||||
this.theEntity.Buffs.HasBuff("FuriousRamsayStandStill");
|
||||
|
||||
if (stopAttacking)
|
||||
{
|
||||
//Log.Out("EAILookCompanion-CanExecute STOP ATTACKING OR STAND STILL");
|
||||
this.theEntity.SetRevengeTarget(null);
|
||||
this.theEntity.SetAttackTarget(null, 0);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.GetAttackTarget() != null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return this.manager.lookTime > 0f;
|
||||
}
|
||||
|
||||
public override void Start()
|
||||
{
|
||||
this.waitTicks = (int)(this.manager.lookTime * 20f);
|
||||
this.manager.lookTime = 0f;
|
||||
this.theEntity.GetEntitySenses().Clear();
|
||||
this.viewTicks = 0;
|
||||
this.theEntity.Jumping = false;
|
||||
this.theEntity.moveHelper.Stop();
|
||||
}
|
||||
|
||||
public override bool Continue()
|
||||
{
|
||||
if (this.theEntity.Buffs.GetCustomVar("onMission") == 1f)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool stopAttacking = this.theEntity.Buffs.HasBuff("buffNPCModStopAttacking") ||
|
||||
this.theEntity.Buffs.HasBuff("FuriousRamsayStandStill");
|
||||
|
||||
if (stopAttacking)
|
||||
{
|
||||
//Log.Out("EAILookCompanion-CanExecute STOP ATTACKING OR STAND STILL");
|
||||
this.theEntity.SetRevengeTarget(null);
|
||||
this.theEntity.SetAttackTarget(null, 0);
|
||||
|
||||
return false;
|
||||
}
|
||||
//Log.Out("EAILookCompanion-Continue START");
|
||||
|
||||
if (this.theEntity.bodyDamage.CurrentStun != EnumEntityStunType.None)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
this.waitTicks--;
|
||||
if (this.waitTicks <= 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
this.viewTicks--;
|
||||
if (this.viewTicks <= 0)
|
||||
{
|
||||
this.viewTicks = 40;
|
||||
Vector3 headPosition = this.theEntity.getHeadPosition();
|
||||
Vector3 vector = this.theEntity.GetForwardVector();
|
||||
vector = Quaternion.Euler(base.RandomFloat * 60f - 30f, base.RandomFloat * 120f - 60f, 0f) * vector;
|
||||
this.theEntity.SetLookPosition(headPosition + vector);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
this.theEntity.SetLookPosition(Vector3.zero);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Format("{0}, wait {1}", base.ToString(), ((float)this.waitTicks / 20f).ToCultureInvariantString());
|
||||
}
|
||||
|
||||
private int waitTicks;
|
||||
private int viewTicks;
|
||||
}
|
||||
1009
Scripts/EAI/NPCs/EAIApproachAndAttackTargetCompanion.cs
Normal file
1009
Scripts/EAI/NPCs/EAIApproachAndAttackTargetCompanion.cs
Normal file
@@ -0,0 +1,1009 @@
|
||||
using GamePath;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using UnityEngine.Scripting;
|
||||
|
||||
[Preserve]
|
||||
public class EAIApproachAndAttackTargetCompanion : EAIBase
|
||||
{
|
||||
public override void Init(EntityAlive _theEntity)
|
||||
{
|
||||
base.Init(_theEntity);
|
||||
this.MutexBits = 3;
|
||||
this.executeDelay = 0.1f;
|
||||
}
|
||||
|
||||
public override void SetData(DictionarySave<string, string> data)
|
||||
{
|
||||
base.SetData(data);
|
||||
this.targetClasses = new List<EAIApproachAndAttackTargetCompanion.TargetClass>();
|
||||
string text;
|
||||
if (data.TryGetValue("class", out text))
|
||||
{
|
||||
string[] array = text.Split(',', StringSplitOptions.None);
|
||||
for (int i = 0; i < array.Length; i += 2)
|
||||
{
|
||||
EAIApproachAndAttackTargetCompanion.TargetClass targetClass = default(EAIApproachAndAttackTargetCompanion.TargetClass);
|
||||
targetClass.type = EntityFactory.GetEntityType(array[i]);
|
||||
targetClass.chaseTimeMax = 0f;
|
||||
if (i + 1 < array.Length)
|
||||
{
|
||||
targetClass.chaseTimeMax = StringParsers.ParseFloat(array[i + 1], 0, -1, NumberStyles.Any);
|
||||
}
|
||||
this.targetClasses.Add(targetClass);
|
||||
if (targetClass.type == typeof(EntityEnemyAnimal))
|
||||
{
|
||||
targetClass.type = typeof(EntityAnimalSnake);
|
||||
this.targetClasses.Add(targetClass);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool NPCEAICanProceed(bool skipTargetVerification = false)
|
||||
{
|
||||
//Log.Out($"EAIApproachAndAttackTargetCompanion::NPCEAICanProceed - skipTargetVerification: {skipTargetVerification}");
|
||||
|
||||
bool result = true;
|
||||
|
||||
if (this.theEntity.Buffs.GetCustomVar("onMission") == 1f ||
|
||||
this.theEntity.Buffs.GetCustomVar("$FR_NPC_Respawn") == 1f ||
|
||||
this.theEntity.Buffs.GetCustomVar("$FR_NPC_Hidden") == 1f
|
||||
)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-NPCEAICanProceed 1");
|
||||
return false;
|
||||
}
|
||||
|
||||
EntityUtilities.CheckDistanceToLeader(this.theEntity, this.targetPlayer);
|
||||
|
||||
this.entityTarget = this.theEntity.GetAttackTarget();
|
||||
//Log.Out($"entityTarget: {entityTarget}");
|
||||
|
||||
if (this.entityTarget == null)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-NPCEAICanProceed 2b");
|
||||
if (this.theEntity.Buffs.GetCustomVar("$eventSpawn") == 1f)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-NPCEAICanProceed eventSpawn == 1f");
|
||||
EntityPlayer closestPlayer = this.theEntity.world.GetClosestPlayer(this.theEntity.position, 120f, false);
|
||||
if (closestPlayer != null)
|
||||
{
|
||||
this.entityTarget = closestPlayer;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-NPCEAICanProceed entityTarget == null checking skipTargetVerification");
|
||||
if (!skipTargetVerification)
|
||||
{
|
||||
//Log.Out($"EAIApproachAndAttackTargetCompanion-NPCEAICanProceed !skipTargetVerification: {skipTargetVerification}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.entityTarget != null)
|
||||
{
|
||||
if (this.entityTarget.IsDead())
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-NPCEAICanProceed 2c");
|
||||
this.theEntity.SetRevengeTarget((EntityAlive) null);
|
||||
this.theEntity.attackTarget = (EntityAlive) null;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!this.theEntity.CanSee(this.entityTarget) && this.theEntity.Buffs.GetCustomVar("$eventSpawn") == 0f)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-NPCEAICanProceed 2d");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool shouldAttack = RebirthUtilities.VerifyFactionStanding(this.theEntity, this.entityTarget);
|
||||
|
||||
if (!shouldAttack)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-NPCEAICanProceed 2e");
|
||||
//this.theEntity.attackTarget = (EntityAlive) null;
|
||||
//this.theEntity.SetRevengeTarget((EntityAlive) null);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.HasAnyTags(FastTags<TagGroup.Global>.Parse("allyanimal")) ||
|
||||
this.theEntity.HasAnyTags(FastTags<TagGroup.Global>.Parse("melee")))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-NPCEAICanProceed IS MELEE");
|
||||
if (this.entityTarget.EntityClass.Tags.Test_AnySet(FastTags<TagGroup.Global>.Parse("nomeleetracking")))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-NPCEAICanProceed NO ANIMAL TRACKING");
|
||||
if (this.theEntity.position.y < this.entityTarget.position.y - 4)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-NPCEAICanProceed TOO HIGH: " + this.entityTarget.EntityClass.entityClassName);
|
||||
this.theEntity.SetRevengeTarget((EntityAlive) null);
|
||||
this.theEntity.attackTarget = (EntityAlive) null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-NPCEAICanProceed 2f, this.entityTarget: " + this.entityTarget.EntityClass.entityClassName);
|
||||
}
|
||||
|
||||
if (this.theEntity.emodel.IsRagdollActive)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-NPCEAICanProceed 3");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.sleepingOrWakingUp || this.theEntity.bodyDamage.CurrentStun != EnumEntityStunType.None || (this.theEntity.Jumping && !this.theEntity.isSwimming))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-NPCEAICanProceed 4");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool stopAttacking = this.theEntity.Buffs.HasBuff("FuriousRamsayBuffPauseAttack") ||
|
||||
this.theEntity.Buffs.HasBuff("buffNPCModStopAttacking") ||
|
||||
this.theEntity.Buffs.HasBuff("buffNPCModStopAttacking") ||
|
||||
this.theEntity.Buffs.HasBuff("FuriousRamsayStandStill");
|
||||
|
||||
if (stopAttacking)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-NPCEAICanProceed 5");
|
||||
this.theEntity.SetRevengeTarget((EntityAlive) null);
|
||||
this.theEntity.attackTarget = (EntityAlive) null;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.sleepingOrWakingUp || this.theEntity.bodyDamage.CurrentStun != EnumEntityStunType.None)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-NPCEAICanProceed 6");
|
||||
return false;
|
||||
}
|
||||
|
||||
//Log.Out($"EAIApproachAndAttackTargetCompanion::NPCEAICanProceed - end result: {result}");
|
||||
return result;
|
||||
}
|
||||
|
||||
public override bool CanExecute()
|
||||
{
|
||||
CheckAnimator();
|
||||
backingUp = false;
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-CanExecute START");
|
||||
|
||||
if (!NPCEAICanProceed(true))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-CanExecute !NPCEAICanProceed(true) return false");
|
||||
return false;
|
||||
}
|
||||
|
||||
//Log.Out($"EAIApproachAndAttackTargetCompanion-CanExecute attackTarget: {theEntity.attackTarget}");
|
||||
|
||||
if (this.targetPlayer == null)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-CanExecute 2");
|
||||
this.OwnerID = (int)this.theEntity.Buffs.GetCustomVar("$Leader");
|
||||
|
||||
if (this.OwnerID > 0)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-CanExecute this.OwnerID: " + this.OwnerID);
|
||||
|
||||
EntityPlayer entityPlayer = (EntityPlayer)this.theEntity.world.GetEntity(this.OwnerID);
|
||||
if (entityPlayer != null)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-CanExecute FOUND OWNER");
|
||||
this.targetPlayer = entityPlayer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.entityTarget != null)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-CanExecute this.entityTarget: " + this.entityTarget.EntityClass.entityClassName);
|
||||
}
|
||||
else
|
||||
{
|
||||
checkEntityPosition();
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-CanExecute NO ATTACK TARGET");
|
||||
return false;
|
||||
}
|
||||
|
||||
Type type = this.entityTarget.GetType();
|
||||
for (int i = 0; i < this.targetClasses.Count; i++)
|
||||
{
|
||||
EAIApproachAndAttackTargetCompanion.TargetClass targetClass = this.targetClasses[i];
|
||||
if (targetClass.type != null && targetClass.type.IsAssignableFrom(type))
|
||||
{
|
||||
this.chaseTimeMax = targetClass.chaseTimeMax;
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-CanExecute 5");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-CanExecute 6");
|
||||
return false;
|
||||
}
|
||||
|
||||
public void checkEntityPosition()
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition START");
|
||||
|
||||
/*if (this.theEntity.Buffs.GetCustomVar("respawn") == 1)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition DIED");
|
||||
return;
|
||||
}*/
|
||||
|
||||
if (!this.theEntity.onGround) return;
|
||||
|
||||
if (this.entityTarget != null)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition HAS ATTACK TARGET");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.theEntity.navigator.noPathAndNotPlanningOne())
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition HAVE PATH");
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.theEntity.Buffs.GetCustomVar("CurrentOrder") != (int)EntityUtilities.Orders.Stay &&
|
||||
this.theEntity.Buffs.GetCustomVar("CurrentOrder") != (int)EntityUtilities.Orders.TempStay
|
||||
)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition NOT AT STAY");
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.theEntity.Buffs.HasBuff("buffTalkingTo"))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition IS TALKING");
|
||||
return;
|
||||
}
|
||||
|
||||
EntityAliveV2 npc = this.theEntity as EntityAliveV2;
|
||||
|
||||
if (npc == null)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition EXIT");
|
||||
return;
|
||||
}
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition STAY 1, npc.position: (" + npc.position + ") / npc.guardPosition: (" + npc.guardPosition + ")");
|
||||
|
||||
if (npc.guardPosition == Vector3.zero)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition NO GUARD POSITION");
|
||||
return;
|
||||
}
|
||||
|
||||
Vector3 entityPosition = EntityUtilities.CenterPosition(npc.position);
|
||||
Vector3 guardPosition = EntityUtilities.CenterPosition(npc.guardPosition);
|
||||
|
||||
if (entityPosition != guardPosition)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition STAY 2, npc.position: (" + npc.position + ") / npc.guardPosition: (" + npc.guardPosition + ")");
|
||||
npc.moveHelper.SetMoveTo(guardPosition, true);
|
||||
|
||||
npc.FindPath(
|
||||
npc.guardPosition,
|
||||
npc.GetMoveSpeedPanic(),
|
||||
false,
|
||||
null);
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition STOP");
|
||||
this.theEntity.moveHelper.Stop();
|
||||
this.theEntity.speedForward = 0;
|
||||
/*Vector3 entityRotation = EntityUtilities.CenterPosition(npc.rotation);
|
||||
Vector3 guardRotation = EntityUtilities.CenterPosition(npc.guardLookPosition);
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition STAY 3, npc.position: (" + npc.position + ") / npc.guardPosition: (" + npc.guardPosition + ")");
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition entityRotation: " + entityRotation);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition guardRotation: " + guardRotation);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition npc.rotation: " + npc.rotation);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition npc.guardLookPosition: " + npc.guardLookPosition);
|
||||
|
||||
if (entityRotation != guardRotation && npc.rotation != npc.guardLookPosition)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition STAY ROTATE");
|
||||
//npc.rotation = npc.guardLookPosition;
|
||||
|
||||
npc.SetLookPosition(npc.guardLookPosition);
|
||||
|
||||
npc.RotateTo(
|
||||
npc.guardLookPosition.x,
|
||||
npc.guardLookPosition.y,
|
||||
npc.guardLookPosition.z,
|
||||
360f,
|
||||
360f);
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition STAY IS IN RIGHT POSITION AND ROTATION");
|
||||
}*/
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition SetLookPosition");
|
||||
npc.SetLookPosition(npc.guardLookPosition);
|
||||
npc.RotateTo(
|
||||
npc.guardLookPosition.x,
|
||||
npc.guardLookPosition.y,
|
||||
npc.guardLookPosition.z,
|
||||
360f,
|
||||
360f);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Start()
|
||||
{
|
||||
//Log.Out($"EAIApproachAndAttackTargetCompanion::Start - this: {theEntity}, target: {theEntity.attackTarget}");
|
||||
this.entityTargetPos = this.entityTarget.position;
|
||||
this.entityTargetVel = Vector3.zero;
|
||||
this.isTargetToEat = false;
|
||||
this.isEating = false;
|
||||
this.theEntity.IsEating = false;
|
||||
this.homeTimeout = (this.theEntity.IsSleeper ? 90f : this.chaseTimeMax);
|
||||
this.hasHome = (this.homeTimeout > 0f);
|
||||
this.isGoingHome = false;
|
||||
if (this.theEntity.ChaseReturnLocation == Vector3.zero)
|
||||
{
|
||||
this.theEntity.ChaseReturnLocation = (this.theEntity.IsSleeper ? this.theEntity.SleeperSpawnPosition : this.theEntity.position);
|
||||
}
|
||||
this.pathCounter = 0;
|
||||
this.relocateTicks = 0;
|
||||
this.attackTimeout = 5;
|
||||
animator = this.theEntity.emodel.avatarController.GetAnimator();
|
||||
}
|
||||
|
||||
public override bool Continue()
|
||||
{
|
||||
CheckAnimator();
|
||||
backingUp = false;
|
||||
|
||||
if (!NPCEAICanProceed())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool result = false;
|
||||
|
||||
EntityAlive attackTarget = this.theEntity.GetAttackTarget();
|
||||
//Log.Out($"EAIApproachAndAttackTargetCompanion::Continue - this: {theEntity}, attackTarget: {attackTarget}");
|
||||
|
||||
if (attackTarget != null)
|
||||
{
|
||||
//Log.Out($"EAIApproachAndAttackTargetCompanion-Continue 1 this: {theEntity}, attackTarget: {attackTarget}, name: {attackTarget.EntityClass.entityClassName}");
|
||||
}
|
||||
else
|
||||
{
|
||||
checkEntityPosition();
|
||||
//Log.Out($"EAIApproachAndAttackTargetCompanion-Continue checkEntityPosition this: {theEntity}, attackTarget: {attackTarget}, name: {attackTarget.EntityClass.entityClassName}");
|
||||
}
|
||||
|
||||
if (this.isGoingHome)
|
||||
{
|
||||
result = !attackTarget && this.theEntity.ChaseReturnLocation != Vector3.zero;
|
||||
//Log.Out($"EAIApproachAndAttackTargetCompanion-Continue 3, Going home this: {theEntity}, result: {result}, theEntity.ChaseReturnLocation: {theEntity.ChaseReturnLocation}");
|
||||
return result;
|
||||
}
|
||||
|
||||
result = attackTarget && !(attackTarget != this.entityTarget);
|
||||
|
||||
//Log.Out($"EAIApproachAndAttackTargetCompanion::Continue End {result}, attackTarget: {attackTarget}");
|
||||
return result;
|
||||
}
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
this.theEntity.IsEating = false;
|
||||
//this.theEntity.moveHelper.Stop();
|
||||
if (this.blockTargetTask != null)
|
||||
{
|
||||
this.blockTargetTask.canExecute = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void CheckAnimator()
|
||||
{
|
||||
if (animator && !backingUp)
|
||||
{
|
||||
animator.SetBool("isBackingUp", false);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update START");
|
||||
CheckAnimator();
|
||||
backingUp = false;
|
||||
|
||||
if (!NPCEAICanProceed())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/*if (this.theEntity.Climbing)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 1");
|
||||
return;
|
||||
}*/
|
||||
|
||||
EntityAliveV2 npc = this.theEntity as EntityAliveV2;
|
||||
|
||||
if (npc == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.relocateTicks > 0)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 2");
|
||||
if (this.theEntity.navigator.noPathAndNotPlanningOne())
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 2a");
|
||||
this.relocateTicks = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 2b");
|
||||
--this.relocateTicks;
|
||||
this.theEntity.moveHelper.SetFocusPos(this.entityTarget.position);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
ItemValue holdingItemItemValue = this.theEntity.inventory.holdingItemItemValue;
|
||||
int holdingItemIdx = this.theEntity.inventory.holdingItemIdx;
|
||||
|
||||
bool isRanged = false;
|
||||
_actionIndex = 0;
|
||||
|
||||
if (this.theEntity.HasAnyTags(FastTags<TagGroup.Global>.Parse("ranged")))
|
||||
{
|
||||
_actionIndex = 1;
|
||||
isRanged = true;
|
||||
}
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 2 _actionIndex: " + _actionIndex);
|
||||
|
||||
ItemAction itemAction = this.theEntity.inventory.holdingItem.Actions[_actionIndex];
|
||||
|
||||
var distance = this.entityTarget.GetDistance(this.theEntity);
|
||||
|
||||
if (isRanged && ((this.theEntity.Buffs.GetCustomVar("CurrentOrder") > 0 && this.theEntity.Buffs.GetCustomVar("CurrentOrder") == (int)EntityUtilities.Orders.Follow) || this.theEntity.Buffs.GetCustomVar("$Leader") == 0))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update distance: " + distance);
|
||||
|
||||
float distanceFromTarget = 4f;
|
||||
|
||||
if (this.entityTarget is EntityPlayer)
|
||||
{
|
||||
distanceFromTarget = 5f;
|
||||
}
|
||||
|
||||
if (distance < distanceFromTarget)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 6");
|
||||
//if (!this.entityTarget.emodel.IsRagdollActive)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 6a");
|
||||
|
||||
int maxDistanceFromLeader = UnityEngine.Random.Range(10, 25);
|
||||
|
||||
backingUp = true;
|
||||
|
||||
Animator animator = this.theEntity.emodel.avatarController.GetAnimator();
|
||||
|
||||
if (animator)
|
||||
{
|
||||
animator.SetBool("isBackingUp", true);
|
||||
}
|
||||
|
||||
EntityUtilities.BackupHelper(this.theEntity, this.entityTarget, distanceFromTarget * 3f, maxDistanceFromLeader);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Animator animator = this.theEntity.emodel.avatarController.GetAnimator();
|
||||
|
||||
if (animator)
|
||||
{
|
||||
animator.SetBool("isBackingUp", false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Vector3 curEntTargPos = this.entityTarget.position;
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update B entityClassName: " + this.entityTarget.EntityClass.entityClassName);
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update SetLookPosition");
|
||||
theEntity.SetLookPosition(curEntTargPos);
|
||||
theEntity.RotateTo(curEntTargPos.x, curEntTargPos.y + 2, curEntTargPos.z, 8f, 8f);
|
||||
|
||||
Vector3 targetDirection = theEntity.position - curEntTargPos;
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update this.entityTarget.position: " + this.entityTarget.position);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update entityTargetPosn: " + curEntTargPos);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update targetDirection: " + targetDirection);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update targetDirection.sqrMagnitude: " + targetDirection.sqrMagnitude);
|
||||
|
||||
/*
|
||||
if (this.theEntity.GetAttackTarget() != null)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update GetAttackTarget: " + this.theEntity.GetAttackTarget().EntityClass.entityClassName);
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update NO ATTACK TARGET");
|
||||
}
|
||||
*/
|
||||
|
||||
bool isTargetWithinItemActionRange = false;
|
||||
|
||||
if (targetDirection.sqrMagnitude < 1f)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 7");
|
||||
this.entityTargetVel = this.entityTargetVel * 0.7f + targetDirection * 0.3f;
|
||||
}
|
||||
this.entityTargetPos = curEntTargPos;
|
||||
this.attackTimeout--;
|
||||
|
||||
this.theEntity.moveHelper.CalcIfUnreachablePos();
|
||||
float itemActionRange;
|
||||
float maxItemActionRange;
|
||||
|
||||
itemActionRange = 1.095f;
|
||||
if (itemAction != null)
|
||||
{
|
||||
itemActionRange = itemAction.Range;
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 8 itemAction.Range: " + itemAction.Range);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 8 isRanged: " + isRanged);
|
||||
if (isRanged)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update USE MaxRange Passive");
|
||||
itemActionRange = EffectManager.GetItemValue(PassiveEffects.MaxRange, holdingItemItemValue, 0f);
|
||||
}
|
||||
}
|
||||
maxItemActionRange = Utils.FastMax(0.7f, itemActionRange - 0.35f);
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 9a, itemActionRange: " + itemActionRange);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 9b, maxItemActionRange: " + maxItemActionRange);
|
||||
|
||||
float maxRangeSquared = maxItemActionRange * maxItemActionRange;
|
||||
float estimatedTimeInTicks = 4f;
|
||||
if (this.theEntity.IsFeral)
|
||||
{
|
||||
estimatedTimeInTicks = 8f;
|
||||
}
|
||||
estimatedTimeInTicks = base.RandomFloat * estimatedTimeInTicks;
|
||||
float targetXZDistanceSq = this.GetTargetXZDistanceSq(estimatedTimeInTicks);
|
||||
float yDiff = curEntTargPos.y - this.theEntity.position.y;
|
||||
float absoluteYDiff = Utils.FastAbs(yDiff);
|
||||
float entityDistance = Vector3.Distance(this.theEntity.position, curEntTargPos);
|
||||
isTargetWithinItemActionRange = entityDistance < maxItemActionRange && this.theEntity.CanSee(this.entityTarget);
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update entityDistance: " + entityDistance);
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update isTargetWithinItemActionRange: " + isTargetWithinItemActionRange);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update maxRangeSquared: " + maxRangeSquared);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update absoluteYDiff: " + absoluteYDiff);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update yDiff: " + yDiff);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update targetXZDistanceSq: " + targetXZDistanceSq);
|
||||
|
||||
if (!backingUp && ((this.theEntity.Buffs.GetCustomVar("CurrentOrder") == (int)EntityUtilities.Orders.Follow) || this.theEntity.Buffs.GetCustomVar("$Leader") == 0))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update !backingUp: " + !backingUp);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update CurrentOrder: " + this.theEntity.Buffs.GetCustomVar("CurrentOrder"));
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update $Leader: " + this.theEntity.Buffs.GetCustomVar("$Leader"));
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 10a");
|
||||
|
||||
if (!isTargetWithinItemActionRange)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 10c");
|
||||
if (absoluteYDiff < 3f && !PathFinderThread.Instance.IsCalculatingPath(this.theEntity.entityId))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 11");
|
||||
PathEntity path = this.theEntity.navigator.getPath();
|
||||
if (path != null && path.NodeCountRemaining() <= 2)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 12");
|
||||
this.pathCounter = 0;
|
||||
}
|
||||
}
|
||||
int pathCounterLessOne = this.pathCounter - 1;
|
||||
this.pathCounter = pathCounterLessOne;
|
||||
if (pathCounterLessOne <= 0 && this.theEntity.CanNavigatePath() && !PathFinderThread.Instance.IsCalculatingPath(this.theEntity.entityId))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 13");
|
||||
this.pathCounter = 6 + base.GetRandom(10);
|
||||
|
||||
Vector3 moveToLocation = GetMoveToLocation(maxItemActionRange);
|
||||
//Vector3 moveToLocation = EntityUtilities.GetMoveToLocation(this.theEntity, this.entityTarget.position, 0);
|
||||
|
||||
if (isRanged)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update BEFORE moveToLocation: " + moveToLocation);
|
||||
//moveToLocation = RandomPositionGenerator.CalcAway(this.theEntity, 2, 5, 5, this.entityTarget.position);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update AFTER moveToLocation: " + moveToLocation);
|
||||
}
|
||||
|
||||
if (moveToLocation.y - this.theEntity.position.y < -8f)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 14");
|
||||
this.pathCounter += 40;
|
||||
if (base.RandomFloat < 0.20000000298023224)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 15");
|
||||
this.seekPosOffset.x = this.seekPosOffset.x + (base.RandomFloat * 0.60000002384185791f - 0.30000001192092896f);
|
||||
this.seekPosOffset.y = this.seekPosOffset.y + (base.RandomFloat * 0.60000002384185791f - 0.30000001192092896f);
|
||||
}
|
||||
moveToLocation.x += this.seekPosOffset.x;
|
||||
moveToLocation.z += this.seekPosOffset.y;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 16");
|
||||
float num8 = (moveToLocation - this.theEntity.position).magnitude - 5f;
|
||||
if (num8 > 0f)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 17");
|
||||
if (num8 > 60f)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 18");
|
||||
num8 = 60f;
|
||||
}
|
||||
this.pathCounter += (int)(num8 / 20f * 20f);
|
||||
}
|
||||
}
|
||||
this.theEntity.FindPath(moveToLocation, this.theEntity.GetMoveSpeedAggro(), true, this);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.theEntity.Climbing)
|
||||
return;
|
||||
|
||||
if (!isTargetWithinItemActionRange)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 19");
|
||||
if (this.theEntity.navigator.noPathAndNotPlanningOne() && this.pathCounter > 0 && yDiff < 2.0999999046325684f)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 20");
|
||||
//Vector3 moveToLocation2 = EntityUtilities.GetMoveToLocation(this.theEntity, this.entityTarget.position, 0);
|
||||
Vector3 moveToLocation = GetMoveToLocation(maxItemActionRange);
|
||||
this.theEntity.moveHelper.SetMoveTo(moveToLocation, true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 21");
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update STOP");
|
||||
this.theEntity.moveHelper.Stop();
|
||||
this.pathCounter = 0;
|
||||
}
|
||||
|
||||
float newItemActionRange = itemActionRange - 0.1f;
|
||||
float newRangeSquared = newItemActionRange * newItemActionRange;
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update A itemActionRange: " + itemActionRange);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update A newItemActionRange: " + newItemActionRange);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update A newRangeSquared: " + newRangeSquared);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update A absoluteYDiff: " + absoluteYDiff);
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update A CanSee: " + this.theEntity.CanSee(this.entityTarget));
|
||||
|
||||
//if ((targetXZDistanceSq > newRangeSquared ? 0 : (absoluteYDiff < 1.25 ? 1 : 0)) == 0)
|
||||
if (!isTargetWithinItemActionRange)
|
||||
{
|
||||
// THIS IS WHERE IT SHOULD STOP TO START BREAKING BLOCKS
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 22");
|
||||
|
||||
//RebirthUtilities.CheckForOpenDoor(this.theEntity);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
this.theEntity.IsBreakingBlocks = false;
|
||||
this.theEntity.IsBreakingDoors = false;
|
||||
if (this.theEntity.bodyDamage.HasLimbs && !this.theEntity.Electrocuted)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 23");
|
||||
this.theEntity.RotateTo(curEntTargPos.x, curEntTargPos.y, curEntTargPos.z, 30f, 30f);
|
||||
}
|
||||
if (this.theEntity.GetDamagedTarget() == this.entityTarget || (this.entityTarget != null && this.entityTarget.GetDamagedTarget() == this.theEntity))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 24");
|
||||
this.homeTimeout = (this.theEntity.IsSleeper ? 90f : this.chaseTimeMax);
|
||||
if (this.blockTargetTask != null)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 25");
|
||||
this.blockTargetTask.canExecute = false;
|
||||
}
|
||||
this.theEntity.ClearDamagedTarget();
|
||||
if (this.entityTarget)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 26");
|
||||
this.entityTarget.ClearDamagedTarget();
|
||||
}
|
||||
if (this.attackTimeout > 0)
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.manager.groupCircle > 0f)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 27");
|
||||
Entity targetIfAttackedNow = this.theEntity.GetTargetIfAttackedNow();
|
||||
if (targetIfAttackedNow != this.entityTarget && (!this.entityTarget.AttachedToEntity || this.entityTarget.AttachedToEntity != targetIfAttackedNow))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 28");
|
||||
if (targetIfAttackedNow != null)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 29");
|
||||
this.relocateTicks = 46;
|
||||
Vector3 vector3 = (this.theEntity.position - curEntTargPos).normalized * (newItemActionRange + 1.1f);
|
||||
float num11 = base.RandomFloat * 28f + 18f;
|
||||
if (base.RandomFloat < 0.5f)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 30");
|
||||
num11 = -num11;
|
||||
}
|
||||
vector3 = Quaternion.Euler(0f, num11, 0f) * vector3;
|
||||
Vector3 targetPos = curEntTargPos + vector3;
|
||||
this.theEntity.FindPath(targetPos, this.theEntity.GetMoveSpeedAggro(), true, this);
|
||||
}
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update E entityClassName: " + this.entityTarget.EntityClass.entityClassName);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 31");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.entityTarget == null)
|
||||
{
|
||||
checkEntityPosition();
|
||||
}
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update _actionIndex: " + _actionIndex);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update isRanged: " + isRanged);
|
||||
|
||||
this.theEntity.SleeperSupressLivingSounds = false;
|
||||
|
||||
if (this.theEntity.Buffs.HasBuff("buffReloadDelay") ||
|
||||
this.theEntity.Buffs.HasBuff("buffReload2") ||
|
||||
this.theEntity.Buffs.HasBuff("buffReload3")
|
||||
)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 33");
|
||||
return;
|
||||
}
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 34");
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update backingUp: " + backingUp);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update distance: " + distance);
|
||||
|
||||
int rangeMax = 20;
|
||||
|
||||
PrefabInstance poiatPosition = RebirthUtilities.GetPrefabAtPosition(this.theEntity.position); // this.theEntity.world.GetPOIAtPosition(this.theEntity.position, false);
|
||||
|
||||
if (poiatPosition != null)
|
||||
{
|
||||
//Give NPCs a better chance at a ragdoll when inside a POI
|
||||
rangeMax = 10;
|
||||
}
|
||||
|
||||
if (this.entityTarget is EntityPlayer)
|
||||
{
|
||||
rangeMax = 100;
|
||||
}
|
||||
|
||||
int chance = UnityEngine.Random.Range(1, rangeMax);
|
||||
|
||||
if (chance < 10 && !this.entityTarget.emodel.IsRagdollActive && distance < this.theEntity.inventory.holdingItem.Actions[0].Range)
|
||||
{
|
||||
_actionIndex = 0;
|
||||
}
|
||||
|
||||
if (_actionIndex == 1)
|
||||
{
|
||||
if (!isTargetWithinItemActionRange && this.theEntity.moveHelper.IsActive)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update Target isn't within range");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (isTargetWithinItemActionRange)
|
||||
{
|
||||
if (this.theEntity.Buffs.HasBuff("buffRangedMeleeDelay"))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update HAS ATTACK DELAY BUFF");
|
||||
return;
|
||||
}
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 35a");
|
||||
if (npc.ExecuteAction(false, _actionIndex))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 35b");
|
||||
this.attackTimeout = this.theEntity.GetAttackTimeoutTicks();
|
||||
|
||||
if (isRanged && _actionIndex == 0)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update ADDED ATTACK DELAY BUFF");
|
||||
this.theEntity.Buffs.AddBuff("buffRangedMeleeDelay");
|
||||
}
|
||||
|
||||
// Check the range on the item action
|
||||
ItemActionRanged.ItemActionDataRanged itemActionData = null;
|
||||
|
||||
if (itemAction is ItemActionRanged itemActionRanged)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 36");
|
||||
itemActionData = this.theEntity.inventory.holdingItemData.actionData[_actionIndex] as ItemActionRanged.ItemActionDataRanged;
|
||||
if (itemActionData != null)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 37");
|
||||
// Check if we are already running.
|
||||
if (itemAction.IsActionRunning(itemActionData))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 38");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void AttackBlock()
|
||||
{
|
||||
this.theEntity.SetLookPosition(Vector3.zero);
|
||||
ItemActionAttackData itemActionAttackData = this.theEntity.inventory.holdingItemData.actionData[0] as ItemActionAttackData;
|
||||
if (itemActionAttackData == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (this.theEntity.Attack(false))
|
||||
{
|
||||
this.theEntity.IsBreakingBlocks = true;
|
||||
float num = 0.25f + base.RandomFloat * 0.8f;
|
||||
if (this.theEntity.moveHelper.IsUnreachableAbove)
|
||||
{
|
||||
num *= 0.5f;
|
||||
}
|
||||
//this.attackDelay = (int)((num + 0.75f) * 20f);
|
||||
itemActionAttackData.hitDelegate = new ItemActionAttackData.HitDelegate(this.GetHitInfo);
|
||||
this.theEntity.Attack(true);
|
||||
}
|
||||
}
|
||||
|
||||
private WorldRayHitInfo GetHitInfo(out float damageScale)
|
||||
{
|
||||
EntityMoveHelper moveHelper = this.theEntity.moveHelper;
|
||||
damageScale = moveHelper.DamageScale;
|
||||
return moveHelper.HitInfo;
|
||||
}
|
||||
|
||||
private float GetTargetXZDistanceSq(float estimatedTicks)
|
||||
{
|
||||
Vector3 vector = this.entityTarget.position;
|
||||
vector += this.entityTargetVel * estimatedTicks;
|
||||
Vector3 vector2 = this.theEntity.position + this.theEntity.motion * estimatedTicks - vector;
|
||||
vector2.y = 0f;
|
||||
return vector2.sqrMagnitude;
|
||||
}
|
||||
|
||||
private Vector3 GetMoveToLocation(float maxDist)
|
||||
{
|
||||
//Log.Out($"GetMoveToLocation maxDist: {maxDist}, entityTarget: {entityTarget}, == null: {(entityTarget == null)}");
|
||||
|
||||
Vector3 vector = this.entityTarget.position;
|
||||
vector += this.entityTargetVel * 6f;
|
||||
vector = this.entityTarget.world.FindSupportingBlockPos(vector);
|
||||
if (maxDist > 0f)
|
||||
{
|
||||
Vector3 vector2 = new Vector3(this.theEntity.position.x, vector.y, this.theEntity.position.z);
|
||||
Vector3 vector3 = vector - vector2;
|
||||
float magnitude = vector3.magnitude;
|
||||
if (magnitude < 3f)
|
||||
{
|
||||
if (magnitude <= maxDist)
|
||||
{
|
||||
float num = vector.y - this.theEntity.position.y;
|
||||
if (num < -3f || num > 1.5f)
|
||||
{
|
||||
return vector;
|
||||
}
|
||||
return vector2;
|
||||
}
|
||||
else
|
||||
{
|
||||
vector3 *= maxDist / magnitude;
|
||||
Vector3 vector4 = vector - vector3;
|
||||
vector4.y += 0.51f;
|
||||
Vector3i pos = World.worldToBlockPos(vector4);
|
||||
BlockValue block = this.entityTarget.world.GetBlock(pos);
|
||||
Block block2 = block.Block;
|
||||
if (block2.PathType <= 0)
|
||||
{
|
||||
RaycastHit raycastHit;
|
||||
if (Physics.Raycast(vector4 - Origin.position, Vector3.down, out raycastHit, 1.02f, 1082195968))
|
||||
{
|
||||
vector4.y = raycastHit.point.y + Origin.position.y;
|
||||
return vector4;
|
||||
}
|
||||
if (block2.IsElevator((int)block.rotation))
|
||||
{
|
||||
vector4.y = vector.y;
|
||||
return vector4;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return vector;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
ItemValue holdingItemItemValue = this.theEntity.inventory.holdingItemItemValue;
|
||||
int holdingItemIdx = this.theEntity.inventory.holdingItemIdx;
|
||||
ItemAction itemAction = holdingItemItemValue.ItemClass.Actions[holdingItemIdx];
|
||||
float num = 1.095f;
|
||||
if (itemAction != null)
|
||||
{
|
||||
num = itemAction.Range;
|
||||
if (num == 0f)
|
||||
{
|
||||
num = EffectManager.GetItemValue(PassiveEffects.MaxRange, holdingItemItemValue, 0f);
|
||||
}
|
||||
}
|
||||
float value = num - 0.1f;
|
||||
float targetXZDistanceSq = this.GetTargetXZDistanceSq(0f);
|
||||
return string.Format("{0}, {1}{2}{3}{4}{5} dist {6} rng {7} timeout {8}", new object[]
|
||||
{
|
||||
base.ToString(),
|
||||
this.entityTarget ? this.entityTarget.EntityName : "",
|
||||
this.theEntity.CanSee(this.entityTarget) ? "(see)" : "",
|
||||
this.theEntity.navigator.noPathAndNotPlanningOne() ? "(-path)" : (this.theEntity.navigator.noPath() ? "(!path)" : ""),
|
||||
this.isTargetToEat ? "(eat)" : "",
|
||||
this.isGoingHome ? "(home)" : "",
|
||||
Mathf.Sqrt(targetXZDistanceSq).ToCultureInvariantString("0.000"),
|
||||
value.ToCultureInvariantString("0.000"),
|
||||
this.homeTimeout.ToCultureInvariantString("0.00")
|
||||
});
|
||||
}
|
||||
|
||||
private int _actionIndex = 0;
|
||||
private const float cSleeperChaseTime = 90f;
|
||||
private List<EAIApproachAndAttackTargetCompanion.TargetClass> targetClasses;
|
||||
private float chaseTimeMax;
|
||||
private bool hasHome;
|
||||
private bool isGoingHome;
|
||||
private float homeTimeout;
|
||||
private EntityPlayer targetPlayer;
|
||||
private EntityAlive entityTarget;
|
||||
private Vector3 entityTargetPos;
|
||||
private Vector3 entityTargetVel;
|
||||
private int attackTimeout;
|
||||
private int pathCounter;
|
||||
private Vector2 seekPosOffset;
|
||||
private bool isTargetToEat;
|
||||
private bool isEating;
|
||||
private int eatCount;
|
||||
private EAIBlockingTargetTask blockTargetTask;
|
||||
private int relocateTicks;
|
||||
private int OwnerID = 0;
|
||||
private bool backingUp = false;
|
||||
private Animator animator = null;
|
||||
|
||||
private struct TargetClass
|
||||
{
|
||||
public Type type;
|
||||
public float chaseTimeMax;
|
||||
}
|
||||
}
|
||||
415
Scripts/EAI/NPCs/EAIFollowLeaderCompanion.cs
Normal file
415
Scripts/EAI/NPCs/EAIFollowLeaderCompanion.cs
Normal file
@@ -0,0 +1,415 @@
|
||||
using GamePath;
|
||||
using UnityEngine.Scripting;
|
||||
|
||||
[Preserve]
|
||||
public class EAIFollowLeaderCompanion : EAITarget
|
||||
{
|
||||
public override void Init(EntityAlive _theEntity)
|
||||
{
|
||||
base.Init(_theEntity, 25f, true);
|
||||
MutexBits = 1;
|
||||
}
|
||||
|
||||
public override void Start()
|
||||
{
|
||||
entityPlayerVel = Vector3.zero;
|
||||
relocateTicks = 0;
|
||||
pathCounter = 0;
|
||||
theEntity.ConditionalTriggerSleeperWakeUp();
|
||||
base.Start();
|
||||
}
|
||||
|
||||
public bool NPCEAICanProceed()
|
||||
{
|
||||
bool result = true;
|
||||
|
||||
OwnerID = (int)theEntity.Buffs.GetCustomVar("$Leader");
|
||||
|
||||
if (OwnerID == 0)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-NPCEAICanProceed 0");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (theEntity.Buffs.GetCustomVar("onMission") == 1f ||
|
||||
theEntity.Buffs.GetCustomVar("$FR_NPC_Respawn") == 1f ||
|
||||
theEntity.Buffs.GetCustomVar("$FR_NPC_Hidden") == 1f
|
||||
)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-NPCEAICanProceed 1");
|
||||
return false;
|
||||
}
|
||||
|
||||
EntityUtilities.CheckDistanceToLeader(theEntity, targetPlayer);
|
||||
|
||||
if (theEntity.emodel.IsRagdollActive)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-NPCEAICanProceed 3");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (theEntity.sleepingOrWakingUp || theEntity.bodyDamage.CurrentStun != EnumEntityStunType.None || (theEntity.Jumping && !theEntity.isSwimming))
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-NPCEAICanProceed theEntity.sleepingOrWakingUp: " + theEntity.sleepingOrWakingUp);
|
||||
//Log.Out("EAIFollowLeaderCompanion-NPCEAICanProceed theEntity.bodyDamage.CurrentStun: " + theEntity.bodyDamage.CurrentStun);
|
||||
//Log.Out("EAIFollowLeaderCompanion-NPCEAICanProceed theEntity.Jumping: " + theEntity.Jumping);
|
||||
//Log.Out("EAIFollowLeaderCompanion-NPCEAICanProceed theEntity.isSwimming: " + theEntity.isSwimming);
|
||||
//Log.Out("EAIFollowLeaderCompanion-NPCEAICanProceed 4");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (theEntity.Buffs.GetCustomVar("CurrentOrder") != (int)EntityUtilities.Orders.Follow)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-CanExecute IS NOT FOLLOWING");
|
||||
return false;
|
||||
}
|
||||
|
||||
/*bool stopAttacking = this.theEntity.Buffs.HasBuff("FuriousRamsayBuffPauseAttack") ||
|
||||
this.theEntity.Buffs.HasBuff("buffNPCModStopAttacking") ||
|
||||
this.theEntity.Buffs.HasBuff("FuriousRamsayStandStill");*/
|
||||
|
||||
bool stopAttacking = theEntity.Buffs.HasBuff("FuriousRamsayStandStill");
|
||||
|
||||
if (stopAttacking)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-NPCEAICanProceed 5");
|
||||
theEntity.SetRevengeTarget((EntityAlive) null);
|
||||
theEntity.attackTarget = (EntityAlive) null;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (theEntity.sleepingOrWakingUp || theEntity.bodyDamage.CurrentStun != EnumEntityStunType.None)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-NPCEAICanProceed 6");
|
||||
return false;
|
||||
}
|
||||
|
||||
//Log.Out($"EAIFollowLeaderCompanion::NPCEAICanProceed END {theEntity}, return: {result}, attackTarget: {theEntity.attackTarget}");
|
||||
return result;
|
||||
}
|
||||
|
||||
public override bool CanExecute()
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-CanExecute START");
|
||||
|
||||
if (!NPCEAICanProceed())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (targetPlayer == null)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-CanExecute 2");
|
||||
OwnerID = (int)theEntity.Buffs.GetCustomVar("$Leader");
|
||||
|
||||
if (OwnerID > 0)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-CanExecute this.OwnerID: " + this.OwnerID);
|
||||
|
||||
EntityPlayer entityPlayer = (EntityPlayer)theEntity.world.GetEntity(OwnerID);
|
||||
if (entityPlayer != null)
|
||||
{
|
||||
targetPlayer = entityPlayer;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//Log.Out($"EAIFollowLeaderCompanion::CanExecute END {theEntity}, return false, attackTarget: {theEntity.attackTarget}");
|
||||
//Log.Out("EAIFollowLeaderCompanion-CanExecute this.theEntity.GetAttackTarget: " + this.theEntity.GetAttackTarget().EntityClass.entityClassName);
|
||||
return false;
|
||||
}
|
||||
|
||||
public override bool Continue()
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Continue START");
|
||||
|
||||
if (!NPCEAICanProceed())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (pathCounter == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//Log.Out($"EAIFollowLeaderCompanion::Continue END {theEntity}, return true, attackTarget: {theEntity.attackTarget}");
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update START");
|
||||
|
||||
if (!NPCEAICanProceed())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (targetPlayer == null)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 2");
|
||||
OwnerID = (int)theEntity.Buffs.GetCustomVar("$Leader");
|
||||
|
||||
if (OwnerID > 0)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update this.OwnerID: " + this.OwnerID);
|
||||
|
||||
EntityPlayer entityPlayer = (EntityPlayer)theEntity.world.GetEntity(OwnerID);
|
||||
if (entityPlayer != null)
|
||||
{
|
||||
targetPlayer = entityPlayer;
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update FOUND OWNER");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (relocateTicks > 0)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 2");
|
||||
if (!theEntity.navigator.noPathAndNotPlanningOne())
|
||||
{
|
||||
//Log.Out($"EAIFollowLeaderCompanion-Update 3 {theEntity}, SetFocusPos: {targetPlayer.position}");
|
||||
relocateTicks--;
|
||||
theEntity.moveHelper.SetFocusPos(targetPlayer.position);
|
||||
return;
|
||||
}
|
||||
relocateTicks = 0;
|
||||
}
|
||||
|
||||
Vector3 vector2 = targetPlayer.position;
|
||||
|
||||
Vector3 a = theEntity.position - vector2;
|
||||
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update entityTargetPosn: " + vector2);
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update a: " + a);
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update a.sqrMagnitude: " + a.sqrMagnitude);
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update this.OwnerID: " + this.theEntity.Buffs.GetCustomVar("$Leader"));
|
||||
|
||||
OwnerID = (int)theEntity.Buffs.GetCustomVar("$Leader");
|
||||
|
||||
float magnitude = 30f;
|
||||
|
||||
bool isClient = SingletonMonoBehaviour<ConnectionManager>.Instance.IsClient;
|
||||
|
||||
if (isClient)
|
||||
{
|
||||
magnitude = 3f;
|
||||
}
|
||||
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update magnitude: " + magnitude);
|
||||
|
||||
if (targetPlayer.entityId == OwnerID && a.sqrMagnitude < magnitude)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update Entity is too close. Ending pathing.");
|
||||
theEntity.moveHelper.Stop();
|
||||
pathCounter = 0;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (targetPlayer.entityId == OwnerID)
|
||||
{
|
||||
/*if (!theEntity.HasAnyTags(FastTags<TagGroup.Global>.Parse("allyanimal")))
|
||||
{
|
||||
theEntity.Crouching = targetPlayer.Crouching;
|
||||
}*/
|
||||
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update theEntity.moveHelper.BlockedTime: " + theEntity.moveHelper.BlockedTime);
|
||||
|
||||
if (theEntity.moveHelper.BlockedTime > 3f)
|
||||
{
|
||||
EntityAliveV2 npc = theEntity as EntityAliveV2;
|
||||
|
||||
if (npc != null)
|
||||
{
|
||||
npc.TeleportToPlayer(targetPlayer, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update SetLookPosition");
|
||||
theEntity.SetLookPosition(vector2);
|
||||
theEntity.RotateTo(vector2.x, vector2.y + 2, vector2.z, 8f, 8f);
|
||||
|
||||
if (a.sqrMagnitude < 1f)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 6");
|
||||
this.entityPlayerVel = entityPlayerVel * 0.7f + a * 0.3f;
|
||||
}
|
||||
entityPlayerPos = vector2;
|
||||
|
||||
theEntity.moveHelper.CalcIfUnreachablePos();
|
||||
|
||||
//Log.Out($"Is unreachable: {theEntity.moveHelper.IsUnreachableSide}");
|
||||
|
||||
if (!theEntity.moveHelper.IsUnreachableSide)
|
||||
EntityUtilities.CheckForClosedDoor(theEntity);
|
||||
|
||||
float num2;
|
||||
float num3;
|
||||
|
||||
num2 = 1.095f;
|
||||
num3 = Utils.FastMax(0.7f, num2 - 0.35f);
|
||||
|
||||
float num4 = num3 * num3;
|
||||
float num5 = 4f;
|
||||
if (theEntity.IsFeral)
|
||||
{
|
||||
num5 = 8f;
|
||||
}
|
||||
num5 = base.RandomFloat * num5;
|
||||
float targetXZDistanceSq = GetTargetXZDistanceSq(num5);
|
||||
float num6 = vector2.y - theEntity.position.y;
|
||||
float num7 = Utils.FastAbs(num6);
|
||||
bool flag = targetXZDistanceSq <= num4 && num7 < 1f;
|
||||
if (!flag)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 9");
|
||||
if (num7 < 3f && !PathFinderThread.Instance.IsCalculatingPath(theEntity.entityId))
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 10");
|
||||
PathEntity path = theEntity.navigator.getPath();
|
||||
if (path != null && path.NodeCountRemaining() <= 2)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 11");
|
||||
pathCounter = 0;
|
||||
}
|
||||
}
|
||||
int num = pathCounter - 1;
|
||||
pathCounter = num;
|
||||
if (num <= 0 && this.theEntity.CanNavigatePath() && !PathFinderThread.Instance.IsCalculatingPath(theEntity.entityId))
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 12");
|
||||
pathCounter = 6 + base.GetRandom(10);
|
||||
Vector3 moveToLocation = EntityUtilities.GetMoveToLocation(this.theEntity, targetPlayer.position, 5);
|
||||
if (moveToLocation.y - theEntity.position.y < -8f)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 13");
|
||||
pathCounter += 40;
|
||||
if (base.RandomFloat < 0.2f)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 14");
|
||||
seekPosOffset.x = this.seekPosOffset.x + (base.RandomFloat * 0.6f - 0.3f);
|
||||
seekPosOffset.y = this.seekPosOffset.y + (base.RandomFloat * 0.6f - 0.3f);
|
||||
}
|
||||
moveToLocation.x += seekPosOffset.x;
|
||||
moveToLocation.z += seekPosOffset.y;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 15");
|
||||
float num8 = (moveToLocation - theEntity.position).magnitude - 5f;
|
||||
if (num8 > 0f)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 16");
|
||||
if (num8 > 60f)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 17");
|
||||
num8 = 60f;
|
||||
}
|
||||
pathCounter += (int)(num8 / 20f * 20f);
|
||||
}
|
||||
}
|
||||
//Log.Out($"EAIFollowLeaderCompanion-Update FindPath moveToLocation: {moveToLocation}");
|
||||
theEntity.FindPath(moveToLocation, this.theEntity.GetMoveSpeedAggro(), true, this);
|
||||
}
|
||||
}
|
||||
if (theEntity.Climbing)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 18");
|
||||
return;
|
||||
}
|
||||
if (!flag)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 20");
|
||||
if (this.theEntity.navigator.noPathAndNotPlanningOne() && pathCounter > 0 && num6 < 2.1f)
|
||||
{
|
||||
Vector3 moveToLocation2 = EntityUtilities.GetMoveToLocation(theEntity, this.targetPlayer.position);
|
||||
//Log.Out($"EAIFollowLeaderCompanion-Update SetMoveTo moveToLocation2: {moveToLocation2}");
|
||||
theEntity.moveHelper.SetMoveTo(moveToLocation2, true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 22 moveHelper.Stop");
|
||||
theEntity.moveHelper.Stop();
|
||||
pathCounter = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private float GetTargetXZDistanceSq(float estimatedTicks)
|
||||
{
|
||||
Vector3 vector = targetPlayer.position;
|
||||
vector += entityPlayerVel * estimatedTicks;
|
||||
Vector3 vector2 = this.theEntity.position + theEntity.motion * estimatedTicks - vector;
|
||||
vector2.y = 0f;
|
||||
return vector2.sqrMagnitude;
|
||||
}
|
||||
|
||||
private Vector3 GetMoveToLocation(float maxDist)
|
||||
{
|
||||
Vector3 vector = targetPlayer.position;
|
||||
vector += entityPlayerVel * 6f;
|
||||
vector = targetPlayer.world.FindSupportingBlockPos(vector);
|
||||
if (maxDist > 0f)
|
||||
{
|
||||
Vector3 vector2 = new Vector3(theEntity.position.x, vector.y, this.theEntity.position.z);
|
||||
Vector3 vector3 = vector - vector2;
|
||||
float magnitude = vector3.magnitude;
|
||||
if (magnitude < 3f)
|
||||
{
|
||||
if (magnitude <= maxDist)
|
||||
{
|
||||
float num = vector.y - theEntity.position.y;
|
||||
if (num < -3f || num > 1.5f)
|
||||
{
|
||||
return vector;
|
||||
}
|
||||
return vector2;
|
||||
}
|
||||
else
|
||||
{
|
||||
vector3 *= maxDist / magnitude;
|
||||
Vector3 vector4 = vector - vector3;
|
||||
vector4.y += 0.51f;
|
||||
Vector3i pos = World.worldToBlockPos(vector4);
|
||||
BlockValue block = targetPlayer.world.GetBlock(pos);
|
||||
Block block2 = block.Block;
|
||||
if (block2.PathType <= 0)
|
||||
{
|
||||
RaycastHit raycastHit;
|
||||
if (Physics.Raycast(vector4 - Origin.position, Vector3.down, out raycastHit, 1.02f, 1082195968))
|
||||
{
|
||||
vector4.y = raycastHit.point.y + Origin.position.y;
|
||||
return vector4;
|
||||
}
|
||||
if (block2.IsElevator((int)block.rotation))
|
||||
{
|
||||
vector4.y = vector.y;
|
||||
return vector4;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return vector;
|
||||
}
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
targetPlayer = null;
|
||||
}
|
||||
|
||||
private EntityPlayer targetPlayer;
|
||||
private Vector3 entityPlayerVel;
|
||||
private Vector3 entityPlayerPos;
|
||||
private int relocateTicks;
|
||||
private int OwnerID = 0;
|
||||
private int pathCounter;
|
||||
private Vector2 seekPosOffset;
|
||||
}
|
||||
327
Scripts/EAI/NPCs/EAIMoveToTargetCompanion.cs
Normal file
327
Scripts/EAI/NPCs/EAIMoveToTargetCompanion.cs
Normal file
@@ -0,0 +1,327 @@
|
||||
using GamePath;
|
||||
using UnityEngine.Scripting;
|
||||
|
||||
[Preserve]
|
||||
public class EAIMoveToTargetCompanion : EAITarget
|
||||
{
|
||||
public override void Init(EntityAlive _theEntity)
|
||||
{
|
||||
base.Init(_theEntity, 25f, true);
|
||||
this.MutexBits = 1;
|
||||
}
|
||||
|
||||
public override void Start()
|
||||
{
|
||||
this.relocateTicks = 0;
|
||||
this.pathCounter = 0;
|
||||
base.Start();
|
||||
}
|
||||
|
||||
public bool NPCEAICanProceed()
|
||||
{
|
||||
bool result = true;
|
||||
|
||||
this.OwnerID = (int)this.theEntity.Buffs.GetCustomVar("$Leader");
|
||||
|
||||
if (this.OwnerID == 0)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-NPCEAICanProceed 0");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.Buffs.GetCustomVar("onMission") == 1f ||
|
||||
this.theEntity.Buffs.GetCustomVar("$FR_NPC_Respawn") == 1f ||
|
||||
this.theEntity.Buffs.GetCustomVar("$FR_NPC_Hidden") == 1f
|
||||
)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-NPCEAICanProceed 1");
|
||||
return false;
|
||||
}
|
||||
|
||||
EntityUtilities.CheckDistanceToLeader(this.theEntity, this.targetPlayer);
|
||||
|
||||
this.entityTarget = this.theEntity.GetAttackTarget();
|
||||
|
||||
if (this.entityTarget == null)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-NPCEAICanProceed this.entityTarget == null");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.targetPlayer != null && !this.targetPlayer.CanEntityBeSeen(this.entityTarget) && !this.theEntity.CanEntityBeSeen(this.entityTarget))
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-NPCEAICanProceed 2b");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.CanEntityBeSeen(this.entityTarget))
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-NPCEAICanProceed 2c");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.emodel.IsRagdollActive)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-NPCEAICanProceed 3");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.sleepingOrWakingUp || this.theEntity.bodyDamage.CurrentStun != EnumEntityStunType.None || (this.theEntity.Jumping && !this.theEntity.isSwimming))
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-NPCEAICanProceed 4");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.Buffs.GetCustomVar("CurrentOrder") != (int)EntityUtilities.Orders.Follow &&
|
||||
this.theEntity.Buffs.GetCustomVar("CurrentOrder") != (int)EntityUtilities.Orders.Guard)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-CanExecute IS NOT FOLLOWING");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool stopAttacking = this.theEntity.Buffs.HasBuff("FuriousRamsayBuffPauseAttack") ||
|
||||
this.theEntity.Buffs.HasBuff("buffNPCModStopAttacking") ||
|
||||
this.theEntity.Buffs.HasBuff("FuriousRamsayStandStill");
|
||||
|
||||
if (stopAttacking)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-NPCEAICanProceed stopAttacking");
|
||||
this.theEntity.SetRevengeTarget((EntityAlive) null);
|
||||
this.theEntity.attackTarget = (EntityAlive) null;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.sleepingOrWakingUp || this.theEntity.bodyDamage.CurrentStun != EnumEntityStunType.None)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-NPCEAICanProceed 6");
|
||||
return false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public override bool CanExecute()
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-CanExecute START");
|
||||
|
||||
if (!NPCEAICanProceed())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.targetPlayer == null)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-CanExecute 2");
|
||||
this.OwnerID = (int)this.theEntity.Buffs.GetCustomVar("$Leader");
|
||||
|
||||
if (this.OwnerID > 0)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-CanExecute this.OwnerID: " + this.OwnerID);
|
||||
|
||||
EntityPlayer entityPlayer = (EntityPlayer)this.theEntity.world.GetEntity(this.OwnerID);
|
||||
if (entityPlayer != null)
|
||||
{
|
||||
this.targetPlayer = entityPlayer;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//Log.Out("EAIMoveToTargetCompanion-CanExecute this.theEntity.GetAttackTarget: " + this.theEntity.GetAttackTarget().EntityClass.entityClassName);
|
||||
return false;
|
||||
}
|
||||
|
||||
public override bool Continue()
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Continue START");
|
||||
if (!NPCEAICanProceed())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (pathCounter == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update START");
|
||||
|
||||
if (!NPCEAICanProceed())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.targetPlayer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/*if (this.OwnerID == 0)
|
||||
{
|
||||
theEntity.moveHelper.CalcIfUnreachablePos();
|
||||
|
||||
//Log.Out($"Is unreachable: {theEntity.moveHelper.IsUnreachableSide}");
|
||||
|
||||
if (!theEntity.moveHelper.IsUnreachableSide)
|
||||
EntityUtilities.CheckForClosedDoor(theEntity);
|
||||
}*/
|
||||
|
||||
if (this.relocateTicks > 0)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update 2");
|
||||
if (!this.theEntity.navigator.noPathAndNotPlanningOne())
|
||||
{
|
||||
//Log.Out($"EAIMoveToTargetCompanion-Update moving to entityTarget.position: {entityTarget.position}");
|
||||
this.relocateTicks--;
|
||||
this.theEntity.moveHelper.SetFocusPos(this.entityTarget.position);
|
||||
return;
|
||||
}
|
||||
this.relocateTicks = 0;
|
||||
}
|
||||
|
||||
Vector3 vector2 = this.entityTarget.position;
|
||||
|
||||
Vector3 a = theEntity.position - vector2;
|
||||
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update entityTargetPosition: " + vector2);
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update a: " + a);
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update a.sqrMagnitude: " + a.sqrMagnitude);
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update this.OwnerID: " + this.theEntity.Buffs.GetCustomVar("$Leader"));
|
||||
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update SetLookPosition");
|
||||
theEntity.SetLookPosition(vector2);
|
||||
theEntity.RotateTo(vector2.x, vector2.y + 2, vector2.z, 8f, 8f);
|
||||
|
||||
if (a.sqrMagnitude < 1f)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update 6");
|
||||
this.entityPlayerVel = this.entityPlayerVel * 0.7f + a * 0.3f;
|
||||
}
|
||||
this.entityPlayerPos = vector2;
|
||||
|
||||
this.theEntity.moveHelper.CalcIfUnreachablePos();
|
||||
float num2;
|
||||
float num3;
|
||||
|
||||
num2 = 1.095f;
|
||||
num3 = Utils.FastMax(0.7f, num2 - 0.35f);
|
||||
|
||||
float num4 = num3 * num3;
|
||||
float num5 = 4f;
|
||||
if (this.theEntity.IsFeral)
|
||||
{
|
||||
num5 = 8f;
|
||||
}
|
||||
num5 = base.RandomFloat * num5;
|
||||
float targetXZDistanceSq = this.GetTargetXZDistanceSq(num5);
|
||||
float num6 = vector2.y - this.theEntity.position.y;
|
||||
float num7 = Utils.FastAbs(num6);
|
||||
bool flag = targetXZDistanceSq <= num4 && num7 < 1f;
|
||||
if (!flag)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update 9");
|
||||
if (num7 < 3f && !PathFinderThread.Instance.IsCalculatingPath(this.theEntity.entityId))
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update 10");
|
||||
PathEntity path = this.theEntity.navigator.getPath();
|
||||
if (path != null && path.NodeCountRemaining() <= 2)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update 11");
|
||||
this.pathCounter = 0;
|
||||
}
|
||||
}
|
||||
int num = this.pathCounter - 1;
|
||||
this.pathCounter = num;
|
||||
if (num <= 0 && this.theEntity.CanNavigatePath() && !PathFinderThread.Instance.IsCalculatingPath(this.theEntity.entityId))
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update 12");
|
||||
this.pathCounter = 6 + base.GetRandom(10);
|
||||
Vector3 moveToLocation = EntityUtilities.GetMoveToLocation(this.theEntity, this.entityTarget.position, 5);
|
||||
if (moveToLocation.y - this.theEntity.position.y < -8f)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update 13");
|
||||
this.pathCounter += 40;
|
||||
if (base.RandomFloat < 0.2f)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update 14");
|
||||
this.seekPosOffset.x = this.seekPosOffset.x + (base.RandomFloat * 0.6f - 0.3f);
|
||||
this.seekPosOffset.y = this.seekPosOffset.y + (base.RandomFloat * 0.6f - 0.3f);
|
||||
}
|
||||
moveToLocation.x += this.seekPosOffset.x;
|
||||
moveToLocation.z += this.seekPosOffset.y;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update 15");
|
||||
float num8 = (moveToLocation - this.theEntity.position).magnitude - 5f;
|
||||
if (num8 > 0f)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update 16");
|
||||
if (num8 > 60f)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update 17");
|
||||
num8 = 60f;
|
||||
}
|
||||
this.pathCounter += (int)(num8 / 20f * 20f);
|
||||
}
|
||||
}
|
||||
//Log.Out($"MoveToTargetCompanion FindPath moveToLocation: {moveToLocation}");
|
||||
this.theEntity.FindPath(moveToLocation, this.theEntity.GetMoveSpeedAggro(), true, this);
|
||||
}
|
||||
}
|
||||
if (this.theEntity.Climbing)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update 18");
|
||||
return;
|
||||
}
|
||||
if (!flag)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update 20");
|
||||
if (this.theEntity.navigator.noPathAndNotPlanningOne() && this.pathCounter > 0 && num6 < 2.1f)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update 21");
|
||||
Vector3 moveToLocation2 = EntityUtilities.GetMoveToLocation(this.theEntity, this.entityTarget.position, 5);
|
||||
//Log.Out($"MoveToTargetCompanion SetMoveTo moveToLocation2: {moveToLocation2}");
|
||||
this.theEntity.moveHelper.SetMoveTo(moveToLocation2, true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update 22");
|
||||
this.theEntity.moveHelper.Stop();
|
||||
this.pathCounter = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private float GetTargetXZDistanceSq(float estimatedTicks)
|
||||
{
|
||||
Vector3 vector = this.entityTarget.position;
|
||||
vector += this.entityPlayerVel * estimatedTicks;
|
||||
Vector3 vector2 = this.theEntity.position + this.theEntity.motion * estimatedTicks - vector;
|
||||
vector2.y = 0f;
|
||||
return vector2.sqrMagnitude;
|
||||
}
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
this.entityTarget = null;
|
||||
this.targetPlayer = null;
|
||||
}
|
||||
|
||||
private EntityPlayer targetPlayer;
|
||||
private EntityAlive entityTarget;
|
||||
private Vector3 entityPlayerVel;
|
||||
private Vector3 entityPlayerPos;
|
||||
private int relocateTicks;
|
||||
private int OwnerID = 0;
|
||||
private int pathCounter;
|
||||
private Vector2 seekPosOffset;
|
||||
}
|
||||
244
Scripts/EAI/NPCs/EAISetAsTargetIfHurtCompanion.cs
Normal file
244
Scripts/EAI/NPCs/EAISetAsTargetIfHurtCompanion.cs
Normal file
@@ -0,0 +1,244 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine.Scripting;
|
||||
|
||||
[Preserve]
|
||||
public class EAISetAsTargetIfHurtCompanion : EAITarget
|
||||
{
|
||||
public override void Init(EntityAlive _theEntity)
|
||||
{
|
||||
base.Init(_theEntity, 0f, false);
|
||||
this.MutexBits = 1;
|
||||
}
|
||||
|
||||
public override void SetData(DictionarySave<string, string> data)
|
||||
{
|
||||
base.SetData(data);
|
||||
this.targetClasses = new List<EAISetAsTargetIfHurtCompanion.TargetClass>();
|
||||
string text;
|
||||
if (data.TryGetValue("class", out text))
|
||||
{
|
||||
string[] array = text.Split(',', StringSplitOptions.None);
|
||||
for (int i = 0; i < array.Length; i++)
|
||||
{
|
||||
EAISetAsTargetIfHurtCompanion.TargetClass item = default(EAISetAsTargetIfHurtCompanion.TargetClass);
|
||||
item.type = EntityFactory.GetEntityType(array[i]);
|
||||
this.targetClasses.Add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool NPCEAICanProceed()
|
||||
{
|
||||
bool result = true;
|
||||
|
||||
if (this.theEntity.Buffs.GetCustomVar("onMission") == 1f ||
|
||||
this.theEntity.Buffs.GetCustomVar("$FR_NPC_Respawn") == 1f ||
|
||||
this.theEntity.Buffs.GetCustomVar("$FR_NPC_Hidden") == 1f
|
||||
)
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-NPCEAICanProceed 1");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool stopAttacking = this.theEntity.Buffs.HasBuff("FuriousRamsayBuffPauseAttack") ||
|
||||
this.theEntity.Buffs.HasBuff("buffNPCModStopAttacking") ||
|
||||
this.theEntity.Buffs.HasBuff("FuriousRamsayStandStill");
|
||||
|
||||
if (stopAttacking)
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-NPCEAICanProceed 2");
|
||||
this.theEntity.SetRevengeTarget((EntityAlive) null);
|
||||
this.theEntity.attackTarget = (EntityAlive) null;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//Log.Out($"EAISetAsTargetIfHurtCompanion::NPCEAICanProceed END {theEntity}, return: {result}, attackTarget: {theEntity.attackTarget}");
|
||||
return result;
|
||||
}
|
||||
|
||||
public override bool CanExecute()
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-CanExecute START");
|
||||
|
||||
if (!NPCEAICanProceed())
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-CanExecute !NPCEAICanProceed()");
|
||||
return false;
|
||||
}
|
||||
|
||||
EntityAlive revengeTarget = this.theEntity.GetRevengeTarget();
|
||||
EntityAlive attackTarget = this.theEntity.GetAttackTarget();
|
||||
|
||||
//Log.Out($"EAISetAsTargetIfHurtCompanion::CanExecute - attackTarget: {theEntity.attackTarget}, revengeTarget: {revengeTarget}");
|
||||
/*
|
||||
if (revengeTarget == null)
|
||||
{
|
||||
//Log.Out($"EAISetAsTargetIfHurtCompanion::CanExecute {theEntity}, revengeTarget: {revengeTarget}, attackTarget: {theEntity.attackTarget}");
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-CanExecute revengeTarget == null");
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-CanExecute revengeTarget: " + revengeTarget.EntityClass.entityClassName);
|
||||
}
|
||||
if (attackTarget == null)
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-CanExecute attackTarget == null");
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-CanExecute attackTarget: " + attackTarget.EntityClass.entityClassName);
|
||||
}
|
||||
*/
|
||||
bool bIsValidTarget = true;
|
||||
|
||||
if (revengeTarget)
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtRebirth-CanExecute revengeTarget.EntityName: " + revengeTarget.EntityName);
|
||||
//Log.Out("EAISetAsTargetIfHurtRebirth-CanExecute revengeTarget.entityType: " + revengeTarget.entityType);
|
||||
//Log.Out("EAISetAsTargetIfHurtRebirth-CanExecute this.theEntity.entityType: " + this.theEntity.entityType);
|
||||
|
||||
bIsValidTarget = RebirthUtilities.VerifyFactionStanding(this.theEntity, revengeTarget); //revengeTarget.entityType != this.theEntity.entityType;
|
||||
//Log.Out("EAISetAsTargetIfHurtRebirth-CanExecute bIsValidTarget: " + bIsValidTarget);
|
||||
}
|
||||
|
||||
if (revengeTarget && revengeTarget != attackTarget && bIsValidTarget)
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-CanExecute 1");
|
||||
if (this.targetClasses != null)
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-CanExecute 2");
|
||||
bool flag = false;
|
||||
Type type = revengeTarget.GetType();
|
||||
for (int i = 0; i < this.targetClasses.Count; i++)
|
||||
{
|
||||
EAISetAsTargetIfHurtCompanion.TargetClass targetClass = this.targetClasses[i];
|
||||
if (targetClass.type != null && targetClass.type.IsAssignableFrom(type))
|
||||
{
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!flag)
|
||||
{
|
||||
//Log.Out($"EAISetAsTargetIfHurtCompanion::CanExecute - attackTarget: {theEntity.attackTarget}, revengeTarget: {revengeTarget} !flag return false");
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-CanExecute 3");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (attackTarget != null && attackTarget.IsAlive() && base.RandomFloat < 0.66f)
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-CanExecute 4");
|
||||
//Log.Out($"EAISetAsTargetIfHurtCompanion::CanExecute - attackTarget: {theEntity.attackTarget}, revengeTarget: {revengeTarget} not null and is alive");
|
||||
this.theEntity.SetRevengeTarget((EntityAlive) null);
|
||||
return false;
|
||||
}
|
||||
if (base.check(revengeTarget))
|
||||
{
|
||||
//Log.Out($"EAISetAsTargetIfHurtCompanion::CanExecute - attackTarget: {theEntity.attackTarget}, revengeTarget: {revengeTarget} base.check return true");
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-CanExecute 5");
|
||||
return true;
|
||||
}
|
||||
Vector3 vector = this.theEntity.position - revengeTarget.position;
|
||||
float searchRadius = EntityClass.list[this.theEntity.entityClass].SearchRadius;
|
||||
vector = revengeTarget.position + vector.normalized * (searchRadius * 0.35f);
|
||||
Vector3 vector2 = this.manager.random.RandomOnUnitSphere * searchRadius;
|
||||
vector.x += vector2.x;
|
||||
vector.z += vector2.z;
|
||||
Vector3i vector3i = World.worldToBlockPos(vector);
|
||||
int height = (int)this.theEntity.world.GetHeight(vector3i.x, vector3i.z);
|
||||
if (height > 0)
|
||||
{
|
||||
vector.y = (float)height;
|
||||
}
|
||||
int num2 = this.theEntity.CalcInvestigateTicks(1200, revengeTarget);
|
||||
this.theEntity.SetInvestigatePosition(vector, num2, true);
|
||||
//Log.Out($"SetInvestigatePosition - vector: {vector}, attackTarget: {theEntity.attackTarget}, revengeTarget: {revengeTarget}");
|
||||
if (this.theEntity.entityType == EntityType.Zombie)
|
||||
{
|
||||
num2 /= 6;
|
||||
}
|
||||
this.theEntity.SetAlertTicks(num2);
|
||||
this.theEntity.SetRevengeTarget((EntityAlive) null);
|
||||
}
|
||||
//Log.Out($"EAISetAsTargetIfHurtCompanion::CanExecute END - attackTarget: {theEntity.attackTarget}, revengeTarget: {revengeTarget} return false");
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void Start()
|
||||
{
|
||||
this.theEntity.SetAttackTarget(this.theEntity.GetRevengeTarget(), 400);
|
||||
//Log.Out($"EAISetAsTargetIfHurtCompanion-Start attackTarget: {theEntity.attackTarget}");
|
||||
|
||||
this.viewAngleSave = this.theEntity.GetMaxViewAngle();
|
||||
this.theEntity.SetMaxViewAngle(270f);
|
||||
this.viewAngleRestoreCounter = 100;
|
||||
base.Start();
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-Update START");
|
||||
|
||||
if (!NPCEAICanProceed())
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-Update !NPCEAICanProceed return");
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.viewAngleRestoreCounter > 0)
|
||||
{
|
||||
this.viewAngleRestoreCounter--;
|
||||
if (this.viewAngleRestoreCounter == 0)
|
||||
{
|
||||
this.restoreViewAngle();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Continue()
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-Continue START");
|
||||
|
||||
if (!NPCEAICanProceed())
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-Continue !NPCEAICanProceed return false");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool revengeTargetIsNull = (this.theEntity.GetRevengeTarget() != null);
|
||||
bool revengeAndAttackTargetDifferent = (this.theEntity.GetAttackTarget() != this.theEntity.GetRevengeTarget());
|
||||
bool baseContinue = base.Continue();
|
||||
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-Continue revengeTargetIsNull: " + revengeTargetIsNull);
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-Continue revengeAndAttackTargetDifferent: " + revengeAndAttackTargetDifferent);
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-Continue baseContinue: " + baseContinue);
|
||||
|
||||
//Log.Out($"EAISetAsTargetIfHurtCompanion::Continue END {theEntity}, return: {(!revengeTargetIsNull || !revengeAndAttackTargetDifferent) && baseContinue}, attackTarget: {theEntity.attackTarget}");
|
||||
return (!revengeTargetIsNull || !revengeAndAttackTargetDifferent) && baseContinue;
|
||||
}
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
base.Reset();
|
||||
this.restoreViewAngle();
|
||||
}
|
||||
|
||||
private void restoreViewAngle()
|
||||
{
|
||||
if (this.viewAngleSave > 0f)
|
||||
{
|
||||
this.theEntity.SetMaxViewAngle(this.viewAngleSave);
|
||||
this.viewAngleSave = 0f;
|
||||
this.viewAngleRestoreCounter = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private List<EAISetAsTargetIfHurtCompanion.TargetClass> targetClasses;
|
||||
private float viewAngleSave;
|
||||
private int viewAngleRestoreCounter;
|
||||
private struct TargetClass
|
||||
{
|
||||
public Type type;
|
||||
}
|
||||
}
|
||||
379
Scripts/EAI/NPCs/EAISetNearestEntityAsTargetCompanion.cs
Normal file
379
Scripts/EAI/NPCs/EAISetNearestEntityAsTargetCompanion.cs
Normal file
@@ -0,0 +1,379 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using UnityEngine.Scripting;
|
||||
|
||||
[Preserve]
|
||||
public class EAISetNearestEntityAsTargetCompanion : EAITarget
|
||||
{
|
||||
public override void Init(EntityAlive _theEntity)
|
||||
{
|
||||
base.Init(_theEntity, 25f, true);
|
||||
this.MutexBits = 1;
|
||||
this.sorter = new EAISetNearestEntityAsTargetSorter(_theEntity);
|
||||
}
|
||||
|
||||
public override void SetData(DictionarySave<string, string> data)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-SetData START");
|
||||
base.SetData(data);
|
||||
this.targetClasses = new List<EAISetNearestEntityAsTargetCompanion.TargetClass>();
|
||||
string text;
|
||||
if (data.TryGetValue("class", out text))
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-SetData 1");
|
||||
string[] array = text.Split(',', StringSplitOptions.None);
|
||||
for (int i = 0; i < array.Length; i += 3)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-SetData i: " + i);
|
||||
EAISetNearestEntityAsTargetCompanion.TargetClass targetClass;
|
||||
targetClass.type = EntityFactory.GetEntityType(array[i]);
|
||||
targetClass.hearDistMax = 0f;
|
||||
if (i + 1 < array.Length)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-SetData 2");
|
||||
targetClass.hearDistMax = StringParsers.ParseFloat(array[i + 1], 0, -1, NumberStyles.Any);
|
||||
}
|
||||
if (targetClass.hearDistMax == 0f)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-SetData 3");
|
||||
targetClass.hearDistMax = 50f;
|
||||
}
|
||||
targetClass.seeDistMax = 0f;
|
||||
if (i + 2 < array.Length)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-SetData 4");
|
||||
targetClass.seeDistMax = StringParsers.ParseFloat(array[i + 2], 0, -1, NumberStyles.Any);
|
||||
}
|
||||
if (targetClass.type == typeof(EntityPlayer))
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-SetData 5");
|
||||
this.playerTargetClassIndex = this.targetClasses.Count;
|
||||
}
|
||||
this.targetClasses.Add(targetClass);
|
||||
}
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-SetData 6");
|
||||
}
|
||||
}
|
||||
|
||||
public bool NPCEAICanProceed()
|
||||
{
|
||||
bool result = true;
|
||||
|
||||
if (this.theEntity.Buffs.GetCustomVar("onMission") == 1f ||
|
||||
this.theEntity.Buffs.GetCustomVar("$FR_NPC_Respawn") == 1f ||
|
||||
this.theEntity.Buffs.GetCustomVar("$FR_NPC_Hidden") == 1f
|
||||
)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-NPCEAICanProceed 1");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool stopAttacking = this.theEntity.Buffs.HasBuff("FuriousRamsayBuffPauseAttack") ||
|
||||
this.theEntity.Buffs.HasBuff("buffNPCModStopAttacking") ||
|
||||
this.theEntity.Buffs.HasBuff("FuriousRamsayStandStill");
|
||||
|
||||
if (stopAttacking)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-NPCEAICanProceed 2");
|
||||
this.theEntity.SetRevengeTarget((EntityAlive) null);
|
||||
this.theEntity.attackTarget = (EntityAlive) null;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public override bool CanExecute()
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-CanExecute START");
|
||||
if (!NPCEAICanProceed())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.Buffs.GetCustomVar("$eventSpawn") == 1f)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-CanExecute EVENT SPAWN");
|
||||
if (this.theEntity.GetAttackTarget() != null)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-CanExecute ALREADY HAS A TARGET");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
this.FindTarget();
|
||||
|
||||
if (!this.closeTargetEntity)
|
||||
{
|
||||
//Log.Out($"! closeTargetEntity: {closeTargetEntity}");
|
||||
return false;
|
||||
}
|
||||
this.targetEntity = this.closeTargetEntity;
|
||||
this.targetPlayer = (this.closeTargetEntity as EntityPlayer);
|
||||
|
||||
//Log.Out($"EAISetNearestEntityAsTargetCompanion-CanExecute this.targetEntity: {this.targetEntity}, targetPlayer: {targetPlayer}");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void FindTarget()
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget START");
|
||||
this.closeTargetDist = float.MaxValue;
|
||||
this.closeTargetEntity = null;
|
||||
float seeDistance = RebirthVariables.customDistanceHunting; //this.theEntity.GetSeeDistance();
|
||||
|
||||
if (this.theEntity.Buffs.HasBuff("buffNPCModFullControlMode") && this.theEntity.Buffs.GetCustomVar("CurrentOrder") == (int)EntityUtilities.Orders.Follow)
|
||||
{
|
||||
seeDistance = RebirthVariables.customDistanceFullControl;
|
||||
}
|
||||
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget this.targetClasses.Count " + this.targetClasses.Count);
|
||||
for (int i = 0; i < this.targetClasses.Count; i++)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget i: " + i);
|
||||
EAISetNearestEntityAsTargetCompanion.TargetClass targetClass = this.targetClasses[i];
|
||||
float num = 100;
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget seeDistance " + seeDistance);
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget targetClass.seeDistMax " + targetClass.seeDistMax);
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget num " + num);
|
||||
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget this.theEntity.IsSleeping " + this.theEntity.IsSleeping);
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget this.theEntity.HasInvestigatePosition " + this.theEntity.HasInvestigatePosition);
|
||||
|
||||
bool hasInvestigatePosition = false; // this.theEntity.HasInvestigatePosition;
|
||||
|
||||
if (!this.theEntity.IsSleeping && !hasInvestigatePosition)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget 1");
|
||||
this.theEntity.world.GetEntitiesInBounds(targetClass.type, BoundsUtils.ExpandBounds(this.theEntity.boundingBox, num, num, num), EAISetNearestEntityAsTargetCompanion.list);
|
||||
EAISetNearestEntityAsTargetCompanion.list.Sort(this.sorter);
|
||||
int j = 0;
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget EAISetNearestEntityAsTargetCompanion.list.Count " + EAISetNearestEntityAsTargetCompanion.list.Count);
|
||||
while (j < EAISetNearestEntityAsTargetCompanion.list.Count)
|
||||
{
|
||||
EntityAlive entityAlive = (EntityAlive)EAISetNearestEntityAsTargetCompanion.list[j];
|
||||
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget j: " + j + " / entityAlive: " + entityAlive.EntityClass.entityClassName);
|
||||
|
||||
//if (!(entityAlive is EntityDrone))
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget 2");
|
||||
bool check = base.check(entityAlive);
|
||||
bool shouldAttack = RebirthUtilities.VerifyFactionStanding(this.theEntity, entityAlive);
|
||||
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget check: " + check);
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget shouldAttack: " + shouldAttack);
|
||||
|
||||
if (!check && entityAlive.entityId != this.theEntity.entityId && shouldAttack)
|
||||
{
|
||||
int OwnerID = (int)this.theEntity.Buffs.GetCustomVar("$Leader");
|
||||
|
||||
if (OwnerID > 0)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget HAS OWNER");
|
||||
EntityPlayer entityPlayer = (EntityPlayer)this.theEntity.world.GetEntity(OwnerID);
|
||||
if (entityPlayer != null)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget FOUND OWNER");
|
||||
if (entityPlayer.CanEntityBeSeen(entityAlive) && !(entityAlive is EntitySupplyCrate))
|
||||
{
|
||||
check = true;
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget OWNER CAN SEE TARGET: " + entityAlive.EntityClass.entityClassName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget check: " + check);
|
||||
|
||||
bool canAttack = true;
|
||||
|
||||
if (this.theEntity.Buffs.HasBuff("buffNPCModFullControlMode") && entityAlive.IsSleeping)
|
||||
{
|
||||
canAttack = false;
|
||||
}
|
||||
|
||||
if (check && (canAttack || entityAlive is EntityAnimalSnake))
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget entityAlive.EntityClass.entityClassName: " + entityAlive.EntityClass.entityClassName);
|
||||
float distance = this.theEntity.GetDistance(entityAlive);
|
||||
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget this.closeTargetDist: " + this.closeTargetDist);
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget distance: " + distance);
|
||||
|
||||
bool bypassDistance = (entityAlive.Buffs.GetCustomVar("$FuriousRamsayAttacking") == 1f ||
|
||||
entityAlive.Buffs.GetCustomVar("$FuriousRamsayAttacked") == 1f ||
|
||||
this.theEntity.Buffs.HasBuff("buffNPCModThreatControlMode")
|
||||
);
|
||||
|
||||
if (bypassDistance && distance > 50)
|
||||
{
|
||||
bypassDistance = false;
|
||||
}
|
||||
|
||||
if (this.theEntity.HasAnyTags(FastTags<TagGroup.Global>.Parse("allyanimal")) ||
|
||||
this.theEntity.HasAnyTags(FastTags<TagGroup.Global>.Parse("melee")))
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget IS MELEE");
|
||||
if (entityAlive.EntityClass.Tags.Test_AnySet(FastTags<TagGroup.Global>.Parse("nomeleetracking")))
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget NO ANIMAL TRACKING");
|
||||
if (this.theEntity.position.y < entityAlive.position.y - 4)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget TOO HIGH: " + entityAlive.EntityClass.entityClassName);
|
||||
j++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget bypassDistance: " + bypassDistance);
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget distance: " + distance);
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget seeDistance: " + seeDistance);
|
||||
|
||||
if (bypassDistance || distance < seeDistance)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget A");
|
||||
this.closeTargetDist = distance;
|
||||
this.closeTargetEntity = entityAlive;
|
||||
this.lastSeenPos = entityAlive.position;
|
||||
|
||||
//Log.Out($"EAI SetNearestEntityAsTargetCompanion - FindTarget entityAlive: {entityAlive.EntityClass.entityClassName}");
|
||||
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget B");
|
||||
int OwnerID = (int)this.theEntity.Buffs.GetCustomVar("$Leader");
|
||||
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget OwnerID: " + OwnerID);
|
||||
|
||||
EntityPlayer owner = null;
|
||||
|
||||
if (OwnerID > 0)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget HAS OWNER");
|
||||
EntityPlayer entityPlayer = (EntityPlayer)this.theEntity.world.GetEntity(OwnerID);
|
||||
if (entityPlayer != null)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget FOUND OWNER");
|
||||
owner = entityPlayer;
|
||||
}
|
||||
}
|
||||
|
||||
if (owner != null)
|
||||
{
|
||||
distance = owner.GetDistance(entityAlive);
|
||||
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget DISTANCE TO OWNER: " + distance);
|
||||
|
||||
if (distance < seeDistance + 5)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget OWNER distance: " + distance);
|
||||
//Log.Out($"EAISetNearestEntityAsTargetCompanion-FindTarget entityAlive: {entityAlive}");
|
||||
|
||||
this.closeTargetDist = distance;
|
||||
this.closeTargetEntity = entityAlive;
|
||||
this.lastSeenPos = entityAlive.position;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
j++;
|
||||
}
|
||||
}
|
||||
}
|
||||
EAISetNearestEntityAsTargetCompanion.list.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
//Log.Out($"FindTarget END - closeTargetEntity: {closeTargetEntity}");
|
||||
}
|
||||
|
||||
public override void Start()
|
||||
{
|
||||
this.theEntity.SetAttackTarget(this.targetEntity, 200);
|
||||
this.theEntity.ConditionalTriggerSleeperWakeUp();
|
||||
base.Start();
|
||||
}
|
||||
|
||||
public override bool Continue()
|
||||
{
|
||||
if (!NPCEAICanProceed())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.targetEntity.IsDead() || this.theEntity.distraction != null)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-Continue 5");
|
||||
if (this.theEntity.GetAttackTarget() == this.targetEntity)
|
||||
{
|
||||
//Log.Out("SetNearestEntityAsTarget - Continue - GetAttackTarget() == this.targetEntity and isDead or distraction not null");
|
||||
this.theEntity.attackTarget = (EntityAlive) null;
|
||||
}
|
||||
//Log.Out($"returning false here");
|
||||
return false;
|
||||
}
|
||||
|
||||
this.findTime += 0.05f;
|
||||
|
||||
if (this.findTime > 2f)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-Continue 7");
|
||||
this.findTime = 0f;
|
||||
this.FindTarget();
|
||||
if (this.closeTargetEntity && this.closeTargetEntity != this.targetEntity)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-Continue we have a close target and its not equal to targetEntity return false");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.theEntity.GetAttackTarget() != this.targetEntity)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-Continue this.theEntity.GetAttackTarget() != this.targetEntity");
|
||||
return false;
|
||||
}
|
||||
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-Continue 19");
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
this.targetEntity = null;
|
||||
this.targetPlayer = null;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Format("{0}, {1}", base.ToString(), this.targetEntity ? this.targetEntity.EntityName : "");
|
||||
}
|
||||
|
||||
private const float cHearDistMax = 50f;
|
||||
private List<EAISetNearestEntityAsTargetCompanion.TargetClass> targetClasses;
|
||||
private int playerTargetClassIndex = -1;
|
||||
private float closeTargetDist;
|
||||
private EntityAlive closeTargetEntity;
|
||||
private EntityAlive targetEntity;
|
||||
private EntityPlayer targetPlayer;
|
||||
private Vector3 lastSeenPos;
|
||||
private float findTime;
|
||||
private float senseSoundTime;
|
||||
private EAISetNearestEntityAsTargetSorter sorter;
|
||||
private static List<Entity> list = new List<Entity>();
|
||||
private struct TargetClass
|
||||
{
|
||||
public Type type;
|
||||
public float hearDistMax;
|
||||
public float seeDistMax;
|
||||
}
|
||||
}
|
||||
129
Scripts/EAI/NPCs/EAIWanderCompanion.cs
Normal file
129
Scripts/EAI/NPCs/EAIWanderCompanion.cs
Normal file
@@ -0,0 +1,129 @@
|
||||
using UnityEngine.Scripting;
|
||||
|
||||
[Preserve]
|
||||
public class EAIWanderCompanion : EAIBase
|
||||
{
|
||||
public const float cLookTimeMax = 3f;
|
||||
public Vector3 position;
|
||||
public float time;
|
||||
|
||||
public override void Init(EntityAlive _theEntity)
|
||||
{
|
||||
base.Init(_theEntity);
|
||||
this.MutexBits = 1;
|
||||
}
|
||||
|
||||
public override void Update() => this.time += 0.05f;
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
//Log.Out("EAIWanderCompanion-Reset START");
|
||||
//Log.Out("StackTrace: '{0}'", Environment.StackTrace);
|
||||
this.manager.lookTime = this.RandomFloat * 3f;
|
||||
this.theEntity.moveHelper.Stop();
|
||||
}
|
||||
|
||||
public bool NPCEAICanProceed(bool skipTargetVerification = false)
|
||||
{
|
||||
if (this.theEntity.Buffs.GetCustomVar("$Leader") > 0f)
|
||||
{
|
||||
//Log.Out("EAIWanderCompanion-NPCEAICanProceed 1");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.Buffs.GetCustomVar("CurrentOrder") > 0)
|
||||
{
|
||||
//Log.Out("EAIWanderCompanion-NPCEAICanProceed 1a");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.Buffs.GetCustomVar("onMission") == 1f ||
|
||||
this.theEntity.Buffs.GetCustomVar("$FR_NPC_Respawn") == 1f ||
|
||||
this.theEntity.Buffs.GetCustomVar("$FR_NPC_Hidden") == 1f
|
||||
)
|
||||
{
|
||||
//Log.Out("EAIWanderCompanion-NPCEAICanProceed 1b");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.GetAttackTarget() != null)
|
||||
{
|
||||
//Log.Out($"EAIWanderCompanion-NPCEAICanProceed theEntity.GetAttackTarget() != null: {theEntity.GetAttackTarget()}");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.Buffs.HasBuff("buffTalkingTo"))
|
||||
{
|
||||
//Log.Out("EAIWanderCompanion-NPCEAICanProceed 3");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.sleepingOrWakingUp)
|
||||
{
|
||||
//Log.Out("EAIWanderCompanion-NPCEAICanProceed 4");
|
||||
return false;
|
||||
}
|
||||
if (this.theEntity.GetTicksNoPlayerAdjacent() >= 120)
|
||||
{
|
||||
//Log.Out("EAIWanderCompanion-NPCEAICanProceed 5");
|
||||
return false;
|
||||
}
|
||||
if (this.theEntity.bodyDamage.CurrentStun != EnumEntityStunType.None)
|
||||
{
|
||||
//Log.Out("EAIWanderCompanion-NPCEAICanProceed 6");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool CanExecute()
|
||||
{
|
||||
if (!NPCEAICanProceed())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.sleepingOrWakingUp)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (this.theEntity.GetTicksNoPlayerAdjacent() >= 120)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (this.theEntity.bodyDamage.CurrentStun != EnumEntityStunType.None)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
int num = (int)(200f * this.executeWaitTime);
|
||||
if (base.GetRandom(1000) >= num)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void Start()
|
||||
{
|
||||
int num = 10;
|
||||
this.theEntity.FindPath(RandomPositionGenerator.Calc(this.theEntity, num, num), this.theEntity.GetMoveSpeed(), false, this);
|
||||
}
|
||||
|
||||
public override bool Continue()
|
||||
{
|
||||
if (!NPCEAICanProceed())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//Log.Out("EAIWanderCompanion-Continue this.theEntity.bodyDamage.CurrentStun == EnumEntityStunType.None: " + (this.theEntity.bodyDamage.CurrentStun == EnumEntityStunType.None));
|
||||
//Log.Out("EAIWanderCompanion-Continue this.theEntity.moveHelper.BlockedTime <= 0.3f: " + (this.theEntity.moveHelper.BlockedTime <= 0.3f));
|
||||
//Log.Out("EAIWanderCompanion-Continue !this.theEntity.navigator.noPathAndNotPlanningOne(): " + !this.theEntity.navigator.noPathAndNotPlanningOne());
|
||||
|
||||
bool result = this.theEntity.bodyDamage.CurrentStun == EnumEntityStunType.None && this.theEntity.moveHelper.BlockedTime <= 0.3f && !this.theEntity.navigator.noPathAndNotPlanningOne();
|
||||
|
||||
//Log.Out("EAIWanderCompanion-Continue result: " + result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
1107
Scripts/EAI/NPCs/V2/EAIApproachAndAttackTargetCompanion.cs
Normal file
1107
Scripts/EAI/NPCs/V2/EAIApproachAndAttackTargetCompanion.cs
Normal file
@@ -0,0 +1,1107 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
using System.Xml.Linq;
|
||||
using GamePath;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Scripting;
|
||||
|
||||
[Preserve]
|
||||
public class EAIApproachAndAttackTargetCompanion : EAIBase
|
||||
{
|
||||
public override void Init(EntityAlive _theEntity)
|
||||
{
|
||||
base.Init(_theEntity);
|
||||
this.MutexBits = 3;
|
||||
this.executeDelay = 0.1f;
|
||||
}
|
||||
|
||||
public override void SetData(DictionarySave<string, string> data)
|
||||
{
|
||||
base.SetData(data);
|
||||
this.targetClasses = new List<EAIApproachAndAttackTargetCompanion.TargetClass>();
|
||||
string text;
|
||||
if (data.TryGetValue("class", out text))
|
||||
{
|
||||
string[] array = text.Split(',', StringSplitOptions.None);
|
||||
for (int i = 0; i < array.Length; i += 2)
|
||||
{
|
||||
EAIApproachAndAttackTargetCompanion.TargetClass targetClass = default(EAIApproachAndAttackTargetCompanion.TargetClass);
|
||||
targetClass.type = EntityFactory.GetEntityType(array[i]);
|
||||
targetClass.chaseTimeMax = 0f;
|
||||
if (i + 1 < array.Length)
|
||||
{
|
||||
targetClass.chaseTimeMax = StringParsers.ParseFloat(array[i + 1], 0, -1, NumberStyles.Any);
|
||||
}
|
||||
this.targetClasses.Add(targetClass);
|
||||
if (targetClass.type == typeof(EntityEnemyAnimal))
|
||||
{
|
||||
targetClass.type = typeof(EntityAnimalSnake);
|
||||
this.targetClasses.Add(targetClass);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool NPCEAICanProceed(bool skipTargetVerification = false)
|
||||
{
|
||||
bool result = true;
|
||||
|
||||
if (this.theEntity.Buffs.GetCustomVar("onMission") == 1f ||
|
||||
this.theEntity.Buffs.GetCustomVar("$FR_NPC_Respawn") == 1f ||
|
||||
this.theEntity.Buffs.GetCustomVar("$FR_NPC_Hidden") == 1f
|
||||
)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-NPCEAICanProceed 1");
|
||||
return false;
|
||||
}
|
||||
|
||||
/*if (this.owner == null)
|
||||
{
|
||||
this.owner = (EntityAlive)EntityUtilities.GetOwner(this.theEntity.entityId);
|
||||
}*/
|
||||
|
||||
EntityUtilities.CheckDistanceToLeader(this.theEntity, this.targetPlayer);
|
||||
|
||||
this.entityTarget = this.theEntity.GetAttackTarget();
|
||||
|
||||
/*if (!skipTargetVerification && this.entityTarget == null)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-NPCEAICanProceed 2b");
|
||||
return false;
|
||||
}*/
|
||||
|
||||
if (this.entityTarget != null)
|
||||
{
|
||||
if (this.entityTarget.IsDead())
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-NPCEAICanProceed 2c");
|
||||
this.theEntity.SetRevengeTarget(null);
|
||||
this.theEntity.SetAttackTarget(null, 0);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!this.theEntity.CanEntityBeSeen(this.entityTarget))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-NPCEAICanProceed 2d");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool shouldAttack = RebirthUtilities.VerifyFactionStanding(this.theEntity, this.entityTarget);
|
||||
|
||||
if (!shouldAttack)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-NPCEAICanProceed 2e");
|
||||
//this.theEntity.SetAttackTarget(null, 0);
|
||||
//this.theEntity.SetRevengeTarget(null);
|
||||
return false;
|
||||
}
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-NPCEAICanProceed 2f, this.entityTarget: " + this.entityTarget.EntityClass.entityClassName);
|
||||
}
|
||||
|
||||
if (this.theEntity.emodel.IsRagdollActive)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-NPCEAICanProceed 3");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.sleepingOrWakingUp || this.theEntity.bodyDamage.CurrentStun != EnumEntityStunType.None || (this.theEntity.Jumping && !this.theEntity.isSwimming))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-NPCEAICanProceed 4");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool stopAttacking = this.theEntity.Buffs.HasBuff("FuriousRamsayBuffPauseAttack") ||
|
||||
this.theEntity.Buffs.HasBuff("buffNPCModStopAttacking") ||
|
||||
this.theEntity.Buffs.HasBuff("FuriousRamsayStandStill");
|
||||
|
||||
if (stopAttacking)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-NPCEAICanProceed 5");
|
||||
this.theEntity.SetRevengeTarget(null);
|
||||
this.theEntity.SetAttackTarget(null, 0);
|
||||
|
||||
//return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.sleepingOrWakingUp || this.theEntity.bodyDamage.CurrentStun != EnumEntityStunType.None)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-NPCEAICanProceed 6");
|
||||
return false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public override bool CanExecute()
|
||||
{
|
||||
CheckAnimator();
|
||||
backingUp = false;
|
||||
this.theEntity.Buffs.SetCustomVar("$IsBackingUp", 0f);
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-CanExecute START");
|
||||
|
||||
if (!NPCEAICanProceed(true))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
EntityAliveV2 npc = (EntityAliveV2)this.theEntity;
|
||||
|
||||
if (this.entityTarget != null)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-CanExecute this.entityTarget: " + this.entityTarget.EntityClass.entityClassName);
|
||||
Type type = this.entityTarget.GetType();
|
||||
for (int i = 0; i < this.targetClasses.Count; i++)
|
||||
{
|
||||
EAIApproachAndAttackTargetCompanion.TargetClass targetClass = this.targetClasses[i];
|
||||
if (targetClass.type != null && targetClass.type.IsAssignableFrom(type))
|
||||
{
|
||||
this.chaseTimeMax = targetClass.chaseTimeMax;
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-CanExecute 5");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-CanExecute 6");
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-CanExecute currentOrder: " + ((EntityNPCRebirth)this.theEntity).currentOrder);
|
||||
if (((EntityNPCRebirth)this.theEntity).currentOrder == (int)EntityUtilities.Orders.Stay)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-CanExecute checkEntityPosition");
|
||||
checkEntityPosition();
|
||||
}
|
||||
|
||||
if (this.targetPlayer == null)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-CanExecute 2");
|
||||
this.OwnerID = (int)this.theEntity.Buffs.GetCustomVar("$Leader");
|
||||
|
||||
if (this.OwnerID > 0)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-CanExecute this.OwnerID: " + this.OwnerID);
|
||||
|
||||
EntityPlayer entityPlayer = (EntityPlayer)this.theEntity.world.GetEntity(this.OwnerID);
|
||||
if (entityPlayer != null)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-CanExecute FOUND OWNER");
|
||||
this.targetPlayer = entityPlayer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.targetPlayer == null)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-CanExecute NO OWNER");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-CanExecute END: GO AHEAD");
|
||||
return true;
|
||||
}
|
||||
|
||||
public void checkEntityPosition()
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition START");
|
||||
|
||||
if (!this.theEntity.onGround) return;
|
||||
|
||||
if (this.entityTarget != null)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition HAS ATTACK TARGET");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.theEntity.navigator.noPathAndNotPlanningOne())
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition HAVE PATH");
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.theEntity.Buffs.HasBuff("buffTalkingTo"))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition IS TALKING");
|
||||
return;
|
||||
}
|
||||
|
||||
EntityAliveV2 npc = this.theEntity as EntityAliveV2;
|
||||
|
||||
if (npc == null)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition EXIT");
|
||||
return;
|
||||
}
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition STAY 1, npc.position: (" + npc.position + ") / npc.guardPosition: (" + npc.guardPosition + ")");
|
||||
|
||||
if (npc.guardPosition == Vector3.zero)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition NO GUARD POSITION");
|
||||
return;
|
||||
}
|
||||
|
||||
Vector3 entityPosition = EntityUtilities.CenterPosition(npc.position);
|
||||
Vector3 guardPosition = EntityUtilities.CenterPosition(npc.guardPosition);
|
||||
|
||||
if (entityPosition != guardPosition)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition STAY 2, npc.position: (" + npc.position + ") / npc.guardPosition: (" + npc.guardPosition + ")");
|
||||
npc.moveHelper.SetMoveTo(guardPosition, true);
|
||||
|
||||
npc.navigator?.clearPath();
|
||||
npc.FindPath(
|
||||
npc.guardPosition,
|
||||
npc.GetMoveSpeedPanic(),
|
||||
false,
|
||||
(EAIBase)this);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.theEntity.motion = Vector3.zero;
|
||||
this.theEntity.navigator?.clearPath();
|
||||
this.theEntity.moveHelper?.Stop();
|
||||
this.theEntity.speedForward = 0;
|
||||
this.theEntity.speedStrafe = 0;
|
||||
|
||||
//this.theEntity.navigator?.clearPath();
|
||||
//this.theEntity.moveHelper.Stop();
|
||||
//this.theEntity.speedForward = 0;
|
||||
/*Vector3 entityRotation = EntityUtilities.CenterPosition(npc.rotation);
|
||||
Vector3 guardRotation = EntityUtilities.CenterPosition(npc.guardLookPosition);
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition STAY 3, npc.position: (" + npc.position + ") / npc.guardPosition: (" + npc.guardPosition + ")");
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition entityRotation: " + entityRotation);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition guardRotation: " + guardRotation);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition npc.rotation: " + npc.rotation);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition npc.guardLookPosition: " + npc.guardLookPosition);
|
||||
|
||||
if (entityRotation != guardRotation && npc.rotation != npc.guardLookPosition)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition STAY ROTATE");
|
||||
//npc.rotation = npc.guardLookPosition;
|
||||
|
||||
npc.SetLookPosition(npc.guardLookPosition);
|
||||
|
||||
npc.RotateTo(
|
||||
npc.guardLookPosition.x,
|
||||
npc.guardLookPosition.y,
|
||||
npc.guardLookPosition.z,
|
||||
360f,
|
||||
360f);
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition STAY IS IN RIGHT POSITION AND ROTATION");
|
||||
}*/
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition SetLookPosition");
|
||||
npc.SetLookPosition(npc.guardLookPosition);
|
||||
npc.RotateTo(
|
||||
npc.guardLookPosition.x,
|
||||
npc.guardLookPosition.y,
|
||||
npc.guardLookPosition.z,
|
||||
360f,
|
||||
360f);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Start()
|
||||
{
|
||||
if (this.entityTarget != null)
|
||||
{
|
||||
this.entityTargetPos = this.entityTarget.position;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.entityTargetPos = Vector3.zero;
|
||||
}
|
||||
this.entityTargetVel = Vector3.zero;
|
||||
this.entityPlayerVel = Vector3.zero;
|
||||
this.isTargetToEat = false;
|
||||
this.isEating = false;
|
||||
this.theEntity.IsEating = false;
|
||||
this.homeTimeout = (this.theEntity.IsSleeper ? 90f : this.chaseTimeMax);
|
||||
this.hasHome = (this.homeTimeout > 0f);
|
||||
this.isGoingHome = false;
|
||||
if (this.theEntity.ChaseReturnLocation == Vector3.zero)
|
||||
{
|
||||
this.theEntity.ChaseReturnLocation = (this.theEntity.IsSleeper ? this.theEntity.SleeperSpawnPosition : this.theEntity.position);
|
||||
}
|
||||
this.pathCounter = 0;
|
||||
this.relocateTicks = 0;
|
||||
this.attackTimeout = 5;
|
||||
animator = this.theEntity.emodel.avatarController.GetAnimator();
|
||||
}
|
||||
|
||||
public override bool Continue()
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Continue START");
|
||||
|
||||
CheckAnimator();
|
||||
backingUp = false;
|
||||
this.theEntity.Buffs.SetCustomVar("$IsBackingUp", 0f);
|
||||
|
||||
if (!NPCEAICanProceed())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool result = false;
|
||||
|
||||
EntityAlive attackTarget = this.theEntity.GetAttackTarget();
|
||||
|
||||
if (attackTarget != null)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Continue 1, attackTarget: " + attackTarget.EntityClass.entityClassName);
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Continue currentOrder: " + ((EntityNPCRebirth)this.theEntity).currentOrder);
|
||||
if (((EntityNPCRebirth)this.theEntity).currentOrder == (int)EntityUtilities.Orders.Stay)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Continue checkEntityPosition");
|
||||
checkEntityPosition();
|
||||
}
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Continue NO ATTACK TARGET");
|
||||
}
|
||||
|
||||
if (this.isGoingHome)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Continue 3, " + result);
|
||||
result = !attackTarget && this.theEntity.ChaseReturnLocation != Vector3.zero;
|
||||
return result;
|
||||
}
|
||||
|
||||
result = attackTarget && !(attackTarget != this.entityTarget);
|
||||
|
||||
if (!result && this.targetPlayer != null)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Continue WILL CONTINUE GIVEN HAS OWNER");
|
||||
return true;
|
||||
}
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Continue 4, " + result);
|
||||
return result;
|
||||
}
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
this.theEntity.IsEating = false;
|
||||
this.theEntity.motion = Vector3.zero;
|
||||
this.theEntity.navigator?.clearPath();
|
||||
this.theEntity.moveHelper?.Stop();
|
||||
this.theEntity.speedForward = 0;
|
||||
this.theEntity.speedStrafe = 0;
|
||||
//this.theEntity.navigator?.clearPath();
|
||||
//this.theEntity.moveHelper.Stop();
|
||||
if (this.blockTargetTask != null)
|
||||
{
|
||||
this.blockTargetTask.canExecute = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void CheckAnimator()
|
||||
{
|
||||
if (animator && !backingUp)
|
||||
{
|
||||
animator.SetBool("isBackingUp", false);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
CheckAnimator();
|
||||
backingUp = false;
|
||||
this.theEntity.Buffs.SetCustomVar("$IsBackingUp", 0f);
|
||||
|
||||
if (!NPCEAICanProceed())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.theEntity.Climbing)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 19");
|
||||
return;
|
||||
}
|
||||
|
||||
EntityAliveV2 npc = this.theEntity as EntityAliveV2;
|
||||
|
||||
if (npc == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.relocateTicks > 0)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 2");
|
||||
if (!this.theEntity.navigator.noPathAndNotPlanningOne())
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 3");
|
||||
this.relocateTicks--;
|
||||
this.theEntity.moveHelper.SetFocusPos(this.entityTarget.position);
|
||||
return;
|
||||
}
|
||||
this.relocateTicks = 0;
|
||||
}
|
||||
|
||||
EntityUtilities.CheckForClosedDoor(this.theEntity);
|
||||
|
||||
float targetXZDistanceSq = 0;
|
||||
|
||||
float distance = 0;
|
||||
|
||||
if (this.entityTarget != null)
|
||||
{
|
||||
distance = this.entityTarget.GetDistance(this.theEntity);
|
||||
}
|
||||
|
||||
bool isRanged = false;
|
||||
|
||||
if (this.theEntity.HasAnyTags(FastTags<TagGroup.Global>.Parse("ranged")))
|
||||
{
|
||||
_actionIndex = 1;
|
||||
isRanged = true;
|
||||
}
|
||||
|
||||
bool skipFollow = false;
|
||||
|
||||
/*if (this.entityTarget != null && isRanged && ((((EntityNPCRebirth)this.theEntity).currentOrder == (int)EntityUtilities.Orders.Follow) || this.theEntity.Buffs.GetCustomVar("$Leader") == 0))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update distance: " + distance);
|
||||
|
||||
float distanceFromTarget = 4f;
|
||||
|
||||
if (this.entityTarget is EntityPlayer)
|
||||
{
|
||||
distanceFromTarget = 5f;
|
||||
}
|
||||
|
||||
if (distance < distanceFromTarget)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 6");
|
||||
//if (!this.entityTarget.emodel.IsRagdollActive)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 6a");
|
||||
|
||||
int maxDistanceFromLeader = UnityEngine.Random.Range(10, 25);
|
||||
|
||||
backingUp = true;
|
||||
this.theEntity.Buffs.SetCustomVar("$IsBackingUp", 1f);
|
||||
|
||||
Animator animator = this.theEntity.emodel.avatarController.GetAnimator();
|
||||
|
||||
if (animator)
|
||||
{
|
||||
animator.SetBool("isBackingUp", true);
|
||||
}
|
||||
|
||||
EntityUtilities.BackupHelper(this.theEntity, this.entityTarget, distanceFromTarget * 3f, maxDistanceFromLeader);
|
||||
}
|
||||
skipFollow = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.theEntity.Buffs.SetCustomVar("$IsBackingUp", 0f);
|
||||
skipFollow = false;
|
||||
Animator animator = this.theEntity.emodel.avatarController.GetAnimator();
|
||||
|
||||
if (animator)
|
||||
{
|
||||
animator.SetBool("isBackingUp", false);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
if (!skipFollow && this.entityTarget == null)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update currentOrder: " + ((EntityNPCRebirth)this.theEntity).currentOrder);
|
||||
if (((EntityNPCRebirth)this.theEntity).currentOrder != (int)EntityUtilities.Orders.Stay)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 1");
|
||||
|
||||
if (this.relocateTicks > 0)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 2");
|
||||
if (!this.theEntity.navigator.noPathAndNotPlanningOne())
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 3");
|
||||
this.relocateTicks--;
|
||||
this.theEntity.moveHelper.SetFocusPos(this.targetPlayer.position);
|
||||
return;
|
||||
}
|
||||
this.relocateTicks = 0;
|
||||
}
|
||||
|
||||
Vector3 vector2 = this.targetPlayer.position;
|
||||
|
||||
Vector3 a = theEntity.position - vector2;
|
||||
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update entityTargetPosn: " + vector2);
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update a: " + a);
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update a.sqrMagnitude: " + a.sqrMagnitude);
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update this.OwnerID: " + this.theEntity.Buffs.GetCustomVar("$Leader"));
|
||||
|
||||
this.OwnerID = (int)this.theEntity.Buffs.GetCustomVar("$Leader");
|
||||
|
||||
float magnitude = 3f; // 30f;
|
||||
|
||||
bool isClient = SingletonMonoBehaviour<ConnectionManager>.Instance.IsClient;
|
||||
|
||||
if (isClient)
|
||||
{
|
||||
magnitude = 3f;
|
||||
}
|
||||
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update magnitude: " + magnitude);
|
||||
|
||||
if (this.targetPlayer.entityId == this.OwnerID && a.sqrMagnitude < magnitude)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update Entity is too close. Ending pathing.");
|
||||
this.theEntity.motion = Vector3.zero;
|
||||
this.theEntity.navigator?.clearPath();
|
||||
this.theEntity.moveHelper?.Stop();
|
||||
this.theEntity.speedForward = 0;
|
||||
this.theEntity.speedStrafe = 0;
|
||||
//this.theEntity.navigator?.clearPath();
|
||||
//this.theEntity.moveHelper.Stop();
|
||||
pathCounter = 0;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.targetPlayer.entityId == this.OwnerID)
|
||||
{
|
||||
if (!this.theEntity.HasAnyTags(FastTags<TagGroup.Global>.Parse("allyanimal")))
|
||||
{
|
||||
this.theEntity.Crouching = this.targetPlayer.Crouching;
|
||||
}
|
||||
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update theEntity.moveHelper.BlockedTime: " + theEntity.moveHelper.BlockedTime);
|
||||
|
||||
if (theEntity.moveHelper.BlockedTime > 3f)
|
||||
{
|
||||
npc.TeleportToPlayer(this.targetPlayer, false);
|
||||
}
|
||||
}
|
||||
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update SetLookPosition");
|
||||
theEntity.SetLookPosition(vector2);
|
||||
theEntity.RotateTo(vector2.x, vector2.y + 2, vector2.z, 8f, 8f);
|
||||
|
||||
if (a.sqrMagnitude < 1f)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 6");
|
||||
this.entityPlayerVel = this.entityPlayerVel * 0.7f + a * 0.3f;
|
||||
}
|
||||
//this.entityPlayerPos = vector2;
|
||||
|
||||
this.theEntity.moveHelper.CalcIfUnreachablePos();
|
||||
float num2;
|
||||
float num3;
|
||||
|
||||
num2 = 1.095f;
|
||||
num3 = Utils.FastMax(0.7f, num2 - 0.35f);
|
||||
|
||||
float num4 = num3 * num3;
|
||||
float num5 = 4f;
|
||||
if (this.theEntity.IsFeral)
|
||||
{
|
||||
num5 = 8f;
|
||||
}
|
||||
num5 = base.RandomFloat * num5;
|
||||
targetXZDistanceSq = this.GetTargetXZDistanceSqPlayer(num5);
|
||||
float num6 = vector2.y - this.theEntity.position.y;
|
||||
float num7 = Utils.FastAbs(num6);
|
||||
bool flag = targetXZDistanceSq <= num4 && num7 < 1f;
|
||||
if (!flag)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 9");
|
||||
if (num7 < 3f && !PathFinderThread.Instance.IsCalculatingPath(this.theEntity.entityId))
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 10");
|
||||
PathEntity path = this.theEntity.navigator.getPath();
|
||||
if (path != null && path.NodeCountRemaining() <= 2)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 11");
|
||||
this.pathCounter = 0;
|
||||
}
|
||||
}
|
||||
int num = this.pathCounter - 1;
|
||||
this.pathCounter = num;
|
||||
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update num: " + num);
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update CanNavigatePath: " + this.theEntity.CanNavigatePath());
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update IsCalculatingPath: " + PathFinderThread.Instance.IsCalculatingPath(this.theEntity.entityId));
|
||||
|
||||
if (num <= 0 && this.theEntity.CanNavigatePath() && !PathFinderThread.Instance.IsCalculatingPath(this.theEntity.entityId))
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 12");
|
||||
this.pathCounter = 6 + base.GetRandom(10);
|
||||
Vector3 moveToLocation = EntityUtilities.GetMoveToLocation(this.theEntity, this.targetPlayer.position, 5);
|
||||
if (moveToLocation.y - this.theEntity.position.y < -8f)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 13");
|
||||
this.pathCounter += 40;
|
||||
if (base.RandomFloat < 0.2f)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 14");
|
||||
this.seekPosOffset.x = this.seekPosOffset.x + (base.RandomFloat * 0.6f - 0.3f);
|
||||
this.seekPosOffset.y = this.seekPosOffset.y + (base.RandomFloat * 0.6f - 0.3f);
|
||||
}
|
||||
moveToLocation.x += this.seekPosOffset.x;
|
||||
moveToLocation.z += this.seekPosOffset.y;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 15");
|
||||
float num8 = (moveToLocation - this.theEntity.position).magnitude - 5f;
|
||||
if (num8 > 0f)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 16");
|
||||
if (num8 > 60f)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 17");
|
||||
num8 = 60f;
|
||||
}
|
||||
this.pathCounter += (int)(num8 / 20f * 20f);
|
||||
}
|
||||
}
|
||||
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update $IsBackingUp: " + this.theEntity.Buffs.GetCustomVar("$IsBackingUp"));
|
||||
|
||||
// THIS WORKS GREAT FOR FOLLOWING THE LEADER BUT MAKES THE ENTITY MOVE INTO THE TARGET
|
||||
this.theEntity.navigator?.clearPath();
|
||||
this.theEntity.FindPath(moveToLocation, this.theEntity.GetMoveSpeedAggro(), false, (EAIBase)this);
|
||||
}
|
||||
}
|
||||
if (this.theEntity.Climbing)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 18");
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 19 checkEntityPosition");
|
||||
checkEntityPosition();
|
||||
}
|
||||
return;
|
||||
}
|
||||
/*else
|
||||
{
|
||||
EntityAlive attackTarget = this.theEntity.GetAttackTarget();
|
||||
|
||||
if ((attackTarget && !(attackTarget != this.entityTarget)) == false)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update NO NEED TO UPDATE");
|
||||
return;
|
||||
}
|
||||
}*/
|
||||
|
||||
ItemValue holdingItemItemValue = this.theEntity.inventory.holdingItemItemValue;
|
||||
int holdingItemIdx = this.theEntity.inventory.holdingItemIdx;
|
||||
|
||||
ItemAction itemAction = this.theEntity.inventory.holdingItem.Actions[_actionIndex];
|
||||
|
||||
Vector3 curEntTargPos = this.entityTarget.position;
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update B entityClassName: " + this.entityTarget.EntityClass.entityClassName);
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update SetLookPosition");
|
||||
theEntity.SetLookPosition(curEntTargPos);
|
||||
theEntity.RotateTo(curEntTargPos.x, curEntTargPos.y + 2, curEntTargPos.z, 8f, 8f);
|
||||
|
||||
Vector3 targetDirection = theEntity.position - curEntTargPos;
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update this.entityTarget.position: " + this.entityTarget.position);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update entityTargetPosn: " + curEntTargPos);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update targetDirection: " + targetDirection);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update targetDirection.sqrMagnitude: " + targetDirection.sqrMagnitude);
|
||||
|
||||
/*
|
||||
if (this.theEntity.GetAttackTarget() != null)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update GetAttackTarget: " + this.theEntity.GetAttackTarget().EntityClass.entityClassName);
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update NO ATTACK TARGET");
|
||||
}
|
||||
*/
|
||||
|
||||
bool isTargetWithinItemActionRange = false;
|
||||
|
||||
if (targetDirection.sqrMagnitude < 1f)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 7");
|
||||
this.entityTargetVel = this.entityTargetVel * 0.7f + targetDirection * 0.3f;
|
||||
}
|
||||
this.entityTargetPos = curEntTargPos;
|
||||
this.attackTimeout--;
|
||||
|
||||
this.theEntity.moveHelper.CalcIfUnreachablePos();
|
||||
float itemActionRange;
|
||||
float maxItemActionRange;
|
||||
|
||||
itemActionRange = 1.095f;
|
||||
if (itemAction != null)
|
||||
{
|
||||
itemActionRange = itemAction.Range;
|
||||
if (itemActionRange == 0f)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 8");
|
||||
itemActionRange = EffectManager.GetItemValue(PassiveEffects.MaxRange, holdingItemItemValue, 0f);
|
||||
}
|
||||
}
|
||||
maxItemActionRange = Utils.FastMax(0.7f, itemActionRange - 0.35f);
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 9a, itemActionRange: " + itemActionRange);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 9b, maxItemActionRange: " + maxItemActionRange);
|
||||
|
||||
float maxRangeSquared = maxItemActionRange * maxItemActionRange;
|
||||
float estimatedTimeInTicks = 4f;
|
||||
if (this.theEntity.IsFeral)
|
||||
{
|
||||
estimatedTimeInTicks = 8f;
|
||||
}
|
||||
estimatedTimeInTicks = base.RandomFloat * estimatedTimeInTicks;
|
||||
targetXZDistanceSq = this.GetTargetXZDistanceSq(estimatedTimeInTicks);
|
||||
float yDiff = curEntTargPos.y - this.theEntity.position.y;
|
||||
float absoluteYDiff = Utils.FastAbs(yDiff);
|
||||
float entityDistance = Vector3.Distance(this.theEntity.position, curEntTargPos);
|
||||
isTargetWithinItemActionRange = entityDistance < maxItemActionRange;
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update entityDistance: " + entityDistance);
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update isTargetWithinItemActionRange: " + isTargetWithinItemActionRange);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update maxRangeSquared: " + maxRangeSquared);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update absoluteYDiff: " + absoluteYDiff);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update yDiff: " + yDiff);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update targetXZDistanceSq: " + targetXZDistanceSq);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update backingUp: " + backingUp);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update CurrentOrder: " + ((EntityNPCRebirth)this.theEntity).currentOrder);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update $Leader: " + this.theEntity.Buffs.GetCustomVar("$Leader"));
|
||||
|
||||
if (!backingUp && ((((EntityNPCRebirth)this.theEntity).currentOrder == (int)EntityUtilities.Orders.Follow) || this.theEntity.Buffs.GetCustomVar("$Leader") == 0))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 10a");
|
||||
|
||||
if (!isTargetWithinItemActionRange)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 10c");
|
||||
if (absoluteYDiff < 3f && !PathFinderThread.Instance.IsCalculatingPath(this.theEntity.entityId))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 11");
|
||||
PathEntity path = this.theEntity.navigator.getPath();
|
||||
if (path != null && path.NodeCountRemaining() <= 2)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 12");
|
||||
this.pathCounter = 0;
|
||||
}
|
||||
}
|
||||
int pathCounterLessOne = this.pathCounter - 1;
|
||||
this.pathCounter = pathCounterLessOne;
|
||||
if (pathCounterLessOne <= 0 && this.theEntity.CanNavigatePath() && !PathFinderThread.Instance.IsCalculatingPath(this.theEntity.entityId))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 13");
|
||||
this.pathCounter = 6 + base.GetRandom(10);
|
||||
Vector3 moveToLocation = EntityUtilities.GetMoveToLocation(this.theEntity, this.entityTarget.position, 0);
|
||||
|
||||
if (isRanged)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update BEFORE moveToLocation: " + moveToLocation);
|
||||
//moveToLocation = RandomPositionGenerator.CalcAway(this.theEntity, 2, 5, 5, this.entityTarget.position);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update AFTER moveToLocation: " + moveToLocation);
|
||||
}
|
||||
|
||||
if (moveToLocation.y - this.theEntity.position.y < -8f)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 14");
|
||||
this.pathCounter += 40;
|
||||
if (base.RandomFloat < 0.2f)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 15");
|
||||
this.seekPosOffset.x = this.seekPosOffset.x + (base.RandomFloat * 0.6f - 0.3f);
|
||||
this.seekPosOffset.y = this.seekPosOffset.y + (base.RandomFloat * 0.6f - 0.3f);
|
||||
}
|
||||
moveToLocation.x += this.seekPosOffset.x;
|
||||
moveToLocation.z += this.seekPosOffset.y;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 16");
|
||||
float num8 = (moveToLocation - this.theEntity.position).magnitude - 5f;
|
||||
if (num8 > 0f)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 17");
|
||||
if (num8 > 60f)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 18");
|
||||
num8 = 60f;
|
||||
}
|
||||
this.pathCounter += (int)(num8 / 20f * 20f);
|
||||
}
|
||||
}
|
||||
// COMMENTED OUT TO REMOVE FORWARD MOVEMENT TOWARDS TARGET
|
||||
//this.theEntity.FindPath(moveToLocation, this.theEntity.GetMoveSpeedAggro(), true, (EAIBase)this);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 21");
|
||||
this.theEntity.motion = Vector3.zero;
|
||||
this.theEntity.navigator?.clearPath();
|
||||
this.theEntity.moveHelper?.Stop();
|
||||
this.theEntity.speedForward = 0;
|
||||
this.theEntity.speedStrafe = 0;
|
||||
this.pathCounter = 0;
|
||||
}
|
||||
|
||||
if (!isTargetWithinItemActionRange)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 19");
|
||||
if (this.theEntity.navigator.noPathAndNotPlanningOne() && this.pathCounter > 0 && yDiff < 2.1f)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 20");
|
||||
Vector3 moveToLocation2 = EntityUtilities.GetMoveToLocation(this.theEntity, this.entityTarget.position, 0);
|
||||
this.theEntity.moveHelper.SetMoveTo(moveToLocation2, true);
|
||||
}
|
||||
}
|
||||
|
||||
float newItemActionRange = itemActionRange - 0.1f;
|
||||
float newRangeSquared = newItemActionRange * newItemActionRange;
|
||||
this.theEntity.IsBreakingBlocks = false;
|
||||
this.theEntity.IsBreakingDoors = false;
|
||||
if (this.theEntity.bodyDamage.HasLimbs && !this.theEntity.Electrocuted)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 23");
|
||||
this.theEntity.RotateTo(curEntTargPos.x, curEntTargPos.y, curEntTargPos.z, 30f, 30f);
|
||||
}
|
||||
if (this.theEntity.GetDamagedTarget() == this.entityTarget || (this.entityTarget != null && this.entityTarget.GetDamagedTarget() == this.theEntity))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 24");
|
||||
this.homeTimeout = (this.theEntity.IsSleeper ? 90f : this.chaseTimeMax);
|
||||
if (this.blockTargetTask != null)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 25");
|
||||
this.blockTargetTask.canExecute = false;
|
||||
}
|
||||
this.theEntity.ClearDamagedTarget();
|
||||
if (this.entityTarget)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 26");
|
||||
this.entityTarget.ClearDamagedTarget();
|
||||
}
|
||||
}
|
||||
|
||||
if (this.manager.groupCircle > 0f)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 27");
|
||||
Entity targetIfAttackedNow = this.theEntity.GetTargetIfAttackedNow();
|
||||
if (targetIfAttackedNow != this.entityTarget && (!this.entityTarget.AttachedToEntity || this.entityTarget.AttachedToEntity != targetIfAttackedNow))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 28");
|
||||
if (targetIfAttackedNow != null)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 29");
|
||||
this.relocateTicks = 46;
|
||||
Vector3 vector3 = (this.theEntity.position - curEntTargPos).normalized * (newItemActionRange + 1.1f);
|
||||
float num11 = base.RandomFloat * 28f + 18f;
|
||||
if (base.RandomFloat < 0.5f)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 30");
|
||||
num11 = -num11;
|
||||
}
|
||||
vector3 = Quaternion.Euler(0f, num11, 0f) * vector3;
|
||||
Vector3 targetPos = curEntTargPos + vector3;
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 30a FIND PATH");
|
||||
|
||||
// MAY BE REQUIRED - TESTING
|
||||
//this.theEntity.navigator?.clearPath();
|
||||
//this.theEntity.FindPath(targetPos, this.theEntity.GetMoveSpeedAggro(), true, (EAIBase)this);
|
||||
}
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update E entityClassName: " + this.entityTarget.EntityClass.entityClassName);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 31");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update _actionIndex: " + _actionIndex);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update isRanged: " + isRanged);
|
||||
|
||||
this.theEntity.SleeperSupressLivingSounds = false;
|
||||
|
||||
if (this.theEntity.Buffs.HasBuff("buffReloadDelay") ||
|
||||
this.theEntity.Buffs.HasBuff("buffReload2") ||
|
||||
this.theEntity.Buffs.HasBuff("buffReload3")
|
||||
)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 33");
|
||||
return;
|
||||
}
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 34");
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update backingUp: " + backingUp);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update distance: " + distance);
|
||||
|
||||
int rangeMax = 20;
|
||||
|
||||
PrefabInstance poiatPosition = this.theEntity.world.GetPOIAtPosition(this.theEntity.position, false);
|
||||
|
||||
if (poiatPosition != null)
|
||||
{
|
||||
//Give NPCs a better chance at a ragdoll when inside a POI
|
||||
rangeMax = 10;
|
||||
}
|
||||
|
||||
if (this.entityTarget is EntityPlayer)
|
||||
{
|
||||
rangeMax = 100;
|
||||
}
|
||||
|
||||
int chance = UnityEngine.Random.Range(1, rangeMax);
|
||||
|
||||
if (chance < 10 && !this.entityTarget.emodel.IsRagdollActive && distance < this.theEntity.inventory.holdingItem.Actions[0].Range)
|
||||
{
|
||||
_actionIndex = 0;
|
||||
}
|
||||
|
||||
if (_actionIndex == 1)
|
||||
{
|
||||
if (!isTargetWithinItemActionRange && this.theEntity.moveHelper.IsActive)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update Target isn't within range");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (isTargetWithinItemActionRange)
|
||||
{
|
||||
if (this.theEntity.Buffs.HasBuff("buffRangedMeleeDelay"))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update HAS ATTACK DELAY BUFF");
|
||||
return;
|
||||
}
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 35a");
|
||||
if (npc.ExecuteAction(false, _actionIndex))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 35b");
|
||||
this.attackTimeout = this.theEntity.GetAttackTimeoutTicks();
|
||||
|
||||
if (isRanged && _actionIndex == 0)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update ADDED ATTACK DELAY BUFF");
|
||||
this.theEntity.Buffs.AddBuff("buffRangedMeleeDelay");
|
||||
}
|
||||
|
||||
// Check the range on the item action
|
||||
ItemActionRanged.ItemActionDataRanged itemActionData = null;
|
||||
|
||||
if (itemAction is ItemActionRanged itemActionRanged)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 36");
|
||||
itemActionData = this.theEntity.inventory.holdingItemData.actionData[_actionIndex] as ItemActionRanged.ItemActionDataRanged;
|
||||
if (itemActionData != null)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 37");
|
||||
// Check if we are already running.
|
||||
if (itemAction.IsActionRunning(itemActionData))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 38");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private float GetTargetXZDistanceSq(float estimatedTicks)
|
||||
{
|
||||
Vector3 vector = this.entityTarget.position;
|
||||
vector += this.entityTargetVel * estimatedTicks;
|
||||
Vector3 vector2 = this.theEntity.position + this.theEntity.motion * estimatedTicks - vector;
|
||||
vector2.y = 0f;
|
||||
return vector2.sqrMagnitude;
|
||||
}
|
||||
|
||||
private float GetTargetXZDistanceSqPlayer(float estimatedTicks)
|
||||
{
|
||||
Vector3 vector = this.targetPlayer.position;
|
||||
vector += this.entityPlayerVel * estimatedTicks;
|
||||
Vector3 vector2 = this.theEntity.position + this.theEntity.motion * estimatedTicks - vector;
|
||||
vector2.y = 0f;
|
||||
return vector2.sqrMagnitude;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
ItemValue holdingItemItemValue = this.theEntity.inventory.holdingItemItemValue;
|
||||
int holdingItemIdx = this.theEntity.inventory.holdingItemIdx;
|
||||
ItemAction itemAction = holdingItemItemValue.ItemClass.Actions[holdingItemIdx];
|
||||
float num = 1.095f;
|
||||
if (itemAction != null)
|
||||
{
|
||||
num = itemAction.Range;
|
||||
if (num == 0f)
|
||||
{
|
||||
num = EffectManager.GetItemValue(PassiveEffects.MaxRange, holdingItemItemValue, 0f);
|
||||
}
|
||||
}
|
||||
float value = num - 0.1f;
|
||||
float targetXZDistanceSq = this.GetTargetXZDistanceSq(0f);
|
||||
return string.Format("{0}, {1}{2}{3}{4}{5} dist {6} rng {7} timeout {8}", new object[]
|
||||
{
|
||||
base.ToString(),
|
||||
this.entityTarget ? this.entityTarget.EntityName : "",
|
||||
this.theEntity.CanSee(this.entityTarget) ? "(see)" : "",
|
||||
this.theEntity.navigator.noPathAndNotPlanningOne() ? "(-path)" : (this.theEntity.navigator.noPath() ? "(!path)" : ""),
|
||||
this.isTargetToEat ? "(eat)" : "",
|
||||
this.isGoingHome ? "(home)" : "",
|
||||
Mathf.Sqrt(targetXZDistanceSq).ToCultureInvariantString("0.000"),
|
||||
value.ToCultureInvariantString("0.000"),
|
||||
this.homeTimeout.ToCultureInvariantString("0.00")
|
||||
});
|
||||
}
|
||||
|
||||
private int _actionIndex = 0;
|
||||
private const float cSleeperChaseTime = 90f;
|
||||
private List<EAIApproachAndAttackTargetCompanion.TargetClass> targetClasses;
|
||||
private float chaseTimeMax;
|
||||
private bool hasHome;
|
||||
private bool isGoingHome;
|
||||
private float homeTimeout;
|
||||
private EntityAlive targetPlayer;
|
||||
private EntityAlive entityTarget;
|
||||
private Vector3 entityTargetPos;
|
||||
private Vector3 entityTargetVel;
|
||||
private Vector3 entityPlayerVel;
|
||||
private int attackTimeout;
|
||||
private int pathCounter;
|
||||
private Vector2 seekPosOffset;
|
||||
private bool isTargetToEat;
|
||||
private bool isEating;
|
||||
private int eatCount;
|
||||
private EAIBlockingTargetTask blockTargetTask;
|
||||
private int relocateTicks;
|
||||
private int OwnerID = 0;
|
||||
private bool backingUp = false;
|
||||
private Animator animator = null;
|
||||
|
||||
private struct TargetClass
|
||||
{
|
||||
public Type type;
|
||||
public float chaseTimeMax;
|
||||
}
|
||||
}
|
||||
378
Scripts/EAI/NPCs/V2/EAIFollowLeaderCompanion.cs
Normal file
378
Scripts/EAI/NPCs/V2/EAIFollowLeaderCompanion.cs
Normal file
@@ -0,0 +1,378 @@
|
||||
using GamePath;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Xml;
|
||||
using UnityEngine.Scripting;
|
||||
using static BlendCycleTimer;
|
||||
using static EntityDrone;
|
||||
|
||||
[Preserve]
|
||||
public class EAIFollowLeaderCompanion : EAITarget
|
||||
{
|
||||
public override void Init(EntityAlive _theEntity)
|
||||
{
|
||||
base.Init(_theEntity, 25f, true);
|
||||
this.MutexBits = 1;
|
||||
}
|
||||
|
||||
public override void Start()
|
||||
{
|
||||
this.entityPlayerVel = Vector3.zero;
|
||||
this.relocateTicks = 0;
|
||||
this.pathCounter = 0;
|
||||
this.theEntity.ConditionalTriggerSleeperWakeUp();
|
||||
base.Start();
|
||||
}
|
||||
|
||||
public bool NPCEAICanProceed()
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-NPCEAICanProceed START");
|
||||
|
||||
bool result = true;
|
||||
|
||||
this.OwnerID = (int)this.theEntity.Buffs.GetCustomVar("$Leader");
|
||||
|
||||
if (this.OwnerID == 0)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-NPCEAICanProceed 0");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.Buffs.GetCustomVar("onMission") == 1f ||
|
||||
this.theEntity.Buffs.GetCustomVar("$FR_NPC_Respawn") == 1f ||
|
||||
this.theEntity.Buffs.GetCustomVar("$FR_NPC_Hidden") == 1f
|
||||
)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-NPCEAICanProceed 1");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.GetAttackTarget() != null)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-NPCEAICanProceed 1a");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.Buffs.GetCustomVar("$IsBackingUp") == 1f)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-NPCEAICanProceed 2");
|
||||
return false;
|
||||
}
|
||||
|
||||
EntityUtilities.CheckDistanceToLeader(this.theEntity, this.targetPlayer);
|
||||
|
||||
if (this.theEntity.emodel.IsRagdollActive)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-NPCEAICanProceed 3");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.sleepingOrWakingUp || this.theEntity.bodyDamage.CurrentStun != EnumEntityStunType.None || (this.theEntity.Jumping && !this.theEntity.isSwimming))
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-NPCEAICanProceed 4");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.Buffs.GetCustomVar("CurrentOrder") != (int)EntityUtilities.Orders.Follow)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-CanExecute IS NOT FOLLOWING");
|
||||
return false;
|
||||
}
|
||||
|
||||
/*bool stopAttacking = this.theEntity.Buffs.HasBuff("FuriousRamsayBuffPauseAttack") ||
|
||||
this.theEntity.Buffs.HasBuff("buffNPCModStopAttacking") ||
|
||||
this.theEntity.Buffs.HasBuff("FuriousRamsayStandStill");*/
|
||||
|
||||
bool stopAttacking = this.theEntity.Buffs.HasBuff("FuriousRamsayStandStill");
|
||||
|
||||
if (stopAttacking)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-NPCEAICanProceed 5");
|
||||
this.theEntity.SetRevengeTarget(null);
|
||||
this.theEntity.SetAttackTarget(null, 0);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.sleepingOrWakingUp || this.theEntity.bodyDamage.CurrentStun != EnumEntityStunType.None)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-NPCEAICanProceed 6");
|
||||
return false;
|
||||
}
|
||||
|
||||
//Log.Out("EAIFollowLeaderCompanion-NPCEAICanProceed result: " + result);
|
||||
return result;
|
||||
}
|
||||
|
||||
public override bool CanExecute()
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-CanExecute START");
|
||||
|
||||
if (!NPCEAICanProceed())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.targetPlayer == null)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-CanExecute 2");
|
||||
this.OwnerID = (int)this.theEntity.Buffs.GetCustomVar("$Leader");
|
||||
|
||||
if (this.OwnerID > 0)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-CanExecute this.OwnerID: " + this.OwnerID);
|
||||
|
||||
EntityPlayer entityPlayer = (EntityPlayer)this.theEntity.world.GetEntity(this.OwnerID);
|
||||
if (entityPlayer != null)
|
||||
{
|
||||
this.targetPlayer = entityPlayer;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//Log.Out("EAIFollowLeaderCompanion-CanExecute this.theEntity.GetAttackTarget: " + this.theEntity.GetAttackTarget().EntityClass.entityClassName);
|
||||
return false;
|
||||
}
|
||||
|
||||
public override bool Continue()
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Continue START");
|
||||
|
||||
if (!NPCEAICanProceed())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (pathCounter == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update START");
|
||||
|
||||
if (!NPCEAICanProceed())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.targetPlayer == null)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 2");
|
||||
this.OwnerID = (int)this.theEntity.Buffs.GetCustomVar("$Leader");
|
||||
|
||||
if (this.OwnerID > 0)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update this.OwnerID: " + this.OwnerID);
|
||||
|
||||
EntityPlayer entityPlayer = (EntityPlayer)this.theEntity.world.GetEntity(this.OwnerID);
|
||||
if (entityPlayer != null)
|
||||
{
|
||||
this.targetPlayer = entityPlayer;
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update FOUND OWNER");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EntityUtilities.CheckForClosedDoor(this.theEntity);
|
||||
|
||||
if (this.relocateTicks > 0)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 2");
|
||||
if (!this.theEntity.navigator.noPathAndNotPlanningOne())
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 3");
|
||||
this.relocateTicks--;
|
||||
this.theEntity.moveHelper.SetFocusPos(this.targetPlayer.position);
|
||||
return;
|
||||
}
|
||||
this.relocateTicks = 0;
|
||||
}
|
||||
|
||||
Vector3 vector2 = this.targetPlayer.position;
|
||||
|
||||
Vector3 a = theEntity.position - vector2;
|
||||
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update entityTargetPosn: " + vector2);
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update a: " + a);
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update a.sqrMagnitude: " + a.sqrMagnitude);
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update this.OwnerID: " + this.theEntity.Buffs.GetCustomVar("$Leader"));
|
||||
|
||||
this.OwnerID = (int)this.theEntity.Buffs.GetCustomVar("$Leader");
|
||||
|
||||
float magnitude = 30f;
|
||||
|
||||
bool isClient = SingletonMonoBehaviour<ConnectionManager>.Instance.IsClient;
|
||||
|
||||
if (isClient)
|
||||
{
|
||||
magnitude = 3f;
|
||||
}
|
||||
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update magnitude: " + magnitude);
|
||||
|
||||
if (this.targetPlayer.entityId == this.OwnerID && a.sqrMagnitude < magnitude)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update Entity is too close. Ending pathing.");
|
||||
//this.theEntity.navigator?.clearPath();
|
||||
this.theEntity.moveHelper.Stop();
|
||||
pathCounter = 0;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.targetPlayer.entityId == this.OwnerID)
|
||||
{
|
||||
if (!this.theEntity.HasAnyTags(FastTags<TagGroup.Global>.Parse("allyanimal")))
|
||||
{
|
||||
this.theEntity.Crouching = this.targetPlayer.Crouching;
|
||||
}
|
||||
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update theEntity.moveHelper.BlockedTime: " + theEntity.moveHelper.BlockedTime);
|
||||
|
||||
if (theEntity.moveHelper.BlockedTime > 3f)
|
||||
{
|
||||
EntityAliveV2 npc = this.theEntity as EntityAliveV2;
|
||||
|
||||
if (npc != null)
|
||||
{
|
||||
npc.TeleportToPlayer(this.targetPlayer, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update SetLookPosition");
|
||||
theEntity.SetLookPosition(vector2);
|
||||
theEntity.RotateTo(vector2.x, vector2.y + 2, vector2.z, 8f, 8f);
|
||||
|
||||
if (a.sqrMagnitude < 1f)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 6");
|
||||
this.entityPlayerVel = this.entityPlayerVel * 0.7f + a * 0.3f;
|
||||
}
|
||||
this.entityPlayerPos = vector2;
|
||||
|
||||
this.theEntity.moveHelper.CalcIfUnreachablePos();
|
||||
float num2;
|
||||
float num3;
|
||||
|
||||
num2 = 1.095f;
|
||||
num3 = Utils.FastMax(0.7f, num2 - 0.35f);
|
||||
|
||||
float num4 = num3 * num3;
|
||||
float num5 = 4f;
|
||||
if (this.theEntity.IsFeral)
|
||||
{
|
||||
num5 = 8f;
|
||||
}
|
||||
num5 = base.RandomFloat * num5;
|
||||
float targetXZDistanceSq = this.GetTargetXZDistanceSq(num5);
|
||||
float num6 = vector2.y - this.theEntity.position.y;
|
||||
float num7 = Utils.FastAbs(num6);
|
||||
bool flag = targetXZDistanceSq <= num4 && num7 < 1f;
|
||||
if (!flag)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 9");
|
||||
if (num7 < 3f && !PathFinderThread.Instance.IsCalculatingPath(this.theEntity.entityId))
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 10");
|
||||
PathEntity path = this.theEntity.navigator.getPath();
|
||||
if (path != null && path.NodeCountRemaining() <= 2)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 11");
|
||||
this.pathCounter = 0;
|
||||
}
|
||||
}
|
||||
int num = this.pathCounter - 1;
|
||||
this.pathCounter = num;
|
||||
if (num <= 0 && this.theEntity.CanNavigatePath() && !PathFinderThread.Instance.IsCalculatingPath(this.theEntity.entityId))
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 12");
|
||||
this.pathCounter = 6 + base.GetRandom(10);
|
||||
Vector3 moveToLocation = EntityUtilities.GetMoveToLocation(this.theEntity, this.targetPlayer.position,5);
|
||||
if (moveToLocation.y - this.theEntity.position.y < -8f)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 13");
|
||||
this.pathCounter += 40;
|
||||
if (base.RandomFloat < 0.2f)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 14");
|
||||
this.seekPosOffset.x = this.seekPosOffset.x + (base.RandomFloat * 0.6f - 0.3f);
|
||||
this.seekPosOffset.y = this.seekPosOffset.y + (base.RandomFloat * 0.6f - 0.3f);
|
||||
}
|
||||
moveToLocation.x += this.seekPosOffset.x;
|
||||
moveToLocation.z += this.seekPosOffset.y;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 15");
|
||||
float num8 = (moveToLocation - this.theEntity.position).magnitude - 5f;
|
||||
if (num8 > 0f)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 16");
|
||||
if (num8 > 60f)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 17");
|
||||
num8 = 60f;
|
||||
}
|
||||
this.pathCounter += (int)(num8 / 20f * 20f);
|
||||
}
|
||||
}
|
||||
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update $IsBackingUp: " + this.theEntity.Buffs.GetCustomVar("$IsBackingUp"));
|
||||
//this.theEntity.FindPath(moveToLocation, this.theEntity.GetMoveSpeedAggro(), false, this);
|
||||
}
|
||||
}
|
||||
if (this.theEntity.Climbing)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 18");
|
||||
return;
|
||||
}
|
||||
/*if (!flag)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 20");
|
||||
if (this.theEntity.navigator.noPathAndNotPlanningOne() && this.pathCounter > 0 && num6 < 2.1f)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 21");
|
||||
Vector3 moveToLocation2 = EntityUtilities.GetMoveToLocation(this.theEntity, this.targetPlayer.position);
|
||||
this.theEntity.moveHelper.SetMoveTo(moveToLocation2, true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 22");
|
||||
//this.theEntity.navigator?.clearPath();
|
||||
this.theEntity.moveHelper.Stop();
|
||||
this.pathCounter = 0;
|
||||
}*/
|
||||
}
|
||||
|
||||
private float GetTargetXZDistanceSq(float estimatedTicks)
|
||||
{
|
||||
Vector3 vector = this.targetPlayer.position;
|
||||
vector += this.entityPlayerVel * estimatedTicks;
|
||||
Vector3 vector2 = this.theEntity.position + this.theEntity.motion * estimatedTicks - vector;
|
||||
vector2.y = 0f;
|
||||
return vector2.sqrMagnitude;
|
||||
}
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
this.targetPlayer = null;
|
||||
}
|
||||
|
||||
private EntityPlayer targetPlayer;
|
||||
private Vector3 entityPlayerVel;
|
||||
private Vector3 entityPlayerPos;
|
||||
private int relocateTicks;
|
||||
private int OwnerID = 0;
|
||||
private int pathCounter;
|
||||
private Vector2 seekPosOffset;
|
||||
}
|
||||
333
Scripts/EAI/NPCs/V2/EAIMoveToTargetCompanion.cs
Normal file
333
Scripts/EAI/NPCs/V2/EAIMoveToTargetCompanion.cs
Normal file
@@ -0,0 +1,333 @@
|
||||
using GamePath;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Xml;
|
||||
using UnityEngine.Scripting;
|
||||
using static BlendCycleTimer;
|
||||
using static EntityDrone;
|
||||
|
||||
[Preserve]
|
||||
public class EAIMoveToTargetCompanion : EAITarget
|
||||
{
|
||||
public override void Init(EntityAlive _theEntity)
|
||||
{
|
||||
base.Init(_theEntity, 25f, true);
|
||||
this.MutexBits = 1;
|
||||
}
|
||||
|
||||
public override void Start()
|
||||
{
|
||||
this.relocateTicks = 0;
|
||||
this.pathCounter = 0;
|
||||
base.Start();
|
||||
}
|
||||
|
||||
public bool NPCEAICanProceed()
|
||||
{
|
||||
bool result = true;
|
||||
|
||||
this.OwnerID = (int)this.theEntity.Buffs.GetCustomVar("$Leader");
|
||||
|
||||
if (this.OwnerID == 0)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-NPCEAICanProceed 0");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.Buffs.GetCustomVar("onMission") == 1f ||
|
||||
this.theEntity.Buffs.GetCustomVar("$FR_NPC_Respawn") == 1f ||
|
||||
this.theEntity.Buffs.GetCustomVar("$FR_NPC_Hidden") == 1f
|
||||
)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-NPCEAICanProceed 1");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.owner == null)
|
||||
{
|
||||
this.owner = (EntityAlive)EntityUtilities.GetOwner(this.theEntity.entityId);
|
||||
}
|
||||
|
||||
EntityUtilities.CheckDistanceToLeader(this.theEntity, this.owner);
|
||||
|
||||
this.entityTarget = this.theEntity.GetAttackTarget();
|
||||
|
||||
if (this.entityTarget == null)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-NPCEAICanProceed 2a");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.owner != null && !this.owner.CanEntityBeSeen(this.entityTarget) && !this.theEntity.CanEntityBeSeen(this.entityTarget))
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-NPCEAICanProceed 2b");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.CanEntityBeSeen(this.entityTarget))
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-NPCEAICanProceed 2c");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.emodel.IsRagdollActive)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-NPCEAICanProceed 3");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.sleepingOrWakingUp || this.theEntity.bodyDamage.CurrentStun != EnumEntityStunType.None || (this.theEntity.Jumping && !this.theEntity.isSwimming))
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-NPCEAICanProceed 4");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (((EntityAliveV2)(this.theEntity)).currentOrder != (int)EntityUtilities.Orders.Follow &&
|
||||
((EntityAliveV2)(this.theEntity)).currentOrder != (int)EntityUtilities.Orders.Guard)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-CanExecute IS NOT FOLLOWING");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool stopAttacking = this.theEntity.Buffs.HasBuff("FuriousRamsayBuffPauseAttack") ||
|
||||
this.theEntity.Buffs.HasBuff("buffNPCModStopAttacking") ||
|
||||
this.theEntity.Buffs.HasBuff("FuriousRamsayStandStill");
|
||||
|
||||
if (stopAttacking)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-NPCEAICanProceed 5");
|
||||
this.theEntity.SetRevengeTarget(null);
|
||||
this.theEntity.SetAttackTarget(null, 0);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.sleepingOrWakingUp || this.theEntity.bodyDamage.CurrentStun != EnumEntityStunType.None)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-NPCEAICanProceed 6");
|
||||
return false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public override bool CanExecute()
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-CanExecute START");
|
||||
|
||||
if (!NPCEAICanProceed())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.owner == null)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-CanExecute 2");
|
||||
this.OwnerID = (int)this.theEntity.Buffs.GetCustomVar("$Leader");
|
||||
|
||||
if (this.OwnerID > 0)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-CanExecute this.OwnerID: " + this.OwnerID);
|
||||
|
||||
EntityAlive entityPlayer = (EntityAlive)this.theEntity.world.GetEntity(this.OwnerID);
|
||||
if (entityPlayer != null)
|
||||
{
|
||||
this.owner = entityPlayer;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//Log.Out("EAIMoveToTargetCompanion-CanExecute this.theEntity.GetAttackTarget: " + this.theEntity.GetAttackTarget().EntityClass.entityClassName);
|
||||
return false;
|
||||
}
|
||||
|
||||
public override bool Continue()
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Continue START");
|
||||
if (!NPCEAICanProceed())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (pathCounter == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update START");
|
||||
|
||||
if (!NPCEAICanProceed())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.owner == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
EntityUtilities.CheckForClosedDoor(this.theEntity);
|
||||
|
||||
if (this.relocateTicks > 0)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update 2");
|
||||
if (!this.theEntity.navigator.noPathAndNotPlanningOne())
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update 3");
|
||||
this.relocateTicks--;
|
||||
this.theEntity.moveHelper.SetFocusPos(this.entityTarget.position);
|
||||
return;
|
||||
}
|
||||
this.relocateTicks = 0;
|
||||
}
|
||||
|
||||
Vector3 vector2 = this.entityTarget.position;
|
||||
|
||||
Vector3 a = theEntity.position - vector2;
|
||||
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update entityTargetPosn: " + vector2);
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update a: " + a);
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update a.sqrMagnitude: " + a.sqrMagnitude);
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update this.OwnerID: " + this.theEntity.Buffs.GetCustomVar("$Leader"));
|
||||
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update SetLookPosition");
|
||||
theEntity.SetLookPosition(vector2);
|
||||
theEntity.RotateTo(vector2.x, vector2.y + 2, vector2.z, 8f, 8f);
|
||||
|
||||
if (a.sqrMagnitude < 1f)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update 6");
|
||||
this.entityPlayerVel = this.entityPlayerVel * 0.7f + a * 0.3f;
|
||||
}
|
||||
//this.entityPlayerPos = vector2;
|
||||
|
||||
this.theEntity.moveHelper.CalcIfUnreachablePos();
|
||||
float num2;
|
||||
float num3;
|
||||
|
||||
num2 = 1.095f;
|
||||
num3 = Utils.FastMax(0.7f, num2 - 0.35f);
|
||||
|
||||
float num4 = num3 * num3;
|
||||
float num5 = 4f;
|
||||
if (this.theEntity.IsFeral)
|
||||
{
|
||||
num5 = 8f;
|
||||
}
|
||||
num5 = base.RandomFloat * num5;
|
||||
float targetXZDistanceSq = this.GetTargetXZDistanceSq(num5);
|
||||
float num6 = vector2.y - this.theEntity.position.y;
|
||||
float num7 = Utils.FastAbs(num6);
|
||||
bool flag = targetXZDistanceSq <= num4 && num7 < 1f;
|
||||
if (!flag)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update 9");
|
||||
if (num7 < 3f && !PathFinderThread.Instance.IsCalculatingPath(this.theEntity.entityId))
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update 10");
|
||||
PathEntity path = this.theEntity.navigator.getPath();
|
||||
if (path != null && path.NodeCountRemaining() <= 2)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update 11");
|
||||
this.pathCounter = 0;
|
||||
}
|
||||
}
|
||||
int num = this.pathCounter - 1;
|
||||
this.pathCounter = num;
|
||||
if (num <= 0 && this.theEntity.CanNavigatePath() && !PathFinderThread.Instance.IsCalculatingPath(this.theEntity.entityId))
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update 12");
|
||||
this.pathCounter = 6 + base.GetRandom(10);
|
||||
Vector3 moveToLocation = EntityUtilities.GetMoveToLocation(this.theEntity, this.entityTarget.position, 5);
|
||||
if (moveToLocation.y - this.theEntity.position.y < -8f)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update 13");
|
||||
this.pathCounter += 40;
|
||||
if (base.RandomFloat < 0.2f)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update 14");
|
||||
this.seekPosOffset.x = this.seekPosOffset.x + (base.RandomFloat * 0.6f - 0.3f);
|
||||
this.seekPosOffset.y = this.seekPosOffset.y + (base.RandomFloat * 0.6f - 0.3f);
|
||||
}
|
||||
moveToLocation.x += this.seekPosOffset.x;
|
||||
moveToLocation.z += this.seekPosOffset.y;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update 15");
|
||||
float num8 = (moveToLocation - this.theEntity.position).magnitude - 5f;
|
||||
if (num8 > 0f)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update 16");
|
||||
if (num8 > 60f)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update 17");
|
||||
num8 = 60f;
|
||||
}
|
||||
this.pathCounter += (int)(num8 / 20f * 20f);
|
||||
}
|
||||
}
|
||||
this.theEntity.FindPath(moveToLocation, this.theEntity.GetMoveSpeedAggro(), false, this);
|
||||
}
|
||||
}
|
||||
if (this.theEntity.Climbing)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update 18");
|
||||
return;
|
||||
}
|
||||
if (!flag)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update 20");
|
||||
if (this.theEntity.navigator.noPathAndNotPlanningOne() && this.pathCounter > 0 && num6 < 2.1f)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update 21");
|
||||
Vector3 moveToLocation2 = EntityUtilities.GetMoveToLocation(this.theEntity, this.entityTarget.position, 5);
|
||||
this.theEntity.moveHelper.SetMoveTo(moveToLocation2, true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update 22");
|
||||
this.theEntity.motion = Vector3.zero;
|
||||
this.theEntity.navigator?.clearPath();
|
||||
this.theEntity.moveHelper?.Stop();
|
||||
this.theEntity.speedForward = 0;
|
||||
this.theEntity.speedStrafe = 0;
|
||||
//this.theEntity.navigator?.clearPath();
|
||||
//this.theEntity.moveHelper.Stop();
|
||||
this.pathCounter = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private float GetTargetXZDistanceSq(float estimatedTicks)
|
||||
{
|
||||
Vector3 vector = this.entityTarget.position;
|
||||
vector += this.entityPlayerVel * estimatedTicks;
|
||||
Vector3 vector2 = this.theEntity.position + this.theEntity.motion * estimatedTicks - vector;
|
||||
vector2.y = 0f;
|
||||
return vector2.sqrMagnitude;
|
||||
}
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
this.entityTarget = null;
|
||||
this.owner = null;
|
||||
}
|
||||
|
||||
private EntityAlive owner;
|
||||
private EntityAlive entityTarget;
|
||||
private Vector3 entityPlayerVel;
|
||||
//private Vector3 entityPlayerPos;
|
||||
private int relocateTicks;
|
||||
private int OwnerID = 0;
|
||||
private int pathCounter;
|
||||
private Vector2 seekPosOffset;
|
||||
}
|
||||
231
Scripts/EAI/NPCs/V2/EAISetAsTargetIfHurtCompanion.cs
Normal file
231
Scripts/EAI/NPCs/V2/EAISetAsTargetIfHurtCompanion.cs
Normal file
@@ -0,0 +1,231 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Scripting;
|
||||
|
||||
[Preserve]
|
||||
public class EAISetAsTargetIfHurtCompanion : EAITarget
|
||||
{
|
||||
public override void Init(EntityAlive _theEntity)
|
||||
{
|
||||
base.Init(_theEntity, 0f, false);
|
||||
this.MutexBits = 1;
|
||||
}
|
||||
|
||||
public override void SetData(DictionarySave<string, string> data)
|
||||
{
|
||||
base.SetData(data);
|
||||
this.targetClasses = new List<EAISetAsTargetIfHurtCompanion.TargetClass>();
|
||||
string text;
|
||||
if (data.TryGetValue("class", out text))
|
||||
{
|
||||
string[] array = text.Split(',', StringSplitOptions.None);
|
||||
for (int i = 0; i < array.Length; i++)
|
||||
{
|
||||
EAISetAsTargetIfHurtCompanion.TargetClass item = default(EAISetAsTargetIfHurtCompanion.TargetClass);
|
||||
item.type = EntityFactory.GetEntityType(array[i]);
|
||||
this.targetClasses.Add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool NPCEAICanProceed()
|
||||
{
|
||||
bool result = true;
|
||||
|
||||
if (this.theEntity.Buffs.GetCustomVar("onMission") == 1f ||
|
||||
this.theEntity.Buffs.GetCustomVar("$FR_NPC_Respawn") == 1f ||
|
||||
this.theEntity.Buffs.GetCustomVar("$FR_NPC_Hidden") == 1f
|
||||
)
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-NPCEAICanProceed 1");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool stopAttacking = this.theEntity.Buffs.HasBuff("FuriousRamsayBuffPauseAttack") ||
|
||||
this.theEntity.Buffs.HasBuff("buffNPCModStopAttacking") ||
|
||||
this.theEntity.Buffs.HasBuff("FuriousRamsayStandStill");
|
||||
|
||||
if (stopAttacking)
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-NPCEAICanProceed 2");
|
||||
this.theEntity.SetRevengeTarget(null);
|
||||
this.theEntity.SetAttackTarget(null, 0);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public override bool CanExecute()
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-CanExecute START");
|
||||
|
||||
if (!NPCEAICanProceed())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
EntityAlive revengeTarget = this.theEntity.GetRevengeTarget();
|
||||
EntityAlive attackTarget = this.theEntity.GetAttackTarget();
|
||||
|
||||
if (revengeTarget == null)
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-CanExecute revengeTarget IS NULL");
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-CanExecute revengeTarget: " + revengeTarget.EntityClass.entityClassName);
|
||||
}
|
||||
if (attackTarget == null)
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-CanExecute attackTarget IS NULL");
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-CanExecute attackTarget: " + attackTarget.EntityClass.entityClassName);
|
||||
}
|
||||
|
||||
bool bIsValidTarget = true;
|
||||
|
||||
if (revengeTarget)
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtRebirth-CanExecute revengeTarget.EntityName: " + revengeTarget.EntityName);
|
||||
//Log.Out("EAISetAsTargetIfHurtRebirth-CanExecute revengeTarget.entityType: " + revengeTarget.entityType);
|
||||
//Log.Out("EAISetAsTargetIfHurtRebirth-CanExecute this.theEntity.entityType: " + this.theEntity.entityType);
|
||||
|
||||
bIsValidTarget = RebirthUtilities.VerifyFactionStanding(this.theEntity, revengeTarget); //revengeTarget.entityType != this.theEntity.entityType;
|
||||
//Log.Out("EAISetAsTargetIfHurtRebirth-CanExecute bIsValidTarget: " + bIsValidTarget);
|
||||
}
|
||||
|
||||
if (revengeTarget && revengeTarget != attackTarget && bIsValidTarget)
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-CanExecute 1");
|
||||
if (this.targetClasses != null)
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-CanExecute 2");
|
||||
bool flag = false;
|
||||
Type type = revengeTarget.GetType();
|
||||
for (int i = 0; i < this.targetClasses.Count; i++)
|
||||
{
|
||||
EAISetAsTargetIfHurtCompanion.TargetClass targetClass = this.targetClasses[i];
|
||||
if (targetClass.type != null && targetClass.type.IsAssignableFrom(type))
|
||||
{
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!flag)
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-CanExecute 3");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (attackTarget != null && attackTarget.IsAlive() && base.RandomFloat < 0.66f)
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-CanExecute 4");
|
||||
this.theEntity.SetRevengeTarget(null);
|
||||
return false;
|
||||
}
|
||||
if (base.check(revengeTarget))
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-CanExecute 5");
|
||||
return true;
|
||||
}
|
||||
Vector3 vector = this.theEntity.position - revengeTarget.position;
|
||||
float num = EntityClass.list[this.theEntity.entityClass].SearchArea * 0.5f;
|
||||
vector = revengeTarget.position + vector.normalized * (num * 0.5f);
|
||||
Vector3 vector2 = this.manager.random.RandomOnUnitSphere * num;
|
||||
vector.x += vector2.x;
|
||||
vector.z += vector2.z;
|
||||
Vector3i vector3i = World.worldToBlockPos(vector);
|
||||
int height = (int)this.theEntity.world.GetHeight(vector3i.x, vector3i.z);
|
||||
if (height > 0)
|
||||
{
|
||||
vector.y = (float)height;
|
||||
}
|
||||
int num2 = this.theEntity.CalcInvestigateTicks(1200, revengeTarget);
|
||||
this.theEntity.SetInvestigatePosition(vector, num2, true);
|
||||
if (this.theEntity.entityType == EntityType.Zombie)
|
||||
{
|
||||
num2 /= 6;
|
||||
}
|
||||
this.theEntity.SetAlertTicks(num2);
|
||||
this.theEntity.SetRevengeTarget(null);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void Start()
|
||||
{
|
||||
this.theEntity.SetAttackTarget(this.theEntity.GetRevengeTarget(), 400);
|
||||
this.viewAngleSave = this.theEntity.GetMaxViewAngle();
|
||||
this.theEntity.SetMaxViewAngle(270f);
|
||||
this.viewAngleRestoreCounter = 100;
|
||||
base.Start();
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
if (!NPCEAICanProceed())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-Update START");
|
||||
|
||||
if (this.viewAngleRestoreCounter > 0)
|
||||
{
|
||||
this.viewAngleRestoreCounter--;
|
||||
if (this.viewAngleRestoreCounter == 0)
|
||||
{
|
||||
this.restoreViewAngle();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Continue()
|
||||
{
|
||||
if (!NPCEAICanProceed())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-Continue START");
|
||||
|
||||
bool revengeTargetIsNull = (this.theEntity.GetRevengeTarget() != null);
|
||||
bool revengeAndAttackTargetDifferent = (this.theEntity.GetAttackTarget() != this.theEntity.GetRevengeTarget());
|
||||
bool baseContinue = base.Continue();
|
||||
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-Continue revengeTargetIsNull: " + revengeTargetIsNull);
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-Continue revengeAndAttackTargetDifferent: " + revengeAndAttackTargetDifferent);
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-Continue baseContinue: " + baseContinue);
|
||||
|
||||
return (!revengeTargetIsNull || !revengeAndAttackTargetDifferent) && baseContinue;
|
||||
}
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
base.Reset();
|
||||
this.restoreViewAngle();
|
||||
}
|
||||
|
||||
private void restoreViewAngle()
|
||||
{
|
||||
if (this.viewAngleSave > 0f)
|
||||
{
|
||||
this.theEntity.SetMaxViewAngle(this.viewAngleSave);
|
||||
this.viewAngleSave = 0f;
|
||||
this.viewAngleRestoreCounter = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private List<EAISetAsTargetIfHurtCompanion.TargetClass> targetClasses;
|
||||
private float viewAngleSave;
|
||||
private int viewAngleRestoreCounter;
|
||||
private struct TargetClass
|
||||
{
|
||||
public Type type;
|
||||
}
|
||||
}
|
||||
362
Scripts/EAI/NPCs/V2/EAISetNearestEntityAsTargetCompanion.cs
Normal file
362
Scripts/EAI/NPCs/V2/EAISetNearestEntityAsTargetCompanion.cs
Normal file
@@ -0,0 +1,362 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Scripting;
|
||||
using static EntityDrone;
|
||||
using static UnityEngine.UI.GridLayoutGroup;
|
||||
|
||||
[Preserve]
|
||||
public class EAISetNearestEntityAsTargetCompanion : EAITarget
|
||||
{
|
||||
public override void Init(EntityAlive _theEntity)
|
||||
{
|
||||
Log.Out("EAISetNearestEntityAsTargetCompanion-Init START");
|
||||
base.Init(_theEntity, 25f, true);
|
||||
this.MutexBits = 1;
|
||||
this.sorter = new EAISetNearestEntityAsTargetSorter(_theEntity);
|
||||
}
|
||||
|
||||
public override void SetData(DictionarySave<string, string> data)
|
||||
{
|
||||
Log.Out("EAISetNearestEntityAsTargetCompanion-SetData START");
|
||||
base.SetData(data);
|
||||
this.targetClasses = new List<EAISetNearestEntityAsTargetCompanion.TargetClass>();
|
||||
string text;
|
||||
if (data.TryGetValue("class", out text))
|
||||
{
|
||||
Log.Out("EAISetNearestEntityAsTargetCompanion-SetData 1");
|
||||
string[] array = text.Split(',', StringSplitOptions.None);
|
||||
for (int i = 0; i < array.Length; i += 3)
|
||||
{
|
||||
Log.Out("EAISetNearestEntityAsTargetCompanion-SetData i: " + i);
|
||||
EAISetNearestEntityAsTargetCompanion.TargetClass targetClass;
|
||||
targetClass.type = EntityFactory.GetEntityType(array[i]);
|
||||
targetClass.hearDistMax = 0f;
|
||||
if (i + 1 < array.Length)
|
||||
{
|
||||
Log.Out("EAISetNearestEntityAsTargetCompanion-SetData 2");
|
||||
targetClass.hearDistMax = StringParsers.ParseFloat(array[i + 1], 0, -1, NumberStyles.Any);
|
||||
}
|
||||
if (targetClass.hearDistMax == 0f)
|
||||
{
|
||||
Log.Out("EAISetNearestEntityAsTargetCompanion-SetData 3");
|
||||
targetClass.hearDistMax = 50f;
|
||||
}
|
||||
targetClass.seeDistMax = 0f;
|
||||
if (i + 2 < array.Length)
|
||||
{
|
||||
Log.Out("EAISetNearestEntityAsTargetCompanion-SetData 4");
|
||||
targetClass.seeDistMax = StringParsers.ParseFloat(array[i + 2], 0, -1, NumberStyles.Any);
|
||||
}
|
||||
if (targetClass.type == typeof(EntityPlayer))
|
||||
{
|
||||
Log.Out("EAISetNearestEntityAsTargetCompanion-SetData 5");
|
||||
this.playerTargetClassIndex = this.targetClasses.Count;
|
||||
}
|
||||
this.targetClasses.Add(targetClass);
|
||||
}
|
||||
Log.Out("EAISetNearestEntityAsTargetCompanion-SetData 6");
|
||||
}
|
||||
}
|
||||
|
||||
public bool NPCEAICanProceed()
|
||||
{
|
||||
bool result = true;
|
||||
|
||||
Log.Out("EAISetNearestEntityAsTargetCompanion-NPCEAICanProceed START");
|
||||
|
||||
if (this.theEntity.GetAttackTarget() != null)
|
||||
{
|
||||
Log.Out("EAISetNearestEntityAsTargetCompanion-NPCEAICanProceed ALREADY HAVE AN ATTACK TARGET");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.Buffs.GetCustomVar("onMission") == 1f ||
|
||||
this.theEntity.Buffs.GetCustomVar("$FR_NPC_Respawn") == 1f ||
|
||||
this.theEntity.Buffs.GetCustomVar("$FR_NPC_Hidden") == 1f
|
||||
)
|
||||
{
|
||||
Log.Out("EAISetNearestEntityAsTargetCompanion-NPCEAICanProceed 1");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool stopAttacking = this.theEntity.Buffs.HasBuff("FuriousRamsayBuffPauseAttack") ||
|
||||
this.theEntity.Buffs.HasBuff("buffNPCModStopAttacking") ||
|
||||
this.theEntity.Buffs.HasBuff("FuriousRamsayStandStill");
|
||||
|
||||
if (stopAttacking)
|
||||
{
|
||||
Log.Out("EAISetNearestEntityAsTargetCompanion-NPCEAICanProceed 2");
|
||||
this.theEntity.SetRevengeTarget(null);
|
||||
this.theEntity.SetAttackTarget(null, 0);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public override bool CanExecute()
|
||||
{
|
||||
Log.Out("EAISetNearestEntityAsTargetCompanion-CanExecute START");
|
||||
|
||||
if (!NPCEAICanProceed())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
this.FindTarget();
|
||||
|
||||
if (!this.closeTargetEntity)
|
||||
{
|
||||
Log.Out($"! closeTargetEntity: {closeTargetEntity}");
|
||||
return false;
|
||||
}
|
||||
this.targetEntity = this.closeTargetEntity;
|
||||
this.targetPlayer = (this.closeTargetEntity as EntityPlayer);
|
||||
|
||||
Log.Out("EAISetNearestEntityAsTargetCompanion-CanExecute this.targetEntity: " + this.targetEntity.EntityClass.entityClassName);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void FindTarget()
|
||||
{
|
||||
Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget START");
|
||||
this.closeTargetDist = float.MaxValue;
|
||||
this.closeTargetEntity = null;
|
||||
float seeDistance = RebirthVariables.customDistanceHunting; //this.theEntity.GetSeeDistance();
|
||||
|
||||
if (this.theEntity.Buffs.HasBuff("buffNPCModFullControlMode") && ((EntityAliveV2)(this.theEntity)).currentOrder == (int)EntityUtilities.Orders.Follow)
|
||||
{
|
||||
seeDistance = RebirthVariables.customDistanceFullControl;
|
||||
}
|
||||
|
||||
Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget this.targetClasses.Count " + this.targetClasses.Count);
|
||||
for (int i = 0; i < this.targetClasses.Count; i++)
|
||||
{
|
||||
Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget i: " + i);
|
||||
EAISetNearestEntityAsTargetCompanion.TargetClass targetClass = this.targetClasses[i];
|
||||
float num = 100;
|
||||
Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget seeDistance " + seeDistance);
|
||||
Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget targetClass.seeDistMax " + targetClass.seeDistMax);
|
||||
Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget num " + num);
|
||||
|
||||
Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget this.theEntity.IsSleeping " + this.theEntity.IsSleeping);
|
||||
Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget this.theEntity.HasInvestigatePosition " + this.theEntity.HasInvestigatePosition);
|
||||
|
||||
bool hasInvestigatePosition = false; // this.theEntity.HasInvestigatePosition;
|
||||
|
||||
if (!this.theEntity.IsSleeping && !hasInvestigatePosition)
|
||||
{
|
||||
Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget 1");
|
||||
this.theEntity.world.GetEntitiesInBounds(targetClass.type, BoundsUtils.ExpandBounds(this.theEntity.boundingBox, num, num, num), EAISetNearestEntityAsTargetCompanion.list);
|
||||
EAISetNearestEntityAsTargetCompanion.list.Sort(this.sorter);
|
||||
int j = 0;
|
||||
Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget EAISetNearestEntityAsTargetCompanion.list.Count " + EAISetNearestEntityAsTargetCompanion.list.Count);
|
||||
while (j < EAISetNearestEntityAsTargetCompanion.list.Count)
|
||||
{
|
||||
EntityAlive entityAlive = (EntityAlive)EAISetNearestEntityAsTargetCompanion.list[j];
|
||||
|
||||
Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget j: " + j + " / entityAlive: " + entityAlive.EntityClass.entityClassName);
|
||||
|
||||
//if (!(entityAlive is EntityDrone))
|
||||
{
|
||||
Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget 2");
|
||||
bool check = base.check(entityAlive);
|
||||
bool shouldAttack = RebirthUtilities.VerifyFactionStanding(this.theEntity, entityAlive);
|
||||
|
||||
if (!check && entityAlive.entityId != this.theEntity.entityId && shouldAttack)
|
||||
{
|
||||
int OwnerID = (int)this.theEntity.Buffs.GetCustomVar("$Leader");
|
||||
|
||||
if (OwnerID > 0)
|
||||
{
|
||||
Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget HAS OWNER");
|
||||
EntityPlayer entityPlayer = (EntityPlayer)this.theEntity.world.GetEntity(OwnerID);
|
||||
if (entityPlayer != null)
|
||||
{
|
||||
Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget FOUND OWNER");
|
||||
if (entityPlayer.CanEntityBeSeen(entityAlive))
|
||||
{
|
||||
check = true;
|
||||
Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget OWNER CAN SEE TARGET: " + entityAlive.EntityClass.entityClassName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget check: " + check);
|
||||
|
||||
if (check && (!entityAlive.IsSleeping || entityAlive is EntityAnimalSnake))
|
||||
{
|
||||
Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget entityAlive.EntityClass.entityClassName: " + entityAlive.EntityClass.entityClassName);
|
||||
float distance = this.theEntity.GetDistance(entityAlive);
|
||||
|
||||
Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget this.closeTargetDist: " + this.closeTargetDist);
|
||||
Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget distance: " + distance);
|
||||
|
||||
bool bypassDistance = (entityAlive.Buffs.GetCustomVar("$FuriousRamsayAttacking") == 1f ||
|
||||
entityAlive.Buffs.GetCustomVar("$FuriousRamsayAttacked") == 1f ||
|
||||
this.theEntity.Buffs.HasBuff("buffNPCModThreatControlMode")
|
||||
);
|
||||
|
||||
if (bypassDistance && distance > 50)
|
||||
{
|
||||
bypassDistance = false;
|
||||
}
|
||||
|
||||
Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget bypassDistance: " + bypassDistance);
|
||||
Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget distance: " + distance);
|
||||
Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget seeDistance: " + seeDistance);
|
||||
|
||||
if (bypassDistance || distance < seeDistance)
|
||||
{
|
||||
Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget A");
|
||||
this.closeTargetDist = distance;
|
||||
this.closeTargetEntity = entityAlive;
|
||||
this.lastSeenPos = entityAlive.position;
|
||||
|
||||
Log.Out($"EAI SetNearestEntityAsTargetCompanion - FindTarget entityAlive: {entityAlive.EntityClass.entityClassName}");
|
||||
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget B");
|
||||
int OwnerID = (int)this.theEntity.Buffs.GetCustomVar("$Leader");
|
||||
|
||||
Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget OwnerID: " + OwnerID);
|
||||
|
||||
EntityPlayer owner = null;
|
||||
|
||||
if (OwnerID > 0)
|
||||
{
|
||||
Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget HAS OWNER");
|
||||
EntityPlayer entityPlayer = (EntityPlayer)this.theEntity.world.GetEntity(OwnerID);
|
||||
if (entityPlayer != null)
|
||||
{
|
||||
Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget FOUND OWNER");
|
||||
owner = entityPlayer;
|
||||
}
|
||||
}
|
||||
|
||||
if (owner != null)
|
||||
{
|
||||
distance = owner.GetDistance(entityAlive);
|
||||
|
||||
Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget DISTANCE TO OWNER: " + distance);
|
||||
|
||||
if (distance < seeDistance + 5)
|
||||
{
|
||||
Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget OWNER distance: " + distance);
|
||||
|
||||
Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget entityAlive: " + entityAlive.EntityClass.entityClassName);
|
||||
|
||||
this.closeTargetDist = distance;
|
||||
this.closeTargetEntity = entityAlive;
|
||||
this.lastSeenPos = entityAlive.position;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
j++;
|
||||
}
|
||||
}
|
||||
}
|
||||
EAISetNearestEntityAsTargetCompanion.list.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
Log.Out($"FindTarget END - closeTargetEntity: {closeTargetEntity}");
|
||||
}
|
||||
|
||||
public override void Start()
|
||||
{
|
||||
Log.Out("EAISetNearestEntityAsTargetCompanion-Start START");
|
||||
this.theEntity.SetAttackTarget(this.targetEntity, 200);
|
||||
this.theEntity.ConditionalTriggerSleeperWakeUp();
|
||||
base.Start();
|
||||
}
|
||||
|
||||
public override bool Continue()
|
||||
{
|
||||
Log.Out("EAISetNearestEntityAsTargetCompanion-Continue START");
|
||||
|
||||
if (!NPCEAICanProceed())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.targetEntity.IsDead() || this.theEntity.distraction != null)
|
||||
{
|
||||
Log.Out("EAISetNearestEntityAsTargetCompanion-Continue 5");
|
||||
if (this.theEntity.GetAttackTarget() == this.targetEntity)
|
||||
{
|
||||
Log.Out("SetNearestEntityAsTarget - Continue - GetAttackTarget() == this.targetEntity and isDead or distraction not null");
|
||||
this.theEntity.SetAttackTarget(null, 0);
|
||||
}
|
||||
Log.Out($"returning false here");
|
||||
return false;
|
||||
}
|
||||
|
||||
this.findTime += 0.05f;
|
||||
|
||||
if (this.findTime > 2f)
|
||||
{
|
||||
Log.Out("EAISetNearestEntityAsTargetCompanion-Continue 7");
|
||||
this.findTime = 0f;
|
||||
this.FindTarget();
|
||||
if (this.closeTargetEntity && this.closeTargetEntity != this.targetEntity)
|
||||
{
|
||||
Log.Out("EAISetNearestEntityAsTargetCompanion-Continue we have a close target and its not equal to targetEntity return false");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.theEntity.GetAttackTarget() != this.targetEntity)
|
||||
{
|
||||
Log.Out("EAISetNearestEntityAsTargetCompanion-Continue this.theEntity.GetAttackTarget() != this.targetEntity");
|
||||
return false;
|
||||
}
|
||||
|
||||
Log.Out("EAISetNearestEntityAsTargetCompanion-Continue 19");
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
Log.Out("EAISetNearestEntityAsTargetCompanion-Reset START");
|
||||
this.targetEntity = null;
|
||||
this.targetPlayer = null;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Format("{0}, {1}", base.ToString(), this.targetEntity ? this.targetEntity.EntityName : "");
|
||||
}
|
||||
|
||||
private const float cHearDistMax = 50f;
|
||||
private List<EAISetNearestEntityAsTargetCompanion.TargetClass> targetClasses;
|
||||
private int playerTargetClassIndex = -1;
|
||||
private float closeTargetDist;
|
||||
private EntityAlive closeTargetEntity;
|
||||
private EntityAlive targetEntity;
|
||||
private EntityPlayer targetPlayer;
|
||||
private Vector3 lastSeenPos;
|
||||
private float findTime;
|
||||
private float senseSoundTime;
|
||||
private EAISetNearestEntityAsTargetSorter sorter;
|
||||
private static List<Entity> list = new List<Entity>();
|
||||
private struct TargetClass
|
||||
{
|
||||
public Type type;
|
||||
public float hearDistMax;
|
||||
public float seeDistMax;
|
||||
}
|
||||
}
|
||||
111
Scripts/EAI/NPCs/V2/EAIWanderCompanion.cs
Normal file
111
Scripts/EAI/NPCs/V2/EAIWanderCompanion.cs
Normal file
@@ -0,0 +1,111 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Scripting;
|
||||
|
||||
[Preserve]
|
||||
public class EAIWanderCompanion : EAIWander
|
||||
{
|
||||
public bool NPCEAICanProceed(bool skipTargetVerification = false)
|
||||
{
|
||||
if (this.theEntity.Buffs.GetCustomVar("$Leader") > 0f)
|
||||
{
|
||||
//Log.Out("EAIWanderCompanion-NPCEAICanProceed 1");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (((EntityAliveV2)(this.theEntity)).currentOrder > 0)
|
||||
{
|
||||
//Log.Out("EAIWanderCompanion-NPCEAICanProceed 1a");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.Buffs.GetCustomVar("onMission") == 1f ||
|
||||
this.theEntity.Buffs.GetCustomVar("$FR_NPC_Respawn") == 1f ||
|
||||
this.theEntity.Buffs.GetCustomVar("$FR_NPC_Hidden") == 1f
|
||||
)
|
||||
{
|
||||
//Log.Out("EAIWanderCompanion-NPCEAICanProceed 1b");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.GetAttackTarget() != null)
|
||||
{
|
||||
//Log.Out("EAIWanderCompanion-NPCEAICanProceed 2");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.Buffs.HasBuff("buffTalkingTo"))
|
||||
{
|
||||
//Log.Out("EAIWanderCompanion-NPCEAICanProceed 3");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.sleepingOrWakingUp)
|
||||
{
|
||||
//Log.Out("EAIWanderCompanion-NPCEAICanProceed 4");
|
||||
return false;
|
||||
}
|
||||
if (this.theEntity.GetTicksNoPlayerAdjacent() >= 120)
|
||||
{
|
||||
//Log.Out("EAIWanderCompanion-NPCEAICanProceed 5");
|
||||
return false;
|
||||
}
|
||||
if (this.theEntity.bodyDamage.CurrentStun != EnumEntityStunType.None)
|
||||
{
|
||||
//Log.Out("EAIWanderCompanion-NPCEAICanProceed 6");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool CanExecute()
|
||||
{
|
||||
if (!NPCEAICanProceed())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.sleepingOrWakingUp)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (this.theEntity.GetTicksNoPlayerAdjacent() >= 120)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (this.theEntity.bodyDamage.CurrentStun != EnumEntityStunType.None)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
int num = (int)(200f * this.executeWaitTime);
|
||||
if (base.GetRandom(1000) >= num)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void Start()
|
||||
{
|
||||
int num = 10;
|
||||
this.theEntity.FindPath(RandomPositionGenerator.Calc(this.theEntity, num, num), this.theEntity.GetMoveSpeed(), false, this);
|
||||
}
|
||||
|
||||
public override bool Continue()
|
||||
{
|
||||
if (!NPCEAICanProceed())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//Log.Out("EAIWanderCompanion-Continue this.theEntity.bodyDamage.CurrentStun == EnumEntityStunType.None: " + (this.theEntity.bodyDamage.CurrentStun == EnumEntityStunType.None));
|
||||
//Log.Out("EAIWanderCompanion-Continue this.theEntity.moveHelper.BlockedTime <= 0.3f: " + (this.theEntity.moveHelper.BlockedTime <= 0.3f));
|
||||
//Log.Out("EAIWanderCompanion-Continue !this.theEntity.navigator.noPathAndNotPlanningOne(): " + !this.theEntity.navigator.noPathAndNotPlanningOne());
|
||||
|
||||
bool result = this.theEntity.bodyDamage.CurrentStun == EnumEntityStunType.None && this.theEntity.moveHelper.BlockedTime <= 0.3f && !this.theEntity.navigator.noPathAndNotPlanningOne();
|
||||
|
||||
//Log.Out("EAIWanderCompanion-Continue result: " + result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
979
Scripts/EAI/NPCs/v1/EAIApproachAndAttackTargetCompanion.cs
Normal file
979
Scripts/EAI/NPCs/v1/EAIApproachAndAttackTargetCompanion.cs
Normal file
@@ -0,0 +1,979 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
using System.Xml.Linq;
|
||||
using GamePath;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Scripting;
|
||||
|
||||
[Preserve]
|
||||
public class EAIApproachAndAttackTargetCompanion : EAIBase
|
||||
{
|
||||
public override void Init(EntityAlive _theEntity)
|
||||
{
|
||||
base.Init(_theEntity);
|
||||
this.MutexBits = 3;
|
||||
this.executeDelay = 0.1f;
|
||||
}
|
||||
|
||||
public override void SetData(DictionarySave<string, string> data)
|
||||
{
|
||||
base.SetData(data);
|
||||
this.targetClasses = new List<EAIApproachAndAttackTargetCompanion.TargetClass>();
|
||||
string text;
|
||||
if (data.TryGetValue("class", out text))
|
||||
{
|
||||
string[] array = text.Split(',', StringSplitOptions.None);
|
||||
for (int i = 0; i < array.Length; i += 2)
|
||||
{
|
||||
EAIApproachAndAttackTargetCompanion.TargetClass targetClass = default(EAIApproachAndAttackTargetCompanion.TargetClass);
|
||||
targetClass.type = EntityFactory.GetEntityType(array[i]);
|
||||
targetClass.chaseTimeMax = 0f;
|
||||
if (i + 1 < array.Length)
|
||||
{
|
||||
targetClass.chaseTimeMax = StringParsers.ParseFloat(array[i + 1], 0, -1, NumberStyles.Any);
|
||||
}
|
||||
this.targetClasses.Add(targetClass);
|
||||
if (targetClass.type == typeof(EntityEnemyAnimal))
|
||||
{
|
||||
targetClass.type = typeof(EntityAnimalSnake);
|
||||
this.targetClasses.Add(targetClass);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool NPCEAICanProceed(bool skipTargetVerification = false)
|
||||
{
|
||||
bool result = true;
|
||||
|
||||
if (this.theEntity.Buffs.GetCustomVar("onMission") == 1f ||
|
||||
this.theEntity.Buffs.GetCustomVar("$FR_NPC_Respawn") == 1f ||
|
||||
this.theEntity.Buffs.GetCustomVar("$FR_NPC_Hidden") == 1f
|
||||
)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-NPCEAICanProceed 1");
|
||||
return false;
|
||||
}
|
||||
|
||||
this.entityTarget = this.theEntity.GetAttackTarget();
|
||||
|
||||
if (!skipTargetVerification && this.entityTarget == null)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-NPCEAICanProceed 2b");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.entityTarget != null)
|
||||
{
|
||||
if (this.entityTarget.IsDead())
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-NPCEAICanProceed 2c");
|
||||
this.theEntity.SetAttackTarget(null, 0);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!this.theEntity.CanEntityBeSeen(this.entityTarget))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-NPCEAICanProceed 2d");
|
||||
return false;
|
||||
}
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-NPCEAICanProceed 2e");
|
||||
bool shouldAttack = RebirthUtilities.VerifyFactionStanding(this.theEntity, this.entityTarget);
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-NPCEAICanProceed 2f, this.entityTarget: " + this.entityTarget.EntityClass.entityClassName);
|
||||
|
||||
if (!shouldAttack)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-NPCEAICanProceed 2g");
|
||||
//this.theEntity.SetAttackTarget(null, 0);
|
||||
//this.theEntity.SetRevengeTarget(null);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.theEntity.emodel.IsRagdollActive)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-NPCEAICanProceed 3");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.sleepingOrWakingUp || this.theEntity.bodyDamage.CurrentStun != EnumEntityStunType.None || (this.theEntity.Jumping && !this.theEntity.isSwimming))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-NPCEAICanProceed 4");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool stopAttacking = this.theEntity.Buffs.HasBuff("FuriousRamsayBuffPauseAttack") ||
|
||||
this.theEntity.Buffs.HasBuff("buffNPCModStopAttacking") ||
|
||||
this.theEntity.Buffs.HasBuff("FuriousRamsayStandStill");
|
||||
|
||||
if (stopAttacking)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-NPCEAICanProceed 5");
|
||||
this.theEntity.SetRevengeTarget(null);
|
||||
this.theEntity.SetAttackTarget(null, 0);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.sleepingOrWakingUp || this.theEntity.bodyDamage.CurrentStun != EnumEntityStunType.None)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-NPCEAICanProceed 6");
|
||||
return false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public override bool CanExecute()
|
||||
{
|
||||
CheckAnimator();
|
||||
backingUp = false;
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-CanExecute START");
|
||||
|
||||
if (!NPCEAICanProceed(true))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.targetPlayer == null)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-CanExecute 2");
|
||||
this.OwnerID = (int)this.theEntity.Buffs.GetCustomVar("$Leader");
|
||||
|
||||
if (this.OwnerID > 0)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-CanExecute this.OwnerID: " + this.OwnerID);
|
||||
|
||||
EntityPlayer entityPlayer = (EntityPlayer)this.theEntity.world.GetEntity(this.OwnerID);
|
||||
if (entityPlayer != null)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-CanExecute FOUND OWNER");
|
||||
this.targetPlayer = entityPlayer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.entityTarget != null)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-CanExecute this.entityTarget: " + this.entityTarget.EntityClass.entityClassName);
|
||||
}
|
||||
else
|
||||
{
|
||||
checkEntityPosition();
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-CanExecute NO ATTACK TARGET");
|
||||
return false;
|
||||
}
|
||||
|
||||
Type type = this.entityTarget.GetType();
|
||||
for (int i = 0; i < this.targetClasses.Count; i++)
|
||||
{
|
||||
EAIApproachAndAttackTargetCompanion.TargetClass targetClass = this.targetClasses[i];
|
||||
if (targetClass.type != null && targetClass.type.IsAssignableFrom(type))
|
||||
{
|
||||
this.chaseTimeMax = targetClass.chaseTimeMax;
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-CanExecute 5");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-CanExecute 6");
|
||||
return false;
|
||||
}
|
||||
|
||||
public void checkEntityPosition()
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition START");
|
||||
|
||||
if (!this.theEntity.onGround) return;
|
||||
|
||||
if (this.theEntity.HasAnyTags(FastTags<TagGroup.Global>.Parse("allyanimal")))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.theEntity.navigator.noPathAndNotPlanningOne())
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition HAVE PATH");
|
||||
return;
|
||||
}
|
||||
|
||||
if (((EntityNPCRebirth)this.theEntity).currentOrder != (int)EntityUtilities.Orders.Stay)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition NOT AT STAY");
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.theEntity.Buffs.HasBuff("buffTalkingTo"))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition IS TALKING");
|
||||
return;
|
||||
}
|
||||
|
||||
EntityAliveV2 npc = this.theEntity as EntityAliveV2;
|
||||
|
||||
if (npc == null)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition EXIT");
|
||||
return;
|
||||
}
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition STAY 1, npc.position: (" + npc.position + ") / npc.guardPosition: (" + npc.guardPosition + ")");
|
||||
|
||||
if (npc.guardPosition == Vector3.zero)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition NO GUARD POSITION");
|
||||
return;
|
||||
}
|
||||
|
||||
Vector3 entityPosition = EntityUtilities.CenterPosition(npc.position);
|
||||
Vector3 guardPosition = EntityUtilities.CenterPosition(npc.guardPosition);
|
||||
|
||||
if (entityPosition != guardPosition)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition STAY 2, npc.position: (" + npc.position + ") / npc.guardPosition: (" + npc.guardPosition + ")");
|
||||
//Vector3 moveToLocation = EntityUtilities.GetMoveToLocation(npc, npc.guardPosition, 0);
|
||||
npc.moveHelper.SetMoveTo(guardPosition, true);
|
||||
|
||||
npc.FindPath(
|
||||
npc.guardPosition,
|
||||
npc.GetMoveSpeedPanic(),
|
||||
false,
|
||||
null);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.theEntity.moveHelper.Stop();
|
||||
this.theEntity.speedForward = 0;
|
||||
/*Vector3 entityRotation = EntityUtilities.CenterPosition(npc.rotation);
|
||||
Vector3 guardRotation = EntityUtilities.CenterPosition(npc.guardLookPosition);
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition STAY 3, npc.position: (" + npc.position + ") / npc.guardPosition: (" + npc.guardPosition + ")");
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition entityRotation: " + entityRotation);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition guardRotation: " + guardRotation);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition npc.rotation: " + npc.rotation);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition npc.guardLookPosition: " + npc.guardLookPosition);
|
||||
|
||||
if (entityRotation != guardRotation && npc.rotation != npc.guardLookPosition)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition STAY ROTATE");
|
||||
//npc.rotation = npc.guardLookPosition;
|
||||
|
||||
npc.SetLookPosition(npc.guardLookPosition);
|
||||
|
||||
npc.RotateTo(
|
||||
npc.guardLookPosition.x,
|
||||
npc.guardLookPosition.y,
|
||||
npc.guardLookPosition.z,
|
||||
360f,
|
||||
360f);
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition STAY IS IN RIGHT POSITION AND ROTATION");
|
||||
}*/
|
||||
|
||||
npc.SetLookPosition(npc.guardLookPosition);
|
||||
|
||||
npc.RotateTo(
|
||||
npc.guardLookPosition.x,
|
||||
npc.guardLookPosition.y,
|
||||
npc.guardLookPosition.z,
|
||||
360f,
|
||||
360f);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Start()
|
||||
{
|
||||
this.entityTargetPos = this.entityTarget.position;
|
||||
this.entityTargetVel = Vector3.zero;
|
||||
this.isTargetToEat = false;
|
||||
this.isEating = false;
|
||||
this.theEntity.IsEating = false;
|
||||
this.homeTimeout = (this.theEntity.IsSleeper ? 90f : this.chaseTimeMax);
|
||||
this.hasHome = (this.homeTimeout > 0f);
|
||||
this.isGoingHome = false;
|
||||
if (this.theEntity.ChaseReturnLocation == Vector3.zero)
|
||||
{
|
||||
this.theEntity.ChaseReturnLocation = (this.theEntity.IsSleeper ? this.theEntity.SleeperSpawnPosition : this.theEntity.position);
|
||||
}
|
||||
this.pathCounter = 0;
|
||||
this.relocateTicks = 0;
|
||||
this.attackTimeout = 5;
|
||||
animator = this.theEntity.emodel.avatarController.GetAnimator();
|
||||
}
|
||||
|
||||
public override bool Continue()
|
||||
{
|
||||
CheckAnimator();
|
||||
backingUp = false;
|
||||
|
||||
if (!NPCEAICanProceed())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool result = false;
|
||||
|
||||
EntityAlive attackTarget = this.theEntity.GetAttackTarget();
|
||||
|
||||
if (attackTarget != null)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Continue 1, attackTarget: " + attackTarget.EntityClass.entityClassName);
|
||||
}
|
||||
else
|
||||
{
|
||||
checkEntityPosition();
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Continue NO ATTACK TARGET");
|
||||
}
|
||||
|
||||
/*bool stopAttacking = this.theEntity.Buffs.HasBuff("buffNPCModStopAttacking") ||
|
||||
this.theEntity.Buffs.HasBuff("FuriousRamsayStandStill");
|
||||
|
||||
if (stopAttacking)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Continue 2");
|
||||
this.OwnerID = (int)this.theEntity.Buffs.GetCustomVar("$Leader");
|
||||
|
||||
if (this.OwnerID > 0)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Continue this.OwnerID: " + this.OwnerID);
|
||||
|
||||
EntityPlayer entityPlayer = (EntityPlayer)this.theEntity.world.GetEntity(OwnerID);
|
||||
if (entityPlayer != null)
|
||||
{
|
||||
attackTarget = entityPlayer;
|
||||
this.entityTarget = entityPlayer;
|
||||
this.theEntity.SetAttackTarget(null, 0);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Continue FOUND OWNER");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
if (this.isGoingHome)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Continue 3, " + result);
|
||||
result = !attackTarget && this.theEntity.ChaseReturnLocation != Vector3.zero;
|
||||
return result;
|
||||
}
|
||||
|
||||
result = attackTarget && !(attackTarget != this.entityTarget);
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Continue 4, " + result);
|
||||
return result;
|
||||
}
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
this.theEntity.IsEating = false;
|
||||
this.theEntity.moveHelper.Stop();
|
||||
if (this.blockTargetTask != null)
|
||||
{
|
||||
this.blockTargetTask.canExecute = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void CheckAnimator()
|
||||
{
|
||||
if (animator && !backingUp)
|
||||
{
|
||||
animator.SetBool("isBackingUp", false);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
CheckAnimator();
|
||||
backingUp = false;
|
||||
|
||||
if (!NPCEAICanProceed())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.targetPlayer != null && ((EntityNPCRebirth)this.theEntity).currentOrder > 0 && ((EntityNPCRebirth)this.theEntity).currentOrder != (int)EntityUtilities.Orders.Follow)
|
||||
{
|
||||
EntityUtilities.CheckDistanceToLeader(this.theEntity, this.targetPlayer);
|
||||
}
|
||||
|
||||
if (this.theEntity.Climbing)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 19");
|
||||
return;
|
||||
}
|
||||
|
||||
EntityAliveV2 npc = this.theEntity as EntityAliveV2;
|
||||
|
||||
if (npc == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.relocateTicks > 0)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 2");
|
||||
if (!this.theEntity.navigator.noPathAndNotPlanningOne())
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 3");
|
||||
this.relocateTicks--;
|
||||
this.theEntity.moveHelper.SetFocusPos(this.entityTarget.position);
|
||||
return;
|
||||
}
|
||||
this.relocateTicks = 0;
|
||||
}
|
||||
|
||||
ItemValue holdingItemItemValue = this.theEntity.inventory.holdingItemItemValue;
|
||||
int holdingItemIdx = this.theEntity.inventory.holdingItemIdx;
|
||||
|
||||
bool isRanged = false;
|
||||
|
||||
if (this.theEntity.HasAnyTags(FastTags<TagGroup.Global>.Parse("ranged")))
|
||||
{
|
||||
_actionIndex = 1;
|
||||
isRanged = true;
|
||||
}
|
||||
|
||||
ItemAction itemAction = this.theEntity.inventory.holdingItem.Actions[_actionIndex];
|
||||
|
||||
var distance = this.entityTarget.GetDistance(this.theEntity);
|
||||
|
||||
if (isRanged && ((((EntityNPCRebirth)this.theEntity).currentOrder > 0 && ((EntityNPCRebirth)this.theEntity).currentOrder == (int)EntityUtilities.Orders.Follow) || this.theEntity.Buffs.GetCustomVar("$Leader") == 0))
|
||||
{
|
||||
/*float MaxRangeForWeapon = EffectManager.GetValue(PassiveEffects.MaxRange, this.theEntity.inventory.holdingItemItemValue,
|
||||
60f, this.theEntity, null, this.theEntity.inventory.holdingItem.ItemTags);
|
||||
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update distance: " + distance);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update MaxRangeForWeapon: " + MaxRangeForWeapon);*/
|
||||
|
||||
float distanceFromTarget = 4f;
|
||||
|
||||
if (this.entityTarget is EntityPlayer)
|
||||
{
|
||||
distanceFromTarget = 5f;
|
||||
}
|
||||
|
||||
if (distance < distanceFromTarget)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 6");
|
||||
//if (!this.entityTarget.emodel.IsRagdollActive)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 6a");
|
||||
|
||||
int maxDistanceFromLeader = UnityEngine.Random.Range(10, 25);
|
||||
|
||||
backingUp = true;
|
||||
|
||||
Animator animator = this.theEntity.emodel.avatarController.GetAnimator();
|
||||
|
||||
if (animator)
|
||||
{
|
||||
animator.SetBool("isBackingUp", true);
|
||||
}
|
||||
|
||||
EntityUtilities.BackupHelper(this.theEntity, this.entityTarget, distanceFromTarget * 3f, maxDistanceFromLeader);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Animator animator = this.theEntity.emodel.avatarController.GetAnimator();
|
||||
|
||||
if (animator)
|
||||
{
|
||||
animator.SetBool("isBackingUp", false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Vector3 curEntTargPos = this.entityTarget.position;
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update B entityClassName: " + this.entityTarget.EntityClass.entityClassName);
|
||||
|
||||
theEntity.SetLookPosition(curEntTargPos);
|
||||
theEntity.RotateTo(curEntTargPos.x, curEntTargPos.y + 2, curEntTargPos.z, 8f, 8f);
|
||||
|
||||
Vector3 targetDirection = theEntity.position - curEntTargPos;
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update this.entityTarget.position: " + this.entityTarget.position);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update entityTargetPosn: " + curEntTargPos);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update targetDirection: " + targetDirection);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update targetDirection.sqrMagnitude: " + targetDirection.sqrMagnitude);
|
||||
|
||||
/* Do you need this?
|
||||
if (this.theEntity.GetAttackTarget() != null)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update GetAttackTarget: " + this.theEntity.GetAttackTarget().EntityClass.entityClassName);
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update NO ATTACK TARGET");
|
||||
}
|
||||
*/
|
||||
|
||||
bool isTargetWithinItemActionRange = false;
|
||||
|
||||
if (targetDirection.sqrMagnitude < 1f)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 7");
|
||||
this.entityTargetVel = this.entityTargetVel * 0.7f + targetDirection * 0.3f;
|
||||
}
|
||||
this.entityTargetPos = curEntTargPos;
|
||||
this.attackTimeout--;
|
||||
|
||||
this.theEntity.moveHelper.CalcIfUnreachablePos();
|
||||
float itemActionRange;
|
||||
float maxItemActionRange;
|
||||
|
||||
itemActionRange = 1.095f;
|
||||
if (itemAction != null)
|
||||
{
|
||||
itemActionRange = itemAction.Range;
|
||||
if (itemActionRange == 0f)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 8");
|
||||
itemActionRange = EffectManager.GetItemValue(PassiveEffects.MaxRange, holdingItemItemValue, 0f);
|
||||
}
|
||||
}
|
||||
maxItemActionRange = Utils.FastMax(0.7f, itemActionRange - 0.35f);
|
||||
|
||||
/*if (isRanged)
|
||||
{
|
||||
maxItemActionRange = itemActionRange / 2;
|
||||
}*/
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 9a, itemActionRange: " + itemActionRange);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 9b, maxItemActionRange: " + maxItemActionRange);
|
||||
|
||||
float maxRangeSquared = maxItemActionRange * maxItemActionRange;
|
||||
float estimatedTimeInTicks = 4f;
|
||||
if (this.theEntity.IsFeral)
|
||||
{
|
||||
estimatedTimeInTicks = 8f;
|
||||
}
|
||||
estimatedTimeInTicks = base.RandomFloat * estimatedTimeInTicks;
|
||||
float targetXZDistanceSq = this.GetTargetXZDistanceSq(estimatedTimeInTicks);
|
||||
float yDiff = curEntTargPos.y - this.theEntity.position.y;
|
||||
float absoluteYDiff = Utils.FastAbs(yDiff);
|
||||
float entityDistance = Vector3.Distance(this.theEntity.position, curEntTargPos);
|
||||
//isTargetWithinItemActionRange = targetXZDistanceSq <= maxRangeSquared && entityDistance < maxItemActionRange;
|
||||
isTargetWithinItemActionRange = entityDistance < maxItemActionRange;
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update entityDistance: " + entityDistance);
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update isTargetWithinItemActionRange: " + isTargetWithinItemActionRange);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update maxRangeSquared: " + maxRangeSquared);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update absoluteYDiff: " + absoluteYDiff);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update yDiff: " + yDiff);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update targetXZDistanceSq: " + targetXZDistanceSq);
|
||||
|
||||
if (!backingUp && ((((EntityNPCRebirth)this.theEntity).currentOrder == (int)EntityUtilities.Orders.Follow) || this.theEntity.Buffs.GetCustomVar("$Leader") == 0))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update !backingUp: " + !backingUp);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update CurrentOrder: " + ((EntityNPCRebirth)this.theEntity).currentOrder);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update $Leader: " + this.theEntity.Buffs.GetCustomVar("$Leader"));
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 10a");
|
||||
|
||||
if (!isTargetWithinItemActionRange)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 10c");
|
||||
if (absoluteYDiff < 3f && !PathFinderThread.Instance.IsCalculatingPath(this.theEntity.entityId))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 11");
|
||||
PathEntity path = this.theEntity.navigator.getPath();
|
||||
if (path != null && path.NodeCountRemaining() <= 2)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 12");
|
||||
this.pathCounter = 0;
|
||||
}
|
||||
}
|
||||
int pathCounterLessOne = this.pathCounter - 1;
|
||||
this.pathCounter = pathCounterLessOne;
|
||||
if (pathCounterLessOne <= 0 && this.theEntity.CanNavigatePath() && !PathFinderThread.Instance.IsCalculatingPath(this.theEntity.entityId))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 13");
|
||||
this.pathCounter = 6 + base.GetRandom(10);
|
||||
//Vector3 moveToLocation = this.GetMoveToLocation(num3);
|
||||
Vector3 moveToLocation = EntityUtilities.GetMoveToLocation(this.theEntity, this.entityTarget.position, 0);
|
||||
|
||||
if (isRanged)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update BEFORE moveToLocation: " + moveToLocation);
|
||||
//moveToLocation = RandomPositionGenerator.CalcAway(this.theEntity, 2, 5, 5, this.entityTarget.position);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update AFTER moveToLocation: " + moveToLocation);
|
||||
}
|
||||
|
||||
if (moveToLocation.y - this.theEntity.position.y < -8f)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 14");
|
||||
this.pathCounter += 40;
|
||||
if (base.RandomFloat < 0.2f)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 15");
|
||||
this.seekPosOffset.x = this.seekPosOffset.x + (base.RandomFloat * 0.6f - 0.3f);
|
||||
this.seekPosOffset.y = this.seekPosOffset.y + (base.RandomFloat * 0.6f - 0.3f);
|
||||
}
|
||||
moveToLocation.x += this.seekPosOffset.x;
|
||||
moveToLocation.z += this.seekPosOffset.y;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 16");
|
||||
float num8 = (moveToLocation - this.theEntity.position).magnitude - 5f;
|
||||
if (num8 > 0f)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 17");
|
||||
if (num8 > 60f)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 18");
|
||||
num8 = 60f;
|
||||
}
|
||||
this.pathCounter += (int)(num8 / 20f * 20f);
|
||||
}
|
||||
}
|
||||
this.theEntity.FindPath(moveToLocation, this.theEntity.GetMoveSpeedAggro(), true, this);
|
||||
}
|
||||
}
|
||||
|
||||
if (!isTargetWithinItemActionRange)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 19");
|
||||
if (this.theEntity.navigator.noPathAndNotPlanningOne() && this.pathCounter > 0 && yDiff < 2.1f)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 20");
|
||||
//Vector3 moveToLocation2 = this.GetMoveToLocation(num3);
|
||||
Vector3 moveToLocation2 = EntityUtilities.GetMoveToLocation(this.theEntity, this.entityTarget.position, 0);
|
||||
this.theEntity.moveHelper.SetMoveTo(moveToLocation2, true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 21");
|
||||
this.theEntity.moveHelper.Stop();
|
||||
this.pathCounter = 0;
|
||||
}
|
||||
|
||||
float newItemActionRange = itemActionRange - 0.1f;
|
||||
float newRangeSquared = newItemActionRange * newItemActionRange;
|
||||
/*if (targetXZDistanceSq > newRangeSquared || absoluteYDiff >= 1.25f)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 22");
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update newItemActionRange: " + newItemActionRange);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update newRangeSquared: " + newRangeSquared);
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update C entityClassName: " + this.entityTarget.EntityClass.entityClassName);
|
||||
return;
|
||||
}*/
|
||||
this.theEntity.IsBreakingBlocks = false;
|
||||
this.theEntity.IsBreakingDoors = false;
|
||||
if (this.theEntity.bodyDamage.HasLimbs && !this.theEntity.Electrocuted)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 23");
|
||||
this.theEntity.RotateTo(curEntTargPos.x, curEntTargPos.y, curEntTargPos.z, 30f, 30f);
|
||||
}
|
||||
if (this.theEntity.GetDamagedTarget() == this.entityTarget || (this.entityTarget != null && this.entityTarget.GetDamagedTarget() == this.theEntity))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 24");
|
||||
this.homeTimeout = (this.theEntity.IsSleeper ? 90f : this.chaseTimeMax);
|
||||
if (this.blockTargetTask != null)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 25");
|
||||
this.blockTargetTask.canExecute = false;
|
||||
}
|
||||
this.theEntity.ClearDamagedTarget();
|
||||
if (this.entityTarget)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 26");
|
||||
this.entityTarget.ClearDamagedTarget();
|
||||
}
|
||||
}
|
||||
|
||||
if (this.manager.groupCircle > 0f)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 27");
|
||||
Entity targetIfAttackedNow = this.theEntity.GetTargetIfAttackedNow();
|
||||
if (targetIfAttackedNow != this.entityTarget && (!this.entityTarget.AttachedToEntity || this.entityTarget.AttachedToEntity != targetIfAttackedNow))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 28");
|
||||
if (targetIfAttackedNow != null)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 29");
|
||||
this.relocateTicks = 46;
|
||||
Vector3 vector3 = (this.theEntity.position - curEntTargPos).normalized * (newItemActionRange + 1.1f);
|
||||
float num11 = base.RandomFloat * 28f + 18f;
|
||||
if (base.RandomFloat < 0.5f)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 30");
|
||||
num11 = -num11;
|
||||
}
|
||||
vector3 = Quaternion.Euler(0f, num11, 0f) * vector3;
|
||||
Vector3 targetPos = curEntTargPos + vector3;
|
||||
this.theEntity.FindPath(targetPos, this.theEntity.GetMoveSpeedAggro(), true, this);
|
||||
}
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update E entityClassName: " + this.entityTarget.EntityClass.entityClassName);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 31");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.entityTarget == null)
|
||||
{
|
||||
checkEntityPosition();
|
||||
}
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update _actionIndex: " + _actionIndex);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update isRanged: " + isRanged);
|
||||
|
||||
/*bool flag2 = this.theEntity.CanSee(this.entityTarget);
|
||||
|
||||
if (this.OwnerID > 0 && !(this.entityTarget is EntityPlayer) && this.entityTarget.Buffs.GetCustomVar("$FuriousRamsayAttacking") == 1f || this.entityTarget.Buffs.GetCustomVar("$FuriousRamsayAttacked") == 1f)
|
||||
{
|
||||
flag2 = true;
|
||||
}*/
|
||||
|
||||
//this.theEntity.SetLookPosition((flag2 && !this.theEntity.IsBreakingBlocks) ? this.entityTarget.getHeadPosition() : Vector3.zero);
|
||||
|
||||
/*if (this.attackTimeout > 0)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 32");
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update D entityClassName: " + this.entityTarget.EntityClass.entityClassName);
|
||||
return;
|
||||
}*/
|
||||
|
||||
this.theEntity.SleeperSupressLivingSounds = false;
|
||||
|
||||
if (this.theEntity.Buffs.HasBuff("buffReloadDelay") ||
|
||||
this.theEntity.Buffs.HasBuff("buffReload2") ||
|
||||
this.theEntity.Buffs.HasBuff("buffReload3")
|
||||
)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 33");
|
||||
return;
|
||||
}
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 34");
|
||||
//if (!(this.entityTarget is EntityPlayer) && npc.ExecuteAction(false, _actionIndex))
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update backingUp: " + backingUp);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update distance: " + distance);
|
||||
|
||||
//if (backingUp && distance < 1.2f)
|
||||
|
||||
int rangeMax = 20;
|
||||
|
||||
PrefabInstance poiatPosition = this.theEntity.world.GetPOIAtPosition(this.theEntity.position, false);
|
||||
|
||||
if (poiatPosition != null)
|
||||
{
|
||||
//Give NPCs a better chance at a ragdoll when inside a POI
|
||||
rangeMax = 10;
|
||||
}
|
||||
|
||||
if (this.entityTarget is EntityPlayer)
|
||||
{
|
||||
rangeMax = 100;
|
||||
}
|
||||
|
||||
int chance = UnityEngine.Random.Range(1, rangeMax);
|
||||
|
||||
if (chance < 10 && !this.entityTarget.emodel.IsRagdollActive && distance < this.theEntity.inventory.holdingItem.Actions[0].Range)
|
||||
{
|
||||
_actionIndex = 0;
|
||||
}
|
||||
|
||||
if (_actionIndex == 1)
|
||||
{
|
||||
if (!isTargetWithinItemActionRange && this.theEntity.moveHelper.IsActive)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update Target isn't within range");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (isTargetWithinItemActionRange)
|
||||
{
|
||||
if (this.theEntity.Buffs.HasBuff("buffRangedMeleeDelay"))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update HAS ATTACK DELAY BUFF");
|
||||
return;
|
||||
}
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 35a");
|
||||
if (npc.ExecuteAction(false, _actionIndex))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 35b");
|
||||
this.attackTimeout = this.theEntity.GetAttackTimeoutTicks();
|
||||
//this.theEntity.Attack(true);
|
||||
|
||||
if (isRanged && _actionIndex == 0)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update ADDED ATTACK DELAY BUFF");
|
||||
this.theEntity.Buffs.AddBuff("buffRangedMeleeDelay");
|
||||
}
|
||||
|
||||
// Check the range on the item action
|
||||
ItemActionRanged.ItemActionDataRanged itemActionData = null;
|
||||
|
||||
if (itemAction is ItemActionRanged itemActionRanged)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 36");
|
||||
itemActionData = this.theEntity.inventory.holdingItemData.actionData[_actionIndex] as ItemActionRanged.ItemActionDataRanged;
|
||||
if (itemActionData != null)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 37");
|
||||
// Check if we are already running.
|
||||
if (itemAction.IsActionRunning(itemActionData))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 38");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*attackTimeout--;
|
||||
if (attackTimeout > 0)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 39, attackTimeout: " + attackTimeout);
|
||||
return;
|
||||
}
|
||||
|
||||
this.attackTimeout = this.theEntity.GetAttackTimeoutTicks();
|
||||
|
||||
if (!npc.ExecuteAction(false, _actionIndex))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 40");
|
||||
return;
|
||||
}
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update ATTACKED, _actionIndex: " + _actionIndex);
|
||||
npc.ExecuteAction(true, _actionIndex);*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private float GetTargetXZDistanceSq(float estimatedTicks)
|
||||
{
|
||||
Vector3 vector = this.entityTarget.position;
|
||||
vector += this.entityTargetVel * estimatedTicks;
|
||||
Vector3 vector2 = this.theEntity.position + this.theEntity.motion * estimatedTicks - vector;
|
||||
vector2.y = 0f;
|
||||
return vector2.sqrMagnitude;
|
||||
}
|
||||
|
||||
private Vector3 GetMoveToLocation(float maxDist)
|
||||
{
|
||||
Vector3 vector = this.entityTarget.position;
|
||||
vector += this.entityTargetVel * 6f;
|
||||
vector = this.entityTarget.world.FindSupportingBlockPos(vector);
|
||||
if (maxDist > 0f)
|
||||
{
|
||||
Vector3 vector2 = new Vector3(this.theEntity.position.x, vector.y, this.theEntity.position.z);
|
||||
Vector3 vector3 = vector - vector2;
|
||||
float magnitude = vector3.magnitude;
|
||||
if (magnitude < 3f)
|
||||
{
|
||||
if (magnitude <= maxDist)
|
||||
{
|
||||
float num = vector.y - this.theEntity.position.y;
|
||||
if (num < -3f || num > 1.5f)
|
||||
{
|
||||
return vector;
|
||||
}
|
||||
return vector2;
|
||||
}
|
||||
else
|
||||
{
|
||||
vector3 *= maxDist / magnitude;
|
||||
Vector3 vector4 = vector - vector3;
|
||||
vector4.y += 0.51f;
|
||||
Vector3i pos = World.worldToBlockPos(vector4);
|
||||
BlockValue block = this.entityTarget.world.GetBlock(pos);
|
||||
Block block2 = block.Block;
|
||||
if (block2.PathType <= 0)
|
||||
{
|
||||
RaycastHit raycastHit;
|
||||
if (Physics.Raycast(vector4 - Origin.position, Vector3.down, out raycastHit, 1.02f, 1082195968))
|
||||
{
|
||||
vector4.y = raycastHit.point.y + Origin.position.y;
|
||||
return vector4;
|
||||
}
|
||||
if (block2.IsElevator((int)block.rotation))
|
||||
{
|
||||
vector4.y = vector.y;
|
||||
return vector4;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return vector;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
ItemValue holdingItemItemValue = this.theEntity.inventory.holdingItemItemValue;
|
||||
int holdingItemIdx = this.theEntity.inventory.holdingItemIdx;
|
||||
ItemAction itemAction = holdingItemItemValue.ItemClass.Actions[holdingItemIdx];
|
||||
float num = 1.095f;
|
||||
if (itemAction != null)
|
||||
{
|
||||
num = itemAction.Range;
|
||||
if (num == 0f)
|
||||
{
|
||||
num = EffectManager.GetItemValue(PassiveEffects.MaxRange, holdingItemItemValue, 0f);
|
||||
}
|
||||
}
|
||||
float value = num - 0.1f;
|
||||
float targetXZDistanceSq = this.GetTargetXZDistanceSq(0f);
|
||||
return string.Format("{0}, {1}{2}{3}{4}{5} dist {6} rng {7} timeout {8}", new object[]
|
||||
{
|
||||
base.ToString(),
|
||||
this.entityTarget ? this.entityTarget.EntityName : "",
|
||||
this.theEntity.CanSee(this.entityTarget) ? "(see)" : "",
|
||||
this.theEntity.navigator.noPathAndNotPlanningOne() ? "(-path)" : (this.theEntity.navigator.noPath() ? "(!path)" : ""),
|
||||
this.isTargetToEat ? "(eat)" : "",
|
||||
this.isGoingHome ? "(home)" : "",
|
||||
Mathf.Sqrt(targetXZDistanceSq).ToCultureInvariantString("0.000"),
|
||||
value.ToCultureInvariantString("0.000"),
|
||||
this.homeTimeout.ToCultureInvariantString("0.00")
|
||||
});
|
||||
}
|
||||
|
||||
private int _actionIndex = 0;
|
||||
private const float cSleeperChaseTime = 90f;
|
||||
private List<EAIApproachAndAttackTargetCompanion.TargetClass> targetClasses;
|
||||
private float chaseTimeMax;
|
||||
private bool hasHome;
|
||||
private bool isGoingHome;
|
||||
private float homeTimeout;
|
||||
private EntityPlayer targetPlayer;
|
||||
private EntityAlive entityTarget;
|
||||
private Vector3 entityTargetPos;
|
||||
private Vector3 entityTargetVel;
|
||||
private int attackTimeout;
|
||||
private int pathCounter;
|
||||
private Vector2 seekPosOffset;
|
||||
private bool isTargetToEat;
|
||||
private bool isEating;
|
||||
private int eatCount;
|
||||
private EAIBlockingTargetTask blockTargetTask;
|
||||
private int relocateTicks;
|
||||
private int OwnerID = 0;
|
||||
private bool backingUp = false;
|
||||
private Animator animator = null;
|
||||
|
||||
private struct TargetClass
|
||||
{
|
||||
public Type type;
|
||||
public float chaseTimeMax;
|
||||
}
|
||||
}
|
||||
420
Scripts/EAI/NPCs/v1/EAIFollowLeaderCompanion.cs
Normal file
420
Scripts/EAI/NPCs/v1/EAIFollowLeaderCompanion.cs
Normal file
@@ -0,0 +1,420 @@
|
||||
using GamePath;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Xml;
|
||||
using UnityEngine.Scripting;
|
||||
using static BlendCycleTimer;
|
||||
using static EntityDrone;
|
||||
|
||||
[Preserve]
|
||||
public class EAIFollowLeaderCompanion : EAITarget
|
||||
{
|
||||
public override void Init(EntityAlive _theEntity)
|
||||
{
|
||||
base.Init(_theEntity, 25f, true);
|
||||
this.MutexBits = 1;
|
||||
}
|
||||
|
||||
public override void Start()
|
||||
{
|
||||
this.entityPlayerVel = Vector3.zero;
|
||||
this.relocateTicks = 0;
|
||||
this.pathCounter = 0;
|
||||
this.theEntity.ConditionalTriggerSleeperWakeUp();
|
||||
base.Start();
|
||||
}
|
||||
|
||||
public bool NPCEAICanProceed()
|
||||
{
|
||||
bool result = true;
|
||||
|
||||
this.OwnerID = (int)this.theEntity.Buffs.GetCustomVar("$Leader");
|
||||
|
||||
if (this.OwnerID == 0)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-NPCEAICanProceed 0");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.Buffs.GetCustomVar("onMission") == 1f ||
|
||||
this.theEntity.Buffs.GetCustomVar("$FR_NPC_Respawn") == 1f ||
|
||||
this.theEntity.Buffs.GetCustomVar("$FR_NPC_Hidden") == 1f
|
||||
)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-NPCEAICanProceed 1");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.emodel.IsRagdollActive)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-NPCEAICanProceed 3");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.sleepingOrWakingUp || this.theEntity.bodyDamage.CurrentStun != EnumEntityStunType.None || (this.theEntity.Jumping && !this.theEntity.isSwimming))
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-NPCEAICanProceed 4");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (((EntityNPCRebirth)this.theEntity).currentOrder != (int)EntityUtilities.Orders.Follow)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-CanExecute IS NOT FOLLOWING");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool stopAttacking = this.theEntity.Buffs.HasBuff("FuriousRamsayBuffPauseAttack") ||
|
||||
this.theEntity.Buffs.HasBuff("buffNPCModStopAttacking") ||
|
||||
this.theEntity.Buffs.HasBuff("FuriousRamsayStandStill");
|
||||
|
||||
if (stopAttacking)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-NPCEAICanProceed 5");
|
||||
this.theEntity.SetRevengeTarget(null);
|
||||
this.theEntity.SetAttackTarget(null, 0);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.sleepingOrWakingUp || this.theEntity.bodyDamage.CurrentStun != EnumEntityStunType.None)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-NPCEAICanProceed 6");
|
||||
return false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public override bool CanExecute()
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-CanExecute START");
|
||||
|
||||
if (!NPCEAICanProceed())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.targetPlayer == null)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-CanExecute 2");
|
||||
this.OwnerID = (int)this.theEntity.Buffs.GetCustomVar("$Leader");
|
||||
|
||||
if (this.OwnerID > 0)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-CanExecute this.OwnerID: " + this.OwnerID);
|
||||
|
||||
EntityPlayer entityPlayer = (EntityPlayer)this.theEntity.world.GetEntity(this.OwnerID);
|
||||
if (entityPlayer != null)
|
||||
{
|
||||
this.targetPlayer = entityPlayer;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//Log.Out("EAIFollowLeaderCompanion-CanExecute this.theEntity.GetAttackTarget: " + this.theEntity.GetAttackTarget().EntityClass.entityClassName);
|
||||
return false;
|
||||
}
|
||||
|
||||
public override bool Continue()
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Continue START");
|
||||
|
||||
/*this.OwnerID = (int)this.theEntity.Buffs.GetCustomVar("$Leader");
|
||||
|
||||
if (this.OwnerID == 0)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Continue 0");
|
||||
|
||||
//bool result = this.theEntity.bodyDamage.CurrentStun == EnumEntityStunType.None && this.theEntity.moveHelper.BlockedTime <= 0.3f;
|
||||
|
||||
return true;
|
||||
}*/
|
||||
|
||||
if (!NPCEAICanProceed())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (pathCounter == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update START");
|
||||
|
||||
if (!NPCEAICanProceed())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.targetPlayer == null)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 2");
|
||||
this.OwnerID = (int)this.theEntity.Buffs.GetCustomVar("$Leader");
|
||||
|
||||
if (this.OwnerID > 0)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update this.OwnerID: " + this.OwnerID);
|
||||
|
||||
EntityPlayer entityPlayer = (EntityPlayer)this.theEntity.world.GetEntity(this.OwnerID);
|
||||
if (entityPlayer != null)
|
||||
{
|
||||
this.targetPlayer = entityPlayer;
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update FOUND OWNER");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EntityUtilities.CheckForClosedDoor(this.theEntity);
|
||||
|
||||
EntityUtilities.CheckDistanceToLeader(this.theEntity, this.targetPlayer);
|
||||
|
||||
if (this.relocateTicks > 0)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 2");
|
||||
if (!this.theEntity.navigator.noPathAndNotPlanningOne())
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 3");
|
||||
this.relocateTicks--;
|
||||
this.theEntity.moveHelper.SetFocusPos(this.targetPlayer.position);
|
||||
return;
|
||||
}
|
||||
this.relocateTicks = 0;
|
||||
}
|
||||
|
||||
Vector3 vector2 = this.targetPlayer.position;
|
||||
|
||||
Vector3 a = theEntity.position - vector2;
|
||||
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update entityTargetPosn: " + vector2);
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update a: " + a);
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update a.sqrMagnitude: " + a.sqrMagnitude);
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update this.OwnerID: " + this.theEntity.Buffs.GetCustomVar("$Leader"));
|
||||
|
||||
this.OwnerID = (int)this.theEntity.Buffs.GetCustomVar("$Leader");
|
||||
|
||||
float magnitude = 30f;
|
||||
|
||||
bool isClient = SingletonMonoBehaviour<ConnectionManager>.Instance.IsClient;
|
||||
|
||||
if (isClient)
|
||||
{
|
||||
magnitude = 3f;
|
||||
}
|
||||
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update magnitude: " + magnitude);
|
||||
|
||||
if (this.targetPlayer.entityId == this.OwnerID && a.sqrMagnitude < magnitude)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update Entity is too close. Ending pathing.");
|
||||
this.theEntity.moveHelper.Stop();
|
||||
pathCounter = 0;
|
||||
/*theEntity.SetLookPosition(vector2);
|
||||
theEntity.RotateTo(vector2.x, vector2.y + 2, vector2.z, 8f, 8f);*/
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.targetPlayer.entityId == this.OwnerID)
|
||||
{
|
||||
if (!this.theEntity.HasAnyTags(FastTags<TagGroup.Global>.Parse("allyanimal")))
|
||||
{
|
||||
this.theEntity.Crouching = this.targetPlayer.Crouching;
|
||||
}
|
||||
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update theEntity.moveHelper.BlockedTime: " + theEntity.moveHelper.BlockedTime);
|
||||
|
||||
if (theEntity.moveHelper.BlockedTime > 3f)
|
||||
{
|
||||
EntityAliveV2 npc = this.theEntity as EntityAliveV2;
|
||||
|
||||
if (npc != null)
|
||||
{
|
||||
npc.TeleportToPlayer(this.targetPlayer, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
theEntity.SetLookPosition(vector2);
|
||||
theEntity.RotateTo(vector2.x, vector2.y + 2, vector2.z, 8f, 8f);
|
||||
|
||||
if (a.sqrMagnitude < 1f)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 6");
|
||||
this.entityPlayerVel = this.entityPlayerVel * 0.7f + a * 0.3f;
|
||||
}
|
||||
this.entityPlayerPos = vector2;
|
||||
|
||||
this.theEntity.moveHelper.CalcIfUnreachablePos();
|
||||
float num2;
|
||||
float num3;
|
||||
|
||||
num2 = 1.095f;
|
||||
num3 = Utils.FastMax(0.7f, num2 - 0.35f);
|
||||
|
||||
float num4 = num3 * num3;
|
||||
float num5 = 4f;
|
||||
if (this.theEntity.IsFeral)
|
||||
{
|
||||
num5 = 8f;
|
||||
}
|
||||
num5 = base.RandomFloat * num5;
|
||||
float targetXZDistanceSq = this.GetTargetXZDistanceSq(num5);
|
||||
float num6 = vector2.y - this.theEntity.position.y;
|
||||
float num7 = Utils.FastAbs(num6);
|
||||
bool flag = targetXZDistanceSq <= num4 && num7 < 1f;
|
||||
if (!flag)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 9");
|
||||
if (num7 < 3f && !PathFinderThread.Instance.IsCalculatingPath(this.theEntity.entityId))
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 10");
|
||||
PathEntity path = this.theEntity.navigator.getPath();
|
||||
if (path != null && path.NodeCountRemaining() <= 2)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 11");
|
||||
this.pathCounter = 0;
|
||||
}
|
||||
}
|
||||
int num = this.pathCounter - 1;
|
||||
this.pathCounter = num;
|
||||
if (num <= 0 && this.theEntity.CanNavigatePath() && !PathFinderThread.Instance.IsCalculatingPath(this.theEntity.entityId))
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 12");
|
||||
this.pathCounter = 6 + base.GetRandom(10);
|
||||
//Vector3 moveToLocation = this.GetMoveToLocation(num3);
|
||||
Vector3 moveToLocation = EntityUtilities.GetMoveToLocation(this.theEntity, this.targetPlayer.position,5);
|
||||
if (moveToLocation.y - this.theEntity.position.y < -8f)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 13");
|
||||
this.pathCounter += 40;
|
||||
if (base.RandomFloat < 0.2f)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 14");
|
||||
this.seekPosOffset.x = this.seekPosOffset.x + (base.RandomFloat * 0.6f - 0.3f);
|
||||
this.seekPosOffset.y = this.seekPosOffset.y + (base.RandomFloat * 0.6f - 0.3f);
|
||||
}
|
||||
moveToLocation.x += this.seekPosOffset.x;
|
||||
moveToLocation.z += this.seekPosOffset.y;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 15");
|
||||
float num8 = (moveToLocation - this.theEntity.position).magnitude - 5f;
|
||||
if (num8 > 0f)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 16");
|
||||
if (num8 > 60f)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 17");
|
||||
num8 = 60f;
|
||||
}
|
||||
this.pathCounter += (int)(num8 / 20f * 20f);
|
||||
}
|
||||
}
|
||||
this.theEntity.FindPath(moveToLocation, this.theEntity.GetMoveSpeedAggro(), true, this);
|
||||
}
|
||||
}
|
||||
if (this.theEntity.Climbing)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 18");
|
||||
return;
|
||||
}
|
||||
if (!flag)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 20");
|
||||
if (this.theEntity.navigator.noPathAndNotPlanningOne() && this.pathCounter > 0 && num6 < 2.1f)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 21");
|
||||
//Vector3 moveToLocation2 = this.GetMoveToLocation(num3);
|
||||
Vector3 moveToLocation2 = EntityUtilities.GetMoveToLocation(this.theEntity, this.targetPlayer.position);
|
||||
this.theEntity.moveHelper.SetMoveTo(moveToLocation2, true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 22");
|
||||
this.theEntity.moveHelper.Stop();
|
||||
this.pathCounter = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private float GetTargetXZDistanceSq(float estimatedTicks)
|
||||
{
|
||||
Vector3 vector = this.targetPlayer.position;
|
||||
vector += this.entityPlayerVel * estimatedTicks;
|
||||
Vector3 vector2 = this.theEntity.position + this.theEntity.motion * estimatedTicks - vector;
|
||||
vector2.y = 0f;
|
||||
return vector2.sqrMagnitude;
|
||||
}
|
||||
|
||||
private Vector3 GetMoveToLocation(float maxDist)
|
||||
{
|
||||
Vector3 vector = this.targetPlayer.position;
|
||||
vector += this.entityPlayerVel * 6f;
|
||||
vector = this.targetPlayer.world.FindSupportingBlockPos(vector);
|
||||
if (maxDist > 0f)
|
||||
{
|
||||
Vector3 vector2 = new Vector3(this.theEntity.position.x, vector.y, this.theEntity.position.z);
|
||||
Vector3 vector3 = vector - vector2;
|
||||
float magnitude = vector3.magnitude;
|
||||
if (magnitude < 3f)
|
||||
{
|
||||
if (magnitude <= maxDist)
|
||||
{
|
||||
float num = vector.y - this.theEntity.position.y;
|
||||
if (num < -3f || num > 1.5f)
|
||||
{
|
||||
return vector;
|
||||
}
|
||||
return vector2;
|
||||
}
|
||||
else
|
||||
{
|
||||
vector3 *= maxDist / magnitude;
|
||||
Vector3 vector4 = vector - vector3;
|
||||
vector4.y += 0.51f;
|
||||
Vector3i pos = World.worldToBlockPos(vector4);
|
||||
BlockValue block = this.targetPlayer.world.GetBlock(pos);
|
||||
Block block2 = block.Block;
|
||||
if (block2.PathType <= 0)
|
||||
{
|
||||
RaycastHit raycastHit;
|
||||
if (Physics.Raycast(vector4 - Origin.position, Vector3.down, out raycastHit, 1.02f, 1082195968))
|
||||
{
|
||||
vector4.y = raycastHit.point.y + Origin.position.y;
|
||||
return vector4;
|
||||
}
|
||||
if (block2.IsElevator((int)block.rotation))
|
||||
{
|
||||
vector4.y = vector.y;
|
||||
return vector4;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return vector;
|
||||
}
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
this.targetPlayer = null;
|
||||
}
|
||||
|
||||
private EntityPlayer targetPlayer;
|
||||
private Vector3 entityPlayerVel;
|
||||
private Vector3 entityPlayerPos;
|
||||
private int relocateTicks;
|
||||
private int OwnerID = 0;
|
||||
private int pathCounter;
|
||||
private Vector2 seekPosOffset;
|
||||
}
|
||||
110
Scripts/EAI/NPCs/v1/EAILookCompanion.cs
Normal file
110
Scripts/EAI/NPCs/v1/EAILookCompanion.cs
Normal file
@@ -0,0 +1,110 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Scripting;
|
||||
|
||||
[Preserve]
|
||||
public class EAILookCompanion : EAIBase
|
||||
{
|
||||
public EAILookCompanion()
|
||||
{
|
||||
this.MutexBits = 1;
|
||||
}
|
||||
|
||||
public override bool CanExecute()
|
||||
{
|
||||
if (this.theEntity.Buffs.GetCustomVar("onMission") == 1f)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//Log.Out("EAILookCompanion-CanExecute START");
|
||||
|
||||
if (this.theEntity.Buffs.GetCustomVar("$Leader") == 0f)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool stopAttacking = this.theEntity.Buffs.HasBuff("buffNPCModStopAttacking") ||
|
||||
this.theEntity.Buffs.HasBuff("FuriousRamsayStandStill");
|
||||
|
||||
if (stopAttacking)
|
||||
{
|
||||
//Log.Out("EAILookCompanion-CanExecute STOP ATTACKING OR STAND STILL");
|
||||
this.theEntity.SetRevengeTarget(null);
|
||||
this.theEntity.SetAttackTarget(null, 0);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.GetAttackTarget() != null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return this.manager.lookTime > 0f;
|
||||
}
|
||||
|
||||
public override void Start()
|
||||
{
|
||||
this.waitTicks = (int)(this.manager.lookTime * 20f);
|
||||
this.manager.lookTime = 0f;
|
||||
this.theEntity.GetEntitySenses().Clear();
|
||||
this.viewTicks = 0;
|
||||
this.theEntity.Jumping = false;
|
||||
this.theEntity.moveHelper.Stop();
|
||||
}
|
||||
|
||||
public override bool Continue()
|
||||
{
|
||||
if (this.theEntity.Buffs.GetCustomVar("onMission") == 1f)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool stopAttacking = this.theEntity.Buffs.HasBuff("buffNPCModStopAttacking") ||
|
||||
this.theEntity.Buffs.HasBuff("FuriousRamsayStandStill");
|
||||
|
||||
if (stopAttacking)
|
||||
{
|
||||
//Log.Out("EAILookCompanion-CanExecute STOP ATTACKING OR STAND STILL");
|
||||
this.theEntity.SetRevengeTarget(null);
|
||||
this.theEntity.SetAttackTarget(null, 0);
|
||||
|
||||
return false;
|
||||
}
|
||||
//Log.Out("EAILookCompanion-Continue START");
|
||||
|
||||
if (this.theEntity.bodyDamage.CurrentStun != EnumEntityStunType.None)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
this.waitTicks--;
|
||||
if (this.waitTicks <= 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
this.viewTicks--;
|
||||
if (this.viewTicks <= 0)
|
||||
{
|
||||
this.viewTicks = 40;
|
||||
Vector3 headPosition = this.theEntity.getHeadPosition();
|
||||
Vector3 vector = this.theEntity.GetForwardVector();
|
||||
vector = Quaternion.Euler(base.RandomFloat * 60f - 30f, base.RandomFloat * 120f - 60f, 0f) * vector;
|
||||
this.theEntity.SetLookPosition(headPosition + vector);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
this.theEntity.SetLookPosition(Vector3.zero);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Format("{0}, wait {1}", base.ToString(), ((float)this.waitTicks / 20f).ToCultureInvariantString());
|
||||
}
|
||||
|
||||
private int waitTicks;
|
||||
private int viewTicks;
|
||||
}
|
||||
385
Scripts/EAI/NPCs/v1/EAIMoveToTargetCompanion.cs
Normal file
385
Scripts/EAI/NPCs/v1/EAIMoveToTargetCompanion.cs
Normal file
@@ -0,0 +1,385 @@
|
||||
using GamePath;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Xml;
|
||||
using UnityEngine.Scripting;
|
||||
using static BlendCycleTimer;
|
||||
using static EntityDrone;
|
||||
|
||||
[Preserve]
|
||||
public class EAIMoveToTargetCompanion : EAITarget
|
||||
{
|
||||
public override void Init(EntityAlive _theEntity)
|
||||
{
|
||||
base.Init(_theEntity, 25f, true);
|
||||
this.MutexBits = 1;
|
||||
}
|
||||
|
||||
public override void Start()
|
||||
{
|
||||
//this.entityPlayerVel = Vector3.zero;
|
||||
this.relocateTicks = 0;
|
||||
this.pathCounter = 0;
|
||||
//this.theEntity.ConditionalTriggerSleeperWakeUp();
|
||||
base.Start();
|
||||
}
|
||||
|
||||
public bool NPCEAICanProceed()
|
||||
{
|
||||
bool result = true;
|
||||
|
||||
this.OwnerID = (int)this.theEntity.Buffs.GetCustomVar("$Leader");
|
||||
|
||||
if (this.OwnerID == 0)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-NPCEAICanProceed 0");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.Buffs.GetCustomVar("onMission") == 1f ||
|
||||
this.theEntity.Buffs.GetCustomVar("$FR_NPC_Respawn") == 1f ||
|
||||
this.theEntity.Buffs.GetCustomVar("$FR_NPC_Hidden") == 1f
|
||||
)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-NPCEAICanProceed 1");
|
||||
return false;
|
||||
}
|
||||
|
||||
this.entityTarget = this.theEntity.GetAttackTarget();
|
||||
|
||||
if (this.entityTarget == null)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-NPCEAICanProceed 2a");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.targetPlayer != null && !this.targetPlayer.CanEntityBeSeen(this.entityTarget) && !this.theEntity.CanEntityBeSeen(this.entityTarget))
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-NPCEAICanProceed 2b");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.CanEntityBeSeen(this.entityTarget))
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-NPCEAICanProceed 2c");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.emodel.IsRagdollActive)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-NPCEAICanProceed 3");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.sleepingOrWakingUp || this.theEntity.bodyDamage.CurrentStun != EnumEntityStunType.None || (this.theEntity.Jumping && !this.theEntity.isSwimming))
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-NPCEAICanProceed 4");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (((EntityNPCRebirth)this.theEntity).currentOrder != (int)EntityUtilities.Orders.Follow)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-CanExecute IS NOT FOLLOWING");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool stopAttacking = this.theEntity.Buffs.HasBuff("FuriousRamsayBuffPauseAttack") ||
|
||||
this.theEntity.Buffs.HasBuff("buffNPCModStopAttacking") ||
|
||||
this.theEntity.Buffs.HasBuff("FuriousRamsayStandStill");
|
||||
|
||||
if (stopAttacking)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-NPCEAICanProceed 5");
|
||||
this.theEntity.SetRevengeTarget(null);
|
||||
this.theEntity.SetAttackTarget(null, 0);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.sleepingOrWakingUp || this.theEntity.bodyDamage.CurrentStun != EnumEntityStunType.None)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-NPCEAICanProceed 6");
|
||||
return false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public override bool CanExecute()
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-CanExecute START");
|
||||
|
||||
if (!NPCEAICanProceed())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.targetPlayer == null)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-CanExecute 2");
|
||||
this.OwnerID = (int)this.theEntity.Buffs.GetCustomVar("$Leader");
|
||||
|
||||
if (this.OwnerID > 0)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-CanExecute this.OwnerID: " + this.OwnerID);
|
||||
|
||||
EntityPlayer entityPlayer = (EntityPlayer)this.theEntity.world.GetEntity(this.OwnerID);
|
||||
if (entityPlayer != null)
|
||||
{
|
||||
this.targetPlayer = entityPlayer;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//Log.Out("EAIMoveToTargetCompanion-CanExecute this.theEntity.GetAttackTarget: " + this.theEntity.GetAttackTarget().EntityClass.entityClassName);
|
||||
return false;
|
||||
}
|
||||
|
||||
public override bool Continue()
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Continue START");
|
||||
|
||||
/*this.OwnerID = (int)this.theEntity.Buffs.GetCustomVar("$Leader");
|
||||
|
||||
if (this.OwnerID == 0)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Continue 0");
|
||||
|
||||
//bool result = this.theEntity.bodyDamage.CurrentStun == EnumEntityStunType.None && this.theEntity.moveHelper.BlockedTime <= 0.3f;
|
||||
|
||||
return true;
|
||||
}*/
|
||||
|
||||
if (!NPCEAICanProceed())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (pathCounter == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update START");
|
||||
|
||||
if (!NPCEAICanProceed())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.targetPlayer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
EntityUtilities.CheckForClosedDoor(this.theEntity);
|
||||
|
||||
EntityUtilities.CheckDistanceToLeader(this.theEntity, this.targetPlayer);
|
||||
|
||||
if (this.relocateTicks > 0)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update 2");
|
||||
if (!this.theEntity.navigator.noPathAndNotPlanningOne())
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update 3");
|
||||
this.relocateTicks--;
|
||||
this.theEntity.moveHelper.SetFocusPos(this.entityTarget.position);
|
||||
return;
|
||||
}
|
||||
this.relocateTicks = 0;
|
||||
}
|
||||
|
||||
Vector3 vector2 = this.entityTarget.position;
|
||||
|
||||
Vector3 a = theEntity.position - vector2;
|
||||
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update entityTargetPosn: " + vector2);
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update a: " + a);
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update a.sqrMagnitude: " + a.sqrMagnitude);
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update this.OwnerID: " + this.theEntity.Buffs.GetCustomVar("$Leader"));
|
||||
|
||||
theEntity.SetLookPosition(vector2);
|
||||
theEntity.RotateTo(vector2.x, vector2.y + 2, vector2.z, 8f, 8f);
|
||||
|
||||
if (a.sqrMagnitude < 1f)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update 6");
|
||||
this.entityPlayerVel = this.entityPlayerVel * 0.7f + a * 0.3f;
|
||||
}
|
||||
this.entityPlayerPos = vector2;
|
||||
|
||||
this.theEntity.moveHelper.CalcIfUnreachablePos();
|
||||
float num2;
|
||||
float num3;
|
||||
|
||||
num2 = 1.095f;
|
||||
num3 = Utils.FastMax(0.7f, num2 - 0.35f);
|
||||
|
||||
float num4 = num3 * num3;
|
||||
float num5 = 4f;
|
||||
if (this.theEntity.IsFeral)
|
||||
{
|
||||
num5 = 8f;
|
||||
}
|
||||
num5 = base.RandomFloat * num5;
|
||||
float targetXZDistanceSq = this.GetTargetXZDistanceSq(num5);
|
||||
float num6 = vector2.y - this.theEntity.position.y;
|
||||
float num7 = Utils.FastAbs(num6);
|
||||
bool flag = targetXZDistanceSq <= num4 && num7 < 1f;
|
||||
if (!flag)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update 9");
|
||||
if (num7 < 3f && !PathFinderThread.Instance.IsCalculatingPath(this.theEntity.entityId))
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update 10");
|
||||
PathEntity path = this.theEntity.navigator.getPath();
|
||||
if (path != null && path.NodeCountRemaining() <= 2)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update 11");
|
||||
this.pathCounter = 0;
|
||||
}
|
||||
}
|
||||
int num = this.pathCounter - 1;
|
||||
this.pathCounter = num;
|
||||
if (num <= 0 && this.theEntity.CanNavigatePath() && !PathFinderThread.Instance.IsCalculatingPath(this.theEntity.entityId))
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update 12");
|
||||
this.pathCounter = 6 + base.GetRandom(10);
|
||||
//Vector3 moveToLocation = this.GetMoveToLocation(num3);
|
||||
Vector3 moveToLocation = EntityUtilities.GetMoveToLocation(this.theEntity, this.entityTarget.position, 5);
|
||||
if (moveToLocation.y - this.theEntity.position.y < -8f)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update 13");
|
||||
this.pathCounter += 40;
|
||||
if (base.RandomFloat < 0.2f)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update 14");
|
||||
this.seekPosOffset.x = this.seekPosOffset.x + (base.RandomFloat * 0.6f - 0.3f);
|
||||
this.seekPosOffset.y = this.seekPosOffset.y + (base.RandomFloat * 0.6f - 0.3f);
|
||||
}
|
||||
moveToLocation.x += this.seekPosOffset.x;
|
||||
moveToLocation.z += this.seekPosOffset.y;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update 15");
|
||||
float num8 = (moveToLocation - this.theEntity.position).magnitude - 5f;
|
||||
if (num8 > 0f)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update 16");
|
||||
if (num8 > 60f)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update 17");
|
||||
num8 = 60f;
|
||||
}
|
||||
this.pathCounter += (int)(num8 / 20f * 20f);
|
||||
}
|
||||
}
|
||||
this.theEntity.FindPath(moveToLocation, this.theEntity.GetMoveSpeedAggro(), true, this);
|
||||
}
|
||||
}
|
||||
if (this.theEntity.Climbing)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update 18");
|
||||
return;
|
||||
}
|
||||
if (!flag)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update 20");
|
||||
if (this.theEntity.navigator.noPathAndNotPlanningOne() && this.pathCounter > 0 && num6 < 2.1f)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update 21");
|
||||
//Vector3 moveToLocation2 = this.GetMoveToLocation(num3);
|
||||
Vector3 moveToLocation2 = EntityUtilities.GetMoveToLocation(this.theEntity, this.entityTarget.position, 5);
|
||||
this.theEntity.moveHelper.SetMoveTo(moveToLocation2, true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update 22");
|
||||
this.theEntity.moveHelper.Stop();
|
||||
this.pathCounter = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private float GetTargetXZDistanceSq(float estimatedTicks)
|
||||
{
|
||||
Vector3 vector = this.entityTarget.position;
|
||||
vector += this.entityPlayerVel * estimatedTicks;
|
||||
Vector3 vector2 = this.theEntity.position + this.theEntity.motion * estimatedTicks - vector;
|
||||
vector2.y = 0f;
|
||||
return vector2.sqrMagnitude;
|
||||
}
|
||||
|
||||
private Vector3 GetMoveToLocation(float maxDist)
|
||||
{
|
||||
Vector3 vector = this.entityTarget.position;
|
||||
vector += this.entityPlayerVel * 6f;
|
||||
vector = this.entityTarget.world.FindSupportingBlockPos(vector);
|
||||
if (maxDist > 0f)
|
||||
{
|
||||
Vector3 vector2 = new Vector3(this.theEntity.position.x, vector.y, this.theEntity.position.z);
|
||||
Vector3 vector3 = vector - vector2;
|
||||
float magnitude = vector3.magnitude;
|
||||
if (magnitude < 3f)
|
||||
{
|
||||
if (magnitude <= maxDist)
|
||||
{
|
||||
float num = vector.y - this.theEntity.position.y;
|
||||
if (num < -3f || num > 1.5f)
|
||||
{
|
||||
return vector;
|
||||
}
|
||||
return vector2;
|
||||
}
|
||||
else
|
||||
{
|
||||
vector3 *= maxDist / magnitude;
|
||||
Vector3 vector4 = vector - vector3;
|
||||
vector4.y += 0.51f;
|
||||
Vector3i pos = World.worldToBlockPos(vector4);
|
||||
BlockValue block = this.entityTarget.world.GetBlock(pos);
|
||||
Block block2 = block.Block;
|
||||
if (block2.PathType <= 0)
|
||||
{
|
||||
RaycastHit raycastHit;
|
||||
if (Physics.Raycast(vector4 - Origin.position, Vector3.down, out raycastHit, 1.02f, 1082195968))
|
||||
{
|
||||
vector4.y = raycastHit.point.y + Origin.position.y;
|
||||
return vector4;
|
||||
}
|
||||
if (block2.IsElevator((int)block.rotation))
|
||||
{
|
||||
vector4.y = vector.y;
|
||||
return vector4;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return vector;
|
||||
}
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
this.entityTarget = null;
|
||||
this.targetPlayer = null;
|
||||
}
|
||||
|
||||
private EntityPlayer targetPlayer;
|
||||
private EntityAlive entityTarget;
|
||||
private Vector3 entityPlayerVel;
|
||||
private Vector3 entityPlayerPos;
|
||||
private int relocateTicks;
|
||||
private int OwnerID = 0;
|
||||
private int pathCounter;
|
||||
private Vector2 seekPosOffset;
|
||||
}
|
||||
232
Scripts/EAI/NPCs/v1/EAISetAsTargetIfHurtCompanion.cs
Normal file
232
Scripts/EAI/NPCs/v1/EAISetAsTargetIfHurtCompanion.cs
Normal file
@@ -0,0 +1,232 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Scripting;
|
||||
|
||||
[Preserve]
|
||||
public class EAISetAsTargetIfHurtCompanion : EAITarget
|
||||
{
|
||||
public override void Init(EntityAlive _theEntity)
|
||||
{
|
||||
base.Init(_theEntity, 0f, false);
|
||||
this.MutexBits = 1;
|
||||
}
|
||||
|
||||
public override void SetData(DictionarySave<string, string> data)
|
||||
{
|
||||
base.SetData(data);
|
||||
this.targetClasses = new List<EAISetAsTargetIfHurtCompanion.TargetClass>();
|
||||
string text;
|
||||
if (data.TryGetValue("class", out text))
|
||||
{
|
||||
string[] array = text.Split(',', StringSplitOptions.None);
|
||||
for (int i = 0; i < array.Length; i++)
|
||||
{
|
||||
EAISetAsTargetIfHurtCompanion.TargetClass item = default(EAISetAsTargetIfHurtCompanion.TargetClass);
|
||||
item.type = EntityFactory.GetEntityType(array[i]);
|
||||
this.targetClasses.Add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool NPCEAICanProceed()
|
||||
{
|
||||
bool result = true;
|
||||
|
||||
if (this.theEntity.Buffs.GetCustomVar("onMission") == 1f ||
|
||||
this.theEntity.Buffs.GetCustomVar("$FR_NPC_Respawn") == 1f ||
|
||||
this.theEntity.Buffs.GetCustomVar("$FR_NPC_Hidden") == 1f
|
||||
)
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-NPCEAICanProceed 1");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool stopAttacking = this.theEntity.Buffs.HasBuff("FuriousRamsayBuffPauseAttack") ||
|
||||
this.theEntity.Buffs.HasBuff("buffNPCModStopAttacking") ||
|
||||
this.theEntity.Buffs.HasBuff("FuriousRamsayStandStill");
|
||||
|
||||
if (stopAttacking)
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-NPCEAICanProceed 2");
|
||||
this.theEntity.SetRevengeTarget(null);
|
||||
this.theEntity.SetAttackTarget(null, 0);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public override bool CanExecute()
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-CanExecute START");
|
||||
|
||||
if (!NPCEAICanProceed())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
EntityAlive revengeTarget = this.theEntity.GetRevengeTarget();
|
||||
EntityAlive attackTarget = this.theEntity.GetAttackTarget();
|
||||
|
||||
if (revengeTarget == null)
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-CanExecute revengeTarget IS NULL");
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-CanExecute revengeTarget: " + revengeTarget.EntityClass.entityClassName);
|
||||
}
|
||||
if (attackTarget == null)
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-CanExecute attackTarget IS NULL");
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-CanExecute attackTarget: " + attackTarget.EntityClass.entityClassName);
|
||||
}
|
||||
|
||||
bool bIsValidTarget = true;
|
||||
|
||||
if (revengeTarget)
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtRebirth-CanExecute revengeTarget.EntityName: " + revengeTarget.EntityName);
|
||||
//Log.Out("EAISetAsTargetIfHurtRebirth-CanExecute revengeTarget.entityType: " + revengeTarget.entityType);
|
||||
//Log.Out("EAISetAsTargetIfHurtRebirth-CanExecute this.theEntity.entityType: " + this.theEntity.entityType);
|
||||
|
||||
//bIsValidTarget = !EntityTargetingUtilities.IsAlly(this.theEntity, revengeTarget);
|
||||
bIsValidTarget = RebirthUtilities.VerifyFactionStanding(this.theEntity, revengeTarget); //revengeTarget.entityType != this.theEntity.entityType;
|
||||
//Log.Out("EAISetAsTargetIfHurtRebirth-CanExecute bIsValidTarget: " + bIsValidTarget);
|
||||
}
|
||||
|
||||
if (revengeTarget && revengeTarget != attackTarget && bIsValidTarget)
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-CanExecute 1");
|
||||
if (this.targetClasses != null)
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-CanExecute 2");
|
||||
bool flag = false;
|
||||
Type type = revengeTarget.GetType();
|
||||
for (int i = 0; i < this.targetClasses.Count; i++)
|
||||
{
|
||||
EAISetAsTargetIfHurtCompanion.TargetClass targetClass = this.targetClasses[i];
|
||||
if (targetClass.type != null && targetClass.type.IsAssignableFrom(type))
|
||||
{
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!flag)
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-CanExecute 3");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (attackTarget != null && attackTarget.IsAlive() && base.RandomFloat < 0.66f)
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-CanExecute 4");
|
||||
this.theEntity.SetRevengeTarget(null);
|
||||
return false;
|
||||
}
|
||||
if (base.check(revengeTarget))
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-CanExecute 5");
|
||||
return true;
|
||||
}
|
||||
Vector3 vector = this.theEntity.position - revengeTarget.position;
|
||||
float num = EntityClass.list[this.theEntity.entityClass].SearchArea * 0.5f;
|
||||
vector = revengeTarget.position + vector.normalized * (num * 0.5f);
|
||||
Vector3 vector2 = this.manager.random.RandomOnUnitSphere * num;
|
||||
vector.x += vector2.x;
|
||||
vector.z += vector2.z;
|
||||
Vector3i vector3i = World.worldToBlockPos(vector);
|
||||
int height = (int)this.theEntity.world.GetHeight(vector3i.x, vector3i.z);
|
||||
if (height > 0)
|
||||
{
|
||||
vector.y = (float)height;
|
||||
}
|
||||
int num2 = this.theEntity.CalcInvestigateTicks(1200, revengeTarget);
|
||||
this.theEntity.SetInvestigatePosition(vector, num2, true);
|
||||
if (this.theEntity.entityType == EntityType.Zombie)
|
||||
{
|
||||
num2 /= 6;
|
||||
}
|
||||
this.theEntity.SetAlertTicks(num2);
|
||||
this.theEntity.SetRevengeTarget(null);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void Start()
|
||||
{
|
||||
this.theEntity.SetAttackTarget(this.theEntity.GetRevengeTarget(), 400);
|
||||
this.viewAngleSave = this.theEntity.GetMaxViewAngle();
|
||||
this.theEntity.SetMaxViewAngle(270f);
|
||||
this.viewAngleRestoreCounter = 100;
|
||||
base.Start();
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
if (!NPCEAICanProceed())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-Update START");
|
||||
|
||||
if (this.viewAngleRestoreCounter > 0)
|
||||
{
|
||||
this.viewAngleRestoreCounter--;
|
||||
if (this.viewAngleRestoreCounter == 0)
|
||||
{
|
||||
this.restoreViewAngle();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Continue()
|
||||
{
|
||||
if (!NPCEAICanProceed())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-Continue START");
|
||||
|
||||
bool revengeTargetIsNull = (this.theEntity.GetRevengeTarget() != null);
|
||||
bool revengeAndAttackTargetDifferent = (this.theEntity.GetAttackTarget() != this.theEntity.GetRevengeTarget());
|
||||
bool baseContinue = base.Continue();
|
||||
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-Continue revengeTargetIsNull: " + revengeTargetIsNull);
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-Continue revengeAndAttackTargetDifferent: " + revengeAndAttackTargetDifferent);
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-Continue baseContinue: " + baseContinue);
|
||||
|
||||
return (!revengeTargetIsNull || !revengeAndAttackTargetDifferent) && baseContinue;
|
||||
}
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
base.Reset();
|
||||
this.restoreViewAngle();
|
||||
}
|
||||
|
||||
private void restoreViewAngle()
|
||||
{
|
||||
if (this.viewAngleSave > 0f)
|
||||
{
|
||||
this.theEntity.SetMaxViewAngle(this.viewAngleSave);
|
||||
this.viewAngleSave = 0f;
|
||||
this.viewAngleRestoreCounter = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private List<EAISetAsTargetIfHurtCompanion.TargetClass> targetClasses;
|
||||
private float viewAngleSave;
|
||||
private int viewAngleRestoreCounter;
|
||||
private struct TargetClass
|
||||
{
|
||||
public Type type;
|
||||
}
|
||||
}
|
||||
415
Scripts/EAI/NPCs/v1/EAISetNearestEntityAsTargetCompanion.cs
Normal file
415
Scripts/EAI/NPCs/v1/EAISetNearestEntityAsTargetCompanion.cs
Normal file
@@ -0,0 +1,415 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Scripting;
|
||||
using static EntityDrone;
|
||||
using static UnityEngine.UI.GridLayoutGroup;
|
||||
|
||||
[Preserve]
|
||||
public class EAISetNearestEntityAsTargetCompanion : EAITarget
|
||||
{
|
||||
public override void Init(EntityAlive _theEntity)
|
||||
{
|
||||
base.Init(_theEntity, 25f, true);
|
||||
this.MutexBits = 1;
|
||||
this.sorter = new EAISetNearestEntityAsTargetSorter(_theEntity);
|
||||
}
|
||||
|
||||
public override void SetData(DictionarySave<string, string> data)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-SetData START");
|
||||
base.SetData(data);
|
||||
this.targetClasses = new List<EAISetNearestEntityAsTargetCompanion.TargetClass>();
|
||||
string text;
|
||||
if (data.TryGetValue("class", out text))
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-SetData 1");
|
||||
string[] array = text.Split(',', StringSplitOptions.None);
|
||||
for (int i = 0; i < array.Length; i += 3)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-SetData i: " + i);
|
||||
EAISetNearestEntityAsTargetCompanion.TargetClass targetClass;
|
||||
targetClass.type = EntityFactory.GetEntityType(array[i]);
|
||||
targetClass.hearDistMax = 0f;
|
||||
if (i + 1 < array.Length)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-SetData 2");
|
||||
targetClass.hearDistMax = StringParsers.ParseFloat(array[i + 1], 0, -1, NumberStyles.Any);
|
||||
}
|
||||
if (targetClass.hearDistMax == 0f)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-SetData 3");
|
||||
targetClass.hearDistMax = 50f;
|
||||
}
|
||||
targetClass.seeDistMax = 0f;
|
||||
if (i + 2 < array.Length)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-SetData 4");
|
||||
targetClass.seeDistMax = StringParsers.ParseFloat(array[i + 2], 0, -1, NumberStyles.Any);
|
||||
}
|
||||
if (targetClass.type == typeof(EntityPlayer))
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-SetData 5");
|
||||
this.playerTargetClassIndex = this.targetClasses.Count;
|
||||
}
|
||||
this.targetClasses.Add(targetClass);
|
||||
}
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-SetData 6");
|
||||
}
|
||||
}
|
||||
|
||||
public bool NPCEAICanProceed()
|
||||
{
|
||||
bool result = true;
|
||||
|
||||
if (this.theEntity.Buffs.GetCustomVar("onMission") == 1f ||
|
||||
this.theEntity.Buffs.GetCustomVar("$FR_NPC_Respawn") == 1f ||
|
||||
this.theEntity.Buffs.GetCustomVar("$FR_NPC_Hidden") == 1f
|
||||
)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-NPCEAICanProceed 1");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool stopAttacking = this.theEntity.Buffs.HasBuff("FuriousRamsayBuffPauseAttack") ||
|
||||
this.theEntity.Buffs.HasBuff("buffNPCModStopAttacking") ||
|
||||
this.theEntity.Buffs.HasBuff("FuriousRamsayStandStill");
|
||||
|
||||
if (stopAttacking)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-NPCEAICanProceed 2");
|
||||
this.theEntity.SetRevengeTarget(null);
|
||||
this.theEntity.SetAttackTarget(null, 0);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public override bool CanExecute()
|
||||
{
|
||||
if (!NPCEAICanProceed())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
FindTarget();
|
||||
|
||||
if (!closeTargetEntity)
|
||||
{
|
||||
//Log.Out($"! closeTargetEntity: {closeTargetEntity}");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (closeTargetEntity is EntityPlayer)
|
||||
{
|
||||
//targetPlayer = (closeTargetEntity as EntityPlayer); // wait, what is this used for?
|
||||
closeTargetEntity = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
targetEntity = closeTargetEntity;
|
||||
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-CanExecute this.targetEntity: " + this.targetEntity.EntityClass.entityClassName);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void FindTarget()
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget START");
|
||||
this.closeTargetDist = float.MaxValue;
|
||||
this.closeTargetEntity = null;
|
||||
float seeDistance = RebirthVariables.customDistanceHunting; //this.theEntity.GetSeeDistance();
|
||||
|
||||
if (this.theEntity.Buffs.HasBuff("buffNPCModFullControlMode") && ((EntityNPCRebirth)this.theEntity).currentOrder == (int)EntityUtilities.Orders.Follow)
|
||||
{
|
||||
seeDistance = RebirthVariables.customDistanceFullControl;
|
||||
}
|
||||
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget this.targetClasses.Count " + this.targetClasses.Count);
|
||||
for (int i = 0; i < this.targetClasses.Count; i++)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget i: " + i);
|
||||
EAISetNearestEntityAsTargetCompanion.TargetClass targetClass = this.targetClasses[i];
|
||||
float num = 100;
|
||||
/*if (targetClass.seeDistMax != 0f)
|
||||
{
|
||||
float v = (targetClass.seeDistMax < 0f) ? (-targetClass.seeDistMax) : (targetClass.seeDistMax * this.theEntity.senseScale);
|
||||
num = Utils.FastMin(num, v);
|
||||
}*/
|
||||
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget seeDistance " + seeDistance);
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget targetClass.seeDistMax " + targetClass.seeDistMax);
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget num " + num);
|
||||
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget this.theEntity.IsSleeping " + this.theEntity.IsSleeping);
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget this.theEntity.HasInvestigatePosition " + this.theEntity.HasInvestigatePosition);
|
||||
|
||||
bool hasInvestigatePosition = false; // this.theEntity.HasInvestigatePosition;
|
||||
|
||||
if (!this.theEntity.IsSleeping && !hasInvestigatePosition)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget 1");
|
||||
this.theEntity.world.GetEntitiesInBounds(targetClass.type, BoundsUtils.ExpandBounds(this.theEntity.boundingBox, num, num, num), EAISetNearestEntityAsTargetCompanion.list);
|
||||
EAISetNearestEntityAsTargetCompanion.list.Sort(this.sorter);
|
||||
int j = 0;
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget EAISetNearestEntityAsTargetCompanion.list.Count " + EAISetNearestEntityAsTargetCompanion.list.Count);
|
||||
while (j < EAISetNearestEntityAsTargetCompanion.list.Count)
|
||||
{
|
||||
EntityAlive entityAlive = (EntityAlive)EAISetNearestEntityAsTargetCompanion.list[j];
|
||||
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget j: " + j + " / entityAlive: " + entityAlive.EntityClass.entityClassName);
|
||||
|
||||
//if (!(entityAlive is EntityDrone))
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget 2");
|
||||
bool check = base.check(entityAlive);
|
||||
bool shouldAttack = RebirthUtilities.VerifyFactionStanding(this.theEntity, entityAlive);
|
||||
|
||||
if (!check && entityAlive.entityId != this.theEntity.entityId && shouldAttack)
|
||||
{
|
||||
int OwnerID = (int)this.theEntity.Buffs.GetCustomVar("$Leader");
|
||||
|
||||
if (OwnerID > 0)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget HAS OWNER");
|
||||
EntityPlayer entityPlayer = (EntityPlayer)this.theEntity.world.GetEntity(OwnerID);
|
||||
if (entityPlayer != null)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget FOUND OWNER");
|
||||
if (entityPlayer.CanEntityBeSeen(entityAlive))
|
||||
{
|
||||
check = true;
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget OWNER CAN SEE TARGET: " + entityAlive.EntityClass.entityClassName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget check: " + check);
|
||||
|
||||
if (check && (!entityAlive.IsSleeping || entityAlive is EntityAnimalSnake))
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget entityAlive.EntityClass.entityClassName: " + entityAlive.EntityClass.entityClassName);
|
||||
float distance = this.theEntity.GetDistance(entityAlive);
|
||||
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget this.closeTargetDist: " + this.closeTargetDist);
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget distance: " + distance);
|
||||
|
||||
bool bypassDistance = (entityAlive.Buffs.GetCustomVar("$FuriousRamsayAttacking") == 1f ||
|
||||
entityAlive.Buffs.GetCustomVar("$FuriousRamsayAttacked") == 1f ||
|
||||
this.theEntity.Buffs.HasBuff("buffNPCModThreatControlMode")
|
||||
);
|
||||
|
||||
if (bypassDistance && distance > 50)
|
||||
{
|
||||
bypassDistance = false;
|
||||
}
|
||||
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget bypassDistance: " + bypassDistance);
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget distance: " + distance);
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget seeDistance: " + seeDistance);
|
||||
|
||||
if (bypassDistance || distance < seeDistance)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget A");
|
||||
this.closeTargetDist = distance;
|
||||
this.closeTargetEntity = entityAlive;
|
||||
this.lastSeenPos = entityAlive.position;
|
||||
|
||||
//Log.Out($"EAI SetNearestEntityAsTargetCompanion - FindTarget entityAlive: {entityAlive.EntityClass.entityClassName}");
|
||||
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget B");
|
||||
int OwnerID = (int)this.theEntity.Buffs.GetCustomVar("$Leader");
|
||||
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget OwnerID: " + OwnerID);
|
||||
|
||||
EntityPlayer owner = null;
|
||||
|
||||
if (OwnerID > 0)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget HAS OWNER");
|
||||
EntityPlayer entityPlayer = (EntityPlayer)this.theEntity.world.GetEntity(OwnerID);
|
||||
if (entityPlayer != null)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget FOUND OWNER");
|
||||
owner = entityPlayer;
|
||||
}
|
||||
}
|
||||
|
||||
if (owner != null)
|
||||
{
|
||||
distance = owner.GetDistance(entityAlive);
|
||||
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget DISTANCE TO OWNER: " + distance);
|
||||
|
||||
if (distance < seeDistance + 5)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget OWNER distance: " + distance);
|
||||
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget entityAlive: " + entityAlive.EntityClass.entityClassName);
|
||||
|
||||
this.closeTargetDist = distance;
|
||||
this.closeTargetEntity = entityAlive;
|
||||
this.lastSeenPos = entityAlive.position;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
j++;
|
||||
}
|
||||
}
|
||||
}
|
||||
EAISetNearestEntityAsTargetCompanion.list.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
//Log.Out($"FindTarget END - closeTargetEntity: {closeTargetEntity}");
|
||||
}
|
||||
|
||||
public override void Start()
|
||||
{
|
||||
this.theEntity.SetAttackTarget(this.targetEntity, 200);
|
||||
this.theEntity.ConditionalTriggerSleeperWakeUp();
|
||||
base.Start();
|
||||
}
|
||||
|
||||
public override bool Continue()
|
||||
{
|
||||
if (!NPCEAICanProceed())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.targetEntity.IsDead() || this.theEntity.distraction != null)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-Continue 5");
|
||||
if (this.theEntity.GetAttackTarget() == this.targetEntity)
|
||||
{
|
||||
//Log.Out("SetNearestEntityAsTarget - Continue - GetAttackTarget() == this.targetEntity and isDead or distraction not null");
|
||||
this.theEntity.SetAttackTarget(null, 0);
|
||||
}
|
||||
//Log.Out($"returning false here");
|
||||
return false;
|
||||
}
|
||||
|
||||
this.findTime += 0.05f;
|
||||
|
||||
if (this.findTime > 2f)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-Continue 7");
|
||||
this.findTime = 0f;
|
||||
this.FindTarget();
|
||||
if (this.closeTargetEntity && this.closeTargetEntity != this.targetEntity)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-Continue we have a close target and its not equal to targetEntity return false");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.theEntity.GetAttackTarget() != this.targetEntity)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-Continue this.theEntity.GetAttackTarget() != this.targetEntity");
|
||||
return false;
|
||||
}
|
||||
|
||||
/*bool canISeeTarget = this.theEntity.CanEntityBeSeen(this.targetEntity);
|
||||
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-Continue 10");
|
||||
|
||||
if (this.theEntity.Buffs.GetCustomVar("$Leader") > 0)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-Continue 11");
|
||||
|
||||
if (this.targetEntity.Buffs.GetCustomVar("$FuriousRamsayAttacking") == 1f || this.targetEntity.Buffs.GetCustomVar("$FuriousRamsayAttacked") == 1f)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-Continue 12");
|
||||
canISeeTarget = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-Continue 13");
|
||||
EntityPlayer entityPlayer = (EntityPlayer)this.theEntity.world.GetEntity((int)this.theEntity.Buffs.GetCustomVar("$Leader"));
|
||||
if (entityPlayer != null)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-Continue 14");
|
||||
if (entityPlayer.CanEntityBeSeen(this.targetEntity))
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-Continue 15");
|
||||
canISeeTarget = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// replaced the vanilla base.check with our work around ignoring stealth
|
||||
bool isCheckGood = base.check(this.targetEntity);
|
||||
if (isCheckGood && canISeeTarget)
|
||||
{
|
||||
//Log.Out("SetNearestEntityAsTarget - Continue I can see and check true, this.targetEntity: " + this.targetEntity.EntityClass.entityClassName);
|
||||
this.theEntity.SetAttackTarget(this.targetEntity, 600);
|
||||
this.lastSeenPos = this.targetEntity.position;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (this.theEntity.GetDistanceSq(this.lastSeenPos) < 2.25f)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-Continue 17");
|
||||
this.lastSeenPos = Vector3.zero;
|
||||
}
|
||||
|
||||
//Log.Out($"SetNearestEntityAsTarget - Continue Setting target to null targetEntity: {targetEntity}");
|
||||
this.theEntity.SetAttackTarget(null, 0);
|
||||
int num = this.theEntity.CalcInvestigateTicks(Constants.cEnemySenseMemory * 20, this.targetEntity);
|
||||
|
||||
if (this.lastSeenPos != Vector3.zero)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-Continue 18");
|
||||
this.theEntity.SetInvestigatePosition(this.lastSeenPos, num, true);
|
||||
}*/
|
||||
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-Continue 19");
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
this.targetEntity = null;
|
||||
//this.targetPlayer = null;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Format("{0}, {1}", base.ToString(), this.targetEntity ? this.targetEntity.EntityName : "");
|
||||
}
|
||||
|
||||
private const float cHearDistMax = 50f;
|
||||
private List<EAISetNearestEntityAsTargetCompanion.TargetClass> targetClasses;
|
||||
private int playerTargetClassIndex = -1;
|
||||
private float closeTargetDist;
|
||||
private EntityAlive closeTargetEntity;
|
||||
private EntityAlive targetEntity;
|
||||
//private EntityPlayer targetPlayer;
|
||||
private Vector3 lastSeenPos;
|
||||
private float findTime;
|
||||
private float senseSoundTime;
|
||||
private EAISetNearestEntityAsTargetSorter sorter;
|
||||
private static List<Entity> list = new List<Entity>();
|
||||
private struct TargetClass
|
||||
{
|
||||
public Type type;
|
||||
public float hearDistMax;
|
||||
public float seeDistMax;
|
||||
}
|
||||
}
|
||||
111
Scripts/EAI/NPCs/v1/EAIWanderCompanion.cs
Normal file
111
Scripts/EAI/NPCs/v1/EAIWanderCompanion.cs
Normal file
@@ -0,0 +1,111 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Scripting;
|
||||
|
||||
[Preserve]
|
||||
public class EAIWanderCompanion : EAIWander
|
||||
{
|
||||
public bool NPCEAICanProceed(bool skipTargetVerification = false)
|
||||
{
|
||||
if (this.theEntity.Buffs.GetCustomVar("$Leader") > 0f)
|
||||
{
|
||||
//Log.Out("EAIWanderCompanion-NPCEAICanProceed 1");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (((EntityNPCRebirth)this.theEntity).currentOrder > 0)
|
||||
{
|
||||
//Log.Out("EAIWanderCompanion-NPCEAICanProceed 1a");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.Buffs.GetCustomVar("onMission") == 1f ||
|
||||
this.theEntity.Buffs.GetCustomVar("$FR_NPC_Respawn") == 1f ||
|
||||
this.theEntity.Buffs.GetCustomVar("$FR_NPC_Hidden") == 1f
|
||||
)
|
||||
{
|
||||
//Log.Out("EAIWanderCompanion-NPCEAICanProceed 1b");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.GetAttackTarget() != null)
|
||||
{
|
||||
//Log.Out("EAIWanderCompanion-NPCEAICanProceed 2");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.Buffs.HasBuff("buffTalkingTo"))
|
||||
{
|
||||
//Log.Out("EAIWanderCompanion-NPCEAICanProceed 3");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.sleepingOrWakingUp)
|
||||
{
|
||||
//Log.Out("EAIWanderCompanion-NPCEAICanProceed 4");
|
||||
return false;
|
||||
}
|
||||
if (this.theEntity.GetTicksNoPlayerAdjacent() >= 120)
|
||||
{
|
||||
//Log.Out("EAIWanderCompanion-NPCEAICanProceed 5");
|
||||
return false;
|
||||
}
|
||||
if (this.theEntity.bodyDamage.CurrentStun != EnumEntityStunType.None)
|
||||
{
|
||||
//Log.Out("EAIWanderCompanion-NPCEAICanProceed 6");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool CanExecute()
|
||||
{
|
||||
if (!NPCEAICanProceed())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.sleepingOrWakingUp)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (this.theEntity.GetTicksNoPlayerAdjacent() >= 120)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (this.theEntity.bodyDamage.CurrentStun != EnumEntityStunType.None)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
int num = (int)(200f * this.executeWaitTime);
|
||||
if (base.GetRandom(1000) >= num)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void Start()
|
||||
{
|
||||
int num = 10;
|
||||
this.theEntity.FindPath(RandomPositionGenerator.Calc(this.theEntity, num, num), this.theEntity.GetMoveSpeed(), false, this);
|
||||
}
|
||||
|
||||
public override bool Continue()
|
||||
{
|
||||
if (!NPCEAICanProceed())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//Log.Out("EAIWanderCompanion-Continue this.theEntity.bodyDamage.CurrentStun == EnumEntityStunType.None: " + (this.theEntity.bodyDamage.CurrentStun == EnumEntityStunType.None));
|
||||
//Log.Out("EAIWanderCompanion-Continue this.theEntity.moveHelper.BlockedTime <= 0.3f: " + (this.theEntity.moveHelper.BlockedTime <= 0.3f));
|
||||
//Log.Out("EAIWanderCompanion-Continue !this.theEntity.navigator.noPathAndNotPlanningOne(): " + !this.theEntity.navigator.noPathAndNotPlanningOne());
|
||||
|
||||
bool result = this.theEntity.bodyDamage.CurrentStun == EnumEntityStunType.None && this.theEntity.moveHelper.BlockedTime <= 0.3f && !this.theEntity.navigator.noPathAndNotPlanningOne();
|
||||
|
||||
//Log.Out("EAIWanderCompanion-Continue result: " + result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
909
Scripts/EAI/_prev/EAIApproachAndAttackTargetCompanion2.cs
Normal file
909
Scripts/EAI/_prev/EAIApproachAndAttackTargetCompanion2.cs
Normal file
@@ -0,0 +1,909 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
using System.Xml.Linq;
|
||||
using GamePath;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Scripting;
|
||||
|
||||
[Preserve]
|
||||
public class EAIApproachAndAttackTargetCompanion : EAIBase
|
||||
{
|
||||
public override void Init(EntityAlive _theEntity)
|
||||
{
|
||||
base.Init(_theEntity);
|
||||
this.MutexBits = 3;
|
||||
this.executeDelay = 0.1f;
|
||||
}
|
||||
|
||||
public override void SetData(DictionarySave<string, string> data)
|
||||
{
|
||||
base.SetData(data);
|
||||
this.targetClasses = new List<EAIApproachAndAttackTargetCompanion.TargetClass>();
|
||||
string text;
|
||||
if (data.TryGetValue("class", out text))
|
||||
{
|
||||
string[] array = text.Split(',', StringSplitOptions.None);
|
||||
for (int i = 0; i < array.Length; i += 2)
|
||||
{
|
||||
EAIApproachAndAttackTargetCompanion.TargetClass targetClass = default(EAIApproachAndAttackTargetCompanion.TargetClass);
|
||||
targetClass.type = EntityFactory.GetEntityType(array[i]);
|
||||
targetClass.chaseTimeMax = 0f;
|
||||
if (i + 1 < array.Length)
|
||||
{
|
||||
targetClass.chaseTimeMax = StringParsers.ParseFloat(array[i + 1], 0, -1, NumberStyles.Any);
|
||||
}
|
||||
this.targetClasses.Add(targetClass);
|
||||
if (targetClass.type == typeof(EntityEnemyAnimal))
|
||||
{
|
||||
targetClass.type = typeof(EntityAnimalSnake);
|
||||
this.targetClasses.Add(targetClass);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool NPCEAICanProceed(bool skipTargetVerification = false)
|
||||
{
|
||||
bool result = true;
|
||||
|
||||
if (this.theEntity.Buffs.GetCustomVar("onMission") == 1f ||
|
||||
this.theEntity.Buffs.GetCustomVar("$FR_NPC_Respawn") == 1f ||
|
||||
this.theEntity.Buffs.GetCustomVar("$FR_NPC_Hidden") == 1f
|
||||
)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-NPCEAICanProceed 1");
|
||||
return false;
|
||||
}
|
||||
|
||||
EntityUtilities.CheckDistanceToLeader(this.theEntity, this.targetPlayer);
|
||||
|
||||
this.entityTarget = this.theEntity.GetAttackTarget();
|
||||
|
||||
if (!skipTargetVerification && this.entityTarget == null)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-NPCEAICanProceed 2b");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.entityTarget != null)
|
||||
{
|
||||
if (this.entityTarget.IsDead())
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-NPCEAICanProceed 2c");
|
||||
this.theEntity.SetRevengeTarget(null);
|
||||
this.theEntity.SetAttackTarget(null, 0);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!this.theEntity.CanEntityBeSeen(this.entityTarget))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-NPCEAICanProceed 2d");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool shouldAttack = RebirthUtilities.VerifyFactionStanding(this.theEntity, this.entityTarget);
|
||||
|
||||
if (!shouldAttack)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-NPCEAICanProceed 2e");
|
||||
//this.theEntity.SetAttackTarget(null, 0);
|
||||
//this.theEntity.SetRevengeTarget(null);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.HasAnyTags(FastTags<TagGroup.Global>.Parse("allyanimal")) ||
|
||||
this.theEntity.HasAnyTags(FastTags<TagGroup.Global>.Parse("melee")))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-NPCEAICanProceed IS MELEE");
|
||||
if (this.entityTarget.EntityClass.Tags.Test_AnySet(FastTags<TagGroup.Global>.Parse("nomeleetracking")))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-NPCEAICanProceed NO ANIMAL TRACKING");
|
||||
if (this.theEntity.position.y < this.entityTarget.position.y - 4)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-NPCEAICanProceed TOO HIGH: " + entityAlive.EntityClass.entityClassName);
|
||||
this.theEntity.SetRevengeTarget(null);
|
||||
this.theEntity.SetAttackTarget(null, 0);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-NPCEAICanProceed 2f, this.entityTarget: " + this.entityTarget.EntityClass.entityClassName);
|
||||
}
|
||||
|
||||
if (this.theEntity.emodel.IsRagdollActive)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-NPCEAICanProceed 3");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.sleepingOrWakingUp || this.theEntity.bodyDamage.CurrentStun != EnumEntityStunType.None || (this.theEntity.Jumping && !this.theEntity.isSwimming))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-NPCEAICanProceed 4");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool stopAttacking = this.theEntity.Buffs.HasBuff("FuriousRamsayBuffPauseAttack") ||
|
||||
this.theEntity.Buffs.HasBuff("buffNPCModStopAttacking") ||
|
||||
this.theEntity.Buffs.HasBuff("FuriousRamsayStandStill");
|
||||
|
||||
if (stopAttacking)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-NPCEAICanProceed 5");
|
||||
this.theEntity.SetRevengeTarget(null);
|
||||
this.theEntity.SetAttackTarget(null, 0);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.sleepingOrWakingUp || this.theEntity.bodyDamage.CurrentStun != EnumEntityStunType.None)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-NPCEAICanProceed 6");
|
||||
return false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public override bool CanExecute()
|
||||
{
|
||||
CheckAnimator();
|
||||
backingUp = false;
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-CanExecute START");
|
||||
|
||||
if (!NPCEAICanProceed(true))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.targetPlayer == null)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-CanExecute 2");
|
||||
this.OwnerID = (int)this.theEntity.Buffs.GetCustomVar("$Leader");
|
||||
|
||||
if (this.OwnerID > 0)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-CanExecute this.OwnerID: " + this.OwnerID);
|
||||
|
||||
EntityPlayer entityPlayer = (EntityPlayer)this.theEntity.world.GetEntity(this.OwnerID);
|
||||
if (entityPlayer != null)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-CanExecute FOUND OWNER");
|
||||
this.targetPlayer = entityPlayer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.entityTarget != null)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-CanExecute this.entityTarget: " + this.entityTarget.EntityClass.entityClassName);
|
||||
}
|
||||
else
|
||||
{
|
||||
checkEntityPosition();
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-CanExecute NO ATTACK TARGET");
|
||||
return false;
|
||||
}
|
||||
|
||||
Type type = this.entityTarget.GetType();
|
||||
for (int i = 0; i < this.targetClasses.Count; i++)
|
||||
{
|
||||
EAIApproachAndAttackTargetCompanion.TargetClass targetClass = this.targetClasses[i];
|
||||
if (targetClass.type != null && targetClass.type.IsAssignableFrom(type))
|
||||
{
|
||||
this.chaseTimeMax = targetClass.chaseTimeMax;
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-CanExecute 5");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-CanExecute 6");
|
||||
return false;
|
||||
}
|
||||
|
||||
public void checkEntityPosition()
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition START");
|
||||
|
||||
if (!this.theEntity.onGround) return;
|
||||
|
||||
if (this.entityTarget != null)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition HAS ATTACK TARGET");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.theEntity.navigator.noPathAndNotPlanningOne())
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition HAVE PATH");
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.theEntity.Buffs.GetCustomVar("CurrentOrder") != (int)EntityUtilities.Orders.Stay)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition NOT AT STAY");
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.theEntity.Buffs.HasBuff("buffTalkingTo"))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition IS TALKING");
|
||||
return;
|
||||
}
|
||||
|
||||
EntityAliveV2 npc = this.theEntity as EntityAliveV2;
|
||||
|
||||
if (npc == null)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition EXIT");
|
||||
return;
|
||||
}
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition STAY 1, npc.position: (" + npc.position + ") / npc.guardPosition: (" + npc.guardPosition + ")");
|
||||
|
||||
if (npc.guardPosition == Vector3.zero)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition NO GUARD POSITION");
|
||||
return;
|
||||
}
|
||||
|
||||
Vector3 entityPosition = EntityUtilities.CenterPosition(npc.position);
|
||||
Vector3 guardPosition = EntityUtilities.CenterPosition(npc.guardPosition);
|
||||
|
||||
if (entityPosition != guardPosition)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition STAY 2, npc.position: (" + npc.position + ") / npc.guardPosition: (" + npc.guardPosition + ")");
|
||||
npc.moveHelper.SetMoveTo(guardPosition, true);
|
||||
|
||||
npc.FindPath(
|
||||
npc.guardPosition,
|
||||
npc.GetMoveSpeedPanic(),
|
||||
false,
|
||||
null);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.theEntity.moveHelper.Stop();
|
||||
this.theEntity.speedForward = 0;
|
||||
/*Vector3 entityRotation = EntityUtilities.CenterPosition(npc.rotation);
|
||||
Vector3 guardRotation = EntityUtilities.CenterPosition(npc.guardLookPosition);
|
||||
|
||||
Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition STAY 3, npc.position: (" + npc.position + ") / npc.guardPosition: (" + npc.guardPosition + ")");
|
||||
|
||||
Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition entityRotation: " + entityRotation);
|
||||
Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition guardRotation: " + guardRotation);
|
||||
Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition npc.rotation: " + npc.rotation);
|
||||
Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition npc.guardLookPosition: " + npc.guardLookPosition);
|
||||
|
||||
if (entityRotation != guardRotation && npc.rotation != npc.guardLookPosition)
|
||||
{
|
||||
Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition STAY ROTATE");
|
||||
//npc.rotation = npc.guardLookPosition;
|
||||
|
||||
npc.SetLookPosition(npc.guardLookPosition);
|
||||
|
||||
npc.RotateTo(
|
||||
npc.guardLookPosition.x,
|
||||
npc.guardLookPosition.y,
|
||||
npc.guardLookPosition.z,
|
||||
360f,
|
||||
360f);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition STAY IS IN RIGHT POSITION AND ROTATION");
|
||||
}*/
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-checkEntityPosition SetLookPosition");
|
||||
npc.SetLookPosition(npc.guardLookPosition);
|
||||
npc.RotateTo(
|
||||
npc.guardLookPosition.x,
|
||||
npc.guardLookPosition.y,
|
||||
npc.guardLookPosition.z,
|
||||
360f,
|
||||
360f);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Start()
|
||||
{
|
||||
this.entityTargetPos = this.entityTarget.position;
|
||||
this.entityTargetVel = Vector3.zero;
|
||||
this.isTargetToEat = false;
|
||||
this.isEating = false;
|
||||
this.theEntity.IsEating = false;
|
||||
this.homeTimeout = (this.theEntity.IsSleeper ? 90f : this.chaseTimeMax);
|
||||
this.hasHome = (this.homeTimeout > 0f);
|
||||
this.isGoingHome = false;
|
||||
if (this.theEntity.ChaseReturnLocation == Vector3.zero)
|
||||
{
|
||||
this.theEntity.ChaseReturnLocation = (this.theEntity.IsSleeper ? this.theEntity.SleeperSpawnPosition : this.theEntity.position);
|
||||
}
|
||||
this.pathCounter = 0;
|
||||
this.relocateTicks = 0;
|
||||
this.attackTimeout = 5;
|
||||
animator = this.theEntity.emodel.avatarController.GetAnimator();
|
||||
}
|
||||
|
||||
public override bool Continue()
|
||||
{
|
||||
CheckAnimator();
|
||||
backingUp = false;
|
||||
|
||||
if (!NPCEAICanProceed())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool result = false;
|
||||
|
||||
EntityAlive attackTarget = this.theEntity.GetAttackTarget();
|
||||
|
||||
if (attackTarget != null)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Continue 1, attackTarget: " + attackTarget.EntityClass.entityClassName);
|
||||
}
|
||||
else
|
||||
{
|
||||
checkEntityPosition();
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Continue NO ATTACK TARGET");
|
||||
}
|
||||
|
||||
if (this.isGoingHome)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Continue 3, " + result);
|
||||
result = !attackTarget && this.theEntity.ChaseReturnLocation != Vector3.zero;
|
||||
return result;
|
||||
}
|
||||
|
||||
result = attackTarget && !(attackTarget != this.entityTarget);
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Continue 4, " + result);
|
||||
return result;
|
||||
}
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
this.theEntity.IsEating = false;
|
||||
this.theEntity.moveHelper.Stop();
|
||||
if (this.blockTargetTask != null)
|
||||
{
|
||||
this.blockTargetTask.canExecute = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void CheckAnimator()
|
||||
{
|
||||
if (animator && !backingUp)
|
||||
{
|
||||
animator.SetBool("isBackingUp", false);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
CheckAnimator();
|
||||
backingUp = false;
|
||||
|
||||
if (!NPCEAICanProceed())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.theEntity.Climbing)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 19");
|
||||
return;
|
||||
}
|
||||
|
||||
EntityAliveV2 npc = this.theEntity as EntityAliveV2;
|
||||
|
||||
if (npc == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.relocateTicks > 0)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 2");
|
||||
if (!this.theEntity.navigator.noPathAndNotPlanningOne())
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 3");
|
||||
this.relocateTicks--;
|
||||
this.theEntity.moveHelper.SetFocusPos(this.entityTarget.position);
|
||||
return;
|
||||
}
|
||||
this.relocateTicks = 0;
|
||||
}
|
||||
|
||||
ItemValue holdingItemItemValue = this.theEntity.inventory.holdingItemItemValue;
|
||||
int holdingItemIdx = this.theEntity.inventory.holdingItemIdx;
|
||||
|
||||
bool isRanged = false;
|
||||
|
||||
if (this.theEntity.HasAnyTags(FastTags<TagGroup.Global>.Parse("ranged")))
|
||||
{
|
||||
_actionIndex = 1;
|
||||
isRanged = true;
|
||||
}
|
||||
|
||||
ItemAction itemAction = this.theEntity.inventory.holdingItem.Actions[_actionIndex];
|
||||
|
||||
var distance = this.entityTarget.GetDistance(this.theEntity);
|
||||
|
||||
if (isRanged && ((this.theEntity.Buffs.GetCustomVar("CurrentOrder") > 0 && this.theEntity.Buffs.GetCustomVar("CurrentOrder") == (int)EntityUtilities.Orders.Follow) || this.theEntity.Buffs.GetCustomVar("$Leader") == 0))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update distance: " + distance);
|
||||
|
||||
float distanceFromTarget = 4f;
|
||||
|
||||
if (this.entityTarget is EntityPlayer)
|
||||
{
|
||||
distanceFromTarget = 5f;
|
||||
}
|
||||
|
||||
if (distance < distanceFromTarget)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 6");
|
||||
//if (!this.entityTarget.emodel.IsRagdollActive)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 6a");
|
||||
|
||||
int maxDistanceFromLeader = UnityEngine.Random.Range(10, 25);
|
||||
|
||||
backingUp = true;
|
||||
|
||||
Animator animator = this.theEntity.emodel.avatarController.GetAnimator();
|
||||
|
||||
if (animator)
|
||||
{
|
||||
animator.SetBool("isBackingUp", true);
|
||||
}
|
||||
|
||||
EntityUtilities.BackupHelper(this.theEntity, this.entityTarget, distanceFromTarget * 3f, maxDistanceFromLeader);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Animator animator = this.theEntity.emodel.avatarController.GetAnimator();
|
||||
|
||||
if (animator)
|
||||
{
|
||||
animator.SetBool("isBackingUp", false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Vector3 curEntTargPos = this.entityTarget.position;
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update B entityClassName: " + this.entityTarget.EntityClass.entityClassName);
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update SetLookPosition");
|
||||
theEntity.SetLookPosition(curEntTargPos);
|
||||
theEntity.RotateTo(curEntTargPos.x, curEntTargPos.y + 2, curEntTargPos.z, 8f, 8f);
|
||||
|
||||
Vector3 targetDirection = theEntity.position - curEntTargPos;
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update this.entityTarget.position: " + this.entityTarget.position);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update entityTargetPosn: " + curEntTargPos);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update targetDirection: " + targetDirection);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update targetDirection.sqrMagnitude: " + targetDirection.sqrMagnitude);
|
||||
|
||||
/*
|
||||
if (this.theEntity.GetAttackTarget() != null)
|
||||
{
|
||||
Log.Out("EAIApproachAndAttackTargetCompanion-Update GetAttackTarget: " + this.theEntity.GetAttackTarget().EntityClass.entityClassName);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Out("EAIApproachAndAttackTargetCompanion-Update NO ATTACK TARGET");
|
||||
}
|
||||
*/
|
||||
|
||||
bool isTargetWithinItemActionRange = false;
|
||||
|
||||
if (targetDirection.sqrMagnitude < 1f)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 7");
|
||||
this.entityTargetVel = this.entityTargetVel * 0.7f + targetDirection * 0.3f;
|
||||
}
|
||||
this.entityTargetPos = curEntTargPos;
|
||||
this.attackTimeout--;
|
||||
|
||||
this.theEntity.moveHelper.CalcIfUnreachablePos();
|
||||
float itemActionRange;
|
||||
float maxItemActionRange;
|
||||
|
||||
itemActionRange = 1.095f;
|
||||
if (itemAction != null)
|
||||
{
|
||||
itemActionRange = itemAction.Range;
|
||||
if (itemActionRange == 0f)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 8");
|
||||
itemActionRange = EffectManager.GetItemValue(PassiveEffects.MaxRange, holdingItemItemValue, 0f);
|
||||
}
|
||||
}
|
||||
maxItemActionRange = Utils.FastMax(0.7f, itemActionRange - 0.35f);
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 9a, itemActionRange: " + itemActionRange);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 9b, maxItemActionRange: " + maxItemActionRange);
|
||||
|
||||
float maxRangeSquared = maxItemActionRange * maxItemActionRange;
|
||||
float estimatedTimeInTicks = 4f;
|
||||
if (this.theEntity.IsFeral)
|
||||
{
|
||||
estimatedTimeInTicks = 8f;
|
||||
}
|
||||
estimatedTimeInTicks = base.RandomFloat * estimatedTimeInTicks;
|
||||
float targetXZDistanceSq = this.GetTargetXZDistanceSq(estimatedTimeInTicks);
|
||||
float yDiff = curEntTargPos.y - this.theEntity.position.y;
|
||||
float absoluteYDiff = Utils.FastAbs(yDiff);
|
||||
float entityDistance = Vector3.Distance(this.theEntity.position, curEntTargPos);
|
||||
isTargetWithinItemActionRange = entityDistance < maxItemActionRange;
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update entityDistance: " + entityDistance);
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update isTargetWithinItemActionRange: " + isTargetWithinItemActionRange);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update maxRangeSquared: " + maxRangeSquared);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update absoluteYDiff: " + absoluteYDiff);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update yDiff: " + yDiff);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update targetXZDistanceSq: " + targetXZDistanceSq);
|
||||
|
||||
if (!backingUp && ((this.theEntity.Buffs.GetCustomVar("CurrentOrder") == (int)EntityUtilities.Orders.Follow) || this.theEntity.Buffs.GetCustomVar("$Leader") == 0))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update !backingUp: " + !backingUp);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update CurrentOrder: " + this.theEntity.Buffs.GetCustomVar("CurrentOrder"));
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update $Leader: " + this.theEntity.Buffs.GetCustomVar("$Leader"));
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 10a");
|
||||
|
||||
if (!isTargetWithinItemActionRange)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 10c");
|
||||
if (absoluteYDiff < 3f && !PathFinderThread.Instance.IsCalculatingPath(this.theEntity.entityId))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 11");
|
||||
PathEntity path = this.theEntity.navigator.getPath();
|
||||
if (path != null && path.NodeCountRemaining() <= 2)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 12");
|
||||
this.pathCounter = 0;
|
||||
}
|
||||
}
|
||||
int pathCounterLessOne = this.pathCounter - 1;
|
||||
this.pathCounter = pathCounterLessOne;
|
||||
if (pathCounterLessOne <= 0 && this.theEntity.CanNavigatePath() && !PathFinderThread.Instance.IsCalculatingPath(this.theEntity.entityId))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 13");
|
||||
this.pathCounter = 6 + base.GetRandom(10);
|
||||
Vector3 moveToLocation = EntityUtilities.GetMoveToLocation(this.theEntity, this.entityTarget.position, 0);
|
||||
|
||||
if (isRanged)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update BEFORE moveToLocation: " + moveToLocation);
|
||||
//moveToLocation = RandomPositionGenerator.CalcAway(this.theEntity, 2, 5, 5, this.entityTarget.position);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update AFTER moveToLocation: " + moveToLocation);
|
||||
}
|
||||
|
||||
if (moveToLocation.y - this.theEntity.position.y < -8f)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 14");
|
||||
this.pathCounter += 40;
|
||||
if (base.RandomFloat < 0.2f)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 15");
|
||||
this.seekPosOffset.x = this.seekPosOffset.x + (base.RandomFloat * 0.6f - 0.3f);
|
||||
this.seekPosOffset.y = this.seekPosOffset.y + (base.RandomFloat * 0.6f - 0.3f);
|
||||
}
|
||||
moveToLocation.x += this.seekPosOffset.x;
|
||||
moveToLocation.z += this.seekPosOffset.y;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 16");
|
||||
float num8 = (moveToLocation - this.theEntity.position).magnitude - 5f;
|
||||
if (num8 > 0f)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 17");
|
||||
if (num8 > 60f)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 18");
|
||||
num8 = 60f;
|
||||
}
|
||||
this.pathCounter += (int)(num8 / 20f * 20f);
|
||||
}
|
||||
}
|
||||
this.theEntity.FindPath(moveToLocation, this.theEntity.GetMoveSpeedAggro(), true, this);
|
||||
}
|
||||
}
|
||||
|
||||
if (!isTargetWithinItemActionRange)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 19");
|
||||
if (this.theEntity.navigator.noPathAndNotPlanningOne() && this.pathCounter > 0 && yDiff < 2.1f)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 20");
|
||||
Vector3 moveToLocation2 = EntityUtilities.GetMoveToLocation(this.theEntity, this.entityTarget.position, 0);
|
||||
this.theEntity.moveHelper.SetMoveTo(moveToLocation2, true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 21");
|
||||
this.theEntity.moveHelper.Stop();
|
||||
this.pathCounter = 0;
|
||||
}
|
||||
|
||||
float newItemActionRange = itemActionRange - 0.1f;
|
||||
float newRangeSquared = newItemActionRange * newItemActionRange;
|
||||
this.theEntity.IsBreakingBlocks = false;
|
||||
this.theEntity.IsBreakingDoors = false;
|
||||
if (this.theEntity.bodyDamage.HasLimbs && !this.theEntity.Electrocuted)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 23");
|
||||
this.theEntity.RotateTo(curEntTargPos.x, curEntTargPos.y, curEntTargPos.z, 30f, 30f);
|
||||
}
|
||||
if (this.theEntity.GetDamagedTarget() == this.entityTarget || (this.entityTarget != null && this.entityTarget.GetDamagedTarget() == this.theEntity))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 24");
|
||||
this.homeTimeout = (this.theEntity.IsSleeper ? 90f : this.chaseTimeMax);
|
||||
if (this.blockTargetTask != null)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 25");
|
||||
this.blockTargetTask.canExecute = false;
|
||||
}
|
||||
this.theEntity.ClearDamagedTarget();
|
||||
if (this.entityTarget)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 26");
|
||||
this.entityTarget.ClearDamagedTarget();
|
||||
}
|
||||
}
|
||||
|
||||
if (this.manager.groupCircle > 0f)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 27");
|
||||
Entity targetIfAttackedNow = this.theEntity.GetTargetIfAttackedNow();
|
||||
if (targetIfAttackedNow != this.entityTarget && (!this.entityTarget.AttachedToEntity || this.entityTarget.AttachedToEntity != targetIfAttackedNow))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 28");
|
||||
if (targetIfAttackedNow != null)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 29");
|
||||
this.relocateTicks = 46;
|
||||
Vector3 vector3 = (this.theEntity.position - curEntTargPos).normalized * (newItemActionRange + 1.1f);
|
||||
float num11 = base.RandomFloat * 28f + 18f;
|
||||
if (base.RandomFloat < 0.5f)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 30");
|
||||
num11 = -num11;
|
||||
}
|
||||
vector3 = Quaternion.Euler(0f, num11, 0f) * vector3;
|
||||
Vector3 targetPos = curEntTargPos + vector3;
|
||||
this.theEntity.FindPath(targetPos, this.theEntity.GetMoveSpeedAggro(), true, this);
|
||||
}
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update E entityClassName: " + this.entityTarget.EntityClass.entityClassName);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 31");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.entityTarget == null)
|
||||
{
|
||||
checkEntityPosition();
|
||||
}
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update _actionIndex: " + _actionIndex);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update isRanged: " + isRanged);
|
||||
|
||||
this.theEntity.SleeperSupressLivingSounds = false;
|
||||
|
||||
if (this.theEntity.Buffs.HasBuff("buffReloadDelay") ||
|
||||
this.theEntity.Buffs.HasBuff("buffReload2") ||
|
||||
this.theEntity.Buffs.HasBuff("buffReload3")
|
||||
)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 33");
|
||||
return;
|
||||
}
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 34");
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update backingUp: " + backingUp);
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update distance: " + distance);
|
||||
|
||||
int rangeMax = 20;
|
||||
|
||||
PrefabInstance poiatPosition = this.theEntity.world.GetPOIAtPosition(this.theEntity.position, false);
|
||||
|
||||
if (poiatPosition != null)
|
||||
{
|
||||
//Give NPCs a better chance at a ragdoll when inside a POI
|
||||
rangeMax = 10;
|
||||
}
|
||||
|
||||
if (this.entityTarget is EntityPlayer)
|
||||
{
|
||||
rangeMax = 100;
|
||||
}
|
||||
|
||||
int chance = UnityEngine.Random.Range(1, rangeMax);
|
||||
|
||||
if (chance < 10 && !this.entityTarget.emodel.IsRagdollActive && distance < this.theEntity.inventory.holdingItem.Actions[0].Range)
|
||||
{
|
||||
_actionIndex = 0;
|
||||
}
|
||||
|
||||
if (_actionIndex == 1)
|
||||
{
|
||||
if (!isTargetWithinItemActionRange && this.theEntity.moveHelper.IsActive)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update Target isn't within range");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (isTargetWithinItemActionRange)
|
||||
{
|
||||
if (this.theEntity.Buffs.HasBuff("buffRangedMeleeDelay"))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update HAS ATTACK DELAY BUFF");
|
||||
return;
|
||||
}
|
||||
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 35a");
|
||||
if (npc.ExecuteAction(false, _actionIndex))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 35b");
|
||||
this.attackTimeout = this.theEntity.GetAttackTimeoutTicks();
|
||||
|
||||
if (isRanged && _actionIndex == 0)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update ADDED ATTACK DELAY BUFF");
|
||||
this.theEntity.Buffs.AddBuff("buffRangedMeleeDelay");
|
||||
}
|
||||
|
||||
// Check the range on the item action
|
||||
ItemActionRanged.ItemActionDataRanged itemActionData = null;
|
||||
|
||||
if (itemAction is ItemActionRanged itemActionRanged)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 36");
|
||||
itemActionData = this.theEntity.inventory.holdingItemData.actionData[_actionIndex] as ItemActionRanged.ItemActionDataRanged;
|
||||
if (itemActionData != null)
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 37");
|
||||
// Check if we are already running.
|
||||
if (itemAction.IsActionRunning(itemActionData))
|
||||
{
|
||||
//Log.Out("EAIApproachAndAttackTargetCompanion-Update 38");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private float GetTargetXZDistanceSq(float estimatedTicks)
|
||||
{
|
||||
Vector3 vector = this.entityTarget.position;
|
||||
vector += this.entityTargetVel * estimatedTicks;
|
||||
Vector3 vector2 = this.theEntity.position + this.theEntity.motion * estimatedTicks - vector;
|
||||
vector2.y = 0f;
|
||||
return vector2.sqrMagnitude;
|
||||
}
|
||||
|
||||
private Vector3 GetMoveToLocation(float maxDist)
|
||||
{
|
||||
Vector3 vector = this.entityTarget.position;
|
||||
vector += this.entityTargetVel * 6f;
|
||||
vector = this.entityTarget.world.FindSupportingBlockPos(vector);
|
||||
if (maxDist > 0f)
|
||||
{
|
||||
Vector3 vector2 = new Vector3(this.theEntity.position.x, vector.y, this.theEntity.position.z);
|
||||
Vector3 vector3 = vector - vector2;
|
||||
float magnitude = vector3.magnitude;
|
||||
if (magnitude < 3f)
|
||||
{
|
||||
if (magnitude <= maxDist)
|
||||
{
|
||||
float num = vector.y - this.theEntity.position.y;
|
||||
if (num < -3f || num > 1.5f)
|
||||
{
|
||||
return vector;
|
||||
}
|
||||
return vector2;
|
||||
}
|
||||
else
|
||||
{
|
||||
vector3 *= maxDist / magnitude;
|
||||
Vector3 vector4 = vector - vector3;
|
||||
vector4.y += 0.51f;
|
||||
Vector3i pos = World.worldToBlockPos(vector4);
|
||||
BlockValue block = this.entityTarget.world.GetBlock(pos);
|
||||
Block block2 = block.Block;
|
||||
if (block2.PathType <= 0)
|
||||
{
|
||||
RaycastHit raycastHit;
|
||||
if (Physics.Raycast(vector4 - Origin.position, Vector3.down, out raycastHit, 1.02f, 1082195968))
|
||||
{
|
||||
vector4.y = raycastHit.point.y + Origin.position.y;
|
||||
return vector4;
|
||||
}
|
||||
if (block2.IsElevator((int)block.rotation))
|
||||
{
|
||||
vector4.y = vector.y;
|
||||
return vector4;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return vector;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
ItemValue holdingItemItemValue = this.theEntity.inventory.holdingItemItemValue;
|
||||
int holdingItemIdx = this.theEntity.inventory.holdingItemIdx;
|
||||
ItemAction itemAction = holdingItemItemValue.ItemClass.Actions[holdingItemIdx];
|
||||
float num = 1.095f;
|
||||
if (itemAction != null)
|
||||
{
|
||||
num = itemAction.Range;
|
||||
if (num == 0f)
|
||||
{
|
||||
num = EffectManager.GetItemValue(PassiveEffects.MaxRange, holdingItemItemValue, 0f);
|
||||
}
|
||||
}
|
||||
float value = num - 0.1f;
|
||||
float targetXZDistanceSq = this.GetTargetXZDistanceSq(0f);
|
||||
return string.Format("{0}, {1}{2}{3}{4}{5} dist {6} rng {7} timeout {8}", new object[]
|
||||
{
|
||||
base.ToString(),
|
||||
this.entityTarget ? this.entityTarget.EntityName : "",
|
||||
this.theEntity.CanSee(this.entityTarget) ? "(see)" : "",
|
||||
this.theEntity.navigator.noPathAndNotPlanningOne() ? "(-path)" : (this.theEntity.navigator.noPath() ? "(!path)" : ""),
|
||||
this.isTargetToEat ? "(eat)" : "",
|
||||
this.isGoingHome ? "(home)" : "",
|
||||
Mathf.Sqrt(targetXZDistanceSq).ToCultureInvariantString("0.000"),
|
||||
value.ToCultureInvariantString("0.000"),
|
||||
this.homeTimeout.ToCultureInvariantString("0.00")
|
||||
});
|
||||
}
|
||||
|
||||
private int _actionIndex = 0;
|
||||
private const float cSleeperChaseTime = 90f;
|
||||
private List<EAIApproachAndAttackTargetCompanion.TargetClass> targetClasses;
|
||||
private float chaseTimeMax;
|
||||
private bool hasHome;
|
||||
private bool isGoingHome;
|
||||
private float homeTimeout;
|
||||
private EntityPlayer targetPlayer;
|
||||
private EntityAlive entityTarget;
|
||||
private Vector3 entityTargetPos;
|
||||
private Vector3 entityTargetVel;
|
||||
private int attackTimeout;
|
||||
private int pathCounter;
|
||||
private Vector2 seekPosOffset;
|
||||
private bool isTargetToEat;
|
||||
private bool isEating;
|
||||
private int eatCount;
|
||||
private EAIBlockingTargetTask blockTargetTask;
|
||||
private int relocateTicks;
|
||||
private int OwnerID = 0;
|
||||
private bool backingUp = false;
|
||||
private Animator animator = null;
|
||||
|
||||
private struct TargetClass
|
||||
{
|
||||
public Type type;
|
||||
public float chaseTimeMax;
|
||||
}
|
||||
}
|
||||
408
Scripts/EAI/_prev/EAIFollowLeaderCompanion2.cs
Normal file
408
Scripts/EAI/_prev/EAIFollowLeaderCompanion2.cs
Normal file
@@ -0,0 +1,408 @@
|
||||
using GamePath;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Xml;
|
||||
using UnityEngine.Scripting;
|
||||
using static BlendCycleTimer;
|
||||
using static EntityDrone;
|
||||
|
||||
[Preserve]
|
||||
public class EAIFollowLeaderCompanion : EAITarget
|
||||
{
|
||||
public override void Init(EntityAlive _theEntity)
|
||||
{
|
||||
base.Init(_theEntity, 25f, true);
|
||||
this.MutexBits = 1;
|
||||
}
|
||||
|
||||
public override void Start()
|
||||
{
|
||||
this.entityPlayerVel = Vector3.zero;
|
||||
this.relocateTicks = 0;
|
||||
this.pathCounter = 0;
|
||||
this.theEntity.ConditionalTriggerSleeperWakeUp();
|
||||
base.Start();
|
||||
}
|
||||
|
||||
public bool NPCEAICanProceed()
|
||||
{
|
||||
bool result = true;
|
||||
|
||||
this.OwnerID = (int)this.theEntity.Buffs.GetCustomVar("$Leader");
|
||||
|
||||
if (this.OwnerID == 0)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-NPCEAICanProceed 0");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.Buffs.GetCustomVar("onMission") == 1f ||
|
||||
this.theEntity.Buffs.GetCustomVar("$FR_NPC_Respawn") == 1f ||
|
||||
this.theEntity.Buffs.GetCustomVar("$FR_NPC_Hidden") == 1f
|
||||
)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-NPCEAICanProceed 1");
|
||||
return false;
|
||||
}
|
||||
|
||||
EntityUtilities.CheckDistanceToLeader(this.theEntity, this.targetPlayer);
|
||||
|
||||
if (this.theEntity.emodel.IsRagdollActive)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-NPCEAICanProceed 3");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.sleepingOrWakingUp || this.theEntity.bodyDamage.CurrentStun != EnumEntityStunType.None || (this.theEntity.Jumping && !this.theEntity.isSwimming))
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-NPCEAICanProceed 4");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.Buffs.GetCustomVar("CurrentOrder") != (int)EntityUtilities.Orders.Follow)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-CanExecute IS NOT FOLLOWING");
|
||||
return false;
|
||||
}
|
||||
|
||||
/*bool stopAttacking = this.theEntity.Buffs.HasBuff("FuriousRamsayBuffPauseAttack") ||
|
||||
this.theEntity.Buffs.HasBuff("buffNPCModStopAttacking") ||
|
||||
this.theEntity.Buffs.HasBuff("FuriousRamsayStandStill");*/
|
||||
|
||||
bool stopAttacking = this.theEntity.Buffs.HasBuff("FuriousRamsayStandStill");
|
||||
|
||||
if (stopAttacking)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-NPCEAICanProceed 5");
|
||||
this.theEntity.SetRevengeTarget(null);
|
||||
this.theEntity.SetAttackTarget(null, 0);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.sleepingOrWakingUp || this.theEntity.bodyDamage.CurrentStun != EnumEntityStunType.None)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-NPCEAICanProceed 6");
|
||||
return false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public override bool CanExecute()
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-CanExecute START");
|
||||
|
||||
if (!NPCEAICanProceed())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.targetPlayer == null)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-CanExecute 2");
|
||||
this.OwnerID = (int)this.theEntity.Buffs.GetCustomVar("$Leader");
|
||||
|
||||
if (this.OwnerID > 0)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-CanExecute this.OwnerID: " + this.OwnerID);
|
||||
|
||||
EntityPlayer entityPlayer = (EntityPlayer)this.theEntity.world.GetEntity(this.OwnerID);
|
||||
if (entityPlayer != null)
|
||||
{
|
||||
this.targetPlayer = entityPlayer;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//Log.Out("EAIFollowLeaderCompanion-CanExecute this.theEntity.GetAttackTarget: " + this.theEntity.GetAttackTarget().EntityClass.entityClassName);
|
||||
return false;
|
||||
}
|
||||
|
||||
public override bool Continue()
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Continue START");
|
||||
|
||||
if (!NPCEAICanProceed())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (pathCounter == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update START");
|
||||
|
||||
if (!NPCEAICanProceed())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.targetPlayer == null)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 2");
|
||||
this.OwnerID = (int)this.theEntity.Buffs.GetCustomVar("$Leader");
|
||||
|
||||
if (this.OwnerID > 0)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update this.OwnerID: " + this.OwnerID);
|
||||
|
||||
EntityPlayer entityPlayer = (EntityPlayer)this.theEntity.world.GetEntity(this.OwnerID);
|
||||
if (entityPlayer != null)
|
||||
{
|
||||
this.targetPlayer = entityPlayer;
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update FOUND OWNER");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EntityUtilities.CheckForClosedDoor(this.theEntity);
|
||||
|
||||
if (this.relocateTicks > 0)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 2");
|
||||
if (!this.theEntity.navigator.noPathAndNotPlanningOne())
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 3");
|
||||
this.relocateTicks--;
|
||||
this.theEntity.moveHelper.SetFocusPos(this.targetPlayer.position);
|
||||
return;
|
||||
}
|
||||
this.relocateTicks = 0;
|
||||
}
|
||||
|
||||
Vector3 vector2 = this.targetPlayer.position;
|
||||
|
||||
Vector3 a = theEntity.position - vector2;
|
||||
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update entityTargetPosn: " + vector2);
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update a: " + a);
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update a.sqrMagnitude: " + a.sqrMagnitude);
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update this.OwnerID: " + this.theEntity.Buffs.GetCustomVar("$Leader"));
|
||||
|
||||
this.OwnerID = (int)this.theEntity.Buffs.GetCustomVar("$Leader");
|
||||
|
||||
float magnitude = 30f;
|
||||
|
||||
bool isClient = SingletonMonoBehaviour<ConnectionManager>.Instance.IsClient;
|
||||
|
||||
if (isClient)
|
||||
{
|
||||
magnitude = 3f;
|
||||
}
|
||||
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update magnitude: " + magnitude);
|
||||
|
||||
if (this.targetPlayer.entityId == this.OwnerID && a.sqrMagnitude < magnitude)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update Entity is too close. Ending pathing.");
|
||||
this.theEntity.moveHelper.Stop();
|
||||
pathCounter = 0;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.targetPlayer.entityId == this.OwnerID)
|
||||
{
|
||||
if (!this.theEntity.HasAnyTags(FastTags<TagGroup.Global>.Parse("allyanimal")))
|
||||
{
|
||||
this.theEntity.Crouching = this.targetPlayer.Crouching;
|
||||
}
|
||||
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update theEntity.moveHelper.BlockedTime: " + theEntity.moveHelper.BlockedTime);
|
||||
|
||||
if (theEntity.moveHelper.BlockedTime > 3f)
|
||||
{
|
||||
EntityAliveV2 npc = this.theEntity as EntityAliveV2;
|
||||
|
||||
if (npc != null)
|
||||
{
|
||||
npc.TeleportToPlayer(this.targetPlayer, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update SetLookPosition");
|
||||
theEntity.SetLookPosition(vector2);
|
||||
theEntity.RotateTo(vector2.x, vector2.y + 2, vector2.z, 8f, 8f);
|
||||
|
||||
if (a.sqrMagnitude < 1f)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 6");
|
||||
this.entityPlayerVel = this.entityPlayerVel * 0.7f + a * 0.3f;
|
||||
}
|
||||
this.entityPlayerPos = vector2;
|
||||
|
||||
this.theEntity.moveHelper.CalcIfUnreachablePos();
|
||||
float num2;
|
||||
float num3;
|
||||
|
||||
num2 = 1.095f;
|
||||
num3 = Utils.FastMax(0.7f, num2 - 0.35f);
|
||||
|
||||
float num4 = num3 * num3;
|
||||
float num5 = 4f;
|
||||
if (this.theEntity.IsFeral)
|
||||
{
|
||||
num5 = 8f;
|
||||
}
|
||||
num5 = base.RandomFloat * num5;
|
||||
float targetXZDistanceSq = this.GetTargetXZDistanceSq(num5);
|
||||
float num6 = vector2.y - this.theEntity.position.y;
|
||||
float num7 = Utils.FastAbs(num6);
|
||||
bool flag = targetXZDistanceSq <= num4 && num7 < 1f;
|
||||
if (!flag)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 9");
|
||||
if (num7 < 3f && !PathFinderThread.Instance.IsCalculatingPath(this.theEntity.entityId))
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 10");
|
||||
PathEntity path = this.theEntity.navigator.getPath();
|
||||
if (path != null && path.NodeCountRemaining() <= 2)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 11");
|
||||
this.pathCounter = 0;
|
||||
}
|
||||
}
|
||||
int num = this.pathCounter - 1;
|
||||
this.pathCounter = num;
|
||||
if (num <= 0 && this.theEntity.CanNavigatePath() && !PathFinderThread.Instance.IsCalculatingPath(this.theEntity.entityId))
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 12");
|
||||
this.pathCounter = 6 + base.GetRandom(10);
|
||||
Vector3 moveToLocation = EntityUtilities.GetMoveToLocation(this.theEntity, this.targetPlayer.position,5);
|
||||
if (moveToLocation.y - this.theEntity.position.y < -8f)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 13");
|
||||
this.pathCounter += 40;
|
||||
if (base.RandomFloat < 0.2f)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 14");
|
||||
this.seekPosOffset.x = this.seekPosOffset.x + (base.RandomFloat * 0.6f - 0.3f);
|
||||
this.seekPosOffset.y = this.seekPosOffset.y + (base.RandomFloat * 0.6f - 0.3f);
|
||||
}
|
||||
moveToLocation.x += this.seekPosOffset.x;
|
||||
moveToLocation.z += this.seekPosOffset.y;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 15");
|
||||
float num8 = (moveToLocation - this.theEntity.position).magnitude - 5f;
|
||||
if (num8 > 0f)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 16");
|
||||
if (num8 > 60f)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 17");
|
||||
num8 = 60f;
|
||||
}
|
||||
this.pathCounter += (int)(num8 / 20f * 20f);
|
||||
}
|
||||
}
|
||||
this.theEntity.FindPath(moveToLocation, this.theEntity.GetMoveSpeedAggro(), true, this);
|
||||
}
|
||||
}
|
||||
if (this.theEntity.Climbing)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 18");
|
||||
return;
|
||||
}
|
||||
if (!flag)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 20");
|
||||
if (this.theEntity.navigator.noPathAndNotPlanningOne() && this.pathCounter > 0 && num6 < 2.1f)
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 21");
|
||||
Vector3 moveToLocation2 = EntityUtilities.GetMoveToLocation(this.theEntity, this.targetPlayer.position);
|
||||
this.theEntity.moveHelper.SetMoveTo(moveToLocation2, true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("EAIFollowLeaderCompanion-Update 22");
|
||||
this.theEntity.moveHelper.Stop();
|
||||
this.pathCounter = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private float GetTargetXZDistanceSq(float estimatedTicks)
|
||||
{
|
||||
Vector3 vector = this.targetPlayer.position;
|
||||
vector += this.entityPlayerVel * estimatedTicks;
|
||||
Vector3 vector2 = this.theEntity.position + this.theEntity.motion * estimatedTicks - vector;
|
||||
vector2.y = 0f;
|
||||
return vector2.sqrMagnitude;
|
||||
}
|
||||
|
||||
private Vector3 GetMoveToLocation(float maxDist)
|
||||
{
|
||||
Vector3 vector = this.targetPlayer.position;
|
||||
vector += this.entityPlayerVel * 6f;
|
||||
vector = this.targetPlayer.world.FindSupportingBlockPos(vector);
|
||||
if (maxDist > 0f)
|
||||
{
|
||||
Vector3 vector2 = new Vector3(this.theEntity.position.x, vector.y, this.theEntity.position.z);
|
||||
Vector3 vector3 = vector - vector2;
|
||||
float magnitude = vector3.magnitude;
|
||||
if (magnitude < 3f)
|
||||
{
|
||||
if (magnitude <= maxDist)
|
||||
{
|
||||
float num = vector.y - this.theEntity.position.y;
|
||||
if (num < -3f || num > 1.5f)
|
||||
{
|
||||
return vector;
|
||||
}
|
||||
return vector2;
|
||||
}
|
||||
else
|
||||
{
|
||||
vector3 *= maxDist / magnitude;
|
||||
Vector3 vector4 = vector - vector3;
|
||||
vector4.y += 0.51f;
|
||||
Vector3i pos = World.worldToBlockPos(vector4);
|
||||
BlockValue block = this.targetPlayer.world.GetBlock(pos);
|
||||
Block block2 = block.Block;
|
||||
if (block2.PathType <= 0)
|
||||
{
|
||||
RaycastHit raycastHit;
|
||||
if (Physics.Raycast(vector4 - Origin.position, Vector3.down, out raycastHit, 1.02f, 1082195968))
|
||||
{
|
||||
vector4.y = raycastHit.point.y + Origin.position.y;
|
||||
return vector4;
|
||||
}
|
||||
if (block2.IsElevator((int)block.rotation))
|
||||
{
|
||||
vector4.y = vector.y;
|
||||
return vector4;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return vector;
|
||||
}
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
this.targetPlayer = null;
|
||||
}
|
||||
|
||||
private EntityPlayer targetPlayer;
|
||||
private Vector3 entityPlayerVel;
|
||||
private Vector3 entityPlayerPos;
|
||||
private int relocateTicks;
|
||||
private int OwnerID = 0;
|
||||
private int pathCounter;
|
||||
private Vector2 seekPosOffset;
|
||||
}
|
||||
371
Scripts/EAI/_prev/EAIMoveToTargetCompanion2.cs
Normal file
371
Scripts/EAI/_prev/EAIMoveToTargetCompanion2.cs
Normal file
@@ -0,0 +1,371 @@
|
||||
using GamePath;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Xml;
|
||||
using UnityEngine.Scripting;
|
||||
using static BlendCycleTimer;
|
||||
using static EntityDrone;
|
||||
|
||||
[Preserve]
|
||||
public class EAIMoveToTargetCompanion : EAITarget
|
||||
{
|
||||
public override void Init(EntityAlive _theEntity)
|
||||
{
|
||||
base.Init(_theEntity, 25f, true);
|
||||
this.MutexBits = 1;
|
||||
}
|
||||
|
||||
public override void Start()
|
||||
{
|
||||
this.relocateTicks = 0;
|
||||
this.pathCounter = 0;
|
||||
base.Start();
|
||||
}
|
||||
|
||||
public bool NPCEAICanProceed()
|
||||
{
|
||||
bool result = true;
|
||||
|
||||
this.OwnerID = (int)this.theEntity.Buffs.GetCustomVar("$Leader");
|
||||
|
||||
if (this.OwnerID == 0)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-NPCEAICanProceed 0");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.Buffs.GetCustomVar("onMission") == 1f ||
|
||||
this.theEntity.Buffs.GetCustomVar("$FR_NPC_Respawn") == 1f ||
|
||||
this.theEntity.Buffs.GetCustomVar("$FR_NPC_Hidden") == 1f
|
||||
)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-NPCEAICanProceed 1");
|
||||
return false;
|
||||
}
|
||||
|
||||
EntityUtilities.CheckDistanceToLeader(this.theEntity, this.targetPlayer);
|
||||
|
||||
this.entityTarget = this.theEntity.GetAttackTarget();
|
||||
|
||||
if (this.entityTarget == null)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-NPCEAICanProceed 2a");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.targetPlayer != null && !this.targetPlayer.CanEntityBeSeen(this.entityTarget) && !this.theEntity.CanEntityBeSeen(this.entityTarget))
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-NPCEAICanProceed 2b");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.CanEntityBeSeen(this.entityTarget))
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-NPCEAICanProceed 2c");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.emodel.IsRagdollActive)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-NPCEAICanProceed 3");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.sleepingOrWakingUp || this.theEntity.bodyDamage.CurrentStun != EnumEntityStunType.None || (this.theEntity.Jumping && !this.theEntity.isSwimming))
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-NPCEAICanProceed 4");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.Buffs.GetCustomVar("CurrentOrder") != (int)EntityUtilities.Orders.Follow &&
|
||||
this.theEntity.Buffs.GetCustomVar("CurrentOrder") != (int)EntityUtilities.Orders.Guard)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-CanExecute IS NOT FOLLOWING");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool stopAttacking = this.theEntity.Buffs.HasBuff("FuriousRamsayBuffPauseAttack") ||
|
||||
this.theEntity.Buffs.HasBuff("buffNPCModStopAttacking") ||
|
||||
this.theEntity.Buffs.HasBuff("FuriousRamsayStandStill");
|
||||
|
||||
if (stopAttacking)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-NPCEAICanProceed 5");
|
||||
this.theEntity.SetRevengeTarget(null);
|
||||
this.theEntity.SetAttackTarget(null, 0);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.theEntity.sleepingOrWakingUp || this.theEntity.bodyDamage.CurrentStun != EnumEntityStunType.None)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-NPCEAICanProceed 6");
|
||||
return false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public override bool CanExecute()
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-CanExecute START");
|
||||
|
||||
if (!NPCEAICanProceed())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.targetPlayer == null)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-CanExecute 2");
|
||||
this.OwnerID = (int)this.theEntity.Buffs.GetCustomVar("$Leader");
|
||||
|
||||
if (this.OwnerID > 0)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-CanExecute this.OwnerID: " + this.OwnerID);
|
||||
|
||||
EntityPlayer entityPlayer = (EntityPlayer)this.theEntity.world.GetEntity(this.OwnerID);
|
||||
if (entityPlayer != null)
|
||||
{
|
||||
this.targetPlayer = entityPlayer;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//Log.Out("EAIMoveToTargetCompanion-CanExecute this.theEntity.GetAttackTarget: " + this.theEntity.GetAttackTarget().EntityClass.entityClassName);
|
||||
return false;
|
||||
}
|
||||
|
||||
public override bool Continue()
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Continue START");
|
||||
if (!NPCEAICanProceed())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (pathCounter == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update START");
|
||||
|
||||
if (!NPCEAICanProceed())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.targetPlayer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
EntityUtilities.CheckForClosedDoor(this.theEntity);
|
||||
|
||||
if (this.relocateTicks > 0)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update 2");
|
||||
if (!this.theEntity.navigator.noPathAndNotPlanningOne())
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update 3");
|
||||
this.relocateTicks--;
|
||||
this.theEntity.moveHelper.SetFocusPos(this.entityTarget.position);
|
||||
return;
|
||||
}
|
||||
this.relocateTicks = 0;
|
||||
}
|
||||
|
||||
Vector3 vector2 = this.entityTarget.position;
|
||||
|
||||
Vector3 a = theEntity.position - vector2;
|
||||
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update entityTargetPosn: " + vector2);
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update a: " + a);
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update a.sqrMagnitude: " + a.sqrMagnitude);
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update this.OwnerID: " + this.theEntity.Buffs.GetCustomVar("$Leader"));
|
||||
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update SetLookPosition");
|
||||
theEntity.SetLookPosition(vector2);
|
||||
theEntity.RotateTo(vector2.x, vector2.y + 2, vector2.z, 8f, 8f);
|
||||
|
||||
if (a.sqrMagnitude < 1f)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update 6");
|
||||
this.entityPlayerVel = this.entityPlayerVel * 0.7f + a * 0.3f;
|
||||
}
|
||||
this.entityPlayerPos = vector2;
|
||||
|
||||
this.theEntity.moveHelper.CalcIfUnreachablePos();
|
||||
float num2;
|
||||
float num3;
|
||||
|
||||
num2 = 1.095f;
|
||||
num3 = Utils.FastMax(0.7f, num2 - 0.35f);
|
||||
|
||||
float num4 = num3 * num3;
|
||||
float num5 = 4f;
|
||||
if (this.theEntity.IsFeral)
|
||||
{
|
||||
num5 = 8f;
|
||||
}
|
||||
num5 = base.RandomFloat * num5;
|
||||
float targetXZDistanceSq = this.GetTargetXZDistanceSq(num5);
|
||||
float num6 = vector2.y - this.theEntity.position.y;
|
||||
float num7 = Utils.FastAbs(num6);
|
||||
bool flag = targetXZDistanceSq <= num4 && num7 < 1f;
|
||||
if (!flag)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update 9");
|
||||
if (num7 < 3f && !PathFinderThread.Instance.IsCalculatingPath(this.theEntity.entityId))
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update 10");
|
||||
PathEntity path = this.theEntity.navigator.getPath();
|
||||
if (path != null && path.NodeCountRemaining() <= 2)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update 11");
|
||||
this.pathCounter = 0;
|
||||
}
|
||||
}
|
||||
int num = this.pathCounter - 1;
|
||||
this.pathCounter = num;
|
||||
if (num <= 0 && this.theEntity.CanNavigatePath() && !PathFinderThread.Instance.IsCalculatingPath(this.theEntity.entityId))
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update 12");
|
||||
this.pathCounter = 6 + base.GetRandom(10);
|
||||
Vector3 moveToLocation = EntityUtilities.GetMoveToLocation(this.theEntity, this.entityTarget.position, 5);
|
||||
if (moveToLocation.y - this.theEntity.position.y < -8f)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update 13");
|
||||
this.pathCounter += 40;
|
||||
if (base.RandomFloat < 0.2f)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update 14");
|
||||
this.seekPosOffset.x = this.seekPosOffset.x + (base.RandomFloat * 0.6f - 0.3f);
|
||||
this.seekPosOffset.y = this.seekPosOffset.y + (base.RandomFloat * 0.6f - 0.3f);
|
||||
}
|
||||
moveToLocation.x += this.seekPosOffset.x;
|
||||
moveToLocation.z += this.seekPosOffset.y;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update 15");
|
||||
float num8 = (moveToLocation - this.theEntity.position).magnitude - 5f;
|
||||
if (num8 > 0f)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update 16");
|
||||
if (num8 > 60f)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update 17");
|
||||
num8 = 60f;
|
||||
}
|
||||
this.pathCounter += (int)(num8 / 20f * 20f);
|
||||
}
|
||||
}
|
||||
this.theEntity.FindPath(moveToLocation, this.theEntity.GetMoveSpeedAggro(), true, this);
|
||||
}
|
||||
}
|
||||
if (this.theEntity.Climbing)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update 18");
|
||||
return;
|
||||
}
|
||||
if (!flag)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update 20");
|
||||
if (this.theEntity.navigator.noPathAndNotPlanningOne() && this.pathCounter > 0 && num6 < 2.1f)
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update 21");
|
||||
Vector3 moveToLocation2 = EntityUtilities.GetMoveToLocation(this.theEntity, this.entityTarget.position, 5);
|
||||
this.theEntity.moveHelper.SetMoveTo(moveToLocation2, true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("EAIMoveToTargetCompanion-Update 22");
|
||||
this.theEntity.moveHelper.Stop();
|
||||
this.pathCounter = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private float GetTargetXZDistanceSq(float estimatedTicks)
|
||||
{
|
||||
Vector3 vector = this.entityTarget.position;
|
||||
vector += this.entityPlayerVel * estimatedTicks;
|
||||
Vector3 vector2 = this.theEntity.position + this.theEntity.motion * estimatedTicks - vector;
|
||||
vector2.y = 0f;
|
||||
return vector2.sqrMagnitude;
|
||||
}
|
||||
|
||||
private Vector3 GetMoveToLocation(float maxDist)
|
||||
{
|
||||
Vector3 vector = this.entityTarget.position;
|
||||
vector += this.entityPlayerVel * 6f;
|
||||
vector = this.entityTarget.world.FindSupportingBlockPos(vector);
|
||||
if (maxDist > 0f)
|
||||
{
|
||||
Vector3 vector2 = new Vector3(this.theEntity.position.x, vector.y, this.theEntity.position.z);
|
||||
Vector3 vector3 = vector - vector2;
|
||||
float magnitude = vector3.magnitude;
|
||||
if (magnitude < 3f)
|
||||
{
|
||||
if (magnitude <= maxDist)
|
||||
{
|
||||
float num = vector.y - this.theEntity.position.y;
|
||||
if (num < -3f || num > 1.5f)
|
||||
{
|
||||
return vector;
|
||||
}
|
||||
return vector2;
|
||||
}
|
||||
else
|
||||
{
|
||||
vector3 *= maxDist / magnitude;
|
||||
Vector3 vector4 = vector - vector3;
|
||||
vector4.y += 0.51f;
|
||||
Vector3i pos = World.worldToBlockPos(vector4);
|
||||
BlockValue block = this.entityTarget.world.GetBlock(pos);
|
||||
Block block2 = block.Block;
|
||||
if (block2.PathType <= 0)
|
||||
{
|
||||
RaycastHit raycastHit;
|
||||
if (Physics.Raycast(vector4 - Origin.position, Vector3.down, out raycastHit, 1.02f, 1082195968))
|
||||
{
|
||||
vector4.y = raycastHit.point.y + Origin.position.y;
|
||||
return vector4;
|
||||
}
|
||||
if (block2.IsElevator((int)block.rotation))
|
||||
{
|
||||
vector4.y = vector.y;
|
||||
return vector4;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return vector;
|
||||
}
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
this.entityTarget = null;
|
||||
this.targetPlayer = null;
|
||||
}
|
||||
|
||||
private EntityPlayer targetPlayer;
|
||||
private EntityAlive entityTarget;
|
||||
private Vector3 entityPlayerVel;
|
||||
private Vector3 entityPlayerPos;
|
||||
private int relocateTicks;
|
||||
private int OwnerID = 0;
|
||||
private int pathCounter;
|
||||
private Vector2 seekPosOffset;
|
||||
}
|
||||
364
Scripts/EAI/_prev/EAISetNearestEntityAsTargetCompanion2.cs
Normal file
364
Scripts/EAI/_prev/EAISetNearestEntityAsTargetCompanion2.cs
Normal file
@@ -0,0 +1,364 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Scripting;
|
||||
|
||||
[Preserve]
|
||||
public class EAISetNearestEntityAsTargetCompanion : EAITarget
|
||||
{
|
||||
public override void Init(EntityAlive _theEntity)
|
||||
{
|
||||
base.Init(_theEntity, 25f, true);
|
||||
this.MutexBits = 1;
|
||||
this.sorter = new EAISetNearestEntityAsTargetSorter(_theEntity);
|
||||
}
|
||||
|
||||
public override void SetData(DictionarySave<string, string> data)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-SetData START");
|
||||
base.SetData(data);
|
||||
this.targetClasses = new List<EAISetNearestEntityAsTargetCompanion.TargetClass>();
|
||||
string text;
|
||||
if (data.TryGetValue("class", out text))
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-SetData 1");
|
||||
string[] array = text.Split(',', StringSplitOptions.None);
|
||||
for (int i = 0; i < array.Length; i += 3)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-SetData i: " + i);
|
||||
EAISetNearestEntityAsTargetCompanion.TargetClass targetClass;
|
||||
targetClass.type = EntityFactory.GetEntityType(array[i]);
|
||||
targetClass.hearDistMax = 0f;
|
||||
if (i + 1 < array.Length)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-SetData 2");
|
||||
targetClass.hearDistMax = StringParsers.ParseFloat(array[i + 1], 0, -1, NumberStyles.Any);
|
||||
}
|
||||
if (targetClass.hearDistMax == 0f)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-SetData 3");
|
||||
targetClass.hearDistMax = 50f;
|
||||
}
|
||||
targetClass.seeDistMax = 0f;
|
||||
if (i + 2 < array.Length)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-SetData 4");
|
||||
targetClass.seeDistMax = StringParsers.ParseFloat(array[i + 2], 0, -1, NumberStyles.Any);
|
||||
}
|
||||
if (targetClass.type == typeof(EntityPlayer))
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-SetData 5");
|
||||
this.playerTargetClassIndex = this.targetClasses.Count;
|
||||
}
|
||||
this.targetClasses.Add(targetClass);
|
||||
}
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-SetData 6");
|
||||
}
|
||||
}
|
||||
|
||||
public bool NPCEAICanProceed()
|
||||
{
|
||||
bool result = true;
|
||||
|
||||
if (this.theEntity.Buffs.GetCustomVar("onMission") == 1f ||
|
||||
this.theEntity.Buffs.GetCustomVar("$FR_NPC_Respawn") == 1f ||
|
||||
this.theEntity.Buffs.GetCustomVar("$FR_NPC_Hidden") == 1f
|
||||
)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-NPCEAICanProceed 1");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool stopAttacking = this.theEntity.Buffs.HasBuff("FuriousRamsayBuffPauseAttack") ||
|
||||
this.theEntity.Buffs.HasBuff("buffNPCModStopAttacking") ||
|
||||
this.theEntity.Buffs.HasBuff("FuriousRamsayStandStill");
|
||||
|
||||
if (stopAttacking)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-NPCEAICanProceed 2");
|
||||
this.theEntity.SetRevengeTarget(null);
|
||||
this.theEntity.SetAttackTarget(null, 0);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public override bool CanExecute()
|
||||
{
|
||||
if (!NPCEAICanProceed())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
this.FindTarget();
|
||||
|
||||
if (!this.closeTargetEntity)
|
||||
{
|
||||
//Log.Out($"! closeTargetEntity: {closeTargetEntity}");
|
||||
return false;
|
||||
}
|
||||
this.targetEntity = this.closeTargetEntity;
|
||||
this.targetPlayer = (this.closeTargetEntity as EntityPlayer);
|
||||
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-CanExecute this.targetEntity: " + this.targetEntity.EntityClass.entityClassName);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void FindTarget()
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget START");
|
||||
this.closeTargetDist = float.MaxValue;
|
||||
this.closeTargetEntity = null;
|
||||
float seeDistance = RebirthVariables.customDistanceHunting; //this.theEntity.GetSeeDistance();
|
||||
|
||||
if (this.theEntity.Buffs.HasBuff("buffNPCModFullControlMode") && this.theEntity.Buffs.GetCustomVar("CurrentOrder") == (int)EntityUtilities.Orders.Follow)
|
||||
{
|
||||
seeDistance = RebirthVariables.customDistanceFullControl;
|
||||
}
|
||||
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget this.targetClasses.Count " + this.targetClasses.Count);
|
||||
for (int i = 0; i < this.targetClasses.Count; i++)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget i: " + i);
|
||||
EAISetNearestEntityAsTargetCompanion.TargetClass targetClass = this.targetClasses[i];
|
||||
float num = 100;
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget seeDistance " + seeDistance);
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget targetClass.seeDistMax " + targetClass.seeDistMax);
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget num " + num);
|
||||
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget this.theEntity.IsSleeping " + this.theEntity.IsSleeping);
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget this.theEntity.HasInvestigatePosition " + this.theEntity.HasInvestigatePosition);
|
||||
|
||||
bool hasInvestigatePosition = false; // this.theEntity.HasInvestigatePosition;
|
||||
|
||||
if (!this.theEntity.IsSleeping && !hasInvestigatePosition)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget 1");
|
||||
this.theEntity.world.GetEntitiesInBounds(targetClass.type, BoundsUtils.ExpandBounds(this.theEntity.boundingBox, num, num, num), EAISetNearestEntityAsTargetCompanion.list);
|
||||
EAISetNearestEntityAsTargetCompanion.list.Sort(this.sorter);
|
||||
int j = 0;
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget EAISetNearestEntityAsTargetCompanion.list.Count " + EAISetNearestEntityAsTargetCompanion.list.Count);
|
||||
while (j < EAISetNearestEntityAsTargetCompanion.list.Count)
|
||||
{
|
||||
EntityAlive entityAlive = (EntityAlive)EAISetNearestEntityAsTargetCompanion.list[j];
|
||||
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget j: " + j + " / entityAlive: " + entityAlive.EntityClass.entityClassName);
|
||||
|
||||
//if (!(entityAlive is EntityDrone))
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget 2");
|
||||
bool check = base.check(entityAlive);
|
||||
bool shouldAttack = RebirthUtilities.VerifyFactionStanding(this.theEntity, entityAlive);
|
||||
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget check: " + check);
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget shouldAttack: " + shouldAttack);
|
||||
|
||||
if (!check && entityAlive.entityId != this.theEntity.entityId && shouldAttack)
|
||||
{
|
||||
int OwnerID = (int)this.theEntity.Buffs.GetCustomVar("$Leader");
|
||||
|
||||
if (OwnerID > 0)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget HAS OWNER");
|
||||
EntityPlayer entityPlayer = (EntityPlayer)this.theEntity.world.GetEntity(OwnerID);
|
||||
if (entityPlayer != null)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget FOUND OWNER");
|
||||
if (entityPlayer.CanEntityBeSeen(entityAlive) && !(entityAlive is EntitySupplyCrate))
|
||||
{
|
||||
check = true;
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget OWNER CAN SEE TARGET: " + entityAlive.EntityClass.entityClassName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget check: " + check);
|
||||
|
||||
if (check && (!entityAlive.IsSleeping || entityAlive is EntityAnimalSnake))
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget entityAlive.EntityClass.entityClassName: " + entityAlive.EntityClass.entityClassName);
|
||||
float distance = this.theEntity.GetDistance(entityAlive);
|
||||
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget this.closeTargetDist: " + this.closeTargetDist);
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget distance: " + distance);
|
||||
|
||||
bool bypassDistance = (entityAlive.Buffs.GetCustomVar("$FuriousRamsayAttacking") == 1f ||
|
||||
entityAlive.Buffs.GetCustomVar("$FuriousRamsayAttacked") == 1f ||
|
||||
this.theEntity.Buffs.HasBuff("buffNPCModThreatControlMode")
|
||||
);
|
||||
|
||||
if (bypassDistance && distance > 50)
|
||||
{
|
||||
bypassDistance = false;
|
||||
}
|
||||
|
||||
if (this.theEntity.HasAnyTags(FastTags<TagGroup.Global>.Parse("allyanimal")) ||
|
||||
this.theEntity.HasAnyTags(FastTags<TagGroup.Global>.Parse("melee")))
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget IS MELEE");
|
||||
if ( entityAlive.EntityClass.Tags.Test_AnySet(FastTags<TagGroup.Global>.Parse("nomeleetracking")))
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget NO ANIMAL TRACKING");
|
||||
if (this.theEntity.position.y < entityAlive.position.y - 4)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget TOO HIGH: " + entityAlive.EntityClass.entityClassName);
|
||||
j++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget bypassDistance: " + bypassDistance);
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget distance: " + distance);
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget seeDistance: " + seeDistance);
|
||||
|
||||
if (bypassDistance || distance < seeDistance)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget A");
|
||||
this.closeTargetDist = distance;
|
||||
this.closeTargetEntity = entityAlive;
|
||||
this.lastSeenPos = entityAlive.position;
|
||||
|
||||
//Log.Out($"EAI SetNearestEntityAsTargetCompanion - FindTarget entityAlive: {entityAlive.EntityClass.entityClassName}");
|
||||
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget B");
|
||||
int OwnerID = (int)this.theEntity.Buffs.GetCustomVar("$Leader");
|
||||
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget OwnerID: " + OwnerID);
|
||||
|
||||
EntityPlayer owner = null;
|
||||
|
||||
if (OwnerID > 0)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget HAS OWNER");
|
||||
EntityPlayer entityPlayer = (EntityPlayer)this.theEntity.world.GetEntity(OwnerID);
|
||||
if (entityPlayer != null)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget FOUND OWNER");
|
||||
owner = entityPlayer;
|
||||
}
|
||||
}
|
||||
|
||||
if (owner != null)
|
||||
{
|
||||
distance = owner.GetDistance(entityAlive);
|
||||
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget DISTANCE TO OWNER: " + distance);
|
||||
|
||||
if (distance < seeDistance + 5)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget OWNER distance: " + distance);
|
||||
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-FindTarget entityAlive: " + entityAlive.EntityClass.entityClassName);
|
||||
|
||||
this.closeTargetDist = distance;
|
||||
this.closeTargetEntity = entityAlive;
|
||||
this.lastSeenPos = entityAlive.position;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
j++;
|
||||
}
|
||||
}
|
||||
}
|
||||
EAISetNearestEntityAsTargetCompanion.list.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
//Log.Out($"FindTarget END - closeTargetEntity: {closeTargetEntity}");
|
||||
}
|
||||
|
||||
public override void Start()
|
||||
{
|
||||
this.theEntity.SetAttackTarget(this.targetEntity, 200);
|
||||
this.theEntity.ConditionalTriggerSleeperWakeUp();
|
||||
base.Start();
|
||||
}
|
||||
|
||||
public override bool Continue()
|
||||
{
|
||||
if (!NPCEAICanProceed())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.targetEntity.IsDead() || this.theEntity.distraction != null)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-Continue 5");
|
||||
if (this.theEntity.GetAttackTarget() == this.targetEntity)
|
||||
{
|
||||
//Log.Out("SetNearestEntityAsTarget - Continue - GetAttackTarget() == this.targetEntity and isDead or distraction not null");
|
||||
this.theEntity.SetAttackTarget(null, 0);
|
||||
}
|
||||
//Log.Out($"returning false here");
|
||||
return false;
|
||||
}
|
||||
|
||||
this.findTime += 0.05f;
|
||||
|
||||
if (this.findTime > 2f)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-Continue 7");
|
||||
this.findTime = 0f;
|
||||
this.FindTarget();
|
||||
if (this.closeTargetEntity && this.closeTargetEntity != this.targetEntity)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-Continue we have a close target and its not equal to targetEntity return false");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.theEntity.GetAttackTarget() != this.targetEntity)
|
||||
{
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-Continue this.theEntity.GetAttackTarget() != this.targetEntity");
|
||||
return false;
|
||||
}
|
||||
|
||||
//Log.Out("EAISetNearestEntityAsTargetCompanion-Continue 19");
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
this.targetEntity = null;
|
||||
this.targetPlayer = null;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Format("{0}, {1}", base.ToString(), this.targetEntity ? this.targetEntity.EntityName : "");
|
||||
}
|
||||
|
||||
private const float cHearDistMax = 50f;
|
||||
private List<EAISetNearestEntityAsTargetCompanion.TargetClass> targetClasses;
|
||||
private int playerTargetClassIndex = -1;
|
||||
private float closeTargetDist;
|
||||
private EntityAlive closeTargetEntity;
|
||||
private EntityAlive targetEntity;
|
||||
private EntityPlayer targetPlayer;
|
||||
private Vector3 lastSeenPos;
|
||||
private float findTime;
|
||||
private float senseSoundTime;
|
||||
private EAISetNearestEntityAsTargetSorter sorter;
|
||||
private static List<Entity> list = new List<Entity>();
|
||||
private struct TargetClass
|
||||
{
|
||||
public Type type;
|
||||
public float hearDistMax;
|
||||
public float seeDistMax;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user