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

📄 role.cpp

📁 网络游戏魔域源代码 测试可以完整变异
💻 CPP
📖 第 1 页 / 共 4 页
字号:
	posHighestWorldPos.y = (posBeginWorldPos.y + posEndWorldPos.y)/2;

	nHightestAltitude += 20;
	// 上升阶段还是下降阶段
	BOOL beUp = false;
	CMyPos posCurrentWorld;
	this->GetWorldPos(posCurrentWorld);

	DWORD dwB2N = (posBeginWorldPos.x - posCurrentWorld.x) * 
					(posBeginWorldPos.x - posCurrentWorld.x) + 
					(posBeginWorldPos.y - posCurrentWorld.y) * 
					(posBeginWorldPos.y - posCurrentWorld.y);

	DWORD dwB2H = (posBeginWorldPos.x - posHighestWorldPos.x) * 
					(posBeginWorldPos.x - posHighestWorldPos.x) + 
					(posBeginWorldPos.y - posHighestWorldPos.y) * 
					(posBeginWorldPos.y - posHighestWorldPos.y);
	if(dwB2H > dwB2N)
		beUp = true;

	// 计算高度
	int nHeight = 0;
	if(beUp)
	{
		int nHeightDef =  nHightestAltitude - nBeginAltitude;
		double dbDisNow = sqrt((posBeginWorldPos.x - posCurrentWorld.x) * (posBeginWorldPos.x - posCurrentWorld.x) +
 					   (posBeginWorldPos.y - posCurrentWorld.y) * (posBeginWorldPos.y - posCurrentWorld.y));
		double dbDisEnd = sqrt((posBeginWorldPos.x - posHighestWorldPos.x) * (posBeginWorldPos.x - posHighestWorldPos.x) +
 					   (posBeginWorldPos.y - posHighestWorldPos.y) * (posBeginWorldPos.y - posHighestWorldPos.y));
		if(dbDisEnd == 0)
			dbDisEnd = 1;
		double pi = 3.1415926535;
		double dbAngle = pi*dbDisNow/dbDisEnd/2;
		nHeight = nBeginAltitude + nHeightDef*sin(dbAngle);

	}
	else
	{
		int nHeightDef =  nHightestAltitude - nEndAltitude;
		double dbDisNow = sqrt((posEndWorldPos.x - posCurrentWorld.x) * (posEndWorldPos.x - posCurrentWorld.x) +
 					   (posEndWorldPos.y - posCurrentWorld.y) * (posEndWorldPos.y - posCurrentWorld.y));
		double dbDisEnd = sqrt((posEndWorldPos.x - posHighestWorldPos.x) * (posEndWorldPos.x - posHighestWorldPos.x) +
 					   (posEndWorldPos.y - posHighestWorldPos.y) * (posEndWorldPos.y - posHighestWorldPos.y));
		if(dbDisEnd == 0)
			dbDisEnd = 1;

		double pi = 3.1415926535;
		double dbAngle = pi*dbDisNow/dbDisEnd/2;
		nHeight = nEndAltitude + nHeightDef*sin(dbAngle);
	}
			
	return nHeight;	
}

//--------------------------------------------------------------
int CRole::GetJumpShadowHeight()
{
	int nHeight = this->GetJumpHeight();
	CMyPos posCell;
	g_objGameMap.World2Cell(m_Info.posWorld.x, m_Info.posWorld.y,
							posCell.x, posCell.y);
	CellInfo* pCellInfo = g_objGameMap.GetCell(posCell.x, posCell.y);
	if(!pCellInfo)
		return 0;	
	int nJumpShadowHeight = g_objGameMap.GetGroundAltitude(pCellInfo) - g_objGameMap.GetBaseAltitude(posCell) - nHeight;
	if(nJumpShadowHeight > 0)
		nJumpShadowHeight = 0;
	return nJumpShadowHeight;
}
//--------------------------------------------------------------
DWORD CRole::GetJumpFrameInterval()
{
	// 取得跳跃距离
	double dbDicAll = sqrt(
		(m_Info.posActionBegin.x- m_Info.posActionEnd.x) * 
		(m_Info.posActionBegin.x - m_Info.posActionEnd.x) +
		(m_Info.posActionBegin.y - m_Info.posActionEnd.y) * 
		(m_Info.posActionBegin.y - m_Info.posActionEnd.y)
		);
	// 取得标准帧间隔
	DWORD dwInteraval = this->GetFrameInterval(_ACTION_JUMP);
	DWORD dwMyInteraval = (DWORD) (dwInteraval*dbDicAll/300+1);
	if(dwMyInteraval < 36)
			dwMyInteraval = 36;
	return dwMyInteraval;
}
//--------------------------------------------------------------
int	CRole::GetOffsetY()
{
	int nOffsetY = 0;
	switch(this->GetActionType())
	{
	case _ACTION_JUMP:
		{
			nOffsetY = this->GetJumpHeight();
		}
		break;
	case _ACTION_WALKL:
	case _ACTION_WALKR:
	case _ACTION_RUNL:
	case _ACTION_RUNR:
		{
			nOffsetY = this->GetWalkHeight();
		}
		break;
	default:
		nOffsetY = g_objGameMap.GetAltitude(m_Info.posMap)- g_objGameMap.GetBaseAltitude(m_Info.posMap);
		break;
	}
	return nOffsetY;
}
//--------------------------------------------------------------
void CRole::AddFStr(char* pszStr, int nMaxHeight, DWORD dwColor, int nStepHeight, int nDelayTime)
{
	m_objFStr.AddStr(pszStr, nMaxHeight, dwColor, nStepHeight , nDelayTime);
}
//--------------------------------------------------------------
void CRole::AddZoomNum(int nNum, DWORD dwColor, DWORD dwDelay, int nRandOffset)
{	
	if (nNum > 0) 
		m_objZoomNum.Add(nNum, dwColor, dwDelay, nRandOffset);
	else
	{
		if (this->IsPlayer ()) 
			m_objEffect.Add("PMISS",false,0,this->GetLook());
		else 
			m_objEffect.Add("MISS",false,0,this->GetLook());
	}
}
//--------------------------------------------------------------
void CRole::Transform(int nIndex)
{
	CTransformInfo* pInfo = g_obj3DRoleData.GetTransformInfo(nIndex);
	if(!pInfo)
		return;
	if(!this->IsNpc())
	{
		this->SetAddSize(pInfo->nAddSize);
		this->SetZoomPercent(pInfo->nScale);
	}
	m_Info.nTransformLook = pInfo->nLook;
	if(m_pIRoleView)
		m_pIRoleView->SetVariable(_VAR_TRANSFORM, pInfo->nLook);
}
//--------------------------------------------------------------
void CRole::ShootArrow(OBJID idTarget, int nHpLose)
{
	CPlayer* pPlayer = g_objPlayerSet.GetPlayer(idTarget, true);
	if(!pPlayer)
		return;
	CMyPos posTarget;
	pPlayer->GetPos(posTarget);

	CCommand cmd;
	cmd.iType		=_COMMAND_ATTACK;
	cmd.iStatus		=_CMDSTATUS_BEGIN;
	cmd.idTarget	=idTarget;
	cmd.dwData		=nHpLose;
	cmd.nDir	=	this->GetDir(posTarget);
	this->SetCommand(&cmd);
	CMagicEffect* pMagicEffect = CMagicEffect::CreateNewArrow(this->GetID(), idTarget, 500000);
	g_objGameMap.AddMagicEffect(pMagicEffect);
}
//--------------------------------------------------------------
void CRole::SetDir(int nDir)
{
/*	if(this->GetID() == g_objHero.GetID() && nDir%8 == 4)
		int kk = 0;
*/
	m_Info.iDirection=nDir%8;
	if(m_Info.cmdProc.iType == _COMMAND_EMOTION)
		m_Info.cmdProc.nDir = m_Info.iDirection;
}
//--------------------------------------------------------------
void CRole::SetFlyOffset(int nOffset)
{
	m_Info.nFlyOffset = nOffset;
}
//--------------------------------------------------------------
int	CRole::GetFlyOffset()
{
	return m_Info.nFlyOffset;
}
//--------------------------------------------------------------
void CRole::SetFlyOffsetGoal(int nOffset)
{
	m_Info.nFlyOffsetGoal = nOffset;
}
//--------------------------------------------------------------
int	CRole::GetFlyOffsetGoal()
{
	return m_Info.nFlyOffsetGoal; 
}
//--------------------------------------------------------------
BOOL CRole::HaveBow()
{
	if(this->m_pIRoleView->GetVariable(_VAR_LOOKCLONE) != 0)
		return false;
	if(this->GetRWeapon()/1000%1000 == 500 || this->GetRWeapon()/1000%1000 == 501)
		return true;
	else
		return false;
}
//--------------------------------------------------------------
BOOL	CRole::IsGuard(void)
{
	if (this->IsNpc() && this->GetMonsterTypeId() >= 100 && this->GetMonsterTypeId() <= 199)
		return true;
	return false;
}
//--------------------------------------------------------------
BOOL	CRole::IsMyPet(void)
{
	if(!this->IsPet())
		return false;
	if(g_objHero.CheckPet(this->GetID()))
		return true;
	return false;
}
//--------------------------------------------------------------
BOOL	CRole::IsHypersensitive()
{
	int nRoleType = this->GetRoleType();
	if(nRoleType == _ROLE_SHOPKEEPER_NPC || 
		nRoleType == _ROLE_TASK_NPC ||
		nRoleType == _ROLE_STORAGE_NPC ||
		nRoleType == _ROLE_TRUNCK_NPC ||
		nRoleType == _ROLE_FACE_NPC ||
		nRoleType == _ROLE_FORGE_NPC ||
		nRoleType == _ROLE_EMBED_NPC ||
		nRoleType == _ROLE_STATUARY_NPC ||
		nRoleType == _ROLE_SYNFLAG_NPC ||
		nRoleType == _ROLE_DICE_NPC
		)
	{
		return true;
	}
	return false;
}
//--------------------------------------------------------------

