Files
space-station-14/Content.Server/Silicons/Borgs/BorgSystem.Transponder.cs
Samuka e5daa54e79 Xenoborgs part 7 (#40042)
* add mothership module

* option for mothership to open self UI

* fix mothership module

* remove mothership body

* swapp real hands for modules

* action sprite for mothership module

* removed hands from mothership core sprite

* xenoborgs now drop a pinpointer to the mothership core once destroyed

* add pinpointer to space movment module

* add base for XenoborgRule

* add xenoborg antag option

* something was needed

* something else was needed

* add ghost role spawn points

* change name in antag selection to Xenoborg Core

* add random spawnPoint markers that don't do anything

* add spawn points to mothership

* update spawn points

* add xenoborgs rule

* add xenoborgs rule to rotation

* add xenoborgs preset

* update preset with secret version
also added xenoborg mode description

* modify Antag Selection system to allow for custom entities via the AntagSelectionDefinition

* fix ghostroles spawners

* fix rule with new entityPrototype

* add spawnpoints to the mothership

* whitelist system to spawnpoints

* updated xenoborg components

* added xenoborg component to xenoborgs

* updated spawnpoints of xenoborgs in the mothership

* add new tags for xenoborg and mothership core

* add new tags for xenoborgs and mothership core

* update ghostrole spawners for xenoborgs

* message for when you get the xenoborg role

* explode all xenoborgs when mothership core dies

* for real now. explode all xenoborgs when mothership core is destroyed

* round end summary for xenoborgs

* temporary

* add guidebook entry for xenoborgs

* instructions on how to borg players

* removed lock from xenoborg control computer

* announcement when all xenoborgs die

* announcement when mothership core is destroyed

* typos

* fix error

* improve xenoborg mind role

* move sounds to xenoborg and mothership component

* play sounds when turned into xenoborg

* change sprites of mothership core actions

* minor fix

* add custom xenoborg start sound

* carps now attack xenoborgs

* added guide link to xenoborgs

* add guidebook link to xenoborgs

* added guidebook link to mothership core

* add link to source of the sound

* fixed minor issue

* has to be 1

* typo

* add light layer to mothership core sprite

* fixed antag selection system

* update guideboook

* update the guidebook again

* alphabet

* documentation

* simplify documentation

Co-authored-by: ScarKy0 <106310278+ScarKy0@users.noreply.github.com>

* make the briefing yml instead of code

* fix bug with sprites

* fix formating

* remove stuff from AntagSelection

* add stuff to AntagSpawner

* fix game rule

* removed secret xenoborg preset

* support for more than one entity for each antag role

* fix gamerule

* fixes

* no xeonborgs

* add xenoborgs to all at once

* engi xenoborg included

* more comments

* more recognizable

* more xenoborgs when more players

* removed unused stuff

* correct access

* removed unnecessary stuff

* use GetAliveHumans and make comments better

* Make the system more robust

* use a constant

* remove overload from the Destroy method

* has to be public to be used in the xenoborg system

* fix the mindrole methods

* not sure, but I was asked to do it

* use a constant for the color

* forgot to make it static

* removed param comments

* removed useless parameters

* fixed stuff

* added event listeneers to xenoborg mind change

* only 4

* unfuck the antagSpawner

* comment

* unfix stuff

* commentary

* removed xenoborg stuff from siliconLawSystem

* move some stuff to the component

* removed space

* removed uncessary stuff

* no need to crate a var

* move stuff from mothership comp to xenoborg comp

* removed XenoborgCoreRoleComponent

* comment on the AntagSelectLocationEvent

* added back empty line

* comment

* make the summary better

* make AntagRoleToPrototypes summary better

* adding useless stuff back cause it was there before

* hascomp instead of trycomp

* again

* LocId instead of string

* make a new logic for the whitelist of the spawnpoint

* added ghostrole tags back

* use hascomp instead of trycomp

* removed whitelist from SpawnPointComponent

* not needed anymore

* no longer subverted

* fixed names

* make it better

* add not

* i'm dumb

* briefing is now handled by the xenoborg system

* call evac if there is too many xenoborgs

* update submodule

* fix division

* Add AutoGenerateComponentPause and AutoPausedField to XenoborgsRuleComponent

* add lines between stuff

* Make the Blocking system more robust

* Make mothership inherit from BaseMob

* remove this stuff cause is bad

* Revert "Make the Blocking system more robust"

This reverts commit 099babfe1daef00e6073e04108920327416e4ca4.

* Mothership core snaps to grid

* stop mothership core from moving

* mothership core is static again

* make guidebook entry on how to xenoborg crew better

* Make mothership core damageable

* If xenoborgs need it, so do zombies i guess

* Start the NextRoundEndCheck

* follow private static readonly naming rule

* Samething

* Fix announcments

* Make it a datafield, no?

* Revert "Make it a datafield, no?"

This reverts commit 62f6255ccccdd583d7f833ae4dbcd09a670f721a.

* remove stuff

* doesn't need to move

* is kinda of a structure

* so it doesn't pry floors as soon as it spawns

* powercell hand to mothership core module

* label for new hand

* core_e -> core-e

* mothership core can pilot the shuttle again

* fix duplicated tag + description to xenoborg tags

* scout xenoborg can now move in space without the jetpack so it can better use the sword module

* improve basic xenoborg module

* remove changes from zombie rule comp

* swap AllEntityQuery for EntityQueryEnumerator

* new line at the end

* change to 15 seconds

* make MothershipCoreDeathAnnouncmentSent into a datafield

---------

Co-authored-by: ScarKy0 <106310278+ScarKy0@users.noreply.github.com>
Co-authored-by: beck-thompson <beck314159@hotmail.com>
2025-11-14 22:10:09 +00:00

209 lines
7.2 KiB
C#

using Content.Shared.Containers.ItemSlots;
using Content.Shared.DeviceNetwork;
using Content.Shared.Damage.Components;
using Content.Shared.FixedPoint;
using Content.Shared.Mobs;
using Content.Shared.Mobs.Systems;
using Content.Shared.Movement.Components;
using Content.Shared.Popups;
using Content.Shared.Robotics;
using Content.Shared.Silicons.Borgs.Components;
using Content.Shared.DeviceNetwork.Components;
using Content.Shared.DeviceNetwork.Events;
using Content.Shared.Emag.Systems;
using Robust.Shared.Utility;
namespace Content.Server.Silicons.Borgs;
/// <inheritdoc/>
public sealed partial class BorgSystem
{
[Dependency] private readonly EmagSystem _emag = default!;
[Dependency] private readonly MobThresholdSystem _mobThresholdSystem = default!;
[Dependency] private readonly ItemSlotsSystem _itemSlotsSystem = default!;
private void InitializeTransponder()
{
SubscribeLocalEvent<BorgTransponderComponent, DeviceNetworkPacketEvent>(OnPacketReceived);
}
public override void Update(float frameTime)
{
base.Update(frameTime);
var now = _timing.CurTime;
var query = EntityQueryEnumerator<BorgTransponderComponent, BorgChassisComponent, DeviceNetworkComponent, MetaDataComponent>();
while (query.MoveNext(out var uid, out var comp, out var chassis, out var device, out var meta))
{
if (comp.NextDisable is { } nextDisable && now >= nextDisable)
DoDisable((uid, comp, chassis, meta));
if (now < comp.NextBroadcast)
continue;
var charge = 0f;
if (_powerCell.TryGetBatteryFromSlot(uid, out var battery))
charge = battery.CurrentCharge / battery.MaxCharge;
var hpPercent = CalcHP(uid);
// checks if it has a brain and if the brain is not a empty MMI (gives false anyway if the fake disable is true)
var hasBrain = CheckBrain(chassis.BrainEntity) && !comp.FakeDisabled;
var canDisable = comp.NextDisable == null && !comp.FakeDisabling;
var data = new CyborgControlData(
comp.Sprite,
comp.Name,
meta.EntityName,
charge,
hpPercent,
chassis.ModuleCount,
hasBrain,
canDisable);
var payload = new NetworkPayload()
{
[DeviceNetworkConstants.Command] = DeviceNetworkConstants.CmdUpdatedState,
[RoboticsConsoleConstants.NET_CYBORG_DATA] = data
};
_deviceNetwork.QueuePacket(uid, null, payload, device: device);
comp.NextBroadcast = now + comp.BroadcastDelay;
}
}
private void DoDisable(Entity<BorgTransponderComponent, BorgChassisComponent, MetaDataComponent> ent)
{
ent.Comp1.NextDisable = null;
if (ent.Comp1.FakeDisabling)
{
ent.Comp1.FakeDisabled = true;
ent.Comp1.FakeDisabling = false;
return;
}
if (ent.Comp2.BrainEntity is not { } brain)
return;
var message = Loc.GetString(ent.Comp1.DisabledPopup, ("name", Name(ent, ent.Comp3)));
Popup.PopupEntity(message, ent);
_container.Remove(brain, ent.Comp2.BrainContainer);
}
private void OnPacketReceived(Entity<BorgTransponderComponent> ent, ref DeviceNetworkPacketEvent args)
{
var payload = args.Data;
if (!payload.TryGetValue(DeviceNetworkConstants.Command, out string? command))
return;
if (command == RoboticsConsoleConstants.NET_DISABLE_COMMAND)
Disable(ent);
else if (command == RoboticsConsoleConstants.NET_DESTROY_COMMAND)
Destroy(ent.Owner);
}
private void Disable(Entity<BorgTransponderComponent, BorgChassisComponent?> ent)
{
if (!Resolve(ent, ref ent.Comp2) || ent.Comp2.BrainEntity == null || ent.Comp1.NextDisable != null)
return;
// update ui immediately
ent.Comp1.NextBroadcast = _timing.CurTime;
// pretend the borg is being disabled forever now
if (CheckEmagged(ent, "disabled"))
ent.Comp1.FakeDisabling = true;
else
Popup.PopupEntity(Loc.GetString(ent.Comp1.DisablingPopup), ent);
ent.Comp1.NextDisable = _timing.CurTime + ent.Comp1.DisableDelay;
}
/// <summary>
/// Makes a borg with <see cref="BorgTransponderComponent"/> explode
/// </summary>
/// <param name="ent">the entity of the borg</param>
public void Destroy(Entity<BorgTransponderComponent?> ent)
{
if (!Resolve(ent, ref ent.Comp))
return;
// this is stealthy until someone realises you havent exploded
if (CheckEmagged(ent, "destroyed"))
{
// prevent reappearing on the console a few seconds later
RemComp<BorgTransponderComponent>(ent);
return;
}
var message = Loc.GetString(ent.Comp.DestroyingPopup, ("name", Name(ent)));
Popup.PopupEntity(message, ent);
_trigger.ActivateTimerTrigger(ent.Owner);
// prevent a shitter borg running into people
RemComp<InputMoverComponent>(ent);
}
private bool CheckEmagged(EntityUid uid, string name)
{
if (_emag.CheckFlag(uid, EmagType.Interaction))
{
Popup.PopupEntity(Loc.GetString($"borg-transponder-emagged-{name}-popup"), uid, uid, PopupType.LargeCaution);
return true;
}
return false;
}
/// <summary>
/// Sets <see cref="BorgTransponderComponent.Sprite"/>.
/// </summary>
public void SetTransponderSprite(Entity<BorgTransponderComponent> ent, SpriteSpecifier sprite)
{
ent.Comp.Sprite = sprite;
}
/// <summary>
/// Sets <see cref="BorgTransponderComponent.Name"/>.
/// </summary>
public void SetTransponderName(Entity<BorgTransponderComponent> ent, string name)
{
ent.Comp.Name = name;
}
/// <summary>
/// Returns a ratio between 0 and 1, 1 when they have no damage and 0 whenever they are crit (or more damaged)
/// </summary>
private float CalcHP(EntityUid uid)
{
if (!TryComp<DamageableComponent>(uid, out var damageable))
return 1;
if (!_mobState.IsAlive(uid))
return 0;
if (!_mobThresholdSystem.TryGetThresholdForState(uid, MobState.Critical, out var threshold))
{
Log.Error($"Borg({ToPrettyString(uid)}), doesn't have critical threshold.");
return 1;
}
return 1 - ((FixedPoint2)(damageable.TotalDamage / threshold)).Float();
}
/// <summary>
/// Returns true if the borg has a brain
/// </summary>
private bool CheckBrain(EntityUid? brainEntity)
{
if (brainEntity == null)
return false;
// if the brainEntity.Value has the component MMIComponent then it is a MMI,
// in that case it trys to get the "brain" of the MMI, if it is null the MMI is empty and so it returns false
if (TryComp<MMIComponent>(brainEntity.Value, out var mmi) && _itemSlotsSystem.GetItemOrNull(brainEntity.Value, mmi.BrainSlotId) == null)
return false;
return true;
}
}