201 lines
7.9 KiB
Rust
201 lines
7.9 KiB
Rust
use super::*;
|
|
|
|
impl From<DomainRuntimeInventoryStateQueryInput> for RuntimeInventoryStateQueryInput {
|
|
fn from(input: DomainRuntimeInventoryStateQueryInput) -> Self {
|
|
Self {
|
|
runtime_session_id: input.runtime_session_id,
|
|
actor_user_id: input.actor_user_id,
|
|
}
|
|
}
|
|
}
|
|
|
|
pub(crate) fn map_runtime_inventory_state_procedure_result(
|
|
result: RuntimeInventoryStateProcedureResult,
|
|
) -> Result<RuntimeInventoryStateRecord, SpacetimeClientError> {
|
|
if !result.ok {
|
|
return Err(SpacetimeClientError::procedure_failed(result.error_message));
|
|
}
|
|
|
|
let snapshot = result
|
|
.snapshot
|
|
.ok_or_else(|| SpacetimeClientError::missing_snapshot("runtime inventory state 快照"))?;
|
|
|
|
Ok(build_runtime_inventory_state_record(
|
|
map_runtime_inventory_state_snapshot(snapshot),
|
|
))
|
|
}
|
|
|
|
pub(crate) fn map_runtime_inventory_state_snapshot(
|
|
snapshot: RuntimeInventoryStateSnapshot,
|
|
) -> DomainRuntimeInventoryStateSnapshot {
|
|
DomainRuntimeInventoryStateSnapshot {
|
|
runtime_session_id: snapshot.runtime_session_id,
|
|
actor_user_id: snapshot.actor_user_id,
|
|
backpack_items: snapshot
|
|
.backpack_items
|
|
.into_iter()
|
|
.map(map_inventory_slot_snapshot)
|
|
.collect(),
|
|
equipment_items: snapshot
|
|
.equipment_items
|
|
.into_iter()
|
|
.map(map_inventory_slot_snapshot)
|
|
.collect(),
|
|
}
|
|
}
|
|
|
|
pub(crate) fn map_inventory_slot_snapshot(
|
|
snapshot: InventorySlotSnapshot,
|
|
) -> module_inventory::InventorySlotSnapshot {
|
|
module_inventory::InventorySlotSnapshot {
|
|
slot_id: snapshot.slot_id,
|
|
runtime_session_id: snapshot.runtime_session_id,
|
|
story_session_id: snapshot.story_session_id,
|
|
actor_user_id: snapshot.actor_user_id,
|
|
container_kind: map_inventory_container_kind(snapshot.container_kind),
|
|
slot_key: snapshot.slot_key,
|
|
item_id: snapshot.item_id,
|
|
category: snapshot.category,
|
|
name: snapshot.name,
|
|
description: snapshot.description,
|
|
quantity: snapshot.quantity,
|
|
rarity: map_inventory_item_rarity(snapshot.rarity),
|
|
tags: snapshot.tags,
|
|
stackable: snapshot.stackable,
|
|
stack_key: snapshot.stack_key,
|
|
equipment_slot_id: snapshot.equipment_slot_id.map(map_inventory_equipment_slot),
|
|
source_kind: map_inventory_item_source_kind(snapshot.source_kind),
|
|
source_reference_id: snapshot.source_reference_id,
|
|
created_at_micros: snapshot.created_at_micros,
|
|
updated_at_micros: snapshot.updated_at_micros,
|
|
}
|
|
}
|
|
|
|
pub(crate) fn map_runtime_item_reward_item_rarity(
|
|
value: DomainRuntimeItemRewardItemRarity,
|
|
) -> RuntimeItemRewardItemRarity {
|
|
match value {
|
|
DomainRuntimeItemRewardItemRarity::Common => RuntimeItemRewardItemRarity::Common,
|
|
DomainRuntimeItemRewardItemRarity::Uncommon => RuntimeItemRewardItemRarity::Uncommon,
|
|
DomainRuntimeItemRewardItemRarity::Rare => RuntimeItemRewardItemRarity::Rare,
|
|
DomainRuntimeItemRewardItemRarity::Epic => RuntimeItemRewardItemRarity::Epic,
|
|
DomainRuntimeItemRewardItemRarity::Legendary => RuntimeItemRewardItemRarity::Legendary,
|
|
}
|
|
}
|
|
|
|
pub(crate) fn map_runtime_item_equipment_slot(
|
|
value: DomainRuntimeItemEquipmentSlot,
|
|
) -> RuntimeItemEquipmentSlot {
|
|
match value {
|
|
DomainRuntimeItemEquipmentSlot::Weapon => RuntimeItemEquipmentSlot::Weapon,
|
|
DomainRuntimeItemEquipmentSlot::Armor => RuntimeItemEquipmentSlot::Armor,
|
|
DomainRuntimeItemEquipmentSlot::Relic => RuntimeItemEquipmentSlot::Relic,
|
|
}
|
|
}
|
|
|
|
pub(crate) fn map_runtime_item_reward_item_rarity_back(
|
|
value: RuntimeItemRewardItemRarity,
|
|
) -> DomainRuntimeItemRewardItemRarity {
|
|
match value {
|
|
RuntimeItemRewardItemRarity::Common => DomainRuntimeItemRewardItemRarity::Common,
|
|
RuntimeItemRewardItemRarity::Uncommon => DomainRuntimeItemRewardItemRarity::Uncommon,
|
|
RuntimeItemRewardItemRarity::Rare => DomainRuntimeItemRewardItemRarity::Rare,
|
|
RuntimeItemRewardItemRarity::Epic => DomainRuntimeItemRewardItemRarity::Epic,
|
|
RuntimeItemRewardItemRarity::Legendary => DomainRuntimeItemRewardItemRarity::Legendary,
|
|
}
|
|
}
|
|
|
|
pub(crate) fn map_runtime_item_equipment_slot_back(
|
|
value: RuntimeItemEquipmentSlot,
|
|
) -> DomainRuntimeItemEquipmentSlot {
|
|
match value {
|
|
RuntimeItemEquipmentSlot::Weapon => DomainRuntimeItemEquipmentSlot::Weapon,
|
|
RuntimeItemEquipmentSlot::Armor => DomainRuntimeItemEquipmentSlot::Armor,
|
|
RuntimeItemEquipmentSlot::Relic => DomainRuntimeItemEquipmentSlot::Relic,
|
|
}
|
|
}
|
|
|
|
pub(crate) fn map_ai_result_reference_kind(
|
|
value: DomainAiResultReferenceKind,
|
|
) -> AiResultReferenceKind {
|
|
match value {
|
|
DomainAiResultReferenceKind::StorySession => AiResultReferenceKind::StorySession,
|
|
DomainAiResultReferenceKind::StoryEvent => AiResultReferenceKind::StoryEvent,
|
|
DomainAiResultReferenceKind::CustomWorldProfile => {
|
|
AiResultReferenceKind::CustomWorldProfile
|
|
}
|
|
DomainAiResultReferenceKind::QuestRecord => AiResultReferenceKind::QuestRecord,
|
|
DomainAiResultReferenceKind::RuntimeItemRecord => AiResultReferenceKind::RuntimeItemRecord,
|
|
DomainAiResultReferenceKind::AssetObject => AiResultReferenceKind::AssetObject,
|
|
}
|
|
}
|
|
|
|
pub(crate) fn map_runtime_item_reward_item_snapshot(
|
|
snapshot: DomainRuntimeItemRewardItemSnapshot,
|
|
) -> RuntimeItemRewardItemSnapshot {
|
|
RuntimeItemRewardItemSnapshot {
|
|
item_id: snapshot.item_id,
|
|
category: snapshot.category,
|
|
item_name: snapshot.item_name,
|
|
description: snapshot.description,
|
|
quantity: snapshot.quantity,
|
|
rarity: map_runtime_item_reward_item_rarity(snapshot.rarity),
|
|
tags: snapshot.tags,
|
|
stackable: snapshot.stackable,
|
|
stack_key: snapshot.stack_key,
|
|
equipment_slot_id: snapshot
|
|
.equipment_slot_id
|
|
.map(map_runtime_item_equipment_slot),
|
|
}
|
|
}
|
|
|
|
pub(crate) fn map_runtime_item_reward_item_snapshot_back(
|
|
snapshot: RuntimeItemRewardItemSnapshot,
|
|
) -> DomainRuntimeItemRewardItemSnapshot {
|
|
DomainRuntimeItemRewardItemSnapshot {
|
|
item_id: snapshot.item_id,
|
|
category: snapshot.category,
|
|
item_name: snapshot.item_name,
|
|
description: snapshot.description,
|
|
quantity: snapshot.quantity,
|
|
rarity: map_runtime_item_reward_item_rarity_back(snapshot.rarity),
|
|
tags: snapshot.tags,
|
|
stackable: snapshot.stackable,
|
|
stack_key: snapshot.stack_key,
|
|
equipment_slot_id: snapshot
|
|
.equipment_slot_id
|
|
.map(map_runtime_item_equipment_slot_back),
|
|
}
|
|
}
|
|
|
|
pub(crate) fn map_inventory_container_kind(
|
|
value: InventoryContainerKind,
|
|
) -> module_inventory::InventoryContainerKind {
|
|
match value {
|
|
InventoryContainerKind::Backpack => module_inventory::InventoryContainerKind::Backpack,
|
|
InventoryContainerKind::Equipment => module_inventory::InventoryContainerKind::Equipment,
|
|
}
|
|
}
|
|
|
|
pub(crate) fn map_inventory_item_rarity(
|
|
value: InventoryItemRarity,
|
|
) -> module_inventory::InventoryItemRarity {
|
|
match value {
|
|
InventoryItemRarity::Common => module_inventory::InventoryItemRarity::Common,
|
|
InventoryItemRarity::Uncommon => module_inventory::InventoryItemRarity::Uncommon,
|
|
InventoryItemRarity::Rare => module_inventory::InventoryItemRarity::Rare,
|
|
InventoryItemRarity::Epic => module_inventory::InventoryItemRarity::Epic,
|
|
InventoryItemRarity::Legendary => module_inventory::InventoryItemRarity::Legendary,
|
|
}
|
|
}
|
|
|
|
pub(crate) fn map_inventory_equipment_slot(
|
|
value: InventoryEquipmentSlot,
|
|
) -> module_inventory::InventoryEquipmentSlot {
|
|
match value {
|
|
InventoryEquipmentSlot::Weapon => module_inventory::InventoryEquipmentSlot::Weapon,
|
|
InventoryEquipmentSlot::Armor => module_inventory::InventoryEquipmentSlot::Armor,
|
|
InventoryEquipmentSlot::Relic => module_inventory::InventoryEquipmentSlot::Relic,
|
|
}
|
|
}
|