warscript 0.0.1-dev.3bc4ba4 → 0.0.1-dev.3c953c8

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 (95) hide show
  1. package/attributes.d.ts +1 -0
  2. package/attributes.lua +9 -0
  3. package/core/types/frame.lua +24 -21
  4. package/core/types/player.d.ts +15 -0
  5. package/core/types/player.lua +56 -14
  6. package/core/types/playerCamera.d.ts +2 -0
  7. package/core/types/playerCamera.lua +123 -5
  8. package/core/types/tileCell.d.ts +11 -1
  9. package/core/types/tileCell.lua +97 -0
  10. package/core/types/timer.d.ts +3 -1
  11. package/core/types/timer.lua +27 -2
  12. package/decl/native.d.ts +6 -4
  13. package/engine/behavior.d.ts +12 -1
  14. package/engine/behavior.lua +172 -70
  15. package/engine/behaviour/ability/apply-buff.lua +1 -1
  16. package/engine/behaviour/ability/emulate-impact.d.ts +1 -1
  17. package/engine/behaviour/ability/emulate-impact.lua +2 -1
  18. package/engine/behaviour/ability/remove-buffs.d.ts +9 -0
  19. package/engine/behaviour/ability/remove-buffs.lua +21 -0
  20. package/engine/behaviour/ability/restore-mana.d.ts +1 -1
  21. package/engine/behaviour/ability/restore-mana.lua +6 -6
  22. package/engine/behaviour/ability.lua +7 -16
  23. package/engine/behaviour/unit/stun-immunity.d.ts +9 -3
  24. package/engine/behaviour/unit/stun-immunity.lua +53 -28
  25. package/engine/behaviour/unit.d.ts +21 -4
  26. package/engine/behaviour/unit.lua +85 -9
  27. package/engine/buff.d.ts +12 -5
  28. package/engine/buff.lua +125 -87
  29. package/engine/internal/ability.d.ts +3 -1
  30. package/engine/internal/ability.lua +34 -11
  31. package/engine/internal/item/ability.lua +51 -1
  32. package/engine/internal/item+owner.lua +12 -6
  33. package/engine/internal/item.d.ts +13 -15
  34. package/engine/internal/item.lua +63 -49
  35. package/engine/internal/misc/frame-coordinates.d.ts +2 -0
  36. package/engine/internal/misc/frame-coordinates.lua +21 -0
  37. package/engine/internal/misc/get-terrain-z.d.ts +2 -0
  38. package/engine/internal/misc/get-terrain-z.lua +11 -0
  39. package/engine/internal/misc/player-local-handle.d.ts +2 -0
  40. package/engine/internal/misc/player-local-handle.lua +5 -0
  41. package/engine/internal/unit/ability.d.ts +35 -5
  42. package/engine/internal/unit/ability.lua +96 -21
  43. package/engine/internal/unit/fly-height.d.ts +7 -0
  44. package/engine/internal/unit/fly-height.lua +20 -0
  45. package/engine/internal/unit/main-selected.lua +12 -27
  46. package/engine/internal/unit/order.d.ts +20 -0
  47. package/engine/internal/unit/order.lua +136 -0
  48. package/engine/internal/unit/scale.d.ts +7 -0
  49. package/engine/internal/unit/scale.lua +20 -0
  50. package/engine/internal/unit+ability.lua +10 -1
  51. package/engine/internal/unit-missile-launch.lua +45 -14
  52. package/engine/internal/unit.d.ts +19 -16
  53. package/engine/internal/unit.lua +170 -136
  54. package/engine/local-client.d.ts +2 -0
  55. package/engine/local-client.lua +30 -0
  56. package/engine/object-data/auxiliary/armor-type.d.ts +11 -0
  57. package/engine/object-data/auxiliary/armor-type.lua +46 -0
  58. package/engine/object-data/entry/ability-type.lua +5 -4
  59. package/engine/object-data/entry/unit-type.d.ts +11 -2
  60. package/engine/object-data/entry/unit-type.lua +59 -1
  61. package/engine/object-field/ability.d.ts +3 -3
  62. package/engine/object-field/ability.lua +7 -6
  63. package/engine/object-field/unit.d.ts +24 -1
  64. package/engine/object-field/unit.lua +91 -0
  65. package/engine/object-field.d.ts +9 -3
  66. package/engine/object-field.lua +204 -115
  67. package/engine/random.d.ts +9 -0
  68. package/engine/random.lua +13 -0
  69. package/engine/standard/fields/unit.d.ts +6 -0
  70. package/engine/standard/fields/unit.lua +11 -0
  71. package/engine/synchronization.d.ts +11 -0
  72. package/engine/synchronization.lua +77 -0
  73. package/engine/text-tag.d.ts +26 -3
  74. package/engine/text-tag.lua +217 -11
  75. package/engine/unit.d.ts +3 -0
  76. package/engine/unit.lua +3 -0
  77. package/net/socket.lua +1 -1
  78. package/objutil/buff.lua +1 -1
  79. package/package.json +2 -2
  80. package/patch-lualib.lua +1 -1
  81. package/utility/arrays.d.ts +1 -0
  82. package/utility/arrays.lua +8 -0
  83. package/utility/callback-array.d.ts +17 -0
  84. package/utility/callback-array.lua +61 -0
  85. package/utility/functions.d.ts +7 -0
  86. package/utility/functions.lua +12 -0
  87. package/utility/linked-set.d.ts +1 -0
  88. package/utility/linked-set.lua +19 -1
  89. package/utility/lua-maps.d.ts +11 -2
  90. package/utility/lua-maps.lua +33 -2
  91. package/utility/lua-sets.d.ts +1 -0
  92. package/utility/lua-sets.lua +4 -0
  93. package/utility/types.d.ts +3 -0
  94. package/core/types/order.d.ts +0 -26
  95. package/core/types/order.lua +0 -65
