warscript 0.0.1-dev.63f1d69 → 0.0.1-dev.65d0014

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 (108) hide show
  1. package/binaryreader.d.ts +1 -0
  2. package/binaryreader.lua +3 -0
  3. package/core/types/effect.d.ts +13 -3
  4. package/core/types/effect.lua +116 -17
  5. package/core/types/frame.d.ts +8 -0
  6. package/core/types/frame.lua +93 -1
  7. package/core/util.d.ts +1 -1
  8. package/core/util.lua +12 -0
  9. package/engine/behavior.d.ts +2 -2
  10. package/engine/behavior.lua +6 -6
  11. package/engine/behaviour/ability/always-enabled.d.ts +7 -0
  12. package/engine/behaviour/ability/always-enabled.lua +31 -0
  13. package/engine/behaviour/ability/apply-buff.d.ts +8 -5
  14. package/engine/behaviour/ability/apply-buff.lua +32 -0
  15. package/engine/behaviour/ability/damage.d.ts +33 -11
  16. package/engine/behaviour/ability/damage.lua +89 -31
  17. package/engine/behaviour/ability/emulate-impact.d.ts +6 -0
  18. package/engine/behaviour/ability/emulate-impact.lua +28 -0
  19. package/engine/behaviour/ability/heal.d.ts +33 -6
  20. package/engine/behaviour/ability/heal.lua +89 -10
  21. package/engine/behaviour/ability/instant-impact.d.ts +2 -2
  22. package/engine/behaviour/ability/instant-impact.lua +4 -19
  23. package/engine/behaviour/ability/on-command-impact.d.ts +8 -0
  24. package/engine/behaviour/ability/on-command-impact.lua +25 -0
  25. package/engine/behaviour/ability/remove-buffs.d.ts +16 -0
  26. package/engine/behaviour/ability/remove-buffs.lua +28 -0
  27. package/engine/behaviour/ability/restore-mana.d.ts +15 -0
  28. package/engine/behaviour/ability/restore-mana.lua +29 -0
  29. package/engine/behaviour/ability.d.ts +15 -3
  30. package/engine/behaviour/ability.lua +93 -34
  31. package/engine/behaviour/unit.d.ts +5 -0
  32. package/engine/behaviour/unit.lua +20 -0
  33. package/engine/buff.d.ts +95 -38
  34. package/engine/buff.lua +424 -200
  35. package/engine/game-map.d.ts +7 -0
  36. package/engine/game-map.lua +32 -0
  37. package/engine/internal/ability.d.ts +16 -13
  38. package/engine/internal/ability.lua +80 -76
  39. package/engine/internal/item/ability.lua +106 -0
  40. package/engine/internal/item+owner.lua +2 -2
  41. package/engine/internal/item.d.ts +2 -2
  42. package/engine/internal/item.lua +56 -25
  43. package/engine/internal/misc/ability-disable-counter.d.ts +2 -0
  44. package/engine/internal/misc/ability-disable-counter.lua +13 -0
  45. package/engine/internal/object-data/auto-attack-speed-increase.d.ts +1 -1
  46. package/engine/internal/object-data/auto-attack-speed-increase.lua +2 -0
  47. package/engine/internal/object-data/evasion-probability.d.ts +2 -0
  48. package/engine/internal/object-data/evasion-probability.lua +16 -0
  49. package/engine/internal/unit/ability.d.ts +10 -1
  50. package/engine/internal/unit/ability.lua +36 -14
  51. package/engine/internal/unit/add-item-to-slot-init.d.ts +2 -0
  52. package/engine/internal/unit/add-item-to-slot-init.lua +23 -0
  53. package/engine/internal/unit/add-item-to-slot.d.ts +2 -0
  54. package/engine/internal/unit/add-item-to-slot.lua +52 -0
  55. package/engine/internal/unit/bonus.d.ts +6 -2
  56. package/engine/internal/unit/bonus.lua +23 -1
  57. package/engine/internal/unit/ignore-events-items.d.ts +2 -0
  58. package/engine/internal/unit/ignore-events-items.lua +5 -0
  59. package/engine/internal/unit/item.d.ts +24 -0
  60. package/engine/internal/unit/item.lua +78 -0
  61. package/engine/internal/unit/main-selected.d.ts +13 -0
  62. package/engine/internal/unit/main-selected.lua +51 -0
  63. package/engine/internal/unit+ability.lua +2 -2
  64. package/engine/internal/unit+transport.lua +4 -10
  65. package/engine/internal/unit-missile-launch.lua +24 -5
  66. package/engine/internal/unit.d.ts +26 -10
  67. package/engine/internal/unit.lua +178 -97
  68. package/engine/internal/utility.lua +12 -0
  69. package/engine/lightning.d.ts +12 -5
  70. package/engine/lightning.lua +48 -14
  71. package/engine/local-client.d.ts +7 -2
  72. package/engine/local-client.lua +82 -0
  73. package/engine/object-data/auxiliary/sound-preset-name.d.ts +5 -1
  74. package/engine/object-data/entry/ability-type.lua +8 -12
  75. package/engine/object-data/entry/buff-type/applicable.lua +10 -34
  76. package/engine/object-data/entry/item-type.d.ts +14 -0
  77. package/engine/object-data/entry/item-type.lua +91 -0
  78. package/engine/object-data/utility/object-data-entry-id-generator.lua +7 -0
  79. package/engine/object-field/ability.d.ts +26 -3
  80. package/engine/object-field/ability.lua +54 -1
  81. package/engine/object-field.d.ts +2 -2
  82. package/engine/object-field.lua +4 -0
  83. package/engine/standard/fields/ability.d.ts +2 -0
  84. package/engine/standard/fields/ability.lua +2 -0
  85. package/engine/unit.d.ts +3 -0
  86. package/engine/unit.lua +3 -0
  87. package/index.d.ts +1 -0
  88. package/index.lua +1 -0
  89. package/lualib_bundle.lua +7 -2
  90. package/net/socket.d.ts +7 -1
  91. package/net/socket.lua +45 -4
  92. package/network.d.ts +1 -0
  93. package/network.lua +3 -2
  94. package/objutil/buff.lua +1 -1
  95. package/package.json +2 -2
  96. package/patch-lua.d.ts +0 -0
  97. package/patch-lua.lua +10 -0
  98. package/property.d.ts +55 -0
  99. package/property.lua +374 -0
  100. package/utility/arrays.d.ts +8 -1
  101. package/utility/arrays.lua +34 -3
  102. package/utility/lazy.d.ts +2 -0
  103. package/utility/lazy.lua +14 -0
  104. package/utility/linked-set.d.ts +11 -2
  105. package/utility/linked-set.lua +5 -2
  106. package/utility/types.d.ts +1 -0
  107. package/core/mapbounds.d.ts +0 -8
  108. package/core/mapbounds.lua +0 -12
