Upload from upload_mods.ps1

This commit is contained in:
Nathaniel Cosford
2025-06-04 16:44:53 +09:30
commit f1fbbe67bb
1722 changed files with 165268 additions and 0 deletions

View 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;
}
}

View 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;
}

View 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;
}

View 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;
}
}

View 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;
}
}

View 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;
}
}

View 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;
}
}

View 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;
}

View 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;
}

View 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;
}
}

View 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;
}
}

View 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;
}
}

View 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;
}
}

View 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;
}

View 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;
}

View 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;
}

View 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;
}
}

View 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;
}
}

View 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;
}
}