Skip to content

Commit

Permalink
More tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamKyle committed Oct 12, 2024
1 parent ab1f57e commit d737a92
Show file tree
Hide file tree
Showing 14 changed files with 368 additions and 46 deletions.
22 changes: 12 additions & 10 deletions app/Game/Events/Console/Commands/EndScheduledEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ protected function endRaid(ScheduledEvent $event, LocationService $locationServi

$raid = $event->raid;

event(new GlobalMessageEvent('The Raid: '.$raid->name.' is now ending! Don\'t worry, the raid will be back soon. Check the event calendar for the next time!'));
event(new GlobalMessageEvent('The Raid: ' . $raid->name . ' is now ending! Don\'t worry, the raid will be back soon. Check the event calendar for the next time!'));

$this->unCorruptLocations($raid, $locationService);

Expand Down Expand Up @@ -315,12 +315,13 @@ protected function endWeeklySpawnEvent(Event $event): void
/**
* End the winter event.
*/
protected function endWinterEvent(KingdomEventService $kingdomEventService,
protected function endWinterEvent(
KingdomEventService $kingdomEventService,
TraverseService $traverseService,
ExplorationAutomationService $explorationAutomationService,
FactionLoyaltyService $factionLoyaltyService,
Event $event): void
{
Event $event
): void {

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

Expand Down Expand Up @@ -374,12 +375,13 @@ protected function endWinterEvent(KingdomEventService $kingdomEventService,
/**
* End the delusional memories' event.
*/
protected function endDelusionalEvent(KingdomEventService $kingdomEventService,
protected function endDelusionalEvent(
KingdomEventService $kingdomEventService,
TraverseService $traverseService,
ExplorationAutomationService $explorationAutomationService,
FactionLoyaltyService $factionLoyaltyService,
Event $event): void
{
Event $event
): void {

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

Expand Down Expand Up @@ -430,14 +432,15 @@ protected function endDelusionalEvent(KingdomEventService $kingdomEventService,
$this->updateAllCharacterStatuses();
}

protected function endFeedBackEvent(CreateSurveySnapshot $createSurveySnapshot): void {
protected function endFeedBackEvent(CreateSurveySnapshot $createSurveySnapshot): void
{
event(new GlobalMessageEvent('The Creator thanks all his players for their valuable feedback. At this time the survey has closed! Feedback is being gathered as we speak'));

$createSurveySnapshot->createSnapShop();

SubmittedSurvey::truncate();

Character::chunkById(250, function($characters) {
Character::chunkById(250, function ($characters) {
foreach ($characters as $character) {
$character->user()->update([
'is_showing_survey' => false,
Expand All @@ -453,7 +456,6 @@ protected function endFeedBackEvent(CreateSurveySnapshot $createSurveySnapshot):
refreshing and clicking the left side bar, there will be a new menu option for the survey stats. Once The Creator has a chance to look
at them, you will find a button at the bottom called The Creators Response, this will be a detailed post about how the stats impact the
direction Tlessa goes in, in order for it be the best PBBG out there!'));

}

private function updateAllCharacterStatuses(): void
Expand Down
17 changes: 6 additions & 11 deletions app/Game/Events/Console/Commands/RestartGlobalEventGoal.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,6 @@ private function updateCharactersGlobalMapEvents(EventGoalsService $eventGoalsSe
*/
private function handleRegularGlobalEvent(GlobalEventGoal $globalEventGoal): void
{
if ($globalEventGoal->total_kills < $globalEventGoal->max_kills) {
return;
}

$globalEventGoal->update([
'next_reward_at' => $globalEventGoal->reward_every,
]);
Expand All @@ -131,7 +127,7 @@ private function handleRegularGlobalEvent(GlobalEventGoal $globalEventGoal): voi
$globalEvent->globalEventKills()->truncate();

event(new GlobalMessageEvent(
'Global Event Goal for: '.$globalEvent->eventType()->getNameForEvent().' Players can now participate again and earn
'Global Event Goal for: ' . $globalEvent->eventType()->getNameForEvent() . ' Players can now participate again and earn
Rewards for meeting the various phases! How exciting!'
));
}
Expand Down Expand Up @@ -189,12 +185,11 @@ private function handleStepBaseGlobalEvent(Event $event): void

$gameMap = GameMap::where('only_during_event_type', $event->type)->first();

event(new GlobalMessageEvent('Global Event Goal for: '.$globalEventGoal->eventType()->getNameForEvent().
' Players can now participate in the new step: '.strtoupper($newStep).'! How exciting!'));
event(new GlobalMessageEvent('Players can participate by going to the map: '.$gameMap->name.
' via Traverse (under the map for desktop, under the map inside Map Movement action drop down for mobile)'.' '.
'And completing either Fighting monsters, Crafting: Weapons, Spells, Armour and Rings or enchanting the already crafted items.'.
event(new GlobalMessageEvent('Global Event Goal for: ' . $globalEventGoal->eventType()->getNameForEvent() .
' Players can now participate in the new step: ' . strtoupper($newStep) . '! How exciting!'));
event(new GlobalMessageEvent('Players can participate by going to the map: ' . $gameMap->name .
' via Traverse (under the map for desktop, under the map inside Map Movement action drop down for mobile)' . ' ' .
'And completing either Fighting monsters, Crafting: Weapons, Spells, Armour and Rings or enchanting the already crafted items.' .
' You can see the event goal for the map specified by being on the map and clicking the Event Goal tab from the map.'));

}
}
10 changes: 5 additions & 5 deletions app/Game/Events/Jobs/InitiateDelusionalMemoriesEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ public function kickOffGlobalEventGoal(): void

event(new GlobalMessageEvent('"Child! We need you!" The Red Hawk Soldier looks at you. There is a fear in his eyes. "Please child. Fight with us!"', 'raid-global-message'));

event(new GlobalMessageEvent('While on the Delusional Memories Plane, characters who kill: ANY CREATURE in either manual or exploration, will increase the new: Global Event Goal. '.
'Players will be rewarded with random Corrupted Ice Gear when specific milestones are reached. '.
event(new GlobalMessageEvent('While on the Delusional Memories Plane, characters who kill: ANY CREATURE in either manual or exploration, will increase the new: Global Event Goal. ' .
'Players will be rewarded with random Corrupted Ice Gear when specific milestones are reached. ' .
'Players who participate and help the battle progress, will move the event forward to a crafting and then enchanting and then back to fighting - and around we go again.'));

event(new GlobalMessageEvent('Players can participate by going to the map: '.$gameMap->name.
' via Traverse (under the map for desktop, under the map inside Map Movement action drop down for mobile)'.' '.
'And completing either Fighting monsters, Crafting: Weapons, Spells, Armour and Rings or enchanting the already crafted items.'.
event(new GlobalMessageEvent('Players can participate by going to the map: ' . $gameMap->name .
' via Traverse (under the map for desktop, under the map inside Map Movement action drop down for mobile)' . ' ' .
'And completing either Fighting monsters, Crafting: Weapons, Spells, Armour and Rings or enchanting the already crafted items.' .
' You can see the event goal for the map specified by being on the map and clicking the Event Goal tab from the map.'));
}
}
1 change: 0 additions & 1 deletion app/Game/Events/Jobs/InitiateWeeklyFactionLoyaltyEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public function __construct(int $eventId)

public function handle(): void
{

$event = ScheduledEvent::find($this->eventId);

if (is_null($event)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function removePledge(Character $character, Faction $faction): array
]);

return $this->successResult([
'message' => 'No longer pledged to: '.$faction->gameMap->name.'.',
'message' => 'No longer pledged to: ' . $faction->gameMap->name . '.',
'factions' => $character->refresh()->factions->transform(function ($faction) {
$faction->map_name = $faction->gameMap->name;
$faction->is_pledged = $faction->character->factionLoyalties()->where('is_pledged', true)->exists();
Expand Down Expand Up @@ -114,7 +114,7 @@ public function assistNpc(Character $character, FactionLoyaltyNpc $factionLoyalt
$result = $this->getLoyaltyInfoForPlane($character->refresh());

return $this->successResult([
'message' => 'You are now assisting '.$factionLoyaltyNpc->npc->real_name.' with their tasks!',
'message' => 'You are now assisting ' . $factionLoyaltyNpc->npc->real_name . ' with their tasks!',
'faction_loyalty' => $result['faction_loyalty'],
]);
}
Expand All @@ -135,7 +135,7 @@ public function stopAssistingNpc(Character $character, FactionLoyaltyNpc $factio
$result = $this->getLoyaltyInfoForPlane($character->refresh());

return $this->successResult([
'message' => 'You stopped assisting '.$factionLoyaltyNpc->npc->real_name.' with their tasks. They are sad but understand.',
'message' => 'You stopped assisting ' . $factionLoyaltyNpc->npc->real_name . ' with their tasks. They are sad but understand.',
'faction_loyalty' => $result['faction_loyalty'],
]);
}
Expand Down Expand Up @@ -197,7 +197,7 @@ public function pledgeLoyalty(Character $character, Faction $faction): array
}

return $this->successResult([
'message' => 'Pledged to: '.$factionLoyalty->faction->gameMap->name.'.',
'message' => 'Pledged to: ' . $factionLoyalty->faction->gameMap->name . '.',
'factions' => $character->refresh()->factions->transform(function ($faction) {
$faction->map_name = $faction->gameMap->name;
$faction->is_pledged = $faction->character->factionloyalties()->where('is_pledged', true)->exists();
Expand Down Expand Up @@ -296,10 +296,6 @@ protected function createCraftingTasks(string $gameMapName): array
$amount = ceil($amount / 2);
}

if ($amount <= 0) {
$amount = 5;
}

$tasks[] = [
'type' => $item->type,
'item_name' => $item->affix_name,
Expand Down Expand Up @@ -355,10 +351,6 @@ protected function createBountyTasks(Character $character, GameMap $gameMap): ar
$amount = ceil($amount / 2);
}

if ($amount <= 0) {
$amount = 5;
}

$tasks[] = [
'type' => 'bounty',
'monster_name' => $monster->name,
Expand Down
80 changes: 79 additions & 1 deletion tests/Console/Events/EndScheduledEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ public function testEndWeeklyFactionLoyaltyEvent()
$this->assertFalse($scheduledEvent->refresh()->currently_running);
}

public function testEndFeedbackEventWithSubmittedSurveys() {
public function testEndFeedbackEventWithSubmittedSurveys()
{
$this->deleteOtherGameMaps();

$scheduledEvent = $this->createScheduledEvent([
Expand Down Expand Up @@ -534,7 +535,84 @@ public function testEndWinterEventWhilePledgedToFactionAndHelpingNPc()
$this->assertFalse($scheduledEvent->refresh()->currently_running);
$this->assertEmpty(Event::all());
$this->assertEmpty(Announcement::all());
}

public function testEndWinterEventWhileNFactionLoayltyExists()
{
$this->deleteOtherGameMaps();

// We go back to this map when the event ends.
$this->createGameMap([
'name' => MapNameValue::SURFACE,
]);

$icePlane = $this->createGameMap([
'name' => MapNameValue::ICE_PLANE,
]);

$character = (new CharacterFactory)->createBaseCharacter()
->assignFactionSystem()
->givePlayerLocation(16, 16, $icePlane)
->kingdomManagement()
->assignKingdom([
'game_map_id' => $icePlane->id,
])
->assignBuilding()
->assignUnits()
->getCharacter();

$monsterCache = [
MapNameValue::SURFACE => [$this->createMonster()],
];

Cache::put('monsters', $monsterCache);

$this->instance(
MapTileValue::class,
Mockery::mock(MapTileValue::class, function (MockInterface $mock) {
$mock->shouldReceive('canWalkOnWater')->andReturn(true);
$mock->shouldReceive('canWalkOnDeathWater')->andReturn(true);
$mock->shouldReceive('canWalkOnMagma')->andReturn(true);
$mock->shouldReceive('isPurgatoryWater')->andReturn(false);
$mock->shouldReceive('isTwistedMemoriesWater')->andReturn(false);
$mock->shouldReceive('isDelusionalMemoriesWater')->andReturn(false);
$mock->shouldReceive('getTileColor')->andReturn('000');
})
);

$scheduledEvent = $this->createScheduledEvent([
'event_type' => EventType::WINTER_EVENT,
'start_date' => now()->addMinutes(5),
'currently_running' => true,
]);

$event = $this->createEvent([
'type' => EventType::WINTER_EVENT,
'started_at' => now(),
'ends_at' => now()->subMinute(10),
]);

$this->createAnnouncement([
'event_id' => $event->id,
]);

$this->createItem(['specialty_type' => ItemSpecialtyType::CORRUPTED_ICE, 'type' => WeaponTypes::HAMMER]);

$character = $character->refresh();

$this->artisan('end:scheduled-event');

$character = $character->refresh();

$this->assertNotEmpty($character->inventory->slots->where('item.specialty_type', ItemSpecialtyType::CORRUPTED_ICE)->all());
$this->assertEmpty($character->kingdoms);
$this->assertEquals(GameMap::where('name', MapNameValue::SURFACE)->first()->id, $character->map->game_map_id);

$this->assertEmpty($character->factionLoyalties()->where('is_pledged', true)->get());

$this->assertFalse($scheduledEvent->refresh()->currently_running);
$this->assertEmpty(Event::all());
$this->assertEmpty(Announcement::all());
}

protected function deleteOtherGameMaps(): void
Expand Down
28 changes: 28 additions & 0 deletions tests/Console/Events/ProcessScheduledEventsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,32 @@ public function testDelusionalMemoriesEvent()
$this->assertGreaterThan(0, Announcement::count());
$this->assertGreaterThan(0, GlobalEventGoal::count());
}

public function testWeeklyFactionEvent()
{

$this->createScheduledEvent([
'event_type' => EventType::WEEKLY_FACTION_LOYALTY_EVENT,
'start_date' => now()->addMinutes(5),
]);

$this->artisan('process:scheduled-events');

$this->assertGreaterThan(0, Event::count());
$this->assertGreaterThan(0, Announcement::count());
}

public function testWeeklyFeedBackEventEvent()
{

$this->createScheduledEvent([
'event_type' => EventType::FEEDBACK_EVENT,
'start_date' => now()->addMinutes(5),
]);

$this->artisan('process:scheduled-events');

$this->assertGreaterThan(0, Event::count());
$this->assertGreaterThan(0, Announcement::count());
}
}
58 changes: 57 additions & 1 deletion tests/Console/Events/RestartGlobalEventGoalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public function setUp(): void
parent::setUp();

$this->character = (new CharacterFactory)->createBaseCharacter()->givePlayerLocation()->getCharacter();

}

public function tearDown(): void
Expand Down Expand Up @@ -87,6 +86,63 @@ public function testResetEventGoal()
$this->assertEmpty($eventGoal->globalEventKills);
}

public function testDoNotResetEventGoalWhenMaxKillsDoMatchCurrentKills()
{

$event = $this->createEvent([
'type' => EventType::DELUSIONAL_MEMORIES_EVENT,
]);

$map = $this->createGameMap([
'name' => MapNameValue::DELUSIONAL_MEMORIES,
'only_during_event_type' => EventType::DELUSIONAL_MEMORIES_EVENT,
]);

(new CharacterFactory)->createBaseCharacter()->givePlayerLocation(16, 16, $map);

$eventGoal = $this->createGlobalEventGoal([
'max_kills' => 1000,
'reward_every' => 100,
'next_reward_at' => 100,
'event_type' => $event->type,
'item_specialty_type_reward' => ItemSpecialtyType::DELUSIONAL_SILVER,
'should_be_unique' => true,
'unique_type' => RandomAffixDetails::LEGENDARY,
'should_be_mythic' => false,
]);

$this->createGlobalEventKill([
'global_event_goal_id' => $eventGoal->id,
'character_id' => $this->character->id,
'kills' => 1000,
]);

$this->createGlobalEventParticipation([
'global_event_goal_id' => $eventGoal->id,
'character_id' => $this->character->id,
'current_kills' => 999,
]);

$this->artisan('restart:global-event-goal');

$eventGoal = $eventGoal->refresh();

$this->assertNotEmpty($eventGoal->globalEventParticipation);
$this->assertNotEmpty($eventGoal->globalEventKills);
}

public function testDoNotRestEventGoalWhenNoGlobalEventGoalExists()
{

$this->createEvent([
'type' => EventType::DELUSIONAL_MEMORIES_EVENT,
]);

$this->artisan('restart:global-event-goal');

$this->assertNull(GlobalEventGoal::first());
}

public function testDoNotRestEventGoal()
{

Expand Down
Loading

0 comments on commit d737a92

Please sign in to comment.