Ejemplo n.º 1
0
 /**
  * Change the kills amount of a char, and levels them up when necessary.
  * @return int
  */
 private function changeKills($amount)
 {
     $amount = (int) $amount;
     GameLog::updateLevellingLog($this->id(), $amount);
     if ($amount !== 0) {
         // Ignore changes that amount to zero.
         if ($amount > 0) {
             // when adding kills, check if levelling occurs
             $this->levelUp();
         }
         query("UPDATE players SET kills = kills + CASE WHEN kills + :amount1 < 0 THEN kills*(-1) ELSE :amount2 END WHERE player_id = :player_id", [':amount1' => [$amount, PDO::PARAM_INT], ':amount2' => [$amount, PDO::PARAM_INT], ':player_id' => $this->id()]);
     }
     return $this->vo->kills = query_item("SELECT kills FROM players WHERE player_id = :player_id", [':player_id' => [$this->id(), PDO::PARAM_INT]]);
 }