51 lines
2.1 KiB
Rust
51 lines
2.1 KiB
Rust
//! 战斗领域错误。
|
|
//!
|
|
//! 错误保持纯领域语义,不能绑定 HTTP 状态码或 SpacetimeDB 字符串格式。
|
|
|
|
use std::{error::Error, fmt};
|
|
|
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
pub enum CombatFieldError {
|
|
MissingBattleStateId,
|
|
MissingStorySessionId,
|
|
MissingRuntimeSessionId,
|
|
MissingActorUserId,
|
|
MissingTargetNpcId,
|
|
MissingTargetName,
|
|
MissingFunctionId,
|
|
InvalidVersion,
|
|
InvalidPlayerVitals,
|
|
InvalidTargetVitals,
|
|
InvalidRewardItem(String),
|
|
BattleAlreadyResolved,
|
|
UnsupportedFunctionId,
|
|
InsufficientMana,
|
|
}
|
|
|
|
impl fmt::Display for CombatFieldError {
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
match self {
|
|
Self::MissingBattleStateId => f.write_str("battle_state.battle_state_id 不能为空"),
|
|
Self::MissingStorySessionId => f.write_str("battle_state.story_session_id 不能为空"),
|
|
Self::MissingRuntimeSessionId => {
|
|
f.write_str("battle_state.runtime_session_id 不能为空")
|
|
}
|
|
Self::MissingActorUserId => f.write_str("battle_state.actor_user_id 不能为空"),
|
|
Self::MissingTargetNpcId => f.write_str("battle_state.target_npc_id 不能为空"),
|
|
Self::MissingTargetName => f.write_str("battle_state.target_name 不能为空"),
|
|
Self::MissingFunctionId => f.write_str("resolve_combat_action.function_id 不能为空"),
|
|
Self::InvalidVersion => f.write_str("battle_state.version 必须大于 0"),
|
|
Self::InvalidPlayerVitals => f.write_str("battle_state 玩家生命或灵力字段不合法"),
|
|
Self::InvalidTargetVitals => f.write_str("battle_state 目标生命字段不合法"),
|
|
Self::InvalidRewardItem(message) => f.write_str(message),
|
|
Self::BattleAlreadyResolved => f.write_str("battle_state 已经结束,不能继续结算"),
|
|
Self::UnsupportedFunctionId => {
|
|
f.write_str("resolve_combat_action.function_id 当前不受支持")
|
|
}
|
|
Self::InsufficientMana => f.write_str("当前灵力不足,无法执行该战斗动作"),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Error for CombatFieldError {}
|