From d0ccb12888bbe3c7967c05d57743cc08dfed114a Mon Sep 17 00:00:00 2001
From: Jon Zenor
Date: Sat, 28 Mar 2020 18:20:03 -0600
Subject: [PATCH 1/4] Closes #52 Zones are added to each star type, and each
zone can have multiple planets assigned to it along with the probability.
---
app/Http/Controllers/StarTypeController.php | 4 +-
app/Http/Controllers/ZoneController.php | 192 ++++++++++++++++++
app/PlanetType.php | 5 +-
app/StarType.php | 5 +-
app/Zone.php | 18 ++
...0_01_12_221235_create_star_types_table.php | 2 +-
.../2020_02_07_231314_populate_star_types.php | 18 +-
.../2020_03_28_220958_create_zones_table.php | 34 ++++
...8_221944_create_planet_type_zone_table.php | 33 +++
public/css/app.css | 4 -
resources/lang/en/common.php | 3 +
resources/sass/app.scss | 4 +-
resources/views/acp/index.blade.php | 4 +-
resources/views/acp/zone/add.blade.php | 26 +++
resources/views/acp/zone/addPlanet.blade.php | 41 ++++
resources/views/acp/zone/edit.blade.php | 25 +++
resources/views/acp/zone/show.blade.php | 42 ++++
resources/views/star-type/edit.blade.php | 4 +-
resources/views/star-type/index.blade.php | 2 +-
resources/views/star-type/new.blade.php | 6 +-
resources/views/star-type/show.blade.php | 30 ++-
routes/web.php | 10 +
22 files changed, 482 insertions(+), 30 deletions(-)
create mode 100644 app/Http/Controllers/ZoneController.php
create mode 100644 app/Zone.php
create mode 100644 database/migrations/2020_03_28_220958_create_zones_table.php
create mode 100644 database/migrations/2020_03_28_221944_create_planet_type_zone_table.php
create mode 100644 resources/views/acp/zone/add.blade.php
create mode 100644 resources/views/acp/zone/addPlanet.blade.php
create mode 100644 resources/views/acp/zone/edit.blade.php
create mode 100644 resources/views/acp/zone/show.blade.php
diff --git a/app/Http/Controllers/StarTypeController.php b/app/Http/Controllers/StarTypeController.php
index bf8152d..93ca915 100644
--- a/app/Http/Controllers/StarTypeController.php
+++ b/app/Http/Controllers/StarTypeController.php
@@ -65,7 +65,7 @@ public function store(Request $request)
$star = new StarType();
- $star->type = $request->type;
+ $star->name = $request->name;
$star->diameter = $request->diameter;
$star->color = $request->color;
$star->probability = $request->probability;
@@ -155,7 +155,7 @@ public function update(Request $request, $id)
return redirect()->route('acp-star-types');
}
- $star->type = $request->name;
+ $star->name = $request->name;
$star->diameter = $request->diameter;
$star->color = $request->color;
$star->probability = $request->probability;
diff --git a/app/Http/Controllers/ZoneController.php b/app/Http/Controllers/ZoneController.php
new file mode 100644
index 0000000..9f7db6b
--- /dev/null
+++ b/app/Http/Controllers/ZoneController.php
@@ -0,0 +1,192 @@
+route('acp');
+ }
+
+ return view('acp.zone.add', [
+ 'starType' => $starType,
+ ]);
+ }
+
+ public function store(Request $request, $id)
+ {
+ if (Gate::denies('manage-game-elements')) {
+ Alert::toast('Permission Denied', 'warning');
+ return redirect('/');
+ }
+
+ $starType = StarType::find($id);
+
+ if (!$starType) {
+ Alert::toast("Invalid Star Type", 'warning');
+ return redirect()->route('acp');
+ }
+
+ $this->validate($request, [
+ 'distance' => 'required|integer',
+ ]);
+
+ $zone = new Zone();
+
+ $zone->distance = $request->distance;
+ $zone->order = ($starType->zones->count() + 1);
+ $zone->star_type_id = $starType->id;
+
+ $zone->save();
+
+ return redirect()->route('acp-star-type', $starType->id);
+ }
+
+ public function edit($id)
+ {
+ if (Gate::denies('manage-game-elements')) {
+ Alert::toast('Permission Denied', 'warning');
+ return redirect('/');
+ }
+
+ $zone = Zone::find($id);
+
+ if (!$zone) {
+ Alert::toast("Invalid Zone", 'warning');
+ return redirect()->route('acp');
+ }
+
+ return view('acp.zone.edit', [
+ 'zone' => $zone,
+ ]);
+ }
+
+ public function update(Request $request, $id)
+ {
+ if (Gate::denies('manage-game-elements')) {
+ Alert::toast('Permission Denied', 'warning');
+ return redirect('/');
+ }
+
+ $zone = Zone::find($id);
+
+ if (!$zone) {
+ Alert::toast("Invalid Zone", 'warning');
+ return redirect()->route('acp');
+ }
+
+ $this->validate($request, [
+ 'distance' => 'required|integer',
+ ]);
+
+ $zone->distance = $request->distance;
+
+ $zone->save();
+
+ return redirect()->route('acp-star-type', $zone->star_type->id);
+ }
+
+ public function show($id)
+ {
+ if (Gate::denies('manage-game-elements')) {
+ Alert::toast('Permission Denied', 'warning');
+ return redirect('/');
+ }
+
+ $zone = Zone::find($id);
+
+ if (!$zone) {
+ Alert::toast("Invalid Zone", 'warning');
+ return redirect()->route('acp');
+ }
+
+ $zone->probability = 0;
+ foreach ($zone->planet_types as $planet) {
+ $zone->probability = $zone->probability + $planet->pivot->probability;
+ }
+
+ return view('acp.zone.show', [
+ 'zone' => $zone,
+ ]);
+ }
+
+ public function addPlanet($id)
+ {
+ if (Gate::denies('manage-game-elements')) {
+ Alert::toast('Permission Denied', 'warning');
+ return redirect('/');
+ }
+
+ $zone = Zone::find($id);
+
+ if (!$zone) {
+ Alert::toast("Invalid Zone", 'warning');
+ return redirect()->route('acp');
+ }
+
+ $planets = PlanetType::all();
+
+ return view('acp.zone.addplanet', [
+ 'zone' => $zone,
+ 'planets' => $planets,
+ ]);
+ }
+
+ public function storePlanet(Request $request, $id)
+ {
+ if (Gate::denies('manage-game-elements')) {
+ Alert::toast('Permission Denied', 'warning');
+ return redirect('/');
+ }
+
+ $zone = Zone::find($id);
+
+ if (!$zone) {
+ Alert::toast("Invalid Zone", 'warning');
+ return redirect()->route('acp');
+ }
+
+ $this->validate($request, [
+ 'planet' => 'required|integer',
+ 'probability' => 'required|integer',
+ ]);
+
+ $zone->planet_types()->attach($request->planet, ['probability' => $request->probability]);
+
+ Alert::toast("Planet Type Added", 'success');
+
+ return redirect()->route('zone-show', $zone->id);
+ }
+
+ public function deletePlanet($id, $planet_id)
+ {
+ if (Gate::denies('manage-game-elements')) {
+ Alert::toast('Permission Denied', 'warning');
+ return redirect('/');
+ }
+
+ DB::table('planet_type_zone')->where('zone_id', '=', $id)->where('planet_type_id', '=', $planet_id)->limit(1)->delete();
+
+ Alert::toast('Planet Type Deleted From Zone', 'success');
+
+ return redirect()->route('zone-show', $id);
+ }
+}
diff --git a/app/PlanetType.php b/app/PlanetType.php
index ac328b9..659ca1c 100644
--- a/app/PlanetType.php
+++ b/app/PlanetType.php
@@ -6,5 +6,8 @@
class PlanetType extends Model
{
- //
+ public function zones()
+ {
+ return $this->belongsToMany('App\Zone')->withPivot('probability');
+ }
}
diff --git a/app/StarType.php b/app/StarType.php
index 8bc29b6..33e99a2 100644
--- a/app/StarType.php
+++ b/app/StarType.php
@@ -6,5 +6,8 @@
class StarType extends Model
{
- //
+ public function zones()
+ {
+ return $this->hasMany('App\Zone');
+ }
}
diff --git a/app/Zone.php b/app/Zone.php
new file mode 100644
index 0000000..3759ea9
--- /dev/null
+++ b/app/Zone.php
@@ -0,0 +1,18 @@
+belongsTo('App\StarType');
+ }
+
+ public function planet_types()
+ {
+ return $this->belongsToMany('App\PlanetType')->withPivot('probability');
+ }
+}
diff --git a/database/migrations/2020_01_12_221235_create_star_types_table.php b/database/migrations/2020_01_12_221235_create_star_types_table.php
index 66cc4c8..a5585a9 100644
--- a/database/migrations/2020_01_12_221235_create_star_types_table.php
+++ b/database/migrations/2020_01_12_221235_create_star_types_table.php
@@ -15,7 +15,7 @@ public function up()
{
Schema::create('star_types', function (Blueprint $table) {
$table->bigIncrements('id');
- $table->string('type', 32);
+ $table->string('name', 32);
$table->bigInteger('diameter');
$table->string('color', 20);
$table->tinyInteger('probability');
diff --git a/database/migrations/2020_02_07_231314_populate_star_types.php b/database/migrations/2020_02_07_231314_populate_star_types.php
index 6eae2b7..e108aa0 100644
--- a/database/migrations/2020_02_07_231314_populate_star_types.php
+++ b/database/migrations/2020_02_07_231314_populate_star_types.php
@@ -14,15 +14,15 @@ class PopulateStarTypes extends Migration
public function up()
{
DB::table('star_types')->insert([
- ['type' => 'Red drawf', 'diameter' => "13000", 'color' => 'red', 'probability' => "30"],
- ['type' => 'Orange drawf', 'diameter' => "45000", 'color' => 'Orange', 'probability' => "23"],
- ['type' => 'Yellow drawf', 'diameter' => "157000", 'color' => 'yellow', 'probability' => "17"],
- ['type' => 'Sun', 'diameter' => "864000", 'color' => 'white', 'probability' => "10"],
- ['type' => 'Blue Giant', 'diameter' => "3020000", 'color' => 'blue', 'probability' => "8"],
- ['type' => 'Orange Giant', 'diameter' => "25500000", 'color' => 'orange', 'probability' => "6"],
- ['type' => 'Red Giant', 'diameter' => "61500000", 'color' => 'red', 'probability' => "3"],
- ['type' => 'Red Supergiant', 'diameter' => "315000000", 'color' => 'red', 'probability' => "2"],
- ['type' => 'Neutron Star', 'diameter' => "10", 'color' => 'white', 'probability' => "1"],
+ ['name' => 'Red Dwarf', 'diameter' => "13000", 'color' => 'red', 'probability' => "30"],
+ ['name' => 'Orange Dwarf', 'diameter' => "45000", 'color' => 'Orange', 'probability' => "23"],
+ ['name' => 'Yellow Dwarf', 'diameter' => "157000", 'color' => 'yellow', 'probability' => "17"],
+ ['name' => 'Sun', 'diameter' => "864000", 'color' => 'white', 'probability' => "10"],
+ ['name' => 'Blue Giant', 'diameter' => "3020000", 'color' => 'blue', 'probability' => "8"],
+ ['name' => 'Orange Giant', 'diameter' => "25500000", 'color' => 'orange', 'probability' => "6"],
+ ['name' => 'Red Giant', 'diameter' => "61500000", 'color' => 'red', 'probability' => "3"],
+ ['name' => 'Red Supergiant', 'diameter' => "315000000", 'color' => 'red', 'probability' => "2"],
+ ['name' => 'Neutron Star', 'diameter' => "10", 'color' => 'white', 'probability' => "1"],
]);
}
diff --git a/database/migrations/2020_03_28_220958_create_zones_table.php b/database/migrations/2020_03_28_220958_create_zones_table.php
new file mode 100644
index 0000000..511ae8f
--- /dev/null
+++ b/database/migrations/2020_03_28_220958_create_zones_table.php
@@ -0,0 +1,34 @@
+bigIncrements('id');
+ $table->bigInteger('star_type_id');
+ $table->tinyInteger('order');
+ $table->smallInteger('distance');
+ $table->timestamps();
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::dropIfExists('zones');
+ }
+}
diff --git a/database/migrations/2020_03_28_221944_create_planet_type_zone_table.php b/database/migrations/2020_03_28_221944_create_planet_type_zone_table.php
new file mode 100644
index 0000000..611e026
--- /dev/null
+++ b/database/migrations/2020_03_28_221944_create_planet_type_zone_table.php
@@ -0,0 +1,33 @@
+bigInteger('zone_id');
+ $table->bigInteger('planet_type_id');
+ $table->tinyInteger('probability');
+ $table->timestamps();
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::dropIfExists('planet_type_zone');
+ }
+}
diff --git a/public/css/app.css b/public/css/app.css
index b564cb8..1e8fbd5 100644
--- a/public/css/app.css
+++ b/public/css/app.css
@@ -11460,8 +11460,6 @@ a:hover {
border-bottom-left-radius: 0.25rem;
border-top-left-radius: 0.5rem;
border-top-right-radius: 0.5rem;
- margin-top: auto;
- margin-bottom: auto;
color: #f7fafc;
}
@@ -11472,8 +11470,6 @@ a:hover {
border-top-left-radius: 0.25rem;
border-top-right-radius: 0.25rem;
width: 100%;
- margin-top: auto;
- margin-bottom: auto;
text-align: center;
}
diff --git a/resources/lang/en/common.php b/resources/lang/en/common.php
index 34632c2..86021e6 100644
--- a/resources/lang/en/common.php
+++ b/resources/lang/en/common.php
@@ -11,4 +11,7 @@
'ore' => 'Titanium',
'gas' => 'Rocket Fuel',
+
+ 'ore_adv' => 'Mathium',
+ 'gas_adv' => 'Hyper Fuel',
];
\ No newline at end of file
diff --git a/resources/sass/app.scss b/resources/sass/app.scss
index 3aefb41..664c758 100644
--- a/resources/sass/app.scss
+++ b/resources/sass/app.scss
@@ -36,11 +36,11 @@ a:hover {
}
.card {
- @apply bg-gray-800 rounded-b rounded-t-lg my-auto text-gray-100;
+ @apply bg-gray-800 rounded-b rounded-t-lg text-gray-100;
}
.card-header {
- @apply bg-gray-300 text-blue-400 shadow-lg rounded-t w-full my-auto text-center;
+ @apply bg-gray-300 text-blue-400 shadow-lg rounded-t w-full text-center;
}
.card-body {
diff --git a/resources/views/acp/index.blade.php b/resources/views/acp/index.blade.php
index aa11211..a82edcd 100644
--- a/resources/views/acp/index.blade.php
+++ b/resources/views/acp/index.blade.php
@@ -30,8 +30,8 @@
diff --git a/resources/views/acp/zone/add.blade.php b/resources/views/acp/zone/add.blade.php
new file mode 100644
index 0000000..6ad7c3f
--- /dev/null
+++ b/resources/views/acp/zone/add.blade.php
@@ -0,0 +1,26 @@
+@extends('site.layout')
+
+@section('body')
+
+@endsection
\ No newline at end of file
diff --git a/resources/views/acp/zone/addPlanet.blade.php b/resources/views/acp/zone/addPlanet.blade.php
new file mode 100644
index 0000000..ca761ab
--- /dev/null
+++ b/resources/views/acp/zone/addPlanet.blade.php
@@ -0,0 +1,41 @@
+@extends('site.layout')
+
+@section('body')
+
+
+
+
{{ $zone->star_type->name }} Zone {{ $zone->order }}
+
+
+
+@endsection
\ No newline at end of file
diff --git a/resources/views/acp/zone/edit.blade.php b/resources/views/acp/zone/edit.blade.php
new file mode 100644
index 0000000..df2fa81
--- /dev/null
+++ b/resources/views/acp/zone/edit.blade.php
@@ -0,0 +1,25 @@
+@extends('site.layout')
+
+@section('body')
+
+@endsection
\ No newline at end of file
diff --git a/resources/views/acp/zone/show.blade.php b/resources/views/acp/zone/show.blade.php
new file mode 100644
index 0000000..3c609d3
--- /dev/null
+++ b/resources/views/acp/zone/show.blade.php
@@ -0,0 +1,42 @@
+@extends('site.layout')
+
+@section('body')
+
+
+
+
+
+
+
+
Planet Type
+
Probability
+
Actions
+
+ @foreach ($zone->planet_types as $planet)
+
+
{{ $planet->type }}
+
{{ $planet->pivot->probability }}%
+
+
+ @endforeach
+
+
+
Total Probability
+
{{ $zone->probability }}%
+
+
+
+
+
+
+
+
+@endsection
\ No newline at end of file
diff --git a/resources/views/star-type/edit.blade.php b/resources/views/star-type/edit.blade.php
index eadff29..26f66a7 100644
--- a/resources/views/star-type/edit.blade.php
+++ b/resources/views/star-type/edit.blade.php
@@ -10,8 +10,8 @@
@csrf
- star type
-
+ Star Type Name
+
@error('name')
diff --git a/resources/views/star-type/index.blade.php b/resources/views/star-type/index.blade.php
index 3a37cda..748b107 100644
--- a/resources/views/star-type/index.blade.php
+++ b/resources/views/star-type/index.blade.php
@@ -15,7 +15,7 @@
@foreach ($stars as $star)
- {{ $star->type }}
+ {{ $star->name }}
Edit
@endforeach
diff --git a/resources/views/star-type/new.blade.php b/resources/views/star-type/new.blade.php
index f4e15d5..eb229c9 100644
--- a/resources/views/star-type/new.blade.php
+++ b/resources/views/star-type/new.blade.php
@@ -10,10 +10,10 @@
@csrf
- Star Type
-
+ Star Type Name
+
- @error('type')
+ @error('name')
{{ $message }}
diff --git a/resources/views/star-type/show.blade.php b/resources/views/star-type/show.blade.php
index b56f97b..12e2fa9 100644
--- a/resources/views/star-type/show.blade.php
+++ b/resources/views/star-type/show.blade.php
@@ -5,10 +5,10 @@
-
Name: {{ $star->type }}
+
Name: {{ $star->name }}
diameter: {{ $star->diameter}}
color: {{ $star->color}}
probobility: {{ $star->probability}}
@@ -23,5 +23,31 @@
Go Back
+
+
+
+
+
Zone Number
+
Miles From Star
+
Number of Planets
+
Edit
+
+ @foreach ($star->zones as $zone)
+
+
+
{{ $zone->distance }},000,000 Miles
+
{{ $zone->planet_types->count() }}
+
+
+ @endforeach
+
+
+
+
+
@endsection
diff --git a/routes/web.php b/routes/web.php
index 9ca01f3..debb9c5 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -81,6 +81,16 @@
Route::get('/acp/star/{id}/edit', 'StarTypeController@edit')->name('edit-star-type')->middleware('auth');
Route::post('/acp/star/{id}/edit', 'StarTypeController@update')->name('update-star-type')->middleware('auth');
+Route::get('/acp/star/{id}/add-zone', 'ZoneController@add')->name('zone-add')->middleware('auth');
+Route::post('/acp/star/{id}/add-zone', 'ZoneController@store')->name('zone-store')->middleware('auth');
+Route::get('/acp/edit-zone/{id}', 'ZoneController@edit')->name('zone-edit')->middleware('auth');
+Route::post('/acp/edit-zone/{id}', 'ZoneController@update')->name('zone-update')->middleware('auth');
+Route::get('/acp/zone/{id}', 'ZoneController@show')->name('zone-show')->middleware('auth');
+
+Route::get('/acp/zone/{id}/add-planet', 'ZoneController@addPlanet')->name('zone-planet-add')->middleware('auth');
+Route::post('/acp/zone/{id}/add-planet', 'ZoneController@storePlanet')->name('zone-planet-store')->middleware('auth');
+Route::get('/acp/zone/{id}/delete-planet/{planet_id}', 'ZoneController@deletePlanet')->name('zone-planet-delete')->middleware('auth');
+
Route::get('/acp/planets', 'PlanetTypeController@index')->name('all-planet-types')->middleware('auth');
Route::get('/acp/planet/new', 'PlanetTypeController@create')->name('create-planet-type')->middleware('auth');
Route::post('/acp/planet/new', 'PlanetTypeController@store')->name('store-planet-type')->middleware('auth');
From 64c920a9aef3818530176eb1353e5da758f28c53 Mon Sep 17 00:00:00 2001
From: Jon Zenor
Date: Fri, 3 Apr 2020 16:52:04 -0600
Subject: [PATCH 2/4] Closes #65 Contracts now expire and are shown on the main
planet page.
---
app/Console/Commands/ProcessContracts.php | 5 +++
app/Contract.php | 13 ++++++
app/Helpers/Formulas.php | 11 +++++
app/Http/Controllers/BaseController.php | 1 +
app/Http/Controllers/CharacterController.php | 4 +-
app/Http/Controllers/ContractController.php | 29 +++++++++++---
app/Http/Controllers/GameController.php | 12 +++++-
config/formulas.php | 3 ++
config/game.php | 2 +-
...9_225728_populate_facility_types_table.php | 10 ++++-
...20_01_28_002119_create_contracts_table.php | 1 +
resources/views/game/contract/new.blade.php | 20 +++++++++-
resources/views/game/facility/show.blade.php | 12 +++++-
resources/views/game/planet.blade.php | 40 ++++++++++++++++++-
14 files changed, 145 insertions(+), 18 deletions(-)
diff --git a/app/Console/Commands/ProcessContracts.php b/app/Console/Commands/ProcessContracts.php
index 82b9ec7..bd28709 100644
--- a/app/Console/Commands/ProcessContracts.php
+++ b/app/Console/Commands/ProcessContracts.php
@@ -91,6 +91,11 @@ public function handle()
$next = $now;
$contract->next_at = $next->addSeconds($contract->frequency);
+
+ if ($contract->expires_at < $now) {
+ $contract->status = "expired";
+ }
+
$contract->save();
}
}
diff --git a/app/Contract.php b/app/Contract.php
index 71af91d..cfad7f3 100644
--- a/app/Contract.php
+++ b/app/Contract.php
@@ -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');
+ }
+
}
diff --git a/app/Helpers/Formulas.php b/app/Helpers/Formulas.php
index 6c6cf70..5ba944c 100644
--- a/app/Helpers/Formulas.php
+++ b/app/Helpers/Formulas.php
@@ -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;
+ }
?>
diff --git a/app/Http/Controllers/BaseController.php b/app/Http/Controllers/BaseController.php
index 3a97b74..4906aed 100644
--- a/app/Http/Controllers/BaseController.php
+++ b/app/Http/Controllers/BaseController.php
@@ -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()
diff --git a/app/Http/Controllers/CharacterController.php b/app/Http/Controllers/CharacterController.php
index d0012d8..727cbb3 100644
--- a/app/Http/Controllers/CharacterController.php
+++ b/app/Http/Controllers/CharacterController.php
@@ -44,7 +44,7 @@ public function show($id)
}
- public function create () {
+ public function create() {
$user_id = Auth::id();
$character = Character::where("user_id", '=', $user_id)->get();
@@ -60,7 +60,7 @@ public function create () {
]);
}
- public function save (Request $request){
+ public function save(Request $request){
$this->validate($request, [
'name' => 'required|string|max:25',
diff --git a/app/Http/Controllers/ContractController.php b/app/Http/Controllers/ContractController.php
index dab408f..ed7cae1 100644
--- a/app/Http/Controllers/ContractController.php
+++ b/app/Http/Controllers/ContractController.php
@@ -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');
}
@@ -39,6 +41,7 @@ public function create($id)
$price['gas'] = materialSellPrice($facility->level, 'gas', 'contract');
$time = calculateContractTime();
$percent = calculateContractMaxSell();
+ $expire = calculateContractExpiration();
return view('game.contract.new', [
'loadCharacter' => $character,
@@ -46,6 +49,7 @@ public function create($id)
'price' => $price,
'time' => $time,
'percent' => $percent,
+ 'expire' => $expire,
]);
}
@@ -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") {
@@ -114,6 +122,7 @@ public function reviewContract(Request $request, $id)
'contract' => $request,
'production' => $production,
'storage' => $storage,
+ 'expire' => $expire,
]);
}
@@ -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") {
@@ -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";
@@ -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');
diff --git a/app/Http/Controllers/GameController.php b/app/Http/Controllers/GameController.php
index c13baf6..fb830c1 100644
--- a/app/Http/Controllers/GameController.php
+++ b/app/Http/Controllers/GameController.php
@@ -5,6 +5,8 @@
use Auth;
use App\Base;
use App\Character;
+use App\Contract;
+use App\Facility;
use Illuminate\Http\Request;
class GameController extends Controller
@@ -18,7 +20,8 @@ public function planet()
$planet = $character->planet;
$bases = Base::where('character_id', '=', $character->id)
- ->where('planet_id', '=', $planet->id)->get();
+ ->where('planet_id', '=', $planet->id)
+ ->orderBy('level')->get();
$planet->ore = 0;
$planet->gas = 0;
@@ -31,7 +34,12 @@ public function planet()
$base->maxStorage = array(
'ore' =>calculateMaxStorage($base->level, $base->bonus, 'ore'),
- 'gas' =>calculateMaxStorage($base->level, $base->bonus, 'gas'));
+ 'gas' =>calculateMaxStorage($base->level, $base->bonus, 'gas')
+ );
+
+ $admin = Facility::where('base_id', '=', $base->id)->where('facility_type_id', '=', 3)->first();
+
+ $base->hasAdmin = ($admin->count()) ? $admin : 0;
}
return view('game.planet', [
diff --git a/config/formulas.php b/config/formulas.php
index be2a6e6..a2df324 100644
--- a/config/formulas.php
+++ b/config/formulas.php
@@ -46,4 +46,7 @@
'base_storage_gas' => 75,
'exponent_storage_gas' => 2,
+
+ 'contract_base_expiration_days' => env('CONTRACT_EXPIRATION_DAYS', 1),
+ 'contract_increase_expiration_days' => env('CONTRACT_EXPIRATION_INCREASE', 2),
];
\ No newline at end of file
diff --git a/config/game.php b/config/game.php
index 9103f9d..dc61183 100644
--- a/config/game.php
+++ b/config/game.php
@@ -15,5 +15,5 @@
'ore_value_reduction' => 0.4,
'gas_value_reduction' => 0.2,
- 'contract_base_rate' => 25,
+ 'contract_base_rate' => env('BASE_CONTRACT_RATE', 20),
];
diff --git a/database/migrations/2020_01_19_225728_populate_facility_types_table.php b/database/migrations/2020_01_19_225728_populate_facility_types_table.php
index 5eeeb89..61b7d82 100644
--- a/database/migrations/2020_01_19_225728_populate_facility_types_table.php
+++ b/database/migrations/2020_01_19_225728_populate_facility_types_table.php
@@ -22,11 +22,15 @@ public function up()
]);
DB::table('facility_types')->insert([
- ['name' => 'Administration', 'required_level' => 3, 'type' => 'admin'],
+ ['name' => 'Administration', 'required_level' => 3, 'type' => 'admin', 'material' => 'contract'],
]);
DB::table('facility_types')->insert([
- ['name' => 'Star Port', 'required_level' => 3, 'type' => 'Factory', 'material' => 'ship'],
+ ['name' => 'Star Port', 'required_level' => 3, 'type' => 'admin', 'material' => 'research'],
+ ]);
+
+ DB::table('facility_types')->insert([
+ ['name' => 'Factory', 'required_level' => 4, 'type' => 'factory', 'material' => 'material'],
]);
}
@@ -41,5 +45,7 @@ public function down()
DB::table('facility_types')->where('name', '=', 'Titanium Mine')->delete();
DB::table('facility_types')->where('name', '=', 'Gas Mine')->delete();
DB::table('facility_types')->where('name', '=', 'Administration')->delete();
+ DB::table('facility_types')->where('name', '=', 'Star Port')->delete();
+ DB::table('facility_types')->where('name', '=', 'Factory')->delete();
}
}
diff --git a/database/migrations/2020_01_28_002119_create_contracts_table.php b/database/migrations/2020_01_28_002119_create_contracts_table.php
index 1544f4d..57b6ed4 100644
--- a/database/migrations/2020_01_28_002119_create_contracts_table.php
+++ b/database/migrations/2020_01_28_002119_create_contracts_table.php
@@ -22,6 +22,7 @@ public function up()
$table->decimal('price', 8, 2);
$table->smallInteger('frequency');
$table->smallInteger('time');
+ $table->dateTime('expires_at');
$table->string('status', 32);
$table->dateTime('next_at');
$table->timestamps();
diff --git a/resources/views/game/contract/new.blade.php b/resources/views/game/contract/new.blade.php
index 275e7cc..963e05a 100644
--- a/resources/views/game/contract/new.blade.php
+++ b/resources/views/game/contract/new.blade.php
@@ -10,7 +10,7 @@
Contract Details
- Sell {{ $percent[$contract->amount] }}% of your available {{ __('common.' . $contract->resource) }} every {{ $time[$contract->frequency] }} minutes? This contract will cost a one time setup fee of {{ __('common.money symbol') }}{{ ($contract->frequency + $contract->amount) * config('game.contract_base_rate') }} .
+ Sell {{ $percent[$contract->amount] }}% of your available {{ __('common.' . $contract->resource) }} every {{ $time[$contract->frequency] }} minutes? This contract will cost a one time setup fee of {{ __('common.money symbol') }}{{ ($contract->frequency + $contract->amount + $contract->length) * config('game.contract_base_rate') }} and will last for {{ $expire[$contract->length] }} Days .
Estimated Income
@@ -25,6 +25,7 @@
+
@@ -45,7 +46,7 @@
- The cost of this will be {{ __('common.money symbol') }}{{ config('game.contract_base_rate') }} x total level of selected options. This cost is a one time fee to establish the contract.
+ The cost of this will be {{ __('common.money symbol') }}{{ config('game.contract_base_rate') }} x total LEVEL of selected options. This cost is a one time fee to establish the contract.
@@ -58,6 +59,7 @@
Resource
Amount
Frequency
+ Length
@@ -83,6 +85,14 @@
@endfor
+
+
+ Select Length
+ @for ($i = 1; $i <= $maxLevel; $i++)
+ LVL {{ $i }} = {{ $expire[$i] }} Days
+ @endfor
+
+
@@ -101,6 +111,12 @@
{{ $message }}
@enderror
+ @error('length')
+
+ {{ $message }}
+
+ @enderror
+
diff --git a/resources/views/game/facility/show.blade.php b/resources/views/game/facility/show.blade.php
index d1d4ccc..1e997e7 100644
--- a/resources/views/game/facility/show.blade.php
+++ b/resources/views/game/facility/show.blade.php
@@ -35,6 +35,7 @@
Frequency
Next Action
+
@foreach ($facility->base->contracts as $contract)
{{ $contract->action }}
@@ -42,13 +43,20 @@
{{ __('common.money symbol') }}{{ $contract->price }}
{{ $contract->amount }}%
{{ ($contract->frequency/60) }}m
- {{ $contract->next_at }}
+
+ @if ($contract->status == "active")
+ {{ $contract->next_at }}
+
+ @else
+ {{ ucfirst($contract->status) }}
+ @endif
+
@endforeach
- @if ($facility->base->contracts->count() < $facility->level)
+ @if ($activeContracts < $facility->level)
diff --git a/resources/views/game/planet.blade.php b/resources/views/game/planet.blade.php
index bd33fdc..c60a9ba 100644
--- a/resources/views/game/planet.blade.php
+++ b/resources/views/game/planet.blade.php
@@ -43,7 +43,45 @@
@if ($base->status != "constructing")
Level: {{ $base->level }}
-
Contracts: {{ $base->contracts->count() }}
+
+ @if ($base->contracts->count())
+
Active Contracts
+
+
+ Type
+ Resource
+ Price
+ Amount
+ Frequency
+ Next Action
+ Expires
+
+
+
+ @foreach ($base->contracts as $contract)
+ @if ($contract->status == "active")
+
+
+
+ {{ ucfirst($contract->action) }}
+ {{ __('common.' . $contract->resource) }}
+ {{ __('common.money symbol') }}{{ $contract->price }}
+ {{ $contract->amount }}%
+ {{ ($contract->frequency/60) }}m
+ {{ $contract->next_at }}
+ {{ $contract->expires_at }}
+
+ @endif
+ @endforeach
+
+
+ @endif
+
+ @if ($base->hasAdmin && $base->hasAdmin->level > $activeCount)
+
+ @endif
From e416a88375f9e36f2a153fe26cc5c91a6eeb3726 Mon Sep 17 00:00:00 2001
From: Jon Zenor
Date: Fri, 3 Apr 2020 20:10:42 -0600
Subject: [PATCH 3/4] #71 Ship plans are listed but nothing happens with them
yet. Need research points, and research cost for the plans, and a way to
actually learn this. Also, I need to change the plans database to add the
cost.
---
app/Character.php | 5 ++
app/Console/Commands/ProcessContracts.php | 2 +-
app/Http/Controllers/CharacterController.php | 8 ++++
app/Http/Controllers/FacilityController.php | 23 ++++++++++
app/Http/Controllers/GameController.php | 2 +-
app/Plan.php | 13 ++++++
config/formulas.php | 6 +--
..._19_225534_create_facility_types_table.php | 1 +
...9_225728_populate_facility_types_table.php | 24 +++-------
...20_01_28_002119_create_contracts_table.php | 2 +-
...020_03_28_164751_populate_planet_types.php | 12 ++++-
.../2020_04_03_230503_create_plans_table.php | 36 +++++++++++++++
...2020_04_03_230727_populate_plans_table.php | 46 +++++++++++++++++++
...04_000713_create_character_plans_table.php | 32 +++++++++++++
resources/views/game/facility/new.blade.php | 4 +-
resources/views/game/facility/show.blade.php | 30 ++++++++----
16 files changed, 212 insertions(+), 34 deletions(-)
create mode 100644 app/Plan.php
create mode 100644 database/migrations/2020_04_03_230503_create_plans_table.php
create mode 100644 database/migrations/2020_04_03_230727_populate_plans_table.php
create mode 100644 database/migrations/2020_04_04_000713_create_character_plans_table.php
diff --git a/app/Character.php b/app/Character.php
index 0a36f17..1475039 100644
--- a/app/Character.php
+++ b/app/Character.php
@@ -30,4 +30,9 @@ public function actions()
{
return $this->hasMany('App\Action');
}
+
+ public function plans()
+ {
+ return $this->belongsToMany('App\Plan');
+ }
}
diff --git a/app/Console/Commands/ProcessContracts.php b/app/Console/Commands/ProcessContracts.php
index bd28709..00a1c48 100644
--- a/app/Console/Commands/ProcessContracts.php
+++ b/app/Console/Commands/ProcessContracts.php
@@ -92,7 +92,7 @@ public function handle()
$next = $now;
$contract->next_at = $next->addSeconds($contract->frequency);
- if ($contract->expires_at < $now) {
+ if ($contract->getOriginal('expires_at') < $now) {
$contract->status = "expired";
}
diff --git a/app/Http/Controllers/CharacterController.php b/app/Http/Controllers/CharacterController.php
index 727cbb3..90370f3 100644
--- a/app/Http/Controllers/CharacterController.php
+++ b/app/Http/Controllers/CharacterController.php
@@ -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;
@@ -78,6 +79,13 @@ public function save(Request $request){
$character->save();
+
+ $plans = Plan::where('learn_from', '=', 'default')->get();
+
+ foreach($plans as $plan) {
+ $character->plans()->attach($plan->id);
+ }
+
return redirect()->route('home');
}
diff --git a/app/Http/Controllers/FacilityController.php b/app/Http/Controllers/FacilityController.php
index 7ce3e93..90bcb54 100644
--- a/app/Http/Controllers/FacilityController.php
+++ b/app/Http/Controllers/FacilityController.php
@@ -8,7 +8,9 @@
use App\Facility;
use App\Character;
use App\FacilityType;
+use App\Plan;
use Illuminate\Http\Request;
+use Illuminate\Support\Facades\DB;
class FacilityController extends Controller
{
@@ -44,9 +46,16 @@ public function create($id)
return redirect()->route('visit-planet');
}
+ $learned = array();
+
+ foreach ($character->plans as $plan) {
+ $learned[$plan->name] = true;
+ }
+
$facilities = FacilityType::where('required_level', '<=', $base->level)->get();
foreach ($facilities as $facility) {
$facility->cost = facilityUpgradeCost( $facility->required_level );
+ $facility->learned = (array_key_exists($facility->required_plan, $learned)) ? true : false;
}
return view('game.facility.new', [
@@ -80,6 +89,12 @@ public function store($id, $build)
return redirect()->route('visit-planet');
}
+ $learned = array();
+
+ foreach ($character->plans as $plan) {
+ $learned[$plan->name] = true;
+ }
+
$facilityType = FacilityType::find($build);
// Make sure the user can create this facility here
@@ -88,6 +103,11 @@ public function store($id, $build)
return redirect()->route('visit-planet');
}
+ if (!array_key_exists($facilityType->required_plan, $learned)) {
+ Alert::toast('You have not yet leraned how to construct this facility', 'warning');
+ return redirect()->route('visit-planet');
+ }
+
$cost = facilityUpgradeCost( $facilityType->required_level );
if ($character->money < $cost['money']) {
@@ -166,9 +186,12 @@ public function show($id)
$facility->miningSpeed = calculateMiningSpeed($facility->level, $facility->bonus, $facility->facility_type->material, 1);
$facility->upgradeCost = facilityUpgradeCost($facility->level + $facility->facility_type->required_level);
+ $plans = Plan::where('learn_from', '=', $facility->facility_type->type)->where('level_required', '<=', $facility->level)->get();
+
return view('game.facility.show', [
'facility' => $facility,
'loadCharacter' => $character,
+ 'plans' => $plans,
]);
}
diff --git a/app/Http/Controllers/GameController.php b/app/Http/Controllers/GameController.php
index fb830c1..81b57b5 100644
--- a/app/Http/Controllers/GameController.php
+++ b/app/Http/Controllers/GameController.php
@@ -39,7 +39,7 @@ public function planet()
$admin = Facility::where('base_id', '=', $base->id)->where('facility_type_id', '=', 3)->first();
- $base->hasAdmin = ($admin->count()) ? $admin : 0;
+ $base->hasAdmin = ($admin) ? $admin : 0;
}
return view('game.planet', [
diff --git a/app/Plan.php b/app/Plan.php
new file mode 100644
index 0000000..9add5e0
--- /dev/null
+++ b/app/Plan.php
@@ -0,0 +1,13 @@
+belongsToMany('App\Character');
+ }
+}
diff --git a/config/formulas.php b/config/formulas.php
index a2df324..7d3fde9 100644
--- a/config/formulas.php
+++ b/config/formulas.php
@@ -9,12 +9,12 @@
'bases_ore_lvl_mod' => -1,
'bases_ore_exponent' => 2,
- 'bases_ore_multiplier' => 50,
+ 'bases_ore_multiplier' => 30,
'bases_ore_addition' => 0,
'bases_gas_lvl_mod' => -2,
'bases_gas_exponent' => 1.75,
- 'bases_gas_multiplier' => 25,
+ 'bases_gas_multiplier' => 20,
'bases_gas_addition' => 0,
@@ -40,7 +40,7 @@
'mining_gas_multiplier' => env('MINING_ORE_MULTIPLIER', 60),
'mining_gas_addition' => 40,
- // Level ^ (exponent_storage + bonus) * base_storage
+ // Base storage limit == Level ^ (exponent_storage + bonus) * base_storage
'base_storage_ore' => 100,
'exponent_storage_ore' => 2,
diff --git a/database/migrations/2020_01_19_225534_create_facility_types_table.php b/database/migrations/2020_01_19_225534_create_facility_types_table.php
index 615aacb..f1b29c2 100644
--- a/database/migrations/2020_01_19_225534_create_facility_types_table.php
+++ b/database/migrations/2020_01_19_225534_create_facility_types_table.php
@@ -19,6 +19,7 @@ public function up()
$table->integer('required_level');
$table->string('type', 32);
$table->string('material', 32)->nullable();
+ $table->string('required_plan');
$table->timestamps();
});
}
diff --git a/database/migrations/2020_01_19_225728_populate_facility_types_table.php b/database/migrations/2020_01_19_225728_populate_facility_types_table.php
index 61b7d82..5fa2b9b 100644
--- a/database/migrations/2020_01_19_225728_populate_facility_types_table.php
+++ b/database/migrations/2020_01_19_225728_populate_facility_types_table.php
@@ -14,23 +14,12 @@ class PopulateFacilityTypesTable extends Migration
public function up()
{
DB::table('facility_types')->insert([
- ['name' => 'Titanium Mine', 'required_level' => 1, 'type' => 'mine', 'material' => 'ore'],
- ]);
-
- DB::table('facility_types')->insert([
- ['name' => 'Gas Mine', 'required_level' => 2, 'type' => 'mine', 'material' => 'gas'],
- ]);
-
- DB::table('facility_types')->insert([
- ['name' => 'Administration', 'required_level' => 3, 'type' => 'admin', 'material' => 'contract'],
- ]);
-
- DB::table('facility_types')->insert([
- ['name' => 'Star Port', 'required_level' => 3, 'type' => 'admin', 'material' => 'research'],
- ]);
-
- DB::table('facility_types')->insert([
- ['name' => 'Factory', 'required_level' => 4, 'type' => 'factory', 'material' => 'material'],
+ ['name' => 'Titanium Mine', 'required_level' => 1, 'type' => 'mine', 'material' => 'ore', 'required_plan' => 'Ore Mine'],
+ ['name' => 'Gas Mine', 'required_level' => 2, 'type' => 'mine', 'material' => 'gas', 'required_plan' => 'Gas Mine'],
+ ['name' => 'Administration', 'required_level' => 3, 'type' => 'admin', 'material' => 'contract', 'required_plan' => 'Admin Office'],
+ ['name' => 'Star Port', 'required_level' => 3, 'type' => 'starport', 'material' => 'research', 'required_plan' => 'Starport'],
+ ['name' => 'University', 'required_level' => 3, 'type' => 'admin', 'material' => 'research', 'required_plan' => 'University'],
+ ['name' => 'Factory', 'required_level' => 4, 'type' => 'factory', 'material' => 'material', 'required_plan' => 'Factory'],
]);
}
@@ -46,6 +35,7 @@ public function down()
DB::table('facility_types')->where('name', '=', 'Gas Mine')->delete();
DB::table('facility_types')->where('name', '=', 'Administration')->delete();
DB::table('facility_types')->where('name', '=', 'Star Port')->delete();
+ DB::table('facility_types')->where('name', '=', 'University')->delete();
DB::table('facility_types')->where('name', '=', 'Factory')->delete();
}
}
diff --git a/database/migrations/2020_01_28_002119_create_contracts_table.php b/database/migrations/2020_01_28_002119_create_contracts_table.php
index 57b6ed4..781e2d6 100644
--- a/database/migrations/2020_01_28_002119_create_contracts_table.php
+++ b/database/migrations/2020_01_28_002119_create_contracts_table.php
@@ -22,8 +22,8 @@ public function up()
$table->decimal('price', 8, 2);
$table->smallInteger('frequency');
$table->smallInteger('time');
- $table->dateTime('expires_at');
$table->string('status', 32);
+ $table->dateTime('expires_at');
$table->dateTime('next_at');
$table->timestamps();
});
diff --git a/database/migrations/2020_03_28_164751_populate_planet_types.php b/database/migrations/2020_03_28_164751_populate_planet_types.php
index 578748d..9be13bf 100644
--- a/database/migrations/2020_03_28_164751_populate_planet_types.php
+++ b/database/migrations/2020_03_28_164751_populate_planet_types.php
@@ -35,6 +35,16 @@ public function up()
*/
public function down()
{
- //
+ DB::table('planet_types')->where('type', '=', 'Earth like')->delete();
+ DB::table('planet_types')->where('type', '=', 'hemi earth')->delete();
+ DB::table('planet_types')->where('type', '=', 'rocky planet')->delete();
+ DB::table('planet_types')->where('type', '=', 'ice planet')->delete();
+ DB::table('planet_types')->where('type', '=', 'astroid belts')->delete();
+ DB::table('planet_types')->where('type', '=', 'melting planet')->delete();
+ DB::table('planet_types')->where('type', '=', 'thick atmishere')->delete();
+ DB::table('planet_types')->where('type', '=', 'ice giant')->delete();
+ DB::table('planet_types')->where('type', '=', 'gas giant')->delete();
+ DB::table('planet_types')->where('type', '=', 'brown drawf')->delete();
+ DB::table('planet_types')->where('type', '=', 'kiper belt')->delete();
}
}
diff --git a/database/migrations/2020_04_03_230503_create_plans_table.php b/database/migrations/2020_04_03_230503_create_plans_table.php
new file mode 100644
index 0000000..11eabf9
--- /dev/null
+++ b/database/migrations/2020_04_03_230503_create_plans_table.php
@@ -0,0 +1,36 @@
+bigIncrements('id');
+ $table->string('name');
+ $table->longText('description');
+ $table->string('learn_from');
+ $table->integer('level_required');
+ $table->string('type');
+ $table->timestamps();
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::dropIfExists('plans');
+ }
+}
diff --git a/database/migrations/2020_04_03_230727_populate_plans_table.php b/database/migrations/2020_04_03_230727_populate_plans_table.php
new file mode 100644
index 0000000..934f94e
--- /dev/null
+++ b/database/migrations/2020_04_03_230727_populate_plans_table.php
@@ -0,0 +1,46 @@
+insert([
+ ['name' => 'Gas Mine', 'learn_from' => 'default', 'level_required' => 0, 'type' => 'facility', 'description' => 'Allows the creation of Gas Mines'],
+ ['name' => 'Ore Mine', 'learn_from' => 'default', 'level_required' => 0, 'type' => 'facility', 'description' => 'Allows the creation of Ore Mines'],
+ ['name' => 'Factory', 'learn_from' => 'default', 'level_required' => 0, 'type' => 'facility', 'description' => 'Factories allow the creation of all kinds of items.'],
+ ['name' => 'Starport', 'learn_from' => 'default', 'level_required' => 0, 'type' => 'facility', 'description' => 'Starports allow you to store your ships while on planet and lets you research new ship designs.'],
+
+ ['name' => 'Admin Office', 'learn_from' => 'university', 'level_required' => 1, 'type' => 'facility', 'description' => 'Create and manage contracts to automatically sell your resources for Keplers.'],
+ ['name' => 'Advanced Ore Mine', 'learn_from' => 'university', 'level_required' => 2, 'type' => 'facility', 'description' => 'Allows the creation of Advanced Ore Mines'],
+ ['name' => 'Advanced Gas Mine', 'learn_from' => 'university', 'level_required' => 3, 'type' => 'facility', 'description' => 'Allows the creation of Advanced Gas Mines'],
+
+ ['name' => 'Basic Shuttle', 'learn_from' => 'starport', 'level_required' => 1, 'type' => 'ship', 'description' => 'Basic shuttle that is a great place to start to travel to other planets in the solar system.'],
+ ]);
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ DB::table('plans')->where('name', '=', 'Gas Mine')->delete();
+ DB::table('plans')->where('name', '=', 'Ore Mine')->delete();
+ DB::table('plans')->where('name', '=', 'Factory')->delete();
+ DB::table('plans')->where('name', '=', 'Starport')->delete();
+ DB::table('plans')->where('name', '=', 'Admin Office')->delete();
+ DB::table('plans')->where('name', '=', 'Advanced Ore Mine')->delete();
+ DB::table('plans')->where('name', '=', 'Advanced Gas Mine')->delete();
+ DB::table('plans')->where('name', '=', 'Basic Shuttle')->delete();
+ }
+}
diff --git a/database/migrations/2020_04_04_000713_create_character_plans_table.php b/database/migrations/2020_04_04_000713_create_character_plans_table.php
new file mode 100644
index 0000000..5793aa2
--- /dev/null
+++ b/database/migrations/2020_04_04_000713_create_character_plans_table.php
@@ -0,0 +1,32 @@
+bigInteger('character_id');
+ $table->bigInteger('plan_id');
+ $table->timestamps();
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::dropIfExists('character_plan');
+ }
+}
diff --git a/resources/views/game/facility/new.blade.php b/resources/views/game/facility/new.blade.php
index a705195..23b8a2f 100644
--- a/resources/views/game/facility/new.blade.php
+++ b/resources/views/game/facility/new.blade.php
@@ -55,8 +55,10 @@
@if ($base->level == 2 && $facility->name == "Titanium Mine")
Limit Reached
- @else
+ @elseif ($facility->learned)
Build
+ @else
+ Not Yet Learned
@endif
diff --git a/resources/views/game/facility/show.blade.php b/resources/views/game/facility/show.blade.php
index 1e997e7..77988a9 100644
--- a/resources/views/game/facility/show.blade.php
+++ b/resources/views/game/facility/show.blade.php
@@ -34,6 +34,7 @@
Amount
Frequency
Next Action
+ Expires
@foreach ($facility->base->contracts as $contract)
@@ -43,14 +44,15 @@
{{ __('common.money symbol') }}{{ $contract->price }}
{{ $contract->amount }}%
{{ ($contract->frequency/60) }}m
-
- @if ($contract->status == "active")
- {{ $contract->next_at }}
-
- @else
- {{ ucfirst($contract->status) }}
- @endif
-
+ @if ($contract->status == "active")
+
+
+ {{ $contract->next_at }}
+ {{ $contract->expires_at }}
+ @else
+ --
+ {{ ucfirst($contract->status) }}
+ @endif
@endforeach
@@ -64,8 +66,18 @@
@endif
-
+ @if ($facility->facility_type->type == "starport")
+
Research Starship Plans
+
+ @if ($plans)
+ @foreach ($plans as $plan)
+ {{ $plan->name }}
+ @endforeach
+ @endif
+ @endif
+
+
Upgrade Facility
@if ($facility->level < $facility->base->level && $facility->status == "completed")
From b56de2955d81c9c27cb13d2c1dd26d24a938e5e0 Mon Sep 17 00:00:00 2001
From: Jon Zenor
Date: Sat, 4 Apr 2020 15:41:08 -0600
Subject: [PATCH 4/4] #71 The starport can now start researching a design. I
still don't know how that research is going to work yet...
---
app/Console/Commands/ProcessResearch.php | 42 +++++++++++++
.../Commands/ProcessResearchPoints.php | 59 +++++++++++++++++++
app/Console/Kernel.php | 1 +
app/Http/Controllers/CharacterController.php | 2 +-
app/Http/Controllers/FacilityController.php | 34 +++++++++++
config/game.php | 3 +
...0_01_04_164111_create_characters_table.php | 1 +
...0_01_19_220838_create_facilities_table.php | 3 +
.../2020_04_03_230503_create_plans_table.php | 1 +
...2020_04_03_230727_populate_plans_table.php | 20 +++----
resources/views/game/facility/show.blade.php | 40 +++++++++++--
resources/views/site/layout.blade.php | 1 +
routes/web.php | 2 +
13 files changed, 193 insertions(+), 16 deletions(-)
create mode 100644 app/Console/Commands/ProcessResearch.php
create mode 100644 app/Console/Commands/ProcessResearchPoints.php
diff --git a/app/Console/Commands/ProcessResearch.php b/app/Console/Commands/ProcessResearch.php
new file mode 100644
index 0000000..48c7f4d
--- /dev/null
+++ b/app/Console/Commands/ProcessResearch.php
@@ -0,0 +1,42 @@
+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;
+ }
+ }
+}
diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php
index a2270d6..99836cd 100644
--- a/app/Console/Kernel.php
+++ b/app/Console/Kernel.php
@@ -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();
}
/**
diff --git a/app/Http/Controllers/CharacterController.php b/app/Http/Controllers/CharacterController.php
index 90370f3..4be4c5d 100644
--- a/app/Http/Controllers/CharacterController.php
+++ b/app/Http/Controllers/CharacterController.php
@@ -75,11 +75,11 @@ 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) {
diff --git a/app/Http/Controllers/FacilityController.php b/app/Http/Controllers/FacilityController.php
index 90bcb54..a3e07e1 100644
--- a/app/Http/Controllers/FacilityController.php
+++ b/app/Http/Controllers/FacilityController.php
@@ -9,6 +9,7 @@
use App\Character;
use App\FacilityType;
use App\Plan;
+use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
@@ -188,10 +189,13 @@ public function show($id)
$plans = Plan::where('learn_from', '=', $facility->facility_type->type)->where('level_required', '<=', $facility->level)->get();
+ $researching = ($facility->researching) ? Plan::find($facility->researching) : null;
+
return view('game.facility.show', [
'facility' => $facility,
'loadCharacter' => $character,
'plans' => $plans,
+ 'researching' => $researching,
]);
}
@@ -255,6 +259,36 @@ public function upgrade(Request $request, $id)
return redirect()->route('visit-planet');
}
+ public function research($id, $plan)
+ {
+ $research = Plan::find($plan);
+ $facility = Facility::find($id);
+
+ if (!$facility) {
+ Alert::toast('Facility Not Found', 'warning');
+ return redirect()->route('visit-planet');
+ }
+
+ $user_id = Auth::id();
+ $character = Character::where('user_id', '=', $user_id)->first();
+
+ if ($facility->base->character->id != $character->id) {
+ Alert::toast('This is not your base', 'warning');
+ return redirect()->route('visit-planet');
+ }
+
+ $now = Carbon::now();
+
+ $facility->researching = $research->id;
+ $facility->research_progress = 0;
+ $facility->researched_at = $now;
+ $facility->save();
+
+ Alert::toast("Research started");
+
+ return redirect()->route('show-facility', $facility->id);
+ }
+
/**
* Show the form for editing the specified resource.
*
diff --git a/config/game.php b/config/game.php
index dc61183..3da8cc7 100644
--- a/config/game.php
+++ b/config/game.php
@@ -3,7 +3,10 @@
return [
'map_size' => 5,
'starting_money' => 2000,
+ 'starting_research' => 0,
'max_bases_per_planet' => 1,
+
+ 'daily_research_points' => 10,
'cost_new_base' => 250,
diff --git a/database/migrations/2020_01_04_164111_create_characters_table.php b/database/migrations/2020_01_04_164111_create_characters_table.php
index 5ad11f4..51d002f 100644
--- a/database/migrations/2020_01_04_164111_create_characters_table.php
+++ b/database/migrations/2020_01_04_164111_create_characters_table.php
@@ -21,6 +21,7 @@ public function up()
$table->bigInteger('faction_id');
$table->integer('planet_id');
$table->integer('money');
+ $table->decimal('research_points', 12, 2);
$table->softDeletes();
$table->timestamps();
});
diff --git a/database/migrations/2020_01_19_220838_create_facilities_table.php b/database/migrations/2020_01_19_220838_create_facilities_table.php
index 3b15d0a..d4bbf8f 100644
--- a/database/migrations/2020_01_19_220838_create_facilities_table.php
+++ b/database/migrations/2020_01_19_220838_create_facilities_table.php
@@ -22,6 +22,9 @@ public function up()
$table->string('status', 32);
$table->dateTime('mined_at')->nullable();
$table->boolean('full')->default(0);
+ $table->bigInteger('researching')->nullable();
+ $table->decimal('research_progress', 8,2)->nullable();
+ $table->dateTime('researched_at')->nullable();
$table->timestamps();
});
}
diff --git a/database/migrations/2020_04_03_230503_create_plans_table.php b/database/migrations/2020_04_03_230503_create_plans_table.php
index 11eabf9..70fb8a5 100644
--- a/database/migrations/2020_04_03_230503_create_plans_table.php
+++ b/database/migrations/2020_04_03_230503_create_plans_table.php
@@ -19,6 +19,7 @@ public function up()
$table->longText('description');
$table->string('learn_from');
$table->integer('level_required');
+ $table->integer('research_points');
$table->string('type');
$table->timestamps();
});
diff --git a/database/migrations/2020_04_03_230727_populate_plans_table.php b/database/migrations/2020_04_03_230727_populate_plans_table.php
index 934f94e..d3269a0 100644
--- a/database/migrations/2020_04_03_230727_populate_plans_table.php
+++ b/database/migrations/2020_04_03_230727_populate_plans_table.php
@@ -14,16 +14,16 @@ class PopulatePlansTable extends Migration
public function up()
{
DB::table('plans')->insert([
- ['name' => 'Gas Mine', 'learn_from' => 'default', 'level_required' => 0, 'type' => 'facility', 'description' => 'Allows the creation of Gas Mines'],
- ['name' => 'Ore Mine', 'learn_from' => 'default', 'level_required' => 0, 'type' => 'facility', 'description' => 'Allows the creation of Ore Mines'],
- ['name' => 'Factory', 'learn_from' => 'default', 'level_required' => 0, 'type' => 'facility', 'description' => 'Factories allow the creation of all kinds of items.'],
- ['name' => 'Starport', 'learn_from' => 'default', 'level_required' => 0, 'type' => 'facility', 'description' => 'Starports allow you to store your ships while on planet and lets you research new ship designs.'],
-
- ['name' => 'Admin Office', 'learn_from' => 'university', 'level_required' => 1, 'type' => 'facility', 'description' => 'Create and manage contracts to automatically sell your resources for Keplers.'],
- ['name' => 'Advanced Ore Mine', 'learn_from' => 'university', 'level_required' => 2, 'type' => 'facility', 'description' => 'Allows the creation of Advanced Ore Mines'],
- ['name' => 'Advanced Gas Mine', 'learn_from' => 'university', 'level_required' => 3, 'type' => 'facility', 'description' => 'Allows the creation of Advanced Gas Mines'],
-
- ['name' => 'Basic Shuttle', 'learn_from' => 'starport', 'level_required' => 1, 'type' => 'ship', 'description' => 'Basic shuttle that is a great place to start to travel to other planets in the solar system.'],
+ ['name' => 'Gas Mine', 'learn_from' => 'default', 'level_required' => 0, 'type' => 'facility', 'research_points' => '0', 'description' => 'Allows the creation of Gas Mines'],
+ ['name' => 'Ore Mine', 'learn_from' => 'default', 'level_required' => 0, 'type' => 'facility', 'research_points' => '0', 'description' => 'Allows the creation of Ore Mines'],
+ ['name' => 'Factory', 'learn_from' => 'default', 'level_required' => 0, 'type' => 'facility', 'research_points' => '0', 'description' => 'Factories allow the creation of all kinds of items.'],
+ ['name' => 'Starport', 'learn_from' => 'default', 'level_required' => 0, 'type' => 'facility', 'research_points' => '0', 'description' => 'Starports allow you to store your ships while on planet and lets you research new ship designs.'],
+
+ ['name' => 'Admin Office', 'learn_from' => 'university', 'level_required' => 1, 'type' => 'facility', 'research_points' => '0', 'description' => 'Create and manage contracts to automatically sell your resources for Keplers.'],
+ ['name' => 'Advanced Ore Mine', 'learn_from' => 'university', 'level_required' => 2, 'type' => 'facility', 'research_points' => '0', 'description' => 'Allows the creation of Advanced Ore Mines'],
+ ['name' => 'Advanced Gas Mine', 'learn_from' => 'university', 'level_required' => 3, 'type' => 'facility', 'research_points' => '0', 'description' => 'Allows the creation of Advanced Gas Mines'],
+
+ ['name' => 'Basic Shuttle', 'learn_from' => 'starport', 'level_required' => 1, 'type' => 'ship', 'research_points' => '1', 'description' => 'Basic shuttle that is a great place to start to travel to other planets in the solar system.'],
]);
}
diff --git a/resources/views/game/facility/show.blade.php b/resources/views/game/facility/show.blade.php
index 77988a9..da41c9e 100644
--- a/resources/views/game/facility/show.blade.php
+++ b/resources/views/game/facility/show.blade.php
@@ -67,13 +67,43 @@
@endif
@if ($facility->facility_type->type == "starport")
+
+
Currently Researching:
+ @if($researching)
+ {{ $researching->name }}
+
Progress: {{ $facility->research_progress }} / {{ $researching->research_points }}
+ @else
+ No Current Research Projects
+ @endif
+
+
+
+
Research Starship Plans
- @if ($plans)
- @foreach ($plans as $plan)
- {{ $plan->name }}
- @endforeach
- @endif
+
+
+ Ship
+ Research Cost
+ Action
+
+
+ @if ($plans)
+ @foreach ($plans as $plan)
+
+ {{ $plan->name }}
+ {{ $plan->research_points }} Research Point
+
+ @if ($plan->id == $facility->researching)
+ Researching...
+ @else
+ Start Research
+ @endif
+
+
+ @endforeach
+ @endif
+
@endif
diff --git a/resources/views/site/layout.blade.php b/resources/views/site/layout.blade.php
index 5e93376..805f4fb 100644
--- a/resources/views/site/layout.blade.php
+++ b/resources/views/site/layout.blade.php
@@ -72,6 +72,7 @@
Species: {{ $character->species->name }}
{{ __('common.money') }}: {{ __('common.money symbol') }}{{ $character->money }}
+ Research Points: {{ $character->research_points }}
diff --git a/routes/web.php b/routes/web.php
index debb9c5..27ecad6 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -39,6 +39,8 @@
Route::post('/facility/{id}/contract', 'ContractController@reviewContract')->name('submit-contract')->middleware('auth');
Route::post('/facility/{id}/contract/confirm', 'ContractController@createContract')->name('confirm-contract')->middleware('auth');
+Route::get('/facility/{id}/research/{plan}', 'FacilityController@research')->name('research-plan')->middleware('auth');
+
Route::get('/base/{base}/sell/{material}', 'BaseController@sell')->name('sell-materials')->middleware('auth');
Route::post('/base/{base}/sell/{material}', 'BaseController@sellConfirm')->name('confirm-sell-materials')->middleware('auth');