warscript 0.0.1-dev.c826fde → 0.0.1-dev.c86de6d

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 (137) hide show
  1. package/attributes.d.ts +1 -0
  2. package/attributes.lua +9 -0
  3. package/core/types/frame.lua +61 -10
  4. package/core/types/handle.lua +6 -9
  5. package/core/types/item.d.ts +1 -0
  6. package/core/types/item.lua +1 -0
  7. package/core/types/player.d.ts +17 -1
  8. package/core/types/player.lua +67 -23
  9. package/core/types/playerCamera.lua +44 -0
  10. package/core/types/sound.lua +1 -1
  11. package/core/types/tileCell.d.ts +11 -1
  12. package/core/types/tileCell.lua +97 -0
  13. package/core/types/timer.d.ts +3 -2
  14. package/core/types/timer.lua +8 -2
  15. package/destroyable.d.ts +1 -0
  16. package/destroyable.lua +9 -0
  17. package/engine/behavior.d.ts +10 -2
  18. package/engine/behavior.lua +157 -76
  19. package/engine/behaviour/ability/apply-buff.lua +4 -4
  20. package/engine/behaviour/ability/damage.d.ts +3 -0
  21. package/engine/behaviour/ability/damage.lua +8 -2
  22. package/engine/behaviour/ability/emulate-impact.lua +5 -4
  23. package/engine/behaviour/ability/remove-buffs.d.ts +9 -0
  24. package/engine/behaviour/ability/remove-buffs.lua +21 -0
  25. package/engine/behaviour/ability.d.ts +11 -6
  26. package/engine/behaviour/ability.lua +31 -1
  27. package/engine/behaviour/unit/stun-immunity.d.ts +9 -5
  28. package/engine/behaviour/unit/stun-immunity.lua +17 -7
  29. package/engine/behaviour/unit.d.ts +9 -3
  30. package/engine/behaviour/unit.lua +106 -24
  31. package/engine/buff.d.ts +65 -18
  32. package/engine/buff.lua +356 -152
  33. package/engine/internal/ability.lua +15 -15
  34. package/engine/internal/item/fields.d.ts +12 -0
  35. package/engine/internal/item/fields.lua +33 -0
  36. package/engine/internal/item.d.ts +12 -13
  37. package/engine/internal/item.lua +59 -47
  38. package/engine/internal/mechanics/cast-ability.lua +6 -3
  39. package/engine/internal/object-data/attribute-bonus.lua +2 -2
  40. package/engine/internal/object-data/health-bonus.d.ts +2 -0
  41. package/engine/internal/object-data/health-bonus.lua +16 -0
  42. package/engine/internal/object-data/mana-bonus.d.ts +2 -0
  43. package/engine/internal/object-data/mana-bonus.lua +16 -0
  44. package/engine/internal/object-data/mana-regeneration-rate-increase-factor.d.ts +2 -0
  45. package/engine/internal/object-data/mana-regeneration-rate-increase-factor.lua +16 -0
  46. package/engine/internal/unit/ability.d.ts +14 -14
  47. package/engine/internal/unit/ability.lua +72 -45
  48. package/engine/internal/unit/attributes.d.ts +17 -0
  49. package/engine/internal/unit/attributes.lua +46 -0
  50. package/engine/internal/unit/bonus.d.ts +6 -0
  51. package/engine/internal/unit/bonus.lua +33 -3
  52. package/engine/internal/unit/fly-height.d.ts +7 -0
  53. package/engine/internal/unit/fly-height.lua +20 -0
  54. package/engine/internal/unit/interrupts.d.ts +12 -0
  55. package/engine/internal/unit/interrupts.lua +28 -0
  56. package/engine/internal/unit/main-selected.lua +12 -27
  57. package/engine/internal/unit/range-event.d.ts +12 -0
  58. package/engine/internal/unit/range-event.lua +90 -0
  59. package/engine/internal/unit/scale.d.ts +7 -0
  60. package/engine/internal/unit/scale.lua +20 -0
  61. package/engine/internal/unit+bonus.lua +3 -3
  62. package/engine/internal/unit-missile-launch.lua +51 -20
  63. package/engine/internal/unit.d.ts +15 -19
  64. package/engine/internal/unit.lua +160 -183
  65. package/engine/local-client.d.ts +7 -0
  66. package/engine/local-client.lua +86 -1
  67. package/engine/object-data/auxiliary/health-regeneration-type.d.ts +8 -0
  68. package/engine/object-data/auxiliary/health-regeneration-type.lua +2 -0
  69. package/engine/object-data/auxiliary/unit-attribute.lua +1 -1
  70. package/engine/object-data/entry/ability-type/{armor-increase.d.ts → armor-bonus.d.ts} +3 -3
  71. package/engine/object-data/entry/ability-type/{armor-increase.lua → armor-bonus.lua} +9 -9
  72. package/engine/object-data/entry/ability-type/health-bonus.d.ts +8 -0
  73. package/engine/object-data/entry/ability-type/health-bonus.lua +26 -0
  74. package/engine/object-data/entry/ability-type/mana-bonus.d.ts +8 -0
  75. package/engine/object-data/entry/ability-type/mana-bonus.lua +26 -0
  76. package/engine/object-data/entry/ability-type/mana-regeneration.d.ts +8 -0
  77. package/engine/object-data/entry/ability-type/mana-regeneration.lua +26 -0
  78. package/engine/object-data/entry/ability-type/reincarnation.d.ts +8 -0
  79. package/engine/object-data/entry/ability-type/reincarnation.lua +26 -0
  80. package/engine/object-data/entry/ability-type.d.ts +2 -0
  81. package/engine/object-data/entry/ability-type.lua +88 -5
  82. package/engine/object-data/entry/buff-type/applicable.lua +113 -109
  83. package/engine/object-data/entry/destructible-type.d.ts +27 -1
  84. package/engine/object-data/entry/destructible-type.lua +155 -0
  85. package/engine/object-data/entry/unit-type.d.ts +4 -0
  86. package/engine/object-data/entry/unit-type.lua +76 -32
  87. package/engine/object-field/ability.lua +2 -2
  88. package/engine/object-field/item.d.ts +22 -0
  89. package/engine/object-field/item.lua +118 -0
  90. package/engine/object-field/unit.d.ts +20 -5
  91. package/engine/object-field/unit.lua +61 -0
  92. package/engine/object-field.d.ts +10 -2
  93. package/engine/object-field.lua +268 -123
  94. package/engine/random.d.ts +10 -0
  95. package/engine/random.lua +21 -0
  96. package/engine/standard/fields/ability.d.ts +2 -2
  97. package/engine/standard/fields/ability.lua +2 -2
  98. package/engine/standard/fields/item.d.ts +4 -0
  99. package/engine/standard/fields/item.lua +6 -0
  100. package/engine/standard/fields/unit.d.ts +11 -3
  101. package/engine/standard/fields/unit.lua +15 -2
  102. package/engine/synchronization.d.ts +11 -0
  103. package/engine/synchronization.lua +77 -0
  104. package/engine/text-tag.lua +3 -2
  105. package/engine/unit.d.ts +5 -0
  106. package/engine/unit.lua +5 -0
  107. package/lualib_bundle.lua +1 -1
  108. package/math.d.ts +2 -0
  109. package/math.lua +14 -0
  110. package/net/socket.lua +1 -1
  111. package/network.lua +25 -1
  112. package/objutil/buff.lua +10 -8
  113. package/objutil/object.lua +1 -1
  114. package/operation.d.ts +8 -1
  115. package/operation.lua +38 -18
  116. package/package.json +5 -5
  117. package/patch-lua.lua +15 -0
  118. package/utility/arrays.d.ts +1 -0
  119. package/utility/arrays.lua +8 -0
  120. package/utility/callback-array.d.ts +5 -1
  121. package/utility/callback-array.lua +16 -1
  122. package/utility/linked-map.d.ts +35 -0
  123. package/utility/linked-map.lua +107 -0
  124. package/utility/linked-set.d.ts +4 -1
  125. package/utility/linked-set.lua +46 -1
  126. package/utility/lua-maps.d.ts +11 -2
  127. package/utility/lua-maps.lua +33 -2
  128. package/utility/random.d.ts +102 -0
  129. package/utility/random.lua +273 -0
  130. package/utility/records.lua +20 -1
  131. package/utility/types.d.ts +3 -0
  132. package/utility/unordered-map.d.ts +27 -0
  133. package/utility/unordered-map.lua +99 -0
  134. /package/engine/internal/object-data/{armor-increase.d.ts → armor-bonus.d.ts} +0 -0
  135. /package/engine/internal/object-data/{armor-increase.lua → armor-bonus.lua} +0 -0
  136. /package/engine/object-data/entry/ability-type/{attribute-increase.d.ts → attribute-bonus.d.ts} +0 -0
  137. /package/engine/object-data/entry/ability-type/{attribute-increase.lua → attribute-bonus.lua} +0 -0
@@ -1,6 +1,7 @@
1
1
  /** @noSelfInFile */
2
2
  import { Event } from "../../event";
3
3
  import { AbstractDestroyable, Destructor } from "../../destroyable";
4
+ import { CallbackId } from "../../utility/callback-array";
4
5
  declare const enum TimerPropertyKey {
5
6
  HANDLE = 0,
6
7
  DESTROY_ON_EXPIRATION = 1,
@@ -22,8 +23,8 @@ export declare class Timer extends AbstractDestroyable {
22
23
  pause(): void;
23
24
  resume(): void;
24
25
  static create(): Timer;
25
- static run<T, K extends KeysOfType<T, (this: T, ...args: any) => any>>(object: T, key: K, ...parameters: T[K] extends (this: T, ...args: any) => any ? Parameters<T[K]> : never): void;
26
- static run<Args extends any[]>(callback: (this: void, ...args: Args) => void, ...args: Args): void;
26
+ static run<T, K extends KeysOfType<T, (this: T, ...args: any) => any>>(object: T, key: K, ...parameters: T[K] extends (this: T, ...args: any) => any ? Parameters<T[K]> : never): CallbackId;
27
+ static run<Args extends any[]>(callback: (this: void, ...args: Args) => void, ...args: Args): CallbackId;
27
28
  static simple<Args extends any[]>(timeout: number, callback: (...args: Args) => void, ...args: Args): Timer;
28
29
  static periodic<Args extends any[]>(period: number, callback: (this: void, timer: Timer, ...args: Args) => void, ...args: Args): Timer;
29
30
  static counted(period: number, count: number, callback: (this: void, timer: Timer) => void): Timer;
@@ -15,6 +15,7 @@ local AbstractDestroyable = ____destroyable.AbstractDestroyable
15
15
  local ____callback_2Darray = require("utility.callback-array")
16
16
  local addCallback = ____callback_2Darray.addCallback
17
17
  local callbackArray = ____callback_2Darray.callbackArray
18
+ local consumeCallback = ____callback_2Darray.consumeCallback
18
19
  local consumeCallbacks = ____callback_2Darray.consumeCallbacks
19
20
  local createTimer = CreateTimer
20
21
  local timerStart = TimerStart
@@ -55,6 +56,11 @@ local function timerSafeCall()
55
56
  end
56
57
  local zeroTimerScheduled = false
57
58
  local zeroTimerCallbacks = callbackArray()
59
+ ---
60
+ -- @internal For use by internal systems only.
61
+ ____exports.consumeZeroTimerCallback = function(id)
62
+ consumeCallback(zeroTimerCallbacks, id)
63
+ end
58
64
  local function invokeZeroTimerCallbacks()
59
65
  zeroTimerScheduled = false
60
66
  consumeCallbacks(zeroTimerCallbacks)
@@ -98,9 +104,9 @@ function Timer.run(self, objectOrCallback, keyOrFirstArg, ...)
98
104
  ____exports.Timer:simple(0, invokeZeroTimerCallbacks)
99
105
  end
100
106
  if ____type(objectOrCallback) == "function" then
101
- addCallback(zeroTimerCallbacks, objectOrCallback, keyOrFirstArg, ...)
107
+ return addCallback(zeroTimerCallbacks, objectOrCallback, keyOrFirstArg, ...)
102
108
  else
103
- addCallback(zeroTimerCallbacks, objectOrCallback[keyOrFirstArg], objectOrCallback, ...)
109
+ return addCallback(zeroTimerCallbacks, objectOrCallback[keyOrFirstArg], objectOrCallback, ...)
104
110
  end
105
111
  end
106
112
  function Timer.simple(self, timeout, callback, ...)
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
@@ -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,12 +14,15 @@ 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
+ constructor(object: T, priority?: BehaviorPriority);
16
22
  protected onDestroy(): Destructor;
17
- 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;
18
26
  protected deregisterEvent(event: Event<any>): boolean;
19
27
  protected onPeriod(...parameters: PeriodicActionParameters): void;
20
28
  protected startPeriodicAction(interval: number, ...parameters: PeriodicActionParameters): void;
@@ -18,56 +18,71 @@ 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
57
59
  end
60
+ local behaviorsByGlobalEvent = {}
61
+ local listenerByBehaviorByGlobalEvent = {}
62
+ local globalEventsByBehavior = {}
58
63
  local behaviorsByEvent = {}
59
64
  local listenerByBehaviorByEvent = {}
60
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
61
71
  ____exports.Behavior = __TS__Class()
62
72
  local Behavior = ____exports.Behavior
63
73
  Behavior.name = "Behavior"
64
74
  __TS__ClassExtends(Behavior, AbstractDestroyable)
65
- function Behavior.prototype.____constructor(self, object)
75
+ function Behavior.prototype.____constructor(self, object, priority)
76
+ if priority == nil then
77
+ priority = 1
78
+ end
66
79
  AbstractDestroyable.prototype.____constructor(self)
67
80
  self.object = object
81
+ self.priority = priority
82
+ local lastBehaviorByObject = lastBehaviorByObjectByPriority[priority]
68
83
  local lastBehavior = lastBehaviorByObject[object]
69
84
  if lastBehavior == nil then
70
- firstBehaviorByObject[object] = self
85
+ firstBehaviorByObjectByPriority[priority][object] = self
71
86
  lastBehaviorByObject[object] = self
72
87
  else
73
88
  self[0] = lastBehavior
@@ -80,18 +95,32 @@ function Behavior.prototype.onDestroy(self)
80
95
  if ____opt_0 ~= nil then
81
96
  ____opt_0:destroy()
82
97
  end
83
- local events = eventsByBehavior[self]
84
- if events ~= nil then
85
- for event in pairs(events) do
86
- 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]
87
102
  if ____opt_2 ~= nil then
88
103
  ____opt_2:remove(self)
89
104
  end
90
- local ____opt_4 = listenerByBehaviorByEvent[event]
105
+ local ____opt_4 = listenerByBehaviorByGlobalEvent[event]
91
106
  if ____opt_4 ~= nil then
92
107
  ____opt_4[self] = nil
93
108
  end
94
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
95
124
  eventsByBehavior[self] = nil
96
125
  end
97
126
  local previousBehavior = self[0]
@@ -99,16 +128,44 @@ function Behavior.prototype.onDestroy(self)
99
128
  if previousBehavior ~= nil then
100
129
  previousBehavior[1] = nextBehavior
101
130
  else
102
- firstBehaviorByObject[self.object] = nextBehavior
131
+ firstBehaviorByObjectByPriority[self.priority][self.object] = nextBehavior
103
132
  end
104
133
  if nextBehavior ~= nil then
105
134
  nextBehavior[0] = previousBehavior
106
135
  else
107
- lastBehaviorByObject[self.object] = previousBehavior
136
+ lastBehaviorByObjectByPriority[self.priority][self.object] = previousBehavior
108
137
  end
109
138
  return AbstractDestroyable.prototype.onDestroy(self)
110
139
  end
111
- 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)
112
169
  local listenerByBehavior = getOrPut(listenerByBehaviorByEvent, event, mutableLuaMap)
113
170
  listenerByBehavior[self] = listener
114
171
  getOrPut(eventsByBehavior, self, mutableLuaSet)[event] = true
@@ -117,19 +174,27 @@ function Behavior.prototype.registerEvent(self, event, listener)
117
174
  event:addListener(function(...)
118
175
  local behaviors = behaviorsByEvent[event]
119
176
  if behaviors ~= nil then
120
- for behavior in pairs(behaviors) do
121
- 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
+ )
122
186
  end
123
187
  end
124
188
  end)
125
- behaviors = __TS__New(LinkedSet)
189
+ behaviors = {}
126
190
  behaviorsByEvent[event] = behaviors
127
191
  end
128
- behaviors:add(self)
192
+ behaviors[self] = true
129
193
  end
130
194
  function Behavior.prototype.deregisterEvent(self, event)
131
195
  local behaviors = behaviorsByEvent[event]
132
- if behaviors ~= nil and behaviors:remove(self) then
196
+ if behaviors ~= nil and behaviors[self] ~= nil then
197
+ behaviors[self] = nil
133
198
  eventsByBehavior[self][event] = nil
134
199
  listenerByBehaviorByEvent[event][self] = nil
135
200
  return true
@@ -161,78 +226,94 @@ function Behavior.prototype.stopPeriodicAction(self)
161
226
  end
