Store ninja objectives in conditions 2 (#20894)

* move spider charge target from role

* shorter field names

* remove ninja role comment

* remove unused systems in SpaceNinjaSystem

* GenericAntagObjectivesAddedEvent

* check if warp point is on same map

* remove unnecessary import

* add missing loc when spider charge has no target

* a

* remove spider charge target requirement comp

* inline SpiderChargeTitle

* allow planting charge without objective

* remove map check

* fix role check when planting

* obj.Target

* Fix merge

---------

Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
Vyacheslav Kovalevsky
2024-01-29 07:06:32 +03:00
committed by GitHub
parent 2a6705818b
commit 7311ce671f
10 changed files with 67 additions and 83 deletions

View File

@@ -60,7 +60,7 @@ public sealed class GenericAntagSystem : EntitySystem
} }
/// <summary> /// <summary>
/// Event raised on a player's entity after its simple antag rule is started and objectives get added. /// Event raised on a player's entity after its simple antag rule is started.
/// Use this to add a briefing, roles, etc. /// Use this to add a briefing, roles, etc.
/// </summary> /// </summary>
[ByRefEvent] [ByRefEvent]

View File

@@ -7,7 +7,6 @@ using Content.Server.PowerCell;
using Content.Server.Research.Systems; using Content.Server.Research.Systems;
using Content.Server.Roles; using Content.Server.Roles;
using Content.Server.GenericAntag; using Content.Server.GenericAntag;
using Content.Server.Warps;
using Content.Shared.Alert; using Content.Shared.Alert;
using Content.Shared.Clothing.EntitySystems; using Content.Shared.Clothing.EntitySystems;
using Content.Shared.Doors.Components; using Content.Shared.Doors.Components;
@@ -17,9 +16,11 @@ using Content.Shared.Ninja.Components;
using Content.Shared.Ninja.Systems; using Content.Shared.Ninja.Systems;
using Content.Shared.Popups; using Content.Shared.Popups;
using Content.Shared.Rounding; using Content.Shared.Rounding;
using Robust.Shared.Random; using Robust.Shared.Audio;
using Robust.Shared.Player;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using Content.Server.Objectives.Components; using Content.Server.Objectives.Components;
using Robust.Shared.Audio.Systems;
namespace Content.Server.Ninja.Systems; namespace Content.Server.Ninja.Systems;
@@ -37,9 +38,9 @@ public sealed class SpaceNinjaSystem : SharedSpaceNinjaSystem
[Dependency] private readonly AlertsSystem _alerts = default!; [Dependency] private readonly AlertsSystem _alerts = default!;
[Dependency] private readonly BatterySystem _battery = default!; [Dependency] private readonly BatterySystem _battery = default!;
[Dependency] private readonly IChatManager _chatMan = default!; [Dependency] private readonly IChatManager _chatMan = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly PowerCellSystem _powerCell = default!; [Dependency] private readonly PowerCellSystem _powerCell = default!;
[Dependency] private readonly RoleSystem _role = default!; [Dependency] private readonly RoleSystem _role = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SharedMindSystem _mind = default!; [Dependency] private readonly SharedMindSystem _mind = default!;
[Dependency] private readonly StealthClothingSystem _stealthClothing = default!; [Dependency] private readonly StealthClothingSystem _stealthClothing = default!;
@@ -161,18 +162,9 @@ public sealed class SpaceNinjaSystem : SharedSpaceNinjaSystem
_role.MindAddRole(mindId, role, mind); _role.MindAddRole(mindId, role, mind);
_role.MindPlaySound(mindId, config.GreetingSound, mind); _role.MindPlaySound(mindId, config.GreetingSound, mind);
// choose spider charge detonation point var session = mind.Session;
var warps = new List<EntityUid>(); _audio.PlayGlobal(config.GreetingSound, Filter.Empty().AddPlayer(session), false, AudioParams.Default);
var query = EntityQueryEnumerator<BombingTargetComponent, WarpPointComponent>(); _chatMan.DispatchServerMessage(session, Loc.GetString("ninja-role-greeting"));
while (query.MoveNext(out var warpUid, out _, out var warp))
{
warps.Add(warpUid);
}
if (warps.Count > 0)
role.SpiderChargeTarget = _random.Pick(warps);
_chatMan.DispatchServerMessage(mind.Session, Loc.GetString("ninja-role-greeting"));
} }
// TODO: PowerCellDraw, modify when cloak enabled // TODO: PowerCellDraw, modify when cloak enabled

View File

