Skip to main content

Data Model

The schema lives in Moondog.Core and is created with EF Core migrations.

Entities​

User​

  • Identity fields via ASP.NET Core Identity
  • DisplayName
  • Role (Player or Admin)
  • CreatedAt, LastLoginAt

Item​

  • Id (authored, stable), Name (unique), Stackable, Weight, Category (Resource/Equipment/Consumable/PetEquipment/RefinedMaterial)
  • DurabilityValue, BasePrice, Sellable, Unsellable
  • Damage (nullable), WeaponType (nullable: Melee/Bow/Crossbow/Throwing)
  • ProjectileSpeed, ProjectileRadius, AmmoType (item id reference), Range
  • Description
  • Resists (text, category:percent pairs such as venom:20: status-effect resists while worn)
  • CuresEffectId (nullable, status_effects): a consumable that ends that effect (an antivenom)
  • GivesEffectId (nullable, status_effects): a consumable that starts that effect (a draught)

NodeType​

  • Id (authored), Name, Appearance, optional ModelPath (one scene, or several separated by | as model variants), Kind (Resource/Sawmill/Crusher/Smelter/Kiln/Vendor/Taskmaster/Spawner/Creature)
  • SkillId (gathering skill), optional yields via NodeTypeYield

NodeTypeYield​

  • NodeTypeId + ItemId (composite key)
  • Quantity, RequiresSkillId (lore gate), RequiresLevel

WorldEntity​

  • Id (identity), NodeTypeId (nullable), OwnerId (nullable)
  • Position (X, Y, Z), RotationY (degrees), NpcData (jsonb for vendors/trainers/spawners/creatures/pets)
  • Variant (nullable): which of its node type's |-separated models it wears, counting from 1
  • EntityKind (Box/Node/Vendor/Taskmaster/Spawner/Creature/Pet/Pack)

Skill​

  • Id (authored), Name, Category (Craft/General/Lore/Pet Combat), AdvancesBy (Use/Purchase)
  • ParentId (skill tree), MaterialItemId (for Lore), RequiredSkillId (prerequisite)
  • Description

CharacterSkill​

  • CharacterId + SkillId (unique)
  • Level, Experience, UpdatedAt

Recipe​

  • Id (authored), Verb, StationKind, DurationSeconds
  • RequiredSkillId (nullable), RequiredLevel (nullable)

RecipeInput / RecipeOutput​

  • RecipeId + ItemId (composite key)
  • Quantity, IsPrimary (output only)

CraftingJob​

  • Id, CharacterId, StationEntityId, RecipeId
  • AccumulatedMs, RunningSince (nullable), DurationMs, Quality
  • CreatedAt

EntityDepletion​

  • EntityId (PK), DepletedAt, RefillsAt

CharacterItem​

  • Id, CharacterId, ItemId, Quantity, Quality (nullable), Durability/MaxDurability (nullable)
  • Equipped, Slot (Head/Chest/Legs/Feet/Hands/MainHand/OffHand/Neck/Ring1/Ring2/Quiver/Belt)
  • CreatedAt

Creature​

  • Id (authored), Name, Kind, Appearance, BaseHp, BaseDamage, AttackCooldownSec, MoveSpeed
  • SkillXpReward, SkillId (advances on kill)
  • PetSkillIds (csv of skill ids for taming)
  • OnHitEffectId (nullable, status_effects), OnHitChance (0-1): a status effect its hits may give
  • Its kind (creature_kinds) carries Resists, category:percent pairs, for its creatures and pets

