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

📄 roleaction.cpp

📁 网络游戏魔域源代码 测试可以完整变异
💻 CPP
📖 第 1 页 / 共 4 页
字号:
			return false;
		}
	}
	
	if (m_Info.cmdProc.iStatus == _CMDSTATUS_PROGRESS ||
		m_Info.cmdProc.iStatus == _CMDSTATUS_CONTINUE)
	{
		if(m_Info.objPath.GetStepAmount() > 0) // not reach target
		{
			StepInfo infoStep;
			m_Info.objPath.GetNextStep(infoStep);
			m_Info.iDirection = infoStep.cStepDir;
			Step();	
			
			// reset action
			if (m_Info.cmdProc.iStatus == _CMDSTATUS_PROGRESS)
			{
				m_Info.cmdProc.iStatus	=_CMDSTATUS_CONTINUE;
				if(m_Info.iActType == _ACTION_WALKR)
					m_Info.iActType	=_ACTION_WALKL;
				else
					m_Info.iActType = _ACTION_WALKR;
			}
			else
			{
				m_Info.cmdProc.iStatus	=_CMDSTATUS_PROGRESS;
				if(m_Info.iActType == _ACTION_WALKR)
					m_Info.iActType	=_ACTION_WALKL;
				else
					m_Info.iActType = _ACTION_WALKR;
			}
		}
		else
		{
			m_Info.objPath.ClearStep();
			m_Info.cmdProc.iStatus	=_CMDSTATUS_ACCOMPLISH;
			
			StandBy();
		}
	}
	
#else
	if(m_Info.cmdProc.iStatus==_CMDSTATUS_BEGIN)
	{
		m_Info.cmdProc.iStatus	=_CMDSTATUS_PROGRESS;
	}
	
	if(m_Info.cmdProc.iStatus == _CMDSTATUS_PROGRESS ||
		m_Info.cmdProc.iStatus == _CMDSTATUS_CONTINUE)
	{
		// reach the target?
		if(IsMapReached())
		{
			m_Info.cmdProc.iStatus	=_CMDSTATUS_ACCOMPLISH;
			StandBy();
		}
		else
		{
			int iStepDir	=GetStepDir();
			if(iStepDir==-1)
				StandBy();
			else
			{
				m_Info.iDirection	=iStepDir;
				Step();
				
				// reset action
				if (m_Info.cmdProc.iStatus == _CMDSTATUS_PROGRESS)
				{
					m_Info.cmdProc.iStatus	=_CMDSTATUS_CONTINUE;
					m_Info.iActType	=_ACTION_WALKL;
				}
				else
				{
					m_Info.cmdProc.iStatus	=_CMDSTATUS_PROGRESS;
					m_Info.iActType	=_ACTION_WALKR;
				}
			}
		}
	}
	
#endif
	
	if(m_Info.cmdProc.iStatus==_CMDSTATUS_ACCOMPLISH)
		return true;
	else
		return false;
}

//--------------------------------------------------------------
// return false always...
BOOL CRole::WalkForward(void)
{
	assert(m_Info.cmdProc.iType == _COMMAND_WALKFORWARD);
	
	/*
	if (m_Info.cmdProc.iStatus == _CMDSTATUS_BEGIN)
	m_Info.cmdProc.iStatus	=_CMDSTATUS_PROGRESS;
	
	  if (m_lstStepDir.size() <= 0)
	  {
	  this->StandBy();
	  }
	  else
	  {
	  m_Info.iDirection	=m_lstStepDir.front();
	  m_lstStepDir.pop_front();
	  
		this->Step();
		}
		
		  return false;
	*/
	
	m_Info.cmdProc.iStatus	=_CMDSTATUS_ACCOMPLISH;
	
	this->SetDir(m_Info.cmdProc.nDir);
	this->Step();
	
	return true;
}

//--------------------------------------------------------------
// Add step, continue run, not interrupt
void	CRole::AddStep(CMyPos posCell)
{
	CPath objPath;
	objPath.ClearStep();
	m_Info.objPath.ClearStep();
	CMyPos posHero;
	g_objGameMap.World2Cell(m_Info.posActionEnd.x, m_Info.posActionEnd.y, posHero.x, posHero.y);
	g_objGameMap.FindPath(objPath, posHero, posCell);
	int nAmount = objPath.GetStepAmount();
	for(int i= 0; i < nAmount; i ++)
	{
		StepInfo infoStep;
		objPath.GetNextStep(infoStep);
		m_Info.objPath.AddStep(infoStep.cStepDir, infoStep.ucStepLength);
	}
}
//--------------------------------------------------------------

// return true if reached target place
BOOL CRole::Run(void)
{
	assert(m_Info.cmdProc.iType==_COMMAND_RUN);

#ifdef	_USE_ASTAR
	if (m_Info.cmdProc.iStatus==_CMDSTATUS_BEGIN)
	{
		m_Info.objPath.ClearStep();

		g_objGameMap.FindPath(m_Info.objPath, m_Info.posMap, m_Info.cmdProc.posTarget);

		if(m_Info.objPath.GetStepAmount() > 0)
		{
			m_Info.cmdProc.iStatus	=_CMDSTATUS_PROGRESS;
		}
		else
		{
			m_Info.objPath.ClearStep();
			m_Info.cmdProc.iStatus	=_CMDSTATUS_ACCOMPLISH;

			StandBy();
			return false;
		}
	}

	if (m_Info.cmdProc.iStatus == _CMDSTATUS_PROGRESS ||
			m_Info.cmdProc.iStatus == _CMDSTATUS_CONTINUE)
	{
		if(m_Info.objPath.GetStepAmount() > 0) // not reach target
		{
			StepInfo infoStep;
			m_Info.objPath.GetNextStep(infoStep);
			m_Info.iDirection	=infoStep.cStepDir;
			Step();	

			// reset action
			if (m_Info.cmdProc.iStatus == _CMDSTATUS_PROGRESS)
			{
				m_Info.cmdProc.iStatus	=_CMDSTATUS_CONTINUE;
				if(m_Info.iActType == _ACTION_RUNR || m_Info.iActType == _ACTION_RUNL)
				{
/*					if(m_Info.iActType == _ACTION_RUNR)
						m_Info.iActType	=_ACTION_RUNL;
					else
						m_Info.iActType = _ACTION_RUNL;*/
				}
				else
				{
/*					if(m_Info.iActType == _ACTION_WALKR)
						m_Info.iActType	=_ACTION_WALKL;
					else
						m_Info.iActType = _ACTION_WALKL;*/
				}
			}
			else
			{
				m_Info.cmdProc.iStatus	=_CMDSTATUS_PROGRESS;
				if(m_Info.iActType == _ACTION_RUNR || m_Info.iActType == _ACTION_RUNL)
				{
/*					if(m_Info.iActType == _ACTION_RUNR)
						m_Info.iActType	=_ACTION_RUNL;
					else
						m_Info.iActType = _ACTION_RUNL;*/
				}
				else
				{
/*					if(m_Info.iActType == _ACTION_WALKR)
						m_Info.iActType	=_ACTION_WALKL;
					else
						m_Info.iActType = _ACTION_WALKL;*/
				}
			}
		}
		else
		{
			m_Info.objPath.ClearStep();
			m_Info.cmdProc.iStatus	=_CMDSTATUS_ACCOMPLISH;

			StandBy();
		}
	}

#else
	if(m_Info.cmdProc.iStatus==_CMDSTATUS_BEGIN)
	{
		m_Info.cmdProc.iStatus	=_CMDSTATUS_PROGRESS;
	}

	if(m_Info.cmdProc.iStatus == _CMDSTATUS_PROGRESS ||
			m_Info.cmdProc.iStatus == _CMDSTATUS_CONTINUE)
	{
		// reach the target?
		if(IsMapReached())
		{
			m_Info.cmdProc.iStatus	=_CMDSTATUS_ACCOMPLISH;
			StandBy();
		}
		else
		{
			int iStepDir	=GetStepDir();
			if(iStepDir==-1)
				StandBy();
			else
			{
				m_Info.iDirection	=iStepDir;
				Step();

				// reset action
				if (m_Info.cmdProc.iStatus == _CMDSTATUS_PROGRESS)
				{
					m_Info.cmdProc.iStatus	=_CMDSTATUS_CONTINUE;
					if(!m_Info.bAdjustRun)
						m_Info.iActType	=_ACTION_RUNL;
					else
						m_Info.iActType	=_ACTION_WALKL;
				}
				else
				{
					m_Info.cmdProc.iStatus	=_CMDSTATUS_PROGRESS;
					if(!m_Info.bAdjustRun)
						m_Info.iActType	=_ACTION_RUNR;
					else
						m_Info.iActType	=_ACTION_WALKR;
				}
			}
		}
	}

#endif

	if(m_Info.cmdProc.iStatus==_CMDSTATUS_ACCOMPLISH)
		return true;
	else
		return false;
}

