exit basic_attack when no weapon is equipped

This commit is contained in:
timokoesters 2020-03-10 20:40:54 +01:00
parent 841a2bbd6d
commit a3fc3c3122

View File

@ -21,58 +21,50 @@ pub fn behavior(data: &JoinData) -> StateUpdate {
remaining_duration,
} = data.character
{
handle_move(data, &mut update);
let tool_kind = data.stats.equipment.main.as_ref().map(|i| i.kind);
let can_apply_damage = !*exhausted
&& if let Some(Tool(tool)) = tool_kind {
*remaining_duration < tool.attack_recover_duration()
} else {
true
};
if let Some(Tool(tool)) = tool_kind {
handle_move(data, &mut update);
let mut new_exhausted = *exhausted;
let mut new_exhausted = *exhausted;
if can_apply_damage {
if let Some(Tool(tool)) = tool_kind {
if !*exhausted && *remaining_duration < tool.attack_recover_duration() {
data.updater.insert(data.entity, Attacking {
weapon: Some(tool),
applied: false,
hit_count: 0,
});
new_exhausted = true;
}
new_exhausted = true;
}
let new_remaining_duration = remaining_duration
.checked_sub(Duration::from_secs_f32(data.dt.0))
.unwrap_or_default();
let new_remaining_duration = remaining_duration
.checked_sub(Duration::from_secs_f32(data.dt.0))
.unwrap_or_default();
if let Some(attack) = data.attacking {
if attack.applied && attack.hit_count > 0 {
data.updater.remove::<Attacking>(data.entity);
update.energy.change_by(100, EnergySource::HitEnemy);
if let Some(attack) = data.attacking {
if attack.applied && attack.hit_count > 0 {
data.updater.remove::<Attacking>(data.entity);
update.energy.change_by(100, EnergySource::HitEnemy);
}
}
}
// Tick down
update.character = CharacterState::BasicAttack {
remaining_duration: new_remaining_duration,
exhausted: new_exhausted,
};
// Check if attack duration has expired
if new_remaining_duration == Duration::default() {
update.character = if let Some(Tool(tool)) = tool_kind {
CharacterState::Wielding { tool }
} else {
CharacterState::Idle {}
// Tick down
update.character = CharacterState::BasicAttack {
remaining_duration: new_remaining_duration,
exhausted: new_exhausted,
};
data.updater.remove::<Attacking>(data.entity);
}
update
// Check if attack duration has expired
if new_remaining_duration == Duration::default() {
update.character = CharacterState::Wielding { tool };
data.updater.remove::<Attacking>(data.entity);
}
update
} else {
update
}
} else {
update.character = CharacterState::Idle {};
update
}
}