warscript 0.0.1-dev.c1eba7d → 0.0.1-dev.c362181

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 (74) hide show
  1. package/config.d.ts +5 -0
  2. package/config.lua +10 -0
  3. package/core/types/sound.d.ts +17 -24
  4. package/core/types/sound.lua +94 -24
  5. package/core/util.lua +6 -1
  6. package/engine/behaviour/ability/apply-buff.d.ts +5 -0
  7. package/engine/behaviour/ability/apply-buff.lua +32 -0
  8. package/engine/behaviour/ability/apply-unit-behavior.lua +1 -0
  9. package/engine/behaviour/ability/damage.d.ts +3 -0
  10. package/engine/behaviour/ability/damage.lua +2 -2
  11. package/engine/behaviour/ability.d.ts +3 -1
  12. package/engine/behaviour/ability.lua +28 -3
  13. package/engine/behaviour/unit.d.ts +2 -0
  14. package/engine/buff.d.ts +56 -41
  15. package/engine/buff.lua +295 -228
  16. package/engine/internal/ability.lua +0 -2
  17. package/engine/internal/item/ability.lua +3 -3
  18. package/engine/internal/item.d.ts +2 -2
  19. package/engine/internal/item.lua +56 -25
  20. package/engine/internal/object-data/auto-attack-speed-increase.d.ts +1 -1
  21. package/engine/internal/object-data/auto-attack-speed-increase.lua +2 -0
  22. package/engine/internal/object-data/evasion-probability.d.ts +2 -0
  23. package/engine/internal/object-data/evasion-probability.lua +16 -0
  24. package/engine/internal/unit/add-item-to-slot-init.d.ts +2 -0
  25. package/engine/internal/unit/add-item-to-slot-init.lua +23 -0
  26. package/engine/internal/unit/add-item-to-slot.d.ts +2 -0
  27. package/engine/internal/unit/add-item-to-slot.lua +52 -0
  28. package/engine/internal/unit/bonus.d.ts +2 -0
  29. package/engine/internal/unit/bonus.lua +17 -0
  30. package/engine/internal/unit/item.lua +3 -4
  31. package/engine/internal/unit.d.ts +7 -1
  32. package/engine/internal/unit.lua +17 -2
  33. package/engine/lightning.d.ts +12 -5
  34. package/engine/lightning.lua +48 -14
  35. package/engine/object-data/auxiliary/animation-name.d.ts +1 -0
  36. package/engine/object-data/auxiliary/animation-name.lua +16 -0
  37. package/engine/object-data/auxiliary/sound-eax.d.ts +10 -0
  38. package/engine/object-data/auxiliary/sound-eax.lua +2 -0
  39. package/engine/object-data/auxiliary/tech-tree-dependency.d.ts +1 -1
  40. package/engine/object-data/entry/ability-type/blank-configurable.lua +12 -1
  41. package/engine/object-data/entry/ability-type/disease-cloud.lua +2 -2
  42. package/engine/object-data/entry/ability-type/engineering-upgrade.lua +2 -2
  43. package/engine/object-data/entry/ability-type/ensnare.d.ts +12 -0
  44. package/engine/object-data/entry/ability-type/ensnare.lua +52 -0
  45. package/engine/object-data/entry/ability-type/feral-spirit.lua +2 -2
  46. package/engine/object-data/entry/ability-type/phoenix-morph.lua +4 -4
  47. package/engine/object-data/entry/ability-type/raise-dead.d.ts +17 -0
  48. package/engine/object-data/entry/ability-type/raise-dead.lua +78 -0
  49. package/engine/object-data/entry/ability-type/summon-quilbeast.lua +2 -2
  50. package/engine/object-data/entry/ability-type/summon-water-elemental.lua +2 -2
  51. package/engine/object-data/entry/ability-type.d.ts +8 -6
  52. package/engine/object-data/entry/ability-type.lua +54 -15
  53. package/engine/object-data/entry/buff-type/applicable.lua +13 -37
  54. package/engine/object-data/entry/buff-type.d.ts +1 -1
  55. package/engine/object-data/entry/buff-type.lua +2 -2
  56. package/engine/object-data/entry/destructible-type.d.ts +1 -1
  57. package/engine/object-data/entry/item-type.d.ts +1 -1
  58. package/engine/object-data/entry/item-type.lua +4 -4
  59. package/engine/object-data/entry/lightning-type.d.ts +1 -1
  60. package/engine/object-data/entry/sound-preset.d.ts +33 -0
  61. package/engine/object-data/entry/sound-preset.lua +140 -0
  62. package/engine/object-data/entry/unit-type.d.ts +8 -1
  63. package/engine/object-data/entry/unit-type.lua +61 -8
  64. package/engine/object-data/entry/upgrade.d.ts +1 -1
  65. package/engine/object-data/entry/upgrade.lua +4 -4
  66. package/engine/object-data/entry.d.ts +16 -14
  67. package/engine/object-data/entry.lua +60 -32
  68. package/engine/standard/entries/sound-preset.d.ts +10 -0
  69. package/engine/standard/entries/sound-preset.lua +10 -0
  70. package/engine/unit.d.ts +1 -0
  71. package/engine/unit.lua +1 -0
  72. package/objutil/unit.lua +8 -0
  73. package/package.json +2 -2
  74. package/utility/reflection.lua +11 -7
@@ -454,8 +454,6 @@ end
454
454
  local function getAbilityCooldown(_, abilityTypeId)
455
455
  return getUnitAbilityCooldownRemaining(abilityActionDummy, abilityTypeId)
456
456
  end
457
- local function doNothing()
458
- end
459
457
  ____exports.ItemAbility = __TS__Class()
460
458
  local ItemAbility = ____exports.ItemAbility
461
459
  ItemAbility.name = "ItemAbility"
@@ -16,6 +16,8 @@ local ____timer = require("core.types.timer")
16
16
  local Timer = ____timer.Timer
17
17
  local ____ignore_2Devents_2Ditems = require("engine.internal.unit.ignore-events-items")
18
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
19
21
  local isItemOwned = IsItemOwned
20
22
  local isItemPowerup = IsItemPowerup
21
23
  local getItemX = GetItemX
@@ -26,7 +28,6 @@ local getItemIntegerField = BlzGetItemIntegerField
26
28
  local setItemBooleanField = BlzSetItemBooleanField
27
29
  local setItemPosition = SetItemPosition
28
30
  local unitAddItem = UnitAddItem
29
- local unitDropItemSlot = UnitDropItemSlot
30
31
  local unitRemoveItem = UnitRemoveItem
31
32
  local unitUseItem = UnitUseItem
32
33
  local unitResetCooldown = UnitResetCooldown
@@ -141,8 +142,7 @@ ____exports.doAbilityActionForceDummy = function(handle, owner, action, ...)
141
142
  unitAddItem(dummy, handle)
142
143
  local result = action(handle, ...)
143
144
  unitRemoveItem(dummy, handle)
144
- unitAddItem(owner, handle)
145
- unitDropItemSlot(owner, handle, slot)
145
+ unitAddItemToSlot(owner, handle, slot)
146
146
  if isPowerup then
147
147
  setItemBooleanField(handle, ITEM_BF_USE_AUTOMATICALLY_WHEN_ACQUIRED, true)
148
148
  end
@@ -78,9 +78,9 @@ export declare class Item extends Handle<jitem> {
78
78
  hasAbility(abilityTypeId: AbilityTypeId): boolean;
79
79
  getAbility(abilityTypeId: AbilityTypeId): ItemAbility | undefined;
80
80
  get abilities(): readonly ItemAbility[];
81
- static getInRange(pos: Vec2, range: number): Item[];
81
+ static getInRange(x: number, y: number, range: number): Item[];
82
82
  static getInRect(rect: ReadonlyRect): Item[];
83
83
  static get onCreate(): Event<[Item]>;
84
- static get onDestroy(): Event<[Item]>;
84
+ static get destroyEvent(): Event<[Item]>;
85
85
  }
86
86
  export {};
@@ -15,6 +15,12 @@ local ____ability = require("engine.internal.ability")
15
15
  local ItemAbility = ____ability.ItemAbility
16
16
  local ____ability = require("engine.internal.item.ability")
17
17
  local doAbilityAction = ____ability.doAbilityAction
18
+ local ____dummy_2Ditem = require("engine.internal.object-data.dummy-item")
19
+ local DUMMY_ITEM_ID = ____dummy_2Ditem.DUMMY_ITEM_ID
20
+ local ____add_2Ditem_2Dto_2Dslot = require("engine.internal.unit.add-item-to-slot")
21
+ local SLOT_FILLER_ITEM_TYPE_ID = ____add_2Ditem_2Dto_2Dslot.SLOT_FILLER_ITEM_TYPE_ID
22
+ local ____vec2 = require("math.vec2")
23
+ local distance = ____vec2.distance
18
24
  local itemAddAbility = BlzItemAddAbility
19
25
  local itemRemoveAbility = BlzItemRemoveAbility
20
26
  local getItemAbility = BlzGetItemAbility
@@ -24,6 +30,12 @@ local getAbilityId = BlzGetAbilityId
24
30
  local getWidgetLife = GetWidgetLife
25
31
  local removeItem = RemoveItem
26
32
  local getHandleId = GetHandleId
33
+ local setRect = SetRect
34
+ local enumItemsInRect = EnumItemsInRect
35
+ local getEnumItem = GetEnumItem
36
+ local getItemTypeId = GetItemTypeId
37
+ local getItemX = GetItemX
38
+ local getItemY = GetItemY
27
39
  local getItemIntegerField = BlzGetItemIntegerField
28
40
  local setItemBooleanField = BlzSetItemBooleanField
29
41
  local getItemBooleanField = BlzGetItemBooleanField
@@ -53,6 +65,32 @@ local function getItemAbilities(handle, item)
53
65
  end
54
66
  return abilities
55
67
  end
68
+ local targetCollection
69
+ local targetCollectionNextIndex
70
+ local centerX
71
+ local centerY
72
+ local enumRange
73
+ local function collectIntoTarget()
74
+ local item = getEnumItem()
75
+ local typeId = getItemTypeId(item)
76
+ if typeId ~= DUMMY_ITEM_ID and typeId ~= SLOT_FILLER_ITEM_TYPE_ID then
77
+ targetCollection[targetCollectionNextIndex] = ____exports.Item:of(item)
78
+ targetCollectionNextIndex = targetCollectionNextIndex + 1
79
+ end
80
+ end
81
+ local function collectIntoTargetRange()
82
+ local item = getEnumItem()
83
+ local typeId = getItemTypeId(item)
84
+ if distance(
85
+ getItemX(item),
86
+ getItemY(item),
87
+ centerX,
88
+ centerY
89
+ ) <= enumRange and typeId ~= DUMMY_ITEM_ID and typeId ~= SLOT_FILLER_ITEM_TYPE_ID then
90
+ targetCollection[targetCollectionNextIndex] = ____exports.Item:of(item)
91
+ targetCollectionNextIndex = targetCollectionNextIndex + 1
92
+ end
93
+ end
56
94
  ____exports.Item = __TS__Class()
57
95
  local Item = ____exports.Item
58
96
  Item.name = "Item"
@@ -111,34 +149,27 @@ function Item.prototype.getAbility(self, abilityTypeId)
111
149
  local ability = self[101][abilityTypeId] ~= nil and doAbilityAction(self.handle, getItemAbility, abilityTypeId)
112
150
  return ability and ItemAbility:of(ability, abilityTypeId, self) or nil
113
151
  end
