Files
2026-06-01 12:46:52 +02:00

375 lines
6.9 KiB
C++

#include "stdafx.h"
#include "SStoreMgr.h"
#include "SGame.h"
#include <assert.h>
#include "SDebug_Util.h"
const size_t DEFAULT_ADD_COUNT = 8; // 기본적으로 올릴 수 있는 아이템 갯수
SStoreMgr & SStoreMgr::GetInstance()
{
static SStoreMgr inst;
return inst;
}
int SStoreMgr::AddItem( STORE_ITEM info )
{
// 갯수 초과
if( m_vItemList.size() >= DEFAULT_ADD_COUNT ) return 0; // TODO : 나중에 캐릭터 상태에 따라 DEFAULT_ADD_COUNT 이 변화됨. (ex:상인캐릭터는 더 많이 올릴 수 있다)
// 이미 존재하면 업데이트만..
if( info.handle )
{
int Cnt(0);
for( std::vector< STORE_ITEM >::iterator it = m_vItemList.begin(); it != m_vItemList.end(); ++it )
{
++Cnt;
if( (*it).handle != info.handle ) continue;
(*it) = info;
arrangeIndex();
return Cnt;
}
}
m_vItemList.push_back( info );
arrangeIndex();
return m_vItemList.size();
}
void SStoreMgr::RemoveItem( ItemBase::ItemCode code )
{
for( std::vector< STORE_ITEM >::iterator it = m_vItemList.begin(); it != m_vItemList.end(); ++it )
{
if( (*it).Code != code ) continue;
m_vItemList.erase( it );
break;
}
arrangeIndex();
}
void SStoreMgr::RemoveItem( AR_HANDLE handle )
{
for( std::vector< STORE_ITEM >::iterator it = m_vItemList.begin(); it != m_vItemList.end(); ++it )
{
if( (*it).handle != handle ) continue;
m_vItemList.erase( it );
break;
}
arrangeIndex();
}
void SStoreMgr::SetItemCount( AR_HANDLE hItem, count_t count )
{
for( std::vector< STORE_ITEM >::iterator it = m_vItemList.begin(); it != m_vItemList.end(); ++it )
{
if( (*it).handle != hItem ) continue;
(*it).count = count.getAmount();
if( !count ) m_vItemList.erase( it );
return;
}
}
void SStoreMgr::ChangeItemPrice( size_t idx, money_t nPrice )
{
if( idx >= m_vItemList.size() || idx < 0 ) return;
m_vItemList[idx].gold = nPrice.getAmount();
}
void SStoreMgr::ChangeItemCount( size_t idx, count_t nCnt )
{
if( idx >= m_vItemList.size() || idx < 0 ) return;
m_vItemList[idx].count = nCnt.getAmount();
}
void SStoreMgr::DecItemCount( AR_HANDLE hItem, count_t count )
{
for( std::vector< STORE_ITEM >::iterator it = m_vItemList.begin(); it != m_vItemList.end(); ++it )
{
if( (*it).handle != hItem ) continue;
SetItemCount( hItem, count_t( (*it).count - count.getAmount() ) );
return;
}
}
void SStoreMgr::arrangeIndex()
{
for( unsigned i = 0; i < m_vItemList.size(); ++i ) m_vItemList[i].nIdx = i;
}
STORE_ITEM SStoreMgr::GetBoothItemInfo( size_t idx )
{
if( idx >= m_vItemList.size() || idx < 0 )
{
assert( false );
static STORE_ITEM store_item;
return store_item;
}
return m_vItemList[idx];
}
void SStoreMgr::Clear() { m_vItemList.clear(); }
XFlag< int > SStoreMgr::GetItemFlag( size_t idx ) const
{
XFlag<int> flag;
if( idx >= m_vItemList.size() || idx < 0 )
{
assert( false );
return flag;
}
flag.CopyFrom( &m_vItemList[idx].Flag );
return flag;
}
size_t SStoreMgr::GetListCount() const
{
return m_vItemList.size();
}
int SStoreMgr::GetEnhance( size_t idx ) const
{
if( idx >= m_vItemList.size() || idx < 0 )
{
assert( false );
return -1;
}
return m_vItemList[idx].enhance;
}
int SStoreMgr::GetLevel( size_t idx ) const
{
if( idx >= m_vItemList.size() || idx < 0 )
{
assert( false );
return -1;
}
return m_vItemList[idx].level;
}
int SStoreMgr::GetEndurance( size_t idx ) const
{
if( idx >= m_vItemList.size() || idx < 0 )
{
assert( false );
return -1;
}
return m_vItemList[idx].endurance;
}
ItemBase::ItemCode SStoreMgr::GetItemCode( size_t idx ) const
{
if( idx >= m_vItemList.size() || idx < 0 )
{
assert( false );
return -1;
}
return m_vItemList[idx].Code;
}
count_t SStoreMgr::GetItemCount( size_t idx ) const
{
if( idx >= m_vItemList.size() || idx < 0 )
{
assert( false );
return count_t( -1 );
}
return count_t( m_vItemList[idx].count );
}
money_t SStoreMgr::GetItemPrice( size_t idx ) const
{
if( idx >= m_vItemList.size() || idx < 0 )
{
assert( false );
return money_t( -1 );
}
return money_t( m_vItemList[idx].gold );
}
AR_HANDLE SStoreMgr::GetItemHandle( size_t idx ) const
{
if( idx >= m_vItemList.size() || idx < 0 )
{
assert( false );
return 0;
}
return m_vItemList[idx].handle;
}
int SStoreMgr::GetItemRemainTime( size_t idx ) const
{
if( idx >= m_vItemList.size() || idx < 0 )
{
assert( false );
return -1;
}
return m_vItemList[idx].remain_time;
}
int* SStoreMgr::GetItemSocket( size_t idx )
{
if( idx >= m_vItemList.size() || idx < 0 )
{
assert( false );
return NULL;
}
return &m_vItemList[idx].socket[0];
}
// tooltip 수정
// 2009-02-05: hunee
int SStoreMgr::GetItemElementalEffectType( size_t idx ) const
{
if( idx >= m_vItemList.size() || idx < 0 )
{
assert( false );
return -1;
}
return m_vItemList[idx].elemental_effect_type;
}
int SStoreMgr::GetItemElementalEffectRemainTime( size_t idx ) const
{
if( idx >= m_vItemList.size() || idx < 0 )
{
assert( false );
return -1;
}
return m_vItemList[idx].elemental_effect_remain_time;
}
int SStoreMgr::GetItemElementalEffectAttackPoint( size_t idx ) const
{
if( idx >= m_vItemList.size() || idx < 0 )
{
assert( false );
return -1;
}
return m_vItemList[idx].elemental_effect_attack_point;
}
int SStoreMgr::GetItemElementalEffectMagicPoint( size_t idx ) const
{
if( idx >= m_vItemList.size() || idx < 0 )
{
assert( false );
return -1;
}
return m_vItemList[idx].elemental_effect_magic_point;
}
// bintitle 추가. 2010.03.17
int SStoreMgr::GetEtherealDurability( size_t idx ) const
{
if( idx >= m_vItemList.size() || idx < 0 )
{
assert( false );
return -1;
}
return m_vItemList[idx].ethereal_durability;
return 0;
}
int SStoreMgr::GetItemAppearanceCode(size_t idx) const
{
if( idx >= m_vItemList.size() || idx < 0 )
{
assert( false );
return -1;
}
return m_vItemList[idx].appearance_code;
return 0;
}
bool SStoreMgr::IsSellMode() const
{
return m_bIsSellMode;
}
void SStoreMgr::SwitchStoreMode( bool bIsSellMode )
{
// 모드가 바뀌면 기존 리스트 날림
if( m_bIsSellMode != bIsSellMode ) m_vItemList.clear();
m_bIsSellMode = bIsSellMode;
}
TS_ITEM_BASE_INFO::AwakenOption* SStoreMgr::GetAwakening( size_t idx )
{
if( idx >= m_vItemList.size() || idx < 0 )
{
assert( false );
return NULL;
}
return &(m_vItemList[idx].awakenoption);
}
TS_ITEM_BASE_INFO::LPRANDOM_OPTION SStoreMgr::GetRandomOption( size_t idx )
{
if( idx >= m_vItemList.size() || idx < 0 )
{
assert( false );
return NULL;
}
return &(m_vItemList[idx].random_option);
}
int SStoreMgr::GetSummonID( size_t idx )
{
if( idx >= m_vItemList.size() || idx < 0 )
{
assert( false );
return NULL;
}
return m_vItemList[idx].summon_id;
}
// Fraun Sky Accessories 7/12/2025
int SStoreMgr::GetAdditionalItemEffect( size_t idx )
{
if( idx >= m_vItemList.size() || idx < 0 )
{
assert( false );
return NULL;
}
return m_vItemList[idx].nAdditionalItemEffect;
}