/** * Gets the player vehicle stats * * @return array */ public function getVehicleStats() { // Generate URI for request $uri = sprintf($this->uris[$this->game]['vehicles'], $this->game, $this->personaID); // Send request $results = $this->sendRequest($uri)['data']; // Create vehicles array $vehicles = new Collection(); foreach ($results['mainVehicleStats'] as $vehicle) { $vehicles->push(['slug' => $vehicle['slug'], 'code' => $vehicle['code'], 'category' => $vehicle['category'], 'kills' => $vehicle['kills'], 'score' => array_key_exists('score', $vehicle) ? $vehicle['score'] : null, 'timeEquipped' => $vehicle['timeIn'], 'serviceStars' => $vehicle['serviceStars'], 'kpm' => MainHelper::divide($vehicle['kills'], MainHelper::divide($vehicle['timeIn'], 60))]); } return $vehicles; }
/** * Parse the battlelog weapons list * * @param array $weapons * * @return $this */ public function parse($weapons) { if (!array_key_exists($this->game, $this->weapons)) { throw new HttpException(500, sprintf('The game "%s" is not supported.', $this->game)); } foreach ($weapons as $weapon) { $category = str_replace(' ', '_', strtolower(trim($weapon['category']))); if (!in_array($category, $this->allowedCategories[$this->game]) || !array_key_exists($category, $this->weapons[$this->game]) || !array_key_exists($weapon['slug'], $this->weapons[$this->game][$category])) { continue; } $status = ['DPS' => false, 'HKP' => false, 'KPM' => false]; $_weaponDPS = $this->weapons[$this->game][$category][$weapon['slug']]; $DPSDiff = 1 - MainHelper::divide($_weaponDPS['max'] - $weapon['dps'], $_weaponDPS['max']); // Convert first letter of each word to an uppercase $weapon['category'] = ucwords($weapon['category']); // Check if the weapon has been used with a damage mod if ($DPSDiff > 1.5 && $weapon['kills'] >= $this->triggers['Kills']) { $status['DPS'] = true; } // Check if the weapon has a high headshot to kill ratio in percentages if ($weapon['hskp'] >= $this->triggers['HKP'] && $weapon['kills'] >= $this->triggers['Kills']) { $status['HKP'] = true; } // Check if the weapon has a high kill per minute if ($weapon['kpm'] >= $this->triggers['KPM'] && $weapon['kills'] >= $this->triggers['Kills']) { $status['KPM'] = true; } // If either DPS, KPM, or HKP get triggered add the weapon to the triggered weapons list if ($status['DPS'] || $status['KPM'] || $status['HKP']) { $this->triggered[] = $weapon + ['triggered' => $status]; } } return $this; }
/** * Fetches records targeted on player to calculate the target reputation * * @return mixed */ public function target() { // Retrieve the punish records $punishments = $this->player->recordsOn()->where('command_type', 9)->get(); foreach ($punishments as $punishment) { $days = Carbon::now()->diffInDays($punishment->record_time); if ($days < 50) { $this->targetReputation -= 20 * MainHelper::divide(50 - $days, 50); } } // Retrieve the forgive records $forgives = $this->player->recordsOn()->where('command_type', 10)->get(); foreach ($forgives as $forgive) { $days = Carbon::now()->diffInDays($forgive->record_time); if ($days < 50) { $this->targetReputation += 20 * MainHelper::divide(50 - $days, 50); } } // Retrieve the rest $records = Record::select(DB::raw('command_type, command_action, COUNT(record_id) AS command_count'))->where('target_id', $this->player->PlayerID)->whereRaw('target_name != source_name')->groupBy('command_type')->groupBy('command_action')->get(); foreach ($records as $record) { $command = sprintf('%u|%u', $record->command_type, $record->command_action); foreach ($this->weights as $weight) { if ($command == $weight['command_typeaction']) { $this->targetReputation += $weight['target_weight'] * $record->command_count; break; } } } return $this; }