Ejemplo n.º 1
0
            public bool LootItems(Objects.Container container, IEnumerable <Loot> loot, bool async)
            {
                if (!container.IsOpen)
                {
                    return(false);
                }

                if (async)
                {
                    //if (this.ResetEvent.IsSet) return false;

                    if (this.DedicatedThread == null || !this.DedicatedThread.IsAlive)
                    {
                        this.DedicatedThread = new Thread(this.Run);
                        this.DedicatedThread.Start();
                        this.ResetEventMultiUse.WaitOne();
                    }

                    if (this.LootItemsCalled != null)
                    {
                        this.LootItemsCalled(container, loot);
                    }
                    return(true);
                }

                this.LootItems(container, loot, this.CachedTiles);
                return(true);
            }
Ejemplo n.º 2
0
 public void OpenParentContainer(Objects.Container c)
 {
     this.FunctionOpenParentContainer.Call(c.OrderNumber);
     if (this.ContainerOpenedParent != null)
     {
         this.ContainerOpenedParent(c);
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Attempts to close a container.
 /// </summary>
 /// <param name="c">The container to close.</param>
 public void CloseContainer(Objects.Container c)
 {
     this.FunctionCloseContainer.Call(c.OrderNumber);
     if (this.ContainerClosed != null)
     {
         this.ContainerClosed(c);
     }
 }
Ejemplo n.º 4
0
        public ItemLocation LootToIndex(Item item, byte index)
        {
            Objects.Container c = Core.client.Inventory.GetContainer(index);

            ItemLocation loc;

            if (c.Ammount < c.Volume)
            {
                if (c.Ammount == 0)
                {
                    loc = ItemLocation.FromContainer((byte)c.Number, 0);
                    return(loc);
                }
                Item LootItem = c.GetItems().FirstOrDefault((Item j) => j.Id == item.Id & j.Count < 100);
                if (LootItem != null)
                {
                    loc = LootItem.Location;
                    return(loc);
                }
                else
                {
                    loc = ItemLocation.FromContainer((byte)c.Number, (byte)c.Ammount);
                    return(loc);
                }
            }
            else
            {
                if (item.ItemData.IsStackable)
                {
                    foreach (Item o in c.GetItems())
                    {
                        if (o.Id == item.Id && o.Count < 100)
                        {
                            loc = o.Location;
                            return(loc);
                        }
                    }
                }


                //this means the bp is full lets see if we find a bp insde
                if (Core.Global.OpenNextBp)
                {
                    foreach (Item o in c.GetItems())
                    {
                        if (o.ItemData.IsContainer)
                        {
                            o.Use(index);
                            Core.SleepRandom();
                            return(LootToIndex(item, index));
                        }
                    }
                }
            }
            return(null);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Waits for an item to be moved, used etc.
 /// Returns true if interaction is completed within the timeframe.
 /// Returns false if time expires.
 /// </summary>
 /// <param name="maxTime">Max amount of milliseconds to wait.</param>
 /// <returns></returns>
 public bool WaitForInteraction(int maxTime)
 {
     if (this.IsContainerItem())
     {
         Objects.Container parent = this.GetParent();
         if (parent == null || !parent.IsOpen)
         {
             return(true);
         }
         byte itemAmount = parent.ItemsAmount;
         for (int i = 0; i < maxTime; i += 50)
         {
             if (itemAmount != parent.ItemsAmount)
             {
                 return(true);
             }
             Item tempItem = parent.GetItemInSlot(this.Slot);
             if (tempItem == null)
             {
                 return(true);
             }
             if (tempItem.ID != this.ID || tempItem.Count != this.Count)
             {
                 return(true);
             }
             System.Threading.Thread.Sleep(50);
         }
         return(false);
     }
     else
     {
         for (int i = 0; i < maxTime; i += 50)
         {
             Item tempItem = this.Client.Inventory.GetItemInSlot((Enums.EquipmentSlots) this.ContainerNumber);
             if (tempItem == null)
             {
                 return(true);
             }
             if (tempItem.ID != this.ID || tempItem.Count != this.Count)
             {
                 return(true);
             }
             else if (tempItem.ID == 0)
             {
                 return(true);
             }
             System.Threading.Thread.Sleep(50);
         }
         return(false);
     }
 }
Ejemplo n.º 6
0
        public ItemLocation LootTo(Item item)
        {
            ItemLocation loc = default(ItemLocation);

            for (int i = 0; i <= Core.LastCorpse - 1; i++)
            {
                Objects.Container c = Core.client.Inventory.GetContainer(Convert.ToByte(i));
                if (c.Ammount < c.Volume)
                {
                    if (c.Ammount == 0)
                    {
                        loc = ItemLocation.FromContainer((byte)c.Number, 0);
                        break;
                    }
                    Item LootItem = c.GetItems().FirstOrDefault((Item j) => j.Id == item.Id & j.Count < 100);
                    if (LootItem != null)
                    {
                        loc = LootItem.Location;
                        break;
                    }
                    else
                    {
                        loc = ItemLocation.FromContainer((byte)c.Number, (byte)c.Ammount);
                        break;
                    }
                }
                else
                {
                    foreach (Item o in c.GetItems())
                    {
                        if (o.Id == item.Id && o.Count < 100)
                        {
                            loc = o.Location;
                            break;
                        }
                    }
                }
            }
            return(loc);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Updates the ID and Count values.
 /// </summary>
 public void Update()
 {
     if (this.IsContainerItem())
     {
         Objects.Container parent = this.GetParent();
         if (parent == null || !parent.IsOpen || this.Slot >= parent.ItemsAmount)
         {
             this.ID    = 0;
             this.Count = 0;
         }
         else
         {
             this.ID = this.Client.Memory.ReadUInt16(this.Address +
                                                     this.Client.Addresses.Item.Distances.ID);
             this.Count = this.Client.Memory.ReadUInt16(this.Address +
                                                        this.Client.Addresses.Item.Distances.Count);
         }
     }
     else
     {
         this.ID    = this.Client.Memory.ReadUInt16(this.Address + this.Client.Addresses.Item.Distances.ID);
         this.Count = this.Client.Memory.ReadUInt16(this.Address + this.Client.Addresses.Item.Distances.Count);
     }
 }
Ejemplo n.º 8
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);
                    }
                }
            }
