[Sci] Non-destructive XenoArch Research (#15398)

* Non-destructive XenoArch research

* nerf the price

* Points -> Extract
This commit is contained in:
Nemanja
2023-04-17 01:57:21 -04:00
committed by GitHub
parent adb6b168b7
commit 2a83a9bc17
11 changed files with 89 additions and 167 deletions

View File

@@ -4,7 +4,7 @@ using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototy
namespace Content.Server.Xenoarchaeology.XenoArtifacts;
[RegisterComponent]
[RegisterComponent, Access(typeof(ArtifactSystem))]
public sealed class ArtifactComponent : Component
{
/// <summary>
@@ -53,22 +53,29 @@ public sealed class ArtifactComponent : Component
public TimeSpan LastActivationTime;
/// <summary>
/// The base price of each node for an artifact
/// A multiplier applied to the calculated point value
/// to determine the monetary value of the artifact
/// </summary>
[DataField("pricePerNode")]
public int PricePerNode = 500;
[DataField("priceMultiplier"), ViewVariables(VVAccess.ReadWrite)]
public float PriceMultiplier = 0.05f;
/// <summary>
/// The base amount of research points for each artifact node.
/// </summary>
[DataField("pointsPerNode")]
[DataField("pointsPerNode"), ViewVariables(VVAccess.ReadWrite)]
public int PointsPerNode = 5000;
/// <summary>
/// Research points which have been "consumed" from the theoretical max value of the artifact.
/// </summary>
[DataField("consumedPoints"), ViewVariables(VVAccess.ReadWrite)]
public int ConsumedPoints;
/// <summary>
/// A multiplier that is raised to the power of the average depth of a node.
/// Used for calculating the research point value of an artifact node.
/// </summary>
[DataField("pointDangerMultiplier")]
[DataField("pointDangerMultiplier"), ViewVariables(VVAccess.ReadWrite)]
public float PointDangerMultiplier = 1.35f;
}

View File

@@ -51,29 +51,7 @@ public sealed partial class ArtifactSystem : EntitySystem
/// </remarks>
private void GetPrice(EntityUid uid, ArtifactComponent component, ref PriceCalculationEvent args)
{
var price = component.NodeTree.Sum(x => GetNodePrice(x, component));
// 25% bonus for fully exploring every node.
var fullyExploredBonus = component.NodeTree.Any(x => !x.Triggered) ? 1 : 1.25f;
args.Price =+ price * fullyExploredBonus;
}
private float GetNodePrice(ArtifactNode node, ArtifactComponent component)
{
if (!node.Discovered) //no money for undiscovered nodes.
return 0;
var triggerProto = _prototype.Index<ArtifactTriggerPrototype>(node.Trigger);
var effectProto = _prototype.Index<ArtifactEffectPrototype>(node.Effect);
//quarter price if not triggered
var priceMultiplier = node.Triggered ? 1f : 0.25f;
//the danger is the average of node depth, effect danger, and trigger danger.
var nodeDanger = (node.Depth + effectProto.TargetDepth + triggerProto.TargetDepth) / 3;
var price = MathF.Pow(2f, nodeDanger) * component.PricePerNode * priceMultiplier;
return price;
args.Price =+ GetResearchPointValue(uid, component) * component.PriceMultiplier;
}
/// <summary>
@@ -96,9 +74,32 @@ public sealed partial class ArtifactSystem : EntitySystem
var sumValue = component.NodeTree.Sum(n => GetNodePointValue(n, component, getMaxPrice));
var fullyExploredBonus = component.NodeTree.All(x => x.Triggered) || getMaxPrice ? 1.25f : 1;
sumValue -= component.ConsumedPoints;
var pointValue = (int) (sumValue * fullyExploredBonus);
return pointValue;
return (int) (sumValue * fullyExploredBonus);
}
/// <summary>
/// Adjusts how many points on the artifact have been consumed
/// </summary>
public void AdjustConsumedPoints(EntityUid uid, int amount, ArtifactComponent? component = null)
{
if (!Resolve(uid, ref component))
return;
component.ConsumedPoints += amount;
}
/// <summary>
/// Sets whether or not the artifact is suppressed,
/// preventing it from activating
/// </summary>
public void SetIsSuppressed(EntityUid uid, bool suppressed, ArtifactComponent? component = null)
{
if (!Resolve(uid, ref component))
return;
component.IsSuppressed = suppressed;
}
/// <summary>
@@ -201,8 +202,8 @@ public sealed partial class ArtifactSystem : EntitySystem
var currentNode = GetNodeFromId(component.CurrentNodeId.Value, component);
var allNodes = currentNode.Edges;
_sawmill.Debug("artifact", $"our node: {currentNode.Id}");
_sawmill.Debug("artifact", $"other nodes: {string.Join(", ", allNodes)}");
_sawmill.Debug($"our node: {currentNode.Id}");
_sawmill.Debug($"other nodes: {string.Join(", ", allNodes)}");
if (TryComp<BiasedArtifactComponent>(uid, out var bias) &&
TryComp<TraversalDistorterComponent>(bias.Provider, out var trav) &&
@@ -225,14 +226,14 @@ public sealed partial class ArtifactSystem : EntitySystem
}
var undiscoveredNodes = allNodes.Where(x => !GetNodeFromId(x, component).Discovered).ToList();
_sawmill.Debug("artifact", $"Undiscovered nodes: {string.Join(", ", undiscoveredNodes)}");
_sawmill.Debug($"Undiscovered nodes: {string.Join(", ", undiscoveredNodes)}");
var newNode = _random.Pick(allNodes);
if (undiscoveredNodes.Any() && _random.Prob(0.75f))
{
newNode = _random.Pick(undiscoveredNodes);
}
_sawmill.Debug("artifact", $"Going to node {newNode}");
_sawmill.Debug($"Going to node {newNode}");
return GetNodeFromId(newNode, component);
}