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

📄 petitem.cpp

📁 天之炼狱1服务器端源文件游戏服务端不完整
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//////////////////////////////////////////////////////////////////////////////// Filename    : PetItem.cpp// Written By  : excel96// Description ://////////////////////////////////////////////////////////////////////////////#include "PetItem.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 "PetUtil.h"#include "EffectHasPet.h"#include "GamePlayer.h"#include "CreatureUtil.h"#include "PetTypeInfo.h"PetItemInfoManager* g_pPetItemInfoManager = NULL;ItemID_t PetItem::m_ItemIDRegistry = 0;Mutex    PetItem::m_Mutex;//////////////////////////////////////////////////////////////////////////////// class PetItem member methods//////////////////////////////////////////////////////////////////////////////PetItem::PetItem()	throw(){	m_ItemType = 0;	m_pPetInfo = NULL;}PetItem::PetItem(ItemType_t itemType, const list<OptionType_t>& optionType)	throw(){	m_ItemType = itemType;	m_pPetInfo = NULL;	if (!g_pItemInfoManager->isPossibleItem(getItemClass(), m_ItemType, optionType))	{		filelog("itembug.log", "PetItem::PetItem() : Invalid item type or option type");		throw ("PetItem::PetItem() : Invalid item type or optionType");	}}void PetItem::create(const string & ownerID, Storage storage, StorageID_t storageID, BYTE x, BYTE y, ItemID_t itemID) 	throw(Error){	__BEGIN_TRY	Statement* pStmt = NULL;	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("DARKEDEN")->createStatement();/*		StringStream sql;		sql << "INSERT INTO PetItemObject "			<< "(ItemID,  ObjectID, ItemType, OwnerID, Storage, StorageID, X, Y, ItemFlag) VALUES(" 			<< m_ItemID << ", "			<< m_ObjectID << ", " << m_ItemType << ", '" << ownerID << "', " 			<<(int)storage << ", " << storageID << ", " <<(int)x << ", " <<(int)y << ", " 			<< (int)m_CreateType << ")";		pStmt->executeQuery(sql.toString());*/		if ( m_pPetInfo == NULL )		{			pStmt->executeQuery("INSERT INTO PetItemObject (ItemID, ObjectID, ItemType, OwnerID, Storage, StorageID, X, Y, ItemFlag) "								"VALUES (%lu, %u, %u, '%s', %u, %u, %u, %u, %u)",								m_ItemID, m_ObjectID, m_ItemType, ownerID.c_str(), storage, storageID, x, y, m_CreateType);		}		else		{			pStmt->executeQuery("INSERT INTO PetItemObject (ItemID, ObjectID, ItemType, OwnerID, Storage, StorageID, X, Y, ItemFlag, "								"PetCreatureType, PetLevel, PetExp, PetHP, PetAttr, PetAttrLevel, PetOption, FoodType, "								"CanGamble, CanCutHead, CanAttack, LastFeedTime) "								"VALUES (%lu, %u, %u, '%s', %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, '%s')",								m_ItemID, m_ObjectID, m_ItemType, ownerID.c_str(), storage, storageID, x, y, m_CreateType,								m_pPetInfo->getPetCreatureType(), m_pPetInfo->getPetLevel(), m_pPetInfo->getPetExp(), m_pPetInfo->getPetHP(), 								m_pPetInfo->getPetAttr(), m_pPetInfo->getPetAttrLevel(),								m_pPetInfo->getPetOption(), m_pPetInfo->getFoodType(),								m_pPetInfo->canGamble(), m_pPetInfo->canCutHead(), m_pPetInfo->canAttack(),								m_pPetInfo->getLastFeedTime().toDateTime().c_str());		}		SAFE_DELETE(pStmt);	}	END_DB(pStmt)	__END_CATCH}//--------------------------------------------------------------------------------// save item//--------------------------------------------------------------------------------void PetItem::tinysave(const char* field) const	throw(Error){	__BEGIN_TRY	Statement* pStmt = NULL;	BEGIN_DB	{		pStmt = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement();		pStmt->executeQuery( "UPDATE PetItemObject SET %s WHERE ItemID=%ld",								field, m_ItemID);		SAFE_DELETE(pStmt);	}	END_DB(pStmt)		__END_CATCH}void PetItem::save(const string & ownerID, Storage storage, StorageID_t storageID, BYTE x, BYTE y) 	throw(Error){	__BEGIN_TRY	Statement* pStmt = NULL;	BEGIN_DB 	{		pStmt = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement();		if ( m_pPetInfo == NULL )		{			pStmt->executeQuery( "UPDATE PetItemObject SET ObjectID=%ld, ItemType=%d, OwnerID='%s', Storage=%d, StorageID=%ld, X=%d, Y=%d WHERE ItemID=%ld",									m_ObjectID, m_ItemType, ownerID.c_str(), (int)storage, storageID, (int)x, (int)y, m_ItemID );		}		else		{			pStmt->executeQuery("UPDATE PetItemObject SET ObjectID=%ld, ItemType=%d, OwnerID='%s', Storage=%d, StorageID=%ld, X=%d, Y=%d, "								"PetCreatureType=%u, PetLevel=%u, PetAttr=%u, PetAttrLevel=%u, PetExp=%u, PetHP=%u, FoodType=%u, "								"CanGamble=%u, CanCutHead=%u, CanAttack=%u, LastFeedTime='%s' "								"WHERE ItemID=%ld",									m_ObjectID, m_ItemType, ownerID.c_str(), (int)storage, storageID, (int)x, (int)y,									m_pPetInfo->getPetCreatureType(), m_pPetInfo->getPetLevel(), m_pPetInfo->getPetAttr(), m_pPetInfo->getPetAttrLevel(),									m_pPetInfo->getPetExp(), m_pPetInfo->getPetHP(), m_pPetInfo->getFoodType(),									m_pPetInfo->canGamble(), m_pPetInfo->canCutHead(), m_pPetInfo->canAttack(), m_pPetInfo->getLastFeedTime().toDateTime().c_str(),									m_ItemID );		}		SAFE_DELETE(pStmt);	}	END_DB(pStmt)		__END_CATCH}void PetItem::savePetInfo() const{	__BEGIN_TRY	Statement* pStmt = NULL;	BEGIN_DB 	{		pStmt = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement();		if ( m_pPetInfo != NULL )		{			pStmt->executeQuery("UPDATE PetItemObject SET "								"PetCreatureType=%u, PetLevel=%u, PetAttr=%u, PetAttrLevel=%u, PetExp=%u, PetHP=%u, FoodType=%u, "								"CanGamble=%u, CanCutHead=%u, CanAttack=%u, LastFeedTime='%s' "								"WHERE ItemID=%ld",									m_pPetInfo->getPetCreatureType(), m_pPetInfo->getPetLevel(), m_pPetInfo->getPetAttr(), m_pPetInfo->getPetAttrLevel(),									m_pPetInfo->getPetExp(), m_pPetInfo->getPetHP(), m_pPetInfo->getFoodType(),									m_pPetInfo->canGamble(), m_pPetInfo->canCutHead(), m_pPetInfo->canAttack(), m_pPetInfo->getLastFeedTime().toDateTime().c_str(),									m_ItemID );		}		SAFE_DELETE(pStmt);	}	END_DB(pStmt)		__END_CATCH}void PetItem::makePCItemInfo(PCItemInfo& result) const{	Item::makePCItemInfo(result);	if ( m_pPetInfo != NULL )	{		list<OptionType_t> olist;		if ( m_pPetInfo->getPetOption() != 0 ) 			olist.push_back(m_pPetInfo->getPetOption());		result.setOptionType( olist );		result.setDurability( m_pPetInfo->getPetHP() );		result.setEnchantLevel( m_pPetInfo->getPetAttr() );		result.setSilver( m_pPetInfo->getPetAttrLevel() );		result.setGrade( (m_pPetInfo->getPetHP()==0)?(m_pPetInfo->getLastFeedTime().daysTo( VSDateTime::currentDateTime() )):(-1) );		result.setItemNum( m_pPetInfo->getPetLevel() );		result.setMainColor( 0xffff );	}}void PetItem::whenPCTake( PlayerCreature* pPC ){	Item::whenPCTake(pPC);	pPC->getPetItems().push_back(this);	if ( !pPC->isFlag( Effect::EFFECT_CLASS_HAS_PET ) )	{		//cout << pPC->getName() << " 俊霸 脐 啊脸促绰 捞棋飘 何抹聪寸" << endl;		EffectHasPet* pEffect = new EffectHasPet(pPC);		pEffect->setNextTime(600);		pPC->setFlag( Effect::EFFECT_CLASS_HAS_PET );		pPC->addEffect(pEffect);	}}void PetItem::whenPCLost( PlayerCreature* pPC ){	Item::whenPCLost(pPC);	if ( m_pPetInfo == pPC->getPetInfo() )	{		pPC->setPetInfo( NULL );		GamePlayer* pGamePlayer = dynamic_cast<GamePlayer*>(pPC->getPlayer());		if ( pGamePlayer != NULL ) sendPetInfo( pGamePlayer, true );	}	pPC->getPetItems().remove(this);	if ( pPC->getPetItems().empty() )	{		//cout << pPC->getName() << " 俊霸辑 脐 啊脸促绰 捞棋飘 都晨聪寸" << endl;		Effect* pEffect = pPC->findEffect( Effect::EFFECT_CLASS_HAS_PET );		if ( pEffect != NULL ) pEffect->setDeadline(0);	}}string PetItem::toString() const 	throw(){	StringStream msg;	msg << "PetItem("		<< "ItemID:"    << m_ItemID		<< ",ItemType:" <<(int)m_ItemType		<< ")";	return msg.toString();}VolumeWidth_t PetItem::getVolumeWidth() const 	throw(Error){	__BEGIN_TRY	return g_pPetItemInfoManager->getItemInfo(m_ItemType)->getVolumeWidth();	__END_CATCH}	VolumeHeight_t PetItem::getVolumeHeight() const 	throw(Error){	__BEGIN_TRY	return g_pPetItemInfoManager->getItemInfo(m_ItemType)->getVolumeHeight();	__END_CATCH}	Weight_t PetItem::getWeight() const 	throw(Error){	__BEGIN_TRY	return g_pPetItemInfoManager->getItemInfo(m_ItemType)->getWeight();	__END_CATCH}//////////////////////////////////////////////////////////////////////////////// class PetItemInfo member methods//////////////////////////////////////////////////////////////////////////////string PetItemInfo::toString() const 	throw(){	StringStream msg;	msg << "PetItemInfo("		<< "ItemType:"     <<(int)m_ItemType		<< ",Name:"        << m_Name		<< ",EName:"       << m_EName		<< ",Price:"       <<(int)m_Price		<< ",VolumeType:"  << Volume2String[m_VolumeType]		<< ",Weight:"      <<(int)m_Weight		<< ",Description:" << m_Description		<< ")";	return msg.toString();}void PetItemInfoManager::load() 	throw(Error){	__BEGIN_TRY

⌨️ 快捷键说明

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