fix login issue*

This commit is contained in:
2026-02-25 12:26:26 -07:00
parent da581f5a20
commit 2c3d0ab580
37 changed files with 4708 additions and 721 deletions

View File

@@ -986,6 +986,13 @@ defmodule Odinsea.Game.Character do
GenServer.call(via_tuple(character_id), {:remove_item_by_id, item_id, quantity})
end
@doc """
Updates the buddy list for a character.
"""
def update_buddies(character_id, buddies) do
GenServer.cast(via_tuple(character_id), {:update_buddies, buddies})
end
# ============================================================================
# GenServer Callbacks - Scripting Operations
# ============================================================================
@@ -1014,6 +1021,14 @@ defmodule Odinsea.Game.Character do
{:noreply, new_state}
end
@impl true
def handle_cast({:update_buddies, buddies}, state) do
# TODO: Store buddies in state when buddy list is added to State struct
# For now, just log the update
Logger.debug("Updated buddy list for character #{state.name}")
{:noreply, state}
end
@impl true
def handle_call({:add_item, inventory_type, item}, _from, state) do
inventory = Map.get(state.inventories, inventory_type, Inventory.new(inventory_type))

View File

@@ -155,6 +155,34 @@ defmodule Odinsea.Game.Inventory do
inv.slot_limit - map_size(inv.items)
end
@doc """
Checks if the inventory has space for a given item and quantity.
Returns true if there's space, false otherwise.
"""
def has_space?(%__MODULE__{} = inv, item_id, quantity) do
# Check if we can stack with existing items of same type
existing = find_by_id(inv, item_id)
if existing do
# Can stack - check if existing stack + quantity <= slot_max
# For simplicity, assume slot_max of 9999 for stackable items
slot_max = existing[:slot_max] || 9999
existing_qty = existing.quantity || 0
if existing_qty + quantity <= slot_max do
true
else
# Need additional slots for overflow
overflow = existing_qty + quantity - slot_max
slots_needed = div(overflow, slot_max) + if rem(overflow, slot_max) > 0, do: 1, else: 0
free_slots(inv) >= slots_needed
end
else
# New item - need at least one free slot
not full?(inv)
end
end
@doc """
Gets the next available slot number.
Returns -1 if the inventory is full.

View File

@@ -124,4 +124,30 @@ defmodule Odinsea.Game.InventoryType do
def slot_limit(type) do
default_slot_limit(type)
end
@doc """
Gets the inventory type from an item_id or type atom.
For item IDs, determines type based on ID ranges:
- Equip: 1-999,999
- Use: 2,000,000-2,999,999
- Setup: 3,000,000-3,999,999
- Etc: 4,000,000-4,999,999
- Cash: 5,000,000+
For atoms, returns the atom if valid, or :undefined.
"""
def get_type(item_id) when is_integer(item_id) do
from_item_id(item_id)
end
def get_type(type) when is_atom(type) do
if type in all_types() do
type
else
:undefined
end
end
def get_type(_), do: :undefined
end

View File

@@ -209,6 +209,13 @@ defmodule Odinsea.Game.Map do
GenServer.call(via_tuple(map_id, channel_id), :get_monsters)
end
@doc """
Gets all monsters on the map (default channel).
"""
def get_monsters(map_id) do
get_monsters(map_id, 1)
end
@doc """
Spawns a monster at the specified spawn point.
"""
@@ -230,6 +237,13 @@ defmodule Odinsea.Game.Map do
GenServer.call(via_tuple(map_id, channel_id), {:damage_monster, oid, damage, character_id})
end
@doc """
Damages a monster (default channel).
"""
def damage_monster(map_id, oid, damage, character_id) do
damage_monster(map_id, 1, oid, damage, character_id)
end
@doc """
Hits a reactor, advancing its state and triggering effects.
"""