Exemplo n.º 1
0
        /// <summary>
        /// Creates <see cref="MonsterSpawnSet"/>s that are defined in the data provided
        /// by the <see cref="Zone"/> and adds them to the system to be interpreted.
        /// </summary>
        private void CreateMonsterSpawns()
        {
            var tileMap = Zone.TileMap;

            // If we have this layer, parse it
            if (tileMap.ObjectGroups.Contains(MobSpawnSetName))
            {
                var groups = tileMap.ObjectGroups[MobSpawnSetName];

                foreach (var mobSpawn in groups.Objects)
                {
                    if (mobSpawn.Type == MobSpawnSetType)
                    {
                        var mobId = Convert.ToInt64(mobSpawn.Properties["MobId"]);
                        var mobCanStray = Convert.ToBoolean(mobSpawn.Properties["MobStrays"]);
                        var mobMaxAmount = Convert.ToInt32(mobSpawn.Properties["MobMax"]);
                        var mobSpawnTime = Convert.ToSingle(mobSpawn.Properties["MobSpawnTime"]);
                        var mobRepeats = Convert.ToBoolean(mobSpawn.Properties["MobRepeats"]);

                        var x = mobSpawn.X;
                        var y = mobSpawn.Y;
                        var width = mobSpawn.Width;
                        var height = mobSpawn.Height;

                        var spawnArea = new Rectangle(x, y, width, height);

                        var spawnSet = new MonsterSpawnSet(mobMaxAmount, mobRepeats, mobSpawnTime, spawnArea, mobCanStray, mobId);
                        _spawnSets.Add(spawnSet);
                    }
                    else
                    {
                        string error =
                            "Zone #{0} has an object incorrectly located on the {1} layer with an object of type {2}. ";
                        Logger.Instance.Info(error, Zone.Id, MobSpawnSetName, mobSpawn.Type);
                    }
                }
            }
        }
Exemplo n.º 2
0
        private Vector2 GetRandomSpawnPosition(MonsterSpawnSet monsterSpawn, Monster monster)
        {
            var maxX = monsterSpawn.SpawnArea.Width;
            var maxY = monsterSpawn.SpawnArea.Height;

            var random = new Random();
            var pickedX = random.Next(0, maxX);
            var pickedY = random.Next(0, maxY);

            var actualX = monsterSpawn.SpawnArea.X + pickedX;
            var actualY = monsterSpawn.SpawnArea.Y + pickedY;

            return new Vector2(actualX, actualY);
        }