warscript 0.0.1-dev.240d8a6 → 0.0.1-dev.273b8f3

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 (101) hide show
  1. package/config.d.ts +5 -0
  2. package/config.lua +10 -0
  3. package/core/types/effect.d.ts +13 -3
  4. package/core/types/effect.lua +116 -17
  5. package/core/types/sound.d.ts +1 -0
  6. package/core/types/sound.lua +36 -2
  7. package/core/util.d.ts +1 -1
  8. package/core/util.lua +6 -0
  9. package/engine/behaviour/ability/always-enabled.d.ts +7 -0
  10. package/engine/behaviour/ability/always-enabled.lua +31 -0
  11. package/engine/behaviour/ability/apply-buff.d.ts +5 -0
  12. package/engine/behaviour/ability/apply-buff.lua +32 -0
  13. package/engine/behaviour/ability/emulate-impact.d.ts +6 -0
  14. package/engine/behaviour/ability/emulate-impact.lua +28 -0
  15. package/engine/behaviour/ability/instant-impact.d.ts +2 -2
  16. package/engine/behaviour/ability/instant-impact.lua +4 -19
  17. package/engine/behaviour/ability/on-command-impact.d.ts +8 -0
  18. package/engine/behaviour/ability/on-command-impact.lua +25 -0
  19. package/engine/behaviour/ability/remove-buffs.d.ts +16 -0
  20. package/engine/behaviour/ability/remove-buffs.lua +28 -0
  21. package/engine/behaviour/ability.d.ts +15 -3
  22. package/engine/behaviour/ability.lua +93 -34
  23. package/engine/buff.d.ts +56 -41
  24. package/engine/buff.lua +278 -231
  25. package/engine/internal/ability.d.ts +13 -2
  26. package/engine/internal/ability.lua +77 -4
  27. package/engine/internal/item/ability.lua +106 -0
  28. package/engine/internal/item.d.ts +2 -2
  29. package/engine/internal/item.lua +56 -25
  30. package/engine/internal/misc/ability-disable-counter.d.ts +2 -0
  31. package/engine/internal/misc/ability-disable-counter.lua +13 -0
  32. package/engine/internal/object-data/auto-attack-speed-increase.d.ts +1 -1
  33. package/engine/internal/object-data/auto-attack-speed-increase.lua +2 -0
  34. package/engine/internal/object-data/evasion-probability.d.ts +2 -0
  35. package/engine/internal/object-data/evasion-probability.lua +16 -0
  36. package/engine/internal/unit/ability.d.ts +10 -1
  37. package/engine/internal/unit/ability.lua +36 -14
  38. package/engine/internal/unit/add-item-to-slot-init.d.ts +2 -0
  39. package/engine/internal/unit/add-item-to-slot-init.lua +23 -0
  40. package/engine/internal/unit/add-item-to-slot.d.ts +2 -0
  41. package/engine/internal/unit/add-item-to-slot.lua +52 -0
  42. package/engine/internal/unit/bonus.d.ts +2 -0
  43. package/engine/internal/unit/bonus.lua +17 -0
  44. package/engine/internal/unit/ignore-events-items.d.ts +2 -0
  45. package/engine/internal/unit/ignore-events-items.lua +5 -0
  46. package/engine/internal/unit/item.d.ts +1 -1
  47. package/engine/internal/unit/item.lua +6 -12
  48. package/engine/internal/unit/main-selected.d.ts +6 -0
  49. package/engine/internal/unit/main-selected.lua +12 -1
  50. package/engine/internal/unit.d.ts +5 -3
  51. package/engine/internal/unit.lua +76 -41
  52. package/engine/internal/utility.lua +12 -0
  53. package/engine/lightning.d.ts +12 -5
  54. package/engine/lightning.lua +48 -14
  55. package/engine/object-data/auxiliary/animation-name.d.ts +1 -0
  56. package/engine/object-data/auxiliary/animation-name.lua +16 -0
  57. package/engine/object-data/auxiliary/sound-preset-name.d.ts +5 -1
  58. package/engine/object-data/auxiliary/tech-tree-dependency.d.ts +1 -1
  59. package/engine/object-data/entry/ability-type/blank-configurable.lua +12 -1
  60. package/engine/object-data/entry/ability-type/curse.lua +2 -2
  61. package/engine/object-data/entry/ability-type/disease-cloud.lua +2 -2
  62. package/engine/object-data/entry/ability-type/engineering-upgrade.lua +2 -2
  63. package/engine/object-data/entry/ability-type/feral-spirit.lua +2 -2
  64. package/engine/object-data/entry/ability-type/phoenix-morph.lua +4 -4
  65. package/engine/object-data/entry/ability-type/summon-quilbeast.lua +2 -2
  66. package/engine/object-data/entry/ability-type/summon-water-elemental.lua +2 -2
  67. package/engine/object-data/entry/ability-type.d.ts +8 -6
  68. package/engine/object-data/entry/ability-type.lua +62 -27
  69. package/engine/object-data/entry/buff-type/applicable.lua +13 -37
  70. package/engine/object-data/entry/buff-type.d.ts +1 -1
  71. package/engine/object-data/entry/buff-type.lua +2 -2
  72. package/engine/object-data/entry/destructible-type.d.ts +1 -1
  73. package/engine/object-data/entry/item-type.d.ts +3 -1
  74. package/engine/object-data/entry/item-type.lua +15 -2
  75. package/engine/object-data/entry/lightning-type.d.ts +1 -1
  76. package/engine/object-data/entry/sound-preset.d.ts +16 -0
  77. package/engine/object-data/entry/sound-preset.lua +36 -0
  78. package/engine/object-data/entry/unit-type.d.ts +8 -1
  79. package/engine/object-data/entry/unit-type.lua +61 -8
  80. package/engine/object-data/entry/upgrade.d.ts +1 -1
  81. package/engine/object-data/entry/upgrade.lua +4 -4
  82. package/engine/object-data/entry.d.ts +16 -14
  83. package/engine/object-data/entry.lua +60 -32
  84. package/engine/object-data/utility/object-data-entry-id-generator.lua +7 -0
  85. package/engine/object-field/ability.d.ts +9 -3
  86. package/engine/object-field/ability.lua +3 -0
  87. package/engine/object-field.d.ts +2 -2
  88. package/engine/object-field.lua +4 -0
  89. package/engine/standard/entries/sound-preset.d.ts +10 -0
  90. package/engine/standard/entries/sound-preset.lua +10 -0
  91. package/engine/standard/fields/ability.d.ts +2 -0
  92. package/engine/standard/fields/ability.lua +2 -0
  93. package/engine/unit.d.ts +1 -0
  94. package/engine/unit.lua +1 -0
  95. package/objutil/unit.lua +8 -0
  96. package/package.json +2 -2
  97. package/utility/arrays.d.ts +8 -1
  98. package/utility/arrays.lua +34 -3
  99. package/utility/lazy.d.ts +2 -0
  100. package/utility/lazy.lua +14 -0
  101. package/utility/reflection.lua +11 -7
