warscript 0.0.1-dev.2bde093 → 0.0.1-dev.2c83888

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 (162) hide show
  1. package/attributes.d.ts +6 -0
  2. package/attributes.lua +17 -1
  3. package/core/types/frame.lua +71 -22
  4. package/core/types/item.d.ts +1 -0
  5. package/core/types/item.lua +1 -0
  6. package/core/types/player.d.ts +16 -0
  7. package/core/types/player.lua +60 -15
  8. package/core/types/playerCamera.d.ts +2 -0
  9. package/core/types/playerCamera.lua +123 -5
  10. package/core/types/sound.lua +1 -1
  11. package/core/types/tileCell.d.ts +11 -1
  12. package/core/types/tileCell.lua +97 -0
  13. package/core/types/timer.d.ts +3 -1
  14. package/core/types/timer.lua +27 -2
  15. package/decl/native.d.ts +6 -4
  16. package/destroyable.d.ts +1 -0
  17. package/destroyable.lua +9 -0
  18. package/engine/behavior.d.ts +14 -1
  19. package/engine/behavior.lua +230 -70
  20. package/engine/behaviour/ability/apply-buff.lua +5 -5
  21. package/engine/behaviour/ability/damage.d.ts +5 -1
  22. package/engine/behaviour/ability/damage.lua +28 -37
  23. package/engine/behaviour/ability/emulate-impact.d.ts +1 -1
  24. package/engine/behaviour/ability/emulate-impact.lua +11 -3
  25. package/engine/behaviour/ability/remove-buffs.d.ts +9 -0
  26. package/engine/behaviour/ability/remove-buffs.lua +21 -0
  27. package/engine/behaviour/ability/restore-mana.d.ts +1 -1
  28. package/engine/behaviour/ability/restore-mana.lua +6 -6
  29. package/engine/behaviour/ability.d.ts +11 -6
  30. package/engine/behaviour/ability.lua +38 -17
  31. package/engine/behaviour/unit/stun-immunity.d.ts +12 -6
  32. package/engine/behaviour/unit/stun-immunity.lua +57 -31
  33. package/engine/behaviour/unit.d.ts +39 -3
  34. package/engine/behaviour/unit.lua +269 -6
  35. package/engine/buff.d.ts +67 -22
  36. package/engine/buff.lua +371 -182
  37. package/engine/internal/ability.d.ts +7 -1
  38. package/engine/internal/ability.lua +49 -9
  39. package/engine/internal/item/ability.lua +63 -11
  40. package/engine/internal/item/is-actively-used.d.ts +7 -0
  41. package/engine/internal/item/is-actively-used.lua +20 -0
  42. package/engine/internal/item+owner.lua +12 -6
  43. package/engine/internal/item.d.ts +14 -16
  44. package/engine/internal/item.lua +122 -60
  45. package/engine/internal/mechanics/cast-ability.lua +6 -3
  46. package/engine/internal/misc/frame-coordinates.lua +21 -0
  47. package/engine/internal/misc/get-terrain-z.d.ts +2 -0
  48. package/engine/internal/misc/get-terrain-z.lua +11 -0
  49. package/engine/internal/misc/player-local-handle.d.ts +2 -0
  50. package/engine/internal/misc/player-local-handle.lua +5 -0
  51. package/engine/internal/object-data/armor-bonus.d.ts +2 -0
  52. package/engine/internal/object-data/attribute-bonus.lua +2 -2
  53. package/engine/internal/object-data/health-bonus.d.ts +2 -0
  54. package/engine/internal/object-data/health-bonus.lua +16 -0
  55. package/engine/internal/object-data/mana-bonus.d.ts +2 -0
  56. package/engine/internal/object-data/mana-bonus.lua +16 -0
  57. package/engine/internal/object-data/mana-regeneration-rate-increase-factor.d.ts +2 -0
  58. package/engine/internal/object-data/mana-regeneration-rate-increase-factor.lua +16 -0
  59. package/engine/internal/unit/ability.d.ts +35 -0
  60. package/engine/internal/unit/ability.lua +98 -9
  61. package/engine/internal/unit/allowed-targets.d.ts +1 -1
  62. package/engine/internal/unit/allowed-targets.lua +9 -1
  63. package/engine/internal/unit/attributes.d.ts +17 -0
  64. package/engine/internal/unit/attributes.lua +46 -0
  65. package/engine/internal/unit/bonus.d.ts +6 -0
  66. package/engine/internal/unit/bonus.lua +33 -3
  67. package/engine/internal/unit/fly-height.d.ts +7 -0
  68. package/engine/internal/unit/fly-height.lua +20 -0
  69. package/engine/internal/unit/interrupts.d.ts +12 -0
  70. package/engine/internal/unit/interrupts.lua +28 -0
  71. package/engine/internal/unit/main-selected.lua +12 -27
  72. package/engine/internal/unit/order.d.ts +20 -0
  73. package/engine/internal/unit/order.lua +136 -0
  74. package/engine/internal/unit/range-event.d.ts +12 -0
  75. package/engine/internal/unit/range-event.lua +90 -0
  76. package/engine/internal/unit/scale.d.ts +7 -0
  77. package/engine/internal/unit/scale.lua +20 -0
  78. package/engine/internal/unit+ability.lua +10 -1
  79. package/engine/internal/unit+bonus.lua +3 -3
  80. package/engine/internal/unit-missile-launch.lua +52 -14
  81. package/engine/internal/unit.d.ts +30 -26
  82. package/engine/internal/unit.lua +319 -244
  83. package/engine/local-client.d.ts +7 -0
  84. package/engine/local-client.lua +86 -1
  85. package/engine/object-data/auxiliary/armor-type.d.ts +11 -0
  86. package/engine/object-data/auxiliary/armor-type.lua +46 -0
  87. package/engine/object-data/auxiliary/health-regeneration-type.d.ts +8 -0
  88. package/engine/object-data/auxiliary/health-regeneration-type.lua +2 -0
  89. package/engine/object-data/auxiliary/unit-attribute.lua +1 -1
  90. package/engine/object-data/entry/ability-type/{armor-increase.d.ts → armor-bonus.d.ts} +3 -3
  91. package/engine/object-data/entry/ability-type/{armor-increase.lua → armor-bonus.lua} +9 -9
  92. package/engine/object-data/entry/ability-type/health-bonus.d.ts +8 -0
  93. package/engine/object-data/entry/ability-type/health-bonus.lua +26 -0
  94. package/engine/object-data/entry/ability-type/mana-bonus.d.ts +8 -0
  95. package/engine/object-data/entry/ability-type/mana-bonus.lua +26 -0
  96. package/engine/object-data/entry/ability-type/mana-regeneration.d.ts +8 -0
  97. package/engine/object-data/entry/ability-type/mana-regeneration.lua +26 -0
  98. package/engine/object-data/entry/ability-type/permanent-invisibility.d.ts +8 -0
  99. package/engine/object-data/entry/ability-type/permanent-invisibility.lua +26 -0
  100. package/engine/object-data/entry/ability-type/reincarnation.d.ts +8 -0
  101. package/engine/object-data/entry/ability-type/reincarnation.lua +26 -0
  102. package/engine/object-data/entry/ability-type.d.ts +2 -0
  103. package/engine/object-data/entry/ability-type.lua +89 -8
  104. package/engine/object-data/entry/buff-type/applicable.lua +113 -109
  105. package/engine/object-data/entry/destructible-type.d.ts +27 -1
  106. package/engine/object-data/entry/destructible-type.lua +155 -0
  107. package/engine/object-data/entry/unit-type.d.ts +15 -2
  108. package/engine/object-data/entry/unit-type.lua +135 -33
  109. package/engine/object-field/ability.d.ts +3 -3
  110. package/engine/object-field/ability.lua +9 -8
  111. package/engine/object-field/item.d.ts +22 -0
  112. package/engine/object-field/item.lua +115 -0
  113. package/engine/object-field/unit.d.ts +31 -5
  114. package/engine/object-field/unit.lua +95 -0
  115. package/engine/object-field.d.ts +18 -7
  116. package/engine/object-field.lua +294 -135
  117. package/engine/random.d.ts +10 -0
  118. package/engine/random.lua +21 -0
  119. package/engine/standard/fields/ability.d.ts +2 -2
  120. package/engine/standard/fields/ability.lua +2 -2
  121. package/engine/standard/fields/item.d.ts +3 -0
  122. package/engine/standard/fields/item.lua +5 -0
  123. package/engine/standard/fields/unit.d.ts +12 -0
  124. package/engine/standard/fields/unit.lua +20 -0
  125. package/engine/synchronization.d.ts +11 -0
  126. package/engine/synchronization.lua +77 -0
  127. package/engine/text-tag.d.ts +36 -2
  128. package/engine/text-tag.lua +250 -10
  129. package/engine/unit.d.ts +6 -0
  130. package/engine/unit.lua +6 -0
  131. package/lualib_bundle.lua +1 -1
  132. package/math.d.ts +2 -0
  133. package/math.lua +14 -0
  134. package/net/socket.lua +1 -1
  135. package/objutil/buff.lua +10 -8
  136. package/objutil/object.lua +1 -1
  137. package/operation.lua +1 -4
  138. package/package.json +5 -5
  139. package/patch-lua.lua +15 -0
  140. package/patch-lualib.lua +1 -1
  141. package/utility/arrays.d.ts +1 -0
  142. package/utility/arrays.lua +8 -0
  143. package/utility/callback-array.d.ts +17 -0
  144. package/utility/callback-array.lua +61 -0
  145. package/utility/functions.d.ts +7 -0
  146. package/utility/functions.lua +12 -0
  147. package/utility/linked-map.d.ts +34 -0
  148. package/utility/linked-map.lua +101 -0
  149. package/utility/linked-set.d.ts +3 -1
  150. package/utility/linked-set.lua +40 -1
  151. package/utility/lua-maps.d.ts +12 -2
  152. package/utility/lua-maps.lua +37 -2
  153. package/utility/lua-sets.d.ts +1 -0
  154. package/utility/lua-sets.lua +4 -0
  155. package/utility/records.lua +20 -1
  156. package/utility/types.d.ts +3 -0
  157. package/core/types/order.d.ts +0 -25
  158. package/core/types/order.lua +0 -55
  159. /package/engine/internal/{object-data/armor-increase.d.ts → misc/frame-coordinates.d.ts} +0 -0
  160. /package/engine/internal/object-data/{armor-increase.lua → armor-bonus.lua} +0 -0
  161. /package/engine/object-data/entry/ability-type/{attribute-increase.d.ts → attribute-bonus.d.ts} +0 -0
  162. /package/engine/object-data/entry/ability-type/{attribute-increase.lua → attribute-bonus.lua} +0 -0
