warscript 0.0.1-dev.9cbb1ff → 0.0.1-dev.9e6f20e

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 (184) hide show
  1. package/attributes.d.ts +6 -0
  2. package/attributes.lua +17 -1
  3. package/core/types/frame.d.ts +1 -0
  4. package/core/types/frame.lua +136 -58
  5. package/core/types/handle.lua +6 -9
  6. package/core/types/item.d.ts +1 -0
  7. package/core/types/item.lua +1 -0
  8. package/core/types/player.d.ts +17 -1
  9. package/core/types/player.lua +70 -24
  10. package/core/types/playerCamera.d.ts +2 -0
  11. package/core/types/playerCamera.lua +123 -5
  12. package/core/types/sound.lua +1 -1
  13. package/core/types/tileCell.d.ts +11 -1
  14. package/core/types/tileCell.lua +97 -0
  15. package/core/types/timer.d.ts +3 -1
  16. package/core/types/timer.lua +27 -2
  17. package/decl/native.d.ts +846 -790
  18. package/destroyable.d.ts +1 -0
  19. package/destroyable.lua +9 -0
  20. package/engine/behavior.d.ts +14 -1
  21. package/engine/behavior.lua +230 -70
  22. package/engine/behaviour/ability/apply-buff.lua +5 -5
  23. package/engine/behaviour/ability/damage.d.ts +9 -3
  24. package/engine/behaviour/ability/damage.lua +31 -37
  25. package/engine/behaviour/ability/emulate-impact.d.ts +1 -1
  26. package/engine/behaviour/ability/emulate-impact.lua +16 -7
  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 +11 -6
  32. package/engine/behaviour/ability.lua +38 -17
  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 +39 -3
  36. package/engine/behaviour/unit.lua +269 -6
  37. package/engine/buff.d.ts +67 -22
  38. package/engine/buff.lua +371 -182
  39. package/engine/internal/ability.d.ts +7 -1
  40. package/engine/internal/ability.lua +64 -24
  41. package/engine/internal/item/ability.lua +63 -11
  42. package/engine/internal/item/fields.d.ts +12 -0
  43. package/engine/internal/item/fields.lua +33 -0
  44. package/engine/internal/item+owner.lua +12 -6
  45. package/engine/internal/item.d.ts +16 -16
  46. package/engine/internal/item.lua +152 -69
  47. package/engine/internal/mechanics/cast-ability.lua +6 -3
  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/armor-bonus.d.ts +2 -0
  56. package/engine/internal/object-data/attribute-bonus.lua +2 -2
  57. package/engine/internal/object-data/health-bonus.d.ts +2 -0
  58. package/engine/internal/object-data/health-bonus.lua +16 -0
  59. package/engine/internal/object-data/mana-bonus.d.ts +2 -0
  60. package/engine/internal/object-data/mana-bonus.lua +16 -0
  61. package/engine/internal/object-data/mana-regeneration-rate-increase-factor.d.ts +2 -0
  62. package/engine/internal/object-data/mana-regeneration-rate-increase-factor.lua +16 -0
  63. package/engine/internal/unit/ability.d.ts +35 -0
  64. package/engine/internal/unit/ability.lua +113 -12
  65. package/engine/internal/unit/allowed-targets.d.ts +1 -1
  66. package/engine/internal/unit/allowed-targets.lua +9 -1
  67. package/engine/internal/unit/attributes.d.ts +17 -0
  68. package/engine/internal/unit/attributes.lua +46 -0
  69. package/engine/internal/unit/bonus.d.ts +6 -0
  70. package/engine/internal/unit/bonus.lua +33 -3
  71. package/engine/internal/unit/buff.d.ts +2 -2
  72. package/engine/internal/unit/buff.lua +32 -17
  73. package/engine/internal/unit/fly-height.d.ts +7 -0
  74. package/engine/internal/unit/fly-height.lua +20 -0
  75. package/engine/internal/unit/interrupts.d.ts +12 -0
  76. package/engine/internal/unit/interrupts.lua +28 -0
  77. package/engine/internal/unit/main-selected.lua +12 -27
  78. package/engine/internal/unit/order.d.ts +20 -0
  79. package/engine/internal/unit/order.lua +136 -0
  80. package/engine/internal/unit/pseudo-passive-abilities.d.ts +2 -0
  81. package/engine/internal/unit/pseudo-passive-abilities.lua +11 -0
  82. package/engine/internal/unit/range-event.d.ts +12 -0
  83. package/engine/internal/unit/range-event.lua +90 -0
  84. package/engine/internal/unit/scale.d.ts +7 -0
  85. package/engine/internal/unit/scale.lua +20 -0
  86. package/engine/internal/unit+ability.lua +10 -1
  87. package/engine/internal/unit+bonus.lua +3 -3
  88. package/engine/internal/unit+damage.d.ts +2 -11
  89. package/engine/internal/unit+damage.lua +10 -14
  90. package/engine/internal/unit+spellSteal.lua +1 -2
  91. package/engine/internal/unit-missile-launch.lua +52 -14
  92. package/engine/internal/unit.d.ts +34 -27
  93. package/engine/internal/unit.lua +365 -273
  94. package/engine/local-client.d.ts +7 -0
  95. package/engine/local-client.lua +86 -1
  96. package/engine/object-data/auxiliary/armor-type.d.ts +11 -0
  97. package/engine/object-data/auxiliary/armor-type.lua +46 -0
  98. package/engine/object-data/auxiliary/attack-type.d.ts +7 -8
  99. package/engine/object-data/auxiliary/attack-type.lua +42 -0
  100. package/engine/object-data/auxiliary/health-regeneration-type.d.ts +8 -0
  101. package/engine/object-data/auxiliary/health-regeneration-type.lua +2 -0
  102. package/engine/object-data/auxiliary/unit-attribute.lua +1 -1
  103. package/engine/object-data/entry/ability-type/{armor-increase.d.ts → armor-bonus.d.ts} +3 -3
  104. package/engine/object-data/entry/ability-type/{armor-increase.lua → armor-bonus.lua} +9 -9
  105. package/engine/object-data/entry/ability-type/blank-configurable.d.ts +3 -0
  106. package/engine/object-data/entry/ability-type/blank-configurable.lua +30 -0
  107. package/engine/object-data/entry/ability-type/health-bonus.d.ts +8 -0
  108. package/engine/object-data/entry/ability-type/health-bonus.lua +26 -0
  109. package/engine/object-data/entry/ability-type/mana-bonus.d.ts +8 -0
  110. package/engine/object-data/entry/ability-type/mana-bonus.lua +26 -0
  111. package/engine/object-data/entry/ability-type/mana-regeneration.d.ts +8 -0
  112. package/engine/object-data/entry/ability-type/mana-regeneration.lua +26 -0
  113. package/engine/object-data/entry/ability-type/permanent-invisibility.d.ts +8 -0
  114. package/engine/object-data/entry/ability-type/permanent-invisibility.lua +26 -0
  115. package/engine/object-data/entry/ability-type/reincarnation.d.ts +8 -0
  116. package/engine/object-data/entry/ability-type/reincarnation.lua +26 -0
  117. package/engine/object-data/entry/ability-type.d.ts +2 -0
  118. package/engine/object-data/entry/ability-type.lua +89 -8
  119. package/engine/object-data/entry/buff-type/applicable.lua +113 -109
  120. package/engine/object-data/entry/destructible-type.d.ts +27 -1
  121. package/engine/object-data/entry/destructible-type.lua +155 -0
  122. package/engine/object-data/entry/unit-type.d.ts +17 -4
  123. package/engine/object-data/entry/unit-type.lua +189 -83
  124. package/engine/object-field/ability.d.ts +4 -4
  125. package/engine/object-field/ability.lua +9 -8
  126. package/engine/object-field/item.d.ts +22 -0
  127. package/engine/object-field/item.lua +118 -0
  128. package/engine/object-field/unit.d.ts +72 -3
  129. package/engine/object-field/unit.lua +268 -7
  130. package/engine/object-field.d.ts +18 -7
  131. package/engine/object-field.lua +294 -135
  132. package/engine/random.d.ts +10 -0
  133. package/engine/random.lua +21 -0
  134. package/engine/standard/fields/ability.d.ts +2 -2
  135. package/engine/standard/fields/ability.lua +2 -2
  136. package/engine/standard/fields/item.d.ts +4 -0
  137. package/engine/standard/fields/item.lua +6 -0
  138. package/engine/standard/fields/unit.d.ts +12 -0
  139. package/engine/standard/fields/unit.lua +20 -0
  140. package/engine/synchronization.d.ts +11 -0
  141. package/engine/synchronization.lua +77 -0
  142. package/engine/text-tag.d.ts +36 -2
  143. package/engine/text-tag.lua +250 -10
  144. package/engine/unit.d.ts +6 -0
  145. package/engine/unit.lua +6 -0
  146. package/event.d.ts +1 -1
  147. package/lualib_bundle.lua +1 -1
  148. package/math.d.ts +2 -0
  149. package/math.lua +14 -0
  150. package/net/socket.lua +1 -1
  151. package/network.lua +25 -1
  152. package/objutil/buff.lua +11 -10
  153. package/objutil/object.lua +1 -1
  154. package/operation.d.ts +8 -1
  155. package/operation.lua +38 -18
  156. package/package.json +5 -5
  157. package/patch-lua.lua +15 -0
  158. package/patch-lualib.lua +1 -1
  159. package/utility/arrays.d.ts +2 -0
  160. package/utility/arrays.lua +11 -0
  161. package/utility/callback-array.d.ts +17 -0
  162. package/utility/callback-array.lua +61 -0
  163. package/utility/functions.d.ts +8 -0
  164. package/utility/functions.lua +13 -0
  165. package/utility/linked-map.d.ts +35 -0
  166. package/utility/linked-map.lua +107 -0
  167. package/utility/linked-set.d.ts +4 -1
  168. package/utility/linked-set.lua +46 -1
  169. package/utility/lua-maps.d.ts +12 -2
  170. package/utility/lua-maps.lua +37 -2
  171. package/utility/lua-sets.d.ts +1 -0
  172. package/utility/lua-sets.lua +4 -0
  173. package/utility/random.d.ts +102 -0
  174. package/utility/random.lua +273 -0
  175. package/utility/records.lua +20 -1
  176. package/utility/types.d.ts +3 -0
  177. package/utility/unordered-map.d.ts +27 -0
  178. package/utility/unordered-map.lua +99 -0
  179. package/core/types/order.d.ts +0 -25
  180. package/core/types/order.lua +0 -55
  181. /package/engine/internal/{object-data/armor-increase.d.ts → misc/damage-metadata-by-target.d.ts} +0 -0
  182. /package/engine/internal/object-data/{armor-increase.lua → armor-bonus.lua} +0 -0
  183. /package/engine/object-data/entry/ability-type/{attribute-increase.d.ts → attribute-bonus.d.ts} +0 -0
  184. /package/engine/object-data/entry/ability-type/{attribute-increase.lua → attribute-bonus.lua} +0 -0
@@ -53,35 +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 resetUnitAnimation = ResetUnitAnimation
62
- local queueUnitAnimation = QueueUnitAnimation
63
73
  local getUnitIntegerField = BlzGetUnitIntegerField
64
74
  local getUnitRealField = BlzGetUnitRealField
65
75
  local getHeroStr = GetHeroStr
66
76
  local getHeroAgi = GetHeroAgi
67
77
  local getHeroInt = GetHeroInt
68
- local setHeroStr = SetHeroStr
69
- local setHeroAgi = SetHeroAgi
70
- local setHeroInt = SetHeroInt
71
78
  local getUnitBooleanField = BlzGetUnitBooleanField
72
79
  local getUnitStringField = BlzGetUnitStringField
73
80
  local setUnitIntegerField = BlzSetUnitIntegerField
74
81
  local setUnitRealField = BlzSetUnitRealField
75
82
  local setUnitBooleanField = BlzSetUnitBooleanField
76
83
  local setUnitStringField = BlzSetUnitStringField
77
- local setUnitScale = SetUnitScale
78
84
  local setUnitPosition = SetUnitPosition
79
85
  local setUnitTimeScale = SetUnitTimeScale
80
86
  local getHandleId = GetHandleId
81
87
  local getUnitCurrentOrder = GetUnitCurrentOrder
82
88
  local createUnit = CreateUnit
83
89
  local killUnit = KillUnit
84
- local setUnitExploded = SetUnitExploded
85
90
  local removeUnit = RemoveUnit
86
91
  local getUnitTypeId = GetUnitTypeId
87
92
  local isHeroUnitId = IsHeroUnitId
@@ -97,15 +102,12 @@ local getSpellTargetItem = GetSpellTargetItem
97
102
  local getSpellTargetDestructable = GetSpellTargetDestructable
98
103
  local isUnitInRangeXY = IsUnitInRangeXY
99
104
  local isUnitInRange = IsUnitInRange
100
- local setResourceAmount = SetResourceAmount
101
- local getResourceAmount = GetResourceAmount
102
105
  local getUnitWeaponRealField = BlzGetUnitWeaponRealField
103
106
  local setUnitWeaponRealField = BlzSetUnitWeaponRealField
104
107
  local getUnitWeaponStringField = BlzGetUnitWeaponStringField
105
108
  local setUnitWeaponStringField = BlzSetUnitWeaponStringField
106
109
  local getUnitAbilityLevel = GetUnitAbilityLevel
107
110
  local unitDisableAbility = BlzUnitDisableAbility
108
- local unitInterruptAttack = BlzUnitInterruptAttack
109
111
  local isUnitInvisible = IsUnitInvisible
110
112
  local isUnitVisible = IsUnitVisible
111
113
  local getUnitX = GetUnitX
@@ -122,15 +124,9 @@ local getOrderedUnit = GetOrderedUnit
122
124
  local getIssuedOrderId = GetIssuedOrderId
123
125
  local isUnitInvulnerable = BlzIsUnitInvulnerable
124
126
  local unitAlive = UnitAlive
125
- local unitAddType = UnitAddType
126
- local unitRemoveType = UnitRemoveType
127
- local isUnitIllusion = IsUnitIllusion
128
- local isUnitType = IsUnitType
129
127
  local isUnitAlly = IsUnitAlly
130
128
  local isUnitEnemy = IsUnitEnemy
131
129
  local getOwningPlayer = GetOwningPlayer
132
- local setUnitColor = SetUnitColor
133
- local showUnitTeamGlow = BlzShowUnitTeamGlow
134
130
  ____exports.UnitClassification = {}
135
131
  local UnitClassification = ____exports.UnitClassification
136
132
  do
@@ -140,6 +136,7 @@ do
140
136
  UnitClassification.GROUND = UNIT_TYPE_GROUND
141
137
  UnitClassification.SUMMONED = UNIT_TYPE_SUMMONED
142
138
  UnitClassification.MECHANICAL = UNIT_TYPE_MECHANICAL
139
+ UnitClassification.WORKER = UNIT_TYPE_PEON
143
140
  UnitClassification.ANCIENT = UNIT_TYPE_ANCIENT
144
141
  UnitClassification.SUICIDAL = UNIT_TYPE_SAPPER
145
142
  UnitClassification.TAUREN = UNIT_TYPE_TAUREN
@@ -347,6 +344,9 @@ local function dispatchAbility(event)
347
344
  }
348
345
  )
349
346
  end
347
+ local function damagingEventPreventRetaliation(self)
348
+ self[0] = true
349
+ end
350
350
  local function damageEventPreventDeath(self, callback, ...)
351
351
  if self[0] ~= nil then
352
352
  return
@@ -358,7 +358,14 @@ local function damageEventPreventDeath(self, callback, ...)
358
358
  rawset(self, 1 + i, (select(i, ...)))
359
359
  end
360
360
  end
361
- 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
+ }
362
369
  local jlimitopByOperator = {
363
370
  [0] = LESS_THAN_OR_EQUAL,
364
371
  [1] = LESS_THAN_OR_EQUAL,
@@ -376,15 +383,27 @@ local modifiers = {
376
383
  end,
377
384
  armor = function(unit, value)
378
385
  if UnitAddAbility(unit, armorBonusAbilityId) then
379
- assert(UnitMakeAbilityPermanent(unit, true, armorBonusAbilityId))
386
+ assert(
387
+ UnitMakeAbilityPermanent(unit, true, armorBonusAbilityId),
388
+ "armor bonus ability must be made permanent",
389
+ unit
390
+ )
380
391
  end
381
- local ability = assert(BlzGetUnitAbility(unit, armorBonusAbilityId))
382
- assert(BlzSetAbilityRealLevelField(
383
- ability,
384
- armorBonusField,
385
- 0,
386
- BlzGetAbilityRealLevelField(ability, armorBonusField, 0) + value
387
- ))
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
+ )
388
407
  end
389
408
  }
390
409
  local getters = {
@@ -402,6 +421,19 @@ function UnitWeapon.prototype.____constructor(self, unit, index)
402
421
  self.unit = unit
403
422
  self.index = index
404
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
+ )
405
437
  __TS__SetDescriptor(
406
438
  UnitWeapon.prototype,
407
439
  "cooldown",
@@ -436,6 +468,19 @@ __TS__SetDescriptor(
436
468
  },
437
469
  true
438
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
+ )
439
484
  __TS__SetDescriptor(
440
485
  UnitWeapon.prototype,
441
486
  "damageBase",
@@ -612,26 +657,30 @@ local fieldSetters = {
612
657
  }
613
658
  local dummies = {}
614
659
  for ____, player in ipairs(Player.all) do
615
- local dummy = assert(createUnit(
616
- player.handle,
617
- dummyUnitId,
618
- 0,
619
- 0,
620
- 270
621
- ))
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
+ )
622
671
  ShowUnit(dummy, false)
623
672
  dummies[player] = dummy
624
673
  end
625
674
  local function delayHealthChecksCallback(unit)
626
- local counter = (unit[103] or 0) - 1
675
+ local counter = (unit[104] or 0) - 1
627
676
  if counter ~= 0 then
628
- unit[103] = counter
677
+ unit[104] = counter
629
678
  return
630
679
  end
631
- unit[103] = nil
632
- local healthBonus = unit[104]
680
+ unit[104] = nil
681
+ local healthBonus = unit[105]
633
682
  if healthBonus ~= nil then
634
- unit[104] = nil
683
+ unit[105] = nil
635
684
  local handle = unit.handle
636
685
  BlzSetUnitMaxHP(
637
686
  handle,
@@ -640,52 +689,78 @@ local function delayHealthChecksCallback(unit)
640
689
  end
641
690
  end
642
691
  local nextSyncId = 1
643
- 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
644
703
  ____exports.Unit = __TS__Class()
645
704
  local Unit = ____exports.Unit
646
705
  Unit.name = "Unit"
647
706
  __TS__ClassExtends(Unit, Handle)
648
707
  function Unit.prototype.____constructor(self, handle)
649
708
  Handle.prototype.____constructor(self, handle)
650
- local ____nextSyncId_0 = nextSyncId
651
- nextSyncId = ____nextSyncId_0 + 1
652
- self.syncId = ____nextSyncId_0
709
+ local ____nextSyncId_1 = nextSyncId
710
+ nextSyncId = ____nextSyncId_1 + 1
711
+ self.syncId = ____nextSyncId_1
653
712
  self._owner = Player:of(getOwningPlayer(handle))
654
- assert(unitAddAbility(handle, leaveDetectAbilityId) and UnitMakeAbilityPermanent(handle, true, leaveDetectAbilityId))
655
- 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
+ )
656
723
  if unitAddAbility(
657
724
  handle,
658
725
  fourCC("Amrf")
659
726
  ) then
660
- assert(unitRemoveAbility(
661
- handle,
662
- fourCC("Amrf")
663
- ))
727
+ assert(
728
+ unitRemoveAbility(
729
+ handle,
730
+ fourCC("Amrf")
731
+ ),
732
+ "fly ability must be removed after addition",
733
+ self
734
+ )
664
735
  end
665
736
  unitBySyncId[self.syncId] = self
666
737
  local ____ = self.abilities
667
738
  end
668
- function Unit.prototype.getEvent(self, event, collector)
669
- self.events = self.events or ({})
670
- local eventId = GetHandleId(event)
671
- if not self.events[eventId] then
672
- 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(
673
745
  TriggerEvent,
674
746
  function(trigger)
675
- TriggerRegisterUnitEvent(trigger, self.handle, event)
747
+ TriggerRegisterUnitEvent(trigger, self.handle, jevent)
676
748
  end,
677
749
  collector or (function() return {} end)
678
750
  )
751
+ self.events:put(eventId, event)
679
752
  end
680
- return self.events[eventId]
753
+ return event
754
+ end
755
+ function Unit.prototype.saveData(self)
756
+ local handle = self.handle
757
+ self[108] = self[108] or getUnitX(handle)
758
+ self[109] = self[109] or getUnitY(handle)
759
+ self._owner = self._owner or Player:of(getOwningPlayer(handle))
681
760
  end
682
761
  function Unit.prototype.onDestroy(self)
683
762
  local handle = self.handle
684
- self[107] = getUnitX(handle)
685
- self[108] = getUnitY(handle)
686
- if not self._owner then
687
- self._owner = Player:of(getOwningPlayer(handle))
688
- end
763
+ self:saveData()
689
764
  local abilities = self.abilities
690
765
  for ____, ability in ipairs(abilities) do
691
766
  ability:destroy()
@@ -721,7 +796,11 @@ function Unit.prototype.addAttackHandler(self, condition, action)
721
796
  self._attackHandlers = handlers
722
797
  if #handlers == 1 then
723
798
  local handle = self.handle
