Skip to content

Commit

Permalink
Fix EtienneLamoureux#278 disable Relic, Charm & Potion stacking
Browse files Browse the repository at this point in the history
  • Loading branch information
hguy committed Aug 17, 2022
1 parent 18d8adb commit 7814a1e
Show file tree
Hide file tree
Showing 10 changed files with 213 additions and 198 deletions.
1 change: 1 addition & 0 deletions src/TQVaultAE.Config/UserConfig.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@
<EnableTQVaultSounds>1</EnableTQVaultSounds>
<CSVDelimiter>Comma</CSVDelimiter>
<EnableEpicLegendaryAffixes>0</EnableEpicLegendaryAffixes>
<DisableAutoStacking>0</DisableAutoStacking>
</UserSettings>
3 changes: 3 additions & 0 deletions src/TQVaultAE.Config/UserSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ public class UserSettings
[XmlElement(ElementName = "EnableEpicLegendaryAffixes")]
public bool EnableEpicLegendaryAffixes { get; set; } = false;

[XmlElement(ElementName = "DisableAutoStacking")]
public bool DisableAutoStacking { get; set; } = false;

#endregion


Expand Down
88 changes: 2 additions & 86 deletions src/TQVaultAE.GUI/Components/EquipmentPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -356,93 +356,9 @@ protected override void TryToPutdownItem(object sender, MouseEventArgs e)

