warscript 0.0.1-dev.c8224f3 → 0.0.1-dev.c826fde

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 (164) hide show
  1. package/attributes.d.ts +5 -0
  2. package/attributes.lua +8 -1
  3. package/config.d.ts +5 -0
  4. package/config.lua +10 -0
  5. package/core/types/effect.d.ts +1 -3
  6. package/core/types/effect.lua +26 -29
  7. package/core/types/frame.lua +10 -12
  8. package/core/types/player.lua +3 -1
  9. package/core/types/playerCamera.d.ts +2 -0
  10. package/core/types/playerCamera.lua +79 -5
  11. package/core/types/sound.d.ts +17 -24
  12. package/core/types/sound.lua +99 -24
  13. package/core/types/timer.d.ts +8 -8
  14. package/core/types/timer.lua +39 -23
  15. package/core/util.lua +6 -1
  16. package/decl/native.d.ts +846 -790
  17. package/engine/behavior.d.ts +5 -0
  18. package/engine/behavior.lua +106 -27
  19. package/engine/behaviour/ability/apply-buff.d.ts +5 -0
  20. package/engine/behaviour/ability/apply-buff.lua +32 -0
  21. package/engine/behaviour/ability/apply-unit-behavior.lua +1 -0
  22. package/engine/behaviour/ability/damage.d.ts +9 -3
  23. package/engine/behaviour/ability/damage.lua +26 -38
  24. package/engine/behaviour/ability/emulate-impact.d.ts +1 -1
  25. package/engine/behaviour/ability/emulate-impact.lua +18 -3
  26. package/engine/behaviour/ability/restore-mana.d.ts +1 -1
  27. package/engine/behaviour/ability/restore-mana.lua +6 -6
  28. package/engine/behaviour/ability.d.ts +7 -2
  29. package/engine/behaviour/ability.lua +42 -24
  30. package/engine/behaviour/unit/stun-immunity.d.ts +5 -3
  31. package/engine/behaviour/unit/stun-immunity.lua +43 -27
  32. package/engine/behaviour/unit.d.ts +32 -0
  33. package/engine/behaviour/unit.lua +185 -4
  34. package/engine/buff.d.ts +57 -44
  35. package/engine/buff.lua +273 -221
  36. package/engine/internal/ability.d.ts +7 -1
  37. package/engine/internal/ability.lua +49 -9
  38. package/engine/internal/item/ability.lua +63 -11
  39. package/engine/internal/item+owner.lua +12 -6
  40. package/engine/internal/item.d.ts +8 -7
  41. package/engine/internal/item.lua +153 -51
  42. package/engine/internal/mechanics/ability-duration.lua +1 -1
  43. package/engine/internal/misc/damage-metadata-by-target.d.ts +2 -0
  44. package/engine/internal/misc/damage-metadata-by-target.lua +5 -0
  45. package/engine/internal/misc/frame-coordinates.d.ts +2 -0
  46. package/engine/internal/misc/frame-coordinates.lua +21 -0
  47. package/engine/internal/misc/get-terrain-z.d.ts +2 -0
  48. package/engine/internal/misc/get-terrain-z.lua +11 -0
  49. package/engine/internal/misc/player-local-handle.d.ts +2 -0
  50. package/engine/internal/misc/player-local-handle.lua +5 -0
  51. package/engine/internal/object-data/auto-attack-speed-increase.d.ts +1 -1
  52. package/engine/internal/object-data/auto-attack-speed-increase.lua +2 -0
  53. package/engine/internal/object-data/evasion-probability.d.ts +2 -0
  54. package/engine/internal/object-data/evasion-probability.lua +16 -0
  55. package/engine/internal/unit/ability.d.ts +35 -0
  56. package/engine/internal/unit/ability.lua +63 -1
  57. package/engine/internal/unit/add-item-to-slot.lua +4 -2
  58. package/engine/internal/unit/allowed-targets.d.ts +1 -1
  59. package/engine/internal/unit/allowed-targets.lua +9 -1
  60. package/engine/internal/unit/bonus.d.ts +2 -0
  61. package/engine/internal/unit/bonus.lua +17 -0
  62. package/engine/internal/unit/order.d.ts +20 -0
  63. package/engine/internal/unit/order.lua +136 -0
  64. package/engine/internal/unit+ability.lua +10 -1
  65. package/engine/internal/unit+damage.d.ts +2 -11
  66. package/engine/internal/unit+damage.lua +10 -14
  67. package/engine/internal/unit+spellSteal.lua +1 -2
  68. package/engine/internal/unit-missile-launch.lua +9 -2
  69. package/engine/internal/unit.d.ts +32 -10
  70. package/engine/internal/unit.lua +257 -110
  71. package/engine/lightning.d.ts +4 -3
  72. package/engine/lightning.lua +21 -12
  73. package/engine/object-data/auxiliary/animation-name.d.ts +1 -0
  74. package/engine/object-data/auxiliary/animation-name.lua +16 -0
  75. package/engine/object-data/auxiliary/armor-type.d.ts +11 -0
  76. package/engine/object-data/auxiliary/armor-type.lua +46 -0
  77. package/engine/object-data/auxiliary/attachment-preset.d.ts +7 -2
  78. package/engine/object-data/auxiliary/attachment-preset.lua +4 -3
  79. package/engine/object-data/auxiliary/attack-type.d.ts +7 -8
  80. package/engine/object-data/auxiliary/attack-type.lua +42 -0
  81. package/engine/object-data/auxiliary/movement-type.d.ts +7 -7
  82. package/engine/object-data/auxiliary/movement-type.lua +22 -0
  83. package/engine/object-data/auxiliary/sound-eax.d.ts +10 -0
  84. package/engine/object-data/auxiliary/sound-eax.lua +2 -0
  85. package/engine/object-data/auxiliary/tech-tree-dependency.d.ts +1 -1
  86. package/engine/object-data/auxiliary/unit-attribute.d.ts +6 -0
  87. package/engine/object-data/auxiliary/unit-attribute.lua +9 -0
  88. package/engine/object-data/entry/ability-type/berserk.d.ts +2 -0
  89. package/engine/object-data/entry/ability-type/berserk.lua +13 -0
  90. package/engine/object-data/entry/ability-type/blank-configurable.lua +12 -1
  91. package/engine/object-data/entry/ability-type/carrion-swarm.d.ts +14 -0
  92. package/engine/object-data/entry/ability-type/carrion-swarm.lua +65 -0
  93. package/engine/object-data/entry/ability-type/disease-cloud.lua +2 -2
  94. package/engine/object-data/entry/ability-type/engineering-upgrade.lua +2 -2
  95. package/engine/object-data/entry/ability-type/ensnare.d.ts +12 -0
  96. package/engine/object-data/entry/ability-type/ensnare.lua +52 -0
  97. package/engine/object-data/entry/ability-type/feral-spirit.lua +2 -2
  98. package/engine/object-data/entry/ability-type/permanent-invisibility.d.ts +8 -0
  99. package/engine/object-data/entry/ability-type/permanent-invisibility.lua +26 -0
  100. package/engine/object-data/entry/ability-type/phase-shift.d.ts +10 -0
  101. package/engine/object-data/entry/ability-type/phase-shift.lua +39 -0
  102. package/engine/object-data/entry/ability-type/phoenix-morph.lua +4 -4
  103. package/engine/object-data/entry/ability-type/raise-dead.d.ts +17 -0
  104. package/engine/object-data/entry/ability-type/raise-dead.lua +78 -0
  105. package/engine/object-data/entry/ability-type/shock-wave.d.ts +4 -0
  106. package/engine/object-data/entry/ability-type/shock-wave.lua +26 -0
  107. package/engine/object-data/entry/ability-type/slow-poison.d.ts +10 -0
  108. package/engine/object-data/entry/ability-type/slow-poison.lua +58 -0
  109. package/engine/object-data/entry/ability-type/summon-quilbeast.lua +2 -2
  110. package/engine/object-data/entry/ability-type/summon-water-elemental.lua +2 -2
  111. package/engine/object-data/entry/ability-type/web.d.ts +12 -0
  112. package/engine/object-data/entry/ability-type/web.lua +52 -0
  113. package/engine/object-data/entry/ability-type.d.ts +19 -17
  114. package/engine/object-data/entry/ability-type.lua +82 -24
  115. package/engine/object-data/entry/buff-type/applicable.lua +18 -37
  116. package/engine/object-data/entry/buff-type.d.ts +6 -12
  117. package/engine/object-data/entry/buff-type.lua +13 -29
  118. package/engine/object-data/entry/destructible-type.d.ts +1 -1
  119. package/engine/object-data/entry/item-type.d.ts +1 -1
  120. package/engine/object-data/entry/item-type.lua +4 -4
  121. package/engine/object-data/entry/lightning-type.d.ts +1 -1
  122. package/engine/object-data/entry/sound-preset.d.ts +33 -0
  123. package/engine/object-data/entry/sound-preset.lua +140 -0
  124. package/engine/object-data/entry/unit-type.d.ts +21 -5
  125. package/engine/object-data/entry/unit-type.lua +214 -93
  126. package/engine/object-data/entry/upgrade.d.ts +1 -1
  127. package/engine/object-data/entry/upgrade.lua +4 -4
  128. package/engine/object-data/entry.d.ts +16 -14
  129. package/engine/object-data/entry.lua +60 -32
  130. package/engine/object-field/ability.d.ts +4 -4
  131. package/engine/object-field/ability.lua +7 -6
  132. package/engine/object-field/unit.d.ts +57 -3
  133. package/engine/object-field/unit.lua +207 -7
  134. package/engine/object-field.d.ts +17 -6
  135. package/engine/object-field.lua +188 -92
  136. package/engine/standard/entries/buff-type.d.ts +3 -0
  137. package/engine/standard/entries/buff-type.lua +3 -0
  138. package/engine/standard/entries/sound-preset.d.ts +10 -0
  139. package/engine/standard/entries/sound-preset.lua +10 -0
  140. package/engine/standard/fields/unit.d.ts +4 -0
  141. package/engine/standard/fields/unit.lua +7 -0
  142. package/engine/text-tag.d.ts +36 -2
  143. package/engine/text-tag.lua +249 -10
  144. package/engine/unit.d.ts +1 -0
  145. package/engine/unit.lua +1 -0
  146. package/objutil/buff.lua +1 -2
  147. package/objutil/unit.lua +8 -0
  148. package/package.json +2 -2
  149. package/patch-lualib.lua +1 -1
  150. package/utility/arrays.d.ts +1 -0
  151. package/utility/arrays.lua +3 -0
  152. package/utility/callback-array.d.ts +13 -0
  153. package/utility/callback-array.lua +46 -0
  154. package/utility/functions.d.ts +8 -0
  155. package/utility/functions.lua +13 -0
  156. package/utility/linked-set.d.ts +1 -0
  157. package/utility/linked-set.lua +3 -0
  158. package/utility/lua-maps.d.ts +4 -0
  159. package/utility/lua-maps.lua +20 -0
  160. package/utility/lua-sets.d.ts +2 -0
  161. package/utility/lua-sets.lua +7 -0
  162. package/utility/reflection.lua +11 -7
  163. package/core/types/order.d.ts +0 -25
  164. package/core/types/order.lua +0 -55
