mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Instance numbers are now based on the AttackDamage struct
This commit is contained in:
parent
ac5bf53c42
commit
c0e78d869e
@ -212,7 +212,8 @@ impl Attack {
|
|||||||
let is_crit = thread_rng().gen::<f32>() < self.crit_chance;
|
let is_crit = thread_rng().gen::<f32>() < self.crit_chance;
|
||||||
let mut is_applied = false;
|
let mut is_applied = false;
|
||||||
let mut accumulated_damage = 0.0;
|
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
|
for damage in self
|
||||||
.damages
|
.damages
|
||||||
.iter()
|
.iter()
|
||||||
@ -236,7 +237,7 @@ impl Attack {
|
|||||||
self.crit_multiplier,
|
self.crit_multiplier,
|
||||||
strength_modifier,
|
strength_modifier,
|
||||||
time,
|
time,
|
||||||
instance,
|
damage.instance,
|
||||||
);
|
);
|
||||||
let applied_damage = -change.amount;
|
let applied_damage = -change.amount;
|
||||||
accumulated_damage += applied_damage;
|
accumulated_damage += applied_damage;
|
||||||
@ -261,7 +262,7 @@ impl Attack {
|
|||||||
time,
|
time,
|
||||||
crit: Some(is_crit),
|
crit: Some(is_crit),
|
||||||
crit_mult: self.crit_multiplier,
|
crit_mult: self.crit_multiplier,
|
||||||
instance,
|
instance: damage.instance,
|
||||||
};
|
};
|
||||||
emit(ServerEvent::HealthChange {
|
emit(ServerEvent::HealthChange {
|
||||||
entity: target.entity,
|
entity: target.entity,
|
||||||
@ -635,15 +636,17 @@ pub struct AttackDamage {
|
|||||||
damage: Damage,
|
damage: Damage,
|
||||||
target: Option<GroupTarget>,
|
target: Option<GroupTarget>,
|
||||||
effects: Vec<CombatEffect>,
|
effects: Vec<CombatEffect>,
|
||||||
|
instance: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
impl AttackDamage {
|
impl AttackDamage {
|
||||||
pub fn new(damage: Damage, target: Option<GroupTarget>) -> Self {
|
pub fn new(damage: Damage, target: Option<GroupTarget>, instance: u64) -> Self {
|
||||||
Self {
|
Self {
|
||||||
damage,
|
damage,
|
||||||
target,
|
target,
|
||||||
effects: Vec::new(),
|
effects: Vec::new(),
|
||||||
|
instance,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,6 +80,7 @@ impl MeleeConstructor {
|
|||||||
value: damage,
|
value: damage,
|
||||||
},
|
},
|
||||||
Some(GroupTarget::OutOfGroup),
|
Some(GroupTarget::OutOfGroup),
|
||||||
|
rand::random(),
|
||||||
)
|
)
|
||||||
.with_effect(buff);
|
.with_effect(buff);
|
||||||
|
|
||||||
@ -128,6 +129,7 @@ impl MeleeConstructor {
|
|||||||
value: damage,
|
value: damage,
|
||||||
},
|
},
|
||||||
Some(GroupTarget::OutOfGroup),
|
Some(GroupTarget::OutOfGroup),
|
||||||
|
rand::random(),
|
||||||
)
|
)
|
||||||
.with_effect(buff);
|
.with_effect(buff);
|
||||||
|
|
||||||
@ -170,6 +172,7 @@ impl MeleeConstructor {
|
|||||||
value: damage,
|
value: damage,
|
||||||
},
|
},
|
||||||
Some(GroupTarget::OutOfGroup),
|
Some(GroupTarget::OutOfGroup),
|
||||||
|
rand::random(),
|
||||||
);
|
);
|
||||||
|
|
||||||
if let Some(damage_effect) = self.damage_effect {
|
if let Some(damage_effect) = self.damage_effect {
|
||||||
@ -210,6 +213,7 @@ impl MeleeConstructor {
|
|||||||
value: damage,
|
value: damage,
|
||||||
},
|
},
|
||||||
None,
|
None,
|
||||||
|
rand::random(),
|
||||||
)
|
)
|
||||||
.with_effect(lifesteal);
|
.with_effect(lifesteal);
|
||||||
|
|
||||||
|
@ -98,6 +98,7 @@ impl ProjectileConstructor {
|
|||||||
crit_chance: f32,
|
crit_chance: f32,
|
||||||
crit_mult: f32,
|
crit_mult: f32,
|
||||||
buff_strength: f32,
|
buff_strength: f32,
|
||||||
|
instance: u64,
|
||||||
) -> Projectile {
|
) -> Projectile {
|
||||||
use ProjectileConstructor::*;
|
use ProjectileConstructor::*;
|
||||||
match self {
|
match self {
|
||||||
@ -129,6 +130,7 @@ impl ProjectileConstructor {
|
|||||||
value: damage,
|
value: damage,
|
||||||
},
|
},
|
||||||
Some(GroupTarget::OutOfGroup),
|
Some(GroupTarget::OutOfGroup),
|
||||||
|
instance,
|
||||||
)
|
)
|
||||||
.with_effect(buff);
|
.with_effect(buff);
|
||||||
let attack = Attack::default()
|
let attack = Attack::default()
|
||||||
@ -169,6 +171,7 @@ impl ProjectileConstructor {
|
|||||||
value: damage,
|
value: damage,
|
||||||
},
|
},
|
||||||
Some(GroupTarget::OutOfGroup),
|
Some(GroupTarget::OutOfGroup),
|
||||||
|
rand::random(),
|
||||||
)
|
)
|
||||||
.with_effect(buff);
|
.with_effect(buff);
|
||||||
let attack = Attack::default()
|
let attack = Attack::default()
|
||||||
@ -207,6 +210,7 @@ impl ProjectileConstructor {
|
|||||||
value: damage,
|
value: damage,
|
||||||
},
|
},
|
||||||
Some(GroupTarget::OutOfGroup),
|
Some(GroupTarget::OutOfGroup),
|
||||||
|
rand::random(),
|
||||||
);
|
);
|
||||||
let attack = Attack::default()
|
let attack = Attack::default()
|
||||||
.with_damage(damage)
|
.with_damage(damage)
|
||||||
@ -286,6 +290,7 @@ impl ProjectileConstructor {
|
|||||||
value: damage,
|
value: damage,
|
||||||
},
|
},
|
||||||
Some(GroupTarget::OutOfGroup),
|
Some(GroupTarget::OutOfGroup),
|
||||||
|
rand::random(),
|
||||||
);
|
);
|
||||||
let attack = Attack::default()
|
let attack = Attack::default()
|
||||||
.with_damage(damage)
|
.with_damage(damage)
|
||||||
@ -337,6 +342,7 @@ impl ProjectileConstructor {
|
|||||||
value: damage,
|
value: damage,
|
||||||
},
|
},
|
||||||
Some(GroupTarget::OutOfGroup),
|
Some(GroupTarget::OutOfGroup),
|
||||||
|
rand::random(),
|
||||||
);
|
);
|
||||||
let attack = Attack::default()
|
let attack = Attack::default()
|
||||||
.with_damage(damage)
|
.with_damage(damage)
|
||||||
@ -373,6 +379,7 @@ impl ProjectileConstructor {
|
|||||||
value: damage,
|
value: damage,
|
||||||
},
|
},
|
||||||
Some(GroupTarget::OutOfGroup),
|
Some(GroupTarget::OutOfGroup),
|
||||||
|
rand::random(),
|
||||||
);
|
);
|
||||||
let attack = Attack::default()
|
let attack = Attack::default()
|
||||||
.with_damage(damage)
|
.with_damage(damage)
|
||||||
@ -424,6 +431,7 @@ impl ProjectileConstructor {
|
|||||||
value: damage,
|
value: damage,
|
||||||
},
|
},
|
||||||
Some(GroupTarget::OutOfGroup),
|
Some(GroupTarget::OutOfGroup),
|
||||||
|
rand::random(),
|
||||||
);
|
);
|
||||||
let attack = Attack::default()
|
let attack = Attack::default()
|
||||||
.with_damage(damage)
|
.with_damage(damage)
|
||||||
|
@ -116,6 +116,7 @@ impl CharacterBehavior for Data {
|
|||||||
value: self.static_data.damage,
|
value: self.static_data.damage,
|
||||||
},
|
},
|
||||||
Some(GroupTarget::OutOfGroup),
|
Some(GroupTarget::OutOfGroup),
|
||||||
|
rand::random(),
|
||||||
);
|
);
|
||||||
if let Some(effect) = self.static_data.damage_effect {
|
if let Some(effect) = self.static_data.damage_effect {
|
||||||
damage = damage.with_effect(effect);
|
damage = damage.with_effect(effect);
|
||||||
|
@ -84,6 +84,7 @@ impl CharacterBehavior for Data {
|
|||||||
crit_chance,
|
crit_chance,
|
||||||
crit_mult,
|
crit_mult,
|
||||||
buff_strength,
|
buff_strength,
|
||||||
|
rand::random(),
|
||||||
);
|
);
|
||||||
// Shoots all projectiles simultaneously
|
// Shoots all projectiles simultaneously
|
||||||
for i in 0..self.static_data.num_projectiles {
|
for i in 0..self.static_data.num_projectiles {
|
||||||
|
@ -119,6 +119,7 @@ impl CharacterBehavior for Data {
|
|||||||
crit_chance,
|
crit_chance,
|
||||||
crit_mult,
|
crit_mult,
|
||||||
buff_strength,
|
buff_strength,
|
||||||
|
rand::random(),
|
||||||
);
|
);
|
||||||
output_events.emit_server(ServerEvent::Shoot {
|
output_events.emit_server(ServerEvent::Shoot {
|
||||||
entity: data.entity,
|
entity: data.entity,
|
||||||
|
@ -264,6 +264,7 @@ impl CharacterBehavior for Data {
|
|||||||
value: damage as f32,
|
value: damage as f32,
|
||||||
},
|
},
|
||||||
Some(GroupTarget::OutOfGroup),
|
Some(GroupTarget::OutOfGroup),
|
||||||
|
rand::random(),
|
||||||
);
|
);
|
||||||
if let Some(effect) = self.static_data.stage_data[stage_index].damage_effect {
|
if let Some(effect) = self.static_data.stage_data[stage_index].damage_effect {
|
||||||
damage = damage.with_effect(effect);
|
damage = damage.with_effect(effect);
|
||||||
|
@ -100,6 +100,7 @@ impl CharacterBehavior for Data {
|
|||||||
crit_chance,
|
crit_chance,
|
||||||
crit_mult,
|
crit_mult,
|
||||||
buff_strength,
|
buff_strength,
|
||||||
|
rand::random(),
|
||||||
);
|
);
|
||||||
output_events.emit_server(ServerEvent::Shoot {
|
output_events.emit_server(ServerEvent::Shoot {
|
||||||
entity: data.entity,
|
entity: data.entity,
|
||||||
|
@ -96,6 +96,7 @@ impl CharacterBehavior for Data {
|
|||||||
value: self.static_data.damage as f32,
|
value: self.static_data.damage as f32,
|
||||||
},
|
},
|
||||||
Some(GroupTarget::OutOfGroup),
|
Some(GroupTarget::OutOfGroup),
|
||||||
|
rand::random(),
|
||||||
);
|
);
|
||||||
if let Some(effect) = self.static_data.damage_effect {
|
if let Some(effect) = self.static_data.damage_effect {
|
||||||
damage = damage.with_effect(effect);
|
damage = damage.with_effect(effect);
|
||||||
|
@ -115,7 +115,7 @@ fn dispatch_action_spawn_projectile(
|
|||||||
pos: Pos(Vec3::zero()),
|
pos: Pos(Vec3::zero()),
|
||||||
dir: Dir::forward(),
|
dir: Dir::forward(),
|
||||||
body: Body::Object(object::Body::Arrow),
|
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,
|
light: None,
|
||||||
speed: 5.0,
|
speed: 5.0,
|
||||||
object: None,
|
object: None,
|
||||||
|
@ -7,6 +7,7 @@ use common_ecs::{Job, Origin, Phase, System};
|
|||||||
use specs::{Entities, Join, Read, ReadStorage, WriteStorage};
|
use specs::{Entities, Join, Read, ReadStorage, WriteStorage};
|
||||||
|
|
||||||
// How long floaters last (in seconds)
|
// How long floaters last (in seconds)
|
||||||
|
// Remove the accumulate times later
|
||||||
pub const HP_SHOWTIME: f32 = 3.0;
|
pub const HP_SHOWTIME: f32 = 3.0;
|
||||||
pub const CRIT_SHOWTIME: f32 = 0.7;
|
pub const CRIT_SHOWTIME: f32 = 0.7;
|
||||||
pub const MY_HP_SHOWTIME: f32 = 2.5;
|
pub const MY_HP_SHOWTIME: f32 = 2.5;
|
||||||
|
@ -58,6 +58,7 @@ use crate::{
|
|||||||
ecs::{
|
ecs::{
|
||||||
comp as vcomp,
|
comp as vcomp,
|
||||||
comp::{HpFloater, HpFloaterList},
|
comp::{HpFloater, HpFloaterList},
|
||||||
|
sys::floater,
|
||||||
},
|
},
|
||||||
game_input::GameInput,
|
game_input::GameInput,
|
||||||
hud::{img_ids::ImgsRot, prompt_dialog::DialogOutcomeEvent},
|
hud::{img_ids::ImgsRot, prompt_dialog::DialogOutcomeEvent},
|
||||||
@ -2416,15 +2417,7 @@ impl Hud {
|
|||||||
+ (max_hp_frac
|
+ (max_hp_frac
|
||||||
* 10.0
|
* 10.0
|
||||||
* if crit {
|
* if crit {
|
||||||
// FIXME: later
|
|
||||||
1.25 * floater.info.crit_mult
|
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 {
|
} else {
|
||||||
1.0
|
1.0
|
||||||
}) as u32
|
}) as u32
|
||||||
@ -2459,7 +2452,7 @@ impl Hud {
|
|||||||
let x = if !crit {
|
let x = if !crit {
|
||||||
0.0
|
0.0
|
||||||
} else {
|
} 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
|
+ (0.03
|
||||||
* ui_widgets.win_w
|
* ui_widgets.win_w
|
||||||
* (floater.rand as f64 - 0.5).signum())
|
* (floater.rand as f64 - 0.5).signum())
|
||||||
@ -2467,16 +2460,8 @@ impl Hud {
|
|||||||
|
|
||||||
// Timer sets text transparency
|
// Timer sets text transparency
|
||||||
let fade = if crit {
|
let fade = if crit {
|
||||||
// FIXME: later
|
|
||||||
// TODO: A setting for popping?
|
|
||||||
((crate::ecs::sys::floater::CRIT_SHOWTIME - floater.timer) * 0.75)
|
((crate::ecs::sys::floater::CRIT_SHOWTIME - floater.timer) * 0.75)
|
||||||
+ 0.5
|
+ 0.5
|
||||||
// if floater.timer <
|
|
||||||
// crate::ecs::sys::floater::CRIT_SHOWTIME {
|
|
||||||
// 1.0
|
|
||||||
// } else {
|
|
||||||
// 0.0
|
|
||||||
// }
|
|
||||||
} else {
|
} else {
|
||||||
((crate::ecs::sys::floater::HP_SHOWTIME - floater.timer) * 0.25)
|
((crate::ecs::sys::floater::HP_SHOWTIME - floater.timer) * 0.25)
|
||||||
+ 0.2
|
+ 0.2
|
||||||
@ -4676,59 +4661,53 @@ impl Hud {
|
|||||||
},
|
},
|
||||||
None => hit_me,
|
None => hit_me,
|
||||||
} {
|
} {
|
||||||
let mut merged = false;
|
// Group up damage from the same tick, with the same instance number and
|
||||||
// Or maybe something like this
|
// has the same crit value
|
||||||
for floater in floater_list.floaters.iter_mut().rev() {
|
for floater in floater_list.floaters.iter_mut().rev() {
|
||||||
if floater.timer > 0.0 {
|
if floater.timer > 0.0 {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if floater.info.instance == info.instance {
|
if floater.info.instance == info.instance
|
||||||
dbg!(floater.info.instance);
|
&& floater.info.crit.unwrap_or(false)
|
||||||
dbg!(floater.timer);
|
== info.crit.unwrap_or(false)
|
||||||
|
{
|
||||||
floater.info.amount += info.amount;
|
floater.info.amount += info.amount;
|
||||||
floater.info.crit_mult = info.crit_mult;
|
floater.info.crit_mult = info.crit_mult;
|
||||||
floater.info.crit = Some(
|
floater.info.crit = Some(
|
||||||
floater.info.crit.unwrap_or(false)
|
floater.info.crit.unwrap_or(false)
|
||||||
|| info.crit.unwrap_or(false)
|
|| info.crit.unwrap_or(false),
|
||||||
);
|
);
|
||||||
merged = true;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
let last_floater = if info.amount < Health::HEALTH_EPSILON {
|
||||||
floater_list
|
floater_list.floaters.iter_mut().rev().find(|f| {
|
||||||
.floaters
|
f.info.amount < Health::HEALTH_EPSILON
|
||||||
.iter_mut()
|
&& info.crit.map_or(f.info.crit.unwrap_or(false), |_| {
|
||||||
.rev()
|
!f.info.crit.unwrap_or(false)
|
||||||
.find(|f| f.info.amount < Health::HEALTH_EPSILON)
|
})
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
floater_list
|
floater_list.floaters.iter_mut().rev().find(|f| {
|
||||||
.floaters
|
f.info.amount > Health::HEALTH_EPSILON
|
||||||
.iter_mut()
|
&& info.crit.map_or(f.info.crit.unwrap_or(false), |_| {
|
||||||
.rev()
|
!f.info.crit.unwrap_or(false)
|
||||||
.find(|f| f.info.amount > Health::HEALTH_EPSILON)
|
})
|
||||||
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
match last_floater {
|
match last_floater {
|
||||||
Some(f)
|
Some(f)
|
||||||
// TODO: Change later so it's based on options
|
// TODO: Change later so it's based on options
|
||||||
if /*(info.crit.unwrap_or(false)
|
if (f.timer < floater::HP_ACCUMULATETIME && !f.info.crit.unwrap_or(false)) =>
|
||||||
|| (f.timer < floater::HP_ACCUMULATETIME
|
|
||||||
&& !f.info.crit.unwrap_or(false)
|
|
||||||
&& !info.crit.unwrap_or(false)) */ false =>
|
|
||||||
{
|
{
|
||||||
dbg!(f.info.instance);
|
|
||||||
dbg!(f.timer);
|
|
||||||
//TODO: Add "jumping" animation on floater when it changes its
|
//TODO: Add "jumping" animation on floater when it changes its
|
||||||
// value
|
// value
|
||||||
f.info.amount += info.amount;
|
f.info.amount += info.amount;
|
||||||
f.info.crit_mult = info.crit_mult;
|
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));
|
f.info.crit = Some(f.info.crit.unwrap_or(false) || info.crit.unwrap_or(false));
|
||||||
},
|
},
|
||||||
_ => {
|
_ => {
|
||||||
|
Loading…
Reference in New Issue
Block a user