feat: default connections from c1 holes to medium size

This commit is contained in:
Guarzo
2025-05-20 04:39:17 -04:00
parent bdc4948afb
commit d6c32e2d39
4 changed files with 70 additions and 32 deletions
+2 -1
View File
@@ -38,7 +38,8 @@ defmodule WandererApp.Api.MapConnection do
:map_id,
:solar_system_source,
:solar_system_target,
:type
:type,
:ship_size_type
]
defaults [:create, :read, :update, :destroy]
+38 -29
View File
@@ -39,40 +39,49 @@ defmodule WandererApp.CachedInfo do
def get_system_static_info(solar_system_id) do
case Cachex.get(:system_static_info_cache, solar_system_id) do
{:ok, nil} ->
{:ok, systems} = WandererApp.Api.MapSolarSystem.read()
case WandererApp.Api.MapSolarSystem.read() do
{:ok, systems} ->
systems
|> Enum.each(fn system ->
Cachex.put(
:system_static_info_cache,
system.solar_system_id,
Map.take(system, [
:solar_system_id,
:region_id,
:constellation_id,
:solar_system_name,
:solar_system_name_lc,
:constellation_name,
:region_name,
:system_class,
:security,
:type_description,
:class_title,
:is_shattered,
:effect_name,
:effect_power,
:statics,
:wandering,
:triglavian_invasion_status,
:sun_type_id
])
)
end)
systems
|> Enum.each(fn system ->
Cachex.put(
:system_static_info_cache,
system.solar_system_id,
Map.take(system, [
:solar_system_id,
:region_id,
:constellation_id,
:solar_system_name,
:solar_system_name_lc,
:constellation_name,
:region_name,
:system_class,
:security,
:type_description,
:class_title,
:is_shattered,
:effect_name,
:effect_power,
:statics,
:wandering,
:triglavian_invasion_status,
:sun_type_id
])
)
end)
Cachex.get(:system_static_info_cache, solar_system_id)
Cachex.get(:system_static_info_cache, solar_system_id)
{:error, reason} ->
Logger.error("Failed to read solar systems from API: #{inspect(reason)}")
{:error, :api_error}
end
{:ok, system_static_info} ->
{:ok, system_static_info}
{:error, reason} ->
Logger.error("Failed to get system static info from cache: #{inspect(reason)}")
{:error, :cache_error}
end
end
+16 -1
View File
@@ -8,6 +8,9 @@ defmodule WandererApp.Map.Operations.Connections do
alias WandererApp.Map.Server
require Logger
@c1_system_class 1
@medium_ship_size 1
@spec list_connections(String.t()) :: [map()] | {:error, atom()}
def list_connections(map_id) do
with {:ok, conns} <- MapConnectionRepo.get_by_map(map_id) do
@@ -50,11 +53,23 @@ defmodule WandererApp.Map.Operations.Connections do
defp do_create(attrs, map_id, char_id) do
with {:ok, source} <- parse_int(attrs["solar_system_source"], "solar_system_source"),
{:ok, target} <- parse_int(attrs["solar_system_target"], "solar_system_target") do
# Check if either system is C1 before creating the connection
{:ok, source_system_info} = WandererApp.Map.Server.ConnectionsImpl.get_system_static_info(source)
{:ok, target_system_info} = WandererApp.Map.Server.ConnectionsImpl.get_system_static_info(target)
# Set ship size type to medium if either system is C1
ship_size_type = if source_system_info.system_class == @c1_system_class or target_system_info.system_class == @c1_system_class do
@medium_ship_size
else
Map.get(attrs, "ship_size_type", 2) |> parse_type()
end
info = %{
solar_system_source_id: source,
solar_system_target_id: target,
character_id: char_id,
type: parse_type(attrs["type"])
type: parse_type(attrs["type"]),
ship_size_type: ship_size_type
}
add_result = Server.add_connection(map_id, info)
case add_result do
@@ -69,6 +69,7 @@ defmodule WandererApp.Map.Server.ConnectionsImpl do
@connection_time_status_eol 1
@connection_type_wormhole 0
@connection_type_stargate 1
@medium_ship_size 1
def get_connection_auto_expire_hours(), do: WandererApp.Env.map_connection_auto_expire_hours()
@@ -351,12 +352,24 @@ defmodule WandererApp.Map.Server.ConnectionsImpl do
@connection_type_wormhole
end
# Check if either system is C1 before creating the connection
{:ok, source_system_info} = get_system_static_info(old_location.solar_system_id)
{:ok, target_system_info} = get_system_static_info(location.solar_system_id)
# Set ship size type to medium if either system is C1
ship_size_type = if source_system_info.system_class == @c1 or target_system_info.system_class == @c1 do
@medium_ship_size
else
2 # Default to large
end
{:ok, connection} =
WandererApp.MapConnectionRepo.create(%{
map_id: map_id,
solar_system_source: old_location.solar_system_id,
solar_system_target: location.solar_system_id,
type: connection_type
type: connection_type,
ship_size_type: ship_size_type
})
if connection_type == @connection_type_wormhole do