Made pets healable

This commit is contained in:
Joshua Barretto 2020-07-06 21:18:30 +01:00
parent 55852f9bc7
commit 99a526f702
2 changed files with 16 additions and 6 deletions

View File

@ -40,6 +40,16 @@ impl Alignment {
_ => false, _ => false,
} }
} }
// TODO: Remove this hack
pub fn is_friendly_to_players(&self) -> bool {
match self {
Alignment::Npc
| Alignment::Tame
| Alignment::Owned(_) => true,
_ => false,
}
}
} }
impl Component for Alignment { impl Component for Alignment {

View File

@ -1,6 +1,6 @@
use crate::{ use crate::{
comp::{ comp::{
Agent, Attacking, Body, CharacterState, HealthChange, HealthSource, Ori, Pos, Scale, Stats, Alignment, Attacking, Body, CharacterState, HealthChange, HealthSource, Ori, Pos, Scale, Stats,
}, },
event::{EventBus, LocalEvent, ServerEvent}, event::{EventBus, LocalEvent, ServerEvent},
sync::Uid, sync::Uid,
@ -25,7 +25,7 @@ impl<'a> System<'a> for Sys {
ReadStorage<'a, Pos>, ReadStorage<'a, Pos>,
ReadStorage<'a, Ori>, ReadStorage<'a, Ori>,
ReadStorage<'a, Scale>, ReadStorage<'a, Scale>,
ReadStorage<'a, Agent>, ReadStorage<'a, Alignment>,
ReadStorage<'a, Body>, ReadStorage<'a, Body>,
ReadStorage<'a, Stats>, ReadStorage<'a, Stats>,
WriteStorage<'a, Attacking>, WriteStorage<'a, Attacking>,
@ -42,7 +42,7 @@ impl<'a> System<'a> for Sys {
positions, positions,
orientations, orientations,
scales, scales,
agents, alignments,
bodies, bodies,
stats, stats,
mut attacking_storage, mut attacking_storage,
@ -74,7 +74,7 @@ impl<'a> System<'a> for Sys {
pos_b, pos_b,
ori_b, ori_b,
scale_b_maybe, scale_b_maybe,
agent_b_maybe, alignment_b_maybe,
character_b, character_b,
stats_b, stats_b,
body_b, body_b,
@ -84,7 +84,7 @@ impl<'a> System<'a> for Sys {
&positions, &positions,
&orientations, &orientations,
scales.maybe(), scales.maybe(),
agents.maybe(), alignments.maybe(),
character_states.maybe(), character_states.maybe(),
&stats, &stats,
&bodies, &bodies,
@ -120,7 +120,7 @@ impl<'a> System<'a> for Sys {
// TODO: remove this when there is a better way to target healing // TODO: remove this when there is a better way to target healing
// Don't heal npc's hp // Don't heal npc's hp
if agent_b_maybe.is_some() && healthchange > 0.0 { if alignment_b_maybe.map(|a| !a.is_friendly_to_players()).unwrap_or(true) && healthchange > 0.0 {
healthchange = 0.0; healthchange = 0.0;
} }