mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Instance number generated inside projectile constructor, remove crit field
This commit is contained in:
parent
6c75ad6ef8
commit
202d558246
@ -258,8 +258,7 @@ impl Attack {
|
||||
by: attacker.map(|x| x.into()),
|
||||
cause: Some(damage.damage.source),
|
||||
time,
|
||||
crit: Some(is_crit),
|
||||
crit_mult: self.crit_multiplier,
|
||||
crit_mult: is_crit.then(|| self.crit_multiplier),
|
||||
instance: damage.instance,
|
||||
};
|
||||
emit(ServerEvent::HealthChange {
|
||||
@ -358,8 +357,7 @@ impl Attack {
|
||||
by: attacker.map(|a| a.into()),
|
||||
cause: None,
|
||||
time,
|
||||
crit: None,
|
||||
crit_mult: self.crit_multiplier,
|
||||
crit_mult: None,
|
||||
instance: rand::random(),
|
||||
};
|
||||
if change.amount.abs() > Health::HEALTH_EPSILON {
|
||||
@ -393,8 +391,7 @@ impl Attack {
|
||||
by: attacker.map(|a| a.into()),
|
||||
cause: None,
|
||||
time,
|
||||
crit: None,
|
||||
crit_mult: self.crit_multiplier,
|
||||
crit_mult: None,
|
||||
instance: rand::random(),
|
||||
};
|
||||
if change.amount.abs() > Health::HEALTH_EPSILON {
|
||||
@ -507,8 +504,7 @@ impl Attack {
|
||||
by: attacker.map(|a| a.into()),
|
||||
cause: None,
|
||||
time,
|
||||
crit: None,
|
||||
crit_mult: self.crit_multiplier,
|
||||
crit_mult: None,
|
||||
instance: rand::random(),
|
||||
};
|
||||
if change.amount.abs() > Health::HEALTH_EPSILON {
|
||||
@ -542,8 +538,7 @@ impl Attack {
|
||||
by: attacker.map(|a| a.into()),
|
||||
cause: None,
|
||||
time,
|
||||
crit: None,
|
||||
crit_mult: self.crit_multiplier,
|
||||
crit_mult: None,
|
||||
instance: rand::random(),
|
||||
};
|
||||
if change.amount.abs() > Health::HEALTH_EPSILON {
|
||||
@ -861,8 +856,7 @@ impl Damage {
|
||||
by: damage_contributor,
|
||||
cause: Some(self.source),
|
||||
time,
|
||||
crit: Some(is_crit),
|
||||
crit_mult,
|
||||
crit_mult: is_crit.then(|| crit_mult),
|
||||
instance,
|
||||
}
|
||||
},
|
||||
@ -876,8 +870,7 @@ impl Damage {
|
||||
by: None,
|
||||
cause: Some(self.source),
|
||||
time,
|
||||
crit: None,
|
||||
crit_mult,
|
||||
crit_mult: None,
|
||||
instance,
|
||||
}
|
||||
},
|
||||
@ -886,8 +879,7 @@ impl Damage {
|
||||
by: None,
|
||||
cause: Some(self.source),
|
||||
time,
|
||||
crit: None,
|
||||
crit_mult,
|
||||
crit_mult: None,
|
||||
instance,
|
||||
},
|
||||
}
|
||||
|
@ -25,10 +25,8 @@ pub struct HealthChange {
|
||||
pub cause: Option<DamageSource>,
|
||||
/// The time that the health change occurred at
|
||||
pub time: Time,
|
||||
/// Whether or not the health change was caused by a crit (None if it
|
||||
/// couldn't have been a crit)
|
||||
pub crit: Option<bool>,
|
||||
pub crit_mult: f32,
|
||||
/// The crit multiplier (None if it isn't a crit)
|
||||
pub crit_mult: Option<f32>,
|
||||
/// A random ID, used to group up health changes
|
||||
// Note: Two or more changes could have the same instance number, if they
|
||||
// came from the same attack (for example - the extra damage caused by
|
||||
@ -142,8 +140,7 @@ impl Health {
|
||||
amount: 0.0,
|
||||
by: None,
|
||||
cause: None,
|
||||
crit: None,
|
||||
crit_mult: 1.0,
|
||||
crit_mult: None,
|
||||
time: Time(0.0),
|
||||
instance: rand::random(),
|
||||
},
|
||||
@ -225,8 +222,7 @@ impl Health {
|
||||
amount: 0.0,
|
||||
by: None,
|
||||
cause: None,
|
||||
crit: None,
|
||||
crit_mult: 1.0,
|
||||
crit_mult: None,
|
||||
time: Time(0.0),
|
||||
instance: rand::random(),
|
||||
},
|
||||
@ -262,8 +258,7 @@ mod tests {
|
||||
time: Time(123.0),
|
||||
by: Some(damage_contrib),
|
||||
cause: None,
|
||||
crit: None,
|
||||
crit_mult: 1.0,
|
||||
crit_mult: None,
|
||||
instance: rand::random(),
|
||||
};
|
||||
|
||||
@ -290,8 +285,7 @@ mod tests {
|
||||
time: Time(123.0),
|
||||
by: Some(damage_contrib),
|
||||
cause: None,
|
||||
crit: None,
|
||||
crit_mult: 1.0,
|
||||
crit_mult: None,
|
||||
instance: rand::random(),
|
||||
};
|
||||
|
||||
@ -312,8 +306,7 @@ mod tests {
|
||||
time: Time(123.0),
|
||||
by: Some(damage_contrib),
|
||||
cause: None,
|
||||
crit: None,
|
||||
crit_mult: 1.0,
|
||||
crit_mult: None,
|
||||
instance: rand::random(),
|
||||
};
|
||||
health.change_by(health_change);
|
||||
@ -340,8 +333,7 @@ mod tests {
|
||||
time: Time(10.0),
|
||||
by: Some(damage_contrib1),
|
||||
cause: None,
|
||||
crit: None,
|
||||
crit_mult: 1.0,
|
||||
crit_mult: None,
|
||||
instance: rand::random(),
|
||||
};
|
||||
health.change_by(health_change);
|
||||
@ -352,8 +344,7 @@ mod tests {
|
||||
time: Time(100.0),
|
||||
by: Some(damage_contrib2),
|
||||
cause: None,
|
||||
crit: None,
|
||||
crit_mult: 1.0,
|
||||
crit_mult: None,
|
||||
instance: rand::random(),
|
||||
};
|
||||
health.change_by(health_change);
|
||||
@ -368,8 +359,7 @@ mod tests {
|
||||
time: Time(620.0),
|
||||
by: Some(damage_contrib2),
|
||||
cause: None,
|
||||
crit: None,
|
||||
crit_mult: 1.0,
|
||||
crit_mult: None,
|
||||
instance: rand::random(),
|
||||
};
|
||||
health.change_by(health_change);
|
||||
|
@ -98,7 +98,6 @@ impl ProjectileConstructor {
|
||||
crit_chance: f32,
|
||||
crit_mult: f32,
|
||||
buff_strength: f32,
|
||||
instance: u64,
|
||||
) -> Projectile {
|
||||
use ProjectileConstructor::*;
|
||||
match self {
|
||||
@ -123,6 +122,7 @@ impl ProjectileConstructor {
|
||||
strength: CombatBuffStrength::DamageFraction(0.1 * buff_strength),
|
||||
chance: 0.1,
|
||||
});
|
||||
let instance = rand::random();
|
||||
let damage = AttackDamage::new(
|
||||
Damage {
|
||||
source: DamageSource::Projectile,
|
||||
|
@ -7,10 +7,9 @@ use vek::*;
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
|
||||
pub struct DamageInfo {
|
||||
pub amount: f32,
|
||||
pub crit: Option<bool>,
|
||||
pub crit_mult: Option<f32>,
|
||||
pub target: Uid,
|
||||
pub by: Option<DamageContributor>,
|
||||
pub crit_mult: f32,
|
||||
pub instance: u64,
|
||||
}
|
||||
|
||||
|
@ -84,7 +84,6 @@ 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 {
|
||||
|
@ -119,7 +119,6 @@ impl CharacterBehavior for Data {
|
||||
crit_chance,
|
||||
crit_mult,
|
||||
buff_strength,
|
||||
rand::random(),
|
||||
);
|
||||
output_events.emit_server(ServerEvent::Shoot {
|
||||
entity: data.entity,
|
||||
|
@ -100,7 +100,6 @@ impl CharacterBehavior for Data {
|
||||
crit_chance,
|
||||
crit_mult,
|
||||
buff_strength,
|
||||
rand::random(),
|
||||
);
|
||||
output_events.emit_server(ServerEvent::Shoot {
|
||||
entity: data.entity,
|
||||
|
@ -274,8 +274,7 @@ impl<'a> System<'a> for Sys {
|
||||
by: damage_contributor,
|
||||
cause,
|
||||
time: *read_data.time,
|
||||
crit: None,
|
||||
crit_mult: 1.0,
|
||||
crit_mult: None,
|
||||
instance: rand::random(),
|
||||
},
|
||||
});
|
||||
|
@ -1056,8 +1056,7 @@ fn handle_health(
|
||||
amount: hp - health.current(),
|
||||
by: None,
|
||||
cause: None,
|
||||
crit: None,
|
||||
crit_mult: 1.0,
|
||||
crit_mult: None,
|
||||
time: *time,
|
||||
instance: rand::random(),
|
||||
};
|
||||
|
@ -89,7 +89,6 @@ pub fn handle_health_change(server: &Server, entity: EcsEntity, change: HealthCh
|
||||
pos: pos.0,
|
||||
info: DamageInfo {
|
||||
amount: change.amount,
|
||||
crit: change.crit,
|
||||
by: change.by,
|
||||
target: *uid,
|
||||
crit_mult: change.crit_mult,
|
||||
|
@ -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, rand::random()),
|
||||
projectile: constr.create_projectile(None, 0.0, 1.0, 1.0),
|
||||
light: None,
|
||||
speed: 5.0,
|
||||
object: None,
|
||||
|
@ -85,7 +85,7 @@ impl<'a> System<'a> for Sys {
|
||||
floater.timer += dt.0;
|
||||
}
|
||||
|
||||
// Clear floaters if newest floater is past show time or health runs out
|
||||
// Clear floaters if newest floater is past show time
|
||||
if floaters.last().map_or(false, |f| {
|
||||
f.timer
|
||||
> if Some(entity) != my_entity.0 {
|
||||
|
@ -1449,10 +1449,11 @@ impl Hud {
|
||||
let crit = damage_floaters
|
||||
.iter()
|
||||
.rev()
|
||||
.find(|f| f.info.crit != None)
|
||||
.map_or(false, |f| f.info.crit.unwrap_or(false));
|
||||
let crit_mult =
|
||||
damage_floaters.last().map_or(1.0, |f| f.info.crit_mult);
|
||||
.find(|f| f.info.crit_mult.is_some())
|
||||
.map_or(false, |f| f.info.crit_mult.is_some());
|
||||
let crit_mult = damage_floaters
|
||||
.last()
|
||||
.map_or(1.0, |f| f.info.crit_mult.unwrap_or(1.0));
|
||||
|
||||
// Increase font size based on fraction of maximum health
|
||||
// "flashes" by having a larger size in the first 100ms
|
||||
@ -1523,28 +1524,21 @@ impl Hud {
|
||||
.abs()
|
||||
.clamp(Health::HEALTH_EPSILON, health.maximum())
|
||||
/ health.maximum();
|
||||
let crit = floater.info.crit.unwrap_or(false);
|
||||
let crit = floater.info.crit_mult.is_some();
|
||||
let crit_mult = floater.info.crit_mult.unwrap_or(1.0);
|
||||
// Increase font size based on fraction of maximum health
|
||||
// "flashes" by having a larger size in the first 100ms
|
||||
// TODO: example
|
||||
let font_size = 30
|
||||
+ (max_hp_frac
|
||||
* 10.0
|
||||
* if crit {
|
||||
1.25 * floater.info.crit_mult
|
||||
} else {
|
||||
1.0
|
||||
}) as u32
|
||||
+ (max_hp_frac * 10.0 * if crit { 1.25 * crit_mult } else { 1.0 })
|
||||
as u32
|
||||
* 3
|
||||
+ if floater.timer < 0.1 {
|
||||
FLASH_MAX
|
||||
* (((1.0 - floater.timer / 0.1)
|
||||
* 10.0
|
||||
* if crit {
|
||||
1.25 * floater.info.crit_mult
|
||||
} else {
|
||||
1.0
|
||||
}) as u32)
|
||||
* if crit { 1.25 * crit_mult } else { 1.0 })
|
||||
as u32)
|
||||
} else {
|
||||
0
|
||||
};
|
||||
@ -2323,10 +2317,11 @@ impl Hud {
|
||||
let crit = damage_floaters
|
||||
.iter()
|
||||
.rev()
|
||||
.find(|f| f.info.crit != None)
|
||||
.map_or(false, |f| f.info.crit.unwrap_or(false));
|
||||
let crit_mult =
|
||||
damage_floaters.last().map_or(1.0, |f| f.info.crit_mult);
|
||||
.find(|f| f.info.crit_mult.is_some())
|
||||
.map_or(false, |f| f.info.crit_mult.is_some());
|
||||
let crit_mult = damage_floaters
|
||||
.last()
|
||||
.map_or(1.0, |f| f.info.crit_mult.unwrap_or(1.0));
|
||||
|
||||
// Increase font size based on fraction of maximum health
|
||||
// "flashes" by having a larger size in the first 100ms
|
||||
@ -2410,29 +2405,20 @@ impl Hud {
|
||||
Health::HEALTH_EPSILON,
|
||||
health.map_or(1.0, |h| h.maximum()),
|
||||
) / health.map_or(1.0, |h| h.maximum());
|
||||
let crit = floater.info.crit.map_or(false, |c| c);
|
||||
let crit = floater.info.crit_mult.is_some();
|
||||
let crit_mult = floater.info.crit_mult.unwrap_or(1.0);
|
||||
// Increase font size based on fraction of maximum health
|
||||
// "flashes" by having a larger size in the first 100ms
|
||||
let font_size = 30
|
||||
+ (max_hp_frac
|
||||
* 10.0
|
||||
* if crit {
|
||||
1.25 * floater.info.crit_mult
|
||||
} else {
|
||||
1.0
|
||||
}) as u32
|
||||
+ (max_hp_frac * 10.0 * if crit { 1.25 * crit_mult } else { 1.0 })
|
||||
as u32
|
||||
* 3
|
||||
+ if floater.timer < 0.1 {
|
||||
FLASH_MAX
|
||||
* (((1.0 - floater.timer / 0.1)
|
||||
* 10.0
|
||||
* if crit {
|
||||
// FIXME: later
|
||||
1.25 * floater.info.crit_mult
|
||||
//1.0
|
||||
} else {
|
||||
1.0
|
||||
}) as u32)
|
||||
* if crit { 1.25 * crit_mult } else { 1.0 })
|
||||
as u32)
|
||||
} else {
|
||||
0
|
||||
};
|
||||
@ -4668,15 +4654,16 @@ impl Hud {
|
||||
break;
|
||||
}
|
||||
if floater.info.instance == info.instance
|
||||
&& floater.info.crit.unwrap_or(false)
|
||||
== info.crit.unwrap_or(false)
|
||||
&& floater.info.crit_mult.is_some() == info.crit_mult.is_some()
|
||||
{
|
||||
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),
|
||||
);
|
||||
floater.info.crit_mult = if info.crit_mult.is_some() {
|
||||
info.crit_mult
|
||||
} else {
|
||||
floater.info.crit_mult
|
||||
};
|
||||
dbg!(&floater.info.crit_mult);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -4686,14 +4673,12 @@ impl Hud {
|
||||
let last_floater = if info.amount < Health::HEALTH_EPSILON {
|
||||
floater_list.floaters.iter_mut().rev().find(|f| {
|
||||
f.info.amount < Health::HEALTH_EPSILON
|
||||
&& info.crit.unwrap_or(false)
|
||||
== f.info.crit.unwrap_or(false)
|
||||
&& info.crit_mult.is_some() == f.info.crit_mult.is_some()
|
||||
})
|
||||
} else {
|
||||
floater_list.floaters.iter_mut().rev().find(|f| {
|
||||
f.info.amount > Health::HEALTH_EPSILON
|
||||
&& info.crit.unwrap_or(false)
|
||||
== f.info.crit.unwrap_or(false)
|
||||
&& info.crit_mult.is_some() == f.info.crit_mult.is_some()
|
||||
})
|
||||
};
|
||||
dbg!(&last_floater);
|
||||
@ -4701,16 +4686,19 @@ impl Hud {
|
||||
match last_floater {
|
||||
Some(f)
|
||||
// TODO: Change later so it's based on options
|
||||
if (f.timer < floater::HP_ACCUMULATETIME && !f.info.crit.unwrap_or(false)) =>
|
||||
if f.timer < floater::HP_ACCUMULATETIME && !f.info.crit_mult.is_some() =>
|
||||
{
|
||||
//TODO: Add "jumping" animation on floater when it changes its
|
||||
// value
|
||||
f.info.amount += info.amount;
|
||||
f.info.crit_mult = info.crit_mult;
|
||||
f.info.crit = Some(f.info.crit.unwrap_or(false) || info.crit.unwrap_or(false));
|
||||
f.info.crit_mult = if info.crit_mult.is_some() {
|
||||
info.crit_mult
|
||||
} else {
|
||||
f.info.crit_mult
|
||||
};
|
||||
},
|
||||
_ => {
|
||||
dbg!(&info.amount);
|
||||
floater_list.floaters.push(HpFloater {
|
||||
timer: 0.0,
|
||||
info: *info,
|
||||
|
Loading…
Reference in New Issue
Block a user