aboutsummaryrefslogtreecommitdiff
path: root/Northstar.CustomServers/mod/scripts/vscripts/weapons/sh_phase_shift.gnut
blob: 52d07f00fb38fbde97fe21b0ad39844b77114b58 (plain)
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
untyped
#if CLIENT
#endif

global function MpAbilityShifter_Init
global function PhaseShift
global function CodeCallback_EnterPhaseShift
global function CodeCallback_ExitPhaseShift
global function CancelPhaseShift

#if SERVER
global function PlayPhaseShiftDisappearFX
global function UntrackAllToneMarks
#endif

const SHIFTER_OUTRO_TIME_BEFORE_END = 1.5

const SHIFTER_PRE_FX = $"P_warpjump_FP"

const SHIFTER_APPEAR_FX = $"P_phase_shift_main"
const SHIFTER_APPEAR_FX_TITAN = $"P_phase_shift_main_XO"
const SHIFTER_DISAPPEAR_FX = $"P_phase_shift_main"
const SHIFTER_DISAPPEAR_FX_TITAN = $"P_phase_shift_main_XO"

const SHIFTER_SCREEN_FX = $"P_phase_shift_screen"
const SHIFTER_PERSONAL_FX = $"P_phase_shift_player"
const SHIFTER_SCREEN_FX_START = $"P_phase_shift_screen_start"
const SHIFTER_COLORCORRECTION = "materials/correction/mp_ability_shifter.raw"

const SHIFTER_PRE_SOUND_1P = "Pilot_PhaseShift_PreActivate_1P"
const SHIFTER_PRE_SOUND_3P = "Pilot_PhaseShift_PreActivate_3P"
global const SHIFTER_START_SOUND_1P = "Pilot_PhaseShift_Activate_1P"
global const SHIFTER_START_SOUND_3P = "Pilot_PhaseShift_Activate_3P"
const SHIFTER_LOOP_SOUND_1P = "Pilot_PhaseShift_Loop_1P"
const SHIFTER_LOOP_SOUND_3P = "Pilot_PhaseShift_Loop_3P"
const SHIFTER_PRE_END_SOUND_1P = "Pilot_PhaseShift_WarningToEnd_1P"
const SHIFTER_PRE_END_SOUND_3P = "Pilot_PhaseShift_WarningToEnd_3P"
global const SHIFTER_END_SOUND_1P = "Pilot_PhaseShift_End_1P"
global const SHIFTER_END_SOUND_3P = "Pilot_PhaseShift_End_3P"

const SHIFTER_PRE_SOUND_1P_TITAN = "Pilot_PhaseShift_PreActivate_1P"
const SHIFTER_PRE_SOUND_3P_TITAN = "Pilot_PhaseShift_PreActivate_3P"
global const SHIFTER_START_SOUND_1P_TITAN = "titan_phasedash_activate_1p"
global const SHIFTER_START_SOUND_3P_TITAN = "titan_phasedash_activate_3p"
const SHIFTER_LOOP_SOUND_1P_TITAN = "titan_phasedash_loop_1p"
const SHIFTER_LOOP_SOUND_3P_TITAN = "titan_phasedash_loop_3p"
const SHIFTER_PRE_END_SOUND_1P_TITAN = "titan_phasedash_warningtoend_1p"
const SHIFTER_PRE_END_SOUND_3P_TITAN = "titan_phasedash_warningtoend_3p"
global const SHIFTER_END_SOUND_1P_TITAN = "titan_phasedash_end_1p"
global const SHIFTER_END_SOUND_3P_TITAN = "titan_phasedash_end_3p"

const int TELEFRAG_DAMAGE = 5000;

struct
{
} file;

void function CodeCallback_EnterPhaseShift( entity ent )
{
	PhaseShift( ent, 0.0, 999.0 )
}

void function CodeCallback_ExitPhaseShift( entity ent )
{
#if SERVER
	CancelPhaseShift( ent )
#endif
}

void function CancelPhaseShift( entity ent )
{
	ent.PhaseShiftCancel()

#if SERVER
	ent.Signal( "ForceStopPhaseShift" )
	PlayPhaseShiftAppearFX( ent )
#endif //
}


void function MpAbilityShifter_Init()
{
#if CLIENT
	//ColorCorrection_RegisterRemoteTurret( "materials/correction/remote_turret.raw" )

	ColorCorrection_RegisterPhaseShift( SHIFTER_COLORCORRECTION )
	thread ClientPhaseShiftFirstPersonFXThread()

	thread ClientRemoteTurretFirstPersonFXThread()
#endif // #if CLIENT

	PrecacheParticleSystem( SHIFTER_PRE_FX )
	PrecacheParticleSystem( SHIFTER_APPEAR_FX )
	PrecacheParticleSystem( SHIFTER_APPEAR_FX_TITAN )
	PrecacheParticleSystem( SHIFTER_DISAPPEAR_FX )
	PrecacheParticleSystem( SHIFTER_DISAPPEAR_FX_TITAN )
	PrecacheParticleSystem( SHIFTER_PERSONAL_FX )
	PrecacheParticleSystem( SHIFTER_SCREEN_FX )
	PrecacheParticleSystem( SHIFTER_SCREEN_FX_START )

	MpAbilityShifterWeapon_Init()

	RegisterSignal( "StartPhaseShift" )
	RegisterSignal( "StopPhaseShift" )
	RegisterSignal( "ForceStopPhaseShift" )
}

int function PhaseShift( entity ent, float warmupTime, float duration )
{
	if ( !IsAlive( ent ) )
		return 0

	if ( ent.IsPhaseShifted() )
		return 0

	// PROTO: this should be better eventually
	// this is to prevent weirdness if you're already in a context action
	if ( ent.IsPlayer() )
	{
		entity proxy = ent.GetFirstPersonProxy()
		if ( ( ent.ContextAction_IsActive() || (proxy != null && proxy.Anim_IsActive()) )
			&& !ent.IsZiplining()
			&& !ent.ContextAction_IsLeeching()
			&& ent.GetTitanSoulBeingRodeoed() == null )
		{
			return 0
		}

		ent.PhaseShiftBegin( warmupTime, duration )

		#if SERVER
			thread ServerPhaseShiftPlayerThread( ent, warmupTime, duration )
		#else
			thread ClientPhaseShiftWarmupThread( ent, warmupTime )
		#endif // #if SERVER

		return 1
	}
	else
	{
		ent.PhaseShiftBegin( warmupTime, duration )

		#if SERVER
			thread ServerPhaseShiftPlayerThread( ent, warmupTime, duration )
		#endif // #if SERVER

		return 1
	}

	unreachable
}

#if SERVER
void function ServerPhaseShiftPlayerThread( entity ent, float warmupTime, float shiftTime )
{
	ent.EndSignal( "OnDeath" )
	ent.EndSignal( "ForceStopPhaseShift" )

	// initialise the two ent.s variables if needed
	if ( !( "oldPhaseStateLock" in ent.s ) || !( "oldPhaseState" in ent.s ) )
	{
		ent.s.oldPhaseStateLock <- false
		ent.s.oldPhaseState <- false
	}		

	bool keepAnimActive = false

	if ( ent.IsPlayer() )
	{
		ent.EndSignal( "player_embarks_titan" )

		Leech_Disallow( ent )
	//	EmitSoundOnEntityExceptToPlayer( ent, ent, SHIFTER_PRE_SOUND_3P )

		entity proxy = ent.GetFirstPersonProxy()
		if ( proxy != null )
			proxy.SetForceVisibleInPhaseShift( true )

		if ( Rodeo_IsAttached( ent ) )
		{
			if ( ent.GetParent() != null && ent.GetParent().IsPhaseShifted() )
				keepAnimActive = true
			else
				ent.Signal( "RodeoOver" )
		}

		if ( ent.IsTitan() )
		{
			UntrackAllToneMarks( ent )
			entity titanSoul = ent.GetTitanSoul()
			if ( titanSoul != null )
			{
				if ( titanSoul.soul.batteryContainer != null )
				{
					titanSoul.soul.batteryContainer.SetForceVisibleInPhaseShift( true )
				}
			}
		}

		Battery_StopFXAndHideIconForPlayer( ent )
	}
	else
	{
		if ( ent.IsTitan() )
			UntrackAllToneMarks( ent )
		ent.EnableNPCFlag( NPC_IGNORE_ALL )
		EmitSoundOnEntity( ent, SHIFTER_PRE_SOUND_3P )
	}

	// only change the oldPhaseState if it's not locked
	if ( !ent.s.oldPhaseStateLock || !GetConVarBool("ns_use_phase_fix") )
	{
		ent.s.oldPhaseStateLock <- true
		ent.s.oldPhaseState <- ent.GetNoTarget()
	}

	OnThreadEnd(
		function() : ( ent )
		{
			if ( IsValid( ent ) )
			{
				ent.Signal( "StopPhaseShift" )
				ent.Solid()
				ent.SetNoTarget( ent.s.oldPhaseState )
				// unlock the oldPhaseState
				ent.s.oldPhaseStateLock <- false

				StopSoundOnEntity( ent, SHIFTER_PRE_SOUND_3P )
				StopSoundOnEntity( ent, SHIFTER_LOOP_SOUND_3P )
				StopSoundOnEntity( ent, SHIFTER_PRE_SOUND_3P_TITAN )
				StopSoundOnEntity( ent, SHIFTER_LOOP_SOUND_3P_TITAN )

				ent.DisablePhaseShiftFlags()

				if ( ent.IsPlayer() )
				{
					Leech_Allow( ent )
					UpdatePlayerHighlightsSettings( ent )

					if ( GetSoulFromPlayer( ent ) != null )
					{
						entity soul = GetSoulFromPlayer( ent )
						if ( soul.soul.batteryContainer != null )
						{
							soul.soul.batteryContainer.SetForceVisibleInPhaseShift( false )
						}
					}

					entity proxy = ent.GetFirstPersonProxy()
					if ( proxy != null )
						proxy.SetForceVisibleInPhaseShift( false )

					if ( PlayerHasBattery( ent ) )
						Battery_StartFX( GetBatteryOnBack( ent ) )
				}
				else
				{
					ent.DisableNPCFlag( NPC_IGNORE_ALL )
					Highlight_ClearEnemyHighlight( ent )
				}

				entity teleFragTarget = ent.GetEntityAtPhaseShiftExitPosition();
				if ( IsValid( teleFragTarget ) )
				{
					if ( !IsHumanSized( teleFragTarget ) )
					{
						if ( ShouldEntitySelfKill( ent, teleFragTarget ) )
						{
							ent.TakeDamage( ent.GetHealth() + 1, teleFragTarget, teleFragTarget, { damageSourceId = eDamageSourceId.phase_shift, scriptType = DF_GIB | DF_BYPASS_SHIELD | DF_SKIPS_DOOMED_STATE } );
						}
						else
						{
							printt( "Pushed players apart" )
							PushPlayersApart( teleFragTarget, ent, 600.0 ) // this will work for NPCs too
						}
					}
					else
					{
						teleFragTarget.TakeDamage( teleFragTarget.GetHealth() + 1, ent, ent, { damageSourceId = eDamageSourceId.phase_shift, scriptType = DF_GIB | DF_BYPASS_SHIELD | DF_SKIPS_DOOMED_STATE } );
					}
				}
			}
		}
	)

	wait warmupTime

	//thread PROTO_CapVelocity( ent )

	entity soul
	if ( ent.IsTitan() )
	{
		soul = ent.GetTitanSoul()
		string titanType = GetSoulTitanSubClass( soul )
		entity rider = GetRodeoPilot( ent )
		if ( rider != null && Rodeo_IsAttached( rider ) )
		{
			if ( !rider.IsPlayer() )
				rider.Signal( "RodeoOver" )
			else
				PhaseShift( rider, 0, shiftTime )
		}
	}

	entity fx = PlayPhaseShiftDisappearFX( ent )
	thread PhaseShiftDisappearEffectCleanup( ent, fx, shiftTime )

	ent.Signal( "StartPhaseShift" )
	if ( !keepAnimActive )
		ent.Signal( "ScriptAnimStop" )
	ent.NotSolid()
	ent.SetNoTarget( true )
	ent.EnablePhaseShiftFlags()
	ent.Highlight_SetCurrentContext( -1 )

	if ( ent.IsPlayer() )
	{
		PlayerDropsScriptedItems( ent )
		if ( ent.IsTitan() )
		{
			EmitSoundOnEntityExceptToPlayer( ent, ent, SHIFTER_START_SOUND_3P_TITAN )
			EmitSoundOnEntityExceptToPlayerNotPredicted( ent, ent, SHIFTER_LOOP_SOUND_3P_TITAN )
		}
		else
		{
			EmitSoundOnEntityExceptToPlayer( ent, ent, SHIFTER_START_SOUND_3P )
			EmitSoundOnEntityExceptToPlayerNotPredicted( ent, ent, SHIFTER_LOOP_SOUND_3P )
		}

		foreach( statusEffect in ent.p.empStatusEffectsToClearForPhaseShift ) //Not great, done to avoid needing code work to get a separate empSlow/empSTurnEffects
		{
			StatusEffect_Stop( ent, statusEffect )
		}

		ent.p.empStatusEffectsToClearForPhaseShift.clear()
	}
	else
	{
		if ( ent.IsTitan() )
		{
			EmitSoundOnEntity( ent, SHIFTER_START_SOUND_3P_TITAN )
			EmitSoundOnEntity( ent, SHIFTER_LOOP_SOUND_3P_TITAN )
		}
		else
		{
			EmitSoundOnEntity( ent, SHIFTER_START_SOUND_3P )
			EmitSoundOnEntity( ent, SHIFTER_LOOP_SOUND_3P )
		}
	}

	float FX_WARMUP_TIME = 0.3
	bool timeAdjusted = false

	if ( shiftTime > FX_WARMUP_TIME )
	{
		shiftTime -= FX_WARMUP_TIME // need to play the fx a little earlier so the timing lines up
		timeAdjusted = true
	}

	if ( shiftTime >= SHIFTER_OUTRO_TIME_BEFORE_END )
	{
		wait ( shiftTime - SHIFTER_OUTRO_TIME_BEFORE_END )

		if ( ent.IsPlayer() )
		{
			if ( ent.IsTitan() )
			{
				EmitSoundOnEntityOnlyToPlayer( ent, ent, SHIFTER_PRE_END_SOUND_1P_TITAN )
				EmitSoundOnEntityExceptToPlayer( ent, ent, SHIFTER_PRE_END_SOUND_3P_TITAN )
			}
			else
			{
				EmitSoundOnEntityOnlyToPlayer( ent, ent, SHIFTER_PRE_END_SOUND_1P )
				EmitSoundOnEntityExceptToPlayer( ent, ent, SHIFTER_PRE_END_SOUND_3P )
			}

		}
		else
		{
			if ( ent.IsTitan() )
				EmitSoundOnEntity( ent, SHIFTER_PRE_END_SOUND_3P_TITAN )
			else
				EmitSoundOnEntity( ent, SHIFTER_PRE_END_SOUND_3P )
		}

		wait SHIFTER_OUTRO_TIME_BEFORE_END
	}
	else
	{
		wait shiftTime
	}

	PlayPhaseShiftAppearFX( ent )

	if ( timeAdjusted )
		wait FX_WARMUP_TIME
}

