📄 streetstall.cpp
字号:
#include "stdafx.h"
#include "StreetStall.h"
#include "usertable.h"
#include "Player.h"
#include "objectstatemanager.h"
#include "itemmanager.h"
cStreetStall::cStreetStall()
{
Init();
}
cStreetStall::~cStreetStall()
{
m_pOwner = NULL;
m_GuestList.RemoveAll();
// EmptyCellAll();
}
void cStreetStall::Init()
{
m_pOwner = NULL;
m_nCurRegistItemNum = 0;
EmptyCellAll();
DeleteGuestAll();
}
BOOL cStreetStall::FillCell( ITEMBASE* pBase, DWORD money, BOOL bLock )
{
WORD pos;
if(!m_pOwner)
{
return FALSE;
}
CItemSlot* pSlot = m_pOwner->GetSlot(pBase->Position);
if( !pSlot )
{
ASSERT(0);
return TRUE;
}
for(int n = 0; n<MAX_STREETSTALL_CELLNUM;++n)
{
if( !m_sArticles[n].bFill )
break;
}
pos = n;
if( pos == MAX_STREETSTALL_CELLNUM ) return FALSE;
if( pBase->wIconIdx == 0 ) return FALSE;
m_sArticles[pos].bFill = TRUE;
m_sArticles[pos].bLock = bLock;
m_sArticles[pos].sItemBase = *pBase;
m_sArticles[pos].dwMoney = money;
++m_nCurRegistItemNum;
pSlot->SetLock(pBase->Position, bLock);
return TRUE;
}
void cStreetStall::EmptyCell( ITEMBASE* pBase )
{
WORD pos;
BOOL bSetItemSlot = TRUE;
CItemSlot* pSlot;
if( m_pOwner )
{
pSlot = m_pOwner->GetSlot(eItemTable_Inventory);
if( !pSlot )
{
ASSERT(0);
bSetItemSlot = FALSE;
}
}
else
bSetItemSlot = FALSE;
for(int n = 0; n<MAX_STREETSTALL_CELLNUM;++n)
{
if( m_sArticles[n].bFill )
{
if(m_sArticles[n].sItemBase.dwDBIdx == pBase->dwDBIdx)
break;
}
}
pos = n;
if( pos == MAX_STREETSTALL_CELLNUM ) return;
if( !m_sArticles[pos].bFill ) return; // 捞固 厚况廉 乐促..
pSlot->SetLock(m_sArticles[pos].sItemBase.Position, FALSE);
m_sArticles[pos].Init();
/* Bugs code!!!!!!
for( int i = pos ; i < MAX_STREETSTALL_CELLNUM-1 ; ++i )
{
if( !m_sArticles[i+1].bFill )
{
m_sArticles[i].Init();
break;
}
m_sArticles[i] = m_sArticles[i+1];
}
*/
for( int i = pos ; i < MAX_STREETSTALL_CELLNUM-1 ; ++i )
{
if( !m_sArticles[i+1].bFill )
break;
m_sArticles[i] = m_sArticles[i+1];
m_sArticles[i+1].Init();
}
--m_nCurRegistItemNum;
}
void cStreetStall::UpdateCell( WORD pos, DURTYPE dur )
{
if( pos > MAX_STREETSTALL_CELLNUM ) return;
if( !m_sArticles[pos].bFill ) return;
m_sArticles[pos].sItemBase.Durability = dur;
}
void cStreetStall::EmptyCellAll()
{
BOOL bSetItemSlot = TRUE;
CItemSlot* pSlot;
if( m_pOwner )
{
pSlot = m_pOwner->GetSlot(eItemTable_Inventory);
if( !pSlot )
{
ASSERT(0);
bSetItemSlot = FALSE;
}
}
else
bSetItemSlot = FALSE;
for(int i=0;i<MAX_STREETSTALL_CELLNUM;++i)
{
if( !m_sArticles[i].bFill ) break;
if( bSetItemSlot )
pSlot->SetLock(m_sArticles[i].sItemBase.Position, FALSE);
m_sArticles[i].Init();
m_sArticles[i].dwMoney = 0;
}
m_nCurRegistItemNum = 0;
}
void cStreetStall::SetMoney( WORD pos, DWORD money )
{
if( pos > MAX_STREETSTALL_CELLNUM ) return; // 肮荐甫 檬苞茄促??
if( !m_sArticles[pos].bFill ) return; // 厚况廉 乐促..
if( m_sArticles[pos].bLock ) return;
m_sArticles[pos].dwMoney = money;
}
void cStreetStall::ChangeCellState( WORD pos, BOOL bLock ) // (林狼)殿废苞绰 促福霸 硅凯狼 牢郸胶啊 逞绢柯促.
{
if(!m_pOwner)
{
return;
}
if( pos > MAX_STREETSTALL_CELLNUM ) return; // 肮荐甫 檬苞茄促??
if( !m_sArticles[pos].bFill ) return; // 厚况廉 乐促..
if( m_sArticles[pos].bLock == bLock ) return;
CItemSlot* pSlot = m_pOwner->GetSlot(m_sArticles[pos].sItemBase.Position);
if( !pSlot )
{
ASSERT(0);
return;
}
pSlot->SetLock(m_sArticles[pos].sItemBase.Position, bLock);
m_sArticles[pos].bLock = bLock;
}
void cStreetStall::AddGuest( CPlayer* pGuest )
{
if( m_GuestList.Find(pGuest) ) return;
pGuest->SetGuestStall( this );
m_GuestList.AddTail( pGuest );
}
void cStreetStall::DeleteGuest( CPlayer* pGuest )
{
pGuest->SetGuestStall( NULL );
if( m_GuestList.Find(pGuest) == FALSE ) return;
m_GuestList.Remove( pGuest );
}
void cStreetStall::DeleteGuestAll()
{
PTRLISTPOS pos = m_GuestList.GetHeadPosition();
while(pos)
{
CPlayer* pGuest = (CPlayer*)m_GuestList.GetNext( pos );
pGuest->SetGuestStall( NULL );
}
m_GuestList.RemoveAll();
}
void cStreetStall::GetStreetStallInfo( STREETSTALL_INFO& stall )
{
for(int i=0;i<MAX_STREETSTALL_CELLNUM;++i)
{
stall.Item[i].wIconIdx = m_sArticles[i].sItemBase.wIconIdx;
stall.Item[i].dwDBIdx = m_sArticles[i].sItemBase.dwDBIdx;
stall.Item[i].Durability = m_sArticles[i].sItemBase.Durability;
stall.Item[i].money = m_sArticles[i].dwMoney;
stall.Item[i].Locked = m_sArticles[i].bLock;
stall.Item[i].Fill = m_sArticles[i].bFill;
if( stall.Item[i].Fill )
{
if( ITEMMGR->IsOptionItem(stall.Item[i].wIconIdx, stall.Item[i].Durability) )
{ // 可记 酒捞袍牢 版快
stall.sOption[stall.count] = *(GetOwner()->GetItemOption(stall.Item[i].Durability));
stall.count++;
}
}
}
if( m_pOwner )
m_pOwner->GetStreetStallTitle(stall.Title);
}
BOOL cStreetStall::CheckItemDBIdx(DWORD idx)
{
for(int i=0;i<MAX_STREETSTALL_CELLNUM;++i)
{
if( m_sArticles[i].bFill )
{
if( m_sArticles[i].sItemBase.dwDBIdx == idx)
return FALSE;
}
}
return TRUE;
}
BOOL cStreetStall::IsFull()
{
for(int i=0;i<MAX_STREETSTALL_CELLNUM;++i)
{
if( !m_sArticles[i].bFill )
return FALSE;
}
return TRUE;
}
/* 颊丛狼 惑怕 函版 Flag 眠啊 03.12.26 */
void cStreetStall::SendMsgGuestAll( MSGBASE* pMsg, int nMsgLen, BOOL bChangeState )
{
PTRLISTPOS pos = m_GuestList.GetHeadPosition();
while(pos)
{
CPlayer* pGuest = (CPlayer*)m_GuestList.GetNext( pos );
if( !pGuest )
continue;
pGuest->SendMsg( pMsg, nMsgLen);
if( bChangeState )
{
if( pGuest->GetState() == eObjectState_StreetStall_Guest)
OBJECTSTATEMGR_OBJ->EndObjectState(pGuest, eObjectState_StreetStall_Guest);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -