warscript 0.0.1-dev.1d1ce87 → 0.0.1-dev.1d3eae2

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 (62) 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/destroyable.d.ts +1 -0
  8. package/destroyable.lua +9 -0
  9. package/engine/behavior.d.ts +10 -2
  10. package/engine/behavior.lua +157 -76
  11. package/engine/behaviour/ability/apply-buff.lua +4 -4
  12. package/engine/behaviour/ability/remove-buffs.d.ts +9 -0
  13. package/engine/behaviour/ability/remove-buffs.lua +21 -0
  14. package/engine/behaviour/ability.d.ts +2 -1
  15. package/engine/behaviour/ability.lua +2 -1
  16. package/engine/behaviour/unit/stun-immunity.d.ts +6 -4
  17. package/engine/behaviour/unit/stun-immunity.lua +1 -1
  18. package/engine/behaviour/unit.d.ts +7 -3
  19. package/engine/behaviour/unit.lua +89 -22
  20. package/engine/buff.d.ts +15 -2
  21. package/engine/buff.lua +95 -17
  22. package/engine/internal/object-data/mana-regeneration-rate-increase-factor.d.ts +2 -0
  23. package/engine/internal/object-data/mana-regeneration-rate-increase-factor.lua +16 -0
  24. package/engine/internal/unit/ability.lua +3 -3
  25. package/engine/internal/unit/bonus.d.ts +2 -0
  26. package/engine/internal/unit/bonus.lua +10 -0
  27. package/engine/internal/unit/fly-height.d.ts +7 -0
  28. package/engine/internal/unit/fly-height.lua +20 -0
  29. package/engine/internal/unit/main-selected.lua +12 -27
  30. package/engine/internal/unit/scale.d.ts +7 -0
  31. package/engine/internal/unit/scale.lua +20 -0
  32. package/engine/internal/unit-missile-launch.lua +41 -23
  33. package/engine/internal/unit.d.ts +13 -10
  34. package/engine/internal/unit.lua +83 -64
  35. package/engine/local-client.d.ts +2 -0
  36. package/engine/local-client.lua +30 -0
  37. package/engine/object-data/auxiliary/health-regeneration-type.d.ts +8 -0
  38. package/engine/object-data/auxiliary/health-regeneration-type.lua +2 -0
  39. package/engine/object-data/entry/ability-type/mana-regeneration.d.ts +8 -0
  40. package/engine/object-data/entry/ability-type/mana-regeneration.lua +26 -0
  41. package/engine/object-data/entry/destructible-type.d.ts +27 -1
  42. package/engine/object-data/entry/destructible-type.lua +155 -0
  43. package/engine/object-data/entry/unit-type.d.ts +4 -0
  44. package/engine/object-data/entry/unit-type.lua +76 -32
  45. package/engine/object-field/unit.d.ts +20 -5
  46. package/engine/object-field/unit.lua +61 -0
  47. package/engine/object-field.d.ts +7 -1
  48. package/engine/object-field.lua +232 -111
  49. package/engine/standard/fields/ability.d.ts +2 -2
  50. package/engine/standard/fields/ability.lua +2 -2
  51. package/engine/standard/fields/unit.d.ts +6 -1
  52. package/engine/standard/fields/unit.lua +9 -0
  53. package/engine/synchronization.d.ts +11 -0
  54. package/engine/synchronization.lua +77 -0
  55. package/engine/text-tag.lua +2 -1
  56. package/engine/unit.d.ts +2 -0
  57. package/engine/unit.lua +2 -0
  58. package/net/socket.lua +1 -1
  59. package/package.json +2 -2
  60. package/utility/callback-array.lua +1 -1
  61. package/utility/linked-set.d.ts +1 -0
  62. package/utility/linked-set.lua +19 -1
@@ -0,0 +1,16 @@
1
+ local ____exports = {}
2
+ local ____mana_2Dregeneration = require("engine.object-data.entry.ability-type.mana-regeneration")
3
+ local ManaRegenerationAbilityType = ____mana_2Dregeneration.ManaRegenerationAbilityType
4
+ ---
5
+ -- @internal For use by internal systems.
6
+ ____exports.MANA_REGENERATION_RATE_INCREASE_FACTOR_DUMMY_ABILITY_TYPE_ID = compiletime(function()
7
+ local abilityType = ManaRegenerationAbilityType:create()
8
+ abilityType.isInternal = true
9
+ abilityType.isButtonVisible = false
10
+ abilityType.manaRegenerationRateIncreaseFactor = 4
11
+ return abilityType.id
12
+ end)
13
+ ---
14
+ -- @internal For use by internal systems.
15
+ ____exports.MANA_REGENERATION_RATE_INCREASE_FACTOR_ABILITY_FIELD = ABILITY_RLF_MANA_REGENERATION_BONUS_AS_FRACTION_OF_NORMAL
16
+ return ____exports
@@ -398,7 +398,7 @@ local function invokeImpactEvent(unit, ability, ...)
398
398
  eventInvoke(internalAbilityImpactEvent, unit, ability, ...)
399
399
  end
