Port medibot + bot spawners from nyano (#9854)

* Port medibot + bot spawners from nyano

* Make the injection thresholds constants

* Remove warning

* Check against const in system too

* resolving systems just isn't worth it

* only resolve entity manager once

* Reduceother resolves too

* fix post-merge

* woops
This commit is contained in:
Rane
2022-07-25 11:33:31 -04:00
committed by GitHub
parent 75574b0765
commit 57206eb49c
20 changed files with 448 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
using Content.Server.AI.WorldState;
using Content.Server.AI.WorldState.States;
using Content.Server.AI.Tracking;
using Content.Shared.Damage;
using Content.Shared.MobState.Components;
using Content.Server.Silicons.Bots;
namespace Content.Server.AI.Utility.Considerations.Bot
{
public sealed class CanInjectCon : Consideration
{
protected override float GetScore(Blackboard context)
{
var entMan = IoCManager.Resolve<IEntityManager>();
var target = context.GetState<TargetEntityState>().GetValue();
if (target == null || !entMan.TryGetComponent(target, out DamageableComponent? damageableComponent))
return 0;
if (entMan.TryGetComponent(target, out RecentlyInjectedComponent? recently))
return 0f;
if (!entMan.TryGetComponent(target, out MobStateComponent? mobState) || mobState.IsDead())
return 0f;
if (damageableComponent.TotalDamage == 0)
return 0f;
if (damageableComponent.TotalDamage <= MedibotComponent.StandardMedDamageThreshold)
return 1f;
if (damageableComponent.TotalDamage >= MedibotComponent.EmergencyMedDamageThreshold)
return 1f;
return 0f;
}
}
}

View File

@@ -0,0 +1,74 @@
using Content.Server.Chemistry.Components.SolutionManager;
using Content.Server.Chemistry.EntitySystems;
using Content.Server.AI.Tracking;
using Content.Server.Popups;
using Content.Server.Chat.Systems;
using Content.Server.Silicons.Bots;
using Content.Shared.MobState.Components;
using Content.Shared.Damage;
using Content.Shared.Interaction;
using Robust.Shared.Player;
using Robust.Shared.Audio;
namespace Content.Server.AI.EntitySystems
{
public sealed class InjectNearbySystem : EntitySystem
{
[Dependency] private readonly EntityLookupSystem _lookup = default!;
[Dependency] private readonly SolutionContainerSystem _solutionSystem = default!;
[Dependency] private readonly PopupSystem _popupSystem = default!;
[Dependency] private readonly ChatSystem _chat = default!;
[Dependency] private readonly SharedInteractionSystem _interactionSystem = default!;
public EntityUid GetNearbyInjectable(EntityUid medibot, float range = 4)
{
foreach (var entity in _lookup.GetEntitiesInRange(medibot, range))
{
if (HasComp<InjectableSolutionComponent>(entity) && HasComp<MobStateComponent>(entity))
return entity;
}
return default;
}
public bool Inject(EntityUid medibot, EntityUid target)
{
if (!TryComp<MedibotComponent>(medibot, out var botComp))
return false;
if (!TryComp<DamageableComponent>(target, out var damage))
return false;
if (!_solutionSystem.TryGetInjectableSolution(target, out var injectable))
return false;
if (!_interactionSystem.InRangeUnobstructed(medibot, target))
return true; // return true lets the bot reattempt the action on the same target
if (damage.TotalDamage == 0)
return false;
if (damage.TotalDamage <= MedibotComponent.StandardMedDamageThreshold)
{
_solutionSystem.TryAddReagent(target, injectable, botComp.StandardMed, botComp.StandardMedInjectAmount, out var accepted);
EnsureComp<RecentlyInjectedComponent>(target);
_popupSystem.PopupEntity(Loc.GetString("hypospray-component-feel-prick-message"), target, Filter.Entities(target));
SoundSystem.Play("/Audio/Items/hypospray.ogg", Filter.Pvs(target), target);
_chat.TrySendInGameICMessage(medibot, Loc.GetString("medibot-finish-inject"), InGameICChatType.Speak, false);
return true;
}
if (damage.TotalDamage >= MedibotComponent.EmergencyMedDamageThreshold)
{
_solutionSystem.TryAddReagent(target, injectable, botComp.EmergencyMed, botComp.EmergencyMedInjectAmount, out var accepted);
EnsureComp<RecentlyInjectedComponent>(target);
_popupSystem.PopupEntity(Loc.GetString("hypospray-component-feel-prick-message"), target, Filter.Entities(target));
SoundSystem.Play("/Audio/Items/hypospray.ogg", Filter.Pvs(target), target);
_chat.TrySendInGameICMessage(medibot, Loc.GetString("medibot-finish-inject"), InGameICChatType.Speak, false);
return true;
}
return false;
}
}
}

View File

@@ -0,0 +1,24 @@
using Content.Server.AI.EntitySystems;
namespace Content.Server.AI.Operators.Bots
{
public sealed class InjectOperator : AiOperator
{
private EntityUid _medibot;
private EntityUid _target;
public InjectOperator(EntityUid medibot, EntityUid target)
{
_medibot = medibot;
_target = target;
}
public override Outcome Execute(float frameTime)
{
var injectSystem = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<InjectNearbySystem>();
if (injectSystem.Inject(_medibot, _target))
return Outcome.Success;
return Outcome.Failed;
}
}
}

View File

@@ -0,0 +1,22 @@
using Content.Server.Chat.Systems;
namespace Content.Server.AI.Operators.Speech
{
public sealed class SpeakOperator : AiOperator
{
private EntityUid _speaker;
private string _speechString;
public SpeakOperator(EntityUid speaker, string speechString)
{
_speaker = speaker;
_speechString = speechString;
}
public override Outcome Execute(float frameTime)
{
var chatSystem = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<ChatSystem>();
chatSystem.TrySendInGameICMessage(_speaker, _speechString, InGameICChatType.Speak, false);
return Outcome.Success;
}
}
}

View File

@@ -0,0 +1,12 @@
namespace Content.Server.AI.Tracking
{
/// Added when a medibot injects someone
/// So they don't get injected again for at least a minute.
[RegisterComponent]
public sealed class RecentlyInjectedComponent : Component
{
public float Accumulator = 0f;
public TimeSpan RemoveTime = TimeSpan.FromMinutes(1);
}
}

View File

@@ -0,0 +1,25 @@
namespace Content.Server.AI.Tracking
{
public sealed class RecentlyInjectedSystem : EntitySystem
{
Queue<EntityUid> RemQueue = new();
public override void Update(float frameTime)
{
base.Update(frameTime);
foreach (var toRemove in RemQueue)
{
RemComp<RecentlyInjectedComponent>(toRemove);
}
RemQueue.Clear();
foreach (var entity in EntityQuery<RecentlyInjectedComponent>())
{
entity.Accumulator += frameTime;
if (entity.Accumulator < entity.RemoveTime.TotalSeconds)
continue;
entity.Accumulator = 0;
RemQueue.Enqueue(entity.Owner);
}
}
}
}

View File

@@ -0,0 +1,57 @@
using Content.Server.AI.Operators;
using Content.Server.AI.Operators.Generic;
using Content.Server.AI.Operators.Movement;
using Content.Server.AI.Operators.Bots;
using Content.Server.AI.Operators.Speech;
using Content.Server.AI.WorldState;
using Content.Server.AI.Utility.Considerations.Containers;
using Content.Server.AI.Utility.Considerations;
using Content.Server.AI.Utility.Considerations.ActionBlocker;
using Content.Server.AI.WorldState.States.Movement;
using Content.Server.AI.WorldState.States;
using Content.Server.AI.Utility.Considerations.Bot;
namespace Content.Server.AI.Utility.Actions.Bots
{
public sealed class InjectNearby : UtilityAction
{
public EntityUid Target { get; set; } = default!;
public override void SetupOperators(Blackboard context)
{
MoveToEntityOperator moveOperator = new MoveToEntityOperator(Owner, Target);
float waitTime = 3f;
ActionOperators = new Queue<AiOperator>(new AiOperator[]
{
moveOperator,
new SpeakOperator(Owner, Loc.GetString("medibot-start-inject")),
new WaitOperator(waitTime),
new InjectOperator(Owner, Target),
});
}
protected override void UpdateBlackboard(Blackboard context)
{
base.UpdateBlackboard(context);
context.GetState<TargetEntityState>().SetValue(Target);
context.GetState<MoveTargetState>().SetValue(Target);
}
protected override IReadOnlyCollection<Func<float>> GetConsiderations(Blackboard context)
{
var considerationsManager = IoCManager.Resolve<ConsiderationsManager>();
return new[]
{
considerationsManager.Get<CanMoveCon>()
.BoolCurve(context),
considerationsManager.Get<TargetAccessibleCon>()
.BoolCurve(context),
considerationsManager.Get<CanInjectCon>()
.BoolCurve(context),
};
}
}
}

View File

@@ -0,0 +1,40 @@
using Content.Server.AI.Components;
using Content.Server.AI.EntitySystems;
using Content.Server.AI.Utility.Actions;
using Content.Server.AI.Utility.Actions.Bots;
using Content.Server.AI.Utility.Considerations;
using Content.Server.AI.WorldState;
using Content.Server.AI.WorldState.States;
using Content.Server.AI.Utility.Considerations.ActionBlocker;
using Content.Server.Silicons.Bots;
namespace Content.Server.AI.Utility.ExpandableActions.Bots
{
public sealed class InjectNearbyExp : ExpandableUtilityAction
{
public override float Bonus => 30;
IEntityManager _entMan = IoCManager.Resolve<IEntityManager>();
protected override IReadOnlyCollection<Func<float>> GetCommonConsiderations(Blackboard context)
{
var considerationsManager = IoCManager.Resolve<ConsiderationsManager>();
return new[]
{
considerationsManager.Get<CanMoveCon>()
.BoolCurve(context),
};
}
public override IEnumerable<UtilityAction> GetActions(Blackboard context)
{
var owner = context.GetState<SelfState>().GetValue();
if (!_entMan.TryGetComponent(owner, out NPCComponent? controller)
|| !_entMan.TryGetComponent(owner, out MedibotComponent? bot))
{
throw new InvalidOperationException();
}
yield return new InjectNearby() {Owner = owner, Target = EntitySystem.Get<InjectNearbySystem>().GetNearbyInjectable(Owner), Bonus = Bonus};
}
}
}

View File

@@ -0,0 +1,31 @@
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
using Content.Shared.Chemistry.Reagent;
namespace Content.Server.Silicons.Bots
{
[RegisterComponent]
public sealed class MedibotComponent : Component
{
/// <summary>
/// Med the bot will inject when UNDER the standard med damage threshold.
/// </summary>
[DataField("standardMed", customTypeSerializer: typeof(PrototypeIdSerializer<ReagentPrototype>))]
public string StandardMed = "Tricordrazine";
[DataField("standardMedInjectAmount")]
public float StandardMedInjectAmount = 15f;
public const float StandardMedDamageThreshold = 50f;
/// <summary>
/// Med the bot will inject when OVER the emergency med damage threshold.
/// </summary>
[DataField("emergencyMed", customTypeSerializer: typeof(PrototypeIdSerializer<ReagentPrototype>))]
public string EmergencyMed = "Inaprovaline";
[DataField("emergencyMedInjectAmount")]
public float EmergencyMedInjectAmount = 15f;
public const float EmergencyMedDamageThreshold = 100f;
}
}

View File

@@ -0,0 +1,2 @@
medibot-start-inject = Hold still, please.
medibot-finish-inject = All done.

View File

@@ -0,0 +1,26 @@
- type: entity
name: medibot spawner
id: SpawnMobMedibot
parent: MarkerBase
components:
- type: Sprite
layers:
- state: green
- texture: Mobs/Silicon/Bots/medibot.rsi/medibot.png
- type: ConditionalSpawner
prototypes:
- MobMedibot
- type: entity
name: cleanbot spawner
id: SpawnMobCleanBot
parent: MarkerBase
components:
- type: Sprite
layers:
- state: green
- texture: Mobs/Silicon/Bots/cleanbot.rsi/cleanbot.png
- type: ConditionalSpawner
prototypes:
- MobCleanBot

View File

@@ -156,3 +156,22 @@
maxVol: 30 maxVol: 30
- type: DrainableSolution - type: DrainableSolution
solution: drainBuffer solution: drainBuffer
- type: entity
parent: MobSiliconBase
id: MobMedibot
name: medibot
description: No substitute for a doctor, but better than nothing.
components:
- type: UtilityNPC
behaviorSets:
- MediBot
- type: Medibot
- type: Sprite
drawdepth: Mobs
sprite: Mobs/Silicon/Bots/medibot.rsi
state: medibot
- type: Speech
- type: Construction
graph: MediBot
node: bot

View File

@@ -15,6 +15,9 @@
- key: enum.HealthAnalyzerUiKey.Key - key: enum.HealthAnalyzerUiKey.Key
type: HealthAnalyzerBoundUserInterface type: HealthAnalyzerBoundUserInterface
- type: HealthAnalyzer - type: HealthAnalyzer
- type: Tag
tags:
- DiscreteHealthAnalyzer
- type: entity - type: entity
parent: HandheldHealthAnalyzer parent: HandheldHealthAnalyzer

View File

@@ -14,6 +14,9 @@
size: 30 size: 30
sprite: Objects/Specific/Medical/firstaidkits.rsi sprite: Objects/Specific/Medical/firstaidkits.rsi
HeldPrefix: firstaid HeldPrefix: firstaid
- type: Tag
tags:
- Medkit
- type: entity - type: entity
name: burn treatment kit name: burn treatment kit

View File

@@ -33,6 +33,11 @@
- BufferNearbyPuddlesExp - BufferNearbyPuddlesExp
- WanderAndWait - WanderAndWait
- type: behaviorSet
id: MediBot
actions:
- InjectNearbyExp
- type: behaviorSet - type: behaviorSet
id: Spirate id: Spirate
actions: actions:

View File

@@ -0,0 +1,33 @@
- type: constructionGraph
id: MediBot
start: start
graph:
- node: start
edges:
- to: bot
steps:
- tag: Medkit
icon:
sprite: Objects/Specific/Medical/firstaidkits.rsi
state: firstaid
name: medkit
- tag: DiscreteHealthAnalyzer
icon:
sprite: Objects/Specific/Medical/healthanalyzer.rsi
state: analyzer
name: health analyzer
doAfter: 2
- prototype: ProximitySensor
icon:
sprite: Objects/Misc/proximity_sensor.rsi
state: icon
name: promixmity sensor
doAfter: 2
- tag: BorgArm
icon:
sprite: Mobs/Silicon/drone.rsi
state: l_hand
name: borg arm
doAfter: 2
- node: bot
entity: MobMedibot

View File

@@ -23,3 +23,16 @@
icon: icon:
sprite: Mobs/Silicon/Bots/honkbot.rsi sprite: Mobs/Silicon/Bots/honkbot.rsi
state: honkbot state: honkbot
- type: construction
name: medibot
id: medibot
graph: MediBot
startNode: start
targetNode: bot
category: Utilities
objectType: Item
description: This bot can help supply basic healing.
icon:
sprite: Mobs/Silicon/Bots/medibot.rsi
state: medibot

View File

@@ -144,6 +144,9 @@
- type: Tag - type: Tag
id: Dice id: Dice
- type: Tag
id: DiscreteHealthAnalyzer #So construction recipes don't eat medical PDAs
- type: Tag - type: Tag
id: Document id: Document
@@ -299,6 +302,9 @@
- type: Tag - type: Tag
id: Matchstick id: Matchstick
- type: Tag
id: Medkit
- type: Tag - type: Tag
id: Metal id: Metal

Binary file not shown.

After

Width:  |  Height:  |  Size: 635 B

View File

@@ -0,0 +1,15 @@
{
"copyright" : "Taken from https://github.com/tgstation/tgstation",
"license" : "CC-BY-SA-3.0",
"size" : {
"x" : 32,
"y" : 32
},
"states" : [
{
"directions" : 1,
"name" : "medibot"
}
],
"version" : 1
}