Пример #1
0
        private IEnumerable<Tile> GetTiles(bool sameFloor, bool getWorldLocation)
        {
            Tile playerTile = null;
            uint startNumber = 0;
            uint endNumber = Addresses.Map.MaxTiles + 1;

            if (sameFloor)
            {
                playerTile = GetTileWithPlayer();

                if (playerTile != null)
                {
                    int playerFloor = playerTile.MemoryLocation.Z;
                    startNumber = new Location(0, 0, playerFloor).ToTileNumber();
                    endNumber = new Location(0, 0, playerFloor + 1).ToTileNumber();
                }
            }

            if (getWorldLocation && playerTile == null)
                playerTile = GetTileWithPlayer();

            for (uint i = startNumber; i < endNumber; i++)
            {
                if (getWorldLocation)
                    yield return GetTile(i, playerTile);
                else
                    yield return GetTile(i);
            }

        }
Пример #2
0
        public static bool Send(Objects.Client client, Location location, Effect effect)
        {
            MagicEffectPacket p = new MagicEffectPacket(client);
            p.Location = location;
            p.Effect = effect;

            return p.Send();
        }
Пример #3
0
        //packet tile constructors
        internal Tile(Client client, uint groundId, Location location)
        {
            this.type = ObjectType.Packet;
            this.client = client;
            this.location = location;
            this.items = new List<Item>();

            if (groundId > 0)
                this.ground = new Item(client, groundId);
        }
        public static bool Send(Objects.Client client, uint creatureId , string creatureName, Location location, string text)
        {
            UpdateCreatureTextPacket p = new UpdateCreatureTextPacket(client);

            p.CreatureId = creatureId;
            p.CreatureName = creatureName;
            p.Location = location;
            p.Text = text;

            return p.Send();
        }
Пример #5
0
        internal Tile(Client client, uint address, uint squareNumber)
        {
            this.type = ObjectType.Memory;
            this.client = client;
            this.squareNumber = squareNumber;
            this.address = address;
            this.memoryLocation = squareNumber.ToMemoryLocation();

            this.objectCount = client.Memory.ReadInt32(address + Pokemon.Addresses.Map.DistanceTileObjectCount) - 1;
            this.ground = new Item(client, client.Memory.ReadUInt32(address + 
                Pokemon.Addresses.Map.DistanceTileObjects + Pokemon.Addresses.Map.DistanceObjectId));
        }
Пример #6
0
        public static bool Send(Objects.Client client, string textId, Location location, Color color, ClientFont font, string text)
        {
            DisplayTextPacket p = new DisplayTextPacket(client);

            p.TextId = textId;
            p.Location = location;
            p.Color = color;
            p.Font = font;
            p.Text = text;

            return p.Send();
        }
        public static bool Send(Objects.Client client, uint creatureId , string creatureName, Location location, Color color, ClientFont font, string text)
        {
            DisplayCreatureTextPacket p = new DisplayCreatureTextPacket(client);

            p.CreatureId = creatureId;
            p.CreatureName = creatureName;
            p.Location = location;
            p.Color = color;
            p.Font = font;
            p.Text = text;

            return p.Send();
        }
Пример #8
0
        public bool DrawCreatureText(uint CreatureID, Location loc, Color color, ClientFont font, string Text)
        {
            //Testing that user has given valid values
            if (CreatureID == 0 || Text == string.Empty)
                return false;

            if (client.Dll.Pipe == null)
            {
                client.Dll.InitializePipe();
                client.Dll.PipeIsReady.WaitOne();
            }

            return Packets.Pipes.DisplayCreatureTextPacket.Send(client, CreatureID, "MyChar", loc, color, font, Text);
        }
Пример #9
0
        public bool DrawCreatureText(string creatureName, Location loc, Color color, ClientFont font, string text)
        {
            //Testing that user has given valid values
            if (creatureName == string.Empty || text == string.Empty)
                return false;

            if (client.Dll.Pipe == null)
            {
                client.Dll.InitializePipe();
                client.Dll.PipeIsReady.WaitOne();
            }

            return Packets.Pipes.DisplayCreatureTextPacket.Send(client, 0, creatureName, loc, color, font, text);
        }
Пример #10
0
        public override bool ParseMessage(NetworkMessage msg, PacketDestination destination)
        {
            if (msg.GetByte() != (byte)PipePacketType.UpdateCreatureText)
                return false;

            Type = PipePacketType.UpdateCreatureText;
            
            CreatureId = msg.GetUInt32();
            CreatureName = msg.GetString();
            Location = new Location((int)msg.GetUInt32(), (int)msg.GetUInt32(), 0);
            Text = msg.GetString();

            return true;
        }
Пример #11
0
        public override bool ParseMessage(NetworkMessage msg, PacketDestination destination)
        {
            if (msg.GetByte() != (byte)PipePacketType.DisplayText)
                return false;

            Type = PipePacketType.DisplayText;
            
            TextId = msg.GetString();
            Location = new Location((int)msg.GetUInt32(), (int)msg.GetUInt32(), 0);
            Color = Color.FromArgb((int)msg.GetUInt32(), (int)msg.GetUInt32(), (int)msg.GetUInt32());
            Font = (ClientFont)msg.GetUInt32();
            Text = msg.GetString();

            return true;
        }
Пример #12
0
        private static Location AdjustLocation(Location loc, int xDiff, int yDiff)
        {
            int xNew = loc.X - xDiff;
            int yNew = loc.Y - yDiff;

            if (xNew > 17)
                xNew -= 18;
            else if (xNew < 0)
                xNew += 18;

            if (yNew > 13)
                yNew -= 14;
            else if (yNew < 0)
                yNew += 14;

            return new Location(xNew, yNew, loc.Z);
        }
Пример #13
0
        protected bool ParseFloorDescription(NetworkMessage msg, int x, int y, int z, int width, int height, int offset, NetworkMessage outMsg)
        {
            ushort skipTiles;

            for (int nx = 0; nx < width; nx++)
            {
                for (int ny = 0; ny < height; ny++)
                {
                    if (m_skipTiles == 0)
                    {
                        ushort tileOpt = msg.PeekUInt16();
                        //Decide if we have to skip tiles
                        // or if it is a real tile
                        if (tileOpt >= 0xFF00)
                        {
                            skipTiles = msg.GetUInt16();
                            outMsg.AddUInt16(skipTiles);

                            m_skipTiles = (short)(skipTiles & 0xFF);
                        }
                        else
                        {
                            //real tile so read tile
                            Objects.Location pos = new Pokemon.Objects.Location(x + nx + offset, y + ny + offset, z);

                            if (!ParseTileDescription(msg, pos, outMsg))
                            {
                                return false;
                            }
                            //read skip tiles info
                            skipTiles = msg.GetUInt16();
                            outMsg.AddUInt16(skipTiles);

                            m_skipTiles = (short)(skipTiles & 0xFF);
                        }
                    }
                    //skipping tiles...
                    else
                    {
                        m_skipTiles--;
                    }
                }
            }
            return true;
        }
Пример #14
0
        protected bool ParseFloorDescription(NetworkMessage msg, int x, int y, int z, int width, int height, int offset, NetworkMessage outMsg)
        {
            ushort skipTiles;

            for (int nx = 0; nx < width; nx++)
            {
                for (int ny = 0; ny < height; ny++)
                {
                    if (m_skipTiles == 0)
                    {
                        ushort tileOpt = msg.PeekUInt16();
                        //Decide if we have to skip tiles
                        // or if it is a real tile
                        if (tileOpt >= 0xFF00)
                        {
                            skipTiles = msg.GetUInt16();
                            outMsg.AddUInt16(skipTiles);

                            m_skipTiles = (short)(skipTiles & 0xFF);
                        }
                        else
                        {
                            //real tile so read tile
                            Objects.Location pos = new Pokemon.Objects.Location(x + nx + offset, y + ny + offset, z);

                            if (!ParseTileDescription(msg, pos, outMsg))
                            {
                                return(false);
                            }
                            //read skip tiles info
                            skipTiles = msg.GetUInt16();
                            outMsg.AddUInt16(skipTiles);

                            m_skipTiles = (short)(skipTiles & 0xFF);
                        }
                    }
                    //skipping tiles...
                    else
                    {
                        m_skipTiles--;
                    }
                }
            }
            return(true);
        }
Пример #15
0
 /// <summary>
 /// Draw a marker with the default text fill and outline colors.
 /// </summary>
 /// <param name="l"></param>
 /// <param name="text"></param>
 /// <param name="markerFill"></param>
 /// <param name="markerOutline"></param>
 /// <param name="g"></param>
 private void DrawMarker(Location l, string text, Color markerFill, Color markerOutline, Graphics g)
 {
     DrawMarker(l, text, markerFill, markerOutline, Color.White, Color.Black, g);
 }
Пример #16
0
 /// <summary>
 /// Draw a marker with the default colors.
 /// </summary>
 /// <param name="l"></param>
 /// <param name="text"></param>
 /// <param name="g"></param>
 private void DrawMarker(Location l, string text, Graphics g)
 {
     DrawMarker(l, text, Color.Yellow, Color.Black, g);
 }
Пример #17
0
        /// <summary>
        /// Set the center of the map to a Tibia Location
        /// </summary>
        /// <param name="l"></param>
        public void SetMapCenter(Location l)
        {
            Point center = GetMapCenterPoint();

            int newX = (int)((l.X - mapBoundary.Left) * zoomFactor * -1 + center.X);
            int newY = (int)((l.Y - mapBoundary.Top) * zoomFactor * -1 + center.Y);

            imagePos.X = newX;
            imagePos.Y = newY;

            Invalidate();
        }
Пример #18
0
        /// <summary>
        /// Convert a Tibia Location to a point on the map
        /// </summary>
        /// <param name="l"></param>
        /// <returns></returns>
        public Point MapCoorsToPoint(Location l)
        {
            int x = l.X;
            int y = l.Y;
            int newX = (int)((x - mapBoundary.Left) * zoomFactor) + imagePos.X;
            int newY = (int)((y - mapBoundary.Top) * zoomFactor) + imagePos.Y;

            return new Point(newX, newY);
        }
Пример #19
0
 public void Update()
 {
     if (creature != null && creature.Client != null && creature.Client.LoggedIn())
     {
         name = creature.Name;
         location = creature.Location;
         hpBar = creature.HPBar;
     }
 }
Пример #20
0
 public MapMarker(string cname, Location loc)
 {
     name = cname;
     location = loc;
     drawHPBar = false;
 }
Пример #21
0
 //memory tile contructors
 internal Tile(Client client, uint address, uint squareNumber, Location location)
     : this(client, address, squareNumber)
 {
     this.location = location;
 }
Пример #22
0
 /// <summary>
 /// Gets the distance between player and creature / player.
 /// </summary>
 /// <returns></returns>
 public double DistanceTo(Location l)
 {
     return Location.DistanceTo(l);
 }
Пример #23
0
        protected bool ParseThing(NetworkMessage msg, Location pos, Tile tile, int n, NetworkMessage outMsg)
        {
            //get thing type
            ushort thingId = msg.GetUInt16();
            outMsg.AddUInt16(thingId);

            PacketCreature c;

            if (thingId == 0x0061 || thingId == 0x0062)
            {

                c = new PacketCreature(Client);
                c.Location = pos;

                //creatures
                if (thingId == 0x0062) //creature is known
                {
                    c.Type = PacketCreatureType.Known;
                    c.Id = msg.GetUInt32();
                    outMsg.AddUInt32(c.Id); //creatureid
                }
                else if (thingId == 0x0061)
                { //creature is not known
                    //perhaps we have to remove a known creature
                    c.RemoveId = msg.GetUInt32();
                    outMsg.AddUInt32(c.RemoveId);

                    //add a new creature
                    c.Type = PacketCreatureType.Unknown;
                    c.Id = msg.GetUInt32();
                    outMsg.AddUInt32(c.Id);

                    c.Name = msg.GetString();
                    outMsg.AddString(c.Name);
                }

                //read creature properties
                c.Health = msg.GetByte();
                outMsg.AddByte(c.Health);

                c.Direction = msg.GetByte();
                outMsg.AddByte(c.Direction);

                c.Outfit = msg.GetOutfit();
                outMsg.AddOutfit(c.Outfit);

                c.LightLevel = msg.GetByte();
                outMsg.AddByte(c.LightLevel);

                c.LightColor = msg.GetByte();
                outMsg.AddByte(c.LightColor);

                c.Speed = msg.GetUInt16();
                outMsg.AddUInt16(c.Speed);

                c.Skull = (Constants.Skull)msg.GetByte();
                outMsg.AddByte((byte)c.Skull);

                c.PartyShield = (Constants.PartyShield)msg.GetByte();
                outMsg.AddByte((byte)c.PartyShield);

                creatures.Add(c);

                return true;
            }
            else if (thingId == 0x0063)
            {
                //creature turn
                c = new PacketCreature(Client);
                c.Location = pos;
                c.Type = PacketCreatureType.Turn;
                c.Id = msg.GetUInt32();
                outMsg.AddUInt32(c.Id);

                c.Direction = msg.GetByte();
                outMsg.AddByte(c.Direction);

                creatures.Add(c);

                return true;
            }
            else
            {
                //item
                UInt16 itemId;
                if (thingId == UInt16.MaxValue)
                {
                    itemId = msg.GetUInt16();
                    outMsg.AddUInt16(itemId);
                }
                else
                    itemId = thingId;

                Item item = new Item(Client, itemId, 0, "", ItemLocation.FromLocation(pos, (byte)n));

                if (item.HasExtraByte)
                {
                    item.Count = msg.GetByte();
                    outMsg.AddByte(item.Count);
                }

                if (n == 0)
                    tile.Ground = item;
                else
                    tile.Items.Add(item);

                return true;
            }
        }
Пример #24
0
        public bool UpdateCreatureText(string CreatureName, Location loc, string NewText)
        {
            //Testing that user has given valid values
            if (CreatureName == string.Empty || NewText == string.Empty)
                return false;

            if (client.Dll.Pipe == null)
            {
                client.Dll.InitializePipe();
                client.Dll.PipeIsReady.WaitOne();
            }

            return Packets.Pipes.UpdateCreatureTextPacket.Send(client, 0, CreatureName, loc, NewText);
        }
Пример #25
0
 private void DrawMarker(Location l, string text, Color markerFill, Color markerOutline, Color textFill, Color textOutline, Graphics g)
 {
     DrawMarker(l, text, markerFill, markerOutline, textFill, textOutline, -1, g);
 }
Пример #26
0
        /// <summary>
        /// Draw a marker given the specifications.
        /// </summary>
        /// <param name="l"></param>
        /// <param name="text"></param>
        /// <param name="markerFill"></param>
        /// <param name="markerOutline"></param>
        /// <param name="textFill"></param>
        /// <param name="textOutline"></param>
        /// <param name="hpBar">if hpBar >= 0 &amp;&amp; &lt;= 100 draw an HP bar</param>
        /// <param name="g"></param>
        private void DrawMarker(Location l, string text, Color markerFill, Color markerOutline, Color textFill, Color textOutline, int hpBar, Graphics g)
        {
            // Convert to Tibia coors
            Point p = MapCoorsToPoint(l);

            // This array of points makes the marker
            Point[] points = {
                new Point(p.X - 3, p.Y - 25),
                new Point(p.X + 3, p.Y - 25),
                new Point(p.X + 3, p.Y - 20),
                new Point(p.X + 10, p.Y - 20),
                new Point(p.X, p.Y),
                new Point(p.X - 10, p.Y - 20),
                new Point(p.X - 3, p.Y - 20)
            };

            // Anti-aliased for nice effect
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

            // Draw the marker
            g.FillPolygon(new SolidBrush(markerFill), points);
            g.DrawPolygon(new Pen(markerOutline), points);

            // The text font
            Font font = new Font("Tahoma", 8, FontStyle.Bold);

            // The rectangle to hold the text
            Rectangle rect = new Rectangle(p.X - 100, 
                p.Y - (((hpBar >= 0 && hpBar <= 100) ? 33 : 27) + font.Height), 
                200, font.Height);

            // Center the text
            StringFormat sf = new StringFormat();
            sf.Alignment = StringAlignment.Center;

            // Add "up" or "down" to the name
            if (l.Z != 0 && l.Z != currentZ)
                text += " (" + (currentZ - l.Z > 0 ? "+" : "") + (currentZ - l.Z) + ")";

            // Draw the outlined text
            DrawOutlinedText(text, font, new SolidBrush(textFill), new SolidBrush(textOutline), rect, sf, g);

            // Draw HP bar if needed
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None;
            if (hpBar >= 0 && hpBar <= 100)
            {
                Rectangle hpOuter = new Rectangle(p.X - 14, p.Y - 27 - 4, 28, 4);
                Rectangle hpInner = new Rectangle(p.X - 13, p.Y - 26 - 4,
                    (int)(hpBar / 100.0 * 26), 2);
                g.FillRectangle(Brushes.Black, hpOuter);
                g.FillRectangle(new SolidBrush(Misc.HpPercentToColor(hpBar)), hpInner);
            }
        }
