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

Closes #52 Zones are added to each star type, and each zone can have … #69

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions app/Character.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,9 @@ public function actions()
{
return $this->hasMany('App\Action');
}

public function plans()
{
return $this->belongsToMany('App\Plan');
}
}
5 changes: 5 additions & 0 deletions app/Console/Commands/ProcessContracts.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ public function handle()

$next = $now;
$contract->next_at = $next->addSeconds($contract->frequency);

if ($contract->getOriginal('expires_at') < $now) {
$contract->status = "expired";
}

$contract->save();
}
}
Expand Down
42 changes: 42 additions & 0 deletions app/Console/Commands/ProcessResearch.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

class ProcessResearch extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'command:name';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';

/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
//
}
}
59 changes: 59 additions & 0 deletions app/Console/Commands/ProcessResearchPoints.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

namespace App\Console\Commands;

use App\Character;
use Illuminate\Console\Command;

class ProcessResearchPoints extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'process:research';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Give research points to users based on how many bases they have.';

/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$characters = Character::all();

foreach ($characters as $character)
{
$base_load = 0;

foreach ($character->bases as $base) {
$base_load = $base_load + $base->level;
}

$newPoints = ((config('game.daily_research_points') + ($base_load / 10)) / 48); // 24
$character->research_points = $character->research_points + $newPoints;

$character->save();

echo "Adding " . $newPoints;
}
}
}
1 change: 1 addition & 0 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ protected function schedule(Schedule $schedule)
$schedule->command('process:actions')->everyMinute();
$schedule->command('process:contracts')->everyMinute();
$schedule->command('process:mines')->everyFiveMinutes();
$schedule->command('process:research')->everyThirtyMinutes();
}

/**
Expand Down
13 changes: 13 additions & 0 deletions app/Contract.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,17 @@ public function getNextAtAttribute($time)
return $diff . "m";
}

public function getExpiresAtAttribute($time)
{
$now = Carbon::now();
$diff = $now->diffInHours($time);

return $diff . " Hours";
}

public function activeContracts($query)
{
return $query->where('status', '=', 'active');
}

}
11 changes: 11 additions & 0 deletions app/Helpers/Formulas.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,15 @@ function calculateContractMaxSell()

return $percent;
}

function calculateContractExpiration()
{
$baseDays = config('formulas.contract_base_expiration_days');

for ($i = 1; $i <= 18; $i++) {
$expires[$i] = $baseDays + ($i * config('formulas.contract_increase_expiration_days'));
}

return $expires;
}
?>
1 change: 1 addition & 0 deletions app/Http/Controllers/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use App\Character;
use Illuminate\Http\Request;

// Show a list of all bases in the ACP
class BaseController extends Controller
{
public function index()
Expand Down
12 changes: 10 additions & 2 deletions app/Http/Controllers/CharacterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Alert;
use Gate;
use App\Character;
use App\Plan;
use App\Species;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
Expand Down Expand Up @@ -44,7 +45,7 @@ public function show($id)
}


public function create () {
public function create() {

$user_id = Auth::id();
$character = Character::where("user_id", '=', $user_id)->get();
Expand All @@ -60,7 +61,7 @@ public function create () {
]);
}

public function save (Request $request){
public function save(Request $request){

$this->validate($request, [
'name' => 'required|string|max:25',
Expand All @@ -74,10 +75,17 @@ public function save (Request $request){
$character->species_id = $request->species;
$character->faction_id = 0;
$character->planet_id = 1; // Earth!
$character->research_points = config('game.starting_research');
$character->money = config('game.starting_money');

$character->save();

$plans = Plan::where('learn_from', '=', 'default')->get();

foreach($plans as $plan) {
$character->plans()->attach($plan->id);
}

return redirect()->route('home');
}

Expand Down
29 changes: 23 additions & 6 deletions app/Http/Controllers/ContractController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ public function create($id)
return redirect()->route('visit-planet');
}

if ($facility->base->contracts->count() >= $facility->level) {
$contracts = Contract::where('base_id', '=', $facility->base->id)->where('status', '=', 'active')->get();

if ($contracts->count() >= $facility->level) {
Alert::toast('Contract Limit Reached', 'error');
return redirect()->route('visit-planet');
}
Expand All @@ -39,13 +41,15 @@ public function create($id)
$price['gas'] = materialSellPrice($facility->level, 'gas', 'contract');
$time = calculateContractTime();
$percent = calculateContractMaxSell();
$expire = calculateContractExpiration();

return view('game.contract.new', [
'loadCharacter' => $character,
'facility' => $facility,
'price' => $price,
'time' => $time,
'percent' => $percent,
'expire' => $expire,
]);
}

Expand All @@ -66,25 +70,29 @@ public function reviewContract(Request $request, $id)
return redirect()->route('visit-planet');
}

if ($facility->base->contracts->count() >= $facility->level) {
$contracts = Contract::where('base_id', '=', $facility->base->id)->where('status', '=', 'active')->get();

if ($contracts->count() >= $facility->level) {
Alert::toast('Contract Limit Reached', 'error');
return redirect()->route('visit-planet');
}

if ($character->money < (($request->frequency + $request->amount) * config('game.contract_base_rate'))) {
/* if ($character->money < (($request->frequency + $request->amount) * config('game.contract_base_rate'))) {
Alert::toast('Not Enough ' . __('common.money'), 'warning');
return redirect()->route('visit-planet');
}

*/
$price['ore'] = materialSellPrice($facility->level, 'ore', 'contract');
$price['gas'] = materialSellPrice($facility->level, 'gas', 'contract');
$time = calculateContractTime();
$percent = calculateContractMaxSell();
$expire = calculateContractExpiration();