@@ -0,0 +1,52 @@
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
+ ---
13
+ -- @internal For use by internal systems only.
14
+ ____exports.SLOT_FILLER_ITEM_TYPE_ID = compiletime(function()
15
+ local itemType = BlankItemType:create()
16
+ itemType.name = "[Warscript/Dummy] Slot Filler"
17
+ return itemType.id
18
+ end)
19
+ ---
20
+ -- @internal For use by internal systems only.
21
+ ____exports.fillerItems = array(
22
+ 6,
23
+ function()
24
+ local item = CreateItem(____exports.SLOT_FILLER_ITEM_TYPE_ID, 0, 0)
25
+ setItemVisible(item, false)
26
+ ignoreEventsItems[item] = true
27
+ return item
28
+ end
29
+ )
30
+ ---
31
+ -- @internal For use by internal systems only.
32
+ ____exports.unitsWithFillerItems = {}
33
+ ---
34
+ -- @internal For use by internal systems only.
35
+ ____exports.unitAddItemToSlot = function(unit, item, slot)
36
+ for previousSlot = 0, slot - 1 do
37
+ if unitItemInSlot(unit, previousSlot) == nil then
38
+ unitAddItem(unit, ____exports.fillerItems[previousSlot + 1])
39
+ ____exports.unitsWithFillerItems[unit] = true
40
+ end
41
+ end
42
+ unitAddItem(unit, item)
43
+ if ____exports.unitsWithFillerItems[unit] ~= nil then
44
+ for previousSlot = 0, slot - 1 do
45
+ local fillerItem = ____exports.fillerItems[previousSlot + 1]
46
+ unitRemoveItem(unit, fillerItem)
47
+ setItemVisible(fillerItem, false)
48
+ end
49
+ ____exports.unitsWithFillerItems[unit] = nil
50
+ end
51
+ end
52
+ 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,7 +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): number | undefined;
14
+ findSlot(item: Item): 0 | 1 | 2 | 3 | 4 | 5 | undefined;
15
15
  protected __newindex(slot: number, item: Item | undefined): void;
16
16
  protected __index(key: string | number): unknown;
17
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
@@ -31,14 +33,7 @@ function UnitItems.prototype.____constructor(self, handle)
31
33
  handleByUnitItems[self] = handle
32
34
  end
33
35
  function UnitItems.prototype.findSlot(self, item)
34
- local handle = handleByUnitItems[self]
35
- local itemHandle = item.handle
36
- for slot = 0, unitInventorySize(handle) - 1 do
37
- if itemHandle == unitItemInSlot(handle, slot) then
38
- return slot
39
- end
40
- end
41
- return nil
36
+ return findUnitItemSlot(handleByUnitItems[self], item.handle)
42
37
  end
43
38
  function UnitItems.prototype.__newindex(self, slot, item)
44
39
  local handle = handleByUnitItems[self]
@@ -52,8 +47,7 @@ function UnitItems.prototype.__newindex(self, slot, item)
52
47
  if isPowerup then
53
48
  setItemBooleanField(itemHandle, ITEM_BF_USE_AUTOMATICALLY_WHEN_ACQUIRED, false)
54
49
  end
55
- unitAddItem(handle, itemHandle)
56
- unitDropItemSlot(handle, itemHandle, slot - 1)
50
+ unitAddItemToSlot(handle, itemHandle, slot - 1)
57
51
  if isPowerup then
58
52
  setItemBooleanField(itemHandle, ITEM_BF_USE_AUTOMATICALLY_WHEN_ACQUIRED, true)
59
53
  end
@@ -1,5 +1,11 @@
1
1
  /** @noSelfInFile */
2
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
+ }
3
9
  declare module "../unit" {
4
10
  namespace Unit {
5
11
  const getMainSelectedOf: (player: Player) => Unit | undefined;
@@ -1,3 +1,5 @@
1
+ local ____lualib = require("lualib_bundle")
2
+ local __TS__New = ____lualib.__TS__New
1
3
  local ____exports = {}
2
4
  local ____player = require("core.types.player")
3
5
  local Player = ____player.Player
@@ -8,6 +10,10 @@ local ____local_2Dclient = require("engine.local-client")
8
10
  local LocalClient = ____local_2Dclient.LocalClient
9
11
  local ____unit = require("engine.internal.unit")
10
12
  local Unit = ____unit.Unit
13
+ local ____event = require("event")
14
+ local Event = ____event.Event
15
+ local mainSelectedUnitChangeEvent = __TS__New(Event)
16
+ rawset(Unit, "mainSelectedUnitChangeEvent", mainSelectedUnitChangeEvent)
11
17
  local mainSelectedUnitByPlayer = {}
12
18
  local syncSlider = BlzCreateFrameByType(
13
19
  "SLIDER",
@@ -27,7 +33,12 @@ BlzTriggerRegisterFrameEvent(trg, syncSlider, FRAMEEVENT_SLIDER_VALUE_CHANGED)
27
33
  TriggerAddAction(
28
34
  trg,
29
35
  function()
30
- mainSelectedUnitByPlayer[Player:of(GetTriggerPlayer())] = Unit:getBySyncId(BlzGetTriggerFrameValue())
36
+ local player = Player:of(GetTriggerPlayer())
37
+ local mainSelectedUnit = Unit:getBySyncId(BlzGetTriggerFrameValue())
38
+ if mainSelectedUnit ~= mainSelectedUnitByPlayer[player] then
39
+ mainSelectedUnitByPlayer[player] = mainSelectedUnit
40
+ Event.invoke(mainSelectedUnitChangeEvent, player)
41
+ end
31
42
  end
32
43
  )
33
44
  rawset(
@@ -133,6 +133,7 @@ export declare class Unit extends Handle<junit> {
133
133
  get isAlive(): boolean;
134
134
  get isDead(): boolean;
135
135
  get isIllusion(): boolean;
136
+ get isStunned(): boolean;
136
137
  get combatClassifications(): CombatClassifications;
137
138
  set combatClassifications(combatClassifications: CombatClassifications);
138
139
  hasCombatClassification(combatClassification: CombatClassification): boolean;
@@ -332,11 +333,12 @@ export declare class Unit extends Handle<junit> {
332
333
  static itemPickedUpEvent: UnitTriggerEvent<[Item]>;
333
334
  static itemUsedEvent: UnitTriggerEvent<[Item]>;
334
335
  static itemStackedEvent: UnitTriggerEvent<[Item]>;
335
- static get itemMovedEvent(): Event<[
336
+ static get itemUseOrderEvent(): Event<[unit: Unit, item: Item]>;
337
+ static get itemMoveOrderEvent(): Event<[
336
338
  unit: Unit,
337
339
  item: Item,
338
- slotFrom: number,
339
- slotTo: number
340
+ slotFrom: 0 | 1 | 2 | 3 | 4 | 5,
341
+ slotTo: 0 | 1 | 2 | 3 | 4 | 5
340
342
  ]>;
341
343
  static get onCreate(): EventDispatcher<[Unit], [Unit]>;
342
344
  static get destroyEvent(): EventDispatcher<[Unit], [Unit]>;
@@ -51,6 +51,8 @@ local ____arrays = require("utility.arrays")
51
51
  local forEach = ____arrays.forEach
52
52
  local ____math = require("math")
53
53
  local min = ____math.min
54
+ local ____ignore_2Devents_2Ditems = require("engine.internal.unit.ignore-events-items")
55
+ local ignoreEventsItems = ____ignore_2Devents_2Ditems.ignoreEventsItems
54
56
  local match = string.match
55
57
  local ____tostring = _G.tostring
56
58
  local setUnitAnimation = SetUnitAnimation
@@ -75,6 +77,7 @@ local setUnitScale = SetUnitScale
75
77
  local setUnitPosition = SetUnitPosition
76
78
  local setUnitTimeScale = SetUnitTimeScale
77
79
  local getHandleId = GetHandleId
80
+ local getUnitCurrentOrder = GetUnitCurrentOrder
78
81
  local createUnit = CreateUnit
79
82
  local killUnit = KillUnit
80
83
  local setUnitExploded = SetUnitExploded
@@ -562,17 +565,6 @@ local function retrieveAbility(unit, ability, abilityId)
562
565
  ____exports.Unit:of(unit)
563
566
  )
564
567
  end
565
- if not unitAddAbility(unit, abilityId) then
566
- if getUnitAbility(unit, abilityId) == ability then
567
- return UnitAbility:of(
568
- ability,
569
- abilityId,
570
- ____exports.Unit:of(unit)
571
- )
572
- end
573
- else
574
- unitRemoveAbility(unit, abilityId)
575
- end
576
568
  for i = 0, unitInventorySize(unit) - 1 do
577
569
  local item = unitItemInSlot(unit, i)
578
570
  if getItemAbility(item, abilityId) == ability then
@@ -940,8 +932,15 @@ function Unit.prototype.interruptAttack(self)
940
932
  unitInterruptAttack(self.handle)
941
933
  end
942
934
  function Unit.prototype.interruptCast(self, abilityId)
943
- unitDisableAbility(self.handle, abilityId, true, false)
944
- unitDisableAbility(self.handle, abilityId, false, false)
935
+ local handle = self.handle
936
+ unitDisableAbility(handle, abilityId, true, false)
937
+ Timer:run(
938
+ unitDisableAbility,
939
+ handle,
940
+ abilityId,
941
+ false,
942
+ false
943
+ )
945
944
  end
946
945
  function Unit.prototype.getDistanceTo(self, target)
947
946
  local handle = self.handle
@@ -1206,6 +1205,14 @@ __TS__SetDescriptor(
1206
1205
  end},
1207
1206
  true
1208
1207
  )
1208
+ __TS__SetDescriptor(
1209
+ Unit.prototype,
1210
+ "isStunned",
1211
+ {get = function(self)
1212
+ return getUnitCurrentOrder(self.handle) == orderId("stunned")
1213
+ end},
1214
+ true
1215
+ )
1209
1216
  __TS__SetDescriptor(
1210
1217
  Unit.prototype,
1211
1218
  "combatClassifications",
@@ -2326,10 +2333,12 @@ Unit.onImmediateOrder = dispatchId(__TS__New(
2326
2333
  ____exports.UnitTriggerEvent,
2327
2334
  EVENT_PLAYER_UNIT_ISSUED_ORDER,
2328
2335
  function()
2329
- local unit = ____exports.Unit:of(getOrderedUnit())
2330
- local issuedOrderId = getIssuedOrderId()
2331
- if unit ~= nil and unit.state == 1 then
2332
- return unit, issuedOrderId
2336
+ local handle = getOrderedUnit()
2337
+ if handle ~= nil and getUnitTypeId(handle) ~= dummyUnitId then
2338
+ local unit = ____exports.Unit:of(handle)
2339
+ if unit.state == 1 then
2340
+ return unit, getIssuedOrderId()
2341
+ end
2333
2342
  end
2334
2343
  return IgnoreEvent
2335
2344
  end
@@ -2520,8 +2529,9 @@ Unit.itemDroppedEvent = __TS__New(
2520
2529
  EVENT_PLAYER_UNIT_DROP_ITEM,
2521
2530
  function()
2522
2531
  local unit = getTriggerUnit()
2523
- if getUnitTypeId(unit) ~= dummyUnitId then
2524
- return ____exports.Unit:of(unit), Item:of(getManipulatedItem())
2532
+ local item = getManipulatedItem()
2533
+ if getUnitTypeId(unit) ~= dummyUnitId and not (ignoreEventsItems[item] ~= nil) then
2534
+ return ____exports.Unit:of(unit), Item:of(item)
2525
2535
  end
2526
2536
  return IgnoreEvent
2527
2537
  end
@@ -2531,8 +2541,9 @@ Unit.itemPickedUpEvent = __TS__New(
2531
2541
  EVENT_PLAYER_UNIT_PICKUP_ITEM,
2532
2542
  function()
2533
2543
  local unit = getTriggerUnit()
2534
- if getUnitTypeId(unit) ~= dummyUnitId then
2535
- return ____exports.Unit:of(unit), Item:of(getManipulatedItem())
2544
+ local item = getManipulatedItem()
2545
+ if getUnitTypeId(unit) ~= dummyUnitId and not (ignoreEventsItems[item] ~= nil) then
2546
+ return ____exports.Unit:of(unit), Item:of(item)
2536
2547
  end
2537
2548
  return IgnoreEvent
2538
2549
  end
@@ -2540,7 +2551,14 @@ Unit.itemPickedUpEvent = __TS__New(
2540
2551
  Unit.itemUsedEvent = __TS__New(
2541
2552
  ____exports.UnitTriggerEvent,
2542
2553
  EVENT_PLAYER_UNIT_USE_ITEM,
2543
- function() return ____exports.Unit:of(getTriggerUnit()), Item:of(getManipulatedItem()) end
2554
+ function()
2555
+ local unit = getTriggerUnit()
2556
+ local item = getManipulatedItem()
2557
+ if getUnitTypeId(unit) ~= dummyUnitId and not (ignoreEventsItems[item] ~= nil) then
2558
+ return ____exports.Unit:of(unit), Item:of(item)
2559
+ end
2560
+ return IgnoreEvent
2561
+ end
2544
2562
  )
2545
2563
  Unit.itemStackedEvent = __TS__New(
2546
2564
  ____exports.UnitTriggerEvent,
@@ -2549,29 +2567,46 @@ Unit.itemStackedEvent = __TS__New(
2549
2567
  )
2550
2568
  __TS__ObjectDefineProperty(
2551
2569
  Unit,
2552
- "itemMovedEvent",
2570
+ "itemUseOrderEvent",
2553
2571
  {get = function(self)
2554
2572
  local event = __TS__New(Event)
2555
- do
2556
- local order = orderId("moveslot1")
2557
- while order <= orderId("moveslot5") do
2558
- self.onTargetOrder[order]:addListener(function(unit, item)
2559
- local slotFrom = unit.items:findSlot(item)
2560
- if slotFrom ~= nil then
2561
- local slotTo = order - orderId("moveslot1")
2562
- invoke(
2563
- event,
2564
- unit,
2565
- item,
2566
- slotFrom,
2567
- slotTo
2568
- )
2569
- end
2570
- end)
2571
- order = order + 1
2573
+ for order = orderId("useslot0"), orderId("useslot5") do
2574
+ local slot = order - orderId("useslot0")
2575
+ local function listener(unit)
2576
+ local item = unit.items[slot + 1]
2577
+ if item ~= nil then
2578
+ invoke(event, unit, item)
2579
+ end
2572
2580
  end
2581
+ self.onImmediateOrder[order]:addListener(listener)
2582
+ self.onTargetOrder[order]:addListener(listener)
2583
+ self.onPointOrder[order]:addListener(listener)
2584
+ end
2585
+ rawset(self, "itemUseOrderEvent", event)
2586
+ return event
2587
+ end}
2588
+ )
2589
+ __TS__ObjectDefineProperty(
2590
+ Unit,
2591
+ "itemMoveOrderEvent",
2592
+ {get = function(self)
2593
+ local event = __TS__New(Event)
2594
+ for order = orderId("moveslot0"), orderId("moveslot5") do
2595
+ local slotTo = order - orderId("moveslot0")
2596
+ self.onTargetOrder[order]:addListener(function(unit, item)
2597
+ local slotFrom = unit.items:findSlot(item)
2598
+ if slotFrom ~= nil then
2599
+ invoke(
2600
+ event,
2601
+ unit,
2602
+ item,
2603
+ slotFrom,
2604
+ slotTo
2605
+ )
2606
+ end
2607
+ end)
2573
2608
  end
2574
- rawset(self, "itemMovedEvent", event)
2609
+ rawset(self, "itemMoveOrderEvent", event)
2575
2610
  return event
2576
2611
  end}
2577
2612
  )
@@ -1,6 +1,8 @@
1
1
  local ____exports = {}
2
2
  local getUnitAbility = BlzGetUnitAbility
3
3
  local unitAddAbility = UnitAddAbility
4
+ local unitInventorySize = UnitInventorySize
5
+ local unitItemInSlot = UnitItemInSlot
4
6
  local unitMakeAbilityPermanent = UnitMakeAbilityPermanent
5
7
  ---
6
8
  -- @internal For use by internal systems only.
@@ -10,4 +12,14 @@ ____exports.addInternalAbility = function(unit, abilityTypeId)
10
12
  end
11
13
  return getUnitAbility(unit, abilityTypeId)
12
14
  end
15
+ ---
16
+ -- @internal For use by internal systems only.
17
+ ____exports.findUnitItemSlot = function(unit, item)
18
+ for slot = 0, unitInventorySize(unit) - 1 do
19
+ if item == unitItemInSlot(unit, slot) then
20
+ return slot
21
+ end
22
+ end
23
+ return nil
24
+ end
13
25
  return ____exports
@@ -1,7 +1,7 @@
1
1
  /** @noSelfInFile */
2
2
  import { LightningTypeId } from "./object-data/entry/lightning-type";
3
- import { Handle, HandleDestructor } from "../core/types/handle";
4
3
  import { Unit } from "../core/types/unit";
4
+ import { AbstractDestroyable, Destructor } from "../destroyable";
5
5
  declare const enum LightningPropertyKey {
6
6
  CHECK_VISIBILITY = 100,
7
7
  SOURCE_UNIT = 101,
@@ -12,10 +12,12 @@ declare const enum LightningPropertyKey {
12
12
  TARGET_X = 106,
13
13
  TARGET_Y = 107,
14
14
  TARGET_Z = 108,
15
- DURATION = 109
15
+ DURATION = 109,
16
+ FADING = 110
16
17
  }
17
18
  export type LightningConstructor<T extends Lightning> = typeof Lightning & (new (handle: jlightning, typeId: LightningTypeId) => T);
18
- export declare class Lightning extends Handle<jlightning> {
19
+ export declare class Lightning extends AbstractDestroyable {
20
+ readonly handle: jlightning;
19
21
  readonly typeId: LightningTypeId;
20
22
  private [LightningPropertyKey.CHECK_VISIBILITY]?;
21
23
  private [LightningPropertyKey.SOURCE_UNIT]?;
@@ -27,8 +29,9 @@ export declare class Lightning extends Handle<jlightning> {
27
29
  private [LightningPropertyKey.TARGET_Y]?;
28
30
  private [LightningPropertyKey.TARGET_Z]?;
29
31
  private [LightningPropertyKey.DURATION]?;
32
+ private [LightningPropertyKey.FADING]?;
30
33
  constructor(handle: jlightning, typeId: LightningTypeId);
31
- protected onDestroy(): HandleDestructor;
34
+ protected onDestroy(): Destructor;
32
35
  static create<T extends Lightning>(this: LightningConstructor<T>, typeId: LightningTypeId, ...parameters: [
33
36
  ...checkVisibility: [boolean] | [],
34
37
  ...sourceAndTarget: [sourceX: number, sourceY: number, targetX: number, targetY: number] | [
@@ -46,6 +49,10 @@ export declare class Lightning extends Handle<jlightning> {
46
49
  target: Unit
47
50
  ]
48
51
  ]): T;
49
- static flash(...parameters: [...parameters: Parameters<(typeof Lightning)["create"]>, duration: number]): void;
52
+ static flash(...parameters: [
53
+ ...parameters: Parameters<(typeof Lightning)["create"]>,
54
+ duration: number,
55
+ fading?: boolean
56
+ ]): void;
50
57
  }
51
58
  export {};
@@ -1,15 +1,16 @@
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 ____exports = {}
5
- local ____handle = require("core.types.handle")
6
- local Handle = ____handle.Handle
7
6
  local ____timer = require("core.types.timer")
8
7
  local Timer = ____timer.Timer
9
8
  local ____functions = require("utility.functions")
10
9
  local forwardByN = ____functions.forwardByN
11
10
  local ____unit_2Dmissile_2Ddata = require("engine.internal.unit-missile-data")
12
11
  local MISSILE_DATA_BY_UNIT_TYPE_ID = ____unit_2Dmissile_2Ddata.MISSILE_DATA_BY_UNIT_TYPE_ID
12
+ local ____destroyable = require("destroyable")
13
+ local AbstractDestroyable = ____destroyable.AbstractDestroyable
13
14
  local ____type = _G.type
14
15
  local select = _G.select
15
16
  local cos = math.cos
@@ -27,6 +28,11 @@ local getUnitZ = BlzGetUnitZ
27
28
  local getUnitFlyHeight = GetUnitFlyHeight
28
29
  local getLocationZ = GetLocationZ
29
30
  local moveLocation = MoveLocation
31
+ local getLightningColorA = GetLightningColorA
32
+ local getLightningColorR = GetLightningColorR
33
+ local getLightningColorG = GetLightningColorG
34
+ local getLightningColorB = GetLightningColorB
35
+ local setLightningColor = SetLightningColor
30
36
  local location = Location(0, 0)
31
37
  local unitToUnitLightnings = setmetatable({}, {__mode = "k"})
32
38
  local unitToPointLightnings = setmetatable({}, {__mode = "k"})
@@ -36,9 +42,10 @@ local temporaryLightningsCount = 0
36
42
  ____exports.Lightning = __TS__Class()
37
43
  local Lightning = ____exports.Lightning
38
44
  Lightning.name = "Lightning"
39
- __TS__ClassExtends(Lightning, Handle)
45
+ __TS__ClassExtends(Lightning, AbstractDestroyable)
40
46
  function Lightning.prototype.____constructor(self, handle, typeId)
41
- Handle.prototype.____constructor(self, handle)
47
+ AbstractDestroyable.prototype.____constructor(self)
48
+ self.handle = handle
42
49
  self.typeId = typeId
43
50
  end
44
51
  function Lightning.prototype.onDestroy(self)
@@ -46,7 +53,7 @@ function Lightning.prototype.onDestroy(self)
46
53
  unitToPointLightnings[self] = nil
47
54
  pointToUnitLightnings[self] = nil
48
55
  destroyLightning(self.handle)
49
- return Handle.prototype.onDestroy(self)
56
+ return AbstractDestroyable.prototype.onDestroy(self)
50
57
  end
51
58
  function Lightning.create(self, typeId, checkVisibility, sourceXOrSourceUnit, sourceYOrTargetXOrTargetUnit, sourceZOrTargetXOrTargetUnitOrTargetY, targetXOrTargetUnitOrTargetYOrTargetZ, targetY, targetZ)
52
59
  if type(checkVisibility) ~= "boolean" then
@@ -62,7 +69,8 @@ function Lightning.create(self, typeId, checkVisibility, sourceXOrSourceUnit, so
62
69
  )
63
70
  end
64
71
  if targetZ ~= nil then
65
- return self:of(
72
+ return __TS__New(
73
+ self,
66
74
  addLightningEx(
67
75
  util.id2s(typeId),
68
76
  checkVisibility,
@@ -79,7 +87,8 @@ function Lightning.create(self, typeId, checkVisibility, sourceXOrSourceUnit, so
79
87
  if targetXOrTargetUnitOrTargetYOrTargetZ ~= nil then
80
88
  if ____type(targetXOrTargetUnitOrTargetYOrTargetZ) == "number" then
81
89
  if ____type(sourceXOrSourceUnit) == "number" then
82
- return self:of(
90
+ return __TS__New(
91
+ self,
83
92
  addLightning(
84
93
  util.id2s(typeId),
85
94
  checkVisibility,
@@ -92,7 +101,8 @@ function Lightning.create(self, typeId, checkVisibility, sourceXOrSourceUnit, so
92
101
  )
93
102
  end
94
103
  local unit = sourceXOrSourceUnit.handle
95
- local lightning = self:of(
104
+ local lightning = __TS__New(
105
+ self,
96
106
  addLightningEx(
97
107
  util.id2s(typeId),
98
108
  checkVisibility,
@@ -117,7 +127,8 @@ function Lightning.create(self, typeId, checkVisibility, sourceXOrSourceUnit, so
117
127
  return lightning
118
128
  end
119
129
  local unit = targetXOrTargetUnitOrTargetYOrTargetZ.handle
120
- local lightning = self:of(
130
+ local lightning = __TS__New(
131
+ self,
121
132
  addLightningEx(
122
133
  util.id2s(typeId),
123
134
  checkVisibility,
@@ -146,7 +157,8 @@ function Lightning.create(self, typeId, checkVisibility, sourceXOrSourceUnit, so
146
157
  local unit = sourceXOrSourceUnit.handle
147
158
  moveLocation(location, sourceYOrTargetXOrTargetUnit, sourceZOrTargetXOrTargetUnitOrTargetY)
148
159
  local z = getLocationZ(location)
149
- local lightning = self:of(
160
+ local lightning = __TS__New(
161
+ self,
150
162
  addLightningEx(
151
163
  util.id2s(typeId),
152
164
  checkVisibility,
@@ -173,7 +185,8 @@ function Lightning.create(self, typeId, checkVisibility, sourceXOrSourceUnit, so
173
185
  local unit = sourceZOrTargetXOrTargetUnitOrTargetY.handle
174
186
  moveLocation(location, sourceXOrSourceUnit, sourceYOrTargetXOrTargetUnit)
175
187
  local z = getLocationZ(location)
176
- local lightning = self:of(
188
+ local lightning = __TS__New(
189
+ self,
177
190
  addLightningEx(
178
191
  util.id2s(typeId),
179
192
  checkVisibility,
@@ -199,7 +212,8 @@ function Lightning.create(self, typeId, checkVisibility, sourceXOrSourceUnit, so
199
212
  end
200
213
  local sourceUnit = sourceXOrSourceUnit.handle
201
214
  local targetUnit = sourceYOrTargetXOrTargetUnit.handle
202
- local lightning = self:of(
215
+ local lightning = __TS__New(
216
+ self,
203
217
  addLightningEx(
204
218
  util.id2s(typeId),
205
219
  checkVisibility,
@@ -225,9 +239,19 @@ function Lightning.create(self, typeId, checkVisibility, sourceXOrSourceUnit, so
225
239
  return lightning
226
240
  end
227
241
  function Lightning.flash(self, ...)
228
- local parametersToForwardCount = select("#", ...) - 1
242
+ local parameterOrDuration, durationOrFading = select(-2, ...)
243
+ local hasFading = ____type(durationOrFading) ~= "number"
244
+ local parametersToForwardCount = select("#", ...) - (hasFading and 2 or 1)
229
245
  local lightning = forwardByN[parametersToForwardCount](____exports.Lightning.create, self, ...)
230
- local duration = select(-1, ...)
246
+ local duration
247
+ if hasFading then
248
+ duration = parameterOrDuration
249
+ if durationOrFading then
250
+ lightning[110] = true
251
+ end
252
+ else
253
+ duration = durationOrFading
254
+ end
231
255
  lightning[109] = duration
232
256
  temporaryLightningsCount = temporaryLightningsCount + 1
233
257
  temporaryLightnings[temporaryLightningsCount] = lightning
@@ -295,6 +319,16 @@ Timer.onPeriod[UPDATE_PERIOD]:addListener(function()
295
319
  temporaryLightnings[temporaryLightningsCount] = nil
296
320
  temporaryLightningsCount = temporaryLightningsCount - 1
297
321
  else
322
+ if lightning[110] then
323
+ local handle = lightning.handle
324
+ setLightningColor(
325
+ handle,
326
+ getLightningColorR(handle),
327
+ getLightningColorG(handle),
328
+ getLightningColorB(handle),
329
+ getLightningColorA(handle) * (1 - UPDATE_PERIOD / duration)
330
+ )
331
+ end
298
332
  lightning[109] = duration - UPDATE_PERIOD
299
333
  i = i + 1
300
334
  end
@@ -12,3 +12,4 @@ export declare const enum AnimationName {
12
12
  STAND = "stand",
13
13
  WALK = "walk"
14
14
  }
15
+ export declare const isAnimationName: (value: string) => value is AnimationName;