1- using BPEssentials . ExtensionMethods ;
2- using BrokeProtocol . API ;
1+ using BrokeProtocol . API ;
32using BrokeProtocol . Entities ;
4- using BrokeProtocol . Required ;
53using BrokeProtocol . Utility ;
6- using BrokeProtocol . Utility . AI ;
7- using System ;
84using System . Linq ;
5+ using System . Collections . Generic ;
96using UnityEngine ;
107
118namespace BPEssentials . RegisteredEvents
@@ -15,20 +12,23 @@ public class OnDropDead : IScript
1512 private readonly int [ ] LicenseIDs = new [ ] { - 700261193 , 607710552 , 499504400 , 1695812550 , - 568534809 } ;
1613
1714 [ Target ( GameSourceEvent . PlayerRemoveItemsDeath , ExecutionMode . Override ) ]
18- protected void OnRemoveItemsDeath ( ShPlayer player )
15+ protected void OnRemoveItemsDeath ( ShPlayer player , bool dropItems )
1916 {
2017 // -- BPE EXTEND
21- if ( BPEssentials . Core . Instance . Settings . KeptItemsOnDeath . KeepAllItemsOnDeath ) { return ; }
18+ if ( Core . Instance . Settings . KeptItemsOnDeath . KeepAllItemsOnDeath ) { return ; }
2219 // BPE EXTEND --
2320
21+ // List for removed items for dropping into briefcase
22+ List < InventoryItem > removedItems = new List < InventoryItem > ( ) ;
23+
2424 // Allows players to keep items/rewards from job ranks
2525 foreach ( InventoryItem myItem in player . myItems . Values . ToArray ( ) )
2626 {
2727 // -- BPE EXTEND
28- if ( BPEssentials . Core . Instance . Settings . KeptItemsOnDeath . KeptItemIds . Contains ( myItem . item . index ) ) { continue ; }
29- if ( BPEssentials . Core . Instance . Settings . KeptItemsOnDeath . KeptItemNames . Contains ( myItem . item . itemName ) ) { continue ; }
30- if ( BPEssentials . Core . Instance . Settings . KeptItemsOnDeath . KeepAllPhones && myItem . item is ShPhone ) { continue ; }
31- if ( BPEssentials . Core . Instance . Settings . KeptItemsOnDeath . KeepAllLicenses && LicenseIDs . Contains ( myItem . item . index ) ) { continue ; }
28+ if ( Core . Instance . Settings . KeptItemsOnDeath . KeptItemIds . Contains ( myItem . item . index ) ) { continue ; }
29+ if ( Core . Instance . Settings . KeptItemsOnDeath . KeptItemNames . Contains ( myItem . item . itemName ) ) { continue ; }
30+ if ( Core . Instance . Settings . KeptItemsOnDeath . KeepAllPhones && myItem . item is ShPhone ) { continue ; }
31+ if ( Core . Instance . Settings . KeptItemsOnDeath . KeepAllLicenses && LicenseIDs . Contains ( myItem . item . index ) ) { continue ; }
3232
3333 // BPE EXTEND --
3434
@@ -50,9 +50,41 @@ protected void OnRemoveItemsDeath(ShPlayer player)
5050 // Remove everything except legal items currently worn
5151 if ( extra > 0 && ( myItem . item . illegal || ! ( myItem . item is ShWearable w ) || player . curWearables [ ( int ) w . type ] . index != w . index ) )
5252 {
53+ removedItems . Add ( new InventoryItem ( myItem . item , extra ) ) ;
5354 player . TransferItem ( DeltaInv . RemoveFromMe , myItem . item . index , extra , true ) ;
5455 }
5556 }
57+
58+ if ( dropItems )
59+ {
60+ // Only drop items if attacker present, to prevent AI suicide item farming
61+ if ( Physics . Raycast (
62+ player . GetPosition + Vector3 . up ,
63+ Vector3 . down ,
64+ out RaycastHit hit ,
65+ 10f ,
66+ MaskIndex . world ) )
67+ {
68+ ShEntity briefcase = player . manager . svManager . AddNewEntity (
69+ player . manager . svManager . briefcasePrefabs . GetRandom ( ) ,
70+ player . GetPlace ,
71+ hit . point ,
72+ Quaternion . LookRotation ( player . GetPositionT . forward ) ,
73+ false ) ;
74+
75+ if ( briefcase )
76+ {
77+ foreach ( var invItem in removedItems )
78+ {
79+ if ( Random . value < 0.8f )
80+ {
81+ invItem . count = Mathf . CeilToInt ( invItem . count * Random . Range ( 0.05f , 0.3f ) ) ;
82+ briefcase . myItems . Add ( invItem . item . index , invItem ) ;
83+ }
84+ }
85+ }
86+ }
87+ }
5688 }
5789 }
5890}
0 commit comments