4
4
using Content . Shared . Interaction . Events ;
5
5
using Robust . Shared . Audio . Systems ;
6
6
using Content . Shared . SS220 . CultYogg . Corruption ;
7
- using Content . Shared . Inventory . Events ;
7
+ using Robust . Shared . Containers ;
8
+ using Robust . Shared . Timing ;
9
+ using JetBrains . FormatRipper . Elf ;
8
10
9
11
namespace Content . Server . SS220 . CultYogg . Corruption ;
10
12
11
13
public sealed class CultYoggCocoonSystem : EntitySystem
12
14
{
13
15
[ Dependency ] private readonly SharedHandsSystem _hands = default ! ;
14
16
[ Dependency ] private readonly SharedAudioSystem _audio = default ! ;
15
-
17
+ [ Dependency ] private readonly IGameTiming _timing = default ! ;
16
18
17
19
public override void Initialize ( )
18
20
{
19
21
base . Initialize ( ) ;
20
22
21
23
SubscribeLocalEvent < CultYoggCocoonComponent , UseInHandEvent > ( OnUseInHand ) ;
22
- SubscribeLocalEvent < CultYoggWeaponComponent , DroppedEvent > ( OnUnequip ) ;
24
+ SubscribeLocalEvent < CultYoggWeaponComponent , EntGotRemovedFromContainerMessage > ( OnRemove ) ;
23
25
}
24
26
private void OnUseInHand ( Entity < CultYoggCocoonComponent > ent , ref UseInHandEvent args )
25
27
{
@@ -35,6 +37,7 @@ private void OnUseInHand(Entity<CultYoggCocoonComponent> ent, ref UseInHandEvent
35
37
comp . SoftDeletedOriginalEntity = corruptComp . SoftDeletedOriginalEntity ;
36
38
comp . Recipe = corruptComp . Recipe ;
37
39
}
40
+
38
41
EntityManager . DeleteEntity ( ent ) ;
39
42
_hands . PickupOrDrop ( args . User , newEnt ) ;
40
43
if ( ent . Comp . Sound != null )
@@ -46,8 +49,34 @@ private void OnUseInHand(Entity<CultYoggCocoonComponent> ent, ref UseInHandEvent
46
49
47
50
args . Handled = true ;
48
51
}
49
- private void OnUnequip ( Entity < CultYoggWeaponComponent > ent , ref DroppedEvent args )
52
+ private void OnRemove ( Entity < CultYoggWeaponComponent > ent , ref EntGotRemovedFromContainerMessage args )
53
+ {
54
+ ent . Comp . BeforeCocooningTime = _timing . CurTime + ent . Comp . CocooningCooldown ;
55
+ }
56
+ public override void Update ( float frameTime )
50
57
{
51
- ;
58
+ base . Update ( frameTime ) ;
59
+
60
+ var query = EntityQueryEnumerator < CultYoggWeaponComponent > ( ) ;
61
+ while ( query . MoveNext ( out var ent , out var comp ) )
62
+ {
63
+ if ( comp . BeforeCocooningTime is null )
64
+ continue ;
65
+
66
+ if ( _timing . CurTime < comp . BeforeCocooningTime )
67
+ continue ;
68
+
69
+ if ( ! TryComp < CultYoggCorruptedComponent > ( ent , out var corruptComp ) )
70
+ return ;
71
+
72
+ var coords = Transform ( ent ) . Coordinates ;
73
+ var newEnt = Spawn ( comp . Item , coords ) ;
74
+
75
+ var corrComp = EnsureComp < CultYoggCorruptedComponent > ( newEnt ) ;
76
+ corrComp . SoftDeletedOriginalEntity = corruptComp . SoftDeletedOriginalEntity ;
77
+ corrComp . Recipe = corruptComp . Recipe ;
78
+
79
+ EntityManager . DeleteEntity ( ent ) ;
80
+ }
52
81
}
53
82
}
0 commit comments