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

📄 actionprepareshop.cpp

📁 天之炼狱1服务器端源文件游戏服务端不完整
💻 CPP
字号:
//////////////////////////////////////////////////////////////////////////////// Filename    : ActionPrepareShop.cpp// Written By  : // Description : // 惑痢 NPC甫 力老 贸澜 肺爹且 锭, 惑痢 NPC啊 迫霸 瞪 酒捞袍阑// 霖厚窍绰 咀记捞促. ShopTemplate 努贰胶客 概聪历甫 曼绊且 巴.//////////////////////////////////////////////////////////////////////////////#include "ActionPrepareShop.h"#include "Creature.h"#include "NPC.h"#include "GamePlayer.h"#include "ShopTemplate.h"#include "OptionInfo.h"#include "DB.h"#include "LogClient.h"#include "ItemFactoryManager.h"#include <stdlib.h>#include <stdio.h>#include <math.h>#include <vector>////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////ActionPrepareShop::ActionPrepareShop()	throw(){	__BEGIN_TRY	m_ListNum        = 0;	m_MarketCondBuy  = 100;	m_MarketCondSell = 100;	__END_CATCH}////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////ActionPrepareShop::~ActionPrepareShop()	throw(){	__BEGIN_TRY	clearList();	__END_CATCH}////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////void ActionPrepareShop::read (PropertyBuffer & propertyBuffer)    throw (Error){	__BEGIN_TRY	try 	{		int        NPCID = propertyBuffer.getPropertyInt("NPCID");		Statement* pStmt = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement();		BEGIN_DB		{			Result* pResult = pStmt->executeQuery("SELECT ID from ShopTemplate where NPCID = %d", NPCID);			while (pResult->next())			{				ShopTemplateID_t id = pResult->getInt(1);				addListElement(id);			}			delete pStmt;		}		END_DB(pStmt)		m_MarketCondBuy  = propertyBuffer.getPropertyInt("MarketConditionBuy");		m_MarketCondSell = propertyBuffer.getPropertyInt("MarketConditionSell");	} 	catch (NoSuchElementException & nsee)	{		throw Error(nsee.toString());	}		__END_CATCH}//////////////////////////////////////////////////////////////////////////////// 咀记阑 角青茄促.// NOTE : ShopTemplate篮 捞 咀记捞 角青登扁 傈俊 葛滴 肺靛登绢 乐绢具 茄促.//////////////////////////////////////////////////////////////////////////////void ActionPrepareShop::execute (Creature * pCreature1 , Creature * pCreature2) 	throw (Error){	__BEGIN_TRY	Assert(pCreature1 != NULL);	Assert(pCreature1->isNPC());	NPC * pNPC = dynamic_cast<NPC*>(pCreature1);	// IDList    : ShopTemplate ID甫 柳凯厘 辆幅俊 蝶扼 盒幅秦 历厘窍扁	//             困茄 府胶飘甸.	// combi[]   : Class付促 minItemType苞 maxItemType俊 狼秦辑 炼钦捞 积变促.	//             捞 炼钦狼 醚 肮荐甫 历厘窍扁 困茄 硅凯	// count[]   : 泅犁 NPC啊 柳凯厘俊 啊瘤绊 乐绰 酒捞袍狼 荐. 开矫 辆幅喊.		list<ShopTemplateID_t> IDList[SHOP_RACK_TYPE_MAX];	int                    combi[SHOP_RACK_TYPE_MAX] = {0,0,0};	int                    count[SHOP_RACK_TYPE_MAX] = {0,0,0};	int                    trialMax = 0;	ShopTemplate*          pTemplate = NULL;	ShopRackType_t         shopType;	int                    itemClass;	ItemType_t             minItemType, maxItemType, itemType;	uint                   minOptionLevel, maxOptionLevel;	OptionType_t           optionType;	// 阿阿狼 讥袍敲复篮 酒捞袍 努贰胶客 弥家, 弥措 鸥涝阑 啊瘤绊 乐促.	// 弥家, 弥措 鸥涝阑 啊瘤绊, 秦寸窍绰 酒捞袍 割 啊瘤甫 	// 积己秦具 茄促绰 巴阑 舅 荐 乐促. 抗甫 甸搁 促澜苞 鞍促.	// MinItemType : 0, MaxItemType : 0 --> 1啊瘤	// MinItemType : 0, MaxItemType : 2 --> 3啊瘤	for (list<ShopTemplateID_t>::const_iterator itr=m_List.begin(); itr != m_List.end(); itr++)	{		// 袍敲复 府胶飘俊辑 窍唱甫 惶酒柯促.		pTemplate = g_pShopTemplateManager->getTemplate((*itr));		Assert(pTemplate != NULL);				shopType    = pTemplate->getShopType();		itemClass   = pTemplate->getItemClass();		minItemType = pTemplate->getMinItemType();		maxItemType = pTemplate->getMaxItemType();				// 讥狼 辆幅(畴钢, 胶其既...)俊 蝶扼		// 积己且 讥 袍敲复狼 ID甫 府胶飘俊 笼绢持绢 滴绊,		// 积己且 酒捞袍狼 辆幅 荐甫 历厘秦 敌促.		IDList[shopType].push_back(*itr);		combi[shopType] += (maxItemType - minItemType + 1);	}	// 阿 讥俊促 酒捞袍阑 积己茄促.	for (ShopRackType_t i=0; i<SHOP_RACK_TYPE_MAX; i++)	{		// 炼钦狼 箭磊肺辑 茄 努贰胶狼 茄 鸥涝 酒捞袍捞 倔付唱 腹捞 柳凯厘俊		// 硅摹瞪 荐 乐绰瘤 舅酒辰促.		// ex) 傈眉 酒捞袍狼 炼钦捞 9啊瘤捞扼搁, 20/9 = 3. 溜 茄 努贰胶狼		// 茄 鸥涝 酒捞袍篮 弥措 3俺鳖瘤 柳凯厘俊 唱鸥朝 荐 乐促.		if (combi[i] == 0) trialMax = 0;		else trialMax = (int)(floor(SHOP_RACK_INDEX_MAX/combi[i]));		// 父老 讥 鸥涝捞 畴钢捞扼搁, 鞍篮 酒捞袍阑 咯矾 俺 		// 积己窍绰 巴篮 狼固啊 绝栏骨肺, 茄锅父 酒捞袍阑 积己茄促.		if (i == SHOP_RACK_NORMAL			|| i==SHOP_RACK_MYSTERIOUS) trialMax = 1;		// 酒鳖 历厘秦 初疽带 讥 袍敲复 ID 府胶飘俊辑 窍唱究阑 惶酒客辑		// 惑痢 酒捞袍阑 积己茄促.		for (list<ShopTemplateID_t>::const_iterator itr=IDList[i].begin(); itr != IDList[i].end(); itr++)		{			pTemplate      = g_pShopTemplateManager->getTemplate((*itr));			itemClass      = pTemplate->getItemClass();			minItemType    = pTemplate->getMinItemType();			maxItemType    = pTemplate->getMaxItemType();			minOptionLevel = pTemplate->getMinOptionLevel();			maxOptionLevel = pTemplate->getMaxOptionLevel();			// 刚历 积己 啊瓷茄 可记 鸥涝狼 氦磐甫 积己秦敌促.			vector<OptionType_t> optionVector = g_pOptionInfoManager->getPossibleOptionVector((Item::ItemClass)itemClass, minOptionLevel, maxOptionLevel);			for (ItemType_t type=minItemType; type<=maxItemType; type++)			{				// 茄 鸥涝狼 讥俊绰 20鳖瘤狼 酒捞袍捞 甸绢埃促.				// 父老 积己秦具 且 酒捞袍狼 辆幅啊 5啊瘤扼搁				// 阿阿狼 酒捞袍阑 4俺鳖瘤 笼绢持阑 荐 乐促.				// 辆幅啊 6啊瘤扼搁, 3俺鳖瘤 笼绢持阑 荐 乐促.				for (int tc=0; tc<trialMax; tc++)				{					itemType  = type;					// 可记 氦磐 郴俊辑 公累困肺 可记阑 惶酒辰促.					// 寸楷洒 啊瓷茄 可记捞 绝促搁, optionType篮 0(公可记)捞促.					Item::ItemClass IClass = Item::ItemClass(itemClass);					list<OptionType_t> optionTypes; 					if (i!=SHOP_RACK_MYSTERIOUS && optionVector.size() > 0) 					{						optionType = optionVector[(rand()%optionVector.size())];						if (optionType!=0)							optionTypes.push_back( optionType );					}										// 角力肺 酒捞袍阑 父电促.					Item* pItem = g_pItemFactoryManager->createItem(IClass, itemType, optionTypes);					Assert(pItem != NULL);					// zone狼 object registery俊 殿废.					(pNPC->getZone()->getObjectRegistry()).registerObject(pItem);					// 秦寸 柳凯厘俊 磊府啊 乐促搁 酒捞袍阑 歹茄促.					if (count[i] < SHOP_RACK_INDEX_MAX)					{						pNPC->insertShopItem(i, count[i], pItem);						count[i] = count[i]++;						log(LOG_SHOP_CREATE_ITEM, pNPC->getName(), "", pItem->toString());					}				}			}		}	}	pNPC->setMarketCondBuy(m_MarketCondBuy);	pNPC->setMarketCondSell(m_MarketCondSell);	__END_CATCH}////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////void ActionPrepareShop::addListElement(ShopTemplateID_t id)	throw(){	__BEGIN_TRY			m_List.push_back(id);	m_ListNum++;	__END_CATCH}////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////string ActionPrepareShop::toString () const 	throw (){	__BEGIN_TRY	StringStream msg;	int          i = 0;	msg << "ActionPrepareShop(";	list<ShopTemplateID_t>::const_iterator itr=m_List.begin();	for (;itr != m_List.end(); itr++)		msg << "Item" << i++ << ":" << (int)(*itr) << ",";	msg << ")";	return msg.toString();	__END_CATCH}

⌨️ 快捷键说明

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