public function action_end() { $character = $this->character; $battle = $character->battle; $monster = $battle->monster; if (!$battle->id) { $this->request->redirect('battle'); } if (Battle::can_fight($character) and Battle::can_fight($battle)) { $this->request->redirect('battle'); } $char = new Character($character); if ($battle->hp <= 0) { $view = 'won'; $character->money = $character->money + $battle->monster->money; $character->xp = $character->xp + $monster->xp; $character->save(); } else { $view = 'lost'; } $this->template->content = View::factory('battle/' . $view)->set('money', $monster->money)->set('xp', $monster->xp); $battle->delete(); }