warscript 0.0.1-dev.c16baee → 0.0.1-dev.c362181

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 (147) hide show
  1. package/binaryreader.d.ts +1 -0
  2. package/binaryreader.lua +3 -0
  3. package/config.d.ts +5 -0
  4. package/config.lua +10 -0
  5. package/core/types/effect.d.ts +13 -3
  6. package/core/types/effect.lua +116 -17
  7. package/core/types/frame.d.ts +8 -0
  8. package/core/types/frame.lua +93 -1
  9. package/core/types/handle.lua +2 -0
  10. package/core/types/sound.d.ts +17 -24
  11. package/core/types/sound.lua +94 -24
  12. package/core/util.d.ts +1 -1
  13. package/core/util.lua +18 -1
  14. package/engine/behavior.d.ts +2 -2
  15. package/engine/behavior.lua +6 -6
  16. package/engine/behaviour/ability/always-enabled.d.ts +7 -0
  17. package/engine/behaviour/ability/always-enabled.lua +31 -0
  18. package/engine/behaviour/ability/apply-buff.d.ts +8 -5
  19. package/engine/behaviour/ability/apply-buff.lua +32 -0
  20. package/engine/behaviour/ability/apply-unit-behavior.lua +1 -0
  21. package/engine/behaviour/ability/damage.d.ts +36 -11
  22. package/engine/behaviour/ability/damage.lua +90 -32
  23. package/engine/behaviour/ability/emulate-impact.d.ts +6 -0
  24. package/engine/behaviour/ability/emulate-impact.lua +28 -0
  25. package/engine/behaviour/ability/heal.d.ts +33 -6
  26. package/engine/behaviour/ability/heal.lua +89 -10
  27. package/engine/behaviour/ability/instant-impact.d.ts +2 -2
  28. package/engine/behaviour/ability/instant-impact.lua +4 -19
  29. package/engine/behaviour/ability/on-command-impact.d.ts +8 -0
  30. package/engine/behaviour/ability/on-command-impact.lua +25 -0
  31. package/engine/behaviour/ability/remove-buffs.d.ts +16 -0
  32. package/engine/behaviour/ability/remove-buffs.lua +28 -0
  33. package/engine/behaviour/ability/restore-mana.d.ts +15 -0
  34. package/engine/behaviour/ability/restore-mana.lua +29 -0
  35. package/engine/behaviour/ability.d.ts +16 -3
  36. package/engine/behaviour/ability.lua +105 -34
  37. package/engine/behaviour/unit.d.ts +7 -0
  38. package/engine/behaviour/unit.lua +20 -0
  39. package/engine/buff.d.ts +101 -39
  40. package/engine/buff.lua +458 -203
  41. package/engine/game-map.d.ts +7 -0
  42. package/engine/game-map.lua +32 -0
  43. package/engine/internal/ability.d.ts +16 -13
  44. package/engine/internal/ability.lua +80 -76
  45. package/engine/internal/item/ability.lua +106 -0
  46. package/engine/internal/item+owner.lua +2 -2
  47. package/engine/internal/item.d.ts +2 -2
  48. package/engine/internal/item.lua +56 -25
  49. package/engine/internal/misc/ability-disable-counter.d.ts +2 -0
  50. package/engine/internal/misc/ability-disable-counter.lua +13 -0
  51. package/engine/internal/object-data/auto-attack-speed-increase.d.ts +1 -1
  52. package/engine/internal/object-data/auto-attack-speed-increase.lua +2 -0
  53. package/engine/internal/object-data/evasion-probability.d.ts +2 -0
  54. package/engine/internal/object-data/evasion-probability.lua +16 -0
  55. package/engine/internal/unit/ability.d.ts +10 -1
  56. package/engine/internal/unit/ability.lua +36 -14
  57. package/engine/internal/unit/add-item-to-slot-init.d.ts +2 -0
  58. package/engine/internal/unit/add-item-to-slot-init.lua +23 -0
  59. package/engine/internal/unit/add-item-to-slot.d.ts +2 -0
  60. package/engine/internal/unit/add-item-to-slot.lua +52 -0
  61. package/engine/internal/unit/bonus.d.ts +6 -2
  62. package/engine/internal/unit/bonus.lua +23 -1
  63. package/engine/internal/unit/ignore-events-items.d.ts +2 -0
  64. package/engine/internal/unit/ignore-events-items.lua +5 -0
  65. package/engine/internal/unit/item.d.ts +24 -0
  66. package/engine/internal/unit/item.lua +78 -0
  67. package/engine/internal/unit/main-selected.d.ts +13 -0
  68. package/engine/internal/unit/main-selected.lua +51 -0
  69. package/engine/internal/unit+ability.lua +2 -2
  70. package/engine/internal/unit+transport.lua +4 -10
  71. package/engine/internal/unit-missile-launch.lua +24 -5
  72. package/engine/internal/unit.d.ts +31 -10
  73. package/engine/internal/unit.lua +181 -91
  74. package/engine/internal/utility.lua +12 -0
  75. package/engine/lightning.d.ts +12 -5
  76. package/engine/lightning.lua +48 -14
  77. package/engine/local-client.d.ts +7 -2
  78. package/engine/local-client.lua +82 -0
  79. package/engine/object-data/auxiliary/animation-name.d.ts +1 -0
  80. package/engine/object-data/auxiliary/animation-name.lua +16 -0
  81. package/engine/object-data/auxiliary/sound-eax.d.ts +10 -0
  82. package/engine/object-data/auxiliary/sound-eax.lua +2 -0
  83. package/engine/object-data/auxiliary/sound-preset-name.d.ts +5 -1
  84. package/engine/object-data/auxiliary/tech-tree-dependency.d.ts +1 -1
  85. package/engine/object-data/entry/ability-type/blank-configurable.lua +12 -1
  86. package/engine/object-data/entry/ability-type/disease-cloud.lua +2 -2
  87. package/engine/object-data/entry/ability-type/engineering-upgrade.lua +2 -2
  88. package/engine/object-data/entry/ability-type/ensnare.d.ts +12 -0
  89. package/engine/object-data/entry/ability-type/ensnare.lua +52 -0
  90. package/engine/object-data/entry/ability-type/feral-spirit.lua +2 -2
  91. package/engine/object-data/entry/ability-type/phoenix-morph.lua +4 -4
  92. package/engine/object-data/entry/ability-type/raise-dead.d.ts +17 -0
  93. package/engine/object-data/entry/ability-type/raise-dead.lua +78 -0
  94. package/engine/object-data/entry/ability-type/summon-quilbeast.lua +2 -2
  95. package/engine/object-data/entry/ability-type/summon-water-elemental.lua +2 -2
  96. package/engine/object-data/entry/ability-type.d.ts +8 -6
  97. package/engine/object-data/entry/ability-type.lua +62 -27
  98. package/engine/object-data/entry/buff-type/applicable.lua +13 -37
  99. package/engine/object-data/entry/buff-type.d.ts +1 -1
  100. package/engine/object-data/entry/buff-type.lua +2 -2
  101. package/engine/object-data/entry/destructible-type.d.ts +1 -1
  102. package/engine/object-data/entry/item-type.d.ts +15 -1
  103. package/engine/object-data/entry/item-type.lua +93 -2
  104. package/engine/object-data/entry/lightning-type.d.ts +1 -1
  105. package/engine/object-data/entry/sound-preset.d.ts +33 -0
  106. package/engine/object-data/entry/sound-preset.lua +140 -0
  107. package/engine/object-data/entry/unit-type.d.ts +8 -1
  108. package/engine/object-data/entry/unit-type.lua +61 -8
  109. package/engine/object-data/entry/upgrade.d.ts +1 -1
  110. package/engine/object-data/entry/upgrade.lua +4 -4
  111. package/engine/object-data/entry.d.ts +16 -14
  112. package/engine/object-data/entry.lua +60 -32
  113. package/engine/object-data/utility/object-data-entry-id-generator.lua +7 -0
  114. package/engine/object-field/ability.d.ts +26 -3
  115. package/engine/object-field/ability.lua +54 -1
  116. package/engine/object-field.d.ts +2 -2
  117. package/engine/object-field.lua +4 -0
  118. package/engine/standard/entries/sound-preset.d.ts +10 -0
  119. package/engine/standard/entries/sound-preset.lua +10 -0
  120. package/engine/standard/fields/ability.d.ts +2 -0
  121. package/engine/standard/fields/ability.lua +2 -0
  122. package/engine/unit.d.ts +3 -0
  123. package/engine/unit.lua +3 -0
  124. package/index.d.ts +1 -0
  125. package/index.lua +1 -0
  126. package/lualib_bundle.lua +7 -2
  127. package/net/socket.d.ts +7 -1
  128. package/net/socket.lua +45 -4
  129. package/network.d.ts +1 -0
  130. package/network.lua +3 -2
  131. package/objutil/buff.lua +1 -1
  132. package/objutil/unit.lua +8 -0
  133. package/package.json +2 -2
  134. package/patch-lua.d.ts +0 -0
  135. package/patch-lua.lua +10 -0
  136. package/property.d.ts +55 -0
  137. package/property.lua +374 -0
  138. package/utility/arrays.d.ts +8 -1
  139. package/utility/arrays.lua +34 -3
  140. package/utility/lazy.d.ts +2 -0
  141. package/utility/lazy.lua +14 -0
  142. package/utility/linked-set.d.ts +11 -2
  143. package/utility/linked-set.lua +5 -2
  144. package/utility/reflection.lua +11 -7
  145. package/utility/types.d.ts +1 -0
  146. package/core/mapbounds.d.ts +0 -8
  147. package/core/mapbounds.lua +0 -12
@@ -51,11 +51,14 @@ local ____arrays = require("utility.arrays")
51
51
  local forEach = ____arrays.forEach
52
52
  local ____math = require("math")
53
53
  local min = ____math.min
54
+ local ____ignore_2Devents_2Ditems = require("engine.internal.unit.ignore-events-items")
55
+ local ignoreEventsItems = ____ignore_2Devents_2Ditems.ignoreEventsItems
54
56
  local match = string.match
55
57
  local ____tostring = _G.tostring
56
58
  local setUnitAnimation = SetUnitAnimation
57
59
  local setUnitAnimationWithRarity = SetUnitAnimationWithRarity
58
60
  local setUnitAnimationByIndex = SetUnitAnimationByIndex
61
+ local resetUnitAnimation = ResetUnitAnimation
59
62
  local queueUnitAnimation = QueueUnitAnimation
60
63
  local getUnitIntegerField = BlzGetUnitIntegerField
61
64
  local getUnitRealField = BlzGetUnitRealField
@@ -75,6 +78,7 @@ local setUnitScale = SetUnitScale
75
78
  local setUnitPosition = SetUnitPosition
76
79
  local setUnitTimeScale = SetUnitTimeScale
77
80
  local getHandleId = GetHandleId
81
+ local getUnitCurrentOrder = GetUnitCurrentOrder
78
82
  local createUnit = CreateUnit
