warscript 0.0.1-dev.8a238c4 → 0.0.1-dev.8a25bb1

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 (220) hide show
  1. package/attributes.d.ts +5 -1
  2. package/attributes.lua +8 -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 -1
  10. package/core/types/frame.lua +93 -1
  11. package/core/types/group.d.ts +0 -1
  12. package/core/types/image.d.ts +0 -1
  13. package/core/types/missile.d.ts +2 -2
  14. package/core/types/missile.lua +8 -2
  15. package/core/types/sound.d.ts +17 -24
  16. package/core/types/sound.lua +99 -24
  17. package/core/types/timer.d.ts +6 -7
  18. package/core/types/timer.lua +18 -21
  19. package/core/types/unit.lua +8 -0
  20. package/core/util.d.ts +1 -1
  21. package/core/util.lua +18 -1
  22. package/decl/index.d.ts +1 -0
  23. package/decl/native.d.ts +840 -786
  24. package/engine/ability.d.ts +1 -1
  25. package/engine/behavior.d.ts +10 -10
  26. package/engine/behavior.lua +6 -6
  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.d.ts +6 -1
  32. package/engine/behaviour/ability/apply-unit-behavior.lua +1 -0
  33. package/engine/behaviour/ability/damage.d.ts +39 -11
  34. package/engine/behaviour/ability/damage.lua +83 -37
  35. package/engine/behaviour/ability/emulate-impact.d.ts +6 -0
  36. package/engine/behaviour/ability/emulate-impact.lua +35 -0
  37. package/engine/behaviour/ability/heal.d.ts +33 -6
  38. package/engine/behaviour/ability/heal.lua +89 -10
  39. package/engine/behaviour/ability/instant-impact.d.ts +2 -2
  40. package/engine/behaviour/ability/instant-impact.lua +4 -19
  41. package/engine/behaviour/ability/on-command-impact.d.ts +8 -0
  42. package/engine/behaviour/ability/on-command-impact.lua +25 -0
  43. package/engine/behaviour/ability/remove-buffs.d.ts +16 -0
  44. package/engine/behaviour/ability/remove-buffs.lua +28 -0
  45. package/engine/behaviour/ability/restore-mana.d.ts +15 -0
  46. package/engine/behaviour/ability/restore-mana.lua +29 -0
  47. package/engine/behaviour/ability.d.ts +27 -4
  48. package/engine/behaviour/ability.lua +152 -17
  49. package/engine/behaviour/unit/stun-immunity.d.ts +0 -1
  50. package/engine/behaviour/unit.d.ts +10 -2
  51. package/engine/behaviour/unit.lua +27 -0
  52. package/engine/buff.d.ts +103 -41
  53. package/engine/buff.lua +465 -212
  54. package/engine/game-map.d.ts +7 -0
  55. package/engine/game-map.lua +32 -0
  56. package/engine/internal/ability.d.ts +16 -13
  57. package/engine/internal/ability.lua +80 -76
  58. package/engine/internal/item/ability.lua +106 -0
  59. package/engine/internal/item+owner.lua +2 -2
  60. package/engine/internal/item.d.ts +4 -3
  61. package/engine/internal/item.lua +56 -25
  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/object-data/auto-attack-speed-increase.d.ts +1 -1
  68. package/engine/internal/object-data/auto-attack-speed-increase.lua +2 -0
  69. package/engine/internal/object-data/evasion-probability.d.ts +2 -0
  70. package/engine/internal/object-data/evasion-probability.lua +16 -0
  71. package/engine/internal/unit/ability.d.ts +10 -1
  72. package/engine/internal/unit/ability.lua +36 -14
  73. package/engine/internal/unit/add-item-to-slot-init.d.ts +2 -0
  74. package/engine/internal/unit/add-item-to-slot-init.lua +23 -0
  75. package/engine/internal/unit/add-item-to-slot.d.ts +2 -0
  76. package/engine/internal/unit/add-item-to-slot.lua +52 -0
  77. package/engine/internal/unit/bonus.d.ts +11 -8
  78. package/engine/internal/unit/bonus.lua +23 -1
  79. package/engine/internal/unit/ignore-events-items.d.ts +2 -0
  80. package/engine/internal/unit/ignore-events-items.lua +5 -0
  81. package/engine/internal/unit/item.d.ts +24 -0
  82. package/engine/internal/unit/item.lua +78 -0
  83. package/engine/internal/unit/main-selected.d.ts +13 -0
  84. package/engine/internal/unit/main-selected.lua +51 -0
  85. package/engine/internal/unit+ability.lua +2 -2
  86. package/engine/internal/unit+damage.d.ts +2 -11
  87. package/engine/internal/unit+damage.lua +10 -14
  88. package/engine/internal/unit+spellSteal.lua +1 -2
  89. package/engine/internal/unit+transport.lua +4 -10
  90. package/engine/internal/unit-missile-launch.lua +24 -5
  91. package/engine/internal/unit.d.ts +46 -14
  92. package/engine/internal/unit.lua +277 -121
  93. package/engine/internal/utility.lua +12 -0
  94. package/engine/lightning.d.ts +12 -5
  95. package/engine/lightning.lua +48 -14
  96. package/engine/local-client.d.ts +7 -2
  97. package/engine/local-client.lua +82 -0
  98. package/engine/object-data/auxiliary/animation-name.d.ts +1 -0
  99. package/engine/object-data/auxiliary/animation-name.lua +16 -0
  100. package/engine/object-data/auxiliary/attachment-preset.d.ts +7 -3
  101. package/engine/object-data/auxiliary/attachment-preset.lua +4 -3
  102. package/engine/object-data/auxiliary/attack-type.d.ts +7 -8
  103. package/engine/object-data/auxiliary/attack-type.lua +42 -0
  104. package/engine/object-data/auxiliary/combat-classification.d.ts +0 -2
  105. package/engine/object-data/auxiliary/movement-type.d.ts +7 -7
  106. package/engine/object-data/auxiliary/movement-type.lua +22 -0
  107. package/engine/object-data/auxiliary/sound-eax.d.ts +10 -0
  108. package/engine/object-data/auxiliary/sound-eax.lua +2 -0
  109. package/engine/object-data/auxiliary/sound-preset-name.d.ts +5 -1
  110. package/engine/object-data/auxiliary/tech-tree-dependency.d.ts +1 -1
  111. package/engine/object-data/auxiliary/unit-attribute.d.ts +6 -0
  112. package/engine/object-data/auxiliary/unit-attribute.lua +9 -0
  113. package/engine/object-data/entry/ability-type/berserk.d.ts +2 -0
  114. package/engine/object-data/entry/ability-type/berserk.lua +13 -0
  115. package/engine/object-data/entry/ability-type/blank-configurable.d.ts +0 -1
  116. package/engine/object-data/entry/ability-type/blank-configurable.lua +12 -1
  117. package/engine/object-data/entry/ability-type/blank-passive.d.ts +0 -1
  118. package/engine/object-data/entry/ability-type/carrion-swarm.d.ts +14 -0
  119. package/engine/object-data/entry/ability-type/carrion-swarm.lua +65 -0
  120. package/engine/object-data/entry/ability-type/channel.d.ts +0 -1
  121. package/engine/object-data/entry/ability-type/disease-cloud.lua +2 -2
  122. package/engine/object-data/entry/ability-type/engineering-upgrade.lua +2 -2
  123. package/engine/object-data/entry/ability-type/ensnare.d.ts +12 -0
  124. package/engine/object-data/entry/ability-type/ensnare.lua +52 -0
  125. package/engine/object-data/entry/ability-type/feral-spirit.lua +2 -2
  126. package/engine/object-data/entry/ability-type/permanent-invisibility.d.ts +8 -0
  127. package/engine/object-data/entry/ability-type/permanent-invisibility.lua +26 -0
  128. package/engine/object-data/entry/ability-type/phase-shift.d.ts +10 -0
  129. package/engine/object-data/entry/ability-type/phase-shift.lua +39 -0
  130. package/engine/object-data/entry/ability-type/phoenix-morph.lua +4 -4
  131. package/engine/object-data/entry/ability-type/raise-dead.d.ts +17 -0
  132. package/engine/object-data/entry/ability-type/raise-dead.lua +78 -0
  133. package/engine/object-data/entry/ability-type/shock-wave.d.ts +4 -0
  134. package/engine/object-data/entry/ability-type/shock-wave.lua +26 -0
  135. package/engine/object-data/entry/ability-type/slow-poison.d.ts +10 -0
  136. package/engine/object-data/entry/ability-type/slow-poison.lua +58 -0
  137. package/engine/object-data/entry/ability-type/summon-quilbeast.lua +2 -2
  138. package/engine/object-data/entry/ability-type/summon-water-elemental.lua +2 -2
  139. package/engine/object-data/entry/ability-type/web.d.ts +12 -0
  140. package/engine/object-data/entry/ability-type/web.lua +52 -0
  141. package/engine/object-data/entry/ability-type.d.ts +19 -18
  142. package/engine/object-data/entry/ability-type.lua +89 -33
  143. package/engine/object-data/entry/buff-type/applicable.d.ts +0 -1
  144. package/engine/object-data/entry/buff-type/applicable.lua +18 -37
  145. package/engine/object-data/entry/buff-type/blank.d.ts +0 -1
  146. package/engine/object-data/entry/buff-type.d.ts +6 -13
  147. package/engine/object-data/entry/buff-type.lua +13 -29
  148. package/engine/object-data/entry/destructible-type.d.ts +1 -2
  149. package/engine/object-data/entry/item-type/blank.d.ts +0 -1
  150. package/engine/object-data/entry/item-type.d.ts +15 -2
  151. package/engine/object-data/entry/item-type.lua +93 -2
  152. package/engine/object-data/entry/lightning-type.d.ts +1 -2
  153. package/engine/object-data/entry/sound-preset.d.ts +33 -0
  154. package/engine/object-data/entry/sound-preset.lua +140 -0
  155. package/engine/object-data/entry/unit-type.d.ts +10 -4
  156. package/engine/object-data/entry/unit-type.lua +155 -92
  157. package/engine/object-data/entry/upgrade/blank.d.ts +0 -1
  158. package/engine/object-data/entry/upgrade.d.ts +1 -2
  159. package/engine/object-data/entry/upgrade.lua +4 -4
  160. package/engine/object-data/entry.d.ts +18 -17
  161. package/engine/object-data/entry.lua +60 -32
  162. package/engine/object-data/utility/object-data-entry-id-generator.lua +7 -0
  163. package/engine/object-field/ability.d.ts +26 -3
  164. package/engine/object-field/ability.lua +54 -1
  165. package/engine/object-field/unit.d.ts +46 -3
  166. package/engine/object-field/unit.lua +173 -7
  167. package/engine/object-field.d.ts +11 -4
  168. package/engine/object-field.lua +162 -76
  169. package/engine/random.d.ts +1 -0
  170. package/engine/random.lua +9 -0
  171. package/engine/standard/entries/buff-type.d.ts +3 -0
  172. package/engine/standard/entries/buff-type.lua +3 -0
  173. package/engine/standard/entries/sound-preset.d.ts +10 -0
  174. package/engine/standard/entries/sound-preset.lua +10 -0
  175. package/engine/standard/fields/ability.d.ts +3 -1
  176. package/engine/standard/fields/ability.lua +3 -1
  177. package/engine/unit.d.ts +3 -0
  178. package/engine/unit.lua +12 -2
  179. package/event.d.ts +2 -3
  180. package/event.lua +9 -5
  181. package/index.d.ts +1 -0
  182. package/index.lua +1 -0
  183. package/lualib_bundle.lua +146 -42
  184. package/math/vec2.d.ts +2 -9
  185. package/math.d.ts +0 -2
  186. package/net/socket.d.ts +7 -1
  187. package/net/socket.lua +45 -4
  188. package/network.d.ts +1 -0
  189. package/network.lua +3 -2
  190. package/objutil/ability.d.ts +0 -1
  191. package/objutil/buff.d.ts +0 -1
  192. package/objutil/buff.lua +2 -3
  193. package/objutil/object.d.ts +0 -1
  194. package/objutil/unit.d.ts +0 -1
  195. package/objutil/unit.lua +8 -0
  196. package/package.json +13 -13
  197. package/patch-lua.d.ts +0 -0
  198. package/patch-lua.lua +10 -0
  199. package/property.d.ts +55 -0
  200. package/property.lua +374 -0
  201. package/string.d.ts +16 -0
  202. package/string.lua +5 -0
  203. package/util/stream.d.ts +0 -1
  204. package/utility/arrays.d.ts +12 -5
  205. package/utility/arrays.lua +37 -3
  206. package/utility/bit-set.d.ts +0 -2
  207. package/utility/functions.d.ts +1 -0
  208. package/utility/functions.lua +1 -0
  209. package/utility/lazy.d.ts +2 -0
  210. package/utility/lazy.lua +14 -0
  211. package/utility/linked-set.d.ts +12 -3
  212. package/utility/linked-set.lua +8 -2
  213. package/utility/lua-maps.d.ts +4 -2
  214. package/utility/lua-maps.lua +16 -0
  215. package/utility/lua-sets.d.ts +2 -2
  216. package/utility/lua-sets.lua +3 -0
  217. package/utility/reflection.lua +11 -7
  218. package/utility/types.d.ts +1 -0
  219. package/core/mapbounds.d.ts +0 -8
  220. package/core/mapbounds.lua +0 -12
@@ -7,6 +7,9 @@ local __TS__Class = ____lualib.__TS__Class
7
7
  local __TS__ClassExtends = ____lualib.__TS__ClassExtends
8
8
  local __TS__SetDescriptor = ____lualib.__TS__SetDescriptor
9
9
  local __TS__ArraySetLength = ____lualib.__TS__ArraySetLength
10
+ local __TS__SparseArrayNew = ____lualib.__TS__SparseArrayNew
11
+ local __TS__SparseArrayPush = ____lualib.__TS__SparseArrayPush
12
+ local __TS__SparseArraySpread = ____lualib.__TS__SparseArraySpread
10
13
  local __TS__InstanceOf = ____lualib.__TS__InstanceOf
11
14
  local __TS__ObjectDefineProperty = ____lualib.__TS__ObjectDefineProperty
12
15
  local Set = ____lualib.Set
@@ -48,12 +51,19 @@ local ____arrays = require("utility.arrays")
48
51
  local forEach = ____arrays.forEach
49
52
  local ____math = require("math")
50
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
51
63
  local match = string.match
52
64
  local ____tostring = _G.tostring
53
65
  local setUnitAnimation = SetUnitAnimation
54
- local setUnitAnimationWithRarity = SetUnitAnimationWithRarity
55
66
  local setUnitAnimationByIndex = SetUnitAnimationByIndex
