warscript 0.0.1-dev.d842bb6 → 0.0.1-dev.dd8349d

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 (117) hide show
  1. package/attributes.d.ts +5 -0
  2. package/attributes.lua +8 -1
  3. package/config.d.ts +5 -0
  4. package/config.lua +10 -0
  5. package/core/types/effect.d.ts +1 -3
  6. package/core/types/effect.lua +26 -29
  7. package/core/types/order.d.ts +1 -0
  8. package/core/types/order.lua +11 -1
  9. package/core/types/sound.d.ts +17 -25
  10. package/core/types/sound.lua +91 -46
  11. package/core/types/timer.d.ts +6 -7
  12. package/core/types/timer.lua +18 -21
  13. package/core/util.lua +6 -1
  14. package/decl/native.d.ts +840 -786
  15. package/engine/behaviour/ability/apply-unit-behavior.lua +1 -0
  16. package/engine/behaviour/ability/damage.d.ts +9 -3
  17. package/engine/behaviour/ability/damage.lua +26 -38
  18. package/engine/behaviour/ability/emulate-impact.lua +7 -0
  19. package/engine/behaviour/ability.d.ts +5 -1
  20. package/engine/behaviour/ability.lua +18 -4
  21. package/engine/behaviour/unit.d.ts +16 -0
  22. package/engine/behaviour/unit.lua +109 -4
  23. package/engine/buff.d.ts +13 -8
  24. package/engine/buff.lua +81 -50
  25. package/engine/internal/ability.d.ts +2 -0
  26. package/engine/internal/ability.lua +7 -0
  27. package/engine/internal/item/ability.lua +12 -10
  28. package/engine/internal/item.d.ts +4 -2
  29. package/engine/internal/item.lua +71 -3
  30. package/engine/internal/mechanics/ability-duration.lua +1 -1
  31. package/engine/internal/misc/damage-metadata-by-target.d.ts +2 -0
  32. package/engine/internal/misc/damage-metadata-by-target.lua +5 -0
  33. package/engine/internal/unit/allowed-targets.d.ts +1 -1
  34. package/engine/internal/unit/allowed-targets.lua +9 -1
  35. package/engine/internal/unit+damage.d.ts +2 -11
  36. package/engine/internal/unit+damage.lua +10 -14
  37. package/engine/internal/unit+spellSteal.lua +1 -2
  38. package/engine/internal/unit-missile-launch.lua +1 -1
  39. package/engine/internal/unit.d.ts +26 -4
  40. package/engine/internal/unit.lua +169 -37
  41. package/engine/object-data/auxiliary/attachment-preset.d.ts +7 -2
  42. package/engine/object-data/auxiliary/attachment-preset.lua +4 -3
  43. package/engine/object-data/auxiliary/attack-type.d.ts +7 -8
  44. package/engine/object-data/auxiliary/attack-type.lua +42 -0
  45. package/engine/object-data/auxiliary/movement-type.d.ts +7 -7
  46. package/engine/object-data/auxiliary/movement-type.lua +22 -0
  47. package/engine/object-data/auxiliary/sound-eax.d.ts +10 -0
  48. package/engine/object-data/auxiliary/sound-eax.lua +2 -0
  49. package/engine/object-data/auxiliary/tech-tree-dependency.d.ts +1 -1
  50. package/engine/object-data/auxiliary/unit-attribute.d.ts +6 -0
  51. package/engine/object-data/auxiliary/unit-attribute.lua +9 -0
  52. package/engine/object-data/entry/ability-type/berserk.d.ts +2 -0
  53. package/engine/object-data/entry/ability-type/berserk.lua +13 -0
  54. package/engine/object-data/entry/ability-type/blank-configurable.lua +0 -9
  55. package/engine/object-data/entry/ability-type/carrion-swarm.d.ts +14 -0
  56. package/engine/object-data/entry/ability-type/carrion-swarm.lua +65 -0
  57. package/engine/object-data/entry/ability-type/curse.lua +2 -2
  58. package/engine/object-data/entry/ability-type/disease-cloud.lua +2 -2
  59. package/engine/object-data/entry/ability-type/engineering-upgrade.lua +2 -2
  60. package/engine/object-data/entry/ability-type/ensnare.d.ts +12 -0
  61. package/engine/object-data/entry/ability-type/ensnare.lua +52 -0
  62. package/engine/object-data/entry/ability-type/feral-spirit.lua +2 -2
  63. package/engine/object-data/entry/ability-type/permanent-invisibility.d.ts +8 -0
  64. package/engine/object-data/entry/ability-type/permanent-invisibility.lua +26 -0
  65. package/engine/object-data/entry/ability-type/phase-shift.d.ts +10 -0
  66. package/engine/object-data/entry/ability-type/phase-shift.lua +39 -0
  67. package/engine/object-data/entry/ability-type/phoenix-morph.lua +4 -4
  68. package/engine/object-data/entry/ability-type/raise-dead.d.ts +17 -0
  69. package/engine/object-data/entry/ability-type/raise-dead.lua +78 -0
  70. package/engine/object-data/entry/ability-type/shock-wave.d.ts +4 -0
  71. package/engine/object-data/entry/ability-type/shock-wave.lua +26 -0
  72. package/engine/object-data/entry/ability-type/slow-poison.d.ts +10 -0
  73. package/engine/object-data/entry/ability-type/slow-poison.lua +58 -0
  74. package/engine/object-data/entry/ability-type/summon-quilbeast.lua +2 -2
  75. package/engine/object-data/entry/ability-type/summon-water-elemental.lua +2 -2
  76. package/engine/object-data/entry/ability-type/web.d.ts +12 -0
  77. package/engine/object-data/entry/ability-type/web.lua +52 -0
  78. package/engine/object-data/entry/ability-type.d.ts +19 -17
  79. package/engine/object-data/entry/ability-type.lua +81 -21
  80. package/engine/object-data/entry/buff-type/applicable.lua +9 -4
  81. package/engine/object-data/entry/buff-type.d.ts +6 -12
  82. package/engine/object-data/entry/buff-type.lua +13 -29
  83. package/engine/object-data/entry/destructible-type.d.ts +1 -1
  84. package/engine/object-data/entry/item-type.d.ts +1 -1
  85. package/engine/object-data/entry/item-type.lua +4 -4
  86. package/engine/object-data/entry/lightning-type.d.ts +1 -1
  87. package/engine/object-data/entry/sound-preset.d.ts +33 -0
  88. package/engine/object-data/entry/sound-preset.lua +140 -0
  89. package/engine/object-data/entry/unit-type.d.ts +10 -3
  90. package/engine/object-data/entry/unit-type.lua +155 -92
  91. package/engine/object-data/entry/upgrade.d.ts +1 -1
  92. package/engine/object-data/entry/upgrade.lua +4 -4
  93. package/engine/object-data/entry.d.ts +16 -14
  94. package/engine/object-data/entry.lua +60 -32
  95. package/engine/object-field/ability.d.ts +1 -1
  96. package/engine/object-field/unit.d.ts +46 -3
  97. package/engine/object-field/unit.lua +173 -7
  98. package/engine/object-field.d.ts +9 -1
  99. package/engine/object-field.lua +158 -76
  100. package/engine/standard/entries/buff-type.d.ts +3 -0
  101. package/engine/standard/entries/buff-type.lua +3 -0
  102. package/engine/standard/entries/sound-preset.d.ts +10 -0
  103. package/engine/standard/entries/sound-preset.lua +10 -0
  104. package/objutil/buff.lua +1 -2
  105. package/objutil/unit.lua +8 -0
  106. package/package.json +2 -2
  107. package/utility/arrays.d.ts +1 -0
  108. package/utility/arrays.lua +3 -0
  109. package/utility/functions.d.ts +1 -0
  110. package/utility/functions.lua +1 -0
  111. package/utility/linked-set.d.ts +1 -0
  112. package/utility/linked-set.lua +3 -0
  113. package/utility/lua-maps.d.ts +3 -0
  114. package/utility/lua-maps.lua +16 -0
  115. package/utility/lua-sets.d.ts +1 -0
  116. package/utility/lua-sets.lua +3 -0
  117. 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,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,7 @@ 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;
