warscript 0.0.1-dev.3af578d → 0.0.1-dev.3b2adda

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 (115) 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/order.d.ts +1 -0
  6. package/core/types/order.lua +11 -1
  7. package/core/types/sound.d.ts +17 -25
  8. package/core/types/sound.lua +91 -46
  9. package/core/types/timer.d.ts +6 -7
  10. package/core/types/timer.lua +18 -21
  11. package/core/util.lua +6 -1
  12. package/decl/native.d.ts +840 -786
  13. package/engine/behaviour/ability/apply-unit-behavior.lua +1 -0
  14. package/engine/behaviour/ability/damage.d.ts +9 -3
  15. package/engine/behaviour/ability/damage.lua +26 -38
  16. package/engine/behaviour/ability/emulate-impact.lua +7 -0
  17. package/engine/behaviour/ability.d.ts +5 -1
  18. package/engine/behaviour/ability.lua +18 -4
  19. package/engine/behaviour/unit.d.ts +12 -0
  20. package/engine/behaviour/unit.lua +85 -0
  21. package/engine/buff.d.ts +13 -8
  22. package/engine/buff.lua +81 -50
  23. package/engine/internal/ability.d.ts +2 -0
  24. package/engine/internal/ability.lua +7 -0
  25. package/engine/internal/item/ability.lua +12 -10
  26. package/engine/internal/item.d.ts +3 -1
  27. package/engine/internal/item.lua +46 -3
  28. package/engine/internal/mechanics/ability-duration.lua +1 -1
  29. package/engine/internal/misc/damage-metadata-by-target.d.ts +2 -0
  30. package/engine/internal/misc/damage-metadata-by-target.lua +5 -0
  31. package/engine/internal/unit/allowed-targets.d.ts +1 -1
  32. package/engine/internal/unit/allowed-targets.lua +9 -1
  33. package/engine/internal/unit+damage.d.ts +2 -11
  34. package/engine/internal/unit+damage.lua +10 -14
  35. package/engine/internal/unit+spellSteal.lua +1 -2
  36. package/engine/internal/unit-missile-launch.lua +1 -1
  37. package/engine/internal/unit.d.ts +25 -4
  38. package/engine/internal/unit.lua +154 -37
  39. package/engine/object-data/auxiliary/attachment-preset.d.ts +7 -2
  40. package/engine/object-data/auxiliary/attachment-preset.lua +4 -3
  41. package/engine/object-data/auxiliary/attack-type.d.ts +7 -8
  42. package/engine/object-data/auxiliary/attack-type.lua +42 -0
  43. package/engine/object-data/auxiliary/movement-type.d.ts +7 -7
  44. package/engine/object-data/auxiliary/movement-type.lua +22 -0
  45. package/engine/object-data/auxiliary/sound-eax.d.ts +10 -0
  46. package/engine/object-data/auxiliary/sound-eax.lua +2 -0
  47. package/engine/object-data/auxiliary/tech-tree-dependency.d.ts +1 -1
  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/blank-configurable.lua +0 -9
  53. package/engine/object-data/entry/ability-type/carrion-swarm.d.ts +14 -0
  54. package/engine/object-data/entry/ability-type/carrion-swarm.lua +65 -0
  55. package/engine/object-data/entry/ability-type/curse.lua +2 -2
  56. package/engine/object-data/entry/ability-type/disease-cloud.lua +2 -2
  57. package/engine/object-data/entry/ability-type/engineering-upgrade.lua +2 -2
  58. package/engine/object-data/entry/ability-type/ensnare.d.ts +12 -0
  59. package/engine/object-data/entry/ability-type/ensnare.lua +52 -0
  60. package/engine/object-data/entry/ability-type/feral-spirit.lua +2 -2
  61. package/engine/object-data/entry/ability-type/permanent-invisibility.d.ts +8 -0
  62. package/engine/object-data/entry/ability-type/permanent-invisibility.lua +26 -0
  63. package/engine/object-data/entry/ability-type/phase-shift.d.ts +10 -0
  64. package/engine/object-data/entry/ability-type/phase-shift.lua +39 -0
  65. package/engine/object-data/entry/ability-type/phoenix-morph.lua +4 -4
  66. package/engine/object-data/entry/ability-type/raise-dead.d.ts +17 -0
  67. package/engine/object-data/entry/ability-type/raise-dead.lua +78 -0
  68. package/engine/object-data/entry/ability-type/shock-wave.d.ts +4 -0
  69. package/engine/object-data/entry/ability-type/shock-wave.lua +26 -0
  70. package/engine/object-data/entry/ability-type/slow-poison.d.ts +10 -0
  71. package/engine/object-data/entry/ability-type/slow-poison.lua +58 -0
  72. package/engine/object-data/entry/ability-type/summon-quilbeast.lua +2 -2
  73. package/engine/object-data/entry/ability-type/summon-water-elemental.lua +2 -2
  74. package/engine/object-data/entry/ability-type/web.d.ts +12 -0
  75. package/engine/object-data/entry/ability-type/web.lua +52 -0
  76. package/engine/object-data/entry/ability-type.d.ts +19 -17
  77. package/engine/object-data/entry/ability-type.lua +81 -21
  78. package/engine/object-data/entry/buff-type/applicable.lua +9 -4
  79. package/engine/object-data/entry/buff-type.d.ts +6 -12
  80. package/engine/object-data/entry/buff-type.lua +13 -29
  81. package/engine/object-data/entry/destructible-type.d.ts +1 -1
  82. package/engine/object-data/entry/item-type.d.ts +1 -1
  83. package/engine/object-data/entry/item-type.lua +4 -4
  84. package/engine/object-data/entry/lightning-type.d.ts +1 -1
  85. package/engine/object-data/entry/sound-preset.d.ts +33 -0
  86. package/engine/object-data/entry/sound-preset.lua +140 -0
  87. package/engine/object-data/entry/unit-type.d.ts +3 -3
  88. package/engine/object-data/entry/unit-type.lua +105 -95
  89. package/engine/object-data/entry/upgrade.d.ts +1 -1
  90. package/engine/object-data/entry/upgrade.lua +4 -4
  91. package/engine/object-data/entry.d.ts +16 -14
  92. package/engine/object-data/entry.lua +60 -32
  93. package/engine/object-field/ability.d.ts +1 -1
  94. package/engine/object-field/unit.d.ts +46 -3
  95. package/engine/object-field/unit.lua +173 -7
  96. package/engine/object-field.d.ts +9 -1
  97. package/engine/object-field.lua +158 -76
  98. package/engine/standard/entries/buff-type.d.ts +3 -0
  99. package/engine/standard/entries/buff-type.lua +3 -0
  100. package/engine/standard/entries/sound-preset.d.ts +10 -0
  101. package/engine/standard/entries/sound-preset.lua +10 -0
  102. package/objutil/buff.lua +1 -2
  103. package/objutil/unit.lua +8 -0
  104. package/package.json +2 -2
  105. package/utility/arrays.d.ts +1 -0
  106. package/utility/arrays.lua +3 -0
  107. package/utility/functions.d.ts +1 -0
  108. package/utility/functions.lua +1 -0
  109. package/utility/linked-set.d.ts +1 -0
  110. package/utility/linked-set.lua +3 -0
  111. package/utility/lua-maps.d.ts +3 -0
  112. package/utility/lua-maps.lua +16 -0
  113. package/utility/lua-sets.d.ts +1 -0
  114. package/utility/lua-sets.lua +3 -0
  115. package/utility/reflection.lua +11 -7
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
@@ -58,6 +58,8 @@ export declare class UnitAbility extends Ability {
58
58
  constructor(handle: jability, typeId: number, owner: Unit);
59
59
  incrementHideCounter(): void;
60
60
  decrementHideCounter(): void;
61
+ incrementDisableCounter(): void;
62
+ decrementDisableCounter(): void;
61
63
  get level(): number;
62
64
  set level(v: number);
63
65
  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,6 +403,12 @@ 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
+ end
409
+ function UnitAbility.prototype.decrementDisableCounter(self)
410
+ unitDisableAbility(self.u, self.typeId, false, false)
411
+ end
405
412
  function UnitAbility.prototype.interruptCast(self)
406
413
  self.owner:interruptCast(self.typeId)
407
414
  end
@@ -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,6 +5,7 @@ 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
10
  export declare const addAndGetAbility: (handle: jitem, abilityTypeId: AbilityTypeId) => jability | null;
10
11
  declare const enum ItemPropertyKey {
@@ -17,7 +18,7 @@ export declare class Item extends Handle<jitem> {
17
18
  constructor(handle: jitem);
18
19
  protected onDestroy(): HandleDestructor;
19
20
  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;
21
+ get typeId(): ItemTypeId;
21
22
  set skinId(v: number);
22
23
  get skinId(): number;
23
24
  set name(v: string);
@@ -73,6 +74,7 @@ export declare class Item extends Handle<jitem> {
73
74
  set position(v: Vec2);
74
75
  set charges(v: number);
75
76
  get charges(): number;
77
+ consumeCharge(): boolean;
76
78
  addAbility(abilityTypeId: AbilityTypeId): ItemAbility | undefined;
77
79
  removeAbility(abilityTypeId: AbilityTypeId): boolean;
78
80
  hasAbility(abilityTypeId: AbilityTypeId): boolean;
@@ -15,6 +15,8 @@ local ____ability = require("engine.internal.ability")
15
15
  local ItemAbility = ____ability.ItemAbility
16
16
  local ____ability = require("engine.internal.item.ability")
17
17
  local doAbilityAction = ____ability.doAbilityAction
18
+ local doAbilityActionForceDummy = ____ability.doAbilityActionForceDummy
19
+ local itemAbilityDummy = ____ability.itemAbilityDummy
18
20
  local ____dummy_2Ditem = require("engine.internal.object-data.dummy-item")
19
21
  local DUMMY_ITEM_ID = ____dummy_2Ditem.DUMMY_ITEM_ID
20
22
  local ____add_2Ditem_2Dto_2Dslot = require("engine.internal.unit.add-item-to-slot")
@@ -36,6 +38,8 @@ local getEnumItem = GetEnumItem
36
38
  local getItemTypeId = GetItemTypeId
37
39
  local getItemX = GetItemX
38
40
  local getItemY = GetItemY
41
+ local getItemCharges = GetItemCharges
42
+ local setItemCharges = SetItemCharges
39
43
  local getItemIntegerField = BlzGetItemIntegerField
40
44
  local setItemBooleanField = BlzSetItemBooleanField
41
45
  local getItemBooleanField = BlzGetItemBooleanField
@@ -116,6 +120,45 @@ end
116
120
  function Item.create(self, id, x, y, skinId)
117
121
  return self:of(BlzCreateItemWithSkin(id, x, y, skinId or id))
118
122
  end
123
+ function Item.prototype.consumeCharge(self)
124
+ local handle = self.handle
125
+ local charges = getItemCharges(handle)
126
+ if charges >= 2 then
127
+ setItemCharges(handle, charges - 1)
128
+ return true
129
+ end
130
+ if charges == 1 then
131
+ if getItemBooleanField(handle, ITEM_BF_PERISHABLE) then
132
+ self:destroy()
133
+ return true
134
+ end
135
+ local ____doAbilityActionForceDummy_2 = doAbilityActionForceDummy
136
+ local ____opt_0 = self.owner
137
+ ____doAbilityActionForceDummy_2(
138
+ handle,
139
+ ____opt_0 and ____opt_0.handle,
140
+ function()
141
+ do
142
+ local i = 0
143
+ local ability = getItemAbilityByIndex(handle, i)
144
+ while ability ~= nil do
145
+ UnitRemoveAbility(
146
+ itemAbilityDummy,
147
+ getAbilityId(ability)
148
+ )
149
+ do
150
+ i = i + 1
151
+ ability = getItemAbilityByIndex(handle, i)
152
+ end
153
+ end
154
+ end
155
+ UnitUseItem(itemAbilityDummy, handle)
156
+ end
157
+ )
158
+ return true
159
+ end
160
+ return false
161
+ end
119
162
  function Item.prototype.addAbility(self, abilityTypeId)
120
163
  local nativeAbility = doAbilityAction(self.handle, ____exports.addAndGetAbility, abilityTypeId)
121
164
  if nativeAbility ~= nil then
@@ -301,7 +344,7 @@ __TS__SetDescriptor(
301
344
  "perishable",
302
345
  {
303
346
  get = function(self)
304
- return BlzGetItemBooleanField(self.handle, ITEM_BF_PERISHABLE)
347
+ return getItemBooleanField(self.handle, ITEM_BF_PERISHABLE)
305
348
  end,
306
349
  set = function(self, v)
307
350
  BlzSetItemBooleanField(self.handle, ITEM_BF_PERISHABLE, v)
@@ -557,10 +600,10 @@ __TS__SetDescriptor(
557
600
  "charges",
558
601
  {
559
602
  get = function(self)
560
- return GetItemCharges(self.handle)
603
+ return getItemCharges(self.handle)
561
604
  end,
562
605
  set = function(self, v)
563
- SetItemCharges(self.handle, v)
606
+ setItemCharges(self.handle, v)
564
607
  end
565
608
  },
566
609
  true
@@ -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
@@ -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" {
@@ -5,7 +5,15 @@ local initializeFilterTargetState = ____combat_2Dclassification.initializeFilter
5
5
  local ____unit = require("engine.internal.unit")
6
6
  local Unit = ____unit.Unit
7
7
  Unit.prototype.isAllowedTarget = function(self, source, allowedTargetCombatClassifications)
8
- initializeFilterTargetState(source, allowedTargetCombatClassifications)
8
+ if allowedTargetCombatClassifications ~= nil then
9
+ initializeFilterTargetState(source, allowedTargetCombatClassifications)
10
+ return filterTarget(self)
11
+ end
12
+ initializeFilterTargetState(source, source.firstWeapon.allowedTargetCombatClassifications)
13
+ if filterTarget(self) then
14
+ return true
15
+ end
16
+ initializeFilterTargetState(source, source.secondWeapon.allowedTargetCombatClassifications)
9
17
  return filterTarget(self)
10
18
  end
11
19
  Unit.getAllowedTargetsInRange = function(source, allowedTargetCombatClassifications, x, y, range)
@@ -1,15 +1,6 @@
1
1
  /** @noSelfInFile */
2
2
  import { Widget } from "../../core/types/widget";
3
- export type AttackType = jattacktype;
4
- export declare namespace AttackType {
5
- const SPELL: jattacktype;
6
- const NORMAL: jattacktype;
7
- const PIERCE: jattacktype;
8
- const SIEGE: jattacktype;
9
- const MAGIC: jattacktype;
10
- const CHAOS: jattacktype;
11
- const HERO: jattacktype;
12
- }
3
+ import { AttackType } from "../object-data/auxiliary/attack-type";
13
4
  export type DamageType = jdamagetype;
14
5
  export declare namespace DamageType {
15
6
  const UNKNOWN: jdamagetype;
@@ -64,6 +55,6 @@ export declare namespace WeaponType {
64
55
  }
65
56
  declare module "./unit" {
66
57
  interface Unit {
67
- damageTarget(target: Widget, amount: number, attack?: boolean, ranged?: boolean, attackType?: AttackType, damageType?: DamageType, weaponType?: WeaponType): boolean;
58
+ damageTarget(target: Widget, amount: number, attack?: boolean, ranged?: boolean, attackType?: AttackType, damageType?: DamageType, weaponType?: WeaponType, metadata?: unknown): boolean;
68
59
  }
69
60
  }
@@ -7,21 +7,14 @@ local ____player = require("core.types.player")
7
7
  local Player = ____player.Player
8
8
  local ____dummy = require("objutil.dummy")
9
9
  local dummyUnitId = ____dummy.dummyUnitId
10
+ local ____attack_2Dtype = require("engine.object-data.auxiliary.attack-type")
11
+ local attackTypeToNative = ____attack_2Dtype.attackTypeToNative
12
+ local ____damage_2Dmetadata_2Dby_2Dtarget = require("engine.internal.misc.damage-metadata-by-target")
13
+ local damageMetadataByTarget = ____damage_2Dmetadata_2Dby_2Dtarget.damageMetadataByTarget
10
14
  local createUnit = CreateUnit
11
15
  local getOwningPlayer = GetOwningPlayer
12
16
  local showUnit = ShowUnit
13
17
  local unitDamageTarget = UnitDamageTarget
14
- ____exports.AttackType = {}
15
- local AttackType = ____exports.AttackType
16
- do
17
- AttackType.SPELL = ATTACK_TYPE_NORMAL
18
- AttackType.NORMAL = ATTACK_TYPE_MELEE
19
- AttackType.PIERCE = ATTACK_TYPE_PIERCE
20
- AttackType.SIEGE = ATTACK_TYPE_SIEGE
21
- AttackType.MAGIC = ATTACK_TYPE_MAGIC
22
- AttackType.CHAOS = ATTACK_TYPE_CHAOS
23
- AttackType.HERO = ATTACK_TYPE_HERO
24
- end
25
18
  ____exports.DamageType = {}
26
19
  local DamageType = ____exports.DamageType
27
20
  do
@@ -88,7 +81,7 @@ for ____, player in ipairs(Player.all) do
88
81
  showUnit(dummy, false)
89
82
  dummies[player] = dummy
90
83
  end
91
- Unit.prototype.damageTarget = function(self, target, amount, attack, ranged, attackType, damageType, weaponType)
84
+ Unit.prototype.damageTarget = function(self, target, amount, attack, ranged, attackType, damageType, weaponType, metadata)
92
85
  if attack == nil then
93
86
  attack = false
94
87
  end
@@ -96,7 +89,7 @@ Unit.prototype.damageTarget = function(self, target, amount, attack, ranged, att
96
89
  ranged = false
97
90
  end
98
91
  if attackType == nil then
99
- attackType = ____exports.AttackType.SPELL
92
+ attackType = 0
100
93
  end
101
94
  if damageType == nil then
102
95
  damageType = ____exports.DamageType.MAGIC
@@ -109,13 +102,16 @@ Unit.prototype.damageTarget = function(self, target, amount, attack, ranged, att
109
102
  if not getOwningPlayer(handle) then
110
103
  handle = dummies[__TS__InstanceOf(target, Unit) and target.owner or (self._owner or Player.neutralAggressive)]
111
104
  end
105
+ if __TS__InstanceOf(target, Unit) then
106
+ damageMetadataByTarget[target] = metadata
107
+ end
112
108
  return unitDamageTarget(
113
109
  handle,
114
110
  targetHandle,
115
111
  amount,
116
112
  attack,
117
113
  ranged,
118
- attackType,
114
+ attackTypeToNative(attackType),
119
115
  damageType,
120
116
  weaponType
121
117
  )
@@ -6,7 +6,6 @@ local ____exports = {}
6
6
  local ____unit = require("engine.internal.unit")
7
7
  local Unit = ____unit.Unit
8
8
  local ____unit_2Bdamage = require("engine.internal.unit+damage")
9
- local AttackType = ____unit_2Bdamage.AttackType
10
9
  local DamageType = ____unit_2Bdamage.DamageType
11
10
  local ____event = require("event")
12
11
  local Event = ____event.Event
@@ -33,7 +32,7 @@ local spellStealEventStack = {}
33
32
  Unit.onDamaging:addListener(function(source, target, event)
34
33
  if event.amount == 0 and source ~= nil then
35
34
  local count = countByUnit[source] or 0
36
- if count > 0 and event.attackType == AttackType.SPELL then
35
+ if count > 0 and event.attackType == 0 then
37
36
  if event.damageType == DamageType.UNKNOWN then
38
37
  spellStealEventStack[#spellStealEventStack + 1] = {
39
38
  sourceBuffIds = source.buffIds,
@@ -44,7 +44,7 @@ local function timerCallback(source, target)
44
44
  Event.invoke(autoAttackFinishEvent, source, target)
45
45
  end
46
46
  Unit.autoAttackStartEvent:addListener(function(source, target)
47
- local attackPoint = source.weapons[1].impactDelay
47
+ local attackPoint = (source:chooseWeapon(target) or source.firstWeapon).impactDelay
48
48
  local timer = Timer:simple(attackPoint, timerCallback, source, target)
49
49
  eventTimerByUnit[source] = timer
50
50
  end)