warscript 0.0.1-dev.b9f7033 → 0.0.1-dev.baa67d8

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 (66) hide show
  1. package/attributes.d.ts +1 -0
  2. package/attributes.lua +9 -0
  3. package/binarywriter.lua +0 -12
  4. package/core/types/player.d.ts +16 -0
  5. package/core/types/player.lua +57 -14
  6. package/core/types/tileCell.d.ts +2 -1
  7. package/core/types/tileCell.lua +5 -0
  8. package/core/types/timer.d.ts +3 -2
  9. package/core/types/timer.lua +8 -2
  10. package/destroyable.d.ts +1 -0
  11. package/destroyable.lua +9 -0
  12. package/engine/behavior.d.ts +7 -1
  13. package/engine/behavior.lua +88 -65
  14. package/engine/behaviour/ability/apply-buff.lua +4 -4
  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.d.ts +2 -1
  18. package/engine/behaviour/ability.lua +2 -1
  19. package/engine/behaviour/unit/stun-immunity.d.ts +8 -4
  20. package/engine/behaviour/unit/stun-immunity.lua +12 -3
  21. package/engine/behaviour/unit.d.ts +9 -3
  22. package/engine/behaviour/unit.lua +94 -22
  23. package/engine/buff.d.ts +12 -2
  24. package/engine/buff.lua +80 -17
  25. package/engine/internal/item.d.ts +12 -12
  26. package/engine/internal/item.lua +41 -26
  27. package/engine/internal/unit/ability.d.ts +14 -14
  28. package/engine/internal/unit/ability.lua +72 -45
  29. package/engine/internal/unit/fly-height.d.ts +7 -0
  30. package/engine/internal/unit/fly-height.lua +20 -0
  31. package/engine/internal/unit/main-selected.lua +12 -27
  32. package/engine/internal/unit/scale.d.ts +7 -0
  33. package/engine/internal/unit/scale.lua +20 -0
  34. package/engine/internal/unit-missile-launch.lua +44 -20
  35. package/engine/internal/unit.d.ts +13 -10
  36. package/engine/internal/unit.lua +83 -64
  37. package/engine/local-client.d.ts +2 -0
  38. package/engine/local-client.lua +30 -0
  39. package/engine/object-data/entry/ability-type.lua +4 -1
  40. package/engine/object-data/entry/destructible-type.d.ts +17 -1
  41. package/engine/object-data/entry/destructible-type.lua +90 -0
  42. package/engine/object-data/entry/unit-type.d.ts +4 -0
  43. package/engine/object-data/entry/unit-type.lua +76 -32
  44. package/engine/object-field/unit.d.ts +13 -1
  45. package/engine/object-field/unit.lua +57 -0
  46. package/engine/object-field.d.ts +7 -1
  47. package/engine/object-field.lua +232 -111
  48. package/engine/standard/fields/ability.d.ts +2 -2
  49. package/engine/standard/fields/ability.lua +2 -2
  50. package/engine/standard/fields/unit.d.ts +3 -1
  51. package/engine/standard/fields/unit.lua +4 -0
  52. package/engine/synchronization.d.ts +11 -0
  53. package/engine/synchronization.lua +77 -0
  54. package/engine/text-tag.lua +3 -2
  55. package/engine/unit.d.ts +2 -0
  56. package/engine/unit.lua +2 -0
  57. package/net/socket.lua +1 -1
  58. package/objutil/buff.lua +1 -1
  59. package/package.json +2 -2
  60. package/utility/arrays.d.ts +1 -0
  61. package/utility/arrays.lua +8 -0
  62. package/utility/callback-array.d.ts +5 -1
  63. package/utility/callback-array.lua +16 -1
  64. package/utility/linked-set.d.ts +1 -0
  65. package/utility/linked-set.lua +19 -1
  66. 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
@@ -161,78 +168,94 @@ function Behavior.prototype.stopPeriodicAction(self)
161
168
  end
162
169
  function Behavior.count(self, object, limit)
163
170
  local behaviorsCount = 0
164
- local behavior = firstBehaviorByObject[object]
165
- while behavior ~= nil and (limit == nil or behaviorsCount < limit) do
166
- if __TS__InstanceOf(behavior, self) then
167
- 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]
168
178
  end
169
- behavior = behavior[1]
170
179
  end
171
180
  return behaviorsCount
172
181
  end
173
182
  function Behavior.getFirst(self, object, countOrPredicate, ...)
174
- local behavior = firstBehaviorByObject[object]
175
183
  if type(countOrPredicate) ~= "number" then
176
- while behavior ~= nil do
177
- if __TS__InstanceOf(behavior, self) and (countOrPredicate == nil or countOrPredicate(behavior, ...)) then
178
- 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]
179
191
  end
180
- behavior = behavior[1]
181
192
  end
182
193
  return nil
183
194
  end
184
195
  local behaviors = {}
185
196
  local behaviorsCount = 0
186
- while behavior ~= nil and behaviorsCount < countOrPredicate do
187
- if __TS__InstanceOf(behavior, self) then
188
- behaviorsCount = behaviorsCount + 1
189
- 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]
190
205
  end
191
- behavior = behavior[1]
192
206
  end
193
207
  return behaviors
194
208
  end
195
209
  function Behavior.getLast(self, object)
196
- local behavior = lastBehaviorByObject[object]
197
- while behavior ~= nil do
198
- if __TS__InstanceOf(behavior, self) then
199
- 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]
200
217
  end
201
- behavior = behavior[0]
202
218
  end
203
219
  return nil
204
220
  end
205
221
  function Behavior.getAll(self, object, predicate, ...)
206
222
  local behaviors = {}
207
223
  local behaviorsCount = 0
208
- local behavior = firstBehaviorByObject[object]
209
- while behavior ~= nil do
210
- if __TS__InstanceOf(behavior, self) and (predicate == nil or predicate(behavior, ...)) then
211
- behaviorsCount = behaviorsCount + 1
212
- 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]
213
232
  end
214
- behavior = behavior[1]
215
233
  end
216
234
  return behaviors
217
235
  end
218
236
  function Behavior.forFirst(self, object, count, consumerOrKey, ...)
219
237
  local behaviorsCount = 0
220
- local behavior = firstBehaviorByObject[object]
221
238
  if type(consumerOrKey) == "function" then
222
- while behavior ~= nil and behaviorsCount < count do
223
- if __TS__InstanceOf(behavior, self) then
224
- safeCall(consumerOrKey, behavior, ...)
225
- 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]
226
247
  end
227
- behavior = behavior[1]
228
248
  end
229
249
  else
230
- while behavior ~= nil and behaviorsCount < count do
231
- if __TS__InstanceOf(behavior, self) then
232
- safeCall(behavior[consumerOrKey], behavior, ...)
233
- 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]
234
258
  end
235
- behavior = behavior[1]
236
259
  end
237
260
  end
238
261
  return behaviorsCount
@@ -27,7 +27,7 @@ function ApplyBuffAbilityBehavior.prototype.____constructor(self, ability, const
27
27
  constructorOrTypeIdOrTypeIds,
28
28
  typeIdOrTypeIdsOrPolarityOrTypeIdSelectionPolicy,
29
29
  polarityOrTypeIdSelectionPolicyOrResistanceType,
30
- ability,
30
+ self,
31
31
  resistanceTypeOrPolarityOrParameters
32
32
  )
33
33
  end
@@ -39,7 +39,7 @@ function ApplyBuffAbilityBehavior.prototype.____constructor(self, ability, const
39
39
  typeIdOrTypeIdsOrPolarityOrTypeIdSelectionPolicy,
40
40
  polarityOrTypeIdSelectionPolicyOrResistanceType,
41
41
  resistanceTypeOrPolarityOrParameters,
42
- ability,
42
+ self,
43
43
  parametersOrResistanceType
44
44
  )
45
45
  end
@@ -50,7 +50,7 @@ function ApplyBuffAbilityBehavior.prototype.____constructor(self, ability, const
50
50
  typeIdOrTypeIdsOrPolarityOrTypeIdSelectionPolicy,
51
51
  polarityOrTypeIdSelectionPolicyOrResistanceType,
52
52
  resistanceTypeOrPolarityOrParameters,
53
- ability,
53
+ self,
54
54
  parametersOrResistanceType
55
55
  )
56
56
  end
@@ -62,7 +62,7 @@ function ApplyBuffAbilityBehavior.prototype.____constructor(self, ability, const
62
62
  polarityOrTypeIdSelectionPolicyOrResistanceType,
63
63
  resistanceTypeOrPolarityOrParameters,
64
64
  parametersOrResistanceType,
65
- ability,
65
+ self,
66
66
  parameters
67
67
  )
