From 9b0699c3d6d1990b23ee0cdd6332829a878220cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A7=E9=BB=91=E5=93=A5?= <5840174@qq.com> Date: Tue, 15 Oct 2024 20:59:31 +0800 Subject: [PATCH] [Core/Player] Replace uint64 with ObjectGUID in Trade (#361) --- src/server/game/Entities/Player/Player.cpp | 2 +- src/server/game/Entities/Player/Player.h | 2 +- src/server/game/Entities/Player/TradeData.cpp | 16 +++--- src/server/game/Entities/Player/TradeData.h | 57 ++++++------------- src/server/game/Handlers/ItemHandler.cpp | 4 +- src/server/game/Handlers/TradeHandler.cpp | 7 +-- .../game/Spells/Auras/SpellAuraEffects.cpp | 2 +- src/server/game/Spells/Auras/SpellAuras.cpp | 2 +- src/server/game/Spells/Auras/SpellAuras.h | 2 +- src/server/game/Spells/Spell.cpp | 12 ++-- src/server/game/Spells/Spell.h | 2 +- 11 files changed, 43 insertions(+), 65 deletions(-) diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp index dbd422eb9..705df64de 100644 --- a/src/server/game/Entities/Player/Player.cpp +++ b/src/server/game/Entities/Player/Player.cpp @@ -11020,7 +11020,7 @@ uint32 Player::GetItemCountWithLimitCategory(uint32 limitCategory, Item* skipIte return count; } -Item* Player::GetItemByGuid(uint64 guid) const +Item* Player::GetItemByGuid(ObjectGuid guid) const { for (uint8 i = EQUIPMENT_SLOT_START; i < INVENTORY_SLOT_ITEM_END; ++i) if (Item* pItem = GetItemByPos(INVENTORY_SLOT_BAG_0, i)) diff --git a/src/server/game/Entities/Player/Player.h b/src/server/game/Entities/Player/Player.h index 31417a519..28b4d994b 100644 --- a/src/server/game/Entities/Player/Player.h +++ b/src/server/game/Entities/Player/Player.h @@ -1449,7 +1449,7 @@ class TC_GAME_API Player : public Unit, public GridObject uint8 FindEquipSlot(ItemTemplate const* proto, uint32 slot, bool swap) const; uint32 GetItemCount(uint32 item, bool inBankAlso = false, Item* skipItem = NULL) const; uint32 GetItemCountWithLimitCategory(uint32 limitCategory, Item* skipItem = NULL) const; - Item* GetItemByGuid(uint64 guid) const; + Item* GetItemByGuid(ObjectGuid guid) const; Item* GetItemByEntry(uint32 entry) const; Item* GetItemByPos(uint16 pos) const; Item* GetItemByPos(uint8 bag, uint8 slot) const; diff --git a/src/server/game/Entities/Player/TradeData.cpp b/src/server/game/Entities/Player/TradeData.cpp index c424a6a80..9e212acf5 100644 --- a/src/server/game/Entities/Player/TradeData.cpp +++ b/src/server/game/Entities/Player/TradeData.cpp @@ -29,10 +29,10 @@ TradeData* TradeData::GetTraderData() const Item* TradeData::GetItem(TradeSlots slot) const { - return m_items[slot] ? m_player->GetItemByGuid(m_items[slot]) : NULL; + return !m_items[slot].IsEmpty() ? m_player->GetItemByGuid(m_items[slot]) : nullptr; } -bool TradeData::HasItem(uint64 itemGuid) const +bool TradeData::HasItem(ObjectGuid itemGuid) const { for (uint8 i = 0; i < TRADE_SLOT_COUNT; ++i) if (m_items[i] == itemGuid) @@ -41,7 +41,7 @@ bool TradeData::HasItem(uint64 itemGuid) const return false; } -TradeSlots TradeData::GetTradeSlotForItem(uint64 itemGuid) const +TradeSlots TradeData::GetTradeSlotForItem(ObjectGuid itemGuid) const { for (uint8 i = 0; i < TRADE_SLOT_COUNT; ++i) if (m_items[i] == itemGuid) @@ -52,12 +52,14 @@ TradeSlots TradeData::GetTradeSlotForItem(uint64 itemGuid) const Item* TradeData::GetSpellCastItem() const { - return m_spellCastItem ? m_player->GetItemByGuid(m_spellCastItem) : NULL; + return !m_spellCastItem.IsEmpty() ? m_player->GetItemByGuid(m_spellCastItem) : nullptr; } -void TradeData::SetItem(TradeSlots slot, Item* item) +void TradeData::SetItem(TradeSlots slot, Item* item, bool update /*= false*/) { - uint64 itemGuid = item ? item->GetGUID() : 0; + ObjectGuid itemGuid = ObjectGuid::Empty; + if (item) + itemGuid = item->GetGUID(); if (m_items[slot] == itemGuid) return; @@ -79,7 +81,7 @@ void TradeData::SetItem(TradeSlots slot, Item* item) void TradeData::SetSpell(uint32 spell_id, Item* castItem /*= NULL*/) { - uint64 itemGuid = castItem ? castItem->GetGUID() : 0; + ObjectGuid itemGuid = castItem ? castItem->GetGUID() : ObjectGuid::Empty; if (m_spell == spell_id && m_spellCastItem == itemGuid) return; diff --git a/src/server/game/Entities/Player/TradeData.h b/src/server/game/Entities/Player/TradeData.h index 4d74725ea..0ecc76afa 100644 --- a/src/server/game/Entities/Player/TradeData.h +++ b/src/server/game/Entities/Player/TradeData.h @@ -20,10 +20,10 @@ enum TradeSlots { - TRADE_SLOT_COUNT = 7, - TRADE_SLOT_TRADED_COUNT = 6, - TRADE_SLOT_NONTRADED = 6, - TRADE_SLOT_INVALID = -1 + TRADE_SLOT_COUNT = 7, + TRADE_SLOT_TRADED_COUNT = 6, + TRADE_SLOT_NONTRADED = 6, + TRADE_SLOT_INVALID = -1 }; class Item; @@ -34,54 +34,33 @@ class TC_GAME_API TradeData public: // constructors TradeData(Player* player, Player* trader, Player* initiator) : m_player(player), m_trader(trader), m_initiator(initiator), m_accepted(false), m_acceptProccess(false), - m_money(0), m_spell(0), m_spellCastItem(0) + m_money(0), m_spell(0), m_spellCastItem() { - memset(m_items, 0, TRADE_SLOT_COUNT * sizeof(uint64)); + //memset(m_items, 0, TRADE_SLOT_COUNT * sizeof(uint64)); } - Player* GetTrader() const - { - return m_trader; - } + Player* GetTrader() const { return m_trader; } TradeData* GetTraderData() const; Item* GetItem(TradeSlots slot) const; - bool HasItem(uint64 itemGuid) const; - TradeSlots GetTradeSlotForItem(uint64 itemGuid) const; - void SetItem(TradeSlots slot, Item* item); + bool HasItem(ObjectGuid itemGuid) const; + TradeSlots GetTradeSlotForItem(ObjectGuid itemGuid) const; + void SetItem(TradeSlots slot, Item* item, bool update = false); - uint32 GetSpell() const - { - return m_spell; - } + uint32 GetSpell() const { return m_spell; } void SetSpell(uint32 spell_id, Item* castItem = NULL); Item* GetSpellCastItem() const; - bool HasSpellCastItem() const - { - return m_spellCastItem != 0; - } + bool HasSpellCastItem() const { return !m_spellCastItem.IsEmpty(); } - uint64 GetMoney() const - { - return m_money; - } + uint64 GetMoney() const { return m_money; } void SetMoney(uint64 money); - bool IsAccepted() const - { - return m_accepted; - } + bool IsAccepted() const { return m_accepted; } void SetAccepted(bool state, bool crosssend = false); - bool IsInAcceptProcess() const - { - return m_acceptProccess; - } - void SetInAcceptProcess(bool state) - { - m_acceptProccess = state; - } + bool IsInAcceptProcess() const { return m_acceptProccess; } + void SetInAcceptProcess(bool state) { m_acceptProccess = state; } bool IsInitiator(Player const* player) const { return m_initiator == player; } @@ -101,9 +80,9 @@ class TC_GAME_API TradeData uint64 m_money; // m_player place money to trade uint32 m_spell; // m_player apply spell to non-traded slot item - uint64 m_spellCastItem; // applied spell casted by item use + ObjectGuid m_spellCastItem; // applied spell casted by item use - uint64 m_items [TRADE_SLOT_COUNT]; // traded items from m_player side including non-traded slot + ObjectGuid m_items[TRADE_SLOT_COUNT]; // traded items from m_player side including non-traded slot }; #endif // TradeData_h__ \ No newline at end of file diff --git a/src/server/game/Handlers/ItemHandler.cpp b/src/server/game/Handlers/ItemHandler.cpp index 103c4993d..2bb287d17 100644 --- a/src/server/game/Handlers/ItemHandler.cpp +++ b/src/server/game/Handlers/ItemHandler.cpp @@ -642,7 +642,7 @@ void WorldSession::HandleBuybackItem(WorldPacket& recvData) void WorldSession::HandleBuyItemInSlotOpcode(WorldPacket& recvData) { TC_LOG_DEBUG("network", "WORLD: Received CMSG_BUY_ITEM_IN_SLOT"); - uint64 vendorguid, bagguid; + ObjectGuid vendorguid, bagguid; uint32 item, slot, count; uint8 bagslot; @@ -669,7 +669,7 @@ void WorldSession::HandleBuyItemInSlotOpcode(WorldPacket& recvData) if (bag == NULL_BAG) return; - GetPlayer()->BuyItemFromVendorSlot(ObjectGuid(vendorguid), slot, item, count, bag, bagslot); + GetPlayer()->BuyItemFromVendorSlot(vendorguid, slot, item, count, bag, bagslot); } void WorldSession::HandleBuyItemOpcode(WorldPacket& recvData) diff --git a/src/server/game/Handlers/TradeHandler.cpp b/src/server/game/Handlers/TradeHandler.cpp index 65b240e2b..130869d9b 100644 --- a/src/server/game/Handlers/TradeHandler.cpp +++ b/src/server/game/Handlers/TradeHandler.cpp @@ -1,4 +1,4 @@ -/* +/* * This file is part of the Pandaria 5.4.8 Project. See THANKS file for Copyright information * * This program is free software; you can redistribute it and/or modify it @@ -564,9 +564,6 @@ void WorldSession::HandleAcceptTradeOpcode(WorldPacket& /*recvPacket*/) } } - int64 mySum = int64(his_trade->GetMoney()) - int64(my_trade->GetMoney()); - int64 hisSum = int64(my_trade->GetMoney()) - int64(his_trade->GetMoney()); - // update money _player->ModifyMoney(-int64(my_trade->GetMoney())); _player->ModifyMoney(his_trade->GetMoney()); @@ -827,7 +824,7 @@ void WorldSession::HandleSetTradeItemOpcode(WorldPacket& recvPacket) return; } - uint64 iGUID = item->GetGUID(); + ObjectGuid iGUID = item->GetGUID(); // prevent place single item into many trade slots using cheating and client bugs if (my_trade->HasItem(iGUID)) diff --git a/src/server/game/Spells/Auras/SpellAuraEffects.cpp b/src/server/game/Spells/Auras/SpellAuraEffects.cpp index 8fd2ff7f2..908b79605 100644 --- a/src/server/game/Spells/Auras/SpellAuraEffects.cpp +++ b/src/server/game/Spells/Auras/SpellAuraEffects.cpp @@ -713,7 +713,7 @@ float AuraEffect::CalculateAmount(Unit* caster, bool recalculate) // check item enchant aura cast if (!amount && caster) - if (uint64 itemGUID = GetBase()->GetCastItemGUID()) + if (ObjectGuid itemGUID = GetBase()->GetCastItemGUID()) if (Player* playerCaster = caster->ToPlayer()) if (Item* castItem = playerCaster->GetItemByGuid(itemGUID)) if (castItem->GetItemSuffixFactor()) diff --git a/src/server/game/Spells/Auras/SpellAuras.cpp b/src/server/game/Spells/Auras/SpellAuras.cpp index ed1d9b4bf..a04eae903 100644 --- a/src/server/game/Spells/Auras/SpellAuras.cpp +++ b/src/server/game/Spells/Auras/SpellAuras.cpp @@ -252,7 +252,7 @@ void AuraApplication::ClientUpdate(bool remove) data << uint8(flags); uint32 itemLevel = 0; - if (uint64 itemGUID = aura->GetCastItemGUID()) + if (ObjectGuid itemGUID = aura->GetCastItemGUID()) if (Unit* caster = aura->GetCaster()) if (Player* player = caster->ToPlayer()) if (Item* castItem = player->GetItemByGuid(itemGUID)) diff --git a/src/server/game/Spells/Auras/SpellAuras.h b/src/server/game/Spells/Auras/SpellAuras.h index da3facac5..b15eaf56d 100644 --- a/src/server/game/Spells/Auras/SpellAuras.h +++ b/src/server/game/Spells/Auras/SpellAuras.h @@ -146,7 +146,7 @@ class Aura SpellInfo const* GetSpellInfo() const { return m_spellInfo; } uint32 GetId() const{ return GetSpellInfo()->Id; } - uint64 GetCastItemGUID() const { return m_castItemGuid; } + ObjectGuid GetCastItemGUID() const { return m_castItemGuid; } ObjectGuid GetCasterGUID() const { return m_casterGuid; } Unit* GetCaster() const; WorldObject* GetOwner() const { return m_owner; } diff --git a/src/server/game/Spells/Spell.cpp b/src/server/game/Spells/Spell.cpp index a47098fda..e6c252747 100644 --- a/src/server/game/Spells/Spell.cpp +++ b/src/server/game/Spells/Spell.cpp @@ -116,8 +116,8 @@ SpellDestination::SpellDestination(WorldObject const& wObj) SpellCastTargets::SpellCastTargets() : m_elevation(0), m_speed(0), m_strTarget() { - m_objectTarget = NULL; - m_itemTarget = NULL; + m_objectTarget = nullptr; + m_itemTarget = nullptr; m_objectTargetGUID = ObjectGuid::Empty; m_itemTargetGUID = ObjectGuid::Empty; @@ -129,8 +129,8 @@ SpellCastTargets::SpellCastTargets() : m_elevation(0), m_speed(0), m_strTarget() SpellCastTargets::SpellCastTargets(Unit* caster, uint32 targetMask, ObjectGuid targetGuid, ObjectGuid itemTargetGuid, ObjectGuid srcTransportGuid, ObjectGuid destTransportGuid, Position srcPos, Position destPos, float elevation, float missileSpeed, std::string targetString) : m_targetMask(targetMask), m_objectTargetGUID(targetGuid), m_itemTargetGUID(itemTargetGuid), m_elevation(elevation), m_speed(missileSpeed), m_strTarget(targetString) { - m_objectTarget = NULL; - m_itemTarget = NULL; + m_objectTarget = nullptr; + m_itemTarget = nullptr; m_itemTargetEntry = 0; m_src._transportGUID = srcTransportGuid; @@ -624,7 +624,7 @@ m_spellValue(new SpellValue(m_spellInfo)), m_researchData(NULL) _triggeredCastFlags = TriggerCastFlags(_triggeredCastFlags | TRIGGERED_IGNORE_CAST_IN_PROGRESS | TRIGGERED_IGNORE_AURA_INTERRUPT_FLAGS); m_CastItem = NULL; - m_castItemGUID = 0; + m_castItemGUID = ObjectGuid::Empty; unitTarget = NULL; itemTarget = NULL; @@ -3418,7 +3418,7 @@ void Spell::prepare(SpellCastTargets const* targets, AuraEffect const* triggered if (m_CastItem) m_castItemGUID = m_CastItem->GetGUID(); else - m_castItemGUID = 0; + m_castItemGUID = ObjectGuid::Empty; InitExplicitTargets(*targets); diff --git a/src/server/game/Spells/Spell.h b/src/server/game/Spells/Spell.h index 713f90f29..89ef54f4f 100644 --- a/src/server/game/Spells/Spell.h +++ b/src/server/game/Spells/Spell.h @@ -472,7 +472,7 @@ class TC_GAME_API Spell SpellInfo const* const m_spellInfo; Item* m_CastItem; - uint64 m_castItemGUID; + ObjectGuid m_castItemGUID; uint8 m_cast_count; uint32 m_glyphIndex; uint32 m_preCastSpell;