Reduce resolve and cut more corners in destructible (#6741)

This commit is contained in:
Leon Friedrich
2022-02-17 15:39:56 +13:00
committed by GitHub
parent 04f29727d9
commit 00c3a181d3
8 changed files with 83 additions and 15 deletions

View File

@@ -1,12 +1,12 @@
using Content.Server.Construction;
using Content.Server.Destructible.Thresholds;
using Content.Server.Explosion.EntitySystems;
using Content.Server.Stack;
using Content.Shared.Acts;
using Content.Shared.Damage;
using JetBrains.Annotations;
using Robust.Server.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
namespace Content.Server.Destructible
@@ -21,6 +21,9 @@ namespace Content.Server.Destructible
[Dependency] public readonly AudioSystem AudioSystem = default!;
[Dependency] public readonly ConstructionSystem ConstructionSystem = default!;
[Dependency] public readonly ExplosionSystem ExplosionSystem = default!;
[Dependency] public readonly StackSystem StackSystem = default!;
[Dependency] public readonly IPrototypeManager PrototypeManager = default!;
[Dependency] public readonly IComponentFactory ComponentFactory = default!;
public override void Initialize()
{

View File

@@ -1,11 +1,5 @@
using System;
using System.Collections.Generic;
using Content.Server.Stack;
using Content.Shared.Prototypes;
using Content.Shared.Random.Helpers;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Serialization.Manager.Attributes;
namespace Content.Server.Destructible.Thresholds.Behaviors
{
@@ -26,6 +20,8 @@ namespace Content.Server.Destructible.Thresholds.Behaviors
{
var position = system.EntityManager.GetComponent<TransformComponent>(owner).MapPosition;
var getRandomVector = () => new Vector2(system.Random.NextFloat(-Offset, Offset), system.Random.NextFloat(-Offset, Offset));
foreach (var (entityId, minMax) in Spawn)
{
var count = minMax.Min >= minMax.Max
@@ -34,19 +30,16 @@ namespace Content.Server.Destructible.Thresholds.Behaviors
if (count == 0) continue;
if (EntityPrototypeHelpers.HasComponent<StackComponent>(entityId))
if (EntityPrototypeHelpers.HasComponent<StackComponent>(entityId, system.PrototypeManager, system.ComponentFactory))
{
var spawned = system.EntityManager.SpawnEntity(entityId, position);
var stack = IoCManager.Resolve<IEntityManager>().GetComponent<StackComponent>(spawned);
EntitySystem.Get<StackSystem>().SetCount(spawned, count, stack);
spawned.RandomOffset(Offset);
var spawned = system.EntityManager.SpawnEntity(entityId, position.Offset(getRandomVector()));
system.StackSystem.SetCount(spawned, count);
}
else
{
for (var i = 0; i < count; i++)
{
var spawned = system.EntityManager.SpawnEntity(entityId, position);
spawned.RandomOffset(Offset);
system.EntityManager.SpawnEntity(entityId, position.Offset(getRandomVector()));
}
}
}