‪Black Ops 3 Source Code Explorer  0.1
‪An script explorer for Black Ops 3 by ZeRoY
_blackjack_challenges.gsc
Go to the documentation of this file.
1 #using scripts\codescripts\struct;
2 
3 #using scripts\shared\callbacks_shared;
4 #using scripts\shared\challenges_shared;
5 #using scripts\shared\drown;
6 #using scripts\shared\scoreevents_shared;
7 #using scripts\shared\system_shared;
8 #using scripts\shared\util_shared;
9 #using scripts\shared\weapons\_weapon_utils;
10 
11 #using scripts\mp\_challenges;
12 #using scripts\mp\gametypes\_loadout;
13 
14 #insert scripts\shared\shared.gsh;
15 
16 #using scripts\mp\_util;
17 
18 #insert scripts\mp\_bonuscard.gsh;
19 
20 #define BLACKJACK_SPECIALIST_INDEX 9
21 #define BLACKJACK_SPECIALIST_KILLS 4 // for blackjack challenge: kills while using a specialist weapon or ability
22 #define BLACKJACK_UNIQUE_SPECIALIST_KILLS 2 // for blackjack challenge: count of unique specialist weapons or abilities used to kill
23 
24 #namespace blackjack_challenges;
25 
26 ‪REGISTER_SYSTEM( "blackjack_challenges", &‪__init__, undefined )
27 
28 function ‪__init__()
29 {
31 }
32 
34 {
35  if ( !isdefined( level.ChallengesCallbacks ) )
36  {
37  level.ChallengesCallbacks = [];
38  }
39 
40  waittillframeend;
41 
43  {
48  }
49 
51 }
52 
54 {
55  player = self;
57  {
58  specialistIndex = player GetSpecialistIndex();
59  isBlackjack = ( specialistIndex == ‪BLACKJACK_SPECIALIST_INDEX );
60  if ( isBlackjack )
61  {
62  player thread ‪track_blackjack_consumable();
63 
64  if ( !isdefined( self.pers[ "blackjack_challenge_active" ] ) )
65  {
66  remaining_time = player ConsumableGet( "blackjack", "awarded" ) - player ConsumableGet( "blackjack", "consumed" );
67 
68  if ( remaining_time > 0 )
69  {
70  special_card_earned = player ‪get_challenge_stat( "special_card_earned" );
71  if ( !special_card_earned )
72  {
73  player.pers[ "blackjack_challenge_active" ] = true;
74  player.pers[ "blackjack_unique_specialist_kills" ] = 0;
75  player.pers[ "blackjack_specialist_kills" ] = 0;
76  player.pers[ "blackjack_unique_weapon_mask" ] = 0;
77  player.pers[ "blackjack_unique_ability_mask" ] = 0;
78  }
79  }
80  }
81  }
82  }
83 }
84 
86 {
87  return ( self.pers[ "blackjack_challenge_active" ] === true );
88 }
89 
90 function ‪on_hero_ability_kill( ability, victimAbility )
91 {
92  player = self;
93 
94  if ( !isdefined( player ) || !isplayer( player ) )
95  return;
96 
97  if ( !isdefined( player.isRoulette ) || !player.isRoulette )
98  return;
99 
100  if ( player ‪is_challenge_active() )
101  {
102  player.pers[ "blackjack_specialist_kills" ]++;
103 
104  currentHeroAbilityMask = player.pers[ "blackjack_unique_ability_mask" ];
105  heroAbilityMask = ‪get_hero_ability_mask( ability );
106  newHeroAbilityMask = heroAbilityMask | currentHeroAbilityMask;
107  if ( newHeroAbilityMask != currentHeroAbilityMask )
108  {
109  player.pers[ "blackjack_unique_specialist_kills" ]++;
110  player.pers[ "blackjack_unique_ability_mask" ] = newHeroAbilityMask;
111  }
112 
114  }
115 }
116 
118 {
119  player = self;
120 
121  special_card_earned = player ‪get_challenge_stat( "special_card_earned" );
122  if ( special_card_earned )
123  {
124  return;
125  }
126 
127  if ( ( player.pers[ "blackjack_specialist_kills" ] >= ‪BLACKJACK_SPECIALIST_KILLS ) &&
128  ( player.pers[ "blackjack_unique_specialist_kills" ] >= ‪BLACKJACK_UNIQUE_SPECIALIST_KILLS ) )
129  {
130  player ‪set_challenge_stat( "special_card_earned", 1 );
131  player AddPlayerStat( "blackjack_challenge", 1 );
132  }
133 }
134 
135 function ‪challenge_kills( data )
136 {
137  attackerisThief = data.attackerIsThief;
138  attackerIsRoulette = data.attackerIsRoulette;
139  attackerIsThiefOrRoulette = attackerisThief || attackerIsRoulette;
140 
141  if ( !attackerIsThiefOrRoulette )
142  return;
143 
144  victim = data.victim;
145  attacker = data.attacker;
146  player = attacker;
147  weapon = data.weapon;
148 
149  if ( !isdefined( weapon ) || ( weapon == level.weaponNone ) )
150  return;
151 
152  if ( !isdefined( player ) || !isplayer( player ) )
153  return;
154 
155  if ( attackerIsThief )
156  {
157  if ( weapon.isHeroWeapon === true )
158  {
159  if ( player ‪is_challenge_active() )
160  {
161  player.pers[ "blackjack_specialist_kills" ]++;
162 
163  currentHeroWeaponMask = player.pers[ "blackjack_unique_weapon_mask" ];
164  heroWeaponMask = ‪get_hero_weapon_mask( attacker, weapon );
165  newHeroWeaponMask = heroWeaponMask | currentHeroWeaponMask;
166  if ( newHeroWeaponMask != currentHeroWeaponMask )
167  {
168  player.pers[ "blackjack_unique_specialist_kills" ] += 1;
169  player.pers[ "blackjack_unique_weapon_mask" ] = newHeroWeaponMask;
170  }
171 
173  }
174  }
175  }
176 
177  // ability kills are handled as events fired from score events
178  // if ( attackerIsRoulette )
179  // {
180  // }
181 }
182 
183 function ‪get_challenge_stat( stat_name )
184 {
185  return self GetDStat( "tenthspecialistcontract", stat_name );
186 }
187 
188 function ‪set_challenge_stat( stat_name, stat_value )
189 {
190  return self SetDStat( "tenthspecialistcontract", stat_name, stat_value );
191 }
192 
193 function ‪get_hero_weapon_mask( attacker, weapon )
194 {
195  if ( !isdefined( weapon ) )
196  return 0;
197 
198  if ( isdefined( weapon.isHeroWeapon ) && !weapon.isHeroWeapon )
199  return 0;
200 
201  switch( weapon.name )
202  {
203  case "hero_minigun":
204  case "hero_minigun_body3":
205  return 1; // note: heroWeaponMask needs to stay unique and consistent for function across TUs and FFOTDs
206  break;
207  case "hero_flamethrower":
208  return 1 << 1;
209  break;
210  case "hero_lightninggun":
211  case "hero_lightninggun_arc":
212  return 1 << 2;
213  break;
214  case "hero_chemicalgelgun":
215  case "hero_firefly_swarm":
216  return 1 << 3;
217  break;
218  case "hero_pineapplegun":
219  case "hero_pineapple_grenade":
220  return 1 << 4;
221  break;
222  case "hero_armblade":
223  return 1 << 5;
224  break;
225  case "hero_bowlauncher":
226  case "hero_bowlauncher2":
227  case "hero_bowlauncher3":
228  case "hero_bowlauncher4":
229  return 1 << 6;
230  break;
231  case "hero_gravityspikes":
232  return 1 << 7;
233  break;
234  case "hero_annihilator":
235  return 1 << 8;
236  break;
237  default:
238  return 0;
239  }
240 }
241 
242 function ‪get_hero_ability_mask( ability )
243 {
244  if ( !isdefined( ability ) )
245  return 0;
246 
247  switch( ability.name )
248  {
249  case "gadget_clone":
250  return 1; // note: heroAbilityMask needs to stay unique and consistent for functions across TUs and FFOTDs
251  break;
252  case "gadget_heat_wave":
253  return 1 << 1;
254  break;
255  case "gadget_flashback":
256  return 1 << 2;
257  break;
258  case "gadget_resurrect":
259  return 1 << 3;
260  break;
261  case "gadget_armor":
262  return 1 << 4;
263  break;
264  case "gadget_camo":
265  return 1 << 5;
266  break;
267  case "gadget_vision_pulse":
268  return 1 << 6;
269  break;
270  case "gadget_speed_burst":
271  return 1 << 7;
272  break;
273  case "gadget_combat_efficiency":
274  return 1 << 8;
275  break;
276  default:
277  return 0;
278  }
279 }
280 
281 function ‪challenge_game_ended( data )
282 {
283  if ( !isdefined( data ) )
284  return;
285 
286  player = data.player;
287  if ( !isdefined( player ) )
288  return;
289 
290  if ( !isPlayer( player ) )
291  return;
292 
293  if ( player ‪util::is_bot() )
294  return;
295 
296  if ( !player ‪is_challenge_active() )
297  return;
298 
299  player ‪report_consumable();
300 }
301 
302 function ‪challenge_round_ended( data )
303 {
304  if ( !isdefined( data ) )
305  return;
306 
307  player = data.player;
308  if ( !isdefined( player ) )
309  return;
310 
311  if ( !isPlayer( player ) )
312  return;
313 
314  if ( player ‪util::is_bot() )
315  return;
316 
317  if ( !player ‪is_challenge_active() )
318  return;
319 
320  player ‪report_consumable();
321 }
322 
324 {
325  level endon( "game_ended" );
326  self notify( "track_blackjack_consumable_singleton" );
327  self endon( "track_blackjack_consumable_singleton" );
328  self endon( "disconnect" );
329 
330  player = self;
331 
332  if ( !isdefined( player.last_blackjack_consumable_time ) )
333  player.last_blackjack_consumable_time = 0;
334 
335  while ( isdefined( player ) )
336  {
337  random_wait_time = GetDvarFloat( "mp_blackjack_consumable_wait", 20.0 ) + RandomFloatRange( -5.0, 5.0 );
338  wait random_wait_time;
339 
340  player ‪report_consumable();
341  }
342 }
343 
345 {
346  player = self;
347 
348  if ( !isdefined( player ) )
349  return;
350 
351  if ( !isdefined( player.timePlayed ) || !isdefined( player.timePlayed["total"] ) )
352  return;
353 
354  current_time_played = player.timePlayed["total"];
355 
356  time_to_report = current_time_played - player.last_blackjack_consumable_time;
357 
358  if ( time_to_report > 0 )
359  {
360  max_time_to_report = player ConsumableGet( "blackjack", "awarded" ) - player ConsumableGet( "blackjack", "consumed" );
361  consumable_increment = int( min( time_to_report, max_time_to_report ) );
362  if ( consumable_increment > 0 )
363  {
364  player ConsumableIncrement( "blackjack", "consumed", consumable_increment ); // so we don't go over awarded time
365  }
366  }
367 
368  player.last_blackjack_consumable_time = current_time_played;
369 }
‪BLACKJACK_SPECIALIST_INDEX
‪#define BLACKJACK_SPECIALIST_INDEX
Definition: _blackjack_challenges.gsc:20
‪report_consumable
‪function report_consumable()
Definition: _blackjack_challenges.gsc:344
‪is_bot
‪function is_bot()
Definition: util_shared.gsc:2488
‪on_player_connect
‪function on_player_connect()
Definition: _blackjack_challenges.gsc:53
‪on_start_gametype
‪function on_start_gametype(func, obj)
Definition: callbacks_shared.csc:285
‪get_hero_weapon_mask
‪function get_hero_weapon_mask(attacker, weapon)
Definition: _blackjack_challenges.gsc:193
‪is_challenge_active
‪function is_challenge_active()
Definition: _blackjack_challenges.gsc:85
‪BLACKJACK_UNIQUE_SPECIALIST_KILLS
‪#define BLACKJACK_UNIQUE_SPECIALIST_KILLS
Definition: _blackjack_challenges.gsc:22
‪BLACKJACK_SPECIALIST_KILLS
‪#define BLACKJACK_SPECIALIST_KILLS
Definition: _blackjack_challenges.gsc:21
‪registerChallengesCallback
‪function registerChallengesCallback(callback, func)
Definition: challenges_shared.gsc:166
‪__init__
‪function __init__()
Definition: _blackjack_challenges.gsc:28
‪on_hero_ability_kill
‪function on_hero_ability_kill(ability, victimAbility)
Definition: _blackjack_challenges.gsc:90
‪check_blackjack_challenge
‪function check_blackjack_challenge()
Definition: _blackjack_challenges.gsc:117
‪canProcessChallenges
‪function canProcessChallenges()
Definition: challenges_shared.gsc:133
‪get_hero_ability_mask
‪function get_hero_ability_mask(ability)
Definition: _blackjack_challenges.gsc:242
‪track_blackjack_consumable
‪function track_blackjack_consumable()
Definition: _blackjack_challenges.gsc:323
‪challenge_kills
‪function challenge_kills(data)
Definition: _blackjack_challenges.gsc:135
‪start_gametype
‪function start_gametype()
Definition: _blackjack_challenges.gsc:33
‪REGISTER_SYSTEM
‪#define REGISTER_SYSTEM(__sys, __func_init_preload, __reqs)
Definition: shared.gsh:204
‪register_hero_ability_kill_event
‪function register_hero_ability_kill_event(event_func)
Definition: scoreevents_shared.gsc:323
‪set_challenge_stat
‪function set_challenge_stat(stat_name, stat_value)
Definition: _blackjack_challenges.gsc:188
‪get_challenge_stat
‪function get_challenge_stat(stat_name)
Definition: _blackjack_challenges.gsc:183
‪challenge_game_ended
‪function challenge_game_ended(data)
Definition: _blackjack_challenges.gsc:281
‪challenge_round_ended
‪function challenge_round_ended(data)
Definition: _blackjack_challenges.gsc:302
‪on_connect
‪function on_connect()
Definition: _arena.gsc:20