Skip to content

Commit

Permalink
feat: set area after teleport
Browse files Browse the repository at this point in the history
  • Loading branch information
pikdum committed Sep 12, 2024
1 parent 503ba5f commit 4625afd
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/game/chat.ex
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,15 @@ defmodule ThistleTea.Game.Chat do
end

def teleport_player(state, x, y, z, map) do
area =
case ThistleTea.Pathfinding.get_zone_and_area(map, {x, y, z}) do
{_zone, area} -> area
nil -> state.character.area
end

character =
state.character
|> Map.put(:area, area)
|> Map.put(:map, map)
|> Map.put(
:movement,
Expand Down
22 changes: 22 additions & 0 deletions lib/pathfinding.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
defmodule ThistleTea.Pathfinding do
def get_zone_and_area(map_id, {x, y, z}) do
load_adt_at(map_id, {x, y})
ThistleTea.Namigator.get_zone_and_area(map_id, x, y, z)
end

def find_random_point_around_circle(map_id, {x, y, z}, radius) do
load_adt_at(map_id, {x, y})
ThistleTea.Namigator.find_random_point_around_circle(map_id, x, y, z, radius)
end

def find_path(map_id, {start_x, start_y, start_z}, {stop_x, stop_y, stop_z}) do
load_adt_at(map_id, {start_x, start_y})
load_adt_at(map_id, {stop_x, stop_y})
ThistleTea.Namigator.find_path(map_id, start_x, start_y, start_z, stop_x, stop_y, stop_z)
end

defp load_adt_at(map_id, {x, y}) do
# TODO: store in :ets or similar, maybe with last access time, and unload periodically?
ThistleTea.Namigator.load_adt_at(map_id, x, y)
end
end

0 comments on commit 4625afd

Please sign in to comment.