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

📄 msginteract.cpp

📁 网络游戏魔域的服务端与客户端完整源代码 包括详细的说明文档与开发日志
💻 CPP
📖 第 1 页 / 共 2 页
字号:
								sprintf(sztemp,"Now Action Type %d",nAction);
								g_objGameMsg.AddMsg(sztemp);
								
#endif							
							}
						}
						else
						    nAction = _ACTION_ATTACK0+::RandGet(3);
						int nDir	= g_objHero.GetDir(pTarget);
						if (!g_objHero.IsMoving() 
							&& !g_objHero.IsAttacking())
						{
							g_objHero.SetActionCmd(nAction, nDir);
#ifdef _DEBUG
						char sztemp[64];
						sprintf(sztemp,"Attack Action Type %d",nAction);
						g_objGameMsg.AddMsg(sztemp);

#endif					
						}
					}
					
				}
				else
				{
					pSender->ResetStepDir();
                    
					int nAction = _ACTION_ATTACK0+::RandGet(3);
					int nDir	= pSender->GetDir(pTarget);
					if(!pSender->IsMyPet())
						pSender->SetActionCmd(nAction, nDir); 
					else if(!pSender->IsMoving() && !pSender->IsAttacking())
					{
						CPet* pPet = (CPet*)pSender;
						if(pSender->IsMyPet() && g_objHero.GetIDMyTarget() == pPet->GetIDMyTarget() && g_objHero.GetProfession() == PROFESSIONAL_WARRIOR)
						{
							int nAttackTime = pSender->GetAttackTimes();
							nAction = _ACTION_ATTACK0 + nAttackTime;
							if(!pSender->IsMoving() && !pSender->IsAttacking())
							    pSender->SetAttackTimes(nAttackTime >= 2?0:nAttackTime+1);
						}
						pSender->SetActionCmd(nAction, nDir); 
					}
				}
			}

			if (pTarget)
			{
				// target show
				int nDir = pTarget->GetDir();
				if(pSender)
					nDir = pTarget->GetDir(pSender);
				DWORD dwColor = _COLOR_YELLOW;
				if (pTarget->GetID() == g_objHero.GetID())
				{
					g_objHero.FlashLastAttackTime();
					if (m_pInfo->dwData > 0)
					{
						dwColor = _COLOR_RED;
						g_objHero.AddZoomNum(m_pInfo->dwData, dwColor, 300, 30);
						
						if (!g_objHero.IsMoving() 
								&& !g_objHero.IsAttacking())
								//&& !g_objHero.TestStatus(USERSTATUS_SUPERSOLDIER) 
								//&& !g_objHero.TestStatus(USERSTATUS_TORNADO))
							g_objHero.SetActionCmd(_ACTION_BRUISE0, nDir);//(nDir+4)%8);
						
						if (pSender && pSender->TestStatus(USERSTATUS_ADJUST_XP))	//对方处于xp增加状态特殊受击光效
							g_objHero.m_objEffect.Add("Xattack05",false,0,g_objHero.GetLook());
					}
					else
					{
						g_objHero.AddZoomNum(m_pInfo->dwData, dwColor, 300, 30);
						if (!g_objHero.IsMoving() 
								&& !g_objHero.IsAttacking())
								//&& !g_objHero.TestStatus(USERSTATUS_SUPERSOLDIER) 
								//&& !g_objHero.TestStatus(USERSTATUS_TORNADO))
							g_objHero.SetActionCmd(_ACTION_DODGE0, nDir);//(nDir+4)%8);
					}
				}
				else
				{
					pTarget->FlashLastAttackTime();							
					if (m_pInfo->dwData > 0)
					{
						if (pTarget->IsGuard())
							dwColor = _COLOR_BLUE;

						// 添加延时的受伤动作命令.
						CCommand cmd;
						cmd.iType	= _COMMAND_WOUND;
						cmd.iStatus	= _CMDSTATUS_BEGIN;
						cmd.nDir	= pTarget->GetDir(pSender);
						cmd.nData	= _ACTION_BRUISE0;
						
						CONST CActionDelayInfo* pInfoDelay = NULL;
 						CONST CWeaponInfo* pInfoWeapon = NULL;
						
						if (pSender)
						{
							DWORD dwKey = pSender->GetActionDelayInfoKey(pTarget);
							pInfoDelay = g_obj3DRoleData.GetActionDelayInfo(dwKey);
							
							dwKey = pSender->GetWeaponInfoKey(pTarget);
							pInfoWeapon = g_obj3DRoleData.GetWeaponInfo(dwKey);
						}
						
						DWORD tmDelay = 200;
						if (pInfoDelay)
							tmDelay = pInfoDelay->tmWoundDelay;
						
						
						CONST CHAR* pszEffect	= NULL;
						CONST CHAR* pszSound	= NULL;	
						if (pInfoWeapon)
						{
							pszEffect	= pInfoWeapon->strHitEffect.c_str();
							pszSound	= pInfoWeapon->strHitSound.c_str();
						}	

						pTarget->AddZoomNum(m_pInfo->dwData, dwColor, tmDelay, 30);
						
						pTarget->SetTimerCommand(cmd, ::TimeGet() + tmDelay, pszEffect, pszSound);
					
						if (pTarget->IsNpc())
						{
							int nLife = (int)pTarget->GetData(CPlayer::_PLAYER_LIFE)-(int)m_pInfo->dwData;
							pTarget->SetData(CPlayer::_PLAYER_LIFE, __max(0, nLife));
							//pTarget->SetLife(__max(0, nLife));
						}	
						if (pSender && pSender->TestStatus(USERSTATUS_ADJUST_XP))	//对方处于xp增加状态特殊受击光效
							pTarget->m_objEffect.Add("Xattack05",false,0,pTarget->GetLook());
					}
					else
					{
						CCommand cmd;
						cmd.iType	= _COMMAND_ACTION;
						cmd.iStatus	= _CMDSTATUS_BEGIN;
						cmd.nData	= _ACTION_DODGE0;
						cmd.nDir	= nDir;

						CONST CActionDelayInfo* pInfoDelay = NULL;
						CONST CWeaponInfo* pInfoWeapon = NULL;
						
						if (pSender)
						{
							DWORD dwKey = pSender->GetActionDelayInfoKey(pTarget);
							pInfoDelay = g_obj3DRoleData.GetActionDelayInfo(dwKey);
							
							dwKey = pSender->GetWeaponInfoKey(pTarget);
							pInfoWeapon = g_obj3DRoleData.GetWeaponInfo(dwKey);							
						}
						
						
						DWORD tmDelay = 200;
						if (pInfoDelay)
							tmDelay = pInfoDelay->tmBlockDelay;
						
						CONST CHAR* pszEffect	= NULL;
						CONST CHAR* pszSound	= NULL;
						if (pInfoWeapon)
						{
							pszEffect	= pInfoWeapon->strBlkEffect.c_str();
							pszSound	= pInfoWeapon->strBlkSound.c_str();
						}
						pTarget->AddZoomNum(m_pInfo->dwData, dwColor, tmDelay, 30);
						
						pTarget->SetTimerCommand(cmd, ::TimeGet() + tmDelay, pszEffect, pszSound);
					}
				}
			}
		}
		break;

	case INTERACT_RUSHATK:
		{
			if (pSender)
			{
			}
		}
		break;

	case INTERACT_KILL:
		{
			if (pTarget)
			{
				pTarget->SetData(CPlayer::_PLAYER_LIFE, 0);
				pTarget->ResetStepDir();

				if (g_objHero.GetID() == m_pInfo->idTarget)
				{
					pTarget->SetPos(m_pInfo->unPosX, m_pInfo->unPosY);
					::PostCmd(CMD_DIE);				
				}

				// do die action
				if (pTarget->IsPlayer())
				{
					// 命令设置
					CCommand cmd;
					cmd.iType	= _COMMAND_DIE;
					cmd.iStatus	= _CMDSTATUS_BEGIN;
					cmd.nDir		=pTarget->GetDir(pSender);
					cmd.dwData		=m_pInfo->usData0;
					
					pTarget->SetCommand(&cmd);
				}
				else
				{
					CONST CActionDelayInfo* pInfoDelay = NULL;
 					CONST CWeaponInfo* pInfoWeapon = NULL;
					
					if (pSender)
					{
						DWORD dwKey = pSender->GetActionDelayInfoKey(pTarget);
						pInfoDelay = g_obj3DRoleData.GetActionDelayInfo(dwKey);
						
						dwKey = pSender->GetWeaponInfoKey(pTarget);
						pInfoWeapon = g_obj3DRoleData.GetWeaponInfo(dwKey);
					}
					
					
					DWORD tmDelay = 200;
					if (pInfoDelay)
						tmDelay = pInfoDelay->tmDieDelay;
					
					
					CONST CHAR* pszEffect	= NULL;
					CONST CHAR* pszSound	= NULL;
					if (pInfoWeapon)
					{
						pszEffect	= pInfoWeapon->strBlkEffect.c_str();
						pszSound	= pInfoWeapon->strBlkSound.c_str();
					}
					
					pTarget->ResetActionData();
					pTarget->ClrTimerCommand();	// 清除没有执行的其他命令
					
					// 命令设置
					CCommand cmd;
					cmd.iType	= _COMMAND_DIE;
					cmd.iStatus	= _CMDSTATUS_BEGIN;
					cmd.nDir	=pTarget->GetDir();
					cmd.dwData	=m_pInfo->usData0;
					
					pTarget->SetTimerCommand(cmd, ::TimeGet() + tmDelay, pszEffect, pszSound);
				}

	
				if (pSender && !pTarget->IsNpc() && !pTarget->IsMyPet())
				{
					const OBJID idMsgDie = 100123;
					g_objGameMsg.AddMsg(_TXTATR_TALK, g_objGameDataSet.GetStr(idMsgDie), pTarget->GetName(), pSender->GetName());
				}
			}

			if (pSender)
			{
				// ko count...
				if (pSender->GetID() == g_objHero.GetID() && pTarget && pTarget->IsMonster()
					&& g_objHero.TestStatus(USERSTATUS_XPFULL))
				{
					g_objHero.AddKoCount();
//					g_objHero.ResetXpFullTime(m_pInfo->usData1);
				}
				if (pTarget->IsPet())
					pTarget->m_objEffect.Add("baby_d2");
				
			}
		}
		break;
	case INTERACT_SOUL:
		// soul ...
		if(!pSender->IsNpc() && pSender->IsPet())
		{
			CPet* pPet = (CPet*)pSender;
			if (pPet->IsMyPet()) 
			{
				pPet->AddPetSoul(m_pInfo->dwData);
			}
			for(int i=0;i<m_pInfo->dwData;i++)
			{
				CMagicEffect* pEffect = 
					CMagicEffect::CreateNew(m_pInfo->idTarget, m_pInfo->idSender,
					0, 0, MAGICEFFECT_SOUL,i);
				if(pEffect)
				{
					g_objGameMap.AddMagicEffect(pEffect);
				}
			}
		}
		break;		

	case INTERACT_ABORTMAGIC:
		{
			if(!pSender->IsMoving() && pSender->GetID() == g_objHero.GetID())
				g_objHero.SetActionCmd(_ACTION_STANDBY);
		}
		break;
	case INTERACT_SHOOT:
		{
			if(pSender && pTarget )
			{
				if ( pTarget->GetID() == g_objHero.GetID())
					g_objHero.SetIDWhoAttackMe(pSender->GetID());
				else
					pTarget->SetIDWhoAttackMe(pSender->GetID());				
			}
			if(pSender && pTarget && (pTarget->GetID() == g_objHero.GetID() || pTarget->IsMyPet()))
				g_objHero.SetIDMyTarget(pTarget->GetID());
#ifdef _DEBUG
			if(pTarget->IsMyPet())
				g_objGameMsg.AddMsg("4");
#endif
			BOOL bFirst = g_objHero.m_bFirstAtk;
			if (pSender && g_objHero.GetID() == pSender->GetID())
			{
				if (g_objHero.m_bFirstAtk)
				{
					g_objHero.m_bFirstAtk = false;
				}
				else
				{
					int nAction = _ACTION_ATTACK0+::RandGet(3);
					int nDir	= g_objHero.GetDir(pTarget);
					g_objHero.SetActionCmd(nAction, nDir);

					CMagicEffect* pEffect = CMagicEffect::CreateNew(pSender->GetID(), pTarget->GetID(), pSender->GetRWeapon(), 0);
					g_objGameMap.AddMagicEffect(pEffect);
					pEffect->AddRoleInfo(m_pInfo->idTarget, m_pInfo->dwData);
					return;
				}
			}
			else
			{
				pSender->ResetStepDir();
				
				int nAction = _ACTION_ATTACK0+::RandGet(3);
				int nDir	= pSender->GetDir(pTarget);
				pSender->SetActionCmd(nAction, nDir); 
			}
			if (g_objHero.GetID() == pSender->GetID() && bFirst)
			{
				// show target lose hp
				if (m_pInfo->dwData > 0)
				{
					if (!pTarget->IsAttacking())
						pTarget->SetActionCmd(_ACTION_BRUISE0, pTarget->GetDir(pSender));
					
					DWORD dwColor = _COLOR_YELLOW;
					if (g_objHero.GetID() == pTarget->GetID())
						dwColor = _COLOR_RED;
					pTarget->AddZoomNum(m_pInfo->dwData, dwColor, 300, 30);
					
					if (pTarget->IsNpc() )
					{
						int nLife = (int)pTarget->GetData(CPlayer::_PLAYER_LIFE)-(int)m_pInfo->dwData;
						pTarget->SetData(CPlayer::_PLAYER_LIFE, __max(0, nLife));
						pTarget->SetLife(__max(0, nLife));
					}
				}
				else
				{
					pTarget->AddZoomNum(m_pInfo->dwData, _COLOR_YELLOW, 300, 30);
					if (!pTarget->IsAttacking() && pTarget->IsPlayer())
						pTarget->SetActionCmd(_ACTION_DODGE0, pTarget->GetDir(pSender));
				}
				
			}
			else
			{
				pSender->ResetStepDir();
				
				if (!pSender->IsMoving())
				{
					pSender->ResetActionData();
				}
				
				int nAction = _ACTION_ATTACK0+::RandGet(3);
				int nDir	= pSender->GetDir(pTarget);
				pSender->SetActionCmd(nAction, nDir); 
				// create arrow
				if(pSender && pTarget)
				{
					CMagicEffect* pEffect = CMagicEffect::CreateNew(pSender->GetID(), pTarget->GetID(), pSender->GetRWeapon(), 0);
					g_objGameMap.AddMagicEffect(pEffect);
					pEffect->AddRoleInfo(m_pInfo->idTarget, m_pInfo->dwData);
					/*
					CMagicEffect* pEffect = CMagicEffect::CreateNewArrow(pSender->GetID(), pTarget->GetID(), pSender->GetLWeapon());
					g_objGameMap.AddMagicEffect(pEffect);
					pEffect->AddRoleInfo(m_pInfo->idTarget, m_pInfo->dwData);
					*/
				}
			}
		}
		break;
	default:
		break;
	}
}

⌨️ 快捷键说明

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