Apply burning buff to entities touching another entity with the burning buff

This commit is contained in:
James Melkonian 2024-02-17 21:56:55 +00:00 committed by crabman
parent 9434b11ae3
commit cc059e2882
3 changed files with 45 additions and 4 deletions

View File

@ -112,6 +112,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Renamed Twiggy Shoulders to match the Twig Armor set - Renamed Twiggy Shoulders to match the Twig Armor set
- No longer stack buffs of the same kind with equal attributes, this could lead to a DoS if ie. an entity stayed long enough in lava. - No longer stack buffs of the same kind with equal attributes, this could lead to a DoS if ie. an entity stayed long enough in lava.
- Nerfed Earthsplitter - Nerfed Earthsplitter
- Burning buff is now contagious
## [0.15.0] - 2023-07-01 ## [0.15.0] - 2023-07-01

View File

@ -765,6 +765,11 @@ pub fn may_harm(
let attacker = owner_if_pet(attacker); let attacker = owner_if_pet(attacker);
let target = owner_if_pet(target); let target = owner_if_pet(target);
// Prevent owners from attacking their pets and vice versa
if attacker == target {
return false;
}
// Get player components // Get player components
let attacker_info = players.get(attacker); let attacker_info = players.get(attacker);
let target_info = players.get(target); let target_info = players.get(target);

View File

@ -1,5 +1,5 @@
use common::{ use common::{
combat::DamageContributor, combat::{self, DamageContributor},
comp::{ comp::{
agent::{Sound, SoundKind}, agent::{Sound, SoundKind},
aura::Auras, aura::Auras,
@ -10,8 +10,8 @@ use common::{
}, },
fluid_dynamics::{Fluid, LiquidKind}, fluid_dynamics::{Fluid, LiquidKind},
item::MaterialStatManifest, item::MaterialStatManifest,
Energy, Group, Health, HealthChange, Inventory, LightEmitter, ModifierKind, PhysicsState, Alignment, Energy, Group, Health, HealthChange, Inventory, LightEmitter, ModifierKind,
Pos, Stats, PhysicsState, Player, Pos, Stats,
}, },
event::{ event::{
BuffEvent, ChangeBodyEvent, CreateSpriteEvent, EmitExt, EnergyChangeEvent, BuffEvent, ChangeBodyEvent, CreateSpriteEvent, EmitExt, EnergyChangeEvent,
@ -64,6 +64,9 @@ pub struct ReadData<'a> {
positions: ReadStorage<'a, Pos>, positions: ReadStorage<'a, Pos>,
bodies: ReadStorage<'a, Body>, bodies: ReadStorage<'a, Body>,
light_emitters: ReadStorage<'a, LightEmitter>, light_emitters: ReadStorage<'a, LightEmitter>,
alignments: ReadStorage<'a, Alignment>,
players: ReadStorage<'a, Player>,
uids: ReadStorage<'a, Uid>,
} }
#[derive(Default)] #[derive(Default)]
@ -147,13 +150,45 @@ impl<'a> System<'a> for Sys {
&read_data.bodies, &read_data.bodies,
&read_data.healths, &read_data.healths,
&read_data.energies, &read_data.energies,
read_data.uids.maybe(),
read_data.physics_states.maybe(), read_data.physics_states.maybe(),
) )
.lend_join(); .lend_join();
buff_join.for_each(|comps| { buff_join.for_each(|comps| {
let (entity, buff_comp, mut stat, body, health, energy, physics_state) = comps; let (entity, buff_comp, mut stat, body, health, energy, uid, physics_state) = comps;
// Apply buffs to entity based off of their current physics_state // Apply buffs to entity based off of their current physics_state
if let Some(physics_state) = physics_state { if let Some(physics_state) = physics_state {
// Set nearby entities on fire if burning
if let Some((_, burning)) = buff_comp.iter_kind(BuffKind::Burning).next() {
for t_entity in physics_state.touch_entities.keys().filter_map(|te_uid| {
read_data.id_maps.uid_entity(*te_uid).filter(|te| {
combat::may_harm(
&read_data.alignments,
&read_data.players,
&read_data.id_maps,
Some(entity),
*te,
)
})
}) {
let duration = burning.data.duration.map(|d| d * 0.9);
if duration.map_or(true, |d| d.0 >= 1.0) {
let source =
uid.map_or(BuffSource::World, |u| BuffSource::Character { by: *u });
emitters.emit(BuffEvent {
entity: t_entity,
buff_change: BuffChange::Add(Buff::new(
BuffKind::Burning,
BuffData::new(burning.data.strength, duration),
vec![BuffCategory::Natural],
source,
*read_data.time,
None,
)),
});
}
}
}
if matches!( if matches!(
physics_state.on_ground.and_then(|b| b.get_sprite()), physics_state.on_ground.and_then(|b| b.get_sprite()),
Some(SpriteKind::EnsnaringVines) | Some(SpriteKind::EnsnaringWeb) Some(SpriteKind::EnsnaringVines) | Some(SpriteKind::EnsnaringWeb)