Upload from upload_mods.ps1
This commit is contained in:
244
Scripts/EAI/NPCs/EAISetAsTargetIfHurtCompanion.cs
Normal file
244
Scripts/EAI/NPCs/EAISetAsTargetIfHurtCompanion.cs
Normal file
@@ -0,0 +1,244 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine.Scripting;
|
||||
|
||||
[Preserve]
|
||||
public class EAISetAsTargetIfHurtCompanion : EAITarget
|
||||
{
|
||||
public override void Init(EntityAlive _theEntity)
|
||||
{
|
||||
base.Init(_theEntity, 0f, false);
|
||||
this.MutexBits = 1;
|
||||
}
|
||||
|
||||
public override void SetData(DictionarySave<string, string> data)
|
||||
{
|
||||
base.SetData(data);
|
||||
this.targetClasses = new List<EAISetAsTargetIfHurtCompanion.TargetClass>();
|
||||
string text;
|
||||
if (data.TryGetValue("class", out text))
|
||||
{
|
||||
string[] array = text.Split(',', StringSplitOptions.None);
|
||||
for (int i = 0; i < array.Length; i++)
|
||||
{
|
||||
EAISetAsTargetIfHurtCompanion.TargetClass item = default(EAISetAsTargetIfHurtCompanion.TargetClass);
|
||||
item.type = EntityFactory.GetEntityType(array[i]);
|
||||
this.targetClasses.Add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool NPCEAICanProceed()
|
||||
{
|
||||
bool result = true;
|
||||
|
||||
if (this.theEntity.Buffs.GetCustomVar("onMission") == 1f ||
|
||||
this.theEntity.Buffs.GetCustomVar("$FR_NPC_Respawn") == 1f ||
|
||||
this.theEntity.Buffs.GetCustomVar("$FR_NPC_Hidden") == 1f
|
||||
)
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-NPCEAICanProceed 1");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool stopAttacking = this.theEntity.Buffs.HasBuff("FuriousRamsayBuffPauseAttack") ||
|
||||
this.theEntity.Buffs.HasBuff("buffNPCModStopAttacking") ||
|
||||
this.theEntity.Buffs.HasBuff("FuriousRamsayStandStill");
|
||||
|
||||
if (stopAttacking)
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-NPCEAICanProceed 2");
|
||||
this.theEntity.SetRevengeTarget((EntityAlive) null);
|
||||
this.theEntity.attackTarget = (EntityAlive) null;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//Log.Out($"EAISetAsTargetIfHurtCompanion::NPCEAICanProceed END {theEntity}, return: {result}, attackTarget: {theEntity.attackTarget}");
|
||||
return result;
|
||||
}
|
||||
|
||||
public override bool CanExecute()
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-CanExecute START");
|
||||
|
||||
if (!NPCEAICanProceed())
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-CanExecute !NPCEAICanProceed()");
|
||||
return false;
|
||||
}
|
||||
|
||||
EntityAlive revengeTarget = this.theEntity.GetRevengeTarget();
|
||||
EntityAlive attackTarget = this.theEntity.GetAttackTarget();
|
||||
|
||||
//Log.Out($"EAISetAsTargetIfHurtCompanion::CanExecute - attackTarget: {theEntity.attackTarget}, revengeTarget: {revengeTarget}");
|
||||
/*
|
||||
if (revengeTarget == null)
|
||||
{
|
||||
//Log.Out($"EAISetAsTargetIfHurtCompanion::CanExecute {theEntity}, revengeTarget: {revengeTarget}, attackTarget: {theEntity.attackTarget}");
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-CanExecute revengeTarget == null");
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-CanExecute revengeTarget: " + revengeTarget.EntityClass.entityClassName);
|
||||
}
|
||||
if (attackTarget == null)
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-CanExecute attackTarget == null");
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-CanExecute attackTarget: " + attackTarget.EntityClass.entityClassName);
|
||||
}
|
||||
*/
|
||||
bool bIsValidTarget = true;
|
||||
|
||||
if (revengeTarget)
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtRebirth-CanExecute revengeTarget.EntityName: " + revengeTarget.EntityName);
|
||||
//Log.Out("EAISetAsTargetIfHurtRebirth-CanExecute revengeTarget.entityType: " + revengeTarget.entityType);
|
||||
//Log.Out("EAISetAsTargetIfHurtRebirth-CanExecute this.theEntity.entityType: " + this.theEntity.entityType);
|
||||
|
||||
bIsValidTarget = RebirthUtilities.VerifyFactionStanding(this.theEntity, revengeTarget); //revengeTarget.entityType != this.theEntity.entityType;
|
||||
//Log.Out("EAISetAsTargetIfHurtRebirth-CanExecute bIsValidTarget: " + bIsValidTarget);
|
||||
}
|
||||
|
||||
if (revengeTarget && revengeTarget != attackTarget && bIsValidTarget)
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-CanExecute 1");
|
||||
if (this.targetClasses != null)
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-CanExecute 2");
|
||||
bool flag = false;
|
||||
Type type = revengeTarget.GetType();
|
||||
for (int i = 0; i < this.targetClasses.Count; i++)
|
||||
{
|
||||
EAISetAsTargetIfHurtCompanion.TargetClass targetClass = this.targetClasses[i];
|
||||
if (targetClass.type != null && targetClass.type.IsAssignableFrom(type))
|
||||
{
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!flag)
|
||||
{
|
||||
//Log.Out($"EAISetAsTargetIfHurtCompanion::CanExecute - attackTarget: {theEntity.attackTarget}, revengeTarget: {revengeTarget} !flag return false");
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-CanExecute 3");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (attackTarget != null && attackTarget.IsAlive() && base.RandomFloat < 0.66f)
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-CanExecute 4");
|
||||
//Log.Out($"EAISetAsTargetIfHurtCompanion::CanExecute - attackTarget: {theEntity.attackTarget}, revengeTarget: {revengeTarget} not null and is alive");
|
||||
this.theEntity.SetRevengeTarget((EntityAlive) null);
|
||||
return false;
|
||||
}
|
||||
if (base.check(revengeTarget))
|
||||
{
|
||||
//Log.Out($"EAISetAsTargetIfHurtCompanion::CanExecute - attackTarget: {theEntity.attackTarget}, revengeTarget: {revengeTarget} base.check return true");
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-CanExecute 5");
|
||||
return true;
|
||||
}
|
||||
Vector3 vector = this.theEntity.position - revengeTarget.position;
|
||||
float searchRadius = EntityClass.list[this.theEntity.entityClass].SearchRadius;
|
||||
vector = revengeTarget.position + vector.normalized * (searchRadius * 0.35f);
|
||||
Vector3 vector2 = this.manager.random.RandomOnUnitSphere * searchRadius;
|
||||
vector.x += vector2.x;
|
||||
vector.z += vector2.z;
|
||||
Vector3i vector3i = World.worldToBlockPos(vector);
|
||||
int height = (int)this.theEntity.world.GetHeight(vector3i.x, vector3i.z);
|
||||
if (height > 0)
|
||||
{
|
||||
vector.y = (float)height;
|
||||
}
|
||||
int num2 = this.theEntity.CalcInvestigateTicks(1200, revengeTarget);
|
||||
this.theEntity.SetInvestigatePosition(vector, num2, true);
|
||||
//Log.Out($"SetInvestigatePosition - vector: {vector}, attackTarget: {theEntity.attackTarget}, revengeTarget: {revengeTarget}");
|
||||
if (this.theEntity.entityType == EntityType.Zombie)
|
||||
{
|
||||
num2 /= 6;
|
||||
}
|
||||
this.theEntity.SetAlertTicks(num2);
|
||||
this.theEntity.SetRevengeTarget((EntityAlive) null);
|
||||
}
|
||||
//Log.Out($"EAISetAsTargetIfHurtCompanion::CanExecute END - attackTarget: {theEntity.attackTarget}, revengeTarget: {revengeTarget} return false");
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void Start()
|
||||
{
|
||||
this.theEntity.SetAttackTarget(this.theEntity.GetRevengeTarget(), 400);
|
||||
//Log.Out($"EAISetAsTargetIfHurtCompanion-Start attackTarget: {theEntity.attackTarget}");
|
||||
|
||||
this.viewAngleSave = this.theEntity.GetMaxViewAngle();
|
||||
this.theEntity.SetMaxViewAngle(270f);
|
||||
this.viewAngleRestoreCounter = 100;
|
||||
base.Start();
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-Update START");
|
||||
|
||||
if (!NPCEAICanProceed())
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-Update !NPCEAICanProceed return");
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.viewAngleRestoreCounter > 0)
|
||||
{
|
||||
this.viewAngleRestoreCounter--;
|
||||
if (this.viewAngleRestoreCounter == 0)
|
||||
{
|
||||
this.restoreViewAngle();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Continue()
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-Continue START");
|
||||
|
||||
if (!NPCEAICanProceed())
|
||||
{
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-Continue !NPCEAICanProceed return false");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool revengeTargetIsNull = (this.theEntity.GetRevengeTarget() != null);
|
||||
bool revengeAndAttackTargetDifferent = (this.theEntity.GetAttackTarget() != this.theEntity.GetRevengeTarget());
|
||||
bool baseContinue = base.Continue();
|
||||
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-Continue revengeTargetIsNull: " + revengeTargetIsNull);
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-Continue revengeAndAttackTargetDifferent: " + revengeAndAttackTargetDifferent);
|
||||
//Log.Out("EAISetAsTargetIfHurtCompanion-Continue baseContinue: " + baseContinue);
|
||||
|
||||
//Log.Out($"EAISetAsTargetIfHurtCompanion::Continue END {theEntity}, return: {(!revengeTargetIsNull || !revengeAndAttackTargetDifferent) && baseContinue}, attackTarget: {theEntity.attackTarget}");
|
||||
return (!revengeTargetIsNull || !revengeAndAttackTargetDifferent) && baseContinue;
|
||||
}
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
base.Reset();
|
||||
this.restoreViewAngle();
|
||||
}
|
||||
|
||||
private void restoreViewAngle()
|
||||
{
|
||||
if (this.viewAngleSave > 0f)
|
||||
{
|
||||
this.theEntity.SetMaxViewAngle(this.viewAngleSave);
|
||||
this.viewAngleSave = 0f;
|
||||
this.viewAngleRestoreCounter = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private List<EAISetAsTargetIfHurtCompanion.TargetClass> targetClasses;
|
||||
private float viewAngleSave;
|
||||
private int viewAngleRestoreCounter;
|
||||
private struct TargetClass
|
||||
{
|
||||
public Type type;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user