If you were in a stance when you used an ability, return to that stance after the ability is complete.

This commit is contained in:
Sam 2022-09-10 21:13:35 -04:00
parent 191174aa30
commit a2242b28f4
30 changed files with 97 additions and 158 deletions

View File

@ -180,6 +180,16 @@ impl CharacterState {
)
}
pub fn was_wielded(&self) -> bool {
match self {
CharacterState::Roll(data) => data.was_wielded,
CharacterState::Stunned(data) => data.was_wielded,
CharacterState::SpriteInteract(data) => data.static_data.was_wielded,
CharacterState::UseItem(data) => data.static_data.was_wielded,
_ => false,
}
}
pub fn is_stealthy(&self) -> bool {
matches!(
self,

View File

@ -9,7 +9,6 @@ use crate::{
states::{
behavior::{CharacterBehavior, JoinData},
utils::*,
wielding,
},
};
use serde::{Deserialize, Serialize};
@ -136,13 +135,12 @@ impl CharacterBehavior for Data {
});
} else {
// Done
update.character =
CharacterState::Wielding(wielding::Data { is_sneaking: false });
end_ability(data, &mut update);
}
},
_ => {
// If it somehow ends up in an incorrect stage section
update.character = CharacterState::Wielding(wielding::Data { is_sneaking: false });
end_ability(data, &mut update);
},
}

View File

@ -11,7 +11,6 @@ use crate::{
states::{
behavior::{CharacterBehavior, JoinData},
utils::*,
wielding,
},
terrain::Block,
uid::Uid,
@ -206,15 +205,14 @@ impl CharacterBehavior for Data {
});
} else {
// Done
update.character =
CharacterState::Wielding(wielding::Data { is_sneaking: false });
end_ability(data, &mut update);
// Make sure attack component is removed
data.updater.remove::<beam::Beam>(data.entity);
}
},
_ => {
// If it somehow ends up in an incorrect stage section
update.character = CharacterState::Wielding(wielding::Data { is_sneaking: false });
end_ability(data, &mut update);
// Make sure attack component is removed
data.updater.remove::<beam::Beam>(data.entity);
},

View File

@ -3,7 +3,6 @@ use crate::{
comp::{character_state::OutputEvents, CharacterState, StateUpdate},
states::{
behavior::{CharacterBehavior, JoinData},
wielding,
},
};
use serde::{Deserialize, Serialize};
@ -102,13 +101,12 @@ impl CharacterBehavior for Data {
});
} else {
// Done
update.character =
CharacterState::Wielding(wielding::Data { is_sneaking: false });
end_ability(data, &mut update);
}
},
_ => {
// If it somehow ends up in an incorrect stage section
update.character = CharacterState::Wielding(wielding::Data { is_sneaking: false });
end_ability(data, &mut update);
},
}

View File

@ -6,7 +6,6 @@ use crate::{
states::{
behavior::{CharacterBehavior, JoinData},
utils::*,
wielding,
},
};
use serde::{Deserialize, Serialize};
@ -122,14 +121,13 @@ impl CharacterBehavior for Data {
if input_is_pressed(data, self.static_data.ability_info.input) {
reset_state(self, data, output_events, &mut update);
} else {
update.character =
CharacterState::Wielding(wielding::Data { is_sneaking: false });
end_ability(data, &mut update);
}
}
},
_ => {
// If it somehow ends up in an incorrect stage section
update.character = CharacterState::Wielding(wielding::Data { is_sneaking: false });
end_ability(data, &mut update);
// Make sure attack component is removed
data.updater.remove::<Melee>(data.entity);
},

View File

@ -7,7 +7,6 @@ use crate::{
states::{
behavior::{CharacterBehavior, JoinData},
utils::*,
wielding,
},
util::Dir,
};
@ -127,14 +126,13 @@ impl CharacterBehavior for Data {
if input_is_pressed(data, self.static_data.ability_info.input) {
reset_state(self, data, output_events, &mut update);
} else {
update.character =
CharacterState::Wielding(wielding::Data { is_sneaking: false });
end_ability(data, &mut update);
}
}
},
_ => {
// If it somehow ends up in an incorrect stage section
update.character = CharacterState::Wielding(wielding::Data { is_sneaking: false });
end_ability(data, &mut update);
},
}

