warscript 0.0.1-dev.7fd7bc7 → 0.0.1-dev.820013f

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 (100) hide show
  1. package/attributes.d.ts +0 -1
  2. package/binaryreader.d.ts +1 -0
  3. package/binaryreader.lua +3 -0
  4. package/core/types/frame.d.ts +5 -1
  5. package/core/types/frame.lua +34 -1
  6. package/core/types/group.d.ts +0 -1
  7. package/core/types/image.d.ts +0 -1
  8. package/core/types/unit.lua +8 -0
  9. package/core/util.d.ts +1 -1
  10. package/core/util.lua +6 -0
  11. package/decl/index.d.ts +1 -0
  12. package/engine/ability.d.ts +1 -1
  13. package/engine/behavior.d.ts +10 -10
  14. package/engine/behavior.lua +6 -6
  15. package/engine/behaviour/ability/apply-buff.d.ts +3 -5
  16. package/engine/behaviour/ability/apply-unit-behavior.d.ts +6 -1
  17. package/engine/behaviour/ability/damage.d.ts +33 -11
  18. package/engine/behaviour/ability/damage.lua +89 -31
  19. package/engine/behaviour/ability/heal.d.ts +33 -6
  20. package/engine/behaviour/ability/heal.lua +89 -10
  21. package/engine/behaviour/ability/restore-mana.d.ts +15 -0
  22. package/engine/behaviour/ability/restore-mana.lua +29 -0
  23. package/engine/behaviour/unit/stun-immunity.d.ts +0 -1
  24. package/engine/behaviour/unit.d.ts +8 -2
  25. package/engine/behaviour/unit.lua +27 -0
  26. package/engine/buff.d.ts +62 -20
  27. package/engine/buff.lua +247 -72
  28. package/engine/game-map.d.ts +7 -0
  29. package/engine/game-map.lua +32 -0
  30. package/engine/internal/ability.d.ts +1 -11
  31. package/engine/internal/ability.lua +2 -78
  32. package/engine/internal/item+owner.lua +2 -2
  33. package/engine/internal/unit/bonus.d.ts +9 -8
  34. package/engine/internal/unit/bonus.lua +6 -1
  35. package/engine/internal/unit/item.d.ts +23 -0
  36. package/engine/internal/unit/item.lua +74 -0
  37. package/engine/internal/unit/main-selected.d.ts +7 -0
  38. package/engine/internal/unit/main-selected.lua +40 -0
  39. package/engine/internal/unit+ability.lua +2 -2
  40. package/engine/internal/unit+transport.lua +4 -10
  41. package/engine/internal/unit-missile-launch.lua +24 -5
  42. package/engine/internal/unit.d.ts +19 -12
  43. package/engine/internal/unit.lua +91 -65
  44. package/engine/local-client.d.ts +7 -2
  45. package/engine/local-client.lua +82 -0
  46. package/engine/object-data/auxiliary/attachment-preset.d.ts +0 -1
  47. package/engine/object-data/auxiliary/combat-classification.d.ts +0 -2
  48. package/engine/object-data/entry/ability-type/blank-configurable.d.ts +0 -1
  49. package/engine/object-data/entry/ability-type/blank-passive.d.ts +0 -1
  50. package/engine/object-data/entry/ability-type/channel.d.ts +0 -1
  51. package/engine/object-data/entry/ability-type.d.ts +0 -1
  52. package/engine/object-data/entry/buff-type/applicable.d.ts +0 -1
  53. package/engine/object-data/entry/buff-type/blank.d.ts +0 -1
  54. package/engine/object-data/entry/buff-type.d.ts +0 -1
  55. package/engine/object-data/entry/destructible-type.d.ts +0 -1
  56. package/engine/object-data/entry/item-type/blank.d.ts +0 -1
  57. package/engine/object-data/entry/item-type.d.ts +12 -1
  58. package/engine/object-data/entry/item-type.lua +78 -0
  59. package/engine/object-data/entry/lightning-type.d.ts +0 -1
  60. package/engine/object-data/entry/unit-type.d.ts +0 -1
  61. package/engine/object-data/entry/upgrade/blank.d.ts +0 -1
  62. package/engine/object-data/entry/upgrade.d.ts +0 -1
  63. package/engine/object-data/entry.d.ts +2 -3
  64. package/engine/object-field/ability.d.ts +18 -1
  65. package/engine/object-field/ability.lua +51 -1
  66. package/engine/object-field.d.ts +0 -1
  67. package/engine/random.d.ts +1 -5
  68. package/engine/unit.d.ts +2 -0
  69. package/engine/unit.lua +11 -2
  70. package/event.d.ts +2 -3
  71. package/event.lua +9 -5
  72. package/index.d.ts +1 -0
  73. package/index.lua +1 -0
  74. package/lualib_bundle.lua +146 -42
  75. package/math/vec2.d.ts +2 -9
  76. package/math.d.ts +0 -2
  77. package/net/socket.d.ts +7 -1
  78. package/net/socket.lua +45 -4
  79. package/network.d.ts +1 -0
  80. package/network.lua +3 -2
  81. package/objutil/ability.d.ts +0 -1
  82. package/objutil/buff.d.ts +0 -1
  83. package/objutil/buff.lua +1 -1
  84. package/objutil/object.d.ts +0 -1
  85. package/objutil/unit.d.ts +0 -1
  86. package/package.json +13 -13
  87. package/patch-lua.d.ts +0 -0
  88. package/patch-lua.lua +10 -0
  89. package/property.d.ts +55 -0
  90. package/property.lua +374 -0
  91. package/util/stream.d.ts +0 -1
  92. package/utility/arrays.d.ts +3 -4
  93. package/utility/bit-set.d.ts +0 -2
  94. package/utility/linked-set.d.ts +11 -3
  95. package/utility/linked-set.lua +5 -2
  96. package/utility/lua-maps.d.ts +1 -2
  97. package/utility/lua-sets.d.ts +1 -2
  98. package/utility/types.d.ts +1 -0
  99. package/core/mapbounds.d.ts +0 -8
  100. package/core/mapbounds.lua +0 -12
