Skip to content

Commit

Permalink
Всякая всячина
Browse files Browse the repository at this point in the history
  • Loading branch information
VigersRay committed Jul 18, 2024
1 parent 00e715d commit 8843ccc
Show file tree
Hide file tree
Showing 37 changed files with 310 additions and 278,079 deletions.
2 changes: 2 additions & 0 deletions Content.Server/Roles/RoleSystem.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Content.Server._Sunrise.EvilTwin;
using Content.Server._Sunrise.Fugitive;
using Content.Server._Sunrise.PlanetPrison;
using Content.Shared.Roles;
Expand All @@ -23,6 +24,7 @@ public override void Initialize()
// Sunrise-start
SubscribeAntagEvents<FugitiveRoleComponent>();
SubscribeAntagEvents<PlanetPrisonerRoleComponent>();
SubscribeAntagEvents<EvilTwinRoleComponent>();
// Sunrise-end
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ private void OnStationPostInit(ref StationPostInitEvent ev)
/// <summary>
/// Ensures the FTL map exists and returns it.
/// </summary>
private EntityUid EnsureFTLMap()
public EntityUid EnsureFTLMap()
{
var query = AllEntityQuery<FTLMapComponent>();

Expand Down
9 changes: 9 additions & 0 deletions Content.Server/_Sunrise/EvilTwin/EvilTwinRoleComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Content.Shared.Roles;

namespace Content.Server._Sunrise.EvilTwin;

[RegisterComponent]
public sealed partial class EvilTwinRoleComponent : AntagonistRoleComponent
{

}
7 changes: 7 additions & 0 deletions Content.Server/_Sunrise/EvilTwin/EvilTwinRuleComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Content.Server._Sunrise.EvilTwin;

[RegisterComponent, Access(typeof(EvilTwinSystem))]
public sealed partial class EvilTwinRuleComponent : Component
{
public List<(EntityUid, string)> TwinsMinds = new();
}
145 changes: 53 additions & 92 deletions Content.Server/_Sunrise/EvilTwin/EvilTwinSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Content.Server.Humanoid;
using Content.Server.Jobs;
using Content.Server.Mind;
using Content.Server.Objectives;
using Content.Server.Objectives.Components;
using Content.Server.Objectives.Systems;
using Content.Server.Preferences.Managers;
Expand All @@ -15,9 +16,11 @@
using Content.Server.Station.Systems;
using Content.Shared.Clothing;
using Content.Shared.Humanoid;
using Content.Shared.Implants;
using Content.Shared.Implants.Components;
using Content.Shared.Mind;
using Content.Shared.Mind.Components;
using Content.Shared.Objectives.Components;
using Content.Shared.Objectives.Systems;
using Content.Shared.Mindshield.Components;
using Content.Shared.Preferences;
using Content.Shared.Preferences.Loadouts;
using Content.Shared.Roles;
Expand All @@ -41,21 +44,43 @@ public sealed class EvilTwinSystem : EntitySystem
[Dependency] private readonly JobSystem _jobSystem = default!;
[Dependency] private readonly MetaDataSystem _metaDataSystem = default!;
[Dependency] private readonly TargetObjectiveSystem _target = default!;
[Dependency] private readonly SharedObjectivesSystem _objectives = default!;
[Dependency] private readonly GameTicker _gameTicker = default!;
[Dependency] private readonly SharedSubdermalImplantSystem _subdermalImplant = default!;

[ValidatePrototypeId<EntityPrototype>]
private const string GameRule = "Fugitive";
[ValidatePrototypeId<AntagPrototype>]
private const string EvilTwinRole = "EvilTwin";
[ValidatePrototypeId<EntityPrototype>]
private const string KillObjective = "KillTwinObjective";
[ValidatePrototypeId<EntityPrototype>]
private const string EscapeObjective = "EscapeShuttleTwinObjective";
[ValidatePrototypeId<EntityPrototype>]
private const string MindShield = "MindShieldImplant";

public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<EvilTwinSpawnerComponent, PlayerAttachedEvent>(OnPlayerAttached);
SubscribeLocalEvent<EvilTwinComponent, MindAddedMessage>(OnMindAdded);
SubscribeLocalEvent<RoundEndTextAppendEvent>(OnRoundEnd);

SubscribeLocalEvent<EvilTwinRuleComponent, ObjectivesTextGetInfoEvent>(OnObjectivesTextGetInfo);
SubscribeLocalEvent<EvilTwinRoleComponent, GetBriefingEvent>(OnGetBriefing);
}

