warscript 0.0.1-dev.0a43a35 → 0.0.1-dev.0d4b872

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 (193) hide show
  1. package/attributes.d.ts +5 -0
  2. package/attributes.lua +8 -1
  3. package/binaryreader.d.ts +1 -0
  4. package/binaryreader.lua +3 -0
  5. package/config.d.ts +5 -0
  6. package/config.lua +10 -0
  7. package/core/types/effect.d.ts +14 -6
  8. package/core/types/effect.lua +131 -35
  9. package/core/types/frame.d.ts +8 -0
  10. package/core/types/frame.lua +93 -1
  11. package/core/types/order.d.ts +1 -0
  12. package/core/types/order.lua +11 -1
  13. package/core/types/sound.d.ts +17 -24
  14. package/core/types/sound.lua +99 -24
  15. package/core/types/timer.d.ts +6 -7
  16. package/core/types/timer.lua +18 -21
  17. package/core/util.d.ts +1 -1
  18. package/core/util.lua +18 -1
  19. package/decl/native.d.ts +840 -786
  20. package/engine/behavior.d.ts +2 -2
  21. package/engine/behavior.lua +6 -6
  22. package/engine/behaviour/ability/always-enabled.d.ts +7 -0
  23. package/engine/behaviour/ability/always-enabled.lua +31 -0
  24. package/engine/behaviour/ability/apply-buff.d.ts +8 -5
  25. package/engine/behaviour/ability/apply-buff.lua +32 -0
  26. package/engine/behaviour/ability/apply-unit-behavior.lua +1 -0
  27. package/engine/behaviour/ability/damage.d.ts +39 -11
  28. package/engine/behaviour/ability/damage.lua +83 -37
  29. package/engine/behaviour/ability/emulate-impact.d.ts +6 -0
  30. package/engine/behaviour/ability/emulate-impact.lua +42 -0
  31. package/engine/behaviour/ability/heal.d.ts +33 -6
  32. package/engine/behaviour/ability/heal.lua +89 -10
  33. package/engine/behaviour/ability/instant-impact.d.ts +2 -2
  34. package/engine/behaviour/ability/instant-impact.lua +4 -19
  35. package/engine/behaviour/ability/on-command-impact.d.ts +8 -0
  36. package/engine/behaviour/ability/on-command-impact.lua +25 -0
  37. package/engine/behaviour/ability/remove-buffs.d.ts +16 -0
  38. package/engine/behaviour/ability/remove-buffs.lua +28 -0
  39. package/engine/behaviour/ability/restore-mana.d.ts +15 -0
  40. package/engine/behaviour/ability/restore-mana.lua +29 -0
  41. package/engine/behaviour/ability.d.ts +20 -4
  42. package/engine/behaviour/ability.lua +112 -39
  43. package/engine/behaviour/unit.d.ts +22 -0
  44. package/engine/behaviour/unit.lua +134 -4
  45. package/engine/buff.d.ts +101 -39
  46. package/engine/buff.lua +458 -203
  47. package/engine/game-map.d.ts +7 -0
  48. package/engine/game-map.lua +32 -0
  49. package/engine/internal/ability.d.ts +20 -13
  50. package/engine/internal/ability.lua +97 -76
  51. package/engine/internal/item/ability.lua +112 -4
  52. package/engine/internal/item+owner.lua +2 -2
  53. package/engine/internal/item.d.ts +7 -4
  54. package/engine/internal/item.lua +131 -28
  55. package/engine/internal/mechanics/ability-duration.lua +1 -1
  56. package/engine/internal/misc/ability-disable-counter.d.ts +2 -0
  57. package/engine/internal/misc/ability-disable-counter.lua +13 -0
  58. package/engine/internal/misc/damage-metadata-by-target.d.ts +2 -0
  59. package/engine/internal/misc/damage-metadata-by-target.lua +5 -0
  60. package/engine/internal/object-data/auto-attack-speed-increase.d.ts +1 -1
  61. package/engine/internal/object-data/auto-attack-speed-increase.lua +2 -0
  62. package/engine/internal/object-data/evasion-probability.d.ts +2 -0
  63. package/engine/internal/object-data/evasion-probability.lua +16 -0
  64. package/engine/internal/unit/ability.d.ts +15 -1
  65. package/engine/internal/unit/ability.lua +50 -14
  66. package/engine/internal/unit/add-item-to-slot-init.d.ts +2 -0
  67. package/engine/internal/unit/add-item-to-slot-init.lua +23 -0
  68. package/engine/internal/unit/add-item-to-slot.d.ts +2 -0
  69. package/engine/internal/unit/add-item-to-slot.lua +52 -0
  70. package/engine/internal/unit/allowed-targets.d.ts +1 -1
  71. package/engine/internal/unit/allowed-targets.lua +9 -1
  72. package/engine/internal/unit/bonus.d.ts +6 -2
  73. package/engine/internal/unit/bonus.lua +23 -1
  74. package/engine/internal/unit/ignore-events-items.d.ts +2 -0
  75. package/engine/internal/unit/ignore-events-items.lua +5 -0
  76. package/engine/internal/unit/item.d.ts +24 -0
  77. package/engine/internal/unit/item.lua +78 -0
  78. package/engine/internal/unit/main-selected.d.ts +13 -0
  79. package/engine/internal/unit/main-selected.lua +51 -0
  80. package/engine/internal/unit+ability.lua +2 -2
  81. package/engine/internal/unit+damage.d.ts +2 -11
  82. package/engine/internal/unit+damage.lua +10 -14
  83. package/engine/internal/unit+spellSteal.lua +1 -2
  84. package/engine/internal/unit+transport.lua +4 -10
  85. package/engine/internal/unit-missile-launch.lua +25 -6
  86. package/engine/internal/unit.d.ts +51 -13
  87. package/engine/internal/unit.lua +340 -124
  88. package/engine/internal/utility.lua +12 -0
  89. package/engine/lightning.d.ts +12 -5
  90. package/engine/lightning.lua +48 -14
  91. package/engine/local-client.d.ts +7 -2
  92. package/engine/local-client.lua +82 -0
  93. package/engine/object-data/auxiliary/animation-name.d.ts +1 -0
  94. package/engine/object-data/auxiliary/animation-name.lua +16 -0
  95. package/engine/object-data/auxiliary/attachment-preset.d.ts +7 -2
  96. package/engine/object-data/auxiliary/attachment-preset.lua +4 -3
  97. package/engine/object-data/auxiliary/attack-type.d.ts +7 -8
  98. package/engine/object-data/auxiliary/attack-type.lua +42 -0
  99. package/engine/object-data/auxiliary/movement-type.d.ts +7 -7
  100. package/engine/object-data/auxiliary/movement-type.lua +22 -0
  101. package/engine/object-data/auxiliary/sound-eax.d.ts +10 -0
  102. package/engine/object-data/auxiliary/sound-eax.lua +2 -0
  103. package/engine/object-data/auxiliary/sound-preset-name.d.ts +5 -1
  104. package/engine/object-data/auxiliary/tech-tree-dependency.d.ts +1 -1
  105. package/engine/object-data/auxiliary/unit-attribute.d.ts +6 -0
  106. package/engine/object-data/auxiliary/unit-attribute.lua +9 -0
  107. package/engine/object-data/entry/ability-type/berserk.d.ts +2 -0
  108. package/engine/object-data/entry/ability-type/berserk.lua +13 -0
  109. package/engine/object-data/entry/ability-type/blank-configurable.lua +12 -1
  110. package/engine/object-data/entry/ability-type/carrion-swarm.d.ts +14 -0
  111. package/engine/object-data/entry/ability-type/carrion-swarm.lua +65 -0
  112. package/engine/object-data/entry/ability-type/disease-cloud.lua +2 -2
  113. package/engine/object-data/entry/ability-type/engineering-upgrade.lua +2 -2
  114. package/engine/object-data/entry/ability-type/ensnare.d.ts +12 -0
  115. package/engine/object-data/entry/ability-type/ensnare.lua +52 -0
  116. package/engine/object-data/entry/ability-type/feral-spirit.lua +2 -2
  117. package/engine/object-data/entry/ability-type/permanent-invisibility.d.ts +8 -0
  118. package/engine/object-data/entry/ability-type/permanent-invisibility.lua +26 -0
  119. package/engine/object-data/entry/ability-type/phase-shift.d.ts +10 -0
  120. package/engine/object-data/entry/ability-type/phase-shift.lua +39 -0
  121. package/engine/object-data/entry/ability-type/phoenix-morph.lua +4 -4
  122. package/engine/object-data/entry/ability-type/raise-dead.d.ts +17 -0
  123. package/engine/object-data/entry/ability-type/raise-dead.lua +78 -0
  124. package/engine/object-data/entry/ability-type/shock-wave.d.ts +4 -0
  125. package/engine/object-data/entry/ability-type/shock-wave.lua +26 -0
  126. package/engine/object-data/entry/ability-type/slow-poison.d.ts +10 -0
  127. package/engine/object-data/entry/ability-type/slow-poison.lua +58 -0
  128. package/engine/object-data/entry/ability-type/summon-quilbeast.lua +2 -2
  129. package/engine/object-data/entry/ability-type/summon-water-elemental.lua +2 -2
  130. package/engine/object-data/entry/ability-type/web.d.ts +12 -0
  131. package/engine/object-data/entry/ability-type/web.lua +52 -0
  132. package/engine/object-data/entry/ability-type.d.ts +19 -17
  133. package/engine/object-data/entry/ability-type.lua +89 -33
  134. package/engine/object-data/entry/buff-type/applicable.lua +18 -37
  135. package/engine/object-data/entry/buff-type.d.ts +6 -12
  136. package/engine/object-data/entry/buff-type.lua +13 -29
  137. package/engine/object-data/entry/destructible-type.d.ts +1 -1
  138. package/engine/object-data/entry/item-type.d.ts +15 -1
  139. package/engine/object-data/entry/item-type.lua +93 -2
  140. package/engine/object-data/entry/lightning-type.d.ts +1 -1
  141. package/engine/object-data/entry/sound-preset.d.ts +33 -0
  142. package/engine/object-data/entry/sound-preset.lua +140 -0
  143. package/engine/object-data/entry/unit-type.d.ts +10 -3
  144. package/engine/object-data/entry/unit-type.lua +155 -92
  145. package/engine/object-data/entry/upgrade.d.ts +1 -1
  146. package/engine/object-data/entry/upgrade.lua +4 -4
  147. package/engine/object-data/entry.d.ts +16 -14
  148. package/engine/object-data/entry.lua +60 -32
  149. package/engine/object-data/utility/object-data-entry-id-generator.lua +7 -0
  150. package/engine/object-field/ability.d.ts +26 -3
  151. package/engine/object-field/ability.lua +54 -1
  152. package/engine/object-field/unit.d.ts +46 -3
  153. package/engine/object-field/unit.lua +173 -7
  154. package/engine/object-field.d.ts +15 -6
  155. package/engine/object-field.lua +170 -79
  156. package/engine/standard/entries/buff-type.d.ts +3 -0
  157. package/engine/standard/entries/buff-type.lua +3 -0
  158. package/engine/standard/entries/sound-preset.d.ts +10 -0
  159. package/engine/standard/entries/sound-preset.lua +10 -0
  160. package/engine/standard/fields/ability.d.ts +2 -0
  161. package/engine/standard/fields/ability.lua +2 -0
  162. package/engine/unit.d.ts +3 -0
  163. package/engine/unit.lua +3 -0
  164. package/index.d.ts +1 -0
  165. package/index.lua +1 -0
  166. package/lualib_bundle.lua +7 -2
  167. package/net/socket.d.ts +7 -1
  168. package/net/socket.lua +45 -4
  169. package/network.d.ts +1 -0
  170. package/network.lua +3 -2
  171. package/objutil/buff.lua +2 -3
  172. package/objutil/unit.lua +8 -0
  173. package/package.json +2 -2
  174. package/patch-lua.d.ts +0 -0
  175. package/patch-lua.lua +10 -0
  176. package/property.d.ts +55 -0
  177. package/property.lua +374 -0
  178. package/utility/arrays.d.ts +9 -1
  179. package/utility/arrays.lua +37 -3
  180. package/utility/functions.d.ts +1 -0
  181. package/utility/functions.lua +1 -0
  182. package/utility/lazy.d.ts +2 -0
  183. package/utility/lazy.lua +14 -0
  184. package/utility/linked-set.d.ts +12 -2
  185. package/utility/linked-set.lua +8 -2
  186. package/utility/lua-maps.d.ts +3 -0
  187. package/utility/lua-maps.lua +16 -0
  188. package/utility/lua-sets.d.ts +1 -0
  189. package/utility/lua-sets.lua +3 -0
  190. package/utility/reflection.lua +11 -7
  191. package/utility/types.d.ts +1 -0
  192. package/core/mapbounds.d.ts +0 -8
  193. package/core/mapbounds.lua +0 -12
@@ -51,12 +51,19 @@ 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
54
63
  local match = string.match
55
64
  local ____tostring = _G.tostring
56
65
  local setUnitAnimation = SetUnitAnimation
57
- local setUnitAnimationWithRarity = SetUnitAnimationWithRarity
58
66
  local setUnitAnimationByIndex = SetUnitAnimationByIndex
59
- local queueUnitAnimation = QueueUnitAnimation
60
67
  local getUnitIntegerField = BlzGetUnitIntegerField
61
68
  local getUnitRealField = BlzGetUnitRealField
62
69
  local getHeroStr = GetHeroStr
@@ -75,9 +82,9 @@ local setUnitScale = SetUnitScale
75
82
  local setUnitPosition = SetUnitPosition
76
83
  local setUnitTimeScale = SetUnitTimeScale
77
84
  local getHandleId = GetHandleId
85
+ local getUnitCurrentOrder = GetUnitCurrentOrder
78
86
  local createUnit = CreateUnit
79
87
  local killUnit = KillUnit
80
- local setUnitExploded = SetUnitExploded
81
88
  local removeUnit = RemoveUnit
82
89
  local getUnitTypeId = GetUnitTypeId
83
90
  local isHeroUnitId = IsHeroUnitId
@@ -93,8 +100,6 @@ local getSpellTargetItem = GetSpellTargetItem
93
100
  local getSpellTargetDestructable = GetSpellTargetDestructable
94
101
  local isUnitInRangeXY = IsUnitInRangeXY
95
102
  local isUnitInRange = IsUnitInRange
96
- local setResourceAmount = SetResourceAmount
97
- local getResourceAmount = GetResourceAmount
98
103
  local getUnitWeaponRealField = BlzGetUnitWeaponRealField
99
104
  local setUnitWeaponRealField = BlzSetUnitWeaponRealField
100
105
  local getUnitWeaponStringField = BlzGetUnitWeaponStringField
@@ -125,8 +130,6 @@ local isUnitType = IsUnitType
125
130
  local isUnitAlly = IsUnitAlly
126
131
  local isUnitEnemy = IsUnitEnemy
127
132
  local getOwningPlayer = GetOwningPlayer
128
- local setUnitColor = SetUnitColor
129
- local showUnitTeamGlow = BlzShowUnitTeamGlow
130
133
  ____exports.UnitClassification = {}
131
134
  local UnitClassification = ____exports.UnitClassification
132
135
  do
@@ -136,6 +139,7 @@ do
136
139
  UnitClassification.GROUND = UNIT_TYPE_GROUND
137
140
  UnitClassification.SUMMONED = UNIT_TYPE_SUMMONED
138
141
  UnitClassification.MECHANICAL = UNIT_TYPE_MECHANICAL
142
+ UnitClassification.WORKER = UNIT_TYPE_PEON
139
143
  UnitClassification.ANCIENT = UNIT_TYPE_ANCIENT
140
144
  UnitClassification.SUICIDAL = UNIT_TYPE_SAPPER
141
145
  UnitClassification.TAUREN = UNIT_TYPE_TAUREN
@@ -290,7 +294,6 @@ local function dispatch(event, idGetter, argsGetter)
290
294
  return event[id]
291
295
  end
292
296
  if not initialized then
293
- local invoke = Event.invoke
294
297
  event:addListener(function(...)
295
298
  local id = idGetter(...)
296
299
  local dispatched = rawget(self, id)
@@ -328,7 +331,6 @@ local function dispatchAbility(event)
328
331
  return event[id]
329
332
  end
330
333
  if not initialized then
331
- local invoke = Event.invoke
332
334
  event:addListener(function(unit, ability, ...)
333
335
  local dispatched = rawget(self, ability.typeId)
334
336
  if dispatched ~= nil then
@@ -345,6 +347,9 @@ local function dispatchAbility(event)
345
347
  }
346
348
  )
347
349
  end
350
+ local function damagingEventPreventRetaliation(self)
351
+ self[0] = true
352
+ end
348
353
  local function damageEventPreventDeath(self, callback, ...)
349
354
  if self[0] ~= nil then
350
355
  return
@@ -356,7 +361,14 @@ local function damageEventPreventDeath(self, callback, ...)
356
361
  rawset(self, 1 + i, (select(i, ...)))
357
362
  end
358
363
  end
359
- local damageSetters = {amount = BlzSetEventDamage, attackType = BlzSetEventAttackType, damageType = BlzSetEventDamageType, weaponType = BlzSetEventWeaponType}
364
+ local damageSetters = {
365
+ amount = BlzSetEventDamage,
366
+ attackType = function(attackType)
367
+ return BlzSetEventAttackType(attackTypeToNative(attackType))
368
+ end,
369
+ damageType = BlzSetEventDamageType,
370
+ weaponType = BlzSetEventWeaponType
371
+ }
360
372
  local jlimitopByOperator = {
361
373
  [0] = LESS_THAN_OR_EQUAL,
362
374
  [1] = LESS_THAN_OR_EQUAL,
@@ -434,6 +446,19 @@ __TS__SetDescriptor(
434
446
  },
435
447
  true
436
448
  )
449
+ __TS__SetDescriptor(
450
+ UnitWeapon.prototype,
451
+ "allowedTargetCombatClassifications",
452
+ {
453
+ get = function(self)
454
+ return BlzGetUnitWeaponIntegerField(self.unit.handle, UNIT_WEAPON_IF_ATTACK_TARGETS_ALLOWED, self.index)
455
+ end,
456
+ set = function(self, allowedTargetCombatClassifications)
457
+ BlzSetUnitWeaponIntegerField(self.unit.handle, UNIT_WEAPON_IF_ATTACK_TARGETS_ALLOWED, self.index, allowedTargetCombatClassifications)
458
+ end
459
+ },
460
+ true
461
+ )
437
462
  __TS__SetDescriptor(
438
463
  UnitWeapon.prototype,
439
464
  "damageBase",
@@ -564,17 +589,6 @@ local function retrieveAbility(unit, ability, abilityId)
564
589
  ____exports.Unit:of(unit)
565
590
  )
566
591
  end
567
- if not unitAddAbility(unit, abilityId) then
568
- if getUnitAbility(unit, abilityId) == ability then
569
- return UnitAbility:of(
570
- ability,
571
- abilityId,
572
- ____exports.Unit:of(unit)
573
- )
574
- end
575
- else
576
- unitRemoveAbility(unit, abilityId)
577
- end
578
592
  for i = 0, unitInventorySize(unit) - 1 do
579
593
  local item = unitItemInSlot(unit, i)
580
594
  if getItemAbility(item, abilityId) == ability then
@@ -632,15 +646,15 @@ for ____, player in ipairs(Player.all) do
632
646
  dummies[player] = dummy
633
647
  end
634
648
  local function delayHealthChecksCallback(unit)
635
- local counter = (unit[102] or 0) - 1
649
+ local counter = (unit[103] or 0) - 1
636
650
  if counter ~= 0 then
637
- unit[102] = counter
651
+ unit[103] = counter
638
652
  return
639
653
  end
640
- unit[102] = nil
641
- local healthBonus = unit[103]
654
+ unit[103] = nil
655
+ local healthBonus = unit[104]
642
656
  if healthBonus ~= nil then
643
- unit[103] = nil
657
+ unit[104] = nil
644
658
  local handle = unit.handle
645
659
  BlzSetUnitMaxHP(
646
660
  handle,
@@ -648,12 +662,18 @@ local function delayHealthChecksCallback(unit)
648
662
  )
649
663
  end
650
664
  end
665
+ local nextSyncId = 1
666
+ local unitBySyncId = setmetatable({}, {__mode = "v"})
667
+ local damagingEventByTarget = setmetatable({}, {__mode = "k"})
651
668
  ____exports.Unit = __TS__Class()
652
669
  local Unit = ____exports.Unit
653
670
  Unit.name = "Unit"
654
671
  __TS__ClassExtends(Unit, Handle)
655
672
  function Unit.prototype.____constructor(self, handle)
656
673
  Handle.prototype.____constructor(self, handle)
674
+ local ____nextSyncId_0 = nextSyncId
675
+ nextSyncId = ____nextSyncId_0 + 1
676
+ self.syncId = ____nextSyncId_0
657
677
  self._owner = Player:of(getOwningPlayer(handle))
658
678
  assert(unitAddAbility(handle, leaveDetectAbilityId) and UnitMakeAbilityPermanent(handle, true, leaveDetectAbilityId))
659
679
  assert(unitAddAbility(handle, morphDetectAbilityId))
@@ -666,6 +686,7 @@ function Unit.prototype.____constructor(self, handle)
666
686
  fourCC("Amrf")
667
687
  ))
668
688
  end
689
+ unitBySyncId[self.syncId] = self
669
690
  local ____ = self.abilities
670
691
  end
671
692
  function Unit.prototype.getEvent(self, event, collector)
@@ -684,6 +705,8 @@ function Unit.prototype.getEvent(self, event, collector)
684
705
  end
685
706
  function Unit.prototype.onDestroy(self)
686
707
  local handle = self.handle
708
+ self[107] = getUnitX(handle)
709
+ self[108] = getUnitY(handle)
687
710
  if not self._owner then
688
711
  self._owner = Player:of(getOwningPlayer(handle))
689
712
  end
@@ -706,6 +729,10 @@ function Unit.prototype.onDestroy(self)
706
729
  if eventsToDestroy ~= nil then
707
730
  forEach(eventsToDestroy, "destroy")
708
731
  end
732
+ if getUnitAbilityLevel(handle, leaveDetectAbilityId) > 0 then
733
+ unitRemoveAbility(handle, leaveDetectAbilityId)
734
+ removeUnit(handle)
735
+ end
709
736
  return Handle.prototype.onDestroy(self)
710
737
  end
711
738
  function Unit.prototype.addAttackHandler(self, condition, action)
@@ -747,8 +774,8 @@ function Unit.prototype.addModifier(self, property, modifier)
747
774
  end}
748
775
  end
749
776
  function Unit.prototype.hasCombatClassification(self, combatClassification)
750
- local ____combatClassification_0 = combatClassification
751
- return getUnitIntegerField(self.handle, UNIT_IF_TARGETED_AS) & ____combatClassification_0 == ____combatClassification_0
777
+ local ____combatClassification_1 = combatClassification
778
+ return getUnitIntegerField(self.handle, UNIT_IF_TARGETED_AS) & ____combatClassification_1 == ____combatClassification_1
752
779
  end
753
780
  function Unit.prototype.addClassification(self, classification)
754
781
  return unitAddType(self.handle, classification)
@@ -766,13 +793,13 @@ function Unit.prototype.isInvisibleTo(self, player)
766
793
  return isUnitInvisible(self.handle, player.handle)
767
794
  end
768
795
  function Unit.prototype.isInRangeOf(self, x, y, range)
769
- local ____temp_1
796
+ local ____temp_2
770
797
  if type(x) == "number" then
771
- ____temp_1 = isUnitInRangeXY(self.handle, x, y, range)
798
+ ____temp_2 = isUnitInRangeXY(self.handle, x, y, range)
772
799
  else
773
- ____temp_1 = isUnitInRange(self.handle, x.handle, y)
800
+ ____temp_2 = isUnitInRange(self.handle, x.handle, y)
774
801
  end
775
- return ____temp_1
802
+ return ____temp_2
776
803
  end
777
804
  function Unit.prototype.isAllyOf(self, unit)
778
805
  return isUnitAlly(
@@ -790,16 +817,28 @@ function Unit.prototype.playAnimation(self, animation, rarity)
790
817
  if type(animation) == "number" then
791
818
  setUnitAnimationByIndex(self.handle, animation)
792
819
  elseif rarity then
793
- setUnitAnimationWithRarity(self.handle, animation, rarity)
820
+ SetUnitAnimationWithRarity(self.handle, animation, rarity)
794
821
  else
795
822
  setUnitAnimation(self.handle, animation)
796
823
  end
797
824
  end
825
+ function Unit.prototype.resetAnimation(self)
826
+ ResetUnitAnimation(self.handle)
827
+ end
798
828
  function Unit.prototype.queueAnimation(self, animation)
799
- queueUnitAnimation(self.handle, animation)
829
+ QueueUnitAnimation(self.handle, animation)
830
+ end
831
+ function Unit.prototype.chooseWeapon(self, target)
832
+ if target:isAllowedTarget(self, self.firstWeapon.allowedTargetCombatClassifications) then
833
+ return self.firstWeapon
834
+ end
835
+ if target:isAllowedTarget(target, self.secondWeapon.allowedTargetCombatClassifications) then
836
+ return self.secondWeapon
837
+ end
838
+ return nil
800
839
  end
801
840
  function Unit.prototype.delayHealthChecks(self)
802
- self[102] = (self[102] or 0) + 1
841
+ self[103] = (self[103] or 0) + 1
803
842
  Timer:run(delayHealthChecksCallback, self)
804
843
  end
805
844
  function Unit.prototype.setPosition(self, x, y)
@@ -809,21 +848,21 @@ function Unit.prototype.isSelected(self, player)
809
848
  return IsUnitSelected(self.handle, player.handle)
810
849
  end
811
850
  function Unit.prototype.explode(self)
812
- setUnitExploded(self.handle, true)
851
+ SetUnitExploded(self.handle, true)
813
852
  killUnit(self.handle)
814
853
  end
815
854
  function Unit.prototype.kill(self)
816
855
  killUnit(self.handle)
817
856
  end
818
857
  function Unit.prototype.revive(self, x, y, doEffect)
819
- local ____ReviveHero_4 = ReviveHero
820
- local ____array_3 = __TS__SparseArrayNew(self.handle, x, y)
821
- local ____doEffect_2 = doEffect
822
- if ____doEffect_2 == nil then
823
- ____doEffect_2 = false
858
+ local ____ReviveHero_5 = ReviveHero
859
+ local ____array_4 = __TS__SparseArrayNew(self.handle, x, y)
860
+ local ____doEffect_3 = doEffect
861
+ if ____doEffect_3 == nil then
862
+ ____doEffect_3 = false
824
863
  end
825
- __TS__SparseArrayPush(____array_3, ____doEffect_2)
826
- ____ReviveHero_4(__TS__SparseArraySpread(____array_3))
864
+ __TS__SparseArrayPush(____array_4, ____doEffect_3)
865
+ ____ReviveHero_5(__TS__SparseArraySpread(____array_4))
827
866
  end
828
867
  function Unit.prototype.healTarget(self, target, amount)
829
868
  if __TS__InstanceOf(target, ____exports.Unit) and target:hasAbility(fourCC("BIhm")) then
@@ -863,7 +902,7 @@ function Unit.prototype.dropItemSlot(self, item, slot)
863
902
  return UnitDropItemSlot(self.handle, item.handle, slot)
864
903
  end
865
904
  function Unit.prototype.itemInSlot(self, slot)
866
- return Item:of(UnitItemInSlot(self.handle, slot))
905
+ return Item:of(unitItemInSlot(self.handle, slot))
867
906
  end
868
907
  function Unit.prototype.addAbility(self, abilityId)
869
908
  if unitAddAbility(self.handle, abilityId) then
@@ -932,8 +971,15 @@ function Unit.prototype.interruptAttack(self)
932
971
  unitInterruptAttack(self.handle)
933
972
  end
934
973
  function Unit.prototype.interruptCast(self, abilityId)
935
- unitDisableAbility(self.handle, abilityId, true, false)
936
- unitDisableAbility(self.handle, abilityId, false, false)
974
+ local handle = self.handle
975
+ unitDisableAbility(handle, abilityId, true, false)
976
+ Timer:run(
977
+ unitDisableAbility,
978
+ handle,
979
+ abilityId,
980
+ false,
981
+ false
982
+ )
937
983
  end
938
984
  function Unit.prototype.getDistanceTo(self, target)
939
985
  local handle = self.handle
@@ -993,18 +1039,18 @@ function Unit.prototype.unpauseEx(self)
993
1039
  self:decrementStunCounter()
994
1040
  end
995
1041
  function Unit.prototype.incrementStunCounter(self)
996
- local stunCounter = self[101] or 0
997
- if not self[100] or stunCounter >= 0 then
1042
+ local stunCounter = self[102] or 0
1043
+ if not self[101] or stunCounter >= 0 then
998
1044
  BlzPauseUnitEx(self.handle, true)
999
1045
  end
1000
- self[101] = stunCounter + 1
1046
+ self[102] = stunCounter + 1
1001
1047
  end
1002
1048
  function Unit.prototype.decrementStunCounter(self)
1003
- local stunCounter = self[101] or 0
1004
- if not self[100] or stunCounter >= 1 then
1049
+ local stunCounter = self[102] or 0
1050
+ if not self[101] or stunCounter >= 1 then
1005
1051
  BlzPauseUnitEx(self.handle, false)
1006
1052
  end
1007
- self[101] = stunCounter - 1
1053
+ self[102] = stunCounter - 1
1008
1054
  end
1009
1055
  function Unit.create(self, owner, id, x, y, facing, skinId)
1010
1056
  local handle = skinId and BlzCreateUnitWithSkin(
@@ -1106,8 +1152,11 @@ function Unit.getInSector(self, pos, range, offsetAngle, centralAngle)
1106
1152
  )
1107
1153
  return targetCollection
1108
1154
  end
1109
- function Unit.getSelectionOf(self, player)
1110
- targetCollection = {}
1155
+ function Unit.getSelectionOf(self, player, target)
1156
+ if target == nil then
1157
+ target = {}
1158
+ end
1159
+ targetCollection = target
1111
1160
  targetCollectionNextIndex = 1
1112
1161
  GroupEnumUnitsSelected(dummyGroup, player.handle, collectIntoTarget)
1113
1162
  return targetCollection
@@ -1129,6 +1178,9 @@ end
1129
1178
  function Unit.prototype.__tostring(self)
1130
1179
  return (((self.constructor.name .. "$") .. util.id2s(self.typeId)) .. "@") .. tostring(getHandleId(self.handle))
1131
1180
  end
1181
+ function Unit.getBySyncId(self, syncId)
1182
+ return unitBySyncId[syncId]
1183
+ end
1132
1184
  __TS__SetDescriptor(
1133
1185
  Unit.prototype,
1134
1186
  "_deltas",
@@ -1192,6 +1244,14 @@ __TS__SetDescriptor(
1192
1244
  end},
1193
1245
  true
1194
1246
  )
1247
+ __TS__SetDescriptor(
1248
+ Unit.prototype,
1249
+ "isStunned",
1250
+ {get = function(self)
1251
+ return getUnitCurrentOrder(self.handle) == orderId("stunned")
1252
+ end},
1253
+ true
1254
+ )
1195
1255
  __TS__SetDescriptor(
1196
1256
  Unit.prototype,
1197
1257
  "combatClassifications",
@@ -1265,6 +1325,19 @@ __TS__SetDescriptor(
1265
1325
  },
1266
1326
  true
1267
1327
  )
1328
+ __TS__SetDescriptor(
1329
+ Unit.prototype,
1330
+ "primaryAttribute",
1331
+ {
1332
+ get = function(self)
1333
+ return getUnitIntegerField(self.handle, UNIT_IF_PRIMARY_ATTRIBUTE)
1334
+ end,
1335
+ set = function(self, primaryAttribute)
1336
+ setUnitIntegerField(self.handle, UNIT_IF_PRIMARY_ATTRIBUTE, primaryAttribute)
1337
+ end
1338
+ },
1339
+ true
1340
+ )
1268
1341
  __TS__SetDescriptor(
1269
1342
  Unit.prototype,
1270
1343
  "strengthBase",
@@ -1386,17 +1459,17 @@ __TS__SetDescriptor(
1386
1459
  "isTeamGlowVisible",
1387
1460
  {
1388
1461
  get = function(self)
1389
- return not self[105]
1462
+ return not self[106]
1390
1463
  end,
1391
1464
  set = function(self, isTeamGlowVisible)
1392
- showUnitTeamGlow(self.handle, isTeamGlowVisible)
1393
- local ____temp_5
1465
+ BlzShowUnitTeamGlow(self.handle, isTeamGlowVisible)
1466
+ local ____temp_6
1394
1467
  if not isTeamGlowVisible then
1395
- ____temp_5 = true
1468
+ ____temp_6 = true
1396
1469
  else
1397
- ____temp_5 = nil
1470
+ ____temp_6 = nil
1398
1471
  end
1399
- self[105] = ____temp_5
1472
+ self[106] = ____temp_6
1400
1473
  end
1401
1474
  },
1402
1475
  true
@@ -1405,9 +1478,9 @@ __TS__SetDescriptor(
1405
1478
  Unit.prototype,
1406
1479
  "color",
1407
1480
  {set = function(self, color)
1408
- setUnitColor(self.handle, color.handle)
1409
- if self[105] then
1410
- showUnitTeamGlow(self.handle, false)
1481
+ SetUnitColor(self.handle, color.handle)
1482
+ if self[106] then
1483
+ BlzShowUnitTeamGlow(self.handle, false)
1411
1484
  end
1412
1485
  end},
1413
1486
  true
@@ -1430,14 +1503,14 @@ __TS__SetDescriptor(
1430
1503
  "maxHealth",
1431
1504
  {
1432
1505
  get = function(self)
1433
- return BlzGetUnitMaxHP(self.handle) - (self[103] or 0) - (self[104] or 0)
1506
+ return BlzGetUnitMaxHP(self.handle) - (self[104] or 0) - (self[105] or 0)
1434
1507
  end,
1435
1508
  set = function(self, maxHealth)
1436
- if maxHealth < 1 and self[102] ~= nil then
1437
- self[103] = (self[103] or 0) + (1 - maxHealth)
1509
+ if maxHealth < 1 and self[103] ~= nil then
1510
+ self[104] = (self[104] or 0) + (1 - maxHealth)
1438
1511
  maxHealth = 1
1439
1512
  end
1440
- BlzSetUnitMaxHP(self.handle, maxHealth + (self[104] or 0))
1513
+ BlzSetUnitMaxHP(self.handle, maxHealth + (self[105] or 0))
1441
1514
  end
1442
1515
  },
1443
1516
  true
@@ -1479,10 +1552,10 @@ __TS__SetDescriptor(
1479
1552
  "health",
1480
1553
  {
1481
1554
  get = function(self)
1482
- return GetWidgetLife(self.handle) - (self[104] or 0)
1555
+ return GetWidgetLife(self.handle) - (self[105] or 0)
1483
1556
  end,
1484
1557
  set = function(self, health)
1485
- SetWidgetLife(self.handle, health + (self[104] or 0))
1558
+ SetWidgetLife(self.handle, health + (self[105] or 0))
1486
1559
  end
1487
1560
  },
1488
1561
  true
@@ -1576,7 +1649,7 @@ __TS__SetDescriptor(
1576
1649
  "x",
1577
1650
  {
1578
1651
  get = function(self)
1579
- return getUnitX(self.handle)
1652
+ return self[107] or getUnitX(self.handle)
1580
1653
  end,
1581
1654
  set = function(self, v)
1582
1655
  SetUnitX(self.handle, v)
@@ -1589,7 +1662,7 @@ __TS__SetDescriptor(
1589
1662
  "y",
1590
1663
  {
1591
1664
  get = function(self)
1592
- return getUnitY(self.handle)
1665
+ return self[108] or getUnitY(self.handle)
1593
1666
  end,
1594
1667
  set = function(self, v)
1595
1668
  SetUnitY(self.handle, v)
@@ -1675,10 +1748,10 @@ __TS__SetDescriptor(
1675
1748
  "gold",
1676
1749
  {
1677
1750
  get = function(self)
1678
- return getResourceAmount(self.handle)
1751
+ return GetResourceAmount(self.handle)
1679
1752
  end,
1680
1753
  set = function(self, gold)
1681
- setResourceAmount(self.handle, gold)
1754
+ SetResourceAmount(self.handle, gold)
1682
1755
  end
1683
1756
  },
1684
1757
  true
@@ -1693,17 +1766,17 @@ __TS__SetDescriptor(
1693
1766
  set = function(self, isPaused)
1694
1767
  local handle = self.handle
1695
1768
  if isPaused and not IsUnitPaused(handle) then
1696
- self[100] = true
1697
- for _ = self[101] or 0, -1 do
1769
+ self[101] = true
1770
+ for _ = self[102] or 0, -1 do
1698
1771
  BlzPauseUnitEx(handle, true)
1699
1772
  end
1700
1773
  PauseUnit(handle, true)
1701
1774
  elseif not isPaused and IsUnitPaused(handle) then
1702
1775
  PauseUnit(handle, false)
1703
- for _ = self[101] or 0, -1 do
1776
+ for _ = self[102] or 0, -1 do
1704
1777
  BlzPauseUnitEx(handle, false)
1705
1778
  end
1706
- self[100] = nil
1779
+ self[101] = nil
1707
1780
  end
1708
1781
  end
1709
1782
  },
@@ -1806,6 +1879,19 @@ __TS__SetDescriptor(
1806
1879
  end},
1807
1880
  true
1808
1881
  )
1882
+ __TS__SetDescriptor(
1883
+ Unit.prototype,
1884
+ "movementType",
1885
+ {
1886
+ get = function(self)
1887
+ return getUnitIntegerField(self.handle, UNIT_IF_MOVE_TYPE)
1888
+ end,
1889
+ set = function(self, movementType)
1890
+ setUnitIntegerField(self.handle, UNIT_IF_MOVE_TYPE, movementType)
1891
+ end
1892
+ },
1893
+ true
1894
+ )
1809
1895
  __TS__SetDescriptor(
1810
1896
  Unit.prototype,
1811
1897
  "pathing",
@@ -1987,6 +2073,14 @@ __TS__SetDescriptor(
1987
2073
  end},
1988
2074
  true
1989
2075
  )
2076
+ __TS__SetDescriptor(
2077
+ Unit.prototype,
2078
+ "targetAcquiredEvent",
2079
+ {get = function(self)
2080
+ return self:getEvent(EVENT_UNIT_ACQUIRED_TARGET)
2081
+ end},
2082
+ true
2083
+ )
1990
2084
  __TS__SetDescriptor(
1991
2085
  Unit.prototype,
1992
2086
  "onSelect",
@@ -2060,7 +2154,6 @@ Unit.onDecay = __TS__New(
2060
2154
  Unit.onResurrect = __TS__New(
2061
2155
  InitializingEvent,
2062
2156
  function(event)
2063
- local invoke = Event.invoke
2064
2157
  local dead = setmetatable({}, {__mode = "k"})
2065
2158
  ____exports.Unit.deathEvent:addListener(function(unit)
2066
2159
  dead[unit] = true
@@ -2076,10 +2169,15 @@ Unit.onResurrect = __TS__New(
2076
2169
  Unit.morphEvent = __TS__New(
2077
2170
  InitializingEvent,
2078
2171
  function(event)
2172
+ local function ifNotLeft(unit)
2173
+ local handle = unit.handle
2174
+ if getUnitAbilityLevel(handle, leaveDetectAbilityId) ~= 0 and unitAddAbility(handle, morphDetectAbilityId) then
2175
+ invoke(event, unit)
2176
+ end
2177
+ end
2079
2178
  ____exports.Unit.onImmediateOrder[orderId("undefend")]:addListener(function(unit)
2080
2179
  if getUnitAbilityLevel(unit.handle, morphDetectAbilityId) == 0 then
2081
- assert(unitAddAbility(unit.handle, morphDetectAbilityId))
2082
- Timer:run(Event.invoke, event, unit)
2180
+ Timer:run(ifNotLeft, unit)
2083
2181
  end
2084
2182
  end)
2085
2183
  end
@@ -2117,27 +2215,26 @@ Unit.onSpellEffect = dispatchId(__TS__New(
2117
2215
  Unit.onTargetCast = dispatchId(__TS__New(
2118
2216
  InitializingEvent,
2119
2217
  function(event)
2120
- local invoke = Event.invoke
2121
2218
  local function listener(unit, id)
2122
- local ____GetSpellTargetUnit_result_8
2219
+ local ____GetSpellTargetUnit_result_9
2123
2220
  if GetSpellTargetUnit() then
2124
- ____GetSpellTargetUnit_result_8 = ____exports.Unit:of(GetSpellTargetUnit())
2221
+ ____GetSpellTargetUnit_result_9 = ____exports.Unit:of(GetSpellTargetUnit())
2125
2222
  else
2126
- local ____GetSpellTargetItem_result_7
2223
+ local ____GetSpellTargetItem_result_8
2127
2224
  if GetSpellTargetItem() then
2128
- ____GetSpellTargetItem_result_7 = Item:of(GetSpellTargetItem())
2225
+ ____GetSpellTargetItem_result_8 = Item:of(GetSpellTargetItem())
2129
2226
  else
2130
- local ____GetSpellTargetDestructable_result_6
2227
+ local ____GetSpellTargetDestructable_result_7
2131
2228
  if GetSpellTargetDestructable() then
2132
- ____GetSpellTargetDestructable_result_6 = Destructable:of(GetSpellTargetDestructable())
2229
+ ____GetSpellTargetDestructable_result_7 = Destructable:of(GetSpellTargetDestructable())
2133
2230
  else
2134
- ____GetSpellTargetDestructable_result_6 = nil
2231
+ ____GetSpellTargetDestructable_result_7 = nil
2135
2232
  end
2136
- ____GetSpellTargetItem_result_7 = ____GetSpellTargetDestructable_result_6
2233
+ ____GetSpellTargetItem_result_8 = ____GetSpellTargetDestructable_result_7
2137
2234
  end
2138
- ____GetSpellTargetUnit_result_8 = ____GetSpellTargetItem_result_7
2235
+ ____GetSpellTargetUnit_result_9 = ____GetSpellTargetItem_result_8
2139
2236
  end
2140
- local target = ____GetSpellTargetUnit_result_8
2237
+ local target = ____GetSpellTargetUnit_result_9
2141
2238
  if target then
2142
2239
  invoke(event, unit, id, target)
2143
2240
  end
@@ -2309,10 +2406,12 @@ Unit.onImmediateOrder = dispatchId(__TS__New(
2309
2406
  ____exports.UnitTriggerEvent,
2310
2407
  EVENT_PLAYER_UNIT_ISSUED_ORDER,
2311
2408
  function()
2312
- local unit = ____exports.Unit:of(getOrderedUnit())
2313
- local issuedOrderId = getIssuedOrderId()
2314
- if unit ~= nil and unit.state == 1 then
2315
- return unit, issuedOrderId
2409
+ local handle = getOrderedUnit()
2410
+ if handle ~= nil and getUnitTypeId(handle) ~= dummyUnitId then
2411
+ local unit = ____exports.Unit:of(handle)
2412
+ if unit.state == 1 then
2413
+ return unit, getIssuedOrderId()
2414
+ end
2316
2415
  end
2317
2416
  return IgnoreEvent
2318
2417
  end
@@ -2334,7 +2433,6 @@ Unit.autoAttackStartEvent = __TS__New(
2334
2433
  )
2335
2434
  Unit.onDamaging = (function()
2336
2435
  local event = __TS__New(Event)
2337
- local invoke = Event.invoke
2338
2436
  local trigger = CreateTrigger()
2339
2437
  TriggerRegisterAnyUnitEventBJ(trigger, EVENT_PLAYER_UNIT_DAMAGING)
2340
2438
  TriggerAddCondition(
@@ -2344,13 +2442,19 @@ Unit.onDamaging = (function()
2344
2442
  if source and source.typeId == dummyUnitId then
2345
2443
  source = nil
2346
2444
  end
2347
- local target = BlzGetEventDamageTarget()
2445
+ local target = ____exports.Unit:of(BlzGetEventDamageTarget())
2446
+ local metadata = damageMetadataByTarget[target]
2447
+ damageMetadataByTarget[target] = nil
2348
2448
  local data = {
2349
2449
  amount = GetEventDamage(),
2350
- attackType = BlzGetEventAttackType(),
2450
+ attackType = nativeToAttackType(BlzGetEventAttackType()),
2351
2451
  damageType = BlzGetEventDamageType(),
2352
2452
  weaponType = BlzGetEventWeaponType(),
2353
- isAttack = BlzGetEventIsAttack()
2453
+ metadata = metadata,
2454
+ isAttack = BlzGetEventIsAttack(),
2455
+ originalAmount = GetEventDamage(),
2456
+ originalMetadata = metadata,
2457
+ preventRetaliation = damagingEventPreventRetaliation
2354
2458
  }
2355
2459
  if data.isAttack and source then
2356
2460
  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
@@ -2364,18 +2468,36 @@ Unit.onDamaging = (function()
2364
2468
  invoke(
2365
2469
  event,
2366
2470
  source,
2367
- ____exports.Unit:of(target),
2471
+ target,
2368
2472
  setmetatable(
2369
2473
  {},
2370
2474
  {
2371
2475
  __index = data,
2372
2476
  __newindex = function(self, key, value)
2373
- damageSetters[key](value)
2477
+ local damageSetter = damageSetters[key]
2478
+ if damageSetter ~= nil then
2479
+ damageSetter(value)
2480
+ end
2374
2481
  data[key] = value
2375
2482
  end
2376
2483
  }
2377
2484
  )
2378
2485
  )
2486
+ if data[0] and source then
2487
+ local sourceOwner = source.owner.handle
2488
+ data[1] = sourceOwner
2489
+ local targetOwner = target.owner.handle
2490
+ data[2] = targetOwner
2491
+ if not GetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE) then
2492
+ SetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE, true)
2493
+ data[3] = true
2494
+ end
2495
+ if not GetPlayerAlliance(targetOwner, sourceOwner, ALLIANCE_PASSIVE) then
2496
+ SetPlayerAlliance(targetOwner, sourceOwner, ALLIANCE_PASSIVE, true)
2497
+ data[4] = true
2498
+ end
2499
+ end
2500
+ damagingEventByTarget[target] = data
2379
2501
  return
2380
2502
  end
2381
2503
  BlzSetEventDamage(0)
@@ -2383,7 +2505,7 @@ Unit.onDamaging = (function()
2383
2505
  BlzSetEventDamageType(DAMAGE_TYPE_UNKNOWN)
2384
2506
  BlzSetEventWeaponType(WEAPON_TYPE_WHOKNOWS)
2385
2507
  local sourceOwner = source.owner.handle
2386
- local targetOwner = GetOwningPlayer(target)
2508
+ local targetOwner = target.owner.handle
2387
2509
  if not GetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE) then
2388
2510
  SetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE, true)
2389
2511
  Timer:run(function()
@@ -2399,23 +2521,19 @@ Unit.onDamaging = (function()
2399
2521
  for ____, ____value in ipairs(source._attackHandlers) do
2400
2522
  local condition = ____value[1]
2401
2523
  local action = ____value[2]
2402
- if condition(
2403
- source,
2404
- ____exports.Unit:of(target),
2405
- data
2406
- ) then
2524
+ if condition(source, target, data) then
2407
2525
  action(
2408
2526
  source,
2409
- ____exports.Unit:of(target),
2527
+ target,
2410
2528
  setmetatable(
2411
2529
  {fire = function()
2412
2530
  UnitDamageTarget(
2413
2531
  source.handle,
2414
- target,
2532
+ target.handle,
2415
2533
  data.amount,
2416
2534
  true,
2417
2535
  true,
2418
- data.attackType,
2536
+ attackTypeToNative(data.attackType),
2419
2537
  data.damageType,
2420
2538
  data.weaponType
2421
2539
  )
@@ -2433,7 +2551,6 @@ end)()
2433
2551
  Unit.onDamage = __TS__New(
2434
2552
  InitializingEvent,
2435
2553
  function(event)
2436
- local invoke = Event.invoke
2437
2554
  local trigger = CreateTrigger()
2438
2555
  TriggerRegisterAnyUnitEventBJ(trigger, EVENT_PLAYER_UNIT_DAMAGED)
2439
2556
  TriggerAddCondition(
@@ -2443,29 +2560,54 @@ Unit.onDamage = __TS__New(
2443
2560
  if source and source.typeId == dummyUnitId then
2444
2561
  source = nil
2445
2562
  end
2563
+ local target = ____exports.Unit:of(BlzGetEventDamageTarget())
2564
+ local damagingEvent = damagingEventByTarget[target]
2565
+ damagingEventByTarget[target] = nil
2446
2566
  local data = {
2447
2567
  amount = GetEventDamage(),
2448
- attackType = BlzGetEventAttackType(),
2568
+ attackType = nativeToAttackType(BlzGetEventAttackType()),
2449
2569
  damageType = BlzGetEventDamageType(),
2450
2570
  weaponType = BlzGetEventWeaponType(),
2571
+ metadata = damagingEvent and damagingEvent.metadata,
2451
2572
  isAttack = BlzGetEventIsAttack(),
2573
+ originalAmount = damagingEvent and damagingEvent.originalAmount or GetEventDamage(),
2574
+ originalMetadata = damagingEvent and damagingEvent.originalMetadata,
2452
2575
  preventDeath = damageEventPreventDeath
2453
2576
  }
2577
+ if damagingEvent then
2578
+ for key, value in pairs(damagingEvent) do
2579
+ if isAttribute(key) then
2580
+ data[key] = value
2581
+ end
2582
+ end
2583
+ local sourceOwner = damagingEvent[1]
2584
+ if sourceOwner then
2585
+ local targetOwner = damagingEvent[2]
2586
+ if damagingEvent[3] then
2587
+ SetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE, false)
2588
+ end
2589
+ if damagingEvent[4] then
2590
+ SetPlayerAlliance(targetOwner, sourceOwner, ALLIANCE_PASSIVE, false)
2591
+ end
2592
+ end
2593
+ end
2454
2594
  local evData = setmetatable(
2455
2595
  {},
2456
2596
  {
2457
2597
  __index = data,
2458
2598
  __newindex = function(self, key, value)
2459
- damageSetters[key](value)
2599
+ local damageSetter = damageSetters[key]
2600
+ if damageSetter ~= nil then
2601
+ damageSetter(value)
2602
+ end
2460
2603
  data[key] = value
2461
2604
  end
2462
2605
  }
2463
2606
  )
2464
- local target = ____exports.Unit:of(BlzGetEventDamageTarget())
2465
2607
  invoke(event, source, target, evData)
2466
2608
  if evData[0] ~= nil and target.health - evData.amount < 0.405 then
2467
2609
  local bonusHealth = math.ceil(evData.amount)
2468
- target[104] = (target[104] or 0) + bonusHealth
2610
+ target[105] = (target[105] or 0) + bonusHealth
2469
2611
  BlzSetUnitMaxHP(
2470
2612
  target.handle,
2471
2613
  BlzGetUnitMaxHP(target.handle) + bonusHealth
@@ -2479,7 +2621,7 @@ Unit.onDamage = __TS__New(
2479
2621
  evData[0],
2480
2622
  table.unpack(evData, 1 + 1, 1 + (evData[1] or 0))
2481
2623
  )
2482
- target[104] = (target[104] or 0) - bonusHealth
2624
+ target[105] = (target[105] or 0) - bonusHealth
2483
2625
  SetWidgetLife(
2484
2626
  target.handle,
2485
2627
  GetWidgetLife(target.handle) - bonusHealth
@@ -2499,32 +2641,106 @@ Unit.onDamage = __TS__New(
2499
2641
  DestroyTrigger(trigger)
2500
2642
  end
2501
2643
  )
2502
- Unit.onItemDrop = __TS__New(
2644
+ Unit.itemDroppedEvent = __TS__New(
2503
2645
  ____exports.UnitTriggerEvent,
2504
2646
  EVENT_PLAYER_UNIT_DROP_ITEM,
2505
2647
  function()
2506
2648
  local unit = getTriggerUnit()
2507
- if getUnitTypeId(unit) ~= dummyUnitId then
2508
- return ____exports.Unit:of(unit), Item:of(getManipulatedItem())
2649
+ local item = getManipulatedItem()
2650
+ if getUnitTypeId(unit) ~= dummyUnitId and not (ignoreEventsItems[item] ~= nil) then
2651
+ return ____exports.Unit:of(unit), Item:of(item)
2509
2652
  end
2510
2653
  return IgnoreEvent
2511
2654
  end
2512
2655
  )
2513
- Unit.onItemPickup = __TS__New(
2656
+ Unit.itemPickedUpEvent = __TS__New(
2514
2657
  ____exports.UnitTriggerEvent,
2515
2658
  EVENT_PLAYER_UNIT_PICKUP_ITEM,
2516
2659
  function()
2517
2660
  local unit = getTriggerUnit()
2518
- if getUnitTypeId(unit) ~= dummyUnitId then
2519
- return ____exports.Unit:of(unit), Item:of(getManipulatedItem())
2661
+ local item = getManipulatedItem()
2662
+ if getUnitTypeId(unit) ~= dummyUnitId and not (ignoreEventsItems[item] ~= nil) then
2663
+ return ____exports.Unit:of(unit), Item:of(item)
2520
2664
  end
2521
2665
  return IgnoreEvent
2522
2666
  end
2523
2667
  )
2524
- Unit.onItemUse = __TS__New(
2668
+ Unit.itemUsedEvent = __TS__New(
2525
2669
  ____exports.UnitTriggerEvent,
2526
2670
  EVENT_PLAYER_UNIT_USE_ITEM,
2527
- function() return ____exports.Unit:of(GetTriggerUnit()), Item:of(GetManipulatedItem()) end
2671
+ function()
2672
+ local unit = getTriggerUnit()
2673
+ local item = getManipulatedItem()
2674
+ if getUnitTypeId(unit) ~= dummyUnitId and not (ignoreEventsItems[item] ~= nil) then
2675
+ return ____exports.Unit:of(unit), Item:of(item)
2676
+ end
2677
+ return IgnoreEvent
2678
+ end
2679
+ )
2680
+ Unit.itemStackedEvent = __TS__New(
2681
+ ____exports.UnitTriggerEvent,
2682
+ EVENT_PLAYER_UNIT_STACK_ITEM,
2683
+ function() return ____exports.Unit:of(getTriggerUnit()), Item:of(getManipulatedItem()) end
2684
+ )
2685
+ __TS__ObjectDefineProperty(
2686
+ Unit,
2687
+ "itemChargesChangedEvent",
2688
+ {get = function(self)
2689
+ local event = __TS__New(Event)
2690
+ Item.chargesChangedEvent:addListener(function(item)
2691
+ local unit = item.owner
2692
+ if unit ~= nil then
2693
+ invoke(event, unit, item)
2694
+ end
2695
+ end)
2696
+ rawset(self, "itemChargesChangedEvent", event)
2697
+ return event
2698
+ end}
2699
+ )
2700
+ __TS__ObjectDefineProperty(
2701
+ Unit,
2702
+ "itemUseOrderEvent",
2703
+ {get = function(self)
2704
+ local event = __TS__New(Event)
2705
+ for order = orderId("useslot0"), orderId("useslot5") do
2706
+ local slot = order - orderId("useslot0")
2707
+ local function listener(unit)
2708
+ local item = unit.items[slot + 1]
2709
+ if item ~= nil then
2710
+ invoke(event, unit, item)
2711
+ end
2712
+ end
2713
+ self.onImmediateOrder[order]:addListener(listener)
2714
+ self.onTargetOrder[order]:addListener(listener)
2715
+ self.onPointOrder[order]:addListener(listener)
2716
+ end
2717
+ rawset(self, "itemUseOrderEvent", event)
2718
+ return event
2719
+ end}
2720
+ )
2721
+ __TS__ObjectDefineProperty(
2722
+ Unit,
2723
+ "itemMoveOrderEvent",
2724
+ {get = function(self)
2725
+ local event = __TS__New(Event)
2726
+ for order = orderId("moveslot0"), orderId("moveslot5") do
2727
+ local slotTo = order - orderId("moveslot0")
2728
+ self.onTargetOrder[order]:addListener(function(unit, item)
2729
+ local slotFrom = unit.items:findSlot(item)
2730
+ if slotFrom ~= nil then
2731
+ invoke(
2732
+ event,
2733
+ unit,
2734
+ item,
2735
+ slotFrom,
2736
+ slotTo
2737
+ )
2738
+ end
2739
+ end)
2740
+ end
2741
+ rawset(self, "itemMoveOrderEvent", event)
2742
+ return event
2743
+ end}
2528
2744
  )
2529
2745
  __TS__ObjectDefineProperty(
2530
2746
  Unit,