warscript 0.0.1-dev.8a25bb1 → 0.0.1-dev.8ba6984

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 (121) 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 +2 -1
  25. package/engine/behaviour/ability.lua +10 -18
  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 +39 -3
  29. package/engine/behaviour/unit.lua +269 -6
  30. package/engine/buff.d.ts +21 -8
  31. package/engine/buff.lua +187 -121
  32. package/engine/internal/ability.d.ts +7 -1
  33. package/engine/internal/ability.lua +49 -9
  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/allowed-targets.d.ts +1 -1
  50. package/engine/internal/unit/allowed-targets.lua +9 -1
  51. package/engine/internal/unit/attributes.d.ts +17 -0
  52. package/engine/internal/unit/attributes.lua +46 -0
  53. package/engine/internal/unit/bonus.d.ts +2 -0
  54. package/engine/internal/unit/bonus.lua +10 -0
  55. package/engine/internal/unit/fly-height.d.ts +7 -0
  56. package/engine/internal/unit/fly-height.lua +20 -0
  57. package/engine/internal/unit/interrupts.d.ts +12 -0
  58. package/engine/internal/unit/interrupts.lua +28 -0
  59. package/engine/internal/unit/main-selected.lua +12 -27
  60. package/engine/internal/unit/order.d.ts +20 -0
  61. package/engine/internal/unit/order.lua +136 -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 +25 -24
  67. package/engine/internal/unit.lua +288 -210
  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.lua +5 -4
  77. package/engine/object-data/entry/destructible-type.d.ts +27 -1
  78. package/engine/object-data/entry/destructible-type.lua +155 -0
  79. package/engine/object-data/entry/unit-type.d.ts +15 -2
  80. package/engine/object-data/entry/unit-type.lua +135 -33
  81. package/engine/object-field/ability.d.ts +3 -3
  82. package/engine/object-field/ability.lua +7 -6
  83. package/engine/object-field/unit.d.ts +31 -5
  84. package/engine/object-field/unit.lua +95 -0
  85. package/engine/object-field.d.ts +17 -6
  86. package/engine/object-field.lua +291 -134
  87. package/engine/random.d.ts +9 -0
  88. package/engine/random.lua +13 -0
  89. package/engine/standard/fields/ability.d.ts +2 -2
  90. package/engine/standard/fields/ability.lua +2 -2
  91. package/engine/standard/fields/unit.d.ts +12 -0
  92. package/engine/standard/fields/unit.lua +20 -0
  93. package/engine/synchronization.d.ts +11 -0
  94. package/engine/synchronization.lua +77 -0
  95. package/engine/text-tag.d.ts +36 -2
  96. package/engine/text-tag.lua +250 -10
  97. package/engine/unit.d.ts +5 -0
  98. package/engine/unit.lua +5 -0
  99. package/net/socket.lua +1 -1
  100. package/objutil/buff.lua +10 -8
  101. package/package.json +2 -2
  102. package/patch-lua.lua +15 -0
  103. package/patch-lualib.lua +1 -1
  104. package/utility/arrays.d.ts +1 -0
  105. package/utility/arrays.lua +8 -0
  106. package/utility/callback-array.d.ts +17 -0
  107. package/utility/callback-array.lua +61 -0
  108. package/utility/functions.d.ts +7 -0
  109. package/utility/functions.lua +12 -0
  110. package/utility/linked-map.d.ts +26 -0
  111. package/utility/linked-map.lua +66 -0
  112. package/utility/linked-set.d.ts +1 -0
  113. package/utility/linked-set.lua +23 -1
  114. package/utility/lua-maps.d.ts +12 -2
  115. package/utility/lua-maps.lua +37 -2
  116. package/utility/lua-sets.d.ts +1 -0
  117. package/utility/lua-sets.lua +4 -0
  118. package/utility/records.lua +20 -1
  119. package/utility/types.d.ts +3 -0
  120. package/core/types/order.d.ts +0 -25
  121. package/core/types/order.lua +0 -55
@@ -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
@@ -347,6 +344,9 @@ local function dispatchAbility(event)
347
344
  }
348
345
  )
349
346
  end
347
+ local function damagingEventPreventRetaliation(self)
348
+ self[0] = true
349
+ end
350
350
  local function damageEventPreventDeath(self, callback, ...)
351
351
  if self[0] ~= nil then
352
352
  return
@@ -383,15 +383,27 @@ local modifiers = {
383
383
  end,
384
384
  armor = function(unit, value)
385
385
  if UnitAddAbility(unit, armorBonusAbilityId) then
386
- assert(UnitMakeAbilityPermanent(unit, true, armorBonusAbilityId))
386
+ assert(
387
+ UnitMakeAbilityPermanent(unit, true, armorBonusAbilityId),
388
+ "armor bonus ability must be made permanent",
389
+ unit
390
+ )
387
391
  end
388
- local ability = assert(BlzGetUnitAbility(unit, armorBonusAbilityId))
389
- assert(BlzSetAbilityRealLevelField(
390
- ability,
391
- armorBonusField,
392
- 0,
393
- BlzGetAbilityRealLevelField(ability, armorBonusField, 0) + value
394
- ))
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
+ )
395
407
  end