162
227
  function Behavior.count(self, object, limit)
163
228
  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
229
+ for priority = 0, 2 do
230
+ local behavior = firstBehaviorByObjectByPriority[priority][object]
231
+ while behavior ~= nil and (limit == nil or behaviorsCount < limit) do
232
+ if __TS__InstanceOf(behavior, self) then
233
+ behaviorsCount = behaviorsCount + 1
234
+ end
235
+ behavior = behavior[1]
168
236
  end
169
- behavior = behavior[1]
170
237
  end
171
238
  return behaviorsCount
172
239
  end
173
240
  function Behavior.getFirst(self, object, countOrPredicate, ...)
174
- local behavior = firstBehaviorByObject[object]
175
241
  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
242
+ for priority = 0, 2 do
243
+ local behavior = firstBehaviorByObjectByPriority[priority][object]
244
+ while behavior ~= nil do
245
+ if __TS__InstanceOf(behavior, self) and (countOrPredicate == nil or countOrPredicate(behavior, ...)) then
246
+ return behavior
247
+ end
248
+ behavior = behavior[1]
179
249
  end
180
- behavior = behavior[1]
181
250
  end
182
251
  return nil
183
252
  end
184
253
  local behaviors = {}
185
254
  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
255
+ for priority = 0, 2 do
256
+ local behavior = firstBehaviorByObjectByPriority[priority][object]
257
+ while behavior ~= nil and behaviorsCount < countOrPredicate do
258
+ if __TS__InstanceOf(behavior, self) then
259
+ behaviorsCount = behaviorsCount + 1
260
+ behaviors[behaviorsCount] = behavior
261
+ end
262
+ behavior = behavior[1]
190
263
  end