Пример #27
0
        public override void ToNetworkMessage(NetworkMessage msg)
        {
            Tile playerTile = Client.Map.GetTileWithPlayer();
            msg.AddByte((byte)Type);
            msg.AddLocation(playerTile.Location);

            //GetMapDescription(playerLocation.X - 8, playerLocation.Y - 6, playerLocation.Z, 18, 14, msg);

            int startz, endz, zstep;

            if (playerTile.Location.Z > 7)
            {
                startz = playerTile.Location.Z - 2;
                endz = Math.Min(15, playerTile.Location.Z + 2);
                zstep = 1;
            }
            else
            {
                startz = 7;
                endz = 0;
                zstep = -1;
            }

            uint mapStart = Client.Memory.ReadUInt32(Addresses.Map.MapPointer);

            for (int z = startz; z != endz + zstep; z += zstep)
            {
                for (int x = 0; x < 18; x++)
                {
                    for (int y = 0; y < 14; y++)
                    {
                        Location memLoc = new Location(x, y, z);
                        uint num = memLoc.ToTileNumber();
                        Tile pCurrent = new Tile(Client, mapStart + (Addresses.Map.StepTile * num), num);

                        foreach (TileObject o in pCurrent.Objects)
                        {
                            if (o.Id == 0x0063)
                            {
                                // Add a creature
                                Creature c = Client.BattleList.GetCreatures().FirstOrDefault(cr => cr.Id == o.Data);

                                if (c == null)
                                    throw new Exception("Creature does not exist.");

                                // Add as unknown
                                msg.AddUInt16((ushort)o.Id);

                                // No need to remove a creature
                                msg.AddUInt32(0);

                                // Add the creature id
                                msg.AddUInt32((uint)c.Id);

                                msg.AddString(c.Name);

                                msg.AddByte((byte)c.HPBar);

                                msg.AddByte((byte)c.Direction);

                                msg.AddOutfit(c.Outfit);

                                msg.AddByte((byte)c.Light);

                                msg.AddByte((byte)c.LightColor);

                                msg.AddUInt16((ushort)c.WalkSpeed);

                                msg.AddByte((byte)c.Skull);

                                msg.AddByte((byte)c.PartyShield);
                            }
                            else
                            {
                                Item item = new Item(Client, (uint)o.Id);

                                msg.AddUInt16((ushort)item.Id);

                                if (item.HasExtraByte)
                                    msg.AddByte(item.Count);
                            }
                        }

                        msg.AddByte(0x00);
                        msg.AddByte(0xFF);
                    }
                }
            }

        }
Пример #28
0
 public MapMarker(string cname, Location loc, byte hp)
 {
     name = cname;
     location = loc;
     hpBar = hp;
     drawHPBar = true;
 }
Пример #29
0
    private Tile GetTile(Location worldLocation, Tile playerTile)
    {
        // All credits goes to blaster_89 who solved this.
        if (playerTile == null) { playerTile = GetTileWithPlayer(); }
         Location memLoc = worldLocation.ToMemoryLocation(playerTile,client);
         uint num = memLoc.ToTileNumber();
 
        int minFloor = 0, maxFloor = 0;
        for (int i = 0; i < 8; i++)
        { 
            if (playerTile.TileNumber   >= Addresses.Map.MaxTiles  * i &&
                playerTile.TileNumber <= Addresses.Map.MaxTiles * (i + 1))
            {
         
                minFloor =  Convert.ToInt32(Addresses.Map.MaxTiles * i);
                maxFloor =  Convert.ToInt32(Addresses.Map.MaxTiles * (i + 1) - 1);
                break;
            }
        }
        if (num > maxFloor) { num = Convert.ToUInt32(num - maxFloor + minFloor - 1); }
        else if (num < minFloor) { num = Convert.ToUInt32(maxFloor - minFloor + num + 1); }
        return GetTile(num, playerTile);
    }
Пример #30
0
 public void Update(Creature c)
 {
     name = c.Name;
     location = c.Location;
     hpBar = c.HPBar;
 }
Пример #31
0
 /// <summary>
 /// Convert a map file name to a location
 /// </summary>
 /// <param name="fileName"></param>
 /// <returns></returns>
 private static Location MapFileNameToLocation(string fileName)
 {
     Location l = new Location(0, 0, 0);
     if (fileName.Length == 12 || fileName.Length == 8)
     {
         l.X = Int32.Parse(fileName.Substring(0, 3)) * MapFileDimension;
         l.Y = Int32.Parse(fileName.Substring(3, 3)) * MapFileDimension;
         l.Z = Int32.Parse(fileName.Substring(6, 2));
     }
     return l;
 }