1
1
// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt
2
+ using System . Numerics ;
2
3
using Content . Server . Actions ;
3
4
using Content . Server . AlertLevel ;
4
5
using Content . Server . Chat . Systems ;
8
9
using Content . Server . Station . Systems ;
9
10
using Content . Shared . Alert ;
10
11
using Content . Shared . Damage ;
12
+ using Content . Shared . Inventory ;
11
13
using Content . Shared . Mobs . Systems ;
12
14
using Content . Shared . SS220 . DarkReaper ;
13
15
using Robust . Shared . Containers ;
16
+ using Robust . Shared . Physics . Systems ;
17
+ using Robust . Shared . Random ;
14
18
using Robust . Shared . Utility ;
15
19
16
20
namespace Content . Server . SS220 . DarkReaper ;
@@ -28,6 +32,10 @@ public sealed class DarkReaperSystem : SharedDarkReaperSystem
28
32
[ Dependency ] private readonly StationSystem _station = default ! ;
29
33
[ Dependency ] private readonly AlertLevelSystem _alertLevel = default ! ;
30
34
[ Dependency ] private readonly ChatSystem _chat = default ! ;
35
+ [ Dependency ] private readonly InventorySystem _inventory = default ! ;
36
+ [ Dependency ] private readonly SharedTransformSystem _transform = default ! ;
37
+ [ Dependency ] private readonly IRobustRandom _random = default ! ;
38
+ [ Dependency ] private readonly SharedPhysicsSystem _physics = default ! ;
31
39
32
40
private readonly ISawmill _sawmill = Logger . GetSawmill ( "DarkReaper" ) ;
33
41
@@ -69,18 +77,47 @@ protected override void OnAfterConsumed(EntityUid uid, DarkReaperComponent comp,
69
77
{
70
78
if ( comp . PhysicalForm && target . IsValid ( ) && ! EntityManager . IsQueuedForDeletion ( target ) && _mobState . IsDead ( target ) )
71
79
{
72
- if ( _container . TryGetContainer ( uid , DarkReaperComponent . ConsumedContainerId , out var container ) )
80
+ if ( ! _container . TryGetContainer ( uid , DarkReaperComponent . ConsumedContainerId , out var container ) )
81
+ return ;
82
+
83
+ if ( ! _container . CanInsert ( target , container ) )
84
+ return ;
85
+
86
+ // spawn gore
87
+ Spawn ( comp . EntityToSpawnAfterConsuming , Transform ( target ) . Coordinates ) ;
88
+
89
+ // randomly drop inventory items
90
+ if ( _inventory . TryGetContainerSlotEnumerator ( target , out var slots ) )
73
91
{
74
- _container . Insert ( target , container ) ;
92
+ while ( slots . MoveNext ( out var containerSlot ) )
93
+ {
94
+ if ( containerSlot . ContainedEntity is not { } containedEntity )
95
+ continue ;
96
+
97
+ if ( ! _random . Prob ( comp . InventoryDropProbabilityOnConsumed ) )
98
+ continue ;
99
+
100
+ if ( ! _container . TryRemoveFromContainer ( containedEntity ) )
101
+ continue ;
102
+
103
+ // set random rotation
104
+ _transform . SetLocalRotationNoLerp ( containedEntity , Angle . FromDegrees ( _random . NextDouble ( 0 , 360 ) ) ) ;
105
+
106
+ // apply random impulse
107
+ var maxAxisImp = comp . SpawnOnDeathImpulseStrength ;
108
+ var impulseVec = new Vector2 ( _random . NextFloat ( - maxAxisImp , maxAxisImp ) , _random . NextFloat ( - maxAxisImp , maxAxisImp ) ) ;
109
+ _physics . ApplyLinearImpulse ( containedEntity , impulseVec ) ;
110
+ }
75
111
}
76
112
113
+ _container . Insert ( target , container ) ;
77
114
_damageable . TryChangeDamage ( uid , comp . HealPerConsume , true , origin : args . Args . User ) ;
78
115
79
116
comp . Consumed ++ ;
80
-
81
117
var stageBefore = comp . CurrentStage ;
82
118
UpdateStage ( uid , comp ) ;
83
- // warn a crew
119
+
120
+ // warn a crew if alert stage is reached
84
121
if ( comp . CurrentStage > stageBefore && comp . CurrentStage == comp . AlertStage )
85
122
{
86
123
var reaperXform = Transform ( uid ) ;
@@ -93,6 +130,7 @@ protected override void OnAfterConsumed(EntityUid uid, DarkReaperComponent comp,
93
130
_chat . DispatchStationAnnouncement ( stationUid ?? uid , announcement , sender , false , Color . Red ) ;
94
131
}
95
132
133
+ // update consoom counter alert
96
134
UpdateAlert ( uid , comp ) ;
97
135
Dirty ( uid , comp ) ;
98
136
}
0 commit comments