warscript 0.0.1-dev.dd8349d → 0.0.1-dev.e0e46c4

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.
Files changed (38) hide show
  1. package/core/types/timer.d.ts +1 -1
  2. package/engine/behaviour/ability/apply-buff.lua +1 -1
  3. package/engine/behaviour/ability/emulate-impact.lua +9 -2
  4. package/engine/behaviour/ability.lua +8 -17
  5. package/engine/behaviour/unit/stun-immunity.d.ts +5 -3
  6. package/engine/behaviour/unit/stun-immunity.lua +43 -27
  7. package/engine/behaviour/unit.d.ts +13 -1
  8. package/engine/behaviour/unit.lua +55 -3
  9. package/engine/buff.d.ts +2 -1
  10. package/engine/buff.lua +9 -3
  11. package/engine/internal/ability.d.ts +2 -0
  12. package/engine/internal/ability.lua +10 -0
  13. package/engine/internal/item/ability.lua +51 -1
  14. package/engine/internal/item.d.ts +1 -0
  15. package/engine/internal/item.lua +7 -3
  16. package/engine/internal/unit/ability.d.ts +35 -0
  17. package/engine/internal/unit/ability.lua +62 -0
  18. package/engine/internal/unit/order.d.ts +20 -0
  19. package/engine/internal/unit/order.lua +136 -0
  20. package/engine/internal/unit.d.ts +2 -1
  21. package/engine/internal/unit.lua +70 -57
  22. package/engine/object-field/unit.d.ts +4 -0
  23. package/engine/object-field/unit.lua +13 -0
  24. package/engine/object-field.d.ts +6 -3
  25. package/engine/object-field.lua +85 -73
  26. package/engine/standard/fields/unit.d.ts +3 -0
  27. package/engine/standard/fields/unit.lua +5 -0
  28. package/engine/text-tag.d.ts +36 -2
  29. package/engine/text-tag.lua +175 -10
  30. package/engine/unit.d.ts +1 -0
  31. package/engine/unit.lua +1 -0
  32. package/package.json +1 -1
  33. package/utility/functions.d.ts +3 -0
  34. package/utility/functions.lua +3 -0
  35. package/utility/lua-maps.d.ts +1 -0
  36. package/utility/lua-maps.lua +4 -0
  37. package/core/types/order.d.ts +0 -26
  38. package/core/types/order.lua +0 -65
@@ -22,7 +22,7 @@ export declare class Timer extends AbstractDestroyable {
22
22
  pause(): void;
23
23
  resume(): void;
24
24
  static create(): Timer;
25
- static run<Args extends any[]>(callback: (...args: Args) => void, ...args: Args): void;
25
+ static run<Args extends any[]>(callback: (this: void, ...args: Args) => void, ...args: Args): void;
26
26
  static simple<Args extends any[]>(timeout: number, callback: (...args: Args) => void, ...args: Args): Timer;
27
27
  static periodic<Args extends any[]>(period: number, callback: (this: void, timer: Timer, ...args: Args) => void, ...args: Args): Timer;
28
28
  static counted(period: number, count: number, callback: (this: void, timer: Timer) => void): Timer;
@@ -148,7 +148,7 @@ function ApplyBuffChannelingTargetAbilityBehavior.prototype.onStop(self)
148
148
  self.buff = nil
149
149
  end
150
150
  end
151
- Buff.destroyEvent:addListener(function(buff)
151
+ Buff.beingDestroyedEvent:addListener(function(buff)
152
152
  local behavior = behaviorByBuff[buff]
153
153
  if behavior ~= nil then
154
154
  behaviorByBuff[buff] = nil
@@ -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
- AbilityBehavior:forAll(self.ability, "onImpact", caster)
40
+ Event.invoke(Unit.abilityImpactEvent, caster, self.ability)
34
41
  end
35
42
  return ____exports
@@ -5,7 +5,6 @@ local __TS__InstanceOf = ____lualib.__TS__InstanceOf
5
5
  local __TS__New = ____lualib.__TS__New
6
6
  local __TS__SetDescriptor = ____lualib.__TS__SetDescriptor
7
7
  local ____exports = {}
8
- local createUnitEventListener
9
8
  local ____behavior = require("engine.behavior")
10
9
  local Behavior = ____behavior.Behavior
11
10
  local ____unit = require("engine.unit")
@@ -30,17 +29,9 @@ local ____ability = require("engine.object-field.ability")
30
29
  local AbilityField = ____ability.AbilityField
31
30
  local AbilityLevelField = ____ability.AbilityLevelField
32
31
  local resolveCurrentAbilityDependentValue = ____ability.resolveCurrentAbilityDependentValue
33
- local ____timer = require("core.types.timer")
34
- local Timer = ____timer.Timer
35
32
  local createBehaviorFunctionsByAbilityTypeId = {}
36
33
  local exclusiveOnImpactHandlerAbilityBehaviorByAbility = setmetatable({}, {__mode = "k"})
37
- local function createZeroTimerUnitEventListener(key)
38
- local unitEventListener = createUnitEventListener(key)
39
- return function(unit, ability, ...)
40
- Timer:run(unitEventListener, unit, ability, ...)
41
- end
42
- end
43
- createUnitEventListener = function(key)
34
+ local function createUnitEventListener(key)
44
35
  return function(unit, ability, ...)
45
36
  ____exports.AbilityBehavior:forAll(ability, key, unit, ...)
46
37
  end
@@ -274,13 +265,13 @@ __TS__SetDescriptor(
274
265
  Unit.abilityDestructibleTargetChannelingStartEvent:addListener(createUnitEventListener("onDestructibleTargetChannelingStart"))
275
266
  Unit.abilityPointTargetChannelingStartEvent:addListener(createUnitEventListener("onPointTargetChannelingStart"))
276
267
  Unit.abilityNoTargetChannelingStartEvent:addListener(createUnitEventListener("onNoTargetChannelingStart"))
277
- Unit.abilityChannelingStartEvent:addListener(createZeroTimerUnitEventListener("onImpact"))
278
- Unit.abilityWidgetTargetChannelingStartEvent:addListener(createZeroTimerUnitEventListener("onWidgetTargetImpact"))
279
- Unit.abilityUnitTargetChannelingStartEvent:addListener(createZeroTimerUnitEventListener("onUnitTargetImpact"))
280
- Unit.abilityItemTargetChannelingStartEvent:addListener(createZeroTimerUnitEventListener("onItemTargetImpact"))
281
- Unit.abilityDestructibleTargetChannelingStartEvent:addListener(createZeroTimerUnitEventListener("onDestructibleTargetImpact"))
282
- Unit.abilityPointTargetChannelingStartEvent:addListener(createZeroTimerUnitEventListener("onPointTargetImpact"))
283
- Unit.abilityNoTargetChannelingStartEvent:addListener(createZeroTimerUnitEventListener("onNoTargetImpact"))
268
+ Unit.abilityImpactEvent:addListener(createUnitEventListener("onImpact"))
269
+ Unit.abilityWidgetTargetImpactEvent:addListener(createUnitEventListener("onWidgetTargetImpact"))
270
+ Unit.abilityUnitTargetImpactEvent:addListener(createUnitEventListener("onUnitTargetImpact"))
271
+ Unit.abilityItemTargetImpactEvent:addListener(createUnitEventListener("onItemTargetImpact"))
272
+ Unit.abilityDestructibleTargetImpactEvent:addListener(createUnitEventListener("onDestructibleTargetImpact"))
273
+ Unit.abilityPointTargetImpactEvent:addListener(createUnitEventListener("onPointTargetImpact"))
274
+ Unit.abilityNoTargetImpactEvent:addListener(createUnitEventListener("onNoTargetImpact"))
284
275
  Unit.abilityChannelingFinishEvent:addListener(createUnitEventListener("onChannelingFinish"))
285
276
  Unit.abilityStopEvent:addListener(createUnitEventListener("onStop"))
286
277
  end)(AbilityBehavior)
@@ -10,9 +10,11 @@ export type StunImmunityUnitBehaviourParameters = {
10
10
  textTagText?: string;
11
11
  };
12
12
  export declare class StunImmunityUnitBehavior extends UnitBehavior {
13
- private readonly parameters;
13
+ readonly parameters: Readonly<StunImmunityUnitBehaviourParameters>;
14
14
  static defaultParameters: StunImmunityUnitBehaviourParameters;
15
- constructor(unit: Unit, parameters?: StunImmunityUnitBehaviourParameters);
15
+ constructor(unit: Unit, parameters?: Readonly<StunImmunityUnitBehaviourParameters>);
16
16
  protected onDestroy(): Destructor;
17
- private onBuffsCheck;
17
+ onDamageReceived(): void;
18
+ onTargetingAbilityChannelingStart(): void;
19
+ onTargetingAbilityImpact(): void;
18
20
  }
@@ -12,31 +12,46 @@ local flatMapToLuaSet = ____arrays.flatMapToLuaSet
12
12
  local map = ____arrays.map
13
13
  local ____text_2Dtag = require("engine.text-tag")
14
14
  local TextTag = ____text_2Dtag.TextTag
15
+ local ____timer = require("core.types.timer")
16
+ local Timer = ____timer.Timer
15
17
  local DEFAULT_BUFF_TYPE_IDS = postcompile(function()
16
18
  return flatMapToLuaSet(
17
19
  AbilityType:getAllByBaseIds(map({
18
- "Aslo",
19
- "AHtc",
20
- "Aens",
21
- "Aprg",
22
- "Apg2",
23
- "AOeq",
24
- "SNeq",
25
- "Aweb",
26
- "Afra",
27
- "Afrb",
28
- "Afrc",
29
- "Afr2",
30
- "Acri",
31
- "Scri",
32
- "AUfn",
33
- "Aspo",
34
- "AEer",
35
- "ACwb"
20
+ "AHtb",
21
+ "AHbh",
22
+ "AOws",
23
+ "AOw2",
24
+ "AUim",
25
+ "Acyc",
26
+ "ANfb",
27
+ "ANsb",
28
+ "ANcs",
29
+ "ANc1",
30
+ "ANc2",
31
+ "ANc3",
32
+ "ACbh",
33
+ "ANbh",
34
+ "SCc1",
35
+ "ACcy",
36
+ "ANb2",
37
+ "Awrs",
38
+ "Awrh",
39
+ "Awrg",
40
+ "ACtb",
41
+ "ACcb"
36
42
  }, fourCC)),
37
43
  function(abilityType) return __TS__ArrayFlat(abilityType.buffTypeIds) end
38
44
  )
39
45
  end)
46
+ local function process(behavior)
47
+ local hasRemovedBuffs = false
48
+ for buffTypeId in pairs(behavior.parameters.buffTypeIds or DEFAULT_BUFF_TYPE_IDS) do
49
+ hasRemovedBuffs = hasRemovedBuffs or behavior.unit:removeBuff(buffTypeId)
50
+ end
51
+ if hasRemovedBuffs and behavior.parameters.textTagText ~= nil then
52
+ TextTag:flash(TextTag.MISS, behavior.parameters.textTagText, behavior.unit.x, behavior.unit.y)
53
+ end
54
+ end
40
55
  ____exports.StunImmunityUnitBehavior = __TS__Class()
41
56
  local StunImmunityUnitBehavior = ____exports.StunImmunityUnitBehavior
42
57
  StunImmunityUnitBehavior.name = "StunImmunityUnitBehavior"
@@ -48,20 +63,21 @@ function StunImmunityUnitBehavior.prototype.____constructor(self, unit, paramete
48
63
  UnitBehavior.prototype.____constructor(self, unit)
49
64
  self.parameters = parameters
50
65
  unit:decrementStunCounter()
51
- self:onBuffsCheck()
66
+ process(self)
52
67
  end
53
68
  function StunImmunityUnitBehavior.prototype.onDestroy(self)
54
69
  self.unit:incrementStunCounter()
55
70
  return UnitBehavior.prototype.onDestroy(self)
56
71
  end
57
- function StunImmunityUnitBehavior.prototype.onBuffsCheck(self)
58
- local hasRemovedBuffs = false
59
- for buffTypeId in pairs(self.parameters.buffTypeIds or DEFAULT_BUFF_TYPE_IDS) do
60
- hasRemovedBuffs = hasRemovedBuffs or self.unit:removeBuff(buffTypeId)
61
- end
62
- if hasRemovedBuffs and self.parameters.textTagText ~= nil then
63
- TextTag:flash(TextTag.MISS, self.parameters.textTagText, self.unit.x, self.unit.y)
64
- end
72
+ function StunImmunityUnitBehavior.prototype.onDamageReceived(self)
73
+ process(self)
74
+ Timer:run(process, self)
75
+ end
76
+ function StunImmunityUnitBehavior.prototype.onTargetingAbilityChannelingStart(self)
77
+ process(self)
78
+ end
79
+ function StunImmunityUnitBehavior.prototype.onTargetingAbilityImpact(self)
80
+ process(self)
65
81
  end
66
82
  StunImmunityUnitBehavior.defaultParameters = {buffTypeIds = DEFAULT_BUFF_TYPE_IDS, textTagPreset = TextTag.MISS, textTagText = nil}
67
83
  return ____exports
@@ -9,13 +9,15 @@ import type { AbilityBehavior } from "./ability";
9
9
  import { Event } from "../../event";
10
10
  import { Destructor } from "../../destroyable";
11
11
  import type { Widget } from "../../core/types/widget";
12
+ import { Destructable } from "../../core/types/destructable";
13
+ import type { Buff } from "../buff";
12
14
  export type UnitBehaviorConstructor<Args extends any[]> = new (unit: Unit, ...args: Args) => UnitBehavior;
13
15
  export declare abstract class UnitBehavior<PeriodicActionParameters extends any[] = any[]> extends Behavior<Unit, PeriodicActionParameters> {
14
16
  constructor(unit: Unit);
15
17
  protected onDestroy(): Destructor;
16
18
  readonly sourceAbilityBehavior?: AbilityBehavior;
17
19
  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;
20
+ registerInRangeUnitEvent<T extends string, Args extends any[]>(this: UnitBehavior<PeriodicActionParameters> & Record<T, (this: this, ...args: Args) => unknown>, event: Event<[...Args]>, extractUnit: (...args: Args) => Unit, range: number, listener: T): void;
19
21
  onImmediateOrder(orderId: number): void;
20
22
  onTargetOrder(orderId: number, target: Widget): void;
21
23
  onPointOrder(orderId: number, x: number, y: number): void;
@@ -30,8 +32,18 @@ export declare abstract class UnitBehavior<PeriodicActionParameters extends any[
30
32
  onAbilityGained(ability: Ability): void;
31
33
  onAbilityLost(ability: Ability): void;
32
34
  onAbilityChannelingStart(ability: Ability): void;
35
+ onAbilityImpact(ability: Ability): void;
36
+ onAbilityWidgetTargetImpact(ability: Ability, target: Widget): void;
37
+ onAbilityUnitTargetImpact(ability: Ability, target: Unit): void;
38
+ onAbilityItemTargetImpact(ability: Ability, target: Item): void;
39
+ onAbilityDestructibleTargetImpact(ability: Ability, target: Destructable): void;
40
+ onAbilityPointTargetImpact(ability: Ability, x: number, y: number): void;
41
+ onAbilityNoTargetImpact(ability: Ability): void;
33
42
  onAbilityChannelingFinish(ability: Ability): void;
34
43
  onAbilityStop(ability: Ability): void;
44
+ onTargetingAbilityChannelingStart(ability: Ability, source: Unit): void;
45
+ onTargetingAbilityImpact(ability: Ability, source: Unit): void;
46
+ onBuffGained(buff: Buff): void;
35
47
  onItemDropped(item: Item): void;
36
48
  onItemPickedUp(item: Item): void;
37
49
  onItemUsed(item: Item): void;
@@ -49,7 +49,7 @@ function UnitBehavior.prototype.onDestroy(self)
49
49
  end
50
50
  return Behavior.prototype.onDestroy(self)
51
51
  end
52
- function UnitBehavior.prototype.registerInRangeUnitEvent(self, event, range, listener)
52
+ function UnitBehavior.prototype.registerInRangeUnitEvent(self, event, extractUnit, range, listener)
53
53
  local rangeByBehavior = getOrPut(rangeByBehaviorByEvent, event, mutableLuaMap)
54
54
  rangeByBehavior[self] = range
55
55
  local listenerByBehavior = getOrPut(listenerByBehaviorByEvent, event, mutableLuaMap)
@@ -57,14 +57,15 @@ function UnitBehavior.prototype.registerInRangeUnitEvent(self, event, range, lis
57
57
  getOrPut(eventsByBehavior, self, mutableLuaSet)[event] = true
58
58
  local behaviors = behaviorsByEvent[event]
59
59
  if behaviors == nil then
60
- event:addListener(function(unit, ...)
60
+ event:addListener(function(...)
61
+ local unit = extractUnit(...)
61
62
  local behaviors = behaviorsByEvent[event]
62
63
  if behaviors ~= nil then
63
64
  for behavior in pairs(behaviors) do
64
65
  local range = rangeByBehavior[behavior]
65
66
  if range ~= nil and unit:getCollisionDistanceTo(behavior.unit) <= range then
66
67
  local ____self_6 = behavior
67
- ____self_6[listenerByBehavior[behavior]](____self_6, unit, ...)
68
+ ____self_6[listenerByBehavior[behavior]](____self_6, ...)
68
69
  end
69
70
  end
70
71
  end
@@ -102,10 +103,30 @@ function UnitBehavior.prototype.onAbilityLost(self, ability)
102
103
  end
103
104
  function UnitBehavior.prototype.onAbilityChannelingStart(self, ability)
104
105
  end
106
+ function UnitBehavior.prototype.onAbilityImpact(self, ability)
107
+ end
108
+ function UnitBehavior.prototype.onAbilityWidgetTargetImpact(self, ability, target)
109
+ end
110
+ function UnitBehavior.prototype.onAbilityUnitTargetImpact(self, ability, target)
111
+ end
112
+ function UnitBehavior.prototype.onAbilityItemTargetImpact(self, ability, target)
113
+ end
114
+ function UnitBehavior.prototype.onAbilityDestructibleTargetImpact(self, ability, target)
115
+ end
116
+ function UnitBehavior.prototype.onAbilityPointTargetImpact(self, ability, x, y)
117
+ end
118
+ function UnitBehavior.prototype.onAbilityNoTargetImpact(self, ability)
119
+ end
105
120
  function UnitBehavior.prototype.onAbilityChannelingFinish(self, ability)
106
121
  end
107
122
  function UnitBehavior.prototype.onAbilityStop(self, ability)
108
123
  end
124
+ function UnitBehavior.prototype.onTargetingAbilityChannelingStart(self, ability, source)
125
+ end
126
+ function UnitBehavior.prototype.onTargetingAbilityImpact(self, ability, source)
127
+ end
128
+ function UnitBehavior.prototype.onBuffGained(self, buff)
129
+ end
109
130
  function UnitBehavior.prototype.onItemDropped(self, item)
110
131
  end
111
132
  function UnitBehavior.prototype.onItemPickedUp(self, item)
@@ -173,6 +194,37 @@ __TS__SetDescriptor(
173
194
  Unit.abilityChannelingStartEvent:addListener(function(source, ability)
174
195
  ____exports.UnitBehavior:forAll(source, "onAbilityChannelingStart", ability)
175
196
  end)
197
+ Unit.abilityUnitTargetChannelingStartEvent:addListener(function(source, ability, target)
198
+ ____exports.UnitBehavior:forAll(target, "onTargetingAbilityChannelingStart", ability, source)
199
+ end)
200
+ Unit.abilityImpactEvent:addListener(function(source, ability)
201
+ ____exports.UnitBehavior:forAll(source, "onAbilityImpact", ability)
202
+ end)
203
+ Unit.abilityWidgetTargetImpactEvent:addListener(function(source, ability, target)
204
+ ____exports.UnitBehavior:forAll(source, "onAbilityWidgetTargetImpact", ability, target)
205
+ end)
206
+ Unit.abilityUnitTargetImpactEvent:addListener(function(source, ability, target)
207
+ ____exports.UnitBehavior:forAll(source, "onAbilityUnitTargetImpact", ability, target)
208
+ ____exports.UnitBehavior:forAll(target, "onTargetingAbilityImpact", ability, source)
209
+ end)
210
+ Unit.abilityItemTargetImpactEvent:addListener(function(source, ability, target)
211
+ ____exports.UnitBehavior:forAll(source, "onAbilityItemTargetImpact", ability, target)
212
+ end)
213
+ Unit.abilityDestructibleTargetImpactEvent:addListener(function(source, ability, target)
214
+ ____exports.UnitBehavior:forAll(source, "onAbilityDestructibleTargetImpact", ability, target)
215
+ end)
216
+ Unit.abilityPointTargetImpactEvent:addListener(function(source, ability, x, y)
217
+ ____exports.UnitBehavior:forAll(
218
+ source,
219
+ "onAbilityPointTargetImpact",
220
+ ability,
221
+ x,
222
+ y
223
+ )
224
+ end)
225
+ Unit.abilityNoTargetImpactEvent:addListener(function(source, ability)
226
+ ____exports.UnitBehavior:forAll(source, "onAbilityNoTargetImpact", ability)
227
+ end)
176
228
  Unit.abilityChannelingFinishEvent:addListener(function(source, ability)
177
229
  ____exports.UnitBehavior:forAll(source, "onAbilityChannelingFinish", ability)
178
230
  end)
package/engine/buff.d.ts CHANGED
@@ -278,6 +278,7 @@ export declare class Buff<AdditionalParameters extends Prohibit<Record<string, a
278
278
  onDeath(source: Unit | undefined): void;
279
279
  onDamageDealt(target: Unit, event: DamageEvent): void;
280
280
  onDamageReceived(source: Unit | undefined, event: DamageEvent): void;
281
- static readonly destroyEvent: Event<[Buff<object>]>;
281
+ static readonly createdEvent: Event<[Buff<object>]>;
282
+ static readonly beingDestroyedEvent: Event<[Buff<object>]>;
282
283
  }
283
284
  export {};
package/engine/buff.lua CHANGED
@@ -304,7 +304,8 @@ buffHealingIntervalTimerCallback = function(buff)
304
304
  source:healTarget(buff[101], healingPerInterval)
305
305
  end
306
306
  end
307
- local buffDestroyEvent = __TS__New(Event)
307
+ local buffCreatedEvent = __TS__New(Event)
308
+ local buffBeingDestroyedEvent = __TS__New(Event)
308
309
  ____exports.Buff = __TS__Class()
309
310
  local Buff = ____exports.Buff
310
311
  Buff.name = "Buff"
@@ -506,6 +507,7 @@ function Buff.prototype.____constructor(self, _unit, typeIdOrTypeIds, polarityOr
506
507
  end
507
508
  self:onCreate()
508
509
  self[100] = 1
510
+ Event.invoke(buffCreatedEvent, self)
509
511
  end
510
512
  function Buff.prototype.getUnitBonus(self, bonusType)
511
513
  local ____opt_38 = self._bonusIdByBonusType
@@ -619,7 +621,7 @@ function Buff.prototype.onDestroy(self)
619
621
  removeUnitBonus(unit, bonusType, bonusId)
620
622
  end
621
623
  end
622
- Event.invoke(buffDestroyEvent, self)
624
+ Event.invoke(buffBeingDestroyedEvent, self)
623
625
  self[100] = 3
624
626
  return UnitBehavior.prototype.onDestroy(self)
625
627
  end
@@ -1288,7 +1290,8 @@ __TS__SetDescriptor(
1288
1290
  },
1289
1291
  true
1290
1292
  )
1291
- Buff.destroyEvent = buffDestroyEvent;
1293
+ Buff.createdEvent = buffCreatedEvent
1294
+ Buff.beingDestroyedEvent = buffBeingDestroyedEvent;
1292
1295
  (function(self)
1293
1296
  local function destroyBuffIfNeeded(buff)
1294
1297
  if getUnitAbility(buff[101].handle, buff.typeId) ~= buff.handle and buff[100] == 1 then
@@ -1342,5 +1345,8 @@ Buff.destroyEvent = buffDestroyEvent;
1342
1345
  ____exports.checkBuffs(target)
1343
1346
  end
1344
1347
  )
1348
+ buffCreatedEvent:addListener(function(buff)
1349
+ UnitBehavior:forAll(buff.unit, "onBuffGained", buff)
1350
+ end)
1345
1351
  end)(Buff)
1346
1352
  return ____exports
@@ -55,11 +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;
61
62
  incrementDisableCounter(): void;
62
63
  decrementDisableCounter(): void;
64
+ get isDisabled(): boolean;
63
65
  get level(): number;
64
66
  set level(v: number);
65
67
  get cooldownRemaining(): number;
@@ -405,13 +405,23 @@ function UnitAbility.prototype.decrementHideCounter(self)
405
405
  end
406
406
  function UnitAbility.prototype.incrementDisableCounter(self)
407
407
  unitDisableAbility(self.u, self.typeId, true, false)
408
+ self.d = (self.d or 0) + 1
408
409
  end
409
410
  function UnitAbility.prototype.decrementDisableCounter(self)
410
411
  unitDisableAbility(self.u, self.typeId, false, false)
412
+ self.d = (self.d or 0) - 1
411
413
  end
412
414
  function UnitAbility.prototype.interruptCast(self)
413
415
  self.owner:interruptCast(self.typeId)
414
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
+ )
415
425
  __TS__SetDescriptor(
416
426
  UnitAbility.prototype,
417
427
  "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 = BlzGetItemAbility(cooldownStarterItem, COOLDOWN_STARTER_ABILITY_TYPE_ID)
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
@@ -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;
@@ -157,14 +157,17 @@ function Item.create(self, id, x, y, skinId)
157
157
  return self:of(BlzCreateItemWithSkin(id, x, y, skinId or id))
158
158
  end
159
159
  function Item.prototype.consumeCharge(self)
160
+ return self:consumeCharges(1)
161
+ end
162
+ function Item.prototype.consumeCharges(self, count)
160
163
  local handle = self.handle
161
164
  local charges = getItemCharges(handle)
162
- if charges >= 2 then
163
- setItemCharges(handle, charges - 1)
165
+ if charges > count then
166
+ setItemCharges(handle, charges - count)
164
167
  invoke(itemChargesChangeEvent, self)
165
168
  return true
166
169
  end
167
- if charges == 1 then
170
+ if charges == count then
168
171
  if getItemBooleanField(handle, ITEM_BF_PERISHABLE) then
169
172
  self:destroy()
170
173
  return true
@@ -174,6 +177,7 @@ function Item.prototype.consumeCharge(self)
174
177
  invoke(itemChargesChangeEvent, self)
175
178
  return true
176
179
  end
180
+ setItemCharges(handle, 1)
177
181
  local ____doAbilityActionForceDummy_2 = doAbilityActionForceDummy
178
182
  local ____opt_0 = self.owner
179
183
  ____doAbilityActionForceDummy_2(handle, ____opt_0 and ____opt_0.handle, consumeCharge)
@@ -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]>;