11using System . Diagnostics . CodeAnalysis ;
2+ using System . Linq ;
23using System . Numerics ;
34using Content . Server . _NF . Shipyard . Systems ;
45using Content . Server . DoAfter ;
56using Content . Server . EUI ;
67using Content . Server . Ghost ;
8+ using Content . Server . Hands . Systems ;
79using Content . Server . Interaction ;
810using Content . Server . Mind ;
911using Content . Server . Popups ;
1719using Content . Shared . DoAfter ;
1820using Content . Shared . DragDrop ;
1921using Content . Shared . Examine ;
22+ using Content . Shared . FixedPoint ;
2023using Content . Shared . GameTicking ;
2124using Content . Shared . Hands . Components ;
2225using Content . Shared . Interaction . Events ;
@@ -61,6 +64,7 @@ public sealed partial class CryoSleepSystem : EntitySystem
6164 [ Dependency ] private readonly IGameTiming _timing = default ! ;
6265 [ Dependency ] private readonly IPlayerManager _player = default ! ;
6366 [ Dependency ] private readonly InventorySystem _inventory = default ! ; //For cryosleep warnings
67+ [ Dependency ] private readonly HandsSystem _hands = default ! ;
6468
6569 private readonly Dictionary < NetUserId , StoredBody ? > _storedBodies = new ( ) ;
6670 private EntityUid ? _storageMap ;
@@ -292,39 +296,54 @@ public bool IsBodyInCryoPod(EntityUid body, Entity<CryoSleepComponent?> cryopod)
292296 }
293297
294298 /// <summary>
295- /// Scans the inventory of an entity about to cryo in order to contrusct a warning message of all appropriate items.
299+ /// Scans the inventory of an entity about to cryo in order to construct a warning message of all appropriate items.
296300 /// </summary>
297301 /// <returns>A warning message to be used with CryoSleepEui</returns>
298302 private CryoSleepWarningMessage ? GetWarningMessages ( EntityUid entity )
299303 {
300304 if ( ! TryComp < InventoryComponent > ( entity , out var inventoryComp ) )
301305 return null ;
302306 //Items check
303- SlotDefinition [ ] slotsToCheck = inventoryComp . Slots ;
307+ var slotsToCheck = inventoryComp . Slots ;
304308 List < WarningItem > warningItemsList = [ ] ;
305309 //Doing the conversion to WarningItem all at once makes more sense to me
306- List < StorageHelper . FoundItem > unconvertedFoundItem = [ ] ;
310+ List < StorageHelper . FoundItem > unconvertedFoundItems = [ ] ;
307311 foreach ( var slotDefinition in slotsToCheck )
308312 {
309313 //The ID is manually checked for a shuttle deed later, and since your PDA *technically* has an uplink in it, this has to be skipped manually.
310314 if ( slotDefinition . Name == "id" )
311315 continue ;
312- //TODO: Check hand slots for important items
313316 if ( _inventory . TryGetSlotEntity ( entity , slotDefinition . Name , out var slotItem ) )
314317 {
315318 if ( ShouldItemWarnOnCryo ( slotItem . Value ) )
316- warningItemsList . Add ( new WarningItem ( slotDefinition . Name , null , slotItem . Value ) ) ;
319+ warningItemsList . Add ( new WarningItem ( slotDefinition . Name , null , null , slotItem . Value ) ) ;
317320 else if ( _entityManager . HasComponent < StorageComponent > ( slotItem . Value ) )
318- StorageHelper . ScanStorageForCondition ( slotItem . Value , ShouldItemWarnOnCryo , ref unconvertedFoundItem ) ;
321+ StorageHelper . ScanStorageForCondition ( slotItem . Value , ShouldItemWarnOnCryo , ref unconvertedFoundItems ) ;
319322 }
320323 }
324+ //Check hands (Thank you Alkheemist for the original form of this code)
325+ if ( TryComp < HandsComponent > ( entity , out var handsComp ) )
326+ {
327+ foreach ( var hand in handsComp . Hands )
328+ {
329+ if ( ! _hands . TryGetHeldItem ( entity , hand . Key , out var heldEntity ) )
330+ continue ;
331+
332+ if ( ShouldItemWarnOnCryo ( heldEntity . Value ) )
333+ warningItemsList . Add ( new WarningItem ( null , null , hand . Key , heldEntity . Value ) ) ;
334+ else if ( _entityManager . HasComponent < StorageComponent > ( heldEntity ) )
335+ StorageHelper . ScanStorageForCondition ( heldEntity . Value , ShouldItemWarnOnCryo , ref unconvertedFoundItems ) ;
336+ }
337+ }
338+
321339 //Convert all FoundItem to a WarningItem
322- foreach ( var found in unconvertedFoundItem )
340+ foreach ( var found in unconvertedFoundItems )
323341 {
324- warningItemsList . Add ( new WarningItem ( null , found . Container , found . Item ) ) ;
342+ warningItemsList . Add ( new WarningItem ( null , found . Container , null , found . Item ) ) ;
325343 }
326344 //Now, we extract the uplinks and shuttle deeds.
327345 WarningItem ? uplink = null ;
346+ FixedPoint2 currencyAmount = 0 ;
328347 WarningItem ? backpackShuttleDeed = null ;
329348 //Listing every point where a shuttle deed was found runs you out of space very fast.
330349 var foundMoreShuttles = false ;
@@ -344,10 +363,13 @@ public bool IsBodyInCryoPod(EntityUid body, Entity<CryoSleepComponent?> cryopod)
344363
345364 warningItemsList . RemoveAt ( i ) ;
346365 }
347- else if ( HasComp < StoreComponent > ( itemStruct . Item ) & & ! uplink . HasValue )
366+ else if ( TryComp < StoreComponent > ( itemStruct . Item , out var uplinkComp ) && ! uplink . HasValue )
348367 {
349368 uplink = itemStruct ;
350369 warningItemsList . RemoveAt ( i ) ;
370+ var currencyProtoId = uplinkComp . Balance . Keys . First ( ) ;
371+ currencyAmount = uplinkComp . Balance [ currencyProtoId ] ;
372+
351373 }
352374 }
353375
@@ -361,6 +383,7 @@ public bool IsBodyInCryoPod(EntityUid body, Entity<CryoSleepComponent?> cryopod)
361383 nwBackpackShuttleDeed ,
362384 foundMoreShuttles ,
363385 nwUplink ,
386+ currencyAmount ,
364387 networkedWarningItems ) ;
365388 }
366389
@@ -387,18 +410,20 @@ private bool TryGetIdCard(EntityUid ent, [NotNullWhen(true)] out EntityUid? idCa
387410 return false ;
388411 }
389412
390- private readonly struct WarningItem ( string ? slotId , EntityUid ? container , EntityUid item )
413+ private readonly struct WarningItem ( string ? slotId , EntityUid ? container , string ? handId , EntityUid item )
391414 {
392- //Exactly one of these two values should be null
415+ //Exactly one of these three values should not be null
393416 public readonly string ? SlotId = slotId ;
394417 public readonly EntityUid ? Container = container ;
418+ public readonly string ? HandId = handId ;
395419
396420 public readonly EntityUid Item = item ;
397421
398422 public CryoSleepWarningMessage . NetworkedWarningItem ToNetworked ( IEntityManager manager )
399423 {
400424 return new CryoSleepWarningMessage . NetworkedWarningItem ( SlotId ,
401425 manager . GetNetEntity ( Container ) ,
426+ HandId ,
402427 manager . GetNetEntity ( Item ) ) ;
403428 }
404429 }
0 commit comments