Skip to content

Commit 82a79d2

Browse files
authored
Merge pull request #98 from broke-protocol/master
Update to 1.12 Hotfix3 changes and match GameSource briefcase drop behavior
2 parents 3f2dec2 + d9baff3 commit 82a79d2

2 files changed

Lines changed: 44 additions & 12 deletions

File tree

src/BPEssentials/Commands/Moderation/Jail.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public void Invoke(ShPlayer player, ShPlayer target, float timeInSeconds)
2424
target.svPlayer.SvTrySetJob(BPAPI.Instance.PrisonerIndex, true, false);
2525
target.GetExtendedPlayer().ResetAndSavePosition(getPositionT.position, getPositionT.rotation, 0);
2626
target.svPlayer.SvClearCrimes();
27-
target.RemoveItemsJail();
27+
target.svPlayer.RemoveItemsJail();
2828
target.StartCoroutine(target.svPlayer.JailTimer(timeInSeconds));
2929
target.svPlayer.Send(SvSendType.Self, Channel.Reliable, ClPacket.ShowTimer, timeInSeconds);
3030
player.TS("player_jail", target.username.CleanerMessage(), timeInSeconds);

src/BPEssentials/Events/OnDropDead.cs

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
using BPEssentials.ExtensionMethods;
2-
using BrokeProtocol.API;
1+
using BrokeProtocol.API;
32
using BrokeProtocol.Entities;
4-
using BrokeProtocol.Required;
53
using BrokeProtocol.Utility;
6-
using BrokeProtocol.Utility.AI;
7-
using System;
84
using System.Linq;
5+
using System.Collections.Generic;
96
using UnityEngine;
107

118
namespace 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

Comments
 (0)