Instance numbers are now based on the AttackDamage struct

This commit is contained in:
socksonme 2022-01-27 19:27:21 +02:00 committed by Socksonme
parent ac5bf53c42
commit c0e78d869e
12 changed files with 52 additions and 51 deletions

View File

@ -212,7 +212,8 @@ impl Attack {
let is_crit = thread_rng().gen::<f32>() < self.crit_chance;
let mut is_applied = false;
let mut accumulated_damage = 0.0;
let instance = rand::random();
// TODO: Issue with shotgun ability
// TODO: Add instance number to AttackDamage?
for damage in self
.damages
.iter()
@ -236,7 +237,7 @@ impl Attack {
self.crit_multiplier,
strength_modifier,
time,
instance,
damage.instance,
);
let applied_damage = -change.amount;
accumulated_damage += applied_damage;
@ -261,7 +262,7 @@ impl Attack {
time,
crit: Some(is_crit),
crit_mult: self.crit_multiplier,
instance,
instance: damage.instance,
};
emit(ServerEvent::HealthChange {
entity: target.entity,
@ -635,15 +636,17 @@ pub struct AttackDamage {
damage: Damage,
target: Option<GroupTarget>,
effects: Vec<CombatEffect>,
instance: u64,
}
#[cfg(not(target_arch = "wasm32"))]
impl AttackDamage {
pub fn new(damage: Damage, target: Option<GroupTarget>) -> Self {
pub fn new(damage: Damage, target: Option<GroupTarget>, instance: u64) -> Self {
Self {
damage,
target,
effects: Vec::new(),
instance,
}
}

View File

@ -80,6 +80,7 @@ impl MeleeConstructor {
value: damage,
},
Some(GroupTarget::OutOfGroup),
rand::random(),
)
.with_effect(buff);
@ -128,6 +129,7 @@ impl MeleeConstructor {
value: damage,
},
Some(GroupTarget::OutOfGroup),
rand::random(),
)
.with_effect(buff);
@ -170,6 +172,7 @@ impl MeleeConstructor {
value: damage,
},
Some(GroupTarget::OutOfGroup),
rand::random(),
);
if let Some(damage_effect) = self.damage_effect {
@ -210,6 +213,7 @@ impl MeleeConstructor {
value: damage,
},
None,
rand::random(),
)
.with_effect(lifesteal);

View File

@ -98,6 +98,7 @@ impl ProjectileConstructor {
crit_chance: f32,
crit_mult: f32,
buff_strength: f32,
instance: u64,
) -> Projectile {
use ProjectileConstructor::*;
match self {
@ -129,6 +130,7 @@ impl ProjectileConstructor {
value: damage,
},
Some(GroupTarget::OutOfGroup),
instance,
)
.with_effect(buff);
let attack = Attack::default()
@ -169,6 +171,7 @@ impl ProjectileConstructor {
value: damage,
},
Some(GroupTarget::OutOfGroup),
rand::random(),
)
.with_effect(buff);
let attack = Attack::default()
@ -207,6 +210,7 @@ impl ProjectileConstructor {
value: damage,
},
Some(GroupTarget::OutOfGroup),
rand::random(),
);
let attack = Attack::default()
.with_damage(damage)
@ -286,6 +290,7 @@ impl ProjectileConstructor {
value: damage,
},
Some(GroupTarget::OutOfGroup),
rand::random(),
);
let attack = Attack::default()
.with_damage(damage)
@ -337,6 +342,7 @@ impl ProjectileConstructor {
value: damage,
},
Some(GroupTarget::OutOfGroup),
rand::random(),
);
let attack = Attack::default()
.with_damage(damage)
@ -373,6 +379,7 @@ impl ProjectileConstructor {
value: damage,
},
Some(GroupTarget::OutOfGroup),
rand::random(),
);
let attack = Attack::default()
.with_damage(damage)
@ -424,6 +431,7 @@ impl ProjectileConstructor {
value: damage,
},
Some(GroupTarget::OutOfGroup),
rand::random(),
);
let attack = Attack::default()
.with_damage(damage)

View File

@ -116,6 +116,7 @@ impl CharacterBehavior for Data {
value: self.static_data.damage,
},
Some(GroupTarget::OutOfGroup),
rand::random(),
);
if let Some(effect) = self.static_data.damage_effect {
damage = damage.with_effect(effect);

View File

@ -84,6 +84,7 @@ impl CharacterBehavior for Data {
crit_chance,
crit_mult,
buff_strength,
rand::random(),
);
// Shoots all projectiles simultaneously
for i in 0..self.static_data.num_projectiles {

View File

@ -119,6 +119,7 @@ impl CharacterBehavior for Data {
crit_chance,
crit_mult,
buff_strength,
rand::random(),
);
output_events.emit_server(ServerEvent::Shoot {
entity: data.entity,

View File

@ -264,6 +264,7 @@ impl CharacterBehavior for Data {
value: damage as f32,
},
Some(GroupTarget::OutOfGroup),
rand::random(),
);
if let Some(effect) = self.static_data.stage_data[stage_index].damage_effect {
damage = damage.with_effect(effect);

View File

@ -100,6 +100,7 @@ impl CharacterBehavior for Data {
crit_chance,
crit_mult,
buff_strength,
rand::random(),
);
output_events.emit_server(ServerEvent::Shoot {
entity: data.entity,

View File

@ -96,6 +96,7 @@ impl CharacterBehavior for Data {
value: self.static_data.damage as f32,
},
Some(GroupTarget::OutOfGroup),
rand::random(),
);
if let Some(effect) = self.static_data.damage_effect {
damage = damage.with_effect(effect);

View File

@ -115,7 +115,7 @@ fn dispatch_action_spawn_projectile(
pos: Pos(Vec3::zero()),
dir: Dir::forward(),
body: Body::Object(object::Body::Arrow),
projectile: constr.create_projectile(None, 0.0, 1.0, 1.0),
projectile: constr.create_projectile(None, 0.0, 1.0, 1.0, rand::random()),
light: None,
speed: 5.0,
object: None,

View File

@ -7,6 +7,7 @@ use common_ecs::{Job, Origin, Phase, System};
use specs::{Entities, Join, Read, ReadStorage, WriteStorage};
// How long floaters last (in seconds)
// Remove the accumulate times later
pub const HP_SHOWTIME: f32 = 3.0;
pub const CRIT_SHOWTIME: f32 = 0.7;
pub const MY_HP_SHOWTIME: f32 = 2.5;

View File

@ -58,6 +58,7 @@ use crate::{
ecs::{
comp as vcomp,
comp::{HpFloater, HpFloaterList},
sys::floater,
},
game_input::GameInput,
hud::{img_ids::ImgsRot, prompt_dialog::DialogOutcomeEvent},
@ -2416,15 +2417,7 @@ impl Hud {
+ (max_hp_frac
* 10.0
* if crit {
// FIXME: later
1.25 * floater.info.crit_mult
// if floater.timer <
// crate::ecs::sys::floater::
// CRIT_SHOWTIME {
// 15.0 * (floater.timer + 0.1)
// } else {
// 1.0
// }
} else {
1.0
}) as u32
@ -2459,7 +2452,7 @@ impl Hud {
let x = if !crit {
0.0
} else {
(floater.rand as f64 - 0.5) * 0.1 * ui_widgets.win_w
(floater.rand as f64 - 0.5) * 0.075 * ui_widgets.win_w
+ (0.03
* ui_widgets.win_w
* (floater.rand as f64 - 0.5).signum())
@ -2467,16 +2460,8 @@ impl Hud {
// Timer sets text transparency
let fade = if crit {
// FIXME: later
// TODO: A setting for popping?
((crate::ecs::sys::floater::CRIT_SHOWTIME - floater.timer) * 0.75)
+ 0.5
// if floater.timer <
// crate::ecs::sys::floater::CRIT_SHOWTIME {
// 1.0
// } else {
// 0.0
// }
} else {
((crate::ecs::sys::floater::HP_SHOWTIME - floater.timer) * 0.25)
+ 0.2
@ -4676,59 +4661,53 @@ impl Hud {
},
None => hit_me,
} {
let mut merged = false;
// Or maybe something like this
// Group up damage from the same tick, with the same instance number and
// has the same crit value
for floater in floater_list.floaters.iter_mut().rev() {
if floater.timer > 0.0 {
break;
}
if floater.info.instance == info.instance {
dbg!(floater.info.instance);
dbg!(floater.timer);
if floater.info.instance == info.instance
&& floater.info.crit.unwrap_or(false)
== info.crit.unwrap_or(false)
{
floater.info.amount += info.amount;
floater.info.crit_mult = info.crit_mult;
floater.info.crit = Some(
floater.info.crit.unwrap_or(false)
|| info.crit.unwrap_or(false)
|| info.crit.unwrap_or(false),
);
merged = true;
}
}
if merged {
return;
}
}
// To separate healing and damage floaters
// To separate healing and damage floaters alongside the crit and
// non-crit ones
let last_floater = if info.amount < Health::HEALTH_EPSILON {
floater_list
.floaters
.iter_mut()
.rev()
.find(|f| f.info.amount < Health::HEALTH_EPSILON)
floater_list.floaters.iter_mut().rev().find(|f| {
f.info.amount < Health::HEALTH_EPSILON
&& info.crit.map_or(f.info.crit.unwrap_or(false), |_| {
!f.info.crit.unwrap_or(false)
})
})
} else {
floater_list
.floaters
.iter_mut()
.rev()
.find(|f| f.info.amount > Health::HEALTH_EPSILON)
floater_list.floaters.iter_mut().rev().find(|f| {
f.info.amount > Health::HEALTH_EPSILON
&& info.crit.map_or(f.info.crit.unwrap_or(false), |_| {
!f.info.crit.unwrap_or(false)
})
})
};
match last_floater {
Some(f)
// TODO: Change later so it's based on options
if /*(info.crit.unwrap_or(false)
|| (f.timer < floater::HP_ACCUMULATETIME
&& !f.info.crit.unwrap_or(false)
&& !info.crit.unwrap_or(false)) */ false =>
if (f.timer < floater::HP_ACCUMULATETIME && !f.info.crit.unwrap_or(false)) =>
{
dbg!(f.info.instance);
dbg!(f.timer);
//TODO: Add "jumping" animation on floater when it changes its
// value
f.info.amount += info.amount;
f.info.crit_mult = info.crit_mult;
// TODO: Temporary ofc.
f.info.crit = Some(f.info.crit.unwrap_or(false) || info.crit.unwrap_or(false));
},
_ => {