feat: added armour passives

This commit is contained in:
TotallyNot 2025-11-04 13:04:56 +01:00
parent cfe2631578
commit 451efd2bb7
Signed by: pyrite
GPG key ID: 7F1BA9170CD35D15
17 changed files with 654 additions and 318 deletions

View file

@ -1,27 +1,55 @@
use std::collections::HashMap;
use bevy_ecs::prelude::*;
use proxisim_models::bundle::armour::{
ArmourBodyPart, ArmourBodyPartSlot, ArmourBodyParts, ArmourCoverage, ArmourValue, ArmourVec,
BodyPartCoverage, Immunities, Immunity, PlayerArmour,
use proxisim_models::bundle::{
armour::{
ArmourBodyPart, ArmourBodyPartSlot, ArmourBodyParts, ArmourCoverage, ArmourValue,
ArmourVec, BodyPartCoverage, Immunities, Immunity, PlayerArmour,
},
bonus::{ArmourBonusType, DamageMitigationBonus},
stat::{
AdditiveBonus, ArmourBonusValue, Defence, Dexterity, MaxHealth, SimpleStatBonus,
SimpleStatEffective,
},
};
use strum::IntoEnumIterator;
use crate::{
Stages,
effect::Effects,
player::status_effect::{
ConcussionGrenade, FlashGrenade, PepperSpray, TearGas, TempDebuffImmunity,
},
};
fn generate_body_parts(
fn equip_armour(
equip_q: Query<(Entity, &PlayerArmour)>,
armour_q: Query<(Entity, &ArmourCoverage, &ArmourValue, Option<&Immunities>)>,
armour_q: Query<(
Entity,
&ArmourCoverage,
&ArmourValue,
Option<&Immunities>,
Option<&ArmourBonusType>,
)>,
mut commands: Commands,
mut effects: Effects,
) {
for (player, equipped_armour) in equip_q.iter() {
let mut parts = ArmourVec::<ArmourBodyPart>::default();
for (armour, coverage, armour_value, immunities) in armour_q.iter_many(equipped_armour) {
// commands.entity(player).add_child(armour);
let mut set = Some(None);
for (armour, coverage, armour_value, immunities, bonus) in
armour_q.iter_many(equipped_armour)
{
if let Some(kind) = &mut set
&& let Some(bonus) = bonus
&& kind.is_none_or(|k| k == *bonus)
{
set = Some(Some(*bonus));
} else {
set = None
}
if let Some(immunities) = immunities {
let mut player = commands.entity(player);
@ -62,6 +90,28 @@ fn generate_body_parts(
}
}
if let Some(Some(set)) = set {
for piece in equipped_armour {
effects.spawn(
SimpleStatBonus::<ArmourBonusValue>::new(
"set bonus",
match set {
ArmourBonusType::Impregnable => 10,
ArmourBonusType::Impenetrable => 10,
ArmourBonusType::Insurmountable => 15,
ArmourBonusType::Invulnerable => 15,
ArmourBonusType::Imperviable => 1,
ArmourBonusType::Immmutable => 5,
ArmourBonusType::Irrepressible => 5,
ArmourBonusType::Impassable => 10,
ArmourBonusType::Kinetokinesis => 0,
},
),
piece,
);
}
}
let parts = parts.0.map(|p| commands.spawn(p).id());
commands
@ -71,6 +121,82 @@ fn generate_body_parts(
}
}
pub(crate) fn configure(stages: &mut Stages) {
stages.equip.add_systems(generate_body_parts);
fn apply_passives(
bonus_q: Query<(
Entity,
&ArmourBonusType,
&SimpleStatEffective<ArmourBonusValue>,
&ChildOf,
)>,
mut effects: Effects,
mut commands: Commands,
) {
let mut max_health_increase = HashMap::<Entity, u16>::new();
for (armour, kind, value, relation) in bonus_q {
match kind {
ArmourBonusType::Imperviable => {
*max_health_increase.entry(relation.parent()).or_default() += value.value;
}
ArmourBonusType::Immmutable => {
effects.spawn(
AdditiveBonus::<Defence>::new("immutable", value.value as f32 / 100.0),
relation.parent(),
);
}
ArmourBonusType::Irrepressible => {
effects.spawn(
AdditiveBonus::<Dexterity>::new("irrepressible", value.value as f32 / 100.0),
relation.parent(),
);
}
ArmourBonusType::Impregnable => {
commands
.entity(armour)
.insert(DamageMitigationBonus::Impregnable {
mitigation: value.value as f32 / 100.0,
});
}
ArmourBonusType::Impenetrable => {
commands
.entity(armour)
.insert(DamageMitigationBonus::Impenetrable {
mitigation: value.value as f32 / 100.0,
});
}
ArmourBonusType::Insurmountable => {
commands
.entity(armour)
.insert(DamageMitigationBonus::Insurmountable {
mitigation: value.value as f32 / 100.0,
});
}
ArmourBonusType::Impassable => {
commands
.entity(armour)
.insert(DamageMitigationBonus::Impassable {
chance: value.value as f32 / 100.0,
});
}
ArmourBonusType::Kinetokinesis => {
commands
.entity(armour)
.insert(DamageMitigationBonus::Kinetokinesis {
mitigation: value.value as f32 / 100.0,
});
}
_ => (),
}
}
for (target, increase) in max_health_increase {
effects.spawn(
SimpleStatBonus::<MaxHealth>::new("marauder", (increase as f32) * 0.01 + 1.0),
target,
);
}
}
pub(crate) fn configure(stages: &mut Stages) {
stages.equip.add_systems(equip_armour);
stages.passives.add_systems(apply_passives);
}

View file

@ -10,10 +10,9 @@
"strategy": {
"type": "in_order",
"order": [
"temporary",
"primary"
"secondary"
],
"reload": true
"reload": false
},
"education": {
"bio2350": true,
@ -86,55 +85,47 @@
"side_effects": 10
},
"weapons": {
"primary": {
"id": 488,
"name": "MP 40",
"kind": "primary",
"cat": "smg",
"base_dmg": 37,
"base_acc": 41,
"dmg": 5,
"acc": 41,
"primary": null,
"secondary": {
"id": 490,
"name": "Blunderbuss",
"kind": "secondary",
"cat": "shotgun",
"base_dmg": 46,
"base_acc": 24,
"dmg": 46,
"acc": 24,
"ammo": {
"clip_size": 32,
"clip_size": 1,
"rate_of_fire": [
3,
5
1,
1
]
},
"mods": [
"high_capacity_mags",
null,
null
],
"bonuses": [
{
"bonus": "specialist",
"value": 10
"bonus": "bleed",
"value": 100
},
null
],
"compatible_mods": [
"reflex_sight",
"holographic_sight",
"acog_sight",
"thermal_sight",
"laser1mw",
"laser5mw",
"laser30mw",
"laser100mw",
"small_suppressor",
"standard_suppressor",
"large_suppressor",
"extended_mags",
"high_capacity_mags",
"extra_clip",
"extra_clip2",
"adjustable_trigger",
"hair_trigger",
"custom_grip",
"standard_brake",
"heavy_duty_brake",
"tactical_brake",
"skeet_choke",
"improved_choke",
"full_choke",
"small_light",
"precision_light",
"tactical_illuminator"
@ -142,36 +133,138 @@
"experience": 0,
"japanese": false
},
"secondary": null,
"melee": null,
"temporary": {
"id": 464,
"name": "Melatonin",
"kind": "temporary",
"cat": "temporary",
"base_dmg": 0,
"base_acc": 0,
"dmg": 0,
"acc": 0,
"ammo": null,
"mods": [
null,
null
],
"bonuses": [
null,
null
],
"compatible_mods": [],
"experience": 0,
"japanese": false
}
"temporary": null
},
"armour": {
"helmet": null,
"body": null,
"pants": null,
"gloves": null,
"boots": null
"helmet": {
"slot": "head",
"id": 1355,
"name": "Vanguard Respirator",
"base_armour": 48,
"armour": 48,
"coverage": {
"body": 2.819999933242798,
"heart": 0,
"stomach": 0,
"chest": 0,
"arm": 0,
"groin": 0,
"leg": 0,
"throat": 0,
"hand": 0,
"foot": 0,
"head": 39.599998474121094
},
"immunities": [
"pepper_spray",
"nerve_gas",
"tear_gas"
],
"bonus": {
"kind": "irrepressible",
"value": null
}
},
"body": {
"slot": "body",
"id": 1356,
"name": "Vanguard Body",
"base_armour": 48,
"armour": 48,
"coverage": {
"body": 44.279998779296875,
"heart": 100,
"stomach": 100,
"chest": 100,
"arm": 100,
"groin": 35.38999938964844,
"leg": 0.2800000011920929,
"throat": 83.52999877929688,
"hand": 0.12999999523162842,
"foot": 0,
"head": 0
},
"immunities": [],
"bonus": {
"kind": "irrepressible",
"value": null
}
},
"pants": {
"slot": "legs",
"id": 1357,
"name": "Vanguard Pants",
"base_armour": 48,
"armour": 48,
"coverage": {
"body": 24.959999084472656,
"heart": 0,
"stomach": 0,
"chest": 0,
"arm": 0,
"groin": 99.06999969482422,
"leg": 100,
"throat": 0,
"hand": 0,
"foot": 25.200000762939453,
"head": 0
},
"immunities": [],
"bonus": {
"kind": "irrepressible",
"value": null
}
},
"gloves": {
"slot": "hands",
"id": 1359,
"name": "Vanguard Gloves",
"base_armour": 48,
"armour": 48,
"coverage": {
"body": 14.399999618530273,
"heart": 0,
"stomach": 0,
"chest": 0,
"arm": 0.7300000190734863,
"groin": 0,
"leg": 0,
"throat": 0,
"hand": 100,
"foot": 0,
"head": 0
},
"immunities": [],
"bonus": {
"kind": "irrepressible",
"value": null
}
},
"boots": {
"slot": "feet",
"id": 1358,
"name": "Vanguard Boots",
"base_armour": 48,
"armour": 48,
"coverage": {
"body": 15.130000114440918,
"heart": 0,
"stomach": 0,
"chest": 0,
"arm": 0,
"groin": 0,
"leg": 5.829999923706055,
"throat": 0,
"hand": 0,
"foot": 100,
"head": 0
},
"immunities": [],
"bonus": {
"kind": "irrepressible",
"value": null
}
}
}
}

View file

@ -4,6 +4,7 @@ use bevy_ecs::prelude::*;
use proxisim_models::{
bundle::{
Id, Name,
armour::Armour,
player::{Attacker, Player},
weapon::Weapon,
},
@ -18,6 +19,7 @@ pub struct EntityRegistry(pub HashMap<Entity, EntityInfo>);
fn read_entities(
player_q: Query<(Entity, &Name, &Id, Has<Attacker>), With<Player>>,
weapon_q: Query<(Entity, &ChildOf, &Name, &Id), With<Weapon>>,
armour_q: Query<(Entity, &ChildOf, &Name, &Id), With<Armour>>,
mut registry: ResMut<EntityRegistry>,
) {
for (player, name, id, is_attacker) in player_q.iter() {
@ -42,6 +44,18 @@ fn read_entities(
},
);
}
for (weapon, player, name, id) in armour_q.iter() {
let (_, _, player_id, _) = player_q.get(player.parent()).unwrap();
registry.0.insert(
weapon,
EntityInfo::Armour {
name: name.0.clone(),
owner: player_id.0,
id: id.0,
},
);
}
}
pub(crate) fn configure(stages: &mut Stages) {

View file

@ -1,7 +1,7 @@
#![warn(clippy::perf, clippy::style, clippy::all)]
#![allow(clippy::type_complexity)]
use bevy_ecs::{message::MessageRegistry, prelude::*, schedule::ScheduleLabel};
use effect::{register_effect, EffectBuilder};
use effect::{EffectBuilder, register_effect};
use metrics::Metrics;
use proxisim_models::{
bundle::player::{Attacker, Current, Defender},
@ -53,6 +53,7 @@ enum FightStatus {
enum Stage {
Equip,
Snapshot,
Passives,
PreFight,
PreTurn,
Turn,
@ -64,6 +65,7 @@ enum Stage {
struct Stages {
equip: Schedule,
snapshot: Schedule,
passives: Schedule,
pre_fight: Schedule,
pre_turn: Schedule,
turn: Schedule,
@ -102,6 +104,7 @@ impl Simulation {
let mut stages = Stages {
equip: Schedule::new(Stage::Equip),
snapshot: Schedule::new(Stage::Snapshot),
passives: Schedule::new(Stage::Passives),
pre_fight: Schedule::new(Stage::PreFight),
pre_turn: Schedule::new(Stage::PreTurn),
turn: Schedule::new(Stage::Turn),
@ -134,8 +137,10 @@ impl Simulation {
defender.spawn(&mut stages.world).insert(Defender);
stages.equip.run(&mut stages.world);
stages.pre_fight.run(&mut stages.world);
effect::run_effects(&mut stages.world);
stages.passives.run(&mut stages.world);
effect::run_effects(&mut stages.world);
stages.pre_fight.run(&mut stages.world);
stages.snapshot.run(&mut stages.world);
Self(stages)

View file

@ -3,9 +3,10 @@ use std::sync::Mutex;
use bevy_ecs::{prelude::*, query::QuerySingleError, system::SystemParam};
use proxisim_models::bundle::{
stat::{
AdditiveBonus, BaselineStat, ClipSize, Clips, CritRate, DamageBonus, Defence, Dexterity,
EffectiveStat, MultiplicativeBonus, SimpleStatBaseline, SimpleStatBonus,
SimpleStatEffective, SimpleStatMarker, Speed, StatMarker, Strength, WeaponAccuracy,
AdditiveBonus, ArmourBonusValue, BaselineStat, ClipSize, Clips, CritRate, DamageBonus,
Defence, Dexterity, EffectiveStat, MultiplicativeBonus, SimpleStatBaseline,
SimpleStatBonus, SimpleStatEffective, SimpleStatMarker, Speed, StatMarker, Strength,
WeaponAccuracy,
},
weapon::WeaponVerb,
};
@ -124,7 +125,12 @@ where
V: Into<LogValue>,
{
fn from(value: Vec<(&'static str, V)>) -> Self {
LogValue::Map(value.into_iter().map(|(k, v)| (k, v.into())).collect())
LogValue::Array(
value
.into_iter()
.map(|(k, v)| LogValue::Array(vec![LogValue::String(k.to_string()), v.into()]))
.collect(),
)
}
}
@ -256,182 +262,6 @@ impl std::fmt::Display for Log {
}
}
/* impl std::fmt::Display for Log {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
for entry in &self.entries {
match entry {
LogEntry::Hit {
actor,
recipient,
weapon,
dmg,
rounds,
crit,
part,
} => {
let actor_info = self.player_registry.get(actor).unwrap();
let recipient_info = self.player_registry.get(recipient).unwrap();
let weapon_info = self.weapon_registry.get(weapon).unwrap();
write!(f, "{} ", actor_info.name)?;
match weapon_info.verb {
WeaponVerb::Fired => {
write!(
f,
"fired {} rounds from of their {} ",
rounds.unwrap(),
weapon_info.name
)?;
if *crit {
write!(f, "critically ")?;
}
writeln!(
f,
"hitting {} in the {} for {}",
recipient_info.name, part, dmg
)?;
}
WeaponVerb::Hit => {
if *crit {
write!(f, "critically ")?;
}
// TODO: Pronouns and weapon verbs
writeln!(
f,
"hit {} with their {} in the {} for {}",
recipient_info.name, weapon_info.name, part, dmg
)?;
}
WeaponVerb::Exploded => {
writeln!(
f,
"{} threw a {} at {}, it exploded for {}",
actor_info.name, weapon_info.name, recipient_info.name, dmg
)?;
}
_ => todo!(),
}
}
LogEntry::Miss {
actor,
recipient,
weapon,
rounds,
} => {
let actor_info = self.player_registry.get(actor).unwrap();
let recipient_info = self.player_registry.get(recipient).unwrap();
let weapon_info = self.weapon_registry.get(weapon).unwrap();
match weapon_info.verb {
WeaponVerb::Hit => {
writeln!(
f,
"{} missed {} with their {}",
actor_info.name, recipient_info.name, weapon_info.name
)?;
}
WeaponVerb::Fired => {
writeln!(
f,
"{} fired {} rounds of their {} missing {}",
actor_info.name,
rounds.unwrap(),
weapon_info.name,
recipient_info.name
)?;
}
_ => todo!(),
}
}
LogEntry::Defeat { actor, recipient } => {
let actor_info = self.player_registry.get(actor).unwrap();
let recipient_info = self.player_registry.get(recipient).unwrap();
writeln!(f, "{} defeated {}", actor_info.name, recipient_info.name)?;
}
LogEntry::Stalemate { actor, recipient } => {
let actor_info = self.player_registry.get(actor).unwrap();
let recipient_info = self.player_registry.get(recipient).unwrap();
writeln!(
f,
"{} stalemated against {}",
actor_info.name, recipient_info.name
)?;
}
LogEntry::Loss { actor, recipient } => {
let actor_info = self.player_registry.get(actor).unwrap();
let recipient_info = self.player_registry.get(recipient).unwrap();
writeln!(
f,
"{} lost against {}",
recipient_info.name, actor_info.name
)?;
}
LogEntry::Reload { actor, weapon } => {
let actor_info = self.player_registry.get(actor).unwrap();
let weapon_info = self.weapon_registry.get(weapon).unwrap();
writeln!(f, "{} reloaded their {}", actor_info.name, weapon_info.name)?;
}
LogEntry::UsedDebuffTemp {
actor,
recipient,
temp,
weapon,
immune,
} => {
let actor_info = self.player_registry.get(actor).unwrap();
let recipient_info = self.player_registry.get(recipient).unwrap();
let weapon_info = self.weapon_registry.get(weapon).unwrap();
match temp {
DebuffingTemp::SmokeGrenade => {
write!(
f,
"{} threw a Smoke Grenade, smoke clouds around {}",
actor_info.name, recipient_info.name
)?;
}
DebuffingTemp::TearGas => {
write!(
f,
"{} threw a Tear Gas Grenade near {}",
actor_info.name, recipient_info.name
)?;
}
DebuffingTemp::PepperSpray => {
write!(
f,
"{} sprayed Pepper Spray in {}'s face",
actor_info.name, recipient_info.name
)?;
}
_ => {
write!(
f,
"{} threw a {} at {}",
actor_info.name, recipient_info.name, weapon_info.name
)?;
}
}
if *immune {
writeln!(f, " but it was ineffective")?;
} else {
writeln!(f)?;
}
}
}
}
Ok(())
}
} */
#[derive(SystemParam)]
pub struct Logger<'w> {
event_writer: MessageWriter<'w, LogEvent>,
@ -603,6 +433,7 @@ pub(crate) fn configure(stages: &mut Stages) {
log_simple_stat_changes::<DamageBonus>,
log_simple_stat_changes::<Clips>,
log_simple_stat_changes::<ClipSize>,
log_simple_stat_changes::<ArmourBonusValue>,
)
.run_if(logging_enabled),
);

View file

@ -1,10 +1,12 @@
use bevy_ecs::prelude::*;
use proxisim_models::bundle::{
passive::{DrugCooldown, Education, FactionUpgrades, Merits},
stat::{AdditiveBonus, CritRate, Defence, Dexterity, SimpleStatBonus, Speed, Strength},
stat::{
AdditiveBonus, CritRate, Defence, Dexterity, MaxHealth, SimpleStatBonus, Speed, Strength,
},
};
use crate::{effect::Effects, Stages};
use crate::{Stages, effect::Effects};
fn spawn_permanent_effects(
merit_q: Query<(
@ -50,6 +52,12 @@ fn spawn_permanent_effects(
player,
);
}
if merits.life > 0 {
effects.spawn(
SimpleStatBonus::<MaxHealth>::new("merits", (merits.life as f32) * 0.05 + 1.0),
player,
);
}
if faction.spd > 0 {
effects.spawn(
@ -75,6 +83,12 @@ fn spawn_permanent_effects(
player,
);
}
if faction.life > 0 {
effects.spawn(
SimpleStatBonus::<MaxHealth>::new("faction", (faction.life as f32) * 0.01 + 1.0),
player,
);
}
#[allow(clippy::too_many_arguments)]
fn spawn_drug_bonuses(

View file

@ -1,14 +1,14 @@
use bevy_ecs::prelude::*;
use proxisim_models::bundle::{
armour::{ArmourBodyPart, ArmourBodyParts},
passive::{FactionUpgrades, Merits},
bonus::DamageMitigationBonus,
player::{
Attacker, BodyPart, ChooseWeapon, CombatTurns, Current, CurrentTarget, Defeated, Defender,
FightEndType, Level, MaxHealth, PartDamageBonus, Player, PlayerStrategy, Weapons,
FightEndType, Health, PartDamageBonus, Player, PlayerStrategy, Weapons,
},
stat::{
AmmoControl, Clips, CritRate, DamageBonus, Defence, Dexterity, EffectiveStat, Health,
SimpleStatBundle, SimpleStatEffective, Speed, Strength, WeaponAccuracy,
AmmoControl, Clips, CritRate, DamageBonus, Defence, Dexterity, EffectiveStat, MaxHealth,
SimpleStatEffective, Speed, Strength, WeaponAccuracy,
},
weapon::{
Ammo, DamageStat, NeedsReload, NonTargeted, RateOfFire, Usable, Uses, Weapon, WeaponSlot,
@ -22,6 +22,7 @@ use crate::{
log,
log::Logger,
metrics::Metrics,
player::status_effect::{Bleed, DamageOverTime, DamageOverTimeType, DeferredDamage},
weapon::{DamageProcEffect, TurnTriggeredEffect, bonus::MultiTurnBonus},
};
@ -52,28 +53,6 @@ fn select_weapon<'a>(
}
}
fn derive_max_health(
level_query: Query<(Entity, &Level, &Merits, &FactionUpgrades)>,
mut cmd: Commands,
) {
for (entity, level, merits, faction) in level_query.iter() {
let base_life = match level.0 {
1..=8 => 100 + (level.0 - 1) * 25,
9..=95 => 275 + (level.0 - 8) * 50,
96.. => 4625 + (level.0 - 95) * 75,
0 => unreachable!(),
};
let max_health =
((base_life as f32) * (1.0 + ((merits.life * 5 + faction.life) as f32) / 100.0)) as u16;
cmd.entity(entity).insert((
MaxHealth(max_health),
SimpleStatBundle::<Health>::new(max_health),
));
}
}
fn designate_first(
attacker_q: Query<Entity, With<Attacker>>,
defender_q: Query<Entity, With<Defender>>,
@ -179,11 +158,12 @@ pub fn use_damaging_weapon(
&SimpleStatEffective<DamageBonus>,
&SimpleStatEffective<CritRate>,
&Children,
&WeaponSlot,
Has<NonTargeted>,
),
(With<Weapon>, With<Current>, Without<NeedsReload>),
>,
player_q: Query<
mut player_q: Query<
(
Entity,
&EffectiveStat<Speed>,
@ -191,6 +171,8 @@ pub fn use_damaging_weapon(
&SimpleStatEffective<CritRate>,
&SimpleStatEffective<WeaponAccuracy>,
&SimpleStatEffective<DamageBonus>,
&Children,
&mut Health,
Has<Attacker>,
),
(With<Player>, With<Current>),
@ -200,12 +182,17 @@ pub fn use_damaging_weapon(
Entity,
&EffectiveStat<Dexterity>,
&EffectiveStat<Defence>,
&SimpleStatEffective<MaxHealth>,
&ArmourBodyParts,
&mut SimpleStatEffective<Health>,
&mut Health,
),
With<CurrentTarget>,
(With<CurrentTarget>, Without<Current>),
>,
armour_q: Query<&ArmourBodyPart>,
(armour_q, damage_q, mut mitigation_q): (
Query<&ArmourBodyPart>,
Query<(Entity, &DeferredDamage)>,
Query<Option<&mut DamageMitigationBonus>>,
),
(damage_proc_q, part_bonus_q): (Query<&DamageProcEffect>, Query<&PartDamageBonus>),
(mut ammo_q, mut temp_q): (
Query<(
@ -224,13 +211,52 @@ pub fn use_damaging_weapon(
Effects,
),
) {
let Ok((weapon, w_dmg, acc, dmg_bonus, crit, children, non_targeted)) = weapon_q.single()
let Ok((weapon, w_dmg, acc, dmg_bonus, crit, children, slot, non_targeted)) = weapon_q.single()
else {
return;
};
let (player, player_spd, player_str, player_crit, acc_bonus, p_dmg_bonus, attacker) =
player_q.single().unwrap();
let (target, target_dex, target_def, armour_parts, mut health) = target_q.single_mut().unwrap();
let (
player,
player_spd,
player_str,
player_crit,
acc_bonus,
p_dmg_bonus,
p_children,
mut p_health,
attacker,
) = player_q.single_mut().unwrap();
let (target, target_dex, target_def, target_max_health, armour_parts, mut health) =
target_q.single_mut().unwrap();
for (instance, damage) in damage_q.iter_many(p_children) {
let health_before = p_health.0;
p_health.0 = p_health.0.saturating_sub(damage.amount);
log!(logger, "deferred_damage", {
health_before: health_before,
health_after: p_health.0,
amount: damage.amount,
label: damage.label,
target: player,
});
commands.entity(instance).despawn();
if p_health.0 == 0 {
log!(logger, "fight_end", {
actor: target,
recipient: player,
fight_end_type: %if attacker {
FightEndType::Loss
} else {
FightEndType::Victory
},
});
metrics.increment_counter(Some(target), "victory", 1);
return;
}
}
if let Ok(mut uses) = temp_q.get_mut(weapon) {
uses.0 -= 1;
@ -253,7 +279,7 @@ pub fn use_damaging_weapon(
.ok()
.map(|(ammo, clips, rof, ammo_ctrl)| {
let ammo_ctrl = 1.0 - (ammo_ctrl).value;
let rof_eff = ((rof.0[0] as f32) * ammo_ctrl)..((rof.0[1] as f32) * ammo_ctrl);
let rof_eff = ((rof.0[0] as f32) * ammo_ctrl)..=((rof.0[1] as f32) * ammo_ctrl);
(ammo, clips, rof_eff)
});
@ -358,6 +384,68 @@ pub fn use_damaging_weapon(
}
}
let bonus_mitigation = match piece {
Some(piece) => {
if let Some(mut mitigation) = mitigation_q.get_mut(piece.armour).unwrap() {
match mitigation.as_mut() {
DamageMitigationBonus::Impregnable { mitigation }
if *slot == WeaponSlot::Melee =>
{
*mitigation
}
DamageMitigationBonus::Impenetrable { mitigation }
if rounds.is_some() =>
{
*mitigation
}
DamageMitigationBonus::Insurmountable { mitigation } => {
if health.0 as f32 / target_max_health.value as f32 <= 0.25 {
*mitigation
} else {
0.0
}
}
DamageMitigationBonus::Impassable { chance } => {
if *chance >= 1.0 || rng.random_bool(*chance as f64) {
1.0
} else {
0.0
}
}
DamageMitigationBonus::Kinetokinesis { mitigation } => {
commands.entity(piece.armour).insert(
DamageMitigationBonus::ActiveKinetokinesis {
mitigation: *mitigation,
remaining_turns: 10,
},
);
0.0
}
DamageMitigationBonus::ActiveKinetokinesis {
mitigation,
remaining_turns,
} => {
*remaining_turns -= 1;
if *remaining_turns == 0 {
commands.entity(piece.armour).insert(
DamageMitigationBonus::Kinetokinesis {
mitigation: *mitigation,
},
);
}
*mitigation
}
_ => 0.0,
}
} else {
0.0
}
}
None => 0.0,
};
// TODO: special ammo
let dmg = dmg_intrinsic
@ -365,6 +453,7 @@ pub fn use_damaging_weapon(
* (1.0 + dmg_bonus.value)
* (1.0 - armour_mitigation)
* (1.0 - def_mitigation)
* (1.0 - bonus_mitigation)
* mult
* dmg_spread;
let dmg = dmg.round() as u32;
@ -414,13 +503,25 @@ pub fn use_damaging_weapon(
bonus.spawn(target, &mut effects, &mut rng.0);
}
}
DamageProcEffect::DamageOverTimer { value, kind } => {
let chance = (value / 100.0) as f64;
if chance > 1.0 || rng.random_bool(chance) {
match kind {
DamageOverTimeType::Bleed => {
commands
.entity(target)
.insert(DamageOverTime::<Bleed>::new(dmg));
}
}
}
}
}
}
}
let health_before = health.value;
let health_before = health.0;
health.value = health.value.saturating_sub(dmg as u16);
health.0 = health.0.saturating_sub(dmg as u16);
log!(logger, "hit_target", {
actor: player,
@ -431,19 +532,20 @@ pub fn use_damaging_weapon(
part_mult: mult,
rounds,
health_before: health_before,
health_after: health.value,
health_after: health.0,
dmg,
dmg_spread,
dmg_intrinsic,
dmg_weapon: w_dmg.0,
armour_mitigation,
def_mitigation,
bonus_mitigation,
bonus_dmg: dmg_bonus.value,
hit_chance: hit_chance,
crit_rate: crit.value,
});
if health.value == 0 && !defeated {
if health.0 == 0 && !defeated {
defeated = true;
commands.entity(target).insert(Defeated);
@ -539,12 +641,23 @@ pub fn restore_initial_state(
}
}
fn record_post_fight_stats(
player_q: Query<(Entity, &SimpleStatEffective<Health>)>,
metrics: Res<Metrics>,
) {
fn record_post_fight_stats(player_q: Query<(Entity, &Health)>, metrics: Res<Metrics>) {
for (player, health) in player_q.iter() {
metrics.record_histogram(Some(player), "rem_health", health.value as u32);
metrics.record_histogram(Some(player), "rem_health", health.0 as u32);
}
}
fn restore_health(
health_q: Query<(Entity, &SimpleStatEffective<MaxHealth>)>,
mut commands: Commands,
mut logger: Logger,
) {
for (player, max_health) in health_q {
log!(logger, "initial_health", {
target: player,
max_health: max_health.value,
});
commands.entity(player).insert(Health(max_health.value));
}
}
@ -554,7 +667,7 @@ pub(crate) fn configure(stages: &mut Stages) {
stages.add_event::<ChooseWeapon>();
stages.equip.add_systems(designate_first);
stages.pre_fight.add_systems(derive_max_health);
stages.pre_fight.add_systems(restore_health);
stages.pre_turn.add_systems(pick_action);
stages.turn.add_systems(use_damaging_weapon);
stages

View file

@ -2,8 +2,8 @@ use std::marker::PhantomData;
use bevy_ecs::prelude::*;
use proxisim_models::bundle::stat::{
AdditiveBonus, AdditiveBonuses, AmmoControl, BaselineStat, ClipSize, Clips, CritRate,
DamageBonus, Defence, Dexterity, EffectiveStat, Health, MultiplicativeBonus,
AdditiveBonus, AdditiveBonuses, AmmoControl, ArmourBonusValue, BaselineStat, ClipSize, Clips,
CritRate, DamageBonus, Defence, Dexterity, EffectiveStat, MaxHealth, MultiplicativeBonus,
MultiplicativeBonuses, SimpleStatBonus, SimpleStatEffective, SimpleStatMarker,
SimpleStatSnapshot, Speed, StatMarker, StatSnapshot, Strength, WeaponAccuracy,
};
@ -196,5 +196,6 @@ pub(crate) fn configure(stages: &mut Stages) {
register_simple_stat_effects::<WeaponAccuracy>(stages);
register_simple_stat_effects::<ClipSize>(stages);
register_simple_stat_effects::<Clips>(stages);
register_simple_stat_effects::<Health>(stages);
register_simple_stat_effects::<MaxHealth>(stages);
register_simple_stat_effects::<ArmourBonusValue>(stages);
}

View file

@ -1,8 +1,9 @@
use std::{collections::VecDeque, marker::PhantomData};
use bevy_ecs::prelude::*;
use proxisim_models::bundle::stat::{
AdditiveBonus, Defence, Dexterity, MultiplicativeBonus, Speed, StatMarker, Strength,
use proxisim_models::bundle::{
player::Current,
stat::{AdditiveBonus, Defence, Dexterity, MultiplicativeBonus, Speed, StatMarker, Strength},
};
use rand::Rng as _;
@ -340,6 +341,46 @@ impl AdditiveStatusEffectMarker<2> for Frozen {
}
}
pub trait DamageOverTimeMarker: Send + Sync + 'static {
const INCREMENTS: &[f32];
const LABEL: &str;
}
#[derive(Component)]
pub struct DamageOverTime<Dot: DamageOverTimeMarker> {
marker: PhantomData<Dot>,
pub base_damage: u32,
pub turn: u16,
}
impl<Dot: DamageOverTimeMarker> DamageOverTime<Dot> {
pub fn new(base_damage: u32) -> Self {
Self {
marker: PhantomData,
base_damage,
turn: 0,
}
}
}
#[derive(Component)]
pub struct DeferredDamage {
pub label: &'static str,
pub amount: u16,
}
#[derive(Clone, Copy)]
pub enum DamageOverTimeType {
Bleed,
}
pub struct Bleed;
impl DamageOverTimeMarker for Bleed {
const INCREMENTS: &[f32] = &[0.45, 0.40, 0.35, 0.30, 0.25, 0.20, 0.15, 0.10, 0.05];
const LABEL: &str = "Bleeding";
}
fn apply_additive_status_effect<const N: usize, M: AdditiveStatusEffectMarker<N>>(
In(entities): In<Vec<Entity>>,
effect_q: Query<(Entity, &ChildOf, &AdditiveStatusEffect<N, M>)>,
@ -510,6 +551,34 @@ fn remove_temp_debuff_effect<Temp: DebuffingTempMarker>(
}
}
fn process_dot<Dot: DamageOverTimeMarker>(
dot_q: Query<(Entity, &mut DamageOverTime<Dot>), With<Current>>,
mut commands: Commands,
mut logger: Logger,
) {
for (player, mut dot) in dot_q {
if dot.turn as usize == Dot::INCREMENTS.len() {
commands.entity(player).remove::<DamageOverTime<Dot>>();
} else {
if dot.turn == 0 {
log!(logger, "spawned_dot", {
target: player,
base_damage: dot.base_damage,
label: Dot::LABEL,
});
}
let factor = Dot::INCREMENTS[dot.turn as usize];
let amount = (factor * dot.base_damage as f32) as u16;
commands.entity(player).with_child(DeferredDamage {
amount,
label: Dot::LABEL,
});
}
dot.turn += 1;
}
}
fn register_debuff_temp<Temp: DebuffingTempMarker>(stages: &mut Stages) {
stages
.register_effect::<TempDebuffEffect<Temp>>()
@ -544,4 +613,6 @@ pub(crate) fn configure(stages: &mut Stages) {
register_status_effect::<4, Motivate>(stages);
register_status_effect::<4, Demoralise>(stages);
register_status_effect::<2, Frozen>(stages);
stages.post_turn.add_systems(process_dot::<Bleed>);
}

View file

@ -12,7 +12,8 @@ use crate::{
Stages,
effect::{Effects, TurnLimitedEffect},
player::status_effect::{
AdditiveStatusEffect, Crippled, Demoralise, Frozen, Motivate, Slow, Weakened, Withered,
AdditiveStatusEffect, Crippled, DamageOverTimeType, Demoralise, Frozen, Motivate, Slow,
Weakened, Withered,
},
};
@ -427,6 +428,15 @@ pub(crate) fn prepare_bonuses(
});
}
WeaponBonusType::Bleed => {
commands
.entity(weapon.parent())
.with_child(DamageProcEffect::DamageOverTimer {
value: value.0,
kind: DamageOverTimeType::Bleed,
});
}
val => unimplemented!("{val:?}"),
}
}
@ -434,6 +444,6 @@ pub(crate) fn prepare_bonuses(
pub(crate) fn configure(stages: &mut Stages) {
stages
.pre_fight
.passives
.add_systems(prepare_bonuses.after(super::apply_passives));
}

View file

@ -1,7 +1,7 @@
use bevy_ecs::prelude::*;
use proxisim_models::bundle::{
passive::{Education, EducationPartDamageBonus, FactionUpgrades, Merits},
player::{Current, PartDamageBonus, Weapons},
player::{Current, PartDamageBonus},
stat::{
AdditiveBonus, AmmoControl, ClipSize, Clips, CritRate, DamageBonus, Dexterity,
SimpleStatBonus, SimpleStatEffective, WeaponAccuracy,
@ -17,6 +17,7 @@ use crate::{
effect::{Effects, TurnLimitedEffect},
log,
log::Logger,
player::status_effect::DamageOverTimeType,
};
use self::bonus::{
@ -152,6 +153,10 @@ pub enum DamageProcEffect {
value: f32,
bonus: SelfStatusEffect,
},
DamageOverTimer {
value: f32,
kind: DamageOverTimeType,
},
}
fn apply_passives(
@ -520,7 +525,7 @@ pub(crate) fn configure(stages: &mut Stages) {
// running this in the snapshot layer ensures that the stat increases aren't restored at the
// end of the run
stages.snapshot.add_systems(apply_first_turn_effects);
stages.pre_fight.add_systems(apply_passives);
stages.equip.add_systems(apply_passives);
stages.turn.add_systems(reload_weapon);
stages.post_turn.add_systems(unset_current);
stages