Core/Items: implement some helper methods for easier readability
Port From (https://github.com/TrinityCore/TrinityCore/commit/9124fd1f1fafea19b118eb69c6a35f94376fc7e8)
This commit is contained in:
@@ -191,7 +191,7 @@ namespace Game.Entities
|
||||
|
||||
DB.Characters.Execute(stmt);
|
||||
|
||||
if ((uState == ItemUpdateState.Changed) && HasItemFlag(ItemFieldFlags.Wrapped))
|
||||
if ((uState == ItemUpdateState.Changed) && IsWrapped())
|
||||
{
|
||||
stmt = DB.Characters.GetPreparedStatement(CharStatements.UPD_GIFT_OWNER);
|
||||
stmt.AddValue(0, GetOwnerGUID().GetCounter());
|
||||
@@ -372,7 +372,7 @@ namespace Game.Entities
|
||||
stmt.AddValue(0, GetGUID().GetCounter());
|
||||
trans.Append(stmt);
|
||||
|
||||
if (HasItemFlag(ItemFieldFlags.Wrapped))
|
||||
if (IsWrapped())
|
||||
{
|
||||
stmt = DB.Characters.GetPreparedStatement(CharStatements.DEL_GIFT);
|
||||
stmt.AddValue(0, GetGUID().GetCounter());
|
||||
@@ -446,7 +446,7 @@ namespace Game.Entities
|
||||
SetUpdateFieldValue(m_values.ModifyValue(m_itemData).ModifyValue(m_itemData.MaxDurability), proto.MaxDurability);
|
||||
|
||||
// do not overwrite durability for wrapped items
|
||||
if (durability > proto.MaxDurability && !HasItemFlag(ItemFieldFlags.Wrapped))
|
||||
if (durability > proto.MaxDurability && !IsWrapped())
|
||||
{
|
||||
SetDurability(proto.MaxDurability);
|
||||
need_save = true;
|
||||
@@ -805,7 +805,7 @@ namespace Game.Entities
|
||||
if (m_lootGenerated)
|
||||
return false;
|
||||
|
||||
if ((!mail || !IsBoundAccountWide()) && (IsSoulBound() && (!HasItemFlag(ItemFieldFlags.BopTradeable) || !trade)))
|
||||
if ((!mail || !IsBoundAccountWide()) && (IsSoulBound() && (!IsBOPTradeable() || !trade)))
|
||||
return false;
|
||||
|
||||
if (IsBag() && (Player.IsBagPos(GetPos()) || !ToBag().IsEmpty()))
|
||||
@@ -924,7 +924,7 @@ namespace Game.Entities
|
||||
bool isEnchantSpell = spellInfo.HasEffect(SpellEffectName.EnchantItem) || spellInfo.HasEffect(SpellEffectName.EnchantItemTemporary) || spellInfo.HasEffect(SpellEffectName.EnchantItemPrismatic);
|
||||
if ((int)spellInfo.EquippedItemClass != -1) // -1 == any item class
|
||||
{
|
||||
if (isEnchantSpell && proto.GetFlags3().HasAnyFlag(ItemFlags3.CanStoreEnchants))
|
||||
if (isEnchantSpell && proto.HasFlag(ItemFlags3.CanStoreEnchants))
|
||||
return true;
|
||||
|
||||
if (spellInfo.EquippedItemClass != proto.GetClass())
|
||||
@@ -1209,7 +1209,7 @@ namespace Game.Entities
|
||||
if (GetOwnerGUID() == player.GetGUID())
|
||||
return false;
|
||||
|
||||
if (HasItemFlag(ItemFieldFlags.BopTradeable))
|
||||
if (IsBOPTradeable())
|
||||
if (allowedGUIDs.Contains(player.GetGUID()))
|
||||
return false;
|
||||
|
||||
@@ -1355,7 +1355,7 @@ namespace Game.Entities
|
||||
|
||||
public void SetNotRefundable(Player owner, bool changestate = true, SQLTransaction trans = null, bool addToCollection = true)
|
||||
{
|
||||
if (!HasItemFlag(ItemFieldFlags.Refundable))
|
||||
if (!IsRefundable())
|
||||
return;
|
||||
|
||||
ItemExpirePurchaseRefund itemExpirePurchaseRefund = new();
|
||||
@@ -1458,7 +1458,7 @@ namespace Game.Entities
|
||||
if (proto.GetClass() == ItemClass.Weapon && proto.GetSubClass() == (uint)ItemSubClassWeapon.FishingPole)
|
||||
return false;
|
||||
|
||||
if (proto.GetFlags2().HasAnyFlag(ItemFlags2.NoAlterItemVisual))
|
||||
if (proto.HasFlag(ItemFlags2.NoAlterItemVisual))
|
||||
return false;
|
||||
|
||||
if (!HasStats())
|
||||
@@ -1614,7 +1614,7 @@ namespace Game.Entities
|
||||
{
|
||||
standardPrice = true;
|
||||
|
||||
if (proto.GetFlags2().HasAnyFlag(ItemFlags2.OverrideGoldCost))
|
||||
if (proto.HasFlag(ItemFlags2.OverrideGoldCost))
|
||||
return proto.GetBuyPrice();
|
||||
|
||||
var qualityPrice = CliDB.ImportPriceQualityStorage.LookupByKey(quality + 1);
|
||||
@@ -1746,7 +1746,7 @@ namespace Game.Entities
|
||||
|
||||
public static uint GetSellPrice(ItemTemplate proto, uint quality, uint itemLevel)
|
||||
{
|
||||
if (proto.GetFlags2().HasAnyFlag(ItemFlags2.OverrideGoldCost))
|
||||
if (proto.HasFlag(ItemFlags2.OverrideGoldCost))
|
||||
return proto.GetSellPrice();
|
||||
|
||||
bool standardPrice;
|
||||
@@ -1772,7 +1772,7 @@ namespace Game.Entities
|
||||
ItemTemplate itemTemplate = GetTemplate();
|
||||
uint minItemLevel = owner.m_unitData.MinItemLevel;
|
||||
uint minItemLevelCutoff = owner.m_unitData.MinItemLevelCutoff;
|
||||
uint maxItemLevel = itemTemplate.GetFlags3().HasAnyFlag(ItemFlags3.IgnoreItemLevelCapInPvp) ? 0u : owner.m_unitData.MaxItemLevel;
|
||||
uint maxItemLevel = itemTemplate.HasFlag(ItemFlags3.IgnoreItemLevelCapInPvp) ? 0u : owner.m_unitData.MaxItemLevel;
|
||||
bool pvpBonus = owner.IsUsingPvpItemLevels();
|
||||
|
||||
uint azeriteLevel = 0;
|
||||
@@ -1867,7 +1867,7 @@ namespace Game.Entities
|
||||
|
||||
public static ItemDisenchantLootRecord GetDisenchantLoot(ItemTemplate itemTemplate, uint quality, uint itemLevel)
|
||||
{
|
||||
if (itemTemplate.GetFlags().HasAnyFlag(ItemFlags.Conjured | ItemFlags.NoDisenchant) || itemTemplate.GetBonding() == ItemBondingType.Quest)
|
||||
if (itemTemplate.HasFlag(ItemFlags.Conjured) || itemTemplate.HasFlag(ItemFlags.NoDisenchant) || itemTemplate.GetBonding() == ItemBondingType.Quest)
|
||||
return null;
|
||||
|
||||
if (itemTemplate.GetArea(0) != 0 || itemTemplate.GetArea(1) != 0 || itemTemplate.GetMap() != 0 || itemTemplate.GetMaxStackSize() > 1)
|
||||
@@ -2501,8 +2501,8 @@ namespace Game.Entities
|
||||
}
|
||||
|
||||
public bool IsSoulBound() { return HasItemFlag(ItemFieldFlags.Soulbound); }
|
||||
public bool IsBoundAccountWide() { return GetTemplate().GetFlags().HasAnyFlag(ItemFlags.IsBoundToAccount); }
|
||||
public bool IsBattlenetAccountBound() { return GetTemplate().GetFlags2().HasAnyFlag(ItemFlags2.BnetAccountTradeOk); }
|
||||
public bool IsBoundAccountWide() { return GetTemplate().HasFlag(ItemFlags.IsBoundToAccount); }
|
||||
public bool IsBattlenetAccountBound() { return GetTemplate().HasFlag(ItemFlags2.BnetAccountTradeOk); }
|
||||
|
||||
public bool HasItemFlag(ItemFieldFlags flag) { return (m_itemData.DynamicFlags & (uint)flag) != 0; }
|
||||
public void AddItemFlag(ItemFieldFlags flags) { SetUpdateFieldFlagValue(m_values.ModifyValue(m_itemData).ModifyValue(m_itemData.DynamicFlags), (uint)flags); }
|
||||
@@ -2517,6 +2517,9 @@ namespace Game.Entities
|
||||
public AzeriteItem ToAzeriteItem() { return IsAzeriteItem() ? this as AzeriteItem : null; }
|
||||
public AzeriteEmpoweredItem ToAzeriteEmpoweredItem() { return IsAzeriteEmpoweredItem() ? this as AzeriteEmpoweredItem : null; }
|
||||
|
||||
public bool IsRefundable() { return HasItemFlag(ItemFieldFlags.Refundable); }
|
||||
public bool IsBOPTradeable() { return HasItemFlag(ItemFieldFlags.BopTradeable); }
|
||||
public bool IsWrapped() { return HasItemFlag(ItemFieldFlags.Wrapped); }
|
||||
public bool IsLocked() { return !HasItemFlag(ItemFieldFlags.Unlocked); }
|
||||
public bool IsBag() { return GetTemplate().GetInventoryType() == InventoryType.Bag; }
|
||||
public bool IsAzeriteItem() { return GetTypeId() == TypeId.AzeriteItem; }
|
||||
@@ -2784,8 +2787,8 @@ namespace Game.Entities
|
||||
for (int i = EffectCount; i < Effects.Length; ++i)
|
||||
Effects[i] = null;
|
||||
|
||||
CanDisenchant = !proto.GetFlags().HasAnyFlag(ItemFlags.NoDisenchant);
|
||||
CanScrap = proto.GetFlags4().HasAnyFlag(ItemFlags4.Scrapable);
|
||||
CanDisenchant = !proto.HasFlag(ItemFlags.NoDisenchant);
|
||||
CanScrap = proto.HasFlag(ItemFlags4.Scrapable);
|
||||
|
||||
_state.SuffixPriority = int.MaxValue;
|
||||
_state.AppearanceModPriority = int.MaxValue;
|
||||
|
||||
@@ -45,9 +45,15 @@ namespace Game.Entities
|
||||
return GetMaxStackSize() == 1 &&
|
||||
GetClass() != ItemClass.Consumable &&
|
||||
GetClass() != ItemClass.Quest &&
|
||||
!GetFlags().HasFlag(ItemFlags.NoCreator) &&
|
||||
!HasFlag(ItemFlags.NoCreator) &&
|
||||
GetId() != 6948; /*Hearthstone*/
|
||||
}
|
||||
|
||||
public bool HasFlag(ItemFlags flag) { return (ExtendedData.Flags[0] & (int)flag) != 0; }
|
||||
public bool HasFlag(ItemFlags2 flag) { return (ExtendedData.Flags[1] & (int)flag) != 0; }
|
||||
public bool HasFlag(ItemFlags3 flag) { return (ExtendedData.Flags[2] & (int)flag) != 0; }
|
||||
public bool HasFlag(ItemFlags4 flag) { return (ExtendedData.Flags[3] & (int)flag) != 0; }
|
||||
public bool HasFlag(ItemFlagsCustom customFlag) { return (FlagsCu & customFlag) != 0; }
|
||||
|
||||
public bool CanChangeEquipStateInCombat()
|
||||
{
|
||||
@@ -180,7 +186,7 @@ namespace Game.Entities
|
||||
dps = CliDB.ItemDamageAmmoStorage.LookupByKey(itemLevel).Quality[(int)quality];
|
||||
break;
|
||||
case InventoryType.Weapon2Hand:
|
||||
if (GetFlags2().HasAnyFlag(ItemFlags2.CasterWeapon))
|
||||
if (HasFlag(ItemFlags2.CasterWeapon))
|
||||
dps = CliDB.ItemDamageTwoHandCasterStorage.LookupByKey(itemLevel).Quality[(int)quality];
|
||||
else
|
||||
dps = CliDB.ItemDamageTwoHandStorage.LookupByKey(itemLevel).Quality[(int)quality];
|
||||
@@ -196,7 +202,7 @@ namespace Game.Entities
|
||||
case ItemSubClassWeapon.Bow:
|
||||
case ItemSubClassWeapon.Gun:
|
||||
case ItemSubClassWeapon.Crossbow:
|
||||
if (GetFlags2().HasAnyFlag(ItemFlags2.CasterWeapon))
|
||||
if (HasFlag(ItemFlags2.CasterWeapon))
|
||||
dps = CliDB.ItemDamageTwoHandCasterStorage.LookupByKey(itemLevel).Quality[(int)quality];
|
||||
else
|
||||
dps = CliDB.ItemDamageTwoHandStorage.LookupByKey(itemLevel).Quality[(int)quality];
|
||||
@@ -208,7 +214,7 @@ namespace Game.Entities
|
||||
case InventoryType.Weapon:
|
||||
case InventoryType.WeaponMainhand:
|
||||
case InventoryType.WeaponOffhand:
|
||||
if (GetFlags2().HasAnyFlag(ItemFlags2.CasterWeapon))
|
||||
if (HasFlag(ItemFlags2.CasterWeapon))
|
||||
dps = CliDB.ItemDamageOneHandCasterStorage.LookupByKey(itemLevel).Quality[(int)quality];
|
||||
else
|
||||
dps = CliDB.ItemDamageOneHandStorage.LookupByKey(itemLevel).Quality[(int)quality];
|
||||
@@ -234,7 +240,7 @@ namespace Game.Entities
|
||||
|
||||
public bool IsUsableByLootSpecialization(Player player, bool alwaysAllowBoundToAccount)
|
||||
{
|
||||
if (GetFlags().HasAnyFlag(ItemFlags.IsBoundToAccount) && alwaysAllowBoundToAccount)
|
||||
if (HasFlag(ItemFlags.IsBoundToAccount) && alwaysAllowBoundToAccount)
|
||||
return true;
|
||||
|
||||
uint spec = player.GetLootSpecId();
|
||||
@@ -265,10 +271,6 @@ namespace Game.Entities
|
||||
public ItemClass GetClass() { return (ItemClass)BasicData.ClassID; }
|
||||
public uint GetSubClass() { return BasicData.SubclassID; }
|
||||
public ItemQuality GetQuality() { return (ItemQuality)ExtendedData.OverallQualityID; }
|
||||
public ItemFlags GetFlags() { return (ItemFlags)ExtendedData.Flags[0]; }
|
||||
public ItemFlags2 GetFlags2() { return (ItemFlags2)ExtendedData.Flags[1]; }
|
||||
public ItemFlags3 GetFlags3() { return (ItemFlags3)ExtendedData.Flags[2]; }
|
||||
public ItemFlags4 GetFlags4() { return (ItemFlags4)ExtendedData.Flags[3]; }
|
||||
public uint GetOtherFactionItemId() { return ExtendedData.FactionRelated; }
|
||||
public float GetPriceRandomValue() { return ExtendedData.PriceRandomValue; }
|
||||
public float GetPriceVariance() { return ExtendedData.PriceVariance; }
|
||||
@@ -327,9 +329,9 @@ namespace Game.Entities
|
||||
}
|
||||
|
||||
public bool IsPotion() { return GetClass() == ItemClass.Consumable && GetSubClass() == (uint)ItemSubClassConsumable.Potion; }
|
||||
public bool IsVellum() { return GetFlags3().HasAnyFlag(ItemFlags3.CanStoreEnchants); }
|
||||
public bool IsConjuredConsumable() { return GetClass() == ItemClass.Consumable && GetFlags().HasAnyFlag(ItemFlags.Conjured); }
|
||||
public bool IsCraftingReagent() { return GetFlags2().HasAnyFlag(ItemFlags2.UsedInATradeskill); }
|
||||
public bool IsVellum() { return HasFlag(ItemFlags3.CanStoreEnchants); }
|
||||
public bool IsConjuredConsumable() { return GetClass() == ItemClass.Consumable && HasFlag(ItemFlags.Conjured); }
|
||||
public bool IsCraftingReagent() { return HasFlag(ItemFlags2.UsedInATradeskill); }
|
||||
|
||||
public bool IsWeapon() { return GetClass() == ItemClass.Weapon; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user