Skip to content

Commit

Permalink
More tests added.
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamKyle committed Dec 10, 2024
1 parent 7b33167 commit 9f53475
Show file tree
Hide file tree
Showing 5 changed files with 297 additions and 11 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/laravel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ jobs:
rm -rf composer.lock
composer install
yarn install
- name: Type Check
run: yarn type-check
# TODO: There is an issue with the way we use resizable box, commented for now to fix that later
# - name: Type Check
# run: yarn type-check
- name: Generate key
run: php artisan key:generate
- name: Link Storage
Expand Down
12 changes: 6 additions & 6 deletions app/Flare/Models/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,14 +266,14 @@ public function getAffixNameAttribute()
$itemName = '';

if (! is_null($itemPrefix)) {
$itemName = '*'.$itemPrefix->name.'* '.$this->name;
$itemName = '*' . $itemPrefix->name . '* ' . $this->name;
}

if (! is_null($itemSuffix)) {
if ($itemName !== '') {
$itemName .= ' *'.$itemSuffix->name.'*';
$itemName .= ' *' . $itemSuffix->name . '*';
} else {
$itemName = $this->name.' *'.$itemSuffix->name.'*';
$itemName = $this->name . ' *' . $itemSuffix->name . '*';
}
}

Expand Down Expand Up @@ -506,15 +506,15 @@ public function getAffixAttribute(string $attribute): float
*/
public function getTotalPercentageForStat(string $stat): float
{
$baseStat = is_null($this->{$stat.'_mod'}) ? 0.0 : $this->{$stat.'_mod'};
$baseStat = is_null($this->{$stat . '_mod'}) ? 0.0 : $this->{$stat . '_mod'};

if (! is_null($this->itemPrefix)) {
$statBonus = $this->itemPrefix->{$stat.'_mod'};
$statBonus = $this->itemPrefix->{$stat . '_mod'};
$baseStat += ! is_null($statBonus) ? $statBonus : 0.0;
}

if (! is_null($this->itemSuffix)) {
$statBonus = $this->itemSuffix->{$stat.'_mod'};
$statBonus = $this->itemSuffix->{$stat . '_mod'};
$baseStat += ! is_null($statBonus) ? $statBonus : 0.0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public function requiredSpecialtyType(Character $character, GuideQuest $quest):

$isInSet = $character->inventorySets->filter(function ($set) use ($quest) {
return $set->slots->filter(function ($slot) use ($quest) {
$slot->item->specialty_type === $quest->required_specialty_type;
return $slot->item->specialty_type === $quest->required_specialty_type;
})->isNotempty();
})->isNotEmpty();

Expand Down
2 changes: 1 addition & 1 deletion app/Game/PassiveSkills/Values/PassiveSkillTypeValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class PassiveSkillTypeValue
public function __construct(int $value)
{
if (! in_array($value, self::$values)) {
throw new Exception($value.' does not exist.');
throw new Exception($value . ' does not exist.');
}

$this->value = $value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
use App\Flare\Models\GameSkill;
use App\Flare\Models\Item;
use App\Flare\Values\ItemEffectsValue;
use App\Flare\Values\ItemSpecialtyType;
use App\Flare\Values\MapNameValue;
use App\Game\GuideQuests\Services\GuideQuestRequirementsService;
use App\Game\Skills\Values\SkillTypeValue;
use Tests\Setup\Character\CharacterFactory;
use Tests\TestCase;
use Tests\Traits\CreateFactionLoyalty;
use Tests\Traits\CreateGameMap;
use Tests\Traits\CreateGameSkill;
use Tests\Traits\CreateGuideQuest;
Expand All @@ -22,7 +24,14 @@

class GuideQuestRequirementsServiceTest extends TestCase
{
use CreateGuideQuest, CreateItem, CreateGameSkill, CreateQuest, CreateNpc, CreateGameMap, RefreshDatabase;
use CreateGuideQuest,
CreateItem,
CreateGameSkill,
CreateQuest,
CreateNpc,
CreateGameMap,
CreateFactionLoyalty,
RefreshDatabase;

private ?CharacterFactory $character;

Expand Down Expand Up @@ -289,4 +298,280 @@ public function testGetSecondaryRequiredQuestItem()

$this->assertContains('secondary_quest_item_id', $finishedRequirements);
}

public function testRequiredFameLevelCheckWhenNoPledgedFaction()
{
$character = $this->character->getCharacter();

$npc = $this->createNpc([
'game_map_id' => $character->map->game_map_id,
]);

$factionLoyalty = $this->createFactionLoyalty([
'faction_id' => $character->factions->first()->id,
'character_id' => $character->id,
'is_pledged' => false,
]);

$factionNpc = $this->createFactionLoyaltyNpc([
'faction_loyalty_id' => $factionLoyalty->id,
'npc_id' => $npc->id,
'current_level' => 0,
'max_level' => 25,
'next_level_fame' => 100,
'currently_helping' => false,
'kingdom_item_defence_bonus' => 0.002,
]);

$this->createFactionLoyaltyNpcTask([
'faction_loyalty_id' => $factionLoyalty->id,
'faction_loyalty_npc_id' => $factionNpc->id,
'fame_tasks' => [],
]);

$guideQuest = $this->createGuideQuest([
'required_fame_level' => 5,
]);

$character = $character->refresh();

$finishedRequirements = $this->guideQuestRequirementsService->requiredFameLevel($character, $guideQuest)->getFinishedRequirements();

$this->assertNotContains('required_fame_level', $finishedRequirements);
}

public function testRequiredFameLevelCheckWhenNotAssistingNPC()
{
$character = $this->character->getCharacter();

$npc = $this->createNpc([
'game_map_id' => $character->map->game_map_id,
]);

$factionLoyalty = $this->createFactionLoyalty([
'faction_id' => $character->factions->first()->id,
'character_id' => $character->id,
'is_pledged' => true,
]);

$factionNpc = $this->createFactionLoyaltyNpc([
'faction_loyalty_id' => $factionLoyalty->id,
'npc_id' => $npc->id,
'current_level' => 0,
'max_level' => 25,
'next_level_fame' => 100,
'currently_helping' => false,
'kingdom_item_defence_bonus' => 0.002,
]);

$this->createFactionLoyaltyNpcTask([
'faction_loyalty_id' => $factionLoyalty->id,
'faction_loyalty_npc_id' => $factionNpc->id,
'fame_tasks' => [],
]);

$guideQuest = $this->createGuideQuest([
'required_fame_level' => 5,
]);

$character = $character->refresh();

$finishedRequirements = $this->guideQuestRequirementsService->requiredFameLevel($character, $guideQuest)->getFinishedRequirements();

$this->assertNotContains('required_fame_level', $finishedRequirements);
}

public function testRequiredFameLevelChec()
{
$character = $this->character->getCharacter();

$npc = $this->createNpc([
'game_map_id' => $character->map->game_map_id,
]);

$factionLoyalty = $this->createFactionLoyalty([
'faction_id' => $character->factions->first()->id,
'character_id' => $character->id,
'is_pledged' => true,
]);

$factionNpc = $this->createFactionLoyaltyNpc([
'faction_loyalty_id' => $factionLoyalty->id,
'npc_id' => $npc->id,
'current_level' => 10,
'max_level' => 25,
'next_level_fame' => 100,
'currently_helping' => true,
'kingdom_item_defence_bonus' => 0.002,
]);

$this->createFactionLoyaltyNpcTask([
'faction_loyalty_id' => $factionLoyalty->id,
'faction_loyalty_npc_id' => $factionNpc->id,
'fame_tasks' => [],
]);

$guideQuest = $this->createGuideQuest([
'required_fame_level' => 5,
]);

$character = $character->refresh();

$finishedRequirements = $this->guideQuestRequirementsService->requiredFameLevel($character, $guideQuest)->getFinishedRequirements();

$this->assertContains('required_fame_level', $finishedRequirements);
}

public function testRequiredSpecialityItemIsInInventory()
{
$item = $this->createItem([
'specialty_type' => ItemSpecialtyType::HELL_FORGED
]);

$character = $this->character->inventoryManagement()->giveItem($item)->getCharacter();

$guideQuest = $this->createGuideQuest([
'required_specialty_type' => ItemSpecialtyType::HELL_FORGED,
]);

$finishedRequirements = $this->guideQuestRequirementsService->requiredSpecialtyType($character, $guideQuest)->getFinishedRequirements();

$this->assertContains('required_specialty_type', $finishedRequirements);
}

public function testRequiredSpecialityItemIsInSet()
{
$item = $this->createItem([
'specialty_type' => ItemSpecialtyType::HELL_FORGED
]);

$character = $this->character->inventorySetManagement()->createInventorySets(2)->putItemInSet($item, 1)->getCharacter();

$guideQuest = $this->createGuideQuest([
'required_specialty_type' => ItemSpecialtyType::HELL_FORGED,
]);

$finishedRequirements = $this->guideQuestRequirementsService->requiredSpecialtyType($character, $guideQuest)->getFinishedRequirements();

$this->assertContains('required_specialty_type', $finishedRequirements);
}

public function testGuideQuestDoesNotRequireHolyStacks()
{
$guideQuest = $this->createGuideQuest([
'required_holy_stacks' => null,
]);

$character = $this->character->getCharacter();


$finishedRequirements = $this->guideQuestRequirementsService->requiredHolyStacks($character, $guideQuest)->getFinishedRequirements();

$this->assertNotContains('required_holy_stacks', $finishedRequirements);
}

public function testGuideQuestDoesRequireHolyStacks()
{
$guideQuest = $this->createGuideQuest([
'required_holy_stacks' => 1,
]);

$item = $this->createItem([
'type' => 'weapon',
'holy_stacks' => 20,
]);

$item->appliedHolyStacks()->create([
'devouring_darkness_bonus' => 0.10,
'stat_increase_bonus' => 0.10,
]);

$item = $item->refresh();

$character = $this->character->inventoryManagement()->giveItem($item, true, 'left-hand')->getCharacter();

$finishedRequirements = $this->guideQuestRequirementsService->requiredHolyStacks($character, $guideQuest)->getFinishedRequirements();

$this->assertContains('required_holy_stacks', $finishedRequirements);
}

public function testFetchRequiredKingdomsCount()
{
$character = $this->character->kingdomManagement()->assignKingdom()->getCharacter();

$guideQuest = $this->createGuideQuest([
'required_kingdoms' => 1,
]);

$finishedRequirements = $this->guideQuestRequirementsService->requiredKingdomCount($character, $guideQuest)->getFinishedRequirements();

$this->assertContains('required_kingdoms', $finishedRequirements);
}

public function testFetchRequiredKingdomGoldBars()
{
$character = $this->character->kingdomManagement()->assignKingdom([
'gold_bars' => 1000
])->getCharacter();

$guideQuest = $this->createGuideQuest([
'required_gold_bars' => 10,
]);

$finishedRequirements = $this->guideQuestRequirementsService->requiredKingdomGoldBarsAmount($character, $guideQuest)->getFinishedRequirements();

$this->assertContains('required_gold_bars', $finishedRequirements);
}

public function testFetchRequiredKingdomBuildingLevel()
{
$character = $this->character->kingdomManagement()->assignKingdom()->assignBuilding([], [
'level' => 5
])->getCharacter();

$guideQuest = $this->createGuideQuest([
'required_kingdom_level' => 2,
]);

$finishedRequirements = $this->guideQuestRequirementsService->requiredKingdomBuildingLevel($character, $guideQuest)->getFinishedRequirements();

$this->assertContains('required_kingdom_level', $finishedRequirements);
}

public function testFetchRequiredKingdomUnitAmount()
{
$character = $this->character->kingdomManagement()->assignKingdom()->assignUnits([], 1000)->getCharacter();

$guideQuest = $this->createGuideQuest([
'required_kingdom_units' => 100,
]);

$finishedRequirements = $this->guideQuestRequirementsService->requiredKingdomUnitCount($character, $guideQuest)->getFinishedRequirements();

$this->assertContains('required_kingdom_units', $finishedRequirements);
}

public function testFetchRequiredKIngdomPassiveSkillLevel()
{
$character = $this->character->assignPassiveSkills()->getCharacter();

$passiveSkill = $character->passiveSkills()->first();

$passiveSkillId = $passiveSkill->passive_skill_id;

$passiveSkill->update([
'current_level' => 5
]);

$character = $character->refresh();

$guideQuest = $this->createGuideQuest([
'required_passive_level' => 2,
'required_passive_skill' => $passiveSkillId,
]);

$finishedRequirements = $this->guideQuestRequirementsService->requiredKingdomPassiveLevel($character, $guideQuest)->getFinishedRequirements();

$this->assertContains('required_passive_level', $finishedRequirements);
}
}

0 comments on commit 9f53475

Please sign in to comment.