Example #1
0
 public static function all()
 {
     $data = ClanFactory::allData();
     $clans = array();
     foreach ($data as $clan_info) {
         $clans[] = self::fleshOutFromData($clan_info, new Clan());
     }
     return $clans;
 }
Example #2
0
 /**
  * Display the combat/action events and mark them as read when displayed.
  */
 public function index()
 {
     $char = new Player(self_char_id());
     $events = $this->getEvents($char->id(), 300);
     // Check for clan to use it in the nav tabs.
     $has_clan = (bool) ClanFactory::clanOfMember($char);
     $this->readEvents($char->id());
     // mark events as viewed.
     $template = 'events.tpl';
     $title = 'Events';
     $parts = ['events' => $events, 'has_clan' => $has_clan, 'char' => $char];
     $options = ['quickstat' => 'player'];
     return ['title' => $title, 'template' => $template, 'parts' => $parts, 'options' => $options];
 }
 public function viewClan()
 {
     $ninja = new Player(self_char_id());
     $page = in('page', 1, 'non_negative_int');
     $limit = 25;
     $offset = non_negative_int(($page - 1) * $limit);
     $type = 1;
     // Clan chat or normal messages.
     $message_count = Message::countByReceiver($ninja, $type);
     // To count all the messages
     Message::markAsRead($ninja, $type);
     // mark messages as read for next viewing.
     $parts = array_merge($this->configure(), ['messages' => Message::findByReceiver($ninja, $type, $limit, $offset), 'message_count' => $message_count, 'pages' => ceil($message_count / $limit), 'current_page' => $page, 'current_tab' => 'clan', 'has_clan' => (bool) ClanFactory::clanOfMember($ninja)]);
     return $this->render($parts, 'Clan Messages');
 }
Example #4
0
 public function index()
 {
     $target = $player = first_value(in('ninja'), in('player'), in('find'), in('target'));
     $target_id = first_value(in('target_id'), in('player_id'), get_char_id($target));
     // Find target_id if possible.
     $target_player_obj = Player::find($target_id);
     $viewed_name_for_title = null;
     if ($target_player_obj !== null) {
         $viewed_name_for_title = $target_player_obj->name();
     }
     if ($target_player_obj === null) {
         $template = 'no-player.tpl';
         $parts = array();
     } else {
         $player_info = $target_player_obj->as_array();
         // Pull the info out of the object.
         if (!$player_info) {
             $template = 'no-player.tpl';
             $parts = array();
         } else {
             $viewing_player_obj = Player::find(self_char_id());
             $self = self_char_id() && self_char_id() == $player_info['player_id'];
             // Record whether this is a self-viewing.
             if ($viewing_player_obj !== null) {
                 $char_info = $viewing_player_obj->dataWithClan();
                 $char_id = $viewing_player_obj->id();
                 $username = $viewing_player_obj->name();
             } else {
                 $char_info = [];
             }
             $player = $target = $player_info['uname'];
             // reset the target and target_id vars.
             $target_id = $player_info['player_id'];
             // Get the player's kills for this date.
             $kills_today = query_item('select sum(killpoints) from levelling_log where _player_id = :player_id and killsdate = CURRENT_DATE and killpoints > 0', array(':player_id' => $target_id));
             $viewers_clan = $viewing_player_obj !== null ? ClanFactory::clanOfMember($viewing_player_obj) : null;
             // Attack Legal section
             $params = array('required_turns' => 0, 'ignores_stealth' => true);
             // 0 for unstealth.
             $attack_error = 'You must become a ninja first.';
             $attack_allowed = false;
             if (null !== $viewing_player_obj) {
                 $AttackLegal = new AttackLegal($viewing_player_obj, $target_player_obj, $params);
                 $attack_allowed = $AttackLegal->check(false);
                 $attack_error = $AttackLegal->getError();
             }
             $sel_rank_spot = "SELECT rank_id FROM rankings WHERE player_id = :char_id limit 1";
             $rank_spot = query_item($sel_rank_spot, array(':char_id' => $player_info['player_id']));
             // Display the player info.
             $status_list = get_status_list($player);
             $gurl = $gravatar_url = $target_player_obj->avatarUrl();
             if ($viewing_player_obj !== null && !$attack_error && !$self) {
                 // They're not dead or otherwise unattackable.
                 // Attack or Duel
                 $skillDAO = new SkillDAO();
                 $is_admin = false;
                 if ($viewing_player_obj) {
                     $is_admin = $viewing_player_obj->isAdmin();
                 }
                 if (!$is_admin) {
                     $combat_skills = $skillDAO->getSkillsByTypeAndClass($viewing_player_obj->_class_id, 'combat', $viewing_player_obj->level);
                     $targeted_skills = $skillDAO->getSkillsByTypeAndClass($viewing_player_obj->_class_id, 'targeted', $viewing_player_obj->level);
                 } else {
                     $combat_skills = $skillDAO->all('combat');
                     $targeted_skills = $skillDAO->all('targeted');
                 }
                 // Pull the items and some necessary data about them.
                 $items = inventory_counts($char_id);
                 $valid_items = rco($items);
                 // row count
             }
             // End of the there-was-no-attack-error section
             $set_bounty_section = '';
             $communication_section = '';
             $player_clan_section = '';
             $clan = ClanFactory::clanOfMember($player_info['player_id']);
             $same_clan = false;
             // Player clan and clan members
             if ($clan) {
                 $viewer_clan = $viewing_player_obj ? ClanFactory::clanOfMember($viewing_player_obj) : null;
                 $clan_id = $clan->getID();
                 $clan_name = $clan->getName();
                 if ($viewer_clan) {
                     $same_clan = $clan->getID() == $viewer_clan->getID();
                     $display_clan_options = $viewing_player_obj && !$self && $same_clan && $viewing_player_obj->isClanLeader();
                 } else {
                     $same_clan = $display_clan_options = false;
                 }
             }
             // Send the info to the template.
             $template = 'player.tpl';
             $parts = get_certain_vars(get_defined_vars(), array('char_info', 'viewing_player_obj', 'target_player_obj', 'combat_skills', 'targeted_skills', 'player_info', 'self', 'rank_spot', 'kills_today', 'gravatar_url', 'status_list', 'clan', 'items'));
         }
     }
     return ['template' => $template, 'title' => 'Ninja' . ($viewed_name_for_title ? ": {$viewed_name_for_title}" : ' Profile'), 'parts' => $parts, 'options' => ['quickstat' => 'player']];
 }
