warscript 0.0.1-dev.fa6dee5 → 0.0.1-dev.fd21394
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/util.lua +1 -1
- package/decl/index.d.ts +1 -0
- package/engine/behavior.d.ts +4 -4
- package/engine/behaviour/unit.d.ts +3 -2
- package/engine/behaviour/unit.lua +7 -0
- package/engine/buff.lua +8 -10
- package/engine/internal/unit.d.ts +1 -1
- package/engine/internal/unit.lua +34 -26
- package/event.d.ts +2 -2
- package/event.lua +9 -5
- package/package.json +1 -1
package/core/util.lua
CHANGED
package/decl/index.d.ts
CHANGED
package/engine/behavior.d.ts
CHANGED
|
@@ -20,9 +20,9 @@ export declare abstract class Behavior<T extends AnyNotNil, PeriodicActionParame
|
|
|
20
20
|
static getFirst<T extends Behavior<AnyNotNil>, ConstructorParameters extends any[], Count extends [number] | []>(this: BehaviorConstructor<T, ConstructorParameters>, object: T extends Behavior<infer Object> ? Object : never, ...[count]: Count): Count extends [number] ? T[] : T | undefined;
|
|
21
21
|
static getLast<T extends Behavior<AnyNotNil>, ConstructorParameters extends any[]>(this: BehaviorConstructor<T, ConstructorParameters>, object: T extends Behavior<infer Object> ? Object : never): T | undefined;
|
|
22
22
|
static getAll<T extends Behavior<AnyNotNil>, ConstructorParameters extends any[]>(this: BehaviorConstructor<T, ConstructorParameters>, object: T extends Behavior<infer Object> ? Object : never): T[];
|
|
23
|
-
static forFirst<T extends Behavior<
|
|
24
|
-
static forFirst<T extends Behavior<
|
|
25
|
-
static forAll<T extends Behavior<
|
|
26
|
-
static forAll<T extends Behavior<
|
|
23
|
+
static forFirst<T extends Behavior<AnyNotNil>, ConstructorParameters extends any[], ConsumerParameters extends any[]>(this: BehaviorConstructor<T, ConstructorParameters>, object: T extends Behavior<infer Object> ? Object : never, count: number, consumer: (this: void, behavior: T, ...parameters: ConsumerParameters) => any, ...parameters: ConsumerParameters): number;
|
|
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
|
+
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
|
+
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
27
|
}
|
|
28
28
|
export {};
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { Behavior } from "../behavior";
|
|
3
3
|
import { Ability } from "../internal/ability";
|
|
4
4
|
import { DamageEvent, DamagingEvent, Unit } from "../internal/unit";
|
|
5
|
+
import "../internal/unit+ability";
|
|
5
6
|
import "../internal/unit-missile-launch";
|
|
6
7
|
export type UnitBehaviorConstructor<Args extends any[]> = new (unit: Unit, ...args: Args) => UnitBehavior;
|
|
7
8
|
export declare abstract class UnitBehavior<PeriodicActionParameters extends any[] = any[]> extends Behavior<Unit, PeriodicActionParameters> {
|
|
@@ -13,8 +14,8 @@ export declare abstract class UnitBehavior<PeriodicActionParameters extends any[
|
|
|
13
14
|
onDamageDealt(target: Unit, event: DamageEvent): void;
|
|
14
15
|
onDamageReceiving(source: Unit | undefined, event: DamagingEvent): void;
|
|
15
16
|
onDamageReceived(source: Unit | undefined, event: DamageEvent): void;
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
onAbilityGained(ability: Ability): void;
|
|
18
|
+
onAbilityLost(ability: Ability): void;
|
|
18
19
|
onKill(target: Unit): void;
|
|
19
20
|
onDeath(source: Unit | undefined): void;
|
|
20
21
|
}
|
|
@@ -7,6 +7,7 @@ local ____behavior = require("engine.behavior")
|
|
|
7
7
|
local Behavior = ____behavior.Behavior
|
|
8
8
|
local ____unit = require("engine.internal.unit")
|
|
9
9
|
local Unit = ____unit.Unit
|
|
10
|
+
require("engine.internal.unit+ability")
|
|
10
11
|
require("engine.internal.unit-missile-launch")
|
|
11
12
|
____exports.UnitBehavior = __TS__Class()
|
|
12
13
|
local UnitBehavior = ____exports.UnitBehavior
|
|
@@ -62,6 +63,12 @@ __TS__SetDescriptor(
|
|
|
62
63
|
end
|
|
63
64
|
____exports.UnitBehavior:forAll(target, "onDamageReceived", source, event)
|
|
64
65
|
end)
|
|
66
|
+
Unit.abilityGainedEvent:addListener(function(source, target)
|
|
67
|
+
____exports.UnitBehavior:forAll(source, "onAbilityGained", target)
|
|
68
|
+
end)
|
|
69
|
+
Unit.abilityLostEvent:addListener(function(source, target)
|
|
70
|
+
____exports.UnitBehavior:forAll(source, "onAbilityLost", target)
|
|
71
|
+
end)
|
|
65
72
|
Unit.deathEvent:addListener(function(target, source)
|
|
66
73
|
if source ~= nil then
|
|
67
74
|
____exports.UnitBehavior:forAll(source, "onKill", target)
|
package/engine/buff.lua
CHANGED
|
@@ -1035,24 +1035,22 @@ __TS__SetDescriptor(
|
|
|
1035
1035
|
true
|
|
1036
1036
|
);
|
|
1037
1037
|
(function(self)
|
|
1038
|
+
local function destroyBuffIfNeeded(buff)
|
|
1039
|
+
if getUnitAbility(buff[100].handle, buff.typeId) ~= buff.handle then
|
|
1040
|
+
buff:destroy()
|
|
1041
|
+
end
|
|
1042
|
+
end
|
|
1038
1043
|
____exports.checkBuff = function(unit, buffTypeId)
|
|
1039
1044
|
local buffByTypeId = buffByTypeIdByUnit[unit]
|
|
1040
1045
|
if buffByTypeId ~= nil then
|
|
1041
1046
|
local buff = buffByTypeId[buffTypeId]
|
|
1042
|
-
if buff ~= nil
|
|
1043
|
-
buff
|
|
1047
|
+
if buff ~= nil then
|
|
1048
|
+
destroyBuffIfNeeded(buff)
|
|
1044
1049
|
end
|
|
1045
1050
|
end
|
|
1046
1051
|
end
|
|
1047
1052
|
____exports.checkBuffs = function(unit)
|
|
1048
|
-
|
|
1049
|
-
if buffByTypeId ~= nil then
|
|
1050
|
-
for ____, buff in pairs(buffByTypeId) do
|
|
1051
|
-
if getUnitAbility(unit.handle, buff.typeId) ~= buff.handle then
|
|
1052
|
-
buff:destroy()
|
|
1053
|
-
end
|
|
1054
|
-
end
|
|
1055
|
-
end
|
|
1053
|
+
____exports.Buff:forAll(unit, destroyBuffIfNeeded)
|
|
1056
1054
|
end
|
|
1057
1055
|
Unit.abilityChannelingStartEvent:addListener(
|
|
1058
1056
|
0,
|
|
@@ -227,7 +227,7 @@ export declare class Unit extends Handle<junit> {
|
|
|
227
227
|
isSelected(player: Player): boolean;
|
|
228
228
|
explode(): void;
|
|
229
229
|
kill(): void;
|
|
230
|
-
revive(
|
|
230
|
+
revive(x: number, y: number, doEffect?: boolean): void;
|
|
231
231
|
healTarget(target: Widget, amount: number): void;
|
|
232
232
|
useItem(item: Item): boolean;
|
|
233
233
|
issueImmediateOrder(order: number): boolean;
|
package/engine/internal/unit.lua
CHANGED
|
@@ -7,6 +7,9 @@ local __TS__Class = ____lualib.__TS__Class
|
|
|
7
7
|
local __TS__ClassExtends = ____lualib.__TS__ClassExtends
|
|
8
8
|
local __TS__SetDescriptor = ____lualib.__TS__SetDescriptor
|
|
9
9
|
local __TS__ArraySetLength = ____lualib.__TS__ArraySetLength
|
|
10
|
+
local __TS__SparseArrayNew = ____lualib.__TS__SparseArrayNew
|
|
11
|
+
local __TS__SparseArrayPush = ____lualib.__TS__SparseArrayPush
|
|
12
|
+
local __TS__SparseArraySpread = ____lualib.__TS__SparseArraySpread
|
|
10
13
|
local __TS__InstanceOf = ____lualib.__TS__InstanceOf
|
|
11
14
|
local __TS__ObjectDefineProperty = ____lualib.__TS__ObjectDefineProperty
|
|
12
15
|
local Set = ____lualib.Set
|
|
@@ -279,16 +282,14 @@ function UnitTriggerEvent.prototype.____constructor(self, eventType, c)
|
|
|
279
282
|
end
|
|
280
283
|
local function dispatch(event, idGetter, argsGetter)
|
|
281
284
|
local initialized = false
|
|
282
|
-
local x = {}
|
|
283
285
|
return setmetatable(
|
|
284
|
-
|
|
286
|
+
{},
|
|
285
287
|
{
|
|
286
288
|
__index = function(self, id)
|
|
287
289
|
if type(id) ~= "number" then
|
|
288
290
|
return event[id]
|
|
289
291
|
end
|
|
290
292
|
if not initialized then
|
|
291
|
-
local invoke = Event.invoke
|
|
292
293
|
event:addListener(function(...)
|
|
293
294
|
local id = idGetter(...)
|
|
294
295
|
local dispatched = rawget(self, id)
|
|
@@ -326,7 +327,6 @@ local function dispatchAbility(event)
|
|
|
326
327
|
return event[id]
|
|
327
328
|
end
|
|
328
329
|
if not initialized then
|
|
329
|
-
local invoke = Event.invoke
|
|
330
330
|
event:addListener(function(unit, ability, ...)
|
|
331
331
|
local dispatched = rawget(self, ability.typeId)
|
|
332
332
|
if dispatched ~= nil then
|
|
@@ -817,8 +817,15 @@ end
|
|
|
817
817
|
function Unit.prototype.kill(self)
|
|
818
818
|
killUnit(self.handle)
|
|
819
819
|
end
|
|
820
|
-
function Unit.prototype.revive(self,
|
|
821
|
-
|
|
820
|
+
function Unit.prototype.revive(self, x, y, doEffect)
|
|
821
|
+
local ____ReviveHero_4 = ReviveHero
|
|
822
|
+
local ____array_3 = __TS__SparseArrayNew(self.handle, x, y)
|
|
823
|
+
local ____doEffect_2 = doEffect
|
|
824
|
+
if ____doEffect_2 == nil then
|
|
825
|
+
____doEffect_2 = false
|
|
826
|
+
end
|
|
827
|
+
__TS__SparseArrayPush(____array_3, ____doEffect_2)
|
|
828
|
+
____ReviveHero_4(__TS__SparseArraySpread(____array_3))
|
|
822
829
|
end
|
|
823
830
|
function Unit.prototype.healTarget(self, target, amount)
|
|
824
831
|
if __TS__InstanceOf(target, ____exports.Unit) and target:hasAbility(fourCC("BIhm")) then
|
|
@@ -1385,13 +1392,13 @@ __TS__SetDescriptor(
|
|
|
1385
1392
|
end,
|
|
1386
1393
|
set = function(self, isTeamGlowVisible)
|
|
1387
1394
|
showUnitTeamGlow(self.handle, isTeamGlowVisible)
|
|
1388
|
-
local
|
|
1395
|
+
local ____temp_5
|
|
1389
1396
|
if not isTeamGlowVisible then
|
|
1390
|
-
|
|
1397
|
+
____temp_5 = true
|
|
1391
1398
|
else
|
|
1392
|
-
|
|
1399
|
+
____temp_5 = nil
|
|
1393
1400
|
end
|
|
1394
|
-
self[105] =
|
|
1401
|
+
self[105] = ____temp_5
|
|
1395
1402
|
end
|
|
1396
1403
|
},
|
|
1397
1404
|
true
|
|
@@ -2055,7 +2062,6 @@ Unit.onDecay = __TS__New(
|
|
|
2055
2062
|
Unit.onResurrect = __TS__New(
|
|
2056
2063
|
InitializingEvent,
|
|
2057
2064
|
function(event)
|
|
2058
|
-
local invoke = Event.invoke
|
|
2059
2065
|
local dead = setmetatable({}, {__mode = "k"})
|
|
2060
2066
|
____exports.Unit.deathEvent:addListener(function(unit)
|
|
2061
2067
|
dead[unit] = true
|
|
@@ -2071,10 +2077,15 @@ Unit.onResurrect = __TS__New(
|
|
|
2071
2077
|
Unit.morphEvent = __TS__New(
|
|
2072
2078
|
InitializingEvent,
|
|
2073
2079
|
function(event)
|
|
2080
|
+
local function ifNotLeft(unit)
|
|
2081
|
+
local handle = unit.handle
|
|
2082
|
+
if getUnitAbilityLevel(handle, leaveDetectAbilityId) ~= 0 and unitAddAbility(handle, morphDetectAbilityId) then
|
|
2083
|
+
invoke(event, unit)
|
|
2084
|
+
end
|
|
2085
|
+
end
|
|
2074
2086
|
____exports.Unit.onImmediateOrder[orderId("undefend")]:addListener(function(unit)
|
|
2075
2087
|
if getUnitAbilityLevel(unit.handle, morphDetectAbilityId) == 0 then
|
|
2076
|
-
|
|
2077
|
-
Timer:run(Event.invoke, event, unit)
|
|
2088
|
+
Timer:run(ifNotLeft, unit)
|
|
2078
2089
|
end
|
|
2079
2090
|
end)
|
|
2080
2091
|
end
|
|
@@ -2112,27 +2123,26 @@ Unit.onSpellEffect = dispatchId(__TS__New(
|
|
|
2112
2123
|
Unit.onTargetCast = dispatchId(__TS__New(
|
|
2113
2124
|
InitializingEvent,
|
|
2114
2125
|
function(event)
|
|
2115
|
-
local invoke = Event.invoke
|
|
2116
2126
|
local function listener(unit, id)
|
|
2117
|
-
local
|
|
2127
|
+
local ____GetSpellTargetUnit_result_8
|
|
2118
2128
|
if GetSpellTargetUnit() then
|
|
2119
|
-
|
|
2129
|
+
____GetSpellTargetUnit_result_8 = ____exports.Unit:of(GetSpellTargetUnit())
|
|
2120
2130
|
else
|
|
2121
|
-
local
|
|
2131
|
+
local ____GetSpellTargetItem_result_7
|
|
2122
2132
|
if GetSpellTargetItem() then
|
|
2123
|
-
|
|
2133
|
+
____GetSpellTargetItem_result_7 = Item:of(GetSpellTargetItem())
|
|
2124
2134
|
else
|
|
2125
|
-
local
|
|
2135
|
+
local ____GetSpellTargetDestructable_result_6
|
|
2126
2136
|
if GetSpellTargetDestructable() then
|
|
2127
|
-
|
|
2137
|
+
____GetSpellTargetDestructable_result_6 = Destructable:of(GetSpellTargetDestructable())
|
|
2128
2138
|
else
|
|
2129
|
-
|
|
2139
|
+
____GetSpellTargetDestructable_result_6 = nil
|
|
2130
2140
|
end
|
|
2131
|
-
|
|
2141
|
+
____GetSpellTargetItem_result_7 = ____GetSpellTargetDestructable_result_6
|
|
2132
2142
|
end
|
|
2133
|
-
|
|
2143
|
+
____GetSpellTargetUnit_result_8 = ____GetSpellTargetItem_result_7
|
|
2134
2144
|
end
|
|
2135
|
-
local target =
|
|
2145
|
+
local target = ____GetSpellTargetUnit_result_8
|
|
2136
2146
|
if target then
|
|
2137
2147
|
invoke(event, unit, id, target)
|
|
2138
2148
|
end
|
|
@@ -2329,7 +2339,6 @@ Unit.autoAttackStartEvent = __TS__New(
|
|
|
2329
2339
|
)
|
|
2330
2340
|
Unit.onDamaging = (function()
|
|
2331
2341
|
local event = __TS__New(Event)
|
|
2332
|
-
local invoke = Event.invoke
|
|
2333
2342
|
local trigger = CreateTrigger()
|
|
2334
2343
|
TriggerRegisterAnyUnitEventBJ(trigger, EVENT_PLAYER_UNIT_DAMAGING)
|
|
2335
2344
|
TriggerAddCondition(
|
|
@@ -2428,7 +2437,6 @@ end)()
|
|
|
2428
2437
|
Unit.onDamage = __TS__New(
|
|
2429
2438
|
InitializingEvent,
|
|
2430
2439
|
function(event)
|
|
2431
|
-
local invoke = Event.invoke
|
|
2432
2440
|
local trigger = CreateTrigger()
|
|
2433
2441
|
TriggerRegisterAnyUnitEventBJ(trigger, EVENT_PLAYER_UNIT_DAMAGED)
|
|
2434
2442
|
TriggerAddCondition(
|
package/event.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** @noSelfInFile */
|
|
2
|
-
export type EventListener<T extends any[]> = (...args: T) => void;
|
|
2
|
+
export type EventListener<T extends any[]> = (this: void, ...args: T) => void;
|
|
3
3
|
export declare const enum EventListenerPriority {
|
|
4
4
|
LOWEST = 0,
|
|
5
5
|
LOW = 1,
|
|
@@ -37,7 +37,7 @@ export type EventDispatchTable<EventType extends Event<any>, KeyType extends num
|
|
|
37
37
|
};
|
|
38
38
|
export type DispatchingEvent<P extends any[], T extends Event<P> = Event<P>, S extends Event<P> = Event<P>> = T & EventDispatchTable<S>;
|
|
39
39
|
export declare const createDispatchingEvent: {
|
|
40
|
-
<T extends Event<any>, S extends Event<EventParameters<T>>>(underlyingEvent: T, extractKey: (...args: EventParameters<T>) => number, ...createEvent: [...(Event<any> extends S ? [(() => S)?] : [() => S])]): DispatchingEvent<EventParameters<T>, T>;
|
|
40
|
+
<T extends Event<any>, S extends Event<EventParameters<T>>>(underlyingEvent: T, extractKey: (this: void, ...args: EventParameters<T>) => number, invokeEvent?: (this: void, event: S, ...args: EventParameters<T>) => unknown, ...createEvent: [...(Event<any> extends S ? [((this: void) => S)?] : [(this: void) => S])]): DispatchingEvent<EventParameters<T>, T, S>;
|
|
41
41
|
};
|
|
42
42
|
export declare class DependentInitializingEvent<T extends any[], R extends any[]> extends InitializingEvent<R, EventListener<T>> {
|
|
43
43
|
constructor(underlyingEvent: Event<T>, priority: EventListenerPriority, collector: (...args: T) => LuaMultiReturn<[false] | [true, ...R]>);
|
package/event.lua
CHANGED
|
@@ -146,8 +146,13 @@ function TriggerEvent.prototype.____constructor(self, r, c)
|
|
|
146
146
|
end
|
|
147
147
|
)
|
|
148
148
|
end
|
|
149
|
-
____exports.createDispatchingEvent = function(underlyingEvent, extractKey, createEvent)
|
|
150
|
-
|
|
149
|
+
____exports.createDispatchingEvent = function(underlyingEvent, extractKey, invokeEvent, createEvent)
|
|
150
|
+
if invokeEvent == nil then
|
|
151
|
+
invokeEvent = ____exports.Event.invoke
|
|
152
|
+
end
|
|
153
|
+
if createEvent == nil then
|
|
154
|
+
createEvent = function() return __TS__New(____exports.Event) end
|
|
155
|
+
end
|
|
151
156
|
local initialized = false
|
|
152
157
|
return setmetatable(
|
|
153
158
|
{},
|
|
@@ -157,17 +162,16 @@ ____exports.createDispatchingEvent = function(underlyingEvent, extractKey, creat
|
|
|
157
162
|
return underlyingEvent[id]
|
|
158
163
|
end
|
|
159
164
|
if not initialized then
|
|
160
|
-
local invoke = ____exports.Event.invoke
|
|
161
165
|
underlyingEvent:addListener(function(...)
|
|
162
166
|
local key = extractKey(...)
|
|
163
167
|
local event = rawget(self, key)
|
|
164
168
|
if event then
|
|
165
|
-
|
|
169
|
+
invokeEvent(event, ...)
|
|
166
170
|
end
|
|
167
171
|
end)
|
|
168
172
|
initialized = true
|
|
169
173
|
end
|
|
170
|
-
local event =
|
|
174
|
+
local event = createEvent()
|
|
171
175
|
rawset(self, id, event)
|
|
172
176
|
return event
|
|
173
177
|
end,
|
package/package.json
CHANGED