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

📄 hero.cpp

📁 网络游戏魔域源代码 测试可以完整变异
💻 CPP
📖 第 1 页 / 共 5 页
字号:
				this->AddProfessionalCoolposEffect(this->GetProfession(), false);
		}
	}
}

//////////////////////////////////////////////////////////////////////
void CHero::Stop(void)
{
	CCommand cmd;
	cmd.iType		=_COMMAND_STOP;
	cmd.iStatus		=_CMDSTATUS_BEGIN;
	
	this->SetCommand(&cmd);
}

//////////////////////////////////////////////////////////////////////
void CHero::Poison(CPlayer* pTarget, OBJID idItem)
{
/*	if (!pTarget || idItem == ID_NONE)
		return;

	if (this->IsDead() || pTarget->IsDead())
		return;

	if (!this->GetItem(idItem))
	{
		const OBJID idItemNotFound = 100031;
		g_objGameMsg.AddMsg(g_objGameDataSet.GetStr(idItemNotFound));
		return;
	}

	// set command of role
	CCommand cmd;
	cmd.iType		=_COMMAND_ACTION;
	cmd.iStatus		=_CMDSTATUS_BEGIN;
	cmd.nData		=_ACTION_CAST;
	cmd.nDir		=this->GetDir(pTarget);
 
	this->SetCommand(&cmd);

	// send msg
	CMyPos posHero;
	this->GetPos(posHero);

	CMsgInteract msg;
	if(msg.Create(INTERACT_POISON, this->GetID(), pTarget->GetID(), posHero.x, posHero.y, idItem))
		msg.Send();*/
}

//////////////////////////////////////////////////////////////////////
void CHero::Dart(CPlayer* pTarget, OBJID idItem)
{
/*	if (!pTarget || idItem == ID_NONE)
		return;

	if (this->IsDead() || pTarget->IsDead())
		return;

	if (!this->GetItem(idItem))
	{
		const OBJID idItemNotFound = 100031;
		g_objGameMsg.AddMsg(g_objGameDataSet.GetStr(idItemNotFound));
		return;
	}

	// set command of role
	CCommand cmd;
	cmd.iType		=_COMMAND_ACTION;
	cmd.iStatus		=_CMDSTATUS_BEGIN;
	cmd.nData		=_ACTION_CAST;
	cmd.nDir		=this->GetDir(pTarget);
 
	this->SetCommand(&cmd);

	// send msg
	CMyPos posHero;
	this->GetPos(posHero);

	CMsgInteract msg;
	if(msg.Create(INTERACT_ASSASSINATE, this->GetID(), pTarget->GetID(), posHero.x, posHero.y, idItem))
		msg.Send();*/
}

//////////////////////////////////////////////////////////////////////

void CHero::Steal(CPlayer* pTarget)
{
	if (!pTarget)
		return;

	if (this->IsDead() || pTarget->IsDead())
		return;

	// send msg
	CMyPos posHero;
	this->GetPos(posHero);

	CMsgInteract msg;
	if(msg.Create(INTERACT_STEAL, this->GetID(), pTarget->GetID(), posHero.x, posHero.y))
		msg.Send();
}

//////////////////////////////////////////////////////////////////////
int nAcxcount = 0;

DWORD CHero::SetCommand(CCommand* pCommand)
{
	if (!pCommand)
		return false;
	m_dwCommandIndex++;
	pCommand->dwIndex = m_dwCommandIndex;	
	// lock attack 命令不可积累
	if(pCommand->iType == _COMMAND_LOCKATK ||
		pCommand->iType == _COMMAND_WALK ||
		pCommand->iType == _COMMAND_RUN)
	{
		for(int i = 0; i < m_infoPlayer.setCmd.size(); i ++)
		{
			if(m_infoPlayer.setCmd[i].iType ==  _COMMAND_LOCKATK ||
				pCommand->iType == _COMMAND_WALK ||
				pCommand->iType == _COMMAND_RUN)
			{
				m_infoPlayer.setCmd.erase(m_infoPlayer.setCmd.begin() + i);
				break;
			}
		}
	}
	// 受伤动作不累积
	// dodge动作不累积
	if(pCommand->iType == _COMMAND_ACTION)
	if(pCommand->nData == _ACTION_DODGE0 || pCommand->nData == _ACTION_BRUISE0)
	{
		if(m_infoPlayer.setCmd.size() != 0)
			return false;
	}
	if(pCommand->iType == _COMMAND_INTONE && !pCommand->bAddUp)
	{
		if(m_infoPlayer.setCmd.size() != 0)
			return false;
	}

	m_infoPlayer.setCmd.push_back(*pCommand);

	if(this->IsMoving() && _COMMAND_ATTACK == pCommand->iType)
		return m_dwCommandIndex;
	if(pCommand->iType == _COMMAND_INTONE || pCommand->iType == _COMMAND_EMOTION || pCommand->iType == _COMMAND_ACTION)
	{
		if(((pCommand->nData == _ACTION_BRUISE0) || (pCommand->nData == _ACTION_DODGE0)) && (this->m_Info.cmdProc.iType == _COMMAND_EMOTION) && 
			(m_Info.cmdProc.nData == _ACTION_INTONE || m_Info.cmdProc.nData == _ACTION_INTONE_DURATION))
			return m_dwCommandIndex;
	}
	if (_COMMAND_STANDBY != pCommand->iType)
	{
		// attack can be interrupted by Jump, Walk, Run, at any time.
		if(_COMMAND_ATTACK == m_Info.cmdProc.iType || 
			_COMMAND_SHOOT == m_Info.cmdProc.iType ||
			_COMMAND_WOUND == m_Info.cmdProc.iType||
			_COMMAND_DEFEND == m_Info.cmdProc.iType ||
			_COMMAND_ACTION == m_Info.cmdProc.iType)

		{
			if(pCommand->iType == _COMMAND_WALK ||
				pCommand->iType == _COMMAND_RUN ||
				pCommand->iType == _COMMAND_JUMP)
				this->ResetActionData();
		}

		// emotion, standby and action can be interrupted at any time.
		if (_COMMAND_STANDBY == m_Info.cmdProc.iType
				|| _COMMAND_EMOTION == m_Info.cmdProc.iType
				|| _COMMAND_INTONE == m_Info.cmdProc.iType)
			this->ResetActionData();


		// cmd accomplished can be interrupted at andy time
		if (_CMDSTATUS_ACCOMPLISH == m_Info.cmdProc.iStatus)
		{
			if (_ACTION_STANDBY == m_Info.iActType 
				    || _ACTION_ALERT == m_Info.iActType
					|| _ACTION_REST1 == m_Info.iActType
					|| _ACTION_REST2 == m_Info.iActType
					|| _ACTION_REST3 == m_Info.iActType)
				this->ResetActionData();
		}

		// die command can interrupt any command
		if (_COMMAND_DIE == pCommand->iType)
			this->ResetActionData();
	}

	// set command now
	if(pCommand->iType == _COMMAND_EMOTION)
	{
		if(pCommand->nData == _ACTION_INTONE)
		{
			nAcxcount ++;
			if(nAcxcount == 2)
				int lll= 1;
		}
	}

	memcpy(&(m_Info.cmdProc), pCommand, sizeof(CCommand));
	return m_dwCommandIndex;
}

//////////////////////////////////////////////////////////////////////
BOOL CHero::ProcessCommand(void)
{
	int iPosX, iPosY;
	this->GetPos(iPosX, iPosY);
	//--------------------------------------------------------
	if(_COMMAND_JUMP == m_Info.cmdProc.iType) 
	{
		if(_CMDSTATUS_BEGIN == m_Info.cmdProc.iStatus)		// is a new jump cmd
		{
/*			CONST MAX_JUMPDISTANCE = 16;
			if (MAX_JUMPDISTANCE < g_objGameMap.GetDistance(iPosX, iPosY, m_Info.cmdProc.posTarget.x, m_Info.cmdProc.posTarget.y))
			{
				this->SetActionCmd(_ACTION_STANDBY);
				const OBJID idCanNotJumpSoFar = 100032;
				g_objGameMsg.AddMsg(g_objGameDataSet.GetStr(idCanNotJumpSoFar));
				return false;
			}
*/
			CMsgAction msg;
			if(msg.Create(this->GetID(), iPosX, iPosY, m_Info.cmdProc.nDir, actionJump, m_Info.cmdProc.posTarget.x, m_Info.cmdProc.posTarget.y, m_Info.cmdProc.dwData))
 				msg.Send();
		}
	}

	//--------------------------------------------------------
	if(_COMMAND_EMOTION == m_Info.cmdProc.iType) 
	{
		if(_CMDSTATUS_BEGIN == m_Info.cmdProc.iStatus && m_Info.cmdProc.bHeroSendMsg)		// is a new emotion cmd
		{
			CMsgAction	msg;
			if(msg.Create(this->GetID(), iPosX, iPosY, m_Info.cmdProc.nDir, actionEmotion, m_Info.cmdProc.nData))
				msg.Send();
		}
	}

	//--------------------------------------------------------	
	if(_COMMAND_ATTACK == m_Info.cmdProc.iType) 
	{
		if(_CMDSTATUS_BEGIN == m_Info.cmdProc.iStatus)		// is a new atk cmd
		{
			CMsgInteract msg;
			if(msg.Create(INTERACT_ATTACK, this->GetID(), m_Info.cmdProc.idTarget, iPosX, iPosY))
				msg.Send();
		}
	}

	//--------------------------------------------------------
	if(_COMMAND_SHOOT == m_Info.cmdProc.iType) 
	{	
		if(_CMDSTATUS_BEGIN == m_Info.cmdProc.iStatus)		// is a new atk cmd
		{
			// 转移到普通攻击
			m_Info.cmdProc.iType = _COMMAND_ATTACK;
			CMsgInteract msg;
			if(msg.Create(INTERACT_SHOOT, this->GetID(), m_Info.cmdProc.idTarget, m_Info.cmdProc.dwData))
			{
				msg.Send();
				CMagicEffect* pEffect = CMagicEffect::CreateNewArrow(this->GetID(), m_Info.cmdProc.idTarget, m_Info.cmdProc.nData);
				g_objGameMap.AddMagicEffect(pEffect);
			}
		}
	}

	//--------------------------------------------------------
	if(_COMMAND_RUSHATK == m_Info.cmdProc.iType) 
	{
		if(_CMDSTATUS_BEGIN == m_Info.cmdProc.iStatus)
		{
			CMsgInteract msg;
			if(msg.Create(INTERACT_RUSHATK, this->GetID(), m_Info.cmdProc.idTarget, iPosX, iPosY, m_Info.cmdProc.posTarget.x, m_Info.cmdProc.posTarget.y, m_Info.cmdProc.idTarget))
				msg.Send();
		}
	}

	//--------------------------------------------------------
	// do command now
	//int iStatusBk	=m_Info.cmdProc.iStatus;
	BOOL bAcomplished	=CRole::ProcessCommand();
	//--------------------------------------------------------
	this->GetPos(iPosX, iPosY);
	
	switch(this->GetActionType())
	{
	case _ACTION_PICKUP:
		{
			CMsgMapItem msg;
			if(msg.Create(m_Info.cmdProc.idTarget, iPosX, iPosY))
				msg.Send();
		}
		break;

	case _ACTION_BUMP:
		{
			CONST MAGIC_BUMP = 1051;
			CMagic* pMagic = this->GetMagic(MAGIC_BUMP);
			if (pMagic)
			{
				int nDir = this->GetDir();
				CMsgInteract msg;
				OBJID idUser = this->GetID();
				unsigned short usMagicType = MAGIC_BUMP;
				OBJID idTarget = 0;
				int nPosX = iPosX;
				int nPosY = iPosY;

				ENCODE_MAGICATTACK(idUser, usMagicType, nDir, nPosX, nPosY)

				IF_SUC (msg.Create( INTERACT_MAGICATTACK, 
									idUser,
									nDir,
									nPosX,
									nPosY,
									usMagicType,
									pMagic->m_infoMagicType.dwLevel,
									nDir))
					msg.Send();
			}
		}
		break;

	case _ACTION_WALKL:
	case _ACTION_WALKR:
		{
			if(m_Info.posActionBegin.x != m_Info.posActionEnd.x ||
				m_Info.posActionBegin.y != m_Info.posActionEnd.y)
			{
				CMyPos posHero;
				this->GetPos(posHero);
				CMsgWalk msg;
				if(msg.Create(this->GetID(),this->GetDir()+8*::RandGet(31)))
					msg.Send();
			}
		}
		break;
		
	case _ACTION_RUNL:
	case _ACTION_RUNR:
		{
			CMyPos posHero;
			this->GetPos(posHero);
			CMsgWalk msg;
			if(msg.Create(this->GetID(),this->GetDir()+8*::RandGet(31), m_Info.nNextStep))
				msg.Send();
		}
		break;
	}
	
	if (this->GetLastCommand() == _COMMAND_LOCKBOOTH && 
			this->GetCommandStatus() == _CMDSTATUS_ACCOMPLISH)
	{
		CMyPos posHero;
		this->GetPos(posHero);
		this->m_objBoothManager.Open();
		CMsgAction msg;
		if (msg.Create(this->GetID(), posHero.x, posHero.y, this->GetDir(), actionChgDir))
			msg.Send();
	}
	if (this->GetLastCommand() == _COMMAND_LOCKATK && 
			this->GetCommandStatus() == _CMDSTATUS_ACCOMPLISH)
	{
		if(!this->HaveBow())
		{
			CPlayer* pPlayer = g_objPlayerSet.GetPlayer(m_Info.cmdProc.idTarget);
			if(pPlayer && (pPlayer->GetRoleType() == _ROLE_STONE_MINE )) 
//							||pPlayer->GetRoleType() == _ROLE_WOOD_NPC))
			{
				CMsgInteract msg;
				if (msg.Create(INTERACT_MINE, this->GetID(), m_Info.cmdProc.idTarget, iPosX, iPosY))
					msg.Send();
			}
			else
			{
				CMsgInteract msg;
				if (msg.Create(INTERACT_ATTACK, this->GetID(), m_Info.cmdProc.idTarget, iPosX, iPosY))
					msg.Send();
			}
		}
		else
		{
			CMsgInteract msg;
			if(msg.Create(INTERACT_SHOOT, this->GetID(), m_Info.cmdProc.idTarget, m_Info.cmdProc.dwData))
				msg.Send();
		}
	}

	//--------------------------------------------------------
	return bAcomplished;
}

//////////////////////////////////////////////////////////////////////
void CHero::SetAlignPos(int nPosX, int nPosY)
{
	CMyPos posHeroAlign	=g_objHero.GetAlignPos();
	g_objPlayerSet.ProcessManager(posHeroAlign.x, posHeroAlign.y);
	g_objGameMap.ProcessManager();
	m_posAlign.x	=nPosX;
	m_posAlign.y	=nPosY;
	g_objGameMap.ProcessRegion(m_posAlign);

	// 自动召唤幻兽
	RECT CallRegion = {504,541,521,574};
	if (this->GetLev() < 2 && m_posAlign.x > CallRegion.left && m_posAlign.x < CallRegion.right
		&& m_posAlign.y > CallRegion.top && m_posAlign.y < CallRegion.bottom) 
	{
		::PostCmd(CMD_CALL_PET_OUT);
	}

	//幻兽走动
	int iPosX, iPosY;
	this->GetPos(iPosX, iPosY);
    //--------------------------------------
	//	if(_COMMAND_JUMP == m_Info.cmdProc.iType || _COMMAND_WALK== m_Info.cmdProc.iType
	//		|| _COMMAND_RUN == m_Info.cmdProc.iType )
	{
		const int MAX_CALL_PET = 3;
		CMyPos posTemp[MAX_CALL_PET];	
		int nHeroDir = g_objHero.GetDir();
		if(this->GetProfession() == PROFESSIONAL_WARRIOR )
		{
			posTemp[0].x = iPosX + _DELTA_X[(nHeroDir+4)%8]*4;
			posTemp[0].y = iPosY + _DELTA_Y[(nHeroDir+4)%8]*4;
			posTemp[1].x = iPosX + _DELTA_X[(nHeroDir+3)%8]*4;
			posTemp[1].y = iPosY + _DELTA_Y[(nHeroDir+3)%8]*4;	
			posTemp[2].x = iPosX + _DELTA_X[(nHeroDir+5)%8]*4;
			posTemp[2].y = iPosY + _DELTA_Y[(nHeroDir+5)%8]*4;
		}
		else if(this->GetProfession() == PROFESSIONAL_ENCHANTER)
		{
			posTemp[0].x = iPosX + _DELTA_X[(nHeroDir+1)%8]*4;
			posTemp[0].y = iPosY + _DELTA_Y[(nHeroDir+1)%8]*4;
			posTemp[1].x = iPosX + _DELTA_X[(nHeroDir+7)%8]*4;
			posTemp[1].y = iPosY + _DELTA_Y[(nHeroDir+7)%8]*4;				
		}
		CPet* pPet = NULL;
		for(int i = 0 ;i < m_setPetInfo.size();i++)
		{			pPet = GetPetByIndex(i);
			if(pPet)
			{
				pPet->SetNextPos(posTemp[i].x,posTemp[i].y);
			}
		}
	}
	
	//--------------------------------------
//	::DebugMsg("英雄对齐坐标(%d, %d)", posHeroAlign.x, posHeroAlign.y);
}

//////////////////////////////////////////////////////////////////////
DWORD	CHero::GetDef()
{
	float fDef = 0.0f;
	fDef += this->GetHealth()*0.5f;

	for (int i=0; i<_MAX_EQUIPMENT; i++)
	{
		if(m_pEquipment[i])
		{
			fDef += m_pEquipment[i]->GetDefense();
		}
	}
	
	fDef += 0.5f ;
	return fDef;
}
//////////////////////////////////////////////////////////////////////
DWORD	CHero::GetMagicDef()
{
	float fDef = 0.0f;
	switch(this->GetProfessionSort())
	{
	case PROFSORT_SOLDIER:
		fDef += this->GetHealth()*0.5f;
		break;
		
	case PROFSORT_ARCHER:
		fDef += this->GetSoul()*0.5f;
		break;
		
	case PROFSORT_MAGICIAN:
		fDef += this->GetSoul()*0.5f;
		break;
	}
	
	for (int i=0; i<_MAX_EQUIPMENT; i++)
	{
		if(m_pEquipment[i])
		{
			fDef += m_pEquipment[i]->GetMagicDefence();
		}
	}
	
	fDef += 0.5f;
	
	return fDef;
}
//////////////////////////////////////////////////////////////////////

DWORD CHero::GetMaxMagicAtk()
{
	float fAtk = 0.0f;
	switch(this->GetProfessionSort())
	{
	case PROFSORT_MAGICIAN:
		fAtk += this->GetSoul()*0.5f;
		break;
	}
	int nAttack = fAtk + 0.5f;
	for (int i=0; i<_MAX_EQUIPMENT; i++)
	{
		if(m_pEquipment[i])
		{
			nAttack += m_pEquipment[i]->GetMaxMagicAttack();
		}
	}
	

⌨️ 快捷键说明

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