68
68
  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
@@ -1,6 +1,7 @@
1
1
  /** @noSelfInFile */
2
2
  import { Behavior } from "../behavior";
3
- import { Unit } from "../unit";
3
+ import { Unit } from "../internal/unit";
4
+ import "../internal/unit/ability";
4
5
  import { Ability } from "../internal/ability";
5
6
  import { AbilityTypeId } from "../object-data/entry/ability-type";
6
7
  import { Widget } from "../../core/types/widget";
@@ -7,8 +7,9 @@ local __TS__SetDescriptor = ____lualib.__TS__SetDescriptor
7
7
  local ____exports = {}
8
8
  local ____behavior = require("engine.behavior")
9
9
  local Behavior = ____behavior.Behavior
10
- local ____unit = require("engine.unit")
10
+ local ____unit = require("engine.internal.unit")
11
11
  local Unit = ____unit.Unit
12
+ require("engine.internal.unit.ability")
12
13
  local ____ability = require("engine.internal.ability")
13
14
  local Ability = ____ability.Ability
14
15
  local ____effect = require("core.types.effect")
@@ -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,26 +1,29 @@
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;
23
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;
24
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;
25
28
  onImmediateOrder(orderId: number): void;
26
29
  onTargetOrder(orderId: number, target: Widget): void;
@@ -48,6 +51,7 @@ export declare abstract class UnitBehavior<PeriodicActionParameters extends any[
48
51
  onTargetingAbilityChannelingStart(ability: Ability, source: Unit): void;
49
52
  onTargetingAbilityImpact(ability: Ability, source: Unit): void;
50
53
  onBuffGained(buff: Buff): void;
54
+ onBuffLost(buff: Buff): void;
51
55
  onItemDropped(item: Item): void;
52
56
  onItemPickedUp(item: Item): void;
53
57
  onItemUsed(item: Item): void;
@@ -55,4 +59,6 @@ export declare abstract class UnitBehavior<PeriodicActionParameters extends any[
55
59
  onItemChargesChanged(item: Item): void;
56
60
  onKill(target: Unit): void;
57
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;
58
64
  }
@@ -22,35 +22,53 @@ local addOrUpdateOrRemoveUnitBonus = ____bonus.addOrUpdateOrRemoveUnitBonus
22
22
  local getUnitBonus = ____bonus.getUnitBonus
23
23
  local removeUnitBonus = ____bonus.removeUnitBonus
24
24
  local safeCall = warpack.safeCall
25
- local behaviorsByEvent = {}
26
- local rangeByBehaviorByEvent = {}
27
- local listenerByBehaviorByEvent = {}
28
- local eventsByBehavior = {}
25
+ local createBehaviorFunctionsByUnitTypeId = {}
26
+ local behaviorsByOwningPlayerEvent = {}
27
+ local listenerByBehaviorByOwningPlayerEvent = {}
28
+ local owningPlayerEventsByBehavior = {}
29
+ local behaviorsByInRangeUnitEvent = {}
30
+ local rangeByBehaviorByInRangeUnitEvent = {}
31
+ local listenerByBehaviorByInRangeUnitEvent = {}
32
+ local inRangeUnitEventsByBehavior = {}
29
33
  ____exports.UnitBehavior = __TS__Class()
30
34
  local UnitBehavior = ____exports.UnitBehavior
31
35
  UnitBehavior.name = "UnitBehavior"
32
36
  __TS__ClassExtends(UnitBehavior, Behavior)
33
- function UnitBehavior.prototype.____constructor(self, unit)
34
- Behavior.prototype.____constructor(self, unit)
37
+ function UnitBehavior.prototype.____constructor(self, unit, priority)
38
+ Behavior.prototype.____constructor(self, unit, priority)
35
39
  end
36
40
  function UnitBehavior.prototype.onDestroy(self)
37
- local events = eventsByBehavior[self]
38
- if events ~= nil then
39
- for event in pairs(events) do
40
- local ____opt_0 = behaviorsByEvent[event]
41
+ local owningPlayerEvents = owningPlayerEventsByBehavior[self]
42
+ if owningPlayerEvents ~= nil then
43
+ for event in pairs(owningPlayerEvents) do
44
+ local ____opt_0 = behaviorsByOwningPlayerEvent[event]
41
45
  if ____opt_0 ~= nil then
42
46
  ____opt_0:remove(self)
43
47
  end
44
- local ____opt_2 = rangeByBehaviorByEvent[event]
48
+ local ____opt_2 = listenerByBehaviorByOwningPlayerEvent[event]
45
49
  if ____opt_2 ~= nil then
46
50
  ____opt_2[self] = nil
47
51
  end
48
- local ____opt_4 = listenerByBehaviorByEvent[event]
52
+ end
53
+ owningPlayerEventsByBehavior[self] = nil
54
+ end
55
+ local inRangeUnitEvents = inRangeUnitEventsByBehavior[self]
56
+ if inRangeUnitEvents ~= nil then
57
+ for event in pairs(inRangeUnitEvents) do
58
+ local ____opt_4 = behaviorsByInRangeUnitEvent[event]
49
59
  if ____opt_4 ~= nil then
50
- ____opt_4[self] = nil
60
+ ____opt_4:remove(self)
61
+ end
62
+ local ____opt_6 = rangeByBehaviorByInRangeUnitEvent[event]
63
+ if ____opt_6 ~= nil then
64
+ ____opt_6[self] = nil
65
+ end
66
+ local ____opt_8 = listenerByBehaviorByInRangeUnitEvent[event]
67
+ if ____opt_8 ~= nil then
68
+ ____opt_8[self] = nil
51
69
  end
52
70
  end
53
- eventsByBehavior[self] = nil
71
+ inRangeUnitEventsByBehavior[self] = nil
54
72
  end
55
73
  if self._bonusIdByBonusType ~= nil then
56
74
  for bonusType, bonusId in pairs(self._bonusIdByBonusType) do
@@ -60,8 +78,8 @@ function UnitBehavior.prototype.onDestroy(self)
60
78
  return Behavior.prototype.onDestroy(self)
61
79
  end
62
80
  function UnitBehavior.prototype.getUnitBonus(self, bonusType)
63
- local ____opt_6 = self._bonusIdByBonusType
64
- local bonusId = ____opt_6 and ____opt_6[bonusType]
81
+ local ____opt_10 = self._bonusIdByBonusType
82
+ local bonusId = ____opt_10 and ____opt_10[bonusType]
65
83
  return bonusId == nil and 0 or getUnitBonus(self.object, bonusType, bonusId)
66
84
  end
67
85
  function UnitBehavior.prototype.addOrUpdateOrRemoveUnitBonus(self, bonusType, value)
@@ -72,16 +90,40 @@ function UnitBehavior.prototype.addOrUpdateOrRemoveUnitBonus(self, bonusType, va
72
90
  end
73
91
  bonusIdByBonusType[bonusType] = addOrUpdateOrRemoveUnitBonus(self.object, bonusType, bonusIdByBonusType[bonusType], value)
74
92
  end
93
+ function UnitBehavior.prototype.registerOwningPlayerEvent(self, event, extractPlayer, listener)
94
+ local listenerByBehavior = getOrPut(listenerByBehaviorByOwningPlayerEvent, event, mutableLuaMap)
95
+ listenerByBehavior[self] = listener
96
+ getOrPut(inRangeUnitEventsByBehavior, self, mutableLuaSet)[event] = true
97
+ local behaviors = behaviorsByOwningPlayerEvent[event]
98
+ if behaviors == nil then
99
+ event:addListener(function(...)
100
+ local behaviors = behaviorsByOwningPlayerEvent[event]
101
+ if behaviors ~= nil then
102
+ local player = extractPlayer(...)
103
+ if player ~= nil then
104
+ for behavior in pairs(behaviors) do
105
+ if behavior.unit.owner == player then
106
+ safeCall(behavior[listenerByBehavior[behavior]], behavior, ...)
107
+ end
108
+ end
109
+ end
110
+ end
111
+ end)
112
+ behaviors = __TS__New(LinkedSet)
113
+ behaviorsByOwningPlayerEvent[event] = behaviors
114
+ end
115
+ behaviors:add(self)
116
+ end
75
117
  function UnitBehavior.prototype.registerInRangeUnitEvent(self, event, extractUnit, range, listener)
76
- local rangeByBehavior = getOrPut(rangeByBehaviorByEvent, event, mutableLuaMap)
118
+ local rangeByBehavior = getOrPut(rangeByBehaviorByInRangeUnitEvent, event, mutableLuaMap)
77
119
  rangeByBehavior[self] = range
78
- local listenerByBehavior = getOrPut(listenerByBehaviorByEvent, event, mutableLuaMap)
120
+ local listenerByBehavior = getOrPut(listenerByBehaviorByInRangeUnitEvent, event, mutableLuaMap)
79
121
  listenerByBehavior[self] = listener
80
- getOrPut(eventsByBehavior, self, mutableLuaSet)[event] = true
81
- local behaviors = behaviorsByEvent[event]
122
+ getOrPut(inRangeUnitEventsByBehavior, self, mutableLuaSet)[event] = true
123
+ local behaviors = behaviorsByInRangeUnitEvent[event]
82
124
  if behaviors == nil then
83
125
  event:addListener(function(...)
84
- local behaviors = behaviorsByEvent[event]
126
+ local behaviors = behaviorsByInRangeUnitEvent[event]
85
127
  if behaviors ~= nil then
86
128
  local unit = extractUnit(...)
87
129
  if unit ~= nil then
@@ -95,7 +137,7 @@ function UnitBehavior.prototype.registerInRangeUnitEvent(self, event, extractUni
95
137
  end
96
138
  end)
97
139
  behaviors = __TS__New(LinkedSet)
98
- behaviorsByEvent[event] = behaviors
140
+ behaviorsByInRangeUnitEvent[event] = behaviors
99
141
  end
100
142
  behaviors:add(self)
101
143
  end
@@ -151,6 +193,8 @@ function UnitBehavior.prototype.onTargetingAbilityImpact(self, ability, source)
151
193
  end
152
194
  function UnitBehavior.prototype.onBuffGained(self, buff)
153
195
  end
196
+ function UnitBehavior.prototype.onBuffLost(self, buff)
197
+ end
154
198
  function UnitBehavior.prototype.onItemDropped(self, item)
155
199
  end
156
200
  function UnitBehavior.prototype.onItemPickedUp(self, item)
@@ -165,6 +209,23 @@ function UnitBehavior.prototype.onKill(self, target)
165
209
  end
166
210
  function UnitBehavior.prototype.onDeath(self, source)
167
211
  end
212
+ function UnitBehavior.prototype.onOwnerChange(self, previousOwner)
213
+ end
214
+ function UnitBehavior.bindUnitType(self, unitTypeId, ...)
215
+ local args = {...}
216
+ local createBehaviorFunctions = createBehaviorFunctionsByUnitTypeId[unitTypeId]
217
+ if createBehaviorFunctions == nil then
218
+ createBehaviorFunctions = {}
219
+ createBehaviorFunctionsByUnitTypeId[unitTypeId] = createBehaviorFunctions
220
+ end
221
+ createBehaviorFunctions[#createBehaviorFunctions + 1] = function(unit)
222
+ return __TS__New(
223
+ self,
224
+ unit,
225
+ table.unpack(args)
226
+ )
227
+ end
228
+ end
168
229
  __TS__SetDescriptor(
169
230
  UnitBehavior.prototype,
170
231
  "unit",
@@ -276,7 +337,18 @@ __TS__SetDescriptor(
276
337
  Unit.itemChargesChangedEvent:addListener(function(unit, item)
277
338
  ____exports.UnitBehavior:forAll(unit, "onItemChargesChanged", item)
278
339
  end)
340
+ Unit.onOwnerChange:addListener(function(unit, previousOwner)
341
+ ____exports.UnitBehavior:forAll(unit, "onOwnerChange", previousOwner)
342
+ end)
279
343
  end)(UnitBehavior)
344
+ Unit.onCreate:addListener(function(unit)
345
+ local createBehaviorFunctions = createBehaviorFunctionsByUnitTypeId[unit.typeId]
346
+ if createBehaviorFunctions ~= nil then
347
+ for ____, createBehavior in ipairs(createBehaviorFunctions) do
348
+ createBehavior(unit)
349
+ end
350
+ end
351
+ end)
280
352
  Unit.destroyEvent:addListener(function(unit)
281
353
  ____exports.UnitBehavior:forAll(unit, "destroy")
282
354
  end)