-
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 adding the global event goal.
- These can be configurered to have the players work together to reach a specfic goal that, at each stage, will allow the players to get a reward.
- Loading branch information
Showing
21 changed files
with
418 additions
and
65 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
namespace App\Flare\Models; | ||
|
||
use App\Flare\Values\EventType; | ||
use App\Flare\Values\ItemSpecialtyType; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Database\Eloquent\Relations\HasMany; | ||
|
||
class GlobalEventGoal extends Model { | ||
|
||
/** | ||
* The attributes that are mass assignable. | ||
* | ||
* @var array | ||
*/ | ||
protected $fillable = [ | ||
'max_kills', | ||
'reward_every_kills', | ||
'next_reward_at', | ||
'event_type', | ||
'item_specialty_type_reward', | ||
'should_be_unique', | ||
'unique_type', | ||
'should_be_mythic', | ||
]; | ||
|
||
/** | ||
* The attributes that should be cast to native types. | ||
* | ||
* @var array | ||
*/ | ||
protected $casts = [ | ||
'max_kills' => 'integer', | ||
'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', | ||
]; | ||
|
||
protected $appends = [ | ||
'total_kills', | ||
]; | ||
|
||
public function globalEventParticipation(): HasMany { | ||
return $this->hasMany(GlobalEventParticipation::class, 'global_event_goal_id', 'id'); | ||
} | ||
|
||
public function eventType(): EventType { | ||
return new EventType($this->event_type); | ||
} | ||
|
||
public function itemSpecialtyType(): itemSpecialtyType { | ||
return new ItemSpecialtyType($this->item_specialty_type_reward); | ||
} | ||
|
||
public function getTotalKillsAttribute(): int { | ||
return $this->globalEventParticipation->sum('current_kills'); | ||
} | ||
} |
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,41 @@ | ||
<?php | ||
|
||
namespace App\Flare\Models; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Database\Eloquent\Relations\BelongsTo; | ||
|
||
class GlobalEventParticipation extends Model { | ||
|
||
protected $table = 'global_event_participation'; | ||
|
||
/** | ||
* The attributes that are mass assignable. | ||
* | ||
* @var array | ||
*/ | ||
protected $fillable = [ | ||
'global_event_goal_id', | ||
'character_id', | ||
'current_kills' | ||
]; | ||
|
||
/** | ||
* The attributes that should be cast to native types. | ||
* | ||
* @var array | ||
*/ | ||
protected $casts = [ | ||
'global_event_goal_id' => 'integer', | ||
'character_id' => 'integer', | ||
'current_kills' => 'integer', | ||
]; | ||
|
||
public function globalEventGoal(): BelongsTo { | ||
return $this->belongsTo(GlobalEventGoal::class, 'global_event_goal_id', 'id'); | ||
} | ||
|
||
public function character(): BelongsTo { | ||
return $this->belongsTo(Character::class, 'character_id', 'id'); | ||
} | ||
} |
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
119 changes: 119 additions & 0 deletions
119
app/Game/Battle/Handlers/GlobalEventParticipationHandler.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,119 @@ | ||
<?php | ||
|
||
namespace App\Game\Battle\Handlers; | ||
|
||
use App\Flare\Builders\RandomAffixGenerator; | ||
use App\Flare\Models\Character; | ||
use App\Flare\Models\GlobalEventGoal; | ||
use App\Flare\Models\Item; | ||
use App\Flare\Values\RandomAffixDetails; | ||
use App\Game\Messages\Events\ServerMessageEvent; | ||
|
||
class GlobalEventParticipationHandler { | ||
|
||
private RandomAffixGenerator $randomAffixGenerator; | ||
|
||
public function __construct(RandomAffixGenerator $randomAffixGenerator) { | ||
$this->randomAffixGenerator = $randomAffixGenerator; | ||
} | ||
|
||
public function handleGlobalEventParticipation(Character $character, GlobalEventGoal $globalEventGoal) { | ||
if ($globalEventGoal->total_kills >= $globalEventGoal->max_kills) { | ||
return; | ||
} | ||
|
||
$globalEventParticipation = $character->globalEventParticipation; | ||
|
||
if ($globalEventParticipation->isEmpty()) { | ||
$character->globalEventParticipation()->create([ | ||
'global_event_goal_id' => $globalEventGoal->id, | ||
'character_id' => $character->id, | ||
'current_kills' => 1, | ||
]); | ||
|
||
return; | ||
} | ||
|
||
$character->globalEventParticipation()->update([ | ||
'current_kills' => $character->globalEventParticipation->current_kills + 1, | ||
]); | ||
|
||
$globalEventGoal = $globalEventGoal->refresh(); | ||
|
||
if ($globalEventGoal->total_kills >= $globalEventGoal->next_reward_at) { | ||
$newAmount = $globalEventGoal->next_reward_at + $globalEventGoal->reward_every_kills; | ||
|
||
$globalEventGoal->update([ | ||
'next_reward_at' => $newAmount >= $globalEventGoal->max_kills ? $globalEventGoal->max_kills : $newAmount, | ||
]); | ||
|
||
$this->rewardCharactersParticipating($globalEventGoal->refresh()); | ||
} | ||
} | ||
|
||
protected function rewardCharactersParticipating(GlobalEventGoal $globalEventGoal) { | ||
Character::whereIn('id', $globalEventGoal->pluck('globalEventParticipation.character_id')->toArray()) | ||
->chunkById(100, function ($characters) use ($globalEventGoal) { | ||
foreach ($characters as $character) { | ||
$this->rewardForCharacter($character, $globalEventGoal); | ||
} | ||
}); | ||
} | ||
|
||
protected function rewardForCharacter(Character $character, GlobalEventGoal $globalEventGoal) { | ||
$randomAffixGenerator = $this->randomAffixGenerator->setCharacter($character); | ||
|
||
$item = Item::where('specialty_type', $globalEventGoal->item_specialty_type_reward) | ||
->whereIsNull('item_prefix_id') | ||
->whereIsNull('item_suffix_id') | ||
->whereDoesntHave('appliedHolyStacks') | ||
->inRandomOrder() | ||
->first(); | ||
|
||
if (is_null($item)) { | ||
return; | ||
} | ||
|
||
if ($globalEventGoal->is_unique) { | ||
$randomAffixGenerator = $this->randomAffixGenerator->setPaidAmount(RandomAffixDetails::LEGENDARY); | ||
|
||
$newItem = $item->duplicate(); | ||
|
||
$newItem->update([ | ||
'item_prefix_id' => $randomAffixGenerator->generateAffix('prefix')->id, | ||
'item_suffix_id' => $randomAffixGenerator->generateAffix('suffix')->id, | ||
]); | ||
|
||
$character->inventory->slots()->create([ | ||
'inventory_id' => $character->inventory->id, | ||
'item_id' => $newItem->id, | ||
]); | ||
|
||
if ($character->isInventoryFull()) { | ||
event(new ServerMessageEvent($character->user, 'Your characters inventory is full. You were rewarded the Event Item either way.')); | ||
} | ||
} | ||
|
||
if ($globalEventGoal->is_mythic) { | ||
$randomAffixGenerator = $this->randomAffixGenerator->setPaidAmount(RandomAffixDetails::MYTHIC); | ||
|
||
$newItem = $item->duplicate(); | ||
|
||
$newItem->update([ | ||
'item_prefix_id' => $randomAffixGenerator->generateAffix('prefix')->id, | ||
'item_suffix_id' => $randomAffixGenerator->generateAffix('suffix')->id, | ||
]); | ||
|
||
$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 great power for participating in the current events global goal')); | ||
|
||
if ($character->isInventoryFull()) { | ||
event(new ServerMessageEvent($character->user, 'Your characters inventory is full. You were rewarded the Event Item either way.')); | ||
} | ||
} | ||
} | ||
} |
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
Oops, something went wrong.