56
- local queueUnitAnimation = QueueUnitAnimation
57
67
  local getUnitIntegerField = BlzGetUnitIntegerField
58
68
  local getUnitRealField = BlzGetUnitRealField
59
69
  local getHeroStr = GetHeroStr
@@ -72,9 +82,9 @@ local setUnitScale = SetUnitScale
72
82
  local setUnitPosition = SetUnitPosition
73
83
  local setUnitTimeScale = SetUnitTimeScale
74
84
  local getHandleId = GetHandleId
85
+ local getUnitCurrentOrder = GetUnitCurrentOrder
75
86
  local createUnit = CreateUnit
76
87
  local killUnit = KillUnit
77
- local setUnitExploded = SetUnitExploded
78
88
  local removeUnit = RemoveUnit
79
89
  local getUnitTypeId = GetUnitTypeId
80
90
  local isHeroUnitId = IsHeroUnitId
@@ -90,8 +100,6 @@ local getSpellTargetItem = GetSpellTargetItem
90
100
  local getSpellTargetDestructable = GetSpellTargetDestructable
91
101
  local isUnitInRangeXY = IsUnitInRangeXY
92
102
  local isUnitInRange = IsUnitInRange
93
- local setResourceAmount = SetResourceAmount
94
- local getResourceAmount = GetResourceAmount
95
103
  local getUnitWeaponRealField = BlzGetUnitWeaponRealField
96
104
  local setUnitWeaponRealField = BlzSetUnitWeaponRealField
97
105
  local getUnitWeaponStringField = BlzGetUnitWeaponStringField
@@ -122,8 +130,6 @@ local isUnitType = IsUnitType
122
130
  local isUnitAlly = IsUnitAlly
123
131
  local isUnitEnemy = IsUnitEnemy
124
132
  local getOwningPlayer = GetOwningPlayer
125
- local setUnitColor = SetUnitColor
126
- local showUnitTeamGlow = BlzShowUnitTeamGlow
127
133
  ____exports.UnitClassification = {}
128
134
  local UnitClassification = ____exports.UnitClassification
129
135
  do
@@ -133,6 +139,7 @@ do
133
139
  UnitClassification.GROUND = UNIT_TYPE_GROUND
134
140
  UnitClassification.SUMMONED = UNIT_TYPE_SUMMONED
135
141
  UnitClassification.MECHANICAL = UNIT_TYPE_MECHANICAL
142
+ UnitClassification.WORKER = UNIT_TYPE_PEON
136
143
  UnitClassification.ANCIENT = UNIT_TYPE_ANCIENT
137
144
  UnitClassification.SUICIDAL = UNIT_TYPE_SAPPER
138
145
  UnitClassification.TAUREN = UNIT_TYPE_TAUREN
@@ -279,16 +286,14 @@ function UnitTriggerEvent.prototype.____constructor(self, eventType, c)
279
286
  end
280
287
  local function dispatch(event, idGetter, argsGetter)
281
288
  local initialized = false
282
- local x = {}
283
289
  return setmetatable(
284
- x,
290
+ {},
285
291
  {
286
292
  __index = function(self, id)
287
293
  if type(id) ~= "number" then
288
294
  return event[id]
289
295
  end
290
296
  if not initialized then
291
- local invoke = Event.invoke
292
297
  event:addListener(function(...)
293
298
  local id = idGetter(...)
294
299
  local dispatched = rawget(self, id)
@@ -326,7 +331,6 @@ local function dispatchAbility(event)
326
331
  return event[id]
327
332
  end
328
333
  if not initialized then
329
- local invoke = Event.invoke
330
334
  event:addListener(function(unit, ability, ...)
331
335
  local dispatched = rawget(self, ability.typeId)
332
336
  if dispatched ~= nil then
@@ -354,7 +358,14 @@ local function damageEventPreventDeath(self, callback, ...)
354
358
  rawset(self, 1 + i, (select(i, ...)))
355
359
  end
356
360
  end
357
- local damageSetters = {amount = BlzSetEventDamage, attackType = BlzSetEventAttackType, damageType = BlzSetEventDamageType, weaponType = BlzSetEventWeaponType}
361
+ local damageSetters = {
362
+ amount = BlzSetEventDamage,
363
+ attackType = function(attackType)
364
+ return BlzSetEventAttackType(attackTypeToNative(attackType))
365
+ end,
366
+ damageType = BlzSetEventDamageType,
367
+ weaponType = BlzSetEventWeaponType
368
+ }
358
369
  local jlimitopByOperator = {
359
370
  [0] = LESS_THAN_OR_EQUAL,
360
371
  [1] = LESS_THAN_OR_EQUAL,
@@ -562,17 +573,6 @@ local function retrieveAbility(unit, ability, abilityId)
562
573
  ____exports.Unit:of(unit)
563
574
  )
564
575
  end
565
- if not unitAddAbility(unit, abilityId) then
566
- if getUnitAbility(unit, abilityId) == ability then
567
- return UnitAbility:of(
568
- ability,
569
- abilityId,
570
- ____exports.Unit:of(unit)
571
- )
572
- end
573
- else
574
- unitRemoveAbility(unit, abilityId)
575
- end
576
576
  for i = 0, unitInventorySize(unit) - 1 do
577
577
  local item = unitItemInSlot(unit, i)
578
578
  if getItemAbility(item, abilityId) == ability then
@@ -630,15 +630,15 @@ for ____, player in ipairs(Player.all) do
630
630
  dummies[player] = dummy
631
631
  end
632
632
  local function delayHealthChecksCallback(unit)
633
- local counter = (unit[102] or 0) - 1
633
+ local counter = (unit[103] or 0) - 1
634
634
  if counter ~= 0 then
635
- unit[102] = counter
635
+ unit[103] = counter
636
636
  return
637
637
  end
638
- unit[102] = nil
639
- local healthBonus = unit[103]
638
+ unit[103] = nil
639
+ local healthBonus = unit[104]
640
640
  if healthBonus ~= nil then
641
- unit[103] = nil
641
+ unit[104] = nil
642
642
  local handle = unit.handle
643
643
  BlzSetUnitMaxHP(
644
644
  handle,
@@ -646,12 +646,18 @@ local function delayHealthChecksCallback(unit)
646
646
  )
647
647
  end
648
648
  end
649
+ local nextSyncId = 1
650
+ local unitBySyncId = setmetatable({}, {__mode = "v"})
651
+ local damagingEventByTarget = setmetatable({}, {__mode = "k"})
649
652
  ____exports.Unit = __TS__Class()
650
653
  local Unit = ____exports.Unit
651
654
  Unit.name = "Unit"
652
655
  __TS__ClassExtends(Unit, Handle)
653
656
  function Unit.prototype.____constructor(self, handle)
654
657
  Handle.prototype.____constructor(self, handle)
658
+ local ____nextSyncId_0 = nextSyncId
659
+ nextSyncId = ____nextSyncId_0 + 1
660
+ self.syncId = ____nextSyncId_0
655
661
  self._owner = Player:of(getOwningPlayer(handle))
656
662
  assert(unitAddAbility(handle, leaveDetectAbilityId) and UnitMakeAbilityPermanent(handle, true, leaveDetectAbilityId))
657
663
  assert(unitAddAbility(handle, morphDetectAbilityId))
@@ -664,6 +670,7 @@ function Unit.prototype.____constructor(self, handle)
664
670
  fourCC("Amrf")
665
671
  ))
666
672
  end
673
+ unitBySyncId[self.syncId] = self
667
674
  local ____ = self.abilities
668
675
  end
669
676
  function Unit.prototype.getEvent(self, event, collector)
@@ -682,6 +689,8 @@ function Unit.prototype.getEvent(self, event, collector)
682
689
  end
683
690
  function Unit.prototype.onDestroy(self)
684
691
  local handle = self.handle
692
+ self[107] = getUnitX(handle)
693
+ self[108] = getUnitY(handle)
685
694
  if not self._owner then
686
695
  self._owner = Player:of(getOwningPlayer(handle))
687
696
  end
@@ -749,8 +758,8 @@ function Unit.prototype.addModifier(self, property, modifier)
749
758
  end}
750
759
  end
751
760
  function Unit.prototype.hasCombatClassification(self, combatClassification)
752
- local ____combatClassification_0 = combatClassification
753
- return getUnitIntegerField(self.handle, UNIT_IF_TARGETED_AS) & ____combatClassification_0 == ____combatClassification_0
761
+ local ____combatClassification_1 = combatClassification
762
+ return getUnitIntegerField(self.handle, UNIT_IF_TARGETED_AS) & ____combatClassification_1 == ____combatClassification_1
754
763
  end
755
764
  function Unit.prototype.addClassification(self, classification)
756
765
  return unitAddType(self.handle, classification)
@@ -768,13 +777,13 @@ function Unit.prototype.isInvisibleTo(self, player)
768
777
  return isUnitInvisible(self.handle, player.handle)
769
778
  end
770
779
  function Unit.prototype.isInRangeOf(self, x, y, range)
771
- local ____temp_1
780
+ local ____temp_2
772
781
  if type(x) == "number" then
773
- ____temp_1 = isUnitInRangeXY(self.handle, x, y, range)
782
+ ____temp_2 = isUnitInRangeXY(self.handle, x, y, range)
774
783
  else
775
- ____temp_1 = isUnitInRange(self.handle, x.handle, y)
784
+ ____temp_2 = isUnitInRange(self.handle, x.handle, y)
776
785
  end
777
- return ____temp_1
786
+ return ____temp_2
778
787
  end
779
788
  function Unit.prototype.isAllyOf(self, unit)
780
789
  return isUnitAlly(
@@ -792,16 +801,19 @@ function Unit.prototype.playAnimation(self, animation, rarity)
792
801
  if type(animation) == "number" then
793
802
  setUnitAnimationByIndex(self.handle, animation)
794
803
  elseif rarity then
795
- setUnitAnimationWithRarity(self.handle, animation, rarity)
804
+ SetUnitAnimationWithRarity(self.handle, animation, rarity)
796
805
  else
797
806
  setUnitAnimation(self.handle, animation)
798
807
  end
799
808
  end
809
+ function Unit.prototype.resetAnimation(self)
810
+ ResetUnitAnimation(self.handle)
811
+ end
800
812
  function Unit.prototype.queueAnimation(self, animation)
801
- queueUnitAnimation(self.handle, animation)
813
+ QueueUnitAnimation(self.handle, animation)
802
814
  end
803
815
  function Unit.prototype.delayHealthChecks(self)
804
- self[102] = (self[102] or 0) + 1
816
+ self[103] = (self[103] or 0) + 1
805
817
  Timer:run(delayHealthChecksCallback, self)
806
818
  end
807
819
  function Unit.prototype.setPosition(self, x, y)
@@ -811,14 +823,21 @@ function Unit.prototype.isSelected(self, player)
811
823
  return IsUnitSelected(self.handle, player.handle)
812
824
  end
813
825
  function Unit.prototype.explode(self)
814
- setUnitExploded(self.handle, true)
826
+ SetUnitExploded(self.handle, true)
815
827
  killUnit(self.handle)
816
828
  end
817
829
  function Unit.prototype.kill(self)
818
830
  killUnit(self.handle)
819
831
  end
820
- function Unit.prototype.revive(self, pos, doEffect)
821
- ReviveHero(self.handle, pos.x, pos.y, doEffect)
832
+ function Unit.prototype.revive(self, x, y, doEffect)
833
+ local ____ReviveHero_5 = ReviveHero
834
+ local ____array_4 = __TS__SparseArrayNew(self.handle, x, y)
835
+ local ____doEffect_3 = doEffect
836
+ if ____doEffect_3 == nil then
837
+ ____doEffect_3 = false
838
+ end
839
+ __TS__SparseArrayPush(____array_4, ____doEffect_3)
840
+ ____ReviveHero_5(__TS__SparseArraySpread(____array_4))
822
841
  end
823
842
  function Unit.prototype.healTarget(self, target, amount)
824
843
  if __TS__InstanceOf(target, ____exports.Unit) and target:hasAbility(fourCC("BIhm")) then
@@ -858,7 +877,7 @@ function Unit.prototype.dropItemSlot(self, item, slot)
858
877
  return UnitDropItemSlot(self.handle, item.handle, slot)
859
878
  end
860
879
  function Unit.prototype.itemInSlot(self, slot)
861
- return Item:of(UnitItemInSlot(self.handle, slot))
880
+ return Item:of(unitItemInSlot(self.handle, slot))
862
881
  end
863
882
  function Unit.prototype.addAbility(self, abilityId)
864
883
  if unitAddAbility(self.handle, abilityId) then
@@ -927,8 +946,15 @@ function Unit.prototype.interruptAttack(self)
927
946
  unitInterruptAttack(self.handle)
928
947
  end
929
948
  function Unit.prototype.interruptCast(self, abilityId)
930
- unitDisableAbility(self.handle, abilityId, true, false)
931
- unitDisableAbility(self.handle, abilityId, false, false)
949
+ local handle = self.handle
950
+ unitDisableAbility(handle, abilityId, true, false)
951
+ Timer:run(
952
+ unitDisableAbility,
953
+ handle,
954
+ abilityId,
955
+ false,
956
+ false
957
+ )
932
958
  end
933
959
  function Unit.prototype.getDistanceTo(self, target)
934
960
  local handle = self.handle
@@ -988,18 +1014,18 @@ function Unit.prototype.unpauseEx(self)
988
1014
  self:decrementStunCounter()
989
1015
  end
990
1016
  function Unit.prototype.incrementStunCounter(self)
991
- local stunCounter = self[101] or 0
992
- if not self[100] or stunCounter >= 0 then
1017
+ local stunCounter = self[102] or 0
1018
+ if not self[101] or stunCounter >= 0 then
993
1019
  BlzPauseUnitEx(self.handle, true)
994
1020
  end
995
- self[101] = stunCounter + 1
1021
+ self[102] = stunCounter + 1
996
1022
  end
997
1023
  function Unit.prototype.decrementStunCounter(self)
998
- local stunCounter = self[101] or 0
999
- if not self[100] or stunCounter >= 1 then
1024
+ local stunCounter = self[102] or 0
1025
+ if not self[101] or stunCounter >= 1 then
1000
1026
  BlzPauseUnitEx(self.handle, false)
1001
1027
  end
1002
- self[101] = stunCounter - 1
1028
+ self[102] = stunCounter - 1
1003
1029
  end
1004
1030
  function Unit.create(self, owner, id, x, y, facing, skinId)
1005
1031
  local handle = skinId and BlzCreateUnitWithSkin(
@@ -1101,8 +1127,11 @@ function Unit.getInSector(self, pos, range, offsetAngle, centralAngle)
1101
1127
  )
1102
1128
  return targetCollection
1103
1129
  end
1104
- function Unit.getSelectionOf(self, player)
1105
- targetCollection = {}
1130
+ function Unit.getSelectionOf(self, player, target)
1131
+ if target == nil then
1132
+ target = {}
1133
+ end
1134
+ targetCollection = target
1106
1135
  targetCollectionNextIndex = 1
1107
1136
  GroupEnumUnitsSelected(dummyGroup, player.handle, collectIntoTarget)
1108
1137
  return targetCollection
@@ -1124,6 +1153,9 @@ end
1124
1153
  function Unit.prototype.__tostring(self)
1125
1154
  return (((self.constructor.name .. "$") .. util.id2s(self.typeId)) .. "@") .. tostring(getHandleId(self.handle))
1126
1155
  end
1156
+ function Unit.getBySyncId(self, syncId)
1157
+ return unitBySyncId[syncId]
1158
+ end
1127
1159
  __TS__SetDescriptor(
1128
1160
  Unit.prototype,
1129
1161
  "_deltas",
@@ -1187,6 +1219,14 @@ __TS__SetDescriptor(
1187
1219
  end},
1188
1220
  true
1189
1221
  )
1222
+ __TS__SetDescriptor(
1223
+ Unit.prototype,
1224
+ "isStunned",
1225
+ {get = function(self)
1226
+ return getUnitCurrentOrder(self.handle) == orderId("stunned")
1227
+ end},
1228
+ true
1229
+ )
1190
1230
  __TS__SetDescriptor(
1191
1231
  Unit.prototype,
1192
1232
  "combatClassifications",
@@ -1260,6 +1300,19 @@ __TS__SetDescriptor(
1260
1300
  },
1261
1301
  true
1262
1302
  )
1303
+ __TS__SetDescriptor(
1304
+ Unit.prototype,
1305
+ "primaryAttribute",
1306
+ {
1307
+ get = function(self)
1308
+ return getUnitIntegerField(self.handle, UNIT_IF_PRIMARY_ATTRIBUTE)
1309
+ end,
1310
+ set = function(self, primaryAttribute)
1311
+ setUnitIntegerField(self.handle, UNIT_IF_PRIMARY_ATTRIBUTE, primaryAttribute)
1312
+ end
1313
+ },
1314
+ true
1315
+ )
1263
1316
  __TS__SetDescriptor(
1264
1317
  Unit.prototype,
1265
1318
  "strengthBase",
@@ -1381,17 +1434,17 @@ __TS__SetDescriptor(
1381
1434
  "isTeamGlowVisible",
1382
1435
  {
1383
1436
  get = function(self)
1384
- return not self[105]
1437
+ return not self[106]
1385
1438
  end,
1386
1439
  set = function(self, isTeamGlowVisible)
1387
- showUnitTeamGlow(self.handle, isTeamGlowVisible)
1388
- local ____temp_2
1440
+ BlzShowUnitTeamGlow(self.handle, isTeamGlowVisible)
1441
+ local ____temp_6
1389
1442
  if not isTeamGlowVisible then
1390
- ____temp_2 = true
1443
+ ____temp_6 = true
1391
1444
  else
1392
- ____temp_2 = nil
1445
+ ____temp_6 = nil
1393
1446
  end
1394
- self[105] = ____temp_2
1447
+ self[106] = ____temp_6
1395
1448
  end
1396
1449
  },
1397
1450
  true
@@ -1400,9 +1453,9 @@ __TS__SetDescriptor(
1400
1453
  Unit.prototype,
1401
1454
  "color",
1402
1455
  {set = function(self, color)
1403
- setUnitColor(self.handle, color.handle)
1404
- if self[105] then
1405
- showUnitTeamGlow(self.handle, false)
1456
+ SetUnitColor(self.handle, color.handle)
1457
+ if self[106] then
1458
+ BlzShowUnitTeamGlow(self.handle, false)
1406
1459
  end
1407
1460
  end},
1408
1461
  true
@@ -1425,14 +1478,14 @@ __TS__SetDescriptor(
1425
1478
  "maxHealth",
1426
1479
  {
1427
1480
  get = function(self)
1428
- return BlzGetUnitMaxHP(self.handle) - (self[103] or 0) - (self[104] or 0)
1481
+ return BlzGetUnitMaxHP(self.handle) - (self[104] or 0) - (self[105] or 0)
1429
1482
  end,
1430
1483
  set = function(self, maxHealth)
1431
- if maxHealth < 1 and self[102] ~= nil then
1432
- self[103] = (self[103] or 0) + (1 - maxHealth)
1484
+ if maxHealth < 1 and self[103] ~= nil then
1485
+ self[104] = (self[104] or 0) + (1 - maxHealth)
1433
1486
  maxHealth = 1
1434
1487
  end
1435
- BlzSetUnitMaxHP(self.handle, maxHealth + (self[104] or 0))
1488
+ BlzSetUnitMaxHP(self.handle, maxHealth + (self[105] or 0))
1436
1489
  end
1437
1490
  },
1438
1491
  true
@@ -1474,10 +1527,10 @@ __TS__SetDescriptor(
1474
1527
  "health",
1475
1528
  {
1476
1529
  get = function(self)
1477
- return GetWidgetLife(self.handle) - (self[104] or 0)
1530
+ return GetWidgetLife(self.handle) - (self[105] or 0)
1478
1531
  end,
1479
1532
  set = function(self, health)
1480
- SetWidgetLife(self.handle, health + (self[104] or 0))
1533
+ SetWidgetLife(self.handle, health + (self[105] or 0))
1481
1534
  end
1482
1535
  },
1483
1536
  true
@@ -1571,7 +1624,7 @@ __TS__SetDescriptor(
1571
1624
  "x",
1572
1625
  {
1573
1626
  get = function(self)
1574
- return getUnitX(self.handle)
1627
+ return self[107] or getUnitX(self.handle)
1575
1628
  end,
1576
1629
  set = function(self, v)
1577
1630
  SetUnitX(self.handle, v)
@@ -1584,7 +1637,7 @@ __TS__SetDescriptor(
1584
1637
  "y",
1585
1638
  {
1586
1639
  get = function(self)
1587
- return getUnitY(self.handle)
1640
+ return self[108] or getUnitY(self.handle)
1588
1641
  end,
1589
1642
  set = function(self, v)
1590
1643
  SetUnitY(self.handle, v)
@@ -1670,10 +1723,10 @@ __TS__SetDescriptor(
1670
1723
  "gold",
1671
1724
  {
1672
1725
  get = function(self)
1673
- return getResourceAmount(self.handle)
1726
+ return GetResourceAmount(self.handle)
1674
1727
  end,
1675
1728
  set = function(self, gold)
1676
- setResourceAmount(self.handle, gold)
1729
+ SetResourceAmount(self.handle, gold)
1677
1730
  end
1678
1731
  },
1679
1732
  true
@@ -1688,17 +1741,17 @@ __TS__SetDescriptor(
1688
1741
  set = function(self, isPaused)
1689
1742
  local handle = self.handle
1690
1743
  if isPaused and not IsUnitPaused(handle) then
1691
- self[100] = true
1692
- for _ = self[101] or 0, -1 do
1744
+ self[101] = true
1745
+ for _ = self[102] or 0, -1 do
1693
1746
  BlzPauseUnitEx(handle, true)
1694
1747
  end
1695
1748
  PauseUnit(handle, true)
1696
1749
  elseif not isPaused and IsUnitPaused(handle) then
1697
1750
  PauseUnit(handle, false)
1698
- for _ = self[101] or 0, -1 do
1751
+ for _ = self[102] or 0, -1 do
1699
1752
  BlzPauseUnitEx(handle, false)
1700
1753
  end
1701
- self[100] = nil
1754
+ self[101] = nil
1702
1755
  end
1703
1756
  end
1704
1757
  },
@@ -1801,6 +1854,19 @@ __TS__SetDescriptor(
1801
1854
  end},
1802
1855
  true
1803
1856
  )
1857
+ __TS__SetDescriptor(
1858
+ Unit.prototype,
1859
+ "movementType",
1860
+ {
1861
+ get = function(self)
1862
+ return getUnitIntegerField(self.handle, UNIT_IF_MOVE_TYPE)
1863
+ end,
1864
+ set = function(self, movementType)
1865
+ setUnitIntegerField(self.handle, UNIT_IF_MOVE_TYPE, movementType)
1866
+ end
1867
+ },
1868
+ true
1869
+ )
1804
1870
  __TS__SetDescriptor(
1805
1871
  Unit.prototype,
1806
1872
  "pathing",
@@ -1982,6 +2048,14 @@ __TS__SetDescriptor(
1982
2048
  end},
1983
2049
  true
1984
2050
  )
2051
+ __TS__SetDescriptor(
2052
+ Unit.prototype,
2053
+ "targetAcquiredEvent",
2054
+ {get = function(self)
2055
+ return self:getEvent(EVENT_UNIT_ACQUIRED_TARGET)
2056
+ end},
2057
+ true
2058
+ )
1985
2059
  __TS__SetDescriptor(
1986
2060
  Unit.prototype,
1987
2061
  "onSelect",
@@ -2055,7 +2129,6 @@ Unit.onDecay = __TS__New(
2055
2129
  Unit.onResurrect = __TS__New(
2056
2130
  InitializingEvent,
2057
2131
  function(event)
2058
- local invoke = Event.invoke
2059
2132
  local dead = setmetatable({}, {__mode = "k"})
2060
2133
  ____exports.Unit.deathEvent:addListener(function(unit)
2061
2134
  dead[unit] = true
@@ -2071,10 +2144,15 @@ Unit.onResurrect = __TS__New(
2071
2144
  Unit.morphEvent = __TS__New(
2072
2145
  InitializingEvent,
2073
2146
  function(event)
2147
+ local function ifNotLeft(unit)
2148
+ local handle = unit.handle
2149
+ if getUnitAbilityLevel(handle, leaveDetectAbilityId) ~= 0 and unitAddAbility(handle, morphDetectAbilityId) then
2150
+ invoke(event, unit)
2151
+ end
2152
+ end
2074
2153
  ____exports.Unit.onImmediateOrder[orderId("undefend")]:addListener(function(unit)
2075
2154
  if getUnitAbilityLevel(unit.handle, morphDetectAbilityId) == 0 then
2076
- assert(unitAddAbility(unit.handle, morphDetectAbilityId))
2077
- Timer:run(Event.invoke, event, unit)
2155
+ Timer:run(ifNotLeft, unit)
2078
2156
  end
2079
2157
  end)
2080
2158
  end
@@ -2112,27 +2190,26 @@ Unit.onSpellEffect = dispatchId(__TS__New(
2112
2190
  Unit.onTargetCast = dispatchId(__TS__New(
2113
2191
  InitializingEvent,
2114
2192
  function(event)
2115
- local invoke = Event.invoke
2116
2193
  local function listener(unit, id)
2117
- local ____GetSpellTargetUnit_result_5
2194
+ local ____GetSpellTargetUnit_result_9
2118
2195
  if GetSpellTargetUnit() then
2119
- ____GetSpellTargetUnit_result_5 = ____exports.Unit:of(GetSpellTargetUnit())
2196
+ ____GetSpellTargetUnit_result_9 = ____exports.Unit:of(GetSpellTargetUnit())
2120
2197
  else
2121
- local ____GetSpellTargetItem_result_4
2198
+ local ____GetSpellTargetItem_result_8
2122
2199
  if GetSpellTargetItem() then
2123
- ____GetSpellTargetItem_result_4 = Item:of(GetSpellTargetItem())
2200
+ ____GetSpellTargetItem_result_8 = Item:of(GetSpellTargetItem())
2124
2201
  else
2125
- local ____GetSpellTargetDestructable_result_3
2202
+ local ____GetSpellTargetDestructable_result_7
2126
2203
  if GetSpellTargetDestructable() then
2127
- ____GetSpellTargetDestructable_result_3 = Destructable:of(GetSpellTargetDestructable())
2204
+ ____GetSpellTargetDestructable_result_7 = Destructable:of(GetSpellTargetDestructable())
2128
2205
  else
2129
- ____GetSpellTargetDestructable_result_3 = nil
2206
+ ____GetSpellTargetDestructable_result_7 = nil
2130
2207
  end
2131
- ____GetSpellTargetItem_result_4 = ____GetSpellTargetDestructable_result_3
2208
+ ____GetSpellTargetItem_result_8 = ____GetSpellTargetDestructable_result_7
2132
2209
  end
2133
- ____GetSpellTargetUnit_result_5 = ____GetSpellTargetItem_result_4
2210
+ ____GetSpellTargetUnit_result_9 = ____GetSpellTargetItem_result_8
2134
2211
  end
2135
- local target = ____GetSpellTargetUnit_result_5
2212
+ local target = ____GetSpellTargetUnit_result_9
2136
2213
  if target then
2137
2214
  invoke(event, unit, id, target)
2138
2215
  end
@@ -2304,10 +2381,12 @@ Unit.onImmediateOrder = dispatchId(__TS__New(
2304
2381
  ____exports.UnitTriggerEvent,
2305
2382
  EVENT_PLAYER_UNIT_ISSUED_ORDER,
2306
2383
  function()
2307
- local unit = ____exports.Unit:of(getOrderedUnit())
2308
- local issuedOrderId = getIssuedOrderId()
2309
- if unit ~= nil and unit.state == 1 then
2310
- return unit, issuedOrderId
2384
+ local handle = getOrderedUnit()
2385
+ if handle ~= nil and getUnitTypeId(handle) ~= dummyUnitId then
2386
+ local unit = ____exports.Unit:of(handle)
2387
+ if unit.state == 1 then
2388
+ return unit, getIssuedOrderId()
2389
+ end
2311
2390
  end
2312
2391
  return IgnoreEvent
2313
2392
  end
@@ -2329,7 +2408,6 @@ Unit.autoAttackStartEvent = __TS__New(
2329
2408
  )
2330
2409
  Unit.onDamaging = (function()
2331
2410
  local event = __TS__New(Event)
2332
- local invoke = Event.invoke
2333
2411
  local trigger = CreateTrigger()
2334
2412
  TriggerRegisterAnyUnitEventBJ(trigger, EVENT_PLAYER_UNIT_DAMAGING)
2335
2413
  TriggerAddCondition(
@@ -2339,13 +2417,18 @@ Unit.onDamaging = (function()
2339
2417
  if source and source.typeId == dummyUnitId then
2340
2418
  source = nil
2341
2419
  end
2342
- local target = BlzGetEventDamageTarget()
2420
+ local target = ____exports.Unit:of(BlzGetEventDamageTarget())
2421
+ local metadata = damageMetadataByTarget[target]
2422
+ damageMetadataByTarget[target] = nil
2343
2423
  local data = {
2344
2424
  amount = GetEventDamage(),
2345
- attackType = BlzGetEventAttackType(),
2425
+ attackType = nativeToAttackType(BlzGetEventAttackType()),
2346
2426
  damageType = BlzGetEventDamageType(),
2347
2427
  weaponType = BlzGetEventWeaponType(),
2348
- isAttack = BlzGetEventIsAttack()
2428
+ metadata = metadata,
2429
+ isAttack = BlzGetEventIsAttack(),
2430
+ originalAmount = GetEventDamage(),
2431
+ originalMetadata = metadata
2349
2432
  }
2350
2433
  if data.isAttack and source then
2351
2434
  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
@@ -2359,18 +2442,22 @@ Unit.onDamaging = (function()
2359
2442
  invoke(
2360
2443
  event,
2361
2444
  source,
2362
- ____exports.Unit:of(target),
2445
+ target,
2363
2446
  setmetatable(
2364
2447
  {},
2365
2448
  {
2366
2449
  __index = data,
2367
2450
  __newindex = function(self, key, value)
2368
- damageSetters[key](value)
2451
+ local damageSetter = damageSetters[key]
2452
+ if damageSetter ~= nil then
2453
+ damageSetter(value)
2454
+ end
2369
2455
  data[key] = value
2370
2456
  end
2371
2457
  }
2372
2458
  )
2373
2459
  )
2460
+ damagingEventByTarget[target] = data
2374
2461
  return
2375
2462
  end
2376
2463
  BlzSetEventDamage(0)
@@ -2378,7 +2465,7 @@ Unit.onDamaging = (function()
2378
2465
  BlzSetEventDamageType(DAMAGE_TYPE_UNKNOWN)
2379
2466
  BlzSetEventWeaponType(WEAPON_TYPE_WHOKNOWS)
2380
2467
  local sourceOwner = source.owner.handle
2381
- local targetOwner = GetOwningPlayer(target)
2468
+ local targetOwner = target.owner.handle
2382
2469
  if not GetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE) then
2383
2470
  SetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE, true)
2384
2471
  Timer:run(function()
@@ -2394,23 +2481,19 @@ Unit.onDamaging = (function()
2394
2481
  for ____, ____value in ipairs(source._attackHandlers) do
2395
2482
  local condition = ____value[1]
2396
2483
  local action = ____value[2]
2397
- if condition(
2398
- source,
2399
- ____exports.Unit:of(target),
2400
- data
2401
- ) then
2484
+ if condition(source, target, data) then
2402
2485
  action(
2403
2486
  source,
2404
- ____exports.Unit:of(target),
2487
+ target,
2405
2488
  setmetatable(
2406
2489
  {fire = function()
2407
2490
  UnitDamageTarget(
2408
2491
  source.handle,
2409
- target,
2492
+ target.handle,
2410
2493
  data.amount,
2411
2494
  true,
2412
2495
  true,
2413
- data.attackType,
2496
+ attackTypeToNative(data.attackType),
2414
2497
  data.damageType,
2415
2498
  data.weaponType
2416
2499
  )
@@ -2428,7 +2511,6 @@ end)()
2428
2511
  Unit.onDamage = __TS__New(
2429
2512
  InitializingEvent,
2430
2513
  function(event)
2431
- local invoke = Event.invoke
2432
2514
  local trigger = CreateTrigger()
2433
2515
  TriggerRegisterAnyUnitEventBJ(trigger, EVENT_PLAYER_UNIT_DAMAGED)
2434
2516
  TriggerAddCondition(
@@ -2438,29 +2520,44 @@ Unit.onDamage = __TS__New(
2438
2520
  if source and source.typeId == dummyUnitId then
2439
2521
  source = nil
2440
2522
  end
2523
+ local target = ____exports.Unit:of(BlzGetEventDamageTarget())
2524
+ local damagingEvent = damagingEventByTarget[target]
2525
+ damagingEventByTarget[target] = nil
2441
2526
  local data = {
2442
2527
  amount = GetEventDamage(),
2443
- attackType = BlzGetEventAttackType(),
2528
+ attackType = nativeToAttackType(BlzGetEventAttackType()),
2444
2529
  damageType = BlzGetEventDamageType(),
2445
2530
  weaponType = BlzGetEventWeaponType(),
2531
+ metadata = damagingEvent and damagingEvent.metadata,
2446
2532
  isAttack = BlzGetEventIsAttack(),
2533
+ originalAmount = damagingEvent and damagingEvent.originalAmount or GetEventDamage(),
2534
+ originalMetadata = damagingEvent and damagingEvent.originalMetadata,
2447
2535
  preventDeath = damageEventPreventDeath
2448
2536
  }
2537
+ if damagingEvent then
2538
+ for key, value in pairs(damagingEvent) do
2539
+ if isAttribute(key) then
2540
+ data[key] = value
2541
+ end
2542
+ end
2543
+ end
2449
2544
  local evData = setmetatable(
2450
2545
  {},
2451
2546
  {
2452
2547
  __index = data,
2453
2548
  __newindex = function(self, key, value)
2454
- damageSetters[key](value)
2549
+ local damageSetter = damageSetters[key]
2550
+ if damageSetter ~= nil then
2551
+ damageSetter(value)
2552
+ end
2455
2553
  data[key] = value
2456
2554
  end
2457
2555
  }
2458
2556
  )
2459
- local target = ____exports.Unit:of(BlzGetEventDamageTarget())
2460
2557
  invoke(event, source, target, evData)
2461
2558
  if evData[0] ~= nil and target.health - evData.amount < 0.405 then
2462
2559
  local bonusHealth = math.ceil(evData.amount)
2463
- target[104] = (target[104] or 0) + bonusHealth
2560
+ target[105] = (target[105] or 0) + bonusHealth
2464
2561
  BlzSetUnitMaxHP(
2465
2562
  target.handle,
2466
2563
  BlzGetUnitMaxHP(target.handle) + bonusHealth
@@ -2474,7 +2571,7 @@ Unit.onDamage = __TS__New(
2474
2571
  evData[0],
2475
2572
  table.unpack(evData, 1 + 1, 1 + (evData[1] or 0))
2476
2573
  )
2477
- target[104] = (target[104] or 0) - bonusHealth
2574
+ target[105] = (target[105] or 0) - bonusHealth
2478
2575
  SetWidgetLife(
2479
2576
  target.handle,
2480
2577
  GetWidgetLife(target.handle) - bonusHealth
@@ -2494,32 +2591,91 @@ Unit.onDamage = __TS__New(
2494
2591
  DestroyTrigger(trigger)
2495
2592
  end
2496
2593
  )
2497
- Unit.onItemDrop = __TS__New(
2594
+ Unit.itemDroppedEvent = __TS__New(
2498
2595
  ____exports.UnitTriggerEvent,
2499
2596
  EVENT_PLAYER_UNIT_DROP_ITEM,
2500
2597
  function()
2501
2598
  local unit = getTriggerUnit()
2502
- if getUnitTypeId(unit) ~= dummyUnitId then
2503
- return ____exports.Unit:of(unit), Item:of(getManipulatedItem())
2599
+ local item = getManipulatedItem()
2600
+ if getUnitTypeId(unit) ~= dummyUnitId and not (ignoreEventsItems[item] ~= nil) then
2601
+ return ____exports.Unit:of(unit), Item:of(item)
2504
2602
  end
2505
2603
  return IgnoreEvent
2506
2604
  end
2507
2605
  )
2508
- Unit.onItemPickup = __TS__New(
2606
+ Unit.itemPickedUpEvent = __TS__New(
2509
2607
  ____exports.UnitTriggerEvent,
2510
2608
  EVENT_PLAYER_UNIT_PICKUP_ITEM,
2511
2609
  function()
2512
2610
  local unit = getTriggerUnit()
2513
- if getUnitTypeId(unit) ~= dummyUnitId then
2514
- return ____exports.Unit:of(unit), Item:of(getManipulatedItem())
2611
+ local item = getManipulatedItem()
2612
+ if getUnitTypeId(unit) ~= dummyUnitId and not (ignoreEventsItems[item] ~= nil) then
2613
+ return ____exports.Unit:of(unit), Item:of(item)
2515
2614
  end
2516
2615
  return IgnoreEvent
2517
2616
  end
2518
2617
  )
2519
- Unit.onItemUse = __TS__New(
2618
+ Unit.itemUsedEvent = __TS__New(
2520
2619
  ____exports.UnitTriggerEvent,
2521
2620
  EVENT_PLAYER_UNIT_USE_ITEM,
2522
- function() return ____exports.Unit:of(GetTriggerUnit()), Item:of(GetManipulatedItem()) end
2621
+ function()
2622
+ local unit = getTriggerUnit()
2623
+ local item = getManipulatedItem()
2624
+ if getUnitTypeId(unit) ~= dummyUnitId and not (ignoreEventsItems[item] ~= nil) then
2625
+ return ____exports.Unit:of(unit), Item:of(item)
2626
+ end
2627
+ return IgnoreEvent
2628
+ end
2629
+ )
2630
+ Unit.itemStackedEvent = __TS__New(
2631
+ ____exports.UnitTriggerEvent,
2632
+ EVENT_PLAYER_UNIT_STACK_ITEM,
2633
+ function() return ____exports.Unit:of(getTriggerUnit()), Item:of(getManipulatedItem()) end
2634
+ )
2635
+ __TS__ObjectDefineProperty(
2636
+ Unit,
2637
+ "itemUseOrderEvent",
2638
+ {get = function(self)
2639
+ local event = __TS__New(Event)
2640
+ for order = orderId("useslot0"), orderId("useslot5") do
2641
+ local slot = order - orderId("useslot0")
2642
+ local function listener(unit)
2643
+ local item = unit.items[slot + 1]
2644
+ if item ~= nil then
2645
+ invoke(event, unit, item)
2646
+ end
2647
+ end
2648
+ self.onImmediateOrder[order]:addListener(listener)
2649
+ self.onTargetOrder[order]:addListener(listener)
2650
+ self.onPointOrder[order]:addListener(listener)
2651
+ end
2652
+ rawset(self, "itemUseOrderEvent", event)
2653
+ return event
2654
+ end}
2655
+ )
2656
+ __TS__ObjectDefineProperty(
2657
+ Unit,
2658
+ "itemMoveOrderEvent",
2659
+ {get = function(self)
2660
+ local event = __TS__New(Event)
2661
+ for order = orderId("moveslot0"), orderId("moveslot5") do
2662
+ local slotTo = order - orderId("moveslot0")
2663
+ self.onTargetOrder[order]:addListener(function(unit, item)
2664
+ local slotFrom = unit.items:findSlot(item)
2665
+ if slotFrom ~= nil then
2666
+ invoke(
2667
+ event,
2668
+ unit,
2669
+ item,
2670
+ slotFrom,
2671
+ slotTo
2672
+ )
2673
+ end
2674
+ end)
2675
+ end
2676
+ rawset(self, "itemMoveOrderEvent", event)
2677
+ return event
2678
+ end}
2523
2679
  )
2524
2680
  __TS__ObjectDefineProperty(
2525
2681
  Unit,