testing
This commit is contained in:
@@ -5,6 +5,7 @@ namespace App\Http\Controllers\Auth;
|
||||
//Library
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\JwtService;
|
||||
use App\Services\UserPrivilegeService;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
@@ -11,6 +11,11 @@ class RefreshUserJwt
|
||||
{
|
||||
protected JwtService $jwtService;
|
||||
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
|
||||
*/
|
||||
public function __construct(JwtService $jwtService)
|
||||
{
|
||||
$this->jwtService = $jwtService;
|
||||
|
||||
@@ -18,8 +18,6 @@ class RequirePermission
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle(Request $request, Closure $next, $permission): Response
|
||||
{
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace App\Http\Middleware;
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use DB;
|
||||
|
||||
use App\Models\Auth\UserRole;
|
||||
use App\Models\Auth\AvailableUserRole;
|
||||
@@ -15,8 +16,6 @@ class RequireRole
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle(Request $request, Closure $next, $role): Response
|
||||
{
|
||||
|
||||
@@ -11,6 +11,12 @@ use Throwable;
|
||||
|
||||
class ValidateJwt
|
||||
{
|
||||
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
|
||||
*/
|
||||
public function handle(Request $request, Closure $next, JwtService $jwtService): Response
|
||||
{
|
||||
$header = $request->header('Authorization');
|
||||
|
||||
@@ -1,330 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Library\Login;
|
||||
|
||||
//Internal Library
|
||||
|
||||
//App Library
|
||||
|
||||
//Models
|
||||
|
||||
class LoginHelper {
|
||||
/**
|
||||
* Check if an alt exists in the database, else, create and return the user object.
|
||||
*
|
||||
* @param \Laravel\Socialite\User $user
|
||||
*/
|
||||
private function createAlt($user, $orgCharacter) {
|
||||
//Check to see if the alt is already in the database
|
||||
$altCount = UserAlt::where(['character_id' => $user->id])->count();
|
||||
|
||||
//Check to see if the new character being added is already a main character
|
||||
$mainCount = User::where(['character_id' => $user->id])->count();
|
||||
|
||||
//If not already in the database, then add the new character
|
||||
if($altCount == 0 && $mainCount == 0) {
|
||||
//Create the new alt in the table
|
||||
$newAlt = new UserAlt;
|
||||
$newAlt->name = $user->getName();
|
||||
$newAlt->main_id = $orgCharacter;
|
||||
$newAlt->character_id = $user->id;
|
||||
$newAlt->avatar = $user->avatar;
|
||||
$newAlt->access_token = $user->token;
|
||||
$newAlt->owner_hash = $user->owner_hash;
|
||||
$newAlt->inserted_at = time();
|
||||
$newAlt->expires_in = $user->expiresIn;
|
||||
$newAlt->save();
|
||||
|
||||
//Create the entry into the EsiToken table
|
||||
if(EsiToken::where(['character_id' => $user->id])->count() == 0) {
|
||||
$this->SaveEsiToken($user);
|
||||
} else {
|
||||
$this->UpdateEsiToken($user);
|
||||
}
|
||||
|
||||
//Create the entry into the EsiScopes table
|
||||
if(sizeof($user->scopes) > 1) {
|
||||
$this->SetScopes($user->scopes, $user->id);
|
||||
}
|
||||
//Return the successfull conclusion of the function
|
||||
return 1;
|
||||
} else {
|
||||
//Return the unsuccessfull conclusion of the function
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a user exists in the database and return the user object.
|
||||
*
|
||||
* @param \Laravel\Socialite\User $user
|
||||
*/
|
||||
private function createOrGetUser($eveUser) {
|
||||
$authUser = null;
|
||||
|
||||
//Search to see if we have a matching user in the database.
|
||||
//At this point we don't care about the information
|
||||
$userCount = User::where([
|
||||
'character_id' => $eveUser->id,
|
||||
])->count();
|
||||
|
||||
//If the user is found, do more checks to see what type of login we are doing
|
||||
if($userCount > 0) {
|
||||
//Search for user in the database
|
||||
$authUser = User::where([
|
||||
'character_id' => $eveUser->id,
|
||||
])->first();
|
||||
|
||||
//Check to see if the owner has changed
|
||||
//If the owner has changed, then update their roles and permissions
|
||||
if($this->OwnerHasChanged($authUser->owner_hash, $eveUser->owner_hash)) {
|
||||
//Get the right role for the user
|
||||
$role = $this->GetRole(null, $eveUser->id);
|
||||
//Set the role for the user
|
||||
$this->SetRole($role, $eveUser->id);
|
||||
|
||||
//Update the user information never the less.
|
||||
$this->UpdateUser($eveUser, $role);
|
||||
|
||||
//Update the user's roles and permission
|
||||
$this->UpdatePermission($eveUser, $role);
|
||||
}
|
||||
|
||||
//Return the user to the calling auth function
|
||||
return $authUser;
|
||||
} else {
|
||||
//Get the role for the character to be stored in the database
|
||||
$role = $this->GetRole(null, $eveUser->id);
|
||||
|
||||
//Create the user account
|
||||
$user = $this->CreateNewUser($eveUser);
|
||||
|
||||
//Set the role for the user
|
||||
$this->SetRole($role, $eveUser->id);
|
||||
|
||||
//Create a user account
|
||||
return $user;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the ESI Token
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
private function UpdateEsiToken($eveUser) {
|
||||
EsiToken::where('character_id', $eveUser->id->update([
|
||||
'character_id' => $eveUser->getId(),
|
||||
'access_token' => $eveUser->token,
|
||||
'refresh_token' => $eveUser->refreshToken,
|
||||
'inserted_at' => time(),
|
||||
'expires_in' => $eveuser->expiresIn,
|
||||
]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new ESI Token in the database
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
private function SaveEsiToken($eveUser) {
|
||||
$token = new EsiToken;
|
||||
$token->character_id = $eveUser->id;
|
||||
$token->access_token = $eveUser->token;
|
||||
$token->refresh_token = $eveUser->refreshToken;
|
||||
$token->inserted_at = time();
|
||||
$token->expires_in = $eveUser->expiresIn;
|
||||
$token->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update avatar
|
||||
*/
|
||||
private function UpdateAvatar($eveUser) {
|
||||
User::where('character_id', $eveUser->id)->update([
|
||||
'avatar' => $eveUser->avatar,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update user permission
|
||||
*/
|
||||
private function UpdatePermission($eveUser, $role) {
|
||||
UserPermission::where(['character_id' => $eveUser->id])->delete();
|
||||
$perm = new UserPermission();
|
||||
$perm->character_id = $eveUser->id;
|
||||
$perm->permission = $role;
|
||||
$perm->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the user
|
||||
*/
|
||||
private function UpdateUser($eveUser, $role) {
|
||||
User::where('character_id', $eveUser->id)->update([
|
||||
'avatar' => $eveUser->avatar,
|
||||
'owner_hash' => $eveUser->owner_hash,
|
||||
'role' => $role,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new user account
|
||||
*/
|
||||
private function CreateNewUser($eveUser) {
|
||||
$user = User::create([
|
||||
'name' => $eveUser->getName(),
|
||||
'avatar' => $eveUser->avatar,
|
||||
'owner_hash' => $eveUser->owner_hash,
|
||||
'character_id' => $eveUser->getId(),
|
||||
'inserted_at' => time(),
|
||||
'expires_in' => $eveUser->expiresIn,
|
||||
'user_type' => $this->GetAccountType(null, $eveUser->id),
|
||||
]);
|
||||
|
||||
//Look for an existing token for the characters
|
||||
$tokenFound = EsiToken::where([
|
||||
'character_id' => $eveUser->id,
|
||||
])->count();
|
||||
|
||||
if($tokenFound == 0) {
|
||||
$token = new EsiToken;
|
||||
$token->character_id = $eveUser->id;
|
||||
$token->access_token = $eveUser->token;
|
||||
$token->refresh_token = $eveUser->refreshToken;
|
||||
$token->inserted_at = time();
|
||||
$token->expires_in = $eveUser->expiresIn;
|
||||
$token->save();
|
||||
} else {
|
||||
EsiToken::where([
|
||||
'character_id' => $eveUser->id,
|
||||
])->update([
|
||||
'character_id' => $eveUser->id,
|
||||
'access_token' => $eveUser->token,
|
||||
'refresh_token' => $eveUser->refreshToken,
|
||||
'inserted_at' => time(),
|
||||
'expires_in' => $eveUser->expiresIn,
|
||||
]);
|
||||
}
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the user role in the database
|
||||
*
|
||||
* @param role
|
||||
* @param charId
|
||||
*/
|
||||
private function SetRole($role, $charId) {
|
||||
$permission = new UserRole;
|
||||
$permission->character_id = $charId;
|
||||
$permission->role = $role;
|
||||
$permission->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the user scopes in the database
|
||||
*
|
||||
* @param scopes
|
||||
* @param charId
|
||||
*/
|
||||
private function SetScopes($scopes, $charId) {
|
||||
//Delete the current scopes, so we can add new scopes into the database
|
||||
EsiScope::where('character_id', $charId)->delete();
|
||||
foreach($scopes as $scope) {
|
||||
$data = new EsiScope;
|
||||
$data->character_id = $charId;
|
||||
$data->scope = $scope;
|
||||
$data->save();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current owner hash, and compare it with the new owner hash
|
||||
*
|
||||
* @param hash
|
||||
* @param charId
|
||||
*/
|
||||
private function OwnerHasChanged($hash, $newHash) {
|
||||
if($hash === $newHash) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the account type and returns it
|
||||
*
|
||||
* @param refreshToken
|
||||
* @param character_id
|
||||
*/
|
||||
private function GetRole($refreshToken, $charId) {
|
||||
$accountType = $this->GetAccountType($refreshToken, $charId);
|
||||
if($accountType == 'Guest') {
|
||||
$role = 'Guest';
|
||||
} else if($accountType == 'Legacy'){
|
||||
$role = 'User';
|
||||
} else if($accountType == 'W4RP') {
|
||||
$role = 'User';
|
||||
} elseif($accountType == 'Renter') {
|
||||
$role = 'Renter';
|
||||
} else {
|
||||
$role = 'None';
|
||||
}
|
||||
|
||||
return $role;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the appropriate account type the user should be assigned through ESI API
|
||||
*
|
||||
* @param refreshToken
|
||||
* @param charId
|
||||
*
|
||||
* @return text
|
||||
*/
|
||||
private function GetAccountType($refreshToken, $charId) {
|
||||
//Declare some variables
|
||||
$esiHelper = new Esi;
|
||||
$lookup = new LookupHelper;
|
||||
|
||||
//Instantiate a new ESI isntance
|
||||
$esi = $esiHelper->SetupEsiAuthentication();
|
||||
|
||||
//Set caching to null
|
||||
$configuration = Configuration::getInstance();
|
||||
$configuration->cache = NullCache::class;
|
||||
|
||||
//Get the character information
|
||||
$character_info = $lookup->GetCharacterInfo($charId);
|
||||
|
||||
//Get the corporation information
|
||||
$corp_info = $lookup->GetCorporationInfo($character_info->corporation_id);
|
||||
|
||||
if($character_info == null || $corp_info == null) {
|
||||
return redirect('/')->with('error', 'Could not create user at this time.');
|
||||
}
|
||||
|
||||
$legacy = AllowedLogin::where(['login_type' => 'Legacy'])->pluck('entity_id')->toArray();
|
||||
$renter = AllowedLogin::where(['login_type' => 'Renter'])->pluck('entity_id')->toArray();
|
||||
|
||||
//Send back the appropriate group
|
||||
if(isset($corp_info->alliance_id)) {
|
||||
if($corp_info->alliance_id == '99004116') {
|
||||
return 'W4RP';
|
||||
} else if(in_array($corp_info->alliance_id, $legacy)) {
|
||||
return 'Legacy';
|
||||
} else if(in_array($corp_info->alliance_id, $renter)) {
|
||||
return 'Renter';
|
||||
} else {
|
||||
return 'Guest';
|
||||
}
|
||||
} else {
|
||||
return 'None';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -1,626 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* W4RP Services
|
||||
* GNU Public License
|
||||
*/
|
||||
|
||||
namespace App\Library\Moons;
|
||||
|
||||
//Internal Library
|
||||
use Session;
|
||||
use DB;
|
||||
use Carbon\Carbon;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use GuzzleHttp\Client;
|
||||
use Log;
|
||||
|
||||
//Library
|
||||
use App\Library\Helpers\LookupHelper;
|
||||
|
||||
//Models
|
||||
use App\Models\Moon\Config;
|
||||
use App\Models\Moon\ItemComposition;
|
||||
use App\Models\Moon\RentalMoon;
|
||||
use App\Models\Moon\OrePrice;
|
||||
use App\Models\Moon\MineralPrice;
|
||||
|
||||
/**
|
||||
* MoonCalc Library
|
||||
*/
|
||||
class MoonCalc {
|
||||
|
||||
/**
|
||||
* Get the ore composition of an ore
|
||||
*/
|
||||
public function GetOreComposition($ore) {
|
||||
$composition = ItemComposition::where([
|
||||
'Name' => $ore,
|
||||
])->first();
|
||||
|
||||
return $composition;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the total worth of a moon
|
||||
*/
|
||||
public function MoonTotalWorth($firstOre = null, $firstQuan = 0.00, $secondOre = null, $secondQuan = 0.00, $thirdOre = null, $thirdQuan = 0.00, $fourthOre = null, $fourthQuan = 0.00) {
|
||||
//Declare variables
|
||||
$total = 0.00;
|
||||
|
||||
//Convert the quantities into numbers we want to utilize
|
||||
$this->ConvertPercentages($firstQuan, $secondQuan, $thirdQuan, $fourthQuan);
|
||||
|
||||
//Calculate the prices from the ores
|
||||
if($firstOre != null) {
|
||||
$total += $this->CalcMoonPrice($firstOre, $firstQuan);
|
||||
}
|
||||
if($secondOre != null) {
|
||||
$total += $this->CalcMoonPrice($secondOre, $secondQuan);
|
||||
}
|
||||
if($thirdOre != null) {
|
||||
$total += $this->CalcMoonPrice($thirdOre, $thirdQuan);
|
||||
}
|
||||
if($fourthOre != null) {
|
||||
$total += $this->CalcMoonPrice($fourthOre, $fourthQuan);
|
||||
}
|
||||
|
||||
//Return the rental price to the caller
|
||||
return $total;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch new prices for items from the market
|
||||
*/
|
||||
public function FetchNewPrices() {
|
||||
//Create the item id array which we will pull data for from Fuzzwork market api
|
||||
$ItemIDs = array(
|
||||
"Tritanium" => 34,
|
||||
"Pyerite" => 35,
|
||||
"Mexallon" => 36,
|
||||
"Isogen" => 37,
|
||||
"Nocxium" => 38,
|
||||
"Zydrine" => 39,
|
||||
"Megacyte" => 40,
|
||||
"Morphite" => 11399,
|
||||
"HeliumIsotopes" => 16274,
|
||||
"NitrogenIsotopes" => 17888,
|
||||
"OxygenIsotopes" => 17887,
|
||||
"HydrogenIsotopes" => 17889,
|
||||
"LiquidOzone" => 16273,
|
||||
"HeavyWater" => 16272,
|
||||
"StrontiumClathrates" => 16275,
|
||||
"AtmosphericGases" => 16634,
|
||||
"EvaporiteDeposits" => 16635,
|
||||
"Hydrocarbons" => 16633,
|
||||
"Silicates" => 16636,
|
||||
"Cobalt" => 16640,
|
||||
"Scandium" => 16639,
|
||||
"Titanium" => 16638,
|
||||
"Tungsten" => 16637,
|
||||
"Cadmium" => 16643,
|
||||
"Platinum" => 16644,
|
||||
"Vanadium" => 16642,
|
||||
"Chromium" => 16641,
|
||||
"Technetium" => 16649,
|
||||
"Hafnium" => 16648,
|
||||
"Caesium" => 16647,
|
||||
"Mercury" => 16646,
|
||||
"Dysprosium" => 16650,
|
||||
"Neodymium" => 16651,
|
||||
"Promethium" => 16652,
|
||||
"Thulium" => 16653,
|
||||
);
|
||||
|
||||
//Create the time variable
|
||||
$time = Carbon::now();
|
||||
|
||||
//Get the json data for each ItemId from https://market.fuzzwork.co.uk/api/
|
||||
//Base url is https://market.fuzzwork.co.uk/aggregates/?region=10000002&types=34
|
||||
//Going to use curl for these requests
|
||||
foreach($ItemIDs as $key => $value) {
|
||||
//Declare a new array each time we cycle through the for loop for the item
|
||||
$item = array();
|
||||
|
||||
//Setup the guzzle client fetch object
|
||||
$client = new Client(['base_uri' => 'https://market.fuzzwork.co.uk/aggregates/']);
|
||||
//Setup the uri for the guzzle client
|
||||
$uri = '?region=10000002&types=' . $value;
|
||||
//Get the result from the guzzle client request
|
||||
$result = $client->request('GET', $uri);
|
||||
//Decode the request into an array from the json body return
|
||||
$item = json_decode($result->getBody(), true);
|
||||
|
||||
//Save the entry into the database
|
||||
$price = new MineralPrice;
|
||||
$price->Name = $key;
|
||||
$price->ItemId = $value;
|
||||
$price->Price = $item[$value]['sell']['median'];
|
||||
$price->Time = $time;
|
||||
$price->save();
|
||||
}
|
||||
|
||||
//Run the update for the item pricing
|
||||
$this->UpdateItemPricing();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the ore units
|
||||
*/
|
||||
public function CalcOreUnits($ore, $percentage) {
|
||||
//Specify the total pull amount
|
||||
$totalPull = 5.55 * (3600.00 * 24.00 *30.00);
|
||||
|
||||
//Find the size of the asteroid from the database
|
||||
$item = ItemComposition::where([
|
||||
'Name' => $ore,
|
||||
])->first();
|
||||
|
||||
//Get the m3 size from the item composition
|
||||
$m3Size = $item->m3Size;
|
||||
|
||||
//Calculate the actual m3 from the total pull amount in m3 using the percentage of the ingredient
|
||||
$actualm3 = floor($totalPull * $percentage);
|
||||
|
||||
//Calculate the units from the m3 pulled from the moon
|
||||
$units = floor($actualm3 / $m3Size);
|
||||
|
||||
//Return the calculated data
|
||||
return $units;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the per item price of a unit of ore
|
||||
*/
|
||||
public function CalculateOrePrice($oreId) {
|
||||
//Declare variables
|
||||
$lookupHelper = new LookupHelper;
|
||||
$finalName = null;
|
||||
|
||||
$pastTime = Carbon::now()->subDays(30);
|
||||
|
||||
//Get the price of the moongoo
|
||||
$tritaniumPrice = MineralPrice::where(['ItemId' => 34])->where('Time', '>', $pastTime)->avg('Price');
|
||||
$pyeritePrice = MineralPrice::where(['ItemId' => 35])->where('Time', '>', $pastTime)->avg('Price');
|
||||
$mexallonPrice = MineralPrice::where(['ItemId' => 36])->where('Time', '>', $pastTime)->avg('Price');
|
||||
$isogenPrice = MineralPrice::where(['ItemId' => 37])->where('Time', '>', $pastTime)->avg('Price');
|
||||
$nocxiumPrice = MineralPrice::where(['ItemId' => 38])->where('Time', '>', $pastTime)->avg('Price');
|
||||
$zydrinePrice = MineralPrice::where(['ItemId' => 39])->where('Time', '>', $pastTime)->avg('Price');
|
||||
$megacytePrice = MineralPrice::where(['ItemId' => 40])->where('Time', '>', $pastTime)->avg('Price');
|
||||
$atmosphericGasesPrice = MineralPrice::where(['ItemId' => 16634])->where('Time', '>', $pastTime)->avg('Price');
|
||||
$evaporiteDepositsPirce = MineralPrice::where(['ItemId' => 16635])->where('Time', '>', $pastTime)->avg('Price');
|
||||
$hydrocarbonsPrice = MineralPrice::where(['ItemId' => 16633])->where('Time', '>', $pastTime)->avg('Price');
|
||||
$silicatesPrice = MineralPrice::where(['ItemId' => 16636])->where('Time', '>', $pastTime)->avg('Price');
|
||||
$cobaltPrice = MineralPrice::where(['ItemId' => 16640])->where('Time', '>', $pastTime)->avg('Price');
|
||||
$scandiumPrice = MineralPrice::where(['ItemId' => 16639])->where('Time', '>', $pastTime)->avg('Price');
|
||||
$titaniumPrice = MineralPrice::where(['ItemId' => 16638])->where('Time', '>', $pastTime)->avg('Price');
|
||||
$tungstenPrice = MineralPrice::where(['ItemId' => 16637])->where('Time', '>', $pastTime)->avg('Price');
|
||||
$cadmiumPrice = MineralPrice::where(['ItemId' => 16643])->where('Time', '>', $pastTime)->avg('Price');
|
||||
$platinumPrice = MineralPrice::where(['ItemId' => 16644])->where('Time', '>', $pastTime)->avg('Price');
|
||||
$vanadiumPrice = MineralPrice::where(['ItemId' => 16642])->where('Time', '>', $pastTime)->avg('Price');
|
||||
$chromiumPrice = MineralPrice::where(['ItemId' => 16641])->where('Time', '>', $pastTime)->avg('Price');
|
||||
$technetiumPrice = MineralPrice::where(['ItemId' => 16649])->where('Time', '>', $pastTime)->avg('Price');
|
||||
$hafniumPrice = MineralPrice::where(['ItemId' => 16648])->where('Time', '>', $pastTime)->avg('Price');
|
||||
$caesiumPrice = MineralPrice::where(['ItemId' => 16647])->where('Time', '>', $pastTime)->avg('Price');
|
||||
$mercuryPrice = MineralPrice::where(['ItemId' => 16646])->where('Time', '>', $pastTime)->avg('Price');
|
||||
$dysprosiumPrice = MineralPrice::where(['ItemId' => 16650])->where('Time', '>', $pastTime)->avg('Price');
|
||||
$neodymiumPrice = MineralPrice::where(['ItemId' => 16651])->where('Time', '>', $pastTime)->avg('Price');
|
||||
$promethiumPrice = MineralPrice::where(['ItemId' => 16652])->where('Time', '>', $pastTime)->avg('Price');
|
||||
$thuliumPrice = MineralPrice::where(['ItemId' => 16653])->where('Time', '>', $pastTime)->avg('Price');
|
||||
|
||||
//Get the name through the lookup table
|
||||
$oreName = $lookupHelper->ItemIdToName($oreId);
|
||||
|
||||
//Strip the prefix from the ore name if it has one.
|
||||
//Then change the ore id if necessary
|
||||
$tempName = explode(' ', $oreName);
|
||||
|
||||
if(sizeof($tempName) == 1) {
|
||||
$finalName = $tempName[0];
|
||||
} else {
|
||||
$finalName = $tempName[sizeof($tempName) - 1];
|
||||
$oreId = $lookupHelper->ItemNameToId($finalName);
|
||||
}
|
||||
|
||||
//Get the item composition for the ore
|
||||
$composition = ItemComposition::where('ItemId', $oreId)->first();
|
||||
|
||||
//Calculate the Batch Price
|
||||
$batchPrice = ( ($composition->Tritanium * $tritaniumPrice) +
|
||||
($composition->Pyerite * $pyeritePrice) +
|
||||
($composition->Mexallon * $mexallonPrice) +
|
||||
($composition->Isogen * $isogenPrice) +
|
||||
($composition->Nocxium * $nocxiumPrice) +
|
||||
($composition->Zydrine * $zydrinePrice) +
|
||||
($composition->Megacyte * $megacytePrice) +
|
||||
($composition->AtmosphericGases * $atmosphericGasesPrice) +
|
||||
($composition->EvaporiteDeposits * $evaporiteDepositsPirce) +
|
||||
($composition->Hydrocarbons * $hydrocarbonsPrice) +
|
||||
($composition->Silicates * $silicatesPrice) +
|
||||
($composition->Cobalt * $cobaltPrice) +
|
||||
($composition->Scandium * $scandiumPrice) +
|
||||
($composition->Titanium * $titaniumPrice) +
|
||||
($composition->Tungsten * $tungstenPrice) +
|
||||
($composition->Cadmium * $cadmiumPrice) +
|
||||
($composition->Platinum * $platinumPrice) +
|
||||
($composition->Vanadium * $vanadiumPrice) +
|
||||
($composition->Chromium * $chromiumPrice)+
|
||||
($composition->Technetium * $technetiumPrice) +
|
||||
($composition->Hafnium * $hafniumPrice) +
|
||||
($composition->Caesium * $caesiumPrice) +
|
||||
($composition->Mercury * $mercuryPrice) +
|
||||
($composition->Dysprosium * $dysprosiumPrice) +
|
||||
($composition->Neodymium * $neodymiumPrice) +
|
||||
($composition->Promethium * $promethiumPrice) +
|
||||
($composition->Thulium * $thuliumPrice));
|
||||
|
||||
//Take the batch price, and divide by batch size to get unit price
|
||||
$price = $batchPrice / $composition->BatchSize;
|
||||
|
||||
//Return the price to the calling function
|
||||
return $price;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update item pricing after new prices were pulled
|
||||
*/
|
||||
private function UpdateItemPricing() {
|
||||
//Get the configuration from the config table
|
||||
$config = DB::table('Config')->first();
|
||||
|
||||
//Calculate refine rate
|
||||
$refineRate = $config->RefineRate / 100.00;
|
||||
|
||||
//Calculate the current time
|
||||
$time = Carbon::now();
|
||||
//Calcualate the current time minus 30 days
|
||||
$pastTime = Carbon::now()->subDays(30);
|
||||
|
||||
//Get the price of the basic minerals
|
||||
$tritaniumPrice = MineralPrice::where(['ItemId' => 34])->where('Time', '>', $pastTime)->avg('Price');
|
||||
$pyeritePrice = MineralPrice::where(['ItemId' => 35])->where('Time', '>', $pastTime)->avg('Price');
|
||||
$mexallonPrice = MineralPrice::where(['ItemId' => 36])->where('Time', '>', $pastTime)->avg('Price');
|
||||
$isogenPrice = MineralPrice::where(['ItemId' => 37])->where('Time', '>', $pastTime)->avg('Price');
|
||||
$nocxiumPrice = MineralPrice::where(['ItemId' => 38])->where('Time', '>', $pastTime)->avg('Price');
|
||||
$zydrinePrice = MineralPrice::where(['ItemId' => 39])->where('Time', '>', $pastTime)->avg('Price');
|
||||
$megacytePrice = MineralPrice::where(['ItemId' => 40])->where('Time', '>', $pastTime)->avg('Price');
|
||||
$morphitePrice = MineralPrice::where(['ItemId' => 11399])->where('Time', '>', $pastTime)->avg('Price');
|
||||
$heliumIsotopesPrice = MineralPrice::where(['ItemId' => 16274])->where('Time', '>', $pastTime)->avg('Price');
|
||||
$nitrogenIsotopesPrice = MineralPrice::where(['ItemId' => 17888])->where('Time', '>', $pastTime)->avg('Price');
|
||||
$oxygenIsotopesPrice = MineralPrice::where(['ItemId' => 17887])->where('Time', '>', $pastTime)->avg('Price');
|
||||
$hydrogenIsotopesPrice = MineralPrice::where(['ItemId' => 17889])->where('Time', '>', $pastTime)->avg('Price');
|
||||
$liquidOzonePrice = MineralPrice::where(['ItemId' => 16273])->where('Time', '>', $pastTime)->avg('Price');
|
||||
$heavyWaterPrice = MineralPrice::where(['ItemId' => 16272])->where('Time', '>', $pastTime)->avg('Price');
|
||||
$strontiumClathratesPrice = MineralPrice::where(['ItemId' => 16275])->where('Time', '>', $pastTime)->avg('Price');
|
||||
//Get the price of the moongoo
|
||||
$atmosphericGasesPrice = MineralPrice::where(['ItemId' => 16634])->where('Time', '>', $pastTime)->avg('Price');
|
||||
$evaporiteDepositsPirce = MineralPrice::where(['ItemId' => 16635])->where('Time', '>', $pastTime)->avg('Price');
|
||||
$hydrocarbonsPrice = MineralPrice::where(['ItemId' => 16633])->where('Time', '>', $pastTime)->avg('Price');
|
||||
$silicatesPrice = MineralPrice::where(['ItemId' => 16636])->where('Time', '>', $pastTime)->avg('Price');
|
||||
$cobaltPrice = MineralPrice::where(['ItemId' => 16640])->where('Time', '>', $pastTime)->avg('Price');
|
||||
$scandiumPrice = MineralPrice::where(['ItemId' => 16639])->where('Time', '>', $pastTime)->avg('Price');
|
||||
$titaniumPrice = MineralPrice::where(['ItemId' => 16638])->where('Time', '>', $pastTime)->avg('Price');
|
||||
$tungstenPrice = MineralPrice::where(['ItemId' => 16637])->where('Time', '>', $pastTime)->avg('Price');
|
||||
$cadmiumPrice = MineralPrice::where(['ItemId' => 16643])->where('Time', '>', $pastTime)->avg('Price');
|
||||
$platinumPrice = MineralPrice::where(['ItemId' => 16644])->where('Time', '>', $pastTime)->avg('Price');
|
||||
$vanadiumPrice = MineralPrice::where(['ItemId' => 16642])->where('Time', '>', $pastTime)->avg('Price');
|
||||
$chromiumPrice = MineralPrice::where(['ItemId' => 16641])->where('Time', '>', $pastTime)->avg('Price');
|
||||
$technetiumPrice = MineralPrice::where(['ItemId' => 16649])->where('Time', '>', $pastTime)->avg('Price');
|
||||
$hafniumPrice = MineralPrice::where(['ItemId' => 16648])->where('Time', '>', $pastTime)->avg('Price');
|
||||
$caesiumPrice = MineralPrice::where(['ItemId' => 16647])->where('Time', '>', $pastTime)->avg('Price');
|
||||
$mercuryPrice = MineralPrice::where(['ItemId' => 16646])->where('Time', '>', $pastTime)->avg('Price');
|
||||
$dysprosiumPrice = MineralPrice::where(['ItemId' => 16650])->where('Time', '>', $pastTime)->avg('Price');
|
||||
$neodymiumPrice = MineralPrice::where(['ItemId' => 16651])->where('Time', '>', $pastTime)->avg('Price');
|
||||
$promethiumPrice = MineralPrice::where(['ItemId' => 16652])->where('Time', '>', $pastTime)->avg('Price');
|
||||
$thuliumPrice = MineralPrice::where(['ItemId' => 16653])->where('Time', '>', $pastTime)->avg('Price');
|
||||
|
||||
//Get the item compositions
|
||||
$items = DB::select('SELECT Name,ItemId FROM ItemComposition');
|
||||
//Go through each of the items and update the price
|
||||
foreach($items as $item) {
|
||||
//Get the item composition
|
||||
$composition = ItemComposition::where('ItemId', $item->ItemId)->first();
|
||||
|
||||
//Calculate the Batch Price
|
||||
$batchPrice = ( ($composition->Tritanium * $tritaniumPrice) +
|
||||
($composition->Pyerite * $pyeritePrice) +
|
||||
($composition->Mexallon * $mexallonPrice) +
|
||||
($composition->Isogen * $isogenPrice) +
|
||||
($composition->Nocxium * $nocxiumPrice) +
|
||||
($composition->Zydrine * $zydrinePrice) +
|
||||
($composition->Megacyte * $megacytePrice) +
|
||||
($composition->Morphite * $morphitePrice) +
|
||||
($composition->HeavyWater * $heavyWaterPrice) +
|
||||
($composition->LiquidOzone * $liquidOzonePrice) +
|
||||
($composition->NitrogenIsotopes * $nitrogenIsotopesPrice) +
|
||||
($composition->HeliumIsotopes * $heliumIsotopesPrice) +
|
||||
($composition->HydrogenIsotopes * $hydrogenIsotopesPrice) +
|
||||
($composition->OxygenIsotopes * $oxygenIsotopesPrice) +
|
||||
($composition->StrontiumClathrates * $strontiumClathratesPrice) +
|
||||
($composition->AtmosphericGases * $atmosphericGasesPrice) +
|
||||
($composition->EvaporiteDeposits * $evaporiteDepositsPirce) +
|
||||
($composition->Hydrocarbons * $hydrocarbonsPrice) +
|
||||
($composition->Silicates * $silicatesPrice) +
|
||||
($composition->Cobalt * $cobaltPrice) +
|
||||
($composition->Scandium * $scandiumPrice) +
|
||||
($composition->Titanium * $titaniumPrice) +
|
||||
($composition->Tungsten * $tungstenPrice) +
|
||||
($composition->Cadmium * $cadmiumPrice) +
|
||||
($composition->Platinum * $platinumPrice) +
|
||||
($composition->Vanadium * $vanadiumPrice) +
|
||||
($composition->Chromium * $chromiumPrice)+
|
||||
($composition->Technetium * $technetiumPrice) +
|
||||
($composition->Hafnium * $hafniumPrice) +
|
||||
($composition->Caesium * $caesiumPrice) +
|
||||
($composition->Mercury * $mercuryPrice) +
|
||||
($composition->Dysprosium * $dysprosiumPrice) +
|
||||
($composition->Neodymium * $neodymiumPrice) +
|
||||
($composition->Promethium * $promethiumPrice) +
|
||||
($composition->Thulium * $thuliumPrice));
|
||||
//Calculate the batch price with the refine rate included
|
||||
//Batch Price is base price for everything
|
||||
$batchPrice = $batchPrice * $refineRate;
|
||||
//Calculate the unit price
|
||||
$price = $batchPrice / $composition->BatchSize;
|
||||
//Calculate the m3 price
|
||||
$m3Price = $price / $composition->m3Size;
|
||||
|
||||
//Check if an item is in the table
|
||||
$count = OrePrice::where('Name', $composition->Name)->count();
|
||||
if($count == 0) {
|
||||
//If the ore wasn't found, then add a new entry
|
||||
$ore = new OrePrice;
|
||||
$ore->Name = $composition->Name;
|
||||
$ore->ItemId = $composition->ItemId;
|
||||
$ore->BatchPrice = $batchPrice;
|
||||
$ore->UnitPrice = $price;
|
||||
$ore->m3Price = $m3Price;
|
||||
$ore->Time = $time;
|
||||
$ore->save();
|
||||
} else {
|
||||
//Update the prices in the Prices table
|
||||
OrePrice::where('Name', $composition->Name)->update([
|
||||
'Name' => $composition->Name,
|
||||
'ItemId' => $composition->ItemId,
|
||||
'BatchPrice' => $batchPrice,
|
||||
'UnitPrice' => $price,
|
||||
'm3Price' => $m3Price,
|
||||
'Time' => $time,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the total amount pulled from a moon
|
||||
*/
|
||||
private function CalculateTotalMoonPull() {
|
||||
//Always assume a 1 month pull which equates to 5.55m3 per second or 2,592,000 seconds
|
||||
//Total pull size is 14,385,600 m3
|
||||
$totalPull = 5.55 * 3600.00 * 24.00 *30.00;
|
||||
|
||||
//Return the total pull
|
||||
return $totalPull;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the rental price of a moon ore from the moon
|
||||
*/
|
||||
private function CalcRentalPrice($ore, $percentage) {
|
||||
//Specify the total pull amount
|
||||
$totalPull = $this->CalculateTotalMoonPull();
|
||||
|
||||
//Setup the total value at 0.00
|
||||
$totalPrice = 0.00;
|
||||
|
||||
//Check to see what type of moon goo the moon is
|
||||
$gasMoonOre = $this->IsGasMoonGoo($ore);
|
||||
|
||||
//Find the size of the asteroid from the database
|
||||
$m3Size = DB::table('ItemComposition')->where('Name', $ore)->value('m3Size');
|
||||
|
||||
//Calculate the actual m3 from the total pull amount in m3 using the percentage of the ingredient
|
||||
$actualm3 = floor($percentage * $totalPull);
|
||||
|
||||
//Calculate the units once we have the size and actual m3 value
|
||||
$units = floor($actualm3 / $m3Size);
|
||||
|
||||
//Look up the unit price from the database
|
||||
$unitPrice = DB::table('ore_prices')->where('Name', $ore)->value('UnitPrice');
|
||||
|
||||
//If the ore is a gas ore, then take only 50% of the price.
|
||||
if($gasMoonOre == true) {
|
||||
$totalPrice = $units * ($unitPrice / 2.00);
|
||||
Log::warning('Found gas ore: ' . $totalPrice);
|
||||
} else {
|
||||
$totalPrice = $units * $unitPrice;
|
||||
}
|
||||
|
||||
//Return the total
|
||||
return $totalPrice;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the moon's total price
|
||||
*/
|
||||
public function CalcMoonPrice($ore, $percentage) {
|
||||
//Specify the total pull amount
|
||||
$totalPull = $this->CalculateTotalMoonPull();
|
||||
|
||||
//Setup the total value at 0.00
|
||||
$totalPrice = 0.00;
|
||||
|
||||
//Find the size of the asteroid from the database
|
||||
$m3Size = DB::table('ItemComposition')->where('Name', $ore)->value('m3Size');
|
||||
|
||||
//Calculate the actual m3 from the total pull amount in m3 using the percentage of the ingredient
|
||||
$actualm3 = floor($percentage * $totalPull);
|
||||
|
||||
//Calculate the units once we have the size and actual m3 value
|
||||
$units = floor($actualm3 / $m3Size);
|
||||
|
||||
//Look up the unit price from the database
|
||||
$unitPrice = DB::table('ore_prices')->where('Name', $ore)->value('UnitPrice');
|
||||
|
||||
//Calculate the total amount from the units and the unit price.
|
||||
$totalPrice = $units * $unitPrice;
|
||||
|
||||
//Return the value
|
||||
return $totalPrice;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a number to a percentage
|
||||
*/
|
||||
private function ConvertToPercentage($quantity) {
|
||||
//Perform the calculation and return the data
|
||||
return $quantity / 100.00;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return if a type of ore is a gas moon goo
|
||||
*/
|
||||
private function IsGasMoonGoo($ore) {
|
||||
$ores = [
|
||||
'Zeolites' => 'Gas',
|
||||
'Sylvite' => 'Gas',
|
||||
'Bitumens' => 'Gas',
|
||||
'Coesite' => 'Gas',
|
||||
];
|
||||
|
||||
foreach($ores as $key => $value) {
|
||||
if(strtolower($key) == strtolower($ore)) {
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the type of ore a particular moon ore is.
|
||||
*/
|
||||
public function IsRMoonGoo($ore) {
|
||||
$ores = [
|
||||
'Zeolites' => 'R4',
|
||||
'Sylvite' => 'R4',
|
||||
'Bitumens' => 'R4',
|
||||
'Coesite' => 'R4',
|
||||
'Cobaltite' => 'R8',
|
||||
'Euxenite' => 'R8',
|
||||
'Titanite' => 'R8',
|
||||
'Scheelite' => 'R8',
|
||||
'Otavite' => 'R16',
|
||||
'Sperrylite' => 'R16',
|
||||
'Vanadinite' => 'R16',
|
||||
'Chromite' => 'R16',
|
||||
'Carnotite' => 'R32',
|
||||
'Zircon' => 'R32',
|
||||
'Pollucite' => 'R32',
|
||||
'Cinnabar' => 'R32',
|
||||
'Xenotime' => 'R64',
|
||||
'Monazite' => 'R64',
|
||||
'Loparite' => 'R64',
|
||||
'Ytterbite' => 'R64',
|
||||
];
|
||||
|
||||
foreach($ores as $key => $value) {
|
||||
if(strtolower($key) == strtolower($ore)) {
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
//Return false if the ore is not found in an array
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if a moon ore is a moon ore, and false
|
||||
* if the ore is not a moon ore.
|
||||
*/
|
||||
public function IsRMoonOre($ore) {
|
||||
$ores = [
|
||||
'Zeolites' => 'R4',
|
||||
'Sylvite' => 'R4',
|
||||
'Bitumens' => 'R4',
|
||||
'Coesite' => 'R4',
|
||||
'Cobaltite' => 'R8',
|
||||
'Euxenite' => 'R8',
|
||||
'Titanite' => 'R8',
|
||||
'Scheelite' => 'R8',
|
||||
'Otavite' => 'R16',
|
||||
'Sperrylite' => 'R16',
|
||||
'Vanadinite' => 'R16',
|
||||
'Chromite' => 'R16',
|
||||
'Carnotite' => 'R32',
|
||||
'Zircon' => 'R32',
|
||||
'Pollucite' => 'R32',
|
||||
'Cinnabar' => 'R32',
|
||||
'Xenotime' => 'R64',
|
||||
'Monazite' => 'R64',
|
||||
'Loparite' => 'R64',
|
||||
'Ytterbite' => 'R64',
|
||||
];
|
||||
|
||||
foreach($ores as $key => $value) {
|
||||
|
||||
if(strtolower($key) == strtolower($ore)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert percentages from quantities into a normalized percentage
|
||||
*/
|
||||
public function ConvertPercentages(&$firstPerc, &$secondPerc, &$thirdPerc, &$fourthPerc) {
|
||||
//Convert the quantities into numbers we want to utilize
|
||||
if($firstPerc >= 1.00) {
|
||||
$firstPerc = $this->ConvertToPercentage($firstPerc);
|
||||
}
|
||||
|
||||
if($secondPerc >= 1.00) {
|
||||
$secondPerc = $this->ConvertToPercentage($secondPerc);
|
||||
}
|
||||
|
||||
if($thirdPerc >= 1.00) {
|
||||
$thirdPerc = $this->ConvertToPercentage($thirdPerc);
|
||||
}
|
||||
|
||||
if($fourthPerc >= 1.00) {
|
||||
$fourthPerc = $this->ConvertToPercentage($fourthPerc);
|
||||
}
|
||||
|
||||
|
||||
//Add up all the percentages
|
||||
$totalPerc = $firstPerc + $secondPerc + $thirdPerc + $fourthPerc;
|
||||
|
||||
//If it is less than 1.00, then we need to normalize the decimal to be 100.0%.
|
||||
if($totalPerc < 1.00) {
|
||||
if($firstPerc > 0.00) {
|
||||
$firstPerc = $firstPerc / $totalPerc;
|
||||
} else {
|
||||
$firstPerc = 0.00;
|
||||
}
|
||||
|
||||
if($secondPerc > 0.00) {
|
||||
$secondPerc = $secondPerc / $totalPerc;
|
||||
} else {
|
||||
$secondPerc = 0.00;
|
||||
}
|
||||
|
||||
if($thirdPerc > 0.00) {
|
||||
$thirdPerc = $thirdPerc / $totalPerc;
|
||||
} else {
|
||||
$thirdPerc = 0.00;
|
||||
}
|
||||
|
||||
if($fourthPerc > 0.00) {
|
||||
$fourthPerc = $fourthPerc / $totalPerc;
|
||||
} else {
|
||||
$fourthPerc = 0.00;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user