396
408
  }
397
409
  local getters = {
@@ -409,6 +421,19 @@ function UnitWeapon.prototype.____constructor(self, unit, index)
409
421
  self.unit = unit
410
422
  self.index = index
411
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
+ )
412
437
  __TS__SetDescriptor(
413
438
  UnitWeapon.prototype,
414
439
  "cooldown",
@@ -443,6 +468,19 @@ __TS__SetDescriptor(
443
468
  },
444
469
  true
445
470
  )
471
+ __TS__SetDescriptor(
472
+ UnitWeapon.prototype,
473
+ "allowedTargetCombatClassifications",
474
+ {
475
+ get = function(self)
476
+ return BlzGetUnitWeaponIntegerField(self.unit.handle, UNIT_WEAPON_IF_ATTACK_TARGETS_ALLOWED, self.index)
477
+ end,
478
+ set = function(self, allowedTargetCombatClassifications)
479
+ BlzSetUnitWeaponIntegerField(self.unit.handle, UNIT_WEAPON_IF_ATTACK_TARGETS_ALLOWED, self.index, allowedTargetCombatClassifications)
480
+ end
481
+ },
482
+ true
483
+ )
446
484
  __TS__SetDescriptor(
447
485
  UnitWeapon.prototype,
448
486
  "damageBase",
@@ -619,26 +657,30 @@ local fieldSetters = {
619
657
  }
620
658
  local dummies = {}
621
659
  for ____, player in ipairs(Player.all) do
622
- local dummy = assert(createUnit(
623
- player.handle,
624
- dummyUnitId,
625
- 0,
626
- 0,
627
- 270
628
- ))
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
+ )
629
671
  ShowUnit(dummy, false)
630
672
  dummies[player] = dummy
631
673
  end
632
674
  local function delayHealthChecksCallback(unit)
633
- local counter = (unit[103] or 0) - 1
675
+ local counter = (unit[104] or 0) - 1
634
676
  if counter ~= 0 then
635
- unit[103] = counter
677
+ unit[104] = counter
636
678
  return
637
679
  end
638
- unit[103] = nil
639
- local healthBonus = unit[104]
680
+ unit[104] = nil
681
+ local healthBonus = unit[105]
640
682
  if healthBonus ~= nil then
641
- unit[104] = nil
683
+ unit[105] = nil
642
684
  local handle = unit.handle
643
685
  BlzSetUnitMaxHP(
644
686
  handle,
@@ -649,48 +691,71 @@ end
649
691
  local nextSyncId = 1
650
692
  local unitBySyncId = setmetatable({}, {__mode = "v"})
651
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
652
703
  ____exports.Unit = __TS__Class()
653
704
  local Unit = ____exports.Unit
654
705
  Unit.name = "Unit"
655
706
  __TS__ClassExtends(Unit, Handle)
656
707
  function Unit.prototype.____constructor(self, handle)
657
708
  Handle.prototype.____constructor(self, handle)
658
- local ____nextSyncId_0 = nextSyncId
659
- nextSyncId = ____nextSyncId_0 + 1
660
- self.syncId = ____nextSyncId_0
709
+ local ____nextSyncId_1 = nextSyncId
710
+ nextSyncId = ____nextSyncId_1 + 1
711
+ self.syncId = ____nextSyncId_1
661
712
  self._owner = Player:of(getOwningPlayer(handle))
662
- assert(unitAddAbility(handle, leaveDetectAbilityId) and UnitMakeAbilityPermanent(handle, true, leaveDetectAbilityId))
663
- 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
+ )
664
723
  if unitAddAbility(
665
724
  handle,
666
725
  fourCC("Amrf")
667
726
  ) then
668
- assert(unitRemoveAbility(
669
- handle,
670
- fourCC("Amrf")
671
- ))
727
+ assert(
728
+ unitRemoveAbility(
729
+ handle,
730
+ fourCC("Amrf")
731
+ ),
732
+ "fly ability must be removed after addition",
733
+ self
734
+ )
672
735
  end
673
736
  unitBySyncId[self.syncId] = self
674
737
  local ____ = self.abilities
675
738
  end
676
- function Unit.prototype.getEvent(self, event, collector)
677
- self.events = self.events or ({})
678
- local eventId = GetHandleId(event)
679
- if not self.events[eventId] then
680
- 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(
681
745
  TriggerEvent,
682
746
  function(trigger)
683
- TriggerRegisterUnitEvent(trigger, self.handle, event)
747
+ TriggerRegisterUnitEvent(trigger, self.handle, jevent)
684
748
  end,
685
749
  collector or (function() return {} end)
686
750
  )
751
+ self.events:put(eventId, event)
687
752
  end
688
- return self.events[eventId]
753
+ return event
689
754
  end
690
755
  function Unit.prototype.onDestroy(self)
691
756
  local handle = self.handle
692
- self[107] = getUnitX(handle)
693
- self[108] = getUnitY(handle)
757
+ self[108] = getUnitX(handle)
758
+ self[109] = getUnitY(handle)
694
759
  if not self._owner then
695
760
  self._owner = Player:of(getOwningPlayer(handle))
696
761
  end
@@ -729,7 +794,11 @@ function Unit.prototype.addAttackHandler(self, condition, action)
729
794
  self._attackHandlers = handlers
730
795
  if #handlers == 1 then
731
796
  local handle = self.handle
732
- assert(unitAddAbility(handle, attackHandlerAbilityId) and UnitMakeAbilityPermanent(handle, true, attackHandlerAbilityId))
797
+ assert(
798
+ unitAddAbility(handle, attackHandlerAbilityId) and UnitMakeAbilityPermanent(handle, true, attackHandlerAbilityId),
799
+ "attack handler ability must be added",
800
+ self
801
+ )
733
802
  end
734
803
  return handler
735
804
  end
@@ -758,17 +827,17 @@ function Unit.prototype.addModifier(self, property, modifier)
758
827
  end}
759
828
  end
760
829
  function Unit.prototype.hasCombatClassification(self, combatClassification)
761
- local ____combatClassification_1 = combatClassification
762
- return getUnitIntegerField(self.handle, UNIT_IF_TARGETED_AS) & ____combatClassification_1 == ____combatClassification_1
830
+ local ____combatClassification_2 = combatClassification
831
+ return getUnitIntegerField(self.handle, UNIT_IF_TARGETED_AS) & ____combatClassification_2 == ____combatClassification_2
763
832
  end
764
833
  function Unit.prototype.addClassification(self, classification)
765
- return unitAddType(self.handle, classification)
834
+ return UnitAddType(self.handle, classification)
766
835
  end
767
836
  function Unit.prototype.removeClassification(self, classification)
768
- return unitRemoveType(self.handle, classification)
837
+ return UnitRemoveType(self.handle, classification)
769
838
  end
770
839
  function Unit.prototype.hasClassification(self, classification)
771
- return isUnitType(self.handle, classification)
840
+ return IsUnitType(self.handle, classification)
772
841
  end
773
842
  function Unit.prototype.isVisibleTo(self, player)
774
843
  return isUnitVisible(self.handle, player.handle)
@@ -777,13 +846,13 @@ function Unit.prototype.isInvisibleTo(self, player)
777
846
  return isUnitInvisible(self.handle, player.handle)
778
847
  end
779
848
  function Unit.prototype.isInRangeOf(self, x, y, range)
780
- local ____temp_2
849
+ local ____temp_3
781
850
  if type(x) == "number" then
782
- ____temp_2 = isUnitInRangeXY(self.handle, x, y, range)
851
+ ____temp_3 = isUnitInRangeXY(self.handle, x, y, range)
783
852
  else
784
- ____temp_2 = isUnitInRange(self.handle, x.handle, y)
853
+ ____temp_3 = isUnitInRange(self.handle, x.handle, y)
785
854
  end
786
- return ____temp_2
855
+ return ____temp_3
787
856
  end
788
857
  function Unit.prototype.isAllyOf(self, unit)
789
858
  return isUnitAlly(
@@ -812,8 +881,19 @@ end
812
881
  function Unit.prototype.queueAnimation(self, animation)
813
882
  QueueUnitAnimation(self.handle, animation)
814
883
  end
884
+ function Unit.prototype.chooseWeapon(self, target)
885
+ local firstWeapon = self.firstWeapon
886
+ if firstWeapon.isEnabled and target:isAllowedTarget(self, firstWeapon.allowedTargetCombatClassifications) then
887
+ return firstWeapon
888
+ end
889
+ local secondWeapon = self.secondWeapon
890
+ if secondWeapon.isEnabled and target:isAllowedTarget(target, secondWeapon.allowedTargetCombatClassifications) then
891
+ return secondWeapon
892
+ end
893
+ return nil
894
+ end
815
895
  function Unit.prototype.delayHealthChecks(self)
816
- self[103] = (self[103] or 0) + 1
896
+ self[104] = (self[104] or 0) + 1
817
897
  Timer:run(delayHealthChecksCallback, self)
818
898
  end
819
899
  function Unit.prototype.setPosition(self, x, y)
@@ -830,14 +910,14 @@ function Unit.prototype.kill(self)
830
910
  killUnit(self.handle)
831
911
  end
832
912
  function Unit.prototype.revive(self, x, y, doEffect)
833
- local ____ReviveHero_5 = ReviveHero
834
- local ____array_4 = __TS__SparseArrayNew(self.handle, x, y)
835
- local ____doEffect_3 = doEffect
836
- if ____doEffect_3 == nil then
837
- ____doEffect_3 = false
913
+ local ____ReviveHero_6 = ReviveHero
914
+ local ____array_5 = __TS__SparseArrayNew(self.handle, x, y)
915
+ local ____doEffect_4 = doEffect
916
+ if ____doEffect_4 == nil then
917
+ ____doEffect_4 = false
838
918
  end
839
- __TS__SparseArrayPush(____array_4, ____doEffect_3)
840
- ____ReviveHero_5(__TS__SparseArraySpread(____array_4))
919
+ __TS__SparseArrayPush(____array_5, ____doEffect_4)
920
+ ____ReviveHero_6(__TS__SparseArraySpread(____array_5))
841
921
  end
842
922
  function Unit.prototype.healTarget(self, target, amount)
843
923
  if __TS__InstanceOf(target, ____exports.Unit) and target:hasAbility(fourCC("BIhm")) then
@@ -880,17 +960,16 @@ function Unit.prototype.itemInSlot(self, slot)
880
960
  return Item:of(unitItemInSlot(self.handle, slot))
881
961
  end
882
962
  function Unit.prototype.addAbility(self, abilityId)
883
- if unitAddAbility(self.handle, abilityId) then
884
- local ability = UnitAbility:of(
885
- checkNotNull(getUnitAbility(self.handle, abilityId)),
886
- abilityId,
887
- self
888
- )
963
+ local ability = UnitAbility:of(
964
+ doUnitAbilityAction(self.handle, abilityId, addAbility, abilityId),
965
+ abilityId,
966
+ self
967
+ )
968
+ if ability ~= nil then
889
969
  local abilities = self.abilities
890
970
  abilities[#abilities + 1] = ability
891
- return ability
892
971
  end
893
- return nil
972
+ return ability
894
973
  end
895
974
  function Unit.prototype.makeAbilityPermanent(self, abilityId, permanent)
896
975
  return UnitMakeAbilityPermanent(self.handle, permanent, abilityId)
@@ -904,31 +983,21 @@ end
904
983
  function Unit.prototype.hasAbility(self, abilityId)
905
984
  return getUnitAbilityLevel(self.handle, abilityId) > 0
906
985
  end
907
- function Unit.prototype.getAbilityById(self, abilityId)
908
- local handle = self.handle
909
- if unitAddAbility(handle, abilityId) then
910
- assert(unitRemoveAbility(handle, abilityId))
911
- return nil
912
- end
913
- return UnitAbility:of(
914
- getUnitAbility(self.handle, abilityId),
915
- abilityId,
916
- self
917
- )
986
+ function Unit.prototype.getAbility(self, abilityId)
987
+ local ability = doUnitAbilityAction(self.handle, abilityId, getUnitAbility, abilityId)
988
+ return UnitAbility:of(ability, abilityId, self)
918
989
  end
919
- function Unit.prototype.removeAbility(self, abilityId)
920
- if unitRemoveAbility(self.handle, abilityId) then
921
- local abilities = self.abilities
922
- for i = 1, #abilities do
923
- if abilities[i].typeId == abilityId then
924
- abilities[i]:destroy()
925
- tremove(abilities, i)
926
- return true
927
- end
990
+ function Unit.prototype.removeAbility(self, abilityTypeId)
991
+ local abilities = self.abilities
992
+ for i = 1, #abilities do
993
+ if abilities[i].typeId == abilityTypeId then
994
+ local ability = abilities[i]
995
+ tremove(abilities, i)
996
+ ability:destroy()
997
+ return true
928
998
  end
929
- return true
930
999
  end
931
- return false
1000
+ return doUnitAbilityAction(self.handle, abilityTypeId, unitRemoveAbility, abilityTypeId)
932
1001
  end
933
1002
  function Unit.prototype.hideAbility(self, abilityId, flag)
934
1003
  BlzUnitHideAbility(self.handle, abilityId, flag)
@@ -942,9 +1011,6 @@ end
942
1011
  function Unit.prototype.endAbilityCooldown(self, abilityId)
943
1012
  BlzEndUnitAbilityCooldown(self.handle, abilityId)
944
1013
  end
945
- function Unit.prototype.interruptAttack(self)
946
- unitInterruptAttack(self.handle)
947
- end
948
1014
  function Unit.prototype.interruptCast(self, abilityId)
949
1015
  local handle = self.handle
950
1016
  unitDisableAbility(handle, abilityId, true, false)
@@ -1015,18 +1081,44 @@ function Unit.prototype.unpauseEx(self)
1015
1081
  end
1016
1082
  function Unit.prototype.incrementStunCounter(self)
1017
1083
  local stunCounter = self[102] or 0
1018
- if not self[101] or stunCounter >= 0 then
1084
+ if not self[101] and (self[103] or 0) <= 0 or stunCounter >= 0 then
1019
1085
  BlzPauseUnitEx(self.handle, true)
1020
1086
  end
1021
1087
  self[102] = stunCounter + 1
1022
1088
  end
1023
1089
  function Unit.prototype.decrementStunCounter(self)
1024
1090
  local stunCounter = self[102] or 0
1025
- if not self[101] or stunCounter >= 1 then
1091
+ if not self[101] and (self[103] or 0) <= 0 or stunCounter >= 1 then
1026
1092
  BlzPauseUnitEx(self.handle, false)
1027
1093
  end
1028
1094
  self[102] = stunCounter - 1
1029
1095
  end
1096
+ function Unit.prototype.incrementForceStunCounter(self)
1097
+ local forceStunCounter = self[103] or 0
1098
+ if forceStunCounter == 0 then
1099
+ local handle = self.handle
1100
+ if not self[101] then
1101
+ for _ = self[102] or 0, -1 do
1102
+ BlzPauseUnitEx(handle, true)
1103
+ end
1104
+ end
1105
+ BlzPauseUnitEx(handle, true)
1106
+ end
1107
+ self[103] = forceStunCounter + 1
1108
+ end
1109
+ function Unit.prototype.decrementForceStunCounter(self)
1110
+ local forceStunCounter = self[103] or 0
1111
+ if forceStunCounter == 1 then
1112
+ local handle = self.handle
1113
+ if not self[101] then
1114
+ for _ = self[102] or 0, -1 do
1115
+ BlzPauseUnitEx(handle, false)
1116
+ end
1117
+ end
1118
+ BlzPauseUnitEx(handle, false)
1119
+ end
1120
+ self[103] = forceStunCounter - 1
1121
+ end
1030
1122
  function Unit.create(self, owner, id, x, y, facing, skinId)
1031
1123
  local handle = skinId and BlzCreateUnitWithSkin(
1032
1124
  owner.handle,
@@ -1215,7 +1307,7 @@ __TS__SetDescriptor(
1215
1307
  Unit.prototype,
1216
1308
  "isIllusion",
1217
1309
  {get = function(self)
1218
- return isUnitIllusion(self.handle)
1310
+ return IsUnitIllusion(self.handle)
1219
1311
  end},
1220
1312
  true
1221
1313
  )
@@ -1313,19 +1405,6 @@ __TS__SetDescriptor(
1313
1405
  },
1314
1406
  true
1315
1407
  )
1316
- __TS__SetDescriptor(
1317
- Unit.prototype,
1318
- "strengthBase",
1319
- {
1320
- get = function(self)
1321
- return getHeroStr(self.handle, false)
1322
- end,
1323
- set = function(self, strengthBase)
1324
- setHeroStr(self.handle, strengthBase, true)
1325
- end
1326
- },
1327
- true
1328
- )
1329
1408
  __TS__SetDescriptor(
1330
1409
  Unit.prototype,
1331
1410
  "strengthBonus",
@@ -1343,19 +1422,6 @@ __TS__SetDescriptor(
1343
1422
  end},
1344
1423
  true
1345
1424
  )
1346
- __TS__SetDescriptor(
1347
- Unit.prototype,
1348
- "agilityBase",
1349
- {
1350
- get = function(self)
1351
- return getHeroAgi(self.handle, false)
1352
- end,
1353
- set = function(self, agilityBase)
1354
- setHeroAgi(self.handle, agilityBase, true)
1355
- end
1356
- },
1357
- true
1358
- )
1359
1425
  __TS__SetDescriptor(
1360
1426
  Unit.prototype,
1361
1427
  "agilityBonus",
@@ -1373,19 +1439,6 @@ __TS__SetDescriptor(
1373
1439
  end},
1374
1440
  true
1375
1441
  )
1376
- __TS__SetDescriptor(
1377
- Unit.prototype,
1378
- "intelligenceBase",
1379
- {
1380
- get = function(self)
1381
- return getHeroInt(self.handle, false)
1382
- end,
1383
- set = function(self, intelligenceBase)
1384
- setHeroInt(self.handle, intelligenceBase, true)
1385
- end
1386
- },
1387
- true
1388
- )
1389
1442
  __TS__SetDescriptor(
1390
1443
  Unit.prototype,
1391
1444
  "intelligenceBonus",
@@ -1434,17 +1487,17 @@ __TS__SetDescriptor(
1434
1487
  "isTeamGlowVisible",
1435
1488
  {
1436
1489
  get = function(self)
1437
- return not self[106]
1490
+ return not self[107]
1438
1491
  end,
1439
1492
  set = function(self, isTeamGlowVisible)
1440
1493
  BlzShowUnitTeamGlow(self.handle, isTeamGlowVisible)
1441
- local ____temp_6
1494
+ local ____temp_7
1442
1495
  if not isTeamGlowVisible then
1443
- ____temp_6 = true
1496
+ ____temp_7 = true
1444
1497
  else
1445
- ____temp_6 = nil
1498
+ ____temp_7 = nil
1446
1499
  end
1447
- self[106] = ____temp_6
1500
+ self[107] = ____temp_7
1448
1501
  end
1449
1502
  },
1450
1503
  true
@@ -1454,7 +1507,7 @@ __TS__SetDescriptor(
1454
1507
  "color",
1455
1508
  {set = function(self, color)
1456
1509
  SetUnitColor(self.handle, color.handle)
1457
- if self[106] then
1510
+ if self[107] then
1458
1511
  BlzShowUnitTeamGlow(self.handle, false)
1459
1512
  end
1460
1513
  end},
@@ -1478,14 +1531,14 @@ __TS__SetDescriptor(
1478
1531
  "maxHealth",
1479
1532
  {
1480
1533
  get = function(self)
1481
- return BlzGetUnitMaxHP(self.handle) - (self[104] or 0) - (self[105] or 0)
1534
+ return BlzGetUnitMaxHP(self.handle) - (self[105] or 0) - (self[106] or 0)
1482
1535
  end,
1483
1536
  set = function(self, maxHealth)
1484
- if maxHealth < 1 and self[103] ~= nil then
1485
- self[104] = (self[104] or 0) + (1 - maxHealth)
1537
+ if maxHealth < 1 and self[104] ~= nil then
1538
+ self[105] = (self[105] or 0) + (1 - maxHealth)
1486
1539
  maxHealth = 1
1487
1540
  end
1488
- BlzSetUnitMaxHP(self.handle, maxHealth + (self[105] or 0))
1541
+ BlzSetUnitMaxHP(self.handle, maxHealth + (self[106] or 0))
1489
1542
  end
1490
1543
  },
1491
1544
  true
@@ -1527,10 +1580,10 @@ __TS__SetDescriptor(
1527
1580
  "health",
1528
1581
  {
1529
1582
  get = function(self)
1530
- return GetWidgetLife(self.handle) - (self[105] or 0)
1583
+ return GetWidgetLife(self.handle) - (self[106] or 0)
1531
1584
  end,
1532
1585
  set = function(self, health)
1533
- SetWidgetLife(self.handle, health + (self[105] or 0))
1586
+ SetWidgetLife(self.handle, health + (self[106] or 0))
1534
1587
  end
1535
1588
  },
1536
1589
  true
@@ -1606,25 +1659,12 @@ __TS__SetDescriptor(
1606
1659
  },
1607
1660
  true
1608
1661
  )
1609
- __TS__SetDescriptor(
1610
- Unit.prototype,
1611
- "flyHeight",
1612
- {
1613
- get = function(self)
1614
- return getUnitFlyHeight(self.handle)
1615
- end,
1616
- set = function(self, v)
1617
- SetUnitFlyHeight(self.handle, v, 100000)
1618
- end
1619
- },
1620
- true
1621
- )
1622
1662
  __TS__SetDescriptor(
1623
1663
  Unit.prototype,
1624
1664
  "x",
1625
1665
  {
1626
1666
  get = function(self)
1627
- return self[107] or getUnitX(self.handle)
1667
+ return self[108] or getUnitX(self.handle)
1628
1668
  end,
1629
1669
  set = function(self, v)
1630
1670
  SetUnitX(self.handle, v)
@@ -1637,7 +1677,7 @@ __TS__SetDescriptor(
1637
1677
  "y",
1638
1678
  {
1639
1679
  get = function(self)
1640
- return self[108] or getUnitY(self.handle)
1680
+ return self[109] or getUnitY(self.handle)
1641
1681
  end,
1642
1682
  set = function(self, v)
1643
1683
  SetUnitY(self.handle, v)
@@ -1742,14 +1782,18 @@ __TS__SetDescriptor(
1742
1782
  local handle = self.handle
1743
1783
  if isPaused and not IsUnitPaused(handle) then
1744
1784
  self[101] = true
1745
- for _ = self[102] or 0, -1 do
1746
- BlzPauseUnitEx(handle, true)
1785
+ if (self[103] or 0) <= 0 then
1786
+ for _ = self[102] or 0, -1 do
1787
+ BlzPauseUnitEx(handle, true)
1788
+ end
1747
1789
  end
1748
1790
  PauseUnit(handle, true)
1749
1791
  elseif not isPaused and IsUnitPaused(handle) then
1750
1792
  PauseUnit(handle, false)
1751
- for _ = self[102] or 0, -1 do
1752
- BlzPauseUnitEx(handle, false)
1793
+ if (self[103] or 0) <= 0 then
1794
+ for _ = self[102] or 0, -1 do
1795
+ BlzPauseUnitEx(handle, false)
1796
+ end
1753
1797
  end
1754
1798
  self[101] = nil
1755
1799
  end
@@ -1807,20 +1851,6 @@ __TS__SetDescriptor(
1807
1851
  },
1808
1852
  true
1809
1853
  )
1810
- __TS__SetDescriptor(
1811
- Unit.prototype,
1812
- "scale",
1813
- {
1814
- get = function(self)
1815
- return getUnitRealField(self.handle, UNIT_RF_SCALING_VALUE)
1816
- end,
1817
- set = function(self, v)
1818
- setUnitScale(self.handle, v, v, v)
1819
- setUnitRealField(self.handle, UNIT_RF_SCALING_VALUE, v)
1820
- end
1821
- },
1822
- true
1823
- )
1824
1854
  __TS__SetDescriptor(
1825
1855
  Unit.prototype,
1826
1856
  "timeScale",
@@ -2116,6 +2146,11 @@ __TS__SetDescriptor(
2116
2146
  end},
2117
2147
  true
2118
2148
  )
2149
+ Unit.levelChangedEvent = __TS__New(
2150
+ ____exports.UnitTriggerEvent,
2151
+ EVENT_PLAYER_HERO_LEVEL,
2152
+ function() return ____exports.Unit:of(getTriggerUnit()) end
2153
+ )
2119
2154
  Unit.deathEvent = __TS__New(
2120
2155
  ____exports.UnitTriggerEvent,
2121
2156
  EVENT_PLAYER_UNIT_DEATH,
@@ -2191,25 +2226,25 @@ Unit.onTargetCast = dispatchId(__TS__New(
2191
2226
  InitializingEvent,
2192
2227
  function(event)
2193
2228
  local function listener(unit, id)
2194
- local ____GetSpellTargetUnit_result_9
2229
+ local ____GetSpellTargetUnit_result_10
2195
2230
  if GetSpellTargetUnit() then
2196
- ____GetSpellTargetUnit_result_9 = ____exports.Unit:of(GetSpellTargetUnit())
2231
+ ____GetSpellTargetUnit_result_10 = ____exports.Unit:of(GetSpellTargetUnit())
2197
2232
  else
2198
- local ____GetSpellTargetItem_result_8
2233
+ local ____GetSpellTargetItem_result_9
2199
2234
  if GetSpellTargetItem() then
2200
- ____GetSpellTargetItem_result_8 = Item:of(GetSpellTargetItem())
2235
+ ____GetSpellTargetItem_result_9 = Item:of(GetSpellTargetItem())
2201
2236
  else
2202
- local ____GetSpellTargetDestructable_result_7
2237
+ local ____GetSpellTargetDestructable_result_8
2203
2238
  if GetSpellTargetDestructable() then
2204
- ____GetSpellTargetDestructable_result_7 = Destructable:of(GetSpellTargetDestructable())
2239
+ ____GetSpellTargetDestructable_result_8 = Destructable:of(GetSpellTargetDestructable())
2205
2240
  else
2206
- ____GetSpellTargetDestructable_result_7 = nil
2241
+ ____GetSpellTargetDestructable_result_8 = nil
2207
2242
  end
2208
- ____GetSpellTargetItem_result_8 = ____GetSpellTargetDestructable_result_7
2243
+ ____GetSpellTargetItem_result_9 = ____GetSpellTargetDestructable_result_8
2209
2244
  end
2210
- ____GetSpellTargetUnit_result_9 = ____GetSpellTargetItem_result_8
2245
+ ____GetSpellTargetUnit_result_10 = ____GetSpellTargetItem_result_9
2211
2246
  end
2212
- local target = ____GetSpellTargetUnit_result_9
2247
+ local target = ____GetSpellTargetUnit_result_10
2213
2248
  if target then
2214
2249
  invoke(event, unit, id, target)
2215
2250
  end
@@ -2428,15 +2463,11 @@ Unit.onDamaging = (function()
2428
2463
  metadata = metadata,
2429
2464
  isAttack = BlzGetEventIsAttack(),
2430
2465
  originalAmount = GetEventDamage(),
2431
- originalMetadata = metadata
2466
+ originalMetadata = metadata,
2467
+ preventRetaliation = damagingEventPreventRetaliation
2432
2468
  }
2433
2469
  if data.isAttack and source then
2434
- 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
2435
- if weapon == -1 then
2436
- local targetsAllowed = BlzGetUnitWeaponIntegerField(source.handle, UNIT_WEAPON_IF_ATTACK_TARGETS_ALLOWED, 0)
2437
- weapon = 0
2438
- end
2439
- data.weapon = assert(source.weapons[weapon + 1])
2470
+ data.weapon = source:chooseWeapon(target)
2440
2471
  end
2441
2472
  if not data.isAttack or not source or not source._attackHandlers then
2442
2473
  invoke(
@@ -2457,6 +2488,20 @@ Unit.onDamaging = (function()
2457
2488
  }
2458
2489
  )
2459
2490
  )
2491
+ if data[0] and source then
2492
+ local sourceOwner = source.owner.handle
2493
+ data[1] = sourceOwner
2494
+ local targetOwner = target.owner.handle
2495
+ data[2] = targetOwner
2496
+ if not GetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE) then
2497
+ SetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE, true)
2498
+ data[3] = true
2499
+ end
2500
+ if not GetPlayerAlliance(targetOwner, sourceOwner, ALLIANCE_PASSIVE) then
2501
+ SetPlayerAlliance(targetOwner, sourceOwner, ALLIANCE_PASSIVE, true)
2502
+ data[4] = true
2503
+ end
2504
+ end
2460
2505
  damagingEventByTarget[target] = data
2461
2506
  return
2462
2507
  end
@@ -2540,6 +2585,16 @@ Unit.onDamage = __TS__New(
2540
2585
  data[key] = value
2541
2586
  end
2542
2587
  end
2588
+ local sourceOwner = damagingEvent[1]
2589
+ if sourceOwner then
2590
+ local targetOwner = damagingEvent[2]
2591
+ if damagingEvent[3] then
2592
+ SetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE, false)
2593
+ end
2594
+ if damagingEvent[4] then
2595
+ SetPlayerAlliance(targetOwner, sourceOwner, ALLIANCE_PASSIVE, false)
2596
+ end
2597
+ end
2543
2598
  end
2544
2599
  local evData = setmetatable(
2545
2600
  {},
@@ -2557,7 +2612,7 @@ Unit.onDamage = __TS__New(
2557
2612
  invoke(event, source, target, evData)
2558
2613
  if evData[0] ~= nil and target.health - evData.amount < 0.405 then
2559
2614
  local bonusHealth = math.ceil(evData.amount)
2560
- target[105] = (target[105] or 0) + bonusHealth
2615
+ target[106] = (target[106] or 0) + bonusHealth
2561
2616
  BlzSetUnitMaxHP(
2562
2617
  target.handle,
2563
2618
  BlzGetUnitMaxHP(target.handle) + bonusHealth
@@ -2571,7 +2626,7 @@ Unit.onDamage = __TS__New(
2571
2626
  evData[0],
2572
2627
  table.unpack(evData, 1 + 1, 1 + (evData[1] or 0))
2573
2628
  )
2574
- target[105] = (target[105] or 0) - bonusHealth
2629
+ target[106] = (target[106] or 0) - bonusHealth
2575
2630
  SetWidgetLife(
2576
2631
  target.handle,
2577
2632
  GetWidgetLife(target.handle) - bonusHealth
@@ -2607,10 +2662,14 @@ Unit.itemPickedUpEvent = __TS__New(
2607
2662
  ____exports.UnitTriggerEvent,
2608
2663
  EVENT_PLAYER_UNIT_PICKUP_ITEM,
2609
2664
  function()
2610
- local unit = getTriggerUnit()
2611
- local item = getManipulatedItem()
2612
- if getUnitTypeId(unit) ~= dummyUnitId and not (ignoreEventsItems[item] ~= nil) then
2613
- return ____exports.Unit:of(unit), Item:of(item)
2665
+ local unitHandle = getTriggerUnit()
2666
+ local itemHandle = getManipulatedItem()
2667
+ if getUnitTypeId(unitHandle) ~= dummyUnitId and not (ignoreEventsItems[itemHandle] ~= nil) then
2668
+ local unit = ____exports.Unit:of(unitHandle)
2669
+ local item = Item:of(itemHandle)
2670
+ if item.owner ~= unit then
2671
+ return unit, item
2672
+ end
2614
2673
  end
2615
2674
  return IgnoreEvent
2616
2675
  end
@@ -2630,7 +2689,22 @@ Unit.itemUsedEvent = __TS__New(
2630
2689
  Unit.itemStackedEvent = __TS__New(
2631
2690
  ____exports.UnitTriggerEvent,
2632
2691
  EVENT_PLAYER_UNIT_STACK_ITEM,
2633
- function() return ____exports.Unit:of(getTriggerUnit()), Item:of(getManipulatedItem()) end
2692
+ function() return ____exports.Unit:of(getTriggerUnit()), Item:of(BlzGetStackingItemTarget()), Item:of(BlzGetStackingItemSource()) end
2693
+ )
2694
+ __TS__ObjectDefineProperty(
2695
+ Unit,
2696
+ "itemChargesChangedEvent",
2697
+ {get = function(self)
2698
+ local event = __TS__New(Event)
2699
+ Item.chargesChangedEvent:addListener(function(item)
2700
+ local unit = item.owner
2701
+ if unit ~= nil then
2702
+ invoke(event, unit, item)
2703
+ end
2704
+ end)
2705
+ rawset(self, "itemChargesChangedEvent", event)
2706
+ return event
2707
+ end}
2634
2708
  )
2635
2709
  __TS__ObjectDefineProperty(
2636
2710
  Unit,
@@ -2702,6 +2776,10 @@ __TS__ObjectDefineProperty(
2702
2776
  rawset(self, "destroyEvent", destroyEvent)
2703
2777
  return destroyEvent
2704
2778
  end}
2779
+ )
2780
+ Unit.synchronize = synchronizer(
2781
+ function(unit) return unit.syncId end,
2782
+ function(syncId) return unitBySyncId[syncId] end
2705
2783
  );
2706
2784
  (function(self)
2707
2785
  local leaveAbilityIds = postcompile(function()
@@ -2731,7 +2809,7 @@ __TS__ObjectDefineProperty(
2731
2809
  return
2732
2810
  end
2733
2811
  end
2734
- unit:destroy()
2812
+ Timer:run(unit, "destroy")
2735
2813
  end)
2736
2814
  end
2737
2815
  end)(Unit)