Skip to content

Commit

Permalink
feat: now unlocking stage time is dynamic and it depends on amount of…
Browse files Browse the repository at this point in the history
… triggers player activated correctly. Failed one stops incrementing
  • Loading branch information
pa.pecherskij committed Dec 21, 2024
1 parent 65727ad commit ec338d4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,16 @@ public sealed partial class XenoArtifactComponent : Component

#region Unlocking
/// <summary>
/// How long does the unlocking state last.
/// How long does the unlocking state last by default.
/// </summary>
[DataField]
public TimeSpan UnlockStateDuration = TimeSpan.FromSeconds(10);
public TimeSpan UnlockStateDuration = TimeSpan.FromSeconds(6);

/// <summary>
/// By how much unlocking state should be prolonged for each node that was unlocked.
/// </summary>
[DataField]
public TimeSpan UnlockStateIncrementPerNode = TimeSpan.FromSeconds(5);

/// <summary>
/// Minimum waiting time between unlock states.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Linq;
using Content.Shared.Chemistry;
using Content.Shared.Damage;
using Content.Shared.Examine;
Expand Down Expand Up @@ -62,6 +63,8 @@ public void TriggerXenoArtifact(Entity<XenoArtifactComponent> ent, Entity<XenoAr
if (_timing.CurTime < ent.Comp.NextUnlockTime)
return;

var index = GetIndex(ent, node);

if (!_unlockingQuery.TryGetComponent(ent, out var unlockingComp))
{
unlockingComp = EnsureComp<XenoArtifactUnlockingComponent>(ent);
Expand All @@ -71,7 +74,18 @@ public void TriggerXenoArtifact(Entity<XenoArtifactComponent> ent, Entity<XenoAr
if (_net.IsServer)
_popup.PopupEntity(Loc.GetString("artifact-unlock-state-begin"), ent);
}
var index = GetIndex(ent, node);
else
{
var predecessorNodeIndices = GetPredecessorNodes((ent, ent), index);
var successorNodeIndices = GetSuccessorNodes((ent, ent), index);
if(unlockingComp.TriggeredNodeIndexes.Count == 0
|| unlockingComp.TriggeredNodeIndexes.All(
x => predecessorNodeIndices.Contains(x) || successorNodeIndices.Contains(x)
)
)
// we add time on each new trigger, if it is not going to fail us
unlockingComp.EndTime += ent.Comp.UnlockStateIncrementPerNode;
}

if (unlockingComp.TriggeredNodeIndexes.Add(index))
{
Expand Down
6 changes: 4 additions & 2 deletions Content.Shared/Xenoarchaeology/Artifact/XAT/BaseXATSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ protected bool CanTrigger(Entity<XenoArtifactComponent> artifact, Entity<XenoArt

protected void Trigger(Entity<XenoArtifactComponent> artifact, Entity<T, XenoArtifactNodeComponent> node)
{
if (Timing.IsFirstTimePredicted)
Log.Debug($"Activated trigger {typeof(T).Name} on node {ToPrettyString(node)} for {ToPrettyString(artifact)}");
if (!Timing.IsFirstTimePredicted)
return;

Log.Debug($"Activated trigger {typeof(T).Name} on node {ToPrettyString(node)} for {ToPrettyString(artifact)}");
XenoArtifact.TriggerXenoArtifact(artifact, (node.Owner, node.Comp2));
}

Expand Down

0 comments on commit ec338d4

Please sign in to comment.