warscript 0.0.1-dev.e72b4b0 → 0.0.1-dev.ea102a7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/core/types/frame.lua +24 -21
  2. package/core/types/player.lua +3 -1
  3. package/core/types/playerCamera.d.ts +2 -0
  4. package/core/types/playerCamera.lua +123 -5
  5. package/core/types/tileCell.d.ts +9 -0
  6. package/core/types/tileCell.lua +92 -0
  7. package/core/types/timer.d.ts +2 -1
  8. package/core/types/timer.lua +21 -2
  9. package/decl/native.d.ts +6 -4
  10. package/engine/behavior.d.ts +5 -0
  11. package/engine/behavior.lua +106 -27
  12. package/engine/behaviour/ability/apply-buff.lua +1 -1
  13. package/engine/behaviour/ability/emulate-impact.d.ts +1 -1
  14. package/engine/behaviour/ability/emulate-impact.lua +2 -1
  15. package/engine/behaviour/ability/restore-mana.d.ts +1 -1
  16. package/engine/behaviour/ability/restore-mana.lua +6 -6
  17. package/engine/behaviour/ability.lua +7 -16
  18. package/engine/behaviour/unit/stun-immunity.d.ts +7 -3
  19. package/engine/behaviour/unit/stun-immunity.lua +52 -27
  20. package/engine/behaviour/unit.d.ts +12 -2
  21. package/engine/behaviour/unit.lua +47 -7
  22. package/engine/buff.d.ts +2 -4
  23. package/engine/buff.lua +68 -83
  24. package/engine/internal/ability.d.ts +3 -1
  25. package/engine/internal/ability.lua +34 -11
  26. package/engine/internal/item/ability.lua +51 -1
  27. package/engine/internal/item+owner.lua +12 -6
  28. package/engine/internal/item.d.ts +13 -15
  29. package/engine/internal/item.lua +63 -49
  30. package/engine/internal/misc/frame-coordinates.d.ts +2 -0
  31. package/engine/internal/misc/frame-coordinates.lua +21 -0
  32. package/engine/internal/misc/get-terrain-z.d.ts +2 -0
  33. package/engine/internal/misc/get-terrain-z.lua +11 -0
  34. package/engine/internal/misc/player-local-handle.d.ts +2 -0
  35. package/engine/internal/misc/player-local-handle.lua +5 -0
  36. package/engine/internal/unit/ability.lua +13 -5
  37. package/engine/internal/unit+ability.lua +10 -1
  38. package/engine/internal/unit-missile-launch.lua +18 -5
  39. package/engine/internal/unit.d.ts +5 -6
  40. package/engine/internal/unit.lua +73 -73
  41. package/engine/object-data/auxiliary/armor-type.d.ts +11 -0
  42. package/engine/object-data/auxiliary/armor-type.lua +46 -0
  43. package/engine/object-data/entry/ability-type.lua +5 -4
  44. package/engine/object-data/entry/unit-type.d.ts +11 -2
  45. package/engine/object-data/entry/unit-type.lua +59 -1
  46. package/engine/object-field/ability.d.ts +3 -3
  47. package/engine/object-field/ability.lua +7 -6
  48. package/engine/object-field/unit.d.ts +7 -0
  49. package/engine/object-field/unit.lua +21 -0
  50. package/engine/object-field.d.ts +2 -2
  51. package/engine/object-field.lua +8 -6
  52. package/engine/random.d.ts +9 -0
  53. package/engine/random.lua +13 -0
  54. package/engine/standard/fields/unit.d.ts +2 -1
  55. package/engine/standard/fields/unit.lua +2 -0
  56. package/engine/text-tag.d.ts +1 -1
  57. package/engine/text-tag.lua +91 -17
  58. package/objutil/buff.lua +1 -1
  59. package/package.json +2 -2
  60. package/patch-lualib.lua +1 -1
  61. package/utility/arrays.d.ts +1 -0
  62. package/utility/arrays.lua +8 -0
  63. package/utility/callback-array.d.ts +13 -0
  64. package/utility/callback-array.lua +46 -0
  65. package/utility/functions.d.ts +7 -0
  66. package/utility/functions.lua +12 -0
  67. package/utility/lua-maps.d.ts +11 -2
  68. package/utility/lua-maps.lua +33 -2
  69. package/utility/lua-sets.d.ts +1 -0
  70. package/utility/lua-sets.lua +4 -0
