warscript 0.0.1-dev.8c7ee30 → 0.0.1-dev.8dbb0ee

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 (223) 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/handle.lua +2 -0
  12. package/core/types/player.d.ts +15 -0
  13. package/core/types/player.lua +56 -14
  14. package/core/types/playerCamera.d.ts +2 -0
  15. package/core/types/playerCamera.lua +123 -5
  16. package/core/types/sound.d.ts +17 -24
  17. package/core/types/sound.lua +99 -24
  18. package/core/types/tileCell.d.ts +9 -0
  19. package/core/types/tileCell.lua +92 -0
  20. package/core/types/timer.d.ts +9 -8
  21. package/core/types/timer.lua +45 -23
  22. package/core/util.d.ts +1 -1
  23. package/core/util.lua +18 -1
  24. package/decl/native.d.ts +846 -790
  25. package/engine/behavior.d.ts +7 -2
  26. package/engine/behavior.lua +112 -33
  27. package/engine/behaviour/ability/always-enabled.d.ts +7 -0
  28. package/engine/behaviour/ability/always-enabled.lua +31 -0
  29. package/engine/behaviour/ability/apply-buff.d.ts +8 -5
  30. package/engine/behaviour/ability/apply-buff.lua +32 -0
  31. package/engine/behaviour/ability/apply-unit-behavior.lua +1 -0
  32. package/engine/behaviour/ability/damage.d.ts +39 -11
  33. package/engine/behaviour/ability/damage.lua +83 -37
  34. package/engine/behaviour/ability/emulate-impact.d.ts +6 -0
  35. package/engine/behaviour/ability/emulate-impact.lua +43 -0
  36. package/engine/behaviour/ability/heal.d.ts +33 -6
  37. package/engine/behaviour/ability/heal.lua +89 -10
  38. package/engine/behaviour/ability/instant-impact.d.ts +2 -2
  39. package/engine/behaviour/ability/instant-impact.lua +4 -19
  40. package/engine/behaviour/ability/on-command-impact.d.ts +8 -0
  41. package/engine/behaviour/ability/on-command-impact.lua +25 -0
  42. package/engine/behaviour/ability/remove-buffs.d.ts +25 -0
  43. package/engine/behaviour/ability/remove-buffs.lua +49 -0
  44. package/engine/behaviour/ability/restore-mana.d.ts +15 -0
  45. package/engine/behaviour/ability/restore-mana.lua +29 -0
  46. package/engine/behaviour/ability.d.ts +20 -4
  47. package/engine/behaviour/ability.lua +111 -47
  48. package/engine/behaviour/unit/stun-immunity.d.ts +7 -3
  49. package/engine/behaviour/unit/stun-immunity.lua +52 -27
  50. package/engine/behaviour/unit.d.ts +39 -0
  51. package/engine/behaviour/unit.lua +210 -4
  52. package/engine/buff.d.ts +102 -42
  53. package/engine/buff.lua +451 -211
  54. package/engine/game-map.d.ts +7 -0
  55. package/engine/game-map.lua +32 -0
  56. package/engine/internal/ability.d.ts +23 -14
  57. package/engine/internal/ability.lua +129 -85
  58. package/engine/internal/item/ability.lua +162 -4
  59. package/engine/internal/item+owner.lua +12 -6
  60. package/engine/internal/item.d.ts +20 -19
  61. package/engine/internal/item.lua +191 -74
  62. package/engine/internal/mechanics/ability-duration.lua +1 -1
  63. package/engine/internal/misc/ability-disable-counter.d.ts +2 -0
  64. package/engine/internal/misc/ability-disable-counter.lua +13 -0
  65. package/engine/internal/misc/damage-metadata-by-target.d.ts +2 -0
  66. package/engine/internal/misc/damage-metadata-by-target.lua +5 -0
  67. package/engine/internal/misc/frame-coordinates.d.ts +2 -0
  68. package/engine/internal/misc/frame-coordinates.lua +21 -0
  69. package/engine/internal/misc/get-terrain-z.d.ts +2 -0
  70. package/engine/internal/misc/get-terrain-z.lua +11 -0
  71. package/engine/internal/misc/player-local-handle.d.ts +2 -0
  72. package/engine/internal/misc/player-local-handle.lua +5 -0
  73. package/engine/internal/object-data/auto-attack-speed-increase.d.ts +1 -1
  74. package/engine/internal/object-data/auto-attack-speed-increase.lua +2 -0
  75. package/engine/internal/object-data/evasion-probability.d.ts +2 -0
  76. package/engine/internal/object-data/evasion-probability.lua +16 -0
  77. package/engine/internal/unit/ability.d.ts +45 -1
  78. package/engine/internal/unit/ability.lua +128 -17
  79. package/engine/internal/unit/add-item-to-slot-init.d.ts +2 -0
  80. package/engine/internal/unit/add-item-to-slot-init.lua +23 -0
  81. package/engine/internal/unit/add-item-to-slot.d.ts +2 -0
  82. package/engine/internal/unit/add-item-to-slot.lua +52 -0
  83. package/engine/internal/unit/allowed-targets.d.ts +1 -1
  84. package/engine/internal/unit/allowed-targets.lua +9 -1
  85. package/engine/internal/unit/bonus.d.ts +6 -2
  86. package/engine/internal/unit/bonus.lua +23 -1
  87. package/engine/internal/unit/ignore-events-items.d.ts +2 -0
  88. package/engine/internal/unit/ignore-events-items.lua +5 -0
  89. package/engine/internal/unit/item.d.ts +24 -0
  90. package/engine/internal/unit/item.lua +78 -0
  91. package/engine/internal/unit/main-selected.d.ts +13 -0
  92. package/engine/internal/unit/main-selected.lua +36 -0
  93. package/engine/internal/unit/order.d.ts +20 -0
  94. package/engine/internal/unit/order.lua +136 -0
  95. package/engine/internal/unit+ability.lua +12 -3
  96. package/engine/internal/unit+damage.d.ts +2 -11
  97. package/engine/internal/unit+damage.lua +10 -14
  98. package/engine/internal/unit+spellSteal.lua +1 -2
  99. package/engine/internal/unit+transport.lua +4 -10
  100. package/engine/internal/unit-missile-launch.lua +60 -13
  101. package/engine/internal/unit.d.ts +63 -18
  102. package/engine/internal/unit.lua +463 -171
  103. package/engine/internal/utility.lua +12 -0
  104. package/engine/lightning.d.ts +12 -5
  105. package/engine/lightning.lua +48 -14
  106. package/engine/local-client.d.ts +9 -2
  107. package/engine/local-client.lua +112 -0
  108. package/engine/object-data/auxiliary/animation-name.d.ts +1 -0
  109. package/engine/object-data/auxiliary/animation-name.lua +16 -0
  110. package/engine/object-data/auxiliary/armor-type.d.ts +11 -0
  111. package/engine/object-data/auxiliary/armor-type.lua +46 -0
  112. package/engine/object-data/auxiliary/attachment-preset.d.ts +7 -2
  113. package/engine/object-data/auxiliary/attachment-preset.lua +4 -3
  114. package/engine/object-data/auxiliary/attack-type.d.ts +7 -8
  115. package/engine/object-data/auxiliary/attack-type.lua +42 -0
  116. package/engine/object-data/auxiliary/movement-type.d.ts +7 -7
  117. package/engine/object-data/auxiliary/movement-type.lua +22 -0
  118. package/engine/object-data/auxiliary/sound-eax.d.ts +10 -0
  119. package/engine/object-data/auxiliary/sound-eax.lua +2 -0
  120. package/engine/object-data/auxiliary/sound-preset-name.d.ts +5 -1
  121. package/engine/object-data/auxiliary/tech-tree-dependency.d.ts +1 -1
  122. package/engine/object-data/auxiliary/unit-attribute.d.ts +6 -0
  123. package/engine/object-data/auxiliary/unit-attribute.lua +9 -0
  124. package/engine/object-data/entry/ability-type/berserk.d.ts +2 -0
  125. package/engine/object-data/entry/ability-type/berserk.lua +13 -0
  126. package/engine/object-data/entry/ability-type/blank-configurable.lua +12 -1
  127. package/engine/object-data/entry/ability-type/carrion-swarm.d.ts +14 -0
  128. package/engine/object-data/entry/ability-type/carrion-swarm.lua +65 -0
  129. package/engine/object-data/entry/ability-type/disease-cloud.lua +2 -2
  130. package/engine/object-data/entry/ability-type/engineering-upgrade.lua +2 -2
  131. package/engine/object-data/entry/ability-type/ensnare.d.ts +12 -0
  132. package/engine/object-data/entry/ability-type/ensnare.lua +52 -0
  133. package/engine/object-data/entry/ability-type/feral-spirit.lua +2 -2
  134. package/engine/object-data/entry/ability-type/permanent-invisibility.d.ts +8 -0
  135. package/engine/object-data/entry/ability-type/permanent-invisibility.lua +26 -0
  136. package/engine/object-data/entry/ability-type/phase-shift.d.ts +10 -0
  137. package/engine/object-data/entry/ability-type/phase-shift.lua +39 -0
  138. package/engine/object-data/entry/ability-type/phoenix-morph.lua +4 -4
  139. package/engine/object-data/entry/ability-type/raise-dead.d.ts +17 -0
  140. package/engine/object-data/entry/ability-type/raise-dead.lua +78 -0
  141. package/engine/object-data/entry/ability-type/shock-wave.d.ts +4 -0
  142. package/engine/object-data/entry/ability-type/shock-wave.lua +26 -0
  143. package/engine/object-data/entry/ability-type/slow-poison.d.ts +10 -0
  144. package/engine/object-data/entry/ability-type/slow-poison.lua +58 -0
  145. package/engine/object-data/entry/ability-type/summon-quilbeast.lua +2 -2
  146. package/engine/object-data/entry/ability-type/summon-water-elemental.lua +2 -2
  147. package/engine/object-data/entry/ability-type/web.d.ts +12 -0
  148. package/engine/object-data/entry/ability-type/web.lua +52 -0
  149. package/engine/object-data/entry/ability-type.d.ts +19 -17
  150. package/engine/object-data/entry/ability-type.lua +93 -36
  151. package/engine/object-data/entry/buff-type/applicable.lua +18 -37
  152. package/engine/object-data/entry/buff-type.d.ts +6 -12
  153. package/engine/object-data/entry/buff-type.lua +13 -29
  154. package/engine/object-data/entry/destructible-type.d.ts +1 -1
  155. package/engine/object-data/entry/item-type.d.ts +15 -1
  156. package/engine/object-data/entry/item-type.lua +93 -2
  157. package/engine/object-data/entry/lightning-type.d.ts +1 -1
  158. package/engine/object-data/entry/sound-preset.d.ts +33 -0
  159. package/engine/object-data/entry/sound-preset.lua +140 -0
  160. package/engine/object-data/entry/unit-type.d.ts +21 -5
  161. package/engine/object-data/entry/unit-type.lua +214 -93
  162. package/engine/object-data/entry/upgrade.d.ts +1 -1
  163. package/engine/object-data/entry/upgrade.lua +4 -4
  164. package/engine/object-data/entry.d.ts +16 -14
  165. package/engine/object-data/entry.lua +60 -32
  166. package/engine/object-data/utility/object-data-entry-id-generator.lua +7 -0
  167. package/engine/object-field/ability.d.ts +28 -5
  168. package/engine/object-field/ability.lua +59 -5
  169. package/engine/object-field/unit.d.ts +57 -3
  170. package/engine/object-field/unit.lua +207 -7
  171. package/engine/object-field.d.ts +17 -6
  172. package/engine/object-field.lua +190 -90
  173. package/engine/random.d.ts +9 -0
  174. package/engine/random.lua +13 -0
  175. package/engine/standard/entries/buff-type.d.ts +3 -0
  176. package/engine/standard/entries/buff-type.lua +3 -0
  177. package/engine/standard/entries/sound-preset.d.ts +10 -0
  178. package/engine/standard/entries/sound-preset.lua +10 -0
  179. package/engine/standard/fields/ability.d.ts +2 -0
  180. package/engine/standard/fields/ability.lua +2 -0
  181. package/engine/standard/fields/unit.d.ts +4 -0
  182. package/engine/standard/fields/unit.lua +7 -0
  183. package/engine/synchronization.d.ts +11 -0
  184. package/engine/synchronization.lua +77 -0
  185. package/engine/text-tag.d.ts +36 -2
  186. package/engine/text-tag.lua +249 -10
  187. package/engine/unit.d.ts +4 -0
  188. package/engine/unit.lua +4 -0
  189. package/index.d.ts +1 -0
  190. package/index.lua +1 -0
  191. package/lualib_bundle.lua +7 -2
  192. package/net/socket.d.ts +7 -1
  193. package/net/socket.lua +45 -4
  194. package/network.d.ts +1 -0
  195. package/network.lua +3 -2
  196. package/objutil/buff.lua +3 -4
  197. package/objutil/unit.lua +8 -0
  198. package/package.json +2 -2
  199. package/patch-lua.d.ts +0 -0
  200. package/patch-lua.lua +10 -0
  201. package/patch-lualib.lua +1 -1
  202. package/property.d.ts +55 -0
  203. package/property.lua +374 -0
  204. package/utility/arrays.d.ts +10 -1
  205. package/utility/arrays.lua +45 -3
  206. package/utility/callback-array.d.ts +17 -0
  207. package/utility/callback-array.lua +61 -0
  208. package/utility/functions.d.ts +8 -0
  209. package/utility/functions.lua +13 -0
  210. package/utility/lazy.d.ts +2 -0
  211. package/utility/lazy.lua +14 -0
  212. package/utility/linked-set.d.ts +13 -2
  213. package/utility/linked-set.lua +27 -3
  214. package/utility/lua-maps.d.ts +15 -2
  215. package/utility/lua-maps.lua +53 -2
  216. package/utility/lua-sets.d.ts +2 -0
  217. package/utility/lua-sets.lua +7 -0
  218. package/utility/reflection.lua +11 -7
  219. package/utility/types.d.ts +4 -0
  220. package/core/mapbounds.d.ts +0 -8
  221. package/core/mapbounds.lua +0 -12
  222. package/core/types/order.d.ts +0 -25
  223. package/core/types/order.lua +0 -55
@@ -6,6 +6,7 @@ local __TS__New = ____lualib.__TS__New
6
6
  local __TS__Class = ____lualib.__TS__Class
7
7
  local __TS__ClassExtends = ____lualib.__TS__ClassExtends
8
8
  local __TS__SetDescriptor = ____lualib.__TS__SetDescriptor
9
+ local __TS__ArraySetLength = ____lualib.__TS__ArraySetLength
9
10
  local __TS__SparseArrayNew = ____lualib.__TS__SparseArrayNew
10
11
  local __TS__SparseArrayPush = ____lualib.__TS__SparseArrayPush
11
12
  local __TS__SparseArraySpread = ____lualib.__TS__SparseArraySpread
@@ -50,12 +51,23 @@ local ____arrays = require("utility.arrays")
50
51
  local forEach = ____arrays.forEach
51
52
  local ____math = require("math")
52
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
53
67
  local match = string.match
54
68
  local ____tostring = _G.tostring
55
69
  local setUnitAnimation = SetUnitAnimation
56
- local setUnitAnimationWithRarity = SetUnitAnimationWithRarity
57
70
  local setUnitAnimationByIndex = SetUnitAnimationByIndex
58
- local queueUnitAnimation = QueueUnitAnimation
59
71
  local getUnitIntegerField = BlzGetUnitIntegerField
60
72
  local getUnitRealField = BlzGetUnitRealField
61
73
  local getHeroStr = GetHeroStr
@@ -74,9 +86,9 @@ local setUnitScale = SetUnitScale
74
86
  local setUnitPosition = SetUnitPosition
75
87
  local setUnitTimeScale = SetUnitTimeScale
76
88
  local getHandleId = GetHandleId
89
+ local getUnitCurrentOrder = GetUnitCurrentOrder
77
90
  local createUnit = CreateUnit
78
91
  local killUnit = KillUnit
79
- local setUnitExploded = SetUnitExploded
80
92
  local removeUnit = RemoveUnit
81
93
  local getUnitTypeId = GetUnitTypeId
82
94
  local isHeroUnitId = IsHeroUnitId
@@ -92,8 +104,6 @@ local getSpellTargetItem = GetSpellTargetItem
92
104
  local getSpellTargetDestructable = GetSpellTargetDestructable
93
105
  local isUnitInRangeXY = IsUnitInRangeXY
94
106
  local isUnitInRange = IsUnitInRange
95
- local setResourceAmount = SetResourceAmount
96
- local getResourceAmount = GetResourceAmount
97
107
  local getUnitWeaponRealField = BlzGetUnitWeaponRealField
98
108
  local setUnitWeaponRealField = BlzSetUnitWeaponRealField
99
109
  local getUnitWeaponStringField = BlzGetUnitWeaponStringField
@@ -117,15 +127,9 @@ local getOrderedUnit = GetOrderedUnit
117
127
  local getIssuedOrderId = GetIssuedOrderId
118
128
  local isUnitInvulnerable = BlzIsUnitInvulnerable
119
129
  local unitAlive = UnitAlive
120
- local unitAddType = UnitAddType
121
- local unitRemoveType = UnitRemoveType
122
- local isUnitIllusion = IsUnitIllusion
123
- local isUnitType = IsUnitType
124
130
  local isUnitAlly = IsUnitAlly
125
131
  local isUnitEnemy = IsUnitEnemy
126
132
  local getOwningPlayer = GetOwningPlayer
127
- local setUnitColor = SetUnitColor
128
- local showUnitTeamGlow = BlzShowUnitTeamGlow
129
133
  ____exports.UnitClassification = {}
130
134
  local UnitClassification = ____exports.UnitClassification
131
135
  do
@@ -135,6 +139,7 @@ do
135
139
  UnitClassification.GROUND = UNIT_TYPE_GROUND
136
140
  UnitClassification.SUMMONED = UNIT_TYPE_SUMMONED
137
141
  UnitClassification.MECHANICAL = UNIT_TYPE_MECHANICAL
142
+ UnitClassification.WORKER = UNIT_TYPE_PEON
138
143
  UnitClassification.ANCIENT = UNIT_TYPE_ANCIENT
139
144
  UnitClassification.SUICIDAL = UNIT_TYPE_SAPPER
140
145
  UnitClassification.TAUREN = UNIT_TYPE_TAUREN
@@ -289,7 +294,6 @@ local function dispatch(event, idGetter, argsGetter)
289
294
  return event[id]
290
295
  end
291
296
  if not initialized then
292
- local invoke = Event.invoke
293
297
  event:addListener(function(...)
294
298
  local id = idGetter(...)
295
299
  local dispatched = rawget(self, id)
@@ -327,7 +331,6 @@ local function dispatchAbility(event)
327
331
  return event[id]
328
332
  end
329
333
  if not initialized then
330
- local invoke = Event.invoke
331
334
  event:addListener(function(unit, ability, ...)
332
335
  local dispatched = rawget(self, ability.typeId)
333
336
  if dispatched ~= nil then
@@ -344,6 +347,9 @@ local function dispatchAbility(event)
344
347
  }
345
348
  )
346
349
  end
350
+ local function damagingEventPreventRetaliation(self)
351
+ self[0] = true
352
+ end
347
353
  local function damageEventPreventDeath(self, callback, ...)
348
354
  if self[0] ~= nil then
349
355
  return
@@ -355,7 +361,14 @@ local function damageEventPreventDeath(self, callback, ...)
355
361
  rawset(self, 1 + i, (select(i, ...)))
356
362
  end
357
363
  end
358
- 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
+ }
359
372
  local jlimitopByOperator = {
360
373
  [0] = LESS_THAN_OR_EQUAL,
361
374
  [1] = LESS_THAN_OR_EQUAL,
@@ -399,6 +412,19 @@ function UnitWeapon.prototype.____constructor(self, unit, index)
399
412
  self.unit = unit
400
413
  self.index = index
401
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
+ )
402
428
  __TS__SetDescriptor(
403
429
  UnitWeapon.prototype,
404
430
  "cooldown",
@@ -433,6 +459,19 @@ __TS__SetDescriptor(
433
459
  },
434
460
  true
435
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
+ )
436
475
  __TS__SetDescriptor(
437
476
  UnitWeapon.prototype,
438
477
  "damageBase",
@@ -563,17 +602,6 @@ local function retrieveAbility(unit, ability, abilityId)
563
602
  ____exports.Unit:of(unit)
564
603
  )
565
604
  end
566
- if not unitAddAbility(unit, abilityId) then
567
- if getUnitAbility(unit, abilityId) == ability then
568
- return UnitAbility:of(
569
- ability,
570
- abilityId,
571
- ____exports.Unit:of(unit)
572
- )
573
- end
574
- else
575
- unitRemoveAbility(unit, abilityId)
576
- end
577
605
  for i = 0, unitInventorySize(unit) - 1 do
578
606
  local item = unitItemInSlot(unit, i)
579
607
  if getItemAbility(item, abilityId) == ability then
@@ -631,15 +659,15 @@ for ____, player in ipairs(Player.all) do
631
659
  dummies[player] = dummy
632
660
  end
633
661
  local function delayHealthChecksCallback(unit)
634
- local counter = (unit[102] or 0) - 1
662
+ local counter = (unit[104] or 0) - 1
635
663
  if counter ~= 0 then
636
- unit[102] = counter
664
+ unit[104] = counter
637
665
  return
638
666
  end
639
- unit[102] = nil
640
- local healthBonus = unit[103]
667
+ unit[104] = nil
668
+ local healthBonus = unit[105]
641
669
  if healthBonus ~= nil then
642
- unit[103] = nil
670
+ unit[105] = nil
643
671
  local handle = unit.handle
644
672
  BlzSetUnitMaxHP(
645
673
  handle,
@@ -647,12 +675,27 @@ local function delayHealthChecksCallback(unit)
647
675
  )
648
676
  end
649
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
650
690
  ____exports.Unit = __TS__Class()
651
691
  local Unit = ____exports.Unit
652
692
  Unit.name = "Unit"
653
693
  __TS__ClassExtends(Unit, Handle)
654
694
  function Unit.prototype.____constructor(self, handle)
655
695
  Handle.prototype.____constructor(self, handle)
696
+ local ____nextSyncId_1 = nextSyncId
697
+ nextSyncId = ____nextSyncId_1 + 1
698
+ self.syncId = ____nextSyncId_1
656
699
  self._owner = Player:of(getOwningPlayer(handle))
657
700
  assert(unitAddAbility(handle, leaveDetectAbilityId) and UnitMakeAbilityPermanent(handle, true, leaveDetectAbilityId))
658
701
  assert(unitAddAbility(handle, morphDetectAbilityId))
@@ -665,6 +708,7 @@ function Unit.prototype.____constructor(self, handle)
665
708
  fourCC("Amrf")
666
709
  ))
667
710
  end
711
+ unitBySyncId[self.syncId] = self
668
712
  local ____ = self.abilities
669
713
  end
670
714
  function Unit.prototype.getEvent(self, event, collector)
@@ -683,9 +727,16 @@ function Unit.prototype.getEvent(self, event, collector)
683
727
  end
684
728
  function Unit.prototype.onDestroy(self)
685
729
  local handle = self.handle
730
+ self[108] = getUnitX(handle)
731
+ self[109] = getUnitY(handle)
686
732
  if not self._owner then
687
733
  self._owner = Player:of(getOwningPlayer(handle))
688
734
  end
735
+ local abilities = self.abilities
736
+ for ____, ability in ipairs(abilities) do
737
+ ability:destroy()
738
+ end
739
+ __TS__ArraySetLength(abilities, 0)
689
740
  for ____, player in ipairs(Player.all) do
690
741
  if self:isSelected(player) then
691
742
  Event.invoke(____exports.Unit.onDeselect, self, player)
@@ -700,6 +751,10 @@ function Unit.prototype.onDestroy(self)
700
751
  if eventsToDestroy ~= nil then
701
752
  forEach(eventsToDestroy, "destroy")
702
753
  end
754
+ if getUnitAbilityLevel(handle, leaveDetectAbilityId) > 0 then
755
+ unitRemoveAbility(handle, leaveDetectAbilityId)
756
+ removeUnit(handle)
757
+ end
703
758
  return Handle.prototype.onDestroy(self)
704
759
  end
705
760
  function Unit.prototype.addAttackHandler(self, condition, action)
@@ -741,17 +796,17 @@ function Unit.prototype.addModifier(self, property, modifier)
741
796
  end}
742
797
  end
743
798
  function Unit.prototype.hasCombatClassification(self, combatClassification)
744
- local ____combatClassification_0 = combatClassification
745
- 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
746
801
  end
747
802
  function Unit.prototype.addClassification(self, classification)
748
- return unitAddType(self.handle, classification)
803
+ return UnitAddType(self.handle, classification)
749
804
  end
750
805
  function Unit.prototype.removeClassification(self, classification)
751
- return unitRemoveType(self.handle, classification)
806
+ return UnitRemoveType(self.handle, classification)
752
807
  end
753
808
  function Unit.prototype.hasClassification(self, classification)
754
- return isUnitType(self.handle, classification)
809
+ return IsUnitType(self.handle, classification)
755
810
  end
756
811
  function Unit.prototype.isVisibleTo(self, player)
757
812
  return isUnitVisible(self.handle, player.handle)
@@ -760,13 +815,13 @@ function Unit.prototype.isInvisibleTo(self, player)
760
815
  return isUnitInvisible(self.handle, player.handle)
761
816
  end
762
817
  function Unit.prototype.isInRangeOf(self, x, y, range)
763
- local ____temp_1
818
+ local ____temp_3
764
819
  if type(x) == "number" then
765
- ____temp_1 = isUnitInRangeXY(self.handle, x, y, range)
820
+ ____temp_3 = isUnitInRangeXY(self.handle, x, y, range)
766
821
  else
767
- ____temp_1 = isUnitInRange(self.handle, x.handle, y)
822
+ ____temp_3 = isUnitInRange(self.handle, x.handle, y)
768
823
  end
769
- return ____temp_1
824
+ return ____temp_3
770
825
  end
771
826
  function Unit.prototype.isAllyOf(self, unit)
