Skip to content

Commit

Permalink
Started splitting out the way we process rewards into their own jobs.
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamKyle committed Dec 4, 2024
1 parent fb937e7 commit 363728c
Show file tree
Hide file tree
Showing 15 changed files with 896 additions and 189 deletions.
10 changes: 10 additions & 0 deletions _ide_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -16960,6 +16960,16 @@
{
/** @var \Spatie\FlareClient\Flare $instance */
return $instance->withStackFrameArguments($withStackFrameArguments, $forcePHPIniSetting);
}
/**
*
*
* @param \Spatie\FlareClient\class-string $exceptionClass
* @static
*/ public static function overrideGrouping($exceptionClass, $type = 'exception_message_and_class')
{
/** @var \Spatie\FlareClient\Flare $instance */
return $instance->overrideGrouping($exceptionClass, $type);
}
/**
*
Expand Down
6 changes: 3 additions & 3 deletions app/Flare/Services/CharacterRewardService.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ public function giveCurrencies(Monster $monster): CharacterRewardService
$this->distributeCopperCoins($monster);

$this->currencyEventReward($monster);

if (! $this->character->is_auto_battling && $this->character->isLoggedIn()) {
dump($this->character->isLoggedIn(), !$this->character->is_auto_battling);
if (!$this->character->is_auto_battling && $this->character->isLoggedIn()) {
event(new UpdateCharacterCurrenciesEvent($this->character->refresh()));
}

Expand Down Expand Up @@ -262,7 +262,7 @@ protected function distributeXP(Monster $monster)
$xp = XPCalculator::fetchXPFromMonster($monster, $this->character->level);

if ($this->character->level >= $monster->max_level && $this->character->user->show_monster_to_low_level_message) {
ServerMessageHandler::sendBasicMessage($this->character->user, $monster->name.' has a max level of: '.number_format($monster->max_level).'. You are only getting 1/3rd of: '.number_format($monster->xp).' XP before all bonuses. Move down the list child.');
ServerMessageHandler::sendBasicMessage($this->character->user, $monster->name . ' has a max level of: ' . number_format($monster->max_level) . '. You are only getting 1/3rd of: ' . number_format($monster->xp) . ' XP before all bonuses. Move down the list child.');

$addBonus = false;
}
Expand Down
2 changes: 1 addition & 1 deletion app/Game/Battle/Handlers/BattleEventHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function processMonsterDeath(int $characterId, int $monsterId): void
return;
}

$this->battleRewardService->setUp($monster, $character)->handleBaseRewards();
$this->battleRewardService->setUp($character->id, $monster->id)->handleBaseRewards();

$this->secondaryRewardService->handleSecondaryRewards($character);
}
Expand Down
68 changes: 68 additions & 0 deletions app/Game/BattleRewardProcessing/Jobs/BattleCurrenciesHandler.php
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 app/Game/BattleRewardProcessing/Jobs/BattleFactionHandler.php
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 app/Game/BattleRewardProcessing/Jobs/BattleGlobalEventHandler.php
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);
}
}
39 changes: 24 additions & 15 deletions app/Game/BattleRewardProcessing/Jobs/BattleItemHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,44 @@

namespace App\Game\BattleRewardProcessing\Jobs;

use App\Flare\Models\Character;
use App\Flare\Models\Monster;
use App\Game\Core\Services\DropCheckService;
use Exception;
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\Core\Services\DropCheckService;


class BattleItemHandler implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

private Character $character;

private Monster $monster;

public function __construct(Character $character, Monster $monster)
{
$this->character = $character;
$this->monster = $monster;
}
public function __construct(private int $characterId, private int $monsterId) {}

/**
* @throws Exception
* Handle the job.
*
* - Handle drops from the monster.
*
* @param DropCheckService $dropCheckService
* @return void
*/
public function handle(DropCheckService $dropCheckService): void
{
$dropCheckService->process($this->character->refresh(), $this->monster);

$character = Character::find($this->characterId);
$monster = Monster::find($this->monsterId);

if (is_null($character)) {
return;
}

if (is_null($monster)) {
return;
}

$dropCheckService->process($character, $monster);
}
}
Loading

0 comments on commit 363728c

Please sign in to comment.