aboutsummaryrefslogtreecommitdiff
path: root/Northstar.CustomServers/scripts/vscripts/pilot/class_wallrun.gnut
blob: 58de59c1890b1a301eba6fc251bdc33856ed4094 (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
untyped

global function ClassWallrun_Init

global function Wallrun_AddPlayer
global function Wallrun_OnPlayerSpawn
global function Wallrun_OnPlayerDeath
global function Wallrun_PlayerTookDamage
global function Wallrun_EnforceWeaponDefaults
global function Wallrun_CreateCopyOfPilotModel

function ClassWallrun_Init()
{

	// Make weapons less effective when playing at higher difficulty.
	level.lethalityMods <- {}
}

function Wallrun_AddPlayer( player )
{
	player.playerClassData[level.pilotClass] <- {}
}


function Wallrun_EnforceWeaponDefaults( player )
{
	if ( player.playerClassData[ level.pilotClass ].primaryWeapon )
	{
		// settings already exist
		return
	}

	player.playerClassData[ level.pilotClass ].primaryWeapon = "mp_weapon_r97"
	player.playerClassData[ level.pilotClass ].secondaryWeapon = "mp_weapon_sniper"

	local offhandWeaponTable = {}
	offhandWeaponTable[0] <- { weapon = "mp_weapon_frag_grenade", mods = [] }
	offhandWeaponTable[1] <- { weapon = "mp_ability_heal", mods = [] }

	player.playerClassData[ level.pilotClass ].offhandWeapons = offhandWeaponTable
	player.playerClassData[ level.pilotClass ].playerSetFile = DEFAULT_PILOT_SETTINGS
}


function Wallrun_OnPlayerSpawn( player )
{
}


function Wallrun_PlayerTookDamage( entity player, damageInfo, entity attacker )
{
	if ( IsDemigod( player ) )
	{
		EntityDemigod_TryAdjustDamageInfo( player, damageInfo )
		return
	}

	AdjustDamageForRodeoPlayers( player, damageInfo, attacker )

	#if VERBOSE_DAMAGE_PRINTOUTS
		printt( "    After Wallrun_PlayerTookDamage:", DamageInfo_GetDamage( damageInfo ) )
	#endif

	if ( player.GetShieldHealthMax() > 0 )
	{
		local shieldDamage = PilotShieldHealthUpdate( player, damageInfo )
		return shieldDamage
	}

	return
}

function AdjustDamageForRodeoPlayers( entity player, var damageInfo, entity attacker )
{
	if ( player == attacker )
		return

	local titanSoulRodeoed = player.GetTitanSoulBeingRodeoed()
	if ( !IsValid( titanSoulRodeoed ) )
		return

	local playerParent = titanSoulRodeoed.GetTitan()

	// dont let npcs hurt rodeo player
	if ( attacker.IsNPC() && attacker != playerParent && DamageInfo_GetDamageSourceIdentifier( damageInfo ) != eDamageSourceId.mp_titanability_smoke )
	{
		DamageInfo_SetDamage( damageInfo, 0 )
		return
	}

	local damage = DamageInfo_GetDamage( damageInfo )

	if ( !ShouldAdjustDamageForRodeoPlayer( damageInfo ) )
		return

	local maxPer500ms

	if ( attacker == playerParent )
	{
		// rodeo'd player can't damage quite as much
		maxPer500ms = 56
	}
	else
	if ( playerParent.GetTeam() == player.GetTeam() )
	{
		// riding same team titan protects you a bit from random fire on that titan
		if ( DamageInfo_GetCustomDamageType( damageInfo ) & DF_EXPLOSION )
		{
			maxPer500ms = 75
		}
		else if ( DamageInfo_GetCustomDamageType( damageInfo ) & DF_MELEE  ) //If melee, players still die in one hit
		{
			maxPer500ms = player.GetMaxHealth() + 1
		}
		else
		{
			maxPer500ms = 175
		}
	}
	else
	{
		return
	}

	//Set a cap on how much damage the playerParent can do.
	local damageTaken = GetTotalDamageTakenInTime( player, 0.5 )

	local allowedDamage = maxPer500ms - damageTaken
	if ( damage < allowedDamage )
		return

	damage = allowedDamage
	if ( damage <= 0 )
		damage = 0

	DamageInfo_SetDamage( damageInfo, damage )
}


function ShouldAdjustDamageForRodeoPlayer( damageInfo )
{
	int sourceID = DamageInfo_GetDamageSourceIdentifier( damageInfo )

	switch( sourceID )
	{
		case eDamageSourceId.rodeo_trap:
		case eDamageSourceId.mp_titanweapon_vortex_shield:
		case eDamageSourceId.mp_titanweapon_vortex_shield_ion:
		case eDamageSourceId.mp_titanability_smoke:
		case eDamageSourceId.mp_weapon_satchel:	//added so that rodeoing players are no longer invulnerable to their satchels when detonated by Titan's smoke
			return false

		default:
			return true
	}
}


function Wallrun_OnPlayerDeath( entity player, damageInfo )
{
	if ( IsValidHeadShot( damageInfo, player ) )
	{
		int damageType = DamageInfo_GetCustomDamageType( damageInfo )
		local soundAlias
		if ( damageType & DF_SHOTGUN )
		{
			EmitSoundOnEntityOnlyToPlayer( player, player, "Flesh.Shotgun.BulletImpact_Headshot_3P_vs_1P" )
			soundAlias = "Flesh.Shotgun.BulletImpact_Headshot_3P_vs_3P"
		}
		else if ( damageType & damageTypes.bullet || damageType & DF_BULLET )
		{
			EmitSoundOnEntityOnlyToPlayer( player, player, "Flesh.Light.BulletImpact_Headshot_3P_vs_1P" )
			soundAlias = "Flesh.Light.BulletImpact_Headshot_3P_vs_3P"
		}
		else if ( damageType & damageTypes.largeCaliber ||  damageType & DF_GIB  )
		{
			EmitSoundOnEntityOnlyToPlayer( player, player, "Flesh.Heavy.BulletImpact_Headshot_3P_vs_1P" )
			soundAlias = "Flesh.Heavy.BulletImpact_Headshot_3P_vs_3P"
		}

		if ( soundAlias )
		{
			entity attacker = DamageInfo_GetAttacker( damageInfo )
			array<entity> pilotArray = GetPlayerArray()
			//Iterating because we need to not play this sound on 2 pilots and the function only allows for 1. Performance difference is negligible according to Eric M between this and adding a specific code function.
			foreach ( pilot in pilotArray )
			{
				if ( !IsValid( pilot ) )
					continue

				if ( pilot == player || pilot == attacker )
					continue

				EmitSoundOnEntityOnlyToPlayer( player, pilot, soundAlias )
			}
		}
	}
}


entity function Wallrun_CreateCopyOfPilotModel( entity player )
{
	const string PLAYER_SETTINGS_FIELD = "bodymodel"

	asset modelName
	if ( player.IsTitan() )
	{
		modelName = GetPlayerSettingsAssetForClassName( player.s.storedPlayerSettings, PLAYER_SETTINGS_FIELD )
	}
	else
	{
		modelName = player.GetPlayerSettingsAsset( PLAYER_SETTINGS_FIELD )
	}

	entity model = CreatePropDynamic( modelName )

	SetTeam( model, player.GetTeam() )

	//model.SetSkin( 0 )

	RandomizeHead( model )

	return model
}