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

📄 castleinfomanager.cpp

📁 天之炼狱1服务器端源文件游戏服务端不完整
💻 CPP
📖 第 1 页 / 共 3 页
字号:
////////////////////////////////////////////////////////////////////////////////// Filename    : CastleInfoManager.cpp// Written By  : // Description : 酒淬狼 己瘤 辟贸俊 乐绰 己俊 措茄 沥焊////////////////////////////////////////////////////////////////////////////////#include "CastleInfoManager.h"#include "PlayerCreature.h"#include "ItemUtil.h"#include <stdio.h>#include "Properties.h"#include "ZoneInfoManager.h"#include "ZoneGroupManager.h"#include "VariableManager.h"#include "Guild.h"#include "GuildManager.h"//#include "HolyLandRaceBonus.h"#include "ZoneUtil.h"#include "NPCManager.h"#include "Zone.h"#include "War.h"#include "WarSystem.h"#include "WarScheduler.h"#include "ClientManager.h"#include "PCManager.h"#include "EventRefreshHolyLandPlayer.h"#include "ShrineInfoManager.h"#include "EffectHasBloodBible.h"#include "CastleSkillInfo.h"#include "GamePlayer.h"#include "DB.h"#include "StringPool.h"#include "Skill.h"#include "Gpackets/GCSystemMessage.h"#include "Gpackets/GCNoticeEvent.h"#include "Gpackets/GCModifyInformation.h"CastleInfo::CastleInfo() : m_Name(""), m_BonusOptionList() , m_CastleZoneIDList(){	m_ZoneID = 0;	m_ShrineID = 0;	m_GuildID = 0;	m_ItemTaxRatio = 0;	m_EntranceFee = 0;	m_TaxBalance = 0;}CastleInfo::~CastleInfo(){}Gold_t CastleInfo::increaseTaxBalance( Gold_t tax ){	if( tax > GUILD_TAX_BALANCE_MAX - m_TaxBalance ) // 醚钦捞 坷滚且 版快	{		tax = GUILD_TAX_BALANCE_MAX - m_TaxBalance;	}	m_TaxBalance = min( GUILD_TAX_BALANCE_MAX, m_TaxBalance + tax );	return m_TaxBalance;}Gold_t CastleInfo::decreaseTaxBalance( Gold_t tax ){	if( tax > m_TaxBalance ) tax = m_TaxBalance;	m_TaxBalance = max( 0, (int)m_TaxBalance - (int)tax );	return m_TaxBalance;}Gold_t CastleInfo::increaseTaxBalanceEx( Gold_t tax )	throw(Error){	__BEGIN_TRY	static char query[100];	increaseTaxBalance(tax);	if( !isCommon() )	{		sprintf( query, "TaxBalance=%d", (int)getTaxBalance() );		g_pCastleInfoManager->tinysave( getZoneID(), query );	}	return getTaxBalance();	__END_CATCH}Gold_t CastleInfo::decreaseTaxBalanceEx( Gold_t tax )	throw(Error){	__BEGIN_TRY	static char query[100];	decreaseTaxBalance(tax);	if( !isCommon() )	{		sprintf( query, "TaxBalance=%d", (int)getTaxBalance() );		g_pCastleInfoManager->tinysave( getZoneID(), query );	}		return getTaxBalance();	__END_CATCH}void CastleInfo::setOptionTypeList( const string& options )	throw(){	__BEGIN_TRY	makeOptionList( options, m_BonusOptionList );	__END_CATCH}void CastleInfo::setZoneIDList( const string& zoneIDs ) 	throw(){	__BEGIN_TRY	makeZoneIDList( zoneIDs, m_CastleZoneIDList );	__END_CATCH}void CastleInfo::setResurrectPosition( ResurrectPriority resurrectPriority, const ZONE_COORD& zoneCoord ){	m_ResurrectPosition[resurrectPriority].set( zoneCoord.id, zoneCoord.x, zoneCoord.y );}void CastleInfo::getResurrectPosition( ResurrectPriority resurrectPriority, ZONE_COORD& zoneCoord ){	zoneCoord.set( m_ResurrectPosition[resurrectPriority].id, m_ResurrectPosition[resurrectPriority].x, m_ResurrectPosition[resurrectPriority].y );}void CastleInfo::broadcast(Packet* pPacket) const	throw (Error){	__BEGIN_TRY	Assert( pPacket != NULL );	list<ZoneID_t>::const_iterator itr = m_CastleZoneIDList.begin();	for ( ; itr != m_CastleZoneIDList.end() ; itr++)	{		Zone* pCastleZone = getZoneByZoneID( *itr );		pCastleZone->broadcastPacket( pPacket );	}	__END_CATCH}bool CastleInfo::isCastleZone(ZoneID_t targetZoneID) const 	throw (Error){	__BEGIN_TRY	list<ZoneID_t>::const_iterator itr = m_CastleZoneIDList.begin();	for ( ; itr != m_CastleZoneIDList.end() ; itr++)	{		ZoneID_t zoneID = *itr;		if (zoneID==targetZoneID)			return true;	}	return false;	__END_CATCH}string CastleInfo::toString() const	throw(){	__BEGIN_TRY		StringStream msg;	msg << "CastleInfo("		<< "ZoneID:" << m_ZoneID		<< ",Item Tax Ratie:" << m_ItemTaxRatio		<< ",Entrance Fee:" << m_EntranceFee		<< ",Tax Balance:" << m_TaxBalance		<< ")";	return msg.toString();	__END_CATCH}//////////////////////////////////////////////////////////////////////////////// constructor//////////////////////////////////////////////////////////////////////////////CastleInfoManager::CastleInfoManager () {	__BEGIN_TRY	__END_CATCH}//////////////////////////////////////////////////////////////////////////////// destructor//////////////////////////////////////////////////////////////////////////////CastleInfoManager::~CastleInfoManager () {	__BEGIN_TRY	hash_map< ZoneID_t , CastleInfo *>::iterator itr = m_CastleInfos.begin();	for (; itr != m_CastleInfos.end(); itr++)	{		CastleInfo* pInfo = itr->second;		SAFE_DELETE(pInfo);	}		// 秦浆甘救俊 乐绰 葛电 pair 甸阑 昏力茄促.	m_CastleInfos.clear();	__END_CATCH}	//////////////////////////////////////////////////////////////////////////////// initialize zone info manager//////////////////////////////////////////////////////////////////////////////void CastleInfoManager::init () 	throw (Error){	__BEGIN_TRY	// init == load	load();				__END_CATCH}	//void testMaxMemory();//////////////////////////////////////////////////////////////////////////////// load from database//////////////////////////////////////////////////////////////////////////////void CastleInfoManager::load ()	throw (Error){	__BEGIN_TRY	clearCastleZoneIDs();	Statement* pStmt = NULL;	BEGIN_DB	{		// create statement		pStmt = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement();		Result* pResult = pStmt->executeQuery(			"SELECT ZoneID, ShrineID, GuildID, Name, Race, ItemTaxRatio, EntranceFee, TaxBalance, BonusOptionType, FirstResurrectZoneID, FirstResurrectX, FirstResurrectY, SecondResurrectZoneID, SecondResurrectX, SecondResurrectY, ThirdResurrectZoneID, ThirdResurrectX, ThirdResurrectY, ZoneIDList FROM CastleInfo WHERE ServerID = %d",			g_pConfig->getPropertyInt( "ServerID" ) );		ZoneCoord_t x, y;		ZONE_COORD zoneCoord;		while (pResult->next()) 		{			uint i = 0;			ZoneID_t zoneID = pResult->getInt(++i);			ZoneInfo* pZoneInfo = g_pZoneInfoManager->getZoneInfo( zoneID );			Assert( pZoneInfo!=NULL );			pZoneInfo->setCastle();			CastleInfo* pCastleInfo = new CastleInfo();			//cout << "new OK" << endl;			pCastleInfo->setZoneID( zoneID );			pCastleInfo->setShrineID( pResult->getInt(++i) );			pCastleInfo->setGuildID( pResult->getInt(++i) );			pCastleInfo->setName( pResult->getString(++i) );			pCastleInfo->setRace( pResult->getInt(++i) );			pCastleInfo->setItemTaxRatio( pResult->getInt(++i) );			pCastleInfo->setEntranceFee( pResult->getInt(++i) );			pCastleInfo->setTaxBalance( pResult->getInt(++i) );			pCastleInfo->setOptionTypeList( pResult->getString(++i) );			zoneID	= pResult->getInt( ++i );			x		= pResult->getInt( ++i );			y		= pResult->getInt( ++i );			zoneCoord.set( zoneID, x, y );			pCastleInfo->setResurrectPosition( CastleInfo::CASTLE_RESURRECT_PRIORITY_FIRST, zoneCoord );			zoneID	= pResult->getInt( ++i );			x		= pResult->getInt( ++i );			y		= pResult->getInt( ++i );			zoneCoord.set( zoneID, x, y );			pCastleInfo->setResurrectPosition( CastleInfo::CASTLE_RESURRECT_PRIORITY_SECOND, zoneCoord );			zoneID	= pResult->getInt( ++i );			x		= pResult->getInt( ++i );			y		= pResult->getInt( ++i );			zoneCoord.set( zoneID, x, y );			pCastleInfo->setResurrectPosition( CastleInfo::CASTLE_RESURRECT_PRIORITY_THIRD, zoneCoord );			pCastleInfo->setZoneIDList( pResult->getString(++i) );			addCastleInfo(pCastleInfo);			cout << pCastleInfo->toString().c_str() << endl;		}					SAFE_DELETE(pStmt);	} 	END_DB(pStmt)	__END_CATCH}void CastleInfoManager::save( ZoneID_t zoneID )	throw(Error){	__BEGIN_TRY	CastleInfo* pCastleInfo = getCastleInfo( zoneID );	if( pCastleInfo == NULL ) return;	Statement* pStmt = NULL;	BEGIN_DB	{		// create statement		pStmt = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement();		pStmt->executeQuery(			"UPDATE CastleInfo SET GuildID=%d, Name='%s', Race=%d, ItemTaxRatio=%d, EntranceFee=%d, TaxBalance=%d WHERE ServerID=%d AND ZoneID=%d",							(int)pCastleInfo->getGuildID(), 							pCastleInfo->getName().c_str(), 							(int)pCastleInfo->getRace(), 							pCastleInfo->getItemTaxRatio(), 							(int)pCastleInfo->getEntranceFee(), 							(int)pCastleInfo->getTaxBalance(), 							(int)g_pConfig->getPropertyInt( "ServerID" ),							(int)zoneID );		SAFE_DELETE(pStmt);	} 	END_DB(pStmt)	__END_CATCH}//////////////////////////////////////////////////////////////////////////////// add zone info to zone info manager//////////////////////////////////////////////////////////////////////////////void CastleInfoManager::addCastleInfo (CastleInfo* pCastleInfo) 	throw (Error){	__BEGIN_TRY	// 老窜 鞍篮 酒捞叼狼 粮捞 乐绰瘤 眉农秦夯促.	hash_map< ZoneID_t , CastleInfo *>::iterator itr = m_CastleInfos.find(pCastleInfo->getZoneID());		if (itr != m_CastleInfos.end())		// 度鞍篮 酒捞叼啊 捞固 粮犁茄促绰 家府促. - -;		throw Error("duplicated zone id");	m_CastleInfos[ pCastleInfo->getZoneID() ] = pCastleInfo;	// 己苞 包访等 葛电 ZoneID甫 殿废茄促.	const list<ZoneID_t>& zoneIDs = pCastleInfo->getZoneIDList();	list<ZoneID_t>::const_iterator iZoneID = zoneIDs.begin();	for (; iZoneID!=zoneIDs.end(); iZoneID++)	{		ZoneID_t zoneID = *iZoneID;		setCastleZoneID(zoneID, pCastleInfo->getZoneID());	}	__END_CATCH}	//////////////////////////////////////////////////////////////////////////////// Delete zone info from zone info manager//////////////////////////////////////////////////////////////////////////////void CastleInfoManager::deleteCastleInfo (ZoneID_t zoneID) 	throw (Error){	__BEGIN_TRY			hash_map< ZoneID_t , CastleInfo *>::iterator itr = m_CastleInfos.find(zoneID);		if (itr != m_CastleInfos.end()) 	{		// 粮阑 昏力茄促.		SAFE_DELETE(itr->second);		// pair甫 昏力茄促.		m_CastleInfos.erase(itr);	} 	else 	{		// 弊繁 粮 酒捞叼甫 茫阑 荐 绝菌阑 锭		return;	}	__END_CATCH}//////////////////////////////////////////////////////////////////////////////// get zone from zone info manager//////////////////////////////////////////////////////////////////////////////CastleInfo* CastleInfoManager::getCastleInfo (ZoneID_t zoneID) const	throw (Error){	__BEGIN_TRY			CastleInfo* pCastleInfo = NULL;	hash_map< ZoneID_t , CastleInfo *>::const_iterator itr = m_CastleInfos.find(zoneID);		if (itr != m_CastleInfos.end()) {		pCastleInfo = itr->second;	} else {		// 弊繁 粮 酒捞叼甫 茫阑 荐 绝菌阑 锭		return NULL;	}	return pCastleInfo;	__END_CATCH}//////////////////////////////////////////////////////////////////////////////// get debug string//////////////////////////////////////////////////////////////////////////////

⌨️ 快捷键说明

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