summaryrefslogtreecommitdiff
path: root/game/server/tf/halloween/spell/tf_spell_pickup.cpp
blob: 89d274c5e7c9214cb1c85060ae9359208921e207 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Spell
//
//=============================================================================//
#include "cbase.h"

#include "tf_spell_pickup.h"
#include "tf_player.h"
#include "halloween/tf_weapon_spellbook.h"
#include "tf_gamerules.h"

LINK_ENTITY_TO_CLASS( tf_spell_pickup, CSpellPickup );

BEGIN_DATADESC( CSpellPickup )

	// Keyfields.
	DEFINE_KEYFIELD( m_nTier, FIELD_INTEGER, "tier" ),

END_DATADESC();


//-----------------------------------------------------------------------------
CSpellPickup::CSpellPickup()
{
	m_nTier = 0;
}

//-----------------------------------------------------------------------------
void CSpellPickup::Spawn( void )
{
	BaseClass::Spawn();
	m_nSkin = m_nTier;
}

//-----------------------------------------------------------------------------
void CSpellPickup::Precache( void )
{
	BaseClass::Precache();

	PrecacheScriptSound( "Halloween.spell_pickup" );
	PrecacheScriptSound( "Halloween.spell_pickup_rare" );
}

//-----------------------------------------------------------------------------
bool CSpellPickup::MyTouch( CBasePlayer *pPlayer )
{
	CTFPlayer *pTFPlayer = ToTFPlayer( pPlayer );
	if ( pTFPlayer )
	{
		CTFSpellBook *pSpellBook = dynamic_cast< CTFSpellBook* >( pTFPlayer->GetEntityForLoadoutSlot( LOADOUT_POSITION_ACTION ) );
		if ( pSpellBook )
		{
			pSpellBook->RollNewSpell( m_nTier );

			CSingleUserRecipientFilter filter( pPlayer );
			const char *pszSoundName = ( m_nTier > 0 ) ? "Halloween.spell_pickup_rare" : "Halloween.spell_pickup";
			EmitSound( filter, entindex(), pszSoundName );
		}
	}

	return true;
}


//-----------------------------------------------------------------------------
bool CSpellPickup::ItemCanBeTouchedByPlayer( CBasePlayer *pPlayer )
{
	if ( IsDisabled() )
		return false;

	// Dont let them pick up new spells if they already have a spell unless its a tier 1 spell
	CTFPlayer *pTFPlayer = ToTFPlayer( pPlayer );
	if ( pTFPlayer && m_nTier == 0 )
	{
		CTFSpellBook *pSpellBook = dynamic_cast< CTFSpellBook* >( pTFPlayer->GetEntityForLoadoutSlot( LOADOUT_POSITION_ACTION ) );
		if ( !pSpellBook )
		{
			// TEMP
			ClientPrint( pPlayer, HUD_PRINTCENTER, "Equip a SpellBook in your ActionSlot to pick this up.", pPlayer->GetPlayerName() );
			return false;
		}
		
		if ( pSpellBook->HasASpellWithCharges() )
		{
			return false;
		}
	}

	return true;
}

//-----------------------------------------------------------------------------
const char *CSpellPickup::GetPowerupModel( void )
{
	if ( TFGameRules() && TFGameRules()->IsHalloweenScenario( CTFGameRules::HALLOWEEN_SCENARIO_DOOMSDAY ) )
	{
		if ( m_nTier == 1 )
		{
			return "models/items/crystal_ball_pickup_major.mdl";
		}
		return "models/items/crystal_ball_pickup.mdl";
	}

	if ( m_nTier == 1 )
	{
		return "models/props_halloween/hwn_spellbook_upright_major.mdl";
	}

	return BaseClass::GetPowerupModel();
}