@@ -1,5 +1,5 @@
1
1
  /** @noSelfInFile */
2
- import { Handle } from "../../core/types/handle";
2
+ import { Handle, HandleDestructor } from "../../core/types/handle";
3
3
  import { Event } from "../../event";
4
4
  import type { Item } from "../../core/types/item";
5
5
  import type { Unit } from "./unit";
@@ -55,14 +55,19 @@ export declare class UnrecognizedAbility extends Ability {
55
55
  export declare class UnitAbility extends Ability {
56
56
  readonly owner: Unit;
57
57
  private readonly u;
58
+ private d?;
58
59
  constructor(handle: jability, typeId: number, owner: Unit);
59
60
  incrementHideCounter(): void;
60
61
  decrementHideCounter(): void;
62
+ incrementDisableCounter(): void;
63
+ decrementDisableCounter(): void;
64
+ get isDisabled(): boolean;
61
65
  get level(): number;
62
66
  set level(v: number);
63
67
  get cooldownRemaining(): number;
64
68
  set cooldownRemaining(cooldownRemaining: number);
65
69
  interruptCast(): void;
70
+ protected onDestroy(): HandleDestructor;
66
71
  static get onCreate(): Event<[UnitAbility]>;
67
72
  static get onDestroy(): Event<[UnitAbility]>;
68
73
  }
@@ -89,6 +94,7 @@ export declare class ItemAbility extends Ability {
89
94
  get cooldownRemaining(): number;
90
95
  set cooldownRemaining(cooldownRemaining: number);
91
96
  interruptCast(): void;
97
+ protected onDestroy(): HandleDestructor;
92
98
  static get onCreate(): Event<[ItemAbility]>;
93
99
  static get onDestroy(): Event<[ItemAbility]>;
94
100
  }
@@ -38,6 +38,7 @@ local getHandleId = GetHandleId
38
38
  local getItemBooleanField = BlzGetItemBooleanField
39
39
  local setItemBooleanField = BlzSetItemBooleanField
40
40
  local unitHideAbility = BlzUnitHideAbility
41
+ local unitDisableAbility = BlzUnitDisableAbility
41
42
  local match = string.match
42
43
  local ____type = _G.type
43
44
  local ____tostring = _G.tostring
@@ -231,6 +232,19 @@ ____exports.getOrderIdByAbilityTypeId = function(abilityTypeId)
231
232
  local parentTypeId = availableFields[abilityTypeId]
232
233
  return order2orderId(orders[____type(parentTypeId) == "number" and parentTypeId or abilityTypeId] or "")
233
234
  end
235
+ ---
236
+ -- @internal For use by internal systems only.
237
+ ____exports.abilityTypeHasField = function(abilityTypeId, field)
238
+ field = ____type(field) == "number" and field or getHandleId(field)
239
+ if commonFields[field] then
240
+ return true
241
+ end
242
+ local id = availableFields[abilityTypeId]
243
+ if ____type(id) == "number" then
244
+ id = availableFields[id]
245
+ end
246
+ return not not (id and id[field])
247
+ end
234
248
  ____exports.Ability = __TS__Class()
235
249
  local Ability = ____exports.Ability
236
250
  Ability.name = "Ability"
@@ -246,15 +260,7 @@ function Ability.prototype.getSnapshot(self)
246
260
  return nil
247
261
  end
248
262
  function Ability.prototype.hasField(self, field)
249
- field = ____type(field) == "number" and field or getHandleId(field)
250
- if commonFields[field] then
251
- return true
252
- end
253
- local id = availableFields[self.typeId]
254
- if ____type(id) == "number" then
255
- id = availableFields[id]
256
- end
257
- return not not (id and id[field])
263
+ return ____exports.abilityTypeHasField(self.typeId, field)
258
264
  end
259
265
  function Ability.prototype.getField(self, field, level)
260
266
  local fieldType = match(
@@ -402,9 +408,37 @@ end
402
408
  function UnitAbility.prototype.decrementHideCounter(self)
403
409
  unitHideAbility(self.u, self.typeId, false)
404
410
  end
411
+ function UnitAbility.prototype.incrementDisableCounter(self)
412
+ local unit = self.u
413
+ local typeId = self.typeId
414
+ unitHideAbility(unit, typeId, true)
415
+ unitDisableAbility(unit, typeId, true, false)
416
+ self.d = (self.d or 0) + 1
417
+ end
418
+ function UnitAbility.prototype.decrementDisableCounter(self)
419
+ local unit = self.u
420
+ local typeId = self.typeId
421
+ unitDisableAbility(unit, typeId, false, false)
422
+ unitHideAbility(unit, typeId, true)
423
+ self.d = (self.d or 0) - 1
424
+ end
405
425
  function UnitAbility.prototype.interruptCast(self)
406
426
  self.owner:interruptCast(self.typeId)
407
427
  end
428
+ function UnitAbility.prototype.onDestroy(self)
429
+ if self.owner.state ~= 2 then
430
+ self.owner:removeAbility(self.typeId)
431
+ end
432
+ return UnitAbility.____super.prototype.onDestroy(self)
433
+ end
434
+ __TS__SetDescriptor(
435
+ UnitAbility.prototype,
436
+ "isDisabled",
437
+ {get = function(self)
438
+ return self.d ~= nil and self.d > 0
439
+ end},
440
+ true
441
+ )
408
442
  __TS__SetDescriptor(
409
443
  UnitAbility.prototype,
410
444
  "level",
@@ -489,6 +523,12 @@ function ItemAbility.prototype.interruptCast(self)
489
523
  setItemBooleanField(handle, ITEM_BF_ACTIVELY_USED, true)
490
524
  end
491
525
  end
526
+ function ItemAbility.prototype.onDestroy(self)
527
+ if self.owner.state ~= 2 then
528
+ self.owner:removeAbility(self.typeId)
529
+ end
530
+ return ItemAbility.____super.prototype.onDestroy(self)
531
+ end
492
532
  __TS__SetDescriptor(
493
533
  ItemAbility.prototype,
494
534
  "level",
@@ -20,6 +20,7 @@ local ____add_2Ditem_2Dto_2Dslot = require("engine.internal.unit.add-item-to-slo
20
20
  local unitAddItemToSlot = ____add_2Ditem_2Dto_2Dslot.unitAddItemToSlot
21
21
  local isItemOwned = IsItemOwned
22
22
  local isItemPowerup = IsItemPowerup
23
+ local getItemAbility = BlzGetItemAbility
23
24
  local getItemX = GetItemX
24
25
  local getItemY = GetItemY
25
26
  local setAbilityRealLevelField = BlzSetAbilityRealLevelField
@@ -31,6 +32,8 @@ local unitAddItem = UnitAddItem
31
32
  local unitRemoveItem = UnitRemoveItem
32
33
  local unitUseItem = UnitUseItem
33
34
  local unitResetCooldown = UnitResetCooldown
35
+ local unitInventorySize = UnitInventorySize
36
+ local unitItemInSlot = UnitItemInSlot
34
37
  local COOLDOWN_STARTER_ABILITY_TYPE_ID = compiletime(function()
35
38
  if not currentMap then
36
39
  return 0
@@ -55,22 +58,24 @@ local COOLDOWN_STARTER_ITEM_TYPE_ID = compiletime(function()
55
58
  itemType.activelyUsed = true
56
59
  return itemType.id
57
60
  end)
58
- local dummy = assert(CreateUnit(
61
+ ---
62
+ -- @internal For use by internal systems only.
63
+ ____exports.itemAbilityDummy = assert(CreateUnit(
59
64
  Player.neutralVictim.handle,
60
65
  dummyUnitId,
61
66
  0,
62
67
  0,
63
68
  270
64
69
  ))
65
- local cooldownStarterItem = UnitAddItemById(dummy, COOLDOWN_STARTER_ITEM_TYPE_ID)
66
- local cooldownStarterAbility = BlzGetItemAbility(cooldownStarterItem, COOLDOWN_STARTER_ABILITY_TYPE_ID)
67
- ShowUnit(dummy, false)
70
+ local cooldownStarterItem = UnitAddItemById(____exports.itemAbilityDummy, COOLDOWN_STARTER_ITEM_TYPE_ID)
71
+ local cooldownStarterAbility = getItemAbility(cooldownStarterItem, COOLDOWN_STARTER_ABILITY_TYPE_ID)
72
+ ShowUnit(____exports.itemAbilityDummy, false)
68
73
  local function startItemCooldownInternal(handle, cooldown)
69
74
  local cooldownGroup = getItemIntegerField(handle, ITEM_IF_COOLDOWN_GROUP)
70
75
  setItemIntegerField(handle, ITEM_IF_COOLDOWN_GROUP, COOLDOWN_STARTER_ABILITY_TYPE_ID)
71
76
  setAbilityRealLevelField(cooldownStarterAbility, ABILITY_RLF_COOLDOWN, 0, cooldown)
72
- unitResetCooldown(dummy)
73
- unitUseItem(dummy, cooldownStarterItem)
77
+ unitResetCooldown(____exports.itemAbilityDummy)
78
+ unitUseItem(____exports.itemAbilityDummy, cooldownStarterItem)
74
79
  Timer:run(restoreCooldownGroup, handle, cooldownGroup)
75
80
  end
76
81
  restoreCooldownGroup = function(handle, cooldownGroup)
@@ -85,7 +90,7 @@ ____exports.startItemCooldown = function(handle, owner, cooldown)
85
90
  end
86
91
  ---
87
92
  -- @internal For use by internal systems only.
88
- ____exports.abilityActionDummy = dummy
93
+ ____exports.abilityActionDummy = ____exports.itemAbilityDummy
89
94
  ---
90
95
  -- @internal For use by internal systems only.
91
96
  ____exports.doAbilityAction = function(handle, action, ...)
@@ -104,11 +109,11 @@ ____exports.doAbilityAction = function(handle, action, ...)
104
109
  end
105
110
  x = getItemX(handle)
106
111
  y = getItemY(handle)
107
- unitAddItem(dummy, handle)
112
+ unitAddItem(____exports.itemAbilityDummy, handle)
108
113
  end
109
114
  local result = action(handle, ...)
110
115
  if not isOwned then
111
- unitRemoveItem(dummy, handle)
116
+ unitRemoveItem(____exports.itemAbilityDummy, handle)
112
117
  setItemPosition(handle, x, y)
113
118
  if isPowerup then
114
119
  setItemBooleanField(handle, ITEM_BF_USE_AUTOMATICALLY_WHEN_ACQUIRED, true)
@@ -139,9 +144,9 @@ ____exports.doAbilityActionForceDummy = function(handle, owner, action, ...)
139
144
  isPowerup = true
140
145
  end
141
146
  unitRemoveItem(owner, handle)
142
- unitAddItem(dummy, handle)
147
+ unitAddItem(____exports.itemAbilityDummy, handle)
143
148
  local result = action(handle, ...)
144
- unitRemoveItem(dummy, handle)
149
+ unitRemoveItem(____exports.itemAbilityDummy, handle)
145
150
  unitAddItemToSlot(owner, handle, slot)
146
151
  if isPowerup then
147
152
  setItemBooleanField(handle, ITEM_BF_USE_AUTOMATICALLY_WHEN_ACQUIRED, true)
@@ -151,4 +156,51 @@ ____exports.doAbilityActionForceDummy = function(handle, owner, action, ...)
151
156
  end
152
157
  return result
153
158
  end
159
+ local depth = 0
160
+ local itemBySlot = {}
161
+ ---
162
+ -- @internal For use by internal systems only.
163
+ ____exports.doUnitAbilityAction = function(unit, abilityTypeId, action, ...)
164
+ local ____depth_0 = depth
165
+ depth = ____depth_0 + 1
166
+ local offset = 6 * ____depth_0
167
+ for slot = 0, unitInventorySize(unit) - 1 do
168
+ local item = unitItemInSlot(unit, slot)
169
+ if getItemAbility(item, abilityTypeId) ~= nil then
170
+ local isAlreadyIgnoredInEvents = ignoreEventsItems[item] ~= nil
171
+ if not isAlreadyIgnoredInEvents then
172
+ ignoreEventsItems[item] = true
173
+ end
174
+ unitRemoveItem(unit, item)
175
+ if not isAlreadyIgnoredInEvents then
176
+ ignoreEventsItems[item] = nil
177
+ end
178
+ itemBySlot[offset + slot] = item
179
+ end
180
+ end
181
+ local result = action(unit, ...)
182
+ for slot = 0, unitInventorySize(unit) - 1 do
183
+ local item = itemBySlot[offset + slot]
184
+ if item ~= nil then
185
+ local isAlreadyIgnoredInEvents = ignoreEventsItems[item] ~= nil
186
+ if not isAlreadyIgnoredInEvents then
187
+ ignoreEventsItems[item] = true
188
+ end
189
+ local isPowerup = isItemPowerup(item)
190
+ if isPowerup then
191
+ setItemBooleanField(item, ITEM_BF_USE_AUTOMATICALLY_WHEN_ACQUIRED, false)
192
+ end
193
+ unitAddItemToSlot(unit, item, slot)
194
+ if isPowerup then
195
+ setItemBooleanField(item, ITEM_BF_USE_AUTOMATICALLY_WHEN_ACQUIRED, true)
196
+ end
197
+ if not isAlreadyIgnoredInEvents then
198
+ ignoreEventsItems[item] = nil
199
+ end
200
+ itemBySlot[offset + slot] = nil
201
+ end
202
+ end
203
+ depth = depth - 1
204
+ return result
205
+ end
154
206
  return ____exports
@@ -6,12 +6,18 @@ local Item = ____item.Item
6
6
  local ____unit = require("engine.internal.unit")
7
7
  local Unit = ____unit.Unit
8
8
  local ownerByItem = setmetatable({}, {__mode = "kv"})
9
- Unit.itemPickedUpEvent:addListener(function(unit, item)
10
- ownerByItem[item] = unit
11
- end)
12
- Unit.itemDroppedEvent:addListener(function(unit, item)
13
- ownerByItem[item] = nil
14
- end)
9
+ Unit.itemPickedUpEvent:addListener(
10
+ 4,
11
+ function(unit, item)
12
+ ownerByItem[item] = unit
13
+ end
14
+ )
15
+ Unit.itemDroppedEvent:addListener(
16
+ 4,
17
+ function(unit, item)
18
+ ownerByItem[item] = nil
19
+ end
20
+ )
15
21
  __TS__ObjectDefineProperty(
16
22
  Item.prototype,
17
23
  "owner",
@@ -5,19 +5,17 @@ import { Event } from "../../event";
5
5
  import { ReadonlyRect } from "../../core/types/rect";
6
6
  import { ItemAbility } from "./ability";
7
7
  import { AbilityTypeId } from "../object-data/entry/ability-type";
8
+ import type { ItemTypeId } from "../object-data/entry/item-type";
8
9
  type DefenseType = 0 | 1 | 2 | 3 | 4 | 5;
9
- export declare const addAndGetAbility: (handle: jitem, abilityTypeId: AbilityTypeId) => jability | null;
10
10
  declare const enum ItemPropertyKey {
11
- ABILITIES = 100,
12
- LUA_INDEX_BY_ABILITY_TYPE_ID = 101
11
+ ABILITIES = 100
13
12
  }
14
13
  export declare class Item extends Handle<jitem> {
15
14
  private readonly [ItemPropertyKey.ABILITIES];
16
- private readonly [ItemPropertyKey.LUA_INDEX_BY_ABILITY_TYPE_ID];
17
15
  constructor(handle: jitem);
18
16
  protected onDestroy(): HandleDestructor;
19
17
  static create<T extends Item>(this: typeof Item & (new (handle: jitem) => T), id: number, x: number, y: number, skinId?: number): T;
20
- get typeId(): number;
18
+ get typeId(): ItemTypeId;
21
19
  set skinId(v: number);
22
20
  get skinId(): number;
23
21
  set name(v: string);
@@ -73,14 +71,17 @@ export declare class Item extends Handle<jitem> {
73
71
  set position(v: Vec2);
74
72
  set charges(v: number);
75
73
  get charges(): number;
74
+ consumeCharge(): boolean;
75
+ consumeCharges(count: number): boolean;
76
76
  addAbility(abilityTypeId: AbilityTypeId): ItemAbility | undefined;
77
77
  removeAbility(abilityTypeId: AbilityTypeId): boolean;
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
+ static readonly chargesChangedEvent: Event<[Item]>;
85
86
  }
86
87
  export {};
@@ -1,20 +1,33 @@
1
1
  local ____lualib = require("lualib_bundle")
2
+ local __TS__New = ____lualib.__TS__New
2
3
  local __TS__Class = ____lualib.__TS__Class
3
4
  local __TS__ClassExtends = ____lualib.__TS__ClassExtends
4
5
  local __TS__SetDescriptor = ____lualib.__TS__SetDescriptor
5
6
  local __TS__ObjectDefineProperty = ____lualib.__TS__ObjectDefineProperty
6
7
  local __TS__Delete = ____lualib.__TS__Delete
7
8
  local ____exports = {}
9
+ local invoke
8
10
  local ____handle = require("core.types.handle")
9
11
  local Handle = ____handle.Handle
10
12
  local ____color = require("core.types.color")
11
13
  local Color = ____color.Color
14
+ local ____event = require("event")
15
+ local Event = ____event.Event
12
16
  local ____rect = require("core.types.rect")
13
17
  local Rect = ____rect.Rect
14
18
  local ____ability = require("engine.internal.ability")
15
19
  local ItemAbility = ____ability.ItemAbility
16
20
  local ____ability = require("engine.internal.item.ability")
17
21
  local doAbilityAction = ____ability.doAbilityAction
22
+ local doAbilityActionForceDummy = ____ability.doAbilityActionForceDummy
23
+ local itemAbilityDummy = ____ability.itemAbilityDummy
24
+ local ____dummy_2Ditem = require("engine.internal.object-data.dummy-item")
25
+ local DUMMY_ITEM_ID = ____dummy_2Ditem.DUMMY_ITEM_ID
26
+ local ____add_2Ditem_2Dto_2Dslot = require("engine.internal.unit.add-item-to-slot")
27
+ local SLOT_FILLER_ITEM_TYPE_ID = ____add_2Ditem_2Dto_2Dslot.SLOT_FILLER_ITEM_TYPE_ID
28
+ local ____vec2 = require("math.vec2")
29
+ local distance = ____vec2.distance
30
+ local itemChargesChangeEvent = __TS__New(Event)
18
31
  local itemAddAbility = BlzItemAddAbility
19
32
  local itemRemoveAbility = BlzItemRemoveAbility
20
33
  local getItemAbility = BlzGetItemAbility
@@ -24,10 +37,34 @@ local getAbilityId = BlzGetAbilityId
24
37
  local getWidgetLife = GetWidgetLife
25
38
  local removeItem = RemoveItem
26
39
  local getHandleId = GetHandleId
40
+ local setRect = SetRect
41
+ local enumItemsInRect = EnumItemsInRect
42
+ local getEnumItem = GetEnumItem
43
+ local getItemTypeId = GetItemTypeId
44
+ local getItemX = GetItemX
45
+ local getItemY = GetItemY
46
+ local getItemCharges = GetItemCharges
47
+ local setItemCharges = SetItemCharges
48
+ local unitRemoveAbility = UnitRemoveAbility
49
+ local unitRemoveItem = UnitRemoveItem
50
+ local unitUseItem = UnitUseItem
51
+ local unitUseItemPoint = UnitUseItemPoint
52
+ local unitUseItemTarget = UnitUseItemTarget
53
+ local tableRemove = table.remove
54
+ _G.SetItemCharges = function(whichItem, charges)
55
+ setItemCharges(whichItem, charges)
56
+ invoke(
57
+ itemChargesChangeEvent,
58
+ ____exports.Item:of(whichItem)
59
+ )
60
+ end
27
61
  local getItemIntegerField = BlzGetItemIntegerField
28
62
  local setItemBooleanField = BlzSetItemBooleanField
29
63
  local getItemBooleanField = BlzGetItemBooleanField
64
+ invoke = Event.invoke
30
65
  local enumRect = Rect:create(0, 0, 0, 0).handle
66
+ ---
67
+ -- @internal For use by internal systems only.
31
68
  ____exports.addAndGetAbility = function(handle, abilityTypeId)
32
69
  if itemAddAbility(handle, abilityTypeId) then
33
70
  return getItemAbility(handle, abilityTypeId)
@@ -53,21 +90,62 @@ local function getItemAbilities(handle, item)
53
90
  end
54
91
  return abilities
55
92
  end
93
+ local function consumeCharge(handle)
94
+ do
95
+ local i = 0
96
+ local ability = getItemAbilityByIndex(handle, i)
97
+ while ability ~= nil do
98
+ unitRemoveAbility(
99
+ itemAbilityDummy,
100
+ getAbilityId(ability)
101
+ )
102
+ do
103
+ i = i + 1
104
+ ability = getItemAbilityByIndex(handle, i)
105
+ end
106
+ end
107
+ end
108
+ return unitUseItem(itemAbilityDummy, handle) or unitUseItemPoint(itemAbilityDummy, handle, 0, 0) or unitUseItemTarget(itemAbilityDummy, handle, itemAbilityDummy)
109
+ end
110
+ local targetCollection
111
+ local targetCollectionNextIndex
112
+ local centerX
113
+ local centerY
114
+ local enumRange
115
+ local function collectIntoTarget()
116
+ local item = getEnumItem()
117
+ local typeId = getItemTypeId(item)
118
+ if typeId ~= DUMMY_ITEM_ID and typeId ~= SLOT_FILLER_ITEM_TYPE_ID then
119
+ targetCollection[targetCollectionNextIndex] = ____exports.Item:of(item)
120
+ targetCollectionNextIndex = targetCollectionNextIndex + 1
121
+ end
122
+ end
123
+ local function collectIntoTargetRange()
124
+ local item = getEnumItem()
125
+ local typeId = getItemTypeId(item)
126
+ if distance(
127
+ getItemX(item),
128
+ getItemY(item),
129
+ centerX,
130
+ centerY
131
+ ) <= enumRange and typeId ~= DUMMY_ITEM_ID and typeId ~= SLOT_FILLER_ITEM_TYPE_ID then
132
+ targetCollection[targetCollectionNextIndex] = ____exports.Item:of(item)
133
+ targetCollectionNextIndex = targetCollectionNextIndex + 1
134
+ end
135
+ end
56
136
  ____exports.Item = __TS__Class()
57
137
  local Item = ____exports.Item
58
138
  Item.name = "Item"
59
139
  __TS__ClassExtends(Item, Handle)
60
140
  function Item.prototype.____constructor(self, handle)
61
141
  Handle.prototype.____constructor(self, handle)
62
- local abilities = doAbilityAction(handle, getItemAbilities, self)
63
- self[100] = abilities
64
- local luaIndexByAbilityTypeId = {}
65
- for i = 1, #abilities do
66
- luaIndexByAbilityTypeId[abilities[i].typeId] = i
67
- end
68
- self[101] = luaIndexByAbilityTypeId
142
+ self[100] = doAbilityAction(handle, getItemAbilities, self)
69
143
  end
70
144
  function Item.prototype.onDestroy(self)
145
+ local owner = self.owner
146
+ if owner ~= nil then
147
+ unitRemoveItem(owner.handle, self.handle)
148
+ end
71
149
  local abilities = self[100]
72
150
  for i = 1, #abilities do
73
151
  abilities[i]:destroy()
@@ -78,67 +156,89 @@ end
78
156
  function Item.create(self, id, x, y, skinId)
79
157
  return self:of(BlzCreateItemWithSkin(id, x, y, skinId or id))
80
158
  end
159
+ function Item.prototype.consumeCharge(self)
160
+ return self:consumeCharges(1)
161
+ end
162
+ function Item.prototype.consumeCharges(self, count)
163
+ local handle = self.handle
164
+ local charges = getItemCharges(handle)
165
+ if charges > count then
166
+ setItemCharges(handle, charges - count)
167
+ invoke(itemChargesChangeEvent, self)
168
+ return true
169
+ end
170
+ if charges == count then
171
+ if getItemBooleanField(handle, ITEM_BF_PERISHABLE) then
172
+ self:destroy()
173
+ return true
174
+ end
175
+ if not getItemBooleanField(handle, ITEM_BF_ACTIVELY_USED) then
176
+ setItemCharges(handle, 0)
177
+ invoke(itemChargesChangeEvent, self)
178
+ return true
179
+ end
180
+ setItemCharges(handle, 1)
181
+ local ____doAbilityActionForceDummy_2 = doAbilityActionForceDummy
182
+ local ____opt_0 = self.owner
183
+ ____doAbilityActionForceDummy_2(handle, ____opt_0 and ____opt_0.handle, consumeCharge)
184
+ invoke(itemChargesChangeEvent, self)
185
+ return true
186
+ end
187
+ return false
188
+ end
81
189
  function Item.prototype.addAbility(self, abilityTypeId)
82
190
  local nativeAbility = doAbilityAction(self.handle, ____exports.addAndGetAbility, abilityTypeId)
83
191
  if nativeAbility ~= nil then
84
192
  local ability = ItemAbility:of(nativeAbility, abilityTypeId, self)
85
193
  local abilities = self[100]
86
- local luaIndex = #abilities + 1
87
- abilities[luaIndex] = ability
88
- self[101][abilityTypeId] = luaIndex
194
+ abilities[#abilities + 1] = ability
89
195
  return ability
90
196
  end
91
197
  return nil
92
198
  end
93
199
  function Item.prototype.removeAbility(self, abilityTypeId)
94
- local luaIndexByAbilityTypeId = self[101]
95
- local luaIndex = luaIndexByAbilityTypeId[abilityTypeId]
96
- if luaIndex ~= nil and doAbilityAction(self.handle, itemRemoveAbility, abilityTypeId) then
97
- luaIndexByAbilityTypeId[abilityTypeId] = nil
98
- local abilities = self[100]
99
- abilities[luaIndex]:destroy()
100
- local abilityTypeIdsLength = #abilities
101
- for j = luaIndex, abilityTypeIdsLength do
102
- abilities[j] = abilities[j + 1]
200
+ local abilities = self[100]
201
+ for i = 1, #abilities do
202
+ if abilities[i].typeId == abilityTypeId then
203
+ local ability = abilities[i]
204
+ tableRemove(abilities, i)
205
+ ability:destroy()
206
+ return true
103
207
  end
104
208
  end
105
- return false
209
+ return doAbilityAction(self.handle, itemRemoveAbility, abilityTypeId)
106
210
  end
107
211
  function Item.prototype.hasAbility(self, abilityTypeId)
108
- return self[101][abilityTypeId] ~= nil
212
+ return doAbilityAction(self.handle, getItemAbility, abilityTypeId) ~= nil
109
213
  end
110
214
  function Item.prototype.getAbility(self, abilityTypeId)
111
- local ability = self[101][abilityTypeId] ~= nil and doAbilityAction(self.handle, getItemAbility, abilityTypeId)
112
- return ability and ItemAbility:of(ability, abilityTypeId, self) or nil
113
- end
114
- function Item.getInRange(self, pos, range)
115
- local collection = {}
116
- SetRect(
117
- enumRect,
118
- pos.x - range,
119
- pos.y - range,
120
- pos.x + range,
121
- pos.y + range
215
+ return ItemAbility:of(
216
+ doAbilityAction(self.handle, getItemAbility, abilityTypeId),
217
+ abilityTypeId,
218
+ self
122
219
  )
123
- EnumItemsInRect(
220
+ end
221
+ function Item.getInRange(self, x, y, range)
222
+ targetCollection = {}
223
+ targetCollectionNextIndex = 1
224
+ centerX = x
225
+ centerY = y
226
+ enumRange = range
227
+ setRect(
124
228
  enumRect,
125
- nil,
126
- function()
127
- collection[#collection + 1] = self:of(GetEnumItem())
128
- end
229
+ x - range,
230
+ y - range,
231
+ x + range,
232
+ y + range
129
233
  )
130
- return collection
234
+ enumItemsInRect(enumRect, nil, collectIntoTargetRange)
235
+ return targetCollection
131
236
  end
132
237
  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
238
+ targetCollection = {}
239
+ targetCollectionNextIndex = 1
240
+ enumItemsInRect(rect.handle, nil, collectIntoTarget)
241
+ return targetCollection
142
242
  end
143
243
  __TS__SetDescriptor(
144
244
  Item.prototype,
@@ -270,7 +370,7 @@ __TS__SetDescriptor(
270
370
  "perishable",
271
371
  {
272
372
  get = function(self)
273
- return BlzGetItemBooleanField(self.handle, ITEM_BF_PERISHABLE)
373
+ return getItemBooleanField(self.handle, ITEM_BF_PERISHABLE)
274
374
  end,
275
375
  set = function(self, v)
276
376
  BlzSetItemBooleanField(self.handle, ITEM_BF_PERISHABLE, v)
@@ -526,10 +626,11 @@ __TS__SetDescriptor(
526
626
  "charges",
527
627
  {
528
628
  get = function(self)
529
- return GetItemCharges(self.handle)
629
+ return getItemCharges(self.handle)
530
630
  end,
531
631
  set = function(self, v)
532
- SetItemCharges(self.handle, v)
632
+ setItemCharges(self.handle, v)
633
+ invoke(itemChargesChangeEvent, self)
533
634
  end
534
635
  },
535
636
  true
@@ -551,11 +652,12 @@ __TS__ObjectDefineProperty(
551
652
  )
552
653
  __TS__ObjectDefineProperty(
553
654
  Item,
554
- "onDestroy",
655
+ "destroyEvent",
555
656
  {get = function(self)
556
657
  return self.onDestroyEvent
557
658
  end}
558
659
  )
660
+ Item.chargesChangedEvent = itemChargesChangeEvent
559
661
  local getManipulatedItem = GetManipulatedItem
560
662
  local trigger = CreateTrigger()
561
663
  TriggerRegisterAnyUnitEventBJ(trigger, EVENT_PLAYER_UNIT_PICKUP_ITEM)
@@ -8,6 +8,6 @@ local DURATION_NORMAL_ABILITY_FLOAT_LEVEL_FIELD = ____ability.DURATION_NORMAL_AB
8
8
  -- @internal For use by internal systems only.
9
9
  ____exports.getAbilityDuration = function(ability, target)
10
10
  local level = ability.level
11
- return target ~= nil and target:hasClassification(UnitClassification.RESISTANT) and DURATION_HERO_ABILITY_FLOAT_LEVEL_FIELD:getValue(ability, level) or DURATION_NORMAL_ABILITY_FLOAT_LEVEL_FIELD:getValue(ability, level)
11
+ return target ~= nil and (target.isHero or target:getField(UNIT_IF_LEVEL) >= 6 or target:hasClassification(UnitClassification.RESISTANT)) and DURATION_HERO_ABILITY_FLOAT_LEVEL_FIELD:getValue(ability, level) or DURATION_NORMAL_ABILITY_FLOAT_LEVEL_FIELD:getValue(ability, level)
12
12
  end
13
13
  return ____exports
@@ -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.damageMetadataByTarget = setmetatable({}, {__mode = "k"})
5
+ return ____exports
@@ -0,0 +1,2 @@
1
+ /** @noSelfInFile */
2
+ export {};
@@ -0,0 +1,21 @@
1
+ local ____exports = {}
2
+ local getLocalClientWidth = BlzGetLocalClientWidth
3
+ local getLocalClientHeight = BlzGetLocalClientHeight
4
+ ---
5
+ -- @internal For use by internal systems only.
6
+ ____exports.getFrameMinXMaxX = function()
7
+ local w = getLocalClientWidth()
8
+ local h = getLocalClientHeight()
9
+ local width4by3 = (w - h / 600 * 800) / 2
10
+ local pxtodpi = 0.6 / h
11
+ local minX = -width4by3 * pxtodpi
12
+ local maxX = minX + w * pxtodpi
13
+ return minX, maxX
14
+ end
15
+ ---
16
+ -- @internal For use by internal systems only.
17
+ ____exports.FRAME_MIN_Y = 0
18
+ ---
19
+ -- @internal For use by internal systems only.
20
+ ____exports.FRAME_MAX_Y = 0.6
21
+ return ____exports
@@ -0,0 +1,2 @@
1
+ /** @noSelfInFile */
2
+ export {};