114
- function Item.getInRange(self, pos, range)
115
- local collection = {}
116
- SetRect(
152
+ function Item.getInRange(self, x, y, range)
153
+ targetCollection = {}
154
+ targetCollectionNextIndex = 1
155
+ centerX = x
156
+ centerY = y
157
+ enumRange = range
158
+ setRect(
117
159
  enumRect,
118
- pos.x - range,
119
- pos.y - range,
120
- pos.x + range,
121
- pos.y + range
160
+ x - range,
161
+ y - range,
162
+ x + range,
163
+ y + range
122
164
  )
123
- EnumItemsInRect(
124
- enumRect,
125
- nil,
126
- function()
127
- collection[#collection + 1] = self:of(GetEnumItem())
128
- end
129
- )
130
- return collection
165
+ enumItemsInRect(enumRect, nil, collectIntoTargetRange)
166
+ return targetCollection
131
167
  end
132
168
  function Item.getInRect(self, rect)
133
- local collection = {}
134
- EnumItemsInRect(
135
- rect.handle,
136
- nil,
137
- function()
138
- collection[#collection + 1] = self:of(GetEnumItem())
139
- end
140
- )
141
- return collection
169
+ targetCollection = {}
170
+ targetCollectionNextIndex = 1
171
+ enumItemsInRect(rect.handle, nil, collectIntoTarget)
172
+ return targetCollection
142
173
  end
143
174
  __TS__SetDescriptor(
144
175
  Item.prototype,
@@ -551,7 +582,7 @@ __TS__ObjectDefineProperty(
551
582
  )
552
583
  __TS__ObjectDefineProperty(
553
584
  Item,
554
- "onDestroy",
585
+ "destroyEvent",
555
586
  {get = function(self)
556
587
  return self.onDestroyEvent
557
588
  end}
@@ -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
@@ -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,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
@@ -9,12 +9,12 @@ local ____unit = require("engine.internal.unit")
9
9
  local Unit = ____unit.Unit
10
10
  local ____utility = require("engine.internal.utility")
11
11
  local findUnitItemSlot = ____utility.findUnitItemSlot
12
+ local ____add_2Ditem_2Dto_2Dslot = require("engine.internal.unit.add-item-to-slot")
13
+ local unitAddItemToSlot = ____add_2Ditem_2Dto_2Dslot.unitAddItemToSlot
12
14
  local rawset = _G.rawset
13
15
  local ____type = _G.type
14
16
  local isItemPowerup = IsItemPowerup
15
17
  local setItemBooleanField = BlzSetItemBooleanField
16
- local unitAddItem = UnitAddItem
17
- local unitDropItemSlot = UnitDropItemSlot
18
18
  local unitInventorySize = UnitInventorySize
19
19
  local unitItemInSlot = UnitItemInSlot
20
20
  local unitRemoveItemFromSlot = UnitRemoveItemFromSlot
@@ -47,8 +47,7 @@ function UnitItems.prototype.__newindex(self, slot, item)
47
47
  if isPowerup then
48
48
  setItemBooleanField(itemHandle, ITEM_BF_USE_AUTOMATICALLY_WHEN_ACQUIRED, false)
49
49
  end
50
- unitAddItem(handle, itemHandle)
51
- unitDropItemSlot(handle, itemHandle, slot - 1)
50
+ unitAddItemToSlot(handle, itemHandle, slot - 1)
52
51
  if isPowerup then
53
52
  setItemBooleanField(itemHandle, ITEM_BF_USE_AUTOMATICALLY_WHEN_ACQUIRED, true)
54
53
  end
@@ -100,7 +100,9 @@ declare const enum UnitPropertyKey {
100
100
  DELAY_HEALTH_CHECKS_COUNTER = 103,
101
101
  DELAY_HEALTH_CHECKS_HEALTH_BONUS = 104,
102
102
  PREVENT_DEATH_HEALTH_BONUS = 105,
103
- IS_TEAM_GLOW_HIDDEN = 106
103
+ IS_TEAM_GLOW_HIDDEN = 106,
104
+ LAST_X = 107,
105
+ LAST_Y = 108
104
106
  }
105
107
  export type UnitSyncId = number & {
106
108
  readonly __unitSyncId: unique symbol;
@@ -113,6 +115,8 @@ export declare class Unit extends Handle<junit> {
113
115
  private [UnitPropertyKey.DELAY_HEALTH_CHECKS_HEALTH_BONUS]?;
114
116
  private [UnitPropertyKey.PREVENT_DEATH_HEALTH_BONUS]?;
115
117
  private [UnitPropertyKey.IS_TEAM_GLOW_HIDDEN]?;
118
+ private [UnitPropertyKey.LAST_X]?;
119
+ private [UnitPropertyKey.LAST_Y]?;
116
120
  private _owner?;
117
121
  private _timeScale?;
118
122
  private events?;
@@ -133,6 +137,7 @@ export declare class Unit extends Handle<junit> {
133
137
  get isAlive(): boolean;
134
138
  get isDead(): boolean;
135
139
  get isIllusion(): boolean;
140
+ get isStunned(): boolean;
136
141
  get combatClassifications(): CombatClassifications;
137
142
  set combatClassifications(combatClassifications: CombatClassifications);
138
143
  hasCombatClassification(combatClassification: CombatClassification): boolean;
@@ -147,6 +152,7 @@ export declare class Unit extends Handle<junit> {
147
152
  isEnemyOf(unit: Unit): boolean;
148
153
  playAnimation(animation: string, rarity?: jraritycontrol): void;
149
154
  playAnimation(animation: number): void;
155
+ resetAnimation(): void;
150
156
  queueAnimation(animation: string): void;
151
157
  get weapons(): [UnitWeapon, UnitWeapon];
152
158
  get firstWeapon(): UnitWeapon;
@@ -58,6 +58,7 @@ local ____tostring = _G.tostring
58
58
  local setUnitAnimation = SetUnitAnimation
59
59
  local setUnitAnimationWithRarity = SetUnitAnimationWithRarity
60
60
  local setUnitAnimationByIndex = SetUnitAnimationByIndex
61
+ local resetUnitAnimation = ResetUnitAnimation
61
62
  local queueUnitAnimation = QueueUnitAnimation
62
63
  local getUnitIntegerField = BlzGetUnitIntegerField
63
64
  local getUnitRealField = BlzGetUnitRealField
@@ -77,6 +78,7 @@ local setUnitScale = SetUnitScale
77
78
  local setUnitPosition = SetUnitPosition
78
79
  local setUnitTimeScale = SetUnitTimeScale
79
80
  local getHandleId = GetHandleId
81
+ local getUnitCurrentOrder = GetUnitCurrentOrder
80
82
  local createUnit = CreateUnit
81
83
  local killUnit = KillUnit
82
84
  local setUnitExploded = SetUnitExploded
@@ -679,6 +681,8 @@ function Unit.prototype.getEvent(self, event, collector)
679
681
  end
680
682
  function Unit.prototype.onDestroy(self)
681
683
  local handle = self.handle
684
+ self[107] = getUnitX(handle)
685
+ self[108] = getUnitY(handle)
682
686
  if not self._owner then
683
687
  self._owner = Player:of(getOwningPlayer(handle))
684
688
  end
@@ -794,6 +798,9 @@ function Unit.prototype.playAnimation(self, animation, rarity)
794
798
  setUnitAnimation(self.handle, animation)
795
799
  end
796
800
  end
801
+ function Unit.prototype.resetAnimation(self)
802
+ resetUnitAnimation(self.handle)
803
+ end
797
804
  function Unit.prototype.queueAnimation(self, animation)
798
805
  queueUnitAnimation(self.handle, animation)
799
806
  end
@@ -1204,6 +1211,14 @@ __TS__SetDescriptor(
1204
1211
  end},
1205
1212
  true
1206
1213
  )
1214
+ __TS__SetDescriptor(
1215
+ Unit.prototype,
1216
+ "isStunned",
1217
+ {get = function(self)
1218
+ return getUnitCurrentOrder(self.handle) == orderId("stunned")
1219
+ end},
1220
+ true
1221
+ )
1207
1222
  __TS__SetDescriptor(
1208
1223
  Unit.prototype,
1209
1224
  "combatClassifications",
@@ -1588,7 +1603,7 @@ __TS__SetDescriptor(
1588
1603
  "x",
1589
1604
  {
1590
1605
  get = function(self)
1591
- return getUnitX(self.handle)
1606
+ return self[107] or getUnitX(self.handle)
1592
1607
  end,
1593
1608
  set = function(self, v)
1594
1609
  SetUnitX(self.handle, v)
@@ -1601,7 +1616,7 @@ __TS__SetDescriptor(
1601
1616
  "y",
1602
1617
  {
1603
1618
  get = function(self)
1604
- return getUnitY(self.handle)
1619
+ return self[108] or getUnitY(self.handle)
1605
1620
  end,
1606
1621
  set = function(self, v)
1607
1622
  SetUnitY(self.handle, v)
@@ -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