function getCMSFields()
 {
     $fields = parent::getCMSFields();
     $fields->addFieldToTab('Root.Main', new TextField('Name', 'Name of the item on the map'));
     $layers = $this->PointsOfInterestLayer();
     $ids = array();
     foreach ($layers->getIterator() as $layer) {
         array_push($ids, $layer->ID);
     }
     $csv = implode(',', $ids);
     if ($this->ShowGuideMarkers && strlen($csv) > 0) {
         $sql = "ID IN (SELECT DISTINCT  PointOfInterestID from ";
         $sql .= "PointsOfInterestLayer_PointsOfInterest WHERE PointsOfInterestLayerID ";
         $sql .= "IN ({$csv}))";
         $pois = PointOfInterest::get()->where($sql);
         $this->owner->getMapField()->setGuidePoints($pois);
     }
     return $fields;
 }
Ejemplo n.º 2
0
 public function get_player_profile($name = NULL)
 {
     //searching by name, null name = no buenos
     if ($name == NULL) {
         return Response::error('404');
     } else {
         $input_name = urldecode($name);
     }
     //Look up the player, latest to account for deletes with the same name
     $player = Player::where('name', '=', $input_name)->order_by('created_at', 'DESC')->first();
     //no player found, why not search?
     if (!$player) {
         return Response::error('404');
     }
     /*
     if( $player->name == 'Thehink' ) {
         return View::make('player.player_profile_banned')
         ->with('title', 'Player Profile for ' . $player->name)
         ->with(compact('player'));
     }
     */
     //But wait there's more, let's see if we know where that player has been
     $locations = false;
     /*Location::where('db_id','=',$player->db_id)
       ->order_by('created_at','DESC')
       ->first();*/
     //provide the spotters name if a location has been sighted
     if ($locations) {
         $spotter = Player::where('db_id', '=', $locations->spotter_db_id)->only('name');
     } else {
         $spotter = NULL;
     }
     //calculate the players closest POI
     if ($locations) {
         if (!Cache::has('poi_lookup')) {
             Cache::forever('poi_lookup', PointOfInterest::get(array('name', 'coord_x', 'coord_y')));
         }
         $pois = Cache::get('poi_lookup');
         $poi_locs = $pois;
         $poi_lastx = round($locations->coord_x);
         $poi_lasty = round($locations->coord_y);
         $poi_nearest = [999999, 'n/a'];
         foreach ($poi_locs as $pois) {
             $xs = 0;
             $ys = 0;
             $xs = $poi_lastx - intval($pois->coord_x);
             $xs = $xs * $xs;
             $ys = $poi_lasty - intval($pois->coord_y);
             $ys = $ys * $ys;
             $distance = round(sqrt($xs + $ys));
             if ($distance < $poi_nearest[0]) {
                 $poi_nearest = [$distance, $pois->name];
             }
         }
         $nearestloc = $poi_nearest[1];
     } else {
         $nearestloc = NULL;
     }
     //Does the player have an army?
     $army = Army::where('armyId', '=', $player->armyid)->order_by('created_at', 'DESC')->first();
     //escape for output in title
     $playerName = htmlentities($player->name);
     //Player website preferences
     $web_prefs = WebsitePref::where('db_id', '=', $player->db_id)->first();
     if (isset($web_prefs->attributes)) {
         $web_prefs = $web_prefs->attributes;
     }
     if (isset($web_prefs['show_inventory'])) {
         if ($web_prefs['show_inventory'] == 1) {
             $inventory = Inventory::where('db_id', '=', $player->db_id)->order_by('updated_at', 'DESC')->first();
         } else {
             $inventory = null;
         }
     } else {
         $inventory = Inventory::where('db_id', '=', $player->db_id)->order_by('updated_at', 'DESC')->first();
     }
     /*
     			Mappings:
     				local c_RawToRefinedConversion = {
     					["78014"] = "77703", --Copper
     					["78015"] = "77704", --Iron
     					["78016"] = "77705", --Aluminum
     					["78017"] = "77706", --Carbon
     					["78018"] = "77707", --Silicate
     					["78019"] = "77708", --Ceramics
     					["78020"] = "77709", --Methine
     					["78021"] = "77710", --Octine
     					["78022"] = "77711", --Nitrine
     					["82420"] = "82419", --Radine
     					["78023"] = "77713", --Petrochemical
     					["78024"] = "77714", --Biopolymer
     					["78025"] = "77715", --Xenografts
     					["78026"] = "77716", --Toxins
     					["78027"] = "77736", --Regenics
     					["78028"] = "77737", --Anabolics
     				}
     				local c_RefinedToRawConversion = {
     					["77703"] = "78014", --Copper
     					["77704"] = "78015", --Iron
     					["77705"] = "78016", --Aluminum
     					["77706"] = "78017", --Carbon
     					["77707"] = "78018", --Silicate
     					["77708"] = "78019", --Ceramics
     					["77709"] = "78020", --Methine
     					["77710"] = "78021", --Octine
     					["77711"] = "78022", --Nitrine
     					["82419"] = "82420", --Radine
     					["77713"] = "78023", --Petrochemical
     					["77714"] = "78024", --Biopolymer
     					["77715"] = "78025", --Xenografts
     					["77716"] = "78026", --Toxins
     					["77736"] = "78027", --Regenics
     					["77737"] = "78028", --Anabolics
     				}
     				local c_ResourceIds = {
     					["10"] = "Crystite",
     					["80404"] = "AMPS",
     					["30412"] = "CHITS",
     					["30404"] = "SiftedEarth",
     					["77703"] = "Metal",
     					["77704"] = "Metal",
     					["77705"] = "Metal",
     					["77706"] = "Carbon",
     					["77707"] = "Carbon",
     					["77708"] = "Carbon",
     					["77709"] = "Ceramic",
     					["77710"] = "Ceramic",
     					["77711"] = "Ceramic",
     					["77713"] = "Biomaterial",
     					["77714"] = "Biomaterial",
     					["77715"] = "Biomaterial",
     					["77716"] = "Polymer",
     					["77736"] = "Polymer",
     					["77737"] = "Polymer",
     					["82419"] = "Ceramic",
     				}
     */
     if ($inventory) {
         $inventory = unserialize($inventory->inventory);
         if (isset($inventory->{10})) {
             $player_crystite_amount = $inventory->{10};
         } else {
             $player_crystite_amount = 0;
         }
         $cache_key_inventory = $player->db_id . "_inventory";
         if (Cache::Get($cache_key_inventory) != $inventory) {
             $raw_resource_names = array('Copper', 'Iron', 'Aluminum', 'Carbon', 'Silicate', 'Ceramics', 'Methine', 'Octine', 'Nitrine', 'Radine', 'Petrochemical', 'Biopolymer', 'Xenografts', 'Toxins', 'Regenics', 'Anabolics');
             $raw_resource_ids = array(78014, 78015, 78016, 78017, 78018, 78019, 78020, 78021, 78022, 82420, 78023, 78024, 78025, 78026, 78027, 78028);
             $refined_resource_ids = array(77703, 77704, 77705, 77706, 77707, 77708, 77709, 77710, 77711, 82419, 77713, 77714, 77715, 77716, 77736, 77737);
             //Convert inventory to an array
             $inventory = (array) $inventory;
             //Get a cache (or make one) of all the resource item image paths
             if (!Cache::has('resource_asset_paths_dump')) {
                 $resource_ids = array_merge($raw_resource_ids, $refined_resource_ids);
                 $resource_icons = hWebIcon::where(function ($query) use($resource_ids) {
                     $query->where('version', '=', Base_Controller::getVersionDate());
                     $query->where_in('itemTypeId', $resource_ids);
                 })->get(array('itemtypeid', 'asset_path'));
                 Cache::forever('resource_asset_paths_dump', $resource_icons);
             } else {
                 $resource_icons = Cache::Get('resource_asset_paths_dump');
             }
             $player_raw_resources = array();
             $player_refined_resources = array();
             $counter_raw = 0;
             $counter_refined = 0;
             foreach ($inventory as $key => $value) {
                 if (in_array($key, $raw_resource_ids)) {
                     $player_raw_resources[$counter_raw]['name'] = $raw_resource_names[array_search($key, $raw_resource_ids)];
                     $player_raw_resources[$counter_raw]['id'] = $key;
                     $player_raw_resources[$counter_raw]['amt'] = $value;
                     for ($i = 0; $i < count($resource_icons); $i++) {
                         if ($resource_icons[$i]->attributes['itemtypeid'] == $key) {
                             $player_raw_resources[$counter_raw]['asset_path'] = $resource_icons[$i]->attributes['asset_path'];
                         }
                     }
                     $counter_raw++;
                 }
                 if (in_array($key, $refined_resource_ids)) {
                     $player_refined_resources[$counter_refined]['name'] = $raw_resource_names[array_search($key, $refined_resource_ids)];
                     $player_refined_resources[$counter_refined]['id'] = $key;
                     $player_refined_resources[$counter_refined]['amt'] = $value;
                     for ($i = 0; $i < count($resource_icons); $i++) {
                         if ($resource_icons[$i]->attributes['itemtypeid'] == $key) {
                             $player_refined_resources[$counter_refined]['asset_path'] = $resource_icons[$i]->attributes['asset_path'];
                         }
                     }
                     $counter_refined++;
                 }
             }
             //set some cache
             Cache::forever($cache_key_inventory . "_refined_resources", $player_refined_resources);
             Cache::forever($cache_key_inventory . "_raw_resources", $player_raw_resources);
         } else {
             $player_refined_resources = Cache::Get($cache_key_inventory . "_refined_resources");
             $player_raw_resources = Cache::Get($cache_key_inventory . "_raw_resources");
         }
         //set inventory to 1, we don't need everything else exposed on the players page
         $inventory = 1;
     }
     //loadouts
     /*
         Mappings:
             $loadout->Gear[$i] = Currently equipped items array
             $loadout->Gear[$i]->slot_index
             $loadout->Gear[$i]->info->durability->pool
             $loadout->Gear[$i]->info->durability->current
             $loadout->Gear[$i]->info->attribute_modifiers[$k] = array of custom attributes for this item
             $loadout->Gear[$i]->info->quality = The quality of the crafted item
             $loadout->Gear[$i]->info->creator_guid = the creators unique player ID
             $loadout->Gear[$i]->info->item_sdb_id = The root item this was crafted from
     
             $loadout->Weapons[$i] = Currently equiped weapons array
             $loadout->Weapons[$i]->info->durability->pool
             $loadout->Weapons[$i]->info->durability->current
             $loadout->Weapons[$i]->info->attribute_modifiers[$k]
             $loadout->Weapons[$i]->info->quality
             $loadout->Weapons[$i]->info->creator_guid
             $loadout->Weapons[$i]->info->item_sdb_id
             $loadout->Weapons[$i]->allocated_power
             $loadout->Weapons[$i]->slot_index = Weapon slot, 0 is main hand, 1 is alt weapon
     */
     /*
         Attribute modifiers mapping:
             5   = Jet Energy Recharge
             6   = health
             7   = health regen
             12  = Run Speed
             29  = weapon splash radius
             35  = Energy (for jetting)
             37  = Jump Height
             950 = Max durability pool
             951 = Mass (unmodified - YOU MUST take the abs of this to get it to display correctly!)
             952 = Power (unmodified - YOU MUST take the abs of this to get it to display correctly!)
             953 = CPU (unmodified - YOU MUST take the abs of this to get it to display correctly!)
             956 = clip size
             954 = damage per round
             977 = Damage
             978 = Debuff Duration
             1121= Air Sprint
     
             Defaults for weapons are set in the "hstats" table.
     */
     if (isset($web_prefs['show_loadout'])) {
         if ($web_prefs['show_loadout'] == 1) {
             $loadout = Loadout::where('db_id', '=', $player->db_id)->first();
         } else {
             $loadout = null;
         }
     } else {
         $loadout = Loadout::where('db_id', '=', $player->db_id)->first();
     }
     if ($loadout) {
         //Lets play the cache game, where all the stuff is stored locally and the points don't matter!
         $loadout = unserialize($loadout->entry);
         //VERSION 0.6 CHECKING (Array = Good, Object = BAD!)
         if (gettype($loadout) == "object") {
             //This is from version 0.6, we can no longer use this data.
             $loadout = null;
         }
         $cache_key_loadouts = $player->db_id . "_loadouts";
         $loadout_md5 = md5(serialize($loadout));
         if (Cache::Get($cache_key_loadouts . '_md5') != $loadout_md5 && $loadout != null) {
             //Oh I am playing the game, the one that will take me to my end.
             //Make sure this isnt a terrible send
             if (isset($loadout[0]->Gear)) {
                 for ($k = 0; $k < count($loadout); $k++) {
                     if ($loadout[$k]->Chassis_ID == 77733 || $loadout[$k]->Chassis_ID == 82394 || $loadout[$k]->Chassis_ID == 31334) {
                         //ignore the training frame
                     } else {
                         //Break each loadout into its own cache
                         Cache::forever($cache_key_loadouts . '_' . $loadout[$k]->Chassis_ID, $loadout[$k]);
                     }
                 }
                 //Cache the loadout md5 so we can call it again later
                 Cache::forever($cache_key_loadouts . '_md5', $loadout_md5);
                 //and finally set loadout=1 so we know to display equipped gear data
                 $loadout = 1;
             }
         }
     }
     //progress (feat. obama)
     if (isset($web_prefs['show_progress'])) {
         if ($web_prefs['show_progress'] == 1) {
             $progress = Progress::where('db_id', '=', $player->db_id)->order_by('updated_at', 'DESC')->first();
         } else {
             $progress = null;
         }
     } else {
         $progress = Progress::where('db_id', '=', $player->db_id)->order_by('updated_at', 'DESC')->first();
     }
     /*
         Mappings:
             $progress->xp[$i].sdb_id = ItemTypeId for chassis
             $progress->xp[$i].name = battle frame name
             $progress->xp[$i].lifetime_xp = amount of xp gained overall
             $progress->xp[$i].current_xp = currently allocated XP (WARNING: key may not exist!)
             $progress->chassis_id = current chassis ID, use this to identify what battleframe the player was last using
             $progress->unlocks.array() = certificate array for currently equipped chassis
     */
     if ($progress) {
         //Progression graph builder
         $player_progresses_cache_key = $player->db_id . "_graph";
         $player_id = $player->db_id;
         $frame_progress_javascript = array();
         if (Cache::has($player_progresses_cache_key)) {
             //pull from cache
             $frame_progress_javascript = Cache::get($player_progresses_cache_key);
         } else {
             //don't cache the query, that wont help us; cache the javascript output for highcharts instead.
             $player_progresses = DB::query('SELECT DISTINCT(`db_id`),`entry`,unix_timestamp(`updated_at`) AS `updated_at` FROM `progresses` WHERE db_id= ' . $player_id . '  AND `created_at` > DATE_SUB(CURDATE(), INTERVAL 7 DAY) GROUP BY `created_at` ORDER BY `updated_at` ASC LIMIT 7');
             //check chassis_id exists
             if (!empty($player_progresses)) {
                 $check_chassis = unserialize($player_progresses[0]->entry);
             } else {
                 $check_chassis = "";
                 $check_chassis_id = false;
             }
             if (!isset($check_chassis->chassis_id)) {
                 $check_chassis_id = false;
             } else {
                 $check_chassis_id = true;
             }
             if ($player_progresses && $check_chassis_id) {
                 $frame_progress = array();
                 for ($i = 0; $i < count($player_progresses); $i++) {
                     $day_progress = unserialize($player_progresses[$i]->entry);
                     unset($day_progress->unlocks);
                     foreach ($day_progress->xp as $key => $value) {
                         if ($value->sdb_id == 77733 || $value->sdb_id == 82394 || $value->sdb_id == 31334) {
                             //ignore training frame
                         } else {
                             $frame_progress[$value->name][$player_progresses[$i]->updated_at] = $value->lifetime_xp;
                         }
                     }
                 }
                 //Make it json datas
                 $frame_progress_javascript = array();
                 foreach ($frame_progress as $battle_frame_name => $value) {
                     $xp_data_string = "[";
                     foreach ($value as $day => $xp_amt) {
                         $xp_data_string .= "[" . $day * 1000 . "," . $xp_amt . "],";
                         $frame_progress_javascript[$battle_frame_name] = rtrim($xp_data_string, ",") . "]";
                     }
                 }
             } else {
                 $frame_progress_javascript = null;
                 $progress = false;
             }
             //build cache
             Cache::put($player_progresses_cache_key, $frame_progress_javascript, 30);
         }
     } else {
         $frame_progress_javascript = null;
         $progress = false;
     }
     //Frames & Unlocks
     if ($progress) {
         $cache_key_progress = $player->db_id . "_progress";
         $progress = $progress->entry;
         $progress_md5 = md5($progress);
         if (Cache::Get($cache_key_progress . "_md5") != $progress_md5) {
             $progress = unserialize($progress);
             if (isset($progress->xp)) {
                 $battle_frame_id_list = array();
                 for ($i = 0; $i < count($progress->xp); $i++) {
                     $battle_frame_id_list[$i] = $progress->xp[$i]->sdb_id;
                 }
                 $battle_frame_images = hWebIcon::where(function ($query) use($battle_frame_id_list) {
                     $query->where('version', '=', Base_Controller::getVersionDate());
                     $query->where_in('itemTypeId', $battle_frame_id_list);
                 })->get();
                 //set some cache
                 Cache::forever($cache_key_progress . "_battleframe_images", $battle_frame_images);
             } else {
                 $battle_frame_images = null;
             }
             if (isset($web_prefs['show_unlocks'])) {
                 $show_unlocks = $web_prefs['show_unlocks'];
             } else {
                 //Assume show unlocks is 1
                 $show_unlocks = 1;
             }
             if (isset($progress->unlocks) && $show_unlocks == 1) {
                 //VERSION 0.6 CHECK (Array = BAD, Object = Good!)
                 if (gettype($progress->unlocks) == "array") {
                     //NOPE.
                     $battle_frame_unlocks = null;
                 } else {
                     if (gettype($progress->unlocks) == "object") {
                         //Looks like 0.7+ to me!
                         //Create a cache for each frame unlock set
                         foreach ($progress->unlocks as $chassis_id => $cert_array) {
                             if ($chassis_id == 77733 || $chassis_id == 82394 || $chassis_id == 31334) {
                                 //ignore training frame
                             } else {
                                 Cache::forever($cache_key_progress . "_" . $chassis_id, $cert_array);
                             }
                         }
                     }
                 }
             }
             //Cache the progress variable so we can do a quick compare on a later load
             Cache::forever($cache_key_progress, $progress);
             Cache::forever($cache_key_progress . "_md5", $progress_md5);
         } else {
             //Assign cache values to local variable names.
             $battle_frame_images = Cache::Get($cache_key_progress . "_battleframe_images");
             $progress = Cache::Get($cache_key_progress);
         }
     } else {
         $battle_frame_unlocks = null;
     }
     return View::make('player.player_profile')->with('title', 'Player Profile for ' . $playerName)->with(compact('player'))->with(compact('locations'))->with(compact('nearestloc'))->with(compact('army'))->with(compact('inventory'))->with(compact('player_raw_resources'))->with(compact('player_refined_resources'))->with(compact('player_crystite_amount'))->with(compact('loadout'))->with(compact('battle_frame_unlocks'))->with(compact('progress'))->with(compact('frame_progress_javascript'))->with(compact('battle_frame_images'))->with(compact('web_prefs'))->with(compact('spotter'));
 }