warscript 0.0.1-dev.4721022 → 0.0.1-dev.475a555

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 (99) hide show
  1. package/attributes.d.ts +5 -0
  2. package/attributes.lua +8 -1
  3. package/core/types/effect.d.ts +1 -3
  4. package/core/types/effect.lua +26 -29
  5. package/core/types/sound.d.ts +17 -25
  6. package/core/types/sound.lua +85 -44
  7. package/core/types/timer.d.ts +6 -7
  8. package/core/types/timer.lua +18 -21
  9. package/decl/native.d.ts +840 -786
  10. package/engine/behaviour/ability/apply-unit-behavior.lua +1 -0
  11. package/engine/behaviour/ability/damage.d.ts +6 -3
  12. package/engine/behaviour/ability/damage.lua +24 -36
  13. package/engine/behaviour/ability/emulate-impact.lua +16 -2
  14. package/engine/behaviour/ability.d.ts +4 -1
  15. package/engine/behaviour/ability.lua +7 -5
  16. package/engine/behaviour/unit.d.ts +17 -0
  17. package/engine/behaviour/unit.lua +114 -4
  18. package/engine/buff.d.ts +13 -8
  19. package/engine/buff.lua +81 -50
  20. package/engine/internal/ability.d.ts +4 -0
  21. package/engine/internal/ability.lua +17 -0
  22. package/engine/internal/item/ability.lua +12 -10
  23. package/engine/internal/item.d.ts +5 -2
  24. package/engine/internal/item.lua +75 -3
  25. package/engine/internal/mechanics/ability-duration.lua +1 -1
  26. package/engine/internal/misc/damage-metadata-by-target.d.ts +2 -0
  27. package/engine/internal/misc/damage-metadata-by-target.lua +5 -0
  28. package/engine/internal/unit/ability.d.ts +5 -0
  29. package/engine/internal/unit/ability.lua +14 -0
  30. package/engine/internal/unit/allowed-targets.d.ts +1 -1
  31. package/engine/internal/unit/allowed-targets.lua +9 -1
  32. package/engine/internal/unit/order.d.ts +20 -0
  33. package/engine/internal/unit/order.lua +136 -0
  34. package/engine/internal/unit+damage.d.ts +2 -11
  35. package/engine/internal/unit+damage.lua +10 -14
  36. package/engine/internal/unit+spellSteal.lua +1 -2
  37. package/engine/internal/unit-missile-launch.lua +1 -1
  38. package/engine/internal/unit.d.ts +27 -4
  39. package/engine/internal/unit.lua +184 -37
  40. package/engine/object-data/auxiliary/attachment-preset.d.ts +7 -2
  41. package/engine/object-data/auxiliary/attachment-preset.lua +4 -3
  42. package/engine/object-data/auxiliary/attack-type.d.ts +7 -8
  43. package/engine/object-data/auxiliary/attack-type.lua +42 -0
  44. package/engine/object-data/auxiliary/movement-type.d.ts +7 -7
  45. package/engine/object-data/auxiliary/movement-type.lua +22 -0
  46. package/engine/object-data/auxiliary/sound-eax.d.ts +10 -0
  47. package/engine/object-data/auxiliary/sound-eax.lua +2 -0
  48. package/engine/object-data/auxiliary/unit-attribute.d.ts +6 -0
  49. package/engine/object-data/auxiliary/unit-attribute.lua +9 -0
  50. package/engine/object-data/entry/ability-type/berserk.d.ts +2 -0
  51. package/engine/object-data/entry/ability-type/berserk.lua +13 -0
  52. package/engine/object-data/entry/ability-type/carrion-swarm.d.ts +14 -0
  53. package/engine/object-data/entry/ability-type/carrion-swarm.lua +65 -0
  54. package/engine/object-data/entry/ability-type/ensnare.d.ts +12 -0
  55. package/engine/object-data/entry/ability-type/ensnare.lua +52 -0
  56. package/engine/object-data/entry/ability-type/permanent-invisibility.d.ts +8 -0
  57. package/engine/object-data/entry/ability-type/permanent-invisibility.lua +26 -0
  58. package/engine/object-data/entry/ability-type/phase-shift.d.ts +10 -0
  59. package/engine/object-data/entry/ability-type/phase-shift.lua +39 -0
  60. package/engine/object-data/entry/ability-type/shock-wave.d.ts +4 -0
  61. package/engine/object-data/entry/ability-type/shock-wave.lua +26 -0
  62. package/engine/object-data/entry/ability-type/slow-poison.d.ts +10 -0
  63. package/engine/object-data/entry/ability-type/slow-poison.lua +58 -0
  64. package/engine/object-data/entry/ability-type/web.d.ts +12 -0
  65. package/engine/object-data/entry/ability-type/web.lua +52 -0
  66. package/engine/object-data/entry/ability-type.d.ts +11 -11
  67. package/engine/object-data/entry/ability-type.lua +31 -10
  68. package/engine/object-data/entry/buff-type/applicable.lua +5 -0
  69. package/engine/object-data/entry/buff-type.d.ts +5 -11
  70. package/engine/object-data/entry/buff-type.lua +11 -27
  71. package/engine/object-data/entry/sound-preset.d.ts +17 -0
  72. package/engine/object-data/entry/sound-preset.lua +104 -0
  73. package/engine/object-data/entry/unit-type.d.ts +2 -2
  74. package/engine/object-data/entry/unit-type.lua +94 -84
  75. package/engine/object-field/ability.d.ts +1 -1
  76. package/engine/object-field/unit.d.ts +46 -3
  77. package/engine/object-field/unit.lua +173 -7
  78. package/engine/object-field.d.ts +15 -4
  79. package/engine/object-field.lua +184 -90
  80. package/engine/standard/entries/buff-type.d.ts +3 -0
  81. package/engine/standard/entries/buff-type.lua +3 -0
  82. package/engine/text-tag.d.ts +12 -1
  83. package/engine/text-tag.lua +44 -10
  84. package/engine/unit.d.ts +1 -0
  85. package/engine/unit.lua +1 -0
  86. package/objutil/buff.lua +1 -2
  87. package/package.json +2 -2
  88. package/utility/arrays.d.ts +1 -0
  89. package/utility/arrays.lua +3 -0
  90. package/utility/functions.d.ts +1 -0
  91. package/utility/functions.lua +1 -0
  92. package/utility/linked-set.d.ts +1 -0
  93. package/utility/linked-set.lua +3 -0
  94. package/utility/lua-maps.d.ts +4 -0
  95. package/utility/lua-maps.lua +20 -0
  96. package/utility/lua-sets.d.ts +1 -0
  97. package/utility/lua-sets.lua +3 -0
  98. package/core/types/order.d.ts +0 -25
  99. package/core/types/order.lua +0 -55
