Merge remote-tracking branch 'upstream/master' into fucking-upstream

This commit is contained in:
Jabak
2024-08-24 13:13:56 +03:00
2222 changed files with 247186 additions and 50848 deletions

View File

@@ -19,26 +19,46 @@ public sealed partial class ArtifactSystem
/// </summary>
/// <param name="artifact"></param>
/// <param name="allNodes"></param>
/// <param name="nodeAmount">The amount of nodes it has.</param>
private void GenerateArtifactNodeTree(EntityUid artifact, ref List<ArtifactNode> allNodes, int nodeAmount)
/// <param name="nodesToCreate">The amount of nodes it has.</param>
private void GenerateArtifactNodeTree(EntityUid artifact, List<ArtifactNode> allNodes, int nodesToCreate)
{
if (nodeAmount < 1)
if (nodesToCreate < 1)
{
Log.Error($"nodeAmount {nodeAmount} is less than 1. Aborting artifact tree generation.");
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;
var rootNode = new ArtifactNode
while (uninitializedNodes.Count > 0)
{
Id = GetValidNodeId()
};
var uninitializedNodes = new List<ArtifactNode> { rootNode };
while (uninitializedNodes.Any())
{
GenerateNode(artifact, ref uninitializedNodes, ref allNodes, nodeAmount);
var node = uninitializedNodes[0];
uninitializedNodes.Remove(node);
node.Trigger = GetRandomTrigger(artifact, ref node);
node.Effect = GetRandomEffect(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);
}
}
@@ -51,46 +71,10 @@ public sealed partial class ArtifactSystem
}
_usedNodeIds.Add(id);
return id;
}
/// <summary>
/// Generate an individual node on the tree.
/// </summary>
private void GenerateNode(EntityUid artifact, ref List<ArtifactNode> uninitializedNodes, ref List<ArtifactNode> allNodes, int targetNodeAmount)
{
if (!uninitializedNodes.Any())
return;
var node = uninitializedNodes.First();
uninitializedNodes.Remove(node);
//Generate the connected nodes
var maxEdges = Math.Max(1, targetNodeAmount - allNodes.Count - uninitializedNodes.Count - 1);
maxEdges = Math.Min(maxEdges, MaxEdgesPerNode);
var minEdges = Math.Clamp(targetNodeAmount - allNodes.Count - uninitializedNodes.Count - 1, 0, 1);
var edgeAmount = _random.Next(minEdges, maxEdges);
for (var i = 0; i < edgeAmount; i++)
{
var neighbor = new ArtifactNode
{
Depth = node.Depth + 1,
Id = GetValidNodeId()
};
node.Edges.Add(neighbor.Id);
neighbor.Edges.Add(node.Id);
uninitializedNodes.Add(neighbor);
}
node.Trigger = GetRandomTrigger(artifact, ref node);
node.Effect = GetRandomEffect(artifact, ref node);
allNodes.Add(node);
}
//yeah these two functions are near duplicates but i don't
//want to implement an interface or abstract parent
@@ -159,6 +143,7 @@ public sealed partial class ArtifactSystem
return key;
}
}
return _random.Pick(weights.Keys); //shouldn't happen
}

View File

