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

📄 aimanager.cpp

📁 国内著名网络游戏dragon的服务端完整源码 内附完整数据库结构
💻 CPP
📖 第 1 页 / 共 5 页
字号:
	{
		m_pActionBag[i]=NULL;						// 皋葛府 檬扁拳
	}
	
	SQLAllocStmt(hDBC,&hStmt);
	
	wsprintf(query_stmt,"select * from AI_ActionBag order by TypeNo");   
	
	ret=SQLExecDirect(hStmt,(UCHAR*)query_stmt,SQL_NTS);
	
	if (ret!=SQL_SUCCESS_WITH_INFO && ret !=SQL_SUCCESS)
	{
		MyLog(0,"LoadAttackBag(), AI_ActionBag Table Query Error!!");
		SQLFreeStmt(hStmt,SQL_DROP);
		return FALSE;
	}
	
	SQLNumResultCols(hStmt,&nClos);
	
	ret=SQLFetch(hStmt);
	if (ret!=SQL_SUCCESS_WITH_INFO && ret !=SQL_SUCCESS)
	{
		MyLog(0,"LoadActionBag(), AI_ActionBag Table Fetch Error!!");
		SQLFreeStmt(hStmt,SQL_DROP);
		return false;
	}
	
	m_iActionBagCount=1;
	while (ret==SQL_SUCCESS)
	{
		m_pActionBag[m_iActionBagCount]=new int[3];
		if (!m_pActionBag[m_iActionBagCount])
		{
			MyLog(0,"LoadActionBag(), AI_ActionBag Memory Alloc Error!!",ret);
			SQLFreeStmt(hStmt,SQL_DROP);
			return false;
		}
		ret=SQLGetData(hStmt, 3,SQL_C_SLONG,&m_pActionBag[m_iActionBagCount][ 0],sizeof(int),&cbValue);	// Func No
		if (m_pActionBag[m_iActionBagCount][ 0]>MAX_ACTION_FUNC)
		{
			MyLog(0,"LoadActionBag(), AI_ActionBag Function Number Error!!",ret);
			SQLFreeStmt(hStmt,SQL_DROP);
			return false;
		}
		ret=SQLGetData(hStmt, 4,SQL_C_SLONG,&m_pActionBag[m_iActionBagCount][ 1],sizeof(int),&cbValue);	// Param1
		ret=SQLGetData(hStmt, 5,SQL_C_SLONG,&m_pActionBag[m_iActionBagCount][ 2],sizeof(int),&cbValue);	// Param2
		
		if (ret!=SQL_SUCCESS_WITH_INFO && ret!=SQL_SUCCESS)
		{
			MyLog(0,"LoadActionBag(), AI_ActionBag Table SQL Return Error(%d)!!",ret);
			SQLFreeStmt(hStmt,SQL_DROP);
			return FALSE;
		}                
		m_iActionBagCount++;
		ret=SQLFetch(hStmt);
	}
    SQLFreeStmt(hStmt,SQL_DROP);
	return TRUE;
}

inline int** CAIManager::GetNpcAIData()
{
	return m_pNpc_AI_Data;
}

inline int* CAIManager::GetNpcAIData(int AI_Type)
{
	return m_pNpc_AI_Data[AI_Type];
}

inline int CAIManager::GetNpcAIData(int AI_Type,int Field)
{
	if (m_iAI_DataCount==NULL) return 0;
	
	if (m_iAI_DataCount<AI_Type)
	{
		//	    JustMsg("Error!! AI_Type Range Fault!! See NPC_Generation_SP's Sel_age_min, max");
		return 0;
	}
	return m_pNpc_AI_Data[AI_Type][Field];
}

inline int CAIManager::GetMagicBagData(int Row,int Col)
{
	if (Row<0 || Row>m_iMagicBagCount) return 0;
	if (Col<0 || Col>9) return 0;
	
	return m_pMagicBag[Row][Col];
}

inline int CAIManager::CheckAIDelayTime(CHARLIST* Npc)
{
	if (global_time-Npc->aitimedelay>Npc->aidelayhowmuch)
	{
		return TRUE;
	}
	return FALSE;
}

inline void CAIManager::SetAIDelayTime(CHARLIST* Npc,int Status,int StatusSub)
{	//< CSD-021021
	Npc->aitimedelay = global_time;
	Npc->aidelayhowmuch = GetNpcAIData(NPC_Gen_Ref[Npc->npc_index].nAINo, Status) + rand()%(GetNpcAIData(NPC_Gen_Ref[Npc->npc_index].nAINo, StatusSub)+1);
}	//> CSD-021021

inline void CAIManager::SetAIDelayTime(CHARLIST* Npc,DWORD time)		//泅犁 惑怕俊辑 AI掉饭捞矫埃父... 疵赴促.
{
	Npc->aidelayhowmuch=Npc->aidelayhowmuch+time;
}

inline bool	CAIManager::isProcess(CHARLIST* Npc)
{	//< CSD-030306
	if (!Npc->IsNpc()) 
	{
		return false;
	}
	
	if (!CheckAIDelayTime(Npc)) 
	{
		return false;
	}
	
	if (Npc->patterntype < NPC_PATTERN_WANDER)		// 扁粮狼 AI鸥涝..
	{
		return false;
	}

	const int nDiffX = Npc->MoveGox/TILE_SIZE - Npc->homex;
	const int nDiffY = Npc->MoveGoy/TILE_SIZE - Npc->homey;
	const int nDist = sqrt(pow(nDiffX, 2.0) + pow(nDiffY, 2.0));
		
	if	(nDist > 25)
	{	//< CSD-030314
		g_pBattleManager->SendNpcTeleport(Npc->GetServerID(), Npc->homex*TILE_SIZE, Npc->homey*TILE_SIZE);
		return false;
	}	//> CSD-030314
	
	return true;
}	//> CSD-030306

inline int  CAIManager::GetNPCSearchRange(CHARLIST* Npc)
{	//< CSD-021021
	return GetNpcAIData(NPC_Gen_Ref[Npc->npc_index].nAINo,FSEARCH_RANGE);
}	//> CSD-021021

inline void CAIManager::SetNextAI(CHARLIST* Npc)
{
	if (!Npc->ChairNum) return;
	if (Npc->patterntype<NPC_PATTERN_ATTACK)
	{
		Npc->patterntype++;									// 604档 刘啊登搁??
	}
}

inline void CAIManager::SetAI(CHARLIST* Npc,int AIPattern)			// LTS DRAGON MODIFY
{
	if (!Npc->ChairNum) return;
	Npc->patterntype=AIPattern;
}

inline void CAIManager::SetAIMove(CHARLIST* Npc)
{
	if (!Npc->ChairNum) return;
	
	Npc->EventPoint=Npc->patterntype;								// Old AI 历厘
	Npc->patterntype=NPC_PATTERN_MOVING;
}

inline void CAIManager::SetAIBMove(CHARLIST* Npc)
{
	if (!Npc->ChairNum) return;
	
	Npc->EventPoint=Npc->patterntype;								// Old AI 历厘
	Npc->patterntype=NPC_PATTERN_BOSS_MOVING;
}


inline void CAIManager::SetAIDefault(CHARLIST* Npc)
{
	Npc->patterntype=NPC_PATTERN_WANDER;
}

inline void CAIManager::SetAIBDefault(CHARLIST* Npc)
{
	Npc->patterntype=NPC_PATTERN_BOSS_WANDER;
}

inline void CAIManager::SetTarget(CHARLIST* Npc,int Target)
{
	if (Target!=-1)
	{
		Npc->targetid=Target;
	}
}

inline void CAIManager::ClearTarget(CHARLIST* Npc)
{
	Npc->targetid=-1;
}

#define	HOME_DIST_1AREA					245
#define HOME_DIST_2AREA					625

inline void CAIManager::RandomMove(CHARLIST* Npc)
{
	int tempValue=rand()%100;
	int Percent=GetNpcAIData(NPC_Gen_Ref[Npc->npc_index].nAINo,FWANDER_RATE); // CSD-021021
	if (tempValue<Percent)						
	{	
		
		bool soFar=false;
		int dir;
		int how;
		int tx=Npc->MoveGox/TILE_SIZE;
		int ty=Npc->MoveGoy/TILE_SIZE;
		
		const DWORD area1 = sqrt(pow(Npc->X/TILE_SIZE - Npc->homex, 2.0) + pow(Npc->Y/TILE_SIZE - Npc->homey, 2.0));
		const DWORD area2 = sqrt(pow(tx - Npc->homex, 2.0) + pow(ty - Npc->homey, 2.0));
		
		if( area1 > HOME_DIST_1AREA )
		{	
			if( area2 > HOME_DIST_2AREA )
			{	//< CSD-030314
				g_pBattleManager->SendNpcTeleport(Npc->GetServerID(), Npc->homex*32, Npc->homey*32);
				return;
			}	//> CSD-030314
		}
		
		dir = rand()%8;
		how = rand()%8+2;
		if (!soFar)
		{
			tx = Npc->MoveSx;
			ty = Npc->MoveSy;
		}
		switch( dir )
		{
		case 0 :			ty +=how; break;
		case 1 : tx -=how;	ty +=how; break;
		case 2 : tx -=how;            break;
		case 3 : tx -=how;	ty -=how; break;
		case 4 :			ty -=how; break;
		case 5 : tx +=how;	ty -=how; break;
		case 6 : tx +=how;		      break;
		case 7 : tx +=how;	ty +=how; break;
		}
		
		if( NPC_MakePathBumn( Npc, tx, ty, how ) )
		{
			if (Npc->patterntype>=NPC_PATTERN_BOSS_WANDER)
				SetAIBMove(Npc);										// Npc AI Status : Move
			else
				SetAIMove(Npc);										// Npc AI Status : Move
			SendMoveNPCArea( connections, Npc->GetServerID());
		}
	}
}

inline void CAIManager::TargetMove(CHARLIST* Npc)		// LTS DRAGON MODIFY
{
	int TargetX,TargetY;
	
	if (NPC_NearCh(Npc,&connections[Npc->targetid].chrlst,&TargetX,&TargetY))
	{
		if (NPC_MakePath(Npc,TargetX,TargetY,rand()%6+2))			// 鸥南栏肺 何磐狼 困摹 罚待
		{
			if (Npc->patterntype>=NPC_PATTERN_BOSS_WANDER) SetAIBMove(Npc);
			else SetAIMove(Npc);
			SetAIDelayTime(Npc,FSTATUS05_DELAY,FSTATUS05_SUBDELAY);		// STATUS05 MOVE
			SendMoveNPCArea( connections, Npc->GetServerID());
		}
		else 
		{
			if (Npc->patterntype>=NPC_PATTERN_BOSS_WANDER) SetAIBDefault(Npc);
			else SetAIDefault(Npc);
			
		}
	}
	else
	{
		if (Npc->patterntype>=NPC_PATTERN_BOSS_WANDER) SetAIBDefault(Npc);
		else SetAIDefault(Npc);
	}
}

inline void CAIManager::ClearMovePattern(CHARLIST* Npc)
{
	Npc->EventPoint=0;
}

inline int CAIManager::GetAttackChange(CHARLIST* Npc)
{
	int LifePercent=Npc->Hp/Npc->HpMax*100;
	if (LifePercent<=90&&LifePercent>70)
	{
		return 1;
	}
	else
		if (LifePercent<=70&&LifePercent>50)
		{
			return 2;
		}
		else
			if (LifePercent<=50&&LifePercent>30)
			{
				return 3;
			}
			else
				if (LifePercent<=30&&LifePercent>10)
				{
					return 4;
				}
				else
					if (LifePercent<=10&&LifePercent>0)
					{
						return 5;
					}
					return 0;
}

inline int CAIManager::CheckSummon(CHARLIST* Npc)
{
	//MyLog(0,"Npc SprNo : %d, Summon : %d",Npc->SprNo,Npc->ElementType);
	if (!GetNpcAIData(NPC_Gen_Ref[Npc->npc_index].nAINo,FSUMMON_MAX))	// CSD-021021
	{
		return FALSE;
	}
	else																		// 家券阁捞促.	
	{ // 捞固 家券 促沁澜
		if (Npc->ElementType>=GetNpcAIData(NPC_Gen_Ref[Npc->npc_index].nAINo,FSUMMON_MAX))	// CSD-021021 
		{ 
			return FALSE;
		}
		
		if (Npc->scan_time>g_curr_time)			// 茄锅 家券茄促澜 矫埃捞 瘤唱瘤 臼疽促
		{
			return FALSE;
		}
		else
		{
			if (rand()%100<GetNpcAIData(NPC_Gen_Ref[Npc->npc_index].nAINo,FSUMMON_PERCENT)) // CSD-021021		 
			{
				return TRUE;
			}
			else 
			{
				return FALSE;
			}
		}
	}
}

inline void CAIManager::CheckSummonDeath(CHARLIST* Defender)						// LTS DRAGON MODIFY
{
	if (Defender->itemweight>=NPC_LIST_START&&Defender->itemweight<MAX_NPC_LIST)
	{
		CHARLIST* ch=&NPCList[Defender->itemweight];		//家券茄 林牢阑 茫绰促.
		
		if (!ch->IsDead())							//磷瘤臼疽芭唱
		{
			if (ch->ElementType>0)					// 家券等 荐啊 乐促搁 	
			{
				ch->ElementType--;
			}
		}
	}
}

