Skip to content

Commit

Permalink
Detective TC gains (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
Simyon264 authored Oct 19, 2024
2 parents 289b250 + 66ccbef commit 79c3137
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 31 deletions.
79 changes: 49 additions & 30 deletions Content.Server/_SSS/SuspicionGameRule/SuspicionRuleSystem.Rules.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Content.Server._SSS.GridMarker;
using System.Linq;
using Content.Server._SSS.GridMarker;
using Content.Server._SSS.SuspicionGameRule.Components;
using Content.Server.Communications;
using Content.Server.Ghost;
Expand Down Expand Up @@ -67,36 +68,8 @@ private void OnMobStateChanged(EntityUid uid, SuspicionPlayerComponent component
// Ok this is fucking horrible
foreach (var traitor in allTraitors)
{
var implantedComponent = CompOrNull<ImplantedComponent>(traitor.body);
if (implantedComponent == null)
continue;

foreach (var implant in implantedComponent.ImplantContainer.ContainedEntities)
{
var storeComp = CompOrNull<StoreComponent>(implant);
if (storeComp == null)
continue;

_storeSystem.TryAddCurrency(new Dictionary<string, FixedPoint2>()
{
{ "Telecrystal", sus.AmountAddedPerKill },
},
implant,
storeComp
);
}
}

var message = Loc.GetString("tc-added-sus", ("tc", sus.AmountAddedPerKill));

var channels = new List<INetChannel>();
foreach (var traitor in allTraitors)
{
var found = _playerManager.TryGetSessionByEntity(traitor.body, out var channel);
if (found)
channels.Add(channel!.Channel);
AddTcToPlayer(traitor.body, sus.AmountAddedPerKill);
}
_chatManager.ChatMessageToMany(ChatChannel.Server, message, message, EntityUid.Invalid, false, true, channels);

var allInnocents = FindAllOfType(SuspicionRole.Innocent);
var allDetectives = FindAllOfType(SuspicionRole.Detective);
Expand Down Expand Up @@ -148,6 +121,7 @@ private void OnExamine(EntityUid uid, SuspicionPlayerComponent component, ref Ex
}

var mind = _mindSystem.GetMind(args.Examined);
var examinerMind = _mindSystem.GetMind(args.Examiner);

if (mind == null)
return;
Expand All @@ -158,6 +132,42 @@ private void OnExamine(EntityUid uid, SuspicionPlayerComponent component, ref Ex
if (role.Value.Comp2.Role == SuspicionRole.Pending)
return;

if (examinerMind.HasValue) // I apologize for this being so nested. Can't use early returns with the other stuff below.
{
// If the examined is a traitor and the examinor is a detective, we give the detective any TC the traitor had.
if (role.Value.Comp2.Role == SuspicionRole.Traitor)
{
if (_roleSystem.MindHasRole<SuspicionRoleComponent>(examinerMind.Value, out var examinerRole))
{
if (examinerRole.Value.Comp2.Role == SuspicionRole.Detective)
{
var implantT = GetUplinkImplant(args.Examined);
var implantD = GetUplinkImplant(args.Examiner);
if (implantT.HasValue && implantD.HasValue)
{
var tc = implantT.Value.Comp.Balance.Values.Sum(x => x.Int());
AddTcToPlayer(args.Examiner, tc);
implantT.Value.Comp.Balance.Clear();

if (_playerManager.TryGetSessionByEntity(args.Examiner, out var session))
{
var msgFound = Loc.GetString("suspicion-found-tc", ("tc", tc));
_chatManager.ChatMessageToOne(
ChatChannel.Server,
msgFound,
msgFound,
EntityUid.Invalid,
false,
client: session.Channel,
recordReplay:true
);
}
}
}
}
}
}

args.PushMarkup(Loc.GetString(
"suspicion-examination",
("ent", args.Examined),
Expand All @@ -175,6 +185,15 @@ private void OnExamine(EntityUid uid, SuspicionPlayerComponent component, ref Ex
if (component.Revealed)
return;

if (role.Value.Comp2.Role == SuspicionRole.Traitor)
{
var allDetectives = FindAllOfType(SuspicionRole.Detective);
foreach (var det in allDetectives) // Once a Traitor is found, all detectives get 1 TC.
{
AddTcToPlayer(det.body, 1, false);
}
}

component.Revealed = true;
var trans = Comp<TransformComponent>(args.Examined);
var loc = _transformSystem.GetMapCoordinates(trans);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private void StartRound(EntityUid uid, SuspicionRuleComponent component, GameRul
}

var traitorCount = MathHelper.Clamp((int) (participatingPlayers.Count * component.TraitorPercentage), 1, allPlayerData.Count);
var detectiveCount = MathHelper.Clamp((int) (participatingPlayers.Count * component.DetectivePercentage), 0, allPlayerData.Count);
var detectiveCount = MathHelper.Clamp((int) (participatingPlayers.Count * component.DetectivePercentage), 1, allPlayerData.Count);

RobustRandom.Shuffle(participatingPlayers); // Shuffle the list so we can just take the first N players
RobustRandom.Shuffle(participatingPlayers);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
using Content.Server._SSS.SuspicionGameRule.Components;
using Content.Shared.Chat;
using Content.Shared.FixedPoint;
using Content.Shared.Humanoid;
using Content.Shared.Implants.Components;
using Content.Shared.Mind;
using Content.Shared.Mind.Components;
using Content.Shared.Roles;
using Content.Shared.Store.Components;
using Robust.Server.Containers;
using Robust.Shared.Map;
using Robust.Shared.Physics.Components;
Expand All @@ -27,6 +30,55 @@ private void SendAnnouncement(string message, Color? colorOverride = null)
colorOverride: colorOverride);
}

private void AddTcToPlayer(EntityUid player, int amount, bool displayMessage = true)
{
var implantedComponent = CompOrNull<ImplantedComponent>(player);
if (implantedComponent == null)
return;

foreach (var implant in implantedComponent.ImplantContainer.ContainedEntities)
{
var storeComp = CompOrNull<StoreComponent>(implant);
if (storeComp == null)
continue;

_storeSystem.TryAddCurrency(new Dictionary<string, FixedPoint2>()
{
{ "Telecrystal", FixedPoint2.New(amount)},
},
implant,
storeComp
);
}

if (!_playerManager.TryGetSessionByEntity(player, out var session))
return;

if (!displayMessage)
return;

var message = Loc.GetString("tc-added-sus", ("tc", amount));
_chatManager.ChatMessageToOne(ChatChannel.Server, message, message, EntityUid.Invalid, false, session.Channel);
}

private Entity<StoreComponent>? GetUplinkImplant(EntityUid player)
{
var implantedComponent = CompOrNull<ImplantedComponent>(player);
if (implantedComponent == null)
return null;

foreach (var implant in implantedComponent.ImplantContainer.ContainedEntities)
{
var storeComp = CompOrNull<StoreComponent>(implant);
if (storeComp == null)
continue;

return (implant, storeComp);
}

return null;
}

/// <summary>
/// Finds all players with a specific role.
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions Resources/Locale/en-US/_SSS/suspicion.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ suspicion-detective-uplink = Detective Uplink
tc-added-sus = You have been given {$tc} TC for your performance.
suspicion-examination = { SUBJECT($ent) } were [color={$col}]{ $role }[/color]
suspicion-examination-chat = [italic]{ $finder }[/italic] found the body of [italic]{ $found }[/italic] { $where } and discovered { SUBJECT($found) } { CONJUGATE-BASIC($found, "were", "was") } { INDEFINITE($role) } [bold][color={ $col }]{ $role }[/color][/bold].
suspicion-found-tc = You found [bold]{$tc} TC[/bold] on the body. They have been added to your uplink.
roles-antag-suspicion-traitor-name = Traitor
roles-antag-suspicion-traitor-objective = Kill the innocents while avoiding detection.
Expand Down

0 comments on commit 79c3137

Please sign in to comment.