示例#1
0
        private bool ShouldPurchaseItem(ShopPurchase shopPurchase)
        {
            var info = Data.ShopItemMap[shopPurchase.ShopItem];

            var itemData = info.ItemData;

            var itemCount = itemData.ItemCount();

            // check inventory count
            if (itemCount >= shopPurchase.MaxCount)
            {
                return(false);
            }

            if (ConditionParser.FreeItemSlots() == 0 && itemCount == 0)
            {
                return(false);
            }

            // check cost
            switch (info.ShopType)
            {
            case ShopType.BlueCrafter:
                if (Memory.Scrips.BlueCrafter < info.Cost)
                {
                    return(false);
                }
                break;

            case ShopType.RedCrafter:
                if (Memory.Scrips.RedCrafter < info.Cost)
                {
                    return(false);
                }
                break;

            case ShopType.BlueGatherer:
                if (Memory.Scrips.BlueGatherer < info.Cost)
                {
                    return(false);
                }
                break;

            case ShopType.RedGatherer:
                if (Memory.Scrips.RedGatherer < info.Cost)
                {
                    return(false);
                }
                break;
            }

            return(true);
        }
        protected override async Task <bool> Main()
        {
            if (interactTimeout.Elapsed.TotalSeconds > Timeout)
            {
                Logger.Error(Localization.Localization.ExCompanyChestDeposit_Timeout);
                isDone = true;
                return(true);
            }

            if (await freeCompanyChestNpc.TeleportTo())
            {
                return(true);
            }

            // Movement
            if (ExProfileBehavior.Me.Distance(freeCompanyChestNpc.Location) > 3.5)
            {
                StatusText = "Moving to Npc -> " + freeCompanyChestNpc.NpcId;

                await freeCompanyChestNpc.Location.MoveTo(radius : 3.4f, name : " NpcId: " + freeCompanyChestNpc.NpcId);

                return(true);
            }

            if (!interactTimeout.IsRunning)
            {
                interactTimeout.Restart();
            }

            var freeCompanyChest = new FreeCompanyChest();

            // Interact
            if (Core.Target == null && ExProfileBehavior.Me.Distance(freeCompanyChestNpc.Location) <= 3.5)
            {
                await freeCompanyChestNpc.Interact();

                await freeCompanyChest.Refresh(2000);

                return(true);
            }

            if (freeCompanyChest.IsValid)
            {
                if (interactTimeout.Elapsed.TotalSeconds > Timeout)
                {
                    await freeCompanyChest.CloseInstance();

                    return(true);
                }

                if (Consolidate && ConditionParser.FreeItemSlots() > 0)
                {
                    StatusText = "Consolidating...";
                    Logger.Info("Consolidating...");

                    var chestBagSlots =
                        new List <BagSlot>(
                            InventoryManager.GetBagsByInventoryBagId(
                                InventoryBagId.GrandCompany_Page1,
                                InventoryBagId.GrandCompany_Page2,
                                InventoryBagId.GrandCompany_Page3).SelectMany(bag => bag.Select(bagSlot => bagSlot)));

                    var bagGroups =
                        chestBagSlots.Where(bs => bs.IsFilled)
                        .GroupBy(bs => bs.TrueItemId)
                        .Select(
                            g => new { g.Key, BagSlots = g.Where(bs => !bs.IsFullStack(true)).OrderByDescending(bs => bs.Count).ToList() })
                        .ToArray();

                    foreach (var bagGroup in bagGroups.Where(g => g.BagSlots.Count > 1))
                    {
                        Logger.Info("Found item to consolidate -> Id: {0}, BagSlots: {1}", bagGroup.Key, bagGroup.BagSlots.Count);

                        for (var i = 0; i < bagGroup.BagSlots.Count; i++)
                        {
                            var destinationBagSlot = bagGroup.BagSlots[i];
                            for (var j = i + 1; j < bagGroup.BagSlots.Count; j++)
                            {
                                if (destinationBagSlot.IsFullStack())
                                {
                                    break;
                                }

                                var sourceBagSlot = bagGroup.BagSlots[j];

                                if (!sourceBagSlot.IsFilled)
                                {
                                    continue;
                                }

                                if (sourceBagSlot.BagId == destinationBagSlot.BagId)
                                {
                                    MoveItem(sourceBagSlot, destinationBagSlot);
                                }
                                else
                                {
                                    var tempBagSlot =
                                        InventoryManager.GetBagsByInventoryBagId(
                                            InventoryBagId.Bag1,
                                            InventoryBagId.Bag2,
                                            InventoryBagId.Bag3,
                                            InventoryBagId.Bag4)
                                        .Select(bag => bag.FirstOrDefault(bagSlot => !bagSlot.IsFilled))
                                        .FirstOrDefault(bagSlot => bagSlot != null);

                                    if (tempBagSlot == null)
                                    {
                                        Logger.Error("We somehow have a full inventory and cannot consolidate");
                                        return(isDone = true);
                                    }

                                    MoveItem(sourceBagSlot, tempBagSlot);

                                    await Coroutine.Sleep(1500);

                                    MoveItem(tempBagSlot, destinationBagSlot);
                                }

                                await Coroutine.Sleep(1000);
                            }
                        }
                    }
                }

                // Now move items
                foreach (var itemId in Ids)
                {
                    // TODO: Might need unique check, but most likely not, spiritbond should take care of collectable
                    var myBagSlots =
                        InventoryManager.FilledInventoryAndArmory.Where(
                            bs => itemId == bs.RawItemId && bs.SpiritBond < float.Epsilon && !bs.Item.Untradeable)
                        .GroupBy(bs => bs.TrueItemId)
                        .Select(g => new { g.Key, BagSlots = g.OrderBy(bs => bs.Count).ToList() })
                        .ToArray();

                    var chestSlots =
                        new List <BagSlot>(
                            InventoryManager.GetBagsByInventoryBagId(
                                InventoryBagId.GrandCompany_Page1,
                                InventoryBagId.GrandCompany_Page2,
                                InventoryBagId.GrandCompany_Page3)
                            .SelectMany(
                                bag => bag.Where(bagSlot => !bagSlot.IsFilled || (itemId == bagSlot.RawItemId && !bagSlot.IsFullStack(true))))
                            .OrderByDescending(bs => bs.Count));

                    var groups = chestSlots.GroupBy(bs => bs.TrueItemId).Select(g => new { g.Key, BagSlots = g.ToArray() }).ToArray();

                    foreach (var sourceBags in myBagSlots)
                    {
                        var destBags =
                            groups.Where(g => g.Key == sourceBags.Key || g.Key == 0)
                            .SelectMany(g => g.BagSlots)
                            .OrderByDescending(bs => bs.Count)
                            .ToList();

                        foreach (var destinationBagSlot in destBags)
                        {
                            foreach (var sourceBagSlot in sourceBags.BagSlots)
                            {
                                if (destinationBagSlot.IsFullStack())
                                {
                                    break;
                                }

                                if (!sourceBagSlot.IsFilled)
                                {
                                    continue;
                                }

                                MoveItem(sourceBagSlot, destinationBagSlot);

                                await Coroutine.Sleep(1000);
                            }
                        }
                    }

                    await Coroutine.Sleep(1000);
                }

                await freeCompanyChest.CloseInstanceGently();

                return(isDone = true);
            }

            return(true);
        }
        private bool ShouldPurchaseItem(ShopPurchase shopPurchase)
        {
            if (shopPurchase.IgnoreItem)
            {
                return(false);
            }

            var info = Data.ShopItemMap[shopPurchase.ShopItem];

            var itemData = info.ItemData;

            var itemCount = itemData.ItemCount();

            // check inventory count
            if (itemCount >= shopPurchase.MaxCount)
            {
                return(false);
            }

            if (ConditionParser.FreeItemSlots() == 0 && itemCount == 0)
            {
                return(false);
            }

            // check cost
            switch (info.ShopJob)
            {
            case ShopJob.Crafter:
            {
                switch (info.ShopType)
                {
                case ShopType.Yellow50:
                    if (Memory.Scrips.YellowCrafter < info.Cost)
                    {
                        return(false);
                    }

                    break;

                case ShopType.Yellow58:
                    if (Memory.Scrips.YellowCrafter < info.Cost)
                    {
                        return(false);
                    }

                    break;

                case ShopType.Yellow61:
                    if (Memory.Scrips.YellowCrafter < info.Cost)
                    {
                        return(false);
                    }

                    break;

                case ShopType.Yellow70:
                    if (Memory.Scrips.YellowCrafter < info.Cost)
                    {
                        return(false);
                    }

                    break;

                case ShopType.White80:
                    if (Memory.Scrips.WhiteCrafter < info.Cost)
                    {
                        return(false);
                    }

                    break;
                }
            }
            break;

            case ShopJob.Gatherer:
            {
                switch (info.ShopType)
                {
                case ShopType.Yellow50:
                    if (Memory.Scrips.YellowGatherer < info.Cost)
                    {
                        return(false);
                    }

                    break;

                case ShopType.Yellow58:
                    if (Memory.Scrips.YellowGatherer < info.Cost)
                    {
                        return(false);
                    }

                    break;

                case ShopType.Yellow61:
                    if (Memory.Scrips.YellowGatherer < info.Cost)
                    {
                        return(false);
                    }

                    break;

                case ShopType.Yellow70:
                    if (Memory.Scrips.YellowGatherer < info.Cost)
                    {
                        return(false);
                    }

                    break;

                case ShopType.White80:
                    if (Memory.Scrips.WhiteGatherer < info.Cost)
                    {
                        return(false);
                    }

                    break;
                }
            }
            break;
            }
            return(true);
        }