From 0cb6411c7add459208c7bc96b5f85a2d86598825 Mon Sep 17 00:00:00 2001 From: BIGZi0348 Date: Tue, 31 Dec 2024 17:27:15 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D1=80=D0=B0=D0=B1?= =?UTF-8?q?=D0=BE=D1=82=D0=BA=D0=B0=20=D1=80=D0=B0=D0=BD=D0=B4=D0=BE=D0=BC?= =?UTF-8?q?=D0=BD=D1=8B=D1=85=20=D0=B0=D1=80=D1=82=D0=B5=D1=84=D0=B0=D0=BA?= =?UTF-8?q?=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../XenoArtifacts/ArtifactSystem.Nodes.cs | 67 ++++++++++++++++++- .../XenoArtifacts/ArtifactSystem.cs | 14 ++++ .../RandomArtifacts/RandomArtifactsSystem.cs | 22 ++++-- .../XenoArtifacts/ArtifactEffectPrototype.cs | 6 ++ .../XenoArch/Effects/normal_effects.yml | 18 +++++ .../XenoArch/Effects/utility_effects.yml | 11 +++ 6 files changed, 129 insertions(+), 9 deletions(-) diff --git a/Content.Server/Xenoarchaeology/XenoArtifacts/ArtifactSystem.Nodes.cs b/Content.Server/Xenoarchaeology/XenoArtifacts/ArtifactSystem.Nodes.cs index 895bb0217b..9099d6d763 100644 --- a/Content.Server/Xenoarchaeology/XenoArtifacts/ArtifactSystem.Nodes.cs +++ b/Content.Server/Xenoarchaeology/XenoArtifacts/ArtifactSystem.Nodes.cs @@ -30,7 +30,7 @@ public sealed partial class ArtifactSystem _usedNodeIds.Clear(); - var uninitializedNodes = new List { new(){ Id = GetValidNodeId() } }; + var uninitializedNodes = new List { 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); } + + /// + /// WD. + /// Generate an Artifact tree with fully developed nodes. + /// + private void GenerateSafeArtifactNodeTree(EntityUid artifact, List 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 { 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); + } + } + + /// + /// WD. + /// + private string GetSafeRandomEffect(EntityUid artifact, ref ArtifactNode node) + { + var allEffects = _prototype.EnumeratePrototypes() + .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; + } } diff --git a/Content.Server/Xenoarchaeology/XenoArtifacts/ArtifactSystem.cs b/Content.Server/Xenoarchaeology/XenoArtifacts/ArtifactSystem.cs index a5469e93dc..253c42be03 100644 --- a/Content.Server/Xenoarchaeology/XenoArtifacts/ArtifactSystem.cs +++ b/Content.Server/Xenoarchaeology/XenoArtifacts/ArtifactSystem.cs @@ -295,4 +295,18 @@ public sealed partial class ArtifactSystem : EntitySystem { return allNodes.First(n => n.Depth == 0); } + + /// + /// WD. Randomize a given artifact. + /// + [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); + } } diff --git a/Content.Server/_White/RandomArtifacts/RandomArtifactsSystem.cs b/Content.Server/_White/RandomArtifacts/RandomArtifactsSystem.cs index 1ef1ac8f11..782b54ca79 100644 --- a/Content.Server/_White/RandomArtifacts/RandomArtifactsSystem.cs +++ b/Content.Server/_White/RandomArtifacts/RandomArtifactsSystem.cs @@ -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()) - { - QueueDel(oldArtifact.Owner); - } + // No we don't + // // Removing old artifact-items and replace it with new funny stealthy items + // foreach (var oldArtifact in EntityQuery()) + // { + // QueueDel(oldArtifact.Owner); + // } var items = EntityQuery().ToList(); _random.Shuffle(items); @@ -55,8 +58,13 @@ public sealed class RandomArtifactsSystem : EntitySystem if (!HasComp(station)) continue; + if (HasComp(entity)) + continue; + var artifactComponent = EnsureComp(entity); - _artifactsSystem.RandomizeArtifact(entity, artifactComponent); + _artifactsSystem.SafeRandomizeArtifact(entity, artifactComponent); + + EnsureComp(entity); } } diff --git a/Content.Shared/Xenoarchaeology/XenoArtifacts/ArtifactEffectPrototype.cs b/Content.Shared/Xenoarchaeology/XenoArtifacts/ArtifactEffectPrototype.cs index f3c3e6d470..933be64a79 100644 --- a/Content.Shared/Xenoarchaeology/XenoArtifacts/ArtifactEffectPrototype.cs +++ b/Content.Shared/Xenoarchaeology/XenoArtifacts/ArtifactEffectPrototype.cs @@ -41,4 +41,10 @@ public sealed partial class ArtifactEffectPrototype : IPrototype [DataField("blacklist")] public EntityWhitelist? Blacklist; + + /// + /// WD. Is it safe for random items? + /// + [DataField] + public bool Safe = false; } diff --git a/Resources/Prototypes/XenoArch/Effects/normal_effects.yml b/Resources/Prototypes/XenoArch/Effects/normal_effects.yml index 493f6dd840..db3240dc4b 100644 --- a/Resources/Prototypes/XenoArch/Effects/normal_effects.yml +++ b/Resources/Prototypes/XenoArch/Effects/normal_effects.yml @@ -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 diff --git a/Resources/Prototypes/XenoArch/Effects/utility_effects.yml b/Resources/Prototypes/XenoArch/Effects/utility_effects.yml index 84df09af33..015af7f7b8 100644 --- a/Resources/Prototypes/XenoArch/Effects/utility_effects.yml +++ b/Resources/Prototypes/XenoArch/Effects/utility_effects.yml @@ -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