Core/Items: implement some helper methods for easier readability

Port From (https://github.com/TrinityCore/TrinityCore/commit/9124fd1f1fafea19b118eb69c6a35f94376fc7e8)
This commit is contained in:
hondacrx
2022-01-06 10:57:06 -05:00
parent 8f8cd4a7d4
commit 6e0becd106
23 changed files with 105 additions and 100 deletions
+2 -2
View File
@@ -614,7 +614,7 @@ namespace Game
}
if (Global.AuctionHouseMgr.GetAItem(item.GetGUID()) || !item.CanBeTraded() || item.IsNotEmptyBag() ||
item.GetTemplate().GetFlags().HasAnyFlag(ItemFlags.Conjured) || item.m_itemData.Expiration != 0 ||
item.GetTemplate().HasFlag(ItemFlags.Conjured) || item.m_itemData.Expiration != 0 ||
item.GetCount() < itemForSale.UseCount)
{
SendAuctionCommandResult(0, AuctionCommand.SellItem, AuctionResult.DatabaseError, throttle.DelayUntilNext);
@@ -826,7 +826,7 @@ namespace Game
}
if (Global.AuctionHouseMgr.GetAItem(item.GetGUID()) || !item.CanBeTraded() || item.IsNotEmptyBag() ||
item.GetTemplate().GetFlags().HasAnyFlag(ItemFlags.Conjured) || item.m_itemData.Expiration != 0 ||
item.GetTemplate().HasFlag(ItemFlags.Conjured) || item.m_itemData.Expiration != 0 ||
item.GetCount() != 1)
{
SendAuctionCommandResult(0, AuctionCommand.SellItem, AuctionResult.DatabaseError, throttle.DelayUntilNext);
+4 -4
View File
@@ -329,7 +329,7 @@ namespace Game
return;
}
if (pItem.GetTemplate().GetFlags().HasAnyFlag(ItemFlags.NoUserDestroy))
if (pItem.GetTemplate().HasFlag(ItemFlags.NoUserDestroy))
{
_player.SendEquipError(InventoryResult.DropBoundItem);
return;
@@ -427,7 +427,7 @@ namespace Game
// prevent selling item for sellprice when the item is still refundable
// this probably happens when right clicking a refundable item, the client sends both
// CMSG_SELL_ITEM and CMSG_REFUND_ITEM (unverified)
if (pItem.HasItemFlag(ItemFieldFlags.Refundable))
if (pItem.IsRefundable())
return; // Therefore, no feedback to client
// special case at auto sell (sell all)
@@ -667,7 +667,7 @@ namespace Game
return;
}
if (!gift.GetTemplate().GetFlags().HasAnyFlag(ItemFlags.IsWrapper)) // cheating: non-wrapper wrapper
if (!gift.GetTemplate().HasFlag(ItemFlags.IsWrapper)) // cheating: non-wrapper wrapper
{
GetPlayer().SendEquipError(InventoryResult.ItemNotFound, gift);
return;
@@ -857,7 +857,7 @@ namespace Game
ItemTemplate iGemProto = gems[i].GetTemplate();
// unique item (for new and already placed bit removed enchantments
if (iGemProto.GetFlags().HasAnyFlag(ItemFlags.UniqueEquippable))
if (iGemProto.HasFlag(ItemFlags.UniqueEquippable))
{
for (int j = 0; j < ItemConst.MaxGemSockets; ++j)
{
+1 -1
View File
@@ -404,7 +404,7 @@ namespace Game
}
else
{
if (pItem.loot.IsLooted() || !proto.GetFlags().HasAnyFlag(ItemFlags.HasLoot)) // Only delete item if no loot or money (unlooted loot is saved to db)
if (pItem.loot.IsLooted() || !proto.HasFlag(ItemFlags.HasLoot)) // Only delete item if no loot or money (unlooted loot is saved to db)
player.DestroyItem(pItem.GetBagSlot(), pItem.GetSlot(), true);
}
return; // item can be looted only single player
+3 -3
View File
@@ -189,7 +189,7 @@ namespace Game
if (item)
{
ItemTemplate itemProto = item.GetTemplate();
if (itemProto == null || !itemProto.GetFlags().HasAnyFlag(ItemFlags.IsBoundToAccount))
if (itemProto == null || !itemProto.HasFlag(ItemFlags.IsBoundToAccount))
{
accountBound = false;
break;
@@ -242,13 +242,13 @@ namespace Game
}
}
if (item.GetTemplate().GetFlags().HasAnyFlag(ItemFlags.Conjured) || item.m_itemData.Expiration != 0)
if (item.GetTemplate().HasFlag(ItemFlags.Conjured) || item.m_itemData.Expiration != 0)
{
player.SendMailResult(0, MailResponseType.Send, MailResponseResult.EquipError, InventoryResult.MailBoundItem);
return;
}
if (packet.Info.Cod != 0 && item.HasItemFlag(ItemFieldFlags.Wrapped))
if (packet.Info.Cod != 0 && item.IsWrapped())
{
player.SendMailResult(0, MailResponseType.Send, MailResponseResult.CantSendWrappedCod);
return;
+3 -3
View File
@@ -500,8 +500,8 @@ namespace Game
if (!Convert.ToBoolean(itemTemplate.GetAllowableClass() & GetPlayer().GetClassMask()) && itemTemplate.GetBonding() == ItemBondingType.OnAcquire)
continue;
if ((itemTemplate.GetFlags2().HasAnyFlag(ItemFlags2.FactionHorde) && GetPlayer().GetTeam() == Team.Alliance) ||
(itemTemplate.GetFlags2().HasAnyFlag(ItemFlags2.FactionAlliance) && GetPlayer().GetTeam() == Team.Horde))
if ((itemTemplate.HasFlag(ItemFlags2.FactionHorde) && GetPlayer().GetTeam() == Team.Alliance) ||
(itemTemplate.HasFlag(ItemFlags2.FactionAlliance) && GetPlayer().GetTeam() == Team.Horde))
continue;
if (leftInStock == 0)
@@ -528,7 +528,7 @@ namespace Game
item.StackCount = (int)itemTemplate.GetBuyCount();
item.Price = (ulong)price;
item.DoNotFilterOnVendor = vendorItem.IgnoreFiltering;
item.Refundable = (itemTemplate.GetFlags() & ItemFlags.ItemPurchaseRecord) != 0 && vendorItem.ExtendedCost != 0 && itemTemplate.GetMaxStackSize() == 1;
item.Refundable = itemTemplate.HasFlag(ItemFlags.ItemPurchaseRecord) && vendorItem.ExtendedCost != 0 && itemTemplate.GetMaxStackSize() == 1;
item.Item.ItemID = vendorItem.item;
if (!vendorItem.BonusListIDs.Empty())
+5 -5
View File
@@ -75,14 +75,14 @@ namespace Game
}
// only allow conjured consumable, bandage, poisons (all should have the 2^21 item flag set in DB)
if (proto.GetClass() == ItemClass.Consumable && !proto.GetFlags().HasAnyFlag(ItemFlags.IgnoreDefaultArenaRestrictions) && user.InArena())
if (proto.GetClass() == ItemClass.Consumable && !proto.HasFlag(ItemFlags.IgnoreDefaultArenaRestrictions) && user.InArena())
{
user.SendEquipError(InventoryResult.NotDuringArenaMatch, item);
return;
}
// don't allow items banned in arena
if (proto.GetFlags().HasAnyFlag(ItemFlags.NotUseableInArena) && user.InArena())
if (proto.HasFlag(ItemFlags.NotUseableInArena) && user.InArena())
{
user.SendEquipError(InventoryResult.NotDuringArenaMatch, item);
return;
@@ -158,7 +158,7 @@ namespace Game
}
// Verify that the bag is an actual bag or wrapped item that can be used "normally"
if (!proto.GetFlags().HasAnyFlag(ItemFlags.HasLoot) && !item.HasItemFlag(ItemFieldFlags.Wrapped))
if (!proto.HasFlag(ItemFlags.HasLoot) && !item.IsWrapped())
{
player.SendEquipError(InventoryResult.ClientLockedOut, item);
Log.outError(LogFilter.Network, "Possible hacking attempt: Player {0} [guid: {1}] tried to open item [guid: {2}, entry: {3}] which is not openable!",
@@ -186,7 +186,7 @@ namespace Game
}
}
if (item.HasItemFlag(ItemFieldFlags.Wrapped))// wrapped?
if (item.IsWrapped())// wrapped?
{
PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_CHARACTER_GIFT_BY_ITEM);
stmt.AddValue(0, item.GetGUID().GetCounter());
@@ -206,7 +206,7 @@ namespace Game
if (!item)
return;
if (item.GetGUID() != itemGuid || !item.HasItemFlag(ItemFieldFlags.Wrapped)) // during getting result, gift was swapped with another item
if (item.GetGUID() != itemGuid || !item.IsWrapped()) // during getting result, gift was swapped with another item
return;
if (result.IsEmpty())
+3 -3
View File
@@ -62,7 +62,7 @@ namespace Game
tradeItem.Item = new ItemInstance(item);
tradeItem.StackCount = (int)item.GetCount();
tradeItem.GiftCreator = item.GetGiftCreator();
if (!item.HasItemFlag(ItemFieldFlags.Wrapped))
if (!item.IsWrapped())
{
tradeItem.Unwrapped.HasValue = true;
TradeUpdated.UnwrappedTradeItem unwrappedItem = tradeItem.Unwrapped.Value;
@@ -124,7 +124,7 @@ namespace Game
}
// adjust time (depends on /played)
if (myItems[i].HasItemFlag(ItemFieldFlags.BopTradeable))
if (myItems[i].IsBOPTradeable())
myItems[i].SetCreatePlayedTime(trader.GetTotalPlayedTime() - (GetPlayer().GetTotalPlayedTime() - myItems[i].m_itemData.CreatePlayedTime));
// store
trader.MoveItemToInventory(traderDst, myItems[i], true, true);
@@ -143,7 +143,7 @@ namespace Game
// adjust time (depends on /played)
if (hisItems[i].HasItemFlag(ItemFieldFlags.BopTradeable))
if (hisItems[i].IsBOPTradeable())
hisItems[i].SetCreatePlayedTime(GetPlayer().GetTotalPlayedTime() - (trader.GetTotalPlayedTime() - hisItems[i].m_itemData.CreatePlayedTime));
// store
GetPlayer().MoveItemToInventory(playerDst, hisItems[i], true, true);