Пример #1
0
 public void Move(Objects.ItemLocation toLocation)
 {
     if (toLocation != null)
     {
         Move(toLocation, (byte)this.Count);
     }
 }
Пример #2
0
 /// <summary>
 /// Attempts to use an item on this creature.
 /// </summary>
 /// <param name="itemLocation">The item to use.</param>
 public void UseItemOn(Objects.ItemLocation itemLocation)
 {
     if (itemLocation != null)
     {
         this.Client.Packets.UseItemOnLocation(itemLocation, this.Location);
     }
 }
Пример #3
0
 /// <summary>
 /// Attempts to use an item on a world location.
 /// If possible, use UseItemOnTile instead, as it provides better performance.
 /// </summary>
 /// <param name="itemLocation">The item's location.</param>
 /// <param name="loc">The world location to use the item on.</param>
 public void UseItemOnLocation(Objects.ItemLocation itemLocation, Objects.Location loc)
 {
     if (itemLocation == null || !loc.IsValid())
     {
         return;
     }
     this.UseItemOnTile(itemLocation, this.Client.Map.GetTile(loc, null));
 }
Пример #4
0
 /// <summary>
 /// Attempts to use an item on a tile.
 /// </summary>
 /// <param name="itemLocation">The item's location.</param>
 /// <param name="tile">The tile to use the item on.</param>
 public void UseItemOnTile(Objects.ItemLocation itemLocation, Map.Tile tile)
 {
     if (itemLocation == null || tile == null)
     {
         return;
     }
     Objects.Map.TileObject tileObj = tile.GetTopUseItem(true);
     this.UseItemOnTileObject(itemLocation, tileObj);
 }
Пример #5
0
 /// <summary>
 /// Attempts to move this item to a given item location.
 /// </summary>
 /// <param name="toLocation">The item locatino to move this item to.</param>
 /// <param name="count">How many of this item to move.</param>
 public void Move(Objects.ItemLocation toLocation, ushort count)
 {
     if (toLocation == null)
     {
         return;
     }
     Objects.ItemLocation itemLoc = this.ToItemLocation();
     itemLoc.ItemCount = count;
     this.Client.Packets.MoveItem(itemLoc, toLocation);
 }
Пример #6
0
 /// <summary>
 /// Attempts to use an item on the battlelist. Useful for shooting runes on creatures.
 /// </summary>
 /// <param name="itemLocation">The item's location.</param>
 /// <param name="c">The creature to use the item on..</param>
 public void UseItemOnBattleList(Objects.ItemLocation itemLocation, Objects.Creature c)
 {
     if (itemLocation == null || c == null)
     {
         return;
     }
     this.FunctionUseItemOnBattleList.Call(itemLocation.WorldLocation.X, itemLocation.WorldLocation.Y, itemLocation.WorldLocation.Z,
                                           itemLocation.ItemID, itemLocation.StackIndex, c.ID);
     if (this.ItemUsedOnBattleList != null)
     {
         this.ItemUsedOnBattleList(itemLocation, c);
     }
 }
Пример #7
0
 /// <summary>
 /// Attempts to move an item from one location to another.
 /// </summary>
 /// <param name="fromItem">The item to be moved.</param>
 /// <param name="toItem">The new location for the item.</param>
 public void MoveItem(Objects.ItemLocation fromItem, Objects.ItemLocation toItem)
 {
     if (fromItem == null || toItem == null)
     {
         return;
     }
     this.FunctionMoveItem.Call(fromItem.WorldLocation.X, fromItem.WorldLocation.Y, fromItem.WorldLocation.Z,
                                fromItem.ItemID, fromItem.StackIndex,
                                toItem.WorldLocation.X, toItem.WorldLocation.Y, toItem.WorldLocation.Z, fromItem.ItemCount);
     if (this.ItemMoved != null)
     {
         this.ItemMoved(fromItem, toItem);
     }
 }
Пример #8
0
 /// <summary>
 /// Attempts to use an item on a tile object.
 /// Use this method with the utmost care, and only send this packet when getting a tile's top item.
 /// </summary>
 /// <param name="itemLocation"></param>
 /// <param name="tileObject"></param>
 public void UseItemOnTileObject(Objects.ItemLocation itemLocation, Map.TileObject tileObject)
 {
     if (itemLocation == null || tileObject == null)
     {
         return;
     }
     this.FunctionUseItemEx.Call(itemLocation.WorldLocation.X, itemLocation.WorldLocation.Y, itemLocation.WorldLocation.Z,
                                 itemLocation.ItemID, itemLocation.StackIndex,
                                 tileObject.Parent.WorldLocation.X, tileObject.Parent.WorldLocation.Y, tileObject.Parent.WorldLocation.Z,
                                 tileObject.ID, tileObject.StackIndex);
     if (this.ItemUsedOn != null)
     {
         this.ItemUsedOn(itemLocation, tileObject.ToItemLocation());
     }
 }
Пример #9
0
            /// <summary>
            /// Attempts to use an item.
            /// </summary>
            /// <param name="itemLocation">The item location to use.</param>
            /// <param name="openInNewWindow">Set this to true if you intend to open an item on the ground, or open a carrying container in a new window.</param>
            public void UseItem(Objects.ItemLocation itemLocation, bool openInNewWindow)
            {
                if (itemLocation == null)
                {
                    return;
                }

                this.FunctionUseItem.Call(itemLocation.WorldLocation.X, itemLocation.WorldLocation.Y, itemLocation.WorldLocation.Z,
                                          itemLocation.ItemID, itemLocation.StackIndex,
                                          !openInNewWindow ?
                                          itemLocation.WorldLocation.Y - Constants.Inventory.MinimumContainerNumber :
                                          this.Client.Inventory.GetClosedContainerNumber());
                if (this.ItemUsed != null)
                {
                    this.ItemUsed(itemLocation);
                }
            }
Пример #10
0
        public void Move(Objects.ItemLocation toLocation, byte count)
        {
            byte c = (byte)((count == 0) ? 1 : count);

            switch (Location.Type)
            {
            case Constants.ItemLocationType.Ground:
                Packets.OutGoing.MoveItem.Send(client, Location.ToLocation(), (ushort)Id, Location.StackOrder, toLocation.ToLocation(), c);
                break;

            case Constants.ItemLocationType.Container:
                Packets.OutGoing.MoveItem.Send(client, Location.ToLocation(), (ushort)Id, Location.ContainerSlot, toLocation.ToLocation(), c);
                break;

            case Constants.ItemLocationType.Slot:
                Packets.OutGoing.MoveItem.Send(client, Location.ToLocation(), (ushort)Id, (byte)Location.Slot, toLocation.ToLocation(), c);
                break;
            }
        }
Пример #11
0
 /// <summary>
 /// Attempts to move this item to a given item location.
 /// </summary>
 /// <param name="toLocation">The item location to move this item to.</param>
 public void Move(Objects.ItemLocation toLocation)
 {
     this.Move(toLocation, this.Count);
 }