76
77
  addAbility(abilityTypeId: AbilityTypeId): ItemAbility | undefined;
77
78
  removeAbility(abilityTypeId: AbilityTypeId): boolean;
78
79
  hasAbility(abilityTypeId: AbilityTypeId): boolean;
@@ -82,5 +83,6 @@ export declare class Item extends Handle<jitem> {
82
83
  static getInRect(rect: ReadonlyRect): Item[];
83
84
  static get onCreate(): Event<[Item]>;
84
85
  static get destroyEvent(): Event<[Item]>;
86
+ static readonly chargesChangedEvent: Event<[Item]>;
85
87
  }
86
88
  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,32 @@ 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
+ local handle = self.handle
161
+ local charges = getItemCharges(handle)
162
+ if charges >= 2 then
163
+ setItemCharges(handle, charges - 1)
164
+ invoke(itemChargesChangeEvent, self)
165
+ return true
166
+ end
167
+ if charges == 1 then
168
+ if getItemBooleanField(handle, ITEM_BF_PERISHABLE) then
169
+ self:destroy()
170
+ return true
171
+ end
172
+ if not getItemBooleanField(handle, ITEM_BF_ACTIVELY_USED) then
173
+ setItemCharges(handle, 0)
174
+ invoke(itemChargesChangeEvent, self)
175
+ return true
176
+ end
177
+ local ____doAbilityActionForceDummy_2 = doAbilityActionForceDummy
178
+ local ____opt_0 = self.owner
179
+ ____doAbilityActionForceDummy_2(handle, ____opt_0 and ____opt_0.handle, consumeCharge)
180
+ invoke(itemChargesChangeEvent, self)
181
+ return true
182
+ end
183
+ return false
184
+ end
119
185
  function Item.prototype.addAbility(self, abilityTypeId)
