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]? --> Adds the Plantbot! The Plantbot will help keep Hydroponics Trays filled with water and cleared of weeds. It will add water in 10u steps if there is less than 80u in the tray, and will clear weeds with 10% per step if there are more than 10% weeds in the tray. If the bot is destroyed, it will spill a bunch of water. It does **not** add nutrients, sample, harvest or plant. If emagged, it'll drink water from trays until no water remains. --- <!-- 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/9e626078-41da-423e-a9e1-f8712323ca69 </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 Plantbot --------- Signed-off-by: Timfa <timfalken@hotmail.com> Co-authored-by: sleepyyapril <123355664+sleepyyapril@users.noreply.github.com> (cherry picked from commit 56022115aaa368a825d2b529dc3675098c59f405)
97 lines
4.0 KiB
C#
97 lines
4.0 KiB
C#
using Content.Server.Botany.Components;
|
|
using Content.Server.Botany.Systems;
|
|
using Content.Server.Chat.Systems;
|
|
using Content.Shared.Chat;
|
|
using Content.Shared.Damage;
|
|
using Content.Shared.Emag.Components;
|
|
using Content.Shared.Interaction;
|
|
using Content.Shared.Popups;
|
|
using Content.Shared.Silicons.Bots;
|
|
using Content.Shared.Tag;
|
|
using Robust.Shared.Audio.Systems;
|
|
using Robust.Shared.Prototypes;
|
|
|
|
namespace Content.Server.NPC.HTN.PrimitiveTasks.Operators.Specific;
|
|
|
|
public sealed partial class PlantbotServiceOperator : HTNOperator
|
|
{
|
|
[Dependency] private readonly IEntityManager _entMan = default!;
|
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
|
|
|
private ChatSystem _chat = default!;
|
|
private SharedAudioSystem _audio = default!;
|
|
private SharedInteractionSystem _interaction = default!;
|
|
private SharedPopupSystem _popup = default!;
|
|
private PlantHolderSystem _plantHolderSystem = default!;
|
|
private DamageableSystem _damageableSystem = default!;
|
|
private TagSystem _tagSystem = default!;
|
|
|
|
public const float RequiredWaterLevelToService = 80f;
|
|
public const float RequiredWeedsAmountToWeed = 1f;
|
|
public const float WaterTransferAmount = 10f;
|
|
public const float WeedsRemovedAmount = 1f;
|
|
public const string SiliconTag = "SiliconMob";
|
|
|
|
/// <summary>
|
|
/// Target entity to inject.
|
|
/// </summary>
|
|
[DataField(required: true)]
|
|
public string TargetKey = string.Empty;
|
|
|
|
public override void Initialize(IEntitySystemManager sysManager)
|
|
{
|
|
base.Initialize(sysManager);
|
|
|
|
_chat = sysManager.GetEntitySystem<ChatSystem>();
|
|
_audio = sysManager.GetEntitySystem<SharedAudioSystem>();
|
|
_interaction = sysManager.GetEntitySystem<SharedInteractionSystem>();
|
|
_popup = sysManager.GetEntitySystem<SharedPopupSystem>();
|
|
_plantHolderSystem = sysManager.GetEntitySystem<PlantHolderSystem>();
|
|
}
|
|
|
|
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, _entMan) || _entMan.Deleted(target))
|
|
return HTNOperatorStatus.Failed;
|
|
|
|
if (!_entMan.TryGetComponent<PlantbotComponent>(owner, out var botComp)
|
|
|| !_entMan.TryGetComponent<PlantHolderComponent>(target, out var plantHolderComponent)
|
|
|| !_interaction.InRangeUnobstructed(owner, target)
|
|
|| (plantHolderComponent is { WaterLevel: >= RequiredWaterLevelToService, WeedLevel: <= RequiredWeedsAmountToWeed } && (!_entMan.HasComponent<EmaggedComponent>(owner) || plantHolderComponent.Dead || plantHolderComponent.WaterLevel <= 0f)))
|
|
return HTNOperatorStatus.Failed;
|
|
|
|
if (botComp.IsEmagged)
|
|
{
|
|
_plantHolderSystem.AdjustWater(target, -WaterTransferAmount);
|
|
_audio.PlayPvs(botComp.RemoveWaterSound, target);
|
|
}
|
|
else
|
|
{
|
|
if (plantHolderComponent.WaterLevel <= RequiredWaterLevelToService)
|
|
{
|
|
_plantHolderSystem.AdjustWater(target, 10);
|
|
_audio.PlayPvs(botComp.WaterSound, target);
|
|
_chat.TrySendInGameICMessage(owner, Loc.GetString("plantbot-add-water"), InGameICChatType.Speak, hideChat: true, hideLog: true);
|
|
}
|
|
else if (plantHolderComponent.WeedLevel >= RequiredWeedsAmountToWeed)
|
|
{
|
|
plantHolderComponent.WeedLevel -= WeedsRemovedAmount;
|
|
_audio.PlayPvs(botComp.WeedSound, target);
|
|
_chat.TrySendInGameICMessage(owner, Loc.GetString("plantbot-remove-weeds"), InGameICChatType.Speak, hideChat: true, hideLog: true);
|
|
}
|
|
else
|
|
return HTNOperatorStatus.Failed;
|
|
}
|
|
|
|
return HTNOperatorStatus.Finished;
|
|
}
|
|
}
|