@@ -51,6 +51,8 @@ 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
@@ -75,6 +77,7 @@ local setUnitScale = SetUnitScale
75
77
  local setUnitPosition = SetUnitPosition
76
78
  local setUnitTimeScale = SetUnitTimeScale
77
79
  local getHandleId = GetHandleId
80
+ local getUnitCurrentOrder = GetUnitCurrentOrder
78
81
  local createUnit = CreateUnit
79
82
  local killUnit = KillUnit
80
83
  local setUnitExploded = SetUnitExploded
@@ -290,7 +293,6 @@ local function dispatch(event, idGetter, argsGetter)
290
293
  return event[id]
291
294
  end
292
295
  if not initialized then
293
- local invoke = Event.invoke
294
296
  event:addListener(function(...)
295
297
  local id = idGetter(...)
296
298
  local dispatched = rawget(self, id)
@@ -328,7 +330,6 @@ local function dispatchAbility(event)
328
330
  return event[id]
329
331
  end
330
332
  if not initialized then
331
- local invoke = Event.invoke
332
333
  event:addListener(function(unit, ability, ...)
333
334
  local dispatched = rawget(self, ability.typeId)
334
335
  if dispatched ~= nil then
@@ -564,17 +565,6 @@ local function retrieveAbility(unit, ability, abilityId)
564
565
  ____exports.Unit:of(unit)
565
566
  )
566
567
  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
568
  for i = 0, unitInventorySize(unit) - 1 do
579
569
  local item = unitItemInSlot(unit, i)
580
570
  if getItemAbility(item, abilityId) == ability then
@@ -632,15 +622,15 @@ for ____, player in ipairs(Player.all) do
632
622
  dummies[player] = dummy
633
623
  end
634
624
  local function delayHealthChecksCallback(unit)
635
- local counter = (unit[102] or 0) - 1
625
+ local counter = (unit[103] or 0) - 1
636
626
  if counter ~= 0 then
637
- unit[102] = counter
627
+ unit[103] = counter
638
628
  return
639
629
  end
640
- unit[102] = nil
641
- local healthBonus = unit[103]
630
+ unit[103] = nil
631
+ local healthBonus = unit[104]
642
632
  if healthBonus ~= nil then
643
- unit[103] = nil
633
+ unit[104] = nil
644
634
  local handle = unit.handle
645
635
  BlzSetUnitMaxHP(
646
636
  handle,
@@ -648,12 +638,17 @@ local function delayHealthChecksCallback(unit)
648
638
  )
649
639
  end
650
640
  end
641
+ local nextSyncId = 1
642
+ local unitBySyncId = setmetatable({}, {__mode = "k"})
651
643
  ____exports.Unit = __TS__Class()
652
644
  local Unit = ____exports.Unit
653
645
  Unit.name = "Unit"
654
646
  __TS__ClassExtends(Unit, Handle)
655
647
  function Unit.prototype.____constructor(self, handle)
656
648
  Handle.prototype.____constructor(self, handle)
649
+ local ____nextSyncId_0 = nextSyncId
650
+ nextSyncId = ____nextSyncId_0 + 1
651
+ self.syncId = ____nextSyncId_0
657
652
  self._owner = Player:of(getOwningPlayer(handle))
658
653
  assert(unitAddAbility(handle, leaveDetectAbilityId) and UnitMakeAbilityPermanent(handle, true, leaveDetectAbilityId))
659
654
  assert(unitAddAbility(handle, morphDetectAbilityId))
@@ -666,6 +661,7 @@ function Unit.prototype.____constructor(self, handle)
666
661
  fourCC("Amrf")
667
662
  ))
668
663
  end
664
+ unitBySyncId[self.syncId] = self
669
665
  local ____ = self.abilities
670
666
  end
671
667
  function Unit.prototype.getEvent(self, event, collector)
@@ -706,7 +702,10 @@ function Unit.prototype.onDestroy(self)
706
702
  if eventsToDestroy ~= nil then
707
703
  forEach(eventsToDestroy, "destroy")
708
704
  end
709
- removeUnit(handle)
705
+ if getUnitAbilityLevel(handle, leaveDetectAbilityId) > 0 then
706
+ unitRemoveAbility(handle, leaveDetectAbilityId)
707
+ removeUnit(handle)
708
+ end
710
709
  return Handle.prototype.onDestroy(self)
711
710
  end
712
711
  function Unit.prototype.addAttackHandler(self, condition, action)
@@ -748,8 +747,8 @@ function Unit.prototype.addModifier(self, property, modifier)
748
747
  end}
749
748
  end
750
749
  function Unit.prototype.hasCombatClassification(self, combatClassification)
751
- local ____combatClassification_0 = combatClassification
752
- return getUnitIntegerField(self.handle, UNIT_IF_TARGETED_AS) & ____combatClassification_0 == ____combatClassification_0
750
+ local ____combatClassification_1 = combatClassification
751
+ return getUnitIntegerField(self.handle, UNIT_IF_TARGETED_AS) & ____combatClassification_1 == ____combatClassification_1
753
752
  end
754
753
  function Unit.prototype.addClassification(self, classification)
755
754
  return unitAddType(self.handle, classification)
@@ -767,13 +766,13 @@ function Unit.prototype.isInvisibleTo(self, player)
767
766
  return isUnitInvisible(self.handle, player.handle)
768
767
  end
769
768
  function Unit.prototype.isInRangeOf(self, x, y, range)
770
- local ____temp_1
769
+ local ____temp_2
771
770
  if type(x) == "number" then
772
- ____temp_1 = isUnitInRangeXY(self.handle, x, y, range)
771
+ ____temp_2 = isUnitInRangeXY(self.handle, x, y, range)
773
772
  else
774
- ____temp_1 = isUnitInRange(self.handle, x.handle, y)
773
+ ____temp_2 = isUnitInRange(self.handle, x.handle, y)
775
774
  end
776
- return ____temp_1
775
+ return ____temp_2
777
776
  end
778
777
  function Unit.prototype.isAllyOf(self, unit)
779
778
  return isUnitAlly(
@@ -800,7 +799,7 @@ function Unit.prototype.queueAnimation(self, animation)
800
799
  queueUnitAnimation(self.handle, animation)
801
800
  end
802
801
  function Unit.prototype.delayHealthChecks(self)
803
- self[102] = (self[102] or 0) + 1
802
+ self[103] = (self[103] or 0) + 1
804
803
  Timer:run(delayHealthChecksCallback, self)
805
804
  end
806
805
  function Unit.prototype.setPosition(self, x, y)
@@ -817,14 +816,14 @@ function Unit.prototype.kill(self)
817
816
  killUnit(self.handle)
818
817
  end
819
818
  function Unit.prototype.revive(self, x, y, doEffect)
820
- local ____ReviveHero_4 = ReviveHero
821
- local ____array_3 = __TS__SparseArrayNew(self.handle, x, y)
822
- local ____doEffect_2 = doEffect
823
- if ____doEffect_2 == nil then
824
- ____doEffect_2 = false
819
+ local ____ReviveHero_5 = ReviveHero
820
+ local ____array_4 = __TS__SparseArrayNew(self.handle, x, y)
821
+ local ____doEffect_3 = doEffect
822
+ if ____doEffect_3 == nil then
823
+ ____doEffect_3 = false
825
824
  end
826
- __TS__SparseArrayPush(____array_3, ____doEffect_2)
827
- ____ReviveHero_4(__TS__SparseArraySpread(____array_3))
825
+ __TS__SparseArrayPush(____array_4, ____doEffect_3)
826
+ ____ReviveHero_5(__TS__SparseArraySpread(____array_4))
828
827
  end
829
828
  function Unit.prototype.healTarget(self, target, amount)
830
829
  if __TS__InstanceOf(target, ____exports.Unit) and target:hasAbility(fourCC("BIhm")) then
@@ -864,7 +863,7 @@ function Unit.prototype.dropItemSlot(self, item, slot)
864
863
  return UnitDropItemSlot(self.handle, item.handle, slot)
865
864
  end
866
865
  function Unit.prototype.itemInSlot(self, slot)
867
- return Item:of(UnitItemInSlot(self.handle, slot))
866
+ return Item:of(unitItemInSlot(self.handle, slot))
868
867
  end
869
868
  function Unit.prototype.addAbility(self, abilityId)
870
869
  if unitAddAbility(self.handle, abilityId) then
@@ -933,8 +932,15 @@ function Unit.prototype.interruptAttack(self)
933
932
  unitInterruptAttack(self.handle)
934
933
  end
935
934
  function Unit.prototype.interruptCast(self, abilityId)
936
- unitDisableAbility(self.handle, abilityId, true, false)
937
- unitDisableAbility(self.handle, abilityId, false, false)
935
+ local handle = self.handle
936
+ unitDisableAbility(handle, abilityId, true, false)
937
+ Timer:run(
938
+ unitDisableAbility,
939
+ handle,
940
+ abilityId,
941
+ false,
942
+ false
943
+ )
938
944
  end
939
945
  function Unit.prototype.getDistanceTo(self, target)
940
946
  local handle = self.handle
@@ -994,18 +1000,18 @@ function Unit.prototype.unpauseEx(self)
994
1000
  self:decrementStunCounter()
995
1001
  end
996
1002
  function Unit.prototype.incrementStunCounter(self)
997
- local stunCounter = self[101] or 0
998
- if not self[100] or stunCounter >= 0 then
1003
+ local stunCounter = self[102] or 0
1004
+ if not self[101] or stunCounter >= 0 then
999
1005
  BlzPauseUnitEx(self.handle, true)
1000
1006
  end
1001
- self[101] = stunCounter + 1
1007
+ self[102] = stunCounter + 1
1002
1008
  end
1003
1009
  function Unit.prototype.decrementStunCounter(self)
1004
- local stunCounter = self[101] or 0
1005
- if not self[100] or stunCounter >= 1 then
1010
+ local stunCounter = self[102] or 0
1011
+ if not self[101] or stunCounter >= 1 then
1006
1012
  BlzPauseUnitEx(self.handle, false)
1007
1013
  end
1008
- self[101] = stunCounter - 1
1014
+ self[102] = stunCounter - 1
1009
1015
  end
1010
1016
  function Unit.create(self, owner, id, x, y, facing, skinId)
1011
1017
  local handle = skinId and BlzCreateUnitWithSkin(
@@ -1107,8 +1113,11 @@ function Unit.getInSector(self, pos, range, offsetAngle, centralAngle)
1107
1113
  )
1108
1114
  return targetCollection
1109
1115
  end
1110
- function Unit.getSelectionOf(self, player)
1111
- targetCollection = {}
1116
+ function Unit.getSelectionOf(self, player, target)
1117
+ if target == nil then
1118
+ target = {}
1119
+ end
1120
+ targetCollection = target
1112
1121
  targetCollectionNextIndex = 1
1113
1122
  GroupEnumUnitsSelected(dummyGroup, player.handle, collectIntoTarget)
1114
1123
  return targetCollection
@@ -1130,6 +1139,9 @@ end
1130
1139
  function Unit.prototype.__tostring(self)
1131
1140
  return (((self.constructor.name .. "$") .. util.id2s(self.typeId)) .. "@") .. tostring(getHandleId(self.handle))
1132
1141
  end
1142
+ function Unit.getBySyncId(self, syncId)
1143
+ return unitBySyncId[syncId]
1144
+ end
1133
1145
  __TS__SetDescriptor(
1134
1146
  Unit.prototype,
1135
1147
  "_deltas",
@@ -1193,6 +1205,14 @@ __TS__SetDescriptor(
1193
1205
  end},
1194
1206
  true
1195
1207
  )
1208
+ __TS__SetDescriptor(
1209
+ Unit.prototype,
1210
+ "isStunned",
1211
+ {get = function(self)
1212
+ return getUnitCurrentOrder(self.handle) == orderId("stunned")
1213
+ end},
1214
+ true
1215
+ )
1196
1216
  __TS__SetDescriptor(
1197
1217
  Unit.prototype,
1198
1218
  "combatClassifications",
@@ -1387,17 +1407,17 @@ __TS__SetDescriptor(
1387
1407
  "isTeamGlowVisible",
1388
1408
  {
1389
1409
  get = function(self)
1390
- return not self[105]
1410
+ return not self[106]
1391
1411
  end,
1392
1412
  set = function(self, isTeamGlowVisible)
1393
1413
  showUnitTeamGlow(self.handle, isTeamGlowVisible)
1394
- local ____temp_5
1414
+ local ____temp_6
1395
1415
  if not isTeamGlowVisible then
1396
- ____temp_5 = true
1416
+ ____temp_6 = true
1397
1417
  else
1398
- ____temp_5 = nil
1418
+ ____temp_6 = nil
1399
1419
  end
1400
- self[105] = ____temp_5
1420
+ self[106] = ____temp_6
1401
1421
  end
1402
1422
  },
1403
1423
  true
@@ -1407,7 +1427,7 @@ __TS__SetDescriptor(
1407
1427
  "color",
1408
1428
  {set = function(self, color)
1409
1429
  setUnitColor(self.handle, color.handle)
1410
- if self[105] then
1430
+ if self[106] then
1411
1431
  showUnitTeamGlow(self.handle, false)
1412
1432
  end
1413
1433
  end},
@@ -1431,14 +1451,14 @@ __TS__SetDescriptor(
1431
1451
  "maxHealth",
1432
1452
  {
1433
1453
  get = function(self)
1434
- return BlzGetUnitMaxHP(self.handle) - (self[103] or 0) - (self[104] or 0)
1454
+ return BlzGetUnitMaxHP(self.handle) - (self[104] or 0) - (self[105] or 0)
1435
1455
  end,
1436
1456
  set = function(self, maxHealth)
1437
- if maxHealth < 1 and self[102] ~= nil then
1438
- self[103] = (self[103] or 0) + (1 - maxHealth)
1457
+ if maxHealth < 1 and self[103] ~= nil then
1458
+ self[104] = (self[104] or 0) + (1 - maxHealth)
1439
1459
  maxHealth = 1
1440
1460
  end
1441
- BlzSetUnitMaxHP(self.handle, maxHealth + (self[104] or 0))
1461
+ BlzSetUnitMaxHP(self.handle, maxHealth + (self[105] or 0))
1442
1462
  end
1443
1463
  },
1444
1464
  true
@@ -1480,10 +1500,10 @@ __TS__SetDescriptor(
1480
1500
  "health",
1481
1501
  {
1482
1502
  get = function(self)
1483
- return GetWidgetLife(self.handle) - (self[104] or 0)
1503
+ return GetWidgetLife(self.handle) - (self[105] or 0)
1484
1504
  end,
1485
1505
  set = function(self, health)
1486
- SetWidgetLife(self.handle, health + (self[104] or 0))
1506
+ SetWidgetLife(self.handle, health + (self[105] or 0))
1487
1507
  end
1488
1508
  },
1489
1509
  true
@@ -1694,17 +1714,17 @@ __TS__SetDescriptor(
1694
1714
  set = function(self, isPaused)
1695
1715
  local handle = self.handle
1696
1716
  if isPaused and not IsUnitPaused(handle) then
1697
- self[100] = true
1698
- for _ = self[101] or 0, -1 do
1717
+ self[101] = true
1718
+ for _ = self[102] or 0, -1 do
1699
1719
  BlzPauseUnitEx(handle, true)
1700
1720
  end
1701
1721
  PauseUnit(handle, true)
1702
1722
  elseif not isPaused and IsUnitPaused(handle) then
1703
1723
  PauseUnit(handle, false)
1704
- for _ = self[101] or 0, -1 do
1724
+ for _ = self[102] or 0, -1 do
1705
1725
  BlzPauseUnitEx(handle, false)
1706
1726
  end
1707
- self[100] = nil
1727
+ self[101] = nil
1708
1728
  end
1709
1729
  end
1710
1730
  },
@@ -2061,7 +2081,6 @@ Unit.onDecay = __TS__New(
2061
2081
  Unit.onResurrect = __TS__New(
2062
2082
  InitializingEvent,
2063
2083
  function(event)
2064
- local invoke = Event.invoke
2065
2084
  local dead = setmetatable({}, {__mode = "k"})
2066
2085
  ____exports.Unit.deathEvent:addListener(function(unit)
2067
2086
  dead[unit] = true
@@ -2077,10 +2096,15 @@ Unit.onResurrect = __TS__New(
2077
2096
  Unit.morphEvent = __TS__New(
2078
2097
  InitializingEvent,
2079
2098
  function(event)
2099
+ local function ifNotLeft(unit)
2100
+ local handle = unit.handle
2101
+ if getUnitAbilityLevel(handle, leaveDetectAbilityId) ~= 0 and unitAddAbility(handle, morphDetectAbilityId) then
2102
+ invoke(event, unit)
2103
+ end
2104
+ end
2080
2105
  ____exports.Unit.onImmediateOrder[orderId("undefend")]:addListener(function(unit)
2081
2106
  if getUnitAbilityLevel(unit.handle, morphDetectAbilityId) == 0 then
2082
- assert(unitAddAbility(unit.handle, morphDetectAbilityId))
2083
- Timer:run(Event.invoke, event, unit)
2107
+ Timer:run(ifNotLeft, unit)
2084
2108
  end
2085
2109
  end)
2086
2110
  end
@@ -2118,27 +2142,26 @@ Unit.onSpellEffect = dispatchId(__TS__New(
2118
2142
  Unit.onTargetCast = dispatchId(__TS__New(
2119
2143
  InitializingEvent,
2120
2144
  function(event)
2121
- local invoke = Event.invoke
2122
2145
  local function listener(unit, id)
2123
- local ____GetSpellTargetUnit_result_8
2146
+ local ____GetSpellTargetUnit_result_9
2124
2147
  if GetSpellTargetUnit() then
2125
- ____GetSpellTargetUnit_result_8 = ____exports.Unit:of(GetSpellTargetUnit())
2148
+ ____GetSpellTargetUnit_result_9 = ____exports.Unit:of(GetSpellTargetUnit())
2126
2149
  else
2127
- local ____GetSpellTargetItem_result_7
2150
+ local ____GetSpellTargetItem_result_8
2128
2151
  if GetSpellTargetItem() then
2129
- ____GetSpellTargetItem_result_7 = Item:of(GetSpellTargetItem())
2152
+ ____GetSpellTargetItem_result_8 = Item:of(GetSpellTargetItem())
2130
2153
  else
2131
- local ____GetSpellTargetDestructable_result_6
2154
+ local ____GetSpellTargetDestructable_result_7
2132
2155
  if GetSpellTargetDestructable() then
2133
- ____GetSpellTargetDestructable_result_6 = Destructable:of(GetSpellTargetDestructable())
2156
+ ____GetSpellTargetDestructable_result_7 = Destructable:of(GetSpellTargetDestructable())
2134
2157
  else
2135
- ____GetSpellTargetDestructable_result_6 = nil
2158
+ ____GetSpellTargetDestructable_result_7 = nil
2136
2159
  end
2137
- ____GetSpellTargetItem_result_7 = ____GetSpellTargetDestructable_result_6
2160
+ ____GetSpellTargetItem_result_8 = ____GetSpellTargetDestructable_result_7
2138
2161
  end
2139
- ____GetSpellTargetUnit_result_8 = ____GetSpellTargetItem_result_7
2162
+ ____GetSpellTargetUnit_result_9 = ____GetSpellTargetItem_result_8
2140
2163
  end
2141
- local target = ____GetSpellTargetUnit_result_8
2164
+ local target = ____GetSpellTargetUnit_result_9
2142
2165
  if target then
2143
2166
  invoke(event, unit, id, target)
2144
2167
  end
@@ -2310,10 +2333,12 @@ Unit.onImmediateOrder = dispatchId(__TS__New(
2310
2333
  ____exports.UnitTriggerEvent,
2311
2334
  EVENT_PLAYER_UNIT_ISSUED_ORDER,
2312
2335
  function()
2313
- local unit = ____exports.Unit:of(getOrderedUnit())
2314
- local issuedOrderId = getIssuedOrderId()
2315
- if unit ~= nil and unit.state == 1 then
2316
- return unit, issuedOrderId
2336
+ local handle = getOrderedUnit()
2337
+ if handle ~= nil and getUnitTypeId(handle) ~= dummyUnitId then
2338
+ local unit = ____exports.Unit:of(handle)
2339
+ if unit.state == 1 then
2340
+ return unit, getIssuedOrderId()
2341
+ end
2317
2342
  end
2318
2343
  return IgnoreEvent
2319
2344
  end
@@ -2335,7 +2360,6 @@ Unit.autoAttackStartEvent = __TS__New(
2335
2360
  )
2336
2361
  Unit.onDamaging = (function()
2337
2362
  local event = __TS__New(Event)
2338
- local invoke = Event.invoke
2339
2363
  local trigger = CreateTrigger()
2340
2364
  TriggerRegisterAnyUnitEventBJ(trigger, EVENT_PLAYER_UNIT_DAMAGING)
2341
2365
  TriggerAddCondition(
@@ -2434,7 +2458,6 @@ end)()
2434
2458
  Unit.onDamage = __TS__New(
2435
2459
  InitializingEvent,
2436
2460
  function(event)
2437
- local invoke = Event.invoke
2438
2461
  local trigger = CreateTrigger()
2439
2462
  TriggerRegisterAnyUnitEventBJ(trigger, EVENT_PLAYER_UNIT_DAMAGED)
2440
2463
  TriggerAddCondition(
@@ -2450,6 +2473,7 @@ Unit.onDamage = __TS__New(
2450
2473
  damageType = BlzGetEventDamageType(),
2451
2474
  weaponType = BlzGetEventWeaponType(),
2452
2475
  isAttack = BlzGetEventIsAttack(),
2476
+ originalAmount = GetEventDamage(),
2453
2477
  preventDeath = damageEventPreventDeath
2454
2478
  }
2455
2479
  local evData = setmetatable(
@@ -2466,7 +2490,7 @@ Unit.onDamage = __TS__New(
2466
2490
  invoke(event, source, target, evData)
2467
2491
  if evData[0] ~= nil and target.health - evData.amount < 0.405 then
2468
2492
  local bonusHealth = math.ceil(evData.amount)
2469
- target[104] = (target[104] or 0) + bonusHealth
2493
+ target[105] = (target[105] or 0) + bonusHealth
2470
2494
  BlzSetUnitMaxHP(
2471
2495
  target.handle,
2472
2496
  BlzGetUnitMaxHP(target.handle) + bonusHealth
@@ -2480,7 +2504,7 @@ Unit.onDamage = __TS__New(
2480
2504
  evData[0],
2481
2505
  table.unpack(evData, 1 + 1, 1 + (evData[1] or 0))
2482
2506
  )
2483
- target[104] = (target[104] or 0) - bonusHealth
2507
+ target[105] = (target[105] or 0) - bonusHealth
2484
2508
  SetWidgetLife(
2485
2509
  target.handle,
2486
2510
  GetWidgetLife(target.handle) - bonusHealth
@@ -2500,32 +2524,91 @@ Unit.onDamage = __TS__New(
2500
2524
  DestroyTrigger(trigger)
2501
2525
  end
2502
2526
  )
2503
- Unit.onItemDrop = __TS__New(
2527
+ Unit.itemDroppedEvent = __TS__New(
2504
2528
  ____exports.UnitTriggerEvent,
2505
2529
  EVENT_PLAYER_UNIT_DROP_ITEM,
2506
2530
  function()
2507
2531
  local unit = getTriggerUnit()
2508
- if getUnitTypeId(unit) ~= dummyUnitId then
2509
- return ____exports.Unit:of(unit), Item:of(getManipulatedItem())
2532
+ local item = getManipulatedItem()
2533
+ if getUnitTypeId(unit) ~= dummyUnitId and not (ignoreEventsItems[item] ~= nil) then
2534
+ return ____exports.Unit:of(unit), Item:of(item)
2510
2535
  end
2511
2536
  return IgnoreEvent
2512
2537
  end
2513
2538
  )
2514
- Unit.onItemPickup = __TS__New(
2539
+ Unit.itemPickedUpEvent = __TS__New(
2515
2540
  ____exports.UnitTriggerEvent,
2516
2541
  EVENT_PLAYER_UNIT_PICKUP_ITEM,
2517
2542
  function()
2518
2543
  local unit = getTriggerUnit()
2519
- if getUnitTypeId(unit) ~= dummyUnitId then
2520
- return ____exports.Unit:of(unit), Item:of(getManipulatedItem())
2544
+ local item = getManipulatedItem()
2545
+ if getUnitTypeId(unit) ~= dummyUnitId and not (ignoreEventsItems[item] ~= nil) then
2546
+ return ____exports.Unit:of(unit), Item:of(item)
2521
2547
  end
2522
2548
  return IgnoreEvent
2523
2549
  end
2524
2550
  )
2525
- Unit.onItemUse = __TS__New(
2551
+ Unit.itemUsedEvent = __TS__New(
2526
2552
  ____exports.UnitTriggerEvent,
2527
2553
  EVENT_PLAYER_UNIT_USE_ITEM,
2528
- function() return ____exports.Unit:of(GetTriggerUnit()), Item:of(GetManipulatedItem()) end
2554
+ function()
2555
+ local unit = getTriggerUnit()
2556
+ local item = getManipulatedItem()
2557
+ if getUnitTypeId(unit) ~= dummyUnitId and not (ignoreEventsItems[item] ~= nil) then
2558
+ return ____exports.Unit:of(unit), Item:of(item)
2559
+ end
2560
+ return IgnoreEvent
2561
+ end
2562
+ )
2563
+ Unit.itemStackedEvent = __TS__New(
2564
+ ____exports.UnitTriggerEvent,
2565
+ EVENT_PLAYER_UNIT_STACK_ITEM,
2566
+ function() return ____exports.Unit:of(getTriggerUnit()), Item:of(getManipulatedItem()) end
2567
+ )
2568
+ __TS__ObjectDefineProperty(
2569
+ Unit,
2570
+ "itemUseOrderEvent",
2571
+ {get = function(self)
2572
+ local event = __TS__New(Event)
2573
+ for order = orderId("useslot0"), orderId("useslot5") do
2574
+ local slot = order - orderId("useslot0")
2575
+ local function listener(unit)
2576
+ local item = unit.items[slot + 1]
2577
+ if item ~= nil then
2578
+ invoke(event, unit, item)
2579
+ end
2580
+ end
2581
+ self.onImmediateOrder[order]:addListener(listener)
2582
+ self.onTargetOrder[order]:addListener(listener)
2583
+ self.onPointOrder[order]:addListener(listener)
2584
+ end
2585
+ rawset(self, "itemUseOrderEvent", event)
2586
+ return event
2587
+ end}
2588
+ )
2589
+ __TS__ObjectDefineProperty(
2590
+ Unit,
2591
+ "itemMoveOrderEvent",
2592
+ {get = function(self)
2593
+ local event = __TS__New(Event)
2594
+ for order = orderId("moveslot0"), orderId("moveslot5") do
2595
+ local slotTo = order - orderId("moveslot0")
2596
+ self.onTargetOrder[order]:addListener(function(unit, item)
2597
+ local slotFrom = unit.items:findSlot(item)
2598
+ if slotFrom ~= nil then
2599
+ invoke(
2600
+ event,
2601
+ unit,
2602
+ item,
2603
+ slotFrom,
2604
+ slotTo
2605
+ )
2606
+ end
2607
+ end)
2608
+ end
2609
+ rawset(self, "itemMoveOrderEvent", event)
2610
+ return event
2611
+ end}
2529
2612
  )
2530
2613
  __TS__ObjectDefineProperty(
2531
2614
  Unit,
@@ -2575,15 +2658,13 @@ __TS__ObjectDefineProperty(
2575
2658
  orderId("unimmolation")
2576
2659
  }) do
2577
2660
  ____exports.Unit.onImmediateOrder[leaveOrderId]:addListener(function(unit)
2578
- if unit.state == 1 then
2579
- local handle = unit.handle
2580
- for i = 1, #leaveAbilityIds do
2581
- if getUnitAbilityLevel(handle, leaveAbilityIds[i]) ~= 0 then
2582
- return
2583
- end
2661
+ local handle = unit.handle
2662
+ for i = 1, #leaveAbilityIds do
2663
+ if getUnitAbilityLevel(handle, leaveAbilityIds[i]) ~= 0 then
2664
+ return
2584
2665
  end
2585
- unit:destroy()
2586
2666
  end
2667
+ unit:destroy()
2587
2668
  end)
2588
2669
  end
2589
2670
  end)(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 {};