warscript 0.0.1-dev.ff5dbcd → 0.0.1-dev.fff719b

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 (170) hide show
  1. package/attributes.d.ts +6 -0
  2. package/attributes.lua +17 -1
  3. package/core/types/effect.d.ts +1 -3
  4. package/core/types/effect.lua +26 -29
  5. package/core/types/frame.lua +24 -21
  6. package/core/types/player.d.ts +16 -0
  7. package/core/types/player.lua +60 -15
  8. package/core/types/playerCamera.d.ts +2 -0
  9. package/core/types/playerCamera.lua +123 -5
  10. package/core/types/sound.d.ts +17 -25
  11. package/core/types/sound.lua +85 -44
  12. package/core/types/tileCell.d.ts +11 -1
  13. package/core/types/tileCell.lua +97 -0
  14. package/core/types/timer.d.ts +9 -8
  15. package/core/types/timer.lua +45 -23
  16. package/decl/native.d.ts +846 -790
  17. package/destroyable.d.ts +1 -0
  18. package/destroyable.lua +9 -0
  19. package/engine/behavior.d.ts +14 -1
  20. package/engine/behavior.lua +230 -70
  21. package/engine/behaviour/ability/apply-buff.lua +5 -5
  22. package/engine/behaviour/ability/apply-unit-behavior.lua +1 -0
  23. package/engine/behaviour/ability/damage.d.ts +9 -3
  24. package/engine/behaviour/ability/damage.lua +26 -38
  25. package/engine/behaviour/ability/emulate-impact.d.ts +1 -1
  26. package/engine/behaviour/ability/emulate-impact.lua +18 -3
  27. package/engine/behaviour/ability/remove-buffs.d.ts +9 -0
  28. package/engine/behaviour/ability/remove-buffs.lua +21 -0
  29. package/engine/behaviour/ability/restore-mana.d.ts +1 -1
  30. package/engine/behaviour/ability/restore-mana.lua +6 -6
  31. package/engine/behaviour/ability.d.ts +7 -2
  32. package/engine/behaviour/ability.lua +28 -22
  33. package/engine/behaviour/unit/stun-immunity.d.ts +12 -6
  34. package/engine/behaviour/unit/stun-immunity.lua +57 -31
  35. package/engine/behaviour/unit.d.ts +40 -2
  36. package/engine/behaviour/unit.lua +269 -6
  37. package/engine/buff.d.ts +32 -14
  38. package/engine/buff.lua +249 -152
  39. package/engine/internal/ability.d.ts +7 -1
  40. package/engine/internal/ability.lua +49 -9
  41. package/engine/internal/item/ability.lua +63 -11
  42. package/engine/internal/item+owner.lua +12 -6
  43. package/engine/internal/item.d.ts +18 -17
  44. package/engine/internal/item.lua +135 -49
  45. package/engine/internal/mechanics/ability-duration.lua +1 -1
  46. package/engine/internal/mechanics/cast-ability.lua +6 -3
  47. package/engine/internal/misc/damage-metadata-by-target.d.ts +2 -0
  48. package/engine/internal/misc/damage-metadata-by-target.lua +5 -0
  49. package/engine/internal/misc/frame-coordinates.d.ts +2 -0
  50. package/engine/internal/misc/frame-coordinates.lua +21 -0
  51. package/engine/internal/misc/get-terrain-z.d.ts +2 -0
  52. package/engine/internal/misc/get-terrain-z.lua +11 -0
  53. package/engine/internal/misc/player-local-handle.d.ts +2 -0
  54. package/engine/internal/misc/player-local-handle.lua +5 -0
  55. package/engine/internal/object-data/mana-regeneration-rate-increase-factor.d.ts +2 -0
  56. package/engine/internal/object-data/mana-regeneration-rate-increase-factor.lua +16 -0
  57. package/engine/internal/unit/ability.d.ts +35 -0
  58. package/engine/internal/unit/ability.lua +98 -9
  59. package/engine/internal/unit/allowed-targets.d.ts +1 -1
  60. package/engine/internal/unit/allowed-targets.lua +9 -1
  61. package/engine/internal/unit/attributes.d.ts +17 -0
  62. package/engine/internal/unit/attributes.lua +46 -0
  63. package/engine/internal/unit/bonus.d.ts +2 -0
  64. package/engine/internal/unit/bonus.lua +10 -0
  65. package/engine/internal/unit/fly-height.d.ts +7 -0
  66. package/engine/internal/unit/fly-height.lua +20 -0
  67. package/engine/internal/unit/interrupts.d.ts +12 -0
  68. package/engine/internal/unit/interrupts.lua +28 -0
  69. package/engine/internal/unit/main-selected.lua +12 -27
  70. package/engine/internal/unit/order.d.ts +20 -0
  71. package/engine/internal/unit/order.lua +136 -0
  72. package/engine/internal/unit/scale.d.ts +7 -0
  73. package/engine/internal/unit/scale.lua +20 -0
  74. package/engine/internal/unit+ability.lua +10 -1
  75. package/engine/internal/unit+damage.d.ts +2 -11
  76. package/engine/internal/unit+damage.lua +10 -14
  77. package/engine/internal/unit+spellSteal.lua +1 -2
  78. package/engine/internal/unit-missile-launch.lua +52 -14
  79. package/engine/internal/unit.d.ts +42 -24
  80. package/engine/internal/unit.lua +377 -232
  81. package/engine/local-client.d.ts +2 -0
  82. package/engine/local-client.lua +30 -0
  83. package/engine/object-data/auxiliary/armor-type.d.ts +11 -0
  84. package/engine/object-data/auxiliary/armor-type.lua +46 -0
  85. package/engine/object-data/auxiliary/attachment-preset.d.ts +7 -2
  86. package/engine/object-data/auxiliary/attachment-preset.lua +4 -3
  87. package/engine/object-data/auxiliary/attack-type.d.ts +7 -8
  88. package/engine/object-data/auxiliary/attack-type.lua +42 -0
  89. package/engine/object-data/auxiliary/health-regeneration-type.d.ts +8 -0
  90. package/engine/object-data/auxiliary/health-regeneration-type.lua +2 -0
  91. package/engine/object-data/auxiliary/movement-type.d.ts +7 -7
  92. package/engine/object-data/auxiliary/movement-type.lua +22 -0
  93. package/engine/object-data/auxiliary/sound-eax.d.ts +10 -0
  94. package/engine/object-data/auxiliary/sound-eax.lua +2 -0
  95. package/engine/object-data/auxiliary/unit-attribute.d.ts +6 -0
  96. package/engine/object-data/auxiliary/unit-attribute.lua +9 -0
  97. package/engine/object-data/entry/ability-type/berserk.d.ts +2 -0
  98. package/engine/object-data/entry/ability-type/berserk.lua +13 -0
  99. package/engine/object-data/entry/ability-type/carrion-swarm.d.ts +14 -0
  100. package/engine/object-data/entry/ability-type/carrion-swarm.lua +65 -0
  101. package/engine/object-data/entry/ability-type/ensnare.d.ts +12 -0
  102. package/engine/object-data/entry/ability-type/ensnare.lua +52 -0
  103. package/engine/object-data/entry/ability-type/mana-regeneration.d.ts +8 -0
  104. package/engine/object-data/entry/ability-type/mana-regeneration.lua +26 -0
  105. package/engine/object-data/entry/ability-type/permanent-invisibility.d.ts +8 -0
  106. package/engine/object-data/entry/ability-type/permanent-invisibility.lua +26 -0
  107. package/engine/object-data/entry/ability-type/phase-shift.d.ts +10 -0
  108. package/engine/object-data/entry/ability-type/phase-shift.lua +39 -0
  109. package/engine/object-data/entry/ability-type/raise-dead.d.ts +17 -0
  110. package/engine/object-data/entry/ability-type/raise-dead.lua +78 -0
  111. package/engine/object-data/entry/ability-type/shock-wave.d.ts +4 -0
  112. package/engine/object-data/entry/ability-type/shock-wave.lua +26 -0
  113. package/engine/object-data/entry/ability-type/slow-poison.d.ts +10 -0
  114. package/engine/object-data/entry/ability-type/slow-poison.lua +58 -0
  115. package/engine/object-data/entry/ability-type/web.d.ts +12 -0
  116. package/engine/object-data/entry/ability-type/web.lua +52 -0
  117. package/engine/object-data/entry/ability-type.d.ts +11 -11
  118. package/engine/object-data/entry/ability-type.lua +35 -13
  119. package/engine/object-data/entry/buff-type/applicable.lua +5 -0
  120. package/engine/object-data/entry/buff-type.d.ts +5 -11
  121. package/engine/object-data/entry/buff-type.lua +11 -27
  122. package/engine/object-data/entry/destructible-type.d.ts +27 -1
  123. package/engine/object-data/entry/destructible-type.lua +155 -0
  124. package/engine/object-data/entry/sound-preset.d.ts +17 -0
  125. package/engine/object-data/entry/sound-preset.lua +104 -0
  126. package/engine/object-data/entry/unit-type.d.ts +17 -4
  127. package/engine/object-data/entry/unit-type.lua +197 -85
  128. package/engine/object-field/ability.d.ts +4 -4
  129. package/engine/object-field/ability.lua +7 -6
  130. package/engine/object-field/unit.d.ts +72 -3
  131. package/engine/object-field/unit.lua +268 -7
  132. package/engine/object-field.d.ts +25 -6
  133. package/engine/object-field.lua +357 -118
  134. package/engine/random.d.ts +9 -0
  135. package/engine/random.lua +13 -0
  136. package/engine/standard/entries/buff-type.d.ts +3 -0
  137. package/engine/standard/entries/buff-type.lua +3 -0
  138. package/engine/standard/fields/ability.d.ts +2 -2
  139. package/engine/standard/fields/ability.lua +2 -2
  140. package/engine/standard/fields/unit.d.ts +12 -0
  141. package/engine/standard/fields/unit.lua +20 -0
  142. package/engine/synchronization.d.ts +11 -0
  143. package/engine/synchronization.lua +77 -0
  144. package/engine/text-tag.d.ts +36 -2
  145. package/engine/text-tag.lua +250 -10
  146. package/engine/unit.d.ts +5 -0
  147. package/engine/unit.lua +5 -0
  148. package/net/socket.lua +1 -1
  149. package/objutil/buff.lua +11 -10
  150. package/package.json +2 -2
  151. package/patch-lua.lua +9 -0
  152. package/patch-lualib.lua +1 -1
  153. package/utility/arrays.d.ts +2 -0
  154. package/utility/arrays.lua +11 -0
  155. package/utility/callback-array.d.ts +17 -0
  156. package/utility/callback-array.lua +61 -0
  157. package/utility/functions.d.ts +8 -0
  158. package/utility/functions.lua +13 -0
  159. package/utility/linked-map.d.ts +26 -0
  160. package/utility/linked-map.lua +66 -0
  161. package/utility/linked-set.d.ts +2 -0
  162. package/utility/linked-set.lua +26 -1
  163. package/utility/lua-maps.d.ts +15 -2
  164. package/utility/lua-maps.lua +53 -2
  165. package/utility/lua-sets.d.ts +2 -0
  166. package/utility/lua-sets.lua +7 -0
  167. package/utility/records.lua +20 -1
  168. package/utility/types.d.ts +3 -0
  169. package/core/types/order.d.ts +0 -25
  170. package/core/types/order.lua +0 -55
