warscript 0.0.1-dev.96a6f7e → 0.0.1-dev.971c803

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 (70) hide show
  1. package/core/types/effect.d.ts +13 -3
  2. package/core/types/effect.lua +116 -17
  3. package/core/types/frame.d.ts +4 -0
  4. package/core/types/frame.lua +71 -0
  5. package/core/util.d.ts +1 -1
  6. package/core/util.lua +6 -0
  7. package/engine/behaviour/ability/always-enabled.d.ts +7 -0
  8. package/engine/behaviour/ability/always-enabled.lua +31 -0
  9. package/engine/behaviour/ability/apply-buff.d.ts +5 -0
  10. package/engine/behaviour/ability/apply-buff.lua +32 -0
  11. package/engine/behaviour/ability/emulate-impact.d.ts +6 -0
  12. package/engine/behaviour/ability/emulate-impact.lua +28 -0
  13. package/engine/behaviour/ability/instant-impact.d.ts +2 -2
  14. package/engine/behaviour/ability/instant-impact.lua +4 -19
  15. package/engine/behaviour/ability/on-command-impact.d.ts +8 -0
  16. package/engine/behaviour/ability/on-command-impact.lua +25 -0
  17. package/engine/behaviour/ability/remove-buffs.d.ts +16 -0
  18. package/engine/behaviour/ability/remove-buffs.lua +28 -0
  19. package/engine/behaviour/ability.d.ts +15 -3
  20. package/engine/behaviour/ability.lua +93 -34
  21. package/engine/buff.d.ts +11 -1
  22. package/engine/buff.lua +50 -19
  23. package/engine/internal/ability.d.ts +15 -2
  24. package/engine/internal/ability.lua +84 -4
  25. package/engine/internal/item/ability.lua +106 -0
  26. package/engine/internal/misc/ability-disable-counter.d.ts +2 -0
  27. package/engine/internal/misc/ability-disable-counter.lua +13 -0
  28. package/engine/internal/object-data/auto-attack-speed-increase.d.ts +1 -1
  29. package/engine/internal/object-data/auto-attack-speed-increase.lua +2 -0
  30. package/engine/internal/object-data/evasion-probability.d.ts +2 -0
  31. package/engine/internal/object-data/evasion-probability.lua +16 -0
  32. package/engine/internal/unit/ability.d.ts +10 -1
  33. package/engine/internal/unit/ability.lua +36 -14
  34. package/engine/internal/unit/add-item-to-slot-init.d.ts +2 -0
  35. package/engine/internal/unit/add-item-to-slot-init.lua +23 -0
  36. package/engine/internal/unit/add-item-to-slot.d.ts +2 -0
  37. package/engine/internal/unit/add-item-to-slot.lua +50 -0
  38. package/engine/internal/unit/bonus.d.ts +2 -0
  39. package/engine/internal/unit/bonus.lua +17 -0
  40. package/engine/internal/unit/ignore-events-items.d.ts +2 -0
  41. package/engine/internal/unit/ignore-events-items.lua +5 -0
  42. package/engine/internal/unit/item.d.ts +1 -0
  43. package/engine/internal/unit/item.lua +8 -4
  44. package/engine/internal/unit/main-selected.d.ts +13 -0
  45. package/engine/internal/unit/main-selected.lua +51 -0
  46. package/engine/internal/unit.d.ts +21 -7
  47. package/engine/internal/unit.lua +152 -77
  48. package/engine/internal/utility.lua +12 -0
  49. package/engine/lightning.d.ts +8 -2
  50. package/engine/lightning.lua +27 -2
  51. package/engine/local-client.d.ts +7 -2
  52. package/engine/local-client.lua +82 -0
  53. package/engine/object-data/auxiliary/sound-preset-name.d.ts +5 -1
  54. package/engine/object-data/entry/ability-type.lua +8 -12
  55. package/engine/object-data/entry/item-type.d.ts +2 -0
  56. package/engine/object-data/entry/item-type.lua +13 -0
  57. package/engine/object-data/utility/object-data-entry-id-generator.lua +7 -0
  58. package/engine/object-field/ability.d.ts +9 -3
  59. package/engine/object-field/ability.lua +3 -0
  60. package/engine/object-field.d.ts +2 -2
  61. package/engine/object-field.lua +4 -0
  62. package/engine/standard/fields/ability.d.ts +2 -0
  63. package/engine/standard/fields/ability.lua +2 -0
  64. package/engine/unit.d.ts +2 -0
  65. package/engine/unit.lua +2 -0
  66. package/package.json +2 -2
  67. package/utility/arrays.d.ts +8 -1
  68. package/utility/arrays.lua +34 -3
  69. package/utility/lazy.d.ts +2 -0
  70. package/utility/lazy.lua +14 -0
@@ -10,7 +10,10 @@ local ____exports = {}
10
10
  local ____handle = require("core.types.handle")
11
11
  local Handle = ____handle.Handle
12
12
  local ____ability = require("engine.internal.item.ability")
