Пример #1
0
 public function tick()
 {
     if ($this->state) {
         // playing
         $this->ticks--;
         $this->broadcastTime();
         if ($this->ticks === 0) {
             if (($cnt = count($this->players)) > 1) {
                 $this->broadcast("The match has ended. There are no winners.");
                 $this->broadcastSpecs("The {$cnt} survivors will share the award of 20 coins.");
                 $mean = 20 / $cnt;
                 foreach ($this->players as $player) {
                     $get = round($mean * Settings::coinsFactor($player->getSession()), 2);
                     $player->getSession()->setCoins($coins = $player->getSession()->getCoins() + $get);
                     $player->getSession()->tell("You are awarded with {$get} coins. You now have {$coins} coins.");
                     $player->addDraw();
                 }
                 $this->game->getDefaultChatChannel()->broadcast("Match in {$this} ended with a draw with {$cnt} survivors!");
             }
             $this->reset();
             return;
         }
         foreach ($this->players as $player) {
             if ($player->getSession()->getPlayer()->getFloorY() < $this->config->lowestY - 1) {
                 $this->kick($player, "you fell out of the arena");
                 $this->broadcast("{$player->getSession()} has fallen!");
                 $player->addLoss();
             }
             if (count($this->players) === 0) {
                 $this->reset();
                 return;
                 // not sure what will happen. ConcurrentModificationException?
             }
         }
     } elseif (count($this->players) > 1) {
         $this->ticks--;
         $this->broadcastTime();
         if ($this->ticks === 0) {
             $this->broadcast("The match now starts!");
             $this->startMatch();
         }
     }
 }
Пример #2
0
 public function update()
 {
     $this->game->getMain()->getMySQLi()->query('INSERT INTO spleef(uid,wins,losses,draws,current_streak)VALUES(%d,%d,%d,%d,%d)ON DUPLICATE KEY UPDATE wins=VALUES(wins),losses=VALUES(losses),draws=VALUES(draws),current_streak=VALUES(current_streak);', MysqlConnection::RAW, (int) $this->session->getUID(), (int) $this->getWins(), (int) $this->getLosses(), (int) $this->getDraws(), 0);
 }