/// <summary> /// Executes the specified location. /// </summary> /// <param name="location">The location.</param> public bool Execute(Location location) { //First execution. if (StartTime == DateTime.MinValue) { StartTime = DateTime.Now; } //Player is attacking. if (Player.Target != null) { return false; } if (Player.IsWalking == false) { //Elapsed time verification. var elapsed = DateTime.Now.Subtract(StartTime); if (elapsed.TotalSeconds >= MaxSecondsIdle) { //if (IsDestinationOutOfRange()) { throw new Exception("The destination is unreachable!"); } throw new Exception("The maximum idle time has been reached."); } //Send the player to requested location. else { Player.Go(location); } } else { StartTime = DateTime.Now; } //Requested location has arrived. if (Player.Location.Equals(location)) { return true; } //Restart the process. Location = location; Wait(200); return Execute(Location); }
/// <summary> /// Drop the stacked item to defined location. /// </summary> public void ContainerToGround(ISlot slotSource, Location sqm) { #region " Packet Structure Analyze " //--------------------------------------------------------- //DROP ITEM //--------------------------------------------------------- //00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 //--------------------------------------------------------- //0F 00 78 FF FF 40 00 00 25 0B 00 34 7D CC 7D 07 01 //SZ ID BP ST ITEMD ST [ X ] [ Y ] ZZ QT //--------------------------------------------------------- #endregion var Builder = new PacketBuilder(0x78, Connection); Builder.Append(0xFF); Builder.Append(0xFF); Builder.Append(slotSource.Container.Position); Builder.Append(0x00); Builder.Append(slotSource.Position); Builder.Append(slotSource.Item.Id); Builder.Append(slotSource.Position); Builder.Append(sqm.X); Builder.Append(sqm.Y); Builder.Append(sqm.Z); Builder.Append(slotSource.Item.Count); Connection.Send(Builder.GetPacket()); }
/// <summary> /// Move the Player to Defined Location. /// </summary> public void Go(Location to) { Model.Player nPlayer = new Model.Player(Connection); Memory.Writer.Uint(Memory.Addresses.Player.GoTo_X, to.X, 2); Memory.Writer.Uint(Memory.Addresses.Player.GoTo_Y, to.Y, 2); Memory.Writer.Uint(Memory.Addresses.Player.GoTo_Z, to.Z, 1); nPlayer.IsWalking = true; }
/// <summary> /// Initializes a new instance of the <see cref="Sqm"/> class. /// </summary> /// <param name="sqmNumber">The SQM number.</param> /// <param name="map">The map.</param> /// <param name="worldLocation">The world location.</param> public Sqm(uint sqmNumber, GraphicsProvider map, Location worldLocation) { Map = map; SqmNumber = sqmNumber; Address = Map.SqmNumberToSqmAddress(SqmNumber); MemoryLocation = map.GetSqmLocation(SqmNumber); WorldLocation = worldLocation; }
/// <summary> /// Gets items in defined location. /// </summary> /// <param name="sqm">The SQM Location.</param> /// <returns></returns> public List<Item> GetItems(Location sqm) { var returnItems = new List<Item>(); var items = GetTileObjectsList(sqm); foreach (TileObject item in items) { returnItems.Add(new Item((uint)item.GetObjectID, (uint)item.GetData)); } return returnItems; }
/// <summary> /// Verify if exists the item in defined Location. /// </summary> /// <param name="sqm">The SQM.</param> /// <param name="itemID">The item ID.</param> /// <returns></returns> public bool ExistItem(Location sqm, uint itemID) { List<TileObject> items = GetTileObjectsList(sqm); foreach (TileObject item in items) { if (item.GetObjectID == (int)itemID) { return true; } } return false; }
public static UpdateCreatureTextPacket Create(ConnectionProvider connection, int CreatureID, string CreatureName, Location TextLoc, string NewText) { PipePacketBuilder p = new PipePacketBuilder(connection, PipePacketType.UpdateCreatureText); p.AddLong(CreatureID); p.AddString(CreatureName); p.AddShort(TextLoc.X); p.AddShort(TextLoc.Y); p.AddString(NewText); return new UpdateCreatureTextPacket(connection, p.GetPacket()); }
public static DisplayTextPacket Create(ConnectionProvider connection, string textId, Location loc, Color color, ClientFont font, string text) { PipePacketBuilder p = new PipePacketBuilder(connection, PipePacketType.DisplayText); p.AddString(textId); p.AddInt(loc.X.ToInt32()); p.AddInt(loc.Y.ToInt32()); p.AddInt(color.R); p.AddInt(color.G); p.AddInt(color.B); p.AddInt((int)font); p.AddString(text); return new DisplayTextPacket(connection, p.GetPacket()); }
public static DisplayCreatureTextPacket Create(ConnectionProvider connection, int creatureID, string creatureName, Location loc, Color color, ClientFont font, string text) { PipePacketBuilder p = new PipePacketBuilder(connection, PipePacketType.DisplayCreatureText); p.AddLong(creatureID); p.AddString(creatureName); p.AddShort(loc.X); p.AddShort(loc.Y); p.AddInt(color.R); p.AddInt(color.G); p.AddInt(color.B); p.AddInt((int)font); p.AddString(text); return new DisplayCreatureTextPacket(connection, p.GetPacket()); }
/// <summary> /// Updates the creature text. /// </summary> /// <param name="CreatureID">The creature ID.</param> /// <param name="loc">The loc.</param> /// <param name="NewText">The new text.</param> public void UpdateCreatureText(int CreatureID, Location loc, string NewText) { Connection.Pipe.Send(UpdateCreatureTextPacket.Create(Connection, CreatureID, "", loc, NewText)); }
/// <summary> /// Gets objects in defined location. /// </summary> /// <param name="sqm">The SQM Location.</param> /// <returns></returns> public List<TileObject> GetTileObjectsList(Location sqm) { return new List<TileObject>(Reader.GetTileObjects(new LocationDefinition((int)sqm.X, (int)sqm.Y, (int)sqm.Z))); }
/// <summary> /// Worlds to memory. /// </summary> /// <param name="location">The location.</param> /// <param name="playerSqm">The player SQM.</param> /// <returns></returns> internal Location WorldToMemory(Location location, Sqm playerSqm) { var memoryLocation = playerSqm.MemoryLocation; uint x = Player.Location.X - memoryLocation.X; uint y = Player.Location.Y - memoryLocation.Y; uint z = Player.Location.Z - memoryLocation.Z; return new Location(location.X - x, location.Y - y, location.Z - z); }
/// <summary> /// Draws the creature text. /// </summary> /// <param name="creatureName">Name of the creature.</param> /// <param name="loc">The loc.</param> /// <param name="color">The color.</param> /// <param name="font">The font.</param> /// <param name="text">The text.</param> public void DrawCreatureText(string creatureName, Location loc, Color color, ClientFont font, string text) { Connection.Pipe.Send(DisplayCreatureTextPacket.Create(Connection, 0, creatureName, loc, color, font, text)); }
/// <summary> /// Gets the SQM number. /// </summary> /// <param name="location">The location.</param> /// <returns></returns> internal uint GetSqmNumber(Location location) { return (location.X + location.Y * 18 + location.Z * 14 * 18).ToUInt32(); }
/// <summary> /// Memories to world. /// </summary> /// <param name="location">The location.</param> /// <param name="playerSqm">The player SQM.</param> /// <returns></returns> internal Location MemoryToWorld(Location location, Sqm playerSqm) { var memoryLocation = playerSqm.MemoryLocation; uint x = Player.Location.X - memoryLocation.X; uint y = Player.Location.Y - memoryLocation.Y; uint z = Player.Location.Z - memoryLocation.Z; return new Location(location.X + x, location.Y + y, location.Z + z); }
/// <summary> /// Distances the specified from. /// </summary> /// <param name="from">From.</param> /// <param name="to">To.</param> /// <returns></returns> public static int Distance(Location from, Location to) { var ix = (from.X - to.X).ToPositive(); var iy = (from.Y - to.Y).ToPositive(); return ((ix + iy) / 2).ToInt32(); }
/// <summary> /// Draws the creature text. /// </summary> /// <param name="CreatureID">The creature ID.</param> /// <param name="loc">The loc.</param> /// <param name="color">The color.</param> /// <param name="font">The font.</param> /// <param name="Text">The text.</param> public void DrawCreatureText(int CreatureID, Location loc, Color color, ClientFont font, string Text) { Connection.Pipe.Send(DisplayCreatureTextPacket.Create(Connection, CreatureID, "MyChar", loc, color, font, Text)); }
/// <summary> /// Use the Defined Item to the Ground. /// e.g: Rope on Ground, Obsidian Knife on Creature, Shovel on Role, etc. /// </summary> public void OnGround(ISlot slotSource, Location sqm, uint tileID, uint stackPosition) { #region " Packet Structure Analyze " //--------------------------------------------------------- //USE ROPE //--------------------------------------------------------- //00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 //--------------------------------------------------------- //11 00 83 FF FF 40 00 0D BB 0B 0D 64 7F C3 7B 0A 82 01 00 //SZ ID BP ST ROPE ST [ X ] [ Y ] ZZ [TID] ?? //--------------------------------------------------------- #endregion PacketBuilder Builder = new PacketBuilder(0x83, connection); Builder.Append(0xFF); Builder.Append(0xFF); Builder.Append(slotSource.Container.Position); Builder.Append(0x00); Builder.Append(slotSource.Position); Builder.Append(slotSource.Item.Id); Builder.Append(slotSource.Position); Builder.Append(sqm.X); Builder.Append(sqm.Y); Builder.Append(sqm.Z); Builder.Append(tileID); Builder.Append(stackPosition); Connection.Send(Builder.GetPacket()); }
/// <summary> /// Draws the screen text. /// </summary> /// <param name="TextName">Name of the text.</param> /// <param name="loc">The loc.</param> /// <param name="color">The color.</param> /// <param name="font">The font.</param> /// <param name="text">The text.</param> public void DrawScreenText(string TextName, Location loc, Color color, ClientFont font, string text) { Connection.Pipe.Send(DisplayTextPacket.Create(Connection, TextName, loc, color, font, text)); }
/// <summary> /// Drop the stacked item to defined location. /// </summary> public void Drop(Location sqm) { if (Id == InventoryID.Container) { StackActions.ContainerToGround(this, sqm); } else { StackActions.SlotToGround(Item, sqm); } }
/// <summary> /// Send a Animated Message to Client. /// </summary> public byte[] SendAnimated(AnimatedMsgColor color, Location sqm, string message) { #region "[rgn] Packet Structure Analyze " #endregion PacketBuilder Builder = new PacketBuilder(0x84, Connection); Builder.Append(sqm.X, 2); Builder.Append(sqm.Y, 2); Builder.Append(sqm.Z, 1); Builder.Append(color.GetHashCode(), 1); Builder.Append(message, true); Builder.SetPacketSource(PacketSource.Server); Connection.Send(Builder.GetPacket()); return Builder.GetPacket().Data; }
/// <summary> /// Move the Player to Defined Location. /// </summary> public void Go(Location To) { Actions.Position.Go(To); }
/// <summary> /// Use the Defined Item to the Ground. /// e.g: Rope on Ground, Obsidian Knife on Creature, Shovel on Role, etc. /// </summary> public void UseOnGround(Location sqm, uint tileID, uint stackPosition) { UseActions.OnGround(Slot, sqm, tileID, stackPosition); }
/// <summary> /// Initializes a new instance of the <see cref="LocationEventArgs"/> class. /// </summary> /// <param name="location">The location.</param> public LocationEventArgs(Location location) { Location = location; }
/// <summary> /// Use the Defined Item in Ground. /// e.g: Eat Food in Ground, Up Stairs, Open Container. /// </summary> public void InGround(Location sqm, uint itemId, uint stackPosition, bool isContainer) { #region " Packet Structure Analyze " //------------------------------------ //Bag //------------------------------------ //0A 00 82 15 7E ED 7B 07 25 0B 01 01 //------------------------------------ //00 01 02 03 04 05 06 07 08 09 10 11 //------------------------------------ #endregion PacketBuilder Builder = new PacketBuilder(0x82, connection); Builder.Append(sqm.X); Builder.Append(sqm.Y); Builder.Append(sqm.Z); Builder.Append(itemId); Builder.Append(stackPosition); if (isContainer) { Builder.Append(new Model.Player(Connection).Containers.Count); } else { Builder.Append(0x00); } Connection.Send(Builder.GetPacket()); }
/// <summary> /// Gets the SQM. /// </summary> /// <param name="loc">The loc.</param> /// <returns></returns> public Sqm GetSQM(Location loc) { var playerSqm = GetPlayerSqm(); var memoryLocation = WorldToMemory(loc, playerSqm); var sqmNumber = GetSqmNumber(memoryLocation); return new Sqm(sqmNumber, this, playerSqm); }
/// <summary> /// Use the Defined Item on a Player in Defined SQM and Drop after use if needed. /// e.g: Use Fluids on Players, Use Runes on Players, etc. /// </summary> public void OnPlayer(ISlot slotSource, Location sqm, bool dropAfterUse) { #region " Packet Structure Analyze " // SZ ID BP SLOT HMM X Y Z ?? QD //---------------------------------------------------------------------- // 11 00 83 FF FF 40 00 00 7E 0C 00 15 7E ED 7B 07 63 00 01 //---------------------------------------------------------------------- // 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 #endregion PacketBuilder Builder = new PacketBuilder(0x83, connection); Builder.Append(0xFF); Builder.Append(0xFF); Builder.Append(slotSource.Container.Position); Builder.Append(0x00); Builder.Append(slotSource.Position); Builder.Append(slotSource.Item.Id); Builder.Append(slotSource.Position); Builder.Append(sqm.X); Builder.Append(sqm.Y); Builder.Append(sqm.Z); Builder.Append(0x63); Builder.Append(0x00); Builder.Append(0x01); //TODO: Test increase this ammount. Connection.Send(Builder.GetPacket()); if (dropAfterUse) { System.Threading.Thread.Sleep(300); new Stack(Connection).ContainerToGround(slotSource, sqm); } }
/// <summary> /// Gets the SQms. /// </summary> /// <param name="range">The range.</param> /// <param name="location">The location.</param> /// <returns></returns> public SqmCollection GetSQMs(int range, Location location) { var sqms = new SqmCollection(); var centerSqm = ((range - 1) / 2); int rows = range, columns = range; for (int r = 0; r < rows; r++) { for (int c = 0; c < columns; c++) { var loc = new Location(); loc.Z = location.Z; loc.X = location.X + ((uint)((-centerSqm) + c)); loc.Y = location.Y + ((uint)((-centerSqm) + r)); sqms.Add(GetSQM(loc)); } } return sqms; }
/// <summary> /// Distances the specified to. /// </summary> /// <param name="to">To.</param> /// <returns></returns> public int Distance(Location to) { return Distance(this, to); }
/// <summary> /// Gets the SQM location. /// </summary> /// <param name="sqmNumber">The SQM number.</param> /// <returns></returns> internal Location GetSqmLocation(uint sqmNumber) { var location = new Location(); location.Z = sqmNumber / (14 * 18); location.Y = (sqmNumber - location.Z * 14 * 18) / 18; location.X = (sqmNumber - location.Z * 14 * 18) - location.Y * 18; return location; }