blastmud/blastmud_game/src/models/corp.rs

134 lines
3.5 KiB
Rust
Raw Normal View History

2023-03-19 00:04:59 +11:00
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
2023-03-19 00:04:59 +11:00
2023-10-01 16:34:25 +11:00
#[derive(Serialize, Deserialize, PartialEq, Eq, Ord, PartialOrd, Clone, Debug)]
2023-03-19 00:04:59 +11:00
pub enum CorpPermission {
Holder, // Implies all permissions.
Hire,
Fire,
Promote,
War,
Configure,
Finance,
2023-03-19 00:04:59 +11:00
}
impl CorpPermission {
pub fn parse(s: &str) -> Option<CorpPermission> {
use CorpPermission::*;
match s {
"holder" => Some(Holder),
"hire" => Some(Hire),
"fire" => Some(Fire),
"promote" => Some(Promote),
"war" => Some(War),
"config" | "configure" => Some(Configure),
"finance" | "finances" => Some(Finance),
_ => None,
}
}
pub fn display(&self) -> &'static str {
use CorpPermission::*;
match self {
Holder => "holder",
Hire => "hire",
Fire => "fire",
Promote => "promote",
War => "war",
Configure => "configure",
Finance => "finance",
}
}
}
2023-03-26 22:29:39 +11:00
#[derive(Serialize, Deserialize, PartialEq, Eq, Ord, PartialOrd, Clone)]
pub enum CorpCommType {
Chat,
Notice,
Connect,
Reward,
Death,
Consent,
}
2023-03-26 22:29:39 +11:00
impl CorpCommType {
pub fn parse(s: &str) -> Option<CorpCommType> {
use CorpCommType::*;
match s {
"chat" => Some(Chat),
"notice" => Some(Notice),
"connect" => Some(Connect),
"reward" => Some(Reward),
"death" => Some(Death),
"consent" => Some(Consent),
_ => None,
2023-03-26 22:29:39 +11:00
}
}
pub fn display(&self) -> &'static str {
use CorpCommType::*;
match self {
Chat => "chat",
Notice => "notice",
Connect => "connect",
Reward => "reward",
Death => "death",
Consent => "consent",
2023-03-26 22:29:39 +11:00
}
}
}
2023-10-01 16:34:25 +11:00
#[derive(Eq, Clone, PartialEq, Debug)]
2023-03-19 00:04:59 +11:00
pub struct CorpId(pub i64);
2023-10-01 16:34:25 +11:00
#[derive(Serialize, Deserialize, Eq, PartialEq, Clone, Debug)]
2023-03-19 22:59:35 +11:00
#[serde(default)]
pub struct Corp {
pub name: String,
pub founded: DateTime<Utc>,
// If true, new members get allow_combat on, and members cannot turn
// allow_combat off. This will allow duly authorised corp members to
// consent to combat with other corps, and have it apply to members.
pub allow_combat_required: bool,
2023-03-19 00:04:59 +11:00
pub member_permissions: Vec<CorpPermission>,
2023-10-01 16:34:25 +11:00
pub credits: u64,
pub tax: u16, // 0-10000, each representing 0.01%
2023-03-19 00:04:59 +11:00
}
impl Default for Corp {
fn default() -> Self {
Self {
name: "Unset".to_owned(),
allow_combat_required: false,
member_permissions: vec![],
founded: Utc::now(),
2023-10-01 16:34:25 +11:00
credits: 0,
tax: 1000,
2023-03-19 00:04:59 +11:00
}
}
}
#[derive(Serialize, Deserialize)]
2023-03-19 22:59:35 +11:00
#[serde(default)]
2023-03-19 00:04:59 +11:00
pub struct CorpMembership {
pub invited_at: Option<DateTime<Utc>>,
pub joined_at: Option<DateTime<Utc>>,
pub permissions: Vec<CorpPermission>,
pub allow_combat: bool,
pub job_title: String,
2023-03-19 15:41:48 +11:00
pub priority: i64,
pub comms_on: Vec<CorpCommType>,
2023-03-19 00:04:59 +11:00
}
impl Default for CorpMembership {
fn default() -> CorpMembership {
use CorpCommType::*;
2023-03-19 00:04:59 +11:00
CorpMembership {
invited_at: None,
joined_at: None,
permissions: vec![],
2023-03-19 00:04:59 +11:00
allow_combat: false,
job_title: "Employee".to_owned(),
2023-03-19 15:41:48 +11:00
priority: 100,
comms_on: vec![Chat, Notice, Connect, Reward, Death, Consent],
2023-03-19 00:04:59 +11:00
}
}
}