Fire update (#602)
* fire spread fixes and optimization * fix liquid drops nefty and suffix * some sharedization * melee fire extinguish * clean up fireSpread system * caution popup * cuffable zombies * fix zombie AI * lighter * torch integration attempt * fix torch igniting * yml tweaks * bonus flammable damage
This commit is contained in:
@@ -2,7 +2,11 @@ using System.Linq;
|
||||
using System.Numerics;
|
||||
using Content.Server.Atmos.Components;
|
||||
using Content.Server.Atmos.EntitySystems;
|
||||
using Content.Server.DoAfter;
|
||||
using Content.Shared._CP14.Temperature;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Maps;
|
||||
using Content.Shared.Weapons.Melee.Events;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Map.Components;
|
||||
using Robust.Shared.Prototypes;
|
||||
@@ -11,7 +15,7 @@ using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Server._CP14.Temperature;
|
||||
|
||||
public sealed partial class CP14FireSpreadSystem : EntitySystem
|
||||
public sealed partial class CP14FireSpreadSystem : CP14SharedFireSpreadSystem
|
||||
{
|
||||
[Dependency] private readonly FlammableSystem _flammable = default!;
|
||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||
@@ -20,29 +24,39 @@ public sealed partial class CP14FireSpreadSystem : EntitySystem
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
[Dependency] private readonly SharedMapSystem _mapSystem = default!;
|
||||
[Dependency] private readonly TileSystem _tile = default!;
|
||||
[Dependency] private readonly ITileDefinitionManager _tiledef = default!;
|
||||
[Dependency] private readonly ITileDefinitionManager _tileDef = default!;
|
||||
|
||||
private EntProtoId _fireProto = "CP14Fire";
|
||||
private readonly EntProtoId _fireProto = "CP14Fire";
|
||||
|
||||
private readonly HashSet<Entity<CP14FireSpreadComponent>> _spreadEnts = new();
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SubscribeLocalEvent<CP14FireSpreadComponent, OnFireChangedEvent>(OnCompInit);
|
||||
SubscribeLocalEvent<CP14DespawnOnExtinguishComponent, OnFireChangedEvent>(OnFireChanged);
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<FlammableComponent, CP14IgnitionDoAfter>(OnFlammableIgnited);
|
||||
SubscribeLocalEvent<CP14FlammableBonusDamageComponent, MeleeHitEvent>(OnFlammableMeleeHit);
|
||||
}
|
||||
|
||||
private void OnFireChanged(Entity<CP14DespawnOnExtinguishComponent> ent, ref OnFireChangedEvent args)
|
||||
private void OnFlammableMeleeHit(Entity<CP14FlammableBonusDamageComponent> ent, ref MeleeHitEvent args)
|
||||
{
|
||||
if (!args.OnFire)
|
||||
QueueDel(ent);
|
||||
}
|
||||
|
||||
private void OnCompInit(Entity<CP14FireSpreadComponent> ent, ref OnFireChangedEvent args)
|
||||
{
|
||||
if (!args.OnFire)
|
||||
if (!TryComp<FlammableComponent>(ent, out var flammable))
|
||||
return;
|
||||
|
||||
var cooldown = _random.NextFloat(ent.Comp.SpreadCooldownMin, ent.Comp.SpreadCooldownMax);
|
||||
ent.Comp.NextSpreadTime = _gameTiming.CurTime + TimeSpan.FromSeconds(cooldown);
|
||||
if (!flammable.OnFire)
|
||||
return;
|
||||
|
||||
args.BonusDamage += ent.Comp.DamagePerStack * flammable.FireStacks;
|
||||
}
|
||||
|
||||
private void OnFlammableIgnited(Entity<FlammableComponent> ent, ref CP14IgnitionDoAfter args)
|
||||
{
|
||||
if (args.Cancelled || args.Handled)
|
||||
return;
|
||||
|
||||
_flammable.AdjustFireStacks(ent, ent.Comp.FirestacksOnIgnite, ent.Comp, true);
|
||||
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
@@ -76,9 +90,10 @@ public sealed partial class CP14FireSpreadSystem : EntitySystem
|
||||
|
||||
private void UpdateFireSpread()
|
||||
{
|
||||
List<Entity<CP14FireSpreadComponent>> spreadUids = new();
|
||||
var query = EntityQueryEnumerator<CP14FireSpreadComponent, FlammableComponent, TransformComponent>();
|
||||
while (query.MoveNext(out var uid, out var spread, out var flammable, out var xform))
|
||||
_spreadEnts.Clear();
|
||||
|
||||
var query = EntityQueryEnumerator<CP14ActiveFireSpreadingComponent, CP14FireSpreadComponent, FlammableComponent, TransformComponent>();
|
||||
while (query.MoveNext(out var uid, out _, out var spread, out var flammable, out var xform))
|
||||
{
|
||||
if (!flammable.OnFire)
|
||||
continue;
|
||||
@@ -92,61 +107,57 @@ public sealed partial class CP14FireSpreadSystem : EntitySystem
|
||||
var cooldown = _random.NextFloat(spread.SpreadCooldownMin, spread.SpreadCooldownMax);
|
||||
spread.NextSpreadTime = _gameTiming.CurTime + TimeSpan.FromSeconds(cooldown);
|
||||
|
||||
spreadUids.Add(new Entity<CP14FireSpreadComponent>(uid, spread));
|
||||
_spreadEnts.Add(new Entity<CP14FireSpreadComponent>(uid, spread));
|
||||
}
|
||||
|
||||
foreach (var uid in spreadUids)
|
||||
foreach (var uid in _spreadEnts)
|
||||
{
|
||||
IgniteEntities(uid, uid.Comp);
|
||||
IgniteTiles(uid, uid.Comp);
|
||||
IgniteEntities(uid);
|
||||
IgniteTiles(uid);
|
||||
}
|
||||
}
|
||||
|
||||
private void IgniteEntities(EntityUid uid, CP14FireSpreadComponent spread)
|
||||
private void IgniteEntities(Entity<CP14FireSpreadComponent> spread)
|
||||
{
|
||||
var targets = _lookup.GetEntitiesInRange<FlammableComponent>(_transform.GetMapCoordinates(uid),
|
||||
spread.Radius,
|
||||
var targets = _lookup.GetEntitiesInRange<FlammableComponent>(_transform.GetMapCoordinates(spread),
|
||||
spread.Comp.Radius,
|
||||
LookupFlags.Uncontained);
|
||||
foreach (var target in targets)
|
||||
{
|
||||
if (!_random.Prob(spread.Prob))
|
||||
if (!_random.Prob(spread.Comp.Prob))
|
||||
continue;
|
||||
|
||||
_flammable.Ignite(target, uid);
|
||||
_flammable.Ignite(target, spread);
|
||||
}
|
||||
}
|
||||
|
||||
private void IgniteTiles(EntityUid uid, CP14FireSpreadComponent spread)
|
||||
private void IgniteTiles(Entity<CP14FireSpreadComponent> spread)
|
||||
{
|
||||
var xform = Transform(uid);
|
||||
if (!TryComp<MapGridComponent>(xform.GridUid, out var grid))
|
||||
return;
|
||||
|
||||
var xform = Transform(spread);
|
||||
// Ignore items inside containers
|
||||
if (!HasComp<MapGridComponent>(xform.ParentUid))
|
||||
if (!TryComp<MapGridComponent>(xform.ParentUid, out var grid))
|
||||
return;
|
||||
|
||||
var localPos = xform.Coordinates.Position;
|
||||
var tileRefs = _mapSystem.GetLocalTilesIntersecting(grid.Owner,
|
||||
var tileRefs = _mapSystem.GetLocalTilesIntersecting(xform.ParentUid,
|
||||
grid,
|
||||
new Box2(
|
||||
localPos + new Vector2(-spread.Radius, -spread.Radius),
|
||||
localPos + new Vector2(spread.Radius, spread.Radius)))
|
||||
localPos + new Vector2(-spread.Comp.Radius, -spread.Comp.Radius),
|
||||
localPos + new Vector2(spread.Comp.Radius, spread.Comp.Radius)))
|
||||
.ToList();
|
||||
|
||||
|
||||
foreach (var tileref in tileRefs)
|
||||
foreach (var tileRef in tileRefs)
|
||||
{
|
||||
if (!_random.Prob(spread.ProbTile))
|
||||
if (!_random.Prob(spread.Comp.ProbTile))
|
||||
continue;
|
||||
|
||||
var tile = tileref.Tile.GetContentTileDefinition();
|
||||
var tile = tileRef.Tile.GetContentTileDefinition();
|
||||
|
||||
if (tile.BurnedTile is null)
|
||||
continue;
|
||||
|
||||
Spawn(_fireProto, _mapSystem.ToCenterCoordinates(tileref, grid));
|
||||
_tile.ReplaceTile(tileref, (ContentTileDefinition)_tiledef[tile.BurnedTile]);
|
||||
Spawn(_fireProto, _mapSystem.ToCenterCoordinates(tileRef, grid));
|
||||
_tile.ReplaceTile(tileRef, (ContentTileDefinition)_tileDef[tile.BurnedTile]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user