Initial SCT implementation to display blocks.

This commit is contained in:
Sam 2021-04-24 00:11:41 -04:00
parent d2d8d43410
commit 372eff2a02
10 changed files with 125 additions and 26 deletions

View File

@ -61,6 +61,7 @@ pub struct AttackerInfo<'a> {
#[cfg(not(target_arch = "wasm32"))]
pub struct TargetInfo<'a> {
pub entity: EcsEntity,
pub uid: Uid,
pub inventory: Option<&'a Inventory>,
pub stats: Option<&'a Stats>,
pub health: Option<&'a Health>,
@ -135,6 +136,7 @@ impl Attack {
emit_outcome(Outcome::Block {
parry,
pos: target.pos,
uid: target.uid,
});
if parry {
1.0

View File

@ -62,6 +62,7 @@ pub enum Outcome {
Block {
pos: Vec3<f32>,
parry: bool,
uid: Uid,
},
}

View File

@ -185,6 +185,7 @@ impl<'a> System<'a> for Sys {
let target_info = TargetInfo {
entity: target,
uid: *uid_b,
inventory: read_data.inventories.get(target),
stats: read_data.stats.get(target),
health: read_data.healths.get(target),

View File

@ -87,11 +87,12 @@ impl<'a> System<'a> for Sys {
}
// Go through all other entities
for (target, pos_b, health_b, body_b) in (
for (target, pos_b, health_b, body_b, uid_b) in (
&read_data.entities,
&read_data.positions,
&read_data.healths,
&read_data.bodies,
&read_data.uids,
)
.join()
{
@ -143,6 +144,7 @@ impl<'a> System<'a> for Sys {
let target_info = TargetInfo {
entity: target,
uid: *uid_b,
inventory: read_data.inventories.get(target),
stats: read_data.stats.get(target),
health: read_data.healths.get(target),

View File

@ -128,6 +128,7 @@ impl<'a> System<'a> for Sys {
let target_info = TargetInfo {
entity: target,
uid: other,
inventory: read_data.inventories.get(target),
stats: read_data.stats.get(target),
health: read_data.healths.get(target),

View File

@ -190,6 +190,7 @@ impl<'a> System<'a> for Sys {
let target_info = TargetInfo {
entity: target,
uid: *uid_b,
inventory: read_data.inventories.get(target),
stats: read_data.stats.get(target),
health: read_data.healths.get(target),

View File

@ -682,6 +682,7 @@ pub fn handle_explosion(server: &Server, pos: Vec3<f32>, explosion: Explosion, o
stats_b_maybe,
ori_b_maybe,
char_state_b_maybe,
uid_b,
),
) in (
&ecs.entities(),
@ -693,6 +694,7 @@ pub fn handle_explosion(server: &Server, pos: Vec3<f32>, explosion: Explosion, o
ecs.read_storage::<comp::Stats>().maybe(),
ecs.read_storage::<comp::Ori>().maybe(),
ecs.read_storage::<comp::CharacterState>().maybe(),
&ecs.read_storage::<Uid>(),
),
)
.join()
@ -736,6 +738,7 @@ pub fn handle_explosion(server: &Server, pos: Vec3<f32>, explosion: Explosion, o
let target_info = combat::TargetInfo {
entity: entity_b,
uid: *uid_b,
inventory: inventory_b_maybe,
stats: stats_b_maybe,
health: Some(health_b),

View File

@ -416,7 +416,7 @@ impl SfxMgr {
][rand::thread_rng().gen_range(1..4)];
audio.play_sfx(file_ref, *pos, None);
},
Outcome::Block { pos, parry } => {
Outcome::Block { pos, parry, .. } => {
// TODO: Get audio for blocking and parrying
let file_ref_block = vec![
"voxygen.audio.sfx.character.block_1",

View File

@ -329,6 +329,11 @@ pub struct ComboFloater {
pub timer: f64,
}
pub struct BlockFloater {
pub owner: Uid,
pub timer: f32,
}
pub struct DebugInfo {
pub tps: f64,
pub frame_time: Duration,
@ -739,6 +744,13 @@ impl PromptDialogSettings {
}
}
pub struct Floaters {
pub exp_floaters: Vec<ExpFloater>,
pub skill_point_displays: Vec<SkillPointGain>,
pub combo_floaters: VecDeque<ComboFloater>,
pub block_floaters: Vec<BlockFloater>,
}
pub struct Hud {
ui: Ui,
ids: Ids,
@ -765,9 +777,7 @@ pub struct Hud {
hotbar: hotbar::State,
events: Vec<Event>,
crosshair_opacity: f32,
exp_floaters: Vec<ExpFloater>,
skill_point_displays: Vec<SkillPointGain>,
combo_floaters: VecDeque<ComboFloater>,
floaters: Floaters,
}
impl Hud {
@ -878,9 +888,12 @@ impl Hud {
hotbar: hotbar_state,
events: Vec::new(),
crosshair_opacity: 0.0,
exp_floaters: Vec::new(),
skill_point_displays: Vec::new(),
combo_floaters: VecDeque::new(),
floaters: Floaters {
exp_floaters: Vec::new(),
skill_point_displays: Vec::new(),
combo_floaters: VecDeque::new(),
block_floaters: Vec::new(),
},
}
}
@ -1174,9 +1187,18 @@ impl Hud {
}
}
// EXP Numbers
self.exp_floaters.retain(|f| f.timer > 0_f32);
self.floaters
.exp_floaters
.iter_mut()
.for_each(|f| f.timer -= dt.as_secs_f32());
self.floaters.exp_floaters.retain(|f| f.timer > 0_f32);
if let Some(uid) = uids.get(me) {
for floater in self.exp_floaters.iter_mut().filter(|f| f.owner == *uid) {
for floater in self
.floaters
.exp_floaters
.iter_mut()
.filter(|f| f.owner == *uid)
{
let number_speed = 50.0; // Number Speed for Single EXP
let player_sct_bg_id = player_sct_bg_id_walker.next(
&mut self.ids.player_sct_bgs,
@ -1221,13 +1243,19 @@ impl Hud {
)
.set(player_sct_id, ui_widgets);
}
floater.timer -= dt.as_secs_f32();
}
}
// Skill points
self.skill_point_displays.retain(|d| d.timer > 0_f32);
self.floaters
.skill_point_displays
.iter_mut()
.for_each(|f| f.timer -= dt.as_secs_f32());
self.floaters
.skill_point_displays
.retain(|d| d.timer > 0_f32);
if let Some(uid) = uids.get(me) {
if let Some(display) = self
.floaters
.skill_point_displays
.iter_mut()
.find(|d| d.owner == *uid)
@ -1311,8 +1339,58 @@ impl Hud {
.left_from(self.ids.player_rank_up_txt_1_bg, 5.0)
.color(Some(Color::Rgba(1.0, 1.0, 1.0, fade)))
.set(self.ids.player_rank_up_icon, ui_widgets);
}
}
// Scrolling Combat Text for Parrying an attack
self.floaters
.block_floaters
.iter_mut()
.for_each(|f| f.timer -= dt.as_secs_f32());
self.floaters.block_floaters.retain(|f| f.timer > 0_f32);
if let Some(uid) = uids.get(me) {
use inline_tweak::tweak;
for floater in self
.floaters
.block_floaters
.iter_mut()
.filter(|f| f.owner == *uid)
{
let number_speed = 50.0;
let player_sct_bg_id = player_sct_bg_id_walker.next(
&mut self.ids.player_sct_bgs,
&mut ui_widgets.widget_id_generator(),
);
let player_sct_id = player_sct_id_walker.next(
&mut self.ids.player_scts,
&mut ui_widgets.widget_id_generator(),
);
let font_size = 30;
let y = floater.timer as f64 * number_speed; // Timer sets the widget offset
// text transparency
let fade = if floater.timer < 0.25 {
floater.timer as f32 / 0.25
} else {
1.0
};
display.timer -= dt.as_secs_f32();
Text::new("Blocked")
.font_size(font_size)
.font_id(self.fonts.cyri.conrod_id)
.color(Color::Rgba(0.0, 0.0, 0.0, fade))
.x_y(
ui_widgets.win_w * (tweak!(0.0)),
ui_widgets.win_h * (tweak!(-0.3)) + y - tweak!(3.0),
)
.set(player_sct_bg_id, ui_widgets);
Text::new("Blocked")
.font_size(font_size)
.font_id(self.fonts.cyri.conrod_id)
.color(Color::Rgba(tweak!(0.9), tweak!(0.85), tweak!(0.2), fade))
.x_y(
ui_widgets.win_w * (tweak!(0.0)),
ui_widgets.win_h * (tweak!(-0.3)) + y,
)
.set(player_sct_id, ui_widgets);
}
}
}
@ -2273,12 +2351,14 @@ impl Hud {
let ability_map = ecs.fetch::<comp::item::tool::AbilityMap>();
let bodies = ecs.read_storage::<comp::Body>();
// Combo floater stuffs
for combo_floater in self.combo_floaters.iter_mut() {
combo_floater.timer -= dt.as_secs_f64();
}
self.combo_floaters.retain(|f| f.timer > 0_f64);
self.floaters
.combo_floaters
.iter_mut()
.for_each(|f| f.timer -= dt.as_secs_f64());
self.floaters.combo_floaters.retain(|f| f.timer > 0_f64);
let combo = if let Some(uid) = ecs.read_storage::<Uid>().get(entity) {
self.combo_floaters
self.floaters
.combo_floaters
.iter()
.find(|c| c.owner == *uid)
.copied()
@ -3425,7 +3505,7 @@ impl Hud {
pub fn handle_outcome(&mut self, outcome: &Outcome) {
match outcome {
Outcome::ExpChange { uid, exp } => self.exp_floaters.push(ExpFloater {
Outcome::ExpChange { uid, exp } => self.floaters.exp_floaters.push(ExpFloater {
owner: *uid,
exp_change: *exp,
timer: 4.0,
@ -3436,17 +3516,25 @@ impl Hud {
skill_tree,
total_points,
..
} => self.skill_point_displays.push(SkillPointGain {
} => self.floaters.skill_point_displays.push(SkillPointGain {
owner: *uid,
skill_tree: *skill_tree,
total_points: *total_points,
timer: 5.0,
}),
Outcome::ComboChange { uid, combo } => self.combo_floaters.push_front(ComboFloater {
owner: *uid,
combo: *combo,
timer: comp::combo::COMBO_DECAY_START,
}),
Outcome::ComboChange { uid, combo } => {
self.floaters.combo_floaters.push_front(ComboFloater {
owner: *uid,
combo: *combo,
timer: comp::combo::COMBO_DECAY_START,
})
},
Outcome::Block { uid, parry, .. } if *parry => {
self.floaters.block_floaters.push(BlockFloater {
owner: *uid,
timer: 1.0,
})
},
_ => {},
}
}

View File

@ -203,7 +203,7 @@ impl ParticleMgr {
});
}
},
Outcome::Block { pos, parry } => {
Outcome::Block { pos, parry, .. } => {
if *parry {
self.particles.resize_with(self.particles.len() + 10, || {
Particle::new(