‪Black Ops 3 Source Code Explorer  0.1
‪An script explorer for Black Ops 3 by ZeRoY
_zm_hero_weapon.gsc
Go to the documentation of this file.
1 #using scripts\codescripts\struct;
2 
3 #using scripts\shared\callbacks_shared;
4 #using scripts\shared\clientfield_shared;
5 #using scripts\shared\laststand_shared;
6 #using scripts\shared\math_shared;
7 #using scripts\shared\util_shared;
8 #using scripts\shared\system_shared;
9 
10 #insert scripts\shared\shared.gsh;
11 
12 #using scripts\shared\abilities\_ability_player;
13 #using scripts\shared\abilities\_ability_util;
14 
15 #insert scripts\shared\abilities\_ability_util.gsh;
16 
17 #using scripts\zm\_zm_audio;
18 #using scripts\zm\_zm_equipment;
19 #using scripts\zm\_zm_laststand;
20 #using scripts\zm\_zm_pers_upgrades_functions;
21 #using scripts\zm\_zm_score;
22 #using scripts\zm\_zm_utility;
23 #using scripts\zm\_zm_weapons;
24 
25 #insert scripts\zm\_zm_utility.gsh;
26 
27 #namespace zm_hero_weapon;
28 
29 //
30 // General hero weapon support
31 //
32 
33 #define HERO_STATE_HIDDEN 0
34 #define HERO_STATE_CHARGING 1
35 #define HERO_STATE_READY 2
36 #define HERO_STATE_INUSE 3
37 #define HERO_STATE_UNAVAILABLE 4
38 
39 // Some of these values may need to be specified on a per-weapon basis at some point, but for now we're just using the values from the sword
40 
41 #define HERO_MINPOWER 0
42 #define HERO_MAXPOWER 100
43 
44 #define HERO_CLIENTFIELD_POWER "zmhud.swordEnergy"
45 #define HERO_CLIENTFIELD_POWER_FLASH "zmhud.swordChargeUpdate"
46 #define HERO_CLIENTFIELD_STATE "zmhud.swordState"
47 
48 #precache( "string", "ZOMBIE_HERO_WEAPON_HINT" );
49 
50 ‪REGISTER_SYSTEM( "zm_hero_weapons", &‪__init__, undefined )
51 
52 function ‪__init__()
53 {
54  ‪DEFAULT( level._hero_weapons, [] );
55 
57 
58  // NOTE: should only be defined here all individual weapons should register using register_hero_recharge_event()
59  level.hero_power_update = &‪hero_power_event_callback;
60 
62 }
63 
64 function ‪gadget_hero_weapon_on_activate( slot, weapon )
65 {
66 }
67 
68 function ‪gadget_hero_weapon_on_off( slot, weapon )
69 {
70  self thread ‪watch_for_glitches( slot, weapon );
71 }
72 
73 function ‪watch_for_glitches( slot, weapon )
74 {
75  wait 1;
76  if ( isdefined(self) )
77  {
78  w_current = self GetCurrentWeapon();
79 
80  if ( IsDefined(w_current) && ‪zm_utility::is_hero_weapon( w_current ) )
81  {
82  self.hero_power = self GadgetPowerGet( 0 );
83  if ( self.hero_power <= 0 )
84  {
86  self.i_tried_to_glitch_the_hero_weapon = 1;
87  //self playlocalsound( level.zmb_laugh_alias );
88  }
89  }
90  }
91 }
92 
93 
94 
95 function ‪register_hero_weapon( weapon_name )
96 {
97  weaponNone = GetWeapon( "none" );
98 
99  weapon = GetWeapon( weapon_name );
100 
101  if ( weapon != weaponNone )
102  {
103  hero_weapon = SpawnStruct();
104  hero_weapon.weapon = weapon;
105  hero_weapon.give_fn = &‪default_give;
106  hero_weapon.take_fn = &‪default_take;
107  hero_weapon.wield_fn = &‪default_wield;
108  hero_weapon.unwield_fn = &‪default_unwield;
109  hero_weapon.power_full_fn = &‪default_power_full;
110  hero_weapon.power_empty_fn = &‪default_power_empty;
111 
112  ‪DEFAULT( level._hero_weapons, [] );
113  level._hero_weapons[weapon] = hero_weapon;
115  }
116 }
117 
118 function ‪register_hero_weapon_give_take_callbacks( weapon_name, give_fn = &‪default_give, take_fn = &‪default_take )
119 {
120  weaponNone = GetWeapon( "none" );
121  weapon = GetWeapon( weapon_name );
122  if ( weapon != weaponNone && IsDefined(level._hero_weapons[weapon]) )
123  {
124  level._hero_weapons[weapon].give_fn = give_fn;
125  level._hero_weapons[weapon].take_fn = take_fn;
126  }
127 }
128 
129 function ‪default_give( weapon )
130 {
131  power = self GadgetPowerGet( 0 );
132  if( power < ‪HERO_MAXPOWER )
133  {
135  }
136  else
137  {
139  }
140 }
141 
142 function ‪default_take( weapon )
143 {
145 }
146 
148 {
149  weaponNone = GetWeapon( "none" );
150  weapon = GetWeapon( weapon_name );
151  if ( weapon != weaponNone && IsDefined(level._hero_weapons[weapon]) )
152  {
153  level._hero_weapons[weapon].wield_fn = wield_fn;
154  level._hero_weapons[weapon].unwield_fn = unwield_fn;
155  }
156 }
157 
158 function ‪default_wield( weapon )
159 {
161 }
162 
163 function ‪default_unwield( weapon )
164 {
166 }
167 
168 function ‪register_hero_weapon_power_callbacks( weapon_name, power_full_fn = &‪default_power_full, power_empty_fn = &‪default_power_empty )
169 {
170  weaponNone = GetWeapon( "none" );
171  weapon = GetWeapon( weapon_name );
172  if ( weapon != weaponNone && IsDefined(level._hero_weapons[weapon]) )
173  {
174  level._hero_weapons[weapon].power_full_fn = power_full_fn;
175  level._hero_weapons[weapon].power_empty_fn = power_empty_fn;
176  }
177 }
178 
179 function ‪default_power_full( weapon )
180 {
182  self thread ‪zm_equipment::show_hint_text( &"ZOMBIE_HERO_WEAPON_HINT", 2 );
183 }
184 
185 function ‪default_power_empty( weapon )
186 {
188 }
189 
190 function ‪set_hero_weapon_state( w_weapon, state )
191 {
192  self.hero_weapon_state = state;
194 }
195 
197 {
199  self thread ‪watch_hero_weapon_give();
200  self thread ‪watch_hero_weapon_take();
201  self thread ‪watch_hero_weapon_change();
202 }
203 
205 {
206  self notify("watch_hero_weapon_give");
207  self endon("watch_hero_weapon_give");
208  self endon( "disconnect" );
209 
210  while ( true )
211  {
212  self waittill( "weapon_give", w_weapon );
213  if ( IsDefined(w_weapon) && ‪zm_utility::is_hero_weapon( w_weapon ) )
214  {
215  self thread ‪watch_hero_power( w_weapon );
216  self [[level._hero_weapons[w_weapon].give_fn]]( w_weapon );
217  }
218  }
219 }
220 
222 {
223  self notify("watch_hero_weapon_take");
224  self endon("watch_hero_weapon_take");
225  self endon( "disconnect" );
226 
227  while ( true )
228  {
229  self waittill( "weapon_take", w_weapon );
230  if ( IsDefined( w_weapon ) && ‪zm_utility::is_hero_weapon( w_weapon ) )
231  {
232  self [[level._hero_weapons[w_weapon].take_fn]]( w_weapon );
233  self notify("stop_watch_hero_power");
234  }
235  }
236 }
237 
239 {
240  self notify("watch_hero_weapon_change");
241  self endon("watch_hero_weapon_change");
242  self endon( "disconnect" );
243 
244  while ( true )
245  {
246  self waittill( "weapon_change", w_current, w_previous );
247  if ( self.sessionstate != "spectator" )
248  {
249  if ( IsDefined(w_previous) && ‪zm_utility::is_hero_weapon( w_previous ) )
250  {
251  self [[level._hero_weapons[w_previous].unwield_fn]]( w_previous );
252 
253  if( self GadgetPowerGet( 0 ) == 100 ) //player didn't use any of the gadget power
254  {
255  if( self HasWeapon( w_previous ) )
256  {
257  self SetWeaponAmmoClip( w_previous, w_previous.clipSize );
258  self [[level._hero_weapons[w_previous].power_full_fn]]( w_previous );
259  }
260  }
261  }
262  if ( IsDefined(w_current) && ‪zm_utility::is_hero_weapon( w_current ) )
263  {
264  self [[level._hero_weapons[w_current].wield_fn]]( w_current );
265  }
266  }
267  }
268 }
269 
270 // self == player
271 function ‪watch_hero_power( w_weapon )
272 {
273  self notify("watch_hero_power");
274  self endon("watch_hero_power");
275  self endon("stop_watch_hero_power");
276  self endon( "disconnect" );
277 
278  ‪DEFAULT( self.hero_power_prev, -1 );
279 
280  while ( true )
281  {
282  self.hero_power = self GadgetPowerGet( 0 );
283  self ‪clientfield::set_player_uimodel( ‪HERO_CLIENTFIELD_POWER, self.hero_power / 100 );
284  if ( self.hero_power != self.hero_power_prev )
285  {
286  self.hero_power_prev = self.hero_power;
287  if(self.hero_power >= ‪HERO_MAXPOWER )
288  {
289  self [[level._hero_weapons[w_weapon].power_full_fn]]( w_weapon );
290  }
291  else if(self.hero_power <= ‪HERO_MINPOWER )
292  {
293  self [[level._hero_weapons[w_weapon].power_empty_fn]]( w_weapon );
294  }
295  }
296 
298  }
299 }
300 
301 // self == player
303 {
304  self endon( "stop_draining_hero_weapon" );
305 
307  while ( isdefined( self ) )
308  {
309  n_rate = 1.0;
310 
311  if ( isdefined(w_weapon.gadget_power_usage_rate) )
312  n_rate = w_weapon.gadget_power_usage_rate;
313 
314  self.hero_power -= ‪SERVER_FRAME * n_rate;
315  self.hero_power = ‪math::clamp( self.hero_power, ‪HERO_MINPOWER, ‪HERO_MAXPOWER );
316  if ( self.hero_power != self.hero_power_prev )
317  {
318  self GadgetPowerSet( 0, self.hero_power );
319  }
320 
322  }
323 }
324 
325 // ------------------------------------------------------------------------------------------------------------
326 // Register hero weapon recharge function
327 // ------------------------------------------------------------------------------------------------------------
328 function ‪register_hero_recharge_event( w_hero, func )
329 {
330  if ( !isdefined( level.a_func_hero_power_update ) )
331  {
332  level.a_func_hero_power_update = [];
333  }
334 
335  if ( !isdefined( level.a_func_hero_power_update[ w_hero ] ) )
336  {
337  level.a_func_hero_power_update[ w_hero ] = func;
338  }
339 }
340 
341 // level.hero_power_update callback function
342 function ‪hero_power_event_callback( e_player, ai_enemy )
343 {
344  w_hero = e_player.current_hero_weapon;
345 
346  if( isdefined( level.a_func_hero_power_update ) && isdefined( level.a_func_hero_power_update[ w_hero ] ) )
347  {
348  level [[ level.a_func_hero_power_update[ w_hero ] ]]( e_player, ai_enemy );
349  }
350  else
351  {
352  level ‪hero_power_event(e_player, ai_enemy);
353  }
354 }
355 
356 function ‪hero_power_event( player, ai_enemy )
357 {
358  if( isdefined( player ) && player ‪zm_utility::has_player_hero_weapon() && !‪IS_EQUAL( player.hero_weapon_state, ‪HERO_STATE_INUSE ) && !‪IS_TRUE( player.disable_hero_power_charging ) )
359  {
360  player ‪player_hero_power_event( ai_enemy );
361  }
362 }
363 
364 function ‪player_hero_power_event( ai_enemy )
365 {
366  if( isdefined( self ) ) //( !IS_TRUE( player.usingsword ) && !IS_TRUE( player.autokill_glaive_active) ) && isdefined( player.current_sword ) )
367  {
368  w_current = self ‪zm_utility::get_player_hero_weapon();
369  if( isdefined( ai_enemy.heroweapon_kill_power ) )
370  {
371  perkFactor = 1.0;
372  if ( self hasperk( "specialty_overcharge" ) )
373  {
374  perkFactor = GetDvarFloat( "gadgetPowerOverchargePerkScoreFactor" );
375  }
376  if ( ‪IS_TRUE( self.i_tried_to_glitch_the_hero_weapon ) )
377  {
378  //perkFactor *= 0.75;
379  }
380 
381  self.hero_power = self.hero_power + perkFactor * ( ai_enemy.heroweapon_kill_power );
382  self.hero_power = ‪math::clamp( self.hero_power, ‪HERO_MINPOWER, ‪HERO_MAXPOWER );
383  if ( self.hero_power != self.hero_power_prev )
384  {
385  self GadgetPowerSet( 0, self.hero_power );
386  self ‪clientfield::set_player_uimodel( ‪HERO_CLIENTFIELD_POWER, self.hero_power / 100 );
388  }
389  }
390  }
391 }
392 
394 {
395  if( isdefined( self.current_hero_weapon ) )
396  {
397  self notify( "weapon_take", self.current_hero_weapon );
398  self GadgetPowerSet( 0, 0 );
399  }
400 }
401 
403 {
404  return ‪IS_EQUAL( self.hero_weapon_state, ‪HERO_STATE_INUSE );
405 }
406 
‪default_power_empty
‪function default_power_empty(weapon)
Definition: _zm_hero_weapon.gsc:185
‪HERO_CLIENTFIELD_POWER_FLASH
‪#define HERO_CLIENTFIELD_POWER_FLASH
Definition: _zm_hero_weapon.gsc:45
‪watch_for_glitches
‪function watch_for_glitches(slot, weapon)
Definition: _zm_hero_weapon.gsc:73
‪HERO_CLIENTFIELD_STATE
‪#define HERO_CLIENTFIELD_STATE
Definition: _zm_hero_weapon.gsc:46
‪hero_power_event
‪function hero_power_event(player, ai_enemy)
Definition: _zm_hero_weapon.gsc:356
‪HERO_STATE_CHARGING
‪#define HERO_STATE_CHARGING
Definition: _zm_hero_weapon.gsc:34
‪GADGET_TYPE_HERO_WEAPON
‪#define GADGET_TYPE_HERO_WEAPON
Definition: _ability_util.gsh:18
‪register_hero_weapon_give_take_callbacks
‪function register_hero_weapon_give_take_callbacks(weapon_name, give_fn=&default_give, take_fn=&default_take)
Definition: _zm_hero_weapon.gsc:118
‪gadget_hero_weapon_on_off
‪function gadget_hero_weapon_on_off(slot, weapon)
Definition: _zm_hero_weapon.gsc:68
‪watch_hero_power
‪function watch_hero_power(w_weapon)
Definition: _zm_hero_weapon.gsc:271
‪watch_hero_weapon_change
‪function watch_hero_weapon_change()
Definition: _zm_hero_weapon.gsc:238
‪HERO_MAXPOWER
‪#define HERO_MAXPOWER
Definition: _zm_hero_weapon.gsc:42
‪get_player_hero_weapon
‪function get_player_hero_weapon()
Definition: _zm_utility.gsc:4430
‪IS_TRUE
‪#define IS_TRUE(__a)
Definition: shared.gsh:251
‪register_hero_weapon_for_level
‪function register_hero_weapon_for_level(weaponname)
Definition: _zm_utility.gsc:4392
‪default_unwield
‪function default_unwield(weapon)
Definition: _zm_hero_weapon.gsc:163
‪register_hero_weapon
‪function register_hero_weapon(weapon_name)
Definition: _zm_hero_weapon.gsc:95
‪watch_hero_weapon_give
‪function watch_hero_weapon_give()
Definition: _zm_hero_weapon.gsc:204
‪default_power_full
‪function default_power_full(weapon)
Definition: _zm_hero_weapon.gsc:179
‪take_hero_weapon
‪function take_hero_weapon()
Definition: _zm_hero_weapon.gsc:393
‪switch_back_primary_weapon
‪function switch_back_primary_weapon(oldprimary, immediate=false)
Definition: _zm_weapons.gsc:280
‪DEFAULT
‪#define DEFAULT(__var, __default)
Definition: shared.gsh:270
‪HERO_CLIENTFIELD_POWER
‪#define HERO_CLIENTFIELD_POWER
Definition: _zm_hero_weapon.gsc:44
‪on_spawned
‪function on_spawned(func, obj)
Definition: callbacks_shared.csc:245
‪register_hero_weapon_power_callbacks
‪function register_hero_weapon_power_callbacks(weapon_name, power_full_fn=&default_power_full, power_empty_fn=&default_power_empty)
Definition: _zm_hero_weapon.gsc:168
‪HERO_STATE_READY
‪#define HERO_STATE_READY
Definition: _zm_hero_weapon.gsc:35
‪watch_hero_weapon_take
‪function watch_hero_weapon_take()
Definition: _zm_hero_weapon.gsc:221
‪on_player_spawned
‪function on_player_spawned()
Definition: _zm_hero_weapon.gsc:196
‪show_hint_text
‪function show_hint_text(str_text_to_show, b_should_blink=false, str_turn_off_notify=HINT_TEXT_TURN_OFF_NOTIFY, n_display_time=HINT_TEXT_DISPLAY_TIME_DEFAULT)
Definition: _util.gsc:1042
‪register_gadget_activation_callbacks
‪function register_gadget_activation_callbacks(type, turn_on, turn_off)
Definition: _ability_player.gsc:237
‪set_hero_weapon_state
‪function set_hero_weapon_state(w_weapon, state)
Definition: _zm_hero_weapon.gsc:190
‪HERO_STATE_HIDDEN
‪#define HERO_STATE_HIDDEN
Definition: _zm_hero_weapon.gsc:33
‪player_hero_power_event
‪function player_hero_power_event(ai_enemy)
Definition: _zm_hero_weapon.gsc:364
‪SERVER_FRAME
‪#define SERVER_FRAME
Definition: shared.gsh:264
‪is_hero_weapon_in_use
‪function is_hero_weapon_in_use()
Definition: _zm_hero_weapon.gsc:402
‪default_give
‪function default_give(weapon)
Definition: _zm_hero_weapon.gsc:129
‪REGISTER_SYSTEM
‪#define REGISTER_SYSTEM(__sys, __func_init_preload, __reqs)
Definition: shared.gsh:204
‪increment_uimodel
‪function increment_uimodel(str_field_name, n_increment_count=1)
Definition: clientfield_shared.gsc:136
‪HERO_MINPOWER
‪#define HERO_MINPOWER
Definition: _zm_hero_weapon.gsc:41
‪continue_draining_hero_weapon
‪function continue_draining_hero_weapon(w_weapon)
Definition: _zm_hero_weapon.gsc:302
‪default_take
‪function default_take(weapon)
Definition: _zm_hero_weapon.gsc:142
‪is_hero_weapon
‪function is_hero_weapon(weapon)
Definition: _zm_utility.gsc:4408
‪IS_EQUAL
‪#define IS_EQUAL(__a, __b)
Definition: shared.gsh:250
‪HERO_STATE_INUSE
‪#define HERO_STATE_INUSE
Definition: _zm_hero_weapon.gsc:36
‪gadget_hero_weapon_on_activate
‪function gadget_hero_weapon_on_activate(slot, weapon)
Definition: _zm_hero_weapon.gsc:64
‪hero_power_event_callback
‪function hero_power_event_callback(e_player, ai_enemy)
Definition: _zm_hero_weapon.gsc:342
‪set_player_uimodel
‪function set_player_uimodel(str_field_name, n_value)
Definition: clientfield_shared.gsc:75
‪register_hero_weapon_wield_unwield_callbacks
‪function register_hero_weapon_wield_unwield_callbacks(weapon_name, wield_fn=&default_wield, unwield_fn=&default_unwield)
Definition: _zm_hero_weapon.gsc:147
‪default_wield
‪function default_wield(weapon)
Definition: _zm_hero_weapon.gsc:158
‪clamp
‪function clamp(val, val_min, val_max)
Definition: math_shared.csc:16
‪__init__
‪function __init__()
Definition: _zm_hero_weapon.gsc:52
‪register_hero_recharge_event
‪function register_hero_recharge_event(w_hero, func)
Definition: _zm_hero_weapon.gsc:328
‪has_player_hero_weapon
‪function has_player_hero_weapon()
Definition: _zm_utility.gsc:4459
‪WAIT_SERVER_FRAME
‪#define WAIT_SERVER_FRAME
Definition: shared.gsh:265