Browse Source

Merge pull request 'weapon_bytes' (#102) from weapon_bytes into master

Reviewed-by: jake <jake@sharnoth.com>
pbs
jake 5 years ago
parent
commit
b92b118fc4
  1. 27
      src/entity/item/weapon.rs
  2. 6
      src/main.rs

27
src/entity/item/weapon.rs

@ -3,7 +3,7 @@ use serde::{Serialize, Deserialize};
#[derive(Debug, Copy, Clone, PartialEq, Eq, Ord, PartialOrd)]
pub enum Attribute {
Native,
Native = 1,
ABeast,
Machine,
Dark,
@ -16,10 +16,16 @@ pub struct WeaponAttribute {
pub value: i8,
}
impl WeaponAttribute {
pub fn value(&self) -> [u8; 2] {
[self.attr as u8, self.value as u8]
}
}
#[derive(Debug, Copy, Clone, PartialEq)]
pub enum WeaponSpecial {
Draw,
Draw = 1,
Drain,
Fill,
Gush,
@ -61,6 +67,12 @@ pub enum WeaponSpecial {
Demons,
}
impl WeaponSpecial {
pub fn value(&self) -> u8 {
*self as u8
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, enum_utils::FromStr, derive_more::Display)]
pub enum WeaponType {
Saber,
@ -879,7 +891,16 @@ impl Weapon {
let mut result = [0u8; 16];
result[0..3].copy_from_slice(&self.weapon.value());
result[3] = self.grind;
// TODO: percents
result[4] = self.special.map(|s| s.value()).unwrap_or(0);
if self.tekked == false {
result[4] += 0x80
};
result[6..8].copy_from_slice(&self.attrs[0].map(|s| s.value()).unwrap_or([0,0]));
result[8..10].copy_from_slice(&self.attrs[1].map(|s| s.value()).unwrap_or([0,0]));
result[10..12].copy_from_slice(&self.attrs[2].map(|s| s.value()).unwrap_or([0,0]));
result
}
}

6
src/main.rs

@ -87,8 +87,10 @@ fn main() {
item::weapon::Weapon {
weapon: item::weapon::WeaponType::Handgun,
grind: 5,
special: None,
attrs: [None; 3],
special: Some(item::weapon::WeaponSpecial::Hell),
attrs: [Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Hit, value: 100}),
None,
None,],
tekked: true,
}
),

Loading…
Cancel
Save