View File

@ -12,7 +12,6 @@ use crate::{
states::{
behavior::{CharacterBehavior, JoinData},
utils::*,
wielding,
},
terrain::Block,
vol::ReadVol,
@ -236,13 +235,12 @@ impl CharacterBehavior for Data {
});
} else {
// Done
update.character =
CharacterState::Wielding(wielding::Data { is_sneaking: false });
end_ability(data, &mut update);
}
},
_ => {
// If it somehow ends up in an incorrect stage section
update.character = CharacterState::Wielding(wielding::Data { is_sneaking: false });
end_ability(data, &mut update);
},
}

View File

@ -4,7 +4,6 @@ use crate::{
states::{
behavior::{CharacterBehavior, JoinData},
utils::*,
wielding,
},
};
use serde::{Deserialize, Serialize};
@ -81,13 +80,12 @@ impl CharacterBehavior for Data {
});
} else {
// Done
update.character =
CharacterState::Wielding(wielding::Data { is_sneaking: false });
end_ability(data, &mut update);
}
},
_ => {
// If it somehow ends up in an incorrect stage section
update.character = CharacterState::Wielding(wielding::Data { is_sneaking: false });
end_ability(data, &mut update);
},
}

View File

@ -3,7 +3,6 @@ use crate::{
states::{
behavior::{CharacterBehavior, JoinData},
utils::*,
wielding,
},
};
use serde::{Deserialize, Serialize};
@ -56,7 +55,7 @@ impl CharacterBehavior for Data {
.0
.magnitude()
.min(self.static_data.max_exit_velocity);
update.character = CharacterState::Wielding(wielding::Data { is_sneaking: false });
end_ability(data, &mut update);
}
}

View File

@ -5,7 +5,6 @@ use crate::{
states::{
behavior::{CharacterBehavior, JoinData},
utils::{StageSection, *},
wielding,
},
};
use serde::{Deserialize, Serialize};
@ -157,15 +156,14 @@ impl CharacterBehavior for Data {
});
} else {
// Done
update.character =
CharacterState::Wielding(wielding::Data { is_sneaking: false });
end_ability(data, &mut update);
// Make sure attack component is removed
data.updater.remove::<Melee>(data.entity);
}
},
_ => {
// If it somehow ends up in an incorrect stage section
update.character = CharacterState::Wielding(wielding::Data { is_sneaking: false });
end_ability(data, &mut update);
// Make sure attack component is removed
data.updater.remove::<Melee>(data.entity);
},

View File

@ -7,7 +7,6 @@ use crate::{
states::{
behavior::{CharacterBehavior, JoinData},
utils::*,
wielding,
},
};
use serde::{Deserialize, Serialize};
@ -173,13 +172,12 @@ impl CharacterBehavior for Data {
});
} else {
// Done
update.character =
CharacterState::Wielding(wielding::Data { is_sneaking: false });
end_ability(data, &mut update);
}
},
_ => {
// If it somehow ends up in an incorrect stage section
update.character = CharacterState::Wielding(wielding::Data { is_sneaking: false });
end_ability(data, &mut update);
},
}

View File

@ -8,7 +8,6 @@ use crate::{
states::{
behavior::{CharacterBehavior, JoinData},
utils::*,
wielding,
},
Damage, DamageKind, DamageSource, GroupTarget, Knockback, KnockbackDir,
};
@ -345,14 +344,13 @@ impl CharacterBehavior for Data {
if input_is_pressed(data, self.static_data.ability_info.input) {
reset_state(self, data, output_events, &mut update);
} else {
update.character =
CharacterState::Wielding(wielding::Data { is_sneaking: false });
end_ability(data, &mut update);
}
}
},
_ => {
// If it somehow ends up in an incorrect stage section
update.character = CharacterState::Wielding(wielding::Data { is_sneaking: false });
end_ability(data, &mut update);
// Make sure attack component is removed
data.updater.remove::<Melee>(data.entity);
},

