示例#1
0
        Connection FindEnemy()
        {
            Connection enemy = null;

            if (_enemies.Count > 0)
            {
                // Grab all the enemies
                _enemyLock.WaitOne();
                KeyValuePair <int, uint>[] enemies = _enemies.ToArray();
                _enemyLock.ReleaseMutex();
                List <int> toRemove = new List <int>();

                // Pick the one that has done the most damage
                PlayMap    myMap         = Program.Server.GetPlayMap(_mapID);
                uint       bestThreatVal = 0;
                Connection bestThreat    = null;
                foreach (KeyValuePair <int, uint> kvp in enemies)
                {
                    Connection e = myMap.GetPlayer(kvp.Key);
                    if (e.Character.CurHP <= 0 || kvp.Value == 0)
                    {
                        toRemove.Add(kvp.Key);
                    }
                    else if (kvp.Value > bestThreatVal)
                    {
                        bestThreatVal = kvp.Value;
                        bestThreat    = e;
                    }
                }

                enemy = bestThreat;

                // Remove any dead guys
                if (toRemove.Count > 0)
                {
                    _enemyLock.WaitOne();
                    foreach (int remove in toRemove)
                    {
                        _enemies.Remove(remove);
                    }
                    _enemyLock.ReleaseMutex();
                }
            }
            return(enemy);
        }
示例#2
0
 public void AddPlayMap(ushort mapID)
 {
     _maps[mapID] = new PlayMap(mapID);
 }