* ECS and damage Data * Comments and newlines * Added Comments * Make TryChangeDamageEvent immutable * Remove SetAllDamage event Use public SetAllDamage function instead * Undo destructible mistakes That was some shit code. * Rename DamageData to DamageSpecifier And misc small edits misc * Cache trigger prototypes. * Renaming destructible classes & functions * Revert "Cache trigger prototypes." This reverts commit 86bae15ba6616884dba75f552dfdfbe2d1fb6586. * Replace prototypes with prototype IDs. * Split damage.yml into individual files * move get/handle component state to system * Update HealthChange doc * Make godmode call Dirty() on damageable component * Add Initialize() to fix damage test * Make non-static * uncache resistance set prototype and trim DamageableComponentState * Remove unnecessary Dirty() calls during initialization * RemoveTryChangeDamageEvent * revert Dirty() * Fix MobState relying on DamageableComponent.Dirty() * Fix DisposalUnit Tests. These were previously failing, but because the async was not await-ed, this never raised the exception. After I fixed MobState component, this exception stopped happening and instead the assertions started being tested & failing * Disposal test 2: electric boogaloo * Fix typos/mistakes also add comments and fix spacing. * Use Uids instead of IEntity * fix merge * Comments, a merge issue, and making some damage ignore resistances * Extend DamageSpecifier and use it for DamageableComponent * fix master merge * Fix Disposal unit test. Again. Snapgrids were removed in master * Execute Exectute
181 lines
5.5 KiB
C#
181 lines
5.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using Content.Server.Alert;
|
|
using Content.Server.Atmos.EntitySystems;
|
|
using Content.Server.Stunnable.Components;
|
|
using Content.Server.Temperature.Components;
|
|
using Content.Shared.ActionBlocker;
|
|
using Content.Shared.Alert;
|
|
using Content.Shared.Atmos;
|
|
using Content.Shared.Atmos.Components;
|
|
using Content.Shared.Damage;
|
|
using Content.Shared.Interaction;
|
|
using Content.Shared.Notification.Managers;
|
|
using Content.Shared.Temperature;
|
|
using Robust.Server.GameObjects;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.Localization;
|
|
using Robust.Shared.Physics;
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
|
using Robust.Shared.ViewVariables;
|
|
|
|
namespace Content.Server.Atmos.Components
|
|
{
|
|
[RegisterComponent]
|
|
public class FlammableComponent : SharedFlammableComponent, IFireAct, IInteractUsing
|
|
{
|
|
private bool _resisting = false;
|
|
private readonly List<EntityUid> _collided = new();
|
|
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
|
public bool OnFire { get; set; }
|
|
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
|
public float FireStacks { get; set; }
|
|
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
|
[DataField("fireSpread")]
|
|
public bool FireSpread { get; private set; } = false;
|
|
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
|
[DataField("canResistFire")]
|
|
public bool CanResistFire { get; private set; } = false;
|
|
|
|
[DataField("damage", required: true)]
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
|
public DamageSpecifier Damage = default!;
|
|
|
|
public void Extinguish()
|
|
{
|
|
if (!OnFire) return;
|
|
OnFire = false;
|
|
FireStacks = 0;
|
|
|
|
_collided.Clear();
|
|
|
|
UpdateAppearance();
|
|
}
|
|
|
|
public void AdjustFireStacks(float relativeFireStacks)
|
|
{
|
|
FireStacks = MathF.Min(MathF.Max(-10f, FireStacks + relativeFireStacks), 20f);
|
|
if (OnFire && FireStacks <= 0)
|
|
Extinguish();
|
|
|
|
UpdateAppearance();
|
|
}
|
|
|
|
public void Update(GasMixture air)
|
|
{
|
|
// Slowly dry ourselves off if wet.
|
|
if (FireStacks < 0)
|
|
{
|
|
FireStacks = MathF.Min(0, FireStacks + 1);
|
|
}
|
|
|
|
Owner.TryGetComponent(out ServerAlertsComponent? status);
|
|
|
|
if (!OnFire)
|
|
{
|
|
status?.ClearAlert(AlertType.Fire);
|
|
return;
|
|
}
|
|
|
|
status?.ShowAlert(AlertType.Fire);
|
|
|
|
if (FireStacks > 0)
|
|
{
|
|
if (Owner.TryGetComponent(out TemperatureComponent? temp))
|
|
{
|
|
temp.ReceiveHeat(200 * FireStacks);
|
|
}
|
|
|
|
// TODO ATMOS Fire resistance from armor
|
|
var damageScale = Math.Min((int) (FireStacks * 2.5f), 10);
|
|
EntitySystem.Get<DamageableSystem>().TryChangeDamage(Owner.Uid, Damage * damageScale);
|
|
|
|
AdjustFireStacks(-0.1f * (_resisting ? 10f : 1f));
|
|
}
|
|
else
|
|
{
|
|
Extinguish();
|
|
return;
|
|
}
|
|
|
|
// If we're in an oxygenless environment, put the fire out.
|
|
if (air.GetMoles(Gas.Oxygen) < 1f)
|
|
{
|
|
Extinguish();
|
|
return;
|
|
}
|
|
|
|
EntitySystem.Get<AtmosphereSystem>().HotspotExpose(Owner.Transform.Coordinates, 700f, 50f, true);
|
|
|
|
var physics = Owner.GetComponent<IPhysBody>();
|
|
|
|
foreach (var uid in _collided.ToArray())
|
|
{
|
|
if (!uid.IsValid() || !Owner.EntityManager.EntityExists(uid))
|
|
{
|
|
_collided.Remove(uid);
|
|
continue;
|
|
}
|
|
|
|
var entity = Owner.EntityManager.GetEntity(uid);
|
|
var otherPhysics = entity.GetComponent<IPhysBody>();
|
|
|
|
if (!physics.GetWorldAABB().Intersects(otherPhysics.GetWorldAABB()))
|
|
{
|
|
_collided.Remove(uid);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void UpdateAppearance()
|
|
{
|
|
if (Owner.Deleted || !Owner.TryGetComponent(out AppearanceComponent? appearanceComponent)) return;
|
|
appearanceComponent.SetData(FireVisuals.OnFire, OnFire);
|
|
appearanceComponent.SetData(FireVisuals.FireStacks, FireStacks);
|
|
}
|
|
|
|
public void FireAct(float temperature, float volume)
|
|
{
|
|
AdjustFireStacks(3);
|
|
EntitySystem.Get<FlammableSystem>().Ignite(this);
|
|
}
|
|
|
|
// This needs some improvements...
|
|
public void Resist()
|
|
{
|
|
if (!OnFire || !EntitySystem.Get<ActionBlockerSystem>().CanInteract(Owner) || _resisting || !Owner.TryGetComponent(out StunnableComponent? stunnable)) return;
|
|
|
|
_resisting = true;
|
|
|
|
Owner.PopupMessage(Loc.GetString("flammable-component-resist-message"));
|
|
stunnable.Paralyze(2f);
|
|
|
|
Owner.SpawnTimer(2000, () =>
|
|
{
|
|
_resisting = false;
|
|
FireStacks -= 3f;
|
|
UpdateAppearance();
|
|
});
|
|
}
|
|
|
|
public async Task<bool> InteractUsing(InteractUsingEventArgs eventArgs)
|
|
{
|
|
foreach (var hotItem in eventArgs.Using.GetAllComponents<IHotItem>())
|
|
{
|
|
if (hotItem.IsCurrentlyHot())
|
|
{
|
|
EntitySystem.Get<FlammableSystem>().Ignite(this);
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|
|
}
|