inline void  CAIManager::SelectAttackMethod(CHARLIST* Npc)				
{
	if (CheckSummon(Npc))							// 家券 阁胶磐捞搁 家券阑 搬沥茄促.
	{
		Npc->fame=4;
		return;
	}
	
	int MagicChange=GetAttackChange(Npc);
	int AI_Type=NPC_Gen_Ref[Npc->npc_index].nAINo; // CSD-021021
	int AttackChance=GetNpcAIData(AI_Type,FATTACK_CHANCE);
	
	int AttackMethodRate1=GetNpcAIData(AI_Type,FATTACK_RATE1)-(MagicChange*AttackChance);
	if (AttackMethodRate1<0) AttackMethodRate1=0;
	
	int AttackMethodRate2=GetNpcAIData(AI_Type,FATTACK_RATE2)+(MagicChange*AttackChance*0.5);
	if (AttackMethodRate2<0) AttackMethodRate2=0;
	
	int AttackMethodRate3=GetNpcAIData(AI_Type,FATTACK_RATE3)+(MagicChange*AttackChance);
	if (AttackMethodRate3<0) AttackMethodRate3=0;
	
	
	int DivValue=AttackMethodRate1+AttackMethodRate2+AttackMethodRate3;
	int RandValue;
	if (DivValue>0) RandValue=rand()%DivValue;
	
	if (RandValue>=0&&RandValue<AttackMethodRate1)
	{
		Npc->fame=1;
	}
	else
		if (RandValue>=AttackMethodRate1&&RandValue<(AttackMethodRate1+AttackMethodRate2))
		{
			Npc->fame=2;
		}
		else
			if (RandValue>=(AttackMethodRate1+AttackMethodRate2)&&RandValue<=DivValue)
			{
				Npc->fame=3;
			}
}

inline int CAIManager::GetAttackBagNo(CHARLIST*Npc)
{
	int AttackMethod=Npc->mantle+FBATTACK_METHOD1-1;	// mantle捞 1何磐 矫累
	return m_pBossStatusData[Npc->CurrentPhase][AttackMethod];
	
}

inline int CAIManager::GetAttackMethodFromAttackBag(int AttackBagNo)
{
	if (AttackBagNo<=0) return -1;
	int RandValue=rand()%5;
	return m_pAttackBag[AttackBagNo][RandValue];
}


inline void  CAIManager::SelectBAttackMethod(CHARLIST* Npc)		// 焊胶阁胶磐狼 傍拜规过汲沥
{
	int AttackBagNo=GetAttackBagNo(Npc);						// NPC FAME捞 傍拜规过阑 瘤沥窍绰 镑捞促.
	Npc->fame=GetAttackMethodFromAttackBag(AttackBagNo);
	if (Npc->fame>=201)
	{
		int MagicBagNo=Npc->fame-200;
		if (MagicBagNo<1||MagicBagNo>m_iMagicBagCount) 
		{
			MyLog(0,"BOSS ACTION NPC MAGIC BAG INDEX ERROR.. CHECK ACTION NPC AND MAGICBAG");
			return;
		}
		int MagicNo=m_pMagicBag[Npc->fame-200][rand()%10];
		Npc->fame=MagicNo;
	}
}


inline void  CAIManager::ClearAttackMethod(CHARLIST* Npc)			// LTS DRAGON MODIFY
{
	Npc->fame=0;												// 傍拜 规过 檬扁拳
}

inline CHARLIST* CAIManager::GetTarget(int TargetID)
{
	if (TargetID<0)
	{
		return NULL;
	}
	if (TargetID>=10000)								// NPC捞搁 
	{
		int tempTargetID=TargetID-10000;				// NPC锅龋 眠免 
		if (NPCList[tempTargetID].bAlive>=DEAD_)		// 磷菌栏搁 	
		{
			return NULL;								// NULL府畔
		}
		else
		{
			return &NPCList[tempTargetID];				// 混疽栏搁 CHARLIST* 府畔
		}
	}
	else
	{
		if (connections[TargetID].dwAgentConnectionIndex&&connections[TargetID].state>=CONNECT_JOIN)		
		{   //< CSD-030509 : 楷搬惑怕 

⌨️ 快捷键说明

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