Example #5
0
 /**
  * Generates a viewspec for rendering pages
  *
  * @param Array $p_parts Name-Value pairs of values to send to the view
  * @return Array A viewspec for rendering
  */
 private function render($p_parts)
 {
     if (!isset($p_parts['pageParts'])) {
         $p_parts['pageParts'] = [];
     }
     if (!isset($p_parts['error'])) {
         $p_parts['error'] = null;
     }
     if (!isset($p_parts['action_message'])) {
         $p_parts['action_message'] = null;
     }
     $p_parts['player'] = Player::find(self_char_id());
     $p_parts['myClan'] = $p_parts['player'] ? ClanFactory::clanOfMember($p_parts['player']) : null;
     $p_parts['clan_creator_min_level'] = self::CLAN_CREATOR_MIN_LEVEL;
     return ['template' => 'clan.tpl', 'title' => $p_parts['title'], 'parts' => $p_parts, 'options' => ['body_classes' => 'clan', 'quickstat' => true]];
 }
Example #6
0
 /**
  * Check whether the player is the leader of their clan.
  * @return boolean
  */
 public function isClanLeader()
 {
     return ($clan = ClanFactory::clanOfMember($this->id())) && $this->id() == $clan->getLeaderID();
 }
Example #7
0
 function testGetClanObjectNumericRating()
 {
     $this->markTestIncomplete('Clan rating is not yet implemented');
     $player1 = new Player($this->char_id);
     $clan = ClanFactory::find($this->clan_id);
     $this->assertTrue($clan->addMember($player1, $player1));
     $this->assertTrue($clan->addMember(new Player($this->char_id_2), $player1));
     $this->assertTrue($clan->rating());
 }
Example #8
0
 /**
  * Display the default stats page
  */
 public function index()
 {
     $char = new Player(self_char_id());
     $parts = ['char' => $char, 'clan' => ClanFactory::clanOfMember($char), 'status_list' => get_status_list(), 'rank_display' => $this->getRank($char->id()), 'profile_max_length' => self::PROFILE_MAX_LENGTH, 'error' => in('error'), 'successMessage' => '', 'profile_changed' => (bool) in('profile_changed'), 'changed' => (bool) in('changed')];
     return $this->render($parts);
 }