772
827
  return isUnitAlly(
@@ -784,16 +839,30 @@ function Unit.prototype.playAnimation(self, animation, rarity)
784
839
  if type(animation) == "number" then
785
840
  setUnitAnimationByIndex(self.handle, animation)
786
841
  elseif rarity then
787
- setUnitAnimationWithRarity(self.handle, animation, rarity)
842
+ SetUnitAnimationWithRarity(self.handle, animation, rarity)
788
843
  else
789
844
  setUnitAnimation(self.handle, animation)
790
845
  end
791
846
  end
847
+ function Unit.prototype.resetAnimation(self)
848
+ ResetUnitAnimation(self.handle)
849
+ end
792
850
  function Unit.prototype.queueAnimation(self, animation)
793
- 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
794
863
  end
795
864
  function Unit.prototype.delayHealthChecks(self)
796
- self[102] = (self[102] or 0) + 1
865
+ self[104] = (self[104] or 0) + 1
797
866
  Timer:run(delayHealthChecksCallback, self)
798
867
  end
799
868
  function Unit.prototype.setPosition(self, x, y)
@@ -803,21 +872,21 @@ function Unit.prototype.isSelected(self, player)
803
872
  return IsUnitSelected(self.handle, player.handle)
804
873
  end
805
874
  function Unit.prototype.explode(self)
806
- setUnitExploded(self.handle, true)
875
+ SetUnitExploded(self.handle, true)
807
876
  killUnit(self.handle)
808
877
  end
809
878
  function Unit.prototype.kill(self)
810
879
  killUnit(self.handle)
811
880
  end
812
881
  function Unit.prototype.revive(self, x, y, doEffect)
813
- local ____ReviveHero_4 = ReviveHero
814
- local ____array_3 = __TS__SparseArrayNew(self.handle, x, y)
815
- local ____doEffect_2 = doEffect
816
- if ____doEffect_2 == nil then
817
- ____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
818
887
  end
819
- __TS__SparseArrayPush(____array_3, ____doEffect_2)
820
- ____ReviveHero_4(__TS__SparseArraySpread(____array_3))
888
+ __TS__SparseArrayPush(____array_5, ____doEffect_4)
889
+ ____ReviveHero_6(__TS__SparseArraySpread(____array_5))
821
890
  end
822
891
  function Unit.prototype.healTarget(self, target, amount)
823
892
  if __TS__InstanceOf(target, ____exports.Unit) and target:hasAbility(fourCC("BIhm")) then
@@ -857,20 +926,19 @@ function Unit.prototype.dropItemSlot(self, item, slot)
857
926
  return UnitDropItemSlot(self.handle, item.handle, slot)
858
927
  end
859
928
  function Unit.prototype.itemInSlot(self, slot)
860
- return Item:of(UnitItemInSlot(self.handle, slot))
929
+ return Item:of(unitItemInSlot(self.handle, slot))
861
930
  end
862
931
  function Unit.prototype.addAbility(self, abilityId)
863
- if unitAddAbility(self.handle, abilityId) then
864
- local ability = UnitAbility:of(
865
- checkNotNull(getUnitAbility(self.handle, abilityId)),
866
- abilityId,
867
- self
868
- )
932
+ local ability = UnitAbility:of(
933
+ doUnitAbilityAction(self.handle, abilityId, addAbility, abilityId),
934
+ abilityId,
935
+ self
936
+ )
937
+ if ability ~= nil then
869
938
  local abilities = self.abilities
870
939
  abilities[#abilities + 1] = ability
871
- return ability
872
940
  end
873
- return nil
941
+ return ability
874
942
  end
875
943
  function Unit.prototype.makeAbilityPermanent(self, abilityId, permanent)
876
944
  return UnitMakeAbilityPermanent(self.handle, permanent, abilityId)
@@ -884,31 +952,21 @@ end
884
952
  function Unit.prototype.hasAbility(self, abilityId)
885
953
  return getUnitAbilityLevel(self.handle, abilityId) > 0
886
954
  end
887
- function Unit.prototype.getAbilityById(self, abilityId)
888
- local handle = self.handle
889
- if unitAddAbility(handle, abilityId) then
890
- assert(unitRemoveAbility(handle, abilityId))
891
- return nil
892
- end
893
- return UnitAbility:of(
894
- getUnitAbility(self.handle, abilityId),
895
- abilityId,
896
- self
897
- )
955
+ function Unit.prototype.getAbility(self, abilityId)
956
+ local ability = doUnitAbilityAction(self.handle, abilityId, getUnitAbility, abilityId)
957
+ return UnitAbility:of(ability, abilityId, self)
898
958
  end
899
- function Unit.prototype.removeAbility(self, abilityId)
900
- if unitRemoveAbility(self.handle, abilityId) then
901
- local abilities = self.abilities
902
- for i = 1, #abilities do
903
- if abilities[i].typeId == abilityId then
904
- abilities[i]:destroy()
905
- tremove(abilities, i)
906
- return true
907
- 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
908
967
  end
909
- return true
910
968
  end
911
- return false
969
+ return doUnitAbilityAction(self.handle, abilityTypeId, unitRemoveAbility, abilityTypeId)
912
970
  end
913
971
  function Unit.prototype.hideAbility(self, abilityId, flag)
914
972
  BlzUnitHideAbility(self.handle, abilityId, flag)
@@ -922,12 +980,34 @@ end
922
980
  function Unit.prototype.endAbilityCooldown(self, abilityId)
923
981
  BlzEndUnitAbilityCooldown(self.handle, abilityId)
924
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
925
998
  function Unit.prototype.interruptAttack(self)
926
999
  unitInterruptAttack(self.handle)
927
1000
  end
928
1001
  function Unit.prototype.interruptCast(self, abilityId)
929
- unitDisableAbility(self.handle, abilityId, true, false)
930
- 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
+ )
931
1011
  end
932
1012
  function Unit.prototype.getDistanceTo(self, target)
933
1013
  local handle = self.handle
@@ -987,18 +1067,44 @@ function Unit.prototype.unpauseEx(self)
987
1067
  self:decrementStunCounter()
988
1068
  end
989
1069
  function Unit.prototype.incrementStunCounter(self)
990
- local stunCounter = self[101] or 0
991
- 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
992
1072
  BlzPauseUnitEx(self.handle, true)
993
1073
  end
994
- self[101] = stunCounter + 1
1074
+ self[102] = stunCounter + 1
995
1075
  end
996
1076
  function Unit.prototype.decrementStunCounter(self)
997
- local stunCounter = self[101] or 0
998
- 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
999
1079
  BlzPauseUnitEx(self.handle, false)
1000
1080
  end
1001
- 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
1002
1108
  end
1003
1109
  function Unit.create(self, owner, id, x, y, facing, skinId)
1004
1110
  local handle = skinId and BlzCreateUnitWithSkin(
@@ -1100,8 +1206,11 @@ function Unit.getInSector(self, pos, range, offsetAngle, centralAngle)
1100
1206
  )
1101
1207
  return targetCollection
1102
1208
  end
1103
- function Unit.getSelectionOf(self, player)
1104
- targetCollection = {}
1209
+ function Unit.getSelectionOf(self, player, target)
1210
+ if target == nil then
1211
+ target = {}
1212
+ end
1213
+ targetCollection = target
1105
1214
  targetCollectionNextIndex = 1
1106
1215
  GroupEnumUnitsSelected(dummyGroup, player.handle, collectIntoTarget)
1107
1216
  return targetCollection
@@ -1123,6 +1232,9 @@ end
1123
1232
  function Unit.prototype.__tostring(self)
1124
1233
  return (((self.constructor.name .. "$") .. util.id2s(self.typeId)) .. "@") .. tostring(getHandleId(self.handle))
1125
1234
  end
1235
+ function Unit.getBySyncId(self, syncId)
1236
+ return unitBySyncId[syncId]
1237
+ end
1126
1238
  __TS__SetDescriptor(
1127
1239
  Unit.prototype,
1128
1240
  "_deltas",
@@ -1182,7 +1294,15 @@ __TS__SetDescriptor(
1182
1294
  Unit.prototype,
1183
1295
  "isIllusion",
1184
1296
  {get = function(self)
1185
- 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")
1186
1306
  end},
1187
1307
  true
1188
1308
  )
@@ -1259,6 +1379,19 @@ __TS__SetDescriptor(
1259
1379
  },
1260
1380
  true
1261
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
+ )
1262
1395
  __TS__SetDescriptor(
1263
1396
  Unit.prototype,
1264
1397
  "strengthBase",
@@ -1380,17 +1513,17 @@ __TS__SetDescriptor(
1380
1513
  "isTeamGlowVisible",
1381
1514
  {
1382
1515
  get = function(self)
1383
- return not self[105]
1516
+ return not self[107]
1384
1517
  end,
1385
1518
  set = function(self, isTeamGlowVisible)
1386
- showUnitTeamGlow(self.handle, isTeamGlowVisible)
1387
- local ____temp_5
1519
+ BlzShowUnitTeamGlow(self.handle, isTeamGlowVisible)
1520
+ local ____temp_7
1388
1521
  if not isTeamGlowVisible then
1389
- ____temp_5 = true
1522
+ ____temp_7 = true
1390
1523
  else
1391
- ____temp_5 = nil
1524
+ ____temp_7 = nil
1392
1525
  end
1393
- self[105] = ____temp_5
1526
+ self[107] = ____temp_7
1394
1527
  end
1395
1528
  },
1396
1529
  true
@@ -1399,9 +1532,9 @@ __TS__SetDescriptor(
1399
1532
  Unit.prototype,
1400
1533
  "color",
1401
1534
  {set = function(self, color)
1402
- setUnitColor(self.handle, color.handle)
1403
- if self[105] then
1404
- showUnitTeamGlow(self.handle, false)
1535
+ SetUnitColor(self.handle, color.handle)
1536
+ if self[107] then
1537
+ BlzShowUnitTeamGlow(self.handle, false)
1405
1538
  end
1406
1539
  end},
1407
1540
  true
@@ -1424,14 +1557,14 @@ __TS__SetDescriptor(
1424
1557
  "maxHealth",
1425
1558
  {
1426
1559
  get = function(self)
1427
- 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)
1428
1561
  end,
1429
1562
  set = function(self, maxHealth)
1430
- if maxHealth < 1 and self[102] ~= nil then
1431
- 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)
1432
1565
  maxHealth = 1
1433
1566
  end
1434
- BlzSetUnitMaxHP(self.handle, maxHealth + (self[104] or 0))
1567
+ BlzSetUnitMaxHP(self.handle, maxHealth + (self[106] or 0))
1435
1568
  end
1436
1569
  },
1437
1570
  true
@@ -1473,10 +1606,10 @@ __TS__SetDescriptor(
1473
1606
  "health",
1474
1607
  {
1475
1608
  get = function(self)
1476
- return GetWidgetLife(self.handle) - (self[104] or 0)
1609
+ return GetWidgetLife(self.handle) - (self[106] or 0)
1477
1610
  end,
1478
1611
  set = function(self, health)
1479
- SetWidgetLife(self.handle, health + (self[104] or 0))
1612
+ SetWidgetLife(self.handle, health + (self[106] or 0))
1480
1613
  end
1481
1614
  },
1482
1615
  true
@@ -1570,7 +1703,7 @@ __TS__SetDescriptor(
1570
1703
  "x",
1571
1704
  {
1572
1705
  get = function(self)
1573
- return getUnitX(self.handle)
1706
+ return self[108] or getUnitX(self.handle)
1574
1707
  end,
1575
1708
  set = function(self, v)
1576
1709
  SetUnitX(self.handle, v)
@@ -1583,7 +1716,7 @@ __TS__SetDescriptor(
1583
1716
  "y",
1584
1717
  {
1585
1718
  get = function(self)
1586
- return getUnitY(self.handle)
1719
+ return self[109] or getUnitY(self.handle)
1587
1720
  end,
1588
1721
  set = function(self, v)
1589
1722
  SetUnitY(self.handle, v)
@@ -1669,10 +1802,10 @@ __TS__SetDescriptor(
1669
1802
  "gold",
1670
1803
  {
1671
1804
  get = function(self)
1672
- return getResourceAmount(self.handle)
1805
+ return GetResourceAmount(self.handle)
1673
1806
  end,
1674
1807
  set = function(self, gold)
1675
- setResourceAmount(self.handle, gold)
1808
+ SetResourceAmount(self.handle, gold)
1676
1809
  end
1677
1810
  },
1678
1811
  true
@@ -1687,17 +1820,21 @@ __TS__SetDescriptor(
1687
1820
  set = function(self, isPaused)
1688
1821
  local handle = self.handle
1689
1822
  if isPaused and not IsUnitPaused(handle) then
1690
- self[100] = true
1691
- for _ = self[101] or 0, -1 do
1692
- BlzPauseUnitEx(handle, true)
1823
+ self[101] = true
1824
+ if (self[103] or 0) <= 0 then
1825
+ for _ = self[102] or 0, -1 do
1826
+ BlzPauseUnitEx(handle, true)
1827
+ end
1693
1828
  end
1694
1829
  PauseUnit(handle, true)
1695
1830
  elseif not isPaused and IsUnitPaused(handle) then
1696
1831
  PauseUnit(handle, false)
1697
- for _ = self[101] or 0, -1 do
1698
- BlzPauseUnitEx(handle, false)
1832
+ if (self[103] or 0) <= 0 then
1833
+ for _ = self[102] or 0, -1 do
1834
+ BlzPauseUnitEx(handle, false)
1835
+ end
1699
1836
  end
1700
- self[100] = nil
1837
+ self[101] = nil
1701
1838
  end
1702
1839
  end
1703
1840
  },
@@ -1800,6 +1937,19 @@ __TS__SetDescriptor(
1800
1937
  end},
1801
1938
  true
1802
1939
  )
1940
+ __TS__SetDescriptor(
1941
+ Unit.prototype,
1942
+ "movementType",
1943
+ {
1944
+ get = function(self)
1945
+ return getUnitIntegerField(self.handle, UNIT_IF_MOVE_TYPE)
1946
+ end,
1947
+ set = function(self, movementType)
1948
+ setUnitIntegerField(self.handle, UNIT_IF_MOVE_TYPE, movementType)
1949
+ end
1950
+ },
1951
+ true
1952
+ )
1803
1953
  __TS__SetDescriptor(
1804
1954
  Unit.prototype,
1805
1955
  "pathing",
@@ -1981,6 +2131,14 @@ __TS__SetDescriptor(
1981
2131
  end},
1982
2132
  true
1983
2133
  )
2134
+ __TS__SetDescriptor(
2135
+ Unit.prototype,
2136
+ "targetAcquiredEvent",
2137
+ {get = function(self)
2138
+ return self:getEvent(EVENT_UNIT_ACQUIRED_TARGET)
2139
+ end},
2140
+ true
2141
+ )
1984
2142
  __TS__SetDescriptor(
1985
2143
  Unit.prototype,
1986
2144
  "onSelect",
@@ -2054,7 +2212,6 @@ Unit.onDecay = __TS__New(
2054
2212
  Unit.onResurrect = __TS__New(
2055
2213
  InitializingEvent,
2056
2214
  function(event)
2057
- local invoke = Event.invoke
2058
2215
  local dead = setmetatable({}, {__mode = "k"})
2059
2216
  ____exports.Unit.deathEvent:addListener(function(unit)
2060
2217
  dead[unit] = true
@@ -2070,10 +2227,15 @@ Unit.onResurrect = __TS__New(
2070
2227
  Unit.morphEvent = __TS__New(
2071
2228
  InitializingEvent,
2072
2229
  function(event)
2230
+ local function ifNotLeft(unit)
2231
+ local handle = unit.handle
2232
+ if getUnitAbilityLevel(handle, leaveDetectAbilityId) ~= 0 and unitAddAbility(handle, morphDetectAbilityId) then
2233
+ invoke(event, unit)
2234
+ end
2235
+ end
2073
2236
  ____exports.Unit.onImmediateOrder[orderId("undefend")]:addListener(function(unit)
2074
2237
  if getUnitAbilityLevel(unit.handle, morphDetectAbilityId) == 0 then
2075
- assert(unitAddAbility(unit.handle, morphDetectAbilityId))
2076
- Timer:run(Event.invoke, event, unit)
2238
+ Timer:run(ifNotLeft, unit)
2077
2239
  end
2078
2240
  end)
2079
2241
  end
@@ -2111,27 +2273,26 @@ Unit.onSpellEffect = dispatchId(__TS__New(
2111
2273
  Unit.onTargetCast = dispatchId(__TS__New(
2112
2274
  InitializingEvent,
2113
2275
  function(event)
2114
- local invoke = Event.invoke
2115
2276
  local function listener(unit, id)
2116
- local ____GetSpellTargetUnit_result_8
2277
+ local ____GetSpellTargetUnit_result_10
2117
2278
  if GetSpellTargetUnit() then
2118
- ____GetSpellTargetUnit_result_8 = ____exports.Unit:of(GetSpellTargetUnit())
2279
+ ____GetSpellTargetUnit_result_10 = ____exports.Unit:of(GetSpellTargetUnit())
2119
2280
  else
2120
- local ____GetSpellTargetItem_result_7
2281
+ local ____GetSpellTargetItem_result_9
2121
2282
  if GetSpellTargetItem() then
2122
- ____GetSpellTargetItem_result_7 = Item:of(GetSpellTargetItem())
2283
+ ____GetSpellTargetItem_result_9 = Item:of(GetSpellTargetItem())
2123
2284
  else
2124
- local ____GetSpellTargetDestructable_result_6
2285
+ local ____GetSpellTargetDestructable_result_8
2125
2286
  if GetSpellTargetDestructable() then
2126
- ____GetSpellTargetDestructable_result_6 = Destructable:of(GetSpellTargetDestructable())
2287
+ ____GetSpellTargetDestructable_result_8 = Destructable:of(GetSpellTargetDestructable())
2127
2288
  else
2128
- ____GetSpellTargetDestructable_result_6 = nil
2289
+ ____GetSpellTargetDestructable_result_8 = nil
2129
2290
  end
2130
- ____GetSpellTargetItem_result_7 = ____GetSpellTargetDestructable_result_6
2291
+ ____GetSpellTargetItem_result_9 = ____GetSpellTargetDestructable_result_8
2131
2292
  end
2132
- ____GetSpellTargetUnit_result_8 = ____GetSpellTargetItem_result_7
2293
+ ____GetSpellTargetUnit_result_10 = ____GetSpellTargetItem_result_9
2133
2294
  end
2134
- local target = ____GetSpellTargetUnit_result_8
2295
+ local target = ____GetSpellTargetUnit_result_10
2135
2296
  if target then
2136
2297
  invoke(event, unit, id, target)
2137
2298
  end
@@ -2303,10 +2464,12 @@ Unit.onImmediateOrder = dispatchId(__TS__New(
2303
2464
  ____exports.UnitTriggerEvent,
2304
2465
  EVENT_PLAYER_UNIT_ISSUED_ORDER,
2305
2466
  function()
2306
- local unit = ____exports.Unit:of(getOrderedUnit())
2307
- local issuedOrderId = getIssuedOrderId()
2308
- if unit ~= nil and unit.state == 1 then
2309
- return unit, issuedOrderId
2467
+ local handle = getOrderedUnit()
2468
+ if handle ~= nil and getUnitTypeId(handle) ~= dummyUnitId then
2469
+ local unit = ____exports.Unit:of(handle)
2470
+ if unit.state == 1 then
2471
+ return unit, getIssuedOrderId()
2472
+ end
2310
2473
  end
2311
2474
  return IgnoreEvent
2312
2475
  end
@@ -2328,7 +2491,6 @@ Unit.autoAttackStartEvent = __TS__New(
2328
2491
  )
2329
2492
  Unit.onDamaging = (function()
2330
2493
  local event = __TS__New(Event)
2331
- local invoke = Event.invoke
2332
2494
  local trigger = CreateTrigger()
2333
2495
  TriggerRegisterAnyUnitEventBJ(trigger, EVENT_PLAYER_UNIT_DAMAGING)
2334
2496
  TriggerAddCondition(
@@ -2338,38 +2500,57 @@ Unit.onDamaging = (function()
2338
2500
  if source and source.typeId == dummyUnitId then
2339
2501
  source = nil
2340
2502
  end
2341
- local target = BlzGetEventDamageTarget()
2503
+ local target = ____exports.Unit:of(BlzGetEventDamageTarget())
2504
+ local metadata = damageMetadataByTarget[target]
2505
+ damageMetadataByTarget[target] = nil
2342
2506
  local data = {
2343
2507
  amount = GetEventDamage(),
2344
- attackType = BlzGetEventAttackType(),
2508
+ attackType = nativeToAttackType(BlzGetEventAttackType()),
2345
2509
  damageType = BlzGetEventDamageType(),
2346
2510
  weaponType = BlzGetEventWeaponType(),
2347
- isAttack = BlzGetEventIsAttack()
2511
+ metadata = metadata,
2512
+ isAttack = BlzGetEventIsAttack(),
2513
+ originalAmount = GetEventDamage(),
2514
+ originalMetadata = metadata,
2515
+ preventRetaliation = damagingEventPreventRetaliation
2348
2516
  }
2349
2517
  if data.isAttack and source then
2350
- 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
2351
- if weapon == -1 then
2352
- local targetsAllowed = BlzGetUnitWeaponIntegerField(source.handle, UNIT_WEAPON_IF_ATTACK_TARGETS_ALLOWED, 0)
2353
- weapon = 0
2354
- end
2355
- data.weapon = assert(source.weapons[weapon + 1])
2518
+ data.weapon = source:chooseWeapon(target)
2356
2519
  end
2357
2520
  if not data.isAttack or not source or not source._attackHandlers then
2358
2521
  invoke(
2359
2522
  event,
2360
2523
  source,
2361
- ____exports.Unit:of(target),
2524
+ target,
2362
2525
  setmetatable(
2363
2526
  {},
2364
2527
  {
2365
2528
  __index = data,
2366
2529
  __newindex = function(self, key, value)
2367
- damageSetters[key](value)
2530
+ local damageSetter = damageSetters[key]
2531
+ if damageSetter ~= nil then
2532
+ damageSetter(value)
2533
+ end
2368
2534
  data[key] = value
2369
2535
  end
2370
2536
  }
2371
2537
  )
2372
2538
  )
2539
+ if data[0] and source then
2540
+ local sourceOwner = source.owner.handle
2541
+ data[1] = sourceOwner
2542
+ local targetOwner = target.owner.handle
2543
+ data[2] = targetOwner
2544
+ if not GetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE) then
2545
+ SetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE, true)
2546
+ data[3] = true
2547
+ end
2548
+ if not GetPlayerAlliance(targetOwner, sourceOwner, ALLIANCE_PASSIVE) then
2549
+ SetPlayerAlliance(targetOwner, sourceOwner, ALLIANCE_PASSIVE, true)
2550
+ data[4] = true
2551
+ end
2552
+ end
2553
+ damagingEventByTarget[target] = data
2373
2554
  return
2374
2555
  end
2375
2556
  BlzSetEventDamage(0)
@@ -2377,7 +2558,7 @@ Unit.onDamaging = (function()
2377
2558
  BlzSetEventDamageType(DAMAGE_TYPE_UNKNOWN)
2378
2559
  BlzSetEventWeaponType(WEAPON_TYPE_WHOKNOWS)
2379
2560
  local sourceOwner = source.owner.handle
2380
- local targetOwner = GetOwningPlayer(target)
2561
+ local targetOwner = target.owner.handle
2381
2562
  if not GetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE) then
2382
2563
  SetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE, true)
2383
2564
  Timer:run(function()
@@ -2393,23 +2574,19 @@ Unit.onDamaging = (function()
2393
2574
  for ____, ____value in ipairs(source._attackHandlers) do
2394
2575
  local condition = ____value[1]
2395
2576
  local action = ____value[2]
2396
- if condition(
2397
- source,
2398
- ____exports.Unit:of(target),
2399
- data
2400
- ) then
2577
+ if condition(source, target, data) then
2401
2578
  action(
2402
2579
  source,
2403
- ____exports.Unit:of(target),
2580
+ target,
2404
2581
  setmetatable(
2405
2582
  {fire = function()
2406
2583
  UnitDamageTarget(
2407
2584
  source.handle,
2408
- target,
2585
+ target.handle,
2409
2586
  data.amount,
2410
2587
  true,
2411
2588
  true,
2412
- data.attackType,
2589
+ attackTypeToNative(data.attackType),
2413
2590
  data.damageType,
2414
2591
  data.weaponType
2415
2592
  )
@@ -2427,7 +2604,6 @@ end)()
2427
2604
  Unit.onDamage = __TS__New(
2428
2605
  InitializingEvent,
2429
2606
  function(event)
2430
- local invoke = Event.invoke
2431
2607
  local trigger = CreateTrigger()
2432
2608
  TriggerRegisterAnyUnitEventBJ(trigger, EVENT_PLAYER_UNIT_DAMAGED)
2433
2609
  TriggerAddCondition(
@@ -2437,29 +2613,54 @@ Unit.onDamage = __TS__New(
2437
2613
  if source and source.typeId == dummyUnitId then
2438
2614
  source = nil
2439
2615
  end
2616
+ local target = ____exports.Unit:of(BlzGetEventDamageTarget())
2617
+ local damagingEvent = damagingEventByTarget[target]
2618
+ damagingEventByTarget[target] = nil
2440
2619
  local data = {
2441
2620
  amount = GetEventDamage(),
2442
- attackType = BlzGetEventAttackType(),
2621
+ attackType = nativeToAttackType(BlzGetEventAttackType()),
2443
2622
  damageType = BlzGetEventDamageType(),
2444
2623
  weaponType = BlzGetEventWeaponType(),
2624
+ metadata = damagingEvent and damagingEvent.metadata,
2445
2625
  isAttack = BlzGetEventIsAttack(),
2626
+ originalAmount = damagingEvent and damagingEvent.originalAmount or GetEventDamage(),
2627
+ originalMetadata = damagingEvent and damagingEvent.originalMetadata,
2446
2628
  preventDeath = damageEventPreventDeath
2447
2629
  }
2630
+ if damagingEvent then
2631
+ for key, value in pairs(damagingEvent) do
2632
+ if isAttribute(key) then
2633
+ data[key] = value
2634
+ end
2635
+ end
2636
+ local sourceOwner = damagingEvent[1]
2637
+ if sourceOwner then
2638
+ local targetOwner = damagingEvent[2]
2639
+ if damagingEvent[3] then
2640
+ SetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE, false)
2641
+ end
2642
+ if damagingEvent[4] then
2643
+ SetPlayerAlliance(targetOwner, sourceOwner, ALLIANCE_PASSIVE, false)
2644
+ end
2645
+ end
2646
+ end
2448
2647
  local evData = setmetatable(
2449
2648
  {},
2450
2649
  {
2451
2650
  __index = data,
2452
2651
  __newindex = function(self, key, value)
2453
- damageSetters[key](value)
2652
+ local damageSetter = damageSetters[key]
2653
+ if damageSetter ~= nil then
2654
+ damageSetter(value)
2655
+ end
2454
2656
  data[key] = value
2455
2657
  end
2456
2658
  }
2457
2659
  )
2458
- local target = ____exports.Unit:of(BlzGetEventDamageTarget())
2459
2660
  invoke(event, source, target, evData)
2460
2661
  if evData[0] ~= nil and target.health - evData.amount < 0.405 then
2461
2662
  local bonusHealth = math.ceil(evData.amount)
2462
- target[104] = (target[104] or 0) + bonusHealth
2663
+ target[106] = (target[106] or 0) + bonusHealth
2463
2664
  BlzSetUnitMaxHP(
2464
2665
  target.handle,
2465
2666
  BlzGetUnitMaxHP(target.handle) + bonusHealth
@@ -2473,7 +2674,7 @@ Unit.onDamage = __TS__New(
2473
2674
  evData[0],
2474
2675
  table.unpack(evData, 1 + 1, 1 + (evData[1] or 0))
2475
2676
  )
2476
- target[104] = (target[104] or 0) - bonusHealth
2677
+ target[106] = (target[106] or 0) - bonusHealth
2477
2678
  SetWidgetLife(
2478
2679
  target.handle,
2479
2680
  GetWidgetLife(target.handle) - bonusHealth
@@ -2493,32 +2694,110 @@ Unit.onDamage = __TS__New(
2493
2694
  DestroyTrigger(trigger)
2494
2695
  end
2495
2696
  )
2496
- Unit.onItemDrop = __TS__New(
2697
+ Unit.itemDroppedEvent = __TS__New(
2497
2698
  ____exports.UnitTriggerEvent,
2498
2699
  EVENT_PLAYER_UNIT_DROP_ITEM,
2499
2700
  function()
2500
2701
  local unit = getTriggerUnit()
2501
- if getUnitTypeId(unit) ~= dummyUnitId then
2502
- return ____exports.Unit:of(unit), Item:of(getManipulatedItem())
2702
+ local item = getManipulatedItem()
2703
+ if getUnitTypeId(unit) ~= dummyUnitId and not (ignoreEventsItems[item] ~= nil) then
2704
+ return ____exports.Unit:of(unit), Item:of(item)
2503
2705
  end
2504
2706
  return IgnoreEvent
2505
2707
  end
2506
2708
  )
2507
- Unit.onItemPickup = __TS__New(
2709
+ Unit.itemPickedUpEvent = __TS__New(
2508
2710
  ____exports.UnitTriggerEvent,
2509
2711
  EVENT_PLAYER_UNIT_PICKUP_ITEM,
2510
2712
  function()
2511
- local unit = getTriggerUnit()
2512
- if getUnitTypeId(unit) ~= dummyUnitId then
2513
- return ____exports.Unit:of(unit), Item:of(getManipulatedItem())
2713
+ local unitHandle = getTriggerUnit()
2714
+ local itemHandle = getManipulatedItem()
2715
+ if getUnitTypeId(unitHandle) ~= dummyUnitId and not (ignoreEventsItems[itemHandle] ~= nil) then
2716
+ local unit = ____exports.Unit:of(unitHandle)
2717
+ local item = Item:of(itemHandle)
2718
+ if item.owner ~= unit then
2719
+ return unit, item
2720
+ end
2514
2721
  end
2515
2722
  return IgnoreEvent
2516
2723
  end
2517
2724
  )
2518
- Unit.onItemUse = __TS__New(
2725
+ Unit.itemUsedEvent = __TS__New(
2519
2726
  ____exports.UnitTriggerEvent,
2520
2727
  EVENT_PLAYER_UNIT_USE_ITEM,
2521
- function() return ____exports.Unit:of(GetTriggerUnit()), Item:of(GetManipulatedItem()) end
2728
+ function()
2729
+ local unit = getTriggerUnit()
2730
+ local item = getManipulatedItem()
2731
+ if getUnitTypeId(unit) ~= dummyUnitId and not (ignoreEventsItems[item] ~= nil) then
2732
+ return ____exports.Unit:of(unit), Item:of(item)
2733
+ end
2734
+ return IgnoreEvent
2735
+ end
2736
+ )
2737
+ Unit.itemStackedEvent = __TS__New(
2738
+ ____exports.UnitTriggerEvent,
2739
+ EVENT_PLAYER_UNIT_STACK_ITEM,
2740
+ function() return ____exports.Unit:of(getTriggerUnit()), Item:of(BlzGetStackingItemTarget()), Item:of(BlzGetStackingItemSource()) end
2741
+ )
2742
+ __TS__ObjectDefineProperty(
2743
+ Unit,
2744
+ "itemChargesChangedEvent",
2745
+ {get = function(self)
2746
+ local event = __TS__New(Event)
2747
+ Item.chargesChangedEvent:addListener(function(item)
2748
+ local unit = item.owner
2749
+ if unit ~= nil then
2750
+ invoke(event, unit, item)
2751
+ end
2752
+ end)
2753
+ rawset(self, "itemChargesChangedEvent", event)
2754
+ return event
2755
+ end}
2756
+ )
2757
+ __TS__ObjectDefineProperty(
2758
+ Unit,
2759
+ "itemUseOrderEvent",
2760
+ {get = function(self)
2761
+ local event = __TS__New(Event)
2762
+ for order = orderId("useslot0"), orderId("useslot5") do
2763
+ local slot = order - orderId("useslot0")
2764
+ local function listener(unit)
2765
+ local item = unit.items[slot + 1]
2766
+ if item ~= nil then
2767
+ invoke(event, unit, item)
2768
+ end
2769
+ end
2770
+ self.onImmediateOrder[order]:addListener(listener)
2771
+ self.onTargetOrder[order]:addListener(listener)
2772
+ self.onPointOrder[order]:addListener(listener)
2773
+ end
2774
+ rawset(self, "itemUseOrderEvent", event)
2775
+ return event
2776
+ end}
2777
+ )
2778
+ __TS__ObjectDefineProperty(
2779
+ Unit,
2780
+ "itemMoveOrderEvent",
2781
+ {get = function(self)
2782
+ local event = __TS__New(Event)
2783
+ for order = orderId("moveslot0"), orderId("moveslot5") do
2784
+ local slotTo = order - orderId("moveslot0")
2785
+ self.onTargetOrder[order]:addListener(function(unit, item)
2786
+ local slotFrom = unit.items:findSlot(item)
2787
+ if slotFrom ~= nil then
2788
+ invoke(
2789
+ event,
2790
+ unit,
2791
+ item,
2792
+ slotFrom,
2793
+ slotTo
2794
+ )
2795
+ end
2796
+ end)
2797
+ end
2798
+ rawset(self, "itemMoveOrderEvent", event)
2799
+ return event
2800
+ end}
2522
2801
  )
2523
2802
  __TS__ObjectDefineProperty(
2524
2803
  Unit,
@@ -2545,6 +2824,10 @@ __TS__ObjectDefineProperty(
2545
2824
  rawset(self, "destroyEvent", destroyEvent)
2546
2825
  return destroyEvent
2547
2826
  end}
2827
+ )
2828
+ Unit.synchronize = synchronizer(
2829
+ function(unit) return unit.syncId end,
2830
+ function(syncId) return unitBySyncId[syncId] end
2548
2831
  );
2549
2832
  (function(self)
2550
2833
  local leaveAbilityIds = postcompile(function()
@@ -2567,6 +2850,15 @@ __TS__ObjectDefineProperty(
2567
2850
  orderId("magicundefense"),
2568
2851
  orderId("unimmolation")
2569
2852
  }) do
2853
+ ____exports.Unit.onImmediateOrder[leaveOrderId]:addListener(function(unit)
2854
+ local handle = unit.handle
2855
+ for i = 1, #leaveAbilityIds do
2856
+ if getUnitAbilityLevel(handle, leaveAbilityIds[i]) ~= 0 then
2857
+ return
2858
+ end
2859
+ end
2860
+ unit:destroy()
2861
+ end)
2570
2862
  end
2571
2863
  end)(Unit)
2572
2864
  return ____exports