warscript 0.0.1-dev.c15015e → 0.0.1-dev.c1c578a

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 (165) 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 +14 -6
  6. package/core/types/effect.lua +131 -35
  7. package/core/types/frame.d.ts +4 -0
  8. package/core/types/frame.lua +71 -0
  9. package/core/types/sound.d.ts +17 -24
  10. package/core/types/sound.lua +99 -24
  11. package/core/types/timer.d.ts +6 -7
  12. package/core/types/timer.lua +18 -21
  13. package/core/util.d.ts +1 -1
  14. package/core/util.lua +18 -1
  15. package/decl/native.d.ts +840 -786
  16. package/engine/behavior.d.ts +2 -2
  17. package/engine/behavior.lua +6 -6
  18. package/engine/behaviour/ability/always-enabled.d.ts +7 -0
  19. package/engine/behaviour/ability/always-enabled.lua +31 -0
  20. package/engine/behaviour/ability/apply-buff.d.ts +5 -0
  21. package/engine/behaviour/ability/apply-buff.lua +32 -0
  22. package/engine/behaviour/ability/apply-unit-behavior.lua +1 -0
  23. package/engine/behaviour/ability/damage.d.ts +9 -3
  24. package/engine/behaviour/ability/damage.lua +26 -38
  25. package/engine/behaviour/ability/emulate-impact.d.ts +6 -0
  26. package/engine/behaviour/ability/emulate-impact.lua +35 -0
  27. package/engine/behaviour/ability/instant-impact.d.ts +2 -2
  28. package/engine/behaviour/ability/instant-impact.lua +4 -19
  29. package/engine/behaviour/ability/on-command-impact.d.ts +8 -0
  30. package/engine/behaviour/ability/on-command-impact.lua +25 -0
  31. package/engine/behaviour/ability/remove-buffs.d.ts +16 -0
  32. package/engine/behaviour/ability/remove-buffs.lua +28 -0
  33. package/engine/behaviour/ability.d.ts +20 -4
  34. package/engine/behaviour/ability.lua +111 -38
  35. package/engine/behaviour/unit.d.ts +2 -0
  36. package/engine/buff.d.ts +62 -42
  37. package/engine/buff.lua +312 -234
  38. package/engine/internal/ability.d.ts +16 -13
  39. package/engine/internal/ability.lua +80 -76
  40. package/engine/internal/item/ability.lua +106 -0
  41. package/engine/internal/item.d.ts +4 -3
  42. package/engine/internal/item.lua +56 -25
  43. package/engine/internal/mechanics/ability-duration.lua +1 -1
  44. package/engine/internal/misc/ability-disable-counter.d.ts +2 -0
  45. package/engine/internal/misc/ability-disable-counter.lua +13 -0
  46. package/engine/internal/misc/damage-metadata-by-target.d.ts +2 -0
  47. package/engine/internal/misc/damage-metadata-by-target.lua +5 -0
  48. package/engine/internal/object-data/auto-attack-speed-increase.d.ts +1 -1
  49. package/engine/internal/object-data/auto-attack-speed-increase.lua +2 -0
  50. package/engine/internal/object-data/evasion-probability.d.ts +2 -0
  51. package/engine/internal/object-data/evasion-probability.lua +16 -0
  52. package/engine/internal/unit/ability.d.ts +10 -1
  53. package/engine/internal/unit/ability.lua +36 -14
  54. package/engine/internal/unit/add-item-to-slot-init.d.ts +2 -0
  55. package/engine/internal/unit/add-item-to-slot-init.lua +23 -0
  56. package/engine/internal/unit/add-item-to-slot.d.ts +2 -0
  57. package/engine/internal/unit/add-item-to-slot.lua +52 -0
  58. package/engine/internal/unit/bonus.d.ts +2 -0
  59. package/engine/internal/unit/bonus.lua +17 -0
  60. package/engine/internal/unit/ignore-events-items.d.ts +2 -0
  61. package/engine/internal/unit/ignore-events-items.lua +5 -0
  62. package/engine/internal/{unit+item.d.ts → unit/item.d.ts} +5 -4
  63. package/engine/internal/{unit+item.lua → unit/item.lua} +32 -11
  64. package/engine/internal/unit/main-selected.d.ts +13 -0
  65. package/engine/internal/unit/main-selected.lua +51 -0
  66. package/engine/internal/unit+damage.d.ts +2 -11
  67. package/engine/internal/unit+damage.lua +10 -14
  68. package/engine/internal/unit+spellSteal.lua +1 -2
  69. package/engine/internal/unit-missile-launch.lua +24 -5
  70. package/engine/internal/unit.d.ts +39 -9
  71. package/engine/internal/unit.lua +247 -113
  72. package/engine/internal/utility.lua +12 -0
  73. package/engine/lightning.d.ts +12 -5
  74. package/engine/lightning.lua +48 -14
  75. package/engine/local-client.d.ts +7 -2
  76. package/engine/local-client.lua +82 -0
  77. package/engine/object-data/auxiliary/animation-name.d.ts +1 -0
  78. package/engine/object-data/auxiliary/animation-name.lua +16 -0
  79. package/engine/object-data/auxiliary/attachment-preset.d.ts +7 -2
  80. package/engine/object-data/auxiliary/attachment-preset.lua +4 -3
  81. package/engine/object-data/auxiliary/attack-type.d.ts +7 -8
  82. package/engine/object-data/auxiliary/attack-type.lua +42 -0
  83. package/engine/object-data/auxiliary/movement-type.d.ts +7 -7
  84. package/engine/object-data/auxiliary/movement-type.lua +22 -0
  85. package/engine/object-data/auxiliary/sound-eax.d.ts +10 -0
  86. package/engine/object-data/auxiliary/sound-eax.lua +2 -0
  87. package/engine/object-data/auxiliary/sound-preset-name.d.ts +5 -1
  88. package/engine/object-data/auxiliary/tech-tree-dependency.d.ts +1 -1
  89. package/engine/object-data/auxiliary/unit-attribute.d.ts +6 -0
  90. package/engine/object-data/auxiliary/unit-attribute.lua +9 -0
  91. package/engine/object-data/entry/ability-type/berserk.d.ts +2 -0
  92. package/engine/object-data/entry/ability-type/berserk.lua +13 -0
  93. package/engine/object-data/entry/ability-type/blank-configurable.lua +12 -1
  94. package/engine/object-data/entry/ability-type/carrion-swarm.d.ts +14 -0
  95. package/engine/object-data/entry/ability-type/carrion-swarm.lua +65 -0
  96. package/engine/object-data/entry/ability-type/disease-cloud.lua +2 -2
  97. package/engine/object-data/entry/ability-type/engineering-upgrade.lua +2 -2
  98. package/engine/object-data/entry/ability-type/ensnare.d.ts +12 -0
  99. package/engine/object-data/entry/ability-type/ensnare.lua +52 -0
  100. package/engine/object-data/entry/ability-type/feral-spirit.lua +2 -2
  101. package/engine/object-data/entry/ability-type/phase-shift.d.ts +10 -0
  102. package/engine/object-data/entry/ability-type/phase-shift.lua +39 -0
  103. package/engine/object-data/entry/ability-type/phoenix-morph.lua +4 -4
  104. package/engine/object-data/entry/ability-type/raise-dead.d.ts +17 -0
  105. package/engine/object-data/entry/ability-type/raise-dead.lua +78 -0
  106. package/engine/object-data/entry/ability-type/shock-wave.d.ts +4 -0
  107. package/engine/object-data/entry/ability-type/shock-wave.lua +26 -0
  108. package/engine/object-data/entry/ability-type/slow-poison.d.ts +10 -0
  109. package/engine/object-data/entry/ability-type/slow-poison.lua +58 -0
  110. package/engine/object-data/entry/ability-type/summon-quilbeast.lua +2 -2
  111. package/engine/object-data/entry/ability-type/summon-water-elemental.lua +2 -2
  112. package/engine/object-data/entry/ability-type/web.d.ts +12 -0
  113. package/engine/object-data/entry/ability-type/web.lua +52 -0
  114. package/engine/object-data/entry/ability-type.d.ts +19 -17
  115. package/engine/object-data/entry/ability-type.lua +89 -33
  116. package/engine/object-data/entry/buff-type/applicable.lua +18 -37
  117. package/engine/object-data/entry/buff-type.d.ts +6 -12
  118. package/engine/object-data/entry/buff-type.lua +13 -29
  119. package/engine/object-data/entry/destructible-type.d.ts +1 -1
  120. package/engine/object-data/entry/item-type.d.ts +15 -1
  121. package/engine/object-data/entry/item-type.lua +93 -2
  122. package/engine/object-data/entry/lightning-type.d.ts +1 -1
  123. package/engine/object-data/entry/sound-preset.d.ts +33 -0
  124. package/engine/object-data/entry/sound-preset.lua +140 -0
  125. package/engine/object-data/entry/unit-type.d.ts +10 -3
  126. package/engine/object-data/entry/unit-type.lua +155 -92
  127. package/engine/object-data/entry/upgrade.d.ts +1 -1
  128. package/engine/object-data/entry/upgrade.lua +4 -4
  129. package/engine/object-data/entry.d.ts +16 -14
  130. package/engine/object-data/entry.lua +60 -32
  131. package/engine/object-data/utility/object-data-entry-id-generator.lua +7 -0
  132. package/engine/object-field/ability.d.ts +10 -4
  133. package/engine/object-field/ability.lua +4 -1
  134. package/engine/object-field/unit.d.ts +46 -3
  135. package/engine/object-field/unit.lua +173 -7
  136. package/engine/object-field.d.ts +11 -3
  137. package/engine/object-field.lua +162 -76
  138. package/engine/standard/entries/buff-type.d.ts +3 -0
  139. package/engine/standard/entries/buff-type.lua +3 -0
  140. package/engine/standard/entries/sound-preset.d.ts +10 -0
  141. package/engine/standard/entries/sound-preset.lua +10 -0
  142. package/engine/standard/fields/ability.d.ts +2 -0
  143. package/engine/standard/fields/ability.lua +2 -0
  144. package/engine/unit.d.ts +3 -1
  145. package/engine/unit.lua +3 -1
  146. package/index.d.ts +1 -0
  147. package/index.lua +1 -0
  148. package/objutil/buff.lua +1 -2
  149. package/objutil/unit.lua +8 -0
  150. package/package.json +2 -2
  151. package/patch-lua.d.ts +0 -0
  152. package/patch-lua.lua +10 -0
  153. package/utility/arrays.d.ts +9 -1
  154. package/utility/arrays.lua +37 -3
  155. package/utility/functions.d.ts +1 -0
  156. package/utility/functions.lua +1 -0
  157. package/utility/lazy.d.ts +2 -0
  158. package/utility/lazy.lua +14 -0
  159. package/utility/linked-set.d.ts +1 -0
  160. package/utility/linked-set.lua +3 -0
  161. package/utility/lua-maps.d.ts +3 -0
  162. package/utility/lua-maps.lua +16 -0
  163. package/utility/lua-sets.d.ts +1 -0
  164. package/utility/lua-sets.lua +3 -0
  165. package/utility/reflection.lua +11 -7
@@ -51,12 +51,19 @@ 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
54
63
  local match = string.match
55
64
  local ____tostring = _G.tostring
56
65
  local setUnitAnimation = SetUnitAnimation
57
- local setUnitAnimationWithRarity = SetUnitAnimationWithRarity
58
66
  local setUnitAnimationByIndex = SetUnitAnimationByIndex
59
- local queueUnitAnimation = QueueUnitAnimation
60
67
  local getUnitIntegerField = BlzGetUnitIntegerField
61
68
  local getUnitRealField = BlzGetUnitRealField
62
69
  local getHeroStr = GetHeroStr
@@ -75,9 +82,9 @@ local setUnitScale = SetUnitScale
75
82
  local setUnitPosition = SetUnitPosition
76
83
  local setUnitTimeScale = SetUnitTimeScale
77
84
  local getHandleId = GetHandleId
85
+ local getUnitCurrentOrder = GetUnitCurrentOrder
78
86
  local createUnit = CreateUnit
79
87
  local killUnit = KillUnit
80
- local setUnitExploded = SetUnitExploded
81
88
  local removeUnit = RemoveUnit
82
89
  local getUnitTypeId = GetUnitTypeId
83
90
  local isHeroUnitId = IsHeroUnitId
@@ -93,8 +100,6 @@ local getSpellTargetItem = GetSpellTargetItem
93
100
  local getSpellTargetDestructable = GetSpellTargetDestructable
94
101
  local isUnitInRangeXY = IsUnitInRangeXY
95
102
  local isUnitInRange = IsUnitInRange
96
- local setResourceAmount = SetResourceAmount
97
- local getResourceAmount = GetResourceAmount
98
103
  local getUnitWeaponRealField = BlzGetUnitWeaponRealField
99
104
  local setUnitWeaponRealField = BlzSetUnitWeaponRealField
100
105
  local getUnitWeaponStringField = BlzGetUnitWeaponStringField
@@ -125,8 +130,6 @@ local isUnitType = IsUnitType
125
130
  local isUnitAlly = IsUnitAlly
126
131
  local isUnitEnemy = IsUnitEnemy
127
132
  local getOwningPlayer = GetOwningPlayer
128
- local setUnitColor = SetUnitColor
129
- local showUnitTeamGlow = BlzShowUnitTeamGlow
130
133
  ____exports.UnitClassification = {}
131
134
  local UnitClassification = ____exports.UnitClassification
132
135
  do
@@ -136,6 +139,7 @@ do
136
139
  UnitClassification.GROUND = UNIT_TYPE_GROUND
137
140
  UnitClassification.SUMMONED = UNIT_TYPE_SUMMONED
138
141
  UnitClassification.MECHANICAL = UNIT_TYPE_MECHANICAL
142
+ UnitClassification.WORKER = UNIT_TYPE_PEON
139
143
  UnitClassification.ANCIENT = UNIT_TYPE_ANCIENT
140
144
  UnitClassification.SUICIDAL = UNIT_TYPE_SAPPER
141
145
  UnitClassification.TAUREN = UNIT_TYPE_TAUREN
@@ -354,7 +358,14 @@ local function damageEventPreventDeath(self, callback, ...)
354
358
  rawset(self, 1 + i, (select(i, ...)))
355
359
  end
356
360
  end
357
- 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
+ }
358
369
  local jlimitopByOperator = {
359
370
  [0] = LESS_THAN_OR_EQUAL,
360
371
  [1] = LESS_THAN_OR_EQUAL,
@@ -562,17 +573,6 @@ local function retrieveAbility(unit, ability, abilityId)
562
573
  ____exports.Unit:of(unit)
563
574
  )
564
575
  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
576
  for i = 0, unitInventorySize(unit) - 1 do
577
577
  local item = unitItemInSlot(unit, i)
578
578
  if getItemAbility(item, abilityId) == ability then
@@ -630,15 +630,15 @@ for ____, player in ipairs(Player.all) do
630
630
  dummies[player] = dummy
631
631
  end
632
632
  local function delayHealthChecksCallback(unit)
633
- local counter = (unit[102] or 0) - 1
633
+ local counter = (unit[103] or 0) - 1
634
634
  if counter ~= 0 then
635
- unit[102] = counter
635
+ unit[103] = counter
636
636
  return
637
637
  end
638
- unit[102] = nil
639
- local healthBonus = unit[103]
638
+ unit[103] = nil
639
+ local healthBonus = unit[104]
640
640
  if healthBonus ~= nil then
641
- unit[103] = nil
641
+ unit[104] = nil
642
642
  local handle = unit.handle
643
643
  BlzSetUnitMaxHP(
644
644
  handle,
@@ -646,12 +646,18 @@ local function delayHealthChecksCallback(unit)
646
646
  )
647
647
  end
648
648
  end
649
+ local nextSyncId = 1
650
+ local unitBySyncId = setmetatable({}, {__mode = "v"})
651
+ local damagingEventByTarget = setmetatable({}, {__mode = "k"})
649
652
  ____exports.Unit = __TS__Class()
650
653
  local Unit = ____exports.Unit
651
654
  Unit.name = "Unit"
652
655
  __TS__ClassExtends(Unit, Handle)
653
656
  function Unit.prototype.____constructor(self, handle)
654
657
  Handle.prototype.____constructor(self, handle)
658
+ local ____nextSyncId_0 = nextSyncId
659
+ nextSyncId = ____nextSyncId_0 + 1
660
+ self.syncId = ____nextSyncId_0
655
661
  self._owner = Player:of(getOwningPlayer(handle))
656
662
  assert(unitAddAbility(handle, leaveDetectAbilityId) and UnitMakeAbilityPermanent(handle, true, leaveDetectAbilityId))
657
663
  assert(unitAddAbility(handle, morphDetectAbilityId))
@@ -664,6 +670,7 @@ function Unit.prototype.____constructor(self, handle)
664
670
  fourCC("Amrf")
665
671
  ))
666
672
  end
673
+ unitBySyncId[self.syncId] = self
667
674
  local ____ = self.abilities
668
675
  end
669
676
  function Unit.prototype.getEvent(self, event, collector)
@@ -682,6 +689,8 @@ function Unit.prototype.getEvent(self, event, collector)
682
689
  end
683
690
  function Unit.prototype.onDestroy(self)
684
691
  local handle = self.handle
692
+ self[107] = getUnitX(handle)
693
+ self[108] = getUnitY(handle)
685
694
  if not self._owner then
686
695
  self._owner = Player:of(getOwningPlayer(handle))
687
696
  end
@@ -749,8 +758,8 @@ function Unit.prototype.addModifier(self, property, modifier)
749
758
  end}
750
759
  end
751
760
  function Unit.prototype.hasCombatClassification(self, combatClassification)
752
- local ____combatClassification_0 = combatClassification
753
- return getUnitIntegerField(self.handle, UNIT_IF_TARGETED_AS) & ____combatClassification_0 == ____combatClassification_0
761
+ local ____combatClassification_1 = combatClassification
762
+ return getUnitIntegerField(self.handle, UNIT_IF_TARGETED_AS) & ____combatClassification_1 == ____combatClassification_1
754
763
  end
755
764
  function Unit.prototype.addClassification(self, classification)
756
765
  return unitAddType(self.handle, classification)
@@ -768,13 +777,13 @@ function Unit.prototype.isInvisibleTo(self, player)
768
777
  return isUnitInvisible(self.handle, player.handle)
769
778
  end
770
779
  function Unit.prototype.isInRangeOf(self, x, y, range)
771
- local ____temp_1
780
+ local ____temp_2
772
781
  if type(x) == "number" then
773
- ____temp_1 = isUnitInRangeXY(self.handle, x, y, range)
782
+ ____temp_2 = isUnitInRangeXY(self.handle, x, y, range)
774
783
  else
775
- ____temp_1 = isUnitInRange(self.handle, x.handle, y)
784
+ ____temp_2 = isUnitInRange(self.handle, x.handle, y)
776
785
  end
777
- return ____temp_1
786
+ return ____temp_2
778
787
  end
779
788
  function Unit.prototype.isAllyOf(self, unit)
780
789
  return isUnitAlly(
@@ -792,16 +801,19 @@ function Unit.prototype.playAnimation(self, animation, rarity)
792
801
  if type(animation) == "number" then
793
802
  setUnitAnimationByIndex(self.handle, animation)
794
803
  elseif rarity then
795
- setUnitAnimationWithRarity(self.handle, animation, rarity)
804
+ SetUnitAnimationWithRarity(self.handle, animation, rarity)
796
805
  else
797
806
  setUnitAnimation(self.handle, animation)
798
807
  end
799
808
  end
809
+ function Unit.prototype.resetAnimation(self)
810
+ ResetUnitAnimation(self.handle)
811
+ end
800
812
  function Unit.prototype.queueAnimation(self, animation)
801
- queueUnitAnimation(self.handle, animation)
813
+ QueueUnitAnimation(self.handle, animation)
802
814
  end
803
815
  function Unit.prototype.delayHealthChecks(self)
804
- self[102] = (self[102] or 0) + 1
816
+ self[103] = (self[103] or 0) + 1
805
817
  Timer:run(delayHealthChecksCallback, self)
806
818
  end
807
819
  function Unit.prototype.setPosition(self, x, y)
@@ -811,21 +823,21 @@ function Unit.prototype.isSelected(self, player)
811
823
  return IsUnitSelected(self.handle, player.handle)
812
824
  end
813
825
  function Unit.prototype.explode(self)
814
- setUnitExploded(self.handle, true)
826
+ SetUnitExploded(self.handle, true)
815
827
  killUnit(self.handle)
816
828
  end
817
829
  function Unit.prototype.kill(self)
818
830
  killUnit(self.handle)
819
831
  end
820
832
  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
833
+ local ____ReviveHero_5 = ReviveHero
834
+ local ____array_4 = __TS__SparseArrayNew(self.handle, x, y)
835
+ local ____doEffect_3 = doEffect
836
+ if ____doEffect_3 == nil then
837
+ ____doEffect_3 = false
826
838
  end
827
- __TS__SparseArrayPush(____array_3, ____doEffect_2)
828
- ____ReviveHero_4(__TS__SparseArraySpread(____array_3))
839
+ __TS__SparseArrayPush(____array_4, ____doEffect_3)
840
+ ____ReviveHero_5(__TS__SparseArraySpread(____array_4))
829
841
  end
830
842
  function Unit.prototype.healTarget(self, target, amount)
831
843
  if __TS__InstanceOf(target, ____exports.Unit) and target:hasAbility(fourCC("BIhm")) then
@@ -934,8 +946,15 @@ function Unit.prototype.interruptAttack(self)
934
946
  unitInterruptAttack(self.handle)
935
947
  end
936
948
  function Unit.prototype.interruptCast(self, abilityId)
937
- unitDisableAbility(self.handle, abilityId, true, false)
938
- unitDisableAbility(self.handle, abilityId, false, false)
949
+ local handle = self.handle
950
+ unitDisableAbility(handle, abilityId, true, false)
951
+ Timer:run(
952
+ unitDisableAbility,
953
+ handle,
954
+ abilityId,
955
+ false,
956
+ false
957
+ )
939
958
  end
940
959
  function Unit.prototype.getDistanceTo(self, target)
941
960
  local handle = self.handle
@@ -995,18 +1014,18 @@ function Unit.prototype.unpauseEx(self)
995
1014
  self:decrementStunCounter()
996
1015
  end
997
1016
  function Unit.prototype.incrementStunCounter(self)
998
- local stunCounter = self[101] or 0
999
- if not self[100] or stunCounter >= 0 then
1017
+ local stunCounter = self[102] or 0
1018
+ if not self[101] or stunCounter >= 0 then
1000
1019
  BlzPauseUnitEx(self.handle, true)
1001
1020
  end
1002
- self[101] = stunCounter + 1
1021
+ self[102] = stunCounter + 1
1003
1022
  end
1004
1023
  function Unit.prototype.decrementStunCounter(self)
1005
- local stunCounter = self[101] or 0
1006
- if not self[100] or stunCounter >= 1 then
1024
+ local stunCounter = self[102] or 0
1025
+ if not self[101] or stunCounter >= 1 then
1007
1026
  BlzPauseUnitEx(self.handle, false)
1008
1027
  end
1009
- self[101] = stunCounter - 1
1028
+ self[102] = stunCounter - 1
1010
1029
  end
1011
1030
  function Unit.create(self, owner, id, x, y, facing, skinId)
1012
1031
  local handle = skinId and BlzCreateUnitWithSkin(
@@ -1108,8 +1127,11 @@ function Unit.getInSector(self, pos, range, offsetAngle, centralAngle)
1108
1127
  )
1109
1128
  return targetCollection
1110
1129
  end
1111
- function Unit.getSelectionOf(self, player)
1112
- targetCollection = {}
1130
+ function Unit.getSelectionOf(self, player, target)
1131
+ if target == nil then
1132
+ target = {}
1133
+ end
1134
+ targetCollection = target
1113
1135
  targetCollectionNextIndex = 1
1114
1136
  GroupEnumUnitsSelected(dummyGroup, player.handle, collectIntoTarget)
1115
1137
  return targetCollection
@@ -1131,6 +1153,9 @@ end
1131
1153
  function Unit.prototype.__tostring(self)
1132
1154
  return (((self.constructor.name .. "$") .. util.id2s(self.typeId)) .. "@") .. tostring(getHandleId(self.handle))
1133
1155
  end
1156
+ function Unit.getBySyncId(self, syncId)
1157
+ return unitBySyncId[syncId]
1158
+ end
1134
1159
  __TS__SetDescriptor(
1135
1160
  Unit.prototype,
1136
1161
  "_deltas",
@@ -1194,6 +1219,14 @@ __TS__SetDescriptor(
1194
1219
  end},
1195
1220
  true
1196
1221
  )
1222
+ __TS__SetDescriptor(
1223
+ Unit.prototype,
1224
+ "isStunned",
1225
+ {get = function(self)
1226
+ return getUnitCurrentOrder(self.handle) == orderId("stunned")
1227
+ end},
1228
+ true
1229
+ )
1197
1230
  __TS__SetDescriptor(
1198
1231
  Unit.prototype,
1199
1232
  "combatClassifications",
@@ -1267,6 +1300,19 @@ __TS__SetDescriptor(
1267
1300
  },
1268
1301
  true
1269
1302
  )
1303
+ __TS__SetDescriptor(
1304
+ Unit.prototype,
1305
+ "primaryAttribute",
1306
+ {
1307
+ get = function(self)
1308
+ return getUnitIntegerField(self.handle, UNIT_IF_PRIMARY_ATTRIBUTE)
1309
+ end,
1310
+ set = function(self, primaryAttribute)
1311
+ setUnitIntegerField(self.handle, UNIT_IF_PRIMARY_ATTRIBUTE, primaryAttribute)
1312
+ end
1313
+ },
1314
+ true
1315
+ )
1270
1316
  __TS__SetDescriptor(
1271
1317
  Unit.prototype,
1272
1318
  "strengthBase",
@@ -1388,17 +1434,17 @@ __TS__SetDescriptor(
1388
1434
  "isTeamGlowVisible",
1389
1435
  {
1390
1436
  get = function(self)
1391
- return not self[105]
1437
+ return not self[106]
1392
1438
  end,
1393
1439
  set = function(self, isTeamGlowVisible)
1394
- showUnitTeamGlow(self.handle, isTeamGlowVisible)
1395
- local ____temp_5
1440
+ BlzShowUnitTeamGlow(self.handle, isTeamGlowVisible)
1441
+ local ____temp_6
1396
1442
  if not isTeamGlowVisible then
1397
- ____temp_5 = true
1443
+ ____temp_6 = true
1398
1444
  else
1399
- ____temp_5 = nil
1445
+ ____temp_6 = nil
1400
1446
  end
1401
- self[105] = ____temp_5
1447
+ self[106] = ____temp_6
1402
1448
  end
1403
1449
  },
1404
1450
  true
@@ -1407,9 +1453,9 @@ __TS__SetDescriptor(
1407
1453
  Unit.prototype,
1408
1454
  "color",
1409
1455
  {set = function(self, color)
1410
- setUnitColor(self.handle, color.handle)
1411
- if self[105] then
1412
- showUnitTeamGlow(self.handle, false)
1456
+ SetUnitColor(self.handle, color.handle)
1457
+ if self[106] then
1458
+ BlzShowUnitTeamGlow(self.handle, false)
1413
1459
  end
1414
1460
  end},
1415
1461
  true
@@ -1432,14 +1478,14 @@ __TS__SetDescriptor(
1432
1478
  "maxHealth",
1433
1479
  {
1434
1480
  get = function(self)
1435
- return BlzGetUnitMaxHP(self.handle) - (self[103] or 0) - (self[104] or 0)
1481
+ return BlzGetUnitMaxHP(self.handle) - (self[104] or 0) - (self[105] or 0)
1436
1482
  end,
1437
1483
  set = function(self, maxHealth)
1438
- if maxHealth < 1 and self[102] ~= nil then
1439
- self[103] = (self[103] or 0) + (1 - maxHealth)
1484
+ if maxHealth < 1 and self[103] ~= nil then
1485
+ self[104] = (self[104] or 0) + (1 - maxHealth)
1440
1486
  maxHealth = 1
1441
1487
  end
1442
- BlzSetUnitMaxHP(self.handle, maxHealth + (self[104] or 0))
1488
+ BlzSetUnitMaxHP(self.handle, maxHealth + (self[105] or 0))
1443
1489
  end
1444
1490
  },
1445
1491
  true
@@ -1481,10 +1527,10 @@ __TS__SetDescriptor(
1481
1527
  "health",
1482
1528
  {
1483
1529
  get = function(self)
1484
- return GetWidgetLife(self.handle) - (self[104] or 0)
1530
+ return GetWidgetLife(self.handle) - (self[105] or 0)
1485
1531
  end,
1486
1532
  set = function(self, health)
1487
- SetWidgetLife(self.handle, health + (self[104] or 0))
1533
+ SetWidgetLife(self.handle, health + (self[105] or 0))
1488
1534
  end
1489
1535
  },
1490
1536
  true
@@ -1578,7 +1624,7 @@ __TS__SetDescriptor(
1578
1624
  "x",
1579
1625
  {
1580
1626
  get = function(self)
1581
- return getUnitX(self.handle)
1627
+ return self[107] or getUnitX(self.handle)
1582
1628
  end,
1583
1629
  set = function(self, v)
1584
1630
  SetUnitX(self.handle, v)
@@ -1591,7 +1637,7 @@ __TS__SetDescriptor(
1591
1637
  "y",
1592
1638
  {
1593
1639
  get = function(self)
1594
- return getUnitY(self.handle)
1640
+ return self[108] or getUnitY(self.handle)
1595
1641
  end,
1596
1642
  set = function(self, v)
1597
1643
  SetUnitY(self.handle, v)
@@ -1677,10 +1723,10 @@ __TS__SetDescriptor(
1677
1723
  "gold",
1678
1724
  {
1679
1725
  get = function(self)
1680
- return getResourceAmount(self.handle)
1726
+ return GetResourceAmount(self.handle)
1681
1727
  end,
1682
1728
  set = function(self, gold)
1683
- setResourceAmount(self.handle, gold)
1729
+ SetResourceAmount(self.handle, gold)
1684
1730
  end
1685
1731
  },
1686
1732
  true
@@ -1695,17 +1741,17 @@ __TS__SetDescriptor(
1695
1741
  set = function(self, isPaused)
1696
1742
  local handle = self.handle
1697
1743
  if isPaused and not IsUnitPaused(handle) then
1698
- self[100] = true
1699
- for _ = self[101] or 0, -1 do
1744
+ self[101] = true
1745
+ for _ = self[102] or 0, -1 do
1700
1746
  BlzPauseUnitEx(handle, true)
1701
1747
  end
1702
1748
  PauseUnit(handle, true)
1703
1749
  elseif not isPaused and IsUnitPaused(handle) then
1704
1750
  PauseUnit(handle, false)
1705
- for _ = self[101] or 0, -1 do
1751
+ for _ = self[102] or 0, -1 do
1706
1752
  BlzPauseUnitEx(handle, false)
1707
1753
  end
1708
- self[100] = nil
1754
+ self[101] = nil
1709
1755
  end
1710
1756
  end
1711
1757
  },
@@ -1808,6 +1854,19 @@ __TS__SetDescriptor(
1808
1854
  end},
1809
1855
  true
1810
1856
  )
1857
+ __TS__SetDescriptor(
1858
+ Unit.prototype,
1859
+ "movementType",
1860
+ {
1861
+ get = function(self)
1862
+ return getUnitIntegerField(self.handle, UNIT_IF_MOVE_TYPE)
1863
+ end,
1864
+ set = function(self, movementType)
1865
+ setUnitIntegerField(self.handle, UNIT_IF_MOVE_TYPE, movementType)
1866
+ end
1867
+ },
1868
+ true
1869
+ )
1811
1870
  __TS__SetDescriptor(
1812
1871
  Unit.prototype,
1813
1872
  "pathing",
@@ -2124,25 +2183,25 @@ Unit.onTargetCast = dispatchId(__TS__New(
2124
2183
  InitializingEvent,
2125
2184
  function(event)
2126
2185
  local function listener(unit, id)
2127
- local ____GetSpellTargetUnit_result_8
2186
+ local ____GetSpellTargetUnit_result_9
2128
2187
  if GetSpellTargetUnit() then
2129
- ____GetSpellTargetUnit_result_8 = ____exports.Unit:of(GetSpellTargetUnit())
2188
+ ____GetSpellTargetUnit_result_9 = ____exports.Unit:of(GetSpellTargetUnit())
2130
2189
  else
2131
- local ____GetSpellTargetItem_result_7
2190
+ local ____GetSpellTargetItem_result_8
2132
2191
  if GetSpellTargetItem() then
2133
- ____GetSpellTargetItem_result_7 = Item:of(GetSpellTargetItem())
2192
+ ____GetSpellTargetItem_result_8 = Item:of(GetSpellTargetItem())
2134
2193
  else
2135
- local ____GetSpellTargetDestructable_result_6
2194
+ local ____GetSpellTargetDestructable_result_7
2136
2195
  if GetSpellTargetDestructable() then
2137
- ____GetSpellTargetDestructable_result_6 = Destructable:of(GetSpellTargetDestructable())
2196
+ ____GetSpellTargetDestructable_result_7 = Destructable:of(GetSpellTargetDestructable())
2138
2197
  else
2139
- ____GetSpellTargetDestructable_result_6 = nil
2198
+ ____GetSpellTargetDestructable_result_7 = nil
2140
2199
  end
2141
- ____GetSpellTargetItem_result_7 = ____GetSpellTargetDestructable_result_6
2200
+ ____GetSpellTargetItem_result_8 = ____GetSpellTargetDestructable_result_7
2142
2201
  end
2143
- ____GetSpellTargetUnit_result_8 = ____GetSpellTargetItem_result_7
2202
+ ____GetSpellTargetUnit_result_9 = ____GetSpellTargetItem_result_8
2144
2203
  end
2145
- local target = ____GetSpellTargetUnit_result_8
2204
+ local target = ____GetSpellTargetUnit_result_9
2146
2205
  if target then
2147
2206
  invoke(event, unit, id, target)
2148
2207
  end
@@ -2314,10 +2373,12 @@ Unit.onImmediateOrder = dispatchId(__TS__New(
2314
2373
  ____exports.UnitTriggerEvent,
2315
2374
  EVENT_PLAYER_UNIT_ISSUED_ORDER,
2316
2375
  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
2376
+ local handle = getOrderedUnit()
2377
+ if handle ~= nil and getUnitTypeId(handle) ~= dummyUnitId then
2378
+ local unit = ____exports.Unit:of(handle)
2379
+ if unit.state == 1 then
2380
+ return unit, getIssuedOrderId()
2381
+ end
2321
2382
  end
2322
2383
  return IgnoreEvent
2323
2384
  end
@@ -2348,13 +2409,18 @@ Unit.onDamaging = (function()
2348
2409
  if source and source.typeId == dummyUnitId then
2349
2410
  source = nil
2350
2411
  end
2351
- local target = BlzGetEventDamageTarget()
2412
+ local target = ____exports.Unit:of(BlzGetEventDamageTarget())
2413
+ local metadata = damageMetadataByTarget[target]
2414
+ damageMetadataByTarget[target] = nil
2352
2415
  local data = {
2353
2416
  amount = GetEventDamage(),
2354
- attackType = BlzGetEventAttackType(),
2417
+ attackType = nativeToAttackType(BlzGetEventAttackType()),
2355
2418
  damageType = BlzGetEventDamageType(),
2356
2419
  weaponType = BlzGetEventWeaponType(),
2357
- isAttack = BlzGetEventIsAttack()
2420
+ metadata = metadata,
2421
+ isAttack = BlzGetEventIsAttack(),
2422
+ originalAmount = GetEventDamage(),
2423
+ originalMetadata = metadata
2358
2424
  }
2359
2425
  if data.isAttack and source then
2360
2426
  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
@@ -2368,18 +2434,22 @@ Unit.onDamaging = (function()
2368
2434
  invoke(
2369
2435
  event,
2370
2436
  source,
2371
- ____exports.Unit:of(target),
2437
+ target,
2372
2438
  setmetatable(
2373
2439
  {},
2374
2440
  {
2375
2441
  __index = data,
2376
2442
  __newindex = function(self, key, value)
2377
- damageSetters[key](value)
2443
+ local damageSetter = damageSetters[key]
2444
+ if damageSetter ~= nil then
2445
+ damageSetter(value)
2446
+ end
2378
2447
  data[key] = value
2379
2448
  end
2380
2449
  }
2381
2450
  )
2382
2451
  )
2452
+ damagingEventByTarget[target] = data
2383
2453
  return
2384
2454
  end
2385
2455
  BlzSetEventDamage(0)
@@ -2387,7 +2457,7 @@ Unit.onDamaging = (function()
2387
2457
  BlzSetEventDamageType(DAMAGE_TYPE_UNKNOWN)
2388
2458
  BlzSetEventWeaponType(WEAPON_TYPE_WHOKNOWS)
2389
2459
  local sourceOwner = source.owner.handle
2390
- local targetOwner = GetOwningPlayer(target)
2460
+ local targetOwner = target.owner.handle
2391
2461
  if not GetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE) then
2392
2462
  SetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE, true)
2393
2463
  Timer:run(function()
@@ -2403,23 +2473,19 @@ Unit.onDamaging = (function()
2403
2473
  for ____, ____value in ipairs(source._attackHandlers) do
2404
2474
  local condition = ____value[1]
2405
2475
  local action = ____value[2]
2406
- if condition(
2407
- source,
2408
- ____exports.Unit:of(target),
2409
- data
2410
- ) then
2476
+ if condition(source, target, data) then
2411
2477
  action(
2412
2478
  source,
2413
- ____exports.Unit:of(target),
2479
+ target,
2414
2480
  setmetatable(
2415
2481
  {fire = function()
2416
2482
  UnitDamageTarget(
2417
2483
  source.handle,
2418
- target,
2484
+ target.handle,
2419
2485
  data.amount,
2420
2486
  true,
2421
2487
  true,
2422
- data.attackType,
2488
+ attackTypeToNative(data.attackType),
2423
2489
  data.damageType,
2424
2490
  data.weaponType
2425
2491
  )
@@ -2446,30 +2512,44 @@ Unit.onDamage = __TS__New(
2446
2512
  if source and source.typeId == dummyUnitId then
2447
2513
  source = nil
2448
2514
  end
2515
+ local target = ____exports.Unit:of(BlzGetEventDamageTarget())
2516
+ local damagingEvent = damagingEventByTarget[target]
2517
+ damagingEventByTarget[target] = nil
2449
2518
  local data = {
2450
2519
  amount = GetEventDamage(),
2451
- attackType = BlzGetEventAttackType(),
2520
+ attackType = nativeToAttackType(BlzGetEventAttackType()),
2452
2521
  damageType = BlzGetEventDamageType(),
2453
2522
  weaponType = BlzGetEventWeaponType(),
2523
+ metadata = damagingEvent and damagingEvent.metadata,
2454
2524
  isAttack = BlzGetEventIsAttack(),
2455
- originalAmount = GetEventDamage(),
2525
+ originalAmount = damagingEvent and damagingEvent.originalAmount or GetEventDamage(),
2526
+ originalMetadata = damagingEvent and damagingEvent.originalMetadata,
2456
2527
  preventDeath = damageEventPreventDeath
2457
2528
  }
2529
+ if damagingEvent then
2530
+ for key, value in pairs(damagingEvent) do
2531
+ if isAttribute(key) then
2532
+ data[key] = value
2533
+ end
2534
+ end
2535
+ end
2458
2536
  local evData = setmetatable(
2459
2537
  {},
2460
2538
  {
2461
2539
  __index = data,
2462
2540
  __newindex = function(self, key, value)
2463
- damageSetters[key](value)
2541
+ local damageSetter = damageSetters[key]
2542
+ if damageSetter ~= nil then
2543
+ damageSetter(value)
2544
+ end
2464
2545
  data[key] = value
2465
2546
  end
2466
2547
  }
2467
2548
  )
2468
- local target = ____exports.Unit:of(BlzGetEventDamageTarget())
2469
2549
  invoke(event, source, target, evData)
2470
2550
  if evData[0] ~= nil and target.health - evData.amount < 0.405 then
2471
2551
  local bonusHealth = math.ceil(evData.amount)
2472
- target[104] = (target[104] or 0) + bonusHealth
2552
+ target[105] = (target[105] or 0) + bonusHealth
2473
2553
  BlzSetUnitMaxHP(
2474
2554
  target.handle,
2475
2555
  BlzGetUnitMaxHP(target.handle) + bonusHealth
@@ -2483,7 +2563,7 @@ Unit.onDamage = __TS__New(
2483
2563
  evData[0],
2484
2564
  table.unpack(evData, 1 + 1, 1 + (evData[1] or 0))
2485
2565
  )
2486
- target[104] = (target[104] or 0) - bonusHealth
2566
+ target[105] = (target[105] or 0) - bonusHealth
2487
2567
  SetWidgetLife(
2488
2568
  target.handle,
2489
2569
  GetWidgetLife(target.handle) - bonusHealth
@@ -2508,8 +2588,9 @@ Unit.itemDroppedEvent = __TS__New(
2508
2588
  EVENT_PLAYER_UNIT_DROP_ITEM,
2509
2589
  function()
2510
2590
  local unit = getTriggerUnit()
2511
- if getUnitTypeId(unit) ~= dummyUnitId then
2512
- return ____exports.Unit:of(unit), Item:of(getManipulatedItem())
2591
+ local item = getManipulatedItem()
2592
+ if getUnitTypeId(unit) ~= dummyUnitId and not (ignoreEventsItems[item] ~= nil) then
2593
+ return ____exports.Unit:of(unit), Item:of(item)
2513
2594
  end
2514
2595
  return IgnoreEvent
2515
2596
  end
@@ -2519,8 +2600,9 @@ Unit.itemPickedUpEvent = __TS__New(
2519
2600
  EVENT_PLAYER_UNIT_PICKUP_ITEM,
2520
2601
  function()
2521
2602
  local unit = getTriggerUnit()
2522
- if getUnitTypeId(unit) ~= dummyUnitId then
2523
- return ____exports.Unit:of(unit), Item:of(getManipulatedItem())
2603
+ local item = getManipulatedItem()
2604
+ if getUnitTypeId(unit) ~= dummyUnitId and not (ignoreEventsItems[item] ~= nil) then
2605
+ return ____exports.Unit:of(unit), Item:of(item)
2524
2606
  end
2525
2607
  return IgnoreEvent
2526
2608
  end
@@ -2528,13 +2610,65 @@ Unit.itemPickedUpEvent = __TS__New(
2528
2610
  Unit.itemUsedEvent = __TS__New(
2529
2611
  ____exports.UnitTriggerEvent,
2530
2612
  EVENT_PLAYER_UNIT_USE_ITEM,
2531
- function() return ____exports.Unit:of(getTriggerUnit()), Item:of(getManipulatedItem()) end
2613
+ function()
2614
+ local unit = getTriggerUnit()
2615
+ local item = getManipulatedItem()
2616
+ if getUnitTypeId(unit) ~= dummyUnitId and not (ignoreEventsItems[item] ~= nil) then
2617
+ return ____exports.Unit:of(unit), Item:of(item)
2618
+ end
2619
+ return IgnoreEvent
2620
+ end
2532
2621
  )
2533
2622
  Unit.itemStackedEvent = __TS__New(
2534
2623
  ____exports.UnitTriggerEvent,
2535
2624
  EVENT_PLAYER_UNIT_STACK_ITEM,
2536
2625
  function() return ____exports.Unit:of(getTriggerUnit()), Item:of(getManipulatedItem()) end
2537
2626
  )
2627
+ __TS__ObjectDefineProperty(
2628
+ Unit,
2629
+ "itemUseOrderEvent",
2630
+ {get = function(self)
2631
+ local event = __TS__New(Event)
2632
+ for order = orderId("useslot0"), orderId("useslot5") do
2633
+ local slot = order - orderId("useslot0")
2634
+ local function listener(unit)
2635
+ local item = unit.items[slot + 1]
2636
+ if item ~= nil then
2637
+ invoke(event, unit, item)
2638
+ end
2639
+ end
2640
+ self.onImmediateOrder[order]:addListener(listener)
2641
+ self.onTargetOrder[order]:addListener(listener)
2642
+ self.onPointOrder[order]:addListener(listener)
2643
+ end
2644
+ rawset(self, "itemUseOrderEvent", event)
2645
+ return event
2646
+ end}
2647
+ )
2648
+ __TS__ObjectDefineProperty(
2649
+ Unit,
2650
+ "itemMoveOrderEvent",
2651
+ {get = function(self)
2652
+ local event = __TS__New(Event)
2653
+ for order = orderId("moveslot0"), orderId("moveslot5") do
2654
+ local slotTo = order - orderId("moveslot0")
2655
+ self.onTargetOrder[order]:addListener(function(unit, item)
2656
+ local slotFrom = unit.items:findSlot(item)
2657
+ if slotFrom ~= nil then
2658
+ invoke(
2659
+ event,
2660
+ unit,
2661
+ item,
2662
+ slotFrom,
2663
+ slotTo
2664
+ )
2665
+ end
2666
+ end)
2667
+ end
2668
+ rawset(self, "itemMoveOrderEvent", event)
2669
+ return event
2670
+ end}
2671
+ )
2538
2672
  __TS__ObjectDefineProperty(
2539
2673
  Unit,
2540
2674
  "onCreate",