warscript 0.0.1-dev.ebee5b2 → 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 (61) 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 +4 -0
  4. package/core/types/frame.lua +71 -0
  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/emulate-impact.d.ts +6 -0
  12. package/engine/behaviour/ability/emulate-impact.lua +28 -0
  13. package/engine/behaviour/ability/instant-impact.d.ts +2 -2
  14. package/engine/behaviour/ability/instant-impact.lua +4 -19
  15. package/engine/behaviour/ability/on-command-impact.d.ts +8 -0
  16. package/engine/behaviour/ability/on-command-impact.lua +25 -0
  17. package/engine/behaviour/ability/remove-buffs.d.ts +16 -0
  18. package/engine/behaviour/ability/remove-buffs.lua +28 -0
  19. package/engine/behaviour/ability.d.ts +14 -3
  20. package/engine/behaviour/ability.lua +79 -33
  21. package/engine/buff.d.ts +6 -1
  22. package/engine/buff.lua +29 -18
  23. package/engine/internal/ability.d.ts +16 -13
  24. package/engine/internal/ability.lua +82 -76
  25. package/engine/internal/item/ability.lua +90 -0
  26. package/engine/internal/misc/ability-disable-counter.d.ts +2 -0
  27. package/engine/internal/misc/ability-disable-counter.lua +13 -0
  28. package/engine/internal/unit/ability.d.ts +10 -1
  29. package/engine/internal/unit/ability.lua +36 -14
  30. package/engine/internal/unit/item.d.ts +24 -0
  31. package/engine/internal/unit/item.lua +79 -0
  32. package/engine/internal/unit/main-selected.d.ts +13 -0
  33. package/engine/internal/unit/main-selected.lua +51 -0
  34. package/engine/internal/unit-missile-launch.lua +24 -5
  35. package/engine/internal/unit.d.ts +20 -24
  36. package/engine/internal/unit.lua +136 -122
  37. package/engine/internal/utility.lua +12 -0
  38. package/engine/local-client.d.ts +7 -2
  39. package/engine/local-client.lua +82 -0
  40. package/engine/object-data/auxiliary/sound-preset-name.d.ts +5 -1
  41. package/engine/object-data/entry/ability-type.lua +8 -12
  42. package/engine/object-data/entry/item-type.d.ts +14 -0
  43. package/engine/object-data/entry/item-type.lua +91 -0
  44. package/engine/object-data/utility/object-data-entry-id-generator.lua +7 -0
  45. package/engine/object-field/ability.d.ts +9 -3
  46. package/engine/object-field/ability.lua +4 -1
  47. package/engine/object-field.d.ts +2 -2
  48. package/engine/object-field.lua +4 -0
  49. package/engine/standard/fields/ability.d.ts +2 -0
  50. package/engine/standard/fields/ability.lua +2 -0
  51. package/engine/unit.d.ts +2 -0
  52. package/engine/unit.lua +2 -0
  53. package/index.d.ts +1 -0
  54. package/index.lua +1 -0
  55. package/package.json +1 -1
  56. package/patch-lua.d.ts +0 -0
  57. package/patch-lua.lua +10 -0
  58. package/utility/arrays.d.ts +8 -1
  59. package/utility/arrays.lua +34 -3
  60. package/utility/lazy.d.ts +2 -0
  61. package/utility/lazy.lua +14 -0
@@ -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)
@@ -68,22 +68,6 @@ declare const modifiers: {
68
68
  speed: (unit: junit, value: number) => void;
69
69
  armor: (unit: junit, value: number) => void;
70
70
  };
71
- export interface UnitItems extends ReadonlyArray<Item | undefined> {
72
- readonly length: 0 | 1 | 2 | 3 | 4 | 5 | 6;
73
- [0]: Item | undefined;
74
- [1]: Item | undefined;
75
- [2]: Item | undefined;
76
- [3]: Item | undefined;
77
- [4]: Item | undefined;
78
- [5]: Item | undefined;
79
- }
80
- export declare class UnitItems {
81
- private readonly handle;
82
- constructor(handle: junit);
83
- protected __newindex(slot: number, item: Item | undefined): void;
84
- protected __index(slot: number): Item | undefined;
85
- protected __len(): number;
86
- }
87
71
  export declare class UnitWeapon {
88
72
  readonly unit: Unit;
89
73
  readonly index: 0 | 1;
@@ -110,14 +94,19 @@ export declare class UnitWeapon {
110
94
  set missileSpeed(missileSpeed: number);
111
95
  }
112
96
  declare const enum UnitPropertyKey {
113
- IS_PAUSED = 100,
114
- STUN_COUNTER = 101,
115
- DELAY_HEALTH_CHECKS_COUNTER = 102,
116
- DELAY_HEALTH_CHECKS_HEALTH_BONUS = 103,
117
- PREVENT_DEATH_HEALTH_BONUS = 104,
118
- 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
119
104
  }
105
+ export type UnitSyncId = number & {
106
+ readonly __unitSyncId: unique symbol;
107
+ };
120
108
  export declare class Unit extends Handle<junit> {
109
+ readonly syncId: UnitSyncId;
121
110
  private [UnitPropertyKey.IS_PAUSED]?;
122
111
  private [UnitPropertyKey.STUN_COUNTER]?;
123
112
  private [UnitPropertyKey.DELAY_HEALTH_CHECKS_COUNTER]?;
@@ -257,7 +246,6 @@ export declare class Unit extends Handle<junit> {
257
246
  dropItemTarget(item: Item, target: Widget): boolean;
258
247
  dropItemSlot(item: Item, slot: number): boolean;
259
248
  itemInSlot(slot: number): Item | null;
260
- get items(): UnitItems;
261
249
  addAbility(abilityId: number): UnitAbility | null;
262
250
  makeAbilityPermanent(abilityId: number, permanent: true): boolean;
263
251
  setAbilityLevel(abilityId: number, level: number): number;
@@ -305,7 +293,7 @@ export declare class Unit extends Handle<junit> {
305
293
  static getInRange(x: number, y: number, range: number, predicate?: (unit: Unit) => boolean): Unit[];
306
294
  static getInCollisionRange(x: number, y: number, range: number, predicate?: (unit: Unit) => boolean): Unit[];
307
295
  static getInSector(pos: Vec2, range: number, offsetAngle: number, centralAngle: number): Unit[];
308
- static getSelectionOf(player: Player): Unit[];
296
+ static getSelectionOf(player: Player, target?: Unit[]): Unit[];
309
297
  static readonly deathEvent: UnitTriggerEvent<[Unit]>;
310
298
  static readonly onDecay: UnitTriggerEvent<[]>;
311
299
  static readonly onResurrect: InitializingEvent<[Unit], void>;
@@ -344,6 +332,13 @@ export declare class Unit extends Handle<junit> {
344
332
  static itemPickedUpEvent: UnitTriggerEvent<[Item]>;
345
333
  static itemUsedEvent: UnitTriggerEvent<[Item]>;
346
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
+ ]>;
347
342
  static get onCreate(): EventDispatcher<[Unit], [Unit]>;
348
343
  static get destroyEvent(): EventDispatcher<[Unit], [Unit]>;
349
344
  getField(field: junitintegerfield | junitrealfield): number;
@@ -354,5 +349,6 @@ export declare class Unit extends Handle<junit> {
354
349
  setField(field: junitbooleanfield, value: boolean): boolean;
355
350
  setField(field: junitstringfield, value: string): boolean;
356
351
  toString(): string;
352
+ static getBySyncId(syncId: UnitSyncId): Unit | undefined;
357
353
  }
358
354
  export {};
@@ -15,7 +15,6 @@ local __TS__ObjectDefineProperty = ____lualib.__TS__ObjectDefineProperty
15
15
  local Set = ____lualib.Set
16
16
  local __TS__Spread = ____lualib.__TS__Spread
17
17
  local ____exports = {}
18
- local unitInventorySize, unitItemInSlot, unitDropItemSlot, unitRemoveItemFromSlot, unitAddItem, isItemPowerup, setItemBooleanField
19
18
  local ____handle = require("core.types.handle")
20
19
  local Handle = ____handle.Handle
21
20
  local ____player = require("core.types.player")
@@ -392,37 +391,6 @@ local getters = {
392
391
  return BlzGetUnitArmor(unit)
393
392
  end
394
393
  }
395
- ____exports.UnitItems = __TS__Class()
396
- local UnitItems = ____exports.UnitItems
397
- UnitItems.name = "UnitItems"
398
- function UnitItems.prototype.____constructor(self, handle)
399
- self.handle = handle
400
- end
401
- function UnitItems.prototype.__newindex(self, slot, item)
402
- local handle = self.handle
403
- if slot < 0 or slot >= unitInventorySize(handle) then
404
- return
405
- end
406
- unitRemoveItemFromSlot(handle, slot)
407
- if item ~= nil then
408
- local itemHandle = item.handle
409
- local isPowerup = isItemPowerup(itemHandle)
410
- if isPowerup then
411
- setItemBooleanField(itemHandle, ITEM_BF_USE_AUTOMATICALLY_WHEN_ACQUIRED, false)
412
- end
413
- unitAddItem(handle, itemHandle)
414
- unitDropItemSlot(handle, itemHandle, slot)
415
- if isPowerup then
416
- setItemBooleanField(itemHandle, ITEM_BF_USE_AUTOMATICALLY_WHEN_ACQUIRED, true)
417
- end
418
- end
419
- end
420
- function UnitItems.prototype.__index(self, slot)
421
- return Item:of(unitItemInSlot(self.handle, slot))
422
- end
423
- function UnitItems.prototype.__len(self)
424
- return unitInventorySize(self.handle)
425
- end
426
394
  ____exports.UnitWeapon = __TS__Class()
427
395
  local UnitWeapon = ____exports.UnitWeapon
428
396
  UnitWeapon.name = "UnitWeapon"
@@ -575,13 +543,8 @@ __TS__SetDescriptor(
575
543
  },
576
544
  true
577
545
  )
578
- unitInventorySize = UnitInventorySize
579
- unitItemInSlot = UnitItemInSlot
580
- unitDropItemSlot = UnitDropItemSlot
581
- unitRemoveItemFromSlot = UnitRemoveItemFromSlot
582
- unitAddItem = UnitAddItem
583
- isItemPowerup = IsItemPowerup
584
- setItemBooleanField = BlzSetItemBooleanField
546
+ local unitInventorySize = UnitInventorySize
547
+ local unitItemInSlot = UnitItemInSlot
585
548
  local getItemAbility = BlzGetItemAbility
586
549
  local getUnitAbility = BlzGetUnitAbility
587
550
  local getUnitAbilityByIndex = BlzGetUnitAbilityByIndex
@@ -599,17 +562,6 @@ local function retrieveAbility(unit, ability, abilityId)
599
562
  ____exports.Unit:of(unit)
600
563
  )
601
564
  end
602
- if not unitAddAbility(unit, abilityId) then
603
- if getUnitAbility(unit, abilityId) == ability then
604
- return UnitAbility:of(
605
- ability,
606
- abilityId,
607
- ____exports.Unit:of(unit)
608
- )
609
- end
610
- else
611
- unitRemoveAbility(unit, abilityId)
612
- end
613
565
  for i = 0, unitInventorySize(unit) - 1 do
614
566
  local item = unitItemInSlot(unit, i)
615
567
  if getItemAbility(item, abilityId) == ability then
@@ -667,15 +619,15 @@ for ____, player in ipairs(Player.all) do
667
619
  dummies[player] = dummy
668
620
  end
669
621
  local function delayHealthChecksCallback(unit)
670
- local counter = (unit[102] or 0) - 1
622
+ local counter = (unit[103] or 0) - 1
671
623
  if counter ~= 0 then
672
- unit[102] = counter
624
+ unit[103] = counter
673
625
  return
674
626
  end
675
- unit[102] = nil
676
- local healthBonus = unit[103]
627
+ unit[103] = nil
628
+ local healthBonus = unit[104]
677
629
  if healthBonus ~= nil then
678
- unit[103] = nil
630
+ unit[104] = nil
679
631
  local handle = unit.handle
680
632
  BlzSetUnitMaxHP(
681
633
  handle,
@@ -683,12 +635,17 @@ local function delayHealthChecksCallback(unit)
683
635
  )
684
636
  end
685
637
  end
638
+ local nextSyncId = 1
639
+ local unitBySyncId = setmetatable({}, {__mode = "k"})
686
640
  ____exports.Unit = __TS__Class()
687
641
  local Unit = ____exports.Unit
688
642
  Unit.name = "Unit"
689
643
  __TS__ClassExtends(Unit, Handle)
690
644
  function Unit.prototype.____constructor(self, handle)
691
645
  Handle.prototype.____constructor(self, handle)
646
+ local ____nextSyncId_0 = nextSyncId
647
+ nextSyncId = ____nextSyncId_0 + 1
648
+ self.syncId = ____nextSyncId_0
692
649
  self._owner = Player:of(getOwningPlayer(handle))
693
650
  assert(unitAddAbility(handle, leaveDetectAbilityId) and UnitMakeAbilityPermanent(handle, true, leaveDetectAbilityId))
694
651
  assert(unitAddAbility(handle, morphDetectAbilityId))
@@ -701,6 +658,7 @@ function Unit.prototype.____constructor(self, handle)
701
658
  fourCC("Amrf")
702
659
  ))
703
660
  end
661
+ unitBySyncId[self.syncId] = self
704
662
  local ____ = self.abilities
705
663
  end
706
664
  function Unit.prototype.getEvent(self, event, collector)
@@ -786,8 +744,8 @@ function Unit.prototype.addModifier(self, property, modifier)
786
744
  end}
787
745
  end
788
746
  function Unit.prototype.hasCombatClassification(self, combatClassification)
789
- local ____combatClassification_0 = combatClassification
790
- 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
791
749
  end
792
750
  function Unit.prototype.addClassification(self, classification)
793
751
  return unitAddType(self.handle, classification)
@@ -805,13 +763,13 @@ function Unit.prototype.isInvisibleTo(self, player)
805
763
  return isUnitInvisible(self.handle, player.handle)
806
764
  end
807
765
  function Unit.prototype.isInRangeOf(self, x, y, range)
808
- local ____temp_1
766
+ local ____temp_2
809
767
  if type(x) == "number" then
810
- ____temp_1 = isUnitInRangeXY(self.handle, x, y, range)
768
+ ____temp_2 = isUnitInRangeXY(self.handle, x, y, range)
811
769
  else
812
- ____temp_1 = isUnitInRange(self.handle, x.handle, y)
770
+ ____temp_2 = isUnitInRange(self.handle, x.handle, y)
813
771
  end
814
- return ____temp_1
772
+ return ____temp_2
815
773
  end
816
774
  function Unit.prototype.isAllyOf(self, unit)
817
775
  return isUnitAlly(
@@ -838,7 +796,7 @@ function Unit.prototype.queueAnimation(self, animation)
838
796
  queueUnitAnimation(self.handle, animation)
839
797
  end
840
798
  function Unit.prototype.delayHealthChecks(self)
841
- self[102] = (self[102] or 0) + 1
799
+ self[103] = (self[103] or 0) + 1
842
800
  Timer:run(delayHealthChecksCallback, self)
843
801
  end
844
802
  function Unit.prototype.setPosition(self, x, y)
@@ -855,14 +813,14 @@ function Unit.prototype.kill(self)
855
813
  killUnit(self.handle)
856
814
  end
857
815
  function Unit.prototype.revive(self, x, y, doEffect)
858
- local ____ReviveHero_4 = ReviveHero
859
- local ____array_3 = __TS__SparseArrayNew(self.handle, x, y)
860
- local ____doEffect_2 = doEffect
861
- if ____doEffect_2 == nil then
862
- ____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
863
821
  end
864
- __TS__SparseArrayPush(____array_3, ____doEffect_2)
865
- ____ReviveHero_4(__TS__SparseArraySpread(____array_3))
822
+ __TS__SparseArrayPush(____array_4, ____doEffect_3)
823
+ ____ReviveHero_5(__TS__SparseArraySpread(____array_4))
866
824
  end
867
825
  function Unit.prototype.healTarget(self, target, amount)
868
826
  if __TS__InstanceOf(target, ____exports.Unit) and target:hasAbility(fourCC("BIhm")) then
@@ -971,8 +929,15 @@ function Unit.prototype.interruptAttack(self)
971
929
  unitInterruptAttack(self.handle)
972
930
  end
973
931
  function Unit.prototype.interruptCast(self, abilityId)
974
- unitDisableAbility(self.handle, abilityId, true, false)
975
- 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
+ )
976
941
  end
977
942
  function Unit.prototype.getDistanceTo(self, target)
978
943
  local handle = self.handle
@@ -1032,18 +997,18 @@ function Unit.prototype.unpauseEx(self)
1032
997
  self:decrementStunCounter()
1033
998
  end
1034
999
  function Unit.prototype.incrementStunCounter(self)
1035
- local stunCounter = self[101] or 0
1036
- if not self[100] or stunCounter >= 0 then
1000
+ local stunCounter = self[102] or 0
1001
+ if not self[101] or stunCounter >= 0 then
1037
1002
  BlzPauseUnitEx(self.handle, true)
1038
1003
  end
1039
- self[101] = stunCounter + 1
1004
+ self[102] = stunCounter + 1
1040
1005
  end
1041
1006
  function Unit.prototype.decrementStunCounter(self)
1042
- local stunCounter = self[101] or 0
1043
- if not self[100] or stunCounter >= 1 then
1007
+ local stunCounter = self[102] or 0
1008
+ if not self[101] or stunCounter >= 1 then
1044
1009
  BlzPauseUnitEx(self.handle, false)
1045
1010
  end
1046
- self[101] = stunCounter - 1
1011
+ self[102] = stunCounter - 1
1047
1012
  end
1048
1013
  function Unit.create(self, owner, id, x, y, facing, skinId)
1049
1014
  local handle = skinId and BlzCreateUnitWithSkin(
@@ -1145,8 +1110,11 @@ function Unit.getInSector(self, pos, range, offsetAngle, centralAngle)
1145
1110
  )
1146
1111
  return targetCollection
1147
1112
  end
1148
- function Unit.getSelectionOf(self, player)
1149
- targetCollection = {}
1113
+ function Unit.getSelectionOf(self, player, target)
1114
+ if target == nil then
1115
+ target = {}
1116
+ end
1117
+ targetCollection = target
1150
1118
  targetCollectionNextIndex = 1
1151
1119
  GroupEnumUnitsSelected(dummyGroup, player.handle, collectIntoTarget)
1152
1120
  return targetCollection
@@ -1168,6 +1136,9 @@ end
1168
1136
  function Unit.prototype.__tostring(self)
1169
1137
  return (((self.constructor.name .. "$") .. util.id2s(self.typeId)) .. "@") .. tostring(getHandleId(self.handle))
1170
1138
  end
1139
+ function Unit.getBySyncId(self, syncId)
1140
+ return unitBySyncId[syncId]
1141
+ end
1171
1142
  __TS__SetDescriptor(
1172
1143
  Unit.prototype,
1173
1144
  "_deltas",
@@ -1425,17 +1396,17 @@ __TS__SetDescriptor(
1425
1396
  "isTeamGlowVisible",
1426
1397
  {
1427
1398
  get = function(self)
1428
- return not self[105]
1399
+ return not self[106]
1429
1400
  end,
1430
1401
  set = function(self, isTeamGlowVisible)
1431
1402
  showUnitTeamGlow(self.handle, isTeamGlowVisible)
1432
- local ____temp_5
1403
+ local ____temp_6
1433
1404
  if not isTeamGlowVisible then
1434
- ____temp_5 = true
1405
+ ____temp_6 = true
1435
1406
  else
1436
- ____temp_5 = nil
1407
+ ____temp_6 = nil
1437
1408
  end
1438
- self[105] = ____temp_5
1409
+ self[106] = ____temp_6
1439
1410
  end
1440
1411
  },
1441
1412
  true
@@ -1445,7 +1416,7 @@ __TS__SetDescriptor(
1445
1416
  "color",
1446
1417
  {set = function(self, color)
1447
1418
  setUnitColor(self.handle, color.handle)
1448
- if self[105] then
1419
+ if self[106] then
1449
1420
  showUnitTeamGlow(self.handle, false)
1450
1421
  end
1451
1422
  end},
@@ -1469,14 +1440,14 @@ __TS__SetDescriptor(
1469
1440
  "maxHealth",
1470
1441
  {
1471
1442
  get = function(self)
1472
- 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)
1473
1444
  end,
1474
1445
  set = function(self, maxHealth)
1475
- if maxHealth < 1 and self[102] ~= nil then
1476
- 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)
1477
1448
  maxHealth = 1
1478
1449
  end
1479
- BlzSetUnitMaxHP(self.handle, maxHealth + (self[104] or 0))
1450
+ BlzSetUnitMaxHP(self.handle, maxHealth + (self[105] or 0))
1480
1451
  end
1481
1452
  },
1482
1453
  true
@@ -1518,10 +1489,10 @@ __TS__SetDescriptor(
1518
1489
  "health",
1519
1490
  {
1520
1491
  get = function(self)
1521
- return GetWidgetLife(self.handle) - (self[104] or 0)
1492
+ return GetWidgetLife(self.handle) - (self[105] or 0)
1522
1493
  end,
1523
1494
  set = function(self, health)
1524
- SetWidgetLife(self.handle, health + (self[104] or 0))
1495
+ SetWidgetLife(self.handle, health + (self[105] or 0))
1525
1496
  end
1526
1497
  },
1527
1498
  true
@@ -1732,17 +1703,17 @@ __TS__SetDescriptor(
1732
1703
  set = function(self, isPaused)
1733
1704
  local handle = self.handle
1734
1705
  if isPaused and not IsUnitPaused(handle) then
1735
- self[100] = true
1736
- for _ = self[101] or 0, -1 do
1706
+ self[101] = true
1707
+ for _ = self[102] or 0, -1 do
1737
1708
  BlzPauseUnitEx(handle, true)
1738
1709
  end
1739
1710
  PauseUnit(handle, true)
1740
1711
  elseif not isPaused and IsUnitPaused(handle) then
1741
1712
  PauseUnit(handle, false)
1742
- for _ = self[101] or 0, -1 do
1713
+ for _ = self[102] or 0, -1 do
1743
1714
  BlzPauseUnitEx(handle, false)
1744
1715
  end
1745
- self[100] = nil
1716
+ self[101] = nil
1746
1717
  end
1747
1718
  end
1748
1719
  },
@@ -1853,16 +1824,6 @@ __TS__SetDescriptor(
1853
1824
  end},
1854
1825
  true
1855
1826
  )
1856
- __TS__SetDescriptor(
1857
- Unit.prototype,
1858
- "items",
1859
- {get = function(self)
1860
- local items = __TS__New(____exports.UnitItems, self.handle)
1861
- rawset(self, "items", items)
1862
- return items
1863
- end},
1864
- true
1865
- )
1866
1827
  __TS__SetDescriptor(
1867
1828
  Unit.prototype,
1868
1829
  "buffIds",
@@ -2171,25 +2132,25 @@ Unit.onTargetCast = dispatchId(__TS__New(
2171
2132
  InitializingEvent,
2172
2133
  function(event)
2173
2134
  local function listener(unit, id)
2174
- local ____GetSpellTargetUnit_result_8
2135
+ local ____GetSpellTargetUnit_result_9
2175
2136
  if GetSpellTargetUnit() then
2176
- ____GetSpellTargetUnit_result_8 = ____exports.Unit:of(GetSpellTargetUnit())
2137
+ ____GetSpellTargetUnit_result_9 = ____exports.Unit:of(GetSpellTargetUnit())
2177
2138
  else
2178
- local ____GetSpellTargetItem_result_7
2139
+ local ____GetSpellTargetItem_result_8
2179
2140
  if GetSpellTargetItem() then
2180
- ____GetSpellTargetItem_result_7 = Item:of(GetSpellTargetItem())
2141
+ ____GetSpellTargetItem_result_8 = Item:of(GetSpellTargetItem())
2181
2142
  else
2182
- local ____GetSpellTargetDestructable_result_6
2143
+ local ____GetSpellTargetDestructable_result_7
2183
2144
  if GetSpellTargetDestructable() then
2184
- ____GetSpellTargetDestructable_result_6 = Destructable:of(GetSpellTargetDestructable())
2145
+ ____GetSpellTargetDestructable_result_7 = Destructable:of(GetSpellTargetDestructable())
2185
2146
  else
2186
- ____GetSpellTargetDestructable_result_6 = nil
2147
+ ____GetSpellTargetDestructable_result_7 = nil
2187
2148
  end
2188
- ____GetSpellTargetItem_result_7 = ____GetSpellTargetDestructable_result_6
2149
+ ____GetSpellTargetItem_result_8 = ____GetSpellTargetDestructable_result_7
2189
2150
  end
2190
- ____GetSpellTargetUnit_result_8 = ____GetSpellTargetItem_result_7
2151
+ ____GetSpellTargetUnit_result_9 = ____GetSpellTargetItem_result_8
2191
2152
  end
2192
- local target = ____GetSpellTargetUnit_result_8
2153
+ local target = ____GetSpellTargetUnit_result_9
2193
2154
  if target then
2194
2155
  invoke(event, unit, id, target)
2195
2156
  end
@@ -2361,10 +2322,12 @@ Unit.onImmediateOrder = dispatchId(__TS__New(
2361
2322
  ____exports.UnitTriggerEvent,
2362
2323
  EVENT_PLAYER_UNIT_ISSUED_ORDER,
2363
2324
  function()
2364
- local unit = ____exports.Unit:of(getOrderedUnit())
2365
- local issuedOrderId = getIssuedOrderId()
2366
- if unit ~= nil and unit.state == 1 then
2367
- 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
2368
2331
  end
2369
2332
  return IgnoreEvent
2370
2333
  end
@@ -2516,7 +2479,7 @@ Unit.onDamage = __TS__New(
2516
2479
  invoke(event, source, target, evData)
2517
2480
  if evData[0] ~= nil and target.health - evData.amount < 0.405 then
2518
2481
  local bonusHealth = math.ceil(evData.amount)
2519
- target[104] = (target[104] or 0) + bonusHealth
2482
+ target[105] = (target[105] or 0) + bonusHealth
2520
2483
  BlzSetUnitMaxHP(
2521
2484
  target.handle,
2522
2485
  BlzGetUnitMaxHP(target.handle) + bonusHealth
@@ -2530,7 +2493,7 @@ Unit.onDamage = __TS__New(
2530
2493
  evData[0],
2531
2494
  table.unpack(evData, 1 + 1, 1 + (evData[1] or 0))
2532
2495
  )
2533
- target[104] = (target[104] or 0) - bonusHealth
2496
+ target[105] = (target[105] or 0) - bonusHealth
2534
2497
  SetWidgetLife(
2535
2498
  target.handle,
2536
2499
  GetWidgetLife(target.handle) - bonusHealth
@@ -2575,13 +2538,64 @@ Unit.itemPickedUpEvent = __TS__New(
2575
2538
  Unit.itemUsedEvent = __TS__New(
2576
2539
  ____exports.UnitTriggerEvent,
2577
2540
  EVENT_PLAYER_UNIT_USE_ITEM,
2578
- 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
2579
2548
  )
2580
2549
  Unit.itemStackedEvent = __TS__New(
2581
2550
  ____exports.UnitTriggerEvent,
2582
2551
  EVENT_PLAYER_UNIT_STACK_ITEM,
2583
2552
  function() return ____exports.Unit:of(getTriggerUnit()), Item:of(getManipulatedItem()) end
2584
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}
2598
+ )
2585
2599
  __TS__ObjectDefineProperty(
2586
2600
  Unit,
2587
2601
  "onCreate",
@@ -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
  }