From d8ec8cf647d11361d896d26943c53f088253180a Mon Sep 17 00:00:00 2001 From: Adam Balan Date: Sat, 16 Dec 2023 23:05:05 -0700 Subject: [PATCH] various fixes to the way the event goal reward system works --- .../GivePhaseRewardsForCharacters.php | 130 ++++++++++++++++++ app/Flare/Models/GlobalEventGoal.php | 1 - .../GlobalEventParticipationHandler.php | 43 +++--- app/Providers/AppServiceProvider.php | 2 + .../crafting-sections/gem-crafting.tsx | 7 + 5 files changed, 161 insertions(+), 22 deletions(-) create mode 100644 app/Console/AfterDeployment/GivePhaseRewardsForCharacters.php diff --git a/app/Console/AfterDeployment/GivePhaseRewardsForCharacters.php b/app/Console/AfterDeployment/GivePhaseRewardsForCharacters.php new file mode 100644 index 000000000..c4803fd95 --- /dev/null +++ b/app/Console/AfterDeployment/GivePhaseRewardsForCharacters.php @@ -0,0 +1,130 @@ +randomAffixGenerator = $randomAffixGenerator; + + $event = Event::whereIn('type', [ + EventType::WINTER_EVENT, + ])->first(); + + $globalEventGoal = GlobalEventGoal::where('event_type', $event->type)->first(); + + Character::whereIn('id', $globalEventGoal->globalEventParticipation->pluck('character_id')->toArray()) + ->chunkById(100, function ($characters) use ($globalEventGoal) { + foreach ($characters as $character) { + + $amountOfKills = $globalEventGoal->globalEventParticipation + ->where('character_id', $character->id) + ->first() + ->current_kills; + + if ($amountOfKills >= $this->fetchKillAmountNeeded($globalEventGoal)) { + $this->rewardForCharacter($character, $globalEventGoal); + } + } + }); + } + + public function fetchKillAmountNeeded(GlobalEventGoal $globalEventGoal): int { + $participationAmount = $this->argument('eventGoalAmount'); + + $participants = $globalEventGoal->globalEventParticipation()->count(); + + if ($participants > 0) { + $participationAmount = round(($participationAmount / $participants)); + } + + return $participationAmount; + } + + protected function rewardForCharacter(Character $character, GlobalEventGoal $globalEventGoal) { + + $item = Item::where('specialty_type', $globalEventGoal->item_specialty_type_reward) + ->whereNull('item_prefix_id') + ->whereNull('item_suffix_id') + ->whereDoesntHave('appliedHolyStacks') + ->inRandomOrder() + ->first(); + + if (is_null($item)) { + return; + } + + if ($globalEventGoal->should_be_unique) { + + $randomAffixGenerator = $this->randomAffixGenerator->setCharacter($character)->setPaidAmount(RandomAffixDetails::LEGENDARY); + + $newItem = $item->duplicate(); + + $newItem->update([ + 'item_prefix_id' => $randomAffixGenerator->generateAffix('prefix')->id, + 'item_suffix_id' => $randomAffixGenerator->generateAffix('suffix')->id, + ]); + + $newItem = $newItem->refresh(); + + $slot = $character->inventory->slots()->create([ + 'inventory_id' => $character->inventory->id, + 'item_id' => $newItem->id, + ]); + + event(new ServerMessageEvent($character->user, 'You were rewarded with an item of Unique power for participating in the current events global goal.', $slot->id)); + + return; + } + + if ($globalEventGoal->should_be_mythic) { + $randomAffixGenerator = $this->randomAffixGenerator->setCharacter($character)->setPaidAmount(RandomAffixDetails::MYTHIC); + + $newItem = $item->duplicate(); + + $newItem->update([ + 'item_prefix_id' => $randomAffixGenerator->generateAffix('prefix')->id, + 'item_suffix_id' => $randomAffixGenerator->generateAffix('suffix')->id, + ]); + + $newItem = $newItem->refresh(); + + $slot = $character->inventory->slots()->create([ + 'inventory_id' => $character->inventory->id, + 'item_id' => $newItem->id, + ]); + + event(new ServerMessageEvent($character->user, 'You were rewarded with an item of Mythical power for participating in the current events global goal.', $slot->id)); + } + } +} diff --git a/app/Flare/Models/GlobalEventGoal.php b/app/Flare/Models/GlobalEventGoal.php index 45b63aefb..f02c54cb2 100644 --- a/app/Flare/Models/GlobalEventGoal.php +++ b/app/Flare/Models/GlobalEventGoal.php @@ -39,7 +39,6 @@ class GlobalEventGoal extends Model { 'reward_every_kills' => 'integer', 'next_reward_at' => 'integer', 'event_type' => 'integer', - 'item_specialty_type_reward' => 'integer', 'should_be_unique' => 'boolean', 'unique_type' => 'integer', 'should_be_mythic' => 'boolean', diff --git a/app/Game/BattleRewardProcessing/Handlers/GlobalEventParticipationHandler.php b/app/Game/BattleRewardProcessing/Handlers/GlobalEventParticipationHandler.php index 4753fefcd..0c3228e61 100644 --- a/app/Game/BattleRewardProcessing/Handlers/GlobalEventParticipationHandler.php +++ b/app/Game/BattleRewardProcessing/Handlers/GlobalEventParticipationHandler.php @@ -40,6 +40,7 @@ public function __construct(RandomAffixGenerator $randomAffixGenerator, EventGoa * @param Character $character * @param GlobalEventGoal $globalEventGoal * @return void + * @throws \Exception */ public function handleGlobalEventParticipation(Character $character, GlobalEventGoal $globalEventGoal) { if ($globalEventGoal->total_kills >= $globalEventGoal->max_kills) { @@ -80,14 +81,15 @@ public function handleGlobalEventParticipation(Character $character, GlobalEvent $globalEventGoal = $globalEventGoal->refresh(); + if ($globalEventGoal->total_kills >= $globalEventGoal->next_reward_at) { $newAmount = $globalEventGoal->next_reward_at + $globalEventGoal->reward_every_kills; + $this->rewardCharactersParticipating($globalEventGoal->refresh()); + $globalEventGoal->update([ 'next_reward_at' => $newAmount >= $globalEventGoal->max_kills ? $globalEventGoal->max_kills : $newAmount, ]); - - $this->rewardCharactersParticipating($globalEventGoal->refresh()); } event(new UpdateEventGoalProgress($this->eventGoalService->getEventGoalData($character))); @@ -98,9 +100,11 @@ public function handleGlobalEventParticipation(Character $character, GlobalEvent * * @param GlobalEventGoal $globalEventGoal * @return void + * @throws \Exception */ protected function rewardCharactersParticipating(GlobalEventGoal $globalEventGoal) { - Character::whereIn('id', $globalEventGoal->pluck('globalEventParticipation.character_id')->toArray()) + + Character::whereIn('id', $globalEventGoal->globalEventParticipation->pluck('character_id')->toArray()) ->chunkById(100, function ($characters) use ($globalEventGoal) { foreach ($characters as $character) { @@ -114,8 +118,6 @@ protected function rewardCharactersParticipating(GlobalEventGoal $globalEventGoa } } }); - - $this->resetParticipationAtPhaseCompletion($globalEventGoal); } /** @@ -124,11 +126,13 @@ protected function rewardCharactersParticipating(GlobalEventGoal $globalEventGoa * @param Character $character * @param GlobalEventGoal $globalEventGoal * @return void + * @throws \Exception */ protected function rewardForCharacter(Character $character, GlobalEventGoal $globalEventGoal) { + $item = Item::where('specialty_type', $globalEventGoal->item_specialty_type_reward) - ->whereIsNull('item_prefix_id') - ->whereIsNull('item_suffix_id') + ->whereNull('item_prefix_id') + ->whereNull('item_suffix_id') ->whereDoesntHave('appliedHolyStacks') ->inRandomOrder() ->first(); @@ -137,8 +141,9 @@ protected function rewardForCharacter(Character $character, GlobalEventGoal $glo return; } - if ($globalEventGoal->is_unique) { - $randomAffixGenerator = $this->randomAffixGenerator->setPaidAmount(RandomAffixDetails::LEGENDARY); + if ($globalEventGoal->should_be_unique) { + + $randomAffixGenerator = $this->randomAffixGenerator->setCharacter($character)->setPaidAmount(RandomAffixDetails::LEGENDARY); $newItem = $item->duplicate(); @@ -147,16 +152,20 @@ protected function rewardForCharacter(Character $character, GlobalEventGoal $glo 'item_suffix_id' => $randomAffixGenerator->generateAffix('suffix')->id, ]); + $newItem = $newItem->refresh(); + $slot = $character->inventory->slots()->create([ 'inventory_id' => $character->inventory->id, 'item_id' => $newItem->id, ]); event(new ServerMessageEvent($character->user, 'You were rewarded with an item of Unique power for participating in the current events global goal.', $slot->id)); + + return; } - if ($globalEventGoal->is_mythic) { - $randomAffixGenerator = $this->randomAffixGenerator->setPaidAmount(RandomAffixDetails::MYTHIC); + if ($globalEventGoal->should_be_mythic) { + $randomAffixGenerator = $this->randomAffixGenerator->setCharacter($character)->setPaidAmount(RandomAffixDetails::MYTHIC); $newItem = $item->duplicate(); @@ -165,6 +174,8 @@ protected function rewardForCharacter(Character $character, GlobalEventGoal $glo 'item_suffix_id' => $randomAffixGenerator->generateAffix('suffix')->id, ]); + $newItem = $newItem->refresh(); + $slot = $character->inventory->slots()->create([ 'inventory_id' => $character->inventory->id, 'item_id' => $newItem->id, @@ -173,14 +184,4 @@ protected function rewardForCharacter(Character $character, GlobalEventGoal $glo event(new ServerMessageEvent($character->user, 'You were rewarded with an item of Mythical power for participating in the current events global goal.', $slot->id)); } } - - /** - * Reset the participation. - * - * @param GlobalEventGoal $globalEventGoal - * @return void - */ - private function resetParticipationAtPhaseCompletion(GlobalEventGoal $globalEventGoal) { - $globalEventGoal->globalEventParticipation()->truncate(); - } } diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 1d9fe1c07..101bdbf42 100755 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -6,6 +6,7 @@ use App\Console\AfterDeployment\AssignNewSkillsToPlayers; use App\Console\AfterDeployment\CreateCharacterAttackDataCache; use App\Console\AfterDeployment\CreateMonsterCache; +use App\Console\AfterDeployment\GivePhaseRewardsForCharacters; use App\Console\AfterDeployment\KickOffEventGoalForWinterEvent; use App\Console\AfterDeployment\RebalanceQuestCurrencyCostsAndRewards; use App\Console\AfterDeployment\ReduceAlchemyItemsCost; @@ -48,6 +49,7 @@ public function register(): void { UpdateCharacterCurrencies::class, RebalanceQuestCurrencyCostsAndRewards::class, KickOffEventGoalForWinterEvent::class, + GivePhaseRewardsForCharacters::class, // Development Commands: CreateCharacter::class, diff --git a/resources/js/game/sections/game-actions-section/components/crafting-sections/gem-crafting.tsx b/resources/js/game/sections/game-actions-section/components/crafting-sections/gem-crafting.tsx index 3951a732a..b4351af83 100755 --- a/resources/js/game/sections/game-actions-section/components/crafting-sections/gem-crafting.tsx +++ b/resources/js/game/sections/game-actions-section/components/crafting-sections/gem-crafting.tsx @@ -41,6 +41,13 @@ export default class GemCrafting extends React.Component { } craft() { + + if (this.state.selectedTier === 0) { + return this.setState({ + error_message: 'Please select a tier.' + }); + } + this.setState({ isCrafting: true, errorMessage: null,