warscript 0.0.1-dev.86b4b59 → 0.0.1-dev.870376f

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 (123) hide show
  1. package/attributes.d.ts +1 -0
  2. package/attributes.lua +9 -0
  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/emulate-impact.d.ts +1 -1
  19. package/engine/behaviour/ability/emulate-impact.lua +11 -3
  20. package/engine/behaviour/ability/remove-buffs.d.ts +9 -0
  21. package/engine/behaviour/ability/remove-buffs.lua +21 -0
  22. package/engine/behaviour/ability/restore-mana.d.ts +1 -1
  23. package/engine/behaviour/ability/restore-mana.lua +6 -6
  24. package/engine/behaviour/ability.d.ts +6 -1
  25. package/engine/behaviour/ability.lua +38 -17
  26. package/engine/behaviour/unit/stun-immunity.d.ts +12 -6
  27. package/engine/behaviour/unit/stun-immunity.lua +57 -31
  28. package/engine/behaviour/unit.d.ts +35 -5
  29. package/engine/behaviour/unit.lua +230 -31
  30. package/engine/buff.d.ts +21 -8
  31. package/engine/buff.lua +187 -121
  32. package/engine/internal/ability.d.ts +5 -1
  33. package/engine/internal/ability.lua +44 -11
  34. package/engine/internal/item/ability.lua +63 -11
  35. package/engine/internal/item+owner.lua +12 -6
  36. package/engine/internal/item.d.ts +16 -16
  37. package/engine/internal/item.lua +135 -49
  38. package/engine/internal/mechanics/cast-ability.lua +6 -3
  39. package/engine/internal/misc/frame-coordinates.d.ts +2 -0
  40. package/engine/internal/misc/frame-coordinates.lua +21 -0
  41. package/engine/internal/misc/get-terrain-z.d.ts +2 -0
  42. package/engine/internal/misc/get-terrain-z.lua +11 -0
  43. package/engine/internal/misc/player-local-handle.d.ts +2 -0
  44. package/engine/internal/misc/player-local-handle.lua +5 -0
  45. package/engine/internal/object-data/mana-regeneration-rate-increase-factor.d.ts +2 -0
  46. package/engine/internal/object-data/mana-regeneration-rate-increase-factor.lua +16 -0
  47. package/engine/internal/unit/ability.d.ts +35 -0
  48. package/engine/internal/unit/ability.lua +98 -9
  49. package/engine/internal/unit/attributes.d.ts +17 -0
  50. package/engine/internal/unit/attributes.lua +46 -0
  51. package/engine/internal/unit/bonus.d.ts +2 -0
  52. package/engine/internal/unit/bonus.lua +10 -0
  53. package/engine/internal/unit/fly-height.d.ts +7 -0
  54. package/engine/internal/unit/fly-height.lua +20 -0
  55. package/engine/internal/unit/interrupts.d.ts +12 -0
  56. package/engine/internal/unit/interrupts.lua +28 -0
  57. package/engine/internal/unit/main-selected.lua +12 -27
  58. package/engine/internal/unit/order.d.ts +20 -0
  59. package/engine/internal/unit/order.lua +136 -0
  60. package/engine/internal/unit/range-event.d.ts +12 -0
  61. package/engine/internal/unit/range-event.lua +90 -0
  62. package/engine/internal/unit/scale.d.ts +7 -0
  63. package/engine/internal/unit/scale.lua +20 -0
  64. package/engine/internal/unit+ability.lua +10 -1
  65. package/engine/internal/unit-missile-launch.lua +52 -14
  66. package/engine/internal/unit.d.ts +21 -24
  67. package/engine/internal/unit.lua +247 -240
  68. package/engine/local-client.d.ts +2 -0
  69. package/engine/local-client.lua +30 -0
  70. package/engine/object-data/auxiliary/armor-type.d.ts +11 -0
  71. package/engine/object-data/auxiliary/armor-type.lua +46 -0
  72. package/engine/object-data/auxiliary/health-regeneration-type.d.ts +8 -0
  73. package/engine/object-data/auxiliary/health-regeneration-type.lua +2 -0
  74. package/engine/object-data/entry/ability-type/mana-regeneration.d.ts +8 -0
  75. package/engine/object-data/entry/ability-type/mana-regeneration.lua +26 -0
  76. package/engine/object-data/entry/ability-type/reincarnation.d.ts +8 -0
  77. package/engine/object-data/entry/ability-type/reincarnation.lua +26 -0
  78. package/engine/object-data/entry/ability-type.lua +5 -4
  79. package/engine/object-data/entry/destructible-type.d.ts +27 -1
  80. package/engine/object-data/entry/destructible-type.lua +155 -0
  81. package/engine/object-data/entry/unit-type.d.ts +15 -2
  82. package/engine/object-data/entry/unit-type.lua +135 -33
  83. package/engine/object-field/ability.d.ts +3 -3
  84. package/engine/object-field/ability.lua +7 -6
  85. package/engine/object-field/unit.d.ts +31 -5
  86. package/engine/object-field/unit.lua +95 -0
  87. package/engine/object-field.d.ts +17 -6
  88. package/engine/object-field.lua +291 -134
  89. package/engine/random.d.ts +10 -0
  90. package/engine/random.lua +21 -0
  91. package/engine/standard/fields/ability.d.ts +2 -2
  92. package/engine/standard/fields/ability.lua +2 -2
  93. package/engine/standard/fields/unit.d.ts +12 -0
  94. package/engine/standard/fields/unit.lua +20 -0
  95. package/engine/synchronization.d.ts +11 -0
  96. package/engine/synchronization.lua +77 -0
  97. package/engine/text-tag.d.ts +36 -2
  98. package/engine/text-tag.lua +250 -10
  99. package/engine/unit.d.ts +6 -0
  100. package/engine/unit.lua +6 -0
  101. package/net/socket.lua +1 -1
  102. package/objutil/buff.lua +10 -8
  103. package/package.json +2 -2
  104. package/patch-lua.lua +15 -0
  105. package/patch-lualib.lua +1 -1
  106. package/utility/arrays.d.ts +1 -0
  107. package/utility/arrays.lua +8 -0
  108. package/utility/callback-array.d.ts +17 -0
  109. package/utility/callback-array.lua +61 -0
  110. package/utility/functions.d.ts +7 -0
  111. package/utility/functions.lua +12 -0
  112. package/utility/linked-map.d.ts +34 -0
  113. package/utility/linked-map.lua +101 -0
  114. package/utility/linked-set.d.ts +3 -1
  115. package/utility/linked-set.lua +40 -1
  116. package/utility/lua-maps.d.ts +12 -2
  117. package/utility/lua-maps.lua +37 -2
  118. package/utility/lua-sets.d.ts +1 -0
  119. package/utility/lua-sets.lua +4 -0
  120. package/utility/records.lua +20 -1
  121. package/utility/types.d.ts +3 -0
  122. package/core/types/order.d.ts +0 -26
  123. package/core/types/order.lua +0 -65
@@ -60,6 +60,12 @@ local ____damage_2Dmetadata_2Dby_2Dtarget = require("engine.internal.misc.damage
60
60
  local damageMetadataByTarget = ____damage_2Dmetadata_2Dby_2Dtarget.damageMetadataByTarget
61
61
  local ____attributes = require("attributes")
62
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
67
+ local ____linked_2Dmap = require("utility.linked-map")
68
+ local LinkedMap = ____linked_2Dmap.LinkedMap
63
69
  local match = string.match
64
70
  local ____tostring = _G.tostring
65
71
  local setUnitAnimation = SetUnitAnimation
@@ -69,16 +75,12 @@ local getUnitRealField = BlzGetUnitRealField
69
75
  local getHeroStr = GetHeroStr
70
76
  local getHeroAgi = GetHeroAgi
71
77
  local getHeroInt = GetHeroInt
72
- local setHeroStr = SetHeroStr
73
- local setHeroAgi = SetHeroAgi
74
- local setHeroInt = SetHeroInt
75
78
  local getUnitBooleanField = BlzGetUnitBooleanField
76
79
  local getUnitStringField = BlzGetUnitStringField
77
80
  local setUnitIntegerField = BlzSetUnitIntegerField
78
81
  local setUnitRealField = BlzSetUnitRealField
79
82
  local setUnitBooleanField = BlzSetUnitBooleanField
80
83
  local setUnitStringField = BlzSetUnitStringField
81
- local setUnitScale = SetUnitScale
82
84
  local setUnitPosition = SetUnitPosition
83
85
  local setUnitTimeScale = SetUnitTimeScale
84
86
  local getHandleId = GetHandleId
@@ -106,7 +108,6 @@ local getUnitWeaponStringField = BlzGetUnitWeaponStringField
106
108
  local setUnitWeaponStringField = BlzSetUnitWeaponStringField
107
109
  local getUnitAbilityLevel = GetUnitAbilityLevel
108
110
  local unitDisableAbility = BlzUnitDisableAbility
109
- local unitInterruptAttack = BlzUnitInterruptAttack
110
111
  local isUnitInvisible = IsUnitInvisible
111
112
  local isUnitVisible = IsUnitVisible
112
113
  local getUnitX = GetUnitX
@@ -123,10 +124,6 @@ local getOrderedUnit = GetOrderedUnit
123
124
  local getIssuedOrderId = GetIssuedOrderId
124
125
  local isUnitInvulnerable = BlzIsUnitInvulnerable
125
126
  local unitAlive = UnitAlive
126
- local unitAddType = UnitAddType
127
- local unitRemoveType = UnitRemoveType
128
- local isUnitIllusion = IsUnitIllusion
129
- local isUnitType = IsUnitType
130
127
  local isUnitAlly = IsUnitAlly
131
128
  local isUnitEnemy = IsUnitEnemy
132
129
  local getOwningPlayer = GetOwningPlayer
@@ -386,15 +383,27 @@ local modifiers = {
386
383
  end,
387
384
  armor = function(unit, value)
388
385
  if UnitAddAbility(unit, armorBonusAbilityId) then
389
- assert(UnitMakeAbilityPermanent(unit, true, armorBonusAbilityId))
386
+ assert(
387
+ UnitMakeAbilityPermanent(unit, true, armorBonusAbilityId),
388
+ "armor bonus ability must be made permanent",
389
+ unit
390
+ )
390
391
  end
391
- local ability = assert(BlzGetUnitAbility(unit, armorBonusAbilityId))
392
- assert(BlzSetAbilityRealLevelField(
393
- ability,
394
- armorBonusField,
395
- 0,
396
- BlzGetAbilityRealLevelField(ability, armorBonusField, 0) + value
397
- ))
392
+ local ability = assert(
393
+ BlzGetUnitAbility(unit, armorBonusAbilityId),
394
+ "armor bonus ability must be existing",
395
+ unit
396
+ )
397
+ assert(
398
+ BlzSetAbilityRealLevelField(
399
+ ability,
400
+ armorBonusField,
401
+ 0,
402
+ BlzGetAbilityRealLevelField(ability, armorBonusField, 0) + value
403
+ ),
404
+ "armor bonus ability field must be set",
405
+ unit
406
+ )
398
407
  end
399
408
  }
400
409
  local getters = {
@@ -412,6 +421,19 @@ function UnitWeapon.prototype.____constructor(self, unit, index)
412
421
  self.unit = unit
413
422
  self.index = index
414
423
  end
424
+ __TS__SetDescriptor(
425
+ UnitWeapon.prototype,
426
+ "isEnabled",
427
+ {
428
+ get = function(self)
429
+ return BlzGetUnitWeaponBooleanField(self.unit.handle, UNIT_WEAPON_BF_ATTACKS_ENABLED, self.index)
430
+ end,
431
+ set = function(self, isEnabled)
432
+ BlzSetUnitWeaponBooleanField(self.unit.handle, UNIT_WEAPON_BF_ATTACKS_ENABLED, self.index, isEnabled)
433
+ end
434
+ },
435
+ true
436
+ )
415
437
  __TS__SetDescriptor(
416
438
  UnitWeapon.prototype,
417
439
  "cooldown",
@@ -635,26 +657,30 @@ local fieldSetters = {
635
657
  }
636
658
  local dummies = {}
637
659
  for ____, player in ipairs(Player.all) do
638
- local dummy = assert(createUnit(
639
- player.handle,
640
- dummyUnitId,
641
- 0,
642
- 0,
643
- 270
644
- ))
660
+ local dummy = assert(
661
+ createUnit(
662
+ player.handle,
663
+ dummyUnitId,
664
+ 0,
665
+ 0,
666
+ 270
667
+ ),
668
+ "dummy must be created",
669
+ player
670
+ )
645
671
  ShowUnit(dummy, false)
646
672
  dummies[player] = dummy
647
673
  end
648
674
  local function delayHealthChecksCallback(unit)
649
- local counter = (unit[103] or 0) - 1
675
+ local counter = (unit[104] or 0) - 1
650
676
  if counter ~= 0 then
651
- unit[103] = counter
677
+ unit[104] = counter
652
678
  return
653
679
  end
654
- unit[103] = nil
655
- local healthBonus = unit[104]
680
+ unit[104] = nil
681
+ local healthBonus = unit[105]
656
682
  if healthBonus ~= nil then
657
- unit[104] = nil
683
+ unit[105] = nil
658
684
  local handle = unit.handle
659
685
  BlzSetUnitMaxHP(
660
686
  handle,
@@ -665,51 +691,76 @@ end
665
691
  local nextSyncId = 1
666
692
  local unitBySyncId = setmetatable({}, {__mode = "v"})
667
693
  local damagingEventByTarget = setmetatable({}, {__mode = "k"})
694
+ local function addAbility(unit, abilityTypeId)
695
+ local ____unitAddAbility_result_0
696
+ if unitAddAbility(unit, abilityTypeId) then
697
+ ____unitAddAbility_result_0 = getUnitAbility(unit, abilityTypeId)
698
+ else
699
+ ____unitAddAbility_result_0 = nil
700
+ end
701
+ return ____unitAddAbility_result_0
702
+ end
668
703
  ____exports.Unit = __TS__Class()
669
704
  local Unit = ____exports.Unit
670
705
  Unit.name = "Unit"
671
706
  __TS__ClassExtends(Unit, Handle)
672
707
  function Unit.prototype.____constructor(self, handle)
673
708
  Handle.prototype.____constructor(self, handle)
674
- local ____nextSyncId_0 = nextSyncId
675
- nextSyncId = ____nextSyncId_0 + 1
676
- self.syncId = ____nextSyncId_0
709
+ local ____nextSyncId_1 = nextSyncId
710
+ nextSyncId = ____nextSyncId_1 + 1
711
+ self.syncId = ____nextSyncId_1
677
712
  self._owner = Player:of(getOwningPlayer(handle))
678
- assert(unitAddAbility(handle, leaveDetectAbilityId) and UnitMakeAbilityPermanent(handle, true, leaveDetectAbilityId))
679
- assert(unitAddAbility(handle, morphDetectAbilityId))
713
+ assert(
714
+ unitAddAbility(handle, leaveDetectAbilityId) and UnitMakeAbilityPermanent(handle, true, leaveDetectAbilityId),
715
+ "leave detection ability must be added",
716
+ self
717
+ )
718
+ assert(
719
+ unitAddAbility(handle, morphDetectAbilityId),
720
+ "morph detection ability must be added",
721
+ self
722
+ )
680
723
  if unitAddAbility(
681
724
  handle,
682
725
  fourCC("Amrf")
683
726
  ) then
684
- assert(unitRemoveAbility(
685
- handle,
686
- fourCC("Amrf")
687
- ))
727
+ assert(
728
+ unitRemoveAbility(
729
+ handle,
730
+ fourCC("Amrf")
731
+ ),
732
+ "fly ability must be removed after addition",
733
+ self
734
+ )
688
735
  end
689
736
  unitBySyncId[self.syncId] = self
690
737
  local ____ = self.abilities
691
738
  end
692
- function Unit.prototype.getEvent(self, event, collector)
693
- self.events = self.events or ({})
694
- local eventId = GetHandleId(event)
695
- if not self.events[eventId] then
696
- self.events[eventId] = __TS__New(
739
+ function Unit.prototype.getEvent(self, jevent, collector)
740
+ self.events = self.events or __TS__New(LinkedMap)
741
+ local eventId = GetHandleId(jevent)
742
+ local event = self.events:get(eventId)
743
+ if event == nil then
744
+ event = __TS__New(
697
745
  TriggerEvent,
698
746
  function(trigger)
699
- TriggerRegisterUnitEvent(trigger, self.handle, event)
747
+ TriggerRegisterUnitEvent(trigger, self.handle, jevent)
700
748
  end,
701
749
  collector or (function() return {} end)
702
750
  )
751
+ self.events:put(eventId, event)
703
752
  end
704
- return self.events[eventId]
753
+ return event
754
+ end
755
+ function Unit.prototype.saveData(self)
756
+ local handle = self.handle
757
+ self[108] = self[108] or getUnitX(handle)
758
+ self[109] = self[109] or getUnitY(handle)
759
+ self._owner = self._owner or Player:of(getOwningPlayer(handle))
705
760
  end
706
761
  function Unit.prototype.onDestroy(self)
707
762
  local handle = self.handle
708
- self[107] = getUnitX(handle)
709
- self[108] = getUnitY(handle)
710
- if not self._owner then
711
- self._owner = Player:of(getOwningPlayer(handle))
712
- end
763
+ self:saveData()
713
764
  local abilities = self.abilities
714
765
  for ____, ability in ipairs(abilities) do
715
766
  ability:destroy()
@@ -745,7 +796,11 @@ function Unit.prototype.addAttackHandler(self, condition, action)
745
796
  self._attackHandlers = handlers
746
797
  if #handlers == 1 then
747
798
  local handle = self.handle
748
- assert(unitAddAbility(handle, attackHandlerAbilityId) and UnitMakeAbilityPermanent(handle, true, attackHandlerAbilityId))
799
+ assert(
800
+ unitAddAbility(handle, attackHandlerAbilityId) and UnitMakeAbilityPermanent(handle, true, attackHandlerAbilityId),
801
+ "attack handler ability must be added",
802
+ self
803
+ )
749
804
  end
750
805
  return handler
751
806
  end
@@ -774,17 +829,17 @@ function Unit.prototype.addModifier(self, property, modifier)
774
829
  end}
775
830
  end
776
831
  function Unit.prototype.hasCombatClassification(self, combatClassification)
777
- local ____combatClassification_1 = combatClassification
778
- return getUnitIntegerField(self.handle, UNIT_IF_TARGETED_AS) & ____combatClassification_1 == ____combatClassification_1
832
+ local ____combatClassification_2 = combatClassification
833
+ return getUnitIntegerField(self.handle, UNIT_IF_TARGETED_AS) & ____combatClassification_2 == ____combatClassification_2
779
834
  end
780
835
  function Unit.prototype.addClassification(self, classification)
781
- return unitAddType(self.handle, classification)
836
+ return UnitAddType(self.handle, classification)
782
837
  end
783
838
  function Unit.prototype.removeClassification(self, classification)
784
- return unitRemoveType(self.handle, classification)
839
+ return UnitRemoveType(self.handle, classification)
785
840
  end
786
841
  function Unit.prototype.hasClassification(self, classification)
787
- return isUnitType(self.handle, classification)
842
+ return IsUnitType(self.handle, classification)
788
843
  end
789
844
  function Unit.prototype.isVisibleTo(self, player)
790
845
  return isUnitVisible(self.handle, player.handle)
@@ -793,13 +848,13 @@ function Unit.prototype.isInvisibleTo(self, player)
793
848
  return isUnitInvisible(self.handle, player.handle)
794
849
  end
795
850
  function Unit.prototype.isInRangeOf(self, x, y, range)
796
- local ____temp_2
851
+ local ____temp_3
797
852
  if type(x) == "number" then
798
- ____temp_2 = isUnitInRangeXY(self.handle, x, y, range)
853
+ ____temp_3 = isUnitInRangeXY(self.handle, x, y, range)
799
854
  else
800
- ____temp_2 = isUnitInRange(self.handle, x.handle, y)
855
+ ____temp_3 = isUnitInRange(self.handle, x.handle, y)
801
856
  end
802
- return ____temp_2
857
+ return ____temp_3
803
858
  end
804
859
  function Unit.prototype.isAllyOf(self, unit)
805
860
  return isUnitAlly(
@@ -829,16 +884,18 @@ function Unit.prototype.queueAnimation(self, animation)
829
884
  QueueUnitAnimation(self.handle, animation)
830
885
  end
831
886
  function Unit.prototype.chooseWeapon(self, target)
832
- if target:isAllowedTarget(self, self.firstWeapon.allowedTargetCombatClassifications) then
833
- return self.firstWeapon
887
+ local firstWeapon = self.firstWeapon
888
+ if firstWeapon.isEnabled and target:isAllowedTarget(self, firstWeapon.allowedTargetCombatClassifications) then
889
+ return firstWeapon
834
890
  end
835
- if target:isAllowedTarget(target, self.secondWeapon.allowedTargetCombatClassifications) then
836
- return self.secondWeapon
891
+ local secondWeapon = self.secondWeapon
892
+ if secondWeapon.isEnabled and target:isAllowedTarget(target, secondWeapon.allowedTargetCombatClassifications) then
893
+ return secondWeapon
837
894
  end
838
895
  return nil
839
896
  end
840
897
  function Unit.prototype.delayHealthChecks(self)
841
- self[103] = (self[103] or 0) + 1
898
+ self[104] = (self[104] or 0) + 1
842
899
  Timer:run(delayHealthChecksCallback, self)
843
900
  end
844
901
  function Unit.prototype.setPosition(self, x, y)
@@ -855,14 +912,14 @@ function Unit.prototype.kill(self)
855
912
  killUnit(self.handle)
856
913
  end
857
914
  function Unit.prototype.revive(self, x, y, doEffect)
858
- local ____ReviveHero_5 = ReviveHero
859
- local ____array_4 = __TS__SparseArrayNew(self.handle, x, y)
860
- local ____doEffect_3 = doEffect
861
- if ____doEffect_3 == nil then
862
- ____doEffect_3 = false
915
+ local ____ReviveHero_6 = ReviveHero
916
+ local ____array_5 = __TS__SparseArrayNew(self.handle, x, y)
917
+ local ____doEffect_4 = doEffect
918
+ if ____doEffect_4 == nil then
919
+ ____doEffect_4 = false
863
920
  end
864
- __TS__SparseArrayPush(____array_4, ____doEffect_3)
865
- ____ReviveHero_5(__TS__SparseArraySpread(____array_4))
921
+ __TS__SparseArrayPush(____array_5, ____doEffect_4)
922
+ ____ReviveHero_6(__TS__SparseArraySpread(____array_5))
866
923
  end
867
924
  function Unit.prototype.healTarget(self, target, amount)
868
925
  if __TS__InstanceOf(target, ____exports.Unit) and target:hasAbility(fourCC("BIhm")) then
@@ -905,17 +962,16 @@ function Unit.prototype.itemInSlot(self, slot)
905
962
  return Item:of(unitItemInSlot(self.handle, slot))
906
963
  end
907
964
  function Unit.prototype.addAbility(self, abilityId)
908
- if unitAddAbility(self.handle, abilityId) then
909
- local ability = UnitAbility:of(
910
- checkNotNull(getUnitAbility(self.handle, abilityId)),
911
- abilityId,
912
- self
913
- )
965
+ local ability = UnitAbility:of(
966
+ doUnitAbilityAction(self.handle, abilityId, addAbility, abilityId),
967
+ abilityId,
968
+ self
969
+ )
970
+ if ability ~= nil then
914
971
  local abilities = self.abilities
915
972
  abilities[#abilities + 1] = ability
916
- return ability
917
973
  end
918
- return nil
974
+ return ability
919
975
  end
920
976
  function Unit.prototype.makeAbilityPermanent(self, abilityId, permanent)
921
977
  return UnitMakeAbilityPermanent(self.handle, permanent, abilityId)
@@ -929,31 +985,21 @@ end
929
985
  function Unit.prototype.hasAbility(self, abilityId)
930
986
  return getUnitAbilityLevel(self.handle, abilityId) > 0
931
987
  end
932
- function Unit.prototype.getAbilityById(self, abilityId)
933
- local handle = self.handle
934
- if unitAddAbility(handle, abilityId) then
935
- assert(unitRemoveAbility(handle, abilityId))
936
- return nil
937
- end
938
- return UnitAbility:of(
939
- getUnitAbility(self.handle, abilityId),
940
- abilityId,
941
- self
942
- )
988
+ function Unit.prototype.getAbility(self, abilityId)
989
+ local ability = doUnitAbilityAction(self.handle, abilityId, getUnitAbility, abilityId)
990
+ return UnitAbility:of(ability, abilityId, self)
943
991
  end
944
- function Unit.prototype.removeAbility(self, abilityId)
945
- if unitRemoveAbility(self.handle, abilityId) then
946
- local abilities = self.abilities
947
- for i = 1, #abilities do
948
- if abilities[i].typeId == abilityId then
949
- abilities[i]:destroy()
950
- tremove(abilities, i)
951
- return true
952
- end
992
+ function Unit.prototype.removeAbility(self, abilityTypeId)
993
+ local abilities = self.abilities
994
+ for i = 1, #abilities do
995
+ if abilities[i].typeId == abilityTypeId then
996
+ local ability = abilities[i]
997
+ tremove(abilities, i)
998
+ ability:destroy()
999
+ return true
953
1000
  end
954
- return true
955
1001
  end
956
- return false
1002
+ return doUnitAbilityAction(self.handle, abilityTypeId, unitRemoveAbility, abilityTypeId)
957
1003
  end
958
1004
  function Unit.prototype.hideAbility(self, abilityId, flag)
959
1005
  BlzUnitHideAbility(self.handle, abilityId, flag)
@@ -967,9 +1013,6 @@ end
967
1013
  function Unit.prototype.endAbilityCooldown(self, abilityId)
968
1014
  BlzEndUnitAbilityCooldown(self.handle, abilityId)
969
1015
  end
970
- function Unit.prototype.interruptAttack(self)
971
- unitInterruptAttack(self.handle)
972
- end
973
1016
  function Unit.prototype.interruptCast(self, abilityId)
974
1017
  local handle = self.handle
975
1018
  unitDisableAbility(handle, abilityId, true, false)
@@ -1040,18 +1083,44 @@ function Unit.prototype.unpauseEx(self)
1040
1083
  end
1041
1084
  function Unit.prototype.incrementStunCounter(self)
1042
1085
  local stunCounter = self[102] or 0
1043
- if not self[101] or stunCounter >= 0 then
1086
+ if not self[101] and (self[103] or 0) <= 0 or stunCounter >= 0 then
1044
1087
  BlzPauseUnitEx(self.handle, true)
1045
1088
  end
1046
1089
  self[102] = stunCounter + 1
1047
1090
  end
1048
1091
  function Unit.prototype.decrementStunCounter(self)
1049
1092
  local stunCounter = self[102] or 0
1050
- if not self[101] or stunCounter >= 1 then
1093
+ if not self[101] and (self[103] or 0) <= 0 or stunCounter >= 1 then
1051
1094
  BlzPauseUnitEx(self.handle, false)
1052
1095
  end
1053
1096
  self[102] = stunCounter - 1
1054
1097
  end
1098
+ function Unit.prototype.incrementForceStunCounter(self)
1099
+ local forceStunCounter = self[103] or 0
1100
+ if forceStunCounter == 0 then
1101
+ local handle = self.handle
1102
+ if not self[101] then
1103
+ for _ = self[102] or 0, -1 do
1104
+ BlzPauseUnitEx(handle, true)
1105
+ end
1106
+ end
1107
+ BlzPauseUnitEx(handle, true)
1108
+ end
1109
+ self[103] = forceStunCounter + 1
1110
+ end
1111
+ function Unit.prototype.decrementForceStunCounter(self)
1112
+ local forceStunCounter = self[103] or 0
1113
+ if forceStunCounter == 1 then
1114
+ local handle = self.handle
1115
+ if not self[101] then
1116
+ for _ = self[102] or 0, -1 do
1117
+ BlzPauseUnitEx(handle, false)
1118
+ end
1119
+ end
1120
+ BlzPauseUnitEx(handle, false)
1121
+ end
1122
+ self[103] = forceStunCounter - 1
1123
+ end
1055
1124
  function Unit.create(self, owner, id, x, y, facing, skinId)
1056
1125
  local handle = skinId and BlzCreateUnitWithSkin(
1057
1126
  owner.handle,
@@ -1240,7 +1309,7 @@ __TS__SetDescriptor(
1240
1309
  Unit.prototype,
1241
1310
  "isIllusion",
1242
1311
  {get = function(self)
1243
- return isUnitIllusion(self.handle)
1312
+ return IsUnitIllusion(self.handle)
1244
1313
  end},
1245
1314
  true
1246
1315
  )
@@ -1338,19 +1407,6 @@ __TS__SetDescriptor(
1338
1407
  },
1339
1408
  true
1340
1409
  )
1341
- __TS__SetDescriptor(
1342
- Unit.prototype,
1343
- "strengthBase",
1344
- {
1345
- get = function(self)
1346
- return getHeroStr(self.handle, false)
1347
- end,
1348
- set = function(self, strengthBase)
1349
- setHeroStr(self.handle, strengthBase, true)
1350
- end
1351
- },
1352
- true
1353
- )
1354
1410
  __TS__SetDescriptor(
1355
1411
  Unit.prototype,
1356
1412
  "strengthBonus",
@@ -1368,19 +1424,6 @@ __TS__SetDescriptor(
1368
1424
  end},
1369
1425
  true
1370
1426
  )
1371
- __TS__SetDescriptor(
1372
- Unit.prototype,
1373
- "agilityBase",
1374
- {
1375
- get = function(self)
1376
- return getHeroAgi(self.handle, false)
1377
- end,
1378
- set = function(self, agilityBase)
1379
- setHeroAgi(self.handle, agilityBase, true)
1380
- end
1381
- },
1382
- true
1383
- )
1384
1427
  __TS__SetDescriptor(
1385
1428
  Unit.prototype,
1386
1429
  "agilityBonus",
@@ -1398,19 +1441,6 @@ __TS__SetDescriptor(
1398
1441
  end},
1399
1442
  true
1400
1443
  )
1401
- __TS__SetDescriptor(
1402
- Unit.prototype,
1403
- "intelligenceBase",
1404
- {
1405
- get = function(self)
1406
- return getHeroInt(self.handle, false)
1407
- end,
1408
- set = function(self, intelligenceBase)
1409
- setHeroInt(self.handle, intelligenceBase, true)
1410
- end
1411
- },
1412
- true
1413
- )
1414
1444
  __TS__SetDescriptor(
1415
1445
  Unit.prototype,
1416
1446
  "intelligenceBonus",
@@ -1459,17 +1489,17 @@ __TS__SetDescriptor(
1459
1489
  "isTeamGlowVisible",
1460
1490
  {
1461
1491
  get = function(self)
1462
- return not self[106]
1492
+ return not self[107]
1463
1493
  end,
1464
1494
  set = function(self, isTeamGlowVisible)
1465
1495
  BlzShowUnitTeamGlow(self.handle, isTeamGlowVisible)
1466
- local ____temp_6
1496
+ local ____temp_7
1467
1497
  if not isTeamGlowVisible then
1468
- ____temp_6 = true
1498
+ ____temp_7 = true
1469
1499
  else
1470
- ____temp_6 = nil
1500
+ ____temp_7 = nil
1471
1501
  end
1472
- self[106] = ____temp_6
1502
+ self[107] = ____temp_7
1473
1503
  end
1474
1504
  },
1475
1505
  true
@@ -1479,7 +1509,7 @@ __TS__SetDescriptor(
1479
1509
  "color",
1480
1510
  {set = function(self, color)
1481
1511
  SetUnitColor(self.handle, color.handle)
1482
- if self[106] then
1512
+ if self[107] then
1483
1513
  BlzShowUnitTeamGlow(self.handle, false)
1484
1514
  end
1485
1515
  end},
@@ -1503,14 +1533,14 @@ __TS__SetDescriptor(
1503
1533
  "maxHealth",
1504
1534
  {
1505
1535
  get = function(self)
1506
- return BlzGetUnitMaxHP(self.handle) - (self[104] or 0) - (self[105] or 0)
1536
+ return BlzGetUnitMaxHP(self.handle) - (self[105] or 0) - (self[106] or 0)
1507
1537
  end,
1508
1538
  set = function(self, maxHealth)
1509
- if maxHealth < 1 and self[103] ~= nil then
1510
- self[104] = (self[104] or 0) + (1 - maxHealth)
1539
+ if maxHealth < 1 and self[104] ~= nil then
1540
+ self[105] = (self[105] or 0) + (1 - maxHealth)
1511
1541
  maxHealth = 1
1512
1542
  end
1513
- BlzSetUnitMaxHP(self.handle, maxHealth + (self[105] or 0))
1543
+ BlzSetUnitMaxHP(self.handle, maxHealth + (self[106] or 0))
1514
1544
  end
1515
1545
  },
1516
1546
  true
@@ -1552,10 +1582,10 @@ __TS__SetDescriptor(
1552
1582
  "health",
1553
1583
  {
1554
1584
  get = function(self)
1555
- return GetWidgetLife(self.handle) - (self[105] or 0)
1585
+ return GetWidgetLife(self.handle) - (self[106] or 0)
1556
1586
  end,
1557
1587
  set = function(self, health)
1558
- SetWidgetLife(self.handle, health + (self[105] or 0))
1588
+ SetWidgetLife(self.handle, health + (self[106] or 0))
1559
1589
  end
1560
1590
  },
1561
1591
  true
@@ -1631,25 +1661,12 @@ __TS__SetDescriptor(
1631
1661
  },
1632
1662
  true
1633
1663
  )
1634
- __TS__SetDescriptor(
1635
- Unit.prototype,
1636
- "flyHeight",
1637
- {
1638
- get = function(self)
1639
- return getUnitFlyHeight(self.handle)
1640
- end,
1641
- set = function(self, v)
1642
- SetUnitFlyHeight(self.handle, v, 100000)
1643
- end
1644
- },
1645
- true
1646
- )
1647
1664
  __TS__SetDescriptor(
1648
1665
  Unit.prototype,
1649
1666
  "x",
1650
1667
  {
1651
1668
  get = function(self)
1652
- return self[107] or getUnitX(self.handle)
1669
+ return self[108] or getUnitX(self.handle)
1653
1670
  end,
1654
1671
  set = function(self, v)
1655
1672
  SetUnitX(self.handle, v)
@@ -1662,7 +1679,7 @@ __TS__SetDescriptor(
1662
1679
  "y",
1663
1680
  {
1664
1681
  get = function(self)
1665
- return self[108] or getUnitY(self.handle)
1682
+ return self[109] or getUnitY(self.handle)
1666
1683
  end,
1667
1684
  set = function(self, v)
1668
1685
  SetUnitY(self.handle, v)
@@ -1767,14 +1784,18 @@ __TS__SetDescriptor(
1767
1784
  local handle = self.handle
1768
1785
  if isPaused and not IsUnitPaused(handle) then
1769
1786
  self[101] = true
1770
- for _ = self[102] or 0, -1 do
1771
- BlzPauseUnitEx(handle, true)
1787
+ if (self[103] or 0) <= 0 then
1788
+ for _ = self[102] or 0, -1 do
1789
+ BlzPauseUnitEx(handle, true)
1790
+ end
1772
1791
  end
1773
1792
  PauseUnit(handle, true)
1774
1793
  elseif not isPaused and IsUnitPaused(handle) then
1775
1794
  PauseUnit(handle, false)
1776
- for _ = self[102] or 0, -1 do
1777
- BlzPauseUnitEx(handle, false)
1795
+ if (self[103] or 0) <= 0 then
1796
+ for _ = self[102] or 0, -1 do
1797
+ BlzPauseUnitEx(handle, false)
1798
+ end
1778
1799
  end
1779
1800
  self[101] = nil
1780
1801
  end
@@ -1832,20 +1853,6 @@ __TS__SetDescriptor(
1832
1853
  },
1833
1854
  true
1834
1855
  )
1835
- __TS__SetDescriptor(
1836
- Unit.prototype,
1837
- "scale",
1838
- {
1839
- get = function(self)
1840
- return getUnitRealField(self.handle, UNIT_RF_SCALING_VALUE)
1841
- end,
1842
- set = function(self, v)
1843
- setUnitScale(self.handle, v, v, v)
1844
- setUnitRealField(self.handle, UNIT_RF_SCALING_VALUE, v)
1845
- end
1846
- },
1847
- true
1848
- )
1849
1856
  __TS__SetDescriptor(
1850
1857
  Unit.prototype,
1851
1858
  "timeScale",
@@ -1982,30 +1989,6 @@ __TS__SetDescriptor(
1982
1989
  end},
1983
1990
  true
1984
1991
  )
1985
- __TS__SetDescriptor(
1986
- Unit.prototype,
1987
- "onUnitInRange",
1988
- {get = function(self)
1989
- local handle = self.handle
1990
- local onUnitInRange = setmetatable(
1991
- {},
1992
- {__index = function(self, value)
1993
- local event = __TS__New(
1994
- TriggerEvent,
1995
- function(trigger)
1996
- TriggerRegisterUnitInRangeSimple(trigger, value, handle)
1997
- end,
1998
- function() return ____exports.Unit:of(handle) end
1999
- )
2000
- rawset(self, value, event)
2001
- return event
2002
- end}
2003
- )
2004
- rawset(self, "onUnitInRange", onUnitInRange)
2005
- return onUnitInRange
2006
- end},
2007
- true
2008
- )
2009
1992
  __TS__SetDescriptor(
2010
1993
  Unit.prototype,
2011
1994
  "onManaEqual",
@@ -2141,6 +2124,11 @@ __TS__SetDescriptor(
2141
2124
  end},
2142
2125
  true
2143
2126
  )
2127
+ Unit.levelChangedEvent = __TS__New(
2128
+ ____exports.UnitTriggerEvent,
2129
+ EVENT_PLAYER_HERO_LEVEL,
2130
+ function() return ____exports.Unit:of(getTriggerUnit()) end
2131
+ )
2144
2132
  Unit.deathEvent = __TS__New(
2145
2133
  ____exports.UnitTriggerEvent,
2146
2134
  EVENT_PLAYER_UNIT_DEATH,
@@ -2216,25 +2204,25 @@ Unit.onTargetCast = dispatchId(__TS__New(
2216
2204
  InitializingEvent,
2217
2205
  function(event)
2218
2206
  local function listener(unit, id)
2219
- local ____GetSpellTargetUnit_result_9
2207
+ local ____GetSpellTargetUnit_result_10
2220
2208
  if GetSpellTargetUnit() then
2221
- ____GetSpellTargetUnit_result_9 = ____exports.Unit:of(GetSpellTargetUnit())
2209
+ ____GetSpellTargetUnit_result_10 = ____exports.Unit:of(GetSpellTargetUnit())
2222
2210
  else
2223
- local ____GetSpellTargetItem_result_8
2211
+ local ____GetSpellTargetItem_result_9
2224
2212
  if GetSpellTargetItem() then
2225
- ____GetSpellTargetItem_result_8 = Item:of(GetSpellTargetItem())
2213
+ ____GetSpellTargetItem_result_9 = Item:of(GetSpellTargetItem())
2226
2214
  else
2227
- local ____GetSpellTargetDestructable_result_7
2215
+ local ____GetSpellTargetDestructable_result_8
2228
2216
  if GetSpellTargetDestructable() then
2229
- ____GetSpellTargetDestructable_result_7 = Destructable:of(GetSpellTargetDestructable())
2217
+ ____GetSpellTargetDestructable_result_8 = Destructable:of(GetSpellTargetDestructable())
2230
2218
  else
2231
- ____GetSpellTargetDestructable_result_7 = nil
2219
+ ____GetSpellTargetDestructable_result_8 = nil
2232
2220
  end
2233
- ____GetSpellTargetItem_result_8 = ____GetSpellTargetDestructable_result_7
2221
+ ____GetSpellTargetItem_result_9 = ____GetSpellTargetDestructable_result_8
2234
2222
  end
2235
- ____GetSpellTargetUnit_result_9 = ____GetSpellTargetItem_result_8
2223
+ ____GetSpellTargetUnit_result_10 = ____GetSpellTargetItem_result_9
2236
2224
  end
2237
- local target = ____GetSpellTargetUnit_result_9
2225
+ local target = ____GetSpellTargetUnit_result_10
2238
2226
  if target then
2239
2227
  invoke(event, unit, id, target)
2240
2228
  end
@@ -2457,12 +2445,7 @@ Unit.onDamaging = (function()
2457
2445
  preventRetaliation = damagingEventPreventRetaliation
2458
2446
  }
2459
2447
  if data.isAttack and source then
2460
- 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
2461
- if weapon == -1 then
2462
- local targetsAllowed = BlzGetUnitWeaponIntegerField(source.handle, UNIT_WEAPON_IF_ATTACK_TARGETS_ALLOWED, 0)
2463
- weapon = 0
2464
- end
2465
- data.weapon = assert(source.weapons[weapon + 1])
2448
+ data.weapon = source:chooseWeapon(target)
2466
2449
  end
2467
2450
  if not data.isAttack or not source or not source._attackHandlers then
2468
2451
  invoke(
@@ -2607,7 +2590,7 @@ Unit.onDamage = __TS__New(
2607
2590
  invoke(event, source, target, evData)
2608
2591
  if evData[0] ~= nil and target.health - evData.amount < 0.405 then
2609
2592
  local bonusHealth = math.ceil(evData.amount)
2610
- target[105] = (target[105] or 0) + bonusHealth
2593
+ target[106] = (target[106] or 0) + bonusHealth
2611
2594
  BlzSetUnitMaxHP(
2612
2595
  target.handle,
2613
2596
  BlzGetUnitMaxHP(target.handle) + bonusHealth
@@ -2621,7 +2604,7 @@ Unit.onDamage = __TS__New(
2621
2604
  evData[0],
2622
2605
  table.unpack(evData, 1 + 1, 1 + (evData[1] or 0))
2623
2606
  )
2624
- target[105] = (target[105] or 0) - bonusHealth
2607
+ target[106] = (target[106] or 0) - bonusHealth
2625
2608
  SetWidgetLife(
2626
2609
  target.handle,
2627
2610
  GetWidgetLife(target.handle) - bonusHealth
@@ -2657,10 +2640,14 @@ Unit.itemPickedUpEvent = __TS__New(
2657
2640
  ____exports.UnitTriggerEvent,
2658
2641
  EVENT_PLAYER_UNIT_PICKUP_ITEM,
2659
2642
  function()
2660
- local unit = getTriggerUnit()
2661
- local item = getManipulatedItem()
2662
- if getUnitTypeId(unit) ~= dummyUnitId and not (ignoreEventsItems[item] ~= nil) then
2663
- return ____exports.Unit:of(unit), Item:of(item)
2643
+ local unitHandle = getTriggerUnit()
2644
+ local itemHandle = getManipulatedItem()
2645
+ if getUnitTypeId(unitHandle) ~= dummyUnitId and not (ignoreEventsItems[itemHandle] ~= nil) then
2646
+ local unit = ____exports.Unit:of(unitHandle)
2647
+ local item = Item:of(itemHandle)
2648
+ if item.owner ~= unit then
2649
+ return unit, item
2650
+ end
2664
2651
  end
2665
2652
  return IgnoreEvent
2666
2653
  end
@@ -2680,7 +2667,22 @@ Unit.itemUsedEvent = __TS__New(
2680
2667
  Unit.itemStackedEvent = __TS__New(
2681
2668
  ____exports.UnitTriggerEvent,
2682
2669
  EVENT_PLAYER_UNIT_STACK_ITEM,
2683
- function() return ____exports.Unit:of(getTriggerUnit()), Item:of(getManipulatedItem()) end
2670
+ function() return ____exports.Unit:of(getTriggerUnit()), Item:of(BlzGetStackingItemTarget()), Item:of(BlzGetStackingItemSource()) end
2671
+ )
2672
+ __TS__ObjectDefineProperty(
2673
+ Unit,
2674
+ "itemChargesChangedEvent",
2675
+ {get = function(self)
2676
+ local event = __TS__New(Event)
2677
+ Item.chargesChangedEvent:addListener(function(item)
2678
+ local unit = item.owner
2679
+ if unit ~= nil then
2680
+ invoke(event, unit, item)
2681
+ end
2682
+ end)
2683
+ rawset(self, "itemChargesChangedEvent", event)
2684
+ return event
2685
+ end}
2684
2686
  )
2685
2687
  __TS__ObjectDefineProperty(
2686
2688
  Unit,
@@ -2752,6 +2754,10 @@ __TS__ObjectDefineProperty(
2752
2754
  rawset(self, "destroyEvent", destroyEvent)
2753
2755
  return destroyEvent
2754
2756
  end}
2757
+ )
2758
+ Unit.synchronize = synchronizer(
2759
+ function(unit) return unit.syncId end,
2760
+ function(syncId) return unitBySyncId[syncId] end
2755
2761
  );
2756
2762
  (function(self)
2757
2763
  local leaveAbilityIds = postcompile(function()
@@ -2781,7 +2787,8 @@ __TS__ObjectDefineProperty(
2781
2787
  return
2782
2788
  end
2783
2789
  end
2784
- unit:destroy()
2790
+ unit:saveData()
2791
+ Timer:run(unit, "destroy")
2785
2792
  end)
2786
2793
  end
2787
2794
  end)(Unit)