diff --git a/apps/channel_service/lib/channel_service/actions/map_actions.ex b/apps/channel_service/lib/channel_service/actions/map_actions.ex index 3a0746b7..359158ec 100644 --- a/apps/channel_service/lib/channel_service/actions/map_actions.ex +++ b/apps/channel_service/lib/channel_service/actions/map_actions.ex @@ -13,19 +13,6 @@ defmodule ChannelService.MapActions do ## Packet handlers - @spec dir(String.t(), map, Socket.t()) :: {:cont, Socket.t()} - def dir("dir", params, %Socket{} = socket) do - %{dir: dir, entity_type: entity_type, entity_id: entity_id} = params - maybe_entity = ElvenCaching.get_entity_by_id(entity_type, entity_id) - - case maybe_entity do - {:ok, entity} -> EntityInteractions.set_dir(entity, dir) - _ -> :ok - end - - {:cont, socket} - end - @spec ncif(String.t(), map, Socket.t()) :: {:cont, Socket.t()} def ncif("ncif", params, %Socket{} = socket) do %{entity_type: entity_type, entity_id: entity_id} = params diff --git a/apps/channel_service/lib/channel_service/endpoint/protocol.ex b/apps/channel_service/lib/channel_service/endpoint/protocol.ex index 438dd037..68f558a5 100644 --- a/apps/channel_service/lib/channel_service/endpoint/protocol.ex +++ b/apps/channel_service/lib/channel_service/endpoint/protocol.ex @@ -73,6 +73,16 @@ defmodule ChannelService.Endpoint.Protocol do {:noreply, socket} end + def handle_info({:direction_changed, entity_type, entity_id, value}, socket) do + # Ignore the event if the target is ourself + if entity_id != socket.assigns.character_id do + attrs = %{entity_type: entity_type, entity_id: entity_id, direction: value} + Socket.send(socket, EntityViews.render(:dir, attrs)) + end + + {:noreply, socket} + end + def handle_info(msg, socket) do Logger.warn("unhandled message: #{inspect(msg)}") {:noreply, socket} diff --git a/apps/channel_service/lib/channel_service/entity_interactions.ex b/apps/channel_service/lib/channel_service/entity_interactions.ex index ccd8fa12..666f78e9 100644 --- a/apps/channel_service/lib/channel_service/entity_interactions.ex +++ b/apps/channel_service/lib/channel_service/entity_interactions.ex @@ -50,22 +50,6 @@ defmodule ChannelService.EntityInteractions do Enum.each(players, &send_entity_leave_packets(&1, character)) end - @spec set_dir(Character.t(), EntityEnums.direction_type_keys()) :: - {:ok, new_char :: Character.t()} | {:error, atom} - def set_dir(%Character{} = character, new_dir) do - new_char = %Character{character | direction: new_dir} - - case CharacterRegistry.write(new_char) do - {:ok, new_char} -> - render = EntityViews.render(:dir, %{entity: new_char}) - broadcast_on_map(new_char, render, false) - {:ok, new_char} - - {:error, _} = x -> - x - end - end - @spec say_to_map(Character.t(), String.t()) :: :ok def say_to_map(%Character{} = character, message) do broadcast_on_map( diff --git a/apps/elven_packets/lib/elven_packets/client_packets/world_packets/area_packets.ex b/apps/elven_packets/lib/elven_packets/client_packets/world_packets/area_packets.ex index fa907868..7ccaad17 100644 --- a/apps/elven_packets/lib/elven_packets/client_packets/world_packets/area_packets.ex +++ b/apps/elven_packets/lib/elven_packets/client_packets/world_packets/area_packets.ex @@ -64,7 +64,7 @@ defmodule ElvenPackets.Client.AreaPackets do ####### @deserializable true defpacket "dir", as: Dir do - field :dir, NsEnum, values: direction_type(:__enumerators__) + field :direction, NsEnum, values: direction_type(:__enumerators__) field :entity_type, NsEnum, values: entity_type(:__enumerators__) field :entity_id, NsInteger end diff --git a/apps/elven_packets/lib/elven_packets/views/entity_views.ex b/apps/elven_packets/lib/elven_packets/views/entity_views.ex index 80b0b434..eade22c6 100644 --- a/apps/elven_packets/lib/elven_packets/views/entity_views.ex +++ b/apps/elven_packets/lib/elven_packets/views/entity_views.ex @@ -54,12 +54,10 @@ defmodule ElvenPackets.Views.EntityViews do end def render(:dir, args) do - entity = required_param(args, :entity) - %Dir{ - entity_type: GameService.entity_type(entity), - entity_id: GameService.entity_id(entity), - direction: entity.__struct__.direction(entity) + entity_type: required_param(args, :entity_type), + entity_id: required_param(args, :entity_id), + direction: required_param(args, :direction) } end diff --git a/apps/elven_packets/test/elven_packets/client_packets/area_packets_test.exs b/apps/elven_packets/test/elven_packets/client_packets/area_packets_test.exs index 679f2858..9d2ed685 100644 --- a/apps/elven_packets/test/elven_packets/client_packets/area_packets_test.exs +++ b/apps/elven_packets/test/elven_packets/client_packets/area_packets_test.exs @@ -53,7 +53,7 @@ defmodule ElvenPackets.Client.AreaPacketsTest do test "can be deserialized" do params = "1 2 3" assert %Dir{} = packet = Dir.deserialize("dir", params, %Socket{}) - assert packet.dir == :east + assert packet.direction == :east assert packet.entity_type == :npc assert packet.entity_id == 3 end diff --git a/apps/elven_packets/test/elven_packets/views/entity_views_test.exs b/apps/elven_packets/test/elven_packets/views/entity_views_test.exs index cfc5ab22..36bf1830 100644 --- a/apps/elven_packets/test/elven_packets/views/entity_views_test.exs +++ b/apps/elven_packets/test/elven_packets/views/entity_views_test.exs @@ -51,13 +51,13 @@ defmodule ElvenPackets.Views.EntityViewsTest do describe "dir" do test "default serialization for players" do - args = %{entity: new_player()} + args = %{entity_type: :player, entity_id: 123, direction: :south} packet = EntityViews.render(:dir, args) assert %Dir{} = packet - assert packet.entity_type == :player - assert packet.entity_id == args.entity.id - assert packet.direction == :south + assert packet.entity_type == args.entity_type + assert packet.entity_id == args.entity_id + assert packet.direction == args.direction end end