warscript 0.0.1-dev.e561d29 → 0.0.1-dev.e698bed

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 (87) 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 +16 -0
  5. package/core/types/player.lua +60 -15
  6. package/core/types/playerCamera.d.ts +2 -0
  7. package/core/types/playerCamera.lua +123 -5
  8. package/core/types/tileCell.d.ts +11 -1
  9. package/core/types/tileCell.lua +97 -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 +10 -1
  14. package/engine/behavior.lua +141 -65
  15. package/engine/behaviour/ability/apply-buff.lua +12 -4
  16. package/engine/behaviour/ability/remove-buffs.d.ts +9 -0
  17. package/engine/behaviour/ability/remove-buffs.lua +21 -0
  18. package/engine/behaviour/ability/restore-mana.d.ts +1 -1
  19. package/engine/behaviour/ability/restore-mana.lua +6 -6
  20. package/engine/behaviour/unit/stun-immunity.d.ts +8 -4
  21. package/engine/behaviour/unit/stun-immunity.lua +12 -3
  22. package/engine/behaviour/unit.d.ts +15 -5
  23. package/engine/behaviour/unit.lua +116 -22
  24. package/engine/buff.d.ts +10 -4
  25. package/engine/buff.lua +119 -84
  26. package/engine/internal/ability.d.ts +3 -1
  27. package/engine/internal/ability.lua +26 -9
  28. package/engine/internal/item+owner.lua +12 -6
  29. package/engine/internal/item.d.ts +13 -15
  30. package/engine/internal/item.lua +63 -49
  31. package/engine/internal/misc/frame-coordinates.d.ts +2 -0
  32. package/engine/internal/misc/frame-coordinates.lua +21 -0
  33. package/engine/internal/misc/get-terrain-z.d.ts +2 -0
  34. package/engine/internal/misc/get-terrain-z.lua +11 -0
  35. package/engine/internal/misc/player-local-handle.d.ts +2 -0
  36. package/engine/internal/misc/player-local-handle.lua +5 -0
  37. package/engine/internal/unit/ability.d.ts +14 -14
  38. package/engine/internal/unit/ability.lua +72 -45
  39. package/engine/internal/unit/fly-height.d.ts +7 -0
  40. package/engine/internal/unit/fly-height.lua +20 -0
  41. package/engine/internal/unit/main-selected.lua +12 -27
  42. package/engine/internal/unit/scale.d.ts +7 -0
  43. package/engine/internal/unit/scale.lua +20 -0
  44. package/engine/internal/unit+ability.lua +10 -1
  45. package/engine/internal/unit-missile-launch.lua +44 -20
  46. package/engine/internal/unit.d.ts +16 -13
  47. package/engine/internal/unit.lua +102 -81
  48. package/engine/local-client.d.ts +2 -0
  49. package/engine/local-client.lua +30 -0
  50. package/engine/object-data/entry/ability-type.lua +4 -1
  51. package/engine/object-data/entry/unit-type.d.ts +4 -0
  52. package/engine/object-data/entry/unit-type.lua +76 -32
  53. package/engine/object-field/ability.d.ts +3 -3
  54. package/engine/object-field/ability.lua +7 -6
  55. package/engine/object-field/unit.d.ts +13 -1
  56. package/engine/object-field/unit.lua +57 -0
  57. package/engine/object-field.d.ts +9 -3
  58. package/engine/object-field.lua +204 -115
  59. package/engine/random.d.ts +9 -0
  60. package/engine/random.lua +13 -0
  61. package/engine/standard/fields/ability.d.ts +2 -2
  62. package/engine/standard/fields/ability.lua +2 -2
  63. package/engine/standard/fields/unit.d.ts +3 -1
  64. package/engine/standard/fields/unit.lua +4 -0
  65. package/engine/synchronization.d.ts +11 -0
  66. package/engine/synchronization.lua +77 -0
  67. package/engine/text-tag.d.ts +1 -1
  68. package/engine/text-tag.lua +92 -17
  69. package/engine/unit.d.ts +2 -0
  70. package/engine/unit.lua +2 -0
  71. package/net/socket.lua +1 -1
  72. package/objutil/buff.lua +1 -1
  73. package/package.json +2 -2
  74. package/patch-lualib.lua +1 -1
  75. package/utility/arrays.d.ts +1 -0
  76. package/utility/arrays.lua +8 -0
  77. package/utility/callback-array.d.ts +17 -0
  78. package/utility/callback-array.lua +61 -0
  79. package/utility/functions.d.ts +2 -0
  80. package/utility/functions.lua +7 -0
  81. package/utility/linked-set.d.ts +1 -0
  82. package/utility/linked-set.lua +19 -1
  83. package/utility/lua-maps.d.ts +11 -2
  84. package/utility/lua-maps.lua +33 -2
  85. package/utility/lua-sets.d.ts +1 -0
  86. package/utility/lua-sets.lua +4 -0
  87. package/utility/types.d.ts +3 -0
@@ -12,6 +12,11 @@ local ____objectPool = require("util.objectPool")
12
12
  local ObjectPool = ____objectPool.ObjectPool
13
13
  local ____destroyable = require("destroyable")
14
14
  local AbstractDestroyable = ____destroyable.AbstractDestroyable
15
+ local ____callback_2Darray = require("utility.callback-array")
16
+ local addCallback = ____callback_2Darray.addCallback
17
+ local callbackArray = ____callback_2Darray.callbackArray
18
+ local consumeCallback = ____callback_2Darray.consumeCallback
19
+ local consumeCallbacks = ____callback_2Darray.consumeCallbacks
15
20
  local createTimer = CreateTimer
16
21
  local timerStart = TimerStart
17
22
  local pauseTimer = PauseTimer
@@ -49,6 +54,17 @@ local function timerSafeCall()
49
54
  end
50
55
  end
51
56
  end
57
+ local zeroTimerScheduled = false
58
+ local zeroTimerCallbacks = callbackArray()
59
+ ---
60
+ -- @internal For use by internal systems only.
61
+ ____exports.consumeZeroTimerCallback = function(id)
62
+ consumeCallback(zeroTimerCallbacks, id)
63
+ end
64
+ local function invokeZeroTimerCallbacks()
65
+ zeroTimerScheduled = false
66
+ consumeCallbacks(zeroTimerCallbacks)
67
+ end
52
68
  ____exports.Timer = __TS__Class()
53
69
  local Timer = ____exports.Timer
54
70
  Timer.name = "Timer"
@@ -83,10 +99,14 @@ function Timer.create(self)
83
99
  return __TS__New(____exports.Timer)
84
100
  end
85
101
  function Timer.run(self, objectOrCallback, keyOrFirstArg, ...)
102
+ if not zeroTimerScheduled then
103
+ zeroTimerScheduled = true
104
+ ____exports.Timer:simple(0, invokeZeroTimerCallbacks)
105
+ end
86
106
  if ____type(objectOrCallback) == "function" then
87
- ____exports.Timer:simple(0, objectOrCallback, keyOrFirstArg, ...)
107
+ return addCallback(zeroTimerCallbacks, objectOrCallback, keyOrFirstArg, ...)
88
108
  else
89
- ____exports.Timer:simple(0, objectOrCallback[keyOrFirstArg], objectOrCallback, ...)
109
+ return addCallback(zeroTimerCallbacks, objectOrCallback[keyOrFirstArg], objectOrCallback, ...)
90
110
  end
91
111
  end
92
112
  function Timer.simple(self, timeout, callback, ...)
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,11 @@
1
1
  /** @noSelfInFile */
2
2
  import { AbstractDestroyable, Destructor } from "../destroyable";
3
+ import { Event } from "../event";
4
+ export declare const enum BehaviorPriority {
5
+ HIGH = 0,
6
+ MEDIUM = 1,
7
+ LOW = 2
8
+ }
3
9
  export type BehaviorConstructor<T extends Behavior<AnyNotNil>, Parameters extends any[] = any[]> = OmitConstructor<typeof Behavior<any>> & (abstract new (...parameters: Parameters) => T);
