warscript 0.0.1-dev.46595c8 → 0.0.1-dev.46e7a52

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 (86) hide show
  1. package/attributes.d.ts +1 -0
  2. package/attributes.lua +9 -0
  3. package/core/types/frame.lua +24 -21
  4. package/core/types/player.d.ts +15 -0
  5. package/core/types/player.lua +56 -14
  6. package/core/types/playerCamera.d.ts +2 -0
  7. package/core/types/playerCamera.lua +123 -5
  8. package/core/types/tileCell.d.ts +9 -0
  9. package/core/types/tileCell.lua +92 -0
  10. package/core/types/timer.d.ts +3 -1
  11. package/core/types/timer.lua +27 -2
  12. package/decl/native.d.ts +6 -4
  13. package/engine/behavior.d.ts +5 -0
  14. package/engine/behavior.lua +106 -27
  15. package/engine/behaviour/ability/apply-buff.lua +1 -1
  16. package/engine/behaviour/ability/emulate-impact.d.ts +1 -1
  17. package/engine/behaviour/ability/emulate-impact.lua +2 -1
  18. package/engine/behaviour/ability/remove-buffs.d.ts +9 -0
  19. package/engine/behaviour/ability/remove-buffs.lua +21 -0
  20. package/engine/behaviour/ability/restore-mana.d.ts +1 -1
  21. package/engine/behaviour/ability/restore-mana.lua +6 -6
  22. package/engine/behaviour/ability.lua +7 -16
  23. package/engine/behaviour/unit/stun-immunity.d.ts +7 -3
  24. package/engine/behaviour/unit/stun-immunity.lua +52 -27
  25. package/engine/behaviour/unit.d.ts +19 -2
  26. package/engine/behaviour/unit.lua +83 -7
  27. package/engine/buff.d.ts +2 -4
  28. package/engine/buff.lua +73 -88
  29. package/engine/internal/ability.d.ts +3 -1
  30. package/engine/internal/ability.lua +34 -11
  31. package/engine/internal/item/ability.lua +51 -1
  32. package/engine/internal/item+owner.lua +12 -6
  33. package/engine/internal/item.d.ts +13 -15
  34. package/engine/internal/item.lua +63 -49
  35. package/engine/internal/misc/frame-coordinates.d.ts +2 -0
  36. package/engine/internal/misc/frame-coordinates.lua +21 -0
  37. package/engine/internal/misc/get-terrain-z.d.ts +2 -0
  38. package/engine/internal/misc/get-terrain-z.lua +11 -0
  39. package/engine/internal/misc/player-local-handle.d.ts +2 -0
  40. package/engine/internal/misc/player-local-handle.lua +5 -0
  41. package/engine/internal/unit/ability.d.ts +35 -5
  42. package/engine/internal/unit/ability.lua +96 -21
  43. package/engine/internal/unit/main-selected.lua +12 -27
  44. package/engine/internal/unit/order.lua +39 -30
  45. package/engine/internal/unit+ability.lua +10 -1
  46. package/engine/internal/unit-missile-launch.lua +45 -14
  47. package/engine/internal/unit.d.ts +18 -12
  48. package/engine/internal/unit.lua +155 -109
  49. package/engine/local-client.d.ts +2 -0
  50. package/engine/local-client.lua +30 -0
  51. package/engine/object-data/auxiliary/armor-type.d.ts +11 -0
  52. package/engine/object-data/auxiliary/armor-type.lua +46 -0
  53. package/engine/object-data/entry/ability-type.lua +5 -4
  54. package/engine/object-data/entry/unit-type.d.ts +11 -2
  55. package/engine/object-data/entry/unit-type.lua +59 -1
  56. package/engine/object-field/ability.d.ts +3 -3
  57. package/engine/object-field/ability.lua +7 -6
  58. package/engine/object-field/unit.d.ts +11 -0
  59. package/engine/object-field/unit.lua +34 -0
  60. package/engine/object-field.d.ts +2 -2
  61. package/engine/object-field.lua +8 -6
  62. package/engine/random.d.ts +9 -0
  63. package/engine/random.lua +13 -0
  64. package/engine/standard/fields/unit.d.ts +4 -0
  65. package/engine/standard/fields/unit.lua +7 -0
  66. package/engine/synchronization.d.ts +11 -0
  67. package/engine/synchronization.lua +77 -0
  68. package/engine/text-tag.d.ts +26 -3
  69. package/engine/text-tag.lua +216 -11
  70. package/net/socket.lua +1 -1
  71. package/objutil/buff.lua +1 -1
  72. package/package.json +2 -2
  73. package/patch-lualib.lua +1 -1
  74. package/utility/arrays.d.ts +1 -0
  75. package/utility/arrays.lua +8 -0
  76. package/utility/callback-array.d.ts +17 -0
  77. package/utility/callback-array.lua +61 -0
  78. package/utility/functions.d.ts +7 -0
  79. package/utility/functions.lua +12 -0
  80. package/utility/linked-set.d.ts +1 -0
  81. package/utility/linked-set.lua +19 -1
  82. package/utility/lua-maps.d.ts +11 -2
  83. package/utility/lua-maps.lua +33 -2
  84. package/utility/lua-sets.d.ts +1 -0
  85. package/utility/lua-sets.lua +4 -0
  86. package/utility/types.d.ts +3 -0
@@ -17,6 +17,11 @@ local getOrPut = ____lua_2Dmaps.getOrPut
17
17
  local mutableLuaMap = ____lua_2Dmaps.mutableLuaMap
18
18
  local ____lua_2Dsets = require("utility.lua-sets")
19
19
  local mutableLuaSet = ____lua_2Dsets.mutableLuaSet
20
+ local ____bonus = require("engine.internal.unit.bonus")
21
+ local addOrUpdateOrRemoveUnitBonus = ____bonus.addOrUpdateOrRemoveUnitBonus
22
+ local getUnitBonus = ____bonus.getUnitBonus
23
+ local removeUnitBonus = ____bonus.removeUnitBonus
24
+ local safeCall = warpack.safeCall
20
25
  local behaviorsByEvent = {}
21
26
  local rangeByBehaviorByEvent = {}
22
27
  local listenerByBehaviorByEvent = {}
@@ -47,9 +52,27 @@ function UnitBehavior.prototype.onDestroy(self)
47
52
  end
48
53
  eventsByBehavior[self] = nil
49
54
  end
55
+ if self._bonusIdByBonusType ~= nil then
56
+ for bonusType, bonusId in pairs(self._bonusIdByBonusType) do
57
+ removeUnitBonus(self.object, bonusType, bonusId)
58
+ end
59
+ end
50
60
  return Behavior.prototype.onDestroy(self)
51
61
  end
52
- function UnitBehavior.prototype.registerInRangeUnitEvent(self, event, range, listener)
62
+ function UnitBehavior.prototype.getUnitBonus(self, bonusType)
63
+ local ____opt_6 = self._bonusIdByBonusType
64
+ local bonusId = ____opt_6 and ____opt_6[bonusType]
65
+ return bonusId == nil and 0 or getUnitBonus(self.object, bonusType, bonusId)
66
+ end
67
+ function UnitBehavior.prototype.addOrUpdateOrRemoveUnitBonus(self, bonusType, value)
68
+ local bonusIdByBonusType = self._bonusIdByBonusType
69
+ if bonusIdByBonusType == nil then
70
+ bonusIdByBonusType = {}
71
+ self._bonusIdByBonusType = bonusIdByBonusType
72
+ end
73
+ bonusIdByBonusType[bonusType] = addOrUpdateOrRemoveUnitBonus(self.object, bonusType, bonusIdByBonusType[bonusType], value)
74
+ end
75
+ function UnitBehavior.prototype.registerInRangeUnitEvent(self, event, extractUnit, range, listener)
53
76
  local rangeByBehavior = getOrPut(rangeByBehaviorByEvent, event, mutableLuaMap)
54
77
  rangeByBehavior[self] = range
55
78
  local listenerByBehavior = getOrPut(listenerByBehaviorByEvent, event, mutableLuaMap)
@@ -57,14 +80,16 @@ function UnitBehavior.prototype.registerInRangeUnitEvent(self, event, range, lis
57
80
  getOrPut(eventsByBehavior, self, mutableLuaSet)[event] = true
58
81
  local behaviors = behaviorsByEvent[event]
59
82
  if behaviors == nil then
60
- event:addListener(function(unit, ...)
83
+ event:addListener(function(...)
61
84
  local behaviors = behaviorsByEvent[event]
62
85
  if behaviors ~= nil then
63
- for behavior in pairs(behaviors) do
64
- local range = rangeByBehavior[behavior]
65
- if range ~= nil and unit:getCollisionDistanceTo(behavior.unit) <= range then
66
- local ____self_6 = behavior
67
- ____self_6[listenerByBehavior[behavior]](____self_6, unit, ...)
86
+ local unit = extractUnit(...)
87
+ if unit ~= nil then
88
+ for behavior in pairs(behaviors) do
89
+ local range = rangeByBehavior[behavior]
90
+ if range ~= nil and unit:getCollisionDistanceTo(behavior.unit) <= range then
91
+ safeCall(behavior[listenerByBehavior[behavior]], behavior, ...)
92
+ end
68
93
  end
69
94
  end
70
95
  end
@@ -104,10 +129,28 @@ function UnitBehavior.prototype.onAbilityChannelingStart(self, ability)
104
129
  end
105
130
  function UnitBehavior.prototype.onAbilityImpact(self, ability)
106
131
  end
132
+ function UnitBehavior.prototype.onAbilityWidgetTargetImpact(self, ability, target)
133
+ end
134
+ function UnitBehavior.prototype.onAbilityUnitTargetImpact(self, ability, target)
135
+ end
136
+ function UnitBehavior.prototype.onAbilityItemTargetImpact(self, ability, target)
137
+ end
138
+ function UnitBehavior.prototype.onAbilityDestructibleTargetImpact(self, ability, target)
139
+ end
140
+ function UnitBehavior.prototype.onAbilityPointTargetImpact(self, ability, x, y)
141
+ end
142
+ function UnitBehavior.prototype.onAbilityNoTargetImpact(self, ability)
143
+ end
107
144
  function UnitBehavior.prototype.onAbilityChannelingFinish(self, ability)
108
145
  end
109
146
  function UnitBehavior.prototype.onAbilityStop(self, ability)
110
147
  end
148
+ function UnitBehavior.prototype.onTargetingAbilityChannelingStart(self, ability, source)
149
+ end
150
+ function UnitBehavior.prototype.onTargetingAbilityImpact(self, ability, source)
151
+ end
152
+ function UnitBehavior.prototype.onBuffGained(self, buff)
153
+ end
111
154
  function UnitBehavior.prototype.onItemDropped(self, item)
112
155
  end
113
156
  function UnitBehavior.prototype.onItemPickedUp(self, item)
@@ -122,6 +165,8 @@ function UnitBehavior.prototype.onKill(self, target)
122
165
  end
123
166
  function UnitBehavior.prototype.onDeath(self, source)
124
167
  end
168
+ function UnitBehavior.prototype.onOwnerChange(self, previousOwner)
169
+ end
125
170
  __TS__SetDescriptor(
126
171
  UnitBehavior.prototype,
127
172
  "unit",
@@ -175,9 +220,37 @@ __TS__SetDescriptor(
175
220
  Unit.abilityChannelingStartEvent:addListener(function(source, ability)
176
221
  ____exports.UnitBehavior:forAll(source, "onAbilityChannelingStart", ability)
177
222
  end)
223
+ Unit.abilityUnitTargetChannelingStartEvent:addListener(function(source, ability, target)
224
+ ____exports.UnitBehavior:forAll(target, "onTargetingAbilityChannelingStart", ability, source)
225
+ end)
178
226
  Unit.abilityImpactEvent:addListener(function(source, ability)
179
227
  ____exports.UnitBehavior:forAll(source, "onAbilityImpact", ability)
180
228
  end)
229
+ Unit.abilityWidgetTargetImpactEvent:addListener(function(source, ability, target)
230
+ ____exports.UnitBehavior:forAll(source, "onAbilityWidgetTargetImpact", ability, target)
231
+ end)
232
+ Unit.abilityUnitTargetImpactEvent:addListener(function(source, ability, target)
233
+ ____exports.UnitBehavior:forAll(source, "onAbilityUnitTargetImpact", ability, target)
234
+ ____exports.UnitBehavior:forAll(target, "onTargetingAbilityImpact", ability, source)
235
+ end)
236
+ Unit.abilityItemTargetImpactEvent:addListener(function(source, ability, target)
237
+ ____exports.UnitBehavior:forAll(source, "onAbilityItemTargetImpact", ability, target)
238
+ end)
239
+ Unit.abilityDestructibleTargetImpactEvent:addListener(function(source, ability, target)
240
+ ____exports.UnitBehavior:forAll(source, "onAbilityDestructibleTargetImpact", ability, target)
241
+ end)
242
+ Unit.abilityPointTargetImpactEvent:addListener(function(source, ability, x, y)
243
+ ____exports.UnitBehavior:forAll(
244
+ source,
245
+ "onAbilityPointTargetImpact",
246
+ ability,
247
+ x,
248
+ y
249
+ )
250
+ end)
251
+ Unit.abilityNoTargetImpactEvent:addListener(function(source, ability)
252
+ ____exports.UnitBehavior:forAll(source, "onAbilityNoTargetImpact", ability)
253
+ end)
181
254
  Unit.abilityChannelingFinishEvent:addListener(function(source, ability)
182
255
  ____exports.UnitBehavior:forAll(source, "onAbilityChannelingFinish", ability)
183
256
  end)
@@ -205,6 +278,9 @@ __TS__SetDescriptor(
205
278
  Unit.itemChargesChangedEvent:addListener(function(unit, item)
206
279
  ____exports.UnitBehavior:forAll(unit, "onItemChargesChanged", item)
207
280
  end)
281
+ Unit.onOwnerChange:addListener(function(unit, previousOwner)
282
+ ____exports.UnitBehavior:forAll(unit, "onOwnerChange", previousOwner)
283
+ end)
208
284
  end)(UnitBehavior)
209
285
  Unit.destroyEvent:addListener(function(unit)
210
286
  ____exports.UnitBehavior:forAll(unit, "destroy")
package/engine/buff.d.ts CHANGED
@@ -201,11 +201,8 @@ export declare class Buff<AdditionalParameters extends Prohibit<Record<string, a
201
201
  private readonly _spellStealPriority?;
202
202
  private readonly _learnLevelMinimum?;
203
203
  private readonly [BuffPropertyKey.MISS_PROBABILITY]?;
204
- private _bonusIdByBonusType?;
205
204
  private readonly _abilityTypeIds?;
206
205
  private _behaviors?;
207
- private getUnitBonus;
208
- private addOrUpdateOrRemoveUnitBonus;
209
206
  constructor(target: Unit, ...parameters: BuffConstructorParameters<AdditionalParameters>);
210
207
  get level(): number;
211
208
  get remainingDamageOverDuration(): number;
@@ -278,6 +275,7 @@ export declare class Buff<AdditionalParameters extends Prohibit<Record<string, a
278
275
  onDeath(source: Unit | undefined): void;
279
276
  onDamageDealt(target: Unit, event: DamageEvent): void;
280
277
  onDamageReceived(source: Unit | undefined, event: DamageEvent): void;
281
- static readonly destroyEvent: Event<[Buff<object>]>;
278
+ static readonly createdEvent: Event<[Buff<object>]>;
279
+ static readonly beingDestroyedEvent: Event<[Buff<object>]>;
282
280
  }
283
281
  export {};
package/engine/buff.lua CHANGED
@@ -28,9 +28,6 @@ local ____math = require("math")
28
28
  local max = ____math.max
29
29
  local min = ____math.min
30
30
  local ____bonus = require("engine.internal.unit.bonus")
31
- local addOrUpdateOrRemoveUnitBonus = ____bonus.addOrUpdateOrRemoveUnitBonus
32
- local getUnitBonus = ____bonus.getUnitBonus
33
- local removeUnitBonus = ____bonus.removeUnitBonus
34
31
  local UnitBonusType = ____bonus.UnitBonusType
35
32
  local ____area_2Ddamage = require("engine.internal.mechanics.area-damage")
36
33
  local damageArea = ____area_2Ddamage.damageArea
@@ -304,7 +301,8 @@ buffHealingIntervalTimerCallback = function(buff)
304
301
  source:healTarget(buff[101], healingPerInterval)
305
302
  end
306
303
  end
307
- local buffDestroyEvent = __TS__New(Event)
304
+ local buffCreatedEvent = __TS__New(Event)
305
+ local buffBeingDestroyedEvent = __TS__New(Event)
308
306
  ____exports.Buff = __TS__Class()
309
307
  local Buff = ____exports.Buff
310
308
  Buff.name = "Buff"
@@ -506,64 +504,52 @@ function Buff.prototype.____constructor(self, _unit, typeIdOrTypeIds, polarityOr
506
504
  end
507
505
  self:onCreate()
508
506
  self[100] = 1
509
- end
510
- function Buff.prototype.getUnitBonus(self, bonusType)
511
- local ____opt_38 = self._bonusIdByBonusType
512
- local bonusId = ____opt_38 and ____opt_38[bonusType]
513
- return bonusId == nil and 0 or getUnitBonus(self._unit, bonusType, bonusId)
514
- end
515
- function Buff.prototype.addOrUpdateOrRemoveUnitBonus(self, bonusType, value)
516
- local bonusIdByBonusType = self._bonusIdByBonusType
517
- if bonusIdByBonusType == nil then
518
- bonusIdByBonusType = {}
519
- self._bonusIdByBonusType = bonusIdByBonusType
520
- end
521
- bonusIdByBonusType[bonusType] = addOrUpdateOrRemoveUnitBonus(self._unit, bonusType, bonusIdByBonusType[bonusType], value)
507
+ Event.invoke(buffCreatedEvent, self)
522
508
  end
523
509
  function Buff.prototype.flashEffect(self, widgetOrXOrParametersOrDuration, yOrParametersOrDuration, parametersOrDuration)
524
510
  if type(widgetOrXOrParametersOrDuration) == "number" and type(yOrParametersOrDuration) == "number" then
525
511
  Effect:flash(self[105], widgetOrXOrParametersOrDuration, yOrParametersOrDuration, parametersOrDuration)
526
512
  else
527
513
  local isWidgetProvided = __TS__InstanceOf(widgetOrXOrParametersOrDuration, Unit) or __TS__InstanceOf(widgetOrXOrParametersOrDuration, Item) or __TS__InstanceOf(widgetOrXOrParametersOrDuration, Destructable)
528
- local ____Effect_42 = Effect
529
- local ____Effect_flash_43 = Effect.flash
530
- local ____array_41 = __TS__SparseArrayNew(
514
+ local ____Effect_40 = Effect
515
+ local ____Effect_flash_41 = Effect.flash
516
+ local ____array_39 = __TS__SparseArrayNew(
531
517
  self[105],
532
518
  isWidgetProvided and widgetOrXOrParametersOrDuration or self._unit,
533
519
  stringValueByBuffTypeIdByFieldId[fourCC("feft")][self.typeId] or "origin"
534
520
  )
535
- local ____isWidgetProvided_40
521
+ local ____isWidgetProvided_38
536
522
  if isWidgetProvided then
537
- ____isWidgetProvided_40 = yOrParametersOrDuration
523
+ ____isWidgetProvided_38 = yOrParametersOrDuration
538
524
  else
539
- ____isWidgetProvided_40 = widgetOrXOrParametersOrDuration
525
+ ____isWidgetProvided_38 = widgetOrXOrParametersOrDuration
540
526
  end
541
- __TS__SparseArrayPush(____array_41, ____isWidgetProvided_40)
542
- ____Effect_flash_43(
543
- ____Effect_42,
544
- __TS__SparseArraySpread(____array_41)
527
+ __TS__SparseArrayPush(____array_39, ____isWidgetProvided_38)
528
+ ____Effect_flash_41(
529
+ ____Effect_40,
530
+ __TS__SparseArraySpread(____array_39)
545
531
  )
546
532
  end
547
533
  end
548
534
  function Buff.prototype.flashSpecialEffect(self, widgetOrDuration, duration)
549
535
  local isWidgetProvided = type(widgetOrDuration) == "table"
550
- local ____Effect_46 = Effect
551
- local ____Effect_flash_47 = Effect.flash
552
- local ____array_45 = __TS__SparseArrayNew(
536
+ local ____Effect_44 = Effect
537
+ local ____Effect_flash_45 = Effect.flash
538
+ local ____array_43 = __TS__SparseArrayNew(
553
539
  self[106],
554
540
  isWidgetProvided and widgetOrDuration or self._unit,
555
541
  stringValueByBuffTypeIdByFieldId[fourCC("fspt")][self.typeId] or "origin"
556
542
  )
557
- local ____isWidgetProvided_44
543
+ local ____isWidgetProvided_42
558
544
  if isWidgetProvided then
559
- ____isWidgetProvided_44 = duration
545
+ ____isWidgetProvided_42 = duration
560
546
  else
561
- ____isWidgetProvided_44 = widgetOrDuration
547
+ ____isWidgetProvided_42 = widgetOrDuration
562
548
  end
563
- __TS__SparseArrayPush(____array_45, ____isWidgetProvided_44)
564
- ____Effect_flash_47(
565
- ____Effect_46,
566
- __TS__SparseArraySpread(____array_45)
549
+ __TS__SparseArrayPush(____array_43, ____isWidgetProvided_42)
550
+ ____Effect_flash_45(
551
+ ____Effect_44,
552
+ __TS__SparseArraySpread(____array_43)
567
553
  )
568
554
  end
569
555
  function Buff.prototype.onCreate(self)
@@ -602,7 +588,7 @@ function Buff.prototype.onDestroy(self)
602
588
  end
603
589
  if self[136] then
604
590
  if self[137] then
605
- unit:decrementStunCounter()
591
+ unit:decrementForceStunCounter()
606
592
  end
607
593
  unit:decrementStunCounter()
608
594
  end
@@ -614,12 +600,7 @@ function Buff.prototype.onDestroy(self)
614
600
  unit:removeAbility(abilityTypeId)
615
601
  end
616
602
  end
617
- if self._bonusIdByBonusType ~= nil then
618
- for bonusType, bonusId in pairs(self._bonusIdByBonusType) do
619
- removeUnitBonus(unit, bonusType, bonusId)
620
- end
621
- end
622
- Event.invoke(buffDestroyEvent, self)
603
+ Event.invoke(buffBeingDestroyedEvent, self)
623
604
  self[100] = 3
624
605
  return UnitBehavior.prototype.onDestroy(self)
625
606
  end
@@ -648,8 +629,8 @@ function Buff.apply(self, ...)
648
629
  end
649
630
  end
650
631
  function Buff.getByTypeId(self, unit, typeId)
651
- local ____opt_48 = buffByTypeIdByUnit[unit]
652
- local buff = ____opt_48 and ____opt_48[typeId]
632
+ local ____opt_46 = buffByTypeIdByUnit[unit]
633
+ local buff = ____opt_46 and ____opt_46[typeId]
653
634
  if __TS__InstanceOf(buff, self) then
654
635
  return buff
655
636
  end
@@ -807,8 +788,8 @@ __TS__SetDescriptor(
807
788
  return
808
789
  end
809
790
  self[112] = damageInterval
810
- local ____opt_50 = self._timer
811
- local elapsed = ____opt_50 and ____opt_50.elapsed or 0
791
+ local ____opt_48 = self._timer
792
+ local elapsed = ____opt_48 and ____opt_48.elapsed or 0
812
793
  local timer = self[114]
813
794
  if timer == nil then
814
795
  timer = Timer:create()
@@ -887,8 +868,8 @@ __TS__SetDescriptor(
887
868
  return
888
869
  end
889
870
  self[117] = healingInterval
890
- local ____opt_52 = self._timer
891
- local elapsed = ____opt_52 and ____opt_52.elapsed or 0
871
+ local ____opt_50 = self._timer
872
+ local elapsed = ____opt_50 and ____opt_50.elapsed or 0
892
873
  local timer = self[119]
893
874
  if timer == nil then
894
875
  timer = Timer:create()
@@ -974,11 +955,11 @@ __TS__SetDescriptor(
974
955
  "turnsIntoGhost",
975
956
  {
976
957
  get = function(self)
977
- local ____self__135_54 = self[135]
978
- if ____self__135_54 == nil then
979
- ____self__135_54 = false
958
+ local ____self__135_52 = self[135]
959
+ if ____self__135_52 == nil then
960
+ ____self__135_52 = false
980
961
  end
981
- return ____self__135_54
962
+ return ____self__135_52
982
963
  end,
983
964
  set = function(self, turnsIntoGhost)
984
965
  if not turnsIntoGhost and self[135] then
@@ -997,22 +978,22 @@ __TS__SetDescriptor(
997
978
  "stuns",
998
979
  {
999
980
  get = function(self)
1000
- local ____self__136_55 = self[136]
1001
- if ____self__136_55 == nil then
1002
- ____self__136_55 = false
981
+ local ____self__136_53 = self[136]
982
+ if ____self__136_53 == nil then
983
+ ____self__136_53 = false
1003
984
  end
1004
- return ____self__136_55
985
+ return ____self__136_53
1005
986
  end,
1006
987
  set = function(self, stuns)
1007
988
  if not stuns and self[136] then
1008
989
  if self[137] then
1009
- self.object:decrementStunCounter()
990
+ self.object:decrementForceStunCounter()
1010
991
  end
1011
992
  self.object:decrementStunCounter()
1012
993
  self[136] = nil
1013
994
  elseif stuns and not self[136] then
1014
995
  if self[137] then
1015
- self.object:incrementStunCounter()
996
+ self.object:incrementForceStunCounter()
1016
997
  end
1017
998
  self.object:incrementStunCounter()
1018
999
  self[136] = true
@@ -1026,21 +1007,21 @@ __TS__SetDescriptor(
1026
1007
  "ignoresStunImmunity",
1027
1008
  {
1028
1009
  get = function(self)
1029
- local ____self__137_56 = self[137]
1030
- if ____self__137_56 == nil then
1031
- ____self__137_56 = false
1010
+ local ____self__137_54 = self[137]
1011
+ if ____self__137_54 == nil then
1012
+ ____self__137_54 = false
1032
1013
  end
1033
- return ____self__137_56
1014
+ return ____self__137_54
1034
1015
  end,
1035
1016
  set = function(self, ignoresStunImmunity)
1036
1017
  if not ignoresStunImmunity and self[137] then
1037
1018
  if self[136] then
1038
- self.object:decrementStunCounter()
1019
+ self.object:decrementForceStunCounter()
1039
1020
  end
1040
1021
  self[137] = nil
1041
1022
  elseif ignoresStunImmunity and not self[137] then
1042
1023
  if self[136] then
1043
- self.object:incrementStunCounter()
1024
+ self.object:incrementForceStunCounter()
1044
1025
  end
1045
1026
  self[137] = true
1046
1027
  end
@@ -1053,11 +1034,11 @@ __TS__SetDescriptor(
1053
1034
  "disablesAutoAttack",
1054
1035
  {
1055
1036
  get = function(self)
1056
- local ____self__138_57 = self[138]
1057
- if ____self__138_57 == nil then
1058
- ____self__138_57 = false
1037
+ local ____self__138_55 = self[138]
1038
+ if ____self__138_55 == nil then
1039
+ ____self__138_55 = false
1059
1040
  end
1060
- return ____self__138_57
1041
+ return ____self__138_55
1061
1042
  end,
1062
1043
  set = function(self, disablesAutoAttack)
1063
1044
  if not disablesAutoAttack and self[138] then
@@ -1076,11 +1057,11 @@ __TS__SetDescriptor(
1076
1057
  "providesInvulnerability",
1077
1058
  {
1078
1059
  get = function(self)
1079
- local ____self__139_58 = self[139]
1080
- if ____self__139_58 == nil then
1081
- ____self__139_58 = false
1060
+ local ____self__139_56 = self[139]
1061
+ if ____self__139_56 == nil then
1062
+ ____self__139_56 = false
1082
1063
  end
1083
- return ____self__139_58
1064
+ return ____self__139_56
1084
1065
  end,
1085
1066
  set = function(self, providesInvulnerability)
1086
1067
  if not providesInvulnerability and self[139] then
@@ -1099,11 +1080,11 @@ __TS__SetDescriptor(
1099
1080
  "killsOnExpiration",
1100
1081
  {
1101
1082
  get = function(self)
1102
- local ____self__140_59 = self[140]
1103
- if ____self__140_59 == nil then
1104
- ____self__140_59 = false
1083
+ local ____self__140_57 = self[140]
1084
+ if ____self__140_57 == nil then
1085
+ ____self__140_57 = false
1105
1086
  end
1106
- return ____self__140_59
1087
+ return ____self__140_57
1107
1088
  end,
1108
1089
  set = function(self, killsOnExpiration)
1109
1090
  if not killsOnExpiration and self[140] then
@@ -1120,11 +1101,11 @@ __TS__SetDescriptor(
1120
1101
  "explodesOnExpiration",
1121
1102
  {
1122
1103
  get = function(self)
1123
- local ____self__141_60 = self[141]
1124
- if ____self__141_60 == nil then
1125
- ____self__141_60 = false
1104
+ local ____self__141_58 = self[141]
1105
+ if ____self__141_58 == nil then
1106
+ ____self__141_58 = false
1126
1107
  end
1127
- return ____self__141_60
1108
+ return ____self__141_58
1128
1109
  end,
1129
1110
  set = function(self, killsOnExpiration)
1130
1111
  if not killsOnExpiration and self[141] then
@@ -1252,13 +1233,13 @@ __TS__SetDescriptor(
1252
1233
  "remainingDuration",
1253
1234
  {
1254
1235
  get = function(self)
1255
- local ____opt_61 = self._timer
1256
- return ____opt_61 and ____opt_61.remaining or 0
1236
+ local ____opt_59 = self._timer
1237
+ return ____opt_59 and ____opt_59.remaining or 0
1257
1238
  end,
1258
1239
  set = function(self, remainingDuration)
1259
- local ____remainingDuration_65 = remainingDuration
1260
- local ____opt_63 = self._timer
1261
- local remainingDurationDelta = ____remainingDuration_65 - (____opt_63 and ____opt_63.remaining or 0)
1240
+ local ____remainingDuration_63 = remainingDuration
1241
+ local ____opt_61 = self._timer
1242
+ local remainingDurationDelta = ____remainingDuration_63 - (____opt_61 and ____opt_61.remaining or 0)
1262
1243
  if remainingDurationDelta ~= 0 then
1263
1244
  self[103] = self[103] + remainingDurationDelta
1264
1245
  if remainingDuration <= 0 then
@@ -1288,7 +1269,8 @@ __TS__SetDescriptor(
1288
1269
  },
1289
1270
  true
1290
1271
  )
1291
- Buff.destroyEvent = buffDestroyEvent;
1272
+ Buff.createdEvent = buffCreatedEvent
1273
+ Buff.beingDestroyedEvent = buffBeingDestroyedEvent;
1292
1274
  (function(self)
1293
1275
  local function destroyBuffIfNeeded(buff)
1294
1276
  if getUnitAbility(buff[101].handle, buff.typeId) ~= buff.handle and buff[100] == 1 then
@@ -1342,5 +1324,8 @@ Buff.destroyEvent = buffDestroyEvent;
1342
1324
  ____exports.checkBuffs(target)
1343
1325
  end
1344
1326
  )
1327
+ buffCreatedEvent:addListener(function(buff)
1328
+ UnitBehavior:forAll(buff.unit, "onBuffGained", buff)
1329
+ end)
1345
1330
  end)(Buff)
1346
1331
  return ____exports
@@ -1,5 +1,5 @@
1
1
  /** @noSelfInFile */
2
- import { Handle } from "../../core/types/handle";
2
+ import { Handle, HandleDestructor } from "../../core/types/handle";
3
3
  import { Event } from "../../event";
4
4
  import type { Item } from "../../core/types/item";
5
5
  import type { Unit } from "./unit";
@@ -67,6 +67,7 @@ export declare class UnitAbility extends Ability {
67
67
  get cooldownRemaining(): number;
68
68
  set cooldownRemaining(cooldownRemaining: number);
69
69
  interruptCast(): void;
70
+ protected onDestroy(): HandleDestructor;
70
71
  static get onCreate(): Event<[UnitAbility]>;
71
72
  static get onDestroy(): Event<[UnitAbility]>;
72
73
  }
@@ -93,6 +94,7 @@ export declare class ItemAbility extends Ability {
93
94
  get cooldownRemaining(): number;
94
95
  set cooldownRemaining(cooldownRemaining: number);
95
96
  interruptCast(): void;
97
+ protected onDestroy(): HandleDestructor;
96
98
  static get onCreate(): Event<[ItemAbility]>;
97
99
  static get onDestroy(): Event<[ItemAbility]>;
98
100
  }
@@ -232,6 +232,19 @@ ____exports.getOrderIdByAbilityTypeId = function(abilityTypeId)
232
232
  local parentTypeId = availableFields[abilityTypeId]
233
233
  return order2orderId(orders[____type(parentTypeId) == "number" and parentTypeId or abilityTypeId] or "")
234
234
  end
235
+ ---
236
+ -- @internal For use by internal systems only.
237
+ ____exports.abilityTypeHasField = function(abilityTypeId, field)
238
+ field = ____type(field) == "number" and field or getHandleId(field)
239
+ if commonFields[field] then
240
+ return true
241
+ end
242
+ local id = availableFields[abilityTypeId]
243
+ if ____type(id) == "number" then
244
+ id = availableFields[id]
245
+ end
246
+ return not not (id and id[field])
247
+ end
235
248
  ____exports.Ability = __TS__Class()
236
249
  local Ability = ____exports.Ability
237
250
  Ability.name = "Ability"
@@ -247,15 +260,7 @@ function Ability.prototype.getSnapshot(self)
247
260
  return nil
248
261
  end
249
262
  function Ability.prototype.hasField(self, field)
250
- field = ____type(field) == "number" and field or getHandleId(field)
251
- if commonFields[field] then
252
- return true
253
- end
254
- local id = availableFields[self.typeId]
255
- if ____type(id) == "number" then
256
- id = availableFields[id]
257
- end
258
- return not not (id and id[field])
263
+ return ____exports.abilityTypeHasField(self.typeId, field)
259
264
  end
260
265
  function Ability.prototype.getField(self, field, level)
261
266
  local fieldType = match(
@@ -404,16 +409,28 @@ function UnitAbility.prototype.decrementHideCounter(self)
404
409
  unitHideAbility(self.u, self.typeId, false)
405
410
  end
406
411
  function UnitAbility.prototype.incrementDisableCounter(self)
407
- unitDisableAbility(self.u, self.typeId, true, false)
412
+ local unit = self.u
413
+ local typeId = self.typeId
414
+ unitHideAbility(unit, typeId, true)
415
+ unitDisableAbility(unit, typeId, true, false)
408
416
  self.d = (self.d or 0) + 1
409
417
  end
410
418
  function UnitAbility.prototype.decrementDisableCounter(self)
411
- unitDisableAbility(self.u, self.typeId, false, false)
419
+ local unit = self.u
420
+ local typeId = self.typeId
421
+ unitDisableAbility(unit, typeId, false, false)
422
+ unitHideAbility(unit, typeId, true)
412
423
  self.d = (self.d or 0) - 1
413
424
  end
414
425
  function UnitAbility.prototype.interruptCast(self)
415
426
  self.owner:interruptCast(self.typeId)
416
427
  end
428
+ function UnitAbility.prototype.onDestroy(self)
429
+ if self.owner.state ~= 2 then
430
+ self.owner:removeAbility(self.typeId)
431
+ end
432
+ return UnitAbility.____super.prototype.onDestroy(self)
433
+ end
417
434
  __TS__SetDescriptor(
418
435
  UnitAbility.prototype,
419
436
  "isDisabled",
@@ -506,6 +523,12 @@ function ItemAbility.prototype.interruptCast(self)
506
523
  setItemBooleanField(handle, ITEM_BF_ACTIVELY_USED, true)
507
524
  end
508
525
  end
526
+ function ItemAbility.prototype.onDestroy(self)
527
+ if self.owner.state ~= 2 then
528
+ self.owner:removeAbility(self.typeId)
529
+ end
530
+ return ItemAbility.____super.prototype.onDestroy(self)
531
+ end
509
532
  __TS__SetDescriptor(
510
533
  ItemAbility.prototype,
511
534
  "level",