KeyValuePair <Subject, int> FindThreat() // look in the threat list for something to kill { // no threats and not helping allies? if (!ThreatList.Any() && !HelpAllies) { return(new KeyValuePair <Subject, int>()); } // grab the local threatlist Dictionary <Subject, int> allThreats = ThreatList.ToDictionary(kvp => kvp.Key, kvp => kvp.Value); // grab the ally's threats if (HelpAllies) { Dictionary <Subject, int> myFriendsThreats = new Dictionary <Subject, int>(); // look at each ally if (AllyList.Count > 0) { foreach (var ally in AllyList) { Intellect friend = ally.GetIntellect(); if (friend) { // look at each threat in that ally foreach (var threat in friend.ThreatList) { // add that threat to this local list if (!myFriendsThreats.ContainsKey(threat.Key)) { myFriendsThreats.Add(threat.Key, threat.Value); } } } } } // put any threats from allies into the full list of threats if (myFriendsThreats.Any()) { foreach (KeyValuePair <Subject, int> kvp in myFriendsThreats.Where(kvp => !allThreats.ContainsKey(kvp.Key))) { allThreats.Add(kvp.Key, kvp.Value); } } } // do i want the closest or the biggest threat? KeyValuePair <Subject, int> final = (MyThreatPriority == ThreatPriority.Nearest ? GetNearestThreat(allThreats, transform) : GetHighestThreat(allThreats)); if (final.Value > 0 || (HelpAllies && AllyList.Count > 0 && AllyList.Where(ally => ally.GetIntellect() != null).Any(ally => ally.GetIntellect().Provoked))) { Provoked = true; } return(final); }
void Awake() { _myRigidbody = GetComponent <Rigidbody2D>(); InputPermission = true; IsDead = false; _myControls = GetComponent <PlayerController>(); WeaponListRuntime = new List <GameObject>(); Stats.MaxWeaponSlots = 2; if (Stats.SubjectGroup == SubjectGroup.Intellect) { _intellect = GetComponent <Intellect>(); } if (_myControls != null) { _isControllable = true; } }