📄 potion.cpp
字号:
//////////////////////////////////////////////////////////////////////////////// Filename : Potion.cpp// Written By : Elca// Description ://////////////////////////////////////////////////////////////////////////////#include "Potion.h"#include "DB.h"#include "Slayer.h"#include "Vampire.h"#include "Belt.h"#include "Motorcycle.h"#include "Stash.h"#include "Utility.h"#include "ItemInfoManager.h"#include "ItemUtil.h"#include "ZoneGroupManager.h"// global variable declarationPotionInfoManager* g_pPotionInfoManager = NULL;ItemID_t Potion::m_ItemIDRegistry = 0;Mutex Potion::m_Mutex;//--------------------------------------------------------------------------------// constructor//--------------------------------------------------------------------------------Potion::Potion() throw()//: m_ItemType(0){ setItemType(0);}Potion::Potion(ItemType_t itemType, const list<OptionType_t>& optionType, ItemNum_t Num) throw()//: m_ItemType(itemType), m_Num(Num){ setItemType(itemType); setNum(Num); //cout << "Potion::Potion(" << getOptionTypeToString(optionType).c_str() << ")" << endl; if (!g_pItemInfoManager->isPossibleItem(getItemClass(), getItemType(), optionType)) { filelog("itembug.log", "Potion::Potion() : Invalid item type or option type"); throw ("Potion::Potion() : Invalid item type or optionType"); }}//--------------------------------------------------------------------------------// create item//--------------------------------------------------------------------------------void Potion::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 PotionObject " << "(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 PotionObject (ItemID, ObjectID, ItemType, OwnerID, Storage, StorageID, X, Y, Num) VALUES(%ld, %ld, %d, '%s', %d, %ld, %d, %d, %d)", m_ItemID, m_ObjectID, getItemType(), ownerID.c_str(), (int)storage, storageID, x, y, (int)getNum() ); SAFE_DELETE(pStmt); } END_DB(pStmt) __END_CATCH}//--------------------------------------------------------------------------------// destroy//--------------------------------------------------------------------------------bool Potion::destroy() throw(Error){ __BEGIN_TRY Statement* pStmt = NULL; BEGIN_DB { // 父距 器记捞扼搁 促弗 Database俊 楷搬秦辑 瘤快档废 茄促. //pStmt = g_pDatabaseManager->getConnection("DIST_DARKEDEN")->createStatement(); 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 Potion::tinysave(const char* field) const throw(Error){ __BEGIN_TRY Statement* pStmt = NULL; BEGIN_DB { //pStmt = g_pDatabaseManager->getConnection("DIST_DARKEDEN")->createStatement(); pStmt = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement(); pStmt->executeQuery( "UPDATE PotionObject SET %s WHERE ItemID=%ld", field, m_ItemID); SAFE_DELETE(pStmt); } END_DB(pStmt) __END_CATCH}//--------------------------------------------------------------------------------// save item//--------------------------------------------------------------------------------void Potion::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("DIST_DARKEDEN")->createStatement(); pStmt = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement(); /* StringStream sql; sql << "UPDATE PotionObject SET " << "ObjectID = " << m_ObjectID << ",ItemType = " << m_ItemType << ",OwnerID = '" << ownerID << "'" << ",Storage = " <<(int)storage << ",StorageID = " << storageID << ",X = " <<(int)x << ",Y = " <<(int)y << ",Num = " <<(int)m_Num << " WHERE ItemID = " << m_ItemID; pStmt->executeQuery(sql.toString()); */ pStmt->executeQuery( "UPDATE PotionObject SET ObjectID=%ld, ItemType=%d, OwnerID='%s', Storage=%d, StorageID=%ld, X=%d, Y=%d, Num=%d WHERE ItemID=%ld", m_ObjectID, getItemType(), ownerID.c_str(), (int)storage, storageID, (int)x, (int)y, (int)getNum(), m_ItemID ); SAFE_DELETE(pStmt); } END_DB(pStmt) __END_CATCH}//--------------------------------------------------------------------------------// get debug string//--------------------------------------------------------------------------------string Potion::toString() const throw(){ StringStream msg; msg << "Potion(" << "ItemID:" << m_ItemID << ",ItemType:" <<(int)getItemType() << ",Num:" <<(int)getNum() << ")"; return msg.toString();}/*//--------------------------------------------------------------------------------// get width//--------------------------------------------------------------------------------VolumeWidth_t Potion::getVolumeWidth() const throw(Error){ __BEGIN_TRY return g_pPotionInfoManager->getItemInfo(m_ItemType)->getVolumeWidth(); __END_CATCH} //--------------------------------------------------------------------------------// get height//--------------------------------------------------------------------------------VolumeHeight_t Potion::getVolumeHeight() const throw(Error){ __BEGIN_TRY return g_pPotionInfoManager->getItemInfo(m_ItemType)->getVolumeHeight(); __END_CATCH} //--------------------------------------------------------------------------------// get weight//--------------------------------------------------------------------------------Weight_t Potion::getWeight() const throw(Error){ __BEGIN_TRY return g_pPotionInfoManager->getItemInfo(m_ItemType)->getWeight(); __END_CATCH}*/int Potion::getHPAmount(void) const throw(){ __BEGIN_TRY PotionInfo* pInfo = dynamic_cast<PotionInfo*>(g_pPotionInfoManager->getItemInfo(getItemType())); return pInfo->getHPAmount(); __END_CATCH}int Potion::getMPAmount(void) const throw(){ __BEGIN_TRY PotionInfo* pInfo = dynamic_cast<PotionInfo*>(g_pPotionInfoManager->getItemInfo(getItemType())); return pInfo->getMPAmount(); __END_CATCH}int Potion::getHPDelay(void) const throw(){ __BEGIN_TRY PotionInfo* pInfo = dynamic_cast<PotionInfo*>(g_pPotionInfoManager->getItemInfo(getItemType())); return pInfo->getHPDelay(); __END_CATCH}int Potion::getMPDelay(void) const throw(){ __BEGIN_TRY PotionInfo* pInfo = dynamic_cast<PotionInfo*>(g_pPotionInfoManager->getItemInfo(getItemType())); return pInfo->getMPDelay(); __END_CATCH}int Potion::getHPQuantity(void) const throw(){ __BEGIN_TRY PotionInfo* pInfo = dynamic_cast<PotionInfo*>(g_pPotionInfoManager->getItemInfo(getItemType())); return pInfo->getHPQuantity(); __END_CATCH}int Potion::getMPQuantity(void) const throw(){ __BEGIN_TRY PotionInfo* pInfo = dynamic_cast<PotionInfo*>(g_pPotionInfoManager->getItemInfo(getItemType())); return pInfo->getMPQuantity(); __END_CATCH}int Potion::getHPRecoveryUnit(void) const throw(){ __BEGIN_TRY PotionInfo* pInfo = dynamic_cast<PotionInfo*>(g_pPotionInfoManager->getItemInfo(getItemType())); return pInfo->getHPRecoveryUnit(); __END_CATCH}int Potion::getMPRecoveryUnit(void) const throw(){ __BEGIN_TRY PotionInfo* pInfo = dynamic_cast<PotionInfo*>(g_pPotionInfoManager->getItemInfo(getItemType())); return pInfo->getMPRecoveryUnit(); __END_CATCH}//--------------------------------------------------------------------------------// parse effect string//--------------------------------------------------------------------------------void PotionInfo::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)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -