warscript 0.0.1-dev.5ca835c → 0.0.1-dev.5e33506

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
package/destroyable.d.ts CHANGED
@@ -10,6 +10,7 @@ export interface Destroyable {
10
10
  destroy(): void;
11
11
  }
12
12
  export declare abstract class AbstractDestroyable implements Destroyable {
13
+ get isDestroyed(): boolean;
13
14
  /**
14
15
  * An overriding function should always call the super one at the end of it,
15
16
  * in the following manner: `return super.onDestroy()`.
package/destroyable.lua CHANGED
@@ -1,6 +1,7 @@
1
1
  local ____lualib = require("lualib_bundle")
2
2
  local __TS__Class = ____lualib.__TS__Class
3
3
  local __TS__New = ____lualib.__TS__New
4
+ local __TS__SetDescriptor = ____lualib.__TS__SetDescriptor
4
5
  local ____exports = {}
5
6
  local ____exception = require("exception")
6
7
  local IllegalStateException = ____exception.IllegalStateException
@@ -28,4 +29,12 @@ function AbstractDestroyable.prototype.destroy(self)
28
29
  end
29
30
  return true
30
31
  end
32
+ __TS__SetDescriptor(
33
+ AbstractDestroyable.prototype,
34
+ "isDestroyed",
35
+ {get = function(self)
36
+ return stateByDestroyable[self] ~= nil
37
+ end},
38
+ true
39
+ )
31
40
  return ____exports
@@ -18,9 +18,11 @@ export declare abstract class Behavior<T extends AnyNotNil, PeriodicActionParame
18
18
  private [BehaviorPropertyKey.PREVIOUS_BEHAVIOR]?;
19
19
  private [BehaviorPropertyKey.NEXT_BEHAVIOR]?;
20
20
  private [BehaviorPropertyKey.TIMER]?;
21
- protected constructor(object: T, priority?: BehaviorPriority);
21
+ constructor(object: T, priority?: BehaviorPriority);
22
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;
23
+ protected registerGlobalEvent<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 deregisterGlobalEvent(event: Event<any>): boolean;
25
+ protected registerEvent<K extends string, Args extends any[]>(this: Behavior<any, PeriodicActionParameters> & Record<K, (this: this, ...args: Args) => unknown>, event: Event<[...Args]>, extractObject: (...args: Args) => T | undefined, listener: K): void;
24
26
  protected deregisterEvent(event: Event<any>): boolean;
25
27
  protected onPeriod(...parameters: PeriodicActionParameters): void;
26
28
  protected startPeriodicAction(interval: number, ...parameters: PeriodicActionParameters): void;
@@ -57,9 +57,17 @@ local function reduceBehaviors(behaviorConstructor, object, operation, initial,
57
57
  end
58
58
  return accumulator
59
59
  end
60
+ local behaviorsByGlobalEvent = {}
61
+ local listenerByBehaviorByGlobalEvent = {}
62
+ local globalEventsByBehavior = {}
60
63
  local behaviorsByEvent = {}
61
64
  local listenerByBehaviorByEvent = {}
62
65
  local eventsByBehavior = {}
66
+ local function safeCallBehaviorListener(behavior, behaviors, listenerByBehavior, ...)
67
+ if behaviors[behavior] ~= nil then
68
+ safeCall(behavior[listenerByBehavior[behavior]], behavior, ...)
69
+ end
70
+ end
63
71
  ____exports.Behavior = __TS__Class()
64
72
  local Behavior = ____exports.Behavior
65
73
  Behavior.name = "Behavior"
@@ -87,18 +95,32 @@ function Behavior.prototype.onDestroy(self)
87
95
  if ____opt_0 ~= nil then
88
96
  ____opt_0:destroy()
89
97
  end
90
- local events = eventsByBehavior[self]
91
- if events ~= nil then
92
- for event in pairs(events) do
93
- local ____opt_2 = behaviorsByEvent[event]
98
+ local globalEvents = globalEventsByBehavior[self]
99
+ if globalEvents ~= nil then
100
+ for event in pairs(globalEvents) do
101
+ local ____opt_2 = behaviorsByGlobalEvent[event]
94
102
  if ____opt_2 ~= nil then
95
103
  ____opt_2:remove(self)
96
104
  end
97
- local ____opt_4 = listenerByBehaviorByEvent[event]
105
+ local ____opt_4 = listenerByBehaviorByGlobalEvent[event]
98
106
  if ____opt_4 ~= nil then
99
107
  ____opt_4[self] = nil
100
108
  end
101
109
  end
110
+ globalEventsByBehavior[self] = nil
111
+ end
112
+ local events = eventsByBehavior[self]
113
+ if events ~= nil then
114
+ for event in pairs(events) do
115
+ local ____opt_6 = behaviorsByEvent[event]
116
+ if ____opt_6 ~= nil then
117
+ ____opt_6[self] = nil
118
+ end
119
+ local ____opt_8 = listenerByBehaviorByEvent[event]
120
+ if ____opt_8 ~= nil then
121
+ ____opt_8[self] = nil
122
+ end
123
+ end
102
124
  eventsByBehavior[self] = nil
103
125
  end
104
126
  local previousBehavior = self[0]
@@ -115,7 +137,35 @@ function Behavior.prototype.onDestroy(self)
115
137
  end
116
138
  return AbstractDestroyable.prototype.onDestroy(self)
117
139
  end
118
- function Behavior.prototype.registerEvent(self, event, listener)
140
+ function Behavior.prototype.registerGlobalEvent(self, event, listener)
141
+ local listenerByBehavior = getOrPut(listenerByBehaviorByGlobalEvent, event, mutableLuaMap)
142
+ listenerByBehavior[self] = listener
143
+ getOrPut(globalEventsByBehavior, self, mutableLuaSet)[event] = true
144
+ local behaviors = behaviorsByGlobalEvent[event]
145
+ if behaviors == nil then
146
+ event:addListener(function(...)
147
+ local behaviors = behaviorsByGlobalEvent[event]
148
+ if behaviors ~= nil then
149
+ for behavior in pairs(behaviors) do
150
+ safeCall(behavior[listenerByBehavior[behavior]], behavior, ...)
151
+ end
152
+ end
153
+ end)
154
+ behaviors = __TS__New(LinkedSet)
155
+ behaviorsByGlobalEvent[event] = behaviors
156
+ end
157
+ behaviors:add(self)
158
+ end
159
+ function Behavior.prototype.deregisterGlobalEvent(self, event)
160
+ local behaviors = behaviorsByGlobalEvent[event]
161
+ if behaviors ~= nil and behaviors:remove(self) then
162
+ globalEventsByBehavior[self][event] = nil
163
+ listenerByBehaviorByGlobalEvent[event][self] = nil
164
+ return true
165
+ end
166
+ return false
167
+ end
168
+ function Behavior.prototype.registerEvent(self, event, extractObject, listener)
119
169
  local listenerByBehavior = getOrPut(listenerByBehaviorByEvent, event, mutableLuaMap)
120
170
  listenerByBehavior[self] = listener
121
171
  getOrPut(eventsByBehavior, self, mutableLuaSet)[event] = true
@@ -124,19 +174,27 @@ function Behavior.prototype.registerEvent(self, event, listener)
124
174
  event:addListener(function(...)
125
175
  local behaviors = behaviorsByEvent[event]
126
176
  if behaviors ~= nil then
127
- for behavior in pairs(behaviors) do
128
- safeCall(behavior[listenerByBehavior[behavior]], behavior, ...)
177
+ local object = extractObject(...)
178
+ if object ~= nil then
179
+ ____exports.Behavior:forAll(
180
+ object,
181
+ safeCallBehaviorListener,
182
+ behaviors,
183
+ listenerByBehavior,
184
+ ...
185
+ )
129
186
  end
130
187
  end
131
188
  end)
132
- behaviors = __TS__New(LinkedSet)
189
+ behaviors = {}
133
190
  behaviorsByEvent[event] = behaviors
134
191
  end
135
- behaviors:add(self)
192
+ behaviors[self] = true
136
193
  end
137
194
  function Behavior.prototype.deregisterEvent(self, event)
138
195
  local behaviors = behaviorsByEvent[event]
139
- if behaviors ~= nil and behaviors:remove(self) then
196
+ if behaviors ~= nil and behaviors[self] ~= nil then
197
+ behaviors[self] = nil
140
198
  eventsByBehavior[self][event] = nil
141
199
  listenerByBehaviorByEvent[event][self] = nil
142
200
  return true
@@ -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
@@ -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,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)
package/engine/buff.d.ts CHANGED
@@ -13,6 +13,7 @@ import { UnitBehavior } from "./behaviour/unit";
13
13
  import type { Widget } from "../core/types/widget";
14
14
  import { Destructor } from "../destroyable";
15
15
  import { Event } from "../event";
16
+ import { AbilityBehavior } from "./behaviour/ability";
16
17
  export type BuffConstructor<T extends Buff<any> = Buff<any>, Args extends any[] = any> = OmitConstructor<typeof Buff<any>> & (new (...args: Args) => T);
17
18
  type EnumParameterValueType<T extends number> = T | AbilityEnumLevelField<T>;
18
19
  type NumberParameterValueType = number | AbilityNumberField | AbilityNumberLevelField;
@@ -141,7 +142,7 @@ export type BuffConstructorParameters<AdditionalParameters extends BuffAdditiona
141
142
  polarity: BuffPolarityParameterType,
142
143
  resistanceType: BuffResistanceTypeParameterType,
143
144
  ...abilityOrParameters: [
144
- ability?: Ability,
145
+ ability?: Ability | AbilityBehavior,
145
146
  parameters?: BuffParameters & Omit<AdditionalParameters, keyof BuffParameters>
146
147
  ] | [parameters?: BuffParameters & Omit<AdditionalParameters, keyof BuffParameters>]
147
148
  ];
package/engine/buff.lua CHANGED
@@ -53,6 +53,8 @@ local ____destructable = require("core.types.destructable")
53
53
  local Destructable = ____destructable.Destructable
54
54
  local ____ability = require("engine.standard.fields.ability")
55
55
  local COOLDOWN_ABILITY_FLOAT_LEVEL_FIELD = ____ability.COOLDOWN_ABILITY_FLOAT_LEVEL_FIELD
56
+ local ____ability = require("engine.behaviour.ability")
57
+ local AbilityBehavior = ____ability.AbilityBehavior
56
58
  local getUnitAbility = BlzGetUnitAbility
57
59
  local stringValueByBuffTypeIdByFieldId = postcompile(function()
58
60
  local stringValueByBuffTypeIdByFieldId = {}
@@ -322,33 +324,38 @@ function Buff.prototype.____constructor(self, _unit, typeIdOrTypeIds, polarityOr
322
324
  local polarity
323
325
  local resistanceType
324
326
  local ability
327
+ local abilityBehavior
325
328
  if type(typeIdOrTypeIds) ~= "number" then
326
329
  typeId = selectBuffTypeIdWithLeastDuration(typeIdOrTypeIds, _unit)
327
330
  polarity = resistanceTypeOrPolarity
328
331
  resistanceType = abilityOrParametersOrResistanceType
329
- if __TS__InstanceOf(parametersOrAbility, Ability) or parametersOrAbility == nil then
332
+ if __TS__InstanceOf(parametersOrAbility, AbilityBehavior) then
333
+ abilityBehavior = parametersOrAbility
334
+ ability = abilityBehavior.ability
335
+ elseif __TS__InstanceOf(parametersOrAbility, Ability) then
330
336
  ability = parametersOrAbility
331
- else
332
- ability = nil
337
+ elseif parametersOrAbility ~= nil then
333
338
  parameters = parametersOrAbility
334
339
  end
335
340
  else
336
341
  typeId = typeIdOrTypeIds
337
342
  polarity = polarityOrTypeIdSelectionPolicy
338
343
  resistanceType = resistanceTypeOrPolarity
339
- if __TS__InstanceOf(abilityOrParametersOrResistanceType, Ability) or abilityOrParametersOrResistanceType == nil then
344
+ if __TS__InstanceOf(abilityOrParametersOrResistanceType, AbilityBehavior) then
345
+ abilityBehavior = abilityOrParametersOrResistanceType
346
+ ability = abilityBehavior.ability
347
+ parameters = parametersOrAbility
348
+ elseif __TS__InstanceOf(abilityOrParametersOrResistanceType, Ability) then
340
349
  ability = abilityOrParametersOrResistanceType
341
350
  parameters = parametersOrAbility
342
- else
343
- ability = nil
351
+ elseif abilityOrParametersOrResistanceType ~= nil then
344
352
  parameters = abilityOrParametersOrResistanceType
353
+ else
354
+ parameters = parametersOrAbility
345
355
  end
346
356
  end
357
+ self.sourceAbilityBehavior = abilityBehavior
347
358
  self.typeId = typeId
348
- if not (__TS__InstanceOf(ability, Ability) or ability == nil) then
349
- parameters = ability
350
- ability = nil
351
- end
352
359
  local defaultParameters = self.constructor.defaultParameters
353
360
  local level = parameters and parameters.level or defaultParameters.level
354
361
  local spellStealPriority = parameters and parameters.spellStealPriority or defaultParameters.spellStealPriority
@@ -1380,5 +1387,8 @@ Buff.beingDestroyedEvent = buffBeingDestroyedEvent;
1380
1387
  buffCreatedEvent:addListener(function(buff)
1381
1388
  UnitBehavior:forAll(buff.unit, "onBuffGained", buff)
1382
1389
  end)
1390
+ buffBeingDestroyedEvent:addListener(function(buff)
1391
+ UnitBehavior:forAll(buff.unit, "onBuffLost", buff)
1392
+ end)
1383
1393
  end)(Buff)
1384
1394
  return ____exports
@@ -1,14 +1,30 @@
1
1
  /** @noSelfInFile */
2
2
  import { ArmorSoundType } from "../auxiliary/armor-sound-type";
3
3
  import { CombatClassifications } from "../auxiliary/combat-classification";
4
- import { ObjectDataEntry, ObjectDataEntryId } from "../entry";
4
+ import { ObjectDataEntry, ObjectDataEntryConstructor, ObjectDataEntryId } from "../entry";
5
5
  export type DestructibleTypeId = ObjectDataEntryId & number & {
6
6
  readonly __destructibleTypeId: unique symbol;
7
7
  };
8
+ export type StandardDestructibleTypeId = DestructibleTypeId & {
9
+ readonly __standardDestructibleTypeId: unique symbol;
10
+ };
8
11
  export declare abstract class DestructibleType extends ObjectDataEntry<DestructibleTypeId> {
12
+ static readonly [id: StandardDestructibleTypeId]: ObjectDataEntryConstructor<DestructibleType>;
9
13
  private static readonly idGenerator;
10
14
  protected static generateId(): number;
11
15
  protected static getObjectData(map: WarMap): WarObjects;
16
+ get fixedFacing(): number;
17
+ set fixedFacing(fixedFacing: number);
18
+ get flyOverHeight(): number;
19
+ set flyOverHeight(flyOverHeight: number);
20
+ get modelPath(): string;
21
+ set modelPath(modelPath: string);
22
+ get modelPathSD(): string;
23
+ set modelPathSD(modelPathSD: string);
24
+ get modelPathHD(): string;
25
+ set modelPathHD(modelPathHD: string);
26
+ get occlusionHeight(): number;
27
+ set occlusionHeight(occlusionHeight: number);
12
28
  get armorSoundType(): ArmorSoundType;
13
29
  set armorSoundType(armorSoundType: ArmorSoundType);
14
30
  get armorSoundTypeSD(): ArmorSoundType;
@@ -17,4 +33,14 @@ export declare abstract class DestructibleType extends ObjectDataEntry<Destructi
17
33
  set armorSoundTypeHD(armorSoundTypeHD: ArmorSoundType);
18
34
  get combatClassifications(): CombatClassifications;
19
35
  set combatClassifications(combatClassifications: CombatClassifications);
36
+ get cliffHeight(): number;
37
+ set cliffHeight(cliffHeight: number);
38
+ get isWalkable(): boolean;
39
+ set isWalkable(isWalkable: boolean);
40
+ get pathingTexturePath(): string;
41
+ set pathingTexturePath(pathingTexturePath: string);
42
+ get deadPathingTexturePath(): string;
43
+ set deadPathingTexturePath(deadPathingTexturePath: string);
44
+ get name(): string;
45
+ set name(name: string);
20
46
  }