Пример #12
0
        /// <summary>
        /// Attempts to make one or more runes.
        /// </summary>
        /// <param name="spellName">The name of the spell.</param>
        /// <param name="runeMana">Minimum amount of mana required to make a rune.</param>
        /// <param name="doMakeUntilMana">Maximum mana to stop recursively making runes.</param>
        /// <param name="makeUntilMana">Whether to recursively make runes.</param>
        public void MakeRune(string spellName, ushort runeMana, bool doMakeUntilMana = false, int makeUntilMana = 0)
        {
            // check if player is connected
            if (!this.Connected)
            {
                return;
            }

            // check if the player has enough mana for the rune
            if (this.Mana < runeMana)
            {
                return;
            }

            // check if the player carries any blank runes
            Item blankRune = this.Client.Inventory.GetItem(this.Client.ItemList.Runes.Blank);

            if (blankRune == null)
            {
                return;
            }

            // check if there is an item in the right hand and move the item
            Item itemRightHand = this.Client.Inventory.GetItemInSlot(Enums.EquipmentSlots.RightHand);

            if (itemRightHand != null)
            {
                Objects.ItemLocation targetItem = this.Client.Inventory.GetFirstSuitableSlot(itemRightHand);
                if (targetItem == null)
                {
                    return;
                }
                itemRightHand.Move(targetItem);
                for (int i = 0; i < 5; i++)
                {
                    if (itemRightHand.WaitForInteraction(1000))
                    {
                        break;
                    }
                    targetItem = this.Client.Inventory.GetFirstSuitableSlot(itemRightHand);
                    if (targetItem == null)
                    {
                        return;
                    }
                    itemRightHand.Move(targetItem);
                }
                Thread.Sleep(500);
            }

            while (true) // initiate loop in case of recursive runemaking
            {
                // find a blank rune and move it to right hand
                blankRune = this.Client.Inventory.GetItem(this.Client.ItemList.Runes.Blank);
                if (blankRune == null)
                {
                    break;
                }
                for (int i = 0; i < 5; i++)
                {
                    blankRune = this.Client.Inventory.GetItem(this.Client.ItemList.Runes.Blank);
                    if (blankRune == null)
                    {
                        break;
                    }
                    Objects.Item temp = this.Client.Inventory.GetItemInSlot(Enums.EquipmentSlots.RightHand);
                    if (temp != null)
                    {
                        break;
                    }
                    blankRune.Move(new ItemLocation(Enums.EquipmentSlots.RightHand));
                    if (blankRune.WaitForInteraction(1000))
                    {
                        break;
                    }
                }

                Thread.Sleep(1000);

                // say the spell and wait for the rune to transform
                for (int i = 0; i < 5; i++)
                {
                    Item tempItem = this.Client.Inventory.GetItemInSlot(Enums.EquipmentSlots.RightHand);
                    if (tempItem == null)
                    {
                        break;
                    }
                    if (tempItem.ID != this.Client.ItemList.Runes.Blank)
                    {
                        break;
                    }
                    this.Client.Packets.Say(spellName);
                    if (tempItem.WaitForInteraction(1000))
                    {
                        break;
                    }
                }
                Thread.Sleep(1000);

                // move the made rune back to its container
                // if the source container is full, try to find a free slot elsewhere
                Item transformedRune = this.Client.Inventory.GetItemInSlot(Enums.EquipmentSlots.RightHand);
                if (transformedRune == null)
                {
                    break;
                }
                Objects.ItemLocation toItem = blankRune.GetParent() != null?blankRune.GetParent().GetFirstEmptySlot() : null;

                if (toItem == null)
                {
                    toItem = this.Client.Inventory.GetFirstSuitableSlot(transformedRune);
                }
                if (toItem == null)
                {
                    break;
                }
                for (int i = 0; i < 5; i++)
                {
                    transformedRune = this.Client.Inventory.GetItemInSlot(Enums.EquipmentSlots.RightHand);
                    if (transformedRune == null)
                    {
                        break;
                    }
                    transformedRune.Move(toItem);
                    if (transformedRune.WaitForInteraction(1000))
                    {
                        break;
                    }
                }
                Thread.Sleep(1000);

                // check if the player should make more runes
                if (doMakeUntilMana && this.Client.Player.Mana > makeUntilMana)
                {
                    continue;
                }
                break;
            }

            // put the item the player carried in his right hand back to its slot
            if (itemRightHand == null)
            {
                return;
            }
            Item oldRHandItem = itemRightHand;

            while (this.Client.Inventory.GetItemInSlot(Enums.EquipmentSlots.RightHand) == null)
            {
                itemRightHand = this.Client.Inventory.GetItem(oldRHandItem.ID);
                if (itemRightHand == null)
                {
                    break;
                }
                itemRightHand.Move(new ItemLocation(Enums.EquipmentSlots.RightHand));
                if (itemRightHand.WaitForInteraction(1000))
                {
                    break;
                }
            }
        }
Пример #13
0
 /// <summary>
 /// Attempts to move this object to a given item location.
 /// </summary>
 /// <param name="c">The client used to perform the operation on.</param>
 /// <param name="toLocation">The item location to move this item to.</param>
 public void Move(Objects.ItemLocation toLocation)
 {
     this.Parent.Client.Packets.MoveItem(this.ToItemLocation(), toLocation);
 }
Пример #14
0
 /// <summary>
 /// Move an item to a location (eg. move a blank rune to the right hand).
 /// </summary>
 /// <param name="toLocation"></param>
 /// <returns></returns>
 public bool Move(Objects.ItemLocation toLocation)
 {
     return(Move(toLocation, this.count));
 }
