-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
created a way to handle updating event map based faction loyalties wh…
…en purgatory is unlocked, while the event is running
- Loading branch information
Showing
6 changed files
with
255 additions
and
54 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
app/Console/AfterDeployment/UpdateCharacterFactionBounties.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace App\Console\AfterDeployment; | ||
|
||
use App\Flare\Models\Character; | ||
use App\Game\Factions\FactionLoyalty\Services\UpdateFactionLoyaltyService; | ||
use Illuminate\Console\Command; | ||
|
||
class UpdateCharacterFactionBounties extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'update:character-faction-bounties {characterId}'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Update a specific characters faction bounties'; | ||
|
||
/** | ||
* Execute the console command. | ||
*/ | ||
public function handle(UpdateFactionLoyaltyService $updateFactionLoyaltyService) { | ||
$characterId = $this->argument('characterId'); | ||
|
||
if (is_null($characterId)) { | ||
$this->error('Missing character id.'); | ||
|
||
return; | ||
} | ||
|
||
$character = Character::find($characterId); | ||
|
||
if (is_null($character)) { | ||
$this->error('Character not found.'); | ||
|
||
return; | ||
} | ||
|
||
$updateFactionLoyaltyService->updateFactionLoyaltyBountyTasks($character); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
app/Game/Factions/FactionLoyalty/Services/UpdateFactionLoyaltyService.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
<?php | ||
|
||
namespace App\Game\Factions\FactionLoyalty\Services; | ||
|
||
use Illuminate\Support\Collection; | ||
use App\Flare\Models\Character; | ||
use App\Flare\Models\FactionLoyaltyNpc; | ||
use App\Flare\Models\FactionLoyaltyNpcTask; | ||
use App\Flare\Models\GameMap; | ||
use App\Flare\Models\Monster; | ||
use App\Flare\Values\MapNameValue; | ||
|
||
class UpdateFactionLoyaltyService { | ||
|
||
/** | ||
* Update faction loyalty bounty tasks for a character. | ||
* | ||
* @param Character $character | ||
* @return void | ||
*/ | ||
public function updateFactionLoyaltyBountyTasks(Character $character): void { | ||
$gameMaps = GameMap::whereIn('name', [ | ||
MapNameValue::DELUSIONAL_MEMORIES, | ||
MapNameValue::ICE_PLANE, | ||
])->get(); | ||
|
||
$characterFactions = $character->factions()->whereIn('game_map_id', $gameMaps->pluck('id')->toArray())->get(); | ||
|
||
$characterFactionLoyalties = $character->factionLoyalties()->whereIn('faction_id', $characterFactions->pluck('id')->toArray())->get(); | ||
|
||
foreach ($characterFactionLoyalties as $characterFactionLoyalty) { | ||
$factionLoyaltyNpcs = $characterFactionLoyalty->factionLoyaltyNpcs; | ||
|
||
$this->handleFactionLoyaltyNpcs($factionLoyaltyNpcs); | ||
} | ||
} | ||
|
||
/** | ||
* Handle the faction loyalty for npcs. | ||
* | ||
* @param Collection $factionLoyaltyNpcs | ||
* @return void | ||
*/ | ||
private function handleFactionLoyaltyNpcs(Collection $factionLoyaltyNpcs): void { | ||
foreach ($factionLoyaltyNpcs as $factionLoyaltyNpc) { | ||
$task = $factionLoyaltyNpc->factionLoyaltyNpcTasks; | ||
|
||
$this->handleTasksForNpc($factionLoyaltyNpc, $task); | ||
} | ||
} | ||
|
||
/** | ||
* Handle tasks for npc. | ||
* | ||
* @param FactionLoyaltyNpc $factionLoyaltyNpc | ||
* @param FactionLoyaltyNpcTask $factionLoyaltyNpcTask | ||
* @return void | ||
*/ | ||
private function handleTasksForNpc(FactionLoyaltyNpc $factionLoyaltyNpc, FactionLoyaltyNpcTask $factionLoyaltyNpcTask): void { | ||
$tasks = $factionLoyaltyNpcTask->fame_tasks; | ||
|
||
$gameMapId = $factionLoyaltyNpc->factionLoyalty->faction->game_map_id; | ||
|
||
foreach ($tasks as $index => $task) { | ||
if ($task['type'] === 'bounty') { | ||
$monster = Monster::find($task['monster_id']); | ||
|
||
if ($monster->game_map_id !== $gameMapId) { | ||
$newMonster = $this->fetchNewMonster($tasks, $gameMapId); | ||
|
||
|
||
$task['monster_id'] = $newMonster->id; | ||
$task['monster_name'] = $newMonster->name; | ||
|
||
$tasks[$index] = $task; | ||
|
||
continue; | ||
} | ||
} | ||
} | ||
|
||
$factionLoyaltyNpcTask->update([ | ||
'fame_tasks' => $tasks, | ||
]); | ||
} | ||
|
||
/** | ||
* Handle finding a new monster for the task. | ||
* | ||
* @param array $tasks | ||
* @param int $gameMapId | ||
* @return Monster | ||
*/ | ||
private function fetchNewMonster(array $tasks, int $gameMapId): Monster { | ||
$monster = Monster::where('game_map_id', $gameMapId) | ||
->where('is_raid_monster', false) | ||
->where('is_raid_boss', false) | ||
->where('is_celestial_entity', false) | ||
->whereNull('only_for_location_type') | ||
->inRandomOrder() | ||
->first(); | ||
|
||
if ($this->hasTaskAlready($tasks, 'monster_id', $monster->id)) { | ||
return $this->fetchNewMonster($tasks, $gameMapId); | ||
} | ||
|
||
return $monster; | ||
} | ||
|
||
/** | ||
* Check if the monster already has a task. | ||
* | ||
* @param array $tasks | ||
* @param string $key | ||
* @param int $id | ||
* @return bool | ||
*/ | ||
private function hasTaskAlready(array $tasks, string $key, int $id): bool | ||
{ | ||
foreach ($tasks as $task) { | ||
if ($task['type'] === 'bounty') { | ||
if ($task[$key] === $id) { | ||
return true; | ||
} | ||
} | ||
|
||
} | ||
|
||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.