warscript 0.0.1-dev.833c02f → 0.0.1-dev.83957b1
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/order.d.ts +1 -0
- package/core/types/order.lua +11 -1
- package/engine/behaviour/ability/emulate-impact.lua +9 -2
- package/engine/behaviour/ability.lua +1 -1
- package/engine/behaviour/unit.d.ts +15 -0
- package/engine/behaviour/unit.lua +114 -4
- package/engine/internal/ability.d.ts +4 -0
- package/engine/internal/ability.lua +17 -0
- package/engine/internal/item/ability.lua +12 -10
- package/engine/internal/item.d.ts +3 -1
- package/engine/internal/item.lua +75 -3
- package/engine/internal/unit/ability.d.ts +5 -0
- package/engine/internal/unit/ability.lua +14 -0
- package/engine/internal/unit/allowed-targets.d.ts +1 -1
- package/engine/internal/unit/allowed-targets.lua +9 -1
- package/engine/internal/unit-missile-launch.lua +1 -1
- package/engine/internal/unit.d.ts +7 -1
- package/engine/internal/unit.lua +74 -1
- package/engine/object-field.d.ts +4 -3
- package/engine/object-field.lua +10 -5
- package/package.json +1 -1
package/core/types/order.d.ts
CHANGED
package/core/types/order.lua
CHANGED
|
@@ -3,16 +3,25 @@ local __TS__ObjectDefineProperty = ____lualib.__TS__ObjectDefineProperty
|
|
|
3
3
|
local ____exports = {}
|
|
4
4
|
local ____unit = require("core.types.unit")
|
|
5
5
|
local Unit = ____unit.Unit
|
|
6
|
+
local ____game = require("core.game")
|
|
7
|
+
local elapsedTime = ____game.elapsedTime
|
|
6
8
|
local getUnitCurrentOrder = GetUnitCurrentOrder
|
|
7
9
|
local orders = setmetatable({}, {__mode = "k"})
|
|
8
10
|
Unit.onImmediateOrder:addListener(function(unit, orderId)
|
|
9
|
-
orders[unit] = {
|
|
11
|
+
orders[unit] = {
|
|
12
|
+
id = orderId,
|
|
13
|
+
startX = unit.x,
|
|
14
|
+
startY = unit.y,
|
|
15
|
+
issueTime = elapsedTime(),
|
|
16
|
+
type = "immediate"
|
|
17
|
+
}
|
|
10
18
|
end)
|
|
11
19
|
Unit.onPointOrder:addListener(function(unit, orderId, x, y)
|
|
12
20
|
orders[unit] = {
|
|
13
21
|
id = orderId,
|
|
14
22
|
startX = unit.x,
|
|
15
23
|
startY = unit.y,
|
|
24
|
+
issueTime = elapsedTime(),
|
|
16
25
|
type = "point",
|
|
17
26
|
targetX = x,
|
|
18
27
|
targetY = y
|
|
@@ -23,6 +32,7 @@ Unit.onTargetOrder:addListener(function(unit, orderId, target)
|
|
|
23
32
|
id = orderId,
|
|
24
33
|
startX = unit.x,
|
|
25
34
|
startY = unit.y,
|
|
35
|
+
issueTime = elapsedTime(),
|
|
26
36
|
type = "target",
|
|
27
37
|
target = target
|
|
28
38
|
}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
local ____lualib = require("lualib_bundle")
|
|
2
2
|
local __TS__Class = ____lualib.__TS__Class
|
|
3
3
|
local __TS__ClassExtends = ____lualib.__TS__ClassExtends
|
|
4
|
+
local __TS__InstanceOf = ____lualib.__TS__InstanceOf
|
|
4
5
|
local ____exports = {}
|
|
5
6
|
local ____ability = require("engine.behaviour.ability")
|
|
6
7
|
local AbilityBehavior = ____ability.AbilityBehavior
|
|
8
|
+
local ____unit = require("engine.internal.unit")
|
|
9
|
+
local Unit = ____unit.Unit
|
|
7
10
|
local ____ability = require("engine.standard.fields.ability")
|
|
8
11
|
local COOLDOWN_ABILITY_FLOAT_LEVEL_FIELD = ____ability.COOLDOWN_ABILITY_FLOAT_LEVEL_FIELD
|
|
9
12
|
local MANA_COST_ABILITY_INTEGER_LEVEL_FIELD = ____ability.MANA_COST_ABILITY_INTEGER_LEVEL_FIELD
|
|
@@ -13,6 +16,10 @@ local MINIMUM_POSITIVE_NORMALIZED_FLOAT = ____math.MINIMUM_POSITIVE_NORMALIZED_F
|
|
|
13
16
|
local ____sound = require("core.types.sound")
|
|
14
17
|
local Sound3D = ____sound.Sound3D
|
|
15
18
|
local SoundSettings = ____sound.SoundSettings
|
|
19
|
+
local ____ability = require("engine.internal.ability")
|
|
20
|
+
local UnitAbility = ____ability.UnitAbility
|
|
21
|
+
local ____event = require("event")
|
|
22
|
+
local Event = ____event.Event
|
|
16
23
|
____exports.EmulateImpactAbilityBehavior = __TS__Class()
|
|
17
24
|
local EmulateImpactAbilityBehavior = ____exports.EmulateImpactAbilityBehavior
|
|
18
25
|
EmulateImpactAbilityBehavior.name = "EmulateImpactAbilityBehavior"
|
|
@@ -20,7 +27,7 @@ __TS__ClassExtends(EmulateImpactAbilityBehavior, AbilityBehavior)
|
|
|
20
27
|
function EmulateImpactAbilityBehavior.prototype.emulateImpact(self, caster)
|
|
21
28
|
local manaCost = self:resolveCurrentAbilityDependentValue(MANA_COST_ABILITY_INTEGER_LEVEL_FIELD)
|
|
22
29
|
local cooldown = self:resolveCurrentAbilityDependentValue(COOLDOWN_ABILITY_FLOAT_LEVEL_FIELD)
|
|
23
|
-
if self.ability.cooldownRemaining ~= 0 or caster.mana < manaCost then
|
|
30
|
+
if self.ability.cooldownRemaining ~= 0 or caster.mana < manaCost or __TS__InstanceOf(self.ability, UnitAbility) and self.ability.isDisabled then
|
|
24
31
|
return
|
|
25
32
|
end
|
|
26
33
|
caster.mana = caster.mana - manaCost
|
|
@@ -30,6 +37,6 @@ function EmulateImpactAbilityBehavior.prototype.emulateImpact(self, caster)
|
|
|
30
37
|
if soundPresetId ~= "" then
|
|
31
38
|
Sound3D:playFromLabel(soundPresetId, SoundSettings.Ability, caster)
|
|
32
39
|
end
|
|
33
|
-
|
|
40
|
+
Event.invoke(Unit.abilityImpactEvent, caster, self.ability)
|
|
34
41
|
end
|
|
35
42
|
return ____exports
|
|
@@ -274,7 +274,7 @@ __TS__SetDescriptor(
|
|
|
274
274
|
Unit.abilityDestructibleTargetChannelingStartEvent:addListener(createUnitEventListener("onDestructibleTargetChannelingStart"))
|
|
275
275
|
Unit.abilityPointTargetChannelingStartEvent:addListener(createUnitEventListener("onPointTargetChannelingStart"))
|
|
276
276
|
Unit.abilityNoTargetChannelingStartEvent:addListener(createUnitEventListener("onNoTargetChannelingStart"))
|
|
277
|
-
Unit.
|
|
277
|
+
Unit.abilityImpactEvent:addListener(createUnitEventListener("onImpact"))
|
|
278
278
|
Unit.abilityWidgetTargetChannelingStartEvent:addListener(createZeroTimerUnitEventListener("onWidgetTargetImpact"))
|
|
279
279
|
Unit.abilityUnitTargetChannelingStartEvent:addListener(createZeroTimerUnitEventListener("onUnitTargetImpact"))
|
|
280
280
|
Unit.abilityItemTargetChannelingStartEvent:addListener(createZeroTimerUnitEventListener("onItemTargetImpact"))
|
|
@@ -6,23 +6,38 @@ import "../internal/unit+ability";
|
|
|
6
6
|
import "../internal/unit-missile-launch";
|
|
7
7
|
import { Item } from "../internal/item";
|
|
8
8
|
import type { AbilityBehavior } from "./ability";
|
|
9
|
+
import { Event } from "../../event";
|
|
10
|
+
import { Destructor } from "../../destroyable";
|
|
11
|
+
import type { Widget } from "../../core/types/widget";
|
|
9
12
|
export type UnitBehaviorConstructor<Args extends any[]> = new (unit: Unit, ...args: Args) => UnitBehavior;
|
|
10
13
|
export declare abstract class UnitBehavior<PeriodicActionParameters extends any[] = any[]> extends Behavior<Unit, PeriodicActionParameters> {
|
|
11
14
|
constructor(unit: Unit);
|
|
15
|
+
protected onDestroy(): Destructor;
|
|
12
16
|
readonly sourceAbilityBehavior?: AbilityBehavior;
|
|
13
17
|
get unit(): Unit;
|
|
18
|
+
registerInRangeUnitEvent<T extends string, Args extends any[]>(this: UnitBehavior<PeriodicActionParameters> & Record<T, (this: this, unit: Unit, ...args: Args) => unknown>, event: Event<[Unit, ...Args]>, range: number, listener: T): void;
|
|
19
|
+
onImmediateOrder(orderId: number): void;
|
|
20
|
+
onTargetOrder(orderId: number, target: Widget): void;
|
|
21
|
+
onPointOrder(orderId: number, x: number, y: number): void;
|
|
14
22
|
onAutoAttackStart(target: Unit): void;
|
|
15
23
|
onAutoAttackFinish(target: Unit): void;
|
|
24
|
+
onTargetingAutoAttackStart(source: Unit): void;
|
|
25
|
+
onTargetingAutoAttackFinish(source: Unit): void;
|
|
16
26
|
onDamageDealing(target: Unit, event: DamagingEvent): void;
|
|
17
27
|
onDamageDealt(target: Unit, event: DamageEvent): void;
|
|
18
28
|
onDamageReceiving(source: Unit | undefined, event: DamagingEvent): void;
|
|
19
29
|
onDamageReceived(source: Unit | undefined, event: DamageEvent): void;
|
|
20
30
|
onAbilityGained(ability: Ability): void;
|
|
21
31
|
onAbilityLost(ability: Ability): void;
|
|
32
|
+
onAbilityChannelingStart(ability: Ability): void;
|
|
33
|
+
onAbilityImpact(ability: Ability): void;
|
|
34
|
+
onAbilityChannelingFinish(ability: Ability): void;
|
|
35
|
+
onAbilityStop(ability: Ability): void;
|
|
22
36
|
onItemDropped(item: Item): void;
|
|
23
37
|
onItemPickedUp(item: Item): void;
|
|
24
38
|
onItemUsed(item: Item): void;
|
|
25
39
|
onItemStacked(item: Item): void;
|
|
40
|
+
onItemChargesChanged(item: Item): void;
|
|
26
41
|
onKill(target: Unit): void;
|
|
27
42
|
onDeath(source: Unit | undefined): void;
|
|
28
43
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
local ____lualib = require("lualib_bundle")
|
|
2
2
|
local __TS__Class = ____lualib.__TS__Class
|
|
3
3
|
local __TS__ClassExtends = ____lualib.__TS__ClassExtends
|
|
4
|
+
local __TS__New = ____lualib.__TS__New
|
|
4
5
|
local __TS__SetDescriptor = ____lualib.__TS__SetDescriptor
|
|
5
6
|
local ____exports = {}
|
|
6
7
|
local ____behavior = require("engine.behavior")
|
|
@@ -9,6 +10,17 @@ local ____unit = require("engine.internal.unit")
|
|
|
9
10
|
local Unit = ____unit.Unit
|
|
10
11
|
require("engine.internal.unit+ability")
|
|
11
12
|
require("engine.internal.unit-missile-launch")
|
|
13
|
+
local ____linked_2Dset = require("utility.linked-set")
|
|
14
|
+
local LinkedSet = ____linked_2Dset.LinkedSet
|
|
15
|
+
local ____lua_2Dmaps = require("utility.lua-maps")
|
|
16
|
+
local getOrPut = ____lua_2Dmaps.getOrPut
|
|
17
|
+
local mutableLuaMap = ____lua_2Dmaps.mutableLuaMap
|
|
18
|
+
local ____lua_2Dsets = require("utility.lua-sets")
|
|
19
|
+
local mutableLuaSet = ____lua_2Dsets.mutableLuaSet
|
|
20
|
+
local behaviorsByEvent = {}
|
|
21
|
+
local rangeByBehaviorByEvent = {}
|
|
22
|
+
local listenerByBehaviorByEvent = {}
|
|
23
|
+
local eventsByBehavior = {}
|
|
12
24
|
____exports.UnitBehavior = __TS__Class()
|
|
13
25
|
local UnitBehavior = ____exports.UnitBehavior
|
|
14
26
|
UnitBehavior.name = "UnitBehavior"
|
|
@@ -16,10 +28,66 @@ __TS__ClassExtends(UnitBehavior, Behavior)
|
|
|
16
28
|
function UnitBehavior.prototype.____constructor(self, unit)
|
|
17
29
|
Behavior.prototype.____constructor(self, unit)
|
|
18
30
|
end
|
|
31
|
+
function UnitBehavior.prototype.onDestroy(self)
|
|
32
|
+
local events = eventsByBehavior[self]
|
|
33
|
+
if events ~= nil then
|
|
34
|
+
for event in pairs(events) do
|
|
35
|
+
local ____opt_0 = behaviorsByEvent[event]
|
|
36
|
+
if ____opt_0 ~= nil then
|
|
37
|
+
____opt_0:remove(self)
|
|
38
|
+
end
|
|
39
|
+
local ____opt_2 = rangeByBehaviorByEvent[event]
|
|
40
|
+
if ____opt_2 ~= nil then
|
|
41
|
+
____opt_2[self] = nil
|
|
42
|
+
end
|
|
43
|
+
local ____opt_4 = listenerByBehaviorByEvent[event]
|
|
44
|
+
if ____opt_4 ~= nil then
|
|
45
|
+
____opt_4[self] = nil
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
eventsByBehavior[self] = nil
|
|
49
|
+
end
|
|
50
|
+
return Behavior.prototype.onDestroy(self)
|
|
51
|
+
end
|
|
52
|
+
function UnitBehavior.prototype.registerInRangeUnitEvent(self, event, range, listener)
|
|
53
|
+
local rangeByBehavior = getOrPut(rangeByBehaviorByEvent, event, mutableLuaMap)
|
|
54
|
+
rangeByBehavior[self] = range
|
|
55
|
+
local listenerByBehavior = getOrPut(listenerByBehaviorByEvent, event, mutableLuaMap)
|
|
56
|
+
listenerByBehavior[self] = listener
|
|
57
|
+
getOrPut(eventsByBehavior, self, mutableLuaSet)[event] = true
|
|
58
|
+
local behaviors = behaviorsByEvent[event]
|
|
59
|
+
if behaviors == nil then
|
|
60
|
+
event:addListener(function(unit, ...)
|
|
61
|
+
local behaviors = behaviorsByEvent[event]
|
|
62
|
+
if behaviors ~= nil then
|
|
63
|
+
for behavior in pairs(behaviors) do
|
|
64
|
+
local range = rangeByBehavior[behavior]
|
|
65
|
+
if range ~= nil and unit:getCollisionDistanceTo(behavior.unit) <= range then
|
|
66
|
+
local ____self_6 = behavior
|
|
67
|
+
____self_6[listenerByBehavior[behavior]](____self_6, unit, ...)
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end)
|
|
72
|
+
behaviors = __TS__New(LinkedSet)
|
|
73
|
+
behaviorsByEvent[event] = behaviors
|
|
74
|
+
end
|
|
75
|
+
behaviors:add(self)
|
|
76
|
+
end
|
|
77
|
+
function UnitBehavior.prototype.onImmediateOrder(self, orderId)
|
|
78
|
+
end
|
|
79
|
+
function UnitBehavior.prototype.onTargetOrder(self, orderId, target)
|
|
80
|
+
end
|
|
81
|
+
function UnitBehavior.prototype.onPointOrder(self, orderId, x, y)
|
|
82
|
+
end
|
|
19
83
|
function UnitBehavior.prototype.onAutoAttackStart(self, target)
|
|
20
84
|
end
|
|
21
85
|
function UnitBehavior.prototype.onAutoAttackFinish(self, target)
|
|
22
86
|
end
|
|
87
|
+
function UnitBehavior.prototype.onTargetingAutoAttackStart(self, source)
|
|
88
|
+
end
|
|
89
|
+
function UnitBehavior.prototype.onTargetingAutoAttackFinish(self, source)
|
|
90
|
+
end
|
|
23
91
|
function UnitBehavior.prototype.onDamageDealing(self, target, event)
|
|
24
92
|
end
|
|
25
93
|
function UnitBehavior.prototype.onDamageDealt(self, target, event)
|
|
@@ -32,6 +100,14 @@ function UnitBehavior.prototype.onAbilityGained(self, ability)
|
|
|
32
100
|
end
|
|
33
101
|
function UnitBehavior.prototype.onAbilityLost(self, ability)
|
|
34
102
|
end
|
|
103
|
+
function UnitBehavior.prototype.onAbilityChannelingStart(self, ability)
|
|
104
|
+
end
|
|
105
|
+
function UnitBehavior.prototype.onAbilityImpact(self, ability)
|
|
106
|
+
end
|
|
107
|
+
function UnitBehavior.prototype.onAbilityChannelingFinish(self, ability)
|
|
108
|
+
end
|
|
109
|
+
function UnitBehavior.prototype.onAbilityStop(self, ability)
|
|
110
|
+
end
|
|
35
111
|
function UnitBehavior.prototype.onItemDropped(self, item)
|
|
36
112
|
end
|
|
37
113
|
function UnitBehavior.prototype.onItemPickedUp(self, item)
|
|
@@ -40,6 +116,8 @@ function UnitBehavior.prototype.onItemUsed(self, item)
|
|
|
40
116
|
end
|
|
41
117
|
function UnitBehavior.prototype.onItemStacked(self, item)
|
|
42
118
|
end
|
|
119
|
+
function UnitBehavior.prototype.onItemChargesChanged(self, item)
|
|
120
|
+
end
|
|
43
121
|
function UnitBehavior.prototype.onKill(self, target)
|
|
44
122
|
end
|
|
45
123
|
function UnitBehavior.prototype.onDeath(self, source)
|
|
@@ -53,11 +131,28 @@ __TS__SetDescriptor(
|
|
|
53
131
|
true
|
|
54
132
|
);
|
|
55
133
|
(function(self)
|
|
134
|
+
Unit.onImmediateOrder:addListener(function(source, orderId)
|
|
135
|
+
____exports.UnitBehavior:forAll(source, "onImmediateOrder", orderId)
|
|
136
|
+
end)
|
|
137
|
+
Unit.onTargetOrder:addListener(function(source, orderId, target)
|
|
138
|
+
____exports.UnitBehavior:forAll(source, "onTargetOrder", orderId, target)
|
|
139
|
+
end)
|
|
140
|
+
Unit.onPointOrder:addListener(function(source, orderId, x, y)
|
|
141
|
+
____exports.UnitBehavior:forAll(
|
|
142
|
+
source,
|
|
143
|
+
"onPointOrder",
|
|
144
|
+
orderId,
|
|
145
|
+
x,
|
|
146
|
+
y
|
|
147
|
+
)
|
|
148
|
+
end)
|
|
56
149
|
Unit.autoAttackStartEvent:addListener(function(source, target)
|
|
57
150
|
____exports.UnitBehavior:forAll(source, "onAutoAttackStart", target)
|
|
151
|
+
____exports.UnitBehavior:forAll(target, "onTargetingAutoAttackStart", source)
|
|
58
152
|
end)
|
|
59
153
|
Unit.autoAttackFinishEvent:addListener(function(source, target)
|
|
60
154
|
____exports.UnitBehavior:forAll(source, "onAutoAttackFinish", target)
|
|
155
|
+
____exports.UnitBehavior:forAll(target, "onTargetingAutoAttackFinish", source)
|
|
61
156
|
end)
|
|
62
157
|
Unit.onDamaging:addListener(function(source, target, event)
|
|
63
158
|
if source ~= nil then
|
|
@@ -71,11 +166,23 @@ __TS__SetDescriptor(
|
|
|
71
166
|
end
|
|
72
167
|
____exports.UnitBehavior:forAll(target, "onDamageReceived", source, event)
|
|
73
168
|
end)
|
|
74
|
-
Unit.abilityGainedEvent:addListener(function(source,
|
|
75
|
-
____exports.UnitBehavior:forAll(source, "onAbilityGained",
|
|
169
|
+
Unit.abilityGainedEvent:addListener(function(source, ability)
|
|
170
|
+
____exports.UnitBehavior:forAll(source, "onAbilityGained", ability)
|
|
76
171
|
end)
|
|
77
|
-
Unit.abilityLostEvent:addListener(function(source,
|
|
78
|
-
____exports.UnitBehavior:forAll(source, "onAbilityLost",
|
|
172
|
+
Unit.abilityLostEvent:addListener(function(source, ability)
|
|
173
|
+
____exports.UnitBehavior:forAll(source, "onAbilityLost", ability)
|
|
174
|
+
end)
|
|
175
|
+
Unit.abilityChannelingStartEvent:addListener(function(source, ability)
|
|
176
|
+
____exports.UnitBehavior:forAll(source, "onAbilityChannelingStart", ability)
|
|
177
|
+
end)
|
|
178
|
+
Unit.abilityImpactEvent:addListener(function(source, ability)
|
|
179
|
+
____exports.UnitBehavior:forAll(source, "onAbilityImpact", ability)
|
|
180
|
+
end)
|
|
181
|
+
Unit.abilityChannelingFinishEvent:addListener(function(source, ability)
|
|
182
|
+
____exports.UnitBehavior:forAll(source, "onAbilityChannelingFinish", ability)
|
|
183
|
+
end)
|
|
184
|
+
Unit.abilityStopEvent:addListener(function(source, ability)
|
|
185
|
+
____exports.UnitBehavior:forAll(source, "onAbilityStop", ability)
|
|
79
186
|
end)
|
|
80
187
|
Unit.deathEvent:addListener(function(target, source)
|
|
81
188
|
if source ~= nil then
|
|
@@ -95,6 +202,9 @@ __TS__SetDescriptor(
|
|
|
95
202
|
Unit.itemStackedEvent:addListener(function(unit, item)
|
|
96
203
|
____exports.UnitBehavior:forAll(unit, "onItemStacked", item)
|
|
97
204
|
end)
|
|
205
|
+
Unit.itemChargesChangedEvent:addListener(function(unit, item)
|
|
206
|
+
____exports.UnitBehavior:forAll(unit, "onItemChargesChanged", item)
|
|
207
|
+
end)
|
|
98
208
|
end)(UnitBehavior)
|
|
99
209
|
Unit.destroyEvent:addListener(function(unit)
|
|
100
210
|
____exports.UnitBehavior:forAll(unit, "destroy")
|
|
@@ -55,9 +55,13 @@ export declare class UnrecognizedAbility extends Ability {
|
|
|
55
55
|
export declare class UnitAbility extends Ability {
|
|
56
56
|
readonly owner: Unit;
|
|
57
57
|
private readonly u;
|
|
58
|
+
private d?;
|
|
58
59
|
constructor(handle: jability, typeId: number, owner: Unit);
|
|
59
60
|
incrementHideCounter(): void;
|
|
60
61
|
decrementHideCounter(): void;
|
|
62
|
+
incrementDisableCounter(): void;
|
|
63
|
+
decrementDisableCounter(): void;
|
|
64
|
+
get isDisabled(): boolean;
|
|
61
65
|
get level(): number;
|
|
62
66
|
set level(v: number);
|
|
63
67
|
get cooldownRemaining(): number;
|
|
@@ -38,6 +38,7 @@ local getHandleId = GetHandleId
|
|
|
38
38
|
local getItemBooleanField = BlzGetItemBooleanField
|
|
39
39
|
local setItemBooleanField = BlzSetItemBooleanField
|
|
40
40
|
local unitHideAbility = BlzUnitHideAbility
|
|
41
|
+
local unitDisableAbility = BlzUnitDisableAbility
|
|
41
42
|
local match = string.match
|
|
42
43
|
local ____type = _G.type
|
|
43
44
|
local ____tostring = _G.tostring
|
|
@@ -402,9 +403,25 @@ end
|
|
|
402
403
|
function UnitAbility.prototype.decrementHideCounter(self)
|
|
403
404
|
unitHideAbility(self.u, self.typeId, false)
|
|
404
405
|
end
|
|
406
|
+
function UnitAbility.prototype.incrementDisableCounter(self)
|
|
407
|
+
unitDisableAbility(self.u, self.typeId, true, false)
|
|
408
|
+
self.d = (self.d or 0) + 1
|
|
409
|
+
end
|
|
410
|
+
function UnitAbility.prototype.decrementDisableCounter(self)
|
|
411
|
+
unitDisableAbility(self.u, self.typeId, false, false)
|
|
412
|
+
self.d = (self.d or 0) - 1
|
|
413
|
+
end
|
|
405
414
|
function UnitAbility.prototype.interruptCast(self)
|
|
406
415
|
self.owner:interruptCast(self.typeId)
|
|
407
416
|
end
|
|
417
|
+
__TS__SetDescriptor(
|
|
418
|
+
UnitAbility.prototype,
|
|
419
|
+
"isDisabled",
|
|
420
|
+
{get = function(self)
|
|
421
|
+
return self.d ~= nil and self.d > 0
|
|
422
|
+
end},
|
|
423
|
+
true
|
|
424
|
+
)
|
|
408
425
|
__TS__SetDescriptor(
|
|
409
426
|
UnitAbility.prototype,
|
|
410
427
|
"level",
|
|
@@ -55,22 +55,24 @@ local COOLDOWN_STARTER_ITEM_TYPE_ID = compiletime(function()
|
|
|
55
55
|
itemType.activelyUsed = true
|
|
56
56
|
return itemType.id
|
|
57
57
|
end)
|
|
58
|
-
|
|
58
|
+
---
|
|
59
|
+
-- @internal For use by internal systems only.
|
|
60
|
+
____exports.itemAbilityDummy = assert(CreateUnit(
|
|
59
61
|
Player.neutralVictim.handle,
|
|
60
62
|
dummyUnitId,
|
|
61
63
|
0,
|
|
62
64
|
0,
|
|
63
65
|
270
|
|
64
66
|
))
|
|
65
|
-
local cooldownStarterItem = UnitAddItemById(
|
|
67
|
+
local cooldownStarterItem = UnitAddItemById(____exports.itemAbilityDummy, COOLDOWN_STARTER_ITEM_TYPE_ID)
|
|
66
68
|
local cooldownStarterAbility = BlzGetItemAbility(cooldownStarterItem, COOLDOWN_STARTER_ABILITY_TYPE_ID)
|
|
67
|
-
ShowUnit(
|
|
69
|
+
ShowUnit(____exports.itemAbilityDummy, false)
|
|
68
70
|
local function startItemCooldownInternal(handle, cooldown)
|
|
69
71
|
local cooldownGroup = getItemIntegerField(handle, ITEM_IF_COOLDOWN_GROUP)
|
|
70
72
|
setItemIntegerField(handle, ITEM_IF_COOLDOWN_GROUP, COOLDOWN_STARTER_ABILITY_TYPE_ID)
|
|
71
73
|
setAbilityRealLevelField(cooldownStarterAbility, ABILITY_RLF_COOLDOWN, 0, cooldown)
|
|
72
|
-
unitResetCooldown(
|
|
73
|
-
unitUseItem(
|
|
74
|
+
unitResetCooldown(____exports.itemAbilityDummy)
|
|
75
|
+
unitUseItem(____exports.itemAbilityDummy, cooldownStarterItem)
|
|
74
76
|
Timer:run(restoreCooldownGroup, handle, cooldownGroup)
|
|
75
77
|
end
|
|
76
78
|
restoreCooldownGroup = function(handle, cooldownGroup)
|
|
@@ -85,7 +87,7 @@ ____exports.startItemCooldown = function(handle, owner, cooldown)
|
|
|
85
87
|
end
|
|
86
88
|
---
|
|
87
89
|
-- @internal For use by internal systems only.
|
|
88
|
-
____exports.abilityActionDummy =
|
|
90
|
+
____exports.abilityActionDummy = ____exports.itemAbilityDummy
|
|
89
91
|
---
|
|
90
92
|
-- @internal For use by internal systems only.
|
|
91
93
|
____exports.doAbilityAction = function(handle, action, ...)
|
|
@@ -104,11 +106,11 @@ ____exports.doAbilityAction = function(handle, action, ...)
|
|
|
104
106
|
end
|
|
105
107
|
x = getItemX(handle)
|
|
106
108
|
y = getItemY(handle)
|
|
107
|
-
unitAddItem(
|
|
109
|
+
unitAddItem(____exports.itemAbilityDummy, handle)
|
|
108
110
|
end
|
|
109
111
|
local result = action(handle, ...)
|
|
110
112
|
if not isOwned then
|
|
111
|
-
unitRemoveItem(
|
|
113
|
+
unitRemoveItem(____exports.itemAbilityDummy, handle)
|
|
112
114
|
setItemPosition(handle, x, y)
|
|
113
115
|
if isPowerup then
|
|
114
116
|
setItemBooleanField(handle, ITEM_BF_USE_AUTOMATICALLY_WHEN_ACQUIRED, true)
|
|
@@ -139,9 +141,9 @@ ____exports.doAbilityActionForceDummy = function(handle, owner, action, ...)
|
|
|
139
141
|
isPowerup = true
|
|
140
142
|
end
|
|
141
143
|
unitRemoveItem(owner, handle)
|
|
142
|
-
unitAddItem(
|
|
144
|
+
unitAddItem(____exports.itemAbilityDummy, handle)
|
|
143
145
|
local result = action(handle, ...)
|
|
144
|
-
unitRemoveItem(
|
|
146
|
+
unitRemoveItem(____exports.itemAbilityDummy, handle)
|
|
145
147
|
unitAddItemToSlot(owner, handle, slot)
|
|
146
148
|
if isPowerup then
|
|
147
149
|
setItemBooleanField(handle, ITEM_BF_USE_AUTOMATICALLY_WHEN_ACQUIRED, true)
|
|
@@ -7,7 +7,6 @@ import { ItemAbility } from "./ability";
|
|
|
7
7
|
import { AbilityTypeId } from "../object-data/entry/ability-type";
|
|
8
8
|
import type { ItemTypeId } from "../object-data/entry/item-type";
|
|
9
9
|
type DefenseType = 0 | 1 | 2 | 3 | 4 | 5;
|
|
10
|
-
export declare const addAndGetAbility: (handle: jitem, abilityTypeId: AbilityTypeId) => jability | null;
|
|
11
10
|
declare const enum ItemPropertyKey {
|
|
12
11
|
ABILITIES = 100,
|
|
13
12
|
LUA_INDEX_BY_ABILITY_TYPE_ID = 101
|
|
@@ -74,6 +73,8 @@ export declare class Item extends Handle<jitem> {
|
|
|
74
73
|
set position(v: Vec2);
|
|
75
74
|
set charges(v: number);
|
|
76
75
|
get charges(): number;
|
|
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;
|
|
@@ -83,5 +84,6 @@ export declare class Item extends Handle<jitem> {
|
|
|
83
84
|
static getInRect(rect: ReadonlyRect): Item[];
|
|
84
85
|
static get onCreate(): Event<[Item]>;
|
|
85
86
|
static get destroyEvent(): Event<[Item]>;
|
|
87
|
+
static readonly chargesChangedEvent: Event<[Item]>;
|
|
86
88
|
}
|
|
87
89
|
export {};
|
package/engine/internal/item.lua
CHANGED
|
@@ -1,26 +1,33 @@
|
|
|
1
1
|
local ____lualib = require("lualib_bundle")
|
|
2
|
+
local __TS__New = ____lualib.__TS__New
|
|
2
3
|
local __TS__Class = ____lualib.__TS__Class
|
|
3
4
|
local __TS__ClassExtends = ____lualib.__TS__ClassExtends
|
|
4
5
|
local __TS__SetDescriptor = ____lualib.__TS__SetDescriptor
|
|
5
6
|
local __TS__ObjectDefineProperty = ____lualib.__TS__ObjectDefineProperty
|
|
6
7
|
local __TS__Delete = ____lualib.__TS__Delete
|
|
7
8
|
local ____exports = {}
|
|
9
|
+
local invoke
|
|
8
10
|
local ____handle = require("core.types.handle")
|
|
9
11
|
local Handle = ____handle.Handle
|
|
10
12
|
local ____color = require("core.types.color")
|
|
11
13
|
local Color = ____color.Color
|
|
14
|
+
local ____event = require("event")
|
|
15
|
+
local Event = ____event.Event
|
|
12
16
|
local ____rect = require("core.types.rect")
|
|
13
17
|
local Rect = ____rect.Rect
|
|
14
18
|
local ____ability = require("engine.internal.ability")
|
|
15
19
|
local ItemAbility = ____ability.ItemAbility
|
|
16
20
|
local ____ability = require("engine.internal.item.ability")
|
|
17
21
|
local doAbilityAction = ____ability.doAbilityAction
|
|
22
|
+
local doAbilityActionForceDummy = ____ability.doAbilityActionForceDummy
|
|
23
|
+
local itemAbilityDummy = ____ability.itemAbilityDummy
|
|
18
24
|
local ____dummy_2Ditem = require("engine.internal.object-data.dummy-item")
|
|
19
25
|
local DUMMY_ITEM_ID = ____dummy_2Ditem.DUMMY_ITEM_ID
|
|
20
26
|
local ____add_2Ditem_2Dto_2Dslot = require("engine.internal.unit.add-item-to-slot")
|
|
21
27
|
local SLOT_FILLER_ITEM_TYPE_ID = ____add_2Ditem_2Dto_2Dslot.SLOT_FILLER_ITEM_TYPE_ID
|
|
22
28
|
local ____vec2 = require("math.vec2")
|
|
23
29
|
local distance = ____vec2.distance
|
|
30
|
+
local itemChargesChangeEvent = __TS__New(Event)
|
|
24
31
|
local itemAddAbility = BlzItemAddAbility
|
|
25
32
|
local itemRemoveAbility = BlzItemRemoveAbility
|
|
26
33
|
local getItemAbility = BlzGetItemAbility
|
|
@@ -36,10 +43,26 @@ local getEnumItem = GetEnumItem
|
|
|
36
43
|
local getItemTypeId = GetItemTypeId
|
|
37
44
|
local getItemX = GetItemX
|
|
38
45
|
local getItemY = GetItemY
|
|
46
|
+
local getItemCharges = GetItemCharges
|
|
47
|
+
local setItemCharges = SetItemCharges
|
|
48
|
+
local unitRemoveAbility = UnitRemoveAbility
|
|
49
|
+
local unitUseItem = UnitUseItem
|
|
50
|
+
local unitUseItemPoint = UnitUseItemPoint
|
|
51
|
+
local unitUseItemTarget = UnitUseItemTarget
|
|
52
|
+
_G.SetItemCharges = function(whichItem, charges)
|
|
53
|
+
setItemCharges(whichItem, charges)
|
|
54
|
+
invoke(
|
|
55
|
+
itemChargesChangeEvent,
|
|
56
|
+
____exports.Item:of(whichItem)
|
|
57
|
+
)
|
|
58
|
+
end
|
|
39
59
|
local getItemIntegerField = BlzGetItemIntegerField
|
|
40
60
|
local setItemBooleanField = BlzSetItemBooleanField
|
|
41
61
|
local getItemBooleanField = BlzGetItemBooleanField
|
|
62
|
+
invoke = Event.invoke
|
|
42
63
|
local enumRect = Rect:create(0, 0, 0, 0).handle
|
|
64
|
+
---
|
|
65
|
+
-- @internal For use by internal systems only.
|
|
43
66
|
____exports.addAndGetAbility = function(handle, abilityTypeId)
|
|
44
67
|
if itemAddAbility(handle, abilityTypeId) then
|
|
45
68
|
return getItemAbility(handle, abilityTypeId)
|
|
@@ -65,6 +88,23 @@ local function getItemAbilities(handle, item)
|
|
|
65
88
|
end
|
|
66
89
|
return abilities
|
|
67
90
|
end
|
|
91
|
+
local function consumeCharge(handle)
|
|
92
|
+
do
|
|
93
|
+
local i = 0
|
|
94
|
+
local ability = getItemAbilityByIndex(handle, i)
|
|
95
|
+
while ability ~= nil do
|
|
96
|
+
unitRemoveAbility(
|
|
97
|
+
itemAbilityDummy,
|
|
98
|
+
getAbilityId(ability)
|
|
99
|
+
)
|
|
100
|
+
do
|
|
101
|
+
i = i + 1
|
|
102
|
+
ability = getItemAbilityByIndex(handle, i)
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
return unitUseItem(itemAbilityDummy, handle) or unitUseItemPoint(itemAbilityDummy, handle, 0, 0) or unitUseItemTarget(itemAbilityDummy, handle, itemAbilityDummy)
|
|
107
|
+
end
|
|
68
108
|
local targetCollection
|
|
69
109
|
local targetCollectionNextIndex
|
|
70
110
|
local centerX
|
|
@@ -116,6 +156,36 @@ end
|
|
|
116
156
|
function Item.create(self, id, x, y, skinId)
|
|
117
157
|
return self:of(BlzCreateItemWithSkin(id, x, y, skinId or id))
|
|
118
158
|
end
|
|
159
|
+
function Item.prototype.consumeCharge(self)
|
|
160
|
+
return self:consumeCharges(1)
|
|
161
|
+
end
|
|
162
|
+
function Item.prototype.consumeCharges(self, count)
|
|
163
|
+
local handle = self.handle
|
|
164
|
+
local charges = getItemCharges(handle)
|
|
165
|
+
if charges > count then
|
|
166
|
+
setItemCharges(handle, charges - count)
|
|
167
|
+
invoke(itemChargesChangeEvent, self)
|
|
168
|
+
return true
|
|
169
|
+
end
|
|
170
|
+
if charges == count then
|
|
171
|
+
if getItemBooleanField(handle, ITEM_BF_PERISHABLE) then
|
|
172
|
+
self:destroy()
|
|
173
|
+
return true
|
|
174
|
+
end
|
|
175
|
+
if not getItemBooleanField(handle, ITEM_BF_ACTIVELY_USED) then
|
|
176
|
+
setItemCharges(handle, 0)
|
|
177
|
+
invoke(itemChargesChangeEvent, self)
|
|
178
|
+
return true
|
|
179
|
+
end
|
|
180
|
+
setItemCharges(handle, 1)
|
|
181
|
+
local ____doAbilityActionForceDummy_2 = doAbilityActionForceDummy
|
|
182
|
+
local ____opt_0 = self.owner
|
|
183
|
+
____doAbilityActionForceDummy_2(handle, ____opt_0 and ____opt_0.handle, consumeCharge)
|
|
184
|
+
invoke(itemChargesChangeEvent, self)
|
|
185
|
+
return true
|
|
186
|
+
end
|
|
187
|
+
return false
|
|
188
|
+
end
|
|
119
189
|
function Item.prototype.addAbility(self, abilityTypeId)
|
|
120
190
|
local nativeAbility = doAbilityAction(self.handle, ____exports.addAndGetAbility, abilityTypeId)
|
|
121
191
|
if nativeAbility ~= nil then
|
|
@@ -301,7 +371,7 @@ __TS__SetDescriptor(
|
|
|
301
371
|
"perishable",
|
|
302
372
|
{
|
|
303
373
|
get = function(self)
|
|
304
|
-
return
|
|
374
|
+
return getItemBooleanField(self.handle, ITEM_BF_PERISHABLE)
|
|
305
375
|
end,
|
|
306
376
|
set = function(self, v)
|
|
307
377
|
BlzSetItemBooleanField(self.handle, ITEM_BF_PERISHABLE, v)
|
|
@@ -557,10 +627,11 @@ __TS__SetDescriptor(
|
|
|
557
627
|
"charges",
|
|
558
628
|
{
|
|
559
629
|
get = function(self)
|
|
560
|
-
return
|
|
630
|
+
return getItemCharges(self.handle)
|
|
561
631
|
end,
|
|
562
632
|
set = function(self, v)
|
|
563
|
-
|
|
633
|
+
setItemCharges(self.handle, v)
|
|
634
|
+
invoke(itemChargesChangeEvent, self)
|
|
564
635
|
end
|
|
565
636
|
},
|
|
566
637
|
true
|
|
@@ -587,6 +658,7 @@ __TS__ObjectDefineProperty(
|
|
|
587
658
|
return self.onDestroyEvent
|
|
588
659
|
end}
|
|
589
660
|
)
|
|
661
|
+
Item.chargesChangedEvent = itemChargesChangeEvent
|
|
590
662
|
local getManipulatedItem = GetManipulatedItem
|
|
591
663
|
local trigger = CreateTrigger()
|
|
592
664
|
TriggerRegisterAnyUnitEventBJ(trigger, EVENT_PLAYER_UNIT_PICKUP_ITEM)
|
|
@@ -131,6 +131,11 @@ 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
|
+
}
|
|
134
139
|
declare module "../unit" {
|
|
135
140
|
namespace Unit {
|
|
136
141
|
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,18 @@ 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
|
+
)
|
|
348
362
|
rawset(
|
|
349
363
|
Unit,
|
|
350
364
|
"abilityChannelingFinishEvent",
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { CombatClassifications } from "../../object-data/auxiliary/combat-classification";
|
|
3
3
|
declare module "../unit" {
|
|
4
4
|
interface Unit {
|
|
5
|
-
isAllowedTarget(this: Unit, source: Unit, allowedTargetCombatClassifications
|
|
5
|
+
isAllowedTarget(this: Unit, source: Unit, allowedTargetCombatClassifications?: CombatClassifications): boolean;
|
|
6
6
|
}
|
|
7
7
|
}
|
|
8
8
|
declare module "../unit" {
|
|
@@ -5,7 +5,15 @@ local initializeFilterTargetState = ____combat_2Dclassification.initializeFilter
|
|
|
5
5
|
local ____unit = require("engine.internal.unit")
|
|
6
6
|
local Unit = ____unit.Unit
|
|
7
7
|
Unit.prototype.isAllowedTarget = function(self, source, allowedTargetCombatClassifications)
|
|
8
|
-
|
|
8
|
+
if allowedTargetCombatClassifications ~= nil then
|
|
9
|
+
initializeFilterTargetState(source, allowedTargetCombatClassifications)
|
|
10
|
+
return filterTarget(self)
|
|
11
|
+
end
|
|
12
|
+
initializeFilterTargetState(source, source.firstWeapon.allowedTargetCombatClassifications)
|
|
13
|
+
if filterTarget(self) then
|
|
14
|
+
return true
|
|
15
|
+
end
|
|
16
|
+
initializeFilterTargetState(source, source.secondWeapon.allowedTargetCombatClassifications)
|
|
9
17
|
return filterTarget(self)
|
|
10
18
|
end
|
|
11
19
|
Unit.getAllowedTargetsInRange = function(source, allowedTargetCombatClassifications, x, y, range)
|
|
@@ -44,7 +44,7 @@ local function timerCallback(source, target)
|
|
|
44
44
|
Event.invoke(autoAttackFinishEvent, source, target)
|
|
45
45
|
end
|
|
46
46
|
Unit.autoAttackStartEvent:addListener(function(source, target)
|
|
47
|
-
local attackPoint = source.
|
|
47
|
+
local attackPoint = (source:chooseWeapon(target) or source.firstWeapon).impactDelay
|
|
48
48
|
local timer = Timer:simple(attackPoint, timerCallback, source, target)
|
|
49
49
|
eventTimerByUnit[source] = timer
|
|
50
50
|
end)
|
|
@@ -50,8 +50,9 @@ export interface DamagingEvent extends AttributesHolder {
|
|
|
50
50
|
readonly isAttack: boolean;
|
|
51
51
|
readonly originalAmount: number;
|
|
52
52
|
readonly originalMetadata: unknown;
|
|
53
|
+
preventRetaliation(this: DamagingEvent): void;
|
|
53
54
|
}
|
|
54
|
-
export type DamageEvent = DamagingEvent & {
|
|
55
|
+
export type DamageEvent = Omit<DamagingEvent, "preventRetaliation"> & {
|
|
55
56
|
preventDeath<P extends any[]>(this: DamageEvent, callback: (this: void, ...parameters: P) => any, ...parameters: P): void;
|
|
56
57
|
};
|
|
57
58
|
export type AttackDamageEvent = DamagingEvent & {
|
|
@@ -83,6 +84,8 @@ export declare class UnitWeapon {
|
|
|
83
84
|
set cooldown(cooldown: number);
|
|
84
85
|
get damage(): [minimumDamage: number, maximumDamage: number];
|
|
85
86
|
set damage([minimumDamage, maximumDamage]: [number, number]);
|
|
87
|
+
get allowedTargetCombatClassifications(): CombatClassifications;
|
|
88
|
+
set allowedTargetCombatClassifications(allowedTargetCombatClassifications: CombatClassifications);
|
|
86
89
|
get damageBase(): number;
|
|
87
90
|
set damageBase(damageBase: number);
|
|
88
91
|
get damageDiceCount(): number;
|
|
@@ -164,6 +167,7 @@ export declare class Unit extends Handle<junit> {
|
|
|
164
167
|
get weapons(): [UnitWeapon, UnitWeapon];
|
|
165
168
|
get firstWeapon(): UnitWeapon;
|
|
166
169
|
get secondWeapon(): UnitWeapon;
|
|
170
|
+
chooseWeapon(target: Unit): UnitWeapon | undefined;
|
|
167
171
|
get level(): number;
|
|
168
172
|
set level(v: number);
|
|
169
173
|
get xp(): number;
|
|
@@ -296,6 +300,7 @@ export declare class Unit extends Handle<junit> {
|
|
|
296
300
|
get onUnitInRange(): Record<number, Event<[Unit]>>;
|
|
297
301
|
get onManaEqual(): Record<number, Event<[Unit, number]>>;
|
|
298
302
|
get manaEvent(): Record<Operator, Record<number, Event<[Unit]>>>;
|
|
303
|
+
get targetAcquiredEvent(): Event;
|
|
299
304
|
get onSelect(): Event;
|
|
300
305
|
get onDeselect(): Event;
|
|
301
306
|
get onImmediateOrder(): Event<[number]>;
|
|
@@ -349,6 +354,7 @@ export declare class Unit extends Handle<junit> {
|
|
|
349
354
|
static itemPickedUpEvent: UnitTriggerEvent<[Item]>;
|
|
350
355
|
static itemUsedEvent: UnitTriggerEvent<[Item]>;
|
|
351
356
|
static itemStackedEvent: UnitTriggerEvent<[Item]>;
|
|
357
|
+
static get itemChargesChangedEvent(): Event<[unit: Unit, item: Item]>;
|
|
352
358
|
static get itemUseOrderEvent(): Event<[unit: Unit, item: Item]>;
|
|
353
359
|
static get itemMoveOrderEvent(): Event<[
|
|
354
360
|
unit: Unit,
|
package/engine/internal/unit.lua
CHANGED
|
@@ -347,6 +347,9 @@ local function dispatchAbility(event)
|
|
|
347
347
|
}
|
|
348
348
|
)
|
|
349
349
|
end
|
|
350
|
+
local function damagingEventPreventRetaliation(self)
|
|
351
|
+
self[0] = true
|
|
352
|
+
end
|
|
350
353
|
local function damageEventPreventDeath(self, callback, ...)
|
|
351
354
|
if self[0] ~= nil then
|
|
352
355
|
return
|
|
@@ -443,6 +446,19 @@ __TS__SetDescriptor(
|
|
|
443
446
|
},
|
|
444
447
|
true
|
|
445
448
|
)
|
|
449
|
+
__TS__SetDescriptor(
|
|
450
|
+
UnitWeapon.prototype,
|
|
451
|
+
"allowedTargetCombatClassifications",
|
|
452
|
+
{
|
|
453
|
+
get = function(self)
|
|
454
|
+
return BlzGetUnitWeaponIntegerField(self.unit.handle, UNIT_WEAPON_IF_ATTACK_TARGETS_ALLOWED, self.index)
|
|
455
|
+
end,
|
|
456
|
+
set = function(self, allowedTargetCombatClassifications)
|
|
457
|
+
BlzSetUnitWeaponIntegerField(self.unit.handle, UNIT_WEAPON_IF_ATTACK_TARGETS_ALLOWED, self.index, allowedTargetCombatClassifications)
|
|
458
|
+
end
|
|
459
|
+
},
|
|
460
|
+
true
|
|
461
|
+
)
|
|
446
462
|
__TS__SetDescriptor(
|
|
447
463
|
UnitWeapon.prototype,
|
|
448
464
|
"damageBase",
|
|
@@ -812,6 +828,15 @@ end
|
|
|
812
828
|
function Unit.prototype.queueAnimation(self, animation)
|
|
813
829
|
QueueUnitAnimation(self.handle, animation)
|
|
814
830
|
end
|
|
831
|
+
function Unit.prototype.chooseWeapon(self, target)
|
|
832
|
+
if target:isAllowedTarget(self, self.firstWeapon.allowedTargetCombatClassifications) then
|
|
833
|
+
return self.firstWeapon
|
|
834
|
+
end
|
|
835
|
+
if target:isAllowedTarget(target, self.secondWeapon.allowedTargetCombatClassifications) then
|
|
836
|
+
return self.secondWeapon
|
|
837
|
+
end
|
|
838
|
+
return nil
|
|
839
|
+
end
|
|
815
840
|
function Unit.prototype.delayHealthChecks(self)
|
|
816
841
|
self[103] = (self[103] or 0) + 1
|
|
817
842
|
Timer:run(delayHealthChecksCallback, self)
|
|
@@ -2048,6 +2073,14 @@ __TS__SetDescriptor(
|
|
|
2048
2073
|
end},
|
|
2049
2074
|
true
|
|
2050
2075
|
)
|
|
2076
|
+
__TS__SetDescriptor(
|
|
2077
|
+
Unit.prototype,
|
|
2078
|
+
"targetAcquiredEvent",
|
|
2079
|
+
{get = function(self)
|
|
2080
|
+
return self:getEvent(EVENT_UNIT_ACQUIRED_TARGET)
|
|
2081
|
+
end},
|
|
2082
|
+
true
|
|
2083
|
+
)
|
|
2051
2084
|
__TS__SetDescriptor(
|
|
2052
2085
|
Unit.prototype,
|
|
2053
2086
|
"onSelect",
|
|
@@ -2420,7 +2453,8 @@ Unit.onDamaging = (function()
|
|
|
2420
2453
|
metadata = metadata,
|
|
2421
2454
|
isAttack = BlzGetEventIsAttack(),
|
|
2422
2455
|
originalAmount = GetEventDamage(),
|
|
2423
|
-
originalMetadata = metadata
|
|
2456
|
+
originalMetadata = metadata,
|
|
2457
|
+
preventRetaliation = damagingEventPreventRetaliation
|
|
2424
2458
|
}
|
|
2425
2459
|
if data.isAttack and source then
|
|
2426
2460
|
local weapon = BlzGetUnitWeaponBooleanField(source.handle, UNIT_WEAPON_BF_ATTACKS_ENABLED, 1) and (BlzGetUnitWeaponBooleanField(source.handle, UNIT_WEAPON_BF_ATTACKS_ENABLED, 0) and -1 or 1) or 0
|
|
@@ -2449,6 +2483,20 @@ Unit.onDamaging = (function()
|
|
|
2449
2483
|
}
|
|
2450
2484
|
)
|
|
2451
2485
|
)
|
|
2486
|
+
if data[0] and source then
|
|
2487
|
+
local sourceOwner = source.owner.handle
|
|
2488
|
+
data[1] = sourceOwner
|
|
2489
|
+
local targetOwner = target.owner.handle
|
|
2490
|
+
data[2] = targetOwner
|
|
2491
|
+
if not GetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE) then
|
|
2492
|
+
SetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE, true)
|
|
2493
|
+
data[3] = true
|
|
2494
|
+
end
|
|
2495
|
+
if not GetPlayerAlliance(targetOwner, sourceOwner, ALLIANCE_PASSIVE) then
|
|
2496
|
+
SetPlayerAlliance(targetOwner, sourceOwner, ALLIANCE_PASSIVE, true)
|
|
2497
|
+
data[4] = true
|
|
2498
|
+
end
|
|
2499
|
+
end
|
|
2452
2500
|
damagingEventByTarget[target] = data
|
|
2453
2501
|
return
|
|
2454
2502
|
end
|
|
@@ -2532,6 +2580,16 @@ Unit.onDamage = __TS__New(
|
|
|
2532
2580
|
data[key] = value
|
|
2533
2581
|
end
|
|
2534
2582
|
end
|
|
2583
|
+
local sourceOwner = damagingEvent[1]
|
|
2584
|
+
if sourceOwner then
|
|
2585
|
+
local targetOwner = damagingEvent[2]
|
|
2586
|
+
if damagingEvent[3] then
|
|
2587
|
+
SetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE, false)
|
|
2588
|
+
end
|
|
2589
|
+
if damagingEvent[4] then
|
|
2590
|
+
SetPlayerAlliance(targetOwner, sourceOwner, ALLIANCE_PASSIVE, false)
|
|
2591
|
+
end
|
|
2592
|
+
end
|
|
2535
2593
|
end
|
|
2536
2594
|
local evData = setmetatable(
|
|
2537
2595
|
{},
|
|
@@ -2624,6 +2682,21 @@ Unit.itemStackedEvent = __TS__New(
|
|
|
2624
2682
|
EVENT_PLAYER_UNIT_STACK_ITEM,
|
|
2625
2683
|
function() return ____exports.Unit:of(getTriggerUnit()), Item:of(getManipulatedItem()) end
|
|
2626
2684
|
)
|
|
2685
|
+
__TS__ObjectDefineProperty(
|
|
2686
|
+
Unit,
|
|
2687
|
+
"itemChargesChangedEvent",
|
|
2688
|
+
{get = function(self)
|
|
2689
|
+
local event = __TS__New(Event)
|
|
2690
|
+
Item.chargesChangedEvent:addListener(function(item)
|
|
2691
|
+
local unit = item.owner
|
|
2692
|
+
if unit ~= nil then
|
|
2693
|
+
invoke(event, unit, item)
|
|
2694
|
+
end
|
|
2695
|
+
end)
|
|
2696
|
+
rawset(self, "itemChargesChangedEvent", event)
|
|
2697
|
+
return event
|
|
2698
|
+
end}
|
|
2699
|
+
)
|
|
2627
2700
|
__TS__ObjectDefineProperty(
|
|
2628
2701
|
Unit,
|
|
2629
2702
|
"itemUseOrderEvent",
|
package/engine/object-field.d.ts
CHANGED
|
@@ -5,9 +5,10 @@ import { ObjectDataEntry, ObjectDataEntryIdType, ObjectDataEntryLevelFieldValueS
|
|
|
5
5
|
export type ObjectFieldId = number & {
|
|
6
6
|
readonly __objectDataEntryFieldId: unique symbol;
|
|
7
7
|
};
|
|
8
|
-
export type ObjectFieldConstructor<T extends ObjectFieldBase<any, any, any, any>> = OmitConstructor<typeof ObjectFieldBase> & (new (id: number) => T);
|
|
8
|
+
export type ObjectFieldConstructor<T extends ObjectFieldBase<any, any, any, any>> = OmitConstructor<typeof ObjectFieldBase> & (new (id: number, isGlobal?: boolean) => T);
|
|
9
9
|
export type ObjectFieldAbstractConstructor<T extends ObjectFieldBase<any, any, any, any>> = OmitConstructor<typeof ObjectFieldBase> & (abstract new (id: number) => T);
|
|
10
10
|
declare abstract class ObjectFieldBase<ObjectDataEntryType extends ObjectDataEntry, InstanceType extends AnyNotNil, ValueType, NativeFieldType> {
|
|
11
|
+
readonly isGlobal: boolean;
|
|
11
12
|
protected abstract readonly instanceClass: AbstractConstructor<InstanceType> | Function;
|
|
12
13
|
supports(instance: AnyNotNil): instance is InstanceType & {
|
|
13
14
|
readonly __oneSidedTypeGuard: unique symbol;
|
|
@@ -18,8 +19,8 @@ declare abstract class ObjectFieldBase<ObjectDataEntryType extends ObjectDataEnt
|
|
|
18
19
|
protected abstract getObjectDataEntryId(instance: InstanceType): ObjectDataEntryIdType<ObjectDataEntryType>;
|
|
19
20
|
protected abstract hasNativeFieldValue(instance: InstanceType): boolean;
|
|
20
21
|
hasValue(instance: InstanceType): boolean;
|
|
21
|
-
constructor(id: number);
|
|
22
|
-
static create<T extends ObjectFieldBase<any, any, any, any>>(this: ObjectFieldConstructor<T>, id?: number): T & symbol;
|
|
22
|
+
constructor(id: number, isGlobal?: boolean);
|
|
23
|
+
static create<T extends ObjectFieldBase<any, any, any, any>>(this: ObjectFieldConstructor<T>, id?: number, isGlobal?: boolean): T & symbol;
|
|
23
24
|
static of<T extends ObjectFieldBase<any, any, any, any>>(this: ObjectFieldAbstractConstructor<T>, id: number): T | undefined;
|
|
24
25
|
}
|
|
25
26
|
export type ObjectFieldValueChangeEvent<T extends ObjectField<any, any, any, any> | ReadonlyObjectFieldType<ObjectField<any, any, any, any>>> = T extends ObjectField<any, infer InstanceType, infer ValueType, any> ? DispatchingEvent<[
|
package/engine/object-field.lua
CHANGED
|
@@ -34,7 +34,11 @@ local idGenerator = __TS__New(
|
|
|
34
34
|
)
|
|
35
35
|
local ObjectFieldBase = __TS__Class()
|
|
36
36
|
ObjectFieldBase.name = "ObjectFieldBase"
|
|
37
|
-
function ObjectFieldBase.prototype.____constructor(self, id)
|
|
37
|
+
function ObjectFieldBase.prototype.____constructor(self, id, isGlobal)
|
|
38
|
+
if isGlobal == nil then
|
|
39
|
+
isGlobal = true
|
|
40
|
+
end
|
|
41
|
+
self.isGlobal = isGlobal
|
|
38
42
|
self.valueByInstance = setmetatable({}, {__mode = "k"})
|
|
39
43
|
if objectFieldById[id] ~= nil then
|
|
40
44
|
error(
|
|
@@ -53,12 +57,13 @@ function ObjectFieldBase.prototype.supports(self, instance)
|
|
|
53
57
|
end
|
|
54
58
|
function ObjectFieldBase.prototype.hasValue(self, instance)
|
|
55
59
|
local defaultValueByObjectDataEntryId = defaultValueByObjectDataEntryIdByObjectFieldId[self.id]
|
|
56
|
-
return defaultValueByObjectDataEntryId ~= nil and defaultValueByObjectDataEntryId[self:getObjectDataEntryId(instance)] ~= nil or self:hasNativeFieldValue(instance)
|
|
60
|
+
return self.isGlobal or defaultValueByObjectDataEntryId ~= nil and defaultValueByObjectDataEntryId[self:getObjectDataEntryId(instance)] ~= nil or self:hasNativeFieldValue(instance)
|
|
57
61
|
end
|
|
58
|
-
function ObjectFieldBase.create(self, id)
|
|
62
|
+
function ObjectFieldBase.create(self, id, isGlobal)
|
|
59
63
|
return __TS__New(
|
|
60
64
|
self,
|
|
61
|
-
id or idGenerator:next()
|
|
65
|
+
id or idGenerator:next(),
|
|
66
|
+
isGlobal
|
|
62
67
|
)
|
|
63
68
|
end
|
|
64
69
|
function ObjectFieldBase.of(self, id)
|
|
@@ -205,7 +210,7 @@ function ObjectField.prototype.setActualValue(self, instance, value)
|
|
|
205
210
|
local defaultValueByObjectDataEntryId = defaultValueByObjectDataEntryIdByObjectFieldId[self.id]
|
|
206
211
|
if defaultValueByObjectDataEntryId ~= nil then
|
|
207
212
|
local defaultValue = defaultValueByObjectDataEntryId[self:getObjectDataEntryId(instance)]
|
|
208
|
-
if defaultValue ~= nil then
|
|
213
|
+
if defaultValue ~= nil or self.isGlobal then
|
|
209
214
|
local ____self_valueByInstance_instance_2 = self.valueByInstance[instance]
|
|
210
215
|
if ____self_valueByInstance_instance_2 == nil then
|
|
211
216
|
____self_valueByInstance_instance_2 = defaultValue
|
package/package.json
CHANGED