Пример #1
0
 private static void SellCurrent()
 {
     Logger.Debug($"selling: {numToBuyOrSell}");
     while (numToBuyOrSell > 0)
     {
         numToBuyOrSell--;
         shopScreen.SellCurrentSelection();
     }
     ResetVariables();
 }
Пример #2
0
        public static bool Shop_Screen_ReceiveButtonPress_Prefix(SG_Shop_Screen __instance, string button,
                                                                 InventoryDataObject_SHOP ___selectedController, bool ___isInBuyingState, SimGameState ___simState)
        {
            Mod.Log.Debug($"SG_S_S:RBP entered with button:({button})");

            State.Reset();
            if (button != "Capitalism" || ___selectedController == null)
            {
                return(true);
            }
            else
            {
                int cBillValue = ___selectedController.GetCBillValue();
                if (___isInBuyingState)
                {
                    Mod.Log.Debug($"SG_S_S:RBP - processing a purchase.");

                    if (___simState.InMechLabStore() &&
                        (___selectedController.GetItemType() == MechLabDraggableItemType.StorePart ||
                         ___selectedController.GetItemType() == MechLabDraggableItemType.SalvagePart))
                    {
                        // TODO: Can we handle this better than HBS does?
                        return(false);
                    }
                    Shop shop  = ___selectedController.GetShop();
                    int  price = shop.GetPrice(___selectedController.shopDefItem, Shop.PurchaseType.Normal, shop.ThisShopType);
                    if (___selectedController.quantity > 1 || ___selectedController.shopDefItem.IsInfinite)
                    {
                        State.StoreIsBuying = true;

                        if (___selectedController.shopDefItem.IsInfinite)
                        {
                            ___selectedController.quantity = 99;
                        }
                        BuyHelper buyHelper = new BuyHelper(__instance, ___selectedController, ___simState);

                        int maxCanPurchase = (int)Math.Floor(___simState.Funds / (double)price);
                        Mod.Log.Debug($"SG_S_S:RBP - maxCanPurchase:{maxCanPurchase} = funds:{___simState.Funds} / price:{price}.");
                        int popupQuantity = maxCanPurchase < ___selectedController.quantity ? maxCanPurchase : ___selectedController.quantity;
                        Mod.Log.Debug($"SG_S_S:RBP - maxCanPurchase:{maxCanPurchase} controllerQuantity:{___selectedController.quantity} -> popupQuantity:{popupQuantity}.");

                        SG_Stores_MultiPurchasePopup orCreatePopupModule =
                            LazySingletonBehavior <UIManager> .Instance.GetOrCreatePopupModule <SG_Stores_MultiPurchasePopup>(string.Empty);

                        orCreatePopupModule.SetData(___simState, ___selectedController.shopDefItem,
                                                    ___selectedController.GetName(), popupQuantity, price, buyHelper.BuyMultipleItems);
                    }
                    else
                    {
                        GenericPopupBuilder.Create("Confirm?", Strings.T("Purchase for {0}?", SimGameState.GetCBillString(price)))
                        .AddButton("Cancel")
                        .AddButton("Accept", __instance.BuyCurrentSelection)
                        .CancelOnEscape()
                        .AddFader(LazySingletonBehavior <UIManager> .Instance.UILookAndColorConstants.PopupBackfill)
                        .Render();
                    }
                }
                else
                {
                    Mod.Log.Debug($"SG_S_S:RBP - processing a sale.");
                    State.StoreIsSelling = true;
                    int num = cBillValue;
                    if (___selectedController.quantity > 1)
                    {
                        SG_Stores_MultiPurchasePopup orCreatePopupModule =
                            LazySingletonBehavior <UIManager> .Instance.GetOrCreatePopupModule <SG_Stores_MultiPurchasePopup>(string.Empty);

                        orCreatePopupModule.SetData(___simState, ___selectedController.shopDefItem,
                                                    ___selectedController.GetName(), ___selectedController.quantity, num, __instance.SoldMultipleItems);
                    }
                    else if (num >= ___simState.Constants.Finances.ShopWarnBeforeSellingPriceMinimum)
                    {
                        GenericPopupBuilder.Create("Confirm?", Strings.T("Sell for {0}?", SimGameState.GetCBillString(num)))
                        .AddButton("Cancel")
                        .AddButton("Accept", __instance.SellCurrentSelection)
                        .CancelOnEscape()
                        .AddFader(LazySingletonBehavior <UIManager> .Instance.UILookAndColorConstants.PopupBackfill)
                        .Render();
                    }
                    else
                    {
                        // Sell a single instance
                        __instance.SellCurrentSelection();
                    }
                }
                return(false);
            }
        }