warscript 0.0.1-dev.5dbd5af → 0.0.1-dev.5e33506

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 (112) hide show
  1. package/attributes.d.ts +6 -0
  2. package/attributes.lua +17 -1
  3. package/core/types/frame.lua +24 -21
  4. package/core/types/player.d.ts +16 -0
  5. package/core/types/player.lua +60 -15
  6. package/core/types/playerCamera.d.ts +2 -0
  7. package/core/types/playerCamera.lua +123 -5
  8. package/core/types/tileCell.d.ts +11 -1
  9. package/core/types/tileCell.lua +97 -0
  10. package/core/types/timer.d.ts +3 -1
  11. package/core/types/timer.lua +27 -2
  12. package/decl/native.d.ts +6 -4
  13. package/destroyable.d.ts +1 -0
  14. package/destroyable.lua +9 -0
  15. package/engine/behavior.d.ts +14 -1
  16. package/engine/behavior.lua +230 -70
  17. package/engine/behaviour/ability/apply-buff.lua +5 -5
  18. package/engine/behaviour/ability/damage.d.ts +4 -2
  19. package/engine/behaviour/ability/damage.lua +24 -36
  20. package/engine/behaviour/ability/emulate-impact.d.ts +1 -1
  21. package/engine/behaviour/ability/emulate-impact.lua +11 -3
  22. package/engine/behaviour/ability/remove-buffs.d.ts +9 -0
  23. package/engine/behaviour/ability/remove-buffs.lua +21 -0
  24. package/engine/behaviour/ability/restore-mana.d.ts +1 -1
  25. package/engine/behaviour/ability/restore-mana.lua +6 -6
  26. package/engine/behaviour/ability.d.ts +2 -1
  27. package/engine/behaviour/ability.lua +10 -18
  28. package/engine/behaviour/unit/stun-immunity.d.ts +11 -5
  29. package/engine/behaviour/unit/stun-immunity.lua +53 -28
  30. package/engine/behaviour/unit.d.ts +39 -3
  31. package/engine/behaviour/unit.lua +259 -6
  32. package/engine/buff.d.ts +14 -6
  33. package/engine/buff.lua +145 -97
  34. package/engine/internal/ability.d.ts +7 -1
  35. package/engine/internal/ability.lua +49 -9
  36. package/engine/internal/item/ability.lua +63 -11
  37. package/engine/internal/item+owner.lua +12 -6
  38. package/engine/internal/item.d.ts +16 -16
  39. package/engine/internal/item.lua +135 -49
  40. package/engine/internal/misc/damage-metadata-by-target.d.ts +2 -0
  41. package/engine/internal/misc/damage-metadata-by-target.lua +5 -0
  42. package/engine/internal/misc/frame-coordinates.d.ts +2 -0
  43. package/engine/internal/misc/frame-coordinates.lua +21 -0
  44. package/engine/internal/misc/get-terrain-z.d.ts +2 -0
  45. package/engine/internal/misc/get-terrain-z.lua +11 -0
  46. package/engine/internal/misc/player-local-handle.d.ts +2 -0
  47. package/engine/internal/misc/player-local-handle.lua +5 -0
  48. package/engine/internal/unit/ability.d.ts +35 -0
  49. package/engine/internal/unit/ability.lua +98 -9
  50. package/engine/internal/unit/allowed-targets.d.ts +1 -1
  51. package/engine/internal/unit/allowed-targets.lua +9 -1
  52. package/engine/internal/unit/fly-height.d.ts +7 -0
  53. package/engine/internal/unit/fly-height.lua +20 -0
  54. package/engine/internal/unit/main-selected.lua +12 -27
  55. package/engine/internal/unit/order.d.ts +20 -0
  56. package/engine/internal/unit/order.lua +136 -0
  57. package/engine/internal/unit/scale.d.ts +7 -0
  58. package/engine/internal/unit/scale.lua +20 -0
  59. package/engine/internal/unit+ability.lua +10 -1
  60. package/engine/internal/unit+damage.d.ts +1 -1
  61. package/engine/internal/unit+damage.lua +6 -1
  62. package/engine/internal/unit-missile-launch.lua +45 -14
  63. package/engine/internal/unit.d.ts +31 -18
  64. package/engine/internal/unit.lua +289 -165
  65. package/engine/local-client.d.ts +2 -0
  66. package/engine/local-client.lua +30 -0
  67. package/engine/object-data/auxiliary/armor-type.d.ts +11 -0
  68. package/engine/object-data/auxiliary/armor-type.lua +46 -0
  69. package/engine/object-data/entry/ability-type/permanent-invisibility.d.ts +8 -0
  70. package/engine/object-data/entry/ability-type/permanent-invisibility.lua +26 -0
  71. package/engine/object-data/entry/ability-type.lua +5 -4
  72. package/engine/object-data/entry/destructible-type.d.ts +27 -1
  73. package/engine/object-data/entry/destructible-type.lua +155 -0
  74. package/engine/object-data/entry/unit-type.d.ts +15 -2
  75. package/engine/object-data/entry/unit-type.lua +135 -33
  76. package/engine/object-field/ability.d.ts +3 -3
  77. package/engine/object-field/ability.lua +7 -6
  78. package/engine/object-field/unit.d.ts +24 -1
  79. package/engine/object-field/unit.lua +91 -0
  80. package/engine/object-field.d.ts +15 -6
  81. package/engine/object-field.lua +258 -123
  82. package/engine/random.d.ts +9 -0
  83. package/engine/random.lua +13 -0
  84. package/engine/standard/fields/ability.d.ts +2 -2
  85. package/engine/standard/fields/ability.lua +2 -2
  86. package/engine/standard/fields/unit.d.ts +6 -0
  87. package/engine/standard/fields/unit.lua +11 -0
  88. package/engine/synchronization.d.ts +11 -0
  89. package/engine/synchronization.lua +77 -0
  90. package/engine/text-tag.d.ts +36 -2
  91. package/engine/text-tag.lua +250 -10
  92. package/engine/unit.d.ts +3 -0
  93. package/engine/unit.lua +3 -0
  94. package/net/socket.lua +1 -1
  95. package/objutil/buff.lua +1 -1
  96. package/package.json +2 -2
  97. package/patch-lualib.lua +1 -1
  98. package/utility/arrays.d.ts +2 -0
  99. package/utility/arrays.lua +11 -0
  100. package/utility/callback-array.d.ts +17 -0
  101. package/utility/callback-array.lua +61 -0
  102. package/utility/functions.d.ts +8 -0
  103. package/utility/functions.lua +13 -0
  104. package/utility/linked-set.d.ts +1 -0
  105. package/utility/linked-set.lua +19 -1
  106. package/utility/lua-maps.d.ts +12 -2
  107. package/utility/lua-maps.lua +37 -2
  108. package/utility/lua-sets.d.ts +1 -0
  109. package/utility/lua-sets.lua +4 -0
  110. package/utility/types.d.ts +3 -0
  111. package/core/types/order.d.ts +0 -25
  112. package/core/types/order.lua +0 -55
@@ -56,13 +56,18 @@ local ignoreEventsItems = ____ignore_2Devents_2Ditems.ignoreEventsItems
56
56
  local ____attack_2Dtype = require("engine.object-data.auxiliary.attack-type")
57
57
  local attackTypeToNative = ____attack_2Dtype.attackTypeToNative
58
58
  local nativeToAttackType = ____attack_2Dtype.nativeToAttackType
59
+ local ____damage_2Dmetadata_2Dby_2Dtarget = require("engine.internal.misc.damage-metadata-by-target")
60
+ local damageMetadataByTarget = ____damage_2Dmetadata_2Dby_2Dtarget.damageMetadataByTarget
61
+ local ____attributes = require("attributes")
62
+ local isAttribute = ____attributes.isAttribute
63
+ local ____ability = require("engine.internal.item.ability")
64
+ local doUnitAbilityAction = ____ability.doUnitAbilityAction
65
+ local ____synchronization = require("engine.synchronization")
66
+ local synchronizer = ____synchronization.synchronizer
59
67
  local match = string.match
60
68
  local ____tostring = _G.tostring
61
69
  local setUnitAnimation = SetUnitAnimation
62
- local setUnitAnimationWithRarity = SetUnitAnimationWithRarity
63
70
  local setUnitAnimationByIndex = SetUnitAnimationByIndex
64
- local resetUnitAnimation = ResetUnitAnimation
65
- local queueUnitAnimation = QueueUnitAnimation
66
71
  local getUnitIntegerField = BlzGetUnitIntegerField
67
72
  local getUnitRealField = BlzGetUnitRealField
68
73
  local getHeroStr = GetHeroStr
@@ -84,7 +89,6 @@ local getHandleId = GetHandleId
84
89
  local getUnitCurrentOrder = GetUnitCurrentOrder
85
90
  local createUnit = CreateUnit
86
91
  local killUnit = KillUnit
87
- local setUnitExploded = SetUnitExploded
88
92
  local removeUnit = RemoveUnit
89
93
  local getUnitTypeId = GetUnitTypeId
90
94
  local isHeroUnitId = IsHeroUnitId
@@ -100,8 +104,6 @@ local getSpellTargetItem = GetSpellTargetItem
100
104
  local getSpellTargetDestructable = GetSpellTargetDestructable
101
105
  local isUnitInRangeXY = IsUnitInRangeXY
102
106
  local isUnitInRange = IsUnitInRange
103
- local setResourceAmount = SetResourceAmount
104
- local getResourceAmount = GetResourceAmount
105
107
  local getUnitWeaponRealField = BlzGetUnitWeaponRealField
106
108
  local setUnitWeaponRealField = BlzSetUnitWeaponRealField
107
109
  local getUnitWeaponStringField = BlzGetUnitWeaponStringField
@@ -125,15 +127,9 @@ local getOrderedUnit = GetOrderedUnit
125
127
  local getIssuedOrderId = GetIssuedOrderId
126
128
  local isUnitInvulnerable = BlzIsUnitInvulnerable
127
129
  local unitAlive = UnitAlive
128
- local unitAddType = UnitAddType
129
- local unitRemoveType = UnitRemoveType
130
- local isUnitIllusion = IsUnitIllusion
131
- local isUnitType = IsUnitType
132
130
  local isUnitAlly = IsUnitAlly
133
131
  local isUnitEnemy = IsUnitEnemy
134
132
  local getOwningPlayer = GetOwningPlayer
135
- local setUnitColor = SetUnitColor
136
- local showUnitTeamGlow = BlzShowUnitTeamGlow
137
133
  ____exports.UnitClassification = {}
138
134
  local UnitClassification = ____exports.UnitClassification
139
135
  do
@@ -143,6 +139,7 @@ do
143
139
  UnitClassification.GROUND = UNIT_TYPE_GROUND
144
140
  UnitClassification.SUMMONED = UNIT_TYPE_SUMMONED
145
141
  UnitClassification.MECHANICAL = UNIT_TYPE_MECHANICAL
142
+ UnitClassification.WORKER = UNIT_TYPE_PEON
146
143
  UnitClassification.ANCIENT = UNIT_TYPE_ANCIENT
147
144
  UnitClassification.SUICIDAL = UNIT_TYPE_SAPPER
148
145
  UnitClassification.TAUREN = UNIT_TYPE_TAUREN
@@ -350,6 +347,9 @@ local function dispatchAbility(event)
350
347
  }
351
348
  )
352
349
  end
350
+ local function damagingEventPreventRetaliation(self)
351
+ self[0] = true
352
+ end
353
353
  local function damageEventPreventDeath(self, callback, ...)
354
354
  if self[0] ~= nil then
355
355
  return
@@ -412,6 +412,19 @@ function UnitWeapon.prototype.____constructor(self, unit, index)
412
412
  self.unit = unit
413
413
  self.index = index
414
414
  end