724
- assert(unitAddAbility(handle, attackHandlerAbilityId) and UnitMakeAbilityPermanent(handle, true, attackHandlerAbilityId))
799
+ assert(
800
+ unitAddAbility(handle, attackHandlerAbilityId) and UnitMakeAbilityPermanent(handle, true, attackHandlerAbilityId),
801
+ "attack handler ability must be added",
802
+ self
803
+ )
725
804
  end
726
805
  return handler
727
806
  end
@@ -750,17 +829,17 @@ function Unit.prototype.addModifier(self, property, modifier)
750
829
  end}
751
830
  end
752
831
  function Unit.prototype.hasCombatClassification(self, combatClassification)
753
- local ____combatClassification_1 = combatClassification
754
- return getUnitIntegerField(self.handle, UNIT_IF_TARGETED_AS) & ____combatClassification_1 == ____combatClassification_1
832
+ local ____combatClassification_2 = combatClassification
833
+ return getUnitIntegerField(self.handle, UNIT_IF_TARGETED_AS) & ____combatClassification_2 == ____combatClassification_2
755
834
  end
756
835
  function Unit.prototype.addClassification(self, classification)
757
- return unitAddType(self.handle, classification)
836
+ return UnitAddType(self.handle, classification)
758
837
  end
759
838
  function Unit.prototype.removeClassification(self, classification)
760
- return unitRemoveType(self.handle, classification)
839
+ return UnitRemoveType(self.handle, classification)
761
840
  end
762
841
  function Unit.prototype.hasClassification(self, classification)
763
- return isUnitType(self.handle, classification)
842
+ return IsUnitType(self.handle, classification)
764
843
  end
765
844
  function Unit.prototype.isVisibleTo(self, player)
766
845
  return isUnitVisible(self.handle, player.handle)
@@ -769,13 +848,13 @@ function Unit.prototype.isInvisibleTo(self, player)
769
848
  return isUnitInvisible(self.handle, player.handle)
770
849
  end
771
850
  function Unit.prototype.isInRangeOf(self, x, y, range)
772
- local ____temp_2
851
+ local ____temp_3
773
852
  if type(x) == "number" then
774
- ____temp_2 = isUnitInRangeXY(self.handle, x, y, range)
853
+ ____temp_3 = isUnitInRangeXY(self.handle, x, y, range)
775
854
  else
776
- ____temp_2 = isUnitInRange(self.handle, x.handle, y)
855
+ ____temp_3 = isUnitInRange(self.handle, x.handle, y)
777
856
  end
778
- return ____temp_2
857
+ return ____temp_3
779
858
  end
780
859
  function Unit.prototype.isAllyOf(self, unit)
