updates?
This commit is contained in:
parent
e7d6b74aab
commit
35413b563c
33 changed files with 10238 additions and 1891 deletions
107
models/src/dto/player.rs
Normal file
107
models/src/dto/player.rs
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
use bevy_ecs::prelude::*;
|
||||
|
||||
use crate::{
|
||||
bundle::{
|
||||
armour::PlayerArmour,
|
||||
passive::{DrugCooldown, Education, FactionUpgrades, Merits, PassiveBundle},
|
||||
player::{PlayerBundle, PlayerStrategy, Weapons},
|
||||
stat::{Defence, Dexterity, Speed, StatBundle, Strength},
|
||||
},
|
||||
dto::{armour::ArmourDto, draw_id, weapon::WeaponDto},
|
||||
};
|
||||
|
||||
#[cfg_attr(feature = "json", derive(serde::Deserialize))]
|
||||
pub struct EquippedWeapons {
|
||||
pub primary: Option<WeaponDto>,
|
||||
pub secondary: Option<WeaponDto>,
|
||||
pub melee: Option<WeaponDto>,
|
||||
pub temporary: Option<WeaponDto>,
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "json", derive(serde::Deserialize))]
|
||||
#[derive(Default)]
|
||||
pub struct EquippedArmour {
|
||||
pub helmet: Option<ArmourDto>,
|
||||
pub body: Option<ArmourDto>,
|
||||
pub pants: Option<ArmourDto>,
|
||||
pub gloves: Option<ArmourDto>,
|
||||
pub boots: Option<ArmourDto>,
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "json", derive(serde::Deserialize))]
|
||||
pub struct Stats {
|
||||
pub str: f32,
|
||||
pub def: f32,
|
||||
pub spd: f32,
|
||||
pub dex: f32,
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "json", derive(serde::Deserialize))]
|
||||
pub struct PlayerDto {
|
||||
pub name: String,
|
||||
pub level: u16,
|
||||
pub stats: Stats,
|
||||
pub merits: Option<Merits>,
|
||||
pub education: Option<Education>,
|
||||
pub weapons: EquippedWeapons,
|
||||
pub armour: EquippedArmour,
|
||||
pub faction: Option<FactionUpgrades>,
|
||||
pub drug: Option<DrugCooldown>,
|
||||
pub strategy: PlayerStrategy,
|
||||
}
|
||||
|
||||
impl PlayerDto {
|
||||
pub fn spawn(self, world: &mut World) -> EntityWorldMut<'_> {
|
||||
let primary = self.weapons.primary.map(|p| p.spawn(world));
|
||||
let secondary = self.weapons.secondary.map(|s| s.spawn(world));
|
||||
let melee = self.weapons.melee.map(|m| m.spawn(world));
|
||||
let temporary = self.weapons.temporary.map(|m| m.spawn(world));
|
||||
let fists = WeaponDto::FISTS.spawn(world);
|
||||
let kick = WeaponDto::KITCHEN_KNIFE.spawn(world);
|
||||
|
||||
let head = self.armour.helmet.map(|a| a.spawn(world));
|
||||
let torso = self.armour.body.map(|a| a.spawn(world));
|
||||
let legs = self.armour.pants.map(|a| a.spawn(world));
|
||||
let hands = self.armour.gloves.map(|a| a.spawn(world));
|
||||
let feet = self.armour.boots.map(|a| a.spawn(world));
|
||||
|
||||
let mut commands = world.spawn(draw_id());
|
||||
|
||||
commands.insert((
|
||||
PlayerBundle::new(self.name, self.level, self.strategy),
|
||||
StatBundle::<Strength>::new(self.stats.str),
|
||||
StatBundle::<Defence>::new(self.stats.def),
|
||||
StatBundle::<Speed>::new(self.stats.spd),
|
||||
StatBundle::<Dexterity>::new(self.stats.dex),
|
||||
));
|
||||
|
||||
let education = self.education.unwrap_or_default();
|
||||
let merits = self.merits.unwrap_or_default();
|
||||
let faction = self.faction.unwrap_or_default();
|
||||
|
||||
commands.insert(PassiveBundle {
|
||||
education,
|
||||
merits,
|
||||
faction,
|
||||
});
|
||||
|
||||
commands.insert(Weapons {
|
||||
primary,
|
||||
secondary,
|
||||
melee,
|
||||
temporary,
|
||||
kick,
|
||||
fists,
|
||||
});
|
||||
|
||||
commands.insert(PlayerArmour {
|
||||
torso,
|
||||
head,
|
||||
legs,
|
||||
feet,
|
||||
hands,
|
||||
});
|
||||
|
||||
commands
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue