112 lines
3.2 KiB
Rust
112 lines
3.2 KiB
Rust
//! 背包领域模型。
|
|
//!
|
|
//! 本文件只承载背包槽、装备槽、堆叠和物品来源等稳定值对象;
|
|
//! SpacetimeDB 表查询写回由 adapter 处理。
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
use shared_kernel::build_prefixed_seed_id;
|
|
#[cfg(feature = "spacetime-types")]
|
|
use spacetimedb::SpacetimeType;
|
|
|
|
pub const INVENTORY_SLOT_ID_PREFIX: &str = "invslot_";
|
|
pub const INVENTORY_MUTATION_ID_PREFIX: &str = "invmut_";
|
|
|
|
#[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))]
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
|
pub enum InventoryContainerKind {
|
|
Backpack,
|
|
Equipment,
|
|
}
|
|
|
|
#[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))]
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
|
pub enum InventoryItemRarity {
|
|
Common,
|
|
Uncommon,
|
|
Rare,
|
|
Epic,
|
|
Legendary,
|
|
}
|
|
|
|
#[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))]
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
|
pub enum InventoryEquipmentSlot {
|
|
Weapon,
|
|
Armor,
|
|
Relic,
|
|
}
|
|
|
|
#[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))]
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
|
pub enum InventoryItemSourceKind {
|
|
StoryReward,
|
|
QuestReward,
|
|
TreasureReward,
|
|
NpcGift,
|
|
NpcTrade,
|
|
CombatDrop,
|
|
ForgeCraft,
|
|
ForgeReforge,
|
|
ManualPatch,
|
|
}
|
|
|
|
#[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))]
|
|
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
|
pub struct InventoryItemSnapshot {
|
|
pub item_id: String,
|
|
pub category: String,
|
|
pub name: String,
|
|
pub description: Option<String>,
|
|
pub quantity: u32,
|
|
pub rarity: InventoryItemRarity,
|
|
pub tags: Vec<String>,
|
|
pub stackable: bool,
|
|
pub stack_key: String,
|
|
pub equipment_slot_id: Option<InventoryEquipmentSlot>,
|
|
pub source_kind: InventoryItemSourceKind,
|
|
pub source_reference_id: Option<String>,
|
|
}
|
|
|
|
#[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))]
|
|
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
|
pub struct InventorySlotSnapshot {
|
|
pub slot_id: String,
|
|
pub runtime_session_id: String,
|
|
pub story_session_id: Option<String>,
|
|
pub actor_user_id: String,
|
|
pub container_kind: InventoryContainerKind,
|
|
pub slot_key: String,
|
|
pub item_id: String,
|
|
pub category: String,
|
|
pub name: String,
|
|
pub description: Option<String>,
|
|
pub quantity: u32,
|
|
pub rarity: InventoryItemRarity,
|
|
pub tags: Vec<String>,
|
|
pub stackable: bool,
|
|
pub stack_key: String,
|
|
pub equipment_slot_id: Option<InventoryEquipmentSlot>,
|
|
pub source_kind: InventoryItemSourceKind,
|
|
pub source_reference_id: Option<String>,
|
|
pub created_at_micros: i64,
|
|
pub updated_at_micros: i64,
|
|
}
|
|
|
|
impl InventoryEquipmentSlot {
|
|
pub fn as_str(self) -> &'static str {
|
|
match self {
|
|
Self::Weapon => "weapon",
|
|
Self::Armor => "armor",
|
|
Self::Relic => "relic",
|
|
}
|
|
}
|
|
}
|
|
|
|
pub fn generate_inventory_slot_id(seed_micros: i64) -> String {
|
|
build_prefixed_seed_id(INVENTORY_SLOT_ID_PREFIX, seed_micros)
|
|
}
|
|
|
|
pub fn generate_inventory_mutation_id(seed_micros: i64) -> String {
|
|
build_prefixed_seed_id(INVENTORY_MUTATION_ID_PREFIX, seed_micros)
|
|
}
|