Skip to content

Commit

Permalink
Code Tweeks
Browse files Browse the repository at this point in the history
  • Loading branch information
ElusiveCoin committed Jan 17, 2025
1 parent bbfda29 commit 5233e19
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 104 deletions.
4 changes: 2 additions & 2 deletions Content.Server/Chemistry/EntitySystems/InjectorSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private void OnInjectorAfterInteract(Entity<InjectorComponent> entity, ref After
/// </summary>
private void InjectDoAfter(Entity<InjectorComponent> injector, EntityUid target, EntityUid user)
{
if (HasComp<BlockInjectionComponent>(target))
if (HasComp<BlockInjectionComponent>(target)) // DeltaV
{
Popup.PopupEntity(Loc.GetString("injector-component-deny-user"), target, user);
return;
Expand Down Expand Up @@ -260,7 +260,7 @@ private bool TryInjectIntoBloodstream(Entity<InjectorComponent> injector, Entity
private bool TryInject(Entity<InjectorComponent> injector, EntityUid targetEntity,
Entity<SolutionComponent> targetSolution, EntityUid user, bool asRefill)
{
if (HasComp<BlockInjectionComponent>(targetEntity))
if (HasComp<BlockInjectionComponent>(targetEntity)) // DeltaV
return false;

if (!SolutionContainers.TryGetSolution(injector.Owner, injector.Comp.SolutionName, out var soln,
Expand Down
31 changes: 20 additions & 11 deletions Content.Server/_DV/Abilities/Chitinid/ChitinidComponent.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,40 @@
using Content.Shared.Damage;
using Content.Shared.Damage.Prototypes;
using Content.Shared.FixedPoint;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;

namespace Content.Server.Abilities.Chitinid;


[RegisterComponent]
public sealed partial class ChitinidComponent : Component
{
[DataField("ChitzitePrototype", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
public string ChitzitePrototype = "Chitzite";
[DataField]
public EntProtoId ChitzitePrototype = "Chitzite";

[DataField("ChitziteActionId",
customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
public string? ChitziteActionId = "ActionChitzite";
[DataField]
public EntProtoId ChitziteActionId = "ActionChitzite";

[DataField("ChitziteAction")]
[DataField]
public EntityUid? ChitziteAction;

[DataField]
public float AmountAbsorbed { get; set; } = 0f;
public FixedPoint2 AmountAbsorbed = 0f;

[DataField]
public DamageSpecifier Healing = new()
{
DamageDict = new()
{
{ "Radiation", -0.5 },
}
};

[DataField]
public float MaximumAbsorbed = 30f;
public FixedPoint2 MaximumAbsorbed = 30f;

[DataField]
public TimeSpan UpdateInterval { get; set; } = TimeSpan.FromSeconds(1);
public TimeSpan UpdateInterval = TimeSpan.FromSeconds(1);

[DataField(customTypeSerializer: typeof(TimeOffsetSerializer))]
public TimeSpan NextUpdate;
Expand Down
90 changes: 32 additions & 58 deletions Content.Server/_DV/Abilities/Chitinid/ChitinidSystem.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
using Content.Server.Abilities.Felinid;
using Content.Server.Chat.Systems;
using Content.Server.Nutrition.Components;
using Content.Server.Popups;
using Content.Shared.Actions;
using Content.Shared.Actions.Events;
using Content.Shared.Audio;
using Content.Shared.Damage;
using Content.Shared.Damage.Prototypes;
using Content.Shared.IdentityManagement;
using Content.Shared.Inventory;
using Content.Shared.Mobs;
using Content.Shared.Mobs.Systems;
using Content.Shared.Popups;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;
Expand All @@ -19,105 +15,83 @@ namespace Content.Server.Abilities.Chitinid;

public sealed partial class ChitinidSystem : EntitySystem
{
[Dependency] private readonly SharedActionsSystem _actionsSystem = default!;
[Dependency] private readonly SharedActionsSystem _actions = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly PopupSystem _popupSystem = default!;
[Dependency] private readonly InventorySystem _inventorySystem = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly IPrototypeManager _proto = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;
[Dependency] private readonly InventorySystem _inventory = default!;
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly DamageableSystem _damageable = default!;
[Dependency] private readonly MobStateSystem _mobState = default!;

public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<ChitinidComponent, ComponentInit>(OnInit);
SubscribeLocalEvent<ChitinidComponent,ChitziteActionEvent>(OnChitzite);
SubscribeLocalEvent<ChitinidComponent,MapInitEvent>(OnMapInit);
SubscribeLocalEvent<ChitinidComponent, ChitziteActionEvent>(OnChitzite);
SubscribeLocalEvent<ChitinidComponent, MapInitEvent>(OnMapInit);
}

private Queue<EntityUid> RemQueue = new();


public override void Update(float frameTime)
{
base.Update(frameTime);
foreach (var bug in RemQueue)
{
RemComp<CoughingUpChitziteComponent>(bug);
}
RemQueue.Clear();

var query = EntityQueryEnumerator<ChitinidComponent, DamageableComponent>();
while (query.MoveNext(out var uid, out var chitinid, out var damageable))
{
if (_gameTiming.CurTime < chitinid.NextUpdate)
if (_timing.CurTime < chitinid.NextUpdate)
continue;

chitinid.NextUpdate += chitinid.UpdateInterval;

if (chitinid.AmountAbsorbed >= chitinid.MaximumAbsorbed && !_mobState.IsDead(uid))
if (chitinid.AmountAbsorbed >= chitinid.MaximumAbsorbed || _mobState.IsDead(uid))
continue;

var damage = new DamageSpecifier(_prototypeManager.Index<DamageTypePrototype>("Radiation"), -0.5);
var delta = _damageable.TryChangeDamage(uid, damage);
if (delta != null)
if (_damageable.TryChangeDamage(uid, chitinid.Healing, damageable: damageable) is {} delta)
{
chitinid.AmountAbsorbed += -(delta.GetTotal().Float());
chitinid.AmountAbsorbed += -delta.GetTotal().Float();
if (chitinid.ChitziteAction != null && chitinid.AmountAbsorbed >= chitinid.MaximumAbsorbed)
{
_actionsSystem.SetCharges(chitinid.ChitziteAction, 1); // You get the charge back and that's it. Tough.
_actionsSystem.SetEnabled(chitinid.ChitziteAction, true);
_actions.SetCharges(chitinid.ChitziteAction, 1); // You get the charge back and that's it. Tough.
_actions.SetEnabled(chitinid.ChitziteAction, true);
}
}
}

foreach (var (chitziteComponent, chitinidComponent) in EntityQuery<CoughingUpChitziteComponent, ChitinidComponent>())
var entQuery = EntityQueryEnumerator<CoughingUpChitziteComponent, ChitinidComponent>();
while (entQuery.MoveNext(out var ent, out var chitzite, out var chitinid))
{
chitziteComponent.Accumulator += frameTime;
if (chitziteComponent.Accumulator < chitziteComponent.CoughUpTime.TotalSeconds)
if (_timing.CurTime < chitzite.NextCough)
continue;

chitziteComponent.Accumulator = 0;
SpawnChitzite(chitziteComponent.Owner, chitinidComponent);
RemQueue.Enqueue(chitziteComponent.Owner);
Spawn(chitinid.ChitzitePrototype, Transform(ent).Coordinates);
chitinid.AmountAbsorbed = 0f;
RemCompDeferred(ent, chitzite);
}
}

private void OnMapInit(Entity<ChitinidComponent> ent, ref MapInitEvent args)
{
ent.Comp.NextUpdate = _gameTiming.CurTime + ent.Comp.UpdateInterval;
}

private void OnInit(EntityUid uid, ChitinidComponent component, ComponentInit args)
{
if (component.ChitziteAction != null)
if (ent.Comp.ChitziteAction != null)
return;

_actionsSystem.AddAction(uid, ref component.ChitziteAction, component.ChitziteActionId);
ent.Comp.NextUpdate = _timing.CurTime + ent.Comp.UpdateInterval;

_actions.AddAction(ent, ref ent.Comp.ChitziteAction, ent.Comp.ChitziteActionId);
}

private void OnChitzite(EntityUid uid, ChitinidComponent component, ChitziteActionEvent args)
private void OnChitzite(Entity<ChitinidComponent> ent, ref ChitziteActionEvent args)
{
if (_inventorySystem.TryGetSlotEntity(uid, "mask", out var maskUid) &&
EntityManager.TryGetComponent<IngestionBlockerComponent>(maskUid, out var blocker) &&
if (_inventory.TryGetSlotEntity(ent, "mask", out var maskUid) &&
TryComp<IngestionBlockerComponent>(maskUid, out var blocker) &&
blocker.Enabled)
{
_popupSystem.PopupEntity(Loc.GetString("chitzite-mask", ("mask", maskUid)), uid, uid);
_popup.PopupEntity(Loc.GetString("chitzite-mask", ("mask", maskUid)), ent, ent);
return;
}

_popupSystem.PopupEntity(Loc.GetString("chitzite-cough", ("name", Identity.Entity(uid, EntityManager))), uid);
_audio.PlayPvs("/Audio/Animals/cat_hiss.ogg", uid, AudioHelpers.WithVariation(0.15f));
_popup.PopupEntity(Loc.GetString("chitzite-cough", ("name", Identity.Entity(ent, EntityManager))), ent);
_audio.PlayPvs("/Audio/Animals/cat_hiss.ogg", ent, AudioHelpers.WithVariation(0.15f));

EnsureComp<CoughingUpChitziteComponent>(uid);
var chitzite = EnsureComp<CoughingUpChitziteComponent>(ent);
chitzite.NextCough = _timing.CurTime + chitzite.CoughUpTime;
args.Handled = true;
}

private void SpawnChitzite(EntityUid uid, ChitinidComponent component)
{
var chitzite = EntityManager.SpawnEntity(component.ChitzitePrototype, Transform(uid).Coordinates);
component.AmountAbsorbed = 0f;
}

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;

namespace Content.Server.Abilities.Chitinid;

[RegisterComponent]
[RegisterComponent, AutoGenerateComponentPause]
public sealed partial class CoughingUpChitziteComponent : Component
{
[DataField("accumulator")]
public float Accumulator = 0f;
[DataField(customTypeSerializer: typeof(TimeOffsetSerializer))]
[AutoPausedField]
public TimeSpan NextCough;

[DataField("coughUpTime")]
[DataField]
public TimeSpan CoughUpTime = TimeSpan.FromSeconds(2.15);
}
28 changes: 14 additions & 14 deletions Resources/Prototypes/Entities/Mobs/Customization/Markings/gauze.yml
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@
id: GauzeHead
bodyPart: Head
markingCategory: Overlay
speciesRestriction: [Dwarf, Human, Reptilian, Arachnid, Moth, Chitinid]
speciesRestriction: [Dwarf, Human, Reptilian, Arachnid, Moth, Chitinid] # Delta V - Chitinid
coloring:
default:
type:
Expand Down Expand Up @@ -312,7 +312,7 @@
id: GauzeMothBlindfold
bodyPart: Eyes
markingCategory: Overlay
speciesRestriction: [Moth, Chitinid]
speciesRestriction: [Moth, Chitinid] # Delta V - Chitinid
coloring:
default:
type:
Expand All @@ -326,7 +326,7 @@
id: GauzeMothShoulder
bodyPart: Chest
markingCategory: Overlay
speciesRestriction: [Moth, Chitinid]
speciesRestriction: [Moth, Chitinid] # Delta V - Chitinid
coloring:
default:
type:
Expand All @@ -340,7 +340,7 @@
id: GauzeMothStomach
bodyPart: Chest
markingCategory: Overlay
speciesRestriction: [Moth, Chitinid]
speciesRestriction: [Moth, Chitinid] # Delta V - Chitinid
coloring:
default:
type:
Expand All @@ -354,7 +354,7 @@
id: GauzeMothLeftEyePatch
bodyPart: Eyes
markingCategory: Overlay
speciesRestriction: [Moth, Chitinid]
speciesRestriction: [Moth, Chitinid] # Delta V - Chitinid
coloring:
default:
type:
Expand All @@ -368,7 +368,7 @@
id: GauzeMothLeftEyePad
bodyPart: Eyes
markingCategory: Overlay
speciesRestriction: [Moth, Chitinid]
speciesRestriction: [Moth, Chitinid] # Delta V - Chitinid
coloring:
default:
type:
Expand All @@ -382,7 +382,7 @@
id: GauzeMothRightEyePatch
bodyPart: Eyes
markingCategory: Overlay
speciesRestriction: [Moth, Chitinid]
speciesRestriction: [Moth, Chitinid] # Delta V - Chitinid
coloring:
default:
type:
Expand All @@ -396,7 +396,7 @@
id: GauzeMothRightEyePad
bodyPart: Eyes
markingCategory: Overlay
speciesRestriction: [Moth, Chitinid]
speciesRestriction: [Moth, Chitinid] # Delta V - Chitinid
coloring:
default:
type:
Expand All @@ -410,7 +410,7 @@
id: GauzeMothUpperArmRight
bodyPart: RArm
markingCategory: Overlay
speciesRestriction: [Moth, Chitinid]
speciesRestriction: [Moth, Chitinid] # Delta V - Chitinid
coloring:
default:
type:
Expand All @@ -424,7 +424,7 @@
id: GauzeMothUpperArmLeft
bodyPart: LArm
markingCategory: Overlay
speciesRestriction: [Moth, Chitinid]
speciesRestriction: [Moth, Chitinid] # Delta V - Chitinid
coloring:
default:
type:
Expand All @@ -438,7 +438,7 @@
id: GauzeMothUpperLegRight
bodyPart: RLeg
markingCategory: Overlay
speciesRestriction: [Moth, Chitinid]
speciesRestriction: [Moth, Chitinid] # Delta V - Chitinid
coloring:
default:
type:
Expand All @@ -452,7 +452,7 @@
id: GauzeMothUpperLegLeft
bodyPart: LLeg
markingCategory: Overlay
speciesRestriction: [Moth, Chitinid]
speciesRestriction: [Moth, Chitinid] # Delta V - Chitinid
coloring:
default:
type:
Expand All @@ -466,7 +466,7 @@
id: GauzeMothLowerLegRight
bodyPart: RFoot
markingCategory: Overlay
speciesRestriction: [Moth, Chitinid]
speciesRestriction: [Moth, Chitinid] # Delta V - Chitinid
coloring:
default:
type:
Expand All @@ -480,7 +480,7 @@
id: GauzeMothLowerLegLeft
bodyPart: LFoot
markingCategory: Overlay
speciesRestriction: [Moth, Chitinid]
speciesRestriction: [Moth, Chitinid] # Delta V - Chitinid
coloring:
default:
type:
Expand Down
Loading

0 comments on commit 5233e19

Please sign in to comment.