Ejemplo n.º 1
0
 public OtSpawn(Location location, int radius)
 {
     this.Location = location;
     this.Radius = radius;
     this.size = (radius * 2) + 1;
     creatures = new OtCreature[size, size];
 }
Ejemplo n.º 2
0
        public Tile(Location location)
        {
            Location = location;
            things = new List<Thing>();

            #if DEBUG_TILE
            if (location.Equals(DEBUG_LOCATION))
                debugEnable = true;
            #endif
        }
Ejemplo n.º 3
0
        internal void OnCreatureSpeak(uint statementId, string name, ushort level, MessageClasses type, Location location, string text)
        {
            var creature = client.BattleList.GetCreature(name);

            if (creature == null)
                return;

            creature.Level = level;
            CreatureSpeak.Raise(this, new CreatureSpeakEventArgs { Id = statementId, Creature = creature, Text = text, Type = type, Location = location });
        }
Ejemplo n.º 4
0
 public bool HasTile(Location location)
 {
     return HasTile(location.ToIndex());
 }
Ejemplo n.º 5
0
 public OtTile GetTile(Location location)
 {
     return GetTile(location.ToIndex());
 }
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);
                }
            }
        }
 public void WriteLocation(Location location)
 {
     WriteUShort((ushort)location.X);
     WriteUShort((ushort)location.Y);
     WriteByte((byte)location.Z);
 }
Ejemplo n.º 8
0
 public OtTile(Location location)
 {
     this.location = location;
 }
Ejemplo n.º 9
0
 private Location GetRelativeLocation(Location loc)
 {
     return new Location(loc.X - Location.X, loc.Y - Location.Y, loc.Z);
 }
Ejemplo n.º 10
0
 public Tile GetTile(Location location)
 {
     return tiles[location.X % 18, location.Y % 14, location.Z % 8];
 }
        private void ParseServerMoveWest(InMessage message)
        {
            var location = new Location(client.PlayerLocation.X - 1, client.PlayerLocation.Y, client.PlayerLocation.Z);
            client.PlayerLocation = location;

            var tiles = new List<Tile>();
            ParseServerMapDescription(message, tiles, location.X - 8, location.Y - 6, location.Z, 1, 14);
            client.Map.OnMapUpdated(tiles);
        }
        private void ParseServerMoveSouth(InMessage message)
        {
            var location = new Location(client.PlayerLocation.X, client.PlayerLocation.Y + 1, client.PlayerLocation.Z);
            client.PlayerLocation = location;

            var tiles = new List<Tile>();
            ParseServerMapDescription(message, tiles, location.X - 8, location.Y + 7, location.Z, 18, 1);
            client.Map.OnMapUpdated(tiles);
        }
        private void ParseServerFloorChangeUp(InMessage message)
        {
            Location myPos = client.PlayerLocation;
            myPos = new Location(myPos.X, myPos.Y, myPos.Z - 1);

            var tiles = new List<Tile>();
            if (myPos.Z == 7)
            {
                int skip = 0;
                ParseServerFloorDescription(message, tiles, myPos.X - 8, myPos.Y - 6, 5, 18, 14, 3, ref skip); //(floor 7 and 6 already set)
                ParseServerFloorDescription(message, tiles, myPos.X - 8, myPos.Y - 6, 4, 18, 14, 4, ref skip);
                ParseServerFloorDescription(message, tiles, myPos.X - 8, myPos.Y - 6, 3, 18, 14, 5, ref skip);
                ParseServerFloorDescription(message, tiles, myPos.X - 8, myPos.Y - 6, 2, 18, 14, 6, ref skip);
                ParseServerFloorDescription(message, tiles, myPos.X - 8, myPos.Y - 6, 1, 18, 14, 7, ref skip);
                ParseServerFloorDescription(message, tiles, myPos.X - 8, myPos.Y - 6, 0, 18, 14, 8, ref skip);

            }
            else if (myPos.Z > 7)
            {
                int skip = 0;
                ParseServerFloorDescription(message, tiles, myPos.X - 8, myPos.Y - 6, myPos.Z - 3, 18, 14, 3, ref skip);
            }

            client.PlayerLocation = new Location(myPos.X + 1, myPos.Y + 1, myPos.Z);
            client.Map.OnMapUpdated(tiles);
        }
        private void ParseServerFloorChangeDown(InMessage message)
        {
            Location myPos = client.PlayerLocation;
            myPos = new Location(myPos.X, myPos.Y, myPos.Z + 1);

            //going from surface to underground

            var tiles = new List<Tile>();

            int skipTiles = 0;
            if (myPos.Z == 8)
            {
                int j, i;
                for (i = myPos.Z, j = -1; i < (int)myPos.Z + 3; ++i, --j)
                    ParseServerFloorDescription(message, tiles, myPos.X - 8, myPos.Y - 6, i, 18, 14, j, ref skipTiles);
            }
            //going further down
            else if (myPos.Z > 8 && myPos.Z < 14)
                ParseServerFloorDescription(message, tiles, myPos.X - 8, myPos.Y - 6, myPos.Z + 2, 18, 14, -3, ref skipTiles);

            client.PlayerLocation = new Location(myPos.X - 1, myPos.Y - 1, myPos.Z);
            client.Map.OnMapUpdated(tiles);
        }
        private Tile ParseServerTileDescription(InMessage message, Location location)
        {
            Tile tile = new Tile(location);
            if (message.PeekUShort() < 0xFF00)
                message.ReadUShort();

            while (message.PeekUShort() < 0xFF00)
                tile.AddThing(GetThing(message));

            client.Map.SetTile(tile);
            return tile;
        }
