warscript 0.0.1-dev.a921742 → 0.0.1-dev.a9a8ba4

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 (180) 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 +4 -0
  8. package/core/types/frame.lua +71 -0
  9. package/core/types/sound.d.ts +17 -24
  10. package/core/types/sound.lua +99 -24
  11. package/core/types/timer.d.ts +7 -8
  12. package/core/types/timer.lua +18 -21
  13. package/core/util.d.ts +1 -1
  14. package/core/util.lua +18 -1
  15. package/decl/native.d.ts +840 -786
  16. package/engine/behavior.d.ts +2 -2
  17. package/engine/behavior.lua +6 -6
  18. package/engine/behaviour/ability/always-enabled.d.ts +7 -0
  19. package/engine/behaviour/ability/always-enabled.lua +31 -0
  20. package/engine/behaviour/ability/apply-buff.d.ts +5 -0
  21. package/engine/behaviour/ability/apply-buff.lua +32 -0
  22. package/engine/behaviour/ability/apply-unit-behavior.lua +1 -0
  23. package/engine/behaviour/ability/damage.d.ts +9 -3
  24. package/engine/behaviour/ability/damage.lua +26 -38
  25. package/engine/behaviour/ability/emulate-impact.d.ts +6 -0
  26. package/engine/behaviour/ability/emulate-impact.lua +42 -0
  27. package/engine/behaviour/ability/instant-impact.d.ts +2 -2
  28. package/engine/behaviour/ability/instant-impact.lua +4 -19
  29. package/engine/behaviour/ability/on-command-impact.d.ts +8 -0
  30. package/engine/behaviour/ability/on-command-impact.lua +25 -0
  31. package/engine/behaviour/ability/remove-buffs.d.ts +16 -0
  32. package/engine/behaviour/ability/remove-buffs.lua +28 -0
  33. package/engine/behaviour/ability.d.ts +20 -4
  34. package/engine/behaviour/ability.lua +111 -47
  35. package/engine/behaviour/unit/stun-immunity.d.ts +5 -3
  36. package/engine/behaviour/unit/stun-immunity.lua +43 -27
  37. package/engine/behaviour/unit.d.ts +28 -0
  38. package/engine/behaviour/unit.lua +160 -4
  39. package/engine/buff.d.ts +63 -42
  40. package/engine/buff.lua +318 -234
  41. package/engine/internal/ability.d.ts +20 -13
  42. package/engine/internal/ability.lua +97 -76
  43. package/engine/internal/item/ability.lua +161 -4
  44. package/engine/internal/item.d.ts +7 -4
  45. package/engine/internal/item.lua +131 -28
  46. package/engine/internal/mechanics/ability-duration.lua +1 -1
  47. package/engine/internal/misc/ability-disable-counter.d.ts +2 -0
  48. package/engine/internal/misc/ability-disable-counter.lua +13 -0
  49. package/engine/internal/misc/damage-metadata-by-target.d.ts +2 -0
  50. package/engine/internal/misc/damage-metadata-by-target.lua +5 -0
  51. package/engine/internal/object-data/auto-attack-speed-increase.d.ts +1 -1
  52. package/engine/internal/object-data/auto-attack-speed-increase.lua +2 -0
  53. package/engine/internal/object-data/evasion-probability.d.ts +2 -0
  54. package/engine/internal/object-data/evasion-probability.lua +16 -0
  55. package/engine/internal/unit/ability.d.ts +45 -1
  56. package/engine/internal/unit/ability.lua +98 -14
  57. package/engine/internal/unit/add-item-to-slot-init.d.ts +2 -0
  58. package/engine/internal/unit/add-item-to-slot-init.lua +23 -0
  59. package/engine/internal/unit/add-item-to-slot.d.ts +2 -0
  60. package/engine/internal/unit/add-item-to-slot.lua +52 -0
  61. package/engine/internal/unit/allowed-targets.d.ts +1 -1
  62. package/engine/internal/unit/allowed-targets.lua +9 -1
  63. package/engine/internal/unit/bonus.d.ts +2 -0
  64. package/engine/internal/unit/bonus.lua +17 -0
  65. package/engine/internal/unit/ignore-events-items.d.ts +2 -0
  66. package/engine/internal/unit/ignore-events-items.lua +5 -0
  67. package/engine/internal/unit/item.d.ts +2 -0
  68. package/engine/internal/unit/item.lua +19 -4
  69. package/engine/internal/unit/main-selected.d.ts +13 -0
  70. package/engine/internal/unit/main-selected.lua +51 -0
  71. package/engine/internal/unit/order.d.ts +20 -0
  72. package/engine/internal/unit/order.lua +136 -0
  73. package/engine/internal/unit+damage.d.ts +2 -11
  74. package/engine/internal/unit+damage.lua +10 -14
  75. package/engine/internal/unit+spellSteal.lua +1 -2
  76. package/engine/internal/unit-missile-launch.lua +25 -6
  77. package/engine/internal/unit.d.ts +48 -11
  78. package/engine/internal/unit.lua +394 -150
  79. package/engine/internal/utility.lua +12 -0
  80. package/engine/lightning.d.ts +12 -5
  81. package/engine/lightning.lua +48 -14
  82. package/engine/local-client.d.ts +7 -2
  83. package/engine/local-client.lua +82 -0
  84. package/engine/object-data/auxiliary/animation-name.d.ts +1 -0
  85. package/engine/object-data/auxiliary/animation-name.lua +16 -0
  86. package/engine/object-data/auxiliary/attachment-preset.d.ts +7 -2
  87. package/engine/object-data/auxiliary/attachment-preset.lua +4 -3
  88. package/engine/object-data/auxiliary/attack-type.d.ts +7 -8
  89. package/engine/object-data/auxiliary/attack-type.lua +42 -0
  90. package/engine/object-data/auxiliary/movement-type.d.ts +7 -7
  91. package/engine/object-data/auxiliary/movement-type.lua +22 -0
  92. package/engine/object-data/auxiliary/sound-eax.d.ts +10 -0
  93. package/engine/object-data/auxiliary/sound-eax.lua +2 -0
  94. package/engine/object-data/auxiliary/sound-preset-name.d.ts +5 -1
  95. package/engine/object-data/auxiliary/tech-tree-dependency.d.ts +1 -1
  96. package/engine/object-data/auxiliary/unit-attribute.d.ts +6 -0
  97. package/engine/object-data/auxiliary/unit-attribute.lua +9 -0
  98. package/engine/object-data/entry/ability-type/berserk.d.ts +2 -0
  99. package/engine/object-data/entry/ability-type/berserk.lua +13 -0
  100. package/engine/object-data/entry/ability-type/blank-configurable.lua +12 -1
  101. package/engine/object-data/entry/ability-type/carrion-swarm.d.ts +14 -0
  102. package/engine/object-data/entry/ability-type/carrion-swarm.lua +65 -0
  103. package/engine/object-data/entry/ability-type/disease-cloud.lua +2 -2
  104. package/engine/object-data/entry/ability-type/engineering-upgrade.lua +2 -2
  105. package/engine/object-data/entry/ability-type/ensnare.d.ts +12 -0
  106. package/engine/object-data/entry/ability-type/ensnare.lua +52 -0
  107. package/engine/object-data/entry/ability-type/feral-spirit.lua +2 -2
  108. package/engine/object-data/entry/ability-type/permanent-invisibility.d.ts +8 -0
  109. package/engine/object-data/entry/ability-type/permanent-invisibility.lua +26 -0
  110. package/engine/object-data/entry/ability-type/phase-shift.d.ts +10 -0
  111. package/engine/object-data/entry/ability-type/phase-shift.lua +39 -0
  112. package/engine/object-data/entry/ability-type/phoenix-morph.lua +4 -4
  113. package/engine/object-data/entry/ability-type/raise-dead.d.ts +17 -0
  114. package/engine/object-data/entry/ability-type/raise-dead.lua +78 -0
  115. package/engine/object-data/entry/ability-type/shock-wave.d.ts +4 -0
  116. package/engine/object-data/entry/ability-type/shock-wave.lua +26 -0
  117. package/engine/object-data/entry/ability-type/slow-poison.d.ts +10 -0
  118. package/engine/object-data/entry/ability-type/slow-poison.lua +58 -0
  119. package/engine/object-data/entry/ability-type/summon-quilbeast.lua +2 -2
  120. package/engine/object-data/entry/ability-type/summon-water-elemental.lua +2 -2
  121. package/engine/object-data/entry/ability-type/web.d.ts +12 -0
  122. package/engine/object-data/entry/ability-type/web.lua +52 -0
  123. package/engine/object-data/entry/ability-type.d.ts +19 -17
  124. package/engine/object-data/entry/ability-type.lua +89 -33
  125. package/engine/object-data/entry/buff-type/applicable.lua +18 -37
  126. package/engine/object-data/entry/buff-type.d.ts +6 -12
  127. package/engine/object-data/entry/buff-type.lua +13 -29
  128. package/engine/object-data/entry/destructible-type.d.ts +1 -1
  129. package/engine/object-data/entry/item-type.d.ts +15 -1
  130. package/engine/object-data/entry/item-type.lua +93 -2
  131. package/engine/object-data/entry/lightning-type.d.ts +1 -1
  132. package/engine/object-data/entry/sound-preset.d.ts +33 -0
  133. package/engine/object-data/entry/sound-preset.lua +140 -0
  134. package/engine/object-data/entry/unit-type.d.ts +10 -3
  135. package/engine/object-data/entry/unit-type.lua +155 -92
  136. package/engine/object-data/entry/upgrade.d.ts +1 -1
  137. package/engine/object-data/entry/upgrade.lua +4 -4
  138. package/engine/object-data/entry.d.ts +16 -14
  139. package/engine/object-data/entry.lua +60 -32
  140. package/engine/object-data/utility/object-data-entry-id-generator.lua +7 -0
  141. package/engine/object-field/ability.d.ts +10 -4
  142. package/engine/object-field/ability.lua +4 -1
  143. package/engine/object-field/unit.d.ts +50 -3
  144. package/engine/object-field/unit.lua +186 -7
  145. package/engine/object-field.d.ts +17 -6
  146. package/engine/object-field.lua +187 -89
  147. package/engine/standard/entries/buff-type.d.ts +3 -0
  148. package/engine/standard/entries/buff-type.lua +3 -0
  149. package/engine/standard/entries/sound-preset.d.ts +10 -0
  150. package/engine/standard/entries/sound-preset.lua +10 -0
  151. package/engine/standard/fields/ability.d.ts +2 -0
  152. package/engine/standard/fields/ability.lua +2 -0
  153. package/engine/standard/fields/unit.d.ts +3 -0
  154. package/engine/standard/fields/unit.lua +5 -0
  155. package/engine/text-tag.d.ts +36 -2
  156. package/engine/text-tag.lua +175 -10
  157. package/engine/unit.d.ts +3 -0
  158. package/engine/unit.lua +3 -0
  159. package/index.d.ts +1 -0
  160. package/index.lua +1 -0
  161. package/objutil/buff.lua +1 -2
  162. package/objutil/unit.lua +8 -0
  163. package/package.json +2 -2
  164. package/patch-lua.d.ts +0 -0
  165. package/patch-lua.lua +10 -0
  166. package/utility/arrays.d.ts +9 -1
  167. package/utility/arrays.lua +37 -3
  168. package/utility/functions.d.ts +1 -0
  169. package/utility/functions.lua +1 -0
  170. package/utility/lazy.d.ts +2 -0
  171. package/utility/lazy.lua +14 -0
  172. package/utility/linked-set.d.ts +1 -0
  173. package/utility/linked-set.lua +3 -0
  174. package/utility/lua-maps.d.ts +4 -0
  175. package/utility/lua-maps.lua +20 -0
  176. package/utility/lua-sets.d.ts +1 -0
  177. package/utility/lua-sets.lua +3 -0
  178. package/utility/reflection.lua +11 -7
  179. package/core/types/order.d.ts +0 -25
  180. 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,10 @@ 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
128
  local isUnitType = IsUnitType
125
129
  local isUnitAlly = IsUnitAlly
126
130
  local isUnitEnemy = IsUnitEnemy
127
131
  local getOwningPlayer = GetOwningPlayer
128
- local setUnitColor = SetUnitColor
129
- local showUnitTeamGlow = BlzShowUnitTeamGlow
130
132
  ____exports.UnitClassification = {}
131
133
  local UnitClassification = ____exports.UnitClassification
132
134
  do
@@ -136,6 +138,7 @@ do
136
138
  UnitClassification.GROUND = UNIT_TYPE_GROUND
137
139
  UnitClassification.SUMMONED = UNIT_TYPE_SUMMONED
138
140
  UnitClassification.MECHANICAL = UNIT_TYPE_MECHANICAL
141
+ UnitClassification.WORKER = UNIT_TYPE_PEON
139
142
  UnitClassification.ANCIENT = UNIT_TYPE_ANCIENT
140
143
  UnitClassification.SUICIDAL = UNIT_TYPE_SAPPER
141
144
  UnitClassification.TAUREN = UNIT_TYPE_TAUREN
@@ -343,6 +346,9 @@ local function dispatchAbility(event)
343
346
  }
344
347
  )
345
348
  end
349
+ local function damagingEventPreventRetaliation(self)
350
+ self[0] = true
351
+ end
346
352
  local function damageEventPreventDeath(self, callback, ...)
347
353
  if self[0] ~= nil then
348
354
  return
@@ -354,7 +360,14 @@ local function damageEventPreventDeath(self, callback, ...)
354
360
  rawset(self, 1 + i, (select(i, ...)))
355
361
  end
356
362
  end
357
- local damageSetters = {amount = BlzSetEventDamage, attackType = BlzSetEventAttackType, damageType = BlzSetEventDamageType, weaponType = BlzSetEventWeaponType}
363
+ local damageSetters = {
364
+ amount = BlzSetEventDamage,
365
+ attackType = function(attackType)
366
+ return BlzSetEventAttackType(attackTypeToNative(attackType))
367
+ end,
368
+ damageType = BlzSetEventDamageType,
369
+ weaponType = BlzSetEventWeaponType
370
+ }
358
371
  local jlimitopByOperator = {
359
372
  [0] = LESS_THAN_OR_EQUAL,
360
373
  [1] = LESS_THAN_OR_EQUAL,
@@ -432,6 +445,19 @@ __TS__SetDescriptor(
432
445
  },
433
446
  true
434
447
  )
448
+ __TS__SetDescriptor(
449
+ UnitWeapon.prototype,
450
+ "allowedTargetCombatClassifications",
451
+ {
452
+ get = function(self)
453
+ return BlzGetUnitWeaponIntegerField(self.unit.handle, UNIT_WEAPON_IF_ATTACK_TARGETS_ALLOWED, self.index)
454
+ end,
455
+ set = function(self, allowedTargetCombatClassifications)
456
+ BlzSetUnitWeaponIntegerField(self.unit.handle, UNIT_WEAPON_IF_ATTACK_TARGETS_ALLOWED, self.index, allowedTargetCombatClassifications)
457
+ end
458
+ },
459
+ true
460
+ )
435
461
  __TS__SetDescriptor(
436
462
  UnitWeapon.prototype,
437
463
  "damageBase",
@@ -562,17 +588,6 @@ local function retrieveAbility(unit, ability, abilityId)
562
588
  ____exports.Unit:of(unit)
563
589
  )
564
590
  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
591
  for i = 0, unitInventorySize(unit) - 1 do
577
592
  local item = unitItemInSlot(unit, i)
578
593
  if getItemAbility(item, abilityId) == ability then
@@ -630,15 +645,15 @@ for ____, player in ipairs(Player.all) do
630
645
  dummies[player] = dummy
631
646
  end
632
647
  local function delayHealthChecksCallback(unit)
633
- local counter = (unit[102] or 0) - 1
648
+ local counter = (unit[103] or 0) - 1
634
649
  if counter ~= 0 then
635
- unit[102] = counter
650
+ unit[103] = counter
636
651
  return
637
652
  end
638
- unit[102] = nil
639
- local healthBonus = unit[103]
653
+ unit[103] = nil
654
+ local healthBonus = unit[104]
640
655
  if healthBonus ~= nil then
641
- unit[103] = nil
656
+ unit[104] = nil
642
657
  local handle = unit.handle
643
658
  BlzSetUnitMaxHP(
644
659
  handle,
@@ -646,12 +661,53 @@ local function delayHealthChecksCallback(unit)
646
661
  )
647
662
  end
648
663
  end
664
+ local nextSyncId = 1
665
+ local unitBySyncId = setmetatable({}, {__mode = "v"})
666
+ local damagingEventByTarget = setmetatable({}, {__mode = "k"})
667
+ local function addAbility(unit, abilityTypeId)
668
+ local handle = unit.handle
669
+ if unitAddAbility(handle, abilityTypeId) then
670
+ local ability = UnitAbility:of(
671
+ checkNotNull(getUnitAbility(handle, abilityTypeId)),
672
+ abilityTypeId,
673
+ unit
674
+ )
675
+ local abilities = unit.abilities
676
+ abilities[#abilities + 1] = ability
677
+ return ability
678
+ end
679
+ return nil
680
+ end
681
+ local function getAbility(unit, abilityTypeId)
682
+ return UnitAbility:of(
683
+ getUnitAbility(unit.handle, abilityTypeId),
684
+ abilityTypeId,
685
+ unit
686
+ )
687
+ end
688
+ local function removeAbility(unit, abilityTypeId)
689
+ if unitRemoveAbility(unit.handle, abilityTypeId) then
690
+ local abilities = unit.abilities
691
+ for i = 1, #abilities do
692
+ if abilities[i].typeId == abilityTypeId then
693
+ abilities[i]:destroy()
694
+ tremove(abilities, i)
695
+ return true
696
+ end
697
+ end
698
+ return true
699
+ end
700
+ return false
701
+ end
649
702
  ____exports.Unit = __TS__Class()
650
703
  local Unit = ____exports.Unit
651
704
  Unit.name = "Unit"
652
705
  __TS__ClassExtends(Unit, Handle)
653
706
  function Unit.prototype.____constructor(self, handle)
654
707
  Handle.prototype.____constructor(self, handle)
708
+ local ____nextSyncId_0 = nextSyncId
709
+ nextSyncId = ____nextSyncId_0 + 1
710
+ self.syncId = ____nextSyncId_0
655
711
  self._owner = Player:of(getOwningPlayer(handle))
656
712
  assert(unitAddAbility(handle, leaveDetectAbilityId) and UnitMakeAbilityPermanent(handle, true, leaveDetectAbilityId))
657
713
  assert(unitAddAbility(handle, morphDetectAbilityId))
@@ -664,6 +720,7 @@ function Unit.prototype.____constructor(self, handle)
664
720
  fourCC("Amrf")
665
721
  ))
666
722
  end
723
+ unitBySyncId[self.syncId] = self
667
724
  local ____ = self.abilities
668
725
  end
669
726
  function Unit.prototype.getEvent(self, event, collector)
@@ -682,6 +739,8 @@ function Unit.prototype.getEvent(self, event, collector)
682
739
  end
683
740
  function Unit.prototype.onDestroy(self)
684
741
  local handle = self.handle
742
+ self[107] = getUnitX(handle)
743
+ self[108] = getUnitY(handle)
685
744
  if not self._owner then
686
745
  self._owner = Player:of(getOwningPlayer(handle))
687
746
  end
@@ -749,14 +808,14 @@ function Unit.prototype.addModifier(self, property, modifier)
749
808
  end}
750
809
  end
751
810
  function Unit.prototype.hasCombatClassification(self, combatClassification)
752
- local ____combatClassification_0 = combatClassification
753
- return getUnitIntegerField(self.handle, UNIT_IF_TARGETED_AS) & ____combatClassification_0 == ____combatClassification_0
811
+ local ____combatClassification_1 = combatClassification
812
+ return getUnitIntegerField(self.handle, UNIT_IF_TARGETED_AS) & ____combatClassification_1 == ____combatClassification_1
754
813
  end
