forked from space-wizards/space-station-14
-
-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #247 from TGRCdev/revenant-animate-action
Added the revenant Animate action
- Loading branch information
Showing
30 changed files
with
815 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using Robust.Client.GameObjects; | ||
using Robust.Shared.GameStates; | ||
|
||
namespace Content.Client.Revenant; | ||
|
||
[RegisterComponent, NetworkedComponent] | ||
public sealed partial class RevenantAnimatedComponent : Component | ||
{ | ||
[DataField, ViewVariables(VVAccess.ReadOnly)] | ||
public float Accumulator = 0f; | ||
|
||
[DataField, ViewVariables(VVAccess.ReadOnly)] | ||
public Entity<PointLightComponent>? LightOverlay; | ||
|
||
[DataField, ViewVariables(VVAccess.ReadWrite)] | ||
public Color LightColor = Color.MediumPurple; | ||
|
||
[DataField, ViewVariables(VVAccess.ReadWrite)] | ||
public float LightRadius = 2f; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using Robust.Client.GameObjects; | ||
using Robust.Shared.Map; | ||
|
||
namespace Content.Client.Revenant; | ||
|
||
public sealed class RevenantAnimatedSystem : EntitySystem | ||
{ | ||
[Dependency] private readonly SharedPointLightSystem _lights = default!; | ||
|
||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
|
||
SubscribeLocalEvent<RevenantAnimatedComponent, ComponentStartup>(OnStartup); | ||
SubscribeLocalEvent<RevenantAnimatedComponent, ComponentShutdown>(OnShutdown); | ||
} | ||
|
||
public override void Update(float frameTime) | ||
{ | ||
base.Update(frameTime); | ||
|
||
var enumerator = EntityQueryEnumerator<RevenantAnimatedComponent>(); | ||
|
||
while (enumerator.MoveNext(out var uid, out var comp)) | ||
{ | ||
if (comp.LightOverlay == null) | ||
continue; | ||
comp.Accumulator += frameTime; | ||
_lights.SetEnergy(comp.LightOverlay.Value.Owner, 2f * Math.Abs((float)Math.Sin(0.25 * Math.PI * comp.Accumulator)), comp.LightOverlay.Value.Comp); | ||
} | ||
} | ||
|
||
private void OnStartup(EntityUid uid, RevenantAnimatedComponent comp, ComponentStartup args) | ||
{ | ||
var lightEnt = Spawn(null, new EntityCoordinates(uid, 0, 0)); | ||
var light = AddComp<PointLightComponent>(lightEnt); | ||
|
||
comp.LightOverlay = (lightEnt, light); | ||
|
||
_lights.SetEnabled(lightEnt, true, light); | ||
_lights.SetColor(lightEnt, comp.LightColor, light); | ||
_lights.SetRadius(lightEnt, comp.LightRadius, light); | ||
} | ||
|
||
private void OnShutdown(EntityUid uid, RevenantAnimatedComponent comp, ComponentShutdown args) | ||
{ | ||
if (comp.LightOverlay != null) | ||
Del(comp.LightOverlay); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
Content.Server/NPC/HTN/Preconditions/ActiveTimerPrecondition.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using Content.Shared.Explosion.Components; | ||
|
||
namespace Content.Server.NPC.HTN.Preconditions; | ||
|
||
/// <summary> | ||
/// Checks for the presence of <see cref="ActiveTimerTriggerComponent"/> | ||
/// </summary> | ||
public sealed partial class ActiveTimerPrecondition : HTNPrecondition | ||
{ | ||
[Dependency] private readonly IEntityManager _entManager = default!; | ||
|
||
/// <summary> | ||
/// When true, passes this precondition when the entity has an active timer. | ||
/// Otherwise, passes this precondition when the entity does not have an active timer. | ||
/// </summary> | ||
[DataField] | ||
public bool Active = true; | ||
|
||
public override bool IsMet(NPCBlackboard blackboard) | ||
{ | ||
var owner = blackboard.GetValue<EntityUid>(NPCBlackboard.Owner); | ||
|
||
return Active == _entManager.HasComponent<ActiveTimerTriggerComponent>(owner); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
Content.Server/NPC/HTN/Preconditions/ThrownPrecondition.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using Content.Shared.Throwing; | ||
|
||
namespace Content.Server.NPC.HTN.Preconditions; | ||
|
||
/// <summary> | ||
/// Checks if the owner is being thrown or not | ||
/// </summary> | ||
public sealed partial class ThrownPrecondition : HTNPrecondition | ||
{ | ||
[Dependency] private readonly IEntityManager _entMan = default!; | ||
|
||
[ViewVariables(VVAccess.ReadWrite)] [DataField] public bool IsBeingThrown = true; | ||
|
||
public override bool IsMet(NPCBlackboard blackboard) | ||
{ | ||
var owner = blackboard.GetValue<EntityUid>(NPCBlackboard.Owner); | ||
|
||
return IsBeingThrown == _entMan.HasComponent<ThrownItemComponent>(owner); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
...t.Server/NPC/HTN/PrimitiveTasks/Operators/Interactions/InteractionActivateSelfOperator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Content.Shared.DoAfter; | ||
using Content.Shared.Interaction; | ||
|
||
namespace Content.Server.NPC.HTN.PrimitiveTasks.Operators.Interactions; | ||
|
||
public sealed partial class InteractionActivateSelfOperator : HTNOperator | ||
{ | ||
[Dependency] private readonly IEntityManager _entManager = default!; | ||
|
||
/// <summary> | ||
/// If this alt-interaction started a do_after where does the key get stored. | ||
/// </summary> | ||
[DataField("idleKey")] | ||
public string IdleKey = "IdleTime"; | ||
|
||
public override async Task<(bool Valid, Dictionary<string, object>? Effects)> Plan(NPCBlackboard blackboard, CancellationToken cancelToken) | ||
{ | ||
return new(true, new Dictionary<string, object>() | ||
{ | ||
{ IdleKey, 1f } | ||
}); | ||
} | ||
|
||
public override HTNOperatorStatus Update(NPCBlackboard blackboard, float frameTime) | ||
{ | ||
var owner = blackboard.GetValue<EntityUid>(NPCBlackboard.Owner); | ||
var intSystem = _entManager.System<SharedInteractionSystem>(); | ||
var count = 0; | ||
|
||
if (_entManager.TryGetComponent<DoAfterComponent>(owner, out var doAfter)) | ||
{ | ||
count = doAfter.DoAfters.Count; | ||
} | ||
|
||
var result = intSystem.InteractionActivate(owner, owner); | ||
|
||
// Interaction started a doafter so set the idle time to it. | ||
if (result && doAfter != null && count != doAfter.DoAfters.Count) | ||
{ | ||
var wait = doAfter.DoAfters.First().Value.Args.Delay; | ||
blackboard.SetValue(IdleKey, (float) wait.TotalSeconds + 0.5f); | ||
} | ||
else | ||
{ | ||
blackboard.SetValue(IdleKey, 1f); | ||
} | ||
|
||
return result ? HTNOperatorStatus.Finished : HTNOperatorStatus.Failed; | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
...Server/NPC/HTN/PrimitiveTasks/Operators/Interactions/InteractionActivateTargetOperator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Content.Shared.DoAfter; | ||
using Content.Shared.Interaction; | ||
|
||
namespace Content.Server.NPC.HTN.PrimitiveTasks.Operators.Interactions; | ||
|
||
public sealed partial class InteractionActivateTargetOperator : HTNOperator | ||
{ | ||
[Dependency] private readonly IEntityManager _entManager = default!; | ||
|
||
[DataField("targetKey")] | ||
public string Key = "Target"; | ||
|
||
/// <summary> | ||
/// If this alt-interaction started a do_after where does the key get stored. | ||
/// </summary> | ||
[DataField("idleKey")] | ||
public string IdleKey = "IdleTime"; | ||
|
||
public override async Task<(bool Valid, Dictionary<string, object>? Effects)> Plan(NPCBlackboard blackboard, CancellationToken cancelToken) | ||
{ | ||
return new(true, new Dictionary<string, object>() | ||
{ | ||
{ IdleKey, 1f } | ||
}); | ||
} | ||
|
||
public override HTNOperatorStatus Update(NPCBlackboard blackboard, float frameTime) | ||
{ | ||
var owner = blackboard.GetValue<EntityUid>(NPCBlackboard.Owner); | ||
var target = blackboard.GetValue<EntityUid>(Key); | ||
var intSystem = _entManager.System<SharedInteractionSystem>(); | ||
var count = 0; | ||
|
||
if (_entManager.TryGetComponent<DoAfterComponent>(owner, out var doAfter)) | ||
{ | ||
count = doAfter.DoAfters.Count; | ||
} | ||
|
||
var result = intSystem.InteractionActivate(owner, target); | ||
|
||
// Interaction started a doafter so set the idle time to it. | ||
if (result && doAfter != null && count != doAfter.DoAfters.Count) | ||
{ | ||
var wait = doAfter.DoAfters.First().Value.Args.Delay; | ||
blackboard.SetValue(IdleKey, (float) wait.TotalSeconds + 0.5f); | ||
} | ||
else | ||
{ | ||
blackboard.SetValue(IdleKey, 1f); | ||
} | ||
|
||
return result ? HTNOperatorStatus.Finished : HTNOperatorStatus.Failed; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
Content.Server/NPC/HTN/PrimitiveTasks/Operators/Interactions/JumpInSlotsOperator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Content.Shared.DoAfter; | ||
using Content.Shared.Interaction; | ||
using Content.Shared.Inventory; | ||
|
||
namespace Content.Server.NPC.HTN.PrimitiveTasks.Operators.Interactions; | ||
|
||
public sealed partial class JumpInSlotsOperator : HTNOperator | ||
{ | ||
private InventorySystem _inventory = default!; | ||
|
||
[DataField("targetKey")] | ||
public string Key = "Target"; | ||
|
||
/// <summary> | ||
/// If true, a failed attempt to jump into slots will still return <see cref="HTNOperatorStatus.Finished"/> | ||
/// </summary> | ||
[DataField] | ||
public bool IgnoreFail = false; | ||
|
||
public override void Initialize(IEntitySystemManager sysManager) | ||
{ | ||
base.Initialize(sysManager); | ||
|
||
_inventory = sysManager.GetEntitySystem<InventorySystem>(); | ||
} | ||
|
||
public override HTNOperatorStatus Update(NPCBlackboard blackboard, float frameTime) | ||
{ | ||
var owner = blackboard.GetValue<EntityUid>(NPCBlackboard.Owner); | ||
var target = blackboard.GetValue<EntityUid>(Key); | ||
|
||
var result = _inventory.TryJumpIntoSlots(owner, target); | ||
|
||
return result || IgnoreFail ? HTNOperatorStatus.Finished : HTNOperatorStatus.Failed; | ||
} | ||
} |
Oops, something went wrong.