@@ -53,34 +53,40 @@ local ____math = require("math")
53
53
  local min = ____math.min
54
54
  local ____ignore_2Devents_2Ditems = require("engine.internal.unit.ignore-events-items")
55
55
  local ignoreEventsItems = ____ignore_2Devents_2Ditems.ignoreEventsItems
56
+ local ____attack_2Dtype = require("engine.object-data.auxiliary.attack-type")
57
+ local attackTypeToNative = ____attack_2Dtype.attackTypeToNative
58
+ local nativeToAttackType = ____attack_2Dtype.nativeToAttackType
59
+ local ____damage_2Dmetadata_2Dby_2Dtarget = require("engine.internal.misc.damage-metadata-by-target")
60
+ local damageMetadataByTarget = ____damage_2Dmetadata_2Dby_2Dtarget.damageMetadataByTarget
61
+ local ____attributes = require("attributes")
62
+ local isAttribute = ____attributes.isAttribute
63
+ local ____ability = require("engine.internal.item.ability")
64
+ local doUnitAbilityAction = ____ability.doUnitAbilityAction
65
+ local ____synchronization = require("engine.synchronization")
66
+ local synchronizer = ____synchronization.synchronizer
67
+ local ____linked_2Dmap = require("utility.linked-map")
68
+ local LinkedMap = ____linked_2Dmap.LinkedMap
56
69
  local match = string.match
57
70
  local ____tostring = _G.tostring
58
71
  local setUnitAnimation = SetUnitAnimation
59
- local setUnitAnimationWithRarity = SetUnitAnimationWithRarity
60
72
  local setUnitAnimationByIndex = SetUnitAnimationByIndex
61
- local queueUnitAnimation = QueueUnitAnimation
62
73
  local getUnitIntegerField = BlzGetUnitIntegerField
63
74
  local getUnitRealField = BlzGetUnitRealField
64
75
  local getHeroStr = GetHeroStr
65
76
  local getHeroAgi = GetHeroAgi
66
77
  local getHeroInt = GetHeroInt
67
- local setHeroStr = SetHeroStr
68
- local setHeroAgi = SetHeroAgi
69
- local setHeroInt = SetHeroInt
70
78
  local getUnitBooleanField = BlzGetUnitBooleanField
71
79
  local getUnitStringField = BlzGetUnitStringField
72
80
  local setUnitIntegerField = BlzSetUnitIntegerField
73
81
  local setUnitRealField = BlzSetUnitRealField
74
82
  local setUnitBooleanField = BlzSetUnitBooleanField
75
83
  local setUnitStringField = BlzSetUnitStringField
76
- local setUnitScale = SetUnitScale
77
84
  local setUnitPosition = SetUnitPosition
78
85
  local setUnitTimeScale = SetUnitTimeScale
79
86
  local getHandleId = GetHandleId
80
87
  local getUnitCurrentOrder = GetUnitCurrentOrder
81
88
  local createUnit = CreateUnit
82
89
  local killUnit = KillUnit
83
- local setUnitExploded = SetUnitExploded
84
90
  local removeUnit = RemoveUnit
85
91
  local getUnitTypeId = GetUnitTypeId
86
92
  local isHeroUnitId = IsHeroUnitId
@@ -96,15 +102,12 @@ local getSpellTargetItem = GetSpellTargetItem
96
102
  local getSpellTargetDestructable = GetSpellTargetDestructable
97
103
  local isUnitInRangeXY = IsUnitInRangeXY
98
104
  local isUnitInRange = IsUnitInRange
99
- local setResourceAmount = SetResourceAmount
100
- local getResourceAmount = GetResourceAmount
101
105
  local getUnitWeaponRealField = BlzGetUnitWeaponRealField
102
106
  local setUnitWeaponRealField = BlzSetUnitWeaponRealField
103
107
  local getUnitWeaponStringField = BlzGetUnitWeaponStringField
104
108
  local setUnitWeaponStringField = BlzSetUnitWeaponStringField
105
109
  local getUnitAbilityLevel = GetUnitAbilityLevel
106
110
  local unitDisableAbility = BlzUnitDisableAbility
107
- local unitInterruptAttack = BlzUnitInterruptAttack
108
111
  local isUnitInvisible = IsUnitInvisible
109
112
  local isUnitVisible = IsUnitVisible
110
113
  local getUnitX = GetUnitX
@@ -121,15 +124,9 @@ local getOrderedUnit = GetOrderedUnit
121
124
  local getIssuedOrderId = GetIssuedOrderId
122
125
  local isUnitInvulnerable = BlzIsUnitInvulnerable
123
126
  local unitAlive = UnitAlive
124
- local unitAddType = UnitAddType
125
- local unitRemoveType = UnitRemoveType
126
- local isUnitIllusion = IsUnitIllusion
127
- local isUnitType = IsUnitType
128
127
  local isUnitAlly = IsUnitAlly
129
128
  local isUnitEnemy = IsUnitEnemy
130
129
  local getOwningPlayer = GetOwningPlayer
131
- local setUnitColor = SetUnitColor
132
- local showUnitTeamGlow = BlzShowUnitTeamGlow
133
130
  ____exports.UnitClassification = {}
134
131
  local UnitClassification = ____exports.UnitClassification
135
132
  do
@@ -139,6 +136,7 @@ do
139
136
  UnitClassification.GROUND = UNIT_TYPE_GROUND
140
137
  UnitClassification.SUMMONED = UNIT_TYPE_SUMMONED
141
138
  UnitClassification.MECHANICAL = UNIT_TYPE_MECHANICAL
139
+ UnitClassification.WORKER = UNIT_TYPE_PEON
142
140
  UnitClassification.ANCIENT = UNIT_TYPE_ANCIENT
143
141
  UnitClassification.SUICIDAL = UNIT_TYPE_SAPPER
144
142
  UnitClassification.TAUREN = UNIT_TYPE_TAUREN
@@ -346,6 +344,9 @@ local function dispatchAbility(event)
346
344
  }
347
345
  )
348
346
  end
347
+ local function damagingEventPreventRetaliation(self)
348
+ self[0] = true
349
+ end
349
350
  local function damageEventPreventDeath(self, callback, ...)
350
351
  if self[0] ~= nil then
351
352
  return
@@ -357,7 +358,14 @@ local function damageEventPreventDeath(self, callback, ...)
357
358
  rawset(self, 1 + i, (select(i, ...)))
358
359
  end
359
360
  end