@@ -130,7 +130,7 @@ public sealed partial class ArtifactSystem : EntitySystem
{
var nodeAmount = _random.Next(component.NodesMin, component.NodesMax);
GenerateArtifactNodeTree(uid, ref component.NodeTree, nodeAmount);
GenerateArtifactNodeTree(uid, component.NodeTree, nodeAmount);
var firstNode = GetRootNode(component.NodeTree);
EnterNode(uid, ref firstNode, component);
}
@@ -185,13 +185,14 @@ public sealed partial class ArtifactSystem : EntitySystem
var currentNode = GetNodeFromId(component.CurrentNodeId.Value, component);
currentNode.Triggered = true;
if (currentNode.Edges.Any())
{
var newNode = GetNewNode(uid, component);
if (newNode == null)
return;
EnterNode(uid, ref newNode, component);
}
if (currentNode.Edges.Count == 0)
return;
var newNode = GetNewNode(uid, component);
if (newNode == null)
return;
EnterNode(uid, ref newNode, component);
}
private ArtifactNode? GetNewNode(EntityUid uid, ArtifactComponent component)
@@ -211,15 +212,15 @@ public sealed partial class ArtifactSystem : EntitySystem
{
switch (trav.BiasDirection)
{
case BiasDirection.In:
var foo = allNodes.Where(x => GetNodeFromId(x, component).Depth < currentNode.Depth).ToHashSet();
if (foo.Any())
allNodes = foo;
case BiasDirection.Up:
var upNodes = allNodes.Where(x => GetNodeFromId(x, component).Depth < currentNode.Depth).ToHashSet();
if (upNodes.Count != 0)
allNodes = upNodes;
break;
case BiasDirection.Out:
var bar = allNodes.Where(x => GetNodeFromId(x, component).Depth > currentNode.Depth).ToHashSet();
if (bar.Any())
allNodes = bar;
case BiasDirection.Down:
var downNodes = allNodes.Where(x => GetNodeFromId(x, component).Depth > currentNode.Depth).ToHashSet();
if (downNodes.Count != 0)
allNodes = downNodes;
break;
}
}
@@ -227,12 +228,14 @@ public sealed partial class ArtifactSystem : EntitySystem
var undiscoveredNodes = allNodes.Where(x => !GetNodeFromId(x, component).Discovered).ToList();
Log.Debug($"Undiscovered nodes: {string.Join(", ", undiscoveredNodes)}");
var newNode = _random.Pick(allNodes);
if (undiscoveredNodes.Any() && _random.Prob(0.75f))
if (undiscoveredNodes.Count != 0 && _random.Prob(0.75f))
{
newNode = _random.Pick(undiscoveredNodes);
}
Log.Debug($"Going to node {newNode}");
return GetNodeFromId(newNode, component);
}

View File

@@ -1,12 +1,14 @@
using Content.Server.Emp;
using Content.Server.Xenoarchaeology.XenoArtifacts.Effects.Components;
using Content.Server.Xenoarchaeology.XenoArtifacts.Events;
using Robust.Server.GameObjects;
namespace Content.Server.Xenoarchaeology.XenoArtifacts.Effects.Systems;
public sealed class EmpArtifactSystem : EntitySystem
{
[Dependency] private readonly EmpSystem _emp = default!;
[Dependency] private readonly TransformSystem _transform = default!;
/// <inheritdoc/>
public override void Initialize()
@@ -16,6 +18,6 @@ public sealed class EmpArtifactSystem : EntitySystem
private void OnActivate(EntityUid uid, EmpArtifactComponent component, ArtifactActivatedEvent args)
{
_emp.EmpPulse(Transform(uid).MapPosition, component.Range, component.EnergyConsumption, component.DisableDuration);
_emp.EmpPulse(_transform.GetMapCoordinates(uid), component.Range, component.EnergyConsumption, component.DisableDuration);
}
}
}

View File

@@ -2,6 +2,7 @@
using Content.Server.Atmos.EntitySystems;
using Content.Server.Xenoarchaeology.XenoArtifacts.Effects.Components;
using Content.Server.Xenoarchaeology.XenoArtifacts.Events;
using Content.Shared.Atmos;
namespace Content.Server.Xenoarchaeology.XenoArtifacts.Effects.Systems;

View File

@@ -35,8 +35,7 @@ public sealed class PortalArtifactSystem : EntitySystem
var secondPortal = Spawn(artifact.Comp.PortalProto, _transform.GetMapCoordinates(target));
//Manual position swapping, because the portal that opens doesn't trigger a collision, and doesn't teleport targets the first time.
_transform.SetCoordinates(artifact, Transform(secondPortal).Coordinates);
_transform.SetCoordinates(target, Transform(firstPortal).Coordinates);
_transform.SwapPositions(target, secondPortal);
_link.TryLink(firstPortal, secondPortal, true);
}

