warscript 0.0.1-dev.e5e97e8 → 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.
@@ -81,6 +81,7 @@ export declare class Player extends Handle<jplayer> {
81
81
  };
82
82
  };
83
83
  static get onChat(): Event<[player: Player, message: string]>;
84
+ static readonly colorChangedEvent: Event<[Player]>;
84
85
  static byId(id: number): Player | undefined;
85
86
  }
86
87
  export {};
@@ -1,7 +1,7 @@
1
1
  local ____lualib = require("lualib_bundle")
2
+ local __TS__New = ____lualib.__TS__New
2
3
  local __TS__Class = ____lualib.__TS__Class
3
4
  local __TS__ClassExtends = ____lualib.__TS__ClassExtends
4
- local __TS__New = ____lualib.__TS__New
5
5
  local __TS__SetDescriptor = ____lualib.__TS__SetDescriptor
6
6
  local __TS__ObjectDefineProperty = ____lualib.__TS__ObjectDefineProperty
7
7
  local ____exports = {}
@@ -49,6 +49,7 @@ local nativeByPlayerAllianceType = {
49
49
  [8] = ALLIANCE_SHARED_CONTROL,
50
50
  [9] = ALLIANCE_SHARED_ADVANCED_CONTROL
51
51
  }
52
+ local playerColorChangedEvent = __TS__New(Event)
52
53
  ____exports.Player = __TS__Class()
53
54
  local Player = ____exports.Player
54
55
  Player.name = "Player"
@@ -300,6 +301,7 @@ __TS__SetDescriptor(
300
301
  end,
301
302
  set = function(self, color)
302
303
  SetPlayerColor(self.handle, color.handle)
304
+ Event.invoke(playerColorChangedEvent, self)
303
305
  end
304
306
  },
305
307
  true
@@ -487,4 +489,5 @@ __TS__ObjectDefineProperty(
487
489
  return event
488
490
  end}
489
491
  )
492
+ Player.colorChangedEvent = playerColorChangedEvent
490
493
  return ____exports
@@ -1,5 +1,6 @@
1
1
  /** @noSelfInFile */
