warscript 0.0.1-dev.f48f7bb → 0.0.1-dev.f70428f

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 (186) hide show
  1. package/attributes.d.ts +6 -0
  2. package/attributes.lua +17 -1
  3. package/config.d.ts +5 -0
  4. package/config.lua +10 -0
  5. package/core/types/effect.d.ts +1 -3
  6. package/core/types/effect.lua +26 -29
  7. package/core/types/frame.lua +24 -21
  8. package/core/types/player.d.ts +15 -0
  9. package/core/types/player.lua +56 -14
  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 +11 -1
  15. package/core/types/tileCell.lua +97 -0
  16. package/core/types/timer.d.ts +9 -8
  17. package/core/types/timer.lua +45 -23
  18. package/core/util.lua +6 -1
  19. package/decl/native.d.ts +846 -790
  20. package/engine/behavior.d.ts +12 -1
  21. package/engine/behavior.lua +172 -70
  22. package/engine/behaviour/ability/apply-buff.d.ts +5 -0
  23. package/engine/behaviour/ability/apply-buff.lua +32 -0
  24. package/engine/behaviour/ability/apply-unit-behavior.lua +1 -0
  25. package/engine/behaviour/ability/damage.d.ts +9 -3
  26. package/engine/behaviour/ability/damage.lua +26 -38
  27. package/engine/behaviour/ability/emulate-impact.d.ts +1 -1
  28. package/engine/behaviour/ability/emulate-impact.lua +18 -3
  29. package/engine/behaviour/ability/remove-buffs.d.ts +9 -0
  30. package/engine/behaviour/ability/remove-buffs.lua +21 -0
  31. package/engine/behaviour/ability/restore-mana.d.ts +1 -1
  32. package/engine/behaviour/ability/restore-mana.lua +6 -6
  33. package/engine/behaviour/ability.d.ts +7 -2
  34. package/engine/behaviour/ability.lua +42 -24
  35. package/engine/behaviour/unit/stun-immunity.d.ts +11 -5
  36. package/engine/behaviour/unit/stun-immunity.lua +53 -28
  37. package/engine/behaviour/unit.d.ts +36 -2
  38. package/engine/behaviour/unit.lua +192 -6
  39. package/engine/buff.d.ts +66 -44
  40. package/engine/buff.lua +330 -225
  41. package/engine/internal/ability.d.ts +7 -1
  42. package/engine/internal/ability.lua +49 -11
  43. package/engine/internal/item/ability.lua +66 -14
  44. package/engine/internal/item+owner.lua +12 -6
  45. package/engine/internal/item.d.ts +20 -19
  46. package/engine/internal/item.lua +191 -74
  47. package/engine/internal/mechanics/ability-duration.lua +1 -1
  48. package/engine/internal/misc/damage-metadata-by-target.d.ts +2 -0
  49. package/engine/internal/misc/damage-metadata-by-target.lua +5 -0
  50. package/engine/internal/misc/frame-coordinates.d.ts +2 -0
  51. package/engine/internal/misc/frame-coordinates.lua +21 -0
  52. package/engine/internal/misc/get-terrain-z.d.ts +2 -0
  53. package/engine/internal/misc/get-terrain-z.lua +11 -0
  54. package/engine/internal/misc/player-local-handle.d.ts +2 -0
  55. package/engine/internal/misc/player-local-handle.lua +5 -0
  56. package/engine/internal/object-data/auto-attack-speed-increase.d.ts +1 -1
  57. package/engine/internal/object-data/auto-attack-speed-increase.lua +2 -0
  58. package/engine/internal/object-data/evasion-probability.d.ts +2 -0
  59. package/engine/internal/object-data/evasion-probability.lua +16 -0
  60. package/engine/internal/unit/ability.d.ts +35 -0
  61. package/engine/internal/unit/ability.lua +98 -9
  62. package/engine/internal/unit/add-item-to-slot-init.d.ts +2 -0
  63. package/engine/internal/unit/add-item-to-slot-init.lua +23 -0
  64. package/engine/internal/unit/add-item-to-slot.d.ts +2 -0
  65. package/engine/internal/unit/add-item-to-slot.lua +52 -0
  66. package/engine/internal/unit/allowed-targets.d.ts +1 -1
  67. package/engine/internal/unit/allowed-targets.lua +9 -1
  68. package/engine/internal/unit/bonus.d.ts +2 -0
  69. package/engine/internal/unit/bonus.lua +17 -0
  70. package/engine/internal/unit/fly-height.d.ts +7 -0
  71. package/engine/internal/unit/fly-height.lua +20 -0
  72. package/engine/internal/unit/item.lua +3 -48
  73. package/engine/internal/unit/main-selected.lua +12 -27
  74. package/engine/internal/unit/order.d.ts +20 -0
  75. package/engine/internal/unit/order.lua +136 -0
  76. package/engine/internal/unit/scale.d.ts +7 -0
  77. package/engine/internal/unit/scale.lua +20 -0
  78. package/engine/internal/unit+ability.lua +10 -1
  79. package/engine/internal/unit+damage.d.ts +2 -11
  80. package/engine/internal/unit+damage.lua +10 -14
  81. package/engine/internal/unit+spellSteal.lua +1 -2
  82. package/engine/internal/unit-missile-launch.lua +45 -14
  83. package/engine/internal/unit.d.ts +43 -17
  84. package/engine/internal/unit.lua +340 -165
  85. package/engine/lightning.d.ts +12 -5
  86. package/engine/lightning.lua +48 -14
  87. package/engine/local-client.d.ts +2 -0
  88. package/engine/local-client.lua +30 -0
  89. package/engine/object-data/auxiliary/animation-name.d.ts +1 -0
  90. package/engine/object-data/auxiliary/animation-name.lua +16 -0
  91. package/engine/object-data/auxiliary/armor-type.d.ts +11 -0
  92. package/engine/object-data/auxiliary/armor-type.lua +46 -0
  93. package/engine/object-data/auxiliary/attachment-preset.d.ts +7 -2
  94. package/engine/object-data/auxiliary/attachment-preset.lua +4 -3
  95. package/engine/object-data/auxiliary/attack-type.d.ts +7 -8
  96. package/engine/object-data/auxiliary/attack-type.lua +42 -0
  97. package/engine/object-data/auxiliary/movement-type.d.ts +7 -7
  98. package/engine/object-data/auxiliary/movement-type.lua +22 -0
  99. package/engine/object-data/auxiliary/sound-eax.d.ts +10 -0
  100. package/engine/object-data/auxiliary/sound-eax.lua +2 -0
  101. package/engine/object-data/auxiliary/tech-tree-dependency.d.ts +1 -1
  102. package/engine/object-data/auxiliary/unit-attribute.d.ts +6 -0
  103. package/engine/object-data/auxiliary/unit-attribute.lua +9 -0
  104. package/engine/object-data/entry/ability-type/berserk.d.ts +2 -0
  105. package/engine/object-data/entry/ability-type/berserk.lua +13 -0
  106. package/engine/object-data/entry/ability-type/blank-configurable.lua +12 -1
  107. package/engine/object-data/entry/ability-type/carrion-swarm.d.ts +14 -0
  108. package/engine/object-data/entry/ability-type/carrion-swarm.lua +65 -0
  109. package/engine/object-data/entry/ability-type/disease-cloud.lua +2 -2
  110. package/engine/object-data/entry/ability-type/engineering-upgrade.lua +2 -2
  111. package/engine/object-data/entry/ability-type/ensnare.d.ts +12 -0
  112. package/engine/object-data/entry/ability-type/ensnare.lua +52 -0
  113. package/engine/object-data/entry/ability-type/feral-spirit.lua +2 -2
  114. package/engine/object-data/entry/ability-type/permanent-invisibility.d.ts +8 -0
  115. package/engine/object-data/entry/ability-type/permanent-invisibility.lua +26 -0
  116. package/engine/object-data/entry/ability-type/phase-shift.d.ts +10 -0
  117. package/engine/object-data/entry/ability-type/phase-shift.lua +39 -0
  118. package/engine/object-data/entry/ability-type/phoenix-morph.lua +4 -4
  119. package/engine/object-data/entry/ability-type/raise-dead.d.ts +17 -0
  120. package/engine/object-data/entry/ability-type/raise-dead.lua +78 -0
  121. package/engine/object-data/entry/ability-type/shock-wave.d.ts +4 -0
  122. package/engine/object-data/entry/ability-type/shock-wave.lua +26 -0
  123. package/engine/object-data/entry/ability-type/slow-poison.d.ts +10 -0
  124. package/engine/object-data/entry/ability-type/slow-poison.lua +58 -0
  125. package/engine/object-data/entry/ability-type/summon-quilbeast.lua +2 -2
  126. package/engine/object-data/entry/ability-type/summon-water-elemental.lua +2 -2
  127. package/engine/object-data/entry/ability-type/web.d.ts +12 -0
  128. package/engine/object-data/entry/ability-type/web.lua +52 -0
  129. package/engine/object-data/entry/ability-type.d.ts +19 -17
  130. package/engine/object-data/entry/ability-type.lua +85 -24
  131. package/engine/object-data/entry/buff-type/applicable.lua +18 -37
  132. package/engine/object-data/entry/buff-type.d.ts +6 -12
  133. package/engine/object-data/entry/buff-type.lua +13 -29
  134. package/engine/object-data/entry/destructible-type.d.ts +1 -1
  135. package/engine/object-data/entry/item-type.d.ts +1 -1
  136. package/engine/object-data/entry/item-type.lua +4 -4
  137. package/engine/object-data/entry/lightning-type.d.ts +1 -1
  138. package/engine/object-data/entry/sound-preset.d.ts +33 -0
  139. package/engine/object-data/entry/sound-preset.lua +140 -0
  140. package/engine/object-data/entry/unit-type.d.ts +21 -5
  141. package/engine/object-data/entry/unit-type.lua +214 -93
  142. package/engine/object-data/entry/upgrade.d.ts +1 -1
  143. package/engine/object-data/entry/upgrade.lua +4 -4
  144. package/engine/object-data/entry.d.ts +16 -14
  145. package/engine/object-data/entry.lua +60 -32
  146. package/engine/object-field/ability.d.ts +4 -4
  147. package/engine/object-field/ability.lua +7 -6
  148. package/engine/object-field/unit.d.ts +69 -3
  149. package/engine/object-field/unit.lua +264 -7
  150. package/engine/object-field.d.ts +23 -6
  151. package/engine/object-field.lua +309 -126
  152. package/engine/random.d.ts +9 -0
  153. package/engine/random.lua +13 -0
  154. package/engine/standard/entries/buff-type.d.ts +3 -0
  155. package/engine/standard/entries/buff-type.lua +3 -0
  156. package/engine/standard/entries/sound-preset.d.ts +10 -0
  157. package/engine/standard/entries/sound-preset.lua +10 -0
  158. package/engine/standard/fields/unit.d.ts +6 -0
  159. package/engine/standard/fields/unit.lua +11 -0
  160. package/engine/synchronization.d.ts +11 -0
  161. package/engine/synchronization.lua +77 -0
  162. package/engine/text-tag.d.ts +36 -2
  163. package/engine/text-tag.lua +250 -10
  164. package/engine/unit.d.ts +4 -0
  165. package/engine/unit.lua +4 -0
  166. package/net/socket.lua +1 -1
  167. package/objutil/buff.lua +2 -3
  168. package/objutil/unit.lua +8 -0
  169. package/package.json +2 -2
  170. package/patch-lualib.lua +1 -1
  171. package/utility/arrays.d.ts +2 -0
  172. package/utility/arrays.lua +11 -0
  173. package/utility/callback-array.d.ts +17 -0
  174. package/utility/callback-array.lua +61 -0
  175. package/utility/functions.d.ts +8 -0
  176. package/utility/functions.lua +13 -0
  177. package/utility/linked-set.d.ts +2 -0
  178. package/utility/linked-set.lua +22 -1
  179. package/utility/lua-maps.d.ts +15 -2
  180. package/utility/lua-maps.lua +53 -2
  181. package/utility/lua-sets.d.ts +2 -0
  182. package/utility/lua-sets.lua +7 -0
  183. package/utility/reflection.lua +11 -7
  184. package/utility/types.d.ts +3 -0
  185. package/core/types/order.d.ts +0 -25
  186. package/core/types/order.lua +0 -55
@@ -53,12 +53,21 @@ local ____math = require("math")
53
53
  local min = ____math.min
54
54
  local ____ignore_2Devents_2Ditems = require("engine.internal.unit.ignore-events-items")
55
55
  local ignoreEventsItems = ____ignore_2Devents_2Ditems.ignoreEventsItems
56
+ local ____attack_2Dtype = require("engine.object-data.auxiliary.attack-type")
57
+ local attackTypeToNative = ____attack_2Dtype.attackTypeToNative
58
+ local nativeToAttackType = ____attack_2Dtype.nativeToAttackType
59
+ local ____damage_2Dmetadata_2Dby_2Dtarget = require("engine.internal.misc.damage-metadata-by-target")
60
+ local damageMetadataByTarget = ____damage_2Dmetadata_2Dby_2Dtarget.damageMetadataByTarget
61
+ local ____attributes = require("attributes")
62
+ local isAttribute = ____attributes.isAttribute
63
+ local ____ability = require("engine.internal.item.ability")
64
+ local doUnitAbilityAction = ____ability.doUnitAbilityAction
65
+ local ____synchronization = require("engine.synchronization")
66
+ local synchronizer = ____synchronization.synchronizer
56
67
  local match = string.match
57
68
  local ____tostring = _G.tostring
58
69
  local setUnitAnimation = SetUnitAnimation
59
- local setUnitAnimationWithRarity = SetUnitAnimationWithRarity
60
70
  local setUnitAnimationByIndex = SetUnitAnimationByIndex
61
- local queueUnitAnimation = QueueUnitAnimation
62
71
  local getUnitIntegerField = BlzGetUnitIntegerField
63
72
  local getUnitRealField = BlzGetUnitRealField
64
73
  local getHeroStr = GetHeroStr
@@ -77,9 +86,9 @@ local setUnitScale = SetUnitScale
77
86
  local setUnitPosition = SetUnitPosition
78
87
  local setUnitTimeScale = SetUnitTimeScale
79
88
  local getHandleId = GetHandleId
89
+ local getUnitCurrentOrder = GetUnitCurrentOrder
80
90
  local createUnit = CreateUnit
81
91
  local killUnit = KillUnit
82
- local setUnitExploded = SetUnitExploded
83
92
  local removeUnit = RemoveUnit
84
93
  local getUnitTypeId = GetUnitTypeId
85
94
  local isHeroUnitId = IsHeroUnitId
@@ -95,8 +104,6 @@ local getSpellTargetItem = GetSpellTargetItem
95
104
  local getSpellTargetDestructable = GetSpellTargetDestructable
96
105
  local isUnitInRangeXY = IsUnitInRangeXY
97
106
  local isUnitInRange = IsUnitInRange
98
- local setResourceAmount = SetResourceAmount
99
- local getResourceAmount = GetResourceAmount
100
107
  local getUnitWeaponRealField = BlzGetUnitWeaponRealField
101
108
  local setUnitWeaponRealField = BlzSetUnitWeaponRealField
102
109
  local getUnitWeaponStringField = BlzGetUnitWeaponStringField
@@ -120,15 +127,9 @@ local getOrderedUnit = GetOrderedUnit
120
127
  local getIssuedOrderId = GetIssuedOrderId
121
128
  local isUnitInvulnerable = BlzIsUnitInvulnerable
122
129
  local unitAlive = UnitAlive
123
- local unitAddType = UnitAddType
124
- local unitRemoveType = UnitRemoveType
125
- local isUnitIllusion = IsUnitIllusion
126
- local isUnitType = IsUnitType
127
130
  local isUnitAlly = IsUnitAlly
128
131
  local isUnitEnemy = IsUnitEnemy
129
132
  local getOwningPlayer = GetOwningPlayer
130
- local setUnitColor = SetUnitColor
131
- local showUnitTeamGlow = BlzShowUnitTeamGlow
132
133
  ____exports.UnitClassification = {}
133
134
  local UnitClassification = ____exports.UnitClassification
134
135
  do
@@ -138,6 +139,7 @@ do
138
139
  UnitClassification.GROUND = UNIT_TYPE_GROUND
139
140
  UnitClassification.SUMMONED = UNIT_TYPE_SUMMONED
140
141
  UnitClassification.MECHANICAL = UNIT_TYPE_MECHANICAL
142
+ UnitClassification.WORKER = UNIT_TYPE_PEON
141
143
  UnitClassification.ANCIENT = UNIT_TYPE_ANCIENT
142
144
  UnitClassification.SUICIDAL = UNIT_TYPE_SAPPER
143
145
  UnitClassification.TAUREN = UNIT_TYPE_TAUREN
@@ -345,6 +347,9 @@ local function dispatchAbility(event)
345
347
  }
346
348
  )
347
349
  end
350
+ local function damagingEventPreventRetaliation(self)
351
+ self[0] = true
352
+ end
348
353
  local function damageEventPreventDeath(self, callback, ...)
349
354
  if self[0] ~= nil then
350
355
  return
@@ -356,7 +361,14 @@ local function damageEventPreventDeath(self, callback, ...)
356
361
  rawset(self, 1 + i, (select(i, ...)))
357
362
  end
358
363
  end
359
- local damageSetters = {amount = BlzSetEventDamage, attackType = BlzSetEventAttackType, damageType = BlzSetEventDamageType, weaponType = BlzSetEventWeaponType}
364
+ local damageSetters = {
365
+ amount = BlzSetEventDamage,
366
+ attackType = function(attackType)
367
+ return BlzSetEventAttackType(attackTypeToNative(attackType))
368
+ end,
369
+ damageType = BlzSetEventDamageType,
370
+ weaponType = BlzSetEventWeaponType
371
+ }
360
372
  local jlimitopByOperator = {
361
373
  [0] = LESS_THAN_OR_EQUAL,
362
374
  [1] = LESS_THAN_OR_EQUAL,
@@ -400,6 +412,19 @@ function UnitWeapon.prototype.____constructor(self, unit, index)
400
412
  self.unit = unit
401
413
  self.index = index
402
414
  end
415
+ __TS__SetDescriptor(
416
+ UnitWeapon.prototype,
417
+ "isEnabled",
418
+ {
419
+ get = function(self)
420
+ return BlzGetUnitWeaponBooleanField(self.unit.handle, UNIT_WEAPON_BF_ATTACKS_ENABLED, self.index)
421
+ end,
422
+ set = function(self, isEnabled)
423
+ BlzSetUnitWeaponBooleanField(self.unit.handle, UNIT_WEAPON_BF_ATTACKS_ENABLED, self.index, isEnabled)
424
+ end
425
+ },
426
+ true
427
+ )
403
428
  __TS__SetDescriptor(
404
429
  UnitWeapon.prototype,
405
430
  "cooldown",
@@ -434,6 +459,19 @@ __TS__SetDescriptor(
434
459
  },
435
460
  true
436
461
  )
462
+ __TS__SetDescriptor(
463
+ UnitWeapon.prototype,
464
+ "allowedTargetCombatClassifications",
465
+ {
466
+ get = function(self)
467
+ return BlzGetUnitWeaponIntegerField(self.unit.handle, UNIT_WEAPON_IF_ATTACK_TARGETS_ALLOWED, self.index)
468
+ end,
469
+ set = function(self, allowedTargetCombatClassifications)
470
+ BlzSetUnitWeaponIntegerField(self.unit.handle, UNIT_WEAPON_IF_ATTACK_TARGETS_ALLOWED, self.index, allowedTargetCombatClassifications)
471
+ end
472
+ },
473
+ true
474
+ )
437
475
  __TS__SetDescriptor(
438
476
  UnitWeapon.prototype,
439
477
  "damageBase",
@@ -621,15 +659,15 @@ for ____, player in ipairs(Player.all) do
621
659
  dummies[player] = dummy
622
660
  end
623
661
  local function delayHealthChecksCallback(unit)
624
- local counter = (unit[103] or 0) - 1
662
+ local counter = (unit[104] or 0) - 1
625
663
  if counter ~= 0 then
626
- unit[103] = counter
664
+ unit[104] = counter
627
665
  return
628
666
  end
629
- unit[103] = nil
630
- local healthBonus = unit[104]
667
+ unit[104] = nil
668
+ local healthBonus = unit[105]
631
669
  if healthBonus ~= nil then
632
- unit[104] = nil
670
+ unit[105] = nil
633
671
  local handle = unit.handle
634
672
  BlzSetUnitMaxHP(
635
673
  handle,
@@ -638,16 +676,26 @@ local function delayHealthChecksCallback(unit)
638
676
  end
639
677
  end
640
678
  local nextSyncId = 1
641
- local unitBySyncId = setmetatable({}, {__mode = "k"})
679
+ local unitBySyncId = setmetatable({}, {__mode = "v"})
680
+ local damagingEventByTarget = setmetatable({}, {__mode = "k"})
681
+ local function addAbility(unit, abilityTypeId)
682
+ local ____unitAddAbility_result_0
683
+ if unitAddAbility(unit, abilityTypeId) then
684
+ ____unitAddAbility_result_0 = getUnitAbility(unit, abilityTypeId)
685
+ else
686
+ ____unitAddAbility_result_0 = nil
687
+ end
688
+ return ____unitAddAbility_result_0
689
+ end
642
690
  ____exports.Unit = __TS__Class()
643
691
  local Unit = ____exports.Unit
644
692
  Unit.name = "Unit"
645
693
  __TS__ClassExtends(Unit, Handle)
646
694
  function Unit.prototype.____constructor(self, handle)
647
695
  Handle.prototype.____constructor(self, handle)
648
- local ____nextSyncId_0 = nextSyncId
649
- nextSyncId = ____nextSyncId_0 + 1
650
- self.syncId = ____nextSyncId_0
696
+ local ____nextSyncId_1 = nextSyncId
697
+ nextSyncId = ____nextSyncId_1 + 1
698
+ self.syncId = ____nextSyncId_1
651
699
  self._owner = Player:of(getOwningPlayer(handle))
652
700
  assert(unitAddAbility(handle, leaveDetectAbilityId) and UnitMakeAbilityPermanent(handle, true, leaveDetectAbilityId))
653
701
  assert(unitAddAbility(handle, morphDetectAbilityId))
@@ -679,6 +727,8 @@ function Unit.prototype.getEvent(self, event, collector)
679
727
  end
680
728
  function Unit.prototype.onDestroy(self)
681
729
  local handle = self.handle
730
+ self[108] = getUnitX(handle)
731
+ self[109] = getUnitY(handle)
682
732
  if not self._owner then
683
733
  self._owner = Player:of(getOwningPlayer(handle))
684
734
  end
@@ -746,17 +796,17 @@ function Unit.prototype.addModifier(self, property, modifier)
746
796
  end}
747
797
  end
748
798
  function Unit.prototype.hasCombatClassification(self, combatClassification)
749
- local ____combatClassification_1 = combatClassification
750
- return getUnitIntegerField(self.handle, UNIT_IF_TARGETED_AS) & ____combatClassification_1 == ____combatClassification_1
799
+ local ____combatClassification_2 = combatClassification
800
+ return getUnitIntegerField(self.handle, UNIT_IF_TARGETED_AS) & ____combatClassification_2 == ____combatClassification_2
751
801
  end
752
802
  function Unit.prototype.addClassification(self, classification)
753
- return unitAddType(self.handle, classification)
803
+ return UnitAddType(self.handle, classification)
754
804
  end
755
805
  function Unit.prototype.removeClassification(self, classification)
756
- return unitRemoveType(self.handle, classification)
806
+ return UnitRemoveType(self.handle, classification)
757
807
  end
758
808
  function Unit.prototype.hasClassification(self, classification)
759
- return isUnitType(self.handle, classification)
809
+ return IsUnitType(self.handle, classification)
760
810
  end
761
811
  function Unit.prototype.isVisibleTo(self, player)
762
812
  return isUnitVisible(self.handle, player.handle)
@@ -765,13 +815,13 @@ function Unit.prototype.isInvisibleTo(self, player)
765
815
  return isUnitInvisible(self.handle, player.handle)
766
816
  end
767
817
  function Unit.prototype.isInRangeOf(self, x, y, range)
768
- local ____temp_2
818
+ local ____temp_3
769
819
  if type(x) == "number" then
770
- ____temp_2 = isUnitInRangeXY(self.handle, x, y, range)
820
+ ____temp_3 = isUnitInRangeXY(self.handle, x, y, range)
771
821
  else
772
- ____temp_2 = isUnitInRange(self.handle, x.handle, y)
822
+ ____temp_3 = isUnitInRange(self.handle, x.handle, y)
773
823
  end
774
- return ____temp_2
824
+ return ____temp_3
775
825
  end
776
826
  function Unit.prototype.isAllyOf(self, unit)
777
827
  return isUnitAlly(
@@ -789,16 +839,30 @@ function Unit.prototype.playAnimation(self, animation, rarity)
789
839
  if type(animation) == "number" then
790
840
  setUnitAnimationByIndex(self.handle, animation)
791
841
  elseif rarity then
792
- setUnitAnimationWithRarity(self.handle, animation, rarity)
842
+ SetUnitAnimationWithRarity(self.handle, animation, rarity)
793
843
  else
794
844
  setUnitAnimation(self.handle, animation)
795
845
  end
796
846
  end
847
+ function Unit.prototype.resetAnimation(self)
848
+ ResetUnitAnimation(self.handle)
849
+ end
797
850
  function Unit.prototype.queueAnimation(self, animation)
798
- queueUnitAnimation(self.handle, animation)
851
+ QueueUnitAnimation(self.handle, animation)
852
+ end
853
+ function Unit.prototype.chooseWeapon(self, target)
854
+ local firstWeapon = self.firstWeapon
855
+ if firstWeapon.isEnabled and target:isAllowedTarget(self, firstWeapon.allowedTargetCombatClassifications) then
856
+ return firstWeapon
857
+ end
858
+ local secondWeapon = self.secondWeapon
859
+ if secondWeapon.isEnabled and target:isAllowedTarget(target, secondWeapon.allowedTargetCombatClassifications) then
860
+ return secondWeapon
861
+ end
862
+ return nil
799
863
  end
800
864
  function Unit.prototype.delayHealthChecks(self)
801
- self[103] = (self[103] or 0) + 1
865
+ self[104] = (self[104] or 0) + 1
802
866
  Timer:run(delayHealthChecksCallback, self)
803
867
  end
804
868
  function Unit.prototype.setPosition(self, x, y)
@@ -808,21 +872,21 @@ function Unit.prototype.isSelected(self, player)
808
872
  return IsUnitSelected(self.handle, player.handle)
809
873
  end
810
874
  function Unit.prototype.explode(self)
811
- setUnitExploded(self.handle, true)
875
+ SetUnitExploded(self.handle, true)
812
876
  killUnit(self.handle)
813
877
  end
814
878
  function Unit.prototype.kill(self)
815
879
  killUnit(self.handle)
816
880
  end
817
881
  function Unit.prototype.revive(self, x, y, doEffect)
818
- local ____ReviveHero_5 = ReviveHero
819
- local ____array_4 = __TS__SparseArrayNew(self.handle, x, y)
820
- local ____doEffect_3 = doEffect
821
- if ____doEffect_3 == nil then
822
- ____doEffect_3 = false
882
+ local ____ReviveHero_6 = ReviveHero
883
+ local ____array_5 = __TS__SparseArrayNew(self.handle, x, y)
884
+ local ____doEffect_4 = doEffect
885
+ if ____doEffect_4 == nil then
886
+ ____doEffect_4 = false
823
887
  end
824
- __TS__SparseArrayPush(____array_4, ____doEffect_3)
825
- ____ReviveHero_5(__TS__SparseArraySpread(____array_4))
888
+ __TS__SparseArrayPush(____array_5, ____doEffect_4)
889
+ ____ReviveHero_6(__TS__SparseArraySpread(____array_5))
826
890
  end
827
891
  function Unit.prototype.healTarget(self, target, amount)
828
892
  if __TS__InstanceOf(target, ____exports.Unit) and target:hasAbility(fourCC("BIhm")) then
@@ -865,17 +929,16 @@ function Unit.prototype.itemInSlot(self, slot)
865
929
  return Item:of(unitItemInSlot(self.handle, slot))
866
930
  end
867
931
  function Unit.prototype.addAbility(self, abilityId)
868
- if unitAddAbility(self.handle, abilityId) then
869
- local ability = UnitAbility:of(
870
- checkNotNull(getUnitAbility(self.handle, abilityId)),
871
- abilityId,
872
- self
873
- )
932
+ local ability = UnitAbility:of(
933
+ doUnitAbilityAction(self.handle, abilityId, addAbility, abilityId),
934
+ abilityId,
935
+ self
936
+ )
937
+ if ability ~= nil then
874
938
  local abilities = self.abilities
875
939
  abilities[#abilities + 1] = ability
876
- return ability
877
940
  end
878
- return nil
941
+ return ability
879
942
  end
880
943
  function Unit.prototype.makeAbilityPermanent(self, abilityId, permanent)
881
944
  return UnitMakeAbilityPermanent(self.handle, permanent, abilityId)
@@ -889,31 +952,21 @@ end
889
952
  function Unit.prototype.hasAbility(self, abilityId)
890
953
  return getUnitAbilityLevel(self.handle, abilityId) > 0
891
954
  end
892
- function Unit.prototype.getAbilityById(self, abilityId)
893
- local handle = self.handle
894
- if unitAddAbility(handle, abilityId) then
895
- assert(unitRemoveAbility(handle, abilityId))
896
- return nil
897
- end
898
- return UnitAbility:of(
899
- getUnitAbility(self.handle, abilityId),
900
- abilityId,
901
- self
902
- )
955
+ function Unit.prototype.getAbility(self, abilityId)
956
+ local ability = doUnitAbilityAction(self.handle, abilityId, getUnitAbility, abilityId)
957
+ return UnitAbility:of(ability, abilityId, self)
903
958
  end
904
- function Unit.prototype.removeAbility(self, abilityId)
905
- if unitRemoveAbility(self.handle, abilityId) then
906
- local abilities = self.abilities
907
- for i = 1, #abilities do
908
- if abilities[i].typeId == abilityId then
909
- abilities[i]:destroy()
910
- tremove(abilities, i)
911
- return true
912
- end
959
+ function Unit.prototype.removeAbility(self, abilityTypeId)
960
+ local abilities = self.abilities
961
+ for i = 1, #abilities do
962
+ if abilities[i].typeId == abilityTypeId then
963
+ local ability = abilities[i]
964
+ tremove(abilities, i)
965
+ ability:destroy()
966
+ return true
913
967
  end
914
- return true
915
968
  end
916
- return false
969
+ return doUnitAbilityAction(self.handle, abilityTypeId, unitRemoveAbility, abilityTypeId)
917
970
  end
918
971
  function Unit.prototype.hideAbility(self, abilityId, flag)
919
972
  BlzUnitHideAbility(self.handle, abilityId, flag)
@@ -927,6 +980,21 @@ end
927
980
  function Unit.prototype.endAbilityCooldown(self, abilityId)
928
981
  BlzEndUnitAbilityCooldown(self.handle, abilityId)
929
982
  end
983
+ function Unit.prototype.interruptMovement(self)
984
+ local handle = self.handle
985
+ unitDisableAbility(
986
+ handle,
987
+ fourCC("Amov"),
988
+ true,
989
+ false
990
+ )
991
+ unitDisableAbility(
992
+ handle,
993
+ fourCC("Amov"),
994
+ false,
995
+ false
996
+ )
997
+ end
930
998
  function Unit.prototype.interruptAttack(self)
931
999
  unitInterruptAttack(self.handle)
932
1000
  end
@@ -1000,18 +1068,44 @@ function Unit.prototype.unpauseEx(self)
1000
1068
  end
1001
1069
  function Unit.prototype.incrementStunCounter(self)
1002
1070
  local stunCounter = self[102] or 0
1003
- if not self[101] or stunCounter >= 0 then
1071
+ if not self[101] and (self[103] or 0) <= 0 or stunCounter >= 0 then
1004
1072
  BlzPauseUnitEx(self.handle, true)
1005
1073
  end
1006
1074
  self[102] = stunCounter + 1
1007
1075
  end
1008
1076
  function Unit.prototype.decrementStunCounter(self)
1009
1077
  local stunCounter = self[102] or 0
1010
- if not self[101] or stunCounter >= 1 then
1078
+ if not self[101] and (self[103] or 0) <= 0 or stunCounter >= 1 then
1011
1079
  BlzPauseUnitEx(self.handle, false)
1012
1080
  end
1013
1081
  self[102] = stunCounter - 1
1014
1082
  end
1083
+ function Unit.prototype.incrementForceStunCounter(self)
1084
+ local forceStunCounter = self[103] or 0
1085
+ if forceStunCounter == 0 then
1086
+ local handle = self.handle
1087
+ if not self[101] then
1088
+ for _ = self[102] or 0, -1 do
1089
+ BlzPauseUnitEx(handle, true)
1090
+ end
1091
+ end
1092
+ BlzPauseUnitEx(handle, true)
1093
+ end
1094
+ self[103] = forceStunCounter + 1
1095
+ end
1096
+ function Unit.prototype.decrementForceStunCounter(self)
1097
+ local forceStunCounter = self[103] or 0
1098
+ if forceStunCounter == 1 then
1099
+ local handle = self.handle
1100
+ if not self[101] then
1101
+ for _ = self[102] or 0, -1 do
1102
+ BlzPauseUnitEx(handle, false)
1103
+ end
1104
+ end
1105
+ BlzPauseUnitEx(handle, false)
1106
+ end
1107
+ self[103] = forceStunCounter - 1
1108
+ end
1015
1109
  function Unit.create(self, owner, id, x, y, facing, skinId)
1016
1110
  local handle = skinId and BlzCreateUnitWithSkin(
1017
1111
  owner.handle,
@@ -1200,7 +1294,15 @@ __TS__SetDescriptor(
1200
1294
  Unit.prototype,
1201
1295
  "isIllusion",
1202
1296
  {get = function(self)
1203
- return isUnitIllusion(self.handle)
1297
+ return IsUnitIllusion(self.handle)
1298
+ end},
1299
+ true
1300
+ )
1301
+ __TS__SetDescriptor(
1302
+ Unit.prototype,
1303
+ "isStunned",
1304
+ {get = function(self)
1305
+ return getUnitCurrentOrder(self.handle) == orderId("stunned")
1204
1306
  end},
1205
1307
  true
1206
1308
  )
@@ -1277,6 +1379,19 @@ __TS__SetDescriptor(
1277
1379
  },
1278
1380
  true
1279
1381
  )
1382
+ __TS__SetDescriptor(
1383
+ Unit.prototype,
1384
+ "primaryAttribute",
1385
+ {
1386
+ get = function(self)
1387
+ return getUnitIntegerField(self.handle, UNIT_IF_PRIMARY_ATTRIBUTE)
1388
+ end,
1389
+ set = function(self, primaryAttribute)
1390
+ setUnitIntegerField(self.handle, UNIT_IF_PRIMARY_ATTRIBUTE, primaryAttribute)
1391
+ end
1392
+ },
1393
+ true
1394
+ )
1280
1395
  __TS__SetDescriptor(
1281
1396
  Unit.prototype,
1282
1397
  "strengthBase",
@@ -1398,17 +1513,17 @@ __TS__SetDescriptor(
1398
1513
  "isTeamGlowVisible",
1399
1514
  {
1400
1515
  get = function(self)
1401
- return not self[106]
1516
+ return not self[107]
1402
1517
  end,
1403
1518
  set = function(self, isTeamGlowVisible)
1404
- showUnitTeamGlow(self.handle, isTeamGlowVisible)
1405
- local ____temp_6
1519
+ BlzShowUnitTeamGlow(self.handle, isTeamGlowVisible)
1520
+ local ____temp_7
1406
1521
  if not isTeamGlowVisible then
1407
- ____temp_6 = true
1522
+ ____temp_7 = true
1408
1523
  else
1409
- ____temp_6 = nil
1524
+ ____temp_7 = nil
1410
1525
  end
1411
- self[106] = ____temp_6
1526
+ self[107] = ____temp_7
1412
1527
  end
1413
1528
  },
1414
1529
  true
@@ -1417,9 +1532,9 @@ __TS__SetDescriptor(
1417
1532
  Unit.prototype,
1418
1533
  "color",
1419
1534
  {set = function(self, color)
1420
- setUnitColor(self.handle, color.handle)
1421
- if self[106] then
1422
- showUnitTeamGlow(self.handle, false)
1535
+ SetUnitColor(self.handle, color.handle)
1536
+ if self[107] then
1537
+ BlzShowUnitTeamGlow(self.handle, false)
1423
1538
  end
1424
1539
  end},
1425
1540
  true
@@ -1442,14 +1557,14 @@ __TS__SetDescriptor(
1442
1557
  "maxHealth",
1443
1558
  {
1444
1559
  get = function(self)
1445
- return BlzGetUnitMaxHP(self.handle) - (self[104] or 0) - (self[105] or 0)
1560
+ return BlzGetUnitMaxHP(self.handle) - (self[105] or 0) - (self[106] or 0)
1446
1561
  end,
1447
1562
  set = function(self, maxHealth)
1448
- if maxHealth < 1 and self[103] ~= nil then
1449
- self[104] = (self[104] or 0) + (1 - maxHealth)
1563
+ if maxHealth < 1 and self[104] ~= nil then
1564
+ self[105] = (self[105] or 0) + (1 - maxHealth)
1450
1565
  maxHealth = 1
1451
1566
  end
1452
- BlzSetUnitMaxHP(self.handle, maxHealth + (self[105] or 0))
1567
+ BlzSetUnitMaxHP(self.handle, maxHealth + (self[106] or 0))
1453
1568
  end
1454
1569
  },
1455
1570
  true
@@ -1491,10 +1606,10 @@ __TS__SetDescriptor(
1491
1606
  "health",
1492
1607
  {
1493
1608
  get = function(self)
1494
- return GetWidgetLife(self.handle) - (self[105] or 0)
1609
+ return GetWidgetLife(self.handle) - (self[106] or 0)
1495
1610
  end,
1496
1611
  set = function(self, health)
1497
- SetWidgetLife(self.handle, health + (self[105] or 0))
1612
+ SetWidgetLife(self.handle, health + (self[106] or 0))
1498
1613
  end
1499
1614
  },
1500
1615
  true
@@ -1570,25 +1685,12 @@ __TS__SetDescriptor(
1570
1685
  },
1571
1686
  true
1572
1687
  )
1573
- __TS__SetDescriptor(
1574
- Unit.prototype,
1575
- "flyHeight",
1576
- {
1577
- get = function(self)
1578
- return getUnitFlyHeight(self.handle)
1579
- end,
1580
- set = function(self, v)
1581
- SetUnitFlyHeight(self.handle, v, 100000)
1582
- end
1583
- },
1584
- true
1585
- )
1586
1688
  __TS__SetDescriptor(
1587
1689
  Unit.prototype,
1588
1690
  "x",
1589
1691
  {
1590
1692
  get = function(self)
1591
- return getUnitX(self.handle)
1693
+ return self[108] or getUnitX(self.handle)
1592
1694
  end,
1593
1695
  set = function(self, v)
1594
1696
  SetUnitX(self.handle, v)
@@ -1601,7 +1703,7 @@ __TS__SetDescriptor(
1601
1703
  "y",
1602
1704
  {
1603
1705
  get = function(self)
1604
- return getUnitY(self.handle)
1706
+ return self[109] or getUnitY(self.handle)
1605
1707
  end,
1606
1708
  set = function(self, v)
1607
1709
  SetUnitY(self.handle, v)
@@ -1687,10 +1789,10 @@ __TS__SetDescriptor(
1687
1789
  "gold",
1688
1790
  {
1689
1791
  get = function(self)
1690
- return getResourceAmount(self.handle)
1792
+ return GetResourceAmount(self.handle)
1691
1793
  end,
1692
1794
  set = function(self, gold)
1693
- setResourceAmount(self.handle, gold)
1795
+ SetResourceAmount(self.handle, gold)
1694
1796
  end
1695
1797
  },
1696
1798
  true
@@ -1706,14 +1808,18 @@ __TS__SetDescriptor(
1706
1808
  local handle = self.handle
1707
1809
  if isPaused and not IsUnitPaused(handle) then
1708
1810
  self[101] = true
1709
- for _ = self[102] or 0, -1 do
1710
- BlzPauseUnitEx(handle, true)
1811
+ if (self[103] or 0) <= 0 then
1812
+ for _ = self[102] or 0, -1 do
1813
+ BlzPauseUnitEx(handle, true)
1814
+ end
1711
1815
  end
1712
1816
  PauseUnit(handle, true)
1713
1817
  elseif not isPaused and IsUnitPaused(handle) then
1714
1818
  PauseUnit(handle, false)
1715
- for _ = self[102] or 0, -1 do
1716
- BlzPauseUnitEx(handle, false)
1819
+ if (self[103] or 0) <= 0 then
1820
+ for _ = self[102] or 0, -1 do
1821
+ BlzPauseUnitEx(handle, false)
1822
+ end
1717
1823
  end
1718
1824
  self[101] = nil
1719
1825
  end
@@ -1771,20 +1877,6 @@ __TS__SetDescriptor(
1771
1877
  },
1772
1878
  true
1773
1879
  )
1774
- __TS__SetDescriptor(
1775
- Unit.prototype,
1776
- "scale",
1777
- {
1778
- get = function(self)
1779
- return getUnitRealField(self.handle, UNIT_RF_SCALING_VALUE)
1780
- end,
1781
- set = function(self, v)
1782
- setUnitScale(self.handle, v, v, v)
1783
- setUnitRealField(self.handle, UNIT_RF_SCALING_VALUE, v)
1784
- end
1785
- },
1786
- true
1787
- )
1788
1880
  __TS__SetDescriptor(
1789
1881
  Unit.prototype,
1790
1882
  "timeScale",
@@ -1818,6 +1910,19 @@ __TS__SetDescriptor(
1818
1910
  end},
1819
1911
  true
1820
1912
  )
1913
+ __TS__SetDescriptor(
1914
+ Unit.prototype,
1915
+ "movementType",
1916
+ {
1917
+ get = function(self)
1918
+ return getUnitIntegerField(self.handle, UNIT_IF_MOVE_TYPE)
1919
+ end,
1920
+ set = function(self, movementType)
1921
+ setUnitIntegerField(self.handle, UNIT_IF_MOVE_TYPE, movementType)
1922
+ end
1923
+ },
1924
+ true
1925
+ )
1821
1926
  __TS__SetDescriptor(
1822
1927
  Unit.prototype,
1823
1928
  "pathing",
@@ -1999,6 +2104,14 @@ __TS__SetDescriptor(
1999
2104
  end},
2000
2105
  true
2001
2106
  )
2107
+ __TS__SetDescriptor(
2108
+ Unit.prototype,
2109
+ "targetAcquiredEvent",
2110
+ {get = function(self)
2111
+ return self:getEvent(EVENT_UNIT_ACQUIRED_TARGET)
2112
+ end},
2113
+ true
2114
+ )
2002
2115
  __TS__SetDescriptor(
2003
2116
  Unit.prototype,
2004
2117
  "onSelect",
@@ -2134,25 +2247,25 @@ Unit.onTargetCast = dispatchId(__TS__New(
2134
2247
  InitializingEvent,
2135
2248
  function(event)
2136
2249
  local function listener(unit, id)
2137
- local ____GetSpellTargetUnit_result_9
2250
+ local ____GetSpellTargetUnit_result_10
2138
2251
  if GetSpellTargetUnit() then
2139
- ____GetSpellTargetUnit_result_9 = ____exports.Unit:of(GetSpellTargetUnit())
2252
+ ____GetSpellTargetUnit_result_10 = ____exports.Unit:of(GetSpellTargetUnit())
2140
2253
  else
2141
- local ____GetSpellTargetItem_result_8
2254
+ local ____GetSpellTargetItem_result_9
2142
2255
  if GetSpellTargetItem() then
2143
- ____GetSpellTargetItem_result_8 = Item:of(GetSpellTargetItem())
2256
+ ____GetSpellTargetItem_result_9 = Item:of(GetSpellTargetItem())
2144
2257
  else
2145
- local ____GetSpellTargetDestructable_result_7
2258
+ local ____GetSpellTargetDestructable_result_8
2146
2259
  if GetSpellTargetDestructable() then
2147
- ____GetSpellTargetDestructable_result_7 = Destructable:of(GetSpellTargetDestructable())
2260
+ ____GetSpellTargetDestructable_result_8 = Destructable:of(GetSpellTargetDestructable())
2148
2261
  else
2149
- ____GetSpellTargetDestructable_result_7 = nil
2262
+ ____GetSpellTargetDestructable_result_8 = nil
2150
2263
  end
2151
- ____GetSpellTargetItem_result_8 = ____GetSpellTargetDestructable_result_7
2264
+ ____GetSpellTargetItem_result_9 = ____GetSpellTargetDestructable_result_8
2152
2265
  end
2153
- ____GetSpellTargetUnit_result_9 = ____GetSpellTargetItem_result_8
2266
+ ____GetSpellTargetUnit_result_10 = ____GetSpellTargetItem_result_9
2154
2267
  end
2155
- local target = ____GetSpellTargetUnit_result_9
2268
+ local target = ____GetSpellTargetUnit_result_10
2156
2269
  if target then
2157
2270
  invoke(event, unit, id, target)
2158
2271
  end
@@ -2360,38 +2473,57 @@ Unit.onDamaging = (function()
2360
2473
  if source and source.typeId == dummyUnitId then
2361
2474
  source = nil
2362
2475
  end
2363
- local target = BlzGetEventDamageTarget()
2476
+ local target = ____exports.Unit:of(BlzGetEventDamageTarget())
2477
+ local metadata = damageMetadataByTarget[target]
2478
+ damageMetadataByTarget[target] = nil
2364
2479
  local data = {
2365
2480
  amount = GetEventDamage(),
2366
- attackType = BlzGetEventAttackType(),
2481
+ attackType = nativeToAttackType(BlzGetEventAttackType()),
2367
2482
  damageType = BlzGetEventDamageType(),
2368
2483
  weaponType = BlzGetEventWeaponType(),
2369
- isAttack = BlzGetEventIsAttack()
2484
+ metadata = metadata,
2485
+ isAttack = BlzGetEventIsAttack(),
2486
+ originalAmount = GetEventDamage(),
2487
+ originalMetadata = metadata,
2488
+ preventRetaliation = damagingEventPreventRetaliation
2370
2489
  }
2371
2490
  if data.isAttack and source then
2372
- local weapon = BlzGetUnitWeaponBooleanField(source.handle, UNIT_WEAPON_BF_ATTACKS_ENABLED, 1) and (BlzGetUnitWeaponBooleanField(source.handle, UNIT_WEAPON_BF_ATTACKS_ENABLED, 0) and -1 or 1) or 0
2373
- if weapon == -1 then
2374
- local targetsAllowed = BlzGetUnitWeaponIntegerField(source.handle, UNIT_WEAPON_IF_ATTACK_TARGETS_ALLOWED, 0)
2375
- weapon = 0
2376
- end
2377
- data.weapon = assert(source.weapons[weapon + 1])
2491
+ data.weapon = source:chooseWeapon(target)
2378
2492
  end
2379
2493
  if not data.isAttack or not source or not source._attackHandlers then
2380
2494
  invoke(
2381
2495
  event,
2382
2496
  source,
2383
- ____exports.Unit:of(target),
2497
+ target,
2384
2498
  setmetatable(
2385
2499
  {},
2386
2500
  {
2387
2501
  __index = data,
2388
2502
  __newindex = function(self, key, value)
2389
- damageSetters[key](value)
2503
+ local damageSetter = damageSetters[key]
2504
+ if damageSetter ~= nil then
2505
+ damageSetter(value)
2506
+ end
2390
2507
  data[key] = value
2391
2508
  end
2392
2509
  }
2393
2510
  )
2394
2511
  )
2512
+ if data[0] and source then
2513
+ local sourceOwner = source.owner.handle
2514
+ data[1] = sourceOwner
2515
+ local targetOwner = target.owner.handle
2516
+ data[2] = targetOwner
2517
+ if not GetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE) then
2518
+ SetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE, true)
2519
+ data[3] = true
2520
+ end
2521
+ if not GetPlayerAlliance(targetOwner, sourceOwner, ALLIANCE_PASSIVE) then
2522
+ SetPlayerAlliance(targetOwner, sourceOwner, ALLIANCE_PASSIVE, true)
2523
+ data[4] = true
2524
+ end
2525
+ end
2526
+ damagingEventByTarget[target] = data
2395
2527
  return
2396
2528
  end
2397
2529
  BlzSetEventDamage(0)
@@ -2399,7 +2531,7 @@ Unit.onDamaging = (function()
2399
2531
  BlzSetEventDamageType(DAMAGE_TYPE_UNKNOWN)
2400
2532
  BlzSetEventWeaponType(WEAPON_TYPE_WHOKNOWS)
2401
2533
  local sourceOwner = source.owner.handle
2402
- local targetOwner = GetOwningPlayer(target)
2534
+ local targetOwner = target.owner.handle
2403
2535
  if not GetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE) then
2404
2536
  SetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE, true)
2405
2537
  Timer:run(function()
@@ -2415,23 +2547,19 @@ Unit.onDamaging = (function()
2415
2547
  for ____, ____value in ipairs(source._attackHandlers) do
2416
2548
  local condition = ____value[1]
2417
2549
  local action = ____value[2]
2418
- if condition(
2419
- source,
2420
- ____exports.Unit:of(target),
2421
- data
2422
- ) then
2550
+ if condition(source, target, data) then
2423
2551
  action(
2424
2552
  source,
2425
- ____exports.Unit:of(target),
2553
+ target,
2426
2554
  setmetatable(
2427
2555
  {fire = function()
2428
2556
  UnitDamageTarget(
2429
2557
  source.handle,
2430
- target,
2558
+ target.handle,
2431
2559
  data.amount,
2432
2560
  true,
2433
2561
  true,
2434
- data.attackType,
2562
+ attackTypeToNative(data.attackType),
2435
2563
  data.damageType,
2436
2564
  data.weaponType
2437
2565
  )
@@ -2458,30 +2586,54 @@ Unit.onDamage = __TS__New(
2458
2586
  if source and source.typeId == dummyUnitId then
2459
2587
  source = nil
2460
2588
  end
2589
+ local target = ____exports.Unit:of(BlzGetEventDamageTarget())
2590
+ local damagingEvent = damagingEventByTarget[target]
2591
+ damagingEventByTarget[target] = nil
2461
2592
  local data = {
2462
2593
  amount = GetEventDamage(),
2463
- attackType = BlzGetEventAttackType(),
2594
+ attackType = nativeToAttackType(BlzGetEventAttackType()),
2464
2595
  damageType = BlzGetEventDamageType(),
2465
2596
  weaponType = BlzGetEventWeaponType(),
2597
+ metadata = damagingEvent and damagingEvent.metadata,
2466
2598
  isAttack = BlzGetEventIsAttack(),
2467
- originalAmount = GetEventDamage(),
2599
+ originalAmount = damagingEvent and damagingEvent.originalAmount or GetEventDamage(),
2600
+ originalMetadata = damagingEvent and damagingEvent.originalMetadata,
2468
2601
  preventDeath = damageEventPreventDeath
2469
2602
  }
2603
+ if damagingEvent then
2604
+ for key, value in pairs(damagingEvent) do
2605
+ if isAttribute(key) then
2606
+ data[key] = value
2607
+ end
2608
+ end
2609
+ local sourceOwner = damagingEvent[1]
2610
+ if sourceOwner then
2611
+ local targetOwner = damagingEvent[2]
2612
+ if damagingEvent[3] then
2613
+ SetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE, false)
2614
+ end
2615
+ if damagingEvent[4] then
2616
+ SetPlayerAlliance(targetOwner, sourceOwner, ALLIANCE_PASSIVE, false)
2617
+ end
2618
+ end
2619
+ end
2470
2620
  local evData = setmetatable(
2471
2621
  {},
2472
2622
  {
2473
2623
  __index = data,
2474
2624
  __newindex = function(self, key, value)
2475
- damageSetters[key](value)
2625
+ local damageSetter = damageSetters[key]
2626
+ if damageSetter ~= nil then
2627
+ damageSetter(value)
2628
+ end
2476
2629
  data[key] = value
2477
2630
  end
2478
2631
  }
2479
2632
  )
2480
- local target = ____exports.Unit:of(BlzGetEventDamageTarget())
2481
2633
  invoke(event, source, target, evData)
2482
2634
  if evData[0] ~= nil and target.health - evData.amount < 0.405 then
2483
2635
  local bonusHealth = math.ceil(evData.amount)
2484
- target[105] = (target[105] or 0) + bonusHealth
2636
+ target[106] = (target[106] or 0) + bonusHealth
2485
2637
  BlzSetUnitMaxHP(
2486
2638
  target.handle,
2487
2639
  BlzGetUnitMaxHP(target.handle) + bonusHealth
@@ -2495,7 +2647,7 @@ Unit.onDamage = __TS__New(
2495
2647
  evData[0],
2496
2648
  table.unpack(evData, 1 + 1, 1 + (evData[1] or 0))
2497
2649
  )
2498
- target[105] = (target[105] or 0) - bonusHealth
2650
+ target[106] = (target[106] or 0) - bonusHealth
2499
2651
  SetWidgetLife(
2500
2652
  target.handle,
2501
2653
  GetWidgetLife(target.handle) - bonusHealth
@@ -2531,10 +2683,14 @@ Unit.itemPickedUpEvent = __TS__New(
2531
2683
  ____exports.UnitTriggerEvent,
2532
2684
  EVENT_PLAYER_UNIT_PICKUP_ITEM,
2533
2685
  function()
2534
- local unit = getTriggerUnit()
2535
- local item = getManipulatedItem()
2536
- if getUnitTypeId(unit) ~= dummyUnitId and not (ignoreEventsItems[item] ~= nil) then
2537
- return ____exports.Unit:of(unit), Item:of(item)
2686
+ local unitHandle = getTriggerUnit()
2687
+ local itemHandle = getManipulatedItem()
2688
+ if getUnitTypeId(unitHandle) ~= dummyUnitId and not (ignoreEventsItems[itemHandle] ~= nil) then
2689
+ local unit = ____exports.Unit:of(unitHandle)
2690
+ local item = Item:of(itemHandle)
2691
+ if item.owner ~= unit then
2692
+ return unit, item
2693
+ end
2538
2694
  end
2539
2695
  return IgnoreEvent
2540
2696
  end
@@ -2554,7 +2710,22 @@ Unit.itemUsedEvent = __TS__New(
2554
2710
  Unit.itemStackedEvent = __TS__New(
2555
2711
  ____exports.UnitTriggerEvent,
2556
2712
  EVENT_PLAYER_UNIT_STACK_ITEM,
2557
- function() return ____exports.Unit:of(getTriggerUnit()), Item:of(getManipulatedItem()) end
2713
+ function() return ____exports.Unit:of(getTriggerUnit()), Item:of(BlzGetStackingItemTarget()), Item:of(BlzGetStackingItemSource()) end
2714
+ )
2715
+ __TS__ObjectDefineProperty(
2716
+ Unit,
2717
+ "itemChargesChangedEvent",
2718
+ {get = function(self)
2719
+ local event = __TS__New(Event)
2720
+ Item.chargesChangedEvent:addListener(function(item)
2721
+ local unit = item.owner
2722
+ if unit ~= nil then
2723
+ invoke(event, unit, item)
2724
+ end
2725
+ end)
2726
+ rawset(self, "itemChargesChangedEvent", event)
2727
+ return event
2728
+ end}
2558
2729
  )
2559
2730
  __TS__ObjectDefineProperty(
2560
2731
  Unit,
@@ -2626,6 +2797,10 @@ __TS__ObjectDefineProperty(
2626
2797
  rawset(self, "destroyEvent", destroyEvent)
2627
2798
  return destroyEvent
2628
2799
  end}
2800
+ )
2801
+ Unit.synchronize = synchronizer(
2802
+ function(unit) return unit.syncId end,
2803
+ function(syncId) return unitBySyncId[syncId] end
2629
2804
  );
2630
2805
  (function(self)
2631
2806
  local leaveAbilityIds = postcompile(function()