-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Expand file tree
/
Copy pathtf_weapon_sword.cpp
More file actions
618 lines (522 loc) · 16.6 KB
/
tf_weapon_sword.cpp
File metadata and controls
618 lines (522 loc) · 16.6 KB
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
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=============================================================================
#include "cbase.h"
#include "tf_weapon_sword.h"
// Client specific.
#ifdef CLIENT_DLL
#include "c_tf_player.h"
#include "econ_entity.h"
// Server specific.
#else
#include "tf_player.h"
#endif
//=============================================================================
//
// Weapon Sword tables.
//
// CTFSword
IMPLEMENT_NETWORKCLASS_ALIASED( TFSword, DT_TFWeaponSword )
BEGIN_NETWORK_TABLE( CTFSword, DT_TFWeaponSword )
END_NETWORK_TABLE()
BEGIN_PREDICTION_DATA( CTFSword )
END_PREDICTION_DATA()
LINK_ENTITY_TO_CLASS( tf_weapon_sword, CTFSword );
PRECACHE_WEAPON_REGISTER( tf_weapon_sword );
// CTFKatana
IMPLEMENT_NETWORKCLASS_ALIASED( TFKatana, DT_TFWeaponKatana )
BEGIN_NETWORK_TABLE( CTFKatana, DT_TFWeaponKatana )
#ifdef CLIENT_DLL
RecvPropBool( RECVINFO( m_bIsBloody ) ),
#else
SendPropBool( SENDINFO( m_bIsBloody ) ),
#endif
END_NETWORK_TABLE()
BEGIN_PREDICTION_DATA( CTFKatana )
END_PREDICTION_DATA()
LINK_ENTITY_TO_CLASS( tf_weapon_katana, CTFKatana );
PRECACHE_WEAPON_REGISTER( tf_weapon_katana );
//=============================================================================
//
// Decapitation melee weapon base implementation.
//
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CTFDecapitationMeleeWeaponBase::CTFDecapitationMeleeWeaponBase()
: m_bHolstering( false )
{
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFDecapitationMeleeWeaponBase::Precache()
{
BaseClass::Precache();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
float CTFDecapitationMeleeWeaponBase::GetMeleeDamage( CBaseEntity *pTarget, int* piDamageType, int* piCustomDamage )
{
float flBaseDamage = BaseClass::GetMeleeDamage( pTarget, piDamageType, piCustomDamage );
*piCustomDamage = TF_DMG_CUSTOM_DECAPITATION;
return flBaseDamage;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
Activity CTFDecapitationMeleeWeaponBase::TranslateViewmodelHandActivityInternal( Activity actBase )
{
CTFPlayer *pPlayer = GetTFPlayerOwner();
if ( !pPlayer )
return BaseClass::TranslateViewmodelHandActivityInternal( actBase );
CEconItemView *pEconItemView = GetAttributeContainer()->GetItem();
if ( pEconItemView )
{
if ( pEconItemView->GetAnimationSlot() == TF_WPN_TYPE_MELEE_ALLCLASS )
return BaseClass::TranslateViewmodelHandActivityInternal( actBase );
}
// Alright, so we have some decapitation weapons (katana) that can be used
// by both the soldier and the demoman, but the classes play totally different
// animations using the same weapon.
//
// This logic is also responsible for playing the correct animations on the
// demo when he's using non-shared weapons like the Eyelanders.
if ( pPlayer->GetPlayerClass()->GetClassIndex() == TF_CLASS_DEMOMAN )
{
switch ( actBase )
{
case ACT_VM_DRAW:
actBase = ACT_VM_DRAW_SPECIAL;
break;
case ACT_VM_HOLSTER:
actBase = ACT_VM_HOLSTER_SPECIAL;
break;
case ACT_VM_IDLE:
actBase = ACT_VM_IDLE_SPECIAL;
break;
case ACT_VM_PULLBACK:
actBase = ACT_VM_PULLBACK_SPECIAL;
break;
case ACT_VM_PRIMARYATTACK:
actBase = ACT_VM_PRIMARYATTACK_SPECIAL;
break;
case ACT_VM_SECONDARYATTACK:
actBase = ACT_VM_PRIMARYATTACK_SPECIAL;
break;
case ACT_VM_HITCENTER:
actBase = ACT_VM_HITCENTER_SPECIAL;
break;
case ACT_VM_SWINGHARD:
actBase = ACT_VM_SWINGHARD_SPECIAL;
break;
case ACT_VM_IDLE_TO_LOWERED:
actBase = ACT_VM_IDLE_TO_LOWERED_SPECIAL;
break;
case ACT_VM_IDLE_LOWERED:
actBase = ACT_VM_IDLE_LOWERED_SPECIAL;
break;
case ACT_VM_LOWERED_TO_IDLE:
actBase = ACT_VM_LOWERED_TO_IDLE_SPECIAL;
break;
default:
break;
}
}
return BaseClass::TranslateViewmodelHandActivityInternal( actBase );
}
/*
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
bool CTFDecapitationMeleeWeaponBase::SendWeaponAnim( int iActivity )
{
}*/
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
bool CTFDecapitationMeleeWeaponBase::CanDecapitate( void )
{
CEconItemView *pScriptItem = GetAttributeContainer()->GetItem();
if ( !pScriptItem )
return false;
CEconItemDefinition *pStaticData = pScriptItem->GetStaticData();
if ( !pStaticData )
return false;
int iDecapitateType = 0;
CALL_ATTRIB_HOOK_INT( iDecapitateType, decapitate_type );
return iDecapitateType != 0;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFDecapitationMeleeWeaponBase::SetupGameEventListeners( void )
{
ListenForGameEvent( "player_death" );
}
#ifdef CLIENT_DLL
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFDecapitationMeleeWeaponBase::UpdateAttachmentModels( void )
{
BaseClass::UpdateAttachmentModels();
CTFPlayer *pTFPlayer = GetTFPlayerOwner();
if ( !pTFPlayer )
return;
if ( !pTFPlayer->IsLocalPlayer() )
return;
if ( !pTFPlayer->GetViewModel() )
return;
if ( !pTFPlayer->m_Shared.IsShieldEquipped() )
return;
CTFWearableDemoShield* pMyShield = dynamic_cast<CTFWearableDemoShield*>( m_hShield.Get() );
if ( pMyShield )
{
pMyShield->UpdateAttachmentModels();
}
else
{
// Find a shield wearable...
for ( int i=0; i<pTFPlayer->GetNumWearables(); ++i )
{
CEconWearable* pItem = pTFPlayer->GetWearable(i);
if ( !pItem )
continue;
pMyShield = dynamic_cast<CTFWearableDemoShield*>( pItem );
if ( !pMyShield )
continue;
m_hShield.Set( pMyShield );
}
if ( pMyShield )
{
pMyShield->UpdateAttachmentModels();
}
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
int CTFDecapitationMeleeWeaponBase::DrawOverriddenViewmodel( C_BaseViewModel *pViewmodel, int flags )
{
int iRes = BaseClass::DrawOverriddenViewmodel( pViewmodel, flags );
CTFWearableDemoShield* pMyShield = dynamic_cast<CTFWearableDemoShield*>( m_hShield.Get() );
if ( pMyShield )
{
pMyShield->DrawOverriddenViewmodel( pViewmodel, flags );
}
return iRes;
}
#endif // CLIENT_DLL
//=============================================================================
//
// Weapon Sword functions.
//
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFSword::WeaponReset( void )
{
BaseClass::WeaponReset();
#ifdef CLIENT_DLL
m_flNextIdleWavRoll = 0;
m_iPrevWavDecap = 0;
#endif
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
int CTFSword::GetSwingRange( void )
{
CTFPlayer *pOwner = ToTFPlayer( GetOwner() );
if ( pOwner && pOwner->m_Shared.InCond( TF_COND_SHIELD_CHARGE ) )
{
return 128;
}
else
{
//int iRange = 0;
//CALL_ATTRIB_HOOK_INT( iRange, is_a_sword )
//return 72;
return 72;
}
}
//-----------------------------------------------------------------------------
// Purpose: A speed mod that is applied even if the weapon isn't in hand.
//-----------------------------------------------------------------------------
float CTFSword::GetSwordSpeedMod( void )
{
if ( m_bHolstering )
return 1.f;
CTFPlayer *pOwner = ToTFPlayer( GetOwner() );
if ( !pOwner )
return 0;
if ( !CanDecapitate() )
return 1.f;
int iDecaps = MIN( MAX_DECAPITATIONS, pOwner->m_Shared.GetDecapitations() );
return 1.f + (iDecaps * 0.08f);
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
int CTFSword::GetSwordHealthMod( void )
{
CTFPlayer *pOwner = ToTFPlayer( GetOwner() );
if ( !pOwner )
return 0;
if ( !CanDecapitate() )
return 0.f;
int iDecaps = MIN( MAX_DECAPITATIONS, pOwner->m_Shared.GetDecapitations() );
return (iDecaps * 15);
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFSword::OnDecapitation( CTFPlayer *pDeadPlayer )
{
BaseClass::OnDecapitation( pDeadPlayer );
#ifdef GAME_DLL
CTFPlayer *pOwner = ToTFPlayer( GetOwner() );
Assert( pOwner );
// The pyro's scythe is actually a "sword" as far as the gameplay code is concerned,
// but we don't want the demo's head-collecting silliness to apply.
if ( pOwner->GetPlayerClass()->GetClassIndex() == TF_CLASS_DEMOMAN )
{
// We have chopped someone's bloody 'ead off!
int iDecap = pOwner->m_Shared.GetDecapitations();
// transfer decapitations
if ( pDeadPlayer )
{
iDecap += pDeadPlayer->m_Shared.GetDecapitations();
}
pOwner->m_Shared.SetDecapitations( ++iDecap );
pOwner->TeamFortress_SetSpeed();
if ( pOwner->m_Shared.GetBestOverhealDecayMult() == -1.f )
{
pOwner->m_Shared.SetBestOverhealDecayMult( 0.25f );
}
if ( pOwner->GetHealth() < pOwner->m_Shared.GetMaxBuffedHealth() )
{
pOwner->TakeHealth( 15, DMG_IGNORE_MAXHEALTH );
}
if ( !pOwner->m_Shared.InCond( TF_COND_DEMO_BUFF ) )
{
pOwner->m_Shared.AddCond( TF_COND_DEMO_BUFF );
}
}
#endif // GAME_DLL
}
#ifdef GAME_DLL
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
bool CTFDecapitationMeleeWeaponBase::Holster( CBaseCombatWeapon *pSwitchingTo )
{
m_bHolstering = true;
bool res = BaseClass::Holster( pSwitchingTo );
m_bHolstering = false;
if ( res )
{
StopListeningForAllEvents();
}
return res;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFDecapitationMeleeWeaponBase::FireGameEvent( IGameEvent *event )
{
const char *pszEventName = event->GetName();
if ( Q_strcmp( pszEventName, "player_death" ) != 0 )
return;
CTFPlayer *pOwner = ToTFPlayer( GetOwner() );
if ( !pOwner )
return;
int iAttackerID = event->GetInt( "attacker" );
if ( iAttackerID != pOwner->GetUserID() )
return;
int iWeaponID = event->GetInt( "weaponid" );
int iCustomKill = event->GetInt( "customkill" );
if ( iWeaponID != TF_WEAPON_SWORD && iCustomKill != TF_DMG_CUSTOM_TAUNTATK_BARBARIAN_SWING )
return;
// Off with their heads!
if ( !CanDecapitate() )
return;
OnDecapitation( ToTFPlayer( UTIL_PlayerByUserId( event->GetInt( "userid" ) ) ) );
}
#endif
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
bool CTFSword::Deploy( void )
{
bool res = BaseClass::Deploy();
if ( !CanDecapitate() )
{
CTFPlayer *pOwner = ToTFPlayer( GetOwner() );
if ( !pOwner )
return res;
pOwner->m_Shared.SetDecapitations( 0 );
return res;
}
#ifdef GAME_DLL
if ( res )
{
SetupGameEventListeners();
}
#else
// When we go active, there's a chance we immediately thirst for heads.
if ( RandomInt( 1,4 ) == 1 )
{
m_flNextIdleWavRoll = gpGlobals->curtime + 3.0;
}
else
{
m_flNextIdleWavRoll = gpGlobals->curtime + RandomFloat( 5.0, 30.0 );
}
#endif
return res;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
int CTFSword::GetCount( void )
{
CTFPlayer *pOwner = ToTFPlayer( GetOwner() );
if ( !pOwner )
return 0;
if ( !CanDecapitate() )
return 0;
return pOwner->m_Shared.GetDecapitations();
}
#ifdef CLIENT_DLL
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFSword::WeaponIdle( void )
{
BaseClass::WeaponIdle();
CTFPlayer *pOwner = ToTFPlayer( GetOwner() );
if ( !pOwner )
return;
if ( !CanDecapitate() )
return;
// If we've decapped someone recently, we roll shortly afterwards
int iDecaps = pOwner->m_Shared.GetDecapitations();
if ( m_iPrevWavDecap < iDecaps )
{
m_flNextIdleWavRoll = MIN( m_flNextIdleWavRoll, gpGlobals->curtime + RandomFloat(3,5) );
}
m_iPrevWavDecap = iDecaps;
// Randomly play sounds to the local player. The more decaps we have, the more chance it's a good wav.
if ( m_flNextIdleWavRoll < gpGlobals->curtime )
{
float flChance = RemapValClamped( iDecaps, 0, 10, 0.25, 0.9 );
if ( RandomFloat() <= flChance )
{
// Chance to get the more powerful wav:
float flChanceForGoodWav = RemapValClamped( iDecaps, 0, 10, 0.1, 0.75 );
if ( RandomFloat() <= flChanceForGoodWav )
{
WeaponSound( SPECIAL2 );
}
else
{
WeaponSound( SPECIAL1 );
}
}
m_flNextIdleWavRoll = gpGlobals->curtime + RandomFloat( 30.0, 60.0 );
}
}
#endif
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CTFKatana::CTFKatana()
{
m_bIsBloody = false;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
bool CTFKatana::Deploy( void )
{
bool res = BaseClass::Deploy();
m_bIsBloody = false;
if ( CanDecapitate() && res )
{
#ifdef GAME_DLL
SetupGameEventListeners();
#endif
}
return res;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
float CTFKatana::GetMeleeDamage( CBaseEntity *pTarget, int* piDamageType, int* piCustomDamage )
{
// Start with our base damage. We use this to generate our custom damage flags,
// if any. We may trash the damage amount.
float fDamage = BaseClass::GetMeleeDamage( pTarget, piDamageType, piCustomDamage );
// The katana is a weapon of honor!!!! (Hitting someone wielding a katana with
// your katana results in a massive damage boost, a one-hit kill.)
if ( IsHonorBound() )
{
CTFPlayer *pTFPlayerTarget = ToTFPlayer( pTarget );
if ( pTFPlayerTarget )
{
// If our victim is wielding the weapon we're looking for, bump the damage way up.
if ( pTFPlayerTarget->GetActiveTFWeapon() && pTFPlayerTarget->GetActiveTFWeapon()->IsHonorBound() )
{
fDamage = MAX( fDamage, pTFPlayerTarget->GetHealth() * 3 );
*piCustomDamage = TF_DMG_CUSTOM_HONORBOUND;
*piDamageType |= DMG_DONT_COUNT_DAMAGE_TOWARDS_CRIT_RATE;
}
}
}
return fDamage;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
int CTFKatana::GetActivityWeaponRole() const
{
CTFPlayer *pPlayer = GetTFPlayerOwner();
if ( pPlayer && pPlayer->GetPlayerClass()->GetClassIndex() == TF_CLASS_DEMOMAN )
{
// demo should use act table item1
return TF_WPN_TYPE_ITEM1;
}
return BaseClass::GetActivityWeaponRole();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFKatana::OnDecapitation( CTFPlayer *pDeadPlayer )
{
BaseClass::OnDecapitation( pDeadPlayer );
#ifndef CLIENT_DLL
m_bIsBloody = true;
#endif
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
int CTFKatana::GetSkinOverride() const
{
if ( m_bIsBloody && !UTIL_IsLowViolence() )
{
CTFPlayer *pPlayer = GetTFPlayerOwner();
if ( pPlayer )
{
return ( ( pPlayer->GetTeamNumber() == TF_TEAM_RED ) ? 2 : 3 );
}
}
return BaseClass::GetSkinOverride();
}