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

📄 actionregeneventshop.cpp

📁 天之炼狱1服务器端源文件游戏服务端不完整
💻 CPP
字号:
////////////////////////////////////////////////////////////////////////////////// Filename    : ActionRegenEventShop.cpp// Written By  : excel96// Description : // 农府胶付胶 捞亥飘侩 惑痢阑 盎脚窍绰 咀记////////////////////////////////////////////////////////////////////////////////#include "ActionRegenEventShop.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>////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////ActionRegenEventShop::ActionRegenEventShop()	throw(){	__BEGIN_TRY	m_Period.tv_sec     = 0;	m_Period.tv_usec    = 0;	m_NextRegen.tv_sec  = 0;	m_NextRegen.tv_usec = 0;	__END_CATCH}////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////ActionRegenEventShop::~ActionRegenEventShop()	throw(){	__BEGIN_TRY	clearList();	__END_CATCH}////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////void ActionRegenEventShop::read (PropertyBuffer & propertyBuffer)    throw (Error){	__BEGIN_TRY	try 	{	    // read NPC id		int        NPCID   = propertyBuffer.getPropertyInt("NPCID");		Statement* pStmt   = NULL;		Result*    pResult = NULL;		BEGIN_DB		{			pStmt   = g_pDatabaseManager->getConnection("DARKEDEN")->createStatement();			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)		// 惑痢 诀单捞飘 林扁甫 佬绢甸牢促. (檬 窜困)		int nSecond = propertyBuffer.getPropertyInt("Period");		m_Period.tv_sec = nSecond;		// 促澜 惑痢 诀单捞飘甫 攫力 且 巴牢啊甫 技泼秦 霖促.		Timeval currentTime;		getCurrentTime(currentTime);		m_NextRegen = currentTime;	} 	catch (NoSuchElementException & nsee)	{		throw Error(nsee.toString());	}		__END_CATCH}////////////////////////////////////////////////////////////////////////////////// 咀记阑 角青茄促.// NOTE : ShopTemplate篮 捞 咀记捞 角青登扁 傈俊 葛滴 肺靛登绢 乐绢具 茄促.////////////////////////////////////////////////////////////////////////////////void ActionRegenEventShop::execute (Creature * pCreature1 , Creature * pCreature2) 	throw (Error){	__BEGIN_TRY	Assert(pCreature1 != NULL);	Assert(pCreature1->isNPC());	NPC* pNPC = dynamic_cast<NPC*>(pCreature1);	Assert(pNPC != NULL);	// 捞亥飘侩 NPC肺 汲沥秦霖促. 	pNPC->setShopType(SHOPTYPE_EVENT);	Zone* pZone = pNPC->getZone();	Assert(pZone != NULL);	// 泅犁 矫埃阑 掘绢辰促.	Timeval currentTime;	getCurrentTime(currentTime);	// 诀单捞飘且 矫埃捞 酒流 登流 臼疽促搁 傲 府畔茄促.	if (currentTime < m_NextRegen) return;	// 林困俊 PC尔 捞具扁窍绊 乐绰 敲饭捞绢啊 绝绰瘤 刚历 八荤茄促.	VSRect rect(0, 0, pZone->getWidth()-1, pZone->getHeight()-1);	int centerX = pNPC->getX();	int centerY = pNPC->getY();	try	{		for (int zx = centerX - 5; zx <= centerX+5; zx++)		{			for (int zy = centerY - 5; zy <= centerY+5; zy++)			{				// 谅钎啊 茄拌甫 逞绢啊瘤 臼疽绰瘤 眉农...				if (!rect.ptInRect(zx, zy))				{					continue;				}				Tile& tile = pZone->getTile(zx, zy);				// 吧绢促聪绰 农府媚甫 八祸				if (tile.hasCreature(Creature::MOVE_MODE_WALKING))				{					Creature* pNearCreature = tile.getCreature(Creature::MOVE_MODE_WALKING);					Assert(pNearCreature != NULL);					// NPC尔 捞具扁窍绊 乐绰 仇捞 乐栏搁 傲 府畔					if (pNearCreature->isPC())					{						return;					}				}				// 朝酒促聪绰 农府媚甫 八祸				if (tile.hasCreature(Creature::MOVE_MODE_FLYING))				{					Creature* pNearCreature = tile.getCreature(Creature::MOVE_MODE_FLYING);					Assert(pNearCreature != NULL);					// NPC尔 捞具扁窍绊 乐绰 仇捞 乐栏搁 傲 府畔					if (pNearCreature->isPC())					{						return;					}				}			}		}	}	catch (Throwable & t)	{		filelog("shopbug.txt", "%s", t.toString().c_str());		return;	}	// 刚历 NPC啊 啊瘤绊 乐绰 酒捞袍阑 傈何 朝府绊...惑痢 滚傈阑 棵赴促.	// 老窜 努府绢窍扁 傈俊 肺弊甫 茄促.	for (ShopRackType_t rackType=0; rackType<SHOP_RACK_TYPE_MAX; rackType++)	{		for (BYTE rackIndex=0; rackIndex<SHOP_RACK_INDEX_MAX; rackIndex++)		{			Item* pShopItem = pNPC->getShopItem(rackType, rackIndex);			if (pShopItem != NULL)				log(LOG_SHOP_DESTROY_ITEM, pNPC->getName(), "", pShopItem->toString());		}	}	pNPC->clearShopItem();	for (int i=0; i<SHOP_RACK_TYPE_MAX; i++)		pNPC->increaseShopVersion(i);	// 酒捞袍阑 父电促.	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++)	{		// 茄 鸥涝狼 讥俊绰 20俺鳖瘤狼 酒捞袍捞 甸绢埃促.		// 父老 积己秦具 且 酒捞袍狼 辆幅啊 5啊瘤扼搁,		// 阿阿狼 酒捞袍阑 4俺鳖瘤 笼绢持阑 荐 乐促.		// 辆幅啊 6啊瘤扼搁, 3俺鳖瘤 笼绢持阑 荐 乐促.		// 捞 矫档 冉荐甫 trialMax 函荐俊促 笼绢持绰促.		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);			// ShopTemplate俊辑 ItemType捞 2,3捞 唱柯促搁 optionType篮 +2肺 炼例窍绊			// ShopTemplate俊辑 ItemType捞 促弗 巴捞扼搁, +3鳖瘤 林档废 茄促.			vector<OptionType_t> optionVector;			if(minItemType == 2 && maxItemType == 3)			{				optionVector.push_back(2);  // STR+2				optionVector.push_back(7);  // DEX+2				optionVector.push_back(12); // INT+2				//optionVector.push_back(50); // DAM+3				optionVector.push_back(79); // ASPEED+2			}			else if(minItemType == 4 && maxItemType ==5)			{				optionVector.push_back(3);  // STR+3				optionVector.push_back(8);  // DEX+3				optionVector.push_back(13); // INT+3				//optionVector.push_back(50); // DAM+3				optionVector.push_back(80); // ASPEED+3			}			else if(minItemType == 6 && maxItemType == 6)			{				optionVector.push_back(4);  // STR+4				optionVector.push_back(9);  // DEX+4				optionVector.push_back(14); // INT+4				//optionVector.push_back(50); // DAM+3				optionVector.push_back(80); // ASPEED+3			}			for (ItemType_t type=minItemType; type<=maxItemType; type++)			{				// 茄 鸥涝狼 讥俊绰 20俺鳖瘤狼 酒捞袍捞 甸绢埃促.				// 父老 积己秦具 且 酒捞袍狼 辆幅啊 5啊瘤扼搁,				// 阿阿狼 酒捞袍阑 4俺鳖瘤 笼绢持阑 荐 乐促.				// 辆幅啊 6啊瘤扼搁, 3俺鳖瘤 笼绢持阑 荐 乐促.				for (int tc=0; tc<trialMax; tc++)				{					itemType = type;					// 可记 氦磐 郴俊辑 公累困肺 可记阑 惶酒辰促.					// 寸楷洒 啊瓷茄 可记捞 绝促搁, optionType篮 0(公可记)捞促.					if (optionVector.size() > 0)					{						int randValue = rand();						int size      = optionVector.size();						int index     = randValue%size;						optionType = optionVector[index];					}					else optionType = 0;					// 角力肺 酒捞袍阑 父电促.					Item::ItemClass IClass = Item::ItemClass(itemClass);					list<OptionType_t> optionTypes;					if (optionType!=0)						optionTypes.push_back( optionType );					Item* pItem = g_pItemFactoryManager->createItem(IClass, itemType, optionTypes);					Assert(pItem != NULL);					// zone狼 object registery俊 殿废.					(pZone->getObjectRegistry()).registerObject(pItem);					// 秦寸 柳凯厘俊 磊府啊 乐促搁 酒捞袍阑 歹茄促.					if (count[i] < SHOP_RACK_INDEX_MAX)					{						pNPC->insertShopItem(i, count[i], pItem);						count[i] = count[i] + 1;					}				}			}		}	}	// 促澜 诀单捞飘且 矫埃阑 沥秦霖促.	m_NextRegen = m_NextRegen + m_Period;	__END_CATCH}////////////////////////////////////////////////////////////////////////////////// get debug string////////////////////////////////////////////////////////////////////////////////string ActionRegenEventShop::toString () const 	throw (){	__BEGIN_TRY	StringStream msg;	int          i = 0;	msg << "ActionRegenEventShop(";	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 + -