-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
103 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,43 @@ | ||
use crate::prelude::*; | ||
|
||
pub fn combat_system_melee( | ||
_commands: Commands, | ||
mut query: Query<(&mut Brain, &mut PhysicalBody)> | ||
mut commands: Commands, | ||
mut query: Query<(&mut Brain, &PhysicalBody, &Position, Option<&Targeting>)>, | ||
mut positions: Query<(Entity, &Position, &mut PhysicalBody)>, | ||
) { | ||
for (mut brain, mut physical_body) in query.iter_mut() { | ||
for (mut brain, physical_body, position, targeting) in query.iter_mut() { | ||
if brain.task != Some(Task::Fight) { continue; } | ||
|
||
// if let Some(n) = &mut physical_body.needs_entertainment { | ||
// n.current += 10.0; | ||
// if n.current >= n.max { | ||
// brain.motivation = None; | ||
// brain.task = None; | ||
// } | ||
// } | ||
if let Some(targeting) = targeting { | ||
let mut entity_found = false; | ||
for (entity, position2, mut physical_body2) in positions.iter_mut() { | ||
if entity == targeting.target { | ||
if position.distance(position2) <= 1 { | ||
// Attack! | ||
println!("Attack!"); | ||
entity_found = true; | ||
do_melee_damage(&mut commands, entity, physical_body, &mut physical_body2); | ||
//commands.entity(targeting.target); | ||
} else { | ||
// Try to follow/hunt the entity. | ||
} | ||
} | ||
} | ||
if !entity_found { | ||
brain.motivation = None; | ||
brain.task = None; | ||
} | ||
} | ||
} | ||
} | ||
|
||
fn do_melee_damage( | ||
commands: &mut Commands, | ||
entity: Entity, | ||
body1: &PhysicalBody, | ||
body2: &mut PhysicalBody, | ||
) { | ||
body2.attributes.health -= 10; | ||
if body2.attributes.health <= 0 { | ||
commands.entity(entity).despawn_recursive(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters