warscript 0.0.1-dev.f48f7bb → 0.0.1-dev.f9166a3

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 (137) hide show
  1. package/attributes.d.ts +5 -0
  2. package/attributes.lua +8 -1
  3. package/config.d.ts +5 -0
  4. package/config.lua +10 -0
  5. package/core/types/effect.d.ts +1 -3
  6. package/core/types/effect.lua +26 -29
  7. package/core/types/order.d.ts +1 -0
  8. package/core/types/order.lua +11 -1
  9. package/core/types/sound.d.ts +17 -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.lua +6 -1
  14. package/decl/native.d.ts +840 -786
  15. package/engine/behaviour/ability/apply-buff.d.ts +5 -0
  16. package/engine/behaviour/ability/apply-buff.lua +32 -0
  17. package/engine/behaviour/ability/apply-unit-behavior.lua +1 -0
  18. package/engine/behaviour/ability/damage.d.ts +9 -3
  19. package/engine/behaviour/ability/damage.lua +26 -38
  20. package/engine/behaviour/ability/emulate-impact.lua +16 -2
  21. package/engine/behaviour/ability.d.ts +7 -2
  22. package/engine/behaviour/ability.lua +35 -8
  23. package/engine/behaviour/unit.d.ts +17 -0
  24. package/engine/behaviour/unit.lua +114 -4
  25. package/engine/buff.d.ts +56 -41
  26. package/engine/buff.lua +295 -228
  27. package/engine/internal/ability.d.ts +4 -0
  28. package/engine/internal/ability.lua +17 -2
  29. package/engine/internal/item/ability.lua +15 -13
  30. package/engine/internal/item.d.ts +7 -4
  31. package/engine/internal/item.lua +131 -28
  32. package/engine/internal/mechanics/ability-duration.lua +1 -1
  33. package/engine/internal/misc/damage-metadata-by-target.d.ts +2 -0
  34. package/engine/internal/misc/damage-metadata-by-target.lua +5 -0
  35. package/engine/internal/object-data/auto-attack-speed-increase.d.ts +1 -1
  36. package/engine/internal/object-data/auto-attack-speed-increase.lua +2 -0
  37. package/engine/internal/object-data/evasion-probability.d.ts +2 -0
  38. package/engine/internal/object-data/evasion-probability.lua +16 -0
  39. package/engine/internal/unit/ability.d.ts +5 -0
  40. package/engine/internal/unit/ability.lua +14 -0
  41. package/engine/internal/unit/add-item-to-slot-init.d.ts +2 -0
  42. package/engine/internal/unit/add-item-to-slot-init.lua +23 -0
  43. package/engine/internal/unit/add-item-to-slot.d.ts +2 -0
  44. package/engine/internal/unit/add-item-to-slot.lua +52 -0
  45. package/engine/internal/unit/allowed-targets.d.ts +1 -1
  46. package/engine/internal/unit/allowed-targets.lua +9 -1
  47. package/engine/internal/unit/bonus.d.ts +2 -0
  48. package/engine/internal/unit/bonus.lua +17 -0
  49. package/engine/internal/unit/item.lua +3 -48
  50. package/engine/internal/unit+damage.d.ts +2 -11
  51. package/engine/internal/unit+damage.lua +10 -14
  52. package/engine/internal/unit+spellSteal.lua +1 -2
  53. package/engine/internal/unit-missile-launch.lua +1 -1
  54. package/engine/internal/unit.d.ts +27 -4
  55. package/engine/internal/unit.lua +178 -37
  56. package/engine/lightning.d.ts +12 -5
  57. package/engine/lightning.lua +48 -14
  58. package/engine/object-data/auxiliary/animation-name.d.ts +1 -0
  59. package/engine/object-data/auxiliary/animation-name.lua +16 -0
  60. package/engine/object-data/auxiliary/attachment-preset.d.ts +7 -2
  61. package/engine/object-data/auxiliary/attachment-preset.lua +4 -3
  62. package/engine/object-data/auxiliary/attack-type.d.ts +7 -8
  63. package/engine/object-data/auxiliary/attack-type.lua +42 -0
  64. package/engine/object-data/auxiliary/movement-type.d.ts +7 -7
  65. package/engine/object-data/auxiliary/movement-type.lua +22 -0
  66. package/engine/object-data/auxiliary/sound-eax.d.ts +10 -0
  67. package/engine/object-data/auxiliary/sound-eax.lua +2 -0
  68. package/engine/object-data/auxiliary/tech-tree-dependency.d.ts +1 -1
  69. package/engine/object-data/auxiliary/unit-attribute.d.ts +6 -0
  70. package/engine/object-data/auxiliary/unit-attribute.lua +9 -0
  71. package/engine/object-data/entry/ability-type/berserk.d.ts +2 -0
  72. package/engine/object-data/entry/ability-type/berserk.lua +13 -0
  73. package/engine/object-data/entry/ability-type/blank-configurable.lua +12 -1
  74. package/engine/object-data/entry/ability-type/carrion-swarm.d.ts +14 -0
  75. package/engine/object-data/entry/ability-type/carrion-swarm.lua +65 -0
  76. package/engine/object-data/entry/ability-type/disease-cloud.lua +2 -2
  77. package/engine/object-data/entry/ability-type/engineering-upgrade.lua +2 -2
  78. package/engine/object-data/entry/ability-type/ensnare.d.ts +12 -0
  79. package/engine/object-data/entry/ability-type/ensnare.lua +52 -0
  80. package/engine/object-data/entry/ability-type/feral-spirit.lua +2 -2
  81. package/engine/object-data/entry/ability-type/permanent-invisibility.d.ts +8 -0
  82. package/engine/object-data/entry/ability-type/permanent-invisibility.lua +26 -0
  83. package/engine/object-data/entry/ability-type/phase-shift.d.ts +10 -0
  84. package/engine/object-data/entry/ability-type/phase-shift.lua +39 -0
  85. package/engine/object-data/entry/ability-type/phoenix-morph.lua +4 -4
  86. package/engine/object-data/entry/ability-type/raise-dead.d.ts +17 -0
  87. package/engine/object-data/entry/ability-type/raise-dead.lua +78 -0
  88. package/engine/object-data/entry/ability-type/shock-wave.d.ts +4 -0
  89. package/engine/object-data/entry/ability-type/shock-wave.lua +26 -0
  90. package/engine/object-data/entry/ability-type/slow-poison.d.ts +10 -0
  91. package/engine/object-data/entry/ability-type/slow-poison.lua +58 -0
  92. package/engine/object-data/entry/ability-type/summon-quilbeast.lua +2 -2
  93. package/engine/object-data/entry/ability-type/summon-water-elemental.lua +2 -2
  94. package/engine/object-data/entry/ability-type/web.d.ts +12 -0
  95. package/engine/object-data/entry/ability-type/web.lua +52 -0
  96. package/engine/object-data/entry/ability-type.d.ts +19 -17
  97. package/engine/object-data/entry/ability-type.lua +81 -21
  98. package/engine/object-data/entry/buff-type/applicable.lua +18 -37
  99. package/engine/object-data/entry/buff-type.d.ts +6 -12
  100. package/engine/object-data/entry/buff-type.lua +13 -29
  101. package/engine/object-data/entry/destructible-type.d.ts +1 -1
  102. package/engine/object-data/entry/item-type.d.ts +1 -1
  103. package/engine/object-data/entry/item-type.lua +4 -4
  104. package/engine/object-data/entry/lightning-type.d.ts +1 -1
  105. package/engine/object-data/entry/sound-preset.d.ts +33 -0
  106. package/engine/object-data/entry/sound-preset.lua +140 -0
  107. package/engine/object-data/entry/unit-type.d.ts +10 -3
  108. package/engine/object-data/entry/unit-type.lua +155 -92
  109. package/engine/object-data/entry/upgrade.d.ts +1 -1
  110. package/engine/object-data/entry/upgrade.lua +4 -4
  111. package/engine/object-data/entry.d.ts +16 -14
  112. package/engine/object-data/entry.lua +60 -32
  113. package/engine/object-field/ability.d.ts +1 -1
  114. package/engine/object-field/unit.d.ts +46 -3
  115. package/engine/object-field/unit.lua +173 -7
  116. package/engine/object-field.d.ts +12 -3
  117. package/engine/object-field.lua +164 -78
  118. package/engine/standard/entries/buff-type.d.ts +3 -0
  119. package/engine/standard/entries/buff-type.lua +3 -0
  120. package/engine/standard/entries/sound-preset.d.ts +10 -0
  121. package/engine/standard/entries/sound-preset.lua +10 -0
  122. package/engine/unit.d.ts +1 -0
  123. package/engine/unit.lua +1 -0
  124. package/objutil/buff.lua +1 -2
  125. package/objutil/unit.lua +8 -0
  126. package/package.json +2 -2
  127. package/utility/arrays.d.ts +1 -0
  128. package/utility/arrays.lua +3 -0
  129. package/utility/functions.d.ts +1 -0
  130. package/utility/functions.lua +1 -0
  131. package/utility/linked-set.d.ts +1 -0
  132. package/utility/linked-set.lua +3 -0
  133. package/utility/lua-maps.d.ts +3 -0
  134. package/utility/lua-maps.lua +16 -0
  135. package/utility/lua-sets.d.ts +1 -0
  136. package/utility/lua-sets.lua +3 -0
  137. package/utility/reflection.lua +11 -7
@@ -53,12 +53,17 @@ local ____math = require("math")
53
53
  local min = ____math.min
54
54
  local ____ignore_2Devents_2Ditems = require("engine.internal.unit.ignore-events-items")
55
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
56
63
  local match = string.match
57
64
  local ____tostring = _G.tostring
58
65
  local setUnitAnimation = SetUnitAnimation
59
- local setUnitAnimationWithRarity = SetUnitAnimationWithRarity
60
66
  local setUnitAnimationByIndex = SetUnitAnimationByIndex
61
- local queueUnitAnimation = QueueUnitAnimation
62
67
  local getUnitIntegerField = BlzGetUnitIntegerField
63
68
  local getUnitRealField = BlzGetUnitRealField
64
69
  local getHeroStr = GetHeroStr
@@ -77,9 +82,9 @@ local setUnitScale = SetUnitScale
77
82
  local setUnitPosition = SetUnitPosition
78
83
  local setUnitTimeScale = SetUnitTimeScale
79
84
  local getHandleId = GetHandleId
85
+ local getUnitCurrentOrder = GetUnitCurrentOrder
80
86
  local createUnit = CreateUnit
81
87
  local killUnit = KillUnit
82
- local setUnitExploded = SetUnitExploded
83
88
  local removeUnit = RemoveUnit
84
89
  local getUnitTypeId = GetUnitTypeId
85
90
  local isHeroUnitId = IsHeroUnitId
@@ -95,8 +100,6 @@ local getSpellTargetItem = GetSpellTargetItem
95
100
  local getSpellTargetDestructable = GetSpellTargetDestructable
96
101
  local isUnitInRangeXY = IsUnitInRangeXY
97
102
  local isUnitInRange = IsUnitInRange
98
- local setResourceAmount = SetResourceAmount
99
- local getResourceAmount = GetResourceAmount
100
103
  local getUnitWeaponRealField = BlzGetUnitWeaponRealField
101
104
  local setUnitWeaponRealField = BlzSetUnitWeaponRealField
102
105
  local getUnitWeaponStringField = BlzGetUnitWeaponStringField
@@ -127,8 +130,6 @@ local isUnitType = IsUnitType
127
130
  local isUnitAlly = IsUnitAlly
128
131
  local isUnitEnemy = IsUnitEnemy
129
132
  local getOwningPlayer = GetOwningPlayer
130
- local setUnitColor = SetUnitColor
131
- local showUnitTeamGlow = BlzShowUnitTeamGlow
132
133
  ____exports.UnitClassification = {}
133
134
  local UnitClassification = ____exports.UnitClassification
134
135
  do
@@ -138,6 +139,7 @@ do
138
139
  UnitClassification.GROUND = UNIT_TYPE_GROUND
139
140
  UnitClassification.SUMMONED = UNIT_TYPE_SUMMONED
140
141
  UnitClassification.MECHANICAL = UNIT_TYPE_MECHANICAL
142
+ UnitClassification.WORKER = UNIT_TYPE_PEON
141
143
  UnitClassification.ANCIENT = UNIT_TYPE_ANCIENT
142
144
  UnitClassification.SUICIDAL = UNIT_TYPE_SAPPER
143
145
  UnitClassification.TAUREN = UNIT_TYPE_TAUREN
@@ -345,6 +347,9 @@ local function dispatchAbility(event)
345
347
  }
346
348
  )
347
349
  end
350
+ local function damagingEventPreventRetaliation(self)
351
+ self[0] = true
352
+ end
348
353
  local function damageEventPreventDeath(self, callback, ...)
349
354
  if self[0] ~= nil then
350
355
  return
@@ -356,7 +361,14 @@ local function damageEventPreventDeath(self, callback, ...)
356
361
  rawset(self, 1 + i, (select(i, ...)))
357
362
  end
358
363
  end
359
- 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
+ }
360
372
  local jlimitopByOperator = {
361
373
  [0] = LESS_THAN_OR_EQUAL,
362
374
  [1] = LESS_THAN_OR_EQUAL,
@@ -434,6 +446,19 @@ __TS__SetDescriptor(
434
446
  },
435
447
  true
436
448
  )
449
+ __TS__SetDescriptor(
450
+ UnitWeapon.prototype,
451
+ "allowedTargetCombatClassifications",
452
+ {
453
+ get = function(self)
454
+ return BlzGetUnitWeaponIntegerField(self.unit.handle, UNIT_WEAPON_IF_ATTACK_TARGETS_ALLOWED, self.index)
455
+ end,
456
+ set = function(self, allowedTargetCombatClassifications)
457
+ BlzSetUnitWeaponIntegerField(self.unit.handle, UNIT_WEAPON_IF_ATTACK_TARGETS_ALLOWED, self.index, allowedTargetCombatClassifications)
458
+ end
459
+ },
460
+ true
461
+ )
437
462
  __TS__SetDescriptor(
438
463
  UnitWeapon.prototype,
439
464
  "damageBase",
@@ -638,7 +663,8 @@ local function delayHealthChecksCallback(unit)
638
663
  end
639
664
  end
640
665
  local nextSyncId = 1
641
- local unitBySyncId = setmetatable({}, {__mode = "k"})
666
+ local unitBySyncId = setmetatable({}, {__mode = "v"})
667
+ local damagingEventByTarget = setmetatable({}, {__mode = "k"})
642
668
  ____exports.Unit = __TS__Class()
643
669
  local Unit = ____exports.Unit
644
670
  Unit.name = "Unit"
@@ -679,6 +705,8 @@ function Unit.prototype.getEvent(self, event, collector)
679
705
  end
680
706
  function Unit.prototype.onDestroy(self)
681
707
  local handle = self.handle
708
+ self[107] = getUnitX(handle)
709
+ self[108] = getUnitY(handle)
682
710
  if not self._owner then
683
711
  self._owner = Player:of(getOwningPlayer(handle))
684
712
  end
@@ -789,13 +817,25 @@ function Unit.prototype.playAnimation(self, animation, rarity)
789
817
  if type(animation) == "number" then
790
818
  setUnitAnimationByIndex(self.handle, animation)
791
819
  elseif rarity then
792
- setUnitAnimationWithRarity(self.handle, animation, rarity)
820
+ SetUnitAnimationWithRarity(self.handle, animation, rarity)
793
821
  else
794
822
  setUnitAnimation(self.handle, animation)
795
823
  end
796
824
  end
825
+ function Unit.prototype.resetAnimation(self)
826
+ ResetUnitAnimation(self.handle)
827
+ end
797
828
  function Unit.prototype.queueAnimation(self, animation)
798
- queueUnitAnimation(self.handle, animation)
829
+ QueueUnitAnimation(self.handle, animation)
830
+ end
831
+ function Unit.prototype.chooseWeapon(self, target)
832
+ if target:isAllowedTarget(self, self.firstWeapon.allowedTargetCombatClassifications) then
833
+ return self.firstWeapon
834
+ end
835
+ if target:isAllowedTarget(target, self.secondWeapon.allowedTargetCombatClassifications) then
836
+ return self.secondWeapon
837
+ end
838
+ return nil
799
839
  end
800
840
  function Unit.prototype.delayHealthChecks(self)
801
841
  self[103] = (self[103] or 0) + 1
@@ -808,7 +848,7 @@ function Unit.prototype.isSelected(self, player)
808
848
  return IsUnitSelected(self.handle, player.handle)
809
849
  end
810
850
  function Unit.prototype.explode(self)
811
- setUnitExploded(self.handle, true)
851
+ SetUnitExploded(self.handle, true)
812
852
  killUnit(self.handle)
813
853
  end
814
854
  function Unit.prototype.kill(self)
@@ -1204,6 +1244,14 @@ __TS__SetDescriptor(
1204
1244
  end},
1205
1245
  true
1206
1246
  )
1247
+ __TS__SetDescriptor(
1248
+ Unit.prototype,
1249
+ "isStunned",
1250
+ {get = function(self)
1251
+ return getUnitCurrentOrder(self.handle) == orderId("stunned")
1252
+ end},
1253
+ true
1254
+ )
1207
1255
  __TS__SetDescriptor(
1208
1256
  Unit.prototype,
1209
1257
  "combatClassifications",
@@ -1277,6 +1325,19 @@ __TS__SetDescriptor(
1277
1325
  },
1278
1326
  true
1279
1327
  )
1328
+ __TS__SetDescriptor(
1329
+ Unit.prototype,
1330
+ "primaryAttribute",
1331
+ {
1332
+ get = function(self)
1333
+ return getUnitIntegerField(self.handle, UNIT_IF_PRIMARY_ATTRIBUTE)
1334
+ end,
1335
+ set = function(self, primaryAttribute)
1336
+ setUnitIntegerField(self.handle, UNIT_IF_PRIMARY_ATTRIBUTE, primaryAttribute)
1337
+ end
1338
+ },
1339
+ true
1340
+ )
1280
1341
  __TS__SetDescriptor(
1281
1342
  Unit.prototype,
1282
1343
  "strengthBase",
@@ -1401,7 +1462,7 @@ __TS__SetDescriptor(
1401
1462
  return not self[106]
1402
1463
  end,
1403
1464
  set = function(self, isTeamGlowVisible)
1404
- showUnitTeamGlow(self.handle, isTeamGlowVisible)
1465
+ BlzShowUnitTeamGlow(self.handle, isTeamGlowVisible)
1405
1466
  local ____temp_6
1406
1467
  if not isTeamGlowVisible then
1407
1468
  ____temp_6 = true
@@ -1417,9 +1478,9 @@ __TS__SetDescriptor(
1417
1478
  Unit.prototype,
1418
1479
  "color",
1419
1480
  {set = function(self, color)
1420
- setUnitColor(self.handle, color.handle)
1481
+ SetUnitColor(self.handle, color.handle)
1421
1482
  if self[106] then
1422
- showUnitTeamGlow(self.handle, false)
1483
+ BlzShowUnitTeamGlow(self.handle, false)
1423
1484
  end
1424
1485
  end},
1425
1486
  true
@@ -1588,7 +1649,7 @@ __TS__SetDescriptor(
1588
1649
  "x",
1589
1650
  {
1590
1651
  get = function(self)
1591
- return getUnitX(self.handle)
1652
+ return self[107] or getUnitX(self.handle)
1592
1653
  end,
1593
1654
  set = function(self, v)
1594
1655
  SetUnitX(self.handle, v)
@@ -1601,7 +1662,7 @@ __TS__SetDescriptor(
1601
1662
  "y",
1602
1663
  {
1603
1664
  get = function(self)
1604
- return getUnitY(self.handle)
1665
+ return self[108] or getUnitY(self.handle)
1605
1666
  end,
1606
1667
  set = function(self, v)
1607
1668
  SetUnitY(self.handle, v)
@@ -1687,10 +1748,10 @@ __TS__SetDescriptor(
1687
1748
  "gold",
1688
1749
  {
1689
1750
  get = function(self)
1690
- return getResourceAmount(self.handle)
1751
+ return GetResourceAmount(self.handle)
1691
1752
  end,
1692
1753
  set = function(self, gold)
1693
- setResourceAmount(self.handle, gold)
1754
+ SetResourceAmount(self.handle, gold)
1694
1755
  end
1695
1756
  },
1696
1757
  true
@@ -1818,6 +1879,19 @@ __TS__SetDescriptor(
1818
1879
  end},
1819
1880
  true
1820
1881
  )
1882
+ __TS__SetDescriptor(
1883
+ Unit.prototype,
1884
+ "movementType",
1885
+ {
1886
+ get = function(self)
1887
+ return getUnitIntegerField(self.handle, UNIT_IF_MOVE_TYPE)
1888
+ end,
1889
+ set = function(self, movementType)
1890
+ setUnitIntegerField(self.handle, UNIT_IF_MOVE_TYPE, movementType)
1891
+ end
1892
+ },
1893
+ true
1894
+ )
1821
1895
  __TS__SetDescriptor(
1822
1896
  Unit.prototype,
1823
1897
  "pathing",
@@ -1999,6 +2073,14 @@ __TS__SetDescriptor(
1999
2073
  end},
2000
2074
  true
2001
2075
  )
2076
+ __TS__SetDescriptor(
2077
+ Unit.prototype,
2078
+ "targetAcquiredEvent",
2079
+ {get = function(self)
2080
+ return self:getEvent(EVENT_UNIT_ACQUIRED_TARGET)
2081
+ end},
2082
+ true
2083
+ )
2002
2084
  __TS__SetDescriptor(
2003
2085
  Unit.prototype,
2004
2086
  "onSelect",
@@ -2360,13 +2442,19 @@ Unit.onDamaging = (function()
2360
2442
  if source and source.typeId == dummyUnitId then
2361
2443
  source = nil
2362
2444
  end
2363
- local target = BlzGetEventDamageTarget()
2445
+ local target = ____exports.Unit:of(BlzGetEventDamageTarget())
2446
+ local metadata = damageMetadataByTarget[target]
2447
+ damageMetadataByTarget[target] = nil
2364
2448
  local data = {
2365
2449
  amount = GetEventDamage(),
2366
- attackType = BlzGetEventAttackType(),
2450
+ attackType = nativeToAttackType(BlzGetEventAttackType()),
2367
2451
  damageType = BlzGetEventDamageType(),
2368
2452
  weaponType = BlzGetEventWeaponType(),
2369
- isAttack = BlzGetEventIsAttack()
2453
+ metadata = metadata,
2454
+ isAttack = BlzGetEventIsAttack(),
2455
+ originalAmount = GetEventDamage(),
2456
+ originalMetadata = metadata,
2457
+ preventRetaliation = damagingEventPreventRetaliation
2370
2458
  }
2371
2459
  if data.isAttack and source then
2372
2460
  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 +2468,36 @@ Unit.onDamaging = (function()
2380
2468
  invoke(
2381
2469
  event,
2382
2470
  source,
2383
- ____exports.Unit:of(target),
2471
+ target,
2384
2472
  setmetatable(
2385
2473
  {},
2386
2474
  {
2387
2475
  __index = data,
2388
2476
  __newindex = function(self, key, value)
2389
- damageSetters[key](value)
2477
+ local damageSetter = damageSetters[key]
2478
+ if damageSetter ~= nil then
2479
+ damageSetter(value)
2480
+ end
2390
2481
  data[key] = value
2391
2482
  end
2392
2483
  }
2393
2484
  )
2394
2485
  )
2486
+ if data[0] and source then
2487
+ local sourceOwner = source.owner.handle
2488
+ data[1] = sourceOwner
2489
+ local targetOwner = target.owner.handle
2490
+ data[2] = targetOwner
2491
+ if not GetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE) then
2492
+ SetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE, true)
2493
+ data[3] = true
2494
+ end
2495
+ if not GetPlayerAlliance(targetOwner, sourceOwner, ALLIANCE_PASSIVE) then
2496
+ SetPlayerAlliance(targetOwner, sourceOwner, ALLIANCE_PASSIVE, true)
2497
+ data[4] = true
2498
+ end
2499
+ end
2500
+ damagingEventByTarget[target] = data
2395
2501
  return
2396
2502
  end
2397
2503
  BlzSetEventDamage(0)
@@ -2399,7 +2505,7 @@ Unit.onDamaging = (function()
2399
2505
  BlzSetEventDamageType(DAMAGE_TYPE_UNKNOWN)
2400
2506
  BlzSetEventWeaponType(WEAPON_TYPE_WHOKNOWS)
2401
2507
  local sourceOwner = source.owner.handle
2402
- local targetOwner = GetOwningPlayer(target)
2508
+ local targetOwner = target.owner.handle
2403
2509
  if not GetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE) then
2404
2510
  SetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE, true)
2405
2511
  Timer:run(function()
@@ -2415,23 +2521,19 @@ Unit.onDamaging = (function()
2415
2521
  for ____, ____value in ipairs(source._attackHandlers) do
2416
2522
  local condition = ____value[1]
2417
2523
  local action = ____value[2]
2418
- if condition(
2419
- source,
2420
- ____exports.Unit:of(target),
2421
- data
2422
- ) then
2524
+ if condition(source, target, data) then
2423
2525
  action(
2424
2526
  source,
2425
- ____exports.Unit:of(target),
2527
+ target,
2426
2528
  setmetatable(
2427
2529
  {fire = function()
2428
2530
  UnitDamageTarget(
2429
2531
  source.handle,
2430
- target,
2532
+ target.handle,
2431
2533
  data.amount,
2432
2534
  true,
2433
2535
  true,
2434
- data.attackType,
2536
+ attackTypeToNative(data.attackType),
2435
2537
  data.damageType,
2436
2538
  data.weaponType
2437
2539
  )
@@ -2458,26 +2560,50 @@ Unit.onDamage = __TS__New(
2458
2560
  if source and source.typeId == dummyUnitId then
2459
2561
  source = nil
2460
2562
  end
2563
+ local target = ____exports.Unit:of(BlzGetEventDamageTarget())
2564
+ local damagingEvent = damagingEventByTarget[target]
2565
+ damagingEventByTarget[target] = nil
2461
2566
  local data = {
2462
2567
  amount = GetEventDamage(),
2463
- attackType = BlzGetEventAttackType(),
2568
+ attackType = nativeToAttackType(BlzGetEventAttackType()),
2464
2569
  damageType = BlzGetEventDamageType(),
2465
2570
  weaponType = BlzGetEventWeaponType(),
2571
+ metadata = damagingEvent and damagingEvent.metadata,
2466
2572
  isAttack = BlzGetEventIsAttack(),
2467
- originalAmount = GetEventDamage(),
2573
+ originalAmount = damagingEvent and damagingEvent.originalAmount or GetEventDamage(),
2574
+ originalMetadata = damagingEvent and damagingEvent.originalMetadata,
2468
2575
  preventDeath = damageEventPreventDeath
2469
2576
  }
2577
+ if damagingEvent then
2578
+ for key, value in pairs(damagingEvent) do
2579
+ if isAttribute(key) then
2580
+ data[key] = value
2581
+ end
2582
+ end
2583
+ local sourceOwner = damagingEvent[1]
2584
+ if sourceOwner then
2585
+ local targetOwner = damagingEvent[2]
2586
+ if damagingEvent[3] then
2587
+ SetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE, false)
2588
+ end
2589
+ if damagingEvent[4] then
2590
+ SetPlayerAlliance(targetOwner, sourceOwner, ALLIANCE_PASSIVE, false)
2591
+ end
2592
+ end
2593
+ end
2470
2594
  local evData = setmetatable(
2471
2595
  {},
2472
2596
  {
2473
2597
  __index = data,
2474
2598
  __newindex = function(self, key, value)
2475
- damageSetters[key](value)
2599
+ local damageSetter = damageSetters[key]
2600
+ if damageSetter ~= nil then
2601
+ damageSetter(value)
2602
+ end
2476
2603
  data[key] = value
2477
2604
  end
2478
2605
  }
2479
2606
  )
2480
- local target = ____exports.Unit:of(BlzGetEventDamageTarget())
2481
2607
  invoke(event, source, target, evData)
2482
2608
  if evData[0] ~= nil and target.health - evData.amount < 0.405 then
2483
2609
  local bonusHealth = math.ceil(evData.amount)
@@ -2556,6 +2682,21 @@ Unit.itemStackedEvent = __TS__New(
2556
2682
  EVENT_PLAYER_UNIT_STACK_ITEM,
2557
2683
  function() return ____exports.Unit:of(getTriggerUnit()), Item:of(getManipulatedItem()) end
2558
2684
  )
2685
+ __TS__ObjectDefineProperty(
2686
+ Unit,
2687
+ "itemChargesChangedEvent",
2688
+ {get = function(self)
2689
+ local event = __TS__New(Event)
2690
+ Item.chargesChangedEvent:addListener(function(item)
2691
+ local unit = item.owner
2692
+ if unit ~= nil then
2693
+ invoke(event, unit, item)
2694
+ end
2695
+ end)
2696
+ rawset(self, "itemChargesChangedEvent", event)
2697
+ return event
2698
+ end}
2699
+ )
2559
2700
  __TS__ObjectDefineProperty(
2560
2701
  Unit,
2561
2702
  "itemUseOrderEvent",
@@ -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;
@@ -1,2 +1,18 @@
1
1
  local ____exports = {}
2
+ local animationNames = {
3
+ attack = true,
4
+ birth = true,
5
+ death = true,
6
+ decay = true,
7
+ dissipate = true,
8
+ morph = true,
9
+ portrait = true,
10
+ sleep = true,
11
+ spell = true,
12
+ stand = true,
13
+ walk = true
14
+ }
15
+ ____exports.isAnimationName = function(value)
16
+ return animationNames[value] ~= nil
17
+ end
2
18
  return ____exports