warscript 0.0.1-dev.bb34489 → 0.0.1-dev.bcab4e5

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 (192) 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/handle.lua +2 -0
  12. package/core/types/order.d.ts +1 -0
  13. package/core/types/order.lua +11 -1
  14. package/core/types/sound.d.ts +17 -24
  15. package/core/types/sound.lua +99 -24
  16. package/core/types/timer.d.ts +6 -7
  17. package/core/types/timer.lua +18 -21
  18. package/core/util.d.ts +1 -1
  19. package/core/util.lua +18 -1
  20. package/decl/native.d.ts +840 -786
  21. package/engine/behavior.d.ts +2 -2
  22. package/engine/behavior.lua +6 -6
  23. package/engine/behaviour/ability/always-enabled.d.ts +7 -0
  24. package/engine/behaviour/ability/always-enabled.lua +31 -0
  25. package/engine/behaviour/ability/apply-buff.d.ts +8 -5
  26. package/engine/behaviour/ability/apply-buff.lua +32 -0
  27. package/engine/behaviour/ability/apply-unit-behavior.lua +1 -0
  28. package/engine/behaviour/ability/damage.d.ts +39 -11
  29. package/engine/behaviour/ability/damage.lua +83 -37
  30. package/engine/behaviour/ability/emulate-impact.d.ts +6 -0
  31. package/engine/behaviour/ability/emulate-impact.lua +35 -0
  32. package/engine/behaviour/ability/heal.d.ts +33 -6
  33. package/engine/behaviour/ability/heal.lua +89 -10
  34. package/engine/behaviour/ability/instant-impact.d.ts +2 -2
  35. package/engine/behaviour/ability/instant-impact.lua +4 -19
  36. package/engine/behaviour/ability/on-command-impact.d.ts +8 -0
  37. package/engine/behaviour/ability/on-command-impact.lua +25 -0
  38. package/engine/behaviour/ability/remove-buffs.d.ts +16 -0
  39. package/engine/behaviour/ability/remove-buffs.lua +28 -0
  40. package/engine/behaviour/ability/restore-mana.d.ts +15 -0
  41. package/engine/behaviour/ability/restore-mana.lua +29 -0
  42. package/engine/behaviour/ability.d.ts +20 -4
  43. package/engine/behaviour/ability.lua +111 -38
  44. package/engine/behaviour/unit.d.ts +13 -0
  45. package/engine/behaviour/unit.lua +84 -0
  46. package/engine/buff.d.ts +101 -39
  47. package/engine/buff.lua +458 -203
  48. package/engine/game-map.d.ts +7 -0
  49. package/engine/game-map.lua +32 -0
  50. package/engine/internal/ability.d.ts +18 -13
  51. package/engine/internal/ability.lua +87 -76
  52. package/engine/internal/item/ability.lua +106 -0
  53. package/engine/internal/item+owner.lua +2 -2
  54. package/engine/internal/item.d.ts +4 -3
  55. package/engine/internal/item.lua +56 -25
  56. package/engine/internal/mechanics/ability-duration.lua +1 -1
  57. package/engine/internal/misc/ability-disable-counter.d.ts +2 -0
  58. package/engine/internal/misc/ability-disable-counter.lua +13 -0
  59. package/engine/internal/misc/damage-metadata-by-target.d.ts +2 -0
  60. package/engine/internal/misc/damage-metadata-by-target.lua +5 -0
  61. package/engine/internal/object-data/auto-attack-speed-increase.d.ts +1 -1
  62. package/engine/internal/object-data/auto-attack-speed-increase.lua +2 -0
  63. package/engine/internal/object-data/evasion-probability.d.ts +2 -0
  64. package/engine/internal/object-data/evasion-probability.lua +16 -0
  65. package/engine/internal/unit/ability.d.ts +10 -1
  66. package/engine/internal/unit/ability.lua +36 -14
  67. package/engine/internal/unit/add-item-to-slot-init.d.ts +2 -0
  68. package/engine/internal/unit/add-item-to-slot-init.lua +23 -0
  69. package/engine/internal/unit/add-item-to-slot.d.ts +2 -0
  70. package/engine/internal/unit/add-item-to-slot.lua +52 -0
  71. package/engine/internal/unit/bonus.d.ts +6 -2
  72. package/engine/internal/unit/bonus.lua +23 -1
  73. package/engine/internal/unit/ignore-events-items.d.ts +2 -0
  74. package/engine/internal/unit/ignore-events-items.lua +5 -0
  75. package/engine/internal/unit/item.d.ts +24 -0
  76. package/engine/internal/unit/item.lua +78 -0
  77. package/engine/internal/unit/main-selected.d.ts +13 -0
  78. package/engine/internal/unit/main-selected.lua +51 -0
  79. package/engine/internal/unit+ability.lua +2 -2
  80. package/engine/internal/unit+damage.d.ts +2 -11
  81. package/engine/internal/unit+damage.lua +10 -14
  82. package/engine/internal/unit+spellSteal.lua +1 -2
  83. package/engine/internal/unit+transport.lua +4 -10
  84. package/engine/internal/unit-missile-launch.lua +25 -6
  85. package/engine/internal/unit.d.ts +50 -13
  86. package/engine/internal/unit.lua +331 -124
  87. package/engine/internal/utility.lua +12 -0
  88. package/engine/lightning.d.ts +12 -5
  89. package/engine/lightning.lua +48 -14
  90. package/engine/local-client.d.ts +7 -2
  91. package/engine/local-client.lua +82 -0
  92. package/engine/object-data/auxiliary/animation-name.d.ts +1 -0
  93. package/engine/object-data/auxiliary/animation-name.lua +16 -0
  94. package/engine/object-data/auxiliary/attachment-preset.d.ts +7 -2
  95. package/engine/object-data/auxiliary/attachment-preset.lua +4 -3
  96. package/engine/object-data/auxiliary/attack-type.d.ts +7 -8
  97. package/engine/object-data/auxiliary/attack-type.lua +42 -0
  98. package/engine/object-data/auxiliary/movement-type.d.ts +7 -7
  99. package/engine/object-data/auxiliary/movement-type.lua +22 -0
  100. package/engine/object-data/auxiliary/sound-eax.d.ts +10 -0
  101. package/engine/object-data/auxiliary/sound-eax.lua +2 -0
  102. package/engine/object-data/auxiliary/sound-preset-name.d.ts +5 -1
  103. package/engine/object-data/auxiliary/tech-tree-dependency.d.ts +1 -1
  104. package/engine/object-data/auxiliary/unit-attribute.d.ts +6 -0
  105. package/engine/object-data/auxiliary/unit-attribute.lua +9 -0
  106. package/engine/object-data/entry/ability-type/berserk.d.ts +2 -0
  107. package/engine/object-data/entry/ability-type/berserk.lua +13 -0
  108. package/engine/object-data/entry/ability-type/blank-configurable.lua +12 -1
  109. package/engine/object-data/entry/ability-type/carrion-swarm.d.ts +14 -0
  110. package/engine/object-data/entry/ability-type/carrion-swarm.lua +65 -0
  111. package/engine/object-data/entry/ability-type/disease-cloud.lua +2 -2
  112. package/engine/object-data/entry/ability-type/engineering-upgrade.lua +2 -2
  113. package/engine/object-data/entry/ability-type/ensnare.d.ts +12 -0
  114. package/engine/object-data/entry/ability-type/ensnare.lua +52 -0
  115. package/engine/object-data/entry/ability-type/feral-spirit.lua +2 -2
  116. package/engine/object-data/entry/ability-type/permanent-invisibility.d.ts +8 -0
  117. package/engine/object-data/entry/ability-type/permanent-invisibility.lua +26 -0
  118. package/engine/object-data/entry/ability-type/phase-shift.d.ts +10 -0
  119. package/engine/object-data/entry/ability-type/phase-shift.lua +39 -0
  120. package/engine/object-data/entry/ability-type/phoenix-morph.lua +4 -4
  121. package/engine/object-data/entry/ability-type/raise-dead.d.ts +17 -0
  122. package/engine/object-data/entry/ability-type/raise-dead.lua +78 -0
  123. package/engine/object-data/entry/ability-type/shock-wave.d.ts +4 -0
  124. package/engine/object-data/entry/ability-type/shock-wave.lua +26 -0
  125. package/engine/object-data/entry/ability-type/slow-poison.d.ts +10 -0
  126. package/engine/object-data/entry/ability-type/slow-poison.lua +58 -0
  127. package/engine/object-data/entry/ability-type/summon-quilbeast.lua +2 -2
  128. package/engine/object-data/entry/ability-type/summon-water-elemental.lua +2 -2
  129. package/engine/object-data/entry/ability-type/web.d.ts +12 -0
  130. package/engine/object-data/entry/ability-type/web.lua +52 -0
  131. package/engine/object-data/entry/ability-type.d.ts +19 -17
  132. package/engine/object-data/entry/ability-type.lua +89 -33
  133. package/engine/object-data/entry/buff-type/applicable.lua +18 -37
  134. package/engine/object-data/entry/buff-type.d.ts +6 -12
  135. package/engine/object-data/entry/buff-type.lua +13 -29
  136. package/engine/object-data/entry/destructible-type.d.ts +1 -1
  137. package/engine/object-data/entry/item-type.d.ts +15 -1
  138. package/engine/object-data/entry/item-type.lua +93 -2
  139. package/engine/object-data/entry/lightning-type.d.ts +1 -1
  140. package/engine/object-data/entry/sound-preset.d.ts +33 -0
  141. package/engine/object-data/entry/sound-preset.lua +140 -0
  142. package/engine/object-data/entry/unit-type.d.ts +10 -3
  143. package/engine/object-data/entry/unit-type.lua +155 -92
  144. package/engine/object-data/entry/upgrade.d.ts +1 -1
  145. package/engine/object-data/entry/upgrade.lua +4 -4
  146. package/engine/object-data/entry.d.ts +16 -14
  147. package/engine/object-data/entry.lua +60 -32
  148. package/engine/object-data/utility/object-data-entry-id-generator.lua +7 -0
  149. package/engine/object-field/ability.d.ts +26 -3
  150. package/engine/object-field/ability.lua +54 -1
  151. package/engine/object-field/unit.d.ts +46 -3
  152. package/engine/object-field/unit.lua +173 -7
  153. package/engine/object-field.d.ts +11 -3
  154. package/engine/object-field.lua +162 -76
  155. package/engine/standard/entries/buff-type.d.ts +3 -0
  156. package/engine/standard/entries/buff-type.lua +3 -0
  157. package/engine/standard/entries/sound-preset.d.ts +10 -0
  158. package/engine/standard/entries/sound-preset.lua +10 -0
  159. package/engine/standard/fields/ability.d.ts +2 -0
  160. package/engine/standard/fields/ability.lua +2 -0
  161. package/engine/unit.d.ts +3 -0
  162. package/engine/unit.lua +3 -0
  163. package/index.d.ts +1 -0
  164. package/index.lua +1 -0
  165. package/lualib_bundle.lua +7 -2
  166. package/net/socket.d.ts +7 -1
  167. package/net/socket.lua +45 -4
  168. package/network.d.ts +1 -0
  169. package/network.lua +3 -2
  170. package/objutil/buff.lua +2 -3
  171. package/objutil/unit.lua +8 -0
  172. package/package.json +2 -2
  173. package/patch-lua.d.ts +0 -0
  174. package/patch-lua.lua +10 -0
  175. package/property.d.ts +55 -0
  176. package/property.lua +374 -0
  177. package/utility/arrays.d.ts +9 -1
  178. package/utility/arrays.lua +37 -3
  179. package/utility/functions.d.ts +1 -0
  180. package/utility/functions.lua +1 -0
  181. package/utility/lazy.d.ts +2 -0
  182. package/utility/lazy.lua +14 -0
  183. package/utility/linked-set.d.ts +12 -2
  184. package/utility/linked-set.lua +8 -2
  185. package/utility/lua-maps.d.ts +3 -0
  186. package/utility/lua-maps.lua +16 -0
  187. package/utility/lua-sets.d.ts +1 -0
  188. package/utility/lua-sets.lua +3 -0
  189. package/utility/reflection.lua +11 -7
  190. package/utility/types.d.ts +1 -0
  191. package/core/mapbounds.d.ts +0 -8
  192. package/core/mapbounds.lua +0 -12
