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

📄 monsterai.cpp

📁 天之炼狱1服务器端源文件游戏服务端不完整
💻 CPP
📖 第 1 页 / 共 4 页
字号:
						{							//cout << "[" << (int)currentTime.tv_sec << "." << (int)currentTime.tv_usec << "] !changeEnemy" << endl;							continue;						}						__BEGIN_PROFILE_MONSTER("DIRECTIVE_ACTION_CHANGE_ENEMY");												Creature* pNewEnemy = m_pBody->getPrimaryEnemy();						if (pNewEnemy!=NULL)						{							pEnemy = pNewEnemy;						}						else						{							// 绝促搁.. checkFindWeakEnemy俊辑 delete窍绊 							// 货肺款 利捞 眠啊啊 登瘤 臼疽促绰 狼固捞促.							// 扁粮狼 利阑 促矫 眠啊茄促.							// by sigi. 2002.10.7							if (m_pBody->getEnemies().empty())							{								m_pBody->addEnemy( pEnemy );							}						}						__END_PROFILE_MONSTER("DIRECTIVE_ACTION_CHANGE_ENEMY");						// 促澜 AI甫 霸加 柳青茄促.						//cout << "[" << (int)currentTime.tv_sec << "." << (int)currentTime.tv_usec << "] changeEnemy" << endl;						continue;					}					break;				// 辟贸狼 绢凋啊肺 捞悼茄促.				case DIRECTIVE_ACTION_MOVE_RANDOM :					{						ratio = pDirective->getParameter();						// 绢凋啊肺 捞悼窍瘤 臼绰促.						if (rand()%100 >= ratio)						{							//cout << "[" << (int)currentTime.tv_sec << "." << (int)currentTime.tv_usec << "] !moveRandom" << endl;							continue;						}						ZoneCoord_t x;						ZoneCoord_t y;						TPOINT p;						__BEGIN_PROFILE_MONSTER("DIRECTIVE_ACTION_MOVE_RANDOM_GET_SAFE_TILE");						x = m_pBody->getX();						y = m_pBody->getY();						p = getSafeTile(m_pBody->getZone(), x, y);						__END_PROFILE_MONSTER("DIRECTIVE_ACTION_MOVE_RANDOM_GET_SAFE_TILE");						// 磊府啊 绝促搁.. 傲 器扁 - -;						if (p.x==-1)						{							///cout << "[" << (int)currentTime.tv_sec << "." << (int)currentTime.tv_usec << "] moveRandom : no position" << endl;							continue;						}						__BEGIN_PROFILE_MONSTER("DIRECTIVE_ACTION_MOVE_RANDOM_MOVE");						ZoneCoord_t x1 = p.x;//x + rand()%7 - 3;						ZoneCoord_t y1 = p.y;//y + rand()%7 - 3;												if (x!=x1 || y!=y1)							move(x1, y1);						__END_PROFILE_MONSTER("DIRECTIVE_ACTION_MOVE_RANDOM_MOVE");						//cout << "[" << (int)currentTime.tv_sec << "." << (int)currentTime.tv_usec << "] moveRandom" << endl;					}					break;				// 泪矫 措扁茄促.				case DIRECTIVE_ACTION_WAIT :					{						__BEGIN_PROFILE_MONSTER("DIRECTIVE_ACTION_WAIT");						Timeval delay;						delay.tv_sec  = 2;						delay.tv_usec = 0;						m_pBody->addAccuDelay(delay);						__END_PROFILE_MONSTER("DIRECTIVE_ACTION_WAIT");						//cout << "[" << (int)currentTime.tv_sec << "." << (int)currentTime.tv_usec << "] wait" << endl;					}					break;				case DIRECTIVE_ACTION_FAST_FLEE :					{						bool result = false;						__BEGIN_PROFILE_MONSTER("DIRECTIVE_ACTION_FAST_FLEE");						int myX = m_pBody->getX();						int myY = m_pBody->getY();						int nmX = pEnemy->getX();						int nmY = pEnemy->getY();						int diffX = myX - nmX;						int diffY = myY - nmY;						float ratio = 5.0 / ( ABS(diffX) + ABS(diffY) );						int newX = myX + diffX * ratio;						int newY = myY + diffY * ratio;						if ( isValidZoneCoord( m_pBody->getZone(), newX, newY ) )							result = m_pBody->getZone()->moveFastMonster( m_pBody, myX, myY, newX, newY, SKILL_RAPID_GLIDING );/*						if ( newX > 0 ) continue;						if ( newY < 0 ) continue;						if ( newX >= m_pBody->getZone()->getWidth() ) continue;						if ( newY >= m_pBody->getZone()->getHeight() ) continue;						if ( !m_pBody->getZone()->moveFastMonster( m_pBody, myX, myY, newX, newY, SKILL_RAPID_GLIDING ) ) continue;*/						__END_PROFILE_MONSTER("DIRECTIVE_ACTION_FAST_FLEE");						if ( !result ) continue;					}					break;			}			break;		}	}	__BEGIN_PROFILE_MONSTER("MAI_POST_DEAL");	// 捞锅 畔俊 绢恫 青悼阑 沁蠢衬俊 蝶扼 青悼 瘤楷 矫埃阑 技泼秦霖促.	switch (m_LastAction)	{		case LAST_ACTION_NONE:		case LAST_ACTION_MOVE:			setDelay(currentTime);			break;		case LAST_ACTION_SKILL:			setAttackDelay(currentTime);			break;	}	// 青悼 函荐甫 货肺 技泼秦 霖促.	m_LastAction = LAST_ACTION_NONE;		// 档噶俊 包茄 函荐甫 犬伏利栏肺 货肺 技泼秦霖促.	if ((rand() & 0x0000007F) > 64)	//%100 > 50)	{		if (m_bDamaged)		{			m_bDamaged = false;			m_Panic    = m_PanicMax;			m_Courage  = m_CourageMax;		}	}	__END_PROFILE_MONSTER("MAI_POST_DEAL");	__END_CATCH}// 磷阑 锭狼 青悼阑 秒茄促.void MonsterAI::actDeadAction(Creature* pEnemy) 	throw(){	__BEGIN_TRY	// MonsterAI狼 茄拌肺 牢秦,	// 利捞 绝阑 版快俊 青且 荐 乐绰 咀记俊绰 茄拌啊 乐促.	if (pEnemy != NULL)	{		// 促捞泛萍宏 府胶飘甫 掘绢辰促.		const list<Directive*>& directiveList = m_pDirectiveSet->getDeadDirectives();		bool bContinue = true;		// 促捞发萍宏 府胶飘甫 窍唱究 八祸窍搁辑,		// 炼扒捞 父练登绰 巴捞 乐绰瘤 眉农茄促.		list<Directive*>::const_iterator itr = directiveList.begin();		for (; itr != directiveList.end() && bContinue; itr++)		{			Directive* pDirective = *itr;			if (pDirective->getAction() == DIRECTIVE_ACTION_USE_SKILL)			{				SkillType_t SkillType = pDirective->getParameter();				int         ratio     = pDirective->getRatio();				SkillHandler* pSkillHandler = g_pSkillHandlerManager->getSkillHandler(SkillType);				Assert(pSkillHandler != NULL);				if ((rand()%ratio) < 100)				{					switch (SkillType)					{						case SKILL_GREEN_POISON:							pSkillHandler->execute(m_pBody);							bContinue = false;							break;						default:							Assert(false);							break;					}				}				else				{					// 扁贱 荤侩捞 犬伏 眉农肺 牢秦 角菩沁促搁 促澜 咀记栏肺 逞绢埃促.					continue;				}			}		}	}	__END_CATCH}void MonsterAI::setDelay(const Timeval& currentTime)	throw(){	__BEGIN_TRY	// 扁粮俊 备茄 矫埃阑 捞侩茄促. 拌魂 临老妨绊. - -; by sigi. 2002.5.6	//Timeval currentTime;	//getCurrentTime(currentTime);	int delay    = m_pBody->getDelay();	if (m_pBody->isFlag(Effect::EFFECT_CLASS_TRANSFORM_TO_BAT))	{		delay = 200; // 250	}	else if (m_pBody->isFlag(Effect::EFFECT_CLASS_TRANSFORM_TO_WOLF))	{		delay = 300; // 375	}	int modifier = (rand()%41)-20;	delay = delay*1000;	delay = delay + delay*modifier/100;	Timeval nexttime;	nexttime.tv_sec  = delay/1000000;	nexttime.tv_usec = delay%1000000;	nexttime = nexttime + m_pBody->getAccuDelay();	m_pBody->clearAccuDelay();	if ( m_pBody->isFlag( Effect::EFFECT_CLASS_ICE_FIELD_TO_CREATURE ) 	||	m_pBody->isFlag( Effect::EFFECT_CLASS_JABBING_VEIN ) )	{		m_pBody->setNextTurn(currentTime + nexttime + nexttime);	}	else	{		m_pBody->setNextTurn(currentTime + nexttime);	}	/*	Timeval currentTime;	Timeval delay;	getCurrentTime(currentTime);	delay.tv_sec  = m_pBody->getDelay()/1000;	delay.tv_usec = (m_pBody->getDelay()%1000)*1000 + rand()%200000;	delay = delay + m_pBody->getAccuDelay();	m_pBody->clearAccuDelay();	m_pBody->setNextTurn(currentTime + delay);	*/		/*	Timeval delay;	delay.tv_sec = 0;	delay.tv_usec = m_pBody->getDelay()* 1000 + rand() % 200000;	m_pBody->setNextTurn(m_pBody->getNextTurn() + delay);	*/	__END_CATCH}void MonsterAI::setAttackDelay(const Timeval& currentTime)	throw(){	__BEGIN_TRY	// 扁粮俊 备茄 矫埃阑 捞侩茄促. 拌魂 临老妨绊. - -; by sigi. 2002.5.6	//Timeval currentTime;	//getCurrentTime(currentTime);	int delay    = m_pBody->getAttackDelay();	int modifier = (rand()%21);	delay = delay*1000;	delay = delay + delay*modifier/100;	Timeval nexttime;	nexttime.tv_sec  = delay/1000000;	nexttime.tv_usec = delay%1000000;	nexttime = nexttime + m_pBody->getAccuDelay();	m_pBody->clearAccuDelay();	if ( m_pBody->isFlag( Effect::EFFECT_CLASS_ICE_OF_SOUL_STONE ) )	{		m_pBody->setNextTurn(currentTime + nexttime + nexttime);	}	else	{		m_pBody->setNextTurn(currentTime + nexttime);	}		/*	Timeval currentTime;	Timeval delay;	getCurrentTime(currentTime);	delay.tv_sec  = m_pBody->getAttackDelay()/1000;	delay.tv_usec = (m_pBody->getAttackDelay()%1000)*1000 + rand()%200000;	delay = delay + m_pBody->getAccuDelay();	m_pBody->clearAccuDelay();	m_pBody->setNextTurn(currentTime + delay);	*/	/*	Timeval delay;	delay.tv_sec = 0;	delay.tv_usec = m_pBody->getAttackDelay()* 1000 + rand() % 200000;	m_pBody->setNextTurn(m_pBody->getNextTurn() + delay);	*/	__END_CATCH}bool checkEnemyRangeMelee(Monster* pMonster, Creature* pEnemy){	Assert(pMonster != NULL);	if (pEnemy == NULL) return false;	Distance_t dist = pMonster->getDistance(pEnemy->getX(), pEnemy->getY());	if (dist <= pMonster->getMeleeRange()) return true;	return false;}bool checkEnemyRangeMissile(Monster* pMonster, Creature* pEnemy){	Assert(pMonster != NULL);	if (pEnemy == NULL) return false;	Distance_t dist = pMonster->getDistance(pEnemy->getX(), pEnemy->getY());	if (dist > pMonster->getMeleeRange() && dist <= pMonster->getSight()) return true;	return false;}bool checkEnemyRangeInMissile(Monster* pMonster, Creature* pEnemy){	Assert(pMonster != NULL);	if (pEnemy == NULL) return false;	Distance_t dist = pMonster->getDistance(pEnemy->getX(), pEnemy->getY());	if (dist <= pMonster->getSight()) return true;	return false;}bool checkEnemyRangeClose(Monster* pMonster, Creature* pEnemy){	Assert(pMonster != NULL);	if (pEnemy == NULL) return false;	Distance_t dist = pMonster->getDistance(pEnemy->getX(), pEnemy->getY());	if (dist <= 1) return true;	return false;}bool checkEnemyRangeOutOfSight(Monster* pMonster, Creature* pEnemy){	Assert(pMonster != NULL);	if (pEnemy == NULL) return false;	Distance_t dist = pMonster->getDistance(pEnemy->getX(), pEnemy->getY());	if (dist > pMonster->getSight()) return true;	return false;}bool checkEnemyDying(Monster* pMonster, Creature* pEnemy){	Assert(pMonster != NULL);	if (pEnemy == NULL) return false;	HP_t EnemyCurHP = 0;	HP_t EnemyMaxHP = 0;	if (pEnemy->isSlayer())	{		Slayer* pSlayer = dynamic_cast<Slayer*>(pEnemy);		EnemyCurHP = pSlayer->getHP(ATTR_CURRENT);		EnemyMaxHP = pSlayer->getHP(ATTR_MAX);	}	else if (pEnemy->isVampire())	{		Vampire* pVampire = dynamic_cast<Vampire*>(pEnemy);		EnemyCurHP = pVampire->getHP(ATTR_CURRENT);		EnemyMaxHP = pVampire->getHP(ATTR_MAX);	}	else if (pEnemy->isOusters())	{		Ousters* pOusters = dynamic_cast<Ousters*>(pEnemy);		EnemyCurHP = pOusters->getHP(ATTR_CURRENT);		EnemyMaxHP = pOusters->getHP(ATTR_MAX);	}	else if (pEnemy->isMonster())	{		Monster* pEnemyMonster = dynamic_cast<Monster*>(pEnemy);		EnemyCurHP = pEnemyMonster->getHP(ATTR_CURRENT);		EnemyMaxHP = pEnemyMonster->getHP(ATTR_MAX);	}	if (EnemyCurHP*5 < EnemyMaxHP) return true;	return false;}bool checkEnemyNotBloodDrained(Monster* pMonster, Creature* pEnemy){	Assert(pMonster != NULL);	if (pEnemy == NULL) return false;	if (pEnemy->isVampire()) return false;	if (!pEnemy->isFlag(Effect::EFFECT_CLASS_BLOOD_DRAIN)) return true;	return false;}bool checkEnemyNotGreenPoisoned(Monster* pMonster, Creature* pEnemy){	Assert(pMonster != NULL);	if (pEnemy == NULL) return false;	if (pEnemy->isVampire()) return false;	if (!pEnemy->isFlag(Effect::EFFECT_CLASS_POISON)) return true;	return false;}bool checkEnemyNotYellowPoisoned(Monster* pMonster, Creature* pEnemy){	Assert(pMonster != NULL);	if (pEnemy == NULL) return false;	if (pEnemy->isVampire()) return false;	if (!pEnemy->isFlag(Effect::EFFECT_CLASS_YELLOW_POISON_TO_CREATURE)) return true;	return false;}bool checkEnemyNotDarkbluePoisoned(Monster* pMonster, Creature* pEnemy){	Assert(pMonster != NULL);	if (pEnemy == NULL) return false;	if (pEnemy->isVampire()) return false;	if (!pEnemy->isFlag(Effect::EFFECT_CLASS_DARKBLUE_POISON)) return true;	return false;}bool checkEnemyNotGreenStalkered(Monster* pMonster, Creature* pEnemy){	Assert(pMonster != NULL);	if (pEnemy == NULL) return false;	if (pEnemy->isVampire()) return false;	if (!pEnemy->isFlag(Effect::EFFECT_CLASS_GREEN_STALKER)) return true;	return false;}bool checkEnemyNotParalyzed(Monster* pMonster, Creature* pEnemy){	Assert(pMonster != NULL);	if (pEnemy == NULL) return false;	if (!pEnemy->isFlag(Effect::EFFECT_CLASS_PARALYZE)) return true;	return false;}bool checkEnemyNotDoomed(Monster* pMonster, Creature* pEnemy){	Assert(pMonster != NULL);	if (pEnemy == NULL) return false;	if (!pEnemy->isFlag(Effect::EFFECT_CLASS_DOOM)) return true;	return false;}bool checkEnemyNotBlinded(Monster* pMonster, Creature* pEnemy){	Assert(pMonster != NULL);	return false;}bool checkEnemyNotInDarkness(Monster* pMonster, Creature* pEnemy){	Assert(pMonster != NULL);	if (pEnemy == NULL) return false;	if (pEnemy->isVampire()) return false;	if (!pEnemy->isFlag(Effect::EFFECT_CLASS_DARKNESS)) return true;	return false;}bool checkEnemyNotSeduction(Monster* pMonster, Creature* pEnemy){	Assert(pMonster != NULL);	if (pEnemy == NULL) return false;	if (!pEnemy->isFlag(Effect::EFFECT_CLASS_SEDUCTION)) return true;	return false;}bool checkEnemyNotDeath(Monster* pMonster, Creature* pEnemy){	Assert(pMonster != NULL);	if (pEnemy == NULL) return false;	if (!pEnemy->isFlag(Effect::EFFECT_CLASS_DEATH)) return true;	return false;}bool checkImOK(Monster* pMonster, Creature* pEnemy){	Assert(pMonster != NULL);	HP_t CurHP = pMonster->getHP(ATTR_CURRENT);	HP_t MaxHP = pMonster->getHP(ATTR_MAX);	if (CurHP > MaxHP/3) return true;	return false;}bool checkImDying(Monster* pMonster, Creature* pEnemy){	Assert(pMonster != NULL);

⌨️ 快捷键说明

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