//--------------------------------------------------------------
// return false always...
BOOL CRole::RunForward(void)
{
	assert(m_Info.cmdProc.iType == _COMMAND_RUNFORWARD);
	
	/*
	if (m_Info.cmdProc.iStatus == _CMDSTATUS_BEGIN)
	m_Info.cmdProc.iStatus	=_CMDSTATUS_PROGRESS;
	
	  if (m_lstStepDir.size() <= 0)
	  {
	  this->StandBy();
	  }
	  else
	  {
	  m_Info.iDirection	=m_lstStepDir.front();
	  m_lstStepDir.pop_front();
	  
		this->Step();
		
		  // reset action
		  if (m_Info.cmdProc.iStatus == _CMDSTATUS_PROGRESS)
		  {
		  m_Info.iActType	=_ACTION_RUNL;
		  m_Info.cmdProc.iStatus =_CMDSTATUS_CONTINUE;
		  }
		  else if (m_Info.cmdProc.iStatus == _CMDSTATUS_CONTINUE)
		  {
		  m_Info.iActType	=_ACTION_RUNR;
		  m_Info.cmdProc.iStatus =_CMDSTATUS_PROGRESS;
		  }		
		  }
		  
			return false;
	*/
	
	m_Info.cmdProc.iStatus	=_CMDSTATUS_ACCOMPLISH;
	
	int nPreAction = m_Info.iActType;
	this->SetDir(m_Info.cmdProc.nDir);
	m_Info.objPath.AddStep(m_Info.cmdProc.dwData, 32);
	this->Step();
	
	/*	if (_ACTION_RUNR == nPreAction)	// last action is runR
	m_Info.iActType	=_ACTION_RUNL;
	else
	m_Info.iActType	=_ACTION_RUNR;*/
	
	return true;
}

