Skip to content

Commit

Permalink
Added more quests
Browse files Browse the repository at this point in the history
- Added lots of little fixes.
- Added logic for ending the winter event.
- Added logic for players who have the most kingdoms when the event ends.
- Added logic for minimum requirment of kills to get a phase reward.
  • Loading branch information
AdamKyle committed Nov 12, 2023
1 parent 272a524 commit 81df126
Show file tree
Hide file tree
Showing 29 changed files with 663 additions and 42 deletions.
2 changes: 2 additions & 0 deletions app/Admin/Services/ItemsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,13 @@ public function formInputs(): array {
ItemEffectsValue::GET_COPPER_COINS,
ItemEffectsValue::ENTER_PURGATORY_HOUSE,
ItemEffectsValue::HIDE_CHAT_LOCATION,
ItemeffectsValue::SETTLE_IN_ICE_PLANE,
],
'specialtyTypes' => [
ItemSpecialtyType::HELL_FORGED,
ItemSpecialtyType::PURGATORY_CHAINS,
ItemSpecialtyType::PIRATE_LORD_LEATHER,
ItemSpecialtyType::CORRUPTED_ICE,
],
'itemSkills' => ItemSkill::whereNull('parent_id')->get(),
'locations' => Location::select('name', 'id')->get(),
Expand Down
35 changes: 35 additions & 0 deletions app/Console/Commands/TestQuery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace App\Console\Commands;

use App\Flare\Models\Character;
use App\Flare\Models\GameMap;
use App\Flare\Values\MapNameValue;
use Illuminate\Console\Command;

class TestQuery extends Command {
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'app:test-query';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';

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

$gameMap = GameMap::where('name', MapNameValue::ICE_PLANE)->first();

$result = Character::join('maps', 'maps.character_id', '=', 'characters.id')
->where('maps.game_map_id', $gameMap->id)->get();
}
}
1 change: 1 addition & 0 deletions app/Flare/View/Livewire/Admin/Monsters/MonstersTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public function filters(): array {
'Shadow Plane Raid Monsters' => 'Shadow Plane Raid Monsters',
'Hell Raid Monsters' => 'Hell Raid Monsters',
'Purgatory Raid Monsters' => 'Purgatory Raid Monsters',
'The Ice Plane Raid Monsters' => 'The Ice Plane Raid Monsters',
])->filter(function (Builder $builder, string $value) {
if (str_contains($value, 'Celestials')) {

Expand Down
75 changes: 65 additions & 10 deletions app/Game/Battle/Handlers/GlobalEventParticipationHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,40 @@
use App\Flare\Models\GlobalEventGoal;
use App\Flare\Models\Item;
use App\Flare\Values\RandomAffixDetails;
use App\Game\Events\Events\UpdateEventGoalProgress;
use App\Game\Events\Services\EventGoalsService;
use App\Game\Messages\Events\ServerMessageEvent;

class GlobalEventParticipationHandler {


/**
* @var RandomAffixGenerator $randomAffixGenerator
*/
private RandomAffixGenerator $randomAffixGenerator;

public function __construct(RandomAffixGenerator $randomAffixGenerator) {
/**
* @var EventGoalsService $eventGoalService
*/
private EventGoalsService $eventGoalService;

/**
* @param RandomAffixGenerator $randomAffixGenerator
* @param EventGoalsService $eventGoalService
*/
public function __construct(RandomAffixGenerator $randomAffixGenerator, EventGoalsService $eventGoalService) {
$this->randomAffixGenerator = $randomAffixGenerator;

$this->eventGoalService = $eventGoalService;
}

/**
* Handle updating the global; event participation
*
* @param Character $character
* @param GlobalEventGoal $globalEventGoal
* @return void
*/
public function handleGlobalEventParticipation(Character $character, GlobalEventGoal $globalEventGoal) {
if ($globalEventGoal->total_kills >= $globalEventGoal->max_kills) {
return;
Expand All @@ -31,6 +55,8 @@ public function handleGlobalEventParticipation(Character $character, GlobalEvent
'current_kills' => 1,
]);

event(new UpdateEventGoalProgress($this->eventGoalService->getEventGoalData()));

return;
}

Expand All @@ -49,17 +75,42 @@ public function handleGlobalEventParticipation(Character $character, GlobalEvent

$this->rewardCharactersParticipating($globalEventGoal->refresh());
}

event(new UpdateEventGoalProgress($this->eventGoalService->getEventGoalData()));
}

/**
* Reward only those who have met the required amount of kills or higher.
*
* @param GlobalEventGoal $globalEventGoal
* @return void
*/
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);

$amountOfKills = $globalEventGoal->globalEventParticipation
->where('character_id', $character->id)
->first()
->current_kills;

if ($amountOfKills >= $this->eventGoalService->fetchKillAmountNeeded($globalEventGoal)) {
$this->rewardForCharacter($character, $globalEventGoal);
}
}
});