@@ -58,28 +58,29 @@ local attackTypeToNative = ____attack_2Dtype.attackTypeToNative
58
58
  local nativeToAttackType = ____attack_2Dtype.nativeToAttackType
59
59
  local ____damage_2Dmetadata_2Dby_2Dtarget = require("engine.internal.misc.damage-metadata-by-target")
60
60
  local damageMetadataByTarget = ____damage_2Dmetadata_2Dby_2Dtarget.damageMetadataByTarget
61
+ local ____attributes = require("attributes")
62
+ local isAttribute = ____attributes.isAttribute
63
+ local ____ability = require("engine.internal.item.ability")
64
+ local doUnitAbilityAction = ____ability.doUnitAbilityAction
65
+ local ____synchronization = require("engine.synchronization")
66
+ local synchronizer = ____synchronization.synchronizer
67
+ local ____linked_2Dmap = require("utility.linked-map")
68
+ local LinkedMap = ____linked_2Dmap.LinkedMap
61
69
  local match = string.match
62
70
  local ____tostring = _G.tostring
63
71
  local setUnitAnimation = SetUnitAnimation
64
- local setUnitAnimationWithRarity = SetUnitAnimationWithRarity
65
72
  local setUnitAnimationByIndex = SetUnitAnimationByIndex
66
- local resetUnitAnimation = ResetUnitAnimation
67
- local queueUnitAnimation = QueueUnitAnimation
68
73
  local getUnitIntegerField = BlzGetUnitIntegerField
69
74
  local getUnitRealField = BlzGetUnitRealField
70
75
  local getHeroStr = GetHeroStr
71
76
  local getHeroAgi = GetHeroAgi
72
77
  local getHeroInt = GetHeroInt
73
- local setHeroStr = SetHeroStr
74
- local setHeroAgi = SetHeroAgi
75
- local setHeroInt = SetHeroInt
76
78
  local getUnitBooleanField = BlzGetUnitBooleanField
77
79
  local getUnitStringField = BlzGetUnitStringField
78
80
  local setUnitIntegerField = BlzSetUnitIntegerField
79
81
  local setUnitRealField = BlzSetUnitRealField
80
82
  local setUnitBooleanField = BlzSetUnitBooleanField
81
83
  local setUnitStringField = BlzSetUnitStringField
82
- local setUnitScale = SetUnitScale
83
84
  local setUnitPosition = SetUnitPosition
84
85
  local setUnitTimeScale = SetUnitTimeScale
85
86
  local getHandleId = GetHandleId
@@ -107,7 +108,6 @@ local getUnitWeaponStringField = BlzGetUnitWeaponStringField
107
108
  local setUnitWeaponStringField = BlzSetUnitWeaponStringField
108
109
  local getUnitAbilityLevel = GetUnitAbilityLevel
109
110
  local unitDisableAbility = BlzUnitDisableAbility
110
- local unitInterruptAttack = BlzUnitInterruptAttack
111
111
  local isUnitInvisible = IsUnitInvisible
112
112
  local isUnitVisible = IsUnitVisible
113
113
  local getUnitX = GetUnitX
@@ -124,10 +124,6 @@ local getOrderedUnit = GetOrderedUnit
124
124
  local getIssuedOrderId = GetIssuedOrderId
125
125
  local isUnitInvulnerable = BlzIsUnitInvulnerable
126
126
  local unitAlive = UnitAlive
