示例#1
0
            private static void InvasionTimer_Elapsed(object sender, ElapsedEventArgs e)
            {
                if (TShock.Utils.ActivePlayers() == 0)
                {
                    return;
                }

                bool boss = spawnedBosses;

                spawnedBosses = true;

                int       spawnX      = Main.spawnTileX - 150;
                int       spawnY      = Main.spawnTileY - 150;
                Rectangle spawnRegion = new Rectangle(spawnX, spawnY, 300, 300).ToPixels();

                int attempts;

                foreach (SpawnMinion minion in CurrentWave.SpawnGroup.SpawnMinions)
                {
                    if (minion.isBoss)
                    {
                        //We already spawned bosses this wave.
                        if (boss)
                        {
                            continue;
                        }

                        //Boss NPC's get 5 (250) spawn attempts.
                        attempts = 5;
                    }
                    else
                    {
                        //Normal NPC's get 3 (150) spawn attempts.
                        attempts = 3;
                    }

                    //Get NPC definition
                    var npcdef = NPCManager.Data.GetNPCbyID(minion.MobID);
                    if (npcdef == null)
                    {
                        TShock.Log.ConsoleError("[CustomNPC]: Error! The custom mob id \"{0}\" does not exist!", minion.MobID);
                        continue;
                    }

                    //Check spawn conditions
                    if (minion.SpawnConditions != SpawnConditions.None && NPCManager.CheckSpawnConditions(minion.SpawnConditions))
                    {
                        continue;
                    }

                    SpawnMinion(spawnRegion, minion, npcdef, attempts);
                }
            }
示例#2
0
        private void InvasionTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            if (TShock.Utils.ActivePlayers() == 0)
            {
                return;
            }

            int spawnFails     = 0;
            int spawnsThisWave = 0;

            int       spawnX      = Main.spawnTileX - 150;
            int       spawnY      = Main.spawnTileY - 150;
            Rectangle SpawnRegion = new Rectangle(spawnX, spawnY, 300, 300);

            foreach (SpawnMinion minions in CurrentWave.SpawnGroup.SpawnMinions)
            {
                var npcdef = NPCManager.Data.GetNPCbyID(minions.MobID);
                if (npcdef == null)
                {
                    TShock.Log.ConsoleError("[CustomNPC]: Error! The custom mob id \"{0}\" does not exist!", minions.MobID);
                    continue;
                }

                // Check spawn conditions
                if (minions.SpawnConditions != SpawnConditions.None)
                {
                    if (NPCManager.CheckSpawnConditions(minions.SpawnConditions))
                    {
                        continue;
                    }
                }

                foreach (TSPlayer player in TShock.Players)
                {
                    //Skip spawning more NPCs when we have likely hit the server's mob limit.
                    if (spawnFails > 40 && spawnsThisWave >= 150)
                    {
                        continue;
                    }

                    if (player == null || player.Dead || !player.Active || !NPCManager.Chance(minions.Chance))
                    {
                        continue;
                    }
                    Rectangle playerframe = new Rectangle((int)player.TPlayer.position.X, (int)player.TPlayer.position.Y, player.TPlayer.width, player.TPlayer.height);
                    if (!playerframe.Intersects(SpawnRegion))
                    {
                        continue;
                    }

                    if (minions.BiomeConditions != BiomeTypes.None)
                    {
                        BiomeTypes biomes = player.GetCurrentBiomes();

                        if ((minions.BiomeConditions & biomes) == 0)
                        {
                            continue;
                        }
                    }

                    // Prevent multiple bosses from spawning during invasions
                    if (minions.isBoss && NPCManager.AliveCount(minions.MobID) > 0)
                    {
                        continue;
                    }

                    int mobid = -1;
                    //Try max 3 times. Since every try checks 50 positions around the player to spawn the mob,
                    //3 tries means a maximum of 150 spawn attempts.
                    for (int i = 0; mobid == -1 && i < 3; i++)
                    {
                        mobid = NPCManager.SpawnMobAroundPlayer(player, npcdef);
                    }

                    if (mobid == -1)
                    {
                        spawnFails++;
                        continue;
                    }

                    NPCManager.GetCustomNPCByIndex(mobid).isInvasion = true;
                    spawnsThisWave++;
                }
            }

            if (spawnFails > 0)
            {
                TShock.Log.ConsoleInfo("[CustomNPC]: Failed to spawn {0} npcs this wave!", spawnFails);
            }
        }