warscript 0.0.1-dev.9ee7706 → 0.0.1-dev.a0cb707

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 (126) hide show
  1. package/attributes.d.ts +6 -0
  2. package/attributes.lua +17 -1
  3. package/core/types/effect.d.ts +1 -3
  4. package/core/types/effect.lua +26 -29
  5. package/core/types/frame.lua +24 -21
  6. package/core/types/player.d.ts +15 -0
  7. package/core/types/player.lua +56 -14
  8. package/core/types/playerCamera.d.ts +2 -0
  9. package/core/types/playerCamera.lua +123 -5
  10. package/core/types/sound.lua +5 -0
  11. package/core/types/tileCell.d.ts +9 -0
  12. package/core/types/tileCell.lua +92 -0
  13. package/core/types/timer.d.ts +9 -8
  14. package/core/types/timer.lua +45 -23
  15. package/decl/native.d.ts +846 -790
  16. package/engine/behavior.d.ts +5 -0
  17. package/engine/behavior.lua +106 -27
  18. package/engine/behaviour/ability/apply-buff.lua +1 -1
  19. package/engine/behaviour/ability/damage.d.ts +6 -3
  20. package/engine/behaviour/ability/damage.lua +24 -36
  21. package/engine/behaviour/ability/emulate-impact.d.ts +1 -1
  22. package/engine/behaviour/ability/emulate-impact.lua +18 -3
  23. package/engine/behaviour/ability/remove-buffs.d.ts +9 -0
  24. package/engine/behaviour/ability/remove-buffs.lua +21 -0
  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 +4 -1
  28. package/engine/behaviour/ability.lua +14 -21
  29. package/engine/behaviour/unit/stun-immunity.d.ts +7 -3
  30. package/engine/behaviour/unit/stun-immunity.lua +52 -27
  31. package/engine/behaviour/unit.d.ts +33 -1
  32. package/engine/behaviour/unit.lua +190 -4
  33. package/engine/buff.d.ts +2 -4
  34. package/engine/buff.lua +68 -83
  35. package/engine/internal/ability.d.ts +7 -1
  36. package/engine/internal/ability.lua +49 -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 +18 -17
  40. package/engine/internal/item.lua +135 -49
  41. package/engine/internal/misc/damage-metadata-by-target.d.ts +2 -0
  42. package/engine/internal/misc/damage-metadata-by-target.lua +5 -0
  43. package/engine/internal/misc/frame-coordinates.d.ts +2 -0
  44. package/engine/internal/misc/frame-coordinates.lua +21 -0
  45. package/engine/internal/misc/get-terrain-z.d.ts +2 -0
  46. package/engine/internal/misc/get-terrain-z.lua +11 -0
  47. package/engine/internal/misc/player-local-handle.d.ts +2 -0
  48. package/engine/internal/misc/player-local-handle.lua +5 -0
  49. package/engine/internal/unit/ability.d.ts +35 -0
  50. package/engine/internal/unit/ability.lua +98 -9
  51. package/engine/internal/unit/allowed-targets.d.ts +1 -1
  52. package/engine/internal/unit/allowed-targets.lua +9 -1
  53. package/engine/internal/unit/main-selected.lua +12 -27
  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 +42 -14
  61. package/engine/internal/unit.d.ts +28 -9
  62. package/engine/internal/unit.lua +267 -116
  63. package/engine/local-client.d.ts +2 -0
  64. package/engine/local-client.lua +30 -0
  65. package/engine/object-data/auxiliary/armor-type.d.ts +11 -0
  66. package/engine/object-data/auxiliary/armor-type.lua +46 -0
  67. package/engine/object-data/auxiliary/attachment-preset.d.ts +7 -2
  68. package/engine/object-data/auxiliary/attachment-preset.lua +4 -3
  69. package/engine/object-data/auxiliary/attack-type.d.ts +7 -8
  70. package/engine/object-data/auxiliary/attack-type.lua +42 -0
  71. package/engine/object-data/auxiliary/movement-type.d.ts +7 -7
  72. package/engine/object-data/auxiliary/movement-type.lua +22 -0
  73. package/engine/object-data/auxiliary/unit-attribute.d.ts +6 -0
  74. package/engine/object-data/auxiliary/unit-attribute.lua +9 -0
  75. package/engine/object-data/entry/ability-type/berserk.d.ts +2 -0
  76. package/engine/object-data/entry/ability-type/berserk.lua +13 -0
  77. package/engine/object-data/entry/ability-type/permanent-invisibility.d.ts +8 -0
  78. package/engine/object-data/entry/ability-type/permanent-invisibility.lua +26 -0
  79. package/engine/object-data/entry/ability-type/phase-shift.d.ts +10 -0
  80. package/engine/object-data/entry/ability-type/phase-shift.lua +39 -0
  81. package/engine/object-data/entry/ability-type/slow-poison.d.ts +10 -0
  82. package/engine/object-data/entry/ability-type/slow-poison.lua +58 -0
  83. package/engine/object-data/entry/ability-type.d.ts +11 -11
  84. package/engine/object-data/entry/ability-type.lua +31 -9
  85. package/engine/object-data/entry/buff-type/applicable.lua +5 -0
  86. package/engine/object-data/entry/buff-type.d.ts +5 -11
  87. package/engine/object-data/entry/buff-type.lua +11 -27
  88. package/engine/object-data/entry/unit-type.d.ts +13 -4
  89. package/engine/object-data/entry/unit-type.lua +153 -85
  90. package/engine/object-field/ability.d.ts +4 -4
  91. package/engine/object-field/ability.lua +7 -6
  92. package/engine/object-field/unit.d.ts +57 -3
  93. package/engine/object-field/unit.lua +207 -7
  94. package/engine/object-field.d.ts +17 -6
  95. package/engine/object-field.lua +188 -92
  96. package/engine/random.d.ts +9 -0
  97. package/engine/random.lua +13 -0
  98. package/engine/standard/entries/buff-type.d.ts +3 -0
  99. package/engine/standard/entries/buff-type.lua +3 -0
  100. package/engine/standard/fields/unit.d.ts +4 -0
  101. package/engine/standard/fields/unit.lua +7 -0
  102. package/engine/synchronization.d.ts +11 -0
  103. package/engine/synchronization.lua +77 -0
  104. package/engine/text-tag.d.ts +36 -2
  105. package/engine/text-tag.lua +249 -10
  106. package/engine/unit.d.ts +1 -0
  107. package/engine/unit.lua +1 -0
  108. package/net/socket.lua +1 -1
  109. package/objutil/buff.lua +2 -3
  110. package/package.json +2 -2
  111. package/patch-lualib.lua +1 -1
  112. package/utility/arrays.d.ts +2 -0
  113. package/utility/arrays.lua +11 -0
  114. package/utility/callback-array.d.ts +17 -0
  115. package/utility/callback-array.lua +61 -0
  116. package/utility/functions.d.ts +8 -0
  117. package/utility/functions.lua +13 -0
  118. package/utility/linked-set.d.ts +2 -0
  119. package/utility/linked-set.lua +22 -1
  120. package/utility/lua-maps.d.ts +15 -2
  121. package/utility/lua-maps.lua +53 -2
  122. package/utility/lua-sets.d.ts +2 -0
  123. package/utility/lua-sets.lua +7 -0
  124. package/utility/types.d.ts +3 -0
  125. package/core/types/order.d.ts +0 -25
  126. package/core/types/order.lua +0 -55
@@ -53,13 +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 resetUnitAnimation = ResetUnitAnimation
62
- local queueUnitAnimation = QueueUnitAnimation
63
69
  local getUnitIntegerField = BlzGetUnitIntegerField
64
70
  local getUnitRealField = BlzGetUnitRealField
65
71
  local getHeroStr = GetHeroStr
@@ -81,7 +87,6 @@ local getHandleId = GetHandleId
81
87
  local getUnitCurrentOrder = GetUnitCurrentOrder
82
88
  local createUnit = CreateUnit
83
89
  local killUnit = KillUnit
84
- local setUnitExploded = SetUnitExploded
85
90
  local removeUnit = RemoveUnit
86
91
  local getUnitTypeId = GetUnitTypeId
87
92
  local isHeroUnitId = IsHeroUnitId
@@ -97,8 +102,6 @@ local getSpellTargetItem = GetSpellTargetItem
97
102
  local getSpellTargetDestructable = GetSpellTargetDestructable
98
103
  local isUnitInRangeXY = IsUnitInRangeXY
99
104
  local isUnitInRange = IsUnitInRange
100
- local setResourceAmount = SetResourceAmount
101
- local getResourceAmount = GetResourceAmount
102
105
  local getUnitWeaponRealField = BlzGetUnitWeaponRealField
103
106
  local setUnitWeaponRealField = BlzSetUnitWeaponRealField
104
107
  local getUnitWeaponStringField = BlzGetUnitWeaponStringField
@@ -122,15 +125,9 @@ local getOrderedUnit = GetOrderedUnit
122
125
  local getIssuedOrderId = GetIssuedOrderId
123
126
  local isUnitInvulnerable = BlzIsUnitInvulnerable
124
127
  local unitAlive = UnitAlive
125
- local unitAddType = UnitAddType
126
- local unitRemoveType = UnitRemoveType
127
- local isUnitIllusion = IsUnitIllusion
128
- local isUnitType = IsUnitType
129
128
  local isUnitAlly = IsUnitAlly
130
129
  local isUnitEnemy = IsUnitEnemy
131
130
  local getOwningPlayer = GetOwningPlayer
132
- local setUnitColor = SetUnitColor
133
- local showUnitTeamGlow = BlzShowUnitTeamGlow
134
131
  ____exports.UnitClassification = {}
135
132
  local UnitClassification = ____exports.UnitClassification
136
133
  do
@@ -140,6 +137,7 @@ do
140
137
  UnitClassification.GROUND = UNIT_TYPE_GROUND
141
138
  UnitClassification.SUMMONED = UNIT_TYPE_SUMMONED
142
139
  UnitClassification.MECHANICAL = UNIT_TYPE_MECHANICAL
140
+ UnitClassification.WORKER = UNIT_TYPE_PEON
143
141
  UnitClassification.ANCIENT = UNIT_TYPE_ANCIENT
144
142
  UnitClassification.SUICIDAL = UNIT_TYPE_SAPPER
145
143
  UnitClassification.TAUREN = UNIT_TYPE_TAUREN
@@ -347,6 +345,9 @@ local function dispatchAbility(event)
347
345
  }
348
346
  )
349
347
  end
348
+ local function damagingEventPreventRetaliation(self)
349
+ self[0] = true
350
+ end
350
351
  local function damageEventPreventDeath(self, callback, ...)
351
352
  if self[0] ~= nil then
352
353
  return
@@ -358,7 +359,14 @@ local function damageEventPreventDeath(self, callback, ...)
358
359
  rawset(self, 1 + i, (select(i, ...)))
359
360
  end
360
361
  end
361
- 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
+ }
362
370
  local jlimitopByOperator = {
363
371
  [0] = LESS_THAN_OR_EQUAL,
364
372
  [1] = LESS_THAN_OR_EQUAL,
@@ -402,6 +410,19 @@ function UnitWeapon.prototype.____constructor(self, unit, index)
402
410
  self.unit = unit
403
411
  self.index = index
404
412
  end
413
+ __TS__SetDescriptor(
414
+ UnitWeapon.prototype,
415
+ "isEnabled",
416
+ {
417
+ get = function(self)
418
+ return BlzGetUnitWeaponBooleanField(self.unit.handle, UNIT_WEAPON_BF_ATTACKS_ENABLED, self.index)
419
+ end,
420
+ set = function(self, isEnabled)
421
+ BlzSetUnitWeaponBooleanField(self.unit.handle, UNIT_WEAPON_BF_ATTACKS_ENABLED, self.index, isEnabled)
422
+ end
423
+ },
424
+ true
425
+ )
405
426
  __TS__SetDescriptor(
406
427
  UnitWeapon.prototype,
407
428
  "cooldown",
@@ -436,6 +457,19 @@ __TS__SetDescriptor(
436
457
  },
437
458
  true
438
459
  )
460
+ __TS__SetDescriptor(
461
+ UnitWeapon.prototype,
462
+ "allowedTargetCombatClassifications",
463
+ {
464
+ get = function(self)
465
+ return BlzGetUnitWeaponIntegerField(self.unit.handle, UNIT_WEAPON_IF_ATTACK_TARGETS_ALLOWED, self.index)
466
+ end,
467
+ set = function(self, allowedTargetCombatClassifications)
468
+ BlzSetUnitWeaponIntegerField(self.unit.handle, UNIT_WEAPON_IF_ATTACK_TARGETS_ALLOWED, self.index, allowedTargetCombatClassifications)
469
+ end
470
+ },
471
+ true
472
+ )
439
473
  __TS__SetDescriptor(
440
474
  UnitWeapon.prototype,
441
475
  "damageBase",
@@ -640,16 +674,26 @@ local function delayHealthChecksCallback(unit)
640
674
  end
641
675
  end
642
676
  local nextSyncId = 1
643
- local unitBySyncId = setmetatable({}, {__mode = "k"})
677
+ local unitBySyncId = setmetatable({}, {__mode = "v"})
678
+ local damagingEventByTarget = setmetatable({}, {__mode = "k"})
679
+ local function addAbility(unit, abilityTypeId)
680
+ local ____unitAddAbility_result_0
681
+ if unitAddAbility(unit, abilityTypeId) then
682
+ ____unitAddAbility_result_0 = getUnitAbility(unit, abilityTypeId)
683
+ else
684
+ ____unitAddAbility_result_0 = nil
685
+ end
686
+ return ____unitAddAbility_result_0
687
+ end
644
688
  ____exports.Unit = __TS__Class()
645
689
  local Unit = ____exports.Unit
646
690
  Unit.name = "Unit"
647
691
  __TS__ClassExtends(Unit, Handle)
648
692
  function Unit.prototype.____constructor(self, handle)
649
693
  Handle.prototype.____constructor(self, handle)
650
- local ____nextSyncId_0 = nextSyncId
651
- nextSyncId = ____nextSyncId_0 + 1
652
- self.syncId = ____nextSyncId_0
694
+ local ____nextSyncId_1 = nextSyncId
695
+ nextSyncId = ____nextSyncId_1 + 1
696
+ self.syncId = ____nextSyncId_1
653
697
  self._owner = Player:of(getOwningPlayer(handle))
654
698
  assert(unitAddAbility(handle, leaveDetectAbilityId) and UnitMakeAbilityPermanent(handle, true, leaveDetectAbilityId))
655
699
  assert(unitAddAbility(handle, morphDetectAbilityId))
@@ -750,17 +794,17 @@ function Unit.prototype.addModifier(self, property, modifier)
750
794
  end}
751
795
  end
752
796
  function Unit.prototype.hasCombatClassification(self, combatClassification)
753
- local ____combatClassification_1 = combatClassification
754
- return getUnitIntegerField(self.handle, UNIT_IF_TARGETED_AS) & ____combatClassification_1 == ____combatClassification_1
797
+ local ____combatClassification_2 = combatClassification
798
+ return getUnitIntegerField(self.handle, UNIT_IF_TARGETED_AS) & ____combatClassification_2 == ____combatClassification_2
755
799
  end
756
800
  function Unit.prototype.addClassification(self, classification)
757
- return unitAddType(self.handle, classification)
801
+ return UnitAddType(self.handle, classification)
758
802
  end
759
803
  function Unit.prototype.removeClassification(self, classification)
760
- return unitRemoveType(self.handle, classification)
804
+ return UnitRemoveType(self.handle, classification)
761
805
  end
762
806
  function Unit.prototype.hasClassification(self, classification)
763
- return isUnitType(self.handle, classification)
807
+ return IsUnitType(self.handle, classification)
764
808
  end
765
809
  function Unit.prototype.isVisibleTo(self, player)
766
810
  return isUnitVisible(self.handle, player.handle)
@@ -769,13 +813,13 @@ function Unit.prototype.isInvisibleTo(self, player)
769
813
  return isUnitInvisible(self.handle, player.handle)
770
814
  end
771
815
  function Unit.prototype.isInRangeOf(self, x, y, range)
772
- local ____temp_2
816
+ local ____temp_3
773
817
  if type(x) == "number" then
774
- ____temp_2 = isUnitInRangeXY(self.handle, x, y, range)
818
+ ____temp_3 = isUnitInRangeXY(self.handle, x, y, range)
775
819
  else
776
- ____temp_2 = isUnitInRange(self.handle, x.handle, y)
820
+ ____temp_3 = isUnitInRange(self.handle, x.handle, y)
777
821
  end
778
- return ____temp_2
822
+ return ____temp_3
779
823
  end
780
824
  function Unit.prototype.isAllyOf(self, unit)
781
825
  return isUnitAlly(
@@ -793,16 +837,27 @@ function Unit.prototype.playAnimation(self, animation, rarity)
793
837
  if type(animation) == "number" then
794
838
  setUnitAnimationByIndex(self.handle, animation)
795
839
  elseif rarity then
796
- setUnitAnimationWithRarity(self.handle, animation, rarity)
840
+ SetUnitAnimationWithRarity(self.handle, animation, rarity)
797
841
  else
798
842
  setUnitAnimation(self.handle, animation)
799
843
  end
800
844
  end
801
845
  function Unit.prototype.resetAnimation(self)
802
- resetUnitAnimation(self.handle)
846
+ ResetUnitAnimation(self.handle)
803
847
  end
804
848
  function Unit.prototype.queueAnimation(self, animation)
805
- queueUnitAnimation(self.handle, animation)
849
+ QueueUnitAnimation(self.handle, animation)
850
+ end
851
+ function Unit.prototype.chooseWeapon(self, target)
852
+ local firstWeapon = self.firstWeapon
853
+ if firstWeapon.isEnabled and target:isAllowedTarget(self, firstWeapon.allowedTargetCombatClassifications) then
854
+ return firstWeapon
855
+ end
856
+ local secondWeapon = self.secondWeapon
857
+ if secondWeapon.isEnabled and target:isAllowedTarget(target, secondWeapon.allowedTargetCombatClassifications) then
858
+ return secondWeapon
859
+ end
860
+ return nil
806
861
  end
807
862
  function Unit.prototype.delayHealthChecks(self)
808
863
  self[103] = (self[103] or 0) + 1
@@ -815,21 +870,21 @@ function Unit.prototype.isSelected(self, player)
815
870
  return IsUnitSelected(self.handle, player.handle)
816
871
  end
817
872
  function Unit.prototype.explode(self)
818
- setUnitExploded(self.handle, true)
873
+ SetUnitExploded(self.handle, true)
819
874
  killUnit(self.handle)
820
875
  end
821
876
  function Unit.prototype.kill(self)
822
877
  killUnit(self.handle)
823
878
  end
824
879
  function Unit.prototype.revive(self, x, y, doEffect)
825
- local ____ReviveHero_5 = ReviveHero
826
- local ____array_4 = __TS__SparseArrayNew(self.handle, x, y)
827
- local ____doEffect_3 = doEffect
828
- if ____doEffect_3 == nil then
829
- ____doEffect_3 = false
880
+ local ____ReviveHero_6 = ReviveHero
881
+ local ____array_5 = __TS__SparseArrayNew(self.handle, x, y)
882
+ local ____doEffect_4 = doEffect
883
+ if ____doEffect_4 == nil then
884
+ ____doEffect_4 = false
830
885
  end
831
- __TS__SparseArrayPush(____array_4, ____doEffect_3)
832
- ____ReviveHero_5(__TS__SparseArraySpread(____array_4))
886
+ __TS__SparseArrayPush(____array_5, ____doEffect_4)
887
+ ____ReviveHero_6(__TS__SparseArraySpread(____array_5))
833
888
  end
834
889
  function Unit.prototype.healTarget(self, target, amount)
835
890
  if __TS__InstanceOf(target, ____exports.Unit) and target:hasAbility(fourCC("BIhm")) then
@@ -872,17 +927,16 @@ function Unit.prototype.itemInSlot(self, slot)
872
927
  return Item:of(unitItemInSlot(self.handle, slot))
873
928
  end
874
929
  function Unit.prototype.addAbility(self, abilityId)
875
- if unitAddAbility(self.handle, abilityId) then
876
- local ability = UnitAbility:of(
877
- checkNotNull(getUnitAbility(self.handle, abilityId)),
878
- abilityId,
879
- self
880
- )
930
+ local ability = UnitAbility:of(
931
+ doUnitAbilityAction(self.handle, abilityId, addAbility, abilityId),
932
+ abilityId,
933
+ self
934
+ )
935
+ if ability ~= nil then
881
936
  local abilities = self.abilities
882
937
  abilities[#abilities + 1] = ability
883
- return ability
884
938
  end
885
- return nil
939
+ return ability
886
940
  end
887
941
  function Unit.prototype.makeAbilityPermanent(self, abilityId, permanent)
888
942
  return UnitMakeAbilityPermanent(self.handle, permanent, abilityId)
@@ -896,31 +950,21 @@ end
896
950
  function Unit.prototype.hasAbility(self, abilityId)
897
951
  return getUnitAbilityLevel(self.handle, abilityId) > 0
898
952
  end
899
- function Unit.prototype.getAbilityById(self, abilityId)
900
- local handle = self.handle
901
- if unitAddAbility(handle, abilityId) then
902
- assert(unitRemoveAbility(handle, abilityId))
903
- return nil
904
- end
905
- return UnitAbility:of(
906
- getUnitAbility(self.handle, abilityId),
907
- abilityId,
908
- self
909
- )
953
+ function Unit.prototype.getAbility(self, abilityId)
954
+ local ability = doUnitAbilityAction(self.handle, abilityId, getUnitAbility, abilityId)
955
+ return UnitAbility:of(ability, abilityId, self)
910
956
  end
911
- function Unit.prototype.removeAbility(self, abilityId)
912
- if unitRemoveAbility(self.handle, abilityId) then
913
- local abilities = self.abilities
914
- for i = 1, #abilities do
915
- if abilities[i].typeId == abilityId then
916
- abilities[i]:destroy()
917
- tremove(abilities, i)
918
- return true
919
- end
957
+ function Unit.prototype.removeAbility(self, abilityTypeId)
958
+ local abilities = self.abilities
959
+ for i = 1, #abilities do
960
+ if abilities[i].typeId == abilityTypeId then
961
+ local ability = abilities[i]
962
+ tremove(abilities, i)
963
+ ability:destroy()
964
+ return true
920
965
  end
921
- return true
922
966
  end
923
- return false
967
+ return doUnitAbilityAction(self.handle, abilityTypeId, unitRemoveAbility, abilityTypeId)
924
968
  end
925
969
  function Unit.prototype.hideAbility(self, abilityId, flag)
926
970
  BlzUnitHideAbility(self.handle, abilityId, flag)
@@ -934,6 +978,21 @@ end
934
978
  function Unit.prototype.endAbilityCooldown(self, abilityId)
935
979
  BlzEndUnitAbilityCooldown(self.handle, abilityId)
936
980
  end
981
+ function Unit.prototype.interruptMovement(self)
982
+ local handle = self.handle
983
+ unitDisableAbility(
984
+ handle,
985
+ fourCC("Amov"),
986
+ true,
987
+ false
988
+ )
989
+ unitDisableAbility(
990
+ handle,
991
+ fourCC("Amov"),
992
+ false,
993
+ false
994
+ )
995
+ end
937
996
  function Unit.prototype.interruptAttack(self)
938
997
  unitInterruptAttack(self.handle)
939
998
  end
@@ -1207,7 +1266,7 @@ __TS__SetDescriptor(
1207
1266
  Unit.prototype,
1208
1267
  "isIllusion",
1209
1268
  {get = function(self)
1210
- return isUnitIllusion(self.handle)
1269
+ return IsUnitIllusion(self.handle)
1211
1270
  end},
1212
1271
  true
1213
1272
  )
@@ -1292,6 +1351,19 @@ __TS__SetDescriptor(
1292
1351
  },
1293
1352
  true
1294
1353
  )
1354
+ __TS__SetDescriptor(
1355
+ Unit.prototype,
1356
+ "primaryAttribute",
1357
+ {
1358
+ get = function(self)
1359
+ return getUnitIntegerField(self.handle, UNIT_IF_PRIMARY_ATTRIBUTE)
1360
+ end,
1361
+ set = function(self, primaryAttribute)
1362
+ setUnitIntegerField(self.handle, UNIT_IF_PRIMARY_ATTRIBUTE, primaryAttribute)
1363
+ end
1364
+ },
1365
+ true
1366
+ )
1295
1367
  __TS__SetDescriptor(
1296
1368
  Unit.prototype,
1297
1369
  "strengthBase",
@@ -1416,14 +1488,14 @@ __TS__SetDescriptor(
1416
1488
  return not self[106]
1417
1489
  end,
1418
1490
  set = function(self, isTeamGlowVisible)
1419
- showUnitTeamGlow(self.handle, isTeamGlowVisible)
1420
- local ____temp_6
1491
+ BlzShowUnitTeamGlow(self.handle, isTeamGlowVisible)
1492
+ local ____temp_7
1421
1493
  if not isTeamGlowVisible then
1422
- ____temp_6 = true
1494
+ ____temp_7 = true
1423
1495
  else
1424
- ____temp_6 = nil
1496
+ ____temp_7 = nil
1425
1497
  end
1426
- self[106] = ____temp_6
1498
+ self[106] = ____temp_7
1427
1499
  end
1428
1500
  },
1429
1501
  true
@@ -1432,9 +1504,9 @@ __TS__SetDescriptor(
1432
1504
  Unit.prototype,
1433
1505
  "color",
1434
1506
  {set = function(self, color)
1435
- setUnitColor(self.handle, color.handle)
1507
+ SetUnitColor(self.handle, color.handle)
1436
1508
  if self[106] then
1437
- showUnitTeamGlow(self.handle, false)
1509
+ BlzShowUnitTeamGlow(self.handle, false)
1438
1510
  end
1439
1511
  end},
1440
1512
  true
@@ -1702,10 +1774,10 @@ __TS__SetDescriptor(
1702
1774
  "gold",
1703
1775
  {
1704
1776
  get = function(self)
1705
- return getResourceAmount(self.handle)
1777
+ return GetResourceAmount(self.handle)
1706
1778
  end,
1707
1779
  set = function(self, gold)
1708
- setResourceAmount(self.handle, gold)
1780
+ SetResourceAmount(self.handle, gold)
1709
1781
  end
1710
1782
  },
1711
1783
  true
@@ -1833,6 +1905,19 @@ __TS__SetDescriptor(
1833
1905
  end},
1834
1906
  true
1835
1907
  )
1908
+ __TS__SetDescriptor(
1909
+ Unit.prototype,
1910
+ "movementType",
1911
+ {
1912
+ get = function(self)
1913
+ return getUnitIntegerField(self.handle, UNIT_IF_MOVE_TYPE)
1914
+ end,
1915
+ set = function(self, movementType)
1916
+ setUnitIntegerField(self.handle, UNIT_IF_MOVE_TYPE, movementType)
1917
+ end
1918
+ },
1919
+ true
1920
+ )
1836
1921
  __TS__SetDescriptor(
1837
1922
  Unit.prototype,
1838
1923
  "pathing",
@@ -2014,6 +2099,14 @@ __TS__SetDescriptor(
2014
2099
  end},
2015
2100
  true
2016
2101
  )
2102
+ __TS__SetDescriptor(
2103
+ Unit.prototype,
2104
+ "targetAcquiredEvent",
2105
+ {get = function(self)
2106
+ return self:getEvent(EVENT_UNIT_ACQUIRED_TARGET)
2107
+ end},
2108
+ true
2109
+ )
2017
2110
  __TS__SetDescriptor(
2018
2111
  Unit.prototype,
2019
2112
  "onSelect",
@@ -2149,25 +2242,25 @@ Unit.onTargetCast = dispatchId(__TS__New(
2149
2242
  InitializingEvent,
2150
2243
  function(event)
2151
2244
  local function listener(unit, id)
2152
- local ____GetSpellTargetUnit_result_9
2245
+ local ____GetSpellTargetUnit_result_10
2153
2246
  if GetSpellTargetUnit() then
2154
- ____GetSpellTargetUnit_result_9 = ____exports.Unit:of(GetSpellTargetUnit())
2247
+ ____GetSpellTargetUnit_result_10 = ____exports.Unit:of(GetSpellTargetUnit())
2155
2248
  else
2156
- local ____GetSpellTargetItem_result_8
2249
+ local ____GetSpellTargetItem_result_9
2157
2250
  if GetSpellTargetItem() then
2158
- ____GetSpellTargetItem_result_8 = Item:of(GetSpellTargetItem())
2251
+ ____GetSpellTargetItem_result_9 = Item:of(GetSpellTargetItem())
2159
2252
  else
2160
- local ____GetSpellTargetDestructable_result_7
2253
+ local ____GetSpellTargetDestructable_result_8
2161
2254
  if GetSpellTargetDestructable() then
2162
- ____GetSpellTargetDestructable_result_7 = Destructable:of(GetSpellTargetDestructable())
2255
+ ____GetSpellTargetDestructable_result_8 = Destructable:of(GetSpellTargetDestructable())
2163
2256
  else
2164
- ____GetSpellTargetDestructable_result_7 = nil
2257
+ ____GetSpellTargetDestructable_result_8 = nil
2165
2258
  end
2166
- ____GetSpellTargetItem_result_8 = ____GetSpellTargetDestructable_result_7
2259
+ ____GetSpellTargetItem_result_9 = ____GetSpellTargetDestructable_result_8
2167
2260
  end
2168
- ____GetSpellTargetUnit_result_9 = ____GetSpellTargetItem_result_8
2261
+ ____GetSpellTargetUnit_result_10 = ____GetSpellTargetItem_result_9
2169
2262
  end
2170
- local target = ____GetSpellTargetUnit_result_9
2263
+ local target = ____GetSpellTargetUnit_result_10
2171
2264
  if target then
2172
2265
  invoke(event, unit, id, target)
2173
2266
  end
@@ -2375,38 +2468,57 @@ Unit.onDamaging = (function()
2375
2468
  if source and source.typeId == dummyUnitId then
2376
2469
  source = nil
2377
2470
  end
2378
- local target = BlzGetEventDamageTarget()
2471
+ local target = ____exports.Unit:of(BlzGetEventDamageTarget())
2472
+ local metadata = damageMetadataByTarget[target]
2473
+ damageMetadataByTarget[target] = nil
2379
2474
  local data = {
2380
2475
  amount = GetEventDamage(),
2381
- attackType = BlzGetEventAttackType(),
2476
+ attackType = nativeToAttackType(BlzGetEventAttackType()),
2382
2477
  damageType = BlzGetEventDamageType(),
2383
2478
  weaponType = BlzGetEventWeaponType(),
2384
- isAttack = BlzGetEventIsAttack()
2479
+ metadata = metadata,
2480
+ isAttack = BlzGetEventIsAttack(),
2481
+ originalAmount = GetEventDamage(),
2482
+ originalMetadata = metadata,
2483
+ preventRetaliation = damagingEventPreventRetaliation
2385
2484
  }
2386
2485
  if data.isAttack and source then
2387
- 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
2388
- if weapon == -1 then
2389
- local targetsAllowed = BlzGetUnitWeaponIntegerField(source.handle, UNIT_WEAPON_IF_ATTACK_TARGETS_ALLOWED, 0)
2390
- weapon = 0
2391
- end
2392
- data.weapon = assert(source.weapons[weapon + 1])
2486
+ data.weapon = source:chooseWeapon(target)
2393
2487
  end
2394
2488
  if not data.isAttack or not source or not source._attackHandlers then
2395
2489
  invoke(
2396
2490
  event,
2397
2491
  source,
2398
- ____exports.Unit:of(target),
2492
+ target,
2399
2493
  setmetatable(
2400
2494
  {},
2401
2495
  {
2402
2496
  __index = data,
2403
2497
  __newindex = function(self, key, value)
2404
- damageSetters[key](value)
2498
+ local damageSetter = damageSetters[key]
2499
+ if damageSetter ~= nil then
2500
+ damageSetter(value)
2501
+ end
2405
2502
  data[key] = value
2406
2503
  end
2407
2504
  }
2408
2505
  )
2409
2506
  )
2507
+ if data[0] and source then
2508
+ local sourceOwner = source.owner.handle
2509
+ data[1] = sourceOwner
2510
+ local targetOwner = target.owner.handle
2511
+ data[2] = targetOwner
2512
+ if not GetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE) then
2513
+ SetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE, true)
2514
+ data[3] = true
2515
+ end
2516
+ if not GetPlayerAlliance(targetOwner, sourceOwner, ALLIANCE_PASSIVE) then
2517
+ SetPlayerAlliance(targetOwner, sourceOwner, ALLIANCE_PASSIVE, true)
2518
+ data[4] = true
2519
+ end
2520
+ end
2521
+ damagingEventByTarget[target] = data
2410
2522
  return
2411
2523
  end
2412
2524
  BlzSetEventDamage(0)
@@ -2414,7 +2526,7 @@ Unit.onDamaging = (function()
2414
2526
  BlzSetEventDamageType(DAMAGE_TYPE_UNKNOWN)
2415
2527
  BlzSetEventWeaponType(WEAPON_TYPE_WHOKNOWS)
2416
2528
  local sourceOwner = source.owner.handle
2417
- local targetOwner = GetOwningPlayer(target)
2529
+ local targetOwner = target.owner.handle
2418
2530
  if not GetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE) then
2419
2531
  SetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE, true)
2420
2532
  Timer:run(function()
@@ -2430,23 +2542,19 @@ Unit.onDamaging = (function()
2430
2542
  for ____, ____value in ipairs(source._attackHandlers) do
2431
2543
  local condition = ____value[1]
2432
2544
  local action = ____value[2]
2433
- if condition(
2434
- source,
2435
- ____exports.Unit:of(target),
2436
- data
2437
- ) then
2545
+ if condition(source, target, data) then
2438
2546
  action(
2439
2547
  source,
2440
- ____exports.Unit:of(target),
2548
+ target,
2441
2549
  setmetatable(
2442
2550
  {fire = function()
2443
2551
  UnitDamageTarget(
2444
2552
  source.handle,
2445
- target,
2553
+ target.handle,
2446
2554
  data.amount,
2447
2555
  true,
2448
2556
  true,
2449
- data.attackType,
2557
+ attackTypeToNative(data.attackType),
2450
2558
  data.damageType,
2451
2559
  data.weaponType
2452
2560
  )
@@ -2473,26 +2581,50 @@ Unit.onDamage = __TS__New(
2473
2581
  if source and source.typeId == dummyUnitId then
2474
2582
  source = nil
2475
2583
  end
2584
+ local target = ____exports.Unit:of(BlzGetEventDamageTarget())
2585
+ local damagingEvent = damagingEventByTarget[target]
2586
+ damagingEventByTarget[target] = nil
2476
2587
  local data = {
2477
2588
  amount = GetEventDamage(),
2478
- attackType = BlzGetEventAttackType(),
2589
+ attackType = nativeToAttackType(BlzGetEventAttackType()),
2479
2590
  damageType = BlzGetEventDamageType(),
2480
2591
  weaponType = BlzGetEventWeaponType(),
2592
+ metadata = damagingEvent and damagingEvent.metadata,
2481
2593
  isAttack = BlzGetEventIsAttack(),
2482
- originalAmount = GetEventDamage(),
2594
+ originalAmount = damagingEvent and damagingEvent.originalAmount or GetEventDamage(),
2595
+ originalMetadata = damagingEvent and damagingEvent.originalMetadata,
2483
2596
  preventDeath = damageEventPreventDeath
2484
2597
  }
2598
+ if damagingEvent then
2599
+ for key, value in pairs(damagingEvent) do
2600
+ if isAttribute(key) then
2601
+ data[key] = value
2602
+ end
2603
+ end
2604
+ local sourceOwner = damagingEvent[1]
2605
+ if sourceOwner then
2606
+ local targetOwner = damagingEvent[2]
2607
+ if damagingEvent[3] then
2608
+ SetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE, false)
2609
+ end
2610
+ if damagingEvent[4] then
2611
+ SetPlayerAlliance(targetOwner, sourceOwner, ALLIANCE_PASSIVE, false)
2612
+ end
2613
+ end
2614
+ end
2485
2615
  local evData = setmetatable(
2486
2616
  {},
2487
2617
  {
2488
2618
  __index = data,
2489
2619
  __newindex = function(self, key, value)
2490
- damageSetters[key](value)
2620
+ local damageSetter = damageSetters[key]
2621
+ if damageSetter ~= nil then
2622
+ damageSetter(value)
2623
+ end
2491
2624
  data[key] = value
2492
2625
  end
2493
2626
  }
2494
2627
  )
2495
- local target = ____exports.Unit:of(BlzGetEventDamageTarget())
2496
2628
  invoke(event, source, target, evData)
2497
2629
  if evData[0] ~= nil and target.health - evData.amount < 0.405 then
2498
2630
  local bonusHealth = math.ceil(evData.amount)
@@ -2546,10 +2678,14 @@ Unit.itemPickedUpEvent = __TS__New(
2546
2678
  ____exports.UnitTriggerEvent,
2547
2679
  EVENT_PLAYER_UNIT_PICKUP_ITEM,
2548
2680
  function()
2549
- local unit = getTriggerUnit()
2550
- local item = getManipulatedItem()
2551
- if getUnitTypeId(unit) ~= dummyUnitId and not (ignoreEventsItems[item] ~= nil) then
2552
- return ____exports.Unit:of(unit), Item:of(item)
2681
+ local unitHandle = getTriggerUnit()
2682
+ local itemHandle = getManipulatedItem()
2683
+ if getUnitTypeId(unitHandle) ~= dummyUnitId and not (ignoreEventsItems[itemHandle] ~= nil) then
2684
+ local unit = ____exports.Unit:of(unitHandle)
2685
+ local item = Item:of(itemHandle)
2686
+ if item.owner ~= unit then
2687
+ return unit, item
2688
+ end
2553
2689
  end
2554
2690
  return IgnoreEvent
2555
2691
  end
@@ -2569,7 +2705,22 @@ Unit.itemUsedEvent = __TS__New(
2569
2705
  Unit.itemStackedEvent = __TS__New(
2570
2706
  ____exports.UnitTriggerEvent,
2571
2707
  EVENT_PLAYER_UNIT_STACK_ITEM,
2572
- function() return ____exports.Unit:of(getTriggerUnit()), Item:of(getManipulatedItem()) end
2708
+ function() return ____exports.Unit:of(getTriggerUnit()), Item:of(BlzGetStackingItemTarget()), Item:of(BlzGetStackingItemSource()) end
2709
+ )
2710
+ __TS__ObjectDefineProperty(
2711
+ Unit,
2712
+ "itemChargesChangedEvent",
2713
+ {get = function(self)
2714
+ local event = __TS__New(Event)
2715
+ Item.chargesChangedEvent:addListener(function(item)
2716
+ local unit = item.owner
2717
+ if unit ~= nil then
2718
+ invoke(event, unit, item)
2719
+ end
2720
+ end)
2721
+ rawset(self, "itemChargesChangedEvent", event)
2722
+ return event
2723
+ end}
2573
2724
  )
2574
2725
  __TS__ObjectDefineProperty(
2575
2726
  Unit,