warscript 0.0.1-dev.63f1d69 → 0.0.1-dev.64a596c

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 (226) hide show
  1. package/attributes.d.ts +6 -0
  2. package/attributes.lua +17 -1
  3. package/binaryreader.d.ts +1 -0
  4. package/binaryreader.lua +3 -0
  5. package/config.d.ts +5 -0
  6. package/config.lua +10 -0
  7. package/core/types/effect.d.ts +14 -6
  8. package/core/types/effect.lua +131 -35
  9. package/core/types/frame.d.ts +8 -0
  10. package/core/types/frame.lua +117 -22
  11. package/core/types/player.d.ts +16 -0
  12. package/core/types/player.lua +60 -15
  13. package/core/types/playerCamera.d.ts +2 -0
  14. package/core/types/playerCamera.lua +123 -5
  15. package/core/types/sound.d.ts +17 -24
  16. package/core/types/sound.lua +99 -24
  17. package/core/types/tileCell.d.ts +11 -1
  18. package/core/types/tileCell.lua +97 -0
  19. package/core/types/timer.d.ts +9 -8
  20. package/core/types/timer.lua +45 -23
  21. package/core/util.d.ts +1 -1
  22. package/core/util.lua +18 -1
  23. package/decl/native.d.ts +846 -790
  24. package/engine/behavior.d.ts +14 -3
  25. package/engine/behavior.lua +175 -73
  26. package/engine/behaviour/ability/always-enabled.d.ts +7 -0
  27. package/engine/behaviour/ability/always-enabled.lua +31 -0
  28. package/engine/behaviour/ability/apply-buff.d.ts +8 -5
  29. package/engine/behaviour/ability/apply-buff.lua +32 -0
  30. package/engine/behaviour/ability/apply-unit-behavior.lua +1 -0
  31. package/engine/behaviour/ability/damage.d.ts +39 -11
  32. package/engine/behaviour/ability/damage.lua +83 -37
  33. package/engine/behaviour/ability/emulate-impact.d.ts +6 -0
  34. package/engine/behaviour/ability/emulate-impact.lua +43 -0
  35. package/engine/behaviour/ability/heal.d.ts +33 -6
  36. package/engine/behaviour/ability/heal.lua +89 -10
  37. package/engine/behaviour/ability/instant-impact.d.ts +2 -2
  38. package/engine/behaviour/ability/instant-impact.lua +4 -19
  39. package/engine/behaviour/ability/on-command-impact.d.ts +8 -0
  40. package/engine/behaviour/ability/on-command-impact.lua +25 -0
  41. package/engine/behaviour/ability/remove-buffs.d.ts +25 -0
  42. package/engine/behaviour/ability/remove-buffs.lua +49 -0
  43. package/engine/behaviour/ability/restore-mana.d.ts +15 -0
  44. package/engine/behaviour/ability/restore-mana.lua +29 -0
  45. package/engine/behaviour/ability.d.ts +20 -4
  46. package/engine/behaviour/ability.lua +111 -47
  47. package/engine/behaviour/unit/stun-immunity.d.ts +11 -5
  48. package/engine/behaviour/unit/stun-immunity.lua +53 -28
  49. package/engine/behaviour/unit.d.ts +45 -2
  50. package/engine/behaviour/unit.lua +279 -6
  51. package/engine/buff.d.ts +111 -42
  52. package/engine/buff.lua +504 -208
  53. package/engine/game-map.d.ts +7 -0
  54. package/engine/game-map.lua +32 -0
  55. package/engine/internal/ability.d.ts +23 -14
  56. package/engine/internal/ability.lua +129 -85
  57. package/engine/internal/item/ability.lua +162 -4
  58. package/engine/internal/item+owner.lua +12 -6
  59. package/engine/internal/item.d.ts +20 -19
  60. package/engine/internal/item.lua +191 -74
  61. package/engine/internal/mechanics/ability-duration.lua +1 -1
  62. package/engine/internal/misc/ability-disable-counter.d.ts +2 -0
  63. package/engine/internal/misc/ability-disable-counter.lua +13 -0
  64. package/engine/internal/misc/damage-metadata-by-target.d.ts +2 -0
  65. package/engine/internal/misc/damage-metadata-by-target.lua +5 -0
  66. package/engine/internal/misc/frame-coordinates.d.ts +2 -0
  67. package/engine/internal/misc/frame-coordinates.lua +21 -0
  68. package/engine/internal/misc/get-terrain-z.d.ts +2 -0
  69. package/engine/internal/misc/get-terrain-z.lua +11 -0
  70. package/engine/internal/misc/player-local-handle.d.ts +2 -0
  71. package/engine/internal/misc/player-local-handle.lua +5 -0
  72. package/engine/internal/object-data/auto-attack-speed-increase.d.ts +1 -1
  73. package/engine/internal/object-data/auto-attack-speed-increase.lua +2 -0
  74. package/engine/internal/object-data/evasion-probability.d.ts +2 -0
  75. package/engine/internal/object-data/evasion-probability.lua +16 -0
  76. package/engine/internal/unit/ability.d.ts +45 -1
  77. package/engine/internal/unit/ability.lua +128 -17
  78. package/engine/internal/unit/add-item-to-slot-init.d.ts +2 -0
  79. package/engine/internal/unit/add-item-to-slot-init.lua +23 -0
  80. package/engine/internal/unit/add-item-to-slot.d.ts +2 -0
  81. package/engine/internal/unit/add-item-to-slot.lua +52 -0
  82. package/engine/internal/unit/allowed-targets.d.ts +1 -1
  83. package/engine/internal/unit/allowed-targets.lua +9 -1
  84. package/engine/internal/unit/bonus.d.ts +6 -2
  85. package/engine/internal/unit/bonus.lua +23 -1
  86. package/engine/internal/unit/fly-height.d.ts +7 -0
  87. package/engine/internal/unit/fly-height.lua +20 -0
  88. package/engine/internal/unit/ignore-events-items.d.ts +2 -0
  89. package/engine/internal/unit/ignore-events-items.lua +5 -0
  90. package/engine/internal/unit/item.d.ts +24 -0
  91. package/engine/internal/unit/item.lua +78 -0
  92. package/engine/internal/unit/main-selected.d.ts +13 -0
  93. package/engine/internal/unit/main-selected.lua +36 -0
  94. package/engine/internal/unit/order.d.ts +20 -0
  95. package/engine/internal/unit/order.lua +136 -0
  96. package/engine/internal/unit/scale.d.ts +7 -0
  97. package/engine/internal/unit/scale.lua +20 -0
  98. package/engine/internal/unit+ability.lua +12 -3
  99. package/engine/internal/unit+damage.d.ts +2 -11
  100. package/engine/internal/unit+damage.lua +10 -14
  101. package/engine/internal/unit+spellSteal.lua +1 -2
  102. package/engine/internal/unit+transport.lua +4 -10
  103. package/engine/internal/unit-missile-launch.lua +63 -13
  104. package/engine/internal/unit.d.ts +63 -22
  105. package/engine/internal/unit.lua +453 -206
  106. package/engine/internal/utility.lua +12 -0
  107. package/engine/lightning.d.ts +12 -5
  108. package/engine/lightning.lua +48 -14
  109. package/engine/local-client.d.ts +9 -2
  110. package/engine/local-client.lua +112 -0
  111. package/engine/object-data/auxiliary/animation-name.d.ts +1 -0
  112. package/engine/object-data/auxiliary/animation-name.lua +16 -0
  113. package/engine/object-data/auxiliary/armor-type.d.ts +11 -0
  114. package/engine/object-data/auxiliary/armor-type.lua +46 -0
  115. package/engine/object-data/auxiliary/attachment-preset.d.ts +7 -2
  116. package/engine/object-data/auxiliary/attachment-preset.lua +4 -3
  117. package/engine/object-data/auxiliary/attack-type.d.ts +7 -8
  118. package/engine/object-data/auxiliary/attack-type.lua +42 -0
  119. package/engine/object-data/auxiliary/movement-type.d.ts +7 -7
  120. package/engine/object-data/auxiliary/movement-type.lua +22 -0
  121. package/engine/object-data/auxiliary/sound-eax.d.ts +10 -0
  122. package/engine/object-data/auxiliary/sound-eax.lua +2 -0
  123. package/engine/object-data/auxiliary/sound-preset-name.d.ts +5 -1
  124. package/engine/object-data/auxiliary/tech-tree-dependency.d.ts +1 -1
  125. package/engine/object-data/auxiliary/unit-attribute.d.ts +6 -0
  126. package/engine/object-data/auxiliary/unit-attribute.lua +9 -0
  127. package/engine/object-data/entry/ability-type/berserk.d.ts +2 -0
  128. package/engine/object-data/entry/ability-type/berserk.lua +13 -0
  129. package/engine/object-data/entry/ability-type/blank-configurable.lua +12 -1
  130. package/engine/object-data/entry/ability-type/carrion-swarm.d.ts +14 -0
  131. package/engine/object-data/entry/ability-type/carrion-swarm.lua +65 -0
  132. package/engine/object-data/entry/ability-type/disease-cloud.lua +2 -2
  133. package/engine/object-data/entry/ability-type/engineering-upgrade.lua +2 -2
  134. package/engine/object-data/entry/ability-type/ensnare.d.ts +12 -0
  135. package/engine/object-data/entry/ability-type/ensnare.lua +52 -0
  136. package/engine/object-data/entry/ability-type/feral-spirit.lua +2 -2
  137. package/engine/object-data/entry/ability-type/permanent-invisibility.d.ts +8 -0
  138. package/engine/object-data/entry/ability-type/permanent-invisibility.lua +26 -0
  139. package/engine/object-data/entry/ability-type/phase-shift.d.ts +10 -0
  140. package/engine/object-data/entry/ability-type/phase-shift.lua +39 -0
  141. package/engine/object-data/entry/ability-type/phoenix-morph.lua +4 -4
  142. package/engine/object-data/entry/ability-type/raise-dead.d.ts +17 -0
  143. package/engine/object-data/entry/ability-type/raise-dead.lua +78 -0
  144. package/engine/object-data/entry/ability-type/shock-wave.d.ts +4 -0
  145. package/engine/object-data/entry/ability-type/shock-wave.lua +26 -0
  146. package/engine/object-data/entry/ability-type/slow-poison.d.ts +10 -0
  147. package/engine/object-data/entry/ability-type/slow-poison.lua +58 -0
  148. package/engine/object-data/entry/ability-type/summon-quilbeast.lua +2 -2
  149. package/engine/object-data/entry/ability-type/summon-water-elemental.lua +2 -2
  150. package/engine/object-data/entry/ability-type/web.d.ts +12 -0
  151. package/engine/object-data/entry/ability-type/web.lua +52 -0
  152. package/engine/object-data/entry/ability-type.d.ts +19 -17
  153. package/engine/object-data/entry/ability-type.lua +93 -36
  154. package/engine/object-data/entry/buff-type/applicable.lua +18 -37
  155. package/engine/object-data/entry/buff-type.d.ts +6 -12
  156. package/engine/object-data/entry/buff-type.lua +13 -29
  157. package/engine/object-data/entry/destructible-type.d.ts +1 -1
  158. package/engine/object-data/entry/item-type.d.ts +15 -1
  159. package/engine/object-data/entry/item-type.lua +93 -2
  160. package/engine/object-data/entry/lightning-type.d.ts +1 -1
  161. package/engine/object-data/entry/sound-preset.d.ts +33 -0
  162. package/engine/object-data/entry/sound-preset.lua +140 -0
  163. package/engine/object-data/entry/unit-type.d.ts +25 -5
  164. package/engine/object-data/entry/unit-type.lua +258 -93
  165. package/engine/object-data/entry/upgrade.d.ts +1 -1
  166. package/engine/object-data/entry/upgrade.lua +4 -4
  167. package/engine/object-data/entry.d.ts +16 -14
  168. package/engine/object-data/entry.lua +60 -32
  169. package/engine/object-data/utility/object-data-entry-id-generator.lua +7 -0
  170. package/engine/object-field/ability.d.ts +28 -5
  171. package/engine/object-field/ability.lua +59 -5
  172. package/engine/object-field/unit.d.ts +69 -3
  173. package/engine/object-field/unit.lua +264 -7
  174. package/engine/object-field.d.ts +23 -6
  175. package/engine/object-field.lua +311 -124
  176. package/engine/random.d.ts +9 -0
  177. package/engine/random.lua +13 -0
  178. package/engine/standard/entries/buff-type.d.ts +3 -0
  179. package/engine/standard/entries/buff-type.lua +3 -0
  180. package/engine/standard/entries/sound-preset.d.ts +10 -0
  181. package/engine/standard/entries/sound-preset.lua +10 -0
  182. package/engine/standard/fields/ability.d.ts +4 -2
  183. package/engine/standard/fields/ability.lua +4 -2
  184. package/engine/standard/fields/unit.d.ts +6 -0
  185. package/engine/standard/fields/unit.lua +11 -0
  186. package/engine/synchronization.d.ts +11 -0
  187. package/engine/synchronization.lua +77 -0
  188. package/engine/text-tag.d.ts +36 -2
  189. package/engine/text-tag.lua +250 -10
  190. package/engine/unit.d.ts +6 -0
  191. package/engine/unit.lua +6 -0
  192. package/index.d.ts +1 -0
  193. package/index.lua +1 -0
  194. package/lualib_bundle.lua +7 -2
  195. package/net/socket.d.ts +7 -1
  196. package/net/socket.lua +45 -4
  197. package/network.d.ts +1 -0
  198. package/network.lua +3 -2
  199. package/objutil/buff.lua +3 -4
  200. package/objutil/unit.lua +8 -0
  201. package/package.json +2 -2
  202. package/patch-lua.d.ts +0 -0
  203. package/patch-lua.lua +10 -0
  204. package/patch-lualib.lua +1 -1
  205. package/property.d.ts +55 -0
  206. package/property.lua +374 -0
  207. package/utility/arrays.d.ts +10 -1
  208. package/utility/arrays.lua +45 -3
  209. package/utility/callback-array.d.ts +17 -0
  210. package/utility/callback-array.lua +61 -0
  211. package/utility/functions.d.ts +8 -0
  212. package/utility/functions.lua +13 -0
  213. package/utility/lazy.d.ts +2 -0
  214. package/utility/lazy.lua +14 -0
  215. package/utility/linked-set.d.ts +13 -2
  216. package/utility/linked-set.lua +27 -3
  217. package/utility/lua-maps.d.ts +15 -2
  218. package/utility/lua-maps.lua +53 -2
  219. package/utility/lua-sets.d.ts +2 -0
  220. package/utility/lua-sets.lua +7 -0
  221. package/utility/reflection.lua +11 -7
  222. package/utility/types.d.ts +4 -0
  223. package/core/mapbounds.d.ts +0 -8
  224. package/core/mapbounds.lua +0 -12
  225. package/core/types/order.d.ts +0 -25
  226. 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
@@ -290,7 +294,6 @@ local function dispatch(event, idGetter, argsGetter)
290
294
  return event[id]
291
295
  end
292
296
  if not initialized then
293
- local invoke = Event.invoke
294
297
  event:addListener(function(...)
295
298
  local id = idGetter(...)
296
299
  local dispatched = rawget(self, id)
@@ -328,7 +331,6 @@ local function dispatchAbility(event)
328
331
  return event[id]
329
332
  end
330
333
  if not initialized then
331
- local invoke = Event.invoke
332
334
  event:addListener(function(unit, ability, ...)
333
335
  local dispatched = rawget(self, ability.typeId)
334
336
  if dispatched ~= nil then
@@ -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",
@@ -564,17 +602,6 @@ local function retrieveAbility(unit, ability, abilityId)
564
602
  ____exports.Unit:of(unit)
565
603
  )
566
604
  end
567
- if not unitAddAbility(unit, abilityId) then
568
- if getUnitAbility(unit, abilityId) == ability then
569
- return UnitAbility:of(
570
- ability,
571
- abilityId,
572
- ____exports.Unit:of(unit)
573
- )
574
- end
575
- else
576
- unitRemoveAbility(unit, abilityId)
577
- end
578
605
  for i = 0, unitInventorySize(unit) - 1 do
579
606
  local item = unitItemInSlot(unit, i)
580
607
  if getItemAbility(item, abilityId) == ability then
@@ -632,15 +659,15 @@ for ____, player in ipairs(Player.all) do
632
659
  dummies[player] = dummy
633
660
  end
634
661
  local function delayHealthChecksCallback(unit)
635
- local counter = (unit[102] or 0) - 1
662
+ local counter = (unit[104] or 0) - 1
636
663
  if counter ~= 0 then
637
- unit[102] = counter
664
+ unit[104] = counter
638
665
  return
639
666
  end
640
- unit[102] = nil
641
- local healthBonus = unit[103]
667
+ unit[104] = nil
668
+ local healthBonus = unit[105]
642
669
  if healthBonus ~= nil then
643
- unit[103] = nil
670
+ unit[105] = nil
644
671
  local handle = unit.handle
645
672
  BlzSetUnitMaxHP(
646
673
  handle,
@@ -648,12 +675,27 @@ local function delayHealthChecksCallback(unit)
648
675
  )
649
676
  end
650
677
  end
678
+ local nextSyncId = 1
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)
696
+ local ____nextSyncId_1 = nextSyncId
697
+ nextSyncId = ____nextSyncId_1 + 1
698
+ self.syncId = ____nextSyncId_1
657
699
  self._owner = Player:of(getOwningPlayer(handle))
658
700
  assert(unitAddAbility(handle, leaveDetectAbilityId) and UnitMakeAbilityPermanent(handle, true, leaveDetectAbilityId))
659
701
  assert(unitAddAbility(handle, morphDetectAbilityId))
@@ -666,6 +708,7 @@ function Unit.prototype.____constructor(self, handle)
666
708
  fourCC("Amrf")
667
709
  ))
668
710
  end
711
+ unitBySyncId[self.syncId] = self
669
712
  local ____ = self.abilities
670
713
  end
671
714
  function Unit.prototype.getEvent(self, event, collector)
@@ -684,6 +727,8 @@ function Unit.prototype.getEvent(self, event, collector)
684
727
  end
685
728
  function Unit.prototype.onDestroy(self)
686
729
  local handle = self.handle
730
+ self[108] = getUnitX(handle)
731
+ self[109] = getUnitY(handle)
687
732
  if not self._owner then
688
733
  self._owner = Player:of(getOwningPlayer(handle))
689
734
  end
@@ -706,7 +751,10 @@ function Unit.prototype.onDestroy(self)
706
751
  if eventsToDestroy ~= nil then
707
752
  forEach(eventsToDestroy, "destroy")
708
753
  end
709
- removeUnit(handle)
754
+ if getUnitAbilityLevel(handle, leaveDetectAbilityId) > 0 then
755
+ unitRemoveAbility(handle, leaveDetectAbilityId)
756
+ removeUnit(handle)
757
+ end
710
758
  return Handle.prototype.onDestroy(self)
711
759
  end
712
760
  function Unit.prototype.addAttackHandler(self, condition, action)
@@ -748,17 +796,17 @@ function Unit.prototype.addModifier(self, property, modifier)
748
796
  end}
749
797
  end
750
798
  function Unit.prototype.hasCombatClassification(self, combatClassification)
751
- local ____combatClassification_0 = combatClassification
752
- return getUnitIntegerField(self.handle, UNIT_IF_TARGETED_AS) & ____combatClassification_0 == ____combatClassification_0
799
+ local ____combatClassification_2 = combatClassification
800
+ return getUnitIntegerField(self.handle, UNIT_IF_TARGETED_AS) & ____combatClassification_2 == ____combatClassification_2
753
801
  end
754
802
  function Unit.prototype.addClassification(self, classification)
755
- return unitAddType(self.handle, classification)
803
+ return UnitAddType(self.handle, classification)
756
804
  end
757
805
  function Unit.prototype.removeClassification(self, classification)
758
- return unitRemoveType(self.handle, classification)
806
+ return UnitRemoveType(self.handle, classification)
759
807
  end
760
808
  function Unit.prototype.hasClassification(self, classification)
761
- return isUnitType(self.handle, classification)
809
+ return IsUnitType(self.handle, classification)
762
810
  end
763
811
  function Unit.prototype.isVisibleTo(self, player)
764
812
  return isUnitVisible(self.handle, player.handle)
@@ -767,13 +815,13 @@ function Unit.prototype.isInvisibleTo(self, player)
767
815
  return isUnitInvisible(self.handle, player.handle)
768
816
  end
769
817
  function Unit.prototype.isInRangeOf(self, x, y, range)
770
- local ____temp_1
818
+ local ____temp_3
771
819
  if type(x) == "number" then
