* Material

* good prototype

* Fix material storage

* You can insert biomass into the cloner

* ok, basic biomass subtraction works

* amogus

* ok chance works

* Alright, the biomass and genetic stuff works

* feedback for cloning

* more reclaimer polish

* ship it

* starting biomass + fix lathes

* I changed my mind on rat mass and these guys are definitely getting ground up

* Doafter

* clean up, sync the two

* fix naming, fix mass

* technology + construction

* additional logging, stop unanchoring when active

* fix event / logs

* dont gib dead salvage

* auto eject

* fix deconstruction behavior

* make warning message better, temporarily disable cancer scanner

* fix biomass stacks

* add easy mode CVAR

* stack cleanup, make biomass 2x as fast

* bugfix

* new sprite from hyenh

* fix tests

* hello? :smilethink:

* :smilethink:

* medical scanner gets antirotting

* fix cloner and medical scanner

Co-authored-by: Moony <moonheart08@users.noreply.github.com>
This commit is contained in:
Rane
2022-08-29 22:31:27 -04:00
committed by GitHub
parent b111ce8246
commit f36d278499
44 changed files with 764 additions and 114 deletions

View File

@@ -17,7 +17,6 @@ namespace Content.Server.Atmos.Miasma
[Dependency] private readonly TransformSystem _transformSystem = default!;
[Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!;
[Dependency] private readonly DamageableSystem _damageableSystem = default!;
[Dependency] private readonly IRobustRandom _random = default!;
/// System Variables

View File

@@ -116,13 +116,13 @@ public sealed class ClimbSystem : SharedClimbSystem
if (TryBonk(component, user))
return;
_doAfterSystem.DoAfter(new DoAfterEventArgs(entityToMove, component.ClimbDelay, default, climbable)
_doAfterSystem.DoAfter(new DoAfterEventArgs(entityToMove, component.ClimbDelay, default, climbable, user)
{
BreakOnTargetMove = true,
BreakOnUserMove = true,
BreakOnDamage = true,
BreakOnStun = true,
UserFinishedEvent = new ClimbFinishedEvent(user, climbable)
UserFinishedEvent = new ClimbFinishedEvent(user, climbable, entityToMove)
});
}
@@ -155,10 +155,10 @@ public sealed class ClimbSystem : SharedClimbSystem
private void OnClimbFinished(EntityUid uid, ClimbingComponent climbing, ClimbFinishedEvent args)
{
Climb(uid, args.User, args.Climbable, climbing: climbing);
Climb(uid, args.User, args.Instigator, args.Climbable, climbing: climbing);
}
private void Climb(EntityUid uid, EntityUid user, EntityUid climbable, bool silent = false, ClimbingComponent? climbing = null,
private void Climb(EntityUid uid, EntityUid user, EntityUid instigator, EntityUid climbable, bool silent = false, ClimbingComponent? climbing = null,
PhysicsComponent? physics = null, FixturesComponent? fixtures = null)
{
if (!Resolve(uid, ref climbing, ref physics, ref fixtures, false))
@@ -174,7 +174,7 @@ public sealed class ClimbSystem : SharedClimbSystem
// there's also the cases where the user might collide with the person they are forcing onto the climbable that i haven't accounted for
RaiseLocalEvent(uid, new StartClimbEvent(climbable), false);
RaiseLocalEvent(climbable, new ClimbedOnEvent(uid), false);
RaiseLocalEvent(climbable, new ClimbedOnEvent(uid, user), false);
if (silent)
return;
@@ -343,7 +343,7 @@ public sealed class ClimbSystem : SharedClimbSystem
public void ForciblySetClimbing(EntityUid uid, EntityUid climbable, ClimbingComponent? component = null)
{
Climb(uid, uid, climbable, true, component);
Climb(uid, uid, uid, climbable, true, component);
}
private void OnBuckleChange(EntityUid uid, ClimbingComponent component, BuckleChangeEvent args)
@@ -436,14 +436,16 @@ public sealed class ClimbSystem : SharedClimbSystem
internal sealed class ClimbFinishedEvent : EntityEventArgs
{
public ClimbFinishedEvent(EntityUid user, EntityUid climbable)
public ClimbFinishedEvent(EntityUid user, EntityUid climbable, EntityUid instigator)
{
User = user;
Climbable = climbable;
Instigator = instigator;
}
public EntityUid User { get; }
public EntityUid Climbable { get; }
public EntityUid Instigator { get; }
}
/// <summary>
@@ -452,10 +454,12 @@ internal sealed class ClimbFinishedEvent : EntityEventArgs
public sealed class ClimbedOnEvent : EntityEventArgs
{
public EntityUid Climber;
public EntityUid Instigator;
public ClimbedOnEvent(EntityUid climber)
public ClimbedOnEvent(EntityUid climber, EntityUid instigator)
{
Climber = climber;
Instigator = instigator;
}
}

View File

@@ -7,8 +7,8 @@ using Content.Server.Mind.Components;
using Content.Server.MachineLinking.System;
using Content.Server.MachineLinking.Events;
using Content.Server.UserInterface;
using Content.Shared.MobState.Components;
using Content.Server.MobState;
using Content.Shared.MobState.Components;
using Content.Server.Power.EntitySystems;
using Robust.Server.GameObjects;
using Robust.Server.Player;
@@ -55,10 +55,6 @@ namespace Content.Server.Cloning.Systems
if (consoleComponent.GeneticScanner != null && consoleComponent.CloningPod != null)
TryClone(uid, consoleComponent.CloningPod.Value, consoleComponent.GeneticScanner.Value, consoleComponent: consoleComponent);
break;
case UiButton.Eject:
if (consoleComponent.CloningPod != null)
TryEject(uid, consoleComponent.CloningPod.Value, consoleComponent: consoleComponent);
break;
}
UpdateUserInterface(consoleComponent);
}
@@ -123,14 +119,6 @@ namespace Content.Server.Cloning.Systems
_uiSystem.GetUiOrNull(consoleComponent.Owner, CloningConsoleUiKey.Key)?.SetState(newState);
}
public void TryEject(EntityUid uid, EntityUid clonePodUid, CloningPodComponent? cloningPod = null, CloningConsoleComponent? consoleComponent = null)
{
if (!Resolve(uid, ref consoleComponent) || !Resolve(clonePodUid, ref cloningPod))
return;
_cloningSystem.Eject(clonePodUid, cloningPod);
}
public void TryClone(EntityUid uid, EntityUid cloningPodUid, EntityUid scannerUid, CloningPodComponent? cloningPod = null, MedicalScannerComponent? scannerComp = null, CloningConsoleComponent? consoleComponent = null)
{
if (!Resolve(uid, ref consoleComponent) || !Resolve(cloningPodUid, ref cloningPod) || !Resolve(scannerUid, ref scannerComp))
@@ -222,9 +210,10 @@ namespace Content.Server.Cloning.Systems
EntityUid? cloneBody = clonePod.BodyContainer.ContainedEntity;
clonerMindPresent = clonePod.Status == CloningPodStatus.Cloning;
if (cloneBody != null)
if (HasComp<ActiveCloningPodComponent>(consoleComponent.CloningPod))
{
cloneBodyInfo = Identity.Name(cloneBody.Value, EntityManager);
if (cloneBody != null)
cloneBodyInfo = Identity.Name(cloneBody.Value, EntityManager);
clonerStatus = ClonerStatus.ClonerOccupied;
}
}
@@ -244,5 +233,6 @@ namespace Content.Server.Cloning.Systems
clonerInRange
);
}
}
}

View File

@@ -1,19 +1,35 @@
using Content.Server.Cloning.Components;
using Content.Server.Mind.Components;
using Content.Server.Power.EntitySystems;
using Content.Shared.GameTicking;
using Content.Shared.CharacterAppearance.Systems;
using Content.Shared.CharacterAppearance.Components;
using Content.Shared.Species;
using Robust.Server.Player;
using Robust.Shared.Prototypes;
using Content.Server.EUI;
using Robust.Shared.Containers;
using Robust.Server.Containers;
using Content.Shared.Damage;
using Content.Shared.Stacks;
using Content.Shared.Examine;
using Content.Shared.Cloning;
using Content.Shared.Atmos;
using Content.Shared.CCVar;
using Content.Server.Cloning.Components;
using Content.Server.Mind.Components;
using Content.Server.Power.EntitySystems;
using Content.Server.Atmos.EntitySystems;
using Content.Server.EUI;
using Content.Server.MachineLinking.System;
using Content.Server.MachineLinking.Events;
using Content.Server.MobState;
using Content.Server.Lathe.Components;
using Content.Shared.Chemistry.Components;
using Content.Server.Fluids.EntitySystems;
using Content.Server.Chat.Systems;
using Content.Server.Construction.Components;
using Content.Server.Stack;
using Robust.Server.GameObjects;
using Robust.Server.Containers;
using Robust.Server.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using Robust.Shared.Configuration;
using Robust.Shared.Containers;
namespace Content.Server.Cloning.Systems
{
@@ -28,17 +44,29 @@ namespace Content.Server.Cloning.Systems
[Dependency] private readonly ContainerSystem _containerSystem = default!;
[Dependency] private readonly MobStateSystem _mobStateSystem = default!;
[Dependency] private readonly PowerReceiverSystem _powerReceiverSystem = default!;
[Dependency] private readonly IRobustRandom _robustRandom = default!;
[Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!;
[Dependency] private readonly TransformSystem _transformSystem = default!;
[Dependency] private readonly SharedStackSystem _stackSystem = default!;
[Dependency] private readonly StackSystem _serverStackSystem = default!;
[Dependency] private readonly SpillableSystem _spillableSystem = default!;
[Dependency] private readonly ChatSystem _chatSystem = default!;
[Dependency] private readonly IConfigurationManager _configManager = default!;
public readonly Dictionary<Mind.Mind, EntityUid> ClonesWaitingForMind = new();
public const float EasyModeCloningCost = 0.7f;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<CloningPodComponent, ComponentInit>(OnComponentInit);
SubscribeLocalEvent<CloningPodComponent, MachineDeconstructedEvent>(OnDeconstruct);
SubscribeLocalEvent<RoundRestartCleanupEvent>(Reset);
SubscribeLocalEvent<BeingClonedComponent, MindAddedMessage>(HandleMindAdded);
SubscribeLocalEvent<CloningPodComponent, PortDisconnectedEvent>(OnPortDisconnected);
SubscribeLocalEvent<CloningPodComponent, AnchorStateChangedEvent>(OnAnchor);
SubscribeLocalEvent<CloningPodComponent, ExaminedEvent>(OnExamined);
}
private void OnComponentInit(EntityUid uid, CloningPodComponent clonePod, ComponentInit args)
@@ -47,6 +75,14 @@ namespace Content.Server.Cloning.Systems
_signalSystem.EnsureReceiverPorts(uid, CloningPodComponent.PodPort);
}
private void OnDeconstruct(EntityUid uid, CloningPodComponent component, MachineDeconstructedEvent args)
{
if (!TryComp<MaterialStorageComponent>(uid, out var storage))
return;
_serverStackSystem.SpawnMultiple(storage.GetMaterialAmount("Biomass"), 100, "Biomass", Transform(uid).Coordinates);
}
private void UpdateAppearance(CloningPodComponent clonePod)
{
if (TryComp<AppearanceComponent>(clonePod.Owner, out var appearance))
@@ -97,11 +133,23 @@ namespace Content.Server.Cloning.Systems
_cloningConsoleSystem.UpdateUserInterface(console);
}
private void OnExamined(EntityUid uid, CloningPodComponent component, ExaminedEvent args)
{
if (!args.IsInDetailsRange || !_powerReceiverSystem.IsPowered(uid))
return;
if (TryComp<MaterialStorageComponent>(uid, out var storage))
args.PushMarkup(Loc.GetString("cloning-pod-biomass", ("number", storage.GetMaterialAmount("Biomass"))));
}
public bool TryCloning(EntityUid uid, EntityUid bodyToClone, Mind.Mind mind, CloningPodComponent? clonePod)
{
if (!Resolve(uid, ref clonePod) || bodyToClone == null)
return false;
if (HasComp<ActiveCloningPodComponent>(uid))
return false;
if (ClonesWaitingForMind.TryGetValue(mind, out var clone))
{
if (EntityManager.EntityExists(clone) &&
@@ -120,11 +168,56 @@ namespace Content.Server.Cloning.Systems
if (mind.UserId == null || !_playerManager.TryGetSessionById(mind.UserId.Value, out var client))
return false; // If we can't track down the client, we can't offer transfer. That'd be quite bad.
if (!TryComp<MaterialStorageComponent>(clonePod.Owner, out var podStorage))
return false;
if (!TryComp<HumanoidAppearanceComponent>(bodyToClone, out var humanoid))
return false; // whatever body was to be cloned, was not a humanoid
var speciesProto = _prototype.Index<SpeciesPrototype>(humanoid.Species).Prototype;
var mob = Spawn(speciesProto, Transform(clonePod.Owner).MapPosition);
if (!_prototype.TryIndex<SpeciesPrototype>(humanoid.Species, out var speciesPrototype))
return false;
if (!TryComp<PhysicsComponent>(bodyToClone, out var physics))
return false;
int cloningCost = (int) physics.FixturesMass;
if (_configManager.GetCVar(CCVars.BiomassEasyMode))
cloningCost = (int) Math.Round(cloningCost * EasyModeCloningCost);
// biomass checks
var biomassAmount = podStorage.GetMaterialAmount("Biomass");
if (biomassAmount < cloningCost)
{
if (clonePod.ConnectedConsole != null)
_chatSystem.TrySendInGameICMessage(clonePod.ConnectedConsole.Value, Loc.GetString("cloning-console-chat-error", ("units", cloningCost)), InGameICChatType.Speak, false);
return false;
}
podStorage.RemoveMaterial("Biomass", cloningCost);
clonePod.UsedBiomass = cloningCost;
// end of biomass checks
// genetic damage checks
if (TryComp<DamageableComponent>(bodyToClone, out var damageable) &&
damageable.Damage.DamageDict.TryGetValue("Cellular", out var cellularDmg))
{
var chance = Math.Clamp((float) (cellularDmg / 100), 0, 1);
if (cellularDmg > 0 && clonePod.ConnectedConsole != null)
_chatSystem.TrySendInGameICMessage(clonePod.ConnectedConsole.Value, Loc.GetString("cloning-console-cellular-warning", ("percent", Math.Round(100 - (chance * 100)))), InGameICChatType.Speak, false);
if (_robustRandom.Prob(chance))
{
UpdateStatus(CloningPodStatus.Gore, clonePod);
clonePod.FailedClone = true;
AddComp<ActiveCloningPodComponent>(uid);
return true;
}
}
// end of genetic damage checks
var mob = Spawn(speciesPrototype.Prototype, Transform(clonePod.Owner).MapPosition);
_appearanceSystem.UpdateAppearance(mob, humanoid.Appearance);
_appearanceSystem.UpdateSexGender(mob, humanoid.Sex, humanoid.Gender);
@@ -156,16 +249,17 @@ namespace Content.Server.Cloning.Systems
if (!_powerReceiverSystem.IsPowered(cloning.Owner))
continue;
if (cloning.BodyContainer.ContainedEntity != null)
{
cloning.CloningProgress += frameTime;
cloning.CloningProgress = MathHelper.Clamp(cloning.CloningProgress, 0f, cloning.CloningTime);
}
if (cloning.BodyContainer.ContainedEntity == null && !cloning.FailedClone)
continue;
if (cloning.CapturedMind?.Session?.AttachedEntity == cloning.BodyContainer.ContainedEntity)
{
cloning.CloningProgress += frameTime;
if (cloning.CloningProgress < cloning.CloningTime)
continue;
if (cloning.FailedClone)
EndFailedCloning(cloning.Owner, cloning);
else
Eject(cloning.Owner, cloning);
}
}
}
@@ -181,10 +275,40 @@ namespace Content.Server.Cloning.Systems
clonePod.BodyContainer.Remove(entity);
clonePod.CapturedMind = null;
clonePod.CloningProgress = 0f;
clonePod.UsedBiomass = 0;
UpdateStatus(CloningPodStatus.Idle, clonePod);
RemCompDeferred<ActiveCloningPodComponent>(uid);
}
private void EndFailedCloning(EntityUid uid, CloningPodComponent clonePod)
{
clonePod.FailedClone = false;
clonePod.CloningProgress = 0f;
UpdateStatus(CloningPodStatus.Idle, clonePod);
var transform = Transform(uid);
var indices = _transformSystem.GetGridOrMapTilePosition(uid);
var tileMix = _atmosphereSystem.GetTileMixture(transform.GridUid, null, indices, true);
Solution bloodSolution = new();
int i = 0;
while (i < 1)
{
tileMix?.AdjustMoles(Gas.Miasma, 6f);
bloodSolution.AddReagent("Blood", 50);
if (_robustRandom.Prob(0.2f))
i++;
}
_spillableSystem.SpillAt(uid, bloodSolution, "PuddleBlood");
var biomassStack = Spawn("MaterialBiomass", transform.Coordinates);
_stackSystem.SetCount(biomassStack, _robustRandom.Next(1, (int) (clonePod.UsedBiomass / 2.5)));
clonePod.UsedBiomass = 0;
RemCompDeferred<ActiveCloningPodComponent>(uid);
}
public void Reset(RoundRestartCleanupEvent ev)
{
ClonesWaitingForMind.Clear();

View File

@@ -10,6 +10,8 @@ namespace Content.Server.Cloning.Components
[ViewVariables] public ContainerSlot BodyContainer = default!;
[ViewVariables] public Mind.Mind? CapturedMind;
[ViewVariables] public float CloningProgress = 0;
[ViewVariables] public int UsedBiomass = 70;
[ViewVariables] public bool FailedClone = false;
[DataField("cloningTime")]
[ViewVariables] public float CloningTime = 30f;
[ViewVariables] public CloningPodStatus Status;

View File

@@ -1,10 +1,7 @@
using Content.Shared.Lathe;
using Content.Shared.Research.Prototypes;
using Robust.Server.GameObjects;
using Content.Shared.Whitelist;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List;
using Content.Shared.Materials;
using Robust.Shared.Audio;
namespace Content.Server.Lathe.Components
@@ -12,20 +9,6 @@ namespace Content.Server.Lathe.Components
[RegisterComponent]
public sealed class LatheComponent : SharedLatheComponent
{
/// <summary>
/// Whitelist for specifying the kind of materials that can be insert into the lathe
/// </summary>
[ViewVariables]
[DataField("whitelist")]
public EntityWhitelist? LatheWhitelist;
/// <summary>
/// Whitelist generated on runtime for what items are specifically used for the lathe's recipes.
/// </summary>
[ViewVariables]
[DataField("materialWhiteList", customTypeSerializer: typeof(PrototypeIdListSerializer<MaterialPrototype>))]
public List<string> MaterialWhiteList = new();
/// <summary>
/// The lathe's construction queue
/// </summary>
@@ -49,12 +32,6 @@ namespace Content.Server.Lathe.Components
/// </summary>
[DataField("producingSound")]
public SoundSpecifier? ProducingSound;
/// <summary>
/// The sound that plays when inserting an item into the lathe, if any
/// </summary>
[DataField("insertingSound")]
public SoundSpecifier? InsertingSound;
/// <summmary>
/// The lathe's UI.

View File

@@ -1,4 +1,8 @@
using Content.Shared.Lathe;
using Content.Shared.Whitelist;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List;
using Content.Shared.Materials;
using Robust.Shared.Audio;
namespace Content.Server.Lathe.Components
{
@@ -17,6 +21,26 @@ namespace Content.Server.Lathe.Components
[DataField("StorageLimit")]
private int _storageLimit = -1;
/// <summary>
/// Whitelist for specifying the kind of items that can be insert into this entity.
/// </summary>
[ViewVariables]
[DataField("whitelist")]
public EntityWhitelist? EntityWhitelist;
/// <summary>
/// Whitelist generated on runtime for what specific materials can be inserted into this entity.
/// </summary>
[ViewVariables]
[DataField("materialWhiteList", customTypeSerializer: typeof(PrototypeIdListSerializer<MaterialPrototype>))]
public List<string> MaterialWhiteList = new();
/// <summary>
/// The sound that plays when inserting an item into the storage
/// </summary>
[DataField("insertingSound")]
public SoundSpecifier? InsertingSound;
public override ComponentState GetComponentState()
{
return new MaterialStorageState(Storage);
@@ -73,5 +97,14 @@ namespace Content.Server.Lathe.Components
{
return InsertMaterial(id, -amount);
}
// forgive me I needed to write a crumb of e/c code to not go fucking insane i swear i will ecs this entire shitty fucking system one day
public int GetMaterialAmount(string id)
{
if (!Storage.TryGetValue(id, out var amount))
return 0;
return amount;
}
}
}

View File

@@ -32,7 +32,7 @@ namespace Content.Server.Lathe
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<LatheComponent, InteractUsingEvent>(OnInteractUsing);
SubscribeLocalEvent<MaterialStorageComponent, InteractUsingEvent>(OnInteractUsing);
SubscribeLocalEvent<LatheComponent, ComponentInit>(OnComponentInit);
SubscribeLocalEvent<LatheComponent, LatheQueueRecipeMessage>(OnLatheQueueRecipeMessage);
SubscribeLocalEvent<LatheComponent, LatheSyncRequestMessage>(OnLatheSyncRequestMessage);
@@ -85,35 +85,34 @@ namespace Content.Server.Lathe
if (recipes == null)
return;
if (!TryComp<MaterialStorageComponent>(uid, out var storage))
return;
foreach (var recipe in recipes)
{
foreach (var mat in recipe.RequiredMaterials)
{
if (!component.MaterialWhiteList.Contains(mat.Key))
component.MaterialWhiteList.Add(mat.Key);
if (!storage.MaterialWhiteList.Contains(mat.Key))
storage.MaterialWhiteList.Add(mat.Key);
}
}
}
/// <summary>
/// When someone tries to use an item on the lathe,
/// insert it if it's a stack and fits inside
/// </summary>
private void OnInteractUsing(EntityUid uid, LatheComponent component, InteractUsingEvent args)
private void OnInteractUsing(EntityUid uid, MaterialStorageComponent component, InteractUsingEvent args)
{
if (args.Handled)
return;
if (!TryComp<MaterialStorageComponent>(uid, out var storage)
|| !TryComp<MaterialComponent>(args.Used, out var material)
|| component.LatheWhitelist?.IsValid(args.Used) == false)
|| storage.EntityWhitelist?.IsValid(args.Used) == false)
return;
args.Handled = true;
var matUsed = false;
foreach (var mat in material.Materials)
if (component.MaterialWhiteList.Contains(mat.ID))
if (storage.MaterialWhiteList.Contains(mat.ID))
matUsed = true;
if (!matUsed)
@@ -148,16 +147,25 @@ namespace Content.Server.Lathe
lastMat = mat;
}
EntityManager.QueueDeleteEntity(args.Used);
// Play a sound when inserting, if any
if (component.InsertingSound != null)
_audioSys.PlayPvs(component.InsertingSound, uid);
_popupSystem.PopupEntity(Loc.GetString("machine-insert-item", ("machine", uid),
("item", args.Used)), uid, Filter.Entities(args.User));
// TODO: You can probably split this part off of lathe component too
if (!TryComp<LatheComponent>(uid, out var lathe))
return;
// We need the prototype to get the color
_prototypeManager.TryIndex(lastMat, out MaterialPrototype? matProto);
EntityManager.QueueDeleteEntity(args.Used);
EnsureComp<LatheInsertingComponent>(uid).TimeRemaining = component.InsertionTime;
EnsureComp<LatheInsertingComponent>(uid).TimeRemaining = lathe.InsertionTime;
_popupSystem.PopupEntity(Loc.GetString("machine-insert-item", ("machine", uid),
("item", args.Used)), uid, Filter.Entities(args.User));

