当前位置: 首页>>代码示例>>C#>>正文


C# Objects.GetItemInSlot方法代码示例

本文整理汇总了C#中System.Objects.GetItemInSlot方法的典型用法代码示例。如果您正苦于以下问题:C# Objects.GetItemInSlot方法的具体用法?C# Objects.GetItemInSlot怎么用?C# Objects.GetItemInSlot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Objects的用法示例。


在下文中一共展示了Objects.GetItemInSlot方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: LootItems

        /// <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);
//.........这里部分代码省略.........
开发者ID:KyLuaa,项目名称:bot,代码行数:101,代码来源:Cavebot.cs

示例2: LootItems

            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));
                    }
//.........这里部分代码省略.........
开发者ID:KyLuaa,项目名称:bot,代码行数:101,代码来源:Cavebot.Looter.cs


注:本文中的System.Objects.GetItemInSlot方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。