JaneDoe-ZS/nap_gameserver/src/logic/procedure/plot_play.rs
2024-07-20 15:59:36 +03:00

56 lines
1.5 KiB
Rust

use super::{ProcedureAction, ProcedureBase, ProcedureError, ProcedureState, ProcedureType};
pub struct ProcedurePlotPlay {
id: i32,
state: ProcedureState,
}
impl ProcedurePlotPlay {
pub fn new(id: i32) -> Self {
Self {
id,
state: ProcedureState::Init,
}
}
}
impl ProcedureBase for ProcedurePlotPlay {
fn id(&self) -> i32 {
self.id
}
fn procedure_type(&self) -> ProcedureType {
ProcedureType::PlotPlay
}
fn on_action(&mut self, action: ProcedureAction) -> Result<ProcedureState, ProcedureError> {
match action {
ProcedureAction::PerformTrigger => {
(self.state == ProcedureState::Init)
.then_some(())
.ok_or(ProcedureError::InvalidState(action, self.state))?;
self.state = ProcedureState::Running;
}
ProcedureAction::PerformEnd => {
(self.state == ProcedureState::Running)
.then_some(())
.ok_or(ProcedureError::InvalidState(action, self.state))?;
self.state = ProcedureState::Finish
}
_ => {
return Err(ProcedureError::UnsupportedAction(
action,
self.procedure_type(),
))
}
}
Ok(self.state)
}
fn is_finished(&self) -> bool {
self.state >= ProcedureState::Running
}
}