2023-02-25 23:49:46 +11:00
|
|
|
use crate::services::effect::DelayedHealthEffect;
|
2023-04-16 01:54:03 +10:00
|
|
|
use crate::static_content::room::Direction;
|
2023-06-07 22:38:46 +10:00
|
|
|
use chrono::{DateTime, Utc};
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use serde_json::Value;
|
|
|
|
use std::collections::VecDeque;
|
2023-01-01 19:24:13 +11:00
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
|
|
|
|
pub enum TaskRecurrence {
|
2023-06-07 22:38:46 +10:00
|
|
|
FixedDuration { seconds: u32 },
|
2023-01-01 19:24:13 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
|
2023-06-07 22:38:46 +10:00
|
|
|
#[serde(tag = "task_type", content = "task_details")]
|
2023-01-01 19:24:13 +11:00
|
|
|
pub enum TaskDetails {
|
2023-01-07 23:06:02 +11:00
|
|
|
RunQueuedCommand,
|
|
|
|
NPCSay {
|
|
|
|
npc_code: String,
|
2023-06-07 22:38:46 +10:00
|
|
|
say_code: String,
|
2023-01-22 01:16:00 +11:00
|
|
|
},
|
2023-01-27 00:36:49 +11:00
|
|
|
NPCWander {
|
|
|
|
npc_code: String,
|
|
|
|
},
|
|
|
|
NPCAggro {
|
|
|
|
npc_code: String,
|
|
|
|
},
|
2023-01-23 22:52:01 +11:00
|
|
|
AttackTick,
|
|
|
|
RecloneNPC {
|
2023-06-07 22:38:46 +10:00
|
|
|
npc_code: String,
|
2023-01-23 22:52:01 +11:00
|
|
|
},
|
|
|
|
RotCorpse {
|
2023-06-07 22:38:46 +10:00
|
|
|
corpse_code: String,
|
2023-01-23 22:52:01 +11:00
|
|
|
},
|
2023-02-25 23:49:46 +11:00
|
|
|
DelayedHealth {
|
|
|
|
item: String,
|
2023-06-07 22:38:46 +10:00
|
|
|
effect_series: VecDeque<DelayedHealthEffect>,
|
2023-02-26 02:01:48 +11:00
|
|
|
},
|
|
|
|
ExpireItem {
|
2023-06-07 22:38:46 +10:00
|
|
|
item_code: String,
|
2023-02-26 02:01:48 +11:00
|
|
|
},
|
2023-04-08 23:51:18 +10:00
|
|
|
ChargeRoom {
|
|
|
|
zone_item: String,
|
2023-06-07 22:38:46 +10:00
|
|
|
daily_price: u64,
|
2023-04-16 01:54:03 +10:00
|
|
|
},
|
|
|
|
SwingShut {
|
|
|
|
room_item: String,
|
2023-06-07 22:38:46 +10:00
|
|
|
direction: Direction,
|
|
|
|
},
|
|
|
|
DestroyUser {
|
|
|
|
username: String,
|
|
|
|
},
|
2023-07-06 22:34:01 +10:00
|
|
|
ChargeWages {
|
|
|
|
npc: String,
|
|
|
|
},
|
2023-08-05 01:49:46 +10:00
|
|
|
TickUrges,
|
|
|
|
ResetSpawns,
|
2023-09-20 23:56:28 +10:00
|
|
|
ResetHanoi,
|
2023-09-26 22:33:41 +10:00
|
|
|
HospitalERSeePatient {
|
|
|
|
item: String,
|
|
|
|
},
|
2023-01-01 19:24:13 +11:00
|
|
|
}
|
|
|
|
impl TaskDetails {
|
|
|
|
pub fn name(self: &Self) -> &'static str {
|
|
|
|
use TaskDetails::*;
|
|
|
|
match self {
|
2023-01-07 23:06:02 +11:00
|
|
|
RunQueuedCommand => "RunQueuedCommand",
|
|
|
|
NPCSay { .. } => "NPCSay",
|
2023-01-27 00:36:49 +11:00
|
|
|
NPCWander { .. } => "NPCWander",
|
|
|
|
NPCAggro { .. } => "NPCAggro",
|
2023-01-23 22:52:01 +11:00
|
|
|
AttackTick => "AttackTick",
|
|
|
|
RecloneNPC { .. } => "RecloneNPC",
|
|
|
|
RotCorpse { .. } => "RotCorpse",
|
2023-02-25 23:49:46 +11:00
|
|
|
DelayedHealth { .. } => "DelayedHealth",
|
2023-02-26 02:01:48 +11:00
|
|
|
ExpireItem { .. } => "ExpireItem",
|
2023-04-08 23:51:18 +10:00
|
|
|
ChargeRoom { .. } => "ChargeRoom",
|
2023-04-16 01:54:03 +10:00
|
|
|
SwingShut { .. } => "SwingShut",
|
2023-06-07 22:38:46 +10:00
|
|
|
DestroyUser { .. } => "DestroyUser",
|
2023-07-06 22:34:01 +10:00
|
|
|
ChargeWages { .. } => "ChargeWages",
|
2023-08-05 01:49:46 +10:00
|
|
|
TickUrges => "TickUrges",
|
|
|
|
ResetSpawns => "ResetSpawns",
|
2023-09-20 23:56:28 +10:00
|
|
|
ResetHanoi => "ResetHanoi",
|
2023-09-26 22:33:41 +10:00
|
|
|
HospitalERSeePatient { .. } => "HospitalERSeePatient",
|
2023-04-08 23:51:18 +10:00
|
|
|
// Don't forget to add to TASK_HANDLER_REGISTRY in regular_tasks.rs too.
|
2023-01-01 19:24:13 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
|
|
|
|
pub struct TaskMeta {
|
|
|
|
pub task_code: String,
|
|
|
|
pub is_static: bool,
|
|
|
|
pub recurrence: Option<TaskRecurrence>,
|
|
|
|
pub consecutive_failure_count: u32,
|
|
|
|
pub next_scheduled: DateTime<Utc>,
|
|
|
|
}
|
|
|
|
|
2023-01-02 13:25:05 +11:00
|
|
|
impl Default for TaskMeta {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
|
|
|
task_code: "unspecified".to_string(),
|
|
|
|
is_static: false,
|
|
|
|
recurrence: None,
|
|
|
|
consecutive_failure_count: 0,
|
2023-06-07 22:38:46 +10:00
|
|
|
next_scheduled: Utc::now() + chrono::Duration::seconds(3600),
|
2023-01-02 13:25:05 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-01 19:24:13 +11:00
|
|
|
#[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,
|
2023-06-07 22:38:46 +10:00
|
|
|
pub task_details: Value,
|
2023-01-01 19:24:13 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq)]
|
|
|
|
#[serde(untagged)]
|
|
|
|
pub enum TaskParse {
|
|
|
|
Known(Task),
|
2023-06-07 22:38:46 +10:00
|
|
|
Unknown(TaskOther),
|
2023-01-01 19:24:13 +11:00
|
|
|
}
|