aboutsummaryrefslogtreecommitdiff
path: root/Northstar.CustomServers/scripts/vscripts/class/cplayer.nut
blob: b9f8f7eb8e97780f7ac1d3f1537009647299c1f8 (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
untyped


global function CodeCallback_RegisterClass_CPlayer
global function PlayerDropsScriptedItems
global function IsDemigod
global function EnableDemigod
global function DisableDemigod

int __nextInputHandle = 0


global struct PlayerSlowDownEffect
{
	float slowEndTime
	float speedCap // max speed multiplier if this slow effect is active
}

function CodeCallback_RegisterClass_CPlayer()
{
	//printl( "Class Script: CPlayer" )

	CPlayer.ClassName <- "CPlayer"
	CPlayer.hasSpawned <- null
	CPlayer.hasConnected <- null
	CPlayer.isSpawning <- null
	CPlayer.isSpawningHotDroppingAsTitan <- false
	CPlayer.disableWeaponSlots <- false
	CPlayer.supportsXRay <- null

	CPlayer.lastTitanTime <- 0

	CPlayer.globalHint <- null
	CPlayer.playerClassData <- null
	CPlayer.escalation <- null
	CPlayer.pilotAbility <- null
	CPlayer.titansBuilt <- 0
	CPlayer.spawnTime <- 0
	CPlayer.serverFlags <- 0
	CPlayer.watchingKillreplayEndTime <- 0.0
	CPlayer.cloakedForever <- false
	CPlayer.stimmedForever <- false

	RegisterSignal( "OnRespawnPlayer" )
	RegisterSignal( "NewViewAnimEntity" )
	RegisterSignal( "PlayerDisconnected" )

	function CPlayer::constructor()
	{
		CBaseEntity.constructor()
	}

	function CPlayer::RespawnPlayer( ent )
	{
		this.Signal( "OnRespawnPlayer", { ent = ent } )

		// hack. Players should clear all these on spawn.
		this.ViewOffsetEntity_Clear()
		ClearPlayerAnimViewEntity( expect entity( this ) )
		this.spawnTime = Time()

		this.ClearReplayDelay()
		this.ClearViewEntity()

		// titan melee can set these vars, and they need to clear on respawn:
		this.SetOwner( null )
		this.kv.VisibilityFlags = ENTITY_VISIBLE_TO_EVERYONE


		Assert( !this.GetParent(), this + " should not have a parent yet! - Parent: " + this.GetParent() )
		Assert( this.s.respawnCount <= 1 || IsMultiplayer(), "Tried to respawn in single player, see callstack" )
		this.Code_RespawnPlayer( ent )
	}

	/*
	CPlayer.__SetTrackEntity <- CPlayer.SetTrackEntity
	function CPlayer::SetTrackEntity( ent )
	{
		printl( "\nTime " + Time() + " Ent " + ent )

		DumpStack()
		this.__SetTrackEntity( ent )
	}
	*/

	function CPlayer::GetDropEntForPoint( origin )
	{
		return null
	}


	function CPlayer::GetPlayerClassData( myClass )
	{
		Assert( myClass in this.playerClassData, myClass + " not in playerClassData" )
		return this.playerClassData[ myClass ]
	}


	function CPlayer::InitMPClasses()
	{
		this.playerClassData = {}

		Titan_AddPlayer( this )
		Wallrun_AddPlayer( this )
	}


	function CPlayer::InitSPClasses()
	{
		this.playerClassData = {}
		SetTargetName( expect entity( this ), expect string( this.GetTargetName() + this.entindex() ) )

		Titan_AddPlayer( this )
	}


	// function SpawnAsClass()
	function CPlayer::SpawnAsClass( className = null )
	{
		if ( !className )
		{
			className = this.GetPlayerClass()
		}

		switch ( className )
		{
			case level.pilotClass:
				Wallrun_OnPlayerSpawn( this )
				break

			default:
				Assert( 0, "Tried to spawn as unsupported " + className )
		}
	}


	function CPlayer::GiveScriptWeapon( weaponName, equipSlot = null )
	{
		this.scope().GiveScriptWeapon( weaponName, equipSlot )
	}

	function CPlayer::OnDeathAsClass( damageInfo )
	{
		switch ( this.GetPlayerClass() )
		{
			case "titan":
				Titan_OnPlayerDeath( expect entity( this ), damageInfo )
				break

			case level.pilotClass:
				Wallrun_OnPlayerDeath( expect entity( this ), damageInfo )
				break
		}
	}

	function CPlayer::Disconnected()
	{
		this.Signal( "_disconnectedInternal" )
		svGlobal.levelEnt.Signal( "PlayerDisconnected" )

		if ( HasSoul( expect entity( this ) ) )
		{
			thread SoulDies( expect entity( this ).GetTitanSoul(), null )
		}

		entity titan = GetPlayerTitanInMap( expect entity( this ) )
		if ( IsAlive( titan ) && titan.IsNPC() )
		{
			local soul = titan.GetTitanSoul()
			if ( IsValid( soul ) && soul.followOnly )
				FreeAutoTitan( titan )
			else
				titan.Die( null, null, { damageSourceId = eDamageSourceId.damagedef_suicide } )
			//				titan.Die()
		}

		PROTO_CleanupTrackedProjectiles( expect entity( this ) )

		if ( this.globalHint != null )
		{
			this.globalHint.Kill_Deprecated_UseDestroyInstead()
			this.globalHint = null
		}
	}


	function CPlayer::GetClassDataEnts()
	{
		local ents = []
		local added

		if ( this.playerClassData == null )
			return ents;

		foreach ( ent in this.playerClassData )
		{
			added = false

			foreach ( newent in ents )
			{
				if ( newent == ent )
				{
					added = true
					break
				}
			}

			if ( !added )
				ents.append( ent )
		}

		return ents
	}


	function CPlayer::CleanupMPClasses()
	{
	}

	function CPlayer::HasXRaySupport()
	{
		return ( this.supportsXRay != null )
	}

	function CPlayer::GiveExtraWeaponMod( mod )
	{
		if ( this.HasExtraWeaponMod( mod ) )
			return

		local mods = this.GetExtraWeaponMods()
		mods.append( mod )

		this.SetExtraWeaponMods( mods )
	}


	function CPlayer::HasExtraWeaponMod( mod )
	{
		local mods = this.GetExtraWeaponMods()
		foreach( _mod in mods )
		{
			if ( _mod == mod )
				return true
		}
		return false
	}


	function CPlayer::TakeExtraWeaponMod( mod )
	{
		if ( !this.HasExtraWeaponMod( mod ) )
			return

		local mods = this.GetExtraWeaponMods()
		mods.fastremovebyvalue( mod )

		this.SetExtraWeaponMods( mods )
	}

	function CPlayer::ClearExtraWeaponMods()
	{
		this.SetExtraWeaponMods( [] )
	}


	function CPlayer::SetPlayerPilotSettings( settingsName )
	{
		this.SetPlayerRequestedSettings( settingsName )
	}

	function CPlayer::RecordLastMatchContribution( contribution )
	{
		// replace with code function
	}

	function CPlayer::RecordLastMatchPerformance( matchPerformance )
	{
		// replace with code function
	}

	function CPlayer::RecordSkill( skill )
	{
		// replace with code function
		this.SetPersistentVar( "ranked.recordedSkill", skill )
	}

	function CPlayer::SetPlayerSettings( settings )
	{
		local oldPlayerClass = CPlayer.GetPlayerClass()

		CPlayer.SetPlayerSettingsWithMods( settings, [] )

		this.RunSettingsChangedFuncs( settings, oldPlayerClass )
	}

	function CPlayer::SetPlayerSettingsFromDataTable( pilotDataTable )
	{
		local oldPlayerClass = CPlayer.GetPlayerClass()

		local settings = pilotDataTable.playerSetFile

		local mods = pilotDataTable.playerSetFileMods

		this.SetPlayerSettingsWithMods( settings, mods )

		this.RunSettingsChangedFuncs( settings, oldPlayerClass )
	}

	function CPlayer::RunSettingsChangedFuncs( settings, oldPlayerClass )
	{
		if ( IsAlive( expect entity( this ) ) && !this.IsTitan() && GetCurrentPlaylistVarFloat( "pilot_health_multiplier", 0.0 ) != 0.0 )
		{
			float pilotHealthMultiplier = GetCurrentPlaylistVarFloat( "pilot_health_multiplier", 1.0 )
			int pilotMaxHealth = int( this.GetMaxHealth() * pilotHealthMultiplier )
			this.SetMaxHealth( pilotMaxHealth )
			this.SetHealth( pilotMaxHealth )
		}

		if ( this.IsTitan() )
		{
			entity soul = expect entity ( this.GetTitanSoul() )
			local index = PlayerSettingsNameToIndex( settings )
			soul.SetPlayerSettingsNum( index )

			foreach ( func in svGlobal.soulSettingsChangeFuncs )
			{
				func( soul )
			}
		}
	}
}

void function PlayerDropsScriptedItems( entity player )
{
	foreach ( callbackFunc in svGlobal.onPlayerDropsScriptedItemsCallbacks )
		callbackFunc( player )
}

bool function IsDemigod( entity player )
{
	return player.p.demigod
}

void function EnableDemigod( entity player )
{
	Assert( player.IsPlayer() )
	player.p.demigod = true
}

void function DisableDemigod( entity player )
{
	Assert( player.IsPlayer() )
	player.p.demigod = false
}