Example #1
0
        /// <summary>
        /// For Custom Loot
        /// </summary>
        /// <param name="args"></param>
        private void OnLootDrop(NpcLootDropEventArgs args)
        {
            CustomNPCVars npcvar = NPCManager.GetCustomNPCByIndex(args.NpcArrayIndex);

            if (npcvar == null || npcvar.droppedLoot)
            {
                return;
            }

            args.Handled = npcvar.customNPC.overrideBaseNPCLoot;

            //Check if monster has been customized
            if (npcvar.customNPC.customNPCLoots != null)
            {
                foreach (CustomNPCLoot obj in npcvar.customNPC.customNPCLoots)
                {
                    if (obj.itemDropChance >= 100 || NPCManager.Chance(obj.itemDropChance))
                    {
                        int pre = 0;
                        if (obj.itemPrefix != null)
                        {
                            pre = obj.itemPrefix[rand.Next(obj.itemPrefix.Count)];
                        }

                        Item.NewItem((int)npcvar.mainNPC.position.X, (int)npcvar.mainNPC.position.Y, npcvar.mainNPC.width, npcvar.mainNPC.height, obj.itemID, obj.itemStack, false, pre, false);
                    }
                }
            }

            npcvar.isDead      = true;
            npcvar.droppedLoot = true;

            npcvar.OnDeath();
        }
Example #2
0
            /// <summary>
            /// Attempts to spawn the given minion for every player online, where applicable.
            /// </summary>
            /// <param name="spawnRegion"></param>
            /// <param name="minion"></param>
            /// <param name="npcdef"></param>
            /// <param name="attempts"></param>
            private static void SpawnMinion(Rectangle spawnRegion, SpawnMinion minion, CustomNPCDefinition npcdef, int attempts)
            {
                //Loop through players
                foreach (TSPlayer player in TShock.Players)
                {
                    if (player == null || player.Dead || !player.Active || !NPCManager.Chance(minion.Chance))
                    {
                        continue;
                    }

                    //Check if the minions can spawn anywhere, or if we need to check if players see them.
                    if (!CurrentWave.SpawnAnywhere)
                    {
                        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;
                        }
                    }

                    //Check biomes
                    if (minion.BiomeConditions != BiomeTypes.None)
                    {
                        BiomeTypes biomes = player.GetCurrentBiomes();

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

                    int mobid = -1;

                    //Try max attempts times. This gives attempts*50 spawn attempts at random positions.
                    for (int i = 0; mobid == -1 && i < attempts; i++)
                    {
                        mobid = NPCManager.SpawnMobAroundPlayer(player, npcdef);
                    }

                    //Spawning failed :(
                    if (mobid == -1)
                    {
                        continue;
                    }

                    NPCManager.GetCustomNPCByIndex(mobid).isInvasion = true;
                }
            }
Example #3
0
        /// <summary>
        /// (Attempts to) Spawn monsters randomly around the current x y position.
        /// </summary>
        /// <param name="npcvar">The Custom NPC to use to spawn children</param>
        /// <param name="amount">The amount to spawn</param>
        /// <param name="sethealth"></param>
        /// <param name="health"></param>
        public void Multiply(CustomNPCDefinition type, int amount, bool sethealth = false, int health = 0)
        {
            //DEBUG
            TShock.Log.ConsoleInfo("DEBUG [Multiply] entry. amount={0}, sethealth={1}, health={2}", amount, sethealth, health);
            //DEBUG

            // MainNPC is gone.
            if (mainNPC == null)
            {
                return;
            }

            if (type == null)
            {
                return;
            }

            for (int i = 0; i < amount; i++)
            {
                int x = (int)mainNPC.position.X + rand.Next(-8, 9);
                int y = (int)mainNPC.position.Y + rand.Next(-8, 9);

                int npc = NPCManager.SpawnNPCAtLocation(x, y, type);
                if (npc == -1)
                {
                    //DEBUG
                    TShock.Log.ConsoleInfo("DEBUG [Multiply] spawn failed. location={0}, {1}", x, y);
                    //DEBUG
                    continue;
                }

                var spawned = NPCManager.GetCustomNPCByIndex(npc);
                if (spawned == null)
                {
                    continue;
                }

                if (sethealth)
                {
                    spawned.mainNPC.life = health;
                }

                spawned.isClone = true;
            }
        }
Example #4
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);
            }
        }