191
- behavior = behavior[1]
192
264
  end
193
265
  return behaviors
194
266
  end
195
267
  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
268
+ for priority = 2, 0, -1 do
269
+ local behavior = lastBehaviorByObjectByPriority[priority][object]
270
+ while behavior ~= nil do
271
+ if __TS__InstanceOf(behavior, self) then
272
+ return behavior
273
+ end
274
+ behavior = behavior[0]
200
275
  end
201
- behavior = behavior[0]
202
276
  end
203
277
  return nil
204
278
  end
205
279
  function Behavior.getAll(self, object, predicate, ...)
206
280
  local behaviors = {}
207
281
  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
282
+ for priority = 0, 2 do
283
+ local behavior = firstBehaviorByObjectByPriority[priority][object]
284
+ while behavior ~= nil do
285
+ if __TS__InstanceOf(behavior, self) and (predicate == nil or predicate(behavior, ...)) then
286
+ behaviorsCount = behaviorsCount + 1
287
+ behaviors[behaviorsCount] = behavior
288
+ end
289
+ behavior = behavior[1]
213
290
  end
214
- behavior = behavior[1]
215
291
  end
216
292
  return behaviors
217
293
  end
218
294
  function Behavior.forFirst(self, object, count, consumerOrKey, ...)
219
295
  local behaviorsCount = 0
220
- local behavior = firstBehaviorByObject[object]
221
296
  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
