mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
feat: add endurance fitness willpower to stats
This commit is contained in:
parent
c2b99f3a62
commit
4f90e6325e
@ -1,3 +1,4 @@
|
||||
use crate::comp::{body::humanoid::Race, Body};
|
||||
use crate::{comp, sync::Uid};
|
||||
use specs::{Component, FlaggedStorage};
|
||||
use specs_idvs::IDVStorage;
|
||||
@ -135,7 +136,7 @@ impl Level {
|
||||
}
|
||||
|
||||
pub fn change_by(&mut self, level: u32) {
|
||||
self.amount = self.amount + level;
|
||||
self.amount += level;
|
||||
}
|
||||
}
|
||||
|
||||
@ -146,6 +147,9 @@ pub struct Stats {
|
||||
pub level: Level,
|
||||
pub exp: Exp,
|
||||
pub equipment: Equipment,
|
||||
pub endurance: u32,
|
||||
pub fitness: u32,
|
||||
pub willpower: u32,
|
||||
pub is_dead: bool,
|
||||
}
|
||||
|
||||
@ -166,7 +170,23 @@ impl Stats {
|
||||
}
|
||||
|
||||
impl Stats {
|
||||
pub fn new(name: String, main: Option<comp::Item>) -> Self {
|
||||
pub fn new(name: String, body: Body, main: Option<comp::Item>) -> Self {
|
||||
let race = if let comp::Body::Humanoid(hbody) = body {
|
||||
Some(hbody.race)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let (endurance, fitness, willpower) = match race {
|
||||
Some(Race::Danari) => (0, 1, 2),
|
||||
Some(Race::Dwarf) => (1, 2, 0),
|
||||
Some(Race::Elf) => (2, 1, 0),
|
||||
Some(Race::Human) => (1, 0, 2),
|
||||
Some(Race::Orc) => (0, 2, 1),
|
||||
Some(Race::Undead) => (2, 0, 1),
|
||||
None => (0, 0, 0),
|
||||
};
|
||||
|
||||
let mut stats = Self {
|
||||
name,
|
||||
health: Health {
|
||||
@ -186,6 +206,9 @@ impl Stats {
|
||||
maximum: 50,
|
||||
},
|
||||
equipment: Equipment { main, alt: None },
|
||||
endurance,
|
||||
fitness,
|
||||
willpower,
|
||||
is_dead: false,
|
||||
};
|
||||
|
||||
|
@ -69,7 +69,7 @@ impl<'a> System<'a> for Sys {
|
||||
|
||||
stat.update_max_hp();
|
||||
stat.health
|
||||
.set_to(stat.health.maximum(), HealthSource::LevelUp)
|
||||
.set_to(stat.health.maximum(), HealthSource::LevelUp);
|
||||
}
|
||||
|
||||
// Accelerate recharging energy if not wielding.
|
||||
|
@ -484,9 +484,14 @@ fn handle_spawn(server: &mut Server, entity: EcsEntity, args: String, action: &C
|
||||
);
|
||||
|
||||
let body = kind_to_body(id);
|
||||
|
||||
let new_entity = server
|
||||
.state
|
||||
.create_npc(pos, comp::Stats::new(get_npc_name(id), None), body)
|
||||
.create_npc(
|
||||
pos,
|
||||
comp::Stats::new(get_npc_name(id), body, None),
|
||||
body,
|
||||
)
|
||||
.with(comp::Vel(vel))
|
||||
.with(comp::MountState::Unmounted)
|
||||
.with(agent.clone())
|
||||
|
@ -257,7 +257,7 @@ impl Server {
|
||||
let spawn_point = state.ecs().read_resource::<SpawnPoint>().0;
|
||||
|
||||
state.write_component(entity, body);
|
||||
state.write_component(entity, comp::Stats::new(name, main));
|
||||
state.write_component(entity, comp::Stats::new(name, body, main));
|
||||
state.write_component(entity, comp::Energy::new(1000));
|
||||
state.write_component(entity, comp::Controller::default());
|
||||
state.write_component(entity, comp::Pos(spawn_point));
|
||||
@ -501,11 +501,10 @@ impl Server {
|
||||
.get(entity)
|
||||
.map(|inv| !inv.is_full())
|
||||
.unwrap_or(false)
|
||||
&& state.try_set_block(pos, Block::empty()).is_some()
|
||||
{
|
||||
if state.try_set_block(pos, Block::empty()).is_some() {
|
||||
comp::Item::try_reclaim_from_block(block)
|
||||
.map(|item| state.give_item(entity, item));
|
||||
}
|
||||
comp::Item::try_reclaim_from_block(block)
|
||||
.map(|item| state.give_item(entity, item));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -517,8 +516,8 @@ impl Server {
|
||||
.get_mut(entity)
|
||||
.and_then(|inv| inv.remove(slot));
|
||||
|
||||
match item_opt {
|
||||
Some(item) => match item.kind {
|
||||
if let Some(item) = item_opt {
|
||||
match item.kind {
|
||||
comp::ItemKind::Tool { .. } => {
|
||||
if let Some(stats) = state
|
||||
.ecs()
|
||||
@ -548,8 +547,7 @@ impl Server {
|
||||
.get_mut(entity)
|
||||
.map(|inv| inv.insert(slot, item));
|
||||
}
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
state.write_component(entity, comp::InventoryUpdate);
|
||||
|
@ -97,15 +97,16 @@ impl<'a> System<'a> for Sys {
|
||||
// Handle chunk supplement
|
||||
for npc in supplement.npcs {
|
||||
let (mut stats, mut body) = if rand::random() {
|
||||
let body = comp::Body::Humanoid(comp::humanoid::Body::random());
|
||||
let stats = comp::Stats::new(
|
||||
"Traveler".to_string(),
|
||||
body,
|
||||
Some(assets::load_expect_cloned("common.items.weapons.staff_1")),
|
||||
);
|
||||
let body = comp::Body::Humanoid(comp::humanoid::Body::random());
|
||||
(stats, body)
|
||||
} else {
|
||||
let stats = comp::Stats::new("Wolf".to_string(), None);
|
||||
let body = comp::Body::QuadrupedMedium(comp::quadruped_medium::Body::random());
|
||||
let stats = comp::Stats::new("Wolf".to_string(), body, None);
|
||||
(stats, body)
|
||||
};
|
||||
let mut scale = 1.0;
|
||||
@ -115,11 +116,13 @@ impl<'a> System<'a> for Sys {
|
||||
|
||||
if npc.boss {
|
||||
if rand::random::<f32>() < 0.8 {
|
||||
let hbody = comp::humanoid::Body::random();
|
||||
body = comp::Body::Humanoid(hbody);
|
||||
stats = comp::Stats::new(
|
||||
"Fearless Wanderer".to_string(),
|
||||
body,
|
||||
Some(assets::load_expect_cloned("common.items.weapons.hammer_1")),
|
||||
);
|
||||
body = comp::Body::Humanoid(comp::humanoid::Body::random());
|
||||
}
|
||||
stats.level.set_level(rand::thread_rng().gen_range(8, 15));
|
||||
scale = 2.0 + rand::random::<f32>();
|
||||
|
Loading…
Reference in New Issue
Block a user