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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: CTF CurrencyPack.
//
//=============================================================================//
#include "cbase.h"
#include "items.h"
#include "tf_gamerules.h"
#include "tf_shareddefs.h"
#include "tf_player.h"
#include "tf_team.h"
#include "engine/IEngineSound.h"
#include "entity_currencypack.h"
#include "tf_gamestats.h"
#include "tf_mann_vs_machine_stats.h"
#include "world.h"
#include "particle_parse.h"
#include "player_vs_environment/tf_population_manager.h"
#include "collisionutils.h"
#include "tf_objective_resource.h"
//=============================================================================
//
// CTF CurrencyPack defines.
//
#define TF_CURRENCYPACK_PICKUP_SOUND "MVM.MoneyPickup"
#define TF_CURRENCYPACK_VANISH_SOUND "MVM.MoneyVanish"
#define TF_CURRENCYPACK_BLINK_PERIOD 5.0f // how long pack blinks before it vanishes
#define TF_CURRENCYPACK_BLINK_DURATION 0.25f // how long a blink lasts
#define TF_CURRENCYPACK_GLOW_THINK_TIME 0.1f // how often should we check if cash should glow
LINK_ENTITY_TO_CLASS( item_currencypack_large, CCurrencyPack );
LINK_ENTITY_TO_CLASS( item_currencypack_medium, CCurrencyPackMedium );
LINK_ENTITY_TO_CLASS( item_currencypack_small, CCurrencyPackSmall );
LINK_ENTITY_TO_CLASS( item_currencypack_custom, CCurrencyPackCustom );
IMPLEMENT_SERVERCLASS_ST( CCurrencyPack, DT_CurrencyPack )
SendPropBool( SENDINFO( m_bDistributed ) ),
END_SEND_TABLE()
IMPLEMENT_AUTO_LIST( ICurrencyPackAutoList );
//=============================================================================
//
// CTF CurrencyPack functions.
//
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CCurrencyPack::CCurrencyPack()
{
m_nAmount = 0;
m_nWaveNumber = MannVsMachineStats_GetCurrentWave();
m_bTouched = false;
m_bClaimed = false;
m_bDistributed = false;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CCurrencyPack::~CCurrencyPack()
{
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCurrencyPack::UpdateOnRemove( void )
{
BaseClass::UpdateOnRemove();
if ( g_pPopulationManager && !m_bTouched )
{
if ( !m_bDistributed )
{
g_pPopulationManager->OnCurrencyPackFade();
}
DispatchParticleEffect( "mvm_cash_explosion", GetAbsOrigin(), GetAbsAngles() );
}
if ( !m_bDistributed && TFObjectiveResource() )
{
TFObjectiveResource()->AddMvMWorldMoney( -m_nAmount );
}
}
//-----------------------------------------------------------------------------
// Purpose: Always transmitted to clients
//-----------------------------------------------------------------------------
int CCurrencyPack::UpdateTransmitState( void )
{
return SetTransmitState( FL_EDICT_ALWAYS );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
int CCurrencyPack::ShouldTransmit( const CCheckTransmitInfo *pInfo )
{
return FL_EDICT_ALWAYS;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCurrencyPack::Spawn( void )
{
BaseClass::Spawn();
m_blinkCount = 0;
m_blinkTimer.Invalidate();
SetContextThink( &CCurrencyPack::BlinkThink, gpGlobals->curtime + GetLifeTime() - TF_CURRENCYPACK_BLINK_PERIOD - RandomFloat( 0.0, TF_CURRENCYPACK_BLINK_DURATION ), "CurrencyPackWaitingToBlinkThink" );
// Force collision size to see if this fixes a bunch of stuck-in-geo issues goes away
SetCollisionBounds( Vector( -10, -10, -10 ), Vector( 10, 10, 10 ) );
if ( m_bDistributed )
{
DispatchParticleEffect( "mvm_cash_embers_red", PATTACH_ABSORIGIN_FOLLOW, this );
}
else
{
DispatchParticleEffect( "mvm_cash_embers", PATTACH_ABSORIGIN_FOLLOW, this );
}
// Store when this drops for time-based accounting - like with wave collection bonus
m_nWaveNumber = MannVsMachineStats_GetCurrentWave();
// if m_nAmount != 0, we already call SetAmount
m_nAmount = m_nAmount == 0 ? TFGameRules()->CalculateCurrencyAmount_ByType( GetPackSize() ) : m_nAmount;
MannVsMachineStats_RoundEvent_CreditsDropped( m_nWaveNumber, m_nAmount );
if ( !m_bDistributed && TFObjectiveResource() )
{
TFObjectiveResource()->AddMvMWorldMoney( m_nAmount );
}
}
//-----------------------------------------------------------------------------
// Purpose: Blink off/on when about to expire and play expire sound
//-----------------------------------------------------------------------------
void CCurrencyPack::BlinkThink( void )
{
// This means the pack was claimed by a player via Radius Currency Collection and
// is likely flying toward them. Regardless, one second later it fires Touch().
if ( IsClaimed() )
return;
++m_blinkCount;
SetRenderMode( kRenderTransAlpha );
if ( m_blinkCount & 0x1 )
{
SetRenderColorA( 25 );
}
else
{
SetRenderColorA( 255 );
}
SetContextThink( &CCurrencyPack::BlinkThink, gpGlobals->curtime + TF_CURRENCYPACK_BLINK_DURATION, "CurrencyPackBlinkThink" );
}
//-----------------------------------------------------------------------------
// Become touchable when we are at rest
//-----------------------------------------------------------------------------
void CCurrencyPack::ComeToRest( void )
{
BaseClass::ComeToRest();
if ( IsClaimed() || m_bDistributed )
return;
// if we've come to rest in an area with no nav, just grant the money to the player
if ( TheNavMesh->GetNavArea( GetAbsOrigin() ) == NULL )
{
TFGameRules()->DistributeCurrencyAmount( m_nAmount );
m_bTouched = true;
UTIL_Remove( this );
return;
}
// See if we've come to rest in a trigger_hurt
for ( int i = 0; i < ITriggerHurtAutoList::AutoList().Count(); i++ )
{
CTriggerHurt *pTrigger = static_cast<CTriggerHurt*>( ITriggerHurtAutoList::AutoList()[i] );
if ( !pTrigger->m_bDisabled )
{
Vector vecMins, vecMaxs;
pTrigger->GetCollideable()->WorldSpaceSurroundingBounds( &vecMins, &vecMaxs );
if ( IsPointInBox( GetCollideable()->GetCollisionOrigin(), vecMins, vecMaxs ) )
{
TFGameRules()->DistributeCurrencyAmount( m_nAmount );
m_bTouched = true;
UTIL_Remove( this );
}
}
}
}
//-----------------------------------------------------------------------------
// Purpose: Sets the value of a custom pack
//-----------------------------------------------------------------------------
void CCurrencyPack::SetAmount( float nAmount )
{
Assert( GetPackSize() == TF_CURRENCY_PACK_CUSTOM ); // Never set an amount unless we're custom
m_nAmount = nAmount;
}
//-----------------------------------------------------------------------------
// Purpose: Distribute the money right away
//-----------------------------------------------------------------------------
void CCurrencyPack::DistributedBy( CBasePlayer* pMoneyMaker )
{
TFGameRules()->DistributeCurrencyAmount( m_nAmount );
if ( pMoneyMaker )
{
CTF_GameStats.Event_PlayerCollectedCurrency( pMoneyMaker, m_nAmount );
}
m_bDistributed = true;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCurrencyPack::Precache( void )
{
PrecacheScriptSound( TF_CURRENCYPACK_PICKUP_SOUND );
PrecacheScriptSound( TF_CURRENCYPACK_VANISH_SOUND );
PrecacheParticleSystem( "mvm_cash_embers" );
PrecacheParticleSystem( "mvm_cash_explosion" );
BaseClass::Precache();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
bool CCurrencyPack::MyTouch( CBasePlayer *pPlayer )
{
if ( ValidTouch( pPlayer ) && !m_bTouched )
{
CTFPlayer *pTFTouchPlayer = ToTFPlayer( pPlayer );
if ( !pTFTouchPlayer )
return false;
if ( pTFTouchPlayer->IsBot() )
return false;
if ( TFGameRules() && TFGameRules()->IsMannVsMachineMode() )
{
// Prevent losing team from grabbing money - screws up stats in checkpoints
if ( TFGameRules()->State_Get() == GR_STATE_TEAM_WIN )
{
if ( TFGameRules()->GetWinningTeam() != pTFTouchPlayer->GetTeamNumber() )
return false;
}
// Scouts gain health when grabbing currency packs
if ( pTFTouchPlayer->GetPlayerClass()->GetClassIndex() == TF_CLASS_SCOUT )
{
const int nCurHealth = pTFTouchPlayer->GetHealth();
const int nMaxHealth = pTFTouchPlayer->GetMaxHealth();
int nHealth = nCurHealth < nMaxHealth ? 50 : 25;
// If we cross the border into insanity, scale the reward
const int nHealthCap = nMaxHealth * 4;
if ( nCurHealth > nHealthCap )
{
nHealth = RemapValClamped( nCurHealth, nHealthCap, (nHealthCap * 1.5f), 20, 5 );
}
pTFTouchPlayer->TakeHealth( nHealth, DMG_IGNORE_MAXHEALTH );
}
MannVsMachineStats_PlayerEvent_PickedUpCredits( pTFTouchPlayer, m_nWaveNumber, m_nAmount );
IGameEvent *event = gameeventmanager->CreateEvent( "mvm_pickup_currency" );
if ( event )
{
event->SetInt( "player", pTFTouchPlayer->entindex() );
event->SetInt( "currency", m_nAmount );
gameeventmanager->FireEvent( event );
}
// is the money blinking and about to burn up?
if ( m_blinkCount > 0 )
{
pTFTouchPlayer->AwardAchievement( ACHIEVEMENT_TF_MVM_PICKUP_MONEY_ABOUT_TO_EXPIRE );
}
}
CReliableBroadcastRecipientFilter filter;
EmitSound( filter, entindex(), TF_CURRENCYPACK_PICKUP_SOUND );
if ( !m_bDistributed )
{
TFGameRules()->DistributeCurrencyAmount( m_nAmount, pTFTouchPlayer );
CTF_GameStats.Event_PlayerCollectedCurrency( pTFTouchPlayer, m_nAmount );
}
if ( ( !pTFTouchPlayer->IsPlayerClass( TF_CLASS_SPY ) ) ||
( !pTFTouchPlayer->m_Shared.IsStealthed() && !pTFTouchPlayer->m_Shared.InCond( TF_COND_STEALTHED_BLINK ) && !pTFTouchPlayer->m_Shared.InCond( TF_COND_DISGUISED ) ) )
{
pTFTouchPlayer->SpeakConceptIfAllowed( MP_CONCEPT_MVM_MONEY_PICKUP );
}
pTFTouchPlayer->SetLastObjectiveTime( gpGlobals->curtime );
m_bTouched = true;
}
return m_bTouched;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
const char *CCurrencyPackCustom::GetDefaultPowerupModel( void )
{
// Custom packs should always be set to a value by hand
Assert( m_nAmount > 0 );
// Try to pick a model that's appropriate to our drop amount (which is in our multiplier)
if ( m_nAmount >= 25 )
return "models/items/currencypack_large.mdl";
if ( m_nAmount >= 10 )
return "models/items/currencypack_medium.mdl";
return "models/items/currencypack_small.mdl";
}
|