use crate::services::effect::{DelayedHealthEffect, DelayedMessageEffect}; use crate::static_content::room::Direction; use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use serde_json::Value; use std::collections::VecDeque; use super::effect::EffectType; #[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)] pub enum TaskRecurrence { FixedDuration { seconds: u32 }, } #[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)] #[serde(tag = "task_type", content = "task_details")] pub enum TaskDetails { RunQueuedCommand, NPCSay { npc_code: String, say_code: String, }, NPCWander { npc_code: String, }, NPCAggro { npc_code: String, }, AttackTick, RecloneNPC { npc_code: String, }, RotCorpse { corpse_code: String, }, DelayedHealth { item: String, effect_series: VecDeque, }, DelayedMessage { item: String, effect_series: VecDeque, }, ExpireItem { item_code: String, }, ChargeRoom { zone_item: String, daily_price: u64, }, SwingShut { room_item: String, direction: Direction, }, DestroyUser { username: String, }, ChargeWages { npc: String, }, TickUrges, ResetSpawns, ResetHanoi, HospitalERSeePatient { item: String, }, DispelEffect { target: String, effect_type: EffectType, }, } impl TaskDetails { pub fn name(self: &Self) -> &'static str { use TaskDetails::*; match self { RunQueuedCommand => "RunQueuedCommand", NPCSay { .. } => "NPCSay", NPCWander { .. } => "NPCWander", NPCAggro { .. } => "NPCAggro", AttackTick => "AttackTick", RecloneNPC { .. } => "RecloneNPC", RotCorpse { .. } => "RotCorpse", DelayedHealth { .. } => "DelayedHealth", DelayedMessage { .. } => "DelayedMessage", DispelEffect { .. } => "DispelEffect", ExpireItem { .. } => "ExpireItem", ChargeRoom { .. } => "ChargeRoom", SwingShut { .. } => "SwingShut", DestroyUser { .. } => "DestroyUser", ChargeWages { .. } => "ChargeWages", TickUrges => "TickUrges", ResetSpawns => "ResetSpawns", ResetHanoi => "ResetHanoi", HospitalERSeePatient { .. } => "HospitalERSeePatient", // Don't forget to add to TASK_HANDLER_REGISTRY in regular_tasks.rs too. } } } #[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)] pub struct TaskMeta { pub task_code: String, pub is_static: bool, pub recurrence: Option, pub consecutive_failure_count: u32, pub next_scheduled: DateTime, } impl Default for TaskMeta { fn default() -> Self { Self { task_code: "unspecified".to_string(), is_static: false, recurrence: None, consecutive_failure_count: 0, next_scheduled: Utc::now() + chrono::Duration::seconds(3600), } } } #[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)] pub struct Task { #[serde(flatten)] pub meta: TaskMeta, #[serde(flatten)] pub details: TaskDetails, // Be careful of backwards compatibility if you add anything new // (consider Option). } #[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq)] pub struct TaskOther { #[serde(flatten)] pub meta: TaskMeta, pub task_type: String, pub task_details: Value, } #[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq)] #[serde(untagged)] pub enum TaskParse { Known(Task), Unknown(TaskOther), }