Skip to content

Commit

Permalink
Merge 6e16840 into 58aeb0e
Browse files Browse the repository at this point in the history
  • Loading branch information
WaveHack committed Jun 9, 2019
2 parents 58aeb0e + 6e16840 commit a23e119
Show file tree
Hide file tree
Showing 13 changed files with 325 additions and 79 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddTargetRealmIdToInfoOpsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('info_ops', function (Blueprint $table) {
$table->unsignedInteger('target_realm_id')
->nullable()
->after('source_dominion_id');

$table->foreign('target_realm_id')->references('id')->on('realms');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('info_ops', function (Blueprint $table) {
$table->dropColumn('target_realm_id');
});
}
}
55 changes: 55 additions & 0 deletions app/resources/views/pages/dominion/op-center/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,61 @@
</table>
</div>
</div>

<div class="box box-primary">
<div class="box-header">
<h3 class="box-title">Clairvoyance Realms</h3>
</div>
<div class="box-body table-responsive">
<table class="table table-hover" id="dominions-table">
<colgroup>
<col>
<col>
<col width="200">
</colgroup>
<thead>
<tr>
<th>Realm</th>
<th>Target</th>
<th class="text-center">Taken</th>
</tr>
</thead>
<tbody>
@foreach ($clairvoyanceRealms as $realm)
@php
$lastInfoOp = $infoOpService->getLastClairvoyance($selectedDominion->realm, $realm);
@endphp
@if ($lastInfoOp->isInvalid())
@continue
@endif
<tr>
<td data-order="{{ $realm->number }}">
<a href="{{ route('dominion.op-center.clairvoyance', $realm->number) }}">{{ $realm->name }} (#{{ $realm->number }})</a>
</td>
<td data-order="{{ $lastInfoOp->targetDominion->name }}">
<a href="{{ route('dominion.op-center.show', $lastInfoOp->targetDominion) }}">{{ $lastInfoOp->targetDominion->name }}</a>
</td>
<td class="text-center" data-search="" data-order="{{ $lastInfoOp->updated_at->getTimestamp() }}">
Clairvoyance by
@if ($lastInfoOp->sourceDominion->id === $selectedDominion->id)
<strong>
{{ $selectedDominion->name }}
</strong>
@else
{{ $lastInfoOp->sourceDominion->name }}
@endif
<br>
<span class="small">
{{ $lastInfoOp->updated_at->diffForHumans() }}
</span>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>

</div>

<div class="col-sm-12 col-md-3">
Expand Down
35 changes: 35 additions & 0 deletions app/resources/views/pages/dominion/op-center/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,41 @@
@endif
@endcomponent
</div>
</div>

<div class="row">
<div class="col-sm-12 col-sm-6">
@component('partials.dominion.op-center.box')
@php
$infoOp = $infoOpService->getInfoOp($selectedDominion->realm, $dominion, 'clairvoyance');
@endphp

@slot('title', 'Town Crier')
@slot('titleIconClass', 'fa fa-newspaper-o')

@if ($infoOp === null)
<p>No recent data available.</p>
<p>Cast magic spell 'Clairvoyance' to reveal information.</p>
@else
<a href="{{ route('dominion.op-center.clairvoyance', $dominion->realm->id) }}">{{ $dominion->realm->name }} (#{{ $dominion->realm->number }})</a>
- <em>Revealed <abbr title="{{ $infoOp->updated_at }}">{{ $infoOp->updated_at->diffForHumans() }}</abbr> by {{ $infoOp->sourceDominion->name }}</em>
@if ($infoOp->isStale())
<span class="label label-warning">Stale</span>
@endif
@endif

@slot('boxFooter')
<div class="pull-right">
<form action="{{ route('dominion.magic') }}" method="post" role="form">
@csrf
<input type="hidden" name="target_dominion" value="{{ $dominion->id }}">
<input type="hidden" name="spell" value="clairvoyance">
<button type="submit" class="btn btn-sm btn-primary">Clairvoyance ({{ number_format($spellCalculator->getManaCost($selectedDominion, 'clairvoyance')) }} mana)</button>
</form>
</div>
@endslot
@endcomponent
</div>

</div>
@endsection
24 changes: 18 additions & 6 deletions app/resources/views/pages/dominion/town-crier.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

@section('content')
<div class="row">

<div class="col-sm-12 col-md-9">
<div class="box box-primary">
<div class="box-header with-border">
<h3 class="box-title"><i class="fa fa-newspaper-o"></i> Town Crier for {{ $realm->name }} (#{{ $realm->number }})</h3>
<h3 class="box-title">
<i class="fa fa-newspaper-o"></i> Town Crier for {{ $realm->name }} (#{{ $realm->number }})
</h3>
</div>

@if ($gameEvents->isEmpty())
Expand All @@ -17,7 +18,6 @@
</div>
@else
<div class="box-body table-responsive no-padding">

<table class="table table-striped">
<colgroup>
<col>
Expand Down Expand Up @@ -63,7 +63,11 @@
@endif
</td>
<td class="text-center">
<a href="{{ route('dominion.event', [$gameEvent->id]) }}">Link</a>
@if ($gameEvent->source->realm_id == $selectedDominion->realm->id)
<a href="{{ route('dominion.event', [$gameEvent->id]) }}">Link</a>
@else
--
@endif
</td>
<td class="text-center">
<span>{{ $gameEvent->created_at }}</span>
Expand All @@ -72,7 +76,11 @@
@endforeach
</tbody>
</table>

@if ($fromOpCenter)
<div class="box-footer">
<em>Revealed <abbr title="{{ $clairvoyanceInfoOp->updated_at }}">{{ $clairvoyanceInfoOp->updated_at->diffForHumans() }}</abbr> by {{ $clairvoyanceInfoOp->sourceDominion->name }}</em>
</div>
@endif
</div>
@endif
</div>
Expand All @@ -84,7 +92,11 @@
<h3 class="box-title">Information</h3>
</div>
<div class="box-body">
<p>All the news for your realm can be seen here. The town crier gives you news for a 2 day period.</p>
@if ($fromOpCenter)
<p>All the news for the target's realm will be shown here. The town crier presents news for a 2 day period.</p>
@else
<p>All the news for your realm can be seen here. The town crier gives you news for a 2 day period.</p>
@endif
<p>You will see only military operations, as well as death messages{{-- and important messages regarding Wonders of the World--}}. Magical and Spy attacks are not known to the Town Crier, and you will have to inquire in the council as to those types of attacks.</p>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions app/routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
// Op Center
$router->get('op-center')->uses('Dominion\OpCenterController@getIndex')->name('op-center');
$router->get('op-center/{dominion}')->uses('Dominion\OpCenterController@getDominion')->name('op-center.show');
$router->get('op-center/clairvoyance/{realmNumber}')->uses('Dominion\OpCenterController@getClairvoyance')->name('op-center.clairvoyance');

// Rankings
$router->get('rankings/{type?}')->uses('Dominion\RankingsController@getRankings')->name('rankings');
Expand Down
2 changes: 2 additions & 0 deletions src/Helpers/NotificationHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,8 @@ public function getIrregularTypes(): array
// Page: Town Crier
'Realmie invaded another dominion',
// Victorious on the battlefield, Priapus (# 16) conquered 64 land from Black Whirling (# 26).
'Dominion failed to invade realmie',
// Fellow dominion Jupiter (# 11) fended of an attack from Miss Piggy (# 31).
'Realmie failed to invade another dominion',
// Sadly, the forces of Starscream (# 31) were beaten back by Myself Yourself (# 44).
'A dominion invaded realmie',
Expand Down
16 changes: 8 additions & 8 deletions src/Helpers/SpellHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function getSelfSpells(Race $race): Collection
return $spell['races']->contains($raceName);
})->first();

return collect([
return collect(array_filter([
[
'name' => 'Gaia\'s Watch',
'description' => '+10% food production',
Expand Down Expand Up @@ -122,7 +122,7 @@ public function getSelfSpells(Race $race): Collection
// 'cooldown' => 22, // todo
// ],
$racialSpell
]);
]));
}

public function getRacialSelfSpells(): Collection
Expand Down Expand Up @@ -199,12 +199,12 @@ public function getInfoOpSpells(): Collection
'key' => 'revelation',
'mana_cost' => 1.2,
],
// [
// 'name' => 'Clairvoyance',
// 'description' => 'Reveal realm town crier',
// 'key' => 'clairvoyance',
// 'mana_cost' => 1.2,
// ],
[
'name' => 'Clairvoyance',
'description' => 'Reveal realm town crier',
'key' => 'clairvoyance',
'mana_cost' => 1.2,
],
// [
// 'name' => 'Disclosure',
// 'description' => 'Reveal wonder',
Expand Down
40 changes: 37 additions & 3 deletions src/Http/Controllers/Dominion/OpCenterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,28 @@
use OpenDominion\Helpers\SpellHelper;
use OpenDominion\Helpers\UnitHelper;
use OpenDominion\Models\Dominion;
use OpenDominion\Models\Realm;
use OpenDominion\Services\Dominion\InfoOpService;
use OpenDominion\Services\GameEventService;

class OpCenterController extends AbstractDominionController
{
public function getIndex()
{
$dominion = $this->getSelectedDominion();

// todo: filter $targetDominions by $dominion range
// todo: keep track of how many dominions are filtered due to range? to see if upper/lower end of realm is active much
$clairvoyanceRealms = $dominion->realm->infoOps()
->where('type', 'clairvoyance')
->get()
->map(static function ($infoOp) {
return $infoOp->targetRealm;
});

return view('pages.dominion.op-center.index', [
'infoOpService' => app(InfoOpService::class),
'rangeCalculator' => app(RangeCalculator::class),
'spellHelper' => app(SpellHelper::class),
'targetDominions' => $dominion->realm->infoOpTargetDominions,
'clairvoyanceRealms' => $clairvoyanceRealms
]);
}

Expand All @@ -51,4 +57,32 @@ public function getDominion(Dominion $dominion)
'dominion' => $dominion,
]);
}

public function getClairvoyance(int $realmNumber)
{
$infoOpService = app(InfoOpService::class);
$targetRealm = Realm::findOrFail($realmNumber);

$clairvoyanceInfoOp = $infoOpService->getInfoOpForRealm(
$this->getSelectedDominion()->realm,
$targetRealm,
'clairvoyance'
);

if ($clairvoyanceInfoOp === null) {
abort(404);
}

$gameEventService = app(GameEventService::class);
$clairvoyanceData = $gameEventService->getClairvoyance($targetRealm, $clairvoyanceInfoOp->updated_at);

$gameEvents = $clairvoyanceData['gameEvents'];
$dominionIds = $clairvoyanceData['dominionIds'];

return view('pages.dominion.town-crier', compact(
'gameEvents',
'dominionIds',
'clairvoyanceInfoOp'
))->with('realm', $targetRealm)->with('fromOpCenter', true);
}
}
51 changes: 7 additions & 44 deletions src/Http/Controllers/Dominion/TownCrierController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,63 +2,26 @@

namespace OpenDominion\Http\Controllers\Dominion;

use Illuminate\Database\Eloquent\Builder;
use OpenDominion\Models\Dominion;
use OpenDominion\Models\GameEvent;
use OpenDominion\Models\Realm;
use OpenDominion\Services\GameEventService;

