Stances can now be left by interacting with the buff bar.

This commit is contained in:
Sam 2023-01-28 11:44:24 -05:00
parent 34168d9c76
commit 3caa9dc529
7 changed files with 68 additions and 53 deletions

View File

@ -1315,6 +1315,10 @@ impl Client {
))); )));
} }
pub fn leave_stance(&mut self) {
self.send_msg(ClientGeneral::ControlEvent(ControlEvent::LeaveStance));
}
pub fn unlock_skill(&mut self, skill: Skill) { pub fn unlock_skill(&mut self, skill: Skill) {
self.send_msg(ClientGeneral::UnlockSkill(skill)); self.send_msg(ClientGeneral::UnlockSkill(skill));
} }

View File

@ -2894,7 +2894,7 @@ pub struct AbilityRequirements {
pub stance: Option<Stance>, pub stance: Option<Stance>,
} }
#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Hash)] #[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Hash, PartialOrd, Ord)]
pub enum SwordStance { pub enum SwordStance {
Crippling, Crippling,
Cleaving, Cleaving,
@ -2922,12 +2922,31 @@ bitflags::bitflags! {
} }
} }
#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Hash)] #[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Hash, PartialOrd, Ord)]
pub enum Stance { pub enum Stance {
None, None,
Sword(SwordStance), Sword(SwordStance),
} }
impl Stance {
pub fn pseudo_ability_id(&self) -> &str {
match self {
Stance::Sword(SwordStance::Heavy) => "veloren.core.pseudo_abilities.sword.heavy_stance",
Stance::Sword(SwordStance::Agile) => "veloren.core.pseudo_abilities.sword.agile_stance",
Stance::Sword(SwordStance::Defensive) => {
"veloren.core.pseudo_abilities.sword.defensive_stance"
},
Stance::Sword(SwordStance::Crippling) => {
"veloren.core.pseudo_abilities.sword.crippling_stance"
},
Stance::Sword(SwordStance::Cleaving) => {
"veloren.core.pseudo_abilities.sword.cleaving_stance"
},
Stance::None => "veloren.core.pseudo_abilities.no_stance",
}
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] #[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub enum AbilityInitEvent { pub enum AbilityInitEvent {
EnterStance(Stance), EnterStance(Stance),

View File

@ -143,6 +143,7 @@ pub enum ControlEvent {
InventoryEvent(InventoryEvent), InventoryEvent(InventoryEvent),
GroupManip(GroupManip), GroupManip(GroupManip),
RemoveBuff(BuffKind), RemoveBuff(BuffKind),
LeaveStance,
Respawn, Respawn,
Utterance(UtteranceKind), Utterance(UtteranceKind),
ChangeAbility { ChangeAbility {

View File

@ -1,5 +1,6 @@
use common::{ use common::{
comp::{ comp::{
ability::Stance,
agent::{Sound, SoundKind}, agent::{Sound, SoundKind},
Body, BuffChange, ControlEvent, Controller, Pos, Body, BuffChange, ControlEvent, Controller, Pos,
}, },
@ -115,6 +116,12 @@ impl<'a> System<'a> for Sys {
new_ability, new_ability,
}); });
}, },
ControlEvent::LeaveStance => {
server_emitter.emit(ServerEvent::ChangeStance {
entity,
stance: Stance::None,
});
},
} }
} }
} }

View File

