public bool SpawnForBanner(Banner banner, IDifficultySetting difficulty, Colony colony, float cooldown, IPandaBoss boss) { int recycleFrequency = MonsterSpawner.GetPathRecycleFrequency(1f / cooldown); NPCType zombieTypeToSpawn = difficulty.GetZombieTypeToSpawn(colony); float maxPathDistance = difficulty.GetMaxPathDistance(colony, zombieTypeToSpawn, banner.SafeRadius); return(CaclulateZombie(banner, colony, zombieTypeToSpawn, recycleFrequency, maxPathDistance)); }
public override void Update() { if (!World.Initialized || AIManager.IsBusy()) { return; } CalculateColoniesThatRequireMonsters(); maxTimePerTick.Reset(); maxTimePerTick.Start(); while (coloniesRequiringZombies.Count > 0 && maxTimePerTick.Elapsed.TotalMilliseconds < variables.MSPerTick) { int i = 0; while (i < coloniesRequiringZombies.Count && maxTimePerTick.Elapsed.TotalMilliseconds < variables.MSPerTick) { var tuple = coloniesRequiringZombies[i]; Colony colony = tuple.item1; Banner banner = tuple.item2; IDifficultySetting difficulty = colony.Owner.DifficultySetting; float cooldown = difficulty.GetZombieSpawnCooldown(colony); if (SpawnForBanner(banner, difficulty, colony, cooldown, null)) { double nextZombieSpawn = NextZombieSpawnTimes.GetValueOrDefault(colony, 0.0) + cooldown; NextZombieSpawnTimes[colony] = nextZombieSpawn; if (nextZombieSpawn > Pipliz.Time.SecondsSinceStartDoubleThisFrame) { coloniesRequiringZombies.RemoveAt(i); } } else if (colony.InSiegeMode) { coloniesRequiringZombies.RemoveAt(i); // only test getting out of siege mode once per time } } } maxTimePerTick.Stop(); }
public void CalculateColoniesThatRequireMonsters() { int bannerCount = BannerTracker.GetCount(); coloniesRequiringZombies.Clear(); for (int i = 0; i < bannerCount; i++) { Banner banner; if (!BannerTracker.TryGetAtIndex(i, out banner) || !banner.KeyLocation.IsValid) { continue; } Colony colony = Colony.Get(banner.Owner); if (colony.FollowerCount == 0) { colony.OnZombieSpawn(true); continue; } var ps = PlayerState.GetPlayerState(banner.Owner); IDifficultySetting difficultyColony = colony.Owner.DifficultySetting; if (!MonsterManager.BossActive) { if (!ps.MonstersEnabled || !difficultyColony.ShouldSpawnZombies(colony)) { colony.OnZombieSpawn(true); continue; } } double nextZombieSpawnTime = NextZombieSpawnTimes.GetValueOrDefault(colony, 0.0); if (nextZombieSpawnTime > Pipliz.Time.SecondsSinceStartDoubleThisFrame) { continue; } if (colony.InSiegeMode) { if (Pipliz.Time.SecondsSinceStartDoubleThisFrame - colony.LastSiegeModeSpawn < siegeModeCooldown) { continue; } else { colony.LastSiegeModeSpawn = Pipliz.Time.SecondsSinceStartDoubleThisFrame; } } // lagging behind, or no cooldown set: teleport to current time if (Pipliz.Time.SecondsSinceStartDoubleThisFrame - nextZombieSpawnTime > MONSTERS_DELAY_THRESHOLD_SECONDS) { NextZombieSpawnTimes[colony] = Pipliz.Time.SecondsSinceStartDoubleThisFrame; } coloniesRequiringZombies.Add(TupleStruct.Create(colony, banner)); } }