Переработка рандомных артефактов
This commit is contained in:
@@ -30,7 +30,7 @@ public sealed partial class ArtifactSystem
|
||||
|
||||
_usedNodeIds.Clear();
|
||||
|
||||
var uninitializedNodes = new List<ArtifactNode> { new(){ Id = GetValidNodeId() } };
|
||||
var uninitializedNodes = new List<ArtifactNode> { new() { Id = GetValidNodeId() } };
|
||||
var createdNodes = 1;
|
||||
|
||||
while (uninitializedNodes.Count > 0)
|
||||
@@ -50,7 +50,7 @@ public sealed partial class ArtifactSystem
|
||||
break;
|
||||
}
|
||||
|
||||
var child = new ArtifactNode {Id = GetValidNodeId(), Depth = node.Depth + 1};
|
||||
var child = new ArtifactNode { Id = GetValidNodeId(), Depth = node.Depth + 1 };
|
||||
node.Edges.Add(child.Id);
|
||||
child.Edges.Add(node.Id);
|
||||
|
||||
@@ -240,4 +240,67 @@ public sealed partial class ArtifactSystem
|
||||
{
|
||||
return nodes.First(x => x.Id == id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// WD.
|
||||
/// Generate an Artifact tree with fully developed nodes.
|
||||
/// </summary>
|
||||
private void GenerateSafeArtifactNodeTree(EntityUid artifact, List<ArtifactNode> allNodes, int nodesToCreate)
|
||||
{
|
||||
if (nodesToCreate < 1)
|
||||
{
|
||||
Log.Error($"nodesToCreate {nodesToCreate} is less than 1. Aborting artifact tree generation.");
|
||||
return;
|
||||
}
|
||||
|
||||
_usedNodeIds.Clear();
|
||||
|
||||
var uninitializedNodes = new List<ArtifactNode> { new() { Id = GetValidNodeId() } };
|
||||
var createdNodes = 1;
|
||||
|
||||
while (uninitializedNodes.Count > 0)
|
||||
{
|
||||
var node = uninitializedNodes[0];
|
||||
uninitializedNodes.Remove(node);
|
||||
|
||||
node.Trigger = GetRandomTrigger(artifact, ref node);
|
||||
node.Effect = GetSafeRandomEffect(artifact, ref node);
|
||||
|
||||
var maxChildren = _random.Next(1, MaxEdgesPerNode - 1);
|
||||
|
||||
for (var i = 0; i < maxChildren; i++)
|
||||
{
|
||||
if (nodesToCreate <= createdNodes)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
var child = new ArtifactNode { Id = GetValidNodeId(), Depth = node.Depth + 1 };
|
||||
node.Edges.Add(child.Id);
|
||||
child.Edges.Add(node.Id);
|
||||
|
||||
uninitializedNodes.Add(child);
|
||||
createdNodes++;
|
||||
}
|
||||
|
||||
allNodes.Add(node);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// WD.
|
||||
/// </summary>
|
||||
private string GetSafeRandomEffect(EntityUid artifact, ref ArtifactNode node)
|
||||
{
|
||||
var allEffects = _prototype.EnumeratePrototypes<ArtifactEffectPrototype>()
|
||||
.Where(x => (x.Whitelist?.IsValid(artifact, EntityManager) ?? true) && (!x.Blacklist?.IsValid(artifact, EntityManager) ?? true) && x.Safe).ToList();
|
||||
var validDepth = allEffects.Select(x => x.TargetDepth).Distinct().ToList();
|
||||
|
||||
var weights = GetDepthWeights(validDepth, node.Depth);
|
||||
var selectedRandomTargetDepth = GetRandomTargetDepth(weights);
|
||||
var targetEffects = allEffects
|
||||
.Where(x => x.TargetDepth == selectedRandomTargetDepth).ToList();
|
||||
|
||||
return _random.Pick(targetEffects).ID;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -295,4 +295,18 @@ public sealed partial class ArtifactSystem : EntitySystem
|
||||
{
|
||||
return allNodes.First(n => n.Depth == 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// WD. Randomize a given artifact.
|
||||
/// </summary>
|
||||
[PublicAPI]
|
||||
public void SafeRandomizeArtifact(EntityUid uid, ArtifactComponent component)
|
||||
{
|
||||
component.NodesMax = 5;
|
||||
var nodeAmount = _random.Next(component.NodesMin, component.NodesMax);
|
||||
|
||||
GenerateSafeArtifactNodeTree(uid, component.NodeTree, nodeAmount);
|
||||
var firstNode = GetRootNode(component.NodeTree);
|
||||
EnterNode(uid, ref firstNode, component);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ using Content.Server.Station.Components;
|
||||
using Content.Server.Station.Systems;
|
||||
using Content.Server.Xenoarchaeology.XenoArtifacts;
|
||||
using Content.Shared._White;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Stacks;
|
||||
using Content.Shared.Item;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.Random;
|
||||
@@ -16,7 +18,7 @@ public sealed class RandomArtifactsSystem : EntitySystem
|
||||
[Dependency] private readonly IConfigurationManager _configurationManager = default!;
|
||||
[Dependency] private readonly StationSystem _station = default!;
|
||||
|
||||
private float _itemToArtifactRatio; // from 0 to 100. In % percents. Default is 0.7%
|
||||
private float _itemToArtifactRatio; // from 0 to 100. In % percents. Default is 0.4%
|
||||
private bool _artifactsEnabled;
|
||||
|
||||
public override void Initialize()
|
||||
@@ -34,11 +36,12 @@ public sealed class RandomArtifactsSystem : EntitySystem
|
||||
if (!_artifactsEnabled)
|
||||
return;
|
||||
|
||||
// Removing old artifact-items and replace it with new funny stealthy items
|
||||
foreach (var oldArtifact in EntityQuery<ArtifactComponent>())
|
||||
{
|
||||
QueueDel(oldArtifact.Owner);
|
||||
}
|
||||
// No we don't
|
||||
// // Removing old artifact-items and replace it with new funny stealthy items
|
||||
// foreach (var oldArtifact in EntityQuery<ArtifactComponent>())
|
||||
// {
|
||||
// QueueDel(oldArtifact.Owner);
|
||||
// }
|
||||
|
||||
var items = EntityQuery<ItemComponent>().ToList();
|
||||
_random.Shuffle(items);
|
||||
@@ -55,8 +58,13 @@ public sealed class RandomArtifactsSystem : EntitySystem
|
||||
if (!HasComp<StationDataComponent>(station))
|
||||
continue;
|
||||
|
||||
if (HasComp<StackComponent>(entity))
|
||||
continue;
|
||||
|
||||
var artifactComponent = EnsureComp<ArtifactComponent>(entity);
|
||||
_artifactsSystem.RandomizeArtifact(entity, artifactComponent);
|
||||
_artifactsSystem.SafeRandomizeArtifact(entity, artifactComponent);
|
||||
|
||||
EnsureComp<DamageableComponent>(entity);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user