Skip to content

Commit

Permalink
Added a lot more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamKyle committed Oct 9, 2024
1 parent c4d5a3f commit 7a6a2df
Show file tree
Hide file tree
Showing 16 changed files with 768 additions and 66 deletions.
4 changes: 2 additions & 2 deletions app/Flare/Models/GlobalEventCraftingInventory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Flare\Models;

use Database\Factories\GlobalEventGoalFactory;
use Database\Factories\GlobalEventCraftingInventoryFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

Expand Down Expand Up @@ -51,6 +51,6 @@ public function character()

protected static function newFactory()
{
return GlobalEventGoalFactory::new();
return GlobalEventCraftingInventoryFactory::new();
}
}
6 changes: 5 additions & 1 deletion app/Flare/Models/GlobalEventCraftingInventorySlot.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Flare\Models;

use Database\Factories\GlobalEventCraftingInventorySlotFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

Expand Down Expand Up @@ -39,5 +40,8 @@ public function inventory()
return $this->belongsTo(GlobalEventCraftingInventory::class, 'global_event_crafting_inventory_id', 'id');
}

protected static function newFactory() {}
protected static function newFactory()
{
return GlobalEventCraftingInventorySlotFactory::new();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ public function handleCraftingTask(Character $character, Item $item): Character
$amountLeft = $task['required_amount'] - $task['current_amount'];

if ($amountLeft === 0) {
ServerMessageHandler::sendBasicMessage($character->user, $helpingNpc->npc->real_name.' does not want anymore of this item anymore. "We\'re done with this child. Move on. I got other tasks for you to do! But you since you crafted it ..."');
ServerMessageHandler::sendBasicMessage($character->user, $helpingNpc->npc->real_name . ' does not want anymore of this item anymore. "We\'re done with this child. Move on. I got other tasks for you to do! But you since you crafted it ..."');
} else {
ServerMessageHandler::sendBasicMessage($character->user, $helpingNpc->npc->real_name.' is elated at your ability to craft: '.$item->affix_name.'. "Thank you child! Only: '.$amountLeft.' Left to go!"');
ServerMessageHandler::sendBasicMessage($character->user, $helpingNpc->npc->real_name . ' is elated at your ability to craft: ' . $item->affix_name . '. "Thank you child! Only: ' . $amountLeft . ' Left to go!"');
}

if ($this->canLevelUpFame($helpingNpc) && $helpingNpc->current_level !== $helpingNpc->max_level) {
Expand Down Expand Up @@ -151,7 +151,7 @@ protected function handOutCurrencies(Character $character, FactionLoyaltyNpc $fa

event(new UpdateTopBarEvent($character->refresh()));

ServerMessageHandler::sendBasicMessage($character->user, 'Your fame with: '.$factionLoyaltyNpc->npc->real_name.' on Plane: '.$factionLoyaltyNpc->npc->gameMap->name);
ServerMessageHandler::sendBasicMessage($character->user, 'Your fame with: ' . $factionLoyaltyNpc->npc->real_name . ' on Plane: ' . $factionLoyaltyNpc->npc->gameMap->name);
}

/**
Expand All @@ -170,7 +170,7 @@ protected function handOutXp(Character $character, FactionLoyaltyNpc $factionLoy

$this->handlePossibleLevelUp($character);

ServerMessageHandler::sendBasicMessage($character->user, 'Rewarded with: '.number_format($factionLoyaltyNpc->current_level * 1000).' XP.');
ServerMessageHandler::sendBasicMessage($character->user, 'Rewarded with: ' . number_format($factionLoyaltyNpc->current_level * 1000) . ' XP.');
}

/**
Expand Down Expand Up @@ -205,7 +205,7 @@ protected function rewardTheUniqueItem(Character $character)
'item_id' => $newItem->id,
]);

event(new ServerMessageEvent($character->user, 'You found something of MEDIUM value child. A simple reward: '.$item->affix_name, $slot->id));
event(new ServerMessageEvent($character->user, 'You found something of MEDIUM value child. A simple reward: ' . $item->affix_name, $slot->id));
}

/**
Expand Down
9 changes: 5 additions & 4 deletions app/Game/Skills/Services/CraftingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ public function fetchCraftableItems(Character $character, array $params, bool $m
*/
public function getCraftingXP(Character $character, string $type): array
{
if ($type == 'hammer' ||
if (
$type == 'hammer' ||
$type == 'bow' ||
$type == 'stave' ||
$type === 'gun' ||
Expand Down Expand Up @@ -255,7 +256,8 @@ protected function attemptToCraftItem(Character $character, Skill $skill, Item $
protected function fetchCraftingSkill(Character $character, string $craftingType): Skill
{

if ($craftingType === 'hammer' ||
if (
$craftingType === 'hammer' ||
$craftingType === 'bow' ||
$craftingType === 'stave' ||
$craftingType === 'gun' ||
Expand All @@ -266,7 +268,7 @@ protected function fetchCraftingSkill(Character $character, string $craftingType
$craftingType = 'weapon';
}

$gameSkill = GameSkill::where('name', ucfirst($craftingType).' Crafting')->first();
$gameSkill = GameSkill::where('name', ucfirst($craftingType) . ' Crafting')->first();

return Skill::where('game_skill_id', $gameSkill->id)->where('character_id', $character->id)->first();
}
Expand Down Expand Up @@ -397,7 +399,6 @@ private function attemptToPickUpItem(Character $character, Item $item): bool
{

if ($this->craftForNpc) {

}

if (! $character->isInventoryFull()) {
Expand Down
42 changes: 18 additions & 24 deletions app/Game/Skills/Services/EnchantItemService.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,34 +128,34 @@ protected function cloneItem(Item $item, ItemAffix $affix)
{
$clonedItem = DuplicateItemHandler::duplicateItem($item);

$clonedItem->{'item_'.$affix->type.'_id'} = $affix->id;
$clonedItem->{'item_' . $affix->type . '_id'} = $affix->id;
$clonedItem->market_sellable = true;
$clonedItem->parent_id = $item->id;
$clonedItem->is_mythic = false;
$clonedItem->is_cosmic = false;

if ($affix->type === 'suffix') {

if (! is_null($clonedItem->itemPrefix)) {
if ($clonedItem->itemPrefix->cost === RandomAffixDetails::MYTHIC) {
$clonedItem->item_prefix_id = null;
if (! is_null($clonedItem->itemSuffix)) {
if ($clonedItem->itemSuffix->cost === RandomAffixDetails::MYTHIC) {
$clonedItem->item_suffix_id = null;
}

if ($clonedItem->itemPrefix->cost === RandomAffixDetails::COSMIC) {
$clonedItem->item_prefix_id = null;
if ($clonedItem->itemSuffix->cost === RandomAffixDetails::COSMIC) {
$clonedItem->item_suffix_id = null;
}
}
}

if ($affix->type === 'prefix') {

if (! is_null($clonedItem->itemSuffix)) {
if ($clonedItem->itemSuffix->cost === RandomAffixDetails::MYTHIC) {
$clonedItem->item_suffix_id = null;
if (! is_null($clonedItem->itemPrefix)) {
if ($clonedItem->itemPrefix->cost === RandomAffixDetails::MYTHIC) {
$clonedItem->item_prefix_id = null;
}

if ($clonedItem->itemSuffix->cost === RandomAffixDetails::COSMIC) {
$clonedItem->item_suffix_id = null;
if ($clonedItem->itemPrefix->cost === RandomAffixDetails::COSMIC) {
$clonedItem->item_prefix_id = null;
}
}
}
Expand All @@ -170,18 +170,12 @@ protected function cloneItem(Item $item, ItemAffix $affix)
*/
protected function getCountOfMatchingItems(): int
{
// Holy stacks are random, so we want a matching
// item only if this item has no stacks on it.
if ($this->item->appliedHolyStacks()->count() === 0) {
return Item::where('name', $this->item->name)
->where('item_prefix_id', $this->item->item_prefix_id)
->where('item_suffix_id', $this->item->item_suffix_id)
->whereDoesntHave('appliedHolyStacks')
->whereDoesntHave('sockets')
->count();
}

return 0;
return Item::where('name', $this->item->name)
->where('item_prefix_id', $this->item->item_prefix_id)
->where('item_suffix_id', $this->item->item_suffix_id)
->whereDoesntHave('appliedHolyStacks')
->whereDoesntHave('sockets')
->count();
}

/**
Expand All @@ -200,6 +194,6 @@ protected function findMatchingItemId(): int
->whereDoesntHave('appliedHolyStacks')
->whereDoesntHave('sockets')
->first()
->id;
->id;
}
}
35 changes: 17 additions & 18 deletions app/Game/Skills/Services/SkillService.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class SkillService

private UpdateCharacterAttackTypesHandler $updateCharacterAttackTypes;

public function __construct(Manager $manager,
public function __construct(
Manager $manager,
BasicSkillsTransformer $basicSkillsTransformer,
SkillsTransformer $skillsTransformer,
UpdateCharacterAttackTypesHandler $updateCharacterAttackTypes
Expand Down Expand Up @@ -97,7 +98,7 @@ public function trainSkill(Character $character, int $skillId, float $xpPercenta
]);

return $this->successResult([
'message' => 'You are now training '.$skill->name,
'message' => 'You are now training ' . $skill->name,
]);
}

Expand All @@ -109,7 +110,8 @@ public function trainSkill(Character $character, int $skillId, float $xpPercenta
* @return void
* @throws Exception
*/
public function assignXPToTrainingSkill(Character $character, int $xp): void {
public function assignXPToTrainingSkill(Character $character, int $xp): void
{
$skillInTraining = $character->skills->where('currently_training', true)->first();
$event = ScheduledEvent::where('event_type', EventType::FEEDBACK_EVENT)->where('currently_running', true)->first();

Expand Down Expand Up @@ -189,6 +191,7 @@ public function getXpWithSkillTrainingReduction(Character $character, int $xp):
public function assignXpToCraftingSkill(GameMap $gameMap, Skill $skill): void
{
if ($skill->level >= 400) {
$skill->update(['xp' => 0]);
return;
}

Expand All @@ -197,10 +200,11 @@ public function assignXpToCraftingSkill(GameMap $gameMap, Skill $skill): void

$newXp = $skill->xp + $xp;

$event = ScheduledEvent::where('event_type', EventType::FEEDBACK_EVENT)->where('currently_running', true)->first();
$event = ScheduledEvent::where('event_type', EventType::FEEDBACK_EVENT)
->where('currently_running', true)
->first();

if (!is_null($event)) {

if ($skill->type()->isEnchanting() || $skill->type()->isCrafting() || $skill->type()->isAlchemy() || $skill->type()->isGemCrafting()) {
$newXp += 175;
} else {
Expand All @@ -209,28 +213,23 @@ public function assignXpToCraftingSkill(GameMap $gameMap, Skill $skill): void
}

while ($newXp >= $skill->xp_max) {

if ($skill->level >= 400) {
$newXp = 0;
break;
}

$skill->update([
'xp' => $newXp,
]);
$skill->update(['xp' => $skill->xp_max]);

$newXp -= $skill->xp_max;

$skill = $skill->refresh();

$skill = $this->levelUpSkill($skill);
}

if ($newXp > 0) {
$skill->update(['xp' => $newXp]);
if ($skill->level >= 400) {
$newXp = 0;
break;
}
}

$skill->update(['xp' => $newXp]);
}


/**
* Level a skill.
*
Expand Down
29 changes: 29 additions & 0 deletions database/factories/GlobalEventCraftingInventoryFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Database\Factories;

use App\Flare\Models\GlobalEventCraftingInventory;
use Illuminate\Database\Eloquent\Factories\Factory;

class GlobalEventCraftingInventoryFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = GlobalEventCraftingInventory::class;

/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'global_event_id' => null,
'character_id' => null,
];
}
}
29 changes: 29 additions & 0 deletions database/factories/GlobalEventCraftingInventorySlotFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Database\Factories;

use App\Flare\Models\GlobalEventCraftingInventorySlot;
use Illuminate\Database\Eloquent\Factories\Factory;

class GlobalEventCraftingInventorySlotFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = GlobalEventCraftingInventorySlot::class;

/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'global_event_crafting_inventory_id' => null,
'item_id' => null,
];
}
}
14 changes: 14 additions & 0 deletions tests/Traits/CreateGlobalCraftingInventory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Tests\Traits;

use App\Flare\Models\GlobalEventCraftingInventory;

trait CreateGlobalCraftingInventory
{

public function createGlobalCraftingInventory(array $options = []): GlobalEventCraftingInventory
{
return GlobalEventCraftingInventory::factory()->create($options);
}
}
14 changes: 14 additions & 0 deletions tests/Traits/CreateGlobalCraftingInventorySlot.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Tests\Traits;

use App\Flare\Models\GlobalEventCraftingInventorySlot;

trait CreateGlobalCraftingInventorySlot
{

public function createGlobalCraftingInventorySlot(array $options = []): GlobalEventCraftingInventorySlot
{
return GlobalEventCraftingInventorySlot::factory()->create($options);
}
}
Loading

0 comments on commit 7a6a2df

Please sign in to comment.