Esempio n. 1
0
        /// <summary>
        /// Writes the configuration to a stream
        /// </summary>
        /// <param name="stream">stream</param>
        public void Write(Stream stream)
        {
            //minion spawns
            List <SpawnMinion> SpawnMinions1 = new List <SpawnMinion>();
            SpawnMinion        SpawnMinion1  = new SpawnMinion("customnpc id", 100, BiomeTypes.None, SpawnConditions.None, false, true);
            SpawnMinion        SpawnMinion2  = new SpawnMinion("customnpc id2", 100, BiomeTypes.None, SpawnConditions.None, false, true);

            SpawnMinions1.Add(SpawnMinion1);
            SpawnMinions1.Add(SpawnMinion2);

            //SpawnGroups
            SpawnsGroups SpawnGroup1 = new SpawnsGroups(true, true, SpawnMinions1, 100);

            //Waves
            List <Waves> Waves1 = new List <Waves>();
            Waves        Wave1  = new Waves("Insert Wavename", SpawnGroup1);

            Waves1.Add(Wave1);

            //WaveSets
            WaveSets = new Dictionary <string, WaveSet>();
            WaveSet WaveSets1 = new WaveSet("WaveName", Waves1);

            WaveSets.Add("WaveSet Name", WaveSets1);

            var str = JsonConvert.SerializeObject(this, Formatting.Indented);

            using (var sw = new StreamWriter(stream))
            {
                sw.Write(str);
            }
        }
Esempio n. 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;
                }
            }