Skip to content

Commit

Permalink
various fixes to the way the event goal reward system works
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamKyle committed Dec 17, 2023
1 parent e0c9d2f commit d8ec8cf
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 22 deletions.
130 changes: 130 additions & 0 deletions app/Console/AfterDeployment/GivePhaseRewardsForCharacters.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<?php

namespace App\Console\AfterDeployment;

use App\Flare\Builders\RandomAffixGenerator;
use App\Flare\Models\Character;
use App\Flare\Models\Event;
use App\Flare\Models\GlobalEventGoal;
use App\Flare\Models\Item;
use App\Flare\Values\RandomAffixDetails;
use App\Game\Events\Values\EventType;
use App\Game\Messages\Events\ServerMessageEvent;
use Illuminate\Console\Command;

class GivePhaseRewardsForCharacters extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'give:phase-rewards-for-characters {eventGoalAmount}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'gives rewards for global event goal rewards';

private RandomAffixGenerator $randomAffixGenerator;

/**
* Execute the console command.
*/
public function handle(RandomAffixGenerator $randomAffixGenerator) {

$this->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));
}
}
}
1 change: 0 additions & 1 deletion app/Flare/Models/GlobalEventGoal.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)));
Expand All @@ -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) {

Expand All @@ -114,8 +118,6 @@ protected function rewardCharactersParticipating(GlobalEventGoal $globalEventGoa
}
}
});

$this->resetParticipationAtPhaseCompletion($globalEventGoal);
}

/**
Expand All @@ -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();
Expand All @@ -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();

Expand All @@ -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();

Expand All @@ -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,
Expand All @@ -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();
}
}
2 changes: 2 additions & 0 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -48,6 +49,7 @@ public function register(): void {
UpdateCharacterCurrencies::class,
RebalanceQuestCurrencyCostsAndRewards::class,
KickOffEventGoalForWinterEvent::class,
GivePhaseRewardsForCharacters::class,

// Development Commands:
CreateCharacter::class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ export default class GemCrafting extends React.Component<any, any> {
}

craft() {

if (this.state.selectedTier === 0) {
return this.setState({
error_message: 'Please select a tier.'
});
}

this.setState({
isCrafting: true,
errorMessage: null,
Expand Down

0 comments on commit d8ec8cf

Please sign in to comment.