Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ninja targets update #2148

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions Content.Server/SS220/CriminalRecords/CriminalRecordSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
using Content.Shared.SS220.Ghost;
using Content.Shared.StationRecords;
using Content.Shared.StatusIcon.Components;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;

Expand Down Expand Up @@ -141,7 +140,9 @@ public void UpdateLastRecordTime(CriminalRecordCatalog catalog)
catalog.LastRecordTime = biggest == -1 ? null : biggest;
}

public void UpdateIdCards(StationRecordKey key, GeneralStationRecord generalRecord)

/// <returns>Null if no IDCard was updated or Uid of updated IDCard</returns>
public EntityUid? UpdateIdCards(StationRecordKey key, GeneralStationRecord generalRecord)
{
CriminalRecord? criminalRecord = null;
if (generalRecord.CriminalRecords != null)
Expand All @@ -167,7 +168,9 @@ public void UpdateIdCards(StationRecordKey key, GeneralStationRecord generalReco

idCard.CurrentSecurityRecord = criminalRecord;
EntityManager.Dirty(uid, idCard);
return uid;
}
return null;
}

public bool RemoveCriminalRecordStatus(StationRecordKey key, int time, EntityUid? sender = null)
Expand All @@ -185,7 +188,9 @@ public bool RemoveCriminalRecordStatus(StationRecordKey key, int time, EntityUid

UpdateLastRecordTime(catalog);
_stationRecords.Synchronize(key.OriginStation);
UpdateIdCards(key, selectedRecord);
var cardId = UpdateIdCards(key, selectedRecord);
if (cardId.HasValue && TryGetLastRecord(key, out _, out var currentCriminalRecord))
RaiseLocalEvent<CriminalStatusEvent>(cardId.Value, new CriminalStatusDeleted(sender, key, ref currentCriminalRecord));

if (sender != null)
{
Expand Down Expand Up @@ -255,7 +260,10 @@ public bool AddCriminalRecordStatus(StationRecordKey key, string message, string

catalog.LastRecordTime = currentRoundTime;
_stationRecords.Synchronize(key.OriginStation);
UpdateIdCards(key, selectedRecord);
var cardId = UpdateIdCards(key, selectedRecord);
if (cardId.HasValue)
RaiseLocalEvent<CriminalStatusEvent>(cardId.Value, new CriminalStatusAdded(sender, key, ref criminalRecord));

_sawmill.Debug("Added new criminal record, synchonizing");

if (sender != null)
Expand Down
27 changes: 27 additions & 0 deletions Content.Server/SS220/CriminalRecords/CriminalRecordsEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt

using Content.Shared.SS220.CriminalRecords;
using Content.Shared.StationRecords;

namespace Content.Server.SS220.CriminalRecords;

public abstract class CriminalStatusEvent(EntityUid? sender, StationRecordKey key, ref CriminalRecord currentCriminalRecord)
{
public EntityUid? Sender { get; } = sender;
public StationRecordKey Key { get; } = key;
public CriminalRecord CurrentCriminalRecord { get; } = currentCriminalRecord;
}

/// <summary>
/// Just Look to its name
/// </summary>
public sealed class CriminalStatusAdded(EntityUid? sender, StationRecordKey key, ref CriminalRecord criminalRecord)
: CriminalStatusEvent(sender, key, ref criminalRecord)
{ }

/// <summary>
/// Just Look to its name
/// </summary>
public sealed class CriminalStatusDeleted(EntityUid? sender, StationRecordKey key, ref CriminalRecord criminalRecord)
: CriminalStatusEvent(sender, key, ref criminalRecord)
{ }
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt

using Content.Server.SS220.Trackers.Components;

namespace Content.Server.SS220.Objectives.Components;

[RegisterComponent]
public sealed partial class FramePersonConditionComponent : Component
{
[DataField(required: true)]
public CriminalStatusTrackerSpecifier CriminalStatusSpecifier = new();

public bool ObjectiveIsDone = false;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt

using Content.Server.SS220.Trackers.Components;

namespace Content.Server.SS220.Objectives.Components;

[RegisterComponent]
public sealed partial class IntimidatePersonConditionComponent : Component
{
[DataField(required: true)]
public DamageTrackerSpecifier DamageTrackerSpecifier = new();

[ViewVariables(VVAccess.ReadWrite)]
public EntityUid TargetMob;

[ViewVariables(VVAccess.ReadWrite)]
public bool ObjectiveIsDone = false;

public IntimidatePersonDescriptionType DescriptionType;
// Two descriptions comes to help player differ done object from one which isn't.

/// <summary>
/// Description will be applied at start. No params in it
/// </summary>
[DataField(required: true)]
public string? StartDescription;

/// <summary>
/// Description will be applied when objective is done. No params in it
/// </summary>
[DataField(required: true)]
public string? SuccessDescription;

/// <summary>
/// Description will be applied when objective is done. No params in it
/// </summary>
[DataField(required: true)]
public string? SSDDescription;
}

public enum IntimidatePersonDescriptionType
{
Start = 0,
Success,
SSD
}
140 changes: 140 additions & 0 deletions Content.Server/SS220/Objectives/Systems/FramePersonConditionSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt

using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Content.Server.Access.Systems;
using Content.Server.Mind;
using Content.Server.Objectives.Components;
using Content.Server.Objectives.Systems;
using Content.Server.SS220.Objectives.Components;
using Content.Server.SS220.Trackers.Components;
using Content.Shared.Mind;
using Content.Shared.Objectives.Components;
using Content.Shared.Roles;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;

namespace Content.Server.SS220.Objectives.Systems;

public sealed class FramePersonConditionSystem : EntitySystem
{
[Dependency] private readonly IdCardSystem _idCard = default!;
[Dependency] private readonly MindSystem _mind = default!;
[Dependency] private readonly IPrototypeManager _prototype = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly SharedRoleSystem _roleSystem = default!;
[Dependency] private readonly TargetObjectiveSystem _targetObjective = default!;

/// <summary>
/// We use this to determine which jobs have legalImmunity... Wait for MRP PR for a special flag.
/// </summary>
private readonly string _legalImmunitySupervisors = "job-supervisors-centcom";

public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<FramePersonConditionComponent, ObjectiveGetProgressEvent>(OnGetProgress);

SubscribeLocalEvent<FramePersonConditionComponent, ObjectiveAssignedEvent>(OnPersonAssigned);
}

private void OnGetProgress(Entity<FramePersonConditionComponent> entity, ref ObjectiveGetProgressEvent args)
{
if (!_targetObjective.GetTarget(entity.Owner, out var target))
return;

if (entity.Comp.ObjectiveIsDone)
{
args.Progress = 1f;
return;
}

if (!TryComp<MindComponent>(target, out var mindComponent)
|| mindComponent.OriginalOwnedEntity == null)
{
Log.Error("while getting progress: target dont have a mindComponent or originalEntity is null");
args.Progress = 1f;
return;
}

args.Progress = GetProgress(GetEntity(mindComponent.OriginalOwnedEntity.Value));
if (args.Progress >= 1f)
entity.Comp.ObjectiveIsDone = true;
}

private void OnPersonAssigned(Entity<FramePersonConditionComponent> entity, ref ObjectiveAssignedEvent args)
{
args.Cancelled = !(TryPickRandomPerson(entity.Owner, args.MindId, out var target)
&& TryComp<MindComponent>(target, out var mindComponent)
&& mindComponent.OriginalOwnedEntity != null
&& TryTrackIdCardOwner(GetEntity(mindComponent.OriginalOwnedEntity.Value), args.MindId, entity.Comp));
}

private bool TryTrackIdCardOwner(EntityUid idCardOwner, EntityUid trackedByMind, FramePersonConditionComponent objective)
{
if (!_idCard.TryFindIdCard(idCardOwner, out var idCard))
return false;

var criminalStatusTracker = AddComp<CriminalStatusTrackerComponent>(idCard);
criminalStatusTracker.CriminalStatusSpecifier = objective.CriminalStatusSpecifier;
criminalStatusTracker.TrackedByMind = trackedByMind;
return true;
}

private bool TryPickRandomPerson(EntityUid objective, EntityUid objectiveOwnerMind, [NotNullWhen(true)] out EntityUid? picked, List<Type>? blacklist = null)
{
picked = null;
if (!TryComp<TargetObjectiveComponent>(objective, out var targetObjective))
return false;

if (targetObjective.Target != null)
return false;

var whitelistedPlayers = _mind.GetAliveHumans(objectiveOwnerMind)
.Where(x => CorrectJob(x) && (blacklist == null || !EntityHasAnyComponent(x, blacklist)))
.ToList();

if (whitelistedPlayers.Count == 0)
return false;

picked = _random.Pick(whitelistedPlayers);
_targetObjective.SetTarget(objective, picked.Value, targetObjective);
return true;
}

private bool EntityHasAnyComponent(EntityUid uid, List<Type> whitelist)
{
foreach (var type in whitelist)
{
if (HasComp(uid, type))
return true;
}
return false;
}

/// <summary>
/// Checks if that job can be framed. Relays on supervisor cause... no RP in code sry.
/// </summary>
private bool CorrectJob(EntityUid mindUid)
{

if (!_roleSystem.MindHasRole<MindRoleComponent>(mindUid, out var role)
|| !role.Value.Comp1.JobPrototype.HasValue)
return false;

if (_prototype.Index(role!.Value.Comp1.JobPrototype!.Value).Supervisors == _legalImmunitySupervisors)
return false;

return true;
}

private float GetProgress(EntityUid target)
{
if (!_idCard.TryFindIdCard(target, out var idCard)
|| !TryComp<CriminalStatusTrackerComponent>(idCard, out var statusTrackerComponent))
return 1f; // Uh... hmmm... fuck.... <- maybe we need to change target at that point. Anyways player have no fault of that.

return statusTrackerComponent.GetProgress();
}
}
Loading
Loading