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

📄 actionredeemmotorcycle.cpp

📁 天之炼狱1服务器端源文件游戏服务端不完整
💻 CPP
字号:
////////////////////////////////////////////////////////////////////////////////// Filename    : ActionRedeemMotorcycle.cpp// Written By  : // Description :////////////////////////////////////////////////////////////////////////////////#include "ActionRedeemMotorcycle.h"#include "Creature.h"#include "GamePlayer.h"#include "Slayer.h"#include "Vampire.h"#include "ParkingCenter.h"#include "Item.h"#include "Zone.h"#include "DB.h"#include "ItemFactoryManager.h"#include "ItemUtil.h"#include "item/Key.h"#include "Gpackets/GCNPCResponse.h"////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////void ActionRedeemMotorcycle::read (PropertyBuffer & propertyBuffer)    throw (Error){    __BEGIN_TRY    __END_CATCH}////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////void ActionRedeemMotorcycle::execute (Creature * pCreature1 , Creature* pCreature2) 	throw (Error){	__BEGIN_TRY	Assert(pCreature1 != NULL);	Assert(pCreature2 != NULL);	Assert(pCreature1->isNPC());	Assert(pCreature2->isPC());	Player* pPlayer = pCreature2->getPlayer();	Assert(pPlayer != NULL);	// 老窜 努扼捞攫飘甫 困秦 ok菩哦阑 窍唱 朝妨林绊...	GCNPCResponse answerOKpkt;	pPlayer->sendPacket(&answerOKpkt);	// 敲饭捞绢啊 浇饭捞绢牢瘤 八荤茄促.	if (pCreature2->isSlayer())	{		Slayer*    pSlayer     = dynamic_cast<Slayer*>(pCreature2);		Zone*      pZone       = pSlayer->getZone();		Inventory* pInventory  = pSlayer->getInventory();		uint       InvenWidth  = pInventory->getWidth();		uint       InvenHeight = pInventory->getHeight();		Item*      pItem       = NULL;		// 牢亥配府甫 八祸茄促.		for (uint y=0; y<InvenHeight; y++)		{			for (uint x=0; x<InvenWidth; x++)			{				// x, y俊 酒捞袍捞 乐促搁...				if (pInventory->hasItem(x, y))				{					pItem = pInventory->getItem(x, y);					if (load(pItem, pSlayer, pZone, pSlayer->getX(), pSlayer->getY()))					{						return;					}				}			}		}	}	else // 轨颇捞绢扼搁...坷配官捞甫 茫酒临 捞蜡啊 乐阑鳖?	{	}	__END_CATCH}////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////bool ActionRedeemMotorcycle::load(Item* pItem, Slayer* pSlayer, Zone* pZone, ZoneCoord_t x, ZoneCoord_t y) const	throw(){	bool bFound = false;	__BEGIN_TRY	// 窜辑啊 登绰 酒捞袍捞 虐啊 酒聪扼搁 false甫 府畔.	if (pItem->getItemClass() != Item::ITEM_CLASS_KEY) return false;	Key* pKey = dynamic_cast<Key*>(pItem);	ItemID_t   targetID = pKey->getTarget();	try {	// 虐啊 嘎促搁 虐狼 鸥百捞 登绰 酒捞袍狼 酒捞袍 ID甫 掘绢辰促.	Statement* pStmt    = NULL;	Result*    pResult  = NULL;	// targetID啊 0牢 版快绰.. targetID(motorcycleObject狼 ItemID)啊 汲沥捞 救等 版快促.	// 捞 锭绰 烙矫肺 targetID甫 key狼 ItemID客 鞍霸 窍搁 等促...绊 夯促.	// targetID啊 motorcycle狼 itemID肺 甸绢啊扁 锭巩俊..	// broadcasting 殿俊辑.. Assert()俊 狼秦辑 促款登菌促...绊 焊咯柳促.  - -;	// by sigi. 2002.12.25 x-mas T_T;	if (targetID==0)	{		targetID = pKey->setNewMotorcycle(pSlayer);/*		// (!) MotorcycleObject甫 积己窍绊 MotorcycleItemID==Target甫 罐酒具 茄促.		// 捞 内靛 力惯 窃荐肺 哗扁甫.. -_-; by sigi		list<OptionType_t> optionNULL;		Item* pMotorcycle = g_pItemFactoryManager->createItem(Item::ITEM_CLASS_MOTORCYCLE, 0, optionNULL);		Assert(pMotorcycle != NULL);		(pZone->getObjectRegistry()).registerObject(pMotorcycle);		pMotorcycle->create(pSlayer->getName(), STORAGE_ZONE, pZone->getZoneID(), pSlayer->getX(), pSlayer->getY());		pKey->setTarget(pMotorcycle->getItemID());		targetID = pMotorcycle->getItemID();		// targetID甫 DB俊档 update矫难具 茄促.		BEGIN_DB		{			pStmt   = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement();			pResult = pStmt->executeQuery(						"UPDATE KeyObject SET Target=%d WHERE ItemID=%d", 									targetID, pKey->getItemID());			SAFE_DELETE(pStmt);		}		END_DB(pStmt)		// 关俊辑 pMotorcycle阑 荤侩秦档 登摆瘤父, 扁粮 内靛 救 扒靛副妨绊 咯扁辑 瘤款促. 		SAFE_DELETE(pMotorcycle);*/	}	else	{		// 茄锅 葛磐荤捞努捞尔 虐尔 楷搬灯绰单 葛磐荤捞努阑 穿啊 磊操 瘤快唱焊促.		// 虐俊 楷搬等 葛磐荤捞努捞 角力肺 叼厚俊 乐绰瘤 眉农窍绊 绝栏搁 货肺 父甸绢辑 持绢霖促.		BEGIN_DB		{			pStmt = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement();			pResult = pStmt->executeQuery("SELECT ItemID FROM MotorcycleObject WHERE ItemID=%lu", targetID);			if ( !pResult->next() )			{				Key* pKey = dynamic_cast<Key*>(pItem);				Assert( pKey != NULL );				targetID = pKey->setNewMotorcycle(pSlayer);			}			SAFE_DELETE(pStmt);		}		END_DB(pStmt);	}		// 鞘混 规绢 内靛 -_-;	if (targetID==0)	{		filelog("errorLog.txt", "[ActionRedeemMotorcycle] itemID=%d, motorItemID=%d", (int)pItem->getItemID(), (int)targetID);		return false;	}	// DB俊 孽府窍扁 傈俊 刚历 按眉啊 积己登绢 乐瘤绰 臼篮瘤 眉农茄促.	if (g_pParkingCenter->hasMotorcycleBox(targetID)) 	{		// 磊操 促款登绢辑 趣矫唱 窍绊..		// 老窜 林籍贸府茄促.  by sigi. 2002.11.16		/*		if (!pSlayer->hasRideMotorcycle()			&& !pSlayer->isFlag(Effect::EFFECT_CLASS_COMA))		{			//return false;			// by sigi. 2002.11.14			MotorcycleBox* pMotorcycleBox = g_pParkingCenter->getMotorcycleBox(targetID);			// 乐促搁 家券茄促.			if (pMotorcycleBox!=NULL				&& !pMotorcycleBox->isTransport())			{				Zone* pMotorZone = pMotorcycleBox->getZone();				ZoneCoord_t motorX = pMotorcycleBox->getX();				ZoneCoord_t motorY = pMotorcycleBox->getY();				Motorcycle* pMotorcycle = pMotorcycleBox->getMotorcycle();				// 鞍篮 粮俊 乐绰 版快				// 芭府啊 呈公 啊鳖快搁 何福瘤 富磊~				if (pMotorZone!=pZone					|| pSlayer->getDistance(motorX, motorY) > 15)				{					// 促弗 zone栏肺 捞悼吝捞扼绊 钎矫茄促.					pMotorcycleBox->setTransport();					// motorcycle阑 slayer狼 zone栏肺 颗变促.					pMotorZone->transportItem( motorX, motorY, pMotorcycle, 												pZone, pSlayer->getX(), pSlayer->getY() );					// Use OK 措侩捞促.					// Use窍搁 酒捞袍捞 荤扼瘤带啊 弊犯瘤 酵促. - -;					//GCCannotUse _GCCannotUse;					//_GCCannotUse.setObjectID(pPacket->getObjectID());					//pGamePlayer->sendPacket(&_GCCannotUse);					// 茄悼救 delay甫 拎具窍绰单..				}			}			return true;		}		*/		return false;	}	ItemID_t     itemID;	ItemType_t   itemType;	string 		 optionType;	Durability_t durability;	BEGIN_DB	{		StringStream sql;		sql << "SELECT ItemID, ItemType, OptionType, Durability "		    << "FROM MotorcycleObject where ItemID = " << targetID;				pStmt   = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement();		pResult = pStmt->executeQuery(sql.toString());		// by sigi. 2002.10.14		// 搬苞拱捞 绝促搁 葛磐荤捞努捞 绝绰 芭零.		if (pResult->getRowCount() <= 0) 		{			bFound = false;			itemID     = targetID;			itemType   = 0;			optionType = "";			durability = 300;		}		else 		{			bFound = true;			pResult->next();			itemID     = pResult->getInt(1);			itemType   = pResult->getInt(2);			optionType = pResult->getString(3);			durability = pResult->getInt(4);		}			// 葛磐荤捞努 按眉甫 积己茄促.			list<OptionType_t> optionTypes;			setOptionTypeFromField(optionTypes, optionType);			Motorcycle* pMotorcycle = new Motorcycle(itemType, optionTypes);			Assert(pMotorcycle != NULL);			pMotorcycle->setItemID(itemID);			pMotorcycle->setDurability(durability);			// 粮俊促 嘿捞扁 傈俊 oid甫 货肺 且寸罐绰促.			(pZone->getObjectRegistry()).registerObject(pMotorcycle);						// 积己茄 葛磐荤捞努阑 粮俊促 爱促嘿牢促.			TPOINT pt = pZone->addItem(pMotorcycle, x, y, false);			if (pt.x == -1)			{				// 坷配官捞甫 粮俊促 歹且 荐 绝菌促. 揪官.				filelog("motorError.txt", "ActionRedeemMotorcycle::load() : 葛磐荤捞努阑 粮俊促 歹且 荐 绝嚼聪促. zoneID=%d, xy=(%d, %d)", (int)pZone->getZoneID(), (int)x, (int)y);	// by sigi. 2002.12.24				throw Error("ActionRedeemMotorcycle::load() : 葛磐荤捞努阑 粮俊促 歹且 荐 绝嚼聪促");			}						// by sigi. 2002.10.14			if (!bFound)			{				pStmt->executeQuery(				"INSERT IGNORE INTO MotorcycleObject (ItemID, ObjectID, ItemType, OwnerID, Storage, StorageID, X, Y, OptionType, Durability) Values (%d, %d, %d, '', %d, %d, %d, %d, '', %d)",					itemID, pMotorcycle->getObjectID(), itemType, STORAGE_ZONE, pZone->getZoneID(), pt.x, pt.y, durability);			}			// 葛磐荤捞努阑 欢欧 季磐俊 殿废秦霖促.			MotorcycleBox* pBox = new MotorcycleBox(pMotorcycle, pZone, pt.x, pt.y);			Assert(pBox != NULL);			try {				g_pParkingCenter->addMotorcycleBox(pBox);			} catch (DuplicatedException& de) {	// by sigi. 2002.12.24				filelog("motorError.txt", "%s - itemID=%d, motorid=%d", de.toString().c_str(), itemID, pMotorcycle->getObjectID());			}			bFound = true;		//}				SAFE_DELETE(pStmt);	}	END_DB(pStmt)	} catch (Throwable& t) {	// by sigi. 2002.12.25		filelog("motorError.txt", "%s - itemID=%d, motorItemID=%d", t.toString().c_str(), (int)pItem->getItemID(), (int)targetID);		// 老窜 促款篮 阜磊.		//throw;	}	__END_CATCH	return bFound;}////////////////////////////////////////////////////////////////////////////////// get debug string////////////////////////////////////////////////////////////////////////////////string ActionRedeemMotorcycle::toString () const 	throw (){	__BEGIN_TRY	StringStream msg;	msg << "ActionRedeemMotorcycle(" << ")";	return msg.toString();	__END_CATCH}

⌨️ 快捷键说明

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