Skip to content

Commit

Permalink
Fixes ThrowItem not working with item(s) has DiscardLimit
Browse files Browse the repository at this point in the history
  • Loading branch information
dounai2333 committed Nov 18, 2023
1 parent a2d111e commit cabbadc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
17 changes: 11 additions & 6 deletions Source/Coop/Player/PlayerInventoryController_ThrowItem_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,7 @@ public override void Replicated(EFT.Player player, Dictionary<string, object> di
{
EFT.Player.PlayerInventoryController playerInventoryController = itemController as EFT.Player.PlayerInventoryController;
if (playerInventoryController == null)
{
playerInventoryController = new(player, player.Profile, false);
playerInventoryController.ResetDiscardLimits();
}

List<ItemsCount> destroyedItems = GetDestroyedItemsFromItem(playerInventoryController, item);
if (destroyedItems.Count != 0)
Expand Down Expand Up @@ -127,8 +124,13 @@ public static List<ItemsCount> GetDestroyedItemsFromItem(EFT.Player.PlayerInvent
{
List<ItemsCount> destroyedItems = new();

if (playerInventoryController.HasDiscardLimit(item, out int itemDiscardLimit) && item.StackObjectsCount > itemDiscardLimit)
destroyedItems.Add(new ItemsCount(item, item.StackObjectsCount - itemDiscardLimit, itemDiscardLimit));
//if (playerInventoryController.HasDiscardLimit(item, out int itemDiscardLimit) && item.StackObjectsCount > itemDiscardLimit)
if (playerInventoryController.HasDiscardLimits && item.LimitedDiscard)
{
int itemDiscardLimit = item.DiscardLimit.Value;
if (item.StackObjectsCount > itemDiscardLimit)
destroyedItems.Add(new ItemsCount(item, item.StackObjectsCount - itemDiscardLimit, itemDiscardLimit));
}

if (item.IsContainer && destroyedItems.Count == 0)
{
Expand All @@ -143,8 +145,11 @@ public static List<ItemsCount> GetDestroyedItemsFromItem(EFT.Player.PlayerInvent
if (itemInContainer == item)
continue;

if (playerInventoryController.HasDiscardLimit(itemInContainer, out int itemInContainerDiscardLimit))
//if (playerInventoryController.HasDiscardLimit(itemInContainer, out int itemInContainerDiscardLimit))
if (playerInventoryController.HasDiscardLimits && itemInContainer.LimitedDiscard)
{
int itemInContainerDiscardLimit = itemInContainer.DiscardLimit.Value;

if (!destroyedItems.Any(x => x.Item.TemplateId == itemInContainer.TemplateId))
{
string templateId = itemInContainer.TemplateId;
Expand Down
7 changes: 1 addition & 6 deletions Source/Coop/Player/Player_DropBackpack_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,9 @@ public static void PatchPostfix(EFT.Player __instance)

EFT.Player.PlayerInventoryController playerInventoryController = itemController as EFT.Player.PlayerInventoryController;
if (playerInventoryController == null)
{
playerInventoryController = new(__instance, __instance.Profile, false);
playerInventoryController.ResetDiscardLimits();
}

if (PlayerInventoryController_ThrowItem_Patch.CallLocally.Contains(__instance.ProfileId))
PlayerInventoryController_ThrowItem_Patch.CallLocally.Remove(__instance.ProfileId);

PlayerInventoryController_ThrowItem_Patch.CallLocally.Remove(__instance.ProfileId);
PlayerInventoryController_ThrowItem_Patch.PostPatch(playerInventoryController, backpack, __instance.Profile);
}

Expand Down

0 comments on commit cabbadc

Please sign in to comment.