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

📄 inventorymgr.cpp

📁 Blood 2全套源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:

		case WEAP_COMBATSHOTGUN:
			w = new CCombatShotgun;
			break;

		case WEAP_FLAYER:
			w = new CFlayer;
			break;
#endif

#ifndef _DEMO
		case WEAP_PROXIMITYBOMB:
			w = new CWeapProximityBomb;
			break;

		case WEAP_REMOTEBOMB:
			w = new CWeapRemoteBomb;
			break;

		case WEAP_TIMEBOMB:
			w = new CWeapTimeBomb;
			break;
#endif
		case WEAP_SHIKARI_CLAW:
			w = new CShikariClaw;
			break;

		case WEAP_SHIKARI_SPIT:
			w = new CShikariSpit;
			break;

		case WEAP_SOUL_CROWBAR:
			w = new CSoulCrowbar;
			break;

		case WEAP_SOUL_AXE:
			w = new CSoulAxe;
			break;
		case WEAP_SOUL_PIPE:
			w = new CSoulPipe;
			break;

		case WEAP_SOUL_HOOK:
			w = new CSoulHook;
			break;

		case WEAP_BEHEMOTH_CLAW:
			w = new CBehemothClaw;
			break;

		case WEAP_ZEALOT_HEAL:
			w = new CZealotHeal;
			break;

		case WEAP_ZEALOT_SHIELD:
			w = new CZealotShield;
			break;

		case WEAP_ZEALOT_ENERGYBLAST:
			w = new CEnergyBlast;
			break;

		case WEAP_ZEALOT_SHOCKWAVE:
			w = new CShockwave;
			break;

		case WEAP_ZEALOT_GROUNDFIRE:
			w = new CGroundStrike;
			break;

		case WEAP_DRUDGE_FIREBALL:
			w = new CFireball;
			break;

		case WEAP_DRUDGE_LIGHTNING:
			w = new CDrudgeLightning;
			break;

		case WEAP_HAND_SQUEEZE:
			w = new CHandSqueeze;
			break;

		case WEAP_THIEF_SUCK:
			w = new CThiefSuck;
			break;

		case WEAP_BONELEECH_SUCK:
			w = new CThiefSuck;
			break;

		case WEAP_NIGHTMARE_BITE:
			w = new CNightmareBite;
			break;

		case WEAP_BEHEMOTH_SHOCKWAVE:
			w = new CBehemothShockwave;
			break;

		case WEAP_DEATHSHROUD_ZAP:
			w = new CDeathShroudZap;
			break;

		case WEAP_NAGA_EYEBEAM:
			w = new CNagaEyes;
			break;

		case WEAP_NAGA_SPIKE:
			w = new CNagaSpike;
			break;

		case WEAP_NAGA_DEBRIS:
			w = new CNagaDebris;
			break;

		case WEAP_GIDEON_SHIELD:
			w = new CGideonShield;
			break;

		case WEAP_GIDEON_WIND:
			w = new CGideonWind;
			break;

		case WEAP_GIDEON_GOO:
			w = new CGooSpit;
			break;

		case WEAP_GIDEON_VOMIT:
			w = new CVomit;
			break;

		case WEAP_GIDEON_SPEAR:
			w = new CGideonSpear;
			break;

		case WEAP_ANCIENTONE_BEAM:
			w = new CAncientOneBeam;
			break;

		case WEAP_ANCIENTONE_TENTACLE:
			w = new CAncientOneTentacle;
			break;

		case WEAP_SKULL:
			w = new CSkull;
			break;

#ifdef _ADD_ON

		case WEAP_GREMLIN_ROCK:
			w = new CGremlinRock;
			break;

		case WEAP_NIGHTMARE_FIREBALLS:
			w = new CNightmareFireballs;
			break;

#endif

		default: return DFALSE;
	}
