/**
  * @param Player $player
  * @return $this
  * @throws InsufficientBidCoinsException
  * @throws UnsuccessfulBidException
  */
 public function acceptBid(Player $player)
 {
     if ($player->debitBidCoins($this->bid_cost)) {
         $this->winner_id = $player->id;
         $this->value += self::AUCTION_BID_VALUE;
         if (!$this->pending() && !$this->onHoliday()) {
             $this->bid_status = self::AUCTION_BID_TIMMING;
             $this->setTimer();
         } else {
             $this->bid_status = self::AUCTION_BID_PENDING;
         }
         if ($this->save()) {
             $this->save();
             return $this;
         } else {
             throw new UnsuccessfulBidException($player, $this);
         }
     } else {
         throw new InsufficientBidCoinsException();
     }
 }
Esempio n. 2
0
 /**
  * @param Player $player
  * @return $this
  * @throws InsufficientBidCoinsException
  */
 private function processBid(Player $player)
 {
     if ($player->hasEnoughBidCoins($this->bid_cost)) {
         if ($player->debitBidCoins($this->bid_cost)) {
             $this->winner_id = $player->id;
             $this->value += self::AUCTION_VALUE_INCREMENT;
             $this->save();
             if ($this->status == self::AUCTION_BIDDING || $this->status == self::AUCTION_CHECKING) {
                 $this->resetTimer();
             }
             // record bid in history
             Bid::record($player, $this);
         }
         return $this;
     } else {
         throw new InsufficientBidCoinsException();
     }
 }