360
- local damageSetters = {amount = BlzSetEventDamage, attackType = BlzSetEventAttackType, damageType = BlzSetEventDamageType, weaponType = BlzSetEventWeaponType}
361
+ local damageSetters = {
362
+ amount = BlzSetEventDamage,
363
+ attackType = function(attackType)
364
+ return BlzSetEventAttackType(attackTypeToNative(attackType))
365
+ end,
366
+ damageType = BlzSetEventDamageType,
367
+ weaponType = BlzSetEventWeaponType
368
+ }
361
369
  local jlimitopByOperator = {
362
370
  [0] = LESS_THAN_OR_EQUAL,
363
371
  [1] = LESS_THAN_OR_EQUAL,
@@ -375,15 +383,27 @@ local modifiers = {
375
383
  end,
376
384
  armor = function(unit, value)
377
385
  if UnitAddAbility(unit, armorBonusAbilityId) then
378
- assert(UnitMakeAbilityPermanent(unit, true, armorBonusAbilityId))
386
+ assert(
387
+ UnitMakeAbilityPermanent(unit, true, armorBonusAbilityId),
388
+ "armor bonus ability must be made permanent",
389
+ unit
390
+ )
379
391
  end
380
- local ability = assert(BlzGetUnitAbility(unit, armorBonusAbilityId))
381
- assert(BlzSetAbilityRealLevelField(
382
- ability,
383
- armorBonusField,
384
- 0,
385
- BlzGetAbilityRealLevelField(ability, armorBonusField, 0) + value
386
- ))
392
+ local ability = assert(
393
+ BlzGetUnitAbility(unit, armorBonusAbilityId),
394
+ "armor bonus ability must be existing",
395
+ unit
396
+ )
397
+ assert(
398
+ BlzSetAbilityRealLevelField(
399
+ ability,
400
+ armorBonusField,
401
+ 0,
402
+ BlzGetAbilityRealLevelField(ability, armorBonusField, 0) + value
403
+ ),
404
+ "armor bonus ability field must be set",
405
+ unit
406
+ )
387
407
  end
388
408
  }
389
409
  local getters = {
@@ -401,6 +421,19 @@ function UnitWeapon.prototype.____constructor(self, unit, index)
401
421
  self.unit = unit
402
422
  self.index = index
403
423
  end
424
+ __TS__SetDescriptor(
425
+ UnitWeapon.prototype,
426
+ "isEnabled",
427
+ {
428
+ get = function(self)
429
+ return BlzGetUnitWeaponBooleanField(self.unit.handle, UNIT_WEAPON_BF_ATTACKS_ENABLED, self.index)
430
+ end,
431
+ set = function(self, isEnabled)
432
+ BlzSetUnitWeaponBooleanField(self.unit.handle, UNIT_WEAPON_BF_ATTACKS_ENABLED, self.index, isEnabled)
433
+ end
434
+ },
435
+ true
436
+ )
404
437
  __TS__SetDescriptor(
405
438
  UnitWeapon.prototype,
406
439
  "cooldown",
@@ -435,6 +468,19 @@ __TS__SetDescriptor(
435
468
  },
436
469
  true
437
470
  )
471
+ __TS__SetDescriptor(
472
+ UnitWeapon.prototype,
473
+ "allowedTargetCombatClassifications",
474
+ {
475
+ get = function(self)
476
+ return BlzGetUnitWeaponIntegerField(self.unit.handle, UNIT_WEAPON_IF_ATTACK_TARGETS_ALLOWED, self.index)
477
+ end,
478
+ set = function(self, allowedTargetCombatClassifications)
479
+ BlzSetUnitWeaponIntegerField(self.unit.handle, UNIT_WEAPON_IF_ATTACK_TARGETS_ALLOWED, self.index, allowedTargetCombatClassifications)
480
+ end
481
+ },
482
+ true
483
+ )
438
484
  __TS__SetDescriptor(
439
485
  UnitWeapon.prototype,
440
486
  "damageBase",
@@ -611,26 +657,30 @@ local fieldSetters = {
611
657
  }
612
658
  local dummies = {}
613
659
  for ____, player in ipairs(Player.all) do
614
- local dummy = assert(createUnit(
615
- player.handle,
616
- dummyUnitId,
617
- 0,
618
- 0,
619
- 270
620
- ))
660
+ local dummy = assert(
661
+ createUnit(
662
+ player.handle,
663
+ dummyUnitId,
664
+ 0,
665
+ 0,
666
+ 270
667
+ ),
668
+ "dummy must be created",
669
+ player
670
+ )
621
671
  ShowUnit(dummy, false)
622
672
  dummies[player] = dummy
623
673
  end
624
674
  local function delayHealthChecksCallback(unit)
625
- local counter = (unit[103] or 0) - 1
675
+ local counter = (unit[104] or 0) - 1
626
676
  if counter ~= 0 then
627
- unit[103] = counter
677
+ unit[104] = counter
628
678
  return
629
679
  end
630
- unit[103] = nil
631
- local healthBonus = unit[104]
680
+ unit[104] = nil
681
+ local healthBonus = unit[105]
632
682
  if healthBonus ~= nil then
633
- unit[104] = nil
683
+ unit[105] = nil
634
684
  local handle = unit.handle
635
685
  BlzSetUnitMaxHP(
636
686
  handle,
@@ -639,47 +689,73 @@ local function delayHealthChecksCallback(unit)
639
689
  end
640
690
  end
641
691
  local nextSyncId = 1
642
- local unitBySyncId = setmetatable({}, {__mode = "k"})
692
+ local unitBySyncId = setmetatable({}, {__mode = "v"})
693
+ local damagingEventByTarget = setmetatable({}, {__mode = "k"})
694
+ local function addAbility(unit, abilityTypeId)
695
+ local ____unitAddAbility_result_0
696
+ if unitAddAbility(unit, abilityTypeId) then
697
+ ____unitAddAbility_result_0 = getUnitAbility(unit, abilityTypeId)
698
+ else
699
+ ____unitAddAbility_result_0 = nil
700
+ end
701
+ return ____unitAddAbility_result_0
702
+ end
643
703
  ____exports.Unit = __TS__Class()
644
704
  local Unit = ____exports.Unit
645
705
  Unit.name = "Unit"
646
706
  __TS__ClassExtends(Unit, Handle)
647
707
  function Unit.prototype.____constructor(self, handle)
648
708
  Handle.prototype.____constructor(self, handle)
649
- local ____nextSyncId_0 = nextSyncId
650
- nextSyncId = ____nextSyncId_0 + 1
651
- self.syncId = ____nextSyncId_0
709
+ local ____nextSyncId_1 = nextSyncId
710
+ nextSyncId = ____nextSyncId_1 + 1
711
+ self.syncId = ____nextSyncId_1
652
712
  self._owner = Player:of(getOwningPlayer(handle))
653
- assert(unitAddAbility(handle, leaveDetectAbilityId) and UnitMakeAbilityPermanent(handle, true, leaveDetectAbilityId))
654
- assert(unitAddAbility(handle, morphDetectAbilityId))
713
+ assert(
714
+ unitAddAbility(handle, leaveDetectAbilityId) and UnitMakeAbilityPermanent(handle, true, leaveDetectAbilityId),
715
+ "leave detection ability must be added",
716
+ self
717
+ )
718
+ assert(
719
+ unitAddAbility(handle, morphDetectAbilityId),
720
+ "morph detection ability must be added",
721
+ self
722
+ )
655
723
  if unitAddAbility(
656
724
  handle,
657
725
  fourCC("Amrf")
658
726
  ) then
659
- assert(unitRemoveAbility(
660
- handle,
661
- fourCC("Amrf")
662
- ))
727
+ assert(
728
+ unitRemoveAbility(
729
+ handle,
730
+ fourCC("Amrf")
731
+ ),
732
+ "fly ability must be removed after addition",
733
+ self
734
+ )
663
735
  end
664
736
  unitBySyncId[self.syncId] = self
665
737
  local ____ = self.abilities
666
738
  end
667
- function Unit.prototype.getEvent(self, event, collector)
668
- self.events = self.events or ({})
669
- local eventId = GetHandleId(event)
670
- if not self.events[eventId] then
671
- self.events[eventId] = __TS__New(
739
+ function Unit.prototype.getEvent(self, jevent, collector)
740
+ self.events = self.events or __TS__New(LinkedMap)
741
+ local eventId = GetHandleId(jevent)
742
+ local event = self.events:get(eventId)
743
+ if event == nil then
744
+ event = __TS__New(
672
745
  TriggerEvent,
673
746
  function(trigger)
674
- TriggerRegisterUnitEvent(trigger, self.handle, event)
747
+ TriggerRegisterUnitEvent(trigger, self.handle, jevent)
675
748
  end,
676
749
  collector or (function() return {} end)
677
750
  )
751
+ self.events:put(eventId, event)
678
752
  end
679
- return self.events[eventId]
753
+ return event
680
754
  end
681
755
  function Unit.prototype.onDestroy(self)
682
756
  local handle = self.handle
757
+ self[108] = getUnitX(handle)
758
+ self[109] = getUnitY(handle)
683
759
  if not self._owner then
684
760
  self._owner = Player:of(getOwningPlayer(handle))
685
761
  end
@@ -718,7 +794,11 @@ function Unit.prototype.addAttackHandler(self, condition, action)
718
794
  self._attackHandlers = handlers
719
795
  if #handlers == 1 then
720
796
  local handle = self.handle
721
- assert(unitAddAbility(handle, attackHandlerAbilityId) and UnitMakeAbilityPermanent(handle, true, attackHandlerAbilityId))
797
+ assert(
798
+ unitAddAbility(handle, attackHandlerAbilityId) and UnitMakeAbilityPermanent(handle, true, attackHandlerAbilityId),
799
+ "attack handler ability must be added",
800
+ self
801
+ )
722
802
  end
723
803
  return handler
724
804
  end
@@ -747,17 +827,17 @@ function Unit.prototype.addModifier(self, property, modifier)
747
827
  end}
748
828
  end
749
829
  function Unit.prototype.hasCombatClassification(self, combatClassification)
750
- local ____combatClassification_1 = combatClassification
751
- return getUnitIntegerField(self.handle, UNIT_IF_TARGETED_AS) & ____combatClassification_1 == ____combatClassification_1
830
+ local ____combatClassification_2 = combatClassification
831
+ return getUnitIntegerField(self.handle, UNIT_IF_TARGETED_AS) & ____combatClassification_2 == ____combatClassification_2
752
832
  end
753
833
  function Unit.prototype.addClassification(self, classification)
754
- return unitAddType(self.handle, classification)
834
+ return UnitAddType(self.handle, classification)
755
835
  end
756
836
  function Unit.prototype.removeClassification(self, classification)
757
- return unitRemoveType(self.handle, classification)
837
+ return UnitRemoveType(self.handle, classification)
758
838
  end
759
839
  function Unit.prototype.hasClassification(self, classification)
760
- return isUnitType(self.handle, classification)
840
+ return IsUnitType(self.handle, classification)
761
841
  end
762
842
  function Unit.prototype.isVisibleTo(self, player)
763
843
  return isUnitVisible(self.handle, player.handle)
@@ -766,13 +846,13 @@ function Unit.prototype.isInvisibleTo(self, player)
766
846
  return isUnitInvisible(self.handle, player.handle)
767
847
  end
768
848
  function Unit.prototype.isInRangeOf(self, x, y, range)
769
- local ____temp_2
849
+ local ____temp_3
770
850
  if type(x) == "number" then
771
- ____temp_2 = isUnitInRangeXY(self.handle, x, y, range)
851
+ ____temp_3 = isUnitInRangeXY(self.handle, x, y, range)
772
852
  else
773
- ____temp_2 = isUnitInRange(self.handle, x.handle, y)
853
+ ____temp_3 = isUnitInRange(self.handle, x.handle, y)
774
854
  end
775
- return ____temp_2
855
+ return ____temp_3
776
856
  end
777
857
  function Unit.prototype.isAllyOf(self, unit)
778
858
  return isUnitAlly(
@@ -790,16 +870,30 @@ function Unit.prototype.playAnimation(self, animation, rarity)
790
870
  if type(animation) == "number" then
791
871
  setUnitAnimationByIndex(self.handle, animation)
792
872
  elseif rarity then
793
- setUnitAnimationWithRarity(self.handle, animation, rarity)
873
+ SetUnitAnimationWithRarity(self.handle, animation, rarity)
794
874
  else
795
875
  setUnitAnimation(self.handle, animation)
796
876
  end
797
877
  end
878
+ function Unit.prototype.resetAnimation(self)
879
+ ResetUnitAnimation(self.handle)
880
+ end
798
881
  function Unit.prototype.queueAnimation(self, animation)
799
- queueUnitAnimation(self.handle, animation)
882
+ QueueUnitAnimation(self.handle, animation)
883
+ end
884
+ function Unit.prototype.chooseWeapon(self, target)
885
+ local firstWeapon = self.firstWeapon
886
+ if firstWeapon.isEnabled and target:isAllowedTarget(self, firstWeapon.allowedTargetCombatClassifications) then
887
+ return firstWeapon
888
+ end
889
+ local secondWeapon = self.secondWeapon
890
+ if secondWeapon.isEnabled and target:isAllowedTarget(target, secondWeapon.allowedTargetCombatClassifications) then
891
+ return secondWeapon
892
+ end
893
+ return nil
800
894
  end
801
895
  function Unit.prototype.delayHealthChecks(self)
802
- self[103] = (self[103] or 0) + 1
896
+ self[104] = (self[104] or 0) + 1
803
897
  Timer:run(delayHealthChecksCallback, self)
804
898
  end
805
899
  function Unit.prototype.setPosition(self, x, y)
@@ -809,21 +903,21 @@ function Unit.prototype.isSelected(self, player)
809
903
  return IsUnitSelected(self.handle, player.handle)
810
904
  end
811
905
  function Unit.prototype.explode(self)
812
- setUnitExploded(self.handle, true)
906
+ SetUnitExploded(self.handle, true)
813
907
  killUnit(self.handle)
814
908
  end
815
909
  function Unit.prototype.kill(self)
816
910
  killUnit(self.handle)
817
911
  end
818
912
  function Unit.prototype.revive(self, x, y, doEffect)
819
- local ____ReviveHero_5 = ReviveHero
820
- local ____array_4 = __TS__SparseArrayNew(self.handle, x, y)
821
- local ____doEffect_3 = doEffect
822
- if ____doEffect_3 == nil then
823
- ____doEffect_3 = false
913
+ local ____ReviveHero_6 = ReviveHero
914
+ local ____array_5 = __TS__SparseArrayNew(self.handle, x, y)
915
+ local ____doEffect_4 = doEffect
916
+ if ____doEffect_4 == nil then
917
+ ____doEffect_4 = false
824
918
  end
825
- __TS__SparseArrayPush(____array_4, ____doEffect_3)
826
- ____ReviveHero_5(__TS__SparseArraySpread(____array_4))
919
+ __TS__SparseArrayPush(____array_5, ____doEffect_4)
920
+ ____ReviveHero_6(__TS__SparseArraySpread(____array_5))
827
921
  end
828
922
  function Unit.prototype.healTarget(self, target, amount)
829
923
  if __TS__InstanceOf(target, ____exports.Unit) and target:hasAbility(fourCC("BIhm")) then
@@ -866,17 +960,16 @@ function Unit.prototype.itemInSlot(self, slot)
866
960
  return Item:of(unitItemInSlot(self.handle, slot))
867
961
  end
868
962
  function Unit.prototype.addAbility(self, abilityId)
869
- if unitAddAbility(self.handle, abilityId) then
870
- local ability = UnitAbility:of(
871
- checkNotNull(getUnitAbility(self.handle, abilityId)),
872
- abilityId,
873
- self
874
- )
963
+ local ability = UnitAbility:of(
964
+ doUnitAbilityAction(self.handle, abilityId, addAbility, abilityId),
965
+ abilityId,
966
+ self
967
+ )
968
+ if ability ~= nil then
875
969
  local abilities = self.abilities
876
970
  abilities[#abilities + 1] = ability
877
- return ability
878
971
  end
879
- return nil
972
+ return ability
880
973
  end
881
974
  function Unit.prototype.makeAbilityPermanent(self, abilityId, permanent)
882
975
  return UnitMakeAbilityPermanent(self.handle, permanent, abilityId)
@@ -890,31 +983,21 @@ end
890
983
  function Unit.prototype.hasAbility(self, abilityId)
891
984
  return getUnitAbilityLevel(self.handle, abilityId) > 0
892
985
  end
893
- function Unit.prototype.getAbilityById(self, abilityId)
894
- local handle = self.handle
895
- if unitAddAbility(handle, abilityId) then
896
- assert(unitRemoveAbility(handle, abilityId))
897
- return nil
898
- end
899
- return UnitAbility:of(
900
- getUnitAbility(self.handle, abilityId),
901
- abilityId,
902
- self
903
- )
986
+ function Unit.prototype.getAbility(self, abilityId)
987
+ local ability = doUnitAbilityAction(self.handle, abilityId, getUnitAbility, abilityId)
988
+ return UnitAbility:of(ability, abilityId, self)
904
989
  end
905
- function Unit.prototype.removeAbility(self, abilityId)
906
- if unitRemoveAbility(self.handle, abilityId) then
907
- local abilities = self.abilities
908
- for i = 1, #abilities do
909
- if abilities[i].typeId == abilityId then
910
- abilities[i]:destroy()
911
- tremove(abilities, i)
912
- return true
913
- end
990
+ function Unit.prototype.removeAbility(self, abilityTypeId)
991
+ local abilities = self.abilities
992
+ for i = 1, #abilities do
993
+ if abilities[i].typeId == abilityTypeId then
994
+ local ability = abilities[i]
995
+ tremove(abilities, i)
996
+ ability:destroy()
997
+ return true
914
998
  end
915
- return true
916
999
  end
917
- return false
1000
+ return doUnitAbilityAction(self.handle, abilityTypeId, unitRemoveAbility, abilityTypeId)
918
1001
  end
919
1002
  function Unit.prototype.hideAbility(self, abilityId, flag)
920
1003
  BlzUnitHideAbility(self.handle, abilityId, flag)
@@ -928,9 +1011,6 @@ end
928
1011
  function Unit.prototype.endAbilityCooldown(self, abilityId)
929
1012
  BlzEndUnitAbilityCooldown(self.handle, abilityId)
930
1013
  end
931
- function Unit.prototype.interruptAttack(self)
932
- unitInterruptAttack(self.handle)
933
- end
934
1014
  function Unit.prototype.interruptCast(self, abilityId)
935
1015
  local handle = self.handle
936
1016
  unitDisableAbility(handle, abilityId, true, false)
@@ -1001,18 +1081,44 @@ function Unit.prototype.unpauseEx(self)
1001
1081
  end
1002
1082
  function Unit.prototype.incrementStunCounter(self)
1003
1083
  local stunCounter = self[102] or 0
1004
- if not self[101] or stunCounter >= 0 then
1084
+ if not self[101] and (self[103] or 0) <= 0 or stunCounter >= 0 then
1005
1085
  BlzPauseUnitEx(self.handle, true)
1006
1086
  end
1007
1087
  self[102] = stunCounter + 1
1008
1088
  end
1009
1089
  function Unit.prototype.decrementStunCounter(self)
1010
1090
  local stunCounter = self[102] or 0
1011
- if not self[101] or stunCounter >= 1 then
1091
+ if not self[101] and (self[103] or 0) <= 0 or stunCounter >= 1 then
1012
1092
  BlzPauseUnitEx(self.handle, false)
1013
1093
  end
1014
1094
  self[102] = stunCounter - 1
1015
1095
  end
1096
+ function Unit.prototype.incrementForceStunCounter(self)
1097
+ local forceStunCounter = self[103] or 0
1098
+ if forceStunCounter == 0 then
1099
+ local handle = self.handle
1100
+ if not self[101] then
1101
+ for _ = self[102] or 0, -1 do
1102
+ BlzPauseUnitEx(handle, true)
1103
+ end
1104
+ end
1105
+ BlzPauseUnitEx(handle, true)
1106
+ end
1107
+ self[103] = forceStunCounter + 1
1108
+ end
1109
+ function Unit.prototype.decrementForceStunCounter(self)
1110
+ local forceStunCounter = self[103] or 0
1111
+ if forceStunCounter == 1 then
1112
+ local handle = self.handle
1113
+ if not self[101] then
1114
+ for _ = self[102] or 0, -1 do
1115
+ BlzPauseUnitEx(handle, false)
1116
+ end
1117
+ end
1118
+ BlzPauseUnitEx(handle, false)
1119
+ end
1120
+ self[103] = forceStunCounter - 1
1121
+ end
1016
1122
  function Unit.create(self, owner, id, x, y, facing, skinId)
1017
1123
  local handle = skinId and BlzCreateUnitWithSkin(
1018
1124
  owner.handle,
@@ -1201,7 +1307,7 @@ __TS__SetDescriptor(
1201
1307
  Unit.prototype,
1202
1308
  "isIllusion",
1203
1309
  {get = function(self)
1204
- return isUnitIllusion(self.handle)
1310
+ return IsUnitIllusion(self.handle)
1205
1311
  end},
1206
1312
  true
1207
1313
  )
@@ -1288,13 +1394,13 @@ __TS__SetDescriptor(
1288
1394
  )
1289
1395
  __TS__SetDescriptor(
1290
1396
  Unit.prototype,
1291
- "strengthBase",
1397
+ "primaryAttribute",
1292
1398
  {
1293
1399
  get = function(self)
1294
- return getHeroStr(self.handle, false)
1400
+ return getUnitIntegerField(self.handle, UNIT_IF_PRIMARY_ATTRIBUTE)
1295
1401
  end,
1296
- set = function(self, strengthBase)
1297
- setHeroStr(self.handle, strengthBase, true)
1402
+ set = function(self, primaryAttribute)
1403
+ setUnitIntegerField(self.handle, UNIT_IF_PRIMARY_ATTRIBUTE, primaryAttribute)
1298
1404
  end
1299
1405
  },
1300
1406
  true
@@ -1316,19 +1422,6 @@ __TS__SetDescriptor(
1316
1422
  end},
1317
1423
  true
1318
1424
  )
1319
- __TS__SetDescriptor(
1320
- Unit.prototype,
1321
- "agilityBase",
1322
- {
1323
- get = function(self)
1324
- return getHeroAgi(self.handle, false)
1325
- end,
1326
- set = function(self, agilityBase)
1327
- setHeroAgi(self.handle, agilityBase, true)
1328
- end
1329
- },
1330
- true
1331
- )
1332
1425
  __TS__SetDescriptor(
1333
1426
  Unit.prototype,
1334
1427
  "agilityBonus",
@@ -1346,19 +1439,6 @@ __TS__SetDescriptor(
1346
1439
  end},
1347
1440
  true
1348
1441
  )
1349
- __TS__SetDescriptor(
1350
- Unit.prototype,
1351
- "intelligenceBase",
1352
- {
1353
- get = function(self)
1354
- return getHeroInt(self.handle, false)
1355
- end,
1356
- set = function(self, intelligenceBase)
1357
- setHeroInt(self.handle, intelligenceBase, true)
1358
- end
1359
- },
1360
- true
1361
- )
1362
1442
  __TS__SetDescriptor(
1363
1443
  Unit.prototype,
1364
1444
  "intelligenceBonus",
@@ -1407,17 +1487,17 @@ __TS__SetDescriptor(
1407
1487
  "isTeamGlowVisible",
1408
1488
  {
1409
1489
  get = function(self)
1410
- return not self[106]
1490
+ return not self[107]
1411
1491
  end,
1412
1492
  set = function(self, isTeamGlowVisible)
1413
- showUnitTeamGlow(self.handle, isTeamGlowVisible)
1414
- local ____temp_6
1493
+ BlzShowUnitTeamGlow(self.handle, isTeamGlowVisible)
1494
+ local ____temp_7
1415
1495
  if not isTeamGlowVisible then
1416
- ____temp_6 = true
1496
+ ____temp_7 = true
1417
1497
  else
1418
- ____temp_6 = nil
1498
+ ____temp_7 = nil
1419
1499
  end
1420
- self[106] = ____temp_6
1500
+ self[107] = ____temp_7
1421
1501
  end
1422
1502
  },
1423
1503
  true
@@ -1426,9 +1506,9 @@ __TS__SetDescriptor(
1426
1506
  Unit.prototype,
1427
1507
  "color",
1428
1508
  {set = function(self, color)
1429
- setUnitColor(self.handle, color.handle)
1430
- if self[106] then
1431
- showUnitTeamGlow(self.handle, false)
1509
+ SetUnitColor(self.handle, color.handle)
1510
+ if self[107] then
1511
+ BlzShowUnitTeamGlow(self.handle, false)
1432
1512
  end
1433
1513
  end},
1434
1514
  true
@@ -1451,14 +1531,14 @@ __TS__SetDescriptor(
1451
1531
  "maxHealth",
1452
1532
  {
1453
1533
  get = function(self)
1454
- return BlzGetUnitMaxHP(self.handle) - (self[104] or 0) - (self[105] or 0)
1534
+ return BlzGetUnitMaxHP(self.handle) - (self[105] or 0) - (self[106] or 0)
1455
1535
  end,
1456
1536
  set = function(self, maxHealth)
1457
- if maxHealth < 1 and self[103] ~= nil then
1458
- self[104] = (self[104] or 0) + (1 - maxHealth)
1537
+ if maxHealth < 1 and self[104] ~= nil then
1538
+ self[105] = (self[105] or 0) + (1 - maxHealth)
1459
1539
  maxHealth = 1
1460
1540
  end
1461
- BlzSetUnitMaxHP(self.handle, maxHealth + (self[105] or 0))
1541
+ BlzSetUnitMaxHP(self.handle, maxHealth + (self[106] or 0))
1462
1542
  end
1463
1543
  },
1464
1544
  true
@@ -1500,10 +1580,10 @@ __TS__SetDescriptor(
1500
1580
  "health",
1501
1581
  {
1502
1582
  get = function(self)
1503
- return GetWidgetLife(self.handle) - (self[105] or 0)
1583
+ return GetWidgetLife(self.handle) - (self[106] or 0)
1504
1584
  end,
1505
1585
  set = function(self, health)
1506
- SetWidgetLife(self.handle, health + (self[105] or 0))
1586
+ SetWidgetLife(self.handle, health + (self[106] or 0))
1507
1587
  end
1508
1588
  },
1509
1589
  true
@@ -1579,25 +1659,12 @@ __TS__SetDescriptor(
1579
1659
  },
1580
1660
  true
1581
1661
  )
1582
- __TS__SetDescriptor(
1583
- Unit.prototype,
1584
- "flyHeight",
1585
- {
1586
- get = function(self)
1587
- return getUnitFlyHeight(self.handle)
1588
- end,
1589
- set = function(self, v)
1590
- SetUnitFlyHeight(self.handle, v, 100000)
1591
- end
1592
- },
1593
- true
1594
- )
1595
1662
  __TS__SetDescriptor(
1596
1663
  Unit.prototype,
1597
1664
  "x",
1598
1665
  {
1599
1666
  get = function(self)
1600
- return getUnitX(self.handle)
1667
+ return self[108] or getUnitX(self.handle)
1601
1668
  end,
1602
1669
  set = function(self, v)
1603
1670
  SetUnitX(self.handle, v)
@@ -1610,7 +1677,7 @@ __TS__SetDescriptor(
1610
1677
  "y",
1611
1678
  {
1612
1679
  get = function(self)
1613
- return getUnitY(self.handle)
1680
+ return self[109] or getUnitY(self.handle)
1614
1681
  end,
1615
1682
  set = function(self, v)
1616
1683
  SetUnitY(self.handle, v)
@@ -1696,10 +1763,10 @@ __TS__SetDescriptor(
1696
1763
  "gold",
1697
1764
  {
1698
1765
  get = function(self)
1699
- return getResourceAmount(self.handle)
1766
+ return GetResourceAmount(self.handle)
1700
1767
  end,
1701
1768
  set = function(self, gold)
1702
- setResourceAmount(self.handle, gold)
1769
+ SetResourceAmount(self.handle, gold)
1703
1770
  end
1704
1771
  },
1705
1772
  true
@@ -1715,14 +1782,18 @@ __TS__SetDescriptor(
1715
1782
  local handle = self.handle
1716
1783
  if isPaused and not IsUnitPaused(handle) then
1717
1784
  self[101] = true
1718
- for _ = self[102] or 0, -1 do
1719
- BlzPauseUnitEx(handle, true)
1785
+ if (self[103] or 0) <= 0 then
1786
+ for _ = self[102] or 0, -1 do
1787
+ BlzPauseUnitEx(handle, true)
1788
+ end
1720
1789
  end
1721
1790
  PauseUnit(handle, true)
1722
1791
  elseif not isPaused and IsUnitPaused(handle) then
1723
1792
  PauseUnit(handle, false)
1724
- for _ = self[102] or 0, -1 do
1725
- BlzPauseUnitEx(handle, false)
1793
+ if (self[103] or 0) <= 0 then
1794
+ for _ = self[102] or 0, -1 do
1795
+ BlzPauseUnitEx(handle, false)
1796
+ end
1726
1797
  end
1727
1798
  self[101] = nil
1728
1799
  end
@@ -1780,20 +1851,6 @@ __TS__SetDescriptor(
1780
1851
  },
1781
1852
  true
1782
1853
  )
1783
- __TS__SetDescriptor(
1784
- Unit.prototype,
1785
- "scale",
1786
- {
1787
- get = function(self)
1788
- return getUnitRealField(self.handle, UNIT_RF_SCALING_VALUE)
1789
- end,
1790
- set = function(self, v)
1791
- setUnitScale(self.handle, v, v, v)
1792
- setUnitRealField(self.handle, UNIT_RF_SCALING_VALUE, v)
1793
- end
1794
- },
1795
- true
1796
- )
1797
1854
  __TS__SetDescriptor(
1798
1855
  Unit.prototype,
1799
1856
  "timeScale",
@@ -1827,6 +1884,19 @@ __TS__SetDescriptor(
1827
1884
  end},
1828
1885
  true
1829
1886
  )
1887
+ __TS__SetDescriptor(
1888
+ Unit.prototype,
1889
+ "movementType",
1890
+ {
1891
+ get = function(self)
1892
+ return getUnitIntegerField(self.handle, UNIT_IF_MOVE_TYPE)
1893
+ end,
1894
+ set = function(self, movementType)
1895
+ setUnitIntegerField(self.handle, UNIT_IF_MOVE_TYPE, movementType)
1896
+ end
1897
+ },
1898
+ true
1899
+ )
1830
1900
  __TS__SetDescriptor(
1831
1901
  Unit.prototype,
1832
1902
  "pathing",
@@ -2008,6 +2078,14 @@ __TS__SetDescriptor(
2008
2078
  end},
2009
2079
  true
2010
2080
  )
2081
+ __TS__SetDescriptor(
2082
+ Unit.prototype,
2083
+ "targetAcquiredEvent",
2084
+ {get = function(self)
2085
+ return self:getEvent(EVENT_UNIT_ACQUIRED_TARGET)
2086
+ end},
2087
+ true
2088
+ )
2011
2089
  __TS__SetDescriptor(
2012
2090
  Unit.prototype,
2013
2091
  "onSelect",
@@ -2068,6 +2146,11 @@ __TS__SetDescriptor(
2068
2146
  end},
2069
2147
  true
2070
2148
  )
2149
+ Unit.levelChangedEvent = __TS__New(
2150
+ ____exports.UnitTriggerEvent,
2151
+ EVENT_PLAYER_HERO_LEVEL,
2152
+ function() return ____exports.Unit:of(getTriggerUnit()) end
2153
+ )
2071
2154
  Unit.deathEvent = __TS__New(
2072
2155
  ____exports.UnitTriggerEvent,
2073
2156
  EVENT_PLAYER_UNIT_DEATH,
@@ -2143,25 +2226,25 @@ Unit.onTargetCast = dispatchId(__TS__New(
2143
2226
  InitializingEvent,
2144
2227
  function(event)
2145
2228
  local function listener(unit, id)
2146
- local ____GetSpellTargetUnit_result_9
2229
+ local ____GetSpellTargetUnit_result_10
2147
2230
  if GetSpellTargetUnit() then
2148
- ____GetSpellTargetUnit_result_9 = ____exports.Unit:of(GetSpellTargetUnit())
2231
+ ____GetSpellTargetUnit_result_10 = ____exports.Unit:of(GetSpellTargetUnit())
2149
2232
  else
2150
- local ____GetSpellTargetItem_result_8
2233
+ local ____GetSpellTargetItem_result_9
2151
2234
  if GetSpellTargetItem() then
2152
- ____GetSpellTargetItem_result_8 = Item:of(GetSpellTargetItem())
2235
+ ____GetSpellTargetItem_result_9 = Item:of(GetSpellTargetItem())
2153
2236
  else
2154
- local ____GetSpellTargetDestructable_result_7
2237
+ local ____GetSpellTargetDestructable_result_8
2155
2238
  if GetSpellTargetDestructable() then
2156
- ____GetSpellTargetDestructable_result_7 = Destructable:of(GetSpellTargetDestructable())
2239
+ ____GetSpellTargetDestructable_result_8 = Destructable:of(GetSpellTargetDestructable())
2157
2240
  else
2158
- ____GetSpellTargetDestructable_result_7 = nil
2241
+ ____GetSpellTargetDestructable_result_8 = nil
2159
2242
  end
2160
- ____GetSpellTargetItem_result_8 = ____GetSpellTargetDestructable_result_7
2243
+ ____GetSpellTargetItem_result_9 = ____GetSpellTargetDestructable_result_8
2161
2244
  end
2162
- ____GetSpellTargetUnit_result_9 = ____GetSpellTargetItem_result_8
2245
+ ____GetSpellTargetUnit_result_10 = ____GetSpellTargetItem_result_9
2163
2246
  end
2164
- local target = ____GetSpellTargetUnit_result_9
2247
+ local target = ____GetSpellTargetUnit_result_10
2165
2248
  if target then
2166
2249
  invoke(event, unit, id, target)
2167
2250
  end
@@ -2369,38 +2452,57 @@ Unit.onDamaging = (function()
2369
2452
  if source and source.typeId == dummyUnitId then
2370
2453
  source = nil
2371
2454
  end
2372
- local target = BlzGetEventDamageTarget()
2455
+ local target = ____exports.Unit:of(BlzGetEventDamageTarget())
2456
+ local metadata = damageMetadataByTarget[target]
2457
+ damageMetadataByTarget[target] = nil
2373
2458
  local data = {
2374
2459
  amount = GetEventDamage(),
2375
- attackType = BlzGetEventAttackType(),
2460
+ attackType = nativeToAttackType(BlzGetEventAttackType()),
2376
2461
  damageType = BlzGetEventDamageType(),
2377
2462
  weaponType = BlzGetEventWeaponType(),
2378
- isAttack = BlzGetEventIsAttack()
2463
+ metadata = metadata,
2464
+ isAttack = BlzGetEventIsAttack(),
2465
+ originalAmount = GetEventDamage(),
2466
+ originalMetadata = metadata,
2467
+ preventRetaliation = damagingEventPreventRetaliation
2379
2468
  }
2380
2469
  if data.isAttack and source then
2381
- 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
2382
- if weapon == -1 then
2383
- local targetsAllowed = BlzGetUnitWeaponIntegerField(source.handle, UNIT_WEAPON_IF_ATTACK_TARGETS_ALLOWED, 0)
2384
- weapon = 0
2385
- end
2386
- data.weapon = assert(source.weapons[weapon + 1])
2470
+ data.weapon = source:chooseWeapon(target)
2387
2471
  end
2388
2472
  if not data.isAttack or not source or not source._attackHandlers then
2389
2473
  invoke(
2390
2474
  event,
2391
2475
  source,
2392
- ____exports.Unit:of(target),
2476
+ target,
2393
2477
  setmetatable(
2394
2478
  {},
2395
2479
  {
2396
2480
  __index = data,
2397
2481
  __newindex = function(self, key, value)
2398
- damageSetters[key](value)
2482
+ local damageSetter = damageSetters[key]
2483
+ if damageSetter ~= nil then
2484
+ damageSetter(value)
2485
+ end
2399
2486
  data[key] = value
2400
2487
  end
2401
2488
  }
2402
2489
  )
2403
2490
  )
2491
+ if data[0] and source then
2492
+ local sourceOwner = source.owner.handle
2493
+ data[1] = sourceOwner
2494
+ local targetOwner = target.owner.handle
2495
+ data[2] = targetOwner
2496
+ if not GetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE) then
2497
+ SetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE, true)
2498
+ data[3] = true
2499
+ end
2500
+ if not GetPlayerAlliance(targetOwner, sourceOwner, ALLIANCE_PASSIVE) then
2501
+ SetPlayerAlliance(targetOwner, sourceOwner, ALLIANCE_PASSIVE, true)
2502
+ data[4] = true
2503
+ end
2504
+ end
2505
+ damagingEventByTarget[target] = data
2404
2506
  return
2405
2507
  end
2406
2508
  BlzSetEventDamage(0)
@@ -2408,7 +2510,7 @@ Unit.onDamaging = (function()
2408
2510
  BlzSetEventDamageType(DAMAGE_TYPE_UNKNOWN)
2409
2511
  BlzSetEventWeaponType(WEAPON_TYPE_WHOKNOWS)
2410
2512
  local sourceOwner = source.owner.handle
2411
- local targetOwner = GetOwningPlayer(target)
2513
+ local targetOwner = target.owner.handle
2412
2514
  if not GetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE) then
2413
2515
  SetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE, true)
2414
2516
  Timer:run(function()
@@ -2424,23 +2526,19 @@ Unit.onDamaging = (function()
2424
2526
  for ____, ____value in ipairs(source._attackHandlers) do
2425
2527
  local condition = ____value[1]
2426
2528
  local action = ____value[2]
2427
- if condition(
2428
- source,
2429
- ____exports.Unit:of(target),
2430
- data
2431
- ) then
2529
+ if condition(source, target, data) then
2432
2530
  action(
2433
2531
  source,
2434
- ____exports.Unit:of(target),
2532
+ target,
2435
2533
  setmetatable(
2436
2534
  {fire = function()
2437
2535
  UnitDamageTarget(
2438
2536
  source.handle,
2439
- target,
2537
+ target.handle,
2440
2538
  data.amount,
2441
2539
  true,
2442
2540
  true,
2443
- data.attackType,
2541
+ attackTypeToNative(data.attackType),
2444
2542
  data.damageType,
2445
2543
  data.weaponType
2446
2544
  )
@@ -2467,30 +2565,54 @@ Unit.onDamage = __TS__New(
2467
2565
  if source and source.typeId == dummyUnitId then
2468
2566
  source = nil
2469
2567
  end
2568
+ local target = ____exports.Unit:of(BlzGetEventDamageTarget())
2569
+ local damagingEvent = damagingEventByTarget[target]
2570
+ damagingEventByTarget[target] = nil
2470
2571
  local data = {
2471
2572
  amount = GetEventDamage(),
2472
- attackType = BlzGetEventAttackType(),
2573
+ attackType = nativeToAttackType(BlzGetEventAttackType()),
2473
2574
  damageType = BlzGetEventDamageType(),
2474
2575
  weaponType = BlzGetEventWeaponType(),
2576
+ metadata = damagingEvent and damagingEvent.metadata,
2475
2577
  isAttack = BlzGetEventIsAttack(),
2476
- originalAmount = GetEventDamage(),
2578
+ originalAmount = damagingEvent and damagingEvent.originalAmount or GetEventDamage(),
2579
+ originalMetadata = damagingEvent and damagingEvent.originalMetadata,
2477
2580
  preventDeath = damageEventPreventDeath
2478
2581
  }
2582
+ if damagingEvent then
2583
+ for key, value in pairs(damagingEvent) do
2584
+ if isAttribute(key) then
2585
+ data[key] = value
2586
+ end
2587
+ end
2588
+ local sourceOwner = damagingEvent[1]
2589
+ if sourceOwner then
2590
+ local targetOwner = damagingEvent[2]
2591
+ if damagingEvent[3] then
2592
+ SetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE, false)
2593
+ end
2594
+ if damagingEvent[4] then
2595
+ SetPlayerAlliance(targetOwner, sourceOwner, ALLIANCE_PASSIVE, false)
2596
+ end
2597
+ end
2598
+ end
2479
2599
  local evData = setmetatable(
2480
2600
  {},
2481
2601
  {
2482
2602
  __index = data,
2483
2603
  __newindex = function(self, key, value)
2484
- damageSetters[key](value)
2604
+ local damageSetter = damageSetters[key]
2605
+ if damageSetter ~= nil then
2606
+ damageSetter(value)
2607
+ end
2485
2608
  data[key] = value
2486
2609
  end
2487
2610
  }
2488
2611
  )
2489
- local target = ____exports.Unit:of(BlzGetEventDamageTarget())
2490
2612
  invoke(event, source, target, evData)
2491
2613
  if evData[0] ~= nil and target.health - evData.amount < 0.405 then
2492
2614
  local bonusHealth = math.ceil(evData.amount)
2493
- target[105] = (target[105] or 0) + bonusHealth
2615
+ target[106] = (target[106] or 0) + bonusHealth
2494
2616
  BlzSetUnitMaxHP(
2495
2617
  target.handle,
2496
2618
  BlzGetUnitMaxHP(target.handle) + bonusHealth
@@ -2504,7 +2626,7 @@ Unit.onDamage = __TS__New(
2504
2626
  evData[0],
2505
2627
  table.unpack(evData, 1 + 1, 1 + (evData[1] or 0))
2506
2628
  )
2507
- target[105] = (target[105] or 0) - bonusHealth
2629
+ target[106] = (target[106] or 0) - bonusHealth
2508
2630
  SetWidgetLife(
2509
2631
  target.handle,
2510
2632
  GetWidgetLife(target.handle) - bonusHealth
@@ -2540,10 +2662,14 @@ Unit.itemPickedUpEvent = __TS__New(
2540
2662
  ____exports.UnitTriggerEvent,
2541
2663
  EVENT_PLAYER_UNIT_PICKUP_ITEM,
2542
2664
  function()
2543
- local unit = getTriggerUnit()
2544
- local item = getManipulatedItem()
2545
- if getUnitTypeId(unit) ~= dummyUnitId and not (ignoreEventsItems[item] ~= nil) then
2546
- return ____exports.Unit:of(unit), Item:of(item)
2665
+ local unitHandle = getTriggerUnit()
2666
+ local itemHandle = getManipulatedItem()
2667
+ if getUnitTypeId(unitHandle) ~= dummyUnitId and not (ignoreEventsItems[itemHandle] ~= nil) then
2668
+ local unit = ____exports.Unit:of(unitHandle)
2669
+ local item = Item:of(itemHandle)
2670
+ if item.owner ~= unit then
2671
+ return unit, item
2672
+ end
2547
2673
  end
2548
2674
  return IgnoreEvent
2549
2675
  end
@@ -2563,7 +2689,22 @@ Unit.itemUsedEvent = __TS__New(
2563
2689
  Unit.itemStackedEvent = __TS__New(
2564
2690
  ____exports.UnitTriggerEvent,
2565
2691
  EVENT_PLAYER_UNIT_STACK_ITEM,
2566
- function() return ____exports.Unit:of(getTriggerUnit()), Item:of(getManipulatedItem()) end
2692
+ function() return ____exports.Unit:of(getTriggerUnit()), Item:of(BlzGetStackingItemTarget()), Item:of(BlzGetStackingItemSource()) end
2693
+ )
2694
+ __TS__ObjectDefineProperty(
2695
+ Unit,
2696
+ "itemChargesChangedEvent",
2697
+ {get = function(self)
2698
+ local event = __TS__New(Event)
2699
+ Item.chargesChangedEvent:addListener(function(item)
2700
+ local unit = item.owner
2701
+ if unit ~= nil then
2702
+ invoke(event, unit, item)
2703
+ end
2704
+ end)
2705
+ rawset(self, "itemChargesChangedEvent", event)
2706
+ return event
2707
+ end}
2567
2708
  )
2568
2709
  __TS__ObjectDefineProperty(
2569
2710
  Unit,
@@ -2635,6 +2776,10 @@ __TS__ObjectDefineProperty(
2635
2776
  rawset(self, "destroyEvent", destroyEvent)
2636
2777
  return destroyEvent
2637
2778
  end}
2779
+ )
2780
+ Unit.synchronize = synchronizer(
2781
+ function(unit) return unit.syncId end,
2782
+ function(syncId) return unitBySyncId[syncId] end
2638
2783
  );
2639
2784
  (function(self)
2640
2785
  local leaveAbilityIds = postcompile(function()