Some code clarity tweaks

This commit is contained in:
Timothy Warren 2022-02-04 09:53:30 -05:00
parent 351b149b27
commit 9b5adaad9c
2 changed files with 29 additions and 26 deletions

View File

@ -424,65 +424,66 @@ fn parse_particle(n: &str) -> SpawnParticleBurst {
macro_rules! apply_effects {
($effects:expr, $eb:expr) => {
for effect in $effects.iter() {
let effect_name = effect.0.as_str();
match effect_name {
// Effects are defined in the raws file as name => value pairs
for (effect_name, value) in $effects.iter() {
match effect_name.as_str() {
"provides_healing" => {
$eb = $eb.with(ProvidesHealing {
heal_amount: effect.1.parse::<i32>().unwrap(),
heal_amount: value.parse::<i32>().unwrap(),
});
}
"provides_mana" => {
$eb = $eb.with(ProvidesMana {
mana_amount: effect.1.parse::<i32>().unwrap(),
mana_amount: value.parse::<i32>().unwrap(),
})
}
"teach_spell" => {
$eb = $eb.with(TeachesSpell {
spell: effect.1.to_string(),
spell: value.to_string(),
})
}
"ranged" => {
$eb = $eb.with(Ranged {
range: effect.1.parse::<i32>().unwrap(),
range: value.parse::<i32>().unwrap(),
});
}
"damage" => {
$eb = $eb.with(InflictsDamage {
damage: effect.1.parse::<i32>().unwrap(),
damage: value.parse::<i32>().unwrap(),
});
}
"area_of_effect" => {
$eb = $eb.with(AreaOfEffect {
radius: effect.1.parse::<i32>().unwrap(),
radius: value.parse::<i32>().unwrap(),
});
}
"confusion" => {
$eb = $eb.with(Confusion {});
$eb = $eb.with(Duration {
turns: effect.1.parse::<i32>().unwrap(),
turns: value.parse::<i32>().unwrap(),
});
}
"magic_mapping" => $eb = $eb.with(MagicMapper {}),
"town_portal" => $eb = $eb.with(TownPortal {}),
"food" => $eb = $eb.with(ProvidesFood {}),
"single_activation" => $eb = $eb.with(SingleActivation {}),
"particle_line" => $eb = $eb.with(parse_particle_line(&effect.1)),
"particle" => $eb = $eb.with(parse_particle(&effect.1)),
"particle_line" => $eb = $eb.with(parse_particle_line(&value)),
"particle" => $eb = $eb.with(parse_particle(&value)),
"remove_curse" => $eb = $eb.with(ProvidesRemoveCurse {}),
"identify" => $eb = $eb.with(ProvidesIdentification {}),
"slow" => {
$eb = $eb.with(Slow {
initiative_penalty: effect.1.parse::<f32>().unwrap(),
initiative_penalty: value.parse::<f32>().unwrap(),
})
}
"damage_over_time" => {
$eb = $eb.with(DamageOverTime {
damage: effect.1.parse::<i32>().unwrap(),
damage: value.parse::<i32>().unwrap(),
})
}
"target_self" => $eb = $eb.with(AlwaysTargetsSelf {}),
_ => {
#[cfg(feature = "debug")]
console::log(format!(
"WARNING: consumable effect '{}' not implemented.",
effect_name

View File

@ -79,6 +79,8 @@ impl<'a> System<'a> for VisibleAI {
reaction.0 as i32 / map.width,
),
);
// First, see if we are attempting to cast a spell
if let Some(abilities) = abilities.get(entity) {
for ability in abilities.abilities.iter() {
if range >= ability.min_range
@ -103,34 +105,33 @@ impl<'a> System<'a> for VisibleAI {
},
)
.expect("Unable to insert intent to cast spell");
done = true;
}
}
}
// Check if there are targets if a ranged weapon is wielded
if !done {
for (weapon, equip) in (&weapons, &equipped).join() {
if let Some(wrange) = weapon.range {
if equip.owner == entity {
if equip.owner == entity && wrange >= range as i32 {
#[cfg(feature = "debug")]
console::log(format!(
"Owner found. Ranges: {}/{}",
"Owner found. Ranges: {}/{}. Inserting shoot",
wrange, range
));
if wrange >= range as i32 {
console::log("Inserting shoot");
wants_shoot
.insert(
entity,
WantsToShoot { target: reaction.2 },
)
.insert(entity, WantsToShoot { target: reaction.2 })
.expect("Unable to insert intent to shoot");
done = true;
}
}
}
}
}
// The target is not in range (yet), so approach/chase the target
if !done {
want_approach
.insert(
@ -143,6 +144,7 @@ impl<'a> System<'a> for VisibleAI {
chasing
.insert(entity, Chasing { target: reaction.2 })
.expect("Unable to insert intent to chase");
done = true;
}
}