public function addLoan_faction($type) { if (is_array($loan = $this->main->getLoan($type))) { /** @var Entity $this */ // I don't know why I need to do this. $loanObj = new Loan($this->getMain()->getXEconLoanService(), $loan["amount"], $this, time() + $loan["horizon"] * 3600, $loan["interest"]); $loanObj->setName($type . " " . $loanObj->getName()); $cnt = 1; foreach ($this->loans as $acc) { if (strstr($acc->getName(), " ", true) === $type) { $cnt++; } } if ($cnt > $loan["maximum"]) { return "Maximum limit for loan {$type} exceeded"; } $liabilities = 0; foreach ($this->getLoans() as $l) { $liabilities += $l; } if (max(0, -$this->getAccount(self::BANK)) + $liabilities + $loan["amount"] > $this->getMain()->getMaxLiability()) { return "Maximum liability exceeded"; } $this->getLoans()[$loanObj->getName()] = $loanObj; return true; } else { return "Unknown loan type. Use /f loan types to see a list of loan types in this server."; } }
public function addLoanRaw(Loan $loan) { $this->loans[$loan->getName()] = $loan; }