/* Disabled strength check [gjk 10/23/98]
	// Make sure we can carry this dang thing
	DDWORD nAttrib;
	int iRet;

	if (w->GetAmmoType() != AMMO_FOCUS)	// not a magic weapon
	{
		nAttrib = m_nAttribStrength;
		iRet = CHWEAP_NOTENOUGHSTRENGTH;
	}
	else
	{
		nAttrib = m_nAttribMagic;
		iRet = CHWEAP_NOTENOUGHMAGIC;
	}

	DDWORD dwWeapStrength;
	if (bLeftHand) 
		dwWeapStrength = w->GetTwoHandStrengthReq();
	else 
		dwWeapStrength = w->GetStrengthReq();

	if (dwWeapStrength > nAttrib)
	{
		w->Term();
		delete w;
		return iRet;
	}
*/
	w->Init(m_hOwner, this, bLeftHand, m_hMuzzleFlash);
	if (m_hClient)
	{
//		w->SetClient(m_hClient, bLeftHand ? m_pLViewModel : m_pViewModel);
		w->SetClient(m_hClient, bLeftHand ? m_pLViewModel : m_pViewModel);
	}

	if (bLeftHand)
		m_LWeapons[emptyslot] = w;
	else
		m_Weapons[emptyslot] = w;

	// if this is the current slot, set a pointer
	if (emptyslot == m_nCurWeaponSlot)
	{
		m_nCurWeapon = nWeapon;
		m_pCurWeapon = w;

		if(m_pCurWeapon->IsOwnerAPlayer())
			w->Draw();
		else
			w->SetupMuzzleFlash();
	}

	return CHWEAP_OK;
}


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	CInventoryMgr::ChangeWeapon()
//
//	PURPOSE:	Changes the current selected weapon
//
// ----------------------------------------------------------------------- //

int CInventoryMgr::ChangeWeapon(DDWORD nWeapon)
{
	CWeapon *w;

	if(nWeapon <= WEAP_NONE || nWeapon >= WEAP_MAXWEAPONTYPES)
		return CHWEAP_NOTAVAIL;

	if(nWeapon == m_nCurWeapon)
		return CHWEAP_CURRENT;

//	if (m_pCurWeapon && !m_pCurWeapon->IsIdle())
//		return CHWEAP_WEAPONBUSY;

	w = NULL;
	for (int i=0;i < SLOTCOUNT_WEAPONS; i++)
	{
		w = m_Weapons[i];
		if (w && w->GetType() == nWeapon)
			break;
		else
			w = NULL;
	}

	if(w == NULL)
		return CHWEAP_NOTAVAIL;

	// Okay, we have it, change to it
	if (m_Weapons[m_nCurWeaponSlot])
		m_Weapons[m_nCurWeaponSlot]->ShowHandModel(DFALSE);
	if (m_LWeapons[m_nCurWeaponSlot])
		m_LWeapons[m_nCurWeaponSlot]->ShowHandModel(DFALSE);

	// See if we have the new weapon & enough strength;
/*
	if (m_hClient)		// Only for player object owners
	{
		if (m_Weapons[m_nCurWeaponSlot])
			m_Weapons[m_nCurWeaponSlot]->Holster();
		if (m_LWeapons[m_nCurWeaponSlot])
			m_LWeapons[m_nCurWeaponSlot]->Holster();

		m_bSwitchingWeapons = DTRUE;
		m_nNextWeaponSlot = i;
	}
	else
	{*/
		m_pCurWeapon->Holster();

		// Okay, we have it, change to it
		if(m_pCurWeapon)
			m_pCurWeapon->ShowHandModel(DFALSE);

		m_pCurWeapon = w;
		m_nCurWeapon = nWeapon;
		m_nCurWeaponSlot = i;
		w->SetupMuzzleFlash();
//	}

	return CHWEAP_OK;
}


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	CInventoryMgr::ChangeWeaponSlot()
//
//	PURPOSE:	Changes to a particular weapon slot
//
// ----------------------------------------------------------------------- //

int CInventoryMgr::ChangeWeaponSlot(DBYTE nSlot)
{
	if(nSlot >= SLOTCOUNT_TOTALWEAPONS)
		return CHWEAP_NOTAVAIL;

//	if(m_pCurWeapon && !m_pCurWeapon->IsIdle())
//		return CHWEAP_WEAPONBUSY;

	CWeapon *w = m_Weapons[nSlot];

	if(m_hClient != DNULL)
	{
		CServerDE* pServerDE = BaseClass::GetServerDE();
		CPlayerObj *pObj = (CPlayerObj*)pServerDE->HandleToObject(m_hOwner);
		pObj->SetZoomMode(DFALSE);
	}

	if (!w) 
		return CHWEAP_NOTAVAIL;
		
	if (w->GetType() == m_nCurWeapon)
		return CHWEAP_CURRENT;

	// Okay, we have it, change to it
	if (m_Weapons[m_nCurWeaponSlot])
		m_Weapons[m_nCurWeaponSlot]->ShowHandModel(DFALSE);
	if (m_LWeapons[m_nCurWeaponSlot])
		m_LWeapons[m_nCurWeaponSlot]->ShowHandModel(DFALSE);

/*	if (m_hClient)		// Only for player object owners
	{
		if (m_Weapons[m_nCurWeaponSlot]) 
			m_Weapons[m_nCurWeaponSlot]->Holster();
		if (m_LWeapons[m_nCurWeaponSlot]) 
			m_LWeapons[m_nCurWeaponSlot]->Holster();

		m_bSwitchingWeapons = DTRUE;
		m_nNextWeaponSlot = nSlot;
	}
	else
	{*/

		// Okay, we have it, change to it
		if(m_pCurWeapon)
		{
			m_pCurWeapon->Holster();
			m_pCurWeapon->ShowHandModel(DFALSE);
		}

		m_pCurWeapon = w;
		m_nCurWeapon = w->GetType();
		m_nCurWeaponSlot = nSlot;
		assert( m_nCurWeaponSlot < 10 );
		w->SetupMuzzleFlash();
//	}

	return CHWEAP_OK;
}

// ----------------------------------------------------------------------- //
// ROUTINE		: CInventoryMgr::FindBestWeapon
// DESCRIPTION	: 
// RETURN TYPE	: CWeapon* 
// PARAMS		: DFLOAT fTargetDist
// ----------------------------------------------------------------------- //

CWeapon* CInventoryMgr::FindBestWeapon(DFLOAT fTargetDist)
{
	CWeapon* pWeapon = m_pCurWeapon;

	for(int i = 0; i < SLOTCOUNT_WEAPONS; i++)
	{
		CWeapon *pW = m_Weapons[i];

		DFLOAT fCurDamage = pWeapon ? (DFLOAT)pWeapon->GetWeaponDamage() : 0.0f;
		DFLOAT fCurAmmo   = pWeapon ? GetAmmoCount(pWeapon->GetAmmoType(DFALSE)) : 0.0f;

		if(pW)
		{
			DFLOAT fRange		= pW->GetWeaponRange();
			DFLOAT fDamage		= (DFLOAT)pW->GetWeaponDamage();
			DFLOAT fDmgRange	= pW->GetWeaponDmgRange();
			DFLOAT fAmmoCount	= GetAmmoCount(pW->GetAmmoType(DFALSE));

			if(fTargetDist < fRange &&  fDmgRange < fTargetDist && fAmmoCount && 
			   (fDamage > fCurDamage || fCurAmmo <= 0.0f))
				pWeapon = pW;
		}
	}

	if(pWeapon == m_pCurWeapon)
		return DNULL;
	else
		return pWeapon;
}

// ----------------------------------------------------------------------- //
//
//	ROUTINE:	CInventoryMgr::SelectNextWeapon()
//
//	PURPOSE:	Changes the current selected weapon to the next available.
//
// ----------------------------------------------------------------------- //

int CInventoryMgr::SelectNextWeapon()
{
	CServerDE* pServerDE = BaseClass::GetServerDE();

	CWeapon *w;

//	if (m_pCurWeapon && (!m_pCurWeapon->IsIdle() || m_pCurWeapon->IsChanging()))
//	{
//		return CHWEAP_WEAPONBUSY;
//	}
	
	if( m_nCurWeaponSlot < 0 || SLOTCOUNT_WEAPONS <= m_nCurWeaponSlot )
		m_nCurWeaponSlot = 0;

	int slot = (m_nCurWeaponSlot + 1) % SLOTCOUNT_WEAPONS;

	while (slot != m_nCurWeaponSlot && !m_Weapons[slot])
		slot = (slot + 1) % SLOTCOUNT_WEAPONS;

	if (slot == m_nCurWeaponSlot)
	{
		pServerDE->CPrint("Weapon slot equals the current slot: %d", m_nCurWeaponSlot);
		return CHWEAP_CURRENT;
	}

	if (!(w = m_Weapons[slot])) 
	{
		pServerDE->CPrint("Weapon is not valid... cannot change weapons.");
		return CHWEAP_NOTAVAIL;
	}

	return ChangeWeaponSlot(slot);
}


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	CInventoryMgr::SelectPrevWeapon()
//
//	PURPOSE:	Changes the current selected weapon to the prev available.
//
// ----------------------------------------------------------------------- //

int CInventoryMgr::SelectPrevWeapon()
{
	CServerDE* pServerDE = BaseClass::GetServerDE();

	CWeapon *w;

//	if (m_pCurWeapon && (!m_pCurWeapon->IsIdle() || m_pCurWeapon->IsChanging()))
//	{
//		return CHWEAP_WEAPONBUSY;
//	}

	if( m_nCurWeaponSlot < 0 || SLOTCOUNT_WEAPONS <= m_nCurWeaponSlot )
		m_nCurWeaponSlot = 0;

	int slot = m_nCurWeaponSlot - 1;
	if (slot < 0) 
		slot = SLOTCOUNT_WEAPONS - 1;

	while (slot != m_nCurWeaponSlot && !m_Weapons[slot])
	{
		slot--;
		if (slot < 0)
			slot = SLOTCOUNT_WEAPONS - 1;
	}

	if (slot == m_nCurWeaponSlot)
	{
		return CHWEAP_CURRENT;
	}

	if (!(w = m_Weapons[slot])) 
	{
		pServerDE->CPrint("Weapon is not valid... cannot change weapons.");		
		return CHWEAP_NOTAVAIL;
	}

	return ChangeWeaponSlot(slot);
}


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	CInventoryMgr::DropWeapon(DBYTE slot)
//
//	PURPOSE:	Drops the current weapon
//
// ----------------------------------------------------------------------- //

int CInventoryMgr::DropWeapon(DBYTE slot)
{
	CServerDE* pServerDE = BaseClass::GetServerDE();
/*
	// Only drop weapons in single player
	if (g_pBloodServerShell->GetGameType() != GAMETYPE_SINGLE)
		return CHWEAP_NOMESSAGE;

	CWeapon	*w = DNULL; //m_Weapons[slot];
/*
	//sanity check
	if(w == DNULL)
		return CHWEAP_NOTAVAIL;

	// Can't drop a weapon while it's busy
	if (w && !w->IsIdle())
		return CHWEAP_WEAPONBUSY;

	// Can't drop the melee weapon
	if (w->GetType() == WEAP_MELEE)
		return CHWEAP_NOMESSAGE;
*/
	// Drop the left-handed weapon if we have it.
/*	if (m_LWeapons[slot])
	{
		w = m_LWeapons[slot];

		// Can't drop a weapon while it's busy
		if (!w->IsIdle())
			return CHWEAP_WEAPONBUSY;

		// Can't drop the melee weapon
		if (w->GetType() == WEAP_MELEE)
			return CHWEAP_NOMESSAGE;
		
		m_LWeapons[slot] = NULL;
		bLeftHand = DTRUE;

		if (w == m_pCurWeapon)
			m_pCurWeapon = m_Weapons[slot];

		w->DropHandModel();

		w->Term();
		delete w;
	}
	else
	{
		w = m_Weapons[slot];

		// Can't drop a weapon while it's busy
		if (!w->IsIdle())
			return CHWEAP_WEAPONBUSY;

		// Can't drop the melee weapon
		if (w->GetType() == WEAP_MELEE)

⌨️ 快捷键说明

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