1313using Content . Shared . Labels . Components ;
1414using Content . Shared . Paper ;
1515using Content . Shared . Station . Components ;
16+ using Content . Shared . Tools ;
1617using JetBrains . Annotations ;
1718using Robust . Shared . Map ;
1819using Robust . Shared . Prototypes ;
1920using Robust . Shared . Timing ;
2021using Robust . Shared . Utility ;
2122
23+ #region Starlight
24+ using Content . Shared . _Starlight . Cargo . TamperSeal . Components ;
25+ using Content . Server . _Starlight . Cargo . TamperSeal . Components ;
26+ using Content . Shared . _Starlight . CCVar ;
27+ using Content . Shared . Access ;
28+ #endregion
29+
2230namespace Content . Server . Cargo . Systems
2331{
2432 public sealed partial class CargoSystem
@@ -27,6 +35,12 @@ public sealed partial class CargoSystem
2735 [ Dependency ] private EmagSystem _emag = default ! ;
2836 [ Dependency ] private IGameTiming _timing = default ! ;
2937
38+ #region Starlight
39+ private float _tamperSealRewardMultiplier = 0.1f ;
40+ private float _tamperSealPenaltyMultiplier = 0.1f ;
41+ private float _tamperSealRefundMultiplier = 0.5f ;
42+ #endregion
43+
3044 private void InitializeConsole ( )
3145 {
3246 SubscribeLocalEvent < CargoOrderConsoleComponent , CargoConsoleAddOrderMessage > ( OnAddOrderMessage ) ;
@@ -36,6 +50,12 @@ private void InitializeConsole()
3650 SubscribeLocalEvent < CargoOrderConsoleComponent , ComponentInit > ( OnInit ) ;
3751 SubscribeLocalEvent < CargoOrderConsoleComponent , InteractUsingEvent > ( OnInteractUsing ) ;
3852 SubscribeLocalEvent < CargoOrderConsoleComponent , GotEmaggedEvent > ( OnEmagged ) ;
53+
54+ // Starlight BEGIN
55+ _cfg . OnValueChanged ( StarlightCCVars . TamperSealRewardMultiplier , v => _tamperSealRewardMultiplier = v , true ) ;
56+ _cfg . OnValueChanged ( StarlightCCVars . TamperSealPenaltyMultiplier , v => _tamperSealPenaltyMultiplier = v , true ) ;
57+ _cfg . OnValueChanged ( StarlightCCVars . TamperSealRefundMultiplier , v => _tamperSealRefundMultiplier = v , true ) ;
58+ // Starlight END
3959 }
4060
4161 private void OnInteractUsingCash ( EntityUid uid , CargoOrderConsoleComponent component , ref InteractUsingEvent args )
@@ -76,7 +96,7 @@ private void OnInteractUsingSlip(Entity<CargoOrderConsoleComponent> ent, ref Int
7696 return ;
7797
7898 var orderId = GenerateOrderId ( orderDatabase ) ;
79- var data = new CargoOrderData ( orderId , product . Product , product . Name , product . Cost , slip . OrderQuantity , slip . Requester , slip . Reason , slip . Account ) ;
99+ var data = new CargoOrderData ( orderId , product . Product , product . Name , product . Cost , slip . OrderQuantity , slip . Requester , slip . Reason , slip . Account , GetNetEntity ( stationUid . Value ) ) ; // Starlight: +stationUid
80100
81101 if ( ! TryAddOrder ( stationUid . Value , ent . Comp . Account , data , orderDatabase ) )
82102 {
@@ -386,7 +406,7 @@ private void OnAddOrderMessage(EntityUid uid, CargoOrderConsoleComponent compone
386406
387407 var targetAccount = component . Mode == CargoOrderConsoleMode . SendToPrimary ? bank . PrimaryAccount : component . Account ;
388408
389- var data = GetOrderData ( args , product , GenerateOrderId ( orderDatabase ) , component . Account ) ;
409+ var data = new CargoOrderData ( GenerateOrderId ( orderDatabase ) , product . Product , product . Name , product . Cost , args . Amount , args . Requester , args . Reason , component . Account , GetNetEntity ( stationUid . Value ) ) ; // Starlight: +stationUid
390410
391411 if ( ! TryAddOrder ( stationUid . Value , targetAccount , data , orderDatabase ) )
392412 {
@@ -464,10 +484,15 @@ private void PlayDenySound(EntityUid uid, CargoOrderConsoleComponent component)
464484 }
465485 }
466486
487+ #region Starlight
488+ // This is an upstream method, but it is now unused due to our changes elsewhere in this file.
489+ /*
467490 private static CargoOrderData GetOrderData(CargoConsoleAddOrderMessage args, CargoProductPrototype cargoProduct, int id, ProtoId<CargoAccountPrototype> account)
468491 {
469492 return new CargoOrderData(id, cargoProduct.Product, cargoProduct.Name, cargoProduct.Cost, args.Amount, args.Requester, args.Reason, account);
470493 }
494+ */
495+ #endregion
471496
472497 public int GetOutstandingOrderCount ( Entity < StationCargoOrderDatabaseComponent > station , ProtoId < CargoAccountPrototype > account )
473498 {
@@ -534,7 +559,7 @@ Entity<StationDataComponent> stationData
534559 DebugTools . Assert ( _protoMan . HasIndex < EntityPrototype > ( spawnId ) ) ;
535560 // Make an order
536561 var id = GenerateOrderId ( component ) ;
537- var order = new CargoOrderData ( id , spawnId , name , cost , qty , sender , description , account ) ;
562+ var order = new CargoOrderData ( id , spawnId , name , cost , qty , sender , description , account , GetNetEntity ( stationData . Owner ) ) ; // Starlight: +stationUid
538563
539564 // Approve it now
540565 order . SetApproverData ( dest , sender ) ;
@@ -652,8 +677,37 @@ private bool FulfillOrder(CargoOrderData order, ProtoId<CargoAccountPrototype> a
652677 }
653678 }
654679
680+ // Starlight BEGIN
681+ // If the entity does not support tamper seals, do not apply one.
682+ if ( ! TryComp < TamperSealableComponent > ( item , out var tamperSealable ) )
683+ return true ;
684+
685+ var recipient = _protoMan . Index ( account ) ;
686+
687+ // Apply a tamper seal to the entity. This does the actual sealing logic.
688+ var seal = EnsureComp < TamperSealComponent > ( item ) ;
689+ seal . Recipient = account ;
690+ seal . RecipientName = recipient . TamperSealName ;
691+ seal . RecipientExamineColor = recipient . Color ;
692+ seal . Color = recipient . TamperSealColor ;
693+ seal . Accesses = new List < TamperSealAccessPattern > ( recipient . TamperSealAccesses ) ;
694+ seal . DestroyToolQualities = new HashSet < ProtoId < ToolQualityPrototype > > ( tamperSealable . DestroyToolQualities ) ;
695+
696+ // Attach a tamper seal value component to enable reward/penalty on unseal/destroy.
697+ var value = EnsureComp < TamperSealValueComponent > ( item ) ;
698+ value . StationId = GetEntity ( order . StationId ) ;
699+ value . Value = order . Price ;
700+ value . Reward = ( int ) Math . Floor ( _tamperSealRewardMultiplier * order . Price ) ; // Rewards rounded down.
701+ value . Penalty = ( int ) Math . Ceiling ( _tamperSealPenaltyMultiplier * order . Price ) ; // Penalties rounded up.
702+ value . Refund = ( int ) Math . Ceiling ( _tamperSealRefundMultiplier * order . Price ) ; // Refunds rounded up.
703+
704+ // Attach an integrity component. This is used by the integrity system to detect repeat tampering.
705+ var integrity = EnsureComp < TamperSealIntegrityBeaconComponent > ( item ) ;
706+ integrity . StationId = GetEntity ( order . StationId ) ;
707+
708+ DirtyEntity ( item ) ;
655709 return true ;
656-
710+ // Starlight END
657711 }
658712
659713 public List < ProtoId < CargoProductPrototype > > GetAvailableProducts ( Entity < CargoOrderConsoleComponent > ent )
0 commit comments