use errors::UnknownVariant;
#[cfg(feature = "job_classifications")]
use jobs::classification::Classification;
#[cfg(feature = "roles")]
use roles::Role;
use std::fmt::{Display, Formatter, Result as FmtResult};
use std::str::FromStr;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "with_serde", derive(Serialize, Deserialize))]
pub enum Job {
Bard,
BlackMage,
Dancer,
Dragoon,
Machinist,
Monk,
Ninja,
Pictomancer,
Reaper,
RedMage,
Samurai,
Summoner,
Viper,
Astrologian,
Sage,
Scholar,
WhiteMage,
DarkKnight,
Gunbreaker,
Paladin,
Warrior,
BlueMage,
}
impl Job {
#[cfg(feature = "all_const")]
pub const ALL: [Job; 20] = [
Job::Bard,
Job::BlackMage,
Job::Dancer,
Job::Dragoon,
Job::Machinist,
Job::Monk,
Job::Ninja,
Job::Reaper,
Job::RedMage,
Job::Samurai,
Job::Summoner,
Job::Astrologian,
Job::Sage,
Job::Scholar,
Job::WhiteMage,
Job::DarkKnight,
Job::Gunbreaker,
Job::Paladin,
Job::Warrior,
Job::BlueMage,
];
pub fn as_str(&self) -> &'static str {
match *self {
Job::Bard => "Bard",
Job::BlackMage => "BlackMage",
Job::Dancer => "Dancer",
Job::Dragoon => "Dragoon",
Job::Machinist => "Machinist",
Job::Monk => "Monk",
Job::Ninja => "Ninja",
Job::Pictomancer => "Pictomancer",
Job::Reaper => "Reaper",
Job::RedMage => "RedMage",
Job::Samurai => "Samurai",
Job::Summoner => "Summoner",
Job::Viper => "Viper",
Job::Astrologian => "Astrologian",
Job::Sage => "Sage",
Job::Scholar => "Scholar",
Job::WhiteMage => "WhiteMage",
Job::DarkKnight => "DarkKnight",
Job::Gunbreaker => "Gunbreaker",
Job::Paladin => "Paladin",
Job::Warrior => "Warrior",
Job::BlueMage => "BlueMage",
}
}
pub fn name(&self) -> &'static str {
match *self {
Job::Bard => "Bard",
Job::BlackMage => "Black Mage",
Job::Dancer => "Dancer",
Job::Dragoon => "Dragoon",
Job::Machinist => "Machinist",
Job::Monk => "Monk",
Job::Ninja => "Ninja",
Job::Pictomancer => "Pictomancer",
Job::Reaper => "Reaper",
Job::RedMage => "Red Mage",
Job::Samurai => "Samurai",
Job::Summoner => "Summoner",
Job::Viper => "Viper",
Job::Astrologian => "Astrologian",
Job::Sage => "Sage",
Job::Scholar => "Scholar",
Job::WhiteMage => "White Mage",
Job::DarkKnight => "Dark Knight",
Job::Gunbreaker => "Gunbreaker",
Job::Paladin => "Paladin",
Job::Warrior => "Warrior",
Job::BlueMage => "Blue Mage",
}
}
pub fn code(&self) -> &'static str {
match *self {
Job::Bard => "BRD",
Job::BlackMage => "BLM",
Job::Dancer => "DNC",
Job::Dragoon => "DRG",
Job::Machinist => "MCH",
Job::Monk => "MNK",
Job::Ninja => "NIN",
Job::Pictomancer => "PCT",
Job::Reaper => "RPR",
Job::RedMage => "RDM",
Job::Samurai => "SAM",
Job::Summoner => "SMN",
Job::Viper => "VPR",
Job::Astrologian => "AST",
Job::Sage => "SGE",
Job::Scholar => "SCH",
Job::WhiteMage => "WHM",
Job::DarkKnight => "DRK",
Job::Gunbreaker => "GNB",
Job::Paladin => "PLD",
Job::Warrior => "WAR",
Job::BlueMage => "BLU",
}
}
#[cfg(feature = "roles")]
pub fn role(&self) -> Role {
match *self {
Job::Bard |
Job::BlackMage |
Job::Dancer |
Job::Dragoon |
Job::Machinist |
Job::Monk |
Job::Ninja |
Job::Pictomancer |
Job::Reaper |
Job::RedMage |
Job::Samurai |
Job::Summoner |
Job::Viper |
Job::BlueMage => Role::Dps,
Job::Astrologian |
Job::Sage |
Job::Scholar |
Job::WhiteMage => Role::Healer,
Job::DarkKnight |
Job::Gunbreaker |
Job::Paladin |
Job::Warrior => Role::Tank,
}
}
#[cfg(feature = "job_classifications")]
pub fn classification(&self) -> Classification {
match *self {
Job::Bard |
Job::Dancer |
Job::DarkKnight |
Job::Dragoon |
Job::Gunbreaker |
Job::Machinist |
Job::Monk |
Job::Ninja |
Job::Paladin |
Job::Reaper |
Job::Samurai |
Job::Warrior |
Job::Viper |
Job::BlueMage => Classification::War,
Job::Astrologian |
Job::BlackMage |
Job::Pictomancer |
Job::RedMage |
Job::Sage |
Job::Scholar |
Job::Summoner |
Job::WhiteMage => Classification::Magic,
}
}
}
impl FromStr for Job {
type Err = UnknownVariant;
fn from_str(s: &str) -> Result<Self, Self::Err> {
let job = match s.to_lowercase().as_str() {
"bard" | "brd" => Job::Bard,
"black mage" | "blackmage" | "blm" => Job::BlackMage,
"dancer" | "dnc" => Job::Dancer,
"dragoon" | "drg" => Job::Dragoon,
"machinist" | "mch" => Job::Machinist,
"monk" | "mnk" => Job::Monk,
"ninja" | "nin" => Job::Ninja,
"pictomancer" | "pct" => Job::Pictomancer,
"reaper" | "rpr" => Job::Reaper,
"red mage" | "redmage" | "rdm" => Job::RedMage,
"samurai" | "sam" => Job::Samurai,
"summoner" | "smn" => Job::Summoner,
"viper" | "vpr" => Job::Viper,
"astrologian" | "ast" => Job::Astrologian,
"sage" | "sge" => Job::Sage,
"scholar" | "sch" => Job::Scholar,
"white mage" | "whitemage" | "whm" => Job::WhiteMage,
"dark knight" | "darkknight" | "drk" => Job::DarkKnight,
"gunbreaker" | "gnb" => Job::Gunbreaker,
"paladin" | "pld" => Job::Paladin,
"warrior" | "war" => Job::Warrior,
"blue mage" | "bluemage" | "blu" => Job::BlueMage,
_ => return Err(UnknownVariant("Job", s.into()))
};
Ok(job)
}
}
impl Display for Job {
fn fmt(&self, f: &mut Formatter) -> FmtResult {
write!(f, "{}", self.name())
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "with_serde", derive(Serialize, Deserialize))]
pub enum Class {
Arcanist,
Archer,
Lancer,
Pugilist,
Rogue,
Thaumaturge,
Conjurer,
Gladiator,
Marauder,
}
impl Class {
#[cfg(feature = "all_const")]
pub const ALL: [Class; 9] = [
Self::Arcanist,
Self::Archer,
Self::Lancer,
Self::Pugilist,
Self::Rogue,
Self::Thaumaturge,
Self::Conjurer,
Self::Gladiator,
Self::Marauder,
];
pub fn as_str(&self) -> &'static str {
match self {
Self::Arcanist => "Arcanist",
Self::Archer => "Archer",
Self::Lancer => "Lancer",
Self::Pugilist => "Pugilist",
Self::Rogue => "Rogue",
Self::Thaumaturge => "Thaumaturge",
Self::Conjurer => "Conjurer",
Self::Gladiator => "Gladiator",
Self::Marauder => "Marauder",
}
}
pub fn name(&self) -> &'static str {
self.as_str()
}
pub fn code(&self) -> &'static str {
match self {
Self::Arcanist => "ACN",
Self::Archer => "ARC",
Self::Lancer => "LNC",
Self::Pugilist => "PGL",
Self::Rogue => "ROG",
Self::Thaumaturge => "THM",
Self::Conjurer => "CNJ",
Self::Gladiator => "GLA",
Self::Marauder => "MRD",
}
}
#[cfg(feature = "roles")]
pub fn role(&self) -> Role {
match self {
Self::Arcanist
| Self::Archer
| Self::Lancer
| Self::Pugilist
| Self::Rogue
| Self::Thaumaturge => Role::Dps,
Self::Conjurer => Role::Healer,
Self::Gladiator
| Self::Marauder => Role::Tank,
}
}
#[cfg(feature = "job_classifications")]
pub fn classification(&self) -> Classification {
match self {
Self::Archer
| Self::Lancer
| Self::Pugilist
| Self::Rogue
| Self::Gladiator
| Self::Marauder => Classification::War,
Self::Arcanist
| Self::Thaumaturge
| Self::Conjurer => Classification::Magic,
}
}
}