warscript 0.0.1-dev.5ca835c → 0.0.1-dev.5d49132
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/player.d.ts +1 -0
- package/core/types/player.lua +4 -1
- package/destroyable.d.ts +1 -0
- package/destroyable.lua +9 -0
- package/engine/behavior.d.ts +4 -2
- package/engine/behavior.lua +69 -11
- package/engine/behaviour/ability/apply-buff.lua +4 -4
- package/engine/behaviour/ability.d.ts +2 -1
- package/engine/behaviour/ability.lua +2 -1
- package/engine/behaviour/unit/stun-immunity.d.ts +7 -5
- package/engine/behaviour/unit/stun-immunity.lua +6 -5
- package/engine/behaviour/unit.d.ts +7 -3
- package/engine/behaviour/unit.lua +101 -24
- package/engine/buff.d.ts +9 -3
- package/engine/buff.lua +62 -34
- package/engine/internal/mechanics/cast-ability.lua +6 -3
- package/engine/internal/object-data/mana-regeneration-rate-increase-factor.d.ts +2 -0
- package/engine/internal/object-data/mana-regeneration-rate-increase-factor.lua +16 -0
- package/engine/internal/unit/attributes.d.ts +17 -0
- package/engine/internal/unit/attributes.lua +46 -0
- package/engine/internal/unit/bonus.d.ts +2 -0
- package/engine/internal/unit/bonus.lua +10 -0
- package/engine/internal/unit/fly-height.lua +3 -3
- package/engine/internal/unit/interrupts.d.ts +12 -0
- package/engine/internal/unit/interrupts.lua +28 -0
- package/engine/internal/unit/scale.lua +3 -3
- package/engine/internal/unit-missile-launch.lua +12 -5
- package/engine/internal/unit.d.ts +2 -8
- package/engine/internal/unit.lua +79 -97
- package/engine/local-client.d.ts +1 -1
- package/engine/local-client.lua +4 -4
- package/engine/object-data/auxiliary/health-regeneration-type.d.ts +8 -0
- package/engine/object-data/auxiliary/health-regeneration-type.lua +2 -0
- package/engine/object-data/entry/ability-type/mana-regeneration.d.ts +8 -0
- package/engine/object-data/entry/ability-type/mana-regeneration.lua +26 -0
- package/engine/object-data/entry/destructible-type.d.ts +27 -1
- package/engine/object-data/entry/destructible-type.lua +155 -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 +7 -4
- package/engine/object-field/unit.lua +4 -0
- package/engine/object-field.d.ts +2 -0
- package/engine/object-field.lua +171 -115
- package/engine/standard/fields/ability.d.ts +2 -2
- package/engine/standard/fields/ability.lua +2 -2
- package/engine/standard/fields/unit.d.ts +11 -5
- package/engine/standard/fields/unit.lua +13 -4
- package/engine/unit.d.ts +2 -0
- package/engine/unit.lua +2 -0
- package/objutil/buff.lua +9 -7
- package/package.json +2 -2
- package/patch-lua.lua +15 -0
- package/utility/linked-map.d.ts +26 -0
- package/utility/linked-map.lua +66 -0
- package/utility/linked-set.lua +4 -0
- package/utility/records.lua +20 -1
package/core/types/player.d.ts
CHANGED
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 = {}
|
|
@@ -49,6 +49,7 @@ local nativeByPlayerAllianceType = {
|
|
|
49
49
|
[8] = ALLIANCE_SHARED_CONTROL,
|
|
50
50
|
[9] = ALLIANCE_SHARED_ADVANCED_CONTROL
|
|
51
51
|
}
|
|
52
|
+
local playerColorChangedEvent = __TS__New(Event)
|
|
52
53
|
____exports.Player = __TS__Class()
|
|
53
54
|
local Player = ____exports.Player
|
|
54
55
|
Player.name = "Player"
|
|
@@ -300,6 +301,7 @@ __TS__SetDescriptor(
|
|
|
300
301
|
end,
|
|
301
302
|
set = function(self, color)
|
|
302
303
|
SetPlayerColor(self.handle, color.handle)
|
|
304
|
+
Event.invoke(playerColorChangedEvent, self)
|
|
303
305
|
end
|
|
304
306
|
},
|
|
305
307
|
true
|
|
@@ -487,4 +489,5 @@ __TS__ObjectDefineProperty(
|
|
|
487
489
|
return event
|
|
488
490
|
end}
|
|
489
491
|
)
|
|
492
|
+
Player.colorChangedEvent = playerColorChangedEvent
|
|
490
493
|
return ____exports
|
package/destroyable.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export interface Destroyable {
|
|
|
10
10
|
destroy(): void;
|
|
11
11
|
}
|
|
12
12
|
export declare abstract class AbstractDestroyable implements Destroyable {
|
|
13
|
+
get isDestroyed(): boolean;
|
|
13
14
|
/**
|
|
14
15
|
* An overriding function should always call the super one at the end of it,
|
|
15
16
|
* in the following manner: `return super.onDestroy()`.
|
package/destroyable.lua
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
local ____lualib = require("lualib_bundle")
|
|
2
2
|
local __TS__Class = ____lualib.__TS__Class
|
|
3
3
|
local __TS__New = ____lualib.__TS__New
|
|
4
|
+
local __TS__SetDescriptor = ____lualib.__TS__SetDescriptor
|
|
4
5
|
local ____exports = {}
|
|
5
6
|
local ____exception = require("exception")
|
|
6
7
|
local IllegalStateException = ____exception.IllegalStateException
|
|
@@ -28,4 +29,12 @@ function AbstractDestroyable.prototype.destroy(self)
|
|
|
28
29
|
end
|
|
29
30
|
return true
|
|
30
31
|
end
|
|
32
|
+
__TS__SetDescriptor(
|
|
33
|
+
AbstractDestroyable.prototype,
|
|
34
|
+
"isDestroyed",
|
|
35
|
+
{get = function(self)
|
|
36
|
+
return stateByDestroyable[self] ~= nil
|
|
37
|
+
end},
|
|
38
|
+
true
|
|
39
|
+
)
|
|
31
40
|
return ____exports
|
package/engine/behavior.d.ts
CHANGED
|
@@ -18,9 +18,11 @@ export declare abstract class Behavior<T extends AnyNotNil, PeriodicActionParame
|
|
|
18
18
|
private [BehaviorPropertyKey.PREVIOUS_BEHAVIOR]?;
|
|
19
19
|
private [BehaviorPropertyKey.NEXT_BEHAVIOR]?;
|
|
20
20
|
private [BehaviorPropertyKey.TIMER]?;
|
|
21
|
-
|
|
21
|
+
constructor(object: T, priority?: BehaviorPriority);
|
|
22
22
|
protected onDestroy(): Destructor;
|
|
23
|
-
protected
|
|
23
|
+
protected registerGlobalEvent<K extends string, Args extends any[]>(this: Behavior<any, PeriodicActionParameters> & Record<K, (this: this, ...args: Args) => unknown>, event: Event<[...Args]>, listener: K): void;
|
|
24
|
+
protected deregisterGlobalEvent(event: Event<any>): boolean;
|
|
25
|
+
protected registerEvent<K extends string, Args extends any[]>(this: Behavior<any, PeriodicActionParameters> & Record<K, (this: this, ...args: Args) => unknown>, event: Event<[...Args]>, extractObject: (...args: Args) => T | undefined, listener: K): void;
|
|
24
26
|
protected deregisterEvent(event: Event<any>): boolean;
|
|
25
27
|
protected onPeriod(...parameters: PeriodicActionParameters): void;
|
|
26
28
|
protected startPeriodicAction(interval: number, ...parameters: PeriodicActionParameters): void;
|
package/engine/behavior.lua
CHANGED
|
@@ -57,9 +57,17 @@ local function reduceBehaviors(behaviorConstructor, object, operation, initial,
|
|
|
57
57
|
end
|
|
58
58
|
return accumulator
|
|
59
59
|
end
|
|
60
|
+
local behaviorsByGlobalEvent = {}
|
|
61
|
+
local listenerByBehaviorByGlobalEvent = {}
|
|
62
|
+
local globalEventsByBehavior = {}
|
|
60
63
|
local behaviorsByEvent = {}
|
|
61
64
|
local listenerByBehaviorByEvent = {}
|
|
62
65
|
local eventsByBehavior = {}
|
|
66
|
+
local function safeCallBehaviorListener(behavior, behaviors, listenerByBehavior, ...)
|
|
67
|
+
if behaviors[behavior] ~= nil then
|
|
68
|
+
safeCall(behavior[listenerByBehavior[behavior]], behavior, ...)
|
|
69
|
+
end
|
|
70
|
+
end
|
|
63
71
|
____exports.Behavior = __TS__Class()
|
|
64
72
|
local Behavior = ____exports.Behavior
|
|
65
73
|
Behavior.name = "Behavior"
|
|
@@ -87,18 +95,32 @@ function Behavior.prototype.onDestroy(self)
|
|
|
87
95
|
if ____opt_0 ~= nil then
|
|
88
96
|
____opt_0:destroy()
|
|
89
97
|
end
|
|
90
|
-
local
|
|
91
|
-
if
|
|
92
|
-
for event in pairs(
|
|
93
|
-
local ____opt_2 =
|
|
98
|
+
local globalEvents = globalEventsByBehavior[self]
|
|
99
|
+
if globalEvents ~= nil then
|
|
100
|
+
for event in pairs(globalEvents) do
|
|
101
|
+
local ____opt_2 = behaviorsByGlobalEvent[event]
|
|
94
102
|
if ____opt_2 ~= nil then
|
|
95
103
|
____opt_2:remove(self)
|
|
96
104
|
end
|
|
97
|
-
local ____opt_4 =
|
|
105
|
+
local ____opt_4 = listenerByBehaviorByGlobalEvent[event]
|
|
98
106
|
if ____opt_4 ~= nil then
|
|
99
107
|
____opt_4[self] = nil
|
|
100
108
|
end
|
|
101
109
|
end
|
|
110
|
+
globalEventsByBehavior[self] = nil
|
|
111
|
+
end
|
|
112
|
+
local events = eventsByBehavior[self]
|
|
113
|
+
if events ~= nil then
|
|
114
|
+
for event in pairs(events) do
|
|
115
|
+
local ____opt_6 = behaviorsByEvent[event]
|
|
116
|
+
if ____opt_6 ~= nil then
|
|
117
|
+
____opt_6[self] = nil
|
|
118
|
+
end
|
|
119
|
+
local ____opt_8 = listenerByBehaviorByEvent[event]
|
|
120
|
+
if ____opt_8 ~= nil then
|
|
121
|
+
____opt_8[self] = nil
|
|
122
|
+
end
|
|
123
|
+
end
|
|
102
124
|
eventsByBehavior[self] = nil
|
|
103
125
|
end
|
|
104
126
|
local previousBehavior = self[0]
|
|
@@ -115,7 +137,35 @@ function Behavior.prototype.onDestroy(self)
|
|
|
115
137
|
end
|
|
116
138
|
return AbstractDestroyable.prototype.onDestroy(self)
|
|
117
139
|
end
|
|
118
|
-
function Behavior.prototype.
|
|
140
|
+
function Behavior.prototype.registerGlobalEvent(self, event, listener)
|
|
141
|
+
local listenerByBehavior = getOrPut(listenerByBehaviorByGlobalEvent, event, mutableLuaMap)
|
|
142
|
+
listenerByBehavior[self] = listener
|
|
143
|
+
getOrPut(globalEventsByBehavior, self, mutableLuaSet)[event] = true
|
|
144
|
+
local behaviors = behaviorsByGlobalEvent[event]
|
|
145
|
+
if behaviors == nil then
|
|
146
|
+
event:addListener(function(...)
|
|
147
|
+
local behaviors = behaviorsByGlobalEvent[event]
|
|
148
|
+
if behaviors ~= nil then
|
|
149
|
+
for behavior in pairs(behaviors) do
|
|
150
|
+
safeCall(behavior[listenerByBehavior[behavior]], behavior, ...)
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
end)
|
|
154
|
+
behaviors = __TS__New(LinkedSet)
|
|
155
|
+
behaviorsByGlobalEvent[event] = behaviors
|
|
156
|
+
end
|
|
157
|
+
behaviors:add(self)
|
|
158
|
+
end
|
|
159
|
+
function Behavior.prototype.deregisterGlobalEvent(self, event)
|
|
160
|
+
local behaviors = behaviorsByGlobalEvent[event]
|
|
161
|
+
if behaviors ~= nil and behaviors:remove(self) then
|
|
162
|
+
globalEventsByBehavior[self][event] = nil
|
|
163
|
+
listenerByBehaviorByGlobalEvent[event][self] = nil
|
|
164
|
+
return true
|
|
165
|
+
end
|
|
166
|
+
return false
|
|
167
|
+
end
|
|
168
|
+
function Behavior.prototype.registerEvent(self, event, extractObject, listener)
|
|
119
169
|
local listenerByBehavior = getOrPut(listenerByBehaviorByEvent, event, mutableLuaMap)
|
|
120
170
|
listenerByBehavior[self] = listener
|
|
121
171
|
getOrPut(eventsByBehavior, self, mutableLuaSet)[event] = true
|
|
@@ -124,19 +174,27 @@ function Behavior.prototype.registerEvent(self, event, listener)
|
|
|
124
174
|
event:addListener(function(...)
|
|
125
175
|
local behaviors = behaviorsByEvent[event]
|
|
126
176
|
if behaviors ~= nil then
|
|
127
|
-
|
|
128
|
-
|
|
177
|
+
local object = extractObject(...)
|
|
178
|
+
if object ~= nil then
|
|
179
|
+
____exports.Behavior:forAll(
|
|
180
|
+
object,
|
|
181
|
+
safeCallBehaviorListener,
|
|
182
|
+
behaviors,
|
|
183
|
+
listenerByBehavior,
|
|
184
|
+
...
|
|
185
|
+
)
|
|
129
186
|
end
|
|
130
187
|
end
|
|
131
188
|
end)
|
|
132
|
-
behaviors =
|
|
189
|
+
behaviors = {}
|
|
133
190
|
behaviorsByEvent[event] = behaviors
|
|
134
191
|
end
|
|
135
|
-
behaviors
|
|
192
|
+
behaviors[self] = true
|
|
136
193
|
end
|
|
137
194
|
function Behavior.prototype.deregisterEvent(self, event)
|
|
138
195
|
local behaviors = behaviorsByEvent[event]
|
|
139
|
-
if behaviors ~= nil and behaviors
|
|
196
|
+
if behaviors ~= nil and behaviors[self] ~= nil then
|
|
197
|
+
behaviors[self] = nil
|
|
140
198
|
eventsByBehavior[self][event] = nil
|
|
141
199
|
listenerByBehaviorByEvent[event][self] = nil
|
|
142
200
|
return true
|
|
@@ -27,7 +27,7 @@ function ApplyBuffAbilityBehavior.prototype.____constructor(self, ability, const
|
|
|
27
27
|
constructorOrTypeIdOrTypeIds,
|
|
28
28
|
typeIdOrTypeIdsOrPolarityOrTypeIdSelectionPolicy,
|
|
29
29
|
polarityOrTypeIdSelectionPolicyOrResistanceType,
|
|
30
|
-
|
|
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
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/** @noSelfInFile */
|
|
2
2
|
import { Behavior } from "../behavior";
|
|
3
|
-
import { Unit } from "../unit";
|
|
3
|
+
import { Unit } from "../internal/unit";
|
|
4
|
+
import "../internal/unit/ability";
|
|
4
5
|
import { Ability } from "../internal/ability";
|
|
5
6
|
import { AbilityTypeId } from "../object-data/entry/ability-type";
|
|
6
7
|
import { Widget } from "../../core/types/widget";
|
|
@@ -7,8 +7,9 @@ local __TS__SetDescriptor = ____lualib.__TS__SetDescriptor
|
|
|
7
7
|
local ____exports = {}
|
|
8
8
|
local ____behavior = require("engine.behavior")
|
|
9
9
|
local Behavior = ____behavior.Behavior
|
|
10
|
-
local ____unit = require("engine.unit")
|
|
10
|
+
local ____unit = require("engine.internal.unit")
|
|
11
11
|
local Unit = ____unit.Unit
|
|
12
|
+
require("engine.internal.unit.ability")
|
|
12
13
|
local ____ability = require("engine.internal.ability")
|
|
13
14
|
local Ability = ____ability.Ability
|
|
14
15
|
local ____effect = require("core.types.effect")
|
|
@@ -4,16 +4,18 @@ import { Unit } from "../../unit";
|
|
|
4
4
|
import { BuffTypeId } from "../../object-data/entry/buff-type";
|
|
5
5
|
import { TextTagPreset } from "../../text-tag";
|
|
6
6
|
import { Destructor } from "../../../destroyable";
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
import { BehaviorPriority } from "../../behavior";
|
|
8
|
+
export type StunImmunityUnitBehaviorParameters = {
|
|
9
|
+
readonly priority?: BehaviorPriority;
|
|
10
|
+
buffTypeIds?: readonly BuffTypeId[];
|
|
9
11
|
textTagPreset?: TextTagPreset;
|
|
10
12
|
textTagText?: string;
|
|
11
13
|
additionalAction?: (this: void, unit: Unit) => void;
|
|
12
14
|
};
|
|
13
15
|
export declare class StunImmunityUnitBehavior extends UnitBehavior {
|
|
14
|
-
readonly parameters: Readonly<
|
|
15
|
-
static defaultParameters:
|
|
16
|
-
constructor(unit: Unit, parameters?: Readonly<
|
|
16
|
+
readonly parameters: Readonly<StunImmunityUnitBehaviorParameters>;
|
|
17
|
+
static defaultParameters: StunImmunityUnitBehaviorParameters;
|
|
18
|
+
constructor(unit: Unit, parameters?: Readonly<StunImmunityUnitBehaviorParameters>);
|
|
17
19
|
protected onDestroy(): Destructor;
|
|
18
20
|
onDamageReceived(): void;
|
|
19
21
|
onTargetingAbilityChannelingStart(): void;
|
|
@@ -8,14 +8,15 @@ local UnitBehavior = ____unit.UnitBehavior
|
|
|
8
8
|
local ____ability_2Dtype = require("engine.object-data.entry.ability-type")
|
|
9
9
|
local AbilityType = ____ability_2Dtype.AbilityType
|
|
10
10
|
local ____arrays = require("utility.arrays")
|
|
11
|
-
local
|
|
11
|
+
local distinct = ____arrays.distinct
|
|
12
|
+
local flatMap = ____arrays.flatMap
|
|
12
13
|
local map = ____arrays.map
|
|
13
14
|
local ____text_2Dtag = require("engine.text-tag")
|
|
14
15
|
local TextTag = ____text_2Dtag.TextTag
|
|
15
16
|
local ____timer = require("core.types.timer")
|
|
16
17
|
local Timer = ____timer.Timer
|
|
17
18
|
local DEFAULT_BUFF_TYPE_IDS = postcompile(function()
|
|
18
|
-
return
|
|
19
|
+
return distinct(flatMap(
|
|
19
20
|
AbilityType:getAllByBaseIds(map({
|
|
20
21
|
"AHtb",
|
|
21
22
|
"AHbh",
|
|
@@ -41,11 +42,11 @@ local DEFAULT_BUFF_TYPE_IDS = postcompile(function()
|
|
|
41
42
|
"ACcb"
|
|
42
43
|
}, fourCC)),
|
|
43
44
|
function(abilityType) return __TS__ArrayFlat(abilityType.buffTypeIds) end
|
|
44
|
-
)
|
|
45
|
+
))
|
|
45
46
|
end)
|
|
46
47
|
local function process(behavior)
|
|
47
48
|
local hasRemovedBuffs = false
|
|
48
|
-
for buffTypeId in
|
|
49
|
+
for ____, buffTypeId in ipairs(behavior.parameters.buffTypeIds or DEFAULT_BUFF_TYPE_IDS) do
|
|
49
50
|
hasRemovedBuffs = hasRemovedBuffs or behavior.unit:removeBuff(buffTypeId)
|
|
50
51
|
end
|
|
51
52
|
if hasRemovedBuffs then
|
|
@@ -67,7 +68,7 @@ function StunImmunityUnitBehavior.prototype.____constructor(self, unit, paramete
|
|
|
67
68
|
if parameters == nil then
|
|
68
69
|
parameters = ____exports.StunImmunityUnitBehavior.defaultParameters
|
|
69
70
|
end
|
|
70
|
-
UnitBehavior.prototype.____constructor(self, unit)
|
|
71
|
+
UnitBehavior.prototype.____constructor(self, unit, parameters.priority)
|
|
71
72
|
self.parameters = parameters
|
|
72
73
|
unit:decrementStunCounter()
|
|
73
74
|
process(self)
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/** @noSelfInFile */
|
|
2
|
-
import { Behavior } from "../behavior";
|
|
2
|
+
import { Behavior, BehaviorPriority } from "../behavior";
|
|
3
3
|
import { Ability } from "../internal/ability";
|
|
4
4
|
import { DamageEvent, DamagingEvent, Unit } from "../internal/unit";
|
|
5
5
|
import "../internal/unit+ability";
|
|
6
6
|
import "../internal/unit-missile-launch";
|
|
7
7
|
import { Item } from "../internal/item";
|
|
8
|
-
import
|
|
8
|
+
import { AbilityBehavior } from "./ability";
|
|
9
9
|
import { Event } from "../../event";
|
|
10
10
|
import { Destructor } from "../../destroyable";
|
|
11
11
|
import type { Widget } from "../../core/types/widget";
|
|
@@ -13,15 +13,17 @@ import { Destructable } from "../../core/types/destructable";
|
|
|
13
13
|
import type { Buff } from "../buff";
|
|
14
14
|
import { UnitBonusType } from "../internal/unit/bonus";
|
|
15
15
|
import { Player } from "../../core/types/player";
|
|
16
|
+
import { UnitTypeId } from "../object-data/entry/unit-type";
|
|
16
17
|
export type UnitBehaviorConstructor<Args extends any[]> = new (unit: Unit, ...args: Args) => UnitBehavior;
|
|
17
18
|
export declare abstract class UnitBehavior<PeriodicActionParameters extends any[] = any[]> extends Behavior<Unit, PeriodicActionParameters> {
|
|
18
19
|
readonly sourceAbilityBehavior?: AbilityBehavior;
|
|
19
20
|
private _bonusIdByBonusType?;
|
|
20
|
-
constructor(unit: Unit);
|
|
21
|
+
constructor(unit: Unit, priority?: BehaviorPriority);
|
|
21
22
|
protected onDestroy(): Destructor;
|
|
22
23
|
get unit(): Unit;
|
|
23
24
|
protected getUnitBonus(bonusType: UnitBonusType): number;
|
|
24
25
|
protected addOrUpdateOrRemoveUnitBonus(bonusType: UnitBonusType, value: number): void;
|
|
26
|
+
protected registerOwningPlayerEvent<T extends string, Args extends any[]>(this: UnitBehavior<PeriodicActionParameters> & Record<T, (this: this, ...args: Args) => unknown>, event: Event<[...Args]>, extractPlayer: (...args: Args) => Player | undefined, listener: T): void;
|
|
25
27
|
protected registerInRangeUnitEvent<T extends string, Args extends any[]>(this: UnitBehavior<PeriodicActionParameters> & Record<T, (this: this, ...args: Args) => unknown>, event: Event<[...Args]>, extractUnit: (...args: Args) => Unit | undefined, range: number, listener: T): void;
|
|
26
28
|
onImmediateOrder(orderId: number): void;
|
|
27
29
|
onTargetOrder(orderId: number, target: Widget): void;
|
|
@@ -49,6 +51,7 @@ export declare abstract class UnitBehavior<PeriodicActionParameters extends any[
|
|
|
49
51
|
onTargetingAbilityChannelingStart(ability: Ability, source: Unit): void;
|
|
50
52
|
onTargetingAbilityImpact(ability: Ability, source: Unit): void;
|
|
51
53
|
onBuffGained(buff: Buff): void;
|
|
54
|
+
onBuffLost(buff: Buff): void;
|
|
52
55
|
onItemDropped(item: Item): void;
|
|
53
56
|
onItemPickedUp(item: Item): void;
|
|
54
57
|
onItemUsed(item: Item): void;
|
|
@@ -57,4 +60,5 @@ export declare abstract class UnitBehavior<PeriodicActionParameters extends any[
|
|
|
57
60
|
onKill(target: Unit): void;
|
|
58
61
|
onDeath(source: Unit | undefined): void;
|
|
59
62
|
onOwnerChange(previousOwner: Player): void;
|
|
63
|
+
static bindUnitType<Args extends any[]>(this: UnitBehaviorConstructor<Args>, unitTypeId: UnitTypeId, ...args: Args): void;
|
|
60
64
|
}
|
|
@@ -21,36 +21,56 @@ local ____bonus = require("engine.internal.unit.bonus")
|
|
|
21
21
|
local addOrUpdateOrRemoveUnitBonus = ____bonus.addOrUpdateOrRemoveUnitBonus
|
|
22
22
|
local getUnitBonus = ____bonus.getUnitBonus
|
|
23
23
|
local removeUnitBonus = ____bonus.removeUnitBonus
|
|
24
|
+
local ____linked_2Dmap = require("utility.linked-map")
|
|
25
|
+
local LinkedMap = ____linked_2Dmap.LinkedMap
|
|
24
26
|
local safeCall = warpack.safeCall
|
|
25
|
-
local
|
|
26
|
-
local
|
|
27
|
-
local
|
|
28
|
-
local
|
|
27
|
+
local createBehaviorFunctionsByUnitTypeId = {}
|
|
28
|
+
local behaviorsByOwningPlayerEvent = {}
|
|
29
|
+
local listenerByBehaviorByOwningPlayerEvent = {}
|
|
30
|
+
local owningPlayerEventsByBehavior = {}
|
|
31
|
+
local behaviorsByInRangeUnitEvent = {}
|
|
32
|
+
local rangeByBehaviorByInRangeUnitEvent = {}
|
|
33
|
+
local listenerByBehaviorByInRangeUnitEvent = {}
|
|
34
|
+
local inRangeUnitEventsByBehavior = {}
|
|
29
35
|
____exports.UnitBehavior = __TS__Class()
|
|
30
36
|
local UnitBehavior = ____exports.UnitBehavior
|
|
31
37
|
UnitBehavior.name = "UnitBehavior"
|
|
32
38
|
__TS__ClassExtends(UnitBehavior, Behavior)
|
|
33
|
-
function UnitBehavior.prototype.____constructor(self, unit)
|
|
34
|
-
Behavior.prototype.____constructor(self, unit)
|
|
39
|
+
function UnitBehavior.prototype.____constructor(self, unit, priority)
|
|
40
|
+
Behavior.prototype.____constructor(self, unit, priority)
|
|
35
41
|
end
|
|
36
42
|
function UnitBehavior.prototype.onDestroy(self)
|
|
37
|
-
local
|
|
38
|
-
if
|
|
39
|
-
for event in pairs(
|
|
40
|
-
local ____opt_0 =
|
|
43
|
+
local owningPlayerEvents = owningPlayerEventsByBehavior[self]
|
|
44
|
+
if owningPlayerEvents ~= nil then
|
|
45
|
+
for event in pairs(owningPlayerEvents) do
|
|
46
|
+
local ____opt_0 = behaviorsByOwningPlayerEvent[event]
|
|
41
47
|
if ____opt_0 ~= nil then
|
|
42
48
|
____opt_0:remove(self)
|
|
43
49
|
end
|
|
44
|
-
local ____opt_2 =
|
|
50
|
+
local ____opt_2 = listenerByBehaviorByOwningPlayerEvent[event]
|
|
45
51
|
if ____opt_2 ~= nil then
|
|
46
52
|
____opt_2[self] = nil
|
|
47
53
|
end
|
|
48
|
-
|
|
54
|
+
end
|
|
55
|
+
owningPlayerEventsByBehavior[self] = nil
|
|
56
|
+
end
|
|
57
|
+
local inRangeUnitEvents = inRangeUnitEventsByBehavior[self]
|
|
58
|
+
if inRangeUnitEvents ~= nil then
|
|
59
|
+
for event in pairs(inRangeUnitEvents) do
|
|
60
|
+
local ____opt_4 = behaviorsByInRangeUnitEvent[event]
|
|
49
61
|
if ____opt_4 ~= nil then
|
|
50
|
-
____opt_4
|
|
62
|
+
____opt_4:remove(self)
|
|
63
|
+
end
|
|
64
|
+
local ____opt_6 = rangeByBehaviorByInRangeUnitEvent[event]
|
|
65
|
+
if ____opt_6 ~= nil then
|
|
66
|
+
____opt_6[self] = nil
|
|
67
|
+
end
|
|
68
|
+
local ____opt_8 = listenerByBehaviorByInRangeUnitEvent[event]
|
|
69
|
+
if ____opt_8 ~= nil then
|
|
70
|
+
____opt_8[self] = nil
|
|
51
71
|
end
|
|
52
72
|
end
|
|
53
|
-
|
|
73
|
+
inRangeUnitEventsByBehavior[self] = nil
|
|
54
74
|
end
|
|
55
75
|
if self._bonusIdByBonusType ~= nil then
|
|
56
76
|
for bonusType, bonusId in pairs(self._bonusIdByBonusType) do
|
|
@@ -60,28 +80,60 @@ function UnitBehavior.prototype.onDestroy(self)
|
|
|
60
80
|
return Behavior.prototype.onDestroy(self)
|
|
61
81
|
end
|
|
62
82
|
function UnitBehavior.prototype.getUnitBonus(self, bonusType)
|
|
63
|
-
local
|
|
64
|
-
local bonusId =
|
|
83
|
+
local ____opt_10 = self._bonusIdByBonusType
|
|
84
|
+
local bonusId = ____opt_10 and ____opt_10:get(bonusType)
|
|
65
85
|
return bonusId == nil and 0 or getUnitBonus(self.object, bonusType, bonusId)
|
|
66
86
|
end
|
|
67
87
|
function UnitBehavior.prototype.addOrUpdateOrRemoveUnitBonus(self, bonusType, value)
|
|
68
88
|
local bonusIdByBonusType = self._bonusIdByBonusType
|
|
69
89
|
if bonusIdByBonusType == nil then
|
|
70
|
-
bonusIdByBonusType =
|
|
90
|
+
bonusIdByBonusType = __TS__New(LinkedMap)
|
|
71
91
|
self._bonusIdByBonusType = bonusIdByBonusType
|
|
72
92
|
end
|
|
73
|
-
bonusIdByBonusType
|
|
93
|
+
bonusIdByBonusType:put(
|
|
94
|
+
bonusType,
|
|
95
|
+
addOrUpdateOrRemoveUnitBonus(
|
|
96
|
+
self.object,
|
|
97
|
+
bonusType,
|
|
98
|
+
bonusIdByBonusType:get(bonusType),
|
|
99
|
+
value
|
|
100
|
+
)
|
|
101
|
+
)
|
|
102
|
+
end
|
|
103
|
+
function UnitBehavior.prototype.registerOwningPlayerEvent(self, event, extractPlayer, listener)
|
|
104
|
+
local listenerByBehavior = getOrPut(listenerByBehaviorByOwningPlayerEvent, event, mutableLuaMap)
|
|
105
|
+
listenerByBehavior[self] = listener
|
|
106
|
+
getOrPut(inRangeUnitEventsByBehavior, self, mutableLuaSet)[event] = true
|
|
107
|
+
local behaviors = behaviorsByOwningPlayerEvent[event]
|
|
108
|
+
if behaviors == nil then
|
|
109
|
+
event:addListener(function(...)
|
|
110
|
+
local behaviors = behaviorsByOwningPlayerEvent[event]
|
|
111
|
+
if behaviors ~= nil then
|
|
112
|
+
local player = extractPlayer(...)
|
|
113
|
+
if player ~= nil then
|
|
114
|
+
for behavior in pairs(behaviors) do
|
|
115
|
+
if behavior.unit.owner == player then
|
|
116
|
+
safeCall(behavior[listenerByBehavior[behavior]], behavior, ...)
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end)
|
|
122
|
+
behaviors = __TS__New(LinkedSet)
|
|
123
|
+
behaviorsByOwningPlayerEvent[event] = behaviors
|
|
124
|
+
end
|
|
125
|
+
behaviors:add(self)
|
|
74
126
|
end
|
|
75
127
|
function UnitBehavior.prototype.registerInRangeUnitEvent(self, event, extractUnit, range, listener)
|
|
76
|
-
local rangeByBehavior = getOrPut(
|
|
128
|
+
local rangeByBehavior = getOrPut(rangeByBehaviorByInRangeUnitEvent, event, mutableLuaMap)
|
|
77
129
|
rangeByBehavior[self] = range
|
|
78
|
-
local listenerByBehavior = getOrPut(
|
|
130
|
+
local listenerByBehavior = getOrPut(listenerByBehaviorByInRangeUnitEvent, event, mutableLuaMap)
|
|
79
131
|
listenerByBehavior[self] = listener
|
|
80
|
-
getOrPut(
|
|
81
|
-
local behaviors =
|
|
132
|
+
getOrPut(inRangeUnitEventsByBehavior, self, mutableLuaSet)[event] = true
|
|
133
|
+
local behaviors = behaviorsByInRangeUnitEvent[event]
|
|
82
134
|
if behaviors == nil then
|
|
83
135
|
event:addListener(function(...)
|
|
84
|
-
local behaviors =
|
|
136
|
+
local behaviors = behaviorsByInRangeUnitEvent[event]
|
|
85
137
|
if behaviors ~= nil then
|
|
86
138
|
local unit = extractUnit(...)
|
|
87
139
|
if unit ~= nil then
|
|
@@ -95,7 +147,7 @@ function UnitBehavior.prototype.registerInRangeUnitEvent(self, event, extractUni
|
|
|
95
147
|
end
|
|
96
148
|
end)
|
|
97
149
|
behaviors = __TS__New(LinkedSet)
|
|
98
|
-
|
|
150
|
+
behaviorsByInRangeUnitEvent[event] = behaviors
|
|
99
151
|
end
|
|
100
152
|
behaviors:add(self)
|
|
101
153
|
end
|
|
@@ -151,6 +203,8 @@ function UnitBehavior.prototype.onTargetingAbilityImpact(self, ability, source)
|
|
|
151
203
|
end
|
|
152
204
|
function UnitBehavior.prototype.onBuffGained(self, buff)
|
|
153
205
|
end
|
|
206
|
+
function UnitBehavior.prototype.onBuffLost(self, buff)
|
|
207
|
+
end
|
|
154
208
|
function UnitBehavior.prototype.onItemDropped(self, item)
|
|
155
209
|
end
|
|
156
210
|
function UnitBehavior.prototype.onItemPickedUp(self, item)
|
|
@@ -167,6 +221,21 @@ function UnitBehavior.prototype.onDeath(self, source)
|
|
|
167
221
|
end
|
|
168
222
|
function UnitBehavior.prototype.onOwnerChange(self, previousOwner)
|
|
169
223
|
end
|
|
224
|
+
function UnitBehavior.bindUnitType(self, unitTypeId, ...)
|
|
225
|
+
local args = {...}
|
|
226
|
+
local createBehaviorFunctions = createBehaviorFunctionsByUnitTypeId[unitTypeId]
|
|
227
|
+
if createBehaviorFunctions == nil then
|
|
228
|
+
createBehaviorFunctions = {}
|
|
229
|
+
createBehaviorFunctionsByUnitTypeId[unitTypeId] = createBehaviorFunctions
|
|
230
|
+
end
|
|
231
|
+
createBehaviorFunctions[#createBehaviorFunctions + 1] = function(unit)
|
|
232
|
+
return __TS__New(
|
|
233
|
+
self,
|
|
234
|
+
unit,
|
|
235
|
+
table.unpack(args)
|
|
236
|
+
)
|
|
237
|
+
end
|
|
238
|
+
end
|
|
170
239
|
__TS__SetDescriptor(
|
|
171
240
|
UnitBehavior.prototype,
|
|
172
241
|
"unit",
|
|
@@ -282,6 +351,14 @@ __TS__SetDescriptor(
|
|
|
282
351
|
____exports.UnitBehavior:forAll(unit, "onOwnerChange", previousOwner)
|
|
283
352
|
end)
|
|
284
353
|
end)(UnitBehavior)
|
|
354
|
+
Unit.onCreate:addListener(function(unit)
|
|
355
|
+
local createBehaviorFunctions = createBehaviorFunctionsByUnitTypeId[unit.typeId]
|
|
356
|
+
if createBehaviorFunctions ~= nil then
|
|
357
|
+
for ____, createBehavior in ipairs(createBehaviorFunctions) do
|
|
358
|
+
createBehavior(unit)
|
|
359
|
+
end
|
|
360
|
+
end
|
|
361
|
+
end)
|
|
285
362
|
Unit.destroyEvent:addListener(function(unit)
|
|
286
363
|
____exports.UnitBehavior:forAll(unit, "destroy")
|
|
287
364
|
end)
|
package/engine/buff.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ import { UnitBehavior } from "./behaviour/unit";
|
|
|
13
13
|
import type { Widget } from "../core/types/widget";
|
|
14
14
|
import { Destructor } from "../destroyable";
|
|
15
15
|
import { Event } from "../event";
|
|
16
|
+
import { AbilityBehavior } from "./behaviour/ability";
|
|
16
17
|
export type BuffConstructor<T extends Buff<any> = Buff<any>, Args extends any[] = any> = OmitConstructor<typeof Buff<any>> & (new (...args: Args) => T);
|
|
17
18
|
type EnumParameterValueType<T extends number> = T | AbilityEnumLevelField<T>;
|
|
18
19
|
type NumberParameterValueType = number | AbilityNumberField | AbilityNumberLevelField;
|
|
@@ -30,8 +31,10 @@ export type BuffParameters<T extends Buff<any> = Buff> = Buff extends T ? {
|
|
|
30
31
|
source?: Unit;
|
|
31
32
|
behaviorConstructors?: (new (unit: Unit) => UnitBehavior)[];
|
|
32
33
|
abilityTypeIds?: Record<AbilityTypeId, {
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
readonly fields?: [
|
|
35
|
+
AbilityNumberField | AbilityNumberLevelField,
|
|
36
|
+
NumberParameterValueType
|
|
37
|
+
][];
|
|
35
38
|
/** Default `true`. */
|
|
36
39
|
readonly isButtonVisible?: boolean;
|
|
37
40
|
/** Default is the level of the source ability or 0 if it is absent. */
|
|
@@ -56,6 +59,7 @@ export type BuffParameters<T extends Buff<any> = Buff> = Buff extends T ? {
|
|
|
56
59
|
armorIncreaseFactor?: NumberParameterValueType;
|
|
57
60
|
attackSpeedIncreaseFactor?: NumberParameterValueType;
|
|
58
61
|
movementSpeedIncreaseFactor?: NumberParameterValueType;
|
|
62
|
+
manaRegenerationRateIncreaseFactor?: NumberParameterValueType;
|
|
59
63
|
evasionProbability?: NumberParameterValueType;
|
|
60
64
|
missProbability?: NumberParameterValueType;
|
|
61
65
|
damageFactor?: NumberParameterValueType;
|
|
@@ -141,7 +145,7 @@ export type BuffConstructorParameters<AdditionalParameters extends BuffAdditiona
|
|
|
141
145
|
polarity: BuffPolarityParameterType,
|
|
142
146
|
resistanceType: BuffResistanceTypeParameterType,
|
|
143
147
|
...abilityOrParameters: [
|
|
144
|
-
ability?: Ability,
|
|
148
|
+
ability?: Ability | AbilityBehavior,
|
|
145
149
|
parameters?: BuffParameters & Omit<AdditionalParameters, keyof BuffParameters>
|
|
146
150
|
] | [parameters?: BuffParameters & Omit<AdditionalParameters, keyof BuffParameters>]
|
|
147
151
|
];
|
|
@@ -264,6 +268,8 @@ export declare class Buff<AdditionalParameters extends Prohibit<Record<string, a
|
|
|
264
268
|
set movementSpeedIncreaseFactor(movementSpeedIncreaseFactor: number);
|
|
265
269
|
get evasionProbability(): number;
|
|
266
270
|
set evasionProbability(evasionProbability: number);
|
|
271
|
+
get manaRegenerationRateIncreaseFactor(): number;
|
|
272
|
+
set manaRegenerationRateIncreaseFactor(manaRegenerationRateIncreaseFactor: number);
|
|
267
273
|
get duration(): number;
|
|
268
274
|
get remainingDuration(): number;
|
|
269
275
|
set remainingDuration(remainingDuration: number);
|