Core/Players: Fixed buying bank tabs

Port From (https://github.com/TrinityCore/TrinityCore/commit/8b2fc59397ebca720726270dc5319f1d2ffa0150)
This commit is contained in:
Hondacrx
2025-09-01 17:15:37 -04:00
parent 737cdc7a63
commit 57459eacf3
5 changed files with 46 additions and 45 deletions
+3
View File
@@ -154,6 +154,9 @@ namespace Framework.Constants
public const byte ChildEquipmentStart = 81;
public const byte ChildEquipmentEnd = 84;
public const byte AccountBankBagStart = 100;
public const byte AccountBankBagEnd = 105;
public const byte Bag0 = 255;
public const byte DefaultSize = 16;
}
+1 -1
View File
@@ -788,7 +788,7 @@ namespace Framework.Constants
NeedCharacterName = 807,
PlayerNotExistOrOffline = 808,
AccountForPlayerNotFound = 809,
// Unused = 810,
BankTabName = 810,
GuildMaster = 811,
GuildOfficer = 812,
GuildVeteran = 813,
@@ -599,12 +599,6 @@ namespace Framework.Constants
Count = (End - Start)
}
public enum AccountBankBagSlots
{
Start = 100,
End = 105
}
public enum PlayerTitle : ulong
{
Disabled = 0x0000000000000000,
+34 -31
View File
@@ -4597,9 +4597,9 @@ namespace Game.Entities
return false;
}
byte FindEquipSlot(Item item, uint slot, bool swap)
byte FindEquipSlot(Item item, byte slot, bool swap)
{
byte[] slots = [ItemConst.NullSlot, ItemConst.NullSlot, ItemConst.NullSlot, ItemConst.NullSlot];
byte[] slots = [ItemConst.NullSlot, ItemConst.NullSlot, ItemConst.NullSlot, ItemConst.NullSlot, ItemConst.NullSlot, ItemConst.NullSlot];
switch (item.GetTemplate().GetInventoryType())
{
case InventoryType.Head:
@@ -4683,8 +4683,12 @@ namespace Game.Entities
slots[0] = EquipmentSlot.MainHand;
break;
case InventoryType.Bag:
if (item.GetTemplate().GetClass() != ItemClass.Container || item.GetTemplate().GetSubClass() != (uint)ItemSubClassContainer.ReagentContainer)
slots = [InventorySlots.BagStart + 0, InventorySlots.BagStart + 1, InventorySlots.BagStart + 2, InventorySlots.BagStart + 3];
if (item.GetTemplate().GetId() == 208392)
slots = [InventorySlots.AccountBankBagStart + 0, InventorySlots.AccountBankBagStart + 1, InventorySlots.AccountBankBagStart + 2, InventorySlots.AccountBankBagStart + 3, InventorySlots.AccountBankBagStart + 4, ItemConst.NullSlot];
else if (item.GetTemplate().GetId() == 242709)
slots = [InventorySlots.BankBagStart + 0, InventorySlots.BankBagStart + 1, InventorySlots.BankBagStart + 2, InventorySlots.BankBagStart + 3, InventorySlots.BankBagStart + 4, InventorySlots.BankBagStart + 5];
else if (item.GetTemplate().GetClass() != ItemClass.Container || item.GetTemplate().GetSubClass() != (int)ItemSubClassContainer.ReagentContainer)
slots = [InventorySlots.BagStart + 0, InventorySlots.BagStart + 1, InventorySlots.BagStart + 2, InventorySlots.BagStart + 3, ItemConst.NullSlot, ItemConst.NullSlot];
else
slots[0] = InventorySlots.ReagentBagStart;
break;
@@ -4753,43 +4757,42 @@ namespace Game.Entities
if (slot != ItemConst.NullSlot)
{
if (swap || GetItemByPos(InventorySlots.Bag0, (byte)slot) == null)
for (byte i = 0; i < 4; ++i)
if (slots[i] == slot)
return (byte)slot;
if (swap || GetItemByPos(InventorySlots.Bag0, slot) == null)
if (slots.Contains(slot))
return slot;
}
else
{
// search free slot at first
for (byte i = 0; i < 4; ++i)
if (slots[i] != ItemConst.NullSlot && GetItemByPos(InventorySlots.Bag0, slots[i]) == null)
var freeSlot = slots.FirstOrDefault(candidateSlot =>
{
if (candidateSlot != ItemConst.NullSlot && GetItemByPos(InventorySlots.Bag0, candidateSlot) == null)
// in case 2hand equipped weapon (without titan grip) offhand slot empty but not free
if (slots[i] != EquipmentSlot.OffHand || !IsTwoHandUsed())
return slots[i];
if (candidateSlot != EquipmentSlot.OffHand || !IsTwoHandUsed())
return true;
return false;
});
if (freeSlot != 0)
return freeSlot;
// if not found free and can swap return slot with lower item level equipped
if (swap)
{
uint minItemLevel = uint.MaxValue;
byte minItemLevelIndex = 0;
for (byte i = 0; i < 4; ++i)
freeSlot = (byte)slots.Min(candidateSlot =>
{
if (slots[i] != ItemConst.NullSlot)
{
Item equipped = GetItemByPos(InventorySlots.Bag0, slots[i]);
if (equipped != null)
{
uint itemLevel = equipped.GetItemLevel(this);
if (itemLevel < minItemLevel)
{
minItemLevel = itemLevel;
minItemLevelIndex = i;
}
}
}
}
if (candidateSlot == ItemConst.NullSlot)
return uint.MaxValue;
return slots[minItemLevelIndex];
Item equipped = GetItemByPos(InventorySlots.Bag0, candidateSlot);
if (equipped != null)
return equipped.GetItemLevel(this);
return 0u;
});
if (freeSlot != 0)
return freeSlot;
}
}
@@ -5155,7 +5158,7 @@ namespace Game.Entities
public static bool IsAccountBankPos(ushort pos) { return IsBankPos((byte)(pos >> 8), (byte)(pos & 255)); }
public static bool IsAccountBankPos(byte bag, byte slot)
{
if (bag >= (int)AccountBankBagSlots.Start && bag < (int)AccountBankBagSlots.End)
if (bag >= (int)InventorySlots.AccountBankBagStart && bag < InventorySlots.AccountBankBagEnd)
return true;
return false;
}
+7 -6
View File
@@ -2,6 +2,7 @@
// Licensed under the GNU GENERAL PUBLIC LICENSE. See LICENSE file in the project root for full license information.
using Framework.Constants;
using Game.Chat;
using Game.DataStorage;
using Game.Entities;
using Game.Networking;
@@ -152,19 +153,17 @@ namespace Game
case BankType.Character:
itemId = 242709;
slot = _player.GetCharacterBankTabCount();
inventorySlot = InventorySlots.BankBagStart;
inventorySlot = (byte)(InventorySlots.BankBagStart + slot);
break;
case BankType.Account:
itemId = 208392;
slot = _player.GetAccountBankTabCount();
inventorySlot = (byte)AccountBankBagSlots.Start;
inventorySlot = (byte)(InventorySlots.AccountBankBagStart + slot);
break;
default:
Log.outDebug(LogFilter.Network, $"WorldSession::HandleBuyBankTab {_player.GetGUID()} - Bank type {buyBankTab.BankType} is not supported.");
return;
}
// next slot
++slot;
var bankTab = CliDB.BankTabStorage.FirstOrDefault(record => record.Value.BankType == (byte)buyBankTab.BankType && record.Value.OrderIndex == slot).Value;
if (bankTab == null)
@@ -188,10 +187,12 @@ namespace Game
switch (buyBankTab.BankType)
{
case BankType.Character:
_player.SetCharacterBankTabCount(slot);
_player.SetCharacterBankTabCount((byte)(slot + 1));
_player.SetCharacterBankTabSettings(slot, new CommandHandler(this).GetParsedString(CypherStrings.BankTabName, slot + 1), "", "", BagSlotFlags.None);
break;
case BankType.Account:
_player.SetAccountBankTabCount(slot);
_player.SetAccountBankTabCount((byte)(slot + 1));
_player.SetAccountBankTabSettings(slot, new CommandHandler(this).GetParsedString(CypherStrings.BankTabName, slot + 1), "", "", BagSlotFlags.None);
break;
default:
break;