mirror of
https://github.com/DeltaV-Station/Delta-v.git
synced 2026-09-29 15:47:26 +00:00
Compare commits
2
Commits
e409e98bf6
...
bible-user
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
37e44ee3ee | ||
|
|
fc28b60175 |
@@ -1,3 +1,4 @@
|
||||
using Content.Server._DV.BibleUser; // DeltaV
|
||||
using Content.Server.Bible.Components;
|
||||
using Content.Server.Ghost.Roles.Events;
|
||||
using Content.Server.Popups;
|
||||
@@ -32,6 +33,7 @@ namespace Content.Server.Bible
|
||||
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||
[Dependency] private readonly UseDelaySystem _delay = default!;
|
||||
[Dependency] private readonly SharedTransformSystem _transform = default!;
|
||||
[Dependency] private readonly BibleUserSystem _bibleUser = default!; // DeltaV - Shared Bible Cooldown
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -116,7 +118,7 @@ namespace Content.Server.Bible
|
||||
return;
|
||||
}
|
||||
|
||||
if (!HasComp<BibleUserComponent>(args.User))
|
||||
if (!TryComp<BibleUserComponent>(args.User, out var bibleUser)) // DeltaV - Changed from HasComp to TryComp
|
||||
{
|
||||
_popupSystem.PopupEntity(Loc.GetString("bible-sizzle"), args.User, args.User);
|
||||
|
||||
@@ -128,9 +130,11 @@ namespace Content.Server.Bible
|
||||
}
|
||||
|
||||
// This only has a chance to fail if the target is not wearing anything on their head and is not a familiar.
|
||||
if (!_invSystem.TryGetSlotEntity(args.Target.Value, "head", out var _) && !HasComp<FamiliarComponent>(args.Target.Value))
|
||||
// DeltaV - also fails if the BibleUser has used another bible in the last 10 seconds.
|
||||
if (!_invSystem.TryGetSlotEntity(args.Target.Value, "head", out var _) && !HasComp<FamiliarComponent>(args.Target.Value)
|
||||
|| !bibleUser.CanHeal) // DeltaV - also fails if the BibleUser has used another bible in the last 10 seconds.
|
||||
{
|
||||
if (_random.Prob(component.FailChance))
|
||||
if (_random.Prob(component.FailChance) || !bibleUser.CanHeal) // DeltaV
|
||||
{
|
||||
var othersFailMessage = Loc.GetString(component.LocPrefix + "-heal-fail-others", ("user", Identity.Entity(args.User, EntityManager)), ("target", Identity.Entity(args.Target.Value, EntityManager)), ("bible", uid));
|
||||
_popupSystem.PopupEntity(othersFailMessage, args.User, Filter.PvsExcept(args.User), true, PopupType.SmallCaution);
|
||||
@@ -162,6 +166,7 @@ namespace Content.Server.Bible
|
||||
_popupSystem.PopupEntity(selfMessage, args.User, args.User, PopupType.Large);
|
||||
_audio.PlayPvs(component.HealSoundPath, args.User);
|
||||
_delay.TryResetDelay((uid, useDelay));
|
||||
_bibleUser.StartBibleCooldown((args.User, bibleUser)); // DeltaV - Shared bible cooldown - Only put on cooldown if the bible healed
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,27 @@
|
||||
namespace Content.Server.Bible.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
public sealed partial class BibleUserComponent : Component {}
|
||||
public sealed partial class BibleUserComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// DeltaV - Wheter or not the BibleUser can heal. This is to prevent multiple bibles from
|
||||
/// being spammed from a single bible user.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public bool CanHeal = true;
|
||||
|
||||
/// <summary>
|
||||
/// DeltaV - The default cooldown of the bible user's ability to heal with a bible.
|
||||
///
|
||||
/// Should match UseDelay of Bible in Resources/Prototypes/Entities/Objects/Specific/Chapel/bibles.yml
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public TimeSpan Cooldown = TimeSpan.FromSeconds(10);
|
||||
|
||||
/// <summary>
|
||||
/// DeltaV - The time that <see cref="CanHeal"/> will be set to true again.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public TimeSpan? NextUse;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
using Content.Server.Bible.Components;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Server._DV.BibleUser;
|
||||
|
||||
/// <summary>
|
||||
/// A system that tracks if the BibleUser has used a bible in the last X seconds (see <see cref="BibleUserComponent.Cooldown"/>).
|
||||
/// This system is used to reset that cooldown.
|
||||
/// <br />
|
||||
/// <br />
|
||||
/// See changes in Content.Server/Bible/BibleSystem.cs around the BibleUser component.
|
||||
/// This system can easily be moved to shared once the upstream bible system is moved to shared.
|
||||
/// </summary>
|
||||
public sealed class BibleUserSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<BibleUserComponent, ComponentInit>(OnComponentInit);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Puts the usage of the Bible on cooldown.
|
||||
/// </summary>
|
||||
/// <param name="entity">The entity that may have the BibleUserComponent to put on cooldown.</param>
|
||||
/// <param name="cooldown">If specified, the amount of time that the bible will be on cooldown.
|
||||
/// If null, <see cref="BibleUserComponent.Cooldown"/> will be used.</param>
|
||||
[PublicAPI]
|
||||
public void StartBibleCooldown(Entity<BibleUserComponent?> entity, TimeSpan? cooldown = null)
|
||||
{
|
||||
if (!Resolve(entity, ref entity.Comp, false))
|
||||
return;
|
||||
|
||||
// If they can't heal yet, don't reset the cooldown
|
||||
if (!entity.Comp.CanHeal)
|
||||
return;
|
||||
|
||||
if (!cooldown.HasValue)
|
||||
cooldown = entity.Comp.Cooldown;
|
||||
|
||||
entity.Comp.CanHeal = false;
|
||||
entity.Comp.NextUse = _timing.CurTime + cooldown.Value;
|
||||
}
|
||||
|
||||
private void OnComponentInit(Entity<BibleUserComponent> entity, ref ComponentInit args)
|
||||
{
|
||||
entity.Comp.NextUse = _timing.CurTime;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates if enough time has passed and the chaplain can use their bible again.
|
||||
/// </summary>
|
||||
/// <param name="frameTime"></param>
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
base.Update(frameTime);
|
||||
|
||||
var query = EntityQueryEnumerator<BibleUserComponent>();
|
||||
while (query.MoveNext(out var uid, out var comp))
|
||||
{
|
||||
// If they can heal, we don't need to check if the cooldown time.
|
||||
if (comp.CanHeal)
|
||||
return;
|
||||
|
||||
if (_timing.CurTime > comp.NextUse)
|
||||
{
|
||||
comp.CanHeal = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user