4
10
  declare const enum BehaviorPropertyKey {
5
11
  PREVIOUS_BEHAVIOR = 0,
@@ -8,11 +14,14 @@ declare const enum BehaviorPropertyKey {
8
14
  }
9
15
  export declare abstract class Behavior<T extends AnyNotNil, PeriodicActionParameters extends any[] = any[]> extends AbstractDestroyable {
10
16
  protected readonly object: T;
17
+ readonly priority: BehaviorPriority;
11
18
  private [BehaviorPropertyKey.PREVIOUS_BEHAVIOR]?;
12
19
  private [BehaviorPropertyKey.NEXT_BEHAVIOR]?;
13
20
  private [BehaviorPropertyKey.TIMER]?;
14
- protected constructor(object: T);
21
+ protected constructor(object: T, priority?: BehaviorPriority);
15
22
  protected onDestroy(): Destructor;
23
+ 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;
24
+ protected deregisterEvent(event: Event<any>): boolean;
16
25
  protected onPeriod(...parameters: PeriodicActionParameters): void;
17
26
  protected startPeriodicAction(interval: number, ...parameters: PeriodicActionParameters): void;
18
27
  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,54 +10,71 @@ 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
- local firstBehaviorByObject = {}
14
- local lastBehaviorByObject = {}
21
+ local firstBehaviorByObjectByPriority = {[0] = {}, [2] = {}, [1] = {}}
22
+ local lastBehaviorByObjectByPriority = {[0] = {}, [2] = {}, [1] = {}}
15
23
  local function invokeBehaviorOnPeriod(behavior, ...)
16
24
  behavior.onPeriod(behavior, ...)
17
25
  end
18
26
  local function reduceBehaviors(behaviorConstructor, object, operation, initial, consumerOrKey, ...)
19
27
  local accumulator = initial
20
- local behavior = firstBehaviorByObject[object]
21
- if behavior ~= nil then
22
- if type(consumerOrKey) == "function" then
23
- repeat
24
- do
25
- if __TS__InstanceOf(behavior, behaviorConstructor) then
26
- local isSuccessful, result = safeCall(consumerOrKey, behavior, ...)
27
- if isSuccessful then
28
- 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
29
39
  end
40
+ behavior = behavior[1]
30
41
  end
31
- behavior = behavior[1]
32
- end
33
- until not (behavior ~= nil)
34
- else
35
- repeat
36
- do
37
- if __TS__InstanceOf(behavior, behaviorConstructor) then
38
- local isSuccessful, result = safeCall(behavior[consumerOrKey], behavior, ...)
39
- if isSuccessful then
40
- 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
41
51
  end
52
+ behavior = behavior[1]
42
53
  end
43
- behavior = behavior[1]
44
- end
45
- until not (behavior ~= nil)
54
+ until not (behavior ~= nil)
55
+ end
46
56
  end
47
57
  end
48
58
  return accumulator
49
59
  end
60
+ local behaviorsByEvent = {}
61
+ local listenerByBehaviorByEvent = {}
62
+ local eventsByBehavior = {}
50
63
  ____exports.Behavior = __TS__Class()
51
64
  local Behavior = ____exports.Behavior
52
65
  Behavior.name = "Behavior"
53
66
  __TS__ClassExtends(Behavior, AbstractDestroyable)
54
- function Behavior.prototype.____constructor(self, object)
67
+ function Behavior.prototype.____constructor(self, object, priority)
68
+ if priority == nil then
69
+ priority = 1
70
+ end
55
71
  AbstractDestroyable.prototype.____constructor(self)
56
72
  self.object = object
73
+ self.priority = priority
74
+ local lastBehaviorByObject = lastBehaviorByObjectByPriority[priority]
57
75
  local lastBehavior = lastBehaviorByObject[object]
58
76
  if lastBehavior == nil then
59
- firstBehaviorByObject[object] = self
77
+ firstBehaviorByObjectByPriority[priority][object] = self
60
78
  lastBehaviorByObject[object] = self
61
79
  else
62
80
  self[0] = lastBehavior
@@ -69,20 +87,62 @@ function Behavior.prototype.onDestroy(self)
69
87
  if ____opt_0 ~= nil then
70
88
  ____opt_0:destroy()
71
89
  end
90
+ local events = eventsByBehavior[self]
91
+ if events ~= nil then
92
+ for event in pairs(events) do
93
+ local ____opt_2 = behaviorsByEvent[event]
94
+ if ____opt_2 ~= nil then
95
+ ____opt_2:remove(self)
96
+ end
97
+ local ____opt_4 = listenerByBehaviorByEvent[event]
98
+ if ____opt_4 ~= nil then
99
+ ____opt_4[self] = nil
100
+ end
101
+ end
102
+ eventsByBehavior[self] = nil
103
+ end
72
104
  local previousBehavior = self[0]
73
105
  local nextBehavior = self[1]
74
106
  if previousBehavior ~= nil then
75
107
  previousBehavior[1] = nextBehavior
76
108
  else
77
- firstBehaviorByObject[self.object] = nextBehavior
109
+ firstBehaviorByObjectByPriority[self.priority][self.object] = nextBehavior
78
110
  end
79
111
  if nextBehavior ~= nil then
80
112
  nextBehavior[0] = previousBehavior
81
113
  else
82
- lastBehaviorByObject[self.object] = previousBehavior
114
+ lastBehaviorByObjectByPriority[self.priority][self.object] = previousBehavior
83
115
  end
84
116
  return AbstractDestroyable.prototype.onDestroy(self)
85
117
  end
118
+ function Behavior.prototype.registerEvent(self, event, listener)
119
+ local listenerByBehavior = getOrPut(listenerByBehaviorByEvent, event, mutableLuaMap)
120
+ listenerByBehavior[self] = listener
121
+ getOrPut(eventsByBehavior, self, mutableLuaSet)[event] = true
122
+ local behaviors = behaviorsByEvent[event]
123
+ if behaviors == nil then
124
+ event:addListener(function(...)
125
+ local behaviors = behaviorsByEvent[event]
126
+ if behaviors ~= nil then
127
+ for behavior in pairs(behaviors) do
128
+ safeCall(behavior[listenerByBehavior[behavior]], behavior, ...)
129
+ end
130
+ end
131
+ end)
132
+ behaviors = __TS__New(LinkedSet)
133
+ behaviorsByEvent[event] = behaviors
134
+ end
135
+ behaviors:add(self)
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
86
146
  function Behavior.prototype.onPeriod(self, ...)
87
147
  end
88
148
  function Behavior.prototype.startPeriodicAction(self, interval, ...)
@@ -108,78 +168,94 @@ function Behavior.prototype.stopPeriodicAction(self)
108
168
  end
109
169
  function Behavior.count(self, object, limit)
110
170
  local behaviorsCount = 0
111
- local behavior = firstBehaviorByObject[object]
112
- while behavior ~= nil and (limit == nil or behaviorsCount < limit) do
113
- if __TS__InstanceOf(behavior, self) then
114
- 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]
115
178
  end
116
- behavior = behavior[1]
117
179
  end
118
180
  return behaviorsCount
119
181
  end
120
182
  function Behavior.getFirst(self, object, countOrPredicate, ...)
121
- local behavior = firstBehaviorByObject[object]
122
183
  if type(countOrPredicate) ~= "number" then
123
- while behavior ~= nil do
124
- if __TS__InstanceOf(behavior, self) and (countOrPredicate == nil or countOrPredicate(behavior, ...)) then
125
- 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]
126
191
  end
