Skip to content

Commit

Permalink
Merge pull request #550 from Zemill/develop
Browse files Browse the repository at this point in the history
Heroes Profile v0.5.0
  • Loading branch information
Zemill authored Nov 30, 2023
2 parents 88dd558 + afa495c commit f5e68a0
Show file tree
Hide file tree
Showing 96 changed files with 1,765 additions and 1,066 deletions.
3 changes: 3 additions & 0 deletions app/Http/Controllers/Auth/BattleNetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ public function handleProviderCallback(Request $request)
public function logout()
{
Auth::logout();
session()->forget('patreonSubscriberSiteFlair');
session()->forget('patreonSubscriberAdFree');


return redirect('/');
}
Expand Down
142 changes: 141 additions & 1 deletion app/Http/Controllers/Global/GlobalLeaderboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,28 @@
namespace App\Http\Controllers\Global;

use App\Models\HeroesDataTalent;
use App\Models\MasterGamesPlayedData;
use App\Models\MasterGamesPlayedDataGroups;
use App\Models\Leaderboard;
use App\Models\MasterMMRDataQM;
use App\Models\MasterMMRDataUD;
use App\Models\MasterMMRDataHL;
use App\Models\MasterMMRDataSL;
use App\Models\MasterMMRDataTL;
use App\Models\MasterMMRDataAR;
use App\Rules\GameTypeInputValidation;
use App\Rules\HeroInputByIDValidation;
use App\Rules\RegionInputValidation;
use App\Rules\RoleInputValidation;
use App\Rules\SeasonInputValidation;
use App\Rules\StackSizeInputValidation;
use App\Models\BattlenetAccount;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;




class GlobalLeaderboardController extends GlobalsInputValidationController
{
public function show(Request $request)
Expand Down Expand Up @@ -104,7 +116,14 @@ public function getLeaderboardData(Request $request)
$talentData = HeroesDataTalent::all();
$talentData = $talentData->keyBy('talent_id');

$data = $data->map(function ($item) use ($heroData, $rankTiers, $talentData, $type, $typeNumber) {

$patreonAccounts = BattlenetAccount::has('patreonAccount')->get();

$data = $data->map(function ($item) use ($heroData, $rankTiers, $talentData, $type, $typeNumber, $patreonAccounts) {
$patreonAccount = $patreonAccounts->where("blizz_id", $item->blizz_id)->where("region", $item->region);

$item->patreon = is_null($patreonAccount) || empty($patreonAccount) || count($patreonAccount) == 0 ? false : true;
$item->hp_owner = ($item->blizz_id == 67280 && $item->region == 1) ? true : false;
$item->mmr = round(1800 + 40 * $item->conservative_rating);
$item->win_rate = round($item->win_rate, 2);
$item->rating = round($item->rating, 2);
Expand All @@ -130,4 +149,125 @@ public function getLeaderboardData(Request $request)

return $data;
}

public function getLeaderboardRating(Request $request)
{
//return response()->json($request->all());

$validationRules = [
'season' => ['required', new SeasonInputValidation()],
'game_type' => ['required', new GameTypeInputValidation()],
'type' => 'required|in:player,hero,role',
'groupsize' => ['required', new StackSizeInputValidation()],
'hero' => ['sometimes', 'nullable', new HeroInputByIDValidation()],
'region' => 'required|integer',
'role' => ['sometimes', 'nullable', new RoleInputValidation()],
'blizz_id' => 'required|integer',
];

$validator = Validator::make($request->all(), $validationRules);

if ($validator->fails()) {
return [
'data' => $request->all(),
'status' => 'failure to validate inputs',
];
}
$blizz_id = $request["blizz_id"];
$hero = $request['hero'];
$role = $this->getMMRTypeValue($request['role']);

$gameType = $this->getGameTypeFilterValues($request['game_type']);
$season = $request['season'];
$region = $request['region'];

$type = $request['type'];
$typeNumber = 0;

if ($type == 'player') {
$typeNumber = $this->getMMRTypeValue($request['type']);
} elseif ($type == 'hero') {
$typeNumber = $hero;
} elseif ($type == 'role') {
$typeNumber = $role;
}

$groupsize = -1;
if ($request['groupsize'] == 'Solo') {
$groupsize = 0;
} elseif ($request['groupsize'] == 'Duo') {
$groupsize = 2;
} elseif ($request['groupsize'] == '3 Players') {
$groupsize = 3;
} elseif ($request['groupsize'] == '4 Players') {
$groupsize = 4;
} elseif ($request['groupsize'] == '5 Players') {
$groupsize = 5;
} elseif ($request['groupsize'] == 'All') {
$groupsize = 0;
}

$table = MasterGamesPlayedData::class;
if($request['groupsize'] != 'All'){
$table = MasterGamesPlayedDataGroups::class;
}

$playerData = $table::select("win_leaderboard", "loss_leaderboard", "games_played_leaderboard")
->where("type_value", $typeNumber)
->where("stack_size", $groupsize)
->where("season", $this->globalDataService->getDefaultSeason())
->where("game_type", $gameType)
->where("blizz_id", $blizz_id)
->where("region", $region)
->first();

if(!$playerData || empty($playerData)){
return ["rating" => 0, "games_played" => 0];
}


$weeksSinceStart = $this->globalDataService->getWeeksSinceSeasonStart();
$maxGamesPlayed = $table::select("games_played_leaderboard")
->where("type_value", $typeNumber)
->where("stack_size", $groupsize)
->where("season", $this->globalDataService->getDefaultSeason())
->where("game_type", $gameType)
->orderByDesc("games_played_leaderboard")
->limit($weeksSinceStart)
->get()
->avg("games_played_leaderboard");


$gamesPlayedForFormula = $playerData->games_played_leaderboard;

if($maxGamesPlayed < $playerData->games_played_leaderboard){
$gamesPlayedForFormula = $maxGamesPlayed;
}

$mmrTable = "";

if($gameType == 1){
$mmrTable = MasterMMRDataQM::class;
}else if($gameType == 2){
$mmrTable = MasterMMRDataUD::class;
}else if($gameType == 3){
$mmrTable = MasterMMRDataHL::class;
}else if($gameType == 4){
$mmrTable = MasterMMRDataTL::class;
}else if($gameType == 5){
$mmrTable = MasterMMRDataSL::class;
}else if($gameType == 6){
$mmrTable = MasterMMRDataAR::class;
}
$playerMMR = $mmrTable::select("conservative_rating")
->where("type_value", $typeNumber)
->where("game_type", $gameType)
->where("blizz_id", $blizz_id)
->where("region", $region)
->first();

$winRate = $playerData->games_played_leaderboard > 0 ? ($playerData->win_leaderboard / $playerData->games_played_leaderboard) * 100 : 0;
$rating = (50 + ($winRate - 50) * ($gamesPlayedForFormula / $maxGamesPlayed)) + ($playerMMR->conservative_rating / 10);
return ["rating" => round($rating, 2), "games_played" => $playerData->games_played_leaderboard];
}
}
10 changes: 9 additions & 1 deletion app/Http/Controllers/Player/FriendFoeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Http\Controllers\Controller;
use App\Models\GameType;
use App\Models\Map;
use App\Models\BattlenetAccount;
use App\Models\SeasonDate;
use App\Rules\GameMapInputValidation;
use App\Rules\GameTypeInputValidation;
Expand Down Expand Up @@ -57,6 +58,7 @@ public function show(Request $request, $battletag, $blizz_id, $region)
'game_map' => $game_map,
'gametypedefault' => $this->globalDataService->getGameTypeDefault(),
'filters' => $this->globalDataService->getFilterData(),
'patreon' => $this->globalDataService->checkIfSiteFlair($blizz_id, $region),
]);

}
Expand Down Expand Up @@ -203,7 +205,10 @@ public function getFriendFoeData(Request $request)
});
});

$finalResults = $checkedData->map(function ($data, $blizz_id) use ($heroDataByID, $region) {
$patreonAccounts = BattlenetAccount::has('patreonAccount')->get();


$finalResults = $checkedData->map(function ($data, $blizz_id) use ($heroDataByID, $region, $patreonAccounts) {
$totalWins = $data->where('winner', 1)->sum('total');
$totalLosses = $data->where('winner', 0)->sum('total');

Expand All @@ -219,11 +224,14 @@ public function getFriendFoeData(Request $request)
];
})->sortByDesc('total_games_played')->first();
$gamesPlayed = $totalWins + $totalLosses;
$patreonAccount = $patreonAccounts->where("blizz_id", $blizz_id)->where("region", $region);

return [
'blizz_id' => $blizz_id,
'hero' => $heroData['hero']['name'],
'region' => $region,
'hp_owner' => ($blizz_id == 67280 && $region = 1) ? true : false,
'patreon' => is_null($patreonAccount) || empty($patreonAccount) || count($patreonAccount) == 0 ? false : true,
'battletag' => explode('#', $data->first()->battletag)[0],
'total_wins' => $totalWins,
'total_losses' => $totalLosses,
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Controllers/Player/PlayerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function show(Request $request, $battletag, $blizz_id, $region)

$season = $request['season'];
$game_type = $request['game_type'];

return view('Player.player')->with([
'settingHero' => $heroUserSettings,
'battletag' => $battletag,
Expand All @@ -74,6 +74,7 @@ public function show(Request $request, $battletag, $blizz_id, $region)
'season' => $season,
'game_type' => $game_type,
'filters' => $this->globalDataService->getFilterData(),
'patreon' => $this->globalDataService->checkIfSiteFlair($blizz_id, $region),
]);
}

Expand Down
2 changes: 2 additions & 0 deletions app/Http/Controllers/Player/PlayerHeroesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public function showAll(Request $request, $battletag, $blizz_id, $region)
'blizz_id' => $blizz_id,
'region' => $region,
'filters' => $this->globalDataService->getFilterData(),
'patreon' => $this->globalDataService->checkIfSiteFlair($blizz_id, $region),
]);

}
Expand Down Expand Up @@ -69,6 +70,7 @@ public function showSingle(Request $request, $battletag, $blizz_id, $region, $he
'heroObject' => $this->globalDataService->getHeroModel($hero),
'filters' => $this->globalDataService->getFilterData(),
'regions' => $this->globalDataService->getRegionIDtoString(),
'patreon' => $this->globalDataService->checkIfSiteFlair($blizz_id, $region),
]);
}
}
1 change: 1 addition & 0 deletions app/Http/Controllers/Player/PlayerMMRController.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public function show(Request $request, $battletag, $blizz_id, $region)
'region' => $region,
'filters' => $this->globalDataService->getFilterData(),
'gametypedefault' => $this->globalDataService->getGameTypeDefault(),
'patreon' => $this->globalDataService->checkIfSiteFlair($blizz_id, $region),
]);
}

Expand Down
2 changes: 2 additions & 0 deletions app/Http/Controllers/Player/PlayerMapsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public function showAll(Request $request, $battletag, $blizz_id, $region)
'account_level' => $account_level,
'region' => $region,
'filters' => $this->globalDataService->getFilterData(),
'patreon' => $this->globalDataService->checkIfSiteFlair($blizz_id, $region),
]);
}

Expand Down Expand Up @@ -72,6 +73,7 @@ public function showSingle(Request $request, $battletag, $blizz_id, $region, $ma
'mapobject' => $mapobject,
'filters' => $this->globalDataService->getFilterData(),
'regions' => $this->globalDataService->getRegionIDtoString(),
'patreon' => $this->globalDataService->checkIfSiteFlair($blizz_id, $region),
]);
}
}
2 changes: 1 addition & 1 deletion app/Http/Controllers/Player/PlayerMatchHistory.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function show(Request $request, $battletag, $blizz_id, $region)
'region' => $region,
'filters' => $this->globalDataService->getFilterData(),
'gametypedefault' => $this->globalDataService->getGameTypeDefault(),
//'talentimages' => $this->globalDataService->getPreloadTalentImageUrls(),
'patreon' => $this->globalDataService->checkIfSiteFlair($blizz_id, $region),
]);
}

