warscript 0.0.1-dev.20f0f7e → 0.0.1-dev.2100d8f

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 (85) hide show
  1. package/attributes.d.ts +1 -0
  2. package/attributes.lua +9 -0
  3. package/core/types/player.d.ts +16 -0
  4. package/core/types/player.lua +57 -14
  5. package/core/types/tileCell.d.ts +2 -1
  6. package/core/types/tileCell.lua +5 -0
  7. package/core/types/timer.d.ts +3 -2
  8. package/core/types/timer.lua +8 -2
  9. package/destroyable.d.ts +1 -0
  10. package/destroyable.lua +9 -0
  11. package/engine/behavior.d.ts +10 -2
  12. package/engine/behavior.lua +157 -76
  13. package/engine/behaviour/ability/apply-buff.lua +4 -4
  14. package/engine/behaviour/ability/remove-buffs.d.ts +9 -0
  15. package/engine/behaviour/ability/remove-buffs.lua +21 -0
  16. package/engine/behaviour/ability.d.ts +2 -1
  17. package/engine/behaviour/ability.lua +2 -1
  18. package/engine/behaviour/unit/stun-immunity.d.ts +9 -5
  19. package/engine/behaviour/unit/stun-immunity.lua +17 -7
  20. package/engine/behaviour/unit.d.ts +9 -3
  21. package/engine/behaviour/unit.lua +106 -24
  22. package/engine/buff.d.ts +19 -4
  23. package/engine/buff.lua +122 -41
  24. package/engine/internal/item.d.ts +12 -12
  25. package/engine/internal/item.lua +41 -26
  26. package/engine/internal/mechanics/cast-ability.lua +6 -3
  27. package/engine/internal/object-data/mana-regeneration-rate-increase-factor.d.ts +2 -0
  28. package/engine/internal/object-data/mana-regeneration-rate-increase-factor.lua +16 -0
  29. package/engine/internal/unit/ability.d.ts +14 -14
  30. package/engine/internal/unit/ability.lua +72 -45
  31. package/engine/internal/unit/attributes.d.ts +17 -0
  32. package/engine/internal/unit/attributes.lua +46 -0
  33. package/engine/internal/unit/bonus.d.ts +2 -0
  34. package/engine/internal/unit/bonus.lua +10 -0
  35. package/engine/internal/unit/fly-height.d.ts +7 -0
  36. package/engine/internal/unit/fly-height.lua +20 -0
  37. package/engine/internal/unit/interrupts.d.ts +12 -0
  38. package/engine/internal/unit/interrupts.lua +28 -0
  39. package/engine/internal/unit/main-selected.lua +12 -27
  40. package/engine/internal/unit/scale.d.ts +7 -0
  41. package/engine/internal/unit/scale.lua +20 -0
  42. package/engine/internal/unit-missile-launch.lua +51 -20
  43. package/engine/internal/unit.d.ts +14 -18
  44. package/engine/internal/unit.lua +99 -133
  45. package/engine/local-client.d.ts +2 -0
  46. package/engine/local-client.lua +30 -0
  47. package/engine/object-data/auxiliary/health-regeneration-type.d.ts +8 -0
  48. package/engine/object-data/auxiliary/health-regeneration-type.lua +2 -0
  49. package/engine/object-data/entry/ability-type/mana-regeneration.d.ts +8 -0
  50. package/engine/object-data/entry/ability-type/mana-regeneration.lua +26 -0
  51. package/engine/object-data/entry/ability-type.lua +4 -1
  52. package/engine/object-data/entry/destructible-type.d.ts +27 -1
  53. package/engine/object-data/entry/destructible-type.lua +155 -0
  54. package/engine/object-data/entry/unit-type.d.ts +4 -0
  55. package/engine/object-data/entry/unit-type.lua +76 -32
  56. package/engine/object-field/unit.d.ts +20 -5
  57. package/engine/object-field/unit.lua +61 -0
  58. package/engine/object-field.d.ts +9 -1
  59. package/engine/object-field.lua +265 -122
  60. package/engine/random.d.ts +4 -0
  61. package/engine/random.lua +10 -0
  62. package/engine/standard/fields/ability.d.ts +2 -2
  63. package/engine/standard/fields/ability.lua +2 -2
  64. package/engine/standard/fields/unit.d.ts +11 -3
  65. package/engine/standard/fields/unit.lua +15 -2
  66. package/engine/synchronization.d.ts +11 -0
  67. package/engine/synchronization.lua +77 -0
  68. package/engine/text-tag.lua +3 -2
  69. package/engine/unit.d.ts +4 -0
  70. package/engine/unit.lua +4 -0
  71. package/net/socket.lua +1 -1
  72. package/objutil/buff.lua +10 -8
  73. package/package.json +2 -2
  74. package/utility/arrays.d.ts +1 -0
  75. package/utility/arrays.lua +8 -0
  76. package/utility/callback-array.d.ts +5 -1
  77. package/utility/callback-array.lua +16 -1
  78. package/utility/linked-map.d.ts +26 -0
  79. package/utility/linked-map.lua +66 -0
  80. package/utility/linked-set.d.ts +1 -0
  81. package/utility/linked-set.lua +23 -1
  82. package/utility/lua-maps.d.ts +11 -2
  83. package/utility/lua-maps.lua +33 -2
  84. package/utility/records.lua +20 -1
  85. package/utility/types.d.ts +3 -0
@@ -9,11 +9,18 @@ local ____timer = require("core.types.timer")
9
9
  local Timer = ____timer.Timer
10
10
  local ____lua_2Dsets = require("utility.lua-sets")
11
11
  local luaSetOf = ____lua_2Dsets.luaSetOf
12
+ local ____attributes = require("attributes")
13
+ local attribute = ____attributes.attribute
14
+ local ____linked_2Dset = require("utility.linked-set")
15
+ local LinkedSet = ____linked_2Dset.LinkedSet
12
16
  local ____math = require("math")
13
- local min = ____math.min
17
+ local ceil = ____math.ceil
14
18
  local autoAttackFinishEvent = __TS__New(Event)
15
19
  rawset(Unit, "autoAttackFinishEvent", autoAttackFinishEvent)
16
- local eventTimerByUnit = {}
20
+ local units = __TS__New(LinkedSet)
21
+ local targetAttribute = attribute()
22
+ local impactDelayAttribute = attribute()
23
+ local passedTimeAttribute = attribute()
17
24
  local instantOrderIds = luaSetOf(
18
25
  orderId("avatar"),
19
26
  orderId("berserk"),
@@ -29,30 +36,54 @@ local instantOrderIds = luaSetOf(
29
36
  orderId("undivineshield"),
30
37
  orderId("unimmolation")
31
38
  )
32
- local function reset(source, orderId)
39
+ ---
40
+ -- @internal For use by internal systems only.
41
+ ____exports.resetAutoAttackTimer = function(unit)
42
+ if units:remove(unit) then
43
+ unit[targetAttribute] = nil
44
+ unit[impactDelayAttribute] = nil
45
+ unit[passedTimeAttribute] = nil
46
+ end
47
+ end
48
+ local function reset(unit, orderId)
33
49
  if not (instantOrderIds[orderId] ~= nil) then
34
- local eventTimer = eventTimerByUnit[source]
35
- if eventTimer then
36
- eventTimer:destroy()
37
- eventTimerByUnit[source] = nil
38
- end
50
+ ____exports.resetAutoAttackTimer(unit)
39
51
  end
40
52
  end
41
53
  Unit.onImmediateOrder:addListener(reset)
42
54
  Unit.onPointOrder:addListener(reset)
43
55
  Unit.onTargetOrder:addListener(reset)
44
- local function timerCallback(source, target)
45
- eventTimerByUnit[source] = nil
46
- Event.invoke(autoAttackFinishEvent, source, target)
56
+ local timerPeriod = 1 / 64
57
+ local function invokeEvent(unit)
58
+ units:remove(unit)
59
+ local target = unit[targetAttribute]
60
+ unit[targetAttribute] = nil
61
+ unit[impactDelayAttribute] = nil
62
+ unit[passedTimeAttribute] = nil
63
+ Event.invoke(autoAttackFinishEvent, unit, target)
64
+ end
65
+ local function checkUnit(unit)
66
+ local passedTime = unit[passedTimeAttribute] + timerPeriod
67
+ local impactDelay = unit[impactDelayAttribute]
68
+ if passedTime >= impactDelay and ceil(passedTime / 0.02) >= ceil(impactDelay / 0.02) then
69
+ invokeEvent(unit)
70
+ else
71
+ unit[passedTimeAttribute] = passedTime
72
+ end
47
73
  end
48
- Unit.autoAttackStartEvent:addListener(function(source, target)
49
- local attackPoint = (source:chooseWeapon(target) or source.firstWeapon).impactDelay
50
- local timer = Timer:simple(
51
- attackPoint + min(0.001, attackPoint / 2),
52
- timerCallback,
53
- source,
54
- target
55
- )
56
- eventTimerByUnit[source] = timer
74
+ Timer.onPeriod[timerPeriod]:addListener(function()
75
+ units:forEach(checkUnit)
57
76
  end)
77
+ Unit.autoAttackStartEvent:addListener(
78
+ 999999,
79
+ function(source, target)
80
+ if source[targetAttribute] ~= nil then
81
+ invokeEvent(source)
82
+ end
83
+ source[targetAttribute] = target
84
+ source[impactDelayAttribute] = (source:chooseWeapon(target) or source.firstWeapon).impactDelay
85
+ source[passedTimeAttribute] = -timerPeriod
86
+ units:add(source)
87
+ end
88
+ )
58
89
  return ____exports
@@ -80,6 +80,8 @@ export declare class UnitWeapon {
80
80
  readonly unit: Unit;
81
81
  readonly index: 0 | 1;
82
82
  constructor(unit: Unit, index: 0 | 1);
83
+ get isEnabled(): boolean;
84
+ set isEnabled(isEnabled: boolean);
83
85
  get cooldown(): number;
84
86
  set cooldown(cooldown: number);
85
87
  get damage(): [minimumDamage: number, maximumDamage: number];
@@ -107,12 +109,13 @@ declare const enum UnitPropertyKey {
107
109
  SYNC_ID = 100,
108
110
  IS_PAUSED = 101,
109
111
  STUN_COUNTER = 102,
110
- DELAY_HEALTH_CHECKS_COUNTER = 103,
111
- DELAY_HEALTH_CHECKS_HEALTH_BONUS = 104,
112
- PREVENT_DEATH_HEALTH_BONUS = 105,
113
- IS_TEAM_GLOW_HIDDEN = 106,
114
- LAST_X = 107,
115
- LAST_Y = 108
112
+ FORCE_STUN_COUNTER = 103,
113
+ DELAY_HEALTH_CHECKS_COUNTER = 104,
114
+ DELAY_HEALTH_CHECKS_HEALTH_BONUS = 105,
115
+ PREVENT_DEATH_HEALTH_BONUS = 106,
116
+ IS_TEAM_GLOW_HIDDEN = 107,
117
+ LAST_X = 108,
118
+ LAST_Y = 109
116
119
  }
117
120
  export type UnitSyncId = number & {
118
121
  readonly __unitSyncId: unique symbol;
@@ -121,6 +124,7 @@ export declare class Unit extends Handle<junit> {
121
124
  readonly syncId: UnitSyncId;
122
125
  private [UnitPropertyKey.IS_PAUSED]?;
123
126
  private [UnitPropertyKey.STUN_COUNTER]?;
127
+ private [UnitPropertyKey.FORCE_STUN_COUNTER]?;
124
128
  private [UnitPropertyKey.DELAY_HEALTH_CHECKS_COUNTER]?;
125
129
  private [UnitPropertyKey.DELAY_HEALTH_CHECKS_HEALTH_BONUS]?;
126
130
  private [UnitPropertyKey.PREVENT_DEATH_HEALTH_BONUS]?;
@@ -173,16 +177,10 @@ export declare class Unit extends Handle<junit> {
173
177
  set xp(v: number);
174
178
  get primaryAttribute(): UnitAttribute;
175
179
  set primaryAttribute(primaryAttribute: UnitAttribute);
176
- get strengthBase(): number;
177
- set strengthBase(strengthBase: number);
178
180
  get strengthBonus(): number;
179
181
  get strength(): number;
180
- get agilityBase(): number;
181
- set agilityBase(agilityBase: number);
182
182
  get agilityBonus(): number;
183
183
  get agility(): number;
184
- get intelligenceBase(): number;
185
- set intelligenceBase(intelligenceBase: number);
186
184
  get intelligenceBonus(): number;
187
185
  get intelligence(): number;
188
186
  get name(): string;
@@ -216,8 +214,6 @@ export declare class Unit extends Handle<junit> {
216
214
  set facing(v: number);
217
215
  get speed(): number;
218
216
  set speed(v: number);
219
- get flyHeight(): number;
220
- set flyHeight(v: number);
221
217
  get x(): number;
222
218
  set x(v: number);
223
219
  get y(): number;
@@ -241,8 +237,6 @@ export declare class Unit extends Handle<junit> {
241
237
  get isInvulnerable(): boolean;
242
238
  get vertexColor(): Color;
243
239
  set vertexColor(v: Color);
244
- get scale(): number;
245
- set scale(v: number);
246
240
  get timeScale(): number;
247
241
  set timeScale(v: number);
248
242
  get collisionSize(): number;
@@ -277,8 +271,6 @@ export declare class Unit extends Handle<junit> {
277
271
  getAbilityRemainingCooldown(abilityId: number): number;
278
272
  startAbilityCooldown(abilityId: number, cooldown: number): void;
279
273
  endAbilityCooldown(abilityId: number): void;
280
- interruptMovement(): void;
281
- interruptAttack(): void;
282
274
  interruptCast(abilityId: number): void;
283
275
  getDistanceTo(target: Unit | Vec2): number;
284
276
  getCollisionDistanceTo(...target: [Unit] | [targetX: number, targetY: number]): number;
@@ -292,6 +284,8 @@ export declare class Unit extends Handle<junit> {
292
284
  unpauseEx(): void;
293
285
  incrementStunCounter(): void;
294
286
  decrementStunCounter(): void;
287
+ incrementForceStunCounter(): void;
288
+ decrementForceStunCounter(): void;
295
289
  set waygateActive(v: boolean);
296
290
  get waygateActive(): boolean;
297
291
  set waygateDestination(v: Vec2);
@@ -316,6 +310,7 @@ export declare class Unit extends Handle<junit> {
316
310
  static getInCollisionRange(x: number, y: number, range: number, predicate?: (unit: Unit) => boolean): Unit[];
317
311
  static getInSector(pos: Vec2, range: number, offsetAngle: number, centralAngle: number): Unit[];
318
312
  static getSelectionOf(player: Player, target?: Unit[]): Unit[];
313
+ static readonly levelChangedEvent: UnitTriggerEvent<[]>;
319
314
  static readonly deathEvent: UnitTriggerEvent<[Unit]>;
320
315
  static readonly onDecay: UnitTriggerEvent<[]>;
321
316
  static readonly onResurrect: InitializingEvent<[Unit], void>;
@@ -373,5 +368,6 @@ export declare class Unit extends Handle<junit> {
373
368
  setField(field: junitstringfield, value: string): boolean;
374
369
  toString(): string;
375
370
  static getBySyncId(syncId: UnitSyncId): Unit | undefined;
371
+ static synchronize: (player: Player, object: Unit | undefined) => Promise<Unit | undefined>;
376
372
  }
377
373
  export {};
@@ -62,6 +62,10 @@ local ____attributes = require("attributes")
62
62
  local isAttribute = ____attributes.isAttribute
63
63
  local ____ability = require("engine.internal.item.ability")
64
64
  local doUnitAbilityAction = ____ability.doUnitAbilityAction
65
+ local ____synchronization = require("engine.synchronization")
66
+ local synchronizer = ____synchronization.synchronizer
67
+ local ____linked_2Dmap = require("utility.linked-map")
68
+ local LinkedMap = ____linked_2Dmap.LinkedMap
65
69
  local match = string.match
66
70
  local ____tostring = _G.tostring
67
71
  local setUnitAnimation = SetUnitAnimation
@@ -71,16 +75,12 @@ local getUnitRealField = BlzGetUnitRealField
71
75
  local getHeroStr = GetHeroStr
72
76
  local getHeroAgi = GetHeroAgi
73
77
  local getHeroInt = GetHeroInt
74
- local setHeroStr = SetHeroStr
75
- local setHeroAgi = SetHeroAgi
76
- local setHeroInt = SetHeroInt
77
78
  local getUnitBooleanField = BlzGetUnitBooleanField
78
79
  local getUnitStringField = BlzGetUnitStringField
79
80
  local setUnitIntegerField = BlzSetUnitIntegerField
80
81
  local setUnitRealField = BlzSetUnitRealField
81
82
  local setUnitBooleanField = BlzSetUnitBooleanField
82
83
  local setUnitStringField = BlzSetUnitStringField
83
- local setUnitScale = SetUnitScale
84
84
  local setUnitPosition = SetUnitPosition
85
85
  local setUnitTimeScale = SetUnitTimeScale
86
86
  local getHandleId = GetHandleId
@@ -108,7 +108,6 @@ local getUnitWeaponStringField = BlzGetUnitWeaponStringField
108
108
  local setUnitWeaponStringField = BlzSetUnitWeaponStringField
109
109
  local getUnitAbilityLevel = GetUnitAbilityLevel
110
110
  local unitDisableAbility = BlzUnitDisableAbility
111
- local unitInterruptAttack = BlzUnitInterruptAttack
112
111
  local isUnitInvisible = IsUnitInvisible
113
112
  local isUnitVisible = IsUnitVisible
114
113
  local getUnitX = GetUnitX
@@ -410,6 +409,19 @@ function UnitWeapon.prototype.____constructor(self, unit, index)
410
409
  self.unit = unit
411
410
  self.index = index
412
411
  end
412
+ __TS__SetDescriptor(
413
+ UnitWeapon.prototype,
414
+ "isEnabled",
415
+ {
416
+ get = function(self)
417
+ return BlzGetUnitWeaponBooleanField(self.unit.handle, UNIT_WEAPON_BF_ATTACKS_ENABLED, self.index)
418
+ end,
419
+ set = function(self, isEnabled)
420
+ BlzSetUnitWeaponBooleanField(self.unit.handle, UNIT_WEAPON_BF_ATTACKS_ENABLED, self.index, isEnabled)
421
+ end
422
+ },
423
+ true
424
+ )
413
425
  __TS__SetDescriptor(
414
426
  UnitWeapon.prototype,
415
427
  "cooldown",
@@ -644,15 +656,15 @@ for ____, player in ipairs(Player.all) do
644
656
  dummies[player] = dummy
645
657
  end
646
658
  local function delayHealthChecksCallback(unit)
647
- local counter = (unit[103] or 0) - 1
659
+ local counter = (unit[104] or 0) - 1
648
660
  if counter ~= 0 then
649
- unit[103] = counter
661
+ unit[104] = counter
650
662
  return
651
663
  end
652
- unit[103] = nil
653
- local healthBonus = unit[104]
664
+ unit[104] = nil
665
+ local healthBonus = unit[105]
654
666
  if healthBonus ~= nil then
655
- unit[104] = nil
667
+ unit[105] = nil
656
668
  local handle = unit.handle
657
669
  BlzSetUnitMaxHP(
658
670
  handle,
@@ -696,24 +708,26 @@ function Unit.prototype.____constructor(self, handle)
696
708
  unitBySyncId[self.syncId] = self
697
709
  local ____ = self.abilities
698
710
  end
699
- function Unit.prototype.getEvent(self, event, collector)
700
- self.events = self.events or ({})
701
- local eventId = GetHandleId(event)
702
- if not self.events[eventId] then
703
- self.events[eventId] = __TS__New(
711
+ function Unit.prototype.getEvent(self, jevent, collector)
712
+ self.events = self.events or __TS__New(LinkedMap)
713
+ local eventId = GetHandleId(jevent)
714
+ local event = self.events:get(eventId)
715
+ if event == nil then
716
+ event = __TS__New(
704
717
  TriggerEvent,
705
718
  function(trigger)
706
- TriggerRegisterUnitEvent(trigger, self.handle, event)
719
+ TriggerRegisterUnitEvent(trigger, self.handle, jevent)
707
720
  end,
708
721
  collector or (function() return {} end)
709
722
  )
723
+ self.events:put(eventId, event)
710
724
  end
711
- return self.events[eventId]
725
+ return event
712
726
  end
713
727
  function Unit.prototype.onDestroy(self)
714
728
  local handle = self.handle
715
- self[107] = getUnitX(handle)
716
- self[108] = getUnitY(handle)
729
+ self[108] = getUnitX(handle)
730
+ self[109] = getUnitY(handle)
717
731
  if not self._owner then
718
732
  self._owner = Player:of(getOwningPlayer(handle))
719
733
  end
@@ -836,16 +850,18 @@ function Unit.prototype.queueAnimation(self, animation)
836
850
  QueueUnitAnimation(self.handle, animation)
837
851
  end
838
852
  function Unit.prototype.chooseWeapon(self, target)
839
- if target:isAllowedTarget(self, self.firstWeapon.allowedTargetCombatClassifications) then
840
- return self.firstWeapon
853
+ local firstWeapon = self.firstWeapon
854
+ if firstWeapon.isEnabled and target:isAllowedTarget(self, firstWeapon.allowedTargetCombatClassifications) then
855
+ return firstWeapon
841
856
  end
842
- if target:isAllowedTarget(target, self.secondWeapon.allowedTargetCombatClassifications) then
843
- return self.secondWeapon
857
+ local secondWeapon = self.secondWeapon
858
+ if secondWeapon.isEnabled and target:isAllowedTarget(target, secondWeapon.allowedTargetCombatClassifications) then
859
+ return secondWeapon
844
860
  end
845
861
  return nil
846
862
  end
847
863
  function Unit.prototype.delayHealthChecks(self)
848
- self[103] = (self[103] or 0) + 1
864
+ self[104] = (self[104] or 0) + 1
849
865
  Timer:run(delayHealthChecksCallback, self)
850
866
  end
851
867
  function Unit.prototype.setPosition(self, x, y)
@@ -963,24 +979,6 @@ end
963
979
  function Unit.prototype.endAbilityCooldown(self, abilityId)
964
980
  BlzEndUnitAbilityCooldown(self.handle, abilityId)
965
981
  end
966
- function Unit.prototype.interruptMovement(self)
967
- local handle = self.handle
968
- unitDisableAbility(
969
- handle,
970
- fourCC("Amov"),
971
- true,
972
- false
973
- )
974
- unitDisableAbility(
975
- handle,
976
- fourCC("Amov"),
977
- false,
978
- false
979
- )
980
- end
981
- function Unit.prototype.interruptAttack(self)
982
- unitInterruptAttack(self.handle)
983
- end
984
982
  function Unit.prototype.interruptCast(self, abilityId)
985
983
  local handle = self.handle
986
984
  unitDisableAbility(handle, abilityId, true, false)
@@ -1051,18 +1049,44 @@ function Unit.prototype.unpauseEx(self)
1051
1049
  end
1052
1050
  function Unit.prototype.incrementStunCounter(self)
1053
1051
  local stunCounter = self[102] or 0
1054
- if not self[101] or stunCounter >= 0 then
1052
+ if not self[101] and (self[103] or 0) <= 0 or stunCounter >= 0 then
1055
1053
  BlzPauseUnitEx(self.handle, true)
1056
1054
  end
1057
1055
  self[102] = stunCounter + 1
1058
1056
  end
1059
1057
  function Unit.prototype.decrementStunCounter(self)
1060
1058
  local stunCounter = self[102] or 0
1061
- if not self[101] or stunCounter >= 1 then
1059
+ if not self[101] and (self[103] or 0) <= 0 or stunCounter >= 1 then
1062
1060
  BlzPauseUnitEx(self.handle, false)
1063
1061
  end
1064
1062
  self[102] = stunCounter - 1
1065
1063
  end
1064
+ function Unit.prototype.incrementForceStunCounter(self)
1065
+ local forceStunCounter = self[103] or 0
1066
+ if forceStunCounter == 0 then
1067
+ local handle = self.handle
1068
+ if not self[101] then
1069
+ for _ = self[102] or 0, -1 do
1070
+ BlzPauseUnitEx(handle, true)
1071
+ end
1072
+ end
1073
+ BlzPauseUnitEx(handle, true)
1074
+ end
1075
+ self[103] = forceStunCounter + 1
1076
+ end
1077
+ function Unit.prototype.decrementForceStunCounter(self)
1078
+ local forceStunCounter = self[103] or 0
1079
+ if forceStunCounter == 1 then
1080
+ local handle = self.handle
1081
+ if not self[101] then
1082
+ for _ = self[102] or 0, -1 do
1083
+ BlzPauseUnitEx(handle, false)
1084
+ end
1085
+ end
1086
+ BlzPauseUnitEx(handle, false)
1087
+ end
1088
+ self[103] = forceStunCounter - 1
1089
+ end
1066
1090
  function Unit.create(self, owner, id, x, y, facing, skinId)
1067
1091
  local handle = skinId and BlzCreateUnitWithSkin(
1068
1092
  owner.handle,
@@ -1349,19 +1373,6 @@ __TS__SetDescriptor(
1349
1373
  },
1350
1374
  true
1351
1375
  )
1352
- __TS__SetDescriptor(
1353
- Unit.prototype,
1354
- "strengthBase",
1355
- {
1356
- get = function(self)
1357
- return getHeroStr(self.handle, false)
1358
- end,
1359
- set = function(self, strengthBase)
1360
- setHeroStr(self.handle, strengthBase, true)
1361
- end
1362
- },
1363
- true
1364
- )
1365
1376
  __TS__SetDescriptor(
1366
1377
  Unit.prototype,
1367
1378
  "strengthBonus",
@@ -1379,19 +1390,6 @@ __TS__SetDescriptor(
1379
1390
  end},
1380
1391
  true
1381
1392
  )
1382
- __TS__SetDescriptor(
1383
- Unit.prototype,
1384
- "agilityBase",
1385
- {
1386
- get = function(self)
1387
- return getHeroAgi(self.handle, false)
1388
- end,
1389
- set = function(self, agilityBase)
1390
- setHeroAgi(self.handle, agilityBase, true)
1391
- end
1392
- },
1393
- true
1394
- )
1395
1393
  __TS__SetDescriptor(
1396
1394
  Unit.prototype,
1397
1395
  "agilityBonus",
@@ -1409,19 +1407,6 @@ __TS__SetDescriptor(
1409
1407
  end},
1410
1408
  true
1411
1409
  )
1412
- __TS__SetDescriptor(
1413
- Unit.prototype,
1414
- "intelligenceBase",
1415
- {
1416
- get = function(self)
1417
- return getHeroInt(self.handle, false)
1418
- end,
1419
- set = function(self, intelligenceBase)
1420
- setHeroInt(self.handle, intelligenceBase, true)
1421
- end
1422
- },
1423
- true
1424
- )
1425
1410
  __TS__SetDescriptor(
1426
1411
  Unit.prototype,
1427
1412
  "intelligenceBonus",
@@ -1470,7 +1455,7 @@ __TS__SetDescriptor(
1470
1455
  "isTeamGlowVisible",
1471
1456
  {
1472
1457
  get = function(self)
1473
- return not self[106]
1458
+ return not self[107]
1474
1459
  end,
1475
1460
  set = function(self, isTeamGlowVisible)
1476
1461
  BlzShowUnitTeamGlow(self.handle, isTeamGlowVisible)
@@ -1480,7 +1465,7 @@ __TS__SetDescriptor(
1480
1465
  else
1481
1466
  ____temp_7 = nil
1482
1467
  end
1483
- self[106] = ____temp_7
1468
+ self[107] = ____temp_7
1484
1469
  end
1485
1470
  },
1486
1471
  true
@@ -1490,7 +1475,7 @@ __TS__SetDescriptor(
1490
1475
  "color",
1491
1476
  {set = function(self, color)
1492
1477
  SetUnitColor(self.handle, color.handle)
1493
- if self[106] then
1478
+ if self[107] then
1494
1479
  BlzShowUnitTeamGlow(self.handle, false)
1495
1480
  end
1496
1481
  end},
@@ -1514,14 +1499,14 @@ __TS__SetDescriptor(
1514
1499
  "maxHealth",
1515
1500
  {
1516
1501
  get = function(self)
1517
- return BlzGetUnitMaxHP(self.handle) - (self[104] or 0) - (self[105] or 0)
1502
+ return BlzGetUnitMaxHP(self.handle) - (self[105] or 0) - (self[106] or 0)
1518
1503
  end,
1519
1504
  set = function(self, maxHealth)
1520
- if maxHealth < 1 and self[103] ~= nil then
1521
- self[104] = (self[104] or 0) + (1 - maxHealth)
1505
+ if maxHealth < 1 and self[104] ~= nil then
1506
+ self[105] = (self[105] or 0) + (1 - maxHealth)
1522
1507
  maxHealth = 1
1523
1508
  end
1524
- BlzSetUnitMaxHP(self.handle, maxHealth + (self[105] or 0))
1509
+ BlzSetUnitMaxHP(self.handle, maxHealth + (self[106] or 0))
1525
1510
  end
1526
1511
  },
1527
1512
  true
@@ -1563,10 +1548,10 @@ __TS__SetDescriptor(
1563
1548
  "health",
1564
1549
  {
1565
1550
  get = function(self)
1566
- return GetWidgetLife(self.handle) - (self[105] or 0)
1551
+ return GetWidgetLife(self.handle) - (self[106] or 0)
1567
1552
  end,
1568
1553
  set = function(self, health)
1569
- SetWidgetLife(self.handle, health + (self[105] or 0))
1554
+ SetWidgetLife(self.handle, health + (self[106] or 0))
1570
1555
  end
1571
1556
  },
1572
1557
  true
@@ -1642,25 +1627,12 @@ __TS__SetDescriptor(
1642
1627
  },
1643
1628
  true
1644
1629
  )
1645
- __TS__SetDescriptor(
1646
- Unit.prototype,
1647
- "flyHeight",
1648
- {
1649
- get = function(self)
1650
- return getUnitFlyHeight(self.handle)
1651
- end,
1652
- set = function(self, v)
1653
- SetUnitFlyHeight(self.handle, v, 100000)
1654
- end
1655
- },
1656
- true
1657
- )
1658
1630
  __TS__SetDescriptor(
1659
1631
  Unit.prototype,
1660
1632
  "x",
1661
1633
  {
1662
1634
  get = function(self)
1663
- return self[107] or getUnitX(self.handle)
1635
+ return self[108] or getUnitX(self.handle)
1664
1636
  end,
1665
1637
  set = function(self, v)
1666
1638
  SetUnitX(self.handle, v)
@@ -1673,7 +1645,7 @@ __TS__SetDescriptor(
1673
1645
  "y",
1674
1646
  {
1675
1647
  get = function(self)
1676
- return self[108] or getUnitY(self.handle)
1648
+ return self[109] or getUnitY(self.handle)
1677
1649
  end,
1678
1650
  set = function(self, v)
1679
1651
  SetUnitY(self.handle, v)
@@ -1778,14 +1750,18 @@ __TS__SetDescriptor(
1778
1750
  local handle = self.handle
1779
1751
  if isPaused and not IsUnitPaused(handle) then
1780
1752
  self[101] = true
1781
- for _ = self[102] or 0, -1 do
1782
- BlzPauseUnitEx(handle, true)
1753
+ if (self[103] or 0) <= 0 then
1754
+ for _ = self[102] or 0, -1 do
1755
+ BlzPauseUnitEx(handle, true)
1756
+ end
1783
1757
  end
1784
1758
  PauseUnit(handle, true)
1785
1759
  elseif not isPaused and IsUnitPaused(handle) then
1786
1760
  PauseUnit(handle, false)
1787
- for _ = self[102] or 0, -1 do
1788
- BlzPauseUnitEx(handle, false)
1761
+ if (self[103] or 0) <= 0 then
1762
+ for _ = self[102] or 0, -1 do
1763
+ BlzPauseUnitEx(handle, false)
1764
+ end
1789
1765
  end
1790
1766
  self[101] = nil
1791
1767
  end
@@ -1843,20 +1819,6 @@ __TS__SetDescriptor(
1843
1819
  },
1844
1820
  true
1845
1821
  )
1846
- __TS__SetDescriptor(
1847
- Unit.prototype,
1848
- "scale",
1849
- {
1850
- get = function(self)
1851
- return getUnitRealField(self.handle, UNIT_RF_SCALING_VALUE)
1852
- end,
1853
- set = function(self, v)
1854
- setUnitScale(self.handle, v, v, v)
1855
- setUnitRealField(self.handle, UNIT_RF_SCALING_VALUE, v)
1856
- end
1857
- },
1858
- true
1859
- )
1860
1822
  __TS__SetDescriptor(
1861
1823
  Unit.prototype,
1862
1824
  "timeScale",
@@ -2152,6 +2114,11 @@ __TS__SetDescriptor(
2152
2114
  end},
2153
2115
  true
2154
2116
  )
2117
+ Unit.levelChangedEvent = __TS__New(
2118
+ ____exports.UnitTriggerEvent,
2119
+ EVENT_PLAYER_HERO_LEVEL,
2120
+ function() return ____exports.Unit:of(getTriggerUnit()) end
2121
+ )
2155
2122
  Unit.deathEvent = __TS__New(
2156
2123
  ____exports.UnitTriggerEvent,
2157
2124
  EVENT_PLAYER_UNIT_DEATH,
@@ -2468,12 +2435,7 @@ Unit.onDamaging = (function()
2468
2435
  preventRetaliation = damagingEventPreventRetaliation
2469
2436
  }
2470
2437
  if data.isAttack and source then
2471
- local weapon = BlzGetUnitWeaponBooleanField(source.handle, UNIT_WEAPON_BF_ATTACKS_ENABLED, 1) and (BlzGetUnitWeaponBooleanField(source.handle, UNIT_WEAPON_BF_ATTACKS_ENABLED, 0) and -1 or 1) or 0
2472
- if weapon == -1 then
2473
- local targetsAllowed = BlzGetUnitWeaponIntegerField(source.handle, UNIT_WEAPON_IF_ATTACK_TARGETS_ALLOWED, 0)
2474
- weapon = 0
2475
- end
2476
- data.weapon = assert(source.weapons[weapon + 1])
2438
+ data.weapon = source:chooseWeapon(target)
2477
2439
  end
2478
2440
  if not data.isAttack or not source or not source._attackHandlers then
2479
2441
  invoke(
@@ -2618,7 +2580,7 @@ Unit.onDamage = __TS__New(
2618
2580
  invoke(event, source, target, evData)
2619
2581
  if evData[0] ~= nil and target.health - evData.amount < 0.405 then
2620
2582
  local bonusHealth = math.ceil(evData.amount)
2621
- target[105] = (target[105] or 0) + bonusHealth
2583
+ target[106] = (target[106] or 0) + bonusHealth
2622
2584
  BlzSetUnitMaxHP(
2623
2585
  target.handle,
2624
2586
  BlzGetUnitMaxHP(target.handle) + bonusHealth
@@ -2632,7 +2594,7 @@ Unit.onDamage = __TS__New(
2632
2594
  evData[0],
2633
2595
  table.unpack(evData, 1 + 1, 1 + (evData[1] or 0))
2634
2596
  )
2635
- target[105] = (target[105] or 0) - bonusHealth
2597
+ target[106] = (target[106] or 0) - bonusHealth
2636
2598
  SetWidgetLife(
2637
2599
  target.handle,
2638
2600
  GetWidgetLife(target.handle) - bonusHealth
@@ -2782,6 +2744,10 @@ __TS__ObjectDefineProperty(
2782
2744
  rawset(self, "destroyEvent", destroyEvent)
2783
2745
  return destroyEvent
2784
2746
  end}
2747
+ )
2748
+ Unit.synchronize = synchronizer(
2749
+ function(unit) return unit.syncId end,
2750
+ function(syncId) return unitBySyncId[syncId] end
2785
2751
  );
2786
2752
  (function(self)
2787
2753
  local leaveAbilityIds = postcompile(function()
@@ -3,6 +3,7 @@ import { Unit } from "../core/types/unit";
3
3
  import { Async } from "../core/types/async";
4
4
  import { Event, TriggerEvent } from "../event";
5
5
  import { GraphicsMode } from "./index";
6
+ import { Color } from "../core/types/color";
6
7
  export declare class LocalClient {
7
8
  private constructor();
8
9
  static readonly locale: string;
@@ -11,6 +12,7 @@ export declare class LocalClient {
11
12
  static get isHD(): boolean;
12
13
  static get graphicsMode(): GraphicsMode;
13
14
  static get isActive(): boolean;
15
+ static pingMinimap(x: number, y: number, duration: number, ...parameters: [] | [red: number, green: number, blue: number, flashy?: boolean] | [color: Color, flashy?: boolean]): void;
14
16
  static get mouseFocusUnit(): Async<Unit> | undefined;
15
17
  static get mainSelectedUnit(): Async<Unit> | undefined;
16
18
  static get mainSelectedUnitChangeEvent(): Event<[