warscript 0.0.1-dev.9e72e49 → 0.0.1-dev.a21905e
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/engine/behaviour/unit.d.ts +5 -0
- package/engine/behaviour/unit.lua +20 -0
- package/engine/internal/item+owner.lua +2 -2
- package/engine/internal/unit/item.d.ts +22 -0
- package/engine/internal/unit/item.lua +63 -0
- package/engine/internal/unit+ability.lua +2 -2
- package/engine/internal/unit.d.ts +4 -3
- package/engine/internal/unit.lua +10 -5
- package/engine/unit.d.ts +1 -0
- package/engine/unit.lua +1 -0
- package/objutil/buff.lua +1 -1
- package/package.json +1 -1
|
@@ -4,6 +4,7 @@ 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
|
+
import { Item } from "../internal/item";
|
|
7
8
|
export type UnitBehaviorConstructor<Args extends any[]> = new (unit: Unit, ...args: Args) => UnitBehavior;
|
|
8
9
|
export declare abstract class UnitBehavior<PeriodicActionParameters extends any[] = any[]> extends Behavior<Unit, PeriodicActionParameters> {
|
|
9
10
|
constructor(unit: Unit);
|
|
@@ -16,6 +17,10 @@ export declare abstract class UnitBehavior<PeriodicActionParameters extends any[
|
|
|
16
17
|
onDamageReceived(source: Unit | undefined, event: DamageEvent): void;
|
|
17
18
|
onAbilityGained(ability: Ability): void;
|
|
18
19
|
onAbilityLost(ability: Ability): void;
|
|
20
|
+
onItemDropped(item: Item): void;
|
|
21
|
+
onItemPickedUp(item: Item): void;
|
|
22
|
+
onItemUsed(item: Item): void;
|
|
23
|
+
onItemStacked(item: Item): void;
|
|
19
24
|
onKill(target: Unit): void;
|
|
20
25
|
onDeath(source: Unit | undefined): void;
|
|
21
26
|
}
|
|
@@ -32,6 +32,14 @@ function UnitBehavior.prototype.onAbilityGained(self, ability)
|
|
|
32
32
|
end
|
|
33
33
|
function UnitBehavior.prototype.onAbilityLost(self, ability)
|
|
34
34
|
end
|
|
35
|
+
function UnitBehavior.prototype.onItemDropped(self, item)
|
|
36
|
+
end
|
|
37
|
+
function UnitBehavior.prototype.onItemPickedUp(self, item)
|
|
38
|
+
end
|
|
39
|
+
function UnitBehavior.prototype.onItemUsed(self, item)
|
|
40
|
+
end
|
|
41
|
+
function UnitBehavior.prototype.onItemStacked(self, item)
|
|
42
|
+
end
|
|
35
43
|
function UnitBehavior.prototype.onKill(self, target)
|
|
36
44
|
end
|
|
37
45
|
function UnitBehavior.prototype.onDeath(self, source)
|
|
@@ -75,6 +83,18 @@ __TS__SetDescriptor(
|
|
|
75
83
|
end
|
|
76
84
|
____exports.UnitBehavior:forAll(target, "onDeath", source)
|
|
77
85
|
end)
|
|
86
|
+
Unit.itemDroppedEvent:addListener(function(unit, item)
|
|
87
|
+
____exports.UnitBehavior:forAll(unit, "onItemDropped", item)
|
|
88
|
+
end)
|
|
89
|
+
Unit.itemPickedUpEvent:addListener(function(unit, item)
|
|
90
|
+
____exports.UnitBehavior:forAll(unit, "onItemPickedUp", item)
|
|
91
|
+
end)
|
|
92
|
+
Unit.itemUsedEvent:addListener(function(unit, item)
|
|
93
|
+
____exports.UnitBehavior:forAll(unit, "onItemUsed", item)
|
|
94
|
+
end)
|
|
95
|
+
Unit.itemStackedEvent:addListener(function(unit, item)
|
|
96
|
+
____exports.UnitBehavior:forAll(unit, "onItemStacked", item)
|
|
97
|
+
end)
|
|
78
98
|
end)(UnitBehavior)
|
|
79
99
|
Unit.destroyEvent:addListener(function(unit)
|
|
80
100
|
____exports.UnitBehavior:forAll(unit, "destroy")
|
|
@@ -6,10 +6,10 @@ local Item = ____item.Item
|
|
|
6
6
|
local ____unit = require("engine.internal.unit")
|
|
7
7
|
local Unit = ____unit.Unit
|
|
8
8
|
local ownerByItem = setmetatable({}, {__mode = "kv"})
|
|
9
|
-
Unit.
|
|
9
|
+
Unit.itemPickedUpEvent:addListener(function(unit, item)
|
|
10
10
|
ownerByItem[item] = unit
|
|
11
11
|
end)
|
|
12
|
-
Unit.
|
|
12
|
+
Unit.itemDroppedEvent:addListener(function(unit, item)
|
|
13
13
|
ownerByItem[item] = nil
|
|
14
14
|
end)
|
|
15
15
|
__TS__ObjectDefineProperty(
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** @noSelfInFile */
|
|
2
|
+
import { Item } from "../item";
|
|
3
|
+
export interface UnitItems extends ReadonlyArray<Item | undefined> {
|
|
4
|
+
readonly length: 0 | 1 | 2 | 3 | 4 | 5 | 6;
|
|
5
|
+
[0]: Item | undefined;
|
|
6
|
+
[1]: Item | undefined;
|
|
7
|
+
[2]: Item | undefined;
|
|
8
|
+
[3]: Item | undefined;
|
|
9
|
+
[4]: Item | undefined;
|
|
10
|
+
[5]: Item | undefined;
|
|
11
|
+
}
|
|
12
|
+
export declare class UnitItems {
|
|
13
|
+
constructor(handle: junit);
|
|
14
|
+
protected __newindex(slot: number, item: Item | undefined): void;
|
|
15
|
+
protected __index(key: string | number): unknown;
|
|
16
|
+
protected __len(): number;
|
|
17
|
+
}
|
|
18
|
+
declare module "../unit" {
|
|
19
|
+
interface Unit {
|
|
20
|
+
readonly items: UnitItems;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
local ____lualib = require("lualib_bundle")
|
|
2
|
+
local __TS__Class = ____lualib.__TS__Class
|
|
3
|
+
local __TS__New = ____lualib.__TS__New
|
|
4
|
+
local __TS__ObjectDefineProperty = ____lualib.__TS__ObjectDefineProperty
|
|
5
|
+
local ____exports = {}
|
|
6
|
+
local ____item = require("engine.internal.item")
|
|
7
|
+
local Item = ____item.Item
|
|
8
|
+
local ____unit = require("engine.internal.unit")
|
|
9
|
+
local Unit = ____unit.Unit
|
|
10
|
+
local rawset = _G.rawset
|
|
11
|
+
local ____type = _G.type
|
|
12
|
+
local isItemPowerup = IsItemPowerup
|
|
13
|
+
local setItemBooleanField = BlzSetItemBooleanField
|
|
14
|
+
local unitAddItem = UnitAddItem
|
|
15
|
+
local unitDropItemSlot = UnitDropItemSlot
|
|
16
|
+
local unitInventorySize = UnitInventorySize
|
|
17
|
+
local unitItemInSlot = UnitItemInSlot
|
|
18
|
+
local unitRemoveItemFromSlot = UnitRemoveItemFromSlot
|
|
19
|
+
local handleByUnitItems = setmetatable({}, {__mode = "k"})
|
|
20
|
+
____exports.UnitItems = __TS__Class()
|
|
21
|
+
local UnitItems = ____exports.UnitItems
|
|
22
|
+
UnitItems.name = "UnitItems"
|
|
23
|
+
function UnitItems.prototype.____constructor(self, handle)
|
|
24
|
+
handleByUnitItems[self] = handle
|
|
25
|
+
end
|
|
26
|
+
function UnitItems.prototype.__newindex(self, slot, item)
|
|
27
|
+
local handle = handleByUnitItems[self]
|
|
28
|
+
if slot < 0 or slot >= unitInventorySize(handle) then
|
|
29
|
+
return
|
|
30
|
+
end
|
|
31
|
+
unitRemoveItemFromSlot(handle, slot)
|
|
32
|
+
if item ~= nil then
|
|
33
|
+
local itemHandle = item.handle
|
|
34
|
+
local isPowerup = isItemPowerup(itemHandle)
|
|
35
|
+
if isPowerup then
|
|
36
|
+
setItemBooleanField(itemHandle, ITEM_BF_USE_AUTOMATICALLY_WHEN_ACQUIRED, false)
|
|
37
|
+
end
|
|
38
|
+
unitAddItem(handle, itemHandle)
|
|
39
|
+
unitDropItemSlot(handle, itemHandle, slot)
|
|
40
|
+
if isPowerup then
|
|
41
|
+
setItemBooleanField(itemHandle, ITEM_BF_USE_AUTOMATICALLY_WHEN_ACQUIRED, true)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
function UnitItems.prototype.__index(self, key)
|
|
46
|
+
if ____type(key) == "number" then
|
|
47
|
+
return Item:of(unitItemInSlot(handleByUnitItems[self], key))
|
|
48
|
+
end
|
|
49
|
+
return rawget(____exports.UnitItems.prototype, key)
|
|
50
|
+
end
|
|
51
|
+
function UnitItems.prototype.__len(self)
|
|
52
|
+
return unitInventorySize(handleByUnitItems[self])
|
|
53
|
+
end
|
|
54
|
+
__TS__ObjectDefineProperty(
|
|
55
|
+
Unit.prototype,
|
|
56
|
+
"items",
|
|
57
|
+
{get = function(self)
|
|
58
|
+
local items = __TS__New(____exports.UnitItems, self.handle)
|
|
59
|
+
rawset(self, "items", items)
|
|
60
|
+
return items
|
|
61
|
+
end}
|
|
62
|
+
)
|
|
63
|
+
return ____exports
|
|
@@ -40,7 +40,7 @@ ItemAbility.onCreate:addListener(
|
|
|
40
40
|
end
|
|
41
41
|
end
|
|
42
42
|
)
|
|
43
|
-
Unit.
|
|
43
|
+
Unit.itemPickedUpEvent:addListener(
|
|
44
44
|
0,
|
|
45
45
|
function(unit, item)
|
|
46
46
|
for ____, ability in ipairs(item.abilities) do
|
|
@@ -48,7 +48,7 @@ Unit.onItemPickup:addListener(
|
|
|
48
48
|
end
|
|
49
49
|
end
|
|
50
50
|
)
|
|
51
|
-
Unit.
|
|
51
|
+
Unit.itemDroppedEvent:addListener(
|
|
52
52
|
4,
|
|
53
53
|
function(unit, item)
|
|
54
54
|
for ____, ability in ipairs(item.abilities) do
|
|
@@ -323,9 +323,10 @@ export declare class Unit extends Handle<junit> {
|
|
|
323
323
|
static readonly autoAttackStartEvent: UnitTriggerEvent<[Unit]>;
|
|
324
324
|
static readonly onDamaging: Event<[source: Unit | undefined, target: Unit, event: DamagingEvent]>;
|
|
325
325
|
static readonly onDamage: InitializingEvent<[source: Unit | undefined, target: Unit, event: DamageEvent], jtrigger>;
|
|
326
|
-
static
|
|
327
|
-
static
|
|
328
|
-
static
|
|
326
|
+
static itemDroppedEvent: UnitTriggerEvent<[Item]>;
|
|
327
|
+
static itemPickedUpEvent: UnitTriggerEvent<[Item]>;
|
|
328
|
+
static itemUsedEvent: UnitTriggerEvent<[Item]>;
|
|
329
|
+
static itemStackedEvent: UnitTriggerEvent<[Item]>;
|
|
329
330
|
static get onCreate(): EventDispatcher<[Unit], [Unit]>;
|
|
330
331
|
static get destroyEvent(): EventDispatcher<[Unit], [Unit]>;
|
|
331
332
|
getField(field: junitintegerfield | junitrealfield): number;
|
package/engine/internal/unit.lua
CHANGED
|
@@ -865,7 +865,7 @@ function Unit.prototype.dropItemSlot(self, item, slot)
|
|
|
865
865
|
return UnitDropItemSlot(self.handle, item.handle, slot)
|
|
866
866
|
end
|
|
867
867
|
function Unit.prototype.itemInSlot(self, slot)
|
|
868
|
-
return Item:of(
|
|
868
|
+
return Item:of(unitItemInSlot(self.handle, slot))
|
|
869
869
|
end
|
|
870
870
|
function Unit.prototype.addAbility(self, abilityId)
|
|
871
871
|
if unitAddAbility(self.handle, abilityId) then
|
|
@@ -2503,7 +2503,7 @@ Unit.onDamage = __TS__New(
|
|
|
2503
2503
|
DestroyTrigger(trigger)
|
|
2504
2504
|
end
|
|
2505
2505
|
)
|
|
2506
|
-
Unit.
|
|
2506
|
+
Unit.itemDroppedEvent = __TS__New(
|
|
2507
2507
|
____exports.UnitTriggerEvent,
|
|
2508
2508
|
EVENT_PLAYER_UNIT_DROP_ITEM,
|
|
2509
2509
|
function()
|
|
@@ -2514,7 +2514,7 @@ Unit.onItemDrop = __TS__New(
|
|
|
2514
2514
|
return IgnoreEvent
|
|
2515
2515
|
end
|
|
2516
2516
|
)
|
|
2517
|
-
Unit.
|
|
2517
|
+
Unit.itemPickedUpEvent = __TS__New(
|
|
2518
2518
|
____exports.UnitTriggerEvent,
|
|
2519
2519
|
EVENT_PLAYER_UNIT_PICKUP_ITEM,
|
|
2520
2520
|
function()
|
|
@@ -2525,10 +2525,15 @@ Unit.onItemPickup = __TS__New(
|
|
|
2525
2525
|
return IgnoreEvent
|
|
2526
2526
|
end
|
|
2527
2527
|
)
|
|
2528
|
-
Unit.
|
|
2528
|
+
Unit.itemUsedEvent = __TS__New(
|
|
2529
2529
|
____exports.UnitTriggerEvent,
|
|
2530
2530
|
EVENT_PLAYER_UNIT_USE_ITEM,
|
|
2531
|
-
function() return ____exports.Unit:of(
|
|
2531
|
+
function() return ____exports.Unit:of(getTriggerUnit()), Item:of(getManipulatedItem()) end
|
|
2532
|
+
)
|
|
2533
|
+
Unit.itemStackedEvent = __TS__New(
|
|
2534
|
+
____exports.UnitTriggerEvent,
|
|
2535
|
+
EVENT_PLAYER_UNIT_STACK_ITEM,
|
|
2536
|
+
function() return ____exports.Unit:of(getTriggerUnit()), Item:of(getManipulatedItem()) end
|
|
2532
2537
|
)
|
|
2533
2538
|
__TS__ObjectDefineProperty(
|
|
2534
2539
|
Unit,
|
package/engine/unit.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import "./internal/unit/ability";
|
|
|
4
4
|
import "./internal/unit/allowed-targets";
|
|
5
5
|
import "./internal/unit/buff";
|
|
6
6
|
import "./internal/unit/expiration-timer";
|
|
7
|
+
import "./internal/unit/item";
|
|
7
8
|
import "./internal/unit+ability";
|
|
8
9
|
import "./internal/unit+damage";
|
|
9
10
|
import "./internal/unit+rally";
|
package/engine/unit.lua
CHANGED
|
@@ -4,6 +4,7 @@ require("engine.internal.unit.ability")
|
|
|
4
4
|
require("engine.internal.unit.allowed-targets")
|
|
5
5
|
require("engine.internal.unit.buff")
|
|
6
6
|
require("engine.internal.unit.expiration-timer")
|
|
7
|
+
require("engine.internal.unit.item")
|
|
7
8
|
require("engine.internal.unit+ability")
|
|
8
9
|
require("engine.internal.unit+damage")
|
|
9
10
|
require("engine.internal.unit+rally")
|
package/objutil/buff.lua
CHANGED
|
@@ -762,7 +762,7 @@ Unit.onDamaging:addListener(function(source, target, event)
|
|
|
762
762
|
end)
|
|
763
763
|
end
|
|
764
764
|
end)
|
|
765
|
-
Unit.
|
|
765
|
+
Unit.itemPickedUpEvent:addListener(function(unit, item)
|
|
766
766
|
if item.powerup and item:hasAbility(fourCC("APdi")) then
|
|
767
767
|
end
|
|
768
768
|
end)
|
package/package.json
CHANGED