View File

@@ -22,7 +22,6 @@ public sealed class ShuffleArtifactSystem : EntitySystem
{
var mobState = GetEntityQuery<MobStateComponent>();
List<EntityCoordinates> allCoords = new();
List<Entity<TransformComponent>> toShuffle = new();
foreach (var ent in _lookup.GetEntitiesInRange(uid, component.Radius, LookupFlags.Dynamic | LookupFlags.Sundries))
@@ -33,13 +32,15 @@ public sealed class ShuffleArtifactSystem : EntitySystem
var xform = Transform(ent);
toShuffle.Add((ent, xform));
allCoords.Add(xform.Coordinates);
}
foreach (var xform in toShuffle)
_random.Shuffle(toShuffle);
while (toShuffle.Count > 1)
{
var xformUid = xform.Owner;
_xform.SetCoordinates(xformUid, xform, _random.PickAndTake(allCoords));
var ent1 = _random.PickAndTake(toShuffle);
var ent2 = _random.PickAndTake(toShuffle);
_xform.SwapPositions((ent1, ent1), (ent2, ent2));
}
}
}

View File

@@ -32,7 +32,7 @@ public sealed class SpawnArtifactSystem : EntitySystem
if (component.Spawns is not {} spawns)
return;
var artifactCord = Transform(uid).MapPosition;
var artifactCord = _transform.GetMapCoordinates(uid);
foreach (var spawn in EntitySpawnCollection.GetSpawns(spawns, _random))
{
var dx = _random.NextFloat(-component.Range, component.Range);

View File

@@ -2,6 +2,7 @@
using Content.Server.Atmos.EntitySystems;
using Content.Server.Xenoarchaeology.XenoArtifacts.Effects.Components;
using Content.Server.Xenoarchaeology.XenoArtifacts.Events;
using Content.Shared.Atmos;
using Robust.Server.GameObjects;
namespace Content.Server.Xenoarchaeology.XenoArtifacts.Effects.Systems;

View File

@@ -4,6 +4,7 @@ using Content.Server.Xenoarchaeology.XenoArtifacts.Events;
using Content.Shared.Maps;
using Content.Shared.Physics;
using Content.Shared.Throwing;
using Robust.Server.GameObjects;
using Robust.Shared.Map.Components;
using Robust.Shared.Physics.Components;
using Robust.Shared.Random;
@@ -16,6 +17,7 @@ public sealed class ThrowArtifactSystem : EntitySystem
[Dependency] private readonly EntityLookupSystem _lookup = default!;
[Dependency] private readonly ThrowingSystem _throwing = default!;
[Dependency] private readonly TileSystem _tile = default!;
[Dependency] private readonly TransformSystem _transform = default!;
/// <inheritdoc/>
public override void Initialize()
@@ -50,7 +52,7 @@ public sealed class ThrowArtifactSystem : EntitySystem
var tempXform = Transform(ent);
var foo = tempXform.MapPosition.Position - xform.MapPosition.Position;
var foo = _transform.GetMapCoordinates(ent, xform: tempXform).Position - _transform.GetMapCoordinates(uid, xform: xform).Position;
_throwing.TryThrow(ent, foo*2, component.ThrowStrength, uid, 0);
}
}

View File

@@ -1,5 +1,6 @@
using Content.Server.Xenoarchaeology.XenoArtifacts.Triggers.Components;
using Content.Shared.Examine;
using Content.Shared.Ghost;
namespace Content.Server.Xenoarchaeology.XenoArtifacts.Triggers.Systems;
@@ -15,6 +16,10 @@ public sealed class ArtifactExamineTriggerSystem : EntitySystem
private void OnExamine(EntityUid uid, ArtifactExamineTriggerComponent component, ExaminedEvent args)
{
// Prevent ghosts from activating this trigger unless they have CanGhostInteract
if (TryComp<GhostComponent>(args.Examiner, out var ghost) && !ghost.CanGhostInteract)
return;
_artifact.TryActivateArtifact(uid);
}
}