Smaller tables and columns (plain SQL)​

  • node_types.RegrowSeconds: above 0, a picked-clean node is full again that long after
  • water_bodies.Depth: water only counts down to Level - Depth (the ruin's flooded passage)
  • hoard_loots: CharacterId + EntityId, LootedAt -- when each player last took from a hoard
  • character_tags: CharacterId + Tag, Source, SetAt -- player tags that NPC conversation checks branch on (cascades with the character)

Inscription (inscriptions, plain SQL)​

  • Id, Key (the level file's panel, unique), Title, X, Y, Z, Text
  • character_inscriptions: CharacterId + InscriptionId, Clarity (0-1, the best a character has made out), FirstReadAt: their Lore journal
  • Migration BuildersInscriptions; see Dungeons

StatusEffect (status_effects)​

  • Id, Name (unique), Category (what resists name, e.g. venom)
  • DamagePerTick, TickSec, DurationSec, Tint (#rrggbb, the health bar's colour), Description
  • Migration SpidersAndStatusEffects; see Creatures

CreatureInstance​

  • EntityId (PK), CreatureId, CurrentHp, State, LastCombatAt

CreatureLoot​

  • CreatureId + ItemId (composite key)
  • MinQty, MaxQty, Chance, IsPrimary

Pet​

  • Id, CharacterId (owner), CreatureId (template), Name
  • Level, CurrentHp, MaxHp, BaseDamage, AttackCooldownSec, MoveSpeed
  • Experience, PetState (Following/Attacking/Staying/Dead)
  • CreatedAt, UpdatedAt

PetItem​

  • Id, PetId, ItemId, Quantity, Quality (nullable), Equipped, Slot (Collar/Saddle/Charm)
  • CreatedAt

PetSkill​

  • Id, PetId, SkillId, Level, Experience, CreatedAt, UpdatedAt
  • Unique (PetId, SkillId)

Character (updated fields)​

  • Stamina (int, default 50) — current stamina pool
  • MaxStamina (int, default 50) — maximum stamina
  • StaminaRegen (float, default 5.0) — stamina recovered per second

Important indexes and constraints​

  • Character name is unique.
  • Server status name is unique.
  • Character belongs to user with cascade delete.
  • Sessions and bans use foreign keys to users.
  • CharacterSkill (CharacterId, SkillId) unique — enables upsert advancement.
  • CharacterItem (CharacterId, ItemId) index — not unique (non-stacking items need multiple rows).
  • Pet (CharacterId) — one active pet per character (enforced by application logic).
  • PetSkill (PetId, SkillId) unique.

JSON payloads​

Commands and audit details are stored as jsonb/text to keep the control protocol flexible.

Additional entities seeded/changed in Step 12 migration:

Item (changed/seed)​

  • ProjectileSpeed (float, default 40.0) — units per second for projectile travel
  • ProjectileRadius (float, default 0.1) — sphere-sweep collision radius
  • AmmoType (int, nullable) — references matching ammo item id
  • Range (float, default 0.0) — max effective distance
  • WeaponType extended: Melee / Bow / Crossbow / Throwing

Character (changed/seed)​

  • Stamina (int, default 50) — current stamina; drained by Block/Parry/Dodge
  • MaxStamina (int, default 50) — maximum stamina cap
  • StaminaRegen (float, default 5.0) — regenerated per server tick

Migration 20261025120000_Step12RangedCombat.cs (new)​

  • Adds columns to items and characters DB tables
  • Seeds ranged weapons: Bow (item 20), Crossbow (item 21), Throwing Knife (item 22)
  • Seeds ammo: Arrows (item 23), Bolts (item 24), Throwing Knives (item 25)
  • Sets starting stamina (50/50/5.0) for all existing characters

Client Items (Equipment Panel)​

  • Quiver slot — new Slot value "Quiver"; holds ammo items only
  • Ammo items: Arrows (item 23), Bolts (item 24), Throwing Knives (item 25)
  • Ammo consumed on ClientFireProjectile RPC, validated server-side

Projectile System (Phase 2)​

  • ClientFireProjectile RPC → server validates weapon drawn + ammo + stamina → spawns projectile entity
  • Projectile ticks each physics frame: pos += vel * dt, lifetime countdown, sphere-sweep collision vs creatures
  • Arrow radius 0.1, Bolt 0.15, Thrown 0.2 — matches 30Hz tick rate
  • ReceiveProjectileSpawn RPC (server → all clients) — visual spawn
  • ReceiveProjectileHit RPC (server → shooter) — impact effect, damage application

Active Defense (Phase 3)​

ActionStamina CostWindowCooldownEffect
Block (hold)5/sContinuousNone50% damage reduction
Parry (tap)150.3s1.5sStagger attacker, riposte window 0.5s
Dodge (double-tap WASD)250.4s iframe2sFull iframe, moves 4m

Housing / Personal Space (Step 19)​

housing_plots table​

  • Id (serial PK)
  • ZoneId (integer, NOT NULL)
  • Position (jsonb, NOT NULL) — {x, y, z}
  • Size (text, default 'Small') — 'Small', 'Medium', 'Large'
  • Price (integer, NOT NULL)
  • OwnerId (uuid, nullable, FK → characters.Id)
  • PurchasedAt (timestamptz, nullable)
  • Permission (text, default 'Private') — 'Private', 'Friends', 'Guild', 'Party', 'Public'

housing_objects table​

  • Id (serial PK)
  • PlotId (integer, FK → housing_plots.Id, ON DELETE CASCADE)
  • ItemId (integer, NOT NULL) — furniture item
  • Position (jsonb, NOT NULL) — {x, y, z, rot}
  • Data (jsonb, default '{}') — state (open/closed, fuel, etc.)

Plot Permissions​

  • Private: only owner
  • Friends: owner + friends list
  • Guild: owner + guild members
  • Party: owner + party members
  • Public: anyone

RPCs​

RPCModeArgs
ClientBuyPlotany_peerplotId
ClientPlaceObjectany_peerplotId, itemId, x, y, z, rot
ClientRemoveObjectany_peerobjectId
ClientSetPlotPermissionany_peerplotId, permission
ReceivePlotUpdateauthorityplotId, data
ReceiveObjectPlacedany_peerobjectId, plotId, itemId, x, y, z, rot
ReceiveObjectRemovedany_peerobjectId

Farming (Step 20)​

See Farming.

crops table​

  • Id (serial PK), Name (text, unique)
  • Model (text) — how the bed draws it: flax, turnip, potato
  • CropItemId (integer, FK → items.Id) — what a harvest gives
  • WetHours (real) — hours the bed must be wet to ripen it
  • YieldMin, YieldMax (integer) — how many of the crop a harvest gives
  • SeedItemId (integer, nullable, FK → items.Id), SeedMin, SeedMax — seed handed back with it

crop_seeds table​

  • ItemId (integer PK, FK → items.Id) — an item that can be planted
  • CropId (integer, FK → crops.Id, ON DELETE CASCADE)

garden_beds table​

One row per planted bed; an empty bed has none.

  • FurnitureId (uuid PK, FK → housing_furniture.Id, ON DELETE CASCADE)
  • CropId (integer, FK → crops.Id)
  • PlantedAt (timestamptz)
  • WetMs (bigint) — wet time banked by earlier waterings
  • WateredAt (timestamptz, nullable) — the latest watering; it counts for up to 24 hours

A Water Pail's waterings are character_items.Stats.water.

housing_wells and housing_well_deliveries​

A plot's well, the same columns as housing_stables (PlotId PK, Design, X, Z, RotationY, Stage, BuildSeconds, BuildMs, BuildRunningSince), and what was handed over to its site, as housing_stable_deliveries. Its design is the housing_designs row well, Kind Well.

Guilds / Clans (Step 18)​

guilds table​

  • Id (serial PK)
  • Name (text, NOT NULL, UNIQUE)
  • Tag (text, NOT NULL, UNIQUE) — 2-5 char abbreviation
  • LeaderId (uuid, FK → characters.Id)
  • Level (integer, default 1)
  • XP (bigint, default 0)
  • Gold (integer, default 0)
  • CreatedAt (timestamptz, default now())
  • MOTD (text, default '')

guild_ranks table​

  • Id (serial PK)
  • GuildId (integer, FK → guilds.Id, ON DELETE CASCADE)
  • Name (text, NOT NULL)
  • Order (integer, NOT NULL)
  • Permissions (jsonb, default '{}')
  • UNIQUE (GuildId, Order)

guild_members table​

  • Id (serial PK)
  • GuildId (integer, FK → guilds.Id, ON DELETE CASCADE)
  • CharacterId (uuid, FK → characters.Id)
  • RankId (integer, FK → guild_ranks.Id)
  • JoinedAt (timestamptz, default now())
  • ContributionXP (bigint, default 0)
  • UNIQUE (CharacterId)

guild_bank table​

  • Id (serial PK)
  • GuildId (integer, FK → guilds.Id, ON DELETE CASCADE)
  • ItemRowId (integer, NOT NULL)
  • Quantity (integer, default 1)
  • DepositedBy (uuid, FK → characters.Id)
  • DepositedAt (timestamptz, default now())

Default Ranks​

  • Leader (order 0): all permissions
  • Officer (order 1): invite, kick, bank withdraw/deposit
  • Member (order 2): bank deposit only

Permissions JSON​

{
canInvite: true,
canKick: true,
canPromote: false,
canBankWithdraw: true,
canBankDeposit: true
}

RPCs​

RPCModeArgs
ClientGuildCreateany_peername, tag
ClientGuildInviteany_peertargetCharacterId
ClientGuildAcceptany_peerguildId
ClientGuildDeclineany_peerguildId
ClientGuildLeaveany_peer—
ClientGuildKickany_peertargetCharacterId
ClientGuildPromoteany_peertargetCharacterId, rankOrder
ClientGuildSetRankany_peerrankName, permissions, order
ClientGuildBankDepositany_peeritemRowId, quantity
ClientGuildBankWithdrawany_peeritemRowId, quantity
ReceiveGuildUpdateauthorityguildId, data

Trading & Market (Step 17)​

trades table​

  • Id (serial PK)
  • PlayerA (uuid, FK → characters.Id)
  • PlayerB (uuid, FK → characters.Id)
  • State (text, default 'Pending') — 'Pending', 'Accepted', 'Confirmed', 'Completed', 'Cancelled'
  • PlayerAItems (jsonb, default '[]')
  • PlayerBItems (jsonb, default '[]')
  • PlayerAGold (integer, default 0)
  • PlayerBGold (integer, default 0)
  • CreatedAt (timestamptz, default now())
  • CompletedAt (timestamptz, nullable)

auction_listings table​

  • Id (serial PK)
  • SellerId (uuid, FK → characters.Id)
  • ItemRowId (integer) — character_items row
  • Quantity (integer, NOT NULL)
  • UnitPrice (integer, NOT NULL)
  • BuyoutPrice (integer, nullable)
  • DurationHours (integer, default 48)
  • ListedAt (timestamptz, default now())
  • ExpiresAt (timestamptz, NOT NULL)
  • BuyerId (uuid, nullable, FK → characters.Id)
  • SoldAt (timestamptz, nullable)
  • Status (text, default 'Active') — 'Active', 'Sold', 'Expired', 'Cancelled'

Direct Trade Flow​

  1. Player A sends ClientTradeRequest to Player B
  2. Player B accepts via ClientTradeAccept
  3. Both add items/gold via ClientTradeAddItem/ClientTradeAddGold
  4. Both confirm via ClientTradeConfirm
  5. Server validates and executes exchange atomically

Auction House Flow​

  1. Player lists item via ClientAuctionList (validates ownership + quantity)
  2. Other players buy via ClientAuctionBuy (validates gold + status)
  3. Seller cancels via ClientAuctionCancel (only if Active)
  4. Expired listings auto-return items (TODO: background job)

RPCs​

RPCModeArgs
ClientTradeRequestany_peertargetCharacterId
ClientTradeAcceptany_peertradeId
ClientTradeAddItemany_peertradeId, itemRowId, quantity
ClientTradeAddGoldany_peertradeId, amount
ClientTradeConfirmany_peertradeId
ClientTradeCancelany_peertradeId
ReceiveTradeUpdateauthoritytradeId, state
ClientAuctionListany_peeritemRowId, quantity, unitPrice, durationHours
ClientAuctionBuyany_peerlistingId
ClientAuctionCancelany_peerlistingId

Party & Group Systems (Step 16)​

parties table​

  • Id (serial PK)
  • LeaderId (uuid, FK → characters.Id)
  • LootMode (text, default 'RoundRobin') — 'RoundRobin', 'NeedGreed', 'Master'
  • CreatedAt (timestamptz, default now())

party_members table​

  • Id (serial PK)
  • PartyId (integer, FK → parties.Id, ON DELETE CASCADE)
  • CharacterId (uuid, FK → characters.Id)
  • JoinedAt (timestamptz, default now())
  • UNIQUE (PartyId, CharacterId)

Loot Modes​

  • RoundRobin: items distributed in turn order
  • NeedGreed: players roll Need/Greed, highest Need wins
  • Master: leader assigns loot manually

RPCs​

RPCModeArgs
ClientPartyInviteany_peertargetCharacterId
ClientPartyAcceptany_peerpartyId
ClientPartyDeclineany_peerpartyId
ClientPartyLeaveany_peer—
ClientPartyKickany_peertargetCharacterId (leader only)
ReceivePartyUpdateauthoritypartyId, members, lootMode
ClientPartySetLootModeany_peerlootMode

World Events (Step 15)​

world_events table​

  • Id (serial PK)
  • Name (text, NOT NULL)
  • EventType (text) — 'Invasion', 'Boss', 'ResourceSurge', 'Rift'
  • ZoneId (integer, NOT NULL)
  • SpawnEntityId (integer, nullable)
  • Schedule (jsonb) — cron-like or interval
  • DurationSec (integer, default 1800)
  • MinPlayers (integer, default 1)
  • MaxPlayers (integer, default 50)
  • RewardTable (jsonb, NOT NULL)
  • Active (boolean, default false)
  • StartedAt (timestamptz, nullable)
  • EndsAt (timestamptz, nullable)

event_participation table​

  • Id (serial PK)
  • EventId (integer, FK → world_events.Id)
  • CharacterId (uuid, FK → characters.Id)
  • Contribution (integer, default 0)
  • RewardClaimed (boolean, default false)

Event Lifecycle​

Scheduled → Active → Completed/Failed → Cooldown

RPCs​

RPCModeArgs
ClientJoinEventany_peereventId
ClientLeaveEventany_peereventId
ReceiveEventStartany_peereventId, eventName, durationSec, maxPlayers
ReceiveEventUpdateany_peereventId, contribution, total
ReceiveEventEndany_peereventId, success

Quest System (Step 14)​

quests table​

  • Id (serial PK)
  • Name (text, NOT NULL)
  • Description (text)
  • MinLevel (integer, default 1)
  • PrereqQuestId (integer, FK → quests.Id)
  • Repeatable (boolean, default false)
  • Data (jsonb, NOT NULL) — steps, objectives, rewards

character_quests table​

  • Id (serial PK)
  • CharacterId (uuid, FK → characters.Id)
  • QuestId (integer, FK → quests.Id)
  • State (text) — 'Active', 'Completed', 'Failed', 'Abandoned'
  • CurrentStep (integer, default 0)
  • Progress (jsonb, default '{}') — objectiveId → count
  • StartedAt (timestamptz, default now())
  • CompletedAt (timestamptz, nullable)

Quest JSON Schema​

{
steps: [
{
id: 1,
objectives: [
{type: Kill, target: Wolf, count: 5},
{type: Collect, itemId: 103, count: 10}
],
rewards: {xp: 100, gold: 50, items: [{itemId: 100, qty: 1}]},
nextStep: 2
}
],
prereqs: [{questId: 5, state: Completed}],
repeatable: false
}

Objective Types​

  • Kill: creatureId + count
  • Collect: itemId + count (inventory check)
  • Interact: entityId (world entity)
  • Reach: zoneId + radius
  • Talk: npcEntityId + dialogueNode
  • Craft: recipeId + count

RPCs​

RPCModeArgs
ClientAcceptQuestany_peerquestId
ClientAbandonQuestany_peerquestId
ReceiveQuestUpdateauthorityquestId, state, step, progress
ClientInteractNPCany_peernpcEntityId

AI & Navigation (Step 13)​

world_entities additions​

  • (int, nullable) — references patrol_paths.Id
  • (float, default 30.0) — distance from spawn before returning
  • (float, default 20.0) — distance at which creatures aggro
  • (text, nullable) — archetype name for behavior

patrol_paths table​

  • (serial PK)
  • (text, unique)
  • (jsonb) — array of {x, y, z} positions
  • (boolean, default true)

Creature AI State Machine​

States: Idle → Patrol → Chase → Attack → Flee → Return

  • Threat table with decay (10%/sec out of combat)
  • Aggro on damage (threat += damage * 1.5)
  • Leash: soft (25m warn, 35m force return)
  • Patrol: half speed along waypoint path
  • Flee: 1.5x speed away from target for 3s
  • Return: heal to full, resume patrol/idle

RPCs​

RPCModeArgs
any_peerentityId, state, targetId
any_peerentityId, x, y, z, rotY

Ranged Weapons (Phase 4)​

WeaponProjectileTypeSpeedRangeDamageAmmoType
Bowarrow40308arrow
Crossbowbolt352512bolt
Throwing Knifethrown50156throwing

Acceptance Criteria (Phase 0–2)​

  1. Ranged: Player equips bow + quiver, fires arrows, hits creature at 20m, creature takes damage
  2. Block: Hold RMB → 50% damage reduction, stamina drains 5/s
  3. Parry: Tap RMB within 0.3s of hit → attacker staggered, riposte window
  4. Dodge: Double-tap direction → 0.4s iframe, moves 4m, 25 stamina
  5. Stamina: Drains on actions, regens 5.0/s, blocks actions at 0
  6. Projectile: Arrow travels at 40 units/tick, sphere-sweep collision, hits at range
  7. All existing checks green

Last updated: Step 12 Phase 0–4 (data model, defense, ranged weapons)