Skip to content

Commit

Permalink
✨ Setup bases for EntityMapActionSystem
Browse files Browse the repository at this point in the history
  • Loading branch information
ImNotAVirus committed Sep 21, 2023
1 parent 2719bba commit dee1f34
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 1 deletion.
2 changes: 2 additions & 0 deletions apps/channel_service/lib/channel_service/endpoint/protocol.ex
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ defmodule ChannelService.Endpoint.Protocol do

@impl true
def handle_info({:entity_spawn, %PlayerBundle{} = player}, socket) do
IO.inspect(player)

case player.id == socket.assigns.character_id do
false ->
EntityInteractions.send_map_enter(player, socket)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
defmodule GameService.Events.DirectionChanged do
@moduledoc """
Event triggered when an Entity change his direction.
"""
use ElvenGard.ECS.Event, fields: []

@type t :: %__MODULE__{}
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
defmodule GameService.Events.EntityInfoRequest do
@moduledoc """
Event triggered when a player request informations for an Entity.
"""
use ElvenGard.ECS.Event, fields: []

@type t :: %__MODULE__{}
end
8 changes: 8 additions & 0 deletions apps/game_service/lib/game_service/events/movement.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
defmodule GameService.Events.Movement do
@moduledoc """
Event triggered when an Entity move.
"""
use ElvenGard.ECS.Event, fields: []

@type t :: %__MODULE__{}
end
8 changes: 8 additions & 0 deletions apps/game_service/lib/game_service/events/sitting.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
defmodule GameService.Events.Sitting do
@moduledoc """
Event triggered when an Entity sitting down or standing up.
"""
use ElvenGard.ECS.Event, fields: []

@type t :: %__MODULE__{}
end
3 changes: 2 additions & 1 deletion apps/game_service/lib/game_service/partitions/static_map.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ defmodule GameService.StaticMapPartition do

defp systems() do
[
GameService.EntityVisibilitySystem
GameService.EntityVisibilitySystem,
GameService.EntityMapActionSystem
]
end
end
34 changes: 34 additions & 0 deletions apps/game_service/lib/game_service/systems/entity_map_action.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
defmodule GameService.EntityMapActionSystem do
@moduledoc """
TODO: Documentation for GameService.EntityMapActionSystem
Note: All Entities must have a PositionComponent or this system will raise
"""

use ElvenGard.ECS.System,
lock_components: [
GameService.EntityComponents.PositionComponent,
GameService.EntityComponents.DirectionComponent,
GameService.EntityComponents.LevelComponent,
GameService.PlayerComponents.HeroLevelComponent,
GameService.EntityComponents.CombatComponent,
# GameService.EntityComponents.BuffComponent,
GameService.EntityComponents.SpeedComponent,
GameService.EntityComponents.SittingComponent
],
event_subscriptions: [
GameService.Events.DirectionChanged,
GameService.Events.EntityInfoRequest,
GameService.Events.Movement,
GameService.Events.Sitting
]

require Logger

# System behaviour

@impl true
def run(event, _delta) do
Logger.warn("#{inspect(__MODULE__)} unhandled event #{inspect(event)}")
end
end

0 comments on commit dee1f34

Please sign in to comment.