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)
78 lines
3.1 KiB
C#
78 lines
3.1 KiB
C#
using Content.Server.Disposal.Unit.Components;
|
|
using Content.Shared.Body.Part;
|
|
using Content.Shared.DeviceLinking;
|
|
using Content.Shared.Disposal;
|
|
using Content.Shared.Hands.Components;
|
|
using Content.Shared.Hands.EntitySystems;
|
|
using Content.Shared.Materials;
|
|
using Content.Shared.Silicons.Bots;
|
|
|
|
|
|
namespace Content.Server.NPC.HTN.PrimitiveTasks.Operators.Specific;
|
|
|
|
public sealed partial class FillLinkedMachineOperator : HTNOperator
|
|
{
|
|
[Dependency] private readonly IEntityManager _entManager = default!;
|
|
private SharedMaterialStorageSystem _sharedMaterialStorage = default!;
|
|
private SharedDisposalUnitSystem _sharedDisposalUnitSystem = default!;
|
|
private SharedHandsSystem _sharedHandsSystem = default!;
|
|
|
|
/// <summary>
|
|
/// Target entity to inject.
|
|
/// </summary>
|
|
[DataField(required: true)]
|
|
public string TargetKey = string.Empty;
|
|
|
|
public override void Initialize(IEntitySystemManager sysManager)
|
|
{
|
|
base.Initialize(sysManager);
|
|
_sharedMaterialStorage = sysManager.GetEntitySystem<SharedMaterialStorageSystem>();
|
|
_sharedDisposalUnitSystem = sysManager.GetEntitySystem<SharedDisposalUnitSystem>();
|
|
_sharedHandsSystem = sysManager.GetEntitySystem<SharedHandsSystem>();
|
|
}
|
|
|
|
public override void TaskShutdown(NPCBlackboard blackboard, HTNOperatorStatus status)
|
|
{
|
|
base.TaskShutdown(blackboard, status);
|
|
blackboard.Remove<EntityUid>(TargetKey);
|
|
}
|
|
|
|
public override HTNOperatorStatus Update(NPCBlackboard blackboard, float frameTime)
|
|
{
|
|
var owner = blackboard.GetValue<EntityUid>(NPCBlackboard.Owner);
|
|
|
|
if (!blackboard.TryGetValue<EntityUid>(TargetKey, out var target, _entManager) || _entManager.Deleted(target)
|
|
|| !_entManager.TryGetComponent(owner, out FillbotComponent? fillbot)
|
|
|| !_entManager.HasComponent<HandsComponent>(owner)
|
|
|| !_entManager.TryGetComponent(owner, out DeviceLinkSourceComponent? fillbotlinks)
|
|
|| fillbotlinks.LinkedPorts.Count != 1
|
|
|| fillbot.LinkedSinkEntity == null
|
|
|| _entManager.Deleted(fillbot.LinkedSinkEntity))
|
|
return HTNOperatorStatus.Failed;
|
|
|
|
_entManager.TryGetComponent(fillbot.LinkedSinkEntity, out MaterialStorageComponent? linkedStorage);
|
|
_entManager.TryGetComponent(fillbot.LinkedSinkEntity, out DisposalUnitComponent? disposalUnit);
|
|
|
|
var heldItem = _sharedHandsSystem.GetActiveItem(owner);
|
|
|
|
if (heldItem == null || _entManager.HasComponent<BodyPartComponent>(heldItem))
|
|
{
|
|
_sharedHandsSystem.TryDrop(owner);
|
|
return HTNOperatorStatus.Failed;
|
|
}
|
|
|
|
if (linkedStorage is not null
|
|
&& _sharedMaterialStorage.TryInsertMaterialEntity(owner, heldItem.Value, fillbot.LinkedSinkEntity!.Value))
|
|
return HTNOperatorStatus.Finished;
|
|
|
|
else if (disposalUnit is not null)
|
|
{
|
|
_sharedDisposalUnitSystem.DoInsertDisposalUnit(fillbot.LinkedSinkEntity!.Value, heldItem.Value, owner);
|
|
return HTNOperatorStatus.Finished;
|
|
}
|
|
|
|
_sharedHandsSystem.TryDrop(owner);
|
|
return HTNOperatorStatus.Failed;
|
|
}
|
|
}
|