415
+ __TS__SetDescriptor(
416
+ UnitWeapon.prototype,
417
+ "isEnabled",
418
+ {
419
+ get = function(self)
420
+ return BlzGetUnitWeaponBooleanField(self.unit.handle, UNIT_WEAPON_BF_ATTACKS_ENABLED, self.index)
421
+ end,
422
+ set = function(self, isEnabled)
423
+ BlzSetUnitWeaponBooleanField(self.unit.handle, UNIT_WEAPON_BF_ATTACKS_ENABLED, self.index, isEnabled)
424
+ end
425
+ },
426
+ true
427
+ )
415
428
  __TS__SetDescriptor(
416
429
  UnitWeapon.prototype,
417
430
  "cooldown",
@@ -446,6 +459,19 @@ __TS__SetDescriptor(
446
459
  },
447
460
  true
448
461
  )
462
+ __TS__SetDescriptor(
463
+ UnitWeapon.prototype,
464
+ "allowedTargetCombatClassifications",
465
+ {
466
+ get = function(self)
467
+ return BlzGetUnitWeaponIntegerField(self.unit.handle, UNIT_WEAPON_IF_ATTACK_TARGETS_ALLOWED, self.index)
468
+ end,
469
+ set = function(self, allowedTargetCombatClassifications)
470
+ BlzSetUnitWeaponIntegerField(self.unit.handle, UNIT_WEAPON_IF_ATTACK_TARGETS_ALLOWED, self.index, allowedTargetCombatClassifications)
471
+ end
472
+ },
473
+ true
474
+ )
449
475
  __TS__SetDescriptor(
450
476
  UnitWeapon.prototype,
451
477
  "damageBase",
@@ -633,15 +659,15 @@ for ____, player in ipairs(Player.all) do
633
659
  dummies[player] = dummy
634
660
  end
635
661
  local function delayHealthChecksCallback(unit)
636
- local counter = (unit[103] or 0) - 1
662
+ local counter = (unit[104] or 0) - 1
637
663
  if counter ~= 0 then
638
- unit[103] = counter
664
+ unit[104] = counter
639
665
  return
640
666
  end
641
- unit[103] = nil
642
- local healthBonus = unit[104]
667
+ unit[104] = nil
668
+ local healthBonus = unit[105]
643
669
  if healthBonus ~= nil then
644
- unit[104] = nil
670
+ unit[105] = nil
645
671
  local handle = unit.handle
646
672
  BlzSetUnitMaxHP(
647
673
  handle,
@@ -650,16 +676,26 @@ local function delayHealthChecksCallback(unit)
650
676
  end
651
677
  end
652
678
  local nextSyncId = 1
653
- local unitBySyncId = setmetatable({}, {__mode = "k"})
679
+ local unitBySyncId = setmetatable({}, {__mode = "v"})
680
+ local damagingEventByTarget = setmetatable({}, {__mode = "k"})
681
+ local function addAbility(unit, abilityTypeId)
682
+ local ____unitAddAbility_result_0
683
+ if unitAddAbility(unit, abilityTypeId) then
684
+ ____unitAddAbility_result_0 = getUnitAbility(unit, abilityTypeId)
685
+ else
686
+ ____unitAddAbility_result_0 = nil
687
+ end
688
+ return ____unitAddAbility_result_0
689
+ end
654
690
  ____exports.Unit = __TS__Class()
655
691
  local Unit = ____exports.Unit
656
692
  Unit.name = "Unit"
657
693
  __TS__ClassExtends(Unit, Handle)
658
694
  function Unit.prototype.____constructor(self, handle)
659
695
  Handle.prototype.____constructor(self, handle)
660
- local ____nextSyncId_0 = nextSyncId
661
- nextSyncId = ____nextSyncId_0 + 1
662
- self.syncId = ____nextSyncId_0
696
+ local ____nextSyncId_1 = nextSyncId
697
+ nextSyncId = ____nextSyncId_1 + 1
698
+ self.syncId = ____nextSyncId_1
663
699
  self._owner = Player:of(getOwningPlayer(handle))
664
700
  assert(unitAddAbility(handle, leaveDetectAbilityId) and UnitMakeAbilityPermanent(handle, true, leaveDetectAbilityId))
665
701
  assert(unitAddAbility(handle, morphDetectAbilityId))
@@ -691,8 +727,8 @@ function Unit.prototype.getEvent(self, event, collector)
691
727
  end
692
728
  function Unit.prototype.onDestroy(self)
693
729
  local handle = self.handle
694
- self[107] = getUnitX(handle)
695
- self[108] = getUnitY(handle)
730
+ self[108] = getUnitX(handle)
731
+ self[109] = getUnitY(handle)
696
732
  if not self._owner then
697
733
  self._owner = Player:of(getOwningPlayer(handle))
698
734
  end
@@ -760,17 +796,17 @@ function Unit.prototype.addModifier(self, property, modifier)
760
796
  end}
761
797
  end
762
798
  function Unit.prototype.hasCombatClassification(self, combatClassification)
763
- local ____combatClassification_1 = combatClassification
764
- return getUnitIntegerField(self.handle, UNIT_IF_TARGETED_AS) & ____combatClassification_1 == ____combatClassification_1
799
+ local ____combatClassification_2 = combatClassification
800
+ return getUnitIntegerField(self.handle, UNIT_IF_TARGETED_AS) & ____combatClassification_2 == ____combatClassification_2
765
801
  end
766
802
  function Unit.prototype.addClassification(self, classification)
767
- return unitAddType(self.handle, classification)
803
+ return UnitAddType(self.handle, classification)
768
804
  end
769
805
  function Unit.prototype.removeClassification(self, classification)
770
- return unitRemoveType(self.handle, classification)
806
+ return UnitRemoveType(self.handle, classification)
771
807
  end
772
808
  function Unit.prototype.hasClassification(self, classification)
773
- return isUnitType(self.handle, classification)
809
+ return IsUnitType(self.handle, classification)
774
810
  end
775
811
  function Unit.prototype.isVisibleTo(self, player)
776
812
  return isUnitVisible(self.handle, player.handle)
@@ -779,13 +815,13 @@ function Unit.prototype.isInvisibleTo(self, player)
779
815
  return isUnitInvisible(self.handle, player.handle)
780
816
  end
781
817
  function Unit.prototype.isInRangeOf(self, x, y, range)
782
- local ____temp_2
818
+ local ____temp_3
783
819
  if type(x) == "number" then
784
- ____temp_2 = isUnitInRangeXY(self.handle, x, y, range)
820
+ ____temp_3 = isUnitInRangeXY(self.handle, x, y, range)
785
821
  else
786
- ____temp_2 = isUnitInRange(self.handle, x.handle, y)
822
+ ____temp_3 = isUnitInRange(self.handle, x.handle, y)
787
823
  end
788
- return ____temp_2
824
+ return ____temp_3
789
825
  end
790
826
  function Unit.prototype.isAllyOf(self, unit)
791
827
  return isUnitAlly(
@@ -803,19 +839,30 @@ function Unit.prototype.playAnimation(self, animation, rarity)
803
839
  if type(animation) == "number" then
804
840
  setUnitAnimationByIndex(self.handle, animation)
805
841
  elseif rarity then
806
- setUnitAnimationWithRarity(self.handle, animation, rarity)
842
+ SetUnitAnimationWithRarity(self.handle, animation, rarity)
807
843
  else
808
844
  setUnitAnimation(self.handle, animation)
809
845
  end
810
846
  end
811
847
  function Unit.prototype.resetAnimation(self)
812
- resetUnitAnimation(self.handle)
848
+ ResetUnitAnimation(self.handle)
813
849
  end
814
850
  function Unit.prototype.queueAnimation(self, animation)
815
- queueUnitAnimation(self.handle, animation)
851
+ QueueUnitAnimation(self.handle, animation)
852
+ end
853
+ function Unit.prototype.chooseWeapon(self, target)
854
+ local firstWeapon = self.firstWeapon
855
+ if firstWeapon.isEnabled and target:isAllowedTarget(self, firstWeapon.allowedTargetCombatClassifications) then
856
+ return firstWeapon
857
+ end
858
+ local secondWeapon = self.secondWeapon
859
+ if secondWeapon.isEnabled and target:isAllowedTarget(target, secondWeapon.allowedTargetCombatClassifications) then
860
+ return secondWeapon
861
+ end
862
+ return nil
816
863
  end
817
864
  function Unit.prototype.delayHealthChecks(self)
818
- self[103] = (self[103] or 0) + 1
865
+ self[104] = (self[104] or 0) + 1
819
866
  Timer:run(delayHealthChecksCallback, self)
820
867
  end
821
868
  function Unit.prototype.setPosition(self, x, y)
@@ -825,21 +872,21 @@ function Unit.prototype.isSelected(self, player)
825
872
  return IsUnitSelected(self.handle, player.handle)
826
873
  end
827
874
  function Unit.prototype.explode(self)
828
- setUnitExploded(self.handle, true)
875
+ SetUnitExploded(self.handle, true)
829
876
  killUnit(self.handle)
830
877
  end
831
878
  function Unit.prototype.kill(self)
832
879
  killUnit(self.handle)
833
880
  end
834
881
  function Unit.prototype.revive(self, x, y, doEffect)
835
- local ____ReviveHero_5 = ReviveHero
836
- local ____array_4 = __TS__SparseArrayNew(self.handle, x, y)
837
- local ____doEffect_3 = doEffect
838
- if ____doEffect_3 == nil then
839
- ____doEffect_3 = false
882
+ local ____ReviveHero_6 = ReviveHero
883
+ local ____array_5 = __TS__SparseArrayNew(self.handle, x, y)
884
+ local ____doEffect_4 = doEffect
885
+ if ____doEffect_4 == nil then
886
+ ____doEffect_4 = false
840
887
  end
841
- __TS__SparseArrayPush(____array_4, ____doEffect_3)
842
- ____ReviveHero_5(__TS__SparseArraySpread(____array_4))
888
+ __TS__SparseArrayPush(____array_5, ____doEffect_4)
889
+ ____ReviveHero_6(__TS__SparseArraySpread(____array_5))
843
890
  end
844
891
  function Unit.prototype.healTarget(self, target, amount)
845
892
  if __TS__InstanceOf(target, ____exports.Unit) and target:hasAbility(fourCC("BIhm")) then
@@ -882,17 +929,16 @@ function Unit.prototype.itemInSlot(self, slot)
882
929
  return Item:of(unitItemInSlot(self.handle, slot))
883
930
  end
884
931
  function Unit.prototype.addAbility(self, abilityId)
885
- if unitAddAbility(self.handle, abilityId) then
886
- local ability = UnitAbility:of(
887
- checkNotNull(getUnitAbility(self.handle, abilityId)),
888
- abilityId,
889
- self
890
- )
932
+ local ability = UnitAbility:of(
933
+ doUnitAbilityAction(self.handle, abilityId, addAbility, abilityId),
934
+ abilityId,
935
+ self
936
+ )
937
+ if ability ~= nil then
891
938
  local abilities = self.abilities
892
939
  abilities[#abilities + 1] = ability
893
- return ability
894
940
  end
895
- return nil
941
+ return ability
896
942
  end
897
943
  function Unit.prototype.makeAbilityPermanent(self, abilityId, permanent)
898
944
  return UnitMakeAbilityPermanent(self.handle, permanent, abilityId)
@@ -906,31 +952,21 @@ end
906
952
  function Unit.prototype.hasAbility(self, abilityId)
907
953
  return getUnitAbilityLevel(self.handle, abilityId) > 0
908
954
  end
909
- function Unit.prototype.getAbilityById(self, abilityId)
910
- local handle = self.handle
911
- if unitAddAbility(handle, abilityId) then
912
- assert(unitRemoveAbility(handle, abilityId))
913
- return nil
914
- end
915
- return UnitAbility:of(
916
- getUnitAbility(self.handle, abilityId),
917
- abilityId,
918
- self
919
- )
955
+ function Unit.prototype.getAbility(self, abilityId)
956
+ local ability = doUnitAbilityAction(self.handle, abilityId, getUnitAbility, abilityId)
957
+ return UnitAbility:of(ability, abilityId, self)
920
958
  end
921
- function Unit.prototype.removeAbility(self, abilityId)
922
- if unitRemoveAbility(self.handle, abilityId) then
923
- local abilities = self.abilities
924
- for i = 1, #abilities do
925
- if abilities[i].typeId == abilityId then
926
- abilities[i]:destroy()
927
- tremove(abilities, i)
928
- return true
929
- end
959
+ function Unit.prototype.removeAbility(self, abilityTypeId)
960
+ local abilities = self.abilities
961
+ for i = 1, #abilities do
962
+ if abilities[i].typeId == abilityTypeId then
963
+ local ability = abilities[i]
964
+ tremove(abilities, i)
965
+ ability:destroy()
966
+ return true
930
967
  end
931
- return true
932
968
  end
933
- return false
969
+ return doUnitAbilityAction(self.handle, abilityTypeId, unitRemoveAbility, abilityTypeId)
934
970
  end
935
971
  function Unit.prototype.hideAbility(self, abilityId, flag)
936
972
  BlzUnitHideAbility(self.handle, abilityId, flag)
@@ -944,6 +980,21 @@ end
944
980
  function Unit.prototype.endAbilityCooldown(self, abilityId)
945
981
  BlzEndUnitAbilityCooldown(self.handle, abilityId)
946
982
  end
983
+ function Unit.prototype.interruptMovement(self)
984
+ local handle = self.handle
985
+ unitDisableAbility(
986
+ handle,
987
+ fourCC("Amov"),
988
+ true,
989
+ false
990
+ )
991
+ unitDisableAbility(
992
+ handle,
993
+ fourCC("Amov"),
994
+ false,
995
+ false
996
+ )
997
+ end
947
998
  function Unit.prototype.interruptAttack(self)
948
999
  unitInterruptAttack(self.handle)
949
1000
  end
@@ -1017,18 +1068,44 @@ function Unit.prototype.unpauseEx(self)
1017
1068
  end
1018
1069
  function Unit.prototype.incrementStunCounter(self)
1019
1070
  local stunCounter = self[102] or 0
1020
- if not self[101] or stunCounter >= 0 then
1071
+ if not self[101] and (self[103] or 0) <= 0 or stunCounter >= 0 then
1021
1072
  BlzPauseUnitEx(self.handle, true)
1022
1073
  end
1023
1074
  self[102] = stunCounter + 1
1024
1075
  end
1025
1076
  function Unit.prototype.decrementStunCounter(self)
1026
1077
  local stunCounter = self[102] or 0
1027
- if not self[101] or stunCounter >= 1 then
1078
+ if not self[101] and (self[103] or 0) <= 0 or stunCounter >= 1 then
1028
1079
  BlzPauseUnitEx(self.handle, false)
1029
1080
  end
1030
1081
  self[102] = stunCounter - 1
1031
1082
  end
1083
+ function Unit.prototype.incrementForceStunCounter(self)
1084
+ local forceStunCounter = self[103] or 0
1085
+ if forceStunCounter == 0 then
1086
+ local handle = self.handle
1087
+ if not self[101] then
1088
+ for _ = self[102] or 0, -1 do
1089
+ BlzPauseUnitEx(handle, true)
1090
+ end
1091
+ end
1092
+ BlzPauseUnitEx(handle, true)
1093
+ end
1094
+ self[103] = forceStunCounter + 1
1095
+ end
1096
+ function Unit.prototype.decrementForceStunCounter(self)
1097
+ local forceStunCounter = self[103] or 0
1098
+ if forceStunCounter == 1 then
1099
+ local handle = self.handle
1100
+ if not self[101] then
1101
+ for _ = self[102] or 0, -1 do
1102
+ BlzPauseUnitEx(handle, false)
1103
+ end
1104
+ end
1105
+ BlzPauseUnitEx(handle, false)
1106
+ end
1107
+ self[103] = forceStunCounter - 1
1108
+ end
1032
1109
  function Unit.create(self, owner, id, x, y, facing, skinId)
1033
1110
  local handle = skinId and BlzCreateUnitWithSkin(
1034
1111
  owner.handle,
@@ -1217,7 +1294,7 @@ __TS__SetDescriptor(
1217
1294
  Unit.prototype,
1218
1295
  "isIllusion",
1219
1296
  {get = function(self)
1220
- return isUnitIllusion(self.handle)
1297
+ return IsUnitIllusion(self.handle)
1221
1298
  end},
1222
1299
  true
1223
1300
  )
@@ -1436,17 +1513,17 @@ __TS__SetDescriptor(
1436
1513
  "isTeamGlowVisible",
1437
1514
  {
1438
1515
  get = function(self)
1439
- return not self[106]
1516
+ return not self[107]
1440
1517
  end,
1441
1518
  set = function(self, isTeamGlowVisible)
1442
- showUnitTeamGlow(self.handle, isTeamGlowVisible)
1443
- local ____temp_6
1519
+ BlzShowUnitTeamGlow(self.handle, isTeamGlowVisible)
1520
+ local ____temp_7
1444
1521
  if not isTeamGlowVisible then
1445
- ____temp_6 = true
1522
+ ____temp_7 = true
1446
1523
  else
1447
- ____temp_6 = nil
1524
+ ____temp_7 = nil
1448
1525
  end
1449
- self[106] = ____temp_6
1526
+ self[107] = ____temp_7
1450
1527
  end
1451
1528
  },
1452
1529
  true
@@ -1455,9 +1532,9 @@ __TS__SetDescriptor(
1455
1532
  Unit.prototype,
1456
1533
  "color",
1457
1534
  {set = function(self, color)
1458
- setUnitColor(self.handle, color.handle)
1459
- if self[106] then
1460
- showUnitTeamGlow(self.handle, false)
1535
+ SetUnitColor(self.handle, color.handle)
1536
+ if self[107] then
1537
+ BlzShowUnitTeamGlow(self.handle, false)
1461
1538
  end
1462
1539
  end},
1463
1540
  true
@@ -1480,14 +1557,14 @@ __TS__SetDescriptor(
1480
1557
  "maxHealth",
1481
1558
  {
1482
1559
  get = function(self)
1483
- return BlzGetUnitMaxHP(self.handle) - (self[104] or 0) - (self[105] or 0)
1560
+ return BlzGetUnitMaxHP(self.handle) - (self[105] or 0) - (self[106] or 0)
1484
1561
  end,
1485
1562
  set = function(self, maxHealth)
1486
- if maxHealth < 1 and self[103] ~= nil then
1487
- self[104] = (self[104] or 0) + (1 - maxHealth)
1563
+ if maxHealth < 1 and self[104] ~= nil then
1564
+ self[105] = (self[105] or 0) + (1 - maxHealth)
1488
1565
  maxHealth = 1
1489
1566
  end
1490
- BlzSetUnitMaxHP(self.handle, maxHealth + (self[105] or 0))
1567
+ BlzSetUnitMaxHP(self.handle, maxHealth + (self[106] or 0))
1491
1568
  end
1492
1569
  },
1493
1570
  true
@@ -1529,10 +1606,10 @@ __TS__SetDescriptor(
1529
1606
  "health",
1530
1607
  {
1531
1608
  get = function(self)
1532
- return GetWidgetLife(self.handle) - (self[105] or 0)
1609
+ return GetWidgetLife(self.handle) - (self[106] or 0)
1533
1610
  end,
1534
1611
  set = function(self, health)
1535
- SetWidgetLife(self.handle, health + (self[105] or 0))
1612
+ SetWidgetLife(self.handle, health + (self[106] or 0))
1536
1613
  end
1537
1614
  },
1538
1615
  true
@@ -1608,25 +1685,12 @@ __TS__SetDescriptor(
1608
1685
  },
1609
1686
  true
1610
1687
  )
1611
- __TS__SetDescriptor(
1612
- Unit.prototype,
1613
- "flyHeight",
1614
- {
1615
- get = function(self)
1616
- return getUnitFlyHeight(self.handle)
1617
- end,
1618
- set = function(self, v)
1619
- SetUnitFlyHeight(self.handle, v, 100000)
1620
- end
1621
- },
1622
- true
1623
- )
1624
1688
  __TS__SetDescriptor(
1625
1689
  Unit.prototype,
1626
1690
  "x",
1627
1691
  {
1628
1692
  get = function(self)
1629
- return self[107] or getUnitX(self.handle)
1693
+ return self[108] or getUnitX(self.handle)
1630
1694
  end,
1631
1695
  set = function(self, v)
1632
1696
  SetUnitX(self.handle, v)
@@ -1639,7 +1703,7 @@ __TS__SetDescriptor(
1639
1703
  "y",
1640
1704
  {
1641
1705
  get = function(self)
1642
- return self[108] or getUnitY(self.handle)
1706
+ return self[109] or getUnitY(self.handle)
1643
1707
  end,
1644
1708
  set = function(self, v)
1645
1709
  SetUnitY(self.handle, v)
@@ -1725,10 +1789,10 @@ __TS__SetDescriptor(
1725
1789
  "gold",
1726
1790
  {
1727
1791
  get = function(self)
1728
- return getResourceAmount(self.handle)
1792
+ return GetResourceAmount(self.handle)
1729
1793
  end,
1730
1794
  set = function(self, gold)
1731
- setResourceAmount(self.handle, gold)
1795
+ SetResourceAmount(self.handle, gold)
1732
1796
  end
1733
1797
  },
1734
1798
  true
@@ -1744,14 +1808,18 @@ __TS__SetDescriptor(
1744
1808
  local handle = self.handle
1745
1809
  if isPaused and not IsUnitPaused(handle) then
1746
1810
  self[101] = true
1747
- for _ = self[102] or 0, -1 do
1748
- BlzPauseUnitEx(handle, true)
1811
+ if (self[103] or 0) <= 0 then
1812
+ for _ = self[102] or 0, -1 do
1813
+ BlzPauseUnitEx(handle, true)
1814
+ end
1749
1815
  end
1750
1816
  PauseUnit(handle, true)
1751
1817
  elseif not isPaused and IsUnitPaused(handle) then
1752
1818
  PauseUnit(handle, false)
1753
- for _ = self[102] or 0, -1 do
1754
- BlzPauseUnitEx(handle, false)
1819
+ if (self[103] or 0) <= 0 then
1820
+ for _ = self[102] or 0, -1 do
1821
+ BlzPauseUnitEx(handle, false)
1822
+ end
1755
1823
  end
1756
1824
  self[101] = nil
1757
1825
  end
@@ -1809,20 +1877,6 @@ __TS__SetDescriptor(
1809
1877
  },
1810
1878
  true
1811
1879
  )
1812
- __TS__SetDescriptor(
1813
- Unit.prototype,
1814
- "scale",
1815
- {
1816
- get = function(self)
1817
- return getUnitRealField(self.handle, UNIT_RF_SCALING_VALUE)
1818
- end,
1819
- set = function(self, v)
1820
- setUnitScale(self.handle, v, v, v)
1821
- setUnitRealField(self.handle, UNIT_RF_SCALING_VALUE, v)
1822
- end
1823
- },
1824
- true
1825
- )
1826
1880
  __TS__SetDescriptor(
1827
1881
  Unit.prototype,
1828
1882
  "timeScale",
@@ -2050,6 +2104,14 @@ __TS__SetDescriptor(
2050
2104
  end},
2051
2105
  true
2052
2106
  )
2107
+ __TS__SetDescriptor(
2108
+ Unit.prototype,
2109
+ "targetAcquiredEvent",
2110
+ {get = function(self)
2111
+ return self:getEvent(EVENT_UNIT_ACQUIRED_TARGET)
2112
+ end},
2113
+ true
2114
+ )
2053
2115
  __TS__SetDescriptor(
2054
2116
  Unit.prototype,
2055
2117
  "onSelect",
@@ -2185,25 +2247,25 @@ Unit.onTargetCast = dispatchId(__TS__New(
2185
2247
  InitializingEvent,
2186
2248
  function(event)
2187
2249
  local function listener(unit, id)
2188
- local ____GetSpellTargetUnit_result_9
2250
+ local ____GetSpellTargetUnit_result_10
2189
2251
  if GetSpellTargetUnit() then
2190
- ____GetSpellTargetUnit_result_9 = ____exports.Unit:of(GetSpellTargetUnit())
2252
+ ____GetSpellTargetUnit_result_10 = ____exports.Unit:of(GetSpellTargetUnit())
2191
2253
  else
2192
- local ____GetSpellTargetItem_result_8
2254
+ local ____GetSpellTargetItem_result_9
2193
2255
  if GetSpellTargetItem() then
2194
- ____GetSpellTargetItem_result_8 = Item:of(GetSpellTargetItem())
2256
+ ____GetSpellTargetItem_result_9 = Item:of(GetSpellTargetItem())
2195
2257
  else
2196
- local ____GetSpellTargetDestructable_result_7
2258
+ local ____GetSpellTargetDestructable_result_8
2197
2259
  if GetSpellTargetDestructable() then
2198
- ____GetSpellTargetDestructable_result_7 = Destructable:of(GetSpellTargetDestructable())
2260
+ ____GetSpellTargetDestructable_result_8 = Destructable:of(GetSpellTargetDestructable())
2199
2261
  else
2200
- ____GetSpellTargetDestructable_result_7 = nil
2262
+ ____GetSpellTargetDestructable_result_8 = nil
2201
2263
  end
2202
- ____GetSpellTargetItem_result_8 = ____GetSpellTargetDestructable_result_7
2264
+ ____GetSpellTargetItem_result_9 = ____GetSpellTargetDestructable_result_8
2203
2265
  end
2204
- ____GetSpellTargetUnit_result_9 = ____GetSpellTargetItem_result_8
2266
+ ____GetSpellTargetUnit_result_10 = ____GetSpellTargetItem_result_9
2205
2267
  end
2206
- local target = ____GetSpellTargetUnit_result_9
2268
+ local target = ____GetSpellTargetUnit_result_10
2207
2269
  if target then
2208
2270
  invoke(event, unit, id, target)
2209
2271
  end
@@ -2411,38 +2473,57 @@ Unit.onDamaging = (function()
2411
2473
  if source and source.typeId == dummyUnitId then
2412
2474
  source = nil
2413
2475
  end
2414
- local target = BlzGetEventDamageTarget()
2476
+ local target = ____exports.Unit:of(BlzGetEventDamageTarget())
2477
+ local metadata = damageMetadataByTarget[target]
2478
+ damageMetadataByTarget[target] = nil
2415
2479
  local data = {
2416
2480
  amount = GetEventDamage(),
2417
2481
  attackType = nativeToAttackType(BlzGetEventAttackType()),
2418
2482
  damageType = BlzGetEventDamageType(),
2419
2483
  weaponType = BlzGetEventWeaponType(),
2420
- isAttack = BlzGetEventIsAttack()
2484
+ metadata = metadata,
2485
+ isAttack = BlzGetEventIsAttack(),
2486
+ originalAmount = GetEventDamage(),
2487
+ originalMetadata = metadata,
2488
+ preventRetaliation = damagingEventPreventRetaliation
2421
2489
  }
2422
2490
  if data.isAttack and source then
2423
- 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
2424
- if weapon == -1 then
2425
- local targetsAllowed = BlzGetUnitWeaponIntegerField(source.handle, UNIT_WEAPON_IF_ATTACK_TARGETS_ALLOWED, 0)
2426
- weapon = 0
2427
- end
2428
- data.weapon = assert(source.weapons[weapon + 1])
2491
+ data.weapon = source:chooseWeapon(target)
2429
2492
  end
2430
2493
  if not data.isAttack or not source or not source._attackHandlers then
2431
2494
  invoke(
2432
2495
  event,
2433
2496
  source,
2434
- ____exports.Unit:of(target),
2497
+ target,
2435
2498
  setmetatable(
2436
2499
  {},
2437
2500
  {
2438
2501
  __index = data,
2439
2502
  __newindex = function(self, key, value)
2440
- damageSetters[key](value)
2503
+ local damageSetter = damageSetters[key]
2504
+ if damageSetter ~= nil then
2505
+ damageSetter(value)
2506
+ end
2441
2507
  data[key] = value
2442
2508
  end
2443
2509
  }
2444
2510
  )
2445
2511
  )
2512
+ if data[0] and source then
2513
+ local sourceOwner = source.owner.handle
2514
+ data[1] = sourceOwner
2515
+ local targetOwner = target.owner.handle
2516
+ data[2] = targetOwner
2517
+ if not GetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE) then
2518
+ SetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE, true)
2519
+ data[3] = true
2520
+ end
2521
+ if not GetPlayerAlliance(targetOwner, sourceOwner, ALLIANCE_PASSIVE) then
2522
+ SetPlayerAlliance(targetOwner, sourceOwner, ALLIANCE_PASSIVE, true)
2523
+ data[4] = true
2524
+ end
2525
+ end
2526
+ damagingEventByTarget[target] = data
2446
2527
  return
2447
2528
  end
2448
2529
  BlzSetEventDamage(0)
@@ -2450,7 +2531,7 @@ Unit.onDamaging = (function()
2450
2531
  BlzSetEventDamageType(DAMAGE_TYPE_UNKNOWN)
2451
2532
  BlzSetEventWeaponType(WEAPON_TYPE_WHOKNOWS)
2452
2533
  local sourceOwner = source.owner.handle
2453
- local targetOwner = GetOwningPlayer(target)
2534
+ local targetOwner = target.owner.handle
2454
2535
  if not GetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE) then
2455
2536
  SetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE, true)
2456
2537
  Timer:run(function()
@@ -2466,19 +2547,15 @@ Unit.onDamaging = (function()
2466
2547
  for ____, ____value in ipairs(source._attackHandlers) do
2467
2548
  local condition = ____value[1]
2468
2549
  local action = ____value[2]
2469
- if condition(
2470
- source,
2471
- ____exports.Unit:of(target),
2472
- data
2473
- ) then
2550
+ if condition(source, target, data) then
2474
2551
  action(
2475
2552
  source,
2476
- ____exports.Unit:of(target),
2553
+ target,
2477
2554
  setmetatable(
2478
2555
  {fire = function()
2479
2556
  UnitDamageTarget(
2480
2557
  source.handle,
2481
- target,
2558
+ target.handle,
2482
2559
  data.amount,
2483
2560
  true,
2484
2561
  true,
@@ -2509,30 +2586,54 @@ Unit.onDamage = __TS__New(
2509
2586
  if source and source.typeId == dummyUnitId then
2510
2587
  source = nil
2511
2588
  end
2589
+ local target = ____exports.Unit:of(BlzGetEventDamageTarget())
2590
+ local damagingEvent = damagingEventByTarget[target]
2591
+ damagingEventByTarget[target] = nil
2512
2592
  local data = {
2513
2593
  amount = GetEventDamage(),
2514
2594
  attackType = nativeToAttackType(BlzGetEventAttackType()),
2515
2595
  damageType = BlzGetEventDamageType(),
2516
2596
  weaponType = BlzGetEventWeaponType(),
2597
+ metadata = damagingEvent and damagingEvent.metadata,
2517
2598
  isAttack = BlzGetEventIsAttack(),
2518
- originalAmount = GetEventDamage(),
2599
+ originalAmount = damagingEvent and damagingEvent.originalAmount or GetEventDamage(),
2600
+ originalMetadata = damagingEvent and damagingEvent.originalMetadata,
2519
2601
  preventDeath = damageEventPreventDeath
2520
2602
  }
2603
+ if damagingEvent then
2604
+ for key, value in pairs(damagingEvent) do
2605
+ if isAttribute(key) then
2606
+ data[key] = value
2607
+ end
2608
+ end
2609
+ local sourceOwner = damagingEvent[1]
2610
+ if sourceOwner then
2611
+ local targetOwner = damagingEvent[2]
2612
+ if damagingEvent[3] then
2613
+ SetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE, false)
2614
+ end
2615
+ if damagingEvent[4] then
2616
+ SetPlayerAlliance(targetOwner, sourceOwner, ALLIANCE_PASSIVE, false)
2617
+ end
2618
+ end
2619
+ end
2521
2620
  local evData = setmetatable(
2522
2621
  {},
2523
2622
  {
2524
2623
  __index = data,
2525
2624
  __newindex = function(self, key, value)
2526
- damageSetters[key](value)
2625
+ local damageSetter = damageSetters[key]
2626
+ if damageSetter ~= nil then
2627
+ damageSetter(value)
2628
+ end
2527
2629
  data[key] = value
2528
2630
  end
2529
2631
  }
2530
2632
  )
2531
- local target = ____exports.Unit:of(BlzGetEventDamageTarget())
2532
2633
  invoke(event, source, target, evData)
2533
2634
  if evData[0] ~= nil and target.health - evData.amount < 0.405 then
2534
2635
  local bonusHealth = math.ceil(evData.amount)
2535
- target[105] = (target[105] or 0) + bonusHealth
2636
+ target[106] = (target[106] or 0) + bonusHealth
2536
2637
  BlzSetUnitMaxHP(
2537
2638
  target.handle,
2538
2639
  BlzGetUnitMaxHP(target.handle) + bonusHealth
@@ -2546,7 +2647,7 @@ Unit.onDamage = __TS__New(
2546
2647
  evData[0],
2547
2648
  table.unpack(evData, 1 + 1, 1 + (evData[1] or 0))
2548
2649
  )
2549
- target[105] = (target[105] or 0) - bonusHealth
2650
+ target[106] = (target[106] or 0) - bonusHealth
2550
2651
  SetWidgetLife(
2551
2652
  target.handle,
2552
2653
  GetWidgetLife(target.handle) - bonusHealth
@@ -2582,10 +2683,14 @@ Unit.itemPickedUpEvent = __TS__New(
2582
2683
  ____exports.UnitTriggerEvent,
2583
2684
  EVENT_PLAYER_UNIT_PICKUP_ITEM,
2584
2685
  function()
2585
- local unit = getTriggerUnit()
2586
- local item = getManipulatedItem()
2587
- if getUnitTypeId(unit) ~= dummyUnitId and not (ignoreEventsItems[item] ~= nil) then
2588
- return ____exports.Unit:of(unit), Item:of(item)
2686
+ local unitHandle = getTriggerUnit()
2687
+ local itemHandle = getManipulatedItem()
2688
+ if getUnitTypeId(unitHandle) ~= dummyUnitId and not (ignoreEventsItems[itemHandle] ~= nil) then
2689
+ local unit = ____exports.Unit:of(unitHandle)
2690
+ local item = Item:of(itemHandle)
2691
+ if item.owner ~= unit then
2692
+ return unit, item
2693
+ end
2589
2694
  end
2590
2695
  return IgnoreEvent
2591
2696
  end
@@ -2605,7 +2710,22 @@ Unit.itemUsedEvent = __TS__New(
2605
2710
  Unit.itemStackedEvent = __TS__New(
2606
2711
  ____exports.UnitTriggerEvent,
2607
2712
  EVENT_PLAYER_UNIT_STACK_ITEM,
2608
- function() return ____exports.Unit:of(getTriggerUnit()), Item:of(getManipulatedItem()) end
2713
+ function() return ____exports.Unit:of(getTriggerUnit()), Item:of(BlzGetStackingItemTarget()), Item:of(BlzGetStackingItemSource()) end
2714
+ )
2715
+ __TS__ObjectDefineProperty(
2716
+ Unit,
2717
+ "itemChargesChangedEvent",
2718
+ {get = function(self)
2719
+ local event = __TS__New(Event)
2720
+ Item.chargesChangedEvent:addListener(function(item)
2721
+ local unit = item.owner
2722
+ if unit ~= nil then
2723
+ invoke(event, unit, item)
2724
+ end
2725
+ end)
2726
+ rawset(self, "itemChargesChangedEvent", event)
2727
+ return event
2728
+ end}
2609
2729
  )
2610
2730
  __TS__ObjectDefineProperty(
2611
2731
  Unit,
@@ -2677,6 +2797,10 @@ __TS__ObjectDefineProperty(
2677
2797
  rawset(self, "destroyEvent", destroyEvent)
2678
2798
  return destroyEvent
2679
2799
  end}
2800
+ )
2801
+ Unit.synchronize = synchronizer(
2802
+ function(unit) return unit.syncId end,
2803
+ function(syncId) return unitBySyncId[syncId] end
2680
2804
  );
2681
2805
  (function(self)
2682
2806
  local leaveAbilityIds = postcompile(function()