📄 streetstallmanager.cpp
字号:
#include "stdafx.h"
#include "StreetStall.h"
#include "StreetStallManager.h"
#include "usertable.h"
#include "PackedData.h"
#include "ObjectStateManager.h"
#include "mapdbmsgparser.h"
#include "Player.h"
#include "itemmanager.h"
#include "CheckRoutine.h"
GLOBALTON(cStreetStallManager)
cStreetStallManager::cStreetStallManager()
{
m_mpStreetStall = new CMemoryPoolTempl<cStreetStall>;
m_mpStreetStall->Init( 100, 50, "StreetStallPool" );
m_StallTable.Initialize(128);
}
cStreetStallManager::~cStreetStallManager()
{
cStreetStall* pStall;
m_StallTable.SetPositionHead();
while(pStall = m_StallTable.GetData())
{
m_mpStreetStall->Free(pStall);
}
m_StallTable.RemoveAll();
SAFE_DELETE(m_mpStreetStall);
}
cStreetStall* cStreetStallManager::CreateStreetStall( CPlayer* pOwner, char* title )
{
// 悼老 敲饭捞绢啊 父电 惑痢捞 粮犁窍绰瘤 犬牢秦具窍唱 ??
ASSERT( !m_StallTable.GetData(pOwner->GetID()) );
cStreetStall* pStall = m_mpStreetStall->Alloc();
pStall->Init();
ASSERT( pStall );
if( pStall == NULL )
return NULL;
pStall->SetOwner( pOwner );
pOwner->SetStreetStallTitle( title );
m_StallTable.Add(pStall,pOwner->GetID());
return pStall;
}
void cStreetStallManager::DeleteStreetStall( CPlayer* pOwner )
{
ASSERT(m_StallTable.GetData(pOwner->GetID()));
cStreetStall* pStall = m_StallTable.GetData(pOwner->GetID());
if( pStall )
{
pStall->EmptyCellAll();
pStall->DeleteGuestAll();
m_mpStreetStall->Free( pStall );
m_StallTable.Remove(pOwner->GetID());
}
}
BOOL cStreetStallManager::IsExist( cStreetStall* pStall )
{
if( m_StallTable.GetData(pStall->GetOwner()->GetID()) == NULL )
return FALSE;
return TRUE;
}
/*
BOOL cStreetStallManager::GuestIn( CPlayer* pOwner, CPlayer* pGuest )
{
cStreetStall* pStall = m_StallTable.GetData(pOwner->GetID());
if( pStall )
{
pStall->AddGuest( pGuest );
return TRUE;
}
return FALSE;
}
void cStreetStallManager::GuestOut( DWORD OwnerId, CPlayer* pGuest )
{
CPlayer* pOwner = (CPlayer*)g_pUserTable->FindUser( OwnerId ); // 坷呈啊 乐绰瘤 拱绢 夯促.
if( pOwner == NULL ) return;
cStreetStall* pStall = m_StallTable.GetData(OwnerId);
if( pStall )
pStall->DeleteGuest( pGuest );
}
*/
cStreetStall* cStreetStallManager::FindStreetStall( CPlayer* pOwner )
{
return m_StallTable.GetData(pOwner->GetID());
}
void cStreetStallManager::StreetStallMode( CPlayer* pPlayer, char* title, BOOL bMode )
{
MSG_STREETSTALL_TITLE msg;
msg.Category = MP_STREETSTALL;
msg.dwObjectID = pPlayer->GetID();
if(bMode == TRUE)
{
OBJECTSTATEMGR_OBJ->StartObjectState(pPlayer, eObjectState_StreetStall_Owner, 0);
msg.Protocol = MP_STREETSTALL_START;
//strcpy( msg.Title, title );
SafeStrCpy( msg.Title, title, MAX_STREETSTALL_TITLELEN );
}
else
{
OBJECTSTATEMGR_OBJ->EndObjectState(pPlayer, eObjectState_StreetStall_Owner, 0);
msg.Protocol = MP_STREETSTALL_END;
}
PACKEDDATA_OBJ->QuickSendExceptObjectSelf(pPlayer,&msg,sizeof(msg));
}
void cStreetStallManager::UserLogOut( CPlayer* pPlayer )
{
cStreetStall* pGestStall = pPlayer->GetGuestStall();
cStreetStall* pOwnerStall = FindStreetStall( pPlayer );
//find
//m_StallTable.GetData(pOwner->GetID());
//m_StallTable.GetData(pStall->GetOwner()->GetID()
if( pGestStall ) // 惑痢俊 颊丛栏肺 曼啊茄 版快...
{
if( IsExist( pGestStall ) )
pGestStall->DeleteGuest( pPlayer ); // 颊丛栏肺 乐绰 惑痢俊辑 唱柯促.
MSGBASE msg;
msg.Category = MP_STREETSTALL;
msg.Protocol = MP_STREETSTALL_CLOSE;
msg.dwObjectID = pPlayer->GetID();
pPlayer->SendMsg(&msg, sizeof(msg));
return;
}
if( pOwnerStall ) // 款康吝牢 惑痢捞 乐绰 版快...
{
// 畴痢葛靛辆丰甫 舅赴促.(磊扁磊脚狼 惑怕函拳)
MSG_STREETSTALL_TITLE msg;
msg.Category = MP_STREETSTALL;
msg.Protocol = MP_STREETSTALL_END;
msg.dwObjectID = pPlayer->GetID();
pPlayer->SendMsg(&msg, sizeof(msg));
// 颊丛甸俊霸 畴痢捞 辆丰登菌澜阑 舅赴促.
MSGBASE CloseSyn;
CloseSyn.Category = MP_STREETSTALL;
CloseSyn.Protocol = MP_STREETSTALL_CLOSE;
CloseSyn.dwObjectID = pPlayer->GetID();
pOwnerStall->SendMsgGuestAll( &CloseSyn, sizeof(MSGBASE), TRUE );
StreetStallMode( pPlayer, NULL, FALSE );
DeleteStreetStall(pPlayer);
return;
}
}
BOOL cStreetStallManager::BuyItem( CPlayer* pOwner, cStreetStall* pStall, CPlayer* pGuest, STREETSTALL_BUYINFO* pBuyInfo )
{
POSTYPE pos = pBuyInfo->StallPos; // 畴痢俊辑狼 困摹
sCELLINFO* pItemInfo = pStall->GetCellInfo( pos );
ITEMBASE ItemBase = pItemInfo->sItemBase;
POSTYPE RealPos = ItemBase.Position; // 角力 酒捞袍 器瘤记
MONEYTYPE money = pItemInfo->dwMoney;
CInventorySlot* pGuestInventory = (CInventorySlot*)pGuest->GetSlot( eItemTable_Inventory );
CInventorySlot* pOwnerInventory = (CInventorySlot*)pOwner->GetSlot( eItemTable_Inventory );
MSG_WORD msgNack; // 坷幅 皋技瘤
MSG_LINKITEM DelSyn; // 畴痢惑俊辑狼 昏力 皋技瘤
MSG_SELLITEM sellMsg; // 林牢俊霸 焊郴绰 皋技瘤
MSG_ITEMEX buyMsg; // 颊丛俊霸 焊郴绰 皋技瘤
POSTYPE absPosOut;
WORD EmptyCellPos[1];
const ITEMBASE* pInvenItem;
if(CanBuyItem(pOwner, pGuest, pItemInfo, EmptyCellPos, pBuyInfo, &ItemBase) == FALSE)
goto ITEMBUY_FAILED;
absPosOut = EmptyCellPos[0]; // 货肺 盲况 持阑 镑
pInvenItem = pOwnerInventory->GetItemInfoAbs(pItemInfo->sItemBase.Position);
if(!CHKRT->ItemOf(pOwner, pInvenItem->Position, pInvenItem->wIconIdx,0,0,CB_EXIST|CB_ICONIDX))
{
goto ITEMBUY_FAILED;
}
if(!CHKRT->ItemOf(pGuest, absPosOut,0,0,0,CB_ICONIDX))
{
goto ITEMBUY_FAILED;
}
ITEMBASE temp;
if(pOwnerInventory->DeleteItemAbs(pOwner, RealPos, &temp, SS_LOCKOMIT) != EI_TRUE)
goto ITEMBUY_FAILED;
temp.Position = absPosOut;
if(pGuestInventory->InsertItemAbs(pGuest, absPosOut, &temp, SS_LOCKOMIT) != EI_TRUE)
{
//rollback
temp.Position = RealPos;
if(pOwnerInventory->InsertItemAbs(pOwner, RealPos, &temp) != EI_TRUE)
{
ASSERT(0);
goto ITEMBUY_FAILED;
}
goto ITEMBUY_FAILED;
}
// 可记 沥焊 眠啊 棺 昏力
if( ITEMMGR->IsOptionItem(ItemBase.wIconIdx, ItemBase.Durability ) )
{
pGuest->AddItemOption(pOwner->GetItemOption(ItemBase.Durability));
pOwner->RemoveItemOption(ItemBase.Durability);
}
pOwner->SetMoney( pItemInfo->dwMoney, MONEY_ADDITION, 0, eItemTable_Inventory, eMoneyLog_GetStreetStall, pGuest->GetID());
pGuest->SetMoney( pItemInfo->dwMoney, MONEY_SUBTRACTION, 0, eItemTable_Inventory, eMoneyLog_LoseStreetStall, pOwner->GetID());
ItemUpdateToDB( pGuest->GetID(), ItemBase.dwDBIdx ,ItemBase.wIconIdx, ItemBase.Durability, absPosOut, 0 );
// Log 林牢
LogItemMoney(pOwner->GetID(), pOwner->GetObjectName(), pGuest->GetID(), pGuest->GetObjectName(),
eLog_StreetStallBuyAll, pOwner->GetMoney(), pGuest->GetMoney(), pItemInfo->dwMoney,
temp.wIconIdx, temp.dwDBIdx, 0, temp.Position, temp.Durability, pOwner->GetPlayerExpPoint());
// 畴痢惑俊辑 昏力茄促.
pStall->EmptyCell( &ItemBase );
DelSyn.Category = MP_STREETSTALL;
DelSyn.Protocol = MP_STREETSTALL_DELETEITEM;
DelSyn.dwObjectID = pBuyInfo->dwObjectID;
DelSyn.ItemInfo = ItemBase;
DelSyn.wAbsPosition = pos;
pStall->SendMsgGuestAll( &DelSyn, sizeof(DelSyn) );
//////////////////////////////////////////////////////
// 林牢俊霸辑 酒捞袍阑 哗绊 捣阑 持绢 霖促./////////////////
sellMsg.Category = MP_STREETSTALL;
sellMsg.Protocol = MP_STREETSTALL_SELLITEM;
sellMsg.dwObjectID = pBuyInfo->StallOwnerID;
sellMsg.ItemInfo = ItemBase;
sellMsg.count = 0;
sellMsg.dwData = pBuyInfo->dwObjectID;
pOwner->SendMsg( &sellMsg, sizeof(sellMsg) );
/////////////////////////////////////////////////////////////
ItemBase.Position = absPosOut;
// 颊丛俊霸 酒捞袍阑 梅啊窍绊 捣阑 猾促.////////////////////
buyMsg.Category = MP_STREETSTALL;
buyMsg.Protocol = MP_STREETSTALL_BUYITEM_ACK;
buyMsg.dwObjectID = pBuyInfo->dwObjectID;
buyMsg.ItemInfo = ItemBase;
buyMsg.count = 0;
if( ITEMMGR->IsOptionItem(ItemBase.wIconIdx, ItemBase.Durability) )
{
buyMsg.sOptionInfo = *(pGuest->GetItemOption(ItemBase.Durability));
buyMsg.count = 1;
}
pGuest->SendMsg( &buyMsg, buyMsg.GetSize() );
/////////////////////////////////////////////////////////////
return TRUE;
ITEMBUY_FAILED:
msgNack.Category = MP_STREETSTALL;
msgNack.Protocol = MP_STREETSTALL_BUYITEM_NACK;
msgNack.dwObjectID = pBuyInfo->dwObjectID;
msgNack.wData = 0;
pGuest->SendMsg( &msgNack, sizeof(msgNack) );
return FALSE;
}
BOOL cStreetStallManager::BuyDupItem( CPlayer* pOwner, cStreetStall* pStall, CPlayer* pGuest, STREETSTALL_BUYINFO* pBuyInfo )
{
POSTYPE pos = pBuyInfo->StallPos; // 畴痢芒俊辑狼 困摹
sCELLINFO* pItemInfo = pStall->GetCellInfo( pos );
ITEMBASE ItemBase = pItemInfo->sItemBase;
POSTYPE RealPos = ItemBase.Position; // 角力 酒捞袍 器瘤记
WORD wBuyNum = pBuyInfo->ItemInfo.Durability;
MONEYTYPE money = pItemInfo->dwMoney*wBuyNum;
CInventorySlot* pGuestInventory = (CInventorySlot *)pGuest->GetSlot( eItemTable_Inventory );
CInventorySlot* pOwnerInventory = (CInventorySlot *)pOwner->GetSlot( eItemTable_Inventory );
WORD rt = NOT_ERROR;
POSTYPE absPosOut;
WORD EmptyCellPos[1];
MSG_WORD msgNack; // 坷幅 皋技瘤
MSG_LINKITEM DelSyn; // 畴痢惑俊辑狼 昏力 皋技瘤
MSG_SELLITEM sellMsg; // 林牢俊霸 焊郴绰 皋技瘤
MSG_ITEMEX buyMsg; // 颊丛俊霸 焊郴绰 皋技瘤
MSG_SELLITEM updateMsg; // 般摹扁 酒捞袍阑 荤绰 版快俊 措茄 贸府
const ITEMBASE* pInvenItem;
if( ItemBase.Durability < wBuyNum )
{
rt = NOT_EXIST;
goto ITEMBUY_FAILED;
}
if(CanBuyItem(pOwner, pGuest, pItemInfo, EmptyCellPos, pBuyInfo, &ItemBase) == FALSE)
goto ITEMBUY_FAILED;
absPosOut = EmptyCellPos[0];
pInvenItem = pOwnerInventory->GetItemInfoAbs(pItemInfo->sItemBase.Position);
if(!CHKRT->ItemOf(pOwner, pInvenItem->Position, pInvenItem->wIconIdx,0,0,CB_EXIST|CB_ICONIDX))
{
goto ITEMBUY_FAILED;
}
if(!CHKRT->ItemOf(pGuest, absPosOut,0,0,0,CB_ICONIDX))
{
goto ITEMBUY_FAILED;
}
if( ItemBase.Durability == wBuyNum )
{
ITEMBASE temp;
if(pOwnerInventory->DeleteItemAbs(pOwner, RealPos, &temp, SS_LOCKOMIT) != EI_TRUE)
goto ITEMBUY_FAILED;
temp.Position = absPosOut;
if(pGuestInventory->InsertItemAbs(pGuest, absPosOut, &temp, SS_LOCKOMIT) != EI_TRUE)
{
//rollback
temp.Position = RealPos;
if(pOwnerInventory->InsertItemAbs(pOwner, RealPos, &temp) != EI_TRUE)
{
ASSERT(0);
goto ITEMBUY_FAILED;
}
goto ITEMBUY_FAILED;
}
ItemUpdateToDB( pGuest->GetID(), temp.dwDBIdx ,temp.wIconIdx, temp.Durability, absPosOut, 0 );
LogItemMoney(pOwner->GetID(), pOwner->GetObjectName(), pGuest->GetID(), pGuest->GetObjectName(),
eLog_StreetStallBuyAll, pOwner->GetMoney(), pGuest->GetMoney(), money,
temp.wIconIdx, temp.dwDBIdx, temp.Position, absPosOut, temp.Durability, pOwner->GetPlayerExpPoint());
// 畴痢惑俊辑 昏力茄促.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -