-
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.
Started splitting out the way we process rewards into their own jobs.
- Loading branch information
Showing
15 changed files
with
896 additions
and
189 deletions.
There are no files selected for viewing
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
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
68 changes: 68 additions & 0 deletions
68
app/Game/BattleRewardProcessing/Jobs/BattleCurrenciesHandler.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,68 @@ | ||
<?php | ||
|
||
namespace App\Game\BattleRewardProcessing\Jobs; | ||
|
||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Foundation\Bus\Dispatchable; | ||
use Illuminate\Queue\InteractsWithQueue; | ||
use Illuminate\Queue\SerializesModels; | ||
use App\Flare\Models\Character; | ||
use App\Flare\Models\Monster; | ||
use App\Flare\Services\CharacterRewardService; | ||
use App\Game\Core\Services\GoldRush; | ||
|
||
class BattleCurrenciesHandler implements ShouldQueue | ||
{ | ||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; | ||
|
||
/** | ||
* @param integer $characterId | ||
* @param integer $monsterId | ||
*/ | ||
public function __construct(private int $characterId, private int $monsterId) {} | ||
|
||
/** | ||
* HAndle the jon | ||
* | ||
* @param CharacterRewardService $characterRewardService | ||
* @param GoldRush $goldRush | ||
* @return void | ||
*/ | ||
public function handle(CharacterRewardService $characterRewardService, GoldRush $goldRush): void | ||
{ | ||
$character = Character::find($this->characterId); | ||
$monster = Monster::find($this->monsterId); | ||
|
||
if (is_null($character)) { | ||
return; | ||
} | ||
|
||
if (is_null($monster)) { | ||
return; | ||
} | ||
|
||
$this->handleCurrenciesRewards($character, $monster, $characterRewardService, $goldRush); | ||
} | ||
|
||
/** | ||
* Handle currency rewards from the fight. | ||
* | ||
* - Also includes potential gold rushes | ||
* | ||
* @param Character $character | ||
* @param Monster $monster | ||
* @param CharacterRewardService $characterRewardService | ||
* @param GoldRush $goldRush | ||
* @return void | ||
*/ | ||
private function handleCurrenciesRewards(Character $character, Monster $monster, CharacterRewardService $characterRewardService, GoldRush $goldRush): void | ||
{ | ||
$characterRewardService->setCharacter($character) | ||
->giveCurrencies($monster); | ||
|
||
$character = $character->refresh(); | ||
|
||
$goldRush->processPotentialGoldRush($character); | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
app/Game/BattleRewardProcessing/Jobs/BattleFactionHandler.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,83 @@ | ||
<?php | ||
|
||
namespace App\Game\BattleRewardProcessing\Jobs; | ||
|
||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Foundation\Bus\Dispatchable; | ||
use Illuminate\Queue\InteractsWithQueue; | ||
use Illuminate\Queue\SerializesModels; | ||
use App\Flare\Models\Character; | ||
use App\Flare\Models\Monster; | ||
use App\Game\BattleRewardProcessing\Handlers\FactionHandler; | ||
use App\Game\BattleRewardProcessing\Handlers\FactionLoyaltyBountyHandler; | ||
|
||
class BattleFactionHandler implements ShouldQueue | ||
{ | ||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; | ||
|
||
/** | ||
* @param integer $characterId | ||
* @param integer $monsterId | ||
*/ | ||
public function __construct(private int $characterId, private int $monsterId) {} | ||
|
||
/** | ||
* Handle the job | ||
* | ||
* @param FactionHandler $factionHandler | ||
* @param FactionLoyaltyBountyHandler $factionLoyaltyBountyHandler | ||
* @return void | ||
*/ | ||
public function handle(FactionHandler $factionHandler, FactionLoyaltyBountyHandler $factionLoyaltyBountyHandler): void | ||
{ | ||
$character = Character::find($this->characterId); | ||
$monster = Monster::find($this->monsterId); | ||
|
||
if (is_null($character)) { | ||
return; | ||
} | ||
|
||
if (is_null($monster)) { | ||
return; | ||
} | ||
|
||
$this->handleFactionRewards($character, $monster, $factionHandler); | ||
|
||
$this->handleFactionBounties($character, $monster, $factionLoyaltyBountyHandler); | ||
} | ||
|
||
/** | ||
* Handle updating the faction | ||
* | ||
* - This also includes the rewards for factions | ||
* | ||
* @param Character $character | ||
* @param Monster $monster | ||
* @param FactionHandler $factionHandler | ||
* @return void | ||
*/ | ||
private function handleFactionRewards(Character $character, Monster $monster, FactionHandler $factionHandler): void | ||
{ | ||
$gameMap = $character->map->gameMap; | ||
|
||
if ($gameMap->mapType()->isPurgatory()) { | ||
return; | ||
} | ||
|
||
$factionHandler->handleFaction($character, $monster); | ||
} | ||
|
||
/** | ||
* Handle faction bounties | ||
* | ||
* @param Character $character | ||
* @param Monster $monster | ||
* @param FactionLoyaltyBountyHandler $factionLoyaltyBountyHandler | ||
* @return void | ||
*/ | ||
private function handleFactionBounties(Character $character, Monster $monster, FactionLoyaltyBountyHandler $factionLoyaltyBountyHandler): void | ||
{ | ||
$factionLoyaltyBountyHandler->handleBounty($character, $monster); | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
app/Game/BattleRewardProcessing/Jobs/BattleGlobalEventHandler.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,76 @@ | ||
<?php | ||
|
||
namespace App\Game\BattleRewardProcessing\Jobs; | ||
|
||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Foundation\Bus\Dispatchable; | ||
use Illuminate\Queue\InteractsWithQueue; | ||
use Illuminate\Queue\SerializesModels; | ||
use App\Flare\Models\Character; | ||
use App\Flare\Models\Event; | ||
use App\Flare\Models\GameMap; | ||
use App\Flare\Models\GlobalEventGoal; | ||
use App\Flare\Values\MapNameValue; | ||
use App\Game\BattleRewardProcessing\Handlers\BattleGlobalEventParticipationHandler; | ||
use App\Game\Events\Values\EventType; | ||
|
||
|
||
class BattleGlobalEventHandler implements ShouldQueue | ||
{ | ||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; | ||
|
||
/** | ||
* @param integer $characterId | ||
*/ | ||
public function __construct(private int $characterId) {} | ||
|
||
/** | ||
* Handle the job | ||
* | ||
* @param BattleGlobalEventParticipationHandler $battleGlobalEventParticipationHandler | ||
* @return void | ||
*/ | ||
public function handle(BattleGlobalEventParticipationHandler $battleGlobalEventParticipationHandler): void | ||
{ | ||
$character = Character::find($this->characterId); | ||
|
||
if (is_null($character)) { | ||
return; | ||
} | ||
|
||
$this->handleGlobalEventGoals($character, $battleGlobalEventParticipationHandler); | ||
} | ||
|
||
/** | ||
* Handle updating global events | ||
* | ||
* @param Character $character | ||
* @param BattleGlobalEventParticipationHandler $battleGlobalEventParticipationHandler | ||
* @return void | ||
*/ | ||
private function handleGlobalEventGoals(Character $character, BattleGlobalEventParticipationHandler $battleGlobalEventParticipationHandler) | ||
{ | ||
$event = Event::whereIn('type', [ | ||
EventType::WINTER_EVENT, | ||
EventType::DELUSIONAL_MEMORIES_EVENT, | ||
])->first(); | ||
|
||
if (is_null($event)) { | ||
return; | ||
} | ||
|
||
$globalEventGoal = GlobalEventGoal::where('event_type', $event->type)->first(); | ||
|
||
$gameMapArrays = GameMap::whereIn('name', [ | ||
MapNameValue::ICE_PLANE, | ||
MapNameValue::DELUSIONAL_MEMORIES, | ||
])->pluck('id')->toArray(); | ||
|
||
if (is_null($globalEventGoal) || ! in_array($character->map->game_map_id, $gameMapArrays)) { | ||
return; | ||
} | ||
|
||
$battleGlobalEventParticipationHandler->handleGlobalEventParticipation($character, $globalEventGoal); | ||
} | ||
} |
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.