@@ -6,6 +6,7 @@ local __TS__New = ____lualib.__TS__New
6
6
  local __TS__Class = ____lualib.__TS__Class
7
7
  local __TS__ClassExtends = ____lualib.__TS__ClassExtends
8
8
  local __TS__SetDescriptor = ____lualib.__TS__SetDescriptor
9
+ local __TS__ArraySetLength = ____lualib.__TS__ArraySetLength
9
10
  local __TS__SparseArrayNew = ____lualib.__TS__SparseArrayNew
10
11
  local __TS__SparseArrayPush = ____lualib.__TS__SparseArrayPush
11
12
  local __TS__SparseArraySpread = ____lualib.__TS__SparseArraySpread
@@ -50,12 +51,19 @@ local ____arrays = require("utility.arrays")
50
51
  local forEach = ____arrays.forEach
51
52
  local ____math = require("math")
52
53
  local min = ____math.min
54
+ local ____ignore_2Devents_2Ditems = require("engine.internal.unit.ignore-events-items")
55
+ local ignoreEventsItems = ____ignore_2Devents_2Ditems.ignoreEventsItems
56
+ local ____attack_2Dtype = require("engine.object-data.auxiliary.attack-type")
57
+ local attackTypeToNative = ____attack_2Dtype.attackTypeToNative
58
+ local nativeToAttackType = ____attack_2Dtype.nativeToAttackType
59
+ local ____damage_2Dmetadata_2Dby_2Dtarget = require("engine.internal.misc.damage-metadata-by-target")
60
+ local damageMetadataByTarget = ____damage_2Dmetadata_2Dby_2Dtarget.damageMetadataByTarget
61
+ local ____attributes = require("attributes")
62
+ local isAttribute = ____attributes.isAttribute
53
63
  local match = string.match
54
64
  local ____tostring = _G.tostring
55
65
  local setUnitAnimation = SetUnitAnimation
56
- local setUnitAnimationWithRarity = SetUnitAnimationWithRarity
57
66
  local setUnitAnimationByIndex = SetUnitAnimationByIndex
58
- local queueUnitAnimation = QueueUnitAnimation
59
67
  local getUnitIntegerField = BlzGetUnitIntegerField
60
68
  local getUnitRealField = BlzGetUnitRealField
61
69
  local getHeroStr = GetHeroStr
@@ -74,9 +82,9 @@ local setUnitScale = SetUnitScale
74
82
  local setUnitPosition = SetUnitPosition
75
83
  local setUnitTimeScale = SetUnitTimeScale
76
84
  local getHandleId = GetHandleId
85
+ local getUnitCurrentOrder = GetUnitCurrentOrder
77
86
  local createUnit = CreateUnit
78
87
  local killUnit = KillUnit
79
- local setUnitExploded = SetUnitExploded
80
88
  local removeUnit = RemoveUnit
81
89
  local getUnitTypeId = GetUnitTypeId
82
90
  local isHeroUnitId = IsHeroUnitId
@@ -92,8 +100,6 @@ local getSpellTargetItem = GetSpellTargetItem
92
100
  local getSpellTargetDestructable = GetSpellTargetDestructable
93
101
  local isUnitInRangeXY = IsUnitInRangeXY
94
102
  local isUnitInRange = IsUnitInRange
95
- local setResourceAmount = SetResourceAmount
96
- local getResourceAmount = GetResourceAmount
97
103
  local getUnitWeaponRealField = BlzGetUnitWeaponRealField
98
104
  local setUnitWeaponRealField = BlzSetUnitWeaponRealField
99
105
  local getUnitWeaponStringField = BlzGetUnitWeaponStringField
@@ -124,8 +130,6 @@ local isUnitType = IsUnitType
124
130
  local isUnitAlly = IsUnitAlly
125
131
  local isUnitEnemy = IsUnitEnemy
126
132
  local getOwningPlayer = GetOwningPlayer
127
- local setUnitColor = SetUnitColor
128
- local showUnitTeamGlow = BlzShowUnitTeamGlow
129
133
  ____exports.UnitClassification = {}
130
134
  local UnitClassification = ____exports.UnitClassification
131
135
  do
@@ -135,6 +139,7 @@ do
135
139
  UnitClassification.GROUND = UNIT_TYPE_GROUND
136
140
  UnitClassification.SUMMONED = UNIT_TYPE_SUMMONED
137
141
  UnitClassification.MECHANICAL = UNIT_TYPE_MECHANICAL
142
+ UnitClassification.WORKER = UNIT_TYPE_PEON
138
143
  UnitClassification.ANCIENT = UNIT_TYPE_ANCIENT
139
144
  UnitClassification.SUICIDAL = UNIT_TYPE_SAPPER
140
145
  UnitClassification.TAUREN = UNIT_TYPE_TAUREN
@@ -289,7 +294,6 @@ local function dispatch(event, idGetter, argsGetter)
289
294
  return event[id]
290
295
  end
291
296
  if not initialized then
292
- local invoke = Event.invoke
293
297
  event:addListener(function(...)
294
298
  local id = idGetter(...)
295
299
  local dispatched = rawget(self, id)
@@ -327,7 +331,6 @@ local function dispatchAbility(event)
327
331
  return event[id]
328
332
  end
329
333
  if not initialized then
330
- local invoke = Event.invoke
331
334
  event:addListener(function(unit, ability, ...)
332
335
  local dispatched = rawget(self, ability.typeId)
333
336
  if dispatched ~= nil then
@@ -344,6 +347,9 @@ local function dispatchAbility(event)
344
347
  }
345
348
  )
346
349
  end
350
+ local function damagingEventPreventRetaliation(self)
351
+ self[0] = true
352
+ end
347
353
  local function damageEventPreventDeath(self, callback, ...)
348
354
  if self[0] ~= nil then
349
355
  return
@@ -355,7 +361,14 @@ local function damageEventPreventDeath(self, callback, ...)
355
361
  rawset(self, 1 + i, (select(i, ...)))
356
362
  end
357
363
  end
358
- local damageSetters = {amount = BlzSetEventDamage, attackType = BlzSetEventAttackType, damageType = BlzSetEventDamageType, weaponType = BlzSetEventWeaponType}
364
+ local damageSetters = {
365
+ amount = BlzSetEventDamage,
366
+ attackType = function(attackType)
367
+ return BlzSetEventAttackType(attackTypeToNative(attackType))
368
+ end,
369
+ damageType = BlzSetEventDamageType,
370
+ weaponType = BlzSetEventWeaponType
371
+ }
359
372
  local jlimitopByOperator = {
360
373
  [0] = LESS_THAN_OR_EQUAL,
361
374
  [1] = LESS_THAN_OR_EQUAL,
@@ -433,6 +446,19 @@ __TS__SetDescriptor(
433
446
  },
434
447
  true
435
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
+ )
436
462
  __TS__SetDescriptor(
437
463
  UnitWeapon.prototype,
438
464
  "damageBase",
@@ -563,17 +589,6 @@ local function retrieveAbility(unit, ability, abilityId)
563
589
  ____exports.Unit:of(unit)
564
590
  )
