warscript 0.0.1-dev.0fdd287 → 0.0.1-dev.1377403

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 (50) hide show
  1. package/attributes.d.ts +4 -0
  2. package/attributes.lua +5 -1
  3. package/core/types/sound.lua +5 -0
  4. package/decl/native.d.ts +840 -786
  5. package/engine/behaviour/ability/damage.d.ts +6 -3
  6. package/engine/behaviour/ability/damage.lua +24 -36
  7. package/engine/behaviour/ability/emulate-impact.lua +7 -0
  8. package/engine/internal/item.d.ts +2 -1
  9. package/engine/internal/misc/damage-metadata-by-target.d.ts +2 -0
  10. package/engine/internal/misc/damage-metadata-by-target.lua +5 -0
  11. package/engine/internal/unit+damage.d.ts +2 -11
  12. package/engine/internal/unit+damage.lua +10 -14
  13. package/engine/internal/unit+spellSteal.lua +1 -2
  14. package/engine/internal/unit.d.ts +12 -2
  15. package/engine/internal/unit.lua +86 -31
  16. package/engine/object-data/auxiliary/attack-type.d.ts +7 -8
  17. package/engine/object-data/auxiliary/attack-type.lua +42 -0
  18. package/engine/object-data/auxiliary/movement-type.d.ts +7 -7
  19. package/engine/object-data/auxiliary/movement-type.lua +22 -0
  20. package/engine/object-data/auxiliary/unit-attribute.d.ts +6 -0
  21. package/engine/object-data/auxiliary/unit-attribute.lua +9 -0
  22. package/engine/object-data/entry/ability-type/berserk.d.ts +2 -0
  23. package/engine/object-data/entry/ability-type/berserk.lua +13 -0
  24. package/engine/object-data/entry/ability-type/slow-poison.d.ts +10 -0
  25. package/engine/object-data/entry/ability-type/slow-poison.lua +58 -0
  26. package/engine/object-data/entry/ability-type.lua +7 -0
  27. package/engine/object-data/entry/buff-type/applicable.lua +5 -0
  28. package/engine/object-data/entry/buff-type.d.ts +5 -11
  29. package/engine/object-data/entry/buff-type.lua +11 -27
  30. package/engine/object-data/entry/unit-type.d.ts +2 -2
  31. package/engine/object-data/entry/unit-type.lua +94 -84
  32. package/engine/object-field/ability.d.ts +1 -1
  33. package/engine/object-field/unit.d.ts +46 -3
  34. package/engine/object-field/unit.lua +173 -7
  35. package/engine/object-field.d.ts +9 -1
  36. package/engine/object-field.lua +158 -76
  37. package/engine/standard/entries/buff-type.d.ts +3 -0
  38. package/engine/standard/entries/buff-type.lua +3 -0
  39. package/objutil/buff.lua +1 -2
  40. package/package.json +2 -2
  41. package/utility/arrays.d.ts +1 -0
  42. package/utility/arrays.lua +3 -0
  43. package/utility/functions.d.ts +1 -0
  44. package/utility/functions.lua +1 -0
  45. package/utility/linked-set.d.ts +1 -0
  46. package/utility/linked-set.lua +3 -0
  47. package/utility/lua-maps.d.ts +3 -0
  48. package/utility/lua-maps.lua +16 -0
  49. package/utility/lua-sets.d.ts +1 -0
  50. package/utility/lua-sets.lua +3 -0
@@ -4,26 +4,29 @@ import { Ability } from "../../internal/ability";
4
4
  import { Unit } from "../../internal/unit";
5
5
  import { AbilityDependentValue } from "../../object-field/ability";
6
6
  import { Widget } from "../../../core/types/widget";
7
- import { AttackType, DamageType, WeaponType } from "../../internal/unit+damage";
7
+ import { DamageType, WeaponType } from "../../internal/unit+damage";
8
8
  import { CombatClassifications } from "../../object-data/auxiliary/combat-classification";
9
+ import { AttackType } from "../../object-data/auxiliary/attack-type";
9
10
  export type DamageAbilityBehaviorParameters = {
10
11
  damagePerStrength?: AbilityDependentValue<number>;
11
12
  damagePerAgility?: AbilityDependentValue<number>;
12
13
  damagePerIntelligence?: AbilityDependentValue<number>;
13
- attackType?: AttackType;
14
+ attackType?: AbilityDependentValue<AttackType>;
14
15
  damageType?: DamageType;
15
16
  weaponType?: WeaponType;
17
+ metadata?: AbilityDependentValue<string | number | boolean>;
16
18
  };
17
19
  export type DamageAreaAbilityBehaviorParameters = DamageAbilityBehaviorParameters & {
18
20
  maximumDamage?: AbilityDependentValue<number>;
19
21
  areaOfEffect?: AbilityDependentValue<number>;
20
22
  allowedTargetCombatClassifications?: AbilityDependentValue<CombatClassifications>;
21
23
  };
22
- declare abstract class DamageAbilityBehavior<T extends DamageAbilityBehaviorParameters = DamageAbilityBehaviorParameters> extends AbilityBehavior {
24
+ export declare abstract class DamageAbilityBehavior<T extends DamageAbilityBehaviorParameters = DamageAbilityBehaviorParameters> extends AbilityBehavior {
23
25
  protected readonly damage: AbilityDependentValue<number>;
24
26
  protected readonly parameters?: T | undefined;
25
27
  protected constructor(ability: Ability, damage: AbilityDependentValue<number>, parameters?: T | undefined);
26
28
  protected calculateDamage(caster: Unit): number;
29
+ protected damageTarget(caster: Unit, target: Widget, damage?: number): void;
27
30
  }
28
31
  export declare class DamageSelfAbilityBehavior extends DamageAbilityBehavior {
29
32
  constructor(ability: Ability, damage: AbilityDependentValue<number>, parameters?: DamageAbilityBehaviorParameters);
@@ -9,7 +9,8 @@ local Unit = ____unit.Unit
9
9
  local ____ability = require("engine.standard.fields.ability")
10
10
  local ALLOWED_TARGETS_ABILITY_COMBAT_CLASSIFICATIONS_LEVEL_FIELD = ____ability.ALLOWED_TARGETS_ABILITY_COMBAT_CLASSIFICATIONS_LEVEL_FIELD
11
11
  local AREA_OF_EFFECT_ABILITY_FLOAT_LEVEL_FIELD = ____ability.AREA_OF_EFFECT_ABILITY_FLOAT_LEVEL_FIELD
12
- local DamageAbilityBehavior = __TS__Class()
12
+ ____exports.DamageAbilityBehavior = __TS__Class()
13
+ local DamageAbilityBehavior = ____exports.DamageAbilityBehavior
13
14
  DamageAbilityBehavior.name = "DamageAbilityBehavior"
14
15
  __TS__ClassExtends(DamageAbilityBehavior, AbilityBehavior)
15
16
  function DamageAbilityBehavior.prototype.____constructor(self, ability, damage, parameters)
@@ -34,49 +35,44 @@ function DamageAbilityBehavior.prototype.calculateDamage(self, caster)
34
35
  end
35
36
  return damage
36
37
  end
37
- ____exports.DamageSelfAbilityBehavior = __TS__Class()
38
- local DamageSelfAbilityBehavior = ____exports.DamageSelfAbilityBehavior
39
- DamageSelfAbilityBehavior.name = "DamageSelfAbilityBehavior"
40
- __TS__ClassExtends(DamageSelfAbilityBehavior, DamageAbilityBehavior)
41
- function DamageSelfAbilityBehavior.prototype.____constructor(self, ability, damage, parameters)
42
- DamageAbilityBehavior.prototype.____constructor(self, ability, damage, parameters)
43
- end
44
- function DamageSelfAbilityBehavior.prototype.onImpact(self, caster)
38
+ function DamageAbilityBehavior.prototype.damageTarget(self, caster, target, damage)
45
39
  local parameters = self.parameters
46
40
  caster:damageTarget(
47
- caster,
48
- self:calculateDamage(caster),
41
+ target,
42
+ damage or self:calculateDamage(caster),
49
43
  nil,
50
44
  nil,
51
- parameters and parameters.attackType,
45
+ self:resolveCurrentAbilityDependentValue(parameters and parameters.attackType),
52
46
  parameters and parameters.damageType,
53
- parameters and parameters.weaponType
47
+ parameters and parameters.weaponType,
48
+ self:resolveCurrentAbilityDependentValue(parameters and parameters.metadata)
54
49
  )
55
50
  end
51
+ ____exports.DamageSelfAbilityBehavior = __TS__Class()
52
+ local DamageSelfAbilityBehavior = ____exports.DamageSelfAbilityBehavior
53
+ DamageSelfAbilityBehavior.name = "DamageSelfAbilityBehavior"
54
+ __TS__ClassExtends(DamageSelfAbilityBehavior, ____exports.DamageAbilityBehavior)
55
+ function DamageSelfAbilityBehavior.prototype.____constructor(self, ability, damage, parameters)
56
+ DamageSelfAbilityBehavior.____super.prototype.____constructor(self, ability, damage, parameters)
57
+ end
58
+ function DamageSelfAbilityBehavior.prototype.onImpact(self, caster)
59
+ self:damageTarget(caster, caster)
60
+ end
56
61
  ____exports.DamageTargetAbilityBehavior = __TS__Class()
57
62
  local DamageTargetAbilityBehavior = ____exports.DamageTargetAbilityBehavior
58
63
  DamageTargetAbilityBehavior.name = "DamageTargetAbilityBehavior"
59
- __TS__ClassExtends(DamageTargetAbilityBehavior, DamageAbilityBehavior)
64
+ __TS__ClassExtends(DamageTargetAbilityBehavior, ____exports.DamageAbilityBehavior)
60
65
  function DamageTargetAbilityBehavior.prototype.____constructor(self, ability, damage, parameters)
61
- DamageAbilityBehavior.prototype.____constructor(self, ability, damage, parameters)
66
+ DamageTargetAbilityBehavior.____super.prototype.____constructor(self, ability, damage, parameters)
62
67
  end
63
68
  function DamageTargetAbilityBehavior.prototype.onWidgetTargetImpact(self, caster, target)
64
- local parameters = self.parameters
65
- caster:damageTarget(
66
- target,
67
- self:calculateDamage(caster),
68
- nil,
69
- nil,
70
- parameters and parameters.attackType,
71
- parameters and parameters.damageType,
72
- parameters and parameters.weaponType
73
- )
69
+ self:damageTarget(caster, target)
74
70
  end
75
71
  local DamageAreaAbilityBehavior = __TS__Class()
76
72
  DamageAreaAbilityBehavior.name = "DamageAreaAbilityBehavior"
77
- __TS__ClassExtends(DamageAreaAbilityBehavior, DamageAbilityBehavior)
73
+ __TS__ClassExtends(DamageAreaAbilityBehavior, ____exports.DamageAbilityBehavior)
78
74
  function DamageAreaAbilityBehavior.prototype.____constructor(self, ability, damage, parameters)
79
- DamageAbilityBehavior.prototype.____constructor(self, ability, damage, parameters)
75
+ DamageAreaAbilityBehavior.____super.prototype.____constructor(self, ability, damage, parameters)
80
76
  end
81
77
  function DamageAreaAbilityBehavior.prototype.damageArea(self, caster, x, y)
82
78
  local parameters = self.parameters
@@ -93,15 +89,7 @@ function DamageAreaAbilityBehavior.prototype.damageArea(self, caster, x, y)
93
89
  damage = maximumDamage / #targets
94
90
  end
95
91
  for ____, target in ipairs(targets) do
96
- caster:damageTarget(
97
- target,
98
- damage,
99
- nil,
100
- nil,
101
- parameters and parameters.attackType,
102
- parameters and parameters.damageType,
103
- parameters and parameters.weaponType
104
- )
92
+ self:damageTarget(caster, target, damage)
105
93
  end
106
94
  end
107
95
  ____exports.DamageSelfAreaAbilityBehavior = __TS__Class()
@@ -10,6 +10,9 @@ local MANA_COST_ABILITY_INTEGER_LEVEL_FIELD = ____ability.MANA_COST_ABILITY_INTE
10
10
  local ____math = require("math")
11
11
  local max = ____math.max
12
12
  local MINIMUM_POSITIVE_NORMALIZED_FLOAT = ____math.MINIMUM_POSITIVE_NORMALIZED_FLOAT
13
+ local ____sound = require("core.types.sound")
14
+ local Sound3D = ____sound.Sound3D
15
+ local SoundSettings = ____sound.SoundSettings
13
16
  ____exports.EmulateImpactAbilityBehavior = __TS__Class()
14
17
  local EmulateImpactAbilityBehavior = ____exports.EmulateImpactAbilityBehavior
15
18
  EmulateImpactAbilityBehavior.name = "EmulateImpactAbilityBehavior"
@@ -23,6 +26,10 @@ function EmulateImpactAbilityBehavior.prototype.emulateImpact(self, caster)
23
26
  caster.mana = caster.mana - manaCost
24
27
  self.ability.cooldownRemaining = max(cooldown, MINIMUM_POSITIVE_NORMALIZED_FLOAT)
25
28
  self:flashCasterEffect(caster)
29
+ local soundPresetId = self.ability:getField(ABILITY_SF_EFFECT_SOUND)
30
+ if soundPresetId ~= "" then
31
+ Sound3D:playFromLabel(soundPresetId, SoundSettings.Ability, caster)
32
+ end
26
33
  AbilityBehavior:forAll(self.ability, "onImpact", caster)
27
34
  end
28
35
  return ____exports
@@ -5,6 +5,7 @@ import { Event } from "../../event";
5
5
  import { ReadonlyRect } from "../../core/types/rect";
6
6
  import { ItemAbility } from "./ability";
7
7
  import { AbilityTypeId } from "../object-data/entry/ability-type";
8
+ import type { ItemTypeId } from "../object-data/entry/item-type";
8
9
  type DefenseType = 0 | 1 | 2 | 3 | 4 | 5;
9
10
  export declare const addAndGetAbility: (handle: jitem, abilityTypeId: AbilityTypeId) => jability | null;
10
11
  declare const enum ItemPropertyKey {
@@ -17,7 +18,7 @@ export declare class Item extends Handle<jitem> {
17
18
  constructor(handle: jitem);
18
19
  protected onDestroy(): HandleDestructor;
19
20
  static create<T extends Item>(this: typeof Item & (new (handle: jitem) => T), id: number, x: number, y: number, skinId?: number): T;
20
- get typeId(): number;
21
+ get typeId(): ItemTypeId;
21
22
  set skinId(v: number);
22
23
  get skinId(): number;
23
24
  set name(v: string);
@@ -0,0 +1,2 @@
1
+ /** @noSelfInFile */
2
+ export {};
@@ -0,0 +1,5 @@
1
+ local ____exports = {}
2
+ ---
3
+ -- @internal For use by internal systems only.
4
+ ____exports.damageMetadataByTarget = setmetatable({}, {__mode = "k"})
5
+ return ____exports
@@ -1,15 +1,6 @@
1
1
  /** @noSelfInFile */
2
2
  import { Widget } from "../../core/types/widget";
3
- export type AttackType = jattacktype;
4
- export declare namespace AttackType {
5
- const SPELL: jattacktype;
6
- const NORMAL: jattacktype;
7
- const PIERCE: jattacktype;
8
- const SIEGE: jattacktype;
9
- const MAGIC: jattacktype;
10
- const CHAOS: jattacktype;
11
- const HERO: jattacktype;
12
- }
3
+ import { AttackType } from "../object-data/auxiliary/attack-type";
13
4
  export type DamageType = jdamagetype;
14
5
  export declare namespace DamageType {
15
6
  const UNKNOWN: jdamagetype;
@@ -64,6 +55,6 @@ export declare namespace WeaponType {
64
55
  }
65
56
  declare module "./unit" {
66
57
  interface Unit {
67
- damageTarget(target: Widget, amount: number, attack?: boolean, ranged?: boolean, attackType?: AttackType, damageType?: DamageType, weaponType?: WeaponType): boolean;
58
+ damageTarget(target: Widget, amount: number, attack?: boolean, ranged?: boolean, attackType?: AttackType, damageType?: DamageType, weaponType?: WeaponType, metadata?: unknown): boolean;
68
59
  }
69
60
  }
@@ -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,
@@ -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;
@@ -36,13 +40,15 @@ type AbilityDispatcherTable<T extends any[] = []> = {
36
40
  readonly [id: number]: Event<[Unit, Ability, ...T]>;
37
41
  };
38
42
  type AbilityEventDispatcher<T extends any[] = []> = Event<[Unit, Ability, ...T]> & AbilityDispatcherTable<T>;
39
- export interface DamagingEvent {
43
+ export interface DamagingEvent extends AttributesHolder {
40
44
  amount: number;
41
- attackType: jattacktype;
45
+ attackType: AttackType;
42
46
  damageType: jdamagetype;
43
47
  weaponType: jweapontype;
48
+ metadata: unknown;
44
49
  readonly isAttack: boolean;
45
50
  readonly originalAmount: number;
51
+ readonly originalMetadata: unknown;
46
52
  }
47
53
  export type DamageEvent = DamagingEvent & {
48
54
  preventDeath<P extends any[]>(this: DamageEvent, callback: (this: void, ...parameters: P) => any, ...parameters: P): void;
@@ -161,6 +167,8 @@ export declare class Unit extends Handle<junit> {
161
167
  set level(v: number);
162
168
  get xp(): number;
163
169
  set xp(v: number);
170
+ get primaryAttribute(): UnitAttribute;
171
+ set primaryAttribute(primaryAttribute: UnitAttribute);
164
172
  get strengthBase(): number;
165
173
  set strengthBase(strengthBase: number);
166
174
  get strengthBonus(): number;
@@ -235,6 +243,8 @@ export declare class Unit extends Handle<junit> {
235
243
  set timeScale(v: number);
236
244
  get collisionSize(): number;
237
245
  get pathingCollisionRange(): number;
246
+ get movementType(): MovementType;
247
+ set movementType(movementType: MovementType);
238
248
  set pathing(v: boolean);
239
249
  isSelected(player: Player): boolean;
240
250
  explode(): void;
@@ -53,6 +53,13 @@ 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
@@ -81,7 +88,6 @@ local getHandleId = GetHandleId
81
88
  local getUnitCurrentOrder = GetUnitCurrentOrder
82
89
  local createUnit = CreateUnit
83
90
  local killUnit = KillUnit
84
- local setUnitExploded = SetUnitExploded
85
91
  local removeUnit = RemoveUnit
86
92
  local getUnitTypeId = GetUnitTypeId
87
93
  local isHeroUnitId = IsHeroUnitId
@@ -97,8 +103,6 @@ local getSpellTargetItem = GetSpellTargetItem
97
103
  local getSpellTargetDestructable = GetSpellTargetDestructable
98
104
  local isUnitInRangeXY = IsUnitInRangeXY
99
105
  local isUnitInRange = IsUnitInRange
100
- local setResourceAmount = SetResourceAmount
101
- local getResourceAmount = GetResourceAmount
102
106
  local getUnitWeaponRealField = BlzGetUnitWeaponRealField
103
107
  local setUnitWeaponRealField = BlzSetUnitWeaponRealField
104
108
  local getUnitWeaponStringField = BlzGetUnitWeaponStringField
@@ -129,8 +133,6 @@ local isUnitType = IsUnitType
129
133
  local isUnitAlly = IsUnitAlly
130
134
  local isUnitEnemy = IsUnitEnemy
131
135
  local getOwningPlayer = GetOwningPlayer
132
- local setUnitColor = SetUnitColor
133
- local showUnitTeamGlow = BlzShowUnitTeamGlow
134
136
  ____exports.UnitClassification = {}
135
137
  local UnitClassification = ____exports.UnitClassification
136
138
  do
@@ -358,7 +360,14 @@ local function damageEventPreventDeath(self, callback, ...)
358
360
  rawset(self, 1 + i, (select(i, ...)))
359
361
  end
360
362
  end
361
- local damageSetters = {amount = BlzSetEventDamage, attackType = BlzSetEventAttackType, damageType = BlzSetEventDamageType, weaponType = BlzSetEventWeaponType}
363
+ local damageSetters = {
364
+ amount = BlzSetEventDamage,
365
+ attackType = function(attackType)
366
+ return BlzSetEventAttackType(attackTypeToNative(attackType))
367
+ end,
368
+ damageType = BlzSetEventDamageType,
369
+ weaponType = BlzSetEventWeaponType
370
+ }
362
371
  local jlimitopByOperator = {
363
372
  [0] = LESS_THAN_OR_EQUAL,
364
373
  [1] = LESS_THAN_OR_EQUAL,
@@ -640,7 +649,8 @@ local function delayHealthChecksCallback(unit)
640
649
  end
641
650
  end
642
651
  local nextSyncId = 1
643
- local unitBySyncId = setmetatable({}, {__mode = "k"})
652
+ local unitBySyncId = setmetatable({}, {__mode = "v"})
653
+ local damagingEventByTarget = setmetatable({}, {__mode = "k"})
644
654
  ____exports.Unit = __TS__Class()
645
655
  local Unit = ____exports.Unit
646
656
  Unit.name = "Unit"
@@ -815,7 +825,7 @@ function Unit.prototype.isSelected(self, player)
815
825
  return IsUnitSelected(self.handle, player.handle)
816
826
  end
817
827
  function Unit.prototype.explode(self)
818
- setUnitExploded(self.handle, true)
828
+ SetUnitExploded(self.handle, true)
819
829
  killUnit(self.handle)
820
830
  end
821
831
  function Unit.prototype.kill(self)
@@ -1292,6 +1302,19 @@ __TS__SetDescriptor(
1292
1302
  },
1293
1303
  true
1294
1304
  )
1305
+ __TS__SetDescriptor(
1306
+ Unit.prototype,
1307
+ "primaryAttribute",
1308
+ {
1309
+ get = function(self)
1310
+ return getUnitIntegerField(self.handle, UNIT_IF_PRIMARY_ATTRIBUTE)
1311
+ end,
1312
+ set = function(self, primaryAttribute)
1313
+ setUnitIntegerField(self.handle, UNIT_IF_PRIMARY_ATTRIBUTE, primaryAttribute)
1314
+ end
1315
+ },
1316
+ true
1317
+ )
1295
1318
  __TS__SetDescriptor(
1296
1319
  Unit.prototype,
1297
1320
  "strengthBase",
@@ -1416,7 +1439,7 @@ __TS__SetDescriptor(
1416
1439
  return not self[106]
1417
1440
  end,
1418
1441
  set = function(self, isTeamGlowVisible)
1419
- showUnitTeamGlow(self.handle, isTeamGlowVisible)
1442
+ BlzShowUnitTeamGlow(self.handle, isTeamGlowVisible)
1420
1443
  local ____temp_6
1421
1444
  if not isTeamGlowVisible then
1422
1445
  ____temp_6 = true
@@ -1432,9 +1455,9 @@ __TS__SetDescriptor(
1432
1455
  Unit.prototype,
1433
1456
  "color",
1434
1457
  {set = function(self, color)
1435
- setUnitColor(self.handle, color.handle)
1458
+ SetUnitColor(self.handle, color.handle)
1436
1459
  if self[106] then
1437
- showUnitTeamGlow(self.handle, false)
1460
+ BlzShowUnitTeamGlow(self.handle, false)
1438
1461
  end
1439
1462
  end},
1440
1463
  true
@@ -1702,10 +1725,10 @@ __TS__SetDescriptor(
1702
1725
  "gold",
1703
1726
  {
1704
1727
  get = function(self)
1705
- return getResourceAmount(self.handle)
1728
+ return GetResourceAmount(self.handle)
1706
1729
  end,
1707
1730
  set = function(self, gold)
1708
- setResourceAmount(self.handle, gold)
1731
+ SetResourceAmount(self.handle, gold)
1709
1732
  end
1710
1733
  },
1711
1734
  true
@@ -1833,6 +1856,19 @@ __TS__SetDescriptor(
1833
1856
  end},
1834
1857
  true
1835
1858
  )
1859
+ __TS__SetDescriptor(
1860
+ Unit.prototype,
1861
+ "movementType",
1862
+ {
1863
+ get = function(self)
1864
+ return getUnitIntegerField(self.handle, UNIT_IF_MOVE_TYPE)
1865
+ end,
1866
+ set = function(self, movementType)
1867
+ setUnitIntegerField(self.handle, UNIT_IF_MOVE_TYPE, movementType)
1868
+ end
1869
+ },
1870
+ true
1871
+ )
1836
1872
  __TS__SetDescriptor(
1837
1873
  Unit.prototype,
1838
1874
  "pathing",
@@ -2375,13 +2411,18 @@ Unit.onDamaging = (function()
2375
2411
  if source and source.typeId == dummyUnitId then
2376
2412
  source = nil
2377
2413
  end
2378
- local target = BlzGetEventDamageTarget()
2414
+ local target = ____exports.Unit:of(BlzGetEventDamageTarget())
2415
+ local metadata = damageMetadataByTarget[target]
2416
+ damageMetadataByTarget[target] = nil
2379
2417
  local data = {
2380
2418
  amount = GetEventDamage(),
2381
- attackType = BlzGetEventAttackType(),
2419
+ attackType = nativeToAttackType(BlzGetEventAttackType()),
2382
2420
  damageType = BlzGetEventDamageType(),
2383
2421
  weaponType = BlzGetEventWeaponType(),
2384
- isAttack = BlzGetEventIsAttack()
2422
+ metadata = metadata,
2423
+ isAttack = BlzGetEventIsAttack(),
2424
+ originalAmount = GetEventDamage(),
2425
+ originalMetadata = metadata
2385
2426
  }
2386
2427
  if data.isAttack and source then
2387
2428
  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
@@ -2395,18 +2436,22 @@ Unit.onDamaging = (function()
2395
2436
  invoke(
2396
2437
  event,
2397
2438
  source,
2398
- ____exports.Unit:of(target),
2439
+ target,
2399
2440
  setmetatable(
2400
2441
  {},
2401
2442
  {
2402
2443
  __index = data,
2403
2444
  __newindex = function(self, key, value)
2404
- damageSetters[key](value)
2445
+ local damageSetter = damageSetters[key]
2446
+ if damageSetter ~= nil then
2447
+ damageSetter(value)
2448
+ end
2405
2449
  data[key] = value
2406
2450
  end
2407
2451
  }
2408
2452
  )
2409
2453
  )
2454
+ damagingEventByTarget[target] = data
2410
2455
  return
2411
2456
  end
2412
2457
  BlzSetEventDamage(0)
@@ -2414,7 +2459,7 @@ Unit.onDamaging = (function()
2414
2459
  BlzSetEventDamageType(DAMAGE_TYPE_UNKNOWN)
2415
2460
  BlzSetEventWeaponType(WEAPON_TYPE_WHOKNOWS)
2416
2461
  local sourceOwner = source.owner.handle
2417
- local targetOwner = GetOwningPlayer(target)
2462
+ local targetOwner = target.owner.handle
2418
2463
  if not GetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE) then
2419
2464
  SetPlayerAlliance(sourceOwner, targetOwner, ALLIANCE_PASSIVE, true)
2420
2465
  Timer:run(function()
@@ -2430,23 +2475,19 @@ Unit.onDamaging = (function()
2430
2475
  for ____, ____value in ipairs(source._attackHandlers) do
2431
2476
  local condition = ____value[1]
2432
2477
  local action = ____value[2]
2433
- if condition(
2434
- source,
2435
- ____exports.Unit:of(target),
2436
- data
2437
- ) then
2478
+ if condition(source, target, data) then
2438
2479
  action(
2439
2480
  source,
2440
- ____exports.Unit:of(target),
2481
+ target,
2441
2482
  setmetatable(
2442
2483
  {fire = function()
2443
2484
  UnitDamageTarget(
2444
2485
  source.handle,
2445
- target,
2486
+ target.handle,
2446
2487
  data.amount,
2447
2488
  true,
2448
2489
  true,
2449
- data.attackType,
2490
+ attackTypeToNative(data.attackType),
2450
2491
  data.damageType,
2451
2492
  data.weaponType
2452
2493
  )
@@ -2473,26 +2514,40 @@ Unit.onDamage = __TS__New(
2473
2514
  if source and source.typeId == dummyUnitId then
2474
2515
  source = nil
2475
2516
  end
2517
+ local target = ____exports.Unit:of(BlzGetEventDamageTarget())
2518
+ local damagingEvent = damagingEventByTarget[target]
2519
+ damagingEventByTarget[target] = nil
2476
2520
  local data = {
2477
2521
  amount = GetEventDamage(),
2478
- attackType = BlzGetEventAttackType(),
2522
+ attackType = nativeToAttackType(BlzGetEventAttackType()),
2479
2523
  damageType = BlzGetEventDamageType(),
2480
2524
  weaponType = BlzGetEventWeaponType(),
2525
+ metadata = damagingEvent and damagingEvent.metadata,
2481
2526
  isAttack = BlzGetEventIsAttack(),
2482
- originalAmount = GetEventDamage(),
2527
+ originalAmount = damagingEvent and damagingEvent.originalAmount or GetEventDamage(),
2528
+ originalMetadata = damagingEvent and damagingEvent.originalMetadata,
2483
2529
  preventDeath = damageEventPreventDeath
2484
2530
  }
2531
+ if damagingEvent then
2532
+ for key, value in pairs(damagingEvent) do
2533
+ if isAttribute(key) then
2534
+ data[key] = value
2535
+ end
2536
+ end
2537
+ end
2485
2538
  local evData = setmetatable(
2486
2539
  {},
2487
2540
  {
2488
2541
  __index = data,
2489
2542
  __newindex = function(self, key, value)
2490
- damageSetters[key](value)
2543
+ local damageSetter = damageSetters[key]
2544
+ if damageSetter ~= nil then
2545
+ damageSetter(value)
2546
+ end
2491
2547
  data[key] = value
2492
2548
  end
2493
2549
  }
2494
2550
  )
2495
- local target = ____exports.Unit:of(BlzGetEventDamageTarget())
2496
2551
  invoke(event, source, target, evData)
2497
2552
  if evData[0] ~= nil and target.health - evData.amount < 0.405 then
2498
2553
  local bonusHealth = math.ceil(evData.amount)
@@ -1,11 +1,10 @@
1
1
  /** @noSelfInFile */
2
2
  export declare const enum AttackType {
3
- NONE = "unknown",
4
- NORMAL = "normal",
5
- PIERCE = "pierce",
6
- SIEGE = "siege",
7
- SPELL = "spells",
8
- CHAOS = "chaos",
9
- MAGIC = "magic",
10
- HERO = "hero"
3
+ SPELL = 0,
4
+ NORMAL = 1,
5
+ PIERCE = 2,
6
+ SIEGE = 3,
7
+ MAGIC = 4,
8
+ CHAOS = 5,
9
+ HERO = 6
11
10
  }
@@ -1,2 +1,44 @@
1
1
  local ____exports = {}
2
+ local ____records = require("utility.records")
3
+ local invertRecord = ____records.invertRecord
4
+ local stringByAttackType = {
5
+ [1] = "normal",
6
+ [2] = "pierce",
7
+ [3] = "siege",
8
+ [0] = "spells",
9
+ [5] = "chaos",
10
+ [4] = "magic",
11
+ [6] = "hero"
12
+ }
13
+ local attackTypeByString = invertRecord(stringByAttackType)
14
+ local nativeByAttackType = {
15
+ [1] = ATTACK_TYPE_MELEE,
16
+ [2] = ATTACK_TYPE_PIERCE,
17
+ [3] = ATTACK_TYPE_SIEGE,
18
+ [0] = ATTACK_TYPE_NORMAL,
19
+ [5] = ATTACK_TYPE_CHAOS,
20
+ [4] = ATTACK_TYPE_MAGIC,
21
+ [6] = ATTACK_TYPE_HERO
22
+ }
23
+ local attackTypeByNative = invertRecord(nativeByAttackType)
24
+ ---
25
+ -- @internal For use by internal systems only.
26
+ ____exports.attackTypeToString = function(attackType)
27
+ return attackType ~= nil and stringByAttackType[attackType] or "unknown"
28
+ end
29
+ ---
30
+ -- @internal For use by internal systems only.
31
+ ____exports.stringToAttackType = function(____string)
32
+ return attackTypeByString[____string]
33
+ end
34
+ ---
35
+ -- @internal For use by internal systems only.
36
+ ____exports.attackTypeToNative = function(attackType)
37
+ return nativeByAttackType[attackType]
38
+ end
39
+ ---
40
+ -- @internal For use by internal systems only.
41
+ ____exports.nativeToAttackType = function(attackType)
42
+ return attackTypeByNative[attackType]
43
+ end
2
44
  return ____exports