aboutsummaryrefslogtreecommitdiff
path: root/Northstar.CustomServers/mod/scripts/vscripts/titan/_titan_hints.gnut
blob: 0e8b4b5b46d0544e6ccaf58bf485f339bdb45ddb (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
global function TitanHints_Init
global function TitanHints_NotifyUsedOffhand
global function TitanHints_ResetThresholds
global function TitanHints_TryShowHint
global function TitanHints_ShowHint

const float FIGHT_START_THRESHOLD = 10.0
const float FIGHT_HINT_THRESHOLD = 8.0
const float TITAN_HINT_COOLDOWN = 15.0

struct
{
	float titanFightStartTime = -99
	float lastDidDamageTime = -99
	float lastTookDamageTime = -99
	float lastShowHintTime = -99
	float lastDodgeTime = -99
	table<int,float> titanHintThresholds
	table<int,float> titanHintThresholdAdd
	table<int,float> lastShowHintTimes
} file

void function TitanHints_Init()
{
	AddDamageCallback( "player", TitanHint_Player_OnDamaged )
	AddDamageCallback( "npc_titan", TitanHint_NPC_OnDamaged )
	AddDamageCallback( "npc_super_spectre", TitanHint_NPC_OnDamaged )

	file.titanHintThresholds[ TITAN_HINT_DASH ] <- 5.0
	file.titanHintThresholds[ OFFHAND_ORDNANCE ] <- 5.0
	file.titanHintThresholds[ OFFHAND_SPECIAL ] <- 5.0
	file.titanHintThresholds[ OFFHAND_ANTIRODEO ] <- 10.0
	file.titanHintThresholds[ OFFHAND_EQUIPMENT ] <- 1.0

	file.lastShowHintTimes[ TITAN_HINT_DASH ] <- -99.0
	file.lastShowHintTimes[ OFFHAND_ORDNANCE ] <- -99.0
	file.lastShowHintTimes[ OFFHAND_SPECIAL ] <- -99.0
	file.lastShowHintTimes[ OFFHAND_ANTIRODEO ] <- -99.0
	file.lastShowHintTimes[ OFFHAND_EQUIPMENT ] <- -99.0

	file.titanHintThresholdAdd[ TITAN_HINT_DASH ] <- 0
	file.titanHintThresholdAdd[ OFFHAND_ORDNANCE ] <- 0
	file.titanHintThresholdAdd[ OFFHAND_SPECIAL ] <- 0
	file.titanHintThresholdAdd[ OFFHAND_ANTIRODEO ] <- 0
	file.titanHintThresholdAdd[ OFFHAND_EQUIPMENT ] <- 0

	AddCallback_OnPlayerInventoryChanged( TitanHints_ResetThresholds )
	AddSpawnCallback( "player", PlayerDidLoad )
}

void function PlayerDidLoad( entity player )
{
	AddPlayerMovementEventCallback( player, ePlayerMovementEvents.DODGE, OnPlayerDodge )
}

void function TitanHint_Player_OnDamaged( entity player, var damageInfo )
{
	if ( !player.IsTitan() )
		return

	entity attacker = DamageInfo_GetAttacker( damageInfo )
	if ( !attacker.IsTitan() && !IsSuperSpectre(attacker) )
		return

	if ( attacker.GetTeam() == player.GetTeam() )
		return

	TrySetFightTime()

	file.lastTookDamageTime = Time()

	array<int> hintsToShow = [ TITAN_HINT_DASH, OFFHAND_EQUIPMENT, OFFHAND_SPECIAL, OFFHAND_ORDNANCE, OFFHAND_ANTIRODEO ]

	if ( GetDoomedState( player ) || GetTitanCurrentRegenTab( player ) < 2 )
		hintsToShow = [ TITAN_HINT_DASH, OFFHAND_SPECIAL ]

	TitanHints_TryShowHint( player, hintsToShow, attacker )
}

void function TitanHint_NPC_OnDamaged( entity victim, var damageInfo )
{
	entity attacker = DamageInfo_GetAttacker( damageInfo )
	if ( !attacker.IsPlayer() )
		return

	if ( !attacker.IsTitan() )
		return

	TrySetFightTime()

	file.lastDidDamageTime = Time()

	TitanHints_TryShowHint( attacker, [ OFFHAND_EQUIPMENT, OFFHAND_ORDNANCE, OFFHAND_ANTIRODEO ], victim )
}

// reset thresholds
void function TitanHints_ResetThresholds( entity player )
{
	if ( !player.IsTitan() )
		return

	foreach ( index, value in file.titanHintThresholdAdd )
	{
		if ( index != TITAN_HINT_DASH ) // don't reset dash
			file.titanHintThresholdAdd[ index ] = 0.0
	}
}

// increase threshold for hints every time the player uses it
void function TitanHints_NotifyUsedOffhand( int index )
{
	// never increment for core
	if ( index == OFFHAND_EQUIPMENT )
		return

	if ( index in file.titanHintThresholds )
	{
		file.titanHintThresholdAdd[ index ] += TITAN_HINT_COOLDOWN
	}
}

bool function TrySetFightTime()
{
	if (
		Time() - file.lastTookDamageTime > FIGHT_START_THRESHOLD &&
		Time() - file.lastDidDamageTime > FIGHT_START_THRESHOLD
		 )
	{
		file.titanFightStartTime = Time()
		return true
	}

	return false
}

void function TitanHints_TryShowHint( entity player, array<int> indexes, entity enemy = null )
{
	if ( GetConVarInt( "hud_setting_showTips" ) == 0 )
		return

	float fightDuration = Time() - file.titanFightStartTime
	if ( fightDuration < FIGHT_HINT_THRESHOLD )
		return

	if ( TitanCoreInUse( player ) )
		return

	foreach ( idx in indexes )
	{
		float threshold = file.titanHintThresholds[idx] + file.titanHintThresholdAdd[idx]

		// have we been fighting for a while?
		if ( fightDuration < max( threshold, TITAN_HINT_COOLDOWN ) )
			continue

		// have we already shown this hint?
		if ( Time() - file.lastShowHintTimes[idx] < max( threshold, TITAN_HINT_COOLDOWN ) )
			continue

		// have we already shown a hint?
		if ( Time() - file.lastShowHintTime < TITAN_HINT_COOLDOWN )
			continue

		if ( idx != TITAN_HINT_DASH )
		{
			// when did you last use this ability?
			if ( Time() - player.p.lastTitanOffhandUseTime[idx] < threshold )
				continue

			entity weapon = player.GetOffhandWeapon( idx )

			if ( weapon == null )
				continue

			// has this ability been available for a while?
			if ( weapon.GetNextAttackAllowedTime() + threshold > Time() )
				continue

			var requiresLocks = weapon.GetWeaponInfoFileKeyField( "requires_lock" )

			if ( requiresLocks != null )
			{
				expect int( requiresLocks )
				if ( requiresLocks == 1 )
				{
					if ( weapon.SmartAmmo_IsEnabled() && !SmartAmmo_CanWeaponBeFired( weapon ) )
						continue
				}
			}


			int curEnergyCost = weapon.GetWeaponCurrentEnergyCost()
			if ( !player.CanUseSharedEnergy( curEnergyCost ) )
				continue

			if ( weapon.IsChargeWeapon() )
			{
				if ( weapon.GetWeaponChargeFraction() > 0.0 )
					continue
			}

			if ( weapon.GetWeaponPrimaryClipCount() < weapon.GetWeaponSettingInt( eWeaponVar.ammo_min_to_fire ) )
				continue

			// special core check
			if ( idx == OFFHAND_EQUIPMENT )
			{
				if( !CheckCoreAvailable( weapon ) )
					continue
				if ( IsConversationPlaying() )
					continue
			}

			var hintType = weapon.GetWeaponInfoFileKeyField( "hint_type" )
			if ( hintType != null )
			{
				if ( hintType == "range_toggle" )
				{
					if ( enemy != null )
					{
						float dist = Distance2D( enemy.GetOrigin(), player.GetOrigin() )

						if ( weapon.HasMod( "ammo_swap_ranged_mode" ) )
						{ // has long range mode, will tell to swap to short range
							if ( dist > 2500 )
							{
								continue
							}
						}
						else
						{ // has short range mode, will tell to swap to long range
							if ( dist < 1500 )
							{
								continue
							}
						}
					}
				}
			}

		}
		else
		{
			if ( Time() - file.lastDodgeTime < threshold )
				continue

			// should check if dodge is available here, but we can't seem to do that
		}

		// show hint
		TitanHints_ShowHint( player, idx )
		break
	}
}

void function TitanHints_ShowHint( entity player, int idx )
{
	Remote_CallFunction_Replay( player, "ServerCallback_ShowOffhandWeaponHint", idx )
	file.lastShowHintTimes[idx] = Time()
	file.lastShowHintTime = Time()
}

void function OnPlayerDodge( entity player )
{
	file.lastDodgeTime = Time()
	file.titanHintThresholdAdd[ TITAN_HINT_DASH ] += TITAN_HINT_COOLDOWN
}