示例#1
0
 public function add_troop($unit_id, $quantity, $combat_id = -1, $update_score = false)
 {
     $troop = new Troop();
     $troop->hydrate(['user_id' => $this->user_id, 'unit_id' => $unit_id, 'quantity' => $quantity, 'combat_id' => $combat_id]);
     $troop->save();
     if ($update_score) {
         // on met à jour le score du joueur
         $unit = self::get_unit_infos()[$unit_id];
         $score = round(($unit['price'] + $unit['life'] + $unit['damage']) / 20);
         $user = new User($this->user_id);
         $user->increase_score($score);
     }
 }