aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client.rs10
-rw-r--r--src/server.rs13
-rw-r--r--src/shared/health.rs8
-rw-r--r--src/shared/player.rs5
-rw-r--r--src/shared/stats.rs3
5 files changed, 21 insertions, 18 deletions
diff --git a/src/client.rs b/src/client.rs
index 277fc2c..bd2c448 100644
--- a/src/client.rs
+++ b/src/client.rs
@@ -482,11 +482,15 @@ fn player_champion(
const HEALTH_OFFSET: f32 = 4.;
-fn render_health(players: Query<(&Health, &PlayerPosition)>, mut gizmos: Gizmos) {
- for (health, position) in players.iter() {
+fn render_health(players: Query<(&Health, &PlayerPosition, &EffectiveStats)>, mut gizmos: Gizmos) {
+ for (health, position, effective_stats) in players.iter() {
let start = position.0 + Vec2::new(-PLAYER_RADIUS, PLAYER_RADIUS + HEALTH_OFFSET);
let end = position.0 + Vec2::new(PLAYER_RADIUS, PLAYER_RADIUS + HEALTH_OFFSET);
- gizmos.line_2d(start, start.lerp(end, health.0 / MAX_HEALTH), Color::RED);
+ gizmos.line_2d(
+ start,
+ start.lerp(end, health.0 / effective_stats.0.max_health),
+ Color::RED,
+ );
}
}
diff --git a/src/server.rs b/src/server.rs
index 55e7ebc..0f34a12 100644
--- a/src/server.rs
+++ b/src/server.rs
@@ -506,11 +506,11 @@ const HEALTH_REGEN: f32 = 5.;
fn health_regen(
health_regen_timer: Res<HealthRegenTimer>,
mut connection_manager: ResMut<ServerConnectionManager>,
- mut healths: Query<(&PlayerId, &mut Health)>,
+ mut healths: Query<(&PlayerId, &mut Health, &EffectiveStats)>,
) {
if health_regen_timer.0.just_finished() {
- for (target_player, mut health) in healths.iter_mut() {
- health.0 = (health.0 + HEALTH_REGEN).min(MAX_HEALTH);
+ for (target_player, mut health, effective_stats) in healths.iter_mut() {
+ health.0 = (health.0 + HEALTH_REGEN).min(effective_stats.0.max_health);
let _ = connection_manager.send_message_to_target::<Channel1, HealthChanged>(
HealthChanged(HealthEvent {
target_player: *target_player,
@@ -522,8 +522,10 @@ fn health_regen(
}
}
-fn effective_stats(mut effective_statses: Query<(&Champion, &mut EffectiveStats, &Buffs)>) {
- for (champion, mut effective_stats, buffs) in effective_statses.iter_mut() {
+fn effective_stats(
+ mut effective_statses: Query<(&Champion, &mut EffectiveStats, &Buffs, &mut Health)>,
+) {
+ for (champion, mut effective_stats, buffs, mut health) in effective_statses.iter_mut() {
let mut stats = BaseStats::from_champion(*champion).0;
if buffs.slow.is_some() {
stats.movement_speed *= 0.85;
@@ -532,6 +534,7 @@ fn effective_stats(mut effective_statses: Query<(&Champion, &mut EffectiveStats,
stats.movement_speed *= 1.25;
}
effective_stats.0 = stats;
+ health.0 = health.0.min(effective_stats.0.max_health);
}
}
diff --git a/src/shared/health.rs b/src/shared/health.rs
index f4a288a..b88f19c 100644
--- a/src/shared/health.rs
+++ b/src/shared/health.rs
@@ -2,11 +2,3 @@ use crate::shared::*;
#[derive(Component, Message, Serialize, Deserialize, Clone, Copy, Debug, PartialEq)]
pub struct Health(pub f32);
-
-pub const MAX_HEALTH: f32 = 100.;
-
-impl Default for Health {
- fn default() -> Self {
- Health(MAX_HEALTH)
- }
-}
diff --git a/src/shared/player.rs b/src/shared/player.rs
index 4f571d8..c42f5cb 100644
--- a/src/shared/player.rs
+++ b/src/shared/player.rs
@@ -30,15 +30,16 @@ impl PlayerBundle {
replicate.target::<Cooldown>(NetworkTarget::Single(id));
replicate.target::<EffectiveStats>(NetworkTarget::Single(id));
let champion = Champion::default();
+ let effective_stats = EffectiveStats(BaseStats::from_champion(champion).0);
PlayerBundle {
id: PlayerId(id),
position: PlayerPosition(position),
color: PlayerColor(color),
imperative: Imperative::Idle,
cooldown: Cooldown::default(),
- health: Health::default(),
+ health: Health(effective_stats.0.max_health),
champion,
- effective_stats: EffectiveStats(BaseStats::from_champion(champion).0),
+ effective_stats,
buffs: Buffs::default(),
activation: Activation::default(),
replicate,
diff --git a/src/shared/stats.rs b/src/shared/stats.rs
index 8513a3c..ae449f0 100644
--- a/src/shared/stats.rs
+++ b/src/shared/stats.rs
@@ -4,6 +4,7 @@ use crate::shared::*;
pub struct Stats {
pub attack_range: f32,
pub movement_speed: f32,
+ pub max_health: f32,
}
#[derive(Component, Message, Clone, Copy, Serialize, Deserialize, PartialEq, Debug)]
@@ -18,10 +19,12 @@ impl BaseStats {
Champion::Meele => BaseStats(Stats {
attack_range: 25.,
movement_speed: 75.,
+ max_health: 150.,
}),
Champion::Ranged => BaseStats(Stats {
attack_range: 60.,
movement_speed: 85.,
+ max_health: 100.,
}),
}
}