Ejemplo n.º 16
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.º 17
0
        private void ParseTileArea(OtFileReader reader, OtFileNode otbNode, bool replaceTiles, ISet<ulong> tileLocations)
        {
            OtPropertyReader props = reader.GetPropertyReader(otbNode);

            int baseX = props.ReadUInt16();
            int baseY = props.ReadUInt16();
            int baseZ = props.ReadByte();

            OtFileNode nodeTile = otbNode.Child;

            while (nodeTile != null)
            {
                if (nodeTile.Type == (long)OtMapNodeTypes.TILE ||
                    nodeTile.Type == (long)OtMapNodeTypes.HOUSETILE)
                {
                    props = reader.GetPropertyReader(nodeTile);

                    var tileLocation = new Location(baseX + props.ReadByte(), baseY + props.ReadByte(), baseZ);

                    var tile = new OtTile(tileLocation);

                    if (nodeTile.Type == (long)OtMapNodeTypes.HOUSETILE)
                    {
                        tile.HouseId = props.ReadUInt32();
                    }

                    while (props.PeekChar() != -1)
                    {
                        byte attribute = props.ReadByte();
                        switch ((OtMapAttribute)attribute)
                        {
                            case OtMapAttribute.TILE_FLAGS:
                                {
                                    tile.Flags = props.ReadUInt32();
                                    break;
                                }
                            case OtMapAttribute.ITEM:
                                {
                                    ushort itemId = props.ReadUInt16();

                                    var itemType = Items.GetItem(itemId);
                                    if (itemType == null)
                                    {
                                        throw new Exception("Unkonw item type " + itemId + " in position " + tileLocation + ".");
                                    }

                                    var item = OtItem.Create(itemType);
                                    tile.InternalAddItem(item);

                                    break;
                                }
                            default:
                                throw new Exception(string.Format("{0} Unknown tile attribute.", tileLocation));
                        }
                    }

                    OtFileNode nodeItem = nodeTile.Child;

                    while (nodeItem != null)
                    {
                        if (nodeItem.Type == (long)OtMapNodeTypes.ITEM)
                        {
                            props = reader.GetPropertyReader(nodeItem);

                            ushort itemId = props.ReadUInt16();

                            var itemType = Items.GetItem(itemId);
                            if (itemType == null)
                            {
                                throw new Exception("Unkonw item type " + itemId + " in position " + tileLocation + ".");
                            }

                            var item = OtItem.Create(itemType);
                            item.Deserialize(reader, nodeItem, props, Items);

                            tile.InternalAddItem(item);
                        }
                        else
                        {
                            throw new Exception(string.Format("{0} Unknown node type.", tileLocation));
                        }
                        nodeItem = nodeItem.Next;
                    }

                    var index = tileLocation.ToIndex();
                    var hasTile = HasTile(index);

                    if (!hasTile)
                    {
                        SetTile(tile);
                        tileLocations.Add(tileLocation.ToIndex());
                    }
                    else if (replaceTiles)
                        SetTile(tile);
                }

                nodeTile = nodeTile.Next;
            }
        }
Ejemplo n.º 18
0
        public void PlayerGoTo(Location location)
        {
            if (IsClinentless || MemoryAddresses.PlayerGoX == 0 || !LoggedIn)
                return;

            Memory.WriteUInt16(ProcessHandle, MemoryAddresses.PlayerGoX, (ushort)location.X);
            Memory.WriteUInt16(ProcessHandle, MemoryAddresses.PlayerGoY, (ushort)location.Y);
            Memory.WriteByte(ProcessHandle, MemoryAddresses.PlayerGoZ, (byte)location.Z);
            Memory.WriteByte(ProcessHandle, MemoryAddresses.ClientBattleListStart + (PlayerBattleListIndex * MemoryAddresses.ClientBattleListStep)
                + MemoryAddresses.ClientBattleListCreatureWalkDistance, 1);
        }