diff --git a/_ide_helper.php b/_ide_helper.php index cba4104e9..43c424d84 100644 --- a/_ide_helper.php +++ b/_ide_helper.php @@ -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); } /** * diff --git a/app/Flare/Services/CharacterRewardService.php b/app/Flare/Services/CharacterRewardService.php index 34ef001f5..d0486af62 100755 --- a/app/Flare/Services/CharacterRewardService.php +++ b/app/Flare/Services/CharacterRewardService.php @@ -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())); } @@ -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; } diff --git a/app/Game/Battle/Handlers/BattleEventHandler.php b/app/Game/Battle/Handlers/BattleEventHandler.php index 3d7319bad..65d2e1221 100755 --- a/app/Game/Battle/Handlers/BattleEventHandler.php +++ b/app/Game/Battle/Handlers/BattleEventHandler.php @@ -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); } diff --git a/app/Game/BattleRewardProcessing/Jobs/BattleCurrenciesHandler.php b/app/Game/BattleRewardProcessing/Jobs/BattleCurrenciesHandler.php new file mode 100755 index 000000000..6f86e50a4 --- /dev/null +++ b/app/Game/BattleRewardProcessing/Jobs/BattleCurrenciesHandler.php @@ -0,0 +1,68 @@ +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); + } +} diff --git a/app/Game/BattleRewardProcessing/Jobs/BattleFactionHandler.php b/app/Game/BattleRewardProcessing/Jobs/BattleFactionHandler.php new file mode 100755 index 000000000..7b37ef5a1 --- /dev/null +++ b/app/Game/BattleRewardProcessing/Jobs/BattleFactionHandler.php @@ -0,0 +1,83 @@ +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); + } +} diff --git a/app/Game/BattleRewardProcessing/Jobs/BattleGlobalEventHandler.php b/app/Game/BattleRewardProcessing/Jobs/BattleGlobalEventHandler.php new file mode 100755 index 000000000..fcc3b23ad --- /dev/null +++ b/app/Game/BattleRewardProcessing/Jobs/BattleGlobalEventHandler.php @@ -0,0 +1,76 @@ +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); + } +} diff --git a/app/Game/BattleRewardProcessing/Jobs/BattleItemHandler.php b/app/Game/BattleRewardProcessing/Jobs/BattleItemHandler.php index da650ef24..084367440 100755 --- a/app/Game/BattleRewardProcessing/Jobs/BattleItemHandler.php +++ b/app/Game/BattleRewardProcessing/Jobs/BattleItemHandler.php @@ -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); } } diff --git a/app/Game/BattleRewardProcessing/Jobs/BattleLocationHandler.php b/app/Game/BattleRewardProcessing/Jobs/BattleLocationHandler.php new file mode 100755 index 000000000..cb395cc5b --- /dev/null +++ b/app/Game/BattleRewardProcessing/Jobs/BattleLocationHandler.php @@ -0,0 +1,93 @@ +characterId = $characterId; + $this->monsterId = $monsterId; + } + + /** + * Handle the job + * + * @param PurgatorySmithHouseRewardHandler $purgatorySmithHouseRewardHandler + * @param GoldMinesRewardHandler $goldMinesRewardHandler + * @param TheOldChurchRewardHandler $theOldChurchRewardHandler + * @return void + */ + public function handle( + PurgatorySmithHouseRewardHandler $purgatorySmithHouseRewardHandler, + GoldMinesRewardHandler $goldMinesRewardHandler, + TheOldChurchRewardHandler $theOldChurchRewardHandler, + ): void { + $character = Character::find($this->characterId); + $monster = Monster::find($this->monsterId); + + if (is_null($character)) { + return; + } + + if (is_null($monster)) { + return; + } + } + + /** + * Process location based rewards + * + * - Handle Purgatory Smithhouse + * - Handle Goldmines + * - Handle The Old Church + * + * @param Character $character + * @param Monster $monster + * @param PurgatorySmithHouseRewardHandler $purgatorySmithHouseRewardHandler + * @param GoldMinesRewardHandler $goldMinesRewardHandler + * @param TheOldChurchRewardHandler $theOldChurchRewardHandler + * @return void + */ + private function processLocationBasedRewards( + Character $character, + Monster $monster, + PurgatorySmithHouseRewardHandler $purgatorySmithHouseRewardHandler, + GoldMinesRewardHandler $goldMinesRewardHandler, + TheOldChurchRewardHandler $theOldChurchRewardHandler, + ): void { + $character = $purgatorySmithHouseRewardHandler->handleFightingAtPurgatorySmithHouse($character, $monster); + + $character = $goldMinesRewardHandler->handleFightingAtGoldMines($character, $monster); + + $theOldChurchRewardHandler->handleFightingAtTheOldChurch($character, $monster); + } +} diff --git a/app/Game/BattleRewardProcessing/Jobs/BattleWeeklyFightHandler.php b/app/Game/BattleRewardProcessing/Jobs/BattleWeeklyFightHandler.php new file mode 100755 index 000000000..c762985a0 --- /dev/null +++ b/app/Game/BattleRewardProcessing/Jobs/BattleWeeklyFightHandler.php @@ -0,0 +1,59 @@ +characterId); + $monster = Monster::find($this->monsterId); + + if (is_null($character)) { + return; + } + + if (is_null($monster)) { + return; + } + } + + /** + * Process dealing with weeklu fights + * + * - These are special locations with specific monsters that only be faught once per week. + * - Handles rewards and updating the weekly fight details including marking the creature as ddefeated for the week. + * + * @param Character $character + * @param Monster $monster + * @param WeeklyBattleService $weeklyBattleService + * @return void + */ + private function processWeeklyFight(Character $character, Monster $monster, WeeklyBattleService $weeklyBattleService): void + { + $weeklyBattleService->handleMonsterDeath($character, $monster); + } +} diff --git a/app/Game/BattleRewardProcessing/Jobs/BattleXpHandler.php b/app/Game/BattleRewardProcessing/Jobs/BattleXpHandler.php new file mode 100755 index 000000000..700ec560d --- /dev/null +++ b/app/Game/BattleRewardProcessing/Jobs/BattleXpHandler.php @@ -0,0 +1,63 @@ +characterId); + $monster = Monster::find($this->monsterId); + + if (is_null($character)) { + return; + } + + if (is_null($monster)) { + return; + } + + $this->processXpReward($character, $monster, $characterRewardService); + } + + /** + * Process XP rewards + * + * - Includes character XP + * - Includes Skill XP + * + * @param Character $character + * @param Monster $monster + * @param CharacterRewardService $characterRewardService + * @return void + */ + private function processXpReward(Character $character, Monster $monster, CharacterRewardService $characterRewardService): void + { + $characterRewardService->setCharacter($character) + ->distributeCharacterXP($monster) + ->distributeSkillXP($monster); + } +} diff --git a/app/Game/BattleRewardProcessing/Services/BattleRewardService.php b/app/Game/BattleRewardProcessing/Services/BattleRewardService.php index 2fc0a495c..fd03b40b5 100644 --- a/app/Game/BattleRewardProcessing/Services/BattleRewardService.php +++ b/app/Game/BattleRewardProcessing/Services/BattleRewardService.php @@ -2,79 +2,39 @@ namespace App\Game\BattleRewardProcessing\Services; -use App\Flare\Models\Character; -use App\Flare\Models\Event; -use App\Flare\Models\GameMap; -use App\Flare\Models\GlobalEventGoal; -use App\Flare\Models\Monster; -use App\Flare\Services\CharacterRewardService; -use App\Flare\Values\MapNameValue; -use App\Game\BattleRewardProcessing\Handlers\BattleGlobalEventParticipationHandler; -use App\Game\BattleRewardProcessing\Handlers\FactionHandler; -use App\Game\BattleRewardProcessing\Handlers\FactionLoyaltyBountyHandler; -use App\Game\BattleRewardProcessing\Handlers\GoldMinesRewardHandler; -use App\Game\BattleRewardProcessing\Handlers\PurgatorySmithHouseRewardHandler; -use App\Game\BattleRewardProcessing\Handlers\TheOldChurchRewardHandler; +use App\Game\BattleRewardProcessing\Jobs\BattleCurrenciesHandler; +use App\Game\BattleRewardProcessing\Jobs\BattleFactionHandler; +use App\Game\BattleRewardProcessing\Jobs\BattleGlobalEventHandler; use App\Game\BattleRewardProcessing\Jobs\BattleItemHandler; -use App\Game\Core\Services\GoldRush; -use App\Game\Events\Values\EventType; +use App\Game\BattleRewardProcessing\Jobs\BattleLocationHandler; +use App\Game\BattleRewardProcessing\Jobs\BattleWeeklyFightHandler; +use App\Game\BattleRewardProcessing\Jobs\BattleXpHandler; class BattleRewardService { - private GameMap $gameMap; - private Monster $monster; - - private Character $character; - - private FactionHandler $factionHandler; - - private CharacterRewardService $characterRewardService; - - private GoldRush $goldRush; - - private BattleGlobalEventParticipationHandler $globalEventParticipationHandler; - - private PurgatorySmithHouseRewardHandler $purgatorySmithHouseRewardHandler; - - private GoldMinesRewardHandler $goldMinesRewardHandler; - - private FactionLoyaltyBountyHandler $factionLoyaltyBountyHandler; - - private TheOldChurchRewardHandler $theOldChurchRewardHandler; - - private WeeklyBattleService $weeklyBattleService; - - public function __construct( - FactionHandler $factionHandler, - CharacterRewardService $characterRewardService, - GoldRush $goldRush, - BattleGlobalEventParticipationHandler $globalEventParticipationHandler, - PurgatorySmithHouseRewardHandler $purgatorySmithHouseRewardHandler, - GoldMinesRewardHandler $goldMinesRewardHandler, - FactionLoyaltyBountyHandler $factionLoyaltyBountyHandler, - TheOldChurchRewardHandler $theOldChurchRewardHandler, - WeeklyBattleService $weeklyBattleService, - ) { - $this->factionHandler = $factionHandler; - $this->characterRewardService = $characterRewardService; - $this->goldRush = $goldRush; - $this->globalEventParticipationHandler = $globalEventParticipationHandler; - $this->purgatorySmithHouseRewardHandler = $purgatorySmithHouseRewardHandler; - $this->goldMinesRewardHandler = $goldMinesRewardHandler; - $this->factionLoyaltyBountyHandler = $factionLoyaltyBountyHandler; - $this->theOldChurchRewardHandler = $theOldChurchRewardHandler; - $this->weeklyBattleService = $weeklyBattleService; - } - - public function setUp(Monster $monster, Character $character): BattleRewardService + /** + * @var integer $characterId + */ + private int $characterId; + + /** + * @var integer $monsterId + */ + private int $monsterId; + + /** + * Set up the battle reward service + * + * @param integer $characterId + * @param integer $monsterId + * @return BattleRewardService + */ + public function setUp(int $characterId, int $monsterId): BattleRewardService { - $this->character = $character; - $this->monster = $monster; - $this->gameMap = $monster->gameMap; - - $this->characterRewardService->setCharacter($character); + $this->characterId = $characterId; + $this->monsterId = $monsterId; return $this; } @@ -82,67 +42,12 @@ public function setUp(Monster $monster, Character $character): BattleRewardServi public function handleBaseRewards() { - $this->handleFactionRewards(); - - $this->characterRewardService->setCharacter($this->character) - ->distributeCharacterXP($this->monster) - ->distributeSkillXP($this->monster) - ->giveCurrencies($this->monster); - - $this->character = $this->characterRewardService->getCharacter(); - - $this->goldRush->processPotentialGoldRush($this->character); - - $this->handleGlobalEventGoals(); - - $character = $this->character->refresh(); - - $character = $this->purgatorySmithHouseRewardHandler->handleFightingAtPurgatorySmithHouse($character, $this->monster); - - $character = $this->goldMinesRewardHandler->handleFightingAtGoldMines($character, $this->monster); - - $character = $this->theOldChurchRewardHandler->handleFightingAtTheOldChurch($character, $this->monster); - - $character = $this->factionLoyaltyBountyHandler->handleBounty($character, $this->monster); - - $character = $this->weeklyBattleService->handleMonsterDeath($character, $this->monster); - - BattleItemHandler::dispatch($character, $this->monster); - } - - protected function handleFactionRewards() - { - if ($this->gameMap->mapType()->isPurgatory()) { - return; - } - - $this->factionHandler->handleFaction($this->character, $this->monster); - - $this->character = $this->character->refresh(); - } - - protected function handleGlobalEventGoals() - { - $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($this->character->map->game_map_id, $gameMapArrays)) { - return; - } - - $this->globalEventParticipationHandler->handleGlobalEventParticipation($this->character->refresh(), $globalEventGoal->refresh()); + BattleXpHandler::dispatch($this->characterId, $this->monsterId)->onQueue('battle_reward_xp')->delay(now()->addSeconds(2)); + BattleCurrenciesHandler::dispatch($this->characterId, $this->monsterId)->onQueue('battle_reward_currencies')->delay(now()->addSeconds(2)); + BattleFactionHandler::dispatch($this->characterId, $this->monsterId)->onQueue('battle_reward_factions')->delay(now()->addSeconds(2)); + BattleGlobalEventHandler::dispatch($this->characterId)->onQueue('battle_reward_global_event')->delay(now()->addSeconds(2)); + BattleLocationHandler::dispatch($this->characterId, $this->monsterId)->onQueue('battle_reward_location_handlers')->delay(now()->addSeconds(2)); + BattleWeeklyFightHandler::dispatch($this->characterId, $this->monsterId)->onQueue('battle_reward_weekly_fights')->delay(now()->addSeconds(2)); + BattleItemHandler::dispatch($this->characterId, $this->monsterId)->onQueue('battle_reward_item_handler')->delay(now()->addSeconds(2)); } } diff --git a/config/database.php b/config/database.php index acfe7a8f3..fd226fa1e 100755 --- a/config/database.php +++ b/config/database.php @@ -166,7 +166,7 @@ 'host' => env('REDIS_HOST', '127.0.0.1'), 'password' => env('REDIS_PASSWORD', null), 'port' => env('REDIS_PORT', 6379), - 'database' => env('REDIS_CACHE_DB', 2), + 'database' => 2, ], 'weekly_spawn' => [ @@ -174,9 +174,75 @@ 'host' => env('REDIS_HOST', '127.0.0.1'), 'password' => env('REDIS_PASSWORD', null), 'port' => env('REDIS_PORT', 6379), - 'database' => env('REDIS_CACHE_DB', 4), + 'database' => 3, + ], + + 'battle_reward_xp' => [ + 'url' => env('REDIS_URL'), + 'host' => env('REDIS_HOST', '127.0.0.1'), + 'password' => env('REDIS_PASSWORD', null), + 'port' => env('REDIS_PORT', 6379), + 'database' => 4, + ], + + 'battle_reward_currencies' => [ + 'url' => env('REDIS_URL'), + 'host' => env('REDIS_HOST', '127.0.0.1'), + 'password' => env('REDIS_PASSWORD', null), + 'port' => env('REDIS_PORT', 6379), + 'database' => 5, + ], + + 'battle_reward_factions' => [ + 'url' => env('REDIS_URL'), + 'host' => env('REDIS_HOST', '127.0.0.1'), + 'password' => env('REDIS_PASSWORD', null), + 'port' => env('REDIS_PORT', 6379), + 'database' => 6, + ], + + + 'battle_reward_global_event' => [ + 'url' => env('REDIS_URL'), + 'host' => env('REDIS_HOST', '127.0.0.1'), + 'password' => env('REDIS_PASSWORD', null), + 'port' => env('REDIS_PORT', 6379), + 'database' => 7, + ], + + 'battle_reward_location_handlers' => [ + 'url' => env('REDIS_URL'), + 'host' => env('REDIS_HOST', '127.0.0.1'), + 'password' => env('REDIS_PASSWORD', null), + 'port' => env('REDIS_PORT', 6379), + 'database' => 8, + ], + + 'battle_reward_weekly_fights' => [ + 'url' => env('REDIS_URL'), + 'host' => env('REDIS_HOST', '127.0.0.1'), + 'password' => env('REDIS_PASSWORD', null), + 'port' => env('REDIS_PORT', 6379), + 'database' => 9, + ], + + 'battle_reward_item_handler' => [ + 'url' => env('REDIS_URL'), + 'host' => env('REDIS_HOST', '127.0.0.1'), + 'password' => env('REDIS_PASSWORD', null), + 'port' => env('REDIS_PORT', 6379), + 'database' => 10, + ], + + 'long_running' => [ + 'url' => env('REDIS_URL'), + 'host' => env('REDIS_HOST', '127.0.0.1'), + 'password' => env('REDIS_PASSWORD', null), + 'port' => env('REDIS_PORT', 6379), + 'database' => 11, ], ], + ]; diff --git a/config/horizon.php b/config/horizon.php index df5bb4dc5..65ee6bf7d 100755 --- a/config/horizon.php +++ b/config/horizon.php @@ -176,7 +176,7 @@ ], 'supervisor-kingdoms' => [ 'connection' => 'kingdom_jobs', - 'queue' => ['default_Long'], + 'queue' => ['kingdom_jobs'], 'balance' => 'auto', 'maxProcesses' => 10, 'memory' => 256, @@ -185,7 +185,7 @@ ], 'supervisor-weekly-spawn' => [ 'connection' => 'weekly_spawn', - 'queue' => ['default_long'], + 'queue' => ['weekly_spawn'], 'balance' => 'auto', 'maxProcesses' => 1, 'memory' => 128, @@ -202,8 +202,79 @@ 'timeout' => 1900, 'nice' => 0, ], + 'supervisor-battle-reward-xp' => [ + 'connection' => 'battle_reward_xp', + 'queue' => ['battle_reward_xp'], + 'balance' => 'auto', + 'maxProcesses' => 25, + 'memory' => 256, + 'tries' => 5, + 'nice' => 0, + ], + + 'supervisor-battle-reward-currencies' => [ + 'connection' => 'battle_reward_currencies', + 'queue' => ['battle_reward_currencies'], + 'balance' => 'auto', + 'maxProcesses' => 25, + 'memory' => 256, + 'tries' => 5, + 'nice' => 0, + ], + + 'supervisor-battle-reward-factions' => [ + 'connection' => 'battle_reward_factions', + 'queue' => ['battle_reward_factions'], + 'balance' => 'auto', + 'maxProcesses' => 25, + 'memory' => 256, + 'tries' => 5, + 'nice' => 0, + ], + + 'supervisor-battle-reward-global-event' => [ + 'connection' => 'battle_reward_global_event', + 'queue' => ['battle_reward_global_event'], + 'balance' => 'auto', + 'maxProcesses' => 25, + 'memory' => 256, + 'tries' => 5, + 'nice' => 0, + ], + + 'supervisor-battle-reward-location-handlers' => [ + 'connection' => 'battle_reward_location_handlers', + 'queue' => ['battle_reward_location_handlers'], + 'balance' => 'auto', + 'maxProcesses' => 25, + 'memory' => 256, + 'tries' => 5, + 'nice' => 0, + ], + + 'supervisor-battle-reward-weekly-fights' => [ + 'connection' => 'battle_reward_weekly_fights', + 'queue' => ['battle_reward_weekly_fights'], + 'balance' => 'auto', + 'maxProcesses' => 25, + 'memory' => 256, + 'tries' => 5, + 'nice' => 0, + ], + + 'supervisor-battle-reward-item-handler' => [ + 'connection' => 'battle_reward_item_handler', + 'queue' => ['battle_reward_item_handler'], + 'balance' => 'auto', + 'maxProcesses' => 25, + 'memory' => 256, + 'tries' => 5, + 'nice' => 0, + ], + ], + 'environments' => [ 'production' => [ 'supervisor-1' => [ @@ -214,22 +285,15 @@ 'balanceCooldown' => 3, ], 'supervisor-kingdoms' => [ - 'connection' => 'redis', - 'queue' => ['default_long'], - 'maxProcesses' => 10, - 'balanceMaxShift' => 1, - 'balanceCooldown' => 3, - ], - 'supervisor-daily-characters' => [ - 'connection' => 'redis', - 'queue' => ['default'], + 'connection' => 'kingdom_jobs', + 'queue' => ['kingdom_jobs'], 'maxProcesses' => 10, 'balanceMaxShift' => 1, 'balanceCooldown' => 3, ], 'supervisor-weekly-spawn' => [ - 'connection' => 'redis', - 'queue' => ['default_long'], + 'connection' => 'weekly_spawn', + 'queue' => ['weekly_spawn'], 'maxProcesses' => 10, 'balanceMaxShift' => 1, 'balanceCooldown' => 3, @@ -237,13 +301,82 @@ 'supervisor-long-running' => [ 'connection' => 'long_running', 'queue' => ['default_long'], - 'balance' => 'auto', 'maxProcesses' => 2, 'memory' => 128, 'tries' => 2, 'timeout' => 900, 'nice' => 0, ], + 'supervisor-battle-reward-xp' => [ + 'connection' => 'battle_reward_xp', + 'queue' => ['battle_reward_xp'], + 'balance' => 'auto', + 'maxProcesses' => 25, + 'memory' => 256, + 'tries' => 5, + 'nice' => 0, + ], + + 'supervisor-battle-reward-currencies' => [ + 'connection' => 'battle_reward_currencies', + 'queue' => ['battle_reward_currencies'], + 'balance' => 'auto', + 'maxProcesses' => 25, + 'memory' => 256, + 'tries' => 5, + 'nice' => 0, + ], + + 'supervisor-battle-reward-factions' => [ + 'connection' => 'battle_reward_factions', + 'queue' => ['battle_reward_factions'], + 'balance' => 'auto', + 'maxProcesses' => 25, + 'memory' => 256, + 'tries' => 5, + 'nice' => 0, + ], + + 'supervisor-battle-reward-global-event' => [ + 'connection' => 'battle_reward_global_event', + 'queue' => ['battle_reward_global_event'], + 'balance' => 'auto', + 'maxProcesses' => 25, + 'memory' => 256, + 'tries' => 5, + 'nice' => 0, + ], + + 'supervisor-battle-reward-location-handlers' => [ + 'connection' => 'battle_reward_location_handlers', + 'queue' => ['battle_reward_location_handlers'], + 'balance' => 'auto', + 'maxProcesses' => 25, + 'memory' => 256, + 'tries' => 5, + 'nice' => 0, + ], + + 'supervisor-battle-reward-weekly-fights' => [ + 'connection' => 'battle_reward_weekly_fights', + 'queue' => ['battle_reward_weekly_fights'], + 'balance' => 'auto', + 'maxProcesses' => 25, + 'memory' => 256, + 'tries' => 5, + 'nice' => 0, + ], + + 'supervisor-battle-reward-item-handler' => [ + 'connection' => 'battle_reward_item_handler', + 'queue' => ['battle_reward_item_handler'], + 'balance' => 'auto', + 'maxProcesses' => 25, + 'memory' => 256, + 'tries' => 5, + 'nice' => 0, + ], + ], 'local' => [ @@ -268,6 +401,77 @@ 'timeout' => 900, 'nice' => 0, ], + 'supervisor-battle-reward-xp' => [ + 'connection' => 'battle_reward_xp', + 'queue' => ['battle_reward_xp'], + 'balance' => 'auto', + 'maxProcesses' => 25, + 'memory' => 256, + 'tries' => 5, + 'nice' => 0, + ], + + 'supervisor-battle-reward-currencies' => [ + 'connection' => 'battle_reward_currencies', + 'queue' => ['battle_reward_currencies'], + 'balance' => 'auto', + 'maxProcesses' => 25, + 'memory' => 256, + 'tries' => 5, + 'nice' => 0, + ], + + 'supervisor-battle-reward-factions' => [ + 'connection' => 'battle_reward_factions', + 'queue' => ['battle_reward_factions'], + 'balance' => 'auto', + 'maxProcesses' => 25, + 'memory' => 256, + 'tries' => 5, + 'nice' => 0, + ], + + 'supervisor-battle-reward-global-event' => [ + 'connection' => 'battle_reward_global_event', + 'queue' => ['battle_reward_global_event'], + 'balance' => 'auto', + 'maxProcesses' => 25, + 'memory' => 256, + 'tries' => 5, + 'nice' => 0, + ], + + 'supervisor-battle-reward-location-handlers' => [ + 'connection' => 'battle_reward_location_handlers', + 'queue' => ['battle_reward_location_handlers'], + 'balance' => 'auto', + 'maxProcesses' => 25, + 'memory' => 256, + 'tries' => 5, + 'nice' => 0, + ], + + 'supervisor-battle-reward-weekly-fights' => [ + 'connection' => 'battle_reward_weekly_fights', + 'queue' => ['battle_reward_weekly_fights'], + 'balance' => 'auto', + 'maxProcesses' => 25, + 'memory' => 256, + 'tries' => 5, + 'nice' => 0, + ], + + 'supervisor-battle-reward-item-handler' => [ + 'connection' => 'battle_reward_item_handler', + 'queue' => ['battle_reward_item_handler'], + 'balance' => 'auto', + 'maxProcesses' => 25, + 'memory' => 256, + 'tries' => 5, + 'nice' => 0, + ], + ], ], + ]; diff --git a/config/queue.php b/config/queue.php index d9a717e4c..84c2142ef 100755 --- a/config/queue.php +++ b/config/queue.php @@ -69,7 +69,7 @@ 'kingdom_jobs' => [ 'driver' => 'redis', 'connection' => 'kingdom_jobs', - 'queue' => env('REDIS_QUEUE', 'default'), + 'queue' => 'kingdom_jobs', 'retry_after' => 90, 'block_for' => null, ], @@ -77,11 +77,67 @@ 'weekly_spawn' => [ 'driver' => 'redis', 'connection' => 'weekly_spawn', - 'queue' => env('REDIS_QUEUE', 'default'), + 'queue' => 'weekly_spawn', 'retry_after' => 90, 'block_for' => null, ], + 'battle_reward_xp' => [ + 'driver' => 'redis', + 'connection' => 'default', + 'queue' => 'battle_reward_xp', + 'retry_after' => 1200, + 'block_for' => null, + ], + + 'battle_reward_currencies' => [ + 'driver' => 'redis', + 'connection' => 'default', + 'queue' => 'battle_reward_currencies', + 'retry_after' => 1200, + 'block_for' => null, + ], + + 'battle_reward_factions' => [ + 'driver' => 'redis', + 'connection' => 'default', + 'queue' => 'battle_reward_factions', + 'retry_after' => 1200, + 'block_for' => null, + ], + + 'battle_reward_global_event' => [ + 'driver' => 'redis', + 'connection' => 'default', + 'queue' => 'battle_reward_global_event', + 'retry_after' => 1200, + 'block_for' => null, + ], + + 'battle_reward_location_handlers' => [ + 'driver' => 'redis', + 'connection' => 'default', + 'queue' => 'battle_reward_location_handlers', + 'retry_after' => 1200, + 'block_for' => null, + ], + + 'battle_reward_weekly_fights' => [ + 'driver' => 'redis', + 'connection' => 'default', + 'queue' => 'battle_reward_weekly_fights', + 'retry_after' => 1200, + 'block_for' => null, + ], + + 'battle_reward_item_handler' => [ + 'driver' => 'redis', + 'connection' => 'default', + 'queue' => 'battle_reward_item_handler', + 'retry_after' => 1200, + 'block_for' => null, + ], + 'long_running' => [ 'driver' => 'redis', 'connection' => 'default', @@ -92,6 +148,7 @@ ], + /* |-------------------------------------------------------------------------- | Failed Queue Jobs diff --git a/tests/Unit/Game/BattleRewardProcessing/Services/BattleRewardServiceTest.php b/tests/Unit/Game/BattleRewardProcessing/Services/BattleRewardServiceTest.php index 915225425..47799f2d9 100644 --- a/tests/Unit/Game/BattleRewardProcessing/Services/BattleRewardServiceTest.php +++ b/tests/Unit/Game/BattleRewardProcessing/Services/BattleRewardServiceTest.php @@ -66,7 +66,7 @@ public function testShouldNotUpdateCharacterCurrenciesWhenNotLoggedIn() Queue::fake(); - $this->battleRewardService->setUp($monster, $character)->handleBaseRewards(); + $this->battleRewardService->setUp($character->id, $monster->id)->handleBaseRewards(); Event::assertNotDispatched(UpdateCharacterCurrenciesEvent::class); } @@ -102,9 +102,7 @@ public function testShouldReceiveLessXpWhenTrainingASkill() Queue::fake(); - $this->battleRewardService->setUp($monster, $character)->handleBaseRewards(); - - Event::assertDispatched(UpdateCharacterCurrenciesEvent::class); + $this->battleRewardService->setUp($character->id, $monster->id)->handleBaseRewards(); $character = $character->refresh(); @@ -144,11 +142,11 @@ public function testShouldReceiveFullXpWhenTrainingASkillThatIsMaxLevel() Event::fake(); - Queue::fake(); - - $this->battleRewardService->setUp($monster, $character)->handleBaseRewards(); + Queue::fake([ + BattleItemHandler::class, + ]); - Event::assertDispatched(UpdateCharacterCurrenciesEvent::class); + $this->battleRewardService->setUp($character->id, $monster->id)->handleBaseRewards(); $character = $character->refresh(); @@ -176,9 +174,11 @@ public function testShouldUpdateCharacterCurrenciesWhenLoggedIn() Event::fake(); - Queue::fake(); + Queue::fake([ + BattleItemHandler::class, + ]); - $this->battleRewardService->setUp($monster, $character)->handleBaseRewards(); + $this->battleRewardService->setUp($character->id, $monster->id)->handleBaseRewards(); Event::assertDispatched(UpdateCharacterCurrenciesEvent::class); } @@ -193,9 +193,11 @@ public function testBattleItemRewardHandlerIsDispatched() Event::fake(); - Queue::fake(); + Queue::fake([ + BattleItemHandler::class, + ]); - $this->battleRewardService->setUp($monster, $character)->handleBaseRewards(); + $this->battleRewardService->setUp($character->id, $monster->id)->handleBaseRewards(); Queue::assertPushed(BattleItemHandler::class); } @@ -210,9 +212,11 @@ public function testShouldGetFactionPoints() Event::fake(); - Queue::fake(); + Queue::fake([ + BattleItemHandler::class, + ]); - $this->battleRewardService->setUp($monster, $character)->handleBaseRewards(); + $this->battleRewardService->setUp($character->id, $monster->id)->handleBaseRewards(); $character = $character->refresh(); @@ -233,9 +237,11 @@ public function testShouldNotUpdateGlobalEventParticipationWhenNoEventIsRunning( Event::fake(); - Queue::fake(); + Queue::fake([ + BattleItemHandler::class, + ]); - $this->battleRewardService->setUp($monster, $character)->handleBaseRewards(); + $this->battleRewardService->setUp($character->id, $monster->id)->handleBaseRewards(); $character = $character->refresh(); @@ -256,9 +262,11 @@ public function testShouldNotUpdateGlobalEventParticipationWhenNoGlobalEventIsRu Event::fake(); - Queue::fake(); + Queue::fake([ + BattleItemHandler::class, + ]); - $this->battleRewardService->setUp($monster, $character)->handleBaseRewards(); + $this->battleRewardService->setUp($character->id, $monster->id)->handleBaseRewards(); $character = $character->refresh(); @@ -294,9 +302,11 @@ public function testShouldUpdateGlobalEventParticipation() Event::fake(); - Queue::fake(); + Queue::fake([ + BattleItemHandler::class, + ]); - $this->battleRewardService->setUp($monster, $character)->handleBaseRewards(); + $this->battleRewardService->setUp($character->id, $monster->id)->handleBaseRewards(); $character = $character->refresh(); @@ -346,9 +356,11 @@ public function testShouldUpdateGlobalEventParticipationWhenParticipationExists( Event::fake(); - Queue::fake(); + Queue::fake([ + BattleItemHandler::class, + ]); - $this->battleRewardService->setUp($monster, $character)->handleBaseRewards(); + $this->battleRewardService->setUp($character->id, $monster->id)->handleBaseRewards(); $character = $character->refresh(); @@ -372,9 +384,11 @@ public function testNoFactionRewardsGivenWhenCharacterIsInPurgatory() Event::fake(); - Queue::fake(); + Queue::fake([ + BattleItemHandler::class, + ]); - $this->battleRewardService->setUp($monster, $character)->handleBaseRewards(); + $this->battleRewardService->setUp($character->id, $monster->id)->handleBaseRewards(); $character = $character->refresh();