public void Tick()
 {
     foreach (Projectile projectile in Projectiles.ToList())
     {
         foreach (IDestructible destructible in Destructibles.ToList())
         {
             if (CheckCollision(projectile, destructible.Actor))
             {
                 if (destructible.IsDestructible && destructible.IsAlive)
                 {
                     switch (destructible.Actor)
                     {
                     case Enemy _ when projectile.Owner is Player:
                     case Player _ when projectile.Owner is Enemy:
                     case GameObject _:
                         destructible.OnHit();
                         projectile.Dispose();
                         break;
                     }
                 }
                 else if (destructible.StopsProjectile)
                 {
                     projectile.Dispose();
                 }
             }
         }
     }
 }
Esempio n. 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);
 }
Esempio n. 3
0
 /// <summary>
 /// Clear all stored data.
 /// </summary>
 private void Clear()
 {
     StructuresSelf.Clear();
     WorkersSelf.Clear();
     UnitsSelf.Clear();
     StructureEnemy.Clear();
     WorkersEnemy.Clear();
     UnitsEnemy.Clear();
     Colonies.Clear();
     PrimaryColony = null;
     UpgradesSelf.Clear();
     MineralFields.Clear();
     VespeneGeysers.Clear();
     Destructibles.Clear();
     XelNagaTowers.Clear();
     Handler = new CaseHandler <Case, IUnit>();
 }
Esempio n. 4
0
 /// <summary>
 /// This function should only be called on the first game frame.
 /// Mineral Fields, Vespene and Destructible is added once and then only updated if visible.
 /// </summary>
 /// <param name="obs">Observation from the newest ResponseObservation</param>
 private void InitialIntel(Observation obs)
 {
     foreach (var unit in obs.RawData.Units)
     {
         if (GameConstants.IsMineralField(unit.UnitType))
         {
             MineralFields.Add(unit.Tag, new IntelUnit(unit));
             GameMap.RegisterNatural(new Point {
                 X = unit.Pos.X - 0.5f, Y = unit.Pos.Y
             }, 0.5f);
             GameMap.RegisterStructure(new Point {
                 X = unit.Pos.X - 0.5f, Y = unit.Pos.Y
             }, 0.5f);
             GameMap.RegisterNatural(new Point {
                 X = unit.Pos.X + 0.5f, Y = unit.Pos.Y
             }, 0.5f);
             GameMap.RegisterStructure(new Point {
                 X = unit.Pos.X + 0.5f, Y = unit.Pos.Y
             }, 0.5f);
         }
         else if (GameConstants.IsVepeneGeyser(unit.UnitType))
         {
             VespeneGeysers.Add(unit.Tag, new IntelUnit(unit));
             GameMap.RegisterNatural(unit.Pos, 1.5f);
             GameMap.RegisterStructure(unit.Pos, 1.5f);
         }
         else if (GameConstants.IsDestructible(unit.UnitType))
         {
             Destructibles.Add(unit.Tag, new IntelUnit(unit));
             GameMap.RegisterStructure(unit.Pos, 0.5f); // TODO - add actual size to destructables
         }
         else if (GameConstants.IsXelNagaTower(unit.UnitType))
         {
             XelNagaTowers.Add(unit.Tag, new IntelUnit(unit));
             GameMap.RegisterStructure(unit.Pos, 0.5f);
         }
     }
 }
Esempio n. 5
0
        public bool TryGetDestructible(ulong tag, out IUnit unit)
        {
            var res = Destructibles.TryGetValue(tag, out var data);

            unit = data; return(res);
        }