Advertisement
Guest User

AIController.cs

a guest
Mar 2nd, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 154.75 KB | None | 0 0
  1. using Game.AI;
  2. using Game.GameData;
  3. using Game.TacticalMode;
  4. using Game.UI;
  5. using Newtonsoft.Json;
  6. using OEIFormats;
  7. using Onyx;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Collections.ObjectModel;
  11. using System.Diagnostics;
  12. using System.IO;
  13. using System.Runtime.CompilerServices;
  14. using System.Text;
  15. using System.Threading;
  16. using UnityEngine;
  17. using UnityEngine.Serialization;
  18.  
  19. namespace Game
  20. {
  21.     [ScriptEventType(new ScriptEvent.ScriptEvents[]
  22.     {
  23.         ScriptEvent.ScriptEvents.OnPerceptionPerLoad,
  24.         ScriptEvent.ScriptEvents.OnPerception,
  25.         ScriptEvent.ScriptEvents.OnPerceptionOfStealthed,
  26.         ScriptEvent.ScriptEvents.OnPerceptionOfNonStealthed,
  27.         ScriptEvent.ScriptEvents.OnInvestigate,
  28.         ScriptEvent.ScriptEvents.OnShoutAlert,
  29.         ScriptEvent.ScriptEvents.OnFriendlyDeathAlert,
  30.         ScriptEvent.ScriptEvents.OnScriptedMoveComplete
  31.     }), RequireComponent(typeof(Mover)), RequireComponent(typeof(Mover)), RequireComponent(typeof(Mover))]
  32.     [Serializable]
  33.     public class AIController : OnyxBehavior, IGameDataOwner, IPersistentData, IPersistentDataJson
  34.     {
  35.         public enum WeatherReactionType
  36.         {
  37.             None,
  38.             SeekCover,
  39.             LeaveCover
  40.         }
  41.  
  42.         public class KiteTarget
  43.         {
  44.             public Faction m_target;
  45.  
  46.             public float m_ignoreTimer;
  47.  
  48.             public float m_ignoreDuration;
  49.  
  50.             protected Faction Target
  51.             {
  52.                 get
  53.                 {
  54.                     return this.m_target;
  55.                 }
  56.             }
  57.  
  58.             protected bool IsIgnoreTimeComplete
  59.             {
  60.                 get
  61.                 {
  62.                     return this.m_ignoreTimer >= this.m_ignoreDuration;
  63.                 }
  64.             }
  65.  
  66.             protected KiteTarget(Faction target)
  67.             {
  68.                 this.m_target = target;
  69.                 this.m_ignoreDuration = GlobalGameSettingsGameData.Instance.KiteTargetIgnoreDuration;
  70.             }
  71.  
  72.             protected void Update(float deltaTime)
  73.             {
  74.                 this.m_ignoreTimer += deltaTime;
  75.             }
  76.         }
  77.  
  78.         [Serializable]
  79.         public class ScheduleInteractionObjectSet
  80.         {
  81.             [Serializable]
  82.             public class TimeSliceInteractionObject
  83.             {
  84.                 [Tooltip("The guid string of the object to interact with for this time slice.")]
  85.                 public string InteractionObjectGuidString = string.Empty;
  86.  
  87.                 [Tooltip("The maximum time in hours a character can randomly wait before changing time slices.")]
  88.                 public float StartTransitionDelay = 0.25f;
  89.  
  90.                 [Tooltip("Whether the character can react to weather during this time slice.")]
  91.                 public bool ReactToWeather = true;
  92.  
  93.                 public string InteractionObjectDebugName = string.Empty;
  94.  
  95.                 public string InteractionObjectDebugSceneName = string.Empty;
  96.  
  97.                 public GameObject m_interactionObject;
  98.  
  99.                 public Guid m_interactionObjectGuid = Guid.Empty;
  100.  
  101.                 protected GameObject InteractionObject
  102.                 {
  103.                     get
  104.                     {
  105.                         this.CacheInteractionObject();
  106.                         return this.m_interactionObject;
  107.                     }
  108.                 }
  109.  
  110.                 protected Guid InteractionObjectGuid
  111.                 {
  112.                     get
  113.                     {
  114.                         if (this.m_interactionObjectGuid == Guid.Empty && !string.IsNullOrEmpty(this.InteractionObjectGuidString))
  115.                         {
  116.                             this.m_interactionObjectGuid = ScriptManager.StringToGuid(this.InteractionObjectGuidString);
  117.                         }
  118.                         return this.m_interactionObjectGuid;
  119.                     }
  120.                 }
  121.  
  122.                 protected TimeSliceInteractionObject()
  123.                 {
  124.                 }
  125.  
  126.                 protected void CacheInteractionObject()
  127.                 {
  128.                     if (this.m_interactionObject == null && !string.IsNullOrEmpty(this.InteractionObjectGuidString))
  129.                     {
  130.                         this.m_interactionObject = InstanceID.GetObjectByID(ScriptManager.StringToGuid(this.InteractionObjectGuidString));
  131.                     }
  132.                 }
  133.             }
  134.  
  135.             public AIController.ScheduleInteractionObjectSet.TimeSliceInteractionObject[] InteractionObjects = new AIController.ScheduleInteractionObjectSet.TimeSliceInteractionObject[20];
  136.  
  137.             protected ScheduleInteractionObjectSet()
  138.             {
  139.             }
  140.         }
  141.  
  142.         public class CombatParams
  143.         {
  144.             public Faction Target;
  145.  
  146.             public AIBehaviorManager.PreparingToActType PreparingToActType;
  147.  
  148.             public float WaitDuration;
  149.  
  150.             protected bool IsPendingCombat
  151.             {
  152.                 get
  153.                 {
  154.                     return this.Target != null;
  155.                 }
  156.             }
  157.  
  158.             protected bool IsTime
  159.             {
  160.                 get
  161.                 {
  162.                     return this.WaitDuration <= 0f;
  163.                 }
  164.             }
  165.  
  166.             protected CombatParams()
  167.             {
  168.             }
  169.  
  170.             protected void SetTarget(Faction target, AIBehaviorManager.PreparingToActType type)
  171.             {
  172.                 this.Target = target;
  173.                 this.PreparingToActType = type;
  174.                 this.WaitDuration = OEIRandom.RangeInclusive(GlobalGameSettingsGameData.Instance.TargetScanMinimumCombatDelay, GlobalGameSettingsGameData.Instance.TargetScanMaximumCombatDelay);
  175.             }
  176.  
  177.             protected void Update()
  178.             {
  179.                 this.WaitDuration -= Time.get_deltaTime();
  180.             }
  181.  
  182.             protected void Reset()
  183.             {
  184.                 this.Target = null;
  185.                 this.PreparingToActType = AIBehaviorManager.PreparingToActType.None;
  186.                 this.WaitDuration = 0f;
  187.             }
  188.         }
  189.  
  190.         public delegate void SummonEvent(GameObject sender, EventArgs args);
  191.  
  192.         public enum DebugMode
  193.         {
  194.             None,
  195.             MouseOver,
  196.             All,
  197.             Shout
  198.         }
  199.  
  200.         public class ObjectsWithLifetime : IEquatable<AIController.ObjectsWithLifetime>
  201.         {
  202.             public AIController Obj;
  203.  
  204.             public float Lifetime;
  205.  
  206.             protected bool Expired
  207.             {
  208.                 get
  209.                 {
  210.                     return this.Lifetime <= 0f;
  211.                 }
  212.             }
  213.  
  214.             protected ObjectsWithLifetime(AIController obj, float lifetime)
  215.             {
  216.                 this.Obj = obj;
  217.                 this.Lifetime = lifetime;
  218.             }
  219.  
  220.             protected void Update()
  221.             {
  222.                 this.Lifetime -= Time.get_deltaTime();
  223.             }
  224.  
  225.             protected bool Equals(AIController.ObjectsWithLifetime other)
  226.             {
  227.                 return other != null && other.Obj.Equals(this.Obj);
  228.             }
  229.  
  230.             protected override bool Equals(object obj)
  231.             {
  232.                 return this.Obj.Equals(obj);
  233.             }
  234.  
  235.             protected override int GetHashCode()
  236.             {
  237.                 return this.Obj.GetHashCode();
  238.             }
  239.         }
  240.  
  241.         public class DisengagementTracker
  242.         {
  243.             public AIController Enemy;
  244.  
  245.             public float WaitDuration;
  246.  
  247.             protected DisengagementTracker(AIController enemy)
  248.             {
  249.                 this.Enemy = enemy;
  250.                 this.WaitDuration = 0f;
  251.             }
  252.         }
  253.  
  254.         [Serializable]
  255.         public class PersistentData
  256.         {
  257.             [NonSerialized]
  258.             public AISummonType ObsoleteSummonType;
  259.  
  260.             [NonSerialized]
  261.             public Guid ObsoleteSummonerGuid = new Guid("00000000-0000-0000-0000-000000000000");
  262.  
  263.             [NonSerialized]
  264.             public ScriptedBehaviorType PersistentScriptedBehavior;
  265.  
  266.             [NonSerialized]
  267.             public Guid PersistentScriptedUseObjectGuid = new Guid("00000000-0000-0000-0000-000000000000");
  268.  
  269.             [NonSerialized]
  270.             public bool ScanForTargetsEnabled = true;
  271.  
  272.             [NonSerialized]
  273.             public bool IsEmerging;
  274.  
  275.             public bool m_IsGuard;
  276.  
  277.             protected PersistentData()
  278.             {
  279.             }
  280.  
  281.             protected void Clear()
  282.             {
  283.                 this.ObsoleteSummonType = AISummonType.NotSummoned;
  284.                 this.ObsoleteSummonerGuid = new Guid("00000000-0000-0000-0000-000000000000");
  285.                 this.PersistentScriptedBehavior = ScriptedBehaviorType.None;
  286.                 this.PersistentScriptedUseObjectGuid = new Guid("00000000-0000-0000-0000-000000000000");
  287.                 this.ScanForTargetsEnabled = true;
  288.                 this.IsEmerging = false;
  289.                 this.m_IsGuard = false;
  290.             }
  291.         }
  292.  
  293.         public static List<AIController> s_activeControllers = new List<AIController>();
  294.  
  295.         public static ReadOnlyCollection<AIController> s_activeControllersReadOnly;
  296.  
  297.         public const int MaxScheduleTimeSlices = 20;
  298.  
  299.         public const float MaxArrivalDistance = 10000f;
  300.  
  301.         [Tooltip("The default behavior of the NPC when not in combat.")]
  302.         public AIBehaviorManager.DefaultAIBehaviorType AIBehavior;
  303.  
  304.         [SerializeField, Tooltip("The file containing the actions to perform when in combat (in addition to progression table decision trees).")]
  305.         public AIDecisionTreeReference[] m_decisionTreeReferences = new AIDecisionTreeReference[0];
  306.  
  307.         public List<AIDecisionTreeData> m_decisionTrees = new List<AIDecisionTreeData>();
  308.  
  309.         [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.")]
  310.         public AIDecisionTreeSelectionType DecisionTreeSelectionOverride = AIDecisionTreeSelectionType.RoundRobin;
  311.  
  312.         public Guid LastDecisionTreeToRunAction = Guid.Empty;
  313.  
  314.         [Tooltip("The AI schedule containing the time slices for interacting with objects.")]
  315.         public ScheduleGameDataReference ScheduleReference = new ScheduleGameDataReference();
  316.  
  317.         [Tooltip("A list of objects for the character to interact with while following a schedule.")]
  318.         public AIController.ScheduleInteractionObjectSet ScheduleInteractionObjects = new AIController.ScheduleInteractionObjectSet();
  319.  
  320.         [Tooltip("If AI Behavior is set to \"Follow\", the character to follow.")]
  321.         public GameObject FollowObject;
  322.  
  323.         [Tooltip("The type of weapon to use in an idle situation.")]
  324.         public WeaponPreferenceType WeaponPreference;
  325.  
  326.         [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.")]
  327.         public ScriptedBehaviorType ScriptedBehavior;
  328.  
  329.         [Tooltip("The object to interact with when the Scripted Behavior is set to Use Scripted Object.")]
  330.         public GameObject ScriptedUseObject;
  331.  
  332.         [ReadOnlyProperty, FormerlySerializedAs("ShoutRange"), SerializeField, Tooltip("(NOTE: Currently ignored value!) When issuing a request for help in combat, alert allies within this distance.")]
  333.         public float m_shoutRange = 9f;
  334.  
  335.         [FormerlySerializedAs("DetectsStealthedCharacters"), SerializeField, Tooltip("If checked, this NPC can see party members who are stealthed.")]
  336.         public bool m_detectsStealthedCharactersSetting = true;
  337.  
  338.         [Obsolete("Use IsGuard instead. Only for data backwards-compat."), HideInInspector, SerializeField, Tooltip("Designates this character to have a 'guard' indicator above their head.")]
  339.         public bool m_isGuard;
  340.  
  341.         [Tooltip("When true, the character must die for combat to end.")]
  342.         public bool CombatEndsOnDeath;
  343.  
  344.         [Tooltip("If true, the character will try to stay near his original start position when not patrolling.")]
  345.         public bool Tethered = true;
  346.  
  347.         [Tooltip("NPCs who are tethered will try to stay within this distance of their start location.")]
  348.         public float TetherDistance = 30f;
  349.  
  350.         [HideInInspector]
  351.         public AIBehaviorStack BehaviorStack = new AIBehaviorStack();
  352.  
  353.         [HideInInspector]
  354.         public ModalStack ModalStack = new ModalStack();
  355.  
  356.         [HideInInspector]
  357.         public bool OverrideSummonBehvaior;
  358.  
  359.         public bool HideOffscreenMeshes;
  360.  
  361.         public CharacterStats m_characterStats;
  362.  
  363.         public Health m_health;
  364.  
  365.         public Faction m_faction;
  366.  
  367.         public AnimationController m_animController;
  368.  
  369.         public Mover m_mover;
  370.  
  371.         public Equipment m_equipment;
  372.  
  373.         public Townie m_townie;
  374.  
  375.         public WorldMapAIController m_shipController;
  376.  
  377.         public PartyMember m_partyMember;
  378.  
  379.         public AISchedule m_aiSchedule = new AISchedule();
  380.  
  381.         public AITownieSchedule m_aiTownieSchedule;
  382.  
  383.         public Dictionary<Guid, ActionCooldown[]> m_cooldowns;
  384.  
  385.         public bool m_isFogVisible;
  386.  
  387.         public AlphaControl m_alphaControl;
  388.  
  389.         public float m_desiredAlpha = 1f;
  390.  
  391.         public bool m_hasNotifiedAttackingSameTargetAsAlly;
  392.  
  393.         public float m_sameTargetCheckTimer;
  394.  
  395.         public float m_primaryAttackReevaluationTimer;
  396.  
  397.         [DebuggerBrowsable(DebuggerBrowsableState.Never), CompilerGenerated]
  398.         public Action<GameObject, bool> OnAttackingSameTargetAsAllyStateChange;
  399.  
  400.         public ScriptEvent m_scriptEvent;
  401.  
  402.         public List<GameObject> m_summonedCreatures = new List<GameObject>();
  403.  
  404.         [DebuggerBrowsable(DebuggerBrowsableState.Never), CompilerGenerated]
  405.         public AIController.SummonEvent OnSummonsChanged;
  406.  
  407.         public OnyxEvent<int> OnConversationAnimation = new OnyxEvent<int>();
  408.  
  409.         public OnyxEvent<FlowChartPlayer, GameObject> OnConversationPauseState = new OnyxEvent<FlowChartPlayer, GameObject>();
  410.  
  411.         public Vector3 m_retreatPosition = Vector3.get_zero();
  412.  
  413.         public List<AIController.KiteTarget> m_kiteTargets = new List<AIController.KiteTarget>(0);
  414.  
  415.         public GameObject m_highestDamageInflictor;
  416.  
  417.         public float m_highestDamageInflicted;
  418.  
  419.         public bool m_ignoreAsCutsceneObstacle;
  420.  
  421.         public bool m_inCutscene;
  422.  
  423.         public Encounter m_parentEncounter;
  424.  
  425.         public bool m_mustDieForCombatToEnd;
  426.  
  427.         public AttackBase m_previousAttack;
  428.  
  429.         public float m_holdTimer;
  430.  
  431.         public bool m_holdMove;
  432.  
  433.         public bool m_unsetEmergeFlags;
  434.  
  435.         public bool m_detectsStealthedCharacters = true;
  436.  
  437.         public const float DefendMyselfMeleeSearchDistance = 3f;
  438.  
  439.         public const float DefendMyselfRangedSearchDistance = 6f;
  440.  
  441.         public const float DefensiveMeleeSearchDistance = 6f;
  442.  
  443.         public const float DefensiveRangedSearchDistance = 9f;
  444.  
  445.         public const float AggressiveSearchDistance = 20f;
  446.  
  447.         public bool m_hasShoutedForHelp;
  448.  
  449.         public bool m_hasBeenInitialized;
  450.  
  451.         public bool m_isBusy;
  452.  
  453.         public OnyxEvent<AIController> OnTurnStart = new OnyxEvent<AIController>();
  454.  
  455.         public OnyxEvent<AIController> OnTurnEnd = new OnyxEvent<AIController>();
  456.  
  457.         public OnyxEvent<TimeType, float> OnTimeElapsed = new OnyxEvent<TimeType, float>();
  458.  
  459.         public bool m_availableAction;
  460.  
  461.         public float m_availableMovement;
  462.  
  463.         public ReadOnlyCollection<GameObject> m_summonedCreaturesReadOnly;
  464.  
  465.         public bool m_shouldReactToWeatherAfterDelay;
  466.  
  467.         public AIController.WeatherReactionType m_weatherReactionType;
  468.  
  469.         public float m_weatherReactionDelay;
  470.  
  471.         public float m_weatherReactionTimer;
  472.  
  473.         public static AIController.DebugMode m_debugMode = AIController.DebugMode.None;
  474.  
  475.         public float m_debugShoutTimer;
  476.  
  477.         public bool m_debugShoutOrigin;
  478.  
  479.         public static bool DebugEngagement = false;
  480.  
  481.         public int m_cachedEngagementLimit;
  482.  
  483.         public List<AIController> m_engagedEnemies = new List<AIController>();
  484.  
  485.         public List<AIController> m_engagedBy = new List<AIController>();
  486.  
  487.         public List<AIController> m_threatenedEnemies = new List<AIController>();
  488.  
  489.         public List<AIController> m_threatenedBy = new List<AIController>();
  490.  
  491.         public ReadOnlyCollection<AIController> m_engagedEnemiesReadOnly;
  492.  
  493.         public ReadOnlyCollection<AIController> m_engagedByReadOnly;
  494.  
  495.         public ReadOnlyCollection<AIController> m_threatenedEnemiesReadOnly;
  496.  
  497.         public ReadOnlyCollection<AIController> m_threatenedByReadOnly;
  498.  
  499.         public bool m_engagementDisabled;
  500.  
  501.         public List<AIController.ObjectsWithLifetime> m_trackedObjectList = new List<AIController.ObjectsWithLifetime>();
  502.  
  503.         public List<AIController.DisengagementTracker> m_disengagementTrackers = new List<AIController.DisengagementTracker>();
  504.  
  505.         public const float ScanInterval = 1f;
  506.  
  507.         public float m_scanWaitDuration;
  508.  
  509.         public bool m_trackingSuspicion;
  510.  
  511.         public float m_suspicionDeltaTime;
  512.  
  513.         public bool m_forcePerceptionChecks;
  514.  
  515.         public bool m_previousPerceptionState;
  516.  
  517.         public bool m_perceptionTriggered;
  518.  
  519.         public AIController.CombatParams m_delayedCombatParams = new AIController.CombatParams();
  520.  
  521.         public float[] m_lastDetectingTimestamp = new float[3];
  522.  
  523.         public OnyxEvent<GameObject, GameObject, bool> OnPerception = new OnyxEvent<GameObject, GameObject, bool>();
  524.  
  525.         public ObjectPool<AIDamageTracker> m_damageTrackerPool = new ObjectPool<AIDamageTracker>(64);
  526.  
  527.         public Dictionary<Faction, List<AIDamageTracker>> m_damageTracker = new Dictionary<Faction, List<AIDamageTracker>>();
  528.  
  529.         public static Guid TypeID = new Guid("ff6a7e96-e229-4589-afab-cb71a7012c6f");
  530.  
  531.         public const int SaveVersion = 3;
  532.  
  533.         [NonSerialized]
  534.         public int m_loadVersion;
  535.  
  536.         [SerializeField]
  537.         public AIController.PersistentData m_persistentAIController = new AIController.PersistentData();
  538.  
  539.         protected event Action<GameObject, bool> OnAttackingSameTargetAsAllyStateChangeEvent
  540.         {
  541.             add
  542.             {
  543.                 Action<GameObject, bool> action = this.OnAttackingSameTargetAsAllyStateChange;
  544.                 Action<GameObject, bool> action2;
  545.                 do
  546.                 {
  547.                     action2 = action;
  548.                     action = Interlocked.CompareExchange<Action<GameObject, bool>>(ref this.OnAttackingSameTargetAsAllyStateChange, (Action<GameObject, bool>)Delegate.Combine(action2, value), action);
  549.                 }
  550.                 while (action != action2);
  551.             }
  552.             remove
  553.             {
  554.                 Action<GameObject, bool> action = this.OnAttackingSameTargetAsAllyStateChange;
  555.                 Action<GameObject, bool> action2;
  556.                 do
  557.                 {
  558.                     action2 = action;
  559.                     action = Interlocked.CompareExchange<Action<GameObject, bool>>(ref this.OnAttackingSameTargetAsAllyStateChange, (Action<GameObject, bool>)Delegate.Remove(action2, value), action);
  560.                 }
  561.                 while (action != action2);
  562.             }
  563.         }
  564.  
  565.         protected event AIController.SummonEvent OnSummonsChangedEvent
  566.         {
  567.             add
  568.             {
  569.                 AIController.SummonEvent summonEvent = this.OnSummonsChanged;
  570.                 AIController.SummonEvent summonEvent2;
  571.                 do
  572.                 {
  573.                     summonEvent2 = summonEvent;
  574.                     summonEvent = Interlocked.CompareExchange<AIController.SummonEvent>(ref this.OnSummonsChanged, (AIController.SummonEvent)Delegate.Combine(summonEvent2, value), summonEvent);
  575.                 }
  576.                 while (summonEvent != summonEvent2);
  577.             }
  578.             remove
  579.             {
  580.                 AIController.SummonEvent summonEvent = this.OnSummonsChanged;
  581.                 AIController.SummonEvent summonEvent2;
  582.                 do
  583.                 {
  584.                     summonEvent2 = summonEvent;
  585.                     summonEvent = Interlocked.CompareExchange<AIController.SummonEvent>(ref this.OnSummonsChanged, (AIController.SummonEvent)Delegate.Remove(summonEvent2, value), summonEvent);
  586.                 }
  587.                 while (summonEvent != summonEvent2);
  588.             }
  589.         }
  590.  
  591.         protected static ReadOnlyCollection<AIController> ActiveControllers
  592.         {
  593.             get
  594.             {
  595.                 if (AIController.s_activeControllersReadOnly == null)
  596.                 {
  597.                     AIController.s_activeControllersReadOnly = new ReadOnlyCollection<AIController>(AIController.s_activeControllers);
  598.                 }
  599.                 return AIController.s_activeControllersReadOnly;
  600.             }
  601.         }
  602.  
  603.         protected List<AIDecisionTreeData> DecisionTrees
  604.         {
  605.             get
  606.             {
  607.                 return this.m_decisionTrees;
  608.             }
  609.         }
  610.  
  611.         protected float ShoutRange
  612.         {
  613.             get
  614.             {
  615.                 return 15f;
  616.             }
  617.         }
  618.  
  619.         protected SummonedCharacter SummonedCharacter
  620.         {
  621.             get;
  622.             set;
  623.         }
  624.  
  625.         protected bool HasRealEnemyNearby
  626.         {
  627.             get;
  628.             set;
  629.         }
  630.  
  631.         protected Vector3 RetreatPosition
  632.         {
  633.             get
  634.             {
  635.                 return this.m_retreatPosition;
  636.             }
  637.         }
  638.  
  639.         protected bool InCutscene
  640.         {
  641.             get
  642.             {
  643.                 return this.m_inCutscene;
  644.             }
  645.             set
  646.             {
  647.                 this.m_inCutscene = value;
  648.             }
  649.         }
  650.  
  651.         protected bool InCastIntro
  652.         {
  653.             get
  654.             {
  655.                 return this.BehaviorStack.CurrentBehavior != null && (this.BehaviorStack.CurrentBehavior.CurrentState is CastIntroState || this.BehaviorStack.CurrentBehavior.CurrentState is GrappleIntroState);
  656.             }
  657.         }
  658.  
  659.         protected bool DetectsStealthedCharacters
  660.         {
  661.             get
  662.             {
  663.                 return this.m_detectsStealthedCharacters && this.m_detectsStealthedCharactersSetting;
  664.             }
  665.             set
  666.             {
  667.                 this.m_detectsStealthedCharacters = value;
  668.             }
  669.         }
  670.  
  671.         protected bool IsGuard
  672.         {
  673.             get
  674.             {
  675.                 return this.m_IsGuard;
  676.             }
  677.             set
  678.             {
  679.                 this.m_IsGuard = value;
  680.                 if (this.IsGuard)
  681.                 {
  682.                     UIInvestigateManager.ShowIcon(base.get_gameObject(), UIInvestigateIndicator.IconType.Guard, 1f);
  683.                 }
  684.             }
  685.         }
  686.  
  687.         protected bool HideStealthViewElements
  688.         {
  689.             get;
  690.             set;
  691.         }
  692.  
  693.         protected int TacticalTurnEventCount
  694.         {
  695.             get;
  696.             set;
  697.         }
  698.  
  699.         protected bool IsInTacticalCombat
  700.         {
  701.             get
  702.             {
  703.                 return this.TacticalTurnEventCount > 0;
  704.             }
  705.         }
  706.  
  707.         protected bool AvailableAction
  708.         {
  709.             get
  710.             {
  711.                 return this.m_availableAction;
  712.             }
  713.             set
  714.             {
  715.                 if (SingletonBehavior<TacticalModeManager>.Instance.UnlimitedActions && SingletonBehavior<PartyManager>.Instance.IsActivePartyMember(this.m_partyMember) && this.m_partyMember.IsControllable)
  716.                 {
  717.                     this.m_availableAction = true;
  718.                 }
  719.                 else
  720.                 {
  721.                     this.m_availableAction = value;
  722.                 }
  723.                 this.CheckEndTurn();
  724.             }
  725.         }
  726.  
  727.         protected float AvailableMovement
  728.         {
  729.             get
  730.             {
  731.                 return this.m_availableMovement;
  732.             }
  733.             set
  734.             {
  735.                 if (SingletonBehavior<TacticalModeManager>.Instance.UnlimitedMovement && SingletonBehavior<PartyManager>.Instance.IsActivePartyMember(this.m_partyMember) && this.m_partyMember.IsControllable)
  736.                 {
  737.                     this.m_availableMovement = Mathf.Max(this.m_availableMovement, value);
  738.                 }
  739.                 else
  740.                 {
  741.                     this.m_availableMovement = value;
  742.                 }
  743.                 this.CheckEndTurn();
  744.             }
  745.         }
  746.  
  747.         protected float AvailableMoveDistance
  748.         {
  749.             get
  750.             {
  751.                 this.Mover.CalculateDesiredSpeed();
  752.                 return this.AvailableMovement * this.Mover.DesiredSpeed;
  753.             }
  754.         }
  755.  
  756.         protected float CachedAvailableMoveDistance
  757.         {
  758.             get;
  759.             set;
  760.         }
  761.  
  762.         protected float ProjectedMoveDistance
  763.         {
  764.             get
  765.             {
  766.                 return this.Mover.PathDistance;
  767.             }
  768.         }
  769.  
  770.         protected CharacterStats CharacterStats
  771.         {
  772.             get
  773.             {
  774.                 return this.m_characterStats;
  775.             }
  776.         }
  777.  
  778.         protected PartyMember PartyMember
  779.         {
  780.             get
  781.             {
  782.                 return this.m_partyMember;
  783.             }
  784.         }
  785.  
  786.         protected Faction Faction
  787.         {
  788.             get
  789.             {
  790.                 return this.m_faction;
  791.             }
  792.         }
  793.  
  794.         protected Equipment Equipment
  795.         {
  796.             get
  797.             {
  798.                 return this.m_equipment;
  799.             }
  800.         }
  801.  
  802.         protected AISchedule AISchedule
  803.         {
  804.             get
  805.             {
  806.                 return this.m_aiSchedule;
  807.             }
  808.         }
  809.  
  810.         protected AITownieSchedule AITownieSchedule
  811.         {
  812.             get
  813.             {
  814.                 return this.m_aiTownieSchedule;
  815.             }
  816.         }
  817.  
  818.         protected Dictionary<Guid, ActionCooldown[]> Cooldowns
  819.         {
  820.             get
  821.             {
  822.                 return this.m_cooldowns;
  823.             }
  824.         }
  825.  
  826.         protected bool IsFogVisible
  827.         {
  828.             get
  829.             {
  830.                 return this.m_isFogVisible;
  831.             }
  832.         }
  833.  
  834.         protected float DesiredAlpha
  835.         {
  836.             get
  837.             {
  838.                 return this.m_desiredAlpha;
  839.             }
  840.         }
  841.  
  842.         protected bool IsTimeToReevaluatePrimaryAttack
  843.         {
  844.             get
  845.             {
  846.                 return this.m_primaryAttackReevaluationTimer <= 0f;
  847.             }
  848.         }
  849.  
  850.         protected AIController GrappleTarget
  851.         {
  852.             get;
  853.             set;
  854.         }
  855.  
  856.         protected Mover Mover
  857.         {
  858.             get
  859.             {
  860.                 if (this.m_mover == null)
  861.                 {
  862.                     this.m_mover = base.GetComponent<Mover>();
  863.                     if (this.m_mover == null)
  864.                     {
  865.                         this.m_mover = ResourceManager.AddComponent<Mover>(base.get_gameObject());
  866.                     }
  867.                 }
  868.                 return this.m_mover;
  869.             }
  870.         }
  871.  
  872.         protected Health Health
  873.         {
  874.             get
  875.             {
  876.                 return this.m_health;
  877.             }
  878.         }
  879.  
  880.         protected bool IsTownie
  881.         {
  882.             get
  883.             {
  884.                 return this.m_townie != null;
  885.             }
  886.         }
  887.  
  888.         protected bool IsTownieReacting
  889.         {
  890.             get
  891.             {
  892.                 return this.m_townie != null && this.m_townie.IsReacting;
  893.             }
  894.         }
  895.  
  896.         protected GameObject HighestDamageInflictor
  897.         {
  898.             get
  899.             {
  900.                 return this.m_highestDamageInflictor;
  901.             }
  902.         }
  903.  
  904.         protected bool MustDieForCombatToEnd
  905.         {
  906.             get
  907.             {
  908.                 return this.m_mustDieForCombatToEnd;
  909.             }
  910.             set
  911.             {
  912.                 this.m_mustDieForCombatToEnd = value;
  913.                 if (this.m_mustDieForCombatToEnd)
  914.                 {
  915.                     this.MarkSummonsMustDieForCombatToEnd();
  916.                 }
  917.             }
  918.         }
  919.  
  920.         protected bool IsInvisible
  921.         {
  922.             get
  923.             {
  924.                 return this.m_desiredAlpha <= 1.401298E-45f || (this.m_characterStats != null && this.m_characterStats.IsInvisible(false));
  925.             }
  926.         }
  927.  
  928.         protected bool IgnoreAsCutsceneObstacle
  929.         {
  930.             get
  931.             {
  932.                 return this.m_ignoreAsCutsceneObstacle;
  933.             }
  934.             set
  935.             {
  936.                 this.m_ignoreAsCutsceneObstacle = value;
  937.             }
  938.         }
  939.  
  940.         protected bool IsBusy
  941.         {
  942.             get
  943.             {
  944.                 return this.m_isBusy;
  945.             }
  946.             set
  947.             {
  948.                 this.m_isBusy = value;
  949.             }
  950.         }
  951.  
  952.         protected bool IsLurking
  953.         {
  954.             get
  955.             {
  956.                 return this.BehaviorStack != null && this.BehaviorStack.CurrentBehavior != null && this.BehaviorStack.CurrentBehavior.CurrentState is EmergeLurkState;
  957.             }
  958.         }
  959.  
  960.         protected bool IsHoldingPosition
  961.         {
  962.             get
  963.             {
  964.                 return this.m_holdMove || this.m_holdTimer > 0f;
  965.             }
  966.         }
  967.  
  968.         protected bool IsFaded
  969.         {
  970.             get
  971.             {
  972.                 return this.m_alphaControl != null && this.m_alphaControl.IsFaded;
  973.             }
  974.         }
  975.  
  976.         protected ReadOnlyCollection<GameObject> SummonedCreatureList
  977.         {
  978.             get
  979.             {
  980.                 if (this.m_summonedCreaturesReadOnly == null)
  981.                 {
  982.                     this.m_summonedCreaturesReadOnly = new ReadOnlyCollection<GameObject>(this.m_summonedCreatures);
  983.                 }
  984.                 return this.m_summonedCreaturesReadOnly;
  985.             }
  986.         }
  987.  
  988.         protected virtual float StealthedCharacterHearingDistance
  989.         {
  990.             get
  991.             {
  992.                 if (!base.get_gameObject().get_activeInHierarchy() || (this.m_health != null && this.m_health.IsDeadOrUnconscious))
  993.                 {
  994.                     return 0f;
  995.                 }
  996.                 if (this.m_characterStats == null)
  997.                 {
  998.                     return 5f;
  999.                 }
  1000.                 return this.m_characterStats.StealthedCharacerHearingDistance;
  1001.             }
  1002.         }
  1003.  
  1004.         protected virtual float StealthedCharacterVisionDistance
  1005.         {
  1006.             get
  1007.             {
  1008.                 if (!base.get_gameObject().get_activeInHierarchy() || (this.m_health != null && this.m_health.IsDeadOrUnconscious))
  1009.                 {
  1010.                     return 0f;
  1011.                 }
  1012.                 if (this.m_characterStats == null)
  1013.                 {
  1014.                     return 10f;
  1015.                 }
  1016.                 return this.m_characterStats.StealthedCharacterVisionDistance;
  1017.             }
  1018.         }
  1019.  
  1020.         protected virtual float StealthedCharacterVisionAngle
  1021.         {
  1022.             get
  1023.             {
  1024.                 if (!base.get_gameObject().get_activeInHierarchy() || (this.m_health != null && this.m_health.IsDeadOrUnconscious))
  1025.                 {
  1026.                     return 0f;
  1027.                 }
  1028.                 if (this.m_characterStats == null)
  1029.                 {
  1030.                     return 30f;
  1031.                 }
  1032.                 return this.m_characterStats.StealthedCharacterVisionAngle;
  1033.             }
  1034.         }
  1035.  
  1036.         protected virtual float PerceptionDistance
  1037.         {
  1038.             get
  1039.             {
  1040.                 if (!base.get_gameObject().get_activeInHierarchy() || (this.m_health != null && this.m_health.IsDeadOrUnconscious))
  1041.                 {
  1042.                     return 0f;
  1043.                 }
  1044.                 if (this.m_characterStats == null)
  1045.                 {
  1046.                     return 5f;
  1047.                 }
  1048.                 return GlobalGameSettingsGameData.Instance.EnemySightRange;
  1049.             }
  1050.         }
  1051.  
  1052.         protected bool IsInCombat
  1053.         {
  1054.             get
  1055.             {
  1056.                 if ((this.m_health == null || !this.m_health.IsDeadOrUnconscious) && this.IsNearCombat())
  1057.                 {
  1058.                     return true;
  1059.                 }
  1060.                 AIBehaviorType currentBehaviorType = this.GetCurrentBehaviorType();
  1061.                 if (currentBehaviorType == AIBehaviorType.Attack || currentBehaviorType == AIBehaviorType.Cast)
  1062.                 {
  1063.                     return true;
  1064.                 }
  1065.                 if (currentBehaviorType == AIBehaviorType.PreparingToAct)
  1066.                 {
  1067.                     PreparingToActParams preparingToActParams = this.BehaviorStack.CurrentBehavior.AIParams as PreparingToActParams;
  1068.                     if (preparingToActParams.CurrentAction != null)
  1069.                     {
  1070.                         Game.AI.Action.ActionType actionType = preparingToActParams.CurrentAction.GetActionType();
  1071.                         if (actionType == Game.AI.Action.ActionType.Attack || actionType == Game.AI.Action.ActionType.AttackDestructible || actionType == Game.AI.Action.ActionType.Cast)
  1072.                         {
  1073.                             return true;
  1074.                         }
  1075.                     }
  1076.                 }
  1077.                 return false;
  1078.             }
  1079.         }
  1080.  
  1081.         protected bool IsFighting
  1082.         {
  1083.             get
  1084.             {
  1085.                 if (this.m_faction != null && this.m_faction.IsDominated)
  1086.                 {
  1087.                     return true;
  1088.                 }
  1089.                 if (this.m_mustDieForCombatToEnd && this.m_health != null && !this.m_health.IsDead)
  1090.                 {
  1091.                     return true;
  1092.                 }
  1093.                 AIBehavior currentBehavior = this.BehaviorStack.CurrentBehavior;
  1094.                 if (currentBehavior != null)
  1095.                 {
  1096.                     AIBehaviorDataComponent aIBehaviorDataComponent = currentBehavior.AIBehaviorData.Component as AIBehaviorDataComponent;
  1097.                     if (aIBehaviorDataComponent != null)
  1098.                     {
  1099.                         if (aIBehaviorDataComponent.InCombatBehavior == CombatBehaviorType.InCombat)
  1100.                         {
  1101.                             return true;
  1102.                         }
  1103.                         if (aIBehaviorDataComponent.InCombatBehavior == CombatBehaviorType.UseGlobalCombatState)
  1104.                         {
  1105.                             return GameState.InCombat;
  1106.                         }
  1107.                         if (aIBehaviorDataComponent.InCombatBehavior == CombatBehaviorType.UseBehaviorCombatState)
  1108.                         {
  1109.                             return currentBehavior.AIParams.InCombat;
  1110.                         }
  1111.                     }
  1112.                 }
  1113.                 return false;
  1114.             }
  1115.         }
  1116.  
  1117.         protected GameObject CurrentTarget
  1118.         {
  1119.             get
  1120.             {
  1121.                 AIBehavior currentBehavior = this.BehaviorStack.CurrentBehavior;
  1122.                 if (currentBehavior != null)
  1123.                 {
  1124.                     GameObject targetObject = currentBehavior.AIParams.GetTargetObject();
  1125.                     if (targetObject != null && (this.m_mover == null || this.m_mover.TargetWaypoint == null || this.m_mover.TargetWaypoint.get_gameObject() != targetObject || this is WorldMapAIController))
  1126.                     {
  1127.                         return targetObject;
  1128.                     }
  1129.                 }
  1130.                 return null;
  1131.             }
  1132.         }
  1133.  
  1134.         protected bool IsAttackingSameTargetAsAlly
  1135.         {
  1136.             get
  1137.             {
  1138.                 GameObject currentTarget = this.CurrentTarget;
  1139.                 if (currentTarget == null)
  1140.                 {
  1141.                     return false;
  1142.                 }
  1143.                 if (SingletonBehavior<PartyManager>.Instance.IsActivePartyMember(base.get_gameObject()))
  1144.                 {
  1145.                     foreach (PartyMember current in SingletonBehavior<PartyManager>.Instance.GetActivePartyMembers())
  1146.                     {
  1147.                         if (current != null && current.get_gameObject() != base.get_gameObject())
  1148.                         {
  1149.                             AIController aIController = current.AIController;
  1150.                             if (aIController.CurrentTarget == currentTarget)
  1151.                             {
  1152.                                 return true;
  1153.                             }
  1154.                         }
  1155.                     }
  1156.                     return false;
  1157.                 }
  1158.                 return false;
  1159.             }
  1160.         }
  1161.  
  1162.         protected bool IsTethered
  1163.         {
  1164.             get
  1165.             {
  1166.                 return this is WorldMapAIController;
  1167.             }
  1168.         }
  1169.  
  1170.         protected float TetherDistanceSq
  1171.         {
  1172.             get
  1173.             {
  1174.                 return this.TetherDistance * this.TetherDistance;
  1175.             }
  1176.         }
  1177.  
  1178.         protected virtual bool IsPet
  1179.         {
  1180.             get
  1181.             {
  1182.                 return this.AIBehavior == AIBehaviorManager.DefaultAIBehaviorType.Pet || (this.SummonedCharacter != null && (this.SummonedCharacter.SummonType == AISummonType.Pet || this.SummonedCharacter.SummonType == AISummonType.CombatPet));
  1183.             }
  1184.         }
  1185.  
  1186.         protected virtual bool IsTargettablePet
  1187.         {
  1188.             get
  1189.             {
  1190.                 return this.SummonedCharacter != null && this.SummonedCharacter.SummonType == AISummonType.CombatPet;
  1191.             }
  1192.         }
  1193.  
  1194.         protected bool IsExecutingDefaultBehavior
  1195.         {
  1196.             get
  1197.             {
  1198.                 return this.BehaviorStack.BehaviorCount == 1;
  1199.             }
  1200.         }
  1201.  
  1202.         protected static AIController.DebugMode DebuggingMode
  1203.         {
  1204.             get
  1205.             {
  1206.                 return AIController.m_debugMode;
  1207.             }
  1208.             set
  1209.             {
  1210.                 AIController.m_debugMode = value;
  1211.             }
  1212.         }
  1213.  
  1214.         protected override bool UsesOnyxGUI
  1215.         {
  1216.             get
  1217.             {
  1218.                 return OnyxBehaviorManagerBase.DebugOnyxGUI;
  1219.             }
  1220.         }
  1221.  
  1222.         protected ReadOnlyCollection<AIController> EngagedEnemies
  1223.         {
  1224.             get
  1225.             {
  1226.                 if (this.m_engagedEnemiesReadOnly == null)
  1227.                 {
  1228.                     this.m_engagedEnemiesReadOnly = new ReadOnlyCollection<AIController>(this.m_engagedEnemies);
  1229.                 }
  1230.                 return this.m_engagedEnemiesReadOnly;
  1231.             }
  1232.         }
  1233.  
  1234.         protected ReadOnlyCollection<AIController> EngagedBy
  1235.         {
  1236.             get
  1237.             {
  1238.                 if (this.m_engagedByReadOnly == null)
  1239.                 {
  1240.                     this.m_engagedByReadOnly = new ReadOnlyCollection<AIController>(this.m_engagedBy);
  1241.                 }
  1242.                 return this.m_engagedByReadOnly;
  1243.             }
  1244.         }
  1245.  
  1246.         protected ReadOnlyCollection<AIController> ThreatenedEnemies
  1247.         {
  1248.             get
  1249.             {
  1250.                 if (this.m_threatenedEnemiesReadOnly == null)
  1251.                 {
  1252.                     this.m_threatenedEnemiesReadOnly = new ReadOnlyCollection<AIController>(this.m_threatenedEnemies);
  1253.                 }
  1254.                 return this.m_threatenedEnemiesReadOnly;
  1255.             }
  1256.         }
  1257.  
  1258.         protected ReadOnlyCollection<AIController> ThreatenedBy
  1259.         {
  1260.             get
  1261.             {
  1262.                 if (this.m_threatenedByReadOnly == null)
  1263.                 {
  1264.                     this.m_threatenedByReadOnly = new ReadOnlyCollection<AIController>(this.m_threatenedBy);
  1265.                 }
  1266.                 return this.m_threatenedByReadOnly;
  1267.             }
  1268.         }
  1269.  
  1270.         protected bool EngagementDisabled
  1271.         {
  1272.             get
  1273.             {
  1274.                 return this.m_engagementDisabled || this.ThreatDisabled;
  1275.             }
  1276.             set
  1277.             {
  1278.                 this.m_engagementDisabled = value;
  1279.             }
  1280.         }
  1281.  
  1282.         protected bool ThreatDisabled
  1283.         {
  1284.             get;
  1285.             set;
  1286.         }
  1287.  
  1288.         protected float TimeSinceStartedHearing
  1289.         {
  1290.             get;
  1291.             set;
  1292.         }
  1293.  
  1294.         protected float TimeSinceStartedSeeing
  1295.         {
  1296.             get;
  1297.             set;
  1298.         }
  1299.  
  1300.         protected AISummonType ObsoleteSummonType
  1301.         {
  1302.             get
  1303.             {
  1304.                 return this.m_persistentAIController.ObsoleteSummonType;
  1305.             }
  1306.             set
  1307.             {
  1308.                 this.m_persistentAIController.ObsoleteSummonType = value;
  1309.             }
  1310.         }
  1311.  
  1312.         protected Guid ObsoleteSummonerGuid
  1313.         {
  1314.             get
  1315.             {
  1316.                 return this.m_persistentAIController.ObsoleteSummonerGuid;
  1317.             }
  1318.             set
  1319.             {
  1320.                 this.m_persistentAIController.ObsoleteSummonerGuid = value;
  1321.             }
  1322.         }
  1323.  
  1324.         protected ScriptedBehaviorType PersistentScriptedBehavior
  1325.         {
  1326.             get
  1327.             {
  1328.                 return this.m_persistentAIController.PersistentScriptedBehavior;
  1329.             }
  1330.             set
  1331.             {
  1332.                 this.m_persistentAIController.PersistentScriptedBehavior = value;
  1333.             }
  1334.         }
  1335.  
  1336.         protected Guid PersistentScriptedUseObjectGuid
  1337.         {
  1338.             get
  1339.             {
  1340.                 return this.m_persistentAIController.PersistentScriptedUseObjectGuid;
  1341.             }
  1342.             set
  1343.             {
  1344.                 this.m_persistentAIController.PersistentScriptedUseObjectGuid = value;
  1345.             }
  1346.         }
  1347.  
  1348.         protected bool ScanForTargetsEnabled
  1349.         {
  1350.             get
  1351.             {
  1352.                 return this.m_persistentAIController.ScanForTargetsEnabled;
  1353.             }
  1354.             set
  1355.             {
  1356.                 this.m_persistentAIController.ScanForTargetsEnabled = value;
  1357.             }
  1358.         }
  1359.  
  1360.         protected bool IsEmerging
  1361.         {
  1362.             get
  1363.             {
  1364.                 return this.m_persistentAIController.IsEmerging;
  1365.             }
  1366.             set
  1367.             {
  1368.                 this.m_persistentAIController.IsEmerging = value;
  1369.             }
  1370.         }
  1371.  
  1372.         protected bool m_IsGuard
  1373.         {
  1374.             get
  1375.             {
  1376.                 return this.m_persistentAIController.m_IsGuard;
  1377.             }
  1378.             set
  1379.             {
  1380.                 this.m_persistentAIController.m_IsGuard = value;
  1381.             }
  1382.         }
  1383.  
  1384.         protected AIController()
  1385.         {
  1386.         }
  1387.  
  1388.         protected void CacheAvailableMoveDistance()
  1389.         {
  1390.             this.CachedAvailableMoveDistance = this.AvailableMoveDistance;
  1391.         }
  1392.  
  1393.         protected void BeginTurn()
  1394.         {
  1395.             this.AvailableAction = true;
  1396.             this.AvailableMovement = TacticalModeManager.MovementTimePerRound;
  1397.             this.OnTurnStart.Trigger(this);
  1398.             this.OnTimeElapsedMethod(TimeType.EffectTime, TacticalModeManager.EffectTimePerRound);
  1399.             this.BehaviorStack.OnTurnStart();
  1400.         }
  1401.  
  1402.         protected void EndTurn()
  1403.         {
  1404.             this.OnTurnEnd.Trigger(this);
  1405.         }
  1406.  
  1407.         protected bool PassTurnIfNPC()
  1408.         {
  1409.             if (!PartyManager.IsControllablePartyMember(this.PartyMember))
  1410.             {
  1411.                 this.PassTurn(PassTurnStyle.Forced);
  1412.                 return true;
  1413.             }
  1414.             return false;
  1415.         }
  1416.  
  1417.         protected void PassTurn(PassTurnStyle style)
  1418.         {
  1419.             this.AvailableAction = false;
  1420.             this.AvailableMovement = 0f;
  1421.             SingletonBehavior<TacticalModeManager>.Instance.FinishTurn(this, style);
  1422.         }
  1423.  
  1424.         protected void PassTurnNoCallback()
  1425.         {
  1426.             this.m_availableAction = false;
  1427.             this.m_availableMovement = 0f;
  1428.         }
  1429.  
  1430.         protected void CheckEndTurn()
  1431.         {
  1432.             if (!this.m_availableAction && (!PartyManager.IsControllablePartyMember(this.PartyMember) || SingletonBehavior<TacticalModeManager>.Instance.AutoPassTurns))
  1433.             {
  1434.                 SingletonBehavior<TacticalModeManager>.Instance.FinishTurn(this, PassTurnStyle.Forced);
  1435.             }
  1436.         }
  1437.  
  1438.         protected override void InitializeDefaultValues()
  1439.         {
  1440.             base.InitializeDefaultValues();
  1441.             this.BehaviorStack.Owner = base.get_gameObject();
  1442.             this.ModalStack.Owner = base.get_gameObject();
  1443.             if (this.m_decisionTreeReferences.Length > 0)
  1444.             {
  1445.                 for (int i = 0; i < this.m_decisionTreeReferences.Length; i++)
  1446.                 {
  1447.                     if (!DataReference.IsNullOrEmpty(this.m_decisionTreeReferences[i]))
  1448.                     {
  1449.                         this.DecisionTrees.Add(this.m_decisionTreeReferences[i].Data);
  1450.                     }
  1451.                 }
  1452.             }
  1453.             if (this.m_characterStats != null)
  1454.             {
  1455.                 AIDecisionTreeCollectionItem[] decisionTrees = this.m_characterStats.GetDecisionTrees();
  1456.                 int num = 0;
  1457.                 while (decisionTrees != null && num < decisionTrees.Length)
  1458.                 {
  1459.                     if (!DataReference.IsNullOrEmpty(decisionTrees[num].AIDecisionTree))
  1460.                     {
  1461.                         this.DecisionTrees.Add(decisionTrees[num].AIDecisionTree.Data);
  1462.                     }
  1463.                     num++;
  1464.                 }
  1465.             }
  1466.         }
  1467.  
  1468.         protected override void Preactivate()
  1469.         {
  1470.             base.Preactivate();
  1471.             this.m_aiSchedule.SetAIController(this);
  1472.             if (SingletonBehavior<AIScheduleManager>.Instance)
  1473.             {
  1474.                 SingletonBehavior<AIScheduleManager>.Instance.AddSchedule(this, this.m_aiSchedule);
  1475.             }
  1476.         }
  1477.  
  1478.         protected override void CacheComponents()
  1479.         {
  1480.             base.CacheComponents();
  1481.             this.UnsubscribeComponentEvents();
  1482.             this.m_characterStats = base.GetComponent<CharacterStats>();
  1483.             this.m_health = base.GetComponent<Health>();
  1484.             this.m_animController = base.GetComponent<AnimationController>();
  1485.             this.m_scriptEvent = base.GetComponent<ScriptEvent>();
  1486.             this.m_mover = base.GetComponent<Mover>();
  1487.             this.m_equipment = base.GetComponent<Equipment>();
  1488.             this.m_faction = base.GetComponent<Faction>();
  1489.             this.m_townie = base.GetComponent<Townie>();
  1490.             this.m_shipController = base.GetComponent<WorldMapAIController>();
  1491.             this.m_aiTownieSchedule = base.GetComponent<AITownieSchedule>();
  1492.             this.m_partyMember = base.GetComponent<PartyMember>();
  1493.             this.SummonedCharacter = base.GetComponent<SummonedCharacter>();
  1494.             if (this.m_health)
  1495.             {
  1496.                 this.m_health.OnRevived += new Action<GameObject, CombatEventArgs>(this.OnHealthRevived);
  1497.                 this.m_health.OnDeath += new Action<GameObject, CombatEventArgs>(this.OnHealthDeath);
  1498.                 this.m_health.OnUnconscious += new Action<GameObject, CombatEventArgs>(this.OnHealthUnconscious);
  1499.             }
  1500.             if (this.m_characterStats)
  1501.             {
  1502.                 this.m_characterStats.StatusEffectManager.OnAddStatusEffect += new Action<StatusEffectManager, StatusEffectInstance>(this.OnAddStatusEffect);
  1503.             }
  1504.             if (this.m_faction)
  1505.             {
  1506.                 this.m_faction.OnFactionChanged.Subscribe(new Action<GameObject, TeamGameData>(this.OnFactionChanged));
  1507.             }
  1508.         }
  1509.  
  1510.         protected void UnsubscribeComponentEvents()
  1511.         {
  1512.             if (this.m_health)
  1513.             {
  1514.                 this.m_health.OnRevived -= new Action<GameObject, CombatEventArgs>(this.OnHealthRevived);
  1515.                 this.m_health.OnDeath -= new Action<GameObject, CombatEventArgs>(this.OnHealthDeath);
  1516.                 this.m_health.OnUnconscious -= new Action<GameObject, CombatEventArgs>(this.OnHealthUnconscious);
  1517.             }
  1518.             if (this.m_characterStats)
  1519.             {
  1520.                 this.m_characterStats.StatusEffectManager.OnAddStatusEffect -= new Action<StatusEffectManager, StatusEffectInstance>(this.OnAddStatusEffect);
  1521.             }
  1522.             if (this.m_faction)
  1523.             {
  1524.                 this.m_faction.OnFactionChanged.Unsubscribe(new Action<GameObject, TeamGameData>(this.OnFactionChanged));
  1525.             }
  1526.         }
  1527.  
  1528.         protected override void OnyxAwake()
  1529.         {
  1530.             base.OnyxAwake();
  1531.             if (this.m_isGuard)
  1532.             {
  1533.                 this.IsGuard = this.m_isGuard;
  1534.                 this.m_isGuard = false;
  1535.             }
  1536.             this.InitCooldowns();
  1537.             this.InitScanning();
  1538.             this.CheckForPerceptionEvent();
  1539.             AIController.s_activeControllers.Add(this);
  1540.             if (!this.m_hasBeenInitialized)
  1541.             {
  1542.                 this.Init();
  1543.             }
  1544.         }
  1545.  
  1546.         protected override void OnyxValidate()
  1547.         {
  1548.             base.OnyxValidate();
  1549.             if (this.m_isGuard)
  1550.             {
  1551.                 this.IsGuard = this.m_isGuard;
  1552.                 this.m_isGuard = false;
  1553.             }
  1554.         }
  1555.  
  1556.         protected override void OnyxStart()
  1557.         {
  1558.             base.OnyxStart();
  1559.             if (this.m_unsetEmergeFlags)
  1560.             {
  1561.                 EmergeLurkState.SetIsActive(base.get_gameObject(), true);
  1562.             }
  1563.             if (this.IsGuard)
  1564.             {
  1565.                 UIInvestigateManager.ShowIcon(base.get_gameObject(), UIInvestigateIndicator.IconType.Guard, 1f);
  1566.             }
  1567.         }
  1568.  
  1569.         protected void OnTimeElapsedMethod(TimeType timeType, float deltaTime)
  1570.         {
  1571.             this.OnTimeElapsed.Trigger(timeType, deltaTime);
  1572.             if (timeType == TimeType.EffectTime)
  1573.             {
  1574.                 this.m_suspicionDeltaTime += deltaTime;
  1575.             }
  1576.             if (timeType == TimeType.EffectTime && this.m_kiteTargets.Count > 0)
  1577.             {
  1578.                 for (int i = this.m_kiteTargets.Count - 1; i >= 0; i--)
  1579.                 {
  1580.                     this.m_kiteTargets[i].Update(deltaTime);
  1581.                     if (this.m_kiteTargets[i].IsIgnoreTimeComplete)
  1582.                     {
  1583.                         this.m_kiteTargets.RemoveAt(i);
  1584.                     }
  1585.                 }
  1586.             }
  1587.         }
  1588.  
  1589.         protected override void OnyxUpdate()
  1590.         {
  1591.             if (GameState.IsLoading)
  1592.             {
  1593.                 return;
  1594.             }
  1595.             if (GameState.Paused)
  1596.             {
  1597.                 this.BehaviorStack.UpdateWhenPaused();
  1598.                 this.UpdateUI();
  1599.                 return;
  1600.             }
  1601.             bool flag;
  1602.             if (this.m_partyMember != null)
  1603.             {
  1604.                 flag = GameState.ShouldBeInTacticalCombat;
  1605.             }
  1606.             else
  1607.             {
  1608.                 flag = (GameState.ShouldBeInTacticalCombat && this.GetBehavior(AIBehaviorType.PreparingToAct) != null && !this.IsLurking);
  1609.             }
  1610.             if (!TacticalModeManager.IsInTacticalCombat(this))
  1611.             {
  1612.                 if (flag)
  1613.                 {
  1614.                     SingletonBehavior<TacticalModeManager>.Instance.EnterCombat(this);
  1615.                 }
  1616.                 this.OnTimeElapsedMethod(TimeType.EffectTime, Time.get_deltaTime());
  1617.             }
  1618.             else if (!flag)
  1619.             {
  1620.                 SingletonBehavior<TacticalModeManager>.Instance.ExitCombat(this);
  1621.             }
  1622.             this.OnTimeElapsedMethod(TimeType.GameTime, Time.get_deltaTime());
  1623.             this.UpdateCombatStance();
  1624.             this.UpdateScanning();
  1625.             this.UpdateEngagement(this.GetPrimaryAttack());
  1626.             this.ModalStack.Update();
  1627.             this.BehaviorStack.Update();
  1628.             this.m_sameTargetCheckTimer -= Time.get_deltaTime();
  1629.             if (this.m_sameTargetCheckTimer <= 0f)
  1630.             {
  1631.                 bool isAttackingSameTargetAsAlly = this.IsAttackingSameTargetAsAlly;
  1632.                 if (!isAttackingSameTargetAsAlly && this.m_hasNotifiedAttackingSameTargetAsAlly)
  1633.                 {
  1634.                     this.m_hasNotifiedAttackingSameTargetAsAlly = false;
  1635.                     if (this.OnAttackingSameTargetAsAllyStateChange != null)
  1636.                     {
  1637.                         this.OnAttackingSameTargetAsAllyStateChange(base.get_gameObject(), false);
  1638.                     }
  1639.                 }
  1640.                 else if (isAttackingSameTargetAsAlly && !this.m_hasNotifiedAttackingSameTargetAsAlly)
  1641.                 {
  1642.                     this.m_hasNotifiedAttackingSameTargetAsAlly = true;
  1643.                     if (this.OnAttackingSameTargetAsAllyStateChange != null)
  1644.                     {
  1645.                         this.OnAttackingSameTargetAsAllyStateChange(base.get_gameObject(), true);
  1646.                     }
  1647.                 }
  1648.                 this.m_sameTargetCheckTimer = 0.1f;
  1649.             }
  1650.             this.m_primaryAttackReevaluationTimer -= Time.get_deltaTime();
  1651.             if (this.m_holdTimer > 0f)
  1652.             {
  1653.                 this.m_holdTimer -= Time.get_deltaTime();
  1654.             }
  1655.             this.CheckForInvalidEngagements();
  1656.             this.m_hasShoutedForHelp = false;
  1657.             for (int i = this.m_trackedObjectList.Count - 1; i >= 0; i--)
  1658.             {
  1659.                 if (this.m_trackedObjectList[i].Obj == null)
  1660.                 {
  1661.                     this.m_trackedObjectList.RemoveAt(i);
  1662.                 }
  1663.                 else
  1664.                 {
  1665.                     this.m_trackedObjectList[i].Update();
  1666.                     if (this.m_trackedObjectList[i].Expired)
  1667.                     {
  1668.                         this.m_trackedObjectList.RemoveAt(i);
  1669.                     }
  1670.                 }
  1671.             }
  1672.             this.UpdateWeatherReaction();
  1673.             this.UpdateUI();
  1674.             if (this.m_debugShoutTimer > 0f)
  1675.             {
  1676.                 this.m_debugShoutTimer -= Time.get_deltaTime();
  1677.             }
  1678.             base.OnyxUpdate();
  1679.         }
  1680.  
  1681.         protected override void OnyxLateUpdate()
  1682.         {
  1683.             base.OnyxLateUpdate();
  1684.             if (this.HideOffscreenMeshes && this.m_mover && this.m_alphaControl)
  1685.             {
  1686.                 if (this.m_mover.IsOnScreen(true) || GameState.IsCutsceneOrConversationRunning())
  1687.                 {
  1688.                     this.m_alphaControl.FadeTo(1f, 0f, AlphaControl.FadeType.Misc);
  1689.                 }
  1690.                 else
  1691.                 {
  1692.                     this.m_alphaControl.FadeTo(0f, 0f, AlphaControl.FadeType.Misc);
  1693.                 }
  1694.             }
  1695.         }
  1696.  
  1697.         protected override void OnyxEnable()
  1698.         {
  1699.             if (!GameState.LoadedGame)
  1700.             {
  1701.                 this.m_aiSchedule.PlaceAIOnSchedulePath();
  1702.             }
  1703.             this.InitDefaultBehavior();
  1704.             GameState.OnLevelLoaded += new Action<string>(this.GameState_OnLevelLoaded);
  1705.             GameState.OnCombatStart.Subscribe(new System.Action(this.HandleCombatStart));
  1706.             GameState.OnCombatEnd.Subscribe(new System.Action(this.HandleCombatEnd));
  1707.             this.CacheAlphaControl(true);
  1708.             base.OnyxEnable();
  1709.         }
  1710.  
  1711.         protected override void OnyxDisable()
  1712.         {
  1713.             if (this.m_alphaControl != null)
  1714.             {
  1715.                 this.m_alphaControl.Alpha = 1f;
  1716.             }
  1717.             GameState.OnLevelLoaded -= new Action<string>(this.GameState_OnLevelLoaded);
  1718.             GameState.OnCombatStart.UnsubscribeSafe(new System.Action(this.HandleCombatStart));
  1719.             GameState.OnCombatEnd.UnsubscribeSafe(new System.Action(this.HandleCombatEnd));
  1720.             if (SingletonBehavior<PartyManager>.Instance == null || !SingletonBehavior<PartyManager>.Instance.IsActivePartyMember(base.get_gameObject()))
  1721.             {
  1722.                 this.KillSummonedCreatures(true);
  1723.             }
  1724.             this.BehaviorStack.ClearAllBehaviorsIncludingDefaultBehavior();
  1725.             if (SingletonBehavior<TacticalModeManager>.Instance != null)
  1726.             {
  1727.                 SingletonBehavior<TacticalModeManager>.Instance.ExitCombat(this);
  1728.             }
  1729.             base.OnyxDisable();
  1730.         }
  1731.  
  1732.         protected override void OnyxDestroy()
  1733.         {
  1734.             if (SingletonBehavior<AIScheduleManager>.Instance)
  1735.             {
  1736.                 SingletonBehavior<AIScheduleManager>.Instance.RemoveSchedule(this, this.m_aiSchedule);
  1737.             }
  1738.             this.KillSummonedCreatures(true);
  1739.             this.BehaviorStack.ClearAllBehaviorsIncludingDefaultBehavior();
  1740.             AIController.s_activeControllers.Remove(this);
  1741.             this.UnsubscribeComponentEvents();
  1742.             base.OnyxDestroy();
  1743.         }
  1744.  
  1745.         protected void Init()
  1746.         {
  1747.             this.m_engagedBy.Clear();
  1748.             this.m_engagedEnemies.Clear();
  1749.             BoxCollider component = base.GetComponent<BoxCollider>();
  1750.             if (component != null && this.Mover != null)
  1751.             {
  1752.                 Vector3 size = new Vector3(this.Mover.Radius * 2f, 1.8f, this.Mover.Radius * 2f);
  1753.                 size.x /= base.get_transform().get_localScale().x;
  1754.                 size.y /= base.get_transform().get_localScale().y;
  1755.                 size.z /= base.get_transform().get_localScale().z;
  1756.                 component.set_size(size);
  1757.                 Vector3 center = new Vector3(component.get_center().x, size.y / 2f, component.get_center().z);
  1758.                 component.set_center(center);
  1759.             }
  1760.             if (Paperdoll.IsObjectPaperdoll(base.get_gameObject()))
  1761.             {
  1762.                 base.get_gameObject().set_layer(LayerMask.NameToLayer("Character"));
  1763.             }
  1764.             this.RecordRetreatPosition(base.get_transform().get_position());
  1765.             if (this.m_faction != null && this.m_partyMember != null)
  1766.             {
  1767.                 this.m_faction.SetToPlayerTeam();
  1768.             }
  1769.             this.m_hasBeenInitialized = true;
  1770.         }
  1771.  
  1772.         protected void GameState_OnLevelLoaded(string sceneName)
  1773.         {
  1774.             if (!GameState.LoadedGame)
  1775.             {
  1776.                 this.TeleportSummonedCreatures(base.get_transform().get_position());
  1777.             }
  1778.         }
  1779.  
  1780.         protected void TeleportSummonedCreatures(Vector3 position)
  1781.         {
  1782.             for (int i = 0; i < this.m_summonedCreatures.Count; i++)
  1783.             {
  1784.                 GameObject gameObject = this.m_summonedCreatures[i];
  1785.                 if (gameObject != null)
  1786.                 {
  1787.                     Mover component = gameObject.GetComponent<Mover>();
  1788.                     AIController component2 = gameObject.GetComponent<AIController>();
  1789.                     Vector3 vector = NavMeshUtility.NearestUnoccupiedLocation(position, 10f, component);
  1790.                     float num = 2.5f;
  1791.                     float num2 = Onyx.Math.Distance2DSquared(vector, position);
  1792.                     if (num2 > num * num)
  1793.                     {
  1794.                         vector = position;
  1795.                         vector.x += 0.1f;
  1796.                         vector.z += 0.1f;
  1797.                     }
  1798.                     gameObject.get_transform().set_position(vector);
  1799.                     if (component2 != null)
  1800.                     {
  1801.                         component2.BehaviorStack.PopAllBehaviors();
  1802.                         component2.RecordRetreatPosition(gameObject.get_transform().get_position());
  1803.                     }
  1804.                     if (component != null)
  1805.                     {
  1806.                         component.BroadcastUpdateEvent();
  1807.                     }
  1808.                 }
  1809.             }
  1810.         }
  1811.  
  1812.         protected void ReInitializeDefaultBehavior()
  1813.         {
  1814.             if (this.BehaviorStack != null && this.BehaviorStack.BehaviorCount > 0)
  1815.             {
  1816.                 this.InitDefaultBehavior();
  1817.             }
  1818.         }
  1819.  
  1820.         protected void InitDefaultBehavior()
  1821.         {
  1822.             this.BehaviorStack.ClearAllBehaviorsIncludingDefaultBehavior();
  1823.             AIBehaviorManager.DefaultAIBehaviorType aIBehavior;
  1824.             if (this.m_partyMember != null)
  1825.             {
  1826.                 aIBehavior = AIBehaviorManager.DefaultAIBehaviorType.Idle;
  1827.             }
  1828.             else if (this.IsPet && !this.OverrideSummonBehvaior)
  1829.             {
  1830.                 aIBehavior = AIBehaviorManager.DefaultAIBehaviorType.Pet;
  1831.             }
  1832.             else if (SummonedCharacter.IsSummonOfType(base.get_gameObject(), AISummonType.AnimalCompanion) && !this.OverrideSummonBehvaior)
  1833.             {
  1834.                 aIBehavior = AIBehaviorManager.DefaultAIBehaviorType.Follow;
  1835.             }
  1836.             else if (this.m_aiTownieSchedule != null)
  1837.             {
  1838.                 aIBehavior = AIBehaviorManager.DefaultAIBehaviorType.TownieSchedule;
  1839.             }
  1840.             else if (this.m_shipController != null)
  1841.             {
  1842.                 aIBehavior = AIBehaviorManager.DefaultAIBehaviorType.Idle;
  1843.             }
  1844.             else
  1845.             {
  1846.                 aIBehavior = this.AIBehavior;
  1847.             }
  1848.             this.AIBehavior = aIBehavior;
  1849.             AIBehavior defaultBehavior = AIBehaviorManager.AllocateAIBehavior(this.AIBehavior);
  1850.             this.BehaviorStack.SetDefaultBehavior(defaultBehavior);
  1851.             if (this.ScriptedBehavior != ScriptedBehaviorType.None)
  1852.             {
  1853.                 this.SetScriptedBehavior(this.ScriptedBehavior);
  1854.             }
  1855.         }
  1856.  
  1857.         protected AIDecisionTreeSelectionType GetDecisionTreeSelectionType()
  1858.         {
  1859.             if (this.m_decisionTreeReferences.Length > 0)
  1860.             {
  1861.                 return this.DecisionTreeSelectionOverride;
  1862.             }
  1863.             if (this.m_characterStats != null)
  1864.             {
  1865.                 return this.m_characterStats.GetDecisionTreeSelectionType();
  1866.             }
  1867.             return AIDecisionTreeSelectionType.RandomOrder;
  1868.         }
  1869.  
  1870.         protected AIDecisionTreeData GetDecisionTreeByID(Guid ID)
  1871.         {
  1872.             for (int i = 0; i < this.DecisionTrees.Count; i++)
  1873.             {
  1874.                 if (this.DecisionTrees[i].get_ID() == ID)
  1875.                 {
  1876.                     return this.DecisionTrees[i];
  1877.                 }
  1878.             }
  1879.             return null;
  1880.         }
  1881.  
  1882.         protected void InitCooldowns()
  1883.         {
  1884.             if (this.m_cooldowns == null)
  1885.             {
  1886.                 this.m_cooldowns = new Dictionary<Guid, ActionCooldown[]>();
  1887.             }
  1888.             this.m_cooldowns.Clear();
  1889.             for (int i = 0; i < this.DecisionTrees.Count; i++)
  1890.             {
  1891.                 AIDecisionTreeData aIDecisionTreeData = this.DecisionTrees[i];
  1892.                 int num = 0;
  1893.                 bool flag = aIDecisionTreeData != null;
  1894.                 if (flag)
  1895.                 {
  1896.                     for (int j = 0; j < aIDecisionTreeData.get_Nodes().Count; j++)
  1897.                     {
  1898.                         if (aIDecisionTreeData.get_Nodes()[j].get_NodeID() > num)
  1899.                         {
  1900.                             num = aIDecisionTreeData.get_Nodes()[j].get_NodeID();
  1901.                         }
  1902.                     }
  1903.                 }
  1904.                 ActionCooldown[] array = null;
  1905.                 this.m_cooldowns.TryGetValue(aIDecisionTreeData.get_ID(), out array);
  1906.                 if (array == null || array.Length != num + 1)
  1907.                 {
  1908.                     array = new ActionCooldown[num + 1];
  1909.                     this.m_cooldowns[aIDecisionTreeData.get_ID()] = array;
  1910.                     for (int k = 0; k < array.Length; k++)
  1911.                     {
  1912.                         array[k] = new ActionCooldown();
  1913.                     }
  1914.                 }
  1915.                 else
  1916.                 {
  1917.                     ActionCooldown[] array2 = array;
  1918.                     for (int l = 0; l < array2.Length; l++)
  1919.                     {
  1920.                         ActionCooldown actionCooldown = array2[l];
  1921.                         actionCooldown.Init(0, 0f);
  1922.                     }
  1923.                 }
  1924.                 if (flag)
  1925.                 {
  1926.                     for (int m = 0; m < aIDecisionTreeData.get_Nodes().Count; m++)
  1927.                     {
  1928.                         AIActionData aIActionData = aIDecisionTreeData.get_Nodes()[m] as AIActionData;
  1929.                         if (aIActionData != null)
  1930.                         {
  1931.                             AIActionComponent aIActionComponent = aIActionData.Component as AIActionComponent;
  1932.                             if (aIActionComponent != null)
  1933.                             {
  1934.                                 array[aIActionData.get_NodeID()].Init(aIActionComponent.MaxUses, aIActionComponent.CooldownTime);
  1935.                             }
  1936.                         }
  1937.                     }
  1938.                 }
  1939.             }
  1940.         }
  1941.  
  1942.         protected void PreSave()
  1943.         {
  1944.             this.PersistentScriptedBehavior = this.ScriptedBehavior;
  1945.             this.PersistentScriptedUseObjectGuid = InstanceID.GetObjectID(this.ScriptedUseObject);
  1946.         }
  1947.  
  1948.         protected void PostLoad()
  1949.         {
  1950.             if (this.ObsoleteSummonType != AISummonType.NotSummoned)
  1951.             {
  1952.                 SummonedCharacter orAddComponent = ResourceManager.GetOrAddComponent<SummonedCharacter>(base.get_gameObject());
  1953.                 orAddComponent.Summoner = InstanceID.GetObjectByID(this.ObsoleteSummonerGuid);
  1954.                 orAddComponent.SummonType = this.ObsoleteSummonType;
  1955.                 this.ObsoleteSummonType = AISummonType.NotSummoned;
  1956.             }
  1957.             this.ObsoleteSummonerGuid = Guid.Empty;
  1958.             this.ScriptedBehavior = this.PersistentScriptedBehavior;
  1959.             this.ScriptedUseObject = InstanceID.GetObjectByID(this.PersistentScriptedUseObjectGuid);
  1960.             if (this.IsEmerging)
  1961.             {
  1962.                 this.m_unsetEmergeFlags = true;
  1963.             }
  1964.         }
  1965.  
  1966.         protected virtual void UpdateUI()
  1967.         {
  1968.             HudEngagementManager instance = HudEngagementManager.Instance;
  1969.             if (instance != null)
  1970.             {
  1971.                 for (int i = 0; i < this.EngagedEnemies.Count; i++)
  1972.                 {
  1973.                     instance.Verify(base.get_gameObject(), this.EngagedEnemies[i].get_gameObject());
  1974.                 }
  1975.                 for (int j = 0; j < this.EngagedBy.Count; j++)
  1976.                 {
  1977.                     instance.Verify(this.EngagedBy[j].get_gameObject(), base.get_gameObject());
  1978.                 }
  1979.             }
  1980.             this.UpdateFading();
  1981.         }
  1982.  
  1983.         protected void UpdateCombatStance()
  1984.         {
  1985.             if (this.m_animController != null)
  1986.             {
  1987.                 if (this.GetCurrentBehaviorType() != AIBehaviorType.Standup)
  1988.                 {
  1989.                     this.m_animController.InCombat = this.IsInCombat;
  1990.                 }
  1991.                 if (this.m_partyMember != null)
  1992.                 {
  1993.                     this.m_animController.IsActionQueued = (!this.m_partyMember.IsNearCombatAndNotFighting || TacticalModeManager.IsInTacticalCombat(this));
  1994.                 }
  1995.                 else
  1996.                 {
  1997.                     this.m_animController.IsActionQueued = true;
  1998.                 }
  1999.                 GameObject currentTarget = this.CurrentTarget;
  2000.                 if (currentTarget != null)
  2001.                 {
  2002.                     this.m_animController.TargetDistance = Onyx.Math.Distance2D(base.get_transform().get_position(), currentTarget.get_transform().get_position());
  2003.                 }
  2004.                 else
  2005.                 {
  2006.                     this.m_animController.TargetDistance = 0f;
  2007.                 }
  2008.             }
  2009.         }
  2010.  
  2011.         protected bool IsNearCombat()
  2012.         {
  2013.             if (this.m_partyMember != null)
  2014.             {
  2015.                 return this.m_partyMember.IsNearCombat;
  2016.             }
  2017.             return this.IsInCombatAgainstParty();
  2018.         }
  2019.  
  2020.         protected bool IsInCombatAndWaiting()
  2021.         {
  2022.             if (!this.IsFighting)
  2023.             {
  2024.                 return false;
  2025.             }
  2026.             if (this.GetCurrentBehaviorType() == AIBehaviorType.PreparingToAct)
  2027.             {
  2028.                 PreparingToActParams preparingToActParams = this.BehaviorStack.CurrentBehavior.AIParams as PreparingToActParams;
  2029.                 if (preparingToActParams.WaitingToSelectAnAction)
  2030.                 {
  2031.                     return true;
  2032.                 }
  2033.             }
  2034.             return false;
  2035.         }
  2036.  
  2037.         protected void SetDecisionTrees(AIDecisionTreeData[] decisionTrees)
  2038.         {
  2039.             this.m_decisionTrees.Clear();
  2040.             if (decisionTrees != null)
  2041.             {
  2042.                 this.m_decisionTrees.AddRange(decisionTrees);
  2043.             }
  2044.             this.InitCooldowns();
  2045.         }
  2046.  
  2047.         protected void SetClassDecisionTrees()
  2048.         {
  2049.             this.m_decisionTrees.Clear();
  2050.             foreach (KeyValuePair<CharacterClassGameData, CharacterClassLevelData> current in this.m_characterStats.GetAllClassLevelData())
  2051.             {
  2052.                 CharacterClassGameData key = current.Key;
  2053.                 if (!DataObject.IsNullOrEmpty(key) && current.Value.HasClass())
  2054.                 {
  2055.                     this.m_decisionTrees.Add(key.DefaultDecisionTree.Data);
  2056.                 }
  2057.             }
  2058.             this.InitCooldowns();
  2059.         }
  2060.  
  2061.         protected void AssignPartyMemberBehavior()
  2062.         {
  2063.             this.BehaviorStack.ClearAllBehaviorsIncludingDefaultBehavior();
  2064.             this.BehaviorStack.SetDefaultBehavior(AIBehaviorManager.AllocateIdleBehavior());
  2065.             if (this.m_faction != null)
  2066.             {
  2067.                 this.m_faction.SetToPlayerTeam();
  2068.             }
  2069.         }
  2070.  
  2071.         protected AutoAttackSettings GetAutoAttackSettings()
  2072.         {
  2073.             if (this.m_partyMember != null)
  2074.             {
  2075.                 return this.m_partyMember.AutoAttackSettings;
  2076.             }
  2077.             return AutoAttackSettings.NPCSettings;
  2078.         }
  2079.  
  2080.         protected void SetScriptedBehavior(ScriptedBehaviorType scriptedBehavior)
  2081.         {
  2082.             this.ScriptedBehavior = scriptedBehavior;
  2083.             this.BehaviorStack.PopAllBehaviors();
  2084.             if (scriptedBehavior != ScriptedBehaviorType.None)
  2085.             {
  2086.                 if (scriptedBehavior != ScriptedBehaviorType.Idle)
  2087.                 {
  2088.                     if (scriptedBehavior == ScriptedBehaviorType.UseScriptedObject)
  2089.                     {
  2090.                         this.PushUseScriptedObjectBehavior();
  2091.                     }
  2092.                 }
  2093.                 else
  2094.                 {
  2095.                     AIBehavior behavior = AIBehaviorManager.AllocateIdleBehavior();
  2096.                     this.BehaviorStack.PushBehavior(behavior, true);
  2097.                 }
  2098.             }
  2099.         }
  2100.  
  2101.         protected void SetScriptedUseObject(GameObject useObject)
  2102.         {
  2103.             this.ScriptedUseObject = useObject;
  2104.             if (this.ScriptedBehavior == ScriptedBehaviorType.UseScriptedObject)
  2105.             {
  2106.                 this.BehaviorStack.PopAllBehaviors();
  2107.                 this.PushUseScriptedObjectBehavior();
  2108.             }
  2109.         }
  2110.  
  2111.         protected void PushUseScriptedObjectBehavior()
  2112.         {
  2113.             if (this.ScriptedUseObject == null)
  2114.             {
  2115.                 AIBehavior behavior = AIBehaviorManager.AllocateIdleBehavior();
  2116.                 this.BehaviorStack.PushBehavior(behavior, true);
  2117.                 return;
  2118.             }
  2119.             Waypoint component = this.ScriptedUseObject.GetComponent<Waypoint>();
  2120.             if (component != null)
  2121.             {
  2122.                 AIBehavior behavior2 = AIBehaviorManager.AllocatePatrolBehavior(component, false);
  2123.                 this.BehaviorStack.PushBehavior(behavior2, true);
  2124.                 return;
  2125.             }
  2126.             Usable component2 = this.ScriptedUseObject.GetComponent<Usable>();
  2127.             if (component2 != null)
  2128.             {
  2129.                 AIBehavior behavior3 = AIBehaviorManager.AllocateUseObjectBehavior(component2);
  2130.                 this.BehaviorStack.PushBehavior(behavior3, true);
  2131.                 return;
  2132.             }
  2133.             AIBehavior behavior4 = AIBehaviorManager.AllocateIdleBehavior();
  2134.             this.BehaviorStack.PushBehavior(behavior4, true);
  2135.         }
  2136.  
  2137.         protected void CacheAlphaControl(bool forceUpdate)
  2138.         {
  2139.             bool flag = this.m_alphaControl != null;
  2140.             if (!flag)
  2141.             {
  2142.                 this.m_alphaControl = ResourceManager.GetOrAddComponent<AlphaControl>(base.get_gameObject());
  2143.             }
  2144.             if (!flag || forceUpdate)
  2145.             {
  2146.                 this.m_isFogVisible = FogOfWar.IsFullyVisible(base.get_transform().get_position());
  2147.                 if (this.m_isFogVisible)
  2148.                 {
  2149.                     this.m_alphaControl.FadeTo(1f, 0f, AlphaControl.FadeType.FogOfWar);
  2150.                 }
  2151.                 else
  2152.                 {
  2153.                     this.m_alphaControl.FadeTo(0f, 0f, AlphaControl.FadeType.FogOfWar);
  2154.                 }
  2155.             }
  2156.         }
  2157.  
  2158.         protected void UpdateFading()
  2159.         {
  2160.             AIBehavior currentBehavior = this.BehaviorStack.CurrentBehavior;
  2161.             float num = 1f;
  2162.             if (this.SummonedCharacter != null)
  2163.             {
  2164.                 AIController component = ComponentUtils.GetComponent<AIController>(this.SummonedCharacter.Summoner);
  2165.                 if (component != null)
  2166.                 {
  2167.                     currentBehavior = component.BehaviorStack.CurrentBehavior;
  2168.                 }
  2169.             }
  2170.             AIState aIState = null;
  2171.             if (currentBehavior != null)
  2172.             {
  2173.                 aIState = currentBehavior.CurrentState;
  2174.                 if (aIState != null)
  2175.                 {
  2176.                     num = aIState.GetDesiredAlpha();
  2177.                 }
  2178.             }
  2179.             bool flag = FogOfWar.IsFullyVisible(base.get_transform().get_position());
  2180.             this.CacheAlphaControl(false);
  2181.             if (flag != this.m_isFogVisible)
  2182.             {
  2183.                 this.m_isFogVisible = flag;
  2184.                 if (flag)
  2185.                 {
  2186.                     this.m_alphaControl.FadeIn(0.5f, AlphaControl.FadeType.FogOfWar);
  2187.                 }
  2188.                 else
  2189.                 {
  2190.                     this.m_alphaControl.FadeOut(0.5f, AlphaControl.FadeType.FogOfWar);
  2191.                 }
  2192.             }
  2193.             if (this.m_desiredAlpha != num)
  2194.             {
  2195.                 this.m_desiredAlpha = num;
  2196.                 if (aIState != null)
  2197.                 {
  2198.                     Waypoint currentWaypoint = aIState.GetCurrentWaypoint();
  2199.                     if (currentWaypoint != null && currentWaypoint.InteractionType == Waypoint.WaypointInteractionType.FadeOut)
  2200.                     {
  2201.                         this.m_alphaControl.OnFadeOut = currentWaypoint.OnFadeOut;
  2202.                     }
  2203.                 }
  2204.                 this.m_alphaControl.FadeTo(this.m_desiredAlpha, 0.5f, AlphaControl.FadeType.AI);
  2205.             }
  2206.         }
  2207.  
  2208.         protected void FaceDirection(Vector3 newFacing)
  2209.         {
  2210.             float num = Time.get_deltaTime();
  2211.             if (GameState.Paused)
  2212.             {
  2213.                 num = Time.get_unscaledDeltaTime();
  2214.             }
  2215.             else if (num < 1.401298E-45f)
  2216.             {
  2217.                 return;
  2218.             }
  2219.             Vector2 heading = Onyx.Math.ToVector2(newFacing);
  2220.             heading.Normalize();
  2221.             Vector2 a = this.m_mover.SteerTowardsHeading(heading, true, num);
  2222.             if (a.get_sqrMagnitude() > 1.401298E-45f)
  2223.             {
  2224.                 base.get_transform().set_rotation(Quaternion.LookRotation(Onyx.Math.ToVector3(a)));
  2225.             }
  2226.         }
  2227.  
  2228.         protected void FaceTarget(GameObject target)
  2229.         {
  2230.             if (target != null)
  2231.             {
  2232.                 Vector3 newFacing = target.get_transform().get_position() - base.get_transform().get_position();
  2233.                 this.FaceDirection(newFacing);
  2234.             }
  2235.         }
  2236.  
  2237.         protected void FaceTarget(Vector3 targetPosition)
  2238.         {
  2239.             Vector3 newFacing = targetPosition - base.get_transform().get_position();
  2240.             this.FaceDirection(newFacing);
  2241.         }
  2242.  
  2243.         protected void FaceTarget(AttackBase attack)
  2244.         {
  2245.             if (attack != null && !attack.AttackData.FaceTarget)
  2246.             {
  2247.                 return;
  2248.             }
  2249.             GameObject currentTarget = this.CurrentTarget;
  2250.             if (currentTarget == base.get_gameObject())
  2251.             {
  2252.                 return;
  2253.             }
  2254.             if (this.m_characterStats != null && this.m_characterStats.StatusEffectManager.HasStatusEffectByType(StatusEffectType.Paralyzed))
  2255.             {
  2256.                 return;
  2257.             }
  2258.             Vector3 vector = Vector3.get_zero();
  2259.             if (currentTarget == null)
  2260.             {
  2261.                 AIBehaviorType currentBehaviorType = this.GetCurrentBehaviorType();
  2262.                 if (currentBehaviorType != AIBehaviorType.Cast)
  2263.                 {
  2264.                     return;
  2265.                 }
  2266.                 vector = this.BehaviorStack.CurrentBehavior.AIParams.GetPosition();
  2267.             }
  2268.             else
  2269.             {
  2270.                 vector = currentTarget.get_transform().get_position();
  2271.             }
  2272.             Vector3 newFacing = vector - base.get_transform().get_position();
  2273.             newFacing.Normalize();
  2274.             this.FaceDirection(newFacing);
  2275.         }
  2276.  
  2277.         protected bool IsFacingTarget(Vector3 targetPosition)
  2278.         {
  2279.             Vector3 vector = targetPosition - base.get_transform().get_position();
  2280.             vector.y = 0f;
  2281.             if (vector.get_sqrMagnitude() < 1.401298E-45f)
  2282.             {
  2283.                 vector = base.get_transform().get_forward();
  2284.             }
  2285.             vector.Normalize();
  2286.             float num = Vector3.Dot(base.get_transform().get_forward(), vector);
  2287.             return num > 0.9659f;
  2288.         }
  2289.  
  2290.         protected void AddChildSummon(GameObject summon)
  2291.         {
  2292.             if (!this.m_summonedCreatures.Contains(summon))
  2293.             {
  2294.                 this.m_summonedCreatures.Add(summon);
  2295.                 if (this.OnSummonsChanged != null)
  2296.                 {
  2297.                     this.OnSummonsChanged(base.get_gameObject(), EventArgs.Empty);
  2298.                 }
  2299.             }
  2300.         }
  2301.  
  2302.         protected bool RemoveChildSummon(GameObject summon)
  2303.         {
  2304.             if (this.m_summonedCreatures.Remove(summon))
  2305.             {
  2306.                 if (this.OnSummonsChanged != null)
  2307.                 {
  2308.                     this.OnSummonsChanged(base.get_gameObject(), EventArgs.Empty);
  2309.                 }
  2310.                 return true;
  2311.             }
  2312.             return false;
  2313.         }
  2314.  
  2315.         protected void ClearChildSummons()
  2316.         {
  2317.             this.m_summonedCreatures.Clear();
  2318.             if (this.OnSummonsChanged != null)
  2319.             {
  2320.                 this.OnSummonsChanged(base.get_gameObject(), EventArgs.Empty);
  2321.             }
  2322.         }
  2323.  
  2324.         protected void KillSummonedCreatures(bool removeAll = false)
  2325.         {
  2326.             for (int i = this.m_summonedCreatures.Count - 1; i >= 0; i--)
  2327.             {
  2328.                 GameObject gameObject = this.m_summonedCreatures[i];
  2329.                 if (gameObject != null)
  2330.                 {
  2331.                     Health component = gameObject.GetComponent<Health>();
  2332.                     bool flag = false;
  2333.                     if (SummonedCharacter.IsSummonOfType(gameObject, AISummonType.AnimalCompanion) && ((component && component.Lifetime > 0f) || removeAll))
  2334.                     {
  2335.                         AnimalCompanionManager component2 = base.GetComponent<AnimalCompanionManager>();
  2336.                         if (component2)
  2337.                         {
  2338.                             component2.RemoveAnimalCompanion(gameObject);
  2339.                         }
  2340.                         else
  2341.                         {
  2342.                             this.m_summonedCreatures.RemoveAt(i);
  2343.                         }
  2344.                         flag = true;
  2345.                     }
  2346.                     else if (SummonedCharacter.IsSummonOfType(gameObject, AISummonType.Summoned))
  2347.                     {
  2348.                         this.m_summonedCreatures.RemoveAt(i);
  2349.                         flag = true;
  2350.                     }
  2351.                     if (flag)
  2352.                     {
  2353.                         if (component != null)
  2354.                         {
  2355.                             if (this.m_health.WillGib && SummonedCharacter.IsSummonOfType(gameObject, AISummonType.AnimalCompanion) && component.Lifetime == 0f)
  2356.                             {
  2357.                                 component.Kill(null, null, false);
  2358.                             }
  2359.                             else
  2360.                             {
  2361.                                 component.Unsummon();
  2362.                             }
  2363.                         }
  2364.                         else
  2365.                         {
  2366.                             SingletonBehavior<CharacterObjectManager>.Instance.DestroyCharacter(base.get_gameObject(), 0f);
  2367.                         }
  2368.                     }
  2369.                 }
  2370.             }
  2371.             if (this.OnSummonsChanged != null)
  2372.             {
  2373.                 this.OnSummonsChanged(base.get_gameObject(), EventArgs.Empty);
  2374.             }
  2375.         }
  2376.  
  2377.         protected void RemovePet()
  2378.         {
  2379.             for (int i = this.m_summonedCreatures.Count - 1; i >= 0; i--)
  2380.             {
  2381.                 GameObject gameObject = this.m_summonedCreatures[i];
  2382.                 AIController component = ComponentUtils.GetComponent<AIController>(gameObject);
  2383.                 if (component != null && component.IsPet)
  2384.                 {
  2385.                     ResourceManager.DestroyGameObject(gameObject);
  2386.                 }
  2387.             }
  2388.             if (this.OnSummonsChanged != null)
  2389.             {
  2390.                 this.OnSummonsChanged(base.get_gameObject(), EventArgs.Empty);
  2391.             }
  2392.         }
  2393.  
  2394.         protected GameObject GetFollowObject()
  2395.         {
  2396.             GameObject gameObject = SummonedCharacter.FindSummoner(base.get_gameObject());
  2397.             if (gameObject == null)
  2398.             {
  2399.                 gameObject = this.FollowObject;
  2400.             }
  2401.             return gameObject;
  2402.         }
  2403.  
  2404.         protected bool IsPathingObstacle()
  2405.         {
  2406.             if (this.m_health != null && this.m_health.IsDeadOrUnconscious)
  2407.             {
  2408.                 return false;
  2409.             }
  2410.             if (this.m_desiredAlpha < 1.401298E-45f)
  2411.             {
  2412.                 return false;
  2413.             }
  2414.             if (this.IgnoreAsCutsceneObstacle)
  2415.             {
  2416.                 return false;
  2417.             }
  2418.             if (this.IsPet)
  2419.             {
  2420.                 return false;
  2421.             }
  2422.             AIBehavior currentBehavior = this.BehaviorStack.CurrentBehavior;
  2423.             if (currentBehavior != null)
  2424.             {
  2425.                 AIState currentState = currentBehavior.CurrentState;
  2426.                 if (currentState != null && !currentState.BlockPathing)
  2427.                 {
  2428.                     return false;
  2429.                 }
  2430.             }
  2431.             return true;
  2432.         }
  2433.  
  2434.         protected bool IsInMovingState()
  2435.         {
  2436.             AIBehavior currentBehavior = this.BehaviorStack.CurrentBehavior;
  2437.             return currentBehavior != null && currentBehavior.CurrentState != null && currentBehavior.CurrentState.IsMoving;
  2438.         }
  2439.  
  2440.         protected bool IsWaitingToMove()
  2441.         {
  2442.             AIBehavior currentBehavior = this.BehaviorStack.CurrentBehavior;
  2443.             return currentBehavior != null && currentBehavior.AIParams.IsWaitingToMove;
  2444.         }
  2445.  
  2446.         protected bool IsPathBlocked()
  2447.         {
  2448.             return this.GetCurrentBehaviorType() == AIBehaviorType.WaitForClearPath;
  2449.         }
  2450.  
  2451.         protected bool IsPathBlockedBy(Mover obstacle)
  2452.         {
  2453.             AIBehavior currentBehavior = this.BehaviorStack.CurrentBehavior;
  2454.             if (currentBehavior != null)
  2455.             {
  2456.                 AIParams aIParams = currentBehavior.AIParams;
  2457.                 if (aIParams != null)
  2458.                 {
  2459.                     WaitForClearPathParams waitForClearPathParams = aIParams as WaitForClearPathParams;
  2460.                     if (waitForClearPathParams != null)
  2461.                     {
  2462.                         return waitForClearPathParams.Blocker == obstacle || (waitForClearPathParams.Obstacles != null && waitForClearPathParams.Obstacles.Contains(obstacle));
  2463.                     }
  2464.                 }
  2465.             }
  2466.             return false;
  2467.         }
  2468.  
  2469.         protected bool IsPathBlockedByObstacles()
  2470.         {
  2471.             AIBehavior currentBehavior = this.BehaviorStack.CurrentBehavior;
  2472.             if (currentBehavior != null)
  2473.             {
  2474.                 AIParams aIParams = currentBehavior.AIParams;
  2475.                 if (aIParams != null)
  2476.                 {
  2477.                     WaitForClearPathParams waitForClearPathParams = aIParams as WaitForClearPathParams;
  2478.                     if (waitForClearPathParams != null)
  2479.                     {
  2480.                         return waitForClearPathParams.Obstacles.Count > 0;
  2481.                     }
  2482.                 }
  2483.             }
  2484.             return false;
  2485.         }
  2486.  
  2487.         protected void OnAddStatusEffect(StatusEffectManager sender, StatusEffectInstance instance)
  2488.         {
  2489.             StatusEffectType statusEffectType = instance.GameData.StatusEffectType;
  2490.             if (statusEffectType != StatusEffectType.KnockedDown)
  2491.             {
  2492.                 if (statusEffectType != StatusEffectType.Paralyzed)
  2493.                 {
  2494.                     if (statusEffectType != StatusEffectType.Stunned)
  2495.                     {
  2496.                         if (statusEffectType != StatusEffectType.Terrified)
  2497.                         {
  2498.                             if (statusEffectType == StatusEffectType.VerticalLaunch)
  2499.                             {
  2500.                                 AIBehavior behavior = this.GetBehavior(AIBehaviorType.Launched);
  2501.                                 if (behavior != null)
  2502.                                 {
  2503.                                     StatusEffectInstanceParams statusEffectInstanceParams = behavior.AIParams as StatusEffectInstanceParams;
  2504.                                     statusEffectInstanceParams.AddStatusEffect(instance);
  2505.                                 }
  2506.                                 else
  2507.                                 {
  2508.                                     this.CancelGrappleBehavior();
  2509.                                     this.PopAllBehaviorsOfType(AIBehaviorType.Standup);
  2510.                                     this.PopAllBehaviorsOfType(AIBehaviorType.HitReact);
  2511.                                     AIBehavior behavior2 = AIBehaviorManager.AllocateLaunchedBehavior(instance);
  2512.                                     this.BehaviorStack.PushBehavior(behavior2);
  2513.                                 }
  2514.                             }
  2515.                         }
  2516.                         else
  2517.                         {
  2518.                             AIBehavior behavior3 = this.GetBehavior(AIBehaviorType.Terrified);
  2519.                             if (behavior3 != null)
  2520.                             {
  2521.                                 StatusEffectInstanceParams statusEffectInstanceParams2 = behavior3.AIParams as StatusEffectInstanceParams;
  2522.                                 statusEffectInstanceParams2.AddStatusEffect(instance);
  2523.                             }
  2524.                             else
  2525.                             {
  2526.                                 this.CancelGrappleBehavior();
  2527.                                 AIBehavior behavior4 = AIBehaviorManager.AllocateTerrifiedBehavior(instance, base.get_gameObject());
  2528.                                 this.BehaviorStack.PushBehavior(behavior4);
  2529.                             }
  2530.                         }
  2531.                     }
  2532.                     else
  2533.                     {
  2534.                         AIBehavior behavior5 = this.GetBehavior(AIBehaviorType.Stunned);
  2535.                         if (behavior5 != null)
  2536.                         {
  2537.                             StatusEffectInstanceParams statusEffectInstanceParams3 = behavior5.AIParams as StatusEffectInstanceParams;
  2538.                             statusEffectInstanceParams3.AddStatusEffect(instance);
  2539.                         }
  2540.                         else
  2541.                         {
  2542.                             this.CancelAndLoseCurrentAction(false);
  2543.                             AIBehavior behavior6 = AIBehaviorManager.AllocateStunnedBehavior(instance);
  2544.                             this.BehaviorStack.PushBehavior(behavior6);
  2545.                         }
  2546.                     }
  2547.                 }
  2548.                 else
  2549.                 {
  2550.                     AIBehavior behavior7 = this.GetBehavior(AIBehaviorType.Paralyzed);
  2551.                     if (behavior7 != null)
  2552.                     {
  2553.                         StatusEffectInstanceParams statusEffectInstanceParams4 = behavior7.AIParams as StatusEffectInstanceParams;
  2554.                         statusEffectInstanceParams4.AddStatusEffect(instance);
  2555.                     }
  2556.                     else
  2557.                     {
  2558.                         this.CancelGrappleBehavior();
  2559.                         AIBehavior behavior8 = AIBehaviorManager.AllocateParalyzedBehavior(instance);
  2560.                         this.BehaviorStack.PushBehavior(behavior8);
  2561.                     }
  2562.                 }
  2563.             }
  2564.             else
  2565.             {
  2566.                 AIBehavior behavior9 = this.GetBehavior(AIBehaviorType.KnockedDown);
  2567.                 if (behavior9 != null)
  2568.                 {
  2569.                     StatusEffectInstanceParams statusEffectInstanceParams5 = behavior9.AIParams as StatusEffectInstanceParams;
  2570.                     statusEffectInstanceParams5.AddStatusEffect(instance);
  2571.                 }
  2572.                 else
  2573.                 {
  2574.                     this.CancelGrappleBehavior();
  2575.                     this.PopAllBehaviorsOfType(AIBehaviorType.Standup);
  2576.                     this.PopAllBehaviorsOfType(AIBehaviorType.HitReact);
  2577.                     AIBehavior behavior10 = AIBehaviorManager.AllocateKnockedDownBehavior(instance);
  2578.                     if (this.GetCurrentBehaviorType() == AIBehaviorType.PushedBack)
  2579.                     {
  2580.                         this.BehaviorStack.QueueBehaviorAtTop(behavior10);
  2581.                     }
  2582.                     else
  2583.                     {
  2584.                         this.BehaviorStack.PushBehavior(behavior10);
  2585.                     }
  2586.                 }
  2587.             }
  2588.         }
  2589.  
  2590.         protected void ReactToWeather(AIController.WeatherReactionType weatherReactionType)
  2591.         {
  2592.             float num = 0f;
  2593.             float num2 = 0f;
  2594.             if (weatherReactionType != AIController.WeatherReactionType.SeekCover)
  2595.             {
  2596.                 if (weatherReactionType == AIController.WeatherReactionType.LeaveCover)
  2597.                 {
  2598.                     num = GlobalGameSettingsGameData.Instance.AISettings.LeaveCoverMinDelay;
  2599.                     num2 = GlobalGameSettingsGameData.Instance.AISettings.LeaveCoverMaxDelay;
  2600.                 }
  2601.             }
  2602.             else
  2603.             {
  2604.                 num = GlobalGameSettingsGameData.Instance.AISettings.SeekCoverMinDelay;
  2605.                 num2 = GlobalGameSettingsGameData.Instance.AISettings.SeekCoverMaxDelay;
  2606.             }
  2607.             this.m_shouldReactToWeatherAfterDelay = true;
  2608.             this.m_weatherReactionType = weatherReactionType;
  2609.             this.m_weatherReactionDelay = Random.Range(num, num2);
  2610.             this.m_weatherReactionTimer = 0f;
  2611.         }
  2612.  
  2613.         protected void UpdateWeatherReaction()
  2614.         {
  2615.             if (this.m_shouldReactToWeatherAfterDelay)
  2616.             {
  2617.                 this.m_weatherReactionTimer += Time.get_deltaTime();
  2618.                 if (this.m_weatherReactionTimer >= this.m_weatherReactionDelay)
  2619.                 {
  2620.                     if ((this.m_weatherReactionType == AIController.WeatherReactionType.SeekCover && SingletonBehavior<WeatherManager>.Instance.IsCurrentConditionTreacherous) || (this.m_weatherReactionType == AIController.WeatherReactionType.LeaveCover && !SingletonBehavior<WeatherManager>.Instance.IsCurrentConditionTreacherous))
  2621.                     {
  2622.                         if (this.AITownieSchedule != null)
  2623.                         {
  2624.                             this.AITownieSchedule.ReactToWeather(this.m_weatherReactionType);
  2625.                         }
  2626.                         else
  2627.                         {
  2628.                             this.AISchedule.ReactToWeather(this.m_weatherReactionType);
  2629.                         }
  2630.                     }
  2631.                     this.m_shouldReactToWeatherAfterDelay = false;
  2632.                     this.m_weatherReactionType = AIController.WeatherReactionType.None;
  2633.                 }
  2634.             }
  2635.         }
  2636.  
  2637.         protected void NotifyRequestHelp(GameObject shouter, GameObject enemy, GameObject caller, GameObject origin, float radius, bool isTownieShout, bool shouterDied, Vector3 lastSeenEnemyPosition)
  2638.         {
  2639.             if (this.BehaviorStack == null)
  2640.             {
  2641.                 return;
  2642.             }
  2643.             if ((this.m_faction != null && this.m_faction.IsDominated) || this.IsPet || shouter == base.get_gameObject())
  2644.             {
  2645.                 return;
  2646.             }
  2647.             if (!base.get_gameObject().get_activeInHierarchy() || (this.m_health != null && this.m_health.IsDeadOrUnconscious))
  2648.             {
  2649.                 return;
  2650.             }
  2651.             Faction component = shouter.GetComponent<Faction>();
  2652.             Faction component2 = enemy.GetComponent<Faction>();
  2653.             if (SingletonBehavior<PartyManager>.Instance.IsActivePartyMember(base.get_gameObject()))
  2654.             {
  2655.                 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))
  2656.                 {
  2657.                     AIBehavior behavior = AIBehaviorManager.AllocatePreparingToActBehaviorWithHelpRequest(shouter, false);
  2658.                     this.BehaviorStack.PushBehavior(behavior, true);
  2659.                 }
  2660.                 return;
  2661.             }
  2662.             if (!isTownieShout)
  2663.             {
  2664.                 lastSeenEnemyPosition = Vector3.get_zero();
  2665.             }
  2666.             if (this.m_faction != null && !this.m_faction.IsFriendly(component))
  2667.             {
  2668.                 return;
  2669.             }
  2670.             if (NavMeshUtility.GetPathingDistance(this.m_mover, this.m_mover.get_transform().get_position(), caller.get_transform().get_position(), false) > radius * GlobalGameSettingsGameData.Instance.RequestHelpShoutRangePathingScalar)
  2671.             {
  2672.                 return;
  2673.             }
  2674.             if (shouterDied)
  2675.             {
  2676.                 this.ExecuteOnFriendlyDeathAlert();
  2677.             }
  2678.             if (!this.IsTownie)
  2679.             {
  2680.                 SingletonBehavior<TacticalModeManager>.Instance.EnterCombat(this);
  2681.             }
  2682.             if (this.CurrentTarget != null)
  2683.             {
  2684.                 this.m_hasShoutedForHelp = true;
  2685.                 AIController.ShoutToAllies(shouter, enemy, base.get_gameObject(), origin, this.ShoutRange, isTownieShout, false, lastSeenEnemyPosition);
  2686.                 return;
  2687.             }
  2688.             if (this.GetCurrentBehaviorType() == AIBehaviorType.WaitForClearPath)
  2689.             {
  2690.                 if (this.m_mover.IsBlockedBy(Mover.BlockFlag.Cluster))
  2691.                 {
  2692.                     return;
  2693.                 }
  2694.                 this.BehaviorStack.PopCurrentBehavior();
  2695.             }
  2696.             if (this.m_faction != null && this.IsTownie)
  2697.             {
  2698.                 if (!this.m_townie.IsReacting)
  2699.                 {
  2700.                     if (!isTownieShout)
  2701.                     {
  2702.                         this.m_townie.ScanForNearbyCombat();
  2703.                         if (!this.m_townie.IsReacting)
  2704.                         {
  2705.                             this.m_townie.BeginCombatReaction(enemy, enemy.get_transform().get_position());
  2706.                         }
  2707.                     }
  2708.                     if (isTownieShout)
  2709.                     {
  2710.                         this.m_townie.BeginCombatReaction(enemy, lastSeenEnemyPosition);
  2711.                     }
  2712.                     this.ExecuteOnShoutAlert();
  2713.                 }
  2714.             }
  2715.             else if (!this.IsInCombat)
  2716.             {
  2717.                 if (!isTownieShout && component2 != null)
  2718.                 {
  2719.                     if (component2.IsInPlayerFaction)
  2720.                     {
  2721.                         this.m_faction.SetRelationshipToPlayer(Relationship.Hostile);
  2722.                     }
  2723.                     this.m_delayedCombatParams.SetTarget(component, AIBehaviorManager.PreparingToActType.HelpRequest);
  2724.                 }
  2725.                 if (isTownieShout && this.GetCurrentBehaviorType() != AIBehaviorType.Investigate)
  2726.                 {
  2727.                     AIBehavior behavior2 = AIBehaviorManager.AllocateInvestigateBehavior(lastSeenEnemyPosition, base.get_transform().get_position(), MovementType.Run, MovementType.Walk, 2f, true);
  2728.                     this.BehaviorStack.PushBehavior(behavior2);
  2729.                     this.ExecuteOnShoutAlert();
  2730.                 }
  2731.             }
  2732.             this.m_hasShoutedForHelp = true;
  2733.             if (isTownieShout)
  2734.             {
  2735.                 AIController.ShoutToAllies(shouter, enemy, base.get_gameObject(), origin, this.ShoutRange, isTownieShout, false, lastSeenEnemyPosition);
  2736.             }
  2737.             else
  2738.             {
  2739.                 AIController.ShoutToAllies(shouter, enemy, base.get_gameObject(), origin, this.ShoutRange, isTownieShout, false, Vector3.get_zero());
  2740.             }
  2741.         }
  2742.  
  2743.         protected void NotifyAttacked(GameObject attacker, DamageInfo damageInfo, float amount)
  2744.         {
  2745.             Faction component = base.GetComponent<Faction>();
  2746.             Faction component2 = ComponentUtils.GetComponent<Faction>(attacker);
  2747.             if (this.IsPet || component.Health == null || component.Health.IsDeadOrUnconscious)
  2748.             {
  2749.                 return;
  2750.             }
  2751.             this.UpdateMustDieForCombatToEnd();
  2752.             this.m_hasShoutedForHelp = true;
  2753.             if (component2 != null && component2.IsInPlayerFaction)
  2754.             {
  2755.                 this.m_faction.NotifyAttackWitnessed();
  2756.             }
  2757.             Trap componentUnlikely = attacker.GetComponentUnlikely<Trap>();
  2758.             if (componentUnlikely != null)
  2759.             {
  2760.                 return;
  2761.             }
  2762.             this.TrackDamage(attacker, amount);
  2763.             if (this.m_highestDamageInflictor == null || amount > this.m_highestDamageInflicted)
  2764.             {
  2765.                 this.m_highestDamageInflictor = attacker;
  2766.                 this.m_highestDamageInflicted = amount;
  2767.             }
  2768.             if (component2 != null && !component.CurrentTeam.IsEmpty() && !component.IsDominated && component2.CurrentTeam != component.CurrentTeam)
  2769.             {
  2770.                 this.ShoutToAllies(attacker, this.ShoutRange, false, false, Vector3.get_zero());
  2771.             }
  2772.             if (this.m_townie != null && this.GetCurrentBehaviorType() == AIBehaviorType.Flee)
  2773.             {
  2774.                 CowerParams cowerParams = this.BehaviorStack.CurrentBehavior.AIParams as CowerParams;
  2775.                 if (cowerParams != null)
  2776.                 {
  2777.                     cowerParams.ResetInCombatTimer();
  2778.                 }
  2779.             }
  2780.             AttackBase attackBase = null;
  2781.             if (damageInfo != null)
  2782.             {
  2783.                 attackBase = damageInfo.Attack;
  2784.             }
  2785.             if (attacker != null && component != null)
  2786.             {
  2787.                 if (this.m_partyMember != null)
  2788.                 {
  2789.                     if (component.IsHostile(attacker))
  2790.                     {
  2791.                         if (!this.IsFighting && !this.m_holdMove && this.m_partyMember.AutoAttackSettings.AutoAttackType != AutoAttackType.Passive && attackBase != null && !attackBase.IsDisengagementAttack)
  2792.                         {
  2793.                             AIBehavior behavior = AIBehaviorManager.AllocatePreparingToActBehaviorWithPreferredTarget(component2, false);
  2794.                             this.BehaviorStack.PushBehavior(behavior, true);
  2795.                         }
  2796.                         return;
  2797.                     }
  2798.                 }
  2799.                 else if (!component.IsHostile(attacker) && component2 != null)
  2800.                 {
  2801.                     if (component.IsInPlayerFaction && component2.IsInPlayerFaction)
  2802.                     {
  2803.                         return;
  2804.                     }
  2805.                     if (component2.CurrentTeam != component.CurrentTeam)
  2806.                     {
  2807.                         if (component2.IsInPlayerFaction && !component2.IsDominated)
  2808.                         {
  2809.                             component.SetRelationshipToPlayer(Relationship.Hostile);
  2810.                         }
  2811.                         else if (component.IsInPlayerFaction && !component.IsDominated)
  2812.                         {
  2813.                             component2.SetRelationshipToPlayer(Relationship.Hostile);
  2814.                         }
  2815.                     }
  2816.                 }
  2817.                 if (this.m_partyMember == null && !this.IsInCombat)
  2818.                 {
  2819.                     if (component.CurrentTeam.TeamType == TeamType.Townie)
  2820.                     {
  2821.                         AIBehavior behavior2 = AIBehaviorManager.AllocateCowerBehavior();
  2822.                         this.BehaviorStack.PushBehavior(behavior2, true);
  2823.                     }
  2824.                     else
  2825.                     {
  2826.                         AIBehavior behavior3 = AIBehaviorManager.AllocatePreparingToActBehaviorWithPreferredTarget(component2, component2.IsInPlayerFaction);
  2827.                         this.BehaviorStack.PushBehavior(behavior3, true);
  2828.                     }
  2829.                 }
  2830.             }
  2831.         }
  2832.  
  2833.         protected void NotifyHitReact(HitReactType interruptType)
  2834.         {
  2835.             AIBehaviorType currentBehaviorType = this.GetCurrentBehaviorType();
  2836.             if (currentBehaviorType != AIBehaviorType.Flee)
  2837.             {
  2838.                 if (interruptType == HitReactType.Prone)
  2839.                 {
  2840.                     AIBehavior behavior = this.GetBehavior(AIBehaviorType.KnockedDown);
  2841.                     if (behavior != null)
  2842.                     {
  2843.                         TimerParams timerParams = behavior.AIParams as TimerParams;
  2844.                         timerParams.Duration += GlobalGameSettingsGameData.Instance.KnockDownDuration;
  2845.                         return;
  2846.                     }
  2847.                     this.PopAllBehaviorsOfType(AIBehaviorType.Standup);
  2848.                 }
  2849.                 else if (interruptType == HitReactType.Normal && currentBehaviorType == AIBehaviorType.HitReact)
  2850.                 {
  2851.                     return;
  2852.                 }
  2853.                 AIBehavior behavior2 = AIBehaviorManager.AllocateHitReactBehavior(interruptType);
  2854.                 this.BehaviorStack.PushBehavior(behavior2);
  2855.             }
  2856.         }
  2857.  
  2858.         protected void NotifyMeleeEngaged(AIController engager)
  2859.         {
  2860.             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))
  2861.             {
  2862.                 if (this.GetAutoAttackSettings().AutoAttackType == AutoAttackType.Passive)
  2863.                 {
  2864.                     if (this.GetCurrentBehaviorType() != AIBehaviorType.WaitForEngagementToEnd)
  2865.                     {
  2866.                         AIBehavior behavior = AIBehaviorManager.AllocateWaitForEngagementToEndBehavior();
  2867.                         this.BehaviorStack.PushBehavior(behavior, true);
  2868.                     }
  2869.                 }
  2870.                 else if (!this.IsFighting)
  2871.                 {
  2872.                     AIBehavior behavior2 = AIBehaviorManager.AllocatePreparingToActBehaviorWithPreferredTarget(engager.Faction, false);
  2873.                     this.BehaviorStack.PushBehavior(behavior2, true);
  2874.                 }
  2875.             }
  2876.         }
  2877.  
  2878.         protected void NotifyNoiseLevel(Vector3 noiseLocation, NoiseLevelGameData noiseLevel)
  2879.         {
  2880.             if (!this.IsInCombat)
  2881.             {
  2882.                 AIBehaviorType currentBehaviorType = this.GetCurrentBehaviorType();
  2883.                 Vector3 originalPosition = base.get_transform().get_position();
  2884.                 if (currentBehaviorType == AIBehaviorType.Investigate && this.BehaviorStack.CurrentBehavior != null)
  2885.                 {
  2886.                     InvestigateParams investigateParams = this.BehaviorStack.CurrentBehavior.AIParams as InvestigateParams;
  2887.                     Vector3 investigatePosition = investigateParams.InvestigatePosition;
  2888.                     float num = Onyx.Math.Distance2DSquared(noiseLocation, investigatePosition);
  2889.                     if (num <= 10f)
  2890.                     {
  2891.                         return;
  2892.                     }
  2893.                     originalPosition = investigateParams.OriginalPosition;
  2894.                     this.BehaviorStack.PopCurrentBehavior();
  2895.                 }
  2896.                 if (currentBehaviorType != AIBehaviorType.PreparingToAct && this.m_townie == null)
  2897.                 {
  2898.                     AIBehavior behavior = AIBehaviorManager.AllocateInvestigateBehavior(noiseLocation, originalPosition, MovementType.Walk, MovementType.Walk, 2f, false);
  2899.                     this.BehaviorStack.PushBehavior(behavior);
  2900.                     SingletonBehavior<ChatterManager>.Instance.StartNPCReactiveBarkChatter(ChatterEventType.Investigate, base.get_gameObject());
  2901.                 }
  2902.             }
  2903.         }
  2904.  
  2905.         protected void OnHealthRevived(GameObject self, CombatEventArgs args)
  2906.         {
  2907.             if (this.Mover != null)
  2908.             {
  2909.                 this.Mover.get_transform().set_position(NavMeshUtility.NearestUnoccupiedLocation(this.Mover.get_transform().get_position(), 10f, this.Mover));
  2910.             }
  2911.             this.PopAllBehaviorsOfType(AIBehaviorType.Dead);
  2912.             this.PopAllBehaviorsOfType(AIBehaviorType.Unconscious);
  2913.             AIBehavior behavior = AIBehaviorManager.AllocateStandupBehavior();
  2914.             this.BehaviorStack.PushBehavior(behavior);
  2915.         }
  2916.  
  2917.         protected void OnHealthUnconscious(GameObject self, CombatEventArgs args)
  2918.         {
  2919.             if (this.Health.IsUnconscious)
  2920.             {
  2921.                 AIBehavior behavior = AIBehaviorManager.AllocateUnconsciousBehavior();
  2922.                 this.BehaviorStack.PushBehavior(behavior, true);
  2923.             }
  2924.         }
  2925.  
  2926.         protected void OnHealthDeath(GameObject self, CombatEventArgs args)
  2927.         {
  2928.             AIBehavior behavior = AIBehaviorManager.AllocateDeadBehavior();
  2929.             this.BehaviorStack.PushBehavior(behavior, true);
  2930.             Faction component = base.GetComponent<Faction>();
  2931.             Faction component2 = ComponentUtils.GetComponent<Faction>(args.Attacker);
  2932.             if (component2 != null && component != null && !component.CurrentTeam.IsEmpty() && component2.CurrentTeam != component.CurrentTeam)
  2933.             {
  2934.                 this.ShoutToAllies(args.Attacker, this.ShoutRange, false, true, Vector3.get_zero());
  2935.             }
  2936.         }
  2937.  
  2938.         protected void OnFactionChanged(GameObject sender, TeamGameData newTeam)
  2939.         {
  2940.             for (int i = 0; i < this.BehaviorStack.BehaviorCount; i++)
  2941.             {
  2942.                 PreparingToActParams preparingToActParams = this.BehaviorStack.GetBehavior(i).AIParams as PreparingToActParams;
  2943.                 if (preparingToActParams != null)
  2944.                 {
  2945.                     Game.AI.Action currentAction = preparingToActParams.CurrentAction;
  2946.                     if (currentAction is BaseAttackAction || currentAction is CastAction)
  2947.                     {
  2948.                         currentAction.Invalidate();
  2949.                     }
  2950.                 }
  2951.             }
  2952.         }
  2953.  
  2954.         protected void UpdateAutoAttackOfSummonedCreatures(bool includeCompanion)
  2955.         {
  2956.             for (int i = 0; i < this.m_summonedCreatures.Count; i++)
  2957.             {
  2958.                 SummonedCharacter component = ComponentUtils.GetComponent<SummonedCharacter>(this.m_summonedCreatures[i]);
  2959.                 if (component != null && component.SummonType != AISummonType.Pet && (component.SummonType != AISummonType.AnimalCompanion || includeCompanion))
  2960.                 {
  2961.                     PartyMember component2 = component.GetComponent<PartyMember>();
  2962.                     if (this.m_partyMember != null && component2 != null && component.SummonType != AISummonType.AnimalCompanion)
  2963.                     {
  2964.                         component2.AutoAttackSettings.Copy(this.m_partyMember.AutoAttackSettings);
  2965.                     }
  2966.                 }
  2967.             }
  2968.         }
  2969.  
  2970.         protected static void TriggerNoiseReaction(GameObject source, Vector3 noiseLocation, NoiseLevelGameData noiseLevel, bool hostilesOnly = true)
  2971.         {
  2972.             if (GameState.IsCutsceneOrConversationRunning())
  2973.             {
  2974.                 return;
  2975.             }
  2976.             if (!SingletonBehavior<PartyManager>.Instance.IsActivePartyMember(source))
  2977.             {
  2978.                 return;
  2979.             }
  2980.             float radius = noiseLevel.Radius;
  2981.             Faction component = ComponentUtils.GetComponent<Faction>(source);
  2982.             RangeManager instance = SingletonBehavior<RangeManager>.Instance;
  2983.             RangeManager.Data factionRange = instance.GetFactionRange(noiseLocation.x, radius + instance.LargestHearingDistance);
  2984.             for (int i = factionRange.m_start; i < factionRange.m_end; i++)
  2985.             {
  2986.                 Faction faction = instance.GetFaction(i);
  2987.                 if (!(faction == null))
  2988.                 {
  2989.                     AIController aIController = faction.AIController;
  2990.                     if (!(aIController == null))
  2991.                     {
  2992.                         if (!(faction.Health != null) || !faction.Health.IsDeadOrUnconscious)
  2993.                         {
  2994.                             float num = Onyx.Math.Distance2DSquared(noiseLocation, faction.get_transform().get_position());
  2995.                             float stealthedCharacterHearingDistance = aIController.StealthedCharacterHearingDistance;
  2996.                             float num2 = stealthedCharacterHearingDistance + radius;
  2997.                             if (num <= num2 * num2)
  2998.                             {
  2999.                                 if (!SingletonBehavior<PartyManager>.Instance.IsActivePartyMember(faction.get_gameObject()))
  3000.                                 {
  3001.                                     if (!hostilesOnly || faction.GetRelationship(component) == Relationship.Hostile || aIController.IsGuard)
  3002.                                     {
  3003.                                         aIController.NotifyNoiseLevel(noiseLocation, noiseLevel);
  3004.                                     }
  3005.                                 }
  3006.                             }
  3007.                         }
  3008.                     }
  3009.                 }
  3010.             }
  3011.         }
  3012.  
  3013.         protected void RequestConversationAnimation(FlowChartPlayer conversation, int variation)
  3014.         {
  3015.             if (conversation == null)
  3016.             {
  3017.                 return;
  3018.             }
  3019.             if (this.GetCurrentBehaviorType() != AIBehaviorType.WaitForDialogueToEnd && this.ShouldConversationInterruptBehavior())
  3020.             {
  3021.                 AIBehavior behavior = AIBehaviorManager.AllocateWaitForDialogueToEndBehavior(null, conversation, false, variation);
  3022.                 this.BehaviorStack.PushBehavior(behavior);
  3023.             }
  3024.             this.OnConversationAnimation.Trigger(variation);
  3025.         }
  3026.  
  3027.         protected bool CanFaceUserForConversation()
  3028.         {
  3029.             if (this.m_animController && this.m_animController.IsPlayingAmbient())
  3030.             {
  3031.                 AIBehavior currentBehaviorOrSubBehavior = this.GetCurrentBehaviorOrSubBehavior();
  3032.                 if (currentBehaviorOrSubBehavior != null)
  3033.                 {
  3034.                     GameObject targetObject = currentBehaviorOrSubBehavior.AIParams.GetTargetObject();
  3035.                     if (targetObject)
  3036.                     {
  3037.                         Waypoint component = targetObject.GetComponent<Waypoint>();
  3038.                         if (component)
  3039.                         {
  3040.                             return component.ShouldFaceUserForConversation;
  3041.                         }
  3042.                     }
  3043.                 }
  3044.             }
  3045.             return true;
  3046.         }
  3047.  
  3048.         protected bool ShouldConversationInterruptBehavior()
  3049.         {
  3050.             if (this.m_animController && this.m_animController.IsPlayingAmbient())
  3051.             {
  3052.                 AIBehavior currentBehaviorOrSubBehavior = this.GetCurrentBehaviorOrSubBehavior();
  3053.                 if (currentBehaviorOrSubBehavior != null)
  3054.                 {
  3055.                     GameObject targetObject = currentBehaviorOrSubBehavior.AIParams.GetTargetObject();
  3056.                     if (targetObject)
  3057.                     {
  3058.                         Waypoint component = targetObject.GetComponent<Waypoint>();
  3059.                         if (component)
  3060.                         {
  3061.                             return !component.ShouldMaintainAmbientForConversation;
  3062.                         }
  3063.                     }
  3064.                 }
  3065.             }
  3066.             return true;
  3067.         }
  3068.  
  3069.         protected void PauseStateForConversation(FlowChartPlayer conversation, GameObject objectToFace)
  3070.         {
  3071.             this.OnConversationPauseState.Trigger(conversation, objectToFace);
  3072.         }
  3073.  
  3074.         protected void ShoutToAllies(GameObject enemy, float radius, bool isTownie, bool shouterDied, Vector3 lastSeenEnemyPosition)
  3075.         {
  3076.             AIController.ShoutToAllies(base.get_gameObject(), enemy, base.get_gameObject(), base.get_gameObject(), radius, isTownie, shouterDied, lastSeenEnemyPosition);
  3077.         }
  3078.  
  3079.         protected static void ShoutToAllies(GameObject shouter, GameObject enemy, GameObject caller, GameObject origin, float radius, bool isTownie, bool shouterDied, Vector3 lastSeenEnemyPosition)
  3080.         {
  3081.             Faction component = caller.GetComponent<Faction>();
  3082.             float num = radius * radius;
  3083.             RangeManager instance = SingletonBehavior<RangeManager>.Instance;
  3084.             RangeManager.Data factionRange = instance.GetFactionRange(caller.get_transform().get_position().x, radius);
  3085.             for (int i = factionRange.m_start; i < factionRange.m_end; i++)
  3086.             {
  3087.                 Faction faction = instance.GetFaction(i);
  3088.                 if (!(faction == null) && !(faction.get_gameObject() == caller))
  3089.                 {
  3090.                     float num2 = Onyx.Math.Distance2DSquared(caller.get_transform().get_position(), faction.get_transform().get_position());
  3091.                     if (num2 <= num)
  3092.                     {
  3093.                         AIController aIController = faction.AIController;
  3094.                         if (aIController != null && !aIController.m_hasShoutedForHelp && faction.GetRelationship(component) == Relationship.Friendly)
  3095.                         {
  3096.                             aIController.NotifyRequestHelp(shouter, enemy, caller, origin, radius, isTownie, shouterDied, lastSeenEnemyPosition);
  3097.                         }
  3098.                     }
  3099.                 }
  3100.             }
  3101.             if (AIController.DebuggingMode == AIController.DebugMode.Shout)
  3102.             {
  3103.                 AIController component2 = caller.GetComponent<AIController>();
  3104.                 if (component2 != null)
  3105.                 {
  3106.                     component2.m_debugShoutTimer = 3f;
  3107.                     component2.m_debugShoutOrigin = (caller == shouter);
  3108.                 }
  3109.             }
  3110.         }
  3111.  
  3112.         protected float GetDesiredAttackArrivalDistance(GameObject target)
  3113.         {
  3114.             AttackBase desiredAttack = this.GetDesiredAttack(target);
  3115.             if (desiredAttack == null)
  3116.             {
  3117.                 return 0.1f;
  3118.             }
  3119.             AIController component = ComponentUtils.GetComponent<AIController>(target);
  3120.             if (component != null)
  3121.             {
  3122.                 return this.GetAttackArrivalDistance(desiredAttack, component, false);
  3123.             }
  3124.             return 0.1f;
  3125.         }
  3126.  
  3127.         protected float GetAttackArrivalDistance(AttackBase attack, AIController targetAIController, bool isForced)
  3128.         {
  3129.             if (attack == null)
  3130.             {
  3131.                 return 0.1f;
  3132.             }
  3133.             if (attack.TargetDirectionOnly && isForced)
  3134.             {
  3135.                 return 10000f;
  3136.             }
  3137.             float num = attack.TotalAttackDistance;
  3138.             if (this.m_mover != null && attack is AttackMelee)
  3139.             {
  3140.                 num += this.m_mover.Radius;
  3141.             }
  3142.             if (targetAIController != null && targetAIController.m_mover != null)
  3143.             {
  3144.                 num += targetAIController.m_mover.Radius;
  3145.             }
  3146.             return num;
  3147.         }
  3148.  
  3149.         protected float GetAttackArrivalDistance(AttackBase attack, Destructible targetDestructible)
  3150.         {
  3151.             if (attack == null)
  3152.             {
  3153.                 return 0.1f;
  3154.             }
  3155.             float num = attack.TotalAttackDistance;
  3156.             if (this.m_mover != null && attack is AttackMelee)
  3157.             {
  3158.                 num += this.m_mover.Radius;
  3159.             }
  3160.             if (targetDestructible)
  3161.             {
  3162.                 num += targetDestructible.Radius;
  3163.             }
  3164.             return num;
  3165.         }
  3166.  
  3167.         protected AttackBase GetPrimaryAttack()
  3168.         {
  3169.             if (this.m_equipment == null)
  3170.             {
  3171.                 return null;
  3172.             }
  3173.             if (this.m_equipment != null)
  3174.             {
  3175.                 AttackBase primaryAttack = this.m_equipment.PrimaryAttack;
  3176.                 if (primaryAttack != null)
  3177.                 {
  3178.                     return primaryAttack;
  3179.                 }
  3180.                 AttackBase secondaryAttack = this.m_equipment.SecondaryAttack;
  3181.                 if (secondaryAttack != null)
  3182.                 {
  3183.                     return secondaryAttack;
  3184.                 }
  3185.                 EquipmentSet currentItems = this.m_equipment.CurrentItems;
  3186.                 if (currentItems != null)
  3187.                 {
  3188.                     for (int i = 0; i < currentItems.WeaponSets.Length; i++)
  3189.                     {
  3190.                         WeaponSet weaponSet = currentItems.WeaponSets[i];
  3191.                         if (!WeaponSet.IsNullOrEmpty(weaponSet))
  3192.                         {
  3193.                             if (weaponSet.PrimaryWeapon != null)
  3194.                             {
  3195.                                 AttackBase attack = weaponSet.PrimaryWeapon.Attack;
  3196.                                 if (attack != null)
  3197.                                 {
  3198.                                     return attack;
  3199.                                 }
  3200.                             }
  3201.                             if (weaponSet.SecondaryWeapon != null)
  3202.                             {
  3203.                                 AttackBase attack2 = weaponSet.SecondaryWeapon.Attack;
  3204.                                 if (attack2 != null)
  3205.                                 {
  3206.                                     return attack2;
  3207.                                 }
  3208.                             }
  3209.                         }
  3210.                     }
  3211.                 }
  3212.             }
  3213.             AttackBase primaryUnarmedAttack = this.m_characterStats.PrimaryUnarmedAttack;
  3214.             if (primaryUnarmedAttack != null)
  3215.             {
  3216.                 return primaryUnarmedAttack;
  3217.             }
  3218.             return null;
  3219.         }
  3220.  
  3221.         protected static AttackBase GetPrimaryAttack(GameObject owner)
  3222.         {
  3223.             if (owner == null)
  3224.             {
  3225.                 return null;
  3226.             }
  3227.             AIController component = owner.GetComponent<AIController>();
  3228.             if (component != null)
  3229.             {
  3230.                 return component.GetPrimaryAttack();
  3231.             }
  3232.             CharacterStats component2 = owner.GetComponent<CharacterStats>();
  3233.             if (component2 != null)
  3234.             {
  3235.                 return component2.PrimaryUnarmedAttack;
  3236.             }
  3237.             return null;
  3238.         }
  3239.  
  3240.         protected void ResetPrimaryAttackReevaluationTimer()
  3241.         {
  3242.             this.m_primaryAttackReevaluationTimer = GlobalGameSettingsGameData.Instance.PrimaryAttackReevaluationInterval;
  3243.         }
  3244.  
  3245.         protected AttackBase GetSecondaryAttack()
  3246.         {
  3247.             if (this.m_equipment != null)
  3248.             {
  3249.                 return this.m_equipment.SecondaryAttack;
  3250.             }
  3251.             return null;
  3252.         }
  3253.  
  3254.         protected AttackBase GetDesiredAttack(GameObject target)
  3255.         {
  3256.             AttackBase primaryAttack = this.GetPrimaryAttack();
  3257.             AttackBase secondaryAttack = this.GetSecondaryAttack();
  3258.             if (secondaryAttack == null)
  3259.             {
  3260.                 return primaryAttack;
  3261.             }
  3262.             if (target != null && !AIController.AreAttacksCompatible(primaryAttack, secondaryAttack))
  3263.             {
  3264.                 return this.PickValidAttack(primaryAttack, secondaryAttack, target);
  3265.             }
  3266.             if (primaryAttack == this.m_previousAttack)
  3267.             {
  3268.                 return secondaryAttack;
  3269.             }
  3270.             return primaryAttack;
  3271.         }
  3272.  
  3273.         protected AttackBase GetOtherAttack(AttackBase attack)
  3274.         {
  3275.             if (this.GetPrimaryAttack() == attack)
  3276.             {
  3277.                 return this.GetSecondaryAttack();
  3278.             }
  3279.             if (this.GetSecondaryAttack() == attack)
  3280.             {
  3281.                 return this.GetPrimaryAttack();
  3282.             }
  3283.             return null;
  3284.         }
  3285.  
  3286.         protected static bool AreAttacksCompatible(AttackBase primaryAttack, AttackBase secondaryAttack)
  3287.         {
  3288.             return (!(primaryAttack is AttackRanged) || !(secondaryAttack is AttackMelee)) && (!(secondaryAttack is AttackRanged) || !(primaryAttack is AttackMelee));
  3289.         }
  3290.  
  3291.         protected AttackBase PickValidAttack(AttackBase primaryAttack, AttackBase secondaryAttack, GameObject target)
  3292.         {
  3293.             float num = this.m_mover.Radius;
  3294.             Mover component = ComponentUtils.GetComponent<Mover>(target);
  3295.             if (component != null)
  3296.             {
  3297.                 num += component.Radius;
  3298.             }
  3299.             else
  3300.             {
  3301.                 num += GlobalGameSettingsGameData.Instance.MinimumMoverRadius;
  3302.             }
  3303.             float num2 = Onyx.Math.Distance2D(base.get_transform().get_position(), target.get_transform().get_position()) - num;
  3304.             if (num2 > GlobalGameSettingsGameData.Instance.CombatSettingsComponent.RangedAutoAttackDistance)
  3305.             {
  3306.                 if (primaryAttack is AttackRanged)
  3307.                 {
  3308.                     return primaryAttack;
  3309.                 }
  3310.                 return secondaryAttack;
  3311.             }
  3312.             else
  3313.             {
  3314.                 if (primaryAttack is AttackMelee)
  3315.                 {
  3316.                     return primaryAttack;
  3317.                 }
  3318.                 return secondaryAttack;
  3319.             }
  3320.         }
  3321.  
  3322.         protected void PerformDesiredAttack(GameObject target)
  3323.         {
  3324.             this.m_previousAttack = this.GetDesiredAttack(target);
  3325.         }
  3326.  
  3327.         protected AttackFirearm GetDesiredFirearmAttack()
  3328.         {
  3329.             return this.GetDesiredAttack(this.CurrentTarget) as AttackFirearm;
  3330.         }
  3331.  
  3332.         protected AttackBase GetCurrentAttack()
  3333.         {
  3334.             for (int i = this.BehaviorStack.BehaviorCount - 1; i >= 0; i--)
  3335.             {
  3336.                 AIBehavior behavior = this.BehaviorStack.GetBehavior(i);
  3337.                 PreparingToActParams preparingToActParams = behavior.AIParams as PreparingToActParams;
  3338.                 if (preparingToActParams != null)
  3339.                 {
  3340.                     Game.AI.Action action = preparingToActParams.CurrentAction;
  3341.                     if (action == null)
  3342.                     {
  3343.                         action = preparingToActParams.ForcedAction;
  3344.                     }
  3345.                     if (action != null)
  3346.                     {
  3347.                         return action.Attack;
  3348.                     }
  3349.                 }
  3350.                 else
  3351.                 {
  3352.                     AIBehaviorType behaviorType = (behavior.AIBehaviorData.Component as AIBehaviorDataComponent).BehaviorType;
  3353.                     if (behaviorType == AIBehaviorType.QueuedAction)
  3354.                     {
  3355.                         return null;
  3356.                     }
  3357.                     ActionParams actionParams = behavior.AIParams as ActionParams;
  3358.                     if (actionParams != null && actionParams.CurrentAction != null)
  3359.                     {
  3360.                         return actionParams.CurrentAction.Attack;
  3361.                     }
  3362.                 }
  3363.             }
  3364.             return null;
  3365.         }
  3366.  
  3367.         protected GenericAbility GetCurrentAbility()
  3368.         {
  3369.             for (int i = this.BehaviorStack.BehaviorCount - 1; i >= 0; i--)
  3370.             {
  3371.                 AIBehavior behavior = this.BehaviorStack.GetBehavior(i);
  3372.                 PreparingToActParams preparingToActParams = behavior.AIParams as PreparingToActParams;
  3373.                 if (preparingToActParams != null)
  3374.                 {
  3375.                     Game.AI.Action action = preparingToActParams.CurrentAction;
  3376.                     if (action == null)
  3377.                     {
  3378.                         action = preparingToActParams.ForcedAction;
  3379.                     }
  3380.                     if (action != null)
  3381.                     {
  3382.                         return action.Ability;
  3383.                     }
  3384.                 }
  3385.                 else
  3386.                 {
  3387.                     AIBehaviorType behaviorType = (behavior.AIBehaviorData.Component as AIBehaviorDataComponent).BehaviorType;
  3388.                     if (behaviorType == AIBehaviorType.QueuedAction)
  3389.                     {
  3390.                         return null;
  3391.                     }
  3392.                     ActionParams actionParams = behavior.AIParams as ActionParams;
  3393.                     if (actionParams != null && actionParams.CurrentAction != null)
  3394.                     {
  3395.                         return actionParams.CurrentAction.Ability;
  3396.                     }
  3397.                 }
  3398.             }
  3399.             return null;
  3400.         }
  3401.  
  3402.         protected GenericAbility GetCurrentIntroStateAbility()
  3403.         {
  3404.             AttackIntroState attackIntroState = (this.BehaviorStack.CurrentBehavior == null) ? null : (this.BehaviorStack.CurrentBehavior.CurrentState as AttackIntroState);
  3405.             if (attackIntroState == null)
  3406.             {
  3407.                 return null;
  3408.             }
  3409.             ActionParams actionParams = attackIntroState.Params as ActionParams;
  3410.             if (actionParams != null && actionParams.CurrentAttack != null && actionParams.CurrentAttack.AbilityOrigin != null)
  3411.             {
  3412.                 return actionParams.CurrentAttack.AbilityOrigin;
  3413.             }
  3414.             return null;
  3415.         }
  3416.  
  3417.         protected bool IsAbilityQueued(GenericAbility ability, bool includeQueuedActions)
  3418.         {
  3419.             for (int i = this.BehaviorStack.BehaviorCount - 1; i > 0; i--)
  3420.             {
  3421.                 AIBehavior behavior = this.BehaviorStack.GetBehavior(i);
  3422.                 AIBehaviorType behaviorType = (behavior.AIBehaviorData.Component as AIBehaviorDataComponent).BehaviorType;
  3423.                 if (behaviorType == AIBehaviorType.Cast || behaviorType == AIBehaviorType.ConsumePotion || includeQueuedActions)
  3424.                 {
  3425.                     ActionParams actionParams = behavior.AIParams as ActionParams;
  3426.                     if (actionParams != null)
  3427.                     {
  3428.                         Game.AI.Action currentAction = actionParams.CurrentAction;
  3429.                         if (currentAction != null && currentAction.Ability == ability)
  3430.                         {
  3431.                             return true;
  3432.                         }
  3433.                     }
  3434.                 }
  3435.                 else if (behaviorType == AIBehaviorType.PreparingToAct)
  3436.                 {
  3437.                     PreparingToActParams preparingToActParams = behavior.AIParams as PreparingToActParams;
  3438.                     if (preparingToActParams != null)
  3439.                     {
  3440.                         Game.AI.Action action = preparingToActParams.CurrentAction;
  3441.                         if (action == null)
  3442.                         {
  3443.                             action = preparingToActParams.ForcedAction;
  3444.                         }
  3445.                         if (action != null && action.Ability == ability)
  3446.                         {
  3447.                             return true;
  3448.                         }
  3449.                     }
  3450.                 }
  3451.             }
  3452.             return false;
  3453.         }
  3454.  
  3455.         protected bool IsInCombatAgainstParty()
  3456.         {
  3457.             Faction component = base.GetComponent<Faction>();
  3458.             if (component != null && component.IsDominated)
  3459.             {
  3460.                 return true;
  3461.             }
  3462.             AIBehavior behavior = this.GetBehavior(AIBehaviorType.PreparingToAct);
  3463.             if (behavior != null)
  3464.             {
  3465.                 PreparingToActParams preparingToActParams = behavior.AIParams as PreparingToActParams;
  3466.                 if (preparingToActParams != null)
  3467.                 {
  3468.                     return preparingToActParams.IsAttackingParty;
  3469.                 }
  3470.             }
  3471.             return false;
  3472.         }
  3473.  
  3474.         protected void StopCombat()
  3475.         {
  3476.             this.m_delayedCombatParams.Reset();
  3477.             this.BehaviorStack.ClearQueuedBehaviors(true);
  3478.             this.BehaviorStack.PopAllBehaviorsBelowPriority(7);
  3479.             AIBehavior currentBehavior = this.BehaviorStack.CurrentBehavior;
  3480.             AIBehaviorType currentBehaviorType = this.GetCurrentBehaviorType();
  3481.             if (currentBehaviorType == AIBehaviorType.KnockedDown)
  3482.             {
  3483.                 KnockedDownState knockedDownState = currentBehavior.CurrentState as KnockedDownState;
  3484.                 if (knockedDownState != null)
  3485.                 {
  3486.                     knockedDownState.Clear();
  3487.                 }
  3488.             }
  3489.             else if (currentBehaviorType == AIBehaviorType.Unconscious)
  3490.             {
  3491.                 UnconsciousState unconsciousState = currentBehavior.CurrentState as UnconsciousState;
  3492.                 if (unconsciousState != null)
  3493.                 {
  3494.                     unconsciousState.Clear();
  3495.                 }
  3496.             }
  3497.             AIBehavior behavior = AIBehaviorManager.AllocateIdleBehavior();
  3498.             this.BehaviorStack.QueueBehavior(behavior);
  3499.             StatusEffectManager component = base.GetComponent<StatusEffectManager>();
  3500.             if (component != null)
  3501.             {
  3502.                 component.HandleOnCombatEnd();
  3503.             }
  3504.             this.MustDieForCombatToEnd = false;
  3505.         }
  3506.  
  3507.         protected void BeginCooldown(Guid decisionTreeID, int nodeID)
  3508.         {
  3509.             ActionCooldown[] array = null;
  3510.             if (this.Cooldowns.TryGetValue(decisionTreeID, out array) && nodeID >= 0 && nodeID < array.Length)
  3511.             {
  3512.                 array[nodeID].BeginCooldown();
  3513.             }
  3514.         }
  3515.  
  3516.         protected void ClearCooldowns()
  3517.         {
  3518.             foreach (ActionCooldown[] current in this.m_cooldowns.Values)
  3519.             {
  3520.                 for (int i = 0; i < current.Length; i++)
  3521.                 {
  3522.                     current[i].Reset();
  3523.                 }
  3524.             }
  3525.         }
  3526.  
  3527.         protected void StartHoldTimer()
  3528.         {
  3529.             if (this.m_holdMove && this.IsInCombat && this.m_partyMember != null)
  3530.             {
  3531.                 this.m_holdTimer = GlobalGameSettingsGameData.Instance.DefaultHoldTime;
  3532.             }
  3533.             this.m_holdMove = false;
  3534.         }
  3535.  
  3536.         protected void ResetHoldTimer()
  3537.         {
  3538.             this.m_holdTimer = 0f;
  3539.             this.m_holdMove = false;
  3540.         }
  3541.  
  3542.         protected void SetHoldMove()
  3543.         {
  3544.             if (this.IsInCombat)
  3545.             {
  3546.                 this.m_holdMove = true;
  3547.             }
  3548.         }
  3549.  
  3550.         protected void HandleCombatStart()
  3551.         {
  3552.             if (this.m_alphaControl != null && this.m_health != null && this.m_health.IsTargetable())
  3553.             {
  3554.                 this.CacheAlphaControl(false);
  3555.                 this.m_alphaControl.EnableOcclusion(true);
  3556.             }
  3557.         }
  3558.  
  3559.         protected void HandleCombatEnd()
  3560.         {
  3561.             if (this.m_partyMember != null)
  3562.             {
  3563.                 this.PopAllBehaviorsOfType(AIBehaviorType.PreparingToAct);
  3564.             }
  3565.             else if (this.m_alphaControl != null)
  3566.             {
  3567.                 this.m_alphaControl.EnableOcclusion(false);
  3568.             }
  3569.             this.m_previousAttack = null;
  3570.             this.ResetHoldTimer();
  3571.             AIController.ReloadFirearms(base.get_gameObject());
  3572.             this.CLearTargetTracking();
  3573.         }
  3574.  
  3575.         protected static void ReloadFirearms(GameObject owner)
  3576.         {
  3577.             if (owner == null)
  3578.             {
  3579.                 return;
  3580.             }
  3581.             Equipment component = owner.GetComponent<Equipment>();
  3582.             if (component != null)
  3583.             {
  3584.                 EquipmentSet currentItems = component.CurrentItems;
  3585.                 if (currentItems != null)
  3586.                 {
  3587.                     for (int i = 0; i < currentItems.WeaponSets.Length; i++)
  3588.                     {
  3589.                         WeaponSet weaponSet = currentItems.WeaponSets[i];
  3590.                         if (weaponSet.PrimaryWeapon != null)
  3591.                         {
  3592.                             AttackFirearm attackFirearm = weaponSet.PrimaryWeapon.Attack as AttackFirearm;
  3593.                             if (attackFirearm != null)
  3594.                             {
  3595.                                 attackFirearm.Reload();
  3596.                             }
  3597.                         }
  3598.                         if (weaponSet.SecondaryWeapon != null)
  3599.                         {
  3600.                             AttackFirearm attackFirearm2 = weaponSet.SecondaryWeapon.Attack as AttackFirearm;
  3601.                             if (attackFirearm2 != null)
  3602.                             {
  3603.                                 attackFirearm2.Reload();
  3604.                             }
  3605.                         }
  3606.                     }
  3607.                 }
  3608.             }
  3609.         }
  3610.  
  3611.         protected void RecordRetreatPosition(Vector3 position)
  3612.         {
  3613.             this.m_retreatPosition = position;
  3614.         }
  3615.  
  3616.         protected bool CanBeTethered()
  3617.         {
  3618.             return this.IsTethered && this.m_retreatPosition.get_sqrMagnitude() >= 1.401298E-45f && !(this.m_partyMember != null);
  3619.         }
  3620.  
  3621.         protected bool IsBeingKited()
  3622.         {
  3623.             if (!this.CanBeTethered())
  3624.             {
  3625.                 return false;
  3626.             }
  3627.             GameObject currentTarget = this.CurrentTarget;
  3628.             if (currentTarget == null)
  3629.             {
  3630.                 return false;
  3631.             }
  3632.             AIController component = currentTarget.GetComponent<AIController>();
  3633.             if (component == null)
  3634.             {
  3635.                 return false;
  3636.             }
  3637.             if (this.m_faction != null && !this.m_faction.IsHostile(component.m_faction))
  3638.             {
  3639.                 return false;
  3640.             }
  3641.             if (!component.Mover.IsMoving)
  3642.             {
  3643.                 return false;
  3644.             }
  3645.             if (this.Mover != null && component.Mover != null && this.Mover.DesiredSpeed > component.Mover.DesiredSpeed)
  3646.             {
  3647.                 return false;
  3648.             }
  3649.             float num = Onyx.Math.Distance2DSquared(base.get_transform().get_position(), component.get_transform().get_position());
  3650.             float num2 = Onyx.Math.Distance2DSquared(base.get_transform().get_position(), this.m_retreatPosition);
  3651.             if (num2 > this.TetherDistanceSq)
  3652.             {
  3653.                 if (num < GlobalGameSettingsGameData.Instance.AISettingsComponent.KiteTargetFarMinimumDistanceSq)
  3654.                 {
  3655.                     return false;
  3656.                 }
  3657.             }
  3658.             else
  3659.             {
  3660.                 if (num2 < this.TetherDistanceSq * 0.33f)
  3661.                 {
  3662.                     return false;
  3663.                 }
  3664.                 if (num < GlobalGameSettingsGameData.Instance.AISettingsComponent.KiteTargetNearMinimumDistanceSq)
  3665.                 {
  3666.                     return false;
  3667.                 }
  3668.             }
  3669.             return true;
  3670.         }
  3671.  
  3672.         protected void AddCurrentTargetToKiteIgnoreList()
  3673.         {
  3674.             GameObject currentTarget = this.CurrentTarget;
  3675.             if (currentTarget == null)
  3676.             {
  3677.                 return;
  3678.             }
  3679.             Faction component = currentTarget.GetComponent<Faction>();
  3680.             if (component == null)
  3681.             {
  3682.                 return;
  3683.             }
  3684.             this.m_kiteTargets.Add(new AIController.KiteTarget(component));
  3685.         }
  3686.  
  3687.         protected bool IsInTetherRange(Faction target)
  3688.         {
  3689.             float distanceToTargetSq = Onyx.Math.Distance2DSquared(base.get_transform().get_position(), target.get_transform().get_position());
  3690.             return this.IsInTetherRangePrecomputed(target, distanceToTargetSq);
  3691.         }
  3692.  
  3693.         protected bool IsInTetherRangePrecomputed(Faction target, float distanceToTargetSq)
  3694.         {
  3695.             if (this.IsInKiteIgnoreList(target))
  3696.             {
  3697.                 return false;
  3698.             }
  3699.             float num = Onyx.Math.Distance2DSquared(target.get_transform().get_position(), this.RetreatPosition);
  3700.             return num <= this.TetherDistanceSq || distanceToTargetSq <= GlobalGameSettingsGameData.Instance.AISettingsComponent.KiteTargetFarMinimumDistanceSq;
  3701.         }
  3702.  
  3703.         protected bool IsInKiteIgnoreList(Faction target)
  3704.         {
  3705.             if (this.m_kiteTargets.Count > 0)
  3706.             {
  3707.                 for (int i = 0; i < this.m_kiteTargets.Count; i++)
  3708.                 {
  3709.                     if (this.m_kiteTargets[i].Target == target)
  3710.                     {
  3711.                         return true;
  3712.                     }
  3713.                 }
  3714.             }
  3715.             return false;
  3716.         }
  3717.  
  3718.         protected void SetParentEncounter(Encounter encounter)
  3719.         {
  3720.             this.m_parentEncounter = encounter;
  3721.         }
  3722.  
  3723.         protected void UpdateMustDieForCombatToEnd()
  3724.         {
  3725.             if (this.m_mustDieForCombatToEnd)
  3726.             {
  3727.                 return;
  3728.             }
  3729.             if (this.m_parentEncounter != null)
  3730.             {
  3731.                 this.m_parentEncounter.SetMustDieForCombatToEndFlags();
  3732.             }
  3733.             else if (this.CombatEndsOnDeath)
  3734.             {
  3735.                 this.MustDieForCombatToEnd = true;
  3736.             }
  3737.             else if (this.Faction.GetRelationshipToPlayer() == Relationship.Hostile && !this.Faction.IsDominated && GodChallengeGameData.AnyEnabledChallenge(GodChallengeGameData.CannotFleeCombatPredicate))
  3738.             {
  3739.                 this.MustDieForCombatToEnd = true;
  3740.             }
  3741.         }
  3742.  
  3743.         protected void MarkSummonsMustDieForCombatToEnd()
  3744.         {
  3745.             for (int i = 0; i < this.m_summonedCreatures.Count; i++)
  3746.             {
  3747.                 AIController component = ComponentUtils.GetComponent<AIController>(this.m_summonedCreatures[i]);
  3748.                 if (component != null)
  3749.                 {
  3750.                     component.m_mustDieForCombatToEnd = true;
  3751.                 }
  3752.             }
  3753.         }
  3754.  
  3755.         protected void InterruptAnimationForCutscene()
  3756.         {
  3757.             if (this.m_animController != null)
  3758.             {
  3759.                 this.m_animController.PlayReaction(ReactionType.None);
  3760.                 this.m_animController.ClearReactions();
  3761.                 if (!this.m_animController.IsPlayingIdle && this.GetCurrentBehaviorType() != AIBehaviorType.Emerge)
  3762.                 {
  3763.                     this.m_animController.Interrupt();
  3764.                 }
  3765.                 this.m_animController.Loop = false;
  3766.                 this.m_animController.ClearAnimationTypes();
  3767.                 this.m_animController.ClearCurrentAnimation();
  3768.             }
  3769.         }
  3770.  
  3771.         protected AIBehaviorType GetCurrentBehaviorType()
  3772.         {
  3773.             if (this.BehaviorStack.CurrentBehavior == null)
  3774.             {
  3775.                 return AIBehaviorType.None;
  3776.             }
  3777.             return (this.BehaviorStack.CurrentBehavior.AIBehaviorData.Component as AIBehaviorDataComponent).BehaviorType;
  3778.         }
  3779.  
  3780.         protected AIBehavior GetBehavior(AIBehaviorType behaviorType)
  3781.         {
  3782.             for (int i = this.BehaviorStack.BehaviorCount - 1; i >= 0; i--)
  3783.             {
  3784.                 AIBehavior behavior = this.BehaviorStack.GetBehavior(i);
  3785.                 if ((behavior.AIBehaviorData.Component as AIBehaviorDataComponent).BehaviorType == behaviorType)
  3786.                 {
  3787.                     return behavior;
  3788.                 }
  3789.             }
  3790.             return null;
  3791.         }
  3792.  
  3793.         protected AIBehavior GetCurrentBehaviorOrSubBehavior()
  3794.         {
  3795.             AIBehavior currentBehavior = this.BehaviorStack.CurrentBehavior;
  3796.             if (currentBehavior == null)
  3797.             {
  3798.                 return null;
  3799.             }
  3800.             if (currentBehavior.CurrentState != null && currentBehavior.CurrentState.SubBehavior != null)
  3801.             {
  3802.                 return currentBehavior.CurrentState.SubBehavior;
  3803.             }
  3804.             return currentBehavior;
  3805.         }
  3806.  
  3807.         protected bool CancelAndLoseCurrentAction(bool isInterrupt)
  3808.         {
  3809.             GenericAbility genericAbility;
  3810.             return this.CancelAndLoseCurrentAction(isInterrupt, out genericAbility);
  3811.         }
  3812.  
  3813.         protected bool CancelAndLoseCurrentAction(bool isInterrupt, out GenericAbility interruptedAbility)
  3814.         {
  3815.             AIBehaviorType currentBehaviorType = this.GetCurrentBehaviorType();
  3816.             if (currentBehaviorType == AIBehaviorType.Attack || currentBehaviorType == AIBehaviorType.Cast || currentBehaviorType == AIBehaviorType.ConsumePotion || currentBehaviorType == AIBehaviorType.Grapple)
  3817.             {
  3818.                 interruptedAbility = null;
  3819.                 ActionParams actionParams = this.BehaviorStack.CurrentBehavior.AIParams as ActionParams;
  3820.                 if (actionParams != null)
  3821.                 {
  3822.                     if (currentBehaviorType == AIBehaviorType.Cast)
  3823.                     {
  3824.                         CastAction castAction = actionParams.CurrentAction as CastAction;
  3825.                         if (castAction != null && castAction.Ability != null && !castAction.IsActionFinished && isInterrupt)
  3826.                         {
  3827.                             castAction.Ability.ConsumeResources();
  3828.                             interruptedAbility = castAction.Ability;
  3829.                         }
  3830.                     }
  3831.                     else if (currentBehaviorType == AIBehaviorType.ConsumePotion)
  3832.                     {
  3833.                         ConsumeItemAction consumeItemAction = actionParams.CurrentAction as ConsumeItemAction;
  3834.                         if (consumeItemAction != null && consumeItemAction.Ability != null && !consumeItemAction.IsAbilityTriggered && isInterrupt)
  3835.                         {
  3836.                             consumeItemAction.Ability.ConsumeResources();
  3837.                             interruptedAbility = consumeItemAction.Ability;
  3838.                         }
  3839.                     }
  3840.                     actionParams.CurrentAction.IsActionFinished = true;
  3841.                 }
  3842.                 this.BehaviorStack.PopCurrentBehavior();
  3843.                 Equipment component = base.GetComponent<Equipment>();
  3844.                 if (component != null)
  3845.                 {
  3846.                     component.ShowSlot(EquipmentSlot.PrimaryWeapon);
  3847.                     component.ShowSlot(EquipmentSlot.SecondaryWeapon);
  3848.                 }
  3849.                 return true;
  3850.             }
  3851.             interruptedAbility = null;
  3852.             return false;
  3853.         }
  3854.  
  3855.         protected bool CancelGrappleBehavior()
  3856.         {
  3857.             if (this.GetCurrentBehaviorType() == AIBehaviorType.Grapple)
  3858.             {
  3859.                 this.BehaviorStack.PopCurrentBehavior();
  3860.                 this.m_animController.Interrupt();
  3861.                 return true;
  3862.             }
  3863.             return false;
  3864.         }
  3865.  
  3866.         protected bool IsCurrentBehaviorUsingWeapon()
  3867.         {
  3868.             AIBehaviorType currentBehaviorType = this.GetCurrentBehaviorType();
  3869.             if (currentBehaviorType == AIBehaviorType.Attack || currentBehaviorType == AIBehaviorType.Cast)
  3870.             {
  3871.                 ActionParams actionParams = this.BehaviorStack.CurrentBehavior.AIParams as ActionParams;
  3872.                 if (actionParams != null && actionParams.CurrentAction != null && actionParams.CurrentAction.Attack != null)
  3873.                 {
  3874.                     return actionParams.CurrentAction.Attack.IsNormalAttack;
  3875.                 }
  3876.             }
  3877.             return false;
  3878.         }
  3879.  
  3880.         protected void PopAllBehaviorsOfType(AIBehaviorType type)
  3881.         {
  3882.             for (int i = this.BehaviorStack.BehaviorCount - 1; i > 0; i--)
  3883.             {
  3884.                 AIBehavior behavior = this.BehaviorStack.GetBehavior(i);
  3885.                 AIBehaviorType behaviorType = (behavior.AIBehaviorData.Component as AIBehaviorDataComponent).BehaviorType;
  3886.                 if (behaviorType == type)
  3887.                 {
  3888.                     this.BehaviorStack.PopBehavior(behavior);
  3889.                 }
  3890.             }
  3891.         }
  3892.  
  3893.         protected void SafePopAllBehaviors(bool force = true)
  3894.         {
  3895.             this.BehaviorStack.ClearQueuedBehaviors(force);
  3896.             AIBehavior currentBehavior = this.BehaviorStack.CurrentBehavior;
  3897.             if (currentBehavior != null && currentBehavior.Priority < 3 && this.GetCurrentBehaviorType() != AIBehaviorType.Standup && (force || currentBehavior.CanBeCancelledByUser))
  3898.             {
  3899.                 this.BehaviorStack.PopAllBehaviors();
  3900.             }
  3901.             this.m_delayedCombatParams.Reset();
  3902.         }
  3903.  
  3904.         protected override void OnyxGUI()
  3905.         {
  3906.             base.OnyxGUI();
  3907.             if (AIController.DebugEngagement)
  3908.             {
  3909.                 this.DrawEngagementDebug();
  3910.             }
  3911.             if (AIController.m_debugMode == AIController.DebugMode.Shout || Stealth.DebuggingStealth)
  3912.             {
  3913.                 bool flag = this.IsFogVisible;
  3914.                 if (!flag)
  3915.                 {
  3916.                     float num = GameUtilities.NearestPlayerSquaredDist(base.get_transform().get_position());
  3917.                     float perceptionDistance = this.PerceptionDistance;
  3918.                     if (num < perceptionDistance * perceptionDistance * 9f)
  3919.                     {
  3920.                         flag = true;
  3921.                     }
  3922.                 }
  3923.                 if (flag)
  3924.                 {
  3925.                     if (AIController.m_debugMode == AIController.DebugMode.Shout && this.m_debugShoutTimer > 0f)
  3926.                     {
  3927.                         Camera mainCamera = OnyxMainCamera.MainCamera;
  3928.                         GUI.set_color((!this.m_debugShoutOrigin) ? new Color(1f, 0.8f, 0.5f) : new Color(1f, 0.5f, 0f));
  3929.                         GUIHelper.DrawCircle(base.get_transform().get_position(), this.ShoutRange, GUI.get_color());
  3930.                         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());
  3931.                         Vector3 vector = base.get_transform().get_position();
  3932.                         vector = mainCamera.WorldToScreenPoint(vector);
  3933.                         vector.y = (float)mainCamera.get_pixelHeight() - vector.y;
  3934.                         GUI.Label(new Rect(vector.x, vector.y, (float)Screen.get_width(), (float)Screen.get_height()), (!this.m_debugShoutOrigin) ? "Shout Relay" : "Shout");
  3935.                         GUI.set_color(Color.get_white());
  3936.                     }
  3937.                     if (Stealth.DebuggingStealth)
  3938.                     {
  3939.                         GUIHelper.DrawCircle(base.get_transform().get_position(), this.StealthedCharacterHearingDistance, Color.get_magenta());
  3940.                         GUIHelper.DrawCircle(base.get_transform().get_position(), this.PerceptionDistance, Color.get_yellow());
  3941.                         GUIHelper.DrawTargetingCone(base.get_transform().get_position(), base.get_transform().get_forward(), this.StealthedCharacterVisionDistance, this.StealthedCharacterVisionAngle, Color.get_blue());
  3942.                     }
  3943.                 }
  3944.             }
  3945.             bool flag2 = AIController.m_debugMode == AIController.DebugMode.All || (AIController.m_debugMode == AIController.DebugMode.MouseOver && GameCursor.ObjectUnderCursor == base.get_gameObject());
  3946.             if (flag2 && this.BehaviorStack != null && this.BehaviorStack.CurrentBehavior != null)
  3947.             {
  3948.                 Camera mainCamera2 = OnyxMainCamera.MainCamera;
  3949.                 Vector3 vector2 = base.get_transform().get_position();
  3950.                 vector2.y += 2.5f;
  3951.                 vector2 = mainCamera2.WorldToScreenPoint(vector2);
  3952.                 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()))
  3953.                 {
  3954.                     return;
  3955.                 }
  3956.                 string text = base.get_name();
  3957.                 if (this.IsFighting)
  3958.                 {
  3959.                     text += "\nIn Combat";
  3960.                     for (int i = 0; i < this.DecisionTrees.Count; i++)
  3961.                     {
  3962.                         text = text + ", " + this.DecisionTrees[i].DebugName;
  3963.                     }
  3964.                 }
  3965.                 string debugText = this.BehaviorStack.CurrentBehavior.GetDebugText();
  3966.                 string text2 = string.Empty;
  3967.                 string debugText2 = this.BehaviorStack.GetDebugText();
  3968.                 string text3 = debugText2.Substring(0, debugText2.IndexOf('\n'));
  3969.                 string text4 = debugText2.Substring(debugText2.IndexOf('\n'));
  3970.                 if (this.BehaviorStack.CurrentBehavior.CurrentState != null)
  3971.                 {
  3972.                     text2 = this.BehaviorStack.CurrentBehavior.CurrentState.GetDebugText();
  3973.                 }
  3974.                 float num2 = 200f;
  3975.                 float num3 = 0f;
  3976.                 GUIStyle gUIStyle = new GUIStyle(GUI.get_skin().get_label());
  3977.                 gUIStyle.set_wordWrap(false);
  3978.                 gUIStyle.set_padding(new RectOffset(0, 0, 1, 1));
  3979.                 gUIStyle.get_normal().set_textColor(Color.get_white());
  3980.                 gUIStyle.set_fontSize(10);
  3981.                 Vector2 vector3 = vector2;
  3982.                 gUIStyle.set_alignment(1);
  3983.                 gUIStyle.set_fontStyle(1);
  3984.                 Vector2 size = gUIStyle.CalcSize(new GUIContent(text));
  3985.                 Vector2 position = vector3 - new Vector2(num2 / 2f, size.y);
  3986.                 gUIStyle.set_alignment(0);
  3987.                 Vector2 size2 = gUIStyle.CalcSize(new GUIContent(text3));
  3988.                 size2.x = num2 * 0.4f;
  3989.                 Vector2 vector4 = new Vector2(vector3.x - 0.1f * num2, position.y);
  3990.                 Vector2 size3 = gUIStyle.CalcSize(new GUIContent(debugText));
  3991.                 Vector2 position2 = vector4 - new Vector2(0f, size3.y + 4f);
  3992.                 Vector2 size4 = gUIStyle.CalcSize(new GUIContent(text2));
  3993.                 num3 = System.Math.Max(num3, vector2.y - (position2.y - size4.y));
  3994.                 Vector2 position3 = new Vector2(position.x, vector2.y - num3 + 10f);
  3995.                 gUIStyle.set_fontStyle(0);
  3996.                 Vector2 size5 = gUIStyle.CalcSize(new GUIContent(text4));
  3997.                 num3 = System.Math.Max(num3, vector2.y - (position3.y - size5.y));
  3998.                 GUI.set_depth((int)(100000f * (base.get_transform().get_position() - mainCamera2.get_transform().get_position()).get_sqrMagnitude()));
  3999.                 GUI.Box(new Rect(vector2.x - num2 / 2f, (float)mainCamera2.get_pixelHeight() - vector2.y, num2, num3), string.Empty);
  4000.                 gUIStyle.set_alignment(1);
  4001.                 gUIStyle.set_fontStyle(1);
  4002.                 this.DrawLabel(text, vector3, size, gUIStyle, mainCamera2);
  4003.                 gUIStyle.set_alignment(0);
  4004.                 this.DrawLabel(text3, position, size2, gUIStyle, mainCamera2);
  4005.                 gUIStyle.set_fontStyle(0);
  4006.                 this.DrawLabel(text4, position3, size5, gUIStyle, mainCamera2);
  4007.                 this.DrawLabel(debugText, vector4, size3, gUIStyle, mainCamera2);
  4008.                 this.DrawLabel(text2, position2, size4, gUIStyle, mainCamera2);
  4009.             }
  4010.         }
  4011.  
  4012.         protected void DrawLabel(string text, Vector2 position, Vector2 size, GUIStyle guiStyle, Camera mainCamera)
  4013.         {
  4014.             if (guiStyle.get_alignment() == 1)
  4015.             {
  4016.                 position.x -= size.x / 2f;
  4017.             }
  4018.             GUI.Label(new Rect(position.x, (float)mainCamera.get_pixelHeight() - position.y, size.x, size.y), text, guiStyle);
  4019.         }
  4020.  
  4021.         protected virtual void OnDrawGizmosSelected()
  4022.         {
  4023.             Gizmos.set_color(Color.get_magenta());
  4024.             Gizmos.DrawLine(base.get_transform().get_position(), base.get_transform().get_position() + base.get_transform().get_forward());
  4025.             if (this.m_characterStats != null)
  4026.             {
  4027.                 Gizmos.set_color(Color.get_white());
  4028.                 GUIHelper.GizmoDrawCircle(base.get_transform().get_position(), this.PerceptionDistance);
  4029.             }
  4030.             Gizmos.set_color(Color.get_red());
  4031.             GUIHelper.GizmoDrawCircle(base.get_transform().get_position(), this.ShoutRange);
  4032.         }
  4033.  
  4034.         protected void GetDataObjects(List<IDataObject> dataObjects)
  4035.         {
  4036.             for (int i = 0; i < this.m_decisionTreeReferences.Length; i++)
  4037.             {
  4038.                 dataObjects.Add(this.m_decisionTreeReferences[i].Data);
  4039.             }
  4040.         }
  4041.  
  4042.         protected Guid[] Editor_GetDecisionTreeGuids()
  4043.         {
  4044.             List<Guid> list = new List<Guid>();
  4045.             if (this.m_decisionTreeReferences.Length != 0)
  4046.             {
  4047.                 for (int i = 0; i < this.m_decisionTreeReferences.Length; i++)
  4048.                 {
  4049.                     if (!DataReference.IsNullOrEmpty(this.m_decisionTreeReferences[i]))
  4050.                     {
  4051.                         this.m_decisionTreeReferences[i].AssignBaseReference();
  4052.                         list.Add(this.m_decisionTreeReferences[i].ID);
  4053.                     }
  4054.                 }
  4055.             }
  4056.             CharacterStats component = base.GetComponent<CharacterStats>();
  4057.             if (component != null)
  4058.             {
  4059.                 Guid[] array = component.Editor_GetDecisionTreeGuids();
  4060.                 if (array != null)
  4061.                 {
  4062.                     list.AddRange(array);
  4063.                 }
  4064.             }
  4065.             return list.ToArray();
  4066.         }
  4067.  
  4068.         protected void DisengageUntargetable()
  4069.         {
  4070.             for (int i = this.m_threatenedEnemies.Count - 1; i >= 0; i--)
  4071.             {
  4072.                 if (!this.IsTargetable(this.m_threatenedEnemies[i]))
  4073.                 {
  4074.                     this.CancelThreat(this.m_threatenedEnemies[i]);
  4075.                 }
  4076.             }
  4077.             for (int j = this.m_threatenedBy.Count - 1; j >= 0; j--)
  4078.             {
  4079.                 AIController aIController = this.m_threatenedBy[j];
  4080.                 if (aIController != null && !aIController.AllowOutgoingThreat())
  4081.                 {
  4082.                     this.NotifyEnemyBreaksThreat(aIController);
  4083.                     this.NotifyEnemyBreaksEngagement(aIController);
  4084.                 }
  4085.             }
  4086.         }
  4087.  
  4088.         protected void CheckForInvalidEngagements()
  4089.         {
  4090.             UnityObjectUtilities.RemoveAllNull<AIController>(this.m_engagedEnemies);
  4091.             UnityObjectUtilities.RemoveAllNull<AIController>(this.m_engagedBy);
  4092.             UnityObjectUtilities.RemoveAllNull<AIController>(this.m_threatenedEnemies);
  4093.             UnityObjectUtilities.RemoveAllNull<AIController>(this.m_threatenedBy);
  4094.             this.DisengageUntargetable();
  4095.             for (int i = 0; i < this.m_disengagementTrackers.Count; i++)
  4096.             {
  4097.                 AIController.DisengagementTracker disengagementTracker = this.m_disengagementTrackers[i];
  4098.                 disengagementTracker.WaitDuration += Time.get_deltaTime();
  4099.             }
  4100.         }
  4101.  
  4102.         protected bool AllowIncomingThreat()
  4103.         {
  4104.             AIBehaviorType currentBehaviorType = this.GetCurrentBehaviorType();
  4105.             return currentBehaviorType != AIBehaviorType.PushedBack && currentBehaviorType != AIBehaviorType.Dead && currentBehaviorType != AIBehaviorType.Unconscious && currentBehaviorType != AIBehaviorType.Grabbed;
  4106.         }
  4107.  
  4108.         protected bool AllowOutgoingThreat()
  4109.         {
  4110.             AIBehaviorType currentBehaviorType = this.GetCurrentBehaviorType();
  4111.             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)
  4112.             {
  4113.                 return false;
  4114.             }
  4115.             AIBehavior currentBehavior = this.BehaviorStack.CurrentBehavior;
  4116.             return currentBehaviorType != AIBehaviorType.UseObject || !(currentBehavior.CurrentState is InUseState);
  4117.         }
  4118.  
  4119.         protected void UpdateEngagement(AttackBase attack)
  4120.         {
  4121.             if (GameState.Paused)
  4122.             {
  4123.                 return;
  4124.             }
  4125.             if (!this.AllowIncomingThreat())
  4126.             {
  4127.                 this.BreakIncomingThreats(false);
  4128.             }
  4129.             if (!this.AllowOutgoingThreat())
  4130.             {
  4131.                 this.BreakOutgoingThreats(false);
  4132.                 return;
  4133.             }
  4134.             if (!(attack is AttackMelee))
  4135.             {
  4136.                 return;
  4137.             }
  4138.             if (this.m_faction == null)
  4139.             {
  4140.                 return;
  4141.             }
  4142.             for (int i = this.m_disengagementTrackers.Count - 1; i >= 0; i--)
  4143.             {
  4144.                 if (!this.IsTargetable(this.m_disengagementTrackers[i].Enemy) || this.m_disengagementTrackers[i].WaitDuration >= GlobalGameSettingsGameData.Instance.ReengagementWaitPeriod)
  4145.                 {
  4146.                     this.m_disengagementTrackers.RemoveAt(i);
  4147.                 }
  4148.             }
  4149.             GameObject currentTarget = this.CurrentTarget;
  4150.             this.m_cachedEngagementLimit = ((!this.m_characterStats) ? 0 : this.m_characterStats.GetEngageableEnemyCount());
  4151.             IList<AIController> threatenedEnemies = this.ThreatenedEnemies;
  4152.             for (int j = threatenedEnemies.Count - 1; j >= 0; j--)
  4153.             {
  4154.                 AIController aIController = threatenedEnemies[j];
  4155.                 if (!this.IsTargetable(aIController) || (this.m_mover.IsMoving && currentTarget != aIController.get_gameObject()))
  4156.                 {
  4157.                     this.CancelThreat(aIController);
  4158.                 }
  4159.                 else
  4160.                 {
  4161.                     Faction faction = aIController.Faction;
  4162.                     if (faction && !faction.IsHostile(this.m_faction) && !this.m_faction.IsHostile(aIController.Faction))
  4163.                     {
  4164.                         this.CancelThreat(aIController);
  4165.                     }
  4166.                     else if (this.IsTargetBeingPushedBack(aIController))
  4167.                     {
  4168.                         this.CancelThreat(aIController);
  4169.                     }
  4170.                     else if (!this.IsWithinThreatRange(aIController, attack))
  4171.                     {
  4172.                         Mover component = ComponentUtils.GetComponent<Mover>(aIController);
  4173.                         if (component.IsMoving && !this.m_mover.IsMoving && this.IsEngaging(aIController))
  4174.                         {
  4175.                             this.DisengageEnemy(aIController, attack);
  4176.                         }
  4177.                         else
  4178.                         {
  4179.                             this.CancelThreat(aIController);
  4180.                         }
  4181.                     }
  4182.                 }
  4183.             }
  4184.             AIController aIController2 = null;
  4185.             if (currentTarget != null)
  4186.             {
  4187.                 aIController2 = ComponentUtils.GetComponent<AIController>(currentTarget);
  4188.             }
  4189.             if (aIController2 != null)
  4190.             {
  4191.                 if (!this.IsThreatening(aIController2) && this.CanThreatenEnemy(aIController2, attack))
  4192.                 {
  4193.                     this.ThreatenEnemy(aIController2);
  4194.                 }
  4195.                 if (!this.IsEngaging(aIController2) && this.IsThreatening(aIController2) && this.CanEngageEnemy(aIController2, attack, false))
  4196.                 {
  4197.                     this.EngageEnemy(aIController2);
  4198.                 }
  4199.             }
  4200.             if (this.IsFighting && FogOfWar.IsFullyVisible(base.get_transform().get_position()) && this.EngagedEnemies.Count < this.m_cachedEngagementLimit)
  4201.             {
  4202.                 RangeManager instance = SingletonBehavior<RangeManager>.Instance;
  4203.                 RangeManager.Data factionRange = instance.GetFactionRange(base.get_transform().get_position().x, this.Mover.Radius + instance.LargestRadius + 3f);
  4204.                 int num = factionRange.m_start;
  4205.                 while (num < factionRange.m_end && this.EngagedEnemies.Count < this.m_cachedEngagementLimit)
  4206.                 {
  4207.                     Faction faction2 = instance.GetFaction(num);
  4208.                     if (!(faction2.AIController == null) && !(faction2.AIController == this))
  4209.                     {
  4210.                         if (faction2 != null && !this.IsEngaging(faction2.AIController) && this.CanEngageEnemy(faction2.AIController, attack, true))
  4211.                         {
  4212.                             this.EngageEnemy(faction2.AIController);
  4213.                         }
  4214.                     }
  4215.                     num++;
  4216.                 }
  4217.             }
  4218.             if (this.EngagedEnemies.Count > 0)
  4219.             {
  4220.                 int num2 = Mathf.Max(0, this.m_cachedEngagementLimit);
  4221.                 if (this.EngagedEnemies.Count > num2)
  4222.                 {
  4223.                     for (int k = 0; k < this.EngagedEnemies.Count; k++)
  4224.                     {
  4225.                         if (aIController2 == null || this.EngagedEnemies[k] != aIController2 || num2 == 0)
  4226.                         {
  4227.                             this.CancelEngagement(this.EngagedEnemies[k]);
  4228.                             break;
  4229.                         }
  4230.                     }
  4231.                 }
  4232.             }
  4233.         }
  4234.  
  4235.         protected void AddThreatenedBy(AIController enemy)
  4236.         {
  4237.             if (!this.m_threatenedBy.Contains(enemy))
  4238.             {
  4239.                 this.m_threatenedBy.Add(enemy);
  4240.             }
  4241.             if (this.CharacterStats != null)
  4242.             {
  4243.                 this.CharacterStats.NotifyThreatenedByOther(enemy);
  4244.             }
  4245.         }
  4246.  
  4247.         protected void AddEngagedBy(AIController enemy)
  4248.         {
  4249.             this.AddThreatenedBy(enemy);
  4250.             if (!this.m_engagedBy.Contains(enemy))
  4251.             {
  4252.                 this.m_engagedBy.Add(enemy);
  4253.                 if (this.CharacterStats != null)
  4254.                 {
  4255.                     this.CharacterStats.NotifyEngagedByOther(enemy);
  4256.                 }
  4257.                 for (int i = 0; i < this.m_disengagementTrackers.Count; i++)
  4258.                 {
  4259.                     if (this.m_disengagementTrackers[i].Enemy == enemy)
  4260.                     {
  4261.                         this.m_disengagementTrackers.RemoveAt(i);
  4262.                         break;
  4263.                     }
  4264.                 }
  4265.             }
  4266.         }
  4267.  
  4268.         protected bool IsEngagedBy(AIController enemy)
  4269.         {
  4270.             return enemy != null && this.m_engagedBy.Contains(enemy);
  4271.         }
  4272.  
  4273.         protected bool IsEngaged()
  4274.         {
  4275.             return this.m_engagedBy.Count > 0;
  4276.         }
  4277.  
  4278.         protected bool IsEngaging()
  4279.         {
  4280.             return this.m_engagedEnemies.Count > 0;
  4281.         }
  4282.  
  4283.         protected bool IsEngaging(AIController enemy)
  4284.         {
  4285.             return enemy != null && this.m_engagedEnemies.Contains(enemy);
  4286.         }
  4287.  
  4288.         protected int GetUniqueEngagementsCount()
  4289.         {
  4290.             int num = this.m_engagedEnemies.Count;
  4291.             foreach (AIController current in this.m_engagedBy)
  4292.             {
  4293.                 if (!this.m_engagedEnemies.Contains(current))
  4294.                 {
  4295.                     num++;
  4296.                 }
  4297.             }
  4298.             return num;
  4299.         }
  4300.  
  4301.         protected bool IsThreatenedBy(AIController enemy)
  4302.         {
  4303.             return enemy != null && this.m_threatenedBy.Contains(enemy);
  4304.         }
  4305.  
  4306.         protected bool IsThreatened()
  4307.         {
  4308.             return this.m_threatenedBy.Count > 0;
  4309.         }
  4310.  
  4311.         protected bool IsThreatening(AIController enemy)
  4312.         {
  4313.             return enemy != null && this.m_threatenedEnemies.Contains(enemy);
  4314.         }
  4315.  
  4316.         protected void NotifyEnemyBreaksThreat(AIController enemy)
  4317.         {
  4318.             if (this.m_threatenedBy.Contains(enemy))
  4319.             {
  4320.                 this.m_threatenedBy.Remove(enemy);
  4321.                 if (this.m_characterStats != null)
  4322.                 {
  4323.                     this.m_characterStats.NotifyThreatenedByOtherBroken(enemy);
  4324.                 }
  4325.             }
  4326.         }
  4327.  
  4328.         protected void NotifyEnemyBreaksEngagement(AIController enemy)
  4329.         {
  4330.             if (this.m_engagedBy.Contains(enemy))
  4331.             {
  4332.                 this.m_engagedBy.Remove(enemy);
  4333.                 if (this.m_characterStats != null)
  4334.                 {
  4335.                     this.m_characterStats.NotifyEngagementByOtherBroken(enemy);
  4336.                 }
  4337.             }
  4338.         }
  4339.  
  4340.         protected void ThreatenEnemy(AIController enemy)
  4341.         {
  4342.             if (enemy == this)
  4343.             {
  4344.                 return;
  4345.             }
  4346.             if (!this.AllowOutgoingThreat() || !enemy.AllowIncomingThreat())
  4347.             {
  4348.                 return;
  4349.             }
  4350.             if (AIController.DebugEngagement)
  4351.             {
  4352.                 UIPopcornTextManager.ShowNotice("threaten (" + enemy.get_name() + ")", base.get_gameObject(), 3f);
  4353.             }
  4354.             if (!this.m_threatenedEnemies.Contains(enemy))
  4355.             {
  4356.                 this.m_threatenedEnemies.Add(enemy);
  4357.             }
  4358.             if (this.m_characterStats != null)
  4359.             {
  4360.                 this.m_characterStats.NotifyThreat(enemy);
  4361.             }
  4362.             enemy.AddThreatenedBy(this);
  4363.         }
  4364.  
  4365.         protected void EngageEnemy(AIController enemy)
  4366.         {
  4367.             this.ThreatenEnemy(enemy);
  4368.             if (this.IsEngaging(enemy))
  4369.             {
  4370.                 return;
  4371.             }
  4372.             if (enemy == this)
  4373.             {
  4374.                 return;
  4375.             }
  4376.             if (!this.AllowOutgoingThreat() || !enemy.AllowIncomingThreat())
  4377.             {
  4378.                 return;
  4379.             }
  4380.             if (AIController.DebugEngagement)
  4381.             {
  4382.                 UIPopcornTextManager.ShowNotice("engage (" + enemy.get_name() + ")", base.get_gameObject(), 3f);
  4383.             }
  4384.             if (!this.m_engagedEnemies.Contains(enemy))
  4385.             {
  4386.                 this.m_engagedEnemies.Add(enemy);
  4387.             }
  4388.             if (this.m_characterStats != null)
  4389.             {
  4390.                 this.m_characterStats.NotifyEngagement(enemy);
  4391.             }
  4392.             enemy.NotifyMeleeEngaged(this);
  4393.             if (SingletonBehavior<FogOfWar>.Instance.PointFullyVisible(base.get_gameObject().get_transform().get_position()))
  4394.             {
  4395.                 Console.AddMessage(Console.Format(GuiStringTable.GetTextWithLinks(100, Gender.Neuter), new object[]
  4396.                 {
  4397.                     CharacterStatsUtility.NameColored(base.get_gameObject()),
  4398.                     CharacterStatsUtility.NameColored(enemy)
  4399.                 }));
  4400.             }
  4401.             enemy.AddEngagedBy(this);
  4402.         }
  4403.  
  4404.         protected void DisengageEnemy(AIController enemy, AttackBase attack)
  4405.         {
  4406.             CharacterStats characterStats = enemy.CharacterStats;
  4407.             if (characterStats != null && !characterStats.IsImmuneToEngagement)
  4408.             {
  4409.                 attack.CloneAndResolveDisengagement(enemy.get_gameObject());
  4410.                 UIPopcornTextManager.ShowNotice(GuiStringTable.GetText(2150), enemy.get_gameObject(), 2.5f);
  4411.             }
  4412.             this.CancelThreat(enemy);
  4413.             if (this.m_characterStats != null)
  4414.             {
  4415.                 this.m_characterStats.NotifyEngagementBreak(enemy);
  4416.             }
  4417.             this.NotifyEnemyBreaksEngagement(enemy);
  4418.             if (enemy)
  4419.             {
  4420.                 enemy.NotifyEnemyBreaksEngagement(this);
  4421.             }
  4422.         }
  4423.  
  4424.         protected void CancelThreat(AIController enemy)
  4425.         {
  4426.             this.CancelEngagement(enemy);
  4427.             if (!this.m_threatenedEnemies.Contains(enemy))
  4428.             {
  4429.                 return;
  4430.             }
  4431.             if (enemy == null)
  4432.             {
  4433.                 this.m_threatenedEnemies.Remove(enemy);
  4434.                 return;
  4435.             }
  4436.             if (AIController.DebugEngagement)
  4437.             {
  4438.                 UIPopcornTextManager.ShowNotice("stop threat (" + enemy.get_name() + ")", base.get_gameObject(), 3f);
  4439.             }
  4440.             this.m_disengagementTrackers.Add(new AIController.DisengagementTracker(enemy));
  4441.             this.m_threatenedEnemies.Remove(enemy);
  4442.             if (enemy != null)
  4443.             {
  4444.                 enemy.NotifyEnemyBreaksThreat(this);
  4445.             }
  4446.             if (this.m_characterStats != null)
  4447.             {
  4448.                 this.m_characterStats.NotifyThreatBreak(enemy);
  4449.             }
  4450.         }
  4451.  
  4452.         protected void CancelEngagement(AIController enemy)
  4453.         {
  4454.             if (!this.m_engagedEnemies.Contains(enemy))
  4455.             {
  4456.                 return;
  4457.             }
  4458.             if (enemy == null)
  4459.             {
  4460.                 this.m_engagedEnemies.Remove(enemy);
  4461.                 return;
  4462.             }
  4463.             if (AIController.DebugEngagement)
  4464.             {
  4465.                 UIPopcornTextManager.ShowNotice("stop engagement (" + enemy.get_name() + ")", base.get_gameObject(), 3f);
  4466.             }
  4467.             this.m_engagedEnemies.Remove(enemy);
  4468.             this.TrackObjectLifetime(enemy, 2f);
  4469.             if (enemy)
  4470.             {
  4471.                 enemy.NotifyEnemyBreaksEngagement(this);
  4472.             }
  4473.             if (this.m_characterStats != null)
  4474.             {
  4475.                 this.m_characterStats.NotifyEngagementBreak(enemy);
  4476.             }
  4477.         }
  4478.  
  4479.         protected void CancelAllThreats()
  4480.         {
  4481.             for (int i = this.ThreatenedEnemies.Count - 1; i >= 0; i--)
  4482.             {
  4483.                 AIController aIController = this.ThreatenedEnemies[i];
  4484.                 if (aIController != null)
  4485.                 {
  4486.                     this.CancelThreat(aIController);
  4487.                 }
  4488.             }
  4489.         }
  4490.  
  4491.         protected void CancelAllThreatsAndDelayReengagement()
  4492.         {
  4493.             for (int i = this.ThreatenedEnemies.Count - 1; i >= 0; i--)
  4494.             {
  4495.                 AIController aIController = this.ThreatenedEnemies[i];
  4496.                 if (aIController != null)
  4497.                 {
  4498.                     this.CancelThreat(aIController);
  4499.                     this.m_disengagementTrackers.Add(new AIController.DisengagementTracker(aIController));
  4500.                 }
  4501.             }
  4502.         }
  4503.  
  4504.         protected bool CanThreatenEnemy(AIController enemy, AttackBase attack)
  4505.         {
  4506.             if (enemy == null)
  4507.             {
  4508.                 return false;
  4509.             }
  4510.             if (!this.IsWithinPotentialThreatRange(enemy))
  4511.             {
  4512.                 return false;
  4513.             }
  4514.             if (this.ThreatDisabled)
  4515.             {
  4516.                 return false;
  4517.             }
  4518.             if (Stealth.IsInStealthMode(base.get_gameObject(), false) || Stealth.IsInStealthMode(enemy.get_gameObject(), false))
  4519.             {
  4520.                 return false;
  4521.             }
  4522.             if (!(attack is AttackMelee))
  4523.             {
  4524.                 return false;
  4525.             }
  4526.             if (!this.IsTargetable(enemy))
  4527.             {
  4528.                 return false;
  4529.             }
  4530.             if (this.IsInvisible)
  4531.             {
  4532.                 return false;
  4533.             }
  4534.             if (this.IsPet)
  4535.             {
  4536.                 return false;
  4537.             }
  4538.             GameObject gameObject = base.get_gameObject();
  4539.             if (enemy.get_gameObject() == gameObject)
  4540.             {
  4541.                 return false;
  4542.             }
  4543.             GameObject currentTarget = this.CurrentTarget;
  4544.             if (this.GetCurrentBehaviorType() == AIBehaviorType.PreparingToAct && currentTarget != enemy.get_gameObject())
  4545.             {
  4546.                 return false;
  4547.             }
  4548.             if (this.m_mover.IsMoving && currentTarget != enemy.get_gameObject())
  4549.             {
  4550.                 return false;
  4551.             }
  4552.             Faction faction = enemy.Faction;
  4553.             if (faction && this.m_faction != null && !faction.IsHostile(this.m_faction) && !this.m_faction.IsHostile(faction))
  4554.             {
  4555.                 return false;
  4556.             }
  4557.             for (int i = 0; i < this.m_disengagementTrackers.Count; i++)
  4558.             {
  4559.                 if (this.m_disengagementTrackers[i].Enemy == enemy)
  4560.                 {
  4561.                     return false;
  4562.                 }
  4563.             }
  4564.             return !enemy.IsInvisible && !enemy.IsPet && this.IsWithinThreatRange(enemy, attack);
  4565.         }
  4566.  
  4567.         protected bool CanEngageEnemy(AIController enemy, AttackBase attack, bool checkLimit)
  4568.         {
  4569.             if (!this.CanThreatenEnemy(enemy, attack))
  4570.             {
  4571.                 return false;
  4572.             }
  4573.             if (this.EngagementDisabled)
  4574.             {
  4575.                 return false;
  4576.             }
  4577.             if (this.CharacterStats != null && this.CharacterStats.StatusEffectManager.HasStatusEffectByType(StatusEffectType.CannotEngage))
  4578.             {
  4579.                 return false;
  4580.             }
  4581.             if (this.IsObjectTracked(enemy))
  4582.             {
  4583.                 return false;
  4584.             }
  4585.             CharacterStats characterStats = enemy.CharacterStats;
  4586.             if (characterStats != null && characterStats.IsImmuneToEngagement)
  4587.             {
  4588.                 return false;
  4589.             }
  4590.             if (this.m_characterStats != null)
  4591.             {
  4592.                 if (this.m_cachedEngagementLimit == 0 || (checkLimit && this.EngagedEnemies.Count >= this.m_cachedEngagementLimit))
  4593.                 {
  4594.                     return false;
  4595.                 }
  4596.                 int minimumLevelThatCanEngageMe = characterStats.GetMinimumLevelThatCanEngageMe();
  4597.                 if (this.m_characterStats.Level < minimumLevelThatCanEngageMe)
  4598.                 {
  4599.                     return false;
  4600.                 }
  4601.             }
  4602.             return true;
  4603.         }
  4604.  
  4605.         protected bool IsWithinThreatRange(AIController enemy, AttackBase attack)
  4606.         {
  4607.             if (enemy == null || this.m_characterStats == null)
  4608.             {
  4609.                 return false;
  4610.             }
  4611.             AttackMelee attackMelee = attack as AttackMelee;
  4612.             if (attackMelee == null)
  4613.             {
  4614.                 return false;
  4615.             }
  4616.             GameObject gameObject = base.get_gameObject();
  4617.             float num = Onyx.Math.Distance2DSquared(enemy.get_transform().get_position(), gameObject.get_transform().get_position());
  4618.             float radius = this.Mover.Radius;
  4619.             Mover mover = enemy.Mover;
  4620.             float num2 = 0.5f;
  4621.             if (mover != null)
  4622.             {
  4623.                 num2 = mover.Radius;
  4624.             }
  4625.             float num3 = attackMelee.AttackMeleeData.EngagementRadius + this.m_characterStats.StatusEffectManager.CalculateValueForStat(StatusEffectType.EngagementRadius, null) + radius + num2;
  4626.             return num <= num3 * num3;
  4627.         }
  4628.  
  4629.         protected bool IsWithinPotentialThreatRange(AIController enemy)
  4630.         {
  4631.             if (enemy == null)
  4632.             {
  4633.                 return false;
  4634.             }
  4635.             GameObject gameObject = base.get_gameObject();
  4636.             float radius = this.Mover.Radius;
  4637.             Mover mover = enemy.Mover;
  4638.             float num = 0.5f;
  4639.             if (mover != null)
  4640.             {
  4641.                 num = mover.Radius;
  4642.             }
  4643.             float num2 = radius + num + 3f;
  4644.             float num3 = Onyx.Math.Distance2DSquared(enemy.get_transform().get_position(), gameObject.get_transform().get_position());
  4645.             return num3 <= num2 * num2;
  4646.         }
  4647.  
  4648.         protected bool IsTargetable(AIController character)
  4649.         {
  4650.             return !(character == null) && this.IsTargetable(character.get_gameObject(), null);
  4651.         }
  4652.  
  4653.         protected bool IsTargetable(GameObject character)
  4654.         {
  4655.             return this.IsTargetable(character, null);
  4656.         }
  4657.  
  4658.         protected bool IsTargetable(GameObject character, AttackBase attack)
  4659.         {
  4660.             Health component = character.GetComponent<Health>();
  4661.             return component != null && component.IsTargetableByAttack(attack);
  4662.         }
  4663.  
  4664.         protected bool IsTargetBeingPushedBack(AIController character)
  4665.         {
  4666.             return !(character == null) && this.GetCurrentBehaviorType() == AIBehaviorType.PushedBack;
  4667.         }
  4668.  
  4669.         protected void TrackObjectLifetime(AIController obj, float lifetime)
  4670.         {
  4671.             AIController.ObjectsWithLifetime item = new AIController.ObjectsWithLifetime(obj, lifetime);
  4672.             this.m_trackedObjectList.Add(item);
  4673.         }
  4674.  
  4675.         protected bool IsObjectTracked(AIController obj)
  4676.         {
  4677.             for (int i = 0; i < this.m_trackedObjectList.Count; i++)
  4678.             {
  4679.                 if (this.m_trackedObjectList[i] != null && this.m_trackedObjectList[i].Obj == obj)
  4680.                 {
  4681.                     return true;
  4682.                 }
  4683.             }
  4684.             return false;
  4685.         }
  4686.  
  4687.         protected void BreakAllThreats(bool engagementOnly = false)
  4688.         {
  4689.             this.BreakIncomingThreats(engagementOnly);
  4690.             this.BreakOutgoingThreats(engagementOnly);
  4691.         }
  4692.  
  4693.         protected void BreakIncomingThreats(bool engagementOnly = false)
  4694.         {
  4695.             for (int i = this.ThreatenedBy.Count - 1; i >= 0; i--)
  4696.             {
  4697.                 AIController aIController = this.ThreatenedBy[i];
  4698.                 if (aIController != null)
  4699.                 {
  4700.                     if (engagementOnly)
  4701.                     {
  4702.                         aIController.CancelEngagement(this);
  4703.                     }
  4704.                     else
  4705.                     {
  4706.                         aIController.CancelThreat(this);
  4707.                     }
  4708.                 }
  4709.             }
  4710.         }
  4711.  
  4712.         protected void BreakOutgoingThreats(bool engagementOnly = false)
  4713.         {
  4714.             for (int i = this.ThreatenedEnemies.Count - 1; i >= 0; i--)
  4715.             {
  4716.                 AIController aIController = this.ThreatenedEnemies[i];
  4717.                 if (aIController != null)
  4718.                 {
  4719.                     if (engagementOnly)
  4720.                     {
  4721.                         this.CancelEngagement(aIController);
  4722.                     }
  4723.                     else
  4724.                     {
  4725.                         this.CancelThreat(aIController);
  4726.                     }
  4727.                 }
  4728.             }
  4729.         }
  4730.  
  4731.         protected void DrawEngagementDebug()
  4732.         {
  4733.             Vector3 zero = Vector3.get_zero();
  4734.             Color color = new Color(0.5f, 0.5f, 0f);
  4735.             Color color2 = new Color(0.5f, 0f, 0f);
  4736.             for (int i = 0; i < this.ThreatenedBy.Count; i++)
  4737.             {
  4738.                 GUIHelper.DrawArrow(this.ThreatenedBy[i].get_transform().get_position() + zero, base.get_transform().get_position() + zero, color);
  4739.             }
  4740.             zero.y += 0.2f;
  4741.             for (int j = 0; j < this.ThreatenedEnemies.Count; j++)
  4742.             {
  4743.                 GUIHelper.DrawArrow(base.get_transform().get_position() + zero, this.ThreatenedEnemies[j].get_transform().get_position() + zero, Color.get_yellow());
  4744.             }
  4745.             zero.y += 0.2f;
  4746.             for (int k = 0; k < this.EngagedBy.Count; k++)
  4747.             {
  4748.                 GUIHelper.DrawArrow(this.EngagedBy[k].get_transform().get_position() + zero, base.get_transform().get_position() + zero, color2);
  4749.             }
  4750.             zero.y += 0.2f;
  4751.             for (int l = 0; l < this.EngagedEnemies.Count; l++)
  4752.             {
  4753.                 GUIHelper.DrawArrow(base.get_transform().get_position() + zero, this.EngagedEnemies[l].get_transform().get_position() + zero, Color.get_red());
  4754.             }
  4755.         }
  4756.  
  4757.         protected void InitScanning()
  4758.         {
  4759.             if (this.m_faction != null && this.m_faction.CurrentTeam.TeamType == TeamType.Townie && this.m_townie == null)
  4760.             {
  4761.                 this.m_townie = ResourceManager.AddComponent<Townie>(base.get_gameObject());
  4762.             }
  4763.             this.m_scanWaitDuration = Random.Range(0f, 1f);
  4764.         }
  4765.  
  4766.         protected void CheckForPerceptionEvent()
  4767.         {
  4768.             if (this.m_scriptEvent)
  4769.             {
  4770.                 for (int i = 0; i < this.m_scriptEvent.Scripts.Count; i++)
  4771.                 {
  4772.                     ScriptEvent.ScriptEvents eventType = this.m_scriptEvent.Scripts[i].eventType;
  4773.                     if (eventType == ScriptEvent.ScriptEvents.OnPerception || eventType == ScriptEvent.ScriptEvents.OnPerceptionPerLoad || eventType == ScriptEvent.ScriptEvents.OnPerceptionOfStealthed || eventType == ScriptEvent.ScriptEvents.OnPerceptionOfNonStealthed)
  4774.                     {
  4775.                         this.m_forcePerceptionChecks = true;
  4776.                         break;
  4777.                     }
  4778.                 }
  4779.             }
  4780.         }
  4781.  
  4782.         protected void UpdateScanning()
  4783.         {
  4784.             if (GameState.IsCutsceneOrConversationRunning())
  4785.             {
  4786.                 return;
  4787.             }
  4788.             if (this.IsPet)
  4789.             {
  4790.                 return;
  4791.             }
  4792.             bool flag = this.m_trackingSuspicion;
  4793.             if (this.m_townie != null && !flag)
  4794.             {
  4795.                 flag = this.m_townie.RequiresImmediateScanning();
  4796.             }
  4797.             if (this.m_delayedCombatParams.IsPendingCombat)
  4798.             {
  4799.                 if (this.m_delayedCombatParams.IsTime)
  4800.                 {
  4801.                     this.EnterCombat(this.m_delayedCombatParams.Target, this.m_delayedCombatParams.PreparingToActType);
  4802.                     this.m_delayedCombatParams.Reset();
  4803.                 }
  4804.                 else
  4805.                 {
  4806.                     this.m_delayedCombatParams.Update();
  4807.                 }
  4808.             }
  4809.             if (!flag)
  4810.             {
  4811.                 this.m_scanWaitDuration -= Time.get_deltaTime();
  4812.                 if (this.m_scanWaitDuration > 0f)
  4813.                 {
  4814.                     return;
  4815.                 }
  4816.                 this.m_scanWaitDuration += 1f;
  4817.             }
  4818.             if (this.m_shipController != null)
  4819.             {
  4820.                 this.m_shipController.ScanForTargets();
  4821.             }
  4822.             if (this.PartyMember == null)
  4823.             {
  4824.                 if (this.m_townie != null && this.m_townie.RequiresScanning())
  4825.                 {
  4826.                     this.m_townie.Scan();
  4827.                 }
  4828.                 this.ScanForTargets();
  4829.             }
  4830.         }
  4831.  
  4832.         protected void ScanForTargets()
  4833.         {
  4834.             this.m_trackingSuspicion = false;
  4835.             if (this.ScanForTargetsEnabled && this.m_faction != null)
  4836.             {
  4837.                 Relationship relationshipToPlayer = this.m_faction.GetRelationshipToPlayer();
  4838.                 if (relationshipToPlayer == Relationship.Neutral || relationshipToPlayer == Relationship.Hostile || this.m_forcePerceptionChecks)
  4839.                 {
  4840.                     float num = this.PerceptionDistance;
  4841.                     num *= num;
  4842.                     bool trackingSuspicion = false;
  4843.                     List<PartyMember> activePartyMembers = SingletonBehavior<PartyManager>.Instance.GetActivePartyMembers();
  4844.                     bool flag = false;
  4845.                     for (int i = 0; i < activePartyMembers.Count; i++)
  4846.                     {
  4847.                         PartyMember partyMember = activePartyMembers[i];
  4848.                         if (partyMember)
  4849.                         {
  4850.                             float num2 = Onyx.Math.Distance2DSquared(base.get_transform().get_position(), partyMember.get_transform().get_position());
  4851.                             if (num2 <= num)
  4852.                             {
  4853.                                 Health component = partyMember.GetComponent<Health>();
  4854.                                 if (!(component == null) && component.IsTargetable())
  4855.                                 {
  4856.                                     trackingSuspicion = true;
  4857.                                     if (Stealth.IsInStealthMode(partyMember.get_gameObject(), false))
  4858.                                     {
  4859.                                         Stealth component2 = partyMember.GetComponent<Stealth>();
  4860.                                         if (component2)
  4861.                                         {
  4862.                                             this.m_trackingSuspicion = true;
  4863.                                             this.UpdateSuspicion(component2, this.m_suspicionDeltaTime, num2);
  4864.                                             float suspicion = component2.GetSuspicion(base.get_gameObject());
  4865.                                             if (!this.IsInCombat && suspicion >= 100f && relationshipToPlayer == Relationship.Hostile && this.GetCurrentBehaviorType() != AIBehaviorType.Investigate)
  4866.                                             {
  4867.                                                 AIBehavior behavior = AIBehaviorManager.AllocateInvestigateBehavior(partyMember.get_transform().get_position(), base.get_transform().get_position(), MovementType.Walk, MovementType.Walk, 2f, true);
  4868.                                                 this.BehaviorStack.PushBehavior(behavior);
  4869.                                                 UIAudioManager.Instance.Play(StealthUIAudioEventType.StealthInvestigated);
  4870.                                                 this.ExecuteOnInvestigate();
  4871.                                             }
  4872.                                             if (suspicion >= 200f)
  4873.                                             {
  4874.                                                 this.ExecuteOnPerception(partyMember.get_gameObject(), true);
  4875.                                                 flag = true;
  4876.                                             }
  4877.                                         }
  4878.                                     }
  4879.                                     else if (!this.IsInCombat && !flag && !this.m_delayedCombatParams.IsPendingCombat && GameUtilities.LineofSight(base.get_transform().get_position(), partyMember.get_transform().get_position()))
  4880.                                     {
  4881.                                         this.ExecuteOnPerception(partyMember.get_gameObject(), false);
  4882.                                         flag = true;
  4883.                                         if (relationshipToPlayer == Relationship.Hostile && this.m_townie == null)
  4884.                                         {
  4885.                                             if (this.GetCurrentBehaviorType() == AIBehaviorType.Investigate)
  4886.                                             {
  4887.                                                 UIInvestigateManager.ShowIcon(base.get_gameObject(), UIInvestigateIndicator.IconType.Spotted, 1f);
  4888.                                             }
  4889.                                             this.m_delayedCombatParams.SetTarget(partyMember.AIController.Faction, AIBehaviorManager.PreparingToActType.PreferredTarget);
  4890.                                         }
  4891.                                     }
  4892.                                 }
  4893.                             }
  4894.                         }
  4895.                     }
  4896.                     if (!flag)
  4897.                     {
  4898.                         this.m_previousPerceptionState = false;
  4899.                         this.m_trackingSuspicion = trackingSuspicion;
  4900.                     }
  4901.                 }
  4902.             }
  4903.             this.m_suspicionDeltaTime = 0f;
  4904.         }
  4905.  
  4906.         protected bool ShouldDetectStealthedCharacter(Stealth enemyStealth)
  4907.         {
  4908.             return this.DetectsStealthedCharacters && this.m_faction && !(enemyStealth == null);
  4909.         }
  4910.  
  4911.         protected void UpdateSuspicion(Stealth enemyStealth, float deltaTime, float distanceSq)
  4912.         {
  4913.             if (!this.ShouldDetectStealthedCharacter(enemyStealth))
  4914.             {
  4915.                 return;
  4916.             }
  4917.             CharacterStats component = enemyStealth.GetComponent<CharacterStats>();
  4918.             if (component == null)
  4919.             {
  4920.                 return;
  4921.             }
  4922.             Mover component2 = enemyStealth.GetComponent<Mover>();
  4923.             if (component2 == null)
  4924.             {
  4925.                 return;
  4926.             }
  4927.             float stealthSkill = (float)component.CalculateSkill(SkillManager.StealthSkill, null);
  4928.             bool flag = false;
  4929.             bool flag2 = false;
  4930.             float num = this.StealthedCharacterHearingDistance;
  4931.             if (distanceSq < num * num)
  4932.             {
  4933.                 float num2 = component2.Radius;
  4934.                 if (component2.IsMoving)
  4935.                 {
  4936.                     deltaTime = Mathf.Max(deltaTime, Time.get_deltaTime());
  4937.                 }
  4938.                 if (this.Mover != null)
  4939.                 {
  4940.                     num2 += this.Mover.Radius;
  4941.                 }
  4942.                 float distancePercent = (Mathf.Sqrt(distanceSq) - num2) / Mathf.Max(num - num2, 1f);
  4943.                 if (distanceSq - num2 * num2 < 0.45f)
  4944.                 {
  4945.                     distancePercent = 0f;
  4946.                 }
  4947.                 flag2 = GameUtilities.LineofSight(base.get_transform().get_position(), enemyStealth.get_gameObject());
  4948.                 flag = true;
  4949.                 if (flag2 && this.m_faction != null)
  4950.                 {
  4951.                     float value = AIController.CalculateSuspicion(deltaTime, distancePercent, (float)SkillManager.StealthSettings.HearingSuspicionRate, stealthSkill, (float)this.m_characterStats.Level);
  4952.                     enemyStealth.AddSuspicion(base.get_gameObject(), value, this.m_faction.GetRelationship(enemyStealth.get_gameObject()), DetectionType.Hearing);
  4953.                     this.m_lastDetectingTimestamp[2] = Time.get_realtimeSinceStartup();
  4954.                     flag2 = true;
  4955.                 }
  4956.             }
  4957.             num = this.StealthedCharacterVisionDistance;
  4958.             if (distanceSq < num * num)
  4959.             {
  4960.                 Vector3 vector = enemyStealth.get_transform().get_position() - base.get_transform().get_position();
  4961.                 float num3 = Vector3.Angle(base.get_transform().get_forward(), vector);
  4962.                 if (num3 < this.StealthedCharacterVisionAngle * 0.5f)
  4963.                 {
  4964.                     if (!flag)
  4965.                     {
  4966.                         flag2 = GameUtilities.LineofSight(base.get_transform().get_position(), enemyStealth.get_gameObject());
  4967.                     }
  4968.                     if (flag2)
  4969.                     {
  4970.                         float value2 = AIController.CalculateSuspicion(deltaTime, 1f, (float)SkillManager.StealthSettings.VisionSuspicionRate, stealthSkill, (float)this.m_characterStats.Level);
  4971.                         enemyStealth.AddSuspicion(base.get_gameObject(), value2, this.m_faction.GetRelationship(enemyStealth.get_gameObject()), DetectionType.Vision);
  4972.                         this.m_lastDetectingTimestamp[1] = Time.get_realtimeSinceStartup();
  4973.                     }
  4974.                 }
  4975.             }
  4976.         }
  4977.  
  4978.         protected float GetLastDetectionTimestamp(DetectionType type)
  4979.         {
  4980.             return this.m_lastDetectingTimestamp[(int)type];
  4981.         }
  4982.  
  4983.         protected static float CalculateSuspicion(float deltaTime, float distancePercent, float baseSuspicionRate, float stealthSkill, float creatureLevel)
  4984.         {
  4985.             if (distancePercent <= 1.401298E-45f)
  4986.             {
  4987.                 return 200f;
  4988.             }
  4989.             float num = SkillManager.StealthSettings.MaxDistanceMultiplier - SkillManager.StealthSettings.MinDistanceMultiplier;
  4990.             float num2 = num * Mathf.Clamp01(distancePercent) + SkillManager.StealthSettings.MinDistanceMultiplier;
  4991.             float num3 = baseSuspicionRate * deltaTime * num2;
  4992.             float num4 = (stealthSkill - creatureLevel * 0.75f) / Mathf.Max(1f, creatureLevel);
  4993.             if (num4 > 0f)
  4994.             {
  4995.                 num4 = Mathf.Min(num4, 1f - SkillManager.StealthSettings.MaxSuspicionStealthDecelerationMultiplier);
  4996.                 return num3 - num3 * num4;
  4997.             }
  4998.             num4 = Mathf.Abs(num4);
  4999.             if (num4 > SkillManager.StealthSettings.MaxSuspicionStealthAccelerationMultiplier)
  5000.             {
  5001.                 num4 = SkillManager.StealthSettings.MaxSuspicionStealthAccelerationMultiplier;
  5002.             }
  5003.             return num3 + num3 * num4;
  5004.         }
  5005.  
  5006.         protected void ClearPerceptionState()
  5007.         {
  5008.             this.m_previousPerceptionState = false;
  5009.         }
  5010.  
  5011.         protected void ExecuteOnPerception(GameObject perceivedCharacter, bool isPerceivedCharacterStealthed)
  5012.         {
  5013.             if (!this.m_previousPerceptionState)
  5014.             {
  5015.                 SpecialCharacterInstanceID.Add(perceivedCharacter, SpecialCharacterInstanceID.SpecialCharacterInstance.Target);
  5016.                 this.m_previousPerceptionState = true;
  5017.                 this.OnPerception.Trigger(base.get_gameObject(), perceivedCharacter, isPerceivedCharacterStealthed);
  5018.                 if (this.m_scriptEvent != null)
  5019.                 {
  5020.                     this.m_scriptEvent.ExecuteScript(ScriptEvent.ScriptEvents.OnPerception);
  5021.                     if (isPerceivedCharacterStealthed)
  5022.                     {
  5023.                         this.m_scriptEvent.ExecuteScript(ScriptEvent.ScriptEvents.OnPerceptionOfStealthed);
  5024.                     }
  5025.                     else
  5026.                     {
  5027.                         this.m_scriptEvent.ExecuteScript(ScriptEvent.ScriptEvents.OnPerceptionOfNonStealthed);
  5028.                     }
  5029.                 }
  5030.                 if (!this.m_perceptionTriggered)
  5031.                 {
  5032.                     if (this.m_scriptEvent != null)
  5033.                     {
  5034.                         this.m_scriptEvent.ExecuteScript(ScriptEvent.ScriptEvents.OnPerceptionPerLoad);
  5035.                     }
  5036.                     this.m_perceptionTriggered = true;
  5037.                     SingletonBehavior<ChatterManager>.Instance.StartNPCReactiveBarkChatter(ChatterEventType.PartyMemberSpotted, base.get_gameObject());
  5038.                 }
  5039.                 SpecialCharacterInstanceID.Remove(SpecialCharacterInstanceID.SpecialCharacterInstance.Target);
  5040.             }
  5041.         }
  5042.  
  5043.         protected void ExecuteOnInvestigate()
  5044.         {
  5045.             if (this.m_scriptEvent != null)
  5046.             {
  5047.                 this.m_scriptEvent.ExecuteScript(ScriptEvent.ScriptEvents.OnInvestigate);
  5048.             }
  5049.         }
  5050.  
  5051.         protected void ExecuteOnShoutAlert()
  5052.         {
  5053.             if (this.m_scriptEvent != null)
  5054.             {
  5055.                 this.m_scriptEvent.ExecuteScript(ScriptEvent.ScriptEvents.OnShoutAlert);
  5056.             }
  5057.         }
  5058.  
  5059.         protected void ExecuteOnFriendlyDeathAlert()
  5060.         {
  5061.             if (this.m_scriptEvent != null)
  5062.             {
  5063.                 this.m_scriptEvent.ExecuteScript(ScriptEvent.ScriptEvents.OnFriendlyDeathAlert);
  5064.             }
  5065.         }
  5066.  
  5067.         protected void EnterCombat(Faction target, AIBehaviorManager.PreparingToActType preparingToActType)
  5068.         {
  5069.             SingletonBehavior<TacticalModeManager>.Instance.EnterCombat(this);
  5070.             if (preparingToActType != AIBehaviorManager.PreparingToActType.HelpRequest)
  5071.             {
  5072.                 if (preparingToActType == AIBehaviorManager.PreparingToActType.PreferredTarget)
  5073.                 {
  5074.                     AIBehavior behavior = AIBehaviorManager.AllocatePreparingToActBehaviorWithPreferredTarget(target, target.IsInPlayerFaction);
  5075.                     if (this.BehaviorStack.PushBehavior(behavior, true))
  5076.                     {
  5077.                         this.ShoutToAllies(target.get_gameObject(), this.ShoutRange, false, false, Vector3.get_zero());
  5078.                     }
  5079.                 }
  5080.             }
  5081.             else
  5082.             {
  5083.                 AIBehavior behavior2 = AIBehaviorManager.AllocatePreparingToActBehaviorWithHelpRequest(target.get_gameObject(), target.IsHostileToPlayer());
  5084.                 this.BehaviorStack.PushBehavior(behavior2, true);
  5085.                 this.ExecuteOnShoutAlert();
  5086.             }
  5087.         }
  5088.  
  5089.         protected void TrackDamage(GameObject attacker, float damageAmount)
  5090.         {
  5091.             Faction component = ComponentUtils.GetComponent<Faction>(attacker);
  5092.             if (component == null)
  5093.             {
  5094.                 return;
  5095.             }
  5096.             if (!this.m_damageTracker.ContainsKey(component))
  5097.             {
  5098.                 this.m_damageTracker.Add(component, new List<AIDamageTracker>());
  5099.             }
  5100.             AIDamageTracker aIDamageTracker = this.m_damageTrackerPool.Allocate();
  5101.             aIDamageTracker.Damage = damageAmount;
  5102.             aIDamageTracker.Timestamp = SingletonBehavior<TimeController>.Instance.GameTimeSinceStartup;
  5103.             this.m_damageTracker[component].Add(aIDamageTracker);
  5104.         }
  5105.  
  5106.         protected float GetDamageThreatValue(Faction attacker)
  5107.         {
  5108.             float num = 0f;
  5109.             List<AIDamageTracker> list;
  5110.             if (this.m_damageTracker.TryGetValue(attacker, out list))
  5111.             {
  5112.                 for (int i = list.Count - 1; i >= 0; i--)
  5113.                 {
  5114.                     AIDamageTracker aIDamageTracker = list[i];
  5115.                     if (aIDamageTracker.Timestamp + GlobalGameSettingsGameData.Instance.ThreatTrackingDuration < SingletonBehavior<TimeController>.Instance.GameTimeSinceStartup)
  5116.                     {
  5117.                         list.Remove(aIDamageTracker);
  5118.                         this.m_damageTrackerPool.Free(aIDamageTracker);
  5119.                     }
  5120.                     else
  5121.                     {
  5122.                         num += aIDamageTracker.Damage;
  5123.                     }
  5124.                 }
  5125.             }
  5126.             return num;
  5127.         }
  5128.  
  5129.         protected void CLearTargetTracking()
  5130.         {
  5131.             foreach (KeyValuePair<Faction, List<AIDamageTracker>> current in this.m_damageTracker)
  5132.             {
  5133.                 List<AIDamageTracker> value = current.Value;
  5134.                 for (int i = value.Count - 1; i >= 0; i--)
  5135.                 {
  5136.                     AIDamageTracker aIDamageTracker = value[i];
  5137.                     value.Remove(aIDamageTracker);
  5138.                     this.m_damageTrackerPool.Free(aIDamageTracker);
  5139.                 }
  5140.             }
  5141.             this.m_damageTracker.Clear();
  5142.         }
  5143.  
  5144.         protected virtual Guid GetTypeID()
  5145.         {
  5146.             return AIController.TypeID;
  5147.         }
  5148.  
  5149.         protected virtual int GetSaveVersion()
  5150.         {
  5151.             return 3;
  5152.         }
  5153.  
  5154.         protected virtual bool ShouldSave()
  5155.         {
  5156.             return true;
  5157.         }
  5158.  
  5159.         protected virtual void Save(BinaryWriter writer)
  5160.         {
  5161.             PersistentUtils.WriteEnum(writer, this.m_persistentAIController.ObsoleteSummonType);
  5162.             PersistentUtils.WriteGuid(writer, this.m_persistentAIController.ObsoleteSummonerGuid);
  5163.             PersistentUtils.WriteEnum(writer, this.m_persistentAIController.PersistentScriptedBehavior);
  5164.             PersistentUtils.WriteGuid(writer, this.m_persistentAIController.PersistentScriptedUseObjectGuid);
  5165.             PersistentUtils.WriteBool(writer, this.m_persistentAIController.ScanForTargetsEnabled);
  5166.             PersistentUtils.WriteBool(writer, this.m_persistentAIController.IsEmerging);
  5167.             PersistentUtils.WriteBool(writer, this.m_persistentAIController.m_IsGuard);
  5168.         }
  5169.  
  5170.         protected virtual void SaveJson(StringBuilder writer)
  5171.         {
  5172.             PersistentUtils.WriteJsonEnum(writer, "ObsoleteSummonType", this.m_persistentAIController.ObsoleteSummonType);
  5173.             PersistentUtils.WriteJsonComma(writer);
  5174.             PersistentUtils.WriteJsonGuid(writer, "ObsoleteSummonerGuid", this.m_persistentAIController.ObsoleteSummonerGuid);
  5175.             PersistentUtils.WriteJsonComma(writer);
  5176.             PersistentUtils.WriteJsonEnum(writer, "PersistentScriptedBehavior", this.m_persistentAIController.PersistentScriptedBehavior);
  5177.             PersistentUtils.WriteJsonComma(writer);
  5178.             PersistentUtils.WriteJsonGuid(writer, "PersistentScriptedUseObjectGuid", this.m_persistentAIController.PersistentScriptedUseObjectGuid);
  5179.             PersistentUtils.WriteJsonComma(writer);
  5180.             PersistentUtils.WriteJsonBool(writer, "ScanForTargetsEnabled", this.m_persistentAIController.ScanForTargetsEnabled);
  5181.             PersistentUtils.WriteJsonComma(writer);
  5182.             PersistentUtils.WriteJsonBool(writer, "IsEmerging", this.m_persistentAIController.IsEmerging);
  5183.             PersistentUtils.WriteJsonComma(writer);
  5184.             PersistentUtils.WriteJsonBool(writer, "m_IsGuard", this.m_persistentAIController.m_IsGuard);
  5185.         }
  5186.  
  5187.         protected virtual void Load(BinaryReader reader, int version)
  5188.         {
  5189.             this.m_loadVersion = version;
  5190.             SaveLoadManager.RegisterIPersistentDataObjectLoaded(this, version);
  5191.             switch (this.m_loadVersion)
  5192.             {
  5193.             case 1:
  5194.                 this.LoadVersion1(reader);
  5195.                 break;
  5196.             case 2:
  5197.                 this.LoadVersion2(reader);
  5198.                 break;
  5199.             case 3:
  5200.                 this.LoadVersion3(reader);
  5201.                 break;
  5202.             default:
  5203.                 throw new Exception("Invalid version number " + version.ToString() + " passed into AIController.");
  5204.             }
  5205.         }
  5206.  
  5207.         protected virtual void LoadJson(JsonTextReader jsonReader)
  5208.         {
  5209.             SaveLoadManager.RegisterIPersistentDataObjectLoaded(this, 1);
  5210.         }
  5211.  
  5212.         protected void LoadVersion3(BinaryReader reader)
  5213.         {
  5214.             this.m_persistentAIController.Clear();
  5215.             this.m_persistentAIController.ObsoleteSummonType = (AISummonType)PersistentUtils.ReadEnum(reader, typeof(AISummonType));
  5216.             this.m_persistentAIController.ObsoleteSummonerGuid = PersistentUtils.ReadGuid(reader);
  5217.             this.m_persistentAIController.PersistentScriptedBehavior = (ScriptedBehaviorType)PersistentUtils.ReadEnum(reader, typeof(ScriptedBehaviorType));
  5218.             this.m_persistentAIController.PersistentScriptedUseObjectGuid = PersistentUtils.ReadGuid(reader);
  5219.             this.m_persistentAIController.ScanForTargetsEnabled = PersistentUtils.ReadBool(reader);
  5220.             this.m_persistentAIController.IsEmerging = PersistentUtils.ReadBool(reader);
  5221.             this.m_persistentAIController.m_IsGuard = PersistentUtils.ReadBool(reader);
  5222.         }
  5223.  
  5224.         protected void LoadVersion2(BinaryReader reader)
  5225.         {
  5226.             this.m_persistentAIController.Clear();
  5227.             this.m_persistentAIController.ObsoleteSummonType = (AISummonType)PersistentUtils.ReadEnum(reader, typeof(AISummonType));
  5228.             this.m_persistentAIController.ObsoleteSummonerGuid = PersistentUtils.ReadGuid(reader);
  5229.             this.m_persistentAIController.PersistentScriptedBehavior = (ScriptedBehaviorType)PersistentUtils.ReadEnum(reader, typeof(ScriptedBehaviorType));
  5230.             this.m_persistentAIController.PersistentScriptedUseObjectGuid = PersistentUtils.ReadGuid(reader);
  5231.             this.m_persistentAIController.ScanForTargetsEnabled = PersistentUtils.ReadBool(reader);
  5232.             this.m_persistentAIController.IsEmerging = PersistentUtils.ReadBool(reader);
  5233.         }
  5234.  
  5235.         protected void LoadVersion1(BinaryReader reader)
  5236.         {
  5237.             this.m_persistentAIController.Clear();
  5238.             this.m_persistentAIController.ObsoleteSummonType = (AISummonType)PersistentUtils.ReadEnum(reader, typeof(AISummonType));
  5239.             this.m_persistentAIController.ObsoleteSummonerGuid = PersistentUtils.ReadGuid(reader);
  5240.             this.m_persistentAIController.PersistentScriptedBehavior = (ScriptedBehaviorType)PersistentUtils.ReadEnum(reader, typeof(ScriptedBehaviorType));
  5241.             this.m_persistentAIController.PersistentScriptedUseObjectGuid = PersistentUtils.ReadGuid(reader);
  5242.             this.m_persistentAIController.ScanForTargetsEnabled = PersistentUtils.ReadBool(reader);
  5243.         }
  5244.     }
  5245. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement