Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new signatures #66

Merged
merged 3 commits into from
Oct 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions app/Http/Controllers/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@ public function signatureIndex() {
'name' => 'Duels statistics',
'route' => 'duels'
],
[
'name' => 'TNT-Games statistics',
'route' => 'tnt_games'
],
[
'name' => 'Cops and Crims statistics',
'route' => 'cops_and_crims'
],
[
'name' => 'Blitz Survival Games statistics',
'route' => 'blitz_survival_games'
],
]
],
'skywars' => [
Expand Down
21 changes: 12 additions & 9 deletions app/Http/Controllers/RedirectOldSignaturesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,17 @@
*/
class RedirectOldSignaturesController extends Controller {
private const URL_MAPPING = [
'main' => 'signatures.general',
'main-small' => 'signatures.general_small',
'tooltip' => 'signatures.general_tooltip',
'bed-wars' => 'signatures.bedwars',
'skywars' => 'signatures.skywars',
'skywars-simple' => 'signatures.skywars_simple',
'skywars-gif' => 'signatures.skywars_gif',
'uhc-champions' => 'signatures.uhc_champions'
'main' => 'signatures.general',
'main-small' => 'signatures.general_small',
'tooltip' => 'signatures.general_tooltip',
'bed-wars' => 'signatures.bedwars',
'skywars' => 'signatures.skywars',
'skywars-simple' => 'signatures.skywars_simple',
'skywars-gif' => 'signatures.skywars_gif',
'uhc-champions' => 'signatures.uhc_champions',
'tnt-games' => 'signatures.tnt_games',
'cops-versus-crims' => 'signatures.cops_and_crims',
'blitz' => 'signatures.blitz_survival_games',
];

/**
Expand All @@ -79,6 +82,6 @@ public function redirect($oldSignatureName, $uuid, $other = null) {

$oldSignatureName = Str::limit($oldSignatureName, 20);

return BaseSignature::generateErrorImage("The signature '{$oldSignatureName}' does not exist. It probably has been (re)moved. You can suggest it to be added again, if it's been removed. Visit Hypixel.Paniek.de.", 404, 800, 200);
return BaseSignature::generateErrorImage("Signature '{$oldSignatureName}' does not exist. Got this signature from hypixel.maxkorlaar.com? It might have been removed. You can suggest it to be added again. Visit Hypixel.Paniek.de or the forum thread.", 404, 800, 250);
}
}
6 changes: 3 additions & 3 deletions app/Http/Controllers/Signatures/BaseSignature.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,13 @@ public static function generateErrorImage($error, $statusCode = 500, $width = 74
$box = new Box($image);
$box->setFontFace(resource_path('fonts/SourceSansPro/SourceSansPro-Light.otf'));
$box->setFontColor(new Color(255, 0, 0));
$box->setFontSize($height / 3);
$box->setFontSize($height / 4);
$box->setBox(5, 0, $width - 5, $height - 5);
$box->setTextAlign('center', 'top');
$box->draw('Something went wrong');

$box->setBox(5, $height / 3 + 10, $width - 5, $height - 5);
$box->setFontSize($height / 6);
$box->setBox(5, $height / 4 + 10, $width - 5, $height - 5);
$box->setFontSize($height / 7);
$box->setFontColor(new Color(0, 0, 0));
$box->draw($error);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
<?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\Signatures;

use App\Utilities\ColourHelper;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Image;
use Plancke\HypixelPHP\classes\gameType\GameTypes;
use Plancke\HypixelPHP\exceptions\HypixelPHPException;
use Plancke\HypixelPHP\responses\player\GameStats;
use Plancke\HypixelPHP\responses\player\Player;

/**
* Class BlitzSurvivalGamesSignatureController
*
* @package App\Http\Controllers\Signatures
*/
class BlitzSurvivalGamesSignatureController extends BaseSignature {
/**
* @inheritDoc
* @throws HypixelPHPException
*/
protected function signature(Request $request, Player $player): Response {
$image = BaseSignature::getImage(550, 160);
$black = imagecolorallocate($image, 0, 0, 0);
$grey = imagecolorallocate($image, 203, 203, 203);
$fontSourceSansProLight = resource_path('fonts/SourceSansPro/SourceSansPro-Light.otf');

$username = $player->getName();
$rankNameWithColour = $this->getColouredRankName($player);

$mainStats = $player->getStats();
/** @var GameStats $stats */
$stats = $mainStats->getGameFromID(GameTypes::SURVIVAL_GAMES);

$wins = $stats->getInt('wins') + $stats->getInt('wins_teams');
$kills = $stats->getInt('kills') + $stats->getInt('kills_teams');
$deaths = $stats->getInt('deaths') + $stats->getInt('deaths_teams');
$losses = $stats->getInt('deaths');

$defaultKit = $stats->get('defaultkit', 'N/A');
$defaultKitLevel = $stats->get(strtolower($defaultKit), 0) + 1;

if ($deaths !== 0) {
$kd = round($kills / $deaths, 2);
} else {
$kd = 'None';
}

if ($wins !== 0) {
$winsPercentage = round(($wins / ($wins + $losses)) * 100, 2);
} else {
$winsPercentage = 0;
}

if ($request->has('no_3d_avatar')) {
[, $textX, $textBeneathAvatarX] = $this->get2dAvatar($player, $image);
} else {
[, $textX, $textBeneathAvatarX] = $this->get3dAvatar($player, $image);
}

if ($request->has('guildTag')) {
$guildTag = '§7[' . $player->getGuildTag() . ']';
if ($guildTag === '§7[]') {
$guildTag = '§7[-]';
}
$usernameBoundingBox = ColourHelper::minecraftStringToTTFText($image, $fontSourceSansProLight, 25, $textX, 14, '§0' . $username . ' ' . $guildTag);
} else {
$usernameBoundingBox = imagettftext($image, 25, 0, $textX, 30, $black, $fontSourceSansProLight, $username);
}

imagettftext($image, 17, 0, $usernameBoundingBox[2] + 10, 30, $grey, $fontSourceSansProLight, 'Blitz Survival Games statistics');

$linesY = [60, 95, 130]; // Y starting points of the various text lines

ColourHelper::minecraftStringToTTFText($image, $fontSourceSansProLight, 20, $textX, 44, $rankNameWithColour); // Rank name (coloured)

imagettftext($image, 20, 0, $textX, $linesY[1], $black, $fontSourceSansProLight, number_format($kills) . ' kills');

imagettftext($image, 20, 0, 275, $linesY[0], $black, $fontSourceSansProLight, $defaultKit . ' ' . $this->numberToRomanRepresentation($defaultKitLevel));

imagettftext($image, 20, 0, 275, $linesY[1], $black, $fontSourceSansProLight, 'KD: ' . $kd);

imagettftext($image, 20, 0, $textBeneathAvatarX, $linesY[2], $black, $fontSourceSansProLight, number_format($wins) . ' wins');

imagettftext($image, 20, 0, 275, $linesY[2], $black, $fontSourceSansProLight, "Wins percentage: {$winsPercentage}%");

$this->addWatermark($image, $fontSourceSansProLight, 550, 160); // Watermark/advertisement

return Image::make($image)->response('png')->setCache([
'public' => true,
'max_age' => 600
]);
}

/**
* @param int $number
*
* @return string
*
* @source https://stackoverflow.com/a/15023547
*/
private function numberToRomanRepresentation(int $number): string {
$map = ['M' => 1000, 'CM' => 900, 'D' => 500, 'CD' => 400, 'C' => 100, 'XC' => 90, 'L' => 50, 'XL' => 40, 'X' => 10, 'IX' => 9, 'V' => 5, 'IV' => 4, 'I' => 1];
$returnValue = '';

while ($number > 0) {
foreach ($map as $roman => $int) {
if ($number >= $int) {
$number -= $int;
$returnValue .= $roman;
break;
}
}
}

return $returnValue;
}
}
119 changes: 119 additions & 0 deletions app/Http/Controllers/Signatures/CopsAndCrimsSignatureController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
<?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\Signatures;

use App\Utilities\ColourHelper;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Image;
use Plancke\HypixelPHP\classes\gameType\GameTypes;
use Plancke\HypixelPHP\exceptions\HypixelPHPException;
use Plancke\HypixelPHP\responses\player\GameStats;
use Plancke\HypixelPHP\responses\player\Player;

/**
* Class CopsAndCrimsSignatureController
*
* @package App\Http\Controllers\Signatures
*/
class CopsAndCrimsSignatureController extends BaseSignature {

/**
* @inheritDoc
* @throws HypixelPHPException
*/
protected function signature(Request $request, Player $player): Response {
$image = BaseSignature::getImage(500, 160);
$black = imagecolorallocate($image, 0, 0, 0);
$grey = imagecolorallocate($image, 203, 203, 203);
$fontSourceSansProLight = resource_path('fonts/SourceSansPro/SourceSansPro-Light.otf');

$username = $player->getName();
$rankNameWithColour = $this->getColouredRankName($player);

$mainStats = $player->getStats();
/** @var GameStats $stats */
$stats = $mainStats->getGameFromID(GameTypes::MCGO);

$kills = $stats->getInt('kills');
$deaths = $stats->getInt('deaths');
$gameWins = $stats->getInt('game_wins');
$roundWins = $stats->getInt('round_wins');
$headshotKills = $stats->getInt('headshot_kills');

if ($deaths !== 0) {
$kd = round($kills / $deaths, 2);
} else {
$kd = 'None';
}

if ($request->has('no_3d_avatar')) {
[, $textX, $textBeneathAvatarX] = $this->get2dAvatar($player, $image);
} else {
[, $textX, $textBeneathAvatarX] = $this->get3dAvatar($player, $image);
}

if ($request->has('guildTag')) {
$guildTag = '§7[' . $player->getGuildTag() . ']';
if ($guildTag === '§7[]') {
$guildTag = '§7[-]';
}
$usernameBoundingBox = ColourHelper::minecraftStringToTTFText($image, $fontSourceSansProLight, 25, $textX, 14, '§0' . $username . ' ' . $guildTag);
} else {
$usernameBoundingBox = imagettftext($image, 25, 0, $textX, 30, $black, $fontSourceSansProLight, $username);
}

imagettftext($image, 17, 0, $usernameBoundingBox[2] + 10, 30, $grey, $fontSourceSansProLight, 'Cops and Crims statistics');

$linesY = [60, 95, 130]; // Y starting points of the various text lines

ColourHelper::minecraftStringToTTFText($image, $fontSourceSansProLight, 20, $textX, 44, $rankNameWithColour); // Rank name (coloured)

imagettftext($image, 20, 0, $textX, $linesY[1], $black, $fontSourceSansProLight, number_format($kills) . ' kills');

imagettftext($image, 20, 0, 275, $linesY[0], $black, $fontSourceSansProLight, number_format($roundWins) . ' round wins');

imagettftext($image, 20, 0, 275, $linesY[1], $black, $fontSourceSansProLight, 'KD: ' . $kd);

imagettftext($image, 20, 0, $textBeneathAvatarX, $linesY[2], $black, $fontSourceSansProLight, number_format($gameWins) . ' wins');

imagettftext($image, 20, 0, 275, $linesY[2], $black, $fontSourceSansProLight, number_format($headshotKills) . ' headshots');

$this->addWatermark($image, $fontSourceSansProLight, 500, 160); // Watermark/advertisement

return Image::make($image)->response('png')->setCache([
'public' => true,
'max_age' => 600
]);
}
}
Loading