private void OnGetBriefing(EntityUid uid, EvilTwinRoleComponent component, ref GetBriefingEvent args)
{
if (!TryComp<MindComponent>(uid, out var mind) || mind.OwnedEntity == null)
return;
if (HasComp<EvilTwinRoleComponent>(uid)) // don't show both briefings
return;
args.Append(Loc.GetString("evil-twin-role-greeting"));
}

private void OnObjectivesTextGetInfo(EntityUid uid, EvilTwinRuleComponent comp, ref ObjectivesTextGetInfoEvent args)
{
args.Minds = comp.TwinsMinds;
args.AgentName = Loc.GetString("evil-twin-round-end-name");
}

private void OnPlayerAttached(EntityUid uid, EvilTwinSpawnerComponent component, PlayerAttachedEvent args)
Expand All @@ -74,13 +99,27 @@ private void OnPlayerAttached(EntityUid uid, EvilTwinSpawnerComponent component,
}
}

public EvilTwinRuleComponent GetEvilTwinRule()
{
var rule = EntityQuery<EvilTwinRuleComponent>().FirstOrDefault();
if (rule != null)
return rule;

_gameTicker.StartGameRule(GameRule, out var ruleEntity);
rule = Comp<EvilTwinRuleComponent>(ruleEntity);

return rule;
}

