warscript 0.0.1-dev.2cd2e68 → 0.0.1-dev.2fcfd45

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 (89) hide show
  1. package/attributes.d.ts +1 -0
  2. package/attributes.lua +9 -0
  3. package/core/types/frame.lua +24 -21
  4. package/core/types/player.d.ts +15 -0
  5. package/core/types/player.lua +56 -14
  6. package/core/types/playerCamera.d.ts +2 -0
  7. package/core/types/playerCamera.lua +123 -5
  8. package/core/types/tileCell.d.ts +9 -0
  9. package/core/types/tileCell.lua +92 -0
  10. package/core/types/timer.d.ts +3 -1
  11. package/core/types/timer.lua +27 -2
  12. package/decl/native.d.ts +6 -4
  13. package/engine/behavior.d.ts +5 -0
  14. package/engine/behavior.lua +106 -27
  15. package/engine/behaviour/ability/apply-buff.lua +1 -1
  16. package/engine/behaviour/ability/emulate-impact.d.ts +1 -1
  17. package/engine/behaviour/ability/emulate-impact.lua +2 -1
  18. package/engine/behaviour/ability/remove-buffs.d.ts +9 -0
  19. package/engine/behaviour/ability/remove-buffs.lua +21 -0
  20. package/engine/behaviour/ability/restore-mana.d.ts +1 -1
  21. package/engine/behaviour/ability/restore-mana.lua +6 -6
  22. package/engine/behaviour/ability.lua +7 -16
  23. package/engine/behaviour/unit/stun-immunity.d.ts +7 -3
  24. package/engine/behaviour/unit/stun-immunity.lua +52 -27
  25. package/engine/behaviour/unit.d.ts +19 -2
  26. package/engine/behaviour/unit.lua +83 -7
  27. package/engine/buff.d.ts +2 -4
  28. package/engine/buff.lua +68 -83
  29. package/engine/internal/ability.d.ts +3 -1
  30. package/engine/internal/ability.lua +34 -11
  31. package/engine/internal/item/ability.lua +51 -1
  32. package/engine/internal/item+owner.lua +12 -6
  33. package/engine/internal/item.d.ts +13 -15
  34. package/engine/internal/item.lua +63 -49
  35. package/engine/internal/misc/frame-coordinates.d.ts +2 -0
  36. package/engine/internal/misc/frame-coordinates.lua +21 -0
  37. package/engine/internal/misc/get-terrain-z.d.ts +2 -0
  38. package/engine/internal/misc/get-terrain-z.lua +11 -0
  39. package/engine/internal/misc/player-local-handle.d.ts +2 -0
  40. package/engine/internal/misc/player-local-handle.lua +5 -0
  41. package/engine/internal/unit/ability.d.ts +35 -5
  42. package/engine/internal/unit/ability.lua +96 -21
  43. package/engine/internal/unit/main-selected.lua +12 -27
  44. package/engine/internal/unit/order.d.ts +20 -0
  45. package/engine/internal/unit/order.lua +136 -0
  46. package/engine/internal/unit+ability.lua +10 -1
  47. package/engine/internal/unit-missile-launch.lua +42 -14
  48. package/engine/internal/unit.d.ts +8 -6
  49. package/engine/internal/unit.lua +108 -83
  50. package/engine/object-data/auxiliary/armor-type.d.ts +11 -0
  51. package/engine/object-data/auxiliary/armor-type.lua +46 -0
  52. package/engine/object-data/entry/ability-type.lua +5 -4
  53. package/engine/object-data/entry/unit-type.d.ts +11 -2
  54. package/engine/object-data/entry/unit-type.lua +59 -1
  55. package/engine/object-field/ability.d.ts +3 -3
  56. package/engine/object-field/ability.lua +7 -6
  57. package/engine/object-field/unit.d.ts +11 -0
  58. package/engine/object-field/unit.lua +34 -0
  59. package/engine/object-field.d.ts +4 -2
  60. package/engine/object-field.lua +20 -17
  61. package/engine/random.d.ts +9 -0
  62. package/engine/random.lua +13 -0
  63. package/engine/standard/fields/unit.d.ts +4 -0
  64. package/engine/standard/fields/unit.lua +7 -0
  65. package/engine/synchronization.d.ts +11 -0
  66. package/engine/synchronization.lua +77 -0
  67. package/engine/text-tag.d.ts +36 -2
  68. package/engine/text-tag.lua +249 -10
  69. package/engine/unit.d.ts +1 -0
  70. package/engine/unit.lua +1 -0
  71. package/net/socket.lua +1 -1
  72. package/objutil/buff.lua +1 -1
  73. package/package.json +2 -2
  74. package/patch-lualib.lua +1 -1
  75. package/utility/arrays.d.ts +1 -0
  76. package/utility/arrays.lua +8 -0
  77. package/utility/callback-array.d.ts +17 -0
  78. package/utility/callback-array.lua +61 -0
  79. package/utility/functions.d.ts +7 -0
  80. package/utility/functions.lua +12 -0
  81. package/utility/linked-set.d.ts +1 -0
  82. package/utility/linked-set.lua +19 -1
  83. package/utility/lua-maps.d.ts +12 -2
  84. package/utility/lua-maps.lua +37 -2
  85. package/utility/lua-sets.d.ts +1 -0
  86. package/utility/lua-sets.lua +4 -0
  87. package/utility/types.d.ts +3 -0
  88. package/core/types/order.d.ts +0 -26
  89. package/core/types/order.lua +0 -65
