warscript 0.0.1-dev.d842bb6 → 0.0.1-dev.dd8349d

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 (117) hide show
  1. package/attributes.d.ts +5 -0
  2. package/attributes.lua +8 -1
  3. package/config.d.ts +5 -0
  4. package/config.lua +10 -0
  5. package/core/types/effect.d.ts +1 -3
  6. package/core/types/effect.lua +26 -29
  7. package/core/types/order.d.ts +1 -0
  8. package/core/types/order.lua +11 -1
  9. package/core/types/sound.d.ts +17 -25
  10. package/core/types/sound.lua +91 -46
  11. package/core/types/timer.d.ts +6 -7
  12. package/core/types/timer.lua +18 -21
  13. package/core/util.lua +6 -1
  14. package/decl/native.d.ts +840 -786
  15. package/engine/behaviour/ability/apply-unit-behavior.lua +1 -0
  16. package/engine/behaviour/ability/damage.d.ts +9 -3
  17. package/engine/behaviour/ability/damage.lua +26 -38
  18. package/engine/behaviour/ability/emulate-impact.lua +7 -0
  19. package/engine/behaviour/ability.d.ts +5 -1
  20. package/engine/behaviour/ability.lua +18 -4
  21. package/engine/behaviour/unit.d.ts +16 -0
  22. package/engine/behaviour/unit.lua +109 -4
  23. package/engine/buff.d.ts +13 -8
  24. package/engine/buff.lua +81 -50
  25. package/engine/internal/ability.d.ts +2 -0
  26. package/engine/internal/ability.lua +7 -0
  27. package/engine/internal/item/ability.lua +12 -10
  28. package/engine/internal/item.d.ts +4 -2
  29. package/engine/internal/item.lua +71 -3
  30. package/engine/internal/mechanics/ability-duration.lua +1 -1
  31. package/engine/internal/misc/damage-metadata-by-target.d.ts +2 -0
  32. package/engine/internal/misc/damage-metadata-by-target.lua +5 -0
  33. package/engine/internal/unit/allowed-targets.d.ts +1 -1
  34. package/engine/internal/unit/allowed-targets.lua +9 -1
  35. package/engine/internal/unit+damage.d.ts +2 -11
  36. package/engine/internal/unit+damage.lua +10 -14
  37. package/engine/internal/unit+spellSteal.lua +1 -2
  38. package/engine/internal/unit-missile-launch.lua +1 -1
  39. package/engine/internal/unit.d.ts +26 -4
  40. package/engine/internal/unit.lua +169 -37
  41. package/engine/object-data/auxiliary/attachment-preset.d.ts +7 -2
  42. package/engine/object-data/auxiliary/attachment-preset.lua +4 -3
  43. package/engine/object-data/auxiliary/attack-type.d.ts +7 -8
  44. package/engine/object-data/auxiliary/attack-type.lua +42 -0
  45. package/engine/object-data/auxiliary/movement-type.d.ts +7 -7
  46. package/engine/object-data/auxiliary/movement-type.lua +22 -0
  47. package/engine/object-data/auxiliary/sound-eax.d.ts +10 -0
  48. package/engine/object-data/auxiliary/sound-eax.lua +2 -0
  49. package/engine/object-data/auxiliary/tech-tree-dependency.d.ts +1 -1
  50. package/engine/object-data/auxiliary/unit-attribute.d.ts +6 -0
  51. package/engine/object-data/auxiliary/unit-attribute.lua +9 -0
  52. package/engine/object-data/entry/ability-type/berserk.d.ts +2 -0
  53. package/engine/object-data/entry/ability-type/berserk.lua +13 -0
  54. package/engine/object-data/entry/ability-type/blank-configurable.lua +0 -9
  55. package/engine/object-data/entry/ability-type/carrion-swarm.d.ts +14 -0
  56. package/engine/object-data/entry/ability-type/carrion-swarm.lua +65 -0
  57. package/engine/object-data/entry/ability-type/curse.lua +2 -2
  58. package/engine/object-data/entry/ability-type/disease-cloud.lua +2 -2
  59. package/engine/object-data/entry/ability-type/engineering-upgrade.lua +2 -2
  60. package/engine/object-data/entry/ability-type/ensnare.d.ts +12 -0
  61. package/engine/object-data/entry/ability-type/ensnare.lua +52 -0
  62. package/engine/object-data/entry/ability-type/feral-spirit.lua +2 -2
  63. package/engine/object-data/entry/ability-type/permanent-invisibility.d.ts +8 -0
  64. package/engine/object-data/entry/ability-type/permanent-invisibility.lua +26 -0
  65. package/engine/object-data/entry/ability-type/phase-shift.d.ts +10 -0
  66. package/engine/object-data/entry/ability-type/phase-shift.lua +39 -0
  67. package/engine/object-data/entry/ability-type/phoenix-morph.lua +4 -4
  68. package/engine/object-data/entry/ability-type/raise-dead.d.ts +17 -0
  69. package/engine/object-data/entry/ability-type/raise-dead.lua +78 -0
  70. package/engine/object-data/entry/ability-type/shock-wave.d.ts +4 -0
  71. package/engine/object-data/entry/ability-type/shock-wave.lua +26 -0
  72. package/engine/object-data/entry/ability-type/slow-poison.d.ts +10 -0
  73. package/engine/object-data/entry/ability-type/slow-poison.lua +58 -0
  74. package/engine/object-data/entry/ability-type/summon-quilbeast.lua +2 -2
  75. package/engine/object-data/entry/ability-type/summon-water-elemental.lua +2 -2
  76. package/engine/object-data/entry/ability-type/web.d.ts +12 -0
  77. package/engine/object-data/entry/ability-type/web.lua +52 -0
  78. package/engine/object-data/entry/ability-type.d.ts +19 -17
  79. package/engine/object-data/entry/ability-type.lua +81 -21
  80. package/engine/object-data/entry/buff-type/applicable.lua +9 -4
  81. package/engine/object-data/entry/buff-type.d.ts +6 -12
  82. package/engine/object-data/entry/buff-type.lua +13 -29
  83. package/engine/object-data/entry/destructible-type.d.ts +1 -1
  84. package/engine/object-data/entry/item-type.d.ts +1 -1
  85. package/engine/object-data/entry/item-type.lua +4 -4
  86. package/engine/object-data/entry/lightning-type.d.ts +1 -1
  87. package/engine/object-data/entry/sound-preset.d.ts +33 -0
  88. package/engine/object-data/entry/sound-preset.lua +140 -0
  89. package/engine/object-data/entry/unit-type.d.ts +10 -3
  90. package/engine/object-data/entry/unit-type.lua +155 -92
  91. package/engine/object-data/entry/upgrade.d.ts +1 -1
  92. package/engine/object-data/entry/upgrade.lua +4 -4
  93. package/engine/object-data/entry.d.ts +16 -14
  94. package/engine/object-data/entry.lua +60 -32
  95. package/engine/object-field/ability.d.ts +1 -1
  96. package/engine/object-field/unit.d.ts +46 -3
  97. package/engine/object-field/unit.lua +173 -7
  98. package/engine/object-field.d.ts +9 -1
  99. package/engine/object-field.lua +158 -76
  100. package/engine/standard/entries/buff-type.d.ts +3 -0
  101. package/engine/standard/entries/buff-type.lua +3 -0
  102. package/engine/standard/entries/sound-preset.d.ts +10 -0
  103. package/engine/standard/entries/sound-preset.lua +10 -0
  104. package/objutil/buff.lua +1 -2
  105. package/objutil/unit.lua +8 -0
  106. package/package.json +2 -2
  107. package/utility/arrays.d.ts +1 -0
  108. package/utility/arrays.lua +3 -0
  109. package/utility/functions.d.ts +1 -0
  110. package/utility/functions.lua +1 -0
  111. package/utility/linked-set.d.ts +1 -0
  112. package/utility/linked-set.lua +3 -0
  113. package/utility/lua-maps.d.ts +3 -0
  114. package/utility/lua-maps.lua +16 -0
  115. package/utility/lua-sets.d.ts +1 -0
  116. package/utility/lua-sets.lua +3 -0
  117. package/utility/reflection.lua +11 -7
@@ -7,21 +7,14 @@ local ____player = require("core.types.player")
7
7
  local Player = ____player.Player
8
8
  local ____dummy = require("objutil.dummy")
9
9
  local dummyUnitId = ____dummy.dummyUnitId
10
+ local ____attack_2Dtype = require("engine.object-data.auxiliary.attack-type")
11
+ local attackTypeToNative = ____attack_2Dtype.attackTypeToNative
12
+ local ____damage_2Dmetadata_2Dby_2Dtarget = require("engine.internal.misc.damage-metadata-by-target")
13
+ local damageMetadataByTarget = ____damage_2Dmetadata_2Dby_2Dtarget.damageMetadataByTarget
10
14
  local createUnit = CreateUnit
11
15
  local getOwningPlayer = GetOwningPlayer
12
16
  local showUnit = ShowUnit
13
17
  local unitDamageTarget = UnitDamageTarget
14
- ____exports.AttackType = {}
15
- local AttackType = ____exports.AttackType
16
- do
17
- AttackType.SPELL = ATTACK_TYPE_NORMAL
18
- AttackType.NORMAL = ATTACK_TYPE_MELEE
19
- AttackType.PIERCE = ATTACK_TYPE_PIERCE
20
- AttackType.SIEGE = ATTACK_TYPE_SIEGE
21
- AttackType.MAGIC = ATTACK_TYPE_MAGIC
22
- AttackType.CHAOS = ATTACK_TYPE_CHAOS
23
- AttackType.HERO = ATTACK_TYPE_HERO
24
- end
25
18
  ____exports.DamageType = {}
26
19
  local DamageType = ____exports.DamageType
27
20
  do
@@ -88,7 +81,7 @@ for ____, player in ipairs(Player.all) do
88
81
  showUnit(dummy, false)
89
82
  dummies[player] = dummy
90
83
  end
91
- Unit.prototype.damageTarget = function(self, target, amount, attack, ranged, attackType, damageType, weaponType)
84
+ Unit.prototype.damageTarget = function(self, target, amount, attack, ranged, attackType, damageType, weaponType, metadata)
92
85
  if attack == nil then
93
86
  attack = false
94
87
  end
@@ -96,7 +89,7 @@ Unit.prototype.damageTarget = function(self, target, amount, attack, ranged, att
96
89
  ranged = false
97
90
  end
98
91
  if attackType == nil then
99
- attackType = ____exports.AttackType.SPELL
92
+ attackType = 0
100
93
  end
101
94
  if damageType == nil then
102
95
  damageType = ____exports.DamageType.MAGIC
@@ -109,13 +102,16 @@ Unit.prototype.damageTarget = function(self, target, amount, attack, ranged, att
109
102
  if not getOwningPlayer(handle) then
110
103
  handle = dummies[__TS__InstanceOf(target, Unit) and target.owner or (self._owner or Player.neutralAggressive)]
111
104
  end
105
+ if __TS__InstanceOf(target, Unit) then
106
+ damageMetadataByTarget[target] = metadata
107
+ end
112
108
  return unitDamageTarget(
113
109
  handle,
114
110
  targetHandle,
115
111
  amount,
116
112
  attack,
117
113
  ranged,
118
- attackType,
114
+ attackTypeToNative(attackType),
119
115
  damageType,
120
116
  weaponType
121
117
  )
@@ -6,7 +6,6 @@ local ____exports = {}
6
6
  local ____unit = require("engine.internal.unit")
7
7
  local Unit = ____unit.Unit
8
8
  local ____unit_2Bdamage = require("engine.internal.unit+damage")
9
- local AttackType = ____unit_2Bdamage.AttackType
10
9
  local DamageType = ____unit_2Bdamage.DamageType
11
10
  local ____event = require("event")
12
11
  local Event = ____event.Event
@@ -33,7 +32,7 @@ local spellStealEventStack = {}
33
32
  Unit.onDamaging:addListener(function(source, target, event)
34
33
  if event.amount == 0 and source ~= nil then
35
34
  local count = countByUnit[source] or 0
36
- if count > 0 and event.attackType == AttackType.SPELL then
35
+ if count > 0 and event.attackType == 0 then
37
36
  if event.damageType == DamageType.UNKNOWN then
38
37
  spellStealEventStack[#spellStealEventStack + 1] = {
39
38
  sourceBuffIds = source.buffIds,
@@ -44,7 +44,7 @@ local function timerCallback(source, target)
44
44
  Event.invoke(autoAttackFinishEvent, source, target)
45
45
  end
46
46
  Unit.autoAttackStartEvent:addListener(function(source, target)
47
- local attackPoint = source.weapons[1].impactDelay
47
+ local attackPoint = (source:chooseWeapon(target) or source.firstWeapon).impactDelay
48
48
  local timer = Timer:simple(attackPoint, timerCallback, source, target)
49
49
  eventTimerByUnit[source] = timer
50
50
  end)
@@ -11,6 +11,10 @@ import { Ability, UnitAbility } from "./ability";
11
11
  import { Widget } from "../../core/types/widget";
12
12
  import type { UnitTypeId } from "../object-data/entry/unit-type";
13
13
  import { CombatClassification, CombatClassifications } from "../object-data/auxiliary/combat-classification";
14
+ import { MovementType } from "../object-data/auxiliary/movement-type";
15
+ import { UnitAttribute } from "../object-data/auxiliary/unit-attribute";
16
+ import { AttackType } from "../object-data/auxiliary/attack-type";
17
+ import { AttributesHolder } from "../../attributes";
14
18
  export type UnitClassification = junittype;
15
19
  export declare namespace UnitClassification {
16
20
  const STRUCTURE: junittype;
@@ -19,6 +23,7 @@ export declare namespace UnitClassification {
19
23
  const GROUND: junittype;
20
24
  const SUMMONED: junittype;
21
25
  const MECHANICAL: junittype;
26
+ const WORKER: junittype;
22
27
  const ANCIENT: junittype;
23
28
  const SUICIDAL: junittype;
24
29
  const TAUREN: junittype;
@@ -36,15 +41,18 @@ type AbilityDispatcherTable<T extends any[] = []> = {
36
41
  readonly [id: number]: Event<[Unit, Ability, ...T]>;
37
42
  };
38
43
  type AbilityEventDispatcher<T extends any[] = []> = Event<[Unit, Ability, ...T]> & AbilityDispatcherTable<T>;
39
- export interface DamagingEvent {
44
+ export interface DamagingEvent extends AttributesHolder {
40
45
  amount: number;
41
- attackType: jattacktype;
46
+ attackType: AttackType;
42
47
  damageType: jdamagetype;
43
48
  weaponType: jweapontype;
49
+ metadata: unknown;
44
50
  readonly isAttack: boolean;
45
51
  readonly originalAmount: number;
52
+ readonly originalMetadata: unknown;
53
+ preventRetaliation(this: DamagingEvent): void;
46
54
  }
47
- export type DamageEvent = DamagingEvent & {
55
+ export type DamageEvent = Omit<DamagingEvent, "preventRetaliation"> & {
48
56
  preventDeath<P extends any[]>(this: DamageEvent, callback: (this: void, ...parameters: P) => any, ...parameters: P): void;
49
57
  };
50
58
  export type AttackDamageEvent = DamagingEvent & {
@@ -76,6 +84,8 @@ export declare class UnitWeapon {
76
84
  set cooldown(cooldown: number);
77
85
  get damage(): [minimumDamage: number, maximumDamage: number];
78
86
  set damage([minimumDamage, maximumDamage]: [number, number]);
87
+ get allowedTargetCombatClassifications(): CombatClassifications;
88
+ set allowedTargetCombatClassifications(allowedTargetCombatClassifications: CombatClassifications);
79
89
  get damageBase(): number;
80
90
  set damageBase(damageBase: number);
81
91
  get damageDiceCount(): number;
@@ -100,7 +110,9 @@ declare const enum UnitPropertyKey {
100
110
  DELAY_HEALTH_CHECKS_COUNTER = 103,
101
111
  DELAY_HEALTH_CHECKS_HEALTH_BONUS = 104,
102
112
  PREVENT_DEATH_HEALTH_BONUS = 105,
103
- IS_TEAM_GLOW_HIDDEN = 106
113
+ IS_TEAM_GLOW_HIDDEN = 106,
114
+ LAST_X = 107,
115
+ LAST_Y = 108
104
116
  }
105
117
  export type UnitSyncId = number & {
106
118
  readonly __unitSyncId: unique symbol;
@@ -113,6 +125,8 @@ export declare class Unit extends Handle<junit> {
113
125
  private [UnitPropertyKey.DELAY_HEALTH_CHECKS_HEALTH_BONUS]?;
114
126
  private [UnitPropertyKey.PREVENT_DEATH_HEALTH_BONUS]?;
115
127
  private [UnitPropertyKey.IS_TEAM_GLOW_HIDDEN]?;
128
+ private [UnitPropertyKey.LAST_X]?;
129
+ private [UnitPropertyKey.LAST_Y]?;
116
130
  private _owner?;
117
131
  private _timeScale?;
118
132
  private events?;
@@ -148,14 +162,18 @@ export declare class Unit extends Handle<junit> {
148
162
  isEnemyOf(unit: Unit): boolean;
149
163
  playAnimation(animation: string, rarity?: jraritycontrol): void;
150
164
  playAnimation(animation: number): void;
165
+ resetAnimation(): void;
151
166
  queueAnimation(animation: string): void;
152
167
  get weapons(): [UnitWeapon, UnitWeapon];
153
168
  get firstWeapon(): UnitWeapon;
154
169
  get secondWeapon(): UnitWeapon;
170
+ chooseWeapon(target: Unit): UnitWeapon | undefined;
155
171
  get level(): number;
156
172
  set level(v: number);
157
173
  get xp(): number;
158
174
  set xp(v: number);
175
+ get primaryAttribute(): UnitAttribute;
176
+ set primaryAttribute(primaryAttribute: UnitAttribute);
159
177
  get strengthBase(): number;
160
178
  set strengthBase(strengthBase: number);
161
179
  get strengthBonus(): number;
@@ -230,6 +248,8 @@ export declare class Unit extends Handle<junit> {
230
248
  set timeScale(v: number);
231
249
  get collisionSize(): number;
232
250
  get pathingCollisionRange(): number;
251
+ get movementType(): MovementType;
252
+ set movementType(movementType: MovementType);
233
253
  set pathing(v: boolean);
234
254
  isSelected(player: Player): boolean;
235
255
  explode(): void;
@@ -280,6 +300,7 @@ export declare class Unit extends Handle<junit> {
280
300
  get onUnitInRange(): Record<number, Event<[Unit]>>;
281
301
  get onManaEqual(): Record<number, Event<[Unit, number]>>;
282
302
  get manaEvent(): Record<Operator, Record<number, Event<[Unit]>>>;
303
+ get targetAcquiredEvent(): Event;
283
304
  get onSelect(): Event;
284
305
  get onDeselect(): Event;
285
306
  get onImmediateOrder(): Event<[number]>;
@@ -333,6 +354,7 @@ export declare class Unit extends Handle<junit> {
333
354
  static itemPickedUpEvent: UnitTriggerEvent<[Item]>;
334
355
  static itemUsedEvent: UnitTriggerEvent<[Item]>;
335
356
  static itemStackedEvent: UnitTriggerEvent<[Item]>;
357
+ static get itemChargesChangedEvent(): Event<[unit: Unit, item: Item]>;
336
358
  static get itemUseOrderEvent(): Event<[unit: Unit, item: Item]>;
337
359
  static get itemMoveOrderEvent(): Event<[
338
360
  unit: Unit,
@@ -53,12 +53,17 @@ local ____math = require("math")
53
53
  local min = ____math.min
54
54
  local ____ignore_2Devents_2Ditems = require("engine.internal.unit.ignore-events-items")
55
55
  local ignoreEventsItems = ____ignore_2Devents_2Ditems.ignoreEventsItems
56
+ local ____attack_2Dtype = require("engine.object-data.auxiliary.attack-type")
57
+ local attackTypeToNative = ____attack_2Dtype.attackTypeToNative
58
+ local nativeToAttackType = ____attack_2Dtype.nativeToAttackType
59
+ local ____damage_2Dmetadata_2Dby_2Dtarget = require("engine.internal.misc.damage-metadata-by-target")
60
+ local damageMetadataByTarget = ____damage_2Dmetadata_2Dby_2Dtarget.damageMetadataByTarget
61
+ local ____attributes = require("attributes")
62
+ local isAttribute = ____attributes.isAttribute
56
63
  local match = string.match
57
64
  local ____tostring = _G.tostring
58
65
  local setUnitAnimation = SetUnitAnimation
59
- local setUnitAnimationWithRarity = SetUnitAnimationWithRarity
60
66
  local setUnitAnimationByIndex = SetUnitAnimationByIndex
61
- local queueUnitAnimation = QueueUnitAnimation
62
67
  local getUnitIntegerField = BlzGetUnitIntegerField
63
68
  local getUnitRealField = BlzGetUnitRealField
64
69
  local getHeroStr = GetHeroStr
@@ -80,7 +85,6 @@ local getHandleId = GetHandleId
80
85
  local getUnitCurrentOrder = GetUnitCurrentOrder
81
86
  local createUnit = CreateUnit
82
87
  local killUnit = KillUnit
83
- local setUnitExploded = SetUnitExploded
84
88
  local removeUnit = RemoveUnit
85
89
  local getUnitTypeId = GetUnitTypeId
86
90
  local isHeroUnitId = IsHeroUnitId
@@ -96,8 +100,6 @@ local getSpellTargetItem = GetSpellTargetItem
96
100
  local getSpellTargetDestructable = GetSpellTargetDestructable
97
101
  local isUnitInRangeXY = IsUnitInRangeXY
98
102
  local isUnitInRange = IsUnitInRange
99
- local setResourceAmount = SetResourceAmount
100
- local getResourceAmount = GetResourceAmount
101
103
  local getUnitWeaponRealField = BlzGetUnitWeaponRealField
102
104
  local setUnitWeaponRealField = BlzSetUnitWeaponRealField
103
105
  local getUnitWeaponStringField = BlzGetUnitWeaponStringField
@@ -128,8 +130,6 @@ local isUnitType = IsUnitType
128
130
  local isUnitAlly = IsUnitAlly
129
131
  local isUnitEnemy = IsUnitEnemy
130
132
  local getOwningPlayer = GetOwningPlayer
131
- local setUnitColor = SetUnitColor
132
- local showUnitTeamGlow = BlzShowUnitTeamGlow
133
133
  ____exports.UnitClassification = {}
134
134
  local UnitClassification = ____exports.UnitClassification
135
135
  do
@@ -139,6 +139,7 @@ do
139
139
  UnitClassification.GROUND = UNIT_TYPE_GROUND
140
140
  UnitClassification.SUMMONED = UNIT_TYPE_SUMMONED
141
141
  UnitClassification.MECHANICAL = UNIT_TYPE_MECHANICAL
142
+ UnitClassification.WORKER = UNIT_TYPE_PEON
142
143
  UnitClassification.ANCIENT = UNIT_TYPE_ANCIENT
143
144
  UnitClassification.SUICIDAL = UNIT_TYPE_SAPPER
144
145
  UnitClassification.TAUREN = UNIT_TYPE_TAUREN
@@ -346,6 +347,9 @@ local function dispatchAbility(event)
346
347
  }
347
348
  )
348
349
  end
350
+ local function damagingEventPreventRetaliation(self)
351
+ self[0] = true
352
+ end
349
353
  local function damageEventPreventDeath(self, callback, ...)
350
354
  if self[0] ~= nil then
351
355
  return
@@ -357,7 +361,14 @@ local function damageEventPreventDeath(self, callback, ...)
357
361
  rawset(self, 1 + i, (select(i, ...)))
358
362
  end
359
363
  end
360
- local damageSetters = {amount = BlzSetEventDamage, attackType = BlzSetEventAttackType, damageType = BlzSetEventDamageType, weaponType = BlzSetEventWeaponType}
364
+ local damageSetters = {
365
+ amount = BlzSetEventDamage,
366
+ attackType = function(attackType)
367
+ return BlzSetEventAttackType(attackTypeToNative(attackType))
368
+ end,
369
+ damageType = BlzSetEventDamageType,
370
+ weaponType = BlzSetEventWeaponType
371
+ }
361
372
  local jlimitopByOperator = {
362
373
  [0] = LESS_THAN_OR_EQUAL,
363
374
  [1] = LESS_THAN_OR_EQUAL,
@@ -435,6 +446,19 @@ __TS__SetDescriptor(
435
446
  },
436
447
  true
437
448
  )
449
+ __TS__SetDescriptor(
450
+ UnitWeapon.prototype,
451
+ "allowedTargetCombatClassifications",
452
+ {
453
+ get = function(self)
454
+ return BlzGetUnitWeaponIntegerField(self.unit.handle, UNIT_WEAPON_IF_ATTACK_TARGETS_ALLOWED, self.index)
455
+ end,
456
+ set = function(self, allowedTargetCombatClassifications)
457
+ BlzSetUnitWeaponIntegerField(self.unit.handle, UNIT_WEAPON_IF_ATTACK_TARGETS_ALLOWED, self.index, allowedTargetCombatClassifications)
458
+ end
459
+ },
460
+ true
461
+ )
438
462
  __TS__SetDescriptor(
439
463
  UnitWeapon.prototype,
440
464
  "damageBase",
@@ -639,7 +663,8 @@ local function delayHealthChecksCallback(unit)
639
663
  end
640
664
  end
641
665
  local nextSyncId = 1
642
- local unitBySyncId = setmetatable({}, {__mode = "k"})
666
+ local unitBySyncId = setmetatable({}, {__mode = "v"})
667
+ local damagingEventByTarget = setmetatable({}, {__mode = "k"})
643
668
  ____exports.Unit = __TS__Class()
644
669
  local Unit = ____exports.Unit
645
670
  Unit.name = "Unit"
@@ -680,6 +705,8 @@ function Unit.prototype.getEvent(self, event, collector)
680
705
  end
681
706
  function Unit.prototype.onDestroy(self)
682
707
  local handle = self.handle
708
+ self[107] = getUnitX(handle)
709
+ self[108] = getUnitY(handle)
683
710
  if not self._owner then
684
711
  self._owner = Player:of(getOwningPlayer(handle))
685
712
  end
@@ -790,13 +817,25 @@ function Unit.prototype.playAnimation(self, animation, rarity)
790
817
  if type(animation) == "number" then
791
818
  setUnitAnimationByIndex(self.handle, animation)
792
819
  elseif rarity then
793
- setUnitAnimationWithRarity(self.handle, animation, rarity)
820
+ SetUnitAnimationWithRarity(self.handle, animation, rarity)
794
821
  else
795
822
  setUnitAnimation(self.handle, animation)
796
823
  end
797
824
  end
825
+ function Unit.prototype.resetAnimation(self)
826
+ ResetUnitAnimation(self.handle)
827
+ end
798
828
  function Unit.prototype.queueAnimation(self, animation)
799
- queueUnitAnimation(self.handle, animation)
829
+ QueueUnitAnimation(self.handle, animation)
830
+ end
831
+ function Unit.prototype.chooseWeapon(self, target)
832
+ if target:isAllowedTarget(self, self.firstWeapon.allowedTargetCombatClassifications) then
833
+ return self.firstWeapon
834
+ end
835
+ if target:isAllowedTarget(target, self.secondWeapon.allowedTargetCombatClassifications) then
836
+ return self.secondWeapon
837
+ end
838
+ return nil
800
839
  end
801
840
  function Unit.prototype.delayHealthChecks(self)
802
841
  self[103] = (self[103] or 0) + 1
@@ -809,7 +848,7 @@ function Unit.prototype.isSelected(self, player)
809
848
  return IsUnitSelected(self.handle, player.handle)
810
849
  end
811
850
  function Unit.prototype.explode(self)
812
- setUnitExploded(self.handle, true)
851
+ SetUnitExploded(self.handle, true)
813
852
  killUnit(self.handle)
814
853
  end
815
854
  function Unit.prototype.kill(self)
@@ -1286,6 +1325,19 @@ __TS__SetDescriptor(
1286
1325
  },
1287
1326
  true
1288
1327
  )
1328
+ __TS__SetDescriptor(
1329
+ Unit.prototype,
1330
+ "primaryAttribute",
1331
+ {
1332
+ get = function(self)
1333
+ return getUnitIntegerField(self.handle, UNIT_IF_PRIMARY_ATTRIBUTE)
1334
+ end,
1335
+ set = function(self, primaryAttribute)
1336
+ setUnitIntegerField(self.handle, UNIT_IF_PRIMARY_ATTRIBUTE, primaryAttribute)
1337
+ end
1338
+ },
1339
+ true
1340
+ )
1289
1341
  __TS__SetDescriptor(
1290
1342
  Unit.prototype,
1291
1343
  "strengthBase",
@@ -1410,7 +1462,7 @@ __TS__SetDescriptor(
1410
1462
  return not self[106]
1411
1463
  end,
1412
1464
  set = function(self, isTeamGlowVisible)
1413
- showUnitTeamGlow(self.handle, isTeamGlowVisible)
1465
+ BlzShowUnitTeamGlow(self.handle, isTeamGlowVisible)
1414
1466
  local ____temp_6
1415
1467
  if not isTeamGlowVisible then
1416
1468
  ____temp_6 = true
@@ -1426,9 +1478,9 @@ __TS__SetDescriptor(
1426
1478
  Unit.prototype,
1427
1479
  "color",
1428
1480
  {set = function(self, color)
1429
- setUnitColor(self.handle, color.handle)
1481
+ SetUnitColor(self.handle, color.handle)
1430
1482
  if self[106] then
1431
- showUnitTeamGlow(self.handle, false)
1483
+ BlzShowUnitTeamGlow(self.handle, false)
1432
1484
  end
1433
1485
  end},
1434
1486
  true
@@ -1597,7 +1649,7 @@ __TS__SetDescriptor(
1597
1649
  "x",
1598
1650
  {
1599
1651
  get = function(self)
1600
- return getUnitX(self.handle)
1652
+ return self[107] or getUnitX(self.handle)
1601
1653
  end,
1602
1654
  set = function(self, v)
1603
1655
  SetUnitX(self.handle, v)
@@ -1610,7 +1662,7 @@ __TS__SetDescriptor(
1610
1662
  "y",
1611
1663
  {
1612
1664
  get = function(self)
1613
- return getUnitY(self.handle)
1665
+ return self[108] or getUnitY(self.handle)
1614
1666
  end,
1615
1667
  set = function(self, v)
1616
1668
  SetUnitY(self.handle, v)
@@ -1696,10 +1748,10 @@ __TS__SetDescriptor(
1696
1748
  "gold",
1697
1749
  {
1698
1750
  get = function(self)
1699
- return getResourceAmount(self.handle)
1751
+ return GetResourceAmount(self.handle)
1700
1752
  end,
1701
1753
  set = function(self, gold)
1702
- setResourceAmount(self.handle, gold)
1754
+ SetResourceAmount(self.handle, gold)
1703
1755
  end
1704
1756
  },
1705
1757
  true
@@ -1827,6 +1879,19 @@ __TS__SetDescriptor(
1827
1879
  end},
1828
1880
  true
1829
1881
  )
1882
+ __TS__SetDescriptor(
1883
+ Unit.prototype,
1884
+ "movementType",
1885
+ {
1886
+ get = function(self)
1887
+ return getUnitIntegerField(self.handle, UNIT_IF_MOVE_TYPE)
1888
+ end,
1889
+ set = function(self, movementType)
1890
+ setUnitIntegerField(self.handle, UNIT_IF_MOVE_TYPE, movementType)
1891
+ end
1892
+ },
1893
+ true
1894
+ )
1830
1895
  __TS__SetDescriptor(
1831
1896
  Unit.prototype,
1832
1897
  "pathing",
@@ -2008,6 +2073,14 @@ __TS__SetDescriptor(
2008
2073
  end},
2009
2074
  true
2010
2075
  )
2076
+ __TS__SetDescriptor(
2077
+ Unit.prototype,
2078
+ "targetAcquiredEvent",
2079
+ {get = function(self)
2080
+ return self:getEvent(EVENT_UNIT_ACQUIRED_TARGET)
2081
+ end},
2082
+ true
2083
+ )
2011
2084
  __TS__SetDescriptor(
2012
2085
  Unit.prototype,
2013
2086
  "onSelect",
@@ -2369,13 +2442,19 @@ Unit.onDamaging = (function()
2369
2442
  if source and source.typeId == dummyUnitId then
2370
2443
  source = nil
2371
2444
  end
2372
- local target = BlzGetEventDamageTarget()
2445
+ local target = ____exports.Unit:of(BlzGetEventDamageTarget())
2446
+ local metadata = damageMetadataByTarget[target]
2447
+ damageMetadataByTarget[target] = nil
2373
2448
  local data = {
2374
2449
  amount = GetEventDamage(),
2375
- attackType = BlzGetEventAttackType(),
2450
+ attackType = nativeToAttackType(BlzGetEventAttackType()),
2376
2451
  damageType = BlzGetEventDamageType(),
2377
2452
  weaponType = BlzGetEventWeaponType(),
2378
- isAttack = BlzGetEventIsAttack()
2453
+ metadata = metadata,
2454
+ isAttack = BlzGetEventIsAttack(),
2455
+ originalAmount = GetEventDamage(),
2456
+ originalMetadata = metadata,
2457
+ preventRetaliation = damagingEventPreventRetaliation
2379
2458
  }
2380
2459
  if data.isAttack and source then
2381
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
@@ -2389,18 +2468,36 @@ Unit.onDamaging = (function()
2389
2468
  invoke(
2390
2469
  event,
2391
2470
  source,
2392
- ____exports.Unit:of(target),
2471
+ target,
2393
2472
  setmetatable(
2394
2473
  {},
2395
2474
  {
2396
2475
  __index = data,
2397
2476
  __newindex = function(self, key, value)
2398
- damageSetters[key](value)
2477
+ local damageSetter = damageSetters[key]
2478
+ if damageSetter ~= nil then
2479
+ damageSetter(value)
2480
+ end
2399
2481
  data[key] = value
2400
2482
  end
2401
2483
  }
2402
2484
  )
2403
2485
  )
2486
+ if data[0] and source then
2487
+ local sourceOwner = source.owner.handle
2488
+ data[1] = sourceOwner
2489
+ local targetOwner = target.owner.handle
2490
+ data[2] = targetOwner
2491
+ if not GetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE) then
2492
+ SetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE, true)
2493
+ data[3] = true
2494
+ end
2495
+ if not GetPlayerAlliance(targetOwner, sourceOwner, ALLIANCE_PASSIVE) then
2496
+ SetPlayerAlliance(targetOwner, sourceOwner, ALLIANCE_PASSIVE, true)
2497
+ data[4] = true
2498
+ end
2499
+ end
2500
+ damagingEventByTarget[target] = data
2404
2501
  return
2405
2502
  end
2406
2503
  BlzSetEventDamage(0)
@@ -2408,7 +2505,7 @@ Unit.onDamaging = (function()
2408
2505
  BlzSetEventDamageType(DAMAGE_TYPE_UNKNOWN)
2409
2506
  BlzSetEventWeaponType(WEAPON_TYPE_WHOKNOWS)
2410
2507
  local sourceOwner = source.owner.handle
2411
- local targetOwner = GetOwningPlayer(target)
2508
+ local targetOwner = target.owner.handle
2412
2509
  if not GetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE) then
2413
2510
  SetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE, true)
2414
2511
  Timer:run(function()
@@ -2424,23 +2521,19 @@ Unit.onDamaging = (function()
2424
2521
  for ____, ____value in ipairs(source._attackHandlers) do
2425
2522
  local condition = ____value[1]
2426
2523
  local action = ____value[2]
2427
- if condition(
2428
- source,
2429
- ____exports.Unit:of(target),
2430
- data
2431
- ) then
2524
+ if condition(source, target, data) then
2432
2525
  action(
2433
2526
  source,
2434
- ____exports.Unit:of(target),
2527
+ target,
2435
2528
  setmetatable(
2436
2529
  {fire = function()
2437
2530
  UnitDamageTarget(
2438
2531
  source.handle,
2439
- target,
2532
+ target.handle,
2440
2533
  data.amount,
2441
2534
  true,
2442
2535
  true,
2443
- data.attackType,
2536
+ attackTypeToNative(data.attackType),
2444
2537
  data.damageType,
2445
2538
  data.weaponType
2446
2539
  )
@@ -2467,26 +2560,50 @@ Unit.onDamage = __TS__New(
2467
2560
  if source and source.typeId == dummyUnitId then
2468
2561
  source = nil
2469
2562
  end
2563
+ local target = ____exports.Unit:of(BlzGetEventDamageTarget())
2564
+ local damagingEvent = damagingEventByTarget[target]
2565
+ damagingEventByTarget[target] = nil
2470
2566
  local data = {
2471
2567
  amount = GetEventDamage(),
2472
- attackType = BlzGetEventAttackType(),
2568
+ attackType = nativeToAttackType(BlzGetEventAttackType()),
2473
2569
  damageType = BlzGetEventDamageType(),
2474
2570
  weaponType = BlzGetEventWeaponType(),
2571
+ metadata = damagingEvent and damagingEvent.metadata,
2475
2572
  isAttack = BlzGetEventIsAttack(),
2476
- originalAmount = GetEventDamage(),
2573
+ originalAmount = damagingEvent and damagingEvent.originalAmount or GetEventDamage(),
2574
+ originalMetadata = damagingEvent and damagingEvent.originalMetadata,
2477
2575
  preventDeath = damageEventPreventDeath
2478
2576
  }
2577
+ if damagingEvent then
2578
+ for key, value in pairs(damagingEvent) do
2579
+ if isAttribute(key) then
2580
+ data[key] = value
2581
+ end
2582
+ end
2583
+ local sourceOwner = damagingEvent[1]
2584
+ if sourceOwner then
2585
+ local targetOwner = damagingEvent[2]
2586
+ if damagingEvent[3] then
2587
+ SetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE, false)
2588
+ end
2589
+ if damagingEvent[4] then
2590
+ SetPlayerAlliance(targetOwner, sourceOwner, ALLIANCE_PASSIVE, false)
2591
+ end
2592
+ end
2593
+ end
2479
2594
  local evData = setmetatable(
2480
2595
  {},
2481
2596
  {
2482
2597
  __index = data,
2483
2598
  __newindex = function(self, key, value)
2484
- damageSetters[key](value)
2599
+ local damageSetter = damageSetters[key]
2600
+ if damageSetter ~= nil then
2601
+ damageSetter(value)
2602
+ end
2485
2603
  data[key] = value
2486
2604
  end
2487
2605
  }
2488
2606
  )
2489
- local target = ____exports.Unit:of(BlzGetEventDamageTarget())
2490
2607
  invoke(event, source, target, evData)
2491
2608
  if evData[0] ~= nil and target.health - evData.amount < 0.405 then
2492
2609
  local bonusHealth = math.ceil(evData.amount)
@@ -2565,6 +2682,21 @@ Unit.itemStackedEvent = __TS__New(
2565
2682
  EVENT_PLAYER_UNIT_STACK_ITEM,
2566
2683
  function() return ____exports.Unit:of(getTriggerUnit()), Item:of(getManipulatedItem()) end
2567
2684
  )
2685
+ __TS__ObjectDefineProperty(
2686
+ Unit,
2687
+ "itemChargesChangedEvent",
2688
+ {get = function(self)
2689
+ local event = __TS__New(Event)
2690
+ Item.chargesChangedEvent:addListener(function(item)
2691
+ local unit = item.owner
2692
+ if unit ~= nil then
2693
+ invoke(event, unit, item)
2694
+ end
2695
+ end)
2696
+ rawset(self, "itemChargesChangedEvent", event)
2697
+ return event
2698
+ end}
2699
+ )
2568
2700
  __TS__ObjectDefineProperty(
2569
2701
  Unit,
2570
2702
  "itemUseOrderEvent",
@@ -2,13 +2,18 @@
2
2
  import { ModelNodeName } from "./model-node-name";
3
3
  import { ModelNodeQualifier } from "./model-node-qualifier";
4
4
  import { Optional } from "../../../utility/types";
5
+ import { EffectParameters } from "../../../core/types/effect";
5
6
  export type AttachmentPreset = {
6
7
  modelPath: string;
7
8
  nodeName: ModelNodeName;
8
9
  nodeQualifiers: ModelNodeQualifier[];
9
10
  };
10
- export type AttachmentPresetInput = Optional<AttachmentPreset, "nodeQualifiers"> | string;
11
- export declare const toAttachmentPreset: (attachmentPresetInput: AttachmentPresetInput) => AttachmentPreset;
11
+ export type EffectPresetWithParameters = AttachmentPreset & {
12
+ parameters?: EffectParameters;
13
+ };
14
+ export type AttachmentPresetInput<T extends AttachmentPreset = AttachmentPreset> = Optional<T, "nodeName" | "nodeQualifiers"> | string;
15
+ export type EffectPresetWithParametersInput = AttachmentPresetInput<EffectPresetWithParameters>;
16
+ export declare const toEffectPreset: (effectPresetInput: EffectPresetWithParametersInput) => EffectPresetWithParameters;
12
17
  export declare const extractAttachmentPresetInputModelPath: (attachmentPresetInput: AttachmentPresetInput | undefined) => string;
13
18
  export declare const extractAttachmentPresetInputNodeFQN: (attachmentPresetInput: AttachmentPresetInput | undefined) => string;
14
19
  export declare const splitAttachmentNodeFQN: (attachmentNodeFQN: string) => LuaMultiReturn<[attachmentNodeName: ModelNodeName, attachmentNodeQualifiers: ModelNodeQualifier[]]>;
@@ -1,9 +1,10 @@
1
1
  local ____lualib = require("lualib_bundle")
2
+ local __TS__ArrayJoin = ____lualib.__TS__ArrayJoin
2
3
  local __TS__StringSplit = ____lualib.__TS__StringSplit
3
4
  local __TS__ArraySlice = ____lualib.__TS__ArraySlice
4
5
  local ____exports = {}
5
- ____exports.toAttachmentPreset = function(attachmentPresetInput)
6
- return type(attachmentPresetInput) == "string" and ({modelPath = attachmentPresetInput, nodeName = "origin", nodeQualifiers = {}}) or ({modelPath = attachmentPresetInput.modelPath, nodeName = attachmentPresetInput.nodeName, nodeQualifiers = attachmentPresetInput.nodeQualifiers or ({})})
6
+ ____exports.toEffectPreset = function(effectPresetInput)
7
+ return type(effectPresetInput) == "string" and ({modelPath = effectPresetInput, nodeName = "origin", nodeQualifiers = {}}) or ({modelPath = effectPresetInput.modelPath, nodeName = effectPresetInput.nodeName or "origin", nodeQualifiers = effectPresetInput.nodeQualifiers or ({}), parameters = effectPresetInput.parameters})
7
8
  end
8
9
  ____exports.extractAttachmentPresetInputModelPath = function(attachmentPresetInput)
9
10
  return type(attachmentPresetInput) == "string" and attachmentPresetInput or (attachmentPresetInput and attachmentPresetInput.modelPath or "")
@@ -12,7 +13,7 @@ ____exports.extractAttachmentPresetInputNodeFQN = function(attachmentPresetInput
12
13
  if type(attachmentPresetInput) == "string" or attachmentPresetInput == nil then
13
14
  return ""
14
15
  end
15
- return table.concat(
16
+ return __TS__ArrayJoin(
16
17
  {
17
18
  attachmentPresetInput.nodeName,
18
19
  table.unpack(attachmentPresetInput.nodeQualifiers or ({}))