CatStation/Content.Server/Changeling/Systems/ServerChangelingLastResortSystem.cs
Princess Cheeseballs 2c6ffecf62
Move GameTicker to Shared (#45834)
* Scope creep my ass

* why was this shit not pushed????

* gone...

* fix that

* review plus buildd

* asfsafsafsafsafas

* grug

* burber

* I'll fix this later

* shrimply die

* also this

* it's snerf or snuthin

* assaads

* round snend

* aaaa

* fix this shit for real

* actually, don't start GameRules until MapInit now that I think aboot it.

* forgot u

* don't actually need this part nullable

* Deffer comp removal

* one liner

* do that too

* chungus

* Honestly makes more sense here, plus WHY are we doing all that shit on "GameRuleAdded" rather than GameRuleStarted(?)

* deferred removal :V

* aaaaaaaaaaaaaaa

* whhop

* Whoop

* better

* landmine that I placed for myself then forgot about lmao

* cleanup

* FUCKING `!`

* gotovo

* amogus

* please don't check by metadata I beg

* waawsasfdfsasfa

* sfafsasfafsas

* fdsaasffsasfa

* code

* fix

* fasasffasfasfsad

* chungaas

* I may be stupid

* gra

* graaaaaaaaaaaaaaaaa

* comment

* gra

* clearing is not predicted and would require major refactors, so don't cache on client.

* lame shit :P

* last holes

* nukeopsfsafsasafsfafsa

* why  was that shit public bruh

* bubrbgwahrghfaka

* dynamic

* revert change that did nothing lmao
2026-09-16 19:34:19 +00:00

108 lines
3.7 KiB
C#

using Content.Shared.Antag;
using Content.Shared.Changeling.Components;
using Content.Shared.Changeling.Systems;
using Content.Shared.DoAfter;
using Content.Shared.Humanoid;
using Content.Shared.IdentityManagement;
using Content.Shared.Mind;
using Content.Shared.Mobs.Systems;
using Content.Shared.Popups;
using Content.Shared.Zombies;
using Robust.Shared.Prototypes;
namespace Content.Server.Changeling.Systems;
public sealed partial class ServerChangelingLastResortSystem : ChangelingLastResortSystem
{
private static readonly ProtoId<AntagSpecifierPrototype> ChangelingAntag = "Changeling";
[Dependency] private SharedMindSystem _mind = default!;
[Dependency] private MobStateSystem _mobState = default!;
[Dependency] private SharedPopupSystem _popup = default!;
[Dependency] private SharedDoAfterSystem _doAfter = default!;
[Dependency] private AntagSelectionSystem _antag = default!;
[SubscribeLocalEvent]
private void OnTakeOverCorpseAction(Entity<ChangelingSlugComponent> ent,
ref ChangelingTakeOverCorpseActionEvent args)
{
// CanTakeOver checks for the existence of ChangelingIdentityComponent on the target.
// As such it cannot be predicted as that component is not networked to sessions other than the owner
// Unless we do fucky networking magic
if (args.Handled || !CanTakeOver(ent.Owner, args.Target))
return;
args.Handled = true;
Audio.PlayPvs(ent.Comp.Sound, ent.Owner);
_popup.PopupEntity(Loc.GetString("changeling-takeover-start-others", ("user", Identity.Entity(ent.Owner, EntityManager))),
ent.Owner,
PopupType.MediumCaution);
var doAfter = new DoAfterArgs(EntityManager,
ent.Owner,
ent.Comp.TakeOverDuration,
new ChangelingTakeOverCorpseDoAfterEvent(),
ent,
target: args.Target)
{
BreakOnDamage = true,
BreakOnMove = true,
DuplicateCondition = DuplicateConditions.None,
RequireCanInteract = false,
};
_doAfter.TryStartDoAfter(doAfter);
}
/// <summary>
/// Checks whether a changeling slug can take over the <paramref name="target"/> body.
/// </summary>
private bool CanTakeOver(EntityUid user, EntityUid target, bool showPopups = true)
{
if (!HasComp<HumanoidProfileComponent>(target))
return false;
if (HasComp<ChangelingIdentityComponent>(target) || HasComp<ZombieComponent>(target))
{
if (showPopups)
_popup.PopupEntity(Loc.GetString("changeling-takeover-is-changeling"), user, user);
return false;
}
if (_mobState.IsDead(target))
return true;
if (showPopups)
_popup.PopupEntity(Loc.GetString("changeling-takeover-not-dead"), user, user);
return false;
}
[SubscribeLocalEvent]
private void OnTakeOverCorpseDoAfter(Entity<ChangelingSlugComponent> ent,
ref ChangelingTakeOverCorpseDoAfterEvent args)
{
args.Handled = true;
if (args.Cancelled || args.Target is not { } target || !CanTakeOver(args.User, target, showPopups: false))
return;
if (!_mind.TryGetMind(args.User, out var mindId, out var mind))
return;
TakeOverCorpse(args.User, target, mindId, mind);
_popup.PopupEntity(Loc.GetString("changeling-takeover-success-self"), target, target, PopupType.Large);
}
private void TakeOverCorpse(EntityUid user, EntityUid target, EntityUid mindId, MindComponent mind)
{
_mind.TransferTo(mindId, target, mind: mind);
_antag.AssignAntagComponents(target, ChangelingAntag);
QueueDel(user);
}
}