@@ -1,4 +1,5 @@
using Content.Server.Explosion.EntitySystems; using Content.Server.Explosion.EntitySystems;
using Content.Server.GameTicking.Rules.Components;
using Content.Server.Mind; using Content.Server.Mind;
using Content.Server.Objectives.Components; using Content.Server.Objectives.Components;
using Content.Server.Popups; using Content.Server.Popups;
@@ -38,7 +39,7 @@ public sealed class SpiderChargeSystem : EntitySystem
var user = args.User; var user = args.User;
if (!_mind.TryGetRole<NinjaRoleComponent>(user, out var role)) if (!_mind.TryGetRole<NinjaRoleComponent>(user, out var _))
{ {
_popup.PopupEntity(Loc.GetString("spider-charge-not-ninja"), user, user); _popup.PopupEntity(Loc.GetString("spider-charge-not-ninja"), user, user);
args.Cancelled = true; args.Cancelled = true;
@@ -46,11 +47,11 @@ public sealed class SpiderChargeSystem : EntitySystem
} }
// allow planting anywhere if there is no target, which should never happen // allow planting anywhere if there is no target, which should never happen
if (role.SpiderChargeTarget == null) if (!_mind.TryGetObjectiveComp<SpiderChargeConditionComponent>(user, out var obj) || obj.Target == null)
return; return;
// assumes warp point still exists // assumes warp point still exists
var targetXform = Transform(role.SpiderChargeTarget.Value); var targetXform = Transform(obj.Target.Value);
var locXform = Transform(args.Target); var locXform = Transform(args.Target);
if (locXform.MapID != targetXform.MapID || if (locXform.MapID != targetXform.MapID ||
(_transform.GetWorldPosition(locXform) - _transform.GetWorldPosition(targetXform)).LengthSquared() > comp.Range * comp.Range) (_transform.GetWorldPosition(locXform) - _transform.GetWorldPosition(targetXform)).LengthSquared() > comp.Range * comp.Range)
@@ -79,6 +80,6 @@ public sealed class SpiderChargeSystem : EntitySystem
return; return;
// assumes the target was destroyed, that the charge wasn't moved somehow // assumes the target was destroyed, that the charge wasn't moved somehow
obj.SpiderChargeDetonated = true; obj.Detonated = true;
} }
} }

View File

@@ -6,9 +6,15 @@ namespace Content.Server.Objectives.Components;
/// <summary> /// <summary>
/// Requires that the player is a ninja and blew up their spider charge at its target location. /// Requires that the player is a ninja and blew up their spider charge at its target location.
/// </summary> /// </summary>
[RegisterComponent, Access(typeof(NinjaConditionsSystem), typeof(SpiderChargeSystem))] [RegisterComponent, Access(typeof(NinjaConditionsSystem), typeof(SpiderChargeSystem), typeof(SpaceNinjaSystem))]
public sealed partial class SpiderChargeConditionComponent : Component public sealed partial class SpiderChargeConditionComponent : Component
{ {
[DataField("spiderChargeDetonated"), ViewVariables(VVAccess.ReadWrite)] [DataField, ViewVariables(VVAccess.ReadWrite)]
public bool SpiderChargeDetonated; public bool Detonated;
/// <summary>
/// Warp point that the spider charge has to target
/// </summary>
[DataField, ViewVariables(VVAccess.ReadWrite)]
public EntityUid? Target;
} }

View File

@@ -1,11 +0,0 @@
using Content.Server.Objectives.Systems;
namespace Content.Server.Objectives.Components;
/// <summary>
/// Requires the player to be a ninja that has a spider charge target assigned, which is almost always the case.
/// </summary>
[RegisterComponent, Access(typeof(SpiderChargeTargetRequirementSystem))]
public sealed partial class SpiderChargeTargetRequirementComponent : Component
{
}

View File

