Made ability key not hardcoded in tool.rs.

This commit is contained in:
Sam 2020-10-15 20:05:58 -05:00
parent d869f7e430
commit e6684009c2
4 changed files with 15 additions and 23 deletions

View File

@ -75,7 +75,6 @@ pub enum CharacterAbility {
projectile_light: Option<LightEmitter>,
projectile_gravity: Option<Gravity>,
projectile_speed: f32,
ability_key: AbilityKey,
},
RepeaterRanged {
energy_cost: u32,
@ -206,7 +205,6 @@ pub enum CharacterAbility {
energy_regen: u32,
energy_cost: u32,
energy_drain: u32,
ability_key: AbilityKey,
},
}
@ -353,8 +351,8 @@ impl Loadout {
}
}
impl From<&CharacterAbility> for CharacterState {
fn from(ability: &CharacterAbility) -> Self {
impl From<(&CharacterAbility, AbilityKey)> for CharacterState {
fn from((ability, key): (&CharacterAbility, AbilityKey)) -> Self {
match ability {
CharacterAbility::BasicMelee {
buildup_duration,
@ -383,7 +381,6 @@ impl From<&CharacterAbility> for CharacterState {
projectile_gravity,
projectile_speed,
energy_cost: _,
ability_key,
} => CharacterState::BasicRanged(basic_ranged::Data {
exhausted: false,
prepare_timer: Duration::default(),
@ -395,7 +392,7 @@ impl From<&CharacterAbility> for CharacterState {
projectile_light: *projectile_light,
projectile_gravity: *projectile_gravity,
projectile_speed: *projectile_speed,
ability_key: *ability_key,
ability_key: key,
}),
CharacterAbility::Boost { duration, only_up } => CharacterState::Boost(boost::Data {
duration: *duration,
@ -667,7 +664,6 @@ impl From<&CharacterAbility> for CharacterState {
energy_regen,
energy_cost,
energy_drain,
ability_key,
} => CharacterState::BasicBeam(basic_beam::Data {
static_data: basic_beam::StaticData {
buildup_duration: *buildup_duration,
@ -682,7 +678,7 @@ impl From<&CharacterAbility> for CharacterState {
energy_regen: *energy_regen,
energy_cost: *energy_cost,
energy_drain: *energy_drain,
ability_key: *ability_key,
ability_key: key,
},
timer: Duration::default(),
stage_section: StageSection::Buildup,

View File

@ -3,7 +3,7 @@
use crate::{
comp::{body::object, projectile, Body, CharacterAbility, Gravity, LightEmitter, Projectile},
states::{combo_melee, utils::AbilityKey},
states::combo_melee,
Explosion,
};
use serde::{Deserialize, Serialize};
@ -309,7 +309,6 @@ impl Tool {
projectile_light: None,
projectile_gravity: Some(Gravity(0.2)),
projectile_speed: 100.0,
ability_key: AbilityKey::Mouse1,
},
ChargedRanged {
energy_cost: 0,
@ -376,7 +375,6 @@ impl Tool {
energy_regen: 50,
energy_cost: 100,
energy_drain: 0,
ability_key: AbilityKey::Mouse1,
},
BasicRanged {
energy_cost: 800,
@ -419,7 +417,6 @@ impl Tool {
}),
projectile_gravity: Some(Gravity(0.5)),
projectile_speed: 40.0,
ability_key: AbilityKey::Mouse2,
},
],
Staff(_) => vec![
@ -464,7 +461,6 @@ impl Tool {
}),
projectile_gravity: Some(Gravity(0.3)),
projectile_speed: 60.0,
ability_key: AbilityKey::Mouse1,
},
BasicBeam {
buildup_duration: Duration::from_millis(250),
@ -479,7 +475,6 @@ impl Tool {
energy_regen: 0,
energy_cost: 0,
energy_drain: 350,
ability_key: AbilityKey::Mouse2,
},
Shockwave {
energy_cost: 600,
@ -580,7 +575,6 @@ impl Tool {
}),
projectile_gravity: None,
projectile_speed: 100.0,
ability_key: AbilityKey::Skill1,
},
]
} else {

View File

@ -253,7 +253,7 @@ pub fn handle_ability1_input(data: &JoinData, update: &mut StateUpdate) {
.and_then(|i| i.ability1.as_ref())
.filter(|ability| ability.requirements_paid(data, update))
{
update.character = ability.into();
update.character = (ability, AbilityKey::Mouse1).into();
}
}
}
@ -283,7 +283,7 @@ pub fn handle_ability2_input(data: &JoinData, update: &mut StateUpdate) {
.and_then(|i| i.ability2.as_ref())
.filter(|ability| ability.requirements_paid(data, update))
{
update.character = ability.into();
update.character = (ability, AbilityKey::Mouse2).into();
}
},
(_, Some(Hands::OneHand)) => {
@ -294,7 +294,7 @@ pub fn handle_ability2_input(data: &JoinData, update: &mut StateUpdate) {
.and_then(|i| i.ability2.as_ref())
.filter(|ability| ability.requirements_paid(data, update))
{
update.character = ability.into();
update.character = (ability, AbilityKey::Mouse2).into();
}
},
(_, _) => {},
@ -312,7 +312,7 @@ pub fn handle_ability3_input(data: &JoinData, update: &mut StateUpdate) {
.and_then(|i| i.ability3.as_ref())
.filter(|ability| ability.requirements_paid(data, update))
{
update.character = ability.into();
update.character = (ability, AbilityKey::Skill1).into();
}
}
}
@ -329,12 +329,12 @@ pub fn handle_dodge_input(data: &JoinData, update: &mut StateUpdate) {
.filter(|ability| ability.requirements_paid(data, update))
{
if data.character.is_wield() {
update.character = ability.into();
update.character = (ability, AbilityKey::Dodge).into();
if let CharacterState::Roll(roll) = &mut update.character {
roll.was_wielded = true;
}
} else {
update.character = ability.into();
update.character = (ability, AbilityKey::Dodge).into();
}
}
}
@ -360,6 +360,7 @@ pub fn ability_key_is_pressed(data: &JoinData, ability_key: AbilityKey) -> bool
AbilityKey::Mouse1 => data.inputs.primary.is_pressed(),
AbilityKey::Mouse2 => data.inputs.secondary.is_pressed(),
AbilityKey::Skill1 => data.inputs.ability3.is_pressed(),
AbilityKey::Dodge => data.inputs.roll.is_pressed(),
}
}
@ -382,4 +383,5 @@ pub enum AbilityKey {
Mouse1,
Mouse2,
Skill1,
Dodge,
}

View File

@ -545,8 +545,8 @@ pub fn handle_explosion(
}
// Don't heal if outside group
// Don't damage in the same group
let is_damage = (friendly_damage || !same_group) && (explosion.max_damage > 0);
let is_heal = same_group && (explosion.max_heal > 0);
let is_damage = (friendly_damage || !same_group) && explosion.max_damage > 0;
let is_heal = same_group && explosion.max_heal > 0 && !friendly_damage;
if !is_heal && !is_damage {
continue;
}