package/engine/buff.lua CHANGED
@@ -28,9 +28,6 @@ local ____math = require("math")
28
28
  local max = ____math.max
29
29
  local min = ____math.min
30
30
  local ____bonus = require("engine.internal.unit.bonus")
31
- local addOrUpdateOrRemoveUnitBonus = ____bonus.addOrUpdateOrRemoveUnitBonus
32
- local getUnitBonus = ____bonus.getUnitBonus
33
- local removeUnitBonus = ____bonus.removeUnitBonus
34
31
  local UnitBonusType = ____bonus.UnitBonusType
35
32
  local ____area_2Ddamage = require("engine.internal.mechanics.area-damage")
36
33
  local damageArea = ____area_2Ddamage.damageArea
@@ -304,7 +301,8 @@ buffHealingIntervalTimerCallback = function(buff)
304
301
  source:healTarget(buff[101], healingPerInterval)
305
302
  end
306
303
  end
307
- local buffDestroyEvent = __TS__New(Event)
304
+ local buffCreatedEvent = __TS__New(Event)
305
+ local buffBeingDestroyedEvent = __TS__New(Event)
308
306
  ____exports.Buff = __TS__Class()
309
307
  local Buff = ____exports.Buff
310
308
  Buff.name = "Buff"
@@ -506,64 +504,52 @@ function Buff.prototype.____constructor(self, _unit, typeIdOrTypeIds, polarityOr
506
504
  end
507
505
  self:onCreate()
508
506
  self[100] = 1
509
- end
510
- function Buff.prototype.getUnitBonus(self, bonusType)
511
- local ____opt_38 = self._bonusIdByBonusType
512
- local bonusId = ____opt_38 and ____opt_38[bonusType]
513
- return bonusId == nil and 0 or getUnitBonus(self._unit, bonusType, bonusId)
514
- end
515
- function Buff.prototype.addOrUpdateOrRemoveUnitBonus(self, bonusType, value)
516
- local bonusIdByBonusType = self._bonusIdByBonusType
517
- if bonusIdByBonusType == nil then
518
- bonusIdByBonusType = {}
519
- self._bonusIdByBonusType = bonusIdByBonusType
520
- end
521
- bonusIdByBonusType[bonusType] = addOrUpdateOrRemoveUnitBonus(self._unit, bonusType, bonusIdByBonusType[bonusType], value)
507
+ Event.invoke(buffCreatedEvent, self)
522
508
  end
523
509
  function Buff.prototype.flashEffect(self, widgetOrXOrParametersOrDuration, yOrParametersOrDuration, parametersOrDuration)
524
510
  if type(widgetOrXOrParametersOrDuration) == "number" and type(yOrParametersOrDuration) == "number" then
525
511
  Effect:flash(self[105], widgetOrXOrParametersOrDuration, yOrParametersOrDuration, parametersOrDuration)
526
512
  else
527
513
  local isWidgetProvided = __TS__InstanceOf(widgetOrXOrParametersOrDuration, Unit) or __TS__InstanceOf(widgetOrXOrParametersOrDuration, Item) or __TS__InstanceOf(widgetOrXOrParametersOrDuration, Destructable)
528
- local ____Effect_42 = Effect
529
- local ____Effect_flash_43 = Effect.flash
530
- local ____array_41 = __TS__SparseArrayNew(
514
+ local ____Effect_40 = Effect
515
+ local ____Effect_flash_41 = Effect.flash
516
+ local ____array_39 = __TS__SparseArrayNew(
531
517
  self[105],
532
518
  isWidgetProvided and widgetOrXOrParametersOrDuration or self._unit,
533
519
  stringValueByBuffTypeIdByFieldId[fourCC("feft")][self.typeId] or "origin"
534
520
  )
535
- local ____isWidgetProvided_40
521
+ local ____isWidgetProvided_38
536
522
  if isWidgetProvided then
537
- ____isWidgetProvided_40 = yOrParametersOrDuration
523
+ ____isWidgetProvided_38 = yOrParametersOrDuration
538
524
  else
539
- ____isWidgetProvided_40 = widgetOrXOrParametersOrDuration
525
+ ____isWidgetProvided_38 = widgetOrXOrParametersOrDuration
540
526
  end
541
- __TS__SparseArrayPush(____array_41, ____isWidgetProvided_40)
542
- ____Effect_flash_43(
543
- ____Effect_42,
544
- __TS__SparseArraySpread(____array_41)
527
+ __TS__SparseArrayPush(____array_39, ____isWidgetProvided_38)
528
+ ____Effect_flash_41(
529
+ ____Effect_40,
530
+ __TS__SparseArraySpread(____array_39)
545
531
  )
546
532
  end
547
533
  end
548
534
  function Buff.prototype.flashSpecialEffect(self, widgetOrDuration, duration)
549
535
  local isWidgetProvided = type(widgetOrDuration) == "table"
550
- local ____Effect_46 = Effect
551
- local ____Effect_flash_47 = Effect.flash
552
- local ____array_45 = __TS__SparseArrayNew(
536
+ local ____Effect_44 = Effect
537
+ local ____Effect_flash_45 = Effect.flash
538
+ local ____array_43 = __TS__SparseArrayNew(
553
539
  self[106],
554
540
  isWidgetProvided and widgetOrDuration or self._unit,
555
541
  stringValueByBuffTypeIdByFieldId[fourCC("fspt")][self.typeId] or "origin"
556
542
  )
557
- local ____isWidgetProvided_44
543
+ local ____isWidgetProvided_42
558
544
  if isWidgetProvided then
559
- ____isWidgetProvided_44 = duration
545
+ ____isWidgetProvided_42 = duration
560
546
  else
561
- ____isWidgetProvided_44 = widgetOrDuration
547
+ ____isWidgetProvided_42 = widgetOrDuration
562
548
  end
563
- __TS__SparseArrayPush(____array_45, ____isWidgetProvided_44)
564
- ____Effect_flash_47(
565
- ____Effect_46,
566
- __TS__SparseArraySpread(____array_45)
549
+ __TS__SparseArrayPush(____array_43, ____isWidgetProvided_42)
550
+ ____Effect_flash_45(
551
+ ____Effect_44,
552
+ __TS__SparseArraySpread(____array_43)
567
553
  )
568
554
  end
569
555
  function Buff.prototype.onCreate(self)
@@ -614,12 +600,7 @@ function Buff.prototype.onDestroy(self)
614
600
  unit:removeAbility(abilityTypeId)
615
601
  end
616
602
  end
617
- if self._bonusIdByBonusType ~= nil then
618
- for bonusType, bonusId in pairs(self._bonusIdByBonusType) do
619
- removeUnitBonus(unit, bonusType, bonusId)
620
- end
621
- end
622
- Event.invoke(buffDestroyEvent, self)
603
+ Event.invoke(buffBeingDestroyedEvent, self)
623
604
  self[100] = 3
624
605
  return UnitBehavior.prototype.onDestroy(self)
625
606
  end
@@ -648,8 +629,8 @@ function Buff.apply(self, ...)
648
629
  end
649
630
  end
650
631
  function Buff.getByTypeId(self, unit, typeId)
651
- local ____opt_48 = buffByTypeIdByUnit[unit]
652
- local buff = ____opt_48 and ____opt_48[typeId]
632
+ local ____opt_46 = buffByTypeIdByUnit[unit]
633
+ local buff = ____opt_46 and ____opt_46[typeId]
653
634
  if __TS__InstanceOf(buff, self) then
654
635
  return buff
655
636
  end
@@ -807,8 +788,8 @@ __TS__SetDescriptor(
807
788
  return
808
789
  end
809
790
  self[112] = damageInterval
810
- local ____opt_50 = self._timer
811
- local elapsed = ____opt_50 and ____opt_50.elapsed or 0
791
+ local ____opt_48 = self._timer
792
+ local elapsed = ____opt_48 and ____opt_48.elapsed or 0
812
793
  local timer = self[114]
813
794
  if timer == nil then
814
795
  timer = Timer:create()
@@ -887,8 +868,8 @@ __TS__SetDescriptor(
887
868
  return
888
869
  end
889
870
  self[117] = healingInterval
890
- local ____opt_52 = self._timer
891
- local elapsed = ____opt_52 and ____opt_52.elapsed or 0
871
+ local ____opt_50 = self._timer
872
+ local elapsed = ____opt_50 and ____opt_50.elapsed or 0
892
873
  local timer = self[119]
893
874
  if timer == nil then
894
875
  timer = Timer:create()
@@ -974,11 +955,11 @@ __TS__SetDescriptor(
974
955
  "turnsIntoGhost",
975
956
  {
976
957
  get = function(self)
977
- local ____self__135_54 = self[135]
978
- if ____self__135_54 == nil then
979
- ____self__135_54 = false
958
+ local ____self__135_52 = self[135]
959
+ if ____self__135_52 == nil then
960
+ ____self__135_52 = false
980
961
  end
981
- return ____self__135_54
962
+ return ____self__135_52
982
963
  end,
983
964
  set = function(self, turnsIntoGhost)
984
965
  if not turnsIntoGhost and self[135] then
@@ -997,11 +978,11 @@ __TS__SetDescriptor(
997
978
  "stuns",
998
979
  {
999
980
  get = function(self)
1000
- local ____self__136_55 = self[136]
1001
- if ____self__136_55 == nil then
1002
- ____self__136_55 = false
981
+ local ____self__136_53 = self[136]
982
+ if ____self__136_53 == nil then
983
+ ____self__136_53 = false
1003
984
  end
1004
- return ____self__136_55
985
+ return ____self__136_53
1005
986
  end,
1006
987
  set = function(self, stuns)
1007
988
  if not stuns and self[136] then
@@ -1026,11 +1007,11 @@ __TS__SetDescriptor(
1026
1007
  "ignoresStunImmunity",
1027
1008
  {
1028
1009
  get = function(self)
1029
- local ____self__137_56 = self[137]
1030
- if ____self__137_56 == nil then
1031
- ____self__137_56 = false
1010
+ local ____self__137_54 = self[137]
1011
+ if ____self__137_54 == nil then
1012
+ ____self__137_54 = false
1032
1013
  end
1033
- return ____self__137_56
1014
+ return ____self__137_54
1034
1015
  end,
1035
1016
  set = function(self, ignoresStunImmunity)
1036
1017
  if not ignoresStunImmunity and self[137] then
@@ -1053,11 +1034,11 @@ __TS__SetDescriptor(
1053
1034
  "disablesAutoAttack",
1054
1035
  {
1055
1036
  get = function(self)
1056
- local ____self__138_57 = self[138]
1057
- if ____self__138_57 == nil then
1058
- ____self__138_57 = false
1037
+ local ____self__138_55 = self[138]
1038
+ if ____self__138_55 == nil then
1039
+ ____self__138_55 = false
1059
1040
  end
1060
- return ____self__138_57
1041
+ return ____self__138_55
1061
1042
  end,
1062
1043
  set = function(self, disablesAutoAttack)
1063
1044
  if not disablesAutoAttack and self[138] then
@@ -1076,11 +1057,11 @@ __TS__SetDescriptor(
1076
1057
  "providesInvulnerability",
1077
1058
  {
1078
1059
  get = function(self)
1079
- local ____self__139_58 = self[139]
1080
- if ____self__139_58 == nil then
1081
- ____self__139_58 = false
1060
+ local ____self__139_56 = self[139]
1061
+ if ____self__139_56 == nil then
1062
+ ____self__139_56 = false
1082
1063
  end
1083
- return ____self__139_58
1064
+ return ____self__139_56
1084
1065
  end,
1085
1066
  set = function(self, providesInvulnerability)
1086
1067
  if not providesInvulnerability and self[139] then
@@ -1099,11 +1080,11 @@ __TS__SetDescriptor(
1099
1080
  "killsOnExpiration",
1100
1081
  {
1101
1082
  get = function(self)
1102
- local ____self__140_59 = self[140]
1103
- if ____self__140_59 == nil then
1104
- ____self__140_59 = false
1083
+ local ____self__140_57 = self[140]
1084
+ if ____self__140_57 == nil then
1085
+ ____self__140_57 = false
1105
1086
  end
1106
- return ____self__140_59
1087
+ return ____self__140_57
1107
1088
  end,
1108
1089
  set = function(self, killsOnExpiration)
1109
1090
  if not killsOnExpiration and self[140] then
@@ -1120,11 +1101,11 @@ __TS__SetDescriptor(
1120
1101
  "explodesOnExpiration",
1121
1102
  {
1122
1103
  get = function(self)
1123
- local ____self__141_60 = self[141]
1124
- if ____self__141_60 == nil then
1125
- ____self__141_60 = false
1104
+ local ____self__141_58 = self[141]
1105
+ if ____self__141_58 == nil then
1106
+ ____self__141_58 = false
1126
1107
  end
1127
- return ____self__141_60
1108
+ return ____self__141_58
1128
1109
  end,
1129
1110
  set = function(self, killsOnExpiration)
1130
1111
  if not killsOnExpiration and self[141] then
@@ -1252,13 +1233,13 @@ __TS__SetDescriptor(
1252
1233
  "remainingDuration",
1253
1234
  {
1254
1235
  get = function(self)
1255
- local ____opt_61 = self._timer
1256
- return ____opt_61 and ____opt_61.remaining or 0
1236
+ local ____opt_59 = self._timer
1237
+ return ____opt_59 and ____opt_59.remaining or 0
1257
1238
  end,
1258
1239
  set = function(self, remainingDuration)
1259
- local ____remainingDuration_65 = remainingDuration
1260
- local ____opt_63 = self._timer
1261
- local remainingDurationDelta = ____remainingDuration_65 - (____opt_63 and ____opt_63.remaining or 0)
1240
+ local ____remainingDuration_63 = remainingDuration
1241
+ local ____opt_61 = self._timer
1242
+ local remainingDurationDelta = ____remainingDuration_63 - (____opt_61 and ____opt_61.remaining or 0)
1262
1243
  if remainingDurationDelta ~= 0 then
1263
1244
  self[103] = self[103] + remainingDurationDelta
1264
1245
  if remainingDuration <= 0 then
@@ -1288,7 +1269,8 @@ __TS__SetDescriptor(
1288
1269
  },
1289
1270
  true
1290
1271
  )
1291
- Buff.destroyEvent = buffDestroyEvent;
1272
+ Buff.createdEvent = buffCreatedEvent
1273
+ Buff.beingDestroyedEvent = buffBeingDestroyedEvent;
1292
1274
  (function(self)
1293
1275
  local function destroyBuffIfNeeded(buff)
1294
1276
  if getUnitAbility(buff[101].handle, buff.typeId) ~= buff.handle and buff[100] == 1 then
@@ -1342,5 +1324,8 @@ Buff.destroyEvent = buffDestroyEvent;
1342
1324
  ____exports.checkBuffs(target)
1343
1325
  end
1344
1326
  )
1327
+ buffCreatedEvent:addListener(function(buff)
1328
+ UnitBehavior:forAll(buff.unit, "onBuffGained", buff)
1329
+ end)
1345
1330
  end)(Buff)
1346
1331
  return ____exports
@@ -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";
@@ -67,6 +67,7 @@ export declare class UnitAbility extends Ability {
67
67
  get cooldownRemaining(): number;
68
68
  set cooldownRemaining(cooldownRemaining: number);
69
69
  interruptCast(): void;
70
+ protected onDestroy(): HandleDestructor;
70
71
  static get onCreate(): Event<[UnitAbility]>;
71
72
  static get onDestroy(): Event<[UnitAbility]>;
72
73
  }
@@ -93,6 +94,7 @@ export declare class ItemAbility extends Ability {
93
94
  get cooldownRemaining(): number;
94
95
  set cooldownRemaining(cooldownRemaining: number);
95
96
  interruptCast(): void;
97
+ protected onDestroy(): HandleDestructor;
96
98
  static get onCreate(): Event<[ItemAbility]>;
97
99
  static get onDestroy(): Event<[ItemAbility]>;
98
100
  }
@@ -232,6 +232,19 @@ ____exports.getOrderIdByAbilityTypeId = function(abilityTypeId)
232
232
  local parentTypeId = availableFields[abilityTypeId]
233
233
  return order2orderId(orders[____type(parentTypeId) == "number" and parentTypeId or abilityTypeId] or "")
234
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
235
248
  ____exports.Ability = __TS__Class()
236
249
  local Ability = ____exports.Ability
237
250
  Ability.name = "Ability"
@@ -247,15 +260,7 @@ function Ability.prototype.getSnapshot(self)
247
260
  return nil
248
261
  end
249
262
  function Ability.prototype.hasField(self, field)
250
- field = ____type(field) == "number" and field or getHandleId(field)
251
- if commonFields[field] then
252
- return true
253
- end
254
- local id = availableFields[self.typeId]
255
- if ____type(id) == "number" then
256
- id = availableFields[id]
257
- end
258
- return not not (id and id[field])
263
+ return ____exports.abilityTypeHasField(self.typeId, field)
259
264
  end
260
265
  function Ability.prototype.getField(self, field, level)
261
266
  local fieldType = match(
@@ -404,16 +409,28 @@ function UnitAbility.prototype.decrementHideCounter(self)
404
409
  unitHideAbility(self.u, self.typeId, false)
405
410
  end
406
411
  function UnitAbility.prototype.incrementDisableCounter(self)
407
- unitDisableAbility(self.u, self.typeId, true, false)
412
+ local unit = self.u
413
+ local typeId = self.typeId
414
+ unitHideAbility(unit, typeId, true)
415
+ unitDisableAbility(unit, typeId, true, false)
408
416
  self.d = (self.d or 0) + 1
409
417
  end
410
418
  function UnitAbility.prototype.decrementDisableCounter(self)
411
- unitDisableAbility(self.u, self.typeId, false, false)
419
+ local unit = self.u
420
+ local typeId = self.typeId
421
+ unitDisableAbility(unit, typeId, false, false)
422
+ unitHideAbility(unit, typeId, true)
412
423
  self.d = (self.d or 0) - 1
413
424
  end
414
425
  function UnitAbility.prototype.interruptCast(self)
415
426
  self.owner:interruptCast(self.typeId)
416
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
417
434
  __TS__SetDescriptor(
418
435
  UnitAbility.prototype,
419
436
  "isDisabled",
@@ -506,6 +523,12 @@ function ItemAbility.prototype.interruptCast(self)
506
523
  setItemBooleanField(handle, ITEM_BF_ACTIVELY_USED, true)
507
524
  end
508
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
509
532
  __TS__SetDescriptor(
510
533
  ItemAbility.prototype,
511
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
@@ -65,7 +68,7 @@ ____exports.itemAbilityDummy = assert(CreateUnit(
65
68
  270
66
69
  ))
67
70
  local cooldownStarterItem = UnitAddItemById(____exports.itemAbilityDummy, COOLDOWN_STARTER_ITEM_TYPE_ID)
68
- local cooldownStarterAbility = BlzGetItemAbility(cooldownStarterItem, COOLDOWN_STARTER_ABILITY_TYPE_ID)
71
+ local cooldownStarterAbility = getItemAbility(cooldownStarterItem, COOLDOWN_STARTER_ABILITY_TYPE_ID)
69
72
  ShowUnit(____exports.itemAbilityDummy, false)
70
73
  local function startItemCooldownInternal(handle, cooldown)
71
74
  local cooldownGroup = getItemIntegerField(handle, ITEM_IF_COOLDOWN_GROUP)
@@ -153,4 +156,51 @@ ____exports.doAbilityActionForceDummy = function(handle, owner, action, ...)
153
156
  end
154
157
  return result
155
158
  end
159
+ local depth = 0
160
+ local itemBySlot = {}
161
+ ---
162
+ -- @internal For use by internal systems only.
163
+ ____exports.doUnitAbilityAction = function(unit, abilityTypeId, action, ...)
164
+ local ____depth_0 = depth
165
+ depth = ____depth_0 + 1
166
+ local offset = 6 * ____depth_0
167
+ for slot = 0, unitInventorySize(unit) - 1 do
168
+ local item = unitItemInSlot(unit, slot)
169
+ if getItemAbility(item, abilityTypeId) ~= nil then
170
+ local isAlreadyIgnoredInEvents = ignoreEventsItems[item] ~= nil
171
+ if not isAlreadyIgnoredInEvents then
172
+ ignoreEventsItems[item] = true
173
+ end
174
+ unitRemoveItem(unit, item)
175
+ if not isAlreadyIgnoredInEvents then
176
+ ignoreEventsItems[item] = nil
177
+ end
178
+ itemBySlot[offset + slot] = item
179
+ end
180
+ end
181
+ local result = action(unit, ...)
182
+ for slot = 0, unitInventorySize(unit) - 1 do
183
+ local item = itemBySlot[offset + slot]
184
+ if item ~= nil then
185
+ local isAlreadyIgnoredInEvents = ignoreEventsItems[item] ~= nil
186
+ if not isAlreadyIgnoredInEvents then
187
+ ignoreEventsItems[item] = true
188
+ end
189
+ local isPowerup = isItemPowerup(item)
190
+ if isPowerup then
191
+ setItemBooleanField(item, ITEM_BF_USE_AUTOMATICALLY_WHEN_ACQUIRED, false)
192
+ end
193
+ unitAddItemToSlot(unit, item, slot)
194
+ if isPowerup then
195
+ setItemBooleanField(item, ITEM_BF_USE_AUTOMATICALLY_WHEN_ACQUIRED, true)
196
+ end
197
+ if not isAlreadyIgnoredInEvents then
198
+ ignoreEventsItems[item] = nil
199
+ end
200
+ itemBySlot[offset + slot] = nil
201
+ end
202
+ end
203
+ depth = depth - 1
204
+ return result
205
+ end
156
206
  return ____exports
@@ -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",
@@ -8,12 +8,10 @@ import { AbilityTypeId } from "../object-data/entry/ability-type";
8
8
  import type { ItemTypeId } from "../object-data/entry/item-type";
9
9
  type DefenseType = 0 | 1 | 2 | 3 | 4 | 5;
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;
@@ -30,22 +28,22 @@ export declare class Item extends Handle<jitem> {
30
28
  get extendedTooltip(): string;
31
29
  set iconPath(v: string);
32
30
  get iconPath(): string;
33
- set dropOnDeath(v: boolean);
34
- get dropOnDeath(): boolean;
35
- set droppable(v: boolean);
36
- get droppable(): boolean;
37
- set pawnable(v: boolean);
38
- get pawnable(): boolean;
39
- set perishable(v: boolean);
40
- get perishable(): boolean;
41
- set powerup(v: boolean);
42
- get powerup(): boolean;
31
+ set dropsOnDeath(dropsOnDeath: boolean);
32
+ get dropsOnDeath(): boolean;
33
+ set canBeDropped(canBeDropped: boolean);
34
+ get canBeDropped(): boolean;
35
+ set canBeSold(canBeSold: boolean);
36
+ get canBeSold(): boolean;
37
+ set perishes(perishes: boolean);
38
+ get perishes(): boolean;
39
+ set isPowerUp(isPowerUp: boolean);
40
+ get isPowerUp(): boolean;
43
41
  get isAlive(): boolean;
44
42
  get isDead(): boolean;
45
43
  set isInvulnerable(isInvulnerable: boolean);
46
44
  get isInvulnerable(): boolean;
47
- set usable(v: boolean);
48
- get usable(): boolean;
45
+ set isActivelyUsed(isActivelyUsed: boolean);
46
+ get isActivelyUsed(): boolean;
49
47
  set visible(v: boolean);
50
48
  get visible(): boolean;
51
49
  set level(v: number);