/** * @return void */ private function logDuel($attacker, $target, $winner, $killpoints) { $duel_log_msg = "%s has dueled {$target->name()} and "; if ($attacker !== $winner) { $duel_log_msg .= "lost at " . date("F j, Y, g:i a"); } else { if ($killpoints > 1 || $killpoints < 0) { $duel_log_msg .= "won {$killpoints} killpoints."; } else { $duel_log_msg = ''; } } if ($duel_log_msg !== '') { Event::create((int) "SysMsg", (int) "SysMsg", sprintf($duel_log_msg, $attacker->name(), $target->name())); GameLog::sendLogOfDuel($attacker->name(), $target->name(), $attacker === $winner, $killpoints); } }
/** * Leveling up Function * * @return boolean */ public function levelUp() { $health_to_add = 100; $turns_to_give = 50; $ki_to_give = 50; $stat_value_to_add = 5; $karma_to_give = 1; if ($this->isAdmin()) { // If the character is an admin, do not auto-level return false; } else { // For normal characters, do auto-level // Have to be under the max level and have enough kills. $level_up_possible = $this->level + 1 <= MAX_PLAYER_LEVEL && $this->kills >= $this->killsRequiredForNextLevel(); if ($level_up_possible) { // Perform the level up actions $this->set_health($this->health() + $health_to_add); $this->set_turns($this->turns() + $turns_to_give); $this->set_ki($this->ki() + $ki_to_give); // Must read from VO for these as accessors return modified values $this->setStamina($this->vo->stamina + $stat_value_to_add); $this->setStrength($this->vo->strength + $stat_value_to_add); $this->setSpeed($this->vo->speed + $stat_value_to_add); // no mutator for these yet $this->vo->kills = max(0, $this->kills - $this->killsRequiredForNextLevel()); $this->vo->karma = $this->karma + $karma_to_give; $this->vo->level = $this->level + 1; $this->save(); GameLog::recordLevelUp($this->id()); $account = AccountFactory::findByChar($this); $account->setKarmaTotal($account->getKarmaTotal() + $karma_to_give); AccountFactory::save($account); // Send a level-up message, for those times when auto-levelling happens. send_event($this->id(), $this->id(), "You levelled up! Your strength raised by {$stat_value_to_add}, speed by {$stat_value_to_add}, stamina by {$stat_value_to_add}, Karma by {$karma_to_give}, and your Ki raised {$ki_to_give}! You gained some health and turns, as well! You are now a level {$this->level} ninja! Go kill some stuff."); return true; } else { return false; } } }
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use NinjaWars\core\RouteNotFoundException; use NinjaWars\core\Router; use NinjaWars\core\environment\RequestWrapper; use NinjaWars\core\data\GameLog; use NinjaWars\core\data\Player; use NinjaWars\core\extensions\SessionFactory; // setup our runtime environment require_once LIB_ROOT . 'environment/bootstrap.php'; try { $container = new Container(); $container['current_player'] = function ($c) { return Player::find(SessionFactory::getSession()->get('player_id')); }; $container['session'] = function ($c) { return SessionFactory::getSession(); }; // Update the activity of the page viewer in the database. RequestWrapper::init(); GameLog::updateActivityInfo(RequestWrapper::$request, SessionFactory::getSession()); // get the request information to parse the route $response = Router::route(Request::createFromGlobals(), $container); if ($response instanceof Response) { $response->send(); } else { throw new \RuntimeException('Route returned something other than a Response'); } } catch (RouteNotFoundException $e) { Router::respond404(); }
} if ($attackerHealthRemaining < 1) { // *** DEFENDER KILLS ATTACKER! *** if ($simultaneousKill = $attackerHealthRemaining < 1) { // *** If both died at the same time. *** } else { $victor = $target; $loser = $attacker; } $attacker_died = true; $defenderKillpoints = 1; if ($duel) { // *** if they were dueling when they died *** $duel_log_msg = "{$attacker} has dueled {$target} and lost at " . date("F j, Y, g:i a"); sendMessage("SysMsg", "SysMsg", $duel_log_msg); GameLog::sendLogOfDuel($attacker, $target, 0, $killpoints); // *** Makes a loss in the duel log. *** } $target_player->addKills($defenderKillpoints); // Adds a kill for the defender $attacking_player->death(); if (!$simultaneousKill) { $loot = floor($gold_mod * $attacking_player->gold()); //Loot for defender if he lives. } $target_msg = "You have killed {$attacker} in combat and taken {$loot} gold."; $attacker_msg = "DEATH: You've been killed by {$target} and lost {$loot} gold!"; sendMessage($attacker, $target, $target_msg); sendMessage($target, $attacker, $attacker_msg); } }