@@ -0,0 +1,136 @@
1
+ local ____lualib = require("lualib_bundle")
2
+ local __TS__ObjectDefineProperty = ____lualib.__TS__ObjectDefineProperty
3
+ local ____exports = {}
4
+ local ____attributes = require("attributes")
5
+ local attribute = ____attributes.attribute
6
+ local ____unit = require("engine.internal.unit")
7
+ local Unit = ____unit.Unit
8
+ local ____game = require("core.game")
9
+ local elapsedTime = ____game.elapsedTime
10
+ local getUnitCurrentOrder = GetUnitCurrentOrder
11
+ local issueImmediateOrderById = IssueImmediateOrderById
12
+ local issuePointOrderById = IssuePointOrderById
13
+ local issueTargetOrderById = IssueTargetOrderById
14
+ local unitLastOrderTypeAttribute = attribute()
15
+ local unitLastOrderIdAttribute = attribute()
16
+ local unitLastOrderStartTimeAttribute = attribute()
17
+ local unitLastOrderStartXAttribute = attribute()
18
+ local unitLastOrderStartYAttribute = attribute()
19
+ local unitLastOrderTargetXAttribute = attribute()
20
+ local unitLastOrderTargetYAttribute = attribute()
21
+ local unitLastOrderTargetAttribute = attribute()
22
+ Unit.onImmediateOrder:addListener(
23
+ 4,
24
+ function(unit, orderId)
25
+ unit[unitLastOrderTypeAttribute] = 0
26
+ unit[unitLastOrderIdAttribute] = orderId
27
+ unit[unitLastOrderStartTimeAttribute] = elapsedTime()
28
+ unit[unitLastOrderStartXAttribute] = unit.x
29
+ unit[unitLastOrderStartYAttribute] = unit.y
30
+ unit[unitLastOrderTargetXAttribute] = nil
31
+ unit[unitLastOrderTargetYAttribute] = nil
32
+ unit[unitLastOrderTargetAttribute] = nil
33
+ end
34
+ )
35
+ Unit.onPointOrder:addListener(
36
+ 4,
37
+ function(unit, orderId, x, y)
38
+ unit[unitLastOrderTypeAttribute] = 1
39
+ unit[unitLastOrderIdAttribute] = orderId
40
+ unit[unitLastOrderStartTimeAttribute] = elapsedTime()
41
+ unit[unitLastOrderStartXAttribute] = unit.x
42
+ unit[unitLastOrderStartYAttribute] = unit.y
43
+ unit[unitLastOrderTargetXAttribute] = x
44
+ unit[unitLastOrderTargetYAttribute] = y
45
+ unit[unitLastOrderTargetAttribute] = nil
46
+ end
47
+ )
48
+ Unit.onTargetOrder:addListener(
49
+ 4,
50
+ function(unit, orderId, target)
51
+ unit[unitLastOrderTypeAttribute] = 2
52
+ unit[unitLastOrderIdAttribute] = orderId
53
+ unit[unitLastOrderStartTimeAttribute] = elapsedTime()
54
+ unit[unitLastOrderStartXAttribute] = unit.x
55
+ unit[unitLastOrderStartYAttribute] = unit.y
56
+ unit[unitLastOrderTargetXAttribute] = target.x
57
+ unit[unitLastOrderTargetYAttribute] = target.y
58
+ unit[unitLastOrderTargetAttribute] = target
59
+ end
60
+ )
61
+ local function toUndefinedIfCurrentOrderDoesNotMatchLast(unit, value)
62
+ local currentOrderId = getUnitCurrentOrder(unit.handle)
63
+ local lastOrderId = unit[unitLastOrderIdAttribute]
64
+ local ____temp_0
65
+ if currentOrderId == lastOrderId or currentOrderId == orderId("patrolAI") and lastOrderId == orderId("patrol") then
66
+ ____temp_0 = value
67
+ else
68
+ ____temp_0 = nil
69
+ end
70
+ return ____temp_0
71
+ end
72
+ __TS__ObjectDefineProperty(
73
+ Unit.prototype,
74
+ "currentOrderType",
75
+ {get = function(self)
76
+ return toUndefinedIfCurrentOrderDoesNotMatchLast(self, self[unitLastOrderTypeAttribute]) or 0
77
+ end}
78
+ )
79
+ __TS__ObjectDefineProperty(
80
+ Unit.prototype,
81
+ "currentOrderId",
82
+ {get = function(self)
83
+ return toUndefinedIfCurrentOrderDoesNotMatchLast(self, self[unitLastOrderIdAttribute]) or 0
84
+ end}
85
+ )
86
+ __TS__ObjectDefineProperty(
87
+ Unit.prototype,
88
+ "currentOrderStartTime",
89
+ {get = function(self)
90
+ return toUndefinedIfCurrentOrderDoesNotMatchLast(self, self[unitLastOrderStartTimeAttribute]) or 0
91
+ end}
92
+ )
93
+ __TS__ObjectDefineProperty(
94
+ Unit.prototype,
95
+ "currentOrderStartX",
96
+ {get = function(self)
97
+ return toUndefinedIfCurrentOrderDoesNotMatchLast(self, self[unitLastOrderStartXAttribute]) or 0
98
+ end}
99
+ )
100
+ __TS__ObjectDefineProperty(
101
+ Unit.prototype,
102
+ "currentOrderStartY",
103
+ {get = function(self)
104
+ return toUndefinedIfCurrentOrderDoesNotMatchLast(self, self[unitLastOrderStartYAttribute]) or 0
105
+ end}
106
+ )
107
+ __TS__ObjectDefineProperty(
108
+ Unit.prototype,
109
+ "currentOrderTargetX",
110
+ {get = function(self)
111
+ return toUndefinedIfCurrentOrderDoesNotMatchLast(self, self[unitLastOrderTargetXAttribute]) or 0
112
+ end}
113
+ )
114
+ __TS__ObjectDefineProperty(
115
+ Unit.prototype,
116
+ "currentOrderTargetY",
117
+ {get = function(self)
118
+ return toUndefinedIfCurrentOrderDoesNotMatchLast(self, self[unitLastOrderTargetYAttribute]) or 0
119
+ end}
120
+ )
121
+ __TS__ObjectDefineProperty(
122
+ Unit.prototype,
123
+ "currentOrderTarget",
124
+ {get = function(self)
125
+ return toUndefinedIfCurrentOrderDoesNotMatchLast(self, self[unitLastOrderTargetAttribute])
126
+ end}
127
+ )
128
+ local issueOrderByType = {
129
+ [0] = issueImmediateOrderById,
130
+ [1] = issuePointOrderById,
131
+ [2] = function(unitHandle, orderId, widget) return issueTargetOrderById(unitHandle, orderId, widget.handle) end
132
+ }
133
+ Unit.prototype.issueOrder = function(self, orderType, orderId, xOrTarget, y)
134
+ return issueOrderByType[orderType](self.handle, orderId, xOrTarget, y)
135
+ end
136
+ return ____exports
@@ -7,8 +7,8 @@ local UnitAbility = ____ability.UnitAbility
7
7
  local ____unit = require("engine.internal.unit")
8
8
  local Unit = ____unit.Unit
9
9
  local ____event = require("event")
10
- local Event = ____event.Event
11
10
  local createDispatchingEvent = ____event.createDispatchingEvent
11
+ local Event = ____event.Event
12
12
  local abilityGainedEvent = createDispatchingEvent(
13
13
  __TS__New(Event),
14
14
  function(unit, ability) return ability.typeId end
@@ -40,6 +40,15 @@ ItemAbility.onCreate:addListener(
40
40
  end
41
41
  end
42
42
  )
43
+ ItemAbility.destroyEvent:addListener(
44
+ 4,
45
+ function(ability)
46
+ local unit = ability.owner.owner
47
+ if unit ~= nil then
48
+ Event.invoke(abilityLostEvent, unit, ability)
49
+ end
50
+ end
51
+ )
43
52
  Unit.itemPickedUpEvent:addListener(
44
53
  0,
45
54
  function(unit, item)
@@ -9,9 +9,16 @@ local ____timer = require("core.types.timer")
9
9
  local Timer = ____timer.Timer
10
10
  local ____lua_2Dsets = require("utility.lua-sets")
11
11
  local luaSetOf = ____lua_2Dsets.luaSetOf
12
+ local ____attributes = require("attributes")
13
+ local attribute = ____attributes.attribute
14
+ local ____linked_2Dset = require("utility.linked-set")
15
+ local LinkedSet = ____linked_2Dset.LinkedSet
12
16
  local autoAttackFinishEvent = __TS__New(Event)
13
17
  rawset(Unit, "autoAttackFinishEvent", autoAttackFinishEvent)
14
- local eventTimerByUnit = {}
18
+ local units = __TS__New(LinkedSet)
19
+ local targetAttribute = attribute()
20
+ local impactDelayAttribute = attribute()
21
+ local passedTimeAttribute = attribute()
15
22
  local instantOrderIds = luaSetOf(
16
23
  orderId("avatar"),
17
24
  orderId("berserk"),
@@ -28,24 +35,45 @@ local instantOrderIds = luaSetOf(
28
35
  orderId("unimmolation")
29
36
  )
30
37
  local function reset(source, orderId)
31
- if not (instantOrderIds[orderId] ~= nil) then
32
- local eventTimer = eventTimerByUnit[source]
33
- if eventTimer then
34
- eventTimer:destroy()
35
- eventTimerByUnit[source] = nil
36
- end
38
+ if not (instantOrderIds[orderId] ~= nil) and units:remove(source) then
39
+ source[targetAttribute] = nil
40
+ source[impactDelayAttribute] = nil
41
+ source[passedTimeAttribute] = nil
37
42
  end
38
43
  end
39
44
  Unit.onImmediateOrder:addListener(reset)
40
45
  Unit.onPointOrder:addListener(reset)
41
46
  Unit.onTargetOrder:addListener(reset)
42
- local function timerCallback(source, target)
43
- eventTimerByUnit[source] = nil
44
- Event.invoke(autoAttackFinishEvent, source, target)
47
+ local timerPeriod = 1 / 64
48
+ local function invokeEvent(unit)
49
+ units:remove(unit)
50
+ local target = unit[targetAttribute]
51
+ unit[targetAttribute] = nil
52
+ unit[impactDelayAttribute] = nil
53
+ unit[passedTimeAttribute] = nil
54
+ Event.invoke(autoAttackFinishEvent, unit, target)
55
+ end
56
+ local function checkUnit(unit)
57
+ local passedTime = unit[passedTimeAttribute] + timerPeriod
58
+ if passedTime >= unit[impactDelayAttribute] then
59
+ invokeEvent(unit)
60
+ else
61
+ unit[passedTimeAttribute] = passedTime
62
+ end
45
63
  end
46
- Unit.autoAttackStartEvent:addListener(function(source, target)
47
- local attackPoint = (source:chooseWeapon(target) or source.firstWeapon).impactDelay
48
- local timer = Timer:simple(attackPoint, timerCallback, source, target)
49
- eventTimerByUnit[source] = timer
64
+ Timer.onPeriod[timerPeriod]:addListener(function()
65
+ units:forEach(checkUnit)
50
66
  end)
67
+ Unit.autoAttackStartEvent:addListener(
68
+ 999999,
69
+ function(source, target)
70
+ if source[targetAttribute] ~= nil then
71
+ invokeEvent(source)
72
+ end
73
+ source[targetAttribute] = target
74
+ source[impactDelayAttribute] = (source:chooseWeapon(target) or source.firstWeapon).impactDelay
75
+ source[passedTimeAttribute] = -timerPeriod
76
+ units:add(source)
77
+ end
78
+ )
51
79
  return ____exports
@@ -80,6 +80,8 @@ export declare class UnitWeapon {
80
80
  readonly unit: Unit;
81
81
  readonly index: 0 | 1;
82
82
  constructor(unit: Unit, index: 0 | 1);
83
+ get isEnabled(): boolean;
84
+ set isEnabled(isEnabled: boolean);
83
85
  get cooldown(): number;
84
86
  set cooldown(cooldown: number);
85
87
  get damage(): [minimumDamage: number, maximumDamage: number];
@@ -160,8 +162,7 @@ export declare class Unit extends Handle<junit> {
160
162
  isInRangeOf(unit: Unit, range: number): boolean;
161
163
  isAllyOf(unit: Unit): boolean;
162
164
  isEnemyOf(unit: Unit): boolean;
163
- playAnimation(animation: string, rarity?: jraritycontrol): void;
164
- playAnimation(animation: number): void;
165
+ playAnimation(...parameters: [animation: number] | [animation: string, rarity?: jraritycontrol]): void;
165
166
  resetAnimation(): void;
166
167
  queueAnimation(animation: string): void;
167
168
  get weapons(): [UnitWeapon, UnitWeapon];
@@ -267,17 +268,18 @@ export declare class Unit extends Handle<junit> {
267
268
  dropItemTarget(item: Item, target: Widget): boolean;
268
269
  dropItemSlot(item: Item, slot: number): boolean;
269
270
  itemInSlot(slot: number): Item | null;
270
- addAbility(abilityId: number): UnitAbility | null;
271
+ addAbility(abilityId: number): UnitAbility | undefined;
271
272
  makeAbilityPermanent(abilityId: number, permanent: true): boolean;
272
273
  setAbilityLevel(abilityId: number, level: number): number;
273
274
  getAbilityLevel(abilityId: number): number;
274
275
  hasAbility(abilityId: number): boolean;
275
- getAbilityById(abilityId: number): UnitAbility | undefined;
276
- removeAbility(abilityId: number): boolean;
276
+ getAbility(abilityId: number): UnitAbility | undefined;
277
+ removeAbility(abilityTypeId: number): boolean;
277
278
  hideAbility(abilityId: number, flag: boolean): void;
278
279
  getAbilityRemainingCooldown(abilityId: number): number;
279
280
  startAbilityCooldown(abilityId: number, cooldown: number): void;
280
281
  endAbilityCooldown(abilityId: number): void;
282
+ interruptMovement(): void;
281
283
  interruptAttack(): void;
282
284
  interruptCast(abilityId: number): void;
283
285
  getDistanceTo(target: Unit | Vec2): number;
@@ -353,7 +355,7 @@ export declare class Unit extends Handle<junit> {
353
355
  static itemDroppedEvent: UnitTriggerEvent<[Item]>;
354
356
  static itemPickedUpEvent: UnitTriggerEvent<[Item]>;
355
357
  static itemUsedEvent: UnitTriggerEvent<[Item]>;
356
- static itemStackedEvent: UnitTriggerEvent<[Item]>;
358
+ static itemStackedEvent: UnitTriggerEvent<[target: Item, source: Item]>;
357
359
  static get itemChargesChangedEvent(): Event<[unit: Unit, item: Item]>;
358
360
  static get itemUseOrderEvent(): Event<[unit: Unit, item: Item]>;
359
361
  static get itemMoveOrderEvent(): Event<[
@@ -60,6 +60,8 @@ local ____damage_2Dmetadata_2Dby_2Dtarget = require("engine.internal.misc.damage
60
60
  local damageMetadataByTarget = ____damage_2Dmetadata_2Dby_2Dtarget.damageMetadataByTarget
61
61
  local ____attributes = require("attributes")
62
62
  local isAttribute = ____attributes.isAttribute
63
+ local ____ability = require("engine.internal.item.ability")
64
+ local doUnitAbilityAction = ____ability.doUnitAbilityAction
63
65
  local match = string.match
64
66
  local ____tostring = _G.tostring
65
67
  local setUnitAnimation = SetUnitAnimation
@@ -123,10 +125,6 @@ local getOrderedUnit = GetOrderedUnit
123
125
  local getIssuedOrderId = GetIssuedOrderId
124
126
  local isUnitInvulnerable = BlzIsUnitInvulnerable
125
127
  local unitAlive = UnitAlive
126
- local unitAddType = UnitAddType
127
- local unitRemoveType = UnitRemoveType
128
- local isUnitIllusion = IsUnitIllusion
129
- local isUnitType = IsUnitType
130
128
  local isUnitAlly = IsUnitAlly
131
129
  local isUnitEnemy = IsUnitEnemy
132
130
  local getOwningPlayer = GetOwningPlayer
@@ -412,6 +410,19 @@ function UnitWeapon.prototype.____constructor(self, unit, index)
412
410
  self.unit = unit
413
411
  self.index = index
414
412
  end
413
+ __TS__SetDescriptor(
414
+ UnitWeapon.prototype,
415
+ "isEnabled",
416
+ {
417
+ get = function(self)
418
+ return BlzGetUnitWeaponBooleanField(self.unit.handle, UNIT_WEAPON_BF_ATTACKS_ENABLED, self.index)
419
+ end,
420
+ set = function(self, isEnabled)
421
+ BlzSetUnitWeaponBooleanField(self.unit.handle, UNIT_WEAPON_BF_ATTACKS_ENABLED, self.index, isEnabled)
422
+ end
423
+ },
424
+ true
425
+ )
415
426
  __TS__SetDescriptor(
416
427
  UnitWeapon.prototype,
417
428
  "cooldown",
@@ -665,15 +676,24 @@ end
665
676
  local nextSyncId = 1
666
677
  local unitBySyncId = setmetatable({}, {__mode = "v"})
667
678
  local damagingEventByTarget = setmetatable({}, {__mode = "k"})
679
+ local function addAbility(unit, abilityTypeId)
680
+ local ____unitAddAbility_result_0
681
+ if unitAddAbility(unit, abilityTypeId) then
682
+ ____unitAddAbility_result_0 = getUnitAbility(unit, abilityTypeId)
683
+ else
684
+ ____unitAddAbility_result_0 = nil
685
+ end
686
+ return ____unitAddAbility_result_0
687
+ end
668
688
  ____exports.Unit = __TS__Class()
669
689
  local Unit = ____exports.Unit
670
690
  Unit.name = "Unit"
671
691
  __TS__ClassExtends(Unit, Handle)
672
692
  function Unit.prototype.____constructor(self, handle)
673
693
  Handle.prototype.____constructor(self, handle)
674
- local ____nextSyncId_0 = nextSyncId
675
- nextSyncId = ____nextSyncId_0 + 1
676
- self.syncId = ____nextSyncId_0
694
+ local ____nextSyncId_1 = nextSyncId
695
+ nextSyncId = ____nextSyncId_1 + 1
696
+ self.syncId = ____nextSyncId_1
677
697
  self._owner = Player:of(getOwningPlayer(handle))
678
698
  assert(unitAddAbility(handle, leaveDetectAbilityId) and UnitMakeAbilityPermanent(handle, true, leaveDetectAbilityId))
679
699
  assert(unitAddAbility(handle, morphDetectAbilityId))
@@ -774,17 +794,17 @@ function Unit.prototype.addModifier(self, property, modifier)
774
794
  end}
775
795
  end
776
796
  function Unit.prototype.hasCombatClassification(self, combatClassification)
777
- local ____combatClassification_1 = combatClassification
778
- return getUnitIntegerField(self.handle, UNIT_IF_TARGETED_AS) & ____combatClassification_1 == ____combatClassification_1
797
+ local ____combatClassification_2 = combatClassification
798
+ return getUnitIntegerField(self.handle, UNIT_IF_TARGETED_AS) & ____combatClassification_2 == ____combatClassification_2
779
799
  end
780
800
  function Unit.prototype.addClassification(self, classification)
781
- return unitAddType(self.handle, classification)
801
+ return UnitAddType(self.handle, classification)
782
802
  end
783
803
  function Unit.prototype.removeClassification(self, classification)
784
- return unitRemoveType(self.handle, classification)
804
+ return UnitRemoveType(self.handle, classification)
785
805
  end
786
806
  function Unit.prototype.hasClassification(self, classification)
787
- return isUnitType(self.handle, classification)
807
+ return IsUnitType(self.handle, classification)
788
808
  end
789
809
  function Unit.prototype.isVisibleTo(self, player)
790
810
  return isUnitVisible(self.handle, player.handle)
@@ -793,13 +813,13 @@ function Unit.prototype.isInvisibleTo(self, player)
793
813
  return isUnitInvisible(self.handle, player.handle)
794
814
  end
795
815
  function Unit.prototype.isInRangeOf(self, x, y, range)
796
- local ____temp_2
816
+ local ____temp_3
797
817
  if type(x) == "number" then
798
- ____temp_2 = isUnitInRangeXY(self.handle, x, y, range)
818
+ ____temp_3 = isUnitInRangeXY(self.handle, x, y, range)
799
819
  else
800
- ____temp_2 = isUnitInRange(self.handle, x.handle, y)
820
+ ____temp_3 = isUnitInRange(self.handle, x.handle, y)
801
821
  end
802
- return ____temp_2
822
+ return ____temp_3
803
823
  end
804
824
  function Unit.prototype.isAllyOf(self, unit)
805
825
  return isUnitAlly(
@@ -829,11 +849,13 @@ function Unit.prototype.queueAnimation(self, animation)
829
849
  QueueUnitAnimation(self.handle, animation)
830
850
  end
831
851
  function Unit.prototype.chooseWeapon(self, target)
832
- if target:isAllowedTarget(self, self.firstWeapon.allowedTargetCombatClassifications) then
833
- return self.firstWeapon
852
+ local firstWeapon = self.firstWeapon
853
+ if firstWeapon.isEnabled and target:isAllowedTarget(self, firstWeapon.allowedTargetCombatClassifications) then
854
+ return firstWeapon
834
855
  end
835
- if target:isAllowedTarget(target, self.secondWeapon.allowedTargetCombatClassifications) then
836
- return self.secondWeapon
856
+ local secondWeapon = self.secondWeapon
857
+ if secondWeapon.isEnabled and target:isAllowedTarget(target, secondWeapon.allowedTargetCombatClassifications) then
858
+ return secondWeapon
837
859
  end
838
860
  return nil
839
861
  end
@@ -855,14 +877,14 @@ function Unit.prototype.kill(self)
855
877
  killUnit(self.handle)
856
878
  end
857
879
  function Unit.prototype.revive(self, x, y, doEffect)
858
- local ____ReviveHero_5 = ReviveHero
859
- local ____array_4 = __TS__SparseArrayNew(self.handle, x, y)
860
- local ____doEffect_3 = doEffect
861
- if ____doEffect_3 == nil then
862
- ____doEffect_3 = false
880
+ local ____ReviveHero_6 = ReviveHero
881
+ local ____array_5 = __TS__SparseArrayNew(self.handle, x, y)
882
+ local ____doEffect_4 = doEffect
883
+ if ____doEffect_4 == nil then
884
+ ____doEffect_4 = false
863
885
  end
864
- __TS__SparseArrayPush(____array_4, ____doEffect_3)
865
- ____ReviveHero_5(__TS__SparseArraySpread(____array_4))
886
+ __TS__SparseArrayPush(____array_5, ____doEffect_4)
887
+ ____ReviveHero_6(__TS__SparseArraySpread(____array_5))
866
888
  end
867
889
  function Unit.prototype.healTarget(self, target, amount)
868
890
  if __TS__InstanceOf(target, ____exports.Unit) and target:hasAbility(fourCC("BIhm")) then
@@ -905,17 +927,16 @@ function Unit.prototype.itemInSlot(self, slot)
905
927
  return Item:of(unitItemInSlot(self.handle, slot))
906
928
  end
907
929
  function Unit.prototype.addAbility(self, abilityId)
908
- if unitAddAbility(self.handle, abilityId) then
909
- local ability = UnitAbility:of(
910
- checkNotNull(getUnitAbility(self.handle, abilityId)),
911
- abilityId,
912
- self
913
- )
930
+ local ability = UnitAbility:of(
931
+ doUnitAbilityAction(self.handle, abilityId, addAbility, abilityId),
932
+ abilityId,
933
+ self
934
+ )
935
+ if ability ~= nil then
914
936
  local abilities = self.abilities
915
937
  abilities[#abilities + 1] = ability
916
- return ability
917
938
  end
918
- return nil
939
+ return ability
919
940
  end
920
941
  function Unit.prototype.makeAbilityPermanent(self, abilityId, permanent)
921
942
  return UnitMakeAbilityPermanent(self.handle, permanent, abilityId)
@@ -929,31 +950,21 @@ end
929
950
  function Unit.prototype.hasAbility(self, abilityId)
930
951
  return getUnitAbilityLevel(self.handle, abilityId) > 0
931
952
  end
932
- function Unit.prototype.getAbilityById(self, abilityId)
933
- local handle = self.handle
934
- if unitAddAbility(handle, abilityId) then
935
- assert(unitRemoveAbility(handle, abilityId))
936
- return nil
937
- end
938
- return UnitAbility:of(
939
- getUnitAbility(self.handle, abilityId),
940
- abilityId,
941
- self
942
- )
953
+ function Unit.prototype.getAbility(self, abilityId)
954
+ local ability = doUnitAbilityAction(self.handle, abilityId, getUnitAbility, abilityId)
955
+ return UnitAbility:of(ability, abilityId, self)
943
956
  end
944
- function Unit.prototype.removeAbility(self, abilityId)
945
- if unitRemoveAbility(self.handle, abilityId) then
946
- local abilities = self.abilities
947
- for i = 1, #abilities do
948
- if abilities[i].typeId == abilityId then
949
- abilities[i]:destroy()
950
- tremove(abilities, i)
951
- return true
952
- end
957
+ function Unit.prototype.removeAbility(self, abilityTypeId)
958
+ local abilities = self.abilities
959
+ for i = 1, #abilities do
960
+ if abilities[i].typeId == abilityTypeId then
961
+ local ability = abilities[i]
962
+ tremove(abilities, i)
963
+ ability:destroy()
964
+ return true
953
965
  end
954
- return true
955
966
  end
956
- return false
967
+ return doUnitAbilityAction(self.handle, abilityTypeId, unitRemoveAbility, abilityTypeId)
957
968
  end
958
969
  function Unit.prototype.hideAbility(self, abilityId, flag)
959
970
  BlzUnitHideAbility(self.handle, abilityId, flag)
@@ -967,6 +978,21 @@ end
967
978
  function Unit.prototype.endAbilityCooldown(self, abilityId)
968
979
  BlzEndUnitAbilityCooldown(self.handle, abilityId)
969
980
  end
981
+ function Unit.prototype.interruptMovement(self)
982
+ local handle = self.handle
983
+ unitDisableAbility(
984
+ handle,
985
+ fourCC("Amov"),
986
+ true,
987
+ false
988
+ )
989
+ unitDisableAbility(
990
+ handle,
991
+ fourCC("Amov"),
992
+ false,
993
+ false
994
+ )
995
+ end
970
996
  function Unit.prototype.interruptAttack(self)
971
997
  unitInterruptAttack(self.handle)
972
998
  end
@@ -1240,7 +1266,7 @@ __TS__SetDescriptor(
1240
1266
  Unit.prototype,
1241
1267
  "isIllusion",
1242
1268
  {get = function(self)
1243
- return isUnitIllusion(self.handle)
1269
+ return IsUnitIllusion(self.handle)
1244
1270
  end},
1245
1271
  true
1246
1272
  )
@@ -1463,13 +1489,13 @@ __TS__SetDescriptor(
1463
1489
  end,
1464
1490
  set = function(self, isTeamGlowVisible)
1465
1491
  BlzShowUnitTeamGlow(self.handle, isTeamGlowVisible)
1466
- local ____temp_6
1492
+ local ____temp_7
1467
1493
  if not isTeamGlowVisible then
1468
- ____temp_6 = true
1494
+ ____temp_7 = true
1469
1495
  else
1470
- ____temp_6 = nil
1496
+ ____temp_7 = nil
1471
1497
  end
1472
- self[106] = ____temp_6
1498
+ self[106] = ____temp_7
1473
1499
  end
1474
1500
  },
1475
1501
  true
@@ -2216,25 +2242,25 @@ Unit.onTargetCast = dispatchId(__TS__New(
2216
2242
  InitializingEvent,
2217
2243
  function(event)
2218
2244
  local function listener(unit, id)
2219
- local ____GetSpellTargetUnit_result_9
2245
+ local ____GetSpellTargetUnit_result_10
2220
2246
  if GetSpellTargetUnit() then
2221
- ____GetSpellTargetUnit_result_9 = ____exports.Unit:of(GetSpellTargetUnit())
2247
+ ____GetSpellTargetUnit_result_10 = ____exports.Unit:of(GetSpellTargetUnit())
2222
2248
  else
2223
- local ____GetSpellTargetItem_result_8
2249
+ local ____GetSpellTargetItem_result_9
2224
2250
  if GetSpellTargetItem() then
2225
- ____GetSpellTargetItem_result_8 = Item:of(GetSpellTargetItem())
2251
+ ____GetSpellTargetItem_result_9 = Item:of(GetSpellTargetItem())
2226
2252
  else
2227
- local ____GetSpellTargetDestructable_result_7
2253
+ local ____GetSpellTargetDestructable_result_8
2228
2254
  if GetSpellTargetDestructable() then
2229
- ____GetSpellTargetDestructable_result_7 = Destructable:of(GetSpellTargetDestructable())
2255
+ ____GetSpellTargetDestructable_result_8 = Destructable:of(GetSpellTargetDestructable())
2230
2256
  else
2231
- ____GetSpellTargetDestructable_result_7 = nil
2257
+ ____GetSpellTargetDestructable_result_8 = nil
2232
2258
  end
2233
- ____GetSpellTargetItem_result_8 = ____GetSpellTargetDestructable_result_7
2259
+ ____GetSpellTargetItem_result_9 = ____GetSpellTargetDestructable_result_8
2234
2260
  end
2235
- ____GetSpellTargetUnit_result_9 = ____GetSpellTargetItem_result_8
2261
+ ____GetSpellTargetUnit_result_10 = ____GetSpellTargetItem_result_9
2236
2262
  end
2237
- local target = ____GetSpellTargetUnit_result_9
2263
+ local target = ____GetSpellTargetUnit_result_10
2238
2264
  if target then
2239
2265
  invoke(event, unit, id, target)
2240
2266
  end
@@ -2457,12 +2483,7 @@ Unit.onDamaging = (function()
2457
2483
  preventRetaliation = damagingEventPreventRetaliation
2458
2484
  }
2459
2485
  if data.isAttack and source then
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
2461
- if weapon == -1 then
2462
- local targetsAllowed = BlzGetUnitWeaponIntegerField(source.handle, UNIT_WEAPON_IF_ATTACK_TARGETS_ALLOWED, 0)
2463
- weapon = 0
2464
- end
2465
- data.weapon = assert(source.weapons[weapon + 1])
2486
+ data.weapon = source:chooseWeapon(target)
2466
2487
  end
2467
2488
  if not data.isAttack or not source or not source._attackHandlers then
2468
2489
  invoke(
@@ -2657,10 +2678,14 @@ Unit.itemPickedUpEvent = __TS__New(
2657
2678
  ____exports.UnitTriggerEvent,
2658
2679
  EVENT_PLAYER_UNIT_PICKUP_ITEM,
2659
2680
  function()
2660
- local unit = getTriggerUnit()
2661
- local item = getManipulatedItem()
2662
- if getUnitTypeId(unit) ~= dummyUnitId and not (ignoreEventsItems[item] ~= nil) then
2663
- return ____exports.Unit:of(unit), Item:of(item)
2681
+ local unitHandle = getTriggerUnit()
2682
+ local itemHandle = getManipulatedItem()
2683
+ if getUnitTypeId(unitHandle) ~= dummyUnitId and not (ignoreEventsItems[itemHandle] ~= nil) then
2684
+ local unit = ____exports.Unit:of(unitHandle)
2685
+ local item = Item:of(itemHandle)
2686
+ if item.owner ~= unit then
2687
+ return unit, item
2688
+ end
2664
2689
  end
2665
2690
  return IgnoreEvent
2666
2691
  end
@@ -2680,7 +2705,7 @@ Unit.itemUsedEvent = __TS__New(
2680
2705
  Unit.itemStackedEvent = __TS__New(
2681
2706
  ____exports.UnitTriggerEvent,
2682
2707
  EVENT_PLAYER_UNIT_STACK_ITEM,
2683
- function() return ____exports.Unit:of(getTriggerUnit()), Item:of(getManipulatedItem()) end
2708
+ function() return ____exports.Unit:of(getTriggerUnit()), Item:of(BlzGetStackingItemTarget()), Item:of(BlzGetStackingItemSource()) end
2684
2709
  )
2685
2710
  __TS__ObjectDefineProperty(
2686
2711
  Unit,
@@ -0,0 +1,11 @@
1
+ /** @noSelfInFile */
2
+ export declare const enum ArmorType {
3
+ LIGHT = 0,
4
+ MEDIUM = 1,
5
+ HEAVY = 2,
6
+ FORTIFIED = 3,
7
+ NORMAL = 4,
8
+ HERO = 5,
9
+ DIVINE = 6,
10
+ UNARMORED = 7
11
+ }