-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Expand file tree
/
Copy pathtf_weapon_spellbook.cpp
More file actions
3556 lines (2994 loc) · 113 KB
/
tf_weapon_spellbook.cpp
File metadata and controls
3556 lines (2994 loc) · 113 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
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=============================================================================
#include "cbase.h"
#include "tf_weapon_spellbook.h"
#include "decals.h"
#include "tf_gamerules.h"
#include "tf_pumpkin_bomb.h"
// Client specific.
#ifdef CLIENT_DLL
#include "c_basedoor.h"
#include "c_tf_player.h"
#include "IEffects.h"
#include "bone_setup.h"
#include "c_tf_gamestats.h"
#include "iclientmode.h"
#include <vgui_controls/AnimationController.h>
#include "econ_notifications.h"
#include "gc_clientsystem.h"
#include "tf_logic_halloween_2014.h"
#include "tf_hud_itemeffectmeter.h"
#include "dlight.h"
#include "iefx.h"
extern void AddSubKeyNamed( KeyValues *pKeys, const char *pszName );
// Server specific.
#else
#include "doors.h"
#include "tf_player.h"
#include "tf_ammo_pack.h"
#include "tf_gamestats.h"
#include "ilagcompensationmanager.h"
#include "collisionutils.h"
#include "particle_parse.h"
#include "tf_projectile_base.h"
#include "tf_gamerules.h"
#include "tf_fx.h"
#include "takedamageinfo.h"
#include "halloween/zombie/zombie.h"
#include "halloween/eyeball_boss/eyeball_boss.h"
#include "halloween/halloween_base_boss.h"
#include "entity_healthkit.h"
#include "eyeball_boss/teleport_vortex.h"
#include "in_buttons.h"
#include "halloween/merasmus/merasmus.h"
#include "tf_weapon_grenade_pipebomb.h"
#include "tf_obj_dispenser.h"
#include "tf_weapon_flamethrower.h"
#endif
ConVar tf_test_spellindex( "tf_test_spellindex", "-1", FCVAR_CHEAT | FCVAR_REPLICATED, "Set to index to always get a specific spell" );
#ifdef GAME_DLL
ConVar tf_halloween_kart_rocketspell_speed( "tf_halloween_kart_rocketspell_speed", "1500", FCVAR_CHEAT );
ConVar tf_halloween_kart_rocketspell_lifetime( "tf_halloween_kart_rocketspell_lifetime", "0.5f", FCVAR_CHEAT );
ConVar tf_halloween_kart_rocketspell_force( "tf_halloween_kart_rocketspell_force", "900.0f", FCVAR_CHEAT );
#endif
extern ConVar tf_eyeball_boss_hover_height;
extern ConVar tf_halloween_kart_normal_speed;
extern ConVar tf_halloween_kart_dash_speed;
//=============================================================================
//
// Weapon Tables
//
// SpellBook --
IMPLEMENT_NETWORKCLASS_ALIASED( TFSpellBook, DT_TFWeaponSpellBook )
BEGIN_NETWORK_TABLE( CTFSpellBook, DT_TFWeaponSpellBook )
#ifdef CLIENT_DLL
RecvPropInt( RECVINFO( m_iSelectedSpellIndex ) ),
RecvPropInt( RECVINFO( m_iSpellCharges ) ),
RecvPropFloat( RECVINFO( m_flTimeNextSpell ) ),
RecvPropBool( RECVINFO( m_bFiredAttack ) ),
#else
SendPropInt( SENDINFO( m_iSelectedSpellIndex ) ),
SendPropInt( SENDINFO( m_iSpellCharges ) ),
SendPropFloat( SENDINFO( m_flTimeNextSpell ) ),
SendPropBool( SENDINFO( m_bFiredAttack ) ),
#endif
END_NETWORK_TABLE()
BEGIN_PREDICTION_DATA( CTFSpellBook )
END_PREDICTION_DATA()
LINK_ENTITY_TO_CLASS( tf_weapon_spellbook, CTFSpellBook );
PRECACHE_WEAPON_REGISTER( tf_weapon_spellbook );
// -- SpellBook
#define SPELL_EMPTY -1
#define SPELL_UNKNOWN -2
#define SPELL_BOXING_GLOVE "models/props_halloween/hwn_spell_boxing_glove.mdl"
//=============================================================================
// Spell Data Structures
//=============================================================================
enum SpellType_t
{
SPELL_ROCKET,
SPELL_JAR, // Explodes on Contact
SPELL_SELF,
};
struct spell_data_t
{
spell_data_t(
const char *pSpellUiName,
int iSpellCharges,
SpellType_t eSpelltype,
const char *pSpellEntityName,
bool (*pCastSpell)(CTFPlayer*),
const char *pszCastSound,
float flSpeedScale,
int iCastContext,
int iSpellContext,
const char *pIconName,
bool bAutoCast = false
) {
m_pSpellUiName = pSpellUiName;
m_eSpellType = eSpelltype;
m_pSpellEntityName = pSpellEntityName;
m_iSpellCharges = iSpellCharges;
m_pCastSpell = pCastSpell;
m_pszCastSound = pszCastSound;
m_flSpeedScale = flSpeedScale;
m_iCastContext = iCastContext;
m_iSpellContext = iSpellContext;
m_pIconName = pIconName;
m_bAutoCast = bAutoCast;
}
const char * m_pSpellUiName;
SpellType_t m_eSpellType;
const char *m_pSpellEntityName;
int m_iSpellCharges;
const char *m_pszCastSound;
float m_flSpeedScale;
int m_iCastContext; // context for the spell caster
int m_iSpellContext; // context for enemies who witness the spell
bool (*m_pCastSpell)(CTFPlayer*);
const char *m_pIconName;
bool m_bAutoCast;
};
static const spell_data_t g_NormalSpellList[] =
{
spell_data_t( "#TF_Spell_Fireball", 2, SPELL_ROCKET, "tf_projectile_spellfireball", NULL, "Halloween.spell_fireball_cast", 1.f,MP_CONCEPT_PLAYER_CAST_BOMB_HEAD_CURSE, MP_CONCEPT_PLAYER_SPELL_BOMB_HEAD_CURSE, "spellbook_fireball" ),
spell_data_t( "#TF_Spell_Bats", 2, SPELL_JAR, "tf_projectile_spellbats", NULL, "Halloween.spell_bat_cast", 1.f, MP_CONCEPT_PLAYER_CAST_MERASMUS_ZAP, MP_CONCEPT_PLAYER_SPELL_MERASMUS_ZAP, "spellbook_bats" ),
spell_data_t( "#TF_Spell_OverHeal", 1, SPELL_SELF, NULL, CTFSpellBook::CastSelfHeal, "Halloween.spell_overheal", 1.f, MP_CONCEPT_PLAYER_CAST_SELF_HEAL, MP_CONCEPT_PLAYER_SPELL_SELF_HEAL, "spellbook_overheal" ),
spell_data_t( "#TF_Spell_MIRV", 1, SPELL_JAR, "tf_projectile_spellmirv", NULL, "Halloween.spell_mirv_cast", 1.f, MP_CONCEPT_PLAYER_CAST_MIRV, MP_CONCEPT_PLAYER_SPELL_MIRV, "spellbook_mirv" ),
spell_data_t( "#TF_Spell_BlastJump", 2, SPELL_SELF, NULL, CTFSpellBook::CastRocketJump, "Halloween.spell_blastjump", 1.f, MP_CONCEPT_PLAYER_CAST_BLAST_JUMP, MP_CONCEPT_PLAYER_SPELL_BLAST_JUMP, "spellbook_blastjump"),
spell_data_t( "#TF_Spell_Stealth", 1, SPELL_SELF, NULL, CTFSpellBook::CastSelfStealth, "Halloween.spell_stealth", 1.f, MP_CONCEPT_PLAYER_CAST_STEALTH, MP_CONCEPT_PLAYER_SPELL_STEALTH, "spellbook_stealth"),
spell_data_t( "#TF_Spell_Teleport", 2, SPELL_JAR, "tf_projectile_spelltransposeteleport", NULL, "Halloween.spell_teleport", 1.f, MP_CONCEPT_PLAYER_CAST_TELEPORT, MP_CONCEPT_PLAYER_SPELL_TELEPORT, "spellbook_teleport"),
};
static const int g_NavMeshSpells = 2; // Number of spells in this list that require a navmesh, they must be at the end of this array
static const spell_data_t g_RareSpellList[] =
{
spell_data_t( "#TF_Spell_LightningBall", 1, SPELL_ROCKET, "tf_projectile_lightningorb", NULL, "Halloween.spell_lightning_cast", 0.4f, MP_CONCEPT_PLAYER_CAST_LIGHTNING_BALL, MP_CONCEPT_PLAYER_SPELL_LIGHTNING_BALL, "spellbook_lightning"),
spell_data_t( "#TF_Spell_Athletic", 1, SPELL_SELF, NULL, CTFSpellBook::CastSelfSpeedBoost, "Halloween.spell_athletic", 1.f, MP_CONCEPT_PLAYER_CAST_MOVEMENT_BUFF, MP_CONCEPT_PLAYER_SPELL_MOVEMENT_BUFF, "spellbook_athletic"),
spell_data_t( "#TF_Spell_Meteor", 1, SPELL_JAR, "tf_projectile_spellmeteorshower", NULL, "Halloween.spell_meteor_cast", 1.f, MP_CONCEPT_PLAYER_CAST_METEOR_SWARM, MP_CONCEPT_PLAYER_SPELL_METEOR_SWARM, "spellbook_meteor"),
spell_data_t( "#TF_Spell_SpawnBoss", 1, SPELL_JAR, "tf_projectile_spellspawnboss", NULL, "Halloween.Merasmus_Spell", 1.f, MP_CONCEPT_PLAYER_CAST_MONOCULOUS, MP_CONCEPT_PLAYER_SPELL_MONOCULOUS, "spellbook_boss"),
spell_data_t( "#TF_Spell_SkeletonHorde", 1, SPELL_JAR, "tf_projectile_spellspawnhorde", NULL, "Halloween.spell_skeleton_horde_cast", 1.f, MP_CONCEPT_PLAYER_CAST_SKELETON_HORDE, MP_CONCEPT_PLAYER_SPELL_SKELETON_HORDE, "spellbook_skeleton"),
};
static const spell_data_t g_KartSpellList[] =
{
// Kart Spells
spell_data_t( "#TF_Spell_Fireball", 1, SPELL_ROCKET, "tf_projectile_spellkartorb", NULL, "Halloween.spell_fireball_cast", 1.f, MP_CONCEPT_PLAYER_CAST_MERASMUS_ZAP, MP_CONCEPT_PLAYER_SPELL_MERASMUS_ZAP, "../hud/Punchglove_icon" ),
spell_data_t( "#TF_Spell_BlastJump", 1, SPELL_SELF, NULL, CTFSpellBook::CastKartRocketJump, "Halloween.spell_blastjump", 1.f, MP_CONCEPT_PLAYER_CAST_BLAST_JUMP, MP_CONCEPT_PLAYER_SPELL_BLAST_JUMP, "../hud/Parachute_icon"),
spell_data_t( "#TF_Spell_OverHeal", 1, SPELL_SELF, NULL, CTFSpellBook::CastKartUber, "Halloween.spell_overheal", 1.f, MP_CONCEPT_PLAYER_CAST_SELF_HEAL, MP_CONCEPT_PLAYER_SPELL_SELF_HEAL, "spellbook_overheal" ),
spell_data_t( "#TF_Spell_BombHead", 1, SPELL_SELF, NULL, CTFSpellBook::CastKartBombHead, "Halloween.spell_overheal", 1.f, MP_CONCEPT_PLAYER_CAST_FIREBALL, MP_CONCEPT_PLAYER_SPELL_FIREBALL, "../hud/bombhead_icon" ),
};
// Do not allow all spells in doomsday
static const int g_doomsdayNormalSpellIndexList[] =
{
0, //Fireball
0, //Fireball x2
2, //overheal
4, //Jump
5, //Stealth
};
static const int g_doomsdayRareSpellIndexList[] =
{
ARRAYSIZE( g_NormalSpellList ) + 0, // Lightning
ARRAYSIZE( g_NormalSpellList ) + 1, // Mini
ARRAYSIZE( g_NormalSpellList ) + 2, // Meteor
ARRAYSIZE( g_NormalSpellList ) + 0, // Lightning
ARRAYSIZE( g_NormalSpellList ) + 1, // Mini
ARRAYSIZE( g_NormalSpellList ) + 2, // Meteor
ARRAYSIZE( g_NormalSpellList ) + 3 // Boss / Monoculus. Smaller chance
};
// Regular SpellList
// teleport and summons removed
static const int g_generalSpellIndexList[] =
{
0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5,
ARRAYSIZE ( g_NormalSpellList ) + 0,
ARRAYSIZE ( g_NormalSpellList ) + 1,
ARRAYSIZE ( g_NormalSpellList ) + 2
};
int GetTotalSpellCount( CTFPlayer *pPlayer )
{
int iSpellCount = ARRAYSIZE( g_NormalSpellList ) + ARRAYSIZE( g_RareSpellList );
if ( pPlayer && pPlayer->m_Shared.InCond( TF_COND_HALLOWEEN_KART ) )
{
iSpellCount += ARRAYSIZE( g_KartSpellList );
}
return iSpellCount;
}
bool IsRareSpell( int iSpellIndex )
{
if ( tf_test_spellindex.GetInt() > 0 )
{
iSpellIndex = tf_test_spellindex.GetInt();
}
return ( ( iSpellIndex >= ARRAYSIZE( g_NormalSpellList ) ) && ( iSpellIndex < ARRAYSIZE( g_NormalSpellList ) + ARRAYSIZE( g_RareSpellList ) ) );
}
const spell_data_t* GetSpellData( int iSpellIndex )
{
if ( tf_test_spellindex.GetInt() > -1 )
{
iSpellIndex = tf_test_spellindex.GetInt();
}
if ( iSpellIndex < 0 )
return NULL;
const int nNormalSpellCount = ARRAYSIZE( g_NormalSpellList );
if ( iSpellIndex < nNormalSpellCount )
return &g_NormalSpellList[ iSpellIndex ];
const int nRareSpellRange = nNormalSpellCount + ARRAYSIZE( g_RareSpellList );
if ( iSpellIndex < nRareSpellRange )
return &g_RareSpellList[ iSpellIndex - nNormalSpellCount ];
const int nKartSpellRange = nRareSpellRange + ARRAYSIZE( g_KartSpellList );
if ( iSpellIndex < nKartSpellRange )
return &g_KartSpellList[ iSpellIndex - nRareSpellRange];
return NULL;
}
int GetSpellIndexFromContext( int iContext )
{
const int nNormalSpellCount = ARRAYSIZE( g_NormalSpellList );
for ( int i=0; i<nNormalSpellCount; ++i )
{
if ( g_NormalSpellList[i].m_iSpellContext == iContext )
{
return i;
}
}
const int nRareSpellCount = ARRAYSIZE( g_RareSpellList );
for ( int i=0; i<nRareSpellCount; ++i )
{
if ( g_RareSpellList[i].m_iSpellContext == iContext )
{
return i + nNormalSpellCount;
}
}
return -1;
}
//=============================================================================
#ifdef CLIENT_DLL
//=============================================================================
// Ui Hud
//=============================================================================
extern ConVar cl_hud_minmode;
DECLARE_HUDELEMENT_DEPTH( CHudSpellMenu, 2 );
CHudSpellMenu::CHudSpellMenu( const char *pElementName ) : CHudElement( pElementName ), BaseClass ( NULL, "HudSpellMenu" )
{
Panel *pParent = g_pClientMode->GetViewport();
SetParent( pParent );
SetHiddenBits( HIDEHUD_MISCSTATUS | HIDEHUD_HEALTH | HIDEHUD_PLAYERDEAD );
m_iNextRollTime = 0;
m_flRollTickGap = 0.05f;
m_bTickSoundA = false;
m_bKillstreakMeterDrawing = false;
m_pSpellIcon = new vgui::ImagePanel( this, "SpellIcon" );
m_pKeyBinding = new CExLabel( this, "ActionText", "" );
ListenForGameEvent( "inventory_updated" );
ListenForGameEvent( "localplayer_respawn" );
ListenForGameEvent( "localplayer_changeclass" );
ListenForGameEvent( "post_inventory_application" );
}
//-----------------------------------------------------------------------------
void CHudSpellMenu::ApplySchemeSettings( vgui::IScheme *pScheme )
{
BaseClass::ApplySchemeSettings( pScheme );
KeyValues *pConditions = NULL;
if ( m_bKillstreakMeterDrawing )
{
pConditions = new KeyValues( "conditions" );
if ( pConditions )
{
AddSubKeyNamed( pConditions, "if_killstreak_visible" );
}
}
// load control settings...
LoadControlSettings( "resource/UI/HudSpellSelection.res", NULL, NULL, pConditions );
SetVisible( false );
UpdateSpellText( -1, -1 );
if ( pConditions )
{
pConditions->deleteThis();
}
}
//=============================================================================
void CHudSpellMenu::OnTick( void )
{
bool bKillstreakMeterDrawing = false;
CHudItemEffectMeter *pMeter = NULL;
for ( int i = 0; i < IHudItemEffectMeterAutoList::AutoList().Count(); ++i )
{
pMeter = static_cast<CHudItemEffectMeter*>( IHudItemEffectMeterAutoList::AutoList()[i] );
if ( pMeter->IsKillstreakMeter() ) // we found the killstreak meter
{
if ( pMeter->IsEnabled() )
{
bKillstreakMeterDrawing = true;
}
break;
}
}
if ( m_bKillstreakMeterDrawing != bKillstreakMeterDrawing )
{
m_bKillstreakMeterDrawing = bKillstreakMeterDrawing;
InvalidateLayout( false, true );
}
vgui::ivgui()->RemoveTickSignal( GetVPanel() );
}
//=============================================================================
void CHudSpellMenu::FireGameEvent( IGameEvent * event )
{
if ( FStrEq( event->GetName(), "post_inventory_application" ) ||
FStrEq( event->GetName(), "localplayer_respawn" ) ||
FStrEq( event->GetName(), "localplayer_changeclass" ) ||
FStrEq( event->GetName(), "inventory_updated" ) )
{
vgui::ivgui()->AddTickSignal( GetVPanel(), 10 );
}
}
//=============================================================================
bool CHudSpellMenu::ShouldDraw( void )
{
if ( TFGameRules() && TFGameRules()->IsUsingSpells() )
{
if ( CTFMinigameLogic::GetMinigameLogic() && CTFMinigameLogic::GetMinigameLogic()->GetActiveMinigame() && ( TFGameRules()->State_Get() != GR_STATE_RND_RUNNING ) )
return false;
C_TFPlayer *pPlayer = C_TFPlayer::GetLocalTFPlayer();
if ( pPlayer && pPlayer->IsAlive() && !pPlayer->m_Shared.InCond( TF_COND_HALLOWEEN_GHOST_MODE ) )
{
CTFSpellBook *pSpellBook = dynamic_cast<CTFSpellBook*>( pPlayer->GetEntityForLoadoutSlot( LOADOUT_POSITION_ACTION ) );
if ( pSpellBook )
{
UpdateSpellText( pSpellBook->m_iSelectedSpellIndex, pSpellBook->m_iSpellCharges );
return CHudElement::ShouldDraw();
}
}
}
return false;
}
//=============================================================================
void CHudSpellMenu::UpdateSpellText( int iSpellIndex, int iChargeCount )
{
if ( iSpellIndex == SPELL_EMPTY || ( iChargeCount <= 0 && iSpellIndex != SPELL_UNKNOWN ) )
{
SetDialogVariable( "counttext", "..." );
//SetDialogVariable( "selectedspell", g_pVGuiLocalize->Find( pSpellData->m_pSpellUiName ) );
m_pSpellIcon->SetImage( "spellbook_nospell" );
m_flRollTickGap = 0.01f;
m_iNextRollTime = 0;
m_pKeyBinding->SetVisible( false );
return;
}
m_pSpellIcon->SetVisible( true );
C_TFPlayer *pLocalPlayer = C_TFPlayer::GetLocalTFPlayer();
if ( !pLocalPlayer )
return;
static wchar_t wLabel[256];
if ( iSpellIndex == SPELL_UNKNOWN )
{
if ( m_iNextRollTime > gpGlobals->curtime )
return;
m_iNextRollTime = gpGlobals->curtime + m_flRollTickGap;
m_flRollTickGap += 0.015f;
static int s_iRandSpell = 0;
s_iRandSpell = ( s_iRandSpell + 1 ) % GetTotalSpellCount( pLocalPlayer );
const spell_data_t *pSpellData = GetSpellData( s_iRandSpell );
SetDialogVariable( "counttext", "?" );
m_pSpellIcon->SetImage( pSpellData->m_pIconName );
pLocalPlayer->EmitSound( m_bTickSoundA ? "Halloween.spelltick_a" : "Halloween.spelltick_b" );
m_bTickSoundA = !m_bTickSoundA;
m_iPrevSelectedSpell = SPELL_UNKNOWN;
m_pKeyBinding->SetVisible( false );
}
else
{
m_flRollTickGap = 0.01f;
m_iNextRollTime = 0;
const spell_data_t *pSpellData = GetSpellData( iSpellIndex );
if ( pSpellData )
{
SetDialogVariable( "counttext", iChargeCount );
m_pSpellIcon->SetImage( pSpellData->m_pIconName );
if ( m_iPrevSelectedSpell != iSpellIndex && iSpellIndex != SPELL_EMPTY )
{
pLocalPlayer->EmitSound( "Halloween.spelltick_set" );
}
m_iPrevSelectedSpell = iSpellIndex;
m_pKeyBinding->SetVisible( !cl_hud_minmode.GetBool() );
// Action Key Text
wchar_t wKeyReplaced[256];
UTIL_ReplaceKeyBindings( g_pVGuiLocalize->Find( "#TF_Spell_Action" ), 0, wKeyReplaced, sizeof( wKeyReplaced ) );
SetDialogVariable( "actiontext", wKeyReplaced );
}
}
}
//-----------------------------------------------------------------------------
// CEquipSpellbookNotification
//-----------------------------------------------------------------------------
void CEquipSpellbookNotification::Accept()
{
m_bHasTriggered = true;
CPlayerInventory *pLocalInv = TFInventoryManager()->GetLocalInventory();
if ( !pLocalInv )
{
MarkForDeletion();
return;
}
C_TFPlayer *pLocalPlayer = C_TFPlayer::GetLocalTFPlayer();
if ( !pLocalPlayer )
{
MarkForDeletion();
return;
}
// try to equip non-stock-spellbook first
static CSchemaItemDefHandle pItemDef_Spellbook( "Basic Spellbook" );
static CSchemaItemDefHandle pItemDef_Diary( "Secret Diary" );
static CSchemaItemDefHandle pItemDef_FancySpellbook( "Halloween Spellbook" );
Assert( pItemDef_Spellbook );
Assert( pItemDef_Diary );
Assert( pItemDef_FancySpellbook );
CEconItemView *pSpellBook = NULL;
if ( pItemDef_Spellbook && pItemDef_Diary && pItemDef_FancySpellbook )
{
for ( int i = 0 ; i < pLocalInv->GetItemCount() ; ++i )
{
CEconItemView *pItem = pLocalInv->GetItem( i );
Assert( pItem );
if ( pItem->GetItemDefinition() == pItemDef_Spellbook
|| pItem->GetItemDefinition() == pItemDef_Diary
|| pItem->GetItemDefinition() == pItemDef_FancySpellbook
) {
pSpellBook = pItem;
break;
}
}
}
// Default item becomes a spellbook in this mode
itemid_t iItemId = INVALID_ITEM_ID;
if ( pSpellBook )
{
iItemId = pSpellBook->GetItemID();
}
TFInventoryManager()->EquipItemInLoadout( pLocalPlayer->GetPlayerClass()->GetClassIndex(), LOADOUT_POSITION_ACTION, iItemId );
// Tell the GC to tell server that we should respawn if we're in a respawn room
MarkForDeletion();
}
//===========================================================================================
void CEquipSpellbookNotification::UpdateTick()
{
C_TFPlayer *pLocalPlayer = C_TFPlayer::GetLocalTFPlayer();
if ( pLocalPlayer )
{
CTFSpellBook *pSpellBook = dynamic_cast<CTFSpellBook*>( pLocalPlayer->Weapon_OwnsThisID( TF_WEAPON_SPELLBOOK ) );
if ( pSpellBook )
{
MarkForDeletion();
}
}
}
#endif // CLIENT_DLL
//===========================================================================================
//
// CTFSpellBook
//
//===========================================================================================
CTFSpellBook::CTFSpellBook()
{
m_iSelectedSpellIndex = -1;
m_iSpellCharges = 0;
m_flTimeNextSpell = 0;
m_bFiredAttack = false;
#ifdef CLIENT_DLL
m_flTimeNextErrorSound = 0;
m_hHandEffect = NULL;
m_hHandEffectWeapon = NULL;
#endif // CLIENT_DLL
#ifdef GAME_DLL
m_pStoredLastWpn = NULL;
m_iPreviouslyCastSpell = -1;
#endif // GAME_DLL
}
void CTFSpellBook::Precache()
{
PrecacheScriptSound( "Halloween.Merasmus_Spell" );
PrecacheScriptSound( "Weapon_SniperRailgun_Large.SingleCrit" );
PrecacheScriptSound( "Halloween.spelltick_a" );
PrecacheScriptSound( "Halloween.spelltick_b" );
PrecacheScriptSound( "Halloween.spelltick_set" );
PrecacheScriptSound( "Halloween.spell_athletic" );
PrecacheScriptSound( "Halloween.spell_bat_cast" );
PrecacheScriptSound( "Halloween.spell_bat_impact" );
PrecacheScriptSound( "Halloween.spell_blastjump" );
PrecacheScriptSound( "Halloween.spell_fireball_cast" );
PrecacheScriptSound( "Halloween.spell_fireball_impact" );
PrecacheScriptSound( "Halloween.spell_lightning_cast" );
PrecacheScriptSound( "Halloween.spell_lightning_impact" );
PrecacheScriptSound( "Halloween.spell_meteor_cast" );
PrecacheScriptSound( "Halloween.spell_meteor_impact" );
PrecacheScriptSound( "Halloween.spell_mirv_cast" );
PrecacheScriptSound( "Halloween.spell_mirv_explode_primary" );
PrecacheScriptSound( "Halloween.spell_mirv_explode_secondary" );
PrecacheScriptSound( "Halloween.spell_skeleton_horde_cast" );
PrecacheScriptSound( "Halloween.spell_skeleton_horde_rise" );
PrecacheScriptSound( "Halloween.spell_spawn_boss" );
PrecacheScriptSound( "Halloween.spell_stealth" );
PrecacheScriptSound( "Halloween.spell_teleport" );
PrecacheScriptSound( "Halloween.spell_overheal" );
PrecacheParticleSystem( "merasmus_zap" );
PrecacheParticleSystem( "spell_cast_wheel_red" );
PrecacheParticleSystem( "spell_cast_wheel_blue" );
PrecacheParticleSystem( "Explosion_bubbles" );
PrecacheParticleSystem( "ExplosionCore_buildings" );
PrecacheParticleSystem( "water_splash01" );
PrecacheParticleSystem( "healshot_trail_blue" );
PrecacheParticleSystem( "healshot_trail_red" );
PrecacheParticleSystem( "xms_snowburst" );
PrecacheParticleSystem( "bomibomicon_ring" );
PrecacheParticleSystem( "bombinomicon_burningdebris" );
PrecacheParticleSystem( "merasmus_tp_bits" );
PrecacheParticleSystem( "spell_fireball_tendril_parent_red" );
PrecacheParticleSystem( "spell_fireball_tendril_parent_blue" );
PrecacheParticleSystem( "spell_fireball_small_blue" );
PrecacheParticleSystem( "spell_fireball_small_red" );
PrecacheParticleSystem( "spell_lightningball_parent_blue" );
PrecacheParticleSystem( "spell_lightningball_parent_red" );
PrecacheParticleSystem( "spell_lightningball_hit_blue" );
PrecacheParticleSystem( "spell_lightningball_hit_red" );
PrecacheParticleSystem( "eyeboss_tp_vortex" );
PrecacheParticleSystem( "spell_overheal_red" );
PrecacheParticleSystem( "spell_overheal_blue" );
PrecacheParticleSystem( "spell_teleport_red" );
PrecacheParticleSystem( "spell_teleport_blue" );
PrecacheParticleSystem( "spell_batball_red" );
PrecacheParticleSystem( "spell_batball_blue" );
PrecacheParticleSystem( "spell_batball_throw_red" );
PrecacheParticleSystem( "spell_batball_throw_blue" );
PrecacheParticleSystem( "spell_batball_impact_red" );
PrecacheParticleSystem( "spell_batball_impact_blue" );
PrecacheParticleSystem( "spell_pumpkin_mirv_goop_red" );
PrecacheParticleSystem( "spell_pumpkin_mirv_goop_blue" );
PrecacheParticleSystem( "spell_skeleton_goop_green" );
PrecacheParticleSystem( "spellbook_rainbow" );
PrecacheParticleSystem( "spellbook_major_burning" );
PrecacheParticleSystem( "spellbook_minor_burning" );
PrecacheModel( "models/props_mvm/mvm_human_skull_collide.mdl" );
PrecacheModel( "models/props_lakeside_event/bomb_temp_hat.mdl" );
PrecacheModel( SPELL_BOXING_GLOVE );
PrecacheModel( "models/props_halloween/bombonomicon.mdl" ); // bomb head spell
PrecacheParticleSystem( "halloween_rockettrail" );
PrecacheParticleSystem( "ExplosionCore_MidAir" );
#ifdef GAME_DLL
CEyeballBoss::PrecacheEyeballBoss();
CZombie::PrecacheZombie();
#endif // GAME_DLL
BaseClass::Precache();
}
//-----------------------------------------------------------------------------
void CTFSpellBook::PrimaryAttack()
{
// cast spell
if ( m_flTimeNextSpell > gpGlobals->curtime )
return;
CTFPlayer *pPlayer = GetTFPlayerOwner();
if ( !pPlayer )
return;
bool bCastSuccessful = false;
bCastSuccessful = CanCastSpell( pPlayer );
if ( bCastSuccessful )
{
#ifdef GAME_DLL
SpeakSpellConceptIfAllowed();
// We need to do this before PrimaryAttack so we use the right spell index
if ( pPlayer->m_Shared.InCond( TF_COND_HALLOWEEN_KART ) )
{
CastKartSpell();
pPlayer->DoAnimationEvent( PLAYERANIMEVENT_CUSTOM_GESTURE, ACT_KART_ACTION_SHOOT );
}
else
{
CastSpell( pPlayer, m_iSelectedSpellIndex );
BaseClass::PrimaryAttack();
}
#endif
#ifdef GAME_DLL
// set a default time cast time if none added
if ( m_flTimeNextSpell < gpGlobals->curtime )
{
m_flTimeNextSpell = gpGlobals->curtime + 0.5f;
}
#endif // GAME_DLL
}
#ifdef CLIENT_DLL
else
{
if ( m_flTimeNextErrorSound < gpGlobals->curtime )
{
m_flTimeNextErrorSound = gpGlobals->curtime + 0.5f;
pPlayer->EmitSound( "Player.DenyWeaponSelection" );
}
}
#endif // CLIENT_DLL
}
//-----------------------------------------------------------------------------
void CTFSpellBook::ItemBusyFrame( void )
{
#ifdef CLIENT_DLL
if ( m_hHandEffectWeapon && m_hHandEffect )
return;
CTFPlayer *pPlayer = GetTFPlayerOwner();
if ( !pPlayer )
return;
if ( IsFirstPersonView() )
{
m_hHandEffectWeapon = pPlayer->GetViewModel();
}
else
{
m_hHandEffectWeapon = pPlayer;
}
if ( !m_hHandEffectWeapon )
return;
if ( UsingViewModel() && !g_pClientMode->ShouldDrawViewModel() )
{
// Prevent effects when the ViewModel is hidden with r_drawviewmodel=0
return;
}
C_BaseAnimating* pBase = (C_BaseAnimating*)m_hHandEffectWeapon.Get();
int iAttachment = pBase->C_BaseAnimating::LookupAttachment( "effect_hand_R" );
// Start the muzzle flash, if a system hasn't already been started.
if ( iAttachment > 0 )
{
const char *pszEffectName = GetHandEffect( GetAttributeContainer()->GetItem(), m_iSelectedSpellIndex >= ARRAYSIZE( g_NormalSpellList ) );
if ( pszEffectName )
{
m_hHandEffect = pBase->ParticleProp()->Create( pszEffectName, PATTACH_POINT_FOLLOW, iAttachment );
}
}
else
{
if ( m_hHandEffect )
{
m_hHandEffectWeapon->ParticleProp()->StopEmission( m_hHandEffect );
m_hHandEffectWeapon = NULL;
m_hHandEffect = NULL;
}
}
#endif
}
//-----------------------------------------------------------------------------
void CTFSpellBook::ItemHolsterFrame( void )
{
#ifdef CLIENT_DLL
if ( !m_hHandEffectWeapon )
return;
// Stop the muzzle flash.
if ( m_hHandEffect )
{
m_hHandEffectWeapon->ParticleProp()->StopEmission( m_hHandEffect );
m_hHandEffectWeapon = NULL;
m_hHandEffect = NULL;
}
#endif
#ifdef GAME_DLL
m_bFiredAttack = false;
#endif
}
//-----------------------------------------------------------------------------
void CTFSpellBook::ItemPostFrame( void )
{
BaseClass::ItemPostFrame();
#ifdef CLIENT_DLL
// attempt to attack then switch back
if ( !m_bFiredAttack && m_iSpellCharges > 0 )
{
PrimaryAttack();
if ( m_hHandEffect )
{
m_hHandEffectWeapon->ParticleProp()->StopEmission( m_hHandEffect );
m_hHandEffectWeapon = NULL;
m_hHandEffect = NULL;
}
}
#endif
#ifdef GAME_DLL
if ( tf_test_spellindex.GetInt() > -1 )
{
SetSelectedSpell( tf_test_spellindex.GetInt() );
}
// attempt to attack then switch back
if ( !m_bFiredAttack && m_iSpellCharges > 0 )
{
PrimaryAttack();
m_bFiredAttack = true;
}
else
{
if ( m_flTimeNextSpell > gpGlobals->curtime )
return;
CTFPlayer *pPlayer = GetTFPlayerOwner();
if ( !pPlayer )
return;
if ( pPlayer->Weapon_Switch( pPlayer->GetLastWeapon() ) )
{
if ( m_pStoredLastWpn != NULL && pPlayer->Weapon_CanSwitchTo( m_pStoredLastWpn.Get() ) )
{
pPlayer->Weapon_SetLast( m_pStoredLastWpn.Get() );
m_pStoredLastWpn = NULL;
}
else
{
pPlayer->Weapon_SetLast( NULL );
}
m_bFiredAttack = false;
}
}
#endif //GAME_DLL
}
//-----------------------------------------------------------------------------
/* static */ const char* CTFSpellBook::GetHandEffect( CEconItemView *pItem, int iTier )
{
// if fancy spellbook //1069
int defIndex = pItem->GetItemDefIndex();
if ( defIndex == 1069 )
{
if ( iTier > 0 )
{
return "spellbook_major_burning";
}
else
{
return "spellbook_minor_burning";
}
}
else if ( defIndex == 5605 ) // secret diary
{
return "spellbook_rainbow";
}
else // else Basic SpellBook
{
if ( iTier > 0 )
{
return "spellbook_major_fire";
}
else
{
return "spellbook_minor_fire";
}
}
}
//-----------------------------------------------------------------------------
bool CTFSpellBook::HasASpellWithCharges()
{
return tf_test_spellindex.GetInt() > -1 || m_iSpellCharges > 0 || m_iSelectedSpellIndex == SPELL_UNKNOWN;
}
//-----------------------------------------------------------------------------
bool CTFSpellBook::CanCastSpell( CTFPlayer *pPlayer )
{
if ( !pPlayer->m_Shared.InCond( TF_COND_HALLOWEEN_KART) && !pPlayer->CanAttack() )
return false;
if ( pPlayer->m_Shared.InCond( TF_COND_HALLOWEEN_THRILLER ) )
return false;
if ( tf_test_spellindex.GetInt() > -1 && tf_test_spellindex.GetInt() < GetTotalSpellCount( pPlayer ) )
return true;
return m_iSpellCharges > 0 && m_iSelectedSpellIndex >= 0 && m_iSelectedSpellIndex < GetTotalSpellCount( pPlayer );
}
//-----------------------------------------------------------------------------
void CTFSpellBook::PaySpellCost( CTFPlayer *pPlayer )
{
m_iSpellCharges--;
}
//-----------------------------------------------------------------------------
void CTFSpellBook::ClearSpell()
{
m_iSpellCharges = 0;
#ifdef GAME_DLL
// If rolling for a spell, clear that too
m_iNextSpell = SPELL_EMPTY;
#endif // GAME_DLL
}
//-----------------------------------------------------------------------------
CBaseEntity *CTFSpellBook::FireJar( CTFPlayer *pPlayer )
{
#ifdef GAME_DLL
if ( pPlayer->m_Shared.InCond( TF_COND_HALLOWEEN_KART ) )
{
TossJarThink();
}
else
{
SetContextThink( &CTFJar::TossJarThink, gpGlobals->curtime + 0.01f, "TOSS_JAR_THINK" );
}
#endif
return NULL;
}
#ifdef GAME_DLL
//-----------------------------------------------------------------------------
void CTFSpellBook::TossJarThink( void )
{
CTFPlayer *pPlayer = GetTFPlayerOwner();
if ( !pPlayer )
return;
// Self casts
const spell_data_t *pSpellData = GetSpellData( m_iPreviouslyCastSpell );
if ( !pSpellData )
return;
if ( pSpellData->m_eSpellType == SPELL_SELF )
{
// Self casts
if ( TFGameRules() )
{
TFGameRules()->HaveAllPlayersSpeakConceptIfAllowed( pSpellData->m_iSpellContext, ( pPlayer->GetTeamNumber() == TF_TEAM_RED ) ? TF_TEAM_BLUE : TF_TEAM_RED );
}
// Play a sound immediately for self-cast spells
EmitSound( pSpellData->m_pszCastSound );
pSpellData->m_pCastSpell( pPlayer );
return;
}
Vector vecForward, vecRight, vecUp;
AngleVectors( pPlayer->EyeAngles(), &vecForward, &vecRight, &vecUp );
float fRight = 7.f;
if ( IsViewModelFlipped() )
{
fRight *= -1;
}
Vector vecSrc = pPlayer->Weapon_ShootPosition();
// Make spell toss position at the hand
vecSrc = vecSrc + ( vecUp * -9.0f ) + ( vecRight * fRight ) + ( vecForward * 3.0f );
Vector vecVelocity = GetVelocityVector( vecForward, vecRight, vecUp ) * pSpellData->m_flSpeedScale;
QAngle angForward = pPlayer->EyeAngles();
// Halloween Hack
// Eye Angles slighty higher
if ( pPlayer->m_Shared.InCond( TF_COND_HALLOWEEN_KART ) )
{
// Add More up for Jar
angForward = pPlayer->GetAbsAngles();
if ( pSpellData->m_eSpellType == SPELL_JAR )
{
angForward.x -= 10.0f;
}
AngleVectors( angForward, &vecForward, &vecRight, &vecUp );
vecVelocity = vecForward * tf_halloween_kart_rocketspell_speed.GetFloat();
}
trace_t trace;
Vector vecEye = pPlayer->EyePosition();
CTraceFilterSimple traceFilter( this, COLLISION_GROUP_NONE );
UTIL_TraceHull( vecEye, vecSrc, -Vector(8,8,8), Vector(8,8,8), MASK_SOLID_BRUSHONLY, &traceFilter, &trace );
// If we started in solid, don't let them fire at all
if ( trace.startsolid )
return;
// Play a sound when we actually cast the projectile
EmitSound( pSpellData->m_pszCastSound );
switch ( pSpellData->m_eSpellType )
{
case SPELL_ROCKET :
{
//QAngle angForward;
//GetProjectileFireSetup( pPlayer, Vector(0,0,0), &vecSrc, &angForward, false );
CreateSpellRocket( trace.endpos, angForward, vecVelocity, GetAngularImpulse(), pPlayer, GetTFWpnData() );
}
break;
case SPELL_JAR :
{
CreateSpellJar( trace.endpos, angForward, vecVelocity, GetAngularImpulse(), pPlayer, GetTFWpnData() );
}
break;
case SPELL_SELF :
break;
}
}
//-----------------------------------------------------------------------------