И твой сорванный голос мне напомнит о прошлом

This commit is contained in:
Remuchi
2024-03-27 21:23:18 +07:00
parent 3c9c149b81
commit 96238b0fb8
29 changed files with 687 additions and 660 deletions

View File

@@ -14,20 +14,16 @@ using Content.Shared.Chat;
using Content.Shared.Chemistry;
using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.Damage;
using Content.Shared.DoAfter;
using Content.Shared.FixedPoint;
using Content.Shared.Humanoid;
using Content.Shared.Mind;
using Content.Shared.Mobs;
using Content.Shared.Mobs.Components;
using Content.Shared.Movement.Systems;
using Content.Shared.Popups;
using Content.Shared.Silicons.Borgs.Components;
using Robust.Server.Containers;
using Robust.Shared.Containers;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Systems;
using Robust.Shared.Player;
using Robust.Shared.Timing;
@@ -36,31 +32,24 @@ namespace Content.Server.Borer;
public sealed class ServerBorerSystem : EntitySystem
{
[Dependency] private readonly SharedActionsSystem _action = default!;
[Dependency] private readonly BloodstreamSystem _bloodstreamSystem = default!;
[Dependency] private readonly IChatManager _chatManager = default!;
[Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!;
[Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly SharedMindSystem _mindSystem = default!;
[Dependency] private readonly PopupSystem _popup = default!;
[Dependency] private readonly QuickDialogSystem _quickDialog = default!;
[Dependency] private readonly ReactiveSystem _reactiveSystem = default!;
[Dependency] private readonly SolutionContainerSystem _solutionContainerSystem = default!;
[Dependency] private readonly StunSystem _stuns = default!;
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly VomitSystem _vomitSystem = default!;
[Dependency] private readonly ContainerSystem _container = default!;
[Dependency] private readonly SharedBorerSystem _sharedBorerSystem = default!;
[Dependency] private readonly MetaDataSystem _metaData = default!;
[Dependency] private readonly DamageableSystem _damageableSystem = default!;
[Dependency] private readonly GodmodeSystem _godmodeSystem = default!;
private const string SugarPrototype = "Sugar";
public override void Initialize()
{
@@ -85,15 +74,18 @@ public sealed class ServerBorerSystem : EntitySystem
SubscribeLocalEvent<BorerHostComponent, BorerReproduceEvent>(OnReproduce);
SubscribeLocalEvent<BorerHostComponent, BorerReproduceAfterEvent>(OnReproduceAfter);
SubscribeLocalEvent<InfestedBorerComponent, BorerBrainResistAfterEvent>(OnResistAfterControl);
}
private void OnReproduceAfter(EntityUid uid, BorerHostComponent component, BorerReproduceAfterEvent args)
{
if (args.Cancelled || !TryComp(component.BorerContainer.ContainedEntities[0], out InfestedBorerComponent? borerComp)
|| !WithrawPoints(component.BorerContainer.ContainedEntities[0], borerComp.ReproduceCost)
|| !TryComp(uid, out TransformComponent? targetTransform))
if (args.Cancelled
|| !TryComp(component.BorerContainer.ContainedEntities[0], out InfestedBorerComponent? borerComp)
|| !WithrawPoints(component.BorerContainer.ContainedEntities[0], borerComp.ReproduceCost)
|| !TryComp(uid, out TransformComponent? targetTransform))
{
return;
}
args.Handled = true;
_vomitSystem.Vomit(uid, -30, -30);
_entityManager.SpawnEntity("MobSimpleBorer", targetTransform.Coordinates);
@@ -103,32 +95,31 @@ public sealed class ServerBorerSystem : EntitySystem
{
if (!TryComp(component.BorerContainer.ContainedEntities[0], out InfestedBorerComponent? borerComp))
return;
if (GetPoints(component.BorerContainer.ContainedEntities[0]) < borerComp.ReproduceCost)
{
_popup.PopupEntity(Loc.GetString("borer-popup-lowchem"),
uid,
uid, PopupType.LargeCaution);
_popup.PopupEntity(Loc.GetString("borer-popup-lowchem"), uid, uid, PopupType.LargeCaution);
return;
}
args.Handled = true;
_doAfterSystem.TryStartDoAfter(new DoAfterArgs(EntityManager,
uid,
TimeSpan.FromSeconds(3),
new BorerReproduceAfterEvent(), uid)
{
Hidden = true
});
_doAfterSystem.TryStartDoAfter(
new DoAfterArgs(EntityManager, uid, TimeSpan.FromSeconds(3), new BorerReproduceAfterEvent(), uid)
{
Hidden = true
});
}
public void ReleaseControl(EntityUid borerUid)
{
if (!TryComp(borerUid, out ActionsComponent? wormActComp) ||
!TryComp(borerUid, out InfestedBorerComponent? borComp) ||
!borComp.Host.HasValue ||
!borComp.ControllingBrain)
if (!TryComp(borerUid, out ActionsComponent? wormActComp)
|| !TryComp(borerUid, out InfestedBorerComponent? borComp)
|| !borComp.Host.HasValue
|| !borComp.ControllingBrain)
{
return;
}
TryComp(borComp.Host.Value, out ActionsComponent? bodyActComp);
var wormHasMind = _mindSystem.TryGetMind(borerUid, out var hostMindId, out var hostMind);
@@ -138,10 +129,10 @@ public sealed class ServerBorerSystem : EntitySystem
if (wormHasMind)
_mindSystem.TransferTo(hostMindId, borComp.Host.Value, mind: hostMind);
if (bodyHasMind)
_mindSystem.TransferTo(mindId, borerUid, mind: mind);
_sharedBorerSystem.AddInfestedAbilities(borerUid, borComp);
_action.RemoveAction(borerUid, borComp.ActionBorerBrainResistEntity, wormActComp);
@@ -164,6 +155,7 @@ public sealed class ServerBorerSystem : EntitySystem
{
if (args.Cancelled)
return;
ReleaseControl(uid);
}
@@ -171,69 +163,69 @@ public sealed class ServerBorerSystem : EntitySystem
{
if (GetPoints(uid) < component.AssumeControlCost)
{
_popup.PopupEntity(Loc.GetString("borer-popup-lowchem"),
uid,
uid, PopupType.LargeCaution);
_popup.PopupEntity(Loc.GetString("borer-popup-lowchem"), uid, uid, PopupType.LargeCaution);
return;
}
if (GetSugarQuantityInHost(uid) > 0)
{
_popup.PopupEntity(Loc.GetString("borer-popup-toomuchsugar"), uid,
uid, PopupType.LargeCaution);
_popup.PopupEntity(Loc.GetString("borer-popup-toomuchsugar"), uid, uid, PopupType.LargeCaution);
}
if (TryComp(component.Host, out MobStateComponent? state) &&
state.CurrentState == MobState.Critical)
if (TryComp(component.Host, out MobStateComponent? state) && state.CurrentState == MobState.Critical)
{
_popup.PopupEntity(Loc.GetString("borer-popup-braintake-critical"), uid,
uid, PopupType.LargeCaution);
_popup.PopupEntity(Loc.GetString("borer-popup-braintake-critical"), uid, uid, PopupType.LargeCaution);
return;
}
args.Handled = true;
_doAfterSystem.TryStartDoAfter(new DoAfterArgs(EntityManager,
uid,
TimeSpan.FromSeconds(30),
new BorerBrainTakeAfterEvent(), uid)
{
Hidden = true
});
_doAfterSystem.TryStartDoAfter(
new DoAfterArgs(EntityManager, uid, TimeSpan.FromSeconds(30), new BorerBrainTakeAfterEvent(), uid)
{
Hidden = true
});
}
private void OnTakeControlAfter(EntityUid uid, InfestedBorerComponent component, BorerBrainTakeAfterEvent args)
{
if (!TryComp(uid, out ActionsComponent? comp) ||
!TryComp(component.Host, out ActionsComponent? hostComp))
if (args.Cancelled)
{
return;
}
else if (TryComp(component.Host, out MobStateComponent? state) &&
state.CurrentState == MobState.Critical)
if (!TryComp(uid, out ActionsComponent? comp) || !TryComp(component.Host, out ActionsComponent? hostComp))
{
_popup.PopupEntity(Loc.GetString("borer-popup-braintake-critical"), uid,
uid, PopupType.LargeCaution);
return;
}
else if (GetSugarQuantityInHost(uid) > 0)
if (TryComp(component.Host, out MobStateComponent? state) && state.CurrentState == MobState.Critical)
{
_popup.PopupEntity(Loc.GetString("borer-popup-toomuchsugar"), uid,
uid, PopupType.LargeCaution);
}
else if (args.Cancelled || !WithrawPoints(uid, component.AssumeControlCost))
_popup.PopupEntity(Loc.GetString("borer-popup-braintake-critical"), uid, uid, PopupType.LargeCaution);
return;
}
if (GetSugarQuantityInHost(uid) > 0)
{
_popup.PopupEntity(Loc.GetString("borer-popup-toomuchsugar"), uid, uid, PopupType.LargeCaution);
return;
}
if (!WithrawPoints(uid, component.AssumeControlCost))
{
return;
}
var borHasMind = _mindSystem.TryGetMind(uid, out var mindId, out var mind);
var hostHasMind = _mindSystem.TryGetMind(component.Host.Value, out var hostMindId, out var hostMind);
if (!borHasMind && !hostHasMind)
return;
if (borHasMind)
{
_mindSystem.TransferTo(mindId, component.Host, mind: mind);
_popup.PopupEntity(Loc.GetString("borer-popup-braintake-success"), component.Host.Value,
component.Host.Value, PopupType.Large);
}
if (hostHasMind)
@@ -260,12 +252,15 @@ public sealed class ServerBorerSystem : EntitySystem
_action.AddAction(component.Host.Value, ref component.ActionBorerBrainReleaseEntity,
component.ActionBorerBrainRelease, component: hostComp);
_action.AddAction(component.Host.Value, ref component.ActionBorerReproduceEntity,
component.ActionBorerReproduce, component: hostComp);
if(component.ActionBorerReproduceEntity.HasValue)
if (component.ActionBorerReproduceEntity.HasValue)
{
_metaData.SetEntityName(component.ActionBorerReproduceEntity.Value,
$"{Loc.GetString("borer-abilities-reproduce-name")} ([color=red]{component.ReproduceCost}c[/color])");
}
component.ControllingBrain = true;
Dirty(uid, component);
@@ -287,9 +282,10 @@ public sealed class ServerBorerSystem : EntitySystem
return;
}
if (TryComp(args.Target, out MobStateComponent? state) &&
state.CurrentState == MobState.Dead)
if (TryComp(args.Target, out MobStateComponent? state) && state.CurrentState == MobState.Dead)
{
return;
}
if (HasComp<BorerHostComponent>(args.Target))
{
@@ -305,7 +301,7 @@ public sealed class ServerBorerSystem : EntitySystem
return;
}
StartInfest(uid, args.Target, component);
StartInfest(uid, args.Target);
args.Handled = true;
}
@@ -316,9 +312,11 @@ public sealed class ServerBorerSystem : EntitySystem
if (!HasComp<HumanoidAppearanceComponent>(args.Target))
return;
if (TryComp(args.Target, out MobStateComponent? state) &&
state.CurrentState == MobState.Dead)
if (TryComp(args.Target, out MobStateComponent? state) && state.CurrentState == MobState.Dead)
{
return;
}
if (HasComp<BorerHostComponent>(args.Target))
{
@@ -348,29 +346,26 @@ public sealed class ServerBorerSystem : EntitySystem
RemComp<BorerComponent>(uid);
}
private void StartInfest(EntityUid user, EntityUid target, BorerComponent comp)
private void StartInfest(EntityUid user, EntityUid target)
{
_doAfterSystem.TryStartDoAfter(new DoAfterArgs(EntityManager,
user,
TimeSpan.FromSeconds(5),
new BorerInfestDoAfterEvent(), user, target)
{
BreakOnTargetMove = true,
BreakOnUserMove = true,
Hidden = true
});
_doAfterSystem.TryStartDoAfter(
new DoAfterArgs(EntityManager, user, TimeSpan.FromSeconds(5), new BorerInfestDoAfterEvent(), user, target)
{
BreakOnMove = true,
Hidden = true
});
}
private void OnBorerScan(EntityUid uid, InfestedBorerComponent component, BorerScanInstantActionEvent args)
{
if (!component.Host.HasValue)
return;
Dictionary<string, FixedPoint2> solution = new();
if (EntityManager.TryGetComponent(component.Host.Value,
out BloodstreamComponent? bloodContainer))
if (EntityManager.TryGetComponent(component.Host.Value, out BloodstreamComponent? bloodContainer))
{
if(_solutionContainerSystem.TryGetSolution(component.Host.Value, bloodContainer.ChemicalSolutionName,
out var sol))
if (_solutionContainerSystem.TryGetSolution(component.Host.Value, bloodContainer.ChemicalSolutionName,
out var sol))
{
foreach (var reagent in sol.Value.Comp.Solution)
{
@@ -414,7 +409,7 @@ public sealed class ServerBorerSystem : EntitySystem
private void OnTelepathicSpeech(EntityUid uid, InfestedBorerComponent component, BorerBrainSpeechActionEvent args)
{
if (!EntityManager.TryGetComponent(uid, out ActorComponent? actor))
if (!TryComp(uid, out ActorComponent? actor))
return;
_quickDialog.OpenDialog(actor.PlayerSession, Loc.GetString("borer-ui-converse-title"),
@@ -422,40 +417,40 @@ public sealed class ServerBorerSystem : EntitySystem
{
_popup.PopupEntity(message, uid, uid, PopupType.Medium);
if (EntityManager.TryGetComponent(component.Host, out ActorComponent? hostActor))
if (EntityManager.TryGetComponent(component.Host, out ActorComponent? _))
{
_popup.PopupEntity(message, component.Host.Value, component.Host.Value,
PopupType.Medium);
}
});
args.Handled = true;
}
private void OnInjectChemicals(BorerInjectActionEvent injectEvent, EntitySessionEventArgs eventArgs)
{
var borerEn = eventArgs.SenderSession.AttachedEntity;
if (EntityManager.TryGetComponent(borerEn,
out InfestedBorerComponent? infestedComponent) &&
infestedComponent.Host.HasValue)
if (!TryComp(borerEn, out InfestedBorerComponent? infestedComponent) || !infestedComponent.Host.HasValue)
{
if (!WithrawPoints(borerEn.Value, injectEvent.Cost))
return;
var solution = new Solution();
solution.AddReagent(injectEvent.ProtoId, 10);
_bloodstreamSystem.TryAddToChemicals(infestedComponent.Host.Value, solution);
_reactiveSystem.DoEntityReaction(infestedComponent.Host.Value, solution, ReactionMethod.Injection);
_popup.PopupEntity(Loc.GetString("borer-popup-injected", ("reagent", Loc.GetString("reagent-name-"+
injectEvent.ProtoId.ToLower().Replace("spacedrugs", "space-drugs")))),
borerEn.Value, borerEn.Value, PopupType.Medium);
return;
}
if (!WithrawPoints(borerEn.Value, injectEvent.Cost))
return;
var solution = new Solution();
solution.AddReagent(injectEvent.ProtoId, 10);
_bloodstreamSystem.TryAddToChemicals(infestedComponent.Host.Value, solution);
_reactiveSystem.DoEntityReaction(infestedComponent.Host.Value, solution, ReactionMethod.Injection);
_popup.PopupEntity(Loc.GetString("borer-popup-injected", ("reagent", Loc.GetString("reagent-name-" +
injectEvent.ProtoId.ToLower().Replace("spacedrugs", "space-drugs")))),
borerEn.Value, borerEn.Value, PopupType.Medium);
}
public bool AddPoints(EntityUid borerUid, int value)
{
if (!EntityManager.TryGetComponent(borerUid,
out InfestedBorerComponent? infestedComponent))
if (!TryComp(borerUid, out InfestedBorerComponent? infestedComponent))
return false;
infestedComponent.Points += value;
@@ -466,21 +461,16 @@ public sealed class ServerBorerSystem : EntitySystem
public int GetPoints(EntityUid borerUid)
{
if (!EntityManager.TryGetComponent(borerUid,
out InfestedBorerComponent? infestedComponent))
return 0;
return infestedComponent.Points;
return TryComp(borerUid, out InfestedBorerComponent? infestedComponent)
? infestedComponent.Points
: 0;
}
public bool WithrawPoints(EntityUid borerUid, int value)
{
if (!EntityManager.TryGetComponent(borerUid,
out InfestedBorerComponent? infestedComponent) || infestedComponent.Points < value)
if (!TryComp(borerUid, out InfestedBorerComponent? infestedComponent) || infestedComponent.Points < value)
{
_popup.PopupEntity(Loc.GetString("borer-popup-lowchem"),
borerUid,
borerUid, PopupType.LargeCaution);
_popup.PopupEntity(Loc.GetString("borer-popup-lowchem"), borerUid, borerUid, PopupType.LargeCaution);
return false;
}
@@ -499,7 +489,10 @@ public sealed class ServerBorerSystem : EntitySystem
{
if (!TryComp(uid, out InfestedBorerComponent? component) ||
!TryComp(component.Host, out BorerHostComponent? hostComponent))
{
return;
}
ReleaseControl(uid);
_vomitSystem.Vomit(component.Host.Value, -20, -20);
@@ -513,16 +506,17 @@ public sealed class ServerBorerSystem : EntitySystem
_godmodeSystem.DisableGodmode(uid);
RemComp<InfestedBorerComponent>(uid);
_action.SetCooldown(borerComponent.ActionStunEntity, _timing.CurTime, _timing.CurTime+TimeSpan.FromSeconds(20));
_action.SetCooldown(borerComponent.ActionInfestEntity, _timing.CurTime, _timing.CurTime+TimeSpan.FromSeconds(20));
_action.SetCooldown(borerComponent.ActionStunEntity, _timing.CurTime,
_timing.CurTime + TimeSpan.FromSeconds(20));
_action.SetCooldown(borerComponent.ActionInfestEntity, _timing.CurTime,
_timing.CurTime + TimeSpan.FromSeconds(20));
}
public int GetSugarQuantityInHost(EntityUid borerUid)
{
var sugarQuantity = 0;
if (EntityManager.TryGetComponent(borerUid,
out InfestedBorerComponent? component) &&
component.Host.HasValue)
if (TryComp(borerUid, out InfestedBorerComponent? component) && component.Host.HasValue)
{
sugarQuantity = GetSugarQuantityInEntity(component.Host.Value);
}
@@ -532,21 +526,20 @@ public sealed class ServerBorerSystem : EntitySystem
public int GetSugarQuantityInEntity(EntityUid uid)
{
if (EntityManager.TryGetComponent(uid,
out BloodstreamComponent? bloodContainer))
if (!TryComp(uid, out BloodstreamComponent? bloodContainer))
return 0;
if (!_solutionContainerSystem.TryGetSolution(uid, bloodContainer.ChemicalSolutionName, out var sol))
return 0;
foreach (var reagent in sol.Value.Comp.Solution)
{
if(_solutionContainerSystem.TryGetSolution(uid, bloodContainer.ChemicalSolutionName,
out var sol))
if (reagent.Reagent.ToString() == SugarPrototype)
{
foreach (var reagent in sol.Value.Comp.Solution)
{
if (reagent.Reagent.ToString() == "Sugar")
{
return reagent.Quantity.Int();
}
}
return reagent.Quantity.Int();
}
}
return 0;
}
}
}