Skip to content

Clean up firing data #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,24 +287,14 @@ pub fn get_weapon_firing_data(
_use_rpl: bool,
) -> Result<JsFiringResponse, JsValue> {
let persistent = PERS_DATA.with(|_perm_data| _perm_data.borrow().clone());
let mut response: types::rs_types::FiringResponse;
let calc_input: Option<CalculationInput> = if _dynamic_traits {
let mut buffer = persistent.weapon.static_calc_input();
buffer.enemy_type = &persistent.enemy.type_;
Some(buffer)
} else {
None
};
response = persistent.weapon.calc_firing_data(calc_input, None, _pvp);
response.apply_pve_bonuses(
persistent.activity.get_rpl_mult(),
persistent.activity.get_pl_delta(),
persistent.weapon.damage_mods.pve,
persistent
.weapon
.damage_mods
.get_mod(&persistent.enemy.type_),
);
let response = persistent.weapon.calc_firing_data(calc_input, None, _pvp);
crate::logging::log(format!("{:?}", response).as_str(), LogLevel::Debug.into());
Ok(response.into())
}
Expand Down
57 changes: 19 additions & 38 deletions src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,34 +136,22 @@ fn test_pulse_firing_data() {
setup_pulse();
PERS_DATA.with(|perm_data| {
let weapon = perm_data.borrow_mut().weapon.clone();
let mut response = weapon.calc_firing_data(None, None, true);
PERS_DATA.with(|perm_data| {
response.apply_pve_bonuses(
perm_data.borrow().activity.get_rpl_mult(),
perm_data.borrow().activity.get_pl_delta(),
perm_data.borrow().weapon.damage_mods.pve,
perm_data
.borrow()
.weapon
.damage_mods
.get_mod(&perm_data.borrow().enemy.type_),
)
});
let response = weapon.calc_firing_data(None, None, true);
assert!(
cmp_floats(response.pvp_impact_damage, 10.0),
cmp_floats(response.impact_damage, 10.0),
"impact damage: {}",
response.pvp_impact_damage
response.impact_damage
);
assert!(
cmp_floats(response.pvp_explosion_damage, 0.0),
cmp_floats(response.explosion_damage, 0.0),
"explosive damage: {}",
response.pvp_explosion_damage
response.explosion_damage
);
assert!(cmp_floats(response.rpm, 900.0), "rpm: {}", response.rpm);
assert!(
cmp_floats(response.pvp_crit_mult, 2.0),
cmp_floats(response.crit_mult, 2.0),
"crit mult: {}",
response.pvp_crit_mult
response.crit_mult
);
});
}
Expand Down Expand Up @@ -276,38 +264,31 @@ fn test_bow_firing_data() {
setup_bow();
PERS_DATA.with(|perm_data| {
let weapon = perm_data.borrow_mut().weapon.clone();
let mut response = weapon.calc_firing_data(None, None, true);
PERS_DATA.with(|perm_data| {
response.apply_pve_bonuses(
perm_data.borrow().activity.get_rpl_mult(),
perm_data.borrow().activity.get_pl_delta(),
perm_data.borrow().weapon.damage_mods.pve,
perm_data
.borrow()
.weapon
.damage_mods
.get_mod(&perm_data.borrow().enemy.type_),
)
});
let response = weapon.calc_firing_data(None, None, true);
assert!(
cmp_floats(response.pvp_impact_damage, 100.0),
cmp_floats(response.impact_damage, 100.0),
"impact damage: {}",
response.pvp_impact_damage
response.impact_damage
);
assert!(
cmp_floats(response.pvp_explosion_damage, 0.0),
cmp_floats(response.explosion_damage, 0.0),
"explosive damage: {}",
response.pvp_explosion_damage
response.explosion_damage
);
assert!(
cmp_floats(response.burst_delay, 20.0 / 30.0),
"draw time: {}",
response.burst_delay
);
assert!(
cmp_floats(response.pvp_crit_mult, 1.5 + (2.0 / 51.0)),
cmp_floats(response.burst_delay, 20.0 / 30.0),
"draw time: {}",
response.burst_delay
);
assert!(
cmp_floats(response.crit_mult, 1.5 + (2.0 / 51.0)),
"crit mult: {}",
response.pvp_crit_mult
response.crit_mult
);
});
}
28 changes: 9 additions & 19 deletions src/types/js_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,19 +227,12 @@ impl From<ResillienceSummary> for JsResillienceSummary {
#[derive(Debug, Clone, Default, Serialize)]
#[wasm_bindgen(js_name = "FiringResponse", inspectable)]
pub struct JsFiringResponse {
#[wasm_bindgen(js_name = "pvpImpactDamage", readonly)]
pub pvp_impact_damage: f64,
#[wasm_bindgen(js_name = "pvpExplosionDamage", readonly)]
pub pvp_explosion_damage: f64,
#[wasm_bindgen(js_name = "pvpCritMult", readonly)]
pub pvp_crit_mult: f64,

#[wasm_bindgen(js_name = "pveImpactDamage", readonly)]
pub pve_impact_damage: f64,
#[wasm_bindgen(js_name = "pveExplosionDamage", readonly)]
pub pve_explosion_damage: f64,
#[wasm_bindgen(js_name = "pveCritMult", readonly)]
pub pve_crit_mult: f64,
#[wasm_bindgen(js_name = "ImpactDamage", readonly)]
pub impact_damage: f64,
#[wasm_bindgen(js_name = "ExplosionDamage", readonly)]
pub explosion_damage: f64,
#[wasm_bindgen(js_name = "CritMult", readonly)]
pub crit_mult: f64,
Comment on lines +231 to +235

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

naive question: will you ever be able to get away from floats, are you stuck with them?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what alternative would you suggest? something like the rust_decimal crate?
i'll be doing a pretty big changes soon, so if the need is there i don't mind throwing that in


#[wasm_bindgen(js_name = "burstDelay", readonly)]
pub burst_delay: f64,
Expand All @@ -255,12 +248,9 @@ pub struct JsFiringResponse {
impl From<FiringResponse> for JsFiringResponse {
fn from(firing: FiringResponse) -> Self {
JsFiringResponse {
pvp_impact_damage: firing.pvp_impact_damage,
pvp_explosion_damage: firing.pvp_explosion_damage,
pvp_crit_mult: firing.pvp_crit_mult,
pve_impact_damage: firing.pve_impact_damage,
pve_explosion_damage: firing.pve_explosion_damage,
pve_crit_mult: firing.pve_crit_mult,
impact_damage: firing.impact_damage,
explosion_damage: firing.explosion_damage,
crit_mult: firing.crit_mult,
burst_delay: firing.burst_delay,
inner_burst_delay: firing.inner_burst_delay,
burst_size: firing.burst_size,
Expand Down
14 changes: 5 additions & 9 deletions src/types/rs_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,9 @@ impl DpsResponse {

#[derive(Debug, Clone, Default)]
pub struct FiringResponse {
pub pvp_impact_damage: f64,
pub pvp_explosion_damage: f64,
pub pvp_crit_mult: f64,

pub pve_impact_damage: f64,
pub pve_explosion_damage: f64,
pub pve_crit_mult: f64,
pub impact_damage: f64,
pub explosion_damage: f64,
pub crit_mult: f64,

pub burst_delay: f64,
pub inner_burst_delay: f64,
Expand All @@ -212,7 +208,7 @@ impl FiringResponse {
.as_str(),
crate::logging::LogLevel::Debug.into(),
);
self.pve_impact_damage *= _rpl_mult * _gpl_mult * _pve_mult * _combatant_mult;
self.pve_explosion_damage *= _rpl_mult * _gpl_mult * _pve_mult * _combatant_mult;
self.impact_damage *= _rpl_mult * _gpl_mult * _pve_mult * _combatant_mult;
self.explosion_damage *= _rpl_mult * _gpl_mult * _pve_mult * _combatant_mult;
}
}
82 changes: 37 additions & 45 deletions src/weapons/stat_calc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,71 +299,49 @@ impl Weapon {
_cached_data: Option<&mut HashMap<String, f64>>,
_pvp: bool,
) -> FiringResponse {
let pve_damage_modifiers: DamageModifierResponse;
let pvp_damage_modifiers: DamageModifierResponse;
let firing_modifiers: FiringModifierResponse;
let mut default_cached_data = HashMap::new();
let cached_data = _cached_data.unwrap_or(&mut default_cached_data);
if _calc_input.is_some() {
firing_modifiers = get_firing_modifier(
self.list_perks(),
&_calc_input.clone().unwrap(),
_pvp,
cached_data,
);
pvp_damage_modifiers = get_dmg_modifier(
self.list_perks(),
&_calc_input.clone().unwrap(),
true,
&mut cached_data.clone(),
);
pve_damage_modifiers = get_dmg_modifier(
self.list_perks(),
&_calc_input.clone().unwrap(),
false,
&mut cached_data.clone(),
);
let (firing_modifiers, damage_modifiers) = if let Some(calc_input) = _calc_input {
(
get_firing_modifier(self.list_perks(), &calc_input, _pvp, cached_data),
get_dmg_modifier(self.list_perks(), &calc_input, _pvp, cached_data),
)
} else {
firing_modifiers = FiringModifierResponse::default();
pvp_damage_modifiers = DamageModifierResponse::default();
pve_damage_modifiers = DamageModifierResponse::default();
(
FiringModifierResponse::default(),
DamageModifierResponse::default(),
)
};
let tmp_dmg_prof = self.get_damage_profile();
let impact_dmg = tmp_dmg_prof.0;
let explosion_dmg = tmp_dmg_prof.1;
let crit_mult = tmp_dmg_prof.2;

//rpm
let fd = self.firing_data;
let extra_charge_delay = if self.weapon_type == WeaponType::FUSIONRIFLE {
0.45
} else if self.weapon_type == WeaponType::LINEARFUSIONRIFLE {
0.95
} else {
0.0
let extra_charge_delay = match self.weapon_type {
WeaponType::LINEARFUSIONRIFLE => 0.95,
WeaponType::FUSIONRIFLE => 0.45,
_ => 0.0,
};

let burst_delay = (fd.burst_delay + firing_modifiers.burst_delay_add)
* firing_modifiers.burst_delay_scale;
let burst_size = fd.burst_size + firing_modifiers.burst_size_add as i32;
let inner_burst_delay = fd.inner_burst_delay * firing_modifiers.inner_burst_scale;
let raw_rpm = 60.0
/ ((burst_delay
+ (inner_burst_delay * (burst_size as f64 - 1.0))
+ extra_charge_delay)
/ ((burst_delay + (inner_burst_delay * (burst_size - 1) as f64) + extra_charge_delay)
/ burst_size as f64);
let rpm: f64;
if self.firing_data.one_ammo {
rpm = raw_rpm / burst_size as f64
let rpm = if self.firing_data.one_ammo {
raw_rpm / burst_size as f64
} else {
rpm = raw_rpm
raw_rpm
};
let out = FiringResponse {
pvp_impact_damage: impact_dmg * pvp_damage_modifiers.impact_dmg_scale,
pvp_explosion_damage: explosion_dmg * pvp_damage_modifiers.explosive_dmg_scale,
pvp_crit_mult: crit_mult * pvp_damage_modifiers.crit_scale,

pve_impact_damage: impact_dmg * pve_damage_modifiers.impact_dmg_scale,
pve_explosion_damage: explosion_dmg * pve_damage_modifiers.explosive_dmg_scale,
pve_crit_mult: crit_mult * pve_damage_modifiers.crit_scale,
let mut out = FiringResponse {
impact_damage: impact_dmg * damage_modifiers.impact_dmg_scale,
explosion_damage: explosion_dmg * damage_modifiers.explosive_dmg_scale,
crit_mult: crit_mult * damage_modifiers.crit_scale,

burst_delay,
burst_size,
Expand All @@ -373,6 +351,20 @@ impl Weapon {

timestamp: fd.timestamp,
};

if !_pvp {
let persistent = crate::PERS_DATA.with(|_perm_data| _perm_data.borrow().clone());
out.apply_pve_bonuses(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the idea that you'd calculate a base value of damage and subsequently apply multipliers for different activities?

If so, the approach I might suggest to make _pvp not a boolean, but rather, an enum that currently contains PvE and PvP. Since they're going to be adding additional PvP modes with different TTKs in season 22, I think might be worthwhile to get ahead of this while you're changing things here.

persistent.activity.get_rpl_mult(),
persistent.activity.get_pl_delta(),
persistent.weapon.damage_mods.pve,
persistent
.weapon
.damage_mods
.get_mod(&persistent.enemy.type_),
);
}

out
}
}
Expand Down