private static void FillBag(Bag bag, long bagCapacity, string[] itemsInput)
    {
        for (int i = 0; i < itemsInput.Length; i += 2)
        {
            long bagCurrentCap = 0;
            var  item          = itemsInput[i];
            long amount        = long.Parse(itemsInput[i + 1]);


            if (item.ToLower() == "Gold".ToLower() &&
                CheckBagCapacity(bagCapacity, bagCurrentCap, amount))
            {
                GoldBag gold = new GoldBag();

                AddGold(bag, item, amount, gold);

                bagCurrentCap += amount;
            }

            if (item.Length > 3 &&
                item.ToLower().EndsWith("Gem".ToLower()) &&
                CheckBagCapacity(bagCapacity, bagCurrentCap, amount))
            {
                GemBag gem = new GemBag();

                long goldSum = bag.GoldBag.Sum(a => a.Quantity);
                long gemSum  = bag.GemBag.Sum(a => a.Quantity);

                if (CheckAmountGoldGem(goldSum, gemSum, amount))
                {
                    AddGem(bag, item, amount, gem);

                    bagCurrentCap += amount;
                }
            }

            if (item.Length == 3 &&
                CheckBagCapacity(bagCapacity, bagCurrentCap, amount))
            {
                CashBag cash = new CashBag();

                var goldSum = bag.GoldBag.Sum(a => a.Quantity);
                var gemSum  = bag.GemBag.Sum(a => a.Quantity);
                var cashSum = bag.CashBag.Sum(a => a.Quantity);

                if (CheckAmountGemCash(gemSum, cashSum, amount) &&
                    CheckAmountGoldCash(goldSum, cashSum, amount))
                {
                    AddCash(bag, item, amount, cash);

                    bagCurrentCap += amount;
                }
            }
        }
    }
 private void AddGem(Bag bag, string item, long amount, GemBag gem)
 {
     if (bag.GemBag.All(a => a.Type != item))
     {
         gem.Type     = item;
         gem.Quantity = amount;
         bag.GemBag.Add(gem);
     }
     else
     {
         bag.GemBag.Find(a => a.Type == item).Quantity += amount;
     }
 }
Пример #3
0
        public override void Action(CommandCaller caller, string input, string[] args)
        {
            if (args.Length != 1)
            {
                BagsOfHoldingMod.sendChat("Use with \"reloadOrder\" with a held bag to reload its order, \"reloadOmnibag\" to reload omnibag's content list and \"remakeBags\" to remake all bag orders into the configs.");
                return;
            }
            if ((args[0].Equals("reloadOrder") || args[0].Equals("\"reloadOrder\"")) && caller.Player.HeldItem.modItem != null && caller.Player.HeldItem.modItem is GenericHoldingBag)
            {
                GenericHoldingBag bag = caller.Player.HeldItem.modItem as GenericHoldingBag;
                bag.setupItemList();
                BagsOfHoldingMod.sendChat("Reloaded bag order");
                return;
            }
            if (args[0].Equals("reloadOmnibag") || args[0].Equals("\"reloadOmnibag\""))
            {
                TrueOmniBag.contents2 = null;
                BagPlayer.reloadOmnibag();
                BagsOfHoldingMod.sendChat("Recreated Omnibag order.");
                return;
            }

            if (args[0].Equals("remakeBags") || args[0].Equals("\"remakeBags\""))
            {
                GenericHoldingBag bg = new BaitBag();
                resetBagConfig(bg);
                bg.remakeFromConfig();
                bg = new ChunkBag();
                resetBagConfig(bg);
                bg.remakeFromConfig();
                bg = new CoinBag();
                resetBagConfig(bg);
                bg.remakeFromConfig();
                bg = new CrateBag();
                resetBagConfig(bg);
                bg.remakeFromConfig();
                bg = new DirtBag();
                resetBagConfig(bg);
                bg.remakeFromConfig();
                bg = new DyeMaterialBag();
                resetBagConfig(bg);
                bg.remakeFromConfig();
                bg = new FishBag();
                resetBagConfig(bg);
                bg.remakeFromConfig();
                bg = new GemBag();
                resetBagConfig(bg);
                bg.remakeFromConfig();
                bg = new MushroomBag();
                resetBagConfig(bg);
                bg.remakeFromConfig();
                bg = new OreBag();
                resetBagConfig(bg);
                bg.remakeFromConfig();
                bg = new PlantBag();
                resetBagConfig(bg);
                bg.remakeFromConfig();
                bg = new WoodBag();
                resetBagConfig(bg);
                bg.remakeFromConfig();

                FishingBag.resetContents();
                NatureBag.resetContents();
                OmniBag.resetContents();

                BagsOfHoldingMod.sendChat("Reset all bag orders to the original order list.");
            }
        }