private void OnMindAdded(EntityUid uid, EvilTwinComponent component, MindAddedMessage args)
{
var evilTwinRule = GetEvilTwinRule();

if (!TryComp<EvilTwinComponent>(uid, out var evilTwin) ||
!_mindSystem.TryGetMind(uid, out var mindId, out var mind))
return;

var role = new TraitorRoleComponent
var role = new EvilTwinRoleComponent
{
PrototypeId = EvilTwinRole,
};
Expand All @@ -89,90 +128,10 @@ private void OnMindAdded(EntityUid uid, EvilTwinComponent component, MindAddedMe
_mindSystem.TryAddObjective(mindId, mind, KillObjective);
if (_mindSystem.TryGetObjectiveComp<TargetObjectiveComponent>(uid, out var obj))
_target.SetTarget(uid, evilTwin.TargetMindId, obj);
}

private void OnRoundEnd(RoundEndTextAppendEvent ev)
{
var twinsCount = EntityQuery<EvilTwinComponent>().Count();
if (twinsCount == 0)
return;

var result = Loc.GetString("evil-twin-round-end-result", ("evil-twin-count", twinsCount));

var query = EntityQueryEnumerator<EvilTwinComponent>();
while (query.MoveNext(out var uid, out var twin))
{
if (!_mindSystem.TryGetMind(uid, out var mindId, out var mind))
continue;

var name = mind.CharacterName;
_mindSystem.TryGetSession(mind.OwnedEntity, out var session);
var username = session?.Name;

var objectives = mind.Objectives.ToArray();
if (objectives.Length == 0)
{
if (username != null)
{
if (name == null)
result += "\n" + Loc.GetString("evil-twin-user-was-an-evil-twin", ("user", username));
else
result += "\n" + Loc.GetString("evil-twin-user-was-an-evil-twin-named", ("user", username), ("name", name));
}
else if (name != null)
result += "\n" + Loc.GetString("evil-twin-was-an-evil-twin-named", ("name", name));

continue;
}

if (username != null)
{
if (name == null)
result += "\n" + Loc.GetString("evil-twin-user-was-an-evil-twin-with-objectives", ("user", username));
else
result += "\n" + Loc.GetString("evil-twin-user-was-an-evil-twin-with-objectives-named", ("user", username), ("name", name));
}
else if (name != null)
result += "\n" + Loc.GetString("evil-twin-was-an-evil-twin-with-objectives-named", ("name", name));

foreach (var objectiveGroup in objectives.GroupBy(o => Comp<ObjectiveComponent>(o).Issuer))
{
foreach (var objective in objectiveGroup)
{
var info = _objectives.GetInfo(objective, mindId, mind);
if (info == null)
continue;

var objectiveTitle = info.Value.Title;
var progress = info.Value.Progress;
if (progress > 0.99f)
{
result += "\n- " + Loc.GetString(
"objectives-objective-success",
("objective", objectiveTitle),
("markupColor", "green")
);
}
else
{
result += "\n- " + Loc.GetString(
"objectives-objective-fail",
("objective", objectiveTitle),
("progress", (int) (progress * 100)),
("markupColor", "red")
);
}
}
}
}
ev.AddLine(result);
evilTwinRule.TwinsMinds.Add((mindId, Name(uid)));
}

/// <summary>
/// Get first random humanoid controlled by player mob with job
/// </summary>
/// <param name="uid">Found humanoid uid</param>
/// <returns>false if not found</returns>
private bool TryGetEligibleHumanoid([NotNullWhen(true)] out EntityUid? uid)
{
var targets = EntityQuery<ActorComponent, AntagTargetComponent, HumanoidAppearanceComponent>().ToList();
Expand All @@ -193,12 +152,6 @@ private bool TryGetEligibleHumanoid([NotNullWhen(true)] out EntityUid? uid)
return false;
}

/// <summary>
/// Spawns "clone" in round start state of target human mob
/// </summary>
/// <param name="target">Target for cloning</param>
/// <param name="coords">Spawn location</param>
/// <returns>null if target in invalid state (ghost, leave, ...)</returns>
private EntityUid? TrySpawnEvilTwin(EntityUid target, EntityCoordinates coords)
{
if (!_mindSystem.TryGetMind(target, out var mindId, out _) ||
Expand Down Expand Up @@ -254,6 +207,14 @@ private bool TryGetEligibleHumanoid([NotNullWhen(true)] out EntityUid? uid)
dna.DNA = dnaComponent.DNA;
}

if (HasComp<MindShieldComponent>(target))
{
var implantEnt = Spawn(MindShield, coords);

if (TryComp<SubdermalImplantComponent>(implantEnt, out var implantComp))
_subdermalImplant.ForceImplant(target, implantEnt, implantComp);
}

EnsureComp<EvilTwinComponent>(twinUid).TargetMindId = mindId;

return twinUid;
Expand Down
30 changes: 18 additions & 12 deletions Content.Server/_Sunrise/Fugitive/FugitiveSystem.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using System.Linq;
using Content.Server.Chat.Managers;
using Content.Server.Chat.Systems;
using Content.Server.Fax;
using Content.Server.GameTicking;
using Content.Server.Mind;
using Content.Server.Objectives;
using Content.Server.Roles;
using Content.Shared.Fax.Components;
using Content.Shared.Humanoid;
using Content.Shared.Mind;
using Content.Shared.Mind.Components;
using Content.Shared.Movement.Systems;
using Content.Shared.Paper;
Expand All @@ -20,27 +21,38 @@ namespace Content.Server._Sunrise.Fugitive
{
public sealed class FugitiveSystem : EntitySystem
{
private const string AntagRole = "Fugitive";
private const string EscapeObjective = "FugitiveEscapeShuttleObjective";
private const string GameRule = "Fugitive";

[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly MovementSpeedModifierSystem _movementSpeed = default!;
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly ChatSystem _chat = default!;
[Dependency] private readonly MindSystem _mindSystem = default!;
[Dependency] private readonly FaxSystem _faxSystem = default!;
[Dependency] private readonly IChatManager _chatManager = default!;
[Dependency] private readonly SharedRoleSystem _roleSystem = default!;
[Dependency] private readonly GameTicker _gameTicker = default!;

[ValidatePrototypeId<AntagPrototype>]
private const string AntagRole = "Fugitive";
[ValidatePrototypeId<EntityPrototype>]
private const string EscapeObjective = "FugitiveEscapeShuttleObjective";
[ValidatePrototypeId<EntityPrototype>]
private const string GameRule = "Fugitive";

public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<FugitiveComponent, MindAddedMessage>(OnMindAdded);

SubscribeLocalEvent<FugitiveRuleComponent, ObjectivesTextGetInfoEvent>(OnObjectivesTextGetInfo);
SubscribeLocalEvent<FugitiveRoleComponent, GetBriefingEvent>(OnGetBriefing);
}

private void OnGetBriefing(EntityUid uid, FugitiveRoleComponent component, ref GetBriefingEvent args)
{
if (!TryComp<MindComponent>(uid, out var mind) || mind.OwnedEntity == null)
return;
if (HasComp<FugitiveRoleComponent>(uid)) // don't show both briefings
return;
args.Append(Loc.GetString("fugitive-role-greeting"));
}

private void OnObjectivesTextGetInfo(EntityUid uid, FugitiveRuleComponent comp, ref ObjectivesTextGetInfoEvent args)
Expand Down Expand Up @@ -131,16 +143,10 @@ private void OnMindAdded(EntityUid uid, FugitiveComponent component, MindAddedMe
PrototypeId = AntagRole,
});

if (_mindSystem.TryGetSession(mind, out var session))
{
_chatManager.DispatchServerMessage(session, Loc.GetString("fugitive-role-greeting"));
}

_mindSystem.TryAddObjective(mindId, mind, EscapeObjective);

fugitiveRule.FugitiveMinds.Add((mindId, Name(uid)));

// workaround seperate shitcode moment
_movementSpeed.RefreshMovementSpeedModifiers(uid);
}

Expand Down
Loading

0 comments on commit 8843ccc

Please sign in to comment.