755
814
  function Unit.prototype.addClassification(self, classification)
756
- return unitAddType(self.handle, classification)
815
+ return UnitAddType(self.handle, classification)
757
816
  end
758
817
  function Unit.prototype.removeClassification(self, classification)
759
- return unitRemoveType(self.handle, classification)
818
+ return UnitRemoveType(self.handle, classification)
760
819
  end
761
820
  function Unit.prototype.hasClassification(self, classification)
762
821
  return isUnitType(self.handle, classification)
@@ -768,13 +827,13 @@ function Unit.prototype.isInvisibleTo(self, player)
768
827
  return isUnitInvisible(self.handle, player.handle)
769
828
  end
770
829
  function Unit.prototype.isInRangeOf(self, x, y, range)
771
- local ____temp_1
830
+ local ____temp_2
772
831
  if type(x) == "number" then
773
- ____temp_1 = isUnitInRangeXY(self.handle, x, y, range)
832
+ ____temp_2 = isUnitInRangeXY(self.handle, x, y, range)
774
833
  else
775
- ____temp_1 = isUnitInRange(self.handle, x.handle, y)
834
+ ____temp_2 = isUnitInRange(self.handle, x.handle, y)
776
835
  end
777
- return ____temp_1
836
+ return ____temp_2
778
837
  end
779
838
  function Unit.prototype.isAllyOf(self, unit)
780
839
  return isUnitAlly(
@@ -792,16 +851,28 @@ function Unit.prototype.playAnimation(self, animation, rarity)
792
851
  if type(animation) == "number" then
793
852
  setUnitAnimationByIndex(self.handle, animation)
794
853
  elseif rarity then
795
- setUnitAnimationWithRarity(self.handle, animation, rarity)
854
+ SetUnitAnimationWithRarity(self.handle, animation, rarity)
796
855
  else
797
856
  setUnitAnimation(self.handle, animation)
798
857
  end
799
858
  end
859
+ function Unit.prototype.resetAnimation(self)
860
+ ResetUnitAnimation(self.handle)
861
+ end
800
862
  function Unit.prototype.queueAnimation(self, animation)
801
- queueUnitAnimation(self.handle, animation)
863
+ QueueUnitAnimation(self.handle, animation)
864
+ end
865
+ function Unit.prototype.chooseWeapon(self, target)
866
+ if target:isAllowedTarget(self, self.firstWeapon.allowedTargetCombatClassifications) then
867
+ return self.firstWeapon
868
+ end
869
+ if target:isAllowedTarget(target, self.secondWeapon.allowedTargetCombatClassifications) then
870
+ return self.secondWeapon
871
+ end
872
+ return nil
802
873
  end
803
874
  function Unit.prototype.delayHealthChecks(self)
804
- self[102] = (self[102] or 0) + 1
875
+ self[103] = (self[103] or 0) + 1
805
876
  Timer:run(delayHealthChecksCallback, self)
806
877
  end
807
878
  function Unit.prototype.setPosition(self, x, y)
@@ -811,21 +882,21 @@ function Unit.prototype.isSelected(self, player)
811
882
  return IsUnitSelected(self.handle, player.handle)
812
883
  end
813
884
  function Unit.prototype.explode(self)
814
- setUnitExploded(self.handle, true)
885
+ SetUnitExploded(self.handle, true)
815
886
  killUnit(self.handle)
816
887
  end
817
888
  function Unit.prototype.kill(self)
818
889
  killUnit(self.handle)
819
890
  end
820
891
  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
892
+ local ____ReviveHero_5 = ReviveHero
893
+ local ____array_4 = __TS__SparseArrayNew(self.handle, x, y)
894
+ local ____doEffect_3 = doEffect
895
+ if ____doEffect_3 == nil then
896
+ ____doEffect_3 = false
826
897
  end
827
- __TS__SparseArrayPush(____array_3, ____doEffect_2)
828
- ____ReviveHero_4(__TS__SparseArraySpread(____array_3))
898
+ __TS__SparseArrayPush(____array_4, ____doEffect_3)
899
+ ____ReviveHero_5(__TS__SparseArraySpread(____array_4))
829
900
  end
830
901
  function Unit.prototype.healTarget(self, target, amount)
831
902
  if __TS__InstanceOf(target, ____exports.Unit) and target:hasAbility(fourCC("BIhm")) then
@@ -868,17 +939,13 @@ function Unit.prototype.itemInSlot(self, slot)
868
939
  return Item:of(unitItemInSlot(self.handle, slot))
869
940
  end
870
941
  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
- )
877
- local abilities = self.abilities
878
- abilities[#abilities + 1] = ability
879
- return ability
880
- end
881
- return nil
942
+ return doUnitAbilityAction(
943
+ self.handle,
944
+ abilityId,
945
+ addAbility,
946
+ self,
947
+ abilityId
948
+ )
882
949
  end
883
950
  function Unit.prototype.makeAbilityPermanent(self, abilityId, permanent)
884
951
  return UnitMakeAbilityPermanent(self.handle, permanent, abilityId)
@@ -893,30 +960,22 @@ function Unit.prototype.hasAbility(self, abilityId)
893
960
  return getUnitAbilityLevel(self.handle, abilityId) > 0
894
961
  end
895
962
  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),
963
+ return doUnitAbilityAction(
964
+ self.handle,
903
965
  abilityId,
904
- self
966
+ getAbility,
967
+ self,
968
+ abilityId
905
969
  )
906
970
  end
907
971
  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
916
- end
917
- return true
918
- end
919
- return false
972
+ return doUnitAbilityAction(
973
+ self.handle,
974
+ abilityId,
975
+ removeAbility,
976
+ self,
977
+ abilityId
978
+ )
920
979
  end
921
980
  function Unit.prototype.hideAbility(self, abilityId, flag)
922
981
  BlzUnitHideAbility(self.handle, abilityId, flag)
@@ -930,12 +989,34 @@ end
930
989
  function Unit.prototype.endAbilityCooldown(self, abilityId)
931
990
  BlzEndUnitAbilityCooldown(self.handle, abilityId)
932
991
  end
992
+ function Unit.prototype.interruptMovement(self)
993
+ local handle = self.handle
994
+ unitDisableAbility(
995
+ handle,
996
+ fourCC("Amov"),
997
+ true,
998
+ false
999
+ )
1000
+ unitDisableAbility(
1001
+ handle,
1002
+ fourCC("Amov"),
1003
+ false,
1004
+ false
1005
+ )
1006
+ end
933
1007
  function Unit.prototype.interruptAttack(self)
934
1008
  unitInterruptAttack(self.handle)
935
1009
  end
936
1010
  function Unit.prototype.interruptCast(self, abilityId)
937
- unitDisableAbility(self.handle, abilityId, true, false)
938
- unitDisableAbility(self.handle, abilityId, false, false)
1011
+ local handle = self.handle
1012
+ unitDisableAbility(handle, abilityId, true, false)
1013
+ Timer:run(
1014
+ unitDisableAbility,
1015
+ handle,
1016
+ abilityId,
1017
+ false,
1018
+ false
1019
+ )
939
1020
  end
940
1021
  function Unit.prototype.getDistanceTo(self, target)
941
1022
  local handle = self.handle
@@ -995,18 +1076,18 @@ function Unit.prototype.unpauseEx(self)
995
1076
  self:decrementStunCounter()
996
1077
  end
997
1078
  function Unit.prototype.incrementStunCounter(self)
998
- local stunCounter = self[101] or 0
999
- if not self[100] or stunCounter >= 0 then
1079
+ local stunCounter = self[102] or 0
1080
+ if not self[101] or stunCounter >= 0 then
1000
1081
  BlzPauseUnitEx(self.handle, true)
1001
1082
  end
1002
- self[101] = stunCounter + 1
1083
+ self[102] = stunCounter + 1
1003
1084
  end
1004
1085
  function Unit.prototype.decrementStunCounter(self)
1005
- local stunCounter = self[101] or 0
1006
- if not self[100] or stunCounter >= 1 then
1086
+ local stunCounter = self[102] or 0
1087
+ if not self[101] or stunCounter >= 1 then
1007
1088
  BlzPauseUnitEx(self.handle, false)
1008
1089
  end
1009
- self[101] = stunCounter - 1
1090
+ self[102] = stunCounter - 1
1010
1091
  end
1011
1092
  function Unit.create(self, owner, id, x, y, facing, skinId)
1012
1093
  local handle = skinId and BlzCreateUnitWithSkin(
@@ -1108,8 +1189,11 @@ function Unit.getInSector(self, pos, range, offsetAngle, centralAngle)
1108
1189
  )
1109
1190
  return targetCollection
1110
1191
  end
1111
- function Unit.getSelectionOf(self, player)
1112
- targetCollection = {}
1192
+ function Unit.getSelectionOf(self, player, target)
1193
+ if target == nil then
1194
+ target = {}
1195
+ end
1196
+ targetCollection = target
1113
1197
  targetCollectionNextIndex = 1
1114
1198
  GroupEnumUnitsSelected(dummyGroup, player.handle, collectIntoTarget)
1115
1199
  return targetCollection
@@ -1131,6 +1215,9 @@ end
1131
1215
  function Unit.prototype.__tostring(self)
1132
1216
  return (((self.constructor.name .. "$") .. util.id2s(self.typeId)) .. "@") .. tostring(getHandleId(self.handle))
1133
1217
  end
1218
+ function Unit.getBySyncId(self, syncId)
1219
+ return unitBySyncId[syncId]
1220
+ end
1134
1221
  __TS__SetDescriptor(
1135
1222
  Unit.prototype,
1136
1223
  "_deltas",
@@ -1190,7 +1277,15 @@ __TS__SetDescriptor(
1190
1277
  Unit.prototype,
1191
1278
  "isIllusion",
1192
1279
  {get = function(self)
1193
- return isUnitIllusion(self.handle)
1280
+ return IsUnitIllusion(self.handle)
1281
+ end},
1282
+ true
1283
+ )
1284
+ __TS__SetDescriptor(
1285
+ Unit.prototype,
1286
+ "isStunned",
1287
+ {get = function(self)
1288
+ return getUnitCurrentOrder(self.handle) == orderId("stunned")
1194
1289
  end},
1195
1290
  true
1196
1291
  )
@@ -1267,6 +1362,19 @@ __TS__SetDescriptor(
1267
1362
  },
1268
1363
  true
1269
1364
  )
1365
+ __TS__SetDescriptor(
1366
+ Unit.prototype,
1367
+ "primaryAttribute",
1368
+ {
1369
+ get = function(self)
1370
+ return getUnitIntegerField(self.handle, UNIT_IF_PRIMARY_ATTRIBUTE)
1371
+ end,
1372
+ set = function(self, primaryAttribute)
1373
+ setUnitIntegerField(self.handle, UNIT_IF_PRIMARY_ATTRIBUTE, primaryAttribute)
1374
+ end
1375
+ },
1376
+ true
1377
+ )
1270
1378
  __TS__SetDescriptor(
1271
1379
  Unit.prototype,
1272
1380
  "strengthBase",
@@ -1388,17 +1496,17 @@ __TS__SetDescriptor(
1388
1496
  "isTeamGlowVisible",
1389
1497
  {
1390
1498
  get = function(self)
1391
- return not self[105]
1499
+ return not self[106]
1392
1500
  end,
1393
1501
  set = function(self, isTeamGlowVisible)
1394
- showUnitTeamGlow(self.handle, isTeamGlowVisible)
1395
- local ____temp_5
1502
+ BlzShowUnitTeamGlow(self.handle, isTeamGlowVisible)
1503
+ local ____temp_6
1396
1504
  if not isTeamGlowVisible then
1397
- ____temp_5 = true
1505
+ ____temp_6 = true
1398
1506
  else
1399
- ____temp_5 = nil
1507
+ ____temp_6 = nil
1400
1508
  end
1401
- self[105] = ____temp_5
1509
+ self[106] = ____temp_6
1402
1510
  end
1403
1511
  },
1404
1512
  true
@@ -1407,9 +1515,9 @@ __TS__SetDescriptor(
1407
1515
  Unit.prototype,
1408
1516
  "color",
1409
1517
  {set = function(self, color)
1410
- setUnitColor(self.handle, color.handle)
1411
- if self[105] then
1412
- showUnitTeamGlow(self.handle, false)
1518
+ SetUnitColor(self.handle, color.handle)
1519
+ if self[106] then
1520
+ BlzShowUnitTeamGlow(self.handle, false)
1413
1521
  end
1414
1522
  end},
1415
1523
  true
@@ -1432,14 +1540,14 @@ __TS__SetDescriptor(
1432
1540
  "maxHealth",
1433
1541
  {
1434
1542
  get = function(self)
1435
- return BlzGetUnitMaxHP(self.handle) - (self[103] or 0) - (self[104] or 0)
1543
+ return BlzGetUnitMaxHP(self.handle) - (self[104] or 0) - (self[105] or 0)
1436
1544
  end,
1437
1545
  set = function(self, maxHealth)
1438
- if maxHealth < 1 and self[102] ~= nil then
1439
- self[103] = (self[103] or 0) + (1 - maxHealth)
1546
+ if maxHealth < 1 and self[103] ~= nil then
1547
+ self[104] = (self[104] or 0) + (1 - maxHealth)
1440
1548
  maxHealth = 1
1441
1549
  end
1442
- BlzSetUnitMaxHP(self.handle, maxHealth + (self[104] or 0))
1550
+ BlzSetUnitMaxHP(self.handle, maxHealth + (self[105] or 0))
1443
1551
  end
1444
1552
  },
1445
1553
  true
@@ -1481,10 +1589,10 @@ __TS__SetDescriptor(
1481
1589
  "health",
1482
1590
  {
1483
1591
  get = function(self)
1484
- return GetWidgetLife(self.handle) - (self[104] or 0)
1592
+ return GetWidgetLife(self.handle) - (self[105] or 0)
1485
1593
  end,
1486
1594
  set = function(self, health)
1487
- SetWidgetLife(self.handle, health + (self[104] or 0))
1595
+ SetWidgetLife(self.handle, health + (self[105] or 0))
1488
1596
  end
1489
1597
  },
1490
1598
  true
@@ -1578,7 +1686,7 @@ __TS__SetDescriptor(
1578
1686
  "x",
1579
1687
  {
1580
1688
  get = function(self)
1581
- return getUnitX(self.handle)
1689
+ return self[107] or getUnitX(self.handle)
1582
1690
  end,
1583
1691
  set = function(self, v)
1584
1692
  SetUnitX(self.handle, v)
@@ -1591,7 +1699,7 @@ __TS__SetDescriptor(
1591
1699
  "y",
1592
1700
  {
1593
1701
  get = function(self)
1594
- return getUnitY(self.handle)
1702
+ return self[108] or getUnitY(self.handle)
1595
1703
  end,
1596
1704
  set = function(self, v)
1597
1705
  SetUnitY(self.handle, v)
@@ -1677,10 +1785,10 @@ __TS__SetDescriptor(
1677
1785
  "gold",
1678
1786
  {
1679
1787
  get = function(self)
1680
- return getResourceAmount(self.handle)
1788
+ return GetResourceAmount(self.handle)
1681
1789
  end,
1682
1790
  set = function(self, gold)
1683
- setResourceAmount(self.handle, gold)
1791
+ SetResourceAmount(self.handle, gold)
1684
1792
  end
1685
1793
  },
1686
1794
  true
@@ -1695,17 +1803,17 @@ __TS__SetDescriptor(
1695
1803
  set = function(self, isPaused)
1696
1804
  local handle = self.handle
1697
1805
  if isPaused and not IsUnitPaused(handle) then
1698
- self[100] = true
1699
- for _ = self[101] or 0, -1 do
1806
+ self[101] = true
1807
+ for _ = self[102] or 0, -1 do
1700
1808
  BlzPauseUnitEx(handle, true)
1701
1809
  end
1702
1810
  PauseUnit(handle, true)
1703
1811
  elseif not isPaused and IsUnitPaused(handle) then
1704
1812
  PauseUnit(handle, false)
1705
- for _ = self[101] or 0, -1 do
1813
+ for _ = self[102] or 0, -1 do
1706
1814
  BlzPauseUnitEx(handle, false)
1707
1815
  end
1708
- self[100] = nil
1816
+ self[101] = nil
1709
1817
  end
1710
1818
  end
1711
1819
  },
@@ -1808,6 +1916,19 @@ __TS__SetDescriptor(
1808
1916
  end},
1809
1917
  true
1810
1918
  )
1919
+ __TS__SetDescriptor(
1920
+ Unit.prototype,
1921
+ "movementType",
1922
+ {
1923
+ get = function(self)
1924
+ return getUnitIntegerField(self.handle, UNIT_IF_MOVE_TYPE)
1925
+ end,
1926
+ set = function(self, movementType)
1927
+ setUnitIntegerField(self.handle, UNIT_IF_MOVE_TYPE, movementType)
1928
+ end
1929
+ },
1930
+ true
1931
+ )
1811
1932
  __TS__SetDescriptor(
1812
1933
  Unit.prototype,
1813
1934
  "pathing",
@@ -1989,6 +2110,14 @@ __TS__SetDescriptor(
1989
2110
  end},
1990
2111
  true
1991
2112
  )
2113
+ __TS__SetDescriptor(
2114
+ Unit.prototype,
2115
+ "targetAcquiredEvent",
2116
+ {get = function(self)
2117
+ return self:getEvent(EVENT_UNIT_ACQUIRED_TARGET)
2118
+ end},
2119
+ true
2120
+ )
1992
2121
  __TS__SetDescriptor(
1993
2122
  Unit.prototype,
1994
2123
  "onSelect",
@@ -2124,25 +2253,25 @@ Unit.onTargetCast = dispatchId(__TS__New(
2124
2253
  InitializingEvent,
2125
2254
  function(event)
2126
2255
  local function listener(unit, id)
2127
- local ____GetSpellTargetUnit_result_8
2256
+ local ____GetSpellTargetUnit_result_9
2128
2257
  if GetSpellTargetUnit() then
2129
- ____GetSpellTargetUnit_result_8 = ____exports.Unit:of(GetSpellTargetUnit())
2258
+ ____GetSpellTargetUnit_result_9 = ____exports.Unit:of(GetSpellTargetUnit())
2130
2259
  else
2131
- local ____GetSpellTargetItem_result_7
2260
+ local ____GetSpellTargetItem_result_8
2132
2261
  if GetSpellTargetItem() then
2133
- ____GetSpellTargetItem_result_7 = Item:of(GetSpellTargetItem())
2262
+ ____GetSpellTargetItem_result_8 = Item:of(GetSpellTargetItem())
2134
2263
  else
2135
- local ____GetSpellTargetDestructable_result_6
2264
+ local ____GetSpellTargetDestructable_result_7
2136
2265
  if GetSpellTargetDestructable() then
2137
- ____GetSpellTargetDestructable_result_6 = Destructable:of(GetSpellTargetDestructable())
2266
+ ____GetSpellTargetDestructable_result_7 = Destructable:of(GetSpellTargetDestructable())
2138
2267
  else
2139
- ____GetSpellTargetDestructable_result_6 = nil
2268
+ ____GetSpellTargetDestructable_result_7 = nil
2140
2269
  end
2141
- ____GetSpellTargetItem_result_7 = ____GetSpellTargetDestructable_result_6
2270
+ ____GetSpellTargetItem_result_8 = ____GetSpellTargetDestructable_result_7
2142
2271
  end
2143
- ____GetSpellTargetUnit_result_8 = ____GetSpellTargetItem_result_7
2272
+ ____GetSpellTargetUnit_result_9 = ____GetSpellTargetItem_result_8
2144
2273
  end
2145
- local target = ____GetSpellTargetUnit_result_8
2274
+ local target = ____GetSpellTargetUnit_result_9
2146
2275
  if target then
2147
2276
  invoke(event, unit, id, target)
2148
2277
  end
@@ -2314,10 +2443,12 @@ Unit.onImmediateOrder = dispatchId(__TS__New(
2314
2443
  ____exports.UnitTriggerEvent,
2315
2444
  EVENT_PLAYER_UNIT_ISSUED_ORDER,
2316
2445
  function()
2317
- local unit = ____exports.Unit:of(getOrderedUnit())
2318
- local issuedOrderId = getIssuedOrderId()
2319
- if unit ~= nil and unit.state == 1 then
2320
- return unit, issuedOrderId
2446
+ local handle = getOrderedUnit()
2447
+ if handle ~= nil and getUnitTypeId(handle) ~= dummyUnitId then
2448
+ local unit = ____exports.Unit:of(handle)
2449
+ if unit.state == 1 then
2450
+ return unit, getIssuedOrderId()
2451
+ end
2321
2452
  end
2322
2453
  return IgnoreEvent
2323
2454
  end
@@ -2348,13 +2479,19 @@ Unit.onDamaging = (function()
2348
2479
  if source and source.typeId == dummyUnitId then
2349
2480
  source = nil
2350
2481
  end
2351
- local target = BlzGetEventDamageTarget()
2482
+ local target = ____exports.Unit:of(BlzGetEventDamageTarget())
2483
+ local metadata = damageMetadataByTarget[target]
2484
+ damageMetadataByTarget[target] = nil
2352
2485
  local data = {
2353
2486
  amount = GetEventDamage(),
2354
- attackType = BlzGetEventAttackType(),
2487
+ attackType = nativeToAttackType(BlzGetEventAttackType()),
2355
2488
  damageType = BlzGetEventDamageType(),
2356
2489
  weaponType = BlzGetEventWeaponType(),
2357
- isAttack = BlzGetEventIsAttack()
2490
+ metadata = metadata,
2491
+ isAttack = BlzGetEventIsAttack(),
2492
+ originalAmount = GetEventDamage(),
2493
+ originalMetadata = metadata,
2494
+ preventRetaliation = damagingEventPreventRetaliation
2358
2495
  }
2359
2496
  if data.isAttack and source then
2360
2497
  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
@@ -2368,18 +2505,36 @@ Unit.onDamaging = (function()
2368
2505
  invoke(
2369
2506
  event,
2370
2507
  source,
2371
- ____exports.Unit:of(target),
2508
+ target,
2372
2509
  setmetatable(
2373
2510
  {},
2374
2511
  {
2375
2512
  __index = data,
2376
2513
  __newindex = function(self, key, value)
2377
- damageSetters[key](value)
2514
+ local damageSetter = damageSetters[key]
2515
+ if damageSetter ~= nil then
2516
+ damageSetter(value)
2517
+ end
2378
2518
  data[key] = value
2379
2519
  end
2380
2520
  }
2381
2521
  )
2382
2522
  )
2523
+ if data[0] and source then
2524
+ local sourceOwner = source.owner.handle
2525
+ data[1] = sourceOwner
2526
+ local targetOwner = target.owner.handle
2527
+ data[2] = targetOwner
2528
+ if not GetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE) then
2529
+ SetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE, true)
2530
+ data[3] = true
2531
+ end
2532
+ if not GetPlayerAlliance(targetOwner, sourceOwner, ALLIANCE_PASSIVE) then
2533
+ SetPlayerAlliance(targetOwner, sourceOwner, ALLIANCE_PASSIVE, true)
2534
+ data[4] = true
2535
+ end
2536
+ end
2537
+ damagingEventByTarget[target] = data
2383
2538
  return
2384
2539
  end
2385
2540
  BlzSetEventDamage(0)
@@ -2387,7 +2542,7 @@ Unit.onDamaging = (function()
2387
2542
  BlzSetEventDamageType(DAMAGE_TYPE_UNKNOWN)
2388
2543
  BlzSetEventWeaponType(WEAPON_TYPE_WHOKNOWS)
2389
2544
  local sourceOwner = source.owner.handle
2390
- local targetOwner = GetOwningPlayer(target)
2545
+ local targetOwner = target.owner.handle
2391
2546
  if not GetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE) then
2392
2547
  SetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE, true)
2393
2548
  Timer:run(function()
@@ -2403,23 +2558,19 @@ Unit.onDamaging = (function()
2403
2558
  for ____, ____value in ipairs(source._attackHandlers) do
2404
2559
  local condition = ____value[1]
2405
2560
  local action = ____value[2]
2406
- if condition(
2407
- source,
2408
- ____exports.Unit:of(target),
2409
- data
2410
- ) then
2561
+ if condition(source, target, data) then
2411
2562
  action(
2412
2563
  source,
2413
- ____exports.Unit:of(target),
2564
+ target,
2414
2565
  setmetatable(
2415
2566
  {fire = function()
2416
2567
  UnitDamageTarget(
2417
2568
  source.handle,
2418
- target,
2569
+ target.handle,
2419
2570
  data.amount,
2420
2571
  true,
2421
2572
  true,
2422
- data.attackType,
2573
+ attackTypeToNative(data.attackType),
2423
2574
  data.damageType,
2424
2575
  data.weaponType
2425
2576
  )
@@ -2446,30 +2597,54 @@ Unit.onDamage = __TS__New(
2446
2597
  if source and source.typeId == dummyUnitId then
2447
2598
  source = nil
2448
2599
  end
2600
+ local target = ____exports.Unit:of(BlzGetEventDamageTarget())
2601
+ local damagingEvent = damagingEventByTarget[target]
2602
+ damagingEventByTarget[target] = nil
2449
2603
  local data = {
2450
2604
  amount = GetEventDamage(),
2451
- attackType = BlzGetEventAttackType(),
2605
+ attackType = nativeToAttackType(BlzGetEventAttackType()),
2452
2606
  damageType = BlzGetEventDamageType(),
2453
2607
  weaponType = BlzGetEventWeaponType(),
2608
+ metadata = damagingEvent and damagingEvent.metadata,
2454
2609
  isAttack = BlzGetEventIsAttack(),
2455
- originalAmount = GetEventDamage(),
2610
+ originalAmount = damagingEvent and damagingEvent.originalAmount or GetEventDamage(),
2611
+ originalMetadata = damagingEvent and damagingEvent.originalMetadata,
2456
2612
  preventDeath = damageEventPreventDeath
2457
2613
  }
2614
+ if damagingEvent then
2615
+ for key, value in pairs(damagingEvent) do
2616
+ if isAttribute(key) then
2617
+ data[key] = value
2618
+ end
2619
+ end
2620
+ local sourceOwner = damagingEvent[1]
2621
+ if sourceOwner then
2622
+ local targetOwner = damagingEvent[2]
2623
+ if damagingEvent[3] then
2624
+ SetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE, false)
2625
+ end
2626
+ if damagingEvent[4] then
2627
+ SetPlayerAlliance(targetOwner, sourceOwner, ALLIANCE_PASSIVE, false)
2628
+ end
2629
+ end
2630
+ end
2458
2631
  local evData = setmetatable(
2459
2632
  {},
2460
2633
  {
2461
2634
  __index = data,
2462
2635
  __newindex = function(self, key, value)
2463
- damageSetters[key](value)
2636
+ local damageSetter = damageSetters[key]
2637
+ if damageSetter ~= nil then
2638
+ damageSetter(value)
2639
+ end
2464
2640
  data[key] = value
2465
2641
  end
2466
2642
  }
2467
2643
  )
2468
- local target = ____exports.Unit:of(BlzGetEventDamageTarget())
2469
2644
  invoke(event, source, target, evData)
2470
2645
  if evData[0] ~= nil and target.health - evData.amount < 0.405 then
2471
2646
  local bonusHealth = math.ceil(evData.amount)
2472
- target[104] = (target[104] or 0) + bonusHealth
2647
+ target[105] = (target[105] or 0) + bonusHealth
2473
2648
  BlzSetUnitMaxHP(
2474
2649
  target.handle,
2475
2650
  BlzGetUnitMaxHP(target.handle) + bonusHealth
@@ -2483,7 +2658,7 @@ Unit.onDamage = __TS__New(
2483
2658
  evData[0],
2484
2659
  table.unpack(evData, 1 + 1, 1 + (evData[1] or 0))
2485
2660
  )
2486
- target[104] = (target[104] or 0) - bonusHealth
2661
+ target[105] = (target[105] or 0) - bonusHealth
2487
2662
  SetWidgetLife(
2488
2663
  target.handle,
2489
2664
  GetWidgetLife(target.handle) - bonusHealth
@@ -2508,8 +2683,9 @@ Unit.itemDroppedEvent = __TS__New(
2508
2683
  EVENT_PLAYER_UNIT_DROP_ITEM,
2509
2684
  function()
2510
2685
  local unit = getTriggerUnit()
2511
- if getUnitTypeId(unit) ~= dummyUnitId then
2512
- return ____exports.Unit:of(unit), Item:of(getManipulatedItem())
2686
+ local item = getManipulatedItem()
2687
+ if getUnitTypeId(unit) ~= dummyUnitId and not (ignoreEventsItems[item] ~= nil) then
2688
+ return ____exports.Unit:of(unit), Item:of(item)
2513
2689
  end
2514
2690
  return IgnoreEvent
2515
2691
  end
@@ -2519,8 +2695,9 @@ Unit.itemPickedUpEvent = __TS__New(
2519
2695
  EVENT_PLAYER_UNIT_PICKUP_ITEM,
2520
2696
  function()
2521
2697
  local unit = getTriggerUnit()
2522
- if getUnitTypeId(unit) ~= dummyUnitId then
2523
- return ____exports.Unit:of(unit), Item:of(getManipulatedItem())
2698
+ local item = getManipulatedItem()
2699
+ if getUnitTypeId(unit) ~= dummyUnitId and not (ignoreEventsItems[item] ~= nil) then
2700
+ return ____exports.Unit:of(unit), Item:of(item)
2524
2701
  end
2525
2702
  return IgnoreEvent
2526
2703
  end
@@ -2528,13 +2705,80 @@ Unit.itemPickedUpEvent = __TS__New(
2528
2705
  Unit.itemUsedEvent = __TS__New(
2529
2706
  ____exports.UnitTriggerEvent,
2530
2707
  EVENT_PLAYER_UNIT_USE_ITEM,
2531
- function() return ____exports.Unit:of(getTriggerUnit()), Item:of(getManipulatedItem()) end
2708
+ function()
2709
+ local unit = getTriggerUnit()
2710
+ local item = getManipulatedItem()
2711
+ if getUnitTypeId(unit) ~= dummyUnitId and not (ignoreEventsItems[item] ~= nil) then
2712
+ return ____exports.Unit:of(unit), Item:of(item)
2713
+ end
2714
+ return IgnoreEvent
2715
+ end
2532
2716
  )
2533
2717
  Unit.itemStackedEvent = __TS__New(
2534
2718
  ____exports.UnitTriggerEvent,
2535
2719
  EVENT_PLAYER_UNIT_STACK_ITEM,
2536
2720
  function() return ____exports.Unit:of(getTriggerUnit()), Item:of(getManipulatedItem()) end
2537
2721
  )
2722
+ __TS__ObjectDefineProperty(
2723
+ Unit,
2724
+ "itemChargesChangedEvent",
2725
+ {get = function(self)
2726
+ local event = __TS__New(Event)
2727
+ Item.chargesChangedEvent:addListener(function(item)
2728
+ local unit = item.owner
2729
+ if unit ~= nil then
2730
+ invoke(event, unit, item)
2731
+ end
2732
+ end)
2733
+ rawset(self, "itemChargesChangedEvent", event)
2734
+ return event
2735
+ end}
2736
+ )
2737
+ __TS__ObjectDefineProperty(
2738
+ Unit,
2739
+ "itemUseOrderEvent",
2740
+ {get = function(self)
2741
+ local event = __TS__New(Event)
2742
+ for order = orderId("useslot0"), orderId("useslot5") do
2743
+ local slot = order - orderId("useslot0")
2744
+ local function listener(unit)
2745
+ local item = unit.items[slot + 1]
2746
+ if item ~= nil then
2747
+ invoke(event, unit, item)
2748
+ end
2749
+ end
2750
+ self.onImmediateOrder[order]:addListener(listener)
2751
+ self.onTargetOrder[order]:addListener(listener)
2752
+ self.onPointOrder[order]:addListener(listener)
2753
+ end
2754
+ rawset(self, "itemUseOrderEvent", event)
2755
+ return event
2756
+ end}
2757
+ )
2758
+ __TS__ObjectDefineProperty(
2759
+ Unit,
2760
+ "itemMoveOrderEvent",
2761
+ {get = function(self)
2762
+ local event = __TS__New(Event)
2763
+ for order = orderId("moveslot0"), orderId("moveslot5") do
2764
+ local slotTo = order - orderId("moveslot0")
2765
+ self.onTargetOrder[order]:addListener(function(unit, item)
2766
+ local slotFrom = unit.items:findSlot(item)
2767
+ if slotFrom ~= nil then
2768
+ invoke(
2769
+ event,
2770
+ unit,
2771
+ item,
2772
+ slotFrom,
2773
+ slotTo
2774
+ )
2775
+ end
2776
+ end)
2777
+ end
2778
+ rawset(self, "itemMoveOrderEvent", event)
2779
+ return event
2780
+ end}
2781
+ )
2538
2782
  __TS__ObjectDefineProperty(
2539
2783
  Unit,
2540
2784
  "onCreate",