$this->resetParticipationAtPhaseCompletion($globalEventGoal);
}

/**
* Generate reward for the character.
*
* @param Character $character
* @param GlobalEventGoal $globalEventGoal
* @return void
*/
protected function rewardForCharacter(Character $character, GlobalEventGoal $globalEventGoal) {
$randomAffixGenerator = $this->randomAffixGenerator->setCharacter($character);

Expand Down Expand Up @@ -89,9 +140,7 @@ protected function rewardForCharacter(Character $character, GlobalEventGoal $glo
'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.'));
}
event(new ServerMessageEvent($character->user, 'You were rewarded with an item of Unique power for participating in the current events global goal.'));
}

if ($globalEventGoal->is_mythic) {
Expand All @@ -109,11 +158,17 @@ protected function rewardForCharacter(Character $character, GlobalEventGoal $glo
'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.'));
}
event(new ServerMessageEvent($character->user, 'You were rewarded with an item of Mythical power for participating in the current events global goal.'));
}
}

/**
* Reset the participation.
*
* @param GlobalEventGoal $globalEventGoal
* @return void
*/
private function resetParticipationAtPhaseCompletion(GlobalEventGoal $globalEventGoal) {
$globalEventGoal->globalEventParticipation()->truncate();
}
}
4 changes: 2 additions & 2 deletions app/Game/Battle/Services/BattleDrop.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ public function handleSpecialLocationQuestItem(Character $character) {

foreach ($items as $item) {
if ($this->canHaveItem($character, $item)) {
$chance = 95 - (95 * $lootingChance);
$roll = RandomNumberGenerator::generateRandomNumber(1, 100);
$chance = 999999 - (999999 * $lootingChance);
$roll = RandomNumberGenerator::generateRandomNumber(1, 1000000);

if ($roll > $chance) {
$this->attemptToPickUpItem($character, $item);
Expand Down
20 changes: 10 additions & 10 deletions app/Game/Core/Services/DropCheckService.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function __construct(BattleDrop $battleDrop, BuildMythicItem $buildMythic
$this->battleDrop = $battleDrop;
$this->buildMythicItem = $buildMythicItem;
}


/**
* Process the drop check.
Expand All @@ -80,9 +80,9 @@ public function process(Character $character, Monster $monster): void {
$this->findLocationWithEffect($characterMap);

$this->battleDrop = $this->battleDrop->setMonster($this->monster)
->setSpecialLocation($this->locationWithEffect)
->setGameMapBonus($this->gameMapBonus)
->setLootingChance($this->lootingChance);
->setSpecialLocation($this->locationWithEffect)
->setGameMapBonus($this->gameMapBonus)
->setLootingChance($this->lootingChance);

$this->handleDropChance($character);

Expand Down Expand Up @@ -146,10 +146,10 @@ public function handleDropChance(Character $character) {
*/
public function findLocationWithEffect(Map $map): void {
$this->locationWithEffect = Location::whereNotNull('enemy_strength_type')
->where('x', $map->character_position_x)
->where('y', $map->character_position_y)
->where('game_map_id', $map->game_map_id)
->first();
->where('x', $map->character_position_x)
->where('y', $map->character_position_y)
->where('game_map_id', $map->game_map_id)
->first();
}

/**
Expand All @@ -171,10 +171,10 @@ protected function canHaveMythic(bool $useLooting = false): bool {

$roll = $roll + $roll * $chance;

return $roll > 990;
return $roll > 999;
}

return $roll > 990;
return $roll > 999;
}

/**
Expand Down
68 changes: 65 additions & 3 deletions app/Game/Events/Console/Commands/EndScheduledEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@
use App\Flare\Models\Announcement;
use App\Flare\Models\ScheduledEvent;
use App\Flare\Events\UpdateScheduledEvents;
use App\Flare\Models\GameMap;
use App\Flare\Models\RaidBoss;
use App\Flare\Models\RaidBossParticipation;
use App\Game\Maps\Services\LocationService;
use App\Game\Raids\Events\CorruptLocations;
use App\Flare\Services\EventSchedulerService;
use App\Flare\Values\MapNameValue;
use App\Game\Events\Services\KingdomEventService;
use App\Game\Maps\Services\TraverseService;
use App\Game\Maps\Services\UpdateRaidMonsters;
use App\Game\Messages\Events\DeleteAnnouncementEvent;
use App\Game\Messages\Events\GlobalMessageEvent;
Expand All @@ -39,10 +43,18 @@ class EndScheduledEvent extends Command {
* @param LocationService $locationService
* @param UpdateRaidMonsters $updateRaidMonsters
* @param EventSchedulerService $eventSchedulerService
* @param KingdomEventService $kingdomEventService,
* @param TraverseService $traverseService,
* @return void
*/
public function handle(LocationService $locationService, UpdateRaidMonsters $updateRaidMonsters, EventSchedulerService $eventSchedulerService) {
$this->endScheduledEvent($locationService, $updateRaidMonsters, $eventSchedulerService);
public function handle(
LocationService $locationService,
UpdateRaidMonsters $updateRaidMonsters,
EventSchedulerService $eventSchedulerService,
KingdomEventService $kingdomEventService,
TraverseService $traverseService
) {
$this->endScheduledEvent($locationService, $updateRaidMonsters, $eventSchedulerService, $kingdomEventService, $traverseService);
}

/**
Expand All @@ -53,7 +65,14 @@ public function handle(LocationService $locationService, UpdateRaidMonsters $upd
* @param EventSchedulerService $eventSchedulerService
* @return void
*/
protected function endScheduledEvent(LocationService $locationService, UpdateRaidMonsters $updateRaidMonsters, EventSchedulerService $eventSchedulerService): void {
protected function endScheduledEvent(
LocationService $locationService,
UpdateRaidMonsters $updateRaidMonsters,
EventSchedulerService $eventSchedulerService,
KingdomEventService $kingdomEventService,
TraverseService $traverseService
): void {

$scheduledEvents = ScheduledEvent::where('end_date', '<=', now())->get();

foreach ($scheduledEvents as $event) {
Expand Down Expand Up @@ -102,6 +121,16 @@ protected function endScheduledEvent(LocationService $locationService, UpdateRai

event(new UpdateScheduledEvents($eventSchedulerService->fetchEvents()));
}

if ($eventType->isWinterEvent()) {
$this->endWinterEvent($kingdomEventService, $traverseService);

$event->update([
'currently_running' => false,
]);

event(new UpdateScheduledEvents($eventSchedulerService->fetchEvents()));
}
}
}

Expand Down Expand Up @@ -183,6 +212,39 @@ protected function endWeeklySpawnEvent() {
$event->delete();
}

/**
* End the winter event.
*
* @param KingdomEventService $kingdomEventService
* @return void
*/
protected function endWinterEvent(KingdomEventService $kingdomEventService, TraverseService $traverseService) {
$event = Event::where('type', EventType::WINTER_EVENT)->first();

$kingdomEventService->handleKingdomRewardsForEvent(MapNameValue::ICE_PLANE);

$gameMap = GameMap::where('name', MapNameValue::ICE_PLANE)->first();
$surfaceMap = GameMap::where('name', MapNameValue::SURFACE)->first();

Character::join('maps', 'maps.character_id', '=', 'characters.id')
->where('maps.game_map_id', $gameMap->id)
->chunk(100, function ($characters) use ($traverseService, $surfaceMap) {
foreach ($characters as $character) {
$traverseService->travel($surfaceMap->id, $character);
}
});

event(new GlobalMessageEvent('The Queen of Ice calls forth her twisted memories and magics to seal the gates to her realm. "My son! You have stolen the memories of my son!" She bellows as she banishes you and others from her realm!'));

$announcement = Announcement::where('event_id', $event->id)->first();

event(new DeleteAnnouncementEvent($announcement->id));

$announcement->delete();

$event->delete();
}

/**
* Set locations back to normal
*
Expand Down
40 changes: 40 additions & 0 deletions app/Game/Events/Events/UpdateEventGoalProgress.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace App\Game\Events\Events;

use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;

class UpdateEventGoalProgress implements ShouldBroadcastNow {
use Dispatchable, InteractsWithSockets, SerializesModels;


/**
* @var array $eventGoalData
*/
public array $eventGoalData;

/**
* Create a new event instance.
*
* @param User $user
* @param array $boons
*/
public function __construct(array $eventGoalData) {
$this->eventGoalData = $eventGoalData;
}

/**
* Get the channels the event should broadcast on.
*
* @return Channel|array
* @codeCoverageIgnore
*/
public function broadcastOn() {
return new PresenceChannel('update-event-goal-progress');
}
}
Loading

0 comments on commit 81df126

Please sign in to comment.