$this->validate($request, [
'amount' => 'required|integer',
'resource' => 'required|string',
'frequency' => 'required|integer',
'length' => 'required|integer',
]);

if ($request->resource != "ore" && $request->resource != "gas") {
Expand Down Expand Up @@ -114,6 +122,7 @@ public function reviewContract(Request $request, $id)
'contract' => $request,
'production' => $production,
'storage' => $storage,
'expire' => $expire,
]);
}

Expand All @@ -134,18 +143,22 @@ public function createContract(Request $request, $id)
return redirect()->route('visit-planet');
}

if ($facility->base->contracts->count() >= $facility->level) {
$contracts = Contract::where('base_id', '=', $facility->base->id)->where('status', '=', 'active')->get();

if ($contracts->count() >= $facility->level) {
Alert::toast('Contract Limit Reached', 'error');
return redirect()->route('visit-planet');
}

$time = calculateContractTime();
$percent = calculateContractMaxSell();
$expire = calculateContractExpiration();

$this->validate($request, [
'amount' => 'required|integer',
'resource' => 'required|string',
'frequency' => 'required|integer',
'length' => 'required|integer',
]);

if ($request->resource != "ore" && $request->resource != "gas") {
Expand All @@ -156,8 +169,11 @@ public function createContract(Request $request, $id)
$price = materialSellPrice($facility->level, $request->resource, 'contract');

$now = new Carbon();
$expires = new Carbon();
$contract = new Contract();

$expires->addHours(floor($expire[$request->length] * 24));

$contract->base_id = $facility->base_id;
$contract->resource = $request->resource;
$contract->action = "sell";
Expand All @@ -167,9 +183,10 @@ public function createContract(Request $request, $id)
$contract->time = 0;
$contract->next_at = $now->addSeconds(floor($time[$request->frequency] * 60));
$contract->status = "active";
$contract->expires_at = $expires;
$contract->save();

$character->money = $character->money - (($request->frequency + $request->amount) * config('game.contract_base_rate'));
$character->money = $character->money - (($request->frequency + $request->amount + $request->length) * config('game.contract_base_rate'));
$character->save();

Alert::toast("Contract created!", 'success');
Expand Down
Loading