void CRole::SetSpriteEffect(UCHAR ucSprite)
{
	if ( ucSprite == 255 )
	// not sprite, test if the player unequip it
	{
		// The player had a sprite delete the effect
		if ( m_Info.ucSprite != 255 )
		{
			char strName[128] ;
			sprintf( strName, "Sprite_%u", m_Info.ucSprite ) ;
			if ( m_objEffect.TestEffect( strName ) )
			{
				m_objEffect.Delete( strName ) ;
			}
			m_Info.ucSprite = 255 ;
		}
	}
	else
	{
		// Not sprite yet,just add it
		if ( m_Info.ucSprite == 255 )
		{
			m_Info.ucSprite = ucSprite ;
			char strName[128] ;
			sprintf( strName, "Sprite_%u", m_Info.ucSprite ) ;
			m_objEffect.Add( strName ,false,0,this->GetLook()) ;
		}
		else
		{
			// The sprite changes, del the old one and add the new one
			if ( m_Info.ucSprite != ucSprite )
			{
				char strName[128] ;
				sprintf( strName, "Sprite_%u", m_Info.ucSprite ) ;
				if ( m_objEffect.TestEffect( strName ) )
				{
					m_objEffect.Delete( strName ) ;
				}

				m_Info.ucSprite = ucSprite ;
				sprintf( strName, "Sprite_%u", m_Info.ucSprite ) ;
				m_objEffect.Add( strName,false,0,this->GetLook() ) ;
			}
		}
	}
}

