Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
706b91d
chore: bump cached_build
BarmonHammer Aug 29, 2023
22929dc
fix: clippy compile
BarmonHammer Aug 29, 2023
0f52e55
chore: set clippy as default linter
BarmonHammer Aug 29, 2023
d406c3f
chore: clippy cleanup
BarmonHammer Aug 29, 2023
5157c3f
chore: add Copy trait to Formula types
BarmonHammer Aug 29, 2023
47cce25
chore: is_weapon_stat to use matches!
BarmonHammer Aug 29, 2023
7ced3fb
chore: Default trait for Stat
BarmonHammer Aug 29, 2023
1baaf3c
chore: perk_value_map_update iterate over values
BarmonHammer Aug 29, 2023
298b5d1
chore: get_mod deref
BarmonHammer Aug 29, 2023
f0782da
chore: clean up set_weapon()
BarmonHammer Aug 29, 2023
7158124
chore: remove an allow all lint tag
BarmonHammer Aug 29, 2023
9ebc3d1
chore: clean up tricksleeves dmr
BarmonHammer Aug 29, 2023
abc330e
chore: remove is_err in generate_weapon
BarmonHammer Aug 29, 2023
0808a3a
chore: clippy auto clean after lint tag removal
BarmonHammer Aug 29, 2023
95e3867
chore: clean up veist stinger
BarmonHammer Aug 29, 2023
8065f32
chore: enumerate resil values in ttk
BarmonHammer Aug 30, 2023
f1873c7
chore: stat_calcs cleanup
BarmonHammer Aug 30, 2023
64a9fc8
chore: exotic_perks
BarmonHammer Aug 30, 2023
e5a0bd3
fix: explosive light?
BarmonHammer Aug 30, 2023
d5671c4
chore: add lint allow tags for CalcInput
BarmonHammer Aug 30, 2023
1cbc81a
chore: clean epr builtIn
BarmonHammer Aug 30, 2023
d7a83b2
chore: add type defs for modifier functions
BarmonHammer Aug 30, 2023
235f842
chore: remove redundant Default()
BarmonHammer Aug 30, 2023
4491e9e
chore: clean up major and bigones spec
BarmonHammer Aug 30, 2023
cb19d71
chore: remove redundant Default() year 1
BarmonHammer Aug 30, 2023
e1bd5f7
chore!: Display trait instead of toString
BarmonHammer Aug 30, 2023
b735069
chore: clean focused fury
BarmonHammer Aug 30, 2023
6085b67
chore: clippy clean
BarmonHammer Aug 30, 2023
d79464f
chore: don't lint build script
BarmonHammer Aug 30, 2023
b2c1c73
Merge branch 'main' into clippy
BarmonHammer Sep 11, 2023
5cd8635
chore: cleaned up some code for harm🥺
oh-yes-0-fps Sep 14, 2023
6a84ad8
ran cargo fmt
oh-yes-0-fps Sep 14, 2023
29de5b6
Merge branch 'main' into error-propagation
BarmonHammer Sep 14, 2023
d6acbd0
clippy🤤
oh-yes-0-fps Sep 14, 2023
371cb1d
🤓
oh-yes-0-fps Sep 14, 2023
33a0497
🙄
oh-yes-0-fps Sep 14, 2023
58ae1c5
Merge branch 'main' into error-propagation
oh-yes-0-fps Sep 14, 2023
a82d384
remove unreachable pub
oh-yes-0-fps Sep 14, 2023
b592cac
Renamed cased enums
oh-yes-0-fps Sep 14, 2023
6c26fe4
re-add unreachable pub
oh-yes-0-fps Sep 14, 2023
a92074a
removed js_types
oh-yes-0-fps Sep 14, 2023
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
11 changes: 1 addition & 10 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,4 @@
*.zip
*.ts
!*.d.ts
database/weapon_formulas.rs
!database/compactor.py
!database/perk_rerouter.py
zdata.json
database/weapon.json
database/weapon_test.json
database/enhanced_handler.rs
/zPythonStuff
/zPveReverser
data.json
/boboswaggins_kitchen
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
"IS_RA": "true"
},
"rust-analyzer.check.command": "clippy",
"rust-analyzer.cargo.target": "wasm32-unknown-unknown",
}
25 changes: 23 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ edition = "2021"
version = "1.0.2"
rust-version = "1.65"
repository = "https://github.com/d2foundry/oracle_engine/"
# build = "build-script-src/main.rs"
build = "build.rs"

