Skip to content

Commit

Permalink
Started adding the global event goal.
Browse files Browse the repository at this point in the history
- 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
AdamKyle committed Nov 5, 2023
1 parent 960a883 commit 1553951
Show file tree
Hide file tree
Showing 21 changed files with 418 additions and 65 deletions.
4 changes: 4 additions & 0 deletions app/Flare/Models/Character.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ public function classSpecialsEquipped() {
return $this->hasMany(CharacterClassSpecialtiesEquipped::class);
}

public function globalEventParticipation() {
return $this->hasOne(GlobalEventParticipation::class, 'character_id', 'id');
}

public function getIsAutoBattlingAttribute() {
return !is_null(CharacterAutomation::where('character_id', $this->id)->first());
}
Expand Down
63 changes: 63 additions & 0 deletions app/Flare/Models/GlobalEventGoal.php
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');
}
}
41 changes: 41 additions & 0 deletions app/Flare/Models/GlobalEventParticipation.php
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');
}
}
2 changes: 1 addition & 1 deletion app/Flare/Values/LocationEffectValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class LocationEffectValue {
self::INCREASE_STATS_BY_FIVE_HUNDRED => '500pts and 5% towards resistances and skills.',
self::INCREASE_STATS_BY_ONE_THOUSAND => '1,000pts and 8% towards resistances and skills. ',
self::INCREASE_STATS_BY_TWO_THOUSAND => '2,000pts and 10% towards resistances and skills.',
self::INCREASE_STATS_BY_THREE_THOUSAND => '3,000pts and 14$ towards resistances and skills.',
self::INCREASE_STATS_BY_THREE_THOUSAND => '3,000pts and 14% towards resistances and skills.',
];

protected static $integerValues = [
Expand Down
2 changes: 1 addition & 1 deletion app/Flare/Values/MapNameValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public function getMapModifers(): array {
'xp_bonus' => 0.50,
'skill_training_bonus' => 0.50,
'drop_chance_bonus' => 0.30,
'enemy_stat_bonus' => 0.30,
'enemy_stat_bonus' => 0.35,
'character_attack_reduction' => 0.30,
'required_location_id' => null,
];
Expand Down
119 changes: 119 additions & 0 deletions app/Game/Battle/Handlers/GlobalEventParticipationHandler.php
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.'));
}
}
}
}
7 changes: 7 additions & 0 deletions app/Game/Battle/Providers/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use App\Flare\Builders\Character\CharacterCacheData;
use App\Flare\Builders\RandomAffixGenerator;
use App\Flare\Builders\RandomItemDropBuilder;
use App\Flare\Models\GlobalEventParticipation;
use App\Flare\ServerFight\Monster\BuildMonster;
use App\Flare\ServerFight\MonsterPlayerFight;
use App\Flare\ServerFight\Pvp\PvpAttack;
Expand Down Expand Up @@ -54,6 +55,12 @@ public function register()
);
});

$this->app->bind(GlobalEventParticipation::class, function($app) {
return new GlobalEventParticipation(
$app->make(RandomAffixGenerator::class),
);
});

$this->app->bind(GoldRush::class, function($app) {
return new GoldRush();
});
Expand Down
15 changes: 8 additions & 7 deletions app/Game/BattleRewardProcessing/Providers/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Game\BattleRewardProcessing\Providers;


use App\Flare\Models\GlobalEventGoal;
use Illuminate\Support\ServiceProvider as ApplicationServiceProvider;
use App\Flare\Services\CharacterRewardService;
use App\Game\Battle\Handlers\FactionHandler;
Expand All @@ -12,8 +12,7 @@
use App\Game\Core\Services\GoldRush;
use App\Game\Mercenaries\Services\MercenaryService;

class ServiceProvider extends ApplicationServiceProvider
{
class ServiceProvider extends ApplicationServiceProvider {
/**
* Register any application services.
*
Expand All @@ -22,15 +21,16 @@ class ServiceProvider extends ApplicationServiceProvider
public function register() {


$this->app->bind(BattleRewardService::class, function($app) {
$this->app->bind(BattleRewardService::class, function ($app) {
return new BattleRewardService(
$app->make(FactionHandler::class),
$app->make(CharacterRewardService::class),
$app->make(GoldRush::class)
$app->make(GoldRush::class),
$app->make(GlobalEventGoal::class)
);
});

$this->app->bind(SecondaryRewardService::class, function($app) {
$this->app->bind(SecondaryRewardService::class, function ($app) {
return new SecondaryRewardService(
$app->make(MercenaryService::class),
$app->make(ClassRankService::class),
Expand All @@ -43,5 +43,6 @@ public function register() {
*
* @return void
*/
public function boot(){}
public function boot() {
}
}
44 changes: 37 additions & 7 deletions app/Game/BattleRewardProcessing/Services/BattleRewardService.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
use App\Flare\Models\GameMap;
use App\Flare\Models\Monster;
use App\Flare\Models\Character;
use App\Flare\Models\Event;
use App\Flare\Models\GlobalEventGoal;
use App\Game\Core\Services\GoldRush;
use App\Game\Battle\Handlers\FactionHandler;
use App\Flare\Services\CharacterRewardService;
use App\Flare\Values\EventType;
use App\Game\Battle\Handlers\GlobalEventParticipationHandler;
use App\Game\Battle\Jobs\BattleItemHandler;

class BattleRewardService {
Expand All @@ -18,11 +22,16 @@ class BattleRewardService {
private FactionHandler $factionHandler;
private CharacterRewardService $characterRewardService;
private GoldRush $goldRush;

public function __construct(FactionHandler $factionHandler, CharacterRewardService $characterRewardService, GoldRush $goldRush) {
$this->factionHandler = $factionHandler;
$this->characterRewardService = $characterRewardService;
$this->goldRush = $goldRush;
private GlobalEventParticipationHandler $globalEventParticipationHandler;

public function __construct(FactionHandler $factionHandler,
CharacterRewardService $characterRewardService,
GoldRush $goldRush,
GlobalEventParticipationHandler $globalEventParticipationHandler) {
$this->factionHandler = $factionHandler;
$this->characterRewardService = $characterRewardService;
$this->goldRush = $goldRush;
$this->globalEventParticipationHandler = $globalEventParticipationHandler;
}

public function setUp(Monster $monster, Character $character): BattleRewardService {
Expand Down Expand Up @@ -52,12 +61,33 @@ public function handleBaseRewards() {
}

protected function handleFactionRewards() {
if ($this->gameMap->mapType()->isPurgatory()) {
if (
$this->gameMap->mapType()->isPurgatory() ||
$this->gameMap->mapType()->isTheIcePlane()
) {
return;
}

$this->factionHandler->handleFaction($this->character, $this->monster);

$this->character = $this->character->refresh();
}

protected function handleGlobalEventGoals() {
$event = Event::whereIn('type', [
EventType::WINTER_EVENT,
])->first();

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

$globalEventGoal = GlobalEventGoal::where('event_type', $event->type)->first();

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

$this->globalEventParticipationHandler->handleGlobalEventParticipation($this->character->refresh(), $globalEventGoal->refresh());
}
}
Loading

0 comments on commit 1553951

Please sign in to comment.