Example #1
0
 public function __construct()
 {
     $this->data = new PlayerVO();
     $this->data->uname = 'User1';
     $this->data->player_id = 1;
     $this->data->level = 20;
     $this->data->health = Player::maxHealthByLevel($this->data->level);
 }
Example #2
0
 /**
  * Revive up to a small max in minor hours, and a stable percent on major hours.
  *
  * Generally the objective is to cause a minor-minor-major pattern:
  * Revive to a fixed minimum number of alive every time (minor or major),
  * and revive beyond the minimum, by percent, every major time
  * to slowly creep towards 100% by healing a percent of whoever is dead
  * For example, if 1,000 out of 1,000 are dead:
  * Minor revive heals to the minimum of 100
  * Minor revive heals none (100 are already alive)
  * Major revive heals 50 from those that are dead (number 5% of all actives)
  * minor revive heals 0 (because at least 100 are already alive)
  * minor revive heals 0 (because at least 100 are already alive)
  * Major revive heals another 50 from those that are dead (if any)
  * etc
  *
  * Defaults
  * sample_use: revive_players(30, 3));
  * @param array('minor_revive_to'=>100, 'major_revive_percent'=>5,
  *      'just_testing'=>false)
  * @return mixed 
  */
 public function revivePlayers($set = array())
 {
     $minor_revive_to = isset($set['minor_revive_to']) ? $set['minor_revive_to'] : 100;
     $major_revive_percent = isset($set['major_revive_percent']) ? $set['major_revive_percent'] : 5;
     $major_hour = 3;
     // Hour for the major revive.
     $pc_data = self::pcsActiveDeadAlive();
     assert($pc_data['active'] > 0);
     // If none dead, return false.
     if ($pc_data['dead'] < 1) {
         return array(0, 0);
     }
     $game_hour = self::gameHour();
     assert(is_numeric($game_hour));
     // Calculate the revive amount
     if (!($game_hour % $major_hour == 0)) {
         // minor
         if ($pc_data['alive'] >= $minor_revive_to) {
             return array(0, $pc_data['dead']);
             // No revives called for yet!
         } else {
             // else revive minor_revive_to - total_alive.
             $revive_amount = (int) floor($minor_revive_to - $pc_data['alive']);
         }
     } else {
         // major.
         $percent_int = (int) floor($major_revive_percent / 100 * $pc_data['active']);
         // Use the max of either pcs dead, or revives requested
         $revive_amount = min($percent_int, $pc_data['dead']);
     }
     assert(isset($revive_amount));
     $maximum_heal = Player::maxHealthByLevel(MAX_PLAYER_LEVEL);
     $revived = self::performNecromancy($revive_amount, $maximum_heal, $game_hour);
     return [$revived, $pc_data['dead']];
 }
function smarty_function_health_percent($p_params)
{
    $health = $p_params['health'];
    $level = $p_params['level'];
    return min(100, round($health / Player::maxHealthByLevel($level) * 100));
}
 public function testFreeResurrectWithChi()
 {
     $this->char->death();
     $this->char->setClass('dragon');
     // dragon class has chi skill
     $this->char->save();
     $cont = new ShrineController();
     $response = $cont->resurrect($this->m_dependencies);
     $final_char = Player::find($this->char->id());
     $reflection = new \ReflectionProperty(get_class($response), 'data');
     $reflection->setAccessible(true);
     $response_data = $reflection->getValue($response);
     $this->assertTrue(in_array('result-resurrect', $response_data['pageParts']));
     $this->assertGreaterThan(floor(Player::maxHealthByLevel($this->char->level) / 2), $final_char->health);
 }
/**
 * Smarty plugin to wrap player health calculation
 *
 * @param int $level Level of pc
 * @return int
 */
function smarty_function_max_health_by_level($level)
{
    return Player::maxHealthByLevel((int) $level);
}
Example #6
0
 /**
  * Create the Response to render
  *
  * @param Array $p_parts Array that gets bound to view
  * @param Player $p_player The player requesting the action
  * @param boolean $p_renderMonks Flag to render links to actions
  * @return Response
  */
 private function render($p_parts = [], $p_player = null, $p_renderMonks = true)
 {
     $p_parts['max_level'] = MAX_PLAYER_LEVEL;
     // For non-logged in loop through stats.
     $p_parts['max_hp'] = Player::maxHealthByLevel(MAX_PLAYER_LEVEL + 1);
     $p_parts['class_change_cost'] = self::CLASS_CHANGE_COST;
     $p_parts['player'] = $p_player;
     if (!isset($p_parts['pageParts'])) {
         $p_parts['pageParts'] = [];
     }
     if (!$p_player) {
         array_unshift($p_parts['pageParts'], 'access-denied');
     } else {
         if ($p_renderMonks) {
             if (empty($this->dimMakReqs($p_player, self::DIM_MAK_COST))) {
                 $p_parts['pageParts'][] = 'reminder-dim-mak';
             }
             if (empty($this->classChangeReqs($p_player, self::CLASS_CHANGE_COST))) {
                 $p_parts['pageParts'][] = 'reminder-class-change';
             }
         }
         $p_parts['pageParts'][] = 'reminder-class';
         $p_parts['pageParts'][] = 'reminder-level';
         if ($p_player->level < MAX_PLAYER_LEVEL) {
             $p_parts['required_kills'] = $p_player->killsRequiredForNextLevel();
             $p_parts['pageParts'][] = 'reminder-next-level';
         }
     }
     $p_parts['pageParts'][] = 'scroll';
     if (!isset($p_parts['error'])) {
         $p_parts['error'] = null;
     }
     return new StreamedViewResponse('Dojo', 'dojo.tpl', $p_parts, ['quickstat' => 'player']);
 }
Example #7
0
 public function fireBoltBaseDamage(Player $pc)
 {
     return (int) floor(Player::maxHealthByLevel($pc->level) / 3);
 }
Example #8
0
 /**
  * Cacluates the starting health for a player when resurrected based on player state
  *
  * @param p_player Player The player object to interrogate
  * @return int
  */
 private function calculateResurrectionHP($p_player)
 {
     $skillController = new Skill();
     // Instantiate Skill interrogator
     // chi triples base health after res
     if ($skillController->hasSkill('Chi', $p_player->name())) {
         $hpMultiplier = 3;
     } else {
         $hpMultiplier = 1;
     }
     $maxHP = Player::maxHealthByLevel($p_player->level) * $hpMultiplier;
     return min($maxHP, $p_player->getMaxHealth());
 }