Factored out weapons into their own rating.

This commit is contained in:
Sam
2021-03-30 12:16:20 -04:00
parent 8365db8041
commit be5d47a512

View File

@ -6,13 +6,13 @@ use crate::{
inventory::{ inventory::{
item::{ item::{
armor::Protection, armor::Protection,
tool::{Tool, ToolKind}, tool::{self, Tool, ToolKind},
Item, ItemKind, MaterialStatManifest, Item, ItemKind, MaterialStatManifest,
}, },
slot::EquipSlot, slot::EquipSlot,
}, },
poise::PoiseChange, poise::PoiseChange,
skills::{SkillGroupKind, SkillSet}, skills::SkillGroupKind,
Body, Combo, Energy, EnergyChange, EnergySource, Health, HealthChange, HealthSource, Body, Combo, Energy, EnergyChange, EnergySource, Health, HealthChange, HealthSource,
Inventory, Stats, Inventory, Stats,
}, },
@ -721,21 +721,54 @@ pub fn get_weapons(inv: &Inventory) -> (Option<ToolKind>, Option<ToolKind>) {
) )
} }
#[cfg(not(target_arch = "wasm32"))] pub fn weapon_rating(item: &Item, msm: &MaterialStatManifest) -> f32 {
fn offensive_rating(inv: &Inventory, skillset: &SkillSet, msm: &MaterialStatManifest) -> f32 { const DAMAGE_WIGHT: f32 = 2.0;
let active_damage = const POISE_WEIGHT: f32 = 1.0;
equipped_item_and_tool(inv, EquipSlot::Mainhand).map_or(0.0, |(item, tool)| {
tool.base_power(msm, item.components()) if let ItemKind::Tool(tool) = item.kind() {
* tool.base_speed(msm, item.components()) let stats = tool::Stats::from((msm, item.components(), tool));
* (1.0 + 0.05 * skillset.earned_sp(SkillGroupKind::Weapon(tool.kind)) as f32)
}); let damage_rating =
let second_damage = stats.power * stats.speed * (1.0 + stats.crit_chance * (stats.crit_mult - 1.0));
equipped_item_and_tool(inv, EquipSlot::Offhand).map_or(0.0, |(item, tool)| { let poise_rating = stats.poise_strength * stats.speed;
tool.base_power(msm, item.components())
* tool.base_speed(msm, item.components()) (damage_rating * DAMAGE_WIGHT + poise_rating * POISE_WEIGHT) / (DAMAGE_WIGHT + POISE_WEIGHT)
* (1.0 + 0.05 * skillset.earned_sp(SkillGroupKind::Weapon(tool.kind)) as f32) } else {
}); 0.0
active_damage.max(second_damage) }
}
fn weapon_skills(inventory: &Inventory, stats: &Stats) -> f32 {
let (mainhand, offhand) = get_weapons(inventory);
let mainhand_skills = if let Some(tool) = mainhand {
stats.skill_set.earned_sp(SkillGroupKind::Weapon(tool)) as f32
} else {
0.0
};
let offhand_skills = if let Some(tool) = offhand {
stats.skill_set.earned_sp(SkillGroupKind::Weapon(tool)) as f32
} else {
0.0
};
mainhand_skills.max(offhand_skills)
}
fn get_weapon_rating(inventory: &Inventory, msm: &MaterialStatManifest) -> f32 {
let mainhand_rating =
if let Some((item, _)) = equipped_item_and_tool(inventory, EquipSlot::Mainhand) {
weapon_rating(item, msm)
} else {
0.0
};
let offhand_rating =
if let Some((item, _)) = equipped_item_and_tool(inventory, EquipSlot::Offhand) {
weapon_rating(item, msm)
} else {
0.0
};
mainhand_rating.max(offhand_rating)
} }
#[cfg(not(target_arch = "wasm32"))] #[cfg(not(target_arch = "wasm32"))]
@ -746,15 +779,29 @@ pub fn combat_rating(
body: Body, body: Body,
msm: &MaterialStatManifest, msm: &MaterialStatManifest,
) -> f32 { ) -> f32 {
let defensive_weighting = 1.0; const WEAPON_WEIGHT: f32 = 1.0;
let offensive_weighting = 1.0; const HEALTH_WEIGHT: f32 = 1.0;
let defensive_rating = health.maximum() as f32 const SKILLS_WEIGHT: f32 = 1.0;
/ (1.0 - Damage::compute_damage_reduction(Some(inventory), Some(stats))).max(0.00001) // Assumes a "standard" max health of 100
/ 100.0; let health_rating = health.base_max() as f32
let offensive_rating = offensive_rating(inventory, &stats.skill_set, msm).max(0.1) / 100.0
+ 0.05 * stats.skill_set.earned_sp(SkillGroupKind::General) as f32; / (1.0 - Damage::compute_damage_reduction(Some(inventory), Some(stats))).max(0.00001);
let combined_rating = (offensive_rating * offensive_weighting
+ defensive_rating * defensive_weighting) // Assumes a standard person has earned 20 skill points in the general skill
/ (offensive_weighting + defensive_weighting); // tree Assumes a standard person has earned 10 skill points for the weapon
// skill tree
let skills_rating = (stats.skill_set.earned_sp(SkillGroupKind::General) as f32 / 20.0
+ weapon_skills(inventory, stats) / 10.0)
/ 2.0;
let weapon_rating = get_weapon_rating(inventory, msm);
let combined_rating = (health_rating * HEALTH_WEIGHT
+ skills_rating * SKILLS_WEIGHT
+ weapon_rating * WEAPON_WEIGHT)
/ (HEALTH_WEIGHT + SKILLS_WEIGHT + WEAPON_WEIGHT);
// Body multiplier meant to account for an enemy being harder than equipment and
// skills would account for. It should only not be 1.0 for non-humanoids
combined_rating * body.combat_multiplier() combined_rating * body.combat_multiplier()
} }