Skip to content

Commit

Permalink
Merge branch 'master' into pr/DEATHB4DEFEAT/540
Browse files Browse the repository at this point in the history
  • Loading branch information
VMSolidus committed Jul 19, 2024
2 parents f825b86 + 5629494 commit 4cf0d13
Show file tree
Hide file tree
Showing 23 changed files with 554 additions and 120 deletions.
24 changes: 24 additions & 0 deletions Content.Server/Antag/Mimic/MobReplacementRuleComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,33 @@ public sealed partial class MobReplacementRuleComponent : Component
[DataField]
public EntProtoId Proto = "MobMimic";

[DataField]
public int NumberToReplace { get; set; }

[DataField]
public string Announcement = "station-event-rampant-intelligence-announcement";

/// <summary>
/// Chance per-entity.
/// </summary>
[DataField]
public float Chance = 0.001f;

[DataField]
public bool DoAnnouncement = true;

[DataField]
public float MimicMeleeDamage = 20f;

[DataField]
public float MimicMoveSpeed = 1f;

[DataField]
public string MimicAIType = "SimpleHostileCompound";

[DataField]
public bool MimicSmashGlass = true;

[DataField]
public bool VendorModify = true;
}
152 changes: 147 additions & 5 deletions Content.Server/Antag/MobReplacementRuleSystem.cs
Original file line number Diff line number Diff line change
@@ -1,37 +1,179 @@
using System.Numerics;
using Content.Server.Antag.Mimic;
using Content.Server.Chat.Systems;
using Content.Server.GameTicking.Rules;
using Content.Server.GameTicking.Rules.Components;
using Content.Server.NPC.Systems;
using Content.Server.Station.Systems;
using Content.Server.GameTicking;
using Content.Shared.VendingMachines;
using Robust.Shared.Map;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using Robust.Server.GameObjects;
using Robust.Shared.Physics.Systems;
using System.Linq;
using Robust.Shared.Physics;
using Content.Shared.Movement.Components;
using Content.Shared.Damage;
using Content.Server.NPC.HTN;
using Content.Server.NPC;
using Content.Shared.Weapons.Melee;
using Content.Server.Advertise;
using Content.Server.Power.Components;
using Content.Shared.CombatMode;

namespace Content.Server.Antag;

