Переработка рандомных артефактов
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -41,4 +41,10 @@ public sealed partial class ArtifactEffectPrototype : IPrototype
|
||||
|
||||
[DataField("blacklist")]
|
||||
public EntityWhitelist? Blacklist;
|
||||
|
||||
/// <summary>
|
||||
/// WD. Is it safe for random items?
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public bool Safe = false;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
id: EffectBadFeeling
|
||||
targetDepth: 0
|
||||
effectHint: artifact-effect-hint-mental
|
||||
safe: true # WD
|
||||
components:
|
||||
- type: TelepathicArtifact
|
||||
messages:
|
||||
@@ -32,6 +33,7 @@
|
||||
id: EffectGoodFeeling
|
||||
targetDepth: 0
|
||||
effectHint: artifact-effect-hint-mental
|
||||
safe: true # WD
|
||||
components:
|
||||
- type: TelepathicArtifact
|
||||
messages:
|
||||
@@ -61,6 +63,7 @@
|
||||
id: EffectJunkSpawn
|
||||
targetDepth: 0
|
||||
effectHint: artifact-effect-hint-creation
|
||||
safe: true # WD
|
||||
components:
|
||||
- type: SpawnArtifact
|
||||
maxSpawns: 10
|
||||
@@ -100,12 +103,14 @@
|
||||
id: EffectLightFlicker
|
||||
targetDepth: 0
|
||||
effectHint: artifact-effect-hint-electrical-interference
|
||||
safe: true # WD
|
||||
components:
|
||||
- type: LightFlickerArtifact
|
||||
|
||||
- type: artifactEffect
|
||||
id: EffectPointLight
|
||||
targetDepth: 0
|
||||
safe: true # WD
|
||||
components:
|
||||
- type: PointLight
|
||||
radius: 8
|
||||
@@ -119,6 +124,7 @@
|
||||
id: EffectBananaSpawn
|
||||
targetDepth: 0
|
||||
effectHint: artifact-effect-hint-creation
|
||||
safe: true # WD
|
||||
components:
|
||||
- type: SpawnArtifact
|
||||
maxSpawns: 20
|
||||
@@ -137,6 +143,7 @@
|
||||
id: EffectFloraSpawn
|
||||
targetDepth: 1
|
||||
effectHint: artifact-effect-hint-creation
|
||||
safe: true # WD
|
||||
components:
|
||||
- type: SpawnArtifact
|
||||
maxSpawns: 3
|
||||
@@ -186,6 +193,7 @@
|
||||
id: EffectCold
|
||||
targetDepth: 1
|
||||
effectHint: artifact-effect-hint-consumption
|
||||
safe: true # WD
|
||||
components:
|
||||
- type: TemperatureArtifact
|
||||
targetTemp: 50
|
||||
@@ -221,6 +229,7 @@
|
||||
id: EffectInstrumentSpawn
|
||||
targetDepth: 1
|
||||
effectHint: artifact-effect-hint-creation
|
||||
safe: true # WD
|
||||
components:
|
||||
- type: SpawnArtifact
|
||||
maxSpawns: 5
|
||||
@@ -231,6 +240,7 @@
|
||||
id: EffectMonkeySpawn
|
||||
targetDepth: 1
|
||||
effectHint: artifact-effect-hint-creation
|
||||
safe: true # WD
|
||||
components:
|
||||
- type: SpawnArtifact
|
||||
spawns:
|
||||
@@ -245,6 +255,7 @@
|
||||
id: EffectChargeBatteries
|
||||
targetDepth: 1
|
||||
effectHint: artifact-effect-hint-release
|
||||
safe: true # WD
|
||||
components:
|
||||
- type: ChargeBatteryArtifact
|
||||
- type: TelepathicArtifact
|
||||
@@ -264,6 +275,7 @@
|
||||
id: EffectKnock
|
||||
targetDepth: 1
|
||||
effectHint: artifact-effect-hint-electrical-interference
|
||||
safe: true # WD
|
||||
components:
|
||||
- type: KnockArtifact
|
||||
|
||||
@@ -291,6 +303,7 @@
|
||||
id: EffectInvisibility
|
||||
targetDepth: 2
|
||||
effectHint: artifact-effect-hint-visual
|
||||
safe: true # WD
|
||||
components:
|
||||
- type: Stealth
|
||||
hadOutline: true
|
||||
@@ -317,6 +330,7 @@
|
||||
id: EffectRareMaterialSpawn
|
||||
targetDepth: 2
|
||||
effectHint: artifact-effect-hint-creation
|
||||
safe: true # WD
|
||||
components:
|
||||
- type: SpawnArtifact
|
||||
spawns:
|
||||
@@ -414,6 +428,7 @@
|
||||
id: EffectCashSpawn
|
||||
targetDepth: 2
|
||||
effectHint: artifact-effect-hint-creation
|
||||
safe: true # WD
|
||||
components:
|
||||
- type: SpawnArtifact
|
||||
maxSpawns: 10
|
||||
@@ -461,6 +476,7 @@
|
||||
id: EffectBlink
|
||||
targetDepth: 2
|
||||
effectHint: artifact-effect-hint-displacement
|
||||
safe: true # WD
|
||||
components:
|
||||
- type: RandomTeleportArtifact
|
||||
|
||||
@@ -592,6 +608,7 @@
|
||||
id: EffectHealAll
|
||||
targetDepth: 3
|
||||
effectHint: artifact-effect-hint-environment
|
||||
safe: true # WD
|
||||
components:
|
||||
- type: DamageNearbyArtifact
|
||||
damageChance: 1
|
||||
@@ -617,6 +634,7 @@
|
||||
id: EffectMaterialSpawn
|
||||
targetDepth: 3
|
||||
effectHint: artifact-effect-hint-creation
|
||||
safe: true # WD
|
||||
components:
|
||||
- type: SpawnArtifact
|
||||
maxSpawns: 5
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
id: EffectIntercom
|
||||
targetDepth: 2
|
||||
effectHint: artifact-effect-hint-communication
|
||||
safe: true # WD
|
||||
permanentComponents:
|
||||
- type: RadioMicrophone
|
||||
powerRequired: false
|
||||
@@ -31,6 +32,7 @@
|
||||
id: EffectRandomInstrument
|
||||
targetDepth: 2
|
||||
effectHint: artifact-effect-hint-mental
|
||||
safe: true # WD
|
||||
permanentComponents:
|
||||
- type: Instrument
|
||||
- type: ActivatableUI
|
||||
@@ -43,6 +45,7 @@
|
||||
id: EffectStorage
|
||||
targetDepth: 2
|
||||
effectHint: artifact-effect-hint-storage
|
||||
safe: true # WD
|
||||
whitelist:
|
||||
components:
|
||||
- Item # it doesnt necessarily have to be restricted from structures, but i think it'll be better that way
|
||||
@@ -62,6 +65,7 @@
|
||||
id: EffectPhasing
|
||||
targetDepth: 2
|
||||
effectHint: artifact-effect-hint-phasing
|
||||
safe: true # WD
|
||||
permanentComponents:
|
||||
- type: PhasingArtifact
|
||||
|
||||
@@ -83,6 +87,7 @@
|
||||
id: EffectSolutionStorage
|
||||
targetDepth: 2
|
||||
effectHint: artifact-effect-hint-storage
|
||||
safe: true # WD
|
||||
whitelist:
|
||||
components:
|
||||
- Item
|
||||
@@ -112,6 +117,7 @@
|
||||
id: EffectSpeedUp
|
||||
targetDepth: 2
|
||||
effectHint: artifact-effect-hint-displacement
|
||||
safe: true # WD
|
||||
whitelist:
|
||||
components:
|
||||
- Item
|
||||
@@ -124,6 +130,7 @@
|
||||
id: EffectDrill
|
||||
targetDepth: 3
|
||||
effectHint: artifact-effect-hint-drill
|
||||
safe: true # WD
|
||||
whitelist:
|
||||
components:
|
||||
- Item
|
||||
@@ -142,6 +149,7 @@
|
||||
id: EffectPowerGen20K
|
||||
targetDepth: 3
|
||||
effectHint: artifact-effect-hint-release
|
||||
safe: true # WD
|
||||
blacklist:
|
||||
components:
|
||||
- Item
|
||||
@@ -159,6 +167,7 @@
|
||||
id: EffectBigIron
|
||||
targetDepth: 3
|
||||
effectHint: artifact-effect-hint-gun
|
||||
safe: true # WD
|
||||
whitelist:
|
||||
components:
|
||||
- Item
|
||||
@@ -192,6 +201,7 @@
|
||||
id: EffectSentience
|
||||
targetDepth: 3
|
||||
effectHint: artifact-effect-hint-sentience
|
||||
safe: true # WD
|
||||
permanentComponents:
|
||||
- type: GhostRole
|
||||
allowMovement: true
|
||||
@@ -208,6 +218,7 @@
|
||||
id: EffectMultitool
|
||||
targetDepth: 3
|
||||
effectHint: artifact-effect-hint-multitool
|
||||
safe: true # WD
|
||||
whitelist:
|
||||
components:
|
||||
- Item
|
||||
|
||||
Reference in New Issue
Block a user