fix login issue*
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user