public virtual void Update(GameTime gameTime) { if (!CanSpawnUnits) { return; } UnitTimer += gameTime.ElapsedGameTime.Milliseconds; while (UnitTimer > MaxUnitTimer) { int reps = 100; UnitTimer -= MaxUnitTimer; WaveUnit waveUnit = null; do { reps--; CurrentUnit++; if (CurrentUnit >= Units.Count) { CurrentUnit = 0; } waveUnit = Units[CurrentUnit]; }while ((waveUnit.Card.GetType().IsSubclassOf(typeof(PlayerCard)) || waveUnit.Card.GetType().IsSubclassOf(typeof(StrikeCard)) || waveUnit.UnitCount < 1) && reps > 0); waveUnit.UnitCount--; CanSpawnUnits = false; foreach (WaveUnit w in Units) { if (w.UnitCount > 0 && !w.Card.GetType().IsSubclassOf(typeof(PlayerCard)) && !w.Card.GetType().IsSubclassOf(typeof(StrikeCard))) { CanSpawnUnits = true; } } LevelMult = 2; for (int i = 0; i < waveUnit.Card.GetUnitBuildNumber(); i++) { UnitBasic u = waveUnit.Card.GetUnit(NeutralManager.NeutralFaction); if (u == null) { //throw new Exception("Null unit error"); return; } WaveManager.self.ParentLevel.AddObject(u); u.SetLevel(waveUnit.Level * LevelMult, 1); NeutralManager.SpawnUnit(u); if (u.GetType().IsSubclassOf(typeof(UnitShip))) { UnitShip u2 = (UnitShip)u; u2.CanCloak = waveUnit.Cloaked; u2.CanSummon = waveUnit.Summoner; u2.IsHuge = waveUnit.Huge; u2.SummonCard = (UnitCard)waveUnit.Card; } } } }
private void ResetDefenseTarget() { Dictionary <MiningPlatform, float> PlatformScores = new Dictionary <MiningPlatform, float>(); foreach (UnitBasic u in FactionManager.SortedUnits[Parent.ParentController.ParentShip.GetTeam()]) { if (u.GetType().IsSubclassOf(typeof(MiningPlatform))) { MiningPlatform m = (MiningPlatform)u; if (!PlatformScores.ContainsKey(m)) { PlatformScores.Add(m, 0); foreach (UnitBasic u2 in FactionManager.SortedUnits[Parent.ParentController.ParentShip.GetTeam()]) { if (u2.GetType().IsSubclassOf(typeof(UnitTurret))) { UnitTurret t2 = (UnitTurret)u2; if (t2.IsAlly(Parent.ParentController.ParentShip) && !t2.Dead) { PlatformScores[m] += Vector2.Distance(t2.Position.get(), m.Position.get()); } } } } } } MiningPlatform forwardPlatform = PathFindingManager.TraceToMiningPlatform(NeutralManager.GetSpawnPosition(), Parent.ParentController.ParentShip.GetTeam()); if (forwardPlatform != null && PlatformScores.ContainsKey(forwardPlatform)) { PlatformScores[forwardPlatform] *= 2; } float BestScore = 0; foreach (MiningPlatform m in PlatformScores.Keys) { if (PlatformScores[m] > BestScore) { CurrentDefenseTarget = m; BestScore = PlatformScores[m]; } } DefenseLocation = PathFindingManager.TraceCellPoint(CurrentDefenseTarget.Position.get(), 10); }