Skip to content

Commit

Permalink
Fix rechargeable items being mergeable
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaioru committed Oct 3, 2023
1 parent cbaa28f commit fe0a48c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Immutable;
using Edelstein.Common.Gameplay.Constants;
using Edelstein.Common.Gameplay.Models.Inventories.Items;
using Edelstein.Protocol.Gameplay.Models.Characters;
using Edelstein.Protocol.Gameplay.Models.Inventories;
Expand Down Expand Up @@ -153,6 +154,7 @@ public bool HasSlotFor(IItemInventory? inventory, ICollection<IItemSlot> items)

var bundles = items
.OfType<IItemSlotBundle>()
.Where(b => !ItemConstants.IsRechargeableItem(b.ID))
.ToImmutableList();
var bundlesMerged = new List<IItemSlotBundle>();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Immutable;
using Edelstein.Common.Gameplay.Constants;
using Edelstein.Common.Gameplay.Models.Inventories.Items;
using Edelstein.Common.Gameplay.Models.Inventories.Modify.Operations;
using Edelstein.Protocol.Gameplay.Models.Inventories;
Expand Down Expand Up @@ -43,7 +44,7 @@ public override short Add(IItemSlot? item)
{
case ItemSlotBundle bundle:
if (_manager.Retrieve(bundle.ID).Result is not IItemBundleTemplate template) goto default;
// if (ItemConstants.IsRechargeableItem(bundle.TemplateID)) goto default; // TODO: rechargeable constants
if (ItemConstants.IsRechargeableItem(template.ID)) goto default;
if (bundle.Number < 1) bundle.Number = 1;

var mergeable = _inventory.Items
Expand Down Expand Up @@ -98,7 +99,7 @@ public override void Remove(int templateID, short count)
foreach (var kv in match)
{
if (removed >= count) return;
if (kv.Value is ItemSlotBundle bundle) // TODO: rechargable
if (kv.Value is ItemSlotBundle bundle && !ItemConstants.IsRechargeableItem(bundle.ID))
{
var diff = count - removed;

Expand Down Expand Up @@ -158,6 +159,7 @@ public override void Sort()
var inventoryCopy = _inventory.Items
.Where(kv => kv.Key > 0)
.OrderBy(kv => kv.Value.ID)
.ThenByDescending(kv => kv.Value is IItemSlotBundle bundle ? bundle.Number : 1)
.ToList();

inventoryCopy.ForEach(kv => RemoveSlot(kv.Key));
Expand Down Expand Up @@ -261,7 +263,7 @@ public void SetSlot(short slot, IItemTemplate? template, short count)
{
var item = this[slot];

if (item is IItemSlotBundle bundle)
if (item is IItemSlotBundle bundle && !ItemConstants.IsRechargeableItem(bundle.ID))
{
if (bundle.Number > count)
{
Expand Down

0 comments on commit fe0a48c

Please sign in to comment.