warscript 0.0.1-dev.24ac045 → 0.0.1-dev.256ff3b

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 (49) hide show
  1. package/core/types/frame.lua +10 -12
  2. package/core/types/player.lua +3 -1
  3. package/core/types/playerCamera.d.ts +2 -0
  4. package/core/types/playerCamera.lua +79 -5
  5. package/core/types/timer.d.ts +1 -0
  6. package/core/types/timer.lua +21 -2
  7. package/decl/native.d.ts +4 -2
  8. package/engine/behavior.d.ts +2 -0
  9. package/engine/behavior.lua +53 -27
  10. package/engine/behaviour/ability/emulate-impact.d.ts +1 -1
  11. package/engine/behaviour/ability/emulate-impact.lua +2 -1
  12. package/engine/behaviour/ability/restore-mana.d.ts +1 -1
  13. package/engine/behaviour/ability/restore-mana.lua +6 -6
  14. package/engine/behaviour/unit.d.ts +6 -2
  15. package/engine/behaviour/unit.lua +24 -2
  16. package/engine/buff.d.ts +0 -3
  17. package/engine/buff.lua +59 -80
  18. package/engine/internal/ability.d.ts +3 -1
  19. package/engine/internal/ability.lua +33 -11
  20. package/engine/internal/item+owner.lua +12 -6
  21. package/engine/internal/item.lua +10 -7
  22. package/engine/internal/misc/frame-coordinates.d.ts +2 -0
  23. package/engine/internal/misc/frame-coordinates.lua +21 -0
  24. package/engine/internal/misc/get-terrain-z.d.ts +2 -0
  25. package/engine/internal/misc/get-terrain-z.lua +11 -0
  26. package/engine/internal/misc/player-local-handle.d.ts +2 -0
  27. package/engine/internal/misc/player-local-handle.lua +5 -0
  28. package/engine/internal/unit+ability.lua +10 -1
  29. package/engine/internal/unit-missile-launch.lua +8 -1
  30. package/engine/internal/unit.d.ts +2 -3
  31. package/engine/internal/unit.lua +15 -14
  32. package/engine/object-data/auxiliary/armor-type.d.ts +11 -0
  33. package/engine/object-data/auxiliary/armor-type.lua +46 -0
  34. package/engine/object-data/entry/ability-type.lua +1 -3
  35. package/engine/object-data/entry/unit-type.d.ts +11 -2
  36. package/engine/object-data/entry/unit-type.lua +59 -1
  37. package/engine/object-field/ability.d.ts +3 -3
  38. package/engine/object-field/ability.lua +7 -6
  39. package/engine/object-field.d.ts +2 -2
  40. package/engine/object-field.lua +8 -6
  41. package/engine/text-tag.d.ts +1 -1
  42. package/engine/text-tag.lua +91 -17
  43. package/package.json +2 -2
  44. package/utility/callback-array.d.ts +13 -0
  45. package/utility/callback-array.lua +46 -0
  46. package/utility/functions.d.ts +4 -0
  47. package/utility/functions.lua +9 -0
  48. package/utility/lua-sets.d.ts +1 -0
  49. package/utility/lua-sets.lua +4 -0
@@ -15,6 +15,10 @@ local Event = ____event.Event
15
15
  local TriggerEvent = ____event.TriggerEvent
16
16
  local ____timer = require("core.types.timer")
17
17
  local Timer = ____timer.Timer
18
+ local ____frame_2Dcoordinates = require("engine.internal.misc.frame-coordinates")
19
+ local FRAME_MAX_Y = ____frame_2Dcoordinates.FRAME_MAX_Y
20
+ local FRAME_MIN_Y = ____frame_2Dcoordinates.FRAME_MIN_Y
21
+ local getFrameMinXMaxX = ____frame_2Dcoordinates.getFrameMinXMaxX
18
22
  local frameClick = BlzFrameClick
19
23
  local frameGetEnable = BlzFrameGetEnable
20
24
  local frameIsVisible = BlzFrameIsVisible
@@ -344,27 +348,21 @@ __TS__ObjectDefineProperty(
344
348
  Frame,
345
349
  "minX",
346
350
  {get = function(self)
347
- local w = BlzGetLocalClientWidth()
348
- local h = BlzGetLocalClientHeight()
349
- local width4by3 = (w - h / 600 * 800) / 2
350
- local pxtodpi = 0.6 / h
351
- return -width4by3 * pxtodpi
351
+ local minX = getFrameMinXMaxX()
352
+ return minX
352
353
  end}
353
354
  )
354
355
  __TS__ObjectDefineProperty(
355
356
  Frame,
356
357
  "maxX",
357
358
  {get = function(self)
358
- local w = BlzGetLocalClientWidth()
359
- local h = BlzGetLocalClientHeight()
360
- local width4by3 = (w - h / 600 * 800) / 2
361
- local pxtodpi = 0.6 / h
362
- return (-width4by3 + w) * pxtodpi
359
+ local ____, maxX = getFrameMinXMaxX()
360
+ return maxX
363
361
  end}
364
362
  )
365
363
  Frame.centerX = 0.4
366
- Frame.minY = 0
367
- Frame.maxY = 0.6
364
+ Frame.minY = FRAME_MIN_Y
365
+ Frame.maxY = FRAME_MAX_Y
368
366
  Frame.centerY = 0.3
369
367
  __TS__SetDescriptor(
370
368
  Frame.prototype,
@@ -21,6 +21,8 @@ local ____exception = require("exception")
21
21
  local IllegalStateException = ____exception.IllegalStateException
22
22
  local ____math = require("math")
23
23
  local MAXIMUM_INTEGER = ____math.MAXIMUM_INTEGER
24
+ local ____player_2Dlocal_2Dhandle = require("engine.internal.misc.player-local-handle")
25
+ local PLAYER_LOCAL_HANDLE = ____player_2Dlocal_2Dhandle.PLAYER_LOCAL_HANDLE
24
26
  local getPlayerColor = GetPlayerColor
25
27
  local getPlayerName = GetPlayerName
26
28
  local getPlayerTechCount = GetPlayerTechCount
@@ -249,7 +251,7 @@ Player.all = (function()
249
251
  end
250
252
  return all
251
253
  end)()
252
- Player["local"] = ____exports.Player:of(GetLocalPlayer())
254
+ Player["local"] = ____exports.Player:of(PLAYER_LOCAL_HANDLE)
253
255
  Player.neutralPassive = ____exports.Player.all[PLAYER_NEUTRAL_PASSIVE + 1]
254
256
  Player.neutralAggressive = ____exports.Player.all[PLAYER_NEUTRAL_AGGRESSIVE + 1]
255
257
  Player.neutralVictim = ____exports.Player.all[bj_PLAYER_NEUTRAL_VICTIM + 1]
@@ -1,4 +1,5 @@
1
1
  /** @noSelfInFile */
2
+ import type { Unit } from "../../engine/internal/unit";
2
3
  export declare class PlayerCamera {
3
4
  private readonly player;
4
5
  private readonly isLocal;
@@ -28,5 +29,6 @@ export declare class PlayerCamera {
28
29
  get roll(): number;
29
30
  set roll(v: number);
30
31
  reset(): void;
32
+ static isUnitInView(unit: Unit): boolean;
31
33
  static of(player: jplayer): PlayerCamera;
32
34
  }
@@ -3,33 +3,49 @@ local __TS__Class = ____lualib.__TS__Class
3
3
  local __TS__New = ____lualib.__TS__New
4
4
  local __TS__SetDescriptor = ____lualib.__TS__SetDescriptor
5
5
  local ____exports = {}
6
+ local ____timer = require("core.types.timer")
7
+ local Timer = ____timer.Timer
8
+ local ____player_2Dlocal_2Dhandle = require("engine.internal.misc.player-local-handle")
9
+ local PLAYER_LOCAL_HANDLE = ____player_2Dlocal_2Dhandle.PLAYER_LOCAL_HANDLE
10
+ local ____preconditions = require("utility.preconditions")
11
+ local check = ____preconditions.check
12
+ local ____frame_2Dcoordinates = require("engine.internal.misc.frame-coordinates")
13
+ local FRAME_MAX_Y = ____frame_2Dcoordinates.FRAME_MAX_Y
14
+ local FRAME_MIN_Y = ____frame_2Dcoordinates.FRAME_MIN_Y
15
+ local getFrameMinXMaxX = ____frame_2Dcoordinates.getFrameMinXMaxX
6
16
  local getHandleId = GetHandleId
7
17
  local setCameraField = SetCameraField
8
18
  local getCameraField = GetCameraField
9
19
  local setCameraPosition = SetCameraPosition
20
+ local getCameraEyePositionX = GetCameraEyePositionX
21
+ local getCameraEyePositionY = GetCameraEyePositionY
22
+ local getCameraEyePositionZ = GetCameraEyePositionZ
10
23
  local getCameraTargetPositionX = GetCameraTargetPositionX
11
24
  local getCameraTargetPositionY = GetCameraTargetPositionY
12
25
  local resetToGameCamera = ResetToGameCamera
26
+ local cos = math.cos
13
27
  local deg = math.deg
14
- local localPlayer = GetLocalPlayer()
28
+ local sin = math.sin
15
29
  local memoized = {}
16
30
  ____exports.PlayerCamera = __TS__Class()
17
31
  local PlayerCamera = ____exports.PlayerCamera
18
32
  PlayerCamera.name = "PlayerCamera"
19
33
  function PlayerCamera.prototype.____constructor(self, player)
20
34
  local id = getHandleId(player)
21
- if memoized[id] then
22
- error("Double-constructor run player camera!")
23
- end
35
+ check(memoized[id] == nil)
24
36
  memoized[id] = self
25
37
  self.player = player
26
- self.isLocal = player == localPlayer
38
+ self.isLocal = player == PLAYER_LOCAL_HANDLE
27
39
  end
28
40
  function PlayerCamera.prototype.reset(self)
29
41
  if self.isLocal then
30
42
  resetToGameCamera(0)
31
43
  end
32
44
  end
45
+ function PlayerCamera.isUnitInView(self, unit)
46
+ local ____, ____, isInView = ____exports.worldCoordinatesToFrame(unit.x, unit.y, unit.z)
47
+ return isInView
48
+ end
33
49
  function PlayerCamera.of(self, player)
34
50
  return memoized[getHandleId(player)] or __TS__New(____exports.PlayerCamera, player)
35
51
  end
@@ -159,4 +175,62 @@ __TS__SetDescriptor(
159
175
  },
160
176
  true
161
177
  )
178
+ local cameraEyeX = 0
179
+ local cameraEyeY = 0
180
+ local cameraEyeZ = 0
181
+ local cameraAngleOfAttack = 0
182
+ local cameraAngleOfAttackCos = 0
183
+ local cameraAngleOfAttackSin = 0
184
+ local cameraRotation = 0
185
+ local cameraRotationCos = 0
186
+ local cameraRotationSin = 0
187
+ local cameraAngleOfAttackCosRotationCos = 0
188
+ local cameraAngleOfAttackCosRotationSin = 0
189
+ local cameraAngleOfAttackSinRotationCos = 0
190
+ local cameraAngleOfAttackSinRotationSin = 0
191
+ local yCenterScreenShift = 0
192
+ local scaleFactor = 0
193
+ local frameMinX = 0
194
+ local frameMaxX = 0
195
+ local isCameraViewPrecalculated = false
196
+ local function precalculateCameraView()
197
+ cameraEyeX = getCameraEyePositionX()
198
+ cameraEyeY = getCameraEyePositionY()
199
+ cameraEyeZ = getCameraEyePositionZ()
200
+ cameraAngleOfAttack = getCameraField(CAMERA_FIELD_ANGLE_OF_ATTACK)
201
+ cameraAngleOfAttackCos = cos(cameraAngleOfAttack)
202
+ cameraAngleOfAttackSin = sin(cameraAngleOfAttack)
203
+ cameraRotation = getCameraField(CAMERA_FIELD_ROTATION)
204
+ cameraRotationCos = cos(cameraRotation)
205
+ cameraRotationSin = sin(cameraRotation)
206
+ cameraAngleOfAttackCosRotationCos = cameraAngleOfAttackCos * cameraRotationCos
207
+ cameraAngleOfAttackCosRotationSin = cameraAngleOfAttackCos * cameraRotationSin
208
+ cameraAngleOfAttackSinRotationCos = cameraAngleOfAttackSin * cameraRotationCos
209
+ cameraAngleOfAttackSinRotationSin = cameraAngleOfAttackSin * cameraRotationSin
210
+ yCenterScreenShift = 0.1284 * cameraAngleOfAttackCos
211
+ local cameraFieldOfView = getCameraField(CAMERA_FIELD_FIELD_OF_VIEW)
212
+ scaleFactor = 0.0524 * cameraFieldOfView ^ 3 - 0.0283 * cameraFieldOfView ^ 2 + 1.061 * cameraFieldOfView
213
+ frameMinX, frameMaxX = getFrameMinXMaxX()
214
+ isCameraViewPrecalculated = true
215
+ end
216
+ Timer.onPeriod[1 / 64]:addListener(
217
+ 4,
218
+ function()
219
+ isCameraViewPrecalculated = false
220
+ end
221
+ )
222
+ ---
223
+ -- @internal For use by internal systems only.
224
+ ____exports.worldCoordinatesToFrame = function(x, y, z)
225
+ if not isCameraViewPrecalculated then
226
+ precalculateCameraView()
227
+ end
228
+ local dx = x - cameraEyeX
229
+ local dy = y - cameraEyeY
230
+ local dz = z - cameraEyeZ
231
+ local xPrime = scaleFactor * (-cameraAngleOfAttackCosRotationCos * dx - cameraAngleOfAttackCosRotationSin * dy - cameraAngleOfAttackSin * dz)
232
+ local frameX = 0.4 + (cameraRotationCos * dy - cameraRotationSin * dx) / xPrime
233
+ local frameY = 0.42625 - yCenterScreenShift + (cameraAngleOfAttackSinRotationCos * dx + cameraAngleOfAttackSinRotationSin * dy - cameraAngleOfAttackCos * dz) / xPrime
234
+ return frameX, frameY, xPrime < 0 and frameX >= frameMinX and frameX <= frameMaxX and frameY >= FRAME_MIN_Y and frameY <= FRAME_MAX_Y
235
+ end
162
236
  return ____exports
@@ -22,6 +22,7 @@ export declare class Timer extends AbstractDestroyable {
22
22
  pause(): void;
23
23
  resume(): void;
24
24
  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;
25
26
  static run<Args extends any[]>(callback: (this: void, ...args: Args) => void, ...args: Args): void;
26
27
  static simple<Args extends any[]>(timeout: number, callback: (...args: Args) => void, ...args: Args): Timer;
27
28
  static periodic<Args extends any[]>(period: number, callback: (this: void, timer: Timer, ...args: Args) => void, ...args: Args): Timer;
@@ -12,6 +12,10 @@ local ____objectPool = require("util.objectPool")
12
12
  local ObjectPool = ____objectPool.ObjectPool
13
13
  local ____destroyable = require("destroyable")
14
14
  local AbstractDestroyable = ____destroyable.AbstractDestroyable
15
+ local ____callback_2Darray = require("utility.callback-array")
16
+ local addCallback = ____callback_2Darray.addCallback
17
+ local callbackArray = ____callback_2Darray.callbackArray
18
+ local consumeCallbacks = ____callback_2Darray.consumeCallbacks
15
19
  local createTimer = CreateTimer
16
20
  local timerStart = TimerStart
17
21
  local pauseTimer = PauseTimer
@@ -24,6 +28,7 @@ local getHandleId = GetHandleId
24
28
  local ____pcall = _G.pcall
25
29
  local ____print = _G.print
26
30
  local select = _G.select
31
+ local ____type = _G.type
27
32
  local safeCall = warpack.safeCall
28
33
  local corunning = coroutine.running
29
34
  local coresume = coroutine.resume
@@ -48,6 +53,12 @@ local function timerSafeCall()
48
53
  end
49
54
  end
50
55
  end
56
+ local zeroTimerScheduled = false
57
+ local zeroTimerCallbacks = callbackArray()
58
+ local function invokeZeroTimerCallbacks()
59
+ zeroTimerScheduled = false
60
+ consumeCallbacks(zeroTimerCallbacks)
61
+ end
51
62
  ____exports.Timer = __TS__Class()
52
63
  local Timer = ____exports.Timer
53
64
  Timer.name = "Timer"
@@ -81,8 +92,16 @@ end
81
92
  function Timer.create(self)
82
93
  return __TS__New(____exports.Timer)
83
94
  end
84
- function Timer.run(self, callback, ...)
85
- ____exports.Timer:simple(0, callback, ...)
95
+ function Timer.run(self, objectOrCallback, keyOrFirstArg, ...)
96
+ if not zeroTimerScheduled then
97
+ zeroTimerScheduled = true
98
+ ____exports.Timer:simple(0, invokeZeroTimerCallbacks)
99
+ end
100
+ if ____type(objectOrCallback) == "function" then
101
+ addCallback(zeroTimerCallbacks, objectOrCallback, keyOrFirstArg, ...)
102
+ else
103
+ addCallback(zeroTimerCallbacks, objectOrCallback[keyOrFirstArg], objectOrCallback, ...)
104
+ end
86
105
  end
87
106
  function Timer.simple(self, timeout, callback, ...)
88
107
  local timer = __TS__New(____exports.Timer)
package/decl/native.d.ts CHANGED
@@ -388,13 +388,15 @@ declare interface jmovetype extends jhandle {
388
388
  declare interface jtargetflag extends jhandle {
389
389
  __jtargetflag: never
390
390
  }
391
- declare interface jarmortype extends jhandle {
391
+ declare type jarmortype = symbol &
392
+ jhandle & {
392
393
  __jarmortype: never
393
394
  }
394
395
  declare interface jheroattribute extends jhandle {
395
396
  __jheroattribute: never
396
397
  }
397
- declare interface jdefensetype extends jhandle {
398
+ declare type jdefensetype = symbol &
399
+ jhandle & {
398
400
  __jdefensetype: never
399
401
  }
400
402
  declare interface jregentype extends jhandle {
@@ -24,5 +24,7 @@ export declare abstract class Behavior<T extends AnyNotNil, PeriodicActionParame
24
24
  static forFirst<T extends Behavior<AnyNotNil>, ConstructorParameters extends any[], K extends KeysOfType<T, (this: T, ...args: any) => any>>(this: BehaviorConstructor<T, ConstructorParameters>, object: T extends Behavior<infer Object> ? Object : never, count: number, key: K, ...parameters: T[K] extends (this: T, ...args: any) => any ? Parameters<T[K]> : never): number;
25
25
  static forAll<T extends Behavior<AnyNotNil>, ConstructorParameters extends any[], ConsumerParameters extends any[]>(this: BehaviorConstructor<T, ConstructorParameters>, object: T extends Behavior<infer Object> ? Object : never, consumer: (this: void, behavior: T, ...parameters: ConsumerParameters) => unknown, ...parameters: ConsumerParameters): number;
26
26
  static forAll<T extends Behavior<AnyNotNil>, ConstructorParameters extends any[], K extends KeysOfType<T, (this: T, ...args: any) => any>>(this: BehaviorConstructor<T, ConstructorParameters>, object: T extends Behavior<infer Object> ? Object : never, key: K, ...parameters: T[K] extends (this: T, ...args: any) => any ? Parameters<T[K]> : never): number;
27
+ static reduce<T extends Behavior<AnyNotNil>, ConstructorParameters extends any[], ConsumerParameters extends any[], Accumulator, R>(this: BehaviorConstructor<T, ConstructorParameters>, object: T extends Behavior<infer Object> ? Object : never, operation: (this: void, accumulator: Accumulator, value: R) => Accumulator, initial: Accumulator, consumer: (this: void, behavior: T, ...parameters: ConsumerParameters) => R, ...parameters: ConsumerParameters): Accumulator;
28
+ static reduce<T extends Behavior<AnyNotNil>, ConstructorParameters extends any[], Accumulator, R, K extends KeysOfType<T, (this: T, ...args: any) => R>>(this: BehaviorConstructor<T, ConstructorParameters>, object: T extends Behavior<infer Object> ? Object : never, operation: (this: void, accumulator: Accumulator, value: R) => Accumulator, initial: Accumulator, key: K, ...parameters: T[K] extends (this: T, ...args: any) => R ? Parameters<T[K]> : never): Accumulator;
27
29
  }
28
30
  export {};
@@ -1,18 +1,52 @@
1
1
  local ____lualib = require("lualib_bundle")
2
+ local __TS__InstanceOf = ____lualib.__TS__InstanceOf
2
3
  local __TS__Class = ____lualib.__TS__Class
3
4
  local __TS__ClassExtends = ____lualib.__TS__ClassExtends
4
- local __TS__InstanceOf = ____lualib.__TS__InstanceOf
5
5
  local ____exports = {}
6
6
  local ____destroyable = require("destroyable")
7
7
  local AbstractDestroyable = ____destroyable.AbstractDestroyable
8
8
  local ____timer = require("core.types.timer")
9
9
  local Timer = ____timer.Timer
10
+ local ____functions = require("utility.functions")
11
+ local increment = ____functions.increment
10
12
  local safeCall = warpack.safeCall
11
13
  local firstBehaviorByObject = {}
12
14
  local lastBehaviorByObject = {}
13
15
  local function invokeBehaviorOnPeriod(behavior, ...)
14
16
  behavior.onPeriod(behavior, ...)
15
17
  end
18
+ local function reduceBehaviors(behaviorConstructor, object, operation, initial, consumerOrKey, ...)
19
+ local accumulator = initial
20
+ local behavior = firstBehaviorByObject[object]
21
+ if behavior ~= nil then
22
+ if type(consumerOrKey) == "function" then
23
+ repeat
24
+ do
25
+ if __TS__InstanceOf(behavior, behaviorConstructor) then
26
+ local isSuccessful, result = safeCall(consumerOrKey, behavior, ...)
27
+ if isSuccessful then
28
+ accumulator = operation(accumulator, result)
29
+ end
30
+ end
31
+ behavior = behavior[1]
32
+ end
33
+ until not (behavior ~= nil)
34
+ else
35
+ repeat
36
+ do
37
+ if __TS__InstanceOf(behavior, behaviorConstructor) then
38
+ local isSuccessful, result = safeCall(behavior[consumerOrKey], behavior, ...)
39
+ if isSuccessful then
40
+ accumulator = operation(accumulator, result)
41
+ end
42
+ end
43
+ behavior = behavior[1]
44
+ end
45
+ until not (behavior ~= nil)
46
+ end
47
+ end
48
+ return accumulator
49
+ end
16
50
  ____exports.Behavior = __TS__Class()
17
51
  local Behavior = ____exports.Behavior
18
52
  Behavior.name = "Behavior"
@@ -151,31 +185,23 @@ function Behavior.forFirst(self, object, count, consumerOrKey, ...)
151
185
  return behaviorsCount
152
186
  end
153
187
  function Behavior.forAll(self, object, consumerOrKey, ...)
154
- local behaviorsCount = 0
155
- local behavior = firstBehaviorByObject[object]
156
- if behavior ~= nil then
157
- if type(consumerOrKey) == "function" then
158
- repeat
159
- do
160
- if __TS__InstanceOf(behavior, self) then
161
- safeCall(consumerOrKey, behavior, ...)
162
- behaviorsCount = behaviorsCount + 1
163
- end
164
- behavior = behavior[1]
165
- end
166
- until not (behavior ~= nil)
167
- else
168
- repeat
169
- do
170
- if __TS__InstanceOf(behavior, self) then
171
- safeCall(behavior[consumerOrKey], behavior, ...)
172
- behaviorsCount = behaviorsCount + 1
173
- end
174
- behavior = behavior[1]
175
- end
176
- until not (behavior ~= nil)
177
- end
178
- end
179
- return behaviorsCount
188
+ return reduceBehaviors(
189
+ self,
190
+ object,
191
+ increment,
192
+ 0,
193
+ consumerOrKey,
194
+ ...
195
+ )
196
+ end
197
+ function Behavior.reduce(self, object, operation, initial, consumerOrKey, ...)
198
+ return reduceBehaviors(
199
+ self,
200
+ object,
201
+ operation,
202
+ initial,
203
+ consumerOrKey,
204
+ ...
205
+ )
180
206
  end
181
207
  return ____exports
@@ -2,5 +2,5 @@
2
2
  import { AbilityBehavior } from "../ability";
3
3
  import { Unit } from "../../internal/unit";
4
4
  export declare abstract class EmulateImpactAbilityBehavior extends AbilityBehavior {
5
- protected emulateImpact(caster: Unit): void;
5
+ protected emulateImpact(caster: Unit): boolean;
6
6
  }
@@ -28,7 +28,7 @@ function EmulateImpactAbilityBehavior.prototype.emulateImpact(self, caster)
28
28
  local manaCost = self:resolveCurrentAbilityDependentValue(MANA_COST_ABILITY_INTEGER_LEVEL_FIELD)
29
29
  local cooldown = self:resolveCurrentAbilityDependentValue(COOLDOWN_ABILITY_FLOAT_LEVEL_FIELD)
30
30
  if self.ability.cooldownRemaining ~= 0 or caster.mana < manaCost or __TS__InstanceOf(self.ability, UnitAbility) and self.ability.isDisabled then
31
- return
31
+ return false
32
32
  end
33
33
  caster.mana = caster.mana - manaCost
34
34
  self.ability.cooldownRemaining = max(cooldown, MINIMUM_POSITIVE_NORMALIZED_FLOAT)
@@ -38,5 +38,6 @@ function EmulateImpactAbilityBehavior.prototype.emulateImpact(self, caster)
38
38
  Sound3D:playFromLabel(soundPresetId, SoundSettings.Ability, caster)
39
39
  end
40
40
  Event.invoke(Unit.abilityImpactEvent, caster, self.ability)
41
+ return true
41
42
  end
42
43
  return ____exports
@@ -8,7 +8,7 @@ export declare class RestoreManaSelfAbilityBehavior extends AbilityBehavior {
8
8
  constructor(ability: Ability, mana: AbilityDependentValue<number>);
9
9
  onImpact(caster: Unit): void;
10
10
  }
11
- export declare class RestoreManaAbilityBehavior extends AbilityBehavior {
11
+ export declare class RestoreManaTargetAbilityBehavior extends AbilityBehavior {
12
12
  private readonly mana;
13
13
  constructor(ability: Ability, mana: AbilityDependentValue<number>);
14
14
  onUnitTargetImpact(caster: Unit, target: Unit): void;
@@ -15,15 +15,15 @@ end
15
15
  function RestoreManaSelfAbilityBehavior.prototype.onImpact(self, caster)
16
16
  caster.mana = caster.mana + self:resolveCurrentAbilityDependentValue(self.mana)
17
17
  end
18
- ____exports.RestoreManaAbilityBehavior = __TS__Class()
19
- local RestoreManaAbilityBehavior = ____exports.RestoreManaAbilityBehavior
20
- RestoreManaAbilityBehavior.name = "RestoreManaAbilityBehavior"
21
- __TS__ClassExtends(RestoreManaAbilityBehavior, AbilityBehavior)
22
- function RestoreManaAbilityBehavior.prototype.____constructor(self, ability, mana)
18
+ ____exports.RestoreManaTargetAbilityBehavior = __TS__Class()
19
+ local RestoreManaTargetAbilityBehavior = ____exports.RestoreManaTargetAbilityBehavior
20
+ RestoreManaTargetAbilityBehavior.name = "RestoreManaTargetAbilityBehavior"
21
+ __TS__ClassExtends(RestoreManaTargetAbilityBehavior, AbilityBehavior)
22
+ function RestoreManaTargetAbilityBehavior.prototype.____constructor(self, ability, mana)
23
23
  AbilityBehavior.prototype.____constructor(self, ability)
24
24
  self.mana = mana
25
25
  end
26
- function RestoreManaAbilityBehavior.prototype.onUnitTargetImpact(self, caster, target)
26
+ function RestoreManaTargetAbilityBehavior.prototype.onUnitTargetImpact(self, caster, target)
27
27
  target.mana = target.mana + self:resolveCurrentAbilityDependentValue(self.mana)
28
28
  end
29
29
  return ____exports
@@ -11,13 +11,17 @@ import { Destructor } from "../../destroyable";
11
11
  import type { Widget } from "../../core/types/widget";
12
12
  import { Destructable } from "../../core/types/destructable";
13
13
  import type { Buff } from "../buff";
14
+ import { UnitBonusType } from "../internal/unit/bonus";
14
15
  export type UnitBehaviorConstructor<Args extends any[]> = new (unit: Unit, ...args: Args) => UnitBehavior;
15
16
  export declare abstract class UnitBehavior<PeriodicActionParameters extends any[] = any[]> extends Behavior<Unit, PeriodicActionParameters> {
17
+ readonly sourceAbilityBehavior?: AbilityBehavior;
18
+ private _bonusIdByBonusType?;
16
19
  constructor(unit: Unit);
17
20
  protected onDestroy(): Destructor;
18
- readonly sourceAbilityBehavior?: AbilityBehavior;
19
21
  get unit(): Unit;
20
- registerInRangeUnitEvent<T extends string, Args extends any[]>(this: UnitBehavior<PeriodicActionParameters> & Record<T, (this: this, ...args: Args) => unknown>, event: Event<[...Args]>, extractUnit: (...args: Args) => Unit | undefined, range: number, listener: T): void;
22
+ protected getUnitBonus(bonusType: UnitBonusType): number;
23
+ protected addOrUpdateOrRemoveUnitBonus(bonusType: UnitBonusType, value: number): void;
24
+ protected registerInRangeUnitEvent<T extends string, Args extends any[]>(this: UnitBehavior<PeriodicActionParameters> & Record<T, (this: this, ...args: Args) => unknown>, event: Event<[...Args]>, extractUnit: (...args: Args) => Unit | undefined, range: number, listener: T): void;
21
25
  onImmediateOrder(orderId: number): void;
22
26
  onTargetOrder(orderId: number, target: Widget): void;
23
27
  onPointOrder(orderId: number, x: number, y: number): void;
@@ -17,6 +17,10 @@ local getOrPut = ____lua_2Dmaps.getOrPut
17
17
  local mutableLuaMap = ____lua_2Dmaps.mutableLuaMap
18
18
  local ____lua_2Dsets = require("utility.lua-sets")
19
19
  local mutableLuaSet = ____lua_2Dsets.mutableLuaSet
20
+ local ____bonus = require("engine.internal.unit.bonus")
21
+ local addOrUpdateOrRemoveUnitBonus = ____bonus.addOrUpdateOrRemoveUnitBonus
22
+ local getUnitBonus = ____bonus.getUnitBonus
23
+ local removeUnitBonus = ____bonus.removeUnitBonus
20
24
  local behaviorsByEvent = {}
21
25
  local rangeByBehaviorByEvent = {}
22
26
  local listenerByBehaviorByEvent = {}
@@ -47,8 +51,26 @@ function UnitBehavior.prototype.onDestroy(self)
47
51
  end
48
52
  eventsByBehavior[self] = nil
49
53
  end
54
+ if self._bonusIdByBonusType ~= nil then
55
+ for bonusType, bonusId in pairs(self._bonusIdByBonusType) do
56
+ removeUnitBonus(self.object, bonusType, bonusId)
57
+ end
58
+ end
50
59
  return Behavior.prototype.onDestroy(self)
51
60
  end
61
+ function UnitBehavior.prototype.getUnitBonus(self, bonusType)
62
+ local ____opt_6 = self._bonusIdByBonusType
63
+ local bonusId = ____opt_6 and ____opt_6[bonusType]
64
+ return bonusId == nil and 0 or getUnitBonus(self.object, bonusType, bonusId)
65
+ end
66
+ function UnitBehavior.prototype.addOrUpdateOrRemoveUnitBonus(self, bonusType, value)
67
+ local bonusIdByBonusType = self._bonusIdByBonusType
68
+ if bonusIdByBonusType == nil then
69
+ bonusIdByBonusType = {}
70
+ self._bonusIdByBonusType = bonusIdByBonusType
71
+ end
72
+ bonusIdByBonusType[bonusType] = addOrUpdateOrRemoveUnitBonus(self.object, bonusType, bonusIdByBonusType[bonusType], value)
73
+ end
52
74
  function UnitBehavior.prototype.registerInRangeUnitEvent(self, event, extractUnit, range, listener)
53
75
  local rangeByBehavior = getOrPut(rangeByBehaviorByEvent, event, mutableLuaMap)
54
76
  rangeByBehavior[self] = range
@@ -65,8 +87,8 @@ function UnitBehavior.prototype.registerInRangeUnitEvent(self, event, extractUni
65
87
  for behavior in pairs(behaviors) do
66
88
  local range = rangeByBehavior[behavior]
67
89
  if range ~= nil and unit:getCollisionDistanceTo(behavior.unit) <= range then
68
- local ____self_6 = behavior
69
- ____self_6[listenerByBehavior[behavior]](____self_6, ...)
90
+ local ____self_8 = behavior
91
+ ____self_8[listenerByBehavior[behavior]](____self_8, ...)
70
92
  end
71
93
  end
72
94
  end
package/engine/buff.d.ts CHANGED
@@ -201,11 +201,8 @@ export declare class Buff<AdditionalParameters extends Prohibit<Record<string, a
201
201
  private readonly _spellStealPriority?;
202
202
  private readonly _learnLevelMinimum?;
203
203
  private readonly [BuffPropertyKey.MISS_PROBABILITY]?;
204
- private _bonusIdByBonusType?;
205
204
  private readonly _abilityTypeIds?;
206
205
  private _behaviors?;
207
- private getUnitBonus;
208
- private addOrUpdateOrRemoveUnitBonus;
209
206
  constructor(target: Unit, ...parameters: BuffConstructorParameters<AdditionalParameters>);
210
207
  get level(): number;
211
208
  get remainingDamageOverDuration(): number;