Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
FoxxoTrystan committed Nov 1, 2024
1 parent c0efed8 commit f5a3b81
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 5 deletions.
80 changes: 76 additions & 4 deletions Content.Server/Cocoon/CocoonerSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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<CocoonerComponent, GetVerbsEvent<InnateVerb>>(AddCocoonVerb);
SubscribeLocalEvent<CocoonerComponent, GetVerbsEvent<InnateVerb>>(AddVerbs);
SubscribeLocalEvent<CocoonComponent, EntInsertedIntoContainerMessage>(OnCocEntInserted);
SubscribeLocalEvent<CocoonComponent, EntRemovedFromContainerMessage>(OnCocEntRemoved);
SubscribeLocalEvent<CocoonComponent, DamageChangedEvent>(OnDamageChanged);
SubscribeLocalEvent<CocoonerComponent, CocoonDoAfterEvent>(OnCocoonDoAfter);
SubscribeLocalEvent<CocoonerComponent, UnCocoonDoAfterEvent>(OnUnCocoonDoAfter);
}

private void AddVerbs(EntityUid uid, CocoonerComponent component, GetVerbsEvent<InnateVerb> args)
{
AddCocoonVerb(uid, component, args);
AddUnCocoonVerb(uid, component, args);
}

private void AddCocoonVerb(EntityUid uid, CocoonerComponent component, GetVerbsEvent<InnateVerb> args)
Expand All @@ -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<InnateVerb> args)
{
if (!args.CanAccess || !args.CanInteract || !HasComp<CocoonComponent>(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);
Expand All @@ -71,9 +104,11 @@ private void OnCocEntInserted(EntityUid uid, CocoonComponent component, EntInser
private void OnCocEntRemoved(EntityUid uid, CocoonComponent component, EntRemovedFromContainerMessage args)
{
if (TryComp<ReplacementAccentComponent>(args.Entity, out var replacement))
replacement.Accent = component.OldAccent ?? replacement.Accent;
else
RemComp<ReplacementAccentComponent>(args.Entity);
if (component.OldAccent is not null)
replacement.Accent = component.OldAccent;
else
RemComp(args.Entity, replacement);


RemComp<StunnedComponent>(args.Entity);
_blindableSystem.UpdateIsBlind(args.Entity);
Expand Down Expand Up @@ -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)
Expand All @@ -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<ButcherableComponent>(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;
}
}
}
5 changes: 5 additions & 0 deletions Content.Shared/Cocoon/CocoonDoAfterEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,9 @@ namespace Content.Shared.Cocoon
public sealed partial class CocoonDoAfterEvent : SimpleDoAfterEvent
{
}

[Serializable, NetSerializable]
public sealed partial class UnCocoonDoAfterEvent : SimpleDoAfterEvent
{
}
}
3 changes: 3 additions & 0 deletions Resources/Locale/en-US/abilities/arachne.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f5a3b81

Please sign in to comment.