|
|
@ -1,7 +1,7 @@ |
|
|
|
use serde::{Serialize, Deserialize};
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize, enum_utils::FromStr, derive_more::Display)]
|
|
|
|
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, Serialize, Deserialize, enum_utils::FromStr, derive_more::Display)]
|
|
|
|
pub enum MagType {
|
|
|
|
Mag,
|
|
|
|
Varuna,
|
|
|
@ -176,21 +176,84 @@ pub enum PhotonBlast { |
|
|
|
|
|
|
|
#[derive(Debug, Copy, Clone, PartialEq)]
|
|
|
|
pub struct Mag {
|
|
|
|
pub unit: MagType,
|
|
|
|
pub def: u32,
|
|
|
|
pub pow: u32,
|
|
|
|
pub dex: u32,
|
|
|
|
pub mnd: u32,
|
|
|
|
pub mag: MagType,
|
|
|
|
pub def: u16,
|
|
|
|
pub pow: u16,
|
|
|
|
pub dex: u16,
|
|
|
|
pub mnd: u16,
|
|
|
|
pub synchro: u8,
|
|
|
|
pub iq: u8,
|
|
|
|
pub photon_blast: [Option<PhotonBlast>; 3],
|
|
|
|
// color
|
|
|
|
pub equipped: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl Mag {
|
|
|
|
pub fn as_bytes(&self) -> [u8; 16] {
|
|
|
|
let mut result = [0; 16];
|
|
|
|
result[0..3].copy_from_slice(&self.mag.value());
|
|
|
|
result[3] = self.photon_blast_value();
|
|
|
|
result[4..6].copy_from_slice(&self.def.to_le_bytes());
|
|
|
|
result[6..8].copy_from_slice(&self.pow.to_le_bytes());
|
|
|
|
result[8..10].copy_from_slice(&self.dex.to_le_bytes());
|
|
|
|
result[10..12].copy_from_slice(&self.mnd.to_le_bytes());
|
|
|
|
//result[12] = color
|
|
|
|
result[14] = self.photon_blast_count();
|
|
|
|
result[13] = self.iq;
|
|
|
|
result[12] = self.synchro;
|
|
|
|
result
|
|
|
|
}
|
|
|
|
|
|
|
|
fn photon_blast_value(&self) -> u8 {
|
|
|
|
let mut photon_blast_list = vec![PhotonBlast::Farlla,
|
|
|
|
PhotonBlast::Estlla,
|
|
|
|
PhotonBlast::Golla,
|
|
|
|
PhotonBlast::Pilla,
|
|
|
|
PhotonBlast::Leilla,
|
|
|
|
PhotonBlast::MyllaYoulla];
|
|
|
|
let mut photon_blast: u8 = 0;
|
|
|
|
|
|
|
|
if let Some(ref pb_mid) = self.photon_blast[0] {
|
|
|
|
match *pb_mid {
|
|
|
|
PhotonBlast::Farlla => {},
|
|
|
|
PhotonBlast::Estlla => photon_blast |= 1,
|
|
|
|
PhotonBlast::Golla => photon_blast |= 2,
|
|
|
|
PhotonBlast::Pilla => photon_blast |= 3,
|
|
|
|
PhotonBlast::Leilla => photon_blast |= 4,
|
|
|
|
PhotonBlast::MyllaYoulla => photon_blast |= 5,
|
|
|
|
}
|
|
|
|
|
|
|
|
photon_blast_list.retain(|k| k != pb_mid);
|
|
|
|
}
|
|
|
|
if let Some(ref pb_right) = self.photon_blast[1] {
|
|
|
|
match *pb_right {
|
|
|
|
PhotonBlast::Farlla => {}
|
|
|
|
PhotonBlast::Estlla => photon_blast |= 1 << 3,
|
|
|
|
PhotonBlast::Golla => photon_blast |= 2 << 3,
|
|
|
|
PhotonBlast::Pilla => photon_blast |= 3 << 3,
|
|
|
|
PhotonBlast::Leilla => photon_blast |= 4 << 3,
|
|
|
|
PhotonBlast::MyllaYoulla => photon_blast |= 5 << 3,
|
|
|
|
}
|
|
|
|
|
|
|
|
photon_blast_list.retain(|k| k != pb_right);
|
|
|
|
}
|
|
|
|
if let Some(ref pb_left) = self.photon_blast[2] {
|
|
|
|
if let Some(pos) = photon_blast_list.iter().position(|k| k == pb_left) {
|
|
|
|
photon_blast |= (pos as u8) << 6;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
photon_blast
|
|
|
|
}
|
|
|
|
|
|
|
|
fn photon_blast_count(&self) -> u8 {
|
|
|
|
let mut count = 0;
|
|
|
|
for i in 0..3 {
|
|
|
|
if let Some(_) = self.photon_blast[i] {
|
|
|
|
count |= 1 << i
|
|
|
|
};
|
|
|
|
}
|
|
|
|
count
|
|
|
|
}
|
|
|
|
}
|