warscript 0.0.1-dev.123f3ce → 0.0.1-dev.1377403

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 (151) hide show
  1. package/attributes.d.ts +4 -0
  2. package/attributes.lua +5 -1
  3. package/config.d.ts +5 -0
  4. package/config.lua +10 -0
  5. package/core/types/effect.d.ts +2 -3
  6. package/core/types/effect.lua +98 -51
  7. package/core/types/sound.d.ts +17 -24
  8. package/core/types/sound.lua +99 -24
  9. package/core/types/timer.d.ts +6 -7
  10. package/core/types/timer.lua +18 -21
  11. package/core/util.d.ts +1 -1
  12. package/core/util.lua +12 -1
  13. package/decl/native.d.ts +840 -786
  14. package/engine/behaviour/ability/always-enabled.d.ts +7 -0
  15. package/engine/behaviour/ability/always-enabled.lua +31 -0
  16. package/engine/behaviour/ability/apply-buff.d.ts +5 -0
  17. package/engine/behaviour/ability/apply-buff.lua +32 -0
  18. package/engine/behaviour/ability/apply-unit-behavior.lua +1 -0
  19. package/engine/behaviour/ability/damage.d.ts +9 -3
  20. package/engine/behaviour/ability/damage.lua +26 -38
  21. package/engine/behaviour/ability/emulate-impact.d.ts +6 -0
  22. package/engine/behaviour/ability/emulate-impact.lua +35 -0
  23. package/engine/behaviour/ability/instant-impact.d.ts +2 -2
  24. package/engine/behaviour/ability/instant-impact.lua +4 -19
  25. package/engine/behaviour/ability/on-command-impact.d.ts +8 -0
  26. package/engine/behaviour/ability/on-command-impact.lua +25 -0
  27. package/engine/behaviour/ability/remove-buffs.d.ts +16 -0
  28. package/engine/behaviour/ability/remove-buffs.lua +28 -0
  29. package/engine/behaviour/ability.d.ts +20 -4
  30. package/engine/behaviour/ability.lua +111 -38
  31. package/engine/behaviour/unit.d.ts +2 -0
  32. package/engine/buff.d.ts +56 -41
  33. package/engine/buff.lua +295 -228
  34. package/engine/internal/ability.d.ts +13 -2
  35. package/engine/internal/ability.lua +77 -4
  36. package/engine/internal/item/ability.lua +106 -0
  37. package/engine/internal/item.d.ts +4 -3
  38. package/engine/internal/item.lua +56 -25
  39. package/engine/internal/mechanics/ability-duration.lua +1 -1
  40. package/engine/internal/misc/ability-disable-counter.d.ts +2 -0
  41. package/engine/internal/misc/ability-disable-counter.lua +13 -0
  42. package/engine/internal/misc/damage-metadata-by-target.d.ts +2 -0
  43. package/engine/internal/misc/damage-metadata-by-target.lua +5 -0
  44. package/engine/internal/object-data/auto-attack-speed-increase.d.ts +1 -1
  45. package/engine/internal/object-data/auto-attack-speed-increase.lua +2 -0
  46. package/engine/internal/object-data/evasion-probability.d.ts +2 -0
  47. package/engine/internal/object-data/evasion-probability.lua +16 -0
  48. package/engine/internal/unit/ability.d.ts +10 -1
  49. package/engine/internal/unit/ability.lua +36 -0
  50. package/engine/internal/unit/add-item-to-slot-init.d.ts +2 -0
  51. package/engine/internal/unit/add-item-to-slot-init.lua +23 -0
  52. package/engine/internal/unit/add-item-to-slot.d.ts +2 -0
  53. package/engine/internal/unit/add-item-to-slot.lua +52 -0
  54. package/engine/internal/unit/bonus.d.ts +2 -0
  55. package/engine/internal/unit/bonus.lua +17 -0
  56. package/engine/internal/unit/ignore-events-items.d.ts +2 -0
  57. package/engine/internal/unit/ignore-events-items.lua +5 -0
  58. package/engine/internal/unit/item.lua +6 -12
  59. package/engine/internal/unit+damage.d.ts +2 -11
  60. package/engine/internal/unit+damage.lua +10 -14
  61. package/engine/internal/unit+spellSteal.lua +1 -2
  62. package/engine/internal/unit.d.ts +21 -4
  63. package/engine/internal/unit.lua +157 -46
  64. package/engine/internal/utility.lua +12 -0
  65. package/engine/lightning.d.ts +12 -5
  66. package/engine/lightning.lua +48 -14
  67. package/engine/object-data/auxiliary/animation-name.d.ts +1 -0
  68. package/engine/object-data/auxiliary/animation-name.lua +16 -0
  69. package/engine/object-data/auxiliary/attachment-preset.d.ts +7 -2
  70. package/engine/object-data/auxiliary/attachment-preset.lua +4 -3
  71. package/engine/object-data/auxiliary/attack-type.d.ts +7 -8
  72. package/engine/object-data/auxiliary/attack-type.lua +42 -0
  73. package/engine/object-data/auxiliary/movement-type.d.ts +7 -7
  74. package/engine/object-data/auxiliary/movement-type.lua +22 -0
  75. package/engine/object-data/auxiliary/sound-eax.d.ts +10 -0
  76. package/engine/object-data/auxiliary/sound-eax.lua +2 -0
  77. package/engine/object-data/auxiliary/sound-preset-name.d.ts +5 -1
  78. package/engine/object-data/auxiliary/tech-tree-dependency.d.ts +1 -1
  79. package/engine/object-data/auxiliary/unit-attribute.d.ts +6 -0
  80. package/engine/object-data/auxiliary/unit-attribute.lua +9 -0
  81. package/engine/object-data/entry/ability-type/berserk.d.ts +2 -0
  82. package/engine/object-data/entry/ability-type/berserk.lua +13 -0
  83. package/engine/object-data/entry/ability-type/blank-configurable.lua +12 -1
  84. package/engine/object-data/entry/ability-type/carrion-swarm.d.ts +14 -0
  85. package/engine/object-data/entry/ability-type/carrion-swarm.lua +65 -0
  86. package/engine/object-data/entry/ability-type/disease-cloud.lua +2 -2
  87. package/engine/object-data/entry/ability-type/engineering-upgrade.lua +2 -2
  88. package/engine/object-data/entry/ability-type/ensnare.d.ts +12 -0
  89. package/engine/object-data/entry/ability-type/ensnare.lua +52 -0
  90. package/engine/object-data/entry/ability-type/feral-spirit.lua +2 -2
  91. package/engine/object-data/entry/ability-type/phase-shift.d.ts +10 -0
  92. package/engine/object-data/entry/ability-type/phase-shift.lua +39 -0
  93. package/engine/object-data/entry/ability-type/phoenix-morph.lua +4 -4
  94. package/engine/object-data/entry/ability-type/raise-dead.d.ts +17 -0
  95. package/engine/object-data/entry/ability-type/raise-dead.lua +78 -0
  96. package/engine/object-data/entry/ability-type/shock-wave.d.ts +4 -0
  97. package/engine/object-data/entry/ability-type/shock-wave.lua +26 -0
  98. package/engine/object-data/entry/ability-type/slow-poison.d.ts +10 -0
  99. package/engine/object-data/entry/ability-type/slow-poison.lua +58 -0
  100. package/engine/object-data/entry/ability-type/summon-quilbeast.lua +2 -2
  101. package/engine/object-data/entry/ability-type/summon-water-elemental.lua +2 -2
  102. package/engine/object-data/entry/ability-type/web.d.ts +12 -0
  103. package/engine/object-data/entry/ability-type/web.lua +52 -0
  104. package/engine/object-data/entry/ability-type.d.ts +19 -17
  105. package/engine/object-data/entry/ability-type.lua +89 -33
  106. package/engine/object-data/entry/buff-type/applicable.lua +18 -37
  107. package/engine/object-data/entry/buff-type.d.ts +6 -12
  108. package/engine/object-data/entry/buff-type.lua +13 -29
  109. package/engine/object-data/entry/destructible-type.d.ts +1 -1
  110. package/engine/object-data/entry/item-type.d.ts +3 -1
  111. package/engine/object-data/entry/item-type.lua +15 -2
  112. package/engine/object-data/entry/lightning-type.d.ts +1 -1
  113. package/engine/object-data/entry/sound-preset.d.ts +33 -0
  114. package/engine/object-data/entry/sound-preset.lua +140 -0
  115. package/engine/object-data/entry/unit-type.d.ts +10 -3
  116. package/engine/object-data/entry/unit-type.lua +155 -92
  117. package/engine/object-data/entry/upgrade.d.ts +1 -1
  118. package/engine/object-data/entry/upgrade.lua +4 -4
  119. package/engine/object-data/entry.d.ts +16 -14
  120. package/engine/object-data/entry.lua +60 -32
  121. package/engine/object-data/utility/object-data-entry-id-generator.lua +7 -0
  122. package/engine/object-field/ability.d.ts +10 -4
  123. package/engine/object-field/ability.lua +3 -0
  124. package/engine/object-field/unit.d.ts +46 -3
  125. package/engine/object-field/unit.lua +173 -7
  126. package/engine/object-field.d.ts +11 -3
  127. package/engine/object-field.lua +162 -76
  128. package/engine/standard/entries/buff-type.d.ts +3 -0
  129. package/engine/standard/entries/buff-type.lua +3 -0
  130. package/engine/standard/entries/sound-preset.d.ts +10 -0
  131. package/engine/standard/entries/sound-preset.lua +10 -0
  132. package/engine/standard/fields/ability.d.ts +2 -0
  133. package/engine/standard/fields/ability.lua +2 -0
  134. package/engine/unit.d.ts +1 -0
  135. package/engine/unit.lua +1 -0
  136. package/objutil/buff.lua +1 -2
  137. package/objutil/unit.lua +8 -0
  138. package/package.json +2 -2
  139. package/utility/arrays.d.ts +1 -0
  140. package/utility/arrays.lua +3 -0
  141. package/utility/functions.d.ts +1 -0
  142. package/utility/functions.lua +1 -0
  143. package/utility/lazy.d.ts +2 -0
  144. package/utility/lazy.lua +14 -0
  145. package/utility/linked-set.d.ts +1 -0
  146. package/utility/linked-set.lua +3 -0
  147. package/utility/lua-maps.d.ts +3 -0
  148. package/utility/lua-maps.lua +16 -0
  149. package/utility/lua-sets.d.ts +1 -0
  150. package/utility/lua-sets.lua +3 -0
  151. package/utility/reflection.lua +11 -7
@@ -51,11 +51,21 @@ 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
66
  local setUnitAnimationWithRarity = SetUnitAnimationWithRarity
58
67
  local setUnitAnimationByIndex = SetUnitAnimationByIndex
68
+ local resetUnitAnimation = ResetUnitAnimation
59
69
  local queueUnitAnimation = QueueUnitAnimation
60
70
  local getUnitIntegerField = BlzGetUnitIntegerField
61
71
  local getUnitRealField = BlzGetUnitRealField
@@ -75,9 +85,9 @@ local setUnitScale = SetUnitScale
75
85
  local setUnitPosition = SetUnitPosition
76
86
  local setUnitTimeScale = SetUnitTimeScale
77
87
  local getHandleId = GetHandleId
88
+ local getUnitCurrentOrder = GetUnitCurrentOrder
78
89
  local createUnit = CreateUnit
79
90
  local killUnit = KillUnit
80
- local setUnitExploded = SetUnitExploded
81
91
  local removeUnit = RemoveUnit
82
92
  local getUnitTypeId = GetUnitTypeId
83
93
  local isHeroUnitId = IsHeroUnitId
@@ -93,8 +103,6 @@ local getSpellTargetItem = GetSpellTargetItem
93
103
  local getSpellTargetDestructable = GetSpellTargetDestructable
94
104
  local isUnitInRangeXY = IsUnitInRangeXY
95
105
  local isUnitInRange = IsUnitInRange
96
- local setResourceAmount = SetResourceAmount
97
- local getResourceAmount = GetResourceAmount
98
106
  local getUnitWeaponRealField = BlzGetUnitWeaponRealField
99
107
  local setUnitWeaponRealField = BlzSetUnitWeaponRealField
100
108
  local getUnitWeaponStringField = BlzGetUnitWeaponStringField
@@ -125,8 +133,6 @@ local isUnitType = IsUnitType
125
133
  local isUnitAlly = IsUnitAlly
126
134
  local isUnitEnemy = IsUnitEnemy
127
135
  local getOwningPlayer = GetOwningPlayer
128
- local setUnitColor = SetUnitColor
129
- local showUnitTeamGlow = BlzShowUnitTeamGlow
130
136
  ____exports.UnitClassification = {}
131
137
  local UnitClassification = ____exports.UnitClassification
132
138
  do
@@ -354,7 +360,14 @@ local function damageEventPreventDeath(self, callback, ...)
354
360
  rawset(self, 1 + i, (select(i, ...)))
355
361
  end
356
362
  end
357
- local damageSetters = {amount = BlzSetEventDamage, attackType = BlzSetEventAttackType, damageType = BlzSetEventDamageType, weaponType = BlzSetEventWeaponType}
363
+ local damageSetters = {
364
+ amount = BlzSetEventDamage,
365
+ attackType = function(attackType)
366
+ return BlzSetEventAttackType(attackTypeToNative(attackType))
367
+ end,
368
+ damageType = BlzSetEventDamageType,
369
+ weaponType = BlzSetEventWeaponType
370
+ }
358
371
  local jlimitopByOperator = {
359
372
  [0] = LESS_THAN_OR_EQUAL,
360
373
  [1] = LESS_THAN_OR_EQUAL,
@@ -636,7 +649,8 @@ local function delayHealthChecksCallback(unit)
636
649
  end
637
650
  end
638
651
  local nextSyncId = 1
639
- local unitBySyncId = setmetatable({}, {__mode = "k"})
652
+ local unitBySyncId = setmetatable({}, {__mode = "v"})
653
+ local damagingEventByTarget = setmetatable({}, {__mode = "k"})
640
654
  ____exports.Unit = __TS__Class()
641
655
  local Unit = ____exports.Unit
642
656
  Unit.name = "Unit"
@@ -677,6 +691,8 @@ function Unit.prototype.getEvent(self, event, collector)
677
691
  end
678
692
  function Unit.prototype.onDestroy(self)
679
693
  local handle = self.handle
694
+ self[107] = getUnitX(handle)
695
+ self[108] = getUnitY(handle)
680
696
  if not self._owner then
681
697
  self._owner = Player:of(getOwningPlayer(handle))
682
698
  end
@@ -792,6 +808,9 @@ function Unit.prototype.playAnimation(self, animation, rarity)
792
808
  setUnitAnimation(self.handle, animation)
793
809
  end
794
810
  end
811
+ function Unit.prototype.resetAnimation(self)
812
+ resetUnitAnimation(self.handle)
813
+ end
795
814
  function Unit.prototype.queueAnimation(self, animation)
796
815
  queueUnitAnimation(self.handle, animation)
797
816
  end
@@ -806,7 +825,7 @@ function Unit.prototype.isSelected(self, player)
806
825
  return IsUnitSelected(self.handle, player.handle)
807
826
  end
808
827
  function Unit.prototype.explode(self)
809
- setUnitExploded(self.handle, true)
828
+ SetUnitExploded(self.handle, true)
810
829
  killUnit(self.handle)
811
830
  end
812
831
  function Unit.prototype.kill(self)
@@ -929,8 +948,15 @@ function Unit.prototype.interruptAttack(self)
929
948
  unitInterruptAttack(self.handle)
930
949
  end
931
950
  function Unit.prototype.interruptCast(self, abilityId)
932
- unitDisableAbility(self.handle, abilityId, true, false)
933
- unitDisableAbility(self.handle, abilityId, false, false)
951
+ local handle = self.handle
952
+ unitDisableAbility(handle, abilityId, true, false)
953
+ Timer:run(
954
+ unitDisableAbility,
955
+ handle,
956
+ abilityId,
957
+ false,
958
+ false
959
+ )
934
960
  end
935
961
  function Unit.prototype.getDistanceTo(self, target)
936
962
  local handle = self.handle
@@ -1195,6 +1221,14 @@ __TS__SetDescriptor(
1195
1221
  end},
1196
1222
  true
1197
1223
  )
1224
+ __TS__SetDescriptor(
1225
+ Unit.prototype,
1226
+ "isStunned",
1227
+ {get = function(self)
1228
+ return getUnitCurrentOrder(self.handle) == orderId("stunned")
1229
+ end},
1230
+ true
1231
+ )
1198
1232
  __TS__SetDescriptor(
1199
1233
  Unit.prototype,
1200
1234
  "combatClassifications",
@@ -1268,6 +1302,19 @@ __TS__SetDescriptor(
1268
1302
  },
1269
1303
  true
1270
1304
  )
1305
+ __TS__SetDescriptor(
1306
+ Unit.prototype,
1307
+ "primaryAttribute",
1308
+ {
1309
+ get = function(self)
1310
+ return getUnitIntegerField(self.handle, UNIT_IF_PRIMARY_ATTRIBUTE)
1311
+ end,
1312
+ set = function(self, primaryAttribute)
1313
+ setUnitIntegerField(self.handle, UNIT_IF_PRIMARY_ATTRIBUTE, primaryAttribute)
1314
+ end
1315
+ },
1316
+ true
1317
+ )
1271
1318
  __TS__SetDescriptor(
1272
1319
  Unit.prototype,
1273
1320
  "strengthBase",
@@ -1392,7 +1439,7 @@ __TS__SetDescriptor(
1392
1439
  return not self[106]
1393
1440
  end,
1394
1441
  set = function(self, isTeamGlowVisible)
1395
- showUnitTeamGlow(self.handle, isTeamGlowVisible)
1442
+ BlzShowUnitTeamGlow(self.handle, isTeamGlowVisible)
1396
1443
  local ____temp_6
1397
1444
  if not isTeamGlowVisible then
1398
1445
  ____temp_6 = true
@@ -1408,9 +1455,9 @@ __TS__SetDescriptor(
1408
1455
  Unit.prototype,
1409
1456
  "color",
1410
1457
  {set = function(self, color)
1411
- setUnitColor(self.handle, color.handle)
1458
+ SetUnitColor(self.handle, color.handle)
1412
1459
  if self[106] then
1413
- showUnitTeamGlow(self.handle, false)
1460
+ BlzShowUnitTeamGlow(self.handle, false)
1414
1461
  end
1415
1462
  end},
1416
1463
  true
@@ -1579,7 +1626,7 @@ __TS__SetDescriptor(
1579
1626
  "x",
1580
1627
  {
1581
1628
  get = function(self)
1582
- return getUnitX(self.handle)
1629
+ return self[107] or getUnitX(self.handle)
1583
1630
  end,
1584
1631
  set = function(self, v)
1585
1632
  SetUnitX(self.handle, v)
@@ -1592,7 +1639,7 @@ __TS__SetDescriptor(
1592
1639
  "y",
1593
1640
  {
1594
1641
  get = function(self)
1595
- return getUnitY(self.handle)
1642
+ return self[108] or getUnitY(self.handle)
1596
1643
  end,
1597
1644
  set = function(self, v)
1598
1645
  SetUnitY(self.handle, v)
@@ -1678,10 +1725,10 @@ __TS__SetDescriptor(
1678
1725
  "gold",
1679
1726
  {
1680
1727
  get = function(self)
1681
- return getResourceAmount(self.handle)
1728
+ return GetResourceAmount(self.handle)
1682
1729
  end,
1683
1730
  set = function(self, gold)
1684
- setResourceAmount(self.handle, gold)
1731
+ SetResourceAmount(self.handle, gold)
1685
1732
  end
1686
1733
  },
1687
1734
  true
@@ -1809,6 +1856,19 @@ __TS__SetDescriptor(
1809
1856
  end},
1810
1857
  true
1811
1858
  )
1859
+ __TS__SetDescriptor(
1860
+ Unit.prototype,
1861
+ "movementType",
1862
+ {
1863
+ get = function(self)
1864
+ return getUnitIntegerField(self.handle, UNIT_IF_MOVE_TYPE)
1865
+ end,
1866
+ set = function(self, movementType)
1867
+ setUnitIntegerField(self.handle, UNIT_IF_MOVE_TYPE, movementType)
1868
+ end
1869
+ },
1870
+ true
1871
+ )
1812
1872
  __TS__SetDescriptor(
1813
1873
  Unit.prototype,
1814
1874
  "pathing",
@@ -2315,10 +2375,12 @@ Unit.onImmediateOrder = dispatchId(__TS__New(
2315
2375
  ____exports.UnitTriggerEvent,
2316
2376
  EVENT_PLAYER_UNIT_ISSUED_ORDER,
2317
2377
  function()
2318
- local unit = ____exports.Unit:of(getOrderedUnit())
2319
- local issuedOrderId = getIssuedOrderId()
2320
- if unit ~= nil and unit.state == 1 then
2321
- return unit, issuedOrderId
2378
+ local handle = getOrderedUnit()
2379
+ if handle ~= nil and getUnitTypeId(handle) ~= dummyUnitId then
2380
+ local unit = ____exports.Unit:of(handle)
2381
+ if unit.state == 1 then
2382
+ return unit, getIssuedOrderId()
2383
+ end
2322
2384
  end
2323
2385
  return IgnoreEvent
2324
2386
  end
@@ -2349,13 +2411,18 @@ Unit.onDamaging = (function()
2349
2411
  if source and source.typeId == dummyUnitId then
2350
2412
  source = nil
2351
2413
  end
2352
- local target = BlzGetEventDamageTarget()
2414
+ local target = ____exports.Unit:of(BlzGetEventDamageTarget())
2415
+ local metadata = damageMetadataByTarget[target]
2416
+ damageMetadataByTarget[target] = nil
2353
2417
  local data = {
2354
2418
  amount = GetEventDamage(),
2355
- attackType = BlzGetEventAttackType(),
2419
+ attackType = nativeToAttackType(BlzGetEventAttackType()),
2356
2420
  damageType = BlzGetEventDamageType(),
2357
2421
  weaponType = BlzGetEventWeaponType(),
2358
- isAttack = BlzGetEventIsAttack()
2422
+ metadata = metadata,
2423
+ isAttack = BlzGetEventIsAttack(),
2424
+ originalAmount = GetEventDamage(),
2425
+ originalMetadata = metadata
2359
2426
  }
2360
2427
  if data.isAttack and source then
2361
2428
  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
@@ -2369,18 +2436,22 @@ Unit.onDamaging = (function()
2369
2436
  invoke(
2370
2437
  event,
2371
2438
  source,
2372
- ____exports.Unit:of(target),
2439
+ target,
2373
2440
  setmetatable(
2374
2441
  {},
2375
2442
  {
2376
2443
  __index = data,
2377
2444
  __newindex = function(self, key, value)
2378
- damageSetters[key](value)
2445
+ local damageSetter = damageSetters[key]
2446
+ if damageSetter ~= nil then
2447
+ damageSetter(value)
2448
+ end
2379
2449
  data[key] = value
2380
2450
  end
2381
2451
  }
2382
2452
  )
2383
2453
  )
2454
+ damagingEventByTarget[target] = data
2384
2455
  return
2385
2456
  end
2386
2457
  BlzSetEventDamage(0)
@@ -2388,7 +2459,7 @@ Unit.onDamaging = (function()
2388
2459
  BlzSetEventDamageType(DAMAGE_TYPE_UNKNOWN)
2389
2460
  BlzSetEventWeaponType(WEAPON_TYPE_WHOKNOWS)
2390
2461
  local sourceOwner = source.owner.handle
2391
- local targetOwner = GetOwningPlayer(target)
2462
+ local targetOwner = target.owner.handle
2392
2463
  if not GetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE) then
2393
2464
  SetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE, true)
2394
2465
  Timer:run(function()
@@ -2404,23 +2475,19 @@ Unit.onDamaging = (function()
2404
2475
  for ____, ____value in ipairs(source._attackHandlers) do
2405
2476
  local condition = ____value[1]
2406
2477
  local action = ____value[2]
2407
- if condition(
2408
- source,
2409
- ____exports.Unit:of(target),
2410
- data
2411
- ) then
2478
+ if condition(source, target, data) then
2412
2479
  action(
2413
2480
  source,
2414
- ____exports.Unit:of(target),
2481
+ target,
2415
2482
  setmetatable(
2416
2483
  {fire = function()
2417
2484
  UnitDamageTarget(
2418
2485
  source.handle,
2419
- target,
2486
+ target.handle,
2420
2487
  data.amount,
2421
2488
  true,
2422
2489
  true,
2423
- data.attackType,
2490
+ attackTypeToNative(data.attackType),
2424
2491
  data.damageType,
2425
2492
  data.weaponType
2426
2493
  )
@@ -2447,26 +2514,40 @@ Unit.onDamage = __TS__New(
2447
2514
  if source and source.typeId == dummyUnitId then
2448
2515
  source = nil
2449
2516
  end
2517
+ local target = ____exports.Unit:of(BlzGetEventDamageTarget())
2518
+ local damagingEvent = damagingEventByTarget[target]
2519
+ damagingEventByTarget[target] = nil
2450
2520
  local data = {
2451
2521
  amount = GetEventDamage(),
2452
- attackType = BlzGetEventAttackType(),
2522
+ attackType = nativeToAttackType(BlzGetEventAttackType()),
2453
2523
  damageType = BlzGetEventDamageType(),
2454
2524
  weaponType = BlzGetEventWeaponType(),
2525
+ metadata = damagingEvent and damagingEvent.metadata,
2455
2526
  isAttack = BlzGetEventIsAttack(),
2456
- originalAmount = GetEventDamage(),
2527
+ originalAmount = damagingEvent and damagingEvent.originalAmount or GetEventDamage(),
2528
+ originalMetadata = damagingEvent and damagingEvent.originalMetadata,
2457
2529
  preventDeath = damageEventPreventDeath
2458
2530
  }
2531
+ if damagingEvent then
2532
+ for key, value in pairs(damagingEvent) do
2533
+ if isAttribute(key) then
2534
+ data[key] = value
2535
+ end
2536
+ end
2537
+ end
2459
2538
  local evData = setmetatable(
2460
2539
  {},
2461
2540
  {
2462
2541
  __index = data,
2463
2542
  __newindex = function(self, key, value)
2464
- damageSetters[key](value)
2543
+ local damageSetter = damageSetters[key]
2544
+ if damageSetter ~= nil then
2545
+ damageSetter(value)
2546
+ end
2465
2547
  data[key] = value
2466
2548
  end
2467
2549
  }
2468
2550
  )
2469
- local target = ____exports.Unit:of(BlzGetEventDamageTarget())
2470
2551
  invoke(event, source, target, evData)
2471
2552
  if evData[0] ~= nil and target.health - evData.amount < 0.405 then
2472
2553
  local bonusHealth = math.ceil(evData.amount)
@@ -2509,8 +2590,9 @@ Unit.itemDroppedEvent = __TS__New(
2509
2590
  EVENT_PLAYER_UNIT_DROP_ITEM,
2510
2591
  function()
2511
2592
  local unit = getTriggerUnit()
2512
- if getUnitTypeId(unit) ~= dummyUnitId then
2513
- return ____exports.Unit:of(unit), Item:of(getManipulatedItem())
2593
+ local item = getManipulatedItem()
2594
+ if getUnitTypeId(unit) ~= dummyUnitId and not (ignoreEventsItems[item] ~= nil) then
2595
+ return ____exports.Unit:of(unit), Item:of(item)
2514
2596
  end
2515
2597
  return IgnoreEvent
2516
2598
  end
@@ -2520,8 +2602,9 @@ Unit.itemPickedUpEvent = __TS__New(
2520
2602
  EVENT_PLAYER_UNIT_PICKUP_ITEM,
2521
2603
  function()
2522
2604
  local unit = getTriggerUnit()
2523
- if getUnitTypeId(unit) ~= dummyUnitId then
2524
- return ____exports.Unit:of(unit), Item:of(getManipulatedItem())
2605
+ local item = getManipulatedItem()
2606
+ if getUnitTypeId(unit) ~= dummyUnitId and not (ignoreEventsItems[item] ~= nil) then
2607
+ return ____exports.Unit:of(unit), Item:of(item)
2525
2608
  end
2526
2609
  return IgnoreEvent
2527
2610
  end
@@ -2529,7 +2612,14 @@ Unit.itemPickedUpEvent = __TS__New(
2529
2612
  Unit.itemUsedEvent = __TS__New(
2530
2613
  ____exports.UnitTriggerEvent,
2531
2614
  EVENT_PLAYER_UNIT_USE_ITEM,
2532
- function() return ____exports.Unit:of(getTriggerUnit()), Item:of(getManipulatedItem()) end
2615
+ function()
2616
+ local unit = getTriggerUnit()
2617
+ local item = getManipulatedItem()
2618
+ if getUnitTypeId(unit) ~= dummyUnitId and not (ignoreEventsItems[item] ~= nil) then
2619
+ return ____exports.Unit:of(unit), Item:of(item)
2620
+ end
2621
+ return IgnoreEvent
2622
+ end
2533
2623
  )
2534
2624
  Unit.itemStackedEvent = __TS__New(
2535
2625
  ____exports.UnitTriggerEvent,
@@ -2538,7 +2628,28 @@ Unit.itemStackedEvent = __TS__New(
2538
2628
  )
2539
2629
  __TS__ObjectDefineProperty(
2540
2630
  Unit,
2541
- "itemMovedEvent",
2631
+ "itemUseOrderEvent",
2632
+ {get = function(self)
2633
+ local event = __TS__New(Event)
2634
+ for order = orderId("useslot0"), orderId("useslot5") do
2635
+ local slot = order - orderId("useslot0")
2636
+ local function listener(unit)
2637
+ local item = unit.items[slot + 1]
2638
+ if item ~= nil then
2639
+ invoke(event, unit, item)
2640
+ end
2641
+ end
2642
+ self.onImmediateOrder[order]:addListener(listener)
2643
+ self.onTargetOrder[order]:addListener(listener)
2644
+ self.onPointOrder[order]:addListener(listener)
2645
+ end
2646
+ rawset(self, "itemUseOrderEvent", event)
2647
+ return event
2648
+ end}
2649
+ )
2650
+ __TS__ObjectDefineProperty(
2651
+ Unit,
2652
+ "itemMoveOrderEvent",
2542
2653
  {get = function(self)
2543
2654
  local event = __TS__New(Event)
2544
2655
  for order = orderId("moveslot0"), orderId("moveslot5") do
@@ -2556,7 +2667,7 @@ __TS__ObjectDefineProperty(
2556
2667
  end
2557
2668
  end)
2558
2669
  end
2559
- rawset(self, "itemMovedEvent", event)
2670
+ rawset(self, "itemMoveOrderEvent", event)
2560
2671
  return event
2561
2672
  end}
2562
2673
  )
@@ -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 {};
@@ -1,15 +1,16 @@
1
1
  local ____lualib = require("lualib_bundle")
2
2
  local __TS__Class = ____lualib.__TS__Class
3
3
  local __TS__ClassExtends = ____lualib.__TS__ClassExtends
4
+ local __TS__New = ____lualib.__TS__New
4
5
  local ____exports = {}
5
- local ____handle = require("core.types.handle")
6
- local Handle = ____handle.Handle
7
6
  local ____timer = require("core.types.timer")
8
7
  local Timer = ____timer.Timer
9
8
  local ____functions = require("utility.functions")
10
9
  local forwardByN = ____functions.forwardByN
11
10
  local ____unit_2Dmissile_2Ddata = require("engine.internal.unit-missile-data")
12
11
  local MISSILE_DATA_BY_UNIT_TYPE_ID = ____unit_2Dmissile_2Ddata.MISSILE_DATA_BY_UNIT_TYPE_ID
12
+ local ____destroyable = require("destroyable")
13
+ local AbstractDestroyable = ____destroyable.AbstractDestroyable
13
14
  local ____type = _G.type
14
15
  local select = _G.select
15
16
  local cos = math.cos
@@ -27,6 +28,11 @@ local getUnitZ = BlzGetUnitZ
27
28
  local getUnitFlyHeight = GetUnitFlyHeight
28
29
  local getLocationZ = GetLocationZ
29
30
  local moveLocation = MoveLocation
31
+ local getLightningColorA = GetLightningColorA
32
+ local getLightningColorR = GetLightningColorR
33
+ local getLightningColorG = GetLightningColorG
34
+ local getLightningColorB = GetLightningColorB
35
+ local setLightningColor = SetLightningColor
30
36
  local location = Location(0, 0)
31
37
  local unitToUnitLightnings = setmetatable({}, {__mode = "k"})
32
38
  local unitToPointLightnings = setmetatable({}, {__mode = "k"})
@@ -36,9 +42,10 @@ local temporaryLightningsCount = 0
36
42
  ____exports.Lightning = __TS__Class()
37
43
  local Lightning = ____exports.Lightning
38
44
  Lightning.name = "Lightning"
39
- __TS__ClassExtends(Lightning, Handle)
45
+ __TS__ClassExtends(Lightning, AbstractDestroyable)
40
46
  function Lightning.prototype.____constructor(self, handle, typeId)
41
- Handle.prototype.____constructor(self, handle)
47
+ AbstractDestroyable.prototype.____constructor(self)
48
+ self.handle = handle
42
49
  self.typeId = typeId
43
50
  end
44
51
  function Lightning.prototype.onDestroy(self)
@@ -46,7 +53,7 @@ function Lightning.prototype.onDestroy(self)
46
53
  unitToPointLightnings[self] = nil
47
54
  pointToUnitLightnings[self] = nil
48
55
  destroyLightning(self.handle)
49
- return Handle.prototype.onDestroy(self)
56
+ return AbstractDestroyable.prototype.onDestroy(self)
50
57
  end
51
58
  function Lightning.create(self, typeId, checkVisibility, sourceXOrSourceUnit, sourceYOrTargetXOrTargetUnit, sourceZOrTargetXOrTargetUnitOrTargetY, targetXOrTargetUnitOrTargetYOrTargetZ, targetY, targetZ)
52
59
  if type(checkVisibility) ~= "boolean" then
@@ -62,7 +69,8 @@ function Lightning.create(self, typeId, checkVisibility, sourceXOrSourceUnit, so
62
69
  )
63
70
  end
64
71
  if targetZ ~= nil then
65
- return self:of(
72
+ return __TS__New(
73
+ self,
66
74
  addLightningEx(
67
75
  util.id2s(typeId),
68
76
  checkVisibility,
@@ -79,7 +87,8 @@ function Lightning.create(self, typeId, checkVisibility, sourceXOrSourceUnit, so
79
87
  if targetXOrTargetUnitOrTargetYOrTargetZ ~= nil then
80
88
  if ____type(targetXOrTargetUnitOrTargetYOrTargetZ) == "number" then
81
89
  if ____type(sourceXOrSourceUnit) == "number" then
82
- return self:of(
90
+ return __TS__New(
91
+ self,
83
92
  addLightning(
84
93
  util.id2s(typeId),
85
94
  checkVisibility,
@@ -92,7 +101,8 @@ function Lightning.create(self, typeId, checkVisibility, sourceXOrSourceUnit, so
92
101
  )
93
102
  end
94
103
  local unit = sourceXOrSourceUnit.handle
95
- local lightning = self:of(
104
+ local lightning = __TS__New(
105
+ self,
96
106
  addLightningEx(
97
107
  util.id2s(typeId),
98
108
  checkVisibility,
@@ -117,7 +127,8 @@ function Lightning.create(self, typeId, checkVisibility, sourceXOrSourceUnit, so
117
127
  return lightning
118
128
  end
119
129
  local unit = targetXOrTargetUnitOrTargetYOrTargetZ.handle
120
- local lightning = self:of(
130
+ local lightning = __TS__New(
131
+ self,
121
132
  addLightningEx(
122
133
  util.id2s(typeId),
123
134
  checkVisibility,
@@ -146,7 +157,8 @@ function Lightning.create(self, typeId, checkVisibility, sourceXOrSourceUnit, so
146
157
  local unit = sourceXOrSourceUnit.handle
147
158
  moveLocation(location, sourceYOrTargetXOrTargetUnit, sourceZOrTargetXOrTargetUnitOrTargetY)
148
159
  local z = getLocationZ(location)
149
- local lightning = self:of(
160
+ local lightning = __TS__New(
161
+ self,
150
162
  addLightningEx(
151
163
  util.id2s(typeId),
152
164
  checkVisibility,
@@ -173,7 +185,8 @@ function Lightning.create(self, typeId, checkVisibility, sourceXOrSourceUnit, so
173
185
  local unit = sourceZOrTargetXOrTargetUnitOrTargetY.handle
174
186
  moveLocation(location, sourceXOrSourceUnit, sourceYOrTargetXOrTargetUnit)
175
187
  local z = getLocationZ(location)
176
- local lightning = self:of(
188
+ local lightning = __TS__New(
189
+ self,
177
190
  addLightningEx(
178
191
  util.id2s(typeId),
179
192
  checkVisibility,
@@ -199,7 +212,8 @@ function Lightning.create(self, typeId, checkVisibility, sourceXOrSourceUnit, so
199
212
  end
200
213
  local sourceUnit = sourceXOrSourceUnit.handle
201
214
  local targetUnit = sourceYOrTargetXOrTargetUnit.handle
202
- local lightning = self:of(
215
+ local lightning = __TS__New(
216
+ self,
203
217
  addLightningEx(
204
218
  util.id2s(typeId),
205
219
  checkVisibility,
@@ -225,9 +239,19 @@ function Lightning.create(self, typeId, checkVisibility, sourceXOrSourceUnit, so
225
239
  return lightning
226
240
  end
227
241
  function Lightning.flash(self, ...)
228
- local parametersToForwardCount = select("#", ...) - 1
242
+ local parameterOrDuration, durationOrFading = select(-2, ...)
243
+ local hasFading = ____type(durationOrFading) ~= "number"
244
+ local parametersToForwardCount = select("#", ...) - (hasFading and 2 or 1)
229
245
  local lightning = forwardByN[parametersToForwardCount](____exports.Lightning.create, self, ...)
230
- local duration = select(-1, ...)
246
+ local duration
247
+ if hasFading then
248
+ duration = parameterOrDuration
249
+ if durationOrFading then
250
+ lightning[110] = true
251
+ end
252
+ else
253
+ duration = durationOrFading
254
+ end
231
255
  lightning[109] = duration
232
256
  temporaryLightningsCount = temporaryLightningsCount + 1
233
257
  temporaryLightnings[temporaryLightningsCount] = lightning
@@ -295,6 +319,16 @@ Timer.onPeriod[UPDATE_PERIOD]:addListener(function()
295
319
  temporaryLightnings[temporaryLightningsCount] = nil
296
320
  temporaryLightningsCount = temporaryLightningsCount - 1
297
321
  else
322
+ if lightning[110] then
323
+ local handle = lightning.handle
324
+ setLightningColor(
325
+ handle,
326
+ getLightningColorR(handle),
327
+ getLightningColorG(handle),
328
+ getLightningColorB(handle),
329
+ getLightningColorA(handle) * (1 - UPDATE_PERIOD / duration)
330
+ )
331
+ end
298
332
  lightning[109] = duration - UPDATE_PERIOD
299
333
  i = i + 1
300
334
  end
@@ -12,3 +12,4 @@ export declare const enum AnimationName {
12
12
  STAND = "stand",
13
13
  WALK = "walk"
14
14
  }
15
+ export declare const isAnimationName: (value: string) => value is AnimationName;