warscript 0.0.1-dev.7411206 → 0.0.1-dev.7912f28

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 (147) hide show
  1. package/attributes.d.ts +0 -1
  2. package/binaryreader.d.ts +1 -0
  3. package/binaryreader.lua +3 -0
  4. package/core/types/effect.d.ts +13 -3
  5. package/core/types/effect.lua +116 -17
  6. package/core/types/frame.d.ts +8 -1
  7. package/core/types/frame.lua +93 -1
  8. package/core/types/group.d.ts +0 -1
  9. package/core/types/image.d.ts +0 -1
  10. package/core/types/missile.d.ts +2 -2
  11. package/core/types/missile.lua +8 -2
  12. package/core/types/unit.lua +8 -0
  13. package/core/util.d.ts +1 -1
  14. package/core/util.lua +12 -0
  15. package/decl/index.d.ts +1 -0
  16. package/engine/ability.d.ts +1 -1
  17. package/engine/behavior.d.ts +10 -10
  18. package/engine/behavior.lua +6 -6
  19. package/engine/behaviour/ability/always-enabled.d.ts +7 -0
  20. package/engine/behaviour/ability/always-enabled.lua +31 -0
  21. package/engine/behaviour/ability/apply-buff.d.ts +3 -5
  22. package/engine/behaviour/ability/apply-unit-behavior.d.ts +6 -1
  23. package/engine/behaviour/ability/damage.d.ts +33 -11
  24. package/engine/behaviour/ability/damage.lua +89 -31
  25. package/engine/behaviour/ability/emulate-impact.d.ts +6 -0
  26. package/engine/behaviour/ability/emulate-impact.lua +28 -0
  27. package/engine/behaviour/ability/heal.d.ts +33 -6
  28. package/engine/behaviour/ability/heal.lua +89 -10
  29. package/engine/behaviour/ability/instant-impact.d.ts +2 -2
  30. package/engine/behaviour/ability/instant-impact.lua +4 -15
  31. package/engine/behaviour/ability/on-command-impact.d.ts +8 -0
  32. package/engine/behaviour/ability/on-command-impact.lua +25 -0
  33. package/engine/behaviour/ability/remove-buffs.d.ts +16 -0
  34. package/engine/behaviour/ability/remove-buffs.lua +28 -0
  35. package/engine/behaviour/ability/restore-mana.d.ts +15 -0
  36. package/engine/behaviour/ability/restore-mana.lua +29 -0
  37. package/engine/behaviour/ability.d.ts +21 -3
  38. package/engine/behaviour/ability.lua +120 -12
  39. package/engine/behaviour/unit/stun-immunity.d.ts +0 -1
  40. package/engine/behaviour/unit.d.ts +8 -2
  41. package/engine/behaviour/unit.lua +27 -0
  42. package/engine/buff.d.ts +68 -21
  43. package/engine/buff.lua +276 -90
  44. package/engine/game-map.d.ts +7 -0
  45. package/engine/game-map.lua +32 -0
  46. package/engine/internal/ability.d.ts +16 -13
  47. package/engine/internal/ability.lua +80 -76
  48. package/engine/internal/item/ability.lua +106 -0
  49. package/engine/internal/item+owner.lua +2 -2
  50. package/engine/internal/misc/ability-disable-counter.d.ts +2 -0
  51. package/engine/internal/misc/ability-disable-counter.lua +13 -0
  52. package/engine/internal/unit/ability.d.ts +10 -1
  53. package/engine/internal/unit/ability.lua +36 -14
  54. package/engine/internal/unit/add-item-to-slot-init.d.ts +2 -0
  55. package/engine/internal/unit/add-item-to-slot-init.lua +23 -0
  56. package/engine/internal/unit/add-item-to-slot.d.ts +2 -0
  57. package/engine/internal/unit/add-item-to-slot.lua +50 -0
  58. package/engine/internal/unit/bonus.d.ts +9 -8
  59. package/engine/internal/unit/bonus.lua +6 -1
  60. package/engine/internal/unit/ignore-events-items.d.ts +2 -0
  61. package/engine/internal/unit/ignore-events-items.lua +5 -0
  62. package/engine/internal/unit/item.d.ts +24 -0
  63. package/engine/internal/unit/item.lua +78 -0
  64. package/engine/internal/unit/main-selected.d.ts +13 -0
  65. package/engine/internal/unit/main-selected.lua +51 -0
  66. package/engine/internal/unit+ability.lua +2 -2
  67. package/engine/internal/unit+transport.lua +4 -10
  68. package/engine/internal/unit-missile-launch.lua +25 -6
  69. package/engine/internal/unit.d.ts +59 -16
  70. package/engine/internal/unit.lua +372 -132
  71. package/engine/internal/utility.lua +12 -0
  72. package/engine/local-client.d.ts +7 -2
  73. package/engine/local-client.lua +82 -0
  74. package/engine/object-data/auxiliary/attachment-preset.d.ts +0 -1
  75. package/engine/object-data/auxiliary/combat-classification.d.ts +0 -2
  76. package/engine/object-data/auxiliary/sound-preset-name.d.ts +5 -1
  77. package/engine/object-data/entry/ability-type/blank-configurable.d.ts +0 -1
  78. package/engine/object-data/entry/ability-type/blank-passive.d.ts +0 -1
  79. package/engine/object-data/entry/ability-type/channel.d.ts +0 -1
  80. package/engine/object-data/entry/ability-type/mine.d.ts +10 -0
  81. package/engine/object-data/entry/ability-type/mine.lua +39 -0
  82. package/engine/object-data/entry/ability-type/spirit-touch.d.ts +2 -2
  83. package/engine/object-data/entry/ability-type/spirit-touch.lua +6 -6
  84. package/engine/object-data/entry/ability-type.d.ts +0 -1
  85. package/engine/object-data/entry/ability-type.lua +8 -12
  86. package/engine/object-data/entry/buff-type/applicable.d.ts +0 -1
  87. package/engine/object-data/entry/buff-type/blank.d.ts +0 -1
  88. package/engine/object-data/entry/buff-type.d.ts +0 -1
  89. package/engine/object-data/entry/destructible-type.d.ts +0 -1
  90. package/engine/object-data/entry/item-type/blank.d.ts +0 -1
  91. package/engine/object-data/entry/item-type.d.ts +14 -1
  92. package/engine/object-data/entry/item-type.lua +91 -0
  93. package/engine/object-data/entry/lightning-type.d.ts +0 -1
  94. package/engine/object-data/entry/unit-type.d.ts +21 -2
  95. package/engine/object-data/entry/unit-type.lua +223 -49
  96. package/engine/object-data/entry/upgrade/blank.d.ts +0 -1
  97. package/engine/object-data/entry/upgrade.d.ts +0 -1
  98. package/engine/object-data/entry.d.ts +2 -3
  99. package/engine/object-data/utility/object-data-entry-id-generator.lua +7 -0
  100. package/engine/object-field/ability.d.ts +26 -3
  101. package/engine/object-field/ability.lua +54 -1
  102. package/engine/object-field.d.ts +2 -3
  103. package/engine/object-field.lua +4 -0
  104. package/engine/random.d.ts +1 -0
  105. package/engine/random.lua +9 -0
  106. package/engine/standard/entries/unit-type.d.ts +39 -1
  107. package/engine/standard/entries/unit-type.lua +39 -1
  108. package/engine/standard/fields/ability.d.ts +3 -1
  109. package/engine/standard/fields/ability.lua +3 -1
  110. package/engine/unit.d.ts +3 -0
  111. package/engine/unit.lua +12 -2
  112. package/event.d.ts +2 -3
  113. package/event.lua +9 -5
  114. package/index.d.ts +1 -0
  115. package/index.lua +1 -0
  116. package/lualib_bundle.lua +146 -42
  117. package/math/vec2.d.ts +2 -9
  118. package/math.d.ts +0 -2
  119. package/net/socket.d.ts +7 -1
  120. package/net/socket.lua +45 -4
  121. package/network.d.ts +1 -0
  122. package/network.lua +3 -2
  123. package/objutil/ability.d.ts +0 -1
  124. package/objutil/buff.d.ts +0 -1
  125. package/objutil/buff.lua +1 -1
  126. package/objutil/object.d.ts +0 -1
  127. package/objutil/unit.d.ts +0 -1
  128. package/package.json +13 -14
  129. package/patch-lua.d.ts +0 -0
  130. package/patch-lua.lua +10 -0
  131. package/property.d.ts +55 -0
  132. package/property.lua +374 -0
  133. package/string.d.ts +30 -0
  134. package/string.lua +14 -0
  135. package/util/stream.d.ts +0 -1
  136. package/utility/arrays.d.ts +11 -5
  137. package/utility/arrays.lua +34 -3
  138. package/utility/bit-set.d.ts +0 -2
  139. package/utility/lazy.d.ts +2 -0
  140. package/utility/lazy.lua +14 -0
  141. package/utility/linked-set.d.ts +11 -3
  142. package/utility/linked-set.lua +5 -2
  143. package/utility/lua-maps.d.ts +1 -2
  144. package/utility/lua-sets.d.ts +1 -2
  145. package/utility/types.d.ts +1 -0
  146. package/core/mapbounds.d.ts +0 -8
  147. package/core/mapbounds.lua +0 -12
@@ -5,9 +5,12 @@ local __TS__ArrayMap = ____lualib.__TS__ArrayMap
5
5
  local __TS__New = ____lualib.__TS__New
6
6
  local __TS__Class = ____lualib.__TS__Class
7
7
  local __TS__ClassExtends = ____lualib.__TS__ClassExtends
8
+ local __TS__SetDescriptor = ____lualib.__TS__SetDescriptor
8
9
  local __TS__ArraySetLength = ____lualib.__TS__ArraySetLength
10
+ local __TS__SparseArrayNew = ____lualib.__TS__SparseArrayNew
11
+ local __TS__SparseArrayPush = ____lualib.__TS__SparseArrayPush
12
+ local __TS__SparseArraySpread = ____lualib.__TS__SparseArraySpread
9
13
  local __TS__InstanceOf = ____lualib.__TS__InstanceOf
10
- local __TS__SetDescriptor = ____lualib.__TS__SetDescriptor
11
14
  local __TS__ObjectDefineProperty = ____lualib.__TS__ObjectDefineProperty
12
15
  local Set = ____lualib.Set
13
16
  local __TS__Spread = ____lualib.__TS__Spread
@@ -48,6 +51,8 @@ local ____arrays = require("utility.arrays")
48
51
  local forEach = ____arrays.forEach
49
52
  local ____math = require("math")
50
53
  local min = ____math.min
54
+ local ____ignore_2Devents_2Ditems = require("engine.internal.unit.ignore-events-items")
55
+ local ignoreEventsItems = ____ignore_2Devents_2Ditems.ignoreEventsItems
51
56
  local match = string.match
52
57
  local ____tostring = _G.tostring
53
58
  local setUnitAnimation = SetUnitAnimation
@@ -92,6 +97,10 @@ local isUnitInRangeXY = IsUnitInRangeXY
92
97
  local isUnitInRange = IsUnitInRange
93
98
  local setResourceAmount = SetResourceAmount
94
99
  local getResourceAmount = GetResourceAmount
100
+ local getUnitWeaponRealField = BlzGetUnitWeaponRealField
101
+ local setUnitWeaponRealField = BlzSetUnitWeaponRealField
102
+ local getUnitWeaponStringField = BlzGetUnitWeaponStringField
103
+ local setUnitWeaponStringField = BlzSetUnitWeaponStringField
95
104
  local getUnitAbilityLevel = GetUnitAbilityLevel
96
105
  local unitDisableAbility = BlzUnitDisableAbility
97
106
  local unitInterruptAttack = BlzUnitInterruptAttack
@@ -275,16 +284,14 @@ function UnitTriggerEvent.prototype.____constructor(self, eventType, c)
275
284
  end
276
285
  local function dispatch(event, idGetter, argsGetter)
277
286
  local initialized = false
278
- local x = {}
279
287
  return setmetatable(
280
- x,
288
+ {},
281
289
  {
282
290
  __index = function(self, id)
283
291
  if type(id) ~= "number" then
284
292
  return event[id]
285
293
  end
286
294
  if not initialized then
287
- local invoke = Event.invoke
288
295
  event:addListener(function(...)
289
296
  local id = idGetter(...)
290
297
  local dispatched = rawget(self, id)
@@ -322,7 +329,6 @@ local function dispatchAbility(event)
322
329
  return event[id]
323
330
  end
324
331
  if not initialized then
325
- local invoke = Event.invoke
326
332
  event:addListener(function(unit, ability, ...)
327
333
  local dispatched = rawget(self, ability.typeId)
328
334
  if dispatched ~= nil then
@@ -387,51 +393,158 @@ local getters = {
387
393
  return BlzGetUnitArmor(unit)
388
394
  end
389
395
  }
390
- local weaponGetters = {
391
- index = function(self, handle, index)
392
- return index
393
- end,
394
- cooldown = function(self, handle, index)
395
- return BlzGetUnitWeaponRealField(handle, UNIT_WEAPON_RF_ATTACK_BASE_COOLDOWN, index)
396
- end,
397
- projectileArc = function(self, handle, index)
398
- return BlzGetUnitWeaponRealField(handle, UNIT_WEAPON_RF_ATTACK_PROJECTILE_ARC, index)
399
- end,
400
- projectileArt = function(self, handle, index)
401
- return BlzGetUnitWeaponStringField(handle, UNIT_WEAPON_SF_ATTACK_PROJECTILE_ART, index)
402
- end,
403
- projectileSpeed = function(self, handle, index)
404
- return BlzGetUnitWeaponRealField(handle, UNIT_WEAPON_RF_ATTACK_PROJECTILE_SPEED, index)
405
- end,
406
- attackPoint = function(self, handle, index)
407
- return BlzGetUnitWeaponRealField(handle, UNIT_WEAPON_RF_ATTACK_DAMAGE_POINT, index)
408
- end
409
- }
410
- local weaponSetters = {
411
- cooldown = function(self, handle, index, value)
412
- assert(BlzSetUnitWeaponRealField(handle, UNIT_WEAPON_RF_ATTACK_BASE_COOLDOWN, index, value))
413
- end,
414
- projectileArc = function(self, handle, index, value)
415
- assert(BlzSetUnitWeaponRealField(handle, UNIT_WEAPON_RF_ATTACK_PROJECTILE_ARC, index, value))
416
- end,
417
- projectileArt = function(self, handle, index, value)
418
- assert(BlzSetUnitWeaponStringField(handle, UNIT_WEAPON_SF_ATTACK_PROJECTILE_ART, index, value))
419
- end,
420
- projectileSpeed = function(self, handle, index, value)
421
- assert(BlzSetUnitWeaponRealField(handle, UNIT_WEAPON_RF_ATTACK_PROJECTILE_SPEED, index, value))
422
- end,
423
- attackPoint = function(self, handle, index, value)
424
- assert(BlzSetUnitWeaponRealField(handle, UNIT_WEAPON_RF_ATTACK_DAMAGE_POINT, index, value))
425
- end
426
- }
427
- local weaponMetatable = {
428
- __index = function(self, key)
429
- return weaponGetters[key](weaponGetters, self.h, self.i)
430
- end,
431
- __newindex = function(self, key, value)
432
- weaponSetters[key](weaponSetters, self.h, self.i, value)
433
- end
434
- }
396
+ ____exports.UnitWeapon = __TS__Class()
397
+ local UnitWeapon = ____exports.UnitWeapon
398
+ UnitWeapon.name = "UnitWeapon"
399
+ function UnitWeapon.prototype.____constructor(self, unit, index)
400
+ self.unit = unit
401
+ self.index = index
402
+ end
403
+ __TS__SetDescriptor(
404
+ UnitWeapon.prototype,
405
+ "cooldown",
406
+ {
407
+ get = function(self)
408
+ return getUnitWeaponRealField(self.unit.handle, UNIT_WEAPON_RF_ATTACK_BASE_COOLDOWN, self.index)
409
+ end,
410
+ set = function(self, cooldown)
411
+ setUnitWeaponRealField(self.unit.handle, UNIT_WEAPON_RF_ATTACK_BASE_COOLDOWN, self.index, cooldown)
412
+ end
413
+ },
414
+ true
415
+ )
416
+ __TS__SetDescriptor(
417
+ UnitWeapon.prototype,
418
+ "damage",
419
+ {
420
+ get = function(self)
421
+ local minimumDamage = self.damageBase + self.damageDiceCount
422
+ local maximumDamage = self.damageBase + self.damageDiceCount * self.damageDiceSideCount
423
+ return {minimumDamage, maximumDamage}
424
+ end,
425
+ set = function(self, ____bindingPattern0)
426
+ local maximumDamage
427
+ local minimumDamage
428
+ minimumDamage = ____bindingPattern0[1]
429
+ maximumDamage = ____bindingPattern0[2]
430
+ self.damageBase = minimumDamage - 1
431
+ self.damageDiceCount = 1
432
+ self.damageDiceSideCount = maximumDamage - minimumDamage + 1
433
+ end
434
+ },
435
+ true
436
+ )
437
+ __TS__SetDescriptor(
438
+ UnitWeapon.prototype,
439
+ "damageBase",
440
+ {
441
+ get = function(self)
442
+ return BlzGetUnitBaseDamage(self.unit.handle, self.index)
443
+ end,
444
+ set = function(self, damageBase)
445
+ BlzSetUnitBaseDamage(self.unit.handle, self.index, damageBase)
446
+ end
447
+ },
448
+ true
449
+ )
450
+ __TS__SetDescriptor(
451
+ UnitWeapon.prototype,
452
+ "damageDiceCount",
453
+ {
454
+ get = function(self)
455
+ return BlzGetUnitDiceNumber(self.unit.handle, self.index)
456
+ end,
457
+ set = function(self, damageDiceCount)
458
+ BlzSetUnitDiceNumber(self.unit.handle, self.index, damageDiceCount)
459
+ end
460
+ },
461
+ true
462
+ )
463
+ __TS__SetDescriptor(
464
+ UnitWeapon.prototype,
465
+ "damageDiceSideCount",
466
+ {
467
+ get = function(self)
468
+ return BlzGetUnitDiceSides(self.unit.handle, self.index)
469
+ end,
470
+ set = function(self, damageDiceSideCount)
471
+ BlzSetUnitDiceSides(self.unit.handle, self.index, damageDiceSideCount)
472
+ end
473
+ },
474
+ true
475
+ )
476
+ __TS__SetDescriptor(
477
+ UnitWeapon.prototype,
478
+ "range",
479
+ {
480
+ get = function(self)
481
+ return getUnitWeaponRealField(self.unit.handle, UNIT_WEAPON_RF_ATTACK_RANGE, self.index)
482
+ end,
483
+ set = function(self, range)
484
+ local handle = self.unit.handle
485
+ local index = self.index
486
+ setUnitWeaponRealField(
487
+ handle,
488
+ UNIT_WEAPON_RF_ATTACK_RANGE,
489
+ index + 1,
490
+ getUnitWeaponRealField(handle, UNIT_WEAPON_RF_ATTACK_RANGE, index + 1) + (range - getUnitWeaponRealField(handle, UNIT_WEAPON_RF_ATTACK_RANGE, index))
491
+ )
492
+ end
493
+ },
494
+ true
495
+ )
496
+ __TS__SetDescriptor(
497
+ UnitWeapon.prototype,
498
+ "impactDelay",
499
+ {
500
+ get = function(self)
501
+ return getUnitWeaponRealField(self.unit.handle, UNIT_WEAPON_RF_ATTACK_DAMAGE_POINT, self.index)
502
+ end,
503
+ set = function(self, impactDelay)
504
+ setUnitWeaponRealField(self.unit.handle, UNIT_WEAPON_RF_ATTACK_DAMAGE_POINT, self.index, impactDelay)
505
+ end
506
+ },
507
+ true
508
+ )
509
+ __TS__SetDescriptor(
510
+ UnitWeapon.prototype,
511
+ "missileArc",
512
+ {
513
+ get = function(self)
514
+ return getUnitWeaponRealField(self.unit.handle, UNIT_WEAPON_RF_ATTACK_PROJECTILE_ARC, self.index)
515
+ end,
516
+ set = function(self, missileArc)
517
+ setUnitWeaponRealField(self.unit.handle, UNIT_WEAPON_RF_ATTACK_PROJECTILE_ARC, self.index, missileArc)
518
+ end
519
+ },
520
+ true
521
+ )
522
+ __TS__SetDescriptor(
523
+ UnitWeapon.prototype,
524
+ "missileModelPath",
525
+ {
526
+ get = function(self)
527
+ return getUnitWeaponStringField(self.unit.handle, UNIT_WEAPON_SF_ATTACK_PROJECTILE_ART, self.index)
528
+ end,
529
+ set = function(self, missileModelPath)
530
+ setUnitWeaponStringField(self.unit.handle, UNIT_WEAPON_SF_ATTACK_PROJECTILE_ART, self.index, missileModelPath)
531
+ end
532
+ },
533
+ true
534
+ )
535
+ __TS__SetDescriptor(
536
+ UnitWeapon.prototype,
537
+ "missileSpeed",
538
+ {
539
+ get = function(self)
540
+ return getUnitWeaponRealField(self.unit.handle, UNIT_WEAPON_RF_ATTACK_PROJECTILE_SPEED, self.index)
541
+ end,
542
+ set = function(self, missileSpeed)
543
+ setUnitWeaponRealField(self.unit.handle, UNIT_WEAPON_RF_ATTACK_PROJECTILE_SPEED, self.index, missileSpeed)
544
+ end
545
+ },
546
+ true
547
+ )
435
548
  local unitInventorySize = UnitInventorySize
436
549
  local unitItemInSlot = UnitItemInSlot
437
550
  local getItemAbility = BlzGetItemAbility
@@ -442,8 +555,6 @@ local getAbilityName = GetAbilityName
442
555
  local unitAddAbility = UnitAddAbility
443
556
  local getUnitGoldCost = GetUnitGoldCost
444
557
  local getUnitLumberCost = GetUnitWoodCost
445
- local unitMakeAbilityPermanent = UnitMakeAbilityPermanent
446
- local unitAddItem = UnitAddItem
447
558
  local unitRemoveAbility = UnitRemoveAbility
448
559
  local function retrieveAbility(unit, ability, abilityId)
449
560
  if ability == nil then
@@ -453,17 +564,6 @@ local function retrieveAbility(unit, ability, abilityId)
453
564
  ____exports.Unit:of(unit)
454
565
  )
455
566
  end
456
- if not unitAddAbility(unit, abilityId) then
457
- if getUnitAbility(unit, abilityId) == ability then
458
- return UnitAbility:of(
459
- ability,
460
- abilityId,
461
- ____exports.Unit:of(unit)
462
- )
463
- end
464
- else
465
- unitRemoveAbility(unit, abilityId)
466
- end
467
567
  for i = 0, unitInventorySize(unit) - 1 do
468
568
  local item = unitItemInSlot(unit, i)
469
569
  if getItemAbility(item, abilityId) == ability then
@@ -520,12 +620,34 @@ for ____, player in ipairs(Player.all) do
520
620
  ShowUnit(dummy, false)
521
621
  dummies[player] = dummy
522
622
  end
623
+ local function delayHealthChecksCallback(unit)
624
+ local counter = (unit[103] or 0) - 1
625
+ if counter ~= 0 then
626
+ unit[103] = counter
627
+ return
628
+ end
629
+ unit[103] = nil
630
+ local healthBonus = unit[104]
631
+ if healthBonus ~= nil then
632
+ unit[104] = nil
633
+ local handle = unit.handle
634
+ BlzSetUnitMaxHP(
635
+ handle,
636
+ BlzGetUnitMaxHP(handle) - healthBonus
637
+ )
638
+ end
639
+ end
640
+ local nextSyncId = 1
641
+ local unitBySyncId = setmetatable({}, {__mode = "k"})
523
642
  ____exports.Unit = __TS__Class()
524
643
  local Unit = ____exports.Unit
525
644
  Unit.name = "Unit"
526
645
  __TS__ClassExtends(Unit, Handle)
527
646
  function Unit.prototype.____constructor(self, handle)
528
647
  Handle.prototype.____constructor(self, handle)
648
+ local ____nextSyncId_0 = nextSyncId
649
+ nextSyncId = ____nextSyncId_0 + 1
650
+ self.syncId = ____nextSyncId_0
529
651
  self._owner = Player:of(getOwningPlayer(handle))
530
652
  assert(unitAddAbility(handle, leaveDetectAbilityId) and UnitMakeAbilityPermanent(handle, true, leaveDetectAbilityId))
531
653
  assert(unitAddAbility(handle, morphDetectAbilityId))
@@ -538,6 +660,7 @@ function Unit.prototype.____constructor(self, handle)
538
660
  fourCC("Amrf")
539
661
  ))
540
662
  end
663
+ unitBySyncId[self.syncId] = self
541
664
  local ____ = self.abilities
542
665
  end
543
666
  function Unit.prototype.getEvent(self, event, collector)
@@ -623,8 +746,8 @@ function Unit.prototype.addModifier(self, property, modifier)
623
746
  end}
624
747
  end
625
748
  function Unit.prototype.hasCombatClassification(self, combatClassification)
626
- local ____combatClassification_0 = combatClassification
627
- return getUnitIntegerField(self.handle, UNIT_IF_TARGETED_AS) & ____combatClassification_0 == ____combatClassification_0
749
+ local ____combatClassification_1 = combatClassification
750
+ return getUnitIntegerField(self.handle, UNIT_IF_TARGETED_AS) & ____combatClassification_1 == ____combatClassification_1
628
751
  end
629
752
  function Unit.prototype.addClassification(self, classification)
630
753
  return unitAddType(self.handle, classification)
@@ -642,13 +765,13 @@ function Unit.prototype.isInvisibleTo(self, player)
642
765
  return isUnitInvisible(self.handle, player.handle)
643
766
  end
644
767
  function Unit.prototype.isInRangeOf(self, x, y, range)
645
- local ____temp_1
768
+ local ____temp_2
646
769
  if type(x) == "number" then
647
- ____temp_1 = isUnitInRangeXY(self.handle, x, y, range)
770
+ ____temp_2 = isUnitInRangeXY(self.handle, x, y, range)
648
771
  else
649
- ____temp_1 = isUnitInRange(self.handle, x.handle, y)
772
+ ____temp_2 = isUnitInRange(self.handle, x.handle, y)
650
773
  end
651
- return ____temp_1
774
+ return ____temp_2
652
775
  end
653
776
  function Unit.prototype.isAllyOf(self, unit)
654
777
  return isUnitAlly(
@@ -674,6 +797,10 @@ end
674
797
  function Unit.prototype.queueAnimation(self, animation)
675
798
  queueUnitAnimation(self.handle, animation)
676
799
  end
800
+ function Unit.prototype.delayHealthChecks(self)
801
+ self[103] = (self[103] or 0) + 1
802
+ Timer:run(delayHealthChecksCallback, self)
803
+ end
677
804
  function Unit.prototype.setPosition(self, x, y)
678
805
  setUnitPosition(self.handle, x, y)
679
806
  end
@@ -687,8 +814,15 @@ end
687
814
  function Unit.prototype.kill(self)
688
815
  killUnit(self.handle)
689
816
  end
690
- function Unit.prototype.revive(self, pos, doEffect)
691
- ReviveHero(self.handle, pos.x, pos.y, doEffect)
817
+ function Unit.prototype.revive(self, x, y, doEffect)
818
+ local ____ReviveHero_5 = ReviveHero
819
+ local ____array_4 = __TS__SparseArrayNew(self.handle, x, y)
820
+ local ____doEffect_3 = doEffect
821
+ if ____doEffect_3 == nil then
822
+ ____doEffect_3 = false
823
+ end
824
+ __TS__SparseArrayPush(____array_4, ____doEffect_3)
825
+ ____ReviveHero_5(__TS__SparseArraySpread(____array_4))
692
826
  end
693
827
  function Unit.prototype.healTarget(self, target, amount)
694
828
  if __TS__InstanceOf(target, ____exports.Unit) and target:hasAbility(fourCC("BIhm")) then
@@ -728,7 +862,7 @@ function Unit.prototype.dropItemSlot(self, item, slot)
728
862
  return UnitDropItemSlot(self.handle, item.handle, slot)
729
863
  end
730
864
  function Unit.prototype.itemInSlot(self, slot)
731
- return Item:of(UnitItemInSlot(self.handle, slot))
865
+ return Item:of(unitItemInSlot(self.handle, slot))
732
866
  end
733
867
  function Unit.prototype.addAbility(self, abilityId)
734
868
  if unitAddAbility(self.handle, abilityId) then
@@ -784,6 +918,9 @@ end
784
918
  function Unit.prototype.hideAbility(self, abilityId, flag)
785
919
  BlzUnitHideAbility(self.handle, abilityId, flag)
786
920
  end
921
+ function Unit.prototype.getAbilityRemainingCooldown(self, abilityId)
922
+ return BlzGetUnitAbilityCooldownRemaining(self.handle, abilityId)
923
+ end
787
924
  function Unit.prototype.startAbilityCooldown(self, abilityId, cooldown)
788
925
  BlzStartUnitAbilityCooldown(self.handle, abilityId, cooldown)
789
926
  end
@@ -794,8 +931,15 @@ function Unit.prototype.interruptAttack(self)
794
931
  unitInterruptAttack(self.handle)
795
932
  end
796
933
  function Unit.prototype.interruptCast(self, abilityId)
797
- unitDisableAbility(self.handle, abilityId, true, false)
798
- unitDisableAbility(self.handle, abilityId, false, false)
934
+ local handle = self.handle
935
+ unitDisableAbility(handle, abilityId, true, false)
936
+ Timer:run(
937
+ unitDisableAbility,
938
+ handle,
939
+ abilityId,
940
+ false,
941
+ false
942
+ )
799
943
  end
800
944
  function Unit.prototype.getDistanceTo(self, target)
801
945
  local handle = self.handle
@@ -855,18 +999,18 @@ function Unit.prototype.unpauseEx(self)
855
999
  self:decrementStunCounter()
856
1000
  end
857
1001
  function Unit.prototype.incrementStunCounter(self)
858
- local stunCounter = self[101] or 0
859
- if not self[100] or stunCounter >= 0 then
1002
+ local stunCounter = self[102] or 0
1003
+ if not self[101] or stunCounter >= 0 then
860
1004
  BlzPauseUnitEx(self.handle, true)
861
1005
  end
862
- self[101] = stunCounter + 1
1006
+ self[102] = stunCounter + 1
863
1007
  end
864
1008
  function Unit.prototype.decrementStunCounter(self)
865
- local stunCounter = self[101] or 0
866
- if not self[100] or stunCounter >= 1 then
1009
+ local stunCounter = self[102] or 0
1010
+ if not self[101] or stunCounter >= 1 then
867
1011
  BlzPauseUnitEx(self.handle, false)
868
1012
  end
869
- self[101] = stunCounter - 1
1013
+ self[102] = stunCounter - 1
870
1014
  end
871
1015
  function Unit.create(self, owner, id, x, y, facing, skinId)
872
1016
  local handle = skinId and BlzCreateUnitWithSkin(
@@ -968,8 +1112,11 @@ function Unit.getInSector(self, pos, range, offsetAngle, centralAngle)
968
1112
  )
969
1113
  return targetCollection
970
1114
  end
971
- function Unit.getSelectionOf(self, player)
972
- targetCollection = {}
1115
+ function Unit.getSelectionOf(self, player, target)
1116
+ if target == nil then
1117
+ target = {}
1118
+ end
1119
+ targetCollection = target
973
1120
  targetCollectionNextIndex = 1
974
1121
  GroupEnumUnitsSelected(dummyGroup, player.handle, collectIntoTarget)
975
1122
  return targetCollection
@@ -991,6 +1138,9 @@ end
991
1138
  function Unit.prototype.__tostring(self)
992
1139
  return (((self.constructor.name .. "$") .. util.id2s(self.typeId)) .. "@") .. tostring(getHandleId(self.handle))
993
1140
  end
1141
+ function Unit.getBySyncId(self, syncId)
1142
+ return unitBySyncId[syncId]
1143
+ end
994
1144
  __TS__SetDescriptor(
995
1145
  Unit.prototype,
996
1146
  "_deltas",
@@ -1054,6 +1204,14 @@ __TS__SetDescriptor(
1054
1204
  end},
1055
1205
  true
1056
1206
  )
1207
+ __TS__SetDescriptor(
1208
+ Unit.prototype,
1209
+ "isStunned",
1210
+ {get = function(self)
1211
+ return isUnitType(self.handle, UNIT_TYPE_STUNNED)
1212
+ end},
1213
+ true
1214
+ )
1057
1215
  __TS__SetDescriptor(
1058
1216
  Unit.prototype,
1059
1217
  "combatClassifications",
@@ -1071,12 +1229,27 @@ __TS__SetDescriptor(
1071
1229
  Unit.prototype,
1072
1230
  "weapons",
1073
1231
  {get = function(self)
1074
- local weapons = {
1075
- setmetatable({h = self.handle, i = 0}, weaponMetatable),
1076
- setmetatable({h = self.handle, i = 1}, weaponMetatable)
1077
- }
1078
- rawset(self, "weapons", weapons)
1079
- return weapons
1232
+ return {self.firstWeapon, self.secondWeapon}
1233
+ end},
1234
+ true
1235
+ )
1236
+ __TS__SetDescriptor(
1237
+ Unit.prototype,
1238
+ "firstWeapon",
1239
+ {get = function(self)
1240
+ local weapon = __TS__New(____exports.UnitWeapon, self, 0)
1241
+ rawset(self, "firstWeapon", weapon)
1242
+ return weapon
1243
+ end},
1244
+ true
1245
+ )
1246
+ __TS__SetDescriptor(
1247
+ Unit.prototype,
1248
+ "secondWeapon",
1249
+ {get = function(self)
1250
+ local weapon = __TS__New(____exports.UnitWeapon, self, 1)
1251
+ rawset(self, "secondWeapon", weapon)
1252
+ return weapon
1080
1253
  end},
1081
1254
  true
1082
1255
  )
@@ -1233,17 +1406,17 @@ __TS__SetDescriptor(
1233
1406
  "isTeamGlowVisible",
1234
1407
  {
1235
1408
  get = function(self)
1236
- return not self[103]
1409
+ return not self[106]
1237
1410
  end,
1238
1411
  set = function(self, isTeamGlowVisible)
1239
1412
  showUnitTeamGlow(self.handle, isTeamGlowVisible)
1240
- local ____temp_2
1413
+ local ____temp_6
1241
1414
  if not isTeamGlowVisible then
1242
- ____temp_2 = true
1415
+ ____temp_6 = true
1243
1416
  else
1244
- ____temp_2 = nil
1417
+ ____temp_6 = nil
1245
1418
  end
1246
- self[103] = ____temp_2
1419
+ self[106] = ____temp_6
1247
1420
  end
1248
1421
  },
1249
1422
  true
@@ -1253,7 +1426,7 @@ __TS__SetDescriptor(
1253
1426
  "color",
1254
1427
  {set = function(self, color)
1255
1428
  setUnitColor(self.handle, color.handle)
1256
- if self[103] then
1429
+ if self[106] then
1257
1430
  showUnitTeamGlow(self.handle, false)
1258
1431
  end
1259
1432
  end},
@@ -1277,10 +1450,14 @@ __TS__SetDescriptor(
1277
1450
  "maxHealth",
1278
1451
  {
1279
1452
  get = function(self)
1280
- return BlzGetUnitMaxHP(self.handle) - (self[102] or 0)
1453
+ return BlzGetUnitMaxHP(self.handle) - (self[104] or 0) - (self[105] or 0)
1281
1454
  end,
1282
1455
  set = function(self, maxHealth)
1283
- BlzSetUnitMaxHP(self.handle, maxHealth + (self[102] or 0))
1456
+ if maxHealth < 1 and self[103] ~= nil then
1457
+ self[104] = (self[104] or 0) + (1 - maxHealth)
1458
+ maxHealth = 1
1459
+ end
1460
+ BlzSetUnitMaxHP(self.handle, maxHealth + (self[105] or 0))
1284
1461
  end
1285
1462
  },
1286
1463
  true
@@ -1322,10 +1499,10 @@ __TS__SetDescriptor(
1322
1499
  "health",
1323
1500
  {
1324
1501
  get = function(self)
1325
- return GetWidgetLife(self.handle) - (self[102] or 0)
1502
+ return GetWidgetLife(self.handle) - (self[105] or 0)
1326
1503
  end,
1327
1504
  set = function(self, health)
1328
- SetWidgetLife(self.handle, health + (self[102] or 0))
1505
+ SetWidgetLife(self.handle, health + (self[105] or 0))
1329
1506
  end
1330
1507
  },
1331
1508
  true
@@ -1536,17 +1713,17 @@ __TS__SetDescriptor(
1536
1713
  set = function(self, isPaused)
1537
1714
  local handle = self.handle
1538
1715
  if isPaused and not IsUnitPaused(handle) then
1539
- self[100] = true
1540
- for _ = self[101] or 0, -1 do
1716
+ self[101] = true
1717
+ for _ = self[102] or 0, -1 do
1541
1718
  BlzPauseUnitEx(handle, true)
1542
1719
  end
1543
1720
  PauseUnit(handle, true)
1544
1721
  elseif not isPaused and IsUnitPaused(handle) then
1545
1722
  PauseUnit(handle, false)
1546
- for _ = self[101] or 0, -1 do
1723
+ for _ = self[102] or 0, -1 do
1547
1724
  BlzPauseUnitEx(handle, false)
1548
1725
  end
1549
- self[100] = nil
1726
+ self[101] = nil
1550
1727
  end
1551
1728
  end
1552
1729
  },
@@ -1903,7 +2080,6 @@ Unit.onDecay = __TS__New(
1903
2080
  Unit.onResurrect = __TS__New(
1904
2081
  InitializingEvent,
1905
2082
  function(event)
1906
- local invoke = Event.invoke
1907
2083
  local dead = setmetatable({}, {__mode = "k"})
1908
2084
  ____exports.Unit.deathEvent:addListener(function(unit)
1909
2085
  dead[unit] = true
@@ -1919,10 +2095,15 @@ Unit.onResurrect = __TS__New(
1919
2095
  Unit.morphEvent = __TS__New(
1920
2096
  InitializingEvent,
1921
2097
  function(event)
2098
+ local function ifNotLeft(unit)
2099
+ local handle = unit.handle
2100
+ if getUnitAbilityLevel(handle, leaveDetectAbilityId) ~= 0 and unitAddAbility(handle, morphDetectAbilityId) then
2101
+ invoke(event, unit)
2102
+ end
2103
+ end
1922
2104
  ____exports.Unit.onImmediateOrder[orderId("undefend")]:addListener(function(unit)
1923
2105
  if getUnitAbilityLevel(unit.handle, morphDetectAbilityId) == 0 then
1924
- assert(unitAddAbility(unit.handle, morphDetectAbilityId))
1925
- Timer:run(Event.invoke, event, unit)
2106
+ Timer:run(ifNotLeft, unit)
1926
2107
  end
1927
2108
  end)
1928
2109
  end
@@ -1960,27 +2141,26 @@ Unit.onSpellEffect = dispatchId(__TS__New(
1960
2141
  Unit.onTargetCast = dispatchId(__TS__New(
1961
2142
  InitializingEvent,
1962
2143
  function(event)
1963
- local invoke = Event.invoke
1964
2144
  local function listener(unit, id)
1965
- local ____GetSpellTargetUnit_result_5
2145
+ local ____GetSpellTargetUnit_result_9
1966
2146
  if GetSpellTargetUnit() then
1967
- ____GetSpellTargetUnit_result_5 = ____exports.Unit:of(GetSpellTargetUnit())
2147
+ ____GetSpellTargetUnit_result_9 = ____exports.Unit:of(GetSpellTargetUnit())
1968
2148
  else
1969
- local ____GetSpellTargetItem_result_4
2149
+ local ____GetSpellTargetItem_result_8
1970
2150
  if GetSpellTargetItem() then
1971
- ____GetSpellTargetItem_result_4 = Item:of(GetSpellTargetItem())
2151
+ ____GetSpellTargetItem_result_8 = Item:of(GetSpellTargetItem())
1972
2152
  else
1973
- local ____GetSpellTargetDestructable_result_3
2153
+ local ____GetSpellTargetDestructable_result_7
1974
2154
  if GetSpellTargetDestructable() then
1975
- ____GetSpellTargetDestructable_result_3 = Destructable:of(GetSpellTargetDestructable())
2155
+ ____GetSpellTargetDestructable_result_7 = Destructable:of(GetSpellTargetDestructable())
1976
2156
  else
1977
- ____GetSpellTargetDestructable_result_3 = nil
2157
+ ____GetSpellTargetDestructable_result_7 = nil
1978
2158
  end
1979
- ____GetSpellTargetItem_result_4 = ____GetSpellTargetDestructable_result_3
2159
+ ____GetSpellTargetItem_result_8 = ____GetSpellTargetDestructable_result_7
1980
2160
  end
1981
- ____GetSpellTargetUnit_result_5 = ____GetSpellTargetItem_result_4
2161
+ ____GetSpellTargetUnit_result_9 = ____GetSpellTargetItem_result_8
1982
2162
  end
1983
- local target = ____GetSpellTargetUnit_result_5
2163
+ local target = ____GetSpellTargetUnit_result_9
1984
2164
  if target then
1985
2165
  invoke(event, unit, id, target)
1986
2166
  end
@@ -2152,10 +2332,12 @@ Unit.onImmediateOrder = dispatchId(__TS__New(
2152
2332
  ____exports.UnitTriggerEvent,
2153
2333
  EVENT_PLAYER_UNIT_ISSUED_ORDER,
2154
2334
  function()
2155
- local unit = ____exports.Unit:of(getOrderedUnit())
2156
- local issuedOrderId = getIssuedOrderId()
2157
- if unit ~= nil and unit.state == 1 then
2158
- return unit, issuedOrderId
2335
+ local handle = getOrderedUnit()
2336
+ if handle ~= nil and getUnitTypeId(handle) ~= dummyUnitId then
2337
+ local unit = ____exports.Unit:of(handle)
2338
+ if unit.state == 1 then
2339
+ return unit, getIssuedOrderId()
2340
+ end
2159
2341
  end
2160
2342
  return IgnoreEvent
2161
2343
  end
@@ -2177,7 +2359,6 @@ Unit.autoAttackStartEvent = __TS__New(
2177
2359
  )
2178
2360
  Unit.onDamaging = (function()
2179
2361
  local event = __TS__New(Event)
2180
- local invoke = Event.invoke
2181
2362
  local trigger = CreateTrigger()
2182
2363
  TriggerRegisterAnyUnitEventBJ(trigger, EVENT_PLAYER_UNIT_DAMAGING)
2183
2364
  TriggerAddCondition(
@@ -2276,7 +2457,6 @@ end)()
2276
2457
  Unit.onDamage = __TS__New(
2277
2458
  InitializingEvent,
2278
2459
  function(event)
2279
- local invoke = Event.invoke
2280
2460
  local trigger = CreateTrigger()
2281
2461
  TriggerRegisterAnyUnitEventBJ(trigger, EVENT_PLAYER_UNIT_DAMAGED)
2282
2462
  TriggerAddCondition(
@@ -2292,6 +2472,7 @@ Unit.onDamage = __TS__New(
2292
2472
  damageType = BlzGetEventDamageType(),
2293
2473
  weaponType = BlzGetEventWeaponType(),
2294
2474
  isAttack = BlzGetEventIsAttack(),
2475
+ originalAmount = GetEventDamage(),
2295
2476
  preventDeath = damageEventPreventDeath
2296
2477
  }
2297
2478
  local evData = setmetatable(
@@ -2308,7 +2489,7 @@ Unit.onDamage = __TS__New(
2308
2489
  invoke(event, source, target, evData)
2309
2490
  if evData[0] ~= nil and target.health - evData.amount < 0.405 then
2310
2491
  local bonusHealth = math.ceil(evData.amount)
2311
- target[102] = (target[102] or 0) + bonusHealth
2492
+ target[105] = (target[105] or 0) + bonusHealth
2312
2493
  BlzSetUnitMaxHP(
2313
2494
  target.handle,
2314
2495
  BlzGetUnitMaxHP(target.handle) + bonusHealth
@@ -2322,7 +2503,7 @@ Unit.onDamage = __TS__New(
2322
2503
  evData[0],
2323
2504
  table.unpack(evData, 1 + 1, 1 + (evData[1] or 0))
2324
2505
  )
2325
- target[102] = (target[102] or 0) - bonusHealth
2506
+ target[105] = (target[105] or 0) - bonusHealth
2326
2507
  SetWidgetLife(
2327
2508
  target.handle,
2328
2509
  GetWidgetLife(target.handle) - bonusHealth
@@ -2342,32 +2523,91 @@ Unit.onDamage = __TS__New(
2342
2523
  DestroyTrigger(trigger)
2343
2524
  end
2344
2525
  )
2345
- Unit.onItemDrop = __TS__New(
2526
+ Unit.itemDroppedEvent = __TS__New(
2346
2527
  ____exports.UnitTriggerEvent,
2347
2528
  EVENT_PLAYER_UNIT_DROP_ITEM,
2348
2529
  function()
2349
2530
  local unit = getTriggerUnit()
2350
- if getUnitTypeId(unit) ~= dummyUnitId then
2351
- return ____exports.Unit:of(unit), Item:of(getManipulatedItem())
2531
+ local item = getManipulatedItem()
2532
+ if getUnitTypeId(unit) ~= dummyUnitId and not (ignoreEventsItems[item] ~= nil) then
2533
+ return ____exports.Unit:of(unit), Item:of(item)
2352
2534
  end
2353
2535
  return IgnoreEvent
2354
2536
  end
2355
2537
  )
2356
- Unit.onItemPickup = __TS__New(
2538
+ Unit.itemPickedUpEvent = __TS__New(
2357
2539
  ____exports.UnitTriggerEvent,
2358
2540
  EVENT_PLAYER_UNIT_PICKUP_ITEM,
2359
2541
  function()
2360
2542
  local unit = getTriggerUnit()
2361
- if getUnitTypeId(unit) ~= dummyUnitId then
2362
- return ____exports.Unit:of(unit), Item:of(getManipulatedItem())
2543
+ local item = getManipulatedItem()
2544
+ if getUnitTypeId(unit) ~= dummyUnitId and not (ignoreEventsItems[item] ~= nil) then
2545
+ return ____exports.Unit:of(unit), Item:of(item)
2363
2546
  end
2364
2547
  return IgnoreEvent
2365
2548
  end
2366
2549
  )
2367
- Unit.onItemUse = __TS__New(
2550
+ Unit.itemUsedEvent = __TS__New(
2368
2551
  ____exports.UnitTriggerEvent,
2369
2552
  EVENT_PLAYER_UNIT_USE_ITEM,
2370
- function() return ____exports.Unit:of(GetTriggerUnit()), Item:of(GetManipulatedItem()) end
2553
+ function()
2554
+ local unit = getTriggerUnit()
2555
+ local item = getManipulatedItem()
2556
+ if getUnitTypeId(unit) ~= dummyUnitId and not (ignoreEventsItems[item] ~= nil) then
2557
+ return ____exports.Unit:of(unit), Item:of(item)
2558
+ end
2559
+ return IgnoreEvent
2560
+ end
2561
+ )
2562
+ Unit.itemStackedEvent = __TS__New(
2563
+ ____exports.UnitTriggerEvent,
2564
+ EVENT_PLAYER_UNIT_STACK_ITEM,
2565
+ function() return ____exports.Unit:of(getTriggerUnit()), Item:of(getManipulatedItem()) end
2566
+ )
2567
+ __TS__ObjectDefineProperty(
2568
+ Unit,
2569
+ "itemUseOrderEvent",
2570
+ {get = function(self)
2571
+ local event = __TS__New(Event)
2572
+ for order = orderId("useslot0"), orderId("useslot5") do
2573
+ local slot = order - orderId("useslot0")
2574
+ local function listener(unit)
2575
+ local item = unit.items[slot + 1]
2576
+ if item ~= nil then
2577
+ invoke(event, unit, item)
2578
+ end
2579
+ end
2580
+ self.onImmediateOrder[order]:addListener(listener)
2581
+ self.onTargetOrder[order]:addListener(listener)
2582
+ self.onPointOrder[order]:addListener(listener)
2583
+ end
2584
+ rawset(self, "itemUseOrderEvent", event)
2585
+ return event
2586
+ end}
2587
+ )
2588
+ __TS__ObjectDefineProperty(
2589
+ Unit,
2590
+ "itemMoveOrderEvent",
2591
+ {get = function(self)
2592
+ local event = __TS__New(Event)
2593
+ for order = orderId("moveslot0"), orderId("moveslot5") do
2594
+ local slotTo = order - orderId("moveslot0")
2595
+ self.onTargetOrder[order]:addListener(function(unit, item)
2596
+ local slotFrom = unit.items:findSlot(item)
2597
+ if slotFrom ~= nil then
2598
+ invoke(
2599
+ event,
2600
+ unit,
2601
+ item,
2602
+ slotFrom,
2603
+ slotTo
2604
+ )
2605
+ end
2606
+ end)
2607
+ end
2608
+ rawset(self, "itemMoveOrderEvent", event)
2609
+ return event
2610
+ end}
2371
2611
  )
2372
2612
  __TS__ObjectDefineProperty(
2373
2613
  Unit,