View File

@@ -0,0 +1,6 @@
namespace Content.Server.Medical.BiomassReclaimer
{
[RegisterComponent]
public sealed class ActiveBiomassReclaimerComponent : Component
{}
}

View File

@@ -0,0 +1,53 @@
using Content.Shared.Storage;
using System.Threading;
namespace Content.Server.Medical.BiomassReclaimer
{
[RegisterComponent]
public sealed class BiomassReclaimerComponent : Component
{
public CancellationTokenSource? CancelToken;
[DataField("accumulator")]
public float Accumulator = 0f;
[DataField("randomMessAccumulator")]
public float RandomMessAccumulator = 0f;
public TimeSpan RandomMessInterval = TimeSpan.FromSeconds(5);
/// <summary>
/// This gets set for each mob it processes.
/// When accumulator hits this, spit out biomass.
/// </summary>
public float CurrentProcessingTime = 70f;
/// <summary>
/// This is calculated from the YieldPerUnitMass
/// and adjusted for genetic damage too.
/// </summary>
public float CurrentExpectedYield = 28f;
public string BloodReagent = "Blood";
public List<EntitySpawnEntry> SpawnedEntities = new();
/// <summary>
/// How many units of biomass it produces for each unit of mass.
/// </summary>
[DataField("yieldPerUnitMass")]
public float YieldPerUnitMass = 0.4f;
/// <summary>
/// Lower number = faster processing.
/// Good for machine upgrading I guess.
/// </summmary>
public float ProcessingSpeedMultiplier = 0.5f;
/// <summary>
/// Will this refuse to gib a living mob?
/// </summary>
[DataField("safetyEnabled")]
public bool SafetyEnabled = true;
}
}

View File

@@ -0,0 +1,245 @@
using System.Threading;
using Content.Shared.MobState.Components;
using Content.Shared.Interaction;
using Content.Shared.Audio;
using Content.Shared.Jittering;
using Content.Shared.Chemistry.Components;
using Content.Shared.Throwing;
using Content.Shared.Construction.Components;
using Content.Shared.Nutrition.Components;
using Content.Shared.Administration.Logs;
using Content.Shared.CCVar;
using Content.Shared.Database;
using Content.Shared.CharacterAppearance.Components;
using Content.Server.MobState;
using Content.Server.Power.Components;
using Content.Server.Fluids.EntitySystems;
using Content.Server.Body.Components;
using Content.Server.Climbing;
using Content.Server.DoAfter;
using Content.Server.Mind.Components;
using Content.Server.Stack;
using Robust.Shared.Player;
using Robust.Shared.Random;
using Robust.Shared.Configuration;
using Robust.Server.Player;
namespace Content.Server.Medical.BiomassReclaimer
{
public sealed class BiomassReclaimerSystem : EntitySystem
{
[Dependency] private readonly IConfigurationManager _configManager = default!;
[Dependency] private readonly StackSystem _stackSystem = default!;
[Dependency] private readonly MobStateSystem _mobState = default!;
[Dependency] private readonly SharedJitteringSystem _jitteringSystem = default!;
[Dependency] private readonly SharedAudioSystem _sharedAudioSystem = default!;
[Dependency] private readonly SharedAmbientSoundSystem _ambientSoundSystem = default!;
[Dependency] private readonly SpillableSystem _spillableSystem = default!;
[Dependency] private readonly ThrowingSystem _throwing = default!;
[Dependency] private readonly IRobustRandom _robustRandom = default!;
[Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
[Dependency] private readonly DoAfterSystem _doAfterSystem = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
public override void Update(float frameTime)
{
base.Update(frameTime);
foreach (var (_, reclaimer) in EntityQuery<ActiveBiomassReclaimerComponent, BiomassReclaimerComponent>())
{
reclaimer.Accumulator += frameTime;
reclaimer.RandomMessAccumulator += frameTime;
if (reclaimer.RandomMessAccumulator >= reclaimer.RandomMessInterval.TotalSeconds)
{
if (_robustRandom.Prob(0.3f))
{
if (_robustRandom.Prob(0.7f))
{
Solution blood = new();
blood.AddReagent(reclaimer.BloodReagent, 50);
_spillableSystem.SpillAt(reclaimer.Owner, blood, "PuddleBlood");
}
if (_robustRandom.Prob(0.1f) && reclaimer.SpawnedEntities.Count > 0)
{
var thrown = Spawn(_robustRandom.Pick(reclaimer.SpawnedEntities).PrototypeId, Transform(reclaimer.Owner).Coordinates);
Vector2 direction = (_robustRandom.Next(-30, 30), _robustRandom.Next(-30, 30));
_throwing.TryThrow(thrown, direction, _robustRandom.Next(1, 10));
}
}
reclaimer.RandomMessAccumulator -= (float) reclaimer.RandomMessInterval.TotalSeconds;
}
if (reclaimer.Accumulator < reclaimer.CurrentProcessingTime)
{
continue;
}
reclaimer.Accumulator = 0;
_stackSystem.SpawnMultiple((int) reclaimer.CurrentExpectedYield, 100, "Biomass", Transform(reclaimer.Owner).Coordinates);
reclaimer.SpawnedEntities.Clear();
RemCompDeferred<ActiveBiomassReclaimerComponent>(reclaimer.Owner);
}
}
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<ActiveBiomassReclaimerComponent, ComponentInit>(OnInit);
SubscribeLocalEvent<ActiveBiomassReclaimerComponent, ComponentShutdown>(OnShutdown);
SubscribeLocalEvent<ActiveBiomassReclaimerComponent, UnanchorAttemptEvent>(OnUnanchorAttempt);
SubscribeLocalEvent<BiomassReclaimerComponent, AfterInteractUsingEvent>(OnAfterInteractUsing);
SubscribeLocalEvent<BiomassReclaimerComponent, ClimbedOnEvent>(OnClimbedOn);
SubscribeLocalEvent<ReclaimSuccessfulEvent>(OnReclaimSuccessful);
SubscribeLocalEvent<ReclaimCancelledEvent>(OnReclaimCancelled);
}
private void OnInit(EntityUid uid, ActiveBiomassReclaimerComponent component, ComponentInit args)
{
_jitteringSystem.AddJitter(uid, -10, 100);
_sharedAudioSystem.Play("/Audio/Machines/reclaimer_startup.ogg", Filter.Pvs(uid), uid);
_ambientSoundSystem.SetAmbience(uid, true);
}
private void OnShutdown(EntityUid uid, ActiveBiomassReclaimerComponent component, ComponentShutdown args)
{
RemComp<JitteringComponent>(uid);
_ambientSoundSystem.SetAmbience(uid, false);
}
private void OnUnanchorAttempt(EntityUid uid, ActiveBiomassReclaimerComponent component, UnanchorAttemptEvent args)
{
args.Cancel();
}
private void OnAfterInteractUsing(EntityUid uid, BiomassReclaimerComponent component, AfterInteractUsingEvent args)
{
if (!args.CanReach)
return;
if (component.CancelToken != null || args.Target == null)
return;
if (HasComp<MobStateComponent>(args.Used) && CanGib(uid, args.Used, component))
{
component.CancelToken = new CancellationTokenSource();
_doAfterSystem.DoAfter(new DoAfterEventArgs(args.User, 7f, component.CancelToken.Token, target: args.Target)
{
BroadcastFinishedEvent = new ReclaimSuccessfulEvent(args.User, args.Used, uid),
BroadcastCancelledEvent = new ReclaimCancelledEvent(uid),
BreakOnTargetMove = true,
BreakOnUserMove = true,
BreakOnStun = true,
NeedHand = true
});
}
}
private void OnClimbedOn(EntityUid uid, BiomassReclaimerComponent component, ClimbedOnEvent args)
{
if (!CanGib(uid, args.Climber, component))
{
Vector2 direction = (_robustRandom.Next(-2, 2), _robustRandom.Next(-2, 2));
_throwing.TryThrow(args.Climber, direction, 0.5f);
return;
}
_adminLogger.Add(LogType.Action, LogImpact.Extreme, $"{ToPrettyString(args.Instigator):player} used a biomass reclaimer to gib {ToPrettyString(args.Climber):target} in {ToPrettyString(uid):reclaimer}");
StartProcessing(args.Climber, component);
}
private void OnReclaimSuccessful(ReclaimSuccessfulEvent args)
{
if (!TryComp<BiomassReclaimerComponent>(args.Reclaimer, out var reclaimer))
return;
_adminLogger.Add(LogType.Action, LogImpact.Extreme, $"{ToPrettyString(args.User):player} used a biomass reclaimer to gib {ToPrettyString(args.Target):target} in {ToPrettyString(args.Reclaimer):reclaimer}");
reclaimer.CancelToken = null;
StartProcessing(args.Target, reclaimer);
}
private void OnReclaimCancelled(ReclaimCancelledEvent args)
{
if (!TryComp<BiomassReclaimerComponent>(args.Reclaimer, out var reclaimer))
return;
reclaimer.CancelToken = null;
}
private void StartProcessing(EntityUid toProcess, BiomassReclaimerComponent component)
{
AddComp<ActiveBiomassReclaimerComponent>(component.Owner);
if (TryComp<BloodstreamComponent>(toProcess, out var stream))
{
component.BloodReagent = stream.BloodReagent;
}
if (TryComp<SharedButcherableComponent>(toProcess, out var butcherableComponent))
{
component.SpawnedEntities = butcherableComponent.SpawnedEntities;
}
component.CurrentExpectedYield = CalculateYield(toProcess, component);
component.CurrentProcessingTime = component.CurrentExpectedYield / component.YieldPerUnitMass * component.ProcessingSpeedMultiplier;
EntityManager.QueueDeleteEntity(toProcess);
}
private float CalculateYield(EntityUid uid, BiomassReclaimerComponent component)
{
if (!TryComp<PhysicsComponent>(uid, out var physics))
{
Logger.Error("Somehow tried to extract biomass from " + uid + ", which has no physics component.");
return 0f;
}
return (physics.FixturesMass * component.YieldPerUnitMass);
}
private bool CanGib(EntityUid uid, EntityUid dragged, BiomassReclaimerComponent component)
{
if (HasComp<ActiveBiomassReclaimerComponent>(uid))
return false;
if (!HasComp<MobStateComponent>(dragged))
return false;
if (!Transform(uid).Anchored)
return false;
if (TryComp<ApcPowerReceiverComponent>(uid, out var power) && !power.Powered)
return false;
if (component.SafetyEnabled && !_mobState.IsDead(dragged))
return false;
// Reject souled bodies in easy mode.
if (_configManager.GetCVar(CCVars.BiomassEasyMode) && HasComp<HumanoidAppearanceComponent>(dragged) &&
TryComp<MindComponent>(dragged, out var mindComp))
{
if (mindComp.Mind?.UserId != null && _playerManager.TryGetSessionById(mindComp.Mind.UserId.Value, out var client))
return false;
}
return true;
}
private sealed class ReclaimCancelledEvent : EntityEventArgs
{
public EntityUid Reclaimer;
public ReclaimCancelledEvent(EntityUid reclaimer)
{
Reclaimer = reclaimer;
}
}
private sealed class ReclaimSuccessfulEvent : EntityEventArgs
{
public EntityUid User;
public EntityUid Target;
public EntityUid Reclaimer;
public ReclaimSuccessfulEvent(EntityUid user, EntityUid target, EntityUid reclaimer)
{
User = user;
Target = target;
Reclaimer = reclaimer;
}
}
}
}

