warscript 0.0.1-dev.e561d29 → 0.0.1-dev.e5e97e8

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 (72) 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 -2
  11. package/core/types/timer.lua +22 -2
  12. package/decl/native.d.ts +2 -2
  13. package/engine/behavior.d.ts +3 -0
  14. package/engine/behavior.lua +53 -0
  15. package/engine/behaviour/ability/remove-buffs.d.ts +9 -0
  16. package/engine/behaviour/ability/remove-buffs.lua +21 -0
  17. package/engine/behaviour/ability/restore-mana.d.ts +1 -1
  18. package/engine/behaviour/ability/restore-mana.lua +6 -6
  19. package/engine/behaviour/unit/stun-immunity.d.ts +2 -0
  20. package/engine/behaviour/unit/stun-immunity.lua +11 -2
  21. package/engine/behaviour/unit.d.ts +8 -2
  22. package/engine/behaviour/unit.lua +29 -2
  23. package/engine/buff.d.ts +0 -3
  24. package/engine/buff.lua +64 -85
  25. package/engine/internal/ability.d.ts +3 -1
  26. package/engine/internal/ability.lua +26 -9
  27. package/engine/internal/item+owner.lua +12 -6
  28. package/engine/internal/item.d.ts +13 -15
  29. package/engine/internal/item.lua +63 -49
  30. package/engine/internal/misc/frame-coordinates.d.ts +2 -0
  31. package/engine/internal/misc/frame-coordinates.lua +21 -0
  32. package/engine/internal/misc/get-terrain-z.d.ts +2 -0
  33. package/engine/internal/misc/get-terrain-z.lua +11 -0
  34. package/engine/internal/misc/player-local-handle.d.ts +2 -0
  35. package/engine/internal/misc/player-local-handle.lua +5 -0
  36. package/engine/internal/unit/ability.d.ts +14 -14
  37. package/engine/internal/unit/ability.lua +72 -45
  38. package/engine/internal/unit/main-selected.lua +12 -27
  39. package/engine/internal/unit+ability.lua +10 -1
  40. package/engine/internal/unit-missile-launch.lua +44 -20
  41. package/engine/internal/unit.d.ts +16 -9
  42. package/engine/internal/unit.lua +102 -54
  43. package/engine/local-client.d.ts +2 -0
  44. package/engine/local-client.lua +30 -0
  45. package/engine/object-data/entry/ability-type.lua +4 -1
  46. package/engine/object-field/ability.d.ts +3 -3
  47. package/engine/object-field/ability.lua +7 -6
  48. package/engine/object-field.d.ts +8 -2
  49. package/engine/object-field.lua +184 -93
  50. package/engine/random.d.ts +9 -0
  51. package/engine/random.lua +13 -0
  52. package/engine/synchronization.d.ts +11 -0
  53. package/engine/synchronization.lua +77 -0
  54. package/engine/text-tag.d.ts +1 -1
  55. package/engine/text-tag.lua +92 -17
  56. package/net/socket.lua +1 -1
  57. package/objutil/buff.lua +1 -1
  58. package/package.json +2 -2
  59. package/patch-lualib.lua +1 -1
  60. package/utility/arrays.d.ts +1 -0
  61. package/utility/arrays.lua +8 -0
  62. package/utility/callback-array.d.ts +17 -0
  63. package/utility/callback-array.lua +61 -0
  64. package/utility/functions.d.ts +2 -0
  65. package/utility/functions.lua +7 -0
  66. package/utility/linked-set.d.ts +1 -0
  67. package/utility/linked-set.lua +19 -1
  68. package/utility/lua-maps.d.ts +11 -2
  69. package/utility/lua-maps.lua +33 -2
  70. package/utility/lua-sets.d.ts +1 -0
  71. package/utility/lua-sets.lua +4 -0
  72. package/utility/types.d.ts +3 -0
package/decl/native.d.ts CHANGED
@@ -5259,8 +5259,8 @@ declare function BlzRemoveAbilityStringLevelArrayField(
5259
5259
  level: number,
5260
5260
  value: string,
5261
5261
  ): boolean
5262
- declare function BlzGetItemAbilityByIndex(whichItem: jitem, index: number): jability | null
5263
- declare function BlzGetItemAbility(whichItem: jitem, abilCode: number): jability | null
5262
+ declare function BlzGetItemAbilityByIndex(whichItem: jitem, index: number): jability | undefined
5263
+ declare function BlzGetItemAbility(whichItem: jitem, abilCode: number): jability | undefined
5264
5264
  declare function BlzItemAddAbility(whichItem: jitem, abilCode: number): boolean
5265
5265
  declare function BlzGetItemBooleanField(whichItem: jitem, whichField: jitembooleanfield): boolean
5266
5266
  declare function BlzGetItemIntegerField(whichItem: jitem, whichField: jitemintegerfield): number
@@ -1,5 +1,6 @@
1
1
  /** @noSelfInFile */
2
2
  import { AbstractDestroyable, Destructor } from "../destroyable";
3
+ import { Event } from "../event";
3
4
  export type BehaviorConstructor<T extends Behavior<AnyNotNil>, Parameters extends any[] = any[]> = OmitConstructor<typeof Behavior<any>> & (abstract new (...parameters: Parameters) => T);
4
5
  declare const enum BehaviorPropertyKey {
5
6
  PREVIOUS_BEHAVIOR = 0,
@@ -13,6 +14,8 @@ export declare abstract class Behavior<T extends AnyNotNil, PeriodicActionParame
13
14
  private [BehaviorPropertyKey.TIMER]?;
14
15
  protected constructor(object: T);
15
16
  protected onDestroy(): Destructor;
17
+ protected registerEvent<K extends string, Args extends any[]>(this: Behavior<any, PeriodicActionParameters> & Record<K, (this: this, ...args: Args) => unknown>, event: Event<[...Args]>, listener: K): void;
18
+ protected deregisterEvent(event: Event<any>): boolean;
16
19
  protected onPeriod(...parameters: PeriodicActionParameters): void;
17
20
  protected startPeriodicAction(interval: number, ...parameters: PeriodicActionParameters): void;
18
21
  protected stopPeriodicAction(): void;
@@ -2,6 +2,7 @@ local ____lualib = require("lualib_bundle")
2
2
  local __TS__InstanceOf = ____lualib.__TS__InstanceOf
3
3
  local __TS__Class = ____lualib.__TS__Class
4
4
  local __TS__ClassExtends = ____lualib.__TS__ClassExtends
5
+ local __TS__New = ____lualib.__TS__New
5
6
  local ____exports = {}
6
7
  local ____destroyable = require("destroyable")
7
8
  local AbstractDestroyable = ____destroyable.AbstractDestroyable
@@ -9,6 +10,13 @@ local ____timer = require("core.types.timer")
9
10
  local Timer = ____timer.Timer
10
11
  local ____functions = require("utility.functions")
11
12
  local increment = ____functions.increment
13
+ local ____linked_2Dset = require("utility.linked-set")
14
+ local LinkedSet = ____linked_2Dset.LinkedSet
15
+ local ____lua_2Dmaps = require("utility.lua-maps")
16
+ local getOrPut = ____lua_2Dmaps.getOrPut
17
+ local mutableLuaMap = ____lua_2Dmaps.mutableLuaMap
18
+ local ____lua_2Dsets = require("utility.lua-sets")
19
+ local mutableLuaSet = ____lua_2Dsets.mutableLuaSet
12
20
  local safeCall = warpack.safeCall
13
21
  local firstBehaviorByObject = {}
14
22
  local lastBehaviorByObject = {}
@@ -47,6 +55,9 @@ local function reduceBehaviors(behaviorConstructor, object, operation, initial,
47
55
  end
48
56
  return accumulator
49
57
  end
58
+ local behaviorsByEvent = {}
59
+ local listenerByBehaviorByEvent = {}
60
+ local eventsByBehavior = {}
50
61
  ____exports.Behavior = __TS__Class()
51
62
  local Behavior = ____exports.Behavior
52
63
  Behavior.name = "Behavior"
@@ -69,6 +80,20 @@ function Behavior.prototype.onDestroy(self)
69
80
  if ____opt_0 ~= nil then
70
81
  ____opt_0:destroy()
71
82
  end
83
+ local events = eventsByBehavior[self]
84
+ if events ~= nil then
85
+ for event in pairs(events) do
86
+ local ____opt_2 = behaviorsByEvent[event]
87
+ if ____opt_2 ~= nil then
88
+ ____opt_2:remove(self)
89
+ end
90
+ local ____opt_4 = listenerByBehaviorByEvent[event]
91
+ if ____opt_4 ~= nil then
92
+ ____opt_4[self] = nil
93
+ end
94
+ end
95
+ eventsByBehavior[self] = nil
96
+ end
72
97
  local previousBehavior = self[0]
73
98
  local nextBehavior = self[1]
74
99
  if previousBehavior ~= nil then
@@ -83,6 +108,34 @@ function Behavior.prototype.onDestroy(self)
83
108
  end
84
109
  return AbstractDestroyable.prototype.onDestroy(self)
85
110
  end
111
+ function Behavior.prototype.registerEvent(self, event, listener)
112
+ local listenerByBehavior = getOrPut(listenerByBehaviorByEvent, event, mutableLuaMap)
113
+ listenerByBehavior[self] = listener
114
+ getOrPut(eventsByBehavior, self, mutableLuaSet)[event] = true
115
+ local behaviors = behaviorsByEvent[event]
116
+ if behaviors == nil then
117
+ event:addListener(function(...)
118
+ local behaviors = behaviorsByEvent[event]
119
+ if behaviors ~= nil then
120
+ for behavior in pairs(behaviors) do
121
+ safeCall(behavior[listenerByBehavior[behavior]], behavior, ...)
122
+ end
123
+ end
124
+ end)
125
+ behaviors = __TS__New(LinkedSet)
126
+ behaviorsByEvent[event] = behaviors
127
+ end
128
+ behaviors:add(self)
129
+ end
130
+ function Behavior.prototype.deregisterEvent(self, event)
131
+ local behaviors = behaviorsByEvent[event]
132
+ if behaviors ~= nil and behaviors:remove(self) then
133
+ eventsByBehavior[self][event] = nil
134
+ listenerByBehaviorByEvent[event][self] = nil
135
+ return true
136
+ end
137
+ return false
138
+ end
86
139
  function Behavior.prototype.onPeriod(self, ...)
87
140
  end
88
141
  function Behavior.prototype.startPeriodicAction(self, interval, ...)
@@ -14,3 +14,12 @@ export declare class RemoveBuffsSelfAbilityBehavior extends AbilityBehavior {
14
14
  constructor(ability: Ability, polarity?: AbilityDependentValue<BuffPolarity> | undefined, resistanceType?: AbilityDependentValue<BuffResistanceType> | undefined, includeExpirationTimers?: AbilityDependentValue<boolean> | undefined, includeAuras?: AbilityDependentValue<boolean> | undefined, autoDispel?: AbilityDependentValue<boolean> | undefined);
15
15
  onImpact(caster: Unit): void;
16
16
  }
17
+ export declare class RemoveBuffsTargetAbilityBehavior extends AbilityBehavior {
18
+ private readonly polarity?;
19
+ private readonly resistanceType?;
20
+ private readonly includeExpirationTimers?;
21
+ private readonly includeAuras?;
22
+ private readonly autoDispel?;
23
+ constructor(ability: Ability, polarity?: AbilityDependentValue<BuffPolarity> | undefined, resistanceType?: AbilityDependentValue<BuffResistanceType> | undefined, includeExpirationTimers?: AbilityDependentValue<boolean> | undefined, includeAuras?: AbilityDependentValue<boolean> | undefined, autoDispel?: AbilityDependentValue<boolean> | undefined);
24
+ onUnitTargetImpact(_: Unit, target: Unit): void;
25
+ }
@@ -25,4 +25,25 @@ function RemoveBuffsSelfAbilityBehavior.prototype.onImpact(self, caster)
25
25
  self:resolveCurrentAbilityDependentValue(self.autoDispel)
26
26
  )
27
27
  end
28
+ ____exports.RemoveBuffsTargetAbilityBehavior = __TS__Class()
29
+ local RemoveBuffsTargetAbilityBehavior = ____exports.RemoveBuffsTargetAbilityBehavior
30
+ RemoveBuffsTargetAbilityBehavior.name = "RemoveBuffsTargetAbilityBehavior"
31
+ __TS__ClassExtends(RemoveBuffsTargetAbilityBehavior, AbilityBehavior)
32
+ function RemoveBuffsTargetAbilityBehavior.prototype.____constructor(self, ability, polarity, resistanceType, includeExpirationTimers, includeAuras, autoDispel)
33
+ AbilityBehavior.prototype.____constructor(self, ability)
34
+ self.polarity = polarity
35
+ self.resistanceType = resistanceType
36
+ self.includeExpirationTimers = includeExpirationTimers
37
+ self.includeAuras = includeAuras
38
+ self.autoDispel = autoDispel
39
+ end
40
+ function RemoveBuffsTargetAbilityBehavior.prototype.onUnitTargetImpact(self, _, target)
41
+ target:removeBuffs(
42
+ self:resolveCurrentAbilityDependentValue(self.polarity),
43
+ self:resolveCurrentAbilityDependentValue(self.resistanceType),
44
+ self:resolveCurrentAbilityDependentValue(self.includeExpirationTimers),
45
+ self:resolveCurrentAbilityDependentValue(self.includeAuras),
46
+ self:resolveCurrentAbilityDependentValue(self.autoDispel)
47
+ )
48
+ end
28
49
  return ____exports
@@ -8,7 +8,7 @@ export declare class RestoreManaSelfAbilityBehavior extends AbilityBehavior {
8
8
  constructor(ability: Ability, mana: AbilityDependentValue<number>);
9
9
  onImpact(caster: Unit): void;
10
10
  }
11
- export declare class RestoreManaAbilityBehavior extends AbilityBehavior {
11
+ export declare class RestoreManaTargetAbilityBehavior extends AbilityBehavior {
12
12
  private readonly mana;
13
13
  constructor(ability: Ability, mana: AbilityDependentValue<number>);
14
14
  onUnitTargetImpact(caster: Unit, target: Unit): void;
@@ -15,15 +15,15 @@ end
15
15
  function RestoreManaSelfAbilityBehavior.prototype.onImpact(self, caster)
16
16
  caster.mana = caster.mana + self:resolveCurrentAbilityDependentValue(self.mana)
17
17
  end
18
- ____exports.RestoreManaAbilityBehavior = __TS__Class()
19
- local RestoreManaAbilityBehavior = ____exports.RestoreManaAbilityBehavior
20
- RestoreManaAbilityBehavior.name = "RestoreManaAbilityBehavior"
21
- __TS__ClassExtends(RestoreManaAbilityBehavior, AbilityBehavior)
22
- function RestoreManaAbilityBehavior.prototype.____constructor(self, ability, mana)
18
+ ____exports.RestoreManaTargetAbilityBehavior = __TS__Class()
19
+ local RestoreManaTargetAbilityBehavior = ____exports.RestoreManaTargetAbilityBehavior
20
+ RestoreManaTargetAbilityBehavior.name = "RestoreManaTargetAbilityBehavior"
21
+ __TS__ClassExtends(RestoreManaTargetAbilityBehavior, AbilityBehavior)
22
+ function RestoreManaTargetAbilityBehavior.prototype.____constructor(self, ability, mana)
23
23
  AbilityBehavior.prototype.____constructor(self, ability)
24
24
  self.mana = mana
25
25
  end
26
- function RestoreManaAbilityBehavior.prototype.onUnitTargetImpact(self, caster, target)
26
+ function RestoreManaTargetAbilityBehavior.prototype.onUnitTargetImpact(self, caster, target)
27
27
  target.mana = target.mana + self:resolveCurrentAbilityDependentValue(self.mana)
28
28
  end
29
29
  return ____exports
@@ -8,6 +8,7 @@ export type StunImmunityUnitBehaviourParameters = {
8
8
  buffTypeIds?: LuaSet<BuffTypeId>;
9
9
  textTagPreset?: TextTagPreset;
10
10
  textTagText?: string;
11
+ additionalAction?: (this: void, unit: Unit) => void;
11
12
  };
12
13
  export declare class StunImmunityUnitBehavior extends UnitBehavior {
13
14
  readonly parameters: Readonly<StunImmunityUnitBehaviourParameters>;
@@ -17,4 +18,5 @@ export declare class StunImmunityUnitBehavior extends UnitBehavior {
17
18
  onDamageReceived(): void;
18
19
  onTargetingAbilityChannelingStart(): void;
19
20
  onTargetingAbilityImpact(): void;
21
+ protected onEffect(): void;
20
22
  }
@@ -48,8 +48,15 @@ local function process(behavior)
48
48
  for buffTypeId in pairs(behavior.parameters.buffTypeIds or DEFAULT_BUFF_TYPE_IDS) do
49
49
  hasRemovedBuffs = hasRemovedBuffs or behavior.unit:removeBuff(buffTypeId)
50
50
  end
51
- if hasRemovedBuffs and behavior.parameters.textTagText ~= nil then
52
- TextTag:flash(TextTag.MISS, behavior.parameters.textTagText, behavior.unit.x, behavior.unit.y)
51
+ if hasRemovedBuffs then
52
+ behavior.onEffect(behavior)
53
+ if behavior.parameters.textTagText ~= nil then
54
+ TextTag:flash(TextTag.MISS, behavior.parameters.textTagText, behavior.unit.x, behavior.unit.y)
55
+ end
56
+ local ____opt_0 = behavior.parameters.additionalAction
57
+ if ____opt_0 ~= nil then
58
+ ____opt_0(behavior.unit)
59
+ end
53
60
  end
54
61
  end
55
62
  ____exports.StunImmunityUnitBehavior = __TS__Class()
@@ -79,5 +86,7 @@ end
79
86
  function StunImmunityUnitBehavior.prototype.onTargetingAbilityImpact(self)
80
87
  process(self)
81
88
  end
89
+ function StunImmunityUnitBehavior.prototype.onEffect(self)
90
+ end
82
91
  StunImmunityUnitBehavior.defaultParameters = {buffTypeIds = DEFAULT_BUFF_TYPE_IDS, textTagPreset = TextTag.MISS, textTagText = nil}
83
92
  return ____exports
@@ -11,13 +11,18 @@ import { Destructor } from "../../destroyable";
11
11
  import type { Widget } from "../../core/types/widget";
12
12
  import { Destructable } from "../../core/types/destructable";
13
13
  import type { Buff } from "../buff";
14
+ import { UnitBonusType } from "../internal/unit/bonus";
15
+ import { Player } from "../../core/types/player";
14
16
  export type UnitBehaviorConstructor<Args extends any[]> = new (unit: Unit, ...args: Args) => UnitBehavior;
15
17
  export declare abstract class UnitBehavior<PeriodicActionParameters extends any[] = any[]> extends Behavior<Unit, PeriodicActionParameters> {
18
+ readonly sourceAbilityBehavior?: AbilityBehavior;
19
+ private _bonusIdByBonusType?;
16
20
  constructor(unit: Unit);
17
21
  protected onDestroy(): Destructor;
18
- readonly sourceAbilityBehavior?: AbilityBehavior;
19
22
  get unit(): Unit;
20
- registerInRangeUnitEvent<T extends string, Args extends any[]>(this: UnitBehavior<PeriodicActionParameters> & Record<T, (this: this, ...args: Args) => unknown>, event: Event<[...Args]>, extractUnit: (...args: Args) => Unit | undefined, range: number, listener: T): void;
23
+ protected getUnitBonus(bonusType: UnitBonusType): number;
24
+ protected addOrUpdateOrRemoveUnitBonus(bonusType: UnitBonusType, value: number): void;
25
+ protected registerInRangeUnitEvent<T extends string, Args extends any[]>(this: UnitBehavior<PeriodicActionParameters> & Record<T, (this: this, ...args: Args) => unknown>, event: Event<[...Args]>, extractUnit: (...args: Args) => Unit | undefined, range: number, listener: T): void;
21
26
  onImmediateOrder(orderId: number): void;
22
27
  onTargetOrder(orderId: number, target: Widget): void;
23
28
  onPointOrder(orderId: number, x: number, y: number): void;
@@ -51,4 +56,5 @@ export declare abstract class UnitBehavior<PeriodicActionParameters extends any[
51
56
  onItemChargesChanged(item: Item): void;
52
57
  onKill(target: Unit): void;
53
58
  onDeath(source: Unit | undefined): void;
59
+ onOwnerChange(previousOwner: Player): void;
54
60
  }
@@ -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,8 +52,26 @@ 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
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
52
75
  function UnitBehavior.prototype.registerInRangeUnitEvent(self, event, extractUnit, range, listener)
53
76
  local rangeByBehavior = getOrPut(rangeByBehaviorByEvent, event, mutableLuaMap)
54
77
  rangeByBehavior[self] = range
@@ -65,8 +88,7 @@ function UnitBehavior.prototype.registerInRangeUnitEvent(self, event, extractUni
65
88
  for behavior in pairs(behaviors) do
66
89
  local range = rangeByBehavior[behavior]
67
90
  if range ~= nil and unit:getCollisionDistanceTo(behavior.unit) <= range then
68
- local ____self_6 = behavior
69
- ____self_6[listenerByBehavior[behavior]](____self_6, ...)
91
+ safeCall(behavior[listenerByBehavior[behavior]], behavior, ...)
70
92
  end
71
93
  end
72
94
  end
@@ -143,6 +165,8 @@ function UnitBehavior.prototype.onKill(self, target)
143
165
  end
144
166
  function UnitBehavior.prototype.onDeath(self, source)
145
167
  end
168
+ function UnitBehavior.prototype.onOwnerChange(self, previousOwner)
169
+ end
146
170
  __TS__SetDescriptor(
147
171
  UnitBehavior.prototype,
148
172
  "unit",
@@ -254,6 +278,9 @@ __TS__SetDescriptor(
254
278
  Unit.itemChargesChangedEvent:addListener(function(unit, item)
255
279
  ____exports.UnitBehavior:forAll(unit, "onItemChargesChanged", item)
256
280
  end)
281
+ Unit.onOwnerChange:addListener(function(unit, previousOwner)
282
+ ____exports.UnitBehavior:forAll(unit, "onOwnerChange", previousOwner)
283
+ end)
257
284
  end)(UnitBehavior)
258
285
  Unit.destroyEvent:addListener(function(unit)
259
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;
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
@@ -509,63 +506,50 @@ function Buff.prototype.____constructor(self, _unit, typeIdOrTypeIds, polarityOr
509
506
  self[100] = 1
510
507
  Event.invoke(buffCreatedEvent, self)
511
508
  end
512
- function Buff.prototype.getUnitBonus(self, bonusType)
513
- local ____opt_38 = self._bonusIdByBonusType
514
- local bonusId = ____opt_38 and ____opt_38[bonusType]
515
- return bonusId == nil and 0 or getUnitBonus(self._unit, bonusType, bonusId)
516
- end
517
- function Buff.prototype.addOrUpdateOrRemoveUnitBonus(self, bonusType, value)
518
- local bonusIdByBonusType = self._bonusIdByBonusType
519
- if bonusIdByBonusType == nil then
520
- bonusIdByBonusType = {}
521
- self._bonusIdByBonusType = bonusIdByBonusType
522
- end
523
- bonusIdByBonusType[bonusType] = addOrUpdateOrRemoveUnitBonus(self._unit, bonusType, bonusIdByBonusType[bonusType], value)
524
- end
525
509
  function Buff.prototype.flashEffect(self, widgetOrXOrParametersOrDuration, yOrParametersOrDuration, parametersOrDuration)
526
510
  if type(widgetOrXOrParametersOrDuration) == "number" and type(yOrParametersOrDuration) == "number" then
527
511
  Effect:flash(self[105], widgetOrXOrParametersOrDuration, yOrParametersOrDuration, parametersOrDuration)
528
512
  else
529
513
  local isWidgetProvided = __TS__InstanceOf(widgetOrXOrParametersOrDuration, Unit) or __TS__InstanceOf(widgetOrXOrParametersOrDuration, Item) or __TS__InstanceOf(widgetOrXOrParametersOrDuration, Destructable)
530
- local ____Effect_42 = Effect
531
- local ____Effect_flash_43 = Effect.flash
532
- local ____array_41 = __TS__SparseArrayNew(
514
+ local ____Effect_40 = Effect
515
+ local ____Effect_flash_41 = Effect.flash
516
+ local ____array_39 = __TS__SparseArrayNew(
533
517
  self[105],
534
518
  isWidgetProvided and widgetOrXOrParametersOrDuration or self._unit,
535
519
  stringValueByBuffTypeIdByFieldId[fourCC("feft")][self.typeId] or "origin"
536
520
  )
537
- local ____isWidgetProvided_40
521
+ local ____isWidgetProvided_38
538
522
  if isWidgetProvided then
539
- ____isWidgetProvided_40 = yOrParametersOrDuration
523
+ ____isWidgetProvided_38 = yOrParametersOrDuration
540
524
  else
541
- ____isWidgetProvided_40 = widgetOrXOrParametersOrDuration
525
+ ____isWidgetProvided_38 = widgetOrXOrParametersOrDuration
542
526
  end
543
- __TS__SparseArrayPush(____array_41, ____isWidgetProvided_40)
544
- ____Effect_flash_43(
545
- ____Effect_42,
546
- __TS__SparseArraySpread(____array_41)
527
+ __TS__SparseArrayPush(____array_39, ____isWidgetProvided_38)
528
+ ____Effect_flash_41(
529
+ ____Effect_40,
530
+ __TS__SparseArraySpread(____array_39)
547
531
  )
548
532
  end
549
533
  end
550
534
  function Buff.prototype.flashSpecialEffect(self, widgetOrDuration, duration)
551
535
  local isWidgetProvided = type(widgetOrDuration) == "table"
552
- local ____Effect_46 = Effect
553
- local ____Effect_flash_47 = Effect.flash
554
- local ____array_45 = __TS__SparseArrayNew(
536
+ local ____Effect_44 = Effect
537
+ local ____Effect_flash_45 = Effect.flash
538
+ local ____array_43 = __TS__SparseArrayNew(
555
539
  self[106],
556
540
  isWidgetProvided and widgetOrDuration or self._unit,
557
541
  stringValueByBuffTypeIdByFieldId[fourCC("fspt")][self.typeId] or "origin"
558
542
  )
559
- local ____isWidgetProvided_44
543
+ local ____isWidgetProvided_42
560
544
  if isWidgetProvided then
561
- ____isWidgetProvided_44 = duration
545
+ ____isWidgetProvided_42 = duration
562
546
  else
563
- ____isWidgetProvided_44 = widgetOrDuration
547
+ ____isWidgetProvided_42 = widgetOrDuration
564
548
  end
565
- __TS__SparseArrayPush(____array_45, ____isWidgetProvided_44)
566
- ____Effect_flash_47(
567
- ____Effect_46,
568
- __TS__SparseArraySpread(____array_45)
549
+ __TS__SparseArrayPush(____array_43, ____isWidgetProvided_42)
550
+ ____Effect_flash_45(
551
+ ____Effect_44,
552
+ __TS__SparseArraySpread(____array_43)
569
553
  )
570
554
  end
571
555
  function Buff.prototype.onCreate(self)
@@ -604,7 +588,7 @@ function Buff.prototype.onDestroy(self)
604
588
  end
605
589
  if self[136] then
606
590
  if self[137] then
607
- unit:decrementStunCounter()
591
+ unit:decrementForceStunCounter()
608
592
  end
609
593
  unit:decrementStunCounter()
610
594
  end
@@ -616,11 +600,6 @@ function Buff.prototype.onDestroy(self)
616
600
  unit:removeAbility(abilityTypeId)
617
601
  end
618
602
  end
619
- if self._bonusIdByBonusType ~= nil then
620
- for bonusType, bonusId in pairs(self._bonusIdByBonusType) do
621
- removeUnitBonus(unit, bonusType, bonusId)
622
- end
623
- end
624
603
  Event.invoke(buffBeingDestroyedEvent, self)
625
604
  self[100] = 3
626
605
  return UnitBehavior.prototype.onDestroy(self)
@@ -650,8 +629,8 @@ function Buff.apply(self, ...)
650
629
  end
651
630
  end
652
631
  function Buff.getByTypeId(self, unit, typeId)
653
- local ____opt_48 = buffByTypeIdByUnit[unit]
654
- local buff = ____opt_48 and ____opt_48[typeId]
632
+ local ____opt_46 = buffByTypeIdByUnit[unit]
633
+ local buff = ____opt_46 and ____opt_46[typeId]
655
634
  if __TS__InstanceOf(buff, self) then
656
635
  return buff
657
636
  end
@@ -809,8 +788,8 @@ __TS__SetDescriptor(
809
788
  return
810
789
  end
811
790
  self[112] = damageInterval
812
- local ____opt_50 = self._timer
813
- 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
814
793
  local timer = self[114]
815
794
  if timer == nil then
816
795
  timer = Timer:create()
@@ -889,8 +868,8 @@ __TS__SetDescriptor(
889
868
  return
890
869
  end
891
870
  self[117] = healingInterval
892
- local ____opt_52 = self._timer
893
- 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
894
873
  local timer = self[119]
895
874
  if timer == nil then
896
875
  timer = Timer:create()
@@ -976,11 +955,11 @@ __TS__SetDescriptor(
976
955
  "turnsIntoGhost",
977
956
  {
978
957
  get = function(self)
979
- local ____self__135_54 = self[135]
980
- if ____self__135_54 == nil then
981
- ____self__135_54 = false
958
+ local ____self__135_52 = self[135]
959
+ if ____self__135_52 == nil then
960
+ ____self__135_52 = false
982
961
  end
983
- return ____self__135_54
962
+ return ____self__135_52
984
963
  end,
985
964
  set = function(self, turnsIntoGhost)
986
965
  if not turnsIntoGhost and self[135] then
@@ -999,22 +978,22 @@ __TS__SetDescriptor(
999
978
  "stuns",
1000
979
  {
1001
980
  get = function(self)
1002
- local ____self__136_55 = self[136]
1003
- if ____self__136_55 == nil then
1004
- ____self__136_55 = false
981
+ local ____self__136_53 = self[136]
982
+ if ____self__136_53 == nil then
983
+ ____self__136_53 = false
1005
984
  end
1006
- return ____self__136_55
985
+ return ____self__136_53
1007
986
  end,
1008
987
  set = function(self, stuns)
1009
988
  if not stuns and self[136] then
1010
989
  if self[137] then
1011
- self.object:decrementStunCounter()
990
+ self.object:decrementForceStunCounter()
1012
991
  end
1013
992
  self.object:decrementStunCounter()
1014
993
  self[136] = nil
1015
994
  elseif stuns and not self[136] then
1016
995
  if self[137] then
1017
- self.object:incrementStunCounter()
996
+ self.object:incrementForceStunCounter()
1018
997
  end
1019
998
  self.object:incrementStunCounter()
1020
999
  self[136] = true
@@ -1028,21 +1007,21 @@ __TS__SetDescriptor(
1028
1007
  "ignoresStunImmunity",
1029
1008
  {
1030
1009
  get = function(self)
1031
- local ____self__137_56 = self[137]
1032
- if ____self__137_56 == nil then
1033
- ____self__137_56 = false
1010
+ local ____self__137_54 = self[137]
1011
+ if ____self__137_54 == nil then
1012
+ ____self__137_54 = false
1034
1013
  end
1035
- return ____self__137_56
1014
+ return ____self__137_54
1036
1015
  end,
1037
1016
  set = function(self, ignoresStunImmunity)
1038
1017
  if not ignoresStunImmunity and self[137] then
1039
1018
  if self[136] then
1040
- self.object:decrementStunCounter()
1019
+ self.object:decrementForceStunCounter()
1041
1020
  end
1042
1021
  self[137] = nil
1043
1022
  elseif ignoresStunImmunity and not self[137] then
1044
1023
  if self[136] then
1045
- self.object:incrementStunCounter()
1024
+ self.object:incrementForceStunCounter()
1046
1025
  end
1047
1026
  self[137] = true
1048
1027
  end
@@ -1055,11 +1034,11 @@ __TS__SetDescriptor(
1055
1034
  "disablesAutoAttack",
1056
1035
  {
1057
1036
  get = function(self)
1058
- local ____self__138_57 = self[138]
1059
- if ____self__138_57 == nil then
1060
- ____self__138_57 = false
1037
+ local ____self__138_55 = self[138]
1038
+ if ____self__138_55 == nil then
1039
+ ____self__138_55 = false
1061
1040
  end
1062
- return ____self__138_57
1041
+ return ____self__138_55
1063
1042
  end,
1064
1043
  set = function(self, disablesAutoAttack)
1065
1044
  if not disablesAutoAttack and self[138] then
@@ -1078,11 +1057,11 @@ __TS__SetDescriptor(
1078
1057
  "providesInvulnerability",
1079
1058
  {
1080
1059
  get = function(self)
1081
- local ____self__139_58 = self[139]
1082
- if ____self__139_58 == nil then
1083
- ____self__139_58 = false
1060
+ local ____self__139_56 = self[139]
1061
+ if ____self__139_56 == nil then
1062
+ ____self__139_56 = false
1084
1063
  end
1085
- return ____self__139_58
1064
+ return ____self__139_56
1086
1065
  end,
1087
1066
  set = function(self, providesInvulnerability)
1088
1067
  if not providesInvulnerability and self[139] then
@@ -1101,11 +1080,11 @@ __TS__SetDescriptor(
1101
1080
  "killsOnExpiration",
1102
1081
  {
1103
1082
  get = function(self)
1104
- local ____self__140_59 = self[140]
1105
- if ____self__140_59 == nil then
1106
- ____self__140_59 = false
1083
+ local ____self__140_57 = self[140]
1084
+ if ____self__140_57 == nil then
1085
+ ____self__140_57 = false
1107
1086
  end
1108
- return ____self__140_59
1087
+ return ____self__140_57
1109
1088
  end,
1110
1089
  set = function(self, killsOnExpiration)
1111
1090
  if not killsOnExpiration and self[140] then
@@ -1122,11 +1101,11 @@ __TS__SetDescriptor(
1122
1101
  "explodesOnExpiration",
1123
1102
  {
1124
1103
  get = function(self)
1125
- local ____self__141_60 = self[141]
1126
- if ____self__141_60 == nil then
1127
- ____self__141_60 = false
1104
+ local ____self__141_58 = self[141]
1105
+ if ____self__141_58 == nil then
1106
+ ____self__141_58 = false
1128
1107
  end
1129
- return ____self__141_60
1108
+ return ____self__141_58
1130
1109
  end,
1131
1110
  set = function(self, killsOnExpiration)
1132
1111
  if not killsOnExpiration and self[141] then
@@ -1254,13 +1233,13 @@ __TS__SetDescriptor(
1254
1233
  "remainingDuration",
1255
1234
  {
1256
1235
  get = function(self)
1257
- local ____opt_61 = self._timer
1258
- 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
1259
1238
  end,
1260
1239
  set = function(self, remainingDuration)
1261
- local ____remainingDuration_65 = remainingDuration
1262
- local ____opt_63 = self._timer
1263
- 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)
1264
1243
  if remainingDurationDelta ~= 0 then
1265
1244
  self[103] = self[103] + remainingDurationDelta
1266
1245
  if remainingDuration <= 0 then
@@ -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
  }