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

📄 monsterai.cpp

📁 天之炼狱1服务器端源文件游戏服务端不完整
💻 CPP
📖 第 1 页 / 共 4 页
字号:
		/*		Dir_t bestDir;		////////////////////////////////////////////////////////////		// (nx, ny)俊辑 格利瘤痢栏肺 氢窍绰 弥急狼 规氢阑 茫绰促.		////////////////////////////////////////////////////////////		if (nx < ex) 		{			if (ny < ey)      bestDir = RIGHTDOWN;			else if (ny > ey) bestDir = RIGHTUP;			else              bestDir = RIGHT;// m_pBody->getY() == ey		} 		else if (nx > ex) 		{			if (ny < ey)      bestDir = LEFTDOWN;			else if (ny > ey) bestDir = LEFTUP;			else              bestDir = LEFT;// m_pBody->getY() == ey		} 		else 		{				if (ny < ey)      bestDir = DOWN; // m_pBody->getX() == ex			else if (ny > ey) bestDir = UP;			else              bestDir = DIR_NONE; // m_pBody->getY() == ey		}		ZoneCoord_t bx = nx + dirMoveMask[bestDir].x;		ZoneCoord_t by = ny + dirMoveMask[bestDir].y;		*/		// 茄 沫 捞悼沁阑锭狼		// best规氢捞 block捞 登绢乐瘤 臼篮 版快俊父 寒鸥扁甫 弊父敌促.		//if (m_pBody->canMove(bx,by)) 		{			// 寒鸥扁甫 弊父敌促.			//cout << "FindBest : " << (int)m_BlockedDir << " - " << m_pBody->getName() << endl;			setMoveRule( MOVE_RULE_NORMAL );		}		return true;	}	const Dir_t DIR_MAX_1 = DIR_MAX-1;	Dir_t dirInc, dirWallInc;	if (bLeft)		{		// 谅荐过		dirInc = 7;		//	+DIR_MAX-1;		dirWallInc = 2;	// 寒捞 乐绢具窍绰 规氢	}	else			{		// 快荐过		dirInc = 1;		dirWallInc = 6;	// +DIR_MAX-3 寒捞 乐绢具窍绰 规氢	}	// 寒捞 乐绢具窍绰 规氢何磐 眉农	ndir = (m_pBody->getDir() + dirWallInc) & DIR_MAX_1;		//----------------------------------------------------------	// 哎妨绰 规氢栏肺 哎 荐 乐栏搁 啊搁 等促.	// 	// 哎 荐 绝绰 捞蜡啊 甘俊 狼茄 block捞 酒囱 版快捞搁 	//        寒鸥扁甫 弊父敌促.	//----------------------------------------------------------	for (int i=0; i<DIR_MAX; i++)	{		// 促澜 谅钎		nx = m_pBody->getX() + dirMoveMask[ndir].x;		ny = m_pBody->getY() + dirMoveMask[ndir].y;		if (m_pBody->canMove(nx,ny))		{			// 公炼扒 啊滚府搁 等促.			// 寒捞 乐绢具 登绰 困摹			//Dir_t 		dirWall = (ndir + dirWallInc) & DIR_MAX_1;			//ZoneCoord_t wallx 	= m_pBody->getX() + dirMoveMask[dirWall].x;			//ZoneCoord_t wally 	= m_pBody->getY() + dirMoveMask[dirWall].y;			// 哎 荐 绝绊 creature俊 狼茄 block捞 酒聪搁 寒捞促.			//if (!m_pBody->canMove(wallx,wally)			//	&& !m_pBody->isBlockedByCreature(wallx,wally)) 			{				//cout << "FindWay : " << (int)dirWall << " - go : " << (int)ndir << " - " << m_pBody->getName() << endl;				return true;			}		}		// 促弗 creature俊 狼秦辑 哎 荐 绝促搁 寒鸥扁甫 弊父敌促.		else if (m_pBody->isBlockedByCreature(nx,ny))		{			break;		}		// 促澜 规氢		ndir = (ndir+dirInc) & DIR_MAX_1;	}	// 寒鸥扁肺 酒公镑档 哎 荐 绝促搁 寒鸥扁甫 弊父敌促. 	setMoveRule( MOVE_RULE_NORMAL );	//cout << "Can't go Wall : " << m_pBody->getName() << endl;	return false;}//////////////////////////////////////////////////////////////////////////////// 青悼 窃荐 (傍拜 包访)//////////////////////////////////////////////////////////////////////////////bool MonsterAI::move(ZoneCoord_t ex, ZoneCoord_t ey)	throw(){	Zone*       pZone   = m_pBody->getZone();	// 窍捞靛 惑怕俊辑绰 框流捞搁 帮鄂窍促...	//if (m_pBody->isFlag(Effect::EFFECT_CLASS_HIDE))	//{	//	m_LastAction = LAST_ACTION_MOVE;	//	return true;	//}		// 捞悼且 困摹,规氢	ZoneCoord_t nx, ny; 	Dir_t ndir;	// 捞悼 规过俊 蝶扼辑 捞悼且 镑阑 搬沥茄促.	bool found = false;	switch (m_MoveRule)	{		// 焊烹狼 捞悼		case MOVE_RULE_NORMAL :			found = moveNormal(ex, ey, nx, ny, ndir);		break;		// 谅荐过		case MOVE_RULE_LEFTWALL :			found = moveWall(ex, ey, nx, ny, ndir, true);		// true啊 left规氢捞促.		break;		// 快荐过		case MOVE_RULE_RIGHTWALL :			found = moveWall(ex, ey, nx, ny, ndir, false);	// false啊 right规氢捞促.		break;		default :		break;	}	// 1. 促澜 规氢捞 惯斑登菌绊,	// 2. 救傈 瘤措啊 酒聪扼搁... 	if ((found) && !(pZone->getZoneLevel(nx, ny) & SAFE_ZONE))	{		// 郴何俊辑 农府贸狼 谅钎客 规氢阑 函版窍哥, 宏肺靛某胶飘甫 舅酒辑 秦霖促.		// 捞固 Q(nx,ny)啊 拌魂登绢 乐栏骨肺 被捞 犁拌魂且 鞘夸绰 绝促.		pZone->moveCreature(m_pBody, nx, ny, ndir);	}	m_LastAction = LAST_ACTION_MOVE;	return true;}bool MonsterAI::move(Creature* pEnemy, bool bRetreat)	throw(){	__BEGIN_TRY	Zone*       pZone   = m_pBody->getZone();	ZoneCoord_t enemyX  = pEnemy->getX();	ZoneCoord_t enemyY  = pEnemy->getY();	ZoneCoord_t myX     = m_pBody->getX();	ZoneCoord_t myY     = m_pBody->getY();	int         xOffset = enemyX - myX;	int         yOffset = enemyY - myY;	ZoneCoord_t ex      = pEnemy->getX();	ZoneCoord_t ey      = pEnemy->getY();	// 档噶阑 磨 版快俊绰 利狼 馆措 谅钎俊 利捞 乐促绊 	// 积阿窍绊, 框流捞搁 等促.	if (bRetreat)	{		////////////////////////////////////////////////////////////		// (enemyX, enemyY)          		//		//                  myX, myY		//		//                           (ex, ey)		//                           		// 利捞 乐绰 器瘤记(enemyX, enemyY)俊辑 		// 措阿急 馆措 规氢栏肺 档噶阑 模促.		////////////////////////////////////////////////////////////		int xOffset2 = xOffset<<1;	// by sigi		int yOffset2 = yOffset<<1;	// by sigi		if (enemyX - xOffset2 < 0) ex = 0;		else if (enemyX - xOffset2 > (int)pZone->getWidth()) ex = pZone->getWidth();		else ex = enemyX - xOffset2;		if (enemyY - yOffset2 < 0) ey = 0;		else if (enemyY - yOffset2 > (int)pZone->getHeight()) ey = pZone->getHeight();		else ey = enemyY - yOffset2;		setMoveRule( MOVE_RULE_NORMAL );	// 沥惑利牢 捞悼	}	return move(ex, ey);	__END_CATCH}bool MonsterAI::flee(Creature* pEnemy)	throw(){	__BEGIN_TRY	if (m_Panic == 0)	{		if (m_Courage == 0)		{			m_Panic   = m_PanicMax;			m_Courage = m_CourageMax;		}		else		{			m_Courage--;		}	}	else m_Panic--;	if (m_Panic > 0)	{		// 档噶模促.		move(pEnemy, true);		return true;	}	return false;	__END_CATCH}int MonsterAI::useSkill(Creature* pEnemy, SkillType_t SkillType, int ratio) 	throw(){	__BEGIN_TRY	__BEGIN_DEBUG	Assert(pEnemy != NULL);	ZoneCoord_t ex = pEnemy->getX();	ZoneCoord_t ey = pEnemy->getY();	Distance_t  dist = m_pBody->getDistance(ex , ey);	// 绢恫 青悼阑 秒且 锭绰 弊 青悼阑 秒且 犬伏捞 倒酒柯促.	if (rand()%100 >= ratio) return SKILL_FAILED_RATIO; 	// [ test code ]	//	Zone* pZone = m_pBody->getZone();	// Assert( pZone != NULL );	//cout << "ZoneID=" << (int)pZone->getZoneID()    //    << ", MonsterCount=" << (int)pZone->getMonsterCount() << endl;	//----------------------------------------------------------	// skill阑 荤侩窍扁 阂啊瓷茄 惑怕扼搁 	// 老窜 啊瓷茄 惑怕肺 父甸绢具 茄促.	// Directive俊 持绢档 登瘤父, 葛电 各捞 悼老窍扁 锭巩俊...	//	// Slayer各/Vampire各栏肺 唱吹瘤 臼阑鳖.. 栏褥 - -;	//----------------------------------------------------------	// Hide惑怕扼搁 脾绢唱客具 茄促.	if (m_pBody->isFlag( Effect::EFFECT_CLASS_HIDE ))	{		SkillType = SKILL_UN_BURROW;	}	// 冠零惑怕扼搁 促矫 函脚	else if (m_pBody->isFlag( Effect::EFFECT_CLASS_TRANSFORM_TO_BAT ))	{		SkillType = SKILL_UN_TRANSFORM;	}	// invisible惑怕扼搁 钱绢具 茄促.	else if (m_pBody->isFlag( Effect::EFFECT_CLASS_INVISIBILITY ))	{		SkillType = SKILL_UN_INVISIBILITY;	}	// 戳措绰 付过静搁 救登绰单.. - -;	SkillHandler* pSkillHandler = g_pSkillHandlerManager->getSkillHandler(SkillType);	Assert(pSkillHandler != NULL);	SkillInfo* pSkillInfo = NULL;	Timeval delay;	switch (SkillType)	{		////////////////////////////////////////////////////////////		// 辟芭府 扁贱甸		////////////////////////////////////////////////////////////		case SKILL_ATTACK_MELEE:		case SKILL_ACID_TOUCH:		case SKILL_BLOOD_DRAIN:		case SKILL_SINGLE_BLOW:		case SKILL_BLOODY_NAIL:			if (dist > m_pBody->getMeleeRange()) return SKILL_FAILED_RANGE;			pSkillHandler->execute(m_pBody, pEnemy);			break;		////////////////////////////////////////////////////////////		// 厘芭府 扁贱甸		////////////////////////////////////////////////////////////		case SKILL_ATTACK_ARMS:			if (dist > m_pBody->getMissileRange()) return SKILL_FAILED_RANGE;			pSkillHandler->execute(m_pBody, pEnemy);			break;		////////////////////////////////////////////////////////////		// 厘芭府 扁贱甸 (with delay)		////////////////////////////////////////////////////////////		case SKILL_GREEN_POISON:		case SKILL_YELLOW_POISON:		case SKILL_DARKBLUE_POISON:		case SKILL_GREEN_STALKER:		case SKILL_ACID_BOLT:		case SKILL_ACID_BALL:		case SKILL_BLOODY_BALL:		case SKILL_BLOODY_WAVE:		case SKILL_BLOODY_MASTER_WAVE:		case SKILL_BLOODY_WARP:		case SKILL_PARALYZE:		case SKILL_DOOM:		case SKILL_SEDUCTION:		case SKILL_DEATH:		case SKILL_DARKNESS:		case SKILL_BLOODY_KNIFE:		case SKILL_BLOODY_SPEAR:		case SKILL_BLOODY_STORM:		case SKILL_ACID_STORM:		case SKILL_POISON_STORM:		case SKILL_HALLUCINATION:		// 2003.04.13-14 阁胶磐啊 荤侩且 荐 乐档废 眠啊.		case SKILL_METEOR_STRIKE:		case SKILL_BLOODY_WALL:		case SKILL_BLOODY_SNAKE:		case SKILL_BLOODY_BREAKER:		case SKILL_ACID_SWAMP:		case SKILL_POISON_STRIKE:		case SKILL_ACID_STRIKE:		case SKILL_HANDS_OF_WISDOM:		case SKILL_POISONOUS_HANDS:		case SKILL_BLOODY_ZENITH:		case SKILL_ACID_ERUPTION:		case SKILL_ICE_FIELD:			pSkillInfo = g_pSkillInfoManager->getSkillInfo(SkillType);			Assert(pSkillInfo != NULL);			if (dist > pSkillInfo->getRange()) return SKILL_FAILED_RANGE;			//cout << "useSkill: " << pSkillInfo->getName().c_str() << endl;			pSkillHandler->execute(m_pBody, pEnemy);			//cout << "useSkillOK: " << pSkillInfo->getName().c_str() << endl;			// 固荤老 筋绰 加档啊 呈公 狐福扁 锭巩俊 瘤楷矫埃阑 技泼秦 霖促.			if (m_pBody->isMaster()#ifdef __UNDERWORLD__				|| m_pBody->getMonsterType() == 599#endif			)		// 付胶磐绰 delay甫 粱 临牢促. by sigi. 2002.9.13			{				delay.tv_sec  = 0;				delay.tv_usec = 700000;			}			else			{				delay.tv_sec  = 1;				delay.tv_usec = 500000;			}			m_pBody->addAccuDelay(delay);			break;		////////////////////////////////////////////////////////////		// 伎橇 扁贱甸		////////////////////////////////////////////////////////////		case SKILL_HIDE:		case SKILL_UN_BURROW:		case SKILL_UN_TRANSFORM:		case SKILL_TRANSFORM_TO_WOLF:		case SKILL_TRANSFORM_TO_BAT:		case SKILL_INVISIBILITY:		case SKILL_UN_INVISIBILITY:		case SKILL_DUPLICATE_SELF:			pSkillHandler->execute(m_pBody);			// delay汲沥			delay.tv_sec  = 1;			delay.tv_usec = 500000;			m_pBody->addAccuDelay(delay);			break;		case SKILL_SUMMON_MONSTERS:			if ( !checkPossibleSummonMonsters(m_pBody, NULL) && !m_pBody->isMaster() ) return SKILL_FAILED_RANGE;						pSkillHandler->execute(m_pBody);			// delay汲沥			delay.tv_sec  = 1;			delay.tv_usec = 500000;			m_pBody->addAccuDelay(delay);			break;		case SKILL_CRITICAL_GROUND:			pSkillHandler->execute(m_pBody);			// delay汲沥			delay.tv_sec  = 1;			delay.tv_usec = 0;			m_pBody->addAccuDelay(delay);			break;		////////////////////////////////////////////////////////////		// QuickFire - -;		////////////////////////////////////////////////////////////		case SKILL_QUICK_FIRE:			pSkillInfo = g_pSkillInfoManager->getSkillInfo(SkillType);			Assert(pSkillInfo != NULL);			if (dist > pSkillInfo->getRange()) return SKILL_FAILED_RANGE;			pSkillHandler->execute(m_pBody, pEnemy);						break;		////////////////////////////////////////////////////////////		// 瘤盔登瘤 臼绰 扁贱		////////////////////////////////////////////////////////////		default:			cerr << "MonsterAI::useSkill() : Try to use unavailable skill!" << endl;			Assert(false);			break;	}	m_LastAction = LAST_ACTION_SKILL;	return 0;	__END_DEBUG	__END_CATCH}//////////////////////////////////////////////////////////////////////////////// 青悼 菩畔 急琶 窃荐//////////////////////////////////////////////////////////////////////////////void MonsterAI::deal(Creature* pEnemy, const Timeval& currentTime)	throw(){	__BEGIN_TRY	Assert(pEnemy != NULL);	// by sigi	// 促捞泛萍宏 府胶飘甫 掘绢辰促.	const list<Directive*>& directiveList = m_pDirectiveSet->getDirectives();	int rValue = 0;	int parameter = 0;	int ratio = 0;	// 促捞发萍宏 府胶飘甫 窍唱究 八祸窍搁辑,	// 炼扒捞 父练登绰 巴捞 乐绰瘤 眉农茄促.	list<Directive*>::const_iterator itr = directiveList.begin();	for (; itr != directiveList.end(); itr++)	{		Directive* pDirective = *itr;		// 炼扒捞 父练窍绰 促捞泛萍宏啊 乐促搁,		// 弊俊 秦寸窍绰 咀记阑 荐青茄促.		if (checkDirective(pDirective, pEnemy))		{			switch (pDirective->getAction())			{				// 利俊霸 促啊埃促.				case DIRECTIVE_ACTION_APPROACH:					__BEGIN_PROFILE_MONSTER("DIRECTIVE_ACTION_APPROACH");					approach(pEnemy);					__END_PROFILE_MONSTER("DIRECTIVE_ACTION_APPROACH");					//cout << "[" << (int)currentTime.tv_sec << "." << (int)currentTime.tv_usec << "] approach" << endl;					break;				// 利栏肺何磐 档噶模促.				case DIRECTIVE_ACTION_FLEE:					__BEGIN_PROFILE_MONSTER("DIRECTIVE_ACTION_FLEE");					if (!flee(pEnemy))					{						setMoveRule( MOVE_RULE_NORMAL );	// 沥惑利牢 捞悼						rValue = useSkill(pEnemy, SKILL_ATTACK_MELEE, 100);						if (rValue != 0) approach(pEnemy);						//cout << "[" << (int)currentTime.tv_sec << "." << (int)currentTime.tv_usec << "] !free" << endl;					}					else					{						//cout << "[" << (int)currentTime.tv_sec << "." << (int)currentTime.tv_usec << "] free" << endl;					}					__END_PROFILE_MONSTER("DIRECTIVE_ACTION_FLEE");					break;				// 胶懦阑 荤侩茄促. 利阑 傍拜窍芭唱, 伎橇 扁贱...				case DIRECTIVE_ACTION_USE_SKILL:					__BEGIN_PROFILE_MONSTER("DIRECTIVE_ACTION_USE_SKILL");					// Block Head 吧妨乐阑锭绰 胶懦阑 荤侩且 荐 绝促.					if ( m_pBody->isFlag( Effect::EFFECT_CLASS_BLOCK_HEAD ) || m_pBody->isFlag( Effect::EFFECT_CLASS_TENDRIL ) ) continue;					parameter = pDirective->getParameter();					ratio     = pDirective->getRatio();					rValue    = useSkill(pEnemy, (SkillType_t)parameter, ratio);					__END_PROFILE_MONSTER("DIRECTIVE_ACTION_USE_SKILL");					if (rValue != 0) 					{						//cout << "[" << (int)currentTime.tv_sec << "." << (int)currentTime.tv_usec << "] !" << SkillTypes2String[parameter] << endl;						continue;					}					//cout << "[" << (int)currentTime.tv_sec << "." << (int)currentTime.tv_usec << "] " << SkillTypes2String[parameter] << endl;					setMoveRule( MOVE_RULE_NORMAL );	// 沥惑利牢 捞悼					break;								// 利阑 器扁茄促.				case DIRECTIVE_ACTION_FORGET:					__BEGIN_PROFILE_MONSTER("DIRECTIVE_ACTION_FORGET");					// by sigi. 2002.10.7					if (!m_pBody->getEnemies().empty())						m_pBody->getEnemies().pop_front();					setMoveRule( MOVE_RULE_NORMAL );	// 沥惑利牢 捞悼					//cout << "[" << (int)currentTime.tv_sec << "." << (int)currentTime.tv_usec << "] forget" << endl;					__END_PROFILE_MONSTER("DIRECTIVE_ACTION_FORGET");					break;				// 货肺款 PrimaryEnemy甫 茫酒辑 眉农茄促.				case DIRECTIVE_ACTION_CHANGE_ENEMY :					{						ratio = pDirective->getParameter();						// 利阑 救 官槽促.						if (rand()%100 >= ratio)

⌨️ 快捷键说明

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