Merge branch 'qutrin/npc-levels' into 'master'

Enemies spawn with random levels, Nametags display levels

See merge request veloren/veloren!532
This commit is contained in:
Acrimon 2019-10-05 15:54:06 +00:00
commit 954881d84d
5 changed files with 48 additions and 33 deletions

View File

@ -133,10 +133,9 @@ impl Exp {
}
impl Level {
// TODO: Uncomment when needed
// pub fn set_level(&mut self, level: u32) {
// self.amount = level;
// }
pub fn set_level(&mut self, level: u32) {
self.amount = level;
}
pub fn level(&self) -> u32 {
self.amount
@ -167,6 +166,12 @@ impl Stats {
.set_to(self.health.maximum(), HealthSource::Revive);
self.is_dead = false;
}
// TODO: Delete this once stat points will be a thing
pub fn update_hp_bonus(&mut self, level: u32) {
self.health
.set_maximum(self.health.maximum() + (10 * level) / 2);
}
}
impl Stats {

View File

@ -40,10 +40,12 @@ impl<'a> System<'a> for Sys {
}
if stat.exp.current() >= stat.exp.maximum() {
stat.exp.change_by(-(stat.exp.maximum() as i64));
stat.exp.change_maximum_by(25);
stat.level.change_by(1);
stat.health.set_maximum(stat.health.maximum() + 10);
while stat.exp.current() >= stat.exp.maximum() {
stat.exp.change_by(-(stat.exp.maximum() as i64));
stat.exp.change_maximum_by(25);
stat.level.change_by(1);
}
stat.update_hp_bonus(stat.level.level());
stat.health
.set_to(stat.health.maximum(), HealthSource::LevelUp)
}

View File

@ -196,14 +196,14 @@ lazy_static! {
"waypoint",
"{}",
"/waypoint : Set your waypoint to your current position",
true,
false,
handle_waypoint,
),
ChatCommand::new(
"adminify",
"{}",
"/adminify <playername> : Temporarily gives a player admin permissions or removes them",
false, // TODO: NO
true,
handle_adminify,
),
ChatCommand::new(

View File

@ -560,6 +560,12 @@ impl Server {
};
let mut scale = 1.0;
// TODO: Remove this and implement scaling or level depending on stuff like species instead
stats.level.set_level(rand::thread_rng().gen_range(1, 20));
if stats.level.level() > 1 {
stats.update_hp_bonus(stats.level.level());
}
if npc.boss {
if rand::random::<f32>() < 0.8 {
stats = comp::Stats::new(

View File

@ -489,36 +489,38 @@ impl Hud {
let mut health_back_id_walker = self.ids.health_bar_backs.walk();
// Render Name Tags
for (pos, name, scale) in (&entities, &pos, &stats, players.maybe(), scales.maybe())
.join()
.filter(|(entity, _, stats, _, _)| *entity != me && !stats.is_dead)
// Don't process nametags outside the vd (visibility further limited by ui backend)
.filter(|(_, pos, _, _, _)| {
Vec2::from(pos.0 - player_pos)
.map2(TerrainChunk::RECT_SIZE, |d: f32, sz| {
d.abs() as f32 / sz as f32
})
.magnitude()
< view_distance as f32
})
.map(|(_, pos, stats, player, scale)| {
// TODO: This is temporary
// If the player used the default character name display their name instead
let name = if stats.name == "Character Name" {
player.map_or(&stats.name, |p| &p.alias)
} else {
&stats.name
};
(pos.0, name, scale)
})
for (pos, name, level, scale) in
(&entities, &pos, &stats, players.maybe(), scales.maybe())
.join()
.filter(|(entity, _, stats, _, _)| *entity != me && !stats.is_dead)
// Don't process nametags outside the vd (visibility further limited by ui backend)
.filter(|(_, pos, _, _, _)| {
Vec2::from(pos.0 - player_pos)
.map2(TerrainChunk::RECT_SIZE, |d: f32, sz| {
d.abs() as f32 / sz as f32
})
.magnitude()
< view_distance as f32
})
.map(|(_, pos, stats, player, scale)| {
// TODO: This is temporary
// If the player used the default character name display their name instead
let name = if stats.name == "Character Name" {
player.map_or(&stats.name, |p| &p.alias)
} else {
&stats.name
};
(pos.0, name, stats.level, scale)
})
{
let info = format!("{} Level {}", name, level.level());
let scale = scale.map(|s| s.0).unwrap_or(1.0);
let id = name_id_walker.next(
&mut self.ids.name_tags,
&mut ui_widgets.widget_id_generator(),
);
Text::new(&name)
Text::new(&info)
.font_size(20)
.color(Color::Rgba(0.61, 0.61, 0.89, 1.0))
.x_y(0.0, 0.0)