View File

@ -6,7 +6,6 @@ use crate::{
states::{
behavior::{CharacterBehavior, JoinData},
utils::*,
wielding,
},
};
use serde::{Deserialize, Serialize};
@ -207,8 +206,7 @@ impl CharacterBehavior for Data {
}
} else {
// Return to wielding
update.character =
CharacterState::Wielding(wielding::Data { is_sneaking: false });
end_ability(data, &mut update);
// Make sure attack component is removed
data.updater.remove::<Melee>(data.entity);
}
@ -216,7 +214,7 @@ impl CharacterBehavior for Data {
},
Some(_) => {
// If it somehow ends up in an incorrect stage section
update.character = CharacterState::Wielding(wielding::Data { is_sneaking: false });
end_ability(data, &mut update);
// Make sure attack component is removed
data.updater.remove::<Melee>(data.entity);
},
@ -227,8 +225,7 @@ impl CharacterBehavior for Data {
}
} else {
// Done
update.character =
CharacterState::Wielding(wielding::Data { is_sneaking: false });
end_ability(data, &mut update);
// Make sure melee component is removed
data.updater.remove::<Melee>(data.entity);
}
@ -238,7 +235,7 @@ impl CharacterBehavior for Data {
if input_is_pressed(data, ability_input) {
next_strike(&mut update)
} else {
} else if !input_is_pressed(data, self.static_data.ability_info.input) {
attempt_input(data, output_events, &mut update);
}
},

View File

@ -6,7 +6,6 @@ use crate::{
states::{
behavior::{CharacterBehavior, JoinData},
utils::*,
wielding,
},
};
use serde::{Deserialize, Serialize};
@ -248,15 +247,14 @@ impl CharacterBehavior for Data {
});
} else {
// Done
update.character =
CharacterState::Wielding(wielding::Data { is_sneaking: false });
end_ability(data, &mut update);
// Make sure attack component is removed
data.updater.remove::<Melee>(data.entity);
}
},
_ => {
// If it somehow ends up in an incorrect stage section
update.character = CharacterState::Wielding(wielding::Data { is_sneaking: false });
end_ability(data, &mut update);
// Make sure attack component is removed
data.updater.remove::<Melee>(data.entity);
},

View File

@ -3,7 +3,6 @@ use crate::{
states::{
behavior::{CharacterBehavior, JoinData},
utils::{StageSection, *},
wielding,
},
};
use serde::{Deserialize, Serialize};
@ -66,8 +65,7 @@ impl CharacterBehavior for Data {
}
} else {
// In character state for too long, leaving in case somethign went wrong
update.character =
CharacterState::Wielding(wielding::Data { is_sneaking: false });
end_ability(data, &mut update);
}
},
StageSection::Action => {
@ -112,15 +110,14 @@ impl CharacterBehavior for Data {
}
} else {
// Done
update.character =
CharacterState::Wielding(wielding::Data { is_sneaking: false });
end_ability(data, &mut update);
// Make sure attack component is removed
data.updater.remove::<Melee>(data.entity);
}
},
_ => {
// If it somehow ends up in an incorrect stage section
update.character = CharacterState::Wielding(wielding::Data { is_sneaking: false });
end_ability(data, &mut update);
// Make sure attack component is removed
data.updater.remove::<Melee>(data.entity);
},

View File

@ -5,7 +5,6 @@ use crate::{
states::{
behavior::{CharacterBehavior, JoinData},
utils::*,
wielding,
},
};
use serde::{Deserialize, Serialize};
@ -132,15 +131,14 @@ impl CharacterBehavior for Data {
}
} else {
// Done
update.character =
CharacterState::Wielding(wielding::Data { is_sneaking: false });
end_ability(data, &mut update);
// Make sure attack component is removed
data.updater.remove::<Melee>(data.entity);
}
},
_ => {
// If it somehow ends up in an incorrect stage section
update.character = CharacterState::Wielding(wielding::Data { is_sneaking: false });
end_ability(data, &mut update);
// Make sure attack component is removed
data.updater.remove::<Melee>(data.entity);
},