package/engine/buff.lua CHANGED
@@ -109,6 +109,7 @@ local buffParametersKeys = {
109
109
  durationIncreaseOnAutoAttack = true,
110
110
  maximumDuration = true,
111
111
  maximumRemainingDuration = true,
112
+ turnsIntoGhost = true,
112
113
  stuns = true,
113
114
  ignoresStunImmunity = true,
114
115
  providesStunImmunity = true,
@@ -174,6 +175,7 @@ local function resolveAndSetNumberValue(buff, property, ability, level, value, d
174
175
  end
175
176
  end
176
177
  local buffBooleanParameters = {
178
+ "turnsIntoGhost",
177
179
  "stuns",
178
180
  "ignoresStunImmunity",
179
181
  "disablesAutoAttack",
@@ -321,7 +323,7 @@ function Buff.prototype.____constructor(self, _unit, typeIdOrTypeIds, polarityOr
321
323
  typeId = selectBuffTypeIdWithLeastDuration(typeIdOrTypeIds, _unit)
322
324
  polarity = resistanceTypeOrPolarity
323
325
  resistanceType = abilityOrParametersOrResistanceType
324
- if __TS__InstanceOf(parametersOrAbility, Ability) then
326
+ if __TS__InstanceOf(parametersOrAbility, Ability) or parametersOrAbility == nil then
325
327
  ability = parametersOrAbility
326
328
  else
327
329
  ability = nil
@@ -331,7 +333,7 @@ function Buff.prototype.____constructor(self, _unit, typeIdOrTypeIds, polarityOr
331
333
  typeId = typeIdOrTypeIds
332
334
  polarity = polarityOrTypeIdSelectionPolicy
333
335
  resistanceType = resistanceTypeOrPolarity
334
- if __TS__InstanceOf(abilityOrParametersOrResistanceType, Ability) then
336
+ if __TS__InstanceOf(abilityOrParametersOrResistanceType, Ability) or abilityOrParametersOrResistanceType == nil then
335
337
  ability = abilityOrParametersOrResistanceType
336
338
  parameters = parametersOrAbility
337
339
  else
@@ -340,7 +342,7 @@ function Buff.prototype.____constructor(self, _unit, typeIdOrTypeIds, polarityOr
340
342
  end
341
343
  end
342
344
  self.typeId = typeId
343
- if not __TS__InstanceOf(ability, Ability) then
345
+ if not (__TS__InstanceOf(ability, Ability) or ability == nil) then
344
346
  parameters = ability
345
347
  ability = nil
346
348
  end
@@ -371,7 +373,7 @@ function Buff.prototype.____constructor(self, _unit, typeIdOrTypeIds, polarityOr
371
373
  local missProbability = parameters and parameters.missProbability or defaultParameters.missProbability
372
374
  if missProbability ~= nil then
373
375
  missProbability = resolveNumberValue(ability, level, missProbability)
374
- self[141] = missProbability
376
+ self[142] = missProbability
375
377
  end
376
378
  local buffByTypeId = buffByTypeIdByUnit[_unit]
377
379
  if buffByTypeId == nil then
@@ -592,15 +594,21 @@ function Buff.prototype.onDestroy(self)
592
594
  behavior:destroy()
593
595
  end
594
596
  end
595
- if self[137] then
597
+ if self[139] then
598
+ unit:decrementInvulnerabilityCounter()
599
+ end
600
+ if self[138] then
596
601
  unit:decrementDisableAutoAttackCounter()
597
602
  end
598
- if self[135] then
599
- if self[136] then
603
+ if self[136] then
604
+ if self[137] then
600
605
  unit:decrementStunCounter()
601
606
  end
602
607
  unit:decrementStunCounter()
603
608
  end
609
+ if self[135] then
610
+ unit:decrementGhostCounter()
611
+ end
604
612
  if self._abilityTypeIds ~= nil then
605
613
  for abilityTypeId in pairs(self._abilityTypeIds) do
606
614
  unit:removeAbility(abilityTypeId)
@@ -655,9 +663,9 @@ function Buff.prototype.onExpiration(self)
655
663
  if self[121] ~= nil then
656
664
  (self[102] or unit):healTarget(unit, self[120] or 0)
657
665
  end
658
- if self[140] then
666
+ if self[141] then
659
667
  unit:explode()
660
- elseif self[139] then
668
+ elseif self[140] then
661
669
  unit:kill()
662
670
  end
663
671
  end
@@ -963,7 +971,7 @@ __TS__SetDescriptor(
963
971
  )
964
972
  __TS__SetDescriptor(
965
973
  Buff.prototype,
966
- "stuns",
974
+ "turnsIntoGhost",
967
975
  {
968
976
  get = function(self)
969
977
  local ____self__135_54 = self[135]
@@ -972,18 +980,12 @@ __TS__SetDescriptor(
972
980
  end
973
981
  return ____self__135_54
974
982
  end,
975
- set = function(self, stuns)
976
- if not stuns and self[135] then
977
- if self[136] then
978
- self.object:decrementStunCounter()
979
- end
980
- self.object:decrementStunCounter()
983
+ set = function(self, turnsIntoGhost)
984
+ if not turnsIntoGhost and self[135] then
985
+ self.object:decrementGhostCounter()
981
986
  self[135] = nil
982
- elseif stuns and not self[135] then
983
- if self[136] then
984
- self.object:incrementStunCounter()
985
- end
986
- self.object:incrementStunCounter()
987
+ elseif turnsIntoGhost and not self[135] then
988
+ self.object:incrementGhostCounter()
987
989
  self[135] = true
988
990
  end
989
991
  end
@@ -992,7 +994,7 @@ __TS__SetDescriptor(
992
994
  )
993
995
  __TS__SetDescriptor(
994
996
  Buff.prototype,
995
- "ignoresStunImmunity",
997
+ "stuns",
996
998
  {
997
999
  get = function(self)
998
1000
  local ____self__136_55 = self[136]
@@ -1001,16 +1003,18 @@ __TS__SetDescriptor(
1001
1003
  end
1002
1004
  return ____self__136_55
1003
1005
  end,
1004
- set = function(self, ignoresStunImmunity)
1005
- if not ignoresStunImmunity and self[136] then
1006
- if self[135] then
1006
+ set = function(self, stuns)
1007
+ if not stuns and self[136] then
1008
+ if self[137] then
1007
1009
  self.object:decrementStunCounter()
1008
1010
  end
1011
+ self.object:decrementStunCounter()
1009
1012
  self[136] = nil
1010
- elseif ignoresStunImmunity and not self[136] then
1011
- if self[135] then
1013
+ elseif stuns and not self[136] then
1014
+ if self[137] then
1012
1015
  self.object:incrementStunCounter()
1013
1016
  end
1017
+ self.object:incrementStunCounter()
1014
1018
  self[136] = true
1015
1019
  end
1016
1020
  end
@@ -1019,7 +1023,7 @@ __TS__SetDescriptor(
1019
1023
  )
1020
1024
  __TS__SetDescriptor(
1021
1025
  Buff.prototype,
1022
- "disablesAutoAttack",
1026
+ "ignoresStunImmunity",
1023
1027
  {
1024
1028
  get = function(self)
1025
1029
  local ____self__137_56 = self[137]
@@ -1028,12 +1032,16 @@ __TS__SetDescriptor(
1028
1032
  end
1029
1033
  return ____self__137_56
1030
1034
  end,
1031
- set = function(self, disablesAutoAttack)
1032
- if not disablesAutoAttack and self[137] then
1033
- self.object:decrementDisableAutoAttackCounter()
1035
+ set = function(self, ignoresStunImmunity)
1036
+ if not ignoresStunImmunity and self[137] then
1037
+ if self[136] then
1038
+ self.object:decrementStunCounter()
1039
+ end
1034
1040
  self[137] = nil
1035
- elseif disablesAutoAttack and not self[137] then
1036
- self.object:incrementDisableAutoAttackCounter()
1041
+ elseif ignoresStunImmunity and not self[137] then
1042
+ if self[136] then
1043
+ self.object:incrementStunCounter()
1044
+ end
1037
1045
  self[137] = true
1038
1046
  end
1039
1047
  end
@@ -1042,7 +1050,7 @@ __TS__SetDescriptor(
1042
1050
  )
1043
1051
  __TS__SetDescriptor(
1044
1052
  Buff.prototype,
1045
- "providesInvulnerability",
1053
+ "disablesAutoAttack",
1046
1054
  {
1047
1055
  get = function(self)
1048
1056
  local ____self__138_57 = self[138]
@@ -1051,12 +1059,12 @@ __TS__SetDescriptor(
1051
1059
  end
1052
1060
  return ____self__138_57
1053
1061
  end,
1054
- set = function(self, providesInvulnerability)
1055
- if not providesInvulnerability and self[138] then
1056
- self.object:decrementInvulnerabilityCounter()
1062
+ set = function(self, disablesAutoAttack)
1063
+ if not disablesAutoAttack and self[138] then
1064
+ self.object:decrementDisableAutoAttackCounter()
1057
1065
  self[138] = nil
1058
- elseif providesInvulnerability and not self[138] then
1059
- self.object:incrementInvulnerabilityCounter()
1066
+ elseif disablesAutoAttack and not self[138] then
1067
+ self.object:incrementDisableAutoAttackCounter()
1060
1068
  self[138] = true
1061
1069
  end
1062
1070
  end
@@ -1065,7 +1073,7 @@ __TS__SetDescriptor(
1065
1073
  )
1066
1074
  __TS__SetDescriptor(
1067
1075
  Buff.prototype,
1068
- "killsOnExpiration",
1076
+ "providesInvulnerability",
1069
1077
  {
1070
1078
  get = function(self)
1071
1079
  local ____self__139_58 = self[139]
@@ -1074,10 +1082,12 @@ __TS__SetDescriptor(
1074
1082
  end
1075
1083
  return ____self__139_58
1076
1084
  end,
1077
- set = function(self, killsOnExpiration)
1078
- if not killsOnExpiration and self[139] then
1085
+ set = function(self, providesInvulnerability)
1086
+ if not providesInvulnerability and self[139] then
1087
+ self.object:decrementInvulnerabilityCounter()
1079
1088
  self[139] = nil
1080
- elseif killsOnExpiration and not self[139] then
1089
+ elseif providesInvulnerability and not self[139] then
1090
+ self.object:incrementInvulnerabilityCounter()
1081
1091
  self[139] = true
1082
1092
  end
1083
1093
  end
@@ -1086,7 +1096,7 @@ __TS__SetDescriptor(
1086
1096
  )
1087
1097
  __TS__SetDescriptor(
1088
1098
  Buff.prototype,
1089
- "explodesOnExpiration",
1099
+ "killsOnExpiration",
1090
1100
  {
1091
1101
  get = function(self)
1092
1102
  local ____self__140_59 = self[140]
@@ -1105,6 +1115,27 @@ __TS__SetDescriptor(
1105
1115
  },
1106
1116
  true
1107
1117
  )
1118
+ __TS__SetDescriptor(
1119
+ Buff.prototype,
1120
+ "explodesOnExpiration",
1121
+ {
1122
+ get = function(self)
1123
+ local ____self__141_60 = self[141]
1124
+ if ____self__141_60 == nil then
1125
+ ____self__141_60 = false
1126
+ end
1127
+ return ____self__141_60
1128
+ end,
1129
+ set = function(self, killsOnExpiration)
1130
+ if not killsOnExpiration and self[141] then
1131
+ self[141] = nil
1132
+ elseif killsOnExpiration and not self[141] then
1133
+ self[141] = true
1134
+ end
1135
+ end
1136
+ },
1137
+ true
1138
+ )
1108
1139
  __TS__SetDescriptor(
1109
1140
  Buff.prototype,
1110
1141
  "maximumDamageDealtEventCount",
@@ -1221,13 +1252,13 @@ __TS__SetDescriptor(
1221
1252
  "remainingDuration",
1222
1253
  {
1223
1254
  get = function(self)
1224
- local ____opt_60 = self._timer
1225
- return ____opt_60 and ____opt_60.remaining or 0
1255
+ local ____opt_61 = self._timer
1256
+ return ____opt_61 and ____opt_61.remaining or 0
1226
1257
  end,
1227
1258
  set = function(self, remainingDuration)
1228
- local ____remainingDuration_64 = remainingDuration
1229
- local ____opt_62 = self._timer
1230
- local remainingDurationDelta = ____remainingDuration_64 - (____opt_62 and ____opt_62.remaining or 0)
1259
+ local ____remainingDuration_65 = remainingDuration
1260
+ local ____opt_63 = self._timer
1261
+ local remainingDurationDelta = ____remainingDuration_65 - (____opt_63 and ____opt_63.remaining or 0)
1231
1262
  if remainingDurationDelta ~= 0 then
1232
1263
  self[103] = self[103] + remainingDurationDelta
1233
1264
  if remainingDuration <= 0 then
@@ -1242,7 +1273,7 @@ __TS__SetDescriptor(
1242
1273
  remainingDuration,
1243
1274
  self._spellStealPriority,
1244
1275
  self._learnLevelMinimum,
1245
- self[141]
1276
+ self[142]
1246
1277
  ) then
1247
1278
  local timer = self._timer
1248
1279
  if timer == nil then
@@ -55,9 +55,13 @@ 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;
@@ -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
@@ -402,9 +403,25 @@ end
402
403
  function UnitAbility.prototype.decrementHideCounter(self)
403
404
  unitHideAbility(self.u, self.typeId, false)
404
405
  end
406
+ function UnitAbility.prototype.incrementDisableCounter(self)
407
+ unitDisableAbility(self.u, self.typeId, true, false)
408
+ self.d = (self.d or 0) + 1
409
+ end
410
+ function UnitAbility.prototype.decrementDisableCounter(self)
411
+ unitDisableAbility(self.u, self.typeId, false, false)
412
+ self.d = (self.d or 0) - 1
413
+ end
405
414
  function UnitAbility.prototype.interruptCast(self)
406
415
  self.owner:interruptCast(self.typeId)
407
416
  end
417
+ __TS__SetDescriptor(
418
+ UnitAbility.prototype,
419
+ "isDisabled",
420
+ {get = function(self)
421
+ return self.d ~= nil and self.d > 0
422
+ end},
423
+ true
424
+ )
408
425
  __TS__SetDescriptor(
409
426
  UnitAbility.prototype,
410
427
  "level",
@@ -55,22 +55,24 @@ local COOLDOWN_STARTER_ITEM_TYPE_ID = compiletime(function()
55
55
  itemType.activelyUsed = true
56
56
  return itemType.id
57
57
  end)
58
- local dummy = assert(CreateUnit(
58
+ ---
59
+ -- @internal For use by internal systems only.
60
+ ____exports.itemAbilityDummy = assert(CreateUnit(
59
61
  Player.neutralVictim.handle,
60
62
  dummyUnitId,
61
63
  0,
62
64
  0,
63
65
  270
64
66
  ))
65
- local cooldownStarterItem = UnitAddItemById(dummy, COOLDOWN_STARTER_ITEM_TYPE_ID)
67
+ local cooldownStarterItem = UnitAddItemById(____exports.itemAbilityDummy, COOLDOWN_STARTER_ITEM_TYPE_ID)
66
68
  local cooldownStarterAbility = BlzGetItemAbility(cooldownStarterItem, COOLDOWN_STARTER_ABILITY_TYPE_ID)
67
- ShowUnit(dummy, false)
69
+ ShowUnit(____exports.itemAbilityDummy, false)
68
70
  local function startItemCooldownInternal(handle, cooldown)
69
71
  local cooldownGroup = getItemIntegerField(handle, ITEM_IF_COOLDOWN_GROUP)
70
72
  setItemIntegerField(handle, ITEM_IF_COOLDOWN_GROUP, COOLDOWN_STARTER_ABILITY_TYPE_ID)
71
73
  setAbilityRealLevelField(cooldownStarterAbility, ABILITY_RLF_COOLDOWN, 0, cooldown)
72
- unitResetCooldown(dummy)
73
- unitUseItem(dummy, cooldownStarterItem)
74
+ unitResetCooldown(____exports.itemAbilityDummy)
75
+ unitUseItem(____exports.itemAbilityDummy, cooldownStarterItem)
74
76
  Timer:run(restoreCooldownGroup, handle, cooldownGroup)
75
77
  end
76
78
  restoreCooldownGroup = function(handle, cooldownGroup)
@@ -85,7 +87,7 @@ ____exports.startItemCooldown = function(handle, owner, cooldown)
85
87
  end
86
88
  ---
87
89
  -- @internal For use by internal systems only.
88
- ____exports.abilityActionDummy = dummy
90
+ ____exports.abilityActionDummy = ____exports.itemAbilityDummy
89
91
  ---
90
92
  -- @internal For use by internal systems only.
91
93
  ____exports.doAbilityAction = function(handle, action, ...)
@@ -104,11 +106,11 @@ ____exports.doAbilityAction = function(handle, action, ...)
104
106
  end
105
107
  x = getItemX(handle)
106
108
  y = getItemY(handle)
107
- unitAddItem(dummy, handle)
109
+ unitAddItem(____exports.itemAbilityDummy, handle)
108
110
  end
109
111
  local result = action(handle, ...)
110
112
  if not isOwned then
111
- unitRemoveItem(dummy, handle)
113
+ unitRemoveItem(____exports.itemAbilityDummy, handle)
112
114
  setItemPosition(handle, x, y)
113
115
  if isPowerup then
114
116
  setItemBooleanField(handle, ITEM_BF_USE_AUTOMATICALLY_WHEN_ACQUIRED, true)
@@ -139,9 +141,9 @@ ____exports.doAbilityActionForceDummy = function(handle, owner, action, ...)
139
141
  isPowerup = true
140
142
  end
141
143
  unitRemoveItem(owner, handle)
142
- unitAddItem(dummy, handle)
144
+ unitAddItem(____exports.itemAbilityDummy, handle)
143
145
  local result = action(handle, ...)
144
- unitRemoveItem(dummy, handle)
146
+ unitRemoveItem(____exports.itemAbilityDummy, handle)
145
147
  unitAddItemToSlot(owner, handle, slot)
146
148
  if isPowerup then
147
149
  setItemBooleanField(handle, ITEM_BF_USE_AUTOMATICALLY_WHEN_ACQUIRED, true)
@@ -5,8 +5,8 @@ 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
11
  ABILITIES = 100,
12
12
  LUA_INDEX_BY_ABILITY_TYPE_ID = 101
@@ -17,7 +17,7 @@ export declare class Item extends Handle<jitem> {
17
17
  constructor(handle: jitem);
18
18
  protected onDestroy(): HandleDestructor;
19
19
  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;
20
+ get typeId(): ItemTypeId;
21
21
  set skinId(v: number);
22
22
  get skinId(): number;
23
23
  set name(v: string);
@@ -73,6 +73,8 @@ export declare class Item extends Handle<jitem> {
73
73
  set position(v: Vec2);
74
74
  set charges(v: number);
75
75
  get charges(): number;
76
+ consumeCharge(): boolean;
77
+ consumeCharges(count: number): boolean;
76
78
  addAbility(abilityTypeId: AbilityTypeId): ItemAbility | undefined;
77
79
  removeAbility(abilityTypeId: AbilityTypeId): boolean;
78
80
  hasAbility(abilityTypeId: AbilityTypeId): boolean;
@@ -82,5 +84,6 @@ export declare class Item extends Handle<jitem> {
82
84
  static getInRect(rect: ReadonlyRect): Item[];
83
85
  static get onCreate(): Event<[Item]>;
84
86
  static get destroyEvent(): Event<[Item]>;
87
+ static readonly chargesChangedEvent: Event<[Item]>;
85
88
  }
86
89
  export {};
@@ -1,26 +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
18
24
  local ____dummy_2Ditem = require("engine.internal.object-data.dummy-item")
19
25
  local DUMMY_ITEM_ID = ____dummy_2Ditem.DUMMY_ITEM_ID
20
26
  local ____add_2Ditem_2Dto_2Dslot = require("engine.internal.unit.add-item-to-slot")
21
27
  local SLOT_FILLER_ITEM_TYPE_ID = ____add_2Ditem_2Dto_2Dslot.SLOT_FILLER_ITEM_TYPE_ID
22
28
  local ____vec2 = require("math.vec2")
23
29
  local distance = ____vec2.distance
30
+ local itemChargesChangeEvent = __TS__New(Event)
24
31
  local itemAddAbility = BlzItemAddAbility
25
32
  local itemRemoveAbility = BlzItemRemoveAbility
26
33
  local getItemAbility = BlzGetItemAbility
@@ -36,10 +43,26 @@ local getEnumItem = GetEnumItem
36
43
  local getItemTypeId = GetItemTypeId
37
44
  local getItemX = GetItemX
38
45
  local getItemY = GetItemY
46
+ local getItemCharges = GetItemCharges
47
+ local setItemCharges = SetItemCharges
48
+ local unitRemoveAbility = UnitRemoveAbility
49
+ local unitUseItem = UnitUseItem
50
+ local unitUseItemPoint = UnitUseItemPoint
51
+ local unitUseItemTarget = UnitUseItemTarget
52
+ _G.SetItemCharges = function(whichItem, charges)
53
+ setItemCharges(whichItem, charges)
54
+ invoke(
55
+ itemChargesChangeEvent,
56
+ ____exports.Item:of(whichItem)
57
+ )
58
+ end
39
59
  local getItemIntegerField = BlzGetItemIntegerField
40
60
  local setItemBooleanField = BlzSetItemBooleanField
41
61
  local getItemBooleanField = BlzGetItemBooleanField
62
+ invoke = Event.invoke
42
63
  local enumRect = Rect:create(0, 0, 0, 0).handle
64
+ ---
65
+ -- @internal For use by internal systems only.
43
66
  ____exports.addAndGetAbility = function(handle, abilityTypeId)
44
67
  if itemAddAbility(handle, abilityTypeId) then
45
68
  return getItemAbility(handle, abilityTypeId)
@@ -65,6 +88,23 @@ local function getItemAbilities(handle, item)
65
88
  end
66
89
  return abilities
67
90
  end
91
+ local function consumeCharge(handle)
92
+ do
93
+ local i = 0
94
+ local ability = getItemAbilityByIndex(handle, i)
95
+ while ability ~= nil do
96
+ unitRemoveAbility(
97
+ itemAbilityDummy,
98
+ getAbilityId(ability)
99
+ )
100
+ do
101
+ i = i + 1
102
+ ability = getItemAbilityByIndex(handle, i)
103
+ end
104
+ end
105
+ end
106
+ return unitUseItem(itemAbilityDummy, handle) or unitUseItemPoint(itemAbilityDummy, handle, 0, 0) or unitUseItemTarget(itemAbilityDummy, handle, itemAbilityDummy)
107
+ end
68
108
  local targetCollection
69
109
  local targetCollectionNextIndex
70
110
  local centerX
@@ -116,6 +156,36 @@ end
116
156
  function Item.create(self, id, x, y, skinId)
117
157
  return self:of(BlzCreateItemWithSkin(id, x, y, skinId or id))
118
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
119
189
  function Item.prototype.addAbility(self, abilityTypeId)
120
190
  local nativeAbility = doAbilityAction(self.handle, ____exports.addAndGetAbility, abilityTypeId)
121
191
  if nativeAbility ~= nil then
@@ -301,7 +371,7 @@ __TS__SetDescriptor(
301
371
  "perishable",
302
372
  {
303
373
  get = function(self)
304
- return BlzGetItemBooleanField(self.handle, ITEM_BF_PERISHABLE)
374
+ return getItemBooleanField(self.handle, ITEM_BF_PERISHABLE)
305
375
  end,
306
376
  set = function(self, v)
307
377
  BlzSetItemBooleanField(self.handle, ITEM_BF_PERISHABLE, v)
@@ -557,10 +627,11 @@ __TS__SetDescriptor(
557
627
  "charges",
558
628
  {
559
629
  get = function(self)
560
- return GetItemCharges(self.handle)
630
+ return getItemCharges(self.handle)
561
631
  end,
562
632
  set = function(self, v)
563
- SetItemCharges(self.handle, v)
633
+ setItemCharges(self.handle, v)
634
+ invoke(itemChargesChangeEvent, self)
564
635
  end
565
636
  },
566
637
  true
@@ -587,6 +658,7 @@ __TS__ObjectDefineProperty(
587
658
  return self.onDestroyEvent
588
659
  end}
589
660
  )
661
+ Item.chargesChangedEvent = itemChargesChangeEvent
590
662
  local getManipulatedItem = GetManipulatedItem
591
663
  local trigger = CreateTrigger()
592
664
  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
@@ -131,6 +131,11 @@ declare module "../unit" {
131
131
  const abilityNoTargetChannelingStartEvent: DispatchingEvent<[Unit, Ability]>;
132
132
  }
133
133
  }
134
+ declare module "../unit" {
135
+ namespace Unit {
136
+ const abilityImpactEvent: DispatchingEvent<[Unit, Ability]>;
137
+ }
138
+ }
134
139
  declare module "../unit" {
135
140
  namespace Unit {
136
141
  const abilityChannelingFinishEvent: DispatchingEvent<[Unit, Ability]>;
@@ -21,6 +21,8 @@ local ____preconditions = require("utility.preconditions")
21
21
  local checkNotNull = ____preconditions.checkNotNull
22
22
  local ____lazy = require("utility.lazy")
23
23
  local lazyRecord = ____lazy.lazyRecord
24
+ local ____timer = require("core.types.timer")
25
+ local Timer = ____timer.Timer
24
26
  local eventInvoke = Event.invoke
25
27
  local condition = Condition
26
28
  local createTrigger = CreateTrigger
@@ -345,6 +347,18 @@ rawset(
345
347
  extractAbilityTypeId
346
348
  )
347
349
  )
350
+ local internalAbilityImpactEvent = __TS__New(Event)
351
+ internalAbilityChannelingStartEvent:addListener(function(...)
352
+ Timer:run(eventInvoke, internalAbilityImpactEvent, ...)
353
+ end)
354
+ rawset(
355
+ Unit,
356
+ "abilityImpactEvent",
357
+ createDispatchingEvent(
358
+ createCommonEvent(internalAbilityImpactEvent),
359
+ extractAbilityTypeId
360
+ )
361
+ )
348
362
  rawset(
349
363
  Unit,
350
364
  "abilityChannelingFinishEvent",
@@ -2,7 +2,7 @@
2
2
  import { CombatClassifications } from "../../object-data/auxiliary/combat-classification";
3
3
  declare module "../unit" {
4
4
  interface Unit {
5
- isAllowedTarget(this: Unit, source: Unit, allowedTargetCombatClassifications: CombatClassifications): boolean;
5
+ isAllowedTarget(this: Unit, source: Unit, allowedTargetCombatClassifications?: CombatClassifications): boolean;
6
6
  }
7
7
  }
8
8
  declare module "../unit" {