125 lines
3.9 KiB
Rust
125 lines
3.9 KiB
Rust
use super::*;
|
|
|
|
impl From<DomainBattleStateQueryInput> for BattleStateQueryInput {
|
|
fn from(input: DomainBattleStateQueryInput) -> Self {
|
|
Self {
|
|
battle_state_id: input.battle_state_id,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl From<DomainResolveCombatActionInput> for ResolveCombatActionInput {
|
|
fn from(input: DomainResolveCombatActionInput) -> Self {
|
|
Self {
|
|
battle_state_id: input.battle_state_id,
|
|
function_id: input.function_id,
|
|
action_text: input.action_text,
|
|
base_damage: input.base_damage,
|
|
mana_cost: input.mana_cost,
|
|
heal: input.heal,
|
|
mana_restore: input.mana_restore,
|
|
counter_multiplier_basis_points: input.counter_multiplier_basis_points,
|
|
updated_at_micros: input.updated_at_micros,
|
|
}
|
|
}
|
|
}
|
|
|
|
pub type BarkBattleDraftConfigRecord = serde_json::Value;
|
|
|
|
pub type BarkBattleRuntimeConfigRecord = serde_json::Value;
|
|
|
|
pub type BarkBattleRunRecord = serde_json::Value;
|
|
|
|
pub(crate) fn map_battle_state_procedure_result(
|
|
result: BattleStateProcedureResult,
|
|
) -> Result<BattleStateRecord, SpacetimeClientError> {
|
|
if !result.ok {
|
|
return Err(SpacetimeClientError::procedure_failed(result.error_message));
|
|
}
|
|
|
|
let snapshot = result
|
|
.snapshot
|
|
.ok_or_else(|| SpacetimeClientError::missing_snapshot("battle_state 快照"))?;
|
|
|
|
Ok(build_battle_state_record(map_battle_state_snapshot(
|
|
snapshot,
|
|
)))
|
|
}
|
|
|
|
pub(crate) fn map_resolve_combat_action_procedure_result(
|
|
result: ResolveCombatActionProcedureResult,
|
|
) -> Result<ResolveCombatActionRecord, SpacetimeClientError> {
|
|
if !result.ok {
|
|
return Err(SpacetimeClientError::procedure_failed(result.error_message));
|
|
}
|
|
|
|
let action_result = result
|
|
.result
|
|
.ok_or_else(|| SpacetimeClientError::missing_snapshot("战斗结算结果"))?;
|
|
|
|
Ok(build_resolve_combat_action_record(
|
|
map_resolve_combat_action_result(action_result),
|
|
))
|
|
}
|
|
|
|
pub(crate) fn map_resolve_combat_action_result(
|
|
result: ResolveCombatActionResult,
|
|
) -> DomainResolveCombatActionResult {
|
|
DomainResolveCombatActionResult {
|
|
snapshot: map_battle_state_snapshot(result.snapshot),
|
|
damage_dealt: result.damage_dealt,
|
|
damage_taken: result.damage_taken,
|
|
outcome: map_combat_outcome(result.outcome),
|
|
}
|
|
}
|
|
|
|
pub(crate) fn map_battle_mode(value: DomainBattleMode) -> BattleMode {
|
|
match value {
|
|
DomainBattleMode::Fight => BattleMode::Fight,
|
|
DomainBattleMode::Spar => BattleMode::Spar,
|
|
}
|
|
}
|
|
|
|
pub(crate) fn map_battle_mode_back(value: BattleMode) -> DomainBattleMode {
|
|
match value {
|
|
BattleMode::Fight => DomainBattleMode::Fight,
|
|
BattleMode::Spar => DomainBattleMode::Spar,
|
|
}
|
|
}
|
|
|
|
pub(crate) fn map_battle_status(value: BattleStatus) -> DomainBattleStatus {
|
|
match value {
|
|
BattleStatus::Ongoing => DomainBattleStatus::Ongoing,
|
|
BattleStatus::Resolved => DomainBattleStatus::Resolved,
|
|
BattleStatus::Aborted => DomainBattleStatus::Aborted,
|
|
}
|
|
}
|
|
|
|
pub(crate) fn map_combat_outcome(value: CombatOutcome) -> DomainCombatOutcome {
|
|
match value {
|
|
CombatOutcome::Ongoing => DomainCombatOutcome::Ongoing,
|
|
CombatOutcome::Victory => DomainCombatOutcome::Victory,
|
|
CombatOutcome::SparComplete => DomainCombatOutcome::SparComplete,
|
|
CombatOutcome::Escaped => DomainCombatOutcome::Escaped,
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
pub struct ResolveCombatActionRecord {
|
|
pub battle_state: BattleStateRecord,
|
|
pub damage_dealt: i32,
|
|
pub damage_taken: i32,
|
|
pub outcome: String,
|
|
}
|
|
|
|
pub(crate) fn build_resolve_combat_action_record(
|
|
result: DomainResolveCombatActionResult,
|
|
) -> ResolveCombatActionRecord {
|
|
ResolveCombatActionRecord {
|
|
battle_state: build_battle_state_record(result.snapshot),
|
|
damage_dealt: result.damage_dealt,
|
|
damage_taken: result.damage_taken,
|
|
outcome: result.outcome.as_str().to_string(),
|
|
}
|
|
}
|