mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-24 17:18:14 +03:00
## Mirror of PR #26287: [Code cleanup: Purge obsoleted SharedPhysicsSystem methods](https://github.com/space-wizards/space-station-14/pull/26287) from <img src="https://avatars.githubusercontent.com/u/10567778?v=4" alt="space-wizards" width="22"/> [space-wizards](https://github.com/space-wizards)/[space-station-14](https://github.com/space-wizards/space-station-14) ###### `964c6d54caae45b205a326143f56d6458a1bbc8a` PR opened by <img src="https://avatars.githubusercontent.com/u/85356?v=4" width="16"/><a href="https://github.com/Tayrtahn"> Tayrtahn</a> at 2024-03-20 13:37:25 UTC --- PR changed 16 files with 43 additions and 43 deletions. The PR had the following labels: - Status: Needs Review --- <details open="true"><summary><h1>Original Body</h1></summary> > <!-- Please read these guidelines before opening your PR: https://docs.spacestation14.io/en/getting-started/pr-guideline --> > <!-- The text between the arrows are comments - they will not be visible on your PR. --> > > Requires https://github.com/space-wizards/RobustToolbox/pull/4979 > > ## About the PR > <!-- What did you change in this PR? --> > Cleans up some obsolete method calls. > > ## Why / Balance / Technical > <!-- Why was it changed? Link any discussions or issues here. Please discuss how this would affect game balance. --> > Cleaning up obsolete Dirty calls in RT required changing the signatures of some public methods in SharedPhysicsSystem. This updates the calls to those methods here in Content to use the new signatures passing in UIDs. > > </details> Co-authored-by: SimpleStation14 <Unknown>
85 lines
3.4 KiB
C#
85 lines
3.4 KiB
C#
using System.Numerics;
|
|
using Content.Server.GameTicking.Rules.Components;
|
|
using Content.Server.StationEvents.Components;
|
|
using Robust.Shared.Map;
|
|
using Robust.Shared.Map.Components;
|
|
using Robust.Shared.Physics.Components;
|
|
using Robust.Shared.Physics.Systems;
|
|
using Robust.Shared.Spawners;
|
|
|
|
namespace Content.Server.StationEvents.Events
|
|
{
|
|
public sealed class MeteorSwarmRule : StationEventSystem<MeteorSwarmRuleComponent>
|
|
{
|
|
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
|
|
|
|
protected override void Started(EntityUid uid, MeteorSwarmRuleComponent component, GameRuleComponent gameRule, GameRuleStartedEvent args)
|
|
{
|
|
base.Started(uid, component, gameRule, args);
|
|
|
|
component.WaveCounter = RobustRandom.Next(component.MinimumWaves, component.MaximumWaves);
|
|
}
|
|
|
|
protected override void ActiveTick(EntityUid uid, MeteorSwarmRuleComponent component, GameRuleComponent gameRule, float frameTime)
|
|
{
|
|
if (component.WaveCounter <= 0)
|
|
{
|
|
ForceEndSelf(uid, gameRule);
|
|
return;
|
|
}
|
|
|
|
component.Cooldown -= frameTime;
|
|
|
|
if (component.Cooldown > 0f)
|
|
return;
|
|
|
|
component.WaveCounter--;
|
|
|
|
component.Cooldown += (component.MaximumCooldown - component.MinimumCooldown) * RobustRandom.NextFloat() + component.MinimumCooldown;
|
|
|
|
Box2? playableArea = null;
|
|
var mapId = GameTicker.DefaultMap;
|
|
|
|
var query = AllEntityQuery<MapGridComponent, TransformComponent>();
|
|
while (query.MoveNext(out var gridId, out _, out var xform))
|
|
{
|
|
if (xform.MapID != mapId)
|
|
continue;
|
|
|
|
var aabb = _physics.GetWorldAABB(gridId);
|
|
playableArea = playableArea?.Union(aabb) ?? aabb;
|
|
}
|
|
|
|
if (playableArea == null)
|
|
{
|
|
ForceEndSelf(uid, gameRule);
|
|
return;
|
|
}
|
|
|
|
var minimumDistance = (playableArea.Value.TopRight - playableArea.Value.Center).Length() + 50f;
|
|
var maximumDistance = minimumDistance + 100f;
|
|
|
|
var center = playableArea.Value.Center;
|
|
|
|
for (var i = 0; i < component.MeteorsPerWave; i++)
|
|
{
|
|
var angle = new Angle(RobustRandom.NextFloat() * MathF.Tau);
|
|
var offset = angle.RotateVec(new Vector2((maximumDistance - minimumDistance) * RobustRandom.NextFloat() + minimumDistance, 0));
|
|
var spawnPosition = new MapCoordinates(center + offset, mapId);
|
|
var meteor = Spawn("MeteorLarge", spawnPosition);
|
|
var physics = EntityManager.GetComponent<PhysicsComponent>(meteor);
|
|
_physics.SetBodyStatus(meteor, physics, BodyStatus.InAir);
|
|
_physics.SetLinearDamping(meteor, physics, 0f);
|
|
_physics.SetAngularDamping(meteor, physics, 0f);
|
|
_physics.ApplyLinearImpulse(meteor, -offset.Normalized() * component.MeteorVelocity * physics.Mass, body: physics);
|
|
_physics.ApplyAngularImpulse(
|
|
meteor,
|
|
physics.Mass * ((component.MaxAngularVelocity - component.MinAngularVelocity) * RobustRandom.NextFloat() + component.MinAngularVelocity),
|
|
body: physics);
|
|
|
|
EnsureComp<TimedDespawnComponent>(meteor).Lifetime = 120f;
|
|
}
|
|
}
|
|
}
|
|
}
|