@@ -7,6 +7,9 @@ local __TS__Class = ____lualib.__TS__Class
7
7
  local __TS__ClassExtends = ____lualib.__TS__ClassExtends
8
8
  local __TS__SetDescriptor = ____lualib.__TS__SetDescriptor
9
9
  local __TS__ArraySetLength = ____lualib.__TS__ArraySetLength
10
+ local __TS__SparseArrayNew = ____lualib.__TS__SparseArrayNew
11
+ local __TS__SparseArrayPush = ____lualib.__TS__SparseArrayPush
12
+ local __TS__SparseArraySpread = ____lualib.__TS__SparseArraySpread
10
13
  local __TS__InstanceOf = ____lualib.__TS__InstanceOf
11
14
  local __TS__ObjectDefineProperty = ____lualib.__TS__ObjectDefineProperty
12
15
  local Set = ____lualib.Set
@@ -279,16 +282,14 @@ function UnitTriggerEvent.prototype.____constructor(self, eventType, c)
279
282
  end
280
283
  local function dispatch(event, idGetter, argsGetter)
281
284
  local initialized = false
282
- local x = {}
283
285
  return setmetatable(
284
- x,
286
+ {},
285
287
  {
286
288
  __index = function(self, id)
287
289
  if type(id) ~= "number" then
288
290
  return event[id]
289
291
  end
290
292
  if not initialized then
291
- local invoke = Event.invoke
292
293
  event:addListener(function(...)
293
294
  local id = idGetter(...)
294
295
  local dispatched = rawget(self, id)
@@ -326,7 +327,6 @@ local function dispatchAbility(event)
326
327
  return event[id]
327
328
  end
328
329
  if not initialized then
329
- local invoke = Event.invoke
330
330
  event:addListener(function(unit, ability, ...)
331
331
  local dispatched = rawget(self, ability.typeId)
332
332
  if dispatched ~= nil then
@@ -630,15 +630,15 @@ for ____, player in ipairs(Player.all) do
630
630
  dummies[player] = dummy
631
631
  end
632
632
  local function delayHealthChecksCallback(unit)
633
- local counter = (unit[102] or 0) - 1
633
+ local counter = (unit[103] or 0) - 1
634
634
  if counter ~= 0 then
635
- unit[102] = counter
635
+ unit[103] = counter
636
636
  return
637
637
  end
638
- unit[102] = nil
639
- local healthBonus = unit[103]
638
+ unit[103] = nil
639
+ local healthBonus = unit[104]
640
640
  if healthBonus ~= nil then
641
- unit[103] = nil
641
+ unit[104] = nil
642
642
  local handle = unit.handle
643
643
  BlzSetUnitMaxHP(
644
644
  handle,
@@ -646,12 +646,17 @@ local function delayHealthChecksCallback(unit)
646
646
  )
647
647
  end
648
648
  end
649
+ local nextSyncId = 1
650
+ local unitBySyncId = setmetatable({}, {__mode = "k"})
649
651
  ____exports.Unit = __TS__Class()
650
652
  local Unit = ____exports.Unit
651
653
  Unit.name = "Unit"
652
654
  __TS__ClassExtends(Unit, Handle)
653
655
  function Unit.prototype.____constructor(self, handle)
654
656
  Handle.prototype.____constructor(self, handle)
657
+ local ____nextSyncId_0 = nextSyncId
658
+ nextSyncId = ____nextSyncId_0 + 1
659
+ self.syncId = ____nextSyncId_0
655
660
  self._owner = Player:of(getOwningPlayer(handle))
656
661
  assert(unitAddAbility(handle, leaveDetectAbilityId) and UnitMakeAbilityPermanent(handle, true, leaveDetectAbilityId))
657
662
  assert(unitAddAbility(handle, morphDetectAbilityId))
@@ -664,6 +669,7 @@ function Unit.prototype.____constructor(self, handle)
664
669
  fourCC("Amrf")
665
670
  ))
666
671
  end
672
+ unitBySyncId[self.syncId] = self
667
673
  local ____ = self.abilities
668
674
  end
669
675
  function Unit.prototype.getEvent(self, event, collector)
@@ -749,8 +755,8 @@ function Unit.prototype.addModifier(self, property, modifier)
749
755
  end}
750
756
  end
751
757
  function Unit.prototype.hasCombatClassification(self, combatClassification)
752
- local ____combatClassification_0 = combatClassification
753
- return getUnitIntegerField(self.handle, UNIT_IF_TARGETED_AS) & ____combatClassification_0 == ____combatClassification_0
758
+ local ____combatClassification_1 = combatClassification
759
+ return getUnitIntegerField(self.handle, UNIT_IF_TARGETED_AS) & ____combatClassification_1 == ____combatClassification_1
754
760
  end
755
761
  function Unit.prototype.addClassification(self, classification)
756
762
  return unitAddType(self.handle, classification)
@@ -768,13 +774,13 @@ function Unit.prototype.isInvisibleTo(self, player)
768
774
  return isUnitInvisible(self.handle, player.handle)
769
775
  end
770
776
  function Unit.prototype.isInRangeOf(self, x, y, range)
771
- local ____temp_1
777
+ local ____temp_2
772
778
  if type(x) == "number" then
773
- ____temp_1 = isUnitInRangeXY(self.handle, x, y, range)
779
+ ____temp_2 = isUnitInRangeXY(self.handle, x, y, range)
774
780
  else
775
- ____temp_1 = isUnitInRange(self.handle, x.handle, y)
781
+ ____temp_2 = isUnitInRange(self.handle, x.handle, y)
776
782
  end
777
- return ____temp_1
783
+ return ____temp_2
778
784
  end
779
785
  function Unit.prototype.isAllyOf(self, unit)
780
786
  return isUnitAlly(
@@ -801,7 +807,7 @@ function Unit.prototype.queueAnimation(self, animation)
801
807
  queueUnitAnimation(self.handle, animation)
802
808
  end
803
809
  function Unit.prototype.delayHealthChecks(self)
804
- self[102] = (self[102] or 0) + 1
810
+ self[103] = (self[103] or 0) + 1
805
811
  Timer:run(delayHealthChecksCallback, self)
806
812
  end
807
813
  function Unit.prototype.setPosition(self, x, y)
@@ -817,8 +823,15 @@ end
817
823
  function Unit.prototype.kill(self)
818
824
  killUnit(self.handle)
819
825
  end
820
- function Unit.prototype.revive(self, pos, doEffect)
821
- ReviveHero(self.handle, pos.x, pos.y, doEffect)
826
+ function Unit.prototype.revive(self, x, y, doEffect)
827
+ local ____ReviveHero_5 = ReviveHero
828
+ local ____array_4 = __TS__SparseArrayNew(self.handle, x, y)
829
+ local ____doEffect_3 = doEffect
830
+ if ____doEffect_3 == nil then
831
+ ____doEffect_3 = false
832
+ end
833
+ __TS__SparseArrayPush(____array_4, ____doEffect_3)
834
+ ____ReviveHero_5(__TS__SparseArraySpread(____array_4))
822
835
  end
823
836
  function Unit.prototype.healTarget(self, target, amount)
824
837
  if __TS__InstanceOf(target, ____exports.Unit) and target:hasAbility(fourCC("BIhm")) then
@@ -858,7 +871,7 @@ function Unit.prototype.dropItemSlot(self, item, slot)
858
871
  return UnitDropItemSlot(self.handle, item.handle, slot)
859
872
  end
860
873
  function Unit.prototype.itemInSlot(self, slot)
861
- return Item:of(UnitItemInSlot(self.handle, slot))
874
+ return Item:of(unitItemInSlot(self.handle, slot))
862
875
  end
863
876
  function Unit.prototype.addAbility(self, abilityId)
864
877
  if unitAddAbility(self.handle, abilityId) then
@@ -988,18 +1001,18 @@ function Unit.prototype.unpauseEx(self)
988
1001
  self:decrementStunCounter()
989
1002
  end
990
1003
  function Unit.prototype.incrementStunCounter(self)
991
- local stunCounter = self[101] or 0
992
- if not self[100] or stunCounter >= 0 then
1004
+ local stunCounter = self[102] or 0
1005
+ if not self[101] or stunCounter >= 0 then
993
1006
  BlzPauseUnitEx(self.handle, true)
994
1007
  end
995
- self[101] = stunCounter + 1
1008
+ self[102] = stunCounter + 1
996
1009
  end
997
1010
  function Unit.prototype.decrementStunCounter(self)
998
- local stunCounter = self[101] or 0
999
- if not self[100] or stunCounter >= 1 then
1011
+ local stunCounter = self[102] or 0
1012
+ if not self[101] or stunCounter >= 1 then
1000
1013
  BlzPauseUnitEx(self.handle, false)
1001
1014
  end
1002
- self[101] = stunCounter - 1
1015
+ self[102] = stunCounter - 1
1003
1016
  end
1004
1017
  function Unit.create(self, owner, id, x, y, facing, skinId)
1005
1018
  local handle = skinId and BlzCreateUnitWithSkin(
@@ -1101,8 +1114,11 @@ function Unit.getInSector(self, pos, range, offsetAngle, centralAngle)
1101
1114
  )
1102
1115
  return targetCollection
1103
1116
  end
1104
- function Unit.getSelectionOf(self, player)
1105
- targetCollection = {}
1117
+ function Unit.getSelectionOf(self, player, target)
1118
+ if target == nil then
1119
+ target = {}
1120
+ end
1121
+ targetCollection = target
1106
1122
  targetCollectionNextIndex = 1
1107
1123
  GroupEnumUnitsSelected(dummyGroup, player.handle, collectIntoTarget)
1108
1124
  return targetCollection
@@ -1124,6 +1140,9 @@ end
1124
1140
  function Unit.prototype.__tostring(self)
1125
1141
  return (((self.constructor.name .. "$") .. util.id2s(self.typeId)) .. "@") .. tostring(getHandleId(self.handle))
1126
1142
  end
1143
+ function Unit.getBySyncId(self, syncId)
1144
+ return unitBySyncId[syncId]
1145
+ end
1127
1146
  __TS__SetDescriptor(
1128
1147
  Unit.prototype,
1129
1148
  "_deltas",
@@ -1381,17 +1400,17 @@ __TS__SetDescriptor(
1381
1400
  "isTeamGlowVisible",
1382
1401
  {
1383
1402
  get = function(self)
1384
- return not self[105]
1403
+ return not self[106]
1385
1404
  end,
1386
1405
  set = function(self, isTeamGlowVisible)
1387
1406
  showUnitTeamGlow(self.handle, isTeamGlowVisible)
1388
- local ____temp_2
1407
+ local ____temp_6
1389
1408
  if not isTeamGlowVisible then
1390
- ____temp_2 = true
1409
+ ____temp_6 = true
1391
1410
  else
1392
- ____temp_2 = nil
1411
+ ____temp_6 = nil
1393
1412
  end
1394
- self[105] = ____temp_2
1413
+ self[106] = ____temp_6
1395
1414
  end
1396
1415
  },
1397
1416
  true
@@ -1401,7 +1420,7 @@ __TS__SetDescriptor(
1401
1420
  "color",
1402
1421
  {set = function(self, color)
1403
1422
  setUnitColor(self.handle, color.handle)
1404
- if self[105] then
1423
+ if self[106] then
1405
1424
  showUnitTeamGlow(self.handle, false)
1406
1425
  end
1407
1426
  end},
@@ -1425,14 +1444,14 @@ __TS__SetDescriptor(
1425
1444
  "maxHealth",
1426
1445
  {
1427
1446
  get = function(self)
1428
- return BlzGetUnitMaxHP(self.handle) - (self[103] or 0) - (self[104] or 0)
1447
+ return BlzGetUnitMaxHP(self.handle) - (self[104] or 0) - (self[105] or 0)
1429
1448
  end,
1430
1449
  set = function(self, maxHealth)
1431
- if maxHealth < 1 and self[102] ~= nil then
1432
- self[103] = (self[103] or 0) + (1 - maxHealth)
1450
+ if maxHealth < 1 and self[103] ~= nil then
1451
+ self[104] = (self[104] or 0) + (1 - maxHealth)
1433
1452
  maxHealth = 1
1434
1453
  end
1435
- BlzSetUnitMaxHP(self.handle, maxHealth + (self[104] or 0))
1454
+ BlzSetUnitMaxHP(self.handle, maxHealth + (self[105] or 0))
1436
1455
  end
1437
1456
  },
1438
1457
  true
@@ -1474,10 +1493,10 @@ __TS__SetDescriptor(
1474
1493
  "health",
1475
1494
  {
1476
1495
  get = function(self)
1477
- return GetWidgetLife(self.handle) - (self[104] or 0)
1496
+ return GetWidgetLife(self.handle) - (self[105] or 0)
1478
1497
  end,
1479
1498
  set = function(self, health)
1480
- SetWidgetLife(self.handle, health + (self[104] or 0))
1499
+ SetWidgetLife(self.handle, health + (self[105] or 0))
1481
1500
  end
1482
1501
  },
1483
1502
  true
@@ -1688,17 +1707,17 @@ __TS__SetDescriptor(
1688
1707
  set = function(self, isPaused)
1689
1708
  local handle = self.handle
1690
1709
  if isPaused and not IsUnitPaused(handle) then
1691
- self[100] = true
1692
- for _ = self[101] or 0, -1 do
1710
+ self[101] = true
1711
+ for _ = self[102] or 0, -1 do
1693
1712
  BlzPauseUnitEx(handle, true)
1694
1713
  end
1695
1714
  PauseUnit(handle, true)
1696
1715
  elseif not isPaused and IsUnitPaused(handle) then
1697
1716
  PauseUnit(handle, false)
1698
- for _ = self[101] or 0, -1 do
1717
+ for _ = self[102] or 0, -1 do
1699
1718
  BlzPauseUnitEx(handle, false)
1700
1719
  end
1701
- self[100] = nil
1720
+ self[101] = nil
1702
1721
  end
1703
1722
  end
1704
1723
  },
@@ -2055,7 +2074,6 @@ Unit.onDecay = __TS__New(
2055
2074
  Unit.onResurrect = __TS__New(
2056
2075
  InitializingEvent,
2057
2076
  function(event)
2058
- local invoke = Event.invoke
2059
2077
  local dead = setmetatable({}, {__mode = "k"})
2060
2078
  ____exports.Unit.deathEvent:addListener(function(unit)
2061
2079
  dead[unit] = true
@@ -2071,10 +2089,15 @@ Unit.onResurrect = __TS__New(
2071
2089
  Unit.morphEvent = __TS__New(
2072
2090
  InitializingEvent,
2073
2091
  function(event)
2092
+ local function ifNotLeft(unit)
2093
+ local handle = unit.handle
2094
+ if getUnitAbilityLevel(handle, leaveDetectAbilityId) ~= 0 and unitAddAbility(handle, morphDetectAbilityId) then
2095
+ invoke(event, unit)
2096
+ end
2097
+ end
2074
2098
  ____exports.Unit.onImmediateOrder[orderId("undefend")]:addListener(function(unit)
2075
2099
  if getUnitAbilityLevel(unit.handle, morphDetectAbilityId) == 0 then
2076
- assert(unitAddAbility(unit.handle, morphDetectAbilityId))
2077
- Timer:run(Event.invoke, event, unit)
2100
+ Timer:run(ifNotLeft, unit)
2078
2101
  end
2079
2102
  end)
2080
2103
  end
@@ -2112,27 +2135,26 @@ Unit.onSpellEffect = dispatchId(__TS__New(
2112
2135
  Unit.onTargetCast = dispatchId(__TS__New(
2113
2136
  InitializingEvent,
2114
2137
  function(event)
2115
- local invoke = Event.invoke
2116
2138
  local function listener(unit, id)
2117
- local ____GetSpellTargetUnit_result_5
2139
+ local ____GetSpellTargetUnit_result_9
2118
2140
  if GetSpellTargetUnit() then
2119
- ____GetSpellTargetUnit_result_5 = ____exports.Unit:of(GetSpellTargetUnit())
2141
+ ____GetSpellTargetUnit_result_9 = ____exports.Unit:of(GetSpellTargetUnit())
2120
2142
  else
2121
- local ____GetSpellTargetItem_result_4
2143
+ local ____GetSpellTargetItem_result_8
2122
2144
  if GetSpellTargetItem() then
2123
- ____GetSpellTargetItem_result_4 = Item:of(GetSpellTargetItem())
2145
+ ____GetSpellTargetItem_result_8 = Item:of(GetSpellTargetItem())
2124
2146
  else
2125
- local ____GetSpellTargetDestructable_result_3
2147
+ local ____GetSpellTargetDestructable_result_7
2126
2148
  if GetSpellTargetDestructable() then
2127
- ____GetSpellTargetDestructable_result_3 = Destructable:of(GetSpellTargetDestructable())
2149
+ ____GetSpellTargetDestructable_result_7 = Destructable:of(GetSpellTargetDestructable())
2128
2150
  else
2129
- ____GetSpellTargetDestructable_result_3 = nil
2151
+ ____GetSpellTargetDestructable_result_7 = nil
2130
2152
  end
2131
- ____GetSpellTargetItem_result_4 = ____GetSpellTargetDestructable_result_3
2153
+ ____GetSpellTargetItem_result_8 = ____GetSpellTargetDestructable_result_7
2132
2154
  end
2133
- ____GetSpellTargetUnit_result_5 = ____GetSpellTargetItem_result_4
2155
+ ____GetSpellTargetUnit_result_9 = ____GetSpellTargetItem_result_8
2134
2156
  end
2135
- local target = ____GetSpellTargetUnit_result_5
2157
+ local target = ____GetSpellTargetUnit_result_9
2136
2158
  if target then
2137
2159
  invoke(event, unit, id, target)
2138
2160
  end
@@ -2329,7 +2351,6 @@ Unit.autoAttackStartEvent = __TS__New(
2329
2351
  )
2330
2352
  Unit.onDamaging = (function()
2331
2353
  local event = __TS__New(Event)
2332
- local invoke = Event.invoke
2333
2354
  local trigger = CreateTrigger()
2334
2355
  TriggerRegisterAnyUnitEventBJ(trigger, EVENT_PLAYER_UNIT_DAMAGING)
2335
2356
  TriggerAddCondition(
@@ -2428,7 +2449,6 @@ end)()
2428
2449
  Unit.onDamage = __TS__New(
2429
2450
  InitializingEvent,
2430
2451
  function(event)
2431
- local invoke = Event.invoke
2432
2452
  local trigger = CreateTrigger()
2433
2453
  TriggerRegisterAnyUnitEventBJ(trigger, EVENT_PLAYER_UNIT_DAMAGED)
2434
2454
  TriggerAddCondition(
@@ -2444,6 +2464,7 @@ Unit.onDamage = __TS__New(
2444
2464
  damageType = BlzGetEventDamageType(),
2445
2465
  weaponType = BlzGetEventWeaponType(),
2446
2466
  isAttack = BlzGetEventIsAttack(),
2467
+ originalAmount = GetEventDamage(),
2447
2468
  preventDeath = damageEventPreventDeath
2448
2469
  }
2449
2470
  local evData = setmetatable(
@@ -2460,7 +2481,7 @@ Unit.onDamage = __TS__New(
2460
2481
  invoke(event, source, target, evData)
2461
2482
  if evData[0] ~= nil and target.health - evData.amount < 0.405 then
2462
2483
  local bonusHealth = math.ceil(evData.amount)
2463
- target[104] = (target[104] or 0) + bonusHealth
2484
+ target[105] = (target[105] or 0) + bonusHealth
2464
2485
  BlzSetUnitMaxHP(
2465
2486
  target.handle,
2466
2487
  BlzGetUnitMaxHP(target.handle) + bonusHealth
@@ -2474,7 +2495,7 @@ Unit.onDamage = __TS__New(
2474
2495
  evData[0],
2475
2496
  table.unpack(evData, 1 + 1, 1 + (evData[1] or 0))
2476
2497
  )
2477
- target[104] = (target[104] or 0) - bonusHealth
2498
+ target[105] = (target[105] or 0) - bonusHealth
2478
2499
  SetWidgetLife(
2479
2500
  target.handle,
2480
2501
  GetWidgetLife(target.handle) - bonusHealth
@@ -2494,7 +2515,7 @@ Unit.onDamage = __TS__New(
2494
2515
  DestroyTrigger(trigger)
2495
2516
  end
2496
2517
  )
2497
- Unit.onItemDrop = __TS__New(
2518
+ Unit.itemDroppedEvent = __TS__New(
2498
2519
  ____exports.UnitTriggerEvent,
2499
2520
  EVENT_PLAYER_UNIT_DROP_ITEM,
2500
2521
  function()
@@ -2505,7 +2526,7 @@ Unit.onItemDrop = __TS__New(
2505
2526
  return IgnoreEvent
2506
2527
  end
2507
2528
  )
2508
- Unit.onItemPickup = __TS__New(
2529
+ Unit.itemPickedUpEvent = __TS__New(
2509
2530
  ____exports.UnitTriggerEvent,
2510
2531
  EVENT_PLAYER_UNIT_PICKUP_ITEM,
2511
2532
  function()
@@ -2516,10 +2537,15 @@ Unit.onItemPickup = __TS__New(
2516
2537
  return IgnoreEvent
2517
2538
  end
2518
2539
  )
2519
- Unit.onItemUse = __TS__New(
2540
+ Unit.itemUsedEvent = __TS__New(
2520
2541
  ____exports.UnitTriggerEvent,
2521
2542
  EVENT_PLAYER_UNIT_USE_ITEM,
2522
- function() return ____exports.Unit:of(GetTriggerUnit()), Item:of(GetManipulatedItem()) end
2543
+ function() return ____exports.Unit:of(getTriggerUnit()), Item:of(getManipulatedItem()) end
2544
+ )
2545
+ Unit.itemStackedEvent = __TS__New(
2546
+ ____exports.UnitTriggerEvent,
2547
+ EVENT_PLAYER_UNIT_STACK_ITEM,
2548
+ function() return ____exports.Unit:of(getTriggerUnit()), Item:of(getManipulatedItem()) end
2523
2549
  )
2524
2550
  __TS__ObjectDefineProperty(
2525
2551
  Unit,
@@ -1,7 +1,7 @@
1
1
  /** @noSelfInFile */
2
2
  import { Unit } from "../core/types/unit";
3
3
  import { Async } from "../core/types/async";
4
- import { TriggerEvent } from "../event";
4
+ import { Event, TriggerEvent } from "../event";
5
5
  import { GraphicsMode } from "./index";
6
6
  export declare class LocalClient {
7
7
  private constructor();
@@ -11,6 +11,11 @@ export declare class LocalClient {
11
11
  static get isHD(): boolean;
12
12
  static get graphicsMode(): GraphicsMode;
13
13
  static get isActive(): boolean;
14
- static get mouseFocusUnit(): Async<Unit>;
14
+ static get mouseFocusUnit(): Async<Unit> | undefined;
15
+ static get mainSelectedUnit(): Async<Unit> | undefined;
16
+ static get mainSelectedUnitChangeEvent(): Event<[
17
+ previousMainSelectedUnit: Unit | undefined,
18
+ newMainSelectedUnit: Unit | undefined
19
+ ]>;
15
20
  static readonly onDisconnect: TriggerEvent<[]>;
16
21
  }
@@ -1,4 +1,5 @@
1
1
  local ____lualib = require("lualib_bundle")
2
+ local __TS__ArrayMap = ____lualib.__TS__ArrayMap
2
3
  local __TS__Class = ____lualib.__TS__Class
3
4
  local __TS__ObjectDefineProperty = ____lualib.__TS__ObjectDefineProperty
4
5
  local __TS__New = ____lualib.__TS__New
@@ -6,13 +7,25 @@ local ____exports = {}
6
7
  local ____unit = require("core.types.unit")
7
8
  local Unit = ____unit.Unit
8
9
  local ____event = require("event")
10
+ local Event = ____event.Event
9
11
  local TriggerEvent = ____event.TriggerEvent
12
+ local ____frame = require("core.types.frame")
13
+ local Frame = ____frame.Frame
14
+ local ____player = require("core.types.player")
15
+ local Player = ____player.Player
16
+ local ____timer = require("core.types.timer")
17
+ local Timer = ____timer.Timer
10
18
  local loadTOCFile = BlzLoadTOCFile
11
19
  local getLocalClientWidth = BlzGetLocalClientWidth
12
20
  local getLocalClientHeight = BlzGetLocalClientHeight
13
21
  local isLocalClientActive = BlzIsLocalClientActive
22
+ local isHeroUnitId = IsHeroUnitId
23
+ local getHandleId = GetHandleId
14
24
  local getMouseFocusUnit = BlzGetMouseFocusUnit
25
+ local getUnitRealField = BlzGetUnitRealField
26
+ local getUnitTypeId = GetUnitTypeId
15
27
  local getLocale = BlzGetLocale
28
+ local tableSort = table.sort
16
29
  local tocPath = "_warscript\\IsHD.toc"
17
30
  compiletime(function()
18
31
  if currentMap then
@@ -21,6 +34,29 @@ compiletime(function()
21
34
  currentMap:addFileString("_HD.w3mod\\" .. tocPath, fdfPath .. "\r\n")
22
35
  end
23
36
  end)
37
+ local selectionButtons
38
+ Timer:run(function()
39
+ selectionButtons = __TS__ArrayMap(
40
+ Frame:byName("SimpleInfoPanelUnitDetail").parent:getChild(5):getChild(0).children,
41
+ function(____, frame) return frame:getChild(1) end
42
+ )
43
+ end)
44
+ local localSelectedUnits = {}
45
+ local indexByLocalSelectedUnit = {}
46
+ local function compareUnitsSelectionPriority(a, b)
47
+ local aHandle = a.handle
48
+ local bHandle = b.handle
49
+ local priorityDelta = getUnitRealField(bHandle, UNIT_RF_PRIORITY) - getUnitRealField(aHandle, UNIT_RF_PRIORITY)
50
+ if priorityDelta ~= 0 then
51
+ return priorityDelta < 0
52
+ end
53
+ local aTypeId = getUnitTypeId(aHandle)
54
+ local bTypeId = getUnitTypeId(bHandle)
55
+ local orderDelta = (isHeroUnitId(aTypeId) and getHandleId(aHandle) or aTypeId) - (isHeroUnitId(bTypeId) and getHandleId(bHandle) or bTypeId)
56
+ return (orderDelta ~= 0 and orderDelta or indexByLocalSelectedUnit[a] - indexByLocalSelectedUnit[b]) < 0
57
+ end
58
+ local mainSelectedUnitChangeEvent
59
+ local previousMainSelectedUnit
24
60
  ____exports.LocalClient = __TS__Class()
25
61
  local LocalClient = ____exports.LocalClient
26
62
  LocalClient.name = "LocalClient"
@@ -69,6 +105,52 @@ __TS__ObjectDefineProperty(
69
105
  return Unit:of(getMouseFocusUnit())
70
106
  end}
71
107
  )
108
+ __TS__ObjectDefineProperty(
109
+ LocalClient,
110
+ "mainSelectedUnit",
111
+ {get = function(self)
112
+ Unit:getSelectionOf(Player["local"], localSelectedUnits)
113
+ for i = 1, #localSelectedUnits do
114
+ indexByLocalSelectedUnit[localSelectedUnits[i]] = i
115
+ end
116
+ tableSort(localSelectedUnits, compareUnitsSelectionPriority)
117
+ local mainSelectedUnitIndex
118
+ if selectionButtons and #localSelectedUnits > 1 then
119
+ local maxButtonWidth = 0
120
+ for i = 0, #selectionButtons - 1 do
121
+ local width = selectionButtons[i + 1].width
122
+ if width > maxButtonWidth then
123
+ maxButtonWidth = width
124
+ mainSelectedUnitIndex = i
125
+ end
126
+ end
127
+ end
128
+ local mainSelectedUnit = localSelectedUnits[(mainSelectedUnitIndex or 0) + 1]
129
+ for i = 1, #localSelectedUnits do
130
+ indexByLocalSelectedUnit[localSelectedUnits[i]] = nil
131
+ localSelectedUnits[i] = nil
132
+ end
133
+ if mainSelectedUnitChangeEvent ~= nil and mainSelectedUnit ~= previousMainSelectedUnit then
134
+ local previousPreviousMainSelectedUnit = previousMainSelectedUnit
135
+ previousMainSelectedUnit = mainSelectedUnit
136
+ Event.invoke(mainSelectedUnitChangeEvent, previousPreviousMainSelectedUnit, previousMainSelectedUnit)
137
+ end
138
+ return mainSelectedUnit
139
+ end}
140
+ )
141
+ __TS__ObjectDefineProperty(
142
+ LocalClient,
143
+ "mainSelectedUnitChangeEvent",
144
+ {get = function(self)
145
+ if mainSelectedUnitChangeEvent == nil then
146
+ mainSelectedUnitChangeEvent = __TS__New(Event)
147
+ Timer.onPeriod[1 / 64]:addListener(function()
148
+ local _ = ____exports.LocalClient.mainSelectedUnit
149
+ end)
150
+ end
151
+ return mainSelectedUnitChangeEvent
152
+ end}
153
+ )
72
154
  LocalClient.onDisconnect = __TS__New(
73
155
  TriggerEvent,
74
156
  function(trigger)
@@ -1,4 +1,3 @@
1
- /// <reference types="@typescript-to-lua/language-extensions" />
2
1
  /** @noSelfInFile */
3
2
  import { ModelNodeName } from "./model-node-name";
4
3
  import { ModelNodeQualifier } from "./model-node-qualifier";
@@ -1,5 +1,3 @@
1
- /// <reference types="@warscript/language-extensions" />
2
- /// <reference types="@typescript-to-lua/language-extensions" />
3
1
  /** @noSelfInFile */
4
2
  export declare const enum CombatClassification {
5
3
  NONE = 1,// 2^0
@@ -1,4 +1,3 @@
1
- /// <reference types="warpack-types/warpack" />
2
1
  /** @noSelfInFile */
3
2
  import { ChannelAbilityType, ChannelAbilityTypeTargetingType } from "./channel";
4
3
  import { ObjectDataEntryLevelFieldValueSupplier } from "../../entry";
@@ -1,4 +1,3 @@
1
- /// <reference types="warpack-types/warpack" />
2
1
  /** @noSelfInFile */
3
2
  import { DiseaseCloudAbilityType } from "./disease-cloud";
4
3
  export declare class BlankPassiveAbilityType extends DiseaseCloudAbilityType {
@@ -1,4 +1,3 @@
1
- /// <reference types="warpack-types/warpack" />
2
1
  /** @noSelfInFile */
3
2
  import { AbilityType, AbilityTypeId } from "../ability-type";
4
3
  import { ObjectDataEntryLevelFieldValueSupplier } from "../../entry";
@@ -1,4 +1,3 @@
1
- /// <reference types="warpack-types/warpack" />
2
1
  /** @noSelfInFile */
3
2
  import "../../internal/unit/ability";
4
3
  import { TupleOf } from "../../../utility/types";
@@ -1,4 +1,3 @@
1
- /// <reference types="warpack-types/warpack" />
2
1
  /** @noSelfInFile */
3
2
  import { BuffPolarity } from "../../auxiliary/buff-polarity";
4
3
  import { BuffResistanceType } from "../../auxiliary/buff-resistance-type";
@@ -1,4 +1,3 @@
1
- /// <reference types="warpack-types/warpack" />
2
1
  /** @noSelfInFile */
3
2
  import { BuffType, BuffTypeId } from "../buff-type";
4
3
  export declare class BlankBuffType extends BuffType {
@@ -1,4 +1,3 @@
1
- /// <reference types="warpack-types/warpack" />
2
1
  /** @noSelfInFile */
3
2
  import { TupleOf } from "../../../utility/types";
4
3
  import { AttachmentPreset, AttachmentPresetInput } from "../auxiliary/attachment-preset";
@@ -1,4 +1,3 @@
1
- /// <reference types="warpack-types/warpack" />
2
1
  /** @noSelfInFile */
3
2
  import { ArmorSoundType } from "../auxiliary/armor-sound-type";
4
3
  import { CombatClassifications } from "../auxiliary/combat-classification";
@@ -1,4 +1,3 @@
1
- /// <reference types="warpack-types/warpack" />
2
1
  /** @noSelfInFile */
3
2
  import { ItemType, ItemTypeId } from "../item-type";
4
3
  export declare class BlankItemType extends ItemType {
@@ -1,4 +1,3 @@
1
- /// <reference types="warpack-types/warpack" />
2
1
  /** @noSelfInFile */
3
2
  import { ArmorSoundType } from "../auxiliary/armor-sound-type";
4
3
  import { ObjectDataEntry, ObjectDataEntryId } from "../entry";
@@ -46,4 +45,16 @@ export declare class ItemType extends ObjectDataEntry<ItemTypeId> {
46
45
  set tooltipText(tooltipText: string);
47
46
  get tooltipExtendedText(): string;
48
47
  set tooltipExtendedText(tooltipText: string);
48
+ get goldCost(): number;
49
+ set goldCost(goldCost: number);
50
+ get lumberCost(): number;
51
+ set lumberCost(lumberCost: number);
52
+ get activelyUsed(): boolean;
53
+ set activelyUsed(activelyUsed: boolean);
54
+ get perishable(): boolean;
55
+ set perishable(perishable: boolean);
56
+ get initialStackSize(): number;
57
+ set initialStackSize(initialStackSize: number);
58
+ get maximumStackSize(): number;
59
+ set maximumStackSize(maximumStackSize: number);
49
60
  }