warscript 0.0.1-dev.f967846 → 0.0.1-dev.fa24390

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 (157) 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 +14 -6
  6. package/core/types/effect.lua +131 -35
  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 -24
  10. package/core/types/sound.lua +99 -24
  11. package/core/types/timer.d.ts +6 -7
  12. package/core/types/timer.lua +18 -21
  13. package/core/util.d.ts +1 -1
  14. package/core/util.lua +12 -1
  15. package/decl/native.d.ts +840 -786
  16. package/engine/behaviour/ability/always-enabled.d.ts +7 -0
  17. package/engine/behaviour/ability/always-enabled.lua +31 -0
  18. package/engine/behaviour/ability/apply-buff.d.ts +5 -0
  19. package/engine/behaviour/ability/apply-buff.lua +32 -0
  20. package/engine/behaviour/ability/apply-unit-behavior.lua +1 -0
  21. package/engine/behaviour/ability/damage.d.ts +9 -3
  22. package/engine/behaviour/ability/damage.lua +26 -38
  23. package/engine/behaviour/ability/emulate-impact.d.ts +6 -0
  24. package/engine/behaviour/ability/emulate-impact.lua +35 -0
  25. package/engine/behaviour/ability/instant-impact.d.ts +2 -2
  26. package/engine/behaviour/ability/instant-impact.lua +4 -19
  27. package/engine/behaviour/ability/on-command-impact.d.ts +8 -0
  28. package/engine/behaviour/ability/on-command-impact.lua +25 -0
  29. package/engine/behaviour/ability/remove-buffs.d.ts +16 -0
  30. package/engine/behaviour/ability/remove-buffs.lua +28 -0
  31. package/engine/behaviour/ability.d.ts +20 -4
  32. package/engine/behaviour/ability.lua +111 -38
  33. package/engine/behaviour/unit.d.ts +2 -0
  34. package/engine/buff.d.ts +62 -42
  35. package/engine/buff.lua +312 -234
  36. package/engine/internal/ability.d.ts +15 -2
  37. package/engine/internal/ability.lua +84 -4
  38. package/engine/internal/item/ability.lua +106 -0
  39. package/engine/internal/item.d.ts +4 -3
  40. package/engine/internal/item.lua +56 -25
  41. package/engine/internal/mechanics/ability-duration.lua +1 -1
  42. package/engine/internal/misc/ability-disable-counter.d.ts +2 -0
  43. package/engine/internal/misc/ability-disable-counter.lua +13 -0
  44. package/engine/internal/misc/damage-metadata-by-target.d.ts +2 -0
  45. package/engine/internal/misc/damage-metadata-by-target.lua +5 -0
  46. package/engine/internal/object-data/auto-attack-speed-increase.d.ts +1 -1
  47. package/engine/internal/object-data/auto-attack-speed-increase.lua +2 -0
  48. package/engine/internal/object-data/evasion-probability.d.ts +2 -0
  49. package/engine/internal/object-data/evasion-probability.lua +16 -0
  50. package/engine/internal/unit/ability.d.ts +10 -1
  51. package/engine/internal/unit/ability.lua +36 -14
  52. package/engine/internal/unit/add-item-to-slot-init.d.ts +2 -0
  53. package/engine/internal/unit/add-item-to-slot-init.lua +23 -0
  54. package/engine/internal/unit/add-item-to-slot.d.ts +2 -0
  55. package/engine/internal/unit/add-item-to-slot.lua +52 -0
  56. package/engine/internal/unit/bonus.d.ts +2 -0
  57. package/engine/internal/unit/bonus.lua +17 -0
  58. package/engine/internal/unit/ignore-events-items.d.ts +2 -0
  59. package/engine/internal/unit/ignore-events-items.lua +5 -0
  60. package/engine/internal/unit/item.lua +6 -12
  61. package/engine/internal/unit/main-selected.d.ts +6 -0
  62. package/engine/internal/unit/main-selected.lua +12 -1
  63. package/engine/internal/unit+damage.d.ts +2 -11
  64. package/engine/internal/unit+damage.lua +10 -14
  65. package/engine/internal/unit+spellSteal.lua +1 -2
  66. package/engine/internal/unit.d.ts +25 -5
  67. package/engine/internal/unit.lua +208 -78
  68. package/engine/internal/utility.lua +12 -0
  69. package/engine/lightning.d.ts +12 -5
  70. package/engine/lightning.lua +48 -14
  71. package/engine/object-data/auxiliary/animation-name.d.ts +1 -0
  72. package/engine/object-data/auxiliary/animation-name.lua +16 -0
  73. package/engine/object-data/auxiliary/attachment-preset.d.ts +7 -2
  74. package/engine/object-data/auxiliary/attachment-preset.lua +4 -3
  75. package/engine/object-data/auxiliary/attack-type.d.ts +7 -8
  76. package/engine/object-data/auxiliary/attack-type.lua +42 -0
  77. package/engine/object-data/auxiliary/movement-type.d.ts +7 -7
  78. package/engine/object-data/auxiliary/movement-type.lua +22 -0
  79. package/engine/object-data/auxiliary/sound-eax.d.ts +10 -0
  80. package/engine/object-data/auxiliary/sound-eax.lua +2 -0
  81. package/engine/object-data/auxiliary/sound-preset-name.d.ts +5 -1
  82. package/engine/object-data/auxiliary/tech-tree-dependency.d.ts +1 -1
  83. package/engine/object-data/auxiliary/unit-attribute.d.ts +6 -0
  84. package/engine/object-data/auxiliary/unit-attribute.lua +9 -0
  85. package/engine/object-data/entry/ability-type/berserk.d.ts +2 -0
  86. package/engine/object-data/entry/ability-type/berserk.lua +13 -0
  87. package/engine/object-data/entry/ability-type/blank-configurable.lua +12 -1
  88. package/engine/object-data/entry/ability-type/carrion-swarm.d.ts +14 -0
  89. package/engine/object-data/entry/ability-type/carrion-swarm.lua +65 -0
  90. package/engine/object-data/entry/ability-type/disease-cloud.lua +2 -2
  91. package/engine/object-data/entry/ability-type/engineering-upgrade.lua +2 -2
  92. package/engine/object-data/entry/ability-type/ensnare.d.ts +12 -0
  93. package/engine/object-data/entry/ability-type/ensnare.lua +52 -0
  94. package/engine/object-data/entry/ability-type/feral-spirit.lua +2 -2
  95. package/engine/object-data/entry/ability-type/permanent-invisibility.d.ts +8 -0
  96. package/engine/object-data/entry/ability-type/permanent-invisibility.lua +26 -0
  97. package/engine/object-data/entry/ability-type/phase-shift.d.ts +10 -0
  98. package/engine/object-data/entry/ability-type/phase-shift.lua +39 -0
  99. package/engine/object-data/entry/ability-type/phoenix-morph.lua +4 -4
  100. package/engine/object-data/entry/ability-type/raise-dead.d.ts +17 -0
  101. package/engine/object-data/entry/ability-type/raise-dead.lua +78 -0
  102. package/engine/object-data/entry/ability-type/shock-wave.d.ts +4 -0
  103. package/engine/object-data/entry/ability-type/shock-wave.lua +26 -0
  104. package/engine/object-data/entry/ability-type/slow-poison.d.ts +10 -0
  105. package/engine/object-data/entry/ability-type/slow-poison.lua +58 -0
  106. package/engine/object-data/entry/ability-type/summon-quilbeast.lua +2 -2
  107. package/engine/object-data/entry/ability-type/summon-water-elemental.lua +2 -2
  108. package/engine/object-data/entry/ability-type/web.d.ts +12 -0
  109. package/engine/object-data/entry/ability-type/web.lua +52 -0
  110. package/engine/object-data/entry/ability-type.d.ts +19 -17
  111. package/engine/object-data/entry/ability-type.lua +89 -33
  112. package/engine/object-data/entry/buff-type/applicable.lua +18 -37
  113. package/engine/object-data/entry/buff-type.d.ts +6 -12
  114. package/engine/object-data/entry/buff-type.lua +13 -29
  115. package/engine/object-data/entry/destructible-type.d.ts +1 -1
  116. package/engine/object-data/entry/item-type.d.ts +3 -1
  117. package/engine/object-data/entry/item-type.lua +15 -2
  118. package/engine/object-data/entry/lightning-type.d.ts +1 -1
  119. package/engine/object-data/entry/sound-preset.d.ts +33 -0
  120. package/engine/object-data/entry/sound-preset.lua +140 -0
  121. package/engine/object-data/entry/unit-type.d.ts +10 -3
  122. package/engine/object-data/entry/unit-type.lua +155 -92
  123. package/engine/object-data/entry/upgrade.d.ts +1 -1
  124. package/engine/object-data/entry/upgrade.lua +4 -4
  125. package/engine/object-data/entry.d.ts +16 -14
  126. package/engine/object-data/entry.lua +60 -32
  127. package/engine/object-data/utility/object-data-entry-id-generator.lua +7 -0
  128. package/engine/object-field/ability.d.ts +10 -4
  129. package/engine/object-field/ability.lua +3 -0
  130. package/engine/object-field/unit.d.ts +46 -3
  131. package/engine/object-field/unit.lua +173 -7
  132. package/engine/object-field.d.ts +11 -3
  133. package/engine/object-field.lua +162 -76
  134. package/engine/standard/entries/buff-type.d.ts +3 -0
  135. package/engine/standard/entries/buff-type.lua +3 -0
  136. package/engine/standard/entries/sound-preset.d.ts +10 -0
  137. package/engine/standard/entries/sound-preset.lua +10 -0
  138. package/engine/standard/fields/ability.d.ts +2 -0
  139. package/engine/standard/fields/ability.lua +2 -0
  140. package/engine/unit.d.ts +1 -0
  141. package/engine/unit.lua +1 -0
  142. package/objutil/buff.lua +1 -2
  143. package/objutil/unit.lua +8 -0
  144. package/package.json +2 -2
  145. package/utility/arrays.d.ts +9 -1
  146. package/utility/arrays.lua +37 -3
  147. package/utility/functions.d.ts +1 -0
  148. package/utility/functions.lua +1 -0
  149. package/utility/lazy.d.ts +2 -0
  150. package/utility/lazy.lua +14 -0
  151. package/utility/linked-set.d.ts +1 -0
  152. package/utility/linked-set.lua +3 -0
  153. package/utility/lua-maps.d.ts +3 -0
  154. package/utility/lua-maps.lua +16 -0
  155. package/utility/lua-sets.d.ts +1 -0
  156. package/utility/lua-sets.lua +3 -0
  157. package/utility/reflection.lua +11 -7
@@ -51,12 +51,19 @@ local ____arrays = require("utility.arrays")
51
51
  local forEach = ____arrays.forEach
52
52
  local ____math = require("math")
53
53
  local min = ____math.min
54
+ local ____ignore_2Devents_2Ditems = require("engine.internal.unit.ignore-events-items")
55
+ local ignoreEventsItems = ____ignore_2Devents_2Ditems.ignoreEventsItems
56
+ local ____attack_2Dtype = require("engine.object-data.auxiliary.attack-type")
57
+ local attackTypeToNative = ____attack_2Dtype.attackTypeToNative
58
+ local nativeToAttackType = ____attack_2Dtype.nativeToAttackType
59
+ local ____damage_2Dmetadata_2Dby_2Dtarget = require("engine.internal.misc.damage-metadata-by-target")
60
+ local damageMetadataByTarget = ____damage_2Dmetadata_2Dby_2Dtarget.damageMetadataByTarget
61
+ local ____attributes = require("attributes")
62
+ local isAttribute = ____attributes.isAttribute
54
63
  local match = string.match
55
64
  local ____tostring = _G.tostring
56
65
  local setUnitAnimation = SetUnitAnimation
57
- local setUnitAnimationWithRarity = SetUnitAnimationWithRarity
58
66
  local setUnitAnimationByIndex = SetUnitAnimationByIndex
59
- local queueUnitAnimation = QueueUnitAnimation
60
67
  local getUnitIntegerField = BlzGetUnitIntegerField
61
68
  local getUnitRealField = BlzGetUnitRealField
62
69
  local getHeroStr = GetHeroStr
@@ -75,9 +82,9 @@ local setUnitScale = SetUnitScale
75
82
  local setUnitPosition = SetUnitPosition
76
83
  local setUnitTimeScale = SetUnitTimeScale
77
84
  local getHandleId = GetHandleId
85
+ local getUnitCurrentOrder = GetUnitCurrentOrder
78
86
  local createUnit = CreateUnit
79
87
  local killUnit = KillUnit
80
- local setUnitExploded = SetUnitExploded
81
88
  local removeUnit = RemoveUnit
82
89
  local getUnitTypeId = GetUnitTypeId
83
90
  local isHeroUnitId = IsHeroUnitId
@@ -93,8 +100,6 @@ local getSpellTargetItem = GetSpellTargetItem
93
100
  local getSpellTargetDestructable = GetSpellTargetDestructable
94
101
  local isUnitInRangeXY = IsUnitInRangeXY
95
102
  local isUnitInRange = IsUnitInRange
96
- local setResourceAmount = SetResourceAmount
97
- local getResourceAmount = GetResourceAmount
98
103
  local getUnitWeaponRealField = BlzGetUnitWeaponRealField
99
104
  local setUnitWeaponRealField = BlzSetUnitWeaponRealField
100
105
  local getUnitWeaponStringField = BlzGetUnitWeaponStringField
@@ -125,8 +130,6 @@ local isUnitType = IsUnitType
125
130
  local isUnitAlly = IsUnitAlly
126
131
  local isUnitEnemy = IsUnitEnemy
127
132
  local getOwningPlayer = GetOwningPlayer
128
- local setUnitColor = SetUnitColor
129
- local showUnitTeamGlow = BlzShowUnitTeamGlow
130
133
  ____exports.UnitClassification = {}
131
134
  local UnitClassification = ____exports.UnitClassification
132
135
  do
@@ -136,6 +139,7 @@ do
136
139
  UnitClassification.GROUND = UNIT_TYPE_GROUND
137
140
  UnitClassification.SUMMONED = UNIT_TYPE_SUMMONED
138
141
  UnitClassification.MECHANICAL = UNIT_TYPE_MECHANICAL
142
+ UnitClassification.WORKER = UNIT_TYPE_PEON
139
143
  UnitClassification.ANCIENT = UNIT_TYPE_ANCIENT
140
144
  UnitClassification.SUICIDAL = UNIT_TYPE_SAPPER
141
145
  UnitClassification.TAUREN = UNIT_TYPE_TAUREN
@@ -343,6 +347,9 @@ local function dispatchAbility(event)
343
347
  }
344
348
  )
345
349
  end
350
+ local function damagingEventPreventRetaliation(self)
351
+ self[0] = true
352
+ end
346
353
  local function damageEventPreventDeath(self, callback, ...)
347
354
  if self[0] ~= nil then
348
355
  return
@@ -354,7 +361,14 @@ local function damageEventPreventDeath(self, callback, ...)
354
361
  rawset(self, 1 + i, (select(i, ...)))
355
362
  end
356
363
  end
357
- local damageSetters = {amount = BlzSetEventDamage, attackType = BlzSetEventAttackType, damageType = BlzSetEventDamageType, weaponType = BlzSetEventWeaponType}
364
+ local damageSetters = {
365
+ amount = BlzSetEventDamage,
366
+ attackType = function(attackType)
367
+ return BlzSetEventAttackType(attackTypeToNative(attackType))
368
+ end,
369
+ damageType = BlzSetEventDamageType,
370
+ weaponType = BlzSetEventWeaponType
371
+ }
358
372
  local jlimitopByOperator = {
359
373
  [0] = LESS_THAN_OR_EQUAL,
360
374
  [1] = LESS_THAN_OR_EQUAL,
@@ -562,17 +576,6 @@ local function retrieveAbility(unit, ability, abilityId)
562
576
  ____exports.Unit:of(unit)
563
577
  )
564
578
  end
565
- if not unitAddAbility(unit, abilityId) then
566
- if getUnitAbility(unit, abilityId) == ability then
567
- return UnitAbility:of(
568
- ability,
569
- abilityId,
570
- ____exports.Unit:of(unit)
571
- )
572
- end
573
- else
574
- unitRemoveAbility(unit, abilityId)
575
- end
576
579
  for i = 0, unitInventorySize(unit) - 1 do
577
580
  local item = unitItemInSlot(unit, i)
578
581
  if getItemAbility(item, abilityId) == ability then
@@ -647,7 +650,8 @@ local function delayHealthChecksCallback(unit)
647
650
  end
648
651
  end
649
652
  local nextSyncId = 1
650
- local unitBySyncId = setmetatable({}, {__mode = "k"})
653
+ local unitBySyncId = setmetatable({}, {__mode = "v"})
654
+ local damagingEventByTarget = setmetatable({}, {__mode = "k"})
651
655
  ____exports.Unit = __TS__Class()
652
656
  local Unit = ____exports.Unit
653
657
  Unit.name = "Unit"
@@ -688,6 +692,8 @@ function Unit.prototype.getEvent(self, event, collector)
688
692
  end
689
693
  function Unit.prototype.onDestroy(self)
690
694
  local handle = self.handle
695
+ self[107] = getUnitX(handle)
696
+ self[108] = getUnitY(handle)
691
697
  if not self._owner then
692
698
  self._owner = Player:of(getOwningPlayer(handle))
693
699
  end
@@ -798,13 +804,16 @@ function Unit.prototype.playAnimation(self, animation, rarity)
798
804
  if type(animation) == "number" then
799
805
  setUnitAnimationByIndex(self.handle, animation)
800
806
  elseif rarity then
801
- setUnitAnimationWithRarity(self.handle, animation, rarity)
807
+ SetUnitAnimationWithRarity(self.handle, animation, rarity)
802
808
  else
803
809
  setUnitAnimation(self.handle, animation)
804
810
  end
805
811
  end
812
+ function Unit.prototype.resetAnimation(self)
813
+ ResetUnitAnimation(self.handle)
814
+ end
806
815
  function Unit.prototype.queueAnimation(self, animation)
807
- queueUnitAnimation(self.handle, animation)
816
+ QueueUnitAnimation(self.handle, animation)
808
817
  end
809
818
  function Unit.prototype.delayHealthChecks(self)
810
819
  self[103] = (self[103] or 0) + 1
@@ -817,7 +826,7 @@ function Unit.prototype.isSelected(self, player)
817
826
  return IsUnitSelected(self.handle, player.handle)
818
827
  end
819
828
  function Unit.prototype.explode(self)
820
- setUnitExploded(self.handle, true)
829
+ SetUnitExploded(self.handle, true)
821
830
  killUnit(self.handle)
822
831
  end
823
832
  function Unit.prototype.kill(self)
@@ -940,8 +949,15 @@ function Unit.prototype.interruptAttack(self)
940
949
  unitInterruptAttack(self.handle)
941
950
  end
942
951
  function Unit.prototype.interruptCast(self, abilityId)
943
- unitDisableAbility(self.handle, abilityId, true, false)
944
- unitDisableAbility(self.handle, abilityId, false, false)
952
+ local handle = self.handle
953
+ unitDisableAbility(handle, abilityId, true, false)
954
+ Timer:run(
955
+ unitDisableAbility,
956
+ handle,
957
+ abilityId,
958
+ false,
959
+ false
960
+ )
945
961
  end
946
962
  function Unit.prototype.getDistanceTo(self, target)
947
963
  local handle = self.handle
@@ -1206,6 +1222,14 @@ __TS__SetDescriptor(
1206
1222
  end},
1207
1223
  true
1208
1224
  )
1225
+ __TS__SetDescriptor(
1226
+ Unit.prototype,
1227
+ "isStunned",
1228
+ {get = function(self)
1229
+ return getUnitCurrentOrder(self.handle) == orderId("stunned")
1230
+ end},
1231
+ true
1232
+ )
1209
1233
  __TS__SetDescriptor(
1210
1234
  Unit.prototype,
1211
1235
  "combatClassifications",
@@ -1279,6 +1303,19 @@ __TS__SetDescriptor(
1279
1303
  },
1280
1304
  true
1281
1305
  )
1306
+ __TS__SetDescriptor(
1307
+ Unit.prototype,
1308
+ "primaryAttribute",
1309
+ {
1310
+ get = function(self)
1311
+ return getUnitIntegerField(self.handle, UNIT_IF_PRIMARY_ATTRIBUTE)
1312
+ end,
1313
+ set = function(self, primaryAttribute)
1314
+ setUnitIntegerField(self.handle, UNIT_IF_PRIMARY_ATTRIBUTE, primaryAttribute)
1315
+ end
1316
+ },
1317
+ true
1318
+ )
1282
1319
  __TS__SetDescriptor(
1283
1320
  Unit.prototype,
1284
1321
  "strengthBase",
@@ -1403,7 +1440,7 @@ __TS__SetDescriptor(
1403
1440
  return not self[106]
1404
1441
  end,
1405
1442
  set = function(self, isTeamGlowVisible)
1406
- showUnitTeamGlow(self.handle, isTeamGlowVisible)
1443
+ BlzShowUnitTeamGlow(self.handle, isTeamGlowVisible)
1407
1444
  local ____temp_6
1408
1445
  if not isTeamGlowVisible then
1409
1446
  ____temp_6 = true
@@ -1419,9 +1456,9 @@ __TS__SetDescriptor(
1419
1456
  Unit.prototype,
1420
1457
  "color",
1421
1458
  {set = function(self, color)
1422
- setUnitColor(self.handle, color.handle)
1459
+ SetUnitColor(self.handle, color.handle)
1423
1460
  if self[106] then
1424
- showUnitTeamGlow(self.handle, false)
1461
+ BlzShowUnitTeamGlow(self.handle, false)
1425
1462
  end
1426
1463
  end},
1427
1464
  true
@@ -1590,7 +1627,7 @@ __TS__SetDescriptor(
1590
1627
  "x",
1591
1628
  {
1592
1629
  get = function(self)
1593
- return getUnitX(self.handle)
1630
+ return self[107] or getUnitX(self.handle)
1594
1631
  end,
1595
1632
  set = function(self, v)
1596
1633
  SetUnitX(self.handle, v)
@@ -1603,7 +1640,7 @@ __TS__SetDescriptor(
1603
1640
  "y",
1604
1641
  {
1605
1642
  get = function(self)
1606
- return getUnitY(self.handle)
1643
+ return self[108] or getUnitY(self.handle)
1607
1644
  end,
1608
1645
  set = function(self, v)
1609
1646
  SetUnitY(self.handle, v)
@@ -1689,10 +1726,10 @@ __TS__SetDescriptor(
1689
1726
  "gold",
1690
1727
  {
1691
1728
  get = function(self)
1692
- return getResourceAmount(self.handle)
1729
+ return GetResourceAmount(self.handle)
1693
1730
  end,
1694
1731
  set = function(self, gold)
1695
- setResourceAmount(self.handle, gold)
1732
+ SetResourceAmount(self.handle, gold)
1696
1733
  end
1697
1734
  },
1698
1735
  true
@@ -1820,6 +1857,19 @@ __TS__SetDescriptor(
1820
1857
  end},
1821
1858
  true
1822
1859
  )
1860
+ __TS__SetDescriptor(
1861
+ Unit.prototype,
1862
+ "movementType",
1863
+ {
1864
+ get = function(self)
1865
+ return getUnitIntegerField(self.handle, UNIT_IF_MOVE_TYPE)
1866
+ end,
1867
+ set = function(self, movementType)
1868
+ setUnitIntegerField(self.handle, UNIT_IF_MOVE_TYPE, movementType)
1869
+ end
1870
+ },
1871
+ true
1872
+ )
1823
1873
  __TS__SetDescriptor(
1824
1874
  Unit.prototype,
1825
1875
  "pathing",
@@ -2001,6 +2051,14 @@ __TS__SetDescriptor(
2001
2051
  end},
2002
2052
  true
2003
2053
  )
2054
+ __TS__SetDescriptor(
2055
+ Unit.prototype,
2056
+ "targetAcquiredEvent",
2057
+ {get = function(self)
2058
+ return self:getEvent(EVENT_UNIT_ACQUIRED_TARGET)
2059
+ end},
2060
+ true
2061
+ )
2004
2062
  __TS__SetDescriptor(
2005
2063
  Unit.prototype,
2006
2064
  "onSelect",
@@ -2326,10 +2384,12 @@ Unit.onImmediateOrder = dispatchId(__TS__New(
2326
2384
  ____exports.UnitTriggerEvent,
2327
2385
  EVENT_PLAYER_UNIT_ISSUED_ORDER,
2328
2386
  function()
2329
- local unit = ____exports.Unit:of(getOrderedUnit())
2330
- local issuedOrderId = getIssuedOrderId()
2331
- if unit ~= nil and unit.state == 1 then
2332
- return unit, issuedOrderId
2387
+ local handle = getOrderedUnit()
2388
+ if handle ~= nil and getUnitTypeId(handle) ~= dummyUnitId then
2389
+ local unit = ____exports.Unit:of(handle)
2390
+ if unit.state == 1 then
2391
+ return unit, getIssuedOrderId()
2392
+ end
2333
2393
  end
2334
2394
  return IgnoreEvent
2335
2395
  end
@@ -2360,13 +2420,19 @@ Unit.onDamaging = (function()
2360
2420
  if source and source.typeId == dummyUnitId then
2361
2421
  source = nil
2362
2422
  end
2363
- local target = BlzGetEventDamageTarget()
2423
+ local target = ____exports.Unit:of(BlzGetEventDamageTarget())
2424
+ local metadata = damageMetadataByTarget[target]
2425
+ damageMetadataByTarget[target] = nil
2364
2426
  local data = {
2365
2427
  amount = GetEventDamage(),
2366
- attackType = BlzGetEventAttackType(),
2428
+ attackType = nativeToAttackType(BlzGetEventAttackType()),
2367
2429
  damageType = BlzGetEventDamageType(),
2368
2430
  weaponType = BlzGetEventWeaponType(),
2369
- isAttack = BlzGetEventIsAttack()
2431
+ metadata = metadata,
2432
+ isAttack = BlzGetEventIsAttack(),
2433
+ originalAmount = GetEventDamage(),
2434
+ originalMetadata = metadata,
2435
+ preventRetaliation = damagingEventPreventRetaliation
2370
2436
  }
2371
2437
  if data.isAttack and source then
2372
2438
  local weapon = BlzGetUnitWeaponBooleanField(source.handle, UNIT_WEAPON_BF_ATTACKS_ENABLED, 1) and (BlzGetUnitWeaponBooleanField(source.handle, UNIT_WEAPON_BF_ATTACKS_ENABLED, 0) and -1 or 1) or 0
@@ -2380,18 +2446,36 @@ Unit.onDamaging = (function()
2380
2446
  invoke(
2381
2447
  event,
2382
2448
  source,
2383
- ____exports.Unit:of(target),
2449
+ target,
2384
2450
  setmetatable(
2385
2451
  {},
2386
2452
  {
2387
2453
  __index = data,
2388
2454
  __newindex = function(self, key, value)
2389
- damageSetters[key](value)
2455
+ local damageSetter = damageSetters[key]
2456
+ if damageSetter ~= nil then
2457
+ damageSetter(value)
2458
+ end
2390
2459
  data[key] = value
2391
2460
  end
2392
2461
  }
2393
2462
  )
2394
2463
  )
2464
+ if data[0] and source then
2465
+ local sourceOwner = source.owner.handle
2466
+ data[1] = sourceOwner
2467
+ local targetOwner = target.owner.handle
2468
+ data[2] = targetOwner
2469
+ if not GetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE) then
2470
+ SetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE, true)
2471
+ data[3] = true
2472
+ end
2473
+ if not GetPlayerAlliance(targetOwner, sourceOwner, ALLIANCE_PASSIVE) then
2474
+ SetPlayerAlliance(targetOwner, sourceOwner, ALLIANCE_PASSIVE, true)
2475
+ data[4] = true
2476
+ end
2477
+ end
2478
+ damagingEventByTarget[target] = data
2395
2479
  return
2396
2480
  end
2397
2481
  BlzSetEventDamage(0)
@@ -2399,7 +2483,7 @@ Unit.onDamaging = (function()
2399
2483
  BlzSetEventDamageType(DAMAGE_TYPE_UNKNOWN)
2400
2484
  BlzSetEventWeaponType(WEAPON_TYPE_WHOKNOWS)
2401
2485
  local sourceOwner = source.owner.handle
2402
- local targetOwner = GetOwningPlayer(target)
2486
+ local targetOwner = target.owner.handle
2403
2487
  if not GetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE) then
2404
2488
  SetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE, true)
2405
2489
  Timer:run(function()
@@ -2415,23 +2499,19 @@ Unit.onDamaging = (function()
2415
2499
  for ____, ____value in ipairs(source._attackHandlers) do
2416
2500
  local condition = ____value[1]
2417
2501
  local action = ____value[2]
2418
- if condition(
2419
- source,
2420
- ____exports.Unit:of(target),
2421
- data
2422
- ) then
2502
+ if condition(source, target, data) then
2423
2503
  action(
2424
2504
  source,
2425
- ____exports.Unit:of(target),
2505
+ target,
2426
2506
  setmetatable(
2427
2507
  {fire = function()
2428
2508
  UnitDamageTarget(
2429
2509
  source.handle,
2430
- target,
2510
+ target.handle,
2431
2511
  data.amount,
2432
2512
  true,
2433
2513
  true,
2434
- data.attackType,
2514
+ attackTypeToNative(data.attackType),
2435
2515
  data.damageType,
2436
2516
  data.weaponType
2437
2517
  )
@@ -2458,26 +2538,50 @@ Unit.onDamage = __TS__New(
2458
2538
  if source and source.typeId == dummyUnitId then
2459
2539
  source = nil
2460
2540
  end
2541
+ local target = ____exports.Unit:of(BlzGetEventDamageTarget())
2542
+ local damagingEvent = damagingEventByTarget[target]
2543
+ damagingEventByTarget[target] = nil
2461
2544
  local data = {
2462
2545
  amount = GetEventDamage(),
2463
- attackType = BlzGetEventAttackType(),
2546
+ attackType = nativeToAttackType(BlzGetEventAttackType()),
2464
2547
  damageType = BlzGetEventDamageType(),
2465
2548
  weaponType = BlzGetEventWeaponType(),
2549
+ metadata = damagingEvent and damagingEvent.metadata,
2466
2550
  isAttack = BlzGetEventIsAttack(),
2467
- originalAmount = GetEventDamage(),
2551
+ originalAmount = damagingEvent and damagingEvent.originalAmount or GetEventDamage(),
2552
+ originalMetadata = damagingEvent and damagingEvent.originalMetadata,
2468
2553
  preventDeath = damageEventPreventDeath
2469
2554
  }
2555
+ if damagingEvent then
2556
+ for key, value in pairs(damagingEvent) do
2557
+ if isAttribute(key) then
2558
+ data[key] = value
2559
+ end
2560
+ end
2561
+ local sourceOwner = damagingEvent[1]
2562
+ if sourceOwner then
2563
+ local targetOwner = damagingEvent[2]
2564
+ if damagingEvent[3] then
2565
+ SetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE, false)
2566
+ end
2567
+ if damagingEvent[4] then
2568
+ SetPlayerAlliance(targetOwner, sourceOwner, ALLIANCE_PASSIVE, false)
2569
+ end
2570
+ end
2571
+ end
2470
2572
  local evData = setmetatable(
2471
2573
  {},
2472
2574
  {
2473
2575
  __index = data,
2474
2576
  __newindex = function(self, key, value)
2475
- damageSetters[key](value)
2577
+ local damageSetter = damageSetters[key]
2578
+ if damageSetter ~= nil then
2579
+ damageSetter(value)
2580
+ end
2476
2581
  data[key] = value
2477
2582
  end
2478
2583
  }
2479
2584
  )
2480
- local target = ____exports.Unit:of(BlzGetEventDamageTarget())
2481
2585
  invoke(event, source, target, evData)
2482
2586
  if evData[0] ~= nil and target.health - evData.amount < 0.405 then
2483
2587
  local bonusHealth = math.ceil(evData.amount)
@@ -2520,8 +2624,9 @@ Unit.itemDroppedEvent = __TS__New(
2520
2624
  EVENT_PLAYER_UNIT_DROP_ITEM,
2521
2625
  function()
2522
2626
  local unit = getTriggerUnit()
2523
- if getUnitTypeId(unit) ~= dummyUnitId then
2524
- return ____exports.Unit:of(unit), Item:of(getManipulatedItem())
2627
+ local item = getManipulatedItem()
2628
+ if getUnitTypeId(unit) ~= dummyUnitId and not (ignoreEventsItems[item] ~= nil) then
2629
+ return ____exports.Unit:of(unit), Item:of(item)
2525
2630
  end
2526
2631
  return IgnoreEvent
2527
2632
  end
@@ -2531,8 +2636,9 @@ Unit.itemPickedUpEvent = __TS__New(
2531
2636
  EVENT_PLAYER_UNIT_PICKUP_ITEM,
2532
2637
  function()
2533
2638
  local unit = getTriggerUnit()
2534
- if getUnitTypeId(unit) ~= dummyUnitId then
2535
- return ____exports.Unit:of(unit), Item:of(getManipulatedItem())
2639
+ local item = getManipulatedItem()
2640
+ if getUnitTypeId(unit) ~= dummyUnitId and not (ignoreEventsItems[item] ~= nil) then
2641
+ return ____exports.Unit:of(unit), Item:of(item)
2536
2642
  end
2537
2643
  return IgnoreEvent
2538
2644
  end
@@ -2540,7 +2646,14 @@ Unit.itemPickedUpEvent = __TS__New(
2540
2646
  Unit.itemUsedEvent = __TS__New(
2541
2647
  ____exports.UnitTriggerEvent,
2542
2648
  EVENT_PLAYER_UNIT_USE_ITEM,
2543
- function() return ____exports.Unit:of(getTriggerUnit()), Item:of(getManipulatedItem()) end
2649
+ function()
2650
+ local unit = getTriggerUnit()
2651
+ local item = getManipulatedItem()
2652
+ if getUnitTypeId(unit) ~= dummyUnitId and not (ignoreEventsItems[item] ~= nil) then
2653
+ return ____exports.Unit:of(unit), Item:of(item)
2654
+ end
2655
+ return IgnoreEvent
2656
+ end
2544
2657
  )
2545
2658
  Unit.itemStackedEvent = __TS__New(
2546
2659
  ____exports.UnitTriggerEvent,
@@ -2549,29 +2662,46 @@ Unit.itemStackedEvent = __TS__New(
2549
2662
  )
2550
2663
  __TS__ObjectDefineProperty(
2551
2664
  Unit,
2552
- "itemMovedEvent",
2665
+ "itemUseOrderEvent",
2553
2666
  {get = function(self)
2554
2667
  local event = __TS__New(Event)
2555
- do
2556
- local order = orderId("moveslot1")
2557
- while order <= orderId("moveslot5") do
2558
- self.onTargetOrder[order]:addListener(function(unit, item)
2559
- local slotFrom = unit.items:findSlot(item)
2560
- if slotFrom ~= nil then
2561
- local slotTo = order - orderId("moveslot1")
2562
- invoke(
2563
- event,
2564
- unit,
2565
- item,
2566
- slotFrom,
2567
- slotTo
2568
- )
2569
- end
2570
- end)
2571
- order = order + 1
2668
+ for order = orderId("useslot0"), orderId("useslot5") do
2669
+ local slot = order - orderId("useslot0")
2670
+ local function listener(unit)
2671
+ local item = unit.items[slot + 1]
2672
+ if item ~= nil then
2673
+ invoke(event, unit, item)
2674
+ end
2572
2675
  end
2676
+ self.onImmediateOrder[order]:addListener(listener)
2677
+ self.onTargetOrder[order]:addListener(listener)
2678
+ self.onPointOrder[order]:addListener(listener)
2679
+ end
2680
+ rawset(self, "itemUseOrderEvent", event)
2681
+ return event
2682
+ end}
2683
+ )
2684
+ __TS__ObjectDefineProperty(
2685
+ Unit,
2686
+ "itemMoveOrderEvent",
2687
+ {get = function(self)
2688
+ local event = __TS__New(Event)
2689
+ for order = orderId("moveslot0"), orderId("moveslot5") do
2690
+ local slotTo = order - orderId("moveslot0")
2691
+ self.onTargetOrder[order]:addListener(function(unit, item)
2692
+ local slotFrom = unit.items:findSlot(item)
2693
+ if slotFrom ~= nil then
2694
+ invoke(
2695
+ event,
2696
+ unit,
2697
+ item,
2698
+ slotFrom,
2699
+ slotTo
2700
+ )
2701
+ end
2702
+ end)
2573
2703
  end
2574
- rawset(self, "itemMovedEvent", event)
2704
+ rawset(self, "itemMoveOrderEvent", event)
2575
2705
  return event
2576
2706
  end}
2577
2707
  )
@@ -1,6 +1,8 @@
1
1
  local ____exports = {}
2
2
  local getUnitAbility = BlzGetUnitAbility
3
3
  local unitAddAbility = UnitAddAbility
4
+ local unitInventorySize = UnitInventorySize
5
+ local unitItemInSlot = UnitItemInSlot
4
6
  local unitMakeAbilityPermanent = UnitMakeAbilityPermanent
5
7
  ---
6
8
  -- @internal For use by internal systems only.
@@ -10,4 +12,14 @@ ____exports.addInternalAbility = function(unit, abilityTypeId)
10
12
  end
11
13
  return getUnitAbility(unit, abilityTypeId)
12
14
  end
15
+ ---
16
+ -- @internal For use by internal systems only.
17
+ ____exports.findUnitItemSlot = function(unit, item)
18
+ for slot = 0, unitInventorySize(unit) - 1 do
19
+ if item == unitItemInSlot(unit, slot) then
20
+ return slot
21
+ end
22
+ end
23
+ return nil
24
+ end
13
25
  return ____exports
@@ -1,7 +1,7 @@
1
1
  /** @noSelfInFile */
2
2
  import { LightningTypeId } from "./object-data/entry/lightning-type";
3
- import { Handle, HandleDestructor } from "../core/types/handle";
4
3
  import { Unit } from "../core/types/unit";
4
+ import { AbstractDestroyable, Destructor } from "../destroyable";
5
5
  declare const enum LightningPropertyKey {
6
6
  CHECK_VISIBILITY = 100,
7
7
  SOURCE_UNIT = 101,
@@ -12,10 +12,12 @@ declare const enum LightningPropertyKey {
12
12
  TARGET_X = 106,
13
13
  TARGET_Y = 107,
14
14
  TARGET_Z = 108,
15
- DURATION = 109
15
+ DURATION = 109,
16
+ FADING = 110
16
17
  }
17
18
  export type LightningConstructor<T extends Lightning> = typeof Lightning & (new (handle: jlightning, typeId: LightningTypeId) => T);
18
- export declare class Lightning extends Handle<jlightning> {
19
+ export declare class Lightning extends AbstractDestroyable {
20
+ readonly handle: jlightning;
19
21
  readonly typeId: LightningTypeId;
20
22
  private [LightningPropertyKey.CHECK_VISIBILITY]?;
21
23
  private [LightningPropertyKey.SOURCE_UNIT]?;
@@ -27,8 +29,9 @@ export declare class Lightning extends Handle<jlightning> {
27
29
  private [LightningPropertyKey.TARGET_Y]?;
28
30
  private [LightningPropertyKey.TARGET_Z]?;
29
31
  private [LightningPropertyKey.DURATION]?;
32
+ private [LightningPropertyKey.FADING]?;
30
33
  constructor(handle: jlightning, typeId: LightningTypeId);
31
- protected onDestroy(): HandleDestructor;
34
+ protected onDestroy(): Destructor;
32
35
  static create<T extends Lightning>(this: LightningConstructor<T>, typeId: LightningTypeId, ...parameters: [
33
36
  ...checkVisibility: [boolean] | [],
34
37
  ...sourceAndTarget: [sourceX: number, sourceY: number, targetX: number, targetY: number] | [
@@ -46,6 +49,10 @@ export declare class Lightning extends Handle<jlightning> {
46
49
  target: Unit
47
50
  ]
48
51
  ]): T;
49
- static flash(...parameters: [...parameters: Parameters<(typeof Lightning)["create"]>, duration: number]): void;
52
+ static flash(...parameters: [
53
+ ...parameters: Parameters<(typeof Lightning)["create"]>,
54
+ duration: number,
55
+ fading?: boolean
56
+ ]): void;
50
57
  }
51
58
  export {};