warscript 0.0.1-dev.69da8a0 → 0.0.1-dev.6c4635c

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 (198) hide show
  1. package/attributes.d.ts +5 -0
  2. package/attributes.lua +8 -1
  3. package/config.d.ts +5 -0
  4. package/config.lua +10 -0
  5. package/core/types/effect.d.ts +14 -6
  6. package/core/types/effect.lua +131 -35
  7. package/core/types/frame.d.ts +3 -0
  8. package/core/types/frame.lua +83 -21
  9. package/core/types/player.lua +3 -1
  10. package/core/types/playerCamera.d.ts +2 -0
  11. package/core/types/playerCamera.lua +123 -5
  12. package/core/types/sound.d.ts +17 -24
  13. package/core/types/sound.lua +99 -24
  14. package/core/types/tileCell.d.ts +9 -0
  15. package/core/types/tileCell.lua +92 -0
  16. package/core/types/timer.d.ts +9 -8
  17. package/core/types/timer.lua +45 -23
  18. package/core/util.d.ts +1 -1
  19. package/core/util.lua +12 -1
  20. package/decl/native.d.ts +846 -790
  21. package/engine/behavior.d.ts +5 -0
  22. package/engine/behavior.lua +106 -27
  23. package/engine/behaviour/ability/always-enabled.d.ts +7 -0
  24. package/engine/behaviour/ability/always-enabled.lua +31 -0
  25. package/engine/behaviour/ability/apply-buff.d.ts +5 -0
  26. package/engine/behaviour/ability/apply-buff.lua +32 -0
  27. package/engine/behaviour/ability/apply-unit-behavior.lua +1 -0
  28. package/engine/behaviour/ability/damage.d.ts +9 -3
  29. package/engine/behaviour/ability/damage.lua +26 -38
  30. package/engine/behaviour/ability/emulate-impact.d.ts +6 -0
  31. package/engine/behaviour/ability/emulate-impact.lua +43 -0
  32. package/engine/behaviour/ability/instant-impact.d.ts +2 -2
  33. package/engine/behaviour/ability/instant-impact.lua +4 -19
  34. package/engine/behaviour/ability/on-command-impact.d.ts +8 -0
  35. package/engine/behaviour/ability/on-command-impact.lua +25 -0
  36. package/engine/behaviour/ability/remove-buffs.d.ts +16 -0
  37. package/engine/behaviour/ability/remove-buffs.lua +28 -0
  38. package/engine/behaviour/ability/restore-mana.d.ts +1 -1
  39. package/engine/behaviour/ability/restore-mana.lua +6 -6
  40. package/engine/behaviour/ability.d.ts +20 -4
  41. package/engine/behaviour/ability.lua +111 -47
  42. package/engine/behaviour/unit/stun-immunity.d.ts +7 -3
  43. package/engine/behaviour/unit/stun-immunity.lua +52 -27
  44. package/engine/behaviour/unit.d.ts +34 -0
  45. package/engine/behaviour/unit.lua +190 -4
  46. package/engine/buff.d.ts +63 -45
  47. package/engine/buff.lua +300 -237
  48. package/engine/internal/ability.d.ts +22 -3
  49. package/engine/internal/ability.lua +133 -13
  50. package/engine/internal/item/ability.lua +162 -4
  51. package/engine/internal/item+owner.lua +12 -6
  52. package/engine/internal/item.d.ts +20 -19
  53. package/engine/internal/item.lua +191 -74
  54. package/engine/internal/mechanics/ability-duration.lua +1 -1
  55. package/engine/internal/misc/ability-disable-counter.d.ts +2 -0
  56. package/engine/internal/misc/ability-disable-counter.lua +13 -0
  57. package/engine/internal/misc/damage-metadata-by-target.d.ts +2 -0
  58. package/engine/internal/misc/damage-metadata-by-target.lua +5 -0
  59. package/engine/internal/misc/frame-coordinates.d.ts +2 -0
  60. package/engine/internal/misc/frame-coordinates.lua +21 -0
  61. package/engine/internal/misc/get-terrain-z.d.ts +2 -0
  62. package/engine/internal/misc/get-terrain-z.lua +11 -0
  63. package/engine/internal/misc/player-local-handle.d.ts +2 -0
  64. package/engine/internal/misc/player-local-handle.lua +5 -0
  65. package/engine/internal/object-data/auto-attack-speed-increase.d.ts +1 -1
  66. package/engine/internal/object-data/auto-attack-speed-increase.lua +2 -0
  67. package/engine/internal/object-data/evasion-probability.d.ts +2 -0
  68. package/engine/internal/object-data/evasion-probability.lua +16 -0
  69. package/engine/internal/unit/ability.d.ts +45 -1
  70. package/engine/internal/unit/ability.lua +128 -17
  71. package/engine/internal/unit/add-item-to-slot-init.d.ts +2 -0
  72. package/engine/internal/unit/add-item-to-slot-init.lua +23 -0
  73. package/engine/internal/unit/add-item-to-slot.d.ts +2 -0
  74. package/engine/internal/unit/add-item-to-slot.lua +52 -0
  75. package/engine/internal/unit/allowed-targets.d.ts +1 -1
  76. package/engine/internal/unit/allowed-targets.lua +9 -1
  77. package/engine/internal/unit/bonus.d.ts +2 -0
  78. package/engine/internal/unit/bonus.lua +17 -0
  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 +1 -0
  82. package/engine/internal/unit/item.lua +8 -4
  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/order.d.ts +20 -0
  86. package/engine/internal/unit/order.lua +136 -0
  87. package/engine/internal/unit+ability.lua +10 -1
  88. package/engine/internal/unit+damage.d.ts +2 -11
  89. package/engine/internal/unit+damage.lua +10 -14
  90. package/engine/internal/unit+spellSteal.lua +1 -2
  91. package/engine/internal/unit-missile-launch.lua +18 -5
  92. package/engine/internal/unit.d.ts +52 -15
  93. package/engine/internal/unit.lua +378 -151
  94. package/engine/internal/utility.lua +12 -0
  95. package/engine/lightning.d.ts +12 -5
  96. package/engine/lightning.lua +48 -14
  97. package/engine/local-client.lua +14 -9
  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/armor-type.d.ts +11 -0
  101. package/engine/object-data/auxiliary/armor-type.lua +46 -0
  102. package/engine/object-data/auxiliary/attachment-preset.d.ts +7 -2
  103. package/engine/object-data/auxiliary/attachment-preset.lua +4 -3
  104. package/engine/object-data/auxiliary/attack-type.d.ts +7 -8
  105. package/engine/object-data/auxiliary/attack-type.lua +42 -0
  106. package/engine/object-data/auxiliary/movement-type.d.ts +7 -7
  107. package/engine/object-data/auxiliary/movement-type.lua +22 -0
  108. package/engine/object-data/auxiliary/sound-eax.d.ts +10 -0
  109. package/engine/object-data/auxiliary/sound-eax.lua +2 -0
  110. package/engine/object-data/auxiliary/sound-preset-name.d.ts +5 -1
  111. package/engine/object-data/auxiliary/tech-tree-dependency.d.ts +1 -1
  112. package/engine/object-data/auxiliary/unit-attribute.d.ts +6 -0
  113. package/engine/object-data/auxiliary/unit-attribute.lua +9 -0
  114. package/engine/object-data/entry/ability-type/berserk.d.ts +2 -0
  115. package/engine/object-data/entry/ability-type/berserk.lua +13 -0
  116. package/engine/object-data/entry/ability-type/blank-configurable.lua +12 -1
  117. package/engine/object-data/entry/ability-type/carrion-swarm.d.ts +14 -0
  118. package/engine/object-data/entry/ability-type/carrion-swarm.lua +65 -0
  119. package/engine/object-data/entry/ability-type/disease-cloud.lua +2 -2
  120. package/engine/object-data/entry/ability-type/engineering-upgrade.lua +2 -2
  121. package/engine/object-data/entry/ability-type/ensnare.d.ts +12 -0
  122. package/engine/object-data/entry/ability-type/ensnare.lua +52 -0
  123. package/engine/object-data/entry/ability-type/feral-spirit.lua +2 -2
  124. package/engine/object-data/entry/ability-type/permanent-invisibility.d.ts +8 -0
  125. package/engine/object-data/entry/ability-type/permanent-invisibility.lua +26 -0
  126. package/engine/object-data/entry/ability-type/phase-shift.d.ts +10 -0
  127. package/engine/object-data/entry/ability-type/phase-shift.lua +39 -0
  128. package/engine/object-data/entry/ability-type/phoenix-morph.lua +4 -4
  129. package/engine/object-data/entry/ability-type/raise-dead.d.ts +17 -0
  130. package/engine/object-data/entry/ability-type/raise-dead.lua +78 -0
  131. package/engine/object-data/entry/ability-type/shock-wave.d.ts +4 -0
  132. package/engine/object-data/entry/ability-type/shock-wave.lua +26 -0
  133. package/engine/object-data/entry/ability-type/slow-poison.d.ts +10 -0
  134. package/engine/object-data/entry/ability-type/slow-poison.lua +58 -0
  135. package/engine/object-data/entry/ability-type/summon-quilbeast.lua +2 -2
  136. package/engine/object-data/entry/ability-type/summon-water-elemental.lua +2 -2
  137. package/engine/object-data/entry/ability-type/web.d.ts +12 -0
  138. package/engine/object-data/entry/ability-type/web.lua +52 -0
  139. package/engine/object-data/entry/ability-type.d.ts +19 -17
  140. package/engine/object-data/entry/ability-type.lua +93 -36
  141. package/engine/object-data/entry/buff-type/applicable.lua +18 -37
  142. package/engine/object-data/entry/buff-type.d.ts +6 -12
  143. package/engine/object-data/entry/buff-type.lua +13 -29
  144. package/engine/object-data/entry/destructible-type.d.ts +1 -1
  145. package/engine/object-data/entry/item-type.d.ts +3 -1
  146. package/engine/object-data/entry/item-type.lua +15 -2
  147. package/engine/object-data/entry/lightning-type.d.ts +1 -1
  148. package/engine/object-data/entry/sound-preset.d.ts +33 -0
  149. package/engine/object-data/entry/sound-preset.lua +140 -0
  150. package/engine/object-data/entry/unit-type.d.ts +21 -5
  151. package/engine/object-data/entry/unit-type.lua +214 -93
  152. package/engine/object-data/entry/upgrade.d.ts +1 -1
  153. package/engine/object-data/entry/upgrade.lua +4 -4
  154. package/engine/object-data/entry.d.ts +16 -14
  155. package/engine/object-data/entry.lua +60 -32
  156. package/engine/object-data/utility/object-data-entry-id-generator.lua +7 -0
  157. package/engine/object-field/ability.d.ts +12 -6
  158. package/engine/object-field/ability.lua +8 -4
  159. package/engine/object-field/unit.d.ts +57 -3
  160. package/engine/object-field/unit.lua +207 -7
  161. package/engine/object-field.d.ts +17 -6
  162. package/engine/object-field.lua +190 -90
  163. package/engine/random.d.ts +9 -0
  164. package/engine/random.lua +13 -0
  165. package/engine/standard/entries/buff-type.d.ts +3 -0
  166. package/engine/standard/entries/buff-type.lua +3 -0
  167. package/engine/standard/entries/sound-preset.d.ts +10 -0
  168. package/engine/standard/entries/sound-preset.lua +10 -0
  169. package/engine/standard/fields/ability.d.ts +2 -0
  170. package/engine/standard/fields/ability.lua +2 -0
  171. package/engine/standard/fields/unit.d.ts +4 -0
  172. package/engine/standard/fields/unit.lua +7 -0
  173. package/engine/text-tag.d.ts +36 -2
  174. package/engine/text-tag.lua +249 -10
  175. package/engine/unit.d.ts +3 -0
  176. package/engine/unit.lua +3 -0
  177. package/objutil/buff.lua +2 -3
  178. package/objutil/unit.lua +8 -0
  179. package/package.json +2 -2
  180. package/patch-lualib.lua +1 -1
  181. package/utility/arrays.d.ts +10 -1
  182. package/utility/arrays.lua +45 -3
  183. package/utility/callback-array.d.ts +17 -0
  184. package/utility/callback-array.lua +61 -0
  185. package/utility/functions.d.ts +8 -0
  186. package/utility/functions.lua +13 -0
  187. package/utility/lazy.d.ts +2 -0
  188. package/utility/lazy.lua +14 -0
  189. package/utility/linked-set.d.ts +1 -0
  190. package/utility/linked-set.lua +3 -0
  191. package/utility/lua-maps.d.ts +15 -2
  192. package/utility/lua-maps.lua +53 -2
  193. package/utility/lua-sets.d.ts +2 -0
  194. package/utility/lua-sets.lua +7 -0
  195. package/utility/reflection.lua +11 -7
  196. package/utility/types.d.ts +3 -0
  197. package/core/types/order.d.ts +0 -25
  198. package/core/types/order.lua +0 -55
@@ -51,12 +51,21 @@ local ____arrays = require("utility.arrays")
51
51
  local forEach = ____arrays.forEach
52
52
  local ____math = require("math")
53
53
  local min = ____math.min
54
+ local ____ignore_2Devents_2Ditems = require("engine.internal.unit.ignore-events-items")
55
+ local ignoreEventsItems = ____ignore_2Devents_2Ditems.ignoreEventsItems
56
+ local ____attack_2Dtype = require("engine.object-data.auxiliary.attack-type")
57
+ local attackTypeToNative = ____attack_2Dtype.attackTypeToNative
58
+ local nativeToAttackType = ____attack_2Dtype.nativeToAttackType
59
+ local ____damage_2Dmetadata_2Dby_2Dtarget = require("engine.internal.misc.damage-metadata-by-target")
60
+ local damageMetadataByTarget = ____damage_2Dmetadata_2Dby_2Dtarget.damageMetadataByTarget
61
+ local ____attributes = require("attributes")
62
+ local isAttribute = ____attributes.isAttribute
63
+ local ____ability = require("engine.internal.item.ability")
64
+ local doUnitAbilityAction = ____ability.doUnitAbilityAction
54
65
  local match = string.match
55
66
  local ____tostring = _G.tostring
56
67
  local setUnitAnimation = SetUnitAnimation
57
- local setUnitAnimationWithRarity = SetUnitAnimationWithRarity
58
68
  local setUnitAnimationByIndex = SetUnitAnimationByIndex
59
- local queueUnitAnimation = QueueUnitAnimation
60
69
  local getUnitIntegerField = BlzGetUnitIntegerField
61
70
  local getUnitRealField = BlzGetUnitRealField
62
71
  local getHeroStr = GetHeroStr
@@ -75,9 +84,9 @@ local setUnitScale = SetUnitScale
75
84
  local setUnitPosition = SetUnitPosition
76
85
  local setUnitTimeScale = SetUnitTimeScale
77
86
  local getHandleId = GetHandleId
87
+ local getUnitCurrentOrder = GetUnitCurrentOrder
78
88
  local createUnit = CreateUnit
79
89
  local killUnit = KillUnit
80
- local setUnitExploded = SetUnitExploded
81
90
  local removeUnit = RemoveUnit
82
91
  local getUnitTypeId = GetUnitTypeId
83
92
  local isHeroUnitId = IsHeroUnitId
@@ -93,8 +102,6 @@ local getSpellTargetItem = GetSpellTargetItem
93
102
  local getSpellTargetDestructable = GetSpellTargetDestructable
94
103
  local isUnitInRangeXY = IsUnitInRangeXY
95
104
  local isUnitInRange = IsUnitInRange
96
- local setResourceAmount = SetResourceAmount
97
- local getResourceAmount = GetResourceAmount
98
105
  local getUnitWeaponRealField = BlzGetUnitWeaponRealField
99
106
  local setUnitWeaponRealField = BlzSetUnitWeaponRealField
100
107
  local getUnitWeaponStringField = BlzGetUnitWeaponStringField
@@ -118,15 +125,9 @@ local getOrderedUnit = GetOrderedUnit
118
125
  local getIssuedOrderId = GetIssuedOrderId
119
126
  local isUnitInvulnerable = BlzIsUnitInvulnerable
120
127
  local unitAlive = UnitAlive
121
- local unitAddType = UnitAddType
122
- local unitRemoveType = UnitRemoveType
123
- local isUnitIllusion = IsUnitIllusion
124
- local isUnitType = IsUnitType
125
128
  local isUnitAlly = IsUnitAlly
126
129
  local isUnitEnemy = IsUnitEnemy
127
130
  local getOwningPlayer = GetOwningPlayer
128
- local setUnitColor = SetUnitColor
129
- local showUnitTeamGlow = BlzShowUnitTeamGlow
130
131
  ____exports.UnitClassification = {}
131
132
  local UnitClassification = ____exports.UnitClassification
132
133
  do
@@ -136,6 +137,7 @@ do
136
137
  UnitClassification.GROUND = UNIT_TYPE_GROUND
137
138
  UnitClassification.SUMMONED = UNIT_TYPE_SUMMONED
138
139
  UnitClassification.MECHANICAL = UNIT_TYPE_MECHANICAL
140
+ UnitClassification.WORKER = UNIT_TYPE_PEON
139
141
  UnitClassification.ANCIENT = UNIT_TYPE_ANCIENT
140
142
  UnitClassification.SUICIDAL = UNIT_TYPE_SAPPER
141
143
  UnitClassification.TAUREN = UNIT_TYPE_TAUREN
@@ -343,6 +345,9 @@ local function dispatchAbility(event)
343
345
  }
344
346
  )
345
347
  end
348
+ local function damagingEventPreventRetaliation(self)
349
+ self[0] = true
350
+ end
346
351
  local function damageEventPreventDeath(self, callback, ...)
347
352
  if self[0] ~= nil then
348
353
  return
@@ -354,7 +359,14 @@ local function damageEventPreventDeath(self, callback, ...)
354
359
  rawset(self, 1 + i, (select(i, ...)))
355
360
  end
356
361
  end
357
- local damageSetters = {amount = BlzSetEventDamage, attackType = BlzSetEventAttackType, damageType = BlzSetEventDamageType, weaponType = BlzSetEventWeaponType}
362
+ local damageSetters = {
363
+ amount = BlzSetEventDamage,
364
+ attackType = function(attackType)
365
+ return BlzSetEventAttackType(attackTypeToNative(attackType))
366
+ end,
367
+ damageType = BlzSetEventDamageType,
368
+ weaponType = BlzSetEventWeaponType
369
+ }
358
370
  local jlimitopByOperator = {
359
371
  [0] = LESS_THAN_OR_EQUAL,
360
372
  [1] = LESS_THAN_OR_EQUAL,
@@ -432,6 +444,19 @@ __TS__SetDescriptor(
432
444
  },
433
445
  true
434
446
  )
447
+ __TS__SetDescriptor(
448
+ UnitWeapon.prototype,
449
+ "allowedTargetCombatClassifications",
450
+ {
451
+ get = function(self)
452
+ return BlzGetUnitWeaponIntegerField(self.unit.handle, UNIT_WEAPON_IF_ATTACK_TARGETS_ALLOWED, self.index)
453
+ end,
454
+ set = function(self, allowedTargetCombatClassifications)
455
+ BlzSetUnitWeaponIntegerField(self.unit.handle, UNIT_WEAPON_IF_ATTACK_TARGETS_ALLOWED, self.index, allowedTargetCombatClassifications)
456
+ end
457
+ },
458
+ true
459
+ )
435
460
  __TS__SetDescriptor(
436
461
  UnitWeapon.prototype,
437
462
  "damageBase",
@@ -562,17 +587,6 @@ local function retrieveAbility(unit, ability, abilityId)
562
587
  ____exports.Unit:of(unit)
563
588
  )
564
589
  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
590
  for i = 0, unitInventorySize(unit) - 1 do
577
591
  local item = unitItemInSlot(unit, i)
578
592
  if getItemAbility(item, abilityId) == ability then
@@ -630,15 +644,15 @@ for ____, player in ipairs(Player.all) do
630
644
  dummies[player] = dummy
631
645
  end
632
646
  local function delayHealthChecksCallback(unit)
633
- local counter = (unit[102] or 0) - 1
647
+ local counter = (unit[103] or 0) - 1
634
648
  if counter ~= 0 then
635
- unit[102] = counter
649
+ unit[103] = counter
636
650
  return
637
651
  end
638
- unit[102] = nil
639
- local healthBonus = unit[103]
652
+ unit[103] = nil
653
+ local healthBonus = unit[104]
640
654
  if healthBonus ~= nil then
641
- unit[103] = nil
655
+ unit[104] = nil
642
656
  local handle = unit.handle
643
657
  BlzSetUnitMaxHP(
644
658
  handle,
@@ -646,12 +660,27 @@ local function delayHealthChecksCallback(unit)
646
660
  )
647
661
  end
648
662
  end
663
+ local nextSyncId = 1
664
+ local unitBySyncId = setmetatable({}, {__mode = "v"})
665
+ local damagingEventByTarget = setmetatable({}, {__mode = "k"})
666
+ local function addAbility(unit, abilityTypeId)
667
+ local ____unitAddAbility_result_0
668
+ if unitAddAbility(unit, abilityTypeId) then
669
+ ____unitAddAbility_result_0 = getUnitAbility(unit, abilityTypeId)
670
+ else
671
+ ____unitAddAbility_result_0 = nil
672
+ end
673
+ return ____unitAddAbility_result_0
674
+ end
649
675
  ____exports.Unit = __TS__Class()
650
676
  local Unit = ____exports.Unit
651
677
  Unit.name = "Unit"
652
678
  __TS__ClassExtends(Unit, Handle)
653
679
  function Unit.prototype.____constructor(self, handle)
654
680
  Handle.prototype.____constructor(self, handle)
681
+ local ____nextSyncId_1 = nextSyncId
682
+ nextSyncId = ____nextSyncId_1 + 1
683
+ self.syncId = ____nextSyncId_1
655
684
  self._owner = Player:of(getOwningPlayer(handle))
656
685
  assert(unitAddAbility(handle, leaveDetectAbilityId) and UnitMakeAbilityPermanent(handle, true, leaveDetectAbilityId))
657
686
  assert(unitAddAbility(handle, morphDetectAbilityId))
@@ -664,6 +693,7 @@ function Unit.prototype.____constructor(self, handle)
664
693
  fourCC("Amrf")
665
694
  ))
666
695
  end
696
+ unitBySyncId[self.syncId] = self
667
697
  local ____ = self.abilities
668
698
  end
669
699
  function Unit.prototype.getEvent(self, event, collector)
@@ -682,6 +712,8 @@ function Unit.prototype.getEvent(self, event, collector)
682
712
  end
683
713
  function Unit.prototype.onDestroy(self)
684
714
  local handle = self.handle
715
+ self[107] = getUnitX(handle)
716
+ self[108] = getUnitY(handle)
685
717
  if not self._owner then
686
718
  self._owner = Player:of(getOwningPlayer(handle))
687
719
  end
@@ -749,17 +781,17 @@ function Unit.prototype.addModifier(self, property, modifier)
749
781
  end}
750
782
  end
751
783
  function Unit.prototype.hasCombatClassification(self, combatClassification)
752
- local ____combatClassification_0 = combatClassification
753
- return getUnitIntegerField(self.handle, UNIT_IF_TARGETED_AS) & ____combatClassification_0 == ____combatClassification_0
784
+ local ____combatClassification_2 = combatClassification
785
+ return getUnitIntegerField(self.handle, UNIT_IF_TARGETED_AS) & ____combatClassification_2 == ____combatClassification_2
754
786
  end
755
787
  function Unit.prototype.addClassification(self, classification)
756
- return unitAddType(self.handle, classification)
788
+ return UnitAddType(self.handle, classification)
757
789
  end
758
790
  function Unit.prototype.removeClassification(self, classification)
759
- return unitRemoveType(self.handle, classification)
791
+ return UnitRemoveType(self.handle, classification)
760
792
  end
761
793
  function Unit.prototype.hasClassification(self, classification)
762
- return isUnitType(self.handle, classification)
794
+ return IsUnitType(self.handle, classification)
763
795
  end
764
796
  function Unit.prototype.isVisibleTo(self, player)
765
797
  return isUnitVisible(self.handle, player.handle)
@@ -768,13 +800,13 @@ function Unit.prototype.isInvisibleTo(self, player)
768
800
  return isUnitInvisible(self.handle, player.handle)
769
801
  end
770
802
  function Unit.prototype.isInRangeOf(self, x, y, range)
771
- local ____temp_1
803
+ local ____temp_3
772
804
  if type(x) == "number" then
773
- ____temp_1 = isUnitInRangeXY(self.handle, x, y, range)
805
+ ____temp_3 = isUnitInRangeXY(self.handle, x, y, range)
774
806
  else
775
- ____temp_1 = isUnitInRange(self.handle, x.handle, y)
807
+ ____temp_3 = isUnitInRange(self.handle, x.handle, y)
776
808
  end
777
- return ____temp_1
809
+ return ____temp_3
778
810
  end
779
811
  function Unit.prototype.isAllyOf(self, unit)
780
812
  return isUnitAlly(
@@ -792,16 +824,28 @@ function Unit.prototype.playAnimation(self, animation, rarity)
792
824
  if type(animation) == "number" then
793
825
  setUnitAnimationByIndex(self.handle, animation)
794
826
  elseif rarity then
795
- setUnitAnimationWithRarity(self.handle, animation, rarity)
827
+ SetUnitAnimationWithRarity(self.handle, animation, rarity)
796
828
  else
797
829
  setUnitAnimation(self.handle, animation)
798
830
  end
799
831
  end
832
+ function Unit.prototype.resetAnimation(self)
833
+ ResetUnitAnimation(self.handle)
834
+ end
800
835
  function Unit.prototype.queueAnimation(self, animation)
801
- queueUnitAnimation(self.handle, animation)
836
+ QueueUnitAnimation(self.handle, animation)
837
+ end
838
+ function Unit.prototype.chooseWeapon(self, target)
839
+ if target:isAllowedTarget(self, self.firstWeapon.allowedTargetCombatClassifications) then
840
+ return self.firstWeapon
841
+ end
842
+ if target:isAllowedTarget(target, self.secondWeapon.allowedTargetCombatClassifications) then
843
+ return self.secondWeapon
844
+ end
845
+ return nil
802
846
  end
803
847
  function Unit.prototype.delayHealthChecks(self)
804
- self[102] = (self[102] or 0) + 1
848
+ self[103] = (self[103] or 0) + 1
805
849
  Timer:run(delayHealthChecksCallback, self)
806
850
  end
807
851
  function Unit.prototype.setPosition(self, x, y)
@@ -811,21 +855,21 @@ function Unit.prototype.isSelected(self, player)
811
855
  return IsUnitSelected(self.handle, player.handle)
812
856
  end
813
857
  function Unit.prototype.explode(self)
814
- setUnitExploded(self.handle, true)
858
+ SetUnitExploded(self.handle, true)
815
859
  killUnit(self.handle)
816
860
  end
817
861
  function Unit.prototype.kill(self)
818
862
  killUnit(self.handle)
819
863
  end
820
864
  function Unit.prototype.revive(self, x, y, doEffect)
821
- local ____ReviveHero_4 = ReviveHero
822
- local ____array_3 = __TS__SparseArrayNew(self.handle, x, y)
823
- local ____doEffect_2 = doEffect
824
- if ____doEffect_2 == nil then
825
- ____doEffect_2 = false
865
+ local ____ReviveHero_6 = ReviveHero
866
+ local ____array_5 = __TS__SparseArrayNew(self.handle, x, y)
867
+ local ____doEffect_4 = doEffect
868
+ if ____doEffect_4 == nil then
869
+ ____doEffect_4 = false
826
870
  end
827
- __TS__SparseArrayPush(____array_3, ____doEffect_2)
828
- ____ReviveHero_4(__TS__SparseArraySpread(____array_3))
871
+ __TS__SparseArrayPush(____array_5, ____doEffect_4)
872
+ ____ReviveHero_6(__TS__SparseArraySpread(____array_5))
829
873
  end
830
874
  function Unit.prototype.healTarget(self, target, amount)
831
875
  if __TS__InstanceOf(target, ____exports.Unit) and target:hasAbility(fourCC("BIhm")) then
@@ -868,17 +912,16 @@ function Unit.prototype.itemInSlot(self, slot)
868
912
  return Item:of(unitItemInSlot(self.handle, slot))
869
913
  end
870
914
  function Unit.prototype.addAbility(self, abilityId)
871
- if unitAddAbility(self.handle, abilityId) then
872
- local ability = UnitAbility:of(
873
- checkNotNull(getUnitAbility(self.handle, abilityId)),
874
- abilityId,
875
- self
876
- )
915
+ local ability = UnitAbility:of(
916
+ doUnitAbilityAction(self.handle, abilityId, addAbility, abilityId),
917
+ abilityId,
918
+ self
919
+ )
920
+ if ability ~= nil then
877
921
  local abilities = self.abilities
878
922
  abilities[#abilities + 1] = ability
879
- return ability
880
923
  end
881
- return nil
924
+ return ability
882
925
  end
883
926
  function Unit.prototype.makeAbilityPermanent(self, abilityId, permanent)
884
927
  return UnitMakeAbilityPermanent(self.handle, permanent, abilityId)
@@ -892,31 +935,21 @@ end
892
935
  function Unit.prototype.hasAbility(self, abilityId)
893
936
  return getUnitAbilityLevel(self.handle, abilityId) > 0
894
937
  end
895
- function Unit.prototype.getAbilityById(self, abilityId)
896
- local handle = self.handle
897
- if unitAddAbility(handle, abilityId) then
898
- assert(unitRemoveAbility(handle, abilityId))
899
- return nil
900
- end
901
- return UnitAbility:of(
902
- getUnitAbility(self.handle, abilityId),
903
- abilityId,
904
- self
905
- )
938
+ function Unit.prototype.getAbility(self, abilityId)
939
+ local ability = doUnitAbilityAction(self.handle, abilityId, getUnitAbility, abilityId)
940
+ return UnitAbility:of(ability, abilityId, self)
906
941
  end
907
- function Unit.prototype.removeAbility(self, abilityId)
908
- if unitRemoveAbility(self.handle, abilityId) then
909
- local abilities = self.abilities
910
- for i = 1, #abilities do
911
- if abilities[i].typeId == abilityId then
912
- abilities[i]:destroy()
913
- tremove(abilities, i)
914
- return true
915
- end
942
+ function Unit.prototype.removeAbility(self, abilityTypeId)
943
+ local abilities = self.abilities
944
+ for i = 1, #abilities do
945
+ if abilities[i].typeId == abilityTypeId then
946
+ local ability = abilities[i]
947
+ tremove(abilities, i)
948
+ ability:destroy()
949
+ return true
916
950
  end
917
- return true
918
951
  end
919
- return false
952
+ return doUnitAbilityAction(self.handle, abilityTypeId, unitRemoveAbility, abilityTypeId)
920
953
  end
921
954
  function Unit.prototype.hideAbility(self, abilityId, flag)
922
955
  BlzUnitHideAbility(self.handle, abilityId, flag)
@@ -930,12 +963,34 @@ end
930
963
  function Unit.prototype.endAbilityCooldown(self, abilityId)
931
964
  BlzEndUnitAbilityCooldown(self.handle, abilityId)
932
965
  end
966
+ function Unit.prototype.interruptMovement(self)
967
+ local handle = self.handle
968
+ unitDisableAbility(
969
+ handle,
970
+ fourCC("Amov"),
971
+ true,
972
+ false
973
+ )
974
+ unitDisableAbility(
975
+ handle,
976
+ fourCC("Amov"),
977
+ false,
978
+ false
979
+ )
980
+ end
933
981
  function Unit.prototype.interruptAttack(self)
934
982
  unitInterruptAttack(self.handle)
935
983
  end
936
984
  function Unit.prototype.interruptCast(self, abilityId)
937
- unitDisableAbility(self.handle, abilityId, true, false)
938
- unitDisableAbility(self.handle, abilityId, false, false)
985
+ local handle = self.handle
986
+ unitDisableAbility(handle, abilityId, true, false)
987
+ Timer:run(
988
+ unitDisableAbility,
989
+ handle,
990
+ abilityId,
991
+ false,
992
+ false
993
+ )
939
994
  end
940
995
  function Unit.prototype.getDistanceTo(self, target)
941
996
  local handle = self.handle
@@ -995,18 +1050,18 @@ function Unit.prototype.unpauseEx(self)
995
1050
  self:decrementStunCounter()
996
1051
  end
997
1052
  function Unit.prototype.incrementStunCounter(self)
998
- local stunCounter = self[101] or 0
999
- if not self[100] or stunCounter >= 0 then
1053
+ local stunCounter = self[102] or 0
1054
+ if not self[101] or stunCounter >= 0 then
1000
1055
  BlzPauseUnitEx(self.handle, true)
1001
1056
  end
1002
- self[101] = stunCounter + 1
1057
+ self[102] = stunCounter + 1
1003
1058
  end
1004
1059
  function Unit.prototype.decrementStunCounter(self)
1005
- local stunCounter = self[101] or 0
1006
- if not self[100] or stunCounter >= 1 then
1060
+ local stunCounter = self[102] or 0
1061
+ if not self[101] or stunCounter >= 1 then
1007
1062
  BlzPauseUnitEx(self.handle, false)
1008
1063
  end
1009
- self[101] = stunCounter - 1
1064
+ self[102] = stunCounter - 1
1010
1065
  end
1011
1066
  function Unit.create(self, owner, id, x, y, facing, skinId)
1012
1067
  local handle = skinId and BlzCreateUnitWithSkin(
@@ -1134,6 +1189,9 @@ end
1134
1189
  function Unit.prototype.__tostring(self)
1135
1190
  return (((self.constructor.name .. "$") .. util.id2s(self.typeId)) .. "@") .. tostring(getHandleId(self.handle))
1136
1191
  end
1192
+ function Unit.getBySyncId(self, syncId)
1193
+ return unitBySyncId[syncId]
1194
+ end
1137
1195
  __TS__SetDescriptor(
1138
1196
  Unit.prototype,
1139
1197
  "_deltas",
@@ -1189,11 +1247,27 @@ __TS__SetDescriptor(
1189
1247
  end},
1190
1248
  true
1191
1249
  )
1250
+ __TS__SetDescriptor(
1251
+ Unit.prototype,
1252
+ "isRemoved",
1253
+ {get = function(self)
1254
+ return getUnitAbilityLevel(self.handle, leaveDetectAbilityId) == 0
1255
+ end},
1256
+ true
1257
+ )
1192
1258
  __TS__SetDescriptor(
1193
1259
  Unit.prototype,
1194
1260
  "isIllusion",
1195
1261
  {get = function(self)
1196
- return isUnitIllusion(self.handle)
1262
+ return IsUnitIllusion(self.handle)
1263
+ end},
1264
+ true
1265
+ )
1266
+ __TS__SetDescriptor(
1267
+ Unit.prototype,
1268
+ "isStunned",
1269
+ {get = function(self)
1270
+ return getUnitCurrentOrder(self.handle) == orderId("stunned")
1197
1271
  end},
1198
1272
  true
1199
1273
  )
@@ -1270,6 +1344,19 @@ __TS__SetDescriptor(
1270
1344
  },
1271
1345
  true
1272
1346
  )
1347
+ __TS__SetDescriptor(
1348
+ Unit.prototype,
1349
+ "primaryAttribute",
1350
+ {
1351
+ get = function(self)
1352
+ return getUnitIntegerField(self.handle, UNIT_IF_PRIMARY_ATTRIBUTE)
1353
+ end,
1354
+ set = function(self, primaryAttribute)
1355
+ setUnitIntegerField(self.handle, UNIT_IF_PRIMARY_ATTRIBUTE, primaryAttribute)
1356
+ end
1357
+ },
1358
+ true
1359
+ )
1273
1360
  __TS__SetDescriptor(
1274
1361
  Unit.prototype,
1275
1362
  "strengthBase",
@@ -1391,17 +1478,17 @@ __TS__SetDescriptor(
1391
1478
  "isTeamGlowVisible",
1392
1479
  {
1393
1480
  get = function(self)
1394
- return not self[105]
1481
+ return not self[106]
1395
1482
  end,
1396
1483
  set = function(self, isTeamGlowVisible)
1397
- showUnitTeamGlow(self.handle, isTeamGlowVisible)
1398
- local ____temp_5
1484
+ BlzShowUnitTeamGlow(self.handle, isTeamGlowVisible)
1485
+ local ____temp_7
1399
1486
  if not isTeamGlowVisible then
1400
- ____temp_5 = true
1487
+ ____temp_7 = true
1401
1488
  else
1402
- ____temp_5 = nil
1489
+ ____temp_7 = nil
1403
1490
  end
1404
- self[105] = ____temp_5
1491
+ self[106] = ____temp_7
1405
1492
  end
1406
1493
  },
1407
1494
  true
@@ -1410,9 +1497,9 @@ __TS__SetDescriptor(
1410
1497
  Unit.prototype,
1411
1498
  "color",
1412
1499
  {set = function(self, color)
1413
- setUnitColor(self.handle, color.handle)
1414
- if self[105] then
1415
- showUnitTeamGlow(self.handle, false)
1500
+ SetUnitColor(self.handle, color.handle)
1501
+ if self[106] then
1502
+ BlzShowUnitTeamGlow(self.handle, false)
1416
1503
  end
1417
1504
  end},
1418
1505
  true
@@ -1435,14 +1522,14 @@ __TS__SetDescriptor(
1435
1522
  "maxHealth",
1436
1523
  {
1437
1524
  get = function(self)
1438
- return BlzGetUnitMaxHP(self.handle) - (self[103] or 0) - (self[104] or 0)
1525
+ return BlzGetUnitMaxHP(self.handle) - (self[104] or 0) - (self[105] or 0)
1439
1526
  end,
1440
1527
  set = function(self, maxHealth)
1441
- if maxHealth < 1 and self[102] ~= nil then
1442
- self[103] = (self[103] or 0) + (1 - maxHealth)
1528
+ if maxHealth < 1 and self[103] ~= nil then
1529
+ self[104] = (self[104] or 0) + (1 - maxHealth)
1443
1530
  maxHealth = 1
1444
1531
  end
1445
- BlzSetUnitMaxHP(self.handle, maxHealth + (self[104] or 0))
1532
+ BlzSetUnitMaxHP(self.handle, maxHealth + (self[105] or 0))
1446
1533
  end
1447
1534
  },
1448
1535
  true
@@ -1484,10 +1571,10 @@ __TS__SetDescriptor(
1484
1571
  "health",
1485
1572
  {
1486
1573
  get = function(self)
1487
- return GetWidgetLife(self.handle) - (self[104] or 0)
1574
+ return GetWidgetLife(self.handle) - (self[105] or 0)
1488
1575
  end,
1489
1576
  set = function(self, health)
1490
- SetWidgetLife(self.handle, health + (self[104] or 0))
1577
+ SetWidgetLife(self.handle, health + (self[105] or 0))
1491
1578
  end
1492
1579
  },
1493
1580
  true
@@ -1581,7 +1668,7 @@ __TS__SetDescriptor(
1581
1668
  "x",
1582
1669
  {
1583
1670
  get = function(self)
1584
- return getUnitX(self.handle)
1671
+ return self[107] or getUnitX(self.handle)
1585
1672
  end,
1586
1673
  set = function(self, v)
1587
1674
  SetUnitX(self.handle, v)
@@ -1594,7 +1681,7 @@ __TS__SetDescriptor(
1594
1681
  "y",
1595
1682
  {
1596
1683
  get = function(self)
1597
- return getUnitY(self.handle)
1684
+ return self[108] or getUnitY(self.handle)
1598
1685
  end,
1599
1686
  set = function(self, v)
1600
1687
  SetUnitY(self.handle, v)
@@ -1680,10 +1767,10 @@ __TS__SetDescriptor(
1680
1767
  "gold",
1681
1768
  {
1682
1769
  get = function(self)
1683
- return getResourceAmount(self.handle)
1770
+ return GetResourceAmount(self.handle)
1684
1771
  end,
1685
1772
  set = function(self, gold)
1686
- setResourceAmount(self.handle, gold)
1773
+ SetResourceAmount(self.handle, gold)
1687
1774
  end
1688
1775
  },
1689
1776
  true
@@ -1698,17 +1785,17 @@ __TS__SetDescriptor(
1698
1785
  set = function(self, isPaused)
1699
1786
  local handle = self.handle
1700
1787
  if isPaused and not IsUnitPaused(handle) then
1701
- self[100] = true
1702
- for _ = self[101] or 0, -1 do
1788
+ self[101] = true
1789
+ for _ = self[102] or 0, -1 do
1703
1790
  BlzPauseUnitEx(handle, true)
1704
1791
  end
1705
1792
  PauseUnit(handle, true)
1706
1793
  elseif not isPaused and IsUnitPaused(handle) then
1707
1794
  PauseUnit(handle, false)
1708
- for _ = self[101] or 0, -1 do
1795
+ for _ = self[102] or 0, -1 do
1709
1796
  BlzPauseUnitEx(handle, false)
1710
1797
  end
1711
- self[100] = nil
1798
+ self[101] = nil
1712
1799
  end
1713
1800
  end
1714
1801
  },
@@ -1811,6 +1898,19 @@ __TS__SetDescriptor(
1811
1898
  end},
1812
1899
  true
1813
1900
  )
1901
+ __TS__SetDescriptor(
1902
+ Unit.prototype,
1903
+ "movementType",
1904
+ {
1905
+ get = function(self)
1906
+ return getUnitIntegerField(self.handle, UNIT_IF_MOVE_TYPE)
1907
+ end,
1908
+ set = function(self, movementType)
1909
+ setUnitIntegerField(self.handle, UNIT_IF_MOVE_TYPE, movementType)
1910
+ end
1911
+ },
1912
+ true
1913
+ )
1814
1914
  __TS__SetDescriptor(
1815
1915
  Unit.prototype,
1816
1916
  "pathing",
@@ -1992,6 +2092,14 @@ __TS__SetDescriptor(
1992
2092
  end},
1993
2093
  true
1994
2094
  )
2095
+ __TS__SetDescriptor(
2096
+ Unit.prototype,
2097
+ "targetAcquiredEvent",
2098
+ {get = function(self)
2099
+ return self:getEvent(EVENT_UNIT_ACQUIRED_TARGET)
2100
+ end},
2101
+ true
2102
+ )
1995
2103
  __TS__SetDescriptor(
1996
2104
  Unit.prototype,
1997
2105
  "onSelect",
@@ -2127,25 +2235,25 @@ Unit.onTargetCast = dispatchId(__TS__New(
2127
2235
  InitializingEvent,
2128
2236
  function(event)
2129
2237
  local function listener(unit, id)
2130
- local ____GetSpellTargetUnit_result_8
2238
+ local ____GetSpellTargetUnit_result_10
2131
2239
  if GetSpellTargetUnit() then
2132
- ____GetSpellTargetUnit_result_8 = ____exports.Unit:of(GetSpellTargetUnit())
2240
+ ____GetSpellTargetUnit_result_10 = ____exports.Unit:of(GetSpellTargetUnit())
2133
2241
  else
2134
- local ____GetSpellTargetItem_result_7
2242
+ local ____GetSpellTargetItem_result_9
2135
2243
  if GetSpellTargetItem() then
2136
- ____GetSpellTargetItem_result_7 = Item:of(GetSpellTargetItem())
2244
+ ____GetSpellTargetItem_result_9 = Item:of(GetSpellTargetItem())
2137
2245
  else
2138
- local ____GetSpellTargetDestructable_result_6
2246
+ local ____GetSpellTargetDestructable_result_8
2139
2247
  if GetSpellTargetDestructable() then
2140
- ____GetSpellTargetDestructable_result_6 = Destructable:of(GetSpellTargetDestructable())
2248
+ ____GetSpellTargetDestructable_result_8 = Destructable:of(GetSpellTargetDestructable())
2141
2249
  else
2142
- ____GetSpellTargetDestructable_result_6 = nil
2250
+ ____GetSpellTargetDestructable_result_8 = nil
2143
2251
  end
2144
- ____GetSpellTargetItem_result_7 = ____GetSpellTargetDestructable_result_6
2252
+ ____GetSpellTargetItem_result_9 = ____GetSpellTargetDestructable_result_8
2145
2253
  end
2146
- ____GetSpellTargetUnit_result_8 = ____GetSpellTargetItem_result_7
2254
+ ____GetSpellTargetUnit_result_10 = ____GetSpellTargetItem_result_9
2147
2255
  end
2148
- local target = ____GetSpellTargetUnit_result_8
2256
+ local target = ____GetSpellTargetUnit_result_10
2149
2257
  if target then
2150
2258
  invoke(event, unit, id, target)
2151
2259
  end
@@ -2317,10 +2425,12 @@ Unit.onImmediateOrder = dispatchId(__TS__New(
2317
2425
  ____exports.UnitTriggerEvent,
2318
2426
  EVENT_PLAYER_UNIT_ISSUED_ORDER,
2319
2427
  function()
2320
- local unit = ____exports.Unit:of(getOrderedUnit())
2321
- local issuedOrderId = getIssuedOrderId()
2322
- if unit ~= nil and unit.state == 1 then
2323
- return unit, issuedOrderId
2428
+ local handle = getOrderedUnit()
2429
+ if handle ~= nil and getUnitTypeId(handle) ~= dummyUnitId then
2430
+ local unit = ____exports.Unit:of(handle)
2431
+ if unit.state == 1 then
2432
+ return unit, getIssuedOrderId()
2433
+ end
2324
2434
  end
2325
2435
  return IgnoreEvent
2326
2436
  end
@@ -2351,13 +2461,19 @@ Unit.onDamaging = (function()
2351
2461
  if source and source.typeId == dummyUnitId then
2352
2462
  source = nil
2353
2463
  end
2354
- local target = BlzGetEventDamageTarget()
2464
+ local target = ____exports.Unit:of(BlzGetEventDamageTarget())
2465
+ local metadata = damageMetadataByTarget[target]
2466
+ damageMetadataByTarget[target] = nil
2355
2467
  local data = {
2356
2468
  amount = GetEventDamage(),
2357
- attackType = BlzGetEventAttackType(),
2469
+ attackType = nativeToAttackType(BlzGetEventAttackType()),
2358
2470
  damageType = BlzGetEventDamageType(),
2359
2471
  weaponType = BlzGetEventWeaponType(),
2360
- isAttack = BlzGetEventIsAttack()
2472
+ metadata = metadata,
2473
+ isAttack = BlzGetEventIsAttack(),
2474
+ originalAmount = GetEventDamage(),
2475
+ originalMetadata = metadata,
2476
+ preventRetaliation = damagingEventPreventRetaliation
2361
2477
  }
2362
2478
  if data.isAttack and source then
2363
2479
  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
@@ -2371,18 +2487,36 @@ Unit.onDamaging = (function()
2371
2487
  invoke(
2372
2488
  event,
2373
2489
  source,
2374
- ____exports.Unit:of(target),
2490
+ target,
2375
2491
  setmetatable(
2376
2492
  {},
2377
2493
  {
2378
2494
  __index = data,
2379
2495
  __newindex = function(self, key, value)
2380
- damageSetters[key](value)
2496
+ local damageSetter = damageSetters[key]
2497
+ if damageSetter ~= nil then
2498
+ damageSetter(value)
2499
+ end
2381
2500
  data[key] = value
2382
2501
  end
2383
2502
  }
2384
2503
  )
2385
2504
  )
2505
+ if data[0] and source then
2506
+ local sourceOwner = source.owner.handle
2507
+ data[1] = sourceOwner
2508
+ local targetOwner = target.owner.handle
2509
+ data[2] = targetOwner
2510
+ if not GetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE) then
2511
+ SetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE, true)
2512
+ data[3] = true
2513
+ end
2514
+ if not GetPlayerAlliance(targetOwner, sourceOwner, ALLIANCE_PASSIVE) then
2515
+ SetPlayerAlliance(targetOwner, sourceOwner, ALLIANCE_PASSIVE, true)
2516
+ data[4] = true
2517
+ end
2518
+ end
2519
+ damagingEventByTarget[target] = data
2386
2520
  return
2387
2521
  end
2388
2522
  BlzSetEventDamage(0)
@@ -2390,7 +2524,7 @@ Unit.onDamaging = (function()
2390
2524
  BlzSetEventDamageType(DAMAGE_TYPE_UNKNOWN)
2391
2525
  BlzSetEventWeaponType(WEAPON_TYPE_WHOKNOWS)
2392
2526
  local sourceOwner = source.owner.handle
2393
- local targetOwner = GetOwningPlayer(target)
2527
+ local targetOwner = target.owner.handle
2394
2528
  if not GetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE) then
2395
2529
  SetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE, true)
2396
2530
  Timer:run(function()
@@ -2406,23 +2540,19 @@ Unit.onDamaging = (function()
2406
2540
  for ____, ____value in ipairs(source._attackHandlers) do
2407
2541
  local condition = ____value[1]
2408
2542
  local action = ____value[2]
2409
- if condition(
2410
- source,
2411
- ____exports.Unit:of(target),
2412
- data
2413
- ) then
2543
+ if condition(source, target, data) then
2414
2544
  action(
2415
2545
  source,
2416
- ____exports.Unit:of(target),
2546
+ target,
2417
2547
  setmetatable(
2418
2548
  {fire = function()
2419
2549
  UnitDamageTarget(
2420
2550
  source.handle,
2421
- target,
2551
+ target.handle,
2422
2552
  data.amount,
2423
2553
  true,
2424
2554
  true,
2425
- data.attackType,
2555
+ attackTypeToNative(data.attackType),
2426
2556
  data.damageType,
2427
2557
  data.weaponType
2428
2558
  )
@@ -2449,30 +2579,54 @@ Unit.onDamage = __TS__New(
2449
2579
  if source and source.typeId == dummyUnitId then
2450
2580
  source = nil
2451
2581
  end
2582
+ local target = ____exports.Unit:of(BlzGetEventDamageTarget())
2583
+ local damagingEvent = damagingEventByTarget[target]
2584
+ damagingEventByTarget[target] = nil
2452
2585
  local data = {
2453
2586
  amount = GetEventDamage(),
2454
- attackType = BlzGetEventAttackType(),
2587
+ attackType = nativeToAttackType(BlzGetEventAttackType()),
2455
2588
  damageType = BlzGetEventDamageType(),
2456
2589
  weaponType = BlzGetEventWeaponType(),
2590
+ metadata = damagingEvent and damagingEvent.metadata,
2457
2591
  isAttack = BlzGetEventIsAttack(),
2458
- originalAmount = GetEventDamage(),
2592
+ originalAmount = damagingEvent and damagingEvent.originalAmount or GetEventDamage(),
2593
+ originalMetadata = damagingEvent and damagingEvent.originalMetadata,
2459
2594
  preventDeath = damageEventPreventDeath
2460
2595
  }
2596
+ if damagingEvent then
2597
+ for key, value in pairs(damagingEvent) do
2598
+ if isAttribute(key) then
2599
+ data[key] = value
2600
+ end
2601
+ end
2602
+ local sourceOwner = damagingEvent[1]
2603
+ if sourceOwner then
2604
+ local targetOwner = damagingEvent[2]
2605
+ if damagingEvent[3] then
2606
+ SetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE, false)
2607
+ end
2608
+ if damagingEvent[4] then
2609
+ SetPlayerAlliance(targetOwner, sourceOwner, ALLIANCE_PASSIVE, false)
2610
+ end
2611
+ end
2612
+ end
2461
2613
  local evData = setmetatable(
2462
2614
  {},
2463
2615
  {
2464
2616
  __index = data,
2465
2617
  __newindex = function(self, key, value)
2466
- damageSetters[key](value)
2618
+ local damageSetter = damageSetters[key]
2619
+ if damageSetter ~= nil then
2620
+ damageSetter(value)
2621
+ end
2467
2622
  data[key] = value
2468
2623
  end
2469
2624
  }
2470
2625
  )
2471
- local target = ____exports.Unit:of(BlzGetEventDamageTarget())
2472
2626
  invoke(event, source, target, evData)
2473
2627
  if evData[0] ~= nil and target.health - evData.amount < 0.405 then
2474
2628
  local bonusHealth = math.ceil(evData.amount)
2475
- target[104] = (target[104] or 0) + bonusHealth
2629
+ target[105] = (target[105] or 0) + bonusHealth
2476
2630
  BlzSetUnitMaxHP(
2477
2631
  target.handle,
2478
2632
  BlzGetUnitMaxHP(target.handle) + bonusHealth
@@ -2486,7 +2640,7 @@ Unit.onDamage = __TS__New(
2486
2640
  evData[0],
2487
2641
  table.unpack(evData, 1 + 1, 1 + (evData[1] or 0))
2488
2642
  )
2489
- target[104] = (target[104] or 0) - bonusHealth
2643
+ target[105] = (target[105] or 0) - bonusHealth
2490
2644
  SetWidgetLife(
2491
2645
  target.handle,
2492
2646
  GetWidgetLife(target.handle) - bonusHealth
@@ -2511,8 +2665,9 @@ Unit.itemDroppedEvent = __TS__New(
2511
2665
  EVENT_PLAYER_UNIT_DROP_ITEM,
2512
2666
  function()
2513
2667
  local unit = getTriggerUnit()
2514
- if getUnitTypeId(unit) ~= dummyUnitId then
2515
- return ____exports.Unit:of(unit), Item:of(getManipulatedItem())
2668
+ local item = getManipulatedItem()
2669
+ if getUnitTypeId(unit) ~= dummyUnitId and not (ignoreEventsItems[item] ~= nil) then
2670
+ return ____exports.Unit:of(unit), Item:of(item)
2516
2671
  end
2517
2672
  return IgnoreEvent
2518
2673
  end
@@ -2521,9 +2676,14 @@ Unit.itemPickedUpEvent = __TS__New(
2521
2676
  ____exports.UnitTriggerEvent,
2522
2677
  EVENT_PLAYER_UNIT_PICKUP_ITEM,
2523
2678
  function()
2524
- local unit = getTriggerUnit()
2525
- if getUnitTypeId(unit) ~= dummyUnitId then
2526
- return ____exports.Unit:of(unit), Item:of(getManipulatedItem())
2679
+ local unitHandle = getTriggerUnit()
2680
+ local itemHandle = getManipulatedItem()
2681
+ if getUnitTypeId(unitHandle) ~= dummyUnitId and not (ignoreEventsItems[itemHandle] ~= nil) then
2682
+ local unit = ____exports.Unit:of(unitHandle)
2683
+ local item = Item:of(itemHandle)
2684
+ if item.owner ~= unit then
2685
+ return unit, item
2686
+ end
2527
2687
  end
2528
2688
  return IgnoreEvent
2529
2689
  end
@@ -2531,12 +2691,79 @@ Unit.itemPickedUpEvent = __TS__New(
2531
2691
  Unit.itemUsedEvent = __TS__New(
2532
2692
  ____exports.UnitTriggerEvent,
2533
2693
  EVENT_PLAYER_UNIT_USE_ITEM,
2534
- function() return ____exports.Unit:of(getTriggerUnit()), Item:of(getManipulatedItem()) end
2694
+ function()
2695
+ local unit = getTriggerUnit()
2696
+ local item = getManipulatedItem()
2697
+ if getUnitTypeId(unit) ~= dummyUnitId and not (ignoreEventsItems[item] ~= nil) then
2698
+ return ____exports.Unit:of(unit), Item:of(item)
2699
+ end
2700
+ return IgnoreEvent
2701
+ end
2535
2702
  )
2536
2703
  Unit.itemStackedEvent = __TS__New(
2537
2704
  ____exports.UnitTriggerEvent,
2538
2705
  EVENT_PLAYER_UNIT_STACK_ITEM,
2539
- function() return ____exports.Unit:of(getTriggerUnit()), Item:of(getManipulatedItem()) end
2706
+ function() return ____exports.Unit:of(getTriggerUnit()), Item:of(BlzGetStackingItemTarget()), Item:of(BlzGetStackingItemSource()) end
2707
+ )
2708
+ __TS__ObjectDefineProperty(
2709
+ Unit,
2710
+ "itemChargesChangedEvent",
2711
+ {get = function(self)
2712
+ local event = __TS__New(Event)
2713
+ Item.chargesChangedEvent:addListener(function(item)
2714
+ local unit = item.owner
2715
+ if unit ~= nil then
2716
+ invoke(event, unit, item)
2717
+ end
2718
+ end)
2719
+ rawset(self, "itemChargesChangedEvent", event)
2720
+ return event
2721
+ end}
2722
+ )
2723
+ __TS__ObjectDefineProperty(
2724
+ Unit,
2725
+ "itemUseOrderEvent",
2726
+ {get = function(self)
2727
+ local event = __TS__New(Event)
2728
+ for order = orderId("useslot0"), orderId("useslot5") do
2729
+ local slot = order - orderId("useslot0")
2730
+ local function listener(unit)
2731
+ local item = unit.items[slot + 1]
2732
+ if item ~= nil then
2733
+ invoke(event, unit, item)
2734
+ end
2735
+ end
2736
+ self.onImmediateOrder[order]:addListener(listener)
2737
+ self.onTargetOrder[order]:addListener(listener)
2738
+ self.onPointOrder[order]:addListener(listener)
2739
+ end
2740
+ rawset(self, "itemUseOrderEvent", event)
2741
+ return event
2742
+ end}
2743
+ )
2744
+ __TS__ObjectDefineProperty(
2745
+ Unit,
2746
+ "itemMoveOrderEvent",
2747
+ {get = function(self)
2748
+ local event = __TS__New(Event)
2749
+ for order = orderId("moveslot0"), orderId("moveslot5") do
2750
+ local slotTo = order - orderId("moveslot0")
2751
+ self.onTargetOrder[order]:addListener(function(unit, item)
2752
+ local slotFrom = unit.items:findSlot(item)
2753
+ if slotFrom ~= nil then
2754
+ invoke(
2755
+ event,
2756
+ unit,
2757
+ item,
2758
+ slotFrom,
2759
+ slotTo
2760
+ )
2761
+ end
2762
+ end)
2763
+ end
2764
+ rawset(self, "itemMoveOrderEvent", event)
2765
+ return event
2766
+ end}
2540
2767
  )
2541
2768
  __TS__ObjectDefineProperty(
2542
2769
  Unit,