public sealed class MobReplacementRuleSystem : GameRuleSystem<MobReplacementRuleComponent>
{
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly StationSystem _station = default!;
[Dependency] private readonly GameTicker _gameTicker = default!;
[Dependency] private readonly ChatSystem _chat = default!;
[Dependency] private readonly IPrototypeManager _prototype = default!;
[Dependency] private readonly IComponentFactory _componentFactory = default!;
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
[Dependency] private readonly NpcFactionSystem _npcFaction = default!;
[Dependency] private readonly NPCSystem _npc = default!;
[Dependency] private readonly TransformSystem _transform = default!;
[Dependency] private readonly AdvertiseSystem _advertise = default!;

Check failure on line 40 in Content.Server/Antag/MobReplacementRuleSystem.cs

View workflow job for this annotation

GitHub Actions / Test Packaging

The type or namespace name 'AdvertiseSystem' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 40 in Content.Server/Antag/MobReplacementRuleSystem.cs

View workflow job for this annotation

GitHub Actions / Test Packaging

The type or namespace name 'AdvertiseSystem' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 40 in Content.Server/Antag/MobReplacementRuleSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'AdvertiseSystem' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 40 in Content.Server/Antag/MobReplacementRuleSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'AdvertiseSystem' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 40 in Content.Server/Antag/MobReplacementRuleSystem.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

The type or namespace name 'AdvertiseSystem' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 40 in Content.Server/Antag/MobReplacementRuleSystem.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

The type or namespace name 'AdvertiseSystem' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 40 in Content.Server/Antag/MobReplacementRuleSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'AdvertiseSystem' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 40 in Content.Server/Antag/MobReplacementRuleSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'AdvertiseSystem' could not be found (are you missing a using directive or an assembly reference?)


protected override void Started(EntityUid uid, MobReplacementRuleComponent component, GameRuleComponent gameRule, GameRuleStartedEvent args)
{
base.Started(uid, component, gameRule, args);

var query = AllEntityQuery<VendingMachineComponent, TransformComponent>();
var spawns = new List<(EntityUid Entity, EntityCoordinates Coordinates)>();
var stations = _gameTicker.GetSpawnableStations();

while (query.MoveNext(out var vendingUid, out _, out var xform))
{
if (!_random.Prob(component.Chance))
var ownerStation = _station.GetOwningStation(vendingUid);

if (ownerStation == null
|| ownerStation != stations[0])
continue;

// Make sure that we aren't running this on something that is already a mimic
if (HasComp<CombatModeComponent>(vendingUid))
continue;

spawns.Add((vendingUid, xform.Coordinates));
}

foreach (var entity in spawns)
if (spawns == null)
{
var coordinates = entity.Coordinates;
Del(entity.Entity);
//WTF THE STATION DOESN'T EXIST! WE MUST BE IN A TEST! QUICK, PUT A MIMIC AT 0,0!!!
Spawn(component.Proto, new EntityCoordinates(uid, new Vector2(0, 0)));
}
else
{
// This is intentionally not clamped. If a server host wants to replace every vending machine in the entire station with a mimic, who am I to stop them?
var k = MathF.MaxMagnitude(component.NumberToReplace, 1);
while (k > 0 && spawns != null && spawns.Count > 0)
{
if (k > 1)
{
var spawnLocation = _random.PickAndTake(spawns);
BuildAMimicWorkshop(spawnLocation.Entity, component);
}
else
{
BuildAMimicWorkshop(spawns[0].Entity, component);
}

if (k == MathF.MaxMagnitude(component.NumberToReplace, 1)
&& component.DoAnnouncement)
_chat.DispatchStationAnnouncement(stations[0], Loc.GetString("station-event-rampant-intelligence-announcement"), playDefaultSound: true,
colorOverride: Color.Red, sender: "Central Command");

k--;
}
}
}

/// <summary>
/// It's like Build a Bear, but MURDER
/// </summary>
/// <param name="uid"></param>
public void BuildAMimicWorkshop(EntityUid uid, MobReplacementRuleComponent component)
{
var metaData = MetaData(uid);
var vendorPrototype = metaData.EntityPrototype;
var mimicProto = _prototype.Index<EntityPrototype>(component.Proto);

var vendorComponents = vendorPrototype?.Components.Keys
.Where(n => n != "Transform" && n != "MetaData")
.Select(name => (name, _componentFactory.GetRegistration(name).Type))
.ToList() ?? new List<(string name, Type type)>();

var mimicComponents = mimicProto?.Components.Keys
.Where(n => n != "Transform" && n != "MetaData")
.Select(name => (name, _componentFactory.GetRegistration(name).Type))
.ToList() ?? new List<(string name, Type type)>();

Spawn(component.Proto, coordinates);
foreach (var name in mimicComponents.Except(vendorComponents))
{
var newComponent = _componentFactory.GetComponent(name.name);
EntityManager.AddComponent(uid, newComponent);
}

var xform = Transform(uid);
if (xform.Anchored)
_transform.Unanchor(uid, xform);

SetupMimicNPC(uid, component);

if (TryComp<AdvertiseComponent>(uid, out var vendor)
&& component.VendorModify)
SetupMimicVendor(uid, component, vendor);
}
/// <summary>
/// This handles getting the entity ready to be a hostile NPC
/// </summary>
/// <param name="uid"></param>
/// <param name="component"></param>
private void SetupMimicNPC(EntityUid uid, MobReplacementRuleComponent component)
{
_physics.SetBodyType(uid, BodyType.KinematicController);
_npcFaction.AddFaction(uid, "SimpleHostile");

var melee = EnsureComp<MeleeWeaponComponent>(uid);
melee.Angle = 0;
DamageSpecifier dspec = new()
{
DamageDict = new()
{
{ "Blunt", component.MimicMeleeDamage }
}
};
melee.Damage = dspec;

var movementSpeed = EnsureComp<MovementSpeedModifierComponent>(uid);
(movementSpeed.BaseSprintSpeed, movementSpeed.BaseWalkSpeed) = (component.MimicMoveSpeed, component.MimicMoveSpeed);

var htn = EnsureComp<HTNComponent>(uid);
htn.RootTask = new HTNCompoundTask() { Task = component.MimicAIType };
htn.Blackboard.SetValue(NPCBlackboard.NavSmash, component.MimicSmashGlass);
_npc.WakeNPC(uid, htn);
}

/// <summary>
/// Handling specific interactions with vending machines
/// </summary>
/// <param name="uid"></param>
/// <param name="mimicComponent"></param>
/// <param name="vendorComponent"></param>
private void SetupMimicVendor(EntityUid uid, MobReplacementRuleComponent mimicComponent, AdvertiseComponent vendorComponent)

Check failure on line 169 in Content.Server/Antag/MobReplacementRuleSystem.cs

View workflow job for this annotation

GitHub Actions / Test Packaging

The type or namespace name 'AdvertiseComponent' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 169 in Content.Server/Antag/MobReplacementRuleSystem.cs

View workflow job for this annotation

GitHub Actions / Test Packaging

The type or namespace name 'AdvertiseComponent' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 169 in Content.Server/Antag/MobReplacementRuleSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'AdvertiseComponent' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 169 in Content.Server/Antag/MobReplacementRuleSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'AdvertiseComponent' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 169 in Content.Server/Antag/MobReplacementRuleSystem.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

The type or namespace name 'AdvertiseComponent' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 169 in Content.Server/Antag/MobReplacementRuleSystem.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

The type or namespace name 'AdvertiseComponent' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 169 in Content.Server/Antag/MobReplacementRuleSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'AdvertiseComponent' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 169 in Content.Server/Antag/MobReplacementRuleSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type or namespace name 'AdvertiseComponent' could not be found (are you missing a using directive or an assembly reference?)
{
vendorComponent.MinimumWait = 5;
vendorComponent.MaximumWait = 15;
_advertise.SayAdvertisement(uid, vendorComponent);
_advertise.RefreshTimer(uid, vendorComponent);

if (TryComp<ApcPowerReceiverComponent>(uid, out var aPC))
aPC.NeedsPower = false;
}
}
12 changes: 12 additions & 0 deletions Content.Server/Atmos/EntitySystems/AtmosphereSystem.CVars.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@ public sealed partial class AtmosphereSystem
public float SpaceWindPressureForceDivisorPush { get; private set; }
public float SpaceWindMaxVelocity { get; private set; }
public float SpaceWindMaxPushForce { get; private set; }
public float SpaceWindMinimumCalculatedMass { get; private set; }
public float SpaceWindMaximumCalculatedInverseMass { get; private set; }
public bool MonstermosUseExpensiveAirflow { get; private set; }
public bool MonstermosEqualization { get; private set; }
public bool MonstermosDepressurization { get; private set; }
public bool MonstermosRipTiles { get; private set; }
public float MonstermosRipTilesMinimumPressure { get; private set; }
public float MonstermosRipTilesPressureOffset { get; private set; }
public bool GridImpulse { get; private set; }
public float SpacingEscapeRatio { get; private set; }
public float SpacingMinGas { get; private set; }
Expand All @@ -26,6 +31,7 @@ public sealed partial class AtmosphereSystem
public float AtmosTickRate { get; private set; }
public float Speedup { get; private set; }
public float HeatScale { get; private set; }
public float HumanoidThrowMultiplier { get; private set; }

