warscript 0.0.1-dev.46a1ede → 0.0.1-dev.4753736

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (159) hide show
  1. package/attributes.d.ts +5 -0
  2. package/attributes.lua +8 -1
  3. package/binarywriter.lua +12 -0
  4. package/config.d.ts +5 -0
  5. package/config.lua +10 -0
  6. package/core/types/effect.d.ts +1 -3
  7. package/core/types/effect.lua +26 -29
  8. package/core/types/frame.lua +24 -21
  9. package/core/types/player.lua +3 -1
  10. package/core/types/playerCamera.d.ts +2 -0
  11. package/core/types/playerCamera.lua +123 -5
  12. package/core/types/sound.d.ts +17 -24
  13. package/core/types/sound.lua +99 -24
  14. package/core/types/tileCell.d.ts +9 -0
  15. package/core/types/tileCell.lua +92 -0
  16. package/core/types/timer.d.ts +8 -8
  17. package/core/types/timer.lua +39 -23
  18. package/core/util.lua +6 -1
  19. package/decl/native.d.ts +846 -790
  20. package/engine/behavior.d.ts +5 -0
  21. package/engine/behavior.lua +106 -27
  22. package/engine/behaviour/ability/apply-buff.lua +1 -1
  23. package/engine/behaviour/ability/apply-unit-behavior.lua +1 -0
  24. package/engine/behaviour/ability/damage.d.ts +9 -3
  25. package/engine/behaviour/ability/damage.lua +26 -38
  26. package/engine/behaviour/ability/emulate-impact.d.ts +1 -1
  27. package/engine/behaviour/ability/emulate-impact.lua +18 -3
  28. package/engine/behaviour/ability/restore-mana.d.ts +1 -1
  29. package/engine/behaviour/ability/restore-mana.lua +6 -6
  30. package/engine/behaviour/ability.d.ts +5 -1
  31. package/engine/behaviour/ability.lua +26 -21
  32. package/engine/behaviour/unit/stun-immunity.d.ts +7 -3
  33. package/engine/behaviour/unit/stun-immunity.lua +52 -27
  34. package/engine/behaviour/unit.d.ts +34 -0
  35. package/engine/behaviour/unit.lua +190 -4
  36. package/engine/buff.d.ts +17 -11
  37. package/engine/buff.lua +109 -83
  38. package/engine/internal/ability.d.ts +7 -1
  39. package/engine/internal/ability.lua +49 -9
  40. package/engine/internal/item/ability.lua +63 -11
  41. package/engine/internal/item+owner.lua +12 -6
  42. package/engine/internal/item.d.ts +6 -5
  43. package/engine/internal/item.lua +97 -26
  44. package/engine/internal/mechanics/ability-duration.lua +1 -1
  45. package/engine/internal/misc/damage-metadata-by-target.d.ts +2 -0
  46. package/engine/internal/misc/damage-metadata-by-target.lua +5 -0
  47. package/engine/internal/misc/frame-coordinates.d.ts +2 -0
  48. package/engine/internal/misc/frame-coordinates.lua +21 -0
  49. package/engine/internal/misc/get-terrain-z.d.ts +2 -0
  50. package/engine/internal/misc/get-terrain-z.lua +11 -0
  51. package/engine/internal/misc/player-local-handle.d.ts +2 -0
  52. package/engine/internal/misc/player-local-handle.lua +5 -0
  53. package/engine/internal/unit/ability.d.ts +35 -0
  54. package/engine/internal/unit/ability.lua +63 -1
  55. package/engine/internal/unit/allowed-targets.d.ts +1 -1
  56. package/engine/internal/unit/allowed-targets.lua +9 -1
  57. package/engine/internal/unit/order.d.ts +20 -0
  58. package/engine/internal/unit/order.lua +136 -0
  59. package/engine/internal/unit+ability.lua +10 -1
  60. package/engine/internal/unit+damage.d.ts +2 -11
  61. package/engine/internal/unit+damage.lua +10 -14
  62. package/engine/internal/unit+spellSteal.lua +1 -2
  63. package/engine/internal/unit-missile-launch.lua +18 -5
  64. package/engine/internal/unit.d.ts +32 -10
  65. package/engine/internal/unit.lua +257 -110
  66. package/engine/object-data/auxiliary/animation-name.d.ts +1 -0
  67. package/engine/object-data/auxiliary/animation-name.lua +16 -0
  68. package/engine/object-data/auxiliary/armor-type.d.ts +11 -0
  69. package/engine/object-data/auxiliary/armor-type.lua +46 -0
  70. package/engine/object-data/auxiliary/attachment-preset.d.ts +7 -2
  71. package/engine/object-data/auxiliary/attachment-preset.lua +4 -3
  72. package/engine/object-data/auxiliary/attack-type.d.ts +7 -8
  73. package/engine/object-data/auxiliary/attack-type.lua +42 -0
  74. package/engine/object-data/auxiliary/movement-type.d.ts +7 -7
  75. package/engine/object-data/auxiliary/movement-type.lua +22 -0
  76. package/engine/object-data/auxiliary/sound-eax.d.ts +10 -0
  77. package/engine/object-data/auxiliary/sound-eax.lua +2 -0
  78. package/engine/object-data/auxiliary/tech-tree-dependency.d.ts +1 -1
  79. package/engine/object-data/auxiliary/unit-attribute.d.ts +6 -0
  80. package/engine/object-data/auxiliary/unit-attribute.lua +9 -0
  81. package/engine/object-data/entry/ability-type/berserk.d.ts +2 -0
  82. package/engine/object-data/entry/ability-type/berserk.lua +13 -0
  83. package/engine/object-data/entry/ability-type/blank-configurable.lua +12 -1
  84. package/engine/object-data/entry/ability-type/carrion-swarm.d.ts +14 -0
  85. package/engine/object-data/entry/ability-type/carrion-swarm.lua +65 -0
  86. package/engine/object-data/entry/ability-type/disease-cloud.lua +2 -2
  87. package/engine/object-data/entry/ability-type/engineering-upgrade.lua +2 -2
  88. package/engine/object-data/entry/ability-type/ensnare.d.ts +12 -0
  89. package/engine/object-data/entry/ability-type/ensnare.lua +52 -0
  90. package/engine/object-data/entry/ability-type/feral-spirit.lua +2 -2
  91. package/engine/object-data/entry/ability-type/permanent-invisibility.d.ts +8 -0
  92. package/engine/object-data/entry/ability-type/permanent-invisibility.lua +26 -0
  93. package/engine/object-data/entry/ability-type/phase-shift.d.ts +10 -0
  94. package/engine/object-data/entry/ability-type/phase-shift.lua +39 -0
  95. package/engine/object-data/entry/ability-type/phoenix-morph.lua +4 -4
  96. package/engine/object-data/entry/ability-type/raise-dead.d.ts +17 -0
  97. package/engine/object-data/entry/ability-type/raise-dead.lua +78 -0
  98. package/engine/object-data/entry/ability-type/shock-wave.d.ts +4 -0
  99. package/engine/object-data/entry/ability-type/shock-wave.lua +26 -0
  100. package/engine/object-data/entry/ability-type/slow-poison.d.ts +10 -0
  101. package/engine/object-data/entry/ability-type/slow-poison.lua +58 -0
  102. package/engine/object-data/entry/ability-type/summon-quilbeast.lua +2 -2
  103. package/engine/object-data/entry/ability-type/summon-water-elemental.lua +2 -2
  104. package/engine/object-data/entry/ability-type/web.d.ts +12 -0
  105. package/engine/object-data/entry/ability-type/web.lua +52 -0
  106. package/engine/object-data/entry/ability-type.d.ts +19 -17
  107. package/engine/object-data/entry/ability-type.lua +85 -24
  108. package/engine/object-data/entry/buff-type/applicable.lua +18 -37
  109. package/engine/object-data/entry/buff-type.d.ts +6 -12
  110. package/engine/object-data/entry/buff-type.lua +13 -29
  111. package/engine/object-data/entry/destructible-type.d.ts +1 -1
  112. package/engine/object-data/entry/item-type.d.ts +1 -1
  113. package/engine/object-data/entry/item-type.lua +4 -4
  114. package/engine/object-data/entry/lightning-type.d.ts +1 -1
  115. package/engine/object-data/entry/sound-preset.d.ts +33 -0
  116. package/engine/object-data/entry/sound-preset.lua +140 -0
  117. package/engine/object-data/entry/unit-type.d.ts +21 -5
  118. package/engine/object-data/entry/unit-type.lua +214 -93
  119. package/engine/object-data/entry/upgrade.d.ts +1 -1
  120. package/engine/object-data/entry/upgrade.lua +4 -4
  121. package/engine/object-data/entry.d.ts +16 -14
  122. package/engine/object-data/entry.lua +60 -32
  123. package/engine/object-field/ability.d.ts +4 -4
  124. package/engine/object-field/ability.lua +7 -6
  125. package/engine/object-field/unit.d.ts +57 -3
  126. package/engine/object-field/unit.lua +207 -7
  127. package/engine/object-field.d.ts +17 -6
  128. package/engine/object-field.lua +188 -92
  129. package/engine/random.d.ts +9 -0
  130. package/engine/random.lua +13 -0
  131. package/engine/standard/entries/buff-type.d.ts +3 -0
  132. package/engine/standard/entries/buff-type.lua +3 -0
  133. package/engine/standard/entries/sound-preset.d.ts +10 -0
  134. package/engine/standard/entries/sound-preset.lua +10 -0
  135. package/engine/standard/fields/unit.d.ts +4 -0
  136. package/engine/standard/fields/unit.lua +7 -0
  137. package/engine/text-tag.d.ts +36 -2
  138. package/engine/text-tag.lua +249 -10
  139. package/engine/unit.d.ts +1 -0
  140. package/engine/unit.lua +1 -0
  141. package/objutil/buff.lua +1 -2
  142. package/objutil/unit.lua +8 -0
  143. package/package.json +2 -2
  144. package/patch-lualib.lua +1 -1
  145. package/utility/arrays.d.ts +2 -0
  146. package/utility/arrays.lua +11 -0
  147. package/utility/callback-array.d.ts +13 -0
  148. package/utility/callback-array.lua +46 -0
  149. package/utility/functions.d.ts +8 -0
  150. package/utility/functions.lua +13 -0
  151. package/utility/linked-set.d.ts +1 -0
  152. package/utility/linked-set.lua +3 -0
  153. package/utility/lua-maps.d.ts +15 -2
  154. package/utility/lua-maps.lua +53 -2
  155. package/utility/lua-sets.d.ts +2 -0
  156. package/utility/lua-sets.lua +7 -0
  157. package/utility/reflection.lua +11 -7
  158. package/core/types/order.d.ts +0 -25
  159. package/core/types/order.lua +0 -55
