# Conflicts: # Content.Client/Administration/UI/Tabs/ObjectsTab/ObjectsTab.xaml.cs # Content.Client/Administration/UI/Tabs/ObjectsTab/ObjectsTabEntry.xaml # Content.Client/Administration/UI/Tabs/ObjectsTab/ObjectsTabEntry.xaml.cs # Content.IntegrationTests/Tests/PostMapInitTest.cs # Content.Server/Chat/Systems/ChatSystem.cs # Content.Server/Clothing/Components/GloveHeatResistanceComponent.cs # Content.Server/Light/EntitySystems/PoweredLightSystem.cs # Content.Server/Medical/HealthAnalyzerSystem.cs # Content.Server/Medical/SuitSensors/SuitSensorComponent.cs # Content.Server/StationEvents/Events/MeteorSwarmSystem.cs # Content.Server/StationEvents/Events/StationEventSystem.cs # Content.Shared/Actions/SharedActionsSystem.cs # Content.Shared/Interaction/SharedInteractionSystem.cs # Resources/Prototypes/AlertLevels/alert_levels.yml # Resources/Prototypes/Catalog/Fills/Lockers/heads.yml # Resources/Prototypes/Catalog/Fills/Lockers/misc.yml # Resources/Prototypes/Catalog/VendingMachines/Inventories/engivend.yml # Resources/Prototypes/Datasets/Names/fortunes.yml # Resources/Prototypes/Datasets/ion_storm.yml # Resources/Prototypes/Entities/Clothing/Neck/mantles.yml # Resources/Prototypes/Entities/Clothing/Uniforms/jumpsuits.yml # Resources/Prototypes/Entities/Markers/Spawners/Random/maintenance.yml # Resources/Prototypes/Entities/Mobs/Cyborgs/base_borg_chassis.yml # Resources/Prototypes/Entities/Objects/Fun/pai.yml # Resources/Prototypes/Entities/Objects/Misc/identification_cards.yml # Resources/Prototypes/Entities/Objects/Specific/Medical/handheld_crew_monitor.yml # Resources/Prototypes/Entities/Structures/Machines/lathe.yml # Resources/Prototypes/GameRules/events.yml # Resources/Prototypes/Loadouts/Jobs/Science/research_director.yml # Resources/Prototypes/Recipes/Lathes/clothing.yml # Resources/Prototypes/game_presets.yml # Resources/Prototypes/secret_weights.yml # Resources/ServerInfo/Guidebook/Engineering/Singularity.xml # Resources/Textures/Clothing/Head/Helmets/security.rsi/equipped-HELMET-vox.png # Resources/Textures/Clothing/Head/Helmets/security.rsi/equipped-HELMET.png # Resources/Textures/Clothing/Head/Helmets/security.rsi/icon.png # Resources/Textures/Clothing/Head/Helmets/security.rsi/inhand-left.png # Resources/Textures/Clothing/Head/Helmets/security.rsi/inhand-right.png # Resources/Textures/Clothing/Head/Helmets/security.rsi/meta.json # Resources/Textures/Clothing/Mask/ert.rsi/meta.json # Resources/Textures/Clothing/Mask/joy.rsi/meta.json # Resources/Textures/Clothing/Mask/squadron.rsi/meta.json # Resources/Textures/Clothing/Neck/Cloaks/cmo.rsi/equipped-NECK.png # Resources/Textures/Clothing/Neck/Cloaks/cmo.rsi/meta.json # Resources/Textures/Clothing/OuterClothing/Armor/security.rsi/equipped-OUTERCLOTHING.png # Resources/Textures/Clothing/OuterClothing/Armor/security.rsi/icon.png # Resources/Textures/Clothing/OuterClothing/Armor/security.rsi/meta.json # Resources/Textures/Clothing/OuterClothing/Hardsuits/medical.rsi/inhand-left.png # Resources/Textures/Clothing/OuterClothing/Hardsuits/medical.rsi/inhand-right.png # Resources/Textures/Clothing/Uniforms/Jumpsuit/hos_alt.rsi/equipped-INNERCLOTHING.png # Resources/Textures/Objects/Specific/Hydroponics/aloe.rsi/produce.png # Resources/Textures/Objects/Specific/Hydroponics/apple.rsi/produce.png # Resources/Textures/Objects/Specific/Hydroponics/cannabis.rsi/produce.png # Resources/Textures/Objects/Tools/crowbar.rsi/meta.json # Resources/Textures/Objects/Tools/crowbar.rsi/red-icon.png # Resources/Textures/Objects/Tools/crowbar.rsi/red-storage.png # Resources/Textures/Structures/Wallmounts/Lighting/light_tube.rsi/base.png # Resources/Textures/Structures/Wallmounts/Lighting/light_tube.rsi/broken.png # Resources/Textures/Structures/Wallmounts/Lighting/light_tube.rsi/burned.png # Resources/Textures/Structures/Wallmounts/Lighting/light_tube.rsi/empty.png # Resources/Textures/Structures/Wallmounts/Lighting/light_tube.rsi/glow.png # Resources/Textures/Structures/Wallmounts/Lighting/light_tube.rsi/meta.json # Resources/migration.yml
100 lines
4 KiB
C#
100 lines
4 KiB
C#
using System.Numerics;
|
|
using Content.Server._Sunrise.Station;
|
|
using Content.Server.Chat.Systems;
|
|
using Content.Server.GameTicking.Rules;
|
|
using Content.Server.Station.Components;
|
|
using Content.Server.Station.Systems;
|
|
using Content.Server.StationEvents.Components;
|
|
using Content.Shared.GameTicking.Components;
|
|
using Content.Shared.Random.Helpers;
|
|
using Robust.Shared.Map;
|
|
using Robust.Shared.Physics.Components;
|
|
using Robust.Shared.Physics.Systems;
|
|
using Robust.Shared.Random;
|
|
|
|
namespace Content.Server.StationEvents.Events;
|
|
|
|
public sealed class MeteorSwarmSystem : GameRuleSystem<MeteorSwarmComponent>
|
|
{
|
|
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
|
|
[Dependency] private readonly ChatSystem _chat = default!;
|
|
[Dependency] private readonly StationSystem _station = default!;
|
|
|
|
protected override void Added(EntityUid uid, MeteorSwarmComponent component, GameRuleComponent gameRule, GameRuleAddedEvent args)
|
|
{
|
|
base.Added(uid, component, gameRule, args);
|
|
|
|
component.WaveCounter = component.Waves.Next(RobustRandom);
|
|
|
|
// we don't want to send to players who aren't in game (i.e. in the lobby)
|
|
Filter allPlayersInGame = Filter.Empty().AddWhere(GameTicker.UserHasJoinedGame);
|
|
|
|
if (component.Announcement is { } locId)
|
|
_chat.DispatchFilteredAnnouncement(allPlayersInGame, Loc.GetString(locId), playSound: false, colorOverride: Color.Gold);
|
|
|
|
_audio.PlayGlobal(component.AnnouncementSound, allPlayersInGame, true);
|
|
}
|
|
|
|
protected override void ActiveTick(EntityUid uid, MeteorSwarmComponent component, GameRuleComponent gameRule, float frameTime)
|
|
{
|
|
if (Timing.CurTime < component.NextWaveTime)
|
|
return;
|
|
|
|
component.NextWaveTime += TimeSpan.FromSeconds(component.WaveCooldown.Next(RobustRandom));
|
|
|
|
var stations = _station.GetStations();
|
|
|
|
var validStations = new List<EntityUid>();
|
|
|
|
foreach (var entityUid in stations)
|
|
{
|
|
if (HasComp<StationMeteorSwarmTargetComponent>(entityUid))
|
|
validStations.Add(entityUid);
|
|
}
|
|
|
|
if (validStations.Count == 0)
|
|
return;
|
|
|
|
var station = RobustRandom.Pick(validStations);
|
|
if (_station.GetLargestGrid(Comp<StationDataComponent>(station)) is not { } grid)
|
|
return;
|
|
|
|
var mapId = Transform(grid).MapID;
|
|
var playableArea = _physics.GetWorldAABB(grid);
|
|
|
|
var minimumDistance = (playableArea.TopRight - playableArea.Center).Length() + 50f;
|
|
var maximumDistance = minimumDistance + 100f;
|
|
|
|
var center = playableArea.Center;
|
|
|
|
var meteorsToSpawn = component.MeteorsPerWave.Next(RobustRandom);
|
|
for (var i = 0; i < meteorsToSpawn; i++)
|
|
{
|
|
var spawnProto = RobustRandom.Pick(component.Meteors);
|
|
|
|
var angle = component.NonDirectional
|
|
? RobustRandom.NextAngle()
|
|
: new Random(uid.Id).NextAngle();
|
|
|
|
var offset = angle.RotateVec(new Vector2((maximumDistance - minimumDistance) * RobustRandom.NextFloat() + minimumDistance, 0));
|
|
|
|
// the line at which spawns occur is perpendicular to the offset.
|
|
// This means the meteors are less likely to bunch up and hit the same thing.
|
|
var subOffsetAngle = RobustRandom.Prob(0.5f)
|
|
? angle + Math.PI / 2
|
|
: angle - Math.PI / 2;
|
|
var subOffset = subOffsetAngle.RotateVec(new Vector2( (playableArea.TopRight - playableArea.Center).Length() / 3 * RobustRandom.NextFloat(), 0));
|
|
|
|
var spawnPosition = new MapCoordinates(center + offset + subOffset, mapId);
|
|
var meteor = Spawn(spawnProto, spawnPosition);
|
|
var physics = Comp<PhysicsComponent>(meteor);
|
|
_physics.ApplyLinearImpulse(meteor, -offset.Normalized() * component.MeteorVelocity * physics.Mass, body: physics);
|
|
}
|
|
|
|
component.WaveCounter--;
|
|
if (component.WaveCounter <= 0)
|
|
{
|
|
ForceEndSelf(uid, gameRule);
|
|
}
|
|
}
|
|
}
|