port over some more

This commit is contained in:
ra
2026-02-14 23:58:01 -07:00
parent 0222be36c5
commit 61176cd416
107 changed files with 9124 additions and 375 deletions

View File

@@ -14,6 +14,8 @@ defmodule Odinsea.Game.Drop do
- Type 3: Explosive/FFA (instant FFA)
"""
alias Odinsea.Game.Item
@type t :: %__MODULE__{
oid: integer(),
item_id: integer(),
@@ -30,7 +32,9 @@ defmodule Odinsea.Game.Drop do
created_at: integer(),
expire_time: integer() | nil,
public_time: integer() | nil,
dropper_oid: integer() | nil
dropper_oid: integer() | nil,
# Item struct for item drops (nil for meso drops)
item: Item.t() | nil
}
defstruct [
@@ -49,7 +53,8 @@ defmodule Odinsea.Game.Drop do
:created_at,
:expire_time,
:public_time,
:dropper_oid
:dropper_oid,
:item
]
# Default drop expiration times (milliseconds)
@@ -65,6 +70,7 @@ defmodule Odinsea.Game.Drop do
individual_reward = Keyword.get(opts, :individual_reward, false)
dropper_oid = Keyword.get(opts, :dropper_oid, nil)
source_position = Keyword.get(opts, :source_position, nil)
item = Keyword.get(opts, :item, nil)
now = System.system_time(:millisecond)
%__MODULE__{
@@ -83,7 +89,8 @@ defmodule Odinsea.Game.Drop do
created_at: now,
expire_time: now + @default_expire_time,
public_time: if(drop_type < 2, do: now + @default_public_time, else: 0),
dropper_oid: dropper_oid
dropper_oid: dropper_oid,
item: item
}
end
@@ -113,7 +120,8 @@ defmodule Odinsea.Game.Drop do
created_at: now,
expire_time: now + @default_expire_time,
public_time: if(drop_type < 2, do: now + @default_public_time, else: 0),
dropper_oid: dropper_oid
dropper_oid: dropper_oid,
item: nil
}
end
@@ -141,13 +149,22 @@ defmodule Odinsea.Game.Drop do
@doc """
Checks if a drop is visible to a specific character.
Considers quest requirements and individual rewards.
For quest items, the character must have the quest started.
For individual rewards, only the owner can see the drop.
"""
def visible_to?(%__MODULE__{} = drop, character_id, _quest_status) do
def visible_to?(%__MODULE__{} = drop, character_id, quest_status) do
# Individual rewards only visible to owner
if drop.individual_reward do
drop.owner_id == character_id
else
true
# Check quest requirement
if drop.quest_id > 0 do
# Only visible if character has quest started (status 1)
Map.get(quest_status, drop.quest_id, 0) == 1
else
true
end
end
end
@@ -158,6 +175,13 @@ defmodule Odinsea.Game.Drop do
drop.meso > 0
end
@doc """
Checks if this is an item drop.
"""
def item?(%__MODULE__{} = drop) do
drop.meso == 0 and drop.item_id > 0
end
@doc """
Gets the display ID (item_id for items, meso amount for meso).
"""
@@ -170,7 +194,13 @@ defmodule Odinsea.Game.Drop do
end
@doc """
Checks if a character can loot this drop.
Checks if a character can loot this drop based on ownership rules.
Drop types:
- 0: Owner only (until timeout)
- 1: Owner's party (until timeout)
- 2: Free-for-all (FFA)
- 3: Explosive (instant FFA)
"""
def can_loot?(%__MODULE__{} = drop, character_id, now) do
# If already picked up, can't loot
@@ -197,4 +227,35 @@ defmodule Odinsea.Game.Drop do
end
end
end
@doc """
Checks if a character can loot this drop, including party check.
Requires party information to validate party drops.
"""
def can_loot_with_party?(%__MODULE__{} = drop, character_id, party_id, party_members, now) do
if drop.picked_up do
false
else
case drop.drop_type do
0 ->
# Timeout for non-owner only
drop.owner_id == character_id or is_public_time?(drop, now)
1 ->
# Timeout for non-owner's party
owner_in_same_party = drop.owner_id in party_members
(owner_in_same_party and party_id != nil) or
drop.owner_id == character_id or
is_public_time?(drop, now)
2 ->
# FFA
true
3 ->
# Explosive/FFA (instant FFA)
true
_ ->
# Default to owner-only
drop.owner_id == character_id
end
end
end
end