aboutsummaryrefslogtreecommitdiff
path: root/Northstar.CustomServers/mod/scripts/vscripts/ai/_ai_spectre.gnut
blob: 214aff96ef0b4196721e2df4a9107f4e7b398b5c (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
global function AiSpectre_Init
global function NPCCarriesBattery

void function AiSpectre_Init()
{
	//AddDamageCallback( "npc_spectre", SpectreOnDamaged )
	AddDeathCallback( "npc_spectre", SpectreOnDeath )
	//AddSpawnCallback( "npc_spectre", SpectreOnSpawned )

	#if !SPECTRE_CHATTER_MP_ENABLED
		AddCallback_OnPlayerKilled( SpectreChatter_OnPlayerKilled )
		AddCallback_OnNPCKilled( SpectreChatter_OnNPCKilled )
	#endif
}

void function SpectreOnSpawned( entity npc )
{

}

void function SpectreOnDeath( entity npc, var damageInfo )
{
	if ( !IsValidHeadShot( damageInfo, npc ) )
		return

	// Set these so cl_player knows to kill the eye glow and play the right SFX
	DamageInfo_AddCustomDamageType( damageInfo, DF_HEADSHOT )
	DamageInfo_AddCustomDamageType( damageInfo, DF_KILLSHOT )
//	EmitSoundOnEntityExceptToPlayer( npc, attacker, "SuicideSpectre.BulletImpact_HeadShot_3P_vs_3P" )

	int bodyGroupIndex = npc.FindBodyGroup( "removableHead" )
	int stateIndex = 1  // 0 = show, 1 = hide
	npc.SetBodygroup( bodyGroupIndex, stateIndex )

	DamageInfo_SetDamage( damageInfo, npc.GetMaxHealth() )

}

// All damage to spectres comes here for modification and then either branches out to other npc types (Suicide, etc) for custom stuff or it just continues like normal.
void function SpectreOnDamaged( entity npc, var damageInfo )
{

}

void function SpectreChatter_OnPlayerKilled( entity playerKilled, entity attacker, var damageInfo )
{
	if ( !IsSpectre( attacker ) )
		return

	if ( playerKilled.IsTitan() )
		thread PlaySpectreChatterAfterDelay( attacker, "spectre_gs_gruntkillstitan_02_1" )
	else
		thread PlaySpectreChatterAfterDelay( attacker, "spectre_gs_killenemypilot_01_1" )

}

void function SpectreChatter_OnNPCKilled( entity npcKilled, entity attacker, var damageInfo )
{
	if ( IsSpectre( npcKilled ) )
	{
		string deadGuySquadName = expect string( npcKilled.kv.squadname )
		if ( deadGuySquadName == "" )
			return

		array<entity> squad = GetNPCArrayBySquad( deadGuySquadName )

		entity speakingSquadMate = null

		foreach( squadMate in squad )
		{
			if ( IsSpectre( squadMate ) )
			{
				speakingSquadMate = squadMate
				break
			}
		}
		if ( speakingSquadMate == null )
			return

		if ( squad.len() == 1 )
			thread PlaySpectreChatterAfterDelay( speakingSquadMate, "spectre_gs_squaddeplete_01_1" )
		else if ( squad.len() > 0  )
			thread PlaySpectreChatterAfterDelay( speakingSquadMate, "spectre_gs_allygrundown_05_1" )
	}
	else
	{
		if ( !IsSpectre( attacker ) )
			return

		if ( npcKilled.IsTitan() )
			thread PlaySpectreChatterAfterDelay( attacker, "spectre_gs_gruntkillstitan_02_1" )
	}
}

void function PlaySpectreChatterAfterDelay( entity spectre, string chatterLine, float delay = 0.3 )
{
	wait delay

	if ( !IsAlive( spectre ) ) //Really this is just an optimization thing, if the spectre is dead no point in running the same check for every player nearby in ShouldPlaySpectreChatterMPLine
		return

	PlaySpectreChatterToAll( chatterLine, spectre )
}

void function NPCCarriesBattery( entity npc )
{
	entity battery = Rodeo_CreateBatteryPack()
	battery.SetParent( npc, "BATTERY_ATTACH" )
	battery.MarkAsNonMovingAttachment()
	thread SpectreBatteryThink( npc, battery )
}

void function SpectreBatteryThink( entity npc, entity battery )
{
	battery.EndSignal( "OnDestroy" )
	npc.EndSignal( "OnDestroy" )

	OnThreadEnd(
	function() : ( battery )
		{
			if ( IsValid( battery ) )
			{
				battery.ClearParent()
				battery.SetAngles( < 0,0,0 > )
				battery.SetVelocity( < 0,0,200 > )
			}
		}
	)

	npc.WaitSignal( "OnDeath" )
}