// If we are a stackable and we have a stackable under us and we are the same type of stackable
// then just add to the stack instead of picking up the other stack
if (dragItem.DoesStack && itemUnderUs != null && itemUnderUs.DoesStack && dragItem.BaseItemId.Equals(itemUnderUs.BaseItemId))
{
itemUnderUs.StackSize += dragItem.StackSize;

// Added this so the tooltip would update with the correct number
itemUnderUs.IsModified = true;
this.Sack.IsModified = true;

// Get rid of ref to itemUnderUs so code below wont do anything with it.
itemUnderUs = null;

// we will just throw away the dragItem now.
}
else if (
dragItem.IsRelic && itemUnderUs != null && itemUnderUs.IsRelic
&& !itemUnderUs.IsRelicComplete && !dragItem.IsRelicComplete
&& dragItem.BaseItemId.Equals(itemUnderUs.BaseItemId)
)
{
// Stack relics
// Save the original Relic number
int originalNumber = itemUnderUs.Number;
int adjustedNumber;

// Adjust the item in the sack
// This is limited to the completion level of the Relic
itemUnderUs.Number += dragItem.Number;

// Check if we completed the item
if (itemUnderUs.IsRelicComplete)
{
float randPercent = (float)Item.GenerateSeed() / 0x7fff;
LootTableCollection table = ItemProvider.BonusTableRelicOrArtifact(itemUnderUs);

if (table != null && table.Length > 0)
{
int i = table.Length;
foreach (var e1 in table)
{
i--;
if (randPercent <= e1.Value.WeightPercent || i == 0)
{
itemUnderUs.RelicBonusId = e1.Key;
break;
}
else
randPercent -= e1.Value.WeightPercent;
}
}

ItemProvider.GetDBData(itemUnderUs);
}

itemUnderUs.IsModified = true;

// Just in case we have more relics than what we need to complete
// We then adjust the one we are holding
adjustedNumber = itemUnderUs.Number - originalNumber;
if (adjustedNumber != dragItem.Number)
{
dragItem.Number -= adjustedNumber;
dragItem.IsModified = true;

// Swap the items so the completed item stays in the
// sack and the remaining items are still being dragged
Item temp = itemUnderUs;
itemUnderUs = dragItem;
dragItem = temp;

// Drop the dragItem here
dragItem.Location = this.CellsUnderDragItem.Location;

// Now add the item to our sack
this.Sack.AddItem(dragItem);
}
else
{
this.Sack.IsModified = true;

// Get rid of ref to itemUnderUs so code below wont do anything with it.
itemUnderUs = null;

// we will just throw away the dragItem now.
}
}
else
if (!(doStackPotions(dragItem, ref itemUnderUs) || doStackRelics(ref dragItem, ref itemUnderUs)))
{
// If not stackable
if (slot != -1)
{
int slotRH = ((slot + 1) / 2) * 2;
Expand Down
201 changes: 106 additions & 95 deletions src/TQVaultAE.GUI/Components/SackPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1170,101 +1170,10 @@ protected virtual void TryToPutdownItem(object sender, MouseEventArgs e)

// If we are a stackable and we have a stackable under us and we are the same type of stackable
// then just add to the stack instead of picking up the other stack
if (dragItem.DoesStack
&& itemUnderUs != null
&& itemUnderUs.DoesStack
&& dragItem.BaseItemId.Equals(itemUnderUs.BaseItemId)
)
{
itemUnderUs.StackSize += dragItem.StackSize;

this.InvalidateItemCacheAll(itemUnderUs, dragItem);

// Added this so the tooltip would update with the correct number
itemUnderUs.IsModified = true;
this.Sack.IsModified = true;

// Get rid of ref to itemUnderUs so code below wont do anything with it.
itemUnderUs = null;

// we will just throw away the dragItem now.
}
else if (dragItem.IsRelic
&& itemUnderUs != null
&& itemUnderUs.IsRelic
&& !itemUnderUs.IsRelicComplete
&& !dragItem.IsRelicComplete
&& dragItem.BaseItemId.Equals(itemUnderUs.BaseItemId)
)
{
// Stack relics
// Save the original Relic number
int originalNumber = itemUnderUs.Number;

// Adjust the item in the sack
// This is limited to the completion level of the Relic
itemUnderUs.Number += dragItem.Number;

// Check if we completed the item
if (itemUnderUs.IsRelicComplete)
{
float randPercent = (float)Item.GenerateSeed() / 0x7fff;
LootTableCollection table = ItemProvider.BonusTableRelicOrArtifact(itemUnderUs);

if (table != null && table.Length > 0)
{
int i = table.Length;
foreach (var e1 in table)
{
i--;
if (randPercent <= e1.Value.WeightPercent || i == 0)
{
itemUnderUs.RelicBonusId = e1.Key;
break;
}
else
randPercent -= e1.Value.WeightPercent;
}
}

ItemProvider.GetDBData(itemUnderUs);
}

itemUnderUs.IsModified = true;

this.InvalidateItemCacheAll(itemUnderUs, dragItem);

// Just in case we have more relics than what we need to complete
// We then adjust the one we are holding
int adjustedNumber = itemUnderUs.Number - originalNumber;
if (adjustedNumber != dragItem.Number)
{
dragItem.Number -= adjustedNumber;
dragItem.IsModified = true;

// Swap the items so the completed item stays in the
// sack and the remaining items are still being dragged
Item temp = itemUnderUs;
itemUnderUs = dragItem;
dragItem = temp;

// Drop the dragItem here
dragItem.Location = this.CellsUnderDragItem.Location;

// Now add the item to our sack
this.Sack.AddItem(dragItem);
}
else
{
this.Sack.IsModified = true;

// Get rid of ref to itemUnderUs so code below wont do anything with it.
itemUnderUs = null;
// we will just throw away the dragItem now.
}
}
else
if (!(doStackPotions(dragItem, ref itemUnderUs) || doStackRelics(ref dragItem, ref itemUnderUs)))
{
// If not stackable
// Drop the dragItem here
dragItem.Location = this.CellsUnderDragItem.Location;

Expand Down Expand Up @@ -1315,6 +1224,108 @@ protected virtual void TryToPutdownItem(object sender, MouseEventArgs e)
}
}

protected bool doStackRelics(ref Item dragItem, ref Item itemUnderUs)
{
bool doStackRelics = dragItem.IsRelic
&& itemUnderUs != null && itemUnderUs.IsRelic
&& !itemUnderUs.IsRelicComplete && !dragItem.IsRelicComplete
&& dragItem.BaseItemId.Equals(itemUnderUs.BaseItemId)
&& !Config.UserSettings.Default.DisableAutoStacking;
if (doStackRelics)
{
// Stack relics
// Save the original Relic number
int originalNumber = itemUnderUs.Number;

// Adjust the item in the sack
// This is limited to the completion level of the Relic
itemUnderUs.Number += dragItem.Number;

// Check if we completed the item
if (itemUnderUs.IsRelicComplete)
{
float randPercent = (float)Item.GenerateSeed() / 0x7fff;
LootTableCollection table = ItemProvider.BonusTableRelicOrArtifact(itemUnderUs);

if (table != null && table.Length > 0)
{
int i = table.Length;
foreach (var e1 in table)
{
i--;
if (randPercent <= e1.Value.WeightPercent || i == 0)
{
itemUnderUs.RelicBonusId = e1.Key;
break;
}
else
randPercent -= e1.Value.WeightPercent;
}
}

ItemProvider.GetDBData(itemUnderUs);
}

itemUnderUs.IsModified = true;

this.InvalidateItemCacheAll(itemUnderUs, dragItem);

// Just in case we have more relics than what we need to complete
// We then adjust the one we are holding
int adjustedNumber = itemUnderUs.Number - originalNumber;
if (adjustedNumber != dragItem.Number)
{
dragItem.Number -= adjustedNumber;
dragItem.IsModified = true;

// Swap the items so the completed item stays in the
// sack and the remaining items are still being dragged
Item temp = itemUnderUs;
itemUnderUs = dragItem;
dragItem = temp;

// Drop the dragItem here
dragItem.Location = this.CellsUnderDragItem.Location;

// Now add the item to our sack
this.Sack.AddItem(dragItem);
}
else
{
this.Sack.IsModified = true;

// Get rid of ref to itemUnderUs so code below wont do anything with it.
itemUnderUs = null;
// we will just throw away the dragItem now.
}
}
return doStackRelics;
}

protected bool doStackPotions(Item dragItem, ref Item itemUnderUs)
{
bool doStackpotions = dragItem.DoesStack
&& itemUnderUs != null && itemUnderUs.DoesStack
&& dragItem.BaseItemId.Equals(itemUnderUs.BaseItemId)
&& !Config.UserSettings.Default.DisableAutoStacking;
if (doStackpotions)
{
itemUnderUs.StackSize += dragItem.StackSize;

this.InvalidateItemCacheAll(itemUnderUs, dragItem);

// Added this so the tooltip would update with the correct number
itemUnderUs.IsModified = true;
this.Sack.IsModified = true;

// Get rid of ref to itemUnderUs so code below wont do anything with it.
itemUnderUs = null;

// we will just throw away the dragItem now.
}
return doStackpotions;
}

protected virtual void MouseUpCallback(object sender, MouseEventArgs e)
{
this.mouseDraw = false;
Expand Down Expand Up @@ -1669,7 +1680,7 @@ private void AddRelicOrArticaftCompletionBonusMenuItems(Item focusedItem)
Font = this.CustomContextMenu.Font,
ForeColor = this.CustomContextMenu.ForeColor,
ToolTipText = tableitem.Key.Raw,
DisplayStyle= ToolStripItemDisplayStyle.ImageAndText,
DisplayStyle = ToolStripItemDisplayStyle.ImageAndText,
};
choice.Click += ChangeBonusItemClicked;

Expand Down Expand Up @@ -2034,7 +2045,7 @@ group flattenedAffix by (flattenedAffix.TypeId, flattenedAffix.Translation) into
choice.Image = this.CustomContextMenuAffixUntranslated;
choice.ToolTipText = "No Translation : " + choice.ToolTipText;
}

if (affixMenu is not null)
{
choice.Text = _DisplayAffixesByEffect
Expand Down
Loading

0 comments on commit 7814a1e

Please sign in to comment.