[Fix] move ninja objectives into NinjaRole (#15490)
Co-authored-by: deltanedas <@deltanedas:kde.org>
This commit is contained in:
43
Content.Server/Ninja/NinjaRole.cs
Normal file
43
Content.Server/Ninja/NinjaRole.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using Content.Server.Traitor;
|
||||
using Content.Shared.Roles;
|
||||
|
||||
namespace Content.Server.Ninja;
|
||||
|
||||
/// <summary>
|
||||
/// Stores the ninja's objectives in the mind so if they die the rest of the greentext persists.
|
||||
/// </summary>
|
||||
public sealed class NinjaRole : TraitorRole
|
||||
{
|
||||
public NinjaRole(Mind.Mind mind, AntagPrototype antagPrototype) : base(mind, antagPrototype) { }
|
||||
|
||||
/// <summary>
|
||||
/// Number of doors that have been doorjacked, used for objective
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public int DoorsJacked = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Research nodes that have been downloaded, used for objective
|
||||
/// </summary>
|
||||
// TODO: client doesn't need to know what nodes are downloaded, just how many
|
||||
[ViewVariables]
|
||||
public HashSet<string> DownloadedNodes = new();
|
||||
|
||||
/// <summary>
|
||||
/// Warp point that the spider charge has to target
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public EntityUid? SpiderChargeTarget = null;
|
||||
|
||||
/// <summary>
|
||||
/// Whether the spider charge has been detonated on the target, used for objective
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public bool SpiderChargeDetonated;
|
||||
|
||||
/// <summary>
|
||||
/// Whether the comms console has been hacked, used for objective
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public bool CalledInThreat;
|
||||
}
|
||||
@@ -1,15 +1,20 @@
|
||||
using Content.Server.Communications;
|
||||
using Content.Server.DoAfter;
|
||||
using Content.Server.Ninja.Systems;
|
||||
using Content.Server.Power.Components;
|
||||
using Content.Shared.DoAfter;
|
||||
using Content.Shared.Interaction.Events;
|
||||
using Content.Shared.Ninja.Components;
|
||||
using Content.Shared.Ninja.Systems;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Research.Components;
|
||||
|
||||
namespace Content.Server.Ninja.Systems;
|
||||
|
||||
public sealed class NinjaGlovesSystem : SharedNinjaGlovesSystem
|
||||
{
|
||||
[Dependency] private readonly new NinjaSystem _ninja = default!;
|
||||
|
||||
protected override void OnDrain(EntityUid uid, NinjaDrainComponent comp, InteractionAttemptEvent args)
|
||||
{
|
||||
if (!GloveCheck(uid, args, out var gloves, out var user, out var target)
|
||||
@@ -29,8 +34,59 @@ public sealed class NinjaGlovesSystem : SharedNinjaGlovesSystem
|
||||
_doAfter.TryStartDoAfter(doAfterArgs);
|
||||
}
|
||||
|
||||
protected override bool IsCommsConsole(EntityUid uid)
|
||||
protected override void OnDownloadDoAfter(EntityUid uid, NinjaDownloadComponent comp, DownloadDoAfterEvent args)
|
||||
{
|
||||
return HasComp<CommunicationsConsoleComponent>(uid);
|
||||
if (args.Cancelled || args.Handled)
|
||||
return;
|
||||
|
||||
var user = args.User;
|
||||
var target = args.Target;
|
||||
|
||||
if (!TryComp<NinjaComponent>(user, out var ninja)
|
||||
|| !TryComp<TechnologyDatabaseComponent>(target, out var database))
|
||||
return;
|
||||
|
||||
var gained = _ninja.Download(uid, database.TechnologyIds);
|
||||
var str = gained == 0
|
||||
? Loc.GetString("ninja-download-fail")
|
||||
: Loc.GetString("ninja-download-success", ("count", gained), ("server", target));
|
||||
|
||||
Popups.PopupEntity(str, user, user, PopupType.Medium);
|
||||
}
|
||||
|
||||
protected override void OnTerror(EntityUid uid, NinjaTerrorComponent comp, InteractionAttemptEvent args)
|
||||
{
|
||||
if (!GloveCheck(uid, args, out var gloves, out var user, out var target)
|
||||
|| !_ninja.GetNinjaRole(user, out var role)
|
||||
|| !HasComp<CommunicationsConsoleComponent>(target))
|
||||
return;
|
||||
|
||||
|
||||
// can only do it once
|
||||
if (role.CalledInThreat)
|
||||
{
|
||||
Popups.PopupEntity(Loc.GetString("ninja-terror-already-called"), user, user);
|
||||
return;
|
||||
}
|
||||
|
||||
var doAfterArgs = new DoAfterArgs(user, comp.TerrorTime, new TerrorDoAfterEvent(), target: target, used: uid, eventTarget: uid)
|
||||
{
|
||||
BreakOnDamage = true,
|
||||
BreakOnUserMove = true,
|
||||
MovementThreshold = 0.5f,
|
||||
CancelDuplicate = false
|
||||
};
|
||||
|
||||
_doAfter.TryStartDoAfter(doAfterArgs);
|
||||
// FIXME: doesnt work, don't show the console popup
|
||||
args.Cancel();
|
||||
}
|
||||
|
||||
protected override void OnTerrorDoAfter(EntityUid uid, NinjaTerrorComponent comp, TerrorDoAfterEvent args)
|
||||
{
|
||||
if (args.Cancelled || args.Handled)
|
||||
return;
|
||||
|
||||
_ninja.CallInThreat(args.User);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,12 +8,12 @@ using Content.Server.GameTicking.Rules;
|
||||
using Content.Server.GameTicking.Rules.Configurations;
|
||||
using Content.Server.Ghost.Roles.Events;
|
||||
using Content.Server.Mind.Components;
|
||||
using Content.Server.Ninja;
|
||||
using Content.Server.Ninja.Components;
|
||||
using Content.Server.Objectives;
|
||||
using Content.Server.Popups;
|
||||
using Content.Server.Power.Components;
|
||||
using Content.Server.PowerCell;
|
||||
using Content.Server.Traitor;
|
||||
using Content.Server.Warps;
|
||||
using Content.Shared.Alert;
|
||||
using Content.Shared.Doors.Components;
|
||||
@@ -32,6 +32,7 @@ using Robust.Shared.Player;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Random;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
|
||||
namespace Content.Server.Ninja.Systems;
|
||||
|
||||
@@ -89,6 +90,49 @@ public sealed class NinjaSystem : SharedNinjaSystem
|
||||
GreetNinja(mind);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Download the given set of nodes, returning how many new nodes were downloaded.'
|
||||
/// </summary>
|
||||
public int Download(EntityUid uid, List<string> ids)
|
||||
{
|
||||
if (!GetNinjaRole(uid, out var role))
|
||||
return 0;
|
||||
|
||||
var oldCount = role.DownloadedNodes.Count;
|
||||
role.DownloadedNodes.UnionWith(ids);
|
||||
var newCount = role.DownloadedNodes.Count;
|
||||
return newCount - oldCount;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a ninja's role using the player's mind
|
||||
/// </summary>
|
||||
public static bool GetNinjaRole(Mind.Mind? mind, [NotNullWhen(true)] out NinjaRole? role)
|
||||
{
|
||||
if (mind == null)
|
||||
{
|
||||
role = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
role = (NinjaRole?) mind.AllRoles
|
||||
.Where(r => r is NinjaRole)
|
||||
.FirstOrDefault();
|
||||
return role != null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a ninja's role using the player's entity id
|
||||
/// </summary>
|
||||
public bool GetNinjaRole(EntityUid uid, [NotNullWhen(true)] out NinjaRole? role)
|
||||
{
|
||||
role = null;
|
||||
if (!TryComp<MindComponent>(uid, out var mind))
|
||||
return false;
|
||||
|
||||
return GetNinjaRole(mind.Mind, out role);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the space ninja spawn gamerule's config
|
||||
/// </summary>
|
||||
@@ -150,14 +194,17 @@ public sealed class NinjaSystem : SharedNinjaSystem
|
||||
return GetNinjaBattery(user, out var battery) && battery.TryUseCharge(charge);
|
||||
}
|
||||
|
||||
public override void CallInThreat(NinjaComponent comp)
|
||||
/// <summary>
|
||||
/// Completes the objective, makes announcement and adds rule of a random threat.
|
||||
/// </summary>
|
||||
public void CallInThreat(EntityUid uid)
|
||||
{
|
||||
base.CallInThreat(comp);
|
||||
|
||||
var config = RuleConfig();
|
||||
if (config.Threats.Count == 0)
|
||||
if (config.Threats.Count == 0 || !GetNinjaRole(uid, out var role) || role.CalledInThreat)
|
||||
return;
|
||||
|
||||
role.CalledInThreat = true;
|
||||
|
||||
var threat = _random.Pick(config.Threats);
|
||||
if (_proto.TryIndex<GameRulePrototype>(threat.Rule, out var rule))
|
||||
{
|
||||
@@ -224,7 +271,38 @@ public sealed class NinjaSystem : SharedNinjaSystem
|
||||
|
||||
_implants.ForceImplant(uid, implant, implantComp);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnNinjaSpawned(EntityUid uid, NinjaComponent comp, GhostRoleSpawnerUsedEvent args)
|
||||
{
|
||||
// inherit spawner's station grid
|
||||
if (TryComp<NinjaStationGridComponent>(args.Spawner, out var station))
|
||||
SetNinjaStationGrid(uid, station.Grid);
|
||||
}
|
||||
|
||||
private void OnNinjaMindAdded(EntityUid uid, NinjaComponent comp, MindAddedMessage args)
|
||||
{
|
||||
Logger.ErrorS("ninja_testing", "AMONG US 2 RELASED");
|
||||
if (TryComp<MindComponent>(uid, out var mind) && mind.Mind != null)
|
||||
GreetNinja(mind.Mind);
|
||||
}
|
||||
|
||||
private void GreetNinja(Mind.Mind mind)
|
||||
{
|
||||
Logger.ErrorS("ninja_testing", "GREETING");
|
||||
if (!mind.TryGetSession(out var session))
|
||||
return;
|
||||
|
||||
var config = RuleConfig();
|
||||
var role = new NinjaRole(mind, _proto.Index<AntagPrototype>("SpaceNinja"));
|
||||
mind.AddRole(role);
|
||||
_traitorRule.Traitors.Add(role);
|
||||
foreach (var objective in config.Objectives)
|
||||
{
|
||||
AddObjective(mind, objective);
|
||||
}
|
||||
|
||||
Logger.ErrorS("ninja_testing", "added role");
|
||||
// choose spider charge detonation point
|
||||
// currently based on warp points, something better could be done (but would likely require mapping work)
|
||||
var warps = new List<EntityUid>();
|
||||
@@ -237,35 +315,7 @@ public sealed class NinjaSystem : SharedNinjaSystem
|
||||
}
|
||||
|
||||
if (warps.Count > 0)
|
||||
comp.SpiderChargeTarget = _random.Pick(warps);
|
||||
}
|
||||
|
||||
private void OnNinjaSpawned(EntityUid uid, NinjaComponent comp, GhostRoleSpawnerUsedEvent args)
|
||||
{
|
||||
// inherit spawner's station grid
|
||||
if (TryComp<NinjaStationGridComponent>(args.Spawner, out var station))
|
||||
SetNinjaStationGrid(uid, station.Grid);
|
||||
}
|
||||
|
||||
private void OnNinjaMindAdded(EntityUid uid, NinjaComponent comp, MindAddedMessage args)
|
||||
{
|
||||
if (TryComp<MindComponent>(uid, out var mind) && mind.Mind != null)
|
||||
GreetNinja(mind.Mind);
|
||||
}
|
||||
|
||||
private void GreetNinja(Mind.Mind mind)
|
||||
{
|
||||
if (!mind.TryGetSession(out var session))
|
||||
return;
|
||||
|
||||
var config = RuleConfig();
|
||||
var role = new TraitorRole(mind, _proto.Index<AntagPrototype>("SpaceNinja"));
|
||||
mind.AddRole(role);
|
||||
_traitorRule.Traitors.Add(role);
|
||||
foreach (var objective in config.Objectives)
|
||||
{
|
||||
AddObjective(mind, objective);
|
||||
}
|
||||
role.SpiderChargeTarget = _random.Pick(warps);
|
||||
|
||||
_audio.PlayGlobal(config.GreetingSound, Filter.Empty().AddPlayer(session), false, AudioParams.Default);
|
||||
_chatMan.DispatchServerMessage(session, Loc.GetString("ninja-role-greeting"));
|
||||
@@ -285,8 +335,8 @@ public sealed class NinjaSystem : SharedNinjaSystem
|
||||
private void OnDoorEmagged(EntityUid uid, DoorComponent door, ref DoorEmaggedEvent args)
|
||||
{
|
||||
// make sure it's a ninja doorjacking it
|
||||
if (TryComp<NinjaComponent>(args.UserUid, out var ninja))
|
||||
ninja.DoorsJacked++;
|
||||
if (GetNinjaRole(args.UserUid, out var role))
|
||||
role.DoorsJacked++;
|
||||
}
|
||||
|
||||
private void UpdateNinja(EntityUid uid, NinjaComponent ninja, float frameTime)
|
||||
|
||||
@@ -26,7 +26,7 @@ public sealed class SpiderChargeSystem : EntitySystem
|
||||
{
|
||||
var user = args.User;
|
||||
|
||||
if (!TryComp<NinjaComponent>(user, out var ninja))
|
||||
if (!_ninja.GetNinjaRole(user, out var role))
|
||||
{
|
||||
_popups.PopupEntity(Loc.GetString("spider-charge-not-ninja"), user, user);
|
||||
args.Handled = true;
|
||||
@@ -34,17 +34,16 @@ public sealed class SpiderChargeSystem : EntitySystem
|
||||
}
|
||||
|
||||
// allow planting anywhere if there is no target, which should never happen
|
||||
if (ninja.SpiderChargeTarget != null)
|
||||
if (role.SpiderChargeTarget == null)
|
||||
return;
|
||||
|
||||
// assumes warp point still exists
|
||||
var target = Transform(role.SpiderChargeTarget.Value).MapPosition;
|
||||
var coords = args.ClickLocation.ToMap(EntityManager, _transform);
|
||||
if (!coords.InRange(target, comp.Range))
|
||||
{
|
||||
// assumes warp point still exists
|
||||
var target = Transform(ninja.SpiderChargeTarget.Value).MapPosition;
|
||||
var coords = args.ClickLocation.ToMap(EntityManager, _transform);
|
||||
if (!coords.InRange(target, comp.Range))
|
||||
{
|
||||
_popups.PopupEntity(Loc.GetString("spider-charge-too-far"), user, user);
|
||||
args.Handled = true;
|
||||
return;
|
||||
}
|
||||
_popups.PopupEntity(Loc.GetString("spider-charge-too-far"), user, user);
|
||||
args.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,10 +54,10 @@ public sealed class SpiderChargeSystem : EntitySystem
|
||||
|
||||
private void OnExplode(EntityUid uid, SpiderChargeComponent comp, TriggerEvent args)
|
||||
{
|
||||
if (comp.Planter == null || !TryComp<NinjaComponent>(comp.Planter, out var ninja))
|
||||
if (comp.Planter == null || !_ninja.GetNinjaRole(comp.Planter.Value, out var role))
|
||||
return;
|
||||
|
||||
// assumes the target was destroyed, that the charge wasn't moved somehow
|
||||
_ninja.DetonateSpiderCharge(ninja);
|
||||
role.SpiderChargeDetonated = true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user