warscript 0.0.1-dev.ee6f224 → 0.0.1-dev.ef189a5
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/attributes.d.ts +1 -0
- package/attributes.lua +9 -0
- package/core/types/player.d.ts +16 -0
- package/core/types/player.lua +57 -14
- package/core/types/tileCell.d.ts +2 -1
- package/core/types/tileCell.lua +5 -0
- package/core/types/timer.d.ts +3 -2
- package/core/types/timer.lua +8 -2
- package/engine/behavior.d.ts +7 -1
- package/engine/behavior.lua +88 -65
- package/engine/behaviour/ability/apply-buff.lua +4 -4
- package/engine/behaviour/ability/remove-buffs.d.ts +9 -0
- package/engine/behaviour/ability/remove-buffs.lua +21 -0
- package/engine/behaviour/ability.d.ts +2 -1
- package/engine/behaviour/ability.lua +2 -1
- package/engine/behaviour/unit/stun-immunity.d.ts +8 -4
- package/engine/behaviour/unit/stun-immunity.lua +12 -3
- package/engine/behaviour/unit.d.ts +9 -3
- package/engine/behaviour/unit.lua +94 -22
- package/engine/buff.d.ts +12 -2
- package/engine/buff.lua +80 -17
- package/engine/internal/item.d.ts +12 -12
- package/engine/internal/item.lua +41 -26
- package/engine/internal/unit/ability.d.ts +14 -14
- package/engine/internal/unit/ability.lua +72 -45
- package/engine/internal/unit/fly-height.d.ts +7 -0
- package/engine/internal/unit/fly-height.lua +20 -0
- package/engine/internal/unit/main-selected.lua +12 -27
- package/engine/internal/unit/scale.d.ts +7 -0
- package/engine/internal/unit/scale.lua +20 -0
- package/engine/internal/unit-missile-launch.lua +44 -20
- package/engine/internal/unit.d.ts +13 -10
- package/engine/internal/unit.lua +83 -64
- package/engine/local-client.d.ts +2 -0
- package/engine/local-client.lua +30 -0
- package/engine/object-data/entry/ability-type.lua +4 -1
- package/engine/object-data/entry/destructible-type.d.ts +5 -1
- package/engine/object-data/entry/destructible-type.lua +12 -0
- package/engine/object-data/entry/unit-type.d.ts +4 -0
- package/engine/object-data/entry/unit-type.lua +76 -32
- package/engine/object-field/unit.d.ts +13 -1
- package/engine/object-field/unit.lua +57 -0
- package/engine/object-field.d.ts +7 -1
- package/engine/object-field.lua +199 -112
- package/engine/standard/fields/ability.d.ts +2 -2
- package/engine/standard/fields/ability.lua +2 -2
- package/engine/standard/fields/unit.d.ts +3 -1
- package/engine/standard/fields/unit.lua +4 -0
- package/engine/synchronization.d.ts +11 -0
- package/engine/synchronization.lua +77 -0
- package/engine/text-tag.lua +3 -2
- package/engine/unit.d.ts +2 -0
- package/engine/unit.lua +2 -0
- package/net/socket.lua +1 -1
- package/objutil/buff.lua +1 -1
- package/package.json +2 -2
- package/utility/arrays.d.ts +1 -0
- package/utility/arrays.lua +8 -0
- package/utility/callback-array.d.ts +5 -1
- package/utility/callback-array.lua +16 -1
- package/utility/linked-set.d.ts +1 -0
- package/utility/linked-set.lua +19 -1
- package/utility/types.d.ts +3 -0
package/attributes.d.ts
CHANGED
|
@@ -13,5 +13,6 @@ export declare namespace Attribute {
|
|
|
13
13
|
export declare class AttributesHolder {
|
|
14
14
|
readonly get: (<T>(attribute: Attribute<T>) => T | undefined) & LuaExtension<"TableGetMethod">;
|
|
15
15
|
readonly set: (<T>(attribute: Attribute<T>, value: T | undefined) => void) & LuaExtension<"TableSetMethod">;
|
|
16
|
+
getOrPut<T>(attribute: Attribute<T>, defaultValue: () => T): T;
|
|
16
17
|
}
|
|
17
18
|
export {};
|
package/attributes.lua
CHANGED
|
@@ -20,4 +20,13 @@ local AttributesHolder = ____exports.AttributesHolder
|
|
|
20
20
|
AttributesHolder.name = "AttributesHolder"
|
|
21
21
|
function AttributesHolder.prototype.____constructor(self)
|
|
22
22
|
end
|
|
23
|
+
function AttributesHolder.prototype.getOrPut(self, attribute, defaultValue)
|
|
24
|
+
local value = self[attribute]
|
|
25
|
+
if value ~= nil then
|
|
26
|
+
return value
|
|
27
|
+
end
|
|
28
|
+
value = defaultValue()
|
|
29
|
+
self[attribute] = value
|
|
30
|
+
return value
|
|
31
|
+
end
|
|
23
32
|
return ____exports
|
package/core/types/player.d.ts
CHANGED
|
@@ -7,6 +7,18 @@ import { UpgradeId } from "../../engine/object-data/entry/upgrade";
|
|
|
7
7
|
interface Unit {
|
|
8
8
|
handle: junit;
|
|
9
9
|
}
|
|
10
|
+
export declare const enum PlayerAllianceType {
|
|
11
|
+
PASSIVE = 0,
|
|
12
|
+
RESCUABLE = 1,
|
|
13
|
+
HELP_REQUEST = 2,
|
|
14
|
+
HELP_RESPONSE = 3,
|
|
15
|
+
SHARED_XP = 4,
|
|
16
|
+
SHARED_SPELLS = 5,
|
|
17
|
+
SHARED_VISION = 6,
|
|
18
|
+
SHARED_VISION_FORCED = 7,
|
|
19
|
+
SHARED_CONTROL = 8,
|
|
20
|
+
SHARED_ADVANCED_CONTROL = 9
|
|
21
|
+
}
|
|
10
22
|
export declare class Player extends Handle<jplayer> {
|
|
11
23
|
static readonly all: Player[];
|
|
12
24
|
static readonly local: Player;
|
|
@@ -42,6 +54,8 @@ export declare class Player extends Handle<jplayer> {
|
|
|
42
54
|
forceUICancel(): void;
|
|
43
55
|
isAllyOf(other: Player): boolean;
|
|
44
56
|
isEnemyOf(other: Player): boolean;
|
|
57
|
+
setAlliance(other: Player, type: PlayerAllianceType, value: boolean): void;
|
|
58
|
+
getAlliance(other: Player, type: PlayerAllianceType): boolean;
|
|
45
59
|
setAbilityAvailable(abilityId: number, available: boolean): void;
|
|
46
60
|
getMaximumUpgradeLevel(upgradeId: UpgradeId): number;
|
|
47
61
|
setMaximumUpgradeLevel(upgradeId: UpgradeId, maximumLevel: number): void;
|
|
@@ -50,6 +64,7 @@ export declare class Player extends Handle<jplayer> {
|
|
|
50
64
|
setUpgradeLevel(upgradeId: UpgradeId, level: number): void;
|
|
51
65
|
private static getEvent;
|
|
52
66
|
private static getMouseEvent;
|
|
67
|
+
static get allianceChangedEvent(): Readonly<Record<PlayerAllianceType, Event<[Player]>>>;
|
|
53
68
|
static get onLeave(): Event<[Player]>;
|
|
54
69
|
static get onMouseDown(): Event<[Player, jmousebuttontype]>;
|
|
55
70
|
static get onMouseUp(): Event<[Player, jmousebuttontype]>;
|
|
@@ -66,6 +81,7 @@ export declare class Player extends Handle<jplayer> {
|
|
|
66
81
|
};
|
|
67
82
|
};
|
|
68
83
|
static get onChat(): Event<[player: Player, message: string]>;
|
|
84
|
+
static readonly colorChangedEvent: Event<[Player]>;
|
|
69
85
|
static byId(id: number): Player | undefined;
|
|
70
86
|
}
|
|
71
87
|
export {};
|
package/core/types/player.lua
CHANGED
|
@@ -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 = {}
|
|
@@ -23,14 +23,33 @@ local ____math = require("math")
|
|
|
23
23
|
local MAXIMUM_INTEGER = ____math.MAXIMUM_INTEGER
|
|
24
24
|
local ____player_2Dlocal_2Dhandle = require("engine.internal.misc.player-local-handle")
|
|
25
25
|
local PLAYER_LOCAL_HANDLE = ____player_2Dlocal_2Dhandle.PLAYER_LOCAL_HANDLE
|
|
26
|
+
local ____lazy = require("utility.lazy")
|
|
27
|
+
local lazyRecord = ____lazy.lazyRecord
|
|
28
|
+
local getPlayerAlliance = GetPlayerAlliance
|
|
26
29
|
local getPlayerColor = GetPlayerColor
|
|
27
30
|
local getPlayerName = GetPlayerName
|
|
28
31
|
local getPlayerTechCount = GetPlayerTechCount
|
|
29
32
|
local getPlayerTechMaxAllowed = GetPlayerTechMaxAllowed
|
|
33
|
+
local getTriggerPlayer = GetTriggerPlayer
|
|
34
|
+
local setPlayerAlliance = SetPlayerAlliance
|
|
30
35
|
local setPlayerTechMaxAllowed = SetPlayerTechMaxAllowed
|
|
31
36
|
local setPlayerTechResearched = SetPlayerTechResearched
|
|
32
37
|
local setPlayerAbilityAvailable = SetPlayerAbilityAvailable
|
|
38
|
+
local triggerRegisterPlayerAllianceChange = TriggerRegisterPlayerAllianceChange
|
|
33
39
|
local playerNative = _G.Player
|
|
40
|
+
local nativeByPlayerAllianceType = {
|
|
41
|
+
[0] = ALLIANCE_PASSIVE,
|
|
42
|
+
[1] = ALLIANCE_RESCUABLE,
|
|
43
|
+
[2] = ALLIANCE_HELP_REQUEST,
|
|
44
|
+
[3] = ALLIANCE_HELP_RESPONSE,
|
|
45
|
+
[4] = ALLIANCE_SHARED_XP,
|
|
46
|
+
[5] = ALLIANCE_SHARED_SPELLS,
|
|
47
|
+
[6] = ALLIANCE_SHARED_VISION,
|
|
48
|
+
[7] = ALLIANCE_SHARED_VISION_FORCED,
|
|
49
|
+
[8] = ALLIANCE_SHARED_CONTROL,
|
|
50
|
+
[9] = ALLIANCE_SHARED_ADVANCED_CONTROL
|
|
51
|
+
}
|
|
52
|
+
local playerColorChangedEvent = __TS__New(Event)
|
|
34
53
|
____exports.Player = __TS__Class()
|
|
35
54
|
local Player = ____exports.Player
|
|
36
55
|
Player.name = "Player"
|
|
@@ -85,6 +104,12 @@ end
|
|
|
85
104
|
function Player.prototype.isEnemyOf(self, other)
|
|
86
105
|
return IsPlayerEnemy(self.handle, other.handle)
|
|
87
106
|
end
|
|
107
|
+
function Player.prototype.setAlliance(self, other, ____type, value)
|
|
108
|
+
setPlayerAlliance(self.handle, other.handle, nativeByPlayerAllianceType[____type], value)
|
|
109
|
+
end
|
|
110
|
+
function Player.prototype.getAlliance(self, other, ____type)
|
|
111
|
+
return getPlayerAlliance(self.handle, other.handle, nativeByPlayerAllianceType[____type])
|
|
112
|
+
end
|
|
88
113
|
function Player.prototype.setAbilityAvailable(self, abilityId, available)
|
|
89
114
|
setPlayerAbilityAvailable(self.handle, abilityId, available)
|
|
90
115
|
end
|
|
@@ -124,14 +149,11 @@ function Player.getMouseEvent(self, event, collector)
|
|
|
124
149
|
self.events[eventId] = __TS__New(
|
|
125
150
|
TriggerEvent,
|
|
126
151
|
function(trigger)
|
|
127
|
-
Timer:
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
for ____, player in ipairs(____exports.Player.all) do
|
|
131
|
-
TriggerRegisterPlayerEvent(trigger, player.handle, event)
|
|
132
|
-
end
|
|
152
|
+
Timer:run(function()
|
|
153
|
+
for ____, player in ipairs(____exports.Player.all) do
|
|
154
|
+
TriggerRegisterPlayerEvent(trigger, player.handle, event)
|
|
133
155
|
end
|
|
134
|
-
)
|
|
156
|
+
end)
|
|
135
157
|
end,
|
|
136
158
|
collector or (function() return {} end)
|
|
137
159
|
)
|
|
@@ -180,7 +202,7 @@ function Player.getKeyEvent(self, isDown)
|
|
|
180
202
|
TriggerAddCondition(
|
|
181
203
|
trigger,
|
|
182
204
|
Condition(function()
|
|
183
|
-
local player = ____exports.Player:of(
|
|
205
|
+
local player = ____exports.Player:of(getTriggerPlayer())
|
|
184
206
|
local key = BlzGetTriggerPlayerKey()
|
|
185
207
|
local metaKey = BlzGetTriggerPlayerMetaKey()
|
|
186
208
|
Event.invoke(event, player, key, metaKey)
|
|
@@ -279,6 +301,7 @@ __TS__SetDescriptor(
|
|
|
279
301
|
end,
|
|
280
302
|
set = function(self, color)
|
|
281
303
|
SetPlayerColor(self.handle, color.handle)
|
|
304
|
+
Event.invoke(playerColorChangedEvent, self)
|
|
282
305
|
end
|
|
283
306
|
},
|
|
284
307
|
true
|
|
@@ -369,13 +392,32 @@ __TS__SetDescriptor(
|
|
|
369
392
|
end},
|
|
370
393
|
true
|
|
371
394
|
)
|
|
395
|
+
__TS__ObjectDefineProperty(
|
|
396
|
+
Player,
|
|
397
|
+
"allianceChangedEvent",
|
|
398
|
+
{get = function(self)
|
|
399
|
+
local event = lazyRecord(function(____type)
|
|
400
|
+
return __TS__New(
|
|
401
|
+
TriggerEvent,
|
|
402
|
+
function(trigger)
|
|
403
|
+
for ____, player in ipairs(____exports.Player.all) do
|
|
404
|
+
triggerRegisterPlayerAllianceChange(trigger, player.handle, nativeByPlayerAllianceType[____type])
|
|
405
|
+
end
|
|
406
|
+
end,
|
|
407
|
+
function() return ____exports.Player:of(getTriggerPlayer()) end
|
|
408
|
+
)
|
|
409
|
+
end)
|
|
410
|
+
rawset(self, "allianceChangedEvent", event)
|
|
411
|
+
return event
|
|
412
|
+
end}
|
|
413
|
+
)
|
|
372
414
|
__TS__ObjectDefineProperty(
|
|
373
415
|
Player,
|
|
374
416
|
"onLeave",
|
|
375
417
|
{get = function(self)
|
|
376
418
|
return ____exports.Player:getEvent(
|
|
377
419
|
EVENT_PLAYER_LEAVE,
|
|
378
|
-
function() return ____exports.Player:of(
|
|
420
|
+
function() return ____exports.Player:of(getTriggerPlayer()) end
|
|
379
421
|
)
|
|
380
422
|
end}
|
|
381
423
|
)
|
|
@@ -385,7 +427,7 @@ __TS__ObjectDefineProperty(
|
|
|
385
427
|
{get = function(self)
|
|
386
428
|
return ____exports.Player:getMouseEvent(
|
|
387
429
|
EVENT_PLAYER_MOUSE_DOWN,
|
|
388
|
-
function() return ____exports.Player:of(
|
|
430
|
+
function() return ____exports.Player:of(getTriggerPlayer()), BlzGetTriggerPlayerMouseButton() end
|
|
389
431
|
)
|
|
390
432
|
end}
|
|
391
433
|
)
|
|
@@ -395,7 +437,7 @@ __TS__ObjectDefineProperty(
|
|
|
395
437
|
{get = function(self)
|
|
396
438
|
return ____exports.Player:getMouseEvent(
|
|
397
439
|
EVENT_PLAYER_MOUSE_UP,
|
|
398
|
-
function() return ____exports.Player:of(
|
|
440
|
+
function() return ____exports.Player:of(getTriggerPlayer()), BlzGetTriggerPlayerMouseButton() end
|
|
399
441
|
)
|
|
400
442
|
end}
|
|
401
443
|
)
|
|
@@ -405,7 +447,7 @@ __TS__ObjectDefineProperty(
|
|
|
405
447
|
{get = function(self)
|
|
406
448
|
return ____exports.Player:getMouseEvent(
|
|
407
449
|
EVENT_PLAYER_MOUSE_MOVE,
|
|
408
|
-
function() return ____exports.Player:of(
|
|
450
|
+
function() return ____exports.Player:of(getTriggerPlayer()), vec2(
|
|
409
451
|
BlzGetTriggerPlayerMouseX(),
|
|
410
452
|
BlzGetTriggerPlayerMouseY()
|
|
411
453
|
) end
|
|
@@ -441,10 +483,11 @@ __TS__ObjectDefineProperty(
|
|
|
441
483
|
TriggerRegisterPlayerChatEvent(trigger, player.handle, "", false)
|
|
442
484
|
end
|
|
443
485
|
end,
|
|
444
|
-
function() return ____exports.Player:of(
|
|
486
|
+
function() return ____exports.Player:of(getTriggerPlayer()), GetEventPlayerChatString() end
|
|
445
487
|
)
|
|
446
488
|
rawset(self, "onChat", event)
|
|
447
489
|
return event
|
|
448
490
|
end}
|
|
449
491
|
)
|
|
492
|
+
Player.colorChangedEvent = playerColorChangedEvent
|
|
450
493
|
return ____exports
|
package/core/types/tileCell.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/** @noSelfInFile */
|
|
2
|
-
|
|
2
|
+
import { AttributesHolder } from "../../attributes";
|
|
3
|
+
export declare class TileCell extends AttributesHolder implements Readonly<Vec2> {
|
|
3
4
|
private readonly id;
|
|
4
5
|
readonly x: number;
|
|
5
6
|
readonly y: number;
|
package/core/types/tileCell.lua
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
local ____lualib = require("lualib_bundle")
|
|
2
2
|
local __TS__Class = ____lualib.__TS__Class
|
|
3
|
+
local __TS__ClassExtends = ____lualib.__TS__ClassExtends
|
|
3
4
|
local __TS__New = ____lualib.__TS__New
|
|
4
5
|
local __TS__SetDescriptor = ____lualib.__TS__SetDescriptor
|
|
5
6
|
local ____exports = {}
|
|
7
|
+
local ____attributes = require("attributes")
|
|
8
|
+
local AttributesHolder = ____attributes.AttributesHolder
|
|
6
9
|
local getTerrainType = GetTerrainType
|
|
7
10
|
local setTerrainType = SetTerrainType
|
|
8
11
|
local getTerrainVariance = GetTerrainVariance
|
|
@@ -13,7 +16,9 @@ local tileCellById = {}
|
|
|
13
16
|
____exports.TileCell = __TS__Class()
|
|
14
17
|
local TileCell = ____exports.TileCell
|
|
15
18
|
TileCell.name = "TileCell"
|
|
19
|
+
__TS__ClassExtends(TileCell, AttributesHolder)
|
|
16
20
|
function TileCell.prototype.____constructor(self, id, x, y, z)
|
|
21
|
+
AttributesHolder.prototype.____constructor(self)
|
|
17
22
|
self.id = id
|
|
18
23
|
self.x = x
|
|
19
24
|
self.y = y
|
package/core/types/timer.d.ts
CHANGED
|
@@ -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):
|
|
26
|
-
static run<Args extends any[]>(callback: (this: void, ...args: Args) => void, ...args: Args):
|
|
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;
|
package/core/types/timer.lua
CHANGED
|
@@ -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/engine/behavior.d.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
/** @noSelfInFile */
|
|
2
2
|
import { AbstractDestroyable, Destructor } from "../destroyable";
|
|
3
3
|
import { Event } from "../event";
|
|
4
|
+
export declare const enum BehaviorPriority {
|
|
5
|
+
HIGH = 0,
|
|
6
|
+
MEDIUM = 1,
|
|
7
|
+
LOW = 2
|
|
8
|
+
}
|
|
4
9
|
export type BehaviorConstructor<T extends Behavior<AnyNotNil>, Parameters extends any[] = any[]> = OmitConstructor<typeof Behavior<any>> & (abstract new (...parameters: Parameters) => T);
|
|
5
10
|
declare const enum BehaviorPropertyKey {
|
|
6
11
|
PREVIOUS_BEHAVIOR = 0,
|
|
@@ -9,10 +14,11 @@ declare const enum BehaviorPropertyKey {
|
|
|
9
14
|
}
|
|
10
15
|
export declare abstract class Behavior<T extends AnyNotNil, PeriodicActionParameters extends any[] = any[]> extends AbstractDestroyable {
|
|
11
16
|
protected readonly object: T;
|
|
17
|
+
readonly priority: BehaviorPriority;
|
|
12
18
|
private [BehaviorPropertyKey.PREVIOUS_BEHAVIOR]?;
|
|
13
19
|
private [BehaviorPropertyKey.NEXT_BEHAVIOR]?;
|
|
14
20
|
private [BehaviorPropertyKey.TIMER]?;
|
|
15
|
-
protected constructor(object: T);
|
|
21
|
+
protected constructor(object: T, priority?: BehaviorPriority);
|
|
16
22
|
protected onDestroy(): Destructor;
|
|
17
23
|
protected registerEvent<K extends string, Args extends any[]>(this: Behavior<any, PeriodicActionParameters> & Record<K, (this: this, ...args: Args) => unknown>, event: Event<[...Args]>, listener: K): void;
|
|
18
24
|
protected deregisterEvent(event: Event<any>): boolean;
|
package/engine/behavior.lua
CHANGED
|
@@ -18,39 +18,41 @@ local mutableLuaMap = ____lua_2Dmaps.mutableLuaMap
|
|
|
18
18
|
local ____lua_2Dsets = require("utility.lua-sets")
|
|
19
19
|
local mutableLuaSet = ____lua_2Dsets.mutableLuaSet
|
|
20
20
|
local safeCall = warpack.safeCall
|
|
21
|
-
local
|
|
22
|
-
local
|
|
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
|
-
|
|
29
|
-
|
|
30
|
-
if
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
-
|
|
52
|
-
|
|
53
|
-
until not (behavior ~= nil)
|
|
54
|
+
until not (behavior ~= nil)
|
|
55
|
+
end
|
|
54
56
|
end
|
|
55
57
|
end
|
|
56
58
|
return accumulator
|
|
@@ -62,12 +64,17 @@ ____exports.Behavior = __TS__Class()
|
|
|
62
64
|
local Behavior = ____exports.Behavior
|
|
63
65
|
Behavior.name = "Behavior"
|
|
64
66
|
__TS__ClassExtends(Behavior, AbstractDestroyable)
|
|
65
|
-
function Behavior.prototype.____constructor(self, object)
|
|
67
|
+
function Behavior.prototype.____constructor(self, object, priority)
|
|
68
|
+
if priority == nil then
|
|
69
|
+
priority = 1
|
|
70
|
+
end
|
|
66
71
|
AbstractDestroyable.prototype.____constructor(self)
|
|
67
72
|
self.object = object
|
|
73
|
+
self.priority = priority
|
|
74
|
+
local lastBehaviorByObject = lastBehaviorByObjectByPriority[priority]
|
|
68
75
|
local lastBehavior = lastBehaviorByObject[object]
|
|
69
76
|
if lastBehavior == nil then
|
|
70
|
-
|
|
77
|
+
firstBehaviorByObjectByPriority[priority][object] = self
|
|
71
78
|
lastBehaviorByObject[object] = self
|
|
72
79
|
else
|
|
73
80
|
self[0] = lastBehavior
|
|
@@ -99,12 +106,12 @@ function Behavior.prototype.onDestroy(self)
|
|
|
99
106
|
if previousBehavior ~= nil then
|
|
100
107
|
previousBehavior[1] = nextBehavior
|
|
101
108
|
else
|
|
102
|
-
|
|
109
|
+
firstBehaviorByObjectByPriority[self.priority][self.object] = nextBehavior
|
|
103
110
|
end
|
|
104
111
|
if nextBehavior ~= nil then
|
|
105
112
|
nextBehavior[0] = previousBehavior
|
|
106
113
|
else
|
|
107
|
-
|
|
114
|
+
lastBehaviorByObjectByPriority[self.priority][self.object] = previousBehavior
|
|
108
115
|
end
|
|
109
116
|
return AbstractDestroyable.prototype.onDestroy(self)
|
|
110
117
|
end
|
|
@@ -161,78 +168,94 @@ function Behavior.prototype.stopPeriodicAction(self)
|
|
|
161
168
|
end
|
|
162
169
|
function Behavior.count(self, object, limit)
|
|
163
170
|
local behaviorsCount = 0
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
171
|
+
for priority = 0, 2 do
|
|
172
|
+
local behavior = firstBehaviorByObjectByPriority[priority][object]
|
|
173
|
+
while behavior ~= nil and (limit == nil or behaviorsCount < limit) do
|
|
174
|
+
if __TS__InstanceOf(behavior, self) then
|
|
175
|
+
behaviorsCount = behaviorsCount + 1
|
|
176
|
+
end
|
|
177
|
+
behavior = behavior[1]
|
|
168
178
|
end
|
|
169
|
-
behavior = behavior[1]
|
|
170
179
|
end
|
|
171
180
|
return behaviorsCount
|
|
172
181
|
end
|
|
173
182
|
function Behavior.getFirst(self, object, countOrPredicate, ...)
|
|
174
|
-
local behavior = firstBehaviorByObject[object]
|
|
175
183
|
if type(countOrPredicate) ~= "number" then
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
184
|
+
for priority = 0, 2 do
|
|
185
|
+
local behavior = firstBehaviorByObjectByPriority[priority][object]
|
|
186
|
+
while behavior ~= nil do
|
|
187
|
+
if __TS__InstanceOf(behavior, self) and (countOrPredicate == nil or countOrPredicate(behavior, ...)) then
|
|
188
|
+
return behavior
|
|
189
|
+
end
|
|
190
|
+
behavior = behavior[1]
|
|
179
191
|
end
|
|
180
|
-
behavior = behavior[1]
|
|
181
192
|
end
|
|
182
193
|
return nil
|
|
183
194
|
end
|
|
184
195
|
local behaviors = {}
|
|
185
196
|
local behaviorsCount = 0
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
197
|
+
for priority = 0, 2 do
|
|
198
|
+
local behavior = firstBehaviorByObjectByPriority[priority][object]
|
|
199
|
+
while behavior ~= nil and behaviorsCount < countOrPredicate do
|
|
200
|
+
if __TS__InstanceOf(behavior, self) then
|
|
201
|
+
behaviorsCount = behaviorsCount + 1
|
|
202
|
+
behaviors[behaviorsCount] = behavior
|
|
203
|
+
end
|
|
204
|
+
behavior = behavior[1]
|
|
190
205
|
end
|
|
191
|
-
behavior = behavior[1]
|
|
192
206
|
end
|
|
193
207
|
return behaviors
|
|
194
208
|
end
|
|
195
209
|
function Behavior.getLast(self, object)
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
210
|
+
for priority = 2, 0, -1 do
|
|
211
|
+
local behavior = lastBehaviorByObjectByPriority[priority][object]
|
|
212
|
+
while behavior ~= nil do
|
|
213
|
+
if __TS__InstanceOf(behavior, self) then
|
|
214
|
+
return behavior
|
|
215
|
+
end
|
|
216
|
+
behavior = behavior[0]
|
|
200
217
|
end
|
|
201
|
-
behavior = behavior[0]
|
|
202
218
|
end
|
|
203
219
|
return nil
|
|
204
220
|
end
|
|
205
221
|
function Behavior.getAll(self, object, predicate, ...)
|
|
206
222
|
local behaviors = {}
|
|
207
223
|
local behaviorsCount = 0
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
224
|
+
for priority = 0, 2 do
|
|
225
|
+
local behavior = firstBehaviorByObjectByPriority[priority][object]
|
|
226
|
+
while behavior ~= nil do
|
|
227
|
+
if __TS__InstanceOf(behavior, self) and (predicate == nil or predicate(behavior, ...)) then
|
|
228
|
+
behaviorsCount = behaviorsCount + 1
|
|
229
|
+
behaviors[behaviorsCount] = behavior
|
|
230
|
+
end
|
|
231
|
+
behavior = behavior[1]
|
|
213
232
|
end
|
|
214
|
-
behavior = behavior[1]
|
|
215
233
|
end
|
|
216
234
|
return behaviors
|
|
217
235
|
end
|
|
218
236
|
function Behavior.forFirst(self, object, count, consumerOrKey, ...)
|
|
219
237
|
local behaviorsCount = 0
|
|
220
|
-
local behavior = firstBehaviorByObject[object]
|
|
221
238
|
if type(consumerOrKey) == "function" then
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
239
|
+
for priority = 0, 2 do
|
|
240
|
+
local behavior = firstBehaviorByObjectByPriority[priority][object]
|
|
241
|
+
while behavior ~= nil and behaviorsCount < count do
|
|
242
|
+
if __TS__InstanceOf(behavior, self) then
|
|
243
|
+
safeCall(consumerOrKey, behavior, ...)
|
|
244
|
+
behaviorsCount = behaviorsCount + 1
|
|
245
|
+
end
|
|
246
|
+
behavior = behavior[1]
|
|
226
247
|
end
|
|
227
|
-
behavior = behavior[1]
|
|
228
248
|
end
|
|
229
249
|
else
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
250
|
+
for priority = 0, 2 do
|
|
251
|
+
local behavior = firstBehaviorByObjectByPriority[priority][object]
|
|
252
|
+
while behavior ~= nil and behaviorsCount < count do
|
|
253
|
+
if __TS__InstanceOf(behavior, self) then
|
|
254
|
+
safeCall(behavior[consumerOrKey], behavior, ...)
|
|
255
|
+
behaviorsCount = behaviorsCount + 1
|
|
256
|
+
end
|
|
257
|
+
behavior = behavior[1]
|
|
234
258
|
end
|
|
235
|
-
behavior = behavior[1]
|
|
236
259
|
end
|
|
237
260
|
end
|
|
238
261
|
return behaviorsCount
|
|
@@ -27,7 +27,7 @@ function ApplyBuffAbilityBehavior.prototype.____constructor(self, ability, const
|
|
|
27
27
|
constructorOrTypeIdOrTypeIds,
|
|
28
28
|
typeIdOrTypeIdsOrPolarityOrTypeIdSelectionPolicy,
|
|
29
29
|
polarityOrTypeIdSelectionPolicyOrResistanceType,
|
|
30
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
65
|
+
self,
|
|
66
66
|
parameters
|
|
67
67
|
)
|
|
68
68
|
end
|
|
@@ -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";
|