Skip to content

Commit

Permalink
Small departure for randomness.
Browse files Browse the repository at this point in the history
  • Loading branch information
EmoGarbage404 committed Jul 16, 2024
1 parent b0bc961 commit 5ad649d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Content.Shared.Destructible.Thresholds;
using Robust.Shared.GameStates;

namespace Content.Shared.Xenoarchaeology.Artifact.Components;
Expand Down Expand Up @@ -45,11 +46,23 @@ public sealed partial class XenoArtifactNodeComponent : Component
/// <summary>
/// The maximum amount of times a node can be generically activated before becoming useless
/// </summary>
[DataField]
[DataField, AutoNetworkedField]
public int MaxDurability = 5;

/// <summary>
/// The variance from MaxDurability present when a node is created.
/// </summary>
[DataField]
public MinMax InitialDurabilityVariation = new(0, 2);
#endregion

#region Research
/// <summary>
/// The amount of points a node is worth with no scaling
/// </summary>
[DataField, AutoNetworkedField]
public float BasePointValue = 5000;

[DataField, AutoNetworkedField]
public int ResearchValue;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void InitializeNode()

private void OnNodeMapInit(Entity<XenoArtifactNodeComponent> ent, ref MapInitEvent args)
{
ReplenishNodeDurability((ent, ent));
SetNodeDurability((ent, ent), ent.Comp.MaxDurability - ent.Comp.InitialDurabilityVariation.Next(RobustRandom));
}

public XenoArtifactNodeComponent XenoArtifactNode(EntityUid uid)
Expand Down Expand Up @@ -56,16 +56,6 @@ public void SetNodeUnlocked(Entity<XenoArtifactComponent> artifact, Entity<XenoA
Dirty(node);
}

/// <summary>
/// Resets a node's durability back to max.
/// </summary>
public void ReplenishNodeDurability(Entity<XenoArtifactNodeComponent?> ent)
{
if (!Resolve(ent, ref ent.Comp))
return;
SetNodeDurability(ent, ent.Comp.MaxDurability);
}

/// <summary>
/// Adds to the nodes durability by the specified value.
/// </summary>
Expand All @@ -86,6 +76,7 @@ public void SetNodeDurability(Entity<XenoArtifactNodeComponent?> ent, int durabi
if (!Resolve(ent, ref ent.Comp))
return;
ent.Comp.Durability = Math.Clamp(durability, 0, ent.Comp.MaxDurability);
UpdateNodeResearchValue((ent, ent.Comp));
Dirty(ent);
}

Expand Down Expand Up @@ -311,6 +302,8 @@ public void UpdateNodeResearchValue(Entity<XenoArtifactNodeComponent> node)
}

var artifact = _xenoArtifactQuery.Get(GetEntity(node.Comp.Attached.Value));
node.Comp.ResearchValue = (int) (Math.Pow(1.25, GetPredecessorNodes((artifact, artifact), node).Count) * 5000);

var durabilityPenalty = 1f - MathF.Pow((float) node.Comp.Durability / node.Comp.MaxDurability, 2);
node.Comp.ResearchValue = (int) (Math.Pow(1.25, GetPredecessorNodes((artifact, artifact), node).Count) * node.Comp.BasePointValue * durabilityPenalty);
}
}

0 comments on commit 5ad649d

Please sign in to comment.