Skip to content

Commit

Permalink
Merge branch 'release/0.6.2-5'
Browse files Browse the repository at this point in the history
  • Loading branch information
WaveHack committed Jun 16, 2019
2 parents c01775c + 5c7b8bd commit 1819a92
Show file tree
Hide file tree
Showing 10 changed files with 131 additions and 31 deletions.
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

## [Unreleased]

### [0.6.2-5] - 2019-06-16
### Added
- Added unread count badge to the council page menu item in the sidebar to indicate new messages since your last council visit

### Fixed
- Fixed unit OP/DP on military training page to show with including certain bonuses
- Fixed error where military DP was counted twice
- Fixed code refactor with SPA/WPA perks
- Fixed error in Op Center with Clairvoyance

## [0.6.2-4] - 2019-06-12
### Fixed
- Fixed Firewalker's Phoenix immortal except vs Icekin perk
Expand Down Expand Up @@ -255,7 +265,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
### Added
- This CHANGELOG file.

[Unreleased]: https://github.com/WaveHack/OpenDominion/compare/0.6.2-4...HEAD
[Unreleased]: https://github.com/WaveHack/OpenDominion/compare/0.6.2-5...HEAD
[0.6.2-5]: https://github.com/WaveHack/OpenDominion/compare/0.6.2-4...0.6.2-5
[0.6.2-4]: https://github.com/WaveHack/OpenDominion/compare/0.6.2-3...0.6.2-4
[0.6.2-3]: https://github.com/WaveHack/OpenDominion/compare/0.6.2-2...0.6.2-3
[0.6.2-2]: https://github.com/WaveHack/OpenDominion/compare/0.6.2-1...0.6.2-2
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

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

class AddCouncilLastReadColumnToDominions extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('dominions', function (Blueprint $table) {
$table->dateTime('council_last_read')
->nullable()
->after('building_dock');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('dominions', function (Blueprint $table) {
$table->dropColumn('council_last_read');
});
}
}
20 changes: 14 additions & 6 deletions app/resources/views/pages/dominion/invade.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,18 @@
@continue
@endif

@php
$offensivePower = $militaryCalculator->getUnitPowerWithPerks($selectedDominion, null, null, $unit, 'offense');
$defensivePower = $militaryCalculator->getUnitPowerWithPerks($selectedDominion, null, null, $unit, 'defense');
$hasDynamicOffensivePower = $unit->perks->filter(static function ($perk) {
return starts_with($perk->key, ['offense_from_', 'offense_staggered_', 'offense_vs_']);
})->count() > 0;
$hasDynamicDefensivePower = $unit->perks->filter(static function ($perk) {
return starts_with($perk->key, ['defense_from_', 'defense_staggered_', 'defense_vs_']);
})->count() > 0;
@endphp

<tr>
<td>
{!! $unitHelper->getUnitTypeIconHtml("unit{$unitSlot}") !!}
Expand All @@ -91,13 +103,9 @@
</span>
</td>
<td class="text-center">
<span id="unit{{ $unitSlot }}_op">
{{ (strpos($unit->power_offense, ".") !== false) ? number_format($unit->power_offense, 1) : number_format($unit->power_offense) }}
</span>
<span id="unit{{ $unitSlot }}_op">{{ (strpos($offensivePower, '.') !== false) ? number_format($offensivePower, 1) : number_format($offensivePower) }}</span>{{ $hasDynamicOffensivePower ? '*' : null }}
/
<span id="unit{{ $unitSlot }}_dp" class="text-muted">
{{ (strpos($unit->power_defense, ".") !== false) ? number_format($unit->power_defense, 1) : number_format($unit->power_defense) }}
</span>
<span id="unit{{ $unitSlot }}_dp" class="text-muted">{{ (strpos($defensivePower, '.') !== false) ? number_format($defensivePower, 1) : number_format($defensivePower) }}</span><span class="text-muted">{{ $hasDynamicDefensivePower ? '*' : null }}</span>
</td>
<td class="text-center">
{{ number_format($selectedDominion->{"military_unit{$unitSlot}"}) }}
Expand Down
18 changes: 14 additions & 4 deletions app/resources/views/pages/dominion/military.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,28 @@
$unit = $selectedDominion->race->units->filter(function ($unit) use ($unitType) {
return ($unit->slot == (int)str_replace('unit', '', $unitType));
})->first();
$offensivePower = $militaryCalculator->getUnitPowerWithPerks($selectedDominion, null, null, $unit, 'offense');
$defensivePower = $militaryCalculator->getUnitPowerWithPerks($selectedDominion, null, null, $unit, 'defense');
$hasDynamicOffensivePower = $unit->perks->filter(static function ($perk) {
return starts_with($perk->key, ['offense_from_', 'offense_staggered_', 'offense_vs_']);
})->count() > 0;
$hasDynamicDefensivePower = $unit->perks->filter(static function ($perk) {
return starts_with($perk->key, ['defense_from_', 'defense_staggered_', 'defense_vs_']);
})->count() > 0;
@endphp
<td class="text-center">
@if ($unit->power_offense == 0)
@if ($offensivePower === 0)
<span class="text-muted">0</span>
@else
{{ (strpos($unit->power_offense, ".") !== false) ? number_format($unit->power_offense, 1) : number_format($unit->power_offense) }}
{{ (strpos($offensivePower, '.') !== false) ? number_format($offensivePower, 1) : number_format($offensivePower) }}{{ $hasDynamicOffensivePower ? '*' : null }}
@endif
/
@if ($unit->power_defense == 0)
@if ($defensivePower === 0)
<span class="text-muted">0</span>
@else
{{ (strpos($unit->power_defense, ".") !== false) ? number_format($unit->power_defense, 1) : number_format($unit->power_defense) }}
{{ (strpos($defensivePower, '.') !== false) ? number_format($defensivePower, 1) : number_format($defensivePower) }}{{ $hasDynamicDefensivePower ? '*' : null }}
@endif
</td>
<td class="text-center">
Expand Down
2 changes: 1 addition & 1 deletion app/resources/views/partials/main-sidebar.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<li class="{{ Route::is('dominion.espionage') ? 'active' : null }}"><a href="{{ route('dominion.espionage') }}"><i class="fa fa-user-secret fa-fw"></i> <span>Espionage</span></a></li>

