warscript 0.0.1-dev.ec4cf89 → 0.0.1-dev.eda504c

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 (207) hide show
  1. package/attributes.d.ts +6 -0
  2. package/attributes.lua +17 -1
  3. package/config.d.ts +5 -0
  4. package/config.lua +10 -0
  5. package/core/types/effect.d.ts +14 -6
  6. package/core/types/effect.lua +131 -35
  7. package/core/types/frame.d.ts +6 -0
  8. package/core/types/frame.lua +115 -22
  9. package/core/types/player.lua +3 -1
  10. package/core/types/playerCamera.d.ts +2 -0
  11. package/core/types/playerCamera.lua +123 -5
  12. package/core/types/sound.d.ts +17 -24
  13. package/core/types/sound.lua +99 -24
  14. package/core/types/tileCell.d.ts +9 -0
  15. package/core/types/tileCell.lua +92 -0
  16. package/core/types/timer.d.ts +9 -8
  17. package/core/types/timer.lua +45 -23
  18. package/core/util.d.ts +1 -1
  19. package/core/util.lua +18 -1
  20. package/decl/native.d.ts +846 -790
  21. package/engine/behavior.d.ts +7 -2
  22. package/engine/behavior.lua +112 -33
  23. package/engine/behaviour/ability/always-enabled.d.ts +7 -0
  24. package/engine/behaviour/ability/always-enabled.lua +31 -0
  25. package/engine/behaviour/ability/apply-buff.d.ts +8 -5
  26. package/engine/behaviour/ability/apply-buff.lua +32 -0
  27. package/engine/behaviour/ability/apply-unit-behavior.lua +1 -0
  28. package/engine/behaviour/ability/damage.d.ts +9 -3
  29. package/engine/behaviour/ability/damage.lua +26 -38
  30. package/engine/behaviour/ability/emulate-impact.d.ts +6 -0
  31. package/engine/behaviour/ability/emulate-impact.lua +43 -0
  32. package/engine/behaviour/ability/instant-impact.d.ts +2 -2
  33. package/engine/behaviour/ability/instant-impact.lua +4 -19
  34. package/engine/behaviour/ability/on-command-impact.d.ts +8 -0
  35. package/engine/behaviour/ability/on-command-impact.lua +25 -0
  36. package/engine/behaviour/ability/remove-buffs.d.ts +16 -0
  37. package/engine/behaviour/ability/remove-buffs.lua +28 -0
  38. package/engine/behaviour/ability/restore-mana.d.ts +1 -1
  39. package/engine/behaviour/ability/restore-mana.lua +6 -6
  40. package/engine/behaviour/ability.d.ts +20 -4
  41. package/engine/behaviour/ability.lua +111 -47
  42. package/engine/behaviour/unit/stun-immunity.d.ts +7 -3
  43. package/engine/behaviour/unit/stun-immunity.lua +52 -27
  44. package/engine/behaviour/unit.d.ts +39 -0
  45. package/engine/behaviour/unit.lua +210 -4
  46. package/engine/buff.d.ts +85 -46
  47. package/engine/buff.lua +373 -229
  48. package/engine/internal/ability.d.ts +23 -14
  49. package/engine/internal/ability.lua +129 -85
  50. package/engine/internal/item/ability.lua +162 -4
  51. package/engine/internal/item+owner.lua +12 -6
  52. package/engine/internal/item.d.ts +20 -19
  53. package/engine/internal/item.lua +191 -74
  54. package/engine/internal/mechanics/ability-duration.lua +1 -1
  55. package/engine/internal/misc/ability-disable-counter.d.ts +2 -0
  56. package/engine/internal/misc/ability-disable-counter.lua +13 -0
  57. package/engine/internal/misc/damage-metadata-by-target.d.ts +2 -0
  58. package/engine/internal/misc/damage-metadata-by-target.lua +5 -0
  59. package/engine/internal/misc/frame-coordinates.d.ts +2 -0
  60. package/engine/internal/misc/frame-coordinates.lua +21 -0
  61. package/engine/internal/misc/get-terrain-z.d.ts +2 -0
  62. package/engine/internal/misc/get-terrain-z.lua +11 -0
  63. package/engine/internal/misc/player-local-handle.d.ts +2 -0
  64. package/engine/internal/misc/player-local-handle.lua +5 -0
  65. package/engine/internal/object-data/auto-attack-speed-increase.d.ts +1 -1
  66. package/engine/internal/object-data/auto-attack-speed-increase.lua +2 -0
  67. package/engine/internal/object-data/evasion-probability.d.ts +2 -0
  68. package/engine/internal/object-data/evasion-probability.lua +16 -0
  69. package/engine/internal/unit/ability.d.ts +45 -1
  70. package/engine/internal/unit/ability.lua +128 -17
  71. package/engine/internal/unit/add-item-to-slot-init.d.ts +2 -0
  72. package/engine/internal/unit/add-item-to-slot-init.lua +23 -0
  73. package/engine/internal/unit/add-item-to-slot.d.ts +2 -0
  74. package/engine/internal/unit/add-item-to-slot.lua +52 -0
  75. package/engine/internal/unit/allowed-targets.d.ts +1 -1
  76. package/engine/internal/unit/allowed-targets.lua +9 -1
  77. package/engine/internal/unit/bonus.d.ts +6 -2
  78. package/engine/internal/unit/bonus.lua +23 -1
  79. package/engine/internal/unit/ignore-events-items.d.ts +2 -0
  80. package/engine/internal/unit/ignore-events-items.lua +5 -0
  81. package/engine/internal/unit/item.d.ts +24 -0
  82. package/engine/internal/unit/item.lua +78 -0
  83. package/engine/internal/unit/main-selected.d.ts +13 -0
  84. package/engine/internal/unit/main-selected.lua +51 -0
  85. package/engine/internal/unit/order.d.ts +20 -0
  86. package/engine/internal/unit/order.lua +136 -0
  87. package/engine/internal/unit+ability.lua +12 -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 +60 -13
  92. package/engine/internal/unit.d.ts +58 -18
  93. package/engine/internal/unit.lua +399 -161
  94. package/engine/internal/utility.lua +12 -0
  95. package/engine/lightning.d.ts +12 -5
  96. package/engine/lightning.lua +48 -14
  97. package/engine/local-client.d.ts +7 -2
  98. package/engine/local-client.lua +82 -0
  99. package/engine/object-data/auxiliary/animation-name.d.ts +1 -0
  100. package/engine/object-data/auxiliary/animation-name.lua +16 -0
  101. package/engine/object-data/auxiliary/armor-type.d.ts +11 -0
  102. package/engine/object-data/auxiliary/armor-type.lua +46 -0
  103. package/engine/object-data/auxiliary/attachment-preset.d.ts +7 -2
  104. package/engine/object-data/auxiliary/attachment-preset.lua +4 -3
  105. package/engine/object-data/auxiliary/attack-type.d.ts +7 -8
  106. package/engine/object-data/auxiliary/attack-type.lua +42 -0
  107. package/engine/object-data/auxiliary/movement-type.d.ts +7 -7
  108. package/engine/object-data/auxiliary/movement-type.lua +22 -0
  109. package/engine/object-data/auxiliary/sound-eax.d.ts +10 -0
  110. package/engine/object-data/auxiliary/sound-eax.lua +2 -0
  111. package/engine/object-data/auxiliary/sound-preset-name.d.ts +5 -1
  112. package/engine/object-data/auxiliary/tech-tree-dependency.d.ts +1 -1
  113. package/engine/object-data/auxiliary/unit-attribute.d.ts +6 -0
  114. package/engine/object-data/auxiliary/unit-attribute.lua +9 -0
  115. package/engine/object-data/entry/ability-type/berserk.d.ts +2 -0
  116. package/engine/object-data/entry/ability-type/berserk.lua +13 -0
  117. package/engine/object-data/entry/ability-type/blank-configurable.lua +12 -1
  118. package/engine/object-data/entry/ability-type/carrion-swarm.d.ts +14 -0
  119. package/engine/object-data/entry/ability-type/carrion-swarm.lua +65 -0
  120. package/engine/object-data/entry/ability-type/disease-cloud.lua +2 -2
  121. package/engine/object-data/entry/ability-type/engineering-upgrade.lua +2 -2
  122. package/engine/object-data/entry/ability-type/ensnare.d.ts +12 -0
  123. package/engine/object-data/entry/ability-type/ensnare.lua +52 -0
  124. package/engine/object-data/entry/ability-type/feral-spirit.lua +2 -2
  125. package/engine/object-data/entry/ability-type/permanent-invisibility.d.ts +8 -0
  126. package/engine/object-data/entry/ability-type/permanent-invisibility.lua +26 -0
  127. package/engine/object-data/entry/ability-type/phase-shift.d.ts +10 -0
  128. package/engine/object-data/entry/ability-type/phase-shift.lua +39 -0
  129. package/engine/object-data/entry/ability-type/phoenix-morph.lua +4 -4
  130. package/engine/object-data/entry/ability-type/raise-dead.d.ts +17 -0
  131. package/engine/object-data/entry/ability-type/raise-dead.lua +78 -0
  132. package/engine/object-data/entry/ability-type/shock-wave.d.ts +4 -0
  133. package/engine/object-data/entry/ability-type/shock-wave.lua +26 -0
  134. package/engine/object-data/entry/ability-type/slow-poison.d.ts +10 -0
  135. package/engine/object-data/entry/ability-type/slow-poison.lua +58 -0
  136. package/engine/object-data/entry/ability-type/summon-quilbeast.lua +2 -2
  137. package/engine/object-data/entry/ability-type/summon-water-elemental.lua +2 -2
  138. package/engine/object-data/entry/ability-type/web.d.ts +12 -0
  139. package/engine/object-data/entry/ability-type/web.lua +52 -0
  140. package/engine/object-data/entry/ability-type.d.ts +19 -17
  141. package/engine/object-data/entry/ability-type.lua +93 -36
  142. package/engine/object-data/entry/buff-type/applicable.lua +18 -37
  143. package/engine/object-data/entry/buff-type.d.ts +6 -12
  144. package/engine/object-data/entry/buff-type.lua +13 -29
  145. package/engine/object-data/entry/destructible-type.d.ts +1 -1
  146. package/engine/object-data/entry/item-type.d.ts +15 -1
  147. package/engine/object-data/entry/item-type.lua +93 -2
  148. package/engine/object-data/entry/lightning-type.d.ts +1 -1
  149. package/engine/object-data/entry/sound-preset.d.ts +33 -0
  150. package/engine/object-data/entry/sound-preset.lua +140 -0
  151. package/engine/object-data/entry/unit-type.d.ts +21 -5
  152. package/engine/object-data/entry/unit-type.lua +214 -93
  153. package/engine/object-data/entry/upgrade.d.ts +1 -1
  154. package/engine/object-data/entry/upgrade.lua +4 -4
  155. package/engine/object-data/entry.d.ts +16 -14
  156. package/engine/object-data/entry.lua +60 -32
  157. package/engine/object-data/utility/object-data-entry-id-generator.lua +7 -0
  158. package/engine/object-field/ability.d.ts +28 -5
  159. package/engine/object-field/ability.lua +59 -5
  160. package/engine/object-field/unit.d.ts +57 -3
  161. package/engine/object-field/unit.lua +207 -7
  162. package/engine/object-field.d.ts +17 -6
  163. package/engine/object-field.lua +190 -90
  164. package/engine/random.d.ts +9 -0
  165. package/engine/random.lua +13 -0
  166. package/engine/standard/entries/buff-type.d.ts +3 -0
  167. package/engine/standard/entries/buff-type.lua +3 -0
  168. package/engine/standard/entries/sound-preset.d.ts +10 -0
  169. package/engine/standard/entries/sound-preset.lua +10 -0
  170. package/engine/standard/fields/ability.d.ts +2 -0
  171. package/engine/standard/fields/ability.lua +2 -0
  172. package/engine/standard/fields/unit.d.ts +4 -0
  173. package/engine/standard/fields/unit.lua +7 -0
  174. package/engine/text-tag.d.ts +36 -2
  175. package/engine/text-tag.lua +249 -10
  176. package/engine/unit.d.ts +4 -0
  177. package/engine/unit.lua +4 -0
  178. package/index.d.ts +1 -0
  179. package/index.lua +1 -0
  180. package/net/socket.d.ts +7 -1
  181. package/net/socket.lua +45 -4
  182. package/network.d.ts +1 -0
  183. package/network.lua +3 -2
  184. package/objutil/buff.lua +3 -4
  185. package/objutil/unit.lua +8 -0
  186. package/package.json +2 -2
  187. package/patch-lua.d.ts +0 -0
  188. package/patch-lua.lua +10 -0
  189. package/patch-lualib.lua +1 -1
  190. package/utility/arrays.d.ts +10 -1
  191. package/utility/arrays.lua +45 -3
  192. package/utility/callback-array.d.ts +17 -0
  193. package/utility/callback-array.lua +61 -0
  194. package/utility/functions.d.ts +8 -0
  195. package/utility/functions.lua +13 -0
  196. package/utility/lazy.d.ts +2 -0
  197. package/utility/lazy.lua +14 -0
  198. package/utility/linked-set.d.ts +12 -2
  199. package/utility/linked-set.lua +10 -3
  200. package/utility/lua-maps.d.ts +15 -2
  201. package/utility/lua-maps.lua +53 -2
  202. package/utility/lua-sets.d.ts +2 -0
  203. package/utility/lua-sets.lua +7 -0
  204. package/utility/reflection.lua +11 -7
  205. package/utility/types.d.ts +4 -0
  206. package/core/types/order.d.ts +0 -25
  207. package/core/types/order.lua +0 -55
@@ -51,12 +51,21 @@ local ____arrays = require("utility.arrays")
51
51
  local forEach = ____arrays.forEach
52
52
  local ____math = require("math")
53
53
  local min = ____math.min
54
+ local ____ignore_2Devents_2Ditems = require("engine.internal.unit.ignore-events-items")
55
+ local ignoreEventsItems = ____ignore_2Devents_2Ditems.ignoreEventsItems
56
+ local ____attack_2Dtype = require("engine.object-data.auxiliary.attack-type")
57
+ local attackTypeToNative = ____attack_2Dtype.attackTypeToNative
58
+ local nativeToAttackType = ____attack_2Dtype.nativeToAttackType
59
+ local ____damage_2Dmetadata_2Dby_2Dtarget = require("engine.internal.misc.damage-metadata-by-target")
60
+ local damageMetadataByTarget = ____damage_2Dmetadata_2Dby_2Dtarget.damageMetadataByTarget
61
+ local ____attributes = require("attributes")
62
+ local isAttribute = ____attributes.isAttribute
63
+ local ____ability = require("engine.internal.item.ability")
64
+ local doUnitAbilityAction = ____ability.doUnitAbilityAction
54
65
  local match = string.match
55
66
  local ____tostring = _G.tostring
56
67
  local setUnitAnimation = SetUnitAnimation
57
- local setUnitAnimationWithRarity = SetUnitAnimationWithRarity
58
68
  local setUnitAnimationByIndex = SetUnitAnimationByIndex
59
- local queueUnitAnimation = QueueUnitAnimation
60
69
  local getUnitIntegerField = BlzGetUnitIntegerField
61
70
  local getUnitRealField = BlzGetUnitRealField
62
71
  local getHeroStr = GetHeroStr
@@ -75,9 +84,9 @@ local setUnitScale = SetUnitScale
75
84
  local setUnitPosition = SetUnitPosition
76
85
  local setUnitTimeScale = SetUnitTimeScale
77
86
  local getHandleId = GetHandleId
87
+ local getUnitCurrentOrder = GetUnitCurrentOrder
78
88
  local createUnit = CreateUnit
79
89
  local killUnit = KillUnit
80
- local setUnitExploded = SetUnitExploded
81
90
  local removeUnit = RemoveUnit
82
91
  local getUnitTypeId = GetUnitTypeId
83
92
  local isHeroUnitId = IsHeroUnitId
@@ -93,8 +102,6 @@ local getSpellTargetItem = GetSpellTargetItem
93
102
  local getSpellTargetDestructable = GetSpellTargetDestructable
94
103
  local isUnitInRangeXY = IsUnitInRangeXY
95
104
  local isUnitInRange = IsUnitInRange
96
- local setResourceAmount = SetResourceAmount
97
- local getResourceAmount = GetResourceAmount
98
105
  local getUnitWeaponRealField = BlzGetUnitWeaponRealField
99
106
  local setUnitWeaponRealField = BlzSetUnitWeaponRealField
100
107
  local getUnitWeaponStringField = BlzGetUnitWeaponStringField
@@ -118,15 +125,9 @@ local getOrderedUnit = GetOrderedUnit
118
125
  local getIssuedOrderId = GetIssuedOrderId
119
126
  local isUnitInvulnerable = BlzIsUnitInvulnerable
120
127
  local unitAlive = UnitAlive
121
- local unitAddType = UnitAddType
122
- local unitRemoveType = UnitRemoveType
123
- local isUnitIllusion = IsUnitIllusion
124
- local isUnitType = IsUnitType
125
128
  local isUnitAlly = IsUnitAlly
126
129
  local isUnitEnemy = IsUnitEnemy
127
130
  local getOwningPlayer = GetOwningPlayer
128
- local setUnitColor = SetUnitColor
129
- local showUnitTeamGlow = BlzShowUnitTeamGlow
130
131
  ____exports.UnitClassification = {}
131
132
  local UnitClassification = ____exports.UnitClassification
132
133
  do
@@ -136,6 +137,7 @@ do
136
137
  UnitClassification.GROUND = UNIT_TYPE_GROUND
137
138
  UnitClassification.SUMMONED = UNIT_TYPE_SUMMONED
138
139
  UnitClassification.MECHANICAL = UNIT_TYPE_MECHANICAL
140
+ UnitClassification.WORKER = UNIT_TYPE_PEON
139
141
  UnitClassification.ANCIENT = UNIT_TYPE_ANCIENT
140
142
  UnitClassification.SUICIDAL = UNIT_TYPE_SAPPER
141
143
  UnitClassification.TAUREN = UNIT_TYPE_TAUREN
@@ -343,6 +345,9 @@ local function dispatchAbility(event)
343
345
  }
344
346
  )
345
347
  end
348
+ local function damagingEventPreventRetaliation(self)
349
+ self[0] = true
350
+ end
346
351
  local function damageEventPreventDeath(self, callback, ...)
347
352
  if self[0] ~= nil then
348
353
  return
@@ -354,7 +359,14 @@ local function damageEventPreventDeath(self, callback, ...)
354
359
  rawset(self, 1 + i, (select(i, ...)))
355
360
  end
356
361
  end
357
- local damageSetters = {amount = BlzSetEventDamage, attackType = BlzSetEventAttackType, damageType = BlzSetEventDamageType, weaponType = BlzSetEventWeaponType}
362
+ local damageSetters = {
363
+ amount = BlzSetEventDamage,
364
+ attackType = function(attackType)
365
+ return BlzSetEventAttackType(attackTypeToNative(attackType))
366
+ end,
367
+ damageType = BlzSetEventDamageType,
368
+ weaponType = BlzSetEventWeaponType
369
+ }
358
370
  local jlimitopByOperator = {
359
371
  [0] = LESS_THAN_OR_EQUAL,
360
372
  [1] = LESS_THAN_OR_EQUAL,
@@ -398,6 +410,19 @@ function UnitWeapon.prototype.____constructor(self, unit, index)
398
410
  self.unit = unit
399
411
  self.index = index
400
412
  end
413
+ __TS__SetDescriptor(
414
+ UnitWeapon.prototype,
415
+ "isEnabled",
416
+ {
417
+ get = function(self)
418
+ return BlzGetUnitWeaponBooleanField(self.unit.handle, UNIT_WEAPON_BF_ATTACKS_ENABLED, self.index)
419
+ end,
420
+ set = function(self, isEnabled)
421
+ BlzSetUnitWeaponBooleanField(self.unit.handle, UNIT_WEAPON_BF_ATTACKS_ENABLED, self.index, isEnabled)
422
+ end
423
+ },
424
+ true
425
+ )
401
426
  __TS__SetDescriptor(
402
427
  UnitWeapon.prototype,
403
428
  "cooldown",
@@ -432,6 +457,19 @@ __TS__SetDescriptor(
432
457
  },
433
458
  true
434
459
  )
460
+ __TS__SetDescriptor(
461
+ UnitWeapon.prototype,
462
+ "allowedTargetCombatClassifications",
463
+ {
464
+ get = function(self)
465
+ return BlzGetUnitWeaponIntegerField(self.unit.handle, UNIT_WEAPON_IF_ATTACK_TARGETS_ALLOWED, self.index)
466
+ end,
467
+ set = function(self, allowedTargetCombatClassifications)
468
+ BlzSetUnitWeaponIntegerField(self.unit.handle, UNIT_WEAPON_IF_ATTACK_TARGETS_ALLOWED, self.index, allowedTargetCombatClassifications)
469
+ end
470
+ },
471
+ true
472
+ )
435
473
  __TS__SetDescriptor(
436
474
  UnitWeapon.prototype,
437
475
  "damageBase",
@@ -562,17 +600,6 @@ local function retrieveAbility(unit, ability, abilityId)
562
600
  ____exports.Unit:of(unit)
563
601
  )
564
602
  end
565
- if not unitAddAbility(unit, abilityId) then
566
- if getUnitAbility(unit, abilityId) == ability then
567
- return UnitAbility:of(
568
- ability,
569
- abilityId,
570
- ____exports.Unit:of(unit)
571
- )
572
- end
573
- else
574
- unitRemoveAbility(unit, abilityId)
575
- end
576
603
  for i = 0, unitInventorySize(unit) - 1 do
577
604
  local item = unitItemInSlot(unit, i)
578
605
  if getItemAbility(item, abilityId) == ability then
@@ -630,15 +657,15 @@ for ____, player in ipairs(Player.all) do
630
657
  dummies[player] = dummy
631
658
  end
632
659
  local function delayHealthChecksCallback(unit)
633
- local counter = (unit[102] or 0) - 1
660
+ local counter = (unit[103] or 0) - 1
634
661
  if counter ~= 0 then
635
- unit[102] = counter
662
+ unit[103] = counter
636
663
  return
637
664
  end
638
- unit[102] = nil
639
- local healthBonus = unit[103]
665
+ unit[103] = nil
666
+ local healthBonus = unit[104]
640
667
  if healthBonus ~= nil then
641
- unit[103] = nil
668
+ unit[104] = nil
642
669
  local handle = unit.handle
643
670
  BlzSetUnitMaxHP(
644
671
  handle,
@@ -646,12 +673,27 @@ local function delayHealthChecksCallback(unit)
646
673
  )
647
674
  end
648
675
  end
676
+ local nextSyncId = 1
677
+ local unitBySyncId = setmetatable({}, {__mode = "v"})
678
+ local damagingEventByTarget = setmetatable({}, {__mode = "k"})
679
+ local function addAbility(unit, abilityTypeId)
680
+ local ____unitAddAbility_result_0
681
+ if unitAddAbility(unit, abilityTypeId) then
682
+ ____unitAddAbility_result_0 = getUnitAbility(unit, abilityTypeId)
683
+ else
684
+ ____unitAddAbility_result_0 = nil
685
+ end
686
+ return ____unitAddAbility_result_0
687
+ end
649
688
  ____exports.Unit = __TS__Class()
650
689
  local Unit = ____exports.Unit
651
690
  Unit.name = "Unit"
652
691
  __TS__ClassExtends(Unit, Handle)
653
692
  function Unit.prototype.____constructor(self, handle)
654
693
  Handle.prototype.____constructor(self, handle)
694
+ local ____nextSyncId_1 = nextSyncId
695
+ nextSyncId = ____nextSyncId_1 + 1
696
+ self.syncId = ____nextSyncId_1
655
697
  self._owner = Player:of(getOwningPlayer(handle))
656
698
  assert(unitAddAbility(handle, leaveDetectAbilityId) and UnitMakeAbilityPermanent(handle, true, leaveDetectAbilityId))
657
699
  assert(unitAddAbility(handle, morphDetectAbilityId))
@@ -664,6 +706,7 @@ function Unit.prototype.____constructor(self, handle)
664
706
  fourCC("Amrf")
665
707
  ))
666
708
  end
709
+ unitBySyncId[self.syncId] = self
667
710
  local ____ = self.abilities
668
711
  end
669
712
  function Unit.prototype.getEvent(self, event, collector)
@@ -682,6 +725,8 @@ function Unit.prototype.getEvent(self, event, collector)
682
725
  end
683
726
  function Unit.prototype.onDestroy(self)
684
727
  local handle = self.handle
728
+ self[107] = getUnitX(handle)
729
+ self[108] = getUnitY(handle)
685
730
  if not self._owner then
686
731
  self._owner = Player:of(getOwningPlayer(handle))
687
732
  end
@@ -749,17 +794,17 @@ function Unit.prototype.addModifier(self, property, modifier)
749
794
  end}
750
795
  end
751
796
  function Unit.prototype.hasCombatClassification(self, combatClassification)
752
- local ____combatClassification_0 = combatClassification
753
- return getUnitIntegerField(self.handle, UNIT_IF_TARGETED_AS) & ____combatClassification_0 == ____combatClassification_0
797
+ local ____combatClassification_2 = combatClassification
798
+ return getUnitIntegerField(self.handle, UNIT_IF_TARGETED_AS) & ____combatClassification_2 == ____combatClassification_2
754
799
  end
755
800
  function Unit.prototype.addClassification(self, classification)
756
- return unitAddType(self.handle, classification)
801
+ return UnitAddType(self.handle, classification)
757
802
  end
758
803
  function Unit.prototype.removeClassification(self, classification)
759
- return unitRemoveType(self.handle, classification)
804
+ return UnitRemoveType(self.handle, classification)
760
805
  end
761
806
  function Unit.prototype.hasClassification(self, classification)
762
- return isUnitType(self.handle, classification)
807
+ return IsUnitType(self.handle, classification)
763
808
  end
764
809
  function Unit.prototype.isVisibleTo(self, player)
765
810
  return isUnitVisible(self.handle, player.handle)
@@ -768,13 +813,13 @@ function Unit.prototype.isInvisibleTo(self, player)
768
813
  return isUnitInvisible(self.handle, player.handle)
769
814
  end
770
815
  function Unit.prototype.isInRangeOf(self, x, y, range)
771
- local ____temp_1
816
+ local ____temp_3
772
817
  if type(x) == "number" then
773
- ____temp_1 = isUnitInRangeXY(self.handle, x, y, range)
818
+ ____temp_3 = isUnitInRangeXY(self.handle, x, y, range)
774
819
  else
775
- ____temp_1 = isUnitInRange(self.handle, x.handle, y)
820
+ ____temp_3 = isUnitInRange(self.handle, x.handle, y)
776
821
  end
777
- return ____temp_1
822
+ return ____temp_3
778
823
  end
779
824
  function Unit.prototype.isAllyOf(self, unit)
780
825
  return isUnitAlly(
@@ -792,16 +837,30 @@ function Unit.prototype.playAnimation(self, animation, rarity)
792
837
  if type(animation) == "number" then
793
838
  setUnitAnimationByIndex(self.handle, animation)
794
839
  elseif rarity then
795
- setUnitAnimationWithRarity(self.handle, animation, rarity)
840
+ SetUnitAnimationWithRarity(self.handle, animation, rarity)
796
841
  else
797
842
  setUnitAnimation(self.handle, animation)
798
843
  end
799
844
  end
845
+ function Unit.prototype.resetAnimation(self)
846
+ ResetUnitAnimation(self.handle)
847
+ end
800
848
  function Unit.prototype.queueAnimation(self, animation)
801
- queueUnitAnimation(self.handle, animation)
849
+ QueueUnitAnimation(self.handle, animation)
850
+ end
851
+ function Unit.prototype.chooseWeapon(self, target)
852
+ local firstWeapon = self.firstWeapon
853
+ if firstWeapon.isEnabled and target:isAllowedTarget(self, firstWeapon.allowedTargetCombatClassifications) then
854
+ return firstWeapon
855
+ end
856
+ local secondWeapon = self.secondWeapon
857
+ if secondWeapon.isEnabled and target:isAllowedTarget(target, secondWeapon.allowedTargetCombatClassifications) then
858
+ return secondWeapon
859
+ end
860
+ return nil
802
861
  end
803
862
  function Unit.prototype.delayHealthChecks(self)
804
- self[102] = (self[102] or 0) + 1
863
+ self[103] = (self[103] or 0) + 1
805
864
  Timer:run(delayHealthChecksCallback, self)
806
865
  end
807
866
  function Unit.prototype.setPosition(self, x, y)
@@ -811,21 +870,21 @@ function Unit.prototype.isSelected(self, player)
811
870
  return IsUnitSelected(self.handle, player.handle)
812
871
  end
813
872
  function Unit.prototype.explode(self)
814
- setUnitExploded(self.handle, true)
873
+ SetUnitExploded(self.handle, true)
815
874
  killUnit(self.handle)
816
875
  end
817
876
  function Unit.prototype.kill(self)
818
877
  killUnit(self.handle)
819
878
  end
820
879
  function Unit.prototype.revive(self, x, y, doEffect)
821
- local ____ReviveHero_4 = ReviveHero
822
- local ____array_3 = __TS__SparseArrayNew(self.handle, x, y)
823
- local ____doEffect_2 = doEffect
824
- if ____doEffect_2 == nil then
825
- ____doEffect_2 = false
880
+ local ____ReviveHero_6 = ReviveHero
881
+ local ____array_5 = __TS__SparseArrayNew(self.handle, x, y)
882
+ local ____doEffect_4 = doEffect
883
+ if ____doEffect_4 == nil then
884
+ ____doEffect_4 = false
826
885
  end
827
- __TS__SparseArrayPush(____array_3, ____doEffect_2)
828
- ____ReviveHero_4(__TS__SparseArraySpread(____array_3))
886
+ __TS__SparseArrayPush(____array_5, ____doEffect_4)
887
+ ____ReviveHero_6(__TS__SparseArraySpread(____array_5))
829
888
  end
830
889
  function Unit.prototype.healTarget(self, target, amount)
831
890
  if __TS__InstanceOf(target, ____exports.Unit) and target:hasAbility(fourCC("BIhm")) then
@@ -865,20 +924,19 @@ function Unit.prototype.dropItemSlot(self, item, slot)
865
924
  return UnitDropItemSlot(self.handle, item.handle, slot)
866
925
  end
867
926
  function Unit.prototype.itemInSlot(self, slot)
868
- return Item:of(UnitItemInSlot(self.handle, slot))
927
+ return Item:of(unitItemInSlot(self.handle, slot))
869
928
  end
870
929
  function Unit.prototype.addAbility(self, abilityId)
871
- if unitAddAbility(self.handle, abilityId) then
872
- local ability = UnitAbility:of(
873
- checkNotNull(getUnitAbility(self.handle, abilityId)),
874
- abilityId,
875
- self
876
- )
930
+ local ability = UnitAbility:of(
931
+ doUnitAbilityAction(self.handle, abilityId, addAbility, abilityId),
932
+ abilityId,
933
+ self
934
+ )
935
+ if ability ~= nil then
877
936
  local abilities = self.abilities
878
937
  abilities[#abilities + 1] = ability
879
- return ability
880
938
  end
881
- return nil
939
+ return ability
882
940
  end
883
941
  function Unit.prototype.makeAbilityPermanent(self, abilityId, permanent)
884
942
  return UnitMakeAbilityPermanent(self.handle, permanent, abilityId)
@@ -892,31 +950,21 @@ end
892
950
  function Unit.prototype.hasAbility(self, abilityId)
893
951
  return getUnitAbilityLevel(self.handle, abilityId) > 0
894
952
  end
895
- function Unit.prototype.getAbilityById(self, abilityId)
896
- local handle = self.handle
897
- if unitAddAbility(handle, abilityId) then
898
- assert(unitRemoveAbility(handle, abilityId))
899
- return nil
900
- end
901
- return UnitAbility:of(
902
- getUnitAbility(self.handle, abilityId),
903
- abilityId,
904
- self
905
- )
953
+ function Unit.prototype.getAbility(self, abilityId)
954
+ local ability = doUnitAbilityAction(self.handle, abilityId, getUnitAbility, abilityId)
955
+ return UnitAbility:of(ability, abilityId, self)
906
956
  end
907
- function Unit.prototype.removeAbility(self, abilityId)
908
- if unitRemoveAbility(self.handle, abilityId) then
909
- local abilities = self.abilities
910
- for i = 1, #abilities do
911
- if abilities[i].typeId == abilityId then
912
- abilities[i]:destroy()
913
- tremove(abilities, i)
914
- return true
915
- end
957
+ function Unit.prototype.removeAbility(self, abilityTypeId)
958
+ local abilities = self.abilities
959
+ for i = 1, #abilities do
960
+ if abilities[i].typeId == abilityTypeId then
961
+ local ability = abilities[i]
962
+ tremove(abilities, i)
963
+ ability:destroy()
964
+ return true
916
965
  end
917
- return true
918
966
  end
919
- return false
967
+ return doUnitAbilityAction(self.handle, abilityTypeId, unitRemoveAbility, abilityTypeId)
920
968
  end
921
969
  function Unit.prototype.hideAbility(self, abilityId, flag)
922
970
  BlzUnitHideAbility(self.handle, abilityId, flag)
@@ -930,12 +978,34 @@ end
930
978
  function Unit.prototype.endAbilityCooldown(self, abilityId)
931
979
  BlzEndUnitAbilityCooldown(self.handle, abilityId)
932
980
  end
981
+ function Unit.prototype.interruptMovement(self)
982
+ local handle = self.handle
983
+ unitDisableAbility(
984
+ handle,
985
+ fourCC("Amov"),
986
+ true,
987
+ false
988
+ )
989
+ unitDisableAbility(
990
+ handle,
991
+ fourCC("Amov"),
992
+ false,
993
+ false
994
+ )
995
+ end
933
996
  function Unit.prototype.interruptAttack(self)
934
997
  unitInterruptAttack(self.handle)
935
998
  end
936
999
  function Unit.prototype.interruptCast(self, abilityId)
937
- unitDisableAbility(self.handle, abilityId, true, false)
938
- unitDisableAbility(self.handle, abilityId, false, false)
1000
+ local handle = self.handle
1001
+ unitDisableAbility(handle, abilityId, true, false)
1002
+ Timer:run(
1003
+ unitDisableAbility,
1004
+ handle,
1005
+ abilityId,
1006
+ false,
1007
+ false
1008
+ )
939
1009
  end
940
1010
  function Unit.prototype.getDistanceTo(self, target)
941
1011
  local handle = self.handle
@@ -995,18 +1065,18 @@ function Unit.prototype.unpauseEx(self)
995
1065
  self:decrementStunCounter()
996
1066
  end
997
1067
  function Unit.prototype.incrementStunCounter(self)
998
- local stunCounter = self[101] or 0
999
- if not self[100] or stunCounter >= 0 then
1068
+ local stunCounter = self[102] or 0
1069
+ if not self[101] or stunCounter >= 0 then
1000
1070
  BlzPauseUnitEx(self.handle, true)
1001
1071
  end
1002
- self[101] = stunCounter + 1
1072
+ self[102] = stunCounter + 1
1003
1073
  end
1004
1074
  function Unit.prototype.decrementStunCounter(self)
1005
- local stunCounter = self[101] or 0
1006
- if not self[100] or stunCounter >= 1 then
1075
+ local stunCounter = self[102] or 0
1076
+ if not self[101] or stunCounter >= 1 then
1007
1077
  BlzPauseUnitEx(self.handle, false)
1008
1078
  end
1009
- self[101] = stunCounter - 1
1079
+ self[102] = stunCounter - 1
1010
1080
  end
1011
1081
  function Unit.create(self, owner, id, x, y, facing, skinId)
1012
1082
  local handle = skinId and BlzCreateUnitWithSkin(
@@ -1108,8 +1178,11 @@ function Unit.getInSector(self, pos, range, offsetAngle, centralAngle)
1108
1178
  )
1109
1179
  return targetCollection
1110
1180
  end
1111
- function Unit.getSelectionOf(self, player)
1112
- targetCollection = {}
1181
+ function Unit.getSelectionOf(self, player, target)
1182
+ if target == nil then
1183
+ target = {}
1184
+ end
1185
+ targetCollection = target
1113
1186
  targetCollectionNextIndex = 1
1114
1187
  GroupEnumUnitsSelected(dummyGroup, player.handle, collectIntoTarget)
1115
1188
  return targetCollection
@@ -1131,6 +1204,9 @@ end
1131
1204
  function Unit.prototype.__tostring(self)
1132
1205
  return (((self.constructor.name .. "$") .. util.id2s(self.typeId)) .. "@") .. tostring(getHandleId(self.handle))
1133
1206
  end
1207
+ function Unit.getBySyncId(self, syncId)
1208
+ return unitBySyncId[syncId]
1209
+ end
1134
1210
  __TS__SetDescriptor(
1135
1211
  Unit.prototype,
1136
1212
  "_deltas",
@@ -1190,7 +1266,15 @@ __TS__SetDescriptor(
1190
1266
  Unit.prototype,
1191
1267
  "isIllusion",
1192
1268
  {get = function(self)
1193
- return isUnitIllusion(self.handle)
1269
+ return IsUnitIllusion(self.handle)
1270
+ end},
1271
+ true
1272
+ )
1273
+ __TS__SetDescriptor(
1274
+ Unit.prototype,
1275
+ "isStunned",
1276
+ {get = function(self)
1277
+ return getUnitCurrentOrder(self.handle) == orderId("stunned")
1194
1278
  end},
1195
1279
  true
1196
1280
  )
@@ -1267,6 +1351,19 @@ __TS__SetDescriptor(
1267
1351
  },
1268
1352
  true
1269
1353
  )
1354
+ __TS__SetDescriptor(
1355
+ Unit.prototype,
1356
+ "primaryAttribute",
1357
+ {
1358
+ get = function(self)
1359
+ return getUnitIntegerField(self.handle, UNIT_IF_PRIMARY_ATTRIBUTE)
1360
+ end,
1361
+ set = function(self, primaryAttribute)
1362
+ setUnitIntegerField(self.handle, UNIT_IF_PRIMARY_ATTRIBUTE, primaryAttribute)
1363
+ end
1364
+ },
1365
+ true
1366
+ )
1270
1367
  __TS__SetDescriptor(
1271
1368
  Unit.prototype,
1272
1369
  "strengthBase",
@@ -1388,17 +1485,17 @@ __TS__SetDescriptor(
1388
1485
  "isTeamGlowVisible",
1389
1486
  {
1390
1487
  get = function(self)
1391
- return not self[105]
1488
+ return not self[106]
1392
1489
  end,
1393
1490
  set = function(self, isTeamGlowVisible)
1394
- showUnitTeamGlow(self.handle, isTeamGlowVisible)
1395
- local ____temp_5
1491
+ BlzShowUnitTeamGlow(self.handle, isTeamGlowVisible)
1492
+ local ____temp_7
1396
1493
  if not isTeamGlowVisible then
1397
- ____temp_5 = true
1494
+ ____temp_7 = true
1398
1495
  else
1399
- ____temp_5 = nil
1496
+ ____temp_7 = nil
1400
1497
  end
1401
- self[105] = ____temp_5
1498
+ self[106] = ____temp_7
1402
1499
  end
1403
1500
  },
1404
1501
  true
@@ -1407,9 +1504,9 @@ __TS__SetDescriptor(
1407
1504
  Unit.prototype,
1408
1505
  "color",
1409
1506
  {set = function(self, color)
1410
- setUnitColor(self.handle, color.handle)
1411
- if self[105] then
1412
- showUnitTeamGlow(self.handle, false)
1507
+ SetUnitColor(self.handle, color.handle)
1508
+ if self[106] then
1509
+ BlzShowUnitTeamGlow(self.handle, false)
1413
1510
  end
1414
1511
  end},
1415
1512
  true
@@ -1432,14 +1529,14 @@ __TS__SetDescriptor(
1432
1529
  "maxHealth",
1433
1530
  {
1434
1531
  get = function(self)
1435
- return BlzGetUnitMaxHP(self.handle) - (self[103] or 0) - (self[104] or 0)
1532
+ return BlzGetUnitMaxHP(self.handle) - (self[104] or 0) - (self[105] or 0)
1436
1533
  end,
1437
1534
  set = function(self, maxHealth)
1438
- if maxHealth < 1 and self[102] ~= nil then
1439
- self[103] = (self[103] or 0) + (1 - maxHealth)
1535
+ if maxHealth < 1 and self[103] ~= nil then
1536
+ self[104] = (self[104] or 0) + (1 - maxHealth)
1440
1537
  maxHealth = 1
1441
1538
  end
1442
- BlzSetUnitMaxHP(self.handle, maxHealth + (self[104] or 0))
1539
+ BlzSetUnitMaxHP(self.handle, maxHealth + (self[105] or 0))
1443
1540
  end
1444
1541
  },
1445
1542
  true
@@ -1481,10 +1578,10 @@ __TS__SetDescriptor(
1481
1578
  "health",
1482
1579
  {
1483
1580
  get = function(self)
1484
- return GetWidgetLife(self.handle) - (self[104] or 0)
1581
+ return GetWidgetLife(self.handle) - (self[105] or 0)
1485
1582
  end,
1486
1583
  set = function(self, health)
1487
- SetWidgetLife(self.handle, health + (self[104] or 0))
1584
+ SetWidgetLife(self.handle, health + (self[105] or 0))
1488
1585
  end
1489
1586
  },
1490
1587
  true
@@ -1578,7 +1675,7 @@ __TS__SetDescriptor(
1578
1675
  "x",
1579
1676
  {
1580
1677
  get = function(self)
1581
- return getUnitX(self.handle)
1678
+ return self[107] or getUnitX(self.handle)
1582
1679
  end,
1583
1680
  set = function(self, v)
1584
1681
  SetUnitX(self.handle, v)
@@ -1591,7 +1688,7 @@ __TS__SetDescriptor(
1591
1688
  "y",
1592
1689
  {
1593
1690
  get = function(self)
1594
- return getUnitY(self.handle)
1691
+ return self[108] or getUnitY(self.handle)
1595
1692
  end,
1596
1693
  set = function(self, v)
1597
1694
  SetUnitY(self.handle, v)
@@ -1677,10 +1774,10 @@ __TS__SetDescriptor(
1677
1774
  "gold",
1678
1775
  {
1679
1776
  get = function(self)
1680
- return getResourceAmount(self.handle)
1777
+ return GetResourceAmount(self.handle)
1681
1778
  end,
1682
1779
  set = function(self, gold)
1683
- setResourceAmount(self.handle, gold)
1780
+ SetResourceAmount(self.handle, gold)
1684
1781
  end
1685
1782
  },
1686
1783
  true
@@ -1695,17 +1792,17 @@ __TS__SetDescriptor(
1695
1792
  set = function(self, isPaused)
1696
1793
  local handle = self.handle
1697
1794
  if isPaused and not IsUnitPaused(handle) then
1698
- self[100] = true
1699
- for _ = self[101] or 0, -1 do
1795
+ self[101] = true
1796
+ for _ = self[102] or 0, -1 do
1700
1797
  BlzPauseUnitEx(handle, true)
1701
1798
  end
1702
1799
  PauseUnit(handle, true)
1703
1800
  elseif not isPaused and IsUnitPaused(handle) then
1704
1801
  PauseUnit(handle, false)
1705
- for _ = self[101] or 0, -1 do
1802
+ for _ = self[102] or 0, -1 do
1706
1803
  BlzPauseUnitEx(handle, false)
1707
1804
  end
1708
- self[100] = nil
1805
+ self[101] = nil
1709
1806
  end
1710
1807
  end
1711
1808
  },
@@ -1808,6 +1905,19 @@ __TS__SetDescriptor(
1808
1905
  end},
1809
1906
  true
1810
1907
  )
1908
+ __TS__SetDescriptor(
1909
+ Unit.prototype,
1910
+ "movementType",
1911
+ {
1912
+ get = function(self)
1913
+ return getUnitIntegerField(self.handle, UNIT_IF_MOVE_TYPE)
1914
+ end,
1915
+ set = function(self, movementType)
1916
+ setUnitIntegerField(self.handle, UNIT_IF_MOVE_TYPE, movementType)
1917
+ end
1918
+ },
1919
+ true
1920
+ )
1811
1921
  __TS__SetDescriptor(
1812
1922
  Unit.prototype,
1813
1923
  "pathing",
@@ -1989,6 +2099,14 @@ __TS__SetDescriptor(
1989
2099
  end},
1990
2100
  true
1991
2101
  )
2102
+ __TS__SetDescriptor(
2103
+ Unit.prototype,
2104
+ "targetAcquiredEvent",
2105
+ {get = function(self)
2106
+ return self:getEvent(EVENT_UNIT_ACQUIRED_TARGET)
2107
+ end},
2108
+ true
2109
+ )
1992
2110
  __TS__SetDescriptor(
1993
2111
  Unit.prototype,
1994
2112
  "onSelect",
@@ -2124,25 +2242,25 @@ Unit.onTargetCast = dispatchId(__TS__New(
2124
2242
  InitializingEvent,
2125
2243
  function(event)
2126
2244
  local function listener(unit, id)
2127
- local ____GetSpellTargetUnit_result_8
2245
+ local ____GetSpellTargetUnit_result_10
2128
2246
  if GetSpellTargetUnit() then
2129
- ____GetSpellTargetUnit_result_8 = ____exports.Unit:of(GetSpellTargetUnit())
2247
+ ____GetSpellTargetUnit_result_10 = ____exports.Unit:of(GetSpellTargetUnit())
2130
2248
  else
2131
- local ____GetSpellTargetItem_result_7
2249
+ local ____GetSpellTargetItem_result_9
2132
2250
  if GetSpellTargetItem() then
2133
- ____GetSpellTargetItem_result_7 = Item:of(GetSpellTargetItem())
2251
+ ____GetSpellTargetItem_result_9 = Item:of(GetSpellTargetItem())
2134
2252
  else
2135
- local ____GetSpellTargetDestructable_result_6
2253
+ local ____GetSpellTargetDestructable_result_8
2136
2254
  if GetSpellTargetDestructable() then
2137
- ____GetSpellTargetDestructable_result_6 = Destructable:of(GetSpellTargetDestructable())
2255
+ ____GetSpellTargetDestructable_result_8 = Destructable:of(GetSpellTargetDestructable())
2138
2256
  else
2139
- ____GetSpellTargetDestructable_result_6 = nil
2257
+ ____GetSpellTargetDestructable_result_8 = nil
2140
2258
  end
2141
- ____GetSpellTargetItem_result_7 = ____GetSpellTargetDestructable_result_6
2259
+ ____GetSpellTargetItem_result_9 = ____GetSpellTargetDestructable_result_8
2142
2260
  end
2143
- ____GetSpellTargetUnit_result_8 = ____GetSpellTargetItem_result_7
2261
+ ____GetSpellTargetUnit_result_10 = ____GetSpellTargetItem_result_9
2144
2262
  end
2145
- local target = ____GetSpellTargetUnit_result_8
2263
+ local target = ____GetSpellTargetUnit_result_10
2146
2264
  if target then
2147
2265
  invoke(event, unit, id, target)
2148
2266
  end
@@ -2314,10 +2432,12 @@ Unit.onImmediateOrder = dispatchId(__TS__New(
2314
2432
  ____exports.UnitTriggerEvent,
2315
2433
  EVENT_PLAYER_UNIT_ISSUED_ORDER,
2316
2434
  function()
2317
- local unit = ____exports.Unit:of(getOrderedUnit())
2318
- local issuedOrderId = getIssuedOrderId()
2319
- if unit ~= nil and unit.state == 1 then
2320
- return unit, issuedOrderId
2435
+ local handle = getOrderedUnit()
2436
+ if handle ~= nil and getUnitTypeId(handle) ~= dummyUnitId then
2437
+ local unit = ____exports.Unit:of(handle)
2438
+ if unit.state == 1 then
2439
+ return unit, getIssuedOrderId()
2440
+ end
2321
2441
  end
2322
2442
  return IgnoreEvent
2323
2443
  end
@@ -2348,38 +2468,57 @@ Unit.onDamaging = (function()
2348
2468
  if source and source.typeId == dummyUnitId then
2349
2469
  source = nil
2350
2470
  end
2351
- local target = BlzGetEventDamageTarget()
2471
+ local target = ____exports.Unit:of(BlzGetEventDamageTarget())
2472
+ local metadata = damageMetadataByTarget[target]
2473
+ damageMetadataByTarget[target] = nil
2352
2474
  local data = {
2353
2475
  amount = GetEventDamage(),
2354
- attackType = BlzGetEventAttackType(),
2476
+ attackType = nativeToAttackType(BlzGetEventAttackType()),
2355
2477
  damageType = BlzGetEventDamageType(),
2356
2478
  weaponType = BlzGetEventWeaponType(),
2357
- isAttack = BlzGetEventIsAttack()
2479
+ metadata = metadata,
2480
+ isAttack = BlzGetEventIsAttack(),
2481
+ originalAmount = GetEventDamage(),
2482
+ originalMetadata = metadata,
2483
+ preventRetaliation = damagingEventPreventRetaliation
2358
2484
  }
2359
2485
  if data.isAttack and source then
2360
- 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
2361
- if weapon == -1 then
2362
- local targetsAllowed = BlzGetUnitWeaponIntegerField(source.handle, UNIT_WEAPON_IF_ATTACK_TARGETS_ALLOWED, 0)
2363
- weapon = 0
2364
- end
2365
- data.weapon = assert(source.weapons[weapon + 1])
2486
+ data.weapon = source:chooseWeapon(target)
2366
2487
  end
2367
2488
  if not data.isAttack or not source or not source._attackHandlers then
2368
2489
  invoke(
2369
2490
  event,
2370
2491
  source,
2371
- ____exports.Unit:of(target),
2492
+ target,
2372
2493
  setmetatable(
2373
2494
  {},
2374
2495
  {
2375
2496
  __index = data,
2376
2497
  __newindex = function(self, key, value)
2377
- damageSetters[key](value)
2498
+ local damageSetter = damageSetters[key]
2499
+ if damageSetter ~= nil then
2500
+ damageSetter(value)
2501
+ end
2378
2502
  data[key] = value
2379
2503
  end
2380
2504
  }
2381
2505
  )
2382
2506
  )
2507
+ if data[0] and source then
2508
+ local sourceOwner = source.owner.handle
2509
+ data[1] = sourceOwner
2510
+ local targetOwner = target.owner.handle
2511
+ data[2] = targetOwner
2512
+ if not GetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE) then
2513
+ SetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE, true)
2514
+ data[3] = true
2515
+ end
2516
+ if not GetPlayerAlliance(targetOwner, sourceOwner, ALLIANCE_PASSIVE) then
2517
+ SetPlayerAlliance(targetOwner, sourceOwner, ALLIANCE_PASSIVE, true)
2518
+ data[4] = true
2519
+ end
2520
+ end
2521
+ damagingEventByTarget[target] = data
2383
2522
  return
2384
2523
  end
2385
2524
  BlzSetEventDamage(0)
@@ -2387,7 +2526,7 @@ Unit.onDamaging = (function()
2387
2526
  BlzSetEventDamageType(DAMAGE_TYPE_UNKNOWN)
2388
2527
  BlzSetEventWeaponType(WEAPON_TYPE_WHOKNOWS)
2389
2528
  local sourceOwner = source.owner.handle
2390
- local targetOwner = GetOwningPlayer(target)
2529
+ local targetOwner = target.owner.handle
2391
2530
  if not GetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE) then
2392
2531
  SetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE, true)
2393
2532
  Timer:run(function()
@@ -2403,23 +2542,19 @@ Unit.onDamaging = (function()
2403
2542
  for ____, ____value in ipairs(source._attackHandlers) do
2404
2543
  local condition = ____value[1]
2405
2544
  local action = ____value[2]
2406
- if condition(
2407
- source,
2408
- ____exports.Unit:of(target),
2409
- data
2410
- ) then
2545
+ if condition(source, target, data) then
2411
2546
  action(
2412
2547
  source,
2413
- ____exports.Unit:of(target),
2548
+ target,
2414
2549
  setmetatable(
2415
2550
  {fire = function()
2416
2551
  UnitDamageTarget(
2417
2552
  source.handle,
2418
- target,
2553
+ target.handle,
2419
2554
  data.amount,
2420
2555
  true,
2421
2556
  true,
2422
- data.attackType,
2557
+ attackTypeToNative(data.attackType),
2423
2558
  data.damageType,
2424
2559
  data.weaponType
2425
2560
  )
@@ -2446,29 +2581,54 @@ Unit.onDamage = __TS__New(
2446
2581
  if source and source.typeId == dummyUnitId then
2447
2582
  source = nil
2448
2583
  end
2584
+ local target = ____exports.Unit:of(BlzGetEventDamageTarget())
2585
+ local damagingEvent = damagingEventByTarget[target]
2586
+ damagingEventByTarget[target] = nil
2449
2587
  local data = {
2450
2588
  amount = GetEventDamage(),
2451
- attackType = BlzGetEventAttackType(),
2589
+ attackType = nativeToAttackType(BlzGetEventAttackType()),
2452
2590
  damageType = BlzGetEventDamageType(),
2453
2591
  weaponType = BlzGetEventWeaponType(),
2592
+ metadata = damagingEvent and damagingEvent.metadata,
2454
2593
  isAttack = BlzGetEventIsAttack(),
2594
+ originalAmount = damagingEvent and damagingEvent.originalAmount or GetEventDamage(),
2595
+ originalMetadata = damagingEvent and damagingEvent.originalMetadata,
2455
2596
  preventDeath = damageEventPreventDeath
2456
2597
  }
2598
+ if damagingEvent then
2599
+ for key, value in pairs(damagingEvent) do
2600
+ if isAttribute(key) then
2601
+ data[key] = value
2602
+ end
2603
+ end
2604
+ local sourceOwner = damagingEvent[1]
2605
+ if sourceOwner then
2606
+ local targetOwner = damagingEvent[2]
2607
+ if damagingEvent[3] then
2608
+ SetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE, false)
2609
+ end
2610
+ if damagingEvent[4] then
2611
+ SetPlayerAlliance(targetOwner, sourceOwner, ALLIANCE_PASSIVE, false)
2612
+ end
2613
+ end
2614
+ end
2457
2615
  local evData = setmetatable(
2458
2616
  {},
2459
2617
  {
2460
2618
  __index = data,
2461
2619
  __newindex = function(self, key, value)
2462
- damageSetters[key](value)
2620
+ local damageSetter = damageSetters[key]
2621
+ if damageSetter ~= nil then
2622
+ damageSetter(value)
2623
+ end
2463
2624
  data[key] = value
2464
2625
  end
2465
2626
  }
2466
2627
  )
2467
- local target = ____exports.Unit:of(BlzGetEventDamageTarget())
2468
2628
  invoke(event, source, target, evData)
2469
2629
  if evData[0] ~= nil and target.health - evData.amount < 0.405 then
2470
2630
  local bonusHealth = math.ceil(evData.amount)
2471
- target[104] = (target[104] or 0) + bonusHealth
2631
+ target[105] = (target[105] or 0) + bonusHealth
2472
2632
  BlzSetUnitMaxHP(
2473
2633
  target.handle,
2474
2634
  BlzGetUnitMaxHP(target.handle) + bonusHealth
@@ -2482,7 +2642,7 @@ Unit.onDamage = __TS__New(
2482
2642
  evData[0],
2483
2643
  table.unpack(evData, 1 + 1, 1 + (evData[1] or 0))
2484
2644
  )
2485
- target[104] = (target[104] or 0) - bonusHealth
2645
+ target[105] = (target[105] or 0) - bonusHealth
2486
2646
  SetWidgetLife(
2487
2647
  target.handle,
2488
2648
  GetWidgetLife(target.handle) - bonusHealth
@@ -2502,32 +2662,110 @@ Unit.onDamage = __TS__New(
2502
2662
  DestroyTrigger(trigger)
2503
2663
  end
2504
2664
  )
2505
- Unit.onItemDrop = __TS__New(
2665
+ Unit.itemDroppedEvent = __TS__New(
2506
2666
  ____exports.UnitTriggerEvent,
2507
2667
  EVENT_PLAYER_UNIT_DROP_ITEM,
2508
2668
  function()
2509
2669
  local unit = getTriggerUnit()
2510
- if getUnitTypeId(unit) ~= dummyUnitId then
2511
- return ____exports.Unit:of(unit), Item:of(getManipulatedItem())
2670
+ local item = getManipulatedItem()
2671
+ if getUnitTypeId(unit) ~= dummyUnitId and not (ignoreEventsItems[item] ~= nil) then
2672
+ return ____exports.Unit:of(unit), Item:of(item)
2512
2673
  end
2513
2674
  return IgnoreEvent
2514
2675
  end
2515
2676
  )
2516
- Unit.onItemPickup = __TS__New(
2677
+ Unit.itemPickedUpEvent = __TS__New(
2517
2678
  ____exports.UnitTriggerEvent,
2518
2679
  EVENT_PLAYER_UNIT_PICKUP_ITEM,
2519
2680
  function()
2520
- local unit = getTriggerUnit()
2521
- if getUnitTypeId(unit) ~= dummyUnitId then
2522
- return ____exports.Unit:of(unit), Item:of(getManipulatedItem())
2681
+ local unitHandle = getTriggerUnit()
2682
+ local itemHandle = getManipulatedItem()
2683
+ if getUnitTypeId(unitHandle) ~= dummyUnitId and not (ignoreEventsItems[itemHandle] ~= nil) then
2684
+ local unit = ____exports.Unit:of(unitHandle)
2685
+ local item = Item:of(itemHandle)
2686
+ if item.owner ~= unit then
2687
+ return unit, item
2688
+ end
2523
2689
  end
2524
2690
  return IgnoreEvent
2525
2691
  end
2526
2692
  )
2527
- Unit.onItemUse = __TS__New(
2693
+ Unit.itemUsedEvent = __TS__New(
2528
2694
  ____exports.UnitTriggerEvent,
2529
2695
  EVENT_PLAYER_UNIT_USE_ITEM,
2530
- function() return ____exports.Unit:of(GetTriggerUnit()), Item:of(GetManipulatedItem()) end
2696
+ function()
2697
+ local unit = getTriggerUnit()
2698
+ local item = getManipulatedItem()
2699
+ if getUnitTypeId(unit) ~= dummyUnitId and not (ignoreEventsItems[item] ~= nil) then
2700
+ return ____exports.Unit:of(unit), Item:of(item)
2701
+ end
2702
+ return IgnoreEvent
2703
+ end
2704
+ )
2705
+ Unit.itemStackedEvent = __TS__New(
2706
+ ____exports.UnitTriggerEvent,
2707
+ EVENT_PLAYER_UNIT_STACK_ITEM,
2708
+ function() return ____exports.Unit:of(getTriggerUnit()), Item:of(BlzGetStackingItemTarget()), Item:of(BlzGetStackingItemSource()) end
2709
+ )
2710
+ __TS__ObjectDefineProperty(
2711
+ Unit,
2712
+ "itemChargesChangedEvent",
2713
+ {get = function(self)
2714
+ local event = __TS__New(Event)
2715
+ Item.chargesChangedEvent:addListener(function(item)
2716
+ local unit = item.owner
2717
+ if unit ~= nil then
2718
+ invoke(event, unit, item)
2719
+ end
2720
+ end)
2721
+ rawset(self, "itemChargesChangedEvent", event)
2722
+ return event
2723
+ end}
2724
+ )
2725
+ __TS__ObjectDefineProperty(
2726
+ Unit,
2727
+ "itemUseOrderEvent",
2728
+ {get = function(self)
2729
+ local event = __TS__New(Event)
2730
+ for order = orderId("useslot0"), orderId("useslot5") do
2731
+ local slot = order - orderId("useslot0")
2732
+ local function listener(unit)
2733
+ local item = unit.items[slot + 1]
2734
+ if item ~= nil then
2735
+ invoke(event, unit, item)
2736
+ end
2737
+ end
2738
+ self.onImmediateOrder[order]:addListener(listener)
2739
+ self.onTargetOrder[order]:addListener(listener)
2740
+ self.onPointOrder[order]:addListener(listener)
2741
+ end
2742
+ rawset(self, "itemUseOrderEvent", event)
2743
+ return event
2744
+ end}
2745
+ )
2746
+ __TS__ObjectDefineProperty(
2747
+ Unit,
2748
+ "itemMoveOrderEvent",
2749
+ {get = function(self)
2750
+ local event = __TS__New(Event)
2751
+ for order = orderId("moveslot0"), orderId("moveslot5") do
2752
+ local slotTo = order - orderId("moveslot0")
2753
+ self.onTargetOrder[order]:addListener(function(unit, item)
2754
+ local slotFrom = unit.items:findSlot(item)
2755
+ if slotFrom ~= nil then
2756
+ invoke(
2757
+ event,
2758
+ unit,
2759
+ item,
2760
+ slotFrom,
2761
+ slotTo
2762
+ )
2763
+ end
2764
+ end)
2765
+ end
2766
+ rawset(self, "itemMoveOrderEvent", event)
2767
+ return event
2768
+ end}
2531
2769
  )
2532
2770
  __TS__ObjectDefineProperty(
2533
2771
  Unit,