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

View File

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

View File

@ -185,6 +185,7 @@ impl<'a> System<'a> for Sys {
let target_info = TargetInfo { let target_info = TargetInfo {
entity: target, entity: target,
uid: *uid_b,
inventory: read_data.inventories.get(target), inventory: read_data.inventories.get(target),
stats: read_data.stats.get(target), stats: read_data.stats.get(target),
health: read_data.healths.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 // 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.entities,
&read_data.positions, &read_data.positions,
&read_data.healths, &read_data.healths,
&read_data.bodies, &read_data.bodies,
&read_data.uids,
) )
.join() .join()
{ {
@ -143,6 +144,7 @@ impl<'a> System<'a> for Sys {
let target_info = TargetInfo { let target_info = TargetInfo {
entity: target, entity: target,
uid: *uid_b,
inventory: read_data.inventories.get(target), inventory: read_data.inventories.get(target),
stats: read_data.stats.get(target), stats: read_data.stats.get(target),
health: read_data.healths.get(target), health: read_data.healths.get(target),

View File

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

View File

@ -190,6 +190,7 @@ impl<'a> System<'a> for Sys {
let target_info = TargetInfo { let target_info = TargetInfo {
entity: target, entity: target,
uid: *uid_b,
inventory: read_data.inventories.get(target), inventory: read_data.inventories.get(target),
stats: read_data.stats.get(target), stats: read_data.stats.get(target),
health: read_data.healths.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, stats_b_maybe,
ori_b_maybe, ori_b_maybe,
char_state_b_maybe, char_state_b_maybe,
uid_b,
), ),
) in ( ) in (
&ecs.entities(), &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::Stats>().maybe(),
ecs.read_storage::<comp::Ori>().maybe(), ecs.read_storage::<comp::Ori>().maybe(),
ecs.read_storage::<comp::CharacterState>().maybe(), ecs.read_storage::<comp::CharacterState>().maybe(),
&ecs.read_storage::<Uid>(),
), ),
) )
.join() .join()
@ -736,6 +738,7 @@ pub fn handle_explosion(server: &Server, pos: Vec3<f32>, explosion: Explosion, o
let target_info = combat::TargetInfo { let target_info = combat::TargetInfo {
entity: entity_b, entity: entity_b,
uid: *uid_b,
inventory: inventory_b_maybe, inventory: inventory_b_maybe,
stats: stats_b_maybe, stats: stats_b_maybe,
health: Some(health_b), health: Some(health_b),

View File

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

View File

@ -329,6 +329,11 @@ pub struct ComboFloater {
pub timer: f64, pub timer: f64,
} }
pub struct BlockFloater {
pub owner: Uid,
pub timer: f32,
}
pub struct DebugInfo { pub struct DebugInfo {
pub tps: f64, pub tps: f64,
pub frame_time: Duration, 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 { pub struct Hud {
ui: Ui, ui: Ui,
ids: Ids, ids: Ids,
@ -765,9 +777,7 @@ pub struct Hud {
hotbar: hotbar::State, hotbar: hotbar::State,
events: Vec<Event>, events: Vec<Event>,
crosshair_opacity: f32, crosshair_opacity: f32,
exp_floaters: Vec<ExpFloater>, floaters: Floaters,
skill_point_displays: Vec<SkillPointGain>,
combo_floaters: VecDeque<ComboFloater>,
} }
impl Hud { impl Hud {
@ -878,9 +888,12 @@ impl Hud {
hotbar: hotbar_state, hotbar: hotbar_state,
events: Vec::new(), events: Vec::new(),
crosshair_opacity: 0.0, crosshair_opacity: 0.0,
floaters: Floaters {
exp_floaters: Vec::new(), exp_floaters: Vec::new(),
skill_point_displays: Vec::new(), skill_point_displays: Vec::new(),
combo_floaters: VecDeque::new(), combo_floaters: VecDeque::new(),
block_floaters: Vec::new(),
},
} }
} }
@ -1174,9 +1187,18 @@ impl Hud {
} }
} }
// EXP Numbers // 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) { 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 number_speed = 50.0; // Number Speed for Single EXP
let player_sct_bg_id = player_sct_bg_id_walker.next( let player_sct_bg_id = player_sct_bg_id_walker.next(
&mut self.ids.player_sct_bgs, &mut self.ids.player_sct_bgs,
@ -1221,13 +1243,19 @@ impl Hud {
) )
.set(player_sct_id, ui_widgets); .set(player_sct_id, ui_widgets);
} }
floater.timer -= dt.as_secs_f32();
} }
} }
// Skill points // 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(uid) = uids.get(me) {
if let Some(display) = self if let Some(display) = self
.floaters
.skill_point_displays .skill_point_displays
.iter_mut() .iter_mut()
.find(|d| d.owner == *uid) .find(|d| d.owner == *uid)
@ -1311,8 +1339,58 @@ impl Hud {
.left_from(self.ids.player_rank_up_txt_1_bg, 5.0) .left_from(self.ids.player_rank_up_txt_1_bg, 5.0)
.color(Some(Color::Rgba(1.0, 1.0, 1.0, fade))) .color(Some(Color::Rgba(1.0, 1.0, 1.0, fade)))
.set(self.ids.player_rank_up_icon, ui_widgets); .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 ability_map = ecs.fetch::<comp::item::tool::AbilityMap>();
let bodies = ecs.read_storage::<comp::Body>(); let bodies = ecs.read_storage::<comp::Body>();
// Combo floater stuffs // Combo floater stuffs
for combo_floater in self.combo_floaters.iter_mut() { self.floaters
combo_floater.timer -= dt.as_secs_f64(); .combo_floaters
} .iter_mut()
self.combo_floaters.retain(|f| f.timer > 0_f64); .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) { let combo = if let Some(uid) = ecs.read_storage::<Uid>().get(entity) {
self.combo_floaters self.floaters
.combo_floaters
.iter() .iter()
.find(|c| c.owner == *uid) .find(|c| c.owner == *uid)
.copied() .copied()
@ -3425,7 +3505,7 @@ impl Hud {
pub fn handle_outcome(&mut self, outcome: &Outcome) { pub fn handle_outcome(&mut self, outcome: &Outcome) {
match outcome { match outcome {
Outcome::ExpChange { uid, exp } => self.exp_floaters.push(ExpFloater { Outcome::ExpChange { uid, exp } => self.floaters.exp_floaters.push(ExpFloater {
owner: *uid, owner: *uid,
exp_change: *exp, exp_change: *exp,
timer: 4.0, timer: 4.0,
@ -3436,17 +3516,25 @@ impl Hud {
skill_tree, skill_tree,
total_points, total_points,
.. ..
} => self.skill_point_displays.push(SkillPointGain { } => self.floaters.skill_point_displays.push(SkillPointGain {
owner: *uid, owner: *uid,
skill_tree: *skill_tree, skill_tree: *skill_tree,
total_points: *total_points, total_points: *total_points,
timer: 5.0, timer: 5.0,
}), }),
Outcome::ComboChange { uid, combo } => self.combo_floaters.push_front(ComboFloater { Outcome::ComboChange { uid, combo } => {
self.floaters.combo_floaters.push_front(ComboFloater {
owner: *uid, owner: *uid,
combo: *combo, combo: *combo,
timer: comp::combo::COMBO_DECAY_START, 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 { if *parry {
self.particles.resize_with(self.particles.len() + 10, || { self.particles.resize_with(self.particles.len() + 10, || {
Particle::new( Particle::new(