Skip to content

[Chapter 66] Missing return in spell_trigger #228

Open
@PierreGuyot

Description

@PierreGuyot

pub fn spell_trigger(creator : Option<Entity>, spell: Entity, targets : &Targets, ecs: &mut World) {
if let Some(template) = ecs.read_storage::<SpellTemplate>().get(spell) {
let mut pools = ecs.write_storage::<Pools>();
if let Some(caster) = creator {
if let Some(pool) = pools.get_mut(caster) {
if template.mana_cost <= pool.mana.current {
pool.mana.current -= template.mana_cost;
}
}
}
}
event_trigger(creator, spell, targets, ecs);
}

There is a missing return statement after the check on the mana pool.
Currently, if the caster lacks the mana for a spell, the pool won't be updated but the spell will still be cast.
For the player, this won't happen because the spell will be cast from the targeting menu, which has the proper check against this, but a direct call to spell_trigger could lead to an error.

(If the check is always supposed to always have been done prior to the call, then let's simply remove it here.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions