Пример #1
0
        // Clone of SoldMultipleItems
        public void BuyMultipleItems(int quantityBought)
        {
            Mod.Log.Debug("BH:BMI entered.");

            //bool isNotStoreOrSalvage = shopIDO.GetItemType() != MechLabDraggableItemType.StorePart &&
            //    shopIDO.GetItemType() != MechLabDraggableItemType.SalvagePart;
            //if (simGameState.InMechLabStore() || !isNotStoreOrSalvage) {
            //    Mod.Logger.Info($"BH:BMI - in the mech lab store, or the part isn't a store part or salvage (is {shopIDO.GetItemType()}). Aborting!");
            //    return;
            //}

            ShopDefItem toBuySDI = shopIDO.shopDefItem;

            // Look for the item in the store inventory
            Shop itemShop = shopIDO.GetShop();
            List <ShopDefItem> activeInventory = itemShop.ActiveInventory;

            Shop.PurchaseType storePT  = toBuySDI.IsInfinite ? Shop.PurchaseType.Normal : Shop.PurchaseType.Special;
            ShopDefItem       storeSDI = activeInventory.Find((ShopDefItem cachedItem) => cachedItem.ID == toBuySDI.ID && cachedItem.Type == shopIDO.shopDefItem.Type);

            if (storeSDI == null)
            {
                Mod.Log.Info("BH:BMI - item not found in store inventory. Aborting!");
                return;
            }

            // Check the price
            int itemPrice = itemShop.GetPrice(storeSDI, storePT, itemShop.ThisShopType);

            Mod.Log.Info($"BH:BMI - itemPrice:{itemPrice} for purchaseType:{storePT}");
            int purchasePrice = itemPrice * quantityBought;

            if (purchasePrice > simGameState.Funds)
            {
                Mod.Log.Info($"BH:BMI - purchasePrice:{purchasePrice} (itemPrice:{itemPrice} x quantity:{quantityBought}) > funds: {simGameState.Funds}. Aborting!");
                return;
            }

            // Check the quantity available
            if (storePT != Shop.PurchaseType.Normal)
            {
                if (storeSDI.Count < quantityBought)
                {
                    Mod.Log.Info($"BH:BMI - store has quantity {storeSDI.Count} in inventory, but {quantityBought} was requested. Aborting!");
                    return;
                }

                storeSDI.Count -= quantityBought;
                if (storeSDI.Count < 1)
                {
                    Mod.Log.Debug($"BH:BMI - Store count below 1, removing!");
                    activeInventory.Remove(storeSDI);
                }
                Mod.Log.Debug($"BH:BMI - Reduced store count by {quantityBought} to {storeSDI.Count}!");
            }

            for (int i = 0; i < quantityBought; i++)
            {
                // Decrement the price
                simGameState.AddFunds(-itemPrice, null, true, true);
                simGameState.AddFromShopDefItem(storeSDI, false, itemPrice, SimGamePurchaseMessage.TransactionType.Purchase);
                Mod.Log.Debug($"BH:BMI - Reducing funds by -{itemPrice} and adding 1 of {storeSDI.ID}");

                if (!toBuySDI.IsInfinite)
                {
                    if (shopIDO.quantity > 1)
                    {
                        shopIDO.ModifyQuantity(-1);
                        Mod.Log.Debug($"BH:BMI - reducing shop inventory by 1 to {shopIDO.quantity}");
                    }
                    else
                    {
                        Mod.Log.Debug($"BH:BMI - shop inventory below 1, removing!");
                        inventoryWidget.RemoveDataItem(shopIDO);
                        if (shopIDO != null)
                        {
                            shopIDO.Pool();
                        }
                        shopIDO = null;
                    }
                }
            }

            inventoryWidget.RefreshInventoryList();

            Mod.Log.Debug("BH:BMI - Updating all money spots");
            shopScreen.UpdateMoneySpot();
            shopScreen.RefreshAllMoneyListings();

            if (toBuySDI.Type == ShopItemType.MechPart)
            {
                shopScreen.OnItemSelected(inventoryWidget.GetSelectedViewItem());
            }

            Mod.Log.Debug("BH:BMI - triggering iron man save");
            Traverse ironManT = Traverse.Create(shopScreen).Field("triggerIronManAutoSave");

            ironManT.SetValue(true);
        }
Пример #2
0
        private static void OnBuyItem(int num)
        {
            var selected = ShopHelper.selectedController;
            var shop_def = selected.shopDefItem;

            Control.LogDebug(DInfo.ShopActions, $"-- {num}x{shop_def.ID}");

            if (selected == null)
            {
                Control.LogError("OnBuyItem null item, cancel");
                return;
            }
            var id = selected.GetId();

            if (!shop_def.IsInfinite && num > selected.quantity)
            {
                Control.LogDebug(DInfo.ShopActions, $"--- {num} > {selected.quantity}, adjucting");
                num = selected.quantity;
            }


            if (BuyItem(shop_def, num))
            {
                Control.LogDebug(DInfo.ShopActions, $"--- refresh shop");
                if (!shop_def.IsInfinite)
                {
                    if (num < selected.quantity)
                    {
                        Control.LogDebug(DInfo.ShopActions, $"---- {num} < {selected.quantity} - reducing");
                        selected.ModifyQuantity(-num);
                    }
                    else
                    {
                        Control.LogDebug(DInfo.ShopActions, $"--- {num} >= {selected.quantity} - removing");
                        selected.quantity = 1;
                        ShopHelper.inventoryWidget.RemoveDataItem(selected);
                        selected.Pool();
                        ShopHelper.selectedController = null;
                    }
                }

                Control.LogDebug(DInfo.ShopActions, $"--- PlayVO");
                if (ShopHelper.canPlayVO)
                {
                    ShopHelper.canPlayVO = false;
                    ShopItemType type = shop_def.Type;
                    string       text;
                    if (type != ShopItemType.Weapon)
                    {
                        if (type == ShopItemType.Mech)
                        {
                            text = "store_newmechs";
                        }
                        else
                        {
                            text = "store_newequipment";
                        }
                    }
                    else
                    {
                        text = "store_newweapons";
                    }
                    if (!string.IsNullOrEmpty(text))
                    {
                        AudioEventManager.PlayAudioEvent("audioeventdef_simgame_vo_barks", text, WwiseManager.GlobalAudioObject, null);
                    }
                    ShopScreen.StartCoroutine(PurchaseVOCooldown(5f));
                }
            }

            ShopHelper.inventoryWidget.RefreshInventoryList();

            ShopScreen.UpdateMoneySpot();
            ShopScreen.RefreshAllMoneyListings();
            if (shop_def.Type == ShopItemType.MechPart)
            {
                ShopScreen.OnItemSelected(ShopHelper.inventoryWidget.GetSelectedViewItem());
            }
            ShopHelper.triggerIronManAutoSave = true;
        }