Skip to content

Commit

Permalink
Dependenices, failing test and various other fixes and changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamKyle committed Nov 24, 2023
1 parent 9357c2b commit 0c6183c
Show file tree
Hide file tree
Showing 24 changed files with 453 additions and 61 deletions.
4 changes: 2 additions & 2 deletions app/Flare/ServerFight/BattleBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ protected function elementalAttack(Character $character, ServerMonster $monster)
$elementalAttack->setCharacterHealth($this->characterHealth);

$characterElementalData = $this->characterCacheData->getCachedCharacterData($character, 'elemental_atonement')['elemental_data'];

$weaponDamage = $this->characterCacheData->getCachedCharacterData($character, 'weapon_attack');

$elementalAttack->doElementalAttack($monster->getElementData(), $characterElementalData, $weaponDamage);
Expand Down Expand Up @@ -164,7 +164,7 @@ protected function doMonsterCounter(Character $character, ServerMonster $monster
if ($this->getMonsterHealth() < 0) {
return;
}

$counter = resolve(Counter::class);

$counter->setCharacterHealth($this->characterHealth);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public function attack(Character $character, ServerMonster $monster, bool $isPla
$this->weaponType->setCharacterHealth($characterHealth);
$this->weaponType->setMonsterHealth($monsterHealth);
$this->weaponType->setCharacterAttackData($character, $isPlayerVoided);
$this->weaponType->setAllowEntrancing(true);
$this->weaponType->doWeaponAttack($character, $monster);

$this->type = $this->weaponType;
Expand Down
32 changes: 24 additions & 8 deletions app/Flare/ServerFight/Fight/CharacterAttacks/Types/CastType.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class CastType extends BattleBase

private SpecialAttacks $specialAttacks;

private bool $allowEntrancing = false;

public function __construct(CharacterCacheData $characterCacheData, Entrance $entrance, CanHit $canHit, SpecialAttacks $specialAttacks) {
parent::__construct($characterCacheData);

Expand All @@ -44,6 +46,12 @@ public function setCharacterCastAndAttack(Character $character, bool $isVoided):
return $this;
}

public function setAllowEntrancing(bool $allow): CastType {
$this->allowEntrancing = $allow;

return $this;
}

public function resetMessages() {
$this->clearMessages();
$this->entrance->clearMessages();
Expand Down Expand Up @@ -120,20 +128,22 @@ public function castAttack(Character $character, ServerMonster $monster) {
$this->elementalAttack($character, $monster);
}

return;
return $this;
}

if (!$this->isEnemyEntranced) {
if (!$this->isEnemyEntranced && $this->allowEntrancing) {
$this->doEnemyEntrance($character, $monster, $this->entrance);
}

//$this->doEnemyEntrance($character, $monster, $this->entrance);
if ($this->isEnemyEntranced) {
$this->doSpellDamage($character, $monster, $spellDamage, true);

if ($this->isEnemyEntranced) {
$this->doSpellDamage($character, $monster, $spellDamage, true);
return $this;
if ($this->allowSecondaryAttacks) {
$this->secondaryAttack($character, $monster);

$this->elementalAttack($character, $monster);
}

} else if ($this->isEnemyEntranced) {
$this->doSpellDamage($character, $monster, $spellDamage, true);
return $this;
}

Expand All @@ -142,6 +152,12 @@ public function castAttack(Character $character, ServerMonster $monster) {

$this->doSpellDamage($character, $monster, $spellDamage, true);

if ($this->allowSecondaryAttacks) {
$this->secondaryAttack($character, $monster);

$this->elementalAttack($character, $monster);
}

return $this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use App\Flare\ServerFight\Fight\CharacterAttacks\SpecialAttacks;
use App\Flare\ServerFight\Fight\Entrance;
use App\Flare\ServerFight\Monster\ServerMonster;
use App\Flare\Values\WeaponTypes;

class WeaponType extends BattleBase {

Expand All @@ -18,6 +19,8 @@ class WeaponType extends BattleBase {

private SpecialAttacks $specialAttacks;

private bool $canEntrance = false;

public function __construct(CharacterCacheData $characterCacheData, Entrance $entrance, CanHit $canHit, SpecialAttacks $specialAttacks) {
parent::__construct($characterCacheData);

Expand All @@ -34,6 +37,12 @@ public function setCharacterAttackData(Character $character, bool $isVoided): We
return $this;
}

public function setAllowEntrancing(bool $allowEntrance): WeaponType {
$this->canEntrance = $allowEntrance;

return $this;
}

public function doPvpWeaponAttack(Character $attacker, Character $defender): WeaponType {
$weaponDamage = $this->attackData['weapon_damage'];

Expand Down Expand Up @@ -78,8 +87,19 @@ public function doPvpWeaponAttack(Character $attacker, Character $defender): Wea
public function doWeaponAttack(Character $character, ServerMonster $serverMonster): WeaponType {
$weaponDamage = $this->attackData['weapon_damage'];

if (!$this->isEnemyEntranced && $this->canEntrance) {
$this->doEnemyEntrance($character, $serverMonster, $this->entrance);
}

if ($this->isEnemyEntranced) {
$this->weaponAttack($character, $serverMonster, $weaponDamage);

if ($this->allowSecondaryAttacks && !$this->abortCharacterIsDead) {
$this->secondaryAttack($character, $serverMonster);

$this->elementalAttack($character, $serverMonster);
}

return $this;
}

Expand All @@ -88,6 +108,12 @@ public function doWeaponAttack(Character $character, ServerMonster $serverMonste

$this->weaponAttack($character, $serverMonster, $weaponDamage);

if ($this->allowSecondaryAttacks && !$this->abortCharacterIsDead) {
$this->secondaryAttack($character, $serverMonster);

$this->elementalAttack($character, $serverMonster);
}

return $this;
}

Expand All @@ -101,7 +127,7 @@ public function doWeaponAttack(Character $character, ServerMonster $serverMonste
} else {
$this->addMessage('Your attack missed!', 'enemy-action');

if ($this->allowSecondaryAttacks) {
if ($this->allowSecondaryAttacks && !$this->abortCharacterIsDead) {
$this->secondaryAttack($character, $serverMonster);

$this->elementalAttack($character, $serverMonster);
Expand Down
11 changes: 10 additions & 1 deletion app/Game/Battle/Controllers/Api/RaidBattleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Flare\Models\RaidBoss;
use App\Flare\Models\Character;
use App\Flare\Models\RaidBossParticipation;
use App\Game\Battle\Events\AttackTimeOutEvent;
use App\Game\Battle\Request\AttackTypeRequest;
use App\Game\Battle\Services\Concerns\HandleCachedRaidCritterHealth;
use Illuminate\Http\JsonResponse;
Expand Down Expand Up @@ -79,12 +80,16 @@ public function fetchRaidMonster(Character $character, Monster $monster): JsonRe
public function fightMonster(AttackTypeRequest $attackTypeRequest, Character $character, Monster $monster): JsonResponse {

if ($monster->is_raid_monster) {
$result = $this->raidBattleService->fightRaidMonster($character, $monster->id, $attackTypeRequest->attack_type, false);
$result = $this->raidBattleService->fightRaidMonster($character, $monster->id, $attackTypeRequest->attack_type);

$status = $result['status'];

unset($result['status']);

if ($result['monster_current_health'] <= 0) {
event(new AttackTimeOutEvent($character));
}

return response()->json($result, $status);
}

Expand All @@ -111,6 +116,10 @@ public function fightMonster(AttackTypeRequest $attackTypeRequest, Character $ch

unset($result['status']);

if ($result['monster_current_health'] <= 0) {
event(new AttackTimeOutEvent($character));
}

return response()->json($result, $status);
}
}
1 change: 1 addition & 0 deletions app/Game/Battle/Handlers/BattleEventHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public function processDeadCharacter(Character $character): void {
*/
public function processMonsterDeath(int $characterId, int $monsterId): void {
$monster = Monster::find($monsterId);

$character = Character::find($characterId);

if (is_null($monster)) {
Expand Down
3 changes: 3 additions & 0 deletions app/Game/Battle/Services/RaidBattleService.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use App\Game\Battle\Events\UpdateRaidBossHealth;
use App\Game\Battle\Handlers\BattleEventHandler;
use App\Game\Battle\Services\Concerns\HandleCachedRaidCritterHealth;
use App\Game\BattleRewardProcessing\Jobs\BattleAttackHandler;
use App\Game\BattleRewardProcessing\Jobs\RaidBossRewardHandler;
use App\Game\Core\Traits\ResponseBuilder;
use Exception;
Expand Down Expand Up @@ -234,6 +235,8 @@ public function fightRaidMonster(Character $character, int $monsterId, string $a

$this->deleteMonsterCacheHealth($character->id, $monsterId);

BattleAttackHandler::dispatch($character->id, $monsterId);

return $this->successResult($resultData);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Game\CharacterInventory\Controllers\Api;

use App\Game\CharacterInventory\Services\EquipBestItemForSlotsTypesService;
use Exception;
use League\Fractal\Manager;
use League\Fractal\Resource\Item as FractalItem;
Expand Down Expand Up @@ -472,6 +473,34 @@ public function equipItem(EquipItemValidation $request, Character $character, Eq
}
}

public function equipBestInSlot(Character $character, EquipBestItemForSlotsTypesService $equipBestItemForSlotsTypesService): JsonResponse {
try {

$changedEquipment = $equipBestItemForSlotsTypesService->compareAndEquipBestItems($character);

$character = $character->refresh();

$this->updateCharacterAttackDataCache($character);

$characterInventoryService = $this->characterInventoryService->setCharacter($character);

$message = $changedEquipment ? 'Equipped or Replaced equipped items with the best in slot items!' : 'You currently have the best items equipped!';

return response()->json([
'inventory' => [
'inventory' => $characterInventoryService->fetchCharacterInventory(),
'equipped' => $characterInventoryService->fetchEquipped(),
'sets' => $characterInventoryService->getCharacterInventorySets(),
],
'message' => $message
]);
} catch (Exception $e) {
return response()->json([
'message' => $e->getMessage()
], 422);
}
}

/**
* @param Request $request
* @param Character $character
Expand Down
Loading

0 comments on commit 0c6183c

Please sign in to comment.