Example #1
0
 public function removeLoan(Loan $loan)
 {
     if ($loan->getOwner() !== $this) {
         return $loan->getOwner()->removeLoan($loan);
     }
     if (!isset($this->loans[$loan->getName()])) {
         return false;
     }
     unset($this->loans[$loan->getName()]);
     return true;
 }
 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.";
     }
 }