772
- ____temp_1 = isUnitInRangeXY(self.handle, x, y, range)
820
+ ____temp_3 = isUnitInRangeXY(self.handle, x, y, range)
773
821
  else
774
- ____temp_1 = isUnitInRange(self.handle, x.handle, y)
822
+ ____temp_3 = isUnitInRange(self.handle, x.handle, y)
775
823
  end
776
- return ____temp_1
824
+ return ____temp_3
777
825
  end
778
826
  function Unit.prototype.isAllyOf(self, unit)
779
827
  return isUnitAlly(
@@ -791,16 +839,30 @@ function Unit.prototype.playAnimation(self, animation, rarity)
791
839
  if type(animation) == "number" then
792
840
  setUnitAnimationByIndex(self.handle, animation)
793
841
  elseif rarity then
794
- setUnitAnimationWithRarity(self.handle, animation, rarity)
842
+ SetUnitAnimationWithRarity(self.handle, animation, rarity)
795
843
  else
796
844
  setUnitAnimation(self.handle, animation)
797
845
  end
798
846
  end
847
+ function Unit.prototype.resetAnimation(self)
848
+ ResetUnitAnimation(self.handle)
849
+ end
799
850
  function Unit.prototype.queueAnimation(self, animation)
800
- 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
801
863
  end
802
864
  function Unit.prototype.delayHealthChecks(self)
803
- self[102] = (self[102] or 0) + 1
865
+ self[104] = (self[104] or 0) + 1
804
866
  Timer:run(delayHealthChecksCallback, self)
805
867
  end
806
868
  function Unit.prototype.setPosition(self, x, y)
@@ -810,21 +872,21 @@ function Unit.prototype.isSelected(self, player)
810
872
  return IsUnitSelected(self.handle, player.handle)
811
873
  end
812
874
  function Unit.prototype.explode(self)
813
- setUnitExploded(self.handle, true)
875
+ SetUnitExploded(self.handle, true)
814
876
  killUnit(self.handle)
815
877
  end
816
878
  function Unit.prototype.kill(self)
817
879
  killUnit(self.handle)
818
880
  end
819
881
  function Unit.prototype.revive(self, x, y, doEffect)
820
- local ____ReviveHero_4 = ReviveHero
821
- local ____array_3 = __TS__SparseArrayNew(self.handle, x, y)
822
- local ____doEffect_2 = doEffect
823
- if ____doEffect_2 == nil then
824
- ____doEffect_2 = 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
825
887
  end
826
- __TS__SparseArrayPush(____array_3, ____doEffect_2)
827
- ____ReviveHero_4(__TS__SparseArraySpread(____array_3))
888
+ __TS__SparseArrayPush(____array_5, ____doEffect_4)
889
+ ____ReviveHero_6(__TS__SparseArraySpread(____array_5))
828
890
  end
829
891
  function Unit.prototype.healTarget(self, target, amount)
830
892
  if __TS__InstanceOf(target, ____exports.Unit) and target:hasAbility(fourCC("BIhm")) then
@@ -864,20 +926,19 @@ function Unit.prototype.dropItemSlot(self, item, slot)
864
926
  return UnitDropItemSlot(self.handle, item.handle, slot)
865
927
  end
866
928
  function Unit.prototype.itemInSlot(self, slot)
867
- return Item:of(UnitItemInSlot(self.handle, slot))
929
+ return Item:of(unitItemInSlot(self.handle, slot))
868
930
  end
869
931
  function Unit.prototype.addAbility(self, abilityId)
870
- if unitAddAbility(self.handle, abilityId) then
871
- local ability = UnitAbility:of(
872
- checkNotNull(getUnitAbility(self.handle, abilityId)),
873
- abilityId,
874
- self
875
- )
932
+ local ability = UnitAbility:of(
933
+ doUnitAbilityAction(self.handle, abilityId, addAbility, abilityId),
934
+ abilityId,
935
+ self
936
+ )
937
+ if ability ~= nil then
876
938
  local abilities = self.abilities
877
939
  abilities[#abilities + 1] = ability
878
- return ability
879
940
  end
880
- return nil
941
+ return ability
881
942
  end
882
943
  function Unit.prototype.makeAbilityPermanent(self, abilityId, permanent)
883
944
  return UnitMakeAbilityPermanent(self.handle, permanent, abilityId)
@@ -891,31 +952,21 @@ end
891
952
  function Unit.prototype.hasAbility(self, abilityId)
892
953
  return getUnitAbilityLevel(self.handle, abilityId) > 0
893
954
  end
894
- function Unit.prototype.getAbilityById(self, abilityId)
895
- local handle = self.handle
896
- if unitAddAbility(handle, abilityId) then
897
- assert(unitRemoveAbility(handle, abilityId))
898
- return nil
899
- end
900
- return UnitAbility:of(
901
- getUnitAbility(self.handle, abilityId),
902
- abilityId,
903
- self
904
- )
955
+ function Unit.prototype.getAbility(self, abilityId)
956
+ local ability = doUnitAbilityAction(self.handle, abilityId, getUnitAbility, abilityId)
957
+ return UnitAbility:of(ability, abilityId, self)
905
958
  end
906
- function Unit.prototype.removeAbility(self, abilityId)
907
- if unitRemoveAbility(self.handle, abilityId) then
908
- local abilities = self.abilities
909
- for i = 1, #abilities do
910
- if abilities[i].typeId == abilityId then
911
- abilities[i]:destroy()
912
- tremove(abilities, i)
913
- return true
914
- 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
915
967
  end
916
- return true
917
968
  end
918
- return false
969
+ return doUnitAbilityAction(self.handle, abilityTypeId, unitRemoveAbility, abilityTypeId)
919
970
  end
920
971
  function Unit.prototype.hideAbility(self, abilityId, flag)
921
972
  BlzUnitHideAbility(self.handle, abilityId, flag)
@@ -929,12 +980,34 @@ end
929
980
  function Unit.prototype.endAbilityCooldown(self, abilityId)
930
981
  BlzEndUnitAbilityCooldown(self.handle, abilityId)
931
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
932
998
  function Unit.prototype.interruptAttack(self)
933
999
  unitInterruptAttack(self.handle)
934
1000
  end
935
1001
  function Unit.prototype.interruptCast(self, abilityId)
936
- unitDisableAbility(self.handle, abilityId, true, false)
937
- 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
+ )
938
1011
  end
939
1012
  function Unit.prototype.getDistanceTo(self, target)
940
1013
  local handle = self.handle
@@ -994,18 +1067,44 @@ function Unit.prototype.unpauseEx(self)
994
1067
  self:decrementStunCounter()
995
1068
  end
996
1069
  function Unit.prototype.incrementStunCounter(self)
997
- local stunCounter = self[101] or 0
998
- if not self[100] or stunCounter >= 0 then
1070
+ local stunCounter = self[102] or 0
1071
+ if not self[101] and (self[103] or 0) <= 0 or stunCounter >= 0 then
999
1072
  BlzPauseUnitEx(self.handle, true)
1000
1073
  end
1001
- self[101] = stunCounter + 1
1074
+ self[102] = stunCounter + 1
1002
1075
  end
1003
1076
  function Unit.prototype.decrementStunCounter(self)
1004
- local stunCounter = self[101] or 0
1005
- if not self[100] or stunCounter >= 1 then
1077
+ local stunCounter = self[102] or 0
1078
+ if not self[101] and (self[103] or 0) <= 0 or stunCounter >= 1 then
1006
1079
  BlzPauseUnitEx(self.handle, false)
1007
1080
  end
1008
- self[101] = stunCounter - 1
1081
+ self[102] = stunCounter - 1
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
1009
1108
  end
1010
1109
  function Unit.create(self, owner, id, x, y, facing, skinId)
1011
1110
  local handle = skinId and BlzCreateUnitWithSkin(
@@ -1107,8 +1206,11 @@ function Unit.getInSector(self, pos, range, offsetAngle, centralAngle)
1107
1206
  )
1108
1207
  return targetCollection
1109
1208
  end
1110
- function Unit.getSelectionOf(self, player)
1111
- targetCollection = {}
1209
+ function Unit.getSelectionOf(self, player, target)
1210
+ if target == nil then
1211
+ target = {}
1212
+ end
1213
+ targetCollection = target
1112
1214
  targetCollectionNextIndex = 1
1113
1215
  GroupEnumUnitsSelected(dummyGroup, player.handle, collectIntoTarget)
1114
1216
  return targetCollection
@@ -1130,6 +1232,9 @@ end
1130
1232
  function Unit.prototype.__tostring(self)
1131
1233
  return (((self.constructor.name .. "$") .. util.id2s(self.typeId)) .. "@") .. tostring(getHandleId(self.handle))
1132
1234
  end
1235
+ function Unit.getBySyncId(self, syncId)
1236
+ return unitBySyncId[syncId]
1237
+ end
1133
1238
  __TS__SetDescriptor(
1134
1239
  Unit.prototype,
1135
1240
  "_deltas",
@@ -1189,7 +1294,15 @@ __TS__SetDescriptor(
1189
1294
  Unit.prototype,
1190
1295
  "isIllusion",
1191
1296
  {get = function(self)
1192
- 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")
1193
1306
  end},
1194
1307
  true
1195
1308
  )
@@ -1266,6 +1379,19 @@ __TS__SetDescriptor(
1266
1379
  },
1267
1380
  true
1268
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
+ )
1269
1395
  __TS__SetDescriptor(
1270
1396
  Unit.prototype,
1271
1397
  "strengthBase",
@@ -1387,17 +1513,17 @@ __TS__SetDescriptor(
1387
1513
  "isTeamGlowVisible",
1388
1514
  {
1389
1515
  get = function(self)
1390
- return not self[105]
1516
+ return not self[107]
1391
1517
  end,
1392
1518
  set = function(self, isTeamGlowVisible)
1393
- showUnitTeamGlow(self.handle, isTeamGlowVisible)
1394
- local ____temp_5
1519
+ BlzShowUnitTeamGlow(self.handle, isTeamGlowVisible)
1520
+ local ____temp_7
1395
1521
  if not isTeamGlowVisible then
1396
- ____temp_5 = true
1522
+ ____temp_7 = true
1397
1523
  else
1398
- ____temp_5 = nil
1524
+ ____temp_7 = nil
1399
1525
  end
1400
- self[105] = ____temp_5
1526
+ self[107] = ____temp_7
1401
1527
  end
1402
1528
  },
1403
1529
  true
@@ -1406,9 +1532,9 @@ __TS__SetDescriptor(
1406
1532
  Unit.prototype,
1407
1533
  "color",
1408
1534
  {set = function(self, color)
1409
- setUnitColor(self.handle, color.handle)
1410
- if self[105] then
1411
- showUnitTeamGlow(self.handle, false)
1535
+ SetUnitColor(self.handle, color.handle)
1536
+ if self[107] then
1537
+ BlzShowUnitTeamGlow(self.handle, false)
1412
1538
  end
1413
1539
  end},
1414
1540
  true
@@ -1431,14 +1557,14 @@ __TS__SetDescriptor(
1431
1557
  "maxHealth",
1432
1558
  {
1433
1559
  get = function(self)
1434
- return BlzGetUnitMaxHP(self.handle) - (self[103] or 0) - (self[104] or 0)
1560
+ return BlzGetUnitMaxHP(self.handle) - (self[105] or 0) - (self[106] or 0)
1435
1561
  end,
1436
1562
  set = function(self, maxHealth)
1437
- if maxHealth < 1 and self[102] ~= nil then
1438
- self[103] = (self[103] or 0) + (1 - maxHealth)
1563
+ if maxHealth < 1 and self[104] ~= nil then
1564
+ self[105] = (self[105] or 0) + (1 - maxHealth)
1439
1565
  maxHealth = 1
1440
1566
  end
1441
- BlzSetUnitMaxHP(self.handle, maxHealth + (self[104] or 0))
1567
+ BlzSetUnitMaxHP(self.handle, maxHealth + (self[106] or 0))
1442
1568
  end
1443
1569
  },
1444
1570
  true
@@ -1480,10 +1606,10 @@ __TS__SetDescriptor(
1480
1606
  "health",
1481
1607
  {
1482
1608
  get = function(self)
1483
- return GetWidgetLife(self.handle) - (self[104] or 0)
1609
+ return GetWidgetLife(self.handle) - (self[106] or 0)
1484
1610
  end,
1485
1611
  set = function(self, health)
1486
- SetWidgetLife(self.handle, health + (self[104] or 0))
1612
+ SetWidgetLife(self.handle, health + (self[106] or 0))
1487
1613
  end
1488
1614
  },
1489
1615
  true
@@ -1559,25 +1685,12 @@ __TS__SetDescriptor(
1559
1685
  },
1560
1686
  true
1561
1687
  )
1562
- __TS__SetDescriptor(
1563
- Unit.prototype,
1564
- "flyHeight",
1565
- {
1566
- get = function(self)
1567
- return getUnitFlyHeight(self.handle)
1568
- end,
1569
- set = function(self, v)
1570
- SetUnitFlyHeight(self.handle, v, 100000)
1571
- end
1572
- },
1573
- true
1574
- )
1575
1688
  __TS__SetDescriptor(
1576
1689
  Unit.prototype,
1577
1690
  "x",
1578
1691
  {
1579
1692
  get = function(self)
1580
- return getUnitX(self.handle)
1693
+ return self[108] or getUnitX(self.handle)
1581
1694
  end,
1582
1695
  set = function(self, v)
1583
1696
  SetUnitX(self.handle, v)
@@ -1590,7 +1703,7 @@ __TS__SetDescriptor(
1590
1703
  "y",
1591
1704
  {
1592
1705
  get = function(self)
1593
- return getUnitY(self.handle)
1706
+ return self[109] or getUnitY(self.handle)
1594
1707
  end,
1595
1708
  set = function(self, v)
1596
1709
  SetUnitY(self.handle, v)
@@ -1676,10 +1789,10 @@ __TS__SetDescriptor(
1676
1789
  "gold",
1677
1790
  {
1678
1791
  get = function(self)
1679
- return getResourceAmount(self.handle)
1792
+ return GetResourceAmount(self.handle)
1680
1793
  end,
1681
1794
  set = function(self, gold)
1682
- setResourceAmount(self.handle, gold)
1795
+ SetResourceAmount(self.handle, gold)
1683
1796
  end
1684
1797
  },
1685
1798
  true
@@ -1694,17 +1807,21 @@ __TS__SetDescriptor(
1694
1807
  set = function(self, isPaused)
1695
1808
  local handle = self.handle
1696
1809
  if isPaused and not IsUnitPaused(handle) then
1697
- self[100] = true
1698
- for _ = self[101] or 0, -1 do
1699
- BlzPauseUnitEx(handle, true)
1810
+ self[101] = true
1811
+ if (self[103] or 0) <= 0 then
1812
+ for _ = self[102] or 0, -1 do
1813
+ BlzPauseUnitEx(handle, true)
1814
+ end
1700
1815
  end
1701
1816
  PauseUnit(handle, true)
1702
1817
  elseif not isPaused and IsUnitPaused(handle) then
1703
1818
  PauseUnit(handle, false)
1704
- for _ = self[101] or 0, -1 do
1705
- 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
1706
1823
  end
1707
- self[100] = nil
1824
+ self[101] = nil
1708
1825
  end
1709
1826
  end
1710
1827
  },
@@ -1760,20 +1877,6 @@ __TS__SetDescriptor(
1760
1877
  },
1761
1878
  true
1762
1879
  )
1763
- __TS__SetDescriptor(
1764
- Unit.prototype,
1765
- "scale",
1766
- {
1767
- get = function(self)
1768
- return getUnitRealField(self.handle, UNIT_RF_SCALING_VALUE)
1769
- end,
1770
- set = function(self, v)
1771
- setUnitScale(self.handle, v, v, v)
1772
- setUnitRealField(self.handle, UNIT_RF_SCALING_VALUE, v)
1773
- end
1774
- },
1775
- true
1776
- )
1777
1880
  __TS__SetDescriptor(
1778
1881
  Unit.prototype,
1779
1882
  "timeScale",
@@ -1807,6 +1910,19 @@ __TS__SetDescriptor(
1807
1910
  end},
1808
1911
  true
1809
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
+ )
1810
1926
  __TS__SetDescriptor(
1811
1927
  Unit.prototype,
1812
1928
  "pathing",
@@ -1988,6 +2104,14 @@ __TS__SetDescriptor(
1988
2104
  end},
1989
2105
  true
1990
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
+ )
1991
2115
  __TS__SetDescriptor(
1992
2116
  Unit.prototype,
1993
2117
  "onSelect",
@@ -2061,7 +2185,6 @@ Unit.onDecay = __TS__New(
2061
2185
  Unit.onResurrect = __TS__New(
2062
2186
  InitializingEvent,
2063
2187
  function(event)
2064
- local invoke = Event.invoke
2065
2188
  local dead = setmetatable({}, {__mode = "k"})
2066
2189
  ____exports.Unit.deathEvent:addListener(function(unit)
2067
2190
  dead[unit] = true
@@ -2077,10 +2200,15 @@ Unit.onResurrect = __TS__New(
2077
2200
  Unit.morphEvent = __TS__New(
2078
2201
  InitializingEvent,
2079
2202
  function(event)
2203
+ local function ifNotLeft(unit)
2204
+ local handle = unit.handle
2205
+ if getUnitAbilityLevel(handle, leaveDetectAbilityId) ~= 0 and unitAddAbility(handle, morphDetectAbilityId) then
2206
+ invoke(event, unit)
2207
+ end
2208
+ end
2080
2209
  ____exports.Unit.onImmediateOrder[orderId("undefend")]:addListener(function(unit)
2081
2210
  if getUnitAbilityLevel(unit.handle, morphDetectAbilityId) == 0 then
2082
- assert(unitAddAbility(unit.handle, morphDetectAbilityId))
2083
- Timer:run(Event.invoke, event, unit)
2211
+ Timer:run(ifNotLeft, unit)
2084
2212
  end
2085
2213
  end)
2086
2214
  end
@@ -2118,27 +2246,26 @@ Unit.onSpellEffect = dispatchId(__TS__New(
2118
2246
  Unit.onTargetCast = dispatchId(__TS__New(
2119
2247
  InitializingEvent,
2120
2248
  function(event)
2121
- local invoke = Event.invoke
2122
2249
  local function listener(unit, id)
2123
- local ____GetSpellTargetUnit_result_8
2250
+ local ____GetSpellTargetUnit_result_10
2124
2251
  if GetSpellTargetUnit() then
2125
- ____GetSpellTargetUnit_result_8 = ____exports.Unit:of(GetSpellTargetUnit())
2252
+ ____GetSpellTargetUnit_result_10 = ____exports.Unit:of(GetSpellTargetUnit())
2126
2253
  else
2127
- local ____GetSpellTargetItem_result_7
2254
+ local ____GetSpellTargetItem_result_9
2128
2255
  if GetSpellTargetItem() then
2129
- ____GetSpellTargetItem_result_7 = Item:of(GetSpellTargetItem())
2256
+ ____GetSpellTargetItem_result_9 = Item:of(GetSpellTargetItem())
2130
2257
  else
2131
- local ____GetSpellTargetDestructable_result_6
2258
+ local ____GetSpellTargetDestructable_result_8
2132
2259
  if GetSpellTargetDestructable() then
2133
- ____GetSpellTargetDestructable_result_6 = Destructable:of(GetSpellTargetDestructable())
2260
+ ____GetSpellTargetDestructable_result_8 = Destructable:of(GetSpellTargetDestructable())
2134
2261
  else
2135
- ____GetSpellTargetDestructable_result_6 = nil
2262
+ ____GetSpellTargetDestructable_result_8 = nil
2136
2263
  end
2137
- ____GetSpellTargetItem_result_7 = ____GetSpellTargetDestructable_result_6
2264
+ ____GetSpellTargetItem_result_9 = ____GetSpellTargetDestructable_result_8
2138
2265
  end
2139
- ____GetSpellTargetUnit_result_8 = ____GetSpellTargetItem_result_7
2266
+ ____GetSpellTargetUnit_result_10 = ____GetSpellTargetItem_result_9
2140
2267
  end
2141
- local target = ____GetSpellTargetUnit_result_8
2268
+ local target = ____GetSpellTargetUnit_result_10
2142
2269
  if target then
2143
2270
  invoke(event, unit, id, target)
2144
2271
  end
@@ -2310,10 +2437,12 @@ Unit.onImmediateOrder = dispatchId(__TS__New(
2310
2437
  ____exports.UnitTriggerEvent,
2311
2438
  EVENT_PLAYER_UNIT_ISSUED_ORDER,
2312
2439
  function()
2313
- local unit = ____exports.Unit:of(getOrderedUnit())
2314
- local issuedOrderId = getIssuedOrderId()
2315
- if unit ~= nil and unit.state == 1 then
2316
- return unit, issuedOrderId
2440
+ local handle = getOrderedUnit()
2441
+ if handle ~= nil and getUnitTypeId(handle) ~= dummyUnitId then
2442
+ local unit = ____exports.Unit:of(handle)
2443
+ if unit.state == 1 then
2444
+ return unit, getIssuedOrderId()
2445
+ end
2317
2446
  end
2318
2447
  return IgnoreEvent
2319
2448
  end
@@ -2335,7 +2464,6 @@ Unit.autoAttackStartEvent = __TS__New(
2335
2464
  )
2336
2465
  Unit.onDamaging = (function()
2337
2466
  local event = __TS__New(Event)
2338
- local invoke = Event.invoke
2339
2467
  local trigger = CreateTrigger()
2340
2468
  TriggerRegisterAnyUnitEventBJ(trigger, EVENT_PLAYER_UNIT_DAMAGING)
2341
2469
  TriggerAddCondition(
@@ -2345,38 +2473,57 @@ Unit.onDamaging = (function()
2345
2473
  if source and source.typeId == dummyUnitId then
2346
2474
  source = nil
2347
2475
  end
2348
- local target = BlzGetEventDamageTarget()
2476
+ local target = ____exports.Unit:of(BlzGetEventDamageTarget())
2477
+ local metadata = damageMetadataByTarget[target]
2478
+ damageMetadataByTarget[target] = nil
2349
2479
  local data = {
2350
2480
  amount = GetEventDamage(),
2351
- attackType = BlzGetEventAttackType(),
2481
+ attackType = nativeToAttackType(BlzGetEventAttackType()),
2352
2482
  damageType = BlzGetEventDamageType(),
2353
2483
  weaponType = BlzGetEventWeaponType(),
2354
- isAttack = BlzGetEventIsAttack()
2484
+ metadata = metadata,
2485
+ isAttack = BlzGetEventIsAttack(),
2486
+ originalAmount = GetEventDamage(),
2487
+ originalMetadata = metadata,
2488
+ preventRetaliation = damagingEventPreventRetaliation
2355
2489
  }
2356
2490
  if data.isAttack and source then
2357
- 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
2358
- if weapon == -1 then
2359
- local targetsAllowed = BlzGetUnitWeaponIntegerField(source.handle, UNIT_WEAPON_IF_ATTACK_TARGETS_ALLOWED, 0)
2360
- weapon = 0
2361
- end
2362
- data.weapon = assert(source.weapons[weapon + 1])
2491
+ data.weapon = source:chooseWeapon(target)
2363
2492
  end
2364
2493
  if not data.isAttack or not source or not source._attackHandlers then
2365
2494
  invoke(
2366
2495
  event,
2367
2496
  source,
2368
- ____exports.Unit:of(target),
2497
+ target,
2369
2498
  setmetatable(
2370
2499
  {},
2371
2500
  {
2372
2501
  __index = data,
2373
2502
  __newindex = function(self, key, value)
2374
- damageSetters[key](value)
2503
+ local damageSetter = damageSetters[key]
2504
+ if damageSetter ~= nil then
2505
+ damageSetter(value)
2506
+ end
2375
2507
  data[key] = value
2376
2508
  end
2377
2509
  }
2378
2510
  )
2379
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
2380
2527
  return
2381
2528
  end
2382
2529
  BlzSetEventDamage(0)
@@ -2384,7 +2531,7 @@ Unit.onDamaging = (function()
2384
2531
  BlzSetEventDamageType(DAMAGE_TYPE_UNKNOWN)
2385
2532
  BlzSetEventWeaponType(WEAPON_TYPE_WHOKNOWS)
2386
2533
  local sourceOwner = source.owner.handle
2387
- local targetOwner = GetOwningPlayer(target)
2534
+ local targetOwner = target.owner.handle
2388
2535
  if not GetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE) then
2389
2536
  SetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE, true)
2390
2537
  Timer:run(function()
@@ -2400,23 +2547,19 @@ Unit.onDamaging = (function()
2400
2547
  for ____, ____value in ipairs(source._attackHandlers) do
2401
2548
  local condition = ____value[1]
2402
2549
  local action = ____value[2]
2403
- if condition(
2404
- source,
2405
- ____exports.Unit:of(target),
2406
- data
2407
- ) then
2550
+ if condition(source, target, data) then
2408
2551
  action(
2409
2552
  source,
2410
- ____exports.Unit:of(target),
2553
+ target,
2411
2554
  setmetatable(
2412
2555
  {fire = function()
2413
2556
  UnitDamageTarget(
2414
2557
  source.handle,
2415
- target,
2558
+ target.handle,
2416
2559
  data.amount,
2417
2560
  true,
2418
2561
  true,
2419
- data.attackType,
2562
+ attackTypeToNative(data.attackType),
2420
2563
  data.damageType,
2421
2564
  data.weaponType
2422
2565
  )
@@ -2434,7 +2577,6 @@ end)()
2434
2577
  Unit.onDamage = __TS__New(
2435
2578
  InitializingEvent,
2436
2579
  function(event)
2437
- local invoke = Event.invoke
2438
2580
  local trigger = CreateTrigger()
2439
2581
  TriggerRegisterAnyUnitEventBJ(trigger, EVENT_PLAYER_UNIT_DAMAGED)
2440
2582
  TriggerAddCondition(
@@ -2444,29 +2586,54 @@ Unit.onDamage = __TS__New(
2444
2586
  if source and source.typeId == dummyUnitId then
2445
2587
  source = nil
2446
2588
  end
2589
+ local target = ____exports.Unit:of(BlzGetEventDamageTarget())
2590
+ local damagingEvent = damagingEventByTarget[target]
2591
+ damagingEventByTarget[target] = nil
2447
2592
  local data = {
2448
2593
  amount = GetEventDamage(),
2449
- attackType = BlzGetEventAttackType(),
2594
+ attackType = nativeToAttackType(BlzGetEventAttackType()),
2450
2595
  damageType = BlzGetEventDamageType(),
2451
2596
  weaponType = BlzGetEventWeaponType(),
2597
+ metadata = damagingEvent and damagingEvent.metadata,
2452
2598
  isAttack = BlzGetEventIsAttack(),
2599
+ originalAmount = damagingEvent and damagingEvent.originalAmount or GetEventDamage(),
2600
+ originalMetadata = damagingEvent and damagingEvent.originalMetadata,
2453
2601
  preventDeath = damageEventPreventDeath
2454
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
2455
2620
  local evData = setmetatable(
2456
2621
  {},
2457
2622
  {
2458
2623
  __index = data,
2459
2624
  __newindex = function(self, key, value)
2460
- damageSetters[key](value)
2625
+ local damageSetter = damageSetters[key]
2626
+ if damageSetter ~= nil then
2627
+ damageSetter(value)
2628
+ end
2461
2629
  data[key] = value
2462
2630
  end
2463
2631
  }
2464
2632
  )
2465
- local target = ____exports.Unit:of(BlzGetEventDamageTarget())
2466
2633
  invoke(event, source, target, evData)
2467
2634
  if evData[0] ~= nil and target.health - evData.amount < 0.405 then
2468
2635
  local bonusHealth = math.ceil(evData.amount)
2469
- target[104] = (target[104] or 0) + bonusHealth
2636
+ target[106] = (target[106] or 0) + bonusHealth
2470
2637
  BlzSetUnitMaxHP(
2471
2638
  target.handle,
2472
2639
  BlzGetUnitMaxHP(target.handle) + bonusHealth
@@ -2480,7 +2647,7 @@ Unit.onDamage = __TS__New(
2480
2647
  evData[0],
2481
2648
  table.unpack(evData, 1 + 1, 1 + (evData[1] or 0))
2482
2649
  )
2483
- target[104] = (target[104] or 0) - bonusHealth
2650
+ target[106] = (target[106] or 0) - bonusHealth
2484
2651
  SetWidgetLife(
2485
2652
  target.handle,
2486
2653
  GetWidgetLife(target.handle) - bonusHealth
@@ -2500,32 +2667,110 @@ Unit.onDamage = __TS__New(
2500
2667
  DestroyTrigger(trigger)
2501
2668
  end
2502
2669
  )
2503
- Unit.onItemDrop = __TS__New(
2670
+ Unit.itemDroppedEvent = __TS__New(
2504
2671
  ____exports.UnitTriggerEvent,
2505
2672
  EVENT_PLAYER_UNIT_DROP_ITEM,
2506
2673
  function()
2507
2674
  local unit = getTriggerUnit()
2508
- if getUnitTypeId(unit) ~= dummyUnitId then
2509
- return ____exports.Unit:of(unit), Item:of(getManipulatedItem())
2675
+ local item = getManipulatedItem()
2676
+ if getUnitTypeId(unit) ~= dummyUnitId and not (ignoreEventsItems[item] ~= nil) then
2677
+ return ____exports.Unit:of(unit), Item:of(item)
2510
2678
  end
2511
2679
  return IgnoreEvent
2512
2680
  end
2513
2681
  )
2514
- Unit.onItemPickup = __TS__New(
2682
+ Unit.itemPickedUpEvent = __TS__New(
2515
2683
  ____exports.UnitTriggerEvent,
2516
2684
  EVENT_PLAYER_UNIT_PICKUP_ITEM,
2517
2685
  function()
2518
- local unit = getTriggerUnit()
2519
- if getUnitTypeId(unit) ~= dummyUnitId then
2520
- return ____exports.Unit:of(unit), Item:of(getManipulatedItem())
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
2521
2694
  end
2522
2695
  return IgnoreEvent
2523
2696
  end
2524
2697
  )
2525
- Unit.onItemUse = __TS__New(
2698
+ Unit.itemUsedEvent = __TS__New(
2526
2699
  ____exports.UnitTriggerEvent,
2527
2700
  EVENT_PLAYER_UNIT_USE_ITEM,
2528
- function() return ____exports.Unit:of(GetTriggerUnit()), Item:of(GetManipulatedItem()) end
2701
+ function()
2702
+ local unit = getTriggerUnit()
2703
+ local item = getManipulatedItem()
2704
+ if getUnitTypeId(unit) ~= dummyUnitId and not (ignoreEventsItems[item] ~= nil) then
2705
+ return ____exports.Unit:of(unit), Item:of(item)
2706
+ end
2707
+ return IgnoreEvent
2708
+ end
2709
+ )
2710
+ Unit.itemStackedEvent = __TS__New(
2711
+ ____exports.UnitTriggerEvent,
2712
+ EVENT_PLAYER_UNIT_STACK_ITEM,
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}
2729
+ )
2730
+ __TS__ObjectDefineProperty(
2731
+ Unit,
2732
+ "itemUseOrderEvent",
2733
+ {get = function(self)
2734
+ local event = __TS__New(Event)
2735
+ for order = orderId("useslot0"), orderId("useslot5") do
2736
+ local slot = order - orderId("useslot0")
2737
+ local function listener(unit)
2738
+ local item = unit.items[slot + 1]
2739
+ if item ~= nil then
2740
+ invoke(event, unit, item)
2741
+ end
2742
+ end
2743
+ self.onImmediateOrder[order]:addListener(listener)
2744
+ self.onTargetOrder[order]:addListener(listener)
2745
+ self.onPointOrder[order]:addListener(listener)
2746
+ end
2747
+ rawset(self, "itemUseOrderEvent", event)
2748
+ return event
2749
+ end}
2750
+ )
2751
+ __TS__ObjectDefineProperty(
2752
+ Unit,
2753
+ "itemMoveOrderEvent",
2754
+ {get = function(self)
2755
+ local event = __TS__New(Event)
2756
+ for order = orderId("moveslot0"), orderId("moveslot5") do
2757
+ local slotTo = order - orderId("moveslot0")
2758
+ self.onTargetOrder[order]:addListener(function(unit, item)
2759
+ local slotFrom = unit.items:findSlot(item)
2760
+ if slotFrom ~= nil then
2761
+ invoke(
2762
+ event,
2763
+ unit,
2764
+ item,
2765
+ slotFrom,
2766
+ slotTo
2767
+ )
2768
+ end
2769
+ end)
2770
+ end
2771
+ rawset(self, "itemMoveOrderEvent", event)
2772
+ return event
2773
+ end}
2529
2774
  )
2530
2775
  __TS__ObjectDefineProperty(
2531
2776
  Unit,
@@ -2552,6 +2797,10 @@ __TS__ObjectDefineProperty(
2552
2797
  rawset(self, "destroyEvent", destroyEvent)
2553
2798
  return destroyEvent
2554
2799
  end}
2800
+ )
2801
+ Unit.synchronize = synchronizer(
2802
+ function(unit) return unit.syncId end,
2803
+ function(syncId) return unitBySyncId[syncId] end
2555
2804
  );
2556
2805
  (function(self)
2557
2806
  local leaveAbilityIds = postcompile(function()
@@ -2575,15 +2824,13 @@ __TS__ObjectDefineProperty(
2575
2824
  orderId("unimmolation")
2576
2825
  }) do
2577
2826
  ____exports.Unit.onImmediateOrder[leaveOrderId]:addListener(function(unit)
2578
- if unit.state == 1 then
2579
- local handle = unit.handle
2580
- for i = 1, #leaveAbilityIds do
2581
- if getUnitAbilityLevel(handle, leaveAbilityIds[i]) ~= 0 then
2582
- return
2583
- end
2827
+ local handle = unit.handle
2828
+ for i = 1, #leaveAbilityIds do
2829
+ if getUnitAbilityLevel(handle, leaveAbilityIds[i]) ~= 0 then
2830
+ return
2584
2831
  end
2585
- unit:destroy()
2586
2832
  end
2833
+ unit:destroy()
2587
2834
  end)
2588
2835
  end
2589
2836
  end)(Unit)