Ejemplo n.º 1
0
        public void AddCreature(OtCreature creature)
        {
            if (!creatures.ContainsKey(creature.Id))
            {
                var spawnLocation = new Location(creature.Location.X - (creature.Location.X % SPAWN_SIZE) + SPAWN_RADIUS,
                                                 creature.Location.Y - (creature.Location.Y % SPAWN_SIZE) + SPAWN_RADIUS, creature.Location.Z);
                var spawnIndex = spawnLocation.ToIndex();

                if (!spawns.ContainsKey(spawnIndex))
                {
                    spawns.Add(spawnIndex, new OtSpawn(spawnLocation, SPAWN_RADIUS));
                }

                var spwan = spawns[spawnIndex];

                if (spwan.AddCreature(creature))
                {
                    if (creature.Type == CreatureType.NPC)
                    {
                        npcCount++;
                    }
                    else if (creature.Type == CreatureType.MONSTER)
                    {
                        monsterCount++;
                    }

                    creatures.Add(creature.Id, creature);
                }
            }
        }
Ejemplo n.º 2
0
        public bool AddCreature(OtCreature creature)
        {
            var relativeLocation = GetRelativeLocation(creature.Location);

            if (!(Math.Abs(relativeLocation.X) <= Radius && Math.Abs(relativeLocation.Y) <= Radius))
                throw new Exception("Can't add this creature to this spawn. Spawn Location: " + Location + ", Creature Location: " + creature.Location);

            creature.Location = relativeLocation;
            if (creatures[relativeLocation.X + Radius, relativeLocation.Y + Radius] == null)
            {
                creatures[relativeLocation.X + Radius, relativeLocation.Y + Radius] = creature;
                return true;
            }

            return false;
        }
Ejemplo n.º 3
0
        public bool AddCreature(OtCreature creature)
        {
            var relativeLocation = GetRelativeLocation(creature.Location);

            if (!(Math.Abs(relativeLocation.X) <= Radius && Math.Abs(relativeLocation.Y) <= Radius))
            {
                throw new Exception("Can't add this creature to this spawn. Spawn Location: " + Location + ", Creature Location: " + creature.Location);
            }

            creature.Location = relativeLocation;
            if (creatures[relativeLocation.X + Radius, relativeLocation.Y + Radius] == null)
            {
                creatures[relativeLocation.X + Radius, relativeLocation.Y + Radius] = creature;
                return(true);
            }

            return(false);
        }
Ejemplo n.º 4
0
        private void LoadSpawn(string fileName, ISet <ulong> tileLocations)
        {
            if (!File.Exists(fileName))
            {
                Trace.WriteLine("Can't load map spawns.");
                return;
            }

            var spawns = XElement.Load(fileName);

            foreach (var spawn in spawns.Elements("spawn"))
            {
                var centerLocation = new Location(spawn.Attribute("centerx").GetInt32(), spawn.Attribute("centery").GetInt32(),
                                                  spawn.Attribute("centerz").GetInt32());

                foreach (var creature in spawn.Elements())
                {
                    var cr = new OtCreature();
                    cr.Id       = ++loadCreatureId;
                    cr.Name     = creature.Attribute("name").GetString();
                    cr.Type     = creature.Name.LocalName.Equals("npc") ? CreatureType.NPC : CreatureType.MONSTER;
                    cr.Location = new Location(centerLocation.X + creature.Attribute("x").GetInt32(),
                                               centerLocation.Y + creature.Attribute("y").GetInt32(), creature.Attribute("z").GetInt32());

                    if (char.IsUpper(cr.Name[0]))
                    {
                        cr.Type = CreatureType.NPC;
                    }

                    if (tileLocations.Contains(cr.Location.ToIndex()) && (cr.Type != CreatureType.NPC || !npcs.Contains(cr.Name)))
                    {
                        AddCreature(cr);

                        if (cr.Type == CreatureType.NPC) //Only one NPC allowed per name.
                        {
                            npcs.Add(cr.Name);
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        private void LoadSpawn(string fileName, ISet<ulong> tileLocations)
        {
            if (!File.Exists(fileName))
            {
                Trace.WriteLine("Can't load map spawns.");
                return;
            }

            var spawns = XElement.Load(fileName);

            foreach (var spawn in spawns.Elements("spawn"))
            {
                var centerLocation = new Location(spawn.Attribute("centerx").GetInt32(), spawn.Attribute("centery").GetInt32(),
                    spawn.Attribute("centerz").GetInt32());

                foreach (var creature in spawn.Elements())
                {
                    var cr = new OtCreature();
                    cr.Id = ++loadCreatureId;
                    cr.Name = creature.Attribute("name").GetString();
                    cr.Type = creature.Name.LocalName.Equals("npc") ? CreatureType.NPC : CreatureType.MONSTER;
                    cr.Location = new Location(centerLocation.X + creature.Attribute("x").GetInt32(),
                        centerLocation.Y + creature.Attribute("y").GetInt32(), creature.Attribute("z").GetInt32());

                    if (char.IsUpper(cr.Name[0]))
                        cr.Type = CreatureType.NPC;

                    if (tileLocations.Contains(cr.Location.ToIndex()) && (cr.Type != CreatureType.NPC || !npcs.Contains(cr.Name)))
                    {
                        AddCreature(cr);

                        if (cr.Type == CreatureType.NPC) //Only one NPC allowed per name.
                            npcs.Add(cr.Name);
                    }
                }
            }
        }
Ejemplo n.º 6
0
        public void AddCreature(OtCreature creature)
        {
            if (!creatures.ContainsKey(creature.Id))
            {
                var spawnLocation = new Location(creature.Location.X - (creature.Location.X % SPAWN_SIZE) + SPAWN_RADIUS,
                    creature.Location.Y - (creature.Location.Y % SPAWN_SIZE) + SPAWN_RADIUS, creature.Location.Z);
                var spawnIndex = spawnLocation.ToIndex();

                if (!spawns.ContainsKey(spawnIndex))
                    spawns.Add(spawnIndex, new OtSpawn(spawnLocation, SPAWN_RADIUS));

                var spwan = spawns[spawnIndex];

                if (spwan.AddCreature(creature))
                {
                    if (creature.Type == CreatureType.NPC)
                        npcCount++;
                    else if (creature.Type == CreatureType.MONSTER)
                        monsterCount++;

                    creatures.Add(creature.Id, creature);
                }
            }
        }