package/engine/buff.lua CHANGED
@@ -16,6 +16,7 @@ local internalApplyBuff = ____applicable.internalApplyBuff
16
16
  local removeBuff = ____applicable.removeBuff
17
17
  local ____ability = require("engine.internal.ability")
18
18
  local Ability = ____ability.Ability
19
+ local UnitAbility = ____ability.UnitAbility
19
20
  local ____ability = require("engine.object-field.ability")
20
21
  local AbilityBooleanField = ____ability.AbilityBooleanField
21
22
  local AbilityNumberField = ____ability.AbilityNumberField
@@ -28,9 +29,6 @@ local ____math = require("math")
28
29
  local max = ____math.max
29
30
  local min = ____math.min
30
31
  local ____bonus = require("engine.internal.unit.bonus")
31
- local addOrUpdateOrRemoveUnitBonus = ____bonus.addOrUpdateOrRemoveUnitBonus
32
- local getUnitBonus = ____bonus.getUnitBonus
33
- local removeUnitBonus = ____bonus.removeUnitBonus
34
32
  local UnitBonusType = ____bonus.UnitBonusType
35
33
  local ____area_2Ddamage = require("engine.internal.mechanics.area-damage")
36
34
  local damageArea = ____area_2Ddamage.damageArea
@@ -53,6 +51,8 @@ local ____item = require("engine.internal.item")
53
51
  local Item = ____item.Item
54
52
  local ____destructable = require("core.types.destructable")
55
53
  local Destructable = ____destructable.Destructable
54
+ local ____ability = require("engine.standard.fields.ability")
55
+ local COOLDOWN_ABILITY_FLOAT_LEVEL_FIELD = ____ability.COOLDOWN_ABILITY_FLOAT_LEVEL_FIELD
56
56
  local getUnitAbility = BlzGetUnitAbility
57
57
  local stringValueByBuffTypeIdByFieldId = postcompile(function()
58
58
  local stringValueByBuffTypeIdByFieldId = {}
@@ -124,7 +124,8 @@ local buffParametersKeys = {
124
124
  damageOnExpiration = true,
125
125
  healingOnExpiration = true,
126
126
  killsOnExpiration = true,
127
- explodesOnExpiration = true
127
+ explodesOnExpiration = true,
128
+ abilityCooldownFactor = true
128
129
  }
129
130
  local function resolveEnumValue(ability, level, value)
130
131
  if value == nil or type(value) == "number" then
@@ -201,7 +202,8 @@ local buffNumberParameters = {
201
202
  "healingPerInterval",
202
203
  "healingOverDuration",
203
204
  "damageOnExpiration",
204
- "healingOnExpiration"
205
+ "healingOnExpiration",
206
+ "abilityCooldownFactor"
205
207
  }
206
208
  local unsuccessfulApplicationMarker = {}
207
209
  local function selectBuffTypeIdWithLeastDuration(buffTypeIds, unit)
@@ -304,7 +306,8 @@ buffHealingIntervalTimerCallback = function(buff)
304
306
  source:healTarget(buff[101], healingPerInterval)
305
307
  end
306
308
  end
307
- local buffDestroyEvent = __TS__New(Event)
309
+ local buffCreatedEvent = __TS__New(Event)
310
+ local buffBeingDestroyedEvent = __TS__New(Event)
308
311
  ____exports.Buff = __TS__Class()
309
312
  local Buff = ____exports.Buff
310
313
  Buff.name = "Buff"
@@ -506,64 +509,68 @@ function Buff.prototype.____constructor(self, _unit, typeIdOrTypeIds, polarityOr
506
509
  end
507
510
  self:onCreate()
508
511
  self[100] = 1
512
+ Event.invoke(buffCreatedEvent, self)
509
513
  end
510
- function Buff.prototype.getUnitBonus(self, bonusType)
511
- local ____opt_38 = self._bonusIdByBonusType
512
- local bonusId = ____opt_38 and ____opt_38[bonusType]
513
- return bonusId == nil and 0 or getUnitBonus(self._unit, bonusType, bonusId)
514
+ function Buff.prototype.onAbilityGained(self, ability)
515
+ if __TS__InstanceOf(ability, UnitAbility) then
516
+ local abilityCooldownModifier = self[144]
517
+ if abilityCooldownModifier then
518
+ COOLDOWN_ABILITY_FLOAT_LEVEL_FIELD:applyModifier(ability, abilityCooldownModifier)
519
+ end
520
+ end
514
521
  end
515
- function Buff.prototype.addOrUpdateOrRemoveUnitBonus(self, bonusType, value)
516
- local bonusIdByBonusType = self._bonusIdByBonusType
517
- if bonusIdByBonusType == nil then
518
- bonusIdByBonusType = {}
519
- self._bonusIdByBonusType = bonusIdByBonusType
522
+ function Buff.prototype.onAbilityLost(self, ability)
523
+ if __TS__InstanceOf(ability, UnitAbility) then
524
+ local abilityCooldownModifier = self[144]
525
+ if abilityCooldownModifier then
526
+ COOLDOWN_ABILITY_FLOAT_LEVEL_FIELD:removeModifier(ability, abilityCooldownModifier)
527
+ end
520
528
  end
521
- bonusIdByBonusType[bonusType] = addOrUpdateOrRemoveUnitBonus(self._unit, bonusType, bonusIdByBonusType[bonusType], value)
522
529
  end
523
530
  function Buff.prototype.flashEffect(self, widgetOrXOrParametersOrDuration, yOrParametersOrDuration, parametersOrDuration)
524
531
  if type(widgetOrXOrParametersOrDuration) == "number" and type(yOrParametersOrDuration) == "number" then
525
532
  Effect:flash(self[105], widgetOrXOrParametersOrDuration, yOrParametersOrDuration, parametersOrDuration)
526
533
  else
527
534
  local isWidgetProvided = __TS__InstanceOf(widgetOrXOrParametersOrDuration, Unit) or __TS__InstanceOf(widgetOrXOrParametersOrDuration, Item) or __TS__InstanceOf(widgetOrXOrParametersOrDuration, Destructable)
528
- local ____Effect_42 = Effect
529
- local ____Effect_flash_43 = Effect.flash
530
- local ____array_41 = __TS__SparseArrayNew(
535
+ local ____Effect_40 = Effect
536
+ local ____Effect_flash_41 = Effect.flash
537
+ local ____array_39 = __TS__SparseArrayNew(
531
538
  self[105],
532
539
  isWidgetProvided and widgetOrXOrParametersOrDuration or self._unit,
533
540
  stringValueByBuffTypeIdByFieldId[fourCC("feft")][self.typeId] or "origin"
534
541
  )
535
- local ____isWidgetProvided_40
542
+ local ____isWidgetProvided_38
536
543
  if isWidgetProvided then
537
- ____isWidgetProvided_40 = yOrParametersOrDuration
544
+ ____isWidgetProvided_38 = yOrParametersOrDuration
538
545
  else
539
- ____isWidgetProvided_40 = widgetOrXOrParametersOrDuration
546
+ ____isWidgetProvided_38 = widgetOrXOrParametersOrDuration
540
547
  end
541
- __TS__SparseArrayPush(____array_41, ____isWidgetProvided_40)
542
- ____Effect_flash_43(
543
- ____Effect_42,
544
- __TS__SparseArraySpread(____array_41)
548
+ __TS__SparseArrayPush(____array_39, ____isWidgetProvided_38)
549
+ ____Effect_flash_41(
550
+ ____Effect_40,
551
+ __TS__SparseArraySpread(____array_39)
545
552
  )
546
553
  end
547
554
  end
548
555
  function Buff.prototype.flashSpecialEffect(self, widgetOrDuration, duration)
549
556
  local isWidgetProvided = type(widgetOrDuration) == "table"
550
- local ____Effect_46 = Effect
551
- local ____Effect_flash_47 = Effect.flash
552
- local ____array_45 = __TS__SparseArrayNew(
557
+ local ____Effect_44 = Effect
558
+ local ____Effect_flash_45 = Effect.flash
559
+ local ____array_43 = __TS__SparseArrayNew(
553
560
  self[106],
554
561
  isWidgetProvided and widgetOrDuration or self._unit,
555
562
  stringValueByBuffTypeIdByFieldId[fourCC("fspt")][self.typeId] or "origin"
556
563
  )
557
- local ____isWidgetProvided_44
564
+ local ____isWidgetProvided_42
558
565
  if isWidgetProvided then
559
- ____isWidgetProvided_44 = duration
566
+ ____isWidgetProvided_42 = duration
560
567
  else
561
- ____isWidgetProvided_44 = widgetOrDuration
568
+ ____isWidgetProvided_42 = widgetOrDuration
562
569
  end
563
- __TS__SparseArrayPush(____array_45, ____isWidgetProvided_44)
564
- ____Effect_flash_47(
565
- ____Effect_46,
566
- __TS__SparseArraySpread(____array_45)
570
+ __TS__SparseArrayPush(____array_43, ____isWidgetProvided_42)
571
+ ____Effect_flash_45(
572
+ ____Effect_44,
573
+ __TS__SparseArraySpread(____array_43)
567
574
  )
568
575
  end
569
576
  function Buff.prototype.onCreate(self)
@@ -594,6 +601,12 @@ function Buff.prototype.onDestroy(self)
594
601
  behavior:destroy()
595
602
  end
596
603
  end
604
+ local previousAbilityCooldownModifier = self[144]
605
+ if previousAbilityCooldownModifier then
606
+ for ____, ability in ipairs(self._unit.abilities) do
607
+ COOLDOWN_ABILITY_FLOAT_LEVEL_FIELD:removeModifier(ability, previousAbilityCooldownModifier)
608
+ end
609
+ end
597
610
  if self[139] then
598
611
  unit:decrementInvulnerabilityCounter()
599
612
  end
@@ -602,7 +615,7 @@ function Buff.prototype.onDestroy(self)
602
615
  end
603
616
  if self[136] then
604
617
  if self[137] then
605
- unit:decrementStunCounter()
618
+ unit:decrementForceStunCounter()
606
619
  end
607
620
  unit:decrementStunCounter()
608
621
  end
@@ -614,12 +627,7 @@ function Buff.prototype.onDestroy(self)
614
627
  unit:removeAbility(abilityTypeId)
615
628
  end
616
629
  end
617
- if self._bonusIdByBonusType ~= nil then
618
- for bonusType, bonusId in pairs(self._bonusIdByBonusType) do
619
- removeUnitBonus(unit, bonusType, bonusId)
620
- end
621
- end
622
- Event.invoke(buffDestroyEvent, self)
630
+ Event.invoke(buffBeingDestroyedEvent, self)
623
631
  self[100] = 3
624
632
  return UnitBehavior.prototype.onDestroy(self)
625
633
  end
@@ -648,8 +656,8 @@ function Buff.apply(self, ...)
648
656
  end
649
657
  end
650
658
  function Buff.getByTypeId(self, unit, typeId)
651
- local ____opt_48 = buffByTypeIdByUnit[unit]
652
- local buff = ____opt_48 and ____opt_48[typeId]
659
+ local ____opt_46 = buffByTypeIdByUnit[unit]
660
+ local buff = ____opt_46 and ____opt_46[typeId]
653
661
  if __TS__InstanceOf(buff, self) then
654
662
  return buff
655
663
  end
@@ -807,8 +815,8 @@ __TS__SetDescriptor(
807
815
  return
808
816
  end
809
817
  self[112] = damageInterval
810
- local ____opt_50 = self._timer
811
- local elapsed = ____opt_50 and ____opt_50.elapsed or 0
818
+ local ____opt_48 = self._timer
819
+ local elapsed = ____opt_48 and ____opt_48.elapsed or 0
812
820
  local timer = self[114]
813
821
  if timer == nil then
814
822
  timer = Timer:create()
@@ -887,8 +895,8 @@ __TS__SetDescriptor(
887
895
  return
888
896
  end
889
897
  self[117] = healingInterval
890
- local ____opt_52 = self._timer
891
- local elapsed = ____opt_52 and ____opt_52.elapsed or 0
898
+ local ____opt_50 = self._timer
899
+ local elapsed = ____opt_50 and ____opt_50.elapsed or 0
892
900
  local timer = self[119]
893
901
  if timer == nil then
894
902
  timer = Timer:create()
@@ -974,11 +982,11 @@ __TS__SetDescriptor(
974
982
  "turnsIntoGhost",
975
983
  {
976
984
  get = function(self)
977
- local ____self__135_54 = self[135]
978
- if ____self__135_54 == nil then
979
- ____self__135_54 = false
985
+ local ____self__135_52 = self[135]
986
+ if ____self__135_52 == nil then
987
+ ____self__135_52 = false
980
988
  end
981
- return ____self__135_54
989
+ return ____self__135_52
982
990
  end,
983
991
  set = function(self, turnsIntoGhost)
984
992
  if not turnsIntoGhost and self[135] then
@@ -997,22 +1005,22 @@ __TS__SetDescriptor(
997
1005
  "stuns",
998
1006
  {
999
1007
  get = function(self)
1000
- local ____self__136_55 = self[136]
1001
- if ____self__136_55 == nil then
1002
- ____self__136_55 = false
1008
+ local ____self__136_53 = self[136]
1009
+ if ____self__136_53 == nil then
1010
+ ____self__136_53 = false
1003
1011
  end
1004
- return ____self__136_55
1012
+ return ____self__136_53
1005
1013
  end,
1006
1014
  set = function(self, stuns)
1007
1015
  if not stuns and self[136] then
1008
1016
  if self[137] then
1009
- self.object:decrementStunCounter()
1017
+ self.object:decrementForceStunCounter()
1010
1018
  end
1011
1019
  self.object:decrementStunCounter()
1012
1020
  self[136] = nil
1013
1021
  elseif stuns and not self[136] then
1014
1022
  if self[137] then
1015
- self.object:incrementStunCounter()
1023
+ self.object:incrementForceStunCounter()
1016
1024
  end
1017
1025
  self.object:incrementStunCounter()
1018
1026
  self[136] = true
@@ -1026,21 +1034,21 @@ __TS__SetDescriptor(
1026
1034
  "ignoresStunImmunity",
1027
1035
  {
1028
1036
  get = function(self)
1029
- local ____self__137_56 = self[137]
1030
- if ____self__137_56 == nil then
1031
- ____self__137_56 = false
1037
+ local ____self__137_54 = self[137]
1038
+ if ____self__137_54 == nil then
1039
+ ____self__137_54 = false
1032
1040
  end
1033
- return ____self__137_56
1041
+ return ____self__137_54
1034
1042
  end,
1035
1043
  set = function(self, ignoresStunImmunity)
1036
1044
  if not ignoresStunImmunity and self[137] then
1037
1045
  if self[136] then
1038
- self.object:decrementStunCounter()
1046
+ self.object:decrementForceStunCounter()
1039
1047
  end
1040
1048
  self[137] = nil
1041
1049
  elseif ignoresStunImmunity and not self[137] then
1042
1050
  if self[136] then
1043
- self.object:incrementStunCounter()
1051
+ self.object:incrementForceStunCounter()
1044
1052
  end
1045
1053
  self[137] = true
1046
1054
  end
@@ -1053,11 +1061,11 @@ __TS__SetDescriptor(
1053
1061
  "disablesAutoAttack",
1054
1062
  {
1055
1063
  get = function(self)
1056
- local ____self__138_57 = self[138]
1057
- if ____self__138_57 == nil then
1058
- ____self__138_57 = false
1064
+ local ____self__138_55 = self[138]
1065
+ if ____self__138_55 == nil then
1066
+ ____self__138_55 = false
1059
1067
  end
1060
- return ____self__138_57
1068
+ return ____self__138_55
1061
1069
  end,
1062
1070
  set = function(self, disablesAutoAttack)
1063
1071
  if not disablesAutoAttack and self[138] then
@@ -1076,11 +1084,11 @@ __TS__SetDescriptor(
1076
1084
  "providesInvulnerability",
1077
1085
  {
1078
1086
  get = function(self)
1079
- local ____self__139_58 = self[139]
1080
- if ____self__139_58 == nil then
1081
- ____self__139_58 = false
1087
+ local ____self__139_56 = self[139]
1088
+ if ____self__139_56 == nil then
1089
+ ____self__139_56 = false
1082
1090
  end
1083
- return ____self__139_58
1091
+ return ____self__139_56
1084
1092
  end,
1085
1093
  set = function(self, providesInvulnerability)
1086
1094
  if not providesInvulnerability and self[139] then
@@ -1099,11 +1107,11 @@ __TS__SetDescriptor(
1099
1107
  "killsOnExpiration",
1100
1108
  {
1101
1109
  get = function(self)
1102
- local ____self__140_59 = self[140]
1103
- if ____self__140_59 == nil then
1104
- ____self__140_59 = false
1110
+ local ____self__140_57 = self[140]
1111
+ if ____self__140_57 == nil then
1112
+ ____self__140_57 = false
1105
1113
  end
1106
- return ____self__140_59
1114
+ return ____self__140_57
1107
1115
  end,
1108
1116
  set = function(self, killsOnExpiration)
1109
1117
  if not killsOnExpiration and self[140] then
@@ -1120,11 +1128,11 @@ __TS__SetDescriptor(
1120
1128
  "explodesOnExpiration",
1121
1129
  {
1122
1130
  get = function(self)
1123
- local ____self__141_60 = self[141]
1124
- if ____self__141_60 == nil then
1125
- ____self__141_60 = false
1131
+ local ____self__141_58 = self[141]
1132
+ if ____self__141_58 == nil then
1133
+ ____self__141_58 = false
1126
1134
  end
1127
- return ____self__141_60
1135
+ return ____self__141_58
1128
1136
  end,
1129
1137
  set = function(self, killsOnExpiration)
1130
1138
  if not killsOnExpiration and self[141] then
@@ -1252,13 +1260,13 @@ __TS__SetDescriptor(
1252
1260
  "remainingDuration",
1253
1261
  {
1254
1262
  get = function(self)
1255
- local ____opt_61 = self._timer
1256
- return ____opt_61 and ____opt_61.remaining or 0
1263
+ local ____opt_59 = self._timer
1264
+ return ____opt_59 and ____opt_59.remaining or 0
1257
1265
  end,
1258
1266
  set = function(self, remainingDuration)
1259
- local ____remainingDuration_65 = remainingDuration
1260
- local ____opt_63 = self._timer
1261
- local remainingDurationDelta = ____remainingDuration_65 - (____opt_63 and ____opt_63.remaining or 0)
1267
+ local ____remainingDuration_63 = remainingDuration
1268
+ local ____opt_61 = self._timer
1269
+ local remainingDurationDelta = ____remainingDuration_63 - (____opt_61 and ____opt_61.remaining or 0)
1262
1270
  if remainingDurationDelta ~= 0 then
1263
1271
  self[103] = self[103] + remainingDurationDelta
1264
1272
  if remainingDuration <= 0 then
@@ -1288,7 +1296,34 @@ __TS__SetDescriptor(
1288
1296
  },
1289
1297
  true
1290
1298
  )
1291
- Buff.destroyEvent = buffDestroyEvent;
1299
+ __TS__SetDescriptor(
1300
+ Buff.prototype,
1301
+ "abilityCooldownFactor",
1302
+ {
1303
+ get = function(self)
1304
+ return self[143] or 1
1305
+ end,
1306
+ set = function(self, abilityCooldownFactor)
1307
+ local previousAbilityCooldownModifier = self[144]
1308
+ if previousAbilityCooldownModifier then
1309
+ for ____, ability in ipairs(self._unit.abilities) do
1310
+ COOLDOWN_ABILITY_FLOAT_LEVEL_FIELD:removeModifier(ability, previousAbilityCooldownModifier)
1311
+ end
1312
+ end
1313
+ local function modifier(ability, level, cooldown)
1314
+ return cooldown * abilityCooldownFactor
1315
+ end
1316
+ for ____, ability in ipairs(self._unit.abilities) do
1317
+ COOLDOWN_ABILITY_FLOAT_LEVEL_FIELD:applyModifier(ability, modifier)
1318
+ end
1319
+ self[144] = modifier
1320
+ self[143] = abilityCooldownFactor
1321
+ end
1322
+ },
1323
+ true
1324
+ )
1325
+ Buff.createdEvent = buffCreatedEvent
1326
+ Buff.beingDestroyedEvent = buffBeingDestroyedEvent;
1292
1327
  (function(self)
1293
1328
  local function destroyBuffIfNeeded(buff)
1294
1329
  if getUnitAbility(buff[101].handle, buff.typeId) ~= buff.handle and buff[100] == 1 then
@@ -1342,5 +1377,8 @@ Buff.destroyEvent = buffDestroyEvent;
1342
1377
  ____exports.checkBuffs(target)
1343
1378
  end
1344
1379
  )
1380
+ buffCreatedEvent:addListener(function(buff)
1381
+ UnitBehavior:forAll(buff.unit, "onBuffGained", buff)
1382
+ end)
1345
1383
  end)(Buff)
1346
1384
  return ____exports
@@ -1,5 +1,5 @@
1
1
  /** @noSelfInFile */
2
- import { Handle } from "../../core/types/handle";
2
+ import { Handle, HandleDestructor } from "../../core/types/handle";
3
3
  import { Event } from "../../event";
4
4
  import type { Item } from "../../core/types/item";
5
5
  import type { Unit } from "./unit";
@@ -67,6 +67,7 @@ export declare class UnitAbility extends Ability {
67
67
  get cooldownRemaining(): number;
68
68
  set cooldownRemaining(cooldownRemaining: number);
69
69
  interruptCast(): void;
70
+ protected onDestroy(): HandleDestructor;
70
71
  static get onCreate(): Event<[UnitAbility]>;
71
72
  static get onDestroy(): Event<[UnitAbility]>;
72
73
  }
@@ -93,6 +94,7 @@ export declare class ItemAbility extends Ability {
93
94
  get cooldownRemaining(): number;
94
95
  set cooldownRemaining(cooldownRemaining: number);
95
96
  interruptCast(): void;
97
+ protected onDestroy(): HandleDestructor;
96
98
  static get onCreate(): Event<[ItemAbility]>;
97
99
  static get onDestroy(): Event<[ItemAbility]>;
98
100
  }
@@ -232,6 +232,19 @@ ____exports.getOrderIdByAbilityTypeId = function(abilityTypeId)
232
232
  local parentTypeId = availableFields[abilityTypeId]
233
233
  return order2orderId(orders[____type(parentTypeId) == "number" and parentTypeId or abilityTypeId] or "")
234
234
  end
235
+ ---
236
+ -- @internal For use by internal systems only.
237
+ ____exports.abilityTypeHasField = function(abilityTypeId, field)
238
+ field = ____type(field) == "number" and field or getHandleId(field)
239
+ if commonFields[field] then
240
+ return true
241
+ end
242
+ local id = availableFields[abilityTypeId]
243
+ if ____type(id) == "number" then
244
+ id = availableFields[id]
245
+ end
246
+ return not not (id and id[field])
247
+ end
235
248
  ____exports.Ability = __TS__Class()
236
249
  local Ability = ____exports.Ability
237
250
  Ability.name = "Ability"
@@ -247,15 +260,7 @@ function Ability.prototype.getSnapshot(self)
247
260
  return nil
248
261
  end
249
262
  function Ability.prototype.hasField(self, field)
250
- field = ____type(field) == "number" and field or getHandleId(field)
251
- if commonFields[field] then
252
- return true
253
- end
254
- local id = availableFields[self.typeId]
255
- if ____type(id) == "number" then
256
- id = availableFields[id]
257
- end
258
- return not not (id and id[field])
263
+ return ____exports.abilityTypeHasField(self.typeId, field)
259
264
  end
260
265
  function Ability.prototype.getField(self, field, level)
261
266
  local fieldType = match(
@@ -404,16 +409,28 @@ function UnitAbility.prototype.decrementHideCounter(self)
404
409
  unitHideAbility(self.u, self.typeId, false)
405
410
  end
406
411
  function UnitAbility.prototype.incrementDisableCounter(self)
407
- unitDisableAbility(self.u, self.typeId, true, false)
412
+ local unit = self.u
413
+ local typeId = self.typeId
414
+ unitHideAbility(unit, typeId, true)
415
+ unitDisableAbility(unit, typeId, true, false)
408
416
  self.d = (self.d or 0) + 1
409
417
  end
410
418
  function UnitAbility.prototype.decrementDisableCounter(self)
411
- unitDisableAbility(self.u, self.typeId, false, false)
419
+ local unit = self.u
420
+ local typeId = self.typeId
421
+ unitDisableAbility(unit, typeId, false, false)
422
+ unitHideAbility(unit, typeId, true)
412
423
  self.d = (self.d or 0) - 1
413
424
  end
414
425
  function UnitAbility.prototype.interruptCast(self)
415
426
  self.owner:interruptCast(self.typeId)
416
427
  end
428
+ function UnitAbility.prototype.onDestroy(self)
429
+ if self.owner.state ~= 2 then
430
+ self.owner:removeAbility(self.typeId)
431
+ end
432
+ return UnitAbility.____super.prototype.onDestroy(self)
433
+ end
417
434
  __TS__SetDescriptor(
418
435
  UnitAbility.prototype,
419
436
  "isDisabled",
@@ -506,6 +523,12 @@ function ItemAbility.prototype.interruptCast(self)
506
523
  setItemBooleanField(handle, ITEM_BF_ACTIVELY_USED, true)
507
524
  end
508
525
  end
526
+ function ItemAbility.prototype.onDestroy(self)
527
+ if self.owner.state ~= 2 then
528
+ self.owner:removeAbility(self.typeId)
529
+ end
530
+ return ItemAbility.____super.prototype.onDestroy(self)
531
+ end
509
532
  __TS__SetDescriptor(
510
533
  ItemAbility.prototype,
511
534
  "level",
@@ -20,6 +20,7 @@ local ____add_2Ditem_2Dto_2Dslot = require("engine.internal.unit.add-item-to-slo
20
20
  local unitAddItemToSlot = ____add_2Ditem_2Dto_2Dslot.unitAddItemToSlot
21
21
  local isItemOwned = IsItemOwned
22
22
  local isItemPowerup = IsItemPowerup
23
+ local getItemAbility = BlzGetItemAbility
23
24
  local getItemX = GetItemX
24
25
  local getItemY = GetItemY
25
26
  local setAbilityRealLevelField = BlzSetAbilityRealLevelField
@@ -31,6 +32,8 @@ local unitAddItem = UnitAddItem
31
32
  local unitRemoveItem = UnitRemoveItem
32
33
  local unitUseItem = UnitUseItem
33
34
  local unitResetCooldown = UnitResetCooldown
35
+ local unitInventorySize = UnitInventorySize
36
+ local unitItemInSlot = UnitItemInSlot
34
37
  local COOLDOWN_STARTER_ABILITY_TYPE_ID = compiletime(function()
35
38
  if not currentMap then
36
39
  return 0
@@ -65,7 +68,7 @@ ____exports.itemAbilityDummy = assert(CreateUnit(
65
68
  270
66
69
  ))
67
70
  local cooldownStarterItem = UnitAddItemById(____exports.itemAbilityDummy, COOLDOWN_STARTER_ITEM_TYPE_ID)
68
- local cooldownStarterAbility = BlzGetItemAbility(cooldownStarterItem, COOLDOWN_STARTER_ABILITY_TYPE_ID)
71
+ local cooldownStarterAbility = getItemAbility(cooldownStarterItem, COOLDOWN_STARTER_ABILITY_TYPE_ID)
69
72
  ShowUnit(____exports.itemAbilityDummy, false)
70
73
  local function startItemCooldownInternal(handle, cooldown)
71
74
  local cooldownGroup = getItemIntegerField(handle, ITEM_IF_COOLDOWN_GROUP)
@@ -153,4 +156,51 @@ ____exports.doAbilityActionForceDummy = function(handle, owner, action, ...)
153
156
  end
154
157
  return result
155
158
  end
159
+ local depth = 0
160
+ local itemBySlot = {}
161
+ ---
162
+ -- @internal For use by internal systems only.
163
+ ____exports.doUnitAbilityAction = function(unit, abilityTypeId, action, ...)
164
+ local ____depth_0 = depth
165
+ depth = ____depth_0 + 1
166
+ local offset = 6 * ____depth_0
167
+ for slot = 0, unitInventorySize(unit) - 1 do
168
+ local item = unitItemInSlot(unit, slot)
169
+ if getItemAbility(item, abilityTypeId) ~= nil then
170
+ local isAlreadyIgnoredInEvents = ignoreEventsItems[item] ~= nil
171
+ if not isAlreadyIgnoredInEvents then
172
+ ignoreEventsItems[item] = true
173
+ end
174
+ unitRemoveItem(unit, item)
175
+ if not isAlreadyIgnoredInEvents then
176
+ ignoreEventsItems[item] = nil
177
+ end
178
+ itemBySlot[offset + slot] = item
179
+ end
180
+ end
181
+ local result = action(unit, ...)
182
+ for slot = 0, unitInventorySize(unit) - 1 do
183
+ local item = itemBySlot[offset + slot]
184
+ if item ~= nil then
185
+ local isAlreadyIgnoredInEvents = ignoreEventsItems[item] ~= nil
186
+ if not isAlreadyIgnoredInEvents then
187
+ ignoreEventsItems[item] = true
188
+ end
189
+ local isPowerup = isItemPowerup(item)
190
+ if isPowerup then
191
+ setItemBooleanField(item, ITEM_BF_USE_AUTOMATICALLY_WHEN_ACQUIRED, false)
192
+ end
193
+ unitAddItemToSlot(unit, item, slot)
194
+ if isPowerup then
195
+ setItemBooleanField(item, ITEM_BF_USE_AUTOMATICALLY_WHEN_ACQUIRED, true)
196
+ end
197
+ if not isAlreadyIgnoredInEvents then
198
+ ignoreEventsItems[item] = nil
199
+ end
200
+ itemBySlot[offset + slot] = nil
201
+ end
202
+ end
203
+ depth = depth - 1
204
+ return result
205
+ end
156
206
  return ____exports
@@ -6,12 +6,18 @@ local Item = ____item.Item
6
6
  local ____unit = require("engine.internal.unit")
7
7
  local Unit = ____unit.Unit
8
8
  local ownerByItem = setmetatable({}, {__mode = "kv"})
9
- Unit.itemPickedUpEvent:addListener(function(unit, item)
10
- ownerByItem[item] = unit
11
- end)
12
- Unit.itemDroppedEvent:addListener(function(unit, item)
13
- ownerByItem[item] = nil
14
- end)
9
+ Unit.itemPickedUpEvent:addListener(
10
+ 4,
11
+ function(unit, item)
12
+ ownerByItem[item] = unit
13
+ end
14
+ )
15
+ Unit.itemDroppedEvent:addListener(
16
+ 4,
17
+ function(unit, item)
18
+ ownerByItem[item] = nil
19
+ end
20
+ )
15
21
  __TS__ObjectDefineProperty(
16
22
  Item.prototype,
17
23
  "owner",
@@ -8,12 +8,10 @@ import { AbilityTypeId } from "../object-data/entry/ability-type";
8
8
  import type { ItemTypeId } from "../object-data/entry/item-type";
9
9
  type DefenseType = 0 | 1 | 2 | 3 | 4 | 5;
10
10
  declare const enum ItemPropertyKey {
11
- ABILITIES = 100,
12
- LUA_INDEX_BY_ABILITY_TYPE_ID = 101
11
+ ABILITIES = 100
13
12
  }
14
13
  export declare class Item extends Handle<jitem> {
15
14
  private readonly [ItemPropertyKey.ABILITIES];
16
- private readonly [ItemPropertyKey.LUA_INDEX_BY_ABILITY_TYPE_ID];
17
15
  constructor(handle: jitem);
18
16
  protected onDestroy(): HandleDestructor;
19
17
  static create<T extends Item>(this: typeof Item & (new (handle: jitem) => T), id: number, x: number, y: number, skinId?: number): T;
@@ -30,22 +28,22 @@ export declare class Item extends Handle<jitem> {
30
28
  get extendedTooltip(): string;
31
29
  set iconPath(v: string);
32
30
  get iconPath(): string;
33
- set dropOnDeath(v: boolean);
34
- get dropOnDeath(): boolean;
35
- set droppable(v: boolean);
36
- get droppable(): boolean;
37
- set pawnable(v: boolean);
38
- get pawnable(): boolean;
39
- set perishable(v: boolean);
40
- get perishable(): boolean;
41
- set powerup(v: boolean);
42
- get powerup(): boolean;
31
+ set dropsOnDeath(dropsOnDeath: boolean);
32
+ get dropsOnDeath(): boolean;
33
+ set canBeDropped(canBeDropped: boolean);
34
+ get canBeDropped(): boolean;
35
+ set canBeSold(canBeSold: boolean);
36
+ get canBeSold(): boolean;
37
+ set perishes(perishes: boolean);
38
+ get perishes(): boolean;
39
+ set isPowerUp(isPowerUp: boolean);
40
+ get isPowerUp(): boolean;
43
41
  get isAlive(): boolean;
44
42
  get isDead(): boolean;
45
43
  set isInvulnerable(isInvulnerable: boolean);
46
44
  get isInvulnerable(): boolean;
47
- set usable(v: boolean);
48
- get usable(): boolean;
45
+ set isActivelyUsed(isActivelyUsed: boolean);
46
+ get isActivelyUsed(): boolean;
49
47
  set visible(v: boolean);
50
48
  get visible(): boolean;
51
49
  set level(v: number);