2
- export declare class TileCell implements Readonly<Vec2> {
2
+ import { AttributesHolder } from "../../attributes";
3
+ export declare class TileCell extends AttributesHolder implements Readonly<Vec2> {
3
4
  private readonly id;
4
5
  readonly x: number;
5
6
  readonly y: number;
@@ -1,8 +1,11 @@
1
1
  local ____lualib = require("lualib_bundle")
2
2
  local __TS__Class = ____lualib.__TS__Class
3
+ local __TS__ClassExtends = ____lualib.__TS__ClassExtends
3
4
  local __TS__New = ____lualib.__TS__New
4
5
  local __TS__SetDescriptor = ____lualib.__TS__SetDescriptor
5
6
  local ____exports = {}
7
+ local ____attributes = require("attributes")
8
+ local AttributesHolder = ____attributes.AttributesHolder
6
9
  local getTerrainType = GetTerrainType
7
10
  local setTerrainType = SetTerrainType
8
11
  local getTerrainVariance = GetTerrainVariance
@@ -13,7 +16,9 @@ local tileCellById = {}
13
16
  ____exports.TileCell = __TS__Class()
14
17
  local TileCell = ____exports.TileCell
15
18
  TileCell.name = "TileCell"
19
+ __TS__ClassExtends(TileCell, AttributesHolder)
16
20
  function TileCell.prototype.____constructor(self, id, x, y, z)
21
+ AttributesHolder.prototype.____constructor(self)
17
22
  self.id = id
18
23
  self.x = x
19
24
  self.y = y
@@ -1,6 +1,11 @@
1
1
  /** @noSelfInFile */
2
2
  import { AbstractDestroyable, Destructor } from "../destroyable";
3
3
  import { Event } from "../event";
4
+ export declare const enum BehaviorPriority {
5
+ HIGH = 0,
6
+ MEDIUM = 1,
7
+ LOW = 2
8
+ }
4
9
  export type BehaviorConstructor<T extends Behavior<AnyNotNil>, Parameters extends any[] = any[]> = OmitConstructor<typeof Behavior<any>> & (abstract new (...parameters: Parameters) => T);
5
10
  declare const enum BehaviorPropertyKey {
6
11
  PREVIOUS_BEHAVIOR = 0,
@@ -9,10 +14,11 @@ declare const enum BehaviorPropertyKey {
9
14
  }
10
15
  export declare abstract class Behavior<T extends AnyNotNil, PeriodicActionParameters extends any[] = any[]> extends AbstractDestroyable {
11
16
  protected readonly object: T;
17
+ readonly priority: BehaviorPriority;
12
18
  private [BehaviorPropertyKey.PREVIOUS_BEHAVIOR]?;
13
19
  private [BehaviorPropertyKey.NEXT_BEHAVIOR]?;
14
20
  private [BehaviorPropertyKey.TIMER]?;
15
- protected constructor(object: T);
21
+ protected constructor(object: T, priority?: BehaviorPriority);
16
22
  protected onDestroy(): Destructor;
17
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;
18
24
  protected deregisterEvent(event: Event<any>): boolean;
@@ -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
@@ -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
@@ -4,16 +4,18 @@ 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;
11
13
  additionalAction?: (this: void, unit: Unit) => void;
12
14
  };
13
15
  export declare class StunImmunityUnitBehavior extends UnitBehavior {
14
- readonly parameters: Readonly<StunImmunityUnitBehaviourParameters>;
15
- static defaultParameters: StunImmunityUnitBehaviourParameters;
16
- constructor(unit: Unit, parameters?: Readonly<StunImmunityUnitBehaviourParameters>);
16
+ readonly parameters: Readonly<StunImmunityUnitBehaviorParameters>;
17
+ static defaultParameters: StunImmunityUnitBehaviorParameters;
18
+ constructor(unit: Unit, parameters?: Readonly<StunImmunityUnitBehaviorParameters>);
17
19
  protected onDestroy(): Destructor;
18
20
  onDamageReceived(): void;
19
21
  onTargetingAbilityChannelingStart(): void;
@@ -67,7 +67,7 @@ function StunImmunityUnitBehavior.prototype.____constructor(self, unit, paramete
67
67
  if parameters == nil then
68
68
  parameters = ____exports.StunImmunityUnitBehavior.defaultParameters
69
69
  end
70
- UnitBehavior.prototype.____constructor(self, unit)
70
+ UnitBehavior.prototype.____constructor(self, unit, parameters.priority)
71
71
  self.parameters = parameters
72
72
  unit:decrementStunCounter()
73
73
  process(self)
@@ -1,11 +1,11 @@
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";
@@ -13,15 +13,17 @@ import { Destructable } from "../../core/types/destructable";
13
13
  import type { Buff } from "../buff";
14
14
  import { UnitBonusType } from "../internal/unit/bonus";
15
15
  import { Player } from "../../core/types/player";
16
+ import { UnitTypeId } from "../object-data/entry/unit-type";
16
17
  export type UnitBehaviorConstructor<Args extends any[]> = new (unit: Unit, ...args: Args) => UnitBehavior;
17
18
  export declare abstract class UnitBehavior<PeriodicActionParameters extends any[] = any[]> extends Behavior<Unit, PeriodicActionParameters> {
18
19
  readonly sourceAbilityBehavior?: AbilityBehavior;
19
20
  private _bonusIdByBonusType?;
20
- constructor(unit: Unit);
21
+ constructor(unit: Unit, priority?: BehaviorPriority);
21
22
  protected onDestroy(): Destructor;
22
23
  get unit(): Unit;
23
24
  protected getUnitBonus(bonusType: UnitBonusType): number;
24
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;
25
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;
26
28
  onImmediateOrder(orderId: number): void;
27
29
  onTargetOrder(orderId: number, target: Widget): void;
@@ -49,6 +51,7 @@ export declare abstract class UnitBehavior<PeriodicActionParameters extends any[
49
51
  onTargetingAbilityChannelingStart(ability: Ability, source: Unit): void;
50
52
  onTargetingAbilityImpact(ability: Ability, source: Unit): void;
51
53
  onBuffGained(buff: Buff): void;
54
+ onBuffLost(buff: Buff): void;
52
55
  onItemDropped(item: Item): void;
53
56
  onItemPickedUp(item: Item): void;
54
57
  onItemUsed(item: Item): void;
@@ -57,4 +60,5 @@ export declare abstract class UnitBehavior<PeriodicActionParameters extends any[
57
60
  onKill(target: Unit): void;
58
61
  onDeath(source: Unit | undefined): void;
59
62
  onOwnerChange(previousOwner: Player): void;
63
+ static bindUnitType<Args extends any[]>(this: UnitBehaviorConstructor<Args>, unitTypeId: UnitTypeId, ...args: Args): void;
60
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)
@@ -167,6 +211,21 @@ function UnitBehavior.prototype.onDeath(self, source)
167
211
  end
168
212
  function UnitBehavior.prototype.onOwnerChange(self, previousOwner)
169
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
170
229
  __TS__SetDescriptor(
171
230
  UnitBehavior.prototype,
172
231
  "unit",
@@ -282,6 +341,14 @@ __TS__SetDescriptor(
282
341
  ____exports.UnitBehavior:forAll(unit, "onOwnerChange", previousOwner)
283
342
  end)
284
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)
285
352
  Unit.destroyEvent:addListener(function(unit)
286
353
  ____exports.UnitBehavior:forAll(unit, "destroy")
287
354
  end)