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

📄 hero.cpp

📁 网络游戏魔域源代码 测试可以完整变异
💻 CPP
📖 第 1 页 / 共 5 页
字号:
	return __max(0, nAttack);
}
//////////////////////////////////////////////////////////////////////
DWORD CHero::GetMinMagicAtk()
{
	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]->GetMinMagicAttack();
		}
	}
	
	return __max(0, nAttack);
}
//////////////////////////////////////////////////////////////////////
DWORD	CHero::GetAdditionAtk()
{
	int nAttack = 0;
	for (int i=0; i<_MAX_EQUIPMENT; i++)
	{
		CItem* pItem = m_pEquipment[i];
		if(pItem && !pItem->TestStatus(_ITEM_STATUS_MAGIC_ADD))
		{
			if ( i + 1 == ITEMPOSITION_SPRITE )
			{
				if ( pItem->GetProfessionRequired() == _SPRITE_ADDITION_PATK )
				{
					nAttack += pItem->GetAmountLimit() ;
				}
			}
			else if(i+1 == ITEMPOSITION_WEAPONR || i+1 == ITEMPOSITION_RINGR ||  i+1 == ITEMPOSITION_SHOES)
				nAttack += m_pEquipment[i]->GetAddition();
		}
	}
	return nAttack;
}
//////////////////////////////////////////////////////////////////////
DWORD	CHero::GetAdditionDef()
{
	int nDef = 0;
	for (int i=0; i<_MAX_EQUIPMENT; i++)
	{
		CItem* pItem = m_pEquipment[i];
		if(pItem && !pItem->TestStatus(_ITEM_STATUS_MAGIC_ADD))
		{
			if ( i + 1 == ITEMPOSITION_SPRITE )
			{
				if ( pItem->GetProfessionRequired() == _SPRITE_ADDITION_PDEF )
				{
					nDef += pItem->GetAmountLimit() ;
				}
			}
			else if(i+1 == ITEMPOSITION_ARMOR || i+1 == ITEMPOSITION_HELMET 
					||  i+1 == ITEMPOSITION_NECKLACE || i+1 == ITEMPOSITION_WEAPONL)
				nDef += m_pEquipment[i]->GetAddition();
		}
	}
	return nDef;
}
//////////////////////////////////////////////////////////////////////
DWORD	CHero::GetAdditionMAtk()
{
	int nAttack = 0;
	for (int i=0; i<_MAX_EQUIPMENT; i++)
	{
		CItem* pItem = m_pEquipment[i];
		if(pItem && pItem->TestStatus(_ITEM_STATUS_MAGIC_ADD))
		{
			if ( i + 1 == ITEMPOSITION_SPRITE )
			{
				if ( pItem->GetProfessionRequired() == _SPRITE_ADDITION_MATK )
				{
					nAttack += pItem->GetAmountLimit() ;
				}
			}
			else if(i+1 == ITEMPOSITION_WEAPONR || i+1 == ITEMPOSITION_RINGR ||  i+1 == ITEMPOSITION_SHOES)
				nAttack += m_pEquipment[i]->GetAddition();
		}
	}
	return nAttack;
}
//////////////////////////////////////////////////////////////////////
DWORD	CHero::GetAdditionMDef()
{
	int nDef = 0;
	for (int i=0; i<_MAX_EQUIPMENT; i++)
	{
		CItem* pItem = m_pEquipment[i];
		if(pItem && pItem->TestStatus(_ITEM_STATUS_MAGIC_ADD))
		{
			if ( i + 1 == ITEMPOSITION_SPRITE )
			{
				if ( pItem->GetProfessionRequired() == _SPRITE_ADDITION_MDEF )
				{
					nDef += pItem->GetAmountLimit() ;
				}
			}
			else if(i+1 == ITEMPOSITION_ARMOR || i+1 == ITEMPOSITION_HELMET 
						||  i+1 == ITEMPOSITION_NECKLACE || i+1 == ITEMPOSITION_WEAPONL)
				nDef += m_pEquipment[i]->GetAddition();
		}
	}
	return nDef;
}
//////////////////////////////////////////////////////////////////////

DWORD CHero::GetMaxAtk()
{
	float fAtk = 0.0f;
	switch(this->GetProfessionSort())
	{
	case PROFSORT_SOLDIER:
		fAtk += this->GetForce()*1.0f;
		break;
		
	case PROFSORT_ARCHER:
		fAtk += this->GetSpeed()*0.5f;
		break;
		
	case PROFSORT_MAGICIAN:
		fAtk += this->GetForce()*0.5f;
		break;
	}
	int nAttack = fAtk + 0.5f;
	
	for (int i=0; i<_MAX_EQUIPMENT; i++)
	{
		if(m_pEquipment[i])
		{
			nAttack += m_pEquipment[i]->GetMaxAttack();
		}
	}

	return __max(0, nAttack);
}

//////////////////////////////////////////////////////////////////////
DWORD CHero::GetMinAtk()
{
	float fAtk = 0.0f;
	switch(this->GetProfessionSort())
	{
	case PROFSORT_SOLDIER:
		fAtk += this->GetForce()*1.0f;
		break;
		
	case PROFSORT_ARCHER:
		fAtk += this->GetSpeed()*0.5f;
		break;
		
	case PROFSORT_MAGICIAN:
		fAtk += this->GetForce()*0.5f;
		break;
	}
	int nAttack = fAtk + 0.5f;
	
	for (int i=0; i<_MAX_EQUIPMENT; i++)
	{
		if(m_pEquipment[i])
		{
			nAttack += m_pEquipment[i]->GetMinAttack();
		}
	}
	
	return __max(0, nAttack);
}

//////////////////////////////////////////////////////////////////////
DWORD CHero::GetDex()
{
	int nDex = this->GetSpeed();

	for (int i=0; i<_MAX_EQUIPMENT; i++)
	{
		if(m_pEquipment[i])
			nDex += m_pEquipment[i]->GetDodge();
	}

	return __max(0, nDex);
}

//////////////////////////////////////////////////////////////////////
DWORD CHero::GetMaxLife()
{
	/*
	int nStep = 0;
	switch(this->GetProfessionSort())
	{
	case PROFSORT_SOLDIER:
		nStep = 5;
		break;
		
	case PROFSORT_ARCHER:
		nStep = 7;
		break;
		
	case PROFSORT_MAGICIAN:
		nStep = 6;
		break;
	}
	int nLife = (this->GetLev() - 1) * 3 + this->GetHealth() * nStep + 30;*/
	int nLife = CPlayer::GetMaxLife();
	for (int i=0; i<_MAX_EQUIPMENT; i++)
	{
		if(m_pEquipment[i])
			nLife += m_pEquipment[i]->GetLife();
	}

	return __max(0, nLife);
}

//////////////////////////////////////////////////////////////////////
DWORD CHero::GetMaxXP()
{
	// todo ...
	return 100;
}
//////////////////////////////////////////////////////////////////////
DWORD CHero::GetMaxMana()
{
/*	int nStep = 0;
	int nLevStep = 0;
	switch(this->GetProfessionSort())
	{
	case PROFSORT_SOLDIER:
		nStep = 5;
		nLevStep = 3;
		break;
		
	case PROFSORT_ARCHER:
		nStep = 5;
		nLevStep = 3;
		break;
		
	case PROFSORT_MAGICIAN:
		nStep = 5;
		nLevStep = 3;
		break;
	}
	int nMaxMana = this->GetSoul() * nStep + (this->GetLev() - 1) * nLevStep;
	*/
	int nMaxMana = this->GetSoul() * 20;
	for (int i=0; i<_MAX_EQUIPMENT; i++)
	{
		if(m_pEquipment[i])
			nMaxMana += m_pEquipment[i]->GetMana();
	}
	return __max(0, nMaxMana);
}

