|
1 | 1 | using InventorySystem; |
2 | 2 | using InventorySystem.Items; |
| 3 | +using InventorySystem.Items.DebugTools; |
| 4 | +using InventorySystem.Items.Firearms; |
| 5 | +using InventorySystem.Items.Keycards; |
3 | 6 | using InventorySystem.Items.Pickups; |
4 | | - |
| 7 | +using InventorySystem.Items.Usables.Scp1344; |
5 | 8 | using LabExtended.API; |
6 | 9 | using LabExtended.Utilities; |
7 | 10 | using Mirror; |
8 | | - |
9 | 11 | using UnityEngine; |
10 | 12 |
|
11 | 13 | #pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable. |
@@ -37,15 +39,15 @@ public static void ReloadPrefabs() |
37 | 39 | /// Gets the current inventory slot of an item. |
38 | 40 | /// </summary> |
39 | 41 | /// <param name="item">The target item.</param> |
40 | | - /// <returns>The item slot number (1 - 8)</returns> |
| 42 | + /// <returns>The item slot number (1 - 8 or 0 if the item does not have an owner)</returns> |
41 | 43 | /// <exception cref="InvalidOperationException"></exception> |
42 | 44 | public static byte GetInventorySlot(this ItemBase item) |
43 | 45 | { |
44 | 46 | if (item == null) |
45 | 47 | throw new ArgumentNullException(nameof(item)); |
46 | | - |
47 | | - if (item.Owner is null) |
48 | | - throw new InvalidOperationException("The targeted item must be owned by a player."); |
| 48 | + |
| 49 | + if (item.Owner == null) |
| 50 | + return 0; |
49 | 51 |
|
50 | 52 | return (byte)(item.OwnerInventory.UserInventory.Items.FindKeyIndex(item.ItemSerial) + 1); |
51 | 53 | } |
@@ -189,6 +191,48 @@ public static bool TryGetRigidbody(this ItemPickupBase pickup, out Rigidbody? ri |
189 | 191 | return itemPickupBase.GetComponent<Rigidbody>(); |
190 | 192 | } |
191 | 193 |
|
| 194 | + /// <summary> |
| 195 | + /// Applies effects granted to an item's owner once the item is dropped. |
| 196 | + /// </summary> |
| 197 | + /// <param name="item">The item to simulate drop of.</param> |
| 198 | + /// <param name="keepItem">Whether or not the item should be kept in the player's inventory.</param> |
| 199 | + /// <returns>true if a pickup of the item should be dropped</returns> |
| 200 | + public static bool SimulateDrop(this ItemBase item, out bool keepItem) |
| 201 | + { |
| 202 | + keepItem = false; |
| 203 | + |
| 204 | + if (item != null && item.Owner != null) |
| 205 | + { |
| 206 | + if (item is Scp1344Item scp1344 && scp1344 != null) |
| 207 | + { |
| 208 | + if (scp1344.Status is Scp1344Status.Deactivating) |
| 209 | + { |
| 210 | + keepItem = true; |
| 211 | + return false; |
| 212 | + } |
| 213 | + |
| 214 | + if (scp1344.Status is Scp1344Status.Active) |
| 215 | + { |
| 216 | + scp1344.ServerSetStatus(Scp1344Status.Dropping); |
| 217 | + |
| 218 | + keepItem = true; |
| 219 | + return false; |
| 220 | + } |
| 221 | + } |
| 222 | + |
| 223 | + if (item is ParticleDisruptor particleDisruptor && particleDisruptor.DeleteOnDrop) |
| 224 | + return false; |
| 225 | + |
| 226 | + if (item is SingleUseKeycardItem singleUseKeycard && singleUseKeycard._destroyed) |
| 227 | + return false; |
| 228 | + |
| 229 | + if (item is RagdollMover) |
| 230 | + return false; |
| 231 | + } |
| 232 | + |
| 233 | + return true; |
| 234 | + } |
| 235 | + |
192 | 236 | /// <summary> |
193 | 237 | /// Freezes the specified pickup. |
194 | 238 | /// </summary> |
|
0 commit comments