You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

135 lines
2.4 KiB

use std::convert::{TryFrom, Into};
#[derive(Debug, Copy, Clone, PartialEq)]
pub enum Attribute {
Native,
ABeast,
Machine,
Dark,
Hit
}
#[derive(Debug, Copy, Clone, PartialEq)]
pub struct WeaponAttribute {
attr: Attribute,
value: u8,
}
#[derive(Debug, Copy, Clone, PartialEq)]
pub enum WeaponSpecial {
Draw,
Drain,
Fill,
Gush,
Heart,
Mind,
Soul,
Geist,
Masters,
Lords,
Kings,
Charge,
Spirit,
Berserk,
Ice,
Frost,
Freeze,
Blizzard,
Bind,
Hold,
Seize,
Arrest,
Heat,
Fire,
Flame,
Burning,
Shock,
Thunder,
Storm,
Tempest,
Dim,
Shadow,
Dark,
Hell,
Panic,
Riot,
Havoc,
Chaos,
Devils,
Demons,
}
pub enum WeaponTypeError {
UnknownWeapon(String)
}
#[derive(Debug, Copy, Clone, PartialEq)]
pub enum WeaponType {
Saber,
Handgun,
Cane,
}
impl WeaponType {
pub fn value(&self) -> [u8; 3] {
match self {
WeaponType::Saber => [0x00, 0x01, 0x00],
WeaponType::Handgun => [0x00, 0x06, 0x00],
WeaponType::Cane => [0x00, 0x0A, 0x00],
}
}
}
impl TryFrom<&str> for WeaponType {
type Error = WeaponTypeError;
fn try_from(value: &str) -> Result<WeaponType, WeaponTypeError> {
match value {
"Saber" => Ok(WeaponType::Saber),
"Handgun" => Ok(WeaponType::Handgun),
"Cane" => Ok(WeaponType::Cane),
_ => Err(WeaponTypeError::UnknownWeapon(value.to_string()))
}
}
}
impl Into<String> for WeaponType {
fn into(self) -> String {
match self {
WeaponType::Saber => "Saber",
WeaponType::Handgun => "Handgun",
WeaponType::Cane => "Cane",
}.to_string()
}
}
#[derive(Debug, Copy, Clone, PartialEq)]
pub struct Weapon {
pub weapon: WeaponType,
pub special: Option<WeaponSpecial>,
pub grind: u8,
pub attrs: [Option<WeaponAttribute>; 3],
}
impl Weapon {
pub fn new(wep: WeaponType) -> Weapon {
Weapon {
weapon: wep,
special: None,
grind: 0,
attrs: [None; 3]
}
}
pub fn as_bytes(&self) -> [u8; 16] {
let mut result = [0u8; 16];
result[0..3].copy_from_slice(&self.weapon.value());
result[3] = self.grind;
// TODO: percents
result
}
}