13
+ local abilityActionDummy = ____ability.abilityActionDummy
13
14
  local doAbilityAction = ____ability.doAbilityAction
15
+ local doAbilityActionForceDummy = ____ability.doAbilityActionForceDummy
16
+ local startItemCooldown = ____ability.startItemCooldown
14
17
  local getUnitAbilityLevel = GetUnitAbilityLevel
15
18
  local setUnitAbilityLevel = SetUnitAbilityLevel
16
19
  local setAbilityIntegerField = BlzSetAbilityIntegerField
@@ -32,6 +35,9 @@ local getAbilityStringLevelField = BlzGetAbilityStringLevelField
32
35
  local getUnitAbilityCooldownRemaining = BlzGetUnitAbilityCooldownRemaining
33
36
  local startUnitAbilityCooldown = BlzStartUnitAbilityCooldown
34
37
  local getHandleId = GetHandleId
38
+ local getItemBooleanField = BlzGetItemBooleanField
39
+ local setItemBooleanField = BlzSetItemBooleanField
40
+ local unitHideAbility = BlzUnitHideAbility
35
41
  local match = string.match
36
42
  local ____type = _G.type
37
43
  local ____tostring = _G.tostring
@@ -295,10 +301,18 @@ __TS__SetDescriptor(
295
301
  )
296
302
  __TS__SetDescriptor(
297
303
  Ability.prototype,
298
- "orderId",
304
+ "orderTypeStringId",
299
305
  {get = function(self)
300
306
  local field = orderIdFieldByParentTypeId[self.parentTypeId]
301
- return order2orderId(field ~= nil and getAbilityStringLevelField(self.handle, ABILITY_SLF_BASE_ORDER_ID_NCL6, self.level) or (orders[self.parentTypeId] or ""))
307
+ return field ~= nil and getAbilityStringLevelField(self.handle, field, self.level) or (orders[self.parentTypeId] or "")
308
+ end},
309
+ true
310
+ )
311
+ __TS__SetDescriptor(
312
+ Ability.prototype,
313
+ "orderTypeId",
314
+ {get = function(self)
315
+ return order2orderId(self.orderTypeStringId)
302
316
  end},
303
317
  true
304
318
  )
@@ -317,6 +331,17 @@ __TS__SetDescriptor(
317
331
  end},
318
332
  true
319
333
  )
334
+ __TS__SetDescriptor(
335
+ Ability.prototype,
336
+ "cooldownRemaining",
337
+ {
338
+ get = function(self)
339
+ end,
340
+ set = function(self, cooldownRemaining)
341
+ end
342
+ },
343
+ true
344
+ )
320
345
  __TS__ObjectDefineProperty(
321
346
  Ability,
322
347
  "onCreate",
@@ -340,6 +365,8 @@ function UnrecognizedAbility.prototype.____constructor(self, typeId, owner)
340
365
  UnrecognizedAbility.____super.prototype.____constructor(self, nil, typeId)
341
366
  self.owner = owner
342
367
  end
368
+ function UnrecognizedAbility.prototype.interruptCast(self)
369
+ end
343
370
  __TS__SetDescriptor(
344
371
  UnrecognizedAbility.prototype,
345
372
  "level",
@@ -348,6 +375,18 @@ __TS__SetDescriptor(
348
375
  end},
349
376
  true
350
377
  )
378
+ __TS__SetDescriptor(
379
+ UnrecognizedAbility.prototype,
380
+ "cooldownRemaining",
381
+ {
382
+ get = function(self)
383
+ return 0
384
+ end,
385
+ set = function(self, _)
386
+ end
387
+ },
388
+ true
389
+ )
351
390
  ____exports.UnitAbility = __TS__Class()
352
391
  local UnitAbility = ____exports.UnitAbility
353
392
  UnitAbility.name = "UnitAbility"
@@ -357,6 +396,15 @@ function UnitAbility.prototype.____constructor(self, handle, typeId, owner)
357
396
  self.owner = owner
358
397
  self.u = owner.handle
359
398
  end
399
+ function UnitAbility.prototype.incrementHideCounter(self)
400
+ unitHideAbility(self.u, self.typeId, true)
401
+ end
402
+ function UnitAbility.prototype.decrementHideCounter(self)
403
+ unitHideAbility(self.u, self.typeId, false)
404
+ end
405
+ function UnitAbility.prototype.interruptCast(self)
406
+ self.owner:interruptCast(self.typeId)
407
+ end
360
408
  __TS__SetDescriptor(
361
409
  UnitAbility.prototype,
362
410
  "level",
@@ -377,8 +425,8 @@ __TS__SetDescriptor(
377
425
  get = function(self)
378
426
  return getUnitAbilityCooldownRemaining(self.u, self.typeId)
379
427
  end,
380
- set = function(self, v)
381
- startUnitAbilityCooldown(self.u, self.typeId, v)
428
+ set = function(self, cooldownRemaining)
429
+ startUnitAbilityCooldown(self.u, self.typeId, cooldownRemaining)
382
430
  end
383
431
  },
384
432
  true
@@ -403,6 +451,9 @@ end
403
451
  local function setAbilityField(_, ability, field, levelOrValue, value)
404
452
  return ____exports.Ability.prototype.setField(ability, field, levelOrValue, value)
405
453
  end
454
+ local function getAbilityCooldown(_, abilityTypeId)
455
+ return getUnitAbilityCooldownRemaining(abilityActionDummy, abilityTypeId)
456
+ end
406
457
  ____exports.ItemAbility = __TS__Class()
407
458
  local ItemAbility = ____exports.ItemAbility
408
459
  ItemAbility.name = "ItemAbility"
@@ -430,6 +481,14 @@ function ItemAbility.prototype.setField(self, field, levelOrValue, value)
430
481
  value
431
482
  )
432
483
  end
484
+ function ItemAbility.prototype.interruptCast(self)
485
+ local handle = self.owner.handle
486
+ local activelyUsed = getItemBooleanField(handle, ITEM_BF_ACTIVELY_USED)
487
+ if activelyUsed then
488
+ setItemBooleanField(handle, ITEM_BF_ACTIVELY_USED, false)
489
+ setItemBooleanField(handle, ITEM_BF_ACTIVELY_USED, true)
490
+ end
491
+ end
433
492
  __TS__SetDescriptor(
434
493
  ItemAbility.prototype,
435
494
  "level",
@@ -438,6 +497,27 @@ __TS__SetDescriptor(
438
497
  end},
439
498
  true
440
499
  )
500
+ __TS__SetDescriptor(
501
+ ItemAbility.prototype,
502
+ "cooldownRemaining",
503
+ {
504
+ get = function(self)
505
+ local item = self.owner
506
+ local ____doAbilityActionForceDummy_4 = doAbilityActionForceDummy
507
+ local ____item_handle_3 = item.handle
508
+ local ____opt_1 = item.owner
509
+ return ____doAbilityActionForceDummy_4(____item_handle_3, ____opt_1 and ____opt_1.handle, getAbilityCooldown, self.typeId)
510
+ end,
511
+ set = function(self, cooldownRemaining)
512
+ local item = self.owner
513
+ local ____startItemCooldown_8 = startItemCooldown
514
+ local ____item_handle_7 = item.handle
515
+ local ____opt_5 = item.owner
516
+ ____startItemCooldown_8(____item_handle_7, ____opt_5 and ____opt_5.handle, cooldownRemaining)
517
+ end
518
+ },
519
+ true
520
+ )
441
521
  __TS__ObjectDefineProperty(
442
522
  ItemAbility,
443
523
  "onCreate",
@@ -1,16 +1,60 @@
1
1
  local ____exports = {}
2
+ local restoreCooldownGroup
2
3
  local ____player = require("core.types.player")
3
4
  local Player = ____player.Player
4
5
  local ____dummy = require("objutil.dummy")
5
6
  local dummyUnitId = ____dummy.dummyUnitId
7
+ local ____utility = require("engine.internal.utility")
8
+ local findUnitItemSlot = ____utility.findUnitItemSlot
9
+ local ____blank = require("engine.object-data.entry.item-type.blank")
10
+ local BlankItemType = ____blank.BlankItemType
11
+ local ____object_2Ddata_2Dentry_2Did_2Dgenerator = require("engine.object-data.utility.object-data-entry-id-generator")
12
+ local abilityTypeIdGenerator = ____object_2Ddata_2Dentry_2Did_2Dgenerator.abilityTypeIdGenerator
13
+ local ____math = require("math")
14
+ local MINIMUM_POSITIVE_NORMALIZED_FLOAT = ____math.MINIMUM_POSITIVE_NORMALIZED_FLOAT
15
+ local ____timer = require("core.types.timer")
16
+ local Timer = ____timer.Timer
17
+ local ____ignore_2Devents_2Ditems = require("engine.internal.unit.ignore-events-items")
18
+ local ignoreEventsItems = ____ignore_2Devents_2Ditems.ignoreEventsItems
19
+ local ____add_2Ditem_2Dto_2Dslot = require("engine.internal.unit.add-item-to-slot")
20
+ local unitAddItemToSlot = ____add_2Ditem_2Dto_2Dslot.unitAddItemToSlot
6
21
  local isItemOwned = IsItemOwned
7
22
  local isItemPowerup = IsItemPowerup
8
23
  local getItemX = GetItemX
9
24
  local getItemY = GetItemY
25
+ local setAbilityRealLevelField = BlzSetAbilityRealLevelField
26
+ local setItemIntegerField = BlzSetItemIntegerField
27
+ local getItemIntegerField = BlzGetItemIntegerField
10
28
  local setItemBooleanField = BlzSetItemBooleanField
11
29
  local setItemPosition = SetItemPosition
12
30
  local unitAddItem = UnitAddItem
13
31
  local unitRemoveItem = UnitRemoveItem
32
+ local unitUseItem = UnitUseItem
33
+ local unitResetCooldown = UnitResetCooldown
34
+ local COOLDOWN_STARTER_ABILITY_TYPE_ID = compiletime(function()
35
+ if not currentMap then
36
+ return 0
37
+ end
38
+ local abilityType = currentMap.objects.ability:newObject(
39
+ util.id2s(abilityTypeIdGenerator:next()),
40
+ "Absk"
41
+ )
42
+ abilityType["bsk1+0"] = 0
43
+ abilityType["bsk2+0"] = 0
44
+ abilityType["bsk3+0"] = 0
45
+ abilityType["amcs+0"] = 0
46
+ abilityType["adur+0"] = MINIMUM_POSITIVE_NORMALIZED_FLOAT
47
+ abilityType["ahdu+0"] = MINIMUM_POSITIVE_NORMALIZED_FLOAT
48
+ return util.s2id(abilityType.id)
49
+ end)
50
+ local COOLDOWN_STARTER_ITEM_TYPE_ID = compiletime(function()
51
+ local itemType = BlankItemType:create()
52
+ itemType.name = "[Warscript/Dummy] Item Cooldown Starter"
53
+ itemType.abilityTypeIds = {COOLDOWN_STARTER_ABILITY_TYPE_ID}
54
+ itemType.cooldownGroupId = COOLDOWN_STARTER_ABILITY_TYPE_ID
55
+ itemType.activelyUsed = true
56
+ return itemType.id
57
+ end)
14
58
  local dummy = assert(CreateUnit(
15
59
  Player.neutralVictim.handle,
16
60
  dummyUnitId,
@@ -18,10 +62,37 @@ local dummy = assert(CreateUnit(
18
62
  0,
19
63
  270
20
64
  ))
65
+ local cooldownStarterItem = UnitAddItemById(dummy, COOLDOWN_STARTER_ITEM_TYPE_ID)
66
+ local cooldownStarterAbility = BlzGetItemAbility(cooldownStarterItem, COOLDOWN_STARTER_ABILITY_TYPE_ID)
21
67
  ShowUnit(dummy, false)
68
+ local function startItemCooldownInternal(handle, cooldown)
69
+ local cooldownGroup = getItemIntegerField(handle, ITEM_IF_COOLDOWN_GROUP)
70
+ setItemIntegerField(handle, ITEM_IF_COOLDOWN_GROUP, COOLDOWN_STARTER_ABILITY_TYPE_ID)
71
+ setAbilityRealLevelField(cooldownStarterAbility, ABILITY_RLF_COOLDOWN, 0, cooldown)
72
+ unitResetCooldown(dummy)
73
+ unitUseItem(dummy, cooldownStarterItem)
74
+ Timer:run(restoreCooldownGroup, handle, cooldownGroup)
75
+ end
76
+ restoreCooldownGroup = function(handle, cooldownGroup)
77
+ if getItemIntegerField(handle, ITEM_IF_COOLDOWN_GROUP) == COOLDOWN_STARTER_ABILITY_TYPE_ID then
78
+ setItemIntegerField(handle, ITEM_IF_COOLDOWN_GROUP, cooldownGroup)
79
+ end
80
+ end
81
+ ---
82
+ -- @internal For use by internal systems only.
83
+ ____exports.startItemCooldown = function(handle, owner, cooldown)
84
+ ____exports.doAbilityActionForceDummy(handle, owner, startItemCooldownInternal, cooldown)
85
+ end
86
+ ---
87
+ -- @internal For use by internal systems only.
88
+ ____exports.abilityActionDummy = dummy
22
89
  ---
23
90
  -- @internal For use by internal systems only.
24
91
  ____exports.doAbilityAction = function(handle, action, ...)
92
+ local isAlreadyIgnoredInEvents = ignoreEventsItems[handle] ~= nil
93
+ if not isAlreadyIgnoredInEvents then
94
+ ignoreEventsItems[handle] = true
95
+ end
25
96
  local isOwned = isItemOwned(handle)
26
97
  local isPowerup
27
98
  local x
@@ -43,6 +114,41 @@ ____exports.doAbilityAction = function(handle, action, ...)
43
114
  setItemBooleanField(handle, ITEM_BF_USE_AUTOMATICALLY_WHEN_ACQUIRED, true)
44
115
  end
45
116
  end
117
+ if not isAlreadyIgnoredInEvents then
118
+ ignoreEventsItems[handle] = nil
119
+ end
120
+ return result
121
+ end
122
+ ---
123
+ -- @internal For use by internal systems only.
124
+ ____exports.doAbilityActionForceDummy = function(handle, owner, action, ...)
125
+ if owner == nil then
126
+ return ____exports.doAbilityAction(handle, action, ...)
127
+ end
128
+ local slot = findUnitItemSlot(owner, handle)
129
+ if slot == nil then
130
+ return ____exports.doAbilityAction(handle, action, ...)
131
+ end
132
+ local isAlreadyIgnoredInEvents = ignoreEventsItems[handle] ~= nil
133
+ if not isAlreadyIgnoredInEvents then
134
+ ignoreEventsItems[handle] = true
135
+ end
136
+ local isPowerup
137
+ if isItemPowerup(handle) then
138
+ setItemBooleanField(handle, ITEM_BF_USE_AUTOMATICALLY_WHEN_ACQUIRED, false)
139
+ isPowerup = true
140
+ end
141
+ unitRemoveItem(owner, handle)
142
+ unitAddItem(dummy, handle)
143
+ local result = action(handle, ...)
144
+ unitRemoveItem(dummy, handle)
145
+ unitAddItemToSlot(owner, handle, slot)
146
+ if isPowerup then
147
+ setItemBooleanField(handle, ITEM_BF_USE_AUTOMATICALLY_WHEN_ACQUIRED, true)
148
+ end
149
+ if not isAlreadyIgnoredInEvents then
150
+ ignoreEventsItems[handle] = nil
151
+ end
46
152
  return result
47
153
  end
48
154
  return ____exports
@@ -0,0 +1,2 @@
1
+ /** @noSelfInFile */
2
+ export {};
@@ -0,0 +1,13 @@
1
+ local ____exports = {}
2
+ local disableAbility = BlzUnitDisableAbility
3
+ ---
4
+ -- @internal For use by internal systems only.
5
+ ____exports.increaseAbilityDisableCounter = function(unit, abilityTypeId, times)
6
+ for _ = 1, times do
7
+ disableAbility(unit, abilityTypeId, true, false)
8
+ end
9
+ for _ = times, -1 do
10
+ disableAbility(unit, abilityTypeId, false, false)
11
+ end
12
+ end
13
+ return ____exports
@@ -1,2 +1,2 @@
1
1
  /** @noSelfInFile */
2
- export declare const AUTO_ATTACK_SPEED_INCREASE_FACTOR_ABILITY_FIELD: jabilityreallevelfield;
2
+ export {};
@@ -10,5 +10,7 @@ ____exports.AUTO_ATTACK_SPEED_INCREASE_DUMMY_ABILITY_TYPE_ID = compiletime(funct
10
10
  abilityType.autoAttackSpeedIncreaseFactor = 0
11
11
  return abilityType.id
12
12
  end)
13
+ ---
14
+ -- @internal For use by internal systems.
13
15
  ____exports.AUTO_ATTACK_SPEED_INCREASE_FACTOR_ABILITY_FIELD = ABILITY_RLF_ATTACK_SPEED_INCREASE_ISX1
14
16
  return ____exports
@@ -0,0 +1,2 @@
1
+ /** @noSelfInFile */
2
+ export {};
@@ -0,0 +1,16 @@
1
+ local ____exports = {}
2
+ local ____evasion = require("engine.object-data.entry.ability-type.evasion")
3
+ local EvasionAbilityType = ____evasion.EvasionAbilityType
4
+ ---
5
+ -- @internal For use by internal systems.
6
+ ____exports.EVASION_PROBABILITY_DUMMY_ABILITY_TYPE_ID = compiletime(function()
7
+ local abilityType = EvasionAbilityType:create()
8
+ abilityType.isInternal = true
9
+ abilityType.isButtonVisible = false
10
+ abilityType.evasionProbability = 0
11
+ return abilityType.id
12
+ end)
13
+ ---
14
+ -- @internal For use by internal systems.
15
+ ____exports.EVASION_PROBABILITY_ABILITY_FIELD = ABILITY_RLF_CHANCE_TO_EVADE_EEV1
16
+ return ____exports
@@ -3,7 +3,7 @@ import { Ability } from "../ability";
3
3
  import { Destructable } from "../../../core/types/destructable";
4
4
  import { Item } from "../item";
5
5
  import { Widget } from "../../../core/types/widget";
6
- import { DispatchingEvent } from "../../../event";
6
+ import { DispatchingEvent, Event } from "../../../event";
7
7
  declare module "../unit" {
8
8
  namespace Unit {
9
9
  const abilityCastingStartEvent: DispatchingEvent<[Unit, Ability]>;
@@ -141,3 +141,12 @@ declare module "../unit" {
141
141
  const abilityStopEvent: DispatchingEvent<[Unit, Ability]>;
142
142
  }
143
143
  }
144
+ declare module "../unit" {
145
+ namespace Unit {
146
+ const abilityCommandEvent: {
147
+ readonly [abilityTypeId: number]: {
148
+ readonly [orderTypeStringId: string]: Event<[Unit, Ability, string]>;
149
+ };
150
+ };
151
+ }
152
+ }
@@ -15,8 +15,15 @@ local UnitTriggerEvent = ____unit.UnitTriggerEvent
15
15
  local ____event = require("event")
16
16
  local createDispatchingEvent = ____event.createDispatchingEvent
17
17
  local DependentInitializingEvent = ____event.DependentInitializingEvent
18
+ local Event = ____event.Event
19
+ local InitializingEvent = ____event.InitializingEvent
18
20
  local ____preconditions = require("utility.preconditions")
19
21
  local checkNotNull = ____preconditions.checkNotNull
22
+ local ____lazy = require("utility.lazy")
23
+ local lazyRecord = ____lazy.lazyRecord
24
+ local eventInvoke = Event.invoke
25
+ local condition = Condition
26
+ local createTrigger = CreateTrigger
20
27
  local getItemAbility = BlzGetItemAbility
21
28
  local getSpellAbility = GetSpellAbility
22
29
  local getSpellAbilityId = GetSpellAbilityId
@@ -26,11 +33,10 @@ local getSpellTargetUnit = GetSpellTargetUnit
26
33
  local getSpellTargetX = GetSpellTargetX
27
34
  local getSpellTargetY = GetSpellTargetY
28
35
  local getTriggerUnit = GetTriggerUnit
29
- local getUnitAbility = BlzGetUnitAbility
30
- local unitAddAbility = UnitAddAbility
36
+ local triggerAddCondition = TriggerAddCondition
37
+ local triggerRegisterCommandEvent = TriggerRegisterCommandEvent
31
38
  local unitInventorySize = UnitInventorySize
32
39
  local unitItemInSlot = UnitItemInSlot
33
- local unitRemoveAbility = UnitRemoveAbility
34
40
  local function retrieveAbility(unit, ability, abilityId)
35
41
  if ability == nil then
36
42
  return __TS__New(
@@ -39,17 +45,6 @@ local function retrieveAbility(unit, ability, abilityId)
39
45
  Unit:of(unit)
40
46
  )
41
47
  end
42
- if not unitAddAbility(unit, abilityId) then
43
- if getUnitAbility(unit, abilityId) == ability then
44
- return UnitAbility:of(
45
- ability,
46
- abilityId,
47
- Unit:of(unit)
48
- )
49
- end
50
- else
51
- unitRemoveAbility(unit, abilityId)
52
- end
53
48
  for i = 0, unitInventorySize(unit) - 1 do
54
49
  local item = unitItemInSlot(unit, i)
55
50
  if getItemAbility(item, abilityId) == ability then
@@ -366,4 +361,31 @@ rawset(
366
361
  extractAbilityTypeId
367
362
  )
368
363
  )
364
+ rawset(
365
+ Unit,
366
+ "abilityCommandEvent",
367
+ lazyRecord(function(abilityTypeId)
368
+ return lazyRecord(function(orderTypeStringId)
369
+ return __TS__New(
370
+ InitializingEvent,
371
+ function(event)
372
+ local trigger = createTrigger()
373
+ triggerRegisterCommandEvent(trigger, abilityTypeId, orderTypeStringId)
374
+ triggerAddCondition(
375
+ trigger,
376
+ condition(function()
377
+ local unit = Unit:of(getTriggerUnit())
378
+ if unit ~= nil then
379
+ local ability = unit:getAbilityById(abilityTypeId)
380
+ if ability ~= nil then
381
+ eventInvoke(event, unit, ability, orderTypeStringId)
382
+ end
383
+ end
384
+ end)
385
+ )
386
+ end
387
+ )
388
+ end)
389
+ end)
390
+ )
369
391
  return ____exports
@@ -0,0 +1,2 @@
1
+ /** @noSelfInFile */
2
+ export {};
@@ -0,0 +1,23 @@
1
+ local ____exports = {}
2
+ local ____unit = require("engine.internal.unit")
3
+ local Unit = ____unit.Unit
4
+ local ____add_2Ditem_2Dto_2Dslot = require("engine.internal.unit.add-item-to-slot")
5
+ local fillerItems = ____add_2Ditem_2Dto_2Dslot.fillerItems
6
+ local unitsWithFillerItems = ____add_2Ditem_2Dto_2Dslot.unitsWithFillerItems
7
+ local setItemVisible = SetItemVisible
8
+ local unitRemoveItem = UnitRemoveItem
9
+ Unit.itemPickedUpEvent:addListener(
10
+ 4,
11
+ function(unit)
12
+ local handle = unit.handle
13
+ if unitsWithFillerItems[handle] ~= nil then
14
+ for previousSlot = 1, 6 do
15
+ local fillerItem = fillerItems[previousSlot]
16
+ unitRemoveItem(handle, fillerItem)
17
+ setItemVisible(fillerItem, false)
18
+ end
19
+ unitsWithFillerItems[handle] = nil
20
+ end
21
+ end
22
+ )
23
+ return ____exports
@@ -0,0 +1,2 @@
1
+ /** @noSelfInFile */
2
+ export {};
@@ -0,0 +1,50 @@
1
+ local ____exports = {}
2
+ local ____blank = require("engine.object-data.entry.item-type.blank")
3
+ local BlankItemType = ____blank.BlankItemType
4
+ local ____arrays = require("utility.arrays")
5
+ local array = ____arrays.array
6
+ local ____ignore_2Devents_2Ditems = require("engine.internal.unit.ignore-events-items")
7
+ local ignoreEventsItems = ____ignore_2Devents_2Ditems.ignoreEventsItems
8
+ local setItemVisible = SetItemVisible
9
+ local unitAddItem = UnitAddItem
10
+ local unitItemInSlot = UnitItemInSlot
11
+ local unitRemoveItem = UnitRemoveItem
12
+ local FILLER_ITEM_TYPE_ID = compiletime(function()
13
+ local itemType = BlankItemType:create()
14
+ itemType.name = "[Warscript/Dummy] Slot Filler"
15
+ return itemType.id
16
+ end)
17
+ ---
18
+ -- @internal For use by internal systems only.
19
+ ____exports.fillerItems = array(
20
+ 6,
21
+ function()
22
+ local item = CreateItem(FILLER_ITEM_TYPE_ID, 0, 0)
23
+ setItemVisible(item, false)
24
+ ignoreEventsItems[item] = true
25
+ return item
26
+ end
27
+ )
28
+ ---
29
+ -- @internal For use by internal systems only.
30
+ ____exports.unitsWithFillerItems = {}
31
+ ---
32
+ -- @internal For use by internal systems only.
33
+ ____exports.unitAddItemToSlot = function(unit, item, slot)
34
+ for previousSlot = 0, slot - 1 do
35
+ if unitItemInSlot(unit, previousSlot) == nil then
36
+ unitAddItem(unit, ____exports.fillerItems[previousSlot + 1])
37
+ ____exports.unitsWithFillerItems[unit] = true
38
+ end
39
+ end
40
+ unitAddItem(unit, item)
41
+ if ____exports.unitsWithFillerItems[unit] ~= nil then
42
+ for previousSlot = 0, slot - 1 do
43
+ local fillerItem = ____exports.fillerItems[previousSlot + 1]
44
+ unitRemoveItem(unit, fillerItem)
45
+ setItemVisible(fillerItem, false)
46
+ end
47
+ ____exports.unitsWithFillerItems[unit] = nil
48
+ end
49
+ end
50
+ return ____exports
@@ -11,6 +11,7 @@ export type UnitMovementSpeedFactorBonusId = UnitBonusId<"movementSpeedFactor">;
11
11
  export type UnitAutoAttackDamageBonusId = UnitBonusId<"autoAttackDamage">;
12
12
  export type UnitDamageFactorBonusId = UnitBonusId<"damageFactor">;
13
13
  export type UnitReceivedDamageFactorBonusId = UnitBonusId<"receivedDamageFactor">;
14
+ export type UnitEvasionProbabilityBonusId = UnitBonusId<"evasionProbability">;
14
15
  export type UnitBonusType<Id extends UnitBonusId = UnitBonusId> = ({
15
16
  abilityTypeId: AbilityTypeId;
16
17
  field: jabilityintegerlevelfield;
@@ -34,6 +35,7 @@ export declare namespace UnitBonusType {
34
35
  const AUTO_ATTACK_DAMAGE: UnitBonusType<UnitAutoAttackDamageBonusId>;
35
36
  const DAMAGE_FACTOR: UnitBonusType<UnitReceivedDamageFactorBonusId>;
36
37
  const RECEIVED_DAMAGE_FACTOR: UnitBonusType<UnitReceivedDamageFactorBonusId>;
38
+ const EVASION_PROBABILITY: UnitBonusType<UnitEvasionProbabilityBonusId>;
37
39
  }
38
40
  export declare const addUnitBonus: <Id extends UnitBonusId>(unit: Unit, bonusType: UnitBonusType<Id>, value: number) => Id;
39
41
  export declare const removeUnitBonus: <Id extends UnitBonusId>(unit: Unit, bonusType: UnitBonusType<Id>, id: Id) => boolean;
@@ -21,8 +21,18 @@ local AUTO_ATTACK_DAMAGE_INCREASE_DUMMY_ABILITY_TYPE_ID = ____auto_2Dattack_2Dda
21
21
  local ____movement_2Dspeed_2Dincrease_2Dfactor = require("engine.internal.object-data.movement-speed-increase-factor")
22
22
  local MOVEMENT_SPEED_INCREASE_FACTOR_ABILITY_FIELD = ____movement_2Dspeed_2Dincrease_2Dfactor.MOVEMENT_SPEED_INCREASE_FACTOR_ABILITY_FIELD
23
23
  local MOVEMENT_SPEED_INCREASE_FACTOR_DUMMY_ABILITY_TYPE_ID = ____movement_2Dspeed_2Dincrease_2Dfactor.MOVEMENT_SPEED_INCREASE_FACTOR_DUMMY_ABILITY_TYPE_ID
24
+ local ____evasion_2Dprobability = require("engine.internal.object-data.evasion-probability")
25
+ local EVASION_PROBABILITY_ABILITY_FIELD = ____evasion_2Dprobability.EVASION_PROBABILITY_ABILITY_FIELD
26
+ local EVASION_PROBABILITY_DUMMY_ABILITY_TYPE_ID = ____evasion_2Dprobability.EVASION_PROBABILITY_DUMMY_ABILITY_TYPE_ID
24
27
  local damageFactorByUnit = {}
25
28
  local receivedDamageFactorByUnit = {}
29
+ local function atLeastOnceProbability(array)
30
+ local oppositeEventProbability = 1
31
+ for i = 1, #array do
32
+ oppositeEventProbability = oppositeEventProbability * (1 - array[i])
33
+ end
34
+ return 1 - oppositeEventProbability
35
+ end
26
36
  ____exports.UnitBonusType = {}
27
37
  local UnitBonusType = ____exports.UnitBonusType
28
38
  do
@@ -56,6 +66,13 @@ do
56
66
  }
57
67
  UnitBonusType.DAMAGE_FACTOR = {reduce = product, valueByUnit = damageFactorByUnit, initialValue = 1}
58
68
  UnitBonusType.RECEIVED_DAMAGE_FACTOR = {reduce = product, valueByUnit = receivedDamageFactorByUnit, initialValue = 1}
69
+ UnitBonusType.EVASION_PROBABILITY = {
70
+ abilityTypeId = EVASION_PROBABILITY_DUMMY_ABILITY_TYPE_ID,
71
+ field = EVASION_PROBABILITY_ABILITY_FIELD,
72
+ integer = false,
73
+ reduce = atLeastOnceProbability,
74
+ initialValue = 0
75
+ }
59
76
  end
60
77
  local bonusesByUnitByBonusType = {}
61
78
  local nextId = 1
@@ -0,0 +1,2 @@
1
+ /** @noSelfInFile */
2
+ export {};
@@ -0,0 +1,5 @@
1
+ local ____exports = {}
2
+ ---
3
+ -- @internal For use by internal systems only.
4
+ ____exports.ignoreEventsItems = {}
5
+ return ____exports
@@ -11,6 +11,7 @@ export interface UnitItems extends ReadonlyArray<Item | undefined> {
11
11
  }
12
12
  export declare class UnitItems {
13
13
  constructor(handle: junit);
14
+ findSlot(item: Item): 0 | 1 | 2 | 3 | 4 | 5 | undefined;
14
15
  protected __newindex(slot: number, item: Item | undefined): void;
15
16
  protected __index(key: string | number): unknown;
16
17
  protected __len(): number;
@@ -7,12 +7,14 @@ local ____item = require("engine.internal.item")
7
7
  local Item = ____item.Item
8
8
  local ____unit = require("engine.internal.unit")
9
9
  local Unit = ____unit.Unit
10
+ local ____utility = require("engine.internal.utility")
11
+ local findUnitItemSlot = ____utility.findUnitItemSlot
12
+ local ____add_2Ditem_2Dto_2Dslot = require("engine.internal.unit.add-item-to-slot")
13
+ local unitAddItemToSlot = ____add_2Ditem_2Dto_2Dslot.unitAddItemToSlot
10
14
  local rawset = _G.rawset
11
15
  local ____type = _G.type
12
16
  local isItemPowerup = IsItemPowerup
13
17
  local setItemBooleanField = BlzSetItemBooleanField
14
- local unitAddItem = UnitAddItem
15
- local unitDropItemSlot = UnitDropItemSlot
16
18
  local unitInventorySize = UnitInventorySize
17
19
  local unitItemInSlot = UnitItemInSlot
18
20
  local unitRemoveItemFromSlot = UnitRemoveItemFromSlot
@@ -30,6 +32,9 @@ UnitItems.name = "UnitItems"
30
32
  function UnitItems.prototype.____constructor(self, handle)
31
33
  handleByUnitItems[self] = handle
32
34
  end
35
+ function UnitItems.prototype.findSlot(self, item)
36
+ return findUnitItemSlot(handleByUnitItems[self], item.handle)
37
+ end
33
38
  function UnitItems.prototype.__newindex(self, slot, item)
34
39
  local handle = handleByUnitItems[self]
35
40
  if slot < 1 or slot > unitInventorySize(handle) then
@@ -42,8 +47,7 @@ function UnitItems.prototype.__newindex(self, slot, item)
42
47
  if isPowerup then
43
48
  setItemBooleanField(itemHandle, ITEM_BF_USE_AUTOMATICALLY_WHEN_ACQUIRED, false)
44
49
  end
45
- unitAddItem(handle, itemHandle)
46
- unitDropItemSlot(handle, itemHandle, slot - 1)
50
+ unitAddItemToSlot(handle, itemHandle, slot - 1)
47
51
  if isPowerup then
48
52
  setItemBooleanField(itemHandle, ITEM_BF_USE_AUTOMATICALLY_WHEN_ACQUIRED, true)
49
53
  end
@@ -0,0 +1,13 @@
1
+ /** @noSelfInFile */
2
+ import { Player } from "../../../core/types/player";
3
+ import { Event } from "../../../event";
4
+ declare module "../unit" {
5
+ namespace Unit {
6
+ const mainSelectedUnitChangeEvent: Event<[Player]>;
7
+ }
8
+ }
9
+ declare module "../unit" {
10
+ namespace Unit {
11
+ const getMainSelectedOf: (player: Player) => Unit | undefined;
12
+ }
13
+ }