⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pupa.cpp

📁 天之炼狱1服务器端源文件游戏服务端不完整
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//////////////////////////////////////////////////////////////////////////////// Filename    : Pupa.cpp// Written By  : Elca// Description ://////////////////////////////////////////////////////////////////////////////#include "Pupa.h"#include "DB.h"#include "Slayer.h"#include "Vampire.h"#include "Ousters.h"#include "Belt.h"#include "OustersArmsband.h"#include "Motorcycle.h"#include "Stash.h"#include "Utility.h"#include "ItemInfoManager.h"#include "ItemUtil.h"#include "ZoneGroupManager.h"// global variable declarationPupaInfoManager* g_pPupaInfoManager = NULL;ItemID_t Pupa::m_ItemIDRegistry = 0;Mutex    Pupa::m_Mutex;//--------------------------------------------------------------------------------// constructor//--------------------------------------------------------------------------------Pupa::Pupa()	throw(): m_ItemType(0){}Pupa::Pupa(ItemType_t itemType, const list<OptionType_t>& optionType, ItemNum_t Num)	throw(): m_ItemType(itemType), m_Num(Num){	//cout << "Pupa::Pupa(" << getOptionTypeToString(optionType).c_str() << ")" << endl;	if (!g_pItemInfoManager->isPossibleItem(getItemClass(), m_ItemType, optionType))	{		filelog("itembug.log", "Pupa::Pupa() : Invalid item type or option type");		throw ("Pupa::Pupa() : Invalid item type or optionType");	}}//--------------------------------------------------------------------------------// create item//--------------------------------------------------------------------------------void Pupa::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 PupaObject "			<< "(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 PupaObject (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 Pupa::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 Pupa::tinysave(const char* field) const	throw(Error){	__BEGIN_TRY	Statement* pStmt = NULL;	BEGIN_DB	{		pStmt = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement();		pStmt->executeQuery( "UPDATE PupaObject SET %s WHERE ItemID=%ld",								field, m_ItemID);		SAFE_DELETE(pStmt);	}	END_DB(pStmt)		__END_CATCH}//--------------------------------------------------------------------------------// save item//--------------------------------------------------------------------------------void Pupa::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 PupaObject 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 Pupa::toString() const 	throw(){	StringStream msg;	msg << "Pupa("		<< "ItemID:"    << m_ItemID		<< ",ItemType:" <<(int)m_ItemType		<< ",Num:"      <<(int)m_Num		<< ")";	return msg.toString();}//--------------------------------------------------------------------------------// get width//--------------------------------------------------------------------------------VolumeWidth_t Pupa::getVolumeWidth() const 	throw(Error){	__BEGIN_TRY	return g_pPupaInfoManager->getItemInfo(m_ItemType)->getVolumeWidth();	__END_CATCH}	//--------------------------------------------------------------------------------// get height//--------------------------------------------------------------------------------VolumeHeight_t Pupa::getVolumeHeight() const 	throw(Error){	__BEGIN_TRY	return g_pPupaInfoManager->getItemInfo(m_ItemType)->getVolumeHeight();	__END_CATCH}	//--------------------------------------------------------------------------------// get weight//--------------------------------------------------------------------------------Weight_t Pupa::getWeight() const 	throw(Error){	__BEGIN_TRY	return g_pPupaInfoManager->getItemInfo(m_ItemType)->getWeight();	__END_CATCH}int Pupa::getHPAmount(void) const	throw(){	__BEGIN_TRY	PupaInfo* pInfo = dynamic_cast<PupaInfo*>(g_pPupaInfoManager->getItemInfo(m_ItemType));	return pInfo->getHPAmount();	__END_CATCH}int Pupa::getMPAmount(void) const	throw(){	__BEGIN_TRY	PupaInfo* pInfo = dynamic_cast<PupaInfo*>(g_pPupaInfoManager->getItemInfo(m_ItemType));	return pInfo->getMPAmount();	__END_CATCH}int Pupa::getHPDelay(void) const	throw(){	__BEGIN_TRY	PupaInfo* pInfo = dynamic_cast<PupaInfo*>(g_pPupaInfoManager->getItemInfo(m_ItemType));	return pInfo->getHPDelay();	__END_CATCH}int Pupa::getMPDelay(void) const	throw(){	__BEGIN_TRY	PupaInfo* pInfo = dynamic_cast<PupaInfo*>(g_pPupaInfoManager->getItemInfo(m_ItemType));	return pInfo->getMPDelay();	__END_CATCH}int Pupa::getHPQuantity(void) const	throw(){	__BEGIN_TRY	PupaInfo* pInfo = dynamic_cast<PupaInfo*>(g_pPupaInfoManager->getItemInfo(m_ItemType));	return pInfo->getHPQuantity();	__END_CATCH}int Pupa::getMPQuantity(void) const	throw(){	__BEGIN_TRY	PupaInfo* pInfo = dynamic_cast<PupaInfo*>(g_pPupaInfoManager->getItemInfo(m_ItemType));	return pInfo->getMPQuantity();	__END_CATCH}int Pupa::getHPRecoveryUnit(void) const	throw(){	__BEGIN_TRY	PupaInfo* pInfo = dynamic_cast<PupaInfo*>(g_pPupaInfoManager->getItemInfo(m_ItemType));	return pInfo->getHPRecoveryUnit();	__END_CATCH}int Pupa::getMPRecoveryUnit(void) const	throw(){	__BEGIN_TRY	PupaInfo* pInfo = dynamic_cast<PupaInfo*>(g_pPupaInfoManager->getItemInfo(m_ItemType));	return pInfo->getMPRecoveryUnit();	__END_CATCH}//--------------------------------------------------------------------------------// parse effect string//--------------------------------------------------------------------------------void PupaInfo::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;		}		else if (recover == "MP")

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -