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

📄 charinfo.cpp

📁 国内著名网络游戏dragon的服务端完整源码 内附完整数据库结构
💻 CPP
📖 第 1 页 / 共 3 页
字号:
	return NPC_Gen_Ref[npc_index].nDrain;
}	//> CSD-021024

int CCharInfo::GetNpcFreezeAvoid() const
{	//< CSD-021024
	return NPC_Gen_Ref[npc_index].nFreeze;
}	//> CSD-021024

int CCharInfo::GetMovePower(BYTE nType) const
{	// 捞悼仿 备窍扁
	const int nMax = __min(MoveP, 310);
	if (IsNpc())  return nMax;
	
	int nBase = 0, nMove = 50;
	// 酒捞袍狼 捞悼仿 啊瘤绊 坷扁
	CItem* pItem = ::ItemUnit(equip[WT_SHOES]);
	
	if (pItem != NULL)
	{ 
		switch (nType)
		{
		case HORSE:
			{
				nBase = __max(8*((nMax - 10)/30), 0);
				nMove += (pItem->GetDefense_power() + nBase)*0.3;
				break;
			}
		case BULL:
			{
				nBase = __max(9*((nMax - 10)/30), 0);
				nMove += (pItem->GetDefense_power() + nBase)*0.3;
				break;
			}
		case PHANTOM:
			{
				nBase = __max(10*((nMax - 10)/30), 0);
				nMove += (pItem->GetDefense_power() + nBase)*0.3;
				break;
			}
		default:
			{
				nMove += pItem->GetDefense_power()*0.3;
				break;
			}
		}
	}
    
	return nMove;
}

int CCharInfo::GetDistance(int nX, int nY) const
{
	const int nDistance = int(sqrt(pow(X - nX, 2) + pow(Y - nY, 2)));
	return nDistance>>5;
}

int CCharInfo::GetRiseFall(int nX, int nY) const
{	// 0 : 角菩,  1 : 绊 -> 历, 2 : 历 -> 绊, 3 : 鞍篮 臭捞
	if (TileMap[MoveSx][MoveSy].empty__4 && !TileMap[nX][nY].empty__4)  return 1;
	if (!TileMap[MoveSx][MoveSy].empty__4 && TileMap[nX][nY].empty__4)  return 2;
	if (TileMap[MoveSx][MoveSy].empty__4 && TileMap[nX][nY].empty__4)  return 3;
	if (!TileMap[MoveSx][MoveSy].empty__4 && !TileMap[nX][nY].empty__4)  return 3;
	return 0;
}

int CCharInfo::GetWeaponKind() const
{
	const int nItem = equip[WT_WEAPON].item_no;
	CItem* pItem = ::ItemUnit(nItem/1000, nItem%1000);	
	return (pItem != NULL) ? pItem->GetItemKind():IK_NONE;
}

int CCharInfo::GetTacticsKind() const
{
	const int nItem = equip[WT_WEAPON].item_no;
	CItem* pItem = ::ItemUnit(nItem/1000, nItem%1000);	
	
	if (pItem == NULL)
	{	// 030116 kyo 坷弗颊俊 乐绰 公扁啊 绝促. 
		return SKILL_UNKNOWN;	// 030117 盖颊老锭绰 tatic捞 坷福瘤 臼绰促. 
	}
	
	const int nTactic = pItem->GetSkill_Ability();
	
	if (nTactic < TACTICS_Crapple || nTactic > TACTICS_Orison)
	{
		return TACTICS_Crapple;
	}
	
	return nTactic;
}

int CCharInfo::GetCombatValue(int nIndex) const 
{
	const int nLevel = Skill[nIndex - 100];
	return Magic_Ref[nIndex].aLevel[nLevel]; 
}

int CCharInfo::GetPureLife() const
{	//< CSD-030806
	const int nLevel = GetLevel();
	int nBase = 0;
	
	switch (Class)
	{	
    case WARRIOR: nBase = NPC_Lev_Ref[nLevel].nWarriorLife; break;
    case THIEF:   nBase = NPC_Lev_Ref[nLevel].nThiefLife;   break;
    case ARCHER:  nBase = NPC_Lev_Ref[nLevel].nArcherLife;  break;
    case WIZARD:  nBase = NPC_Lev_Ref[nLevel].nWizardLife;  break;
    case PRIEST:  nBase = NPC_Lev_Ref[nLevel].nPriestLife;  break;
	}
	
	const int nCon = GetAbility(CON)/5;
	return (nBase + 111 + (nCon - 1)*(15 + nCon))<<1;
}	//> CSD-030806

int CCharInfo::GetExtendAc() const
{
	return CalcNewAc() + 
		   RareEM.GetStaticRareHardest(StaticRare) +
	       RareEM.GetStaticRareHighShield(StaticRare) +
		   RareEM.GetDynamicRareValue(FITEM_HEAVY_ARMOR, DynamicRare);
}

int CCharInfo::GetItemEffectNumber() const
{	//< CSD-031101 : 拱府利 傍拜 己傍 咯何 魄窜
	CItem_Weapon* pWeapon = static_cast<CItem_Weapon*>(::ItemUnit(equip[WT_WEAPON]));
	
	if (pWeapon == NULL)
	{
		return 0;
	}

	if (pWeapon->SkillEffect <= 0)
	{
		return 0;
	}

	const int nRate = pWeapon->kind_of_magic +  rand()%pWeapon->SkillEffect;
	
	if (++m_nItemEffectCount <= nRate)
	{ 
		return 0;
	}

	m_nItemEffectCount = 0;
	return pWeapon->nWeaponSpeed;
}	//> CSD-031101

void CCharInfo::GetStepInfo(char* pData, int nSize)
{	// 窜拌 单捞鸥 备窍扁
	if (nSize < MAX_STEP)  return;
	
	pData[CLS_STEP] = char(m_nClsStep);
	pData[DUAL_CLS] = char(m_nDualCls);
	pData[EXP_STEP] = char(m_nExpStep);
	
	for (int i = 0; i < NO_TAC; ++i)
	{
		pData[i + T01_STEP] = char(m_aTacStep[i]);
	}
	
	pData[CSP_STEP] = char(m_gnCombat.GetPoint());
	pData[MAX_STEP] = '\0';
}

void CCharInfo::SetStepInfo(char* pData, int nSize)
{	//< CSD-030806 : 窜拌 单捞鸥 犁汲沥
	if (nSize < MAX_STEP)  return;
	
	m_nClsStep = __int8(pData[CLS_STEP]);
	m_nDualCls = __int8(pData[DUAL_CLS]);
	m_nExpStep = __int8(pData[EXP_STEP]);

	const int nLevel = GetLevel();

	if (m_nExpStep != NPC_Lev_Ref[nLevel].nStep)
	{
		m_nExpStep = NPC_Lev_Ref[nLevel].nStep;
	}
	
	for (int i = 0; i < NO_TAC; ++i)
	{
		m_aTacStep[i] = __int8(pData[i + T01_STEP]);
	}

	int nCombatPoint = __int8(pData[CSP_STEP]);

	if (nCombatPoint > NPC_Lev_Ref[nLevel].nCspMax)
	{
		nCombatPoint = NPC_Lev_Ref[nLevel].nCspMax;
	}
	
	m_gnCombat.SetPoint(nCombatPoint);
}	//> CSD-030806

int CCharInfo::CorrectCombatAttack(int nCombat, int nResult) const
{	// 傍拜 傈捧胶懦 加己 焊沥
	const int nLevel = GetCombatLevel(nCombat);
	
	switch (nResult)
	{
    case CSR_NORMAL: 
		{
			return Magic_Ref[nCombat].aLevel[nLevel] + Magic_Ref[nCombat].aRandom[nLevel]/2;
		}
    case CSR_PRIOR: 
		{
			return Magic_Ref[nCombat].aLevel[nLevel] + Magic_Ref[nCombat].aRandom[nLevel];
		}
    case CSR_POSTERIOR: 
		{
			return Magic_Ref[nCombat].aLevel[nLevel];
		}
    case CSR_CONFLICT: 
		{
			return Magic_Ref[nCombat].aLevel[nLevel] + Magic_Ref[nCombat].aRandom[nLevel];
		}
    case CSR_EQUAL:
		{
			return Magic_Ref[nCombat].aLevel[nLevel] + Magic_Ref[nCombat].aRandom[nLevel]/2;
		}
	}
	
	return 0;
}

int CCharInfo::CorrectCombatDefense(int nCombat, int nResult) const
{	// 规绢 傈捧胶懦 加己 焊沥
	const int nLevel = GetCombatLevel(nCombat);
	
	switch (nResult)
	{
    case CSR_NORMAL: 
		{
			return Magic_Ref[nCombat].aLevel[nLevel] + Magic_Ref[nCombat].aRandom[nLevel]/2;
		}
    case CSR_PRIOR: 
		{
			return Magic_Ref[nCombat].aLevel[nLevel];
		}
    case CSR_POSTERIOR: 
		{
			return Magic_Ref[nCombat].aLevel[nLevel] + Magic_Ref[nCombat].aRandom[nLevel];
		}
    case CSR_CONFLICT: 
		{
			return Magic_Ref[nCombat].aLevel[nLevel] + Magic_Ref[nCombat].aRandom[nLevel];
		}
    case CSR_EQUAL:
		{
			return Magic_Ref[nCombat].aLevel[nLevel] + Magic_Ref[nCombat].aRandom[nLevel]/2;
		}
	}
	
	return 0;
}

int CCharInfo::CorrectItemEffect() const
{	//< CSD-031007
	CItem_Weapon* pWeapon = static_cast<CItem_Weapon*>(::ItemUnit(equip[WT_WEAPON]));
	
	if (pWeapon == NULL)
	{
		return 0;
	}

	return pWeapon->Incr_damage;
}	//> CSD-031007

bool CCharInfo::LevelUpAbility()
{	//< CSD-030806 : 版氰摹 饭骇诀
	if (!IsPlayer())
	{
		return false;
	}

	if (!IsLevelUp())
	{
		return false;
	}

	if (Exp <= NPC_Lev_Ref[m_nLevel].nMaxExp)
	{
		return false;
	}
	
	++m_nLevel;

	Exp = NPC_Lev_Ref[m_nLevel].nMinExp;
	SetExperienceStep(NPC_Lev_Ref[m_nLevel].nStep);
	Hp = HpMax;
	SendCharInfoBasic(HP, Hp);
	Mana = ManaMax;
	SendCharInfoBasic(MP, Mana);
	m_gnAbility.Increase(10);
	return true;
}	//> CSD-030806

bool CCharInfo::LevelUpTactics(int nKind)
{	//< CSD-030314 : 琶平 版氰摹 饭骇诀
	int nLevel = Skill[TACTICS_Crapple + nKind];
	if (!IsPlayer())                                         return false;
	if (!IsLevelUp(nLevel))                                  return false;
	if (tac_skillEXP[nKind] <= NPC_Lev_Ref[nLevel].nMaxExp)  return false;
	
	++nLevel;
	tac_skillEXP[nKind] = NPC_Lev_Ref[nLevel].nMinExp;
	SetTacticsStep(nKind, NPC_Lev_Ref[nLevel].nStep);
	Skill[TACTICS_Crapple + nKind] = nLevel;
	return true;	
}	//> CSD-030314

bool CCharInfo::LevelUpCombat(int nKind, int nPoint)
{	// 傈捧胶懦 饭骇诀
	if (!m_gnCombat.IsEnough(nPoint))  return false;
	
	int nLevel = GetCombatLevel(nKind);
	
	if (nLevel < MAX_COMBAT_LEVEL)
	{
		nLevel += nPoint;
		SetCombatLevel(nKind, nLevel);
		m_gnCombat.Decrease(nPoint);
		return true;
	}
	
	return false;
}

bool CCharInfo::ChangeUpAddExp(int nExp)
{	//< CSD-030806
	if (IsNpc())
	{
		return false;
	}

	const int nLevel = GetLevel();

	if (nLevel > MAX_EXP_LEVEL)
	{
		return false;
	}

	float fPlusRate = 1.0;

	switch (Class)
	{
	case WARRIOR: fPlusRate = NPC_Lev_Ref[nLevel].nWarriorExpRate/100.0; break;
	case THIEF:   fPlusRate = NPC_Lev_Ref[nLevel].nThiefExpRate/100.0;   break;
	case ARCHER:  fPlusRate = NPC_Lev_Ref[nLevel].nArcherExpRate/100.0;  break;
	case WIZARD:  fPlusRate = NPC_Lev_Ref[nLevel].nWizardExpRate/100.0;  break;
	case PRIEST:  fPlusRate = NPC_Lev_Ref[nLevel].nPriestExpRate/100.0;  break;
	}

	IncExperience(nExp*fPlusRate);
	return true;
}	//> CSD-030806

bool CCharInfo::ChangeUpAddExpBonus(int nExp)
{	//< CSD-030806
	if (IsNpc())
	{
		return false;
	}

	if (GetLevel() > MAX_EXP_LEVEL)
	{
		return false;
	}
	
	IncExperience(nExp);
	return true;
}	//> CSD-030806


bool CCharInfo::ChangeUpTacExp(int nType, int nExp)
{	//< CSD-TW-030624
	if (nExp <= 0)                                   return false;
	if (nType < 0 && nType > 13)                     return false;
	if (!IsPlayer())                                 return false;
	if (!IsLevelUp(Skill[TACTICS_Crapple + nType]))  return false;
	
	switch (nType)
	{
	case 0: // 老馆 Tactics
		{	
			const int nKind = GetTacticsKind();
			
			if (SKILL_UNKNOWN == nKind) break; // 030116 kyo 盖颊老订 怕平捞 棵福瘤 救绰促. 
			AddPhysicalTacExp1(nKind - TACTICS_Crapple, nExp);
			
			if (IsShield())
			{
				const int nParrying = TACTICS_Parrying - TACTICS_Crapple;
				AddPhysicalTacExp1(nParrying, nExp);
				// 版氰摹 函拳甫 困茄 Packet 傈价
				t_packet packet;
				packet.h.header.type = CMD_TACTICS_PARRYING_EXP;
				packet.h.header.size = sizeof(t_tactics_parrying_exp);
				packet.u.tactics_parrying_exp.exp = tac_skillEXP[nParrying];
				packet.u.tactics_parrying_exp.step = GetTacticsStep(nParrying);
				::QueuePacket(connections, GetServerID(), &packet, 1);
			}
			
			break;
		}
	case 1:	// 琶平荐访俊辑 Tactics
		{
			const int nKind = GetTacticsKind();
			if( SKILL_UNKNOWN == nKind ) break; // 030116 kyo 盖颊老订 怕平捞 棵福瘤 救绰促. 				
			AddPhysicalTacExp2(nKind - TACTICS_Crapple, nExp);
			
			if (IsShield())
			{
				const int nParrying = TACTICS_Parrying - TACTICS_Crapple;
				AddPhysicalTacExp2(nParrying , nExp);
				// 版氰摹 函拳甫 困茄 Packet 傈价
				t_packet packet;
				packet.h.header.type = CMD_TACTICS_PARRYING_EXP;
				packet.h.header.size = sizeof(t_tactics_parrying_exp);
				packet.u.tactics_parrying_exp.exp = tac_skillEXP[nParrying];
				packet.u.tactics_parrying_exp.step = GetTacticsStep(nParrying);
				::QueuePacket(connections, GetServerID(), &packet, 1);
			}
			
			break;
		}
    case 2: // 老馆 Tactics
		{
			const int nKind = (Spell == 0) ? TACTICS_Magery - TACTICS_Crapple:
			TACTICS_Orison - TACTICS_Crapple;
			AddMagicTacExp1(nKind, nExp);
			break;
		}
    case 3:	// 琶平荐访俊辑 Tactics
		{
			const int nKind = (Spell == 0) ? TACTICS_Magery - TACTICS_Crapple:
			TACTICS_Orison - TACTICS_Crapple;
			AddMagicTacExp2(nKind, nExp);
			break;
		}
    case 4: // 嘎疽阑 版快 规菩 琶平
		{
			if (IsShield() && Peacests)
			{
				const int nParrying = TACTICS_Parrying - TACTICS_Crapple;
				AddPhysicalTacExp1(nParrying, nExp);
				// 版氰摹 函拳甫 困茄 Packet 傈价
				t_packet packet;
				packet.h.header.type = CMD_TACTICS_PARRYING_EXP;
				packet.h.header.size = sizeof(t_tactics_parrying_exp);
				packet.u.tactics_parrying_exp.exp = tac_skillEXP[nParrying];
				packet.u.tactics_parrying_exp.step = GetTacticsStep(nParrying);
				::QueuePacket(connections, GetServerID(), &packet, 1);
			}
			
			break;
		}
    case 5: // 颇萍矫 拱府利 傍拜 琶平
		{
			const int nKind = GetTacticsKind();
			if( SKILL_UNKNOWN == nKind ) break; // 030116 kyo 盖颊老订 怕平捞 棵福瘤 救绰促. 
			AddPhysicalTacExp3(nKind - TACTICS_Crapple, nExp);
			break; 
		}
	}
	
	return true;
}	//> CSD-TW-030624

void CCharInfo::GenerateNpcName()
{	//< CSD-030408
	const int nName = (NPC_MaleName_Count == 0) ? 0:(rand()%NPC_MaleName_Count);
	strcpy(Name, NPC_Name_Ref[nName].Male);
	::EatRearWhiteChar(Name);

	memset(HostName, 0, NM_LENGTH);
	namenumber = nName;
}	//> CSD-030408

void CCharInfo::AutoAttribute()
{	//< CSD-021024 : 磊悼 加己 汲沥
	const int nBasicResist = RareEM.GetStaticRareBasicResist(StaticRare) +
							 RareEM.GetDynamicRareValue(FITEM_INVALID_RESIST, DynamicRare);
	if (nBasicResist > 0)
	{
		if (rand()%101 < nBasicResist)
		{
			m_bsAttr.set(IGNORE_MAGIC_RESIST);
		}
		else
		{
			m_bsAttr.reset(IGNORE_MAGIC_RESIST);
		}
	}
	else
	{
		m_bsAttr.reset(IGNORE_MAGIC_RESIST);
	}
}	//> CSD-021024

void CCharInfo::SetAttribute(int nRace)
{	//< CSD-030408 : NPC 加己 汲沥
	switch (nRace)
	{	
	case GUARD:
		{	// 版厚盔牢 版快
			m_bsAttr.set(IGNORE_STRIKE_ATTACK);
			m_bsAttr.set(IGNORE_MAGIC_AMPLIFY);
			
			if (eventno >= 0)  
			{
				eventno = -1;
			}

			break;
		}
	case NORM_MON:
		{	// 阁胶磐甸篮 笼救俊 甸绢哎荐 绝促. 
			notcomeinside = true;
			break;
		}
	}
}	//> CSD-030408

bool CCharInfo::IsShield() const
{
	ItemAttr shield = equip[WT_SHIELD];
	if (shield.item_no == 0)  return false;
	
	CItem* pShield = ItemUnit(shield);
	if (pShield == NULL)  return false;

⌨️ 快捷键说明

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