120
186
  local nativeAbility = doAbilityAction(self.handle, ____exports.addAndGetAbility, abilityTypeId)
121
187
  if nativeAbility ~= nil then
@@ -301,7 +367,7 @@ __TS__SetDescriptor(
301
367
  "perishable",
302
368
  {
303
369
  get = function(self)
304
- return BlzGetItemBooleanField(self.handle, ITEM_BF_PERISHABLE)
370
+ return getItemBooleanField(self.handle, ITEM_BF_PERISHABLE)
305
371
  end,
306
372
  set = function(self, v)
307
373
  BlzSetItemBooleanField(self.handle, ITEM_BF_PERISHABLE, v)
@@ -557,10 +623,11 @@ __TS__SetDescriptor(
557
623
  "charges",
558
624
  {
559
625
  get = function(self)
560
- return GetItemCharges(self.handle)
626
+ return getItemCharges(self.handle)
561
627
  end,
562
628
  set = function(self, v)
563
- SetItemCharges(self.handle, v)
629
+ setItemCharges(self.handle, v)
630
+ invoke(itemChargesChangeEvent, self)
564
631
  end
565
632
  },
566
633
  true
@@ -587,6 +654,7 @@ __TS__ObjectDefineProperty(
587
654
  return self.onDestroyEvent
588
655
  end}
589
656
  )
657
+ Item.chargesChangedEvent = itemChargesChangeEvent
590
658
  local getManipulatedItem = GetManipulatedItem
591
659
  local trigger = CreateTrigger()
592
660
  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
@@ -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
  }