Skip to content

Commit

Permalink
[Core/Player] Replace uint64 with ObjectGUID in Trade (#361)
Browse files Browse the repository at this point in the history
  • Loading branch information
5840174 authored Oct 15, 2024
1 parent 50daab9 commit 9b0699c
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 65 deletions.
2 changes: 1 addition & 1 deletion src/server/game/Entities/Player/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion src/server/game/Entities/Player/Player.h
Original file line number Diff line number Diff line change
Expand Up @@ -1449,7 +1449,7 @@ class TC_GAME_API Player : public Unit, public GridObject<Player>
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;
Expand Down
16 changes: 9 additions & 7 deletions src/server/game/Entities/Player/TradeData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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;
Expand All @@ -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;
Expand Down
57 changes: 18 additions & 39 deletions src/server/game/Entities/Player/TradeData.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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; }

Expand All @@ -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__
4 changes: 2 additions & 2 deletions src/server/game/Handlers/ItemHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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)
Expand Down
7 changes: 2 additions & 5 deletions src/server/game/Handlers/TradeHandler.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion src/server/game/Spells/Auras/SpellAuraEffects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion src/server/game/Spells/Auras/SpellAuras.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion src/server/game/Spells/Auras/SpellAuras.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
12 changes: 6 additions & 6 deletions src/server/game/Spells/Spell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/server/game/Spells/Spell.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 9b0699c

Please sign in to comment.