127
- behavior = behavior[1]
128
192
  end
129
193
  return nil
130
194
  end
131
195
  local behaviors = {}
132
196
  local behaviorsCount = 0
133
- while behavior ~= nil and behaviorsCount < countOrPredicate do
134
- if __TS__InstanceOf(behavior, self) then
135
- behaviorsCount = behaviorsCount + 1
136
- 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]
137
205
  end
138
- behavior = behavior[1]
139
206
  end
140
207
  return behaviors
141
208
  end
142
209
  function Behavior.getLast(self, object)
143
- local behavior = lastBehaviorByObject[object]
144
- while behavior ~= nil do
145
- if __TS__InstanceOf(behavior, self) then
146
- 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]
147
217
  end
148
- behavior = behavior[0]
149
218
  end
150
219
  return nil
151
220
  end
152
221
  function Behavior.getAll(self, object, predicate, ...)
153
222
  local behaviors = {}
154
223
  local behaviorsCount = 0
155
- local behavior = firstBehaviorByObject[object]
156
- while behavior ~= nil do
157
- if __TS__InstanceOf(behavior, self) and (predicate == nil or predicate(behavior, ...)) then
158
- behaviorsCount = behaviorsCount + 1
159
- 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]
160
232
  end
161
- behavior = behavior[1]
162
233
  end
163
234
  return behaviors
164
235
  end
165
236
  function Behavior.forFirst(self, object, count, consumerOrKey, ...)
166
237
  local behaviorsCount = 0
167
- local behavior = firstBehaviorByObject[object]
168
238
  if type(consumerOrKey) == "function" then
169
- while behavior ~= nil and behaviorsCount < count do
170
- if __TS__InstanceOf(behavior, self) then
171
- safeCall(consumerOrKey, behavior, ...)
172
- 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]
173
247
  end
174
- behavior = behavior[1]
175
248
  end
176
249
  else
177
- while behavior ~= nil and behaviorsCount < count do
178
- if __TS__InstanceOf(behavior, self) then
179
- safeCall(behavior[consumerOrKey], behavior, ...)
180
- 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]
181
258
  end
182
- behavior = behavior[1]
183
259
  end
184
260
  end
185
261
  return behaviorsCount
@@ -22,7 +22,7 @@ function ApplyBuffAbilityBehavior.prototype.____constructor(self, ability, const
22
22
  AbilityBehavior.prototype.____constructor(self, ability)
23
23
  if type(constructorOrTypeIdOrTypeIds) == "number" then
24
24
  self.applyBuff = function(unit)
25
- return Buff:apply(
25
+ local buff = Buff:apply(
26
26
  unit,
27
27
  constructorOrTypeIdOrTypeIds,
28
28
  typeIdOrTypeIdsOrPolarityOrTypeIdSelectionPolicy,
@@ -30,10 +30,12 @@ function ApplyBuffAbilityBehavior.prototype.____constructor(self, ability, const
30
30
  ability,
31
31
  resistanceTypeOrPolarityOrParameters
32
32
  )
33
+ buff.sourceAbilityBehavior = self
34
+ return buff
33
35
  end
34
36
  elseif __TS__ArrayIsArray(constructorOrTypeIdOrTypeIds) then
35
37
  self.applyBuff = function(unit)
36
- return Buff:apply(
38
+ local buff = Buff:apply(
37
39
  unit,
38
40
  constructorOrTypeIdOrTypeIds,
39
41
  typeIdOrTypeIdsOrPolarityOrTypeIdSelectionPolicy,
@@ -42,10 +44,12 @@ function ApplyBuffAbilityBehavior.prototype.____constructor(self, ability, const
42
44
  ability,
43
45
  parametersOrResistanceType
44
46
  )
47
+ buff.sourceAbilityBehavior = self
48
+ return buff
45
49
  end
46
50
  elseif type(typeIdOrTypeIdsOrPolarityOrTypeIdSelectionPolicy) == "number" then
47
51
  self.applyBuff = function(unit)
48
- return constructorOrTypeIdOrTypeIds:apply(
52
+ local buff = constructorOrTypeIdOrTypeIds:apply(
49
53
  unit,
50
54
  typeIdOrTypeIdsOrPolarityOrTypeIdSelectionPolicy,
51
55
  polarityOrTypeIdSelectionPolicyOrResistanceType,
@@ -53,10 +57,12 @@ function ApplyBuffAbilityBehavior.prototype.____constructor(self, ability, const
53
57
  ability,
54
58
  parametersOrResistanceType
55
59
  )
60
+ buff.sourceAbilityBehavior = self
61
+ return buff
56
62
  end
57
63
  else
58
64
  self.applyBuff = function(unit)
59
- return constructorOrTypeIdOrTypeIds:apply(
65
+ local buff = constructorOrTypeIdOrTypeIds:apply(
60
66
  unit,
61
67
  typeIdOrTypeIdsOrPolarityOrTypeIdSelectionPolicy,
62
68
  polarityOrTypeIdSelectionPolicyOrResistanceType,
@@ -65,6 +71,8 @@ function ApplyBuffAbilityBehavior.prototype.____constructor(self, ability, const
65
71
  ability,
66
72
  parameters
67
73
  )
74
+ buff.sourceAbilityBehavior = self
75
+ return buff
68
76
  end
69
77
  end
70
78
  end
@@ -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
@@ -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,23 +1,30 @@
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
+ import { UnitBonusType } from "../internal/unit/bonus";
15
+ import { Player } from "../../core/types/player";
16
+ import { UnitTypeId } from "../object-data/entry/unit-type";
14
17
  export type UnitBehaviorConstructor<Args extends any[]> = new (unit: Unit, ...args: Args) => UnitBehavior;
15
18
  export declare abstract class UnitBehavior<PeriodicActionParameters extends any[] = any[]> extends Behavior<Unit, PeriodicActionParameters> {
16
- constructor(unit: Unit);
17
- protected onDestroy(): Destructor;
18
19
  readonly sourceAbilityBehavior?: AbilityBehavior;
20
+ private _bonusIdByBonusType?;
21
+ constructor(unit: Unit, priority?: BehaviorPriority);
22
+ protected onDestroy(): Destructor;
19
23
  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;
24
+ protected getUnitBonus(bonusType: UnitBonusType): number;
25
+ protected addOrUpdateOrRemoveUnitBonus(bonusType: UnitBonusType, value: number): void;
26
+ protected registerOwningPlayerEvent<T extends string, Args extends any[]>(this: UnitBehavior<PeriodicActionParameters> & Record<T, (this: this, ...args: Args) => unknown>, event: Event<[...Args]>, extractPlayer: (...args: Args) => Player | undefined, listener: T): void;
27
+ 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
28
  onImmediateOrder(orderId: number): void;
22
29
  onTargetOrder(orderId: number, target: Widget): void;
23
30
  onPointOrder(orderId: number, x: number, y: number): void;
@@ -44,6 +51,7 @@ export declare abstract class UnitBehavior<PeriodicActionParameters extends any[
44
51
  onTargetingAbilityChannelingStart(ability: Ability, source: Unit): void;
45
52
  onTargetingAbilityImpact(ability: Ability, source: Unit): void;
46
53
  onBuffGained(buff: Buff): void;
54
+ onBuffLost(buff: Buff): void;
47
55
  onItemDropped(item: Item): void;
48
56
  onItemPickedUp(item: Item): void;
49
57
  onItemUsed(item: Item): void;
@@ -51,4 +59,6 @@ export declare abstract class UnitBehavior<PeriodicActionParameters extends any[
51
59
  onItemChargesChanged(item: Item): void;
52
60
  onKill(target: Unit): void;
53
61
  onDeath(source: Unit | undefined): void;
62
+ onOwnerChange(previousOwner: Player): void;
63
+ static bindUnitType<Args extends any[]>(this: UnitBehaviorConstructor<Args>, unitTypeId: UnitTypeId, ...args: Args): void;
54
64
  }