// WarehouseSlotContainer.cpp: implementation of the CWarehouseSlotContainer class. // ////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "WarehouseSlotContainer.h" #include "Player.h" #include #include "ItemManager.h" #include "FunctionalRestrictManager.h" #include "StatisticsManager.h" #include "GameServerEx.h" #include "ChaoState.h" #include ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// CWarehouseSlotContainer::CWarehouseSlotContainer() : m_pPlayer(NULL) , m_Money(0) , m_bChanged(false) , m_bStarted(false) { Init(MAX_WAREHOUSE_SLOT_NUM, SI_WAREHOUSE); } CWarehouseSlotContainer::~CWarehouseSlotContainer() { } void CWarehouseSlotContainer::ClearAll() { SCItemSlotContainer::ClearAll(); m_Money = 0; m_bChanged = false; m_bStarted = false; } BOOL CWarehouseSlotContainer::ValidState() { if( SCItemSlotContainer::ValidState() ) { ProtectorWarehouse& rPROTECT = m_pPlayer->GetWarehouseInventoryProtector().WAREHOUSE(); if( !rPROTECT.IsUsable() ) return FALSE; return IsEnableService(); } return FALSE; } BOOL CWarehouseSlotContainer::IsEnableService() { if( m_pPlayer->GetChaoState().IsChaoState() ) return FALSE; return g_FunctionalRestrictMgr.IsPossibleFunction( eFUNCTIONALRESTRICT_USE_WAREHOUSE ); } BOOL CWarehouseSlotContainer::DepositMoney( MONEY PlusMoney ) { if( !IsStarted() || !IsEnableService() ) return FALSE; m_Money += PlusMoney; m_bChanged = true; // g_pGameServer->PlusWareMoneyPlus( PlusMoney ); g_StatisticsManager.PlusStatisticType( eSTATISTIC_MONEY_WAREHOUSE_PLUS, PlusMoney ); return TRUE; } BOOL CWarehouseSlotContainer::WithDrawMoney( MONEY MinusMoney ) { if(!IsStarted() || !IsEnableService()) return FALSE; if( m_Money < MinusMoney ) return FALSE; m_Money -= MinusMoney; m_bChanged = true; // g_pGameServer->MinusWareMoneyMinus( MinusMoney ); g_StatisticsManager.PlusStatisticType( eSTATISTIC_MONEY_WAREHOUSE_MINUS, MinusMoney ); return TRUE; } VOID CWarehouseSlotContainer::StartWarehouse() { nsSlot::ItemManagerUpdateImpl* const item_updater_impl = m_pPlayer->GetItemManager()->GetUpdaterImpl(); for(POSTYPE i=0;iAddSerialCode( eSERIAL_WAREHOUSE_START, GetSlotIdx(), i, ((SCItemSlot&)GetSlot(i)).GetWorldSerial() ); } } m_bStarted = true; } VOID CWarehouseSlotContainer::EndWarehouse() { nsSlot::ItemManagerUpdateImpl* const item_updater_impl = m_pPlayer->GetItemManager()->GetUpdaterImpl(); for(POSTYPE i=0;iRemoveExpirationItem( rSlot ); item_updater_impl->RemoveSerialCode( GetSlotIdx(), i, rSlot.GetWorldSerial() ); } } ClearAll(); } BOOL CWarehouseSlotContainer::SaveWarehouseToDBP() { // ½ÃÀÛ ¾ÈµÇ¾îÀÖÀ¸¸é return if( !IsStarted() ) return FALSE; // blockedµÈ ½ÃÁ¡¿¡ ¾ÆÀÌÅÛ º¯°æÀÌ ÀϾÁö ¾ÊÀ¸¸é, ´Ù½Ã â°í¸¦ ¿­¾úÀ» ¶§, // blockedÀÌ ¾ÈµÇ°í, »óÁ¡¿¡ ÆÈ ¼ö Àֱ⠶§¹®¿¡! // º¯°æÀÌ ¾øÀ¸¸é return //if( !m_bChanged ) return TRUE; MSG_DG_CHARINFO_WAREHOUSE_CMD cmsg; cmsg.m_dwKey = m_pPlayer->GetUserKey(); cmsg.char_guid_ = m_pPlayer->GetCharGuid(); // f101021.2L cmsg.m_ChannelID = g_pGameServer->GetKey().GetChannelID(); cmsg.m_WarehouseMoney = GetCurMoney(); SerializeItemInfo( cmsg.m_ItemInfo, SERIALIZE_LOAD ); BOOL rt = m_pPlayer->SendToGameDBPServer( &cmsg, cmsg.GetSize() ); ASSERT( rt && "DB·Î º¸³¾ ¼ö ¾ø½À´Ï´Ù." ); m_bChanged = false; return TRUE; } //#include RC::eSLOT_INSERT_RESULT CWarehouseSlotContainer::InsertSlot( POSTYPE AtPos, SCSlot & IN rSlot ) { if( !IsStarted() || !IsEnableService() ) return RC::RC_INSERT_SLOT_DISABLE_SERVICE; RC::eSLOT_INSERT_RESULT rt = SCSlotContainer::InsertSlot( AtPos, rSlot ); if( RC::RC_INSERT_SLOT_SUCCESS == rt ) { SCItemSlot & rCurSlot = (SCItemSlot &)GetSlot(AtPos); if (nsSlot::ItemManagerUpdateImpl* const item_updater_impl = m_pPlayer->GetItemManager()->GetUpdaterImpl()) { item_updater_impl->AddSerialCode( eSERIAL_WAREHOUSE, GetSlotIdx(), AtPos, rCurSlot.GetWorldSerial() ); } m_bChanged = true; } return rt; } BOOL CWarehouseSlotContainer::DeleteSlot( POSTYPE AtPos, SCSlot * pSlotOut ) { if( !IsStarted() || !IsEnableService() ) return FALSE; SCItemSlot TmpDeleteItemSlot; BOOL rt = SCSlotContainer::DeleteSlot( AtPos, &TmpDeleteItemSlot ); if( rt ) { if( pSlotOut ) { ((SCItemSlot*)pSlotOut)->Copy(TmpDeleteItemSlot); } /* static char buff[128]; std::string itemInfo = "â°íÀ¯Àú:"; itemInfo += m_pPlayer->GetCharName(); itemInfo += ",item»èÁ¦:"; itemInfo += tmpItemSlot.GetItemInfo()->m_pszName; itemInfo += "pos("; itemInfo += _itoa(AtPos, buff, 10 ); itemInfo += "),"; itemInfo += "code("; itemInfo += _itoa(tmpItemSlot.GetItemCode(), buff, 10 ); itemInfo += ")"; SUNLOG( eFULL_LOG, const_cast(itemInfo.c_str()) );*/ if (nsSlot::ItemManagerUpdateImpl* const item_updater_impl = m_pPlayer->GetItemManager()->GetUpdaterImpl()) { item_updater_impl->RemoveSerialCode( GetSlotIdx(), AtPos, TmpDeleteItemSlot.GetWorldSerial() ); } m_bChanged = true; } return rt; } //VOID CWarehouseSlotContainer::UpdateSlot( POSTYPE AtPos, eSlotType type, DBSERIAL serial, SLOTCODE code, POSTYPE quickPos, DURATYPE dura, BYTE level, eUPDATE_BIT upbits ) //{ // SCSlotContainer::UpdateSlot( AtPos, type, serial, code, quickPos, dura, level, upbits ); // m_bChanged = true; //} // //VOID CWarehouseSlotContainer::UpdateSlot( POSTYPE AtPos, SCSlot & IN rSlot ) //{ // SCItemSlotContainer::UpdateSlot( AtPos, rSlot ); // m_bChanged = true; //} // ·Î±× ±â·Ï¿ëÀ¸·Î ¸¸µë VOID CWarehouseSlotContainer::SerializeItemInfo( BYTE * pStream, WORD wSize, eSERIALIZE eType ) { ASSERT( wSize >= MAX_WAREHOUSESTREAM_SIZE ); if( eType == SERIALIZE_LOAD ) { memset( pStream, 0, wSize ); ITEMSTREAMEX * pStreamEx = (ITEMSTREAMEX *)pStream; for(POSTYPE i=0;i(rSlot); // CHANGES: f110106.3L, added the rule to solve a problem by external GM control // in this case, it's possible when a 'pet' or 'rider' item is summoned. // a calling case of OnInsert can prevent by other game rules. if (item_slot.IsUserBlocked()) { item_slot.SetUserBlocked(false); }; if (nsSlot::ItemManagerUpdateImpl* const item_updater_impl = m_pPlayer->GetItemManager()->GetUpdaterImpl()) { item_updater_impl->AddExpirationItem(item_slot); } } void CWarehouseSlotContainer::OnDelete( SCSlot & IN rSlot ) { if (nsSlot::ItemManagerUpdateImpl* const item_updater_impl = m_pPlayer->GetItemManager()->GetUpdaterImpl()) { item_updater_impl->RemoveExpirationItem( (SCItemSlot &)rSlot ); } } //================================================================================================== // (f100527.4L) WAREHOUSE_TOTAL_INFO_TYPE = { _WAREHOUSE_TOTAL_INFO } //template void CWarehouseSlotContainer::SerializeItemInfo(_WAREHOUSE_TOTAL_INFO& total_info, eSERIALIZE serialize_type) { POSTYPE number_of_max_slots = GetMaxSlotNum(); if (number_of_max_slots > MAX_WAREHOUSE_SLOT_NUM) { SUNLOG(eCRITICAL_LOG, _T("[CWarehouseSlotContainer] Invalid MaxSlotNum[%d/%d]"), number_of_max_slots, MAX_WAREHOUSE_SLOT_NUM); SetMaxSlotNum(MAX_WAREHOUSE_SLOT_NUM); number_of_max_slots = GetMaxSlotNum(); } // if (serialize_type == SERIALIZE_LOAD) { total_info.m_Count = 0; _WAREHOUSE_TOTAL_INFO::SLOT_TYPE* slot_it = total_info.m_Slot; for (POSTYPE pos = 0; pos < number_of_max_slots; ++pos) { if (IsEmpty(pos)) { continue; } slot_it->m_Pos = pos; SCItemSlotContainer::SerializeItemStream(slot_it->m_Pos, &slot_it->m_Stream, serialize_type); ++total_info.m_Count; ++slot_it; } } else if (serialize_type == SERIALIZE_STORE) { ASSERT(GetSlotNum() == 0); _WAREHOUSE_TOTAL_INFO::SLOT_TYPE* slot_it = total_info.m_Slot; for (POSTYPE total_count = total_info.m_Count; total_count; --total_count, ++slot_it) { SCItemSlotContainer::SerializeItemStream(slot_it->m_Pos, &slot_it->m_Stream, serialize_type); } m_bChanged = false; } }