warscript 0.0.1-dev.d1328b7 → 0.0.1-dev.d1499df

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 (205) 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 +14 -6
  6. package/core/types/effect.lua +131 -35
  7. package/core/types/frame.d.ts +3 -0
  8. package/core/types/frame.lua +83 -21
  9. package/core/types/player.d.ts +15 -0
  10. package/core/types/player.lua +56 -14
  11. package/core/types/playerCamera.d.ts +2 -0
  12. package/core/types/playerCamera.lua +123 -5
  13. package/core/types/sound.d.ts +17 -24
  14. package/core/types/sound.lua +99 -24
  15. package/core/types/tileCell.d.ts +11 -1
  16. package/core/types/tileCell.lua +97 -0
  17. package/core/types/timer.d.ts +9 -8
  18. package/core/types/timer.lua +45 -23
  19. package/core/util.d.ts +1 -1
  20. package/core/util.lua +12 -1
  21. package/decl/native.d.ts +846 -790
  22. package/engine/behavior.d.ts +5 -0
  23. package/engine/behavior.lua +106 -27
  24. package/engine/behaviour/ability/always-enabled.d.ts +7 -0
  25. package/engine/behaviour/ability/always-enabled.lua +31 -0
  26. package/engine/behaviour/ability/apply-buff.d.ts +5 -0
  27. package/engine/behaviour/ability/apply-buff.lua +32 -0
  28. package/engine/behaviour/ability/apply-unit-behavior.lua +1 -0
  29. package/engine/behaviour/ability/damage.d.ts +9 -3
  30. package/engine/behaviour/ability/damage.lua +26 -38
  31. package/engine/behaviour/ability/emulate-impact.d.ts +6 -0
  32. package/engine/behaviour/ability/emulate-impact.lua +43 -0
  33. package/engine/behaviour/ability/instant-impact.d.ts +2 -2
  34. package/engine/behaviour/ability/instant-impact.lua +4 -19
  35. package/engine/behaviour/ability/on-command-impact.d.ts +8 -0
  36. package/engine/behaviour/ability/on-command-impact.lua +25 -0
  37. package/engine/behaviour/ability/remove-buffs.d.ts +25 -0
  38. package/engine/behaviour/ability/remove-buffs.lua +49 -0
  39. package/engine/behaviour/ability/restore-mana.d.ts +1 -1
  40. package/engine/behaviour/ability/restore-mana.lua +6 -6
  41. package/engine/behaviour/ability.d.ts +20 -4
  42. package/engine/behaviour/ability.lua +111 -47
  43. package/engine/behaviour/unit/stun-immunity.d.ts +7 -3
  44. package/engine/behaviour/unit/stun-immunity.lua +52 -27
  45. package/engine/behaviour/unit.d.ts +34 -0
  46. package/engine/behaviour/unit.lua +190 -4
  47. package/engine/buff.d.ts +72 -45
  48. package/engine/buff.lua +357 -241
  49. package/engine/internal/ability.d.ts +20 -3
  50. package/engine/internal/ability.lua +126 -13
  51. package/engine/internal/item/ability.lua +162 -4
  52. package/engine/internal/item+owner.lua +12 -6
  53. package/engine/internal/item.d.ts +20 -19
  54. package/engine/internal/item.lua +191 -74
  55. package/engine/internal/mechanics/ability-duration.lua +1 -1
  56. package/engine/internal/misc/ability-disable-counter.d.ts +2 -0
  57. package/engine/internal/misc/ability-disable-counter.lua +13 -0
  58. package/engine/internal/misc/damage-metadata-by-target.d.ts +2 -0
  59. package/engine/internal/misc/damage-metadata-by-target.lua +5 -0
  60. package/engine/internal/misc/frame-coordinates.d.ts +2 -0
  61. package/engine/internal/misc/frame-coordinates.lua +21 -0
  62. package/engine/internal/misc/get-terrain-z.d.ts +2 -0
  63. package/engine/internal/misc/get-terrain-z.lua +11 -0
  64. package/engine/internal/misc/player-local-handle.d.ts +2 -0
  65. package/engine/internal/misc/player-local-handle.lua +5 -0
  66. package/engine/internal/object-data/auto-attack-speed-increase.d.ts +1 -1
  67. package/engine/internal/object-data/auto-attack-speed-increase.lua +2 -0
  68. package/engine/internal/object-data/evasion-probability.d.ts +2 -0
  69. package/engine/internal/object-data/evasion-probability.lua +16 -0
  70. package/engine/internal/unit/ability.d.ts +45 -1
  71. package/engine/internal/unit/ability.lua +128 -17
  72. package/engine/internal/unit/add-item-to-slot-init.d.ts +2 -0
  73. package/engine/internal/unit/add-item-to-slot-init.lua +23 -0
  74. package/engine/internal/unit/add-item-to-slot.d.ts +2 -0
  75. package/engine/internal/unit/add-item-to-slot.lua +52 -0
  76. package/engine/internal/unit/allowed-targets.d.ts +1 -1
  77. package/engine/internal/unit/allowed-targets.lua +9 -1
  78. package/engine/internal/unit/bonus.d.ts +2 -0
  79. package/engine/internal/unit/bonus.lua +17 -0
  80. package/engine/internal/unit/fly-height.d.ts +7 -0
  81. package/engine/internal/unit/fly-height.lua +20 -0
  82. package/engine/internal/unit/ignore-events-items.d.ts +2 -0
  83. package/engine/internal/unit/ignore-events-items.lua +5 -0
  84. package/engine/internal/unit/item.d.ts +1 -0
  85. package/engine/internal/unit/item.lua +8 -4
  86. package/engine/internal/unit/main-selected.d.ts +6 -0
  87. package/engine/internal/unit/main-selected.lua +18 -22
  88. package/engine/internal/unit/order.d.ts +20 -0
  89. package/engine/internal/unit/order.lua +136 -0
  90. package/engine/internal/unit+ability.lua +10 -1
  91. package/engine/internal/unit+damage.d.ts +2 -11
  92. package/engine/internal/unit+damage.lua +10 -14
  93. package/engine/internal/unit+spellSteal.lua +1 -2
  94. package/engine/internal/unit-missile-launch.lua +45 -14
  95. package/engine/internal/unit.d.ts +50 -15
  96. package/engine/internal/unit.lua +413 -170
  97. package/engine/internal/utility.lua +12 -0
  98. package/engine/lightning.d.ts +12 -5
  99. package/engine/lightning.lua +48 -14
  100. package/engine/local-client.d.ts +2 -0
  101. package/engine/local-client.lua +30 -0
  102. package/engine/object-data/auxiliary/animation-name.d.ts +1 -0
  103. package/engine/object-data/auxiliary/animation-name.lua +16 -0
  104. package/engine/object-data/auxiliary/armor-type.d.ts +11 -0
  105. package/engine/object-data/auxiliary/armor-type.lua +46 -0
  106. package/engine/object-data/auxiliary/attachment-preset.d.ts +7 -2
  107. package/engine/object-data/auxiliary/attachment-preset.lua +4 -3
  108. package/engine/object-data/auxiliary/attack-type.d.ts +7 -8
  109. package/engine/object-data/auxiliary/attack-type.lua +42 -0
  110. package/engine/object-data/auxiliary/movement-type.d.ts +7 -7
  111. package/engine/object-data/auxiliary/movement-type.lua +22 -0
  112. package/engine/object-data/auxiliary/sound-eax.d.ts +10 -0
  113. package/engine/object-data/auxiliary/sound-eax.lua +2 -0
  114. package/engine/object-data/auxiliary/sound-preset-name.d.ts +5 -1
  115. package/engine/object-data/auxiliary/tech-tree-dependency.d.ts +1 -1
  116. package/engine/object-data/auxiliary/unit-attribute.d.ts +6 -0
  117. package/engine/object-data/auxiliary/unit-attribute.lua +9 -0
  118. package/engine/object-data/entry/ability-type/berserk.d.ts +2 -0
  119. package/engine/object-data/entry/ability-type/berserk.lua +13 -0
  120. package/engine/object-data/entry/ability-type/blank-configurable.lua +12 -1
  121. package/engine/object-data/entry/ability-type/carrion-swarm.d.ts +14 -0
  122. package/engine/object-data/entry/ability-type/carrion-swarm.lua +65 -0
  123. package/engine/object-data/entry/ability-type/disease-cloud.lua +2 -2
  124. package/engine/object-data/entry/ability-type/engineering-upgrade.lua +2 -2
  125. package/engine/object-data/entry/ability-type/ensnare.d.ts +12 -0
  126. package/engine/object-data/entry/ability-type/ensnare.lua +52 -0
  127. package/engine/object-data/entry/ability-type/feral-spirit.lua +2 -2
  128. package/engine/object-data/entry/ability-type/permanent-invisibility.d.ts +8 -0
  129. package/engine/object-data/entry/ability-type/permanent-invisibility.lua +26 -0
  130. package/engine/object-data/entry/ability-type/phase-shift.d.ts +10 -0
  131. package/engine/object-data/entry/ability-type/phase-shift.lua +39 -0
  132. package/engine/object-data/entry/ability-type/phoenix-morph.lua +4 -4
  133. package/engine/object-data/entry/ability-type/raise-dead.d.ts +17 -0
  134. package/engine/object-data/entry/ability-type/raise-dead.lua +78 -0
  135. package/engine/object-data/entry/ability-type/shock-wave.d.ts +4 -0
  136. package/engine/object-data/entry/ability-type/shock-wave.lua +26 -0
  137. package/engine/object-data/entry/ability-type/slow-poison.d.ts +10 -0
  138. package/engine/object-data/entry/ability-type/slow-poison.lua +58 -0
  139. package/engine/object-data/entry/ability-type/summon-quilbeast.lua +2 -2
  140. package/engine/object-data/entry/ability-type/summon-water-elemental.lua +2 -2
  141. package/engine/object-data/entry/ability-type/web.d.ts +12 -0
  142. package/engine/object-data/entry/ability-type/web.lua +52 -0
  143. package/engine/object-data/entry/ability-type.d.ts +19 -17
  144. package/engine/object-data/entry/ability-type.lua +93 -36
  145. package/engine/object-data/entry/buff-type/applicable.lua +18 -37
  146. package/engine/object-data/entry/buff-type.d.ts +6 -12
  147. package/engine/object-data/entry/buff-type.lua +13 -29
  148. package/engine/object-data/entry/destructible-type.d.ts +1 -1
  149. package/engine/object-data/entry/item-type.d.ts +3 -1
  150. package/engine/object-data/entry/item-type.lua +15 -2
  151. package/engine/object-data/entry/lightning-type.d.ts +1 -1
  152. package/engine/object-data/entry/sound-preset.d.ts +33 -0
  153. package/engine/object-data/entry/sound-preset.lua +140 -0
  154. package/engine/object-data/entry/unit-type.d.ts +21 -5
  155. package/engine/object-data/entry/unit-type.lua +214 -93
  156. package/engine/object-data/entry/upgrade.d.ts +1 -1
  157. package/engine/object-data/entry/upgrade.lua +4 -4
  158. package/engine/object-data/entry.d.ts +16 -14
  159. package/engine/object-data/entry.lua +60 -32
  160. package/engine/object-data/utility/object-data-entry-id-generator.lua +7 -0
  161. package/engine/object-field/ability.d.ts +12 -6
  162. package/engine/object-field/ability.lua +8 -4
  163. package/engine/object-field/unit.d.ts +61 -3
  164. package/engine/object-field/unit.lua +220 -7
  165. package/engine/object-field.d.ts +23 -6
  166. package/engine/object-field.lua +303 -114
  167. package/engine/random.d.ts +9 -0
  168. package/engine/random.lua +13 -0
  169. package/engine/standard/entries/buff-type.d.ts +3 -0
  170. package/engine/standard/entries/buff-type.lua +3 -0
  171. package/engine/standard/entries/sound-preset.d.ts +10 -0
  172. package/engine/standard/entries/sound-preset.lua +10 -0
  173. package/engine/standard/fields/ability.d.ts +2 -0
  174. package/engine/standard/fields/ability.lua +2 -0
  175. package/engine/standard/fields/unit.d.ts +5 -0
  176. package/engine/standard/fields/unit.lua +9 -0
  177. package/engine/synchronization.d.ts +11 -0
  178. package/engine/synchronization.lua +77 -0
  179. package/engine/text-tag.d.ts +36 -2
  180. package/engine/text-tag.lua +250 -10
  181. package/engine/unit.d.ts +3 -0
  182. package/engine/unit.lua +3 -0
  183. package/net/socket.lua +1 -1
  184. package/objutil/buff.lua +2 -3
  185. package/objutil/unit.lua +8 -0
  186. package/package.json +2 -2
  187. package/patch-lualib.lua +1 -1
  188. package/utility/arrays.d.ts +10 -1
  189. package/utility/arrays.lua +45 -3
  190. package/utility/callback-array.d.ts +17 -0
  191. package/utility/callback-array.lua +61 -0
  192. package/utility/functions.d.ts +8 -0
  193. package/utility/functions.lua +13 -0
  194. package/utility/lazy.d.ts +2 -0
  195. package/utility/lazy.lua +14 -0
  196. package/utility/linked-set.d.ts +2 -0
  197. package/utility/linked-set.lua +22 -1
  198. package/utility/lua-maps.d.ts +15 -2
  199. package/utility/lua-maps.lua +53 -2
  200. package/utility/lua-sets.d.ts +2 -0
  201. package/utility/lua-sets.lua +7 -0
  202. package/utility/reflection.lua +11 -7
  203. package/utility/types.d.ts +3 -0
  204. package/core/types/order.d.ts +0 -25
  205. package/core/types/order.lua +0 -55
