Skip to content

Commit

Permalink
making some adjustments to what we need to send back for movement and…
Browse files Browse the repository at this point in the history
… how we call updates
  • Loading branch information
AdamKyle committed Oct 12, 2024
1 parent c10b800 commit 8c121df
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use App\Flare\Models\Character;
use App\Game\Character\Builders\AttackBuilders\Handler\UpdateCharacterAttackTypesHandler;
use App\Game\Core\Traits\UpdateMarketBoard;
use App\Game\Exploration\Events\ExplorationLogUpdate;
use Exception;
use Illuminate\Bus\Queueable;
Expand All @@ -15,7 +14,7 @@

class CharacterAttackTypesCacheBuilder implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, UpdateMarketBoard;
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

public Character $character;

Expand Down
12 changes: 8 additions & 4 deletions app/Game/Maps/Controllers/Api/MapController.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,11 @@ public function teleport(TeleportRequest $request, Character $character): JsonRe
return response()->json(['invalid input'], 429);
}

$response = $this->teleportService->setCoordinatesToTravelTo($request->x, $request->y)
$this->teleportService->setCoordinatesToTravelTo($request->x, $request->y)
->setCost($request->cost)
->setTimeOutValue($request->timeout)
->setTimeOutValue($request->timeout);

$response = $this->teleportService
->teleport($character);

$status = $response['status'];
Expand All @@ -123,9 +125,11 @@ public function setSail(SetSailValidation $request, Character $character): JsonR
return response()->json(['invalid input'], 429);
}

$response = $this->setSail->setCoordinatesToTravelTo($request->x, $request->y)
$this->setSail->setCoordinatesToTravelTo($request->x, $request->y)
->setCost($request->cost)
->setTimeOutValue($request->timeout)
->setTimeOutValue($request->timeout);

$response = $this->setSail
->setSail($character);

$status = $response['status'];
Expand Down
5 changes: 2 additions & 3 deletions app/Game/Maps/Events/UpdateMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace App\Game\Maps\Events;

use App\Flare\Models\User;
use App\Game\Core\Traits\KingdomCache;
use App\Game\Maps\Services\LocationService;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
Expand All @@ -14,7 +13,7 @@

class UpdateMap implements ShouldBroadcastNow
{
use Dispatchable, InteractsWithSockets, KingdomCache, SerializesModels;
use Dispatchable, InteractsWithSockets, SerializesModels;

public array $mapDetails;

Expand All @@ -35,6 +34,6 @@ public function __construct(User $user, bool $pvpMapUpdate = false)
*/
public function broadcastOn(): Channel|array
{
return new PrivateChannel('update-plane-'.$this->user->id);
return new PrivateChannel('update-plane-' . $this->user->id);
}
}
5 changes: 2 additions & 3 deletions app/Game/Maps/Services/BaseMovementService.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ protected function traversePlayer(Location $location, Character $character): boo
$gameMap = GameMap::where('name', MapNameValue::TWISTED_MEMORIES)->first();

if (is_null($gameMap)) {
throw new Exception('Could not teleport to Twisted Gate.');
throw new Exception('Could not traverse to Twisted Gate.');
}

$this->traverseService->travel($gameMap->id, $character);
Expand Down Expand Up @@ -223,7 +223,7 @@ protected function canPlayerEnterLocation(Character $character, Location $locati
$slot = $character->inventory->slots()->where('item_id', $item->id)->first();

if (is_null($slot)) {
event(new ServerMessageEvent($character->user, 'Cannot enter this location without a '.$item->name));
event(new ServerMessageEvent($character->user, 'Cannot enter this location without a ' . $item->name));

return false;
}
Expand Down Expand Up @@ -258,7 +258,6 @@ protected function canPlayerMoveToLocation(Character $character): bool
}

if ($gameMap->mapType()->isTheIcePlane()) {

}

if ($gameMap->mapType()->isPurgatory()) {
Expand Down
8 changes: 3 additions & 5 deletions app/Game/Maps/Services/PctService.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ protected function handleNewPlaneUpdate(Character $character, CelestialFight $ce

event(new UpdateMap($character->user));

event(new ServerMessageEvent($character->user, 'Child! I have done it. I have used the magics to move you to: (X/Y) '.$celestialFight->x_position.'/'.$celestialFight->y_position.' on the plane: '.$celestialFight->monster->gameMap->name));
event(new ServerMessageEvent($character->user, 'Child! I have done it. I have used the magics to move you to: (X/Y) ' . $celestialFight->x_position . '/' . $celestialFight->y_position . ' on the plane: ' . $celestialFight->monster->gameMap->name));
}

/**
Expand Down Expand Up @@ -136,9 +136,7 @@ protected function teleportToCelestial(Character $character, CelestialFight $cel

$character = $character->refresh();

event(new UpdateMap($character->user, true));

event(new ServerMessageEvent($character->user, 'Child! I have done it. I have used the magics to move you to: (X/Y) '.$celestialFight->x_position.'/'.$celestialFight->y_position));
event(new ServerMessageEvent($character->user, 'Child! I have done it. I have used the magics to move you to: (X/Y) ' . $celestialFight->x_position . '/' . $celestialFight->y_position));
}

/**
Expand Down Expand Up @@ -178,7 +176,7 @@ protected function getDirections(Character $character, CelestialFight $celestial

if (! $teleport) {

$message = 'Child! '.$celestialFight->monster->name.' is at (X/Y): '.$x.'/'.$y.' on the: '.$map->name.'Plane.';
$message = 'Child! ' . $celestialFight->monster->name . ' is at (X/Y): ' . $x . '/' . $y . ' on the: ' . $map->name . 'Plane.';

broadcast(new ServerMessageEvent($character->user, $message));

Expand Down
8 changes: 4 additions & 4 deletions app/Game/Maps/Services/SetSailService.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@ class SetSailService extends BaseMovementService

private PortService $portService;

public function __construct(MapTileValue $mapTileValue,
public function __construct(
MapTileValue $mapTileValue,
MapPositionValue $mapPositionValue,
CoordinatesCache $coordinatesCache,
ConjureService $conjureService,
MovementService $movementService,
PortService $portService,
TraverseService $traverseService,
) {
parent::__construct($mapTileValue,
parent::__construct(
$mapTileValue,
$mapPositionValue,
$coordinatesCache,
$conjureService,
Expand Down Expand Up @@ -71,8 +73,6 @@ public function setSail(Character $character): array

$this->updateMonstersList($character, $toPort);

$this->updateKingdomOwnedKingdom($character);

return $this->successResult($this->movementService->accessLocationService()->getLocationData($character));
}

Expand Down
8 changes: 4 additions & 4 deletions app/Game/Maps/Services/TeleportService.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ class TeleportService extends BaseMovementService
{
use ResponseBuilder;

public function __construct(MapTileValue $mapTileValue,
public function __construct(
MapTileValue $mapTileValue,
MapPositionValue $mapPositionValue,
CoordinatesCache $coordinatesCache,
ConjureService $conjureService,
MovementService $movementService,
TraverseService $traverseService,
) {
parent::__construct($mapTileValue,
parent::__construct(
$mapTileValue,
$mapPositionValue,
$coordinatesCache,
$conjureService,
Expand Down Expand Up @@ -119,7 +121,5 @@ protected function teleportCharacter(Character $character, ?Location $location =
}

$this->updateMonstersList($character, $location);

$this->updateKingdomOwnedKingdom($character);
}
}
8 changes: 4 additions & 4 deletions app/Game/Maps/Services/WalkingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ class WalkingService extends BaseMovementService
{
use ResponseBuilder;

public function __construct(MapTileValue $mapTileValue,
public function __construct(
MapTileValue $mapTileValue,
MapPositionValue $mapPositionValue,
CoordinatesCache $coordinatesCache,
ConjureService $conjureService,
MovementService $movementService,
TraverseService $traverseService,
) {
parent::__construct($mapTileValue,
parent::__construct(
$mapTileValue,
$mapPositionValue,
$coordinatesCache,
$conjureService,
Expand Down Expand Up @@ -76,8 +78,6 @@ public function movePlayerToNewLocation(Character $character): array

$this->updateMonstersList($character, $location);

$this->updateKingdomOwnedKingdom($character);

event(new MoveTimeOutEvent($character));

return $this->successResult($this->movementService->accessLocationService()->getLocationData($character));
Expand Down
6 changes: 3 additions & 3 deletions app/Game/Quests/Services/QuestHandlerService.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ public function moveCharacter(Character $character, Npc $npc): array|Character

$character = $character->refresh();

Log::info('Updating map ...');
event(new UpdateMap($character->user));

CharacterAttackTypesCacheBuilder::dispatch($character);

Log::info('CharacterAttackTypesCacheBuilder called ...');
Expand Down Expand Up @@ -197,9 +200,6 @@ public function moveCharacter(Character $character, Npc $npc): array|Character

protected function updateMapDetails(Character $character): void
{
Log::info('Updating map ...');
event(new UpdateMap($character->user));

$monsters = Cache::get('monsters')[$character->map->gameMap->name];

Log::info('Updating monster list ...');
Expand Down

0 comments on commit 8c121df

Please sign in to comment.