From f5a3b81a1c0b79c42034cccdde1e321360866d74 Mon Sep 17 00:00:00 2001 From: FoxxoTrystan Date: Fri, 1 Nov 2024 17:23:45 +0100 Subject: [PATCH] Fixes --- Content.Server/Cocoon/CocoonerSystem.cs | 80 ++++++++++++++++++- Content.Shared/Cocoon/CocoonDoAfterEvent.cs | 5 ++ Resources/Locale/en-US/abilities/arachne.ftl | 3 + .../Entities/Structures/Webbing/webs.yml | 2 +- 4 files changed, 85 insertions(+), 5 deletions(-) diff --git a/Content.Server/Cocoon/CocoonerSystem.cs b/Content.Server/Cocoon/CocoonerSystem.cs index a53ebbb5f57..676eb9808b2 100644 --- a/Content.Server/Cocoon/CocoonerSystem.cs +++ b/Content.Server/Cocoon/CocoonerSystem.cs @@ -14,6 +14,11 @@ using Content.Server.Speech.Components; using Robust.Shared.Containers; using Content.Shared.Mobs.Components; +using Content.Shared.Destructible; +using Robust.Shared.Random; +using Content.Shared.Nutrition.Components; +using Content.Shared.Storage; +using Robust.Shared.Utility; namespace Content.Server.Cocoon { @@ -25,17 +30,26 @@ public sealed class CocooningSystem : EntitySystem [Dependency] private readonly BlindableSystem _blindableSystem = default!; [Dependency] private readonly DamageableSystem _damageableSystem = default!; [Dependency] private readonly ISharedAdminLogManager _adminLogger = default!; + [Dependency] private readonly SharedDestructibleSystem _destructibleSystem = default!; + [Dependency] private readonly IRobustRandom _robustRandom = default!; private const string BodySlot = "body_slot"; public override void Initialize() { base.Initialize(); - SubscribeLocalEvent>(AddCocoonVerb); + SubscribeLocalEvent>(AddVerbs); SubscribeLocalEvent(OnCocEntInserted); SubscribeLocalEvent(OnCocEntRemoved); SubscribeLocalEvent(OnDamageChanged); SubscribeLocalEvent(OnCocoonDoAfter); + SubscribeLocalEvent(OnUnCocoonDoAfter); + } + + private void AddVerbs(EntityUid uid, CocoonerComponent component, GetVerbsEvent args) + { + AddCocoonVerb(uid, component, args); + AddUnCocoonVerb(uid, component, args); } private void AddCocoonVerb(EntityUid uid, CocoonerComponent component, GetVerbsEvent args) @@ -50,6 +64,25 @@ private void AddCocoonVerb(EntityUid uid, CocoonerComponent component, GetVerbsE StartCocooning(uid, component, args.Target); }, Text = Loc.GetString("cocoon"), + Icon = new SpriteSpecifier.Texture(new ResPath("/Textures/Interface/Actions/web.png")), + Priority = 2 + }; + args.Verbs.Add(verb); + } + + private void AddUnCocoonVerb(EntityUid uid, CocoonerComponent component, GetVerbsEvent args) + { + if (!args.CanAccess || !args.CanInteract || !HasComp(args.Target)) + return; + + InnateVerb verb = new() + { + Act = () => + { + StartUnCocooning(uid, component, args.Target); + }, + Text = Loc.GetString("uncocoon"), + Icon = new SpriteSpecifier.Texture(new ResPath("/Textures/Interface/Actions/web.png")), Priority = 2 }; args.Verbs.Add(verb); @@ -71,9 +104,11 @@ private void OnCocEntInserted(EntityUid uid, CocoonComponent component, EntInser private void OnCocEntRemoved(EntityUid uid, CocoonComponent component, EntRemovedFromContainerMessage args) { if (TryComp(args.Entity, out var replacement)) - replacement.Accent = component.OldAccent ?? replacement.Accent; - else - RemComp(args.Entity); + if (component.OldAccent is not null) + replacement.Accent = component.OldAccent; + else + RemComp(args.Entity, replacement); + RemComp(args.Entity); _blindableSystem.UpdateIsBlind(args.Entity); @@ -107,6 +142,22 @@ private void StartCocooning(EntityUid uid, CocoonerComponent component, EntityUi _doAfter.TryStartDoAfter(args); } + private void StartUnCocooning(EntityUid uid, CocoonerComponent component, EntityUid target) + { + _popupSystem.PopupEntity(Loc.GetString("uncocoon-start-third-person", ("target", target), ("spider", Identity.Entity(uid, EntityManager))), uid, + Shared.Popups.PopupType.MediumCaution); + + var delay = component.CocoonDelay / 2; + + var args = new DoAfterArgs(EntityManager, uid, delay, new UnCocoonDoAfterEvent(), uid, target: target) + { + BreakOnUserMove = true, + BreakOnTargetMove = true, + }; + + _doAfter.TryStartDoAfter(args); + } + private void OnCocoonDoAfter(EntityUid uid, CocoonerComponent component, CocoonDoAfterEvent args) { if (args.Handled || args.Cancelled || args.Args.Target == null) @@ -128,5 +179,26 @@ private void OnCocoonDoAfter(EntityUid uid, CocoonerComponent component, CocoonD _adminLogger.Add(LogType.Action, impact, $"{ToPrettyString(args.Args.User):player} cocooned {ToPrettyString(args.Args.Target.Value):target}"); args.Handled = true; } + + private void OnUnCocoonDoAfter(EntityUid uid, CocoonerComponent component, UnCocoonDoAfterEvent args) + { + if (args.Handled || args.Cancelled || args.Args.Target == null) + return; + + if (TryComp(args.Args.Target.Value, out var butcher)) + { + var spawnEntities = EntitySpawnCollection.GetSpawns(butcher.SpawnedEntities, _robustRandom); + var coords = Transform(args.Args.Target.Value).MapPosition; + EntityUid popupEnt = default!; + foreach (var proto in spawnEntities) + popupEnt = Spawn(proto, coords.Offset(_robustRandom.NextVector2(0.25f))); + } + + _destructibleSystem.DestroyEntity(args.Args.Target.Value); + + _adminLogger.Add(LogType.Action, LogImpact.Low + , $"{ToPrettyString(args.Args.User):player} uncocooned {ToPrettyString(args.Args.Target.Value):target}"); + args.Handled = true; + } } } diff --git a/Content.Shared/Cocoon/CocoonDoAfterEvent.cs b/Content.Shared/Cocoon/CocoonDoAfterEvent.cs index 55986d28945..0b9049e9890 100644 --- a/Content.Shared/Cocoon/CocoonDoAfterEvent.cs +++ b/Content.Shared/Cocoon/CocoonDoAfterEvent.cs @@ -7,4 +7,9 @@ namespace Content.Shared.Cocoon public sealed partial class CocoonDoAfterEvent : SimpleDoAfterEvent { } + + [Serializable, NetSerializable] + public sealed partial class UnCocoonDoAfterEvent : SimpleDoAfterEvent + { + } } diff --git a/Resources/Locale/en-US/abilities/arachne.ftl b/Resources/Locale/en-US/abilities/arachne.ftl index 6f6348d7212..857d104e5f9 100644 --- a/Resources/Locale/en-US/abilities/arachne.ftl +++ b/Resources/Locale/en-US/abilities/arachne.ftl @@ -8,6 +8,9 @@ spin-web-start-second-person = You start spinning a web. spin-web-start-third-person = {CAPITALIZE(THE($spider))} starts spinning a web! cocoon-start-second-person = You start cocooning {THE($target)}. cocoon-start-third-person = {CAPITALIZE(THE($spider))} starts cocooning {THE($target)}. +uncocoon-start-second-person = You start releasing {THE($target)}. +uncocoon-start-third-person = {CAPITALIZE(THE($spider))} starts releasing {THE($target)}. spun-web-second-person = You spin up a web. spun-web-third-person = {CAPITALIZE(THE($spider))} spins up a web! cocoon = Cocoon +uncocoon = Uncocoon diff --git a/Resources/Prototypes/Nyanotrasen/Entities/Structures/Webbing/webs.yml b/Resources/Prototypes/Nyanotrasen/Entities/Structures/Webbing/webs.yml index e483ea5da71..c3e020090fd 100644 --- a/Resources/Prototypes/Nyanotrasen/Entities/Structures/Webbing/webs.yml +++ b/Resources/Prototypes/Nyanotrasen/Entities/Structures/Webbing/webs.yml @@ -60,7 +60,7 @@ butcheringType: Knife butcherDelay: 12 spawned: - - id: MaterialCloth1 + - id: MaterialWebSilk1 amount: 1 prob: 0.5 #This doesn't cost hunger so should at least make it not worth it time-wise - type: Appearance