예제 #1
0
 /// <summary>
 /// Notify listeners of dead units and remove from the index.
 /// </summary>
 /// <param name="event">Event from the newest ResponseObservation</param>
 private void DeadUnits(Event @event)
 {
     if (@event == null)
     {
         return;
     }
     foreach (var id in @event.DeadUnits)
     {
         if (UnitsSelf.TryGetValue(id, out var deadUnit))
         {
             UnitsSelf.Remove(id);
             Handler.Handle(Case.UnitDestroyed, deadUnit);
         }
         else if (StructuresSelf.TryGetValue(id, out deadUnit))
         {
             StructuresSelf.Remove(id);
             Handler.Handle(Case.StructureDestroyed, deadUnit);
         }
         else if (WorkersSelf.TryGetValue(id, out deadUnit))
         {
             WorkersSelf.Remove(id);
             Handler.Handle(Case.WorkerDestroyed, deadUnit);
         }
         else if (UnitsEnemy.TryGetValue(id, out deadUnit))
         {
             UnitsEnemy.Remove(id);
             Handler.Handle(Case.UnitAddedEnemy, deadUnit);
         }
         else if (StructureEnemy.TryGetValue(id, out deadUnit))
         {
             StructureEnemy.Remove(id);
             Handler.Handle(Case.StructureAddedEnemy, deadUnit);
         }
         else if (WorkersEnemy.TryGetValue(id, out deadUnit))
         {
             WorkersEnemy.Remove(id);
             Handler.Handle(Case.WorkerAddedEnemy, deadUnit);
         }
         else if (MineralFields.TryGetValue(id, out deadUnit))
         {
             MineralFields.Remove(id);
             foreach (var c in Colonies)
             {
                 if (c.Minerals.Remove(deadUnit))
                 {
                     break;
                 }
             }
             Handler.Handle(Case.MineralDepleted, deadUnit);
         }
     }
 }
예제 #2
0
 public bool TryGet(ulong tag, out IUnit unit)
 {
     if (UnitsSelf.TryGetValue(tag, out var u))
     {
         unit = u;
         return(true);
     }
     if (StructuresSelf.TryGetValue(tag, out var building))
     {
         unit = building;
         return(true);
     }
     if (WorkersSelf.TryGetValue(tag, out var worker))
     {
         unit = worker;
         return(true);
     }
     if (StructureEnemy.TryGetValue(tag, out var buildingE))
     {
         unit = buildingE;
         return(true);
     }
     if (UnitsEnemy.TryGetValue(tag, out var uE))
     {
         unit = uE;
         return(true);
     }
     if (WorkersEnemy.TryGetValue(tag, out var workerE))
     {
         unit = workerE;
         return(true);
     }
     if (Destructibles.TryGetValue(tag, out var destructible))
     {
         unit = destructible;
         return(true);
     }
     if (MineralFields.TryGetValue(tag, out var mineral))
     {
         unit = mineral;
         return(true);
     }
     if (VespeneGeysers.TryGetValue(tag, out var vespene))
     {
         unit = vespene;
         return(true);
     }
     unit = null;
     return(false);
 }