public static void Update() { m_sortHelper.Clear(); foreach (var pair in CurrentBotsAttackingPlayer) { m_sortHelper.Add(pair.Value); } CurrentBotsAttackingPlayer.Clear(); foreach (MySmallShipBot bot in m_sortHelper) { float distance = Vector3.Distance(MyCamera.Position, bot.GetPosition()); CurrentBotsAttackingPlayer.Add(new KeyValuePair <float, MySmallShipBot>(distance, bot)); } CurrentBotsAttackingPlayer.Sort(Compare); m_sortHelper.Clear(); }
public static void AddAttacker(MySmallShipBot attacker, MyEntity target) { if (MySession.IsPlayerShip(target)) { foreach (var pair in CurrentBotsAttackingPlayer) { if (pair.Value == attacker) { return; } } float attackerDistance = Vector3.Distance(MyCamera.Position, attacker.GetPosition()); if (CurrentBotsAttackingPlayer.Count == MaxBotsAttackingPlayer) { if (CurrentBotsAttackingPlayer[CurrentBotsAttackingPlayer.Count - 1].Key <= attackerDistance) { return; } for (int i = 0; i < CurrentBotsAttackingPlayer.Count; i++) { var pair = CurrentBotsAttackingPlayer[i]; if (attackerDistance < pair.Key) { CurrentBotsAttackingPlayer.RemoveAt(i); break; } } } CurrentBotsAttackingPlayer.Add(new KeyValuePair <float, MySmallShipBot>(attackerDistance, attacker)); CurrentBotsAttackingPlayer.Sort(Compare); } System.Diagnostics.Debug.Assert(CurrentBotsAttackingPlayer.Count <= MaxBotsAttackingPlayer); }