Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Game.AI;
- using Game.GameData;
- using Game.TacticalMode;
- using Game.UI;
- using Newtonsoft.Json;
- using OEIFormats;
- using Onyx;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Diagnostics;
- using System.IO;
- using System.Runtime.CompilerServices;
- using System.Text;
- using System.Threading;
- using UnityEngine;
- using UnityEngine.Serialization;
- namespace Game
- {
- [ScriptEventType(new ScriptEvent.ScriptEvents[]
- {
- ScriptEvent.ScriptEvents.OnPerceptionPerLoad,
- ScriptEvent.ScriptEvents.OnPerception,
- ScriptEvent.ScriptEvents.OnPerceptionOfStealthed,
- ScriptEvent.ScriptEvents.OnPerceptionOfNonStealthed,
- ScriptEvent.ScriptEvents.OnInvestigate,
- ScriptEvent.ScriptEvents.OnShoutAlert,
- ScriptEvent.ScriptEvents.OnFriendlyDeathAlert,
- ScriptEvent.ScriptEvents.OnScriptedMoveComplete
- }), RequireComponent(typeof(Mover)), RequireComponent(typeof(Mover)), RequireComponent(typeof(Mover))]
- [Serializable]
- public class AIController : OnyxBehavior, IGameDataOwner, IPersistentData, IPersistentDataJson
- {
- public enum WeatherReactionType
- {
- None,
- SeekCover,
- LeaveCover
- }
- public class KiteTarget
- {
- public Faction m_target;
- public float m_ignoreTimer;
- public float m_ignoreDuration;
- protected Faction Target
- {
- get
- {
- return this.m_target;
- }
- }
- protected bool IsIgnoreTimeComplete
- {
- get
- {
- return this.m_ignoreTimer >= this.m_ignoreDuration;
- }
- }
- protected KiteTarget(Faction target)
- {
- this.m_target = target;
- this.m_ignoreDuration = GlobalGameSettingsGameData.Instance.KiteTargetIgnoreDuration;
- }
- protected void Update(float deltaTime)
- {
- this.m_ignoreTimer += deltaTime;
- }
- }
- [Serializable]
- public class ScheduleInteractionObjectSet
- {
- [Serializable]
- public class TimeSliceInteractionObject
- {
- [Tooltip("The guid string of the object to interact with for this time slice.")]
- public string InteractionObjectGuidString = string.Empty;
- [Tooltip("The maximum time in hours a character can randomly wait before changing time slices.")]
- public float StartTransitionDelay = 0.25f;
- [Tooltip("Whether the character can react to weather during this time slice.")]
- public bool ReactToWeather = true;
- public string InteractionObjectDebugName = string.Empty;
- public string InteractionObjectDebugSceneName = string.Empty;
- public GameObject m_interactionObject;
- public Guid m_interactionObjectGuid = Guid.Empty;
- protected GameObject InteractionObject
- {
- get
- {
- this.CacheInteractionObject();
- return this.m_interactionObject;
- }
- }
- protected Guid InteractionObjectGuid
- {
- get
- {
- if (this.m_interactionObjectGuid == Guid.Empty && !string.IsNullOrEmpty(this.InteractionObjectGuidString))
- {
- this.m_interactionObjectGuid = ScriptManager.StringToGuid(this.InteractionObjectGuidString);
- }
- return this.m_interactionObjectGuid;
- }
- }
- protected TimeSliceInteractionObject()
- {
- }
- protected void CacheInteractionObject()
- {
- if (this.m_interactionObject == null && !string.IsNullOrEmpty(this.InteractionObjectGuidString))
- {
- this.m_interactionObject = InstanceID.GetObjectByID(ScriptManager.StringToGuid(this.InteractionObjectGuidString));
- }
- }
- }
- public AIController.ScheduleInteractionObjectSet.TimeSliceInteractionObject[] InteractionObjects = new AIController.ScheduleInteractionObjectSet.TimeSliceInteractionObject[20];
- protected ScheduleInteractionObjectSet()
- {
- }
- }
- public class CombatParams
- {
- public Faction Target;
- public AIBehaviorManager.PreparingToActType PreparingToActType;
- public float WaitDuration;
- protected bool IsPendingCombat
- {
- get
- {
- return this.Target != null;
- }
- }
- protected bool IsTime
- {
- get
- {
- return this.WaitDuration <= 0f;
- }
- }
- protected CombatParams()
- {
- }
- protected void SetTarget(Faction target, AIBehaviorManager.PreparingToActType type)
- {
- this.Target = target;
- this.PreparingToActType = type;
- this.WaitDuration = OEIRandom.RangeInclusive(GlobalGameSettingsGameData.Instance.TargetScanMinimumCombatDelay, GlobalGameSettingsGameData.Instance.TargetScanMaximumCombatDelay);
- }
- protected void Update()
- {
- this.WaitDuration -= Time.get_deltaTime();
- }
- protected void Reset()
- {
- this.Target = null;
- this.PreparingToActType = AIBehaviorManager.PreparingToActType.None;
- this.WaitDuration = 0f;
- }
- }
- public delegate void SummonEvent(GameObject sender, EventArgs args);
- public enum DebugMode
- {
- None,
- MouseOver,
- All,
- Shout
- }
- public class ObjectsWithLifetime : IEquatable<AIController.ObjectsWithLifetime>
- {
- public AIController Obj;
- public float Lifetime;
- protected bool Expired
- {
- get
- {
- return this.Lifetime <= 0f;
- }
- }
- protected ObjectsWithLifetime(AIController obj, float lifetime)
- {
- this.Obj = obj;
- this.Lifetime = lifetime;
- }
- protected void Update()
- {
- this.Lifetime -= Time.get_deltaTime();
- }
- protected bool Equals(AIController.ObjectsWithLifetime other)
- {
- return other != null && other.Obj.Equals(this.Obj);
- }
- protected override bool Equals(object obj)
- {
- return this.Obj.Equals(obj);
- }
- protected override int GetHashCode()
- {
- return this.Obj.GetHashCode();
- }
- }
- public class DisengagementTracker
- {
- public AIController Enemy;
- public float WaitDuration;
- protected DisengagementTracker(AIController enemy)
- {
- this.Enemy = enemy;
- this.WaitDuration = 0f;
- }
- }
- [Serializable]
- public class PersistentData
- {
- [NonSerialized]
- public AISummonType ObsoleteSummonType;
- [NonSerialized]
- public Guid ObsoleteSummonerGuid = new Guid("00000000-0000-0000-0000-000000000000");
- [NonSerialized]
- public ScriptedBehaviorType PersistentScriptedBehavior;
- [NonSerialized]
- public Guid PersistentScriptedUseObjectGuid = new Guid("00000000-0000-0000-0000-000000000000");
- [NonSerialized]
- public bool ScanForTargetsEnabled = true;
- [NonSerialized]
- public bool IsEmerging;
- public bool m_IsGuard;
- protected PersistentData()
- {
- }
- protected void Clear()
- {
- this.ObsoleteSummonType = AISummonType.NotSummoned;
- this.ObsoleteSummonerGuid = new Guid("00000000-0000-0000-0000-000000000000");
- this.PersistentScriptedBehavior = ScriptedBehaviorType.None;
- this.PersistentScriptedUseObjectGuid = new Guid("00000000-0000-0000-0000-000000000000");
- this.ScanForTargetsEnabled = true;
- this.IsEmerging = false;
- this.m_IsGuard = false;
- }
- }
- public static List<AIController> s_activeControllers = new List<AIController>();
- public static ReadOnlyCollection<AIController> s_activeControllersReadOnly;
- public const int MaxScheduleTimeSlices = 20;
- public const float MaxArrivalDistance = 10000f;
- [Tooltip("The default behavior of the NPC when not in combat.")]
- public AIBehaviorManager.DefaultAIBehaviorType AIBehavior;
- [SerializeField, Tooltip("The file containing the actions to perform when in combat (in addition to progression table decision trees).")]
- public AIDecisionTreeReference[] m_decisionTreeReferences = new AIDecisionTreeReference[0];
- public List<AIDecisionTreeData> m_decisionTrees = new List<AIDecisionTreeData>();
- [Tooltip("The method of choosing which DecisionTree action to run if multiple trees have a valid action to run (overrides progression table decision tree selection). Only used if AIController has additional DecisionTrees set.")]
- public AIDecisionTreeSelectionType DecisionTreeSelectionOverride = AIDecisionTreeSelectionType.RoundRobin;
- public Guid LastDecisionTreeToRunAction = Guid.Empty;
- [Tooltip("The AI schedule containing the time slices for interacting with objects.")]
- public ScheduleGameDataReference ScheduleReference = new ScheduleGameDataReference();
- [Tooltip("A list of objects for the character to interact with while following a schedule.")]
- public AIController.ScheduleInteractionObjectSet ScheduleInteractionObjects = new AIController.ScheduleInteractionObjectSet();
- [Tooltip("If AI Behavior is set to \"Follow\", the character to follow.")]
- public GameObject FollowObject;
- [Tooltip("The type of weapon to use in an idle situation.")]
- public WeaponPreferenceType WeaponPreference;
- [Tooltip("The behavior to execute which can be modified through script. None = Use default behavior. Idle = Stand in place. Use Scripted Object = Interact with the object set in Scripted Use Object.")]
- public ScriptedBehaviorType ScriptedBehavior;
- [Tooltip("The object to interact with when the Scripted Behavior is set to Use Scripted Object.")]
- public GameObject ScriptedUseObject;
- [ReadOnlyProperty, FormerlySerializedAs("ShoutRange"), SerializeField, Tooltip("(NOTE: Currently ignored value!) When issuing a request for help in combat, alert allies within this distance.")]
- public float m_shoutRange = 9f;
- [FormerlySerializedAs("DetectsStealthedCharacters"), SerializeField, Tooltip("If checked, this NPC can see party members who are stealthed.")]
- public bool m_detectsStealthedCharactersSetting = true;
- [Obsolete("Use IsGuard instead. Only for data backwards-compat."), HideInInspector, SerializeField, Tooltip("Designates this character to have a 'guard' indicator above their head.")]
- public bool m_isGuard;
- [Tooltip("When true, the character must die for combat to end.")]
- public bool CombatEndsOnDeath;
- [Tooltip("If true, the character will try to stay near his original start position when not patrolling.")]
- public bool Tethered = true;
- [Tooltip("NPCs who are tethered will try to stay within this distance of their start location.")]
- public float TetherDistance = 30f;
- [HideInInspector]
- public AIBehaviorStack BehaviorStack = new AIBehaviorStack();
- [HideInInspector]
- public ModalStack ModalStack = new ModalStack();
- [HideInInspector]
- public bool OverrideSummonBehvaior;
- public bool HideOffscreenMeshes;
- public CharacterStats m_characterStats;
- public Health m_health;
- public Faction m_faction;
- public AnimationController m_animController;
- public Mover m_mover;
- public Equipment m_equipment;
- public Townie m_townie;
- public WorldMapAIController m_shipController;
- public PartyMember m_partyMember;
- public AISchedule m_aiSchedule = new AISchedule();
- public AITownieSchedule m_aiTownieSchedule;
- public Dictionary<Guid, ActionCooldown[]> m_cooldowns;
- public bool m_isFogVisible;
- public AlphaControl m_alphaControl;
- public float m_desiredAlpha = 1f;
- public bool m_hasNotifiedAttackingSameTargetAsAlly;
- public float m_sameTargetCheckTimer;
- public float m_primaryAttackReevaluationTimer;
- [DebuggerBrowsable(DebuggerBrowsableState.Never), CompilerGenerated]
- public Action<GameObject, bool> OnAttackingSameTargetAsAllyStateChange;
- public ScriptEvent m_scriptEvent;
- public List<GameObject> m_summonedCreatures = new List<GameObject>();
- [DebuggerBrowsable(DebuggerBrowsableState.Never), CompilerGenerated]
- public AIController.SummonEvent OnSummonsChanged;
- public OnyxEvent<int> OnConversationAnimation = new OnyxEvent<int>();
- public OnyxEvent<FlowChartPlayer, GameObject> OnConversationPauseState = new OnyxEvent<FlowChartPlayer, GameObject>();
- public Vector3 m_retreatPosition = Vector3.get_zero();
- public List<AIController.KiteTarget> m_kiteTargets = new List<AIController.KiteTarget>(0);
- public GameObject m_highestDamageInflictor;
- public float m_highestDamageInflicted;
- public bool m_ignoreAsCutsceneObstacle;
- public bool m_inCutscene;
- public Encounter m_parentEncounter;
- public bool m_mustDieForCombatToEnd;
- public AttackBase m_previousAttack;
- public float m_holdTimer;
- public bool m_holdMove;
- public bool m_unsetEmergeFlags;
- public bool m_detectsStealthedCharacters = true;
- public const float DefendMyselfMeleeSearchDistance = 3f;
- public const float DefendMyselfRangedSearchDistance = 6f;
- public const float DefensiveMeleeSearchDistance = 6f;
- public const float DefensiveRangedSearchDistance = 9f;
- public const float AggressiveSearchDistance = 20f;
- public bool m_hasShoutedForHelp;
- public bool m_hasBeenInitialized;
- public bool m_isBusy;
- public OnyxEvent<AIController> OnTurnStart = new OnyxEvent<AIController>();
- public OnyxEvent<AIController> OnTurnEnd = new OnyxEvent<AIController>();
- public OnyxEvent<TimeType, float> OnTimeElapsed = new OnyxEvent<TimeType, float>();
- public bool m_availableAction;
- public float m_availableMovement;
- public ReadOnlyCollection<GameObject> m_summonedCreaturesReadOnly;
- public bool m_shouldReactToWeatherAfterDelay;
- public AIController.WeatherReactionType m_weatherReactionType;
- public float m_weatherReactionDelay;
- public float m_weatherReactionTimer;
- public static AIController.DebugMode m_debugMode = AIController.DebugMode.None;
- public float m_debugShoutTimer;
- public bool m_debugShoutOrigin;
- public static bool DebugEngagement = false;
- public int m_cachedEngagementLimit;
- public List<AIController> m_engagedEnemies = new List<AIController>();
- public List<AIController> m_engagedBy = new List<AIController>();
- public List<AIController> m_threatenedEnemies = new List<AIController>();
- public List<AIController> m_threatenedBy = new List<AIController>();
- public ReadOnlyCollection<AIController> m_engagedEnemiesReadOnly;
- public ReadOnlyCollection<AIController> m_engagedByReadOnly;
- public ReadOnlyCollection<AIController> m_threatenedEnemiesReadOnly;
- public ReadOnlyCollection<AIController> m_threatenedByReadOnly;
- public bool m_engagementDisabled;
- public List<AIController.ObjectsWithLifetime> m_trackedObjectList = new List<AIController.ObjectsWithLifetime>();
- public List<AIController.DisengagementTracker> m_disengagementTrackers = new List<AIController.DisengagementTracker>();
- public const float ScanInterval = 1f;
- public float m_scanWaitDuration;
- public bool m_trackingSuspicion;
- public float m_suspicionDeltaTime;
- public bool m_forcePerceptionChecks;
- public bool m_previousPerceptionState;
- public bool m_perceptionTriggered;
- public AIController.CombatParams m_delayedCombatParams = new AIController.CombatParams();
- public float[] m_lastDetectingTimestamp = new float[3];
- public OnyxEvent<GameObject, GameObject, bool> OnPerception = new OnyxEvent<GameObject, GameObject, bool>();
- public ObjectPool<AIDamageTracker> m_damageTrackerPool = new ObjectPool<AIDamageTracker>(64);
- public Dictionary<Faction, List<AIDamageTracker>> m_damageTracker = new Dictionary<Faction, List<AIDamageTracker>>();
- public static Guid TypeID = new Guid("ff6a7e96-e229-4589-afab-cb71a7012c6f");
- public const int SaveVersion = 3;
- [NonSerialized]
- public int m_loadVersion;
- [SerializeField]
- public AIController.PersistentData m_persistentAIController = new AIController.PersistentData();
- protected event Action<GameObject, bool> OnAttackingSameTargetAsAllyStateChangeEvent
- {
- add
- {
- Action<GameObject, bool> action = this.OnAttackingSameTargetAsAllyStateChange;
- Action<GameObject, bool> action2;
- do
- {
- action2 = action;
- action = Interlocked.CompareExchange<Action<GameObject, bool>>(ref this.OnAttackingSameTargetAsAllyStateChange, (Action<GameObject, bool>)Delegate.Combine(action2, value), action);
- }
- while (action != action2);
- }
- remove
- {
- Action<GameObject, bool> action = this.OnAttackingSameTargetAsAllyStateChange;
- Action<GameObject, bool> action2;
- do
- {
- action2 = action;
- action = Interlocked.CompareExchange<Action<GameObject, bool>>(ref this.OnAttackingSameTargetAsAllyStateChange, (Action<GameObject, bool>)Delegate.Remove(action2, value), action);
- }
- while (action != action2);
- }
- }
- protected event AIController.SummonEvent OnSummonsChangedEvent
- {
- add
- {
- AIController.SummonEvent summonEvent = this.OnSummonsChanged;
- AIController.SummonEvent summonEvent2;
- do
- {
- summonEvent2 = summonEvent;
- summonEvent = Interlocked.CompareExchange<AIController.SummonEvent>(ref this.OnSummonsChanged, (AIController.SummonEvent)Delegate.Combine(summonEvent2, value), summonEvent);
- }
- while (summonEvent != summonEvent2);
- }
- remove
- {
- AIController.SummonEvent summonEvent = this.OnSummonsChanged;
- AIController.SummonEvent summonEvent2;
- do
- {
- summonEvent2 = summonEvent;
- summonEvent = Interlocked.CompareExchange<AIController.SummonEvent>(ref this.OnSummonsChanged, (AIController.SummonEvent)Delegate.Remove(summonEvent2, value), summonEvent);
- }
- while (summonEvent != summonEvent2);
- }
- }
- protected static ReadOnlyCollection<AIController> ActiveControllers
- {
- get
- {
- if (AIController.s_activeControllersReadOnly == null)
- {
- AIController.s_activeControllersReadOnly = new ReadOnlyCollection<AIController>(AIController.s_activeControllers);
- }
- return AIController.s_activeControllersReadOnly;
- }
- }
- protected List<AIDecisionTreeData> DecisionTrees
- {
- get
- {
- return this.m_decisionTrees;
- }
- }
- protected float ShoutRange
- {
- get
- {
- return 15f;
- }
- }
- protected SummonedCharacter SummonedCharacter
- {
- get;
- set;
- }
- protected bool HasRealEnemyNearby
- {
- get;
- set;
- }
- protected Vector3 RetreatPosition
- {
- get
- {
- return this.m_retreatPosition;
- }
- }
- protected bool InCutscene
- {
- get
- {
- return this.m_inCutscene;
- }
- set
- {
- this.m_inCutscene = value;
- }
- }
- protected bool InCastIntro
- {
- get
- {
- return this.BehaviorStack.CurrentBehavior != null && (this.BehaviorStack.CurrentBehavior.CurrentState is CastIntroState || this.BehaviorStack.CurrentBehavior.CurrentState is GrappleIntroState);
- }
- }
- protected bool DetectsStealthedCharacters
- {
- get
- {
- return this.m_detectsStealthedCharacters && this.m_detectsStealthedCharactersSetting;
- }
- set
- {
- this.m_detectsStealthedCharacters = value;
- }
- }
- protected bool IsGuard
- {
- get
- {
- return this.m_IsGuard;
- }
- set
- {
- this.m_IsGuard = value;
- if (this.IsGuard)
- {
- UIInvestigateManager.ShowIcon(base.get_gameObject(), UIInvestigateIndicator.IconType.Guard, 1f);
- }
- }
- }
- protected bool HideStealthViewElements
- {
- get;
- set;
- }
- protected int TacticalTurnEventCount
- {
- get;
- set;
- }
- protected bool IsInTacticalCombat
- {
- get
- {
- return this.TacticalTurnEventCount > 0;
- }
- }
- protected bool AvailableAction
- {
- get
- {
- return this.m_availableAction;
- }
- set
- {
- if (SingletonBehavior<TacticalModeManager>.Instance.UnlimitedActions && SingletonBehavior<PartyManager>.Instance.IsActivePartyMember(this.m_partyMember) && this.m_partyMember.IsControllable)
- {
- this.m_availableAction = true;
- }
- else
- {
- this.m_availableAction = value;
- }
- this.CheckEndTurn();
- }
- }
- protected float AvailableMovement
- {
- get
- {
- return this.m_availableMovement;
- }
- set
- {
- if (SingletonBehavior<TacticalModeManager>.Instance.UnlimitedMovement && SingletonBehavior<PartyManager>.Instance.IsActivePartyMember(this.m_partyMember) && this.m_partyMember.IsControllable)
- {
- this.m_availableMovement = Mathf.Max(this.m_availableMovement, value);
- }
- else
- {
- this.m_availableMovement = value;
- }
- this.CheckEndTurn();
- }
- }
- protected float AvailableMoveDistance
- {
- get
- {
- this.Mover.CalculateDesiredSpeed();
- return this.AvailableMovement * this.Mover.DesiredSpeed;
- }
- }
- protected float CachedAvailableMoveDistance
- {
- get;
- set;
- }
- protected float ProjectedMoveDistance
- {
- get
- {
- return this.Mover.PathDistance;
- }
- }
- protected CharacterStats CharacterStats
- {
- get
- {
- return this.m_characterStats;
- }
- }
- protected PartyMember PartyMember
- {
- get
- {
- return this.m_partyMember;
- }
- }
- protected Faction Faction
- {
- get
- {
- return this.m_faction;
- }
- }
- protected Equipment Equipment
- {
- get
- {
- return this.m_equipment;
- }
- }
- protected AISchedule AISchedule
- {
- get
- {
- return this.m_aiSchedule;
- }
- }
- protected AITownieSchedule AITownieSchedule
- {
- get
- {
- return this.m_aiTownieSchedule;
- }
- }
- protected Dictionary<Guid, ActionCooldown[]> Cooldowns
- {
- get
- {
- return this.m_cooldowns;
- }
- }
- protected bool IsFogVisible
- {
- get
- {
- return this.m_isFogVisible;
- }
- }
- protected float DesiredAlpha
- {
- get
- {
- return this.m_desiredAlpha;
- }
- }
- protected bool IsTimeToReevaluatePrimaryAttack
- {
- get
- {
- return this.m_primaryAttackReevaluationTimer <= 0f;
- }
- }
- protected AIController GrappleTarget
- {
- get;
- set;
- }
- protected Mover Mover
- {
- get
- {
- if (this.m_mover == null)
- {
- this.m_mover = base.GetComponent<Mover>();
- if (this.m_mover == null)
- {
- this.m_mover = ResourceManager.AddComponent<Mover>(base.get_gameObject());
- }
- }
- return this.m_mover;
- }
- }
- protected Health Health
- {
- get
- {
- return this.m_health;
- }
- }
- protected bool IsTownie
- {
- get
- {
- return this.m_townie != null;
- }
- }
- protected bool IsTownieReacting
- {
- get
- {
- return this.m_townie != null && this.m_townie.IsReacting;
- }
- }
- protected GameObject HighestDamageInflictor
- {
- get
- {
- return this.m_highestDamageInflictor;
- }
- }
- protected bool MustDieForCombatToEnd
- {
- get
- {
- return this.m_mustDieForCombatToEnd;
- }
- set
- {
- this.m_mustDieForCombatToEnd = value;
- if (this.m_mustDieForCombatToEnd)
- {
- this.MarkSummonsMustDieForCombatToEnd();
- }
- }
- }
- protected bool IsInvisible
- {
- get
- {
- return this.m_desiredAlpha <= 1.401298E-45f || (this.m_characterStats != null && this.m_characterStats.IsInvisible(false));
- }
- }
- protected bool IgnoreAsCutsceneObstacle
- {
- get
- {
- return this.m_ignoreAsCutsceneObstacle;
- }
- set
- {
- this.m_ignoreAsCutsceneObstacle = value;
- }
- }
- protected bool IsBusy
- {
- get
- {
- return this.m_isBusy;
- }
- set
- {
- this.m_isBusy = value;
- }
- }
- protected bool IsLurking
- {
- get
- {
- return this.BehaviorStack != null && this.BehaviorStack.CurrentBehavior != null && this.BehaviorStack.CurrentBehavior.CurrentState is EmergeLurkState;
- }
- }
- protected bool IsHoldingPosition
- {
- get
- {
- return this.m_holdMove || this.m_holdTimer > 0f;
- }
- }
- protected bool IsFaded
- {
- get
- {
- return this.m_alphaControl != null && this.m_alphaControl.IsFaded;
- }
- }
- protected ReadOnlyCollection<GameObject> SummonedCreatureList
- {
- get
- {
- if (this.m_summonedCreaturesReadOnly == null)
- {
- this.m_summonedCreaturesReadOnly = new ReadOnlyCollection<GameObject>(this.m_summonedCreatures);
- }
- return this.m_summonedCreaturesReadOnly;
- }
- }
- protected virtual float StealthedCharacterHearingDistance
- {
- get
- {
- if (!base.get_gameObject().get_activeInHierarchy() || (this.m_health != null && this.m_health.IsDeadOrUnconscious))
- {
- return 0f;
- }
- if (this.m_characterStats == null)
- {
- return 5f;
- }
- return this.m_characterStats.StealthedCharacerHearingDistance;
- }
- }
- protected virtual float StealthedCharacterVisionDistance
- {
- get
- {
- if (!base.get_gameObject().get_activeInHierarchy() || (this.m_health != null && this.m_health.IsDeadOrUnconscious))
- {
- return 0f;
- }
- if (this.m_characterStats == null)
- {
- return 10f;
- }
- return this.m_characterStats.StealthedCharacterVisionDistance;
- }
- }
- protected virtual float StealthedCharacterVisionAngle
- {
- get
- {
- if (!base.get_gameObject().get_activeInHierarchy() || (this.m_health != null && this.m_health.IsDeadOrUnconscious))
- {
- return 0f;
- }
- if (this.m_characterStats == null)
- {
- return 30f;
- }
- return this.m_characterStats.StealthedCharacterVisionAngle;
- }
- }
- protected virtual float PerceptionDistance
- {
- get
- {
- if (!base.get_gameObject().get_activeInHierarchy() || (this.m_health != null && this.m_health.IsDeadOrUnconscious))
- {
- return 0f;
- }
- if (this.m_characterStats == null)
- {
- return 5f;
- }
- return GlobalGameSettingsGameData.Instance.EnemySightRange;
- }
- }
- protected bool IsInCombat
- {
- get
- {
- if ((this.m_health == null || !this.m_health.IsDeadOrUnconscious) && this.IsNearCombat())
- {
- return true;
- }
- AIBehaviorType currentBehaviorType = this.GetCurrentBehaviorType();
- if (currentBehaviorType == AIBehaviorType.Attack || currentBehaviorType == AIBehaviorType.Cast)
- {
- return true;
- }
- if (currentBehaviorType == AIBehaviorType.PreparingToAct)
- {
- PreparingToActParams preparingToActParams = this.BehaviorStack.CurrentBehavior.AIParams as PreparingToActParams;
- if (preparingToActParams.CurrentAction != null)
- {
- Game.AI.Action.ActionType actionType = preparingToActParams.CurrentAction.GetActionType();
- if (actionType == Game.AI.Action.ActionType.Attack || actionType == Game.AI.Action.ActionType.AttackDestructible || actionType == Game.AI.Action.ActionType.Cast)
- {
- return true;
- }
- }
- }
- return false;
- }
- }
- protected bool IsFighting
- {
- get
- {
- if (this.m_faction != null && this.m_faction.IsDominated)
- {
- return true;
- }
- if (this.m_mustDieForCombatToEnd && this.m_health != null && !this.m_health.IsDead)
- {
- return true;
- }
- AIBehavior currentBehavior = this.BehaviorStack.CurrentBehavior;
- if (currentBehavior != null)
- {
- AIBehaviorDataComponent aIBehaviorDataComponent = currentBehavior.AIBehaviorData.Component as AIBehaviorDataComponent;
- if (aIBehaviorDataComponent != null)
- {
- if (aIBehaviorDataComponent.InCombatBehavior == CombatBehaviorType.InCombat)
- {
- return true;
- }
- if (aIBehaviorDataComponent.InCombatBehavior == CombatBehaviorType.UseGlobalCombatState)
- {
- return GameState.InCombat;
- }
- if (aIBehaviorDataComponent.InCombatBehavior == CombatBehaviorType.UseBehaviorCombatState)
- {
- return currentBehavior.AIParams.InCombat;
- }
- }
- }
- return false;
- }
- }
- protected GameObject CurrentTarget
- {
- get
- {
- AIBehavior currentBehavior = this.BehaviorStack.CurrentBehavior;
- if (currentBehavior != null)
- {
- GameObject targetObject = currentBehavior.AIParams.GetTargetObject();
- if (targetObject != null && (this.m_mover == null || this.m_mover.TargetWaypoint == null || this.m_mover.TargetWaypoint.get_gameObject() != targetObject || this is WorldMapAIController))
- {
- return targetObject;
- }
- }
- return null;
- }
- }
- protected bool IsAttackingSameTargetAsAlly
- {
- get
- {
- GameObject currentTarget = this.CurrentTarget;
- if (currentTarget == null)
- {
- return false;
- }
- if (SingletonBehavior<PartyManager>.Instance.IsActivePartyMember(base.get_gameObject()))
- {
- foreach (PartyMember current in SingletonBehavior<PartyManager>.Instance.GetActivePartyMembers())
- {
- if (current != null && current.get_gameObject() != base.get_gameObject())
- {
- AIController aIController = current.AIController;
- if (aIController.CurrentTarget == currentTarget)
- {
- return true;
- }
- }
- }
- return false;
- }
- return false;
- }
- }
- protected bool IsTethered
- {
- get
- {
- return this is WorldMapAIController;
- }
- }
- protected float TetherDistanceSq
- {
- get
- {
- return this.TetherDistance * this.TetherDistance;
- }
- }
- protected virtual bool IsPet
- {
- get
- {
- return this.AIBehavior == AIBehaviorManager.DefaultAIBehaviorType.Pet || (this.SummonedCharacter != null && (this.SummonedCharacter.SummonType == AISummonType.Pet || this.SummonedCharacter.SummonType == AISummonType.CombatPet));
- }
- }
- protected virtual bool IsTargettablePet
- {
- get
- {
- return this.SummonedCharacter != null && this.SummonedCharacter.SummonType == AISummonType.CombatPet;
- }
- }
- protected bool IsExecutingDefaultBehavior
- {
- get
- {
- return this.BehaviorStack.BehaviorCount == 1;
- }
- }
- protected static AIController.DebugMode DebuggingMode
- {
- get
- {
- return AIController.m_debugMode;
- }
- set
- {
- AIController.m_debugMode = value;
- }
- }
- protected override bool UsesOnyxGUI
- {
- get
- {
- return OnyxBehaviorManagerBase.DebugOnyxGUI;
- }
- }
- protected ReadOnlyCollection<AIController> EngagedEnemies
- {
- get
- {
- if (this.m_engagedEnemiesReadOnly == null)
- {
- this.m_engagedEnemiesReadOnly = new ReadOnlyCollection<AIController>(this.m_engagedEnemies);
- }
- return this.m_engagedEnemiesReadOnly;
- }
- }
- protected ReadOnlyCollection<AIController> EngagedBy
- {
- get
- {
- if (this.m_engagedByReadOnly == null)
- {
- this.m_engagedByReadOnly = new ReadOnlyCollection<AIController>(this.m_engagedBy);
- }
- return this.m_engagedByReadOnly;
- }
- }
- protected ReadOnlyCollection<AIController> ThreatenedEnemies
- {
- get
- {
- if (this.m_threatenedEnemiesReadOnly == null)
- {
- this.m_threatenedEnemiesReadOnly = new ReadOnlyCollection<AIController>(this.m_threatenedEnemies);
- }
- return this.m_threatenedEnemiesReadOnly;
- }
- }
- protected ReadOnlyCollection<AIController> ThreatenedBy
- {
- get
- {
- if (this.m_threatenedByReadOnly == null)
- {
- this.m_threatenedByReadOnly = new ReadOnlyCollection<AIController>(this.m_threatenedBy);
- }
- return this.m_threatenedByReadOnly;
- }
- }
- protected bool EngagementDisabled
- {
- get
- {
- return this.m_engagementDisabled || this.ThreatDisabled;
- }
- set
- {
- this.m_engagementDisabled = value;
- }
- }
- protected bool ThreatDisabled
- {
- get;
- set;
- }
- protected float TimeSinceStartedHearing
- {
- get;
- set;
- }
- protected float TimeSinceStartedSeeing
- {
- get;
- set;
- }
- protected AISummonType ObsoleteSummonType
- {
- get
- {
- return this.m_persistentAIController.ObsoleteSummonType;
- }
- set
- {
- this.m_persistentAIController.ObsoleteSummonType = value;
- }
- }
- protected Guid ObsoleteSummonerGuid
- {
- get
- {
- return this.m_persistentAIController.ObsoleteSummonerGuid;
- }
- set
- {
- this.m_persistentAIController.ObsoleteSummonerGuid = value;
- }
- }
- protected ScriptedBehaviorType PersistentScriptedBehavior
- {
- get
- {
- return this.m_persistentAIController.PersistentScriptedBehavior;
- }
- set
- {
- this.m_persistentAIController.PersistentScriptedBehavior = value;
- }
- }
- protected Guid PersistentScriptedUseObjectGuid
- {
- get
- {
- return this.m_persistentAIController.PersistentScriptedUseObjectGuid;
- }
- set
- {
- this.m_persistentAIController.PersistentScriptedUseObjectGuid = value;
- }
- }
- protected bool ScanForTargetsEnabled
- {
- get
- {
- return this.m_persistentAIController.ScanForTargetsEnabled;
- }
- set
- {
- this.m_persistentAIController.ScanForTargetsEnabled = value;
- }
- }
- protected bool IsEmerging
- {
- get
- {
- return this.m_persistentAIController.IsEmerging;
- }
- set
- {
- this.m_persistentAIController.IsEmerging = value;
- }
- }
- protected bool m_IsGuard
- {
- get
- {
- return this.m_persistentAIController.m_IsGuard;
- }
- set
- {
- this.m_persistentAIController.m_IsGuard = value;
- }
- }
- protected AIController()
- {
- }
- protected void CacheAvailableMoveDistance()
- {
- this.CachedAvailableMoveDistance = this.AvailableMoveDistance;
- }
- protected void BeginTurn()
- {
- this.AvailableAction = true;
- this.AvailableMovement = TacticalModeManager.MovementTimePerRound;
- this.OnTurnStart.Trigger(this);
- this.OnTimeElapsedMethod(TimeType.EffectTime, TacticalModeManager.EffectTimePerRound);
- this.BehaviorStack.OnTurnStart();
- }
- protected void EndTurn()
- {
- this.OnTurnEnd.Trigger(this);
- }
- protected bool PassTurnIfNPC()
- {
- if (!PartyManager.IsControllablePartyMember(this.PartyMember))
- {
- this.PassTurn(PassTurnStyle.Forced);
- return true;
- }
- return false;
- }
- protected void PassTurn(PassTurnStyle style)
- {
- this.AvailableAction = false;
- this.AvailableMovement = 0f;
- SingletonBehavior<TacticalModeManager>.Instance.FinishTurn(this, style);
- }
- protected void PassTurnNoCallback()
- {
- this.m_availableAction = false;
- this.m_availableMovement = 0f;
- }
- protected void CheckEndTurn()
- {
- if (!this.m_availableAction && (!PartyManager.IsControllablePartyMember(this.PartyMember) || SingletonBehavior<TacticalModeManager>.Instance.AutoPassTurns))
- {
- SingletonBehavior<TacticalModeManager>.Instance.FinishTurn(this, PassTurnStyle.Forced);
- }
- }
- protected override void InitializeDefaultValues()
- {
- base.InitializeDefaultValues();
- this.BehaviorStack.Owner = base.get_gameObject();
- this.ModalStack.Owner = base.get_gameObject();
- if (this.m_decisionTreeReferences.Length > 0)
- {
- for (int i = 0; i < this.m_decisionTreeReferences.Length; i++)
- {
- if (!DataReference.IsNullOrEmpty(this.m_decisionTreeReferences[i]))
- {
- this.DecisionTrees.Add(this.m_decisionTreeReferences[i].Data);
- }
- }
- }
- if (this.m_characterStats != null)
- {
- AIDecisionTreeCollectionItem[] decisionTrees = this.m_characterStats.GetDecisionTrees();
- int num = 0;
- while (decisionTrees != null && num < decisionTrees.Length)
- {
- if (!DataReference.IsNullOrEmpty(decisionTrees[num].AIDecisionTree))
- {
- this.DecisionTrees.Add(decisionTrees[num].AIDecisionTree.Data);
- }
- num++;
- }
- }
- }
- protected override void Preactivate()
- {
- base.Preactivate();
- this.m_aiSchedule.SetAIController(this);
- if (SingletonBehavior<AIScheduleManager>.Instance)
- {
- SingletonBehavior<AIScheduleManager>.Instance.AddSchedule(this, this.m_aiSchedule);
- }
- }
- protected override void CacheComponents()
- {
- base.CacheComponents();
- this.UnsubscribeComponentEvents();
- this.m_characterStats = base.GetComponent<CharacterStats>();
- this.m_health = base.GetComponent<Health>();
- this.m_animController = base.GetComponent<AnimationController>();
- this.m_scriptEvent = base.GetComponent<ScriptEvent>();
- this.m_mover = base.GetComponent<Mover>();
- this.m_equipment = base.GetComponent<Equipment>();
- this.m_faction = base.GetComponent<Faction>();
- this.m_townie = base.GetComponent<Townie>();
- this.m_shipController = base.GetComponent<WorldMapAIController>();
- this.m_aiTownieSchedule = base.GetComponent<AITownieSchedule>();
- this.m_partyMember = base.GetComponent<PartyMember>();
- this.SummonedCharacter = base.GetComponent<SummonedCharacter>();
- if (this.m_health)
- {
- this.m_health.OnRevived += new Action<GameObject, CombatEventArgs>(this.OnHealthRevived);
- this.m_health.OnDeath += new Action<GameObject, CombatEventArgs>(this.OnHealthDeath);
- this.m_health.OnUnconscious += new Action<GameObject, CombatEventArgs>(this.OnHealthUnconscious);
- }
- if (this.m_characterStats)
- {
- this.m_characterStats.StatusEffectManager.OnAddStatusEffect += new Action<StatusEffectManager, StatusEffectInstance>(this.OnAddStatusEffect);
- }
- if (this.m_faction)
- {
- this.m_faction.OnFactionChanged.Subscribe(new Action<GameObject, TeamGameData>(this.OnFactionChanged));
- }
- }
- protected void UnsubscribeComponentEvents()
- {
- if (this.m_health)
- {
- this.m_health.OnRevived -= new Action<GameObject, CombatEventArgs>(this.OnHealthRevived);
- this.m_health.OnDeath -= new Action<GameObject, CombatEventArgs>(this.OnHealthDeath);
- this.m_health.OnUnconscious -= new Action<GameObject, CombatEventArgs>(this.OnHealthUnconscious);
- }
- if (this.m_characterStats)
- {
- this.m_characterStats.StatusEffectManager.OnAddStatusEffect -= new Action<StatusEffectManager, StatusEffectInstance>(this.OnAddStatusEffect);
- }
- if (this.m_faction)
- {
- this.m_faction.OnFactionChanged.Unsubscribe(new Action<GameObject, TeamGameData>(this.OnFactionChanged));
- }
- }
- protected override void OnyxAwake()
- {
- base.OnyxAwake();
- if (this.m_isGuard)
- {
- this.IsGuard = this.m_isGuard;
- this.m_isGuard = false;
- }
- this.InitCooldowns();
- this.InitScanning();
- this.CheckForPerceptionEvent();
- AIController.s_activeControllers.Add(this);
- if (!this.m_hasBeenInitialized)
- {
- this.Init();
- }
- }
- protected override void OnyxValidate()
- {
- base.OnyxValidate();
- if (this.m_isGuard)
- {
- this.IsGuard = this.m_isGuard;
- this.m_isGuard = false;
- }
- }
- protected override void OnyxStart()
- {
- base.OnyxStart();
- if (this.m_unsetEmergeFlags)
- {
- EmergeLurkState.SetIsActive(base.get_gameObject(), true);
- }
- if (this.IsGuard)
- {
- UIInvestigateManager.ShowIcon(base.get_gameObject(), UIInvestigateIndicator.IconType.Guard, 1f);
- }
- }
- protected void OnTimeElapsedMethod(TimeType timeType, float deltaTime)
- {
- this.OnTimeElapsed.Trigger(timeType, deltaTime);
- if (timeType == TimeType.EffectTime)
- {
- this.m_suspicionDeltaTime += deltaTime;
- }
- if (timeType == TimeType.EffectTime && this.m_kiteTargets.Count > 0)
- {
- for (int i = this.m_kiteTargets.Count - 1; i >= 0; i--)
- {
- this.m_kiteTargets[i].Update(deltaTime);
- if (this.m_kiteTargets[i].IsIgnoreTimeComplete)
- {
- this.m_kiteTargets.RemoveAt(i);
- }
- }
- }
- }
- protected override void OnyxUpdate()
- {
- if (GameState.IsLoading)
- {
- return;
- }
- if (GameState.Paused)
- {
- this.BehaviorStack.UpdateWhenPaused();
- this.UpdateUI();
- return;
- }
- bool flag;
- if (this.m_partyMember != null)
- {
- flag = GameState.ShouldBeInTacticalCombat;
- }
- else
- {
- flag = (GameState.ShouldBeInTacticalCombat && this.GetBehavior(AIBehaviorType.PreparingToAct) != null && !this.IsLurking);
- }
- if (!TacticalModeManager.IsInTacticalCombat(this))
- {
- if (flag)
- {
- SingletonBehavior<TacticalModeManager>.Instance.EnterCombat(this);
- }
- this.OnTimeElapsedMethod(TimeType.EffectTime, Time.get_deltaTime());
- }
- else if (!flag)
- {
- SingletonBehavior<TacticalModeManager>.Instance.ExitCombat(this);
- }
- this.OnTimeElapsedMethod(TimeType.GameTime, Time.get_deltaTime());
- this.UpdateCombatStance();
- this.UpdateScanning();
- this.UpdateEngagement(this.GetPrimaryAttack());
- this.ModalStack.Update();
- this.BehaviorStack.Update();
- this.m_sameTargetCheckTimer -= Time.get_deltaTime();
- if (this.m_sameTargetCheckTimer <= 0f)
- {
- bool isAttackingSameTargetAsAlly = this.IsAttackingSameTargetAsAlly;
- if (!isAttackingSameTargetAsAlly && this.m_hasNotifiedAttackingSameTargetAsAlly)
- {
- this.m_hasNotifiedAttackingSameTargetAsAlly = false;
- if (this.OnAttackingSameTargetAsAllyStateChange != null)
- {
- this.OnAttackingSameTargetAsAllyStateChange(base.get_gameObject(), false);
- }
- }
- else if (isAttackingSameTargetAsAlly && !this.m_hasNotifiedAttackingSameTargetAsAlly)
- {
- this.m_hasNotifiedAttackingSameTargetAsAlly = true;
- if (this.OnAttackingSameTargetAsAllyStateChange != null)
- {
- this.OnAttackingSameTargetAsAllyStateChange(base.get_gameObject(), true);
- }
- }
- this.m_sameTargetCheckTimer = 0.1f;
- }
- this.m_primaryAttackReevaluationTimer -= Time.get_deltaTime();
- if (this.m_holdTimer > 0f)
- {
- this.m_holdTimer -= Time.get_deltaTime();
- }
- this.CheckForInvalidEngagements();
- this.m_hasShoutedForHelp = false;
- for (int i = this.m_trackedObjectList.Count - 1; i >= 0; i--)
- {
- if (this.m_trackedObjectList[i].Obj == null)
- {
- this.m_trackedObjectList.RemoveAt(i);
- }
- else
- {
- this.m_trackedObjectList[i].Update();
- if (this.m_trackedObjectList[i].Expired)
- {
- this.m_trackedObjectList.RemoveAt(i);
- }
- }
- }
- this.UpdateWeatherReaction();
- this.UpdateUI();
- if (this.m_debugShoutTimer > 0f)
- {
- this.m_debugShoutTimer -= Time.get_deltaTime();
- }
- base.OnyxUpdate();
- }
- protected override void OnyxLateUpdate()
- {
- base.OnyxLateUpdate();
- if (this.HideOffscreenMeshes && this.m_mover && this.m_alphaControl)
- {
- if (this.m_mover.IsOnScreen(true) || GameState.IsCutsceneOrConversationRunning())
- {
- this.m_alphaControl.FadeTo(1f, 0f, AlphaControl.FadeType.Misc);
- }
- else
- {
- this.m_alphaControl.FadeTo(0f, 0f, AlphaControl.FadeType.Misc);
- }
- }
- }
- protected override void OnyxEnable()
- {
- if (!GameState.LoadedGame)
- {
- this.m_aiSchedule.PlaceAIOnSchedulePath();
- }
- this.InitDefaultBehavior();
- GameState.OnLevelLoaded += new Action<string>(this.GameState_OnLevelLoaded);
- GameState.OnCombatStart.Subscribe(new System.Action(this.HandleCombatStart));
- GameState.OnCombatEnd.Subscribe(new System.Action(this.HandleCombatEnd));
- this.CacheAlphaControl(true);
- base.OnyxEnable();
- }
- protected override void OnyxDisable()
- {
- if (this.m_alphaControl != null)
- {
- this.m_alphaControl.Alpha = 1f;
- }
- GameState.OnLevelLoaded -= new Action<string>(this.GameState_OnLevelLoaded);
- GameState.OnCombatStart.UnsubscribeSafe(new System.Action(this.HandleCombatStart));
- GameState.OnCombatEnd.UnsubscribeSafe(new System.Action(this.HandleCombatEnd));
- if (SingletonBehavior<PartyManager>.Instance == null || !SingletonBehavior<PartyManager>.Instance.IsActivePartyMember(base.get_gameObject()))
- {
- this.KillSummonedCreatures(true);
- }
- this.BehaviorStack.ClearAllBehaviorsIncludingDefaultBehavior();
- if (SingletonBehavior<TacticalModeManager>.Instance != null)
- {
- SingletonBehavior<TacticalModeManager>.Instance.ExitCombat(this);
- }
- base.OnyxDisable();
- }
- protected override void OnyxDestroy()
- {
- if (SingletonBehavior<AIScheduleManager>.Instance)
- {
- SingletonBehavior<AIScheduleManager>.Instance.RemoveSchedule(this, this.m_aiSchedule);
- }
- this.KillSummonedCreatures(true);
- this.BehaviorStack.ClearAllBehaviorsIncludingDefaultBehavior();
- AIController.s_activeControllers.Remove(this);
- this.UnsubscribeComponentEvents();
- base.OnyxDestroy();
- }
- protected void Init()
- {
- this.m_engagedBy.Clear();
- this.m_engagedEnemies.Clear();
- BoxCollider component = base.GetComponent<BoxCollider>();
- if (component != null && this.Mover != null)
- {
- Vector3 size = new Vector3(this.Mover.Radius * 2f, 1.8f, this.Mover.Radius * 2f);
- size.x /= base.get_transform().get_localScale().x;
- size.y /= base.get_transform().get_localScale().y;
- size.z /= base.get_transform().get_localScale().z;
- component.set_size(size);
- Vector3 center = new Vector3(component.get_center().x, size.y / 2f, component.get_center().z);
- component.set_center(center);
- }
- if (Paperdoll.IsObjectPaperdoll(base.get_gameObject()))
- {
- base.get_gameObject().set_layer(LayerMask.NameToLayer("Character"));
- }
- this.RecordRetreatPosition(base.get_transform().get_position());
- if (this.m_faction != null && this.m_partyMember != null)
- {
- this.m_faction.SetToPlayerTeam();
- }
- this.m_hasBeenInitialized = true;
- }
- protected void GameState_OnLevelLoaded(string sceneName)
- {
- if (!GameState.LoadedGame)
- {
- this.TeleportSummonedCreatures(base.get_transform().get_position());
- }
- }
- protected void TeleportSummonedCreatures(Vector3 position)
- {
- for (int i = 0; i < this.m_summonedCreatures.Count; i++)
- {
- GameObject gameObject = this.m_summonedCreatures[i];
- if (gameObject != null)
- {
- Mover component = gameObject.GetComponent<Mover>();
- AIController component2 = gameObject.GetComponent<AIController>();
- Vector3 vector = NavMeshUtility.NearestUnoccupiedLocation(position, 10f, component);
- float num = 2.5f;
- float num2 = Onyx.Math.Distance2DSquared(vector, position);
- if (num2 > num * num)
- {
- vector = position;
- vector.x += 0.1f;
- vector.z += 0.1f;
- }
- gameObject.get_transform().set_position(vector);
- if (component2 != null)
- {
- component2.BehaviorStack.PopAllBehaviors();
- component2.RecordRetreatPosition(gameObject.get_transform().get_position());
- }
- if (component != null)
- {
- component.BroadcastUpdateEvent();
- }
- }
- }
- }
- protected void ReInitializeDefaultBehavior()
- {
- if (this.BehaviorStack != null && this.BehaviorStack.BehaviorCount > 0)
- {
- this.InitDefaultBehavior();
- }
- }
- protected void InitDefaultBehavior()
- {
- this.BehaviorStack.ClearAllBehaviorsIncludingDefaultBehavior();
- AIBehaviorManager.DefaultAIBehaviorType aIBehavior;
- if (this.m_partyMember != null)
- {
- aIBehavior = AIBehaviorManager.DefaultAIBehaviorType.Idle;
- }
- else if (this.IsPet && !this.OverrideSummonBehvaior)
- {
- aIBehavior = AIBehaviorManager.DefaultAIBehaviorType.Pet;
- }
- else if (SummonedCharacter.IsSummonOfType(base.get_gameObject(), AISummonType.AnimalCompanion) && !this.OverrideSummonBehvaior)
- {
- aIBehavior = AIBehaviorManager.DefaultAIBehaviorType.Follow;
- }
- else if (this.m_aiTownieSchedule != null)
- {
- aIBehavior = AIBehaviorManager.DefaultAIBehaviorType.TownieSchedule;
- }
- else if (this.m_shipController != null)
- {
- aIBehavior = AIBehaviorManager.DefaultAIBehaviorType.Idle;
- }
- else
- {
- aIBehavior = this.AIBehavior;
- }
- this.AIBehavior = aIBehavior;
- AIBehavior defaultBehavior = AIBehaviorManager.AllocateAIBehavior(this.AIBehavior);
- this.BehaviorStack.SetDefaultBehavior(defaultBehavior);
- if (this.ScriptedBehavior != ScriptedBehaviorType.None)
- {
- this.SetScriptedBehavior(this.ScriptedBehavior);
- }
- }
- protected AIDecisionTreeSelectionType GetDecisionTreeSelectionType()
- {
- if (this.m_decisionTreeReferences.Length > 0)
- {
- return this.DecisionTreeSelectionOverride;
- }
- if (this.m_characterStats != null)
- {
- return this.m_characterStats.GetDecisionTreeSelectionType();
- }
- return AIDecisionTreeSelectionType.RandomOrder;
- }
- protected AIDecisionTreeData GetDecisionTreeByID(Guid ID)
- {
- for (int i = 0; i < this.DecisionTrees.Count; i++)
- {
- if (this.DecisionTrees[i].get_ID() == ID)
- {
- return this.DecisionTrees[i];
- }
- }
- return null;
- }
- protected void InitCooldowns()
- {
- if (this.m_cooldowns == null)
- {
- this.m_cooldowns = new Dictionary<Guid, ActionCooldown[]>();
- }
- this.m_cooldowns.Clear();
- for (int i = 0; i < this.DecisionTrees.Count; i++)
- {
- AIDecisionTreeData aIDecisionTreeData = this.DecisionTrees[i];
- int num = 0;
- bool flag = aIDecisionTreeData != null;
- if (flag)
- {
- for (int j = 0; j < aIDecisionTreeData.get_Nodes().Count; j++)
- {
- if (aIDecisionTreeData.get_Nodes()[j].get_NodeID() > num)
- {
- num = aIDecisionTreeData.get_Nodes()[j].get_NodeID();
- }
- }
- }
- ActionCooldown[] array = null;
- this.m_cooldowns.TryGetValue(aIDecisionTreeData.get_ID(), out array);
- if (array == null || array.Length != num + 1)
- {
- array = new ActionCooldown[num + 1];
- this.m_cooldowns[aIDecisionTreeData.get_ID()] = array;
- for (int k = 0; k < array.Length; k++)
- {
- array[k] = new ActionCooldown();
- }
- }
- else
- {
- ActionCooldown[] array2 = array;
- for (int l = 0; l < array2.Length; l++)
- {
- ActionCooldown actionCooldown = array2[l];
- actionCooldown.Init(0, 0f);
- }
- }
- if (flag)
- {
- for (int m = 0; m < aIDecisionTreeData.get_Nodes().Count; m++)
- {
- AIActionData aIActionData = aIDecisionTreeData.get_Nodes()[m] as AIActionData;
- if (aIActionData != null)
- {
- AIActionComponent aIActionComponent = aIActionData.Component as AIActionComponent;
- if (aIActionComponent != null)
- {
- array[aIActionData.get_NodeID()].Init(aIActionComponent.MaxUses, aIActionComponent.CooldownTime);
- }
- }
- }
- }
- }
- }
- protected void PreSave()
- {
- this.PersistentScriptedBehavior = this.ScriptedBehavior;
- this.PersistentScriptedUseObjectGuid = InstanceID.GetObjectID(this.ScriptedUseObject);
- }
- protected void PostLoad()
- {
- if (this.ObsoleteSummonType != AISummonType.NotSummoned)
- {
- SummonedCharacter orAddComponent = ResourceManager.GetOrAddComponent<SummonedCharacter>(base.get_gameObject());
- orAddComponent.Summoner = InstanceID.GetObjectByID(this.ObsoleteSummonerGuid);
- orAddComponent.SummonType = this.ObsoleteSummonType;
- this.ObsoleteSummonType = AISummonType.NotSummoned;
- }
- this.ObsoleteSummonerGuid = Guid.Empty;
- this.ScriptedBehavior = this.PersistentScriptedBehavior;
- this.ScriptedUseObject = InstanceID.GetObjectByID(this.PersistentScriptedUseObjectGuid);
- if (this.IsEmerging)
- {
- this.m_unsetEmergeFlags = true;
- }
- }
- protected virtual void UpdateUI()
- {
- HudEngagementManager instance = HudEngagementManager.Instance;
- if (instance != null)
- {
- for (int i = 0; i < this.EngagedEnemies.Count; i++)
- {
- instance.Verify(base.get_gameObject(), this.EngagedEnemies[i].get_gameObject());
- }
- for (int j = 0; j < this.EngagedBy.Count; j++)
- {
- instance.Verify(this.EngagedBy[j].get_gameObject(), base.get_gameObject());
- }
- }
- this.UpdateFading();
- }
- protected void UpdateCombatStance()
- {
- if (this.m_animController != null)
- {
- if (this.GetCurrentBehaviorType() != AIBehaviorType.Standup)
- {
- this.m_animController.InCombat = this.IsInCombat;
- }
- if (this.m_partyMember != null)
- {
- this.m_animController.IsActionQueued = (!this.m_partyMember.IsNearCombatAndNotFighting || TacticalModeManager.IsInTacticalCombat(this));
- }
- else
- {
- this.m_animController.IsActionQueued = true;
- }
- GameObject currentTarget = this.CurrentTarget;
- if (currentTarget != null)
- {
- this.m_animController.TargetDistance = Onyx.Math.Distance2D(base.get_transform().get_position(), currentTarget.get_transform().get_position());
- }
- else
- {
- this.m_animController.TargetDistance = 0f;
- }
- }
- }
- protected bool IsNearCombat()
- {
- if (this.m_partyMember != null)
- {
- return this.m_partyMember.IsNearCombat;
- }
- return this.IsInCombatAgainstParty();
- }
- protected bool IsInCombatAndWaiting()
- {
- if (!this.IsFighting)
- {
- return false;
- }
- if (this.GetCurrentBehaviorType() == AIBehaviorType.PreparingToAct)
- {
- PreparingToActParams preparingToActParams = this.BehaviorStack.CurrentBehavior.AIParams as PreparingToActParams;
- if (preparingToActParams.WaitingToSelectAnAction)
- {
- return true;
- }
- }
- return false;
- }
- protected void SetDecisionTrees(AIDecisionTreeData[] decisionTrees)
- {
- this.m_decisionTrees.Clear();
- if (decisionTrees != null)
- {
- this.m_decisionTrees.AddRange(decisionTrees);
- }
- this.InitCooldowns();
- }
- protected void SetClassDecisionTrees()
- {
- this.m_decisionTrees.Clear();
- foreach (KeyValuePair<CharacterClassGameData, CharacterClassLevelData> current in this.m_characterStats.GetAllClassLevelData())
- {
- CharacterClassGameData key = current.Key;
- if (!DataObject.IsNullOrEmpty(key) && current.Value.HasClass())
- {
- this.m_decisionTrees.Add(key.DefaultDecisionTree.Data);
- }
- }
- this.InitCooldowns();
- }
- protected void AssignPartyMemberBehavior()
- {
- this.BehaviorStack.ClearAllBehaviorsIncludingDefaultBehavior();
- this.BehaviorStack.SetDefaultBehavior(AIBehaviorManager.AllocateIdleBehavior());
- if (this.m_faction != null)
- {
- this.m_faction.SetToPlayerTeam();
- }
- }
- protected AutoAttackSettings GetAutoAttackSettings()
- {
- if (this.m_partyMember != null)
- {
- return this.m_partyMember.AutoAttackSettings;
- }
- return AutoAttackSettings.NPCSettings;
- }
- protected void SetScriptedBehavior(ScriptedBehaviorType scriptedBehavior)
- {
- this.ScriptedBehavior = scriptedBehavior;
- this.BehaviorStack.PopAllBehaviors();
- if (scriptedBehavior != ScriptedBehaviorType.None)
- {
- if (scriptedBehavior != ScriptedBehaviorType.Idle)
- {
- if (scriptedBehavior == ScriptedBehaviorType.UseScriptedObject)
- {
- this.PushUseScriptedObjectBehavior();
- }
- }
- else
- {
- AIBehavior behavior = AIBehaviorManager.AllocateIdleBehavior();
- this.BehaviorStack.PushBehavior(behavior, true);
- }
- }
- }
- protected void SetScriptedUseObject(GameObject useObject)
- {
- this.ScriptedUseObject = useObject;
- if (this.ScriptedBehavior == ScriptedBehaviorType.UseScriptedObject)
- {
- this.BehaviorStack.PopAllBehaviors();
- this.PushUseScriptedObjectBehavior();
- }
- }
- protected void PushUseScriptedObjectBehavior()
- {
- if (this.ScriptedUseObject == null)
- {
- AIBehavior behavior = AIBehaviorManager.AllocateIdleBehavior();
- this.BehaviorStack.PushBehavior(behavior, true);
- return;
- }
- Waypoint component = this.ScriptedUseObject.GetComponent<Waypoint>();
- if (component != null)
- {
- AIBehavior behavior2 = AIBehaviorManager.AllocatePatrolBehavior(component, false);
- this.BehaviorStack.PushBehavior(behavior2, true);
- return;
- }
- Usable component2 = this.ScriptedUseObject.GetComponent<Usable>();
- if (component2 != null)
- {
- AIBehavior behavior3 = AIBehaviorManager.AllocateUseObjectBehavior(component2);
- this.BehaviorStack.PushBehavior(behavior3, true);
- return;
- }
- AIBehavior behavior4 = AIBehaviorManager.AllocateIdleBehavior();
- this.BehaviorStack.PushBehavior(behavior4, true);
- }
- protected void CacheAlphaControl(bool forceUpdate)
- {
- bool flag = this.m_alphaControl != null;
- if (!flag)
- {
- this.m_alphaControl = ResourceManager.GetOrAddComponent<AlphaControl>(base.get_gameObject());
- }
- if (!flag || forceUpdate)
- {
- this.m_isFogVisible = FogOfWar.IsFullyVisible(base.get_transform().get_position());
- if (this.m_isFogVisible)
- {
- this.m_alphaControl.FadeTo(1f, 0f, AlphaControl.FadeType.FogOfWar);
- }
- else
- {
- this.m_alphaControl.FadeTo(0f, 0f, AlphaControl.FadeType.FogOfWar);
- }
- }
- }
- protected void UpdateFading()
- {
- AIBehavior currentBehavior = this.BehaviorStack.CurrentBehavior;
- float num = 1f;
- if (this.SummonedCharacter != null)
- {
- AIController component = ComponentUtils.GetComponent<AIController>(this.SummonedCharacter.Summoner);
- if (component != null)
- {
- currentBehavior = component.BehaviorStack.CurrentBehavior;
- }
- }
- AIState aIState = null;
- if (currentBehavior != null)
- {
- aIState = currentBehavior.CurrentState;
- if (aIState != null)
- {
- num = aIState.GetDesiredAlpha();
- }
- }
- bool flag = FogOfWar.IsFullyVisible(base.get_transform().get_position());
- this.CacheAlphaControl(false);
- if (flag != this.m_isFogVisible)
- {
- this.m_isFogVisible = flag;
- if (flag)
- {
- this.m_alphaControl.FadeIn(0.5f, AlphaControl.FadeType.FogOfWar);
- }
- else
- {
- this.m_alphaControl.FadeOut(0.5f, AlphaControl.FadeType.FogOfWar);
- }
- }
- if (this.m_desiredAlpha != num)
- {
- this.m_desiredAlpha = num;
- if (aIState != null)
- {
- Waypoint currentWaypoint = aIState.GetCurrentWaypoint();
- if (currentWaypoint != null && currentWaypoint.InteractionType == Waypoint.WaypointInteractionType.FadeOut)
- {
- this.m_alphaControl.OnFadeOut = currentWaypoint.OnFadeOut;
- }
- }
- this.m_alphaControl.FadeTo(this.m_desiredAlpha, 0.5f, AlphaControl.FadeType.AI);
- }
- }
- protected void FaceDirection(Vector3 newFacing)
- {
- float num = Time.get_deltaTime();
- if (GameState.Paused)
- {
- num = Time.get_unscaledDeltaTime();
- }
- else if (num < 1.401298E-45f)
- {
- return;
- }
- Vector2 heading = Onyx.Math.ToVector2(newFacing);
- heading.Normalize();
- Vector2 a = this.m_mover.SteerTowardsHeading(heading, true, num);
- if (a.get_sqrMagnitude() > 1.401298E-45f)
- {
- base.get_transform().set_rotation(Quaternion.LookRotation(Onyx.Math.ToVector3(a)));
- }
- }
- protected void FaceTarget(GameObject target)
- {
- if (target != null)
- {
- Vector3 newFacing = target.get_transform().get_position() - base.get_transform().get_position();
- this.FaceDirection(newFacing);
- }
- }
- protected void FaceTarget(Vector3 targetPosition)
- {
- Vector3 newFacing = targetPosition - base.get_transform().get_position();
- this.FaceDirection(newFacing);
- }
- protected void FaceTarget(AttackBase attack)
- {
- if (attack != null && !attack.AttackData.FaceTarget)
- {
- return;
- }
- GameObject currentTarget = this.CurrentTarget;
- if (currentTarget == base.get_gameObject())
- {
- return;
- }
- if (this.m_characterStats != null && this.m_characterStats.StatusEffectManager.HasStatusEffectByType(StatusEffectType.Paralyzed))
- {
- return;
- }
- Vector3 vector = Vector3.get_zero();
- if (currentTarget == null)
- {
- AIBehaviorType currentBehaviorType = this.GetCurrentBehaviorType();
- if (currentBehaviorType != AIBehaviorType.Cast)
- {
- return;
- }
- vector = this.BehaviorStack.CurrentBehavior.AIParams.GetPosition();
- }
- else
- {
- vector = currentTarget.get_transform().get_position();
- }
- Vector3 newFacing = vector - base.get_transform().get_position();
- newFacing.Normalize();
- this.FaceDirection(newFacing);
- }
- protected bool IsFacingTarget(Vector3 targetPosition)
- {
- Vector3 vector = targetPosition - base.get_transform().get_position();
- vector.y = 0f;
- if (vector.get_sqrMagnitude() < 1.401298E-45f)
- {
- vector = base.get_transform().get_forward();
- }
- vector.Normalize();
- float num = Vector3.Dot(base.get_transform().get_forward(), vector);
- return num > 0.9659f;
- }
- protected void AddChildSummon(GameObject summon)
- {
- if (!this.m_summonedCreatures.Contains(summon))
- {
- this.m_summonedCreatures.Add(summon);
- if (this.OnSummonsChanged != null)
- {
- this.OnSummonsChanged(base.get_gameObject(), EventArgs.Empty);
- }
- }
- }
- protected bool RemoveChildSummon(GameObject summon)
- {
- if (this.m_summonedCreatures.Remove(summon))
- {
- if (this.OnSummonsChanged != null)
- {
- this.OnSummonsChanged(base.get_gameObject(), EventArgs.Empty);
- }
- return true;
- }
- return false;
- }
- protected void ClearChildSummons()
- {
- this.m_summonedCreatures.Clear();
- if (this.OnSummonsChanged != null)
- {
- this.OnSummonsChanged(base.get_gameObject(), EventArgs.Empty);
- }
- }
- protected void KillSummonedCreatures(bool removeAll = false)
- {
- for (int i = this.m_summonedCreatures.Count - 1; i >= 0; i--)
- {
- GameObject gameObject = this.m_summonedCreatures[i];
- if (gameObject != null)
- {
- Health component = gameObject.GetComponent<Health>();
- bool flag = false;
- if (SummonedCharacter.IsSummonOfType(gameObject, AISummonType.AnimalCompanion) && ((component && component.Lifetime > 0f) || removeAll))
- {
- AnimalCompanionManager component2 = base.GetComponent<AnimalCompanionManager>();
- if (component2)
- {
- component2.RemoveAnimalCompanion(gameObject);
- }
- else
- {
- this.m_summonedCreatures.RemoveAt(i);
- }
- flag = true;
- }
- else if (SummonedCharacter.IsSummonOfType(gameObject, AISummonType.Summoned))
- {
- this.m_summonedCreatures.RemoveAt(i);
- flag = true;
- }
- if (flag)
- {
- if (component != null)
- {
- if (this.m_health.WillGib && SummonedCharacter.IsSummonOfType(gameObject, AISummonType.AnimalCompanion) && component.Lifetime == 0f)
- {
- component.Kill(null, null, false);
- }
- else
- {
- component.Unsummon();
- }
- }
- else
- {
- SingletonBehavior<CharacterObjectManager>.Instance.DestroyCharacter(base.get_gameObject(), 0f);
- }
- }
- }
- }
- if (this.OnSummonsChanged != null)
- {
- this.OnSummonsChanged(base.get_gameObject(), EventArgs.Empty);
- }
- }
- protected void RemovePet()
- {
- for (int i = this.m_summonedCreatures.Count - 1; i >= 0; i--)
- {
- GameObject gameObject = this.m_summonedCreatures[i];
- AIController component = ComponentUtils.GetComponent<AIController>(gameObject);
- if (component != null && component.IsPet)
- {
- ResourceManager.DestroyGameObject(gameObject);
- }
- }
- if (this.OnSummonsChanged != null)
- {
- this.OnSummonsChanged(base.get_gameObject(), EventArgs.Empty);
- }
- }
- protected GameObject GetFollowObject()
- {
- GameObject gameObject = SummonedCharacter.FindSummoner(base.get_gameObject());
- if (gameObject == null)
- {
- gameObject = this.FollowObject;
- }
- return gameObject;
- }
- protected bool IsPathingObstacle()
- {
- if (this.m_health != null && this.m_health.IsDeadOrUnconscious)
- {
- return false;
- }
- if (this.m_desiredAlpha < 1.401298E-45f)
- {
- return false;
- }
- if (this.IgnoreAsCutsceneObstacle)
- {
- return false;
- }
- if (this.IsPet)
- {
- return false;
- }
- AIBehavior currentBehavior = this.BehaviorStack.CurrentBehavior;
- if (currentBehavior != null)
- {
- AIState currentState = currentBehavior.CurrentState;
- if (currentState != null && !currentState.BlockPathing)
- {
- return false;
- }
- }
- return true;
- }
- protected bool IsInMovingState()
- {
- AIBehavior currentBehavior = this.BehaviorStack.CurrentBehavior;
- return currentBehavior != null && currentBehavior.CurrentState != null && currentBehavior.CurrentState.IsMoving;
- }
- protected bool IsWaitingToMove()
- {
- AIBehavior currentBehavior = this.BehaviorStack.CurrentBehavior;
- return currentBehavior != null && currentBehavior.AIParams.IsWaitingToMove;
- }
- protected bool IsPathBlocked()
- {
- return this.GetCurrentBehaviorType() == AIBehaviorType.WaitForClearPath;
- }
- protected bool IsPathBlockedBy(Mover obstacle)
- {
- AIBehavior currentBehavior = this.BehaviorStack.CurrentBehavior;
- if (currentBehavior != null)
- {
- AIParams aIParams = currentBehavior.AIParams;
- if (aIParams != null)
- {
- WaitForClearPathParams waitForClearPathParams = aIParams as WaitForClearPathParams;
- if (waitForClearPathParams != null)
- {
- return waitForClearPathParams.Blocker == obstacle || (waitForClearPathParams.Obstacles != null && waitForClearPathParams.Obstacles.Contains(obstacle));
- }
- }
- }
- return false;
- }
- protected bool IsPathBlockedByObstacles()
- {
- AIBehavior currentBehavior = this.BehaviorStack.CurrentBehavior;
- if (currentBehavior != null)
- {
- AIParams aIParams = currentBehavior.AIParams;
- if (aIParams != null)
- {
- WaitForClearPathParams waitForClearPathParams = aIParams as WaitForClearPathParams;
- if (waitForClearPathParams != null)
- {
- return waitForClearPathParams.Obstacles.Count > 0;
- }
- }
- }
- return false;
- }
- protected void OnAddStatusEffect(StatusEffectManager sender, StatusEffectInstance instance)
- {
- StatusEffectType statusEffectType = instance.GameData.StatusEffectType;
- if (statusEffectType != StatusEffectType.KnockedDown)
- {
- if (statusEffectType != StatusEffectType.Paralyzed)
- {
- if (statusEffectType != StatusEffectType.Stunned)
- {
- if (statusEffectType != StatusEffectType.Terrified)
- {
- if (statusEffectType == StatusEffectType.VerticalLaunch)
- {
- AIBehavior behavior = this.GetBehavior(AIBehaviorType.Launched);
- if (behavior != null)
- {
- StatusEffectInstanceParams statusEffectInstanceParams = behavior.AIParams as StatusEffectInstanceParams;
- statusEffectInstanceParams.AddStatusEffect(instance);
- }
- else
- {
- this.CancelGrappleBehavior();
- this.PopAllBehaviorsOfType(AIBehaviorType.Standup);
- this.PopAllBehaviorsOfType(AIBehaviorType.HitReact);
- AIBehavior behavior2 = AIBehaviorManager.AllocateLaunchedBehavior(instance);
- this.BehaviorStack.PushBehavior(behavior2);
- }
- }
- }
- else
- {
- AIBehavior behavior3 = this.GetBehavior(AIBehaviorType.Terrified);
- if (behavior3 != null)
- {
- StatusEffectInstanceParams statusEffectInstanceParams2 = behavior3.AIParams as StatusEffectInstanceParams;
- statusEffectInstanceParams2.AddStatusEffect(instance);
- }
- else
- {
- this.CancelGrappleBehavior();
- AIBehavior behavior4 = AIBehaviorManager.AllocateTerrifiedBehavior(instance, base.get_gameObject());
- this.BehaviorStack.PushBehavior(behavior4);
- }
- }
- }
- else
- {
- AIBehavior behavior5 = this.GetBehavior(AIBehaviorType.Stunned);
- if (behavior5 != null)
- {
- StatusEffectInstanceParams statusEffectInstanceParams3 = behavior5.AIParams as StatusEffectInstanceParams;
- statusEffectInstanceParams3.AddStatusEffect(instance);
- }
- else
- {
- this.CancelAndLoseCurrentAction(false);
- AIBehavior behavior6 = AIBehaviorManager.AllocateStunnedBehavior(instance);
- this.BehaviorStack.PushBehavior(behavior6);
- }
- }
- }
- else
- {
- AIBehavior behavior7 = this.GetBehavior(AIBehaviorType.Paralyzed);
- if (behavior7 != null)
- {
- StatusEffectInstanceParams statusEffectInstanceParams4 = behavior7.AIParams as StatusEffectInstanceParams;
- statusEffectInstanceParams4.AddStatusEffect(instance);
- }
- else
- {
- this.CancelGrappleBehavior();
- AIBehavior behavior8 = AIBehaviorManager.AllocateParalyzedBehavior(instance);
- this.BehaviorStack.PushBehavior(behavior8);
- }
- }
- }
- else
- {
- AIBehavior behavior9 = this.GetBehavior(AIBehaviorType.KnockedDown);
- if (behavior9 != null)
- {
- StatusEffectInstanceParams statusEffectInstanceParams5 = behavior9.AIParams as StatusEffectInstanceParams;
- statusEffectInstanceParams5.AddStatusEffect(instance);
- }
- else
- {
- this.CancelGrappleBehavior();
- this.PopAllBehaviorsOfType(AIBehaviorType.Standup);
- this.PopAllBehaviorsOfType(AIBehaviorType.HitReact);
- AIBehavior behavior10 = AIBehaviorManager.AllocateKnockedDownBehavior(instance);
- if (this.GetCurrentBehaviorType() == AIBehaviorType.PushedBack)
- {
- this.BehaviorStack.QueueBehaviorAtTop(behavior10);
- }
- else
- {
- this.BehaviorStack.PushBehavior(behavior10);
- }
- }
- }
- }
- protected void ReactToWeather(AIController.WeatherReactionType weatherReactionType)
- {
- float num = 0f;
- float num2 = 0f;
- if (weatherReactionType != AIController.WeatherReactionType.SeekCover)
- {
- if (weatherReactionType == AIController.WeatherReactionType.LeaveCover)
- {
- num = GlobalGameSettingsGameData.Instance.AISettings.LeaveCoverMinDelay;
- num2 = GlobalGameSettingsGameData.Instance.AISettings.LeaveCoverMaxDelay;
- }
- }
- else
- {
- num = GlobalGameSettingsGameData.Instance.AISettings.SeekCoverMinDelay;
- num2 = GlobalGameSettingsGameData.Instance.AISettings.SeekCoverMaxDelay;
- }
- this.m_shouldReactToWeatherAfterDelay = true;
- this.m_weatherReactionType = weatherReactionType;
- this.m_weatherReactionDelay = Random.Range(num, num2);
- this.m_weatherReactionTimer = 0f;
- }
- protected void UpdateWeatherReaction()
- {
- if (this.m_shouldReactToWeatherAfterDelay)
- {
- this.m_weatherReactionTimer += Time.get_deltaTime();
- if (this.m_weatherReactionTimer >= this.m_weatherReactionDelay)
- {
- if ((this.m_weatherReactionType == AIController.WeatherReactionType.SeekCover && SingletonBehavior<WeatherManager>.Instance.IsCurrentConditionTreacherous) || (this.m_weatherReactionType == AIController.WeatherReactionType.LeaveCover && !SingletonBehavior<WeatherManager>.Instance.IsCurrentConditionTreacherous))
- {
- if (this.AITownieSchedule != null)
- {
- this.AITownieSchedule.ReactToWeather(this.m_weatherReactionType);
- }
- else
- {
- this.AISchedule.ReactToWeather(this.m_weatherReactionType);
- }
- }
- this.m_shouldReactToWeatherAfterDelay = false;
- this.m_weatherReactionType = AIController.WeatherReactionType.None;
- }
- }
- }
- protected void NotifyRequestHelp(GameObject shouter, GameObject enemy, GameObject caller, GameObject origin, float radius, bool isTownieShout, bool shouterDied, Vector3 lastSeenEnemyPosition)
- {
- if (this.BehaviorStack == null)
- {
- return;
- }
- if ((this.m_faction != null && this.m_faction.IsDominated) || this.IsPet || shouter == base.get_gameObject())
- {
- return;
- }
- if (!base.get_gameObject().get_activeInHierarchy() || (this.m_health != null && this.m_health.IsDeadOrUnconscious))
- {
- return;
- }
- Faction component = shouter.GetComponent<Faction>();
- Faction component2 = enemy.GetComponent<Faction>();
- if (SingletonBehavior<PartyManager>.Instance.IsActivePartyMember(base.get_gameObject()))
- {
- if (!this.IsFighting && !this.m_holdMove && !Stealth.IsInStealthMode(base.get_gameObject(), false) && (this.m_partyMember.AutoAttackSettings.AutoAttackType == AutoAttackType.Defensive || this.m_partyMember.AutoAttackSettings.AutoAttackType == AutoAttackType.Aggressive))
- {
- AIBehavior behavior = AIBehaviorManager.AllocatePreparingToActBehaviorWithHelpRequest(shouter, false);
- this.BehaviorStack.PushBehavior(behavior, true);
- }
- return;
- }
- if (!isTownieShout)
- {
- lastSeenEnemyPosition = Vector3.get_zero();
- }
- if (this.m_faction != null && !this.m_faction.IsFriendly(component))
- {
- return;
- }
- if (NavMeshUtility.GetPathingDistance(this.m_mover, this.m_mover.get_transform().get_position(), caller.get_transform().get_position(), false) > radius * GlobalGameSettingsGameData.Instance.RequestHelpShoutRangePathingScalar)
- {
- return;
- }
- if (shouterDied)
- {
- this.ExecuteOnFriendlyDeathAlert();
- }
- if (!this.IsTownie)
- {
- SingletonBehavior<TacticalModeManager>.Instance.EnterCombat(this);
- }
- if (this.CurrentTarget != null)
- {
- this.m_hasShoutedForHelp = true;
- AIController.ShoutToAllies(shouter, enemy, base.get_gameObject(), origin, this.ShoutRange, isTownieShout, false, lastSeenEnemyPosition);
- return;
- }
- if (this.GetCurrentBehaviorType() == AIBehaviorType.WaitForClearPath)
- {
- if (this.m_mover.IsBlockedBy(Mover.BlockFlag.Cluster))
- {
- return;
- }
- this.BehaviorStack.PopCurrentBehavior();
- }
- if (this.m_faction != null && this.IsTownie)
- {
- if (!this.m_townie.IsReacting)
- {
- if (!isTownieShout)
- {
- this.m_townie.ScanForNearbyCombat();
- if (!this.m_townie.IsReacting)
- {
- this.m_townie.BeginCombatReaction(enemy, enemy.get_transform().get_position());
- }
- }
- if (isTownieShout)
- {
- this.m_townie.BeginCombatReaction(enemy, lastSeenEnemyPosition);
- }
- this.ExecuteOnShoutAlert();
- }
- }
- else if (!this.IsInCombat)
- {
- if (!isTownieShout && component2 != null)
- {
- if (component2.IsInPlayerFaction)
- {
- this.m_faction.SetRelationshipToPlayer(Relationship.Hostile);
- }
- this.m_delayedCombatParams.SetTarget(component, AIBehaviorManager.PreparingToActType.HelpRequest);
- }
- if (isTownieShout && this.GetCurrentBehaviorType() != AIBehaviorType.Investigate)
- {
- AIBehavior behavior2 = AIBehaviorManager.AllocateInvestigateBehavior(lastSeenEnemyPosition, base.get_transform().get_position(), MovementType.Run, MovementType.Walk, 2f, true);
- this.BehaviorStack.PushBehavior(behavior2);
- this.ExecuteOnShoutAlert();
- }
- }
- this.m_hasShoutedForHelp = true;
- if (isTownieShout)
- {
- AIController.ShoutToAllies(shouter, enemy, base.get_gameObject(), origin, this.ShoutRange, isTownieShout, false, lastSeenEnemyPosition);
- }
- else
- {
- AIController.ShoutToAllies(shouter, enemy, base.get_gameObject(), origin, this.ShoutRange, isTownieShout, false, Vector3.get_zero());
- }
- }
- protected void NotifyAttacked(GameObject attacker, DamageInfo damageInfo, float amount)
- {
- Faction component = base.GetComponent<Faction>();
- Faction component2 = ComponentUtils.GetComponent<Faction>(attacker);
- if (this.IsPet || component.Health == null || component.Health.IsDeadOrUnconscious)
- {
- return;
- }
- this.UpdateMustDieForCombatToEnd();
- this.m_hasShoutedForHelp = true;
- if (component2 != null && component2.IsInPlayerFaction)
- {
- this.m_faction.NotifyAttackWitnessed();
- }
- Trap componentUnlikely = attacker.GetComponentUnlikely<Trap>();
- if (componentUnlikely != null)
- {
- return;
- }
- this.TrackDamage(attacker, amount);
- if (this.m_highestDamageInflictor == null || amount > this.m_highestDamageInflicted)
- {
- this.m_highestDamageInflictor = attacker;
- this.m_highestDamageInflicted = amount;
- }
- if (component2 != null && !component.CurrentTeam.IsEmpty() && !component.IsDominated && component2.CurrentTeam != component.CurrentTeam)
- {
- this.ShoutToAllies(attacker, this.ShoutRange, false, false, Vector3.get_zero());
- }
- if (this.m_townie != null && this.GetCurrentBehaviorType() == AIBehaviorType.Flee)
- {
- CowerParams cowerParams = this.BehaviorStack.CurrentBehavior.AIParams as CowerParams;
- if (cowerParams != null)
- {
- cowerParams.ResetInCombatTimer();
- }
- }
- AttackBase attackBase = null;
- if (damageInfo != null)
- {
- attackBase = damageInfo.Attack;
- }
- if (attacker != null && component != null)
- {
- if (this.m_partyMember != null)
- {
- if (component.IsHostile(attacker))
- {
- if (!this.IsFighting && !this.m_holdMove && this.m_partyMember.AutoAttackSettings.AutoAttackType != AutoAttackType.Passive && attackBase != null && !attackBase.IsDisengagementAttack)
- {
- AIBehavior behavior = AIBehaviorManager.AllocatePreparingToActBehaviorWithPreferredTarget(component2, false);
- this.BehaviorStack.PushBehavior(behavior, true);
- }
- return;
- }
- }
- else if (!component.IsHostile(attacker) && component2 != null)
- {
- if (component.IsInPlayerFaction && component2.IsInPlayerFaction)
- {
- return;
- }
- if (component2.CurrentTeam != component.CurrentTeam)
- {
- if (component2.IsInPlayerFaction && !component2.IsDominated)
- {
- component.SetRelationshipToPlayer(Relationship.Hostile);
- }
- else if (component.IsInPlayerFaction && !component.IsDominated)
- {
- component2.SetRelationshipToPlayer(Relationship.Hostile);
- }
- }
- }
- if (this.m_partyMember == null && !this.IsInCombat)
- {
- if (component.CurrentTeam.TeamType == TeamType.Townie)
- {
- AIBehavior behavior2 = AIBehaviorManager.AllocateCowerBehavior();
- this.BehaviorStack.PushBehavior(behavior2, true);
- }
- else
- {
- AIBehavior behavior3 = AIBehaviorManager.AllocatePreparingToActBehaviorWithPreferredTarget(component2, component2.IsInPlayerFaction);
- this.BehaviorStack.PushBehavior(behavior3, true);
- }
- }
- }
- }
- protected void NotifyHitReact(HitReactType interruptType)
- {
- AIBehaviorType currentBehaviorType = this.GetCurrentBehaviorType();
- if (currentBehaviorType != AIBehaviorType.Flee)
- {
- if (interruptType == HitReactType.Prone)
- {
- AIBehavior behavior = this.GetBehavior(AIBehaviorType.KnockedDown);
- if (behavior != null)
- {
- TimerParams timerParams = behavior.AIParams as TimerParams;
- timerParams.Duration += GlobalGameSettingsGameData.Instance.KnockDownDuration;
- return;
- }
- this.PopAllBehaviorsOfType(AIBehaviorType.Standup);
- }
- else if (interruptType == HitReactType.Normal && currentBehaviorType == AIBehaviorType.HitReact)
- {
- return;
- }
- AIBehavior behavior2 = AIBehaviorManager.AllocateHitReactBehavior(interruptType);
- this.BehaviorStack.PushBehavior(behavior2);
- }
- }
- protected void NotifyMeleeEngaged(AIController engager)
- {
- if (this.m_mover.IsMoving && this.CurrentTarget != engager.get_gameObject() && this.m_partyMember != null && !GameState.Option.GetOption(GameOption.BoolOption.DISABLE_PARTY_MOVEMENT_STOP_ON_ENGAGEMENT))
- {
- if (this.GetAutoAttackSettings().AutoAttackType == AutoAttackType.Passive)
- {
- if (this.GetCurrentBehaviorType() != AIBehaviorType.WaitForEngagementToEnd)
- {
- AIBehavior behavior = AIBehaviorManager.AllocateWaitForEngagementToEndBehavior();
- this.BehaviorStack.PushBehavior(behavior, true);
- }
- }
- else if (!this.IsFighting)
- {
- AIBehavior behavior2 = AIBehaviorManager.AllocatePreparingToActBehaviorWithPreferredTarget(engager.Faction, false);
- this.BehaviorStack.PushBehavior(behavior2, true);
- }
- }
- }
- protected void NotifyNoiseLevel(Vector3 noiseLocation, NoiseLevelGameData noiseLevel)
- {
- if (!this.IsInCombat)
- {
- AIBehaviorType currentBehaviorType = this.GetCurrentBehaviorType();
- Vector3 originalPosition = base.get_transform().get_position();
- if (currentBehaviorType == AIBehaviorType.Investigate && this.BehaviorStack.CurrentBehavior != null)
- {
- InvestigateParams investigateParams = this.BehaviorStack.CurrentBehavior.AIParams as InvestigateParams;
- Vector3 investigatePosition = investigateParams.InvestigatePosition;
- float num = Onyx.Math.Distance2DSquared(noiseLocation, investigatePosition);
- if (num <= 10f)
- {
- return;
- }
- originalPosition = investigateParams.OriginalPosition;
- this.BehaviorStack.PopCurrentBehavior();
- }
- if (currentBehaviorType != AIBehaviorType.PreparingToAct && this.m_townie == null)
- {
- AIBehavior behavior = AIBehaviorManager.AllocateInvestigateBehavior(noiseLocation, originalPosition, MovementType.Walk, MovementType.Walk, 2f, false);
- this.BehaviorStack.PushBehavior(behavior);
- SingletonBehavior<ChatterManager>.Instance.StartNPCReactiveBarkChatter(ChatterEventType.Investigate, base.get_gameObject());
- }
- }
- }
- protected void OnHealthRevived(GameObject self, CombatEventArgs args)
- {
- if (this.Mover != null)
- {
- this.Mover.get_transform().set_position(NavMeshUtility.NearestUnoccupiedLocation(this.Mover.get_transform().get_position(), 10f, this.Mover));
- }
- this.PopAllBehaviorsOfType(AIBehaviorType.Dead);
- this.PopAllBehaviorsOfType(AIBehaviorType.Unconscious);
- AIBehavior behavior = AIBehaviorManager.AllocateStandupBehavior();
- this.BehaviorStack.PushBehavior(behavior);
- }
- protected void OnHealthUnconscious(GameObject self, CombatEventArgs args)
- {
- if (this.Health.IsUnconscious)
- {
- AIBehavior behavior = AIBehaviorManager.AllocateUnconsciousBehavior();
- this.BehaviorStack.PushBehavior(behavior, true);
- }
- }
- protected void OnHealthDeath(GameObject self, CombatEventArgs args)
- {
- AIBehavior behavior = AIBehaviorManager.AllocateDeadBehavior();
- this.BehaviorStack.PushBehavior(behavior, true);
- Faction component = base.GetComponent<Faction>();
- Faction component2 = ComponentUtils.GetComponent<Faction>(args.Attacker);
- if (component2 != null && component != null && !component.CurrentTeam.IsEmpty() && component2.CurrentTeam != component.CurrentTeam)
- {
- this.ShoutToAllies(args.Attacker, this.ShoutRange, false, true, Vector3.get_zero());
- }
- }
- protected void OnFactionChanged(GameObject sender, TeamGameData newTeam)
- {
- for (int i = 0; i < this.BehaviorStack.BehaviorCount; i++)
- {
- PreparingToActParams preparingToActParams = this.BehaviorStack.GetBehavior(i).AIParams as PreparingToActParams;
- if (preparingToActParams != null)
- {
- Game.AI.Action currentAction = preparingToActParams.CurrentAction;
- if (currentAction is BaseAttackAction || currentAction is CastAction)
- {
- currentAction.Invalidate();
- }
- }
- }
- }
- protected void UpdateAutoAttackOfSummonedCreatures(bool includeCompanion)
- {
- for (int i = 0; i < this.m_summonedCreatures.Count; i++)
- {
- SummonedCharacter component = ComponentUtils.GetComponent<SummonedCharacter>(this.m_summonedCreatures[i]);
- if (component != null && component.SummonType != AISummonType.Pet && (component.SummonType != AISummonType.AnimalCompanion || includeCompanion))
- {
- PartyMember component2 = component.GetComponent<PartyMember>();
- if (this.m_partyMember != null && component2 != null && component.SummonType != AISummonType.AnimalCompanion)
- {
- component2.AutoAttackSettings.Copy(this.m_partyMember.AutoAttackSettings);
- }
- }
- }
- }
- protected static void TriggerNoiseReaction(GameObject source, Vector3 noiseLocation, NoiseLevelGameData noiseLevel, bool hostilesOnly = true)
- {
- if (GameState.IsCutsceneOrConversationRunning())
- {
- return;
- }
- if (!SingletonBehavior<PartyManager>.Instance.IsActivePartyMember(source))
- {
- return;
- }
- float radius = noiseLevel.Radius;
- Faction component = ComponentUtils.GetComponent<Faction>(source);
- RangeManager instance = SingletonBehavior<RangeManager>.Instance;
- RangeManager.Data factionRange = instance.GetFactionRange(noiseLocation.x, radius + instance.LargestHearingDistance);
- for (int i = factionRange.m_start; i < factionRange.m_end; i++)
- {
- Faction faction = instance.GetFaction(i);
- if (!(faction == null))
- {
- AIController aIController = faction.AIController;
- if (!(aIController == null))
- {
- if (!(faction.Health != null) || !faction.Health.IsDeadOrUnconscious)
- {
- float num = Onyx.Math.Distance2DSquared(noiseLocation, faction.get_transform().get_position());
- float stealthedCharacterHearingDistance = aIController.StealthedCharacterHearingDistance;
- float num2 = stealthedCharacterHearingDistance + radius;
- if (num <= num2 * num2)
- {
- if (!SingletonBehavior<PartyManager>.Instance.IsActivePartyMember(faction.get_gameObject()))
- {
- if (!hostilesOnly || faction.GetRelationship(component) == Relationship.Hostile || aIController.IsGuard)
- {
- aIController.NotifyNoiseLevel(noiseLocation, noiseLevel);
- }
- }
- }
- }
- }
- }
- }
- }
- protected void RequestConversationAnimation(FlowChartPlayer conversation, int variation)
- {
- if (conversation == null)
- {
- return;
- }
- if (this.GetCurrentBehaviorType() != AIBehaviorType.WaitForDialogueToEnd && this.ShouldConversationInterruptBehavior())
- {
- AIBehavior behavior = AIBehaviorManager.AllocateWaitForDialogueToEndBehavior(null, conversation, false, variation);
- this.BehaviorStack.PushBehavior(behavior);
- }
- this.OnConversationAnimation.Trigger(variation);
- }
- protected bool CanFaceUserForConversation()
- {
- if (this.m_animController && this.m_animController.IsPlayingAmbient())
- {
- AIBehavior currentBehaviorOrSubBehavior = this.GetCurrentBehaviorOrSubBehavior();
- if (currentBehaviorOrSubBehavior != null)
- {
- GameObject targetObject = currentBehaviorOrSubBehavior.AIParams.GetTargetObject();
- if (targetObject)
- {
- Waypoint component = targetObject.GetComponent<Waypoint>();
- if (component)
- {
- return component.ShouldFaceUserForConversation;
- }
- }
- }
- }
- return true;
- }
- protected bool ShouldConversationInterruptBehavior()
- {
- if (this.m_animController && this.m_animController.IsPlayingAmbient())
- {
- AIBehavior currentBehaviorOrSubBehavior = this.GetCurrentBehaviorOrSubBehavior();
- if (currentBehaviorOrSubBehavior != null)
- {
- GameObject targetObject = currentBehaviorOrSubBehavior.AIParams.GetTargetObject();
- if (targetObject)
- {
- Waypoint component = targetObject.GetComponent<Waypoint>();
- if (component)
- {
- return !component.ShouldMaintainAmbientForConversation;
- }
- }
- }
- }
- return true;
- }
- protected void PauseStateForConversation(FlowChartPlayer conversation, GameObject objectToFace)
- {
- this.OnConversationPauseState.Trigger(conversation, objectToFace);
- }
- protected void ShoutToAllies(GameObject enemy, float radius, bool isTownie, bool shouterDied, Vector3 lastSeenEnemyPosition)
- {
- AIController.ShoutToAllies(base.get_gameObject(), enemy, base.get_gameObject(), base.get_gameObject(), radius, isTownie, shouterDied, lastSeenEnemyPosition);
- }
- protected static void ShoutToAllies(GameObject shouter, GameObject enemy, GameObject caller, GameObject origin, float radius, bool isTownie, bool shouterDied, Vector3 lastSeenEnemyPosition)
- {
- Faction component = caller.GetComponent<Faction>();
- float num = radius * radius;
- RangeManager instance = SingletonBehavior<RangeManager>.Instance;
- RangeManager.Data factionRange = instance.GetFactionRange(caller.get_transform().get_position().x, radius);
- for (int i = factionRange.m_start; i < factionRange.m_end; i++)
- {
- Faction faction = instance.GetFaction(i);
- if (!(faction == null) && !(faction.get_gameObject() == caller))
- {
- float num2 = Onyx.Math.Distance2DSquared(caller.get_transform().get_position(), faction.get_transform().get_position());
- if (num2 <= num)
- {
- AIController aIController = faction.AIController;
- if (aIController != null && !aIController.m_hasShoutedForHelp && faction.GetRelationship(component) == Relationship.Friendly)
- {
- aIController.NotifyRequestHelp(shouter, enemy, caller, origin, radius, isTownie, shouterDied, lastSeenEnemyPosition);
- }
- }
- }
- }
- if (AIController.DebuggingMode == AIController.DebugMode.Shout)
- {
- AIController component2 = caller.GetComponent<AIController>();
- if (component2 != null)
- {
- component2.m_debugShoutTimer = 3f;
- component2.m_debugShoutOrigin = (caller == shouter);
- }
- }
- }
- protected float GetDesiredAttackArrivalDistance(GameObject target)
- {
- AttackBase desiredAttack = this.GetDesiredAttack(target);
- if (desiredAttack == null)
- {
- return 0.1f;
- }
- AIController component = ComponentUtils.GetComponent<AIController>(target);
- if (component != null)
- {
- return this.GetAttackArrivalDistance(desiredAttack, component, false);
- }
- return 0.1f;
- }
- protected float GetAttackArrivalDistance(AttackBase attack, AIController targetAIController, bool isForced)
- {
- if (attack == null)
- {
- return 0.1f;
- }
- if (attack.TargetDirectionOnly && isForced)
- {
- return 10000f;
- }
- float num = attack.TotalAttackDistance;
- if (this.m_mover != null && attack is AttackMelee)
- {
- num += this.m_mover.Radius;
- }
- if (targetAIController != null && targetAIController.m_mover != null)
- {
- num += targetAIController.m_mover.Radius;
- }
- return num;
- }
- protected float GetAttackArrivalDistance(AttackBase attack, Destructible targetDestructible)
- {
- if (attack == null)
- {
- return 0.1f;
- }
- float num = attack.TotalAttackDistance;
- if (this.m_mover != null && attack is AttackMelee)
- {
- num += this.m_mover.Radius;
- }
- if (targetDestructible)
- {
- num += targetDestructible.Radius;
- }
- return num;
- }
- protected AttackBase GetPrimaryAttack()
- {
- if (this.m_equipment == null)
- {
- return null;
- }
- if (this.m_equipment != null)
- {
- AttackBase primaryAttack = this.m_equipment.PrimaryAttack;
- if (primaryAttack != null)
- {
- return primaryAttack;
- }
- AttackBase secondaryAttack = this.m_equipment.SecondaryAttack;
- if (secondaryAttack != null)
- {
- return secondaryAttack;
- }
- EquipmentSet currentItems = this.m_equipment.CurrentItems;
- if (currentItems != null)
- {
- for (int i = 0; i < currentItems.WeaponSets.Length; i++)
- {
- WeaponSet weaponSet = currentItems.WeaponSets[i];
- if (!WeaponSet.IsNullOrEmpty(weaponSet))
- {
- if (weaponSet.PrimaryWeapon != null)
- {
- AttackBase attack = weaponSet.PrimaryWeapon.Attack;
- if (attack != null)
- {
- return attack;
- }
- }
- if (weaponSet.SecondaryWeapon != null)
- {
- AttackBase attack2 = weaponSet.SecondaryWeapon.Attack;
- if (attack2 != null)
- {
- return attack2;
- }
- }
- }
- }
- }
- }
- AttackBase primaryUnarmedAttack = this.m_characterStats.PrimaryUnarmedAttack;
- if (primaryUnarmedAttack != null)
- {
- return primaryUnarmedAttack;
- }
- return null;
- }
- protected static AttackBase GetPrimaryAttack(GameObject owner)
- {
- if (owner == null)
- {
- return null;
- }
- AIController component = owner.GetComponent<AIController>();
- if (component != null)
- {
- return component.GetPrimaryAttack();
- }
- CharacterStats component2 = owner.GetComponent<CharacterStats>();
- if (component2 != null)
- {
- return component2.PrimaryUnarmedAttack;
- }
- return null;
- }
- protected void ResetPrimaryAttackReevaluationTimer()
- {
- this.m_primaryAttackReevaluationTimer = GlobalGameSettingsGameData.Instance.PrimaryAttackReevaluationInterval;
- }
- protected AttackBase GetSecondaryAttack()
- {
- if (this.m_equipment != null)
- {
- return this.m_equipment.SecondaryAttack;
- }
- return null;
- }
- protected AttackBase GetDesiredAttack(GameObject target)
- {
- AttackBase primaryAttack = this.GetPrimaryAttack();
- AttackBase secondaryAttack = this.GetSecondaryAttack();
- if (secondaryAttack == null)
- {
- return primaryAttack;
- }
- if (target != null && !AIController.AreAttacksCompatible(primaryAttack, secondaryAttack))
- {
- return this.PickValidAttack(primaryAttack, secondaryAttack, target);
- }
- if (primaryAttack == this.m_previousAttack)
- {
- return secondaryAttack;
- }
- return primaryAttack;
- }
- protected AttackBase GetOtherAttack(AttackBase attack)
- {
- if (this.GetPrimaryAttack() == attack)
- {
- return this.GetSecondaryAttack();
- }
- if (this.GetSecondaryAttack() == attack)
- {
- return this.GetPrimaryAttack();
- }
- return null;
- }
- protected static bool AreAttacksCompatible(AttackBase primaryAttack, AttackBase secondaryAttack)
- {
- return (!(primaryAttack is AttackRanged) || !(secondaryAttack is AttackMelee)) && (!(secondaryAttack is AttackRanged) || !(primaryAttack is AttackMelee));
- }
- protected AttackBase PickValidAttack(AttackBase primaryAttack, AttackBase secondaryAttack, GameObject target)
- {
- float num = this.m_mover.Radius;
- Mover component = ComponentUtils.GetComponent<Mover>(target);
- if (component != null)
- {
- num += component.Radius;
- }
- else
- {
- num += GlobalGameSettingsGameData.Instance.MinimumMoverRadius;
- }
- float num2 = Onyx.Math.Distance2D(base.get_transform().get_position(), target.get_transform().get_position()) - num;
- if (num2 > GlobalGameSettingsGameData.Instance.CombatSettingsComponent.RangedAutoAttackDistance)
- {
- if (primaryAttack is AttackRanged)
- {
- return primaryAttack;
- }
- return secondaryAttack;
- }
- else
- {
- if (primaryAttack is AttackMelee)
- {
- return primaryAttack;
- }
- return secondaryAttack;
- }
- }
- protected void PerformDesiredAttack(GameObject target)
- {
- this.m_previousAttack = this.GetDesiredAttack(target);
- }
- protected AttackFirearm GetDesiredFirearmAttack()
- {
- return this.GetDesiredAttack(this.CurrentTarget) as AttackFirearm;
- }
- protected AttackBase GetCurrentAttack()
- {
- for (int i = this.BehaviorStack.BehaviorCount - 1; i >= 0; i--)
- {
- AIBehavior behavior = this.BehaviorStack.GetBehavior(i);
- PreparingToActParams preparingToActParams = behavior.AIParams as PreparingToActParams;
- if (preparingToActParams != null)
- {
- Game.AI.Action action = preparingToActParams.CurrentAction;
- if (action == null)
- {
- action = preparingToActParams.ForcedAction;
- }
- if (action != null)
- {
- return action.Attack;
- }
- }
- else
- {
- AIBehaviorType behaviorType = (behavior.AIBehaviorData.Component as AIBehaviorDataComponent).BehaviorType;
- if (behaviorType == AIBehaviorType.QueuedAction)
- {
- return null;
- }
- ActionParams actionParams = behavior.AIParams as ActionParams;
- if (actionParams != null && actionParams.CurrentAction != null)
- {
- return actionParams.CurrentAction.Attack;
- }
- }
- }
- return null;
- }
- protected GenericAbility GetCurrentAbility()
- {
- for (int i = this.BehaviorStack.BehaviorCount - 1; i >= 0; i--)
- {
- AIBehavior behavior = this.BehaviorStack.GetBehavior(i);
- PreparingToActParams preparingToActParams = behavior.AIParams as PreparingToActParams;
- if (preparingToActParams != null)
- {
- Game.AI.Action action = preparingToActParams.CurrentAction;
- if (action == null)
- {
- action = preparingToActParams.ForcedAction;
- }
- if (action != null)
- {
- return action.Ability;
- }
- }
- else
- {
- AIBehaviorType behaviorType = (behavior.AIBehaviorData.Component as AIBehaviorDataComponent).BehaviorType;
- if (behaviorType == AIBehaviorType.QueuedAction)
- {
- return null;
- }
- ActionParams actionParams = behavior.AIParams as ActionParams;
- if (actionParams != null && actionParams.CurrentAction != null)
- {
- return actionParams.CurrentAction.Ability;
- }
- }
- }
- return null;
- }
- protected GenericAbility GetCurrentIntroStateAbility()
- {
- AttackIntroState attackIntroState = (this.BehaviorStack.CurrentBehavior == null) ? null : (this.BehaviorStack.CurrentBehavior.CurrentState as AttackIntroState);
- if (attackIntroState == null)
- {
- return null;
- }
- ActionParams actionParams = attackIntroState.Params as ActionParams;
- if (actionParams != null && actionParams.CurrentAttack != null && actionParams.CurrentAttack.AbilityOrigin != null)
- {
- return actionParams.CurrentAttack.AbilityOrigin;
- }
- return null;
- }
- protected bool IsAbilityQueued(GenericAbility ability, bool includeQueuedActions)
- {
- for (int i = this.BehaviorStack.BehaviorCount - 1; i > 0; i--)
- {
- AIBehavior behavior = this.BehaviorStack.GetBehavior(i);
- AIBehaviorType behaviorType = (behavior.AIBehaviorData.Component as AIBehaviorDataComponent).BehaviorType;
- if (behaviorType == AIBehaviorType.Cast || behaviorType == AIBehaviorType.ConsumePotion || includeQueuedActions)
- {
- ActionParams actionParams = behavior.AIParams as ActionParams;
- if (actionParams != null)
- {
- Game.AI.Action currentAction = actionParams.CurrentAction;
- if (currentAction != null && currentAction.Ability == ability)
- {
- return true;
- }
- }
- }
- else if (behaviorType == AIBehaviorType.PreparingToAct)
- {
- PreparingToActParams preparingToActParams = behavior.AIParams as PreparingToActParams;
- if (preparingToActParams != null)
- {
- Game.AI.Action action = preparingToActParams.CurrentAction;
- if (action == null)
- {
- action = preparingToActParams.ForcedAction;
- }
- if (action != null && action.Ability == ability)
- {
- return true;
- }
- }
- }
- }
- return false;
- }
- protected bool IsInCombatAgainstParty()
- {
- Faction component = base.GetComponent<Faction>();
- if (component != null && component.IsDominated)
- {
- return true;
- }
- AIBehavior behavior = this.GetBehavior(AIBehaviorType.PreparingToAct);
- if (behavior != null)
- {
- PreparingToActParams preparingToActParams = behavior.AIParams as PreparingToActParams;
- if (preparingToActParams != null)
- {
- return preparingToActParams.IsAttackingParty;
- }
- }
- return false;
- }
- protected void StopCombat()
- {
- this.m_delayedCombatParams.Reset();
- this.BehaviorStack.ClearQueuedBehaviors(true);
- this.BehaviorStack.PopAllBehaviorsBelowPriority(7);
- AIBehavior currentBehavior = this.BehaviorStack.CurrentBehavior;
- AIBehaviorType currentBehaviorType = this.GetCurrentBehaviorType();
- if (currentBehaviorType == AIBehaviorType.KnockedDown)
- {
- KnockedDownState knockedDownState = currentBehavior.CurrentState as KnockedDownState;
- if (knockedDownState != null)
- {
- knockedDownState.Clear();
- }
- }
- else if (currentBehaviorType == AIBehaviorType.Unconscious)
- {
- UnconsciousState unconsciousState = currentBehavior.CurrentState as UnconsciousState;
- if (unconsciousState != null)
- {
- unconsciousState.Clear();
- }
- }
- AIBehavior behavior = AIBehaviorManager.AllocateIdleBehavior();
- this.BehaviorStack.QueueBehavior(behavior);
- StatusEffectManager component = base.GetComponent<StatusEffectManager>();
- if (component != null)
- {
- component.HandleOnCombatEnd();
- }
- this.MustDieForCombatToEnd = false;
- }
- protected void BeginCooldown(Guid decisionTreeID, int nodeID)
- {
- ActionCooldown[] array = null;
- if (this.Cooldowns.TryGetValue(decisionTreeID, out array) && nodeID >= 0 && nodeID < array.Length)
- {
- array[nodeID].BeginCooldown();
- }
- }
- protected void ClearCooldowns()
- {
- foreach (ActionCooldown[] current in this.m_cooldowns.Values)
- {
- for (int i = 0; i < current.Length; i++)
- {
- current[i].Reset();
- }
- }
- }
- protected void StartHoldTimer()
- {
- if (this.m_holdMove && this.IsInCombat && this.m_partyMember != null)
- {
- this.m_holdTimer = GlobalGameSettingsGameData.Instance.DefaultHoldTime;
- }
- this.m_holdMove = false;
- }
- protected void ResetHoldTimer()
- {
- this.m_holdTimer = 0f;
- this.m_holdMove = false;
- }
- protected void SetHoldMove()
- {
- if (this.IsInCombat)
- {
- this.m_holdMove = true;
- }
- }
- protected void HandleCombatStart()
- {
- if (this.m_alphaControl != null && this.m_health != null && this.m_health.IsTargetable())
- {
- this.CacheAlphaControl(false);
- this.m_alphaControl.EnableOcclusion(true);
- }
- }
- protected void HandleCombatEnd()
- {
- if (this.m_partyMember != null)
- {
- this.PopAllBehaviorsOfType(AIBehaviorType.PreparingToAct);
- }
- else if (this.m_alphaControl != null)
- {
- this.m_alphaControl.EnableOcclusion(false);
- }
- this.m_previousAttack = null;
- this.ResetHoldTimer();
- AIController.ReloadFirearms(base.get_gameObject());
- this.CLearTargetTracking();
- }
- protected static void ReloadFirearms(GameObject owner)
- {
- if (owner == null)
- {
- return;
- }
- Equipment component = owner.GetComponent<Equipment>();
- if (component != null)
- {
- EquipmentSet currentItems = component.CurrentItems;
- if (currentItems != null)
- {
- for (int i = 0; i < currentItems.WeaponSets.Length; i++)
- {
- WeaponSet weaponSet = currentItems.WeaponSets[i];
- if (weaponSet.PrimaryWeapon != null)
- {
- AttackFirearm attackFirearm = weaponSet.PrimaryWeapon.Attack as AttackFirearm;
- if (attackFirearm != null)
- {
- attackFirearm.Reload();
- }
- }
- if (weaponSet.SecondaryWeapon != null)
- {
- AttackFirearm attackFirearm2 = weaponSet.SecondaryWeapon.Attack as AttackFirearm;
- if (attackFirearm2 != null)
- {
- attackFirearm2.Reload();
- }
- }
- }
- }
- }
- }
- protected void RecordRetreatPosition(Vector3 position)
- {
- this.m_retreatPosition = position;
- }
- protected bool CanBeTethered()
- {
- return this.IsTethered && this.m_retreatPosition.get_sqrMagnitude() >= 1.401298E-45f && !(this.m_partyMember != null);
- }
- protected bool IsBeingKited()
- {
- if (!this.CanBeTethered())
- {
- return false;
- }
- GameObject currentTarget = this.CurrentTarget;
- if (currentTarget == null)
- {
- return false;
- }
- AIController component = currentTarget.GetComponent<AIController>();
- if (component == null)
- {
- return false;
- }
- if (this.m_faction != null && !this.m_faction.IsHostile(component.m_faction))
- {
- return false;
- }
- if (!component.Mover.IsMoving)
- {
- return false;
- }
- if (this.Mover != null && component.Mover != null && this.Mover.DesiredSpeed > component.Mover.DesiredSpeed)
- {
- return false;
- }
- float num = Onyx.Math.Distance2DSquared(base.get_transform().get_position(), component.get_transform().get_position());
- float num2 = Onyx.Math.Distance2DSquared(base.get_transform().get_position(), this.m_retreatPosition);
- if (num2 > this.TetherDistanceSq)
- {
- if (num < GlobalGameSettingsGameData.Instance.AISettingsComponent.KiteTargetFarMinimumDistanceSq)
- {
- return false;
- }
- }
- else
- {
- if (num2 < this.TetherDistanceSq * 0.33f)
- {
- return false;
- }
- if (num < GlobalGameSettingsGameData.Instance.AISettingsComponent.KiteTargetNearMinimumDistanceSq)
- {
- return false;
- }
- }
- return true;
- }
- protected void AddCurrentTargetToKiteIgnoreList()
- {
- GameObject currentTarget = this.CurrentTarget;
- if (currentTarget == null)
- {
- return;
- }
- Faction component = currentTarget.GetComponent<Faction>();
- if (component == null)
- {
- return;
- }
- this.m_kiteTargets.Add(new AIController.KiteTarget(component));
- }
- protected bool IsInTetherRange(Faction target)
- {
- float distanceToTargetSq = Onyx.Math.Distance2DSquared(base.get_transform().get_position(), target.get_transform().get_position());
- return this.IsInTetherRangePrecomputed(target, distanceToTargetSq);
- }
- protected bool IsInTetherRangePrecomputed(Faction target, float distanceToTargetSq)
- {
- if (this.IsInKiteIgnoreList(target))
- {
- return false;
- }
- float num = Onyx.Math.Distance2DSquared(target.get_transform().get_position(), this.RetreatPosition);
- return num <= this.TetherDistanceSq || distanceToTargetSq <= GlobalGameSettingsGameData.Instance.AISettingsComponent.KiteTargetFarMinimumDistanceSq;
- }
- protected bool IsInKiteIgnoreList(Faction target)
- {
- if (this.m_kiteTargets.Count > 0)
- {
- for (int i = 0; i < this.m_kiteTargets.Count; i++)
- {
- if (this.m_kiteTargets[i].Target == target)
- {
- return true;
- }
- }
- }
- return false;
- }
- protected void SetParentEncounter(Encounter encounter)
- {
- this.m_parentEncounter = encounter;
- }
- protected void UpdateMustDieForCombatToEnd()
- {
- if (this.m_mustDieForCombatToEnd)
- {
- return;
- }
- if (this.m_parentEncounter != null)
- {
- this.m_parentEncounter.SetMustDieForCombatToEndFlags();
- }
- else if (this.CombatEndsOnDeath)
- {
- this.MustDieForCombatToEnd = true;
- }
- else if (this.Faction.GetRelationshipToPlayer() == Relationship.Hostile && !this.Faction.IsDominated && GodChallengeGameData.AnyEnabledChallenge(GodChallengeGameData.CannotFleeCombatPredicate))
- {
- this.MustDieForCombatToEnd = true;
- }
- }
- protected void MarkSummonsMustDieForCombatToEnd()
- {
- for (int i = 0; i < this.m_summonedCreatures.Count; i++)
- {
- AIController component = ComponentUtils.GetComponent<AIController>(this.m_summonedCreatures[i]);
- if (component != null)
- {
- component.m_mustDieForCombatToEnd = true;
- }
- }
- }
- protected void InterruptAnimationForCutscene()
- {
- if (this.m_animController != null)
- {
- this.m_animController.PlayReaction(ReactionType.None);
- this.m_animController.ClearReactions();
- if (!this.m_animController.IsPlayingIdle && this.GetCurrentBehaviorType() != AIBehaviorType.Emerge)
- {
- this.m_animController.Interrupt();
- }
- this.m_animController.Loop = false;
- this.m_animController.ClearAnimationTypes();
- this.m_animController.ClearCurrentAnimation();
- }
- }
- protected AIBehaviorType GetCurrentBehaviorType()
- {
- if (this.BehaviorStack.CurrentBehavior == null)
- {
- return AIBehaviorType.None;
- }
- return (this.BehaviorStack.CurrentBehavior.AIBehaviorData.Component as AIBehaviorDataComponent).BehaviorType;
- }
- protected AIBehavior GetBehavior(AIBehaviorType behaviorType)
- {
- for (int i = this.BehaviorStack.BehaviorCount - 1; i >= 0; i--)
- {
- AIBehavior behavior = this.BehaviorStack.GetBehavior(i);
- if ((behavior.AIBehaviorData.Component as AIBehaviorDataComponent).BehaviorType == behaviorType)
- {
- return behavior;
- }
- }
- return null;
- }
- protected AIBehavior GetCurrentBehaviorOrSubBehavior()
- {
- AIBehavior currentBehavior = this.BehaviorStack.CurrentBehavior;
- if (currentBehavior == null)
- {
- return null;
- }
- if (currentBehavior.CurrentState != null && currentBehavior.CurrentState.SubBehavior != null)
- {
- return currentBehavior.CurrentState.SubBehavior;
- }
- return currentBehavior;
- }
- protected bool CancelAndLoseCurrentAction(bool isInterrupt)
- {
- GenericAbility genericAbility;
- return this.CancelAndLoseCurrentAction(isInterrupt, out genericAbility);
- }
- protected bool CancelAndLoseCurrentAction(bool isInterrupt, out GenericAbility interruptedAbility)
- {
- AIBehaviorType currentBehaviorType = this.GetCurrentBehaviorType();
- if (currentBehaviorType == AIBehaviorType.Attack || currentBehaviorType == AIBehaviorType.Cast || currentBehaviorType == AIBehaviorType.ConsumePotion || currentBehaviorType == AIBehaviorType.Grapple)
- {
- interruptedAbility = null;
- ActionParams actionParams = this.BehaviorStack.CurrentBehavior.AIParams as ActionParams;
- if (actionParams != null)
- {
- if (currentBehaviorType == AIBehaviorType.Cast)
- {
- CastAction castAction = actionParams.CurrentAction as CastAction;
- if (castAction != null && castAction.Ability != null && !castAction.IsActionFinished && isInterrupt)
- {
- castAction.Ability.ConsumeResources();
- interruptedAbility = castAction.Ability;
- }
- }
- else if (currentBehaviorType == AIBehaviorType.ConsumePotion)
- {
- ConsumeItemAction consumeItemAction = actionParams.CurrentAction as ConsumeItemAction;
- if (consumeItemAction != null && consumeItemAction.Ability != null && !consumeItemAction.IsAbilityTriggered && isInterrupt)
- {
- consumeItemAction.Ability.ConsumeResources();
- interruptedAbility = consumeItemAction.Ability;
- }
- }
- actionParams.CurrentAction.IsActionFinished = true;
- }
- this.BehaviorStack.PopCurrentBehavior();
- Equipment component = base.GetComponent<Equipment>();
- if (component != null)
- {
- component.ShowSlot(EquipmentSlot.PrimaryWeapon);
- component.ShowSlot(EquipmentSlot.SecondaryWeapon);
- }
- return true;
- }
- interruptedAbility = null;
- return false;
- }
- protected bool CancelGrappleBehavior()
- {
- if (this.GetCurrentBehaviorType() == AIBehaviorType.Grapple)
- {
- this.BehaviorStack.PopCurrentBehavior();
- this.m_animController.Interrupt();
- return true;
- }
- return false;
- }
- protected bool IsCurrentBehaviorUsingWeapon()
- {
- AIBehaviorType currentBehaviorType = this.GetCurrentBehaviorType();
- if (currentBehaviorType == AIBehaviorType.Attack || currentBehaviorType == AIBehaviorType.Cast)
- {
- ActionParams actionParams = this.BehaviorStack.CurrentBehavior.AIParams as ActionParams;
- if (actionParams != null && actionParams.CurrentAction != null && actionParams.CurrentAction.Attack != null)
- {
- return actionParams.CurrentAction.Attack.IsNormalAttack;
- }
- }
- return false;
- }
- protected void PopAllBehaviorsOfType(AIBehaviorType type)
- {
- for (int i = this.BehaviorStack.BehaviorCount - 1; i > 0; i--)
- {
- AIBehavior behavior = this.BehaviorStack.GetBehavior(i);
- AIBehaviorType behaviorType = (behavior.AIBehaviorData.Component as AIBehaviorDataComponent).BehaviorType;
- if (behaviorType == type)
- {
- this.BehaviorStack.PopBehavior(behavior);
- }
- }
- }
- protected void SafePopAllBehaviors(bool force = true)
- {
- this.BehaviorStack.ClearQueuedBehaviors(force);
- AIBehavior currentBehavior = this.BehaviorStack.CurrentBehavior;
- if (currentBehavior != null && currentBehavior.Priority < 3 && this.GetCurrentBehaviorType() != AIBehaviorType.Standup && (force || currentBehavior.CanBeCancelledByUser))
- {
- this.BehaviorStack.PopAllBehaviors();
- }
- this.m_delayedCombatParams.Reset();
- }
- protected override void OnyxGUI()
- {
- base.OnyxGUI();
- if (AIController.DebugEngagement)
- {
- this.DrawEngagementDebug();
- }
- if (AIController.m_debugMode == AIController.DebugMode.Shout || Stealth.DebuggingStealth)
- {
- bool flag = this.IsFogVisible;
- if (!flag)
- {
- float num = GameUtilities.NearestPlayerSquaredDist(base.get_transform().get_position());
- float perceptionDistance = this.PerceptionDistance;
- if (num < perceptionDistance * perceptionDistance * 9f)
- {
- flag = true;
- }
- }
- if (flag)
- {
- if (AIController.m_debugMode == AIController.DebugMode.Shout && this.m_debugShoutTimer > 0f)
- {
- Camera mainCamera = OnyxMainCamera.MainCamera;
- GUI.set_color((!this.m_debugShoutOrigin) ? new Color(1f, 0.8f, 0.5f) : new Color(1f, 0.5f, 0f));
- GUIHelper.DrawCircle(base.get_transform().get_position(), this.ShoutRange, GUI.get_color());
- GUIHelper.DrawArrow(new Vector3(base.get_transform().get_position().x - 0.5f, base.get_transform().get_position().y, base.get_transform().get_position().z - 0.5f), base.get_transform().get_position(), GUI.get_color());
- Vector3 vector = base.get_transform().get_position();
- vector = mainCamera.WorldToScreenPoint(vector);
- vector.y = (float)mainCamera.get_pixelHeight() - vector.y;
- GUI.Label(new Rect(vector.x, vector.y, (float)Screen.get_width(), (float)Screen.get_height()), (!this.m_debugShoutOrigin) ? "Shout Relay" : "Shout");
- GUI.set_color(Color.get_white());
- }
- if (Stealth.DebuggingStealth)
- {
- GUIHelper.DrawCircle(base.get_transform().get_position(), this.StealthedCharacterHearingDistance, Color.get_magenta());
- GUIHelper.DrawCircle(base.get_transform().get_position(), this.PerceptionDistance, Color.get_yellow());
- GUIHelper.DrawTargetingCone(base.get_transform().get_position(), base.get_transform().get_forward(), this.StealthedCharacterVisionDistance, this.StealthedCharacterVisionAngle, Color.get_blue());
- }
- }
- }
- bool flag2 = AIController.m_debugMode == AIController.DebugMode.All || (AIController.m_debugMode == AIController.DebugMode.MouseOver && GameCursor.ObjectUnderCursor == base.get_gameObject());
- if (flag2 && this.BehaviorStack != null && this.BehaviorStack.CurrentBehavior != null)
- {
- Camera mainCamera2 = OnyxMainCamera.MainCamera;
- Vector3 vector2 = base.get_transform().get_position();
- vector2.y += 2.5f;
- vector2 = mainCamera2.WorldToScreenPoint(vector2);
- if (vector2.x < (float)(-(float)mainCamera2.get_pixelWidth()) || vector2.x > (float)(2 * mainCamera2.get_pixelWidth()) || vector2.y < (float)(-(float)mainCamera2.get_pixelHeight()) || vector2.y > (float)(2 * mainCamera2.get_pixelHeight()))
- {
- return;
- }
- string text = base.get_name();
- if (this.IsFighting)
- {
- text += "\nIn Combat";
- for (int i = 0; i < this.DecisionTrees.Count; i++)
- {
- text = text + ", " + this.DecisionTrees[i].DebugName;
- }
- }
- string debugText = this.BehaviorStack.CurrentBehavior.GetDebugText();
- string text2 = string.Empty;
- string debugText2 = this.BehaviorStack.GetDebugText();
- string text3 = debugText2.Substring(0, debugText2.IndexOf('\n'));
- string text4 = debugText2.Substring(debugText2.IndexOf('\n'));
- if (this.BehaviorStack.CurrentBehavior.CurrentState != null)
- {
- text2 = this.BehaviorStack.CurrentBehavior.CurrentState.GetDebugText();
- }
- float num2 = 200f;
- float num3 = 0f;
- GUIStyle gUIStyle = new GUIStyle(GUI.get_skin().get_label());
- gUIStyle.set_wordWrap(false);
- gUIStyle.set_padding(new RectOffset(0, 0, 1, 1));
- gUIStyle.get_normal().set_textColor(Color.get_white());
- gUIStyle.set_fontSize(10);
- Vector2 vector3 = vector2;
- gUIStyle.set_alignment(1);
- gUIStyle.set_fontStyle(1);
- Vector2 size = gUIStyle.CalcSize(new GUIContent(text));
- Vector2 position = vector3 - new Vector2(num2 / 2f, size.y);
- gUIStyle.set_alignment(0);
- Vector2 size2 = gUIStyle.CalcSize(new GUIContent(text3));
- size2.x = num2 * 0.4f;
- Vector2 vector4 = new Vector2(vector3.x - 0.1f * num2, position.y);
- Vector2 size3 = gUIStyle.CalcSize(new GUIContent(debugText));
- Vector2 position2 = vector4 - new Vector2(0f, size3.y + 4f);
- Vector2 size4 = gUIStyle.CalcSize(new GUIContent(text2));
- num3 = System.Math.Max(num3, vector2.y - (position2.y - size4.y));
- Vector2 position3 = new Vector2(position.x, vector2.y - num3 + 10f);
- gUIStyle.set_fontStyle(0);
- Vector2 size5 = gUIStyle.CalcSize(new GUIContent(text4));
- num3 = System.Math.Max(num3, vector2.y - (position3.y - size5.y));
- GUI.set_depth((int)(100000f * (base.get_transform().get_position() - mainCamera2.get_transform().get_position()).get_sqrMagnitude()));
- GUI.Box(new Rect(vector2.x - num2 / 2f, (float)mainCamera2.get_pixelHeight() - vector2.y, num2, num3), string.Empty);
- gUIStyle.set_alignment(1);
- gUIStyle.set_fontStyle(1);
- this.DrawLabel(text, vector3, size, gUIStyle, mainCamera2);
- gUIStyle.set_alignment(0);
- this.DrawLabel(text3, position, size2, gUIStyle, mainCamera2);
- gUIStyle.set_fontStyle(0);
- this.DrawLabel(text4, position3, size5, gUIStyle, mainCamera2);
- this.DrawLabel(debugText, vector4, size3, gUIStyle, mainCamera2);
- this.DrawLabel(text2, position2, size4, gUIStyle, mainCamera2);
- }
- }
- protected void DrawLabel(string text, Vector2 position, Vector2 size, GUIStyle guiStyle, Camera mainCamera)
- {
- if (guiStyle.get_alignment() == 1)
- {
- position.x -= size.x / 2f;
- }
- GUI.Label(new Rect(position.x, (float)mainCamera.get_pixelHeight() - position.y, size.x, size.y), text, guiStyle);
- }
- protected virtual void OnDrawGizmosSelected()
- {
- Gizmos.set_color(Color.get_magenta());
- Gizmos.DrawLine(base.get_transform().get_position(), base.get_transform().get_position() + base.get_transform().get_forward());
- if (this.m_characterStats != null)
- {
- Gizmos.set_color(Color.get_white());
- GUIHelper.GizmoDrawCircle(base.get_transform().get_position(), this.PerceptionDistance);
- }
- Gizmos.set_color(Color.get_red());
- GUIHelper.GizmoDrawCircle(base.get_transform().get_position(), this.ShoutRange);
- }
- protected void GetDataObjects(List<IDataObject> dataObjects)
- {
- for (int i = 0; i < this.m_decisionTreeReferences.Length; i++)
- {
- dataObjects.Add(this.m_decisionTreeReferences[i].Data);
- }
- }
- protected Guid[] Editor_GetDecisionTreeGuids()
- {
- List<Guid> list = new List<Guid>();
- if (this.m_decisionTreeReferences.Length != 0)
- {
- for (int i = 0; i < this.m_decisionTreeReferences.Length; i++)
- {
- if (!DataReference.IsNullOrEmpty(this.m_decisionTreeReferences[i]))
- {
- this.m_decisionTreeReferences[i].AssignBaseReference();
- list.Add(this.m_decisionTreeReferences[i].ID);
- }
- }
- }
- CharacterStats component = base.GetComponent<CharacterStats>();
- if (component != null)
- {
- Guid[] array = component.Editor_GetDecisionTreeGuids();
- if (array != null)
- {
- list.AddRange(array);
- }
- }
- return list.ToArray();
- }
- protected void DisengageUntargetable()
- {
- for (int i = this.m_threatenedEnemies.Count - 1; i >= 0; i--)
- {
- if (!this.IsTargetable(this.m_threatenedEnemies[i]))
- {
- this.CancelThreat(this.m_threatenedEnemies[i]);
- }
- }
- for (int j = this.m_threatenedBy.Count - 1; j >= 0; j--)
- {
- AIController aIController = this.m_threatenedBy[j];
- if (aIController != null && !aIController.AllowOutgoingThreat())
- {
- this.NotifyEnemyBreaksThreat(aIController);
- this.NotifyEnemyBreaksEngagement(aIController);
- }
- }
- }
- protected void CheckForInvalidEngagements()
- {
- UnityObjectUtilities.RemoveAllNull<AIController>(this.m_engagedEnemies);
- UnityObjectUtilities.RemoveAllNull<AIController>(this.m_engagedBy);
- UnityObjectUtilities.RemoveAllNull<AIController>(this.m_threatenedEnemies);
- UnityObjectUtilities.RemoveAllNull<AIController>(this.m_threatenedBy);
- this.DisengageUntargetable();
- for (int i = 0; i < this.m_disengagementTrackers.Count; i++)
- {
- AIController.DisengagementTracker disengagementTracker = this.m_disengagementTrackers[i];
- disengagementTracker.WaitDuration += Time.get_deltaTime();
- }
- }
- protected bool AllowIncomingThreat()
- {
- AIBehaviorType currentBehaviorType = this.GetCurrentBehaviorType();
- return currentBehaviorType != AIBehaviorType.PushedBack && currentBehaviorType != AIBehaviorType.Dead && currentBehaviorType != AIBehaviorType.Unconscious && currentBehaviorType != AIBehaviorType.Grabbed;
- }
- protected bool AllowOutgoingThreat()
- {
- AIBehaviorType currentBehaviorType = this.GetCurrentBehaviorType();
- if (currentBehaviorType == AIBehaviorType.Stunned || currentBehaviorType == AIBehaviorType.PushedBack || currentBehaviorType == AIBehaviorType.Paralyzed || currentBehaviorType == AIBehaviorType.Terrified || currentBehaviorType == AIBehaviorType.KnockedDown || currentBehaviorType == AIBehaviorType.Dead || currentBehaviorType == AIBehaviorType.Unconscious || currentBehaviorType == AIBehaviorType.Launched || currentBehaviorType == AIBehaviorType.Grabbed)
- {
- return false;
- }
- AIBehavior currentBehavior = this.BehaviorStack.CurrentBehavior;
- return currentBehaviorType != AIBehaviorType.UseObject || !(currentBehavior.CurrentState is InUseState);
- }
- protected void UpdateEngagement(AttackBase attack)
- {
- if (GameState.Paused)
- {
- return;
- }
- if (!this.AllowIncomingThreat())
- {
- this.BreakIncomingThreats(false);
- }
- if (!this.AllowOutgoingThreat())
- {
- this.BreakOutgoingThreats(false);
- return;
- }
- if (!(attack is AttackMelee))
- {
- return;
- }
- if (this.m_faction == null)
- {
- return;
- }
- for (int i = this.m_disengagementTrackers.Count - 1; i >= 0; i--)
- {
- if (!this.IsTargetable(this.m_disengagementTrackers[i].Enemy) || this.m_disengagementTrackers[i].WaitDuration >= GlobalGameSettingsGameData.Instance.ReengagementWaitPeriod)
- {
- this.m_disengagementTrackers.RemoveAt(i);
- }
- }
- GameObject currentTarget = this.CurrentTarget;
- this.m_cachedEngagementLimit = ((!this.m_characterStats) ? 0 : this.m_characterStats.GetEngageableEnemyCount());
- IList<AIController> threatenedEnemies = this.ThreatenedEnemies;
- for (int j = threatenedEnemies.Count - 1; j >= 0; j--)
- {
- AIController aIController = threatenedEnemies[j];
- if (!this.IsTargetable(aIController) || (this.m_mover.IsMoving && currentTarget != aIController.get_gameObject()))
- {
- this.CancelThreat(aIController);
- }
- else
- {
- Faction faction = aIController.Faction;
- if (faction && !faction.IsHostile(this.m_faction) && !this.m_faction.IsHostile(aIController.Faction))
- {
- this.CancelThreat(aIController);
- }
- else if (this.IsTargetBeingPushedBack(aIController))
- {
- this.CancelThreat(aIController);
- }
- else if (!this.IsWithinThreatRange(aIController, attack))
- {
- Mover component = ComponentUtils.GetComponent<Mover>(aIController);
- if (component.IsMoving && !this.m_mover.IsMoving && this.IsEngaging(aIController))
- {
- this.DisengageEnemy(aIController, attack);
- }
- else
- {
- this.CancelThreat(aIController);
- }
- }
- }
- }
- AIController aIController2 = null;
- if (currentTarget != null)
- {
- aIController2 = ComponentUtils.GetComponent<AIController>(currentTarget);
- }
- if (aIController2 != null)
- {
- if (!this.IsThreatening(aIController2) && this.CanThreatenEnemy(aIController2, attack))
- {
- this.ThreatenEnemy(aIController2);
- }
- if (!this.IsEngaging(aIController2) && this.IsThreatening(aIController2) && this.CanEngageEnemy(aIController2, attack, false))
- {
- this.EngageEnemy(aIController2);
- }
- }
- if (this.IsFighting && FogOfWar.IsFullyVisible(base.get_transform().get_position()) && this.EngagedEnemies.Count < this.m_cachedEngagementLimit)
- {
- RangeManager instance = SingletonBehavior<RangeManager>.Instance;
- RangeManager.Data factionRange = instance.GetFactionRange(base.get_transform().get_position().x, this.Mover.Radius + instance.LargestRadius + 3f);
- int num = factionRange.m_start;
- while (num < factionRange.m_end && this.EngagedEnemies.Count < this.m_cachedEngagementLimit)
- {
- Faction faction2 = instance.GetFaction(num);
- if (!(faction2.AIController == null) && !(faction2.AIController == this))
- {
- if (faction2 != null && !this.IsEngaging(faction2.AIController) && this.CanEngageEnemy(faction2.AIController, attack, true))
- {
- this.EngageEnemy(faction2.AIController);
- }
- }
- num++;
- }
- }
- if (this.EngagedEnemies.Count > 0)
- {
- int num2 = Mathf.Max(0, this.m_cachedEngagementLimit);
- if (this.EngagedEnemies.Count > num2)
- {
- for (int k = 0; k < this.EngagedEnemies.Count; k++)
- {
- if (aIController2 == null || this.EngagedEnemies[k] != aIController2 || num2 == 0)
- {
- this.CancelEngagement(this.EngagedEnemies[k]);
- break;
- }
- }
- }
- }
- }
- protected void AddThreatenedBy(AIController enemy)
- {
- if (!this.m_threatenedBy.Contains(enemy))
- {
- this.m_threatenedBy.Add(enemy);
- }
- if (this.CharacterStats != null)
- {
- this.CharacterStats.NotifyThreatenedByOther(enemy);
- }
- }
- protected void AddEngagedBy(AIController enemy)
- {
- this.AddThreatenedBy(enemy);
- if (!this.m_engagedBy.Contains(enemy))
- {
- this.m_engagedBy.Add(enemy);
- if (this.CharacterStats != null)
- {
- this.CharacterStats.NotifyEngagedByOther(enemy);
- }
- for (int i = 0; i < this.m_disengagementTrackers.Count; i++)
- {
- if (this.m_disengagementTrackers[i].Enemy == enemy)
- {
- this.m_disengagementTrackers.RemoveAt(i);
- break;
- }
- }
- }
- }
- protected bool IsEngagedBy(AIController enemy)
- {
- return enemy != null && this.m_engagedBy.Contains(enemy);
- }
- protected bool IsEngaged()
- {
- return this.m_engagedBy.Count > 0;
- }
- protected bool IsEngaging()
- {
- return this.m_engagedEnemies.Count > 0;
- }
- protected bool IsEngaging(AIController enemy)
- {
- return enemy != null && this.m_engagedEnemies.Contains(enemy);
- }
- protected int GetUniqueEngagementsCount()
- {
- int num = this.m_engagedEnemies.Count;
- foreach (AIController current in this.m_engagedBy)
- {
- if (!this.m_engagedEnemies.Contains(current))
- {
- num++;
- }
- }
- return num;
- }
- protected bool IsThreatenedBy(AIController enemy)
- {
- return enemy != null && this.m_threatenedBy.Contains(enemy);
- }
- protected bool IsThreatened()
- {
- return this.m_threatenedBy.Count > 0;
- }
- protected bool IsThreatening(AIController enemy)
- {
- return enemy != null && this.m_threatenedEnemies.Contains(enemy);
- }
- protected void NotifyEnemyBreaksThreat(AIController enemy)
- {
- if (this.m_threatenedBy.Contains(enemy))
- {
- this.m_threatenedBy.Remove(enemy);
- if (this.m_characterStats != null)
- {
- this.m_characterStats.NotifyThreatenedByOtherBroken(enemy);
- }
- }
- }
- protected void NotifyEnemyBreaksEngagement(AIController enemy)
- {
- if (this.m_engagedBy.Contains(enemy))
- {
- this.m_engagedBy.Remove(enemy);
- if (this.m_characterStats != null)
- {
- this.m_characterStats.NotifyEngagementByOtherBroken(enemy);
- }
- }
- }
- protected void ThreatenEnemy(AIController enemy)
- {
- if (enemy == this)
- {
- return;
- }
- if (!this.AllowOutgoingThreat() || !enemy.AllowIncomingThreat())
- {
- return;
- }
- if (AIController.DebugEngagement)
- {
- UIPopcornTextManager.ShowNotice("threaten (" + enemy.get_name() + ")", base.get_gameObject(), 3f);
- }
- if (!this.m_threatenedEnemies.Contains(enemy))
- {
- this.m_threatenedEnemies.Add(enemy);
- }
- if (this.m_characterStats != null)
- {
- this.m_characterStats.NotifyThreat(enemy);
- }
- enemy.AddThreatenedBy(this);
- }
- protected void EngageEnemy(AIController enemy)
- {
- this.ThreatenEnemy(enemy);
- if (this.IsEngaging(enemy))
- {
- return;
- }
- if (enemy == this)
- {
- return;
- }
- if (!this.AllowOutgoingThreat() || !enemy.AllowIncomingThreat())
- {
- return;
- }
- if (AIController.DebugEngagement)
- {
- UIPopcornTextManager.ShowNotice("engage (" + enemy.get_name() + ")", base.get_gameObject(), 3f);
- }
- if (!this.m_engagedEnemies.Contains(enemy))
- {
- this.m_engagedEnemies.Add(enemy);
- }
- if (this.m_characterStats != null)
- {
- this.m_characterStats.NotifyEngagement(enemy);
- }
- enemy.NotifyMeleeEngaged(this);
- if (SingletonBehavior<FogOfWar>.Instance.PointFullyVisible(base.get_gameObject().get_transform().get_position()))
- {
- Console.AddMessage(Console.Format(GuiStringTable.GetTextWithLinks(100, Gender.Neuter), new object[]
- {
- CharacterStatsUtility.NameColored(base.get_gameObject()),
- CharacterStatsUtility.NameColored(enemy)
- }));
- }
- enemy.AddEngagedBy(this);
- }
- protected void DisengageEnemy(AIController enemy, AttackBase attack)
- {
- CharacterStats characterStats = enemy.CharacterStats;
- if (characterStats != null && !characterStats.IsImmuneToEngagement)
- {
- attack.CloneAndResolveDisengagement(enemy.get_gameObject());
- UIPopcornTextManager.ShowNotice(GuiStringTable.GetText(2150), enemy.get_gameObject(), 2.5f);
- }
- this.CancelThreat(enemy);
- if (this.m_characterStats != null)
- {
- this.m_characterStats.NotifyEngagementBreak(enemy);
- }
- this.NotifyEnemyBreaksEngagement(enemy);
- if (enemy)
- {
- enemy.NotifyEnemyBreaksEngagement(this);
- }
- }
- protected void CancelThreat(AIController enemy)
- {
- this.CancelEngagement(enemy);
- if (!this.m_threatenedEnemies.Contains(enemy))
- {
- return;
- }
- if (enemy == null)
- {
- this.m_threatenedEnemies.Remove(enemy);
- return;
- }
- if (AIController.DebugEngagement)
- {
- UIPopcornTextManager.ShowNotice("stop threat (" + enemy.get_name() + ")", base.get_gameObject(), 3f);
- }
- this.m_disengagementTrackers.Add(new AIController.DisengagementTracker(enemy));
- this.m_threatenedEnemies.Remove(enemy);
- if (enemy != null)
- {
- enemy.NotifyEnemyBreaksThreat(this);
- }
- if (this.m_characterStats != null)
- {
- this.m_characterStats.NotifyThreatBreak(enemy);
- }
- }
- protected void CancelEngagement(AIController enemy)
- {
- if (!this.m_engagedEnemies.Contains(enemy))
- {
- return;
- }
- if (enemy == null)
- {
- this.m_engagedEnemies.Remove(enemy);
- return;
- }
- if (AIController.DebugEngagement)
- {
- UIPopcornTextManager.ShowNotice("stop engagement (" + enemy.get_name() + ")", base.get_gameObject(), 3f);
- }
- this.m_engagedEnemies.Remove(enemy);
- this.TrackObjectLifetime(enemy, 2f);
- if (enemy)
- {
- enemy.NotifyEnemyBreaksEngagement(this);
- }
- if (this.m_characterStats != null)
- {
- this.m_characterStats.NotifyEngagementBreak(enemy);
- }
- }
- protected void CancelAllThreats()
- {
- for (int i = this.ThreatenedEnemies.Count - 1; i >= 0; i--)
- {
- AIController aIController = this.ThreatenedEnemies[i];
- if (aIController != null)
- {
- this.CancelThreat(aIController);
- }
- }
- }
- protected void CancelAllThreatsAndDelayReengagement()
- {
- for (int i = this.ThreatenedEnemies.Count - 1; i >= 0; i--)
- {
- AIController aIController = this.ThreatenedEnemies[i];
- if (aIController != null)
- {
- this.CancelThreat(aIController);
- this.m_disengagementTrackers.Add(new AIController.DisengagementTracker(aIController));
- }
- }
- }
- protected bool CanThreatenEnemy(AIController enemy, AttackBase attack)
- {
- if (enemy == null)
- {
- return false;
- }
- if (!this.IsWithinPotentialThreatRange(enemy))
- {
- return false;
- }
- if (this.ThreatDisabled)
- {
- return false;
- }
- if (Stealth.IsInStealthMode(base.get_gameObject(), false) || Stealth.IsInStealthMode(enemy.get_gameObject(), false))
- {
- return false;
- }
- if (!(attack is AttackMelee))
- {
- return false;
- }
- if (!this.IsTargetable(enemy))
- {
- return false;
- }
- if (this.IsInvisible)
- {
- return false;
- }
- if (this.IsPet)
- {
- return false;
- }
- GameObject gameObject = base.get_gameObject();
- if (enemy.get_gameObject() == gameObject)
- {
- return false;
- }
- GameObject currentTarget = this.CurrentTarget;
- if (this.GetCurrentBehaviorType() == AIBehaviorType.PreparingToAct && currentTarget != enemy.get_gameObject())
- {
- return false;
- }
- if (this.m_mover.IsMoving && currentTarget != enemy.get_gameObject())
- {
- return false;
- }
- Faction faction = enemy.Faction;
- if (faction && this.m_faction != null && !faction.IsHostile(this.m_faction) && !this.m_faction.IsHostile(faction))
- {
- return false;
- }
- for (int i = 0; i < this.m_disengagementTrackers.Count; i++)
- {
- if (this.m_disengagementTrackers[i].Enemy == enemy)
- {
- return false;
- }
- }
- return !enemy.IsInvisible && !enemy.IsPet && this.IsWithinThreatRange(enemy, attack);
- }
- protected bool CanEngageEnemy(AIController enemy, AttackBase attack, bool checkLimit)
- {
- if (!this.CanThreatenEnemy(enemy, attack))
- {
- return false;
- }
- if (this.EngagementDisabled)
- {
- return false;
- }
- if (this.CharacterStats != null && this.CharacterStats.StatusEffectManager.HasStatusEffectByType(StatusEffectType.CannotEngage))
- {
- return false;
- }
- if (this.IsObjectTracked(enemy))
- {
- return false;
- }
- CharacterStats characterStats = enemy.CharacterStats;
- if (characterStats != null && characterStats.IsImmuneToEngagement)
- {
- return false;
- }
- if (this.m_characterStats != null)
- {
- if (this.m_cachedEngagementLimit == 0 || (checkLimit && this.EngagedEnemies.Count >= this.m_cachedEngagementLimit))
- {
- return false;
- }
- int minimumLevelThatCanEngageMe = characterStats.GetMinimumLevelThatCanEngageMe();
- if (this.m_characterStats.Level < minimumLevelThatCanEngageMe)
- {
- return false;
- }
- }
- return true;
- }
- protected bool IsWithinThreatRange(AIController enemy, AttackBase attack)
- {
- if (enemy == null || this.m_characterStats == null)
- {
- return false;
- }
- AttackMelee attackMelee = attack as AttackMelee;
- if (attackMelee == null)
- {
- return false;
- }
- GameObject gameObject = base.get_gameObject();
- float num = Onyx.Math.Distance2DSquared(enemy.get_transform().get_position(), gameObject.get_transform().get_position());
- float radius = this.Mover.Radius;
- Mover mover = enemy.Mover;
- float num2 = 0.5f;
- if (mover != null)
- {
- num2 = mover.Radius;
- }
- float num3 = attackMelee.AttackMeleeData.EngagementRadius + this.m_characterStats.StatusEffectManager.CalculateValueForStat(StatusEffectType.EngagementRadius, null) + radius + num2;
- return num <= num3 * num3;
- }
- protected bool IsWithinPotentialThreatRange(AIController enemy)
- {
- if (enemy == null)
- {
- return false;
- }
- GameObject gameObject = base.get_gameObject();
- float radius = this.Mover.Radius;
- Mover mover = enemy.Mover;
- float num = 0.5f;
- if (mover != null)
- {
- num = mover.Radius;
- }
- float num2 = radius + num + 3f;
- float num3 = Onyx.Math.Distance2DSquared(enemy.get_transform().get_position(), gameObject.get_transform().get_position());
- return num3 <= num2 * num2;
- }
- protected bool IsTargetable(AIController character)
- {
- return !(character == null) && this.IsTargetable(character.get_gameObject(), null);
- }
- protected bool IsTargetable(GameObject character)
- {
- return this.IsTargetable(character, null);
- }
- protected bool IsTargetable(GameObject character, AttackBase attack)
- {
- Health component = character.GetComponent<Health>();
- return component != null && component.IsTargetableByAttack(attack);
- }
- protected bool IsTargetBeingPushedBack(AIController character)
- {
- return !(character == null) && this.GetCurrentBehaviorType() == AIBehaviorType.PushedBack;
- }
- protected void TrackObjectLifetime(AIController obj, float lifetime)
- {
- AIController.ObjectsWithLifetime item = new AIController.ObjectsWithLifetime(obj, lifetime);
- this.m_trackedObjectList.Add(item);
- }
- protected bool IsObjectTracked(AIController obj)
- {
- for (int i = 0; i < this.m_trackedObjectList.Count; i++)
- {
- if (this.m_trackedObjectList[i] != null && this.m_trackedObjectList[i].Obj == obj)
- {
- return true;
- }
- }
- return false;
- }
- protected void BreakAllThreats(bool engagementOnly = false)
- {
- this.BreakIncomingThreats(engagementOnly);
- this.BreakOutgoingThreats(engagementOnly);
- }
- protected void BreakIncomingThreats(bool engagementOnly = false)
- {
- for (int i = this.ThreatenedBy.Count - 1; i >= 0; i--)
- {
- AIController aIController = this.ThreatenedBy[i];
- if (aIController != null)
- {
- if (engagementOnly)
- {
- aIController.CancelEngagement(this);
- }
- else
- {
- aIController.CancelThreat(this);
- }
- }
- }
- }
- protected void BreakOutgoingThreats(bool engagementOnly = false)
- {
- for (int i = this.ThreatenedEnemies.Count - 1; i >= 0; i--)
- {
- AIController aIController = this.ThreatenedEnemies[i];
- if (aIController != null)
- {
- if (engagementOnly)
- {
- this.CancelEngagement(aIController);
- }
- else
- {
- this.CancelThreat(aIController);
- }
- }
- }
- }
- protected void DrawEngagementDebug()
- {
- Vector3 zero = Vector3.get_zero();
- Color color = new Color(0.5f, 0.5f, 0f);
- Color color2 = new Color(0.5f, 0f, 0f);
- for (int i = 0; i < this.ThreatenedBy.Count; i++)
- {
- GUIHelper.DrawArrow(this.ThreatenedBy[i].get_transform().get_position() + zero, base.get_transform().get_position() + zero, color);
- }
- zero.y += 0.2f;
- for (int j = 0; j < this.ThreatenedEnemies.Count; j++)
- {
- GUIHelper.DrawArrow(base.get_transform().get_position() + zero, this.ThreatenedEnemies[j].get_transform().get_position() + zero, Color.get_yellow());
- }
- zero.y += 0.2f;
- for (int k = 0; k < this.EngagedBy.Count; k++)
- {
- GUIHelper.DrawArrow(this.EngagedBy[k].get_transform().get_position() + zero, base.get_transform().get_position() + zero, color2);
- }
- zero.y += 0.2f;
- for (int l = 0; l < this.EngagedEnemies.Count; l++)
- {
- GUIHelper.DrawArrow(base.get_transform().get_position() + zero, this.EngagedEnemies[l].get_transform().get_position() + zero, Color.get_red());
- }
- }
- protected void InitScanning()
- {
- if (this.m_faction != null && this.m_faction.CurrentTeam.TeamType == TeamType.Townie && this.m_townie == null)
- {
- this.m_townie = ResourceManager.AddComponent<Townie>(base.get_gameObject());
- }
- this.m_scanWaitDuration = Random.Range(0f, 1f);
- }
- protected void CheckForPerceptionEvent()
- {
- if (this.m_scriptEvent)
- {
- for (int i = 0; i < this.m_scriptEvent.Scripts.Count; i++)
- {
- ScriptEvent.ScriptEvents eventType = this.m_scriptEvent.Scripts[i].eventType;
- if (eventType == ScriptEvent.ScriptEvents.OnPerception || eventType == ScriptEvent.ScriptEvents.OnPerceptionPerLoad || eventType == ScriptEvent.ScriptEvents.OnPerceptionOfStealthed || eventType == ScriptEvent.ScriptEvents.OnPerceptionOfNonStealthed)
- {
- this.m_forcePerceptionChecks = true;
- break;
- }
- }
- }
- }
- protected void UpdateScanning()
- {
- if (GameState.IsCutsceneOrConversationRunning())
- {
- return;
- }
- if (this.IsPet)
- {
- return;
- }
- bool flag = this.m_trackingSuspicion;
- if (this.m_townie != null && !flag)
- {
- flag = this.m_townie.RequiresImmediateScanning();
- }
- if (this.m_delayedCombatParams.IsPendingCombat)
- {
- if (this.m_delayedCombatParams.IsTime)
- {
- this.EnterCombat(this.m_delayedCombatParams.Target, this.m_delayedCombatParams.PreparingToActType);
- this.m_delayedCombatParams.Reset();
- }
- else
- {
- this.m_delayedCombatParams.Update();
- }
- }
- if (!flag)
- {
- this.m_scanWaitDuration -= Time.get_deltaTime();
- if (this.m_scanWaitDuration > 0f)
- {
- return;
- }
- this.m_scanWaitDuration += 1f;
- }
- if (this.m_shipController != null)
- {
- this.m_shipController.ScanForTargets();
- }
- if (this.PartyMember == null)
- {
- if (this.m_townie != null && this.m_townie.RequiresScanning())
- {
- this.m_townie.Scan();
- }
- this.ScanForTargets();
- }
- }
- protected void ScanForTargets()
- {
- this.m_trackingSuspicion = false;
- if (this.ScanForTargetsEnabled && this.m_faction != null)
- {
- Relationship relationshipToPlayer = this.m_faction.GetRelationshipToPlayer();
- if (relationshipToPlayer == Relationship.Neutral || relationshipToPlayer == Relationship.Hostile || this.m_forcePerceptionChecks)
- {
- float num = this.PerceptionDistance;
- num *= num;
- bool trackingSuspicion = false;
- List<PartyMember> activePartyMembers = SingletonBehavior<PartyManager>.Instance.GetActivePartyMembers();
- bool flag = false;
- for (int i = 0; i < activePartyMembers.Count; i++)
- {
- PartyMember partyMember = activePartyMembers[i];
- if (partyMember)
- {
- float num2 = Onyx.Math.Distance2DSquared(base.get_transform().get_position(), partyMember.get_transform().get_position());
- if (num2 <= num)
- {
- Health component = partyMember.GetComponent<Health>();
- if (!(component == null) && component.IsTargetable())
- {
- trackingSuspicion = true;
- if (Stealth.IsInStealthMode(partyMember.get_gameObject(), false))
- {
- Stealth component2 = partyMember.GetComponent<Stealth>();
- if (component2)
- {
- this.m_trackingSuspicion = true;
- this.UpdateSuspicion(component2, this.m_suspicionDeltaTime, num2);
- float suspicion = component2.GetSuspicion(base.get_gameObject());
- if (!this.IsInCombat && suspicion >= 100f && relationshipToPlayer == Relationship.Hostile && this.GetCurrentBehaviorType() != AIBehaviorType.Investigate)
- {
- AIBehavior behavior = AIBehaviorManager.AllocateInvestigateBehavior(partyMember.get_transform().get_position(), base.get_transform().get_position(), MovementType.Walk, MovementType.Walk, 2f, true);
- this.BehaviorStack.PushBehavior(behavior);
- UIAudioManager.Instance.Play(StealthUIAudioEventType.StealthInvestigated);
- this.ExecuteOnInvestigate();
- }
- if (suspicion >= 200f)
- {
- this.ExecuteOnPerception(partyMember.get_gameObject(), true);
- flag = true;
- }
- }
- }
- else if (!this.IsInCombat && !flag && !this.m_delayedCombatParams.IsPendingCombat && GameUtilities.LineofSight(base.get_transform().get_position(), partyMember.get_transform().get_position()))
- {
- this.ExecuteOnPerception(partyMember.get_gameObject(), false);
- flag = true;
- if (relationshipToPlayer == Relationship.Hostile && this.m_townie == null)
- {
- if (this.GetCurrentBehaviorType() == AIBehaviorType.Investigate)
- {
- UIInvestigateManager.ShowIcon(base.get_gameObject(), UIInvestigateIndicator.IconType.Spotted, 1f);
- }
- this.m_delayedCombatParams.SetTarget(partyMember.AIController.Faction, AIBehaviorManager.PreparingToActType.PreferredTarget);
- }
- }
- }
- }
- }
- }
- if (!flag)
- {
- this.m_previousPerceptionState = false;
- this.m_trackingSuspicion = trackingSuspicion;
- }
- }
- }
- this.m_suspicionDeltaTime = 0f;
- }
- protected bool ShouldDetectStealthedCharacter(Stealth enemyStealth)
- {
- return this.DetectsStealthedCharacters && this.m_faction && !(enemyStealth == null);
- }
- protected void UpdateSuspicion(Stealth enemyStealth, float deltaTime, float distanceSq)
- {
- if (!this.ShouldDetectStealthedCharacter(enemyStealth))
- {
- return;
- }
- CharacterStats component = enemyStealth.GetComponent<CharacterStats>();
- if (component == null)
- {
- return;
- }
- Mover component2 = enemyStealth.GetComponent<Mover>();
- if (component2 == null)
- {
- return;
- }
- float stealthSkill = (float)component.CalculateSkill(SkillManager.StealthSkill, null);
- bool flag = false;
- bool flag2 = false;
- float num = this.StealthedCharacterHearingDistance;
- if (distanceSq < num * num)
- {
- float num2 = component2.Radius;
- if (component2.IsMoving)
- {
- deltaTime = Mathf.Max(deltaTime, Time.get_deltaTime());
- }
- if (this.Mover != null)
- {
- num2 += this.Mover.Radius;
- }
- float distancePercent = (Mathf.Sqrt(distanceSq) - num2) / Mathf.Max(num - num2, 1f);
- if (distanceSq - num2 * num2 < 0.45f)
- {
- distancePercent = 0f;
- }
- flag2 = GameUtilities.LineofSight(base.get_transform().get_position(), enemyStealth.get_gameObject());
- flag = true;
- if (flag2 && this.m_faction != null)
- {
- float value = AIController.CalculateSuspicion(deltaTime, distancePercent, (float)SkillManager.StealthSettings.HearingSuspicionRate, stealthSkill, (float)this.m_characterStats.Level);
- enemyStealth.AddSuspicion(base.get_gameObject(), value, this.m_faction.GetRelationship(enemyStealth.get_gameObject()), DetectionType.Hearing);
- this.m_lastDetectingTimestamp[2] = Time.get_realtimeSinceStartup();
- flag2 = true;
- }
- }
- num = this.StealthedCharacterVisionDistance;
- if (distanceSq < num * num)
- {
- Vector3 vector = enemyStealth.get_transform().get_position() - base.get_transform().get_position();
- float num3 = Vector3.Angle(base.get_transform().get_forward(), vector);
- if (num3 < this.StealthedCharacterVisionAngle * 0.5f)
- {
- if (!flag)
- {
- flag2 = GameUtilities.LineofSight(base.get_transform().get_position(), enemyStealth.get_gameObject());
- }
- if (flag2)
- {
- float value2 = AIController.CalculateSuspicion(deltaTime, 1f, (float)SkillManager.StealthSettings.VisionSuspicionRate, stealthSkill, (float)this.m_characterStats.Level);
- enemyStealth.AddSuspicion(base.get_gameObject(), value2, this.m_faction.GetRelationship(enemyStealth.get_gameObject()), DetectionType.Vision);
- this.m_lastDetectingTimestamp[1] = Time.get_realtimeSinceStartup();
- }
- }
- }
- }
- protected float GetLastDetectionTimestamp(DetectionType type)
- {
- return this.m_lastDetectingTimestamp[(int)type];
- }
- protected static float CalculateSuspicion(float deltaTime, float distancePercent, float baseSuspicionRate, float stealthSkill, float creatureLevel)
- {
- if (distancePercent <= 1.401298E-45f)
- {
- return 200f;
- }
- float num = SkillManager.StealthSettings.MaxDistanceMultiplier - SkillManager.StealthSettings.MinDistanceMultiplier;
- float num2 = num * Mathf.Clamp01(distancePercent) + SkillManager.StealthSettings.MinDistanceMultiplier;
- float num3 = baseSuspicionRate * deltaTime * num2;
- float num4 = (stealthSkill - creatureLevel * 0.75f) / Mathf.Max(1f, creatureLevel);
- if (num4 > 0f)
- {
- num4 = Mathf.Min(num4, 1f - SkillManager.StealthSettings.MaxSuspicionStealthDecelerationMultiplier);
- return num3 - num3 * num4;
- }
- num4 = Mathf.Abs(num4);
- if (num4 > SkillManager.StealthSettings.MaxSuspicionStealthAccelerationMultiplier)
- {
- num4 = SkillManager.StealthSettings.MaxSuspicionStealthAccelerationMultiplier;
- }
- return num3 + num3 * num4;
- }
- protected void ClearPerceptionState()
- {
- this.m_previousPerceptionState = false;
- }
- protected void ExecuteOnPerception(GameObject perceivedCharacter, bool isPerceivedCharacterStealthed)
- {
- if (!this.m_previousPerceptionState)
- {
- SpecialCharacterInstanceID.Add(perceivedCharacter, SpecialCharacterInstanceID.SpecialCharacterInstance.Target);
- this.m_previousPerceptionState = true;
- this.OnPerception.Trigger(base.get_gameObject(), perceivedCharacter, isPerceivedCharacterStealthed);
- if (this.m_scriptEvent != null)
- {
- this.m_scriptEvent.ExecuteScript(ScriptEvent.ScriptEvents.OnPerception);
- if (isPerceivedCharacterStealthed)
- {
- this.m_scriptEvent.ExecuteScript(ScriptEvent.ScriptEvents.OnPerceptionOfStealthed);
- }
- else
- {
- this.m_scriptEvent.ExecuteScript(ScriptEvent.ScriptEvents.OnPerceptionOfNonStealthed);
- }
- }
- if (!this.m_perceptionTriggered)
- {
- if (this.m_scriptEvent != null)
- {
- this.m_scriptEvent.ExecuteScript(ScriptEvent.ScriptEvents.OnPerceptionPerLoad);
- }
- this.m_perceptionTriggered = true;
- SingletonBehavior<ChatterManager>.Instance.StartNPCReactiveBarkChatter(ChatterEventType.PartyMemberSpotted, base.get_gameObject());
- }
- SpecialCharacterInstanceID.Remove(SpecialCharacterInstanceID.SpecialCharacterInstance.Target);
- }
- }
- protected void ExecuteOnInvestigate()
- {
- if (this.m_scriptEvent != null)
- {
- this.m_scriptEvent.ExecuteScript(ScriptEvent.ScriptEvents.OnInvestigate);
- }
- }
- protected void ExecuteOnShoutAlert()
- {
- if (this.m_scriptEvent != null)
- {
- this.m_scriptEvent.ExecuteScript(ScriptEvent.ScriptEvents.OnShoutAlert);
- }
- }
- protected void ExecuteOnFriendlyDeathAlert()
- {
- if (this.m_scriptEvent != null)
- {
- this.m_scriptEvent.ExecuteScript(ScriptEvent.ScriptEvents.OnFriendlyDeathAlert);
- }
- }
- protected void EnterCombat(Faction target, AIBehaviorManager.PreparingToActType preparingToActType)
- {
- SingletonBehavior<TacticalModeManager>.Instance.EnterCombat(this);
- if (preparingToActType != AIBehaviorManager.PreparingToActType.HelpRequest)
- {
- if (preparingToActType == AIBehaviorManager.PreparingToActType.PreferredTarget)
- {
- AIBehavior behavior = AIBehaviorManager.AllocatePreparingToActBehaviorWithPreferredTarget(target, target.IsInPlayerFaction);
- if (this.BehaviorStack.PushBehavior(behavior, true))
- {
- this.ShoutToAllies(target.get_gameObject(), this.ShoutRange, false, false, Vector3.get_zero());
- }
- }
- }
- else
- {
- AIBehavior behavior2 = AIBehaviorManager.AllocatePreparingToActBehaviorWithHelpRequest(target.get_gameObject(), target.IsHostileToPlayer());
- this.BehaviorStack.PushBehavior(behavior2, true);
- this.ExecuteOnShoutAlert();
- }
- }
- protected void TrackDamage(GameObject attacker, float damageAmount)
- {
- Faction component = ComponentUtils.GetComponent<Faction>(attacker);
- if (component == null)
- {
- return;
- }
- if (!this.m_damageTracker.ContainsKey(component))
- {
- this.m_damageTracker.Add(component, new List<AIDamageTracker>());
- }
- AIDamageTracker aIDamageTracker = this.m_damageTrackerPool.Allocate();
- aIDamageTracker.Damage = damageAmount;
- aIDamageTracker.Timestamp = SingletonBehavior<TimeController>.Instance.GameTimeSinceStartup;
- this.m_damageTracker[component].Add(aIDamageTracker);
- }
- protected float GetDamageThreatValue(Faction attacker)
- {
- float num = 0f;
- List<AIDamageTracker> list;
- if (this.m_damageTracker.TryGetValue(attacker, out list))
- {
- for (int i = list.Count - 1; i >= 0; i--)
- {
- AIDamageTracker aIDamageTracker = list[i];
- if (aIDamageTracker.Timestamp + GlobalGameSettingsGameData.Instance.ThreatTrackingDuration < SingletonBehavior<TimeController>.Instance.GameTimeSinceStartup)
- {
- list.Remove(aIDamageTracker);
- this.m_damageTrackerPool.Free(aIDamageTracker);
- }
- else
- {
- num += aIDamageTracker.Damage;
- }
- }
- }
- return num;
- }
- protected void CLearTargetTracking()
- {
- foreach (KeyValuePair<Faction, List<AIDamageTracker>> current in this.m_damageTracker)
- {
- List<AIDamageTracker> value = current.Value;
- for (int i = value.Count - 1; i >= 0; i--)
- {
- AIDamageTracker aIDamageTracker = value[i];
- value.Remove(aIDamageTracker);
- this.m_damageTrackerPool.Free(aIDamageTracker);
- }
- }
- this.m_damageTracker.Clear();
- }
- protected virtual Guid GetTypeID()
- {
- return AIController.TypeID;
- }
- protected virtual int GetSaveVersion()
- {
- return 3;
- }
- protected virtual bool ShouldSave()
- {
- return true;
- }
- protected virtual void Save(BinaryWriter writer)
- {
- PersistentUtils.WriteEnum(writer, this.m_persistentAIController.ObsoleteSummonType);
- PersistentUtils.WriteGuid(writer, this.m_persistentAIController.ObsoleteSummonerGuid);
- PersistentUtils.WriteEnum(writer, this.m_persistentAIController.PersistentScriptedBehavior);
- PersistentUtils.WriteGuid(writer, this.m_persistentAIController.PersistentScriptedUseObjectGuid);
- PersistentUtils.WriteBool(writer, this.m_persistentAIController.ScanForTargetsEnabled);
- PersistentUtils.WriteBool(writer, this.m_persistentAIController.IsEmerging);
- PersistentUtils.WriteBool(writer, this.m_persistentAIController.m_IsGuard);
- }
- protected virtual void SaveJson(StringBuilder writer)
- {
- PersistentUtils.WriteJsonEnum(writer, "ObsoleteSummonType", this.m_persistentAIController.ObsoleteSummonType);
- PersistentUtils.WriteJsonComma(writer);
- PersistentUtils.WriteJsonGuid(writer, "ObsoleteSummonerGuid", this.m_persistentAIController.ObsoleteSummonerGuid);
- PersistentUtils.WriteJsonComma(writer);
- PersistentUtils.WriteJsonEnum(writer, "PersistentScriptedBehavior", this.m_persistentAIController.PersistentScriptedBehavior);
- PersistentUtils.WriteJsonComma(writer);
- PersistentUtils.WriteJsonGuid(writer, "PersistentScriptedUseObjectGuid", this.m_persistentAIController.PersistentScriptedUseObjectGuid);
- PersistentUtils.WriteJsonComma(writer);
- PersistentUtils.WriteJsonBool(writer, "ScanForTargetsEnabled", this.m_persistentAIController.ScanForTargetsEnabled);
- PersistentUtils.WriteJsonComma(writer);
- PersistentUtils.WriteJsonBool(writer, "IsEmerging", this.m_persistentAIController.IsEmerging);
- PersistentUtils.WriteJsonComma(writer);
- PersistentUtils.WriteJsonBool(writer, "m_IsGuard", this.m_persistentAIController.m_IsGuard);
- }
- protected virtual void Load(BinaryReader reader, int version)
- {
- this.m_loadVersion = version;
- SaveLoadManager.RegisterIPersistentDataObjectLoaded(this, version);
- switch (this.m_loadVersion)
- {
- case 1:
- this.LoadVersion1(reader);
- break;
- case 2:
- this.LoadVersion2(reader);
- break;
- case 3:
- this.LoadVersion3(reader);
- break;
- default:
- throw new Exception("Invalid version number " + version.ToString() + " passed into AIController.");
- }
- }
- protected virtual void LoadJson(JsonTextReader jsonReader)
- {
- SaveLoadManager.RegisterIPersistentDataObjectLoaded(this, 1);
- }
- protected void LoadVersion3(BinaryReader reader)
- {
- this.m_persistentAIController.Clear();
- this.m_persistentAIController.ObsoleteSummonType = (AISummonType)PersistentUtils.ReadEnum(reader, typeof(AISummonType));
- this.m_persistentAIController.ObsoleteSummonerGuid = PersistentUtils.ReadGuid(reader);
- this.m_persistentAIController.PersistentScriptedBehavior = (ScriptedBehaviorType)PersistentUtils.ReadEnum(reader, typeof(ScriptedBehaviorType));
- this.m_persistentAIController.PersistentScriptedUseObjectGuid = PersistentUtils.ReadGuid(reader);
- this.m_persistentAIController.ScanForTargetsEnabled = PersistentUtils.ReadBool(reader);
- this.m_persistentAIController.IsEmerging = PersistentUtils.ReadBool(reader);
- this.m_persistentAIController.m_IsGuard = PersistentUtils.ReadBool(reader);
- }
- protected void LoadVersion2(BinaryReader reader)
- {
- this.m_persistentAIController.Clear();
- this.m_persistentAIController.ObsoleteSummonType = (AISummonType)PersistentUtils.ReadEnum(reader, typeof(AISummonType));
- this.m_persistentAIController.ObsoleteSummonerGuid = PersistentUtils.ReadGuid(reader);
- this.m_persistentAIController.PersistentScriptedBehavior = (ScriptedBehaviorType)PersistentUtils.ReadEnum(reader, typeof(ScriptedBehaviorType));
- this.m_persistentAIController.PersistentScriptedUseObjectGuid = PersistentUtils.ReadGuid(reader);
- this.m_persistentAIController.ScanForTargetsEnabled = PersistentUtils.ReadBool(reader);
- this.m_persistentAIController.IsEmerging = PersistentUtils.ReadBool(reader);
- }
- protected void LoadVersion1(BinaryReader reader)
- {
- this.m_persistentAIController.Clear();
- this.m_persistentAIController.ObsoleteSummonType = (AISummonType)PersistentUtils.ReadEnum(reader, typeof(AISummonType));
- this.m_persistentAIController.ObsoleteSummonerGuid = PersistentUtils.ReadGuid(reader);
- this.m_persistentAIController.PersistentScriptedBehavior = (ScriptedBehaviorType)PersistentUtils.ReadEnum(reader, typeof(ScriptedBehaviorType));
- this.m_persistentAIController.PersistentScriptedUseObjectGuid = PersistentUtils.ReadGuid(reader);
- this.m_persistentAIController.ScanForTargetsEnabled = PersistentUtils.ReadBool(reader);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement