warscript 0.0.1-dev.38157d0 → 0.0.1-dev.397722e
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/effect.d.ts +13 -3
- package/core/types/effect.lua +116 -17
- package/core/types/frame.d.ts +4 -0
- package/core/types/frame.lua +71 -0
- package/core/util.d.ts +1 -1
- package/core/util.lua +12 -0
- package/engine/behavior.d.ts +2 -2
- package/engine/behavior.lua +6 -6
- package/engine/behaviour/ability/always-enabled.d.ts +7 -0
- package/engine/behaviour/ability/always-enabled.lua +31 -0
- package/engine/behaviour/ability/emulate-impact.d.ts +6 -0
- package/engine/behaviour/ability/emulate-impact.lua +29 -0
- package/engine/behaviour/ability/instant-impact.d.ts +2 -2
- package/engine/behaviour/ability/instant-impact.lua +4 -19
- package/engine/behaviour/ability/on-command-impact.d.ts +8 -0
- package/engine/behaviour/ability/on-command-impact.lua +25 -0
- package/engine/behaviour/ability/remove-buffs.d.ts +16 -0
- package/engine/behaviour/ability/remove-buffs.lua +28 -0
- package/engine/behaviour/ability.d.ts +9 -2
- package/engine/behaviour/ability.lua +47 -33
- package/engine/buff.d.ts +6 -1
- package/engine/buff.lua +29 -18
- package/engine/internal/ability.d.ts +16 -13
- package/engine/internal/ability.lua +82 -76
- package/engine/internal/item/ability.lua +90 -0
- package/engine/internal/misc/ability-disable-counter.d.ts +2 -0
- package/engine/internal/misc/ability-disable-counter.lua +13 -0
- package/engine/internal/unit/ability.d.ts +10 -1
- package/engine/internal/unit/ability.lua +36 -14
- package/engine/internal/unit/item.d.ts +24 -0
- package/engine/internal/unit/item.lua +79 -0
- package/engine/internal/unit/main-selected.d.ts +13 -0
- package/engine/internal/unit/main-selected.lua +51 -0
- package/engine/internal/unit-missile-launch.lua +24 -5
- package/engine/internal/unit.d.ts +20 -18
- package/engine/internal/unit.lua +136 -122
- package/engine/internal/utility.lua +12 -0
- package/engine/local-client.d.ts +7 -2
- package/engine/local-client.lua +82 -0
- package/engine/object-data/auxiliary/sound-preset-name.d.ts +5 -1
- package/engine/object-data/entry/ability-type.lua +8 -12
- package/engine/object-data/entry/item-type.d.ts +14 -0
- package/engine/object-data/entry/item-type.lua +91 -0
- package/engine/object-data/utility/object-data-entry-id-generator.lua +7 -0
- package/engine/object-field/ability.d.ts +4 -1
- package/engine/object-field/ability.lua +1 -1
- package/engine/standard/fields/ability.d.ts +2 -0
- package/engine/standard/fields/ability.lua +2 -0
- package/engine/unit.d.ts +2 -0
- package/engine/unit.lua +2 -0
- package/index.d.ts +1 -0
- package/index.lua +1 -0
- package/package.json +1 -1
- package/patch-lua.d.ts +0 -0
- package/patch-lua.lua +10 -0
- package/utility/arrays.d.ts +8 -1
- package/utility/arrays.lua +34 -3
- package/utility/lazy.d.ts +2 -0
- package/utility/lazy.lua +14 -0
|
@@ -1,16 +1,57 @@
|
|
|
1
1
|
local ____exports = {}
|
|
2
|
+
local restoreCooldownGroup
|
|
2
3
|
local ____player = require("core.types.player")
|
|
3
4
|
local Player = ____player.Player
|
|
4
5
|
local ____dummy = require("objutil.dummy")
|
|
5
6
|
local dummyUnitId = ____dummy.dummyUnitId
|
|
7
|
+
local ____utility = require("engine.internal.utility")
|
|
8
|
+
local findUnitItemSlot = ____utility.findUnitItemSlot
|
|
9
|
+
local ____blank = require("engine.object-data.entry.item-type.blank")
|
|
10
|
+
local BlankItemType = ____blank.BlankItemType
|
|
11
|
+
local ____object_2Ddata_2Dentry_2Did_2Dgenerator = require("engine.object-data.utility.object-data-entry-id-generator")
|
|
12
|
+
local abilityTypeIdGenerator = ____object_2Ddata_2Dentry_2Did_2Dgenerator.abilityTypeIdGenerator
|
|
13
|
+
local ____math = require("math")
|
|
14
|
+
local MINIMUM_POSITIVE_NORMALIZED_FLOAT = ____math.MINIMUM_POSITIVE_NORMALIZED_FLOAT
|
|
15
|
+
local ____timer = require("core.types.timer")
|
|
16
|
+
local Timer = ____timer.Timer
|
|
6
17
|
local isItemOwned = IsItemOwned
|
|
7
18
|
local isItemPowerup = IsItemPowerup
|
|
8
19
|
local getItemX = GetItemX
|
|
9
20
|
local getItemY = GetItemY
|
|
21
|
+
local setAbilityRealLevelField = BlzSetAbilityRealLevelField
|
|
22
|
+
local setItemIntegerField = BlzSetItemIntegerField
|
|
23
|
+
local getItemIntegerField = BlzGetItemIntegerField
|
|
10
24
|
local setItemBooleanField = BlzSetItemBooleanField
|
|
11
25
|
local setItemPosition = SetItemPosition
|
|
12
26
|
local unitAddItem = UnitAddItem
|
|
27
|
+
local unitDropItemSlot = UnitDropItemSlot
|
|
13
28
|
local unitRemoveItem = UnitRemoveItem
|
|
29
|
+
local unitUseItem = UnitUseItem
|
|
30
|
+
local unitResetCooldown = UnitResetCooldown
|
|
31
|
+
local COOLDOWN_STARTER_ABILITY_TYPE_ID = compiletime(function()
|
|
32
|
+
if not currentMap then
|
|
33
|
+
return 0
|
|
34
|
+
end
|
|
35
|
+
local abilityType = currentMap.objects.ability:newObject(
|
|
36
|
+
util.id2s(abilityTypeIdGenerator:next()),
|
|
37
|
+
"Absk"
|
|
38
|
+
)
|
|
39
|
+
abilityType["bsk1+0"] = 0
|
|
40
|
+
abilityType["bsk2+0"] = 0
|
|
41
|
+
abilityType["bsk3+0"] = 0
|
|
42
|
+
abilityType["amcs+0"] = 0
|
|
43
|
+
abilityType["adur+0"] = MINIMUM_POSITIVE_NORMALIZED_FLOAT
|
|
44
|
+
abilityType["ahdu+0"] = MINIMUM_POSITIVE_NORMALIZED_FLOAT
|
|
45
|
+
return util.s2id(abilityType.id)
|
|
46
|
+
end)
|
|
47
|
+
local COOLDOWN_STARTER_ITEM_TYPE_ID = compiletime(function()
|
|
48
|
+
local itemType = BlankItemType:create()
|
|
49
|
+
itemType.name = "[Warscript/Dummy] Item Cooldown Starter"
|
|
50
|
+
itemType.abilityTypeIds = {COOLDOWN_STARTER_ABILITY_TYPE_ID}
|
|
51
|
+
itemType.cooldownGroupId = COOLDOWN_STARTER_ABILITY_TYPE_ID
|
|
52
|
+
itemType.activelyUsed = true
|
|
53
|
+
return itemType.id
|
|
54
|
+
end)
|
|
14
55
|
local dummy = assert(CreateUnit(
|
|
15
56
|
Player.neutralVictim.handle,
|
|
16
57
|
dummyUnitId,
|
|
@@ -18,7 +59,30 @@ local dummy = assert(CreateUnit(
|
|
|
18
59
|
0,
|
|
19
60
|
270
|
|
20
61
|
))
|
|
62
|
+
local cooldownStarterItem = UnitAddItemById(dummy, COOLDOWN_STARTER_ITEM_TYPE_ID)
|
|
63
|
+
local cooldownStarterAbility = BlzGetItemAbility(cooldownStarterItem, COOLDOWN_STARTER_ABILITY_TYPE_ID)
|
|
21
64
|
ShowUnit(dummy, false)
|
|
65
|
+
local function startItemCooldownInternal(handle, cooldown)
|
|
66
|
+
local cooldownGroup = getItemIntegerField(handle, ITEM_IF_COOLDOWN_GROUP)
|
|
67
|
+
setItemIntegerField(handle, ITEM_IF_COOLDOWN_GROUP, COOLDOWN_STARTER_ABILITY_TYPE_ID)
|
|
68
|
+
setAbilityRealLevelField(cooldownStarterAbility, ABILITY_RLF_COOLDOWN, 0, cooldown)
|
|
69
|
+
unitResetCooldown(dummy)
|
|
70
|
+
unitUseItem(dummy, cooldownStarterItem)
|
|
71
|
+
Timer:run(restoreCooldownGroup, handle, cooldownGroup)
|
|
72
|
+
end
|
|
73
|
+
restoreCooldownGroup = function(handle, cooldownGroup)
|
|
74
|
+
if getItemIntegerField(handle, ITEM_IF_COOLDOWN_GROUP) == COOLDOWN_STARTER_ABILITY_TYPE_ID then
|
|
75
|
+
setItemIntegerField(handle, ITEM_IF_COOLDOWN_GROUP, cooldownGroup)
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
---
|
|
79
|
+
-- @internal For use by internal systems only.
|
|
80
|
+
____exports.startItemCooldown = function(handle, owner, cooldown)
|
|
81
|
+
____exports.doAbilityActionForceDummy(handle, owner, startItemCooldownInternal, cooldown)
|
|
82
|
+
end
|
|
83
|
+
---
|
|
84
|
+
-- @internal For use by internal systems only.
|
|
85
|
+
____exports.abilityActionDummy = dummy
|
|
22
86
|
---
|
|
23
87
|
-- @internal For use by internal systems only.
|
|
24
88
|
____exports.doAbilityAction = function(handle, action, ...)
|
|
@@ -45,4 +109,30 @@ ____exports.doAbilityAction = function(handle, action, ...)
|
|
|
45
109
|
end
|
|
46
110
|
return result
|
|
47
111
|
end
|
|
112
|
+
---
|
|
113
|
+
-- @internal For use by internal systems only.
|
|
114
|
+
____exports.doAbilityActionForceDummy = function(handle, owner, action, ...)
|
|
115
|
+
if owner == nil then
|
|
116
|
+
return ____exports.doAbilityAction(handle, action, ...)
|
|
117
|
+
end
|
|
118
|
+
local slot = findUnitItemSlot(owner, handle)
|
|
119
|
+
if slot == nil then
|
|
120
|
+
return ____exports.doAbilityAction(handle, action, ...)
|
|
121
|
+
end
|
|
122
|
+
local isPowerup
|
|
123
|
+
if isItemPowerup(handle) then
|
|
124
|
+
setItemBooleanField(handle, ITEM_BF_USE_AUTOMATICALLY_WHEN_ACQUIRED, false)
|
|
125
|
+
isPowerup = true
|
|
126
|
+
end
|
|
127
|
+
unitRemoveItem(owner, handle)
|
|
128
|
+
unitAddItem(dummy, handle)
|
|
129
|
+
local result = action(handle, ...)
|
|
130
|
+
unitRemoveItem(dummy, handle)
|
|
131
|
+
unitAddItem(owner, handle)
|
|
132
|
+
unitDropItemSlot(owner, handle, slot)
|
|
133
|
+
if isPowerup then
|
|
134
|
+
setItemBooleanField(handle, ITEM_BF_USE_AUTOMATICALLY_WHEN_ACQUIRED, true)
|
|
135
|
+
end
|
|
136
|
+
return result
|
|
137
|
+
end
|
|
48
138
|
return ____exports
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
local ____exports = {}
|
|
2
|
+
local disableAbility = BlzUnitDisableAbility
|
|
3
|
+
---
|
|
4
|
+
-- @internal For use by internal systems only.
|
|
5
|
+
____exports.increaseAbilityDisableCounter = function(unit, abilityTypeId, times)
|
|
6
|
+
for _ = 1, times do
|
|
7
|
+
disableAbility(unit, abilityTypeId, true, false)
|
|
8
|
+
end
|
|
9
|
+
for _ = times, -1 do
|
|
10
|
+
disableAbility(unit, abilityTypeId, false, false)
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
return ____exports
|
|
@@ -3,7 +3,7 @@ import { Ability } from "../ability";
|
|
|
3
3
|
import { Destructable } from "../../../core/types/destructable";
|
|
4
4
|
import { Item } from "../item";
|
|
5
5
|
import { Widget } from "../../../core/types/widget";
|
|
6
|
-
import { DispatchingEvent } from "../../../event";
|
|
6
|
+
import { DispatchingEvent, Event } from "../../../event";
|
|
7
7
|
declare module "../unit" {
|
|
8
8
|
namespace Unit {
|
|
9
9
|
const abilityCastingStartEvent: DispatchingEvent<[Unit, Ability]>;
|
|
@@ -141,3 +141,12 @@ declare module "../unit" {
|
|
|
141
141
|
const abilityStopEvent: DispatchingEvent<[Unit, Ability]>;
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
|
+
declare module "../unit" {
|
|
145
|
+
namespace Unit {
|
|
146
|
+
const abilityCommandEvent: {
|
|
147
|
+
readonly [abilityTypeId: number]: {
|
|
148
|
+
readonly [orderTypeStringId: string]: Event<[Unit, Ability, string]>;
|
|
149
|
+
};
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
}
|
|
@@ -15,8 +15,15 @@ local UnitTriggerEvent = ____unit.UnitTriggerEvent
|
|
|
15
15
|
local ____event = require("event")
|
|
16
16
|
local createDispatchingEvent = ____event.createDispatchingEvent
|
|
17
17
|
local DependentInitializingEvent = ____event.DependentInitializingEvent
|
|
18
|
+
local Event = ____event.Event
|
|
19
|
+
local InitializingEvent = ____event.InitializingEvent
|
|
18
20
|
local ____preconditions = require("utility.preconditions")
|
|
19
21
|
local checkNotNull = ____preconditions.checkNotNull
|
|
22
|
+
local ____lazy = require("utility.lazy")
|
|
23
|
+
local lazyRecord = ____lazy.lazyRecord
|
|
24
|
+
local eventInvoke = Event.invoke
|
|
25
|
+
local condition = Condition
|
|
26
|
+
local createTrigger = CreateTrigger
|
|
20
27
|
local getItemAbility = BlzGetItemAbility
|
|
21
28
|
local getSpellAbility = GetSpellAbility
|
|
22
29
|
local getSpellAbilityId = GetSpellAbilityId
|
|
@@ -26,11 +33,10 @@ local getSpellTargetUnit = GetSpellTargetUnit
|
|
|
26
33
|
local getSpellTargetX = GetSpellTargetX
|
|
27
34
|
local getSpellTargetY = GetSpellTargetY
|
|
28
35
|
local getTriggerUnit = GetTriggerUnit
|
|
29
|
-
local
|
|
30
|
-
local
|
|
36
|
+
local triggerAddCondition = TriggerAddCondition
|
|
37
|
+
local triggerRegisterCommandEvent = TriggerRegisterCommandEvent
|
|
31
38
|
local unitInventorySize = UnitInventorySize
|
|
32
39
|
local unitItemInSlot = UnitItemInSlot
|
|
33
|
-
local unitRemoveAbility = UnitRemoveAbility
|
|
34
40
|
local function retrieveAbility(unit, ability, abilityId)
|
|
35
41
|
if ability == nil then
|
|
36
42
|
return __TS__New(
|
|
@@ -39,17 +45,6 @@ local function retrieveAbility(unit, ability, abilityId)
|
|
|
39
45
|
Unit:of(unit)
|
|
40
46
|
)
|
|
41
47
|
end
|
|
42
|
-
if not unitAddAbility(unit, abilityId) then
|
|
43
|
-
if getUnitAbility(unit, abilityId) == ability then
|
|
44
|
-
return UnitAbility:of(
|
|
45
|
-
ability,
|
|
46
|
-
abilityId,
|
|
47
|
-
Unit:of(unit)
|
|
48
|
-
)
|
|
49
|
-
end
|
|
50
|
-
else
|
|
51
|
-
unitRemoveAbility(unit, abilityId)
|
|
52
|
-
end
|
|
53
48
|
for i = 0, unitInventorySize(unit) - 1 do
|
|
54
49
|
local item = unitItemInSlot(unit, i)
|
|
55
50
|
if getItemAbility(item, abilityId) == ability then
|
|
@@ -366,4 +361,31 @@ rawset(
|
|
|
366
361
|
extractAbilityTypeId
|
|
367
362
|
)
|
|
368
363
|
)
|
|
364
|
+
rawset(
|
|
365
|
+
Unit,
|
|
366
|
+
"abilityCommandEvent",
|
|
367
|
+
lazyRecord(function(abilityTypeId)
|
|
368
|
+
return lazyRecord(function(orderTypeStringId)
|
|
369
|
+
return __TS__New(
|
|
370
|
+
InitializingEvent,
|
|
371
|
+
function(event)
|
|
372
|
+
local trigger = createTrigger()
|
|
373
|
+
triggerRegisterCommandEvent(trigger, abilityTypeId, orderTypeStringId)
|
|
374
|
+
triggerAddCondition(
|
|
375
|
+
trigger,
|
|
376
|
+
condition(function()
|
|
377
|
+
local unit = Unit:of(getTriggerUnit())
|
|
378
|
+
if unit ~= nil then
|
|
379
|
+
local ability = unit:getAbilityById(abilityTypeId)
|
|
380
|
+
if ability ~= nil then
|
|
381
|
+
eventInvoke(event, unit, ability, orderTypeStringId)
|
|
382
|
+
end
|
|
383
|
+
end
|
|
384
|
+
end)
|
|
385
|
+
)
|
|
386
|
+
end
|
|
387
|
+
)
|
|
388
|
+
end)
|
|
389
|
+
end)
|
|
390
|
+
)
|
|
369
391
|
return ____exports
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
findSlot(item: Item): 0 | 1 | 2 | 3 | 4 | 5 | undefined;
|
|
15
|
+
protected __newindex(slot: number, item: Item | undefined): void;
|
|
16
|
+
protected __index(key: string | number): unknown;
|
|
17
|
+
protected __len(): number;
|
|
18
|
+
protected __ipairs(): LuaIterator<LuaMultiReturn<[number, Item | undefined]>, junit>;
|
|
19
|
+
}
|
|
20
|
+
declare module "../unit" {
|
|
21
|
+
interface Unit {
|
|
22
|
+
readonly items: UnitItems;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
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 ____utility = require("engine.internal.utility")
|
|
11
|
+
local findUnitItemSlot = ____utility.findUnitItemSlot
|
|
12
|
+
local rawset = _G.rawset
|
|
13
|
+
local ____type = _G.type
|
|
14
|
+
local isItemPowerup = IsItemPowerup
|
|
15
|
+
local setItemBooleanField = BlzSetItemBooleanField
|
|
16
|
+
local unitAddItem = UnitAddItem
|
|
17
|
+
local unitDropItemSlot = UnitDropItemSlot
|
|
18
|
+
local unitInventorySize = UnitInventorySize
|
|
19
|
+
local unitItemInSlot = UnitItemInSlot
|
|
20
|
+
local unitRemoveItemFromSlot = UnitRemoveItemFromSlot
|
|
21
|
+
local handleByUnitItems = setmetatable({}, {__mode = "k"})
|
|
22
|
+
local function unitItemsNext(handle, index)
|
|
23
|
+
local slot = index & 7
|
|
24
|
+
if index >> 3 == slot then
|
|
25
|
+
return nil, nil
|
|
26
|
+
end
|
|
27
|
+
return index + 1, Item:of(unitItemInSlot(handle, slot))
|
|
28
|
+
end
|
|
29
|
+
____exports.UnitItems = __TS__Class()
|
|
30
|
+
local UnitItems = ____exports.UnitItems
|
|
31
|
+
UnitItems.name = "UnitItems"
|
|
32
|
+
function UnitItems.prototype.____constructor(self, handle)
|
|
33
|
+
handleByUnitItems[self] = handle
|
|
34
|
+
end
|
|
35
|
+
function UnitItems.prototype.findSlot(self, item)
|
|
36
|
+
return findUnitItemSlot(handleByUnitItems[self], item.handle)
|
|
37
|
+
end
|
|
38
|
+
function UnitItems.prototype.__newindex(self, slot, item)
|
|
39
|
+
local handle = handleByUnitItems[self]
|
|
40
|
+
if slot < 1 or slot > unitInventorySize(handle) then
|
|
41
|
+
return
|
|
42
|
+
end
|
|
43
|
+
unitRemoveItemFromSlot(handle, slot - 1)
|
|
44
|
+
if item ~= nil then
|
|
45
|
+
local itemHandle = item.handle
|
|
46
|
+
local isPowerup = isItemPowerup(itemHandle)
|
|
47
|
+
if isPowerup then
|
|
48
|
+
setItemBooleanField(itemHandle, ITEM_BF_USE_AUTOMATICALLY_WHEN_ACQUIRED, false)
|
|
49
|
+
end
|
|
50
|
+
unitAddItem(handle, itemHandle)
|
|
51
|
+
unitDropItemSlot(handle, itemHandle, slot - 1)
|
|
52
|
+
if isPowerup then
|
|
53
|
+
setItemBooleanField(itemHandle, ITEM_BF_USE_AUTOMATICALLY_WHEN_ACQUIRED, true)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
function UnitItems.prototype.__index(self, key)
|
|
58
|
+
if ____type(key) == "number" then
|
|
59
|
+
return Item:of(unitItemInSlot(handleByUnitItems[self], key - 1))
|
|
60
|
+
end
|
|
61
|
+
return rawget(____exports.UnitItems.prototype, key)
|
|
62
|
+
end
|
|
63
|
+
function UnitItems.prototype.__len(self)
|
|
64
|
+
return unitInventorySize(handleByUnitItems[self])
|
|
65
|
+
end
|
|
66
|
+
function UnitItems.prototype.__ipairs(self)
|
|
67
|
+
local handle = handleByUnitItems[self]
|
|
68
|
+
return unitItemsNext, handle, unitInventorySize(handle) << 3
|
|
69
|
+
end
|
|
70
|
+
__TS__ObjectDefineProperty(
|
|
71
|
+
Unit.prototype,
|
|
72
|
+
"items",
|
|
73
|
+
{get = function(self)
|
|
74
|
+
local items = __TS__New(____exports.UnitItems, self.handle)
|
|
75
|
+
rawset(self, "items", items)
|
|
76
|
+
return items
|
|
77
|
+
end}
|
|
78
|
+
)
|
|
79
|
+
return ____exports
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** @noSelfInFile */
|
|
2
|
+
import { Player } from "../../../core/types/player";
|
|
3
|
+
import { Event } from "../../../event";
|
|
4
|
+
declare module "../unit" {
|
|
5
|
+
namespace Unit {
|
|
6
|
+
const mainSelectedUnitChangeEvent: Event<[Player]>;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
declare module "../unit" {
|
|
10
|
+
namespace Unit {
|
|
11
|
+
const getMainSelectedOf: (player: Player) => Unit | undefined;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
local ____lualib = require("lualib_bundle")
|
|
2
|
+
local __TS__New = ____lualib.__TS__New
|
|
3
|
+
local ____exports = {}
|
|
4
|
+
local ____player = require("core.types.player")
|
|
5
|
+
local Player = ____player.Player
|
|
6
|
+
local ____math = require("math")
|
|
7
|
+
local MAXIMUM_INTEGER = ____math.MAXIMUM_INTEGER
|
|
8
|
+
local MINIMUM_INTEGER = ____math.MINIMUM_INTEGER
|
|
9
|
+
local ____local_2Dclient = require("engine.local-client")
|
|
10
|
+
local LocalClient = ____local_2Dclient.LocalClient
|
|
11
|
+
local ____unit = require("engine.internal.unit")
|
|
12
|
+
local Unit = ____unit.Unit
|
|
13
|
+
local ____event = require("event")
|
|
14
|
+
local Event = ____event.Event
|
|
15
|
+
local mainSelectedUnitChangeEvent = __TS__New(Event)
|
|
16
|
+
rawset(Unit, "mainSelectedUnitChangeEvent", mainSelectedUnitChangeEvent)
|
|
17
|
+
local mainSelectedUnitByPlayer = {}
|
|
18
|
+
local syncSlider = BlzCreateFrameByType(
|
|
19
|
+
"SLIDER",
|
|
20
|
+
"UnitSyncId",
|
|
21
|
+
BlzGetOriginFrame(ORIGIN_FRAME_WORLD_FRAME, 0),
|
|
22
|
+
"",
|
|
23
|
+
0
|
|
24
|
+
)
|
|
25
|
+
BlzFrameSetMinMaxValue(syncSlider, MINIMUM_INTEGER, MAXIMUM_INTEGER)
|
|
26
|
+
LocalClient.mainSelectedUnitChangeEvent:addListener(function()
|
|
27
|
+
local ____opt_0 = LocalClient.mainSelectedUnit
|
|
28
|
+
local syncId = ____opt_0 and ____opt_0.syncId
|
|
29
|
+
BlzFrameSetValue(syncSlider, syncId or 0)
|
|
30
|
+
end)
|
|
31
|
+
local trg = CreateTrigger()
|
|
32
|
+
BlzTriggerRegisterFrameEvent(trg, syncSlider, FRAMEEVENT_SLIDER_VALUE_CHANGED)
|
|
33
|
+
TriggerAddAction(
|
|
34
|
+
trg,
|
|
35
|
+
function()
|
|
36
|
+
local player = Player:of(GetTriggerPlayer())
|
|
37
|
+
local mainSelectedUnit = Unit:getBySyncId(BlzGetTriggerFrameValue())
|
|
38
|
+
if mainSelectedUnit ~= mainSelectedUnitByPlayer[player] then
|
|
39
|
+
mainSelectedUnitByPlayer[player] = mainSelectedUnit
|
|
40
|
+
Event.invoke(mainSelectedUnitChangeEvent, player)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
)
|
|
44
|
+
rawset(
|
|
45
|
+
Unit,
|
|
46
|
+
"getMainSelectedOf",
|
|
47
|
+
function(player)
|
|
48
|
+
return mainSelectedUnitByPlayer[player]
|
|
49
|
+
end
|
|
50
|
+
)
|
|
51
|
+
return ____exports
|
|
@@ -7,14 +7,33 @@ local ____event = require("event")
|
|
|
7
7
|
local Event = ____event.Event
|
|
8
8
|
local ____timer = require("core.types.timer")
|
|
9
9
|
local Timer = ____timer.Timer
|
|
10
|
+
local ____lua_2Dsets = require("utility.lua-sets")
|
|
11
|
+
local luaSetOf = ____lua_2Dsets.luaSetOf
|
|
10
12
|
local autoAttackFinishEvent = __TS__New(Event)
|
|
11
13
|
rawset(Unit, "autoAttackFinishEvent", autoAttackFinishEvent)
|
|
12
14
|
local eventTimerByUnit = {}
|
|
13
|
-
local
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
local instantOrderIds = luaSetOf(
|
|
16
|
+
orderId("avatar"),
|
|
17
|
+
orderId("berserk"),
|
|
18
|
+
orderId("divineshield"),
|
|
19
|
+
orderId("immolation"),
|
|
20
|
+
orderId("moveslot0"),
|
|
21
|
+
orderId("moveslot1"),
|
|
22
|
+
orderId("moveslot2"),
|
|
23
|
+
orderId("moveslot3"),
|
|
24
|
+
orderId("moveslot4"),
|
|
25
|
+
orderId("moveslot5"),
|
|
26
|
+
orderId("unavatar"),
|
|
27
|
+
orderId("undivineshield"),
|
|
28
|
+
orderId("unimmolation")
|
|
29
|
+
)
|
|
30
|
+
local function reset(source, orderId)
|
|
31
|
+
if not (instantOrderIds[orderId] ~= nil) then
|
|
32
|
+
local eventTimer = eventTimerByUnit[source]
|
|
33
|
+
if eventTimer then
|
|
34
|
+
eventTimer:destroy()
|
|
35
|
+
eventTimerByUnit[source] = nil
|
|
36
|
+
end
|
|
18
37
|
end
|
|
19
38
|
end
|
|
20
39
|
Unit.onImmediateOrder:addListener(reset)
|
|
@@ -68,16 +68,6 @@ declare const modifiers: {
|
|
|
68
68
|
speed: (unit: junit, value: number) => void;
|
|
69
69
|
armor: (unit: junit, value: number) => void;
|
|
70
70
|
};
|
|
71
|
-
export interface UnitItems extends Array<Item | undefined> {
|
|
72
|
-
readonly length: 0 | 1 | 2 | 3 | 4 | 5 | 6;
|
|
73
|
-
}
|
|
74
|
-
export declare class UnitItems {
|
|
75
|
-
private readonly handle;
|
|
76
|
-
constructor(handle: junit);
|
|
77
|
-
protected __newindex(slot: number, item: Item | undefined): void;
|
|
78
|
-
protected __index(slot: number): Item | undefined;
|
|
79
|
-
protected __len(): number;
|
|
80
|
-
}
|
|
81
71
|
export declare class UnitWeapon {
|
|
82
72
|
readonly unit: Unit;
|
|
83
73
|
readonly index: 0 | 1;
|
|
@@ -104,14 +94,19 @@ export declare class UnitWeapon {
|
|
|
104
94
|
set missileSpeed(missileSpeed: number);
|
|
105
95
|
}
|
|
106
96
|
declare const enum UnitPropertyKey {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
97
|
+
SYNC_ID = 100,
|
|
98
|
+
IS_PAUSED = 101,
|
|
99
|
+
STUN_COUNTER = 102,
|
|
100
|
+
DELAY_HEALTH_CHECKS_COUNTER = 103,
|
|
101
|
+
DELAY_HEALTH_CHECKS_HEALTH_BONUS = 104,
|
|
102
|
+
PREVENT_DEATH_HEALTH_BONUS = 105,
|
|
103
|
+
IS_TEAM_GLOW_HIDDEN = 106
|
|
113
104
|
}
|
|
105
|
+
export type UnitSyncId = number & {
|
|
106
|
+
readonly __unitSyncId: unique symbol;
|
|
107
|
+
};
|
|
114
108
|
export declare class Unit extends Handle<junit> {
|
|
109
|
+
readonly syncId: UnitSyncId;
|
|
115
110
|
private [UnitPropertyKey.IS_PAUSED]?;
|
|
116
111
|
private [UnitPropertyKey.STUN_COUNTER]?;
|
|
117
112
|
private [UnitPropertyKey.DELAY_HEALTH_CHECKS_COUNTER]?;
|
|
@@ -251,7 +246,6 @@ export declare class Unit extends Handle<junit> {
|
|
|
251
246
|
dropItemTarget(item: Item, target: Widget): boolean;
|
|
252
247
|
dropItemSlot(item: Item, slot: number): boolean;
|
|
253
248
|
itemInSlot(slot: number): Item | null;
|
|
254
|
-
get items(): UnitItems;
|
|
255
249
|
addAbility(abilityId: number): UnitAbility | null;
|
|
256
250
|
makeAbilityPermanent(abilityId: number, permanent: true): boolean;
|
|
257
251
|
setAbilityLevel(abilityId: number, level: number): number;
|
|
@@ -299,7 +293,7 @@ export declare class Unit extends Handle<junit> {
|
|
|
299
293
|
static getInRange(x: number, y: number, range: number, predicate?: (unit: Unit) => boolean): Unit[];
|
|
300
294
|
static getInCollisionRange(x: number, y: number, range: number, predicate?: (unit: Unit) => boolean): Unit[];
|
|
301
295
|
static getInSector(pos: Vec2, range: number, offsetAngle: number, centralAngle: number): Unit[];
|
|
302
|
-
static getSelectionOf(player: Player): Unit[];
|
|
296
|
+
static getSelectionOf(player: Player, target?: Unit[]): Unit[];
|
|
303
297
|
static readonly deathEvent: UnitTriggerEvent<[Unit]>;
|
|
304
298
|
static readonly onDecay: UnitTriggerEvent<[]>;
|
|
305
299
|
static readonly onResurrect: InitializingEvent<[Unit], void>;
|
|
@@ -338,6 +332,13 @@ export declare class Unit extends Handle<junit> {
|
|
|
338
332
|
static itemPickedUpEvent: UnitTriggerEvent<[Item]>;
|
|
339
333
|
static itemUsedEvent: UnitTriggerEvent<[Item]>;
|
|
340
334
|
static itemStackedEvent: UnitTriggerEvent<[Item]>;
|
|
335
|
+
static get itemUseOrderEvent(): Event<[unit: Unit, item: Item]>;
|
|
336
|
+
static get itemMoveOrderEvent(): Event<[
|
|
337
|
+
unit: Unit,
|
|
338
|
+
item: Item,
|
|
339
|
+
slotFrom: 0 | 1 | 2 | 3 | 4 | 5,
|
|
340
|
+
slotTo: 0 | 1 | 2 | 3 | 4 | 5
|
|
341
|
+
]>;
|
|
341
342
|
static get onCreate(): EventDispatcher<[Unit], [Unit]>;
|
|
342
343
|
static get destroyEvent(): EventDispatcher<[Unit], [Unit]>;
|
|
343
344
|
getField(field: junitintegerfield | junitrealfield): number;
|
|
@@ -348,5 +349,6 @@ export declare class Unit extends Handle<junit> {
|
|
|
348
349
|
setField(field: junitbooleanfield, value: boolean): boolean;
|
|
349
350
|
setField(field: junitstringfield, value: string): boolean;
|
|
350
351
|
toString(): string;
|
|
352
|
+
static getBySyncId(syncId: UnitSyncId): Unit | undefined;
|
|
351
353
|
}
|
|
352
354
|
export {};
|