@@ -51,12 +51,23 @@ local ____arrays = require("utility.arrays")
51
51
  local forEach = ____arrays.forEach
52
52
  local ____math = require("math")
53
53
  local min = ____math.min
54
+ local ____ignore_2Devents_2Ditems = require("engine.internal.unit.ignore-events-items")
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
54
67
  local match = string.match
55
68
  local ____tostring = _G.tostring
56
69
  local setUnitAnimation = SetUnitAnimation
57
- local setUnitAnimationWithRarity = SetUnitAnimationWithRarity
58
70
  local setUnitAnimationByIndex = SetUnitAnimationByIndex
59
- local queueUnitAnimation = QueueUnitAnimation
60
71
  local getUnitIntegerField = BlzGetUnitIntegerField
61
72
  local getUnitRealField = BlzGetUnitRealField
62
73
  local getHeroStr = GetHeroStr
@@ -75,9 +86,9 @@ local setUnitScale = SetUnitScale
75
86
  local setUnitPosition = SetUnitPosition
76
87
  local setUnitTimeScale = SetUnitTimeScale
77
88
  local getHandleId = GetHandleId
89
+ local getUnitCurrentOrder = GetUnitCurrentOrder
78
90
  local createUnit = CreateUnit
79
91
  local killUnit = KillUnit
80
- local setUnitExploded = SetUnitExploded
81
92
  local removeUnit = RemoveUnit
82
93
  local getUnitTypeId = GetUnitTypeId
83
94
  local isHeroUnitId = IsHeroUnitId
@@ -93,8 +104,6 @@ local getSpellTargetItem = GetSpellTargetItem
93
104
  local getSpellTargetDestructable = GetSpellTargetDestructable
94
105
  local isUnitInRangeXY = IsUnitInRangeXY
95
106
  local isUnitInRange = IsUnitInRange
96
- local setResourceAmount = SetResourceAmount
97
- local getResourceAmount = GetResourceAmount
98
107
  local getUnitWeaponRealField = BlzGetUnitWeaponRealField
99
108
  local setUnitWeaponRealField = BlzSetUnitWeaponRealField
100
109
  local getUnitWeaponStringField = BlzGetUnitWeaponStringField
@@ -118,15 +127,9 @@ local getOrderedUnit = GetOrderedUnit
118
127
  local getIssuedOrderId = GetIssuedOrderId
119
128
  local isUnitInvulnerable = BlzIsUnitInvulnerable
120
129
  local unitAlive = UnitAlive
121
- local unitAddType = UnitAddType
122
- local unitRemoveType = UnitRemoveType
123
- local isUnitIllusion = IsUnitIllusion
124
- local isUnitType = IsUnitType
125
130
  local isUnitAlly = IsUnitAlly
126
131
  local isUnitEnemy = IsUnitEnemy
127
132
  local getOwningPlayer = GetOwningPlayer
128
- local setUnitColor = SetUnitColor
129
- local showUnitTeamGlow = BlzShowUnitTeamGlow
130
133
  ____exports.UnitClassification = {}
131
134
  local UnitClassification = ____exports.UnitClassification
132
135
  do
@@ -136,6 +139,7 @@ do
136
139
  UnitClassification.GROUND = UNIT_TYPE_GROUND
137
140
  UnitClassification.SUMMONED = UNIT_TYPE_SUMMONED
138
141
  UnitClassification.MECHANICAL = UNIT_TYPE_MECHANICAL
142
+ UnitClassification.WORKER = UNIT_TYPE_PEON
139
143
  UnitClassification.ANCIENT = UNIT_TYPE_ANCIENT
140
144
  UnitClassification.SUICIDAL = UNIT_TYPE_SAPPER
141
145
  UnitClassification.TAUREN = UNIT_TYPE_TAUREN
@@ -343,6 +347,9 @@ local function dispatchAbility(event)
343
347
  }
344
348
  )
345
349
  end
350
+ local function damagingEventPreventRetaliation(self)
351
+ self[0] = true
352
+ end
346
353
  local function damageEventPreventDeath(self, callback, ...)
347
354
  if self[0] ~= nil then
348
355
  return
@@ -354,7 +361,14 @@ local function damageEventPreventDeath(self, callback, ...)
354
361
  rawset(self, 1 + i, (select(i, ...)))
355
362
  end
356
363
  end
357
- 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
+ }
358
372
  local jlimitopByOperator = {
359
373
  [0] = LESS_THAN_OR_EQUAL,
360
374
  [1] = LESS_THAN_OR_EQUAL,
@@ -398,6 +412,19 @@ function UnitWeapon.prototype.____constructor(self, unit, index)
398
412
  self.unit = unit
399
413
  self.index = index
400
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
+ )
401
428
  __TS__SetDescriptor(
402
429
  UnitWeapon.prototype,
403
430
  "cooldown",
@@ -432,6 +459,19 @@ __TS__SetDescriptor(
432
459
  },
433
460
  true
434
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
+ )
435
475
  __TS__SetDescriptor(
436
476
  UnitWeapon.prototype,
437
477
  "damageBase",
@@ -562,17 +602,6 @@ local function retrieveAbility(unit, ability, abilityId)
562
602
  ____exports.Unit:of(unit)
563
603
  )
564
604
  end
565
- if not unitAddAbility(unit, abilityId) then
566
- if getUnitAbility(unit, abilityId) == ability then
567
- return UnitAbility:of(
568
- ability,
569
- abilityId,
570
- ____exports.Unit:of(unit)
571
- )
572
- end
573
- else
574
- unitRemoveAbility(unit, abilityId)
575
- end
576
605
  for i = 0, unitInventorySize(unit) - 1 do
577
606
  local item = unitItemInSlot(unit, i)
578
607
  if getItemAbility(item, abilityId) == ability then
@@ -630,15 +659,15 @@ for ____, player in ipairs(Player.all) do
630
659
  dummies[player] = dummy
631
660
  end
632
661
  local function delayHealthChecksCallback(unit)
633
- local counter = (unit[103] or 0) - 1
662
+ local counter = (unit[104] or 0) - 1
634
663
  if counter ~= 0 then
635
- unit[103] = counter
664
+ unit[104] = counter
636
665
  return
637
666
  end
638
- unit[103] = nil
639
- local healthBonus = unit[104]
667
+ unit[104] = nil
668
+ local healthBonus = unit[105]
640
669
  if healthBonus ~= nil then
641
- unit[104] = nil
670
+ unit[105] = nil
642
671
  local handle = unit.handle
643
672
  BlzSetUnitMaxHP(
644
673
  handle,
@@ -647,16 +676,26 @@ local function delayHealthChecksCallback(unit)
647
676
  end
648
677
  end
649
678
  local nextSyncId = 1
650
- 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
651
690
  ____exports.Unit = __TS__Class()
652
691
  local Unit = ____exports.Unit
653
692
  Unit.name = "Unit"
654
693
  __TS__ClassExtends(Unit, Handle)
655
694
  function Unit.prototype.____constructor(self, handle)
656
695
  Handle.prototype.____constructor(self, handle)
657
- local ____nextSyncId_0 = nextSyncId
658
- nextSyncId = ____nextSyncId_0 + 1
659
- self.syncId = ____nextSyncId_0
696
+ local ____nextSyncId_1 = nextSyncId
697
+ nextSyncId = ____nextSyncId_1 + 1
698
+ self.syncId = ____nextSyncId_1
660
699
  self._owner = Player:of(getOwningPlayer(handle))
661
700
  assert(unitAddAbility(handle, leaveDetectAbilityId) and UnitMakeAbilityPermanent(handle, true, leaveDetectAbilityId))
662
701
  assert(unitAddAbility(handle, morphDetectAbilityId))
@@ -688,6 +727,8 @@ function Unit.prototype.getEvent(self, event, collector)
688
727
  end
689
728
  function Unit.prototype.onDestroy(self)
690
729
  local handle = self.handle
730
+ self[108] = getUnitX(handle)
731
+ self[109] = getUnitY(handle)
691
732
  if not self._owner then
692
733
  self._owner = Player:of(getOwningPlayer(handle))
693
734
  end
@@ -755,17 +796,17 @@ function Unit.prototype.addModifier(self, property, modifier)
755
796
  end}
756
797
  end
757
798
  function Unit.prototype.hasCombatClassification(self, combatClassification)
758
- local ____combatClassification_1 = combatClassification
759
- 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
760
801
  end
761
802
  function Unit.prototype.addClassification(self, classification)
762
- return unitAddType(self.handle, classification)
803
+ return UnitAddType(self.handle, classification)
763
804
  end
764
805
  function Unit.prototype.removeClassification(self, classification)
765
- return unitRemoveType(self.handle, classification)
806
+ return UnitRemoveType(self.handle, classification)
766
807
  end
767
808
  function Unit.prototype.hasClassification(self, classification)
768
- return isUnitType(self.handle, classification)
809
+ return IsUnitType(self.handle, classification)
769
810
  end
770
811
  function Unit.prototype.isVisibleTo(self, player)
771
812
  return isUnitVisible(self.handle, player.handle)
@@ -774,13 +815,13 @@ function Unit.prototype.isInvisibleTo(self, player)
774
815
  return isUnitInvisible(self.handle, player.handle)
775
816
  end
776
817
  function Unit.prototype.isInRangeOf(self, x, y, range)
777
- local ____temp_2
818
+ local ____temp_3
778
819
  if type(x) == "number" then
779
- ____temp_2 = isUnitInRangeXY(self.handle, x, y, range)
820
+ ____temp_3 = isUnitInRangeXY(self.handle, x, y, range)
780
821
  else
781
- ____temp_2 = isUnitInRange(self.handle, x.handle, y)
822
+ ____temp_3 = isUnitInRange(self.handle, x.handle, y)
782
823
  end
783
- return ____temp_2
824
+ return ____temp_3
784
825
  end
785
826
  function Unit.prototype.isAllyOf(self, unit)