400
400
  internalAbilityChannelingStartEvent:addListener(
401
- -999999,
401
+ 999999,
402
402
  function(unit, ability, ...)
403
403
  ability[impactCallbackIdAttribute] = Timer:run(invokeImpactEvent, unit, ability, ...)
404
404
  end
@@ -409,8 +409,8 @@ local function consumeImpactCallback(_, ability)
409
409
  consumeZeroTimerCallback(impactCallbackId)
410
410
  end
411
411
  end
412
- internalAbilityChannelingFinishEvent:addListener(-999999, consumeImpactCallback)
413
- internalAbilityStopEvent:addListener(-999999, consumeImpactCallback)
412
+ internalAbilityChannelingFinishEvent:addListener(999999, consumeImpactCallback)
413
+ internalAbilityStopEvent:addListener(999999, consumeImpactCallback)
414
414
  rawset(
415
415
  Unit,
416
416
  "abilityImpactEvent",
@@ -12,6 +12,7 @@ export type UnitAutoAttackDamageBonusId = UnitBonusId<"autoAttackDamage">;
12
12
  export type UnitDamageFactorBonusId = UnitBonusId<"damageFactor">;
13
13
  export type UnitReceivedDamageFactorBonusId = UnitBonusId<"receivedDamageFactor">;
14
14
  export type UnitEvasionProbabilityBonusId = UnitBonusId<"evasionProbability">;
15
+ export type UnitManaRegenerationRateFactorBonusId = UnitBonusId<"manaRegenerationRateFactor">;
15
16
  export type UnitBonusType<Id extends UnitBonusId = UnitBonusId> = ({
16
17
  abilityTypeId: AbilityTypeId;
17
18
  field: jabilityintegerlevelfield;
@@ -36,6 +37,7 @@ export declare namespace UnitBonusType {
36
37
  const DAMAGE_FACTOR: UnitBonusType<UnitReceivedDamageFactorBonusId>;
37
38
  const RECEIVED_DAMAGE_FACTOR: UnitBonusType<UnitReceivedDamageFactorBonusId>;
38
39
  const EVASION_PROBABILITY: UnitBonusType<UnitEvasionProbabilityBonusId>;
40
+ const MANA_REGENERATION_RATE_FACTOR: UnitBonusType<UnitManaRegenerationRateFactorBonusId>;
39
41
  }
40
42
  export declare const addUnitBonus: <Id extends UnitBonusId>(unit: Unit, bonusType: UnitBonusType<Id>, value: number) => Id;
41
43
  export declare const removeUnitBonus: <Id extends UnitBonusId>(unit: Unit, bonusType: UnitBonusType<Id>, id: Id) => boolean;
@@ -24,6 +24,9 @@ local MOVEMENT_SPEED_INCREASE_FACTOR_DUMMY_ABILITY_TYPE_ID = ____movement_2Dspee
24
24
  local ____evasion_2Dprobability = require("engine.internal.object-data.evasion-probability")
25
25
  local EVASION_PROBABILITY_ABILITY_FIELD = ____evasion_2Dprobability.EVASION_PROBABILITY_ABILITY_FIELD
26
26
  local EVASION_PROBABILITY_DUMMY_ABILITY_TYPE_ID = ____evasion_2Dprobability.EVASION_PROBABILITY_DUMMY_ABILITY_TYPE_ID
27
+ local ____mana_2Dregeneration_2Drate_2Dincrease_2Dfactor = require("engine.internal.object-data.mana-regeneration-rate-increase-factor")
28
+ local MANA_REGENERATION_RATE_INCREASE_FACTOR_ABILITY_FIELD = ____mana_2Dregeneration_2Drate_2Dincrease_2Dfactor.MANA_REGENERATION_RATE_INCREASE_FACTOR_ABILITY_FIELD
29
+ local MANA_REGENERATION_RATE_INCREASE_FACTOR_DUMMY_ABILITY_TYPE_ID = ____mana_2Dregeneration_2Drate_2Dincrease_2Dfactor.MANA_REGENERATION_RATE_INCREASE_FACTOR_DUMMY_ABILITY_TYPE_ID
27
30
  local damageFactorByUnit = {}
28
31
  local receivedDamageFactorByUnit = {}
29
32
  local function atLeastOnceProbability(array)
@@ -73,6 +76,13 @@ do
73
76
  reduce = atLeastOnceProbability,
74
77
  initialValue = 0
75
78
  }
79
+ UnitBonusType.MANA_REGENERATION_RATE_FACTOR = {
80
+ abilityTypeId = MANA_REGENERATION_RATE_INCREASE_FACTOR_DUMMY_ABILITY_TYPE_ID,
81
+ field = MANA_REGENERATION_RATE_INCREASE_FACTOR_ABILITY_FIELD,
82
+ integer = false,
83
+ reduce = sum,
84
+ initialValue = 0
85
+ }
76
86
  end
77
87
  local bonusesByUnitByBonusType = {}
78
88
  local nextId = 1
@@ -0,0 +1,7 @@
1
+ /** @noSelfInFile */
2
+ declare module "../unit" {
3
+ interface Unit {
4
+ flyHeight: number;
5
+ }
6
+ }
7
+ export {};
@@ -0,0 +1,20 @@
1
+ local ____lualib = require("lualib_bundle")
2
+ local __TS__ObjectDefineProperty = ____lualib.__TS__ObjectDefineProperty
3
+ local ____exports = {}
4
+ local ____unit = require("engine.internal.unit")
5
+ local Unit = ____unit.Unit
6
+ local ____unit = require("engine.standard.fields.unit")
7
+ local FLY_HEIGHT_UNIT_FLOAT_FIELD = ____unit.FLY_HEIGHT_UNIT_FLOAT_FIELD
8
+ __TS__ObjectDefineProperty(
9
+ Unit.prototype,
10
+ "flyHeight",
11
+ {
12
+ get = function(self)
13
+ return FLY_HEIGHT_UNIT_FLOAT_FIELD:getValue(self)
14
+ end,
15
+ set = function(self, value)
16
+ FLY_HEIGHT_UNIT_FLOAT_FIELD:setValue(self, value)
17
+ end
18
+ }
19
+ )
20
+ return ____exports
@@ -1,46 +1,31 @@
1
1
  local ____lualib = require("lualib_bundle")
2
2
  local __TS__New = ____lualib.__TS__New
3
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
4
  local ____local_2Dclient = require("engine.local-client")
10
5
  local LocalClient = ____local_2Dclient.LocalClient
11
6
  local ____unit = require("engine.internal.unit")
12
7
  local Unit = ____unit.Unit
13
8
  local ____event = require("event")
14
9
  local Event = ____event.Event
10
+ local ____synchronization = require("engine.synchronization")
11
+ local ObjectBus = ____synchronization.ObjectBus
15
12
  local mainSelectedUnitChangeEvent = __TS__New(Event)
16
13
  rawset(Unit, "mainSelectedUnitChangeEvent", mainSelectedUnitChangeEvent)
17
14
  local mainSelectedUnitByPlayer = {}
18
- local syncSlider = BlzCreateFrameByType(
19
- "SLIDER",
20
- "UnitSyncId",
21
- BlzGetOriginFrame(ORIGIN_FRAME_WORLD_FRAME, 0),
22
- "",
23
- 0
15
+ local unitBus = __TS__New(
16
+ ObjectBus,
17
+ function(unit) return unit.syncId end,
18
+ function(syncId) return Unit:getBySyncId(syncId) end
24
19
  )
25
- BlzFrameSetMinMaxValue(syncSlider, MINIMUM_INTEGER, MAXIMUM_INTEGER)
26
20
  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)
21
+ unitBus:send(LocalClient.mainSelectedUnit)
30
22
  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
23
+ unitBus.event:addListener(function(player, unit)
24
+ if unit ~= mainSelectedUnitByPlayer[player] then
25
+ mainSelectedUnitByPlayer[player] = unit
26
+ Event.invoke(mainSelectedUnitChangeEvent, player)
42
27
  end
43
- )
28
+ end)
44
29
  rawset(
45
30
  Unit,
46
31
  "getMainSelectedOf",
@@ -0,0 +1,7 @@
1
+ /** @noSelfInFile */
2
+ declare module "../unit" {
3
+ interface Unit {
4
+ scale: number;
5
+ }
6
+ }
7
+ export {};
@@ -0,0 +1,20 @@
1
+ local ____lualib = require("lualib_bundle")
2
+ local __TS__ObjectDefineProperty = ____lualib.__TS__ObjectDefineProperty
3
+ local ____exports = {}
4
+ local ____unit = require("engine.internal.unit")
5
+ local Unit = ____unit.Unit
6
+ local ____unit = require("engine.standard.fields.unit")
7
+ local SCALING_VALUE_UNIT_FLOAT_FIELD = ____unit.SCALING_VALUE_UNIT_FLOAT_FIELD
8
+ __TS__ObjectDefineProperty(
9
+ Unit.prototype,
10
+ "scale",
11
+ {
12
+ get = function(self)
13
+ return SCALING_VALUE_UNIT_FLOAT_FIELD:getValue(self)
14
+ end,
15
+ set = function(self, value)
16
+ SCALING_VALUE_UNIT_FLOAT_FIELD:setValue(self, value)
17
+ end
18
+ }
19
+ )
20
+ return ____exports
@@ -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"),
@@ -30,35 +37,46 @@ local instantOrderIds = luaSetOf(
30
37
  orderId("unimmolation")
31
38
  )
32
39
  local function reset(source, orderId)
33
- if not (instantOrderIds[orderId] ~= nil) then
34
- local eventTimer = eventTimerByUnit[source]
35
- if eventTimer then
36
- eventTimer:destroy()
37
- eventTimerByUnit[source] = nil
38
- end
40
+ if not (instantOrderIds[orderId] ~= nil) and units:remove(source) then
41
+ source[targetAttribute] = nil
42
+ source[impactDelayAttribute] = nil
43
+ source[passedTimeAttribute] = nil
39
44
  end
40
45
  end
41
46
  Unit.onImmediateOrder:addListener(reset)
42
47
  Unit.onPointOrder:addListener(reset)
43
48
  Unit.onTargetOrder:addListener(reset)
44
- local function timerCallback(source, target)
45
- eventTimerByUnit[source] = nil
46
- Event.invoke(autoAttackFinishEvent, source, target)
49
+ local timerPeriod = 1 / 64
50
+ local function invokeEvent(unit)
51
+ units:remove(unit)
52
+ local target = unit[targetAttribute]
53
+ unit[targetAttribute] = nil
54
+ unit[impactDelayAttribute] = nil
55
+ unit[passedTimeAttribute] = nil
56
+ Event.invoke(autoAttackFinishEvent, unit, target)
57
+ end
58
+ local function checkUnit(unit)
59
+ local passedTime = unit[passedTimeAttribute] + timerPeriod
60
+ local impactDelay = unit[impactDelayAttribute]
61
+ if passedTime >= impactDelay and ceil(passedTime / 0.02) >= ceil(impactDelay / 0.02) then
62
+ invokeEvent(unit)
63
+ else
64
+ unit[passedTimeAttribute] = passedTime
65
+ end
47
66
  end
67
+ Timer.onPeriod[timerPeriod]:addListener(function()
68
+ units:forEach(checkUnit)
69
+ end)
48
70
  Unit.autoAttackStartEvent:addListener(
49
- 4,
71
+ 999999,
50
72
  function(source, target)
51
- local attackPoint = (source:chooseWeapon(target) or source.firstWeapon).impactDelay
52
- local timer = Timer:simple(
53
- attackPoint + min(
54
- compiletime(1 / 64),
55
- attackPoint / 2
56
- ),
57
- timerCallback,
58
- source,
59
- target
60
- )
61
- eventTimerByUnit[source] = timer
73
+ if source[targetAttribute] ~= nil then
74
+ invokeEvent(source)
75
+ end
76
+ source[targetAttribute] = target
77
+ source[impactDelayAttribute] = (source:chooseWeapon(target) or source.firstWeapon).impactDelay
78
+ source[passedTimeAttribute] = -timerPeriod
79
+ units:add(source)
62
80
  end
63
81
  )
64
82
  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]?;
@@ -216,8 +220,6 @@ export declare class Unit extends Handle<junit> {
216
220
  set facing(v: number);
217
221
  get speed(): number;
218
222
  set speed(v: number);
219
- get flyHeight(): number;
220
- set flyHeight(v: number);
221
223
  get x(): number;
222
224
  set x(v: number);
223
225
  get y(): number;
@@ -241,8 +243,6 @@ export declare class Unit extends Handle<junit> {
241
243
  get isInvulnerable(): boolean;
242
244
  get vertexColor(): Color;
243
245
  set vertexColor(v: Color);
244
- get scale(): number;
245
- set scale(v: number);
246
246
  get timeScale(): number;
247
247
  set timeScale(v: number);
248
248
  get collisionSize(): number;
@@ -292,6 +292,8 @@ export declare class Unit extends Handle<junit> {
292
292
  unpauseEx(): void;
293
293
  incrementStunCounter(): void;
294
294
  decrementStunCounter(): void;
295
+ incrementForceStunCounter(): void;
296
+ decrementForceStunCounter(): void;
295
297
  set waygateActive(v: boolean);
296
298
  get waygateActive(): boolean;
297
299
  set waygateDestination(v: Vec2);
@@ -373,5 +375,6 @@ export declare class Unit extends Handle<junit> {
373
375
  setField(field: junitstringfield, value: string): boolean;
374
376
  toString(): string;
375
377
  static getBySyncId(syncId: UnitSyncId): Unit | undefined;
378
+ static synchronize: (player: Player, object: Unit | undefined) => Promise<Unit | undefined>;
376
379
  }
377
380
  export {};
@@ -62,6 +62,8 @@ 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
65
67
  local match = string.match
66
68
  local ____tostring = _G.tostring
67
69
  local setUnitAnimation = SetUnitAnimation
@@ -410,6 +412,19 @@ function UnitWeapon.prototype.____constructor(self, unit, index)
410
412
  self.unit = unit
411
413
  self.index = index
412
414
  end
415
+ __TS__SetDescriptor(
416
+ UnitWeapon.prototype,
417
+ "isEnabled",
418
+ {
419
+ get = function(self)
420
+ return BlzGetUnitWeaponBooleanField(self.unit.handle, UNIT_WEAPON_BF_ATTACKS_ENABLED, self.index)
421
+ end,
422
+ set = function(self, isEnabled)
423
+ BlzSetUnitWeaponBooleanField(self.unit.handle, UNIT_WEAPON_BF_ATTACKS_ENABLED, self.index, isEnabled)
424
+ end
425
+ },
426
+ true
427
+ )
413
428
  __TS__SetDescriptor(
414
429
  UnitWeapon.prototype,
415
430
  "cooldown",
@@ -644,15 +659,15 @@ for ____, player in ipairs(Player.all) do
644
659
  dummies[player] = dummy
645
660
  end
646
661
  local function delayHealthChecksCallback(unit)
647
- local counter = (unit[103] or 0) - 1
662
+ local counter = (unit[104] or 0) - 1
648
663
  if counter ~= 0 then
649
- unit[103] = counter
664
+ unit[104] = counter
650
665
  return
651
666
  end
652
- unit[103] = nil
653
- local healthBonus = unit[104]
667
+ unit[104] = nil
668
+ local healthBonus = unit[105]
654
669
  if healthBonus ~= nil then
655
- unit[104] = nil
670
+ unit[105] = nil
656
671
  local handle = unit.handle
657
672
  BlzSetUnitMaxHP(
658
673
  handle,
@@ -712,8 +727,8 @@ function Unit.prototype.getEvent(self, event, collector)
712
727
  end
713
728
  function Unit.prototype.onDestroy(self)
714
729
  local handle = self.handle
715
- self[107] = getUnitX(handle)
716
- self[108] = getUnitY(handle)
730
+ self[108] = getUnitX(handle)
731
+ self[109] = getUnitY(handle)
717
732
  if not self._owner then
718
733
  self._owner = Player:of(getOwningPlayer(handle))
719
734
  end
@@ -836,16 +851,18 @@ function Unit.prototype.queueAnimation(self, animation)
836
851
  QueueUnitAnimation(self.handle, animation)
837
852
  end
838
853
  function Unit.prototype.chooseWeapon(self, target)
839
- if target:isAllowedTarget(self, self.firstWeapon.allowedTargetCombatClassifications) then
840
- return self.firstWeapon
854
+ local firstWeapon = self.firstWeapon
855
+ if firstWeapon.isEnabled and target:isAllowedTarget(self, firstWeapon.allowedTargetCombatClassifications) then
856
+ return firstWeapon
841
857
  end
842
- if target:isAllowedTarget(target, self.secondWeapon.allowedTargetCombatClassifications) then
843
- return self.secondWeapon
858
+ local secondWeapon = self.secondWeapon
859
+ if secondWeapon.isEnabled and target:isAllowedTarget(target, secondWeapon.allowedTargetCombatClassifications) then
860
+ return secondWeapon
844
861
  end
845
862
  return nil
846
863
  end
847
864
  function Unit.prototype.delayHealthChecks(self)
848
- self[103] = (self[103] or 0) + 1
865
+ self[104] = (self[104] or 0) + 1
849
866
  Timer:run(delayHealthChecksCallback, self)
850
867
  end
851
868
  function Unit.prototype.setPosition(self, x, y)
@@ -1051,18 +1068,44 @@ function Unit.prototype.unpauseEx(self)
1051
1068
  end
1052
1069
  function Unit.prototype.incrementStunCounter(self)
1053
1070
  local stunCounter = self[102] or 0
1054
- if not self[101] or stunCounter >= 0 then
1071
+ if not self[101] and (self[103] or 0) <= 0 or stunCounter >= 0 then
1055
1072
  BlzPauseUnitEx(self.handle, true)
1056
1073
  end
1057
1074
  self[102] = stunCounter + 1
1058
1075
  end
1059
1076
  function Unit.prototype.decrementStunCounter(self)
1060
1077
  local stunCounter = self[102] or 0
1061
- if not self[101] or stunCounter >= 1 then
1078
+ if not self[101] and (self[103] or 0) <= 0 or stunCounter >= 1 then
1062
1079
  BlzPauseUnitEx(self.handle, false)
1063
1080
  end
1064
1081
  self[102] = stunCounter - 1
1065
1082
  end
1083
+ function Unit.prototype.incrementForceStunCounter(self)
1084
+ local forceStunCounter = self[103] or 0
1085
+ if forceStunCounter == 0 then
1086
+ local handle = self.handle
1087
+ if not self[101] then
1088
+ for _ = self[102] or 0, -1 do
1089
+ BlzPauseUnitEx(handle, true)
1090
+ end
1091
+ end
1092
+ BlzPauseUnitEx(handle, true)
1093
+ end
1094
+ self[103] = forceStunCounter + 1
1095
+ end
1096
+ function Unit.prototype.decrementForceStunCounter(self)
1097
+ local forceStunCounter = self[103] or 0
1098
+ if forceStunCounter == 1 then
1099
+ local handle = self.handle
1100
+ if not self[101] then
1101
+ for _ = self[102] or 0, -1 do
1102
+ BlzPauseUnitEx(handle, false)
1103
+ end
1104
+ end
1105
+ BlzPauseUnitEx(handle, false)
1106
+ end
1107
+ self[103] = forceStunCounter - 1
1108
+ end
1066
1109
  function Unit.create(self, owner, id, x, y, facing, skinId)
1067
1110
  local handle = skinId and BlzCreateUnitWithSkin(
1068
1111
  owner.handle,
@@ -1470,7 +1513,7 @@ __TS__SetDescriptor(
1470
1513
  "isTeamGlowVisible",
1471
1514
  {
1472
1515
  get = function(self)
1473
- return not self[106]
1516
+ return not self[107]
1474
1517
  end,
1475
1518
  set = function(self, isTeamGlowVisible)
1476
1519
  BlzShowUnitTeamGlow(self.handle, isTeamGlowVisible)
@@ -1480,7 +1523,7 @@ __TS__SetDescriptor(
1480
1523
  else
1481
1524
  ____temp_7 = nil
1482
1525
  end
1483
- self[106] = ____temp_7
1526
+ self[107] = ____temp_7
1484
1527
  end
1485
1528
  },
1486
1529
  true
@@ -1490,7 +1533,7 @@ __TS__SetDescriptor(
1490
1533
  "color",
1491
1534
  {set = function(self, color)
1492
1535
  SetUnitColor(self.handle, color.handle)
1493
- if self[106] then
1536
+ if self[107] then
1494
1537
  BlzShowUnitTeamGlow(self.handle, false)
1495
1538
  end
1496
1539
  end},
@@ -1514,14 +1557,14 @@ __TS__SetDescriptor(
1514
1557
  "maxHealth",
1515
1558
  {
1516
1559
  get = function(self)
1517
- return BlzGetUnitMaxHP(self.handle) - (self[104] or 0) - (self[105] or 0)
1560
+ return BlzGetUnitMaxHP(self.handle) - (self[105] or 0) - (self[106] or 0)
1518
1561
  end,
1519
1562
  set = function(self, maxHealth)
1520
- if maxHealth < 1 and self[103] ~= nil then
1521
- self[104] = (self[104] or 0) + (1 - maxHealth)
1563
+ if maxHealth < 1 and self[104] ~= nil then
1564
+ self[105] = (self[105] or 0) + (1 - maxHealth)
1522
1565
  maxHealth = 1
1523
1566
  end
1524
- BlzSetUnitMaxHP(self.handle, maxHealth + (self[105] or 0))
1567
+ BlzSetUnitMaxHP(self.handle, maxHealth + (self[106] or 0))
1525
1568
  end
1526
1569
  },
1527
1570
  true
@@ -1563,10 +1606,10 @@ __TS__SetDescriptor(
1563
1606
  "health",
1564
1607
  {
1565
1608
  get = function(self)
1566
- return GetWidgetLife(self.handle) - (self[105] or 0)
1609
+ return GetWidgetLife(self.handle) - (self[106] or 0)
1567
1610
  end,
1568
1611
  set = function(self, health)
1569
- SetWidgetLife(self.handle, health + (self[105] or 0))
1612
+ SetWidgetLife(self.handle, health + (self[106] or 0))
1570
1613
  end
1571
1614
  },
1572
1615
  true
@@ -1642,25 +1685,12 @@ __TS__SetDescriptor(
1642
1685
  },
1643
1686
  true
1644
1687
  )
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
1688
  __TS__SetDescriptor(
1659
1689
  Unit.prototype,
1660
1690
  "x",
1661
1691
  {
1662
1692
  get = function(self)
1663
- return self[107] or getUnitX(self.handle)
1693
+ return self[108] or getUnitX(self.handle)
1664
1694
  end,
1665
1695
  set = function(self, v)
1666
1696
  SetUnitX(self.handle, v)
@@ -1673,7 +1703,7 @@ __TS__SetDescriptor(
1673
1703
  "y",
1674
1704
  {
1675
1705
  get = function(self)
1676
- return self[108] or getUnitY(self.handle)
1706
+ return self[109] or getUnitY(self.handle)
1677
1707
  end,
1678
1708
  set = function(self, v)
1679
1709
  SetUnitY(self.handle, v)
@@ -1778,14 +1808,18 @@ __TS__SetDescriptor(
1778
1808
  local handle = self.handle
1779
1809
  if isPaused and not IsUnitPaused(handle) then
1780
1810
  self[101] = true
1781
- for _ = self[102] or 0, -1 do
1782
- BlzPauseUnitEx(handle, true)
1811
+ if (self[103] or 0) <= 0 then
1812
+ for _ = self[102] or 0, -1 do
1813
+ BlzPauseUnitEx(handle, true)
1814
+ end
1783
1815
  end
1784
1816
  PauseUnit(handle, true)
1785
1817
  elseif not isPaused and IsUnitPaused(handle) then
1786
1818
  PauseUnit(handle, false)
1787
- for _ = self[102] or 0, -1 do
1788
- BlzPauseUnitEx(handle, false)
1819
+ if (self[103] or 0) <= 0 then
1820
+ for _ = self[102] or 0, -1 do
1821
+ BlzPauseUnitEx(handle, false)
1822
+ end
1789
1823
  end
1790
1824
  self[101] = nil
1791
1825
  end
@@ -1843,20 +1877,6 @@ __TS__SetDescriptor(
1843
1877
  },
1844
1878
  true
1845
1879
  )
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
1880
  __TS__SetDescriptor(
1861
1881
  Unit.prototype,
1862
1882
  "timeScale",
@@ -2468,12 +2488,7 @@ Unit.onDamaging = (function()
2468
2488
  preventRetaliation = damagingEventPreventRetaliation
2469
2489
  }
2470
2490
  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])
2491
+ data.weapon = source:chooseWeapon(target)
2477
2492
  end
2478
2493
  if not data.isAttack or not source or not source._attackHandlers then
2479
2494
  invoke(
@@ -2618,7 +2633,7 @@ Unit.onDamage = __TS__New(
2618
2633
  invoke(event, source, target, evData)
2619
2634
  if evData[0] ~= nil and target.health - evData.amount < 0.405 then
2620
2635
  local bonusHealth = math.ceil(evData.amount)
2621
- target[105] = (target[105] or 0) + bonusHealth
2636
+ target[106] = (target[106] or 0) + bonusHealth
2622
2637
  BlzSetUnitMaxHP(
2623
2638
  target.handle,
2624
2639
  BlzGetUnitMaxHP(target.handle) + bonusHealth
@@ -2632,7 +2647,7 @@ Unit.onDamage = __TS__New(
2632
2647
  evData[0],
2633
2648
  table.unpack(evData, 1 + 1, 1 + (evData[1] or 0))
2634
2649
  )
2635
- target[105] = (target[105] or 0) - bonusHealth
2650
+ target[106] = (target[106] or 0) - bonusHealth
2636
2651
  SetWidgetLife(
2637
2652
  target.handle,
2638
2653
  GetWidgetLife(target.handle) - bonusHealth
@@ -2782,6 +2797,10 @@ __TS__ObjectDefineProperty(
2782
2797
  rawset(self, "destroyEvent", destroyEvent)
2783
2798
  return destroyEvent
2784
2799
  end}
2800
+ )
2801
+ Unit.synchronize = synchronizer(
2802
+ function(unit) return unit.syncId end,
2803
+ function(syncId) return unitBySyncId[syncId] end
2785
2804
  );
2786
2805
  (function(self)
2787
2806
  local leaveAbilityIds = postcompile(function()