warscript 0.0.1-dev.d842bb6 → 0.0.1-dev.da5fb2e

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 (153) hide show
  1. package/attributes.d.ts +5 -0
  2. package/attributes.lua +8 -1
  3. package/config.d.ts +5 -0
  4. package/config.lua +10 -0
  5. package/core/types/effect.d.ts +1 -3
  6. package/core/types/effect.lua +26 -29
  7. package/core/types/frame.lua +10 -12
  8. package/core/types/player.lua +3 -1
  9. package/core/types/playerCamera.d.ts +2 -0
  10. package/core/types/playerCamera.lua +79 -5
  11. package/core/types/sound.d.ts +17 -25
  12. package/core/types/sound.lua +91 -46
  13. package/core/types/timer.d.ts +8 -8
  14. package/core/types/timer.lua +39 -23
  15. package/core/util.lua +6 -1
  16. package/decl/native.d.ts +844 -788
  17. package/engine/behavior.d.ts +5 -0
  18. package/engine/behavior.lua +106 -27
  19. package/engine/behaviour/ability/apply-buff.lua +1 -1
  20. package/engine/behaviour/ability/apply-unit-behavior.lua +1 -0
  21. package/engine/behaviour/ability/damage.d.ts +9 -3
  22. package/engine/behaviour/ability/damage.lua +26 -38
  23. package/engine/behaviour/ability/emulate-impact.d.ts +1 -1
  24. package/engine/behaviour/ability/emulate-impact.lua +18 -3
  25. package/engine/behaviour/ability/restore-mana.d.ts +1 -1
  26. package/engine/behaviour/ability/restore-mana.lua +6 -6
  27. package/engine/behaviour/ability.d.ts +5 -1
  28. package/engine/behaviour/ability.lua +26 -21
  29. package/engine/behaviour/unit/stun-immunity.d.ts +5 -3
  30. package/engine/behaviour/unit/stun-immunity.lua +43 -27
  31. package/engine/behaviour/unit.d.ts +32 -0
  32. package/engine/behaviour/unit.lua +185 -4
  33. package/engine/buff.d.ts +15 -12
  34. package/engine/buff.lua +133 -117
  35. package/engine/internal/ability.d.ts +7 -1
  36. package/engine/internal/ability.lua +48 -9
  37. package/engine/internal/item/ability.lua +63 -11
  38. package/engine/internal/item+owner.lua +12 -6
  39. package/engine/internal/item.d.ts +5 -2
  40. package/engine/internal/item.lua +85 -10
  41. package/engine/internal/mechanics/ability-duration.lua +1 -1
  42. package/engine/internal/misc/damage-metadata-by-target.d.ts +2 -0
  43. package/engine/internal/misc/damage-metadata-by-target.lua +5 -0
  44. package/engine/internal/misc/frame-coordinates.d.ts +2 -0
  45. package/engine/internal/misc/frame-coordinates.lua +21 -0
  46. package/engine/internal/misc/get-terrain-z.d.ts +2 -0
  47. package/engine/internal/misc/get-terrain-z.lua +11 -0
  48. package/engine/internal/misc/player-local-handle.d.ts +2 -0
  49. package/engine/internal/misc/player-local-handle.lua +5 -0
  50. package/engine/internal/unit/ability.d.ts +35 -0
  51. package/engine/internal/unit/ability.lua +62 -0
  52. package/engine/internal/unit/allowed-targets.d.ts +1 -1
  53. package/engine/internal/unit/allowed-targets.lua +9 -1
  54. package/engine/internal/unit/order.d.ts +20 -0
  55. package/engine/internal/unit/order.lua +136 -0
  56. package/engine/internal/unit+ability.lua +10 -1
  57. package/engine/internal/unit+damage.d.ts +2 -11
  58. package/engine/internal/unit+damage.lua +10 -14
  59. package/engine/internal/unit+spellSteal.lua +1 -2
  60. package/engine/internal/unit-missile-launch.lua +9 -2
  61. package/engine/internal/unit.d.ts +30 -8
  62. package/engine/internal/unit.lua +253 -107
  63. package/engine/object-data/auxiliary/armor-type.d.ts +11 -0
  64. package/engine/object-data/auxiliary/armor-type.lua +46 -0
  65. package/engine/object-data/auxiliary/attachment-preset.d.ts +7 -2
  66. package/engine/object-data/auxiliary/attachment-preset.lua +4 -3
  67. package/engine/object-data/auxiliary/attack-type.d.ts +7 -8
  68. package/engine/object-data/auxiliary/attack-type.lua +42 -0
  69. package/engine/object-data/auxiliary/movement-type.d.ts +7 -7
  70. package/engine/object-data/auxiliary/movement-type.lua +22 -0
  71. package/engine/object-data/auxiliary/sound-eax.d.ts +10 -0
  72. package/engine/object-data/auxiliary/sound-eax.lua +2 -0
  73. package/engine/object-data/auxiliary/tech-tree-dependency.d.ts +1 -1
  74. package/engine/object-data/auxiliary/unit-attribute.d.ts +6 -0
  75. package/engine/object-data/auxiliary/unit-attribute.lua +9 -0
  76. package/engine/object-data/entry/ability-type/berserk.d.ts +2 -0
  77. package/engine/object-data/entry/ability-type/berserk.lua +13 -0
  78. package/engine/object-data/entry/ability-type/blank-configurable.lua +0 -9
  79. package/engine/object-data/entry/ability-type/carrion-swarm.d.ts +14 -0
  80. package/engine/object-data/entry/ability-type/carrion-swarm.lua +65 -0
  81. package/engine/object-data/entry/ability-type/curse.lua +2 -2
  82. package/engine/object-data/entry/ability-type/disease-cloud.lua +2 -2
  83. package/engine/object-data/entry/ability-type/engineering-upgrade.lua +2 -2
  84. package/engine/object-data/entry/ability-type/ensnare.d.ts +12 -0
  85. package/engine/object-data/entry/ability-type/ensnare.lua +52 -0
  86. package/engine/object-data/entry/ability-type/feral-spirit.lua +2 -2
  87. package/engine/object-data/entry/ability-type/permanent-invisibility.d.ts +8 -0
  88. package/engine/object-data/entry/ability-type/permanent-invisibility.lua +26 -0
  89. package/engine/object-data/entry/ability-type/phase-shift.d.ts +10 -0
  90. package/engine/object-data/entry/ability-type/phase-shift.lua +39 -0
  91. package/engine/object-data/entry/ability-type/phoenix-morph.lua +4 -4
  92. package/engine/object-data/entry/ability-type/raise-dead.d.ts +17 -0
  93. package/engine/object-data/entry/ability-type/raise-dead.lua +78 -0
  94. package/engine/object-data/entry/ability-type/shock-wave.d.ts +4 -0
  95. package/engine/object-data/entry/ability-type/shock-wave.lua +26 -0
  96. package/engine/object-data/entry/ability-type/slow-poison.d.ts +10 -0
  97. package/engine/object-data/entry/ability-type/slow-poison.lua +58 -0
  98. package/engine/object-data/entry/ability-type/summon-quilbeast.lua +2 -2
  99. package/engine/object-data/entry/ability-type/summon-water-elemental.lua +2 -2
  100. package/engine/object-data/entry/ability-type/web.d.ts +12 -0
  101. package/engine/object-data/entry/ability-type/web.lua +52 -0
  102. package/engine/object-data/entry/ability-type.d.ts +19 -17
  103. package/engine/object-data/entry/ability-type.lua +82 -24
  104. package/engine/object-data/entry/buff-type/applicable.lua +9 -4
  105. package/engine/object-data/entry/buff-type.d.ts +6 -12
  106. package/engine/object-data/entry/buff-type.lua +13 -29
  107. package/engine/object-data/entry/destructible-type.d.ts +1 -1
  108. package/engine/object-data/entry/item-type.d.ts +1 -1
  109. package/engine/object-data/entry/item-type.lua +4 -4
  110. package/engine/object-data/entry/lightning-type.d.ts +1 -1
  111. package/engine/object-data/entry/sound-preset.d.ts +33 -0
  112. package/engine/object-data/entry/sound-preset.lua +140 -0
  113. package/engine/object-data/entry/unit-type.d.ts +21 -5
  114. package/engine/object-data/entry/unit-type.lua +214 -93
  115. package/engine/object-data/entry/upgrade.d.ts +1 -1
  116. package/engine/object-data/entry/upgrade.lua +4 -4
  117. package/engine/object-data/entry.d.ts +16 -14
  118. package/engine/object-data/entry.lua +60 -32
  119. package/engine/object-field/ability.d.ts +4 -4
  120. package/engine/object-field/ability.lua +7 -6
  121. package/engine/object-field/unit.d.ts +57 -3
  122. package/engine/object-field/unit.lua +207 -7
  123. package/engine/object-field.d.ts +17 -6
  124. package/engine/object-field.lua +188 -92
  125. package/engine/standard/entries/buff-type.d.ts +3 -0
  126. package/engine/standard/entries/buff-type.lua +3 -0
  127. package/engine/standard/entries/sound-preset.d.ts +10 -0
  128. package/engine/standard/entries/sound-preset.lua +10 -0
  129. package/engine/standard/fields/unit.d.ts +4 -0
  130. package/engine/standard/fields/unit.lua +7 -0
  131. package/engine/text-tag.d.ts +36 -2
  132. package/engine/text-tag.lua +249 -10
  133. package/engine/unit.d.ts +1 -0
  134. package/engine/unit.lua +1 -0
  135. package/objutil/buff.lua +1 -2
  136. package/objutil/unit.lua +8 -0
  137. package/package.json +2 -2
  138. package/patch-lualib.lua +1 -1
  139. package/utility/arrays.d.ts +1 -0
  140. package/utility/arrays.lua +3 -0
  141. package/utility/callback-array.d.ts +13 -0
  142. package/utility/callback-array.lua +46 -0
  143. package/utility/functions.d.ts +8 -0
  144. package/utility/functions.lua +13 -0
  145. package/utility/linked-set.d.ts +1 -0
  146. package/utility/linked-set.lua +3 -0
  147. package/utility/lua-maps.d.ts +4 -0
  148. package/utility/lua-maps.lua +20 -0
  149. package/utility/lua-sets.d.ts +2 -0
  150. package/utility/lua-sets.lua +7 -0
  151. package/utility/reflection.lua +11 -7
  152. package/core/types/order.d.ts +0 -25
  153. package/core/types/order.lua +0 -55
@@ -53,12 +53,19 @@ 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
56
65
  local match = string.match
57
66
  local ____tostring = _G.tostring
58
67
  local setUnitAnimation = SetUnitAnimation
59
- local setUnitAnimationWithRarity = SetUnitAnimationWithRarity
60
68
  local setUnitAnimationByIndex = SetUnitAnimationByIndex
61
- local queueUnitAnimation = QueueUnitAnimation
62
69
  local getUnitIntegerField = BlzGetUnitIntegerField
63
70
  local getUnitRealField = BlzGetUnitRealField
64
71
  local getHeroStr = GetHeroStr
@@ -80,7 +87,6 @@ local getHandleId = GetHandleId
80
87
  local getUnitCurrentOrder = GetUnitCurrentOrder
81
88
  local createUnit = CreateUnit
82
89
  local killUnit = KillUnit
83
- local setUnitExploded = SetUnitExploded
84
90
  local removeUnit = RemoveUnit
85
91
  local getUnitTypeId = GetUnitTypeId
86
92
  local isHeroUnitId = IsHeroUnitId
@@ -96,8 +102,6 @@ local getSpellTargetItem = GetSpellTargetItem
96
102
  local getSpellTargetDestructable = GetSpellTargetDestructable
97
103
  local isUnitInRangeXY = IsUnitInRangeXY
98
104
  local isUnitInRange = IsUnitInRange
99
- local setResourceAmount = SetResourceAmount
100
- local getResourceAmount = GetResourceAmount
101
105
  local getUnitWeaponRealField = BlzGetUnitWeaponRealField
102
106
  local setUnitWeaponRealField = BlzSetUnitWeaponRealField
103
107
  local getUnitWeaponStringField = BlzGetUnitWeaponStringField
@@ -121,15 +125,9 @@ local getOrderedUnit = GetOrderedUnit
121
125
  local getIssuedOrderId = GetIssuedOrderId
122
126
  local isUnitInvulnerable = BlzIsUnitInvulnerable
123
127
  local unitAlive = UnitAlive
124
- local unitAddType = UnitAddType
125
- local unitRemoveType = UnitRemoveType
126
- local isUnitIllusion = IsUnitIllusion
127
- local isUnitType = IsUnitType
128
128
  local isUnitAlly = IsUnitAlly
129
129
  local isUnitEnemy = IsUnitEnemy
130
130
  local getOwningPlayer = GetOwningPlayer
131
- local setUnitColor = SetUnitColor
132
- local showUnitTeamGlow = BlzShowUnitTeamGlow
133
131
  ____exports.UnitClassification = {}
134
132
  local UnitClassification = ____exports.UnitClassification
135
133
  do
@@ -139,6 +137,7 @@ do
139
137
  UnitClassification.GROUND = UNIT_TYPE_GROUND
140
138
  UnitClassification.SUMMONED = UNIT_TYPE_SUMMONED
141
139
  UnitClassification.MECHANICAL = UNIT_TYPE_MECHANICAL
140
+ UnitClassification.WORKER = UNIT_TYPE_PEON
142
141
  UnitClassification.ANCIENT = UNIT_TYPE_ANCIENT
143
142
  UnitClassification.SUICIDAL = UNIT_TYPE_SAPPER
144
143
  UnitClassification.TAUREN = UNIT_TYPE_TAUREN
@@ -346,6 +345,9 @@ local function dispatchAbility(event)
346
345
  }
347
346
  )
348
347
  end
348
+ local function damagingEventPreventRetaliation(self)
349
+ self[0] = true
350
+ end
349
351
  local function damageEventPreventDeath(self, callback, ...)
350
352
  if self[0] ~= nil then
351
353
  return
@@ -357,7 +359,14 @@ local function damageEventPreventDeath(self, callback, ...)
357
359
  rawset(self, 1 + i, (select(i, ...)))
358
360
  end
359
361
  end
360
- 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
+ }
361
370
  local jlimitopByOperator = {
362
371
  [0] = LESS_THAN_OR_EQUAL,
363
372
  [1] = LESS_THAN_OR_EQUAL,
@@ -435,6 +444,19 @@ __TS__SetDescriptor(
435
444
  },
436
445
  true
437
446
  )
447
+ __TS__SetDescriptor(
448
+ UnitWeapon.prototype,
449
+ "allowedTargetCombatClassifications",
450
+ {
451
+ get = function(self)
452
+ return BlzGetUnitWeaponIntegerField(self.unit.handle, UNIT_WEAPON_IF_ATTACK_TARGETS_ALLOWED, self.index)
453
+ end,
454
+ set = function(self, allowedTargetCombatClassifications)
455
+ BlzSetUnitWeaponIntegerField(self.unit.handle, UNIT_WEAPON_IF_ATTACK_TARGETS_ALLOWED, self.index, allowedTargetCombatClassifications)
456
+ end
457
+ },
458
+ true
459
+ )
438
460
  __TS__SetDescriptor(
439
461
  UnitWeapon.prototype,
440
462
  "damageBase",
@@ -639,16 +661,26 @@ local function delayHealthChecksCallback(unit)
639
661
  end
640
662
  end
641
663
  local nextSyncId = 1
642
- local unitBySyncId = setmetatable({}, {__mode = "k"})
664
+ local unitBySyncId = setmetatable({}, {__mode = "v"})
665
+ local damagingEventByTarget = setmetatable({}, {__mode = "k"})
666
+ local function addAbility(unit, abilityTypeId)
667
+ local ____unitAddAbility_result_0
668
+ if unitAddAbility(unit, abilityTypeId) then
669
+ ____unitAddAbility_result_0 = getUnitAbility(unit, abilityTypeId)
670
+ else
671
+ ____unitAddAbility_result_0 = nil
672
+ end
673
+ return ____unitAddAbility_result_0
674
+ end
643
675
  ____exports.Unit = __TS__Class()
644
676
  local Unit = ____exports.Unit
645
677
  Unit.name = "Unit"
646
678
  __TS__ClassExtends(Unit, Handle)
647
679
  function Unit.prototype.____constructor(self, handle)
648
680
  Handle.prototype.____constructor(self, handle)
649
- local ____nextSyncId_0 = nextSyncId
650
- nextSyncId = ____nextSyncId_0 + 1
651
- self.syncId = ____nextSyncId_0
681
+ local ____nextSyncId_1 = nextSyncId
682
+ nextSyncId = ____nextSyncId_1 + 1
683
+ self.syncId = ____nextSyncId_1
652
684
  self._owner = Player:of(getOwningPlayer(handle))
653
685
  assert(unitAddAbility(handle, leaveDetectAbilityId) and UnitMakeAbilityPermanent(handle, true, leaveDetectAbilityId))
654
686
  assert(unitAddAbility(handle, morphDetectAbilityId))
@@ -680,6 +712,8 @@ function Unit.prototype.getEvent(self, event, collector)
680
712
  end
681
713
  function Unit.prototype.onDestroy(self)
682
714
  local handle = self.handle
715
+ self[107] = getUnitX(handle)
716
+ self[108] = getUnitY(handle)
683
717
  if not self._owner then
684
718
  self._owner = Player:of(getOwningPlayer(handle))
685
719
  end
@@ -747,17 +781,17 @@ function Unit.prototype.addModifier(self, property, modifier)
747
781
  end}
748
782
  end
749
783
  function Unit.prototype.hasCombatClassification(self, combatClassification)
750
- local ____combatClassification_1 = combatClassification
751
- return getUnitIntegerField(self.handle, UNIT_IF_TARGETED_AS) & ____combatClassification_1 == ____combatClassification_1
784
+ local ____combatClassification_2 = combatClassification
785
+ return getUnitIntegerField(self.handle, UNIT_IF_TARGETED_AS) & ____combatClassification_2 == ____combatClassification_2
752
786
  end
753
787
  function Unit.prototype.addClassification(self, classification)
754
- return unitAddType(self.handle, classification)
788
+ return UnitAddType(self.handle, classification)
755
789
  end
756
790
  function Unit.prototype.removeClassification(self, classification)
757
- return unitRemoveType(self.handle, classification)
791
+ return UnitRemoveType(self.handle, classification)
758
792
  end
759
793
  function Unit.prototype.hasClassification(self, classification)
760
- return isUnitType(self.handle, classification)
794
+ return IsUnitType(self.handle, classification)
761
795
  end
762
796
  function Unit.prototype.isVisibleTo(self, player)
763
797
  return isUnitVisible(self.handle, player.handle)
@@ -766,13 +800,13 @@ function Unit.prototype.isInvisibleTo(self, player)
766
800
  return isUnitInvisible(self.handle, player.handle)
767
801
  end
768
802
  function Unit.prototype.isInRangeOf(self, x, y, range)
769
- local ____temp_2
803
+ local ____temp_3
770
804
  if type(x) == "number" then
771
- ____temp_2 = isUnitInRangeXY(self.handle, x, y, range)
805
+ ____temp_3 = isUnitInRangeXY(self.handle, x, y, range)
772
806
  else
773
- ____temp_2 = isUnitInRange(self.handle, x.handle, y)
807
+ ____temp_3 = isUnitInRange(self.handle, x.handle, y)
774
808
  end
775
- return ____temp_2
809
+ return ____temp_3
776
810
  end
777
811
  function Unit.prototype.isAllyOf(self, unit)
778
812
  return isUnitAlly(
@@ -790,13 +824,25 @@ function Unit.prototype.playAnimation(self, animation, rarity)
790
824
  if type(animation) == "number" then
791
825
  setUnitAnimationByIndex(self.handle, animation)
792
826
  elseif rarity then
793
- setUnitAnimationWithRarity(self.handle, animation, rarity)
827
+ SetUnitAnimationWithRarity(self.handle, animation, rarity)
794
828
  else
795
829
  setUnitAnimation(self.handle, animation)
796
830
  end
797
831
  end
832
+ function Unit.prototype.resetAnimation(self)
833
+ ResetUnitAnimation(self.handle)
834
+ end
798
835
  function Unit.prototype.queueAnimation(self, animation)
799
- queueUnitAnimation(self.handle, animation)
836
+ QueueUnitAnimation(self.handle, animation)
837
+ end
838
+ function Unit.prototype.chooseWeapon(self, target)
839
+ if target:isAllowedTarget(self, self.firstWeapon.allowedTargetCombatClassifications) then
840
+ return self.firstWeapon
841
+ end
842
+ if target:isAllowedTarget(target, self.secondWeapon.allowedTargetCombatClassifications) then
843
+ return self.secondWeapon
844
+ end
845
+ return nil
800
846
  end
801
847
  function Unit.prototype.delayHealthChecks(self)
802
848
  self[103] = (self[103] or 0) + 1
@@ -809,21 +855,21 @@ function Unit.prototype.isSelected(self, player)
809
855
  return IsUnitSelected(self.handle, player.handle)
810
856
  end
811
857
  function Unit.prototype.explode(self)
812
- setUnitExploded(self.handle, true)
858
+ SetUnitExploded(self.handle, true)
813
859
  killUnit(self.handle)
814
860
  end
815
861
  function Unit.prototype.kill(self)
816
862
  killUnit(self.handle)
817
863
  end
818
864
  function Unit.prototype.revive(self, x, y, doEffect)
819
- local ____ReviveHero_5 = ReviveHero
820
- local ____array_4 = __TS__SparseArrayNew(self.handle, x, y)
821
- local ____doEffect_3 = doEffect
822
- if ____doEffect_3 == nil then
823
- ____doEffect_3 = false
865
+ local ____ReviveHero_6 = ReviveHero
866
+ local ____array_5 = __TS__SparseArrayNew(self.handle, x, y)
867
+ local ____doEffect_4 = doEffect
868
+ if ____doEffect_4 == nil then
869
+ ____doEffect_4 = false
824
870
  end
825
- __TS__SparseArrayPush(____array_4, ____doEffect_3)
826
- ____ReviveHero_5(__TS__SparseArraySpread(____array_4))
871
+ __TS__SparseArrayPush(____array_5, ____doEffect_4)
872
+ ____ReviveHero_6(__TS__SparseArraySpread(____array_5))
827
873
  end
828
874
  function Unit.prototype.healTarget(self, target, amount)
829
875
  if __TS__InstanceOf(target, ____exports.Unit) and target:hasAbility(fourCC("BIhm")) then
@@ -866,17 +912,16 @@ function Unit.prototype.itemInSlot(self, slot)
866
912
  return Item:of(unitItemInSlot(self.handle, slot))
867
913
  end
868
914
  function Unit.prototype.addAbility(self, abilityId)
869
- if unitAddAbility(self.handle, abilityId) then
870
- local ability = UnitAbility:of(
871
- checkNotNull(getUnitAbility(self.handle, abilityId)),
872
- abilityId,
873
- self
874
- )
915
+ local ability = UnitAbility:of(
916
+ doUnitAbilityAction(self.handle, abilityId, addAbility, abilityId),
917
+ abilityId,
918
+ self
919
+ )
920
+ if ability ~= nil then
875
921
  local abilities = self.abilities
876
922
  abilities[#abilities + 1] = ability
877
- return ability
878
923
  end
879
- return nil
924
+ return ability
880
925
  end
881
926
  function Unit.prototype.makeAbilityPermanent(self, abilityId, permanent)
882
927
  return UnitMakeAbilityPermanent(self.handle, permanent, abilityId)
@@ -891,28 +936,17 @@ function Unit.prototype.hasAbility(self, abilityId)
891
936
  return getUnitAbilityLevel(self.handle, abilityId) > 0
892
937
  end
893
938
  function Unit.prototype.getAbilityById(self, abilityId)
894
- local handle = self.handle
895
- if unitAddAbility(handle, abilityId) then
896
- assert(unitRemoveAbility(handle, abilityId))
897
- return nil
898
- end
899
- return UnitAbility:of(
900
- getUnitAbility(self.handle, abilityId),
901
- abilityId,
902
- self
903
- )
939
+ local ability = doUnitAbilityAction(self.handle, abilityId, getUnitAbility, abilityId)
940
+ return UnitAbility:of(ability, abilityId, self)
904
941
  end
905
942
  function Unit.prototype.removeAbility(self, abilityId)
906
- if unitRemoveAbility(self.handle, abilityId) then
907
- local abilities = self.abilities
908
- for i = 1, #abilities do
909
- if abilities[i].typeId == abilityId then
910
- abilities[i]:destroy()
911
- tremove(abilities, i)
912
- return true
913
- end
943
+ local abilities = self.abilities
944
+ for i = 1, #abilities do
945
+ if abilities[i].typeId == abilityId then
946
+ abilities[i]:destroy()
947
+ tremove(abilities, i)
948
+ return true
914
949
  end
915
- return true
916
950
  end
917
951
  return false
918
952
  end
@@ -928,6 +962,21 @@ end
928
962
  function Unit.prototype.endAbilityCooldown(self, abilityId)
929
963
  BlzEndUnitAbilityCooldown(self.handle, abilityId)
930
964
  end
965
+ function Unit.prototype.interruptMovement(self)
966
+ local handle = self.handle
967
+ unitDisableAbility(
968
+ handle,
969
+ fourCC("Amov"),
970
+ true,
971
+ false
972
+ )
973
+ unitDisableAbility(
974
+ handle,
975
+ fourCC("Amov"),
976
+ false,
977
+ false
978
+ )
979
+ end
931
980
  function Unit.prototype.interruptAttack(self)
932
981
  unitInterruptAttack(self.handle)
933
982
  end
@@ -1201,7 +1250,7 @@ __TS__SetDescriptor(
1201
1250
  Unit.prototype,
1202
1251
  "isIllusion",
1203
1252
  {get = function(self)
1204
- return isUnitIllusion(self.handle)
1253
+ return IsUnitIllusion(self.handle)
1205
1254
  end},
1206
1255
  true
1207
1256
  )
@@ -1286,6 +1335,19 @@ __TS__SetDescriptor(
1286
1335
  },
1287
1336
  true
1288
1337
  )
1338
+ __TS__SetDescriptor(
1339
+ Unit.prototype,
1340
+ "primaryAttribute",
1341
+ {
1342
+ get = function(self)
1343
+ return getUnitIntegerField(self.handle, UNIT_IF_PRIMARY_ATTRIBUTE)
1344
+ end,
1345
+ set = function(self, primaryAttribute)
1346
+ setUnitIntegerField(self.handle, UNIT_IF_PRIMARY_ATTRIBUTE, primaryAttribute)
1347
+ end
1348
+ },
1349
+ true
1350
+ )
1289
1351
  __TS__SetDescriptor(
1290
1352
  Unit.prototype,
1291
1353
  "strengthBase",
@@ -1410,14 +1472,14 @@ __TS__SetDescriptor(
1410
1472
  return not self[106]
1411
1473
  end,
1412
1474
  set = function(self, isTeamGlowVisible)
1413
- showUnitTeamGlow(self.handle, isTeamGlowVisible)
1414
- local ____temp_6
1475
+ BlzShowUnitTeamGlow(self.handle, isTeamGlowVisible)
1476
+ local ____temp_7
1415
1477
  if not isTeamGlowVisible then
1416
- ____temp_6 = true
1478
+ ____temp_7 = true
1417
1479
  else
1418
- ____temp_6 = nil
1480
+ ____temp_7 = nil
1419
1481
  end
1420
- self[106] = ____temp_6
1482
+ self[106] = ____temp_7
1421
1483
  end
1422
1484
  },
1423
1485
  true
@@ -1426,9 +1488,9 @@ __TS__SetDescriptor(
1426
1488
  Unit.prototype,
1427
1489
  "color",
1428
1490
  {set = function(self, color)
1429
- setUnitColor(self.handle, color.handle)
1491
+ SetUnitColor(self.handle, color.handle)
1430
1492
  if self[106] then
1431
- showUnitTeamGlow(self.handle, false)
1493
+ BlzShowUnitTeamGlow(self.handle, false)
1432
1494
  end
1433
1495
  end},
1434
1496
  true
@@ -1597,7 +1659,7 @@ __TS__SetDescriptor(
1597
1659
  "x",
1598
1660
  {
1599
1661
  get = function(self)
1600
- return getUnitX(self.handle)
1662
+ return self[107] or getUnitX(self.handle)
1601
1663
  end,
1602
1664
  set = function(self, v)
1603
1665
  SetUnitX(self.handle, v)
@@ -1610,7 +1672,7 @@ __TS__SetDescriptor(
1610
1672
  "y",
1611
1673
  {
1612
1674
  get = function(self)
1613
- return getUnitY(self.handle)
1675
+ return self[108] or getUnitY(self.handle)
1614
1676
  end,
1615
1677
  set = function(self, v)
1616
1678
  SetUnitY(self.handle, v)
@@ -1696,10 +1758,10 @@ __TS__SetDescriptor(
1696
1758
  "gold",
1697
1759
  {
1698
1760
  get = function(self)
1699
- return getResourceAmount(self.handle)
1761
+ return GetResourceAmount(self.handle)
1700
1762
  end,
1701
1763
  set = function(self, gold)
1702
- setResourceAmount(self.handle, gold)
1764
+ SetResourceAmount(self.handle, gold)
1703
1765
  end
1704
1766
  },
1705
1767
  true
@@ -1827,6 +1889,19 @@ __TS__SetDescriptor(
1827
1889
  end},
1828
1890
  true
1829
1891
  )
1892
+ __TS__SetDescriptor(
1893
+ Unit.prototype,
1894
+ "movementType",
1895
+ {
1896
+ get = function(self)
1897
+ return getUnitIntegerField(self.handle, UNIT_IF_MOVE_TYPE)
1898
+ end,
1899
+ set = function(self, movementType)
1900
+ setUnitIntegerField(self.handle, UNIT_IF_MOVE_TYPE, movementType)
1901
+ end
1902
+ },
1903
+ true
1904
+ )
1830
1905
  __TS__SetDescriptor(
1831
1906
  Unit.prototype,
1832
1907
  "pathing",
@@ -2008,6 +2083,14 @@ __TS__SetDescriptor(
2008
2083
  end},
2009
2084
  true
2010
2085
  )
2086
+ __TS__SetDescriptor(
2087
+ Unit.prototype,
2088
+ "targetAcquiredEvent",
2089
+ {get = function(self)
2090
+ return self:getEvent(EVENT_UNIT_ACQUIRED_TARGET)
2091
+ end},
2092
+ true
2093
+ )
2011
2094
  __TS__SetDescriptor(
2012
2095
  Unit.prototype,
2013
2096
  "onSelect",
@@ -2143,25 +2226,25 @@ Unit.onTargetCast = dispatchId(__TS__New(
2143
2226
  InitializingEvent,
2144
2227
  function(event)
2145
2228
  local function listener(unit, id)
2146
- local ____GetSpellTargetUnit_result_9
2229
+ local ____GetSpellTargetUnit_result_10
2147
2230
  if GetSpellTargetUnit() then
2148
- ____GetSpellTargetUnit_result_9 = ____exports.Unit:of(GetSpellTargetUnit())
2231
+ ____GetSpellTargetUnit_result_10 = ____exports.Unit:of(GetSpellTargetUnit())
2149
2232
  else
2150
- local ____GetSpellTargetItem_result_8
2233
+ local ____GetSpellTargetItem_result_9
2151
2234
  if GetSpellTargetItem() then
2152
- ____GetSpellTargetItem_result_8 = Item:of(GetSpellTargetItem())
2235
+ ____GetSpellTargetItem_result_9 = Item:of(GetSpellTargetItem())
2153
2236
  else
2154
- local ____GetSpellTargetDestructable_result_7
2237
+ local ____GetSpellTargetDestructable_result_8
2155
2238
  if GetSpellTargetDestructable() then
2156
- ____GetSpellTargetDestructable_result_7 = Destructable:of(GetSpellTargetDestructable())
2239
+ ____GetSpellTargetDestructable_result_8 = Destructable:of(GetSpellTargetDestructable())
2157
2240
  else
2158
- ____GetSpellTargetDestructable_result_7 = nil
2241
+ ____GetSpellTargetDestructable_result_8 = nil
2159
2242
  end
2160
- ____GetSpellTargetItem_result_8 = ____GetSpellTargetDestructable_result_7
2243
+ ____GetSpellTargetItem_result_9 = ____GetSpellTargetDestructable_result_8
2161
2244
  end
2162
- ____GetSpellTargetUnit_result_9 = ____GetSpellTargetItem_result_8
2245
+ ____GetSpellTargetUnit_result_10 = ____GetSpellTargetItem_result_9
2163
2246
  end
2164
- local target = ____GetSpellTargetUnit_result_9
2247
+ local target = ____GetSpellTargetUnit_result_10
2165
2248
  if target then
2166
2249
  invoke(event, unit, id, target)
2167
2250
  end
@@ -2369,13 +2452,19 @@ Unit.onDamaging = (function()
2369
2452
  if source and source.typeId == dummyUnitId then
2370
2453
  source = nil
2371
2454
  end
2372
- local target = BlzGetEventDamageTarget()
2455
+ local target = ____exports.Unit:of(BlzGetEventDamageTarget())
2456
+ local metadata = damageMetadataByTarget[target]
2457
+ damageMetadataByTarget[target] = nil
2373
2458
  local data = {
2374
2459
  amount = GetEventDamage(),
2375
- attackType = BlzGetEventAttackType(),
2460
+ attackType = nativeToAttackType(BlzGetEventAttackType()),
2376
2461
  damageType = BlzGetEventDamageType(),
2377
2462
  weaponType = BlzGetEventWeaponType(),
2378
- isAttack = BlzGetEventIsAttack()
2463
+ metadata = metadata,
2464
+ isAttack = BlzGetEventIsAttack(),
2465
+ originalAmount = GetEventDamage(),
2466
+ originalMetadata = metadata,
2467
+ preventRetaliation = damagingEventPreventRetaliation
2379
2468
  }
2380
2469
  if data.isAttack and source then
2381
2470
  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
@@ -2389,18 +2478,36 @@ Unit.onDamaging = (function()
2389
2478
  invoke(
2390
2479
  event,
2391
2480
  source,
2392
- ____exports.Unit:of(target),
2481
+ target,
2393
2482
  setmetatable(
2394
2483
  {},
2395
2484
  {
2396
2485
  __index = data,
2397
2486
  __newindex = function(self, key, value)
2398
- damageSetters[key](value)
2487
+ local damageSetter = damageSetters[key]
2488
+ if damageSetter ~= nil then
2489
+ damageSetter(value)
2490
+ end
2399
2491
  data[key] = value
2400
2492
  end
2401
2493
  }
2402
2494
  )
2403
2495
  )
2496
+ if data[0] and source then
2497
+ local sourceOwner = source.owner.handle
2498
+ data[1] = sourceOwner
2499
+ local targetOwner = target.owner.handle
2500
+ data[2] = targetOwner
2501
+ if not GetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE) then
2502
+ SetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE, true)
2503
+ data[3] = true
2504
+ end
2505
+ if not GetPlayerAlliance(targetOwner, sourceOwner, ALLIANCE_PASSIVE) then
2506
+ SetPlayerAlliance(targetOwner, sourceOwner, ALLIANCE_PASSIVE, true)
2507
+ data[4] = true
2508
+ end
2509
+ end
2510
+ damagingEventByTarget[target] = data
2404
2511
  return
2405
2512
  end
2406
2513
  BlzSetEventDamage(0)
@@ -2408,7 +2515,7 @@ Unit.onDamaging = (function()
2408
2515
  BlzSetEventDamageType(DAMAGE_TYPE_UNKNOWN)
2409
2516
  BlzSetEventWeaponType(WEAPON_TYPE_WHOKNOWS)
2410
2517
  local sourceOwner = source.owner.handle
2411
- local targetOwner = GetOwningPlayer(target)
2518
+ local targetOwner = target.owner.handle
2412
2519
  if not GetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE) then
2413
2520
  SetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE, true)
2414
2521
  Timer:run(function()
@@ -2424,23 +2531,19 @@ Unit.onDamaging = (function()
2424
2531
  for ____, ____value in ipairs(source._attackHandlers) do
2425
2532
  local condition = ____value[1]
2426
2533
  local action = ____value[2]
2427
- if condition(
2428
- source,
2429
- ____exports.Unit:of(target),
2430
- data
2431
- ) then
2534
+ if condition(source, target, data) then
2432
2535
  action(
2433
2536
  source,
2434
- ____exports.Unit:of(target),
2537
+ target,
2435
2538
  setmetatable(
2436
2539
  {fire = function()
2437
2540
  UnitDamageTarget(
2438
2541
  source.handle,
2439
- target,
2542
+ target.handle,
2440
2543
  data.amount,
2441
2544
  true,
2442
2545
  true,
2443
- data.attackType,
2546
+ attackTypeToNative(data.attackType),
2444
2547
  data.damageType,
2445
2548
  data.weaponType
2446
2549
  )
@@ -2467,26 +2570,50 @@ Unit.onDamage = __TS__New(
2467
2570
  if source and source.typeId == dummyUnitId then
2468
2571
  source = nil
2469
2572
  end
2573
+ local target = ____exports.Unit:of(BlzGetEventDamageTarget())
2574
+ local damagingEvent = damagingEventByTarget[target]
2575
+ damagingEventByTarget[target] = nil
2470
2576
  local data = {
2471
2577
  amount = GetEventDamage(),
2472
- attackType = BlzGetEventAttackType(),
2578
+ attackType = nativeToAttackType(BlzGetEventAttackType()),
2473
2579
  damageType = BlzGetEventDamageType(),
2474
2580
  weaponType = BlzGetEventWeaponType(),
2581
+ metadata = damagingEvent and damagingEvent.metadata,
2475
2582
  isAttack = BlzGetEventIsAttack(),
2476
- originalAmount = GetEventDamage(),
2583
+ originalAmount = damagingEvent and damagingEvent.originalAmount or GetEventDamage(),
2584
+ originalMetadata = damagingEvent and damagingEvent.originalMetadata,
2477
2585
  preventDeath = damageEventPreventDeath
2478
2586
  }
2587
+ if damagingEvent then
2588
+ for key, value in pairs(damagingEvent) do
2589
+ if isAttribute(key) then
2590
+ data[key] = value
2591
+ end
2592
+ end
2593
+ local sourceOwner = damagingEvent[1]
2594
+ if sourceOwner then
2595
+ local targetOwner = damagingEvent[2]
2596
+ if damagingEvent[3] then
2597
+ SetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE, false)
2598
+ end
2599
+ if damagingEvent[4] then
2600
+ SetPlayerAlliance(targetOwner, sourceOwner, ALLIANCE_PASSIVE, false)
2601
+ end
2602
+ end
2603
+ end
2479
2604
  local evData = setmetatable(
2480
2605
  {},
2481
2606
  {
2482
2607
  __index = data,
2483
2608
  __newindex = function(self, key, value)
2484
- damageSetters[key](value)
2609
+ local damageSetter = damageSetters[key]
2610
+ if damageSetter ~= nil then
2611
+ damageSetter(value)
2612
+ end
2485
2613
  data[key] = value
2486
2614
  end
2487
2615
  }
2488
2616
  )
2489
- local target = ____exports.Unit:of(BlzGetEventDamageTarget())
2490
2617
  invoke(event, source, target, evData)
2491
2618
  if evData[0] ~= nil and target.health - evData.amount < 0.405 then
2492
2619
  local bonusHealth = math.ceil(evData.amount)
@@ -2540,10 +2667,14 @@ Unit.itemPickedUpEvent = __TS__New(
2540
2667
  ____exports.UnitTriggerEvent,
2541
2668
  EVENT_PLAYER_UNIT_PICKUP_ITEM,
2542
2669
  function()
2543
- local unit = getTriggerUnit()
2544
- local item = getManipulatedItem()
2545
- if getUnitTypeId(unit) ~= dummyUnitId and not (ignoreEventsItems[item] ~= nil) then
2546
- return ____exports.Unit:of(unit), Item:of(item)
2670
+ local unitHandle = getTriggerUnit()
2671
+ local itemHandle = getManipulatedItem()
2672
+ if getUnitTypeId(unitHandle) ~= dummyUnitId and not (ignoreEventsItems[itemHandle] ~= nil) then
2673
+ local unit = ____exports.Unit:of(unitHandle)
2674
+ local item = Item:of(itemHandle)
2675
+ if item.owner ~= unit then
2676
+ return unit, item
2677
+ end
2547
2678
  end
2548
2679
  return IgnoreEvent
2549
2680
  end
@@ -2563,7 +2694,22 @@ Unit.itemUsedEvent = __TS__New(
2563
2694
  Unit.itemStackedEvent = __TS__New(
2564
2695
  ____exports.UnitTriggerEvent,
2565
2696
  EVENT_PLAYER_UNIT_STACK_ITEM,
2566
- function() return ____exports.Unit:of(getTriggerUnit()), Item:of(getManipulatedItem()) end
2697
+ function() return ____exports.Unit:of(getTriggerUnit()), Item:of(BlzGetStackingItemTarget()), Item:of(BlzGetStackingItemSource()) end
2698
+ )
2699
+ __TS__ObjectDefineProperty(
2700
+ Unit,
2701
+ "itemChargesChangedEvent",
2702
+ {get = function(self)
2703
+ local event = __TS__New(Event)
2704
+ Item.chargesChangedEvent:addListener(function(item)
2705
+ local unit = item.owner
2706
+ if unit ~= nil then
2707
+ invoke(event, unit, item)
2708
+ end
2709
+ end)
2710
+ rawset(self, "itemChargesChangedEvent", event)
2711
+ return event
2712
+ end}
2567
2713
  )
2568
2714
  __TS__ObjectDefineProperty(
2569
2715
  Unit,