Skip to content

Commit

Permalink
✨ カスタム補正をその他のステータスに移動して艦娘側に保存されるようにした
Browse files Browse the repository at this point in the history
  • Loading branch information
madonoharu committed Jun 21, 2022
1 parent 96c14d6 commit df840e1
Show file tree
Hide file tree
Showing 22 changed files with 111 additions and 125 deletions.
3 changes: 0 additions & 3 deletions crates/fleethub-core/src/analyzer/fleet_cutin_analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,13 @@ impl<'a> FleetCutinAnalyzer<'a> {
engagement: Engagement,
) -> WarfareContext {
let attacker_env = self.comp.create_warfare_ship_environment(ship, formation);

let target_env = self.target_env.clone();
let custom_mods = Default::default();

WarfareContext {
attacker_env,
target_env,
engagement,
air_state: self.air_state,
custom_mods,
}
}

Expand Down
7 changes: 1 addition & 6 deletions crates/fleethub-core/src/analyzer/warfare_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ use crate::{
TorpedoAttackContext, WarfareContext, WarfareShipEnvironment,
},
ship::Ship,
types::{
AirState, BattleConfig, CustomPowerModifiers, DayCutin, Engagement, Formation, NightCutin,
OrgType, Role,
},
types::{AirState, BattleConfig, DayCutin, Engagement, Formation, NightCutin, OrgType, Role},
};

use super::{AttackInfo, AttackInfoItem, AttackStats, DayCutinRateInfo, NightCutinRateAnalyzer};
Expand All @@ -30,7 +27,6 @@ pub struct WarfareAnalyzerShipEnvironment {
pub formation: Formation,
pub fleet_los_mod: Option<f64>,
pub night_situation: NightSituation,
pub custom_mods: CustomPowerModifiers,
}

impl WarfareAnalyzerShipEnvironment {
Expand Down Expand Up @@ -79,7 +75,6 @@ impl WarfareAnalyzerContext {
target_env: self.target_env.as_warfare_ship_environment(),
engagement: self.engagement,
air_state: self.air_state,
custom_mods: self.attacker_env.custom_mods.clone(),
}
}
}
Expand Down
11 changes: 3 additions & 8 deletions crates/fleethub-core/src/attack/asw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use crate::{
attack::{DefenseParams, HitRateParams},
ship::Ship,
types::{
gear_id, matches_gear_id, AttackPowerModifier, BattleConfig, CustomPowerModifiers,
Engagement, GearAttr, GearType, ShipType,
gear_id, matches_gear_id, AttackPowerModifier, BattleConfig, Engagement, GearAttr,
GearType, ShipType,
},
};

Expand Down Expand Up @@ -54,8 +54,6 @@ pub struct AswAttackContext<'a> {
pub formation_power_mod: f64,
pub formation_accuracy_mod: f64,
pub formation_evasion_mod: f64,

pub custom_mods: &'a CustomPowerModifiers,
}

impl<'a> AswAttackContext<'a> {
Expand All @@ -68,7 +66,6 @@ impl<'a> AswAttackContext<'a> {
let WarfareContext {
attacker_env,
target_env,
custom_mods,
engagement,
..
} = ctx;
Expand All @@ -95,8 +92,6 @@ impl<'a> AswAttackContext<'a> {
formation_power_mod,
formation_accuracy_mod,
formation_evasion_mod,

custom_mods,
}
}

Expand Down Expand Up @@ -159,7 +154,7 @@ impl<'a> AswAttackContext<'a> {
ap_shell_mod: None,
carrier_power: None,
special_enemy_mods: Default::default(),
custom_mods: self.custom_mods.clone(),
custom_mods: attacker.custom_power_mods(),
})
};

Expand Down
3 changes: 1 addition & 2 deletions crates/fleethub-core/src/attack/context.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use serde::{Deserialize, Serialize};
use tsify::Tsify;

use crate::types::{AirState, CustomPowerModifiers, Engagement, Formation, OrgType, Role};
use crate::types::{AirState, Engagement, Formation, OrgType, Role};

#[derive(Debug, Clone, Default, Serialize, Deserialize, Tsify)]
#[tsify(into_wasm_abi, from_wasm_abi)]
Expand Down Expand Up @@ -30,5 +30,4 @@ pub struct WarfareContext {
pub target_env: WarfareShipEnvironment,
pub engagement: Engagement,
pub air_state: AirState,
pub custom_mods: CustomPowerModifiers,
}
9 changes: 3 additions & 6 deletions crates/fleethub-core/src/attack/night.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use crate::{
attack::DefenseParams,
ship::Ship,
types::{
AttackPowerModifier, BattleConfig, ContactRank, CustomPowerModifiers, GearType,
NightAttackType, NightSpecialAttack, ShipType, SpecialAttackDef,
AttackPowerModifier, BattleConfig, ContactRank, GearType, NightAttackType,
NightSpecialAttack, ShipType, SpecialAttackDef,
},
};

Expand Down Expand Up @@ -38,8 +38,6 @@ pub struct NightAttackContext<'a> {
pub formation_accuracy_mod: f64,
pub formation_evasion_mod: f64,

pub custom_mods: &'a CustomPowerModifiers,

pub special_attack_def: Option<SpecialAttackDef<NightSpecialAttack>>,
}

Expand Down Expand Up @@ -68,7 +66,6 @@ impl<'a> NightAttackContext<'a> {
Self {
attacker_env,
target_env,
custom_mods: &warfare_context.custom_mods,
attacker_situation,
target_situation,
attack_type,
Expand Down Expand Up @@ -188,7 +185,7 @@ fn calc_attack_power_params(
let postcap_mod = Default::default();

let special_enemy_mods = special_enemy_modifiers(attacker, target.special_enemy_type(), false);
let custom_mods = ctx.custom_mods.clone();
let custom_mods = attacker.custom_power_mods();

let base = AttackPowerParams {
cap: NIGHT_POWER_CAP,
Expand Down
8 changes: 3 additions & 5 deletions crates/fleethub-core/src/attack/shelling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use crate::{
attack::{AttackPowerParams, HitRateParams},
ship::Ship,
types::{
AirState, AttackPowerModifier, BattleConfig, CustomPowerModifiers, Engagement,
ShellingSpecialAttack, SpecialAttackDef,
AirState, AttackPowerModifier, BattleConfig, Engagement, ShellingSpecialAttack,
SpecialAttackDef,
},
};

Expand Down Expand Up @@ -47,7 +47,6 @@ pub struct ShellingAttackContext<'a> {

pub attacker_env: &'a WarfareShipEnvironment,
pub target_env: &'a WarfareShipEnvironment,
pub custom_mods: &'a CustomPowerModifiers,
pub engagement: Engagement,
pub air_state: AirState,

Expand Down Expand Up @@ -91,7 +90,6 @@ impl<'a> ShellingAttackContext<'a> {
attack_type,
attacker_env,
target_env,
custom_mods: &warfare_context.custom_mods,
air_state: warfare_context.air_state,
engagement: warfare_context.engagement,
formation_power_mod,
Expand Down Expand Up @@ -180,7 +178,7 @@ impl<'a> ShellingAttackContext<'a> {
let precap_mod = AttackPowerModifier::new(a14, b14);
let postcap_mod = AttackPowerModifier::new(a11, 0.0);

let custom_mods = self.custom_mods.clone();
let custom_mods = attacker.custom_power_mods();

let params = AttackPowerParams {
basic,
Expand Down
9 changes: 2 additions & 7 deletions crates/fleethub-core/src/attack/shelling_support.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
types::{AttackPowerModifier, BattleConfig, CustomPowerModifiers, Engagement, FormationDef},
types::{AttackPowerModifier, BattleConfig, Engagement, FormationDef},
Ship,
};

Expand All @@ -19,7 +19,6 @@ pub struct ShellingSupportAttackParams<'a> {
pub engagement: Engagement,
pub attacker_formation_def: &'a FormationDef,
pub target_formation_def: &'a FormationDef,
pub custom_mods: CustomPowerModifiers,
pub defense_params: Option<DefenseParams>,
}

Expand All @@ -32,7 +31,6 @@ impl<'a> ShellingSupportAttackParams<'a> {
engagement,
attacker_formation_def,
target_formation_def,
custom_mods,
defense_params,
} = self;

Expand Down Expand Up @@ -97,7 +95,7 @@ impl<'a> ShellingSupportAttackParams<'a> {
remaining_ammo_mod,
armor_penetration: 0.0,
special_enemy_mods,
custom_mods,
custom_mods: attacker.custom_power_mods(),
};

Some(params)
Expand Down Expand Up @@ -161,8 +159,6 @@ impl<'a> ShellingSupportAttackContext<'a> {
let attacker_formation_def = self.config.get_formation_def_by_env(attacker_env);
let target_formation_def = self.config.get_formation_def_by_env(target_env);

let custom_mods = self.warfare_context.custom_mods.clone();

let armor_penetration = 0.0;
let defense_params =
DefenseParams::from_target(target, target_env.org_type.side(), armor_penetration);
Expand All @@ -174,7 +170,6 @@ impl<'a> ShellingSupportAttackContext<'a> {
engagement: self.warfare_context.engagement,
attacker_formation_def,
target_formation_def,
custom_mods,
defense_params,
}
}
Expand Down
6 changes: 2 additions & 4 deletions crates/fleethub-core/src/attack/torpedo.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
ship::Ship,
types::{AirState, AttackPowerModifier, BattleConfig, CustomPowerModifiers, Engagement},
types::{AirState, AttackPowerModifier, BattleConfig, Engagement},
};

use super::{
Expand All @@ -15,7 +15,6 @@ const TORPEDO_CRITICAL_RATE_CONSTANT: f64 = 1.5;
pub struct TorpedoAttackContext<'a> {
pub attacker_env: &'a WarfareShipEnvironment,
pub target_env: &'a WarfareShipEnvironment,
pub custom_mods: &'a CustomPowerModifiers,
pub engagement: Engagement,
pub air_state: AirState,

Expand All @@ -39,7 +38,6 @@ impl<'a> TorpedoAttackContext<'a> {
Self {
attacker_env,
target_env,
custom_mods: &warfare_context.custom_mods,
air_state: warfare_context.air_state,
engagement: warfare_context.engagement,
formation_power_mod,
Expand Down Expand Up @@ -71,7 +69,7 @@ impl<'a> TorpedoAttackContext<'a> {
proficiency_critical_mod: None,
armor_penetration: 0.0,
special_enemy_mods: Default::default(),
custom_mods: self.custom_mods.clone(),
custom_mods: attacker.custom_power_mods(),
})
}

Expand Down
8 changes: 6 additions & 2 deletions crates/fleethub-core/src/ship.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ use crate::{
plane::{Plane, PlaneImpl, PlaneMut},
types::{
ctype, gear_id, matches_gear_id, matches_ship_id, ship_id, AirStateRank, AirWaveType,
DamageState, DayCutin, EBonuses, GearAttr, GearType, MoraleState, ShipAttr, ShipCategory,
ShipMeta, ShipState, ShipType, SlotSizeVec, SpecialEnemyType,
CustomPowerModifiers, DamageState, DayCutin, EBonuses, GearAttr, GearType, MoraleState,
ShipAttr, ShipCategory, ShipMeta, ShipState, ShipType, SlotSizeVec, SpecialEnemyType,
},
utils::xxh3,
};
Expand Down Expand Up @@ -905,6 +905,10 @@ impl Ship {
self.state.clone()
}

pub fn custom_power_mods(&self) -> CustomPowerModifiers {
self.state.custom_power_mods.clone()
}

pub fn meta(&self) -> ShipMeta {
ShipMeta {
id: self.id.clone(),
Expand Down
7 changes: 1 addition & 6 deletions crates/fleethub-core/src/simulator/shelling_support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
comp::Comp,
fleet::Fleet,
ship::Ship,
types::{BattleConfig, CustomPowerModifiers, Engagement, Formation, FormationDef, Side},
types::{BattleConfig, Engagement, Formation, FormationDef, Side},
};

use super::{BattleLogger, SimulatorResult};
Expand Down Expand Up @@ -88,7 +88,6 @@ pub struct ShellingSupportSimulatorParams {
attacker_formation: Formation,
target_formation: Formation,
engagement: Engagement,
custom_mods: CustomPowerModifiers,
}

struct ShellingSupportBattle<'a, R>
Expand All @@ -101,7 +100,6 @@ where
engagement: Engagement,
attacker_formation_def: &'a FormationDef,
target_formation_def: &'a FormationDef,
custom_mods: CustomPowerModifiers,
}

impl<'a, R> ShellingSupportBattle<'a, R>
Expand Down Expand Up @@ -134,7 +132,6 @@ where
attacker_formation_def: &self.attacker_formation_def,
target_formation_def: &self.target_formation_def,
engagement: self.engagement,
custom_mods: self.custom_mods.clone(),
defense_params,
}
.into_attack_params()
Expand Down Expand Up @@ -179,7 +176,6 @@ where
attacker_formation,
target_formation,
engagement,
custom_mods,
} = params;

let attacker_formation_def = config.get_formation_def(attacker_formation, 6, 0);
Expand All @@ -193,7 +189,6 @@ where
engagement,
attacker_formation_def,
target_formation_def,
custom_mods,
},
}
}
Expand Down
6 changes: 3 additions & 3 deletions crates/fleethub-core/src/types/attack_power_modifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use serde::{Deserialize, Serialize};
use tsify::Tsify;

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Tsify)]
#[serde(default)]
pub struct AttackPowerModifier {
pub a: f64,
pub b: f64,
Expand Down Expand Up @@ -77,11 +78,10 @@ impl SpecialEnemyModifiers {
}

#[derive(Debug, Default, Clone, Hash, Serialize, Deserialize, Tsify)]
#[tsify(into_wasm_abi)]
#[serde(default)]
pub struct CustomPowerModifiers {
#[serde(default)]
pub precap_mod: AttackPowerModifier,
#[serde(default)]
pub postcap_mod: AttackPowerModifier,
#[serde(default)]
pub basic_power_mod: AttackPowerModifier,
}
3 changes: 2 additions & 1 deletion crates/fleethub-core/src/types/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ pub struct ShipState {
#[tsify(type = "number")]
pub night_gunfit_accuracy: Option<OrderedFloat<f64>>,

pub custom_power_mods: Option<CustomPowerModifiers>,
#[serde(default)]
pub custom_power_mods: CustomPowerModifiers,
}

#[derive(Debug, Default, Clone, Hash, Serialize, Deserialize, Tsify)]
Expand Down
Loading

0 comments on commit df840e1

Please sign in to comment.