View File

@@ -48,7 +48,7 @@ namespace Content.Server.Medical
private void OnComponentInit(EntityUid uid, MedicalScannerComponent scannerComponent, ComponentInit args)
{
base.Initialize();
scannerComponent.BodyContainer = _containerSystem.EnsureContainer<ContainerSlot>(uid, $"{scannerComponent.Name}-bodyContainer");
scannerComponent.BodyContainer = _containerSystem.EnsureContainer<ContainerSlot>(uid, $"scanner-bodyContainer");
_signalSystem.EnsureReceiverPorts(uid, MedicalScannerComponent.ScannerPort);
}

View File

@@ -1,11 +1,13 @@
using Content.Shared.Damage;
using Content.Server.Body.Components;
using Content.Server.MobState;
namespace Content.Server.Salvage;
public sealed class SalvageMobRestrictionsSystem : EntitySystem
{
[Dependency] private readonly DamageableSystem _damageableSystem = default!;
[Dependency] private readonly MobStateSystem _mobStateSystem = default!;
public override void Initialize()
{
base.Initialize();
@@ -49,6 +51,7 @@ public sealed class SalvageMobRestrictionsSystem : EntitySystem
foreach (var target in component.MobsToKill)
{
if (Deleted(target, metaQuery)) continue;
if (_mobStateSystem.IsDead(target)) continue; // DONT WASTE BIOMASS
if (bodyQuery.TryGetComponent(target, out var body))
{
// Just because.

View File

@@ -83,6 +83,44 @@ namespace Content.Server.Stack
return entity;
}
/// <summary>
/// Say you want to spawn 97 stacks of something that has a max stack count of 30.
/// This would spawn 3 stacks of 30 and 1 stack of 7.
/// </summary>
public void SpawnMultiple(int amount, int maxCountPerStack, StackPrototype prototype, EntityCoordinates spawnPosition)
{
while (amount > 0)
{
if (amount > maxCountPerStack)
{
var entity = Spawn("MaterialBiomass", spawnPosition);
var stack = Comp<StackComponent>(entity);
SetCount(entity, maxCountPerStack, stack);
amount -= maxCountPerStack;
}
else
{
var entity = Spawn("MaterialBiomass", spawnPosition);
var stack = Comp<StackComponent>(entity);
SetCount(entity, amount, stack);
amount = 0;
}
}
}
public void SpawnMultiple(int amount, int maxCountPerStack, string prototype, EntityCoordinates spawnPosition)
{
if (!_prototypeManager.TryIndex<StackPrototype>(prototype, out var stackType))
{
Logger.Error("Failed to index stack prototype " + prototype);
return;
}
SpawnMultiple(amount, maxCountPerStack, stackType, spawnPosition);
}
private void OnStackAlternativeInteract(EntityUid uid, StackComponent stack, GetVerbsEvent<AlternativeVerb> args)
{
if (!args.CanAccess || !args.CanInteract || args.Hands == null)