Core/Player: Move TradeData to its own file

(cherry picked from commit 2d7d6f505c)

Conflicts:
	src/server/game/Entities/Item/Item.cpp
	src/server/game/Entities/Player/Player.cpp
	src/server/game/Entities/Player/Player.h
	src/server/game/Handlers/TradeHandler.cpp
	src/server/game/Spells/Spell.cpp
This commit is contained in:
Carbenium
2015-11-13 02:39:45 +01:00
parent 86aa1996a4
commit 1438c841ed
7 changed files with 225 additions and 180 deletions
+1
View File
@@ -28,6 +28,7 @@
#include "ConditionMgr.h"
#include "Player.h"
#include "WorldSession.h"
#include "TradeData.h"
void AddItemsSetItem(Player* player, Item* item)
{
-121
View File
@@ -289,127 +289,6 @@ std::ostringstream& operator<< (std::ostringstream& ss, PlayerTaxi const& taxi)
return ss;
}
//== TradeData =================================================
TradeData* TradeData::GetTraderData() const
{
return m_trader->GetTradeData();
}
Item* TradeData::GetItem(TradeSlots slot) const
{
return m_items[slot] ? m_player->GetItemByGuid(m_items[slot]) : NULL;
}
bool TradeData::HasItem(ObjectGuid itemGuid) const
{
for (uint8 i = 0; i < TRADE_SLOT_COUNT; ++i)
if (m_items[i] == itemGuid)
return true;
return false;
}
TradeSlots TradeData::GetTradeSlotForItem(ObjectGuid itemGuid) const
{
for (uint8 i = 0; i < TRADE_SLOT_COUNT; ++i)
if (m_items[i] == itemGuid)
return TradeSlots(i);
return TRADE_SLOT_INVALID;
}
Item* TradeData::GetSpellCastItem() const
{
return m_spellCastItem ? m_player->GetItemByGuid(m_spellCastItem) : NULL;
}
void TradeData::SetItem(TradeSlots slot, Item* item, bool update /*= false*/)
{
ObjectGuid itemGuid;
if (item)
itemGuid = item->GetGUID();
if (m_items[slot] == itemGuid && !update)
return;
m_items[slot] = itemGuid;
SetAccepted(false);
GetTraderData()->SetAccepted(false);
Update();
// need remove possible trader spell applied to changed item
if (slot == TRADE_SLOT_NONTRADED)
GetTraderData()->SetSpell(0);
// need remove possible player spell applied (possible move reagent)
SetSpell(0);
}
void TradeData::SetSpell(uint32 spell_id, Item* castItem /*= NULL*/)
{
ObjectGuid itemGuid = castItem ? castItem->GetGUID() : ObjectGuid::Empty;
if (m_spell == spell_id && m_spellCastItem == itemGuid)
return;
m_spell = spell_id;
m_spellCastItem = itemGuid;
SetAccepted(false);
GetTraderData()->SetAccepted(false);
Update(true); // send spell info to item owner
Update(false); // send spell info to caster self
}
void TradeData::SetMoney(uint32 money)
{
if (m_money == money)
return;
if (!m_player->HasEnoughMoney(money))
{
TradeStatusInfo info;
info.Status = TRADE_STATUS_CLOSE_WINDOW;
info.Result = EQUIP_ERR_NOT_ENOUGH_MONEY;
m_player->GetSession()->SendTradeStatus(info);
return;
}
m_money = money;
SetAccepted(false);
GetTraderData()->SetAccepted(false);
Update(true);
}
void TradeData::Update(bool forTarget /*= true*/)
{
if (forTarget)
m_trader->GetSession()->SendUpdateTrade(true); // player state for trader
else
m_player->GetSession()->SendUpdateTrade(false); // player state for player
}
void TradeData::SetAccepted(bool state, bool crosssend /*= false*/)
{
m_accepted = state;
if (!state)
{
TradeStatusInfo info;
info.Status = TRADE_STATUS_BACK_TO_TRADE;
if (crosssend)
m_trader->GetSession()->SendTradeStatus(info);
else
m_player->GetSession()->SendTradeStatus(info);
}
}
// == KillRewarder ====================================================
// KillRewarder incapsulates logic of rewarding player upon kill with:
// * XP;
+2 -59
View File
@@ -29,6 +29,7 @@
#include "SpellMgr.h"
#include "SpellHistory.h"
#include "Unit.h"
#include "TradeData.h"
#include <limits>
#include <string>
@@ -687,14 +688,6 @@ struct ItemPosCount
};
typedef std::vector<ItemPosCount> ItemPosCountVec;
enum TradeSlots
{
TRADE_SLOT_COUNT = 7,
TRADE_SLOT_TRADED_COUNT = 6,
TRADE_SLOT_NONTRADED = 6,
TRADE_SLOT_INVALID = -1
};
enum TransferAbortReason
{
TRANSFER_ABORT_NONE = 0x00,
@@ -1007,56 +1000,6 @@ struct TradeStatusInfo
uint8 Slot;
};
class TradeData
{
public: // constructors
TradeData(Player* player, Player* trader) :
m_player(player), m_trader(trader), m_accepted(false), m_acceptProccess(false),
m_money(0), m_spell(0), m_spellCastItem() { }
Player* GetTrader() const { return m_trader; }
TradeData* GetTraderData() const;
Item* GetItem(TradeSlots slot) const;
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; }
void SetSpell(uint32 spell_id, Item* castItem = NULL);
Item* GetSpellCastItem() const;
bool HasSpellCastItem() const { return !m_spellCastItem.IsEmpty(); }
uint32 GetMoney() const { return m_money; }
void SetMoney(uint32 money);
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; }
private: // internal functions
void Update(bool for_trader = true);
private: // fields
Player* m_player; // Player who own of this TradeData
Player* m_trader; // Player who trade with m_player
bool m_accepted; // m_player press accept for trade list
bool m_acceptProccess; // one from player/trader press accept and this processed
uint32 m_money; // m_player place money to trade
uint32 m_spell; // m_player apply spell to non-traded slot item
ObjectGuid m_spellCastItem; // applied spell cast by item use
ObjectGuid m_items[TRADE_SLOT_COUNT]; // traded items from m_player side including non-traded slot
};
class KillRewarder
{
public:
@@ -1325,7 +1268,7 @@ class Player : public Unit, public GridObject<Player>
float GetReputationPriceDiscount(Creature const* creature) const;
Player* GetTrader() const { return m_trade ? m_trade->GetTrader() : NULL; }
Player* GetTrader() const { return m_trade ? m_trade->GetTrader() : nullptr; }
TradeData* GetTradeData() const { return m_trade; }
void TradeCancel(bool sendback);
@@ -0,0 +1,139 @@
/*
* Copyright (C) 2008-2015 TrinityCore <http://www.trinitycore.org/>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "TradeData.h"
#include "Player.h"
#include "WorldSession.h"
TradeData* TradeData::GetTraderData() const
{
return _trader->GetTradeData();
}
Item* TradeData::GetItem(TradeSlots slot) const
{
return !_items[slot].IsEmpty() ? _player->GetItemByGuid(_items[slot]) : nullptr;
}
bool TradeData::HasItem(ObjectGuid itemGuid) const
{
for (uint8 i = 0; i < TRADE_SLOT_COUNT; ++i)
if (_items[i] == itemGuid)
return true;
return false;
}
TradeSlots TradeData::GetTradeSlotForItem(ObjectGuid itemGuid) const
{
for (uint8 i = 0; i < TRADE_SLOT_COUNT; ++i)
if (_items[i] == itemGuid)
return TradeSlots(i);
return TRADE_SLOT_INVALID;
}
Item* TradeData::GetSpellCastItem() const
{
return !_spellCastItem.IsEmpty() ? _player->GetItemByGuid(_spellCastItem) : nullptr;
}
void TradeData::SetItem(TradeSlots slot, Item* item, bool update /*= false*/)
{
ObjectGuid itemGuid;
if (item)
itemGuid = item->GetGUID();
if (_items[slot] == itemGuid && !update)
return;
_items[slot] = itemGuid;
SetAccepted(false);
GetTraderData()->SetAccepted(false);
Update();
// need remove possible trader spell applied to changed item
if (slot == TRADE_SLOT_NONTRADED)
GetTraderData()->SetSpell(0);
// need remove possible player spell applied (possible move reagent)
SetSpell(0);
}
void TradeData::SetSpell(uint32 spell_id, Item* castItem /*= nullptr*/)
{
ObjectGuid itemGuid = castItem ? castItem->GetGUID() : ObjectGuid::Empty;
if (_spell == spell_id && _spellCastItem == itemGuid)
return;
_spell = spell_id;
_spellCastItem = itemGuid;
SetAccepted(false);
GetTraderData()->SetAccepted(false);
Update(true); // send spell info to item owner
Update(false); // send spell info to caster self
}
void TradeData::SetMoney(uint32 money)
{
if (_money == money)
return;
if (!_player->HasEnoughMoney(money))
{
TradeStatusInfo info;
info.Status = TRADE_STATUS_CLOSE_WINDOW;
info.Result = EQUIP_ERR_NOT_ENOUGH_MONEY;
_player->GetSession()->SendTradeStatus(info);
return;
}
_money = money;
SetAccepted(false);
GetTraderData()->SetAccepted(false);
Update(true);
}
void TradeData::Update(bool forTrader /*= true*/) const
{
if (forTrader)
_trader->GetSession()->SendUpdateTrade(true); // player state for trader
else
_player->GetSession()->SendUpdateTrade(false); // player state for player
}
void TradeData::SetAccepted(bool state, bool forTrader /*= false*/)
{
_accepted = state;
if (!state)
{
TradeStatusInfo info;
info.Status = TRADE_STATUS_BACK_TO_TRADE;
if (forTrader)
_trader->GetSession()->SendTradeStatus(info);
else
_player->GetSession()->SendTradeStatus(info);
}
}
@@ -0,0 +1,81 @@
/*
* Copyright (C) 2008-2015 TrinityCore <http://www.trinitycore.org/>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TradeData_h__
#define TradeData_h__
#include "ObjectGuid.h"
enum TradeSlots
{
TRADE_SLOT_COUNT = 7,
TRADE_SLOT_TRADED_COUNT = 6,
TRADE_SLOT_NONTRADED = 6,
TRADE_SLOT_INVALID = -1
};
class Item;
class Player;
class TradeData
{
public:
TradeData(Player* player, Player* trader) :
_player(player), _trader(trader), _accepted(false), _acceptProccess(false),
_money(0), _spell(0), _spellCastItem() { }
Player* GetTrader() const { return _trader; }
TradeData* GetTraderData() const;
Item* GetItem(TradeSlots slot) const;
bool HasItem(ObjectGuid itemGuid) const;
TradeSlots GetTradeSlotForItem(ObjectGuid itemGuid) const;
void SetItem(TradeSlots slot, Item* item, bool update = false);
uint32 GetSpell() const { return _spell; }
void SetSpell(uint32 spell_id, Item* castItem = nullptr);
Item* GetSpellCastItem() const;
bool HasSpellCastItem() const { return !_spellCastItem.IsEmpty(); }
uint32 GetMoney() const { return _money; }
void SetMoney(uint32 money);
bool IsAccepted() const { return _accepted; }
void SetAccepted(bool state, bool forTrader = false);
bool IsInAcceptProcess() const { return _acceptProccess; }
void SetInAcceptProcess(bool state) { _acceptProccess = state; }
private:
void Update(bool for_trader = true) const;
Player* _player; // Player who own of this TradeData
Player* _trader; // Player who trade with _player
bool _accepted; // _player press accept for trade list
bool _acceptProccess; // one from player/trader press accept and this processed
uint32 _money; // _player place money to trade
uint32 _spell; // _player apply spell to non-traded slot item
ObjectGuid _spellCastItem; // applied spell cast by item use
ObjectGuid _items[TRADE_SLOT_COUNT]; // traded items from _player side including non-traded slot
};
#endif // TradeData_h__
@@ -28,6 +28,7 @@
#include "SocialMgr.h"
#include "Language.h"
#include "AccountMgr.h"
#include "TradeData.h"
void WorldSession::SendTradeStatus(TradeStatusInfo const& info)
{
+1
View File
@@ -53,6 +53,7 @@
#include "SpellHistory.h"
#include "Battlefield.h"
#include "BattlefieldMgr.h"
#include "TradeData.h"
extern pEffect SpellEffects[TOTAL_SPELL_EFFECTS];