warscript 0.0.1-dev.d7e0522 → 0.0.1-dev.da5fb2e
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/frame.lua +10 -12
- package/core/types/player.lua +3 -1
- package/core/types/playerCamera.d.ts +2 -0
- package/core/types/playerCamera.lua +79 -5
- package/core/types/timer.d.ts +2 -1
- package/core/types/timer.lua +21 -2
- package/decl/native.d.ts +4 -2
- package/engine/behavior.d.ts +5 -0
- package/engine/behavior.lua +106 -27
- package/engine/behaviour/ability/apply-buff.lua +1 -1
- package/engine/behaviour/ability/emulate-impact.d.ts +1 -1
- package/engine/behaviour/ability/emulate-impact.lua +11 -3
- package/engine/behaviour/ability/restore-mana.d.ts +1 -1
- package/engine/behaviour/ability/restore-mana.lua +6 -6
- package/engine/behaviour/ability.lua +8 -17
- package/engine/behaviour/unit/stun-immunity.d.ts +5 -3
- package/engine/behaviour/unit/stun-immunity.lua +43 -27
- package/engine/behaviour/unit.d.ts +19 -2
- package/engine/behaviour/unit.lua +88 -7
- package/engine/buff.d.ts +2 -4
- package/engine/buff.lua +68 -83
- package/engine/internal/ability.d.ts +5 -1
- package/engine/internal/ability.lua +43 -11
- package/engine/internal/item/ability.lua +51 -1
- package/engine/internal/item+owner.lua +12 -6
- package/engine/internal/item.d.ts +1 -0
- package/engine/internal/item.lua +20 -11
- package/engine/internal/misc/frame-coordinates.d.ts +2 -0
- package/engine/internal/misc/frame-coordinates.lua +21 -0
- package/engine/internal/misc/get-terrain-z.d.ts +2 -0
- package/engine/internal/misc/get-terrain-z.lua +11 -0
- package/engine/internal/misc/player-local-handle.d.ts +2 -0
- package/engine/internal/misc/player-local-handle.lua +5 -0
- package/engine/internal/unit/ability.d.ts +35 -0
- package/engine/internal/unit/ability.lua +62 -0
- package/engine/internal/unit/order.d.ts +20 -0
- package/engine/internal/unit/order.lua +136 -0
- package/engine/internal/unit+ability.lua +10 -1
- package/engine/internal/unit-missile-launch.lua +8 -1
- package/engine/internal/unit.d.ts +4 -4
- package/engine/internal/unit.lua +84 -70
- package/engine/object-data/auxiliary/armor-type.d.ts +11 -0
- package/engine/object-data/auxiliary/armor-type.lua +46 -0
- package/engine/object-data/entry/ability-type.lua +1 -3
- package/engine/object-data/entry/unit-type.d.ts +11 -2
- package/engine/object-data/entry/unit-type.lua +59 -1
- package/engine/object-field/ability.d.ts +3 -3
- package/engine/object-field/ability.lua +7 -6
- package/engine/object-field/unit.d.ts +11 -0
- package/engine/object-field/unit.lua +34 -0
- package/engine/object-field.d.ts +8 -5
- package/engine/object-field.lua +90 -76
- package/engine/standard/fields/unit.d.ts +4 -0
- package/engine/standard/fields/unit.lua +7 -0
- package/engine/text-tag.d.ts +36 -2
- package/engine/text-tag.lua +249 -10
- package/engine/unit.d.ts +1 -0
- package/engine/unit.lua +1 -0
- package/package.json +2 -2
- package/patch-lualib.lua +1 -1
- package/utility/callback-array.d.ts +13 -0
- package/utility/callback-array.lua +46 -0
- package/utility/functions.d.ts +7 -0
- package/utility/functions.lua +12 -0
- package/utility/lua-maps.d.ts +1 -0
- package/utility/lua-maps.lua +4 -0
- package/utility/lua-sets.d.ts +1 -0
- package/utility/lua-sets.lua +4 -0
- package/core/types/order.d.ts +0 -26
- package/core/types/order.lua +0 -65
|
@@ -13,6 +13,7 @@ local ____ability = require("engine.internal.item.ability")
|
|
|
13
13
|
local abilityActionDummy = ____ability.abilityActionDummy
|
|
14
14
|
local doAbilityAction = ____ability.doAbilityAction
|
|
15
15
|
local doAbilityActionForceDummy = ____ability.doAbilityActionForceDummy
|
|
16
|
+
local doUnitAbilityAction = ____ability.doUnitAbilityAction
|
|
16
17
|
local startItemCooldown = ____ability.startItemCooldown
|
|
17
18
|
local getUnitAbilityLevel = GetUnitAbilityLevel
|
|
18
19
|
local setUnitAbilityLevel = SetUnitAbilityLevel
|
|
@@ -39,6 +40,8 @@ local getItemBooleanField = BlzGetItemBooleanField
|
|
|
39
40
|
local setItemBooleanField = BlzSetItemBooleanField
|
|
40
41
|
local unitHideAbility = BlzUnitHideAbility
|
|
41
42
|
local unitDisableAbility = BlzUnitDisableAbility
|
|
43
|
+
local unitRemoveAbility = UnitRemoveAbility
|
|
44
|
+
local itemRemoveAbility = BlzItemRemoveAbility
|
|
42
45
|
local match = string.match
|
|
43
46
|
local ____type = _G.type
|
|
44
47
|
local ____tostring = _G.tostring
|
|
@@ -232,6 +235,19 @@ ____exports.getOrderIdByAbilityTypeId = function(abilityTypeId)
|
|
|
232
235
|
local parentTypeId = availableFields[abilityTypeId]
|
|
233
236
|
return order2orderId(orders[____type(parentTypeId) == "number" and parentTypeId or abilityTypeId] or "")
|
|
234
237
|
end
|
|
238
|
+
---
|
|
239
|
+
-- @internal For use by internal systems only.
|
|
240
|
+
____exports.abilityTypeHasField = function(abilityTypeId, field)
|
|
241
|
+
field = ____type(field) == "number" and field or getHandleId(field)
|
|
242
|
+
if commonFields[field] then
|
|
243
|
+
return true
|
|
244
|
+
end
|
|
245
|
+
local id = availableFields[abilityTypeId]
|
|
246
|
+
if ____type(id) == "number" then
|
|
247
|
+
id = availableFields[id]
|
|
248
|
+
end
|
|
249
|
+
return not not (id and id[field])
|
|
250
|
+
end
|
|
235
251
|
____exports.Ability = __TS__Class()
|
|
236
252
|
local Ability = ____exports.Ability
|
|
237
253
|
Ability.name = "Ability"
|
|
@@ -247,15 +263,7 @@ function Ability.prototype.getSnapshot(self)
|
|
|
247
263
|
return nil
|
|
248
264
|
end
|
|
249
265
|
function Ability.prototype.hasField(self, field)
|
|
250
|
-
|
|
251
|
-
if commonFields[field] then
|
|
252
|
-
return true
|
|
253
|
-
end
|
|
254
|
-
local id = availableFields[self.typeId]
|
|
255
|
-
if ____type(id) == "number" then
|
|
256
|
-
id = availableFields[id]
|
|
257
|
-
end
|
|
258
|
-
return not not (id and id[field])
|
|
266
|
+
return ____exports.abilityTypeHasField(self.typeId, field)
|
|
259
267
|
end
|
|
260
268
|
function Ability.prototype.getField(self, field, level)
|
|
261
269
|
local fieldType = match(
|
|
@@ -404,14 +412,34 @@ function UnitAbility.prototype.decrementHideCounter(self)
|
|
|
404
412
|
unitHideAbility(self.u, self.typeId, false)
|
|
405
413
|
end
|
|
406
414
|
function UnitAbility.prototype.incrementDisableCounter(self)
|
|
407
|
-
|
|
415
|
+
local unit = self.u
|
|
416
|
+
local typeId = self.typeId
|
|
417
|
+
unitHideAbility(unit, typeId, true)
|
|
418
|
+
unitDisableAbility(unit, typeId, true, false)
|
|
419
|
+
self.d = (self.d or 0) + 1
|
|
408
420
|
end
|
|
409
421
|
function UnitAbility.prototype.decrementDisableCounter(self)
|
|
410
|
-
|
|
422
|
+
local unit = self.u
|
|
423
|
+
local typeId = self.typeId
|
|
424
|
+
unitDisableAbility(unit, typeId, false, false)
|
|
425
|
+
unitHideAbility(unit, typeId, true)
|
|
426
|
+
self.d = (self.d or 0) - 1
|
|
411
427
|
end
|
|
412
428
|
function UnitAbility.prototype.interruptCast(self)
|
|
413
429
|
self.owner:interruptCast(self.typeId)
|
|
414
430
|
end
|
|
431
|
+
function UnitAbility.prototype.onDestroy(self)
|
|
432
|
+
doUnitAbilityAction(self.owner.handle, self.typeId, unitRemoveAbility, self.typeId)
|
|
433
|
+
return UnitAbility.____super.prototype.onDestroy(self)
|
|
434
|
+
end
|
|
435
|
+
__TS__SetDescriptor(
|
|
436
|
+
UnitAbility.prototype,
|
|
437
|
+
"isDisabled",
|
|
438
|
+
{get = function(self)
|
|
439
|
+
return self.d ~= nil and self.d > 0
|
|
440
|
+
end},
|
|
441
|
+
true
|
|
442
|
+
)
|
|
415
443
|
__TS__SetDescriptor(
|
|
416
444
|
UnitAbility.prototype,
|
|
417
445
|
"level",
|
|
@@ -496,6 +524,10 @@ function ItemAbility.prototype.interruptCast(self)
|
|
|
496
524
|
setItemBooleanField(handle, ITEM_BF_ACTIVELY_USED, true)
|
|
497
525
|
end
|
|
498
526
|
end
|
|
527
|
+
function ItemAbility.prototype.onDestroy(self)
|
|
528
|
+
doAbilityAction(self.owner.handle, itemRemoveAbility, self.typeId)
|
|
529
|
+
return ItemAbility.____super.prototype.onDestroy(self)
|
|
530
|
+
end
|
|
499
531
|
__TS__SetDescriptor(
|
|
500
532
|
ItemAbility.prototype,
|
|
501
533
|
"level",
|
|
@@ -20,6 +20,7 @@ local ____add_2Ditem_2Dto_2Dslot = require("engine.internal.unit.add-item-to-slo
|
|
|
20
20
|
local unitAddItemToSlot = ____add_2Ditem_2Dto_2Dslot.unitAddItemToSlot
|
|
21
21
|
local isItemOwned = IsItemOwned
|
|
22
22
|
local isItemPowerup = IsItemPowerup
|
|
23
|
+
local getItemAbility = BlzGetItemAbility
|
|
23
24
|
local getItemX = GetItemX
|
|
24
25
|
local getItemY = GetItemY
|
|
25
26
|
local setAbilityRealLevelField = BlzSetAbilityRealLevelField
|
|
@@ -31,6 +32,8 @@ local unitAddItem = UnitAddItem
|
|
|
31
32
|
local unitRemoveItem = UnitRemoveItem
|
|
32
33
|
local unitUseItem = UnitUseItem
|
|
33
34
|
local unitResetCooldown = UnitResetCooldown
|
|
35
|
+
local unitInventorySize = UnitInventorySize
|
|
36
|
+
local unitItemInSlot = UnitItemInSlot
|
|
34
37
|
local COOLDOWN_STARTER_ABILITY_TYPE_ID = compiletime(function()
|
|
35
38
|
if not currentMap then
|
|
36
39
|
return 0
|
|
@@ -65,7 +68,7 @@ ____exports.itemAbilityDummy = assert(CreateUnit(
|
|
|
65
68
|
270
|
|
66
69
|
))
|
|
67
70
|
local cooldownStarterItem = UnitAddItemById(____exports.itemAbilityDummy, COOLDOWN_STARTER_ITEM_TYPE_ID)
|
|
68
|
-
local cooldownStarterAbility =
|
|
71
|
+
local cooldownStarterAbility = getItemAbility(cooldownStarterItem, COOLDOWN_STARTER_ABILITY_TYPE_ID)
|
|
69
72
|
ShowUnit(____exports.itemAbilityDummy, false)
|
|
70
73
|
local function startItemCooldownInternal(handle, cooldown)
|
|
71
74
|
local cooldownGroup = getItemIntegerField(handle, ITEM_IF_COOLDOWN_GROUP)
|
|
@@ -153,4 +156,51 @@ ____exports.doAbilityActionForceDummy = function(handle, owner, action, ...)
|
|
|
153
156
|
end
|
|
154
157
|
return result
|
|
155
158
|
end
|
|
159
|
+
local depth = 0
|
|
160
|
+
local itemBySlot = {}
|
|
161
|
+
---
|
|
162
|
+
-- @internal For use by internal systems only.
|
|
163
|
+
____exports.doUnitAbilityAction = function(unit, abilityTypeId, action, ...)
|
|
164
|
+
local ____depth_0 = depth
|
|
165
|
+
depth = ____depth_0 + 1
|
|
166
|
+
local offset = 6 * ____depth_0
|
|
167
|
+
for slot = 0, unitInventorySize(unit) - 1 do
|
|
168
|
+
local item = unitItemInSlot(unit, slot)
|
|
169
|
+
if getItemAbility(item, abilityTypeId) ~= nil then
|
|
170
|
+
local isAlreadyIgnoredInEvents = ignoreEventsItems[item] ~= nil
|
|
171
|
+
if not isAlreadyIgnoredInEvents then
|
|
172
|
+
ignoreEventsItems[item] = true
|
|
173
|
+
end
|
|
174
|
+
unitRemoveItem(unit, item)
|
|
175
|
+
if not isAlreadyIgnoredInEvents then
|
|
176
|
+
ignoreEventsItems[item] = nil
|
|
177
|
+
end
|
|
178
|
+
itemBySlot[offset + slot] = item
|
|
179
|
+
end
|
|
180
|
+
end
|
|
181
|
+
local result = action(unit, ...)
|
|
182
|
+
for slot = 0, unitInventorySize(unit) - 1 do
|
|
183
|
+
local item = itemBySlot[offset + slot]
|
|
184
|
+
if item ~= nil then
|
|
185
|
+
local isAlreadyIgnoredInEvents = ignoreEventsItems[item] ~= nil
|
|
186
|
+
if not isAlreadyIgnoredInEvents then
|
|
187
|
+
ignoreEventsItems[item] = true
|
|
188
|
+
end
|
|
189
|
+
local isPowerup = isItemPowerup(item)
|
|
190
|
+
if isPowerup then
|
|
191
|
+
setItemBooleanField(item, ITEM_BF_USE_AUTOMATICALLY_WHEN_ACQUIRED, false)
|
|
192
|
+
end
|
|
193
|
+
unitAddItemToSlot(unit, item, slot)
|
|
194
|
+
if isPowerup then
|
|
195
|
+
setItemBooleanField(item, ITEM_BF_USE_AUTOMATICALLY_WHEN_ACQUIRED, true)
|
|
196
|
+
end
|
|
197
|
+
if not isAlreadyIgnoredInEvents then
|
|
198
|
+
ignoreEventsItems[item] = nil
|
|
199
|
+
end
|
|
200
|
+
itemBySlot[offset + slot] = nil
|
|
201
|
+
end
|
|
202
|
+
end
|
|
203
|
+
depth = depth - 1
|
|
204
|
+
return result
|
|
205
|
+
end
|
|
156
206
|
return ____exports
|
|
@@ -6,12 +6,18 @@ 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.itemPickedUpEvent:addListener(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
Unit.itemPickedUpEvent:addListener(
|
|
10
|
+
4,
|
|
11
|
+
function(unit, item)
|
|
12
|
+
ownerByItem[item] = unit
|
|
13
|
+
end
|
|
14
|
+
)
|
|
15
|
+
Unit.itemDroppedEvent:addListener(
|
|
16
|
+
4,
|
|
17
|
+
function(unit, item)
|
|
18
|
+
ownerByItem[item] = nil
|
|
19
|
+
end
|
|
20
|
+
)
|
|
15
21
|
__TS__ObjectDefineProperty(
|
|
16
22
|
Item.prototype,
|
|
17
23
|
"owner",
|
|
@@ -74,6 +74,7 @@ export declare class Item extends Handle<jitem> {
|
|
|
74
74
|
set charges(v: number);
|
|
75
75
|
get charges(): number;
|
|
76
76
|
consumeCharge(): boolean;
|
|
77
|
+
consumeCharges(count: number): boolean;
|
|
77
78
|
addAbility(abilityTypeId: AbilityTypeId): ItemAbility | undefined;
|
|
78
79
|
removeAbility(abilityTypeId: AbilityTypeId): boolean;
|
|
79
80
|
hasAbility(abilityTypeId: AbilityTypeId): boolean;
|
package/engine/internal/item.lua
CHANGED
|
@@ -29,7 +29,6 @@ local ____vec2 = require("math.vec2")
|
|
|
29
29
|
local distance = ____vec2.distance
|
|
30
30
|
local itemChargesChangeEvent = __TS__New(Event)
|
|
31
31
|
local itemAddAbility = BlzItemAddAbility
|
|
32
|
-
local itemRemoveAbility = BlzItemRemoveAbility
|
|
33
32
|
local getItemAbility = BlzGetItemAbility
|
|
34
33
|
local isItemPowerup = IsItemPowerup
|
|
35
34
|
local getItemAbilityByIndex = BlzGetItemAbilityByIndex
|
|
@@ -46,7 +45,11 @@ local getItemY = GetItemY
|
|
|
46
45
|
local getItemCharges = GetItemCharges
|
|
47
46
|
local setItemCharges = SetItemCharges
|
|
48
47
|
local unitRemoveAbility = UnitRemoveAbility
|
|
48
|
+
local unitRemoveItem = UnitRemoveItem
|
|
49
49
|
local unitUseItem = UnitUseItem
|
|
50
|
+
local unitUseItemPoint = UnitUseItemPoint
|
|
51
|
+
local unitUseItemTarget = UnitUseItemTarget
|
|
52
|
+
local tableRemove = table.remove
|
|
50
53
|
_G.SetItemCharges = function(whichItem, charges)
|
|
51
54
|
setItemCharges(whichItem, charges)
|
|
52
55
|
invoke(
|
|
@@ -101,7 +104,7 @@ local function consumeCharge(handle)
|
|
|
101
104
|
end
|
|
102
105
|
end
|
|
103
106
|
end
|
|
104
|
-
unitUseItem(itemAbilityDummy, handle)
|
|
107
|
+
return unitUseItem(itemAbilityDummy, handle) or unitUseItemPoint(itemAbilityDummy, handle, 0, 0) or unitUseItemTarget(itemAbilityDummy, handle, itemAbilityDummy)
|
|
105
108
|
end
|
|
106
109
|
local targetCollection
|
|
107
110
|
local targetCollectionNextIndex
|
|
@@ -144,6 +147,10 @@ function Item.prototype.____constructor(self, handle)
|
|
|
144
147
|
self[101] = luaIndexByAbilityTypeId
|
|
145
148
|
end
|
|
146
149
|
function Item.prototype.onDestroy(self)
|
|
150
|
+
local owner = self.owner
|
|
151
|
+
if owner ~= nil then
|
|
152
|
+
unitRemoveItem(owner.handle, self.handle)
|
|
153
|
+
end
|
|
147
154
|
local abilities = self[100]
|
|
148
155
|
for i = 1, #abilities do
|
|
149
156
|
abilities[i]:destroy()
|
|
@@ -155,14 +162,17 @@ function Item.create(self, id, x, y, skinId)
|
|
|
155
162
|
return self:of(BlzCreateItemWithSkin(id, x, y, skinId or id))
|
|
156
163
|
end
|
|
157
164
|
function Item.prototype.consumeCharge(self)
|
|
165
|
+
return self:consumeCharges(1)
|
|
166
|
+
end
|
|
167
|
+
function Item.prototype.consumeCharges(self, count)
|
|
158
168
|
local handle = self.handle
|
|
159
169
|
local charges = getItemCharges(handle)
|
|
160
|
-
if charges
|
|
161
|
-
setItemCharges(handle, charges -
|
|
170
|
+
if charges > count then
|
|
171
|
+
setItemCharges(handle, charges - count)
|
|
162
172
|
invoke(itemChargesChangeEvent, self)
|
|
163
173
|
return true
|
|
164
174
|
end
|
|
165
|
-
if charges ==
|
|
175
|
+
if charges == count then
|
|
166
176
|
if getItemBooleanField(handle, ITEM_BF_PERISHABLE) then
|
|
167
177
|
self:destroy()
|
|
168
178
|
return true
|
|
@@ -172,6 +182,7 @@ function Item.prototype.consumeCharge(self)
|
|
|
172
182
|
invoke(itemChargesChangeEvent, self)
|
|
173
183
|
return true
|
|
174
184
|
end
|
|
185
|
+
setItemCharges(handle, 1)
|
|
175
186
|
local ____doAbilityActionForceDummy_2 = doAbilityActionForceDummy
|
|
176
187
|
local ____opt_0 = self.owner
|
|
177
188
|
____doAbilityActionForceDummy_2(handle, ____opt_0 and ____opt_0.handle, consumeCharge)
|
|
@@ -195,14 +206,12 @@ end
|
|
|
195
206
|
function Item.prototype.removeAbility(self, abilityTypeId)
|
|
196
207
|
local luaIndexByAbilityTypeId = self[101]
|
|
197
208
|
local luaIndex = luaIndexByAbilityTypeId[abilityTypeId]
|
|
198
|
-
if luaIndex ~= nil
|
|
199
|
-
luaIndexByAbilityTypeId[abilityTypeId] = nil
|
|
209
|
+
if luaIndex ~= nil then
|
|
200
210
|
local abilities = self[100]
|
|
201
211
|
abilities[luaIndex]:destroy()
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
end
|
|
212
|
+
tableRemove(abilities, luaIndex)
|
|
213
|
+
luaIndexByAbilityTypeId[abilityTypeId] = nil
|
|
214
|
+
return true
|
|
206
215
|
end
|
|
207
216
|
return false
|
|
208
217
|
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
local ____exports = {}
|
|
2
|
+
local getLocalClientWidth = BlzGetLocalClientWidth
|
|
3
|
+
local getLocalClientHeight = BlzGetLocalClientHeight
|
|
4
|
+
---
|
|
5
|
+
-- @internal For use by internal systems only.
|
|
6
|
+
____exports.getFrameMinXMaxX = function()
|
|
7
|
+
local w = getLocalClientWidth()
|
|
8
|
+
local h = getLocalClientHeight()
|
|
9
|
+
local width4by3 = (w - h / 600 * 800) / 2
|
|
10
|
+
local pxtodpi = 0.6 / h
|
|
11
|
+
local minX = -width4by3 * pxtodpi
|
|
12
|
+
local maxX = minX + w * pxtodpi
|
|
13
|
+
return minX, maxX
|
|
14
|
+
end
|
|
15
|
+
---
|
|
16
|
+
-- @internal For use by internal systems only.
|
|
17
|
+
____exports.FRAME_MIN_Y = 0
|
|
18
|
+
---
|
|
19
|
+
-- @internal For use by internal systems only.
|
|
20
|
+
____exports.FRAME_MAX_Y = 0.6
|
|
21
|
+
return ____exports
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
local ____exports = {}
|
|
2
|
+
local getLocationZ = GetLocationZ
|
|
3
|
+
local moveLocation = MoveLocation
|
|
4
|
+
local location = Location(0, 0)
|
|
5
|
+
---
|
|
6
|
+
-- @internal For use by internal systems only.
|
|
7
|
+
____exports.getTerrainZ = function(x, y)
|
|
8
|
+
moveLocation(location, x, y)
|
|
9
|
+
return getLocationZ(location)
|
|
10
|
+
end
|
|
11
|
+
return ____exports
|
|
@@ -131,6 +131,41 @@ declare module "../unit" {
|
|
|
131
131
|
const abilityNoTargetChannelingStartEvent: DispatchingEvent<[Unit, Ability]>;
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
|
+
declare module "../unit" {
|
|
135
|
+
namespace Unit {
|
|
136
|
+
const abilityImpactEvent: DispatchingEvent<[Unit, Ability]>;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
declare module "../unit" {
|
|
140
|
+
namespace Unit {
|
|
141
|
+
const abilityWidgetTargetImpactEvent: DispatchingEvent<[Unit, Ability, Widget]>;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
declare module "../unit" {
|
|
145
|
+
namespace Unit {
|
|
146
|
+
const abilityUnitTargetImpactEvent: DispatchingEvent<[Unit, Ability, Unit]>;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
declare module "../unit" {
|
|
150
|
+
namespace Unit {
|
|
151
|
+
const abilityItemTargetImpactEvent: DispatchingEvent<[Unit, Ability, Item]>;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
declare module "../unit" {
|
|
155
|
+
namespace Unit {
|
|
156
|
+
const abilityDestructibleTargetImpactEvent: DispatchingEvent<[Unit, Ability, Destructable]>;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
declare module "../unit" {
|
|
160
|
+
namespace Unit {
|
|
161
|
+
const abilityPointTargetImpactEvent: DispatchingEvent<[Unit, Ability, number, number]>;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
declare module "../unit" {
|
|
165
|
+
namespace Unit {
|
|
166
|
+
const abilityNoTargetImpactEvent: DispatchingEvent<[Unit, Ability]>;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
134
169
|
declare module "../unit" {
|
|
135
170
|
namespace Unit {
|
|
136
171
|
const abilityChannelingFinishEvent: DispatchingEvent<[Unit, Ability]>;
|
|
@@ -21,6 +21,8 @@ local ____preconditions = require("utility.preconditions")
|
|
|
21
21
|
local checkNotNull = ____preconditions.checkNotNull
|
|
22
22
|
local ____lazy = require("utility.lazy")
|
|
23
23
|
local lazyRecord = ____lazy.lazyRecord
|
|
24
|
+
local ____timer = require("core.types.timer")
|
|
25
|
+
local Timer = ____timer.Timer
|
|
24
26
|
local eventInvoke = Event.invoke
|
|
25
27
|
local condition = Condition
|
|
26
28
|
local createTrigger = CreateTrigger
|
|
@@ -345,6 +347,66 @@ rawset(
|
|
|
345
347
|
extractAbilityTypeId
|
|
346
348
|
)
|
|
347
349
|
)
|
|
350
|
+
local internalAbilityImpactEvent = __TS__New(Event)
|
|
351
|
+
internalAbilityChannelingStartEvent:addListener(function(...)
|
|
352
|
+
Timer:run(eventInvoke, internalAbilityImpactEvent, ...)
|
|
353
|
+
end)
|
|
354
|
+
rawset(
|
|
355
|
+
Unit,
|
|
356
|
+
"abilityImpactEvent",
|
|
357
|
+
createDispatchingEvent(
|
|
358
|
+
createCommonEvent(internalAbilityImpactEvent),
|
|
359
|
+
extractAbilityTypeId
|
|
360
|
+
)
|
|
361
|
+
)
|
|
362
|
+
rawset(
|
|
363
|
+
Unit,
|
|
364
|
+
"abilityWidgetTargetImpactEvent",
|
|
365
|
+
createDispatchingEvent(
|
|
366
|
+
createWidgetTargetEvent(internalAbilityImpactEvent),
|
|
367
|
+
extractAbilityTypeId
|
|
368
|
+
)
|
|
369
|
+
)
|
|
370
|
+
rawset(
|
|
371
|
+
Unit,
|
|
372
|
+
"abilityUnitTargetImpactEvent",
|
|
373
|
+
createDispatchingEvent(
|
|
374
|
+
createUnitTargetEvent(internalAbilityImpactEvent),
|
|
375
|
+
extractAbilityTypeId
|
|
376
|
+
)
|
|
377
|
+
)
|
|
378
|
+
rawset(
|
|
379
|
+
Unit,
|
|
380
|
+
"abilityItemTargetImpactEvent",
|
|
381
|
+
createDispatchingEvent(
|
|
382
|
+
createItemTargetEvent(internalAbilityImpactEvent),
|
|
383
|
+
extractAbilityTypeId
|
|
384
|
+
)
|
|
385
|
+
)
|
|
386
|
+
rawset(
|
|
387
|
+
Unit,
|
|
388
|
+
"abilityDestructibleTargetImpactEvent",
|
|
389
|
+
createDispatchingEvent(
|
|
390
|
+
createDestructibleTargetEvent(internalAbilityImpactEvent),
|
|
391
|
+
extractAbilityTypeId
|
|
392
|
+
)
|
|
393
|
+
)
|
|
394
|
+
rawset(
|
|
395
|
+
Unit,
|
|
396
|
+
"abilityPointTargetImpactEvent",
|
|
397
|
+
createDispatchingEvent(
|
|
398
|
+
createPointTargetEvent(internalAbilityImpactEvent),
|
|
399
|
+
extractAbilityTypeId
|
|
400
|
+
)
|
|
401
|
+
)
|
|
402
|
+
rawset(
|
|
403
|
+
Unit,
|
|
404
|
+
"abilityNoTargetImpactEvent",
|
|
405
|
+
createDispatchingEvent(
|
|
406
|
+
createNoTargetEvent(internalAbilityImpactEvent),
|
|
407
|
+
extractAbilityTypeId
|
|
408
|
+
)
|
|
409
|
+
)
|
|
348
410
|
rawset(
|
|
349
411
|
Unit,
|
|
350
412
|
"abilityChannelingFinishEvent",
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** @noSelfInFile */
|
|
2
|
+
import { Widget } from "../../../core/types/widget";
|
|
3
|
+
export declare const enum OrderType {
|
|
4
|
+
IMMEDIATE = 0,
|
|
5
|
+
POINT = 1,
|
|
6
|
+
TARGET = 2
|
|
7
|
+
}
|
|
8
|
+
declare module "../unit" {
|
|
9
|
+
interface Unit {
|
|
10
|
+
readonly currentOrderType: OrderType;
|
|
11
|
+
readonly currentOrderId: number;
|
|
12
|
+
readonly currentOrderStartTime: number;
|
|
13
|
+
readonly currentOrderStartX: number;
|
|
14
|
+
readonly currentOrderStartY: number;
|
|
15
|
+
readonly currentOrderTargetX: number;
|
|
16
|
+
readonly currentOrderTargetY: number;
|
|
17
|
+
readonly currentOrderTarget?: Widget;
|
|
18
|
+
issueOrder(...order: [orderType: OrderType.IMMEDIATE, orderId: number] | [orderType: OrderType.POINT, orderId: number, x: number, y: number] | [orderType: OrderType.TARGET, orderId: number, target: Widget]): boolean;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
local ____lualib = require("lualib_bundle")
|
|
2
|
+
local __TS__ObjectDefineProperty = ____lualib.__TS__ObjectDefineProperty
|
|
3
|
+
local ____exports = {}
|
|
4
|
+
local ____attributes = require("attributes")
|
|
5
|
+
local attribute = ____attributes.attribute
|
|
6
|
+
local ____unit = require("engine.internal.unit")
|
|
7
|
+
local Unit = ____unit.Unit
|
|
8
|
+
local ____game = require("core.game")
|
|
9
|
+
local elapsedTime = ____game.elapsedTime
|
|
10
|
+
local getUnitCurrentOrder = GetUnitCurrentOrder
|
|
11
|
+
local issueImmediateOrderById = IssueImmediateOrderById
|
|
12
|
+
local issuePointOrderById = IssuePointOrderById
|
|
13
|
+
local issueTargetOrderById = IssueTargetOrderById
|
|
14
|
+
local unitLastOrderTypeAttribute = attribute()
|
|
15
|
+
local unitLastOrderIdAttribute = attribute()
|
|
16
|
+
local unitLastOrderStartTimeAttribute = attribute()
|
|
17
|
+
local unitLastOrderStartXAttribute = attribute()
|
|
18
|
+
local unitLastOrderStartYAttribute = attribute()
|
|
19
|
+
local unitLastOrderTargetXAttribute = attribute()
|
|
20
|
+
local unitLastOrderTargetYAttribute = attribute()
|
|
21
|
+
local unitLastOrderTargetAttribute = attribute()
|
|
22
|
+
Unit.onImmediateOrder:addListener(
|
|
23
|
+
4,
|
|
24
|
+
function(unit, orderId)
|
|
25
|
+
unit[unitLastOrderTypeAttribute] = 0
|
|
26
|
+
unit[unitLastOrderIdAttribute] = orderId
|
|
27
|
+
unit[unitLastOrderStartTimeAttribute] = elapsedTime()
|
|
28
|
+
unit[unitLastOrderStartXAttribute] = unit.x
|
|
29
|
+
unit[unitLastOrderStartYAttribute] = unit.y
|
|
30
|
+
unit[unitLastOrderTargetXAttribute] = nil
|
|
31
|
+
unit[unitLastOrderTargetYAttribute] = nil
|
|
32
|
+
unit[unitLastOrderTargetAttribute] = nil
|
|
33
|
+
end
|
|
34
|
+
)
|
|
35
|
+
Unit.onPointOrder:addListener(
|
|
36
|
+
4,
|
|
37
|
+
function(unit, orderId, x, y)
|
|
38
|
+
unit[unitLastOrderTypeAttribute] = 1
|
|
39
|
+
unit[unitLastOrderIdAttribute] = orderId
|
|
40
|
+
unit[unitLastOrderStartTimeAttribute] = elapsedTime()
|
|
41
|
+
unit[unitLastOrderStartXAttribute] = unit.x
|
|
42
|
+
unit[unitLastOrderStartYAttribute] = unit.y
|
|
43
|
+
unit[unitLastOrderTargetXAttribute] = x
|
|
44
|
+
unit[unitLastOrderTargetYAttribute] = y
|
|
45
|
+
unit[unitLastOrderTargetAttribute] = nil
|
|
46
|
+
end
|
|
47
|
+
)
|
|
48
|
+
Unit.onTargetOrder:addListener(
|
|
49
|
+
4,
|
|
50
|
+
function(unit, orderId, target)
|
|
51
|
+
unit[unitLastOrderTypeAttribute] = 2
|
|
52
|
+
unit[unitLastOrderIdAttribute] = orderId
|
|
53
|
+
unit[unitLastOrderStartTimeAttribute] = elapsedTime()
|
|
54
|
+
unit[unitLastOrderStartXAttribute] = unit.x
|
|
55
|
+
unit[unitLastOrderStartYAttribute] = unit.y
|
|
56
|
+
unit[unitLastOrderTargetXAttribute] = target.x
|
|
57
|
+
unit[unitLastOrderTargetYAttribute] = target.y
|
|
58
|
+
unit[unitLastOrderTargetAttribute] = target
|
|
59
|
+
end
|
|
60
|
+
)
|
|
61
|
+
local function toUndefinedIfCurrentOrderDoesNotMatchLast(unit, value)
|
|
62
|
+
local currentOrderId = getUnitCurrentOrder(unit.handle)
|
|
63
|
+
local lastOrderId = unit[unitLastOrderIdAttribute]
|
|
64
|
+
local ____temp_0
|
|
65
|
+
if currentOrderId == lastOrderId or currentOrderId == orderId("patrolAI") and lastOrderId == orderId("patrol") then
|
|
66
|
+
____temp_0 = value
|
|
67
|
+
else
|
|
68
|
+
____temp_0 = nil
|
|
69
|
+
end
|
|
70
|
+
return ____temp_0
|
|
71
|
+
end
|
|
72
|
+
__TS__ObjectDefineProperty(
|
|
73
|
+
Unit.prototype,
|
|
74
|
+
"currentOrderType",
|
|
75
|
+
{get = function(self)
|
|
76
|
+
return toUndefinedIfCurrentOrderDoesNotMatchLast(self, self[unitLastOrderTypeAttribute]) or 0
|
|
77
|
+
end}
|
|
78
|
+
)
|
|
79
|
+
__TS__ObjectDefineProperty(
|
|
80
|
+
Unit.prototype,
|
|
81
|
+
"currentOrderId",
|
|
82
|
+
{get = function(self)
|
|
83
|
+
return toUndefinedIfCurrentOrderDoesNotMatchLast(self, self[unitLastOrderIdAttribute]) or 0
|
|
84
|
+
end}
|
|
85
|
+
)
|
|
86
|
+
__TS__ObjectDefineProperty(
|
|
87
|
+
Unit.prototype,
|
|
88
|
+
"currentOrderStartTime",
|
|
89
|
+
{get = function(self)
|
|
90
|
+
return toUndefinedIfCurrentOrderDoesNotMatchLast(self, self[unitLastOrderStartTimeAttribute]) or 0
|
|
91
|
+
end}
|
|
92
|
+
)
|
|
93
|
+
__TS__ObjectDefineProperty(
|
|
94
|
+
Unit.prototype,
|
|
95
|
+
"currentOrderStartX",
|
|
96
|
+
{get = function(self)
|
|
97
|
+
return toUndefinedIfCurrentOrderDoesNotMatchLast(self, self[unitLastOrderStartXAttribute]) or 0
|
|
98
|
+
end}
|
|
99
|
+
)
|
|
100
|
+
__TS__ObjectDefineProperty(
|
|
101
|
+
Unit.prototype,
|
|
102
|
+
"currentOrderStartY",
|
|
103
|
+
{get = function(self)
|
|
104
|
+
return toUndefinedIfCurrentOrderDoesNotMatchLast(self, self[unitLastOrderStartYAttribute]) or 0
|
|
105
|
+
end}
|
|
106
|
+
)
|
|
107
|
+
__TS__ObjectDefineProperty(
|
|
108
|
+
Unit.prototype,
|
|
109
|
+
"currentOrderTargetX",
|
|
110
|
+
{get = function(self)
|
|
111
|
+
return toUndefinedIfCurrentOrderDoesNotMatchLast(self, self[unitLastOrderTargetXAttribute]) or 0
|
|
112
|
+
end}
|
|
113
|
+
)
|
|
114
|
+
__TS__ObjectDefineProperty(
|
|
115
|
+
Unit.prototype,
|
|
116
|
+
"currentOrderTargetY",
|
|
117
|
+
{get = function(self)
|
|
118
|
+
return toUndefinedIfCurrentOrderDoesNotMatchLast(self, self[unitLastOrderTargetYAttribute]) or 0
|
|
119
|
+
end}
|
|
120
|
+
)
|
|
121
|
+
__TS__ObjectDefineProperty(
|
|
122
|
+
Unit.prototype,
|
|
123
|
+
"currentOrderTarget",
|
|
124
|
+
{get = function(self)
|
|
125
|
+
return toUndefinedIfCurrentOrderDoesNotMatchLast(self, self[unitLastOrderTargetAttribute])
|
|
126
|
+
end}
|
|
127
|
+
)
|
|
128
|
+
local issueOrderByType = {
|
|
129
|
+
[0] = issueImmediateOrderById,
|
|
130
|
+
[1] = issuePointOrderById,
|
|
131
|
+
[2] = function(unitHandle, orderId, widget) return issueTargetOrderById(unitHandle, orderId, widget.handle) end
|
|
132
|
+
}
|
|
133
|
+
Unit.prototype.issueOrder = function(self, orderType, orderId, xOrTarget, y)
|
|
134
|
+
return issueOrderByType[orderType](self.handle, orderId, xOrTarget, y)
|
|
135
|
+
end
|
|
136
|
+
return ____exports
|
|
@@ -7,8 +7,8 @@ local UnitAbility = ____ability.UnitAbility
|
|
|
7
7
|
local ____unit = require("engine.internal.unit")
|
|
8
8
|
local Unit = ____unit.Unit
|
|
9
9
|
local ____event = require("event")
|
|
10
|
-
local Event = ____event.Event
|
|
11
10
|
local createDispatchingEvent = ____event.createDispatchingEvent
|
|
11
|
+
local Event = ____event.Event
|
|
12
12
|
local abilityGainedEvent = createDispatchingEvent(
|
|
13
13
|
__TS__New(Event),
|
|
14
14
|
function(unit, ability) return ability.typeId end
|
|
@@ -40,6 +40,15 @@ ItemAbility.onCreate:addListener(
|
|
|
40
40
|
end
|
|
41
41
|
end
|
|
42
42
|
)
|
|
43
|
+
ItemAbility.destroyEvent:addListener(
|
|
44
|
+
4,
|
|
45
|
+
function(ability)
|
|
46
|
+
local unit = ability.owner.owner
|
|
47
|
+
if unit ~= nil then
|
|
48
|
+
Event.invoke(abilityLostEvent, unit, ability)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
)
|
|
43
52
|
Unit.itemPickedUpEvent:addListener(
|
|
44
53
|
0,
|
|
45
54
|
function(unit, item)
|
|
@@ -9,6 +9,8 @@ local ____timer = require("core.types.timer")
|
|
|
9
9
|
local Timer = ____timer.Timer
|
|
10
10
|
local ____lua_2Dsets = require("utility.lua-sets")
|
|
11
11
|
local luaSetOf = ____lua_2Dsets.luaSetOf
|
|
12
|
+
local ____math = require("math")
|
|
13
|
+
local min = ____math.min
|
|
12
14
|
local autoAttackFinishEvent = __TS__New(Event)
|
|
13
15
|
rawset(Unit, "autoAttackFinishEvent", autoAttackFinishEvent)
|
|
14
16
|
local eventTimerByUnit = {}
|
|
@@ -45,7 +47,12 @@ local function timerCallback(source, target)
|
|
|
45
47
|
end
|
|
46
48
|
Unit.autoAttackStartEvent:addListener(function(source, target)
|
|
47
49
|
local attackPoint = (source:chooseWeapon(target) or source.firstWeapon).impactDelay
|
|
48
|
-
local timer = Timer:simple(
|
|
50
|
+
local timer = Timer:simple(
|
|
51
|
+
attackPoint + min(0.001, attackPoint / 2),
|
|
52
|
+
timerCallback,
|
|
53
|
+
source,
|
|
54
|
+
target
|
|
55
|
+
)
|
|
49
56
|
eventTimerByUnit[source] = timer
|
|
50
57
|
end)
|
|
51
58
|
return ____exports
|