//--------------------------------------------------------------
BOOL CRole::Follow(void)
{
	assert(_COMMAND_FOLLOW == m_Info.cmdProc.iType);

	// get follow target
	CRole*	pTarget	=g_objPlayerSet.GetPlayer(m_Info.cmdProc.idTarget);
	if(!pTarget)
	{
		if(g_objHero.GetID() == m_Info.cmdProc.idTarget)
			pTarget	=&g_objHero;
		else	// error, no target found
		{
			m_Info.cmdProc.iStatus	=_CMDSTATUS_ACCOMPLISH;
			StandBy();
			return false;
		}
	}

	// get follow pos
	int nTargetX=0, nTargetY=0;
	pTarget->GetPrePos(nTargetX, nTargetY);

	if(nTargetX != m_Info.cmdProc.posTarget.x ||
			nTargetY != m_Info.cmdProc.posTarget.y)
	{
		m_Info.cmdProc.iStatus		=_CMDSTATUS_BEGIN;
		m_Info.cmdProc.posTarget.x	=nTargetX;
		m_Info.cmdProc.posTarget.y	=nTargetY;
	}

	// step now...
#ifdef	_USE_ASTAR
	if (m_Info.cmdProc.iStatus==_CMDSTATUS_BEGIN)
	{
		m_Info.objPath.ClearStep();

		g_objGameMap.FindPath(m_Info.objPath, m_Info.posMap, m_Info.cmdProc.posTarget);

		if(m_Info.objPath.GetStepAmount() > 0)
		{
			m_Info.cmdProc.iStatus	=_CMDSTATUS_PROGRESS;
		}
		else
		{
			m_Info.objPath.ClearStep();
			m_Info.cmdProc.iStatus	=_CMDSTATUS_ACCOMPLISH;

			StandBy();
			return false;
		}
	}

	if (m_Info.cmdProc.iStatus == _CMDSTATUS_PROGRESS ||
			m_Info.cmdProc.iStatus == _CMDSTATUS_CONTINUE)
	{
		if(m_Info.objPath.GetStepAmount() > 0) // not reach target
		{
			StepInfo infoStep;
			m_Info.objPath.GetNextStep(infoStep);
			m_Info.iDirection	=infoStep.cStepDir;

			// reset action
			if (m_Info.cmdProc.iStatus == _CMDSTATUS_PROGRESS)
			{
				m_Info.cmdProc.iStatus	=_CMDSTATUS_CONTINUE;
			}
			else
			{
				m_Info.cmdProc.iStatus	=_CMDSTATUS_PROGRESS;
			}
			Step();	
		}
		else
		{
			m_Info.objPath.ClearStep();
			m_Info.cmdProc.iStatus	=_CMDSTATUS_ACCOMPLISH;

			StandBy();
		}
	}
	
#else
	if(m_Info.cmdProc.iStatus == _CMDSTATUS_BEGIN)
	{
		m_Info.cmdProc.iStatus	=_CMDSTATUS_PROGRESS;
	}

	if(m_Info.cmdProc.iStatus == _CMDSTATUS_PROGRESS)
	{
		if(m_Info.posMap.x == m_Info.cmdProc.posData.x &&
				m_Info.posMap.y == m_Info.cmdProc.posData.y)
		{
			m_Info.cmdProc.iStatus	=_CMDSTATUS_CONTINUE;
			StandBy();
		}
		else
		{
			int iStepDir	=GetStepDir();
			if(iStepDir==-1)
				StandBy();
			else
			{
				m_Info.iDirection	=iStepDir;
				Step();
			}
		}
	}

#endif

	if(m_Info.cmdProc.iStatus==_CMDSTATUS_ACCOMPLISH)
		return true;
	else
		return false;
}


//--------------------------------------------------------------

void CRole::SetActionCmd(int nAction, int nDir/*=-1*/, DWORD dwType/*=0*/, BOOL bData/*=false*/)
{
	CCommand cmd;
	cmd.iType	= _COMMAND_ACTION;
	cmd.iStatus	= _CMDSTATUS_BEGIN;
	cmd.nData	= nAction;
	cmd.nDir	= (-1 == nDir) ? this->GetDir() : nDir;
	cmd.dwData	= dwType;
	cmd.bData	= bData;
	this->SetCommand(&cmd);
}

//--------------------------------------------------------------
void CRole::SetIntoneCmd(int nAction, int nDir/*=-1*/, DWORD dwType/*=0*/, BOOL bData/*=false*/)
{
	CCommand cmd;
	cmd.iType	= _COMMAND_INTONE;
	cmd.iStatus	= _CMDSTATUS_BEGIN;
	cmd.nData	= nAction;
	cmd.nDir	= (-1 == nDir) ? this->GetDir() : nDir;
	cmd.dwData	= dwType;
	cmd.bData	= bData;
	this->SetCommand(&cmd);
}

⌨️ 快捷键说明

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