// ASSUMES THAT SECOND ENTITY IS NOT HUMAN SIZED
bool function ShouldEntitySelfKill( entity ent, entity largeTelefragTarget )
{
	if ( IsHumanSized( ent ) )
		return true

	if ( IsSingleplayer() )
		return false

	return ( DistanceSqr( largeTelefragTarget.GetOrigin(), ent.GetOrigin() ) < 4096.0 )
}

void function PhaseShiftDisappearEffectCleanup( entity ent, entity fx, float duration )
{
	fx.EndSignal( "OnDestroy" )
	ent.EndSignal( "ForceStopPhaseShift" )

	OnThreadEnd(
	function() : ( fx )
		{
			if ( IsValid( fx ) )
			{
				EffectStop( fx )
			}
		}
	)

	float bufferTime = 1.4
	if ( ent.IsTitan() )
		bufferTime = 0.0

	wait max( duration - bufferTime, 0.0 )
}

entity function PlayPhaseShiftAppearFX( entity ent )
{
	asset effect = SHIFTER_APPEAR_FX
	if ( !IsHumanSized( ent ) )
		effect = SHIFTER_APPEAR_FX_TITAN

	if ( ent.IsPlayer() )
	{
		if ( ent.IsTitan() )
			EmitSoundOnEntityExceptToPlayer( ent, ent, SHIFTER_END_SOUND_3P_TITAN )
		else
			EmitSoundOnEntityExceptToPlayer( ent, ent, SHIFTER_END_SOUND_3P )

		return PlayFXOnEntityForEveryoneExceptPlayer( effect, ent, ent )
	}
	else
	{
		if ( ent.IsTitan() )
			EmitSoundOnEntity( ent, SHIFTER_END_SOUND_3P_TITAN )
		else
			EmitSoundOnEntity( ent, SHIFTER_END_SOUND_3P )
		return PlayFXOnEntity( effect, ent )
	}
}