Пример #15
0
            private void LootItems(Objects.Container lootContainer, IEnumerable <Loot> loots,
                                   Map.TileCollection tiles)
            {
                Random rand = new Random();

                if (!this.Parent.StopwatchFoodEater.IsRunning)
                {
                    this.Parent.StopwatchFoodEater.Start();
                }
                int index = lootContainer.ItemsAmount - 1, retryCount = 0;

                while (index >= 0 && !this.Cancel)
                {
                    // sanity checks
                    if (lootContainer.ItemsAmount == 0 || !lootContainer.IsOpen)
                    {
                        break;
                    }
                    if (retryCount >= 3)
                    {
                        retryCount = 0;
                        index--;
                        continue;
                    }

                    // get item
                    Objects.Item item = lootContainer.GetItemInSlot((byte)index);
                    if (item == null)
                    {
                        index--;
                        retryCount = 0;
                        continue;
                    }

                    // check if it's food, eat it if so
                    if (this.Parent.CurrentSettings.EatFood &&
                        this.Parent.StopwatchFoodEater.Elapsed.TotalSeconds > 20 &&
                        this.Parent.Client.ItemList.Food.All.Contains(item.ID))
                    {
                        if (item.Count <= 1)
                        {
                            item.Use();
                        }
                        else
                        {
                            for (int i = 0; i < Math.Min(item.Count, (ushort)3); i++)
                            {
                                item.Use();
                                Thread.Sleep(rand.Next(200, 325));
                            }
                        }
                        this.Parent.StopwatchFoodEater.Restart();
                        Thread.Sleep(rand.Next(200, 350));
                        index--;
                        continue;
                    }

                    // check if we want to loot this item
                    Loot loot = null;
                    foreach (Loot l in loots)
                    {
                        if (l.ID == item.ID)
                        {
                            loot = l;
                            break;
                        }
                    }
                    if (loot == null)
                    {
                        index--;
                        continue;
                    }

                    // loot this item
                    bool successful = false;
                    switch (loot.Destination)
                    {
                    case Loot.Destinations.Ground:
                        Objects.Map.Tile playerTile = tiles.GetTile(count: this.Parent.Client.Player.ID);
                        if (playerTile == null)
                        {
                            break;
                        }
                        List <Map.Tile> adjacentTiles = tiles.GetAdjacentTileCollection(playerTile).GetTiles().ToList();
                        adjacentTiles.Shuffle();
                        foreach (Objects.Map.Tile tile in adjacentTiles)
                        {
                            if (!tile.IsWalkable())
                            {
                                continue;
                            }

                            item.Move(new Objects.ItemLocation(tile.WorldLocation));
                            successful = true;
                            break;
                        }
                        break;

                    case Loot.Destinations.EmptyContainer:
                        Objects.ItemLocation toItem = this.Parent.Client.Inventory.GetFirstSuitableSlot(item, loot.Index);
                        if (toItem == null)
                        {
                            break;
                        }
                        item.Move(toItem);
                        successful = true;
                        break;
                    }

                    // if successful, check if it's looted
                    // if it wasn't looted, try again
                    if (successful)
                    {
                        if (!item.WaitForInteraction(800))
                        {
                            retryCount++;
                            continue;
                        }
                        if (this.Parent.ItemLooted != null)
                        {
                            this.Parent.ItemLooted(item);
                        }
                        if (!this.Parent.CurrentSettings.FastLooting)
                        {
                            Thread.Sleep(rand.Next(400, 700));
                        }
                    }

                    retryCount = 0;
                    index--;
                }

                if (this.Parent.CurrentSettings.OpenContainers &&
                    !this.Cancel &&
                    lootContainer.IsOpen &&
                    lootContainer.ItemsAmount > 0)
                {
                    bool found = false;
                    foreach (Objects.Item item in lootContainer.GetItems().Reverse())
                    {
                        if (item.HasFlag(Enums.ObjectPropertiesFlags.IsContainer))
                        {
                            for (int i = 0; i < 3; i++)
                            {
                                item.Use();
                                if (item.WaitForInteraction(800))
                                {
                                    break;
                                }
                            }
                            found = true;
                            break;
                        }
                    }
                    if (found)
                    {
                        this.LootItems(lootContainer, loots, this.CachedTiles);
                    }
                }
            }
Пример #16
0
 /// <summary>
 /// Move an item to a location (eg. move a blank rune to the right hand).
 /// </summary>
 /// <param name="toLocation"></param>
 /// <returns></returns>
 public bool Move(Objects.ItemLocation toLocation, byte count)
 {
     return(Packets.Outgoing.ItemMovePacket.Send(client, location.ToLocation(), (ushort)id, location.ToBytes()[4], toLocation.ToLocation(), count));
 }