<li class="header">COMMS</li>
<li class="{{ Route::is('dominion.council*') ? 'active' : null }}"><a href="{{ route('dominion.council') }}"><i class="fa fa-group ra-fw"></i> <span>The Council</span></a></li>
<li class="{{ Route::is('dominion.council*') ? 'active' : null }}"><a href="{{ route('dominion.council') }}"><i class="fa fa-group ra-fw"></i> <span>The Council</span> {!! $councilUnreadCount > 0 ? ('<span class="pull-right-container"><small class="label pull-right bg-green">' . $councilUnreadCount . '</small></span>') : null !!}</a></li>
<li class="{{ Route::is('dominion.op-center*') ? 'active' : null }}"><a href="{{ route('dominion.op-center') }}"><i class="fa fa-globe ra-fw"></i> <span>Op Center</span></a></li>

<li class="header">REALM</li>
Expand Down
2 changes: 1 addition & 1 deletion src/Calculators/Dominion/Actions/TrainingCalculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function getTrainingCostsPerUnit(Dominion $dominion): array
{
$costsPerUnit = [];
$archmageBaseCost = 1000;
$archmageBaseCost -= $dominion->race->getPerkValue('archmage_cost');
$archmageBaseCost += $dominion->race->getPerkValue('archmage_cost');

$wizardCostMultiplier = $this->getWizardCostMultiplier($dominion);

Expand Down
24 changes: 8 additions & 16 deletions src/Calculators/Dominion/MilitaryCalculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -511,16 +511,12 @@ public function getSpyRatioRaw(Dominion $dominion, string $type = 'offense'): fl

// Add units which count as (partial) spies (Lizardfolk Chameleon)
foreach ($dominion->race->units as $unit) {
if ($unit->perkType === null) {
continue;
}

if ($type === 'offense' && $unit->perkType->key === 'counts_as_spy_offense') {
$spies += floor($dominion->{"military_unit{$unit->slot}"} * (float)$unit->unit_perk_type_values);
if ($type === 'offense' && $unit->getPerkValue('counts_as_spy_offense')) {
$spies += floor($dominion->{"military_unit{$unit->slot}"} * (float) $unit->getPerkValue('counts_as_spy_offense'));
}

if ($type === 'defense' && $unit->perkType->key === 'counts_as_spy_defense') {
$spies += floor($dominion->{"military_unit{$unit->slot}"} * (float)$unit->unit_perk_type_values);
if ($type === 'defense' && $unit->getPerkValue('counts_as_spy_defense')) {
$spies += floor($dominion->{"military_unit{$unit->slot}"} * (float) $unit->getPerkValue('counts_as_spy_defense'));
}
}

Expand Down Expand Up @@ -584,16 +580,12 @@ public function getWizardRatioRaw(Dominion $dominion, string $type = 'offense'):

// Add units which count as (partial) spies (Dark Elf Adept)
foreach ($dominion->race->units as $unit) {
if ($unit->perkType === null) {
continue;
}

if ($type === 'offense' && $unit->perkType->key === 'counts_as_wizard_offense') {
$wizards += floor($dominion->{"military_unit{$unit->slot}"} * (float)$unit->unit_perk_type_values);
if ($type === 'offense' && $unit->getPerkValue('counts_as_wizard_offense')) {
$wizards += floor($dominion->{"military_unit{$unit->slot}"} * (float) $unit->getPerkValue('counts_as_wizard_offense'));
}

if ($type === 'defense' && $unit->perkType->key === 'counts_as_wizard_defense') {
$wizards += floor($dominion->{"military_unit{$unit->slot}"} * (float)$unit->unit_perk_type_values);
if ($type === 'defense' && $unit->getPerkValue('counts_as_wizard_defense')) {
$wizards += floor($dominion->{"military_unit{$unit->slot}"} * (float) $unit->getPerkValue('counts_as_wizard_defense'));
}
}

Expand Down
13 changes: 11 additions & 2 deletions src/Http/Controllers/Dominion/CouncilController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
namespace OpenDominion\Http\Controllers\Dominion;

use Exception;
use Illuminate\Support\Facades\DB;
use OpenDominion\Http\Requests\Dominion\Council\CreatePostRequest;
use OpenDominion\Http\Requests\Dominion\Council\CreateThreadRequest;
use OpenDominion\Models\Council;
use OpenDominion\Services\Analytics\AnalyticsEvent;
use OpenDominion\Models\Dominion;
use OpenDominion\Services\CouncilService;
use RuntimeException;

Expand All @@ -16,6 +15,7 @@ class CouncilController extends AbstractDominionController
public function getIndex()
{
$dominion = $this->getSelectedDominion();
$this->updateDominionCouncilLastRead($dominion);
$councilService = app(CouncilService::class);

return view('pages.dominion.council.index', [
Expand Down Expand Up @@ -69,6 +69,9 @@ public function getThread(Council\Thread $thread)
{
$this->guardAgainstCrossRealm($thread);

$dominion = $this->getSelectedDominion();
$this->updateDominionCouncilLastRead($dominion);

$thread->load(['dominion.user', 'posts.dominion.user']);

return view('pages.dominion.council.thread', compact(
Expand Down Expand Up @@ -112,4 +115,10 @@ protected function guardAgainstCrossRealm(Council\Thread $thread)
throw new RuntimeException('No permission to view thread'); // todo: modelnotfoundexception?
}
}

protected function updateDominionCouncilLastRead(Dominion $dominion): void
{
$dominion->council_last_read = now();
$dominion->save();
}
}
1 change: 1 addition & 0 deletions src/Models/Dominion.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
* @property int $building_shrine
* @property int $building_barracks
* @property int $building_dock
* @property \Illuminate\Support\Carbon|null $council_last_read
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property int|null $pack_id
Expand Down
35 changes: 35 additions & 0 deletions src/Providers/ComposerServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
use Illuminate\Contracts\View\View;
use OpenDominion\Calculators\NetworthCalculator;
use OpenDominion\Helpers\NotificationHelper;
use OpenDominion\Models\Council\Post;
use OpenDominion\Models\Council\Thread;
use OpenDominion\Models\Dominion;
use OpenDominion\Services\Dominion\SelectorService;

class ComposerServiceProvider extends AbstractServiceProvider
Expand All @@ -21,6 +24,38 @@ public function boot()
$view->with('selectorService', app(SelectorService::class));
});

view()->composer('partials.main-sidebar', function (View $view) {
$selectorService = app(SelectorService::class);

if (!$selectorService->hasUserSelectedDominion()) {
return;
}

/** @var Dominion $dominion */
$dominion = $selectorService->getUserSelectedDominion();

$lastRead = $dominion->council_last_read;

$councilUnreadCount = $dominion->realm
->councilThreads()
->with('posts')
->get()
->map(static function (Thread $thread) use ($lastRead) {
$unreadCount = $thread->posts->filter(static function (Post $post) use ($lastRead) {
return $post->created_at > $lastRead;
})->count();

if ($thread->created_at > $lastRead) {
$unreadCount++;
}

return $unreadCount;
})
->sum();

$view->with('councilUnreadCount', $councilUnreadCount);
});

view()->composer('partials.main-footer', function (View $view) {
$version = (Cache::has('version-html') ? Cache::get('version-html') : 'unknown');
$view->with('version', $version);
Expand Down

0 comments on commit 1819a92

Please sign in to comment.