Move git root from Client/ to src/ to track all source code: - Client: Game client source (moved to Client/Client/) - Server: Game server source - GameTools: Development tools - CryptoSource: Encryption utilities - database: Database scripts - Script: Game scripts - rylCoder_16.02.2008_src: Legacy coder tools - GMFont, Game: Additional resources 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
775 lines
21 KiB
C++
775 lines
21 KiB
C++
|
||
#include "stdafx.h"
|
||
|
||
#include <Network/Packet/PacketStruct/CharCommunityPacket.h>
|
||
#include <Network/Packet/WrapPacket.h>
|
||
#include <Network/Packet/PacketCommand.h>
|
||
#include <Network/Packet/ChatPacket.h>
|
||
#include <Network/Stream/SendStream.h>
|
||
#include <Network/Dispatch/GameClient/GameClientDispatch.h>
|
||
#include <Network/Dispatch/GameClient/SendCharCommunity.h>
|
||
|
||
#include <Creature/Character/Character.h>
|
||
#include <Creature/Siege/CampShop.h>
|
||
|
||
#include <Community/Guild/Guild.h>
|
||
#include <Community/Guild/GuildMgr.h>
|
||
|
||
#include <Item/Item.h>
|
||
#include <Item/ItemFactory.h>
|
||
|
||
#include <Map/FieldMap/Cell.h>
|
||
#include <Log/ItemLog.h>
|
||
#include <Utility/Math/Math.h>
|
||
|
||
#include "StallContainer.h"
|
||
#include "ContainerConstant.h"
|
||
|
||
using namespace Item;
|
||
|
||
|
||
// ------------------------------------------------------------------------------------------
|
||
// CShopContainer
|
||
|
||
CShopContainer::CShopContainer()
|
||
{
|
||
Clear();
|
||
}
|
||
|
||
CShopContainer::~CShopContainer()
|
||
{
|
||
Destroy();
|
||
}
|
||
|
||
bool CShopContainer::Initialize(unsigned long dwCID, unsigned char cWidth, unsigned char cHeight)
|
||
{
|
||
return CArrayContainer::Initialize(dwCID, cWidth, cHeight, 1);
|
||
}
|
||
|
||
void CShopContainer::Clear(void)
|
||
{
|
||
std::fill_n(m_aryCustomerID, int(MAX_CUSTOMER_NUM), 0);
|
||
}
|
||
|
||
void CShopContainer::Destroy(void)
|
||
{
|
||
if (NULL != m_lppItems)
|
||
{
|
||
delete [] m_lppItems;
|
||
m_lppItems = NULL;
|
||
}
|
||
}
|
||
|
||
CItem* CShopContainer::GetItem(ItemPos itemPos)
|
||
{
|
||
return CArrayContainer::GetItem(itemPos);
|
||
}
|
||
|
||
bool CShopContainer::RemoveItem(ItemPos itemPos)
|
||
{
|
||
CItem* lpItem = GetItem(itemPos);
|
||
if (NULL != lpItem)
|
||
{
|
||
lpItem->SetStallPrice(0);
|
||
if (true == CArrayContainer::RemoveItem(itemPos))
|
||
{
|
||
lpItem->MoveItem(lpItem->GetPos());
|
||
return true;
|
||
}
|
||
}
|
||
|
||
return false;
|
||
}
|
||
|
||
bool CShopContainer::Enter(CCharacter* lpCustomer)
|
||
{
|
||
if (NULL != lpCustomer && 0 != m_dwCID)
|
||
{
|
||
for (int nIndex = 0; nIndex < MAX_CUSTOMER_NUM; nIndex++)
|
||
{
|
||
if (0 == m_aryCustomerID[nIndex])
|
||
{
|
||
m_aryCustomerID[nIndex] = lpCustomer->GetCID();
|
||
lpCustomer->GetStall().SetOtherOwner(m_dwCID);
|
||
SendCharStallItemInfo(lpCustomer);
|
||
|
||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>α<EFBFBD> : <20><><EFBFBD><EFBFBD>(<28>մ<EFBFBD>CID)
|
||
CAggresiveCreature* lpCreature = CCreatureManager::GetInstance().GetAggresiveCreature(m_dwCID);
|
||
if (NULL != lpCreature)
|
||
{
|
||
GAMELOG::LogStallEnterLeave(*lpCreature, lpCustomer->GetCID(), true);
|
||
}
|
||
return true;
|
||
}
|
||
}
|
||
}
|
||
|
||
return false;
|
||
}
|
||
|
||
bool CShopContainer::Leave(CCharacter* lpCustomer)
|
||
{
|
||
if (NULL != lpCustomer && 0 != m_dwCID)
|
||
{
|
||
for (int nIndex = 0; nIndex < MAX_CUSTOMER_NUM; nIndex++)
|
||
{
|
||
if (m_aryCustomerID[nIndex] == lpCustomer->GetCID())
|
||
{
|
||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>α<EFBFBD> : <20><><EFBFBD><EFBFBD>(<28>մ<EFBFBD>CID)
|
||
CAggresiveCreature* lpCreature = CCreatureManager::GetInstance().GetAggresiveCreature(m_dwCID);
|
||
if (NULL != lpCreature)
|
||
{
|
||
GAMELOG::LogStallEnterLeave(*lpCreature, lpCustomer->GetCID(), false);
|
||
}
|
||
|
||
lpCustomer->GetStall().SetOtherOwner(0);
|
||
|
||
std::copy(m_aryCustomerID + nIndex + 1, m_aryCustomerID + MAX_CUSTOMER_NUM, m_aryCustomerID + nIndex);
|
||
m_aryCustomerID[MAX_CUSTOMER_NUM - 1] = 0;
|
||
|
||
return true;
|
||
}
|
||
}
|
||
}
|
||
|
||
return false;
|
||
}
|
||
|
||
unsigned char CShopContainer::GetCurrentCustomerNum(void)
|
||
{
|
||
unsigned char cCurrentNum = 0;
|
||
|
||
for (int nIndex = 0; nIndex < MAX_CUSTOMER_NUM; ++nIndex)
|
||
{
|
||
if (0 != m_aryCustomerID[nIndex])
|
||
{
|
||
++cCurrentNum;
|
||
}
|
||
}
|
||
|
||
return cCurrentNum;
|
||
}
|
||
|
||
void CShopContainer::SwapPosAllItem(void)
|
||
{
|
||
CItem** lppItem = m_lppItems;
|
||
CItem** lppItemPastEnd = m_lppItems + m_nMaxSize;
|
||
|
||
for (; lppItem != lppItemPastEnd; ++lppItem)
|
||
{
|
||
CItem* lpItem = *lppItem;
|
||
if (NULL != lpItem && m_lpNullItem != lpItem)
|
||
{
|
||
lpItem->SwapPos();
|
||
}
|
||
}
|
||
}
|
||
|
||
bool CShopContainer::StallPriceOut(unsigned long* szStallPriceBuffer_Out, unsigned char& cItemNum_Out) const
|
||
{
|
||
CItem** lppItem = m_lppItems;
|
||
CItem** lppItemPastEnd = m_lppItems + m_nMaxSize;
|
||
|
||
for (; lppItem != lppItemPastEnd; ++lppItem)
|
||
{
|
||
CItem* lpItem = *lppItem;
|
||
if (NULL != lpItem && m_lpNullItem != lpItem)
|
||
{
|
||
szStallPriceBuffer_Out[cItemNum_Out] = lpItem->GetBuyPrice();
|
||
cItemNum_Out++;
|
||
}
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
bool CShopContainer::Close(void)
|
||
{
|
||
for (int nIndex = 0; nIndex < MAX_CUSTOMER_NUM && 0 != m_aryCustomerID[0]; ++nIndex)
|
||
{
|
||
CCharacter* lpCustomer = CCreatureManager::GetInstance().GetCharacter(m_aryCustomerID[0]);
|
||
if (NULL != lpCustomer)
|
||
{
|
||
// Leave <20>Լ<EFBFBD> <20><><EFBFBD>ο<EFBFBD><CEBF><EFBFBD> <20>ε<EFBFBD><CEB5><EFBFBD><EFBFBD><EFBFBD> <20><>ȭ<EFBFBD><C8AD> <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD> 0<><30> <20>ε<EFBFBD><CEB5><EFBFBD><EFBFBD><EFBFBD> <20>մ<EFBFBD><D5B4><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> ó<><C3B3><EFBFBD>ϸ<EFBFBD> <20>ȴ<EFBFBD>.
|
||
Leave(lpCustomer);
|
||
|
||
CGameClientDispatch* lpDispatch = lpCustomer->GetDispatcher();
|
||
if (NULL != lpDispatch)
|
||
{
|
||
GameClientSendPacket::SendCharStallEnter(lpDispatch->GetSendStream(), lpCustomer->GetCID(), 0, 0);
|
||
}
|
||
}
|
||
}
|
||
|
||
Clear();
|
||
|
||
return true;
|
||
}
|
||
|
||
bool CShopContainer::SendAllCustomer(const char* szPacket, const unsigned long dwPacketSize,
|
||
bool bIncludeOwner, unsigned char cCMD_In)
|
||
{
|
||
for (int nIndex = 0; nIndex < MAX_CUSTOMER_NUM; nIndex++)
|
||
{
|
||
if (0 == m_aryCustomerID[nIndex]) { break; }
|
||
|
||
CCharacter* lpCustomer = CCreatureManager::GetInstance().GetCharacter(m_aryCustomerID[nIndex]);
|
||
if (NULL != lpCustomer)
|
||
{
|
||
CGameClientDispatch* lpDispatch = lpCustomer->GetDispatcher();
|
||
if (NULL != lpDispatch)
|
||
{
|
||
lpDispatch->GetSendStream().PutBuffer(szPacket, dwPacketSize, cCMD_In);
|
||
}
|
||
}
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
bool CShopContainer::SendRemoveItem(TakeType takeType, unsigned char cCmd, const char* strBuyUser)
|
||
{
|
||
PktStRI pktStRI;
|
||
|
||
pktStRI.m_dwCharID = m_dwCID;
|
||
pktStRI.m_dwShopID = m_dwCID;
|
||
pktStRI.m_TakeType = takeType;
|
||
pktStRI.m_dwPrice = 0;
|
||
pktStRI.m_cCmd = cCmd;
|
||
strcpy(pktStRI.m_BuyUser, strBuyUser);
|
||
|
||
char* szPacket = reinterpret_cast<char*>(&pktStRI);
|
||
if (PacketWrap::WrapCrypt(szPacket, sizeof(PktStRI), CmdCharStallRegisterItem, 0, PktBase::NO_SERVER_ERR))
|
||
{
|
||
return SendAllCustomer(szPacket, sizeof(PktStRI), true, CmdCharStallRegisterItem);
|
||
}
|
||
|
||
return false;
|
||
}
|
||
|
||
bool CShopContainer::SendCharStallEnter(unsigned long dwCustomerID, unsigned long dwOwnerID)
|
||
{
|
||
PktStE pktStE;
|
||
|
||
pktStE.m_dwCustomerID = dwCustomerID;
|
||
pktStE.m_dwOwnerID = dwOwnerID;
|
||
|
||
char* szPacket = reinterpret_cast<char*>(&pktStE);
|
||
if (PacketWrap::WrapCrypt(szPacket, sizeof(PktStE), CmdCharStallEnter, 0, 0))
|
||
{
|
||
return SendAllCustomer(szPacket, sizeof(PktStE), true, CmdCharStallEnter);
|
||
}
|
||
|
||
return false;
|
||
}
|
||
|
||
// ------------------------------------------------------------------------------------------
|
||
// CCharacterShopContainer
|
||
|
||
CCharacterShopContainer::CCharacterShopContainer()
|
||
: m_dwOtherOwnerID(0)
|
||
{
|
||
Clear();
|
||
}
|
||
|
||
CCharacterShopContainer::~CCharacterShopContainer()
|
||
{
|
||
Destroy();
|
||
}
|
||
|
||
void CCharacterShopContainer::Clear(void)
|
||
{
|
||
std::fill_n(m_strStallName, int(MAX_STALL_NAME_LEN), 0);
|
||
|
||
CShopContainer::Clear();
|
||
}
|
||
|
||
void CCharacterShopContainer::RollBackAllItem(void)
|
||
{
|
||
for (unsigned short nHeight = 0; nHeight < m_nYSize; ++nHeight)
|
||
{
|
||
const unsigned short nHeightPos = m_nXSize * nHeight;
|
||
|
||
for (unsigned short nWidth = 0; nWidth < m_nXSize; ++nWidth)
|
||
{
|
||
CItem* lpItem = m_lppItems[nHeightPos + nWidth];
|
||
if (NULL == lpItem || m_lpNullItem == lpItem) { continue; }
|
||
|
||
lpItem->MoveItem(lpItem->GetPos());
|
||
lpItem->SetStallPrice(0);
|
||
}
|
||
}
|
||
|
||
std::fill_n(m_lppItems, int(m_nXSize*m_nYSize), reinterpret_cast<CItem*>(NULL));
|
||
}
|
||
|
||
bool CCharacterShopContainer::SetItem(ItemPos itemPos, CItem* lpItem)
|
||
{
|
||
CCharacter* lpCharacter = CCreatureManager::GetInstance().GetCharacter(m_dwCID);
|
||
if (NULL != lpCharacter)
|
||
{
|
||
if (false == lpCharacter->GetInventory().SetItem(lpItem->GetPos(), lpItem))
|
||
{
|
||
SERLOG1(g_Log, "CID:%10u <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>Ͻ<EFBFBD> <20>κ<EFBFBD><CEBA>丮<EFBFBD><E4B8AE> <20><>ũ<EFBFBD><C5A9> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD>Ͽ<EFBFBD><CFBF><EFBFBD><EFBFBD>ϴ<EFBFBD>.",
|
||
lpCharacter->GetCID());
|
||
return false;
|
||
}
|
||
|
||
if (false == CArrayContainer::SetItem(itemPos, lpItem))
|
||
{
|
||
SERLOG1(g_Log, "CID:%10u <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ø<EFBFBD><C3B8>µ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>Ͽ<EFBFBD><CFBF><EFBFBD><EFBFBD>ϴ<EFBFBD>.", lpCharacter->GetCID());
|
||
if (false == lpCharacter->GetInventory().RemoveItem(lpItem->GetPos()))
|
||
{
|
||
SERLOG1(g_Log, "CID:%10u <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>Ͽ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>Ͽ<EFBFBD> <20>κ<EFBFBD><CEBA>丮<EFBFBD><E4B8AE><EFBFBD><EFBFBD> <20><> <20><>ũ<EFBFBD><C5A9> <20><><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>Ͽ<EFBFBD><CFBF><EFBFBD><EFBFBD>ϴ<EFBFBD>.",
|
||
lpCharacter->GetCID());
|
||
}
|
||
return false;
|
||
}
|
||
|
||
const int MAX_BUFFER = sizeof(PktStIInfo) + MAX_ITEM_SIZE + sizeof(unsigned long);
|
||
char szBuffer[MAX_BUFFER];
|
||
|
||
lpItem->SwapPos();
|
||
size_t nItemSize = MAX_ITEM_SIZE;
|
||
lpItem->SerializeOut(szBuffer + sizeof(PktStIInfo), nItemSize);
|
||
if (0 == nItemSize) { return false; }
|
||
lpItem->SwapPos();
|
||
|
||
unsigned long* dwStallPrice = reinterpret_cast<unsigned long*>(szBuffer + sizeof(PktStIInfo) + nItemSize);
|
||
*dwStallPrice = lpItem->GetBuyPrice();
|
||
|
||
PktStIInfo* lpPktStIInfo = reinterpret_cast<PktStIInfo*>(szBuffer);
|
||
|
||
lpPktStIInfo->m_dwOwnerID = m_dwCID;
|
||
|
||
std::copy(m_aryCustomerID, m_aryCustomerID + MAX_CUSTOMER_NUM, lpPktStIInfo->m_dwCustomerID);
|
||
|
||
lpPktStIInfo->m_dwItemSize = static_cast<unsigned long>(nItemSize);
|
||
lpPktStIInfo->m_cItemNum = 1;
|
||
|
||
if (PacketWrap::WrapCrypt(szBuffer, static_cast<unsigned short>(sizeof(PktStIInfo) + nItemSize + sizeof(unsigned long)),
|
||
CmdCharStallItemInfo, 0, 0))
|
||
{
|
||
return SendAllCustomer(szBuffer,
|
||
static_cast<unsigned long>(sizeof(PktStIInfo) + nItemSize + sizeof(unsigned long)),
|
||
false, CmdCharStallItemInfo);
|
||
}
|
||
}
|
||
|
||
return false;
|
||
}
|
||
|
||
bool CCharacterShopContainer::Open(char *strStallName)
|
||
{
|
||
if (0 != strcmp(m_strStallName, "") || 0 == m_dwCID) { return false; }
|
||
|
||
strncpy(m_strStallName, strStallName, MAX_STALL_NAME_LEN);
|
||
|
||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>α<EFBFBD> : <20><><EFBFBD><EFBFBD>(<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20≯<EFBFBD>)
|
||
CAggresiveCreature* lpCreature = CCreatureManager::GetInstance().GetAggresiveCreature(m_dwCID);
|
||
if (NULL != lpCreature)
|
||
{
|
||
GAMELOG::LogStallOpenClose(*lpCreature, m_strStallName, true);
|
||
}
|
||
return true;
|
||
}
|
||
|
||
bool CCharacterShopContainer::Close(void)
|
||
{
|
||
CShopContainer::Close();
|
||
|
||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>α<EFBFBD> : <20>ݱ<EFBFBD>(<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20≯<EFBFBD>)
|
||
CAggresiveCreature* lpCreature = CCreatureManager::GetInstance().GetAggresiveCreature(m_dwCID);
|
||
if (NULL != lpCreature)
|
||
{
|
||
GAMELOG::LogStallOpenClose(*lpCreature, m_strStallName, false);
|
||
}
|
||
|
||
RollBackAllItem();
|
||
|
||
return true;
|
||
}
|
||
|
||
bool CCharacterShopContainer::SendCharStallItemInfo(CCharacter *lpCustomer)
|
||
{
|
||
const int MAX_BUFFER = sizeof(PktStIInfo) +
|
||
((MAX_ITEM_SIZE + sizeof(unsigned long)) * ContainerConstant::STALL_WIDTH * ContainerConstant::STALL_HEIGHT);
|
||
|
||
char szBuffer[MAX_BUFFER];
|
||
|
||
SwapPosAllItem();
|
||
unsigned long dwItemSize = MAX_ITEM_SIZE * m_nXSize * m_nYSize;
|
||
SerializeOut(szBuffer + sizeof(PktStIInfo), dwItemSize);
|
||
SwapPosAllItem();
|
||
|
||
unsigned char cItemNum = 0;
|
||
StallPriceOut(reinterpret_cast<unsigned long*>(szBuffer + sizeof(PktStIInfo) + dwItemSize), cItemNum);
|
||
|
||
CGameClientDispatch* lpDispatch = lpCustomer->GetDispatcher();
|
||
if (NULL != lpDispatch)
|
||
{
|
||
return GameClientSendPacket::SendCharStallItemInfo(lpDispatch->GetSendStream(),
|
||
m_dwCID, m_aryCustomerID, 0, 0, szBuffer, dwItemSize, cItemNum);
|
||
}
|
||
|
||
return false;
|
||
}
|
||
|
||
bool CCharacterShopContainer::SendCharStallOpen(char *strStallName)
|
||
{
|
||
CCharacter* lpCharacter = CCreatureManager::GetInstance().GetCharacter(m_dwCID);
|
||
if (NULL != lpCharacter)
|
||
{
|
||
CCell* lpCell = lpCharacter->GetCellPos().m_lpCell;
|
||
if (NULL == lpCell)
|
||
{
|
||
ERRLOG1(g_Log, "CID:%10u <20><> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>.", m_dwCID);
|
||
return false;
|
||
}
|
||
|
||
PktStO pktStO;
|
||
memset(&pktStO, 0, sizeof(PktStO));
|
||
|
||
pktStO.m_dwCharID = m_dwCID;
|
||
strncpy(pktStO.m_StallName, strStallName, PktStO::MAX_STALL_NAME_LEN);
|
||
pktStO.m_StallName[PktStO::MAX_STALL_NAME_LEN - 1] = 0;
|
||
|
||
lpCell->SendAllNearCellCharacter(&pktStO, sizeof(PktStO), CmdCharStallOpen);
|
||
return true;
|
||
}
|
||
|
||
return false;
|
||
}
|
||
|
||
bool CCharacterShopContainer::SendAllCustomer(const char* szPacket, const unsigned long dwPacketSize,
|
||
bool bIncludeOwner, unsigned char cCMD_In)
|
||
{
|
||
if (true == bIncludeOwner)
|
||
{
|
||
CCharacter* lpCharacter = CCreatureManager::GetInstance().GetCharacter(m_dwCID);
|
||
if (NULL != lpCharacter)
|
||
{
|
||
CGameClientDispatch* lpDispatch = lpCharacter->GetDispatcher();
|
||
if (NULL != lpDispatch)
|
||
{
|
||
lpDispatch->GetSendStream().PutBuffer(szPacket, dwPacketSize, cCMD_In);
|
||
}
|
||
}
|
||
}
|
||
|
||
return CShopContainer::SendAllCustomer(szPacket, dwPacketSize, bIncludeOwner, cCMD_In);
|
||
}
|
||
|
||
|
||
// ------------------------------------------------------------------------------------------
|
||
// CCampShopContainer
|
||
|
||
CCampShopContainer::CCampShopContainer(void)
|
||
: m_cUpdateCount(0)
|
||
{
|
||
}
|
||
|
||
CCampShopContainer::~CCampShopContainer(void)
|
||
{
|
||
}
|
||
|
||
bool CCampShopContainer::SetItem(ItemPos itemPos, CItem* lpItem)
|
||
{
|
||
if (false == CArrayContainer::SetItem(itemPos, lpItem))
|
||
{
|
||
SERLOG1(g_Log, "CID:%10u <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ø<EFBFBD><C3B8>µ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>Ͽ<EFBFBD><CFBF><EFBFBD><EFBFBD>ϴ<EFBFBD>.", m_dwCID);
|
||
return false;
|
||
}
|
||
|
||
const int MAX_BUFFER = sizeof(PktStIInfo) + MAX_ITEM_SIZE + sizeof(unsigned long);
|
||
char szBuffer[MAX_BUFFER];
|
||
|
||
size_t nItemSize = MAX_ITEM_SIZE;
|
||
lpItem->SerializeOut(szBuffer + sizeof(PktStIInfo), nItemSize);
|
||
if (0 == nItemSize) { return false; }
|
||
|
||
unsigned long* dwStallPrice = reinterpret_cast<unsigned long*>(szBuffer + sizeof(PktStIInfo) + nItemSize);
|
||
*dwStallPrice = lpItem->GetBuyPrice();
|
||
|
||
PktStIInfo* lpPktStIInfo = reinterpret_cast<PktStIInfo*>(szBuffer);
|
||
|
||
lpPktStIInfo->m_dwOwnerID = m_dwCID;
|
||
|
||
CCampShop* lpShop =
|
||
reinterpret_cast<CCampShop*>(CCreatureManager::GetInstance().GetSiegeObject(m_dwCID));
|
||
if (NULL != lpShop)
|
||
{
|
||
lpPktStIInfo->m_dwTempSafe = lpShop->GetTempSafe();
|
||
lpPktStIInfo->m_cTax = lpShop->GetTax();
|
||
}
|
||
|
||
std::copy(m_aryCustomerID, m_aryCustomerID + MAX_CUSTOMER_NUM, lpPktStIInfo->m_dwCustomerID);
|
||
|
||
lpPktStIInfo->m_dwItemSize = static_cast<unsigned long>(nItemSize);
|
||
lpPktStIInfo->m_cItemNum = 1;
|
||
|
||
if (PacketWrap::WrapCrypt(szBuffer, static_cast<unsigned short>(sizeof(PktStIInfo) + nItemSize + sizeof(unsigned long)),
|
||
CmdCharStallItemInfo, 0, 0))
|
||
{
|
||
IncreaseUpdateCount();
|
||
return SendAllCustomer(szBuffer,
|
||
static_cast<unsigned long>(sizeof(PktStIInfo) + nItemSize + sizeof(unsigned long)),
|
||
false, CmdCharStallItemInfo);
|
||
}
|
||
|
||
return false;
|
||
}
|
||
|
||
bool CCampShopContainer::RemoveItem(ItemPos itemPos)
|
||
{
|
||
IncreaseUpdateCount();
|
||
return CShopContainer::RemoveItem(itemPos);
|
||
}
|
||
|
||
void CCampShopContainer::DropItem(CCell* lpCell, const Position& currentPos, unsigned long dwOffencerGID)
|
||
{
|
||
for (unsigned short nTab = 0; nTab < m_nTabNum; ++nTab)
|
||
{
|
||
for (unsigned short nHeight = 0; nHeight < m_nYSize; ++nHeight)
|
||
{
|
||
for (unsigned short nWidth = 0; nWidth < m_nXSize; ++nWidth)
|
||
{
|
||
CItem* lpItem = m_lppItems[m_nSizePerTab * nTab + m_nXSize * nHeight + nWidth];
|
||
if (NULL != lpItem)
|
||
{
|
||
RemoveItem(lpItem->GetPos());
|
||
|
||
// <20><><EFBFBD>ϵ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>) <20><><EFBFBD>̽<EFBFBD><CCBD>̹Ƿ<CCB9> <20>ȸ<EFBFBD> <20><>ó<EFBFBD><C3B3> <20><><EFBFBD>δ<EFBFBD>.
|
||
unsigned char cNum = (lpItem->IsSet(DetailData::STACKABLE)) ? lpItem->GetNumOrDurability() : 1;
|
||
SendRemoveItem(TakeType::TakeType(lpItem->GetPos(), ItemPos(), cNum), PktStRI::SC_CAMP_SELL, "");
|
||
|
||
CCell::ItemInfo itemInfo;
|
||
const Position Pos(currentPos.m_fPointX + Math::Random::ComplexRandom(40) - 20,
|
||
currentPos.m_fPointY,
|
||
currentPos.m_fPointZ + Math::Random::ComplexRandom(40) - 20);
|
||
|
||
lpCell->SetItem(Pos, lpItem, 0, dwOffencerGID,
|
||
(0 == dwOffencerGID) ? CCell::NONE : CCell::GUILD, itemInfo);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
bool CCampShopContainer::StallPriceIn(const unsigned long* szStallPriceBuffer_In, unsigned char cItemNum_In)
|
||
{
|
||
CItem** lppItem = m_lppItems;
|
||
CItem** lppItemPastEnd = m_lppItems + m_nMaxSize;
|
||
|
||
unsigned char cItemIndex = 0;
|
||
|
||
for (; lppItem != lppItemPastEnd; ++lppItem)
|
||
{
|
||
CItem* lpItem = *lppItem;
|
||
if (NULL != lpItem && m_lpNullItem != lpItem)
|
||
{
|
||
if (cItemIndex >= cItemNum_In)
|
||
{
|
||
ERRLOG1(g_Log, "CID:0x%08x <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> DB<44><42> <20><><EFBFBD>ϵ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20>ʽ<EFBFBD><CABD>ϴ<EFBFBD>.", m_dwCID);
|
||
return false;
|
||
}
|
||
|
||
lpItem->SetStallPrice(szStallPriceBuffer_In[cItemIndex]);
|
||
++cItemIndex;
|
||
}
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
bool CCampShopContainer::SendCharStallItemInfo(CCharacter *lpCustomer)
|
||
{
|
||
CGameClientDispatch* lpDispatch = lpCustomer->GetDispatcher();
|
||
if (NULL != lpDispatch)
|
||
{
|
||
return SendCharStallItemInfo(lpDispatch->GetSendStream());
|
||
}
|
||
|
||
return false;
|
||
}
|
||
|
||
CItem* CCampShopContainer::RegisterCancelItem(CCharacter* lpCharacter, TakeType takeType, unsigned long dwPrice, unsigned char cCmd)
|
||
{
|
||
CCampShop* lpShop =
|
||
reinterpret_cast<CCampShop*>(CCreatureManager::GetInstance().GetSiegeObject(m_dwCID));
|
||
if (NULL != lpShop)
|
||
{
|
||
if (lpCharacter->GetGID() != lpShop->GetGID())
|
||
{
|
||
ERRLOG4(g_Log, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>/<2F><><EFBFBD><EFBFBD><EFBFBD>Ϸ<EFBFBD><CFB7><EFBFBD> ij<><C4B3><EFBFBD>Ϳ<EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ID<49><44> <20>ٸ<EFBFBD><D9B8>ϴ<EFBFBD>. "
|
||
"SenderID:%10u, SenderGID:%10u, CampID:%10u, CampGID:%10u",
|
||
lpCharacter->GetCID(), lpCharacter->GetGID(), m_dwCID, lpShop->GetGID());
|
||
return NULL;
|
||
}
|
||
|
||
Guild::CGuild* lpGuild = Guild::CGuildMgr::GetInstance().GetGuild(lpCharacter->GetGID());
|
||
if (NULL == lpGuild)
|
||
{
|
||
ERRLOG2(g_Log, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>/<2F><><EFBFBD><EFBFBD><EFBFBD>Ϸ<EFBFBD><CFB7><EFBFBD> ij<><C4B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>尡 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ʽ<EFBFBD><CABD>ϴ<EFBFBD>. SenderID:%10u, SenderGID:%10u",
|
||
lpCharacter->GetCID(), lpCharacter->GetGID());
|
||
return NULL;
|
||
}
|
||
|
||
if (lpGuild->GetMaster().m_dwCID != lpCharacter->GetCID())
|
||
{
|
||
ERRLOG2(g_Log, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>/<2F><><EFBFBD><EFBFBD><EFBFBD>Ϸ<EFBFBD><CFB7><EFBFBD> ij<><C4B3><EFBFBD>Ͱ<EFBFBD> <20><><EFBFBD>帶<EFBFBD><E5B8B6><EFBFBD>Ͱ<EFBFBD> <20>ƴմϴ<D5B4>. SenderID:%10u, SenderGID:%10u",
|
||
lpCharacter->GetCID(), lpCharacter->GetGID());
|
||
return NULL;
|
||
}
|
||
|
||
switch (cCmd)
|
||
{
|
||
case PktStRI::SC_CAMP_REGISTER:
|
||
{
|
||
if (takeType.m_dstPos.m_cPos != TakeType::TS_CAMPSHOP)
|
||
{
|
||
ERRLOG1(g_Log, "CID:%10u <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>߸<EFBFBD> <20>÷<EFBFBD> <20><><EFBFBD>ҽ<EFBFBD><D2BD>ϴ<EFBFBD>."
|
||
"RegisterPacket<EFBFBD><EFBFBD> DstPos<6F><73> Stall<6C><6C> <20>ƴմϴ<D5B4>.", lpCharacter->GetCID());
|
||
return NULL;
|
||
}
|
||
|
||
if (NULL != GetItem(takeType.m_dstPos))
|
||
{
|
||
ERRLOG3(g_Log, "CID:%10u <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>ġ<EFBFBD><C4A1> <20>̹<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>մϴ<D5B4>. Ŭ<><C5AC><EFBFBD>̾<EFBFBD>Ʈ<EFBFBD><C6AE> <20><> <20><>ġ:(%d, 0x%04x)",
|
||
lpCharacter->GetCID(), takeType.m_dstPos.m_cPos, takeType.m_dstPos.m_cIndex);
|
||
return NULL;
|
||
}
|
||
|
||
CItem* lpItem = lpCharacter->GetItem(takeType.m_srcPos);
|
||
if (NULL != lpItem)
|
||
{
|
||
if (false == lpItem->GetItemInfo().m_DetailData.m_bExchangeAndDrop )
|
||
{
|
||
ERRLOG1(g_Log, "CID:%10u <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>߸<EFBFBD> <20>÷<EFBFBD> <20><><EFBFBD>ҽ<EFBFBD><D2BD>ϴ<EFBFBD>."
|
||
"ExchangeAndDrop<EFBFBD><EFBFBD> TRUE<55><45> <20>ƴմϴ<D5B4>.", lpCharacter->GetCID());
|
||
|
||
return NULL;
|
||
}
|
||
|
||
if (true == lpCharacter->RemoveItem(takeType.m_srcPos))
|
||
{
|
||
lpItem->SetStallPrice(dwPrice);
|
||
if (true == SetItem(takeType.m_dstPos, lpItem))
|
||
{
|
||
return lpItem;
|
||
}
|
||
else
|
||
{
|
||
lpItem->SetStallPrice(0);
|
||
if (false == lpCharacter->SetItem(takeType.m_srcPos, lpItem))
|
||
{
|
||
SERLOG3(g_Log, "CID:0x%08x <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>̵<EFBFBD> <20><><EFBFBD><EFBFBD> : (%d, 0x%04x) <20><><EFBFBD>ڸ<EFBFBD><DAB8><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD>. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.",
|
||
lpCharacter->GetCID(), takeType.m_srcPos.m_cPos, takeType.m_srcPos.m_cIndex);
|
||
DELETE_ITEM(lpItem);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
break;
|
||
}
|
||
|
||
case PktStRI::SC_CAMP_CANCEL:
|
||
{
|
||
if (takeType.m_srcPos.m_cPos != TakeType::TS_CAMPSHOP)
|
||
{
|
||
ERRLOG1(g_Log, "CID:%10u <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ø<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>Ͽ<EFBFBD><CFBF><EFBFBD><EFBFBD>ϴ<EFBFBD>."
|
||
"CancelPacket<EFBFBD><EFBFBD> SrcPos<6F><73> Stall<6C><6C> <20>ƴմϴ<D5B4>.", lpCharacter->GetCID());
|
||
return NULL;
|
||
}
|
||
|
||
if (NULL != lpCharacter->GetItem(takeType.m_dstPos))
|
||
{
|
||
ERRLOG3(g_Log, "CID:%10u <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>ġ<EFBFBD><C4A1> <20>̹<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>մϴ<D5B4>. Ŭ<><C5AC><EFBFBD>̾<EFBFBD>Ʈ<EFBFBD><C6AE> <20><> <20><>ġ:(%d, 0x%04x)",
|
||
lpCharacter->GetCID(), takeType.m_dstPos.m_cPos, takeType.m_dstPos.m_cIndex);
|
||
return NULL;
|
||
}
|
||
|
||
CItem* lpItem = GetItem(takeType.m_srcPos);
|
||
if (NULL != lpItem)
|
||
{
|
||
if (true == RemoveItem(takeType.m_srcPos))
|
||
{
|
||
SendRemoveItem(takeType, PktStRI::SC_CAMP_CANCEL, "");
|
||
if (true == lpCharacter->SetItem(takeType.m_dstPos, lpItem))
|
||
{
|
||
return lpItem;
|
||
}
|
||
else
|
||
{
|
||
if (false == SetItem(takeType.m_srcPos, lpItem))
|
||
{
|
||
SERLOG3(g_Log, "CID:0x%08x <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>̵<EFBFBD> <20><><EFBFBD><EFBFBD> : (%d, 0x%04x) <20><><EFBFBD>ڸ<EFBFBD><DAB8><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD>. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.",
|
||
lpCharacter->GetCID(), takeType.m_srcPos.m_cPos, takeType.m_srcPos.m_cIndex);
|
||
DELETE_ITEM(lpItem);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
return NULL;
|
||
}
|
||
|
||
bool CCampShopContainer::CheckUpdateCount(void)
|
||
{
|
||
if (UPDATE_COUNT <= m_cUpdateCount)
|
||
{
|
||
m_cUpdateCount = 0;
|
||
return true;
|
||
}
|
||
|
||
return false;
|
||
}
|
||
|
||
bool CCampShopContainer::SendCharStallItemInfo(CSendStream& SendStream)
|
||
{
|
||
CCampShop* lpShop =
|
||
reinterpret_cast<CCampShop*>(CCreatureManager::GetInstance().GetSiegeObject(m_dwCID));
|
||
if (NULL != lpShop)
|
||
{
|
||
const int MAX_BUFFER = sizeof(PktStIInfo) +
|
||
((Item::MAX_ITEM_SIZE + sizeof(unsigned long)) *
|
||
ContainerConstant::CAMPSHOP_WIDTH * ContainerConstant::CAMPSHOP_HEIGHT);
|
||
|
||
char szBuffer[MAX_BUFFER];
|
||
|
||
unsigned long dwItemSize = Item::MAX_ITEM_SIZE * m_nXSize * m_nYSize;
|
||
SerializeOut(szBuffer + sizeof(PktStIInfo), dwItemSize);
|
||
|
||
unsigned char cItemNum = 0;
|
||
StallPriceOut(reinterpret_cast<unsigned long*>(szBuffer + sizeof(PktStIInfo) + dwItemSize), cItemNum);
|
||
|
||
return GameClientSendPacket::SendCharStallItemInfo(SendStream, m_dwCID, m_aryCustomerID,
|
||
lpShop->GetTempSafe(), lpShop->GetTax(), szBuffer, dwItemSize, cItemNum);
|
||
}
|
||
|
||
return false;
|
||
}
|
||
|
||
bool CCampShopContainer::IsEmpty() const
|
||
{
|
||
for (unsigned short nTab = 0; nTab < m_nTabNum; ++nTab)
|
||
{
|
||
for (unsigned short nHeight = 0; nHeight < m_nYSize; ++nHeight)
|
||
{
|
||
for (unsigned short nWidth = 0; nWidth < m_nXSize; ++nWidth)
|
||
{
|
||
const CItem* lpItem = m_lppItems[m_nSizePerTab * nTab + m_nXSize * nHeight + nWidth];
|
||
if (NULL != lpItem)
|
||
{
|
||
return false;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
return true;
|
||
} |