//--------------------------------------------------------------
BOOL CRole::LoadKongfu(const char* pszFileName)	
{
	if(!pszFileName)
		return false;
	FILE* fp = fopen(pszFileName, "rb");
	if(!fp)
		return false;
	m_setKongfu.clear();
	char szHead[16]="NDKONGFU";
	fread(szHead, sizeof(char), 16, fp);
	DWORD dwVersion = 1000;
	fread(&dwVersion, sizeof(DWORD), 1, fp);
	DWORD dwFormat = 0;
	fread(&dwFormat, sizeof(DWORD), 1, fp);
	DWORD dwActionAmount = 0;
	fread(&dwActionAmount, sizeof(DWORD), 1, fp);
	for(int i = 0; i  < dwActionAmount; i ++)	
	{
		KongfuAction actionKongfu;
		fread(&actionKongfu.cDir, sizeof(char), 1, fp);
		fread(&actionKongfu.dwFrameInterval, sizeof(DWORD), 1, fp);
		
		int nSize = 0;
		fread(&nSize, sizeof(int), 1, fp);
		fread(&actionKongfu.szEffect, sizeof(char), nSize, fp);
		fread(&actionKongfu.nAction, sizeof(int), 1, fp);
		int nStepAmount = 0;
		fread(&nStepAmount, sizeof(int), 1, fp);
		for(int j = 0; j < nStepAmount; j ++)
		{
			char cStep;
			fread(&cStep, sizeof(char), 1, fp);
			actionKongfu.setStep.push_back(cStep);
		}
		m_setKongfu.push_back(actionKongfu);
	}
	fclose(fp);
	return true;
}
//--------------------------------------------------------------
void CRole::Disappear(DWORD dwLast)
{
	m_dwDisappear = ::TimeGet();
	m_dwDisappearLast = dwLast;
}
//--------------------------------------------------------------
void CRole::AddBeAttackCommandInfo(OBJID idSender, int nSenderCommandIndex, int nAction, int nFrameIndex, int nLife, DWORD dwColor)
{
	BeAttackCmdInfo* pInfo = new BeAttackCmdInfo;
	if(pInfo)
	{
		pInfo->idPlayer = idSender;
		pInfo->dwSenderCommandIndex = nSenderCommandIndex;
		pInfo->nAction = nAction;
		pInfo->nFrameIndex = nFrameIndex;
		pInfo->nLife = nLife;
		pInfo->dwColor = dwColor;
		m_setBeAttackCmdInfo.push_back(pInfo);
	}
}
//--------------------------------------------------------------
void CRole::PerformBeAttackCmd(BeAttackCmdInfo* pInfo)
{
	if(!pInfo)
		return;
	// target show
	CPlayer* pTarget = (CPlayer*)this;
	int nDir = pTarget->GetDir();
	CPlayer* pSender = g_objPlayerSet.GetPlayer(pInfo->idPlayer, true);
	if(pSender)
		nDir = pTarget->GetDir(pSender);
	DWORD dwColor = _COLOR_YELLOW;
	if (pTarget->GetID() == g_objHero.GetID())
	{
		if (pInfo->nLife > 0)
		{
			dwColor = _COLOR_RED;
			g_objHero.AddZoomNum(pInfo->nLife, 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);
		}
		else
		{
			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
	{
		if (pInfo->nLife > 0)
		{
			pTarget->AddZoomNum(pInfo->nLife, dwColor, 300, 30);
			
			if (!pTarget->IsAttacking())
			{
				pTarget->ResetStepDir();
				pTarget->SetActionCmd(_ACTION_BRUISE0, nDir);
			}						
			
			if (pTarget->IsNpc())
			{
				int nLife = (int)pTarget->GetData(CPlayer::_PLAYER_LIFE)-(int)pInfo->nLife;
				pTarget->SetData(CPlayer::_PLAYER_LIFE, __max(0, nLife));
				//pTarget->SetLife(__max(0, nLife));
			}					
		}
		else
		{
			if (!pTarget->IsAttacking())
			{
				pTarget->ResetStepDir();
				if(pTarget->IsPlayer())
					pTarget->SetActionCmd(_ACTION_DODGE0, nDir);
			}						
		}
	}
}
//--------------------------------------------------------------

⌨️ 快捷键说明

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