Пример #17
0
        /// <summary>
        /// Loots all items from a given container.
        /// </summary>
        /// <param name="fromContainer">The Objects.Container object to loot.</param>
        private void LootItems(Objects.Container fromContainer)
        {
            if (fromContainer == null || !fromContainer.IsOpen || fromContainer.ItemsAmount == 0) return;
            if (!this.StopwatchFoodEater.IsRunning) this.StopwatchFoodEater.Start();
            int index = fromContainer.ItemsAmount - 1,
                retryCount = 0;
            Random rand = new Random();
            #region item handling for this container
            while (index >= 0)
            {
                if (!fromContainer.IsOpen || fromContainer.ItemsAmount == 0) return;
                if (retryCount >= 3)
                {
                    retryCount = 0;
                    index--;
                    continue;
                }

                Objects.Item item = fromContainer.GetItemInSlot((byte)index);
                if (item == null)
                {
                    index--;
                    continue;
                }
                // check if it's food, and eat if it is
                if (!this.StopwatchFoodEater.IsRunning) this.StopwatchFoodEater.Start();
                if (this.CurrentSettings.EatFood &&
                    this.Client.ItemList.Food.All.Contains(item.ID) &&
                    this.StopwatchFoodEater.ElapsedMilliseconds >= 16000)
                {
                    this.StopwatchFoodEater.Reset();
                    this.StopwatchFoodEater.Start();
                    ushort amount = item.Count;
                    item.Use();
                    if (amount <= 1)
                    {
                        Thread.Sleep(rand.Next(175, 265));
                        index--;
                        continue;
                    }
                    else
                    {
                        for (int i = 0; i < Math.Min(amount, (ushort)3); i++)
                        {
                            item = fromContainer.GetItemInSlot((byte)index);
                            if (item == null) break;
                            item.Use();
                            Thread.Sleep(rand.Next(150, 280));
                            if (this.Client.Window.StatusBar.GetText() == Enums.StatusBar.YouAreFull) break;
                        }
                        if (fromContainer.GetItemInSlot((byte)index) == null)
                        {
                            index--;
                            continue;
                        }
                    }
                }
                // check if item is in the loot list
                Loot loot = null;
                foreach (Loot l in this.Loots.ToArray())
                {
                    if (l.ID != item.ID) continue;

                    loot = l;
                    break;
                }
                if (loot == null ||
                    (loot.Destination != Loot.Destinations.Ground && loot.Cap > this.Client.Player.Cap))
                {
                    index--;
                    continue;
                }
                Objects.ItemLocation toItem = null;
                switch (loot.Destination)
                {
                    case Loot.Destinations.Ground:
                        Map.Tile playerTile = this.Client.Map.GetPlayerTile();
                        if (playerTile == null) break;
                        List<Map.Tile> adjacentTiles = new List<Map.Tile>(this.Client.Map.GetAdjacentTiles(playerTile).GetTiles());
                        adjacentTiles.Shuffle();
                        Map.Tile suitableTile = playerTile;
                        foreach (Map.Tile t in adjacentTiles)
                        {
                            if (t.IsWalkable())
                            {
                                suitableTile = t;
                                break;
                            }
                        }
                        Map.TileObject topItem = suitableTile.GetTopMoveItem();
                        item.Move(topItem.ToItemLocation());
                        toItem = new Objects.ItemLocation(new Objects.Item(this.Client));
                        break;
                    case Loot.Destinations.EmptyContainer:
                        toItem = this.Client.Inventory.GetFirstSuitableSlot(item, loot.Index);
                        if (toItem != null) item.Move(toItem);
                        break;
                }
                if (toItem != null)
                {
                    if (!item.WaitForInteraction(800))
                    {
                        retryCount++;
                        continue;
                    }
                    else
                    {
                        if (this.ItemLooted != null) this.ItemLooted(item);
                        if (!this.CurrentSettings.FastLooting) Thread.Sleep(rand.Next(350, 700));
                        retryCount = 0;
                    }
                }
                index--;
            }
            #endregion
            index = (byte)(fromContainer.ItemsAmount - 1); retryCount = 0;
            if (!this.CurrentSettings.OpenContainers) return;
            while (index >= 0)
            {
                if (!fromContainer.IsOpen || fromContainer.ItemsAmount == 0) return;
                if (retryCount >= 3) { retryCount = 0; index--; continue; }

                Objects.Item item = fromContainer.GetItemInSlot((byte)index);
                if (item == null)
                {
                    index--;
                    continue;
                }
                if (item.HasFlag(Enums.ObjectPropertiesFlags.IsContainer))
                {
                    item.Use();
                    if (!item.WaitForInteraction(800))
                    {
                        retryCount++;
                        continue;
                    }
                    else
                    {
                        if (!this.CurrentSettings.FastLooting) Thread.Sleep(rand.Next(450, 600));
                        this.LootItems(fromContainer);
                        return;
                    }
                }
                index--;
            }
        }