mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-18 14:07:53 +03:00
<!-- This is a semi-strict format, you can add/remove sections as needed but the order/format should be kept the same Remove these comments before submitting --> # Description <!-- Explain this PR in as much detail as applicable Some example prompts to consider: How might this affect the game? The codebase? What might be some alternatives to this? How/Who does this benefit/hurt [the game/codebase]? --> The Weldbot is a medibot for IPC's, Borgs and other Silicon bots. It'll behave pretty much as a medibot would, except it welds. Upon destruction, it will spill fuel on the ground. Nasty stuff. --- <!-- This is default collapsed, readers click to expand it and see all your media The PR media section can get very large at times, so this is a good way to keep it clean The title is written using HTML tags The title must be within the <summary> tags or you won't see it --> <details><summary><h1>Media</h1></summary> <p> Note: The weldbot was slow in this video, and healed only 5 units of damage. It will heal 50 now, but I don't have an up-to-date video. https://github.com/user-attachments/assets/11c2343b-3e7e-4536-8238-4ee28d51c045 </p> </details> --- # Changelog <!-- You can add an author after the `🆑` to change the name that appears in the changelog (ex: `🆑 Death`) Leaving it blank will default to your GitHub display name This includes all available types for the changelog --> 🆑 Timfa - add: Added weldbot! It'll fix IPC's, Borgs and other robots. If they stay still for long enough... --------- Signed-off-by: Timfa <timfalken@hotmail.com> Co-authored-by: Remuchi <72476615+Remuchi@users.noreply.github.com> Co-authored-by: stellar-novas <stellar_novas@riseup.net> (cherry picked from commit 20a0c5ba97bf5f6916f5a18499d56a77d21b6770)
84 lines
3.2 KiB
C#
84 lines
3.2 KiB
C#
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using Content.Server.NPC.Pathfinding;
|
|
using Content.Shared.Damage;
|
|
using Content.Shared.Emag.Components;
|
|
using Content.Shared.Interaction;
|
|
using Content.Shared.Silicons.Bots;
|
|
using Content.Shared.Tag;
|
|
using Robust.Shared.Prototypes;
|
|
|
|
namespace Content.Server.NPC.HTN.PrimitiveTasks.Operators.Specific;
|
|
|
|
public sealed partial class PickNearbyWeldableOperator : HTNOperator
|
|
{
|
|
[Dependency] private readonly IEntityManager _entManager = default!;
|
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
|
private EntityLookupSystem _lookup = default!;
|
|
private WeldbotSystem _weldbot = default!;
|
|
private PathfindingSystem _pathfinding = default!;
|
|
private TagSystem _tagSystem = default!;
|
|
|
|
[DataField] public string RangeKey = NPCBlackboard.WeldbotWeldRange;
|
|
|
|
/// <summary>
|
|
/// Target entity to weld
|
|
/// </summary>
|
|
[DataField(required: true)]
|
|
public string TargetKey = string.Empty;
|
|
|
|
/// <summary>
|
|
/// Target entitycoordinates to move to.
|
|
/// </summary>
|
|
[DataField(required: true)]
|
|
public string TargetMoveKey = string.Empty;
|
|
|
|
public override void Initialize(IEntitySystemManager sysManager)
|
|
{
|
|
base.Initialize(sysManager);
|
|
_lookup = sysManager.GetEntitySystem<EntityLookupSystem>();
|
|
_weldbot = sysManager.GetEntitySystem<WeldbotSystem>();
|
|
_pathfinding = sysManager.GetEntitySystem<PathfindingSystem>();
|
|
_tagSystem = sysManager.GetEntitySystem<TagSystem>();
|
|
}
|
|
|
|
public override async Task<(bool Valid, Dictionary<string, object>? Effects)> Plan(NPCBlackboard blackboard,
|
|
CancellationToken cancelToken)
|
|
{
|
|
var owner = blackboard.GetValue<EntityUid>(NPCBlackboard.Owner);
|
|
|
|
if (!blackboard.TryGetValue<float>(RangeKey, out var range, _entManager) || !_entManager.TryGetComponent<WeldbotComponent>(owner, out var weldbot))
|
|
return (false, null);
|
|
|
|
var damageQuery = _entManager.GetEntityQuery<DamageableComponent>();
|
|
var emagged = _entManager.HasComponent<EmaggedComponent>(owner);
|
|
|
|
foreach (var target in _lookup.GetEntitiesInRange(owner, range))
|
|
{
|
|
if (!damageQuery.TryGetComponent(target, out var damage))
|
|
continue;
|
|
|
|
var tagPrototype = _prototypeManager.Index<TagPrototype>(WeldbotWeldOperator.SiliconTag);
|
|
|
|
if (!_entManager.TryGetComponent<TagComponent>(target, out var tagComponent) || !_tagSystem.HasTag(tagComponent, tagPrototype) || !emagged && damage.DamagePerGroup["Brute"].Value == 0)
|
|
continue;
|
|
|
|
//Needed to make sure it doesn't sometimes stop right outside it's interaction range
|
|
var pathRange = SharedInteractionSystem.InteractionRange - 1f;
|
|
var path = await _pathfinding.GetPath(owner, target, pathRange, cancelToken);
|
|
|
|
if (path.Result == PathResult.NoPath)
|
|
continue;
|
|
|
|
return (true, new Dictionary<string, object>()
|
|
{
|
|
{TargetKey, target},
|
|
{TargetMoveKey, _entManager.GetComponent<TransformComponent>(target).Coordinates},
|
|
{NPCBlackboard.PathfindKey, path},
|
|
});
|
|
}
|
|
|
|
return (false, null);
|
|
}
|
|
}
|