class TownCrierController extends AbstractDominionController
{
public function getIndex()
{
$dominion = $this->getSelectedDominion();
$gameEventService = app(GameEventService::class);

$dominion = $this->getSelectedDominion();
$realm = $dominion->realm;
$dominionIds = $realm->dominions
->pluck('id')
->toArray();

$gameEvents = GameEvent::query()
->where('round_id', $dominion->round->id)
->where('created_at', '>', now()->subDays(2))
->where(function (Builder $query) use ($realm, $dominionIds) {
$query
->orWhere(function (Builder $query) use ($dominionIds) {
$query->where('source_type', Dominion::class)
->whereIn('source_id', $dominionIds);
})
->orWhere(function (Builder $query) use ($dominionIds) {
$query->where('target_type', Dominion::class)
->whereIn('target_id', $dominionIds);
})
->orWhere(function (Builder $query) use ($realm) {
$query->where('source_type', Realm::class)
->where('source_id', $realm->id);
})
->orWhere(function (Builder $query) use ($realm) {
$query->where('target_type', Realm::class)
->where('target_id', $realm->id);
});
})
->orderBy('created_at', 'desc')
->get()
// Filter out unsuccessful invasions against realmies
->filter(function (GameEvent $gameEvent) use ($dominionIds) {
if (
($gameEvent->type === 'invasion') &&
($gameEvent->target_type === Dominion::class) &&
in_array($gameEvent->target_id, $dominionIds, true)
) {
return $gameEvent->data['result']['success'];
}
$townCrierData = $gameEventService->getTownCrier($dominion);

return true;
});
$gameEvents = $townCrierData['gameEvents'];
$dominionIds = $townCrierData['dominionIds'];

return view('pages.dominion.town-crier', compact(
'gameEvents',
'realm',
'dominionIds'
));
))->with('fromOpCenter', false);
}
}

0 comments on commit a23e119

Please sign in to comment.