565
591
  end
566
- if not unitAddAbility(unit, abilityId) then
567
- if getUnitAbility(unit, abilityId) == ability then
568
- return UnitAbility:of(
569
- ability,
570
- abilityId,
571
- ____exports.Unit:of(unit)
572
- )
573
- end
574
- else
575
- unitRemoveAbility(unit, abilityId)
576
- end
577
592
  for i = 0, unitInventorySize(unit) - 1 do
578
593
  local item = unitItemInSlot(unit, i)
579
594
  if getItemAbility(item, abilityId) == ability then
@@ -631,15 +646,15 @@ for ____, player in ipairs(Player.all) do
631
646
  dummies[player] = dummy
632
647
  end
633
648
  local function delayHealthChecksCallback(unit)
634
- local counter = (unit[102] or 0) - 1
649
+ local counter = (unit[103] or 0) - 1
635
650
  if counter ~= 0 then
636
- unit[102] = counter
651
+ unit[103] = counter
637
652
  return
638
653
  end
639
- unit[102] = nil
640
- local healthBonus = unit[103]
654
+ unit[103] = nil
655
+ local healthBonus = unit[104]
641
656
  if healthBonus ~= nil then
642
- unit[103] = nil
657
+ unit[104] = nil
643
658
  local handle = unit.handle
644
659
  BlzSetUnitMaxHP(
645
660
  handle,
@@ -647,12 +662,18 @@ local function delayHealthChecksCallback(unit)
647
662
  )
648
663
  end
649
664
  end
665
+ local nextSyncId = 1
666
+ local unitBySyncId = setmetatable({}, {__mode = "v"})
667
+ local damagingEventByTarget = setmetatable({}, {__mode = "k"})
650
668
  ____exports.Unit = __TS__Class()
651
669
  local Unit = ____exports.Unit
652
670
  Unit.name = "Unit"
653
671
  __TS__ClassExtends(Unit, Handle)
654
672
  function Unit.prototype.____constructor(self, handle)
655
673
  Handle.prototype.____constructor(self, handle)
674
+ local ____nextSyncId_0 = nextSyncId
675
+ nextSyncId = ____nextSyncId_0 + 1
676
+ self.syncId = ____nextSyncId_0
656
677
  self._owner = Player:of(getOwningPlayer(handle))
657
678
  assert(unitAddAbility(handle, leaveDetectAbilityId) and UnitMakeAbilityPermanent(handle, true, leaveDetectAbilityId))
658
679
  assert(unitAddAbility(handle, morphDetectAbilityId))
@@ -665,6 +686,7 @@ function Unit.prototype.____constructor(self, handle)
665
686
  fourCC("Amrf")
666
687
  ))
667
688
  end
689
+ unitBySyncId[self.syncId] = self
668
690
  local ____ = self.abilities
669
691
  end
670
692
  function Unit.prototype.getEvent(self, event, collector)
@@ -683,9 +705,16 @@ function Unit.prototype.getEvent(self, event, collector)
683
705
  end
684
706
  function Unit.prototype.onDestroy(self)
685
707
  local handle = self.handle
708
+ self[107] = getUnitX(handle)
709
+ self[108] = getUnitY(handle)
686
710
  if not self._owner then
687
711
  self._owner = Player:of(getOwningPlayer(handle))
688
712
  end
713
+ local abilities = self.abilities
714
+ for ____, ability in ipairs(abilities) do
715
+ ability:destroy()
716
+ end
717
+ __TS__ArraySetLength(abilities, 0)
689
718
  for ____, player in ipairs(Player.all) do
690
719
  if self:isSelected(player) then
691
720
  Event.invoke(____exports.Unit.onDeselect, self, player)
@@ -700,6 +729,10 @@ function Unit.prototype.onDestroy(self)
700
729
  if eventsToDestroy ~= nil then
701
730
  forEach(eventsToDestroy, "destroy")
702
731
  end
732
+ if getUnitAbilityLevel(handle, leaveDetectAbilityId) > 0 then
733
+ unitRemoveAbility(handle, leaveDetectAbilityId)
734
+ removeUnit(handle)
735
+ end
703
736
  return Handle.prototype.onDestroy(self)
704
737
  end
705
738
  function Unit.prototype.addAttackHandler(self, condition, action)
@@ -741,8 +774,8 @@ function Unit.prototype.addModifier(self, property, modifier)
741
774
  end}
742
775
  end
743
776
  function Unit.prototype.hasCombatClassification(self, combatClassification)
744
- local ____combatClassification_0 = combatClassification
745
- 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
746
779
  end
747
780
  function Unit.prototype.addClassification(self, classification)
748
781
  return unitAddType(self.handle, classification)
@@ -760,13 +793,13 @@ function Unit.prototype.isInvisibleTo(self, player)
760
793
  return isUnitInvisible(self.handle, player.handle)
761
794
  end
762
795
  function Unit.prototype.isInRangeOf(self, x, y, range)
763
- local ____temp_1
796
+ local ____temp_2
764
797
  if type(x) == "number" then
765
- ____temp_1 = isUnitInRangeXY(self.handle, x, y, range)
798
+ ____temp_2 = isUnitInRangeXY(self.handle, x, y, range)
766
799
  else
767
- ____temp_1 = isUnitInRange(self.handle, x.handle, y)
800
+ ____temp_2 = isUnitInRange(self.handle, x.handle, y)
768
801
  end
769
- return ____temp_1
802
+ return ____temp_2
770
803
  end
771
804
  function Unit.prototype.isAllyOf(self, unit)