786
827
  return isUnitAlly(
@@ -798,16 +839,30 @@ function Unit.prototype.playAnimation(self, animation, rarity)
798
839
  if type(animation) == "number" then
799
840
  setUnitAnimationByIndex(self.handle, animation)
800
841
  elseif rarity then
801
- setUnitAnimationWithRarity(self.handle, animation, rarity)
842
+ SetUnitAnimationWithRarity(self.handle, animation, rarity)
802
843
  else
803
844
  setUnitAnimation(self.handle, animation)
804
845
  end
805
846
  end
847
+ function Unit.prototype.resetAnimation(self)
848
+ ResetUnitAnimation(self.handle)
849
+ end
806
850
  function Unit.prototype.queueAnimation(self, animation)
807
- 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
808
863
  end
809
864
  function Unit.prototype.delayHealthChecks(self)
810
- self[103] = (self[103] or 0) + 1
865
+ self[104] = (self[104] or 0) + 1
811
866
  Timer:run(delayHealthChecksCallback, self)
812
867
  end
813
868
  function Unit.prototype.setPosition(self, x, y)
@@ -817,21 +872,21 @@ function Unit.prototype.isSelected(self, player)
817
872
  return IsUnitSelected(self.handle, player.handle)
818
873
  end
819
874
  function Unit.prototype.explode(self)
820
- setUnitExploded(self.handle, true)
875
+ SetUnitExploded(self.handle, true)
821
876
  killUnit(self.handle)
822
877
  end
823
878
  function Unit.prototype.kill(self)
824
879
  killUnit(self.handle)
825
880
  end
826
881
  function Unit.prototype.revive(self, x, y, doEffect)
827
- local ____ReviveHero_5 = ReviveHero
828
- local ____array_4 = __TS__SparseArrayNew(self.handle, x, y)
829
- local ____doEffect_3 = doEffect
830
- if ____doEffect_3 == nil then
831
- ____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
832
887
  end
833
- __TS__SparseArrayPush(____array_4, ____doEffect_3)
834
- ____ReviveHero_5(__TS__SparseArraySpread(____array_4))
888
+ __TS__SparseArrayPush(____array_5, ____doEffect_4)
889
+ ____ReviveHero_6(__TS__SparseArraySpread(____array_5))
835
890
  end
836
891
  function Unit.prototype.healTarget(self, target, amount)
837
892
  if __TS__InstanceOf(target, ____exports.Unit) and target:hasAbility(fourCC("BIhm")) then
@@ -874,17 +929,16 @@ function Unit.prototype.itemInSlot(self, slot)
874
929
  return Item:of(unitItemInSlot(self.handle, slot))
875
930
  end
876
931
  function Unit.prototype.addAbility(self, abilityId)
877
- if unitAddAbility(self.handle, abilityId) then
878
- local ability = UnitAbility:of(
879
- checkNotNull(getUnitAbility(self.handle, abilityId)),
880
- abilityId,
881
- self
882
- )
932
+ local ability = UnitAbility:of(
933
+ doUnitAbilityAction(self.handle, abilityId, addAbility, abilityId),
934
+ abilityId,
935
+ self
936
+ )
937
+ if ability ~= nil then
883
938
  local abilities = self.abilities
884
939
  abilities[#abilities + 1] = ability
885
- return ability
886
940
  end
887
- return nil
941
+ return ability
888
942
  end
889
943
  function Unit.prototype.makeAbilityPermanent(self, abilityId, permanent)
890
944
  return UnitMakeAbilityPermanent(self.handle, permanent, abilityId)
@@ -898,31 +952,21 @@ end
898
952
  function Unit.prototype.hasAbility(self, abilityId)
899
953
  return getUnitAbilityLevel(self.handle, abilityId) > 0
900
954
  end
901
- function Unit.prototype.getAbilityById(self, abilityId)
902
- local handle = self.handle
903
- if unitAddAbility(handle, abilityId) then
904
- assert(unitRemoveAbility(handle, abilityId))
905
- return nil
906
- end
907
- return UnitAbility:of(
908
- getUnitAbility(self.handle, abilityId),
909
- abilityId,
910
- self
911
- )
955
+ function Unit.prototype.getAbility(self, abilityId)
956
+ local ability = doUnitAbilityAction(self.handle, abilityId, getUnitAbility, abilityId)
957
+ return UnitAbility:of(ability, abilityId, self)
912
958
  end
913
- function Unit.prototype.removeAbility(self, abilityId)
914
- if unitRemoveAbility(self.handle, abilityId) then
915
- local abilities = self.abilities
916
- for i = 1, #abilities do
917
- if abilities[i].typeId == abilityId then
918
- abilities[i]:destroy()
919
- tremove(abilities, i)
920
- return true
921
- 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
922
967
  end
923
- return true
924
968
  end
925
- return false
969
+ return doUnitAbilityAction(self.handle, abilityTypeId, unitRemoveAbility, abilityTypeId)
926
970
  end
927
971
  function Unit.prototype.hideAbility(self, abilityId, flag)
928
972
  BlzUnitHideAbility(self.handle, abilityId, flag)
@@ -936,12 +980,34 @@ end
936
980
  function Unit.prototype.endAbilityCooldown(self, abilityId)
937
981
  BlzEndUnitAbilityCooldown(self.handle, abilityId)
938
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
939
998
  function Unit.prototype.interruptAttack(self)
940
999
  unitInterruptAttack(self.handle)
941
1000
  end
942
1001
  function Unit.prototype.interruptCast(self, abilityId)
943
- unitDisableAbility(self.handle, abilityId, true, false)
944
- unitDisableAbility(self.handle, abilityId, false, false)
1002
+ local handle = self.handle
1003
+ unitDisableAbility(handle, abilityId, true, false)
1004
+ Timer:run(
1005
+ unitDisableAbility,
1006
+ handle,
1007
+ abilityId,
1008
+ false,
1009
+ false
1010
+ )
945
1011
  end
946
1012
  function Unit.prototype.getDistanceTo(self, target)
947
1013
  local handle = self.handle
@@ -1002,18 +1068,44 @@ function Unit.prototype.unpauseEx(self)
1002
1068
  end
1003
1069
  function Unit.prototype.incrementStunCounter(self)
1004
1070
  local stunCounter = self[102] or 0
1005
- if not self[101] or stunCounter >= 0 then
1071
+ if not self[101] and (self[103] or 0) <= 0 or stunCounter >= 0 then
1006
1072
  BlzPauseUnitEx(self.handle, true)
1007
1073
  end
1008
1074
  self[102] = stunCounter + 1
1009
1075
  end
1010
1076
  function Unit.prototype.decrementStunCounter(self)
1011
1077
  local stunCounter = self[102] or 0
1012
- if not self[101] or stunCounter >= 1 then
1078
+ if not self[101] and (self[103] or 0) <= 0 or stunCounter >= 1 then
1013
1079
  BlzPauseUnitEx(self.handle, false)
1014
1080
  end
1015
1081
  self[102] = stunCounter - 1
1016
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
1017
1109
  function Unit.create(self, owner, id, x, y, facing, skinId)
1018
1110
  local handle = skinId and BlzCreateUnitWithSkin(
1019
1111
  owner.handle,
@@ -1202,7 +1294,15 @@ __TS__SetDescriptor(
1202
1294
  Unit.prototype,
1203
1295
  "isIllusion",
1204
1296
  {get = function(self)
1205
- 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")
1206
1306
  end},
1207
1307
  true
1208
1308
  )
@@ -1279,6 +1379,19 @@ __TS__SetDescriptor(
1279
1379
  },
1280
1380
  true
1281
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
+ )
1282
1395
  __TS__SetDescriptor(
1283
1396
  Unit.prototype,
1284
1397
  "strengthBase",
@@ -1400,17 +1513,17 @@ __TS__SetDescriptor(
1400
1513
  "isTeamGlowVisible",
1401
1514
  {
1402
1515
  get = function(self)
1403
- return not self[106]
1516
+ return not self[107]
1404
1517
  end,
1405
1518
  set = function(self, isTeamGlowVisible)
1406
- showUnitTeamGlow(self.handle, isTeamGlowVisible)
1407
- local ____temp_6
1519
+ BlzShowUnitTeamGlow(self.handle, isTeamGlowVisible)
1520
+ local ____temp_7
1408
1521
  if not isTeamGlowVisible then
1409
- ____temp_6 = true
1522
+ ____temp_7 = true
1410
1523
  else
1411
- ____temp_6 = nil
1524
+ ____temp_7 = nil
1412
1525
  end
1413
- self[106] = ____temp_6
1526
+ self[107] = ____temp_7
1414
1527
  end
1415
1528
  },
1416
1529
  true
@@ -1419,9 +1532,9 @@ __TS__SetDescriptor(
1419
1532
  Unit.prototype,
1420
1533
  "color",
1421
1534
  {set = function(self, color)
1422
- setUnitColor(self.handle, color.handle)
1423
- if self[106] then
1424
- showUnitTeamGlow(self.handle, false)
1535
+ SetUnitColor(self.handle, color.handle)
1536
+ if self[107] then
1537
+ BlzShowUnitTeamGlow(self.handle, false)
1425
1538
  end
1426
1539
  end},
1427
1540
  true
@@ -1444,14 +1557,14 @@ __TS__SetDescriptor(
1444
1557
  "maxHealth",
1445
1558
  {
1446
1559
  get = function(self)
1447
- 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)
1448
1561
  end,
1449
1562
  set = function(self, maxHealth)
1450
- if maxHealth < 1 and self[103] ~= nil then
1451
- 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)
1452
1565
  maxHealth = 1
1453
1566
  end
1454
- BlzSetUnitMaxHP(self.handle, maxHealth + (self[105] or 0))
1567
+ BlzSetUnitMaxHP(self.handle, maxHealth + (self[106] or 0))
1455
1568
  end
1456
1569
  },
1457
1570
  true
@@ -1493,10 +1606,10 @@ __TS__SetDescriptor(
1493
1606
  "health",
1494
1607
  {
1495
1608
  get = function(self)
1496
- return GetWidgetLife(self.handle) - (self[105] or 0)
1609
+ return GetWidgetLife(self.handle) - (self[106] or 0)
1497
1610
  end,
1498
1611
  set = function(self, health)
1499
- SetWidgetLife(self.handle, health + (self[105] or 0))
1612
+ SetWidgetLife(self.handle, health + (self[106] or 0))
1500
1613
  end
1501
1614
  },
1502
1615
  true
@@ -1572,25 +1685,12 @@ __TS__SetDescriptor(
1572
1685
  },
1573
1686
  true
1574
1687
  )
1575
- __TS__SetDescriptor(
1576
- Unit.prototype,
1577
- "flyHeight",
1578
- {
1579
- get = function(self)
1580
- return getUnitFlyHeight(self.handle)
1581
- end,
1582
- set = function(self, v)
1583
- SetUnitFlyHeight(self.handle, v, 100000)
1584
- end
1585
- },
1586
- true
1587
- )
1588
1688
  __TS__SetDescriptor(
1589
1689
  Unit.prototype,
1590
1690
  "x",
1591
1691
  {
1592
1692
  get = function(self)
1593
- return getUnitX(self.handle)
1693
+ return self[108] or getUnitX(self.handle)
1594
1694
  end,
1595
1695
  set = function(self, v)
1596
1696
  SetUnitX(self.handle, v)
@@ -1603,7 +1703,7 @@ __TS__SetDescriptor(
1603
1703
  "y",
1604
1704
  {
1605
1705
  get = function(self)
1606
- return getUnitY(self.handle)
1706
+ return self[109] or getUnitY(self.handle)
1607
1707
  end,
1608
1708
  set = function(self, v)
1609
1709
  SetUnitY(self.handle, v)
@@ -1689,10 +1789,10 @@ __TS__SetDescriptor(
1689
1789
  "gold",
1690
1790
  {
1691
1791
  get = function(self)
1692
- return getResourceAmount(self.handle)
1792
+ return GetResourceAmount(self.handle)
1693
1793
  end,
1694
1794
  set = function(self, gold)
1695
- setResourceAmount(self.handle, gold)
1795
+ SetResourceAmount(self.handle, gold)
1696
1796
  end
1697
1797
  },
1698
1798
  true
@@ -1708,14 +1808,18 @@ __TS__SetDescriptor(
1708
1808
  local handle = self.handle
1709
1809
  if isPaused and not IsUnitPaused(handle) then
1710
1810
  self[101] = true
1711
- for _ = self[102] or 0, -1 do
1712
- 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
1713
1815
  end
1714
1816
  PauseUnit(handle, true)
1715
1817
  elseif not isPaused and IsUnitPaused(handle) then
1716
1818
  PauseUnit(handle, false)
1717
- for _ = self[102] or 0, -1 do
1718
- 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
1719
1823
  end
1720
1824
  self[101] = nil
1721
1825
  end
@@ -1820,6 +1924,19 @@ __TS__SetDescriptor(
1820
1924
  end},
1821
1925
  true
1822
1926
  )
1927
+ __TS__SetDescriptor(
1928
+ Unit.prototype,
1929
+ "movementType",
1930
+ {
1931
+ get = function(self)
1932
+ return getUnitIntegerField(self.handle, UNIT_IF_MOVE_TYPE)
1933
+ end,
1934
+ set = function(self, movementType)
1935
+ setUnitIntegerField(self.handle, UNIT_IF_MOVE_TYPE, movementType)
1936
+ end
1937
+ },
1938
+ true
1939
+ )
1823
1940
  __TS__SetDescriptor(
1824
1941
  Unit.prototype,
1825
1942
  "pathing",
@@ -2001,6 +2118,14 @@ __TS__SetDescriptor(
2001
2118
  end},
2002
2119
  true
2003
2120
  )
2121
+ __TS__SetDescriptor(
2122
+ Unit.prototype,
2123
+ "targetAcquiredEvent",
2124
+ {get = function(self)
2125
+ return self:getEvent(EVENT_UNIT_ACQUIRED_TARGET)
2126
+ end},
2127
+ true
2128
+ )
2004
2129
  __TS__SetDescriptor(
2005
2130
  Unit.prototype,
2006
2131
  "onSelect",
@@ -2136,25 +2261,25 @@ Unit.onTargetCast = dispatchId(__TS__New(
2136
2261
  InitializingEvent,
2137
2262
  function(event)
2138
2263
  local function listener(unit, id)
2139
- local ____GetSpellTargetUnit_result_9
2264
+ local ____GetSpellTargetUnit_result_10
2140
2265
  if GetSpellTargetUnit() then
2141
- ____GetSpellTargetUnit_result_9 = ____exports.Unit:of(GetSpellTargetUnit())
2266
+ ____GetSpellTargetUnit_result_10 = ____exports.Unit:of(GetSpellTargetUnit())
2142
2267
  else
2143
- local ____GetSpellTargetItem_result_8
2268
+ local ____GetSpellTargetItem_result_9
2144
2269
  if GetSpellTargetItem() then
2145
- ____GetSpellTargetItem_result_8 = Item:of(GetSpellTargetItem())
2270
+ ____GetSpellTargetItem_result_9 = Item:of(GetSpellTargetItem())
2146
2271
  else
2147
- local ____GetSpellTargetDestructable_result_7
2272
+ local ____GetSpellTargetDestructable_result_8
2148
2273
  if GetSpellTargetDestructable() then
2149
- ____GetSpellTargetDestructable_result_7 = Destructable:of(GetSpellTargetDestructable())
2274
+ ____GetSpellTargetDestructable_result_8 = Destructable:of(GetSpellTargetDestructable())
2150
2275
  else
2151
- ____GetSpellTargetDestructable_result_7 = nil
2276
+ ____GetSpellTargetDestructable_result_8 = nil
2152
2277
  end
2153
- ____GetSpellTargetItem_result_8 = ____GetSpellTargetDestructable_result_7
2278
+ ____GetSpellTargetItem_result_9 = ____GetSpellTargetDestructable_result_8
2154
2279
  end
2155
- ____GetSpellTargetUnit_result_9 = ____GetSpellTargetItem_result_8
2280
+ ____GetSpellTargetUnit_result_10 = ____GetSpellTargetItem_result_9
2156
2281
  end
2157
- local target = ____GetSpellTargetUnit_result_9
2282
+ local target = ____GetSpellTargetUnit_result_10
2158
2283
  if target then
2159
2284
  invoke(event, unit, id, target)
2160
2285
  end
@@ -2326,10 +2451,12 @@ Unit.onImmediateOrder = dispatchId(__TS__New(
2326
2451
  ____exports.UnitTriggerEvent,
2327
2452
  EVENT_PLAYER_UNIT_ISSUED_ORDER,
2328
2453
  function()
2329
- local unit = ____exports.Unit:of(getOrderedUnit())
2330
- local issuedOrderId = getIssuedOrderId()
2331
- if unit ~= nil and unit.state == 1 then
2332
- return unit, issuedOrderId
2454
+ local handle = getOrderedUnit()
2455
+ if handle ~= nil and getUnitTypeId(handle) ~= dummyUnitId then
2456
+ local unit = ____exports.Unit:of(handle)
2457
+ if unit.state == 1 then
2458
+ return unit, getIssuedOrderId()
2459
+ end
2333
2460
  end
2334
2461
  return IgnoreEvent
2335
2462
  end
@@ -2360,38 +2487,57 @@ Unit.onDamaging = (function()
2360
2487
  if source and source.typeId == dummyUnitId then
2361
2488
  source = nil
2362
2489
  end
2363
- local target = BlzGetEventDamageTarget()
2490
+ local target = ____exports.Unit:of(BlzGetEventDamageTarget())
2491
+ local metadata = damageMetadataByTarget[target]
2492
+ damageMetadataByTarget[target] = nil
2364
2493
  local data = {
2365
2494
  amount = GetEventDamage(),
2366
- attackType = BlzGetEventAttackType(),
2495
+ attackType = nativeToAttackType(BlzGetEventAttackType()),
2367
2496
  damageType = BlzGetEventDamageType(),
2368
2497
  weaponType = BlzGetEventWeaponType(),
2369
- isAttack = BlzGetEventIsAttack()
2498
+ metadata = metadata,
2499
+ isAttack = BlzGetEventIsAttack(),
2500
+ originalAmount = GetEventDamage(),
2501
+ originalMetadata = metadata,
2502
+ preventRetaliation = damagingEventPreventRetaliation
2370
2503
  }
2371
2504
  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])
2505
+ data.weapon = source:chooseWeapon(target)
2378
2506
  end
2379
2507
  if not data.isAttack or not source or not source._attackHandlers then
2380
2508
  invoke(
2381
2509
  event,
2382
2510
  source,
2383
- ____exports.Unit:of(target),
2511
+ target,
2384
2512
  setmetatable(
2385
2513
  {},
2386
2514
  {
2387
2515
  __index = data,
2388
2516
  __newindex = function(self, key, value)
2389
- damageSetters[key](value)
2517
+ local damageSetter = damageSetters[key]
2518
+ if damageSetter ~= nil then
2519
+ damageSetter(value)
2520
+ end
2390
2521
  data[key] = value
2391
2522
  end
2392
2523
  }
2393
2524
  )
2394
2525
  )
2526
+ if data[0] and source then
2527
+ local sourceOwner = source.owner.handle
2528
+ data[1] = sourceOwner
2529
+ local targetOwner = target.owner.handle
2530
+ data[2] = targetOwner
2531
+ if not GetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE) then
2532
+ SetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE, true)
2533
+ data[3] = true
2534
+ end
2535
+ if not GetPlayerAlliance(targetOwner, sourceOwner, ALLIANCE_PASSIVE) then
2536
+ SetPlayerAlliance(targetOwner, sourceOwner, ALLIANCE_PASSIVE, true)
2537
+ data[4] = true
2538
+ end
2539
+ end
2540
+ damagingEventByTarget[target] = data
2395
2541
  return
2396
2542
  end
2397
2543
  BlzSetEventDamage(0)
@@ -2399,7 +2545,7 @@ Unit.onDamaging = (function()
2399
2545
  BlzSetEventDamageType(DAMAGE_TYPE_UNKNOWN)
2400
2546
  BlzSetEventWeaponType(WEAPON_TYPE_WHOKNOWS)
2401
2547
  local sourceOwner = source.owner.handle
2402
- local targetOwner = GetOwningPlayer(target)
2548
+ local targetOwner = target.owner.handle
2403
2549
  if not GetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE) then
2404
2550
  SetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE, true)
2405
2551
  Timer:run(function()
@@ -2415,23 +2561,19 @@ Unit.onDamaging = (function()
2415
2561
  for ____, ____value in ipairs(source._attackHandlers) do
2416
2562
  local condition = ____value[1]
2417
2563
  local action = ____value[2]
2418
- if condition(
2419
- source,
2420
- ____exports.Unit:of(target),
2421
- data
2422
- ) then
2564
+ if condition(source, target, data) then
2423
2565
  action(
2424
2566
  source,
2425
- ____exports.Unit:of(target),
2567
+ target,
2426
2568
  setmetatable(
2427
2569
  {fire = function()
2428
2570
  UnitDamageTarget(
2429
2571
  source.handle,
2430
- target,
2572
+ target.handle,
2431
2573
  data.amount,
2432
2574
  true,
2433
2575
  true,
2434
- data.attackType,
2576
+ attackTypeToNative(data.attackType),
2435
2577
  data.damageType,
2436
2578
  data.weaponType
2437
2579
  )
@@ -2458,30 +2600,54 @@ Unit.onDamage = __TS__New(
2458
2600
  if source and source.typeId == dummyUnitId then
2459
2601
  source = nil
2460
2602
  end
2603
+ local target = ____exports.Unit:of(BlzGetEventDamageTarget())
2604
+ local damagingEvent = damagingEventByTarget[target]
2605
+ damagingEventByTarget[target] = nil
2461
2606
  local data = {
2462
2607
  amount = GetEventDamage(),
2463
- attackType = BlzGetEventAttackType(),
2608
+ attackType = nativeToAttackType(BlzGetEventAttackType()),
2464
2609
  damageType = BlzGetEventDamageType(),
2465
2610
  weaponType = BlzGetEventWeaponType(),
2611
+ metadata = damagingEvent and damagingEvent.metadata,
2466
2612
  isAttack = BlzGetEventIsAttack(),
2467
- originalAmount = GetEventDamage(),
2613
+ originalAmount = damagingEvent and damagingEvent.originalAmount or GetEventDamage(),
2614
+ originalMetadata = damagingEvent and damagingEvent.originalMetadata,
2468
2615
  preventDeath = damageEventPreventDeath
2469
2616
  }
2617
+ if damagingEvent then
2618
+ for key, value in pairs(damagingEvent) do
2619
+ if isAttribute(key) then
2620
+ data[key] = value
2621
+ end
2622
+ end
2623
+ local sourceOwner = damagingEvent[1]
2624
+ if sourceOwner then
2625
+ local targetOwner = damagingEvent[2]
2626
+ if damagingEvent[3] then
2627
+ SetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE, false)
2628
+ end
2629
+ if damagingEvent[4] then
2630
+ SetPlayerAlliance(targetOwner, sourceOwner, ALLIANCE_PASSIVE, false)
2631
+ end
2632
+ end
2633
+ end
2470
2634
  local evData = setmetatable(
2471
2635
  {},
2472
2636
  {
2473
2637
  __index = data,
2474
2638
  __newindex = function(self, key, value)
2475
- damageSetters[key](value)
2639
+ local damageSetter = damageSetters[key]
2640
+ if damageSetter ~= nil then
2641
+ damageSetter(value)
2642
+ end
2476
2643
  data[key] = value
2477
2644
  end
2478
2645
  }
2479
2646
  )
2480
- local target = ____exports.Unit:of(BlzGetEventDamageTarget())
2481
2647
  invoke(event, source, target, evData)
2482
2648
  if evData[0] ~= nil and target.health - evData.amount < 0.405 then
2483
2649
  local bonusHealth = math.ceil(evData.amount)
2484
- target[105] = (target[105] or 0) + bonusHealth
2650
+ target[106] = (target[106] or 0) + bonusHealth
2485
2651
  BlzSetUnitMaxHP(
2486
2652
  target.handle,
2487
2653
  BlzGetUnitMaxHP(target.handle) + bonusHealth
@@ -2495,7 +2661,7 @@ Unit.onDamage = __TS__New(
2495
2661
  evData[0],
2496
2662
  table.unpack(evData, 1 + 1, 1 + (evData[1] or 0))
2497
2663
  )
2498
- target[105] = (target[105] or 0) - bonusHealth
2664
+ target[106] = (target[106] or 0) - bonusHealth
2499
2665
  SetWidgetLife(
2500
2666
  target.handle,
2501
2667
  GetWidgetLife(target.handle) - bonusHealth
@@ -2520,8 +2686,9 @@ Unit.itemDroppedEvent = __TS__New(
2520
2686
  EVENT_PLAYER_UNIT_DROP_ITEM,
2521
2687
  function()
2522
2688
  local unit = getTriggerUnit()
2523
- if getUnitTypeId(unit) ~= dummyUnitId then
2524
- return ____exports.Unit:of(unit), Item:of(getManipulatedItem())
2689
+ local item = getManipulatedItem()
2690
+ if getUnitTypeId(unit) ~= dummyUnitId and not (ignoreEventsItems[item] ~= nil) then
2691
+ return ____exports.Unit:of(unit), Item:of(item)
2525
2692
  end
2526
2693
  return IgnoreEvent
2527
2694
  end
@@ -2530,9 +2697,14 @@ Unit.itemPickedUpEvent = __TS__New(
2530
2697
  ____exports.UnitTriggerEvent,
2531
2698
  EVENT_PLAYER_UNIT_PICKUP_ITEM,
2532
2699
  function()
2533
- local unit = getTriggerUnit()
2534
- if getUnitTypeId(unit) ~= dummyUnitId then
2535
- return ____exports.Unit:of(unit), Item:of(getManipulatedItem())
2700
+ local unitHandle = getTriggerUnit()
2701
+ local itemHandle = getManipulatedItem()
2702
+ if getUnitTypeId(unitHandle) ~= dummyUnitId and not (ignoreEventsItems[itemHandle] ~= nil) then
2703
+ local unit = ____exports.Unit:of(unitHandle)
2704
+ local item = Item:of(itemHandle)
2705
+ if item.owner ~= unit then
2706
+ return unit, item
2707
+ end
2536
2708
  end
2537
2709
  return IgnoreEvent
2538
2710
  end
@@ -2540,12 +2712,79 @@ Unit.itemPickedUpEvent = __TS__New(
2540
2712
  Unit.itemUsedEvent = __TS__New(
2541
2713
  ____exports.UnitTriggerEvent,
2542
2714
  EVENT_PLAYER_UNIT_USE_ITEM,
2543
- function() return ____exports.Unit:of(getTriggerUnit()), Item:of(getManipulatedItem()) end
2715
+ function()
2716
+ local unit = getTriggerUnit()
2717
+ local item = getManipulatedItem()
2718
+ if getUnitTypeId(unit) ~= dummyUnitId and not (ignoreEventsItems[item] ~= nil) then
2719
+ return ____exports.Unit:of(unit), Item:of(item)
2720
+ end
2721
+ return IgnoreEvent
2722
+ end
2544
2723
  )
2545
2724
  Unit.itemStackedEvent = __TS__New(
2546
2725
  ____exports.UnitTriggerEvent,
2547
2726
  EVENT_PLAYER_UNIT_STACK_ITEM,
2548
- function() return ____exports.Unit:of(getTriggerUnit()), Item:of(getManipulatedItem()) end
2727
+ function() return ____exports.Unit:of(getTriggerUnit()), Item:of(BlzGetStackingItemTarget()), Item:of(BlzGetStackingItemSource()) end
2728
+ )
2729
+ __TS__ObjectDefineProperty(
2730
+ Unit,
2731
+ "itemChargesChangedEvent",
2732
+ {get = function(self)
2733
+ local event = __TS__New(Event)
2734
+ Item.chargesChangedEvent:addListener(function(item)
2735
+ local unit = item.owner
2736
+ if unit ~= nil then
2737
+ invoke(event, unit, item)
2738
+ end
2739
+ end)
2740
+ rawset(self, "itemChargesChangedEvent", event)
2741
+ return event
2742
+ end}
2743
+ )
2744
+ __TS__ObjectDefineProperty(
2745
+ Unit,
2746
+ "itemUseOrderEvent",
2747
+ {get = function(self)
2748
+ local event = __TS__New(Event)
2749
+ for order = orderId("useslot0"), orderId("useslot5") do
2750
+ local slot = order - orderId("useslot0")
2751
+ local function listener(unit)
2752
+ local item = unit.items[slot + 1]
2753
+ if item ~= nil then
2754
+ invoke(event, unit, item)
2755
+ end
2756
+ end
2757
+ self.onImmediateOrder[order]:addListener(listener)
2758
+ self.onTargetOrder[order]:addListener(listener)
2759
+ self.onPointOrder[order]:addListener(listener)
2760
+ end
2761
+ rawset(self, "itemUseOrderEvent", event)
2762
+ return event
2763
+ end}
2764
+ )
2765
+ __TS__ObjectDefineProperty(
2766
+ Unit,
2767
+ "itemMoveOrderEvent",
2768
+ {get = function(self)
2769
+ local event = __TS__New(Event)
2770
+ for order = orderId("moveslot0"), orderId("moveslot5") do
2771
+ local slotTo = order - orderId("moveslot0")
2772
+ self.onTargetOrder[order]:addListener(function(unit, item)
2773
+ local slotFrom = unit.items:findSlot(item)
2774
+ if slotFrom ~= nil then
2775
+ invoke(
2776
+ event,
2777
+ unit,
2778
+ item,
2779
+ slotFrom,
2780
+ slotTo
2781
+ )
2782
+ end
2783
+ end)
2784
+ end
2785
+ rawset(self, "itemMoveOrderEvent", event)
2786
+ return event
2787
+ end}
2549
2788
  )
2550
2789
  __TS__ObjectDefineProperty(
2551
2790
  Unit,
@@ -2572,6 +2811,10 @@ __TS__ObjectDefineProperty(
2572
2811
  rawset(self, "destroyEvent", destroyEvent)
2573
2812
  return destroyEvent
2574
2813
  end}
2814
+ )
2815
+ Unit.synchronize = synchronizer(
2816
+ function(unit) return unit.syncId end,
2817
+ function(syncId) return unitBySyncId[syncId] end
2575
2818
  );
2576
2819
  (function(self)
2577
2820
  local leaveAbilityIds = postcompile(function()