warscript 0.0.1-dev.ec4cf89 → 0.0.1-dev.ed60fea

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 (76) hide show
  1. package/core/types/effect.d.ts +13 -3
  2. package/core/types/effect.lua +116 -17
  3. package/core/types/frame.d.ts +6 -0
  4. package/core/types/frame.lua +91 -1
  5. package/core/util.d.ts +1 -1
  6. package/core/util.lua +12 -0
  7. package/engine/behavior.d.ts +2 -2
  8. package/engine/behavior.lua +6 -6
  9. package/engine/behaviour/ability/always-enabled.d.ts +7 -0
  10. package/engine/behaviour/ability/always-enabled.lua +31 -0
  11. package/engine/behaviour/ability/apply-buff.d.ts +3 -5
  12. package/engine/behaviour/ability/emulate-impact.d.ts +6 -0
  13. package/engine/behaviour/ability/emulate-impact.lua +28 -0
  14. package/engine/behaviour/ability/instant-impact.d.ts +2 -2
  15. package/engine/behaviour/ability/instant-impact.lua +4 -19
  16. package/engine/behaviour/ability/on-command-impact.d.ts +8 -0
  17. package/engine/behaviour/ability/on-command-impact.lua +25 -0
  18. package/engine/behaviour/ability/remove-buffs.d.ts +16 -0
  19. package/engine/behaviour/ability/remove-buffs.lua +28 -0
  20. package/engine/behaviour/ability.d.ts +14 -3
  21. package/engine/behaviour/ability.lua +79 -33
  22. package/engine/behaviour/unit.d.ts +5 -0
  23. package/engine/behaviour/unit.lua +20 -0
  24. package/engine/buff.d.ts +38 -12
  25. package/engine/buff.lua +171 -79
  26. package/engine/internal/ability.d.ts +16 -13
  27. package/engine/internal/ability.lua +82 -76
  28. package/engine/internal/item/ability.lua +90 -0
  29. package/engine/internal/item+owner.lua +2 -2
  30. package/engine/internal/misc/ability-disable-counter.d.ts +2 -0
  31. package/engine/internal/misc/ability-disable-counter.lua +13 -0
  32. package/engine/internal/unit/ability.d.ts +10 -1
  33. package/engine/internal/unit/ability.lua +36 -14
  34. package/engine/internal/unit/bonus.d.ts +4 -2
  35. package/engine/internal/unit/bonus.lua +6 -1
  36. package/engine/internal/unit/item.d.ts +24 -0
  37. package/engine/internal/unit/item.lua +79 -0
  38. package/engine/internal/unit/main-selected.d.ts +13 -0
  39. package/engine/internal/unit/main-selected.lua +51 -0
  40. package/engine/internal/unit+ability.lua +2 -2
  41. package/engine/internal/unit-missile-launch.lua +24 -5
  42. package/engine/internal/unit.d.ts +25 -10
  43. package/engine/internal/unit.lua +144 -77
  44. package/engine/internal/utility.lua +12 -0
  45. package/engine/local-client.d.ts +7 -2
  46. package/engine/local-client.lua +82 -0
  47. package/engine/object-data/auxiliary/sound-preset-name.d.ts +5 -1
  48. package/engine/object-data/entry/ability-type.lua +8 -12
  49. package/engine/object-data/entry/item-type.d.ts +14 -0
  50. package/engine/object-data/entry/item-type.lua +91 -0
  51. package/engine/object-data/utility/object-data-entry-id-generator.lua +7 -0
  52. package/engine/object-field/ability.d.ts +26 -3
  53. package/engine/object-field/ability.lua +54 -1
  54. package/engine/object-field.d.ts +2 -2
  55. package/engine/object-field.lua +4 -0
  56. package/engine/standard/fields/ability.d.ts +2 -0
  57. package/engine/standard/fields/ability.lua +2 -0
  58. package/engine/unit.d.ts +2 -0
  59. package/engine/unit.lua +2 -0
  60. package/index.d.ts +1 -0
  61. package/index.lua +1 -0
  62. package/net/socket.d.ts +7 -1
  63. package/net/socket.lua +45 -4
  64. package/network.d.ts +1 -0
  65. package/network.lua +3 -2
  66. package/objutil/buff.lua +1 -1
  67. package/package.json +2 -2
  68. package/patch-lua.d.ts +0 -0
  69. package/patch-lua.lua +10 -0
  70. package/utility/arrays.d.ts +8 -1
  71. package/utility/arrays.lua +34 -3
  72. package/utility/lazy.d.ts +2 -0
  73. package/utility/lazy.lua +14 -0
  74. package/utility/linked-set.d.ts +11 -2
  75. package/utility/linked-set.lua +5 -2
  76. package/utility/types.d.ts +1 -0
@@ -0,0 +1,51 @@
1
+ local ____lualib = require("lualib_bundle")
2
+ local __TS__New = ____lualib.__TS__New
3
+ local ____exports = {}
4
+ local ____player = require("core.types.player")
5
+ local Player = ____player.Player
6
+ local ____math = require("math")
7
+ local MAXIMUM_INTEGER = ____math.MAXIMUM_INTEGER
8
+ local MINIMUM_INTEGER = ____math.MINIMUM_INTEGER
9
+ local ____local_2Dclient = require("engine.local-client")
10
+ local LocalClient = ____local_2Dclient.LocalClient
11
+ local ____unit = require("engine.internal.unit")
12
+ local Unit = ____unit.Unit
13
+ local ____event = require("event")
14
+ local Event = ____event.Event
15
+ local mainSelectedUnitChangeEvent = __TS__New(Event)
16
+ rawset(Unit, "mainSelectedUnitChangeEvent", mainSelectedUnitChangeEvent)
17
+ local mainSelectedUnitByPlayer = {}
18
+ local syncSlider = BlzCreateFrameByType(
19
+ "SLIDER",
20
+ "UnitSyncId",
21
+ BlzGetOriginFrame(ORIGIN_FRAME_WORLD_FRAME, 0),
22
+ "",
23
+ 0
24
+ )
25
+ BlzFrameSetMinMaxValue(syncSlider, MINIMUM_INTEGER, MAXIMUM_INTEGER)
26
+ LocalClient.mainSelectedUnitChangeEvent:addListener(function()
27
+ local ____opt_0 = LocalClient.mainSelectedUnit
28
+ local syncId = ____opt_0 and ____opt_0.syncId
29
+ BlzFrameSetValue(syncSlider, syncId or 0)
30
+ end)
31
+ local trg = CreateTrigger()
32
+ BlzTriggerRegisterFrameEvent(trg, syncSlider, FRAMEEVENT_SLIDER_VALUE_CHANGED)
33
+ TriggerAddAction(
34
+ trg,
35
+ function()
36
+ local player = Player:of(GetTriggerPlayer())
37
+ local mainSelectedUnit = Unit:getBySyncId(BlzGetTriggerFrameValue())
38
+ if mainSelectedUnit ~= mainSelectedUnitByPlayer[player] then
39
+ mainSelectedUnitByPlayer[player] = mainSelectedUnit
40
+ Event.invoke(mainSelectedUnitChangeEvent, player)
41
+ end
42
+ end
43
+ )
44
+ rawset(
45
+ Unit,
46
+ "getMainSelectedOf",
47
+ function(player)
48
+ return mainSelectedUnitByPlayer[player]
49
+ end
50
+ )
51
+ return ____exports
@@ -40,7 +40,7 @@ ItemAbility.onCreate:addListener(
40
40
  end
41
41
  end
42
42
  )
43
- Unit.onItemPickup:addListener(
43
+ Unit.itemPickedUpEvent:addListener(
44
44
  0,
45
45
  function(unit, item)
46
46
  for ____, ability in ipairs(item.abilities) do
@@ -48,7 +48,7 @@ Unit.onItemPickup:addListener(
48
48
  end
49
49
  end
50
50
  )
51
- Unit.onItemDrop:addListener(
51
+ Unit.itemDroppedEvent:addListener(
52
52
  4,
53
53
  function(unit, item)
54
54
  for ____, ability in ipairs(item.abilities) do
@@ -7,14 +7,33 @@ local ____event = require("event")
7
7
  local Event = ____event.Event
8
8
  local ____timer = require("core.types.timer")
9
9
  local Timer = ____timer.Timer
10
+ local ____lua_2Dsets = require("utility.lua-sets")
11
+ local luaSetOf = ____lua_2Dsets.luaSetOf
10
12
  local autoAttackFinishEvent = __TS__New(Event)
11
13
  rawset(Unit, "autoAttackFinishEvent", autoAttackFinishEvent)
12
14
  local eventTimerByUnit = {}
13
- local function reset(source)
14
- local eventTimer = eventTimerByUnit[source]
15
- if eventTimer then
16
- eventTimer:destroy()
17
- eventTimerByUnit[source] = nil
15
+ local instantOrderIds = luaSetOf(
16
+ orderId("avatar"),
17
+ orderId("berserk"),
18
+ orderId("divineshield"),
19
+ orderId("immolation"),
20
+ orderId("moveslot0"),
21
+ orderId("moveslot1"),
22
+ orderId("moveslot2"),
23
+ orderId("moveslot3"),
24
+ orderId("moveslot4"),
25
+ orderId("moveslot5"),
26
+ orderId("unavatar"),
27
+ orderId("undivineshield"),
28
+ orderId("unimmolation")
29
+ )
30
+ local function reset(source, orderId)
31
+ if not (instantOrderIds[orderId] ~= nil) then
32
+ local eventTimer = eventTimerByUnit[source]
33
+ if eventTimer then
34
+ eventTimer:destroy()
35
+ eventTimerByUnit[source] = nil
36
+ end
18
37
  end
19
38
  end
20
39
  Unit.onImmediateOrder:addListener(reset)
@@ -42,6 +42,7 @@ export interface DamagingEvent {
42
42
  damageType: jdamagetype;
43
43
  weaponType: jweapontype;
44
44
  readonly isAttack: boolean;
45
+ readonly originalAmount: number;
45
46
  }
46
47
  export type DamageEvent = DamagingEvent & {
47
48
  preventDeath<P extends any[]>(this: DamageEvent, callback: (this: void, ...parameters: P) => any, ...parameters: P): void;
@@ -93,14 +94,19 @@ export declare class UnitWeapon {
93
94
  set missileSpeed(missileSpeed: number);
94
95
  }
95
96
  declare const enum UnitPropertyKey {
96
- IS_PAUSED = 100,
97
- STUN_COUNTER = 101,
98
- DELAY_HEALTH_CHECKS_COUNTER = 102,
99
- DELAY_HEALTH_CHECKS_HEALTH_BONUS = 103,
100
- PREVENT_DEATH_HEALTH_BONUS = 104,
101
- IS_TEAM_GLOW_HIDDEN = 105
97
+ SYNC_ID = 100,
98
+ IS_PAUSED = 101,
99
+ STUN_COUNTER = 102,
100
+ DELAY_HEALTH_CHECKS_COUNTER = 103,
101
+ DELAY_HEALTH_CHECKS_HEALTH_BONUS = 104,
102
+ PREVENT_DEATH_HEALTH_BONUS = 105,
103
+ IS_TEAM_GLOW_HIDDEN = 106
102
104
  }
105
+ export type UnitSyncId = number & {
106
+ readonly __unitSyncId: unique symbol;
107
+ };
103
108
  export declare class Unit extends Handle<junit> {
109
+ readonly syncId: UnitSyncId;
104
110
  private [UnitPropertyKey.IS_PAUSED]?;
105
111
  private [UnitPropertyKey.STUN_COUNTER]?;
106
112
  private [UnitPropertyKey.DELAY_HEALTH_CHECKS_COUNTER]?;
@@ -287,7 +293,7 @@ export declare class Unit extends Handle<junit> {
287
293
  static getInRange(x: number, y: number, range: number, predicate?: (unit: Unit) => boolean): Unit[];
288
294
  static getInCollisionRange(x: number, y: number, range: number, predicate?: (unit: Unit) => boolean): Unit[];
289
295
  static getInSector(pos: Vec2, range: number, offsetAngle: number, centralAngle: number): Unit[];
290
- static getSelectionOf(player: Player): Unit[];
296
+ static getSelectionOf(player: Player, target?: Unit[]): Unit[];
291
297
  static readonly deathEvent: UnitTriggerEvent<[Unit]>;
292
298
  static readonly onDecay: UnitTriggerEvent<[]>;
293
299
  static readonly onResurrect: InitializingEvent<[Unit], void>;
@@ -322,9 +328,17 @@ export declare class Unit extends Handle<junit> {
322
328
  static readonly autoAttackStartEvent: UnitTriggerEvent<[Unit]>;
323
329
  static readonly onDamaging: Event<[source: Unit | undefined, target: Unit, event: DamagingEvent]>;
324
330
  static readonly onDamage: InitializingEvent<[source: Unit | undefined, target: Unit, event: DamageEvent], jtrigger>;
325
- static onItemDrop: UnitTriggerEvent<[Item]>;
326
- static onItemPickup: UnitTriggerEvent<[Item]>;
327
- static onItemUse: UnitTriggerEvent<[Item]>;
331
+ static itemDroppedEvent: UnitTriggerEvent<[Item]>;
332
+ static itemPickedUpEvent: UnitTriggerEvent<[Item]>;
333
+ static itemUsedEvent: UnitTriggerEvent<[Item]>;
334
+ static itemStackedEvent: UnitTriggerEvent<[Item]>;
335
+ static get itemUseOrderEvent(): Event<[unit: Unit, item: Item]>;
336
+ static get itemMoveOrderEvent(): Event<[
337
+ unit: Unit,
338
+ item: Item,
339
+ slotFrom: 0 | 1 | 2 | 3 | 4 | 5,
340
+ slotTo: 0 | 1 | 2 | 3 | 4 | 5
341
+ ]>;
328
342
  static get onCreate(): EventDispatcher<[Unit], [Unit]>;
329
343
  static get destroyEvent(): EventDispatcher<[Unit], [Unit]>;
330
344
  getField(field: junitintegerfield | junitrealfield): number;
@@ -335,5 +349,6 @@ export declare class Unit extends Handle<junit> {
335
349
  setField(field: junitbooleanfield, value: boolean): boolean;
336
350
  setField(field: junitstringfield, value: string): boolean;
337
351
  toString(): string;
352
+ static getBySyncId(syncId: UnitSyncId): Unit | undefined;
338
353
  }
339
354
  export {};
@@ -562,17 +562,6 @@ local function retrieveAbility(unit, ability, abilityId)
562
562
  ____exports.Unit:of(unit)
563
563
  )
564
564
  end
565
- if not unitAddAbility(unit, abilityId) then
566
- if getUnitAbility(unit, abilityId) == ability then
567
- return UnitAbility:of(
568
- ability,
569
- abilityId,
570
- ____exports.Unit:of(unit)
571
- )
572
- end
573
- else
574
- unitRemoveAbility(unit, abilityId)
575
- end
576
565
  for i = 0, unitInventorySize(unit) - 1 do
577
566
  local item = unitItemInSlot(unit, i)
578
567
  if getItemAbility(item, abilityId) == ability then
@@ -630,15 +619,15 @@ for ____, player in ipairs(Player.all) do
630
619
  dummies[player] = dummy
631
620
  end
632
621
  local function delayHealthChecksCallback(unit)
633
- local counter = (unit[102] or 0) - 1
622
+ local counter = (unit[103] or 0) - 1
634
623
  if counter ~= 0 then
635
- unit[102] = counter
624
+ unit[103] = counter
636
625
  return
637
626
  end
638
- unit[102] = nil
639
- local healthBonus = unit[103]
627
+ unit[103] = nil
628
+ local healthBonus = unit[104]
640
629
  if healthBonus ~= nil then
641
- unit[103] = nil
630
+ unit[104] = nil
642
631
  local handle = unit.handle
643
632
  BlzSetUnitMaxHP(
644
633
  handle,
@@ -646,12 +635,17 @@ local function delayHealthChecksCallback(unit)
646
635
  )
647
636
  end
648
637
  end
638
+ local nextSyncId = 1
639
+ local unitBySyncId = setmetatable({}, {__mode = "k"})
649
640
  ____exports.Unit = __TS__Class()
650
641
  local Unit = ____exports.Unit
651
642
  Unit.name = "Unit"
652
643
  __TS__ClassExtends(Unit, Handle)
653
644
  function Unit.prototype.____constructor(self, handle)
654
645
  Handle.prototype.____constructor(self, handle)
646
+ local ____nextSyncId_0 = nextSyncId
647
+ nextSyncId = ____nextSyncId_0 + 1
648
+ self.syncId = ____nextSyncId_0
655
649
  self._owner = Player:of(getOwningPlayer(handle))
656
650
  assert(unitAddAbility(handle, leaveDetectAbilityId) and UnitMakeAbilityPermanent(handle, true, leaveDetectAbilityId))
657
651
  assert(unitAddAbility(handle, morphDetectAbilityId))
@@ -664,6 +658,7 @@ function Unit.prototype.____constructor(self, handle)
664
658
  fourCC("Amrf")
665
659
  ))
666
660
  end
661
+ unitBySyncId[self.syncId] = self
667
662
  local ____ = self.abilities
668
663
  end
669
664
  function Unit.prototype.getEvent(self, event, collector)
@@ -749,8 +744,8 @@ function Unit.prototype.addModifier(self, property, modifier)
749
744
  end}
750
745
  end
751
746
  function Unit.prototype.hasCombatClassification(self, combatClassification)
752
- local ____combatClassification_0 = combatClassification
753
- return getUnitIntegerField(self.handle, UNIT_IF_TARGETED_AS) & ____combatClassification_0 == ____combatClassification_0
747
+ local ____combatClassification_1 = combatClassification
748
+ return getUnitIntegerField(self.handle, UNIT_IF_TARGETED_AS) & ____combatClassification_1 == ____combatClassification_1
754
749
  end
755
750
  function Unit.prototype.addClassification(self, classification)
756
751
  return unitAddType(self.handle, classification)
@@ -768,13 +763,13 @@ function Unit.prototype.isInvisibleTo(self, player)
768
763
  return isUnitInvisible(self.handle, player.handle)
769
764
  end
770
765
  function Unit.prototype.isInRangeOf(self, x, y, range)
771
- local ____temp_1
766
+ local ____temp_2
772
767
  if type(x) == "number" then
773
- ____temp_1 = isUnitInRangeXY(self.handle, x, y, range)
768
+ ____temp_2 = isUnitInRangeXY(self.handle, x, y, range)
774
769
  else
775
- ____temp_1 = isUnitInRange(self.handle, x.handle, y)
770
+ ____temp_2 = isUnitInRange(self.handle, x.handle, y)
776
771
  end
777
- return ____temp_1
772
+ return ____temp_2
778
773
  end
779
774
  function Unit.prototype.isAllyOf(self, unit)
780
775
  return isUnitAlly(
@@ -801,7 +796,7 @@ function Unit.prototype.queueAnimation(self, animation)
801
796
  queueUnitAnimation(self.handle, animation)
802
797
  end
803
798
  function Unit.prototype.delayHealthChecks(self)
804
- self[102] = (self[102] or 0) + 1
799
+ self[103] = (self[103] or 0) + 1
805
800
  Timer:run(delayHealthChecksCallback, self)
806
801
  end
807
802
  function Unit.prototype.setPosition(self, x, y)
@@ -818,14 +813,14 @@ function Unit.prototype.kill(self)
818
813
  killUnit(self.handle)
819
814
  end
820
815
  function Unit.prototype.revive(self, x, y, doEffect)
821
- local ____ReviveHero_4 = ReviveHero
822
- local ____array_3 = __TS__SparseArrayNew(self.handle, x, y)
823
- local ____doEffect_2 = doEffect
824
- if ____doEffect_2 == nil then
825
- ____doEffect_2 = false
816
+ local ____ReviveHero_5 = ReviveHero
817
+ local ____array_4 = __TS__SparseArrayNew(self.handle, x, y)
818
+ local ____doEffect_3 = doEffect
819
+ if ____doEffect_3 == nil then
820
+ ____doEffect_3 = false
826
821
  end
827
- __TS__SparseArrayPush(____array_3, ____doEffect_2)
828
- ____ReviveHero_4(__TS__SparseArraySpread(____array_3))
822
+ __TS__SparseArrayPush(____array_4, ____doEffect_3)
823
+ ____ReviveHero_5(__TS__SparseArraySpread(____array_4))
829
824
  end
830
825
  function Unit.prototype.healTarget(self, target, amount)
831
826
  if __TS__InstanceOf(target, ____exports.Unit) and target:hasAbility(fourCC("BIhm")) then
@@ -865,7 +860,7 @@ function Unit.prototype.dropItemSlot(self, item, slot)
865
860
  return UnitDropItemSlot(self.handle, item.handle, slot)
866
861
  end
867
862
  function Unit.prototype.itemInSlot(self, slot)
868
- return Item:of(UnitItemInSlot(self.handle, slot))
863
+ return Item:of(unitItemInSlot(self.handle, slot))
869
864
  end
870
865
  function Unit.prototype.addAbility(self, abilityId)
871
866
  if unitAddAbility(self.handle, abilityId) then
@@ -934,8 +929,15 @@ function Unit.prototype.interruptAttack(self)
934
929
  unitInterruptAttack(self.handle)
935
930
  end
936
931
  function Unit.prototype.interruptCast(self, abilityId)
937
- unitDisableAbility(self.handle, abilityId, true, false)
938
- unitDisableAbility(self.handle, abilityId, false, false)
932
+ local handle = self.handle
933
+ unitDisableAbility(handle, abilityId, true, false)
934
+ Timer:run(
935
+ unitDisableAbility,
936
+ handle,
937
+ abilityId,
938
+ false,
939
+ false
940
+ )
939
941
  end
940
942
  function Unit.prototype.getDistanceTo(self, target)
941
943
  local handle = self.handle
@@ -995,18 +997,18 @@ function Unit.prototype.unpauseEx(self)
995
997
  self:decrementStunCounter()
996
998
  end
997
999
  function Unit.prototype.incrementStunCounter(self)
998
- local stunCounter = self[101] or 0
999
- if not self[100] or stunCounter >= 0 then
1000
+ local stunCounter = self[102] or 0
1001
+ if not self[101] or stunCounter >= 0 then
1000
1002
  BlzPauseUnitEx(self.handle, true)
1001
1003
  end
1002
- self[101] = stunCounter + 1
1004
+ self[102] = stunCounter + 1
1003
1005
  end
1004
1006
  function Unit.prototype.decrementStunCounter(self)
1005
- local stunCounter = self[101] or 0
1006
- if not self[100] or stunCounter >= 1 then
1007
+ local stunCounter = self[102] or 0
1008
+ if not self[101] or stunCounter >= 1 then
1007
1009
  BlzPauseUnitEx(self.handle, false)
1008
1010
  end
1009
- self[101] = stunCounter - 1
1011
+ self[102] = stunCounter - 1
1010
1012
  end
1011
1013
  function Unit.create(self, owner, id, x, y, facing, skinId)
1012
1014
  local handle = skinId and BlzCreateUnitWithSkin(
@@ -1108,8 +1110,11 @@ function Unit.getInSector(self, pos, range, offsetAngle, centralAngle)
1108
1110
  )
1109
1111
  return targetCollection
1110
1112
  end
1111
- function Unit.getSelectionOf(self, player)
1112
- targetCollection = {}
1113
+ function Unit.getSelectionOf(self, player, target)
1114
+ if target == nil then
1115
+ target = {}
1116
+ end
1117
+ targetCollection = target
1113
1118
  targetCollectionNextIndex = 1
1114
1119
  GroupEnumUnitsSelected(dummyGroup, player.handle, collectIntoTarget)
1115
1120
  return targetCollection
@@ -1131,6 +1136,9 @@ end
1131
1136
  function Unit.prototype.__tostring(self)
1132
1137
  return (((self.constructor.name .. "$") .. util.id2s(self.typeId)) .. "@") .. tostring(getHandleId(self.handle))
1133
1138
  end
1139
+ function Unit.getBySyncId(self, syncId)
1140
+ return unitBySyncId[syncId]
1141
+ end
1134
1142
  __TS__SetDescriptor(
1135
1143
  Unit.prototype,
1136
1144
  "_deltas",
@@ -1388,17 +1396,17 @@ __TS__SetDescriptor(
1388
1396
  "isTeamGlowVisible",
1389
1397
  {
1390
1398
  get = function(self)
1391
- return not self[105]
1399
+ return not self[106]
1392
1400
  end,
1393
1401
  set = function(self, isTeamGlowVisible)
1394
1402
  showUnitTeamGlow(self.handle, isTeamGlowVisible)
1395
- local ____temp_5
1403
+ local ____temp_6
1396
1404
  if not isTeamGlowVisible then
1397
- ____temp_5 = true
1405
+ ____temp_6 = true
1398
1406
  else
1399
- ____temp_5 = nil
1407
+ ____temp_6 = nil
1400
1408
  end
1401
- self[105] = ____temp_5
1409
+ self[106] = ____temp_6
1402
1410
  end
1403
1411
  },
1404
1412
  true
@@ -1408,7 +1416,7 @@ __TS__SetDescriptor(
1408
1416
  "color",
1409
1417
  {set = function(self, color)
1410
1418
  setUnitColor(self.handle, color.handle)
1411
- if self[105] then
1419
+ if self[106] then
1412
1420
  showUnitTeamGlow(self.handle, false)
1413
1421
  end
1414
1422
  end},
@@ -1432,14 +1440,14 @@ __TS__SetDescriptor(
1432
1440
  "maxHealth",
1433
1441
  {
1434
1442
  get = function(self)
1435
- return BlzGetUnitMaxHP(self.handle) - (self[103] or 0) - (self[104] or 0)
1443
+ return BlzGetUnitMaxHP(self.handle) - (self[104] or 0) - (self[105] or 0)
1436
1444
  end,
1437
1445
  set = function(self, maxHealth)
1438
- if maxHealth < 1 and self[102] ~= nil then
1439
- self[103] = (self[103] or 0) + (1 - maxHealth)
1446
+ if maxHealth < 1 and self[103] ~= nil then
1447
+ self[104] = (self[104] or 0) + (1 - maxHealth)
1440
1448
  maxHealth = 1
1441
1449
  end
1442
- BlzSetUnitMaxHP(self.handle, maxHealth + (self[104] or 0))
1450
+ BlzSetUnitMaxHP(self.handle, maxHealth + (self[105] or 0))
1443
1451
  end
1444
1452
  },
1445
1453
  true
@@ -1481,10 +1489,10 @@ __TS__SetDescriptor(
1481
1489
  "health",
1482
1490
  {
1483
1491
  get = function(self)
1484
- return GetWidgetLife(self.handle) - (self[104] or 0)
1492
+ return GetWidgetLife(self.handle) - (self[105] or 0)
1485
1493
  end,
1486
1494
  set = function(self, health)
1487
- SetWidgetLife(self.handle, health + (self[104] or 0))
1495
+ SetWidgetLife(self.handle, health + (self[105] or 0))
1488
1496
  end
1489
1497
  },
1490
1498
  true
@@ -1695,17 +1703,17 @@ __TS__SetDescriptor(
1695
1703
  set = function(self, isPaused)
1696
1704
  local handle = self.handle
1697
1705
  if isPaused and not IsUnitPaused(handle) then
1698
- self[100] = true
1699
- for _ = self[101] or 0, -1 do
1706
+ self[101] = true
1707
+ for _ = self[102] or 0, -1 do
1700
1708
  BlzPauseUnitEx(handle, true)
1701
1709
  end
1702
1710
  PauseUnit(handle, true)
1703
1711
  elseif not isPaused and IsUnitPaused(handle) then
1704
1712
  PauseUnit(handle, false)
1705
- for _ = self[101] or 0, -1 do
1713
+ for _ = self[102] or 0, -1 do
1706
1714
  BlzPauseUnitEx(handle, false)
1707
1715
  end
1708
- self[100] = nil
1716
+ self[101] = nil
1709
1717
  end
1710
1718
  end
1711
1719
  },
@@ -2124,25 +2132,25 @@ Unit.onTargetCast = dispatchId(__TS__New(
2124
2132
  InitializingEvent,
2125
2133
  function(event)
2126
2134
  local function listener(unit, id)
2127
- local ____GetSpellTargetUnit_result_8
2135
+ local ____GetSpellTargetUnit_result_9
2128
2136
  if GetSpellTargetUnit() then
2129
- ____GetSpellTargetUnit_result_8 = ____exports.Unit:of(GetSpellTargetUnit())
2137
+ ____GetSpellTargetUnit_result_9 = ____exports.Unit:of(GetSpellTargetUnit())
2130
2138
  else
2131
- local ____GetSpellTargetItem_result_7
2139
+ local ____GetSpellTargetItem_result_8
2132
2140
  if GetSpellTargetItem() then
2133
- ____GetSpellTargetItem_result_7 = Item:of(GetSpellTargetItem())
2141
+ ____GetSpellTargetItem_result_8 = Item:of(GetSpellTargetItem())
2134
2142
  else
2135
- local ____GetSpellTargetDestructable_result_6
2143
+ local ____GetSpellTargetDestructable_result_7
2136
2144
  if GetSpellTargetDestructable() then
2137
- ____GetSpellTargetDestructable_result_6 = Destructable:of(GetSpellTargetDestructable())
2145
+ ____GetSpellTargetDestructable_result_7 = Destructable:of(GetSpellTargetDestructable())
2138
2146
  else
2139
- ____GetSpellTargetDestructable_result_6 = nil
2147
+ ____GetSpellTargetDestructable_result_7 = nil
2140
2148
  end
2141
- ____GetSpellTargetItem_result_7 = ____GetSpellTargetDestructable_result_6
2149
+ ____GetSpellTargetItem_result_8 = ____GetSpellTargetDestructable_result_7
2142
2150
  end
2143
- ____GetSpellTargetUnit_result_8 = ____GetSpellTargetItem_result_7
2151
+ ____GetSpellTargetUnit_result_9 = ____GetSpellTargetItem_result_8
2144
2152
  end
2145
- local target = ____GetSpellTargetUnit_result_8
2153
+ local target = ____GetSpellTargetUnit_result_9
2146
2154
  if target then
2147
2155
  invoke(event, unit, id, target)
2148
2156
  end
@@ -2314,10 +2322,12 @@ Unit.onImmediateOrder = dispatchId(__TS__New(
2314
2322
  ____exports.UnitTriggerEvent,
2315
2323
  EVENT_PLAYER_UNIT_ISSUED_ORDER,
2316
2324
  function()
2317
- local unit = ____exports.Unit:of(getOrderedUnit())
2318
- local issuedOrderId = getIssuedOrderId()
2319
- if unit ~= nil and unit.state == 1 then
2320
- return unit, issuedOrderId
2325
+ local handle = getOrderedUnit()
2326
+ if handle ~= nil and getUnitTypeId(handle) ~= dummyUnitId then
2327
+ local unit = ____exports.Unit:of(handle)
2328
+ if unit.state == 1 then
2329
+ return unit, getIssuedOrderId()
2330
+ end
2321
2331
  end
2322
2332
  return IgnoreEvent
2323
2333
  end
@@ -2452,6 +2462,7 @@ Unit.onDamage = __TS__New(
2452
2462
  damageType = BlzGetEventDamageType(),
2453
2463
  weaponType = BlzGetEventWeaponType(),
2454
2464
  isAttack = BlzGetEventIsAttack(),
2465
+ originalAmount = GetEventDamage(),
2455
2466
  preventDeath = damageEventPreventDeath
2456
2467
  }
2457
2468
  local evData = setmetatable(
@@ -2468,7 +2479,7 @@ Unit.onDamage = __TS__New(
2468
2479
  invoke(event, source, target, evData)
2469
2480
  if evData[0] ~= nil and target.health - evData.amount < 0.405 then
2470
2481
  local bonusHealth = math.ceil(evData.amount)
2471
- target[104] = (target[104] or 0) + bonusHealth
2482
+ target[105] = (target[105] or 0) + bonusHealth
2472
2483
  BlzSetUnitMaxHP(
2473
2484
  target.handle,
2474
2485
  BlzGetUnitMaxHP(target.handle) + bonusHealth
@@ -2482,7 +2493,7 @@ Unit.onDamage = __TS__New(
2482
2493
  evData[0],
2483
2494
  table.unpack(evData, 1 + 1, 1 + (evData[1] or 0))
2484
2495
  )
2485
- target[104] = (target[104] or 0) - bonusHealth
2496
+ target[105] = (target[105] or 0) - bonusHealth
2486
2497
  SetWidgetLife(
2487
2498
  target.handle,
2488
2499
  GetWidgetLife(target.handle) - bonusHealth
@@ -2502,7 +2513,7 @@ Unit.onDamage = __TS__New(
2502
2513
  DestroyTrigger(trigger)
2503
2514
  end
2504
2515
  )
2505
- Unit.onItemDrop = __TS__New(
2516
+ Unit.itemDroppedEvent = __TS__New(
2506
2517
  ____exports.UnitTriggerEvent,
2507
2518
  EVENT_PLAYER_UNIT_DROP_ITEM,
2508
2519
  function()
@@ -2513,7 +2524,7 @@ Unit.onItemDrop = __TS__New(
2513
2524
  return IgnoreEvent
2514
2525
  end
2515
2526
  )
2516
- Unit.onItemPickup = __TS__New(
2527
+ Unit.itemPickedUpEvent = __TS__New(
2517
2528
  ____exports.UnitTriggerEvent,
2518
2529
  EVENT_PLAYER_UNIT_PICKUP_ITEM,
2519
2530
  function()
@@ -2524,10 +2535,66 @@ Unit.onItemPickup = __TS__New(
2524
2535
  return IgnoreEvent
2525
2536
  end
2526
2537
  )
2527
- Unit.onItemUse = __TS__New(
2538
+ Unit.itemUsedEvent = __TS__New(
2528
2539
  ____exports.UnitTriggerEvent,
2529
2540
  EVENT_PLAYER_UNIT_USE_ITEM,
2530
- function() return ____exports.Unit:of(GetTriggerUnit()), Item:of(GetManipulatedItem()) end
2541
+ function()
2542
+ local unit = getTriggerUnit()
2543
+ if getUnitTypeId(unit) ~= dummyUnitId then
2544
+ return ____exports.Unit:of(unit), Item:of(getManipulatedItem())
2545
+ end
2546
+ return IgnoreEvent
2547
+ end
2548
+ )
2549
+ Unit.itemStackedEvent = __TS__New(
2550
+ ____exports.UnitTriggerEvent,
2551
+ EVENT_PLAYER_UNIT_STACK_ITEM,
2552
+ function() return ____exports.Unit:of(getTriggerUnit()), Item:of(getManipulatedItem()) end
2553
+ )
2554
+ __TS__ObjectDefineProperty(
2555
+ Unit,
2556
+ "itemUseOrderEvent",
2557
+ {get = function(self)
2558
+ local event = __TS__New(Event)
2559
+ for order = orderId("useslot0"), orderId("useslot5") do
2560
+ local slot = order - orderId("useslot0")
2561
+ local function listener(unit)
2562
+ local item = unit.items[slot + 1]
2563
+ if item ~= nil then
2564
+ invoke(event, unit, item)
2565
+ end
2566
+ end
2567
+ self.onImmediateOrder[order]:addListener(listener)
2568
+ self.onTargetOrder[order]:addListener(listener)
2569
+ self.onPointOrder[order]:addListener(listener)
2570
+ end
2571
+ rawset(self, "itemUseOrderEvent", event)
2572
+ return event
2573
+ end}
2574
+ )
2575
+ __TS__ObjectDefineProperty(
2576
+ Unit,
2577
+ "itemMoveOrderEvent",
2578
+ {get = function(self)
2579
+ local event = __TS__New(Event)
2580
+ for order = orderId("moveslot0"), orderId("moveslot5") do
2581
+ local slotTo = order - orderId("moveslot0")
2582
+ self.onTargetOrder[order]:addListener(function(unit, item)
2583
+ local slotFrom = unit.items:findSlot(item)
2584
+ if slotFrom ~= nil then
2585
+ invoke(
2586
+ event,
2587
+ unit,
2588
+ item,
2589
+ slotFrom,
2590
+ slotTo
2591
+ )
2592
+ end
2593
+ end)
2594
+ end
2595
+ rawset(self, "itemMoveOrderEvent", event)
2596
+ return event
2597
+ end}
2531
2598
  )
2532
2599
  __TS__ObjectDefineProperty(
2533
2600
  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 { 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
  }