public bool GoToBed(Food foodEaten = null) { this.TimeOfLastLogin = Environment.TickCount; if (!this.Parent.Player.Connected) { return(true); } int oneHour = 1000 * 60 * 60, regenTime = foodEaten != null ? (int)(maxRegenTime - foodEaten.RegenerationTime) : 0; int timeToSleep = this.Parent.Player.Mana >= this.SpellMana ? 1000 * 60 * 45 // wait 45 minutes if no blanks are present : (int)Math.Ceiling(((float)(this.SpellMana - this.Parent.Player.Mana) / (float)manaPerHour) * oneHour + 1000 * 3); if (regenTime > 0 && timeToSleep > regenTime) { timeToSleep = regenTime; } if (timeToSleep > maxRegenTime) { timeToSleep = maxRegenTime; } this.TimeNeededToRegen = timeToSleep; System.IO.File.AppendAllText("bedmagedebug.txt", DateTime.UtcNow.TimeOfDay.ToString() + " - " + this.CharacterName + " - sleep time: " + TimeSpan.FromMilliseconds(this.TimeNeededToRegen).ToString() + " ate food: " + (foodEaten != null ? "yes" : "no") + "\n"); TileCollection tiles = null; while (!this.Parent.Player.Location.IsAdjacentTo(this.BedLocation)) { Thread.Sleep(500); if (this.Parent.Player.IsWalking) { continue; } if (!this.Parent.Player.Location.IsOnScreen(this.BedLocation)) { return(false); } tiles = this.Parent.Map.GetTilesOnScreen(); // find closest adjacent tile int closestDistance = 50; Location closestLocation = Location.Invalid; foreach (Tile adjTile in tiles.GetAdjacentTiles(this.BedLocation)) { var tilesToAdjLocation = this.Parent.Player.Location.GetTilesToLocation(this.Parent, adjTile.WorldLocation, tiles, this.Parent.PathFinder).ToArray(); if (tilesToAdjLocation.Length == 0) { continue; } if (closestDistance <= tilesToAdjLocation.Length) { continue; } closestDistance = tilesToAdjLocation.Length; closestLocation = adjTile.WorldLocation; } if (!closestLocation.IsValid()) { return(false); } this.Parent.Player.GoTo = closestLocation; } tiles = this.Parent.Map.GetTilesOnScreen(); Tile tile = tiles.GetTile(this.BedLocation); if (tile == null) { return(false); } TileObject topItem = tile.GetTopUseItem(false); if (topItem == null) { return(false); } while (this.Parent.Player.Connected) { topItem.Use(); Thread.Sleep(500); } return(true); }
public static void Main(Client client) { List <ushort> depotLockers = new List <ushort>() { 2589, 2590, 2591, 2592 //7.6+ 3497, 3498, 3499, 3500 }; List <DepotItem> itemsToDeposit = new List <DepotItem>() { new DepotItem(2599, 2594) //new DepotItem(2004, 2594) // yellow (ankrahmun) bps to depot chest }; List <DepotItem> itemsToTake = new List <DepotItem>() { new DepotItem(2599, 2594, 1) //new DepotItem(2004, 2004, 1) // yellow bps from a yellow bp inside locker }; Location currentLockerLocation = Location.Invalid; TileCollection tilesOnScreen = null; Tile playerTile = null; // find and reach depot locker while (true) { Thread.Sleep(500); if (client.Player.IsWalking) { continue; } if (currentLockerLocation.IsValid() && client.Player.Location == currentLockerLocation) { break; } tilesOnScreen = client.Map.GetTilesOnScreen(); var lockerTiles = tilesOnScreen.GetTileCollectionWithObjects(depotLockers); if (lockerTiles.IsEmpty()) { break; } playerTile = tilesOnScreen.GetPlayerTile(); if (playerTile == null) { break; } var tiles = lockerTiles.GetTiles().ToList(); tiles.Sort(delegate(Tile first, Tile second) { return(playerTile.WorldLocation.DistanceTo(first.WorldLocation).CompareTo( playerTile.WorldLocation.DistanceTo(second.WorldLocation))); }); foreach (Tile t in tiles) { TileObject topItem = t.GetTopUseItem(false); if (!depotLockers.Contains(topItem.ID)) { continue; } Tile closestTile = tilesOnScreen.GetClosestNearbyTile(playerTile, t); if (closestTile == null) { continue; } currentLockerLocation = closestTile.WorldLocation; client.Player.GoTo = currentLockerLocation; break; } } if (!currentLockerLocation.IsValid() || client.Player.Location != currentLockerLocation) { return; } // open depot locker tilesOnScreen = client.Map.GetTilesOnScreen(); playerTile = tilesOnScreen.GetPlayerTile(); if (playerTile == null) { return; } foreach (Tile adjacentTile in tilesOnScreen.GetAdjacentTiles(playerTile)) { Container depotContainer = client.Inventory.GetFirstClosedContainer(); for (int i = 0; i < 5; i++) { adjacentTile.UpdateObjects(); TileObject topItem = adjacentTile.GetTopUseItem(false); if (!depotLockers.Contains(topItem.ID)) { break; } topItem.Use(); Thread.Sleep(500); if (!depotContainer.IsOpen) { continue; } break; } if (!depotContainer.IsOpen) { continue; } // locker is open, run deposit logic // sort by depth itemsToDeposit.Sort(delegate(DepotItem first, DepotItem second) { return(first.Depth.CompareTo(second.Depth)); }); DepotItem last = null, current = null; for (int i = 0; i < itemsToDeposit.Count; i++) { current = itemsToDeposit[i]; // get back to root container if necessary if (last == null || current.ContainerID != last.ContainerID || current.Depth != last.Depth) { while (depotContainer.HasParent) { depotContainer.OpenParentContainer(); Thread.Sleep(500); } } // open containers if necessary byte depth = 0; while (current.Depth > depth && depotContainer.IsOpen) { Item subContainer = null; if (current.ContainerID != 0) { subContainer = depotContainer.GetItem(current.ContainerID); if (subContainer == null) { break; } if (!subContainer.HasFlag(Enums.ObjectPropertiesFlags.IsContainer)) { break; } } else { foreach (Item item in depotContainer.GetItems()) { if (!item.HasFlag(Enums.ObjectPropertiesFlags.IsContainer)) { continue; } subContainer = item; break; } } if (subContainer == null) { break; } subContainer.Use(); Thread.Sleep(1000); depth++; } // check if we reached the depth // if not, skip this item if (current.Depth != depth) { continue; } // move items to depot foreach (Item item in client.Inventory.GetItems()) { if (!depotContainer.IsOpen) { break; } if (current.ItemID != item.ID) { continue; } if (current.ContainerID == 0) // no container specified, put in current container { if (depotContainer.IsFull) { break; } ItemLocation slot = depotContainer.GetFirstEmptySlot(); if (slot == null) { break; } item.Move(slot); item.WaitForInteraction(500); break; } // put item inside container Item subContainer = depotContainer.GetItem(current.ContainerID); if (subContainer == null) { break; } item.Move(subContainer.ToItemLocation()); item.WaitForInteraction(500); break; } last = current; } // deposit logic done, run withdraw logic if (itemsToTake.Count == 0 || !depotContainer.IsOpen) { return; } last = null; for (int i = 0; i < itemsToTake.Count; i++) { current = itemsToTake[i]; // get back to root container if necessary if (last == null || current.ContainerID != last.ContainerID || current.Depth != last.Depth) { while (depotContainer.HasParent) { depotContainer.OpenParentContainer(); Thread.Sleep(500); } } // open containers if necessary byte depth = 0; while (current.Depth > depth && depotContainer.IsOpen) { Item subContainer = null; if (current.ContainerID != 0) { subContainer = depotContainer.GetItem(current.ContainerID); if (subContainer == null) { break; } if (!subContainer.HasFlag(Enums.ObjectPropertiesFlags.IsContainer)) { break; } } else { foreach (Item item in depotContainer.GetItems()) { if (!item.HasFlag(Enums.ObjectPropertiesFlags.IsContainer)) { continue; } subContainer = item; break; } } if (subContainer == null) { break; } subContainer.Use(); Thread.Sleep(1000); depth++; } // check if we reached the depth // if not, skip this item if (current.Depth != depth) { continue; } // move items to the player's inventory foreach (Item item in depotContainer.GetItems()) { if (!depotContainer.IsOpen) { break; } if (current.ItemID != item.ID) { continue; } ItemLocation slot = client.Inventory.GetFirstSuitableSlot(item); if (slot == null) { break; } item.Move(slot); item.WaitForInteraction(500); break; } } if (depotContainer != null && depotContainer.IsOpen) { depotContainer.Close(); } return; } }