2023-09-10 03:51:51 +01:00
|
|
|
using Content.Server.GameTicking.Rules;
|
|
|
|
|
using Content.Server.Traitor.Components;
|
|
|
|
|
using Content.Shared.Mind.Components;
|
|
|
|
|
|
|
|
|
|
namespace Content.Server.Traitor.Systems;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Makes entities with <see cref="AutoTraitorComponent"/> a traitor either immediately if they have a mind or when a mind is added.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public sealed class AutoTraitorSystem : EntitySystem
|
|
|
|
|
{
|
|
|
|
|
[Dependency] private readonly TraitorRuleSystem _traitorRule = default!;
|
|
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
|
|
|
|
SubscribeLocalEvent<AutoTraitorComponent, MindAddedMessage>(OnMindAdded);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnMindAdded(EntityUid uid, AutoTraitorComponent comp, MindAddedMessage args)
|
|
|
|
|
{
|
|
|
|
|
TryMakeTraitor(uid, comp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets the GiveUplink field.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void SetGiveUplink(EntityUid uid, bool giveUplink, AutoTraitorComponent? comp = null)
|
|
|
|
|
{
|
|
|
|
|
if (!Resolve(uid, ref comp))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
comp.GiveUplink = giveUplink;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets the GiveObjectives field.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void SetGiveObjectives(EntityUid uid, bool giveObjectives, AutoTraitorComponent? comp = null)
|
|
|
|
|
{
|
|
|
|
|
if (!Resolve(uid, ref comp))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
comp.GiveObjectives = giveObjectives;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Checks if there is a mind, then makes it a traitor using the options.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool TryMakeTraitor(EntityUid uid, AutoTraitorComponent? comp = null)
|
|
|
|
|
{
|
|
|
|
|
if (!Resolve(uid, ref comp))
|
|
|
|
|
return false;
|
|
|
|
|
|
Refactor antag rule code (#23445)
* Initial Pass, Rev, Thief
* Zombie initial pass
* Rebase, Traitor
* Nukeops, More overloads
* Revert RevolutionaryRuleComponent
* Use TryRoundStartAttempt, Rewrite nukie spawning
* Comments, Add task scheduler to GameRuleSystem
* Zombie initial testing done
* Sort methods, rework GameRuleTask
* Add CCVar, Initial testing continues
* Might as well get rid of the obsolete logging
* Oops, i dont know how to log apparently
* Suggested formatting fixes
* Suggested changes
* Fix merge issues
* Minor optimisation
* Allowed thief to choose other antags
* Review changes
* Spawn items on floor first, then inserting
* minor tweaks
* Shift as much as possible to ProtoId<>
* Remove unneeded
* Add exclusive antag attribute
* Fix merge issues
* Minor formatting fix
* Convert to struct
* Cleanup
* Review cleanup (need to test a lot)
* Some fixes, (mostly) tested
* oop
* Pass tests (for real)
---------
Co-authored-by: Rainfall <rainfey0+git@gmail.com>
Co-authored-by: AJCM <AJCM@tutanota.com>
2024-02-29 06:25:10 +00:00
|
|
|
//Start the rule if it has not already been started
|
|
|
|
|
var traitorRuleComponent = _traitorRule.StartGameRule();
|
|
|
|
|
_traitorRule.MakeTraitor(uid, traitorRuleComponent, giveUplink: comp.GiveUplink, giveObjectives: comp.GiveObjectives);
|
2023-09-10 03:51:51 +01:00
|
|
|
// prevent spamming anything if it fails
|
|
|
|
|
RemComp<AutoTraitorComponent>(uid);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|