warscript 0.0.1-dev.ed60fea → 0.0.1-dev.f48f7bb
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.
|
@@ -14,6 +14,8 @@ local ____math = require("math")
|
|
|
14
14
|
local MINIMUM_POSITIVE_NORMALIZED_FLOAT = ____math.MINIMUM_POSITIVE_NORMALIZED_FLOAT
|
|
15
15
|
local ____timer = require("core.types.timer")
|
|
16
16
|
local Timer = ____timer.Timer
|
|
17
|
+
local ____ignore_2Devents_2Ditems = require("engine.internal.unit.ignore-events-items")
|
|
18
|
+
local ignoreEventsItems = ____ignore_2Devents_2Ditems.ignoreEventsItems
|
|
17
19
|
local isItemOwned = IsItemOwned
|
|
18
20
|
local isItemPowerup = IsItemPowerup
|
|
19
21
|
local getItemX = GetItemX
|
|
@@ -86,6 +88,10 @@ ____exports.abilityActionDummy = dummy
|
|
|
86
88
|
---
|
|
87
89
|
-- @internal For use by internal systems only.
|
|
88
90
|
____exports.doAbilityAction = function(handle, action, ...)
|
|
91
|
+
local isAlreadyIgnoredInEvents = ignoreEventsItems[handle] ~= nil
|
|
92
|
+
if not isAlreadyIgnoredInEvents then
|
|
93
|
+
ignoreEventsItems[handle] = true
|
|
94
|
+
end
|
|
89
95
|
local isOwned = isItemOwned(handle)
|
|
90
96
|
local isPowerup
|
|
91
97
|
local x
|
|
@@ -107,6 +113,9 @@ ____exports.doAbilityAction = function(handle, action, ...)
|
|
|
107
113
|
setItemBooleanField(handle, ITEM_BF_USE_AUTOMATICALLY_WHEN_ACQUIRED, true)
|
|
108
114
|
end
|
|
109
115
|
end
|
|
116
|
+
if not isAlreadyIgnoredInEvents then
|
|
117
|
+
ignoreEventsItems[handle] = nil
|
|
118
|
+
end
|
|
110
119
|
return result
|
|
111
120
|
end
|
|
112
121
|
---
|
|
@@ -119,6 +128,10 @@ ____exports.doAbilityActionForceDummy = function(handle, owner, action, ...)
|
|
|
119
128
|
if slot == nil then
|
|
120
129
|
return ____exports.doAbilityAction(handle, action, ...)
|
|
121
130
|
end
|
|
131
|
+
local isAlreadyIgnoredInEvents = ignoreEventsItems[handle] ~= nil
|
|
132
|
+
if not isAlreadyIgnoredInEvents then
|
|
133
|
+
ignoreEventsItems[handle] = true
|
|
134
|
+
end
|
|
122
135
|
local isPowerup
|
|
123
136
|
if isItemPowerup(handle) then
|
|
124
137
|
setItemBooleanField(handle, ITEM_BF_USE_AUTOMATICALLY_WHEN_ACQUIRED, false)
|
|
@@ -133,6 +146,9 @@ ____exports.doAbilityActionForceDummy = function(handle, owner, action, ...)
|
|
|
133
146
|
if isPowerup then
|
|
134
147
|
setItemBooleanField(handle, ITEM_BF_USE_AUTOMATICALLY_WHEN_ACQUIRED, true)
|
|
135
148
|
end
|
|
149
|
+
if not isAlreadyIgnoredInEvents then
|
|
150
|
+
ignoreEventsItems[handle] = nil
|
|
151
|
+
end
|
|
136
152
|
return result
|
|
137
153
|
end
|
|
138
154
|
return ____exports
|
|
@@ -9,15 +9,36 @@ local ____unit = require("engine.internal.unit")
|
|
|
9
9
|
local Unit = ____unit.Unit
|
|
10
10
|
local ____utility = require("engine.internal.utility")
|
|
11
11
|
local findUnitItemSlot = ____utility.findUnitItemSlot
|
|
12
|
+
local ____blank = require("engine.object-data.entry.item-type.blank")
|
|
13
|
+
local BlankItemType = ____blank.BlankItemType
|
|
14
|
+
local ____arrays = require("utility.arrays")
|
|
15
|
+
local array = ____arrays.array
|
|
16
|
+
local ____ignore_2Devents_2Ditems = require("engine.internal.unit.ignore-events-items")
|
|
17
|
+
local ignoreEventsItems = ____ignore_2Devents_2Ditems.ignoreEventsItems
|
|
12
18
|
local rawset = _G.rawset
|
|
13
19
|
local ____type = _G.type
|
|
14
20
|
local isItemPowerup = IsItemPowerup
|
|
15
21
|
local setItemBooleanField = BlzSetItemBooleanField
|
|
16
22
|
local unitAddItem = UnitAddItem
|
|
17
|
-
local unitDropItemSlot = UnitDropItemSlot
|
|
18
23
|
local unitInventorySize = UnitInventorySize
|
|
19
24
|
local unitItemInSlot = UnitItemInSlot
|
|
25
|
+
local unitRemoveItem = UnitRemoveItem
|
|
20
26
|
local unitRemoveItemFromSlot = UnitRemoveItemFromSlot
|
|
27
|
+
local FILLER_ITEM_TYPE_ID = compiletime(function()
|
|
28
|
+
local itemType = BlankItemType:create()
|
|
29
|
+
itemType.name = "[Warscript/Dummy] Slot Filler"
|
|
30
|
+
return itemType.id
|
|
31
|
+
end)
|
|
32
|
+
local fillerItems = array(
|
|
33
|
+
6,
|
|
34
|
+
function()
|
|
35
|
+
local item = CreateItem(FILLER_ITEM_TYPE_ID, 0, 0)
|
|
36
|
+
SetItemVisible(item, false)
|
|
37
|
+
ignoreEventsItems[item] = true
|
|
38
|
+
return item
|
|
39
|
+
end
|
|
40
|
+
)
|
|
41
|
+
local unitsWithFillerItems = {}
|
|
21
42
|
local handleByUnitItems = setmetatable({}, {__mode = "k"})
|
|
22
43
|
local function unitItemsNext(handle, index)
|
|
23
44
|
local slot = index & 7
|
|
@@ -47,8 +68,19 @@ function UnitItems.prototype.__newindex(self, slot, item)
|
|
|
47
68
|
if isPowerup then
|
|
48
69
|
setItemBooleanField(itemHandle, ITEM_BF_USE_AUTOMATICALLY_WHEN_ACQUIRED, false)
|
|
49
70
|
end
|
|
71
|
+
for previousSlot = 0, slot - 2 do
|
|
72
|
+
if unitItemInSlot(handle, previousSlot) == nil then
|
|
73
|
+
unitAddItem(handle, fillerItems[previousSlot + 1])
|
|
74
|
+
unitsWithFillerItems[handle] = true
|
|
75
|
+
end
|
|
76
|
+
end
|
|
50
77
|
unitAddItem(handle, itemHandle)
|
|
51
|
-
|
|
78
|
+
if unitsWithFillerItems[handle] ~= nil then
|
|
79
|
+
for previousSlot = 0, slot - 2 do
|
|
80
|
+
unitRemoveItem(handle, fillerItems[previousSlot + 1])
|
|
81
|
+
end
|
|
82
|
+
unitsWithFillerItems[handle] = nil
|
|
83
|
+
end
|
|
52
84
|
if isPowerup then
|
|
53
85
|
setItemBooleanField(itemHandle, ITEM_BF_USE_AUTOMATICALLY_WHEN_ACQUIRED, true)
|
|
54
86
|
end
|
|
@@ -67,6 +99,18 @@ function UnitItems.prototype.__ipairs(self)
|
|
|
67
99
|
local handle = handleByUnitItems[self]
|
|
68
100
|
return unitItemsNext, handle, unitInventorySize(handle) << 3
|
|
69
101
|
end
|
|
102
|
+
Unit.itemPickedUpEvent:addListener(
|
|
103
|
+
4,
|
|
104
|
+
function(unit)
|
|
105
|
+
local handle = unit.handle
|
|
106
|
+
if unitsWithFillerItems[handle] ~= nil then
|
|
107
|
+
for previousSlot = 1, 6 do
|
|
108
|
+
unitRemoveItem(handle, fillerItems[previousSlot])
|
|
109
|
+
end
|
|
110
|
+
unitsWithFillerItems[handle] = nil
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
)
|
|
70
114
|
__TS__ObjectDefineProperty(
|
|
71
115
|
Unit.prototype,
|
|
72
116
|
"items",
|
package/engine/internal/unit.lua
CHANGED
|
@@ -51,6 +51,8 @@ local ____arrays = require("utility.arrays")
|
|
|
51
51
|
local forEach = ____arrays.forEach
|
|
52
52
|
local ____math = require("math")
|
|
53
53
|
local min = ____math.min
|
|
54
|
+
local ____ignore_2Devents_2Ditems = require("engine.internal.unit.ignore-events-items")
|
|
55
|
+
local ignoreEventsItems = ____ignore_2Devents_2Ditems.ignoreEventsItems
|
|
54
56
|
local match = string.match
|
|
55
57
|
local ____tostring = _G.tostring
|
|
56
58
|
local setUnitAnimation = SetUnitAnimation
|
|
@@ -2518,8 +2520,9 @@ Unit.itemDroppedEvent = __TS__New(
|
|
|
2518
2520
|
EVENT_PLAYER_UNIT_DROP_ITEM,
|
|
2519
2521
|
function()
|
|
2520
2522
|
local unit = getTriggerUnit()
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
+
local item = getManipulatedItem()
|
|
2524
|
+
if getUnitTypeId(unit) ~= dummyUnitId and not (ignoreEventsItems[item] ~= nil) then
|
|
2525
|
+
return ____exports.Unit:of(unit), Item:of(item)
|
|
2523
2526
|
end
|
|
2524
2527
|
return IgnoreEvent
|
|
2525
2528
|
end
|
|
@@ -2529,8 +2532,9 @@ Unit.itemPickedUpEvent = __TS__New(
|
|
|
2529
2532
|
EVENT_PLAYER_UNIT_PICKUP_ITEM,
|
|
2530
2533
|
function()
|
|
2531
2534
|
local unit = getTriggerUnit()
|
|
2532
|
-
|
|
2533
|
-
|
|
2535
|
+
local item = getManipulatedItem()
|
|
2536
|
+
if getUnitTypeId(unit) ~= dummyUnitId and not (ignoreEventsItems[item] ~= nil) then
|
|
2537
|
+
return ____exports.Unit:of(unit), Item:of(item)
|
|
2534
2538
|
end
|
|
2535
2539
|
return IgnoreEvent
|
|
2536
2540
|
end
|
|
@@ -2540,8 +2544,9 @@ Unit.itemUsedEvent = __TS__New(
|
|
|
2540
2544
|
EVENT_PLAYER_UNIT_USE_ITEM,
|
|
2541
2545
|
function()
|
|
2542
2546
|
local unit = getTriggerUnit()
|
|
2543
|
-
|
|
2544
|
-
|
|
2547
|
+
local item = getManipulatedItem()
|
|
2548
|
+
if getUnitTypeId(unit) ~= dummyUnitId and not (ignoreEventsItems[item] ~= nil) then
|
|
2549
|
+
return ____exports.Unit:of(unit), Item:of(item)
|
|
2545
2550
|
end
|
|
2546
2551
|
return IgnoreEvent
|
|
2547
2552
|
end
|
package/package.json
CHANGED