fix: non-humanoid npcs can attack again

This commit is contained in:
timokoesters 2020-02-24 22:20:50 +01:00
parent d0439fdd84
commit 4cc998f92b
5 changed files with 18 additions and 18 deletions

View File

@ -143,7 +143,7 @@ impl Component for CharacterState {
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)]
pub struct Attacking {
pub weapon: ToolData,
pub weapon: Option<ToolData>,
}
impl Component for Attacking {

View File

@ -14,14 +14,14 @@ pub struct State {
impl StateHandler for State {
fn new(ecs_data: &EcsStateData) -> Self {
let tool_data =
let remaining_duration =
if let Some(Tool(data)) = ecs_data.stats.equipment.main.as_ref().map(|i| i.kind) {
data
data.attack_duration()
} else {
ToolData::default()
Duration::from_millis(300)
};
Self {
remaining_duration: tool_data.attack_duration(),
remaining_duration,
exhausted: false,
}
}
@ -43,7 +43,7 @@ impl StateHandler for State {
&& if let Some(Tool(data)) = tool_kind {
(self.remaining_duration < data.attack_recover_duration())
} else {
false
true
};
let mut exhausted = self.exhausted;
@ -52,9 +52,13 @@ impl StateHandler for State {
if let Some(Tool(data)) = tool_kind {
ecs_data
.updater
.insert(*ecs_data.entity, Attacking { weapon: data });
exhausted = true;
.insert(*ecs_data.entity, Attacking { weapon: Some(data) });
} else {
ecs_data
.updater
.insert(*ecs_data.entity, Attacking { weapon: None });
}
exhausted = true;
} else {
ecs_data.updater.remove::<Attacking>(*ecs_data.entity);
}

View File

@ -47,9 +47,7 @@ pub fn handle_move_dir(ecs_data: &EcsStateData, update: &mut StateUpdate) {
pub fn handle_wield(ecs_data: &EcsStateData, update: &mut StateUpdate) {
if ecs_data.inputs.primary.is_pressed() {
if let Some(Tool(_)) = ecs_data.stats.equipment.main.as_ref().map(|i| &i.kind) {
update.character = CharacterState::Wielding(None);
}
update.character = CharacterState::Wielding(None);
}
}

View File

@ -14,16 +14,14 @@ pub struct State {
impl StateHandler for State {
fn new(ecs_data: &EcsStateData) -> Self {
let tool_data =
let equip_delay =
if let Some(Tool(data)) = ecs_data.stats.equipment.main.as_ref().map(|i| i.kind) {
data
data.equip_time()
} else {
ToolData::default()
Duration::default()
};
Self {
equip_delay: tool_data.equip_time(),
}
Self { equip_delay }
}
fn handle(&self, ecs_data: &EcsStateData) -> StateUpdate {

View File

@ -99,7 +99,7 @@ impl<'a> System<'a> for Sys {
&& ori2.angle_between(pos_b2 - pos2) < ATTACK_ANGLE.to_radians() / 2.0 + (rad_b / pos2.distance(pos_b2)).atan()
{
// Weapon gives base damage
let mut dmg = attack.weapon.base_damage as i32;
let mut dmg = attack.weapon.map(|w| w.base_damage as i32).unwrap_or(3);
// Block
if character_b.is_block()