/// <summary> /// Pays the selected loan by the specified amount. /// If the player pays it off the win condition is triggered. /// </summary> public void payDebt() { try{ float amount = float.Parse(paymentAmount.text, CultureInfo.InvariantCulture.NumberFormat); int loanNum = int.Parse(paymentId.text); Debug.Log($"{creditorId}: receiving ${amount} payment on loan ${loanNum}"); Loan selectedLoan = myLoans.First(l => l.ID == loanNum); ValidLoan thisLoan = validLoans.First(m => m.loanType == selectedLoan.type); // Don't pay off another lender's loans here... Done. -ZM if (thisLoan == null) { dialogText.text = "I think you are looking for the other guy."; audioS.PlayOneShot(failureSound, Settings.volume); return; } if (amount < 0.0f || selectedLoan.Equals(null)) { dialogText.text = thisLoan.errorPaidText; audioS.PlayOneShot(failureSound, Settings.volume); return; } if (StateManager.cashOnHand < amount) // amount is more than money on hand { dialogText.text = thisLoan.failurePaidText; audioS.PlayOneShot(failureSound, Settings.volume); return; } else if (selectedLoan.total <= amount) // amount is more than the debt { StateManager.cashOnHand -= selectedLoan.total; StateManager.cashOnHand += selectedLoan.collateral; // get back extra amount paid on secured loans StateManager.loanList.Remove(selectedLoan); checkWin(); updateFields(); dialogText.text = thisLoan.successPaidText; audioS.PlayOneShot(paymentSound, Settings.volume); return; } else // none of the above // reduce debt and money by amount { selectedLoan.total -= amount; StateManager.cashOnHand -= amount; updateFields(); dialogText.text = thisLoan.successPaidText; audioS.PlayOneShot(paymentSound, Settings.volume); return; } } catch (Exception e) { dialogText.text = "Wait... What happened? Where am I?"; Debug.Log($"Exception found: {e}"); } }
/// <summary> /// Attempts to add a loan of the specified amount of money, /// failure conditions included and will affect the dialog /// </summary> public void addDebt(ValidLoan associatedLoanData) { try{ float amount = float.Parse(associatedLoanData.addLoanInput.text, CultureInfo.InvariantCulture.NumberFormat); LoanType loanType = associatedLoanData.loanType; if (amount < 0.0f) { dialogText.text = associatedLoanData.errorText; audioS.PlayOneShot(failureSound, Settings.volume); Debug.Log($"{creditorId}: You're supposed to borrow from *me*!"); return; } if ( (threatLevel < threatThreshold) && ((maxLoanAmount * StateManager.maxLoanAdjuster) >= (loanTotal + amount)) && // secured loans bypass this a bit... (numberOfLoans < loanHardCap) ) { float modifiedInterest = associatedLoanData.interestRate * associatedLoanData.collateralRateReduction * StateManager.rateAdjuster; // collateralRateReduction should always be 1 for unsecured loans float collateral = (float)Math.Round(associatedLoanData.collateralAmountPercent * amount, 2); // collateralAmountPercent should always be 0 for unsecured loans float modifiedAmount = (float)Math.Round(collateral + amount, 2); Loan newLoan = new Loan(StateManager.nextID, modifiedAmount, modifiedInterest, loanType, collateral, creditorId); Debug.Log($"{creditorId}: adding ${modifiedAmount} loan with a {collateral} deposit @ {modifiedInterest*100}%"); StateManager.loanList.Add(newLoan); StateManager.cashOnHand += amount; StateManager.nextID++; initialDebtType.addLoanInput.text = ""; updateFields(); dialogText.text = associatedLoanData.successText; audioS.PlayOneShot(paymentSound, Settings.volume * debtIsLoud); return; } Debug.Log($"{creditorId}: Bad dog, no biscuit!"); dialogText.text = associatedLoanData.failureText; audioS.PlayOneShot(failureSound, Settings.volume); return; } catch (Exception e) { dialogText.text = "Oh, hi, who are you? And why do you smell like motor oil?"; Debug.Log($"Exception found: {e}"); } }