Revert "Gamerule Entities" (#15724)
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
using Content.Server.GameTicking;
|
||||
using Content.Server.GameTicking.Rules.Components;
|
||||
using Content.Server.Spawners.Components;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Random;
|
||||
@@ -23,67 +22,65 @@ namespace Content.Server.Spawners.EntitySystems
|
||||
|
||||
private void OnCondSpawnMapInit(EntityUid uid, ConditionalSpawnerComponent component, MapInitEvent args)
|
||||
{
|
||||
TrySpawn(uid, component);
|
||||
TrySpawn(component);
|
||||
}
|
||||
|
||||
private void OnRandSpawnMapInit(EntityUid uid, RandomSpawnerComponent component, MapInitEvent args)
|
||||
{
|
||||
Spawn(uid, component);
|
||||
QueueDel(uid);
|
||||
Spawn(component);
|
||||
EntityManager.QueueDeleteEntity(uid);
|
||||
}
|
||||
|
||||
private void OnRuleStarted(ref GameRuleStartedEvent args)
|
||||
private void OnRuleStarted(GameRuleStartedEvent args)
|
||||
{
|
||||
var query = EntityQueryEnumerator<ConditionalSpawnerComponent>();
|
||||
while (query.MoveNext(out var uid, out var spawner))
|
||||
foreach (var spawner in EntityManager.EntityQuery<ConditionalSpawnerComponent>())
|
||||
{
|
||||
RuleStarted(uid, spawner, args);
|
||||
RuleStarted(spawner, args);
|
||||
}
|
||||
}
|
||||
|
||||
public void RuleStarted(EntityUid uid, ConditionalSpawnerComponent component, GameRuleStartedEvent obj)
|
||||
public void RuleStarted(ConditionalSpawnerComponent component, GameRuleStartedEvent obj)
|
||||
{
|
||||
if (component.GameRules.Contains(obj.RuleId))
|
||||
Spawn(uid, component);
|
||||
if(component.GameRules.Contains(obj.Rule.ID))
|
||||
Spawn(component);
|
||||
}
|
||||
|
||||
private void TrySpawn(EntityUid uid, ConditionalSpawnerComponent component)
|
||||
private void TrySpawn(ConditionalSpawnerComponent component)
|
||||
{
|
||||
if (component.GameRules.Count == 0)
|
||||
{
|
||||
Spawn(uid, component);
|
||||
Spawn(component);
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var rule in component.GameRules)
|
||||
{
|
||||
if (!_ticker.IsGameRuleActive(rule))
|
||||
continue;
|
||||
Spawn(uid, component);
|
||||
if (!_ticker.IsGameRuleStarted(rule)) continue;
|
||||
Spawn(component);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private void Spawn(EntityUid uid, ConditionalSpawnerComponent component)
|
||||
private void Spawn(ConditionalSpawnerComponent component)
|
||||
{
|
||||
if (component.Chance != 1.0f && !_robustRandom.Prob(component.Chance))
|
||||
return;
|
||||
|
||||
if (component.Prototypes.Count == 0)
|
||||
{
|
||||
Logger.Warning($"Prototype list in ConditionalSpawnComponent is empty! Entity: {ToPrettyString(uid)}");
|
||||
Logger.Warning($"Prototype list in ConditionalSpawnComponent is empty! Entity: {component.Owner}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Deleted(uid))
|
||||
EntityManager.SpawnEntity(_robustRandom.Pick(component.Prototypes), Transform(uid).Coordinates);
|
||||
if (!Deleted(component.Owner))
|
||||
EntityManager.SpawnEntity(_robustRandom.Pick(component.Prototypes), Transform(component.Owner).Coordinates);
|
||||
}
|
||||
|
||||
private void Spawn(EntityUid uid, RandomSpawnerComponent component)
|
||||
private void Spawn(RandomSpawnerComponent component)
|
||||
{
|
||||
if (component.RarePrototypes.Count > 0 && (component.RareChance == 1.0f || _robustRandom.Prob(component.RareChance)))
|
||||
{
|
||||
EntityManager.SpawnEntity(_robustRandom.Pick(component.RarePrototypes), Transform(uid).Coordinates);
|
||||
EntityManager.SpawnEntity(_robustRandom.Pick(component.RarePrototypes), Transform(component.Owner).Coordinates);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -92,18 +89,17 @@ namespace Content.Server.Spawners.EntitySystems
|
||||
|
||||
if (component.Prototypes.Count == 0)
|
||||
{
|
||||
Logger.Warning($"Prototype list in RandomSpawnerComponent is empty! Entity: {ToPrettyString(uid)}");
|
||||
Logger.Warning($"Prototype list in RandomSpawnerComponent is empty! Entity: {component.Owner}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (Deleted(uid))
|
||||
return;
|
||||
if (Deleted(component.Owner)) return;
|
||||
|
||||
var offset = component.Offset;
|
||||
var xOffset = _robustRandom.NextFloat(-offset, offset);
|
||||
var yOffset = _robustRandom.NextFloat(-offset, offset);
|
||||
|
||||
var coordinates = Transform(uid).Coordinates.Offset(new Vector2(xOffset, yOffset));
|
||||
var coordinates = Transform(component.Owner).Coordinates.Offset(new Vector2(xOffset, yOffset));
|
||||
|
||||
EntityManager.SpawnEntity(_robustRandom.Pick(component.Prototypes), coordinates);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user