View File

@ -3,7 +3,6 @@ use crate::{
states::{
behavior::{CharacterBehavior, JoinData},
utils::{StageSection, *},
wielding,
},
};
use serde::{Deserialize, Serialize};
@ -140,15 +139,14 @@ impl CharacterBehavior for Data {
});
} else {
// Done
update.character =
CharacterState::Wielding(wielding::Data { is_sneaking: false });
end_ability(data, &mut update);
// Make sure attack component is removed
data.updater.remove::<Melee>(data.entity);
}
},
_ => {
// If it somehow ends up in an incorrect stage section
update.character = CharacterState::Wielding(wielding::Data { is_sneaking: false });
end_ability(data, &mut update);
// Make sure attack component is removed
data.updater.remove::<Melee>(data.entity);
},

View File

@ -3,7 +3,6 @@ use crate::{
states::{
behavior::{CharacterBehavior, JoinData},
utils::*,
wielding,
},
};
use serde::{Deserialize, Serialize};
@ -60,14 +59,13 @@ impl CharacterBehavior for Data {
if input_is_pressed(data, self.static_data.ability_info.input) {
reset_state(self, data, output_events, &mut update);
} else {
update.character =
CharacterState::Wielding(wielding::Data { is_sneaking: false });
end_ability(data, &mut update);
}
}
},
_ => {
// If it somehow ends up in an incorrect stage section
update.character = CharacterState::Wielding(wielding::Data { is_sneaking: false });
end_ability(data, &mut update);
// Make sure attack component is removed
data.updater.remove::<Melee>(data.entity);
},

View File

@ -3,7 +3,6 @@ use crate::{
states::{
behavior::{CharacterBehavior, JoinData},
utils::*,
wielding,
},
};
use serde::{Deserialize, Serialize};
@ -114,15 +113,14 @@ impl CharacterBehavior for Data {
}
} else {
// Done
update.character =
CharacterState::Wielding(wielding::Data { is_sneaking: false });
end_ability(data, &mut update);
// Make sure attack component is removed
data.updater.remove::<Melee>(data.entity);
}
},
_ => {
// If it somehow ends up in an incorrect stage section
update.character = CharacterState::Wielding(wielding::Data { is_sneaking: false });
end_ability(data, &mut update);
// Make sure attack component is removed
data.updater.remove::<Melee>(data.entity);
},

View File

@ -7,7 +7,6 @@ use crate::{
states::{
behavior::{CharacterBehavior, JoinData},
utils::{StageSection, *},
wielding,
},
};
use serde::{Deserialize, Serialize};
@ -149,13 +148,12 @@ impl CharacterBehavior for Data {
});
} else {
// Done
update.character =
CharacterState::Wielding(wielding::Data { is_sneaking: false });
end_ability(data, &mut update);
}
},
_ => {
// If it somehow ends up in an incorrect stage section
update.character = CharacterState::Wielding(wielding::Data { is_sneaking: false });
end_ability(data, &mut update);
},
}

View File

@ -3,7 +3,6 @@ use crate::{
states::{
behavior::{CharacterBehavior, JoinData},
utils::*,
wielding,
},
};
use serde::{Deserialize, Serialize};
@ -56,8 +55,7 @@ impl CharacterBehavior for Data {
} else {
// If duration finishes with no pary occurring, end character state
// Transition to action happens in parry hook server event
update.character =
CharacterState::Wielding(wielding::Data { is_sneaking: false });
end_ability(data, &mut update);
}
},
StageSection::Action => {
@ -96,15 +94,14 @@ impl CharacterBehavior for Data {
}
} else {
// Done
update.character =
CharacterState::Wielding(wielding::Data { is_sneaking: false });
end_ability(data, &mut update);
// Make sure attack component is removed
data.updater.remove::<Melee>(data.entity);
}
},
_ => {
// If it somehow ends up in an incorrect stage section
update.character = CharacterState::Wielding(wielding::Data { is_sneaking: false });
end_ability(data, &mut update);
// Make sure attack component is removed
data.updater.remove::<Melee>(data.entity);
},

View File

@ -7,9 +7,7 @@ use crate::{
event::ServerEvent,
states::{
behavior::{CharacterBehavior, JoinData},
idle,
utils::*,
wielding,
},
};
use serde::{Deserialize, Serialize};
@ -134,30 +132,16 @@ impl CharacterBehavior for Data {
c.stage = stage;
}
} else {
update.character = CharacterState::Wielding(wielding::Data {
is_sneaking: self.is_sneaking,
});
end_ability(data, &mut update);
}
} else {
update.character = if self.was_wielded {
CharacterState::Wielding(wielding::Data {
is_sneaking: self.is_sneaking,
})
} else {
CharacterState::Idle(idle::Data {
is_sneaking: self.is_sneaking,
footwear: None,
})
}
end_ability(data, &mut update);
}
}
},
_ => {
// If it somehow ends up in an incorrect stage section
update.character = CharacterState::Idle(idle::Data {
is_sneaking: self.is_sneaking,
footwear: None,
});
end_ability(data, &mut update);
},
}

View File

@ -8,7 +8,6 @@ use crate::{
states::{
behavior::{CharacterBehavior, JoinData},
utils::*,
wielding,
},
};
use serde::{Deserialize, Serialize};
@ -105,13 +104,12 @@ impl CharacterBehavior for Data {
});
} else {
// Done
update.character =
CharacterState::Wielding(wielding::Data { is_sneaking: false });
end_ability(data, &mut update);
}
},
_ => {
// If it somehow ends up in an incorrect stage section
update.character = CharacterState::Wielding(wielding::Data { is_sneaking: false });
end_ability(data, &mut update);
},
}

View File

@ -8,7 +8,6 @@ use crate::{
states::{
behavior::{CharacterBehavior, JoinData},
utils::*,
wielding,
},
};
use serde::{Deserialize, Serialize};
@ -158,13 +157,12 @@ impl CharacterBehavior for Data {
});
} else {
// Done
update.character =
CharacterState::Wielding(wielding::Data { is_sneaking: false });
end_ability(data, &mut update);
}
},
_ => {
// If it somehow ends up in an incorrect stage section
update.character = CharacterState::Wielding(wielding::Data { is_sneaking: false });
end_ability(data, &mut update);
},
}

View File

@ -4,7 +4,6 @@ use crate::{
states::{
behavior::{CharacterBehavior, JoinData},
utils::*,
wielding,
},
};
use serde::{Deserialize, Serialize};
@ -152,15 +151,14 @@ impl CharacterBehavior for Data {
});
} else {
// Done
update.character =
CharacterState::Wielding(wielding::Data { is_sneaking: false });
end_ability(data, &mut update);
// Make sure attack component is removed
data.updater.remove::<Melee>(data.entity);
}
},
_ => {
// If it somehow ends up in an incorrect stage section
update.character = CharacterState::Wielding(wielding::Data { is_sneaking: false });
end_ability(data, &mut update);
// Make sure attack component is removed
data.updater.remove::<Melee>(data.entity);
},

View File

@ -4,7 +4,6 @@ use crate::{
event::ServerEvent,
states::{
behavior::{CharacterBehavior, JoinData},
idle, wielding,
},
terrain::SpriteKind,
util::Dir,
@ -98,22 +97,12 @@ impl CharacterBehavior for Data {
let inv_manip = InventoryManip::Collect(self.static_data.sprite_pos);
output_events.emit_server(ServerEvent::InventoryManip(data.entity, inv_manip));
// Done
update.character = if self.static_data.was_wielded {
CharacterState::Wielding(wielding::Data {
is_sneaking: self.static_data.was_sneak,
})
} else {
CharacterState::Idle(idle::Data {
is_sneaking: self.static_data.was_sneak,
footwear: None,
})
}
end_ability(data, &mut update);
}
},
_ => {
// If it somehow ends up in an incorrect stage section
update.character = CharacterState::Idle(idle::Data::default());
end_ability(data, &mut update);
},
}

View File

@ -5,7 +5,6 @@ use crate::{
states::{
behavior::{CharacterBehavior, JoinData},
utils::*,
wielding,
},
terrain::{Block, SpriteKind},
vol::ReadVol,
@ -157,13 +156,12 @@ impl CharacterBehavior for Data {
});
} else {
// Done
update.character =
CharacterState::Wielding(wielding::Data { is_sneaking: false });
end_ability(data, &mut update);
}
},
_ => {
// If it somehow ends up in an incorrect stage section
update.character = CharacterState::Wielding(wielding::Data { is_sneaking: false });
end_ability(data, &mut update);
},
}

View File

@ -3,7 +3,6 @@ use crate::{
comp::{character_state::OutputEvents, CharacterState, PoiseState, StateUpdate},
states::{
behavior::{CharacterBehavior, JoinData},
idle, wielding,
},
};
use serde::{Deserialize, Serialize};
@ -68,22 +67,12 @@ impl CharacterBehavior for Data {
});
} else {
// Done
if self.was_wielded {
update.character =
CharacterState::Wielding(wielding::Data { is_sneaking: false });
} else {
update.character = CharacterState::Idle(idle::Data::default());
}
end_ability(data, &mut update);
}
},
_ => {
// If it somehow ends up in an incorrect stage section
if self.was_wielded {
update.character =
CharacterState::Wielding(wielding::Data { is_sneaking: false });
} else {
update.character = CharacterState::Idle(idle::Data::default());
}
end_ability(data, &mut update);
},
}

View File

@ -12,7 +12,6 @@ use crate::{
event::ServerEvent,
states::{
behavior::{CharacterBehavior, JoinData},
idle, wielding,
},
};
use serde::{Deserialize, Serialize};
@ -125,21 +124,12 @@ impl CharacterBehavior for Data {
});
} else {
// Done
update.character = if self.static_data.was_wielded {
CharacterState::Wielding(wielding::Data {
is_sneaking: self.static_data.was_sneak,
})
} else {
CharacterState::Idle(idle::Data {
is_sneaking: self.static_data.was_sneak,
footwear: None,
})
}
end_ability(data, &mut update);
}
},
_ => {
// If it somehow ends up in an incorrect stage section
update.character = CharacterState::Idle(idle::Data::default());
end_ability(data, &mut update);
},
}

View File

@ -1282,6 +1282,7 @@ pub struct AbilityInfo {
pub input_attr: Option<InputAttr>,
pub ability_meta: AbilityMeta,
pub ability: Option<Ability>,
return_ability: Option<InputKind>,
}
impl AbilityInfo {
@ -1306,6 +1307,19 @@ impl AbilityInfo {
.zip(data.active_abilities)
.map(|(i, a)| a.get_ability(i, data.inventory, Some(data.skill_set)));
let return_ability = {
let should_return = match data.character {
CharacterState::ComboMelee2(data) => data.static_data.is_stance,
_ => false,
};
if should_return {
data.character.ability_info().map(|info| info.input)
} else {
None
}
};
Self {
tool,
hand,
@ -1313,10 +1327,23 @@ impl AbilityInfo {
input_attr: data.controller.queued_inputs.get(&input).copied(),
ability_meta,
ability,
return_ability,
}
}
}
pub fn end_ability(data: &JoinData<'_>, update: &mut StateUpdate) {
if let Some(return_ability) = data.character.ability_info().and_then(|info| info.return_ability) {
handle_ability(data, update, return_ability);
} else if data.character.is_wield() || data.character.was_wielded() {
update.character =
CharacterState::Wielding(wielding::Data { is_sneaking: data.character.is_stealthy() });
} else {
update.character =
CharacterState::Idle(idle::Data { is_sneaking: data.character.is_stealthy(), footwear: None });
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub enum HandInfo {
TwoHanded,