127
- local unitAddType = UnitAddType
128
- local unitRemoveType = UnitRemoveType
129
- local isUnitIllusion = IsUnitIllusion
130
- local isUnitType = IsUnitType
131
127
  local isUnitAlly = IsUnitAlly
132
128
  local isUnitEnemy = IsUnitEnemy
133
129
  local getOwningPlayer = GetOwningPlayer
@@ -140,6 +136,7 @@ do
140
136
  UnitClassification.GROUND = UNIT_TYPE_GROUND
141
137
  UnitClassification.SUMMONED = UNIT_TYPE_SUMMONED
142
138
  UnitClassification.MECHANICAL = UNIT_TYPE_MECHANICAL
139
+ UnitClassification.WORKER = UNIT_TYPE_PEON
143
140
  UnitClassification.ANCIENT = UNIT_TYPE_ANCIENT
144
141
  UnitClassification.SUICIDAL = UNIT_TYPE_SAPPER
145
142
  UnitClassification.TAUREN = UNIT_TYPE_TAUREN
@@ -347,6 +344,9 @@ local function dispatchAbility(event)
347
344
  }
348
345
  )
349
346
  end
347
+ local function damagingEventPreventRetaliation(self)
348
+ self[0] = true
349
+ end
350
350
  local function damageEventPreventDeath(self, callback, ...)
351
351
  if self[0] ~= nil then
352
352
  return
@@ -383,15 +383,27 @@ local modifiers = {
383
383
  end,
384
384
  armor = function(unit, value)
385
385
  if UnitAddAbility(unit, armorBonusAbilityId) then
386
- assert(UnitMakeAbilityPermanent(unit, true, armorBonusAbilityId))
386
+ assert(
387
+ UnitMakeAbilityPermanent(unit, true, armorBonusAbilityId),
388
+ "armor bonus ability must be made permanent",
389
+ unit
390
+ )
387
391
  end
388
- local ability = assert(BlzGetUnitAbility(unit, armorBonusAbilityId))
389
- assert(BlzSetAbilityRealLevelField(
390
- ability,
391
- armorBonusField,
392
- 0,
393
- BlzGetAbilityRealLevelField(ability, armorBonusField, 0) + value
394
- ))
392
+ local ability = assert(
393
+ BlzGetUnitAbility(unit, armorBonusAbilityId),
394
+ "armor bonus ability must be existing",
395
+ unit
396
+ )
397
+ assert(
398
+ BlzSetAbilityRealLevelField(
399
+ ability,
400
+ armorBonusField,
401
+ 0,
402
+ BlzGetAbilityRealLevelField(ability, armorBonusField, 0) + value
403
+ ),
404
+ "armor bonus ability field must be set",
405
+ unit
406
+ )
395
407
  end
396
408
  }
397
409
  local getters = {
@@ -409,6 +421,19 @@ function UnitWeapon.prototype.____constructor(self, unit, index)
409
421
  self.unit = unit
410
422
  self.index = index
411
423
  end
424
+ __TS__SetDescriptor(
425
+ UnitWeapon.prototype,
426
+ "isEnabled",
427
+ {
428
+ get = function(self)
429
+ return BlzGetUnitWeaponBooleanField(self.unit.handle, UNIT_WEAPON_BF_ATTACKS_ENABLED, self.index)
430
+ end,
431
+ set = function(self, isEnabled)
432
+ BlzSetUnitWeaponBooleanField(self.unit.handle, UNIT_WEAPON_BF_ATTACKS_ENABLED, self.index, isEnabled)
433
+ end
434
+ },
435
+ true
436
+ )
412
437
  __TS__SetDescriptor(
413
438
  UnitWeapon.prototype,
414
439
  "cooldown",
@@ -443,6 +468,19 @@ __TS__SetDescriptor(
443
468
  },
444
469
  true
445
470
  )
471
+ __TS__SetDescriptor(
472
+ UnitWeapon.prototype,
473
+ "allowedTargetCombatClassifications",
474
+ {
475
+ get = function(self)
476
+ return BlzGetUnitWeaponIntegerField(self.unit.handle, UNIT_WEAPON_IF_ATTACK_TARGETS_ALLOWED, self.index)
477
+ end,
478
+ set = function(self, allowedTargetCombatClassifications)
479
+ BlzSetUnitWeaponIntegerField(self.unit.handle, UNIT_WEAPON_IF_ATTACK_TARGETS_ALLOWED, self.index, allowedTargetCombatClassifications)
480
+ end
481
+ },
482
+ true
483
+ )
446
484
  __TS__SetDescriptor(
447
485
  UnitWeapon.prototype,
448
486
  "damageBase",
@@ -619,26 +657,30 @@ local fieldSetters = {
619
657
  }
620
658
  local dummies = {}
621
659
  for ____, player in ipairs(Player.all) do
622
- local dummy = assert(createUnit(
623
- player.handle,
624
- dummyUnitId,
625
- 0,
626
- 0,
627
- 270
628
- ))
660
+ local dummy = assert(
661
+ createUnit(
662
+ player.handle,
663
+ dummyUnitId,
664
+ 0,
665
+ 0,
666
+ 270
667
+ ),
668
+ "dummy must be created",
669
+ player
670
+ )
629
671
  ShowUnit(dummy, false)
630
672
  dummies[player] = dummy
631
673
  end
632
674
  local function delayHealthChecksCallback(unit)
633
- local counter = (unit[103] or 0) - 1
675
+ local counter = (unit[104] or 0) - 1
634
676
  if counter ~= 0 then
635
- unit[103] = counter
677
+ unit[104] = counter
636
678
  return
637
679
  end
638
- unit[103] = nil
639
- local healthBonus = unit[104]
680
+ unit[104] = nil
681
+ local healthBonus = unit[105]
640
682
  if healthBonus ~= nil then
641
- unit[104] = nil
683
+ unit[105] = nil
642
684
  local handle = unit.handle
643
685
  BlzSetUnitMaxHP(
644
686
  handle,
@@ -649,51 +691,76 @@ end
649
691
  local nextSyncId = 1
650
692
  local unitBySyncId = setmetatable({}, {__mode = "v"})
651
693
  local damagingEventByTarget = setmetatable({}, {__mode = "k"})
694
+ local function addAbility(unit, abilityTypeId)
695
+ local ____unitAddAbility_result_0
696
+ if unitAddAbility(unit, abilityTypeId) then
697
+ ____unitAddAbility_result_0 = getUnitAbility(unit, abilityTypeId)
698
+ else
699
+ ____unitAddAbility_result_0 = nil
700
+ end
701
+ return ____unitAddAbility_result_0
702
+ end
652
703
  ____exports.Unit = __TS__Class()
653
704
  local Unit = ____exports.Unit
654
705
  Unit.name = "Unit"
655
706
  __TS__ClassExtends(Unit, Handle)
656
707
  function Unit.prototype.____constructor(self, handle)
657
708
  Handle.prototype.____constructor(self, handle)
658
- local ____nextSyncId_0 = nextSyncId
659
- nextSyncId = ____nextSyncId_0 + 1
660
- self.syncId = ____nextSyncId_0
709
+ local ____nextSyncId_1 = nextSyncId
710
+ nextSyncId = ____nextSyncId_1 + 1
711
+ self.syncId = ____nextSyncId_1
661
712
  self._owner = Player:of(getOwningPlayer(handle))
662
- assert(unitAddAbility(handle, leaveDetectAbilityId) and UnitMakeAbilityPermanent(handle, true, leaveDetectAbilityId))
663
- assert(unitAddAbility(handle, morphDetectAbilityId))
713
+ assert(
714
+ unitAddAbility(handle, leaveDetectAbilityId) and UnitMakeAbilityPermanent(handle, true, leaveDetectAbilityId),
715
+ "leave detection ability must be added",
716
+ self
717
+ )
718
+ assert(
719
+ unitAddAbility(handle, morphDetectAbilityId),
720
+ "morph detection ability must be added",
721
+ self
722
+ )
664
723
  if unitAddAbility(
665
724
  handle,
666
725
  fourCC("Amrf")
667
726
  ) then
668
- assert(unitRemoveAbility(
669
- handle,
670
- fourCC("Amrf")
671
- ))
727
+ assert(
728
+ unitRemoveAbility(
729
+ handle,
730
+ fourCC("Amrf")
731
+ ),
732
+ "fly ability must be removed after addition",
733
+ self
734
+ )
672
735
  end
673
736
  unitBySyncId[self.syncId] = self
674
737
  local ____ = self.abilities
675
738
  end
676
- function Unit.prototype.getEvent(self, event, collector)
677
- self.events = self.events or ({})
678
- local eventId = GetHandleId(event)
679
- if not self.events[eventId] then
680
- self.events[eventId] = __TS__New(
739
+ function Unit.prototype.getEvent(self, jevent, collector)
740
+ self.events = self.events or __TS__New(LinkedMap)
741
+ local eventId = GetHandleId(jevent)
742
+ local event = self.events:get(eventId)
743
+ if event == nil then
744
+ event = __TS__New(
681
745
  TriggerEvent,
682
746
  function(trigger)
683
- TriggerRegisterUnitEvent(trigger, self.handle, event)
747
+ TriggerRegisterUnitEvent(trigger, self.handle, jevent)
684
748
  end,
685
749
  collector or (function() return {} end)
686
750
  )
751
+ self.events:put(eventId, event)
687
752
  end
688
- return self.events[eventId]
753
+ return event
754
+ end
755
+ function Unit.prototype.saveData(self)
756
+ local handle = self.handle
757
+ self[108] = self[108] or getUnitX(handle)
758
+ self[109] = self[109] or getUnitY(handle)
759
+ self._owner = self._owner or Player:of(getOwningPlayer(handle))
689
760
  end
690
761
  function Unit.prototype.onDestroy(self)
691
762
  local handle = self.handle
692
- self[107] = getUnitX(handle)
693
- self[108] = getUnitY(handle)
694
- if not self._owner then
695
- self._owner = Player:of(getOwningPlayer(handle))
696
- end
763
+ self:saveData()
697
764
  local abilities = self.abilities
698
765
  for ____, ability in ipairs(abilities) do
699
766
  ability:destroy()
@@ -729,7 +796,11 @@ function Unit.prototype.addAttackHandler(self, condition, action)
729
796
  self._attackHandlers = handlers
730
797
  if #handlers == 1 then
731
798
  local handle = self.handle
732
- assert(unitAddAbility(handle, attackHandlerAbilityId) and UnitMakeAbilityPermanent(handle, true, attackHandlerAbilityId))
799
+ assert(
800
+ unitAddAbility(handle, attackHandlerAbilityId) and UnitMakeAbilityPermanent(handle, true, attackHandlerAbilityId),
801
+ "attack handler ability must be added",
802
+ self
803
+ )
733
804
  end
734
805
  return handler
735
806
  end
@@ -758,17 +829,17 @@ function Unit.prototype.addModifier(self, property, modifier)
758
829
  end}
759
830
  end
760
831
  function Unit.prototype.hasCombatClassification(self, combatClassification)
761
- local ____combatClassification_1 = combatClassification
762
- return getUnitIntegerField(self.handle, UNIT_IF_TARGETED_AS) & ____combatClassification_1 == ____combatClassification_1
832
+ local ____combatClassification_2 = combatClassification
833
+ return getUnitIntegerField(self.handle, UNIT_IF_TARGETED_AS) & ____combatClassification_2 == ____combatClassification_2
763
834
  end
764
835
  function Unit.prototype.addClassification(self, classification)
765
- return unitAddType(self.handle, classification)
836
+ return UnitAddType(self.handle, classification)
766
837
  end
767
838
  function Unit.prototype.removeClassification(self, classification)
768
- return unitRemoveType(self.handle, classification)
839
+ return UnitRemoveType(self.handle, classification)
769
840
  end
770
841
  function Unit.prototype.hasClassification(self, classification)
771
- return isUnitType(self.handle, classification)
842
+ return IsUnitType(self.handle, classification)
772
843
  end
773
844
  function Unit.prototype.isVisibleTo(self, player)
774
845
  return isUnitVisible(self.handle, player.handle)
@@ -777,13 +848,13 @@ function Unit.prototype.isInvisibleTo(self, player)
777
848
  return isUnitInvisible(self.handle, player.handle)
778
849
  end
779
850
  function Unit.prototype.isInRangeOf(self, x, y, range)
780
- local ____temp_2
851
+ local ____temp_3
781
852
  if type(x) == "number" then
782
- ____temp_2 = isUnitInRangeXY(self.handle, x, y, range)
853
+ ____temp_3 = isUnitInRangeXY(self.handle, x, y, range)
783
854
  else
784
- ____temp_2 = isUnitInRange(self.handle, x.handle, y)
855
+ ____temp_3 = isUnitInRange(self.handle, x.handle, y)
785
856
  end
786
- return ____temp_2
857
+ return ____temp_3
787
858
  end
788
859
  function Unit.prototype.isAllyOf(self, unit)
789
860
  return isUnitAlly(
@@ -801,19 +872,30 @@ function Unit.prototype.playAnimation(self, animation, rarity)
801
872
  if type(animation) == "number" then
802
873
  setUnitAnimationByIndex(self.handle, animation)
803
874
  elseif rarity then
804
- setUnitAnimationWithRarity(self.handle, animation, rarity)
875
+ SetUnitAnimationWithRarity(self.handle, animation, rarity)
805
876
  else
806
877
  setUnitAnimation(self.handle, animation)
807
878
  end
808
879
  end
809
880
  function Unit.prototype.resetAnimation(self)
810
- resetUnitAnimation(self.handle)
881
+ ResetUnitAnimation(self.handle)
811
882
  end
812
883
  function Unit.prototype.queueAnimation(self, animation)
813
- queueUnitAnimation(self.handle, animation)
884
+ QueueUnitAnimation(self.handle, animation)
885
+ end
886
+ function Unit.prototype.chooseWeapon(self, target)
887
+ local firstWeapon = self.firstWeapon
888
+ if firstWeapon.isEnabled and target:isAllowedTarget(self, firstWeapon.allowedTargetCombatClassifications) then
889
+ return firstWeapon
890
+ end
891
+ local secondWeapon = self.secondWeapon
892
+ if secondWeapon.isEnabled and target:isAllowedTarget(target, secondWeapon.allowedTargetCombatClassifications) then
893
+ return secondWeapon
894
+ end
895
+ return nil
814
896
  end
815
897
  function Unit.prototype.delayHealthChecks(self)
816
- self[103] = (self[103] or 0) + 1
898
+ self[104] = (self[104] or 0) + 1
817
899
  Timer:run(delayHealthChecksCallback, self)
818
900
  end
819
901
  function Unit.prototype.setPosition(self, x, y)
@@ -830,14 +912,14 @@ function Unit.prototype.kill(self)
830
912
  killUnit(self.handle)
831
913
  end
832
914
  function Unit.prototype.revive(self, x, y, doEffect)
833
- local ____ReviveHero_5 = ReviveHero
834
- local ____array_4 = __TS__SparseArrayNew(self.handle, x, y)
835
- local ____doEffect_3 = doEffect
836
- if ____doEffect_3 == nil then
837
- ____doEffect_3 = false
915
+ local ____ReviveHero_6 = ReviveHero
916
+ local ____array_5 = __TS__SparseArrayNew(self.handle, x, y)
917
+ local ____doEffect_4 = doEffect
918
+ if ____doEffect_4 == nil then
919
+ ____doEffect_4 = false
838
920
  end
839
- __TS__SparseArrayPush(____array_4, ____doEffect_3)
840
- ____ReviveHero_5(__TS__SparseArraySpread(____array_4))
921
+ __TS__SparseArrayPush(____array_5, ____doEffect_4)
922
+ ____ReviveHero_6(__TS__SparseArraySpread(____array_5))
841
923
  end
842
924
  function Unit.prototype.healTarget(self, target, amount)
843
925
  if __TS__InstanceOf(target, ____exports.Unit) and target:hasAbility(fourCC("BIhm")) then
@@ -880,17 +962,16 @@ function Unit.prototype.itemInSlot(self, slot)
880
962
  return Item:of(unitItemInSlot(self.handle, slot))
881
963
  end
882
964
  function Unit.prototype.addAbility(self, abilityId)
883
- if unitAddAbility(self.handle, abilityId) then
884
- local ability = UnitAbility:of(
885
- checkNotNull(getUnitAbility(self.handle, abilityId)),
886
- abilityId,
887
- self
888
- )
965
+ local ability = UnitAbility:of(
966
+ doUnitAbilityAction(self.handle, abilityId, addAbility, abilityId),
967
+ abilityId,
968
+ self
969
+ )
970
+ if ability ~= nil then
889
971
  local abilities = self.abilities
890
972
  abilities[#abilities + 1] = ability
891
- return ability
892
973
  end
893
- return nil
974
+ return ability
894
975
  end
895
976
  function Unit.prototype.makeAbilityPermanent(self, abilityId, permanent)
896
977
  return UnitMakeAbilityPermanent(self.handle, permanent, abilityId)
@@ -904,31 +985,21 @@ end
904
985
  function Unit.prototype.hasAbility(self, abilityId)
905
986
  return getUnitAbilityLevel(self.handle, abilityId) > 0
906
987
  end
907
- function Unit.prototype.getAbilityById(self, abilityId)
908
- local handle = self.handle
909
- if unitAddAbility(handle, abilityId) then
910
- assert(unitRemoveAbility(handle, abilityId))
911
- return nil
912
- end
913
- return UnitAbility:of(
914
- getUnitAbility(self.handle, abilityId),
915
- abilityId,
916
- self
917
- )
988
+ function Unit.prototype.getAbility(self, abilityId)
989
+ local ability = doUnitAbilityAction(self.handle, abilityId, getUnitAbility, abilityId)
990
+ return UnitAbility:of(ability, abilityId, self)
918
991
  end
919
- function Unit.prototype.removeAbility(self, abilityId)
920
- if unitRemoveAbility(self.handle, abilityId) then
921
- local abilities = self.abilities
922
- for i = 1, #abilities do
923
- if abilities[i].typeId == abilityId then
924
- abilities[i]:destroy()
925
- tremove(abilities, i)
926
- return true
927
- end
992
+ function Unit.prototype.removeAbility(self, abilityTypeId)
993
+ local abilities = self.abilities
994
+ for i = 1, #abilities do
995
+ if abilities[i].typeId == abilityTypeId then
996
+ local ability = abilities[i]
997
+ tremove(abilities, i)
998
+ ability:destroy()
999
+ return true
928
1000
  end
929
- return true
930
1001
  end
931
- return false
1002
+ return doUnitAbilityAction(self.handle, abilityTypeId, unitRemoveAbility, abilityTypeId)
932
1003
  end
933
1004
  function Unit.prototype.hideAbility(self, abilityId, flag)
934
1005
  BlzUnitHideAbility(self.handle, abilityId, flag)
@@ -942,9 +1013,6 @@ end
942
1013
  function Unit.prototype.endAbilityCooldown(self, abilityId)
943
1014
  BlzEndUnitAbilityCooldown(self.handle, abilityId)
944
1015
  end
945
- function Unit.prototype.interruptAttack(self)
946
- unitInterruptAttack(self.handle)
947
- end
948
1016
  function Unit.prototype.interruptCast(self, abilityId)
949
1017
  local handle = self.handle
950
1018
  unitDisableAbility(handle, abilityId, true, false)
@@ -1015,18 +1083,44 @@ function Unit.prototype.unpauseEx(self)
1015
1083
  end
1016
1084
  function Unit.prototype.incrementStunCounter(self)
1017
1085
  local stunCounter = self[102] or 0
1018
- if not self[101] or stunCounter >= 0 then
1086
+ if not self[101] and (self[103] or 0) <= 0 or stunCounter >= 0 then
1019
1087
  BlzPauseUnitEx(self.handle, true)
1020
1088
  end
1021
1089
  self[102] = stunCounter + 1
1022
1090
  end
1023
1091
  function Unit.prototype.decrementStunCounter(self)
1024
1092
  local stunCounter = self[102] or 0
1025
- if not self[101] or stunCounter >= 1 then
1093
+ if not self[101] and (self[103] or 0) <= 0 or stunCounter >= 1 then
1026
1094
  BlzPauseUnitEx(self.handle, false)
1027
1095
  end
1028
1096
  self[102] = stunCounter - 1
1029
1097
  end
1098
+ function Unit.prototype.incrementForceStunCounter(self)
1099
+ local forceStunCounter = self[103] or 0
1100
+ if forceStunCounter == 0 then
1101
+ local handle = self.handle
1102
+ if not self[101] then
1103
+ for _ = self[102] or 0, -1 do
1104
+ BlzPauseUnitEx(handle, true)
1105
+ end
1106
+ end
1107
+ BlzPauseUnitEx(handle, true)
1108
+ end
1109
+ self[103] = forceStunCounter + 1
1110
+ end
1111
+ function Unit.prototype.decrementForceStunCounter(self)
1112
+ local forceStunCounter = self[103] or 0
1113
+ if forceStunCounter == 1 then
1114
+ local handle = self.handle
1115
+ if not self[101] then
1116
+ for _ = self[102] or 0, -1 do
1117
+ BlzPauseUnitEx(handle, false)
1118
+ end
1119
+ end
1120
+ BlzPauseUnitEx(handle, false)
1121
+ end
1122
+ self[103] = forceStunCounter - 1
1123
+ end
1030
1124
  function Unit.create(self, owner, id, x, y, facing, skinId)
1031
1125
  local handle = skinId and BlzCreateUnitWithSkin(
1032
1126
  owner.handle,
@@ -1215,7 +1309,7 @@ __TS__SetDescriptor(
1215
1309
  Unit.prototype,
1216
1310
  "isIllusion",
1217
1311
  {get = function(self)
1218
- return isUnitIllusion(self.handle)
1312
+ return IsUnitIllusion(self.handle)
1219
1313
  end},
1220
1314
  true
1221
1315
  )
@@ -1313,19 +1407,6 @@ __TS__SetDescriptor(
1313
1407
  },
1314
1408
  true
1315
1409
  )
1316
- __TS__SetDescriptor(
1317
- Unit.prototype,
1318
- "strengthBase",
1319
- {
1320
- get = function(self)
1321
- return getHeroStr(self.handle, false)
1322
- end,
1323
- set = function(self, strengthBase)
1324
- setHeroStr(self.handle, strengthBase, true)
1325
- end
1326
- },
1327
- true
1328
- )
1329
1410
  __TS__SetDescriptor(
1330
1411
  Unit.prototype,
1331
1412
  "strengthBonus",
@@ -1343,19 +1424,6 @@ __TS__SetDescriptor(
1343
1424
  end},
1344
1425
  true
1345
1426
  )
1346
- __TS__SetDescriptor(
1347
- Unit.prototype,
1348
- "agilityBase",
1349
- {
1350
- get = function(self)
1351
- return getHeroAgi(self.handle, false)
1352
- end,
1353
- set = function(self, agilityBase)
1354
- setHeroAgi(self.handle, agilityBase, true)
1355
- end
1356
- },
1357
- true
1358
- )
1359
1427
  __TS__SetDescriptor(
1360
1428
  Unit.prototype,
1361
1429
  "agilityBonus",
@@ -1373,19 +1441,6 @@ __TS__SetDescriptor(
1373
1441
  end},
1374
1442
  true
1375
1443
  )
1376
- __TS__SetDescriptor(
1377
- Unit.prototype,
1378
- "intelligenceBase",
1379
- {
1380
- get = function(self)
1381
- return getHeroInt(self.handle, false)
1382
- end,
1383
- set = function(self, intelligenceBase)
1384
- setHeroInt(self.handle, intelligenceBase, true)
1385
- end
1386
- },
1387
- true
1388
- )
1389
1444
  __TS__SetDescriptor(
1390
1445
  Unit.prototype,
1391
1446
  "intelligenceBonus",
@@ -1434,17 +1489,17 @@ __TS__SetDescriptor(
1434
1489
  "isTeamGlowVisible",
1435
1490
  {
1436
1491
  get = function(self)
1437
- return not self[106]
1492
+ return not self[107]
1438
1493
  end,
1439
1494
  set = function(self, isTeamGlowVisible)
1440
1495
  BlzShowUnitTeamGlow(self.handle, isTeamGlowVisible)
1441
- local ____temp_6
1496
+ local ____temp_7
1442
1497
  if not isTeamGlowVisible then
1443
- ____temp_6 = true
1498
+ ____temp_7 = true
1444
1499
  else
1445
- ____temp_6 = nil
1500
+ ____temp_7 = nil
1446
1501
  end
1447
- self[106] = ____temp_6
1502
+ self[107] = ____temp_7
1448
1503
  end
1449
1504
  },
1450
1505
  true
@@ -1454,7 +1509,7 @@ __TS__SetDescriptor(
1454
1509
  "color",
1455
1510
  {set = function(self, color)
1456
1511
  SetUnitColor(self.handle, color.handle)
1457
- if self[106] then
1512
+ if self[107] then
1458
1513
  BlzShowUnitTeamGlow(self.handle, false)
1459
1514
  end
1460
1515
  end},
@@ -1478,14 +1533,14 @@ __TS__SetDescriptor(
1478
1533
  "maxHealth",
1479
1534
  {
1480
1535
  get = function(self)
1481
- return BlzGetUnitMaxHP(self.handle) - (self[104] or 0) - (self[105] or 0)
1536
+ return BlzGetUnitMaxHP(self.handle) - (self[105] or 0) - (self[106] or 0)
1482
1537
  end,
1483
1538
  set = function(self, maxHealth)
1484
- if maxHealth < 1 and self[103] ~= nil then
1485
- self[104] = (self[104] or 0) + (1 - maxHealth)
1539
+ if maxHealth < 1 and self[104] ~= nil then
1540
+ self[105] = (self[105] or 0) + (1 - maxHealth)
1486
1541
  maxHealth = 1
1487
1542
  end
1488
- BlzSetUnitMaxHP(self.handle, maxHealth + (self[105] or 0))
1543
+ BlzSetUnitMaxHP(self.handle, maxHealth + (self[106] or 0))
1489
1544
  end
1490
1545
  },
1491
1546
  true
@@ -1527,10 +1582,10 @@ __TS__SetDescriptor(
1527
1582
  "health",
1528
1583
  {
1529
1584
  get = function(self)
1530
- return GetWidgetLife(self.handle) - (self[105] or 0)
1585
+ return GetWidgetLife(self.handle) - (self[106] or 0)
1531
1586
  end,
1532
1587
  set = function(self, health)
1533
- SetWidgetLife(self.handle, health + (self[105] or 0))
1588
+ SetWidgetLife(self.handle, health + (self[106] or 0))
1534
1589
  end
1535
1590
  },
1536
1591
  true
@@ -1606,25 +1661,12 @@ __TS__SetDescriptor(
1606
1661
  },
1607
1662
  true
1608
1663
  )
1609
- __TS__SetDescriptor(
1610
- Unit.prototype,
1611
- "flyHeight",
1612
- {
1613
- get = function(self)
1614
- return getUnitFlyHeight(self.handle)
1615
- end,
1616
- set = function(self, v)
1617
- SetUnitFlyHeight(self.handle, v, 100000)
1618
- end
1619
- },
1620
- true
1621
- )
1622
1664
  __TS__SetDescriptor(
1623
1665
  Unit.prototype,
1624
1666
  "x",
1625
1667
  {
1626
1668
  get = function(self)
1627
- return self[107] or getUnitX(self.handle)
1669
+ return self[108] or getUnitX(self.handle)
1628
1670
  end,
1629
1671
  set = function(self, v)
1630
1672
  SetUnitX(self.handle, v)
@@ -1637,7 +1679,7 @@ __TS__SetDescriptor(
1637
1679
  "y",
1638
1680
  {
1639
1681
  get = function(self)
1640
- return self[108] or getUnitY(self.handle)
1682
+ return self[109] or getUnitY(self.handle)
1641
1683
  end,
1642
1684
  set = function(self, v)
1643
1685
  SetUnitY(self.handle, v)
@@ -1742,14 +1784,18 @@ __TS__SetDescriptor(
1742
1784
  local handle = self.handle
1743
1785
  if isPaused and not IsUnitPaused(handle) then
1744
1786
  self[101] = true
1745
- for _ = self[102] or 0, -1 do
1746
- BlzPauseUnitEx(handle, true)
1787
+ if (self[103] or 0) <= 0 then
1788
+ for _ = self[102] or 0, -1 do
1789
+ BlzPauseUnitEx(handle, true)
1790
+ end
1747
1791
  end
1748
1792
  PauseUnit(handle, true)
1749
1793
  elseif not isPaused and IsUnitPaused(handle) then
1750
1794
  PauseUnit(handle, false)
1751
- for _ = self[102] or 0, -1 do
1752
- BlzPauseUnitEx(handle, false)
1795
+ if (self[103] or 0) <= 0 then
1796
+ for _ = self[102] or 0, -1 do
1797
+ BlzPauseUnitEx(handle, false)
1798
+ end
1753
1799
  end
1754
1800
  self[101] = nil
1755
1801
  end
@@ -1807,20 +1853,6 @@ __TS__SetDescriptor(
1807
1853
  },
1808
1854
  true
1809
1855
  )
1810
- __TS__SetDescriptor(
1811
- Unit.prototype,
1812
- "scale",
1813
- {
1814
- get = function(self)
1815
- return getUnitRealField(self.handle, UNIT_RF_SCALING_VALUE)
1816
- end,
1817
- set = function(self, v)
1818
- setUnitScale(self.handle, v, v, v)
1819
- setUnitRealField(self.handle, UNIT_RF_SCALING_VALUE, v)
1820
- end
1821
- },
1822
- true
1823
- )
1824
1856
  __TS__SetDescriptor(
1825
1857
  Unit.prototype,
1826
1858
  "timeScale",
@@ -1957,30 +1989,6 @@ __TS__SetDescriptor(
1957
1989
  end},
1958
1990
  true
1959
1991
  )
1960
- __TS__SetDescriptor(
1961
- Unit.prototype,
1962
- "onUnitInRange",
1963
- {get = function(self)
1964
- local handle = self.handle
1965
- local onUnitInRange = setmetatable(
1966
- {},
1967
- {__index = function(self, value)
1968
- local event = __TS__New(
1969
- TriggerEvent,
1970
- function(trigger)
1971
- TriggerRegisterUnitInRangeSimple(trigger, value, handle)
1972
- end,
1973
- function() return ____exports.Unit:of(handle) end
1974
- )
1975
- rawset(self, value, event)
1976
- return event
1977
- end}
1978
- )
1979
- rawset(self, "onUnitInRange", onUnitInRange)
1980
- return onUnitInRange
1981
- end},
1982
- true
1983
- )
1984
1992
  __TS__SetDescriptor(
1985
1993
  Unit.prototype,
1986
1994
  "onManaEqual",
@@ -2048,6 +2056,14 @@ __TS__SetDescriptor(
2048
2056
  end},
2049
2057
  true
2050
2058
  )
2059
+ __TS__SetDescriptor(
2060
+ Unit.prototype,
2061
+ "targetAcquiredEvent",
2062
+ {get = function(self)
2063
+ return self:getEvent(EVENT_UNIT_ACQUIRED_TARGET)
2064
+ end},
2065
+ true
2066
+ )
2051
2067
  __TS__SetDescriptor(
2052
2068
  Unit.prototype,
2053
2069
  "onSelect",
@@ -2108,6 +2124,11 @@ __TS__SetDescriptor(
2108
2124
  end},
2109
2125
  true
2110
2126
  )
2127
+ Unit.levelChangedEvent = __TS__New(
2128
+ ____exports.UnitTriggerEvent,
2129
+ EVENT_PLAYER_HERO_LEVEL,
2130
+ function() return ____exports.Unit:of(getTriggerUnit()) end
2131
+ )
2111
2132
  Unit.deathEvent = __TS__New(
2112
2133
  ____exports.UnitTriggerEvent,
2113
2134
  EVENT_PLAYER_UNIT_DEATH,
@@ -2183,25 +2204,25 @@ Unit.onTargetCast = dispatchId(__TS__New(
2183
2204
  InitializingEvent,
2184
2205
  function(event)
2185
2206
  local function listener(unit, id)
2186
- local ____GetSpellTargetUnit_result_9
2207
+ local ____GetSpellTargetUnit_result_10
2187
2208
  if GetSpellTargetUnit() then
2188
- ____GetSpellTargetUnit_result_9 = ____exports.Unit:of(GetSpellTargetUnit())
2209
+ ____GetSpellTargetUnit_result_10 = ____exports.Unit:of(GetSpellTargetUnit())
2189
2210
  else
2190
- local ____GetSpellTargetItem_result_8
2211
+ local ____GetSpellTargetItem_result_9
2191
2212
  if GetSpellTargetItem() then
2192
- ____GetSpellTargetItem_result_8 = Item:of(GetSpellTargetItem())
2213
+ ____GetSpellTargetItem_result_9 = Item:of(GetSpellTargetItem())
2193
2214
  else
2194
- local ____GetSpellTargetDestructable_result_7
2215
+ local ____GetSpellTargetDestructable_result_8
2195
2216
  if GetSpellTargetDestructable() then
2196
- ____GetSpellTargetDestructable_result_7 = Destructable:of(GetSpellTargetDestructable())
2217
+ ____GetSpellTargetDestructable_result_8 = Destructable:of(GetSpellTargetDestructable())
2197
2218
  else
2198
- ____GetSpellTargetDestructable_result_7 = nil
2219
+ ____GetSpellTargetDestructable_result_8 = nil
2199
2220
  end
2200
- ____GetSpellTargetItem_result_8 = ____GetSpellTargetDestructable_result_7
2221
+ ____GetSpellTargetItem_result_9 = ____GetSpellTargetDestructable_result_8
2201
2222
  end
2202
- ____GetSpellTargetUnit_result_9 = ____GetSpellTargetItem_result_8
2223
+ ____GetSpellTargetUnit_result_10 = ____GetSpellTargetItem_result_9
2203
2224
  end
2204
- local target = ____GetSpellTargetUnit_result_9
2225
+ local target = ____GetSpellTargetUnit_result_10
2205
2226
  if target then
2206
2227
  invoke(event, unit, id, target)
2207
2228
  end
@@ -2420,15 +2441,11 @@ Unit.onDamaging = (function()
2420
2441
  metadata = metadata,
2421
2442
  isAttack = BlzGetEventIsAttack(),
2422
2443
  originalAmount = GetEventDamage(),
2423
- originalMetadata = metadata
2444
+ originalMetadata = metadata,
2445
+ preventRetaliation = damagingEventPreventRetaliation
2424
2446
  }
2425
2447
  if data.isAttack and source then
2426
- 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
2427
- if weapon == -1 then
2428
- local targetsAllowed = BlzGetUnitWeaponIntegerField(source.handle, UNIT_WEAPON_IF_ATTACK_TARGETS_ALLOWED, 0)
2429
- weapon = 0
2430
- end
2431
- data.weapon = assert(source.weapons[weapon + 1])
2448
+ data.weapon = source:chooseWeapon(target)
2432
2449
  end
2433
2450
  if not data.isAttack or not source or not source._attackHandlers then
2434
2451
  invoke(
@@ -2449,6 +2466,20 @@ Unit.onDamaging = (function()
2449
2466
  }
2450
2467
  )
2451
2468
  )
2469
+ if data[0] and source then
2470
+ local sourceOwner = source.owner.handle
2471
+ data[1] = sourceOwner
2472
+ local targetOwner = target.owner.handle
2473
+ data[2] = targetOwner
2474
+ if not GetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE) then
2475
+ SetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE, true)
2476
+ data[3] = true
2477
+ end
2478
+ if not GetPlayerAlliance(targetOwner, sourceOwner, ALLIANCE_PASSIVE) then
2479
+ SetPlayerAlliance(targetOwner, sourceOwner, ALLIANCE_PASSIVE, true)
2480
+ data[4] = true
2481
+ end
2482
+ end
2452
2483
  damagingEventByTarget[target] = data
2453
2484
  return
2454
2485
  end
@@ -2526,12 +2557,32 @@ Unit.onDamage = __TS__New(
2526
2557
  originalMetadata = damagingEvent and damagingEvent.originalMetadata,
2527
2558
  preventDeath = damageEventPreventDeath
2528
2559
  }
2560
+ if damagingEvent then
2561
+ for key, value in pairs(damagingEvent) do
2562
+ if isAttribute(key) then
2563
+ data[key] = value
2564
+ end
2565
+ end
2566
+ local sourceOwner = damagingEvent[1]
2567
+ if sourceOwner then
2568
+ local targetOwner = damagingEvent[2]
2569
+ if damagingEvent[3] then
2570
+ SetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE, false)
2571
+ end
2572
+ if damagingEvent[4] then
2573
+ SetPlayerAlliance(targetOwner, sourceOwner, ALLIANCE_PASSIVE, false)
2574
+ end
2575
+ end
2576
+ end
2529
2577
  local evData = setmetatable(
2530
2578
  {},
2531
2579
  {
2532
2580
  __index = data,
2533
2581
  __newindex = function(self, key, value)
2534
- damageSetters[key](value)
2582
+ local damageSetter = damageSetters[key]
2583
+ if damageSetter ~= nil then
2584
+ damageSetter(value)
2585
+ end
2535
2586
  data[key] = value
2536
2587
  end
2537
2588
  }
@@ -2539,7 +2590,7 @@ Unit.onDamage = __TS__New(
2539
2590
  invoke(event, source, target, evData)
2540
2591
  if evData[0] ~= nil and target.health - evData.amount < 0.405 then
2541
2592
  local bonusHealth = math.ceil(evData.amount)
2542
- target[105] = (target[105] or 0) + bonusHealth
2593
+ target[106] = (target[106] or 0) + bonusHealth
2543
2594
  BlzSetUnitMaxHP(
2544
2595
  target.handle,
2545
2596
  BlzGetUnitMaxHP(target.handle) + bonusHealth
@@ -2553,7 +2604,7 @@ Unit.onDamage = __TS__New(
2553
2604
  evData[0],
2554
2605
  table.unpack(evData, 1 + 1, 1 + (evData[1] or 0))
2555
2606
  )
2556
- target[105] = (target[105] or 0) - bonusHealth
2607
+ target[106] = (target[106] or 0) - bonusHealth
2557
2608
  SetWidgetLife(
2558
2609
  target.handle,
2559
2610
  GetWidgetLife(target.handle) - bonusHealth
@@ -2589,10 +2640,14 @@ Unit.itemPickedUpEvent = __TS__New(
2589
2640
  ____exports.UnitTriggerEvent,
2590
2641
  EVENT_PLAYER_UNIT_PICKUP_ITEM,
2591
2642
  function()
2592
- local unit = getTriggerUnit()
2593
- local item = getManipulatedItem()
2594
- if getUnitTypeId(unit) ~= dummyUnitId and not (ignoreEventsItems[item] ~= nil) then
2595
- return ____exports.Unit:of(unit), Item:of(item)
2643
+ local unitHandle = getTriggerUnit()
2644
+ local itemHandle = getManipulatedItem()
2645
+ if getUnitTypeId(unitHandle) ~= dummyUnitId and not (ignoreEventsItems[itemHandle] ~= nil) then
2646
+ local unit = ____exports.Unit:of(unitHandle)
2647
+ local item = Item:of(itemHandle)
2648
+ if item.owner ~= unit then
2649
+ return unit, item
2650
+ end
2596
2651
  end
2597
2652
  return IgnoreEvent
2598
2653
  end
@@ -2612,7 +2667,22 @@ Unit.itemUsedEvent = __TS__New(
2612
2667
  Unit.itemStackedEvent = __TS__New(
2613
2668
  ____exports.UnitTriggerEvent,
2614
2669
  EVENT_PLAYER_UNIT_STACK_ITEM,
2615
- function() return ____exports.Unit:of(getTriggerUnit()), Item:of(getManipulatedItem()) end
2670
+ function() return ____exports.Unit:of(getTriggerUnit()), Item:of(BlzGetStackingItemTarget()), Item:of(BlzGetStackingItemSource()) end
2671
+ )
2672
+ __TS__ObjectDefineProperty(
2673
+ Unit,
2674
+ "itemChargesChangedEvent",
2675
+ {get = function(self)
2676
+ local event = __TS__New(Event)
2677
+ Item.chargesChangedEvent:addListener(function(item)
2678
+ local unit = item.owner
2679
+ if unit ~= nil then
2680
+ invoke(event, unit, item)
2681
+ end
2682
+ end)
2683
+ rawset(self, "itemChargesChangedEvent", event)
2684
+ return event
2685
+ end}
2616
2686
  )
2617
2687
  __TS__ObjectDefineProperty(
2618
2688
  Unit,
@@ -2684,6 +2754,10 @@ __TS__ObjectDefineProperty(
2684
2754
  rawset(self, "destroyEvent", destroyEvent)
2685
2755
  return destroyEvent
2686
2756
  end}
2757
+ )
2758
+ Unit.synchronize = synchronizer(
2759
+ function(unit) return unit.syncId end,
2760
+ function(syncId) return unitBySyncId[syncId] end
2687
2761
  );
2688
2762
  (function(self)
2689
2763
  local leaveAbilityIds = postcompile(function()
@@ -2713,7 +2787,8 @@ __TS__ObjectDefineProperty(
2713
2787
  return
2714
2788
  end
2715
2789
  end
2716
- unit:destroy()
2790
+ unit:saveData()
2791
+ Timer:run(unit, "destroy")
2717
2792
  end)
2718
2793
  end
2719
2794
  end)(Unit)