Ejemplo n.º 9
0
            private void Run()
            {
                Map.TileCollection tiles         = null;
                Objects.Map.Tile   corpseTile    = null;
                Objects.Container  lootContainer = null;
                Loot[]             loots         = null;
                Random             rand          = new Random();

                this.OpenCorpseCalled += new OpenCorpseCalledHandler(delegate(Map.TileCollection tileCollection, Objects.Map.Tile tile)
                {
                    tiles      = tileCollection;
                    corpseTile = tile;
                    this.ResetEvent.Set();
                });
                this.LootItemsCalled += new LootItemsCalledHandler(delegate(Objects.Container container, IEnumerable <Loot> loot)
                {
                    lootContainer = container;
                    loots         = loot.ToArray();
                    this.ResetEvent.Set();
                });

                // signal parent thread that this thread is ready
                this.ResetEventMultiUse.Set();

                while (true)
                {
                    try
                    {
                        this.Cancel = false;
                        this.ResetEvent.Wait();

                        #region open corpse
                        if (corpseTile != null)
                        {
                            while (!this.Cancel)
                            {
                                this.ResetEventMultiUse.WaitOne();

                                if (this.Cancel || corpseTile == null)
                                {
                                    break;
                                }
                                if (!this.Parent.Client.Player.Location.IsOnScreen(corpseTile.WorldLocation))
                                {
                                    break;
                                }
                                if (this.Parent.Client.Player.IsWalking)
                                {
                                    continue;
                                }

                                Map.TileObject topItem = corpseTile.GetTopUseItem(false);
                                if (topItem == null || !topItem.HasFlag(Enums.ObjectPropertiesFlags.IsContainer))
                                {
                                    break;
                                }
                                Objects.Map.Tile playerTile = this.CachedTiles.GetTile(count: this.Parent.Client.Player.ID);
                                if (playerTile == null)
                                {
                                    break;
                                }

                                if (playerTile.WorldLocation.DistanceTo(corpseTile.WorldLocation) >= 2)
                                {
                                    int distance = int.MaxValue;
                                    Objects.Map.Tile bestTile = corpseTile;
                                    foreach (Objects.Map.Tile tile in this.CachedTiles.GetAdjacentTileCollection(corpseTile).GetTiles())
                                    {
                                        if (!tile.IsWalkable())
                                        {
                                            continue;
                                        }

                                        var pathToTile = playerTile.WorldLocation.GetTilesToLocation(this.Parent.Client,
                                                                                                     tile.WorldLocation, this.CachedTiles, this.Parent.PathFinder, true).ToArray();
                                        if (pathToTile.Length == 0)
                                        {
                                            continue;
                                        }

                                        if (distance > pathToTile.Length)
                                        {
                                            distance = pathToTile.Length;
                                            bestTile = tile;
                                        }
                                    }

                                    if (bestTile == corpseTile &&
                                        !playerTile.WorldLocation.CanReachLocation(this.Parent.Client, bestTile.WorldLocation))
                                    {
                                        break;
                                    }

                                    this.Parent.Client.Player.GoTo = bestTile.WorldLocation;
                                    continue;
                                }

                                for (int i = 0; i < 2; i++)
                                {
                                    if (this.Cancel)
                                    {
                                        break;
                                    }
                                    Objects.Container container = this.Parent.Client.Inventory.GetContainer(this.Parent.Client.Inventory.GetClosedContainerNumber());
                                    topItem.Use();
                                    for (int j = 0; j < 5; j++)
                                    {
                                        Thread.Sleep(100);
                                        if (container.IsOpen)
                                        {
                                            break;
                                        }
                                    }
                                    if (!container.IsOpen)
                                    {
                                        continue;
                                    }
                                    if (this.CorpseOpened != null)
                                    {
                                        this.CorpseOpened(container);
                                    }
                                    break;
                                }
                                break;
                            }

                            corpseTile = null;
                        }
                        #endregion

                        #region loot item(s)
                        if (lootContainer != null)
                        {
                            if (!lootContainer.IsOpen || lootContainer.ItemsAmount == 0)
                            {
                                if (!this.Cancel && this.LootingFinished != null)
                                {
                                    this.LootingFinished(lootContainer);
                                }
                                lootContainer = null;
                                continue;
                            }

                            this.LootItems(lootContainer, loots, tiles);

                            if (!this.Cancel && this.LootingFinished != null)
                            {
                                this.LootingFinished(lootContainer);
                            }

                            lootContainer = null;
                            loots         = null;
                        }
                        #endregion

                        this.ResetEvent.Reset();
                    }
                    catch (Exception ex)
                    {
                        if (this.ErrorOccurred != null)
                        {
                            this.ErrorOccurred(ex);
                        }
                    }
                }
            }