/// <summary>
/// Time between each atmos sub-update. If you are writing an atmos device, use AtmosDeviceUpdateEvent.dt
Expand All @@ -41,9 +47,14 @@ private void InitializeCVars()
Subs.CVar(_cfg, CCVars.SpaceWindPressureForceDivisorPush, value => SpaceWindPressureForceDivisorPush = value, true);
Subs.CVar(_cfg, CCVars.SpaceWindMaxVelocity, value => SpaceWindMaxVelocity = value, true);
Subs.CVar(_cfg, CCVars.SpaceWindMaxPushForce, value => SpaceWindMaxPushForce = value, true);
Subs.CVar(_cfg, CCVars.SpaceWindMinimumCalculatedMass, value => SpaceWindMinimumCalculatedMass = value, true);
Subs.CVar(_cfg, CCVars.SpaceWindMaximumCalculatedInverseMass, value => SpaceWindMaximumCalculatedInverseMass = value, true);
Subs.CVar(_cfg, CCVars.MonstermosUseExpensiveAirflow, value => MonstermosUseExpensiveAirflow = value, true);
Subs.CVar(_cfg, CCVars.MonstermosEqualization, value => MonstermosEqualization = value, true);
Subs.CVar(_cfg, CCVars.MonstermosDepressurization, value => MonstermosDepressurization = value, true);
Subs.CVar(_cfg, CCVars.MonstermosRipTiles, value => MonstermosRipTiles = value, true);
Subs.CVar(_cfg, CCVars.MonstermosRipTilesMinimumPressure, value => MonstermosRipTilesMinimumPressure = value, true);
Subs.CVar(_cfg, CCVars.MonstermosRipTilesPressureOffset, value => MonstermosRipTilesPressureOffset = value, true);
Subs.CVar(_cfg, CCVars.AtmosGridImpulse, value => GridImpulse = value, true);
Subs.CVar(_cfg, CCVars.AtmosSpacingEscapeRatio, value => SpacingEscapeRatio = value, true);
Subs.CVar(_cfg, CCVars.AtmosSpacingMinGas, value => SpacingMinGas = value, true);
Expand All @@ -55,6 +66,7 @@ private void InitializeCVars()
Subs.CVar(_cfg, CCVars.AtmosHeatScale, value => { HeatScale = value; InitializeGases(); }, true);
Subs.CVar(_cfg, CCVars.ExcitedGroups, value => ExcitedGroups = value, true);
Subs.CVar(_cfg, CCVars.ExcitedGroupsSpaceIsAllConsuming, value => ExcitedGroupsSpaceIsAllConsuming = value, true);
Subs.CVar(_cfg, CCVars.AtmosHumanoidThrowMultiplier, value => HumanoidThrowMultiplier = value, true);
}
}
}
Loading

0 comments on commit 4cf0d13

Please sign in to comment.