Expand Down
1 change: 1 addition & 0 deletions app/Http/Controllers/Player/PlayerMatchupsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public function show(Request $request, $battletag, $blizz_id, $region)
'blizz_id' => $blizz_id,
'region' => $region,
'filters' => $this->globalDataService->getFilterData(),
'patreon' => $this->globalDataService->checkIfSiteFlair($blizz_id, $region),
]);
}

Expand Down
2 changes: 2 additions & 0 deletions app/Http/Controllers/Player/PlayerRolesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public function showAll(Request $request, $battletag, $blizz_id, $region)
'account_level' => $account_level,
'region' => $region,
'filters' => $this->globalDataService->getFilterData(),
'patreon' => $this->globalDataService->checkIfSiteFlair($blizz_id, $region),
]);
}

Expand Down Expand Up @@ -62,6 +63,7 @@ public function showSingle(Request $request, $battletag, $blizz_id, $region, $ro
'role' => $role,
'filters' => $this->globalDataService->getFilterData(),
'regions' => $this->globalDataService->getRegionIDtoString(),
'patreon' => $this->globalDataService->checkIfSiteFlair($blizz_id, $region),
]);
}
}
1 change: 1 addition & 0 deletions app/Http/Controllers/Player/PlayerTalentsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public function show(Request $request, $battletag, $blizz_id, $region)
'region' => $region,
'filters' => $this->globalDataService->getFilterData(),
'talentimages' => $this->globalDataService->getPreloadTalentImageUrls(),
'patreon' => $this->globalDataService->checkIfSiteFlair($blizz_id, $region),
]);
}

Expand Down
20 changes: 1 addition & 19 deletions app/Http/Controllers/SingleMatchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,8 @@ public function getData(Request $request)
'winner' => $row->winner,
'team' => $row->team,
'party' => ! $this->esport ? $row->party : null,
'match_award' => ! $this->esport ? Awards::find($row->match_award) : null,
'hero' => $heroData[$row->hero],
'patreon_subscriber' => ! $this->esport ? $this->isPatreonSubscriber($row->battletag, $blizz_id, $region) : null,
'patreon_subscriber' => ! $this->esport ? $this->globalDataService->checkIfSiteFlair($blizz_id, $region) : null,
'match_award' => ! $this->esport ? Award::where('award_id', $row->match_award)->first() : null,
'hero_level' => $containsAccount ? null : $hero_level_calculated,
'avg_hero_level' => $containsAccount ? null : $avg_hero_level,
Expand Down Expand Up @@ -403,23 +402,6 @@ public function getData(Request $request)
return $groupedData[0];
}

private function isPatreonSubscriber($battletag, $blizz_id, $region)
{
$data = BattlenetAccount::where('blizz_id', $blizz_id)->where('region', $region)->first();

if (empty($data)) {
return false;
}

$data = $data->patreonAccount;

if ($data->site_flair == 1) {
return true;
}

return false;
}

private function updatePartyData(&$playerArray)
{
$partyArray = [];
Expand Down
19 changes: 13 additions & 6 deletions app/Http/Middleware/CheckIfPatreonSupporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Symfony\Component\HttpFoundation\Response;
use App\Models\PatreonAccount;

class CheckIfPatreonSupporter
{
Expand All @@ -16,15 +17,21 @@ class CheckIfPatreonSupporter
*/
public function handle(Request $request, Closure $next): Response
{
if (Auth::check()) {

if (Auth::check()) {
$user = Auth::user();
if ($user->site_flair == 1) {
session(['patreonSubscriberSiteFlair' => true]);
}
$patreonUser = PatreonAccount::where("battlenet_accounts_id", $user->battlenet_accounts_id)->first();

if($patreonUser){
if ($patreonUser->site_flair == 1) {
session(['patreonSubscriberSiteFlair' => true]);
}

if ($user->ad_free == 1) {
session(['patreonSubscriberAdFree' => true]);
if ($patreonUser->ad_free == 1) {
session(['patreonSubscriberAdFree' => true]);
}
}

}

return $next($request);
Expand Down
Loading

0 comments on commit f5e68a0

Please sign in to comment.