297
+ for priority = 0, 2 do
298
+ local behavior = firstBehaviorByObjectByPriority[priority][object]
299
+ while behavior ~= nil and behaviorsCount < count do
300
+ if __TS__InstanceOf(behavior, self) then
301
+ safeCall(consumerOrKey, behavior, ...)
302
+ behaviorsCount = behaviorsCount + 1
303
+ end
304
+ behavior = behavior[1]
226
305
  end
227
- behavior = behavior[1]
228
306
  end
229
307
  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
308
+ for priority = 0, 2 do
309
+ local behavior = firstBehaviorByObjectByPriority[priority][object]
310
+ while behavior ~= nil and behaviorsCount < count do
311
+ if __TS__InstanceOf(behavior, self) then
312
+ safeCall(behavior[consumerOrKey], behavior, ...)
313
+ behaviorsCount = behaviorsCount + 1
314
+ end
315
+ behavior = behavior[1]
234
316
  end
235
- behavior = behavior[1]
236
317
  end
237
318
  end
238
319
  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
@@ -25,8 +25,11 @@ export declare abstract class DamageAbilityBehavior<T extends DamageAbilityBehav
25
25
  protected readonly damage: AbilityDependentValue<number>;
26
26
  protected readonly parameters?: T | undefined;
27
27
  protected constructor(ability: Ability, damage: AbilityDependentValue<number>, parameters?: T | undefined);
28
+ protected precalculatedDamage?: number;
28
29
  protected calculateDamage(caster: Unit): number;
29
30
  protected damageTarget(caster: Unit, target: Widget, damage?: number): void;
31
+ onChannelingStart(caster: Unit): void;
32
+ onStop(): void;
30
33
  }
