mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-18 05:59:03 +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 humble fillbot! Takes items from the ground and inserts them into a lathe, silo or disposal unit it's linked to! --- # TODO <!-- A list of everything you have to do before this PR is "complete" You probably won't have to complete everything before merging but it's good to leave future references --> - [x] Make the robot pick up items - [x] Make the robot insert items - [x] Make the robot differentiate between trash inputs - [ ] Make the robot only linkable to the correct ports --- <!-- 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> https://github.com/user-attachments/assets/f0cd26c0-36fb-43e2-8bdb-c100f033668b https://github.com/user-attachments/assets/3809b033-01a6-4b4f-96e0-f4730dd2e92d https://github.com/user-attachments/assets/ccf325f3-ee60-42f8-9e68-75fafe596a7b </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 --> 🆑 - add: Added Fillbot. Link it to a lathe, material silo, ore processor or disposal unit with a multitool and watch it gather stuff! --------- Signed-off-by: Timfa <timfalken@hotmail.com> Co-authored-by: VMSolidus <evilexecutive@gmail.com> Co-authored-by: sleepyyapril <123355664+sleepyyapril@users.noreply.github.com> (cherry picked from commit a71192bdf05a3b7a40323bb16983c25be432bfc4)
61 lines
2.2 KiB
C#
61 lines
2.2 KiB
C#
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using Content.Server.NPC.Pathfinding;
|
|
using Content.Shared.DeviceLinking;
|
|
using Content.Shared.Interaction;
|
|
using Content.Shared.Silicons.Bots;
|
|
|
|
namespace Content.Server.NPC.HTN.PrimitiveTasks.Operators.Specific;
|
|
|
|
public sealed partial class FindLinkedMachineOperator : HTNOperator
|
|
{
|
|
[Dependency] private readonly IEntityManager _entManager = default!;
|
|
private PathfindingSystem _pathfinding = default!;
|
|
|
|
[DataField] public string RangeKey = NPCBlackboard.FillbotPickupRange;
|
|
|
|
/// <summary>
|
|
/// Target entity to find
|
|
/// </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);
|
|
_pathfinding = sysManager.GetEntitySystem<PathfindingSystem>();
|
|
}
|
|
|
|
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 _, _entManager)
|
|
|| !_entManager.TryGetComponent<FillbotComponent>(owner, out var fillbot)
|
|
|| !_entManager.TryGetComponent<DeviceLinkSourceComponent>(owner, out var fillbotlinks)
|
|
|| fillbotlinks.LinkedPorts.Count != 1
|
|
|| fillbot.LinkedSinkEntity == null
|
|
|| _entManager.Deleted(fillbot.LinkedSinkEntity))
|
|
return (false, null);
|
|
|
|
var path = await _pathfinding.GetPath(owner, fillbot.LinkedSinkEntity.Value, SharedInteractionSystem.InteractionRange - 0.5f, cancelToken);
|
|
|
|
if (path.Result == PathResult.NoPath)
|
|
return (false, null);
|
|
|
|
return (true, new()
|
|
{
|
|
{TargetKey, fillbot.LinkedSinkEntity},
|
|
{TargetMoveKey, _entManager.GetComponent<TransformComponent>(fillbot.LinkedSinkEntity.Value).Coordinates},
|
|
{NPCBlackboard.PathfindKey, path},
|
|
});
|
|
}
|
|
}
|