entity function PlayPhaseShiftDisappearFX( entity ent )
{
	asset effect = SHIFTER_DISAPPEAR_FX
	if ( !IsHumanSized( ent ) )
		effect = SHIFTER_DISAPPEAR_FX_TITAN

	int fxid = GetParticleSystemIndex( effect )
	int attachId = ent.LookupAttachment( "ORIGIN" )

	return StartParticleEffectOnEntity_ReturnEntity( ent, fxid,  FX_PATTACH_POINT_FOLLOW, attachId )
}

array<entity> function GetAttachedEnts( entity ent )
{
	array<entity> ents = [ ent ]

	if ( HasSoul( ent ) )
	{
		entity soul = ent.GetTitanSoul()
		if ( IsValid( soul.soul.batteryContainer ) )
			ents.append( soul.soul.batteryContainer )
	}

	entity weapon = ent.GetActiveWeapon()
	if ( IsValid( weapon ) )
		ents.append( weapon )

	return ents
}

/*
void function PROTO_CapVelocity( player )
{
	player.EndSignal( "OnDeath" )
	player.EndSignal( "StopPhaseShift" )

	while( 1 )
	{
		local newVel = player.GetVelocity()
		local zVel = newVel.z
		newVel = Vector( newVel.x, newVel.y, 0 )
		local speed = Length( newVel )
		newVel = Normalize( newVel )
		speed = min( speed, 400 )
		newVel = newVel * speed
		player.SetVelocity( Vector(newVel.x,newVel.y,zVel) )
		WaitFrame()
	}
}
*/

void function UntrackAllToneMarks( entity ent )
{
	if ( IsSingleplayer() ) //JFS::Probably want to remove this for R3
		return

	array<entity> enemyTitans = GetTitanArrayOfEnemies( ent.GetTeam() )
	foreach( titan in enemyTitans )
	{
		entity offhand = titan.GetOffhandWeapon( OFFHAND_RIGHT )
		if ( !IsValid( offhand ) )
			return

		if ( offhand.GetWeaponClassName() != "mp_titanweapon_tracker_rockets" )
			continue

		offhand.SmartAmmo_UntrackEntity( ent )
	}
}
#endif // #if SERVER


#if CLIENT
void function ClientPhaseShiftWarmupThread( entity player, float warmupTime )
{
	player.EndSignal( "OnDeath" )

	if ( player != GetLocalViewPlayer() )
		return
	if ( InPrediction() && !IsFirstTimePredicted() )
		return

	if ( warmupTime <= 0 )
		return

	int index = GetParticleSystemIndex( SHIFTER_PRE_FX )
	int fxID = StartParticleEffectInWorldWithHandle( index, ZERO_VECTOR, ZERO_VECTOR )

	OnThreadEnd(
		function() : ( fxID )
		{
			EffectStop( fxID, true, true );
		}
	)

	if ( player.IsTitan() )
		EmitSoundOnEntity( player, SHIFTER_PRE_SOUND_1P_TITAN )
	else
		EmitSoundOnEntity( player, SHIFTER_PRE_SOUND_1P )

	wait warmupTime
}

void function ClientPhaseShiftFirstPersonFXThread()
{
	int effectSparkles;
	int effectScreen;
	bool effectsAreActive = false;
	bool endSoundPlayed = false;
	entity ourPlayer = null;

	while( true )
	{
		if ( effectsAreActive )
		{
			entity localViewPlayer = GetLocalViewPlayer();

			bool needShutdown = false;
			if ( !IsValid( ourPlayer ) || !IsAlive( ourPlayer ) )
				needShutdown = true;
			else if ( ourPlayer != localViewPlayer )
				needShutdown = true;
			else if ( !ourPlayer.IsPhaseShifted() )
				needShutdown = true;

			if ( needShutdown )
			{
				if ( IsValid( ourPlayer ) && (ourPlayer == localViewPlayer) )
				{
					// FX
					{
						int fxIndex = GetParticleSystemIndex( SHIFTER_SCREEN_FX_START )
						StartParticleEffectInWorldWithHandle( fxIndex, ZERO_VECTOR, ZERO_VECTOR )
					}

					// FX
					{
						int fxIndex = GetParticleSystemIndex( SHIFTER_APPEAR_FX )
						vector viewAngles = ourPlayer.EyeAngles()
						vector viewForward = AnglesToForward( viewAngles )
						vector viewForward2d = Normalize( Vector( viewForward.x, viewForward.y, 0.0 ) )
						StartParticleEffectOnEntityWithPos( ourPlayer, fxIndex, FX_PATTACH_ABSORIGIN, -1, (viewForward2d * 30), ZERO_VECTOR )
					}

					if ( ourPlayer.IsTitan() )
					{
						EmitSoundOnEntity( ourPlayer, SHIFTER_END_SOUND_1P_TITAN )
					}
					else
					{
						EmitSoundOnEntity( ourPlayer, SHIFTER_END_SOUND_1P )
					}
					StopSoundOnEntity( ourPlayer, SHIFTER_LOOP_SOUND_1P )
					StopSoundOnEntity( ourPlayer, SHIFTER_LOOP_SOUND_1P_TITAN )
				}

				ClientPhaseShift_SCRIPT_HACKS_OFF()

				EffectStop( effectSparkles, true, true )
				EffectStop( effectScreen, true, true )
				effectsAreActive = false;
				ourPlayer = null;
				endSoundPlayed = false;
			}
			else if ( IsValid( localViewPlayer ) && localViewPlayer.IsPhaseShifted() )
			{
				if ( !endSoundPlayed && (localViewPlayer.PhaseShiftTimeRemaining() <= SHIFTER_OUTRO_TIME_BEFORE_END) )
				{
					endSoundPlayed = true;
					if ( localViewPlayer.IsTitan() )
						EmitSoundOnEntity( localViewPlayer, SHIFTER_PRE_END_SOUND_1P_TITAN )
					else
						EmitSoundOnEntity( localViewPlayer, SHIFTER_PRE_END_SOUND_1P )
				}
			}

		}

		if ( !effectsAreActive )
		{
			entity localViewPlayer = GetLocalViewPlayer();

			if ( IsValid( localViewPlayer ) && localViewPlayer.IsPhaseShifted() )
			{
				// FX
				{
					int fxIndex = GetParticleSystemIndex( SHIFTER_PERSONAL_FX )
					int attachIdx = localViewPlayer.LookupAttachment( "CHESTFOCUS" )
					effectSparkles = StartParticleEffectOnEntity( localViewPlayer, fxIndex, FX_PATTACH_POINT_FOLLOW, attachIdx )
				}

				// FX
				{
					int fxIndex = GetParticleSystemIndex( SHIFTER_SCREEN_FX )
					effectScreen = StartParticleEffectInWorldWithHandle( fxIndex, ZERO_VECTOR, ZERO_VECTOR )
				}

				// FX
				{
					int fxIndex = GetParticleSystemIndex( SHIFTER_SCREEN_FX_START )
					StartParticleEffectInWorldWithHandle( fxIndex, ZERO_VECTOR, ZERO_VECTOR )
				}

				// FX
				{
					entity viewModelEntity = localViewPlayer.GetViewModelEntity()
					entity firstPersonProxy = localViewPlayer.GetPredictedFirstPersonProxy()

					if ( IsValid( viewModelEntity ) )
					{
						viewModelEntity.Highlight_HideInside( 0.0 )
						viewModelEntity.Highlight_HideOutline( 0.0 )
					}

					if ( IsValid( firstPersonProxy ) )
					{
						firstPersonProxy.Highlight_HideInside( 0.0 )
						firstPersonProxy.Highlight_HideOutline( 0.0 )
					}
				}

				ClientPhaseShift_SCRIPT_HACKS_ON()

				if ( localViewPlayer.IsTitan() )
					EmitSoundOnEntity( localViewPlayer, SHIFTER_START_SOUND_1P_TITAN )
				else
					EmitSoundOnEntity( localViewPlayer, SHIFTER_START_SOUND_1P )

				if ( localViewPlayer.IsTitan() )
					EmitSoundOnEntity( localViewPlayer, SHIFTER_LOOP_SOUND_1P_TITAN )
				else
					EmitSoundOnEntity( localViewPlayer, SHIFTER_LOOP_SOUND_1P )

				effectsAreActive = true;
				ourPlayer = localViewPlayer;
			}
		}

		WaitFrame()
	}
}

void function ClientRemoteTurretFirstPersonFXThread()
{
	int effectSparkles;
	int effectScreen;
	bool effectsAreActive = false;
	entity ourPlayer = null;

	const string TURRET_LOOP_SOUND = "Pilot_RemoteTurret_Loop_1P"

	while( true )
	{
		if ( effectsAreActive )
		{
			entity localViewPlayer = GetLocalViewPlayer();

			bool needShutdown = false;
			if ( !IsValid( ourPlayer ) || !IsAlive( ourPlayer ) )
				needShutdown = true;
			else if ( ourPlayer != localViewPlayer )
				needShutdown = true;
			else if ( ourPlayer.GetRemoteTurret() == null )
				needShutdown = true;

			if ( needShutdown )
			{
				if ( IsValid( ourPlayer ) && (ourPlayer == localViewPlayer) )
					StopSoundOnEntity( ourPlayer, TURRET_LOOP_SOUND )

				effectsAreActive = false;
				ourPlayer = null;
			}
		}

		if ( !effectsAreActive )
		{
			entity localViewPlayer = GetLocalViewPlayer();
			if ( IsValid( localViewPlayer ) && (localViewPlayer.GetRemoteTurret() != null) )
			{
				EmitSoundOnEntity( localViewPlayer, TURRET_LOOP_SOUND )
				effectsAreActive = true;
				ourPlayer = localViewPlayer;
			}
		}

		WaitFrame()
	}
}

void function ClientPhaseShift_SCRIPT_HACKS_ON()
{
	entity localViewPlayer = GetLocalViewPlayer();

	localViewPlayer.Signal( "StartPhaseShift" )

	if ( localViewPlayer == GetLocalClientPlayer() )
	{
		//localViewPlayer.cv.PlayerPetTitanIcon.Hide()
		//localViewPlayer.cv.PlayerPetTitanArrow.Hide()
		//localViewPlayer.cv.PlayerPetTitanLabel.Hide()
	}
}

void function ClientPhaseShift_SCRIPT_HACKS_OFF()
{
	entity localViewPlayer = GetLocalViewPlayer();

	if ( localViewPlayer == GetLocalClientPlayer() )
		UpdatePetTitanIcon( localViewPlayer )

	//It would be great if we could automatically hide icons using SetEntityOverhead if that entity is phased out.
	// if ( GameRules_GetGameMode() == SURVIVOR )
	// 	DisplayScrapCounter( GetLocalClientPlayer(), LIFE_ALIVE, LIFE_ALIVE )
}

#endif // #if CLIENT