@@ -1,7 +1,10 @@
using Content.Server.Roles;
using Content.Server.Objectives.Components; using Content.Server.Objectives.Components;
using Content.Server.Warps; using Content.Server.Warps;
using Content.Shared.Objectives.Components; using Content.Shared.Objectives.Components;
using Content.Shared.Mind;
using Content.Shared.Ninja.Components;
using Robust.Shared.Random;
using Content.Server.Roles;
namespace Content.Server.Objectives.Systems; namespace Content.Server.Objectives.Systems;
@@ -13,11 +16,14 @@ public sealed class NinjaConditionsSystem : EntitySystem
{ {
[Dependency] private readonly MetaDataSystem _metaData = default!; [Dependency] private readonly MetaDataSystem _metaData = default!;
[Dependency] private readonly NumberObjectiveSystem _number = default!; [Dependency] private readonly NumberObjectiveSystem _number = default!;
[Dependency] private readonly SharedMindSystem _mind = default!;
[Dependency] private readonly IRobustRandom _random = default!;
public override void Initialize() public override void Initialize()
{ {
SubscribeLocalEvent<DoorjackConditionComponent, ObjectiveGetProgressEvent>(OnDoorjackGetProgress); SubscribeLocalEvent<DoorjackConditionComponent, ObjectiveGetProgressEvent>(OnDoorjackGetProgress);
SubscribeLocalEvent<SpiderChargeConditionComponent, RequirementCheckEvent>(OnSpiderChargeRequirementCheck);
SubscribeLocalEvent<SpiderChargeConditionComponent, ObjectiveAfterAssignEvent>(OnSpiderChargeAfterAssign); SubscribeLocalEvent<SpiderChargeConditionComponent, ObjectiveAfterAssignEvent>(OnSpiderChargeAfterAssign);
SubscribeLocalEvent<SpiderChargeConditionComponent, ObjectiveGetProgressEvent>(OnSpiderChargeGetProgress); SubscribeLocalEvent<SpiderChargeConditionComponent, ObjectiveGetProgressEvent>(OnSpiderChargeGetProgress);
@@ -43,28 +49,50 @@ public sealed class NinjaConditionsSystem : EntitySystem
} }
// spider charge // spider charge
private void OnSpiderChargeRequirementCheck(EntityUid uid, SpiderChargeConditionComponent comp, ref RequirementCheckEvent args)
{
if (args.Cancelled || !HasComp<NinjaRoleComponent>(args.MindId))
{
return;
}
// choose spider charge detonation point
var warps = new List<EntityUid>();
var query = EntityQueryEnumerator<BombingTargetComponent, WarpPointComponent>();
while (query.MoveNext(out var warpUid, out _, out var warp))
{
if (warp.Location != null)
{
warps.Add(warpUid);
}
}
if (warps.Count <= 0)
{
args.Cancelled = true;
return;
}
comp.Target = _random.Pick(warps);
}
private void OnSpiderChargeAfterAssign(EntityUid uid, SpiderChargeConditionComponent comp, ref ObjectiveAfterAssignEvent args) private void OnSpiderChargeAfterAssign(EntityUid uid, SpiderChargeConditionComponent comp, ref ObjectiveAfterAssignEvent args)
{ {
_metaData.SetEntityName(uid, SpiderChargeTitle(args.MindId), args.Meta); string title;
if (comp.Target == null || !TryComp<WarpPointComponent>(comp.Target, out var warp) || warp.Location == null)
{
// this should never really happen but eh
title = Loc.GetString("objective-condition-spider-charge-title-no-target");
}
else
{
title = Loc.GetString("objective-condition-spider-charge-title", ("location", warp.Location));
}
_metaData.SetEntityName(uid, title, args.Meta);
} }
private void OnSpiderChargeGetProgress(EntityUid uid, SpiderChargeConditionComponent comp, ref ObjectiveGetProgressEvent args) private void OnSpiderChargeGetProgress(EntityUid uid, SpiderChargeConditionComponent comp, ref ObjectiveGetProgressEvent args)
{ {
args.Progress = comp.SpiderChargeDetonated ? 1f : 0f; args.Progress = comp.Detonated ? 1f : 0f;
}
private string SpiderChargeTitle(EntityUid mindId)
{
if (!TryComp<NinjaRoleComponent>(mindId, out var role) ||
role.SpiderChargeTarget == null ||
!TryComp<WarpPointComponent>(role.SpiderChargeTarget, out var warp))
{
// this should never really happen but eh
return Loc.GetString("objective-condition-spider-charge-title-no-target");
}
return Loc.GetString("objective-condition-spider-charge-title", ("location", warp.Location ?? Name(role.SpiderChargeTarget.Value)));
} }
// steal research // steal research

View File

@@ -1,24 +0,0 @@
using Content.Server.Objectives.Components;
using Content.Server.Roles;
using Content.Shared.Objectives.Components;
namespace Content.Server.Objectives.Systems;
public sealed class SpiderChargeTargetRequirementSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<SpiderChargeTargetRequirementComponent, RequirementCheckEvent>(OnCheck);
}
private void OnCheck(EntityUid uid, SpiderChargeTargetRequirementComponent comp, ref RequirementCheckEvent args)
{
if (args.Cancelled)
return;
if (!TryComp<NinjaRoleComponent>(args.MindId, out var role) || role.SpiderChargeTarget == null)
args.Cancelled = true;
}
}

View File

@@ -2,15 +2,7 @@ using Content.Shared.Roles;
namespace Content.Server.Roles; namespace Content.Server.Roles;
/// <summary>
/// Stores the ninja's objectives on the mind so if they die the rest of the greentext persists.
/// </summary>
[RegisterComponent] [RegisterComponent]
public sealed partial class NinjaRoleComponent : AntagonistRoleComponent public sealed partial class NinjaRoleComponent : AntagonistRoleComponent
{ {
/// <summary>
/// Warp point that the spider charge has to target
/// </summary>
[DataField("spiderChargeTarget")]
public EntityUid? SpiderChargeTarget;
} }

View File

@@ -1 +1,2 @@
objective-condition-spider-charge-title-no-target = Detonate the spider clan charge (no target)
objective-condition-spider-charge-title = Detonate the spider clan charge in {$location} objective-condition-spider-charge-title = Detonate the spider clan charge in {$location}

View File

@@ -54,7 +54,6 @@
icon: icon:
sprite: Objects/Weapons/Bombs/spidercharge.rsi sprite: Objects/Weapons/Bombs/spidercharge.rsi
state: icon state: icon
- type: SpiderChargeTargetRequirement
- type: SpiderChargeCondition - type: SpiderChargeCondition
- type: entity - type: entity