cgshoprequestbuyhandler.cpp

来自「天之炼狱1服务器端源文件游戏服务端不完整」· C++ 代码 · 共 927 行 · 第 1/3 页

CPP
927
字号
//////////////////////////////////////////////////////////////////////////////// Filename    : CGShopRequestBuyHandler.cpp// Written By  : 辫己刮// Description : //////////////////////////////////////////////////////////////////////////////#include "CGShopRequestBuy.h"#ifdef __GAME_SERVER__	#include "GamePlayer.h"	#include "NPC.h"	#include "Slayer.h"	#include "Vampire.h"	#include "ItemInfo.h"	#include "ItemInfoManager.h"	#include "ItemFactoryManager.h"	#include "PriceManager.h"	#include "Tile.h"	#include "ParkingCenter.h"	#include "ItemUtil.h"	#include "LogClient.h"	#include "ZoneUtil.h"	#include "CastleInfoManager.h"	#include "Utility.h"	#include "item/Key.h"	#include "item/Potion.h"	#include "item/Magazine.h"	#include "Gpackets/GCShopBuyOK.h"	#include "Gpackets/GCShopBuyFail.h"	#include "Gpackets/GCShopSold.h"	#include "SystemAvailabilitiesManager.h"	#include <stdio.h>#endif//////////////////////////////////////////////////////////////////////////////// 敲饭捞绢啊 盔窍绰 拱扒阑 颇绰 NPC客 弊 酒捞袍捞 乐绰瘤// 犬牢窍绊, 老馆 酒捞袍苞 葛磐 荤捞努 贸府何盒栏肺 盒扁茄促.//////////////////////////////////////////////////////////////////////////////void CGShopRequestBuyHandler::execute (CGShopRequestBuy* pPacket , Player* pPlayer)	 throw (ProtocolException , Error){	__BEGIN_TRY __BEGIN_DEBUG_EX#ifdef __GAME_SERVER__		Assert(pPacket != NULL);	Assert(pPlayer != NULL);	// 菩哦 沥焊甫 惶酒辰促.	ObjectID_t      NPCID       = pPacket->getObjectID();	ShopRackType_t  shopType    = pPacket->getShopType();	BYTE            shopIndex   = pPacket->getShopIndex();	ItemNum_t       itemNum     = pPacket->getItemNum();	GamePlayer*     pGamePlayer = dynamic_cast<GamePlayer*>(pPlayer);	Creature*       pNPCBase    = NULL;	Creature* pPC = pGamePlayer->getCreature();	Assert(pPC != NULL);	Zone* pZone = pPC->getZone();	Assert(pZone != NULL);	if ( shopType == SHOP_RACK_MYSTERIOUS )	{		SYSTEM_ASSERT( SYSTEM_GAMBLE );	}	//try 	//{ 	// NoSuch力芭. by sigi. 2002.5.2	pNPCBase = pZone->getCreature(NPCID); 	//}		if (pNPCBase==NULL)//catch (NoSuchElementException) 	{ 		GCShopBuyFail gcShopBuyFail;		gcShopBuyFail.setCode(GC_SHOP_BUY_FAIL_NPC_NOT_EXIST);		gcShopBuyFail.setAmount(0);		pPlayer->sendPacket(&gcShopBuyFail);		return;	}	if (!pNPCBase->isNPC())	{		GCShopBuyFail gcShopBuyFail;		gcShopBuyFail.setCode(GC_SHOP_BUY_FAIL_NOT_NPC);		gcShopBuyFail.setAmount(0);		pPlayer->sendPacket(&gcShopBuyFail);		return;	}	NPC* pNPC = dynamic_cast<NPC*>(pNPCBase);	/*	// 惑痢俊 酒捞袍 乐绰瘤 绝绰瘤 眉农侩	for (int i=0; i<=2; i++)	{		for (int j=0; j<20; j++)		{			cout << (int)pNPC->isExistShopItem(i, j) << " ";		}		cout << endl;	}	*/	if (pNPC->getShopType() == SHOPTYPE_NORMAL)	{		// 敲饭捞绢啊 备涝窍绊磊 窍绰 酒捞袍阑 NPC啊 啊瘤绊 乐绰瘤 八荤		if (pNPC->isExistShopItem(shopType, shopIndex) == false) 		{			GCShopBuyFail gcShopBuyFail;			gcShopBuyFail.setCode(GC_SHOP_BUY_FAIL_ITEM_NOT_EXIST);			gcShopBuyFail.setAmount(0);			pPlayer->sendPacket(&gcShopBuyFail);			return;		}		Item* pItem = pNPC->getShopItem(shopType, shopIndex);		// 酒捞袍 肮荐啊 沥惑利牢瘤甫 八荤		if (itemNum < 1 || itemNum > ItemMaxStack[pItem->getItemClass()])		{			throw ProtocolException("CGShopRequestBuyHandler::execute() : 酒捞袍 肮荐 坷幅!");		}		// 酒捞袍 肮荐啊 2俺 捞惑捞扼搁 沥惑利牢 酒捞袍牢瘤甫 八荤		// 阶老 荐 乐绰 酒捞袍捞 酒聪扼搁 肮荐甫 1肺 技泼秦 霖促.		if (itemNum > 1 && !isStackable(pItem->getItemClass()))			pPacket->setItemNum(1);		if (pItem->getItemClass() == Item::ITEM_CLASS_MOTORCYCLE) executeMotorcycle(pPacket, pPlayer);		else executeNormal(pPacket, pPlayer);	}///////////////////////////////////////////////////////////////////////// 2001斥 农府胶付胶 捞亥飘甫 困秦辑 荤侩等 窃荐捞促.// 2002斥 绢赴捞朝 捞亥飘甫 困秦辑 犁荤侩凳. // XMAS_EVENT俊辑 STAR_EVENT肺 荐沥登绢具 且 巴栏肺 抗沥//  2002.5.2 厘全芒(changaya@metrotech.co.kr)//////////////////////////////////////////////////////////////////////#ifdef __XMAS_EVENT_CODE__	else if (pNPC->getShopType() == SHOPTYPE_EVENT)	{		// 敲饭捞绢啊 备涝窍绊磊 窍绰 酒捞袍阑 NPC啊 啊瘤绊 乐绰瘤 八荤		if (pNPC->isExistShopItem(shopType, shopIndex) == false) 		{			GCShopBuyFail gcShopBuyFail;			gcShopBuyFail.setCode(GC_SHOP_BUY_FAIL_ITEM_NOT_EXIST);			gcShopBuyFail.setAmount(0);			pPlayer->sendPacket(&gcShopBuyFail);			return;		}		// 酒捞袍 肮荐啊 沥惑利牢瘤甫 八荤		if (itemNum != 1) 			throw ProtocolException("CGShopRequestBuyHandler::execute() : 酒捞袍 肮荐 坷幅!");		executeEvent(pPacket, pPlayer);	}#endif	//cout << "Buy ok" << endl;#endif	__END_DEBUG_EX __END_CATCH}//////////////////////////////////////////////////////////////////////////////// 老馆 酒捞袍狼 备涝阑 贸府茄促.//////////////////////////////////////////////////////////////////////////////void CGShopRequestBuyHandler::executeNormal (CGShopRequestBuy* pPacket , Player* pPlayer)	 throw (ProtocolException , Error){	__BEGIN_TRY __BEGIN_DEBUG_EX#ifdef __GAME_SERVER__	ObjectID_t      NPCID       = pPacket->getObjectID();	ShopRackType_t  shopType    = pPacket->getShopType();	BYTE            shopIndex   = pPacket->getShopIndex();	ItemNum_t       itemNum     = pPacket->getItemNum();	Coord_t         x           = pPacket->getX();	Coord_t         y           = pPacket->getY();	GamePlayer*     pGamePlayer = dynamic_cast<GamePlayer*>(pPlayer);	Creature*       pCreature   = pGamePlayer->getCreature();	PlayerCreature* pPC         = dynamic_cast<PlayerCreature*>(pCreature);	Zone*           pZone       = pPC->getZone();	NPC*            pNPC        = dynamic_cast<NPC*>(pZone->getCreature(NPCID));	// NoSuch力芭. by sigi. 2002.5.2	if (pNPC==NULL) return;	Item*           pItem       = pNPC->getShopItem(shopType, shopIndex);	Price_t         itemMoney;	bool 			bMysteriousRack = (shopType==SHOP_RACK_MYSTERIOUS);	// Mysterious item篮 啊拜 拌魂捞 促福促.	if (bMysteriousRack)	{		//cout << pPacket->toString().c_str() << endl;		itemMoney = g_pPriceManager->getMysteriousPrice(pItem->getItemClass(), pCreature);		//cout << "CGShopRequestBuyHandler::MysteriousItem Price = " << itemMoney << endl;	}	else	{		itemMoney = g_pPriceManager->getPrice(pItem, pNPC->getMarketCondSell(), shopType, pPC) * itemNum;		//cout << "CGShopRequestBuyHandler::normalItem Price = " << itemMoney << endl;	}	if ( pZone->isCastle() ) 	{		int itemTaxRatio = g_pCastleInfoManager->getItemTaxRatio( pPC );		if (itemTaxRatio > 100)		{			int NewItemMoney = getPercentValue((int)itemMoney, itemTaxRatio);			Gold_t itemTax = ( NewItemMoney - itemMoney ) / 2;	// 技陛狼 例馆父 陛绊俊 持绰促.			g_pCastleInfoManager->increaseTaxBalance( pZone->getZoneID(), itemTax );			itemMoney = NewItemMoney;		}	}	Item::ItemClass IClass     	 	= pItem->getItemClass();	ItemType_t      IType   	    = pItem->getItemType();	const list<OptionType_t>& OType = pItem->getOptionTypeList();	Inventory* pInventory  = pPC->getInventory();	Gold_t     playerMoney = pPC->getGold();	if (playerMoney < itemMoney)	{		GCShopBuyFail gcShopBuyFail;		gcShopBuyFail.setCode(GC_SHOP_BUY_FAIL_NOT_ENOUGH_MONEY);		gcShopBuyFail.setAmount(0);		pPlayer->sendPacket(&gcShopBuyFail);		//cout << "Not Enough Money for Mysterious Item" << endl;		return;	}		// mysterious item阑 积己秦滚赴促.	if (bMysteriousRack)	{		if (pZone->isPremiumZone() || pZone->isPayPlay())		{			pItem = getRandomMysteriousItem( pCreature, IClass );		}		else		{			// premium zone捞 酒聪搁 gamble level阑 30栏肺 力茄茄促.			pItem = getRandomMysteriousItem( pCreature, IClass, 30 );		}		Assert(pItem!=NULL);		(pZone->getObjectRegistry()).registerObject(pItem);	}	// 刚历 器记捞唱, 藕芒 鞍篮 版快俊绰 酒捞袍 肮荐甫 技泼秦 林绊 唱辑...	if (isStackable(pItem))	{		pItem->setNum(itemNum);	}	else	{		pItem->setNum(1);	}	if (!pInventory->canAddingEx(x, y, pItem))	{		GCShopBuyFail gcShopBuyFail;		gcShopBuyFail.setCode(GC_SHOP_BUY_FAIL_NOT_ENOUGH_SPACE);		gcShopBuyFail.setAmount(0);		pPlayer->sendPacket(&gcShopBuyFail);		// mysterious item篮 困俊辑 getRandomMysteriousItem()阑 烹秦辑		// 积己登菌扁 锭巩俊 瘤况拎具 茄促.		if (bMysteriousRack) SAFE_DELETE(pItem);		//cout << "Can't Add to Inventory" << endl;		return;	}	if ( pItem != NULL ) pItem->whenPCTake( pPC );	// 敲饭捞绢啊 魂 酒捞袍捞 胶其既 酒捞袍捞扼搁 惑痢 滚傈阑 棵赴促.	if (shopType == SHOP_RACK_SPECIAL)	{		pNPC->increaseShopVersion(shopType);	}	// 敲饭捞绢狼 捣阑 临牢促.	//pPC->setGoldEx(playerMoney - itemMoney);	// by sigi. 2002.9.4	pPC->decreaseGoldEx(itemMoney);	//cout << "addItemEx" << endl;	Item* pReturnItem = pInventory->addItemEx(x, y, pItem);	if (pReturnItem == pItem)

⌨️ 快捷键说明

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