Added attack hook event, attacks now cancel item use and sprite interaction.

This commit is contained in:
Sam 2021-08-28 21:55:01 -04:00
parent 513982ca43
commit 44c3b0f153
6 changed files with 47 additions and 14 deletions

View File

@ -452,6 +452,13 @@ impl Attack {
}
}
}
// Emits event to handle things that should happen for any successful attack,
// regardless of if the attack had any damages or effects in it
if is_applied {
emit(ServerEvent::EntityAttackedHook {
entity: target.entity,
});
}
is_applied
}
}

View File

@ -197,6 +197,9 @@ pub enum ServerEvent {
pet_entity: EcsEntity,
owner_entity: EcsEntity,
},
EntityAttackedHook {
entity: EcsEntity,
},
}
pub struct EventBus<E> {

View File

@ -134,18 +134,6 @@ impl<'a> System<'a> for Sys {
let was_wielded = char_state.is_wield();
let poise_state = poise.poise_state();
let pos = pos.0;
// Remove potion/saturation buff if knocked into poise state
if !matches!(poise_state, PoiseState::Normal) {
use comp::buff::{BuffChange, BuffKind};
server_emitter.emit(ServerEvent::Buff {
entity,
buff_change: BuffChange::RemoveByKind(BuffKind::Potion),
});
server_emitter.emit(ServerEvent::Buff {
entity,
buff_change: BuffChange::RemoveByKind(BuffKind::Saturation),
});
}
match poise_state {
PoiseState::Normal => {},
PoiseState::Interrupted => {

View File

@ -1230,3 +1230,30 @@ pub fn handle_teleport_to(server: &Server, entity: EcsEntity, target: Uid, max_r
}
}
}
/// Intended to handle things that should happen for any successful attack,
/// regardless of the damages and effects specific to that attack
pub fn handle_entity_attacked_hook(server: &Server, entity: EcsEntity) {
let ecs = &server.state.ecs();
let server_eventbus = ecs.read_resource::<EventBus<ServerEvent>>();
if let Some(mut char_state) = ecs.write_storage::<CharacterState>().get_mut(entity) {
// Interrupt sprite interaction and item use if any attack is applied to entity
if matches!(
*char_state,
CharacterState::SpriteInteract(_) | CharacterState::UseItem(_)
) {
*char_state = CharacterState::Idle;
}
}
// Remove potion/saturation buff if attacked
server_eventbus.emit_now(ServerEvent::Buff {
entity,
buff_change: buff::BuffChange::RemoveByKind(buff::BuffKind::Potion),
});
server_eventbus.emit_now(ServerEvent::Buff {
entity,
buff_change: buff::BuffChange::RemoveByKind(buff::BuffKind::Saturation),
});
}

View File

@ -7,7 +7,7 @@ use entity_creation::{
};
use entity_manipulation::{
handle_aura, handle_bonk, handle_buff, handle_combo_change, handle_damage, handle_delete,
handle_destroy, handle_energy_change, handle_explosion, handle_knockback,
handle_destroy, handle_energy_change, handle_entity_attacked_hook, handle_explosion, handle_knockback,
handle_land_on_ground, handle_poise, handle_respawn, handle_teleport_to,
};
use group_manip::handle_group;
@ -229,6 +229,9 @@ impl Server {
pet_entity,
owner_entity,
} => handle_tame_pet(self, pet_entity, owner_entity),
ServerEvent::EntityAttackedHook { entity } => {
handle_entity_attacked_hook(self, entity)
},
}
}

View File

@ -1148,7 +1148,12 @@ impl FigureMgr {
};
anim::character::CollectAnimation::update_skeleton(
&target_base,
(pos.0, time, Some(s.stage_section), anim::vek::Vec3::from(sprite_pos.map(|x| x as f32))),
(
pos.0,
time,
Some(s.stage_section),
anim::vek::Vec3::from(sprite_pos.map(|x| x as f32)),
),
stage_progress,
&mut state_animation_rate,
skeleton_attr,