[build-dependencies]
Expand All @@ -12,6 +13,7 @@ serde = { version = "^1.0", features = ["derive"]}
reqwest = { version = "^0.11", features = ["json", "blocking"] }
serde_json = "^1.0"
ron = "^0.8"
thiserror = "1.0.48"

[dev-dependencies]
num-traits = "0.2"
Expand All @@ -20,12 +22,12 @@ num-traits = "0.2"
[dependencies]
serde = { version = "^1.0", features = ["derive"]}

serde-wasm-bindgen = { version = "^0.5"}
serde-wasm-bindgen = { version = "^0.6"}
console_error_panic_hook = { version = "0.1.7"}
wasm-bindgen = { version = "^0.2"}

num_enum = "0.7.0"
lol_alloc = "0.4.0"
lol_alloc = { version = "0.4.0", default-features = false}
piecewise-linear = "0.1.0"


Expand All @@ -34,4 +36,5 @@ crate-type = ["cdylib"]

[profile.release]
lto = true
strip = true
opt-level = "z"
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@

Oracle Engine is [Foundry](https://d2foundry.gg)'s Rust and WebAssembly based Destiny 2 calculation API, originally forked from the [D2 Calculation API](https://github.com/D2-Insight/D2_Calculation_API). This repo is what holds the weapon formulas, stat calculations, perk info, etc. that we use to display on Foundry.

This is also where we plan on having our project board for keeping track of our tasks on a lower level. We hope that this will give insight on what we are spending our time on and what is in the near future.
This is also where we plan on having our project board for keeping track of our tasks on a lower level. We hope that this will give insight on what we are spending our time on and what is in the near future.

If you wish to interact with us on a closer basis, our [Discord Server](https://discord.gg/dzW2DZBBQH) is where you can find us and have discussions with like minded guardians. We look forward to seeing you there!
If you wish to interact with us on a closer basis, our [Discord Server](https://discord.gg/dzW2DZBBQH) is where you can find us and have discussions with like minded guardians. We look forward to seeing you there!

## Building Oracle Engine for Foundry
## Building Oracle Engine

Run `cargo build` to install the dependencies required by Oracle Engine.
Run `cargo build` to install the dependencies required by Oracle Engine.

In order to build the WebAssembly (wasm) pack you will need to download wasm-pack from this [site](https://rustwasm.github.io/wasm-pack/installer/) or via this cURL command:

`curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh`
`cargo install wasm-pack`

Once you have this installed you can build the app via this wasm-pack command.

`wasm-pack build --release --target web`

## Contributing

Looking to help contribute to Foundry? We welcome you to contribute to our project! Please see our [CONTRIBUTING.md](./CONTRIBUTING.md) to learn the various ways you can help us. Thank you for having an interest in contributing!
Looking to help contribute to Foundry? We welcome you to contribute to our project! Please see our [CONTRIBUTING.md](./CONTRIBUTING.md) to learn the various ways you can help us. Thank you for having an interest in contributing!
38 changes: 18 additions & 20 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl UuidTimestamp for StatQuadraticFormula {
}

#[derive(Debug, Clone, Serialize, Default)]
pub struct DamageMods {
pub struct DamageModFormula {
pub pve: f64,
pub minor: f64,
pub elite: f64,
Expand All @@ -109,9 +109,9 @@ pub struct DamageMods {
pub vehicle: f64,
pub timestamp: u64,
}
impl From<&Map<String, Value>> for DamageMods {
impl From<&Map<String, Value>> for DamageModFormula {
fn from(_val: &Map<String, Value>) -> Self {
DamageMods {
DamageModFormula {
pve: 1.0,
minor: _val
.get("minor")
Expand Down Expand Up @@ -147,10 +147,10 @@ impl From<&Map<String, Value>> for DamageMods {
}
}
}
impl DamageMods {
impl DamageModFormula {
pub fn add_pve_mult(self, mult: f64) -> Self {
// not super memory efficient but it works
DamageMods {
DamageModFormula {
pve: mult,
minor: self.minor,
elite: self.elite,
Expand All @@ -162,7 +162,7 @@ impl DamageMods {
}
}
}
impl UuidTimestamp for DamageMods {
impl UuidTimestamp for DamageModFormula {
fn uuid(&self) -> f64 {
(self.pve - 12.0) * 6729.0
+ self.minor * 18342.0
Expand Down Expand Up @@ -294,7 +294,7 @@ impl UuidTimestamp for AmmoFormula {
}

#[derive(Debug, Clone, Serialize, Default)]
pub struct FiringData {
pub struct FiringDataFormula {
pub damage: f64,
pub crit_mult: f64,
pub burst_delay: f64,
Expand All @@ -304,9 +304,9 @@ pub struct FiringData {
pub charge: bool,
pub timestamp: u64,
}
impl From<&Map<String, Value>> for FiringData {
impl From<&Map<String, Value>> for FiringDataFormula {
fn from(_val: &Map<String, Value>) -> Self {
FiringData {
FiringDataFormula {
damage: _val["damage"].as_f64().unwrap_or_default(),
crit_mult: _val["crit_mult"].as_f64().unwrap_or_default(),
burst_delay: _val["burst_delay"].as_f64().unwrap_or_default(),
Expand All @@ -326,7 +326,7 @@ impl From<&Map<String, Value>> for FiringData {
}
}
}
impl UuidTimestamp for FiringData {
impl UuidTimestamp for FiringDataFormula {
fn uuid(&self) -> f64 {
(self.damage * 821.88
+ self.crit_mult * 388.1
Expand Down Expand Up @@ -358,7 +358,7 @@ fn write_variable(
) {
let res = writeln!(
writer,
"#[doc=r#\"{}\"#]\n#[allow(dead_code)]\n#[allow(clippy::approx_constant)]\npub const {}: {} = {};",
"#[doc=r#\"{}\"#]\n#[allow(dead_code)]\n#[allow(clippy::approx_constant)]\npub(crate) const {}: {} = {};",
doc, name, datatype, value
);
if res.is_err() {
Expand All @@ -380,9 +380,7 @@ fn main() {
let mut formula_file = std::fs::File::create(formula_dst).unwrap();

//write imports in file
let res = writeln!(
formula_file,
"use crate::types::rs_types::{{StatQuadraticFormula, RangeFormula, HandlingFormula, ReloadFormula, DamageMods, AmmoFormula, DataPointers, FiringData, WeaponPath}};");
let res = writeln!(formula_file, "use crate::types::prelude::*;");
if res.is_err() {
panic!("cargo:warning=error writing imports");
}
Expand Down Expand Up @@ -496,8 +494,8 @@ fn construct_weapon_formulas(formula_file: &mut File, cached: &mut CachedBuildDa
let mut range_data: Vec<RangeFormula> = vec![RangeFormula::default()];
let mut reload_data: Vec<ReloadFormula> = vec![ReloadFormula::default()];
let mut ammo_data: Vec<AmmoFormula> = vec![AmmoFormula::default()];
let mut firing_data: Vec<FiringData> = vec![FiringData::default()];
let mut scalar_data: Vec<DamageMods> = vec![DamageMods::default()];
let mut firing_data: Vec<FiringDataFormula> = vec![FiringDataFormula::default()];
let mut scalar_data: Vec<DamageModFormula> = vec![DamageModFormula::default()];

let mut updated_weapon_defs: Vec<(WeaponPath, DataPointers)> = Vec::new();
for (weapon_id, inner_values) in new_jdata.as_object().unwrap() {
Expand Down Expand Up @@ -647,7 +645,7 @@ fn construct_weapon_formulas(formula_file: &mut File, cached: &mut CachedBuildDa
handling_data.push(handling);
}

let b_scalar: DamageMods = cat
let b_scalar: DamageModFormula = cat
.get("combatant_scalars")
.unwrap_or_else(|| {
err_list.push(format!(
Expand Down Expand Up @@ -686,7 +684,7 @@ fn construct_weapon_formulas(formula_file: &mut File, cached: &mut CachedBuildDa
ammo_data.push(ammo);
}

let mut firing: FiringData = (&fam).into();
let mut firing: FiringDataFormula = (&fam).into();
firing.burst_delay *= 1.0 / 30.0;
firing.inner_burst_delay *= 1.0 / 30.0;
firing.crit_mult = 1.5 + (firing.crit_mult / 51.0);
Expand Down Expand Up @@ -752,14 +750,14 @@ fn construct_weapon_formulas(formula_file: &mut File, cached: &mut CachedBuildDa
write_variable(
formula_file,
"SCALAR_DATA",
&format!("[DamageMods; {}]", scalar_data.len()),
&format!("[DamageModFormula; {}]", scalar_data.len()),
format!("{:?}", scalar_data),
"Array of combatant scalar formulas",
);
write_variable(
formula_file,
"FIRING_DATA",
&format!("[FiringData; {}]", firing_data.len()),
&format!("[FiringDataFormula; {}]", firing_data.len()),
format!("{:?}", firing_data),
"Array of firing data formulas",
);
Expand Down
7 changes: 3 additions & 4 deletions src/abilities/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[derive(Default)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub enum AbilityType {
GRENADE,
MELEE,
Expand All @@ -14,8 +13,8 @@ pub enum AbilityType {
UNKNOWN,
}


#[derive(Debug, Clone, Default)]
#[allow(dead_code)]
#[derive(Debug, Clone, Copy, Default)]
pub struct AbilityDamageProfile {
impact: f64,
secondary: f64,
Expand Down
43 changes: 20 additions & 23 deletions src/activity/damage_calc.rs
Original file line number Diff line number Diff line change
@@ -1,32 +1,29 @@
#![allow(dead_code)]
use super::Activity;
use crate::{enemies::EnemyType, logging, types::rs_types::DamageMods};
use crate::logging;
use piecewise_linear::PiecewiseLinearFunction;
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone)]
pub struct DifficultyData {
name: String,
// name: String,
cap: i32,
table: PiecewiseLinearFunction<f64>,
}

const WEAPON_DELTA_EXPONENT: f64 = 0.00672;

#[derive(Debug, Clone)]
#[derive(Default)]
#[derive(Debug, Clone, Copy, Default, serde::Deserialize)]
pub enum DifficultyOptions {
#[default]
NORMAL = 1,
RAID = 2,
MASTER = 3,
Normal = 1,
Raid = 2,
Master = 3,
}

impl DifficultyOptions {
pub fn get_difficulty_data(&self) -> DifficultyData {
match self {
DifficultyOptions::NORMAL => DifficultyData {
name: "Normal".to_string(),
DifficultyOptions::Normal => DifficultyData {
// name: "Normal".to_string(),
cap: 50,
table: PiecewiseLinearFunction::try_from(vec![
(-99.0, 0.4018),
Expand All @@ -41,10 +38,10 @@ impl DifficultyOptions {
(-10.0, 0.7800),
(0.0, 1.0),
])
.unwrap(),
.expect("Failed to create PiecewiseLinearFunction in difficulty data"),
},
DifficultyOptions::MASTER => DifficultyData {
name: "Master".to_string(),
DifficultyOptions::Master => DifficultyData {
// name: "Master".to_string(),
cap: 20,
table: PiecewiseLinearFunction::try_from(vec![
(-99.0, 0.4018),
Expand All @@ -59,10 +56,10 @@ impl DifficultyOptions {
(-10.0, 0.6800),
(0.0, 0.8500),
])
.unwrap(),
.expect("Failed to create PiecewiseLinearFunction in difficulty data"),
},
DifficultyOptions::RAID => DifficultyData {
name: "Raid & Dungeon".to_string(),
DifficultyOptions::Raid => DifficultyData {
// name: "Raid & Dungeon".to_string(),
cap: 20,
table: PiecewiseLinearFunction::try_from(vec![
(-99.0, 0.4018),
Expand All @@ -77,18 +74,18 @@ impl DifficultyOptions {
(-10.0, 0.73),
(0.0, 0.925),
])
.unwrap(),
.expect("Failed to create PiecewiseLinearFunction in difficulty data"),
},
}
}
}
impl From<i32> for DifficultyOptions {
fn from(i: i32) -> Self {
match i {
1 => DifficultyOptions::NORMAL,
2 => DifficultyOptions::RAID,
3 => DifficultyOptions::MASTER,
_ => DifficultyOptions::NORMAL,
1 => DifficultyOptions::Normal,
2 => DifficultyOptions::Raid,
3 => DifficultyOptions::Master,
_ => DifficultyOptions::Normal,
}
}
}
Expand All @@ -111,7 +108,7 @@ pub(super) fn get_gear_delta_mult(_activity: &Activity) -> f64 {
} else {
difficulty_data.table.y_at_x(0.0)
}
.unwrap();
.expect("Failed to get gear delta mult");

crate::logging::log(
format!("gear_delta_mult: {}", gear_delta_mult).as_str(),
Expand Down
Loading