コード例 #1
0
        static void ForeachBanner(Vector3Int position, Banner banner, ref Data data)
        {
            Colony colony = banner.Colony;

            if (colony == null)
            {
                return;
            }

            if (colony.FollowerCount == 0)
            {
                colony.OnZombieSpawn(true);
                return;
            }

            IColonyDifficultySetting difficultyColony = colony.DifficultySetting;
            ColonyState colonyState = ColonyState.GetColonyState(colony);

            if (!difficultyColony.ShouldSpawnZombies(colony) || !colonyState.MonstersEnabled)
            {
                colony.OnZombieSpawn(true);
                return;
            }

            double nextZombieSpawnTime = Extensions.GetValueOrDefault(data.NextZombieSpawnTimes, colony, 0.0);

            if (nextZombieSpawnTime > ServerTime.SecondsSinceStart)
            {
                return;
            }

            if (colony.InSiegeMode)
            {
                if (ServerTime.SecondsSinceStart - colony.LastSiegeModeSpawn < SIEGEMODE_COOLDOWN_SECONDS)
                {
                    return;
                }
                else
                {
                    colony.LastSiegeModeSpawn = ServerTime.SecondsSinceStart;
                }
            }

            if (ServerTime.SecondsSinceStart - nextZombieSpawnTime > MONSTERS_DELAY_THRESHOLD_SECONDS)
            {
                // lagging behind, or no cooldown set: teleport closer to current time
                data.NextZombieSpawnTimes[colony] = ServerTime.SecondsSinceStart - MONSTERS_DELAY_THRESHOLD_SECONDS;
            }

            data.ColoniesRequiringZombies.AddIfUnique(colony);
        }
コード例 #2
0
        public void QueueSpawnZombie(Colony colony, IColonyDifficultySetting difficulty, float cooldown)
        {
            int     recycleFrequency = GetPathRecycleFrequency(1f / cooldown);
            NPCType typeToSpawn      = GetTypeToSpawn(colony);
            Banner  banner           = colony.GetRandomBanner();

            if (banner == null)
            {
                return;
            }
            float maxPathDistance = difficulty.GetMaxPathDistance(colony, typeToSpawn, banner.SafeRadius);

            QueueSpawnZombie(banner, typeToSpawn, recycleFrequency, maxPathDistance);
        }
コード例 #3
0
        public void RegisterMonsterSpawnedElsewhere(IMonster monster, bool notifyColonyForSiegeMode = true)
        {
            ThreadManager.AssertIsMainThread();
            ModLoader.Callbacks.OnMonsterSpawned.Invoke(monster);
            MonsterTracker.Add(monster);
            Colony goalColony = monster.OriginalGoal;

            if (goalColony != null)
            {
                IColonyDifficultySetting difficulty = goalColony.DifficultySetting;
                float cooldown = difficulty.GetZombieSpawnCooldown(goalColony);
                NextZombieSpawnTimes[goalColony] = Extensions.GetValueOrDefault(NextZombieSpawnTimes, goalColony, ServerTime.SecondsSinceStart) + cooldown;

                if (notifyColonyForSiegeMode)
                {
                    goalColony.OnZombieSpawn(true);
                }
            }
        }
コード例 #4
0
        public virtual void Update()
        {
            if (World.FramesSinceInitialization < 2 || isQueuedForPathing || !ChunkQueue.CompletedInitialLoad)
            {
                return;
            }

            if (--pathCacheUpdateCounter <= 0)
            {
                pathCacheUpdateCounter = VERIFY_PATHCACHE_EVERY_X_UPDATES;
                pathCache.VerifyGoals();
            }

            QueuedSpawnResult result;

            while (QueuedSpawnResults.TryDequeue(out result))
            {
                Colony colony = result.Payload.banner?.Colony;
                if (colony == null)
                {
                    continue;
                }

                switch (result.result)
                {
                case QueuedSpawnResult.EResult.BadFailSpawn:
                case QueuedSpawnResult.EResult.FailPath:
                    NextZombieSpawnTimes[colony] = NextZombieSpawnTimes[colony] - colony.DifficultySetting.GetZombieSpawnCooldown(colony);
                    colony.OnZombieSpawn(false);
                    break;

                case QueuedSpawnResult.EResult.GoodFailSpawn:
                    colony.OnZombieSpawn(true);
                    break;

                case QueuedSpawnResult.EResult.SuccessPath:
                    if (result.Payload.recycleFrequency > 1)
                    {
                        pathCache.AddCopy(result.path);
                    }
                    SpawnZombie(result.Payload.typeToSpawn, result.path, colony, true);
                    break;
                }
            }


            Data data;

            data.ColoniesRequiringZombies = coloniesRequiringZombies;
            data.NextZombieSpawnTimes     = NextZombieSpawnTimes;
            ServerManager.BlockEntityTracker.BannerTracker.Foreach(ForeachBanner, ref data);

            for (int i = 0; i < coloniesRequiringZombies.Count; i++)
            {
                Colony colony = coloniesRequiringZombies[i];
                IColonyDifficultySetting difficulty = colony.DifficultySetting;
                float cooldown = difficulty.GetZombieSpawnCooldown(colony);

                double nextZombieSpawn = Extensions.GetValueOrDefault(NextZombieSpawnTimes, colony, ServerTime.SecondsSinceStart);

                while (true)
                {
                    QueueSpawnZombie(colony, difficulty, cooldown);
                    nextZombieSpawn += cooldown;
                    if (nextZombieSpawn > ServerTime.SecondsSinceStart || colony.InSiegeMode)
                    {
                        break;
                    }
                }

                NextZombieSpawnTimes[colony] = nextZombieSpawn;
            }

            coloniesRequiringZombies.Clear();

            if (QueuedSpawns.Count > 0)
            {
                isQueuedForPathing = true;
                ServerManager.PathingManager.QueueAction(this);
            }
        }
コード例 #5
0
 public void QueueSpawnZombie(Colony colony, IColonyDifficultySetting difficulty)
 {
     QueueSpawnZombie(colony, difficulty, difficulty.GetZombieSpawnCooldown(colony));
 }