예제 #1
0
        public void PathingThreadAction(PathingContext context)
        {
            if (BossActive)
            {
                foreach (var colony in ServerManager.ColonyTracker.ColoniesByID.Values)
                {
                    var bannerGoal = colony.Banners.FirstOrDefault();

                    if (bannerGoal == null)
                    {
                        continue;
                    }

                    var cs = ColonyState.GetColonyState(colony);

                    if (cs.BossesEnabled &&
                        cs.ColonyRef.OwnerIsOnline() &&
                        colony.FollowerCount > CurrentPandaBoss.MinColonists)
                    {
                        if (CurrentPandaBoss != null && !SpawnedBosses.ContainsKey(cs))
                        {
                            Vector3Int positionFinal;
                            switch (((MonsterSpawner)MonsterTracker.MonsterSpawner).TryGetSpawnLocation(context, bannerGoal.Position, bannerGoal.SafeRadius, 200, 500f, out positionFinal))
                            {
                            case MonsterSpawner.ESpawnResult.Success:
                                if (context.Pathing.TryFindPath(positionFinal, bannerGoal.Position, out var path, 2000000000) == EPathFindingResult.Success)
                                {
                                    var pandaboss = (IPandaBoss)CurrentPandaBoss.GetNewInstance(path, colony);
                                    _pandaBossesSpawnQueue.Enqueue(pandaboss);
                                    SpawnedBosses.Add(cs, pandaboss);
                                }

                                break;

                            case MonsterSpawner.ESpawnResult.NotLoaded:
                            case MonsterSpawner.ESpawnResult.Impossible:
                                colony.OnZombieSpawn(true);
                                break;

                            case MonsterSpawner.ESpawnResult.Fail:
                                CantSpawnBoss(cs);
                                break;
                            }
                        }
                    }
                }
            }
        }
예제 #2
0
        public static void OnUpdate()
        {
            if (!World.Initialized)
            {
                return;
            }

            var secondsSinceStartDouble = Time.SecondsSinceStartDouble;

            if (World.Initialized)
            {
                if (!TimeCycle.IsDay &&
                    !BossActive &&
                    _nextBossUpdateTime <= secondsSinceStartDouble)
                {
                    BossActive = true;
                    var bossType = GetMonsterType();

                    if (bossType != null)
                    {
                        _monsterManager.CurrentPandaBoss = bossType;
                        ServerManager.PathingManager.QueueAction(_monsterManager);
                        _justQueued = secondsSinceStartDouble + 5;

                        if (Players.CountConnected != 0)
                        {
                            APILogger.Log(ChatColor.yellow, $"Boss Active! Boss is: {bossType.name}");
                        }
                    }
                    else
                    {
                        BossActive = false;
                        GetNextBossSpawnTime();
                    }
                }

                if (BossActive && _justQueued < secondsSinceStartDouble)
                {
                    var turnOffBoss = true;

                    if (_pandaBossesSpawnQueue.Count > 0)
                    {
                        var pandaboss = _pandaBossesSpawnQueue.Dequeue();
                        var cs        = ColonyState.GetColonyState(pandaboss.OriginalGoal);
                        BossSpawned?.Invoke(MonsterTracker.MonsterSpawner, new BossSpawnedEvent(cs, pandaboss));

                        ModLoader.Callbacks.OnMonsterSpawned.Invoke(pandaboss);
                        MonsterTracker.Add(pandaboss);
                        cs.ColonyRef.OnZombieSpawn(true);
                        cs.FaiedBossSpawns = 0;
                        PandaChat.Send(cs, _localizationHelper, $"[{pandaboss.name}] {pandaboss.AnnouncementText}", ChatColor.red);

                        if (!string.IsNullOrEmpty(pandaboss.AnnouncementAudio))
                        {
                            cs.ColonyRef.ForEachOwner(o => AudioManager.SendAudio(o.Position, pandaboss.AnnouncementAudio));
                        }
                    }

                    foreach (var colony in ServerManager.ColonyTracker.ColoniesByID.Values)
                    {
                        var bannerGoal = colony.Banners.FirstOrDefault();
                        var cs         = ColonyState.GetColonyState(colony);

                        if (bannerGoal != null &&
                            cs.BossesEnabled &&
                            cs.ColonyRef.OwnerIsOnline())
                        {
                            if (SpawnedBosses.ContainsKey(cs) &&
                                SpawnedBosses[cs].IsValid &&
                                SpawnedBosses[cs].CurrentHealth > 0)
                            {
                                if (colony.TemporaryData.GetAsOrDefault("BossIndicator", 0) < Time.SecondsSinceStartInt)
                                {
                                    Indicator.SendIconIndicatorNear(new Vector3Int(SpawnedBosses[cs].Position),
                                                                    SpawnedBosses[cs].ID,
                                                                    new IndicatorState(1, ItemId.GetItemId(GameInitializer.NAMESPACE + ".Poisoned").Id,
                                                                                       false, false));

                                    colony.TemporaryData.SetAs("BossIndicator", Time.SecondsSinceStartInt + 1);
                                }

                                turnOffBoss = false;
                            }
                        }


                        if (turnOffBoss)
                        {
                            if (Players.CountConnected != 0 && SpawnedBosses.Count != 0)
                            {
                                APILogger.Log(ChatColor.yellow, $"All bosses cleared!");
                                var boss = SpawnedBosses.FirstOrDefault().Value;
                                PandaChat.SendToAll($"[{boss.name}] {boss.DeathText}", _localizationHelper, ChatColor.red);
                            }

                            BossActive = false;
                            SpawnedBosses.Clear();
                            GetNextBossSpawnTime();
                        }
                    }
                }
            }
        }