772
805
  return isUnitAlly(
@@ -784,16 +817,28 @@ function Unit.prototype.playAnimation(self, animation, rarity)
784
817
  if type(animation) == "number" then
785
818
  setUnitAnimationByIndex(self.handle, animation)
786
819
  elseif rarity then
787
- setUnitAnimationWithRarity(self.handle, animation, rarity)
820
+ SetUnitAnimationWithRarity(self.handle, animation, rarity)
788
821
  else
789
822
  setUnitAnimation(self.handle, animation)
790
823
  end
791
824
  end
825
+ function Unit.prototype.resetAnimation(self)
826
+ ResetUnitAnimation(self.handle)
827
+ end
792
828
  function Unit.prototype.queueAnimation(self, animation)
793
- 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
794
839
  end
795
840
  function Unit.prototype.delayHealthChecks(self)
796
- self[102] = (self[102] or 0) + 1
841
+ self[103] = (self[103] or 0) + 1
797
842
  Timer:run(delayHealthChecksCallback, self)
798
843
  end
799
844
  function Unit.prototype.setPosition(self, x, y)
@@ -803,21 +848,21 @@ function Unit.prototype.isSelected(self, player)
803
848
  return IsUnitSelected(self.handle, player.handle)
804
849
  end
805
850
  function Unit.prototype.explode(self)
806
- setUnitExploded(self.handle, true)
851
+ SetUnitExploded(self.handle, true)
807
852
  killUnit(self.handle)
808
853
  end
809
854
  function Unit.prototype.kill(self)
810
855
  killUnit(self.handle)
811
856
  end
812
857
  function Unit.prototype.revive(self, x, y, doEffect)
813
- local ____ReviveHero_4 = ReviveHero
814
- local ____array_3 = __TS__SparseArrayNew(self.handle, x, y)
815
- local ____doEffect_2 = doEffect
816
- if ____doEffect_2 == nil then
817
- ____doEffect_2 = false
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
818
863
  end
819
- __TS__SparseArrayPush(____array_3, ____doEffect_2)
820
- ____ReviveHero_4(__TS__SparseArraySpread(____array_3))
864
+ __TS__SparseArrayPush(____array_4, ____doEffect_3)
865
+ ____ReviveHero_5(__TS__SparseArraySpread(____array_4))
821
866
  end
822
867
  function Unit.prototype.healTarget(self, target, amount)
823
868
  if __TS__InstanceOf(target, ____exports.Unit) and target:hasAbility(fourCC("BIhm")) then
@@ -857,7 +902,7 @@ function Unit.prototype.dropItemSlot(self, item, slot)
857
902
  return UnitDropItemSlot(self.handle, item.handle, slot)
858
903
  end
859
904
  function Unit.prototype.itemInSlot(self, slot)
860
- return Item:of(UnitItemInSlot(self.handle, slot))
905
+ return Item:of(unitItemInSlot(self.handle, slot))
861
906
  end
862
907
  function Unit.prototype.addAbility(self, abilityId)
863
908
  if unitAddAbility(self.handle, abilityId) then
@@ -926,8 +971,15 @@ function Unit.prototype.interruptAttack(self)
926
971
  unitInterruptAttack(self.handle)
927
972
  end
928
973
  function Unit.prototype.interruptCast(self, abilityId)
929
- unitDisableAbility(self.handle, abilityId, true, false)
930
- 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
+ )
931
983
  end
932
984
  function Unit.prototype.getDistanceTo(self, target)
933
985
  local handle = self.handle
@@ -987,18 +1039,18 @@ function Unit.prototype.unpauseEx(self)
987
1039
  self:decrementStunCounter()
988
1040
  end
989
1041
  function Unit.prototype.incrementStunCounter(self)
990
- local stunCounter = self[101] or 0
991
- if not self[100] or stunCounter >= 0 then
1042
+ local stunCounter = self[102] or 0
1043
+ if not self[101] or stunCounter >= 0 then
992
1044
  BlzPauseUnitEx(self.handle, true)
993
1045
  end
994
- self[101] = stunCounter + 1
1046
+ self[102] = stunCounter + 1
995
1047
  end
996
1048
  function Unit.prototype.decrementStunCounter(self)
997
- local stunCounter = self[101] or 0
998
- if not self[100] or stunCounter >= 1 then
1049
+ local stunCounter = self[102] or 0
1050
+ if not self[101] or stunCounter >= 1 then
999
1051
  BlzPauseUnitEx(self.handle, false)
1000
1052
  end
1001
- self[101] = stunCounter - 1
1053
+ self[102] = stunCounter - 1
1002
1054
  end
1003
1055
  function Unit.create(self, owner, id, x, y, facing, skinId)
1004
1056
  local handle = skinId and BlzCreateUnitWithSkin(
@@ -1100,8 +1152,11 @@ function Unit.getInSector(self, pos, range, offsetAngle, centralAngle)
1100
1152
  )
1101
1153
  return targetCollection
1102
1154
  end
1103
- function Unit.getSelectionOf(self, player)
1104
- targetCollection = {}
1155
+ function Unit.getSelectionOf(self, player, target)
1156
+ if target == nil then
1157
+ target = {}
1158
+ end
1159
+ targetCollection = target
1105
1160
  targetCollectionNextIndex = 1
1106
1161
  GroupEnumUnitsSelected(dummyGroup, player.handle, collectIntoTarget)
1107
1162
  return targetCollection
@@ -1123,6 +1178,9 @@ end
1123
1178
  function Unit.prototype.__tostring(self)
1124
1179
  return (((self.constructor.name .. "$") .. util.id2s(self.typeId)) .. "@") .. tostring(getHandleId(self.handle))
1125
1180
  end