package/engine/buff.lua CHANGED
@@ -28,9 +28,6 @@ local ____math = require("math")
28
28
  local max = ____math.max
29
29
  local min = ____math.min
30
30
  local ____bonus = require("engine.internal.unit.bonus")
31
- local addOrUpdateOrRemoveUnitBonus = ____bonus.addOrUpdateOrRemoveUnitBonus
32
- local getUnitBonus = ____bonus.getUnitBonus
33
- local removeUnitBonus = ____bonus.removeUnitBonus
34
31
  local UnitBonusType = ____bonus.UnitBonusType
35
32
  local ____area_2Ddamage = require("engine.internal.mechanics.area-damage")
36
33
  local damageArea = ____area_2Ddamage.damageArea
@@ -102,12 +99,14 @@ local buffParametersKeys = {
102
99
  attackSpeedIncreaseFactor = true,
103
100
  movementSpeedIncreaseFactor = true,
104
101
  evasionProbability = true,
102
+ missProbability = true,
105
103
  damageFactor = true,
106
104
  receivedDamageFactor = true,
107
105
  receivedMagicDamageFactor = true,
108
106
  durationIncreaseOnAutoAttack = true,
109
107
  maximumDuration = true,
110
108
  maximumRemainingDuration = true,
109
+ turnsIntoGhost = true,
111
110
  stuns = true,
112
111
  ignoresStunImmunity = true,
113
112
  providesStunImmunity = true,
@@ -173,6 +172,7 @@ local function resolveAndSetNumberValue(buff, property, ability, level, value, d
173
172
  end
174
173
  end
175
174
  local buffBooleanParameters = {
175
+ "turnsIntoGhost",
176
176
  "stuns",
177
177
  "ignoresStunImmunity",
178
178
  "disablesAutoAttack",
@@ -301,7 +301,8 @@ buffHealingIntervalTimerCallback = function(buff)
301
301
  source:healTarget(buff[101], healingPerInterval)
302
302
  end
303
303
  end
304
- local buffDestroyEvent = __TS__New(Event)
304
+ local buffCreatedEvent = __TS__New(Event)
305
+ local buffBeingDestroyedEvent = __TS__New(Event)
305
306
  ____exports.Buff = __TS__Class()
306
307
  local Buff = ____exports.Buff
307
308
  Buff.name = "Buff"
@@ -320,7 +321,7 @@ function Buff.prototype.____constructor(self, _unit, typeIdOrTypeIds, polarityOr
320
321
  typeId = selectBuffTypeIdWithLeastDuration(typeIdOrTypeIds, _unit)
321
322
  polarity = resistanceTypeOrPolarity
322
323
  resistanceType = abilityOrParametersOrResistanceType
323
- if __TS__InstanceOf(parametersOrAbility, Ability) then
324
+ if __TS__InstanceOf(parametersOrAbility, Ability) or parametersOrAbility == nil then
324
325
  ability = parametersOrAbility
325
326
  else
326
327
  ability = nil
@@ -330,7 +331,7 @@ function Buff.prototype.____constructor(self, _unit, typeIdOrTypeIds, polarityOr
330
331
  typeId = typeIdOrTypeIds
331
332
  polarity = polarityOrTypeIdSelectionPolicy
332
333
  resistanceType = resistanceTypeOrPolarity
333
- if __TS__InstanceOf(abilityOrParametersOrResistanceType, Ability) then
334
+ if __TS__InstanceOf(abilityOrParametersOrResistanceType, Ability) or abilityOrParametersOrResistanceType == nil then
334
335
  ability = abilityOrParametersOrResistanceType
335
336
  parameters = parametersOrAbility
336
337
  else
@@ -339,7 +340,7 @@ function Buff.prototype.____constructor(self, _unit, typeIdOrTypeIds, polarityOr
339
340
  end
340
341
  end
341
342
  self.typeId = typeId
342
- if not __TS__InstanceOf(ability, Ability) then
343
+ if not (__TS__InstanceOf(ability, Ability) or ability == nil) then
343
344
  parameters = ability
344
345
  ability = nil
345
346
  end
@@ -367,14 +368,19 @@ function Buff.prototype.____constructor(self, _unit, typeIdOrTypeIds, polarityOr
367
368
  end
368
369
  self.polarity = resolveEnumValue(ability, level, polarity)
369
370
  self.resistanceType = resolveEnumValue(ability, level, resistanceType)
371
+ local missProbability = parameters and parameters.missProbability or defaultParameters.missProbability
372
+ if missProbability ~= nil then
373
+ missProbability = resolveNumberValue(ability, level, missProbability)
374
+ self[142] = missProbability
375
+ end
370
376
  local buffByTypeId = buffByTypeIdByUnit[_unit]
371
377
  if buffByTypeId == nil then
372
378
  buffByTypeId = {}
373
379
  buffByTypeIdByUnit[_unit] = buffByTypeId
374
380
  end
375
- local ____opt_13 = buffByTypeId[typeId]
376
- if ____opt_13 ~= nil then
377
- ____opt_13:destroy()
381
+ local ____opt_15 = buffByTypeId[typeId]
382
+ if ____opt_15 ~= nil then
383
+ ____opt_15:destroy()
378
384
  end
379
385
  local uniqueGroup = parameters and parameters.uniqueGroup or defaultParameters and defaultParameters.uniqueGroup
380
386
  if uniqueGroup ~= nil then
@@ -388,13 +394,16 @@ function Buff.prototype.____constructor(self, _unit, typeIdOrTypeIds, polarityOr
388
394
  level,
389
395
  duration,
390
396
  spellStealPriority,
391
- learnLevelMinimum
397
+ learnLevelMinimum,
398
+ missProbability
392
399
  ) then
400
+ self[100] = 1
393
401
  UnitBehavior.prototype.destroy(self)
394
402
  error(unsuccessfulApplicationMarker, 0)
395
403
  end
396
404
  local handle = BlzGetUnitAbility(_unit.handle, typeId)
397
405
  if handle == nil then
406
+ self[100] = 1
398
407
  UnitBehavior.prototype.destroy(self)
399
408
  error(unsuccessfulApplicationMarker, 0)
400
409
  end
@@ -410,13 +419,13 @@ function Buff.prototype.____constructor(self, _unit, typeIdOrTypeIds, polarityOr
410
419
  self[106] = BlzGetAbilityStringLevelField(self.handle, ABILITY_SLF_SPECIAL, 0)
411
420
  if parameters ~= nil or (next(defaultParameters)) ~= nil then
412
421
  for ____, buffBooleanParameter in ipairs(buffBooleanParameters) do
413
- local ____ability_22 = ability
414
- local ____level_23 = level
415
- local ____temp_21 = parameters and parameters[buffBooleanParameter]
416
- if ____temp_21 == nil then
417
- ____temp_21 = defaultParameters[buffBooleanParameter]
422
+ local ____ability_24 = ability
423
+ local ____level_25 = level
424
+ local ____temp_23 = parameters and parameters[buffBooleanParameter]
425
+ if ____temp_23 == nil then
426
+ ____temp_23 = defaultParameters[buffBooleanParameter]
418
427
  end
419
- if resolveBooleanValue(____ability_22, ____level_23, ____temp_21) then
428
+ if resolveBooleanValue(____ability_24, ____level_25, ____temp_23) then
420
429
  self[buffBooleanParameter] = true
421
430
  end
422
431
  end
@@ -495,19 +504,7 @@ function Buff.prototype.____constructor(self, _unit, typeIdOrTypeIds, polarityOr
495
504
  end
496
505
  self:onCreate()
497
506
  self[100] = 1
498
- end
499
- function Buff.prototype.getUnitBonus(self, bonusType)
500
- local ____opt_36 = self._bonusIdByBonusType
501
- local bonusId = ____opt_36 and ____opt_36[bonusType]
502
- return bonusId == nil and 0 or getUnitBonus(self._unit, bonusType, bonusId)
503
- end
504
- function Buff.prototype.addOrUpdateOrRemoveUnitBonus(self, bonusType, value)
505
- local bonusIdByBonusType = self._bonusIdByBonusType
506
- if bonusIdByBonusType == nil then
507
- bonusIdByBonusType = {}
508
- self._bonusIdByBonusType = bonusIdByBonusType
509
- end
510
- bonusIdByBonusType[bonusType] = addOrUpdateOrRemoveUnitBonus(self._unit, bonusType, bonusIdByBonusType[bonusType], value)
507
+ Event.invoke(buffCreatedEvent, self)
511
508
  end
512
509
  function Buff.prototype.flashEffect(self, widgetOrXOrParametersOrDuration, yOrParametersOrDuration, parametersOrDuration)
513
510
  if type(widgetOrXOrParametersOrDuration) == "number" and type(yOrParametersOrDuration) == "number" then
@@ -583,26 +580,27 @@ function Buff.prototype.onDestroy(self)
583
580
  behavior:destroy()
584
581
  end
585
582
  end
586
- if self[137] then
583
+ if self[139] then
584
+ unit:decrementInvulnerabilityCounter()
585
+ end
586
+ if self[138] then
587
587
  unit:decrementDisableAutoAttackCounter()
588
588
  end
589
- if self[135] then
590
- if self[136] then
589
+ if self[136] then
590
+ if self[137] then
591
591
  unit:decrementStunCounter()
592
592
  end
593
593
  unit:decrementStunCounter()
594
594
  end
595
+ if self[135] then
596
+ unit:decrementGhostCounter()
597
+ end
595
598
  if self._abilityTypeIds ~= nil then
596
599
  for abilityTypeId in pairs(self._abilityTypeIds) do
597
600
  unit:removeAbility(abilityTypeId)
598
601
  end
599
602
  end
600
- if self._bonusIdByBonusType ~= nil then
601
- for bonusType, bonusId in pairs(self._bonusIdByBonusType) do
602
- removeUnitBonus(unit, bonusType, bonusId)
603
- end
604
- end
605
- Event.invoke(buffDestroyEvent, self)
603
+ Event.invoke(buffBeingDestroyedEvent, self)
606
604
  self[100] = 3
607
605
  return UnitBehavior.prototype.onDestroy(self)
608
606
  end
@@ -646,9 +644,9 @@ function Buff.prototype.onExpiration(self)
646
644
  if self[121] ~= nil then
647
645
  (self[102] or unit):healTarget(unit, self[120] or 0)
648
646
  end
649
- if self[140] then
647
+ if self[141] then
650
648
  unit:explode()
651
- elseif self[139] then
649
+ elseif self[140] then
652
650
  unit:kill()
653
651
  end
654
652
  end
@@ -954,7 +952,7 @@ __TS__SetDescriptor(
954
952
  )
955
953
  __TS__SetDescriptor(
956
954
  Buff.prototype,
957
- "stuns",
955
+ "turnsIntoGhost",
958
956
  {
959
957
  get = function(self)
960
958
  local ____self__135_52 = self[135]
@@ -963,18 +961,12 @@ __TS__SetDescriptor(
963
961
  end
964
962
  return ____self__135_52
965
963
  end,
966
- set = function(self, stuns)
967
- if not stuns and self[135] then
968
- if self[136] then
969
- self.object:decrementStunCounter()
970
- end
971
- self.object:decrementStunCounter()
964
+ set = function(self, turnsIntoGhost)
965
+ if not turnsIntoGhost and self[135] then
966
+ self.object:decrementGhostCounter()
972
967
  self[135] = nil
973
- elseif stuns and not self[135] then
974
- if self[136] then
975
- self.object:incrementStunCounter()
976
- end
977
- self.object:incrementStunCounter()
968
+ elseif turnsIntoGhost and not self[135] then
969
+ self.object:incrementGhostCounter()
978
970
  self[135] = true
979
971
  end
980
972
  end
@@ -983,7 +975,7 @@ __TS__SetDescriptor(
983
975
  )
984
976
  __TS__SetDescriptor(
985
977
  Buff.prototype,
986
- "ignoresStunImmunity",
978
+ "stuns",
987
979
  {
988
980
  get = function(self)
989
981
  local ____self__136_53 = self[136]
@@ -992,16 +984,18 @@ __TS__SetDescriptor(
992
984
  end
993
985
  return ____self__136_53
994
986
  end,
995
- set = function(self, ignoresStunImmunity)
996
- if not ignoresStunImmunity and self[136] then
997
- if self[135] then
987
+ set = function(self, stuns)
988
+ if not stuns and self[136] then
989
+ if self[137] then
998
990
  self.object:decrementStunCounter()
999
991
  end
992
+ self.object:decrementStunCounter()
1000
993
  self[136] = nil
1001
- elseif ignoresStunImmunity and not self[136] then
1002
- if self[135] then
994
+ elseif stuns and not self[136] then
995
+ if self[137] then
1003
996
  self.object:incrementStunCounter()
1004
997
  end
998
+ self.object:incrementStunCounter()
1005
999
  self[136] = true
1006
1000
  end
1007
1001
  end
@@ -1010,7 +1004,7 @@ __TS__SetDescriptor(
1010
1004
  )
1011
1005
  __TS__SetDescriptor(
1012
1006
  Buff.prototype,
1013
- "disablesAutoAttack",
1007
+ "ignoresStunImmunity",
1014
1008
  {
1015
1009
  get = function(self)
1016
1010
  local ____self__137_54 = self[137]
@@ -1019,12 +1013,16 @@ __TS__SetDescriptor(
1019
1013
  end
1020
1014
  return ____self__137_54
1021
1015
  end,
1022
- set = function(self, disablesAutoAttack)
1023
- if not disablesAutoAttack and self[137] then
1024
- self.object:decrementDisableAutoAttackCounter()
1016
+ set = function(self, ignoresStunImmunity)
1017
+ if not ignoresStunImmunity and self[137] then
1018
+ if self[136] then
1019
+ self.object:decrementStunCounter()
1020
+ end
1025
1021
  self[137] = nil
1026
- elseif disablesAutoAttack and not self[137] then
1027
- self.object:incrementDisableAutoAttackCounter()
1022
+ elseif ignoresStunImmunity and not self[137] then
1023
+ if self[136] then
1024
+ self.object:incrementStunCounter()
1025
+ end
1028
1026
  self[137] = true
1029
1027
  end
1030
1028
  end
@@ -1033,7 +1031,7 @@ __TS__SetDescriptor(
1033
1031
  )
1034
1032
  __TS__SetDescriptor(
1035
1033
  Buff.prototype,
1036
- "providesInvulnerability",
1034
+ "disablesAutoAttack",
1037
1035
  {
1038
1036
  get = function(self)
1039
1037
  local ____self__138_55 = self[138]
@@ -1042,12 +1040,12 @@ __TS__SetDescriptor(
1042
1040
  end
1043
1041
  return ____self__138_55
1044
1042
  end,
1045
- set = function(self, providesInvulnerability)
1046
- if not providesInvulnerability and self[138] then
1047
- self.object:decrementInvulnerabilityCounter()
1043
+ set = function(self, disablesAutoAttack)
1044
+ if not disablesAutoAttack and self[138] then
1045
+ self.object:decrementDisableAutoAttackCounter()
1048
1046
  self[138] = nil
1049
- elseif providesInvulnerability and not self[138] then
1050
- self.object:incrementInvulnerabilityCounter()
1047
+ elseif disablesAutoAttack and not self[138] then
1048
+ self.object:incrementDisableAutoAttackCounter()
1051
1049
  self[138] = true
1052
1050
  end
1053
1051
  end
@@ -1056,7 +1054,7 @@ __TS__SetDescriptor(
1056
1054
  )
1057
1055
  __TS__SetDescriptor(
1058
1056
  Buff.prototype,
1059
- "killsOnExpiration",
1057
+ "providesInvulnerability",
1060
1058
  {
1061
1059
  get = function(self)
1062
1060
  local ____self__139_56 = self[139]
@@ -1065,10 +1063,12 @@ __TS__SetDescriptor(
1065
1063
  end
1066
1064
  return ____self__139_56
1067
1065
  end,
1068
- set = function(self, killsOnExpiration)
1069
- if not killsOnExpiration and self[139] then
1066
+ set = function(self, providesInvulnerability)
1067
+ if not providesInvulnerability and self[139] then
1068
+ self.object:decrementInvulnerabilityCounter()
1070
1069
  self[139] = nil
1071
- elseif killsOnExpiration and not self[139] then
1070
+ elseif providesInvulnerability and not self[139] then
1071
+ self.object:incrementInvulnerabilityCounter()
1072
1072
  self[139] = true
1073
1073
  end
1074
1074
  end
@@ -1077,7 +1077,7 @@ __TS__SetDescriptor(
1077
1077
  )
1078
1078
  __TS__SetDescriptor(
1079
1079
  Buff.prototype,
1080
- "explodesOnExpiration",
1080
+ "killsOnExpiration",
1081
1081
  {
1082
1082
  get = function(self)
1083
1083
  local ____self__140_57 = self[140]
@@ -1096,6 +1096,27 @@ __TS__SetDescriptor(
1096
1096
  },
1097
1097
  true
1098
1098
  )
1099
+ __TS__SetDescriptor(
1100
+ Buff.prototype,
1101
+ "explodesOnExpiration",
1102
+ {
1103
+ get = function(self)
1104
+ local ____self__141_58 = self[141]
1105
+ if ____self__141_58 == nil then
1106
+ ____self__141_58 = false
1107
+ end
1108
+ return ____self__141_58
1109
+ end,
1110
+ set = function(self, killsOnExpiration)
1111
+ if not killsOnExpiration and self[141] then
1112
+ self[141] = nil
1113
+ elseif killsOnExpiration and not self[141] then
1114
+ self[141] = true
1115
+ end
1116
+ end
1117
+ },
1118
+ true
1119
+ )
1099
1120
  __TS__SetDescriptor(
1100
1121
  Buff.prototype,
1101
1122
  "maximumDamageDealtEventCount",
@@ -1212,13 +1233,13 @@ __TS__SetDescriptor(
1212
1233
  "remainingDuration",
1213
1234
  {
1214
1235
  get = function(self)
1215
- local ____opt_58 = self._timer
1216
- return ____opt_58 and ____opt_58.remaining or 0
1236
+ local ____opt_59 = self._timer
1237
+ return ____opt_59 and ____opt_59.remaining or 0
1217
1238
  end,
1218
1239
  set = function(self, remainingDuration)
1219
- local ____remainingDuration_62 = remainingDuration
1220
- local ____opt_60 = self._timer
1221
- local remainingDurationDelta = ____remainingDuration_62 - (____opt_60 and ____opt_60.remaining or 0)
1240
+ local ____remainingDuration_63 = remainingDuration
1241
+ local ____opt_61 = self._timer
1242
+ local remainingDurationDelta = ____remainingDuration_63 - (____opt_61 and ____opt_61.remaining or 0)
1222
1243
  if remainingDurationDelta ~= 0 then
1223
1244
  self[103] = self[103] + remainingDurationDelta
1224
1245
  if remainingDuration <= 0 then
@@ -1232,7 +1253,8 @@ __TS__SetDescriptor(
1232
1253
  self._level,
1233
1254
  remainingDuration,
1234
1255
  self._spellStealPriority,
1235
- self._learnLevelMinimum
1256
+ self._learnLevelMinimum,
1257
+ self[142]
1236
1258
  ) then
1237
1259
  local timer = self._timer
1238
1260
  if timer == nil then
@@ -1247,7 +1269,8 @@ __TS__SetDescriptor(
1247
1269
  },
1248
1270
  true
1249
1271
  )
1250
- Buff.destroyEvent = buffDestroyEvent;
1272
+ Buff.createdEvent = buffCreatedEvent
1273
+ Buff.beingDestroyedEvent = buffBeingDestroyedEvent;
1251
1274
  (function(self)
1252
1275
  local function destroyBuffIfNeeded(buff)
1253
1276
  if getUnitAbility(buff[101].handle, buff.typeId) ~= buff.handle and buff[100] == 1 then
@@ -1301,5 +1324,8 @@ Buff.destroyEvent = buffDestroyEvent;
1301
1324
  ____exports.checkBuffs(target)
1302
1325
  end
1303
1326
  )
1327
+ buffCreatedEvent:addListener(function(buff)
1328
+ UnitBehavior:forAll(buff.unit, "onBuffGained", buff)
1329
+ end)
1304
1330
  end)(Buff)
1305
1331
  return ____exports
@@ -1,5 +1,5 @@
1
1
  /** @noSelfInFile */
2
- import { Handle } from "../../core/types/handle";
2
+ import { Handle, HandleDestructor } from "../../core/types/handle";
3
3
  import { Event } from "../../event";
4
4
  import type { Item } from "../../core/types/item";
5
5
  import type { Unit } from "./unit";
@@ -55,14 +55,19 @@ export declare class UnrecognizedAbility extends Ability {
55
55
  export declare class UnitAbility extends Ability {
56
56
  readonly owner: Unit;
57
57
  private readonly u;
58
+ private d?;
58
59
  constructor(handle: jability, typeId: number, owner: Unit);
59
60
  incrementHideCounter(): void;
60
61
  decrementHideCounter(): void;
62
+ incrementDisableCounter(): void;
63
+ decrementDisableCounter(): void;
64
+ get isDisabled(): boolean;
61
65
  get level(): number;
62
66
  set level(v: number);
63
67
  get cooldownRemaining(): number;
64
68
  set cooldownRemaining(cooldownRemaining: number);
65
69
  interruptCast(): void;
70
+ protected onDestroy(): HandleDestructor;
66
71
  static get onCreate(): Event<[UnitAbility]>;
67
72
  static get onDestroy(): Event<[UnitAbility]>;
68
73
  }
@@ -89,6 +94,7 @@ export declare class ItemAbility extends Ability {
89
94
  get cooldownRemaining(): number;
90
95
  set cooldownRemaining(cooldownRemaining: number);
91
96
  interruptCast(): void;
97
+ protected onDestroy(): HandleDestructor;
92
98
  static get onCreate(): Event<[ItemAbility]>;
93
99
  static get onDestroy(): Event<[ItemAbility]>;
94
100
  }
@@ -38,6 +38,7 @@ local getHandleId = GetHandleId
38
38
  local getItemBooleanField = BlzGetItemBooleanField
39
39
  local setItemBooleanField = BlzSetItemBooleanField
40
40
  local unitHideAbility = BlzUnitHideAbility
41
+ local unitDisableAbility = BlzUnitDisableAbility
41
42
  local match = string.match
42
43
  local ____type = _G.type
43
44
  local ____tostring = _G.tostring
@@ -231,6 +232,19 @@ ____exports.getOrderIdByAbilityTypeId = function(abilityTypeId)
231
232
  local parentTypeId = availableFields[abilityTypeId]
232
233
  return order2orderId(orders[____type(parentTypeId) == "number" and parentTypeId or abilityTypeId] or "")
233
234
  end
235
+ ---
236
+ -- @internal For use by internal systems only.
237
+ ____exports.abilityTypeHasField = function(abilityTypeId, field)
238
+ field = ____type(field) == "number" and field or getHandleId(field)
239
+ if commonFields[field] then
240
+ return true
241
+ end
242
+ local id = availableFields[abilityTypeId]
243
+ if ____type(id) == "number" then
244
+ id = availableFields[id]
245
+ end
246
+ return not not (id and id[field])
247
+ end
234
248
  ____exports.Ability = __TS__Class()
235
249
  local Ability = ____exports.Ability
236
250
  Ability.name = "Ability"
@@ -246,15 +260,7 @@ function Ability.prototype.getSnapshot(self)
246
260
  return nil
247
261
  end
248
262
  function Ability.prototype.hasField(self, field)
249
- field = ____type(field) == "number" and field or getHandleId(field)
250
- if commonFields[field] then
251
- return true
252
- end
253
- local id = availableFields[self.typeId]
254
- if ____type(id) == "number" then
255
- id = availableFields[id]
256
- end
257
- return not not (id and id[field])
263
+ return ____exports.abilityTypeHasField(self.typeId, field)
258
264
  end
259
265
  function Ability.prototype.getField(self, field, level)
260
266
  local fieldType = match(
@@ -402,9 +408,37 @@ end
402
408
  function UnitAbility.prototype.decrementHideCounter(self)
403
409
  unitHideAbility(self.u, self.typeId, false)
404
410
  end
411
+ function UnitAbility.prototype.incrementDisableCounter(self)
412
+ local unit = self.u
413
+ local typeId = self.typeId
414
+ unitHideAbility(unit, typeId, true)
415
+ unitDisableAbility(unit, typeId, true, false)
416
+ self.d = (self.d or 0) + 1
417
+ end
418
+ function UnitAbility.prototype.decrementDisableCounter(self)
419
+ local unit = self.u
420
+ local typeId = self.typeId
421
+ unitDisableAbility(unit, typeId, false, false)
422
+ unitHideAbility(unit, typeId, true)
423
+ self.d = (self.d or 0) - 1
424
+ end
405
425
  function UnitAbility.prototype.interruptCast(self)
406
426
  self.owner:interruptCast(self.typeId)
407
427
  end
428
+ function UnitAbility.prototype.onDestroy(self)
429
+ if self.owner.state ~= 2 then
430
+ self.owner:removeAbility(self.typeId)
431
+ end
432
+ return UnitAbility.____super.prototype.onDestroy(self)
433
+ end
434
+ __TS__SetDescriptor(
435
+ UnitAbility.prototype,
436
+ "isDisabled",
437
+ {get = function(self)
438
+ return self.d ~= nil and self.d > 0
439
+ end},
440
+ true
441
+ )
408
442
  __TS__SetDescriptor(
409
443
  UnitAbility.prototype,
410
444
  "level",
@@ -489,6 +523,12 @@ function ItemAbility.prototype.interruptCast(self)
489
523
  setItemBooleanField(handle, ITEM_BF_ACTIVELY_USED, true)
490
524
  end
491
525
  end
526
+ function ItemAbility.prototype.onDestroy(self)
527
+ if self.owner.state ~= 2 then
528
+ self.owner:removeAbility(self.typeId)
529
+ end
530
+ return ItemAbility.____super.prototype.onDestroy(self)
531
+ end
492
532
  __TS__SetDescriptor(
493
533
  ItemAbility.prototype,
494
534
  "level",
@@ -20,6 +20,7 @@ local ____add_2Ditem_2Dto_2Dslot = require("engine.internal.unit.add-item-to-slo
20
20
  local unitAddItemToSlot = ____add_2Ditem_2Dto_2Dslot.unitAddItemToSlot
21
21
  local isItemOwned = IsItemOwned
22
22
  local isItemPowerup = IsItemPowerup
23
+ local getItemAbility = BlzGetItemAbility
23
24
  local getItemX = GetItemX
24
25
  local getItemY = GetItemY
25
26
  local setAbilityRealLevelField = BlzSetAbilityRealLevelField
@@ -31,6 +32,8 @@ local unitAddItem = UnitAddItem
31
32
  local unitRemoveItem = UnitRemoveItem
32
33
  local unitUseItem = UnitUseItem
33
34
  local unitResetCooldown = UnitResetCooldown
35
+ local unitInventorySize = UnitInventorySize
36
+ local unitItemInSlot = UnitItemInSlot
34
37
  local COOLDOWN_STARTER_ABILITY_TYPE_ID = compiletime(function()
35
38
  if not currentMap then
36
39
  return 0
@@ -55,22 +58,24 @@ local COOLDOWN_STARTER_ITEM_TYPE_ID = compiletime(function()
55
58
  itemType.activelyUsed = true
56
59
  return itemType.id
57
60
  end)
58
- local dummy = assert(CreateUnit(
61
+ ---
62
+ -- @internal For use by internal systems only.
63
+ ____exports.itemAbilityDummy = assert(CreateUnit(
59
64
  Player.neutralVictim.handle,
60
65
  dummyUnitId,
61
66
  0,
62
67
  0,
63
68
  270
64
69
  ))
65
- local cooldownStarterItem = UnitAddItemById(dummy, COOLDOWN_STARTER_ITEM_TYPE_ID)
66
- local cooldownStarterAbility = BlzGetItemAbility(cooldownStarterItem, COOLDOWN_STARTER_ABILITY_TYPE_ID)
67
- ShowUnit(dummy, false)
70
+ local cooldownStarterItem = UnitAddItemById(____exports.itemAbilityDummy, COOLDOWN_STARTER_ITEM_TYPE_ID)
71
+ local cooldownStarterAbility = getItemAbility(cooldownStarterItem, COOLDOWN_STARTER_ABILITY_TYPE_ID)
72
+ ShowUnit(____exports.itemAbilityDummy, false)
68
73
  local function startItemCooldownInternal(handle, cooldown)
69
74
  local cooldownGroup = getItemIntegerField(handle, ITEM_IF_COOLDOWN_GROUP)
70
75
  setItemIntegerField(handle, ITEM_IF_COOLDOWN_GROUP, COOLDOWN_STARTER_ABILITY_TYPE_ID)
71
76
  setAbilityRealLevelField(cooldownStarterAbility, ABILITY_RLF_COOLDOWN, 0, cooldown)
72
- unitResetCooldown(dummy)
73
- unitUseItem(dummy, cooldownStarterItem)
77
+ unitResetCooldown(____exports.itemAbilityDummy)
78
+ unitUseItem(____exports.itemAbilityDummy, cooldownStarterItem)
74
79
  Timer:run(restoreCooldownGroup, handle, cooldownGroup)
75
80
  end
76
81
  restoreCooldownGroup = function(handle, cooldownGroup)
@@ -85,7 +90,7 @@ ____exports.startItemCooldown = function(handle, owner, cooldown)
85
90
  end
86
91
  ---
87
92
  -- @internal For use by internal systems only.
88
- ____exports.abilityActionDummy = dummy
93
+ ____exports.abilityActionDummy = ____exports.itemAbilityDummy
89
94
  ---
90
95
  -- @internal For use by internal systems only.
91
96
  ____exports.doAbilityAction = function(handle, action, ...)
@@ -104,11 +109,11 @@ ____exports.doAbilityAction = function(handle, action, ...)
104
109
  end
105
110
  x = getItemX(handle)
106
111
  y = getItemY(handle)
107
- unitAddItem(dummy, handle)
112
+ unitAddItem(____exports.itemAbilityDummy, handle)
108
113
  end
109
114
  local result = action(handle, ...)
110
115
  if not isOwned then
111
- unitRemoveItem(dummy, handle)
116
+ unitRemoveItem(____exports.itemAbilityDummy, handle)
112
117
  setItemPosition(handle, x, y)
113
118
  if isPowerup then
114
119
  setItemBooleanField(handle, ITEM_BF_USE_AUTOMATICALLY_WHEN_ACQUIRED, true)
@@ -139,9 +144,9 @@ ____exports.doAbilityActionForceDummy = function(handle, owner, action, ...)
139
144
  isPowerup = true
140
145
  end
141
146
  unitRemoveItem(owner, handle)
142
- unitAddItem(dummy, handle)
147
+ unitAddItem(____exports.itemAbilityDummy, handle)
143
148
  local result = action(handle, ...)
144
- unitRemoveItem(dummy, handle)
149
+ unitRemoveItem(____exports.itemAbilityDummy, handle)
145
150
  unitAddItemToSlot(owner, handle, slot)
146
151
  if isPowerup then
147
152
  setItemBooleanField(handle, ITEM_BF_USE_AUTOMATICALLY_WHEN_ACQUIRED, true)
@@ -151,4 +156,51 @@ ____exports.doAbilityActionForceDummy = function(handle, owner, action, ...)
151
156
  end
152
157
  return result
153
158
  end
159
+ local depth = 0
160
+ local itemBySlot = {}
161
+ ---
162
+ -- @internal For use by internal systems only.
163
+ ____exports.doUnitAbilityAction = function(unit, abilityTypeId, action, ...)
164
+ local ____depth_0 = depth
165
+ depth = ____depth_0 + 1
166
+ local offset = 6 * ____depth_0
167
+ for slot = 0, unitInventorySize(unit) - 1 do
168
+ local item = unitItemInSlot(unit, slot)
169
+ if getItemAbility(item, abilityTypeId) ~= nil then
170
+ local isAlreadyIgnoredInEvents = ignoreEventsItems[item] ~= nil
171
+ if not isAlreadyIgnoredInEvents then
172
+ ignoreEventsItems[item] = true
173
+ end
174
+ unitRemoveItem(unit, item)
175
+ if not isAlreadyIgnoredInEvents then
176
+ ignoreEventsItems[item] = nil
177
+ end
178
+ itemBySlot[offset + slot] = item
179
+ end
180
+ end
181
+ local result = action(unit, ...)
182
+ for slot = 0, unitInventorySize(unit) - 1 do
183
+ local item = itemBySlot[offset + slot]
184
+ if item ~= nil then
185
+ local isAlreadyIgnoredInEvents = ignoreEventsItems[item] ~= nil
186
+ if not isAlreadyIgnoredInEvents then
187
+ ignoreEventsItems[item] = true
188
+ end
189
+ local isPowerup = isItemPowerup(item)
190
+ if isPowerup then
191
+ setItemBooleanField(item, ITEM_BF_USE_AUTOMATICALLY_WHEN_ACQUIRED, false)
192
+ end
193
+ unitAddItemToSlot(unit, item, slot)
194
+ if isPowerup then
195
+ setItemBooleanField(item, ITEM_BF_USE_AUTOMATICALLY_WHEN_ACQUIRED, true)
196
+ end
197
+ if not isAlreadyIgnoredInEvents then
198
+ ignoreEventsItems[item] = nil
199
+ end
200
+ itemBySlot[offset + slot] = nil
201
+ end
202
+ end
203
+ depth = depth - 1
204
+ return result
205
+ end
154
206
  return ____exports