exit basic_attack when no weapon is equipped

This commit is contained in:
timokoesters 2020-03-10 20:40:54 +01:00
parent 8efcda724e
commit d902828e00

View File

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