79
83
  local killUnit = KillUnit
80
84
  local setUnitExploded = SetUnitExploded
@@ -290,7 +294,6 @@ local function dispatch(event, idGetter, argsGetter)
290
294
  return event[id]
291
295
  end
292
296
  if not initialized then
293
- local invoke = Event.invoke
294
297
  event:addListener(function(...)
295
298
  local id = idGetter(...)
296
299
  local dispatched = rawget(self, id)
@@ -328,7 +331,6 @@ local function dispatchAbility(event)
328
331
  return event[id]
329
332
  end
330
333
  if not initialized then
331
- local invoke = Event.invoke
332
334
  event:addListener(function(unit, ability, ...)
333
335
  local dispatched = rawget(self, ability.typeId)
334
336
  if dispatched ~= nil then
@@ -564,17 +566,6 @@ local function retrieveAbility(unit, ability, abilityId)
564
566
  ____exports.Unit:of(unit)
565
567
  )
566
568
  end
567
- if not unitAddAbility(unit, abilityId) then
568
- if getUnitAbility(unit, abilityId) == ability then
569
- return UnitAbility:of(
570
- ability,
571
- abilityId,
572
- ____exports.Unit:of(unit)
573
- )
574
- end
575
- else
576
- unitRemoveAbility(unit, abilityId)
577
- end
578
569
  for i = 0, unitInventorySize(unit) - 1 do
579
570
  local item = unitItemInSlot(unit, i)
580
571
  if getItemAbility(item, abilityId) == ability then
@@ -632,15 +623,15 @@ for ____, player in ipairs(Player.all) do
632
623
  dummies[player] = dummy
633
624
  end
634
625
  local function delayHealthChecksCallback(unit)
635
- local counter = (unit[102] or 0) - 1
626
+ local counter = (unit[103] or 0) - 1
636
627
  if counter ~= 0 then
637
- unit[102] = counter
628
+ unit[103] = counter
638
629
  return
639
630
  end
640
- unit[102] = nil
641
- local healthBonus = unit[103]
631
+ unit[103] = nil
632
+ local healthBonus = unit[104]
642
633
  if healthBonus ~= nil then
643
- unit[103] = nil
634
+ unit[104] = nil
644
635
  local handle = unit.handle
645
636
  BlzSetUnitMaxHP(
646
637
  handle,
@@ -648,12 +639,17 @@ local function delayHealthChecksCallback(unit)
648
639
  )
649
640
  end
650
641
  end
642
+ local nextSyncId = 1
643
+ local unitBySyncId = setmetatable({}, {__mode = "k"})
651
644
  ____exports.Unit = __TS__Class()
652
645
  local Unit = ____exports.Unit
653
646
  Unit.name = "Unit"
654
647
  __TS__ClassExtends(Unit, Handle)
655
648
  function Unit.prototype.____constructor(self, handle)
656
649
  Handle.prototype.____constructor(self, handle)
650
+ local ____nextSyncId_0 = nextSyncId
651
+ nextSyncId = ____nextSyncId_0 + 1
652
+ self.syncId = ____nextSyncId_0
657
653
  self._owner = Player:of(getOwningPlayer(handle))
658
654
  assert(unitAddAbility(handle, leaveDetectAbilityId) and UnitMakeAbilityPermanent(handle, true, leaveDetectAbilityId))
659
655
  assert(unitAddAbility(handle, morphDetectAbilityId))
@@ -666,6 +662,7 @@ function Unit.prototype.____constructor(self, handle)
666
662
  fourCC("Amrf")
667
663
  ))
668
664
  end
665
+ unitBySyncId[self.syncId] = self
669
666
  local ____ = self.abilities
670
667
  end
671
668
  function Unit.prototype.getEvent(self, event, collector)
@@ -684,6 +681,8 @@ function Unit.prototype.getEvent(self, event, collector)
684
681
  end
685
682
  function Unit.prototype.onDestroy(self)
686
683
  local handle = self.handle
684
+ self[107] = getUnitX(handle)
685
+ self[108] = getUnitY(handle)
687
686
  if not self._owner then
688
687
  self._owner = Player:of(getOwningPlayer(handle))
689
688
  end
@@ -706,6 +705,10 @@ function Unit.prototype.onDestroy(self)
706
705
  if eventsToDestroy ~= nil then
707
706
  forEach(eventsToDestroy, "destroy")
708
707
  end
708
+ if getUnitAbilityLevel(handle, leaveDetectAbilityId) > 0 then
709
+ unitRemoveAbility(handle, leaveDetectAbilityId)
710
+ removeUnit(handle)
711
+ end
709
712
  return Handle.prototype.onDestroy(self)
710
713
  end
711
714
  function Unit.prototype.addAttackHandler(self, condition, action)
@@ -747,8 +750,8 @@ function Unit.prototype.addModifier(self, property, modifier)
747
750
  end}
748
751
  end
749
752
  function Unit.prototype.hasCombatClassification(self, combatClassification)
750
- local ____combatClassification_0 = combatClassification
751
- return getUnitIntegerField(self.handle, UNIT_IF_TARGETED_AS) & ____combatClassification_0 == ____combatClassification_0
753
+ local ____combatClassification_1 = combatClassification
754
+ return getUnitIntegerField(self.handle, UNIT_IF_TARGETED_AS) & ____combatClassification_1 == ____combatClassification_1
752
755
  end
753
756
  function Unit.prototype.addClassification(self, classification)
754
757
  return unitAddType(self.handle, classification)
@@ -766,13 +769,13 @@ function Unit.prototype.isInvisibleTo(self, player)
766
769
  return isUnitInvisible(self.handle, player.handle)
767
770
  end
768
771
  function Unit.prototype.isInRangeOf(self, x, y, range)
769
- local ____temp_1
772
+ local ____temp_2
770
773
  if type(x) == "number" then
771
- ____temp_1 = isUnitInRangeXY(self.handle, x, y, range)
774
+ ____temp_2 = isUnitInRangeXY(self.handle, x, y, range)
772
775
  else
773
- ____temp_1 = isUnitInRange(self.handle, x.handle, y)
776
+ ____temp_2 = isUnitInRange(self.handle, x.handle, y)
774
777
  end
775
- return ____temp_1
778
+ return ____temp_2
776
779
  end
777
780
  function Unit.prototype.isAllyOf(self, unit)
778
781
  return isUnitAlly(
@@ -795,11 +798,14 @@ function Unit.prototype.playAnimation(self, animation, rarity)
795
798
  setUnitAnimation(self.handle, animation)
796
799
  end
797
800
  end
801
+ function Unit.prototype.resetAnimation(self)
802
+ resetUnitAnimation(self.handle)
803
+ end
798
804
  function Unit.prototype.queueAnimation(self, animation)
799
805
  queueUnitAnimation(self.handle, animation)
800
806
  end
801
807
  function Unit.prototype.delayHealthChecks(self)
802
- self[102] = (self[102] or 0) + 1
808
+ self[103] = (self[103] or 0) + 1
803
809
  Timer:run(delayHealthChecksCallback, self)
804
810
  end
805
811
  function Unit.prototype.setPosition(self, x, y)
@@ -816,14 +822,14 @@ function Unit.prototype.kill(self)
816
822
  killUnit(self.handle)
817
823
  end
818
824
  function Unit.prototype.revive(self, x, y, doEffect)
819
- local ____ReviveHero_4 = ReviveHero
820
- local ____array_3 = __TS__SparseArrayNew(self.handle, x, y)
821
- local ____doEffect_2 = doEffect
822
- if ____doEffect_2 == nil then
823
- ____doEffect_2 = false
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
824
830
  end
825
- __TS__SparseArrayPush(____array_3, ____doEffect_2)
826
- ____ReviveHero_4(__TS__SparseArraySpread(____array_3))
831
+ __TS__SparseArrayPush(____array_4, ____doEffect_3)
832
+ ____ReviveHero_5(__TS__SparseArraySpread(____array_4))
827
833
  end
828
834
  function Unit.prototype.healTarget(self, target, amount)
829
835
  if __TS__InstanceOf(target, ____exports.Unit) and target:hasAbility(fourCC("BIhm")) then
@@ -863,7 +869,7 @@ function Unit.prototype.dropItemSlot(self, item, slot)
863
869
  return UnitDropItemSlot(self.handle, item.handle, slot)
864
870
  end
865
871
  function Unit.prototype.itemInSlot(self, slot)
866
- return Item:of(UnitItemInSlot(self.handle, slot))
872
+ return Item:of(unitItemInSlot(self.handle, slot))
867
873
  end
868
874
  function Unit.prototype.addAbility(self, abilityId)
869
875
  if unitAddAbility(self.handle, abilityId) then
@@ -932,8 +938,15 @@ function Unit.prototype.interruptAttack(self)
932
938
  unitInterruptAttack(self.handle)
933
939
  end
934
940
  function Unit.prototype.interruptCast(self, abilityId)
935
- unitDisableAbility(self.handle, abilityId, true, false)
936
- unitDisableAbility(self.handle, abilityId, false, false)
941
+ local handle = self.handle
942
+ unitDisableAbility(handle, abilityId, true, false)
943
+ Timer:run(
944
+ unitDisableAbility,
945
+ handle,
946
+ abilityId,
947
+ false,
948
+ false
949
+ )
937
950
  end
938
951
  function Unit.prototype.getDistanceTo(self, target)
939
952
  local handle = self.handle
@@ -993,18 +1006,18 @@ function Unit.prototype.unpauseEx(self)
993
1006
  self:decrementStunCounter()
994
1007
  end
995
1008
  function Unit.prototype.incrementStunCounter(self)
996
- local stunCounter = self[101] or 0
997
- if not self[100] or stunCounter >= 0 then
1009
+ local stunCounter = self[102] or 0
1010
+ if not self[101] or stunCounter >= 0 then
998
1011
  BlzPauseUnitEx(self.handle, true)
999
1012
  end
1000
- self[101] = stunCounter + 1
1013
+ self[102] = stunCounter + 1
1001
1014
  end
1002
1015
  function Unit.prototype.decrementStunCounter(self)
1003
- local stunCounter = self[101] or 0
1004
- if not self[100] or stunCounter >= 1 then
1016
+ local stunCounter = self[102] or 0
1017
+ if not self[101] or stunCounter >= 1 then
1005
1018
  BlzPauseUnitEx(self.handle, false)
1006
1019
  end
1007
- self[101] = stunCounter - 1
1020
+ self[102] = stunCounter - 1
1008
1021
  end
1009
1022
  function Unit.create(self, owner, id, x, y, facing, skinId)
1010
1023
  local handle = skinId and BlzCreateUnitWithSkin(
@@ -1106,8 +1119,11 @@ function Unit.getInSector(self, pos, range, offsetAngle, centralAngle)
1106
1119
  )
1107
1120
  return targetCollection
1108
1121
  end
1109
- function Unit.getSelectionOf(self, player)
1110
- targetCollection = {}
1122
+ function Unit.getSelectionOf(self, player, target)
1123
+ if target == nil then
1124
+ target = {}
1125
+ end
1126
+ targetCollection = target
1111
1127
  targetCollectionNextIndex = 1
1112
1128
  GroupEnumUnitsSelected(dummyGroup, player.handle, collectIntoTarget)
1113
1129
  return targetCollection
@@ -1129,6 +1145,9 @@ end
1129
1145
  function Unit.prototype.__tostring(self)
1130
1146
  return (((self.constructor.name .. "$") .. util.id2s(self.typeId)) .. "@") .. tostring(getHandleId(self.handle))
1131
1147
  end
1148
+ function Unit.getBySyncId(self, syncId)
1149
+ return unitBySyncId[syncId]
1150
+ end
1132
1151
  __TS__SetDescriptor(
1133
1152
  Unit.prototype,
1134
1153
  "_deltas",
@@ -1192,6 +1211,14 @@ __TS__SetDescriptor(
1192
1211
  end},
1193
1212
  true
1194
1213
  )
1214
+ __TS__SetDescriptor(
1215
+ Unit.prototype,
1216
+ "isStunned",
1217
+ {get = function(self)
1218
+ return getUnitCurrentOrder(self.handle) == orderId("stunned")
1219
+ end},
1220
+ true
1221
+ )
1195
1222
  __TS__SetDescriptor(
1196
1223
  Unit.prototype,
1197
1224
  "combatClassifications",
@@ -1386,17 +1413,17 @@ __TS__SetDescriptor(
1386
1413
  "isTeamGlowVisible",
1387
1414
  {
1388
1415
  get = function(self)
1389
- return not self[105]
1416
+ return not self[106]
1390
1417
  end,
1391
1418
  set = function(self, isTeamGlowVisible)
1392
1419
  showUnitTeamGlow(self.handle, isTeamGlowVisible)
1393
- local ____temp_5
1420
+ local ____temp_6
1394
1421
  if not isTeamGlowVisible then
1395
- ____temp_5 = true
1422
+ ____temp_6 = true
1396
1423
  else
1397
- ____temp_5 = nil
1424
+ ____temp_6 = nil
1398
1425
  end
1399
- self[105] = ____temp_5
1426
+ self[106] = ____temp_6
1400
1427
  end
1401
1428
  },
1402
1429
  true
@@ -1406,7 +1433,7 @@ __TS__SetDescriptor(
1406
1433
  "color",
1407
1434
  {set = function(self, color)
1408
1435
  setUnitColor(self.handle, color.handle)
1409
- if self[105] then
1436
+ if self[106] then
1410
1437
  showUnitTeamGlow(self.handle, false)
1411
1438
  end
1412
1439
  end},
@@ -1430,14 +1457,14 @@ __TS__SetDescriptor(
1430
1457
  "maxHealth",
1431
1458
  {
1432
1459
  get = function(self)
1433
- return BlzGetUnitMaxHP(self.handle) - (self[103] or 0) - (self[104] or 0)
1460
+ return BlzGetUnitMaxHP(self.handle) - (self[104] or 0) - (self[105] or 0)
1434
1461
  end,
1435
1462
  set = function(self, maxHealth)
1436
- if maxHealth < 1 and self[102] ~= nil then
1437
- self[103] = (self[103] or 0) + (1 - maxHealth)
1463
+ if maxHealth < 1 and self[103] ~= nil then
1464
+ self[104] = (self[104] or 0) + (1 - maxHealth)
1438
1465
  maxHealth = 1
1439
1466
  end
1440
- BlzSetUnitMaxHP(self.handle, maxHealth + (self[104] or 0))
1467
+ BlzSetUnitMaxHP(self.handle, maxHealth + (self[105] or 0))
1441
1468
  end
1442
1469
  },
1443
1470
  true
@@ -1479,10 +1506,10 @@ __TS__SetDescriptor(
1479
1506
  "health",
1480
1507
  {
1481
1508
  get = function(self)
1482
- return GetWidgetLife(self.handle) - (self[104] or 0)
1509
+ return GetWidgetLife(self.handle) - (self[105] or 0)
1483
1510
  end,
1484
1511
  set = function(self, health)
1485
- SetWidgetLife(self.handle, health + (self[104] or 0))
1512
+ SetWidgetLife(self.handle, health + (self[105] or 0))
1486
1513
  end
1487
1514
  },
1488
1515
  true
@@ -1576,7 +1603,7 @@ __TS__SetDescriptor(
1576
1603
  "x",
1577
1604
  {
1578
1605
  get = function(self)
1579
- return getUnitX(self.handle)
1606
+ return self[107] or getUnitX(self.handle)
1580
1607
  end,
1581
1608
  set = function(self, v)
1582
1609
  SetUnitX(self.handle, v)
@@ -1589,7 +1616,7 @@ __TS__SetDescriptor(
1589
1616
  "y",
1590
1617
  {
1591
1618
  get = function(self)
1592
- return getUnitY(self.handle)
1619
+ return self[108] or getUnitY(self.handle)
1593
1620
  end,
1594
1621
  set = function(self, v)
1595
1622
  SetUnitY(self.handle, v)
@@ -1693,17 +1720,17 @@ __TS__SetDescriptor(
1693
1720
  set = function(self, isPaused)
1694
1721
  local handle = self.handle
1695
1722
  if isPaused and not IsUnitPaused(handle) then
1696
- self[100] = true
1697
- for _ = self[101] or 0, -1 do
1723
+ self[101] = true
1724
+ for _ = self[102] or 0, -1 do
1698
1725
  BlzPauseUnitEx(handle, true)
1699
1726
  end
1700
1727
  PauseUnit(handle, true)
1701
1728
  elseif not isPaused and IsUnitPaused(handle) then
1702
1729
  PauseUnit(handle, false)
1703
- for _ = self[101] or 0, -1 do
1730
+ for _ = self[102] or 0, -1 do
1704
1731
  BlzPauseUnitEx(handle, false)
1705
1732
  end
1706
- self[100] = nil
1733
+ self[101] = nil
1707
1734
  end
1708
1735
  end
1709
1736
  },
@@ -2060,7 +2087,6 @@ Unit.onDecay = __TS__New(
2060
2087
  Unit.onResurrect = __TS__New(
2061
2088
  InitializingEvent,
2062
2089
  function(event)
2063
- local invoke = Event.invoke
2064
2090
  local dead = setmetatable({}, {__mode = "k"})
2065
2091
  ____exports.Unit.deathEvent:addListener(function(unit)
2066
2092
  dead[unit] = true
@@ -2076,10 +2102,15 @@ Unit.onResurrect = __TS__New(
2076
2102
  Unit.morphEvent = __TS__New(
2077
2103
  InitializingEvent,
2078
2104
  function(event)
2105
+ local function ifNotLeft(unit)
2106
+ local handle = unit.handle
2107
+ if getUnitAbilityLevel(handle, leaveDetectAbilityId) ~= 0 and unitAddAbility(handle, morphDetectAbilityId) then
2108
+ invoke(event, unit)
2109
+ end
2110
+ end
2079
2111
  ____exports.Unit.onImmediateOrder[orderId("undefend")]:addListener(function(unit)
2080
2112
  if getUnitAbilityLevel(unit.handle, morphDetectAbilityId) == 0 then
2081
- assert(unitAddAbility(unit.handle, morphDetectAbilityId))
2082
- Timer:run(Event.invoke, event, unit)
2113
+ Timer:run(ifNotLeft, unit)
2083
2114
  end
2084
2115
  end)
2085
2116
  end
@@ -2117,27 +2148,26 @@ Unit.onSpellEffect = dispatchId(__TS__New(
2117
2148
  Unit.onTargetCast = dispatchId(__TS__New(
2118
2149
  InitializingEvent,
2119
2150
  function(event)
2120
- local invoke = Event.invoke
2121
2151
  local function listener(unit, id)
2122
- local ____GetSpellTargetUnit_result_8
2152
+ local ____GetSpellTargetUnit_result_9
2123
2153
  if GetSpellTargetUnit() then
2124
- ____GetSpellTargetUnit_result_8 = ____exports.Unit:of(GetSpellTargetUnit())
2154
+ ____GetSpellTargetUnit_result_9 = ____exports.Unit:of(GetSpellTargetUnit())
2125
2155
  else
2126
- local ____GetSpellTargetItem_result_7
2156
+ local ____GetSpellTargetItem_result_8
2127
2157
  if GetSpellTargetItem() then
2128
- ____GetSpellTargetItem_result_7 = Item:of(GetSpellTargetItem())
2158
+ ____GetSpellTargetItem_result_8 = Item:of(GetSpellTargetItem())
2129
2159
  else
2130
- local ____GetSpellTargetDestructable_result_6
2160
+ local ____GetSpellTargetDestructable_result_7
2131
2161
  if GetSpellTargetDestructable() then
2132
- ____GetSpellTargetDestructable_result_6 = Destructable:of(GetSpellTargetDestructable())
2162
+ ____GetSpellTargetDestructable_result_7 = Destructable:of(GetSpellTargetDestructable())
2133
2163
  else
2134
- ____GetSpellTargetDestructable_result_6 = nil
2164
+ ____GetSpellTargetDestructable_result_7 = nil
2135
2165
  end
2136
- ____GetSpellTargetItem_result_7 = ____GetSpellTargetDestructable_result_6
2166
+ ____GetSpellTargetItem_result_8 = ____GetSpellTargetDestructable_result_7
2137
2167
  end
2138
- ____GetSpellTargetUnit_result_8 = ____GetSpellTargetItem_result_7
2168
+ ____GetSpellTargetUnit_result_9 = ____GetSpellTargetItem_result_8
2139
2169
  end
2140
- local target = ____GetSpellTargetUnit_result_8
2170
+ local target = ____GetSpellTargetUnit_result_9
2141
2171
  if target then
2142
2172
  invoke(event, unit, id, target)
2143
2173
  end
@@ -2309,10 +2339,12 @@ Unit.onImmediateOrder = dispatchId(__TS__New(
2309
2339
  ____exports.UnitTriggerEvent,
2310
2340
  EVENT_PLAYER_UNIT_ISSUED_ORDER,
2311
2341
  function()
2312
- local unit = ____exports.Unit:of(getOrderedUnit())
2313
- local issuedOrderId = getIssuedOrderId()
2314
- if unit ~= nil and unit.state == 1 then
2315
- return unit, issuedOrderId
2342
+ local handle = getOrderedUnit()
2343
+ if handle ~= nil and getUnitTypeId(handle) ~= dummyUnitId then
2344
+ local unit = ____exports.Unit:of(handle)
2345
+ if unit.state == 1 then
2346
+ return unit, getIssuedOrderId()
2347
+ end
2316
2348
  end
2317
2349
  return IgnoreEvent
2318
2350
  end
@@ -2334,7 +2366,6 @@ Unit.autoAttackStartEvent = __TS__New(
2334
2366
  )
2335
2367
  Unit.onDamaging = (function()
2336
2368
  local event = __TS__New(Event)
2337
- local invoke = Event.invoke
2338
2369
  local trigger = CreateTrigger()
2339
2370
  TriggerRegisterAnyUnitEventBJ(trigger, EVENT_PLAYER_UNIT_DAMAGING)
2340
2371
  TriggerAddCondition(
@@ -2433,7 +2464,6 @@ end)()
2433
2464
  Unit.onDamage = __TS__New(
2434
2465
  InitializingEvent,
2435
2466
  function(event)
2436
- local invoke = Event.invoke
2437
2467
  local trigger = CreateTrigger()
2438
2468
  TriggerRegisterAnyUnitEventBJ(trigger, EVENT_PLAYER_UNIT_DAMAGED)
2439
2469
  TriggerAddCondition(
@@ -2449,6 +2479,7 @@ Unit.onDamage = __TS__New(
2449
2479
  damageType = BlzGetEventDamageType(),
2450
2480
  weaponType = BlzGetEventWeaponType(),
2451
2481
  isAttack = BlzGetEventIsAttack(),
2482
+ originalAmount = GetEventDamage(),
2452
2483
  preventDeath = damageEventPreventDeath
2453
2484
  }
2454
2485
  local evData = setmetatable(
@@ -2465,7 +2496,7 @@ Unit.onDamage = __TS__New(
2465
2496
  invoke(event, source, target, evData)
2466
2497
  if evData[0] ~= nil and target.health - evData.amount < 0.405 then
2467
2498
  local bonusHealth = math.ceil(evData.amount)
2468
- target[104] = (target[104] or 0) + bonusHealth
2499
+ target[105] = (target[105] or 0) + bonusHealth
2469
2500
  BlzSetUnitMaxHP(
2470
2501
  target.handle,
2471
2502
  BlzGetUnitMaxHP(target.handle) + bonusHealth
@@ -2479,7 +2510,7 @@ Unit.onDamage = __TS__New(
2479
2510
  evData[0],
2480
2511
  table.unpack(evData, 1 + 1, 1 + (evData[1] or 0))
2481
2512
  )
2482
- target[104] = (target[104] or 0) - bonusHealth
2513
+ target[105] = (target[105] or 0) - bonusHealth
2483
2514
  SetWidgetLife(
2484
2515
  target.handle,
2485
2516
  GetWidgetLife(target.handle) - bonusHealth
@@ -2499,32 +2530,91 @@ Unit.onDamage = __TS__New(
2499
2530
  DestroyTrigger(trigger)
2500
2531
  end
2501
2532
  )
2502
- Unit.onItemDrop = __TS__New(
2533
+ Unit.itemDroppedEvent = __TS__New(
2503
2534
  ____exports.UnitTriggerEvent,
2504
2535
  EVENT_PLAYER_UNIT_DROP_ITEM,
2505
2536
  function()
2506
2537
  local unit = getTriggerUnit()
2507
- if getUnitTypeId(unit) ~= dummyUnitId then
2508
- return ____exports.Unit:of(unit), Item:of(getManipulatedItem())
2538
+ local item = getManipulatedItem()
2539
+ if getUnitTypeId(unit) ~= dummyUnitId and not (ignoreEventsItems[item] ~= nil) then
2540
+ return ____exports.Unit:of(unit), Item:of(item)
2509
2541
  end
2510
2542
  return IgnoreEvent
2511
2543
  end
2512
2544
  )
2513
- Unit.onItemPickup = __TS__New(
2545
+ Unit.itemPickedUpEvent = __TS__New(
2514
2546
  ____exports.UnitTriggerEvent,
2515
2547
  EVENT_PLAYER_UNIT_PICKUP_ITEM,
2516
2548
  function()
2517
2549
  local unit = getTriggerUnit()
2518
- if getUnitTypeId(unit) ~= dummyUnitId then
2519
- return ____exports.Unit:of(unit), Item:of(getManipulatedItem())
2550
+ local item = getManipulatedItem()
2551
+ if getUnitTypeId(unit) ~= dummyUnitId and not (ignoreEventsItems[item] ~= nil) then
2552
+ return ____exports.Unit:of(unit), Item:of(item)
2520
2553
  end
2521
2554
  return IgnoreEvent
2522
2555
  end
2523
2556
  )
2524
- Unit.onItemUse = __TS__New(
2557
+ Unit.itemUsedEvent = __TS__New(
2525
2558
  ____exports.UnitTriggerEvent,
2526
2559
  EVENT_PLAYER_UNIT_USE_ITEM,
2527
- function() return ____exports.Unit:of(GetTriggerUnit()), Item:of(GetManipulatedItem()) end
2560
+ function()
2561
+ local unit = getTriggerUnit()
2562
+ local item = getManipulatedItem()
2563
+ if getUnitTypeId(unit) ~= dummyUnitId and not (ignoreEventsItems[item] ~= nil) then
2564
+ return ____exports.Unit:of(unit), Item:of(item)
2565
+ end
2566
+ return IgnoreEvent
2567
+ end
2568
+ )
2569
+ Unit.itemStackedEvent = __TS__New(
2570
+ ____exports.UnitTriggerEvent,
2571
+ EVENT_PLAYER_UNIT_STACK_ITEM,
2572
+ function() return ____exports.Unit:of(getTriggerUnit()), Item:of(getManipulatedItem()) end
2573
+ )
2574
+ __TS__ObjectDefineProperty(
2575
+ Unit,
2576
+ "itemUseOrderEvent",
2577
+ {get = function(self)
2578
+ local event = __TS__New(Event)
2579
+ for order = orderId("useslot0"), orderId("useslot5") do
2580
+ local slot = order - orderId("useslot0")
2581
+ local function listener(unit)
2582
+ local item = unit.items[slot + 1]
2583
+ if item ~= nil then
2584
+ invoke(event, unit, item)
2585
+ end
2586
+ end
2587
+ self.onImmediateOrder[order]:addListener(listener)
2588
+ self.onTargetOrder[order]:addListener(listener)
2589
+ self.onPointOrder[order]:addListener(listener)
2590
+ end
2591
+ rawset(self, "itemUseOrderEvent", event)
2592
+ return event
2593
+ end}
2594
+ )
2595
+ __TS__ObjectDefineProperty(
2596
+ Unit,
2597
+ "itemMoveOrderEvent",
2598
+ {get = function(self)
2599
+ local event = __TS__New(Event)
2600
+ for order = orderId("moveslot0"), orderId("moveslot5") do
2601
+ local slotTo = order - orderId("moveslot0")
2602
+ self.onTargetOrder[order]:addListener(function(unit, item)
2603
+ local slotFrom = unit.items:findSlot(item)
2604
+ if slotFrom ~= nil then
2605
+ invoke(
2606
+ event,
2607
+ unit,
2608
+ item,
2609
+ slotFrom,
2610
+ slotTo
2611
+ )
2612
+ end
2613
+ end)
2614
+ end
2615
+ rawset(self, "itemMoveOrderEvent", event)
2616
+ return event
2617
+ end}
2528
2618
  )
2529
2619
  __TS__ObjectDefineProperty(
2530
2620
  Unit,
@@ -1,6 +1,8 @@
1
1
  local ____exports = {}
2
2
  local getUnitAbility = BlzGetUnitAbility
3
3
  local unitAddAbility = UnitAddAbility
4
+ local unitInventorySize = UnitInventorySize
5
+ local unitItemInSlot = UnitItemInSlot
4
6
  local unitMakeAbilityPermanent = UnitMakeAbilityPermanent
5
7
  ---
6
8
  -- @internal For use by internal systems only.
@@ -10,4 +12,14 @@ ____exports.addInternalAbility = function(unit, abilityTypeId)
10
12
  end
11
13
  return getUnitAbility(unit, abilityTypeId)
12
14
  end
15
+ ---
16
+ -- @internal For use by internal systems only.
17
+ ____exports.findUnitItemSlot = function(unit, item)
18
+ for slot = 0, unitInventorySize(unit) - 1 do
19
+ if item == unitItemInSlot(unit, slot) then
20
+ return slot
21
+ end
22
+ end
23
+ return nil
24
+ end
13
25
  return ____exports
@@ -1,7 +1,7 @@
1
1
  /** @noSelfInFile */
2
2
  import { LightningTypeId } from "./object-data/entry/lightning-type";
3
- import { Handle, HandleDestructor } from "../core/types/handle";
4
3
  import { Unit } from "../core/types/unit";
4
+ import { AbstractDestroyable, Destructor } from "../destroyable";
5
5
  declare const enum LightningPropertyKey {
6
6
  CHECK_VISIBILITY = 100,
7
7
  SOURCE_UNIT = 101,
@@ -12,10 +12,12 @@ declare const enum LightningPropertyKey {
12
12
  TARGET_X = 106,
13
13
  TARGET_Y = 107,
14
14
  TARGET_Z = 108,
15
- DURATION = 109
15
+ DURATION = 109,
16
+ FADING = 110
16
17
  }
17
18
  export type LightningConstructor<T extends Lightning> = typeof Lightning & (new (handle: jlightning, typeId: LightningTypeId) => T);
18
- export declare class Lightning extends Handle<jlightning> {
19
+ export declare class Lightning extends AbstractDestroyable {
20
+ readonly handle: jlightning;
19
21
  readonly typeId: LightningTypeId;
20
22
  private [LightningPropertyKey.CHECK_VISIBILITY]?;
21
23
  private [LightningPropertyKey.SOURCE_UNIT]?;
@@ -27,8 +29,9 @@ export declare class Lightning extends Handle<jlightning> {
27
29
  private [LightningPropertyKey.TARGET_Y]?;
28
30
  private [LightningPropertyKey.TARGET_Z]?;
29
31
  private [LightningPropertyKey.DURATION]?;
32
+ private [LightningPropertyKey.FADING]?;
30
33
  constructor(handle: jlightning, typeId: LightningTypeId);
31
- protected onDestroy(): HandleDestructor;
34
+ protected onDestroy(): Destructor;
32
35
  static create<T extends Lightning>(this: LightningConstructor<T>, typeId: LightningTypeId, ...parameters: [
33
36
  ...checkVisibility: [boolean] | [],
34
37
  ...sourceAndTarget: [sourceX: number, sourceY: number, targetX: number, targetY: number] | [
@@ -46,6 +49,10 @@ export declare class Lightning extends Handle<jlightning> {
46
49
  target: Unit
47
50
  ]
48
51
  ]): T;
49
- static flash(...parameters: [...parameters: Parameters<(typeof Lightning)["create"]>, duration: number]): void;
52
+ static flash(...parameters: [
53
+ ...parameters: Parameters<(typeof Lightning)["create"]>,
54
+ duration: number,
55
+ fading?: boolean
56
+ ]): void;
50
57
  }
51
58
  export {};