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); } }
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(); }
//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(); }
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)); }
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(); }
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); }
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); }
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; }
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; }
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); }
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; }
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); }
/// <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); }
/// <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); }
/// <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(); }
/// <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); }
public void Update() { if (creature != null && creature.Client != null && creature.Client.LoggedIn()) { name = creature.Name; location = creature.Location; hpBar = creature.HPBar; } }
public MapMarker(string cname, Location loc) { name = cname; location = loc; drawHPBar = false; }
//memory tile contructors internal Tile(Client client, uint address, uint squareNumber, Location location) : this(client, address, squareNumber) { this.location = location; }
/// <summary> /// Gets the distance between player and creature / player. /// </summary> /// <returns></returns> public double DistanceTo(Location l) { return Location.DistanceTo(l); }
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; } }
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); }
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); }
/// <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 && <= 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); } }
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); } } } }
public MapMarker(string cname, Location loc, byte hp) { name = cname; location = loc; hpBar = hp; drawHPBar = true; }
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); }
public void Update(Creature c) { name = c.Name; location = c.Location; hpBar = c.HPBar; }
/// <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; }