Created new fields in roll. Centralized generation of abilities. Added builder function for rolls since they are not yet tied to equipment.

This commit is contained in:
Sam 2020-11-05 12:28:18 -06:00
parent 121364821a
commit 55e75adec0
4 changed files with 56 additions and 33 deletions

View File

@ -113,7 +113,16 @@ pub enum CharacterAbility {
is_interruptible: bool,
},
BasicBlock,
Roll,
Roll {
energy_cost: u32,
buildup_duration: Duration,
movement_duration: Duration,
recover_duration: Duration,
roll_strength: f32,
buildup_iframes: bool,
movement_iframes: bool,
recover_iframes: bool,
},
ComboMelee {
stage_data: Vec<combo_melee::Stage>,
initial_energy_gain: u32,
@ -214,13 +223,12 @@ impl CharacterAbility {
/// applicable.
pub fn requirements_paid(&self, data: &JoinData, update: &mut StateUpdate) -> bool {
match self {
CharacterAbility::Roll => {
CharacterAbility::Roll {energy_cost, .. } => {
data.physics.on_ground
&& data.body.is_humanoid()
&& data.vel.0.xy().magnitude_squared() > 0.5
&& update
.energy
.try_change_by(-220, EnergySource::Ability)
.try_change_by(-(*energy_cost as i32), EnergySource::Ability)
.is_ok()
},
CharacterAbility::DashMelee { energy_cost, .. } => update
@ -293,8 +301,8 @@ impl From<Item> for ItemConfig {
ability1: ability_drain.next(),
ability2: ability_drain.next(),
ability3: ability_drain.next(),
block_ability: Some(CharacterAbility::BasicBlock),
dodge_ability: Some(CharacterAbility::Roll),
block_ability: None,
dodge_ability: Some(get_roll()),
};
}
@ -302,6 +310,19 @@ impl From<Item> for ItemConfig {
}
}
fn get_roll() -> CharacterAbility {
CharacterAbility::Roll {
energy_cost: 100,
buildup_duration: Duration::from_millis(100),
movement_duration: Duration::from_millis(250),
recover_duration: Duration::from_millis(150),
roll_strength: 1.0,
buildup_iframes: true,
movement_iframes: true,
recover_iframes: false,
}
}
#[derive(Arraygen, Clone, PartialEq, Default, Debug, Serialize, Deserialize)]
#[gen_array(pub fn get_armor: &Option<Item>)]
pub struct Loadout {
@ -461,11 +482,24 @@ impl From<(&CharacterAbility, AbilityKey)> for CharacterState {
exhausted: false,
}),
CharacterAbility::BasicBlock => CharacterState::BasicBlock,
CharacterAbility::Roll => CharacterState::Roll(roll::Data {
CharacterAbility::Roll {
energy_cost: _,
buildup_duration,
movement_duration,
recover_duration,
roll_strength,
buildup_iframes,
movement_iframes,
recover_iframes,
} => CharacterState::Roll(roll::Data {
static_data: roll::StaticData {
buildup_duration: Duration::from_millis(100),
movement_duration: Duration::from_millis(300),
recover_duration: Duration::from_millis(100),
buildup_duration: *buildup_duration,
movement_duration: *movement_duration,
recover_duration: *recover_duration,
roll_strength: *roll_strength,
buildup_iframes: *buildup_iframes,
movement_iframes: *movement_iframes,
recover_iframes: *recover_iframes,
},
timer: Duration::default(),
stage_section: StageSection::Buildup,

View File

@ -144,18 +144,8 @@ impl LoadoutBuilder {
_ => {},
};
let active_item = if let Some(ItemKind::Tool(tool)) = main_tool.as_ref().map(|i| i.kind()) {
let mut abilities = tool.get_abilities();
let mut ability_drain = abilities.drain(..);
main_tool.map(|item| ItemConfig {
item,
ability1: ability_drain.next(),
ability2: ability_drain.next(),
ability3: ability_drain.next(),
block_ability: None,
dodge_ability: Some(CharacterAbility::Roll),
})
let active_item = if let Some(ItemKind::Tool(_)) = main_tool.as_ref().map(|i| i.kind()) {
main_tool.map(|item| ItemConfig::from(item))
} else {
Some(ItemConfig {
// We need the empty item so npcs can attack

View File

@ -19,6 +19,14 @@ pub struct StaticData {
pub movement_duration: Duration,
/// How long it takes to recover from roll
pub recover_duration: Duration,
/// How strong the roll is
pub roll_strength: f32,
/// Whether you are immune to damage in buildup
pub buildup_iframes: bool,
/// Whether you are immune to damage in movement
pub movement_iframes: bool,
/// Whether you are immune to damage in recover
pub recover_iframes: bool,
}
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]

View File

@ -176,17 +176,8 @@ pub fn handle_possess(server: &Server, possessor_uid: Uid, possesse_uid: Uid) {
.or_insert(comp::Loadout::default());
let item = comp::Item::new_from_asset_expect("common.items.debug.possess");
if let item::ItemKind::Tool(tool) = item.kind() {
let mut abilities = tool.get_abilities();
let mut ability_drain = abilities.drain(..);
let debug_item = comp::ItemConfig {
item,
ability1: ability_drain.next(),
ability2: ability_drain.next(),
ability3: ability_drain.next(),
block_ability: None,
dodge_ability: None,
};
if let item::ItemKind::Tool(_) = item.kind() {
let debug_item = comp::ItemConfig::from(item);
std::mem::swap(&mut loadout.active_item, &mut loadout.second_item);
loadout.active_item = Some(debug_item);
}