Browse Source

bunch of item additions

pull/3/head
jake 5 years ago
parent
commit
355de1a8a9
  1. 46
      src/item/armor.rs
  2. 18
      src/item/mod.rs
  3. 45
      src/item/shield.rs
  4. 64
      src/item/tool.rs
  5. 40
      src/item/weapon.rs

46
src/item/armor.rs

@ -0,0 +1,46 @@
use std::convert::{TryFrom, Into};
use std::io::{Read, Seek};
use crate::{PSOPacketData, PacketParseError};
#[derive(Debug, Copy, Clone, PartialEq)]
pub enum ArmorType {
Frame,
Armor,
}
impl ArmorType {
pub fn value(&self) -> [u8; 3] {
match self {
ArmorType::Frame => [0x01, 0x01, 0x00],
ArmorType::Armor => [0x01, 0x01, 0x00],
}
}
}
// TODO: TryFrom<&str>
// TODO Into<String>
#[derive(Debug, Copy, Clone, PartialEq)]
pub struct Armor {
pub armor: ArmorType,
pub dfp: u8,
pub evp: u8,
pub slots: u8,
}
impl Armor {
pub fn as_bytes(&self) -> [u8; 16] {
let mut result = [0; 16];
result[0..3].copy_from_slice(&self.armor.value());
// TODO: other attrs
result
}
}

18
src/item/mod.rs

@ -1,4 +1,7 @@
pub mod weapon;
pub mod tool;
pub mod armor;
pub mod shield;
use std::io::{Read, Seek};
use crate::{PSOPacketData, PacketParseError};
@ -8,11 +11,11 @@ use crate::{PSOPacketData, PacketParseError};
#[derive(Debug, Copy, Clone)]
pub enum Item {
Weapon(weapon::Weapon),
//Armor(Armor),
//Shield(Shield),
Armor(armor::Armor),
Shield(shield::Shield),
//Unit(Unit),
//Mag(Mag),
//Tool(Tool),
Tool(tool::Tool),
}
@ -23,8 +26,17 @@ impl Item {
pub fn as_bytes(&self) -> [u8; 16] {
match self {
Item::Weapon(wep) => wep.as_bytes(),
Item::Armor(armor) => armor.as_bytes(),
Item::Shield(shield) => shield.as_bytes(),
Item::Tool(tool) => tool.as_bytes(),
}
}
pub fn is_stackable(&self) -> bool {
match self {
Item::Tool(_) => true,
_ => false,
}
}
}

45
src/item/shield.rs

@ -0,0 +1,45 @@
use std::convert::{TryFrom, Into};
use std::io::{Read, Seek};
use crate::{PSOPacketData, PacketParseError};
#[derive(Debug, Copy, Clone, PartialEq)]
pub enum ShieldType {
Barrier,
Shield,
}
impl ShieldType {
pub fn value(&self) -> [u8; 3] {
match self {
ShieldType::Barrier => [0x01, 0x02, 0x00],
ShieldType::Shield => [0x01, 0x02, 0x01],
}
}
}
// TODO: TryFrom<&str>
// TODO Into<String>
#[derive(Debug, Copy, Clone, PartialEq)]
pub struct Shield {
pub shield: ShieldType,
pub dfp: u8,
pub evp: u8,
}
impl Shield {
pub fn as_bytes(&self) -> [u8; 16] {
let mut result = [0; 16];
result[0..3].copy_from_slice(&self.shield.value());
// TODO: other attrs
result
}
}

64
src/item/tool.rs

@ -0,0 +1,64 @@
#[derive(Debug, Copy, Clone, PartialEq)]
pub enum ToolType {
Monomate,
Dimate,
Trimate,
Monofluid,
Difluid,
Trifluid,
ScapeDoll,
}
impl ToolType {
pub fn is_stackable(&self) -> bool {
match self {
ToolType::Monomate => true,
ToolType::Dimate => true,
ToolType::Trimate => true,
ToolType::Monofluid => true,
ToolType::Difluid => true,
ToolType::Trifluid => true,
ToolType::ScapeDoll => false,
}
}
pub fn value(&self) -> [u8; 3] {
match self {
ToolType::Monomate => [0x03, 0x00, 0x00],
ToolType::Monofluid => [0x03, 0x01, 0x00],
_ => panic!()
}
}
}
#[derive(Debug, Copy, Clone, PartialEq)]
pub struct Tool {
pub tool: ToolType,
pub count: usize,
}
impl Tool {
pub fn new(tool: ToolType, count: usize) -> Tool {
Tool {
tool: tool,
count: count,
}
}
pub fn as_bytes(&self) -> [u8; 16] {
let mut result = [0; 16];
result[0..3].copy_from_slice(&self.tool.value());
result[5] = self.count as u8;
result
}
}

40
src/item/weapon.rs

@ -4,7 +4,7 @@ use std::io::{Read, Seek};
use crate::{PSOPacketData, PacketParseError};
#[derive(Debug, Copy, Clone)]
#[derive(Debug, Copy, Clone, PartialEq)]
pub enum Attribute {
Native,
ABeast,
@ -13,14 +13,14 @@ pub enum Attribute {
Hit
}
#[derive(Debug, Copy, Clone)]
#[derive(Debug, Copy, Clone, PartialEq)]
pub struct WeaponAttribute {
attr: Attribute,
value: u8,
}
#[derive(Debug, Copy, Clone)]
#[derive(Debug, Copy, Clone, PartialEq)]
pub enum WeaponSpecial {
Draw,
Drain,
@ -68,7 +68,7 @@ pub enum WeaponTypeError {
UnknownWeapon(String)
}
#[derive(Debug, Copy, Clone)]
#[derive(Debug, Copy, Clone, PartialEq)]
pub enum WeaponType {
Saber,
Handgun,
@ -76,7 +76,7 @@ pub enum WeaponType {
}
impl WeaponType {
fn value(&self) -> [u8; 3] {
pub fn value(&self) -> [u8; 3] {
match self {
WeaponType::Saber => [0x00, 0x01, 0x00],
WeaponType::Handgun => [0x00, 0x06, 0x00],
@ -108,7 +108,7 @@ impl Into<String> for WeaponType {
}
#[derive(Debug, Copy, Clone)]
#[derive(Debug, Copy, Clone, PartialEq)]
pub struct Weapon {
pub weapon: WeaponType,
pub special: Option<WeaponSpecial>,
@ -118,7 +118,7 @@ pub struct Weapon {
impl Weapon {
pub fn new(&self, wep: WeaponType) -> Weapon {
pub fn new(wep: WeaponType) -> Weapon {
Weapon {
weapon: wep,
special: None,
@ -131,33 +131,9 @@ impl Weapon {
let mut result = [0u8; 16];
result[0..3].copy_from_slice(&self.weapon.value());
result[3] = self.grind;
//result.extend_from_slice(&self.weapon.value());
//result.push(self.grind);
//result.extend_from_slice(&[0,0,0,0]);
//result.extend_from_slice(&[0,0,0,0]);
//result.extend_from_slice(&[0,0,0,0]);
// TODO: percents
result
}
}
/*impl PSOPacketData for Weapon{
fn from_bytes<R: Read + Seek>(cursor: &mut R) -> Result<Self, PacketParseError> {
unimplemented!()
}
fn as_bytes(&self) -> Vec<u8> {
let mut result = Vec::new();
result.extend_from_slice(&self.weapon.value());
result.push(self.grind);
result.extend_from_slice(&[0,0,0,0]);
result.extend_from_slice(&[0,0,0,0]);
result.extend_from_slice(&[0,0,0,0]);
result
}
}*/
Loading…
Cancel
Save