Skip to content

Commit

Permalink
Add Mega Walls guild statistics
Browse files Browse the repository at this point in the history
Final K/D is based on the combined value of finalKills and final_kills (#11 (comment))
  • Loading branch information
MaxKorlaar committed Jul 5, 2020
1 parent c934f89 commit 6b25b11
Show file tree
Hide file tree
Showing 9 changed files with 290 additions and 17 deletions.
3 changes: 2 additions & 1 deletion .idea/inspectionProfiles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

139 changes: 139 additions & 0 deletions app/Http/Controllers/Guild/MegaWallsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
<?php
/*
* Copyright (c) 2020 Max Korlaar
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions, a visible attribution to the original author(s)
* of the software available to the public, and the following disclaimer
* in the documentation and/or other materials provided with the distribution.
*
* Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

namespace App\Http\Controllers\Guild;

use App\Exceptions\HypixelFetchException;
use App\Utilities\HypixelAPI;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\View\Factory;
use Illuminate\Http\Request;
use Illuminate\View\View;
use Plancke\HypixelPHP\classes\gameType\GameTypes;
use Plancke\HypixelPHP\exceptions\HypixelPHPException;
use Plancke\HypixelPHP\responses\guild\Guild;
use Plancke\HypixelPHP\responses\player\GameStats;
use Plancke\HypixelPHP\responses\player\Player;

/**
* Class MegaWallsController
*
* @package App\Http\Controllers\Guild
*/
class MegaWallsController extends MemberController {
/**
* @param Request $request
* @param string $nameOrId
*
* @return array[]|Application|Factory|View
* @throws HypixelFetchException
* @throws HypixelPHPException
*/
public function getMegaWallsStatistics(Request $request, string $nameOrId) {
$HypixelAPI = new HypixelAPI();

if (HypixelAPI::isValidMongoId($nameOrId)) {
$guild = $HypixelAPI->getGuildById($nameOrId);
} else {
$guild = $HypixelAPI->getGuildByName($nameOrId);
}

if ($guild instanceof Guild) {
$memberList = $this->getMegaWallsMemberList($guild);

if ($request->wantsJson()) {
return $memberList;
}

return view('guild.games.megawalls', [
'guild' => $guild,
'urls' => [
'get_members' => route('guild.games.megawalls.json', [$guild->getID()])
]
] + $memberList);
}

throw new HypixelFetchException('An unknown error has occurred while trying to fetch this Guild or its members from Hypixel');
}

/**
* @param Guild $guild
*
* @return array
* @throws HypixelPHPException
*/
private function getMegaWallsMemberList(Guild $guild): array {
return $this->getMemberList($guild, static function (Player $player) {
/** @var GameStats $stats */
$stats = $player->getStats()->getGameFromID(GameTypes::WALLS3);

$kills = $stats->getInt('kills');
$deaths = $stats->getInt('deaths');

if ($deaths > 0) {
$kd = round($kills / $deaths, 2);
} else {
$kd = 'N/A';
}

$wins = $stats->getInt('wins');
$losses = $stats->getInt('losses');
if (($wins + $losses) > 0) {
$winsPercentage = round(($wins / ($wins + $losses)) * 100, 1);
} else {
$winsPercentage = 0;
}

$finalKills = $stats->getInt('finalKills') + $stats->getInt('final_kills');
$finalDeaths = $stats->getInt('finalDeaths') + $stats->getInt('final_deaths');

if ($finalDeaths > 0) {
$finalKd = round($finalKills / $finalDeaths, 2);
} else {
$finalKd = 'N/A';
}

return [
'wins' => $wins,
'losses' => $losses,
'kills' => $kills,
'deaths' => $deaths,
'assists' => $stats->getInt('assists'),
'wins_percentage' => $winsPercentage,
'kd' => $kd,
'kills_final' => $finalKills,
'deaths_final' => $finalDeaths,
'kd_final' => $finalKd
];
});
}
}
3 changes: 2 additions & 1 deletion resources/js/guild.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import SkyWarsTable from "./guild/SkyWarsTable";
import MembersTable from "./guild/MembersTable";
import BedWarsTable from "./guild/BedWarsTable";
import TNTGamesTable from "./guild/TNTGamesTable";
import MegaWallsTable from "./guild/MegaWallsTable";

const axios = require('axios').default;

Expand All @@ -47,7 +48,7 @@ Vue.use(VueLazyload, {
// noinspection ObjectAllocationIgnored
new Vue({
el: '#guild-members-app',
components: {SkyWarsTable, MembersTable, BedWarsTable, TNTGamesTable},
components: {SkyWarsTable, MembersTable, BedWarsTable, TNTGamesTable, MegaWallsTable},
data: {
members: [],
meta: {
Expand Down
117 changes: 117 additions & 0 deletions resources/js/guild/MegaWallsTable.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<!--
- Copyright (c) 2020 Max Korlaar
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are met:
-
- * Redistributions of source code must retain the above copyright notice, this
- list of conditions and the following disclaimer.
-
- * Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions, a visible attribution to the original author(s)
- of the software available to the public, and the following disclaimer
- in the documentation and/or other materials provided with the distribution.
-
- * Neither the name of the copyright holder nor the names of its
- contributors may be used to endorse or promote products derived from
- this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->

<template>
<div class="table-container">
<sortable-table :data="members" class="guild-members compact bordered">
<template v-slot:head>
<tr>
<sortable-header name="formatted_name">
Username
</sortable-header>
<sortable-header name="wins">Wins</sortable-header>
<sortable-header name="kills">Kills</sortable-header>
<sortable-header name="assists">Assists</sortable-header>
<sortable-header name="kd">K/D</sortable-header>
<sortable-header name="wins_percentage">Games won</sortable-header>
<sortable-header name="kills_final">Final kills</sortable-header>
<sortable-header name="kd_final">Final K/D</sortable-header>
</tr>
</template>
<template v-slot="data">
<td>
<img alt="" v-lazy="data.item.skin_url">
<div class="loader" v-if="data.item.loading">
<span></span>
<span></span>
<span></span>
</div>
<span class="formatted-name" v-html="data.item.formatted_name"></span>
</td>
<td>
{{ data.item.wins }}
</td>
<td>
{{ data.item.kills }}
</td>
<td>
{{ data.item.assists }}
</td>
<td>
{{ data.item.kd }}
</td>
<td>
{{ data.item.wins_percentage }}%
</td>
<td>
{{ data.item.kills_final }}
</td>
<td>
{{ data.item.kd_final }}
</td>
</template>
<template v-slot:footer>
<tr>
<th>Guild Average</th>
<calculated-cell name="wins"></calculated-cell>
<calculated-cell name="kills"></calculated-cell>
<calculated-cell name="assists"></calculated-cell>
<calculated-cell :precision="2" name="kd"></calculated-cell>
<calculated-cell :precision="1" name="wins_percentage">%</calculated-cell>
<calculated-cell name="kills_final"></calculated-cell>
<calculated-cell :precision="2" name="kd_final"></calculated-cell>
</tr>
<tr>
<th>Guild Total</th>
<calculated-cell name="wins" type="total"></calculated-cell>
<calculated-cell name="kills" type="total"></calculated-cell>
<calculated-cell name="assists" type="total"></calculated-cell>
<calculated-cell :precision="2" deaths="deaths" kills="kills" type="total_kd"></calculated-cell>
<calculated-cell :precision="1" losses="losses" type="total_wins_percentage" wins="wins">%</calculated-cell>
<calculated-cell name="kills_final" type="total"></calculated-cell>
<calculated-cell :precision="2" deaths="deaths_final" kills="kills_final" type="total_kd"></calculated-cell>
</tr>
</template>
</sortable-table>
</div>
</template>

<script>
import SortableTable from "../components/SortableTable";
import SortableHeader from "../components/SortableHeader";
import CalculatedCell from "../components/CalculatedCell";

export default {
name: "MegaWallsTable",
components: {SortableTable, SortableHeader, CalculatedCell},
props: ['members']
}
</script>
15 changes: 12 additions & 3 deletions resources/lang/en/guild.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
],

'games' => [
'skywars' => [
'skywars' => [
'page_title' => ':name SkyWars statistics',
'title' => "<a href=':link'>:name</a>'s SkyWars statistics",

Expand All @@ -106,7 +106,7 @@
'description' => 'View the SkyWars statistics of the Hypixel guild :name on :site. You can browse through the list and compare SkyWars statistics of guild members.'
],
],
'bedwars' => [
'bedwars' => [
'page_title' => ':name Bed Wars statistics',
'title' => "<a href=':link'>:name</a>'s Bed Wars statistics",

Expand All @@ -115,7 +115,7 @@
'description' => 'View the Bed Wars statistics of the Hypixel guild :name on :site. You can browse through the list and compare Bed Wars statistics of guild members.'
],
],
'tntgames' => [
'tntgames' => [
'page_title' => ':name TNT-Games statistics',
'title' => "<a href=':link'>:name</a>'s TNT-Games statistics",

Expand All @@ -124,6 +124,15 @@
'description' => 'View the TNT-Games statistics of the Hypixel guild :name on :site. You can browse through the list and compare TNT-Games statistics of guild members.'
],
],
'megawalls' => [
'page_title' => ':name Mega Walls statistics',
'title' => "<a href=':link'>:name</a>'s Mega Walls statistics",

'social' => [
'title' => ':name TNT-Games statistics - :site',
'description' => 'View the Mega Walls statistics of the Hypixel guild :name on :site. You can browse through the list and compare Mega Walls statistics of guild members.'
],
],
],

];
3 changes: 2 additions & 1 deletion resources/lang/nl/guild.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
'recently_viewed_members_and_views' => ':count leden – :views keer bekeken',

'info' => [
'title' => ':name Guild',
'title' => ':name Guild',
'members' => 'Ledenlijst',

'social' => [
'title' => ':name - :site',
Expand Down
12 changes: 12 additions & 0 deletions resources/views/guild/games/megawalls.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% extends 'guild/members.twig' %}

{% block page_title %}{{ trans('guild.games.megawalls.page_title', { name: guild.name }) }}{% endblock %}
{% block social_title %}{{ trans('guild.games.megawalls.social.title', { name: guild.name, site: config_get('app.name') }) }}{% endblock %}
{% block social_description %}{{ trans('guild.games.megawalls.social.description', { name: guild.name, site: config_get('app.name') }) }}{% endblock %}

{% block table_title %}
<h1>{{ trans('guild.games.megawalls.title', { name: guild.name, link: route('guild.info', [guild.name]) })|raw }}</h1>{% endblock %}

{% block members_table %}
<mega-walls-table :members="members"></mega-walls-table>
{% endblock %}
12 changes: 1 addition & 11 deletions resources/views/guild/info.twig
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,7 @@
<a href="{{ route('guild.games.skywars', [guild.name]) }}" class="button">{{ trans('guild.info.skywars_statistics') }}</a>
<a href="{{ route('guild.games.bedwars', [guild.name]) }}" class="button">{{ trans('guild.info.bedwars_statistics') }}</a>
<a href="{{ route('guild.games.tntgames', [guild.name]) }}" class="button">{{ trans('guild.info.tntgames_statistics') }}</a>
<ul>
<li>
<a target="_blank" href="//hypixel.maxkorlaar.com/guild/{{ guild.id }}/statistics/megawalls">{{ trans('guild.info.megawalls_statistics') }}</a>
</li>
<li>
<a target="_blank" href="//hypixel.maxkorlaar.com/guild/{{ guild.id }}/statistics/crazywalls">{{ trans('guild.info.crazywalls_statistics') }}</a>
</li>
<li>
<a target="_blank" href="//hypixel.maxkorlaar.com/guild/{{ guild.id }}/statistics/quakecraft">{{ trans('guild.info.quakecraft_statistics') }}</a>
</li>
</ul>
<a href="{{ route('guild.games.megawalls', [guild.name]) }}" class="button">{{ trans('guild.info.megawalls_statistics') }}</a>
{% if config_get('signatures.google_ads_client_id') %}
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- Guild pages -->
Expand Down
3 changes: 3 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@
Route::get('/guild/{name}/games/tnt-games', 'Guild\TNTGamesController@getTNTGamesStatistics')->name('guild.games.tntgames');
Route::get('/guild/{name}/games/tnt-games.json', 'Guild\TNTGamesController@getTNTGamesStatistics')->name('guild.games.tntgames.json');

Route::get('/guild/{name}/games/megawalls', 'Guild\MegaWallsController@getMegaWallsStatistics')->name('guild.games.megawalls');
Route::get('/guild/{name}/games/megawalls.json', 'Guild\MegaWallsController@getMegaWallsStatistics')->name('guild.games.megawalls.json');

Route::prefix('status-sig')->group(static function () {
Route::get('get-{name}/{uuid}{other?}', 'RedirectOldSignaturesController@redirect');
});
Expand Down

0 comments on commit 6b25b11

Please sign in to comment.