//////////////////////////////////////////////////////////////////////
BOOL CHero::CanJump(CMyPos posTarGet)
{
	// Can I Jump Over It?
	int nCanJumpHeight =  m_nHeightCanJump;
//	if(this->TestStatus(USERSTATUS_FLY))
//		nCanJumpHeight = 100;
	CMyPos posStart, posEnd;
	posEnd = posTarGet;


	DEQUE_CELL setCell;
	this->GetPos(posStart);

	CMyPos posHighest;
	g_objGameMap.Sampling(setCell, posHighest, posStart, posEnd, 32);

	CellInfo* pTargetCell = g_objGameMap.GetCell(posHighest.x, posHighest.y);
	if(!pTargetCell)
		return false;

	CellInfo* pCellInfo = g_objGameMap.GetCell(posStart.x, posStart.y);
	if(!pCellInfo)
		return false;

	if(g_objGameMap.GetGroundAltitude(pTargetCell) - g_objGameMap.GetGroundAltitude(pCellInfo) > nCanJumpHeight)
		return false;

	return true;
}

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

	CMyPos posHero;
	this->GetPos(posHero);

	CMsgInteract msg;
	MYASSERT (msg.Create(INTERACT_JOINSYN, this->GetID(), pTarget->GetID(), posHero.x, posHero.y));

	msg.Send();
}

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

	CMyPos posHero;
	this->GetPos(posHero);

	CMsgInteract msg;
	MYASSERT (msg.Create(INTERACT_ACCEPTSYNMEMBER, this->GetID(), pTarget->GetID(), posHero.x, posHero.y));

	msg.Send();
}

//////////////////////////////////////////////////////////////////////
void CHero::TitleSynMember	(CPlayer* pTarget, const char* pszTitle)
{
	if (!pTarget || !pszTitle)
		return;

	CMsgName msg;
	MYASSERT (msg.Create(NAMEACT_CHANGE_SYNTITLE, pszTitle, pTarget->GetID()));
	msg.Send();
}

//////////////////////////////////////////////////////////////////////
void CHero::KickoutSynMember(CPlayer* pTarget)
{
	if (!pTarget)
		return;
	CMsgSyndicate msg;
	if(msg.Create(KICKOUT_MEMBER, pTarget->GetID()))
		msg.Send();
}

//////////////////////////////////////////////////////////////////////
void CHero::QuitSyn(void)
{
	CMyPos posHero;
	this->GetPos(posHero);

	CMsgAction msg;
	MYASSERT (msg.Create(this->GetID(), posHero.x, posHero.y, this->GetDir(), actionQuitSyn));
	msg.Send();
}

//////////////////////////////////////////////////////////////////////
void CHero::ReBorn()
{
	if (this->IsMoving())
	{
		const OBJID idCanNotReBorn = 100034;
		g_objGameMsg.AddMsg(g_objGameDataSet.GetStr(idCanNotReBorn));
		return;
	}

	if (!this->TestStatus(USERSTATUS_GHOST))
		return;

	CMsgAction msg;
	if (msg.Create(this->GetID(), 0, 0, 0, actionReborn))
		msg.Send();
/*
	CMyPos posCell;
	g_objHero.GetPos(posCell);
	if(msg.Create(g_objHero.GetID(), 0, 0, g_objHero.GetDir(), actionSynchro, posCell.x, posCell.y))
		msg.Send();*/
}

//////////////////////////////////////////////////////////////////////
BOOL CHero::ProcessChgMap(void)
{
	if (this->IsDead() || this->IsGhost())
		return false;

	if (_CMDSTATUS_ACCOMPLISH != this->GetCommandStatus())
		return false;
	int nActionType = this->GetActionType();
	if(_ACTION_STANDBY != nActionType && 
		_ACTION_REST1 != nActionType &&
		_ACTION_REST2 != nActionType &&
		_ACTION_REST3 != nActionType &&
		_ACTION_STANDBY_I != nActionType &&
		_ACTION_FLY_STANDBY != nActionType &&
		_ACTION_FLY_ALERT != nActionType)
		return false;
	
	CMyPos posHero;
	this->GetPos(posHero);

	// 看九格
	int nX[9]={0,1,-1,1,0,1,-1,-1,0};
	int nY[9]={0,1,-1,0,1,-1,1,0,-1};

	for(int i = 0; i < 9; i ++)
	{
		CMyPos posTest;
		posTest.x = posHero.x + nX[i];
		posTest.y = posHero.y + nY[i];

		if (g_objGameMap.GetExitIndex(posTest) >= 0)
		{
			CMsgAction msg;
			IF_SUC (msg.Create (this->GetID(), posHero.x, posHero.y, this->GetDir(), actionChgMap, posTest.x, posTest.y))
			{
				msg.Send();

				g_uStatus = _STATUS_WAITING;
				return true;
			}
		}
	}

	return false;
}

//////////////////////////////////////////////////////////////////////
void CHero::ProcessReborn(void)
{
	// reborn...
	if (this->IsGhost() && m_timeGhost != 0 && ::TimeGet()-m_timeGhost >= 20*1000)
	{
		m_timeGhost = 0;
	}

	// to ghost...
	if (this->IsDead() && m_timeDie != 0 && ::TimeGet()-m_timeDie >= 3000)
	{
		m_timeDie = 0;

		CMsgAction msg;
		if (msg.Create(this->GetID(), 0, 0, 0, actionGhost))
			msg.Send();
	}
}


//////////////////////////////////////////////////////////////////////
void CHero::Process(void* pInfo)
{
	if(::TimeGet()	- m_dwTimeWhoAttackMe > 30* 1000)
		m_idWhoAttackMe = ID_NONE;
	CPlayer* pPlayer = g_objPlayerSet.GetPlayer(m_idMyTarget);
	if(!pPlayer || pPlayer->IsDead())
		this->SetIDMyTarget(ID_NONE);

	this->ProcessMusic();
	if(this->GetPhysicalForce() == 0)
		m_Info.bAdjustRun = true;
	else
		m_Info.bAdjustRun = false;

	m_objCheck.Process();
	CPlayer::Process(pInfo);

	m_objTeam.Process();
	m_objDummy.ProcessDummy();
	m_objPlayerDummy.ProcessDummy();
	this->ProcessMagicBusy();
	this->ProcessReborn();
	this->ProcessXp();
	this->ProcessChgMap();
	this->ProcessFriend();
	this->ProcessEnemy();
	this->ProcessMousePlayer();
	this->ProcessMagic();
	this->ProcessAbortTransformDialog();
	this->ProcessLifeForeCast();
	m_objDiceManager.Process();
	
	//int nLife = this->GetLife();
	//int nCurLife = this->GetCurLife();
	int nLife = this->GetData(CPlayer::_PLAYER_LIFE);
	int nCurLife = this->GetData(CPlayer::_PLAYER_CURRENTLIFE);
	int nMaxLife = this->GetMaxLife();
	if(nCurLife < nLife)
	{
		if(nMaxLife >= 80)
			nCurLife += nMaxLife/80;
		else
			nCurLife ++;
	}
	if(nCurLife > nLife)
		nCurLife = nLife;
	this->SetData(CPlayer::_PLAYER_CURRENTLIFE, nCurLife);

	// a puzzle ... 
	this->SetCurLife(::RandGet(INT_MAX));
/*
	//-----------------------------------------------------------------
	{
		DWORD dwKey[4] = {::RandGet(INT_MAX), ::RandGet(INT_MAX), ::RandGet(INT_MAX), ::RandGet(INT_MAX)};
		this->m_infoPlayer.dataCurLife.set_key(dwKey, 4);
		this->SetCurLife(nCurLife);
	}
	//-----------------------------------------------------------------
	{
		DWORD dwKey[4] = {::RandGet(INT_MAX), ::RandGet(INT_MAX), ::RandGet(INT_MAX), ::RandGet(INT_MAX)};
		this->m_infoPlayer.dataLife.set_key(dwKey, 4);
		this->SetLife(nLife);
	}
*/
	int nMana = this->GetData(CPlayer::_PLAYER_MANA);
	int nCurMana = this->GetCurMana();
	int nMaxMana = this->GetMaxMana();
	if(nCurMana < nMana)
	{
		if(nMaxMana >= 80)
			nCurMana += nMaxMana/80;
		else
			nCurMana ++;
	}
	if(nCurMana > nMana)
		nCurMana = nMana;
	//--------------------

⌨️ 快捷键说明

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