1181
+ function Unit.getBySyncId(self, syncId)
1182
+ return unitBySyncId[syncId]
1183
+ end
1126
1184
  __TS__SetDescriptor(
1127
1185
  Unit.prototype,
1128
1186
  "_deltas",
@@ -1186,6 +1244,14 @@ __TS__SetDescriptor(
1186
1244
  end},
1187
1245
  true
1188
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
+ )
1189
1255
  __TS__SetDescriptor(
1190
1256
  Unit.prototype,
1191
1257
  "combatClassifications",
@@ -1259,6 +1325,19 @@ __TS__SetDescriptor(
1259
1325
  },
1260
1326
  true
1261
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
+ )
1262
1341
  __TS__SetDescriptor(
1263
1342
  Unit.prototype,
1264
1343
  "strengthBase",
@@ -1380,17 +1459,17 @@ __TS__SetDescriptor(
1380
1459
  "isTeamGlowVisible",
1381
1460
  {
1382
1461
  get = function(self)
1383
- return not self[105]
1462
+ return not self[106]
1384
1463
  end,
1385
1464
  set = function(self, isTeamGlowVisible)
1386
- showUnitTeamGlow(self.handle, isTeamGlowVisible)
1387
- local ____temp_5
1465
+ BlzShowUnitTeamGlow(self.handle, isTeamGlowVisible)
1466
+ local ____temp_6
1388
1467
  if not isTeamGlowVisible then
1389
- ____temp_5 = true
1468
+ ____temp_6 = true
1390
1469
  else
1391
- ____temp_5 = nil
1470
+ ____temp_6 = nil
1392
1471
  end
1393
- self[105] = ____temp_5
1472
+ self[106] = ____temp_6
1394
1473
  end
1395
1474
  },
1396
1475
  true
@@ -1399,9 +1478,9 @@ __TS__SetDescriptor(
1399
1478
  Unit.prototype,
1400
1479
  "color",
1401
1480
  {set = function(self, color)
1402
- setUnitColor(self.handle, color.handle)
1403
- if self[105] then
1404
- showUnitTeamGlow(self.handle, false)
1481
+ SetUnitColor(self.handle, color.handle)
1482
+ if self[106] then
1483
+ BlzShowUnitTeamGlow(self.handle, false)
1405
1484
  end
1406
1485
  end},
1407
1486
  true
@@ -1424,14 +1503,14 @@ __TS__SetDescriptor(
1424
1503
  "maxHealth",
1425
1504
  {
1426
1505
  get = function(self)
1427
- 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)
1428
1507
  end,
1429
1508
  set = function(self, maxHealth)
1430
- if maxHealth < 1 and self[102] ~= nil then
1431
- 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)
1432
1511
  maxHealth = 1
1433
1512
  end
1434
- BlzSetUnitMaxHP(self.handle, maxHealth + (self[104] or 0))
1513
+ BlzSetUnitMaxHP(self.handle, maxHealth + (self[105] or 0))
1435
1514
  end
1436
1515
  },
1437
1516
  true
@@ -1473,10 +1552,10 @@ __TS__SetDescriptor(
1473
1552
  "health",
1474
1553
  {
1475
1554
  get = function(self)
1476
- return GetWidgetLife(self.handle) - (self[104] or 0)
1555
+ return GetWidgetLife(self.handle) - (self[105] or 0)
1477
1556
  end,
1478
1557
  set = function(self, health)
1479
- SetWidgetLife(self.handle, health + (self[104] or 0))
1558
+ SetWidgetLife(self.handle, health + (self[105] or 0))
1480
1559
  end
1481
1560
  },
1482
1561
  true
@@ -1570,7 +1649,7 @@ __TS__SetDescriptor(
1570
1649
  "x",
1571
1650
  {
1572
1651
  get = function(self)
1573
- return getUnitX(self.handle)
1652
+ return self[107] or getUnitX(self.handle)
1574
1653
  end,
1575
1654
  set = function(self, v)
1576
1655
  SetUnitX(self.handle, v)
@@ -1583,7 +1662,7 @@ __TS__SetDescriptor(
1583
1662
  "y",
1584
1663
  {
1585
1664
  get = function(self)
1586
- return getUnitY(self.handle)
1665
+ return self[108] or getUnitY(self.handle)
1587
1666
  end,
1588
1667
  set = function(self, v)
1589
1668
  SetUnitY(self.handle, v)
@@ -1669,10 +1748,10 @@ __TS__SetDescriptor(
1669
1748
  "gold",
1670
1749
  {
1671
1750
  get = function(self)
1672
- return getResourceAmount(self.handle)
1751
+ return GetResourceAmount(self.handle)
1673
1752
  end,
1674
1753
  set = function(self, gold)
1675
- setResourceAmount(self.handle, gold)
1754
+ SetResourceAmount(self.handle, gold)
1676
1755
  end
1677
1756
  },
1678
1757
  true
@@ -1687,17 +1766,17 @@ __TS__SetDescriptor(
1687
1766
  set = function(self, isPaused)
1688
1767
  local handle = self.handle
1689
1768
  if isPaused and not IsUnitPaused(handle) then
1690
- self[100] = true
1691
- for _ = self[101] or 0, -1 do
1769
+ self[101] = true
1770
+ for _ = self[102] or 0, -1 do
1692
1771
  BlzPauseUnitEx(handle, true)
1693
1772
  end
1694
1773
  PauseUnit(handle, true)
1695
1774
  elseif not isPaused and IsUnitPaused(handle) then
1696
1775
  PauseUnit(handle, false)
1697
- for _ = self[101] or 0, -1 do
1776
+ for _ = self[102] or 0, -1 do
1698
1777
  BlzPauseUnitEx(handle, false)
1699
1778
  end
1700
- self[100] = nil
1779
+ self[101] = nil
1701
1780
  end
1702
1781
  end
1703
1782
  },
@@ -1800,6 +1879,19 @@ __TS__SetDescriptor(
1800
1879
  end},
1801
1880
  true
1802
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
+ )
1803
1895
  __TS__SetDescriptor(
1804
1896
  Unit.prototype,
1805
1897
  "pathing",
@@ -1981,6 +2073,14 @@ __TS__SetDescriptor(
1981
2073
  end},
1982
2074
  true
1983
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
+ )
1984
2084
  __TS__SetDescriptor(
1985
2085
  Unit.prototype,
1986
2086
  "onSelect",
@@ -2054,7 +2154,6 @@ Unit.onDecay = __TS__New(
2054
2154
  Unit.onResurrect = __TS__New(
2055
2155
  InitializingEvent,
2056
2156
  function(event)
2057
- local invoke = Event.invoke
2058
2157
  local dead = setmetatable({}, {__mode = "k"})
2059
2158
  ____exports.Unit.deathEvent:addListener(function(unit)
2060
2159
  dead[unit] = true
@@ -2070,10 +2169,15 @@ Unit.onResurrect = __TS__New(
2070
2169
  Unit.morphEvent = __TS__New(
2071
2170
  InitializingEvent,
2072
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
2073
2178
  ____exports.Unit.onImmediateOrder[orderId("undefend")]:addListener(function(unit)
2074
2179
  if getUnitAbilityLevel(unit.handle, morphDetectAbilityId) == 0 then
2075
- assert(unitAddAbility(unit.handle, morphDetectAbilityId))
2076
- Timer:run(Event.invoke, event, unit)
2180
+ Timer:run(ifNotLeft, unit)
2077
2181
  end
2078
2182
  end)
2079
2183
  end
@@ -2111,27 +2215,26 @@ Unit.onSpellEffect = dispatchId(__TS__New(
2111
2215
  Unit.onTargetCast = dispatchId(__TS__New(
2112
2216
  InitializingEvent,
2113
2217
  function(event)
2114
- local invoke = Event.invoke
2115
2218
  local function listener(unit, id)
2116
- local ____GetSpellTargetUnit_result_8
2219
+ local ____GetSpellTargetUnit_result_9
2117
2220
  if GetSpellTargetUnit() then
2118
- ____GetSpellTargetUnit_result_8 = ____exports.Unit:of(GetSpellTargetUnit())
2221
+ ____GetSpellTargetUnit_result_9 = ____exports.Unit:of(GetSpellTargetUnit())
2119
2222
  else
2120
- local ____GetSpellTargetItem_result_7
2223
+ local ____GetSpellTargetItem_result_8
2121
2224
  if GetSpellTargetItem() then
2122
- ____GetSpellTargetItem_result_7 = Item:of(GetSpellTargetItem())
2225
+ ____GetSpellTargetItem_result_8 = Item:of(GetSpellTargetItem())
2123
2226
  else
2124
- local ____GetSpellTargetDestructable_result_6
2227
+ local ____GetSpellTargetDestructable_result_7
2125
2228
  if GetSpellTargetDestructable() then
2126
- ____GetSpellTargetDestructable_result_6 = Destructable:of(GetSpellTargetDestructable())
2229
+ ____GetSpellTargetDestructable_result_7 = Destructable:of(GetSpellTargetDestructable())
2127
2230
  else
2128
- ____GetSpellTargetDestructable_result_6 = nil
2231
+ ____GetSpellTargetDestructable_result_7 = nil
2129
2232
  end
2130
- ____GetSpellTargetItem_result_7 = ____GetSpellTargetDestructable_result_6
2233
+ ____GetSpellTargetItem_result_8 = ____GetSpellTargetDestructable_result_7
2131
2234
  end
2132
- ____GetSpellTargetUnit_result_8 = ____GetSpellTargetItem_result_7
2235
+ ____GetSpellTargetUnit_result_9 = ____GetSpellTargetItem_result_8
2133
2236
  end
2134
- local target = ____GetSpellTargetUnit_result_8
2237
+ local target = ____GetSpellTargetUnit_result_9
2135
2238
  if target then
2136
2239
  invoke(event, unit, id, target)
2137
2240
  end
@@ -2303,10 +2406,12 @@ Unit.onImmediateOrder = dispatchId(__TS__New(
2303
2406
  ____exports.UnitTriggerEvent,
2304
2407
  EVENT_PLAYER_UNIT_ISSUED_ORDER,
2305
2408
  function()
2306
- local unit = ____exports.Unit:of(getOrderedUnit())
2307
- local issuedOrderId = getIssuedOrderId()
2308
- if unit ~= nil and unit.state == 1 then
2309
- return unit, issuedOrderId
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
2310
2415
  end
2311
2416
  return IgnoreEvent
2312
2417
  end
@@ -2328,7 +2433,6 @@ Unit.autoAttackStartEvent = __TS__New(
2328
2433
  )
2329
2434
  Unit.onDamaging = (function()
2330
2435
  local event = __TS__New(Event)
2331
- local invoke = Event.invoke
2332
2436
  local trigger = CreateTrigger()
2333
2437
  TriggerRegisterAnyUnitEventBJ(trigger, EVENT_PLAYER_UNIT_DAMAGING)
2334
2438
  TriggerAddCondition(
@@ -2338,13 +2442,19 @@ Unit.onDamaging = (function()
2338
2442
  if source and source.typeId == dummyUnitId then
2339
2443
  source = nil
2340
2444
  end
2341
- local target = BlzGetEventDamageTarget()
2445
+ local target = ____exports.Unit:of(BlzGetEventDamageTarget())
2446
+ local metadata = damageMetadataByTarget[target]
2447
+ damageMetadataByTarget[target] = nil
2342
2448
  local data = {
2343
2449
  amount = GetEventDamage(),
2344
- attackType = BlzGetEventAttackType(),
2450
+ attackType = nativeToAttackType(BlzGetEventAttackType()),
2345
2451
  damageType = BlzGetEventDamageType(),
2346
2452
  weaponType = BlzGetEventWeaponType(),
2347
- isAttack = BlzGetEventIsAttack()
2453
+ metadata = metadata,
2454
+ isAttack = BlzGetEventIsAttack(),
2455
+ originalAmount = GetEventDamage(),
2456
+ originalMetadata = metadata,
2457
+ preventRetaliation = damagingEventPreventRetaliation
2348
2458
  }
2349
2459
  if data.isAttack and source then
2350
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
@@ -2358,18 +2468,36 @@ Unit.onDamaging = (function()
2358
2468
  invoke(
2359
2469
  event,
2360
2470
  source,
2361
- ____exports.Unit:of(target),
2471
+ target,
2362
2472
  setmetatable(
2363
2473
  {},
2364
2474
  {
2365
2475
  __index = data,
2366
2476
  __newindex = function(self, key, value)
2367
- damageSetters[key](value)
2477
+ local damageSetter = damageSetters[key]
2478
+ if damageSetter ~= nil then
2479
+ damageSetter(value)
2480
+ end
2368
2481
  data[key] = value
2369
2482
  end
2370
2483
  }
2371
2484
  )
2372
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
2373
2501
  return
2374
2502
  end
2375
2503
  BlzSetEventDamage(0)
@@ -2377,7 +2505,7 @@ Unit.onDamaging = (function()
2377
2505
  BlzSetEventDamageType(DAMAGE_TYPE_UNKNOWN)
2378
2506
  BlzSetEventWeaponType(WEAPON_TYPE_WHOKNOWS)
2379
2507
  local sourceOwner = source.owner.handle
2380
- local targetOwner = GetOwningPlayer(target)
2508
+ local targetOwner = target.owner.handle
2381
2509
  if not GetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE) then
2382
2510
  SetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE, true)
2383
2511
  Timer:run(function()
@@ -2393,23 +2521,19 @@ Unit.onDamaging = (function()
2393
2521
  for ____, ____value in ipairs(source._attackHandlers) do
2394
2522
  local condition = ____value[1]
2395
2523
  local action = ____value[2]
2396
- if condition(
2397
- source,
2398
- ____exports.Unit:of(target),
2399
- data
2400
- ) then
2524
+ if condition(source, target, data) then
2401
2525
  action(
2402
2526
  source,
2403
- ____exports.Unit:of(target),
2527
+ target,
2404
2528
  setmetatable(
2405
2529
  {fire = function()
2406
2530
  UnitDamageTarget(
2407
2531
  source.handle,
2408
- target,
2532
+ target.handle,
2409
2533
  data.amount,
2410
2534
  true,
2411
2535
  true,
2412
- data.attackType,
2536
+ attackTypeToNative(data.attackType),
2413
2537
  data.damageType,
2414
2538
  data.weaponType
2415
2539
  )
@@ -2427,7 +2551,6 @@ end)()
2427
2551
  Unit.onDamage = __TS__New(
2428
2552
  InitializingEvent,
2429
2553
  function(event)
2430
- local invoke = Event.invoke
2431
2554
  local trigger = CreateTrigger()
2432
2555
  TriggerRegisterAnyUnitEventBJ(trigger, EVENT_PLAYER_UNIT_DAMAGED)
2433
2556
  TriggerAddCondition(
@@ -2437,29 +2560,54 @@ Unit.onDamage = __TS__New(
2437
2560
  if source and source.typeId == dummyUnitId then
2438
2561
  source = nil
2439
2562
  end
2563
+ local target = ____exports.Unit:of(BlzGetEventDamageTarget())
2564
+ local damagingEvent = damagingEventByTarget[target]
2565
+ damagingEventByTarget[target] = nil
2440
2566
  local data = {
2441
2567
  amount = GetEventDamage(),
2442
- attackType = BlzGetEventAttackType(),
2568
+ attackType = nativeToAttackType(BlzGetEventAttackType()),
2443
2569
  damageType = BlzGetEventDamageType(),
2444
2570
  weaponType = BlzGetEventWeaponType(),
2571
+ metadata = damagingEvent and damagingEvent.metadata,
2445
2572
  isAttack = BlzGetEventIsAttack(),
2573
+ originalAmount = damagingEvent and damagingEvent.originalAmount or GetEventDamage(),
2574
+ originalMetadata = damagingEvent and damagingEvent.originalMetadata,
2446
2575
  preventDeath = damageEventPreventDeath
2447
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
2448
2594
  local evData = setmetatable(
2449
2595
  {},
2450
2596
  {
2451
2597
  __index = data,
2452
2598
  __newindex = function(self, key, value)
2453
- damageSetters[key](value)
2599
+ local damageSetter = damageSetters[key]
2600
+ if damageSetter ~= nil then
2601
+ damageSetter(value)
2602
+ end
2454
2603
  data[key] = value
2455
2604
  end
2456
2605
  }
2457
2606
  )
2458
- local target = ____exports.Unit:of(BlzGetEventDamageTarget())
2459
2607
  invoke(event, source, target, evData)
2460
2608
  if evData[0] ~= nil and target.health - evData.amount < 0.405 then
2461
2609
  local bonusHealth = math.ceil(evData.amount)
2462
- target[104] = (target[104] or 0) + bonusHealth
2610
+ target[105] = (target[105] or 0) + bonusHealth
2463
2611
  BlzSetUnitMaxHP(
2464
2612
  target.handle,
2465
2613
  BlzGetUnitMaxHP(target.handle) + bonusHealth
@@ -2473,7 +2621,7 @@ Unit.onDamage = __TS__New(
2473
2621
  evData[0],
2474
2622
  table.unpack(evData, 1 + 1, 1 + (evData[1] or 0))
2475
2623
  )
2476
- target[104] = (target[104] or 0) - bonusHealth
2624
+ target[105] = (target[105] or 0) - bonusHealth
2477
2625
  SetWidgetLife(
2478
2626
  target.handle,
2479
2627
  GetWidgetLife(target.handle) - bonusHealth
@@ -2493,32 +2641,91 @@ Unit.onDamage = __TS__New(
2493
2641
  DestroyTrigger(trigger)
2494
2642
  end
2495
2643
  )
2496
- Unit.onItemDrop = __TS__New(
2644
+ Unit.itemDroppedEvent = __TS__New(
2497
2645
  ____exports.UnitTriggerEvent,
2498
2646
  EVENT_PLAYER_UNIT_DROP_ITEM,
2499
2647
  function()
2500
2648
  local unit = getTriggerUnit()
2501
- if getUnitTypeId(unit) ~= dummyUnitId then
2502
- 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)
2503
2652
  end
2504
2653
  return IgnoreEvent
2505
2654
  end
2506
2655
  )
2507
- Unit.onItemPickup = __TS__New(
2656
+ Unit.itemPickedUpEvent = __TS__New(
2508
2657
  ____exports.UnitTriggerEvent,
2509
2658
  EVENT_PLAYER_UNIT_PICKUP_ITEM,
2510
2659
  function()
2511
2660
  local unit = getTriggerUnit()
2512
- if getUnitTypeId(unit) ~= dummyUnitId then
2513
- 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)
2514
2664
  end
2515
2665
  return IgnoreEvent
2516
2666
  end
2517
2667
  )
2518
- Unit.onItemUse = __TS__New(
2668
+ Unit.itemUsedEvent = __TS__New(
2519
2669
  ____exports.UnitTriggerEvent,
2520
2670
  EVENT_PLAYER_UNIT_USE_ITEM,
2521
- 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
+ "itemUseOrderEvent",
2688
+ {get = function(self)
2689
+ local event = __TS__New(Event)
2690
+ for order = orderId("useslot0"), orderId("useslot5") do
2691
+ local slot = order - orderId("useslot0")
2692
+ local function listener(unit)
2693
+ local item = unit.items[slot + 1]
2694
+ if item ~= nil then
2695
+ invoke(event, unit, item)
2696
+ end
2697
+ end
2698
+ self.onImmediateOrder[order]:addListener(listener)
2699
+ self.onTargetOrder[order]:addListener(listener)
2700
+ self.onPointOrder[order]:addListener(listener)
2701
+ end
2702
+ rawset(self, "itemUseOrderEvent", event)
2703
+ return event
2704
+ end}
2705
+ )
2706
+ __TS__ObjectDefineProperty(
2707
+ Unit,
2708
+ "itemMoveOrderEvent",
2709
+ {get = function(self)
2710
+ local event = __TS__New(Event)
2711
+ for order = orderId("moveslot0"), orderId("moveslot5") do
2712
+ local slotTo = order - orderId("moveslot0")
2713
+ self.onTargetOrder[order]:addListener(function(unit, item)
2714
+ local slotFrom = unit.items:findSlot(item)
2715
+ if slotFrom ~= nil then
2716
+ invoke(
2717
+ event,
2718
+ unit,
2719
+ item,
2720
+ slotFrom,
2721
+ slotTo
2722
+ )
2723
+ end
2724
+ end)
2725
+ end
2726
+ rawset(self, "itemMoveOrderEvent", event)
2727
+ return event
2728
+ end}
2522
2729
  )
2523
2730
  __TS__ObjectDefineProperty(
2524
2731
  Unit,