781
860
  return isUnitAlly(
@@ -793,19 +872,30 @@ function Unit.prototype.playAnimation(self, animation, rarity)
793
872
  if type(animation) == "number" then
794
873
  setUnitAnimationByIndex(self.handle, animation)
795
874
  elseif rarity then
796
- setUnitAnimationWithRarity(self.handle, animation, rarity)
875
+ SetUnitAnimationWithRarity(self.handle, animation, rarity)
797
876
  else
798
877
  setUnitAnimation(self.handle, animation)
799
878
  end
800
879
  end
801
880
  function Unit.prototype.resetAnimation(self)
802
- resetUnitAnimation(self.handle)
881
+ ResetUnitAnimation(self.handle)
803
882
  end
804
883
  function Unit.prototype.queueAnimation(self, animation)
805
- queueUnitAnimation(self.handle, animation)
884
+ QueueUnitAnimation(self.handle, animation)
885
+ end
886
+ function Unit.prototype.chooseWeapon(self, target)
887
+ local firstWeapon = self.firstWeapon
888
+ if firstWeapon.isEnabled and target:isAllowedTarget(self, firstWeapon.allowedTargetCombatClassifications) then
889
+ return firstWeapon
890
+ end
891
+ local secondWeapon = self.secondWeapon
892
+ if secondWeapon.isEnabled and target:isAllowedTarget(target, secondWeapon.allowedTargetCombatClassifications) then
893
+ return secondWeapon
894
+ end
895
+ return nil
806
896
  end
807
897
  function Unit.prototype.delayHealthChecks(self)
808
- self[103] = (self[103] or 0) + 1
898
+ self[104] = (self[104] or 0) + 1
809
899
  Timer:run(delayHealthChecksCallback, self)
810
900
  end
811
901
  function Unit.prototype.setPosition(self, x, y)
@@ -815,21 +905,21 @@ function Unit.prototype.isSelected(self, player)
815
905
  return IsUnitSelected(self.handle, player.handle)
816
906
  end
817
907
  function Unit.prototype.explode(self)
818
- setUnitExploded(self.handle, true)
908
+ SetUnitExploded(self.handle, true)
819
909
  killUnit(self.handle)
820
910
  end
821
911
  function Unit.prototype.kill(self)
822
912
  killUnit(self.handle)
823
913
  end
824
914
  function Unit.prototype.revive(self, x, y, doEffect)
825
- local ____ReviveHero_5 = ReviveHero
826
- local ____array_4 = __TS__SparseArrayNew(self.handle, x, y)
827
- local ____doEffect_3 = doEffect
828
- if ____doEffect_3 == nil then
829
- ____doEffect_3 = false
915
+ local ____ReviveHero_6 = ReviveHero
916
+ local ____array_5 = __TS__SparseArrayNew(self.handle, x, y)
917
+ local ____doEffect_4 = doEffect
918
+ if ____doEffect_4 == nil then
919
+ ____doEffect_4 = false
830
920
  end
831
- __TS__SparseArrayPush(____array_4, ____doEffect_3)
832
- ____ReviveHero_5(__TS__SparseArraySpread(____array_4))
921
+ __TS__SparseArrayPush(____array_5, ____doEffect_4)
922
+ ____ReviveHero_6(__TS__SparseArraySpread(____array_5))
833
923
  end
834
924
  function Unit.prototype.healTarget(self, target, amount)
835
925
  if __TS__InstanceOf(target, ____exports.Unit) and target:hasAbility(fourCC("BIhm")) then
@@ -872,17 +962,16 @@ function Unit.prototype.itemInSlot(self, slot)
872
962
  return Item:of(unitItemInSlot(self.handle, slot))
873
963
  end
874
964
  function Unit.prototype.addAbility(self, abilityId)
875
- if unitAddAbility(self.handle, abilityId) then
876
- local ability = UnitAbility:of(
877
- checkNotNull(getUnitAbility(self.handle, abilityId)),
878
- abilityId,
879
- self
880
- )
965
+ local ability = UnitAbility:of(
966
+ doUnitAbilityAction(self.handle, abilityId, addAbility, abilityId),
967
+ abilityId,
968
+ self
969
+ )
970
+ if ability ~= nil then
881
971
  local abilities = self.abilities
882
972
  abilities[#abilities + 1] = ability
883
- return ability
884
973
  end
885
- return nil
974
+ return ability
886
975
  end
887
976
  function Unit.prototype.makeAbilityPermanent(self, abilityId, permanent)
888
977
  return UnitMakeAbilityPermanent(self.handle, permanent, abilityId)
@@ -896,31 +985,21 @@ end
896
985
  function Unit.prototype.hasAbility(self, abilityId)
897
986
  return getUnitAbilityLevel(self.handle, abilityId) > 0
898
987
  end
899
- function Unit.prototype.getAbilityById(self, abilityId)
900
- local handle = self.handle
901
- if unitAddAbility(handle, abilityId) then
902
- assert(unitRemoveAbility(handle, abilityId))
903
- return nil
904
- end
905
- return UnitAbility:of(
906
- getUnitAbility(self.handle, abilityId),
907
- abilityId,
908
- self
909
- )
988
+ function Unit.prototype.getAbility(self, abilityId)
989
+ local ability = doUnitAbilityAction(self.handle, abilityId, getUnitAbility, abilityId)
990
+ return UnitAbility:of(ability, abilityId, self)
910
991
  end
911
- function Unit.prototype.removeAbility(self, abilityId)
912
- if unitRemoveAbility(self.handle, abilityId) then
913
- local abilities = self.abilities
914
- for i = 1, #abilities do
915
- if abilities[i].typeId == abilityId then
916
- abilities[i]:destroy()
917
- tremove(abilities, i)
918
- return true
919
- end
992
+ function Unit.prototype.removeAbility(self, abilityTypeId)
993
+ local abilities = self.abilities
994
+ for i = 1, #abilities do
995
+ if abilities[i].typeId == abilityTypeId then
996
+ local ability = abilities[i]
997
+ tremove(abilities, i)
998
+ ability:destroy()
999
+ return true
920
1000
  end
921
- return true
922
1001
  end
923
- return false
1002
+ return doUnitAbilityAction(self.handle, abilityTypeId, unitRemoveAbility, abilityTypeId)
924
1003
  end
925
1004
  function Unit.prototype.hideAbility(self, abilityId, flag)
926
1005
  BlzUnitHideAbility(self.handle, abilityId, flag)
@@ -934,9 +1013,6 @@ end
934
1013
  function Unit.prototype.endAbilityCooldown(self, abilityId)
935
1014
  BlzEndUnitAbilityCooldown(self.handle, abilityId)
936
1015
  end
937
- function Unit.prototype.interruptAttack(self)
938
- unitInterruptAttack(self.handle)
939
- end
940
1016
  function Unit.prototype.interruptCast(self, abilityId)
941
1017
  local handle = self.handle
942
1018
  unitDisableAbility(handle, abilityId, true, false)
@@ -1007,18 +1083,44 @@ function Unit.prototype.unpauseEx(self)
1007
1083
  end
1008
1084
  function Unit.prototype.incrementStunCounter(self)
1009
1085
  local stunCounter = self[102] or 0
1010
- if not self[101] or stunCounter >= 0 then
1086
+ if not self[101] and (self[103] or 0) <= 0 or stunCounter >= 0 then
1011
1087
  BlzPauseUnitEx(self.handle, true)
1012
1088
  end
1013
1089
  self[102] = stunCounter + 1
1014
1090
  end
1015
1091
  function Unit.prototype.decrementStunCounter(self)
1016
1092
  local stunCounter = self[102] or 0
1017
- if not self[101] or stunCounter >= 1 then
1093
+ if not self[101] and (self[103] or 0) <= 0 or stunCounter >= 1 then
1018
1094
  BlzPauseUnitEx(self.handle, false)
1019
1095
  end
1020
1096
  self[102] = stunCounter - 1
1021
1097
  end
1098
+ function Unit.prototype.incrementForceStunCounter(self)
1099
+ local forceStunCounter = self[103] or 0
1100
+ if forceStunCounter == 0 then
1101
+ local handle = self.handle
1102
+ if not self[101] then
1103
+ for _ = self[102] or 0, -1 do
1104
+ BlzPauseUnitEx(handle, true)
1105
+ end
1106
+ end
1107
+ BlzPauseUnitEx(handle, true)
1108
+ end
1109
+ self[103] = forceStunCounter + 1
1110
+ end
1111
+ function Unit.prototype.decrementForceStunCounter(self)
1112
+ local forceStunCounter = self[103] or 0
1113
+ if forceStunCounter == 1 then
1114
+ local handle = self.handle
1115
+ if not self[101] then
1116
+ for _ = self[102] or 0, -1 do
1117
+ BlzPauseUnitEx(handle, false)
1118
+ end
1119
+ end
1120
+ BlzPauseUnitEx(handle, false)
1121
+ end
1122
+ self[103] = forceStunCounter - 1
1123
+ end
1022
1124
  function Unit.create(self, owner, id, x, y, facing, skinId)
1023
1125
  local handle = skinId and BlzCreateUnitWithSkin(
1024
1126
  owner.handle,
@@ -1207,7 +1309,7 @@ __TS__SetDescriptor(
1207
1309
  Unit.prototype,
1208
1310
  "isIllusion",
1209
1311
  {get = function(self)
1210
- return isUnitIllusion(self.handle)
1312
+ return IsUnitIllusion(self.handle)
1211
1313
  end},
1212
1314
  true
1213
1315
  )
@@ -1305,19 +1407,6 @@ __TS__SetDescriptor(
1305
1407
  },
1306
1408
  true
1307
1409
  )
1308
- __TS__SetDescriptor(
1309
- Unit.prototype,
1310
- "strengthBase",
1311
- {
1312
- get = function(self)
1313
- return getHeroStr(self.handle, false)
1314
- end,
1315
- set = function(self, strengthBase)
1316
- setHeroStr(self.handle, strengthBase, true)
1317
- end
1318
- },
1319
- true
1320
- )
1321
1410
  __TS__SetDescriptor(
1322
1411
  Unit.prototype,
1323
1412
  "strengthBonus",
@@ -1335,19 +1424,6 @@ __TS__SetDescriptor(
1335
1424
  end},
1336
1425
  true
1337
1426
  )
1338
- __TS__SetDescriptor(
1339
- Unit.prototype,
1340
- "agilityBase",
1341
- {
1342
- get = function(self)
1343
- return getHeroAgi(self.handle, false)
1344
- end,
1345
- set = function(self, agilityBase)
1346
- setHeroAgi(self.handle, agilityBase, true)
1347
- end
1348
- },
1349
- true
1350
- )
1351
1427
  __TS__SetDescriptor(
1352
1428
  Unit.prototype,
1353
1429
  "agilityBonus",
@@ -1365,19 +1441,6 @@ __TS__SetDescriptor(
1365
1441
  end},
1366
1442
  true
1367
1443
  )
1368
- __TS__SetDescriptor(
1369
- Unit.prototype,
1370
- "intelligenceBase",
1371
- {
1372
- get = function(self)
1373
- return getHeroInt(self.handle, false)
1374
- end,
1375
- set = function(self, intelligenceBase)
1376
- setHeroInt(self.handle, intelligenceBase, true)
1377
- end
1378
- },
1379
- true
1380
- )
1381
1444
  __TS__SetDescriptor(
1382
1445
  Unit.prototype,
1383
1446
  "intelligenceBonus",
@@ -1426,17 +1489,17 @@ __TS__SetDescriptor(
1426
1489
  "isTeamGlowVisible",
1427
1490
  {
1428
1491
  get = function(self)
1429
- return not self[106]
1492
+ return not self[107]
1430
1493
  end,
1431
1494
  set = function(self, isTeamGlowVisible)
1432
- showUnitTeamGlow(self.handle, isTeamGlowVisible)
1433
- local ____temp_6
1495
+ BlzShowUnitTeamGlow(self.handle, isTeamGlowVisible)
1496
+ local ____temp_7
1434
1497
  if not isTeamGlowVisible then
1435
- ____temp_6 = true
1498
+ ____temp_7 = true
1436
1499
  else
1437
- ____temp_6 = nil
1500
+ ____temp_7 = nil
1438
1501
  end
1439
- self[106] = ____temp_6
1502
+ self[107] = ____temp_7
1440
1503
  end
1441
1504
  },
1442
1505
  true
@@ -1445,9 +1508,9 @@ __TS__SetDescriptor(
1445
1508
  Unit.prototype,
1446
1509
  "color",
1447
1510
  {set = function(self, color)
1448
- setUnitColor(self.handle, color.handle)
1449
- if self[106] then
1450
- showUnitTeamGlow(self.handle, false)
1511
+ SetUnitColor(self.handle, color.handle)
1512
+ if self[107] then
1513
+ BlzShowUnitTeamGlow(self.handle, false)
1451
1514
  end
1452
1515
  end},
1453
1516
  true
@@ -1470,14 +1533,14 @@ __TS__SetDescriptor(
1470
1533
  "maxHealth",
1471
1534
  {
1472
1535
  get = function(self)
1473
- return BlzGetUnitMaxHP(self.handle) - (self[104] or 0) - (self[105] or 0)
1536
+ return BlzGetUnitMaxHP(self.handle) - (self[105] or 0) - (self[106] or 0)
1474
1537
  end,
1475
1538
  set = function(self, maxHealth)
1476
- if maxHealth < 1 and self[103] ~= nil then
1477
- self[104] = (self[104] or 0) + (1 - maxHealth)
1539
+ if maxHealth < 1 and self[104] ~= nil then
1540
+ self[105] = (self[105] or 0) + (1 - maxHealth)
1478
1541
  maxHealth = 1
1479
1542
  end
1480
- BlzSetUnitMaxHP(self.handle, maxHealth + (self[105] or 0))
1543
+ BlzSetUnitMaxHP(self.handle, maxHealth + (self[106] or 0))
1481
1544
  end
1482
1545
  },
1483
1546
  true
@@ -1519,10 +1582,10 @@ __TS__SetDescriptor(
1519
1582
  "health",
1520
1583
  {
1521
1584
  get = function(self)
1522
- return GetWidgetLife(self.handle) - (self[105] or 0)
1585
+ return GetWidgetLife(self.handle) - (self[106] or 0)
1523
1586
  end,
1524
1587
  set = function(self, health)
1525
- SetWidgetLife(self.handle, health + (self[105] or 0))
1588
+ SetWidgetLife(self.handle, health + (self[106] or 0))
1526
1589
  end
1527
1590
  },
1528
1591
  true
@@ -1598,25 +1661,12 @@ __TS__SetDescriptor(
1598
1661
  },
1599
1662
  true
1600
1663
  )
1601
- __TS__SetDescriptor(
1602
- Unit.prototype,
1603
- "flyHeight",
1604
- {
1605
- get = function(self)
1606
- return getUnitFlyHeight(self.handle)
1607
- end,
1608
- set = function(self, v)
1609
- SetUnitFlyHeight(self.handle, v, 100000)
1610
- end
1611
- },
1612
- true
1613
- )
1614
1664
  __TS__SetDescriptor(
1615
1665
  Unit.prototype,
1616
1666
  "x",
1617
1667
  {
1618
1668
  get = function(self)
1619
- return self[107] or getUnitX(self.handle)
1669
+ return self[108] or getUnitX(self.handle)
1620
1670
  end,
1621
1671
  set = function(self, v)
1622
1672
  SetUnitX(self.handle, v)
@@ -1629,7 +1679,7 @@ __TS__SetDescriptor(
1629
1679
  "y",
1630
1680
  {
1631
1681
  get = function(self)
1632
- return self[108] or getUnitY(self.handle)
1682
+ return self[109] or getUnitY(self.handle)
1633
1683
  end,
1634
1684
  set = function(self, v)
1635
1685
  SetUnitY(self.handle, v)
@@ -1715,10 +1765,10 @@ __TS__SetDescriptor(
1715
1765
  "gold",
1716
1766
  {
1717
1767
  get = function(self)
1718
- return getResourceAmount(self.handle)
1768
+ return GetResourceAmount(self.handle)
1719
1769
  end,
1720
1770
  set = function(self, gold)
1721
- setResourceAmount(self.handle, gold)
1771
+ SetResourceAmount(self.handle, gold)
1722
1772
  end
1723
1773
  },
1724
1774
  true
@@ -1734,14 +1784,18 @@ __TS__SetDescriptor(
1734
1784
  local handle = self.handle
1735
1785
  if isPaused and not IsUnitPaused(handle) then
1736
1786
  self[101] = true
1737
- for _ = self[102] or 0, -1 do
1738
- BlzPauseUnitEx(handle, true)
1787
+ if (self[103] or 0) <= 0 then
1788
+ for _ = self[102] or 0, -1 do
1789
+ BlzPauseUnitEx(handle, true)
1790
+ end
1739
1791
  end
1740
1792
  PauseUnit(handle, true)
1741
1793
  elseif not isPaused and IsUnitPaused(handle) then
1742
1794
  PauseUnit(handle, false)
1743
- for _ = self[102] or 0, -1 do
1744
- BlzPauseUnitEx(handle, false)
1795
+ if (self[103] or 0) <= 0 then
1796
+ for _ = self[102] or 0, -1 do
1797
+ BlzPauseUnitEx(handle, false)
1798
+ end
1745
1799
  end
1746
1800
  self[101] = nil
1747
1801
  end
@@ -1799,20 +1853,6 @@ __TS__SetDescriptor(
1799
1853
  },
1800
1854
  true
1801
1855
  )
1802
- __TS__SetDescriptor(
1803
- Unit.prototype,
1804
- "scale",
1805
- {
1806
- get = function(self)
1807
- return getUnitRealField(self.handle, UNIT_RF_SCALING_VALUE)
1808
- end,
1809
- set = function(self, v)
1810
- setUnitScale(self.handle, v, v, v)
1811
- setUnitRealField(self.handle, UNIT_RF_SCALING_VALUE, v)
1812
- end
1813
- },
1814
- true
1815
- )
1816
1856
  __TS__SetDescriptor(
1817
1857
  Unit.prototype,
1818
1858
  "timeScale",
@@ -1949,30 +1989,6 @@ __TS__SetDescriptor(
1949
1989
  end},
1950
1990
  true
1951
1991
  )
1952
- __TS__SetDescriptor(
1953
- Unit.prototype,
1954
- "onUnitInRange",
1955
- {get = function(self)
1956
- local handle = self.handle
1957
- local onUnitInRange = setmetatable(
1958
- {},
1959
- {__index = function(self, value)
1960
- local event = __TS__New(
1961
- TriggerEvent,
1962
- function(trigger)
1963
- TriggerRegisterUnitInRangeSimple(trigger, value, handle)
1964
- end,
1965
- function() return ____exports.Unit:of(handle) end
1966
- )
1967
- rawset(self, value, event)
1968
- return event
1969
- end}
1970
- )
1971
- rawset(self, "onUnitInRange", onUnitInRange)
1972
- return onUnitInRange
1973
- end},
1974
- true
1975
- )
1976
1992
  __TS__SetDescriptor(
1977
1993
  Unit.prototype,
1978
1994
  "onManaEqual",
@@ -2040,6 +2056,14 @@ __TS__SetDescriptor(
2040
2056
  end},
2041
2057
  true
2042
2058
  )
2059
+ __TS__SetDescriptor(
2060
+ Unit.prototype,
2061
+ "targetAcquiredEvent",
2062
+ {get = function(self)
2063
+ return self:getEvent(EVENT_UNIT_ACQUIRED_TARGET)
2064
+ end},
2065
+ true
2066
+ )
2043
2067
  __TS__SetDescriptor(
2044
2068
  Unit.prototype,
2045
2069
  "onSelect",
@@ -2100,6 +2124,11 @@ __TS__SetDescriptor(
2100
2124
  end},
2101
2125
  true
2102
2126
  )
2127
+ Unit.levelChangedEvent = __TS__New(
2128
+ ____exports.UnitTriggerEvent,
2129
+ EVENT_PLAYER_HERO_LEVEL,
2130
+ function() return ____exports.Unit:of(getTriggerUnit()) end
2131
+ )
2103
2132
  Unit.deathEvent = __TS__New(
2104
2133
  ____exports.UnitTriggerEvent,
2105
2134
  EVENT_PLAYER_UNIT_DEATH,
@@ -2175,25 +2204,25 @@ Unit.onTargetCast = dispatchId(__TS__New(
2175
2204
  InitializingEvent,
2176
2205
  function(event)
2177
2206
  local function listener(unit, id)
2178
- local ____GetSpellTargetUnit_result_9
2207
+ local ____GetSpellTargetUnit_result_10
2179
2208
  if GetSpellTargetUnit() then
2180
- ____GetSpellTargetUnit_result_9 = ____exports.Unit:of(GetSpellTargetUnit())
2209
+ ____GetSpellTargetUnit_result_10 = ____exports.Unit:of(GetSpellTargetUnit())
2181
2210
  else
2182
- local ____GetSpellTargetItem_result_8
2211
+ local ____GetSpellTargetItem_result_9
2183
2212
  if GetSpellTargetItem() then
2184
- ____GetSpellTargetItem_result_8 = Item:of(GetSpellTargetItem())
2213
+ ____GetSpellTargetItem_result_9 = Item:of(GetSpellTargetItem())
2185
2214
  else
2186
- local ____GetSpellTargetDestructable_result_7
2215
+ local ____GetSpellTargetDestructable_result_8
2187
2216
  if GetSpellTargetDestructable() then
2188
- ____GetSpellTargetDestructable_result_7 = Destructable:of(GetSpellTargetDestructable())
2217
+ ____GetSpellTargetDestructable_result_8 = Destructable:of(GetSpellTargetDestructable())
2189
2218
  else
2190
- ____GetSpellTargetDestructable_result_7 = nil
2219
+ ____GetSpellTargetDestructable_result_8 = nil
2191
2220
  end
2192
- ____GetSpellTargetItem_result_8 = ____GetSpellTargetDestructable_result_7
2221
+ ____GetSpellTargetItem_result_9 = ____GetSpellTargetDestructable_result_8
2193
2222
  end
2194
- ____GetSpellTargetUnit_result_9 = ____GetSpellTargetItem_result_8
2223
+ ____GetSpellTargetUnit_result_10 = ____GetSpellTargetItem_result_9
2195
2224
  end
2196
- local target = ____GetSpellTargetUnit_result_9
2225
+ local target = ____GetSpellTargetUnit_result_10
2197
2226
  if target then
2198
2227
  invoke(event, unit, id, target)
2199
2228
  end
@@ -2401,38 +2430,57 @@ Unit.onDamaging = (function()
2401
2430
  if source and source.typeId == dummyUnitId then
2402
2431
  source = nil
2403
2432
  end
2404
- local target = BlzGetEventDamageTarget()
2433
+ local target = ____exports.Unit:of(BlzGetEventDamageTarget())
2434
+ local metadata = damageMetadataByTarget[target]
2435
+ damageMetadataByTarget[target] = nil
2405
2436
  local data = {
2406
2437
  amount = GetEventDamage(),
2407
- attackType = BlzGetEventAttackType(),
2438
+ attackType = nativeToAttackType(BlzGetEventAttackType()),
2408
2439
  damageType = BlzGetEventDamageType(),
2409
2440
  weaponType = BlzGetEventWeaponType(),
2410
- isAttack = BlzGetEventIsAttack()
2441
+ metadata = metadata,
2442
+ isAttack = BlzGetEventIsAttack(),
2443
+ originalAmount = GetEventDamage(),
2444
+ originalMetadata = metadata,
2445
+ preventRetaliation = damagingEventPreventRetaliation
2411
2446
  }
2412
2447
  if data.isAttack and source then
2413
- 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
2414
- if weapon == -1 then
2415
- local targetsAllowed = BlzGetUnitWeaponIntegerField(source.handle, UNIT_WEAPON_IF_ATTACK_TARGETS_ALLOWED, 0)
2416
- weapon = 0
2417
- end
2418
- data.weapon = assert(source.weapons[weapon + 1])
2448
+ data.weapon = source:chooseWeapon(target)
2419
2449
  end
2420
2450
  if not data.isAttack or not source or not source._attackHandlers then
2421
2451
  invoke(
2422
2452
  event,
2423
2453
  source,
2424
- ____exports.Unit:of(target),
2454
+ target,
2425
2455
  setmetatable(
2426
2456
  {},
2427
2457
  {
2428
2458
  __index = data,
2429
2459
  __newindex = function(self, key, value)
2430
- damageSetters[key](value)
2460
+ local damageSetter = damageSetters[key]
2461
+ if damageSetter ~= nil then
2462
+ damageSetter(value)
2463
+ end
2431
2464
  data[key] = value
2432
2465
  end
2433
2466
  }
2434
2467
  )
2435
2468
  )
2469
+ if data[0] and source then
2470
+ local sourceOwner = source.owner.handle
2471
+ data[1] = sourceOwner
2472
+ local targetOwner = target.owner.handle
2473
+ data[2] = targetOwner
2474
+ if not GetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE) then
2475
+ SetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE, true)
2476
+ data[3] = true
2477
+ end
2478
+ if not GetPlayerAlliance(targetOwner, sourceOwner, ALLIANCE_PASSIVE) then
2479
+ SetPlayerAlliance(targetOwner, sourceOwner, ALLIANCE_PASSIVE, true)
2480
+ data[4] = true
2481
+ end
2482
+ end
2483
+ damagingEventByTarget[target] = data
2436
2484
  return
2437
2485
  end
2438
2486
  BlzSetEventDamage(0)
@@ -2440,7 +2488,7 @@ Unit.onDamaging = (function()
2440
2488
  BlzSetEventDamageType(DAMAGE_TYPE_UNKNOWN)
2441
2489
  BlzSetEventWeaponType(WEAPON_TYPE_WHOKNOWS)
2442
2490
  local sourceOwner = source.owner.handle
2443
- local targetOwner = GetOwningPlayer(target)
2491
+ local targetOwner = target.owner.handle
2444
2492
  if not GetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE) then
2445
2493
  SetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE, true)
2446
2494
  Timer:run(function()
@@ -2456,23 +2504,19 @@ Unit.onDamaging = (function()
2456
2504
  for ____, ____value in ipairs(source._attackHandlers) do
2457
2505
  local condition = ____value[1]
2458
2506
  local action = ____value[2]
2459
- if condition(
2460
- source,
2461
- ____exports.Unit:of(target),
2462
- data
2463
- ) then
2507
+ if condition(source, target, data) then
2464
2508
  action(
2465
2509
  source,
2466
- ____exports.Unit:of(target),
2510
+ target,
2467
2511
  setmetatable(
2468
2512
  {fire = function()
2469
2513
  UnitDamageTarget(
2470
2514
  source.handle,
2471
- target,
2515
+ target.handle,
2472
2516
  data.amount,
2473
2517
  true,
2474
2518
  true,
2475
- data.attackType,
2519
+ attackTypeToNative(data.attackType),
2476
2520
  data.damageType,
2477
2521
  data.weaponType
2478
2522
  )
@@ -2499,30 +2543,54 @@ Unit.onDamage = __TS__New(
2499
2543
  if source and source.typeId == dummyUnitId then
2500
2544
  source = nil
2501
2545
  end
2546
+ local target = ____exports.Unit:of(BlzGetEventDamageTarget())
2547
+ local damagingEvent = damagingEventByTarget[target]
2548
+ damagingEventByTarget[target] = nil
2502
2549
  local data = {
2503
2550
  amount = GetEventDamage(),
2504
- attackType = BlzGetEventAttackType(),
2551
+ attackType = nativeToAttackType(BlzGetEventAttackType()),
2505
2552
  damageType = BlzGetEventDamageType(),
2506
2553
  weaponType = BlzGetEventWeaponType(),
2554
+ metadata = damagingEvent and damagingEvent.metadata,
2507
2555
  isAttack = BlzGetEventIsAttack(),
2508
- originalAmount = GetEventDamage(),
2556
+ originalAmount = damagingEvent and damagingEvent.originalAmount or GetEventDamage(),
2557
+ originalMetadata = damagingEvent and damagingEvent.originalMetadata,
2509
2558
  preventDeath = damageEventPreventDeath
2510
2559
  }
2560
+ if damagingEvent then
2561
+ for key, value in pairs(damagingEvent) do
2562
+ if isAttribute(key) then
2563
+ data[key] = value
2564
+ end
2565
+ end
2566
+ local sourceOwner = damagingEvent[1]
2567
+ if sourceOwner then
2568
+ local targetOwner = damagingEvent[2]
2569
+ if damagingEvent[3] then
2570
+ SetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE, false)
2571
+ end
2572
+ if damagingEvent[4] then
2573
+ SetPlayerAlliance(targetOwner, sourceOwner, ALLIANCE_PASSIVE, false)
2574
+ end
2575
+ end
2576
+ end
2511
2577
  local evData = setmetatable(
2512
2578
  {},
2513
2579
  {
2514
2580
  __index = data,
2515
2581
  __newindex = function(self, key, value)
2516
- damageSetters[key](value)
2582
+ local damageSetter = damageSetters[key]
2583
+ if damageSetter ~= nil then
2584
+ damageSetter(value)
2585
+ end
2517
2586
  data[key] = value
2518
2587
  end
2519
2588
  }
2520
2589
  )
2521
- local target = ____exports.Unit:of(BlzGetEventDamageTarget())
2522
2590
  invoke(event, source, target, evData)
2523
2591
  if evData[0] ~= nil and target.health - evData.amount < 0.405 then
2524
2592
  local bonusHealth = math.ceil(evData.amount)
2525
- target[105] = (target[105] or 0) + bonusHealth
2593
+ target[106] = (target[106] or 0) + bonusHealth
2526
2594
  BlzSetUnitMaxHP(
2527
2595
  target.handle,
2528
2596
  BlzGetUnitMaxHP(target.handle) + bonusHealth
@@ -2536,7 +2604,7 @@ Unit.onDamage = __TS__New(
2536
2604
  evData[0],
2537
2605
  table.unpack(evData, 1 + 1, 1 + (evData[1] or 0))
2538
2606
  )
2539
- target[105] = (target[105] or 0) - bonusHealth
2607
+ target[106] = (target[106] or 0) - bonusHealth
2540
2608
  SetWidgetLife(
2541
2609
  target.handle,
2542
2610
  GetWidgetLife(target.handle) - bonusHealth
@@ -2572,10 +2640,14 @@ Unit.itemPickedUpEvent = __TS__New(
2572
2640
  ____exports.UnitTriggerEvent,
2573
2641
  EVENT_PLAYER_UNIT_PICKUP_ITEM,
2574
2642
  function()
2575
- local unit = getTriggerUnit()
2576
- local item = getManipulatedItem()
2577
- if getUnitTypeId(unit) ~= dummyUnitId and not (ignoreEventsItems[item] ~= nil) then
2578
- return ____exports.Unit:of(unit), Item:of(item)
2643
+ local unitHandle = getTriggerUnit()
2644
+ local itemHandle = getManipulatedItem()
2645
+ if getUnitTypeId(unitHandle) ~= dummyUnitId and not (ignoreEventsItems[itemHandle] ~= nil) then
2646
+ local unit = ____exports.Unit:of(unitHandle)
2647
+ local item = Item:of(itemHandle)
2648
+ if item.owner ~= unit then
2649
+ return unit, item
2650
+ end
2579
2651
  end
2580
2652
  return IgnoreEvent
2581
2653
  end
@@ -2595,7 +2667,22 @@ Unit.itemUsedEvent = __TS__New(
2595
2667
  Unit.itemStackedEvent = __TS__New(
2596
2668
  ____exports.UnitTriggerEvent,
2597
2669
  EVENT_PLAYER_UNIT_STACK_ITEM,
2598
- function() return ____exports.Unit:of(getTriggerUnit()), Item:of(getManipulatedItem()) end
2670
+ function() return ____exports.Unit:of(getTriggerUnit()), Item:of(BlzGetStackingItemTarget()), Item:of(BlzGetStackingItemSource()) end
2671
+ )
2672
+ __TS__ObjectDefineProperty(
2673
+ Unit,
2674
+ "itemChargesChangedEvent",
2675
+ {get = function(self)
2676
+ local event = __TS__New(Event)
2677
+ Item.chargesChangedEvent:addListener(function(item)
2678
+ local unit = item.owner
2679
+ if unit ~= nil then
2680
+ invoke(event, unit, item)
2681
+ end
2682
+ end)
2683
+ rawset(self, "itemChargesChangedEvent", event)
2684
+ return event
2685
+ end}
2599
2686
  )
2600
2687
  __TS__ObjectDefineProperty(
2601
2688
  Unit,
@@ -2667,6 +2754,10 @@ __TS__ObjectDefineProperty(
2667
2754
  rawset(self, "destroyEvent", destroyEvent)
2668
2755
  return destroyEvent
2669
2756
  end}
2757
+ )
2758
+ Unit.synchronize = synchronizer(
2759
+ function(unit) return unit.syncId end,
2760
+ function(syncId) return unitBySyncId[syncId] end
2670
2761
  );
2671
2762
  (function(self)
2672
2763
  local leaveAbilityIds = postcompile(function()
@@ -2696,7 +2787,8 @@ __TS__ObjectDefineProperty(
2696
2787
  return
2697
2788
  end
2698
2789
  end
2699
- unit:destroy()
2790
+ unit:saveData()
2791
+ Timer:run(unit, "destroy")
2700
2792
  end)
2701
2793
  end
2702
2794
  end)(Unit)