215 lines
4.4 KiB
C++
215 lines
4.4 KiB
C++
#include "stdafx.h"
|
|
#include "SStorageMgr.h"
|
|
#include "SGame.h"
|
|
|
|
#include "SDebug_Util.h"
|
|
|
|
SStorageMgr::SStorageMgr()
|
|
: SGameUIMgr() // 2011.03.29 - servantes
|
|
, m_hDragItem( 0 )
|
|
, m_bIsOpen( false )
|
|
, m_nStorageMode( 0 )
|
|
, m_iMaxSlotNum( 0 )
|
|
, m_dwCheckLendingTime( 0 )
|
|
, m_nCheckCount( 0 )
|
|
{
|
|
|
|
}
|
|
|
|
SStorageMgr::~SStorageMgr()
|
|
{
|
|
Clear();
|
|
}
|
|
|
|
void SStorageMgr::Clear()
|
|
{
|
|
std::vector<SInventorySlot*>::iterator it = m_vecItemList.begin();
|
|
while( it != m_vecItemList.end() )
|
|
{
|
|
SAFE_DELETE( (*it) );
|
|
it = m_vecItemList.erase(it);
|
|
}
|
|
|
|
m_vecItemList.clear();
|
|
|
|
m_bIsOpen = false;
|
|
m_hDragItem = 0;
|
|
m_nStorageMode = 0;
|
|
}
|
|
|
|
void SStorageMgr::ResetInfo()
|
|
{
|
|
Clear();
|
|
}
|
|
|
|
int SStorageMgr::AddItem( TS_ITEM_INFO* pItemInfo )
|
|
{
|
|
for( unsigned int i = 0; i < m_vecItemList.size(); i++ )
|
|
{
|
|
if( m_vecItemList[i]->GetHandle() == pItemInfo->handle )
|
|
{
|
|
m_vecItemList[i]->SetItem( pItemInfo );
|
|
return static_cast<int>(m_vecItemList.size());
|
|
}
|
|
}
|
|
|
|
SInventorySlot* pInvenSlot = new SInventorySlot;
|
|
pInvenSlot->SetItem( pItemInfo );
|
|
m_vecItemList.push_back( pInvenSlot );
|
|
|
|
return (int)m_vecItemList.size();
|
|
}
|
|
|
|
void SStorageMgr::DeleteItem( AR_HANDLE hItem )
|
|
{
|
|
if( m_vecItemList.size() <= 0 )
|
|
{
|
|
return;
|
|
}
|
|
|
|
std::vector<SInventorySlot*>::iterator it = m_vecItemList.begin();
|
|
while( it != m_vecItemList.end() )
|
|
{
|
|
if( (*it)->GetHandle() == hItem )
|
|
{
|
|
SAFE_DELETE( (*it) );
|
|
_onEraseItem( m_vecItemList.erase(it) );
|
|
return;
|
|
}
|
|
it++;
|
|
}
|
|
}
|
|
void SStorageMgr::UpdateItemCount( AR_HANDLE hItem, count_t nCount )
|
|
{
|
|
if( m_vecItemList.size() <= 0 ) return;
|
|
|
|
std::vector<SInventorySlot*>::iterator it = m_vecItemList.begin();
|
|
while( it != m_vecItemList.end() )
|
|
{
|
|
SInventorySlot* pSlot = (*it);
|
|
if( pSlot && pSlot->GetHandle() == hItem )
|
|
{
|
|
(*it)->SetItemCount( nCount );
|
|
return;
|
|
}
|
|
it++;
|
|
}
|
|
}
|
|
|
|
void SStorageMgr::_onEraseItem( std::vector<SInventorySlot*>::iterator it )
|
|
{
|
|
for( ; it != m_vecItemList.end() ; ++it )
|
|
{
|
|
((*it)->GetItem())->index--;
|
|
}
|
|
}
|
|
|
|
bool SStorageMgr::IsExistItem( AR_HANDLE hItem )
|
|
{
|
|
for (int i = 0; i < static_cast<int>(m_vecItemList.size()); i++)
|
|
{
|
|
if (m_vecItemList[i]->GetHandle() == hItem)
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
bool SStorageMgr::IsExistItem( AR_HANDLE hItem, count_t nItemCount )
|
|
{
|
|
for (int i = 0; i < static_cast<int>(m_vecItemList.size()); i++)
|
|
{
|
|
if (m_vecItemList[i]->GetHandle() == hItem &&
|
|
m_vecItemList[i]->GetItemCount() >= nItemCount)
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
const count_t SStorageMgr::GetItemCount( AR_HANDLE hItem ) const
|
|
{
|
|
if( m_vecItemList.size() <= 0 ) return count_t( -1 );
|
|
|
|
std::vector<SInventorySlot*>::const_iterator it = m_vecItemList.begin();
|
|
while( it != m_vecItemList.end() )
|
|
{
|
|
SInventorySlot* pSlot = (*it);
|
|
if( pSlot && pSlot->GetHandle() == hItem )
|
|
{
|
|
return (*it)->GetItemCount();
|
|
}
|
|
it++;
|
|
}
|
|
|
|
return count_t( -1 );
|
|
}
|
|
|
|
SInventorySlot* SStorageMgr::GetItemInfo( AR_HANDLE hItem )
|
|
{
|
|
std::vector<SInventorySlot*>::iterator it = m_vecItemList.begin();
|
|
while( it != m_vecItemList.end() )
|
|
{
|
|
SInventorySlot* pSlot = (*it);
|
|
if( pSlot->GetHandle() == hItem )
|
|
return (*it);
|
|
|
|
++it;
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
void SStorageMgr::SortItemList()
|
|
{
|
|
struct TItemLess
|
|
{
|
|
//두인자가 같을 경우 무조건 false가 나오도록 해야한다. 흠 false가 바꾸는 것인데...
|
|
bool operator () ( SInventorySlot* a, SInventorySlot* b )
|
|
{
|
|
if( !a || !b ) return true;
|
|
|
|
TS_ITEM_INFO* pInfo_1 = a->GetItem();
|
|
TS_ITEM_INFO* pInfo_2 = b->GetItem();
|
|
if( !pInfo_1 || !pInfo_2 ) return true;
|
|
|
|
return pInfo_1->index < pInfo_2->index;
|
|
}
|
|
} pred;
|
|
|
|
std::sort( m_vecItemList.begin(), m_vecItemList.end(), pred );
|
|
}
|
|
|
|
void SStorageMgr::Process( DWORD time )
|
|
{
|
|
//대여 시간 처리
|
|
if( m_dwCheckLendingTime == 0 )
|
|
{
|
|
m_dwCheckLendingTime = time;
|
|
}
|
|
else
|
|
{
|
|
if( (time - m_dwCheckLendingTime) >= CHECK_LENDING_TIME )
|
|
{ //대여 아이템 갱신
|
|
m_dwCheckLendingTime = time;
|
|
|
|
++m_nCheckCount;
|
|
for ( unsigned int i(0); m_vecItemList.size()>i; i++ )
|
|
{
|
|
if (( m_vecItemList[i]->GetItem()->elemental_effect_type != 0 ) &&
|
|
( m_vecItemList[i]->GetItem()->elemental_effect_remain_time > 0 ))
|
|
--m_vecItemList[i]->GetItem()->elemental_effect_remain_time;
|
|
|
|
if( m_vecItemList[i]->GetItem()->remain_time > 0 )
|
|
--m_vecItemList[i]->GetItem()->remain_time;
|
|
}
|
|
|
|
if( m_nCheckCount >= 60 )
|
|
{
|
|
m_nCheckCount = 0;
|
|
ProcMsgAtStatic( &(SIMSG_UI_STATE_UPDATE(SIMSG_TOGGLE_UIWINDOW::UIWINDOW_STORAGE)) );
|
|
}
|
|
}
|
|
}
|
|
}
|