1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
//! Non-combat job types

#[cfg(feature = "job_classifications")]
use jobs::classification::Classification;
use errors::UnknownVariant;

use std::fmt::{Display, Formatter, Result as FmtResult};
use std::str::FromStr;

/// The Disciple of the Land and Disciple of the Hand jobs available in the game.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "with_serde", derive(Serialize, Deserialize))]
pub enum NonCombatJob {
  // Gatherers
  Botanist,
  Fisher,
  Miner,

  // Crafters
  Alchemist,
  Armorer,
  Blacksmith,
  Carpenter,
  Culinarian,
  Goldsmith,
  Leatherworker,
  Weaver,
}

impl NonCombatJob {
  #[cfg(feature = "all_const")]
  pub const ALL: [NonCombatJob; 11] = [
    NonCombatJob::Botanist,
    NonCombatJob::Fisher,
    NonCombatJob::Miner,

    NonCombatJob::Alchemist,
    NonCombatJob::Armorer,
    NonCombatJob::Blacksmith,
    NonCombatJob::Carpenter,
    NonCombatJob::Culinarian,
    NonCombatJob::Goldsmith,
    NonCombatJob::Leatherworker,
    NonCombatJob::Weaver,
  ];

  pub fn as_str(&self) -> &'static str {
    match *self {
      NonCombatJob::Botanist => "Botanist",
      NonCombatJob::Fisher => "Fisher",
      NonCombatJob::Miner => "Miner",

      NonCombatJob::Alchemist => "Alchemist",
      NonCombatJob::Armorer => "Armorer",
      NonCombatJob::Blacksmith => "Blacksmith",
      NonCombatJob::Carpenter => "Carpenter",
      NonCombatJob::Culinarian => "Culinarian",
      NonCombatJob::Goldsmith => "Goldsmith",
      NonCombatJob::Leatherworker => "Leatherworker",
      NonCombatJob::Weaver => "Weaver",
    }
  }

  pub fn name(&self) -> &'static str {
    // if any variants with spaces are added, this must be changed
    self.as_str()
  }

  pub fn code(&self) -> &'static str {
    match *self {
      NonCombatJob::Botanist => "BTN",
      NonCombatJob::Fisher => "FSH",
      NonCombatJob::Miner => "MIN",

      NonCombatJob::Alchemist => "ALC",
      NonCombatJob::Armorer => "ARM",
      NonCombatJob::Blacksmith => "BSM",
      NonCombatJob::Carpenter => "CRP",
      NonCombatJob::Culinarian => "CUL",
      NonCombatJob::Goldsmith => "GSM",
      NonCombatJob::Leatherworker => "LTW",
      NonCombatJob::Weaver => "WVR",
    }
  }

  #[cfg(feature = "job_classifications")]
  pub fn classification(&self) -> Classification {
    match *self {
      NonCombatJob::Botanist |
      NonCombatJob::Fisher |
      NonCombatJob::Miner => Classification::Land,

      NonCombatJob::Alchemist |
      NonCombatJob::Armorer |
      NonCombatJob::Blacksmith |
      NonCombatJob::Carpenter |
      NonCombatJob::Culinarian |
      NonCombatJob::Goldsmith |
      NonCombatJob::Leatherworker |
      NonCombatJob::Weaver => Classification::Hand,
    }
  }
}

impl FromStr for NonCombatJob {
  type Err = UnknownVariant;

  fn from_str(s: &str) -> Result<Self, Self::Err> {
    let job = match s.to_lowercase().as_str() {
      "botanist" | "btn" => NonCombatJob::Botanist,
      "fisher" | "fsh" => NonCombatJob::Fisher,
      "miner" | "min" => NonCombatJob::Miner,

      "alchemist" | "alc" => NonCombatJob::Alchemist,
      "armorer" | "arm" => NonCombatJob::Armorer,
      "blacksmith" | "bsm" => NonCombatJob::Blacksmith,
      "carpenter" | "crp" => NonCombatJob::Carpenter,
      "culinarian" | "cul" => NonCombatJob::Culinarian,
      "goldsmith" | "gsm" => NonCombatJob::Goldsmith,
      "leatherworker" | "ltw" => NonCombatJob::Leatherworker,
      "weaver" | "wvr" => NonCombatJob::Weaver,
      _ => return Err(UnknownVariant("NonCombatJob", s.into()))
    };

    Ok(job)
  }
}

impl Display for NonCombatJob {
  fn fmt(&self, f: &mut Formatter) -> FmtResult {
    write!(f, "{}", self.name())
  }
}