@ -94,6 +94,7 @@ pub struct State {
pub enum Event { pub enum Event {
RemoveBuff(BuffKind), RemoveBuff(BuffKind),
LeaveStance,
} }
const MULTIPLICITY_COLOR: Color = TEXT_COLOR; const MULTIPLICITY_COLOR: Color = TEXT_COLOR;
@ -283,7 +284,7 @@ impl<'a> Widget for BuffsBar<'a> {
{ {
match buff.kind { match buff.kind {
BuffIconKind::Buff { kind, .. } => event.push(Event::RemoveBuff(kind)), BuffIconKind::Buff { kind, .. } => event.push(Event::RemoveBuff(kind)),
BuffIconKind::Ability { .. } => {}, BuffIconKind::Stance(_) => event.push(Event::LeaveStance),
} }
}; };
}); });
@ -471,7 +472,7 @@ impl<'a> Widget for BuffsBar<'a> {
{ {
match buff.kind { match buff.kind {
BuffIconKind::Buff { kind, .. } => event.push(Event::RemoveBuff(kind)), BuffIconKind::Buff { kind, .. } => event.push(Event::RemoveBuff(kind)),
BuffIconKind::Ability { .. } => {}, BuffIconKind::Stance(_) => event.push(Event::LeaveStance),
} }
} }
Text::new(&remaining_time) Text::new(&remaining_time)

View File

@ -85,7 +85,7 @@ use common::{
combat, combat,
comp::{ comp::{
self, self,
ability::AuxiliaryAbility, ability::{AuxiliaryAbility, Stance},
fluid_dynamics, fluid_dynamics,
inventory::{slot::InvSlotId, trade_pricing::TradePricing, CollectFailedReason}, inventory::{slot::InvSlotId, trade_pricing::TradePricing, CollectFailedReason},
item::{ item::{
@ -460,29 +460,27 @@ impl<W: Positionable> Position for W {
} }
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
pub enum BuffIconKind<'a> { pub enum BuffIconKind {
Buff { Buff {
kind: BuffKind, kind: BuffKind,
data: BuffData, data: BuffData,
multiplicity: usize, multiplicity: usize,
}, },
Ability { Stance(Stance),
ability_id: &'a str,
},
} }
impl<'a> BuffIconKind<'a> { impl BuffIconKind {
pub fn image(&self, imgs: &Imgs) -> conrod_core::image::Id { pub fn image(&self, imgs: &Imgs) -> conrod_core::image::Id {
match self { match self {
Self::Buff { kind, .. } => get_buff_image(*kind, imgs), Self::Buff { kind, .. } => get_buff_image(*kind, imgs),
Self::Ability { ability_id, .. } => util::ability_image(imgs, ability_id), Self::Stance(stance) => util::ability_image(imgs, stance.pseudo_ability_id()),
} }
} }
pub fn max_duration(&self) -> Option<Secs> { pub fn max_duration(&self) -> Option<Secs> {
match self { match self {
Self::Buff { data, .. } => data.duration, Self::Buff { data, .. } => data.duration,
Self::Ability { .. } => None, Self::Stance(_) => None,
} }
} }
@ -499,14 +497,14 @@ impl<'a> BuffIconKind<'a> {
get_buff_title(*kind, localized_strings), get_buff_title(*kind, localized_strings),
get_buff_desc(*kind, *data, localized_strings), get_buff_desc(*kind, *data, localized_strings),
), ),
Self::Ability { ability_id } => { Self::Stance(stance) => {
util::ability_description(ability_id, localized_strings) util::ability_description(stance.pseudo_ability_id(), localized_strings)
}, },
} }
} }
} }
impl<'a> PartialOrd for BuffIconKind<'a> { impl PartialOrd for BuffIconKind {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> { fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
match (self, other) { match (self, other) {
( (
@ -515,19 +513,16 @@ impl<'a> PartialOrd for BuffIconKind<'a> {
kind: other_kind, .. kind: other_kind, ..
}, },
) => Some(kind.cmp(other_kind)), ) => Some(kind.cmp(other_kind)),
(BuffIconKind::Buff { .. }, BuffIconKind::Ability { .. }) => Some(Ordering::Greater), (BuffIconKind::Buff { .. }, BuffIconKind::Stance(_)) => Some(Ordering::Greater),
(BuffIconKind::Ability { .. }, BuffIconKind::Buff { .. }) => Some(Ordering::Less), (BuffIconKind::Stance(_), BuffIconKind::Buff { .. }) => Some(Ordering::Less),
( (BuffIconKind::Stance(stance), BuffIconKind::Stance(stance_other)) => {
BuffIconKind::Ability { ability_id }, Some(stance.cmp(stance_other))
BuffIconKind::Ability { },
ability_id: other_id,
},
) => Some(ability_id.cmp(other_id)),
} }
} }
} }
impl<'a> Ord for BuffIconKind<'a> { impl Ord for BuffIconKind {
fn cmp(&self, other: &Self) -> Ordering { fn cmp(&self, other: &Self) -> Ordering {
// We know this is safe since we can look at the partialord implementation and // We know this is safe since we can look at the partialord implementation and
// see that every variant is wrapped in Some // see that every variant is wrapped in Some
@ -535,7 +530,7 @@ impl<'a> Ord for BuffIconKind<'a> {
} }
} }
impl<'a> PartialEq for BuffIconKind<'a> { impl PartialEq for BuffIconKind {
fn eq(&self, other: &Self) -> bool { fn eq(&self, other: &Self) -> bool {
match (self, other) { match (self, other) {
( (
@ -544,31 +539,28 @@ impl<'a> PartialEq for BuffIconKind<'a> {
kind: other_kind, .. kind: other_kind, ..
}, },
) => kind == other_kind, ) => kind == other_kind,
( (BuffIconKind::Stance(stance), BuffIconKind::Stance(stance_other)) => {
BuffIconKind::Ability { ability_id }, stance == stance_other
BuffIconKind::Ability { },
ability_id: other_id,
},
) => ability_id == other_id,
_ => false, _ => false,
} }
} }
} }
impl<'a> Eq for BuffIconKind<'a> {} impl Eq for BuffIconKind {}
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
pub struct BuffIcon<'a> { pub struct BuffIcon {
kind: BuffIconKind<'a>, kind: BuffIconKind,
is_buff: bool, is_buff: bool,
end_time: Option<f64>, end_time: Option<f64>,
} }
impl<'a> BuffIcon<'a> { impl BuffIcon {
pub fn multiplicity(&self) -> usize { pub fn multiplicity(&self) -> usize {
match self.kind { match self.kind {
BuffIconKind::Buff { multiplicity, .. } => multiplicity, BuffIconKind::Buff { multiplicity, .. } => multiplicity,
BuffIconKind::Ability { .. } => 1, BuffIconKind::Stance(_) => 1,
} }
} }
@ -589,25 +581,13 @@ impl<'a> BuffIcon<'a> {
} }
fn from_stance(stance: &comp::Stance) -> Option<Self> { fn from_stance(stance: &comp::Stance) -> Option<Self> {
use comp::ability::{Stance, SwordStance}; let stance = if let Stance::None = stance {
let id = match stance { return None;
Stance::Sword(SwordStance::Heavy) => "veloren.core.pseudo_abilities.sword.heavy_stance", } else {
Stance::Sword(SwordStance::Agile) => "veloren.core.pseudo_abilities.sword.agile_stance", stance
Stance::Sword(SwordStance::Defensive) => {
"veloren.core.pseudo_abilities.sword.defensive_stance"
},
Stance::Sword(SwordStance::Crippling) => {
"veloren.core.pseudo_abilities.sword.crippling_stance"
},
Stance::Sword(SwordStance::Cleaving) => {
"veloren.core.pseudo_abilities.sword.cleaving_stance"
},
Stance::None => {
return None;
},
}; };
Some(BuffIcon { Some(BuffIcon {
kind: BuffIconKind::Ability { ability_id: id }, kind: BuffIconKind::Stance(*stance),
is_buff: true, is_buff: true,
end_time: None, end_time: None,
}) })
@ -745,6 +725,7 @@ pub enum Event {
LeaveGroup, LeaveGroup,
AssignLeader(Uid), AssignLeader(Uid),
RemoveBuff(BuffKind), RemoveBuff(BuffKind),
LeaveStance,
UnlockSkill(Skill), UnlockSkill(Skill),
SelectExpBar(Option<SkillGroupKind>), SelectExpBar(Option<SkillGroupKind>),
@ -3170,6 +3151,7 @@ impl Hud {
{ {
match event { match event {
buffs::Event::RemoveBuff(buff_id) => events.push(Event::RemoveBuff(buff_id)), buffs::Event::RemoveBuff(buff_id) => events.push(Event::RemoveBuff(buff_id)),
buffs::Event::LeaveStance => events.push(Event::LeaveStance),
} }
} }
} }

View File

@ -1446,6 +1446,7 @@ impl PlayState for SessionState {
HudEvent::RemoveBuff(buff_id) => { HudEvent::RemoveBuff(buff_id) => {
self.client.borrow_mut().remove_buff(buff_id); self.client.borrow_mut().remove_buff(buff_id);
}, },
HudEvent::LeaveStance => self.client.borrow_mut().leave_stance(),
HudEvent::UnlockSkill(skill) => { HudEvent::UnlockSkill(skill) => {
self.client.borrow_mut().unlock_skill(skill); self.client.borrow_mut().unlock_skill(skill);
}, },