cleans up mobs.json, adds MoveModes

This commit is contained in:
Llywelwyn 2023-08-15 20:28:21 +01:00
parent 198486df1d
commit 084e5e6f7b
5 changed files with 68 additions and 41 deletions

View file

@ -51,6 +51,17 @@ pub struct Faction {
pub name: String,
}
#[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq, Hash)]
pub enum Movement {
Static,
Random,
}
#[derive(Component, Debug, Serialize, Deserialize, Clone)]
pub struct MoveMode {
pub mode: Movement,
}
#[derive(Component, Debug, Serialize, Deserialize, Clone)]
pub struct Prop {}

View file

@ -559,6 +559,7 @@ fn main() -> rltk::BError {
gs.ecs.register::<NaturalAttacks>();
gs.ecs.register::<ArmourClassBonus>();
gs.ecs.register::<Cursed>();
gs.ecs.register::<MoveMode>();
gs.ecs.register::<ProvidesHealing>();
gs.ecs.register::<InflictsDamage>();
gs.ecs.register::<Ranged>();

View file

@ -291,10 +291,16 @@ pub fn spawn_named_mob(
}
let mut has_mind = true;
let mut has_faction = false;
let mut blocks_tile = true;
let mut has_move_mode = false;
if let Some(flags) = &mob_template.flags {
for flag in flags.iter() {
match flag.as_str() {
"BLOCKS_TILE" => eb = eb.with(BlocksTile {}),
"PASSABLE" => blocks_tile = false,
"STATIC" => {
eb = eb.with(MoveMode { mode: Movement::Static });
has_move_mode = true;
}
"MINDLESS" => {
eb = eb.with(Faction { name: "mindless".to_string() });
has_faction = true;
@ -322,6 +328,13 @@ pub fn spawn_named_mob(
}
}
}
if blocks_tile {
eb = eb.with(BlocksTile {});
}
// If we didn't already add one, just move randomly.
if !has_move_mode {
eb = eb.with(MoveMode { mode: Movement::Random });
}
// If we're anything other than MINDLESS, add a mind.
if has_mind {
eb = eb.with(Mind {});

View file

@ -83,6 +83,7 @@ pub fn save_game(ecs: &mut World) {
MagicMapper,
MeleeWeapon,
Mind,
MoveMode,
MultiAttack,
NaturalAttacks,
Name,
@ -200,6 +201,7 @@ pub fn load_game(ecs: &mut World) {
MagicMapper,
MeleeWeapon,
Mind,
MoveMode,
MultiAttack,
NaturalAttacks,
Name,