‪Black Ops 3 Source Code Explorer  0.1
‪An script explorer for Black Ops 3 by ZeRoY
_ability_power.gsc
Go to the documentation of this file.
1 #using scripts\codescripts\struct;
2 #using scripts\shared\callbacks_shared;
3 #using scripts\shared\flagsys_shared;
4 #using scripts\shared\hud_util_shared;
5 #using scripts\shared\system_shared;
6 #using scripts\shared\abilities\_ability_gadgets;
7 #using scripts\shared\abilities\_ability_player;
8 #using scripts\shared\abilities\_ability_util;
9 
10 #insert scripts\shared\shared.gsh;
11 #insert scripts\shared\abilities\_ability_util.gsh;
12 
13 #namespace ability_power;
14 
15 ‪REGISTER_SYSTEM( "ability_power", &‪__init__, undefined )
16 
17 function ‪__init__()
18 {
20 }
21 
22 //---------------------------------------------------------
23 // power and gadget activation
24 
26 {
27 }
28 
29 function ‪power_is_hero_ability( gadget )
30 {
31  return gadget.gadget_type != ‪GADGET_TYPE_NONE;
32 }
33 
34 function ‪is_weapon_or_variant_same_as_gadget( weapon, gadget )
35 {
36  if ( weapon == gadget )
37  {
38  return true;
39  }
40 
41  if ( isdefined( level.weaponLightningGun ) && gadget == level.weaponLightningGun )
42  {
43  if ( isdefined( level.weaponLightningGunArc ) && weapon == level.weaponLightningGunArc )
44  {
45  return true;
46  }
47  }
48 
49  return false;
50 }
51 
52 function ‪power_gain_event_score( eAttacker, score, weapon, hero_restricted )
53 {
54  if( score > 0 )
55  {
56  for ( slot = ‪GADGET_HELD_0; slot < ‪GADGET_HELD_COUNT; slot++ )
57  {
58  gadget = self._gadgets_player[slot];
59 
60  if ( isdefined( gadget ) )
61  {
62  ignoreSelf = gadget.gadget_powerGainScoreIgnoreSelf;
63 
64  if ( isdefined( weapon ) && ignoreSelf && ‪is_weapon_or_variant_same_as_gadget( weapon, gadget ) )
65  {
66  continue;
67  }
68 
69  ignoreWhenActive = gadget.gadget_powerGainScoreIgnoreWhenActive;
70 
71  if ( ignoreWhenActive && self GadgetIsActive( slot ) )
72  {
73  continue;
74  }
75 
76  if ( isdefined( hero_restricted ) && hero_restricted && ‪power_is_hero_ability( gadget ) )
77  {
78  continue;
79  }
80 
81  scoreFactor = gadget.gadget_powerGainScoreFactor;
82  if ( isdefined( self.gadgetThiefActive ) && self.gadgetThiefActive == true )
83  {
84  continue; // handled exclusively by gadget_thief
85  }
86 
87  gametypeFactor = GetGametypeSetting( "scoreHeroPowerGainFactor" );
88 
89  perkFactor = 1.0;
90  if ( self hasperk( "specialty_overcharge" ) )
91  {
92  perkFactor = GetDvarFloat( "gadgetPowerOverchargePerkScoreFactor" );
93  }
94 
95  if ( scoreFactor > 0 && gametypeFactor > 0 )
96  {
97  gainToAdd = score * scoreFactor * gametypeFactor * perkFactor;
98  self ‪power_gain_event( slot, eAttacker, gainToAdd, "score" );
99  }
100  }
101  }
102  }
103 }
104 
105 function ‪power_gain_event_damage_actor( eAttacker )
106 {
107  baseGain = 0.0;
108 
109  if( baseGain > 0 )
110  {
111  for ( slot = ‪GADGET_HELD_0; slot < ‪GADGET_HELD_COUNT; slot++ )
112  {
113  if ( IsDefined( self._gadgets_player[slot] ) )
114  {
115  self ‪power_gain_event( slot, eAttacker, baseGain, "damaged actor" );
116  }
117  }
118  }
119 }
120 
121 function ‪power_gain_event_killed_actor( eAttacker, meansOfDeath )
122 {
123  baseGain = 5.0;
124 
125  for ( slot = ‪GADGET_HELD_0; slot < ‪GADGET_HELD_COUNT; slot++ )
126  {
127  if ( IsDefined( self._gadgets_player[slot] ) )
128  {
129  if ( meansOfDeath == "MOD_MELEE_ASSASSINATE" && self ‪ability_util::gadget_is_camo_suit_on() )
130  {
131  if ( self._gadgets_player[slot].gadget_powertakedowngain > 0 )
132  {
133  source = "assassinate actor";
134  self ‪power_gain_event( slot, eAttacker, self._gadgets_player[slot].gadget_powertakedowngain, source );
135  }
136  }
137 
138  if ( self._gadgets_player[slot].gadget_powerreplenishfactor > 0 )
139  {
140  gainToAdd = baseGain * self._gadgets_player[slot].gadget_powerreplenishfactor;
141  if ( gainToAdd > 0 )
142  {
143  source = "killed actor";
144  self ‪power_gain_event( slot, eAttacker, gainToAdd, source );
145  }
146  }
147  }
148  }
149 }
150 
151 function ‪power_gain_event( slot, eAttacker, val, source )
152 {
153  if ( !isdefined( self ) || !isalive( self ) )
154  {
155  return;
156  }
157 
158  powerToAdd = val;
159 
160  if ( powerToAdd > 0.1 || powerToAdd < -0.1 )
161  {
162  powerLeft = self GadgetPowerChange( slot, powerToAdd );
163  }
164 }
165 
166 function ‪power_loss_event_took_damage( eAttacker, eInflictor, weapon, sMeansOfDeath, iDamage )
167 {
168  baseLoss = iDamage;
169 
170  for ( slot = ‪GADGET_HELD_0; slot < ‪GADGET_HELD_COUNT; slot++ )
171  {
172  if ( IsDefined( self._gadgets_player[slot] ) )
173  {
174  if ( self GadgetIsActive( slot ) )
175  {
176  powerLoss = baseLoss * self._gadgets_player[slot].gadget_powerOnLossOnDamage;
177  if ( powerLoss > 0 )
178  {
179  self ‪power_loss_event( slot, eAttacker, powerLoss, "took damage with power on" );
180  }
181 
182  if ( self._gadgets_player[slot].gadget_flickerOnDamage > 0 )
183  {
184  self ‪ability_gadgets::SetFlickering( slot, self._gadgets_player[slot].gadget_flickerOnDamage );
185  }
186  }
187  else
188  {
189  powerLoss = baseLoss * self._gadgets_player[slot].gadget_powerOffLossOnDamage;
190  if ( powerLoss > 0 )
191  {
192  self ‪power_loss_event( slot, eAttacker, powerLoss, "took damage" );
193  }
194  }
195  }
196  }
197 }
198 
199 function ‪power_loss_event( slot, eAttacker, val, source )
200 {
201  powerToRemove = -val;
202 
203  if ( powerToRemove > 0.1 || powerToRemove < -0.1 )
204  {
205  powerLeft = self GadgetPowerChange( slot, powerToRemove );
206  }
207 }
208 
210 {
211  powerLeft = self GadgetPowerChange( slot, 0 );
212  powerLeft = self GadgetPowerChange( slot, -powerLeft );
213 }
214 
216 {
217  velocity = self GetVelocity();
218  speedsq = lengthsquared( velocity );
219 
220  return speedsq > self._gadgets_player.gadget_powermovespeed * self._gadgets_player.gadget_powermovespeed;
221 }
222 
223 function ‪power_consume_timer_think( slot, weapon )
224 {
225  self endon( "disconnect" );
226  self endon( "death" );
227 
228  time = GetTime();
229 
230  while ( 1 )
231  {
232  wait( 0.1 );
233 
234  if ( !IsDefined( self._gadgets_player[slot] ) )
235  {
236  return;
237  }
238 
239  if ( !self GadgetIsActive( slot ) )
240  {
241  return;
242  }
243 
244  currentTime = GetTime();
245  interval = currentTime - time;
246  time = currentTime;
247  powerConsumpted = 0;
248 
249  //sprint
250  if( self IsOnGround() )
251  {
252  if ( self._gadgets_player[slot].gadget_powersprintloss > 0 && self IsSprinting() )
253  {
254  powerConsumpted += 1.0 * interval / 1000 * self._gadgets_player[slot].gadget_powersprintloss;
255  }
256  //move
257  else if ( self._gadgets_player[slot].gadget_powermoveloss && self ‪IsMovingPowerloss() )
258  {
259  powerConsumpted += 1.0 * interval / 1000 * self._gadgets_player[slot].gadget_powermoveloss;
260  }
261  }
262 
263  //--jump
264  //--juke
265  //--melee
266  //--attack
267 
268  if ( powerConsumpted > 0.1 )
269  {
270  self ‪power_loss_event( slot, self, powerConsumpted, "consume" );
271  if ( self._gadgets_player[slot].gadget_flickerOnPowerloss > 0 )
272  {
273  self ‪ability_gadgets::SetFlickering( slot, self._gadgets_player[slot].gadget_flickerOnPowerloss );
274  }
275  }
276  }
277 }
‪power_gain_event_killed_actor
‪function power_gain_event_killed_actor(eAttacker, meansOfDeath)
Definition: _ability_power.gsc:121
‪power_gain_event
‪function power_gain_event(slot, eAttacker, val, source)
Definition: _ability_power.gsc:151
‪SetFlickering
‪function SetFlickering(slot, length)
Definition: _ability_gadgets.gsc:37
‪GADGET_HELD_0
‪#define GADGET_HELD_0
Definition: _ability_util.gsh:59
‪power_drain_completely
‪function power_drain_completely(slot)
Definition: _ability_power.gsc:209
‪IsMovingPowerloss
‪function IsMovingPowerloss()
Definition: _ability_power.gsc:215
‪power_loss_event
‪function power_loss_event(slot, eAttacker, val, source)
Definition: _ability_power.gsc:199
‪power_loss_event_took_damage
‪function power_loss_event_took_damage(eAttacker, eInflictor, weapon, sMeansOfDeath, iDamage)
Definition: _ability_power.gsc:166
‪power_gain_event_damage_actor
‪function power_gain_event_damage_actor(eAttacker)
Definition: _ability_power.gsc:105
‪on_player_connect
‪function on_player_connect()
Definition: _ability_power.gsc:25
‪GADGET_HELD_COUNT
‪#define GADGET_HELD_COUNT
Definition: _ability_util.gsh:62
‪gadget_is_camo_suit_on
‪function gadget_is_camo_suit_on()
Definition: _ability_util.gsc:40
‪REGISTER_SYSTEM
‪#define REGISTER_SYSTEM(__sys, __func_init_preload, __reqs)
Definition: shared.gsh:204
‪power_is_hero_ability
‪function power_is_hero_ability(gadget)
Definition: _ability_power.gsc:29
‪power_gain_event_score
‪function power_gain_event_score(eAttacker, score, weapon, hero_restricted)
Definition: _ability_power.gsc:52
‪__init__
‪function __init__()
Definition: _ability_power.gsc:17
‪is_weapon_or_variant_same_as_gadget
‪function is_weapon_or_variant_same_as_gadget(weapon, gadget)
Definition: _ability_power.gsc:34
‪on_connect
‪function on_connect()
Definition: _arena.gsc:20
‪power_consume_timer_think
‪function power_consume_timer_think(slot, weapon)
Definition: _ability_power.gsc:223
‪GADGET_TYPE_NONE
‪#define GADGET_TYPE_NONE
Definition: _ability_util.gsh:4