warscript 0.0.1-dev.d1983c6 → 0.0.1-dev.d1b563b
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.
- package/core/types/frame.lua +14 -9
- package/core/types/playerCamera.lua +44 -0
- package/core/types/tileCell.d.ts +9 -0
- package/core/types/tileCell.lua +92 -0
- package/core/types/timer.lua +16 -2
- package/decl/native.d.ts +2 -2
- package/engine/behavior.d.ts +3 -0
- package/engine/behavior.lua +53 -0
- package/engine/behaviour/unit.d.ts +6 -2
- package/engine/behaviour/unit.lua +24 -2
- package/engine/buff.d.ts +0 -3
- package/engine/buff.lua +59 -80
- package/engine/internal/ability.d.ts +3 -1
- package/engine/internal/ability.lua +26 -9
- package/engine/internal/item+owner.lua +12 -6
- package/engine/internal/item.d.ts +1 -3
- package/engine/internal/item.lua +22 -23
- package/engine/internal/unit/ability.lua +1 -1
- package/engine/internal/unit+ability.lua +10 -1
- package/engine/internal/unit.d.ts +3 -3
- package/engine/internal/unit.lua +19 -17
- package/engine/object-field/ability.d.ts +3 -3
- package/engine/object-field/ability.lua +7 -6
- package/engine/object-field.d.ts +2 -2
- package/engine/object-field.lua +8 -6
- package/engine/random.d.ts +9 -0
- package/engine/random.lua +13 -0
- package/package.json +2 -2
- package/patch-lualib.lua +1 -1
- package/utility/callback-array.d.ts +13 -0
- package/utility/callback-array.lua +46 -0
- package/utility/lua-maps.d.ts +6 -1
- package/utility/lua-maps.lua +20 -2
package/core/types/frame.lua
CHANGED
|
@@ -19,13 +19,16 @@ local ____frame_2Dcoordinates = require("engine.internal.misc.frame-coordinates"
|
|
|
19
19
|
local FRAME_MAX_Y = ____frame_2Dcoordinates.FRAME_MAX_Y
|
|
20
20
|
local FRAME_MIN_Y = ____frame_2Dcoordinates.FRAME_MIN_Y
|
|
21
21
|
local getFrameMinXMaxX = ____frame_2Dcoordinates.getFrameMinXMaxX
|
|
22
|
+
local ____playerCamera = require("core.types.playerCamera")
|
|
23
|
+
local frameCoordinatesToWorld = ____playerCamera.frameCoordinatesToWorld
|
|
24
|
+
local worldCoordinatesToFrame = ____playerCamera.worldCoordinatesToFrame
|
|
25
|
+
local ____get_2Dterrain_2Dz = require("engine.internal.misc.get-terrain-z")
|
|
26
|
+
local getTerrainZ = ____get_2Dterrain_2Dz.getTerrainZ
|
|
22
27
|
local frameClick = BlzFrameClick
|
|
23
28
|
local frameGetEnable = BlzFrameGetEnable
|
|
24
29
|
local frameIsVisible = BlzFrameIsVisible
|
|
25
30
|
local frameSetEnable = BlzFrameSetEnable
|
|
26
31
|
local frameSetScale = BlzFrameSetScale
|
|
27
|
-
local getCameraTargetPositionX = GetCameraTargetPositionX
|
|
28
|
-
local getCameraTargetPositionY = GetCameraTargetPositionY
|
|
29
32
|
local ____rawget = _G.rawget
|
|
30
33
|
local rawset = _G.rawset
|
|
31
34
|
local invoke = Event.invoke
|
|
@@ -936,16 +939,19 @@ __TS__ObjectDefineProperty(
|
|
|
936
939
|
local event = __TS__New(Event)
|
|
937
940
|
local syncX = 0
|
|
938
941
|
local syncY = 0
|
|
939
|
-
local
|
|
940
|
-
local
|
|
942
|
+
local syncFrameX = 0
|
|
943
|
+
local syncFrameY = 0
|
|
941
944
|
local lastX = syncX
|
|
942
945
|
local lastY = syncY
|
|
943
946
|
self.onMouseMove:addListener(function(player, x, y)
|
|
944
947
|
if player.isLocal then
|
|
945
948
|
syncX = x
|
|
946
949
|
syncY = y
|
|
947
|
-
|
|
948
|
-
|
|
950
|
+
syncFrameX, syncFrameY = worldCoordinatesToFrame(
|
|
951
|
+
x,
|
|
952
|
+
y,
|
|
953
|
+
getTerrainZ(x, y)
|
|
954
|
+
)
|
|
949
955
|
lastX = x
|
|
950
956
|
lastY = y
|
|
951
957
|
invoke(event, x, y)
|
|
@@ -955,9 +961,8 @@ __TS__ObjectDefineProperty(
|
|
|
955
961
|
if syncX == 0 and syncY == 0 then
|
|
956
962
|
return
|
|
957
963
|
end
|
|
958
|
-
local x
|
|
959
|
-
|
|
960
|
-
if x ~= lastX or y ~= lastY then
|
|
964
|
+
local x, y, ____, isDefinite = frameCoordinatesToWorld(syncFrameX, syncFrameY)
|
|
965
|
+
if isDefinite and (x ~= lastX or y ~= lastY) then
|
|
961
966
|
lastX = x
|
|
962
967
|
lastY = y
|
|
963
968
|
invoke(event, x, y)
|
|
@@ -13,6 +13,8 @@ local ____frame_2Dcoordinates = require("engine.internal.misc.frame-coordinates"
|
|
|
13
13
|
local FRAME_MAX_Y = ____frame_2Dcoordinates.FRAME_MAX_Y
|
|
14
14
|
local FRAME_MIN_Y = ____frame_2Dcoordinates.FRAME_MIN_Y
|
|
15
15
|
local getFrameMinXMaxX = ____frame_2Dcoordinates.getFrameMinXMaxX
|
|
16
|
+
local ____get_2Dterrain_2Dz = require("engine.internal.misc.get-terrain-z")
|
|
17
|
+
local getTerrainZ = ____get_2Dterrain_2Dz.getTerrainZ
|
|
16
18
|
local getHandleId = GetHandleId
|
|
17
19
|
local setCameraField = SetCameraField
|
|
18
20
|
local getCameraField = GetCameraField
|
|
@@ -26,6 +28,7 @@ local resetToGameCamera = ResetToGameCamera
|
|
|
26
28
|
local cos = math.cos
|
|
27
29
|
local deg = math.deg
|
|
28
30
|
local sin = math.sin
|
|
31
|
+
local sqrt = math.sqrt
|
|
29
32
|
local memoized = {}
|
|
30
33
|
____exports.PlayerCamera = __TS__Class()
|
|
31
34
|
local PlayerCamera = ____exports.PlayerCamera
|
|
@@ -233,4 +236,45 @@ ____exports.worldCoordinatesToFrame = function(x, y, z)
|
|
|
233
236
|
local frameY = 0.42625 - yCenterScreenShift + (cameraAngleOfAttackSinRotationCos * dx + cameraAngleOfAttackSinRotationSin * dy - cameraAngleOfAttackCos * dz) / xPrime
|
|
234
237
|
return frameX, frameY, xPrime < 0 and frameX >= frameMinX and frameX <= frameMaxX and frameY >= FRAME_MIN_Y and frameY <= FRAME_MAX_Y
|
|
235
238
|
end
|
|
239
|
+
---
|
|
240
|
+
-- @internal For use by internal systems only.
|
|
241
|
+
____exports.frameCoordinatesToWorld = function(x, y)
|
|
242
|
+
if not isCameraViewPrecalculated then
|
|
243
|
+
precalculateCameraView()
|
|
244
|
+
end
|
|
245
|
+
local a = (x - 0.4) * scaleFactor
|
|
246
|
+
local b = (0.42625 - yCenterScreenShift - y) * scaleFactor
|
|
247
|
+
local nx = 1 / sqrt(1 + a * a + b * b)
|
|
248
|
+
local ny = sqrt(1 - (1 + b * b) * nx * nx)
|
|
249
|
+
local nz = sqrt(1 - nx * nx - ny * ny)
|
|
250
|
+
if a > 0 then
|
|
251
|
+
ny = -ny
|
|
252
|
+
end
|
|
253
|
+
if b < 0 then
|
|
254
|
+
nz = -nz
|
|
255
|
+
end
|
|
256
|
+
local nxPrime = cameraAngleOfAttackCosRotationCos * nx - cameraRotationSin * ny + cameraAngleOfAttackSinRotationCos * nz
|
|
257
|
+
local nyPrime = cameraAngleOfAttackCosRotationSin * nx + cameraRotationCos * ny + cameraAngleOfAttackSinRotationSin * nz
|
|
258
|
+
local nzPrime = -cameraAngleOfAttackSin * nx + cameraAngleOfAttackCos * nz
|
|
259
|
+
local zGuess = getTerrainZ(cameraEyeX, cameraEyeY)
|
|
260
|
+
local xGuess = cameraEyeX + nxPrime * (cameraEyeZ - zGuess) / nzPrime
|
|
261
|
+
local yGuess = cameraEyeY + nyPrime * (cameraEyeZ - zGuess) / nzPrime
|
|
262
|
+
local zWorld = getTerrainZ(xGuess, yGuess)
|
|
263
|
+
local deltaZ = zWorld - zGuess
|
|
264
|
+
zGuess = zWorld
|
|
265
|
+
local zWorldOld = zWorld
|
|
266
|
+
local deltaZOld = deltaZ
|
|
267
|
+
local i = 0
|
|
268
|
+
while (deltaZ > 1 or deltaZ < -1) and i < 50 do
|
|
269
|
+
xGuess = cameraEyeX + nxPrime * (cameraEyeZ - zGuess) / nzPrime
|
|
270
|
+
yGuess = cameraEyeY + nyPrime * (cameraEyeZ - zGuess) / nzPrime
|
|
271
|
+
zWorld = getTerrainZ(xGuess, yGuess)
|
|
272
|
+
deltaZ = zWorld - zGuess
|
|
273
|
+
zGuess = (deltaZOld * zWorld - deltaZ * zWorldOld) / (deltaZOld - deltaZ)
|
|
274
|
+
zWorldOld = zWorld
|
|
275
|
+
deltaZOld = deltaZ
|
|
276
|
+
i = i + 1
|
|
277
|
+
end
|
|
278
|
+
return xGuess, yGuess, zWorld, i < 50
|
|
279
|
+
end
|
|
236
280
|
return ____exports
|
package/core/types/tileCell.d.ts
CHANGED
|
@@ -5,6 +5,15 @@ export declare class TileCell implements Readonly<Vec2> {
|
|
|
5
5
|
readonly y: number;
|
|
6
6
|
readonly z: undefined;
|
|
7
7
|
protected constructor(id: number, x: number, y: number, z: undefined);
|
|
8
|
+
get up(): TileCell;
|
|
9
|
+
get down(): TileCell;
|
|
10
|
+
get left(): TileCell;
|
|
11
|
+
get right(): TileCell;
|
|
12
|
+
get terrainTypeId(): number;
|
|
13
|
+
set terrainTypeId(terrainTypeId: number);
|
|
14
|
+
get terrainVariance(): number;
|
|
15
|
+
set terrainVariance(terrainVariance: number);
|
|
16
|
+
randomizeTerrainVariance(): void;
|
|
8
17
|
isInRangeOf(x: number, y: number, range: number): boolean;
|
|
9
18
|
isInRangeOf(tileCell: TileCell, range: number): boolean;
|
|
10
19
|
static getInRect(minX: number, minY: number, maxX: number, maxY: number): TileCell[];
|
package/core/types/tileCell.lua
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
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 = {}
|
|
6
|
+
local getTerrainType = GetTerrainType
|
|
7
|
+
local setTerrainType = SetTerrainType
|
|
8
|
+
local getTerrainVariance = GetTerrainVariance
|
|
5
9
|
local abs = math.abs
|
|
6
10
|
local ____type = math.type
|
|
7
11
|
local ult = math.ult
|
|
@@ -16,6 +20,18 @@ function TileCell.prototype.____constructor(self, id, x, y, z)
|
|
|
16
20
|
self.z = z
|
|
17
21
|
tileCellById[id] = self
|
|
18
22
|
end
|
|
23
|
+
function TileCell.prototype.randomizeTerrainVariance(self)
|
|
24
|
+
local x = self.x
|
|
25
|
+
local y = self.y
|
|
26
|
+
setTerrainType(
|
|
27
|
+
x,
|
|
28
|
+
y,
|
|
29
|
+
getTerrainType(x, y),
|
|
30
|
+
-1,
|
|
31
|
+
1,
|
|
32
|
+
1
|
|
33
|
+
)
|
|
34
|
+
end
|
|
19
35
|
function TileCell.prototype.isInRangeOf(self, x, y, range)
|
|
20
36
|
if range == nil then
|
|
21
37
|
range = y
|
|
@@ -97,4 +113,80 @@ function TileCell.of(x, y)
|
|
|
97
113
|
nil
|
|
98
114
|
)
|
|
99
115
|
end
|
|
116
|
+
__TS__SetDescriptor(
|
|
117
|
+
TileCell.prototype,
|
|
118
|
+
"up",
|
|
119
|
+
{get = function(self)
|
|
120
|
+
return ____exports.TileCell.of(self.x, self.y + 128)
|
|
121
|
+
end},
|
|
122
|
+
true
|
|
123
|
+
)
|
|
124
|
+
__TS__SetDescriptor(
|
|
125
|
+
TileCell.prototype,
|
|
126
|
+
"down",
|
|
127
|
+
{get = function(self)
|
|
128
|
+
return ____exports.TileCell.of(self.x, self.y - 128)
|
|
129
|
+
end},
|
|
130
|
+
true
|
|
131
|
+
)
|
|
132
|
+
__TS__SetDescriptor(
|
|
133
|
+
TileCell.prototype,
|
|
134
|
+
"left",
|
|
135
|
+
{get = function(self)
|
|
136
|
+
return ____exports.TileCell.of(self.x - 128, self.y)
|
|
137
|
+
end},
|
|
138
|
+
true
|
|
139
|
+
)
|
|
140
|
+
__TS__SetDescriptor(
|
|
141
|
+
TileCell.prototype,
|
|
142
|
+
"right",
|
|
143
|
+
{get = function(self)
|
|
144
|
+
return ____exports.TileCell.of(self.x + 128, self.y)
|
|
145
|
+
end},
|
|
146
|
+
true
|
|
147
|
+
)
|
|
148
|
+
__TS__SetDescriptor(
|
|
149
|
+
TileCell.prototype,
|
|
150
|
+
"terrainTypeId",
|
|
151
|
+
{
|
|
152
|
+
get = function(self)
|
|
153
|
+
return getTerrainType(self.x, self.y)
|
|
154
|
+
end,
|
|
155
|
+
set = function(self, terrainTypeId)
|
|
156
|
+
local x = self.x
|
|
157
|
+
local y = self.y
|
|
158
|
+
setTerrainType(
|
|
159
|
+
x,
|
|
160
|
+
y,
|
|
161
|
+
terrainTypeId,
|
|
162
|
+
getTerrainVariance(x, y),
|
|
163
|
+
1,
|
|
164
|
+
1
|
|
165
|
+
)
|
|
166
|
+
end
|
|
167
|
+
},
|
|
168
|
+
true
|
|
169
|
+
)
|
|
170
|
+
__TS__SetDescriptor(
|
|
171
|
+
TileCell.prototype,
|
|
172
|
+
"terrainVariance",
|
|
173
|
+
{
|
|
174
|
+
get = function(self)
|
|
175
|
+
return getTerrainVariance(self.x, self.y)
|
|
176
|
+
end,
|
|
177
|
+
set = function(self, terrainVariance)
|
|
178
|
+
local x = self.x
|
|
179
|
+
local y = self.y
|
|
180
|
+
setTerrainType(
|
|
181
|
+
x,
|
|
182
|
+
y,
|
|
183
|
+
getTerrainType(x, y),
|
|
184
|
+
terrainVariance,
|
|
185
|
+
1,
|
|
186
|
+
1
|
|
187
|
+
)
|
|
188
|
+
end
|
|
189
|
+
},
|
|
190
|
+
true
|
|
191
|
+
)
|
|
100
192
|
return ____exports
|
package/core/types/timer.lua
CHANGED
|
@@ -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
|
|
@@ -49,6 +53,12 @@ local function timerSafeCall()
|
|
|
49
53
|
end
|
|
50
54
|
end
|
|
51
55
|
end
|
|
56
|
+
local zeroTimerScheduled = false
|
|
57
|
+
local zeroTimerCallbacks = callbackArray()
|
|
58
|
+
local function invokeZeroTimerCallbacks()
|
|
59
|
+
zeroTimerScheduled = false
|
|
60
|
+
consumeCallbacks(zeroTimerCallbacks)
|
|
61
|
+
end
|
|
52
62
|
____exports.Timer = __TS__Class()
|
|
53
63
|
local Timer = ____exports.Timer
|
|
54
64
|
Timer.name = "Timer"
|
|
@@ -83,10 +93,14 @@ function Timer.create(self)
|
|
|
83
93
|
return __TS__New(____exports.Timer)
|
|
84
94
|
end
|
|
85
95
|
function Timer.run(self, objectOrCallback, keyOrFirstArg, ...)
|
|
96
|
+
if not zeroTimerScheduled then
|
|
97
|
+
zeroTimerScheduled = true
|
|
98
|
+
____exports.Timer:simple(0, invokeZeroTimerCallbacks)
|
|
99
|
+
end
|
|
86
100
|
if ____type(objectOrCallback) == "function" then
|
|
87
|
-
|
|
101
|
+
addCallback(zeroTimerCallbacks, objectOrCallback, keyOrFirstArg, ...)
|
|
88
102
|
else
|
|
89
|
-
|
|
103
|
+
addCallback(zeroTimerCallbacks, objectOrCallback[keyOrFirstArg], objectOrCallback, ...)
|
|
90
104
|
end
|
|
91
105
|
end
|
|
92
106
|
function Timer.simple(self, timeout, callback, ...)
|
package/decl/native.d.ts
CHANGED
|
@@ -5259,8 +5259,8 @@ declare function BlzRemoveAbilityStringLevelArrayField(
|
|
|
5259
5259
|
level: number,
|
|
5260
5260
|
value: string,
|
|
5261
5261
|
): boolean
|
|
5262
|
-
declare function BlzGetItemAbilityByIndex(whichItem: jitem, index: number): jability |
|
|
5263
|
-
declare function BlzGetItemAbility(whichItem: jitem, abilCode: number): jability |
|
|
5262
|
+
declare function BlzGetItemAbilityByIndex(whichItem: jitem, index: number): jability | undefined
|
|
5263
|
+
declare function BlzGetItemAbility(whichItem: jitem, abilCode: number): jability | undefined
|
|
5264
5264
|
declare function BlzItemAddAbility(whichItem: jitem, abilCode: number): boolean
|
|
5265
5265
|
declare function BlzGetItemBooleanField(whichItem: jitem, whichField: jitembooleanfield): boolean
|
|
5266
5266
|
declare function BlzGetItemIntegerField(whichItem: jitem, whichField: jitemintegerfield): number
|
package/engine/behavior.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/** @noSelfInFile */
|
|
2
2
|
import { AbstractDestroyable, Destructor } from "../destroyable";
|
|
3
|
+
import { Event } from "../event";
|
|
3
4
|
export type BehaviorConstructor<T extends Behavior<AnyNotNil>, Parameters extends any[] = any[]> = OmitConstructor<typeof Behavior<any>> & (abstract new (...parameters: Parameters) => T);
|
|
4
5
|
declare const enum BehaviorPropertyKey {
|
|
5
6
|
PREVIOUS_BEHAVIOR = 0,
|
|
@@ -13,6 +14,8 @@ export declare abstract class Behavior<T extends AnyNotNil, PeriodicActionParame
|
|
|
13
14
|
private [BehaviorPropertyKey.TIMER]?;
|
|
14
15
|
protected constructor(object: T);
|
|
15
16
|
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;
|
|
18
|
+
protected deregisterEvent(event: Event<any>): boolean;
|
|
16
19
|
protected onPeriod(...parameters: PeriodicActionParameters): void;
|
|
17
20
|
protected startPeriodicAction(interval: number, ...parameters: PeriodicActionParameters): void;
|
|
18
21
|
protected stopPeriodicAction(): void;
|
package/engine/behavior.lua
CHANGED
|
@@ -2,6 +2,7 @@ local ____lualib = require("lualib_bundle")
|
|
|
2
2
|
local __TS__InstanceOf = ____lualib.__TS__InstanceOf
|
|
3
3
|
local __TS__Class = ____lualib.__TS__Class
|
|
4
4
|
local __TS__ClassExtends = ____lualib.__TS__ClassExtends
|
|
5
|
+
local __TS__New = ____lualib.__TS__New
|
|
5
6
|
local ____exports = {}
|
|
6
7
|
local ____destroyable = require("destroyable")
|
|
7
8
|
local AbstractDestroyable = ____destroyable.AbstractDestroyable
|
|
@@ -9,6 +10,13 @@ local ____timer = require("core.types.timer")
|
|
|
9
10
|
local Timer = ____timer.Timer
|
|
10
11
|
local ____functions = require("utility.functions")
|
|
11
12
|
local increment = ____functions.increment
|
|
13
|
+
local ____linked_2Dset = require("utility.linked-set")
|
|
14
|
+
local LinkedSet = ____linked_2Dset.LinkedSet
|
|
15
|
+
local ____lua_2Dmaps = require("utility.lua-maps")
|
|
16
|
+
local getOrPut = ____lua_2Dmaps.getOrPut
|
|
17
|
+
local mutableLuaMap = ____lua_2Dmaps.mutableLuaMap
|
|
18
|
+
local ____lua_2Dsets = require("utility.lua-sets")
|
|
19
|
+
local mutableLuaSet = ____lua_2Dsets.mutableLuaSet
|
|
12
20
|
local safeCall = warpack.safeCall
|
|
13
21
|
local firstBehaviorByObject = {}
|
|
14
22
|
local lastBehaviorByObject = {}
|
|
@@ -47,6 +55,9 @@ local function reduceBehaviors(behaviorConstructor, object, operation, initial,
|
|
|
47
55
|
end
|
|
48
56
|
return accumulator
|
|
49
57
|
end
|
|
58
|
+
local behaviorsByEvent = {}
|
|
59
|
+
local listenerByBehaviorByEvent = {}
|
|
60
|
+
local eventsByBehavior = {}
|
|
50
61
|
____exports.Behavior = __TS__Class()
|
|
51
62
|
local Behavior = ____exports.Behavior
|
|
52
63
|
Behavior.name = "Behavior"
|
|
@@ -69,6 +80,20 @@ function Behavior.prototype.onDestroy(self)
|
|
|
69
80
|
if ____opt_0 ~= nil then
|
|
70
81
|
____opt_0:destroy()
|
|
71
82
|
end
|
|
83
|
+
local events = eventsByBehavior[self]
|
|
84
|
+
if events ~= nil then
|
|
85
|
+
for event in pairs(events) do
|
|
86
|
+
local ____opt_2 = behaviorsByEvent[event]
|
|
87
|
+
if ____opt_2 ~= nil then
|
|
88
|
+
____opt_2:remove(self)
|
|
89
|
+
end
|
|
90
|
+
local ____opt_4 = listenerByBehaviorByEvent[event]
|
|
91
|
+
if ____opt_4 ~= nil then
|
|
92
|
+
____opt_4[self] = nil
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
eventsByBehavior[self] = nil
|
|
96
|
+
end
|
|
72
97
|
local previousBehavior = self[0]
|
|
73
98
|
local nextBehavior = self[1]
|
|
74
99
|
if previousBehavior ~= nil then
|
|
@@ -83,6 +108,34 @@ function Behavior.prototype.onDestroy(self)
|
|
|
83
108
|
end
|
|
84
109
|
return AbstractDestroyable.prototype.onDestroy(self)
|
|
85
110
|
end
|
|
111
|
+
function Behavior.prototype.registerEvent(self, event, listener)
|
|
112
|
+
local listenerByBehavior = getOrPut(listenerByBehaviorByEvent, event, mutableLuaMap)
|
|
113
|
+
listenerByBehavior[self] = listener
|
|
114
|
+
getOrPut(eventsByBehavior, self, mutableLuaSet)[event] = true
|
|
115
|
+
local behaviors = behaviorsByEvent[event]
|
|
116
|
+
if behaviors == nil then
|
|
117
|
+
event:addListener(function(...)
|
|
118
|
+
local behaviors = behaviorsByEvent[event]
|
|
119
|
+
if behaviors ~= nil then
|
|
120
|
+
for behavior in pairs(behaviors) do
|
|
121
|
+
safeCall(behavior[listenerByBehavior[behavior]], behavior, ...)
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
end)
|
|
125
|
+
behaviors = __TS__New(LinkedSet)
|
|
126
|
+
behaviorsByEvent[event] = behaviors
|
|
127
|
+
end
|
|
128
|
+
behaviors:add(self)
|
|
129
|
+
end
|
|
130
|
+
function Behavior.prototype.deregisterEvent(self, event)
|
|
131
|
+
local behaviors = behaviorsByEvent[event]
|
|
132
|
+
if behaviors ~= nil and behaviors:remove(self) then
|
|
133
|
+
eventsByBehavior[self][event] = nil
|
|
134
|
+
listenerByBehaviorByEvent[event][self] = nil
|
|
135
|
+
return true
|
|
136
|
+
end
|
|
137
|
+
return false
|
|
138
|
+
end
|
|
86
139
|
function Behavior.prototype.onPeriod(self, ...)
|
|
87
140
|
end
|
|
88
141
|
function Behavior.prototype.startPeriodicAction(self, interval, ...)
|
|
@@ -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
|
-
|
|
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,11 @@ 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
|
|
24
|
+
local safeCall = warpack.safeCall
|
|
20
25
|
local behaviorsByEvent = {}
|
|
21
26
|
local rangeByBehaviorByEvent = {}
|
|
22
27
|
local listenerByBehaviorByEvent = {}
|
|
@@ -47,8 +52,26 @@ function UnitBehavior.prototype.onDestroy(self)
|
|
|
47
52
|
end
|
|
48
53
|
eventsByBehavior[self] = nil
|
|
49
54
|
end
|
|
55
|
+
if self._bonusIdByBonusType ~= nil then
|
|
56
|
+
for bonusType, bonusId in pairs(self._bonusIdByBonusType) do
|
|
57
|
+
removeUnitBonus(self.object, bonusType, bonusId)
|
|
58
|
+
end
|
|
59
|
+
end
|
|
50
60
|
return Behavior.prototype.onDestroy(self)
|
|
51
61
|
end
|
|
62
|
+
function UnitBehavior.prototype.getUnitBonus(self, bonusType)
|
|
63
|
+
local ____opt_6 = self._bonusIdByBonusType
|
|
64
|
+
local bonusId = ____opt_6 and ____opt_6[bonusType]
|
|
65
|
+
return bonusId == nil and 0 or getUnitBonus(self.object, bonusType, bonusId)
|
|
66
|
+
end
|
|
67
|
+
function UnitBehavior.prototype.addOrUpdateOrRemoveUnitBonus(self, bonusType, value)
|
|
68
|
+
local bonusIdByBonusType = self._bonusIdByBonusType
|
|
69
|
+
if bonusIdByBonusType == nil then
|
|
70
|
+
bonusIdByBonusType = {}
|
|
71
|
+
self._bonusIdByBonusType = bonusIdByBonusType
|
|
72
|
+
end
|
|
73
|
+
bonusIdByBonusType[bonusType] = addOrUpdateOrRemoveUnitBonus(self.object, bonusType, bonusIdByBonusType[bonusType], value)
|
|
74
|
+
end
|
|
52
75
|
function UnitBehavior.prototype.registerInRangeUnitEvent(self, event, extractUnit, range, listener)
|
|
53
76
|
local rangeByBehavior = getOrPut(rangeByBehaviorByEvent, event, mutableLuaMap)
|
|
54
77
|
rangeByBehavior[self] = range
|
|
@@ -65,8 +88,7 @@ function UnitBehavior.prototype.registerInRangeUnitEvent(self, event, extractUni
|
|
|
65
88
|
for behavior in pairs(behaviors) do
|
|
66
89
|
local range = rangeByBehavior[behavior]
|
|
67
90
|
if range ~= nil and unit:getCollisionDistanceTo(behavior.unit) <= range then
|
|
68
|
-
|
|
69
|
-
____self_6[listenerByBehavior[behavior]](____self_6, ...)
|
|
91
|
+
safeCall(behavior[listenerByBehavior[behavior]], behavior, ...)
|
|
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;
|