📄 larva.cpp
字号:
//////////////////////////////////////////////////////////////////////////////// Filename : Larva.cpp// Written By : Elca// Description ://////////////////////////////////////////////////////////////////////////////#include "Larva.h"#include "DB.h"#include "Slayer.h"#include "Vampire.h"#include "Ousters.h"#include "Belt.h"#include "Motorcycle.h"#include "Stash.h"#include "Utility.h"#include "ItemInfoManager.h"#include "ItemUtil.h"#include "ZoneGroupManager.h"// global variable declarationLarvaInfoManager* g_pLarvaInfoManager = NULL;ItemID_t Larva::m_ItemIDRegistry = 0;Mutex Larva::m_Mutex;//--------------------------------------------------------------------------------// constructor//--------------------------------------------------------------------------------Larva::Larva() throw(): m_ItemType(0){}Larva::Larva(ItemType_t itemType, const list<OptionType_t>& optionType, ItemNum_t Num) throw(): m_ItemType(itemType), m_Num(Num){ //cout << "Larva::Larva(" << getOptionTypeToString(optionType).c_str() << ")" << endl; if (!g_pItemInfoManager->isPossibleItem(getItemClass(), m_ItemType, optionType)) { filelog("itembug.log", "Larva::Larva() : Invalid item type or option type"); throw ("Larva::Larva() : Invalid item type or optionType"); }}//--------------------------------------------------------------------------------// create item//--------------------------------------------------------------------------------void Larva::create(const string & ownerID, Storage storage, StorageID_t storageID, BYTE x, BYTE y, ItemID_t itemID) throw(Error){ __BEGIN_TRY Statement* pStmt; if (itemID==0) { __ENTER_CRITICAL_SECTION(m_Mutex) m_ItemIDRegistry += g_pItemInfoManager->getItemIDSuccessor(); m_ItemID = m_ItemIDRegistry; __LEAVE_CRITICAL_SECTION(m_Mutex) } else { m_ItemID = itemID; } BEGIN_DB { //pStmt = g_pDatabaseManager->getConnection("DIST_DARKEDEN")->createStatement(); pStmt = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement(); /* StringStream sql; sql << "INSERT INTO LarvaObject " << "(ItemID, ObjectID, ItemType, OwnerID, Storage, StorageID, X, Y, Num) VALUES(" << m_ItemID << ", " << m_ObjectID << ", " << m_ItemType << ", '" << ownerID << "', " <<(int)storage << ", " << storageID << ", " <<(int)x << ", " <<(int)y << ", " << (int)m_Num << ")"; pStmt->executeQuery(sql.toString()); */ // StringStream力芭. by sigi. 2002.5.13 pStmt->executeQuery( "INSERT INTO LarvaObject (ItemID, ObjectID, ItemType, OwnerID, Storage, StorageID, X, Y, Num) VALUES(%ld, %ld, %d, '%s', %d, %ld, %d, %d, %d)", m_ItemID, m_ObjectID, m_ItemType, ownerID.c_str(), (int)storage, storageID, x, y, (int)m_Num ); SAFE_DELETE(pStmt); } END_DB(pStmt) __END_CATCH}//--------------------------------------------------------------------------------// destroy//--------------------------------------------------------------------------------bool Larva::destroy() throw(Error){ __BEGIN_TRY Statement* pStmt = NULL; BEGIN_DB { pStmt = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement(); pStmt->executeQuery("DELETE FROM %s WHERE ItemID = %ld", getObjectTableName().c_str(), m_ItemID); if (pStmt->getAffectedRowCount()==0) { SAFE_DELETE(pStmt); return false; } SAFE_DELETE(pStmt); } END_DB(pStmt) __END_CATCH return true;}//--------------------------------------------------------------------------------// save item//--------------------------------------------------------------------------------void Larva::tinysave(const char* field) const throw(Error){ __BEGIN_TRY Statement* pStmt = NULL; BEGIN_DB { pStmt = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement(); pStmt->executeQuery( "UPDATE LarvaObject SET %s WHERE ItemID=%ld", field, m_ItemID); SAFE_DELETE(pStmt); } END_DB(pStmt) __END_CATCH}//--------------------------------------------------------------------------------// save item//--------------------------------------------------------------------------------void Larva::save(const string & ownerID, Storage storage, StorageID_t storageID, BYTE x, BYTE y) throw(Error){ __BEGIN_TRY Statement* pStmt; BEGIN_DB { pStmt = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement(); pStmt->executeQuery( "UPDATE LarvaObject SET ObjectID=%ld, ItemType=%d, OwnerID='%s', Storage=%d, StorageID=%ld, X=%d, Y=%d, Num=%d WHERE ItemID=%ld", m_ObjectID, m_ItemType, ownerID.c_str(), (int)storage, storageID, (int)x, (int)y, (int)m_Num, m_ItemID ); SAFE_DELETE(pStmt); } END_DB(pStmt) __END_CATCH}//--------------------------------------------------------------------------------// get debug string//--------------------------------------------------------------------------------string Larva::toString() const throw(){ StringStream msg; msg << "Larva(" << "ItemID:" << m_ItemID << ",ItemType:" <<(int)m_ItemType << ",Num:" <<(int)m_Num << ")"; return msg.toString();}//--------------------------------------------------------------------------------// get width//--------------------------------------------------------------------------------VolumeWidth_t Larva::getVolumeWidth() const throw(Error){ __BEGIN_TRY return g_pLarvaInfoManager->getItemInfo(m_ItemType)->getVolumeWidth(); __END_CATCH} //--------------------------------------------------------------------------------// get height//--------------------------------------------------------------------------------VolumeHeight_t Larva::getVolumeHeight() const throw(Error){ __BEGIN_TRY return g_pLarvaInfoManager->getItemInfo(m_ItemType)->getVolumeHeight(); __END_CATCH} //--------------------------------------------------------------------------------// get weight//--------------------------------------------------------------------------------Weight_t Larva::getWeight() const throw(Error){ __BEGIN_TRY return g_pLarvaInfoManager->getItemInfo(m_ItemType)->getWeight(); __END_CATCH}int Larva::getHPAmount(void) const throw(){ __BEGIN_TRY LarvaInfo* pInfo = dynamic_cast<LarvaInfo*>(g_pLarvaInfoManager->getItemInfo(m_ItemType)); return pInfo->getHPAmount(); __END_CATCH}int Larva::getMPAmount(void) const throw(){ __BEGIN_TRY LarvaInfo* pInfo = dynamic_cast<LarvaInfo*>(g_pLarvaInfoManager->getItemInfo(m_ItemType)); return pInfo->getMPAmount(); __END_CATCH}int Larva::getHPDelay(void) const throw(){ __BEGIN_TRY LarvaInfo* pInfo = dynamic_cast<LarvaInfo*>(g_pLarvaInfoManager->getItemInfo(m_ItemType)); return pInfo->getHPDelay(); __END_CATCH}int Larva::getMPDelay(void) const throw(){ __BEGIN_TRY LarvaInfo* pInfo = dynamic_cast<LarvaInfo*>(g_pLarvaInfoManager->getItemInfo(m_ItemType)); return pInfo->getMPDelay(); __END_CATCH}int Larva::getHPQuantity(void) const throw(){ __BEGIN_TRY LarvaInfo* pInfo = dynamic_cast<LarvaInfo*>(g_pLarvaInfoManager->getItemInfo(m_ItemType)); return pInfo->getHPQuantity(); __END_CATCH}int Larva::getMPQuantity(void) const throw(){ __BEGIN_TRY LarvaInfo* pInfo = dynamic_cast<LarvaInfo*>(g_pLarvaInfoManager->getItemInfo(m_ItemType)); return pInfo->getMPQuantity(); __END_CATCH}int Larva::getHPRecoveryUnit(void) const throw(){ __BEGIN_TRY LarvaInfo* pInfo = dynamic_cast<LarvaInfo*>(g_pLarvaInfoManager->getItemInfo(m_ItemType)); return pInfo->getHPRecoveryUnit(); __END_CATCH}int Larva::getMPRecoveryUnit(void) const throw(){ __BEGIN_TRY LarvaInfo* pInfo = dynamic_cast<LarvaInfo*>(g_pLarvaInfoManager->getItemInfo(m_ItemType)); return pInfo->getMPRecoveryUnit(); __END_CATCH}//--------------------------------------------------------------------------------// parse effect string//--------------------------------------------------------------------------------void LarvaInfo::parseEffect(const string& effect) throw(){ __BEGIN_TRY m_HPAmount = 0; m_HPDelay = 0; m_HPRecoveryUnit = 0; m_MPAmount = 0; m_MPDelay = 0; m_MPRecoveryUnit = 0; if (effect.size() < 5) return; uint a = 0, b = 0, c = 0, d = 0, e = 0; while (e < effect.size() - 1) { //////////////////////////////////////////////////////////// //(HP,+50,2,1)(MP+10) // a b ca //////////////////////////////////////////////////////////// a = effect.find_first_of('(', e); b = effect.find_first_of(',', a+1); c = effect.find_first_of(',', b+1); d = effect.find_first_of(',', c+1); e = effect.find_first_of(')', d+1); if (a > b || b > c || c > d || d > e) break; string recover = trim(effect.substr(a+1, b-a-1)); uint amount = atoi(effect.substr(b+1, c-b-1).c_str()); uint delay = atoi(effect.substr(c+1, d-c-1).c_str()); uint unit = atoi(effect.substr(d+1, e-d-1).c_str()); if (recover == "HP") { m_HPAmount =(int)amount; m_HPDelay =(int)delay; m_HPRecoveryUnit =(int)unit; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -