warscript 0.0.1-dev.7278154 → 0.0.1-dev.72f8823

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 (63) hide show
  1. package/attributes.d.ts +1 -0
  2. package/attributes.lua +9 -0
  3. package/core/types/frame.lua +14 -9
  4. package/core/types/player.d.ts +15 -0
  5. package/core/types/player.lua +53 -13
  6. package/core/types/playerCamera.lua +44 -0
  7. package/core/types/tileCell.d.ts +11 -1
  8. package/core/types/tileCell.lua +97 -0
  9. package/core/types/timer.d.ts +3 -2
  10. package/core/types/timer.lua +8 -2
  11. package/decl/native.d.ts +2 -2
  12. package/engine/behavior.d.ts +8 -1
  13. package/engine/behavior.lua +97 -65
  14. package/engine/behaviour/ability/remove-buffs.d.ts +9 -0
  15. package/engine/behaviour/ability/remove-buffs.lua +21 -0
  16. package/engine/behaviour/unit/stun-immunity.d.ts +8 -4
  17. package/engine/behaviour/unit/stun-immunity.lua +12 -3
  18. package/engine/behaviour/unit.d.ts +7 -3
  19. package/engine/behaviour/unit.lua +31 -2
  20. package/engine/buff.d.ts +10 -1
  21. package/engine/buff.lua +60 -7
  22. package/engine/internal/ability.lua +6 -5
  23. package/engine/internal/item.d.ts +13 -15
  24. package/engine/internal/item.lua +59 -48
  25. package/engine/internal/unit/ability.d.ts +14 -14
  26. package/engine/internal/unit/ability.lua +72 -45
  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 +44 -20
  33. package/engine/internal/unit.d.ts +15 -12
  34. package/engine/internal/unit.lua +89 -69
  35. package/engine/local-client.d.ts +2 -0
  36. package/engine/local-client.lua +30 -0
  37. package/engine/object-data/entry/ability-type.lua +4 -1
  38. package/engine/object-field/unit.d.ts +13 -1
  39. package/engine/object-field/unit.lua +57 -0
  40. package/engine/object-field.d.ts +7 -1
  41. package/engine/object-field.lua +199 -112
  42. package/engine/random.d.ts +9 -0
  43. package/engine/random.lua +13 -0
  44. package/engine/standard/fields/unit.d.ts +3 -1
  45. package/engine/standard/fields/unit.lua +4 -0
  46. package/engine/synchronization.d.ts +11 -0
  47. package/engine/synchronization.lua +77 -0
  48. package/engine/text-tag.lua +3 -2
  49. package/engine/unit.d.ts +2 -0
  50. package/engine/unit.lua +2 -0
  51. package/net/socket.lua +1 -1
  52. package/objutil/buff.lua +1 -1
  53. package/package.json +2 -2
  54. package/patch-lualib.lua +1 -1
  55. package/utility/arrays.d.ts +1 -0
  56. package/utility/arrays.lua +8 -0
  57. package/utility/callback-array.d.ts +5 -1
  58. package/utility/callback-array.lua +16 -1
  59. package/utility/linked-set.d.ts +1 -0
  60. package/utility/linked-set.lua +19 -1
  61. package/utility/lua-maps.d.ts +11 -2
  62. package/utility/lua-maps.lua +33 -2
  63. package/utility/types.d.ts +3 -0
@@ -18,39 +18,41 @@ local mutableLuaMap = ____lua_2Dmaps.mutableLuaMap
18
18
  local ____lua_2Dsets = require("utility.lua-sets")
19
19
  local mutableLuaSet = ____lua_2Dsets.mutableLuaSet
20
20
  local safeCall = warpack.safeCall
21
- local firstBehaviorByObject = {}
22
- local lastBehaviorByObject = {}
21
+ local firstBehaviorByObjectByPriority = {[0] = {}, [2] = {}, [1] = {}}
22
+ local lastBehaviorByObjectByPriority = {[0] = {}, [2] = {}, [1] = {}}
23
23
  local function invokeBehaviorOnPeriod(behavior, ...)
24
24
  behavior.onPeriod(behavior, ...)
25
25
  end
26
26
  local function reduceBehaviors(behaviorConstructor, object, operation, initial, consumerOrKey, ...)
27
27
  local accumulator = initial
28
- local behavior = firstBehaviorByObject[object]
29
- if behavior ~= nil then
30
- if type(consumerOrKey) == "function" then
31
- repeat
32
- do
33
- if __TS__InstanceOf(behavior, behaviorConstructor) then
34
- local isSuccessful, result = safeCall(consumerOrKey, behavior, ...)
35
- if isSuccessful then
36
- accumulator = operation(accumulator, result)
28
+ for priority = 0, 2 do
29
+ local behavior = firstBehaviorByObjectByPriority[priority][object]
30
+ if behavior ~= nil then
31
+ if type(consumerOrKey) == "function" then
32
+ repeat
33
+ do
34
+ if __TS__InstanceOf(behavior, behaviorConstructor) then
35
+ local isSuccessful, result = safeCall(consumerOrKey, behavior, ...)
36
+ if isSuccessful then
37
+ accumulator = operation(accumulator, result)
38
+ end
37
39
  end
40
+ behavior = behavior[1]
38
41
  end
39
- behavior = behavior[1]
40
- end
41
- until not (behavior ~= nil)
42
- else
43
- repeat
44
- do
45
- if __TS__InstanceOf(behavior, behaviorConstructor) then
46
- local isSuccessful, result = safeCall(behavior[consumerOrKey], behavior, ...)
47
- if isSuccessful then
48
- accumulator = operation(accumulator, result)
42
+ until not (behavior ~= nil)
43
+ else
44
+ repeat
45
+ do
46
+ if __TS__InstanceOf(behavior, behaviorConstructor) then
47
+ local isSuccessful, result = safeCall(behavior[consumerOrKey], behavior, ...)
48
+ if isSuccessful then
49
+ accumulator = operation(accumulator, result)
50
+ end
49
51
  end
52
+ behavior = behavior[1]
50
53
  end
51
- behavior = behavior[1]
52
- end
53
- until not (behavior ~= nil)
54
+ until not (behavior ~= nil)
55
+ end
54
56
  end
55
57
  end
56
58
  return accumulator
@@ -62,12 +64,17 @@ ____exports.Behavior = __TS__Class()
62
64
  local Behavior = ____exports.Behavior
63
65
  Behavior.name = "Behavior"
64
66
  __TS__ClassExtends(Behavior, AbstractDestroyable)
65
- function Behavior.prototype.____constructor(self, object)
67
+ function Behavior.prototype.____constructor(self, object, priority)
68
+ if priority == nil then
69
+ priority = 1
70
+ end
66
71
  AbstractDestroyable.prototype.____constructor(self)
67
72
  self.object = object
73
+ self.priority = priority
74
+ local lastBehaviorByObject = lastBehaviorByObjectByPriority[priority]
68
75
  local lastBehavior = lastBehaviorByObject[object]
69
76
  if lastBehavior == nil then
70
- firstBehaviorByObject[object] = self
77
+ firstBehaviorByObjectByPriority[priority][object] = self
71
78
  lastBehaviorByObject[object] = self
72
79
  else
73
80
  self[0] = lastBehavior
@@ -99,12 +106,12 @@ function Behavior.prototype.onDestroy(self)
99
106
  if previousBehavior ~= nil then
100
107
  previousBehavior[1] = nextBehavior
101
108
  else
102
- firstBehaviorByObject[self.object] = nextBehavior
109
+ firstBehaviorByObjectByPriority[self.priority][self.object] = nextBehavior
103
110
  end
104
111
  if nextBehavior ~= nil then
105
112
  nextBehavior[0] = previousBehavior
106
113
  else
107
- lastBehaviorByObject[self.object] = previousBehavior
114
+ lastBehaviorByObjectByPriority[self.priority][self.object] = previousBehavior
108
115
  end
109
116
  return AbstractDestroyable.prototype.onDestroy(self)
110
117
  end
@@ -127,6 +134,15 @@ function Behavior.prototype.registerEvent(self, event, listener)
127
134
  end
128
135
  behaviors:add(self)
129
136
  end
137
+ function Behavior.prototype.deregisterEvent(self, event)
138
+ local behaviors = behaviorsByEvent[event]
139
+ if behaviors ~= nil and behaviors:remove(self) then
140
+ eventsByBehavior[self][event] = nil
141
+ listenerByBehaviorByEvent[event][self] = nil
142
+ return true
143
+ end
144
+ return false
145
+ end
130
146
  function Behavior.prototype.onPeriod(self, ...)
131
147
  end
132
148
  function Behavior.prototype.startPeriodicAction(self, interval, ...)
@@ -152,78 +168,94 @@ function Behavior.prototype.stopPeriodicAction(self)
152
168
  end
153
169
  function Behavior.count(self, object, limit)
154
170
  local behaviorsCount = 0
155
- local behavior = firstBehaviorByObject[object]
156
- while behavior ~= nil and (limit == nil or behaviorsCount < limit) do
157
- if __TS__InstanceOf(behavior, self) then
158
- behaviorsCount = behaviorsCount + 1
171
+ for priority = 0, 2 do
172
+ local behavior = firstBehaviorByObjectByPriority[priority][object]
173
+ while behavior ~= nil and (limit == nil or behaviorsCount < limit) do
174
+ if __TS__InstanceOf(behavior, self) then
175
+ behaviorsCount = behaviorsCount + 1
176
+ end
177
+ behavior = behavior[1]
159
178
  end
160
- behavior = behavior[1]
161
179
  end
162
180
  return behaviorsCount
163
181
  end
164
182
  function Behavior.getFirst(self, object, countOrPredicate, ...)
165
- local behavior = firstBehaviorByObject[object]
166
183
  if type(countOrPredicate) ~= "number" then
167
- while behavior ~= nil do
168
- if __TS__InstanceOf(behavior, self) and (countOrPredicate == nil or countOrPredicate(behavior, ...)) then
169
- return behavior
184
+ for priority = 0, 2 do
185
+ local behavior = firstBehaviorByObjectByPriority[priority][object]
186
+ while behavior ~= nil do
187
+ if __TS__InstanceOf(behavior, self) and (countOrPredicate == nil or countOrPredicate(behavior, ...)) then
188
+ return behavior
189
+ end
190
+ behavior = behavior[1]
170
191
  end
171
- behavior = behavior[1]
172
192
  end
173
193
  return nil
174
194
  end
175
195
  local behaviors = {}
176
196
  local behaviorsCount = 0
177
- while behavior ~= nil and behaviorsCount < countOrPredicate do
178
- if __TS__InstanceOf(behavior, self) then
179
- behaviorsCount = behaviorsCount + 1
180
- behaviors[behaviorsCount] = behavior
197
+ for priority = 0, 2 do
198
+ local behavior = firstBehaviorByObjectByPriority[priority][object]
199
+ while behavior ~= nil and behaviorsCount < countOrPredicate do
200
+ if __TS__InstanceOf(behavior, self) then
201
+ behaviorsCount = behaviorsCount + 1
202
+ behaviors[behaviorsCount] = behavior
203
+ end
204
+ behavior = behavior[1]
181
205
  end
182
- behavior = behavior[1]
183
206
  end
184
207
  return behaviors
185
208
  end
186
209
  function Behavior.getLast(self, object)
187
- local behavior = lastBehaviorByObject[object]
188
- while behavior ~= nil do
189
- if __TS__InstanceOf(behavior, self) then
190
- return behavior
210
+ for priority = 2, 0, -1 do
211
+ local behavior = lastBehaviorByObjectByPriority[priority][object]
212
+ while behavior ~= nil do
213
+ if __TS__InstanceOf(behavior, self) then
214
+ return behavior
215
+ end
216
+ behavior = behavior[0]
191
217
  end
192
- behavior = behavior[0]
193
218
  end
194
219
  return nil
195
220
  end
196
221
  function Behavior.getAll(self, object, predicate, ...)
197
222
  local behaviors = {}
198
223
  local behaviorsCount = 0
199
- local behavior = firstBehaviorByObject[object]
200
- while behavior ~= nil do
201
- if __TS__InstanceOf(behavior, self) and (predicate == nil or predicate(behavior, ...)) then
202
- behaviorsCount = behaviorsCount + 1
203
- behaviors[behaviorsCount] = behavior
224
+ for priority = 0, 2 do
225
+ local behavior = firstBehaviorByObjectByPriority[priority][object]
226
+ while behavior ~= nil do
227
+ if __TS__InstanceOf(behavior, self) and (predicate == nil or predicate(behavior, ...)) then
228
+ behaviorsCount = behaviorsCount + 1
229
+ behaviors[behaviorsCount] = behavior
230
+ end
231
+ behavior = behavior[1]
204
232
  end
205
- behavior = behavior[1]
206
233
  end
207
234
  return behaviors
208
235
  end
209
236
  function Behavior.forFirst(self, object, count, consumerOrKey, ...)
210
237
  local behaviorsCount = 0
211
- local behavior = firstBehaviorByObject[object]
212
238
  if type(consumerOrKey) == "function" then
213
- while behavior ~= nil and behaviorsCount < count do
214
- if __TS__InstanceOf(behavior, self) then
215
- safeCall(consumerOrKey, behavior, ...)
216
- behaviorsCount = behaviorsCount + 1
239
+ for priority = 0, 2 do
240
+ local behavior = firstBehaviorByObjectByPriority[priority][object]
241
+ while behavior ~= nil and behaviorsCount < count do
242
+ if __TS__InstanceOf(behavior, self) then
243
+ safeCall(consumerOrKey, behavior, ...)
244
+ behaviorsCount = behaviorsCount + 1
245
+ end
246
+ behavior = behavior[1]
217
247
  end
218
- behavior = behavior[1]
219
248
  end
220
249
  else
221
- while behavior ~= nil and behaviorsCount < count do
222
- if __TS__InstanceOf(behavior, self) then
223
- safeCall(behavior[consumerOrKey], behavior, ...)
224
- behaviorsCount = behaviorsCount + 1
250
+ for priority = 0, 2 do
251
+ local behavior = firstBehaviorByObjectByPriority[priority][object]
252
+ while behavior ~= nil and behaviorsCount < count do
253
+ if __TS__InstanceOf(behavior, self) then
254
+ safeCall(behavior[consumerOrKey], behavior, ...)
255
+ behaviorsCount = behaviorsCount + 1
256
+ end
257
+ behavior = behavior[1]
225
258
  end
226
- behavior = behavior[1]
227
259
  end
228
260
  end
229
261
  return behaviorsCount
@@ -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
@@ -4,17 +4,21 @@ import { Unit } from "../../unit";
4
4
  import { BuffTypeId } from "../../object-data/entry/buff-type";
5
5
  import { TextTagPreset } from "../../text-tag";
6
6
  import { Destructor } from "../../../destroyable";
7
- export type StunImmunityUnitBehaviourParameters = {
7
+ import { BehaviorPriority } from "../../behavior";
8
+ export type StunImmunityUnitBehaviorParameters = {
9
+ readonly priority?: BehaviorPriority;
8
10
  buffTypeIds?: LuaSet<BuffTypeId>;
9
11
  textTagPreset?: TextTagPreset;
10
12
  textTagText?: string;
13
+ additionalAction?: (this: void, unit: Unit) => void;
11
14
  };
12
15
  export declare class StunImmunityUnitBehavior extends UnitBehavior {
13
- readonly parameters: Readonly<StunImmunityUnitBehaviourParameters>;
14
- static defaultParameters: StunImmunityUnitBehaviourParameters;
15
- constructor(unit: Unit, parameters?: Readonly<StunImmunityUnitBehaviourParameters>);
16
+ readonly parameters: Readonly<StunImmunityUnitBehaviorParameters>;
17
+ static defaultParameters: StunImmunityUnitBehaviorParameters;
18
+ constructor(unit: Unit, parameters?: Readonly<StunImmunityUnitBehaviorParameters>);
16
19
  protected onDestroy(): Destructor;
17
20
  onDamageReceived(): void;
18
21
  onTargetingAbilityChannelingStart(): void;
19
22
  onTargetingAbilityImpact(): void;
23
+ protected onEffect(): void;
20
24
  }
@@ -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()
@@ -60,7 +67,7 @@ function StunImmunityUnitBehavior.prototype.____constructor(self, unit, paramete
60
67
  if parameters == nil then
61
68
  parameters = ____exports.StunImmunityUnitBehavior.defaultParameters
62
69
  end
63
- UnitBehavior.prototype.____constructor(self, unit)
70
+ UnitBehavior.prototype.____constructor(self, unit, parameters.priority)
64
71
  self.parameters = parameters
65
72
  unit:decrementStunCounter()
66
73
  process(self)
@@ -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
@@ -1,22 +1,24 @@
1
1
  /** @noSelfInFile */
2
- import { Behavior } from "../behavior";
2
+ import { Behavior, BehaviorPriority } from "../behavior";
3
3
  import { Ability } from "../internal/ability";
4
4
  import { DamageEvent, DamagingEvent, Unit } from "../internal/unit";
5
5
  import "../internal/unit+ability";
6
6
  import "../internal/unit-missile-launch";
7
7
  import { Item } from "../internal/item";
8
- import type { AbilityBehavior } from "./ability";
8
+ import { AbilityBehavior } from "./ability";
9
9
  import { Event } from "../../event";
10
10
  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
14
  import { UnitBonusType } from "../internal/unit/bonus";
15
+ import { Player } from "../../core/types/player";
16
+ import { UnitTypeId } from "../object-data/entry/unit-type";
15
17
  export type UnitBehaviorConstructor<Args extends any[]> = new (unit: Unit, ...args: Args) => UnitBehavior;
16
18
  export declare abstract class UnitBehavior<PeriodicActionParameters extends any[] = any[]> extends Behavior<Unit, PeriodicActionParameters> {
17
19
  readonly sourceAbilityBehavior?: AbilityBehavior;
18
20
  private _bonusIdByBonusType?;
19
- constructor(unit: Unit);
21
+ constructor(unit: Unit, priority?: BehaviorPriority);
20
22
  protected onDestroy(): Destructor;
21
23
  get unit(): Unit;
22
24
  protected getUnitBonus(bonusType: UnitBonusType): number;
@@ -55,4 +57,6 @@ export declare abstract class UnitBehavior<PeriodicActionParameters extends any[
55
57
  onItemChargesChanged(item: Item): void;
56
58
  onKill(target: Unit): void;
57
59
  onDeath(source: Unit | undefined): void;
60
+ onOwnerChange(previousOwner: Player): void;
61
+ static bindUnitType<Args extends any[]>(this: UnitBehaviorConstructor<Args>, unitTypeId: UnitTypeId, ...args: Args): void;
58
62
  }
@@ -22,6 +22,7 @@ local addOrUpdateOrRemoveUnitBonus = ____bonus.addOrUpdateOrRemoveUnitBonus
22
22
  local getUnitBonus = ____bonus.getUnitBonus
23
23
  local removeUnitBonus = ____bonus.removeUnitBonus
24
24
  local safeCall = warpack.safeCall
25
+ local createBehaviorFunctionsByUnitTypeId = {}
25
26
  local behaviorsByEvent = {}
26
27
  local rangeByBehaviorByEvent = {}
27
28
  local listenerByBehaviorByEvent = {}
@@ -30,8 +31,8 @@ ____exports.UnitBehavior = __TS__Class()
30
31
  local UnitBehavior = ____exports.UnitBehavior
31
32
  UnitBehavior.name = "UnitBehavior"
32
33
  __TS__ClassExtends(UnitBehavior, Behavior)
33
- function UnitBehavior.prototype.____constructor(self, unit)
34
- Behavior.prototype.____constructor(self, unit)
34
+ function UnitBehavior.prototype.____constructor(self, unit, priority)
35
+ Behavior.prototype.____constructor(self, unit, priority)
35
36
  end
36
37
  function UnitBehavior.prototype.onDestroy(self)
37
38
  local events = eventsByBehavior[self]
@@ -165,6 +166,23 @@ function UnitBehavior.prototype.onKill(self, target)
165
166
  end
166
167
  function UnitBehavior.prototype.onDeath(self, source)
167
168
  end
169
+ function UnitBehavior.prototype.onOwnerChange(self, previousOwner)
170
+ end
171
+ function UnitBehavior.bindUnitType(self, unitTypeId, ...)
172
+ local args = {...}
173
+ local createBehaviorFunctions = createBehaviorFunctionsByUnitTypeId[unitTypeId]
174
+ if createBehaviorFunctions == nil then
175
+ createBehaviorFunctions = {}
176
+ createBehaviorFunctionsByUnitTypeId[unitTypeId] = createBehaviorFunctions
177
+ end
178
+ createBehaviorFunctions[#createBehaviorFunctions + 1] = function(unit)
179
+ return __TS__New(
180
+ self,
181
+ unit,
182
+ table.unpack(args)
183
+ )
184
+ end
185
+ end
168
186
  __TS__SetDescriptor(
169
187
  UnitBehavior.prototype,
170
188
  "unit",
@@ -276,7 +294,18 @@ __TS__SetDescriptor(
276
294
  Unit.itemChargesChangedEvent:addListener(function(unit, item)
277
295
  ____exports.UnitBehavior:forAll(unit, "onItemChargesChanged", item)
278
296
  end)
297
+ Unit.onOwnerChange:addListener(function(unit, previousOwner)
298
+ ____exports.UnitBehavior:forAll(unit, "onOwnerChange", previousOwner)
299
+ end)
279
300
  end)(UnitBehavior)
301
+ Unit.onCreate:addListener(function(unit)
302
+ local createBehaviorFunctions = createBehaviorFunctionsByUnitTypeId[unit.typeId]
303
+ if createBehaviorFunctions ~= nil then
304
+ for ____, createBehavior in ipairs(createBehaviorFunctions) do
305
+ createBehavior(unit)
306
+ end
307
+ end
308
+ end)
280
309
  Unit.destroyEvent:addListener(function(unit)
281
310
  ____exports.UnitBehavior:forAll(unit, "destroy")
282
311
  end)
package/engine/buff.d.ts CHANGED
@@ -79,6 +79,7 @@ export type BuffParameters<T extends Buff<any> = Buff> = Buff extends T ? {
79
79
  healingOnExpiration?: NumberParameterValueType;
80
80
  killsOnExpiration?: BooleanParameterValueType;
81
81
  explodesOnExpiration?: BooleanParameterValueType;
82
+ abilityCooldownFactor?: NumberParameterValueType;
82
83
  uniqueGroup?: BuffUniqueGroup;
83
84
  } : BuffParameters & (T extends Buff<infer AdditionalParameters> ? AdditionalParameters : object);
84
85
  declare const enum BuffPropertyKey {
@@ -124,7 +125,9 @@ declare const enum BuffPropertyKey {
124
125
  PROVIDES_INVULNERABILITY = 139,
125
126
  KILLS_ON_EXPIRATION = 140,
126
127
  EXPLODES_ON_EXPIRATION = 141,
127
- MISS_PROBABILITY = 142
128
+ MISS_PROBABILITY = 142,
129
+ ABILITY_COOLDOWN_FACTOR = 143,
130
+ ABILITY_COOLDOWN_MODIFIER = 144
128
131
  }
129
132
  export declare const enum BuffTypeIdSelectionPolicy {
130
133
  LEAST_DURATION = 0
@@ -187,6 +190,8 @@ export declare class Buff<AdditionalParameters extends Prohibit<Record<string, a
187
190
  private [BuffPropertyKey.PROVIDES_INVULNERABILITY]?;
188
191
  private [BuffPropertyKey.KILLS_ON_EXPIRATION]?;
189
192
  private [BuffPropertyKey.EXPLODES_ON_EXPIRATION]?;
193
+ private [BuffPropertyKey.ABILITY_COOLDOWN_FACTOR]?;
194
+ private [BuffPropertyKey.ABILITY_COOLDOWN_MODIFIER]?;
190
195
  protected static readonly defaultParameters: BuffParameters;
191
196
  get source(): Unit;
192
197
  readonly typeId: ApplicableBuffTypeId;
@@ -262,6 +267,10 @@ export declare class Buff<AdditionalParameters extends Prohibit<Record<string, a
262
267
  get duration(): number;
263
268
  get remainingDuration(): number;
264
269
  set remainingDuration(remainingDuration: number);
270
+ get abilityCooldownFactor(): number;
271
+ set abilityCooldownFactor(abilityCooldownFactor: number);
272
+ onAbilityGained(ability: Ability): void;
273
+ onAbilityLost(ability: Ability): void;
265
274
  flashEffect(...parameters: [
266
275
  ...widgetOrXY: [] | [Widget] | [x: number, x: number],
267
276
  ...parametersOrDuration: [] | [EffectParameters] | [number]
package/engine/buff.lua CHANGED
@@ -16,6 +16,7 @@ local internalApplyBuff = ____applicable.internalApplyBuff
16
16
  local removeBuff = ____applicable.removeBuff
17
17
  local ____ability = require("engine.internal.ability")
18
18
  local Ability = ____ability.Ability
19
+ local UnitAbility = ____ability.UnitAbility
19
20
  local ____ability = require("engine.object-field.ability")
20
21
  local AbilityBooleanField = ____ability.AbilityBooleanField
21
22
  local AbilityNumberField = ____ability.AbilityNumberField
@@ -50,6 +51,8 @@ local ____item = require("engine.internal.item")
50
51
  local Item = ____item.Item
51
52
  local ____destructable = require("core.types.destructable")
52
53
  local Destructable = ____destructable.Destructable
54
+ local ____ability = require("engine.standard.fields.ability")
55
+ local COOLDOWN_ABILITY_FLOAT_LEVEL_FIELD = ____ability.COOLDOWN_ABILITY_FLOAT_LEVEL_FIELD
53
56
  local getUnitAbility = BlzGetUnitAbility
54
57
  local stringValueByBuffTypeIdByFieldId = postcompile(function()
55
58
  local stringValueByBuffTypeIdByFieldId = {}
@@ -121,7 +124,8 @@ local buffParametersKeys = {
121
124
  damageOnExpiration = true,
122
125
  healingOnExpiration = true,
123
126
  killsOnExpiration = true,
124
- explodesOnExpiration = true
127
+ explodesOnExpiration = true,
128
+ abilityCooldownFactor = true
125
129
  }
126
130
  local function resolveEnumValue(ability, level, value)
127
131
  if value == nil or type(value) == "number" then
@@ -198,7 +202,8 @@ local buffNumberParameters = {
198
202
  "healingPerInterval",
199
203
  "healingOverDuration",
200
204
  "damageOnExpiration",
201
- "healingOnExpiration"
205
+ "healingOnExpiration",
206
+ "abilityCooldownFactor"
202
207
  }
203
208
  local unsuccessfulApplicationMarker = {}
204
209
  local function selectBuffTypeIdWithLeastDuration(buffTypeIds, unit)
@@ -506,6 +511,22 @@ function Buff.prototype.____constructor(self, _unit, typeIdOrTypeIds, polarityOr
506
511
  self[100] = 1
507
512
  Event.invoke(buffCreatedEvent, self)
508
513
  end
514
+ function Buff.prototype.onAbilityGained(self, ability)
515
+ if __TS__InstanceOf(ability, UnitAbility) then
516
+ local abilityCooldownModifier = self[144]
517
+ if abilityCooldownModifier then
518
+ COOLDOWN_ABILITY_FLOAT_LEVEL_FIELD:applyModifier(ability, abilityCooldownModifier)
519
+ end
520
+ end
521
+ end
522
+ function Buff.prototype.onAbilityLost(self, ability)
523
+ if __TS__InstanceOf(ability, UnitAbility) then
524
+ local abilityCooldownModifier = self[144]
525
+ if abilityCooldownModifier then
526
+ COOLDOWN_ABILITY_FLOAT_LEVEL_FIELD:removeModifier(ability, abilityCooldownModifier)
527
+ end
528
+ end
529
+ end
509
530
  function Buff.prototype.flashEffect(self, widgetOrXOrParametersOrDuration, yOrParametersOrDuration, parametersOrDuration)
510
531
  if type(widgetOrXOrParametersOrDuration) == "number" and type(yOrParametersOrDuration) == "number" then
511
532
  Effect:flash(self[105], widgetOrXOrParametersOrDuration, yOrParametersOrDuration, parametersOrDuration)
@@ -580,6 +601,12 @@ function Buff.prototype.onDestroy(self)
580
601
  behavior:destroy()
581
602
  end
582
603
  end
604
+ local previousAbilityCooldownModifier = self[144]
605
+ if previousAbilityCooldownModifier then
606
+ for ____, ability in ipairs(self._unit.abilities) do
607
+ COOLDOWN_ABILITY_FLOAT_LEVEL_FIELD:removeModifier(ability, previousAbilityCooldownModifier)
608
+ end
609
+ end
583
610
  if self[139] then
584
611
  unit:decrementInvulnerabilityCounter()
585
612
  end
@@ -588,7 +615,7 @@ function Buff.prototype.onDestroy(self)
588
615
  end
589
616
  if self[136] then
590
617
  if self[137] then
591
- unit:decrementStunCounter()
618
+ unit:decrementForceStunCounter()
592
619
  end
593
620
  unit:decrementStunCounter()
594
621
  end
@@ -987,13 +1014,13 @@ __TS__SetDescriptor(
987
1014
  set = function(self, stuns)
988
1015
  if not stuns and self[136] then
989
1016
  if self[137] then
990
- self.object:decrementStunCounter()
1017
+ self.object:decrementForceStunCounter()
991
1018
  end
992
1019
  self.object:decrementStunCounter()
993
1020
  self[136] = nil
994
1021
  elseif stuns and not self[136] then
995
1022
  if self[137] then
996
- self.object:incrementStunCounter()
1023
+ self.object:incrementForceStunCounter()
997
1024
  end
998
1025
  self.object:incrementStunCounter()
999
1026
  self[136] = true
@@ -1016,12 +1043,12 @@ __TS__SetDescriptor(
1016
1043
  set = function(self, ignoresStunImmunity)
1017
1044
  if not ignoresStunImmunity and self[137] then
1018
1045
  if self[136] then
1019
- self.object:decrementStunCounter()
1046
+ self.object:decrementForceStunCounter()
1020
1047
  end
1021
1048
  self[137] = nil
1022
1049
  elseif ignoresStunImmunity and not self[137] then
1023
1050
  if self[136] then
1024
- self.object:incrementStunCounter()
1051
+ self.object:incrementForceStunCounter()
1025
1052
  end
1026
1053
  self[137] = true
1027
1054
  end
@@ -1269,6 +1296,32 @@ __TS__SetDescriptor(
1269
1296
  },
1270
1297
  true
1271
1298
  )
1299
+ __TS__SetDescriptor(
1300
+ Buff.prototype,
1301
+ "abilityCooldownFactor",
1302
+ {
1303
+ get = function(self)
1304
+ return self[143] or 1
1305
+ end,
1306
+ set = function(self, abilityCooldownFactor)
1307
+ local previousAbilityCooldownModifier = self[144]
1308
+ if previousAbilityCooldownModifier then
1309
+ for ____, ability in ipairs(self._unit.abilities) do
1310
+ COOLDOWN_ABILITY_FLOAT_LEVEL_FIELD:removeModifier(ability, previousAbilityCooldownModifier)
1311
+ end
1312
+ end
1313
+ local function modifier(ability, level, cooldown)
1314
+ return cooldown * abilityCooldownFactor
1315
+ end
1316
+ for ____, ability in ipairs(self._unit.abilities) do
1317
+ COOLDOWN_ABILITY_FLOAT_LEVEL_FIELD:applyModifier(ability, modifier)
1318
+ end
1319
+ self[144] = modifier
1320
+ self[143] = abilityCooldownFactor
1321
+ end
1322
+ },
1323
+ true
1324
+ )
1272
1325
  Buff.createdEvent = buffCreatedEvent
1273
1326
  Buff.beingDestroyedEvent = buffBeingDestroyedEvent;
1274
1327
  (function(self)