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

📄 user.cpp

📁 网络游戏魔域的服务端与客户端完整源代码 包括详细的说明文档与开发日志
💻 CPP
📖 第 1 页 / 共 5 页
字号:
		return true;

	int nDislocation = this->GetDistance(nPosX, nPosY);
	if (nDislocation >= nMaxDislocation)
		return false;

	if (nDislocation <= 0)
		return true;


	if (this->IsGM())
		this->SendSysMsg("syn move: (%u, %u)->(%u, %u)",
									this->GetPosX(), this->GetPosY(),
									nPosX, nPosY);

	CMapPtr pMap = this->GetMap();
	IF_NOT(pMap && pMap->IsValidPoint(nPosX, nPosY))
		return false;
	
	// correct pos
	CMsgAction msg;
	if (msg.Create(this->GetID(), nPosX, nPosY, this->GetDir(), actionSynchro, nPosX, nPosY))
		this->BroadcastRoomMsg(&msg, EXCLUDE_SELF);

	// process move
	this->ProcessOnMove(MOVEMODE_SYNCHRO);
	this->JumpPos(nPosX, nPosY);
	return true;
}

//////////////////////////////////////////////////////////////////////
void CUser::ProcessAfterMove()
{
	IThingSet* pSet = GetMap()->QueryBlock(GetPosX(), GetPosY()).QuerySet();
	for(int i = 0; i < pSet->GetAmount(); i++)
	{
		IMapThing* pTarget = pSet->GetObjByIndex(i);
		CMapTrap* pTrap;
		if(pTarget && pTarget->QueryObj(OBJ_TRAP, IPP_OF(pTrap))
				&& pTrap->IsTrapSort() && pTarget->GetPosX() == GetPosX() && pTarget->GetPosY() == GetPosY())
		{
			pTrap->TrapAttack(QueryRole());
		}
	}
}

//////////////////////////////////////////////////////////////////////
void CUser::ProcessOnMove(int nMoveMode)
{
	if(QueryBooth())
		QueryBooth()->LeaveMap();

	if (nMoveMode != MOVEMODE_TRACK)
		SetPose(_ACTION_STANDBY);

	// stop fight
	if(nMoveMode != MOVEMODE_TRACK && nMoveMode != MOVEMODE_JUMPMAGICATTCK 
		&& nMoveMode != MOVEMODE_COLLIDE && nMoveMode != MOVEMODE_SYNCHRO)
	{
		ClrAttackTarget();
	}

	if(nMoveMode == MOVEMODE_RUN || nMoveMode == MOVEMODE_JUMP || nMoveMode == MOVEMODE_WALK
		|| (nMoveMode >= MOVEMODE_RUN_DIR0 && nMoveMode <= MOVEMODE_RUN_DIR7))		// && QueryMagic()->IsKeepBow()
	{
		if (QueryMagic())
			QueryMagic()->AbortMagic(true);

		// run
		if(nMoveMode == MOVEMODE_RUN || (nMoveMode >= MOVEMODE_RUN_DIR0 && nMoveMode <= MOVEMODE_RUN_DIR7))
		{
	#ifdef	PALED_DEBUG
			if(!m_bRun)
				SendSysMsg("RUN");
	#endif
			m_bRun	= true;
		}
		else
			ResetEnergyInc();
	}

//	if(nMoveMode != MOVEMODE_SHIFT && nMoveMode != MOVEMODE_SYNCHRO)
//		QueryStatusSet()->DelObj(STATUS_WEAPONDAMAGE);

//	if(nMoveMode != MOVEMODE_SHIFT && nMoveMode != MOVEMODE_SYNCHRO)
//		QueryStatusSet()->DelObj(STATUS_KEEPBOW);

	// stop mine
	this->StopMine();

	// foot print
	m_tFootPrint = ::TimeGet();
	m_posFootPrint.x = this->GetPosX();
	m_posFootPrint.y = this->GetPosY();

	// unlock
	CRole::DetachStatus(this->QueryRole(), STATUS_PK_PROTECT);
	//m_tLock.Clear();
}


//////////////////////////////////////////////////////////////////////
void CUser::ProcessOnAttack()
{
	CRole::DetachStatus(this->QueryRole(), STATUS_PK_PROTECT);
	//m_tLock.Clear();
}
//////////////////////////////////////////////////////////////////////
void CUser::GetFootPrint	(int& nPosX, int& nPosY)
{
	if (::TimeGet()-m_tFootPrint >= TIME_FOOTPRINT)
	{	// time out
		nPosX = this->GetPosX();
		nPosY = this->GetPosY();
	}
	else
	{
		nPosX = m_posFootPrint.x;
		nPosY = m_posFootPrint.y;
	}
}

//////////////////////////////////////////////////////////////////////
void CUser::SetLife(int nLife, BOOL bUpdate)
{
	int nOldLife = this->GetLife();
	if(QueryTransformation())
	{
		if(nLife > 0)
		{
			QueryTransformation()->SetLife(nLife);

			// recalc user life
			nLife = ::CutTrail(1, MulDiv(nLife, GetMaxLife(), QueryTransformation()->GetMaxLife()));
		}
		else
		{
			SAFE_RELEASE(m_pTransformation);
			SynchroTransform();
		}
	}

	m_data.SetLife(nLife, bUpdate);

	// 调整移动速度
	IStatus* pStatus = this->QueryStatus(STATUS_SLOWDOWN2);
	if (pStatus)
	{
		if ((nOldLife*2 < this->GetMaxLife() && this->GetLife()*2 >= this->GetMaxLife())
			|| (nOldLife*2 >= this->GetMaxLife() && this->GetLife()*2 < this->GetMaxLife()))
		{
			CMsgUserAttrib msg;
			if (msg.Create(this->GetID(), _USERATTRIB_SPEED, AdjustSpeed(this->GetSpeed())))
				this->BroadcastRoomMsg(&msg, INCLUDE_SELF);
		}
	}
}

//////////////////////////////////////////////////////////////////////
// get attrib
//////////////////////////////////////////////////////////////////////
DWORD CUser::GetLife()
{
	if(QueryTransformation())
		return QueryTransformation()->GetLife();

	int nMaxLife = this->GetMaxLife();
	if (m_data.GetLife() > nMaxLife)
		m_data.SetLife(nMaxLife);

	return m_data.GetLife();
}

//////////////////////////////////////////////////////////////////////
DWORD CUser::GetMaxLife()
{
	if(QueryTransformation())
		return QueryTransformation()->GetMaxLife();

	//int nMaxLife = (this->GetLev()-1) * 3 + 30;	// 没有等级、职业加成
	/*switch(this->GetProfessionSort())
	{
	case PROFSORT_SOLDIER:
		nMaxLife += m_data.GetHealth() * 5;
		break;
	case PROFSORT_ARCHER:
		nMaxLife += m_data.GetHealth() * 7;
		break;
	case PROFSORT_MAGICIAN:
		nMaxLife += m_data.GetHealth() * 6;
		break;
	}*/
	int nMaxLife = m_data.GetHealth()*10;	// 基础生命 = 体质 * 10;	// 体质就是耐力

	for(int i = ITEMPOSITION_EQUIPBEGIN; i < ITEMPOSITION_EQUIPEND; i++)
	{
		CItemPtr* ppEquip = GetEquipItemPtr(i);
		CHECKF(ppEquip);
		CItemPtr& pEquip = *ppEquip;
		if(pEquip)
			nMaxLife += pEquip->GetInt(ITEMDATA_LIFE);
	}

	nMaxLife	= nMaxLife * m_data.GetMaxLifePercent() / 1000;		// 因为有个受伤度的问题,这里需要调整最大血量

	IStatus* pStatus = QueryStatus(STATUS_MAXLIFE);
	if (pStatus)
	{
		nMaxLife	= ::CutTrail(0, AdjustData(nMaxLife, pStatus->GetPower(), 100));
	}

	// 防御型幻兽合体增加最大生命
	if (m_idLinkEudemonType == ITEMTYPE_EUDEMON_DEF)
		nMaxLife += m_nLinkValue;

	return __max(0, nMaxLife);
}

//////////////////////////////////////////////////////////////////////
DWORD CUser::GetMaxMana()
{
	/*int nMaxMana = 0;
	switch(this->GetProfessionSort())
	{
	case PROFSORT_SOLDIER:
		nMaxMana += GetSoulSum()*5 + (GetLev()-1)*3;
		break;

	case PROFSORT_ARCHER:
		nMaxMana += GetSoulSum()*5 + (GetLev()-1)*3;
		break;

	case PROFSORT_MAGICIAN:
		nMaxMana += GetSoulSum()*5 + (GetLev()-1)*3;
		break;

	}*/
	int nMaxMana = GetSoulSum()*20;

	for(int i = ITEMPOSITION_EQUIPBEGIN; i < ITEMPOSITION_EQUIPEND; i++)
	{
		CItemPtr* ppEquip = GetEquipItemPtr(i);
		CHECKF(ppEquip);
		CItemPtr& pEquip = *ppEquip;
		if(pEquip)
			nMaxMana += pEquip->GetInt(ITEMDATA_MANA);
	}	

	return __max(0, nMaxMana);
}

//////////////////////////////////////////////////////////////////////
DWORD CUser::GetAttack()
{
	if(QueryTransformation())
		return QueryTransformation()->GetAttack();

	/*float fAtk = 0.0f;
	switch(this->GetProfessionSort())
	{
	case PROFSORT_SOLDIER:
		fAtk += m_data.GetForce()*1.0f;
		break;

	case PROFSORT_ARCHER:
		fAtk += m_data.GetSpeed()*0.5f;
		break;

	case PROFSORT_MAGICIAN:
		fAtk += m_data.GetForce()*0.5f;
		break;
	}

	return (fAtk+0.5f);*/
	return m_data.GetForce();
}

//////////////////////////////////////////////////////////////////////
DWORD CUser::GetMagicAttack()
{
	if(QueryTransformation())
		return QueryTransformation()->GetAttack();

	/*float fAtk = 0.0f;
	switch(this->GetProfessionSort())
	{
	case PROFSORT_MAGICIAN:
		fAtk += GetSoulSum()*0.5f;
		break;
	}

	return (fAtk+0.5f);*/
	return GetSoulSum();
}

//////////////////////////////////////////////////////////////////////
DWORD CUser::GetAtkHitRate()
{
	if (QueryTransformation())
		return QueryTransformation()->GetHitRate();

	int nAtkHitRate = 0;

	for(int i = ITEMPOSITION_EQUIPBEGIN; i < ITEMPOSITION_EQUIPEND; i++)
	{
		CItemPtr* ppEquip = GetEquipItemPtr(i);
		CHECKF(ppEquip);
		CItemPtr& pEquip = *ppEquip;
		if (pEquip)
		{
			nAtkHitRate += pEquip->GetHitRate();
		}
	}

	return nAtkHitRate;
}

//////////////////////////////////////////////////////////////////////
DWORD CUser::GetMinAtk()
{
	if(QueryTransformation())
		return QueryTransformation()->GetMinAtk();

	int nMinAtk	= this->GetAttack();

	for(int i = ITEMPOSITION_EQUIPBEGIN; i < ITEMPOSITION_EQUIPEND; i++)
	{
		CItemPtr* ppEquip = GetEquipItemPtr(i);
		CHECKF(ppEquip);
		CItemPtr& pEquip = *ppEquip;
		if (pEquip)
		{
			int nEquipAtk = pEquip->GetMinAtk();


			if (ITEMPOSITION_WEAPONL == i && !pEquip->IsShield())
				nEquipAtk = nEquipAtk/2;
			else if (ITEMPOSITION_SPRITE == i)	// 精灵存储的附加属性是*100以后的值
				nEquipAtk = nEquipAtk/100;

			nMinAtk += nEquipAtk;
		}
	}

	return __max(0, nMinAtk);
}

//////////////////////////////////////////////////////////////////////
DWORD CUser::GetMaxAtk()
{
	if(QueryTransformation())
		return QueryTransformation()->GetMaxAtk();

	int nMaxAtk	= this->GetAttack();

	for(int i = ITEMPOSITION_EQUIPBEGIN; i < ITEMPOSITION_EQUIPEND; i++)
	{
		CItemPtr* ppEquip = GetEquipItemPtr(i);
		CHECKF(ppEquip);
		CItemPtr& pEquip = *ppEquip;
		if(pEquip)
		{
			int nEquipAtk = pEquip->GetMaxAtk();


			if (ITEMPOSITION_WEAPONL == i && !pEquip->IsShield())
				nEquipAtk = nEquipAtk/2;
			else if (ITEMPOSITION_SPRITE == i)	// 精灵存储的附加属性是*100以后的值
				nEquipAtk = nEquipAtk/100;

			nMaxAtk += nEquipAtk;
		}
	}

	return __max(0, nMaxAtk);
}

//////////////////////////////////////////////////////////////////////
DWORD CUser::GetMgcMinAtk()
{
	if(QueryTransformation())
		return QueryTransformation()->GetMgcMinAtk();

	int nMinAtk	= this->GetMagicAttack();

	for(int i = ITEMPOSITION_EQUIPBEGIN; i < ITEMPOSITION_EQUIPEND; i++)
	{
		CItemPtr* ppEquip = GetEquipItemPtr(i);
		CHECKF(ppEquip);
		CItemPtr& pEquip = *ppEquip;
		if (pEquip)
		{
			int nEquipAtk = pEquip->GetMgcMinAtk();


			if (ITEMPOSITION_WEAPONL == i && !pEquip->IsShield())
				nEquipAtk = nEquipAtk/2;
			else if (ITEMPOSITION_SPRITE == i)	// 精灵存储的附加属性是*100以后的值
				nEquipAtk = nEquipAtk/100;

			nMinAtk += nEquipAtk;
		}
	}

	return __max(0, nMinAtk);
}

//////////////////////////////////////////////////////////////////////
DWORD CUser::GetMgcMaxAtk()
{
	if(QueryTransformation())
		return QueryTransformation()->GetMaxAtk();

	int nMaxAtk	= this->GetMagicAttack();

	for(int i = ITEMPOSITION_EQUIPBEGIN; i < ITEMPOSITION_EQUIPEND; i++)
	{
		CItemPtr* ppEquip = GetEquipItemPtr(i);
		CHECKF(ppEquip);
		CItemPtr& pEquip = *ppEquip;
		if(pEquip)
		{
			int nEquipAtk = pEquip->GetMgcMaxAtk();


			if (ITEMPOSITION_WEAPONL == i && !pEquip->IsShield())
				nEquipAtk = nEquipAtk/2;
			else if (ITEMPOSITION_SPRITE == i)	// 精灵存储的附加属性是*100以后的值
				nEquipAtk = nEquipAtk/100;

			nMaxAtk += nEquipAtk;
		}
	}

	return __max(0, nMaxAtk);
}

//////////////////////////////////////////////////////////////////////
DWORD CUser::GetDefence()
{
	if(QueryTransformation())
		return QueryTransformation()->GetDefence();

	/*float fDef = 0.0f;
	switch(this->GetProfessionSort())
	{
	case PROFSORT_SOLDIER:
		fDef += m_data.GetHealth()*0.5f;
		break;

	case PROFSORT_ARCHER:
		fDef += m_data.GetHealth()*0.5f;
		break;

	case PROFSORT_WIZARD:
		fDef += m_data.GetHealth()*1.5f;
		break;

	case PROFSORT_MAGICIAN:
		fDef += m_data.GetHealth()*0.5f;
		break;
	}

	return (fDef+0.5f);*/
	return 0;
}

//////////////////////////////////////////////////////////////////////
DWORD CUser::GetDef()
{
	if(QueryTransformation())
		return QueryTransformation()->GetDef();

	int nDef = this->GetDefence();

	for(int i = ITEMPOSITION_EQUIPBEGIN; i < ITEMPOSITION_EQUIPEND; i++)
	{
		CItemPtr* ppEquip = GetEquipItemPtr(i);
		CHECKF(ppEquip);
		CItemPtr& pEquip = *ppEquip;
		if(pEquip)
		{
			int nEquipDef = pEquip->GetDef();

			if (ITEMPOSITION_SPRITE == i)
				nEquipDef = nEquipDef / 100;	// 精灵存储的附加属性是*100以后的值

			nDef += nEquipDef;
		}
	}
	
	return __max(0, nDef);
}

//////////////////////////////////////////////////////////////////////
DWORD CUser::GetSoulSum()
{
	int nData = this->GetSoul();

/*
	for(int i = ITEMPOSITION_EQUIPBEGIN; i < ITEMPOSITION_EQUIPEND; i++)
	{
		CItem* pEquip = this->GetEquipItemByPos(i);
		if(pEquip)
			nData += pEquip->GetInt(ITEMDATA_ADD_SOUL);
	}
*/

	return __max(0, nData);
}

⌨️ 快捷键说明

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