2019-08-29 02:48:06 +00:00
|
|
|
use rand::{seq::SliceRandom, thread_rng, Rng};
|
|
|
|
use vek::Rgb;
|
2019-06-28 23:42:51 +00:00
|
|
|
|
|
|
|
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
|
|
|
pub struct Body {
|
|
|
|
pub race: Race,
|
|
|
|
pub body_type: BodyType,
|
|
|
|
pub chest: Chest,
|
|
|
|
pub belt: Belt,
|
|
|
|
pub pants: Pants,
|
|
|
|
pub hand: Hand,
|
|
|
|
pub foot: Foot,
|
|
|
|
pub shoulder: Shoulder,
|
2019-08-24 23:18:47 +00:00
|
|
|
pub hair_style: HairStyle,
|
|
|
|
pub beard: Beard,
|
|
|
|
pub eyebrows: Eyebrows,
|
|
|
|
pub accessory: Accessory,
|
2019-08-29 02:48:06 +00:00
|
|
|
pub hair_color: u8,
|
|
|
|
pub skin: u8,
|
|
|
|
pub eye_color: u8,
|
2019-06-28 23:42:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Body {
|
|
|
|
pub fn random() -> Self {
|
|
|
|
let mut rng = thread_rng();
|
2019-08-29 02:48:06 +00:00
|
|
|
let race = *(&ALL_RACES).choose(&mut rng).unwrap();
|
2019-06-28 23:42:51 +00:00
|
|
|
Self {
|
2019-08-29 02:48:06 +00:00
|
|
|
race,
|
2019-06-28 23:42:51 +00:00
|
|
|
body_type: *(&ALL_BODY_TYPES).choose(&mut rng).unwrap(),
|
|
|
|
chest: *(&ALL_CHESTS).choose(&mut rng).unwrap(),
|
|
|
|
belt: *(&ALL_BELTS).choose(&mut rng).unwrap(),
|
|
|
|
pants: *(&ALL_PANTS).choose(&mut rng).unwrap(),
|
|
|
|
hand: *(&ALL_HANDS).choose(&mut rng).unwrap(),
|
|
|
|
foot: *(&ALL_FEET).choose(&mut rng).unwrap(),
|
|
|
|
shoulder: *(&ALL_SHOULDERS).choose(&mut rng).unwrap(),
|
2019-08-24 23:18:47 +00:00
|
|
|
hair_style: *(&ALL_HAIR_STYLES).choose(&mut rng).unwrap(),
|
|
|
|
beard: *(&ALL_BEARDS).choose(&mut rng).unwrap(),
|
|
|
|
eyebrows: *(&ALL_EYEBROWS).choose(&mut rng).unwrap(),
|
|
|
|
accessory: *(&ALL_ACCESSORIES).choose(&mut rng).unwrap(),
|
2019-08-29 02:48:06 +00:00
|
|
|
hair_color: rng.gen_range(0, race.num_hair_colors()) as u8,
|
|
|
|
skin: rng.gen_range(0, race.num_skin_colors()) as u8,
|
|
|
|
eye_color: rng.gen_range(0, race.num_eye_colors()) as u8,
|
2019-06-28 23:42:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
|
|
|
pub enum Race {
|
|
|
|
Danari,
|
|
|
|
Dwarf,
|
|
|
|
Elf,
|
|
|
|
Human,
|
|
|
|
Orc,
|
|
|
|
Undead,
|
|
|
|
}
|
|
|
|
pub const ALL_RACES: [Race; 6] = [
|
|
|
|
Race::Danari,
|
|
|
|
Race::Dwarf,
|
|
|
|
Race::Elf,
|
|
|
|
Race::Human,
|
|
|
|
Race::Orc,
|
|
|
|
Race::Undead,
|
|
|
|
];
|
2019-08-31 01:55:10 +00:00
|
|
|
|
2019-08-29 02:48:06 +00:00
|
|
|
// Hair Colors
|
|
|
|
pub const DANARI_HAIR_COLORS: [(u8, u8, u8); 4] = [
|
|
|
|
(198, 169, 113),
|
2019-08-29 09:29:36 +00:00
|
|
|
(146, 32, 32),
|
|
|
|
(198, 169, 113),
|
|
|
|
(198, 169, 113),
|
2019-08-29 02:48:06 +00:00
|
|
|
];
|
2019-08-29 09:29:36 +00:00
|
|
|
pub const DWARF_HAIR_COLORS: [(u8, u8, u8); 3] = [(126, 26, 26), (54, 46, 38), (54, 46, 38)];
|
|
|
|
pub const ELF_HAIR_COLORS: [(u8, u8, u8); 3] = [(66, 83, 113), (13, 76, 41), (66, 83, 113)];
|
|
|
|
pub const HUMAN_HAIR_COLORS: [(u8, u8, u8); 3] = [(73, 42, 36), (73, 42, 36), (73, 42, 36)];
|
|
|
|
pub const ORC_HAIR_COLORS: [(u8, u8, u8); 3] = [(11, 11, 11), (54, 30, 26), (54, 30, 26)];
|
|
|
|
pub const UNDEAD_HAIR_COLORS: [(u8, u8, u8); 3] = [(0, 131, 122), (24, 19, 17), (0, 131, 122)];
|
2019-08-31 01:55:10 +00:00
|
|
|
|
2019-08-29 02:48:06 +00:00
|
|
|
// Skin colors
|
|
|
|
pub const DANARI_SKIN_COLORS: [(u8, u8, u8); 4] = [
|
2019-08-29 09:29:36 +00:00
|
|
|
(57, 120, 148),
|
|
|
|
(57, 120, 148),
|
|
|
|
(57, 120, 148),
|
|
|
|
(57, 120, 148),
|
2019-08-29 02:48:06 +00:00
|
|
|
];
|
2019-08-29 09:29:36 +00:00
|
|
|
pub const DWARF_SKIN_COLORS: [(u8, u8, u8); 3] = [(215, 175, 123), (193, 136, 87), (193, 136, 87)];
|
|
|
|
pub const ELF_SKIN_COLORS: [(u8, u8, u8); 3] = [(169, 145, 177), (145, 133, 148), (255, 200, 15)];
|
2019-08-29 02:48:06 +00:00
|
|
|
pub const HUMAN_SKIN_COLORS: [(u8, u8, u8); 3] =
|
2019-08-29 09:29:36 +00:00
|
|
|
[(255, 200, 159), (220, 169, 125), (220, 169, 125)];
|
|
|
|
pub const ORC_SKIN_COLORS: [(u8, u8, u8); 3] = [(68, 129, 44), (77, 150, 51), (45, 95, 32)];
|
2019-08-29 02:48:06 +00:00
|
|
|
pub const UNDEAD_SKIN_COLORS: [(u8, u8, u8); 3] =
|
2019-08-29 09:29:36 +00:00
|
|
|
[(255, 255, 255), (203, 255, 215), (213, 220, 180)];
|
2019-08-31 01:55:10 +00:00
|
|
|
|
|
|
|
// Eye colors
|
|
|
|
pub const DANARI_EYE_COLORS: [EyeColor; 7] = [
|
|
|
|
EyeColor::Black,
|
|
|
|
EyeColor::Blue,
|
|
|
|
EyeColor::Green,
|
|
|
|
EyeColor::Brown,
|
|
|
|
EyeColor::Red,
|
|
|
|
EyeColor::White,
|
|
|
|
EyeColor::Orange,
|
|
|
|
];
|
|
|
|
pub const DWARF_EYE_COLORS: [EyeColor; 7] = [
|
|
|
|
EyeColor::Black,
|
|
|
|
EyeColor::Blue,
|
|
|
|
EyeColor::Green,
|
|
|
|
EyeColor::Brown,
|
|
|
|
EyeColor::Red,
|
|
|
|
EyeColor::White,
|
|
|
|
EyeColor::Orange,
|
|
|
|
];
|
|
|
|
pub const ELF_EYE_COLORS: [EyeColor; 7] = [
|
|
|
|
EyeColor::Black,
|
|
|
|
EyeColor::Blue,
|
|
|
|
EyeColor::Green,
|
|
|
|
EyeColor::Brown,
|
|
|
|
EyeColor::Red,
|
|
|
|
EyeColor::White,
|
|
|
|
EyeColor::Orange,
|
|
|
|
];
|
|
|
|
pub const HUMAN_EYE_COLORS: [EyeColor; 7] = [
|
|
|
|
EyeColor::Black,
|
|
|
|
EyeColor::Blue,
|
|
|
|
EyeColor::Green,
|
|
|
|
EyeColor::Brown,
|
|
|
|
EyeColor::Red,
|
|
|
|
EyeColor::White,
|
|
|
|
EyeColor::Orange,
|
|
|
|
];
|
|
|
|
pub const ORC_EYE_COLORS: [EyeColor; 7] = [
|
|
|
|
EyeColor::Black,
|
|
|
|
EyeColor::Blue,
|
|
|
|
EyeColor::Green,
|
|
|
|
EyeColor::Brown,
|
|
|
|
EyeColor::Red,
|
|
|
|
EyeColor::White,
|
|
|
|
EyeColor::Orange,
|
|
|
|
];
|
|
|
|
pub const UNDEAD_EYE_COLORS: [EyeColor; 7] = [
|
|
|
|
EyeColor::Black,
|
|
|
|
EyeColor::Blue,
|
|
|
|
EyeColor::Green,
|
|
|
|
EyeColor::Brown,
|
|
|
|
EyeColor::Red,
|
|
|
|
EyeColor::White,
|
|
|
|
EyeColor::Orange,
|
|
|
|
];
|
|
|
|
|
2019-08-29 02:48:06 +00:00
|
|
|
impl Race {
|
|
|
|
fn hair_colors(self) -> &'static [(u8, u8, u8)] {
|
|
|
|
match self {
|
|
|
|
Race::Danari => &DANARI_HAIR_COLORS,
|
|
|
|
Race::Dwarf => &DWARF_HAIR_COLORS,
|
|
|
|
Race::Elf => &ELF_HAIR_COLORS,
|
|
|
|
Race::Human => &HUMAN_HAIR_COLORS,
|
|
|
|
Race::Orc => &ORC_HAIR_COLORS,
|
|
|
|
Race::Undead => &UNDEAD_HAIR_COLORS,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn skin_colors(self) -> &'static [(u8, u8, u8)] {
|
|
|
|
match self {
|
|
|
|
Race::Danari => &DANARI_SKIN_COLORS,
|
|
|
|
Race::Dwarf => &DWARF_SKIN_COLORS,
|
|
|
|
Race::Elf => &ELF_SKIN_COLORS,
|
|
|
|
Race::Human => &HUMAN_SKIN_COLORS,
|
|
|
|
Race::Orc => &ORC_SKIN_COLORS,
|
|
|
|
Race::Undead => &UNDEAD_SKIN_COLORS,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn eye_colors(self) -> &'static [EyeColor] {
|
|
|
|
match self {
|
2019-08-31 01:55:10 +00:00
|
|
|
Race::Danari => &DANARI_EYE_COLORS,
|
|
|
|
Race::Dwarf => &DWARF_EYE_COLORS,
|
|
|
|
Race::Elf => &ELF_EYE_COLORS,
|
|
|
|
Race::Human => &HUMAN_EYE_COLORS,
|
|
|
|
Race::Orc => &ORC_EYE_COLORS,
|
|
|
|
Race::Undead => &UNDEAD_EYE_COLORS,
|
2019-08-29 02:48:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
pub fn hair_color(self, val: u8) -> Rgb<u8> {
|
|
|
|
self.hair_colors()
|
|
|
|
.get(val as usize)
|
|
|
|
.copied()
|
|
|
|
.unwrap_or((0, 0, 0))
|
|
|
|
.into()
|
|
|
|
}
|
|
|
|
pub fn num_hair_colors(self) -> usize {
|
|
|
|
self.hair_colors().len()
|
|
|
|
}
|
|
|
|
pub fn skin_color(self, val: u8) -> Rgb<u8> {
|
|
|
|
self.skin_colors()
|
|
|
|
.get(val as usize)
|
|
|
|
.copied()
|
|
|
|
.unwrap_or((0, 0, 0))
|
|
|
|
.into()
|
|
|
|
}
|
|
|
|
pub fn num_skin_colors(self) -> usize {
|
|
|
|
self.skin_colors().len()
|
|
|
|
}
|
|
|
|
pub fn eye_color(self, val: u8) -> EyeColor {
|
|
|
|
self.eye_colors()
|
|
|
|
.get(val as usize)
|
|
|
|
.copied()
|
2019-08-29 09:29:36 +00:00
|
|
|
.unwrap_or(EyeColor::Blue)
|
2019-08-29 02:48:06 +00:00
|
|
|
}
|
|
|
|
pub fn num_eye_colors(self) -> usize {
|
|
|
|
self.eye_colors().len()
|
|
|
|
}
|
|
|
|
}
|
2019-06-28 23:42:51 +00:00
|
|
|
|
|
|
|
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
|
|
|
pub enum BodyType {
|
|
|
|
Female,
|
|
|
|
Male,
|
|
|
|
}
|
|
|
|
pub const ALL_BODY_TYPES: [BodyType; 2] = [BodyType::Female, BodyType::Male];
|
|
|
|
|
|
|
|
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
|
|
|
pub enum Chest {
|
|
|
|
Blue,
|
|
|
|
Brown,
|
|
|
|
Dark,
|
|
|
|
Green,
|
|
|
|
Orange,
|
|
|
|
}
|
|
|
|
pub const ALL_CHESTS: [Chest; 5] = [
|
|
|
|
Chest::Blue,
|
|
|
|
Chest::Brown,
|
|
|
|
Chest::Dark,
|
|
|
|
Chest::Green,
|
|
|
|
Chest::Orange,
|
|
|
|
];
|
|
|
|
|
|
|
|
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
|
|
|
pub enum Belt {
|
|
|
|
Dark,
|
|
|
|
}
|
|
|
|
pub const ALL_BELTS: [Belt; 1] = [
|
|
|
|
//Belt::Default,
|
|
|
|
Belt::Dark,
|
|
|
|
];
|
|
|
|
|
|
|
|
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
|
|
|
pub enum Pants {
|
|
|
|
Blue,
|
|
|
|
Brown,
|
|
|
|
Dark,
|
|
|
|
Green,
|
|
|
|
Orange,
|
|
|
|
}
|
|
|
|
pub const ALL_PANTS: [Pants; 5] = [
|
|
|
|
Pants::Blue,
|
|
|
|
Pants::Brown,
|
|
|
|
Pants::Dark,
|
|
|
|
Pants::Green,
|
|
|
|
Pants::Orange,
|
|
|
|
];
|
|
|
|
|
|
|
|
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
|
|
|
pub enum Hand {
|
|
|
|
Default,
|
|
|
|
}
|
|
|
|
pub const ALL_HANDS: [Hand; 1] = [Hand::Default];
|
|
|
|
|
|
|
|
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
|
|
|
pub enum Foot {
|
|
|
|
Dark,
|
|
|
|
}
|
|
|
|
pub const ALL_FEET: [Foot; 1] = [Foot::Dark];
|
|
|
|
|
|
|
|
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
|
|
|
pub enum Shoulder {
|
|
|
|
None,
|
|
|
|
Brown1,
|
|
|
|
}
|
|
|
|
pub const ALL_SHOULDERS: [Shoulder; 2] = [Shoulder::None, Shoulder::Brown1];
|
2019-08-24 23:18:47 +00:00
|
|
|
|
|
|
|
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
|
|
|
pub enum HairStyle {
|
|
|
|
None,
|
|
|
|
Temp1,
|
|
|
|
Temp2,
|
|
|
|
}
|
|
|
|
pub const ALL_HAIR_STYLES: [HairStyle; 3] = [HairStyle::None, HairStyle::Temp1, HairStyle::Temp2];
|
|
|
|
|
|
|
|
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
|
|
|
pub enum Eyebrows {
|
|
|
|
Yup,
|
|
|
|
}
|
|
|
|
pub const ALL_EYEBROWS: [Eyebrows; 1] = [Eyebrows::Yup];
|
|
|
|
|
|
|
|
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
|
|
|
pub enum EyeColor {
|
|
|
|
Black,
|
|
|
|
Blue,
|
|
|
|
Green,
|
|
|
|
Brown,
|
|
|
|
Red,
|
2019-08-29 09:29:36 +00:00
|
|
|
Orange,
|
2019-08-24 23:18:47 +00:00
|
|
|
White,
|
|
|
|
}
|
2019-08-29 09:29:36 +00:00
|
|
|
pub const ALL_EYE_COLORS: [EyeColor; 7] = [
|
2019-08-24 23:18:47 +00:00
|
|
|
EyeColor::Black,
|
|
|
|
EyeColor::Blue,
|
|
|
|
EyeColor::Green,
|
|
|
|
EyeColor::Brown,
|
|
|
|
EyeColor::Red,
|
|
|
|
EyeColor::White,
|
2019-08-29 09:29:36 +00:00
|
|
|
EyeColor::Orange,
|
2019-08-24 23:18:47 +00:00
|
|
|
];
|
2019-08-29 02:48:06 +00:00
|
|
|
impl EyeColor {
|
|
|
|
pub fn light_rgb(self) -> Rgb<u8> {
|
|
|
|
match self {
|
2019-08-29 09:29:36 +00:00
|
|
|
EyeColor::Black => Rgb::new(71, 59, 49),
|
|
|
|
EyeColor::Blue => Rgb::new(75, 158, 191),
|
|
|
|
EyeColor::Green => Rgb::new(110, 167, 113),
|
|
|
|
EyeColor::Brown => Rgb::new(73, 42, 36),
|
|
|
|
EyeColor::Red => Rgb::new(182, 0, 0),
|
2019-08-29 02:48:06 +00:00
|
|
|
EyeColor::White => Rgb::new(255, 255, 255),
|
2019-08-29 09:29:36 +00:00
|
|
|
EyeColor::Orange => Rgb::new(161, 69, 0),
|
2019-08-29 02:48:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
pub fn dark_rgb(self) -> Rgb<u8> {
|
|
|
|
match self {
|
2019-08-29 09:29:36 +00:00
|
|
|
EyeColor::Black => Rgb::new(32, 32, 32),
|
|
|
|
EyeColor::Blue => Rgb::new(62, 130, 159),
|
|
|
|
EyeColor::Green => Rgb::new(81, 124, 84),
|
|
|
|
EyeColor::Brown => Rgb::new(54, 30, 26),
|
|
|
|
EyeColor::Red => Rgb::new(148, 0, 0),
|
2019-08-29 02:48:06 +00:00
|
|
|
EyeColor::White => Rgb::new(255, 255, 255),
|
2019-08-29 09:29:36 +00:00
|
|
|
EyeColor::Orange => Rgb::new(148, 64, 0),
|
2019-08-29 02:48:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
pub fn white_rgb(self) -> Rgb<u8> {
|
|
|
|
match self {
|
|
|
|
EyeColor::White => Rgb::new(0, 0, 0),
|
|
|
|
_ => Rgb::new(255, 255, 255),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-08-24 23:18:47 +00:00
|
|
|
|
|
|
|
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
|
|
|
pub enum Accessory {
|
|
|
|
Nothing,
|
|
|
|
Something,
|
|
|
|
}
|
|
|
|
pub const ALL_ACCESSORIES: [Accessory; 2] = [Accessory::Nothing, Accessory::Something];
|
|
|
|
|
|
|
|
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
|
|
|
pub enum Beard {
|
|
|
|
None,
|
|
|
|
Some,
|
|
|
|
}
|
|
|
|
pub const ALL_BEARDS: [Beard; 2] = [Beard::None, Beard::Some];
|