Files
wwdpublic/Content.Server/NPC/HTN/PrimitiveTasks/Operators/Specific/WeldbotWeldOperator.cs
Timfa b7c755531a Weldbot (#1703)
<!--
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)
2025-02-15 00:03:45 +03:00

92 lines
3.8 KiB
C#

using Content.Server.Chat.Systems;
using Content.Shared.Chat;
using Content.Shared.Damage;
using Content.Shared.Damage.Prototypes;
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 WeldbotWeldOperator : HTNOperator
{
[Dependency] private readonly IEntityManager _entMan = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
private ChatSystem _chat = default!;
private WeldbotSystem _weldbot = default!;
private SharedAudioSystem _audio = default!;
private SharedInteractionSystem _interaction = default!;
private SharedPopupSystem _popup = default!;
private DamageableSystem _damageableSystem = default!;
private TagSystem _tagSystem = default!;
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>();
_weldbot = sysManager.GetEntitySystem<WeldbotSystem>();
_audio = sysManager.GetEntitySystem<SharedAudioSystem>();
_interaction = sysManager.GetEntitySystem<SharedInteractionSystem>();
_popup = sysManager.GetEntitySystem<SharedPopupSystem>();
_damageableSystem = sysManager.GetEntitySystem<DamageableSystem>();
_tagSystem = sysManager.GetEntitySystem<TagSystem>();
}
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;
var tagPrototype = _prototypeManager.Index<TagPrototype>(SiliconTag);
if (!_entMan.TryGetComponent<TagComponent>(target, out var tagComponent) || !_tagSystem.HasTag(tagComponent, tagPrototype)
|| !_entMan.TryGetComponent<WeldbotComponent>(owner, out var botComp)
|| !_entMan.TryGetComponent<DamageableComponent>(target, out var damage)
|| !_interaction.InRangeUnobstructed(owner, target)
|| (damage.DamagePerGroup["Brute"].Value == 0 && !_entMan.HasComponent<EmaggedComponent>(owner)))
return HTNOperatorStatus.Failed;
if (botComp.IsEmagged)
{
if (!_prototypeManager.TryIndex<DamageGroupPrototype>("Burn", out var prototype))
return HTNOperatorStatus.Failed;
_damageableSystem.TryChangeDamage(target, new DamageSpecifier(prototype, 10), true, false, damage);
}
else
{
if (!_prototypeManager.TryIndex<DamageGroupPrototype>("Brute", out var prototype))
return HTNOperatorStatus.Failed;
_damageableSystem.TryChangeDamage(target, new DamageSpecifier(prototype, -50), true, false, damage);
}
_audio.PlayPvs(botComp.WeldSound, target);
if(damage.DamagePerGroup["Brute"].Value == 0) //only say "all done if we're actually done!"
_chat.TrySendInGameICMessage(owner, Loc.GetString("weldbot-finish-weld"), InGameICChatType.Speak, hideChat: true, hideLog: true);
return HTNOperatorStatus.Finished;
}
}