📄 timelimititemmanager.cpp
字号:
#include "TimeLimitItemManager.h"#include "DB.h"#include "Item.h"#include "PlayerCreature.h"#include "Gpackets/GCTimeLimitItemInfo.h"TimeLimitItemManager::~TimeLimitItemManager(){ TableRecordList::iterator itr = m_TableRecords.begin(); for ( ; itr != m_TableRecords.end() ; ++itr ) { SAFE_DELETE( *itr ); } m_TableRecords.clear(); m_ItemTimeLimits.clear(); m_loaded = false;}void TimeLimitItemManager::load() throw(Error){ __BEGIN_TRY Statement* pStmt = NULL; BEGIN_DB { pStmt = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement(); Result* pResult = pStmt->executeQuery( "SELECT ItemClass, ItemID, LimitDateTime from TimeLimitItems where OwnerID='%s' and Status=%u", m_pOwnerPC->getName().c_str(), (uint)VALID ); while( pResult->next() ) { TableRecord* pTableRecord = new TableRecord; pTableRecord->m_ItemClass = (Item::ItemClass)pResult->getInt(1); pTableRecord->m_ItemID = pResult->getInt(2); const string limitDateTime = pResult->getString(3); pTableRecord->m_TimeLimit = VSDateTime( limitDateTime ); m_TableRecords.push_back( pTableRecord ); } SAFE_DELETE(pStmt); } END_DB(pStmt) m_loaded = true; __END_CATCH}// 酒捞袍阑 抛捞喉苞 厚背秦辑 坷宏璃飘 酒捞叼甫 殿废秦霖促.// true 啊 府畔瞪 版快 坷宏璃飘 酒捞叼啊 殿废等促.// false 啊 府畔瞪 版快 坷宏璃飘啊 酒捞叼啊 殿废登瘤 臼栏骨肺 m_ItemTimeLimits[pItem->ObjectID()] 绰// 抗寇啊 惯积茄促.bool TimeLimitItemManager::registerItem( Item* pItem ) throw(Error){ __BEGIN_TRY if ( m_ItemTimeLimits.find( pItem->getObjectID() ) != m_ItemTimeLimits.end() ) return false; TableRecordList::iterator itr = m_TableRecords.begin(); TableRecordList::iterator endItr = m_TableRecords.end(); for ( ; itr != endItr ; ++itr ) { TableRecord* pTableRecord = *itr; if ( pTableRecord != NULL ) { if ( pTableRecord->m_ItemClass == pItem->getItemClass() && pTableRecord->m_ItemID == pItem->getItemID() ) { m_ItemTimeLimits[ pItem->getObjectID() ] = pTableRecord->m_TimeLimit; pItem->setTimeLimitItem(); return true; } } } return false; __END_CATCH}bool TimeLimitItemManager::checkTimeLimit( Item* pItem ) throw(Error){ __BEGIN_TRY Assert( m_loaded ); ObjectID_t objectID = pItem->getObjectID(); ItemTimeLimitMap::iterator itr = m_ItemTimeLimits.find( objectID ); if ( itr == m_ItemTimeLimits.end() ) { if ( !registerItem( pItem ) ) { // 矫埃力茄 酒捞袍捞 酒聪促. // 溜 矫埃力茄 公力茄捞促. ぞぞ return true; } } VSDateTime currentTime = VSDateTime::currentDateTime(); if ( currentTime > m_ItemTimeLimits[ objectID ] ) { cout << pItem->toString() << " 矫埃力茄 檬苞 : " << currentTime.toString() << " > " << m_ItemTimeLimits[ objectID ].toString() << endl; // 矫埃 力茄捞 瘤车促. return false; } return true; __END_CATCH}bool TimeLimitItemManager::wasteIfTimeOver( Item* pItem ) throw(Error){ __BEGIN_TRY if ( checkTimeLimit( pItem ) ) return false; Statement* pStmt = NULL; BEGIN_DB { pStmt = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement(); pStmt->executeQuery( "UPDATE TimeLimitItems SET Status=%u where OwnerID='%s' and ItemClass=%u and ItemID=%u", (uint)EXPIRED, m_pOwnerPC->getName().c_str(), (uint)pItem->getItemClass(), (uint)pItem->getItemID() ); if ( pStmt->getAffectedRowCount() == 0 ) { SAFE_DELETE(pStmt); return false; } SAFE_DELETE(pStmt); } END_DB(pStmt) return true; __END_CATCH}bool TimeLimitItemManager::makeTimeLimitItemInfo( GCTimeLimitItemInfo& gcTLII ) const throw(Error){ __BEGIN_TRY Assert( m_loaded ); if ( m_ItemTimeLimits.empty() ) return false;// gcTLII.clear(); VSDateTime currentTime = VSDateTime::currentDateTime(); ItemTimeLimitMap::const_iterator itr = m_ItemTimeLimits.begin(); ItemTimeLimitMap::const_iterator endItr = m_ItemTimeLimits.end(); for ( ; itr != endItr ; ++itr ) { int diffSecs = currentTime.secsTo( itr->second ); if ( diffSecs < 0 ) diffSecs = 0; gcTLII.addTimeLimit( itr->first, diffSecs ); } return true; __END_CATCH}// 馆靛矫 粮俊 酒捞袍阑 殿废茄 饶俊 龋免秦具 茄促.void TimeLimitItemManager::addTimeLimitItem( Item* pItem, DWORD time ) throw(Error){ __BEGIN_TRY Assert( pItem != NULL ); Assert( time != 0 ); VSDateTime timeLimit = VSDateTime::currentDateTime().addSecs(time); Statement* pStmt = NULL; BEGIN_DB { pStmt = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement(); pStmt->executeQuery( "INSERT INTO TimeLimitItems (OwnerID, ItemClass, ItemID, LimitDateTime) VALUES ('%s',%u,%u,'%s')", m_pOwnerPC->getName().c_str(), (uint)pItem->getItemClass(), (uint)pItem->getItemID(), timeLimit.toDateTime().c_str() ); SAFE_DELETE(pStmt); } END_DB(pStmt) TableRecord* pTableRecord = new TableRecord; pTableRecord->m_ItemClass = pItem->getItemClass(); pTableRecord->m_ItemID = pItem->getItemID(); pTableRecord->m_TimeLimit = timeLimit; m_TableRecords.push_back( pTableRecord ); registerItem( pItem ); __END_CATCH}// 皋葛府俊 乐绰 局绰 老窜 酒流 矫埃捞 巢篮 逞捞促.bool TimeLimitItemManager::changeStatus( Item* pItem, TimeLimitStatus status ) throw(Error){ __BEGIN_TRY Assert( status != VALID ); Statement* pStmt = NULL; BEGIN_DB { pStmt = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement(); pStmt->executeQuery( "UPDATE TimeLimitItems SET Status=%u where OwnerID='%s' and ItemClass=%u and ItemID=%u", (uint)status, m_pOwnerPC->getName().c_str(), (uint)pItem->getItemClass(), (uint)pItem->getItemID() ); if ( pStmt->getAffectedRowCount() == 0 ) { SAFE_DELETE(pStmt); return false; } SAFE_DELETE(pStmt); } END_DB(pStmt) TableRecordList::iterator itr = m_TableRecords.begin(); TableRecordList::iterator endItr = m_TableRecords.end(); bool erased = false; for ( ; itr != endItr ; ++itr ) { if ( (*itr)->m_ItemClass == pItem->getItemClass() && (*itr)->m_ItemID == pItem->getItemID() ) { m_TableRecords.erase( itr ); erased = true; break; } } if ( !erased ) filelog( "QuestItem.log", "[%u,%u] : 矫埃力茄 酒捞袍阑 抛捞喉俊辑 瘤奎绰单 皋葛府俊 绝嚼聪促.", (uint)pItem->getItemClass(), (uint)pItem->getItemID() ); // 困氰 -_- ObjectID..... 0捞搁 欢抄促. 酒捞袍 迫 锭绰 粮 救俊 乐阑锭父 何福聪鳖 老窜 0老 府啊 绝促. ItemTimeLimitMap::iterator itr2 = m_ItemTimeLimits.find( pItem->getObjectID() ); if ( itr2 != m_ItemTimeLimits.end() ) { m_ItemTimeLimits.erase( itr2 ); } else { filelog( "QuestItem.log", "[%u,%u] : Item Time Limit Map 俊档 绝嚼聪促.", (uint)pItem->getItemClass(), (uint)pItem->getItemID() ); } return true; __END_CATCH}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -