Clean up vending machines and port their visualizer (#10465)

This commit is contained in:
Andreas Kämper
2022-08-31 14:12:09 +02:00
committed by GitHub
parent 6b0e03e0d7
commit 42f3155c85
62 changed files with 873 additions and 850 deletions

View File

@@ -1,6 +1,4 @@
using Content.Server.VendingMachines;
using Content.Shared.Throwing;
using Robust.Shared.Random;
namespace Content.Server.Destructible.Thresholds.Behaviors
{
@@ -30,17 +28,15 @@ namespace Content.Server.Destructible.Thresholds.Behaviors
!system.EntityManager.TryGetComponent<TransformComponent>(owner, out var xform))
return;
var throwingsys = system.EntityManager.EntitySysManager.GetEntitySystem<ThrowingSystem>();
var totalItems = vendingcomp.AllInventory.Count;
var vendingMachineSystem = EntitySystem.Get<VendingMachineSystem>();
var inventory = vendingMachineSystem.GetAvailableInventory(owner, vendingcomp);
if (inventory.Count <= 0)
return;
var toEject = Math.Min(totalItems * Percent, Max);
var toEject = Math.Min(inventory.Count * Percent, Max);
for (var i = 0; i < toEject; i++)
{
var entity = system.EntityManager.SpawnEntity(system.Random.PickAndTake(vendingcomp.AllInventory).ID, xform.Coordinates);
float range = vendingcomp.NonLimitedEjectRange;
Vector2 direction = new Vector2(system.Random.NextFloat(-range, range), system.Random.NextFloat(-range, range));
throwingsys.TryThrow(entity, direction, vendingcomp.NonLimitedEjectForce);
vendingMachineSystem.EjectRandom(owner, throwItem: true, forceEject: true, vendingcomp);
}
}
}