コード例 #1
0
 /// <summary>
 /// Loan step 1 - Show an input popup to ask for the loan amount.
 /// </summary>
 private void AskLoanAmount(BankLoanCapacity capacity)
 {
     InformationManager.ShowTextInquiry(new TextInquiryData(
                                            titleText: $"How much do you want, Sir?",
                                            text: $"Your current balance is <b>{BankAccount.Gold}</b><img src=\"Icons\\Coin@2x\">.\n" +
                                            $"You maximum loan capacity is <b>{capacity.MaxAmount}</b><img src=\"Icons\\Coin@2x\">.",
                                            isAffirmativeOptionShown: true,
                                            isNegativeOptionShown: true,
                                            affirmativeText: "Continue",
                                            negativeText: "Cancel",
                                            textCondition: new Func <string, bool>((string amountInput) =>
     {
         return(int.TryParse(amountInput, out int amount) &&
                capacity.MinAmount <= amount &&
                capacity.MaxAmount >= amount);
     }),
                                            affirmativeAction: new Action <string>((string amountInput) =>
     {
         if (int.TryParse(amountInput, out int amount) && capacity.MinAmount <= amount && capacity.MaxAmount >= amount)
         {
             this.AskLoanDuration(capacity, amount);
         }
         else
         {
             InformationManager.DisplayMessage(new InformationMessage($"Your loan simulation has been aborted."));
         }
     }),
                                            negativeAction: new Action(() => { })
                                            ), true);
 }
コード例 #2
0
        /// <summary>
        /// Loan step 3 - Show an input popup to ask for the loan delay.
        /// </summary>
        private void AskLoanDelay(BankLoanCapacity capacity, int amount, int duration)
        {
            InformationManager.ShowMultiSelectionInquiry(new MultiSelectionInquiryData(
                                                             titleText: $"How long would you like to wait before repaying?",
                                                             descriptionText: $"Be reasonable.",
                                                             isExitShown: true,
                                                             maxSelectableOptionCount: 1,
                                                             affirmativeText: "Continue",
                                                             negativeText: "Back",
                                                             inquiryElements: new List <InquiryElement>()
            {
                new InquiryElement("5_days", "5 days", new ImageIdentifier(ImageIdentifierType.Null)),
                new InquiryElement("10_days", "10 days", new ImageIdentifier(ImageIdentifierType.Null)),
                new InquiryElement("15_days", "15 days", new ImageIdentifier(ImageIdentifierType.Null)),
                new InquiryElement("20_days", "20 days", new ImageIdentifier(ImageIdentifierType.Null))
            },
                                                             affirmativeAction: new Action <List <InquiryElement> >((List <InquiryElement> elements) =>
            {
                var selected = elements.First();

                switch (selected.Identifier as string)
                {
                case "5_days":
                    this.AskLoanConfirmation(capacity, amount, duration, 5);
                    break;

                case "10_days":
                    this.AskLoanConfirmation(capacity, amount, duration, 10);
                    break;

                case "15_days":
                    this.AskLoanConfirmation(capacity, amount, duration, 15);
                    break;

                case "20_days":
                    this.AskLoanConfirmation(capacity, amount, duration, 20);
                    break;

                default:
                    InformationManager.DisplayMessage(new InformationMessage($"Your loan simulation has been aborted."));
                    break;
                }
            }),
                                                             negativeAction: new Action <List <InquiryElement> >((List <InquiryElement> elements) =>
            {
                this.AskLoanDuration(capacity, amount);
            })
                                                             ));
        }
コード例 #3
0
        /// <summary>
        /// Loan step 2 - Show an input popup to ask for the loan duration.
        /// </summary>
        private void AskLoanDuration(BankLoanCapacity capacity, int amount)
        {
            InformationManager.ShowMultiSelectionInquiry(new MultiSelectionInquiryData(
                                                             titleText: $"How long do you want to repay?",
                                                             descriptionText: $"Please chose carefuly, we don't like bad payers and I assure you wouldn't like to be one.",
                                                             isExitShown: true,
                                                             maxSelectableOptionCount: 1,
                                                             affirmativeText: "Continue",
                                                             negativeText: "Back",
                                                             inquiryElements: new List <InquiryElement>()
            {
                new InquiryElement("10_days", "10 days", new ImageIdentifier(ImageIdentifierType.Null)),
                new InquiryElement("20_days", "20 days", new ImageIdentifier(ImageIdentifierType.Null)),
                new InquiryElement("40_days", "40 days", new ImageIdentifier(ImageIdentifierType.Null)),
                new InquiryElement("80_days", "80 days", new ImageIdentifier(ImageIdentifierType.Null))
            },
                                                             affirmativeAction: new Action <List <InquiryElement> >((List <InquiryElement> elements) =>
            {
                var selected = elements.First();

                switch (selected.Identifier as string)
                {
                case "10_days":
                    this.AskLoanDelay(capacity, amount, 10);
                    break;

                case "20_days":
                    this.AskLoanDelay(capacity, amount, 20);
                    break;

                case "40_days":
                    this.AskLoanDelay(capacity, amount, 40);
                    break;

                case "80_days":
                    this.AskLoanDelay(capacity, amount, 80);
                    break;

                default:
                    InformationManager.DisplayMessage(new InformationMessage($"Your loan simulation has been aborted."));
                    break;
                }
            }),
                                                             negativeAction: new Action <List <InquiryElement> >((List <InquiryElement> elements) =>
            {
                this.AskLoanAmount(capacity);
            })
                                                             ));
        }
コード例 #4
0
        /// <summary>
        /// Loan step 4 - Show a text popup to ask for the loan confirmation and process it.
        /// </summary>
        private void AskLoanConfirmation(BankLoanCapacity capacity, int amount, int duration, int delay)
        {
            var simulation = new BankLoanSimulation(Hero.MainHero, amount, delay, duration);

            InformationManager.ShowInquiry(new InquiryData(
                                               titleText: "Are you sure, their is no comming back with us ?",
                                               text: $"You will begin to pay <b>{simulation.Payments * -1}</b><img src=\"Icons\\Coin@2x\"> a day from your account for <b>{simulation.Duration} days</b> in <b>{simulation.Delay} days</b>. " +
                                               $"Borrowing from us {amount}<img src=\"Icons\\Coin@2x\"> will cost you <b>{simulation.Cost}</b><img src=\"Icons\\Coin@2x\"> of bank interests for a total of <b>{simulation.Total}</b><img src=\"Icons\\Coin@2x\"> repaid.\n",
                                               isAffirmativeOptionShown: true,
                                               isNegativeOptionShown: true,
                                               affirmativeText: "Agree",
                                               negativeText: "Refuse",
                                               affirmativeAction: new Action(() =>
            {
                BankAccount.Loans.Add(new BankLoan(simulation));
            }),
                                               negativeAction: new Action(() =>
            {
                this.AskLoanDelay(capacity, amount, duration);
            })
                                               ));
        }
コード例 #5
0
        public override void RegisterEvents()
        {
            // Daily hook to process payments
            CampaignEvents.DailyTickClanEvent.AddNonSerializedListener(this, new Action <Clan>((Clan clan) =>
            {
                if (clan.StringId != Hero.MainHero.Clan.StringId)
                {
                    return;
                }

                var(purse, account, payment) = BankAccount.ApplyDailyTransactions();

                if (purse > 0)
                {
                    InformationManager.DisplayMessage(
                        new InformationMessage($"Iron Bank: <b>{purse:+#;-#;0}</b><img src=\"Icons\\Coin@2x\"> from interests.")
                        );
                }

                if (account > 0)
                {
                    InformationManager.DisplayMessage(
                        new InformationMessage($"Iron Bank: <b>{account:+#;-#;0}</b><img src=\"Icons\\Coin@2x\"> to your account from interests.")
                        );
                }

                if (payment < 0)
                {
                    InformationManager.DisplayMessage(
                        new InformationMessage($"Iron Bank: <b>{payment:+#;-#;0}</b><img src=\"Icons\\Coin@2x\"> to your account from your current loans.")
                        );
                }
            }));

            CampaignEvents.OnSessionLaunchedEvent.AddNonSerializedListener(this, new Action <CampaignGameStarter>((CampaignGameStarter campaignGameStarter) =>
            {
                // Bank option in town menu
                campaignGameStarter.AddGameMenuOption(
                    menuId : TOWN_MENU_ID,
                    optionId : BANK_MENU_ID,
                    optionText : "{=town_bank}Go to the bank",
                    index : BANK_MENU_INDEX,
                    isLeave : false,
                    isRepeatable : false,
                    condition : delegate(MenuCallbackArgs args)
                {
                    args.optionLeaveType = GameMenuOption.LeaveType.Submenu;
                    return(true);
                },
                    consequence : delegate(MenuCallbackArgs args)
                {
                    args.MenuContext.SwitchToMenu(BANK_MENU_ID);
                    return;
                }
                    );

                // Inside the bank menu
                campaignGameStarter.AddGameMenu(
                    menuId : BANK_MENU_ID,
                    menuText : "{=bank_account}{IronBank_Menu_Bank}",
                    menuFlags : GameMenu.MenuFlags.none,
                    overlay : TaleWorlds.CampaignSystem.Overlay.GameOverlays.MenuOverlayType.None,
                    initDelegate : delegate(MenuCallbackArgs args)
                {
                    this.UpdateBankMenuText();
                }
                    );

                // Deposit option
                campaignGameStarter.AddGameMenuOption(
                    menuId : BANK_MENU_ID,
                    optionId : BANK_MENU_DEPOSIT_ID,
                    optionText : "{=bank_account_deposit}Make a deposit",
                    index : BANK_MENU_DEPOSIT_INDEX,
                    isLeave : false,
                    isRepeatable : false,
                    condition : delegate(MenuCallbackArgs args)
                {
                    args.optionLeaveType = GameMenuOption.LeaveType.Trade;
                    args.IsEnabled       = Hero.MainHero.Gold >= 0;
                    return(true);
                },
                    consequence : delegate(MenuCallbackArgs args)
                {
                    this.AskDeposit();
                }
                    );

                // Withdraw option
                campaignGameStarter.AddGameMenuOption(
                    menuId : BANK_MENU_ID,
                    optionId : BANK_MENU_WITHDRAW_ID,
                    optionText : "{=bank_account_withdraw}Make a withdraw",
                    index : BANK_MENU_WITHDRAW_INDEX,
                    isLeave : false,
                    isRepeatable : false,
                    condition : delegate(MenuCallbackArgs args)
                {
                    args.optionLeaveType = GameMenuOption.LeaveType.Trade;
                    args.IsEnabled       = Hero.MainHero.Gold >= 0;
                    return(true);
                },
                    consequence : delegate(MenuCallbackArgs args)
                {
                    this.AskWithdraw();
                }
                    );

                // Loan option
                campaignGameStarter.AddGameMenuOption(
                    menuId : BANK_MENU_ID,
                    optionId : BANK_MENU_TAKE_LOAN_ID,
                    optionText : "{=bank_account_take_loan}Take a loan",
                    index : BANK_MENU_TAKE_LOAN_INDEX,
                    isLeave : false,
                    isRepeatable : false,
                    condition : delegate(MenuCallbackArgs args)
                {
                    var capacity         = new BankLoanCapacity(Hero.MainHero);
                    args.optionLeaveType = GameMenuOption.LeaveType.Trade;
                    args.IsEnabled       = Hero.MainHero.Gold >= 0 && capacity.MinAmount > 0;
                    return(true);
                },
                    consequence : delegate(MenuCallbackArgs args)
                {
                    var capacity = new BankLoanCapacity(Hero.MainHero);
                    this.AskLoanAmount(capacity);
                }
                    );

                // Current loans
                campaignGameStarter.AddGameMenuOption(
                    menuId : BANK_MENU_ID,
                    optionId : BANK_MENU_SEE_LOANS_ID,
                    optionText : "{=bank_account_see_loans}See my loans",
                    index : BANK_MENU_SEE_LOANs_INDEX,
                    isLeave : false,
                    isRepeatable : false,
                    condition : delegate(MenuCallbackArgs args)
                {
                    args.optionLeaveType = GameMenuOption.LeaveType.Trade;
                    args.IsEnabled       = BankAccount.Loans.Count > 0;
                    return(true);
                },
                    consequence : delegate(MenuCallbackArgs args)
                {
                    this.ShowLoans();
                }
                    );

                // Reinvestment ratio setting
                campaignGameStarter.AddGameMenuOption(
                    menuId : BANK_MENU_ID,
                    optionId : BANK_MENU_REINVESTMENT_ID,
                    optionText : "{=bank_account_reinvestment}Set my reinvestment ratio",
                    index : BANK_MENU_REINVESTMENT_INDEX,
                    isLeave : false,
                    isRepeatable : false,
                    condition : delegate(MenuCallbackArgs args)
                {
                    args.optionLeaveType = GameMenuOption.LeaveType.Trade;
                    args.IsEnabled       = Hero.MainHero.Gold >= 0;
                    return(true);
                },
                    consequence : delegate(MenuCallbackArgs args)
                {
                    this.AskReinvestmentRatio();
                }
                    );

                // Leave option
                campaignGameStarter.AddGameMenuOption(
                    menuId : BANK_MENU_ID,
                    optionId : BANK_MENU_LEAVE_ID,
                    optionText : "{=bank_account_leave}Return to the city",
                    index : BANK_MENU_LEAVE_INDEX,
                    isLeave : true,
                    isRepeatable : false,
                    condition : delegate(MenuCallbackArgs args)
                {
                    args.optionLeaveType = GameMenuOption.LeaveType.Leave;
                    return(true);
                },
                    consequence : delegate(MenuCallbackArgs args)
                {
                    args.MenuContext.SwitchToMenu(TOWN_MENU_ID);
                    return;
                }
                    );
            }));
        }