jake 5 years ago
parent
commit
9a1feb8836
  1. 75
      src/entity/item/mag.rs
  2. 7
      src/entity/item/mod.rs
  3. 1
      src/entity/item/tool.rs
  4. 27
      src/login/character.rs
  5. 7
      src/ship/items.rs

75
src/entity/item/mag.rs

@ -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
}
}

7
src/entity/item/mod.rs

@ -44,7 +44,8 @@ pub enum ItemType {
Shield(shield::ShieldType),
Unit(unit::UnitType),
Tool(tool::ToolType),
TechniqueDisk(tech::Technique)
TechniqueDisk(tech::Technique),
Mag(mag::MagType),
}
@ -55,7 +56,8 @@ pub enum ItemDetail {
Shield(shield::Shield),
Unit(unit::Unit),
Tool(tool::Tool),
TechniqueDisk(tech::TechniqueDisk)
TechniqueDisk(tech::TechniqueDisk),
Mag(mag::Mag),
}
impl ItemDetail {
@ -74,6 +76,7 @@ impl ItemDetail {
ItemDetail::Unit(u) => ItemType::Unit(u.unit),
ItemDetail::Tool(t) => ItemType::Tool(t.tool),
ItemDetail::TechniqueDisk(d) => ItemType::TechniqueDisk(d.tech),
ItemDetail::Mag(m) => ItemType::Mag(m.mag),
}
}
}

1
src/entity/item/tool.rs

@ -405,6 +405,7 @@ impl Tool {
result[0..3].copy_from_slice(&self.tool.value());
result
}
pub fn as_stacked_bytes(&self, len: usize) -> [u8; 16] {
let mut result = [0; 16];
result[0..3].copy_from_slice(&self.tool.value());

27
src/login/character.rs

@ -22,6 +22,7 @@ use crate::entity::item::weapon::Weapon;
use crate::entity::item::armor::Armor;
use crate::entity::item::tech::Technique;
use crate::entity::item::tool::Tool;
use crate::entity::item::mag::{Mag, MagType, PhotonBlast};
use crate::entity::character::{Character, CharacterClass, TechLevel};
use crate::login::login::get_login_status;
@ -201,7 +202,7 @@ fn new_character<EG: EntityGateway>(entity_gateway: &mut EG, user: &UserAccount,
let new_weapon = match char.char_class {
CharacterClass::HUmar | CharacterClass::HUnewearl | CharacterClass::HUcast | CharacterClass::HUcaseal => item::weapon::WeaponType::Saber,
CharacterClass::RAmar | CharacterClass::RAmarl | CharacterClass::RAcast | CharacterClass::RAcaseal => item::weapon::WeaponType::Handgun,
CharacterClass::FOmar | CharacterClass::FOmarl| CharacterClass::FOnewm | CharacterClass::FOnewearl => item::weapon::WeaponType::Cane,
CharacterClass::FOmar | CharacterClass::FOmarl | CharacterClass::FOnewm | CharacterClass::FOnewearl => item::weapon::WeaponType::Cane,
};
entity_gateway.new_item(
@ -233,6 +234,24 @@ fn new_character<EG: EntityGateway>(entity_gateway: &mut EG, user: &UserAccount,
index: 1,
});
entity_gateway.new_item(
ItemDetail::Mag(
Mag {
mag: MagType::Mag,
def: 500,
pow: 0,
dex: 0,
mnd: 0,
synchro: 20,
iq: 0,
photon_blast: [None; 3],
equipped: true,
}),
ItemLocation::Inventory {
character_id: char.id,
index: 2,
});
for _ in 0..4 {
entity_gateway.new_item(
ItemDetail::Tool (
@ -241,7 +260,7 @@ fn new_character<EG: EntityGateway>(entity_gateway: &mut EG, user: &UserAccount,
}),
ItemLocation::Inventory {
character_id: char.id,
index: 2,
index: 3,
});
entity_gateway.new_item(
ItemDetail::Tool (
@ -250,11 +269,9 @@ fn new_character<EG: EntityGateway>(entity_gateway: &mut EG, user: &UserAccount,
}),
ItemLocation::Inventory {
character_id: char.id,
index: 3,
index: 4,
});
}
// TODO: starter mag
}

7
src/ship/items.rs

@ -10,6 +10,7 @@ use crate::entity::item::armor::Armor;
use crate::entity::item::shield::Shield;
use crate::entity::item::unit::Unit;
use crate::entity::item::tool::Tool;
use crate::entity::item::mag::Mag;
#[derive(Debug, PartialEq)]
@ -39,6 +40,7 @@ impl ActiveItem {
ItemDetail::Unit(u) => u.as_bytes(),
ItemDetail::Tool(t) => t.as_individual_bytes(),
ItemDetail::TechniqueDisk(d) => d.as_bytes(),
ItemDetail::Mag(m) => m.as_bytes(),
}
},
StackedItem::Stacked(i) => {
@ -61,6 +63,7 @@ impl ActiveInventory {
.fold([InventoryItem::default(); 30], |mut inventory, (index, item)| {
let bytes = item.as_client_bytes();
inventory[index].data1.copy_from_slice(&bytes[0..12]);
inventory[index].data2.copy_from_slice(&bytes[12..16]);
inventory[index].item_id = item.id.0;
// does this do anything?
@ -69,7 +72,7 @@ impl ActiveInventory {
StackedItem::Individual(Item {item: ItemDetail::Armor(Armor {equipped: true, ..}), ..}) => 1,
StackedItem::Individual(Item {item: ItemDetail::Shield(Shield {equipped: true, ..}), ..}) => 1,
StackedItem::Individual(Item {item: ItemDetail::Unit(Unit{equipped: true, ..}), ..}) => 1,
//StackedItem::Individual(Item {item: ItemDetail::Mag(Mag{equipped: true, ..}), ..}) => 1,
StackedItem::Individual(Item {item: ItemDetail::Mag(Mag{equipped: true, ..}), ..}) => 1,
_ => 0,
};
// because this actually equips the item
@ -78,7 +81,7 @@ impl ActiveInventory {
StackedItem::Individual(Item {item: ItemDetail::Armor(Armor {equipped: true, ..}), ..}) => 8,
StackedItem::Individual(Item {item: ItemDetail::Shield(Shield {equipped: true, ..}), ..}) => 8,
StackedItem::Individual(Item {item: ItemDetail::Unit(Unit {equipped: true, ..}), ..}) => 8,
//StackedItem::Individual(Item {item: ItemDetail::Mag(Mag{equipped: true, ..}), ..}) => 8,
StackedItem::Individual(Item {item: ItemDetail::Mag(Mag{equipped: true, ..}), ..}) => 8,
_ => 0,
};
inventory

Loading…
Cancel
Save