Skip to content

Commit

Permalink
Плач и крики при получении урона. (#50)
Browse files Browse the repository at this point in the history
* фикс спонсорских лоадаутов

* paws

* чейнжлог
  • Loading branch information
VigersRay authored Jun 9, 2024
1 parent ccf8bd6 commit 1edd480
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 0 deletions.
33 changes: 33 additions & 0 deletions Content.Server/_Sunrise/Paws/PawsComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using Content.Shared.FixedPoint;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;

namespace Content.Server.Sunrise.Paws
{
[RegisterComponent]
public sealed partial class PawsComponent : Component
{
[ViewVariables(VVAccess.ReadWrite)]
[DataField("screamInterval")]
public float ScreamInterval = 3;

[ViewVariables(VVAccess.ReadWrite)]
[DataField("coughInterval")]
public float CoughInterval = 5;

[ViewVariables(VVAccess.ReadWrite)]
[DataField("thresholdDamage")]
public FixedPoint2 ThresholdDamage = 5;

public List<string> EmotesTakeDamage = new()
{
"Scream",
"Crying"
};

[DataField("nextChargeTime", customTypeSerializer: typeof(TimeOffsetSerializer)), ViewVariables(VVAccess.ReadWrite)]
public TimeSpan NextScreamTime = TimeSpan.FromSeconds(0);

[DataField("nextCoughTime", customTypeSerializer: typeof(TimeOffsetSerializer)), ViewVariables(VVAccess.ReadWrite)]
public TimeSpan NextCoughTime = TimeSpan.FromSeconds(0);
}
}
70 changes: 70 additions & 0 deletions Content.Server/_Sunrise/Paws/PawsSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using Content.Server.Chat.Systems;
using Content.Shared.Damage;
using Content.Shared.Mobs;
using Content.Shared.Mobs.Components;
using Content.Shared.Mobs.Systems;
using Robust.Shared.Random;
using Robust.Shared.Timing;

namespace Content.Server.Sunrise.Paws
{
public sealed class PawsSystem : EntitySystem
{
[Dependency] private readonly MobStateSystem _mobStateSystem = default!;
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly ChatSystem _chatSystem = default!;
[Dependency] private readonly IRobustRandom _random = default!;

public override void Initialize()
{
base.Initialize();
// SubscribeLocalEvent<PawsComponent, MobStateChangedEvent>(OnMobStateChanged);
SubscribeLocalEvent<PawsComponent, DamageChangedEvent>(OnDamaged);
}

// private void OnMobStateChanged(EntityUid uid, PawsComponent component, MobStateChangedEvent args)
// {
// if (args.NewMobState == MobState.Dead)
// _audioSystem.PlayPvs(component.DeadSound, uid, component.DeadSound.Params);
// }

private void OnDamaged(EntityUid uid, PawsComponent component, DamageChangedEvent args)
{
if (!_mobStateSystem.IsAlive(uid))
return;

if (!args.DamageIncreased)
return;

var curTime = _timing.CurTime;

if (curTime < component.NextScreamTime)
return;

if (args.DamageDelta!.GetTotal() < component.ThresholdDamage)
return;

component.NextScreamTime = curTime + TimeSpan.FromSeconds(component.ScreamInterval);
_chatSystem.TryEmoteWithChat(uid, _random.Pick(component.EmotesTakeDamage));
}

public override void Update(float frameTime)
{
base.Update(frameTime);
var curTime = _timing.CurTime;

var query = EntityQueryEnumerator<PawsComponent, MobStateComponent>();
while (query.MoveNext(out var uid, out var comp, out var state))
{
if (state.CurrentState != MobState.Critical)
continue;

if (curTime < comp.NextCoughTime)
return;

comp.NextCoughTime = curTime + TimeSpan.FromSeconds(comp.CoughInterval);
_chatSystem.TryEmoteWithChat(uid, "Cough", ignoreActionBlocker: true);
}
}
}
}
14 changes: 14 additions & 0 deletions Resources/Changelog/ChangelogSunrise.yml
Original file line number Diff line number Diff line change
Expand Up @@ -353,3 +353,17 @@ Entries:
type: Tweak
id: 31
time: '2024-06-09T00:03:07.870112+00:00'
- author: VigersRay
changes:
- message: "\u041F\u0440\u0438 \u043F\u043E\u043B\u0443\u0447\u0435\u043D\u0438\u0438\
\ \u0443\u0440\u043E\u043D\u0430 \u0433\u0443\u043C\u0430\u043D\u043E\u0438\u0434\
\u044B \u0442\u0435\u043F\u0435\u0440\u044C \u043A\u0440\u0438\u0447\u0430\u0442\
\ \u0438 \u043F\u043B\u0430\u0447\u0443\u0442."
type: Tweak
- message: "\u0411\u0443\u0434\u0443\u0447\u0438 \u0432 \u043A\u0440\u0438\u0442\
\u0438\u0447\u0435\u0441\u043A\u043E\u043C \u0441\u043E\u0441\u0442\u043E\u044F\
\u043D\u0438\u0438 \u0433\u0443\u043C\u0430\u043D\u043E\u0438\u0434\u044B \u043A\
\u0430\u0448\u043B\u044F\u044E\u0442."
type: Tweak
id: 32
time: '2024-06-09T02:52:26.930025+00:00'
4 changes: 4 additions & 0 deletions Resources/Prototypes/Entities/Mobs/Species/base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@
- CanPilot
- FootstepSound
- DoorBumpOpener
- type: Paws
screamInterval: 3
thresholdDamage: 5
coughInterval: 5

- type: entity
save: false
Expand Down

0 comments on commit 1edd480

Please sign in to comment.