31
34
  export declare class DamageSelfAbilityBehavior extends DamageAbilityBehavior {
32
35
  constructor(ability: Ability, damage: AbilityDependentValue<number>, parameters?: DamageAbilityBehaviorParameters);
@@ -39,7 +39,7 @@ function DamageAbilityBehavior.prototype.damageTarget(self, caster, target, dama
39
39
  local parameters = self.parameters
40
40
  caster:damageTarget(
41
41
  target,
42
- damage or self:calculateDamage(caster),
42
+ damage or self.precalculatedDamage or self:calculateDamage(caster),
43
43
  nil,
44
44
  nil,
45
45
  self:resolveCurrentAbilityDependentValue(parameters and parameters.attackType),
@@ -48,6 +48,12 @@ function DamageAbilityBehavior.prototype.damageTarget(self, caster, target, dama
48
48
  self:resolveCurrentAbilityDependentValue(parameters and parameters.metadata)
49
49
  )
50
50
  end
51
+ function DamageAbilityBehavior.prototype.onChannelingStart(self, caster)
52
+ self.precalculatedDamage = self:calculateDamage(caster)
53
+ end
54
+ function DamageAbilityBehavior.prototype.onStop(self)
55
+ self.precalculatedDamage = nil
56
+ end
51
57
  ____exports.DamageSelfAbilityBehavior = __TS__Class()
52
58
  local DamageSelfAbilityBehavior = ____exports.DamageSelfAbilityBehavior
53
59
  DamageSelfAbilityBehavior.name = "DamageSelfAbilityBehavior"
@@ -83,7 +89,7 @@ function DamageAreaAbilityBehavior.prototype.damageArea(self, caster, x, y)
83
89
  y,
84
90
  self:resolveCurrentAbilityDependentValue(parameters and parameters.areaOfEffect or AREA_OF_EFFECT_ABILITY_FLOAT_LEVEL_FIELD)
85
91
  )
86
- local damage = self:calculateDamage(caster)
92
+ local damage = self.precalculatedDamage or self:calculateDamage(caster)
87
93
  local maximumDamage = self:resolveCurrentAbilityDependentValue(parameters and parameters.maximumDamage or 0)
88
94
  if maximumDamage ~= 0 and damage > maximumDamage then
89
95
  damage = maximumDamage / #targets
@@ -10,9 +10,6 @@ local Unit = ____unit.Unit
10
10
  local ____ability = require("engine.standard.fields.ability")
11
11
  local COOLDOWN_ABILITY_FLOAT_LEVEL_FIELD = ____ability.COOLDOWN_ABILITY_FLOAT_LEVEL_FIELD
12
12
  local MANA_COST_ABILITY_INTEGER_LEVEL_FIELD = ____ability.MANA_COST_ABILITY_INTEGER_LEVEL_FIELD
13
- local ____math = require("math")
14
- local max = ____math.max
15
- local MINIMUM_POSITIVE_NORMALIZED_FLOAT = ____math.MINIMUM_POSITIVE_NORMALIZED_FLOAT
16
13
  local ____sound = require("core.types.sound")
17
14
  local Sound3D = ____sound.Sound3D
18
15
  local SoundSettings = ____sound.SoundSettings
@@ -31,7 +28,11 @@ function EmulateImpactAbilityBehavior.prototype.emulateImpact(self, caster)
31
28
  return false
32
29
  end
33
30
  caster.mana = caster.mana - manaCost
34
- self.ability.cooldownRemaining = max(cooldown, MINIMUM_POSITIVE_NORMALIZED_FLOAT)
31
+ if cooldown == 0 then
32
+ self.ability:interruptCast()
33
+ else
34
+ self.ability.cooldownRemaining = cooldown
35
+ end
35
36
  self:flashCasterEffect(caster)
36
37
  local soundPresetId = self.ability:getField(ABILITY_SF_EFFECT_SOUND)
37
38
  if soundPresetId ~= "" then
@@ -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";
@@ -25,16 +26,20 @@ export declare abstract class AbilityBehavior<Parameters extends {
25
26
  get unit(): Unit | undefined;
26
27
  protected resolveCurrentAbilityDependentValue<T extends boolean | number | string>(value: AbilityDependentValue<T>): T;
27
28
  protected resolveCurrentAbilityDependentValue<T extends boolean | number | string>(value?: AbilityDependentValue<T>): T | undefined;
28
- protected flashCasterEffect(widget: Widget, ...parametersOrDuration: [parameters?: EffectParameters] | [duration?: number, parameters?: EffectParameters]): void;
29
- protected flashTargetEffect(widget: Widget, ...parametersOrDuration: [parameters?: EffectParameters] | [duration?: number, parameters?: EffectParameters]): void;
30
- protected flashAreaEffect(x: number, y: number, ...parametersOrDuration: [parameters?: EffectParameters] | [duration?: number, parameters?: EffectParameters]): void;
31
- protected flashEffect(x: number, y: number, ...parametersOrDuration: [parameters?: EffectParameters] | [duration?: number, parameters?: EffectParameters]): void;
32
- protected flashSpecialEffect(...args: [
29
+ flashCasterEffect(widget: Widget, ...parametersOrDuration: [parameters?: EffectParameters] | [duration?: number, parameters?: EffectParameters]): void;
30
+ flashTargetEffect(widget: Widget, ...parametersOrDuration: [parameters?: EffectParameters] | [duration?: number, parameters?: EffectParameters]): void;
31
+ flashAreaEffect(x: number, y: number, ...parametersOrDuration: [parameters?: EffectParameters] | [duration?: number, parameters?: EffectParameters]): void;
32
+ flashEffect(x: number, y: number, ...parametersOrDuration: [parameters?: EffectParameters] | [duration?: number, parameters?: EffectParameters]): void;
33
+ flashSpecialEffect(...args: [
33
34
  ...pointOrWidget: [x: number, y: number] | [widget: Widget],
34
35
  ...parametersOrDuration: [parameters?: EffectParameters] | [duration?: number, parameters?: EffectParameters]
35
36
  ]): void;
36
37
  private static MissileLaunchConfig;
37
38
  private get missileLaunchConfig();
39
+ protected launchMissile(source: Unit, ...args: [
40
+ ...pointOrWidget: [x: number, y: number] | [widget: Unit /** TODO: support Widget */],
41
+ ...parameters: NonNullable<Parameters["missileParameters"]>
42
+ ]): void;
38
43
  protected onCreate(): void;
39
44
  onValueChange(_value: ReadonlySubscribableAbilityDependentValue<string | number | boolean>): void;
40
45
  onMissileArrival(...parameters: NonNullable<Parameters["missileParameters"]>): void;