warscript 0.0.1-dev.d63794c → 0.0.1-dev.d690591

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 (129) hide show
  1. package/config.d.ts +5 -0
  2. package/config.lua +10 -0
  3. package/core/types/effect.d.ts +1 -3
  4. package/core/types/effect.lua +26 -29
  5. package/core/types/sound.d.ts +17 -24
  6. package/core/types/sound.lua +99 -24
  7. package/core/types/timer.d.ts +6 -7
  8. package/core/types/timer.lua +18 -21
  9. package/core/util.lua +6 -1
  10. package/decl/native.d.ts +840 -786
  11. package/engine/behaviour/ability/apply-buff.d.ts +5 -0
  12. package/engine/behaviour/ability/apply-buff.lua +32 -0
  13. package/engine/behaviour/ability/apply-unit-behavior.lua +1 -0
  14. package/engine/behaviour/ability/damage.d.ts +9 -3
  15. package/engine/behaviour/ability/damage.lua +26 -38
  16. package/engine/behaviour/ability/emulate-impact.lua +11 -5
  17. package/engine/behaviour/ability/on-command-impact.lua +7 -0
  18. package/engine/behaviour/ability.d.ts +12 -3
  19. package/engine/behaviour/ability.lua +66 -7
  20. package/engine/behaviour/unit.d.ts +2 -0
  21. package/engine/buff.d.ts +56 -41
  22. package/engine/buff.lua +295 -228
  23. package/engine/internal/ability.lua +17 -24
  24. package/engine/internal/item/ability.lua +77 -3
  25. package/engine/internal/item.d.ts +4 -3
  26. package/engine/internal/item.lua +56 -25
  27. package/engine/internal/mechanics/ability-duration.lua +1 -1
  28. package/engine/internal/misc/damage-metadata-by-target.d.ts +2 -0
  29. package/engine/internal/misc/damage-metadata-by-target.lua +5 -0
  30. package/engine/internal/object-data/auto-attack-speed-increase.d.ts +1 -1
  31. package/engine/internal/object-data/auto-attack-speed-increase.lua +2 -0
  32. package/engine/internal/object-data/evasion-probability.d.ts +2 -0
  33. package/engine/internal/object-data/evasion-probability.lua +16 -0
  34. package/engine/internal/unit/add-item-to-slot-init.d.ts +2 -0
  35. package/engine/internal/unit/add-item-to-slot-init.lua +23 -0
  36. package/engine/internal/unit/add-item-to-slot.d.ts +2 -0
  37. package/engine/internal/unit/add-item-to-slot.lua +52 -0
  38. package/engine/internal/unit/bonus.d.ts +2 -0
  39. package/engine/internal/unit/bonus.lua +17 -0
  40. package/engine/internal/unit/ignore-events-items.d.ts +2 -0
  41. package/engine/internal/unit/ignore-events-items.lua +5 -0
  42. package/engine/internal/unit/item.lua +3 -4
  43. package/engine/internal/unit+damage.d.ts +2 -11
  44. package/engine/internal/unit+damage.lua +10 -14
  45. package/engine/internal/unit+spellSteal.lua +1 -2
  46. package/engine/internal/unit.d.ts +17 -2
  47. package/engine/internal/unit.lua +121 -43
  48. package/engine/lightning.d.ts +12 -5
  49. package/engine/lightning.lua +48 -14
  50. package/engine/object-data/auxiliary/animation-name.d.ts +1 -0
  51. package/engine/object-data/auxiliary/animation-name.lua +16 -0
  52. package/engine/object-data/auxiliary/attachment-preset.d.ts +7 -2
  53. package/engine/object-data/auxiliary/attachment-preset.lua +4 -3
  54. package/engine/object-data/auxiliary/attack-type.d.ts +7 -8
  55. package/engine/object-data/auxiliary/attack-type.lua +42 -0
  56. package/engine/object-data/auxiliary/movement-type.d.ts +7 -7
  57. package/engine/object-data/auxiliary/movement-type.lua +22 -0
  58. package/engine/object-data/auxiliary/sound-eax.d.ts +10 -0
  59. package/engine/object-data/auxiliary/sound-eax.lua +2 -0
  60. package/engine/object-data/auxiliary/tech-tree-dependency.d.ts +1 -1
  61. package/engine/object-data/auxiliary/unit-attribute.d.ts +6 -0
  62. package/engine/object-data/auxiliary/unit-attribute.lua +9 -0
  63. package/engine/object-data/entry/ability-type/berserk.d.ts +2 -0
  64. package/engine/object-data/entry/ability-type/berserk.lua +13 -0
  65. package/engine/object-data/entry/ability-type/blank-configurable.lua +12 -1
  66. package/engine/object-data/entry/ability-type/carrion-swarm.d.ts +14 -0
  67. package/engine/object-data/entry/ability-type/carrion-swarm.lua +65 -0
  68. package/engine/object-data/entry/ability-type/disease-cloud.lua +2 -2
  69. package/engine/object-data/entry/ability-type/engineering-upgrade.lua +2 -2
  70. package/engine/object-data/entry/ability-type/ensnare.d.ts +12 -0
  71. package/engine/object-data/entry/ability-type/ensnare.lua +52 -0
  72. package/engine/object-data/entry/ability-type/feral-spirit.lua +2 -2
  73. package/engine/object-data/entry/ability-type/phase-shift.d.ts +10 -0
  74. package/engine/object-data/entry/ability-type/phase-shift.lua +39 -0
  75. package/engine/object-data/entry/ability-type/phoenix-morph.lua +4 -4
  76. package/engine/object-data/entry/ability-type/raise-dead.d.ts +17 -0
  77. package/engine/object-data/entry/ability-type/raise-dead.lua +78 -0
  78. package/engine/object-data/entry/ability-type/shock-wave.d.ts +4 -0
  79. package/engine/object-data/entry/ability-type/shock-wave.lua +26 -0
  80. package/engine/object-data/entry/ability-type/slow-poison.d.ts +10 -0
  81. package/engine/object-data/entry/ability-type/slow-poison.lua +58 -0
  82. package/engine/object-data/entry/ability-type/summon-quilbeast.lua +2 -2
  83. package/engine/object-data/entry/ability-type/summon-water-elemental.lua +2 -2
  84. package/engine/object-data/entry/ability-type/web.d.ts +12 -0
  85. package/engine/object-data/entry/ability-type/web.lua +52 -0
  86. package/engine/object-data/entry/ability-type.d.ts +19 -17
  87. package/engine/object-data/entry/ability-type.lua +89 -33
  88. package/engine/object-data/entry/buff-type/applicable.lua +18 -37
  89. package/engine/object-data/entry/buff-type.d.ts +6 -12
  90. package/engine/object-data/entry/buff-type.lua +13 -29
  91. package/engine/object-data/entry/destructible-type.d.ts +1 -1
  92. package/engine/object-data/entry/item-type.d.ts +3 -1
  93. package/engine/object-data/entry/item-type.lua +15 -2
  94. package/engine/object-data/entry/lightning-type.d.ts +1 -1
  95. package/engine/object-data/entry/sound-preset.d.ts +33 -0
  96. package/engine/object-data/entry/sound-preset.lua +140 -0
  97. package/engine/object-data/entry/unit-type.d.ts +10 -3
  98. package/engine/object-data/entry/unit-type.lua +155 -92
  99. package/engine/object-data/entry/upgrade.d.ts +1 -1
  100. package/engine/object-data/entry/upgrade.lua +4 -4
  101. package/engine/object-data/entry.d.ts +16 -14
  102. package/engine/object-data/entry.lua +60 -32
  103. package/engine/object-data/utility/object-data-entry-id-generator.lua +7 -0
  104. package/engine/object-field/ability.d.ts +6 -3
  105. package/engine/object-field/ability.lua +3 -0
  106. package/engine/object-field/unit.d.ts +46 -3
  107. package/engine/object-field/unit.lua +173 -7
  108. package/engine/object-field.d.ts +11 -3
  109. package/engine/object-field.lua +162 -76
  110. package/engine/standard/entries/buff-type.d.ts +3 -0
  111. package/engine/standard/entries/buff-type.lua +3 -0
  112. package/engine/standard/entries/sound-preset.d.ts +10 -0
  113. package/engine/standard/entries/sound-preset.lua +10 -0
  114. package/engine/unit.d.ts +1 -0
  115. package/engine/unit.lua +1 -0
  116. package/objutil/buff.lua +1 -2
  117. package/objutil/unit.lua +8 -0
  118. package/package.json +2 -2
  119. package/utility/arrays.d.ts +1 -0
  120. package/utility/arrays.lua +3 -0
  121. package/utility/functions.d.ts +1 -0
  122. package/utility/functions.lua +1 -0
  123. package/utility/linked-set.d.ts +1 -0
  124. package/utility/linked-set.lua +3 -0
  125. package/utility/lua-maps.d.ts +3 -0
  126. package/utility/lua-maps.lua +16 -0
  127. package/utility/lua-sets.d.ts +1 -0
  128. package/utility/lua-sets.lua +3 -0
  129. package/utility/reflection.lua +11 -7
@@ -13,6 +13,7 @@ local ____ability = require("engine.internal.item.ability")
13
13
  local abilityActionDummy = ____ability.abilityActionDummy
14
14
  local doAbilityAction = ____ability.doAbilityAction
15
15
  local doAbilityActionForceDummy = ____ability.doAbilityActionForceDummy
16
+ local startItemCooldown = ____ability.startItemCooldown
16
17
  local getUnitAbilityLevel = GetUnitAbilityLevel
17
18
  local setUnitAbilityLevel = SetUnitAbilityLevel
18
19
  local setAbilityIntegerField = BlzSetAbilityIntegerField
@@ -34,6 +35,8 @@ local getAbilityStringLevelField = BlzGetAbilityStringLevelField
34
35
  local getUnitAbilityCooldownRemaining = BlzGetUnitAbilityCooldownRemaining
35
36
  local startUnitAbilityCooldown = BlzStartUnitAbilityCooldown
36
37
  local getHandleId = GetHandleId
38
+ local getItemBooleanField = BlzGetItemBooleanField
39
+ local setItemBooleanField = BlzSetItemBooleanField
37
40
  local unitHideAbility = BlzUnitHideAbility
38
41
  local match = string.match
39
42
  local ____type = _G.type
@@ -451,11 +454,6 @@ end
451
454
  local function getAbilityCooldown(_, abilityTypeId)
452
455
  return getUnitAbilityCooldownRemaining(abilityActionDummy, abilityTypeId)
453
456
  end
454
- local function startAbilityCooldown(_, abilityTypeId, cooldown)
455
- startUnitAbilityCooldown(abilityActionDummy, abilityTypeId, cooldown)
456
- end
457
- local function doNothing()
458
- end
459
457
  ____exports.ItemAbility = __TS__Class()
460
458
  local ItemAbility = ____exports.ItemAbility
461
459
  ItemAbility.name = "ItemAbility"
@@ -484,11 +482,12 @@ function ItemAbility.prototype.setField(self, field, levelOrValue, value)
484
482
  )
485
483
  end
486
484
  function ItemAbility.prototype.interruptCast(self)
487
- local item = self.owner
488
- local ____doAbilityActionForceDummy_4 = doAbilityActionForceDummy
489
- local ____item_handle_3 = item.handle
490
- local ____opt_1 = item.owner
491
- ____doAbilityActionForceDummy_4(____item_handle_3, ____opt_1 and ____opt_1.handle, doNothing)
485
+ local handle = self.owner.handle
486
+ local activelyUsed = getItemBooleanField(handle, ITEM_BF_ACTIVELY_USED)
487
+ if activelyUsed then
488
+ setItemBooleanField(handle, ITEM_BF_ACTIVELY_USED, false)
489
+ setItemBooleanField(handle, ITEM_BF_ACTIVELY_USED, true)
490
+ end
492
491
  end
493
492
  __TS__SetDescriptor(
494
493
  ItemAbility.prototype,
@@ -504,23 +503,17 @@ __TS__SetDescriptor(
504
503
  {
505
504
  get = function(self)
506
505
  local item = self.owner
507
- local ____doAbilityActionForceDummy_8 = doAbilityActionForceDummy
508
- local ____item_handle_7 = item.handle
509
- local ____opt_5 = item.owner
510
- return ____doAbilityActionForceDummy_8(____item_handle_7, ____opt_5 and ____opt_5.handle, getAbilityCooldown, self.typeId)
506
+ local ____doAbilityActionForceDummy_4 = doAbilityActionForceDummy
507
+ local ____item_handle_3 = item.handle
508
+ local ____opt_1 = item.owner
509
+ return ____doAbilityActionForceDummy_4(____item_handle_3, ____opt_1 and ____opt_1.handle, getAbilityCooldown, self.typeId)
511
510
  end,
512
511
  set = function(self, cooldownRemaining)
513
512
  local item = self.owner
514
- local ____doAbilityActionForceDummy_12 = doAbilityActionForceDummy
515
- local ____item_handle_11 = item.handle
516
- local ____opt_9 = item.owner
517
- ____doAbilityActionForceDummy_12(
518
- ____item_handle_11,
519
- ____opt_9 and ____opt_9.handle,
520
- startAbilityCooldown,
521
- self.typeId,
522
- cooldownRemaining
523
- )
513
+ local ____startItemCooldown_8 = startItemCooldown
514
+ local ____item_handle_7 = item.handle
515
+ local ____opt_5 = item.owner
516
+ ____startItemCooldown_8(____item_handle_7, ____opt_5 and ____opt_5.handle, cooldownRemaining)
524
517
  end
525
518
  },
526
519
  true
@@ -1,19 +1,60 @@
1
1
  local ____exports = {}
2
+ local restoreCooldownGroup
2
3
  local ____player = require("core.types.player")
3
4
  local Player = ____player.Player
4
5
  local ____dummy = require("objutil.dummy")
5
6
  local dummyUnitId = ____dummy.dummyUnitId
6
7
  local ____utility = require("engine.internal.utility")
7
8
  local findUnitItemSlot = ____utility.findUnitItemSlot
9
+ local ____blank = require("engine.object-data.entry.item-type.blank")
10
+ local BlankItemType = ____blank.BlankItemType
11
+ local ____object_2Ddata_2Dentry_2Did_2Dgenerator = require("engine.object-data.utility.object-data-entry-id-generator")
12
+ local abilityTypeIdGenerator = ____object_2Ddata_2Dentry_2Did_2Dgenerator.abilityTypeIdGenerator
13
+ local ____math = require("math")
14
+ local MINIMUM_POSITIVE_NORMALIZED_FLOAT = ____math.MINIMUM_POSITIVE_NORMALIZED_FLOAT
15
+ local ____timer = require("core.types.timer")
16
+ local Timer = ____timer.Timer
17
+ local ____ignore_2Devents_2Ditems = require("engine.internal.unit.ignore-events-items")
18
+ local ignoreEventsItems = ____ignore_2Devents_2Ditems.ignoreEventsItems
19
+ local ____add_2Ditem_2Dto_2Dslot = require("engine.internal.unit.add-item-to-slot")
20
+ local unitAddItemToSlot = ____add_2Ditem_2Dto_2Dslot.unitAddItemToSlot
8
21
  local isItemOwned = IsItemOwned
9
22
  local isItemPowerup = IsItemPowerup
10
23
  local getItemX = GetItemX
11
24
  local getItemY = GetItemY
25
+ local setAbilityRealLevelField = BlzSetAbilityRealLevelField
26
+ local setItemIntegerField = BlzSetItemIntegerField
27
+ local getItemIntegerField = BlzGetItemIntegerField
12
28
  local setItemBooleanField = BlzSetItemBooleanField
13
29
  local setItemPosition = SetItemPosition
14
30
  local unitAddItem = UnitAddItem
15
- local unitDropItemSlot = UnitDropItemSlot
16
31
  local unitRemoveItem = UnitRemoveItem
32
+ local unitUseItem = UnitUseItem
33
+ local unitResetCooldown = UnitResetCooldown
34
+ local COOLDOWN_STARTER_ABILITY_TYPE_ID = compiletime(function()
35
+ if not currentMap then
36
+ return 0
37
+ end
38
+ local abilityType = currentMap.objects.ability:newObject(
39
+ util.id2s(abilityTypeIdGenerator:next()),
40
+ "Absk"
41
+ )
42
+ abilityType["bsk1+0"] = 0
43
+ abilityType["bsk2+0"] = 0
44
+ abilityType["bsk3+0"] = 0
45
+ abilityType["amcs+0"] = 0
46
+ abilityType["adur+0"] = MINIMUM_POSITIVE_NORMALIZED_FLOAT
47
+ abilityType["ahdu+0"] = MINIMUM_POSITIVE_NORMALIZED_FLOAT
48
+ return util.s2id(abilityType.id)
49
+ end)
50
+ local COOLDOWN_STARTER_ITEM_TYPE_ID = compiletime(function()
51
+ local itemType = BlankItemType:create()
52
+ itemType.name = "[Warscript/Dummy] Item Cooldown Starter"
53
+ itemType.abilityTypeIds = {COOLDOWN_STARTER_ABILITY_TYPE_ID}
54
+ itemType.cooldownGroupId = COOLDOWN_STARTER_ABILITY_TYPE_ID
55
+ itemType.activelyUsed = true
56
+ return itemType.id
57
+ end)
17
58
  local dummy = assert(CreateUnit(
18
59
  Player.neutralVictim.handle,
19
60
  dummyUnitId,
@@ -21,13 +62,37 @@ local dummy = assert(CreateUnit(
21
62
  0,
22
63
  270
23
64
  ))
65
+ local cooldownStarterItem = UnitAddItemById(dummy, COOLDOWN_STARTER_ITEM_TYPE_ID)
66
+ local cooldownStarterAbility = BlzGetItemAbility(cooldownStarterItem, COOLDOWN_STARTER_ABILITY_TYPE_ID)
24
67
  ShowUnit(dummy, false)
68
+ local function startItemCooldownInternal(handle, cooldown)
69
+ local cooldownGroup = getItemIntegerField(handle, ITEM_IF_COOLDOWN_GROUP)
70
+ setItemIntegerField(handle, ITEM_IF_COOLDOWN_GROUP, COOLDOWN_STARTER_ABILITY_TYPE_ID)
71
+ setAbilityRealLevelField(cooldownStarterAbility, ABILITY_RLF_COOLDOWN, 0, cooldown)
72
+ unitResetCooldown(dummy)
73
+ unitUseItem(dummy, cooldownStarterItem)
74
+ Timer:run(restoreCooldownGroup, handle, cooldownGroup)
75
+ end
76
+ restoreCooldownGroup = function(handle, cooldownGroup)
77
+ if getItemIntegerField(handle, ITEM_IF_COOLDOWN_GROUP) == COOLDOWN_STARTER_ABILITY_TYPE_ID then
78
+ setItemIntegerField(handle, ITEM_IF_COOLDOWN_GROUP, cooldownGroup)
79
+ end
80
+ end
81
+ ---
82
+ -- @internal For use by internal systems only.
83
+ ____exports.startItemCooldown = function(handle, owner, cooldown)
84
+ ____exports.doAbilityActionForceDummy(handle, owner, startItemCooldownInternal, cooldown)
85
+ end
25
86
  ---
26
87
  -- @internal For use by internal systems only.
27
88
  ____exports.abilityActionDummy = dummy
28
89
  ---
29
90
  -- @internal For use by internal systems only.
30
91
  ____exports.doAbilityAction = function(handle, action, ...)
92
+ local isAlreadyIgnoredInEvents = ignoreEventsItems[handle] ~= nil
93
+ if not isAlreadyIgnoredInEvents then
94
+ ignoreEventsItems[handle] = true
95
+ end
31
96
  local isOwned = isItemOwned(handle)
32
97
  local isPowerup
33
98
  local x
@@ -49,6 +114,9 @@ ____exports.doAbilityAction = function(handle, action, ...)
49
114
  setItemBooleanField(handle, ITEM_BF_USE_AUTOMATICALLY_WHEN_ACQUIRED, true)
50
115
  end
51
116
  end
117
+ if not isAlreadyIgnoredInEvents then
118
+ ignoreEventsItems[handle] = nil
119
+ end
52
120
  return result
53
121
  end
54
122
  ---
@@ -61,6 +129,10 @@ ____exports.doAbilityActionForceDummy = function(handle, owner, action, ...)
61
129
  if slot == nil then
62
130
  return ____exports.doAbilityAction(handle, action, ...)
63
131
  end
132
+ local isAlreadyIgnoredInEvents = ignoreEventsItems[handle] ~= nil
133
+ if not isAlreadyIgnoredInEvents then
134
+ ignoreEventsItems[handle] = true
135
+ end
64
136
  local isPowerup
65
137
  if isItemPowerup(handle) then
66
138
  setItemBooleanField(handle, ITEM_BF_USE_AUTOMATICALLY_WHEN_ACQUIRED, false)
@@ -70,11 +142,13 @@ ____exports.doAbilityActionForceDummy = function(handle, owner, action, ...)
70
142
  unitAddItem(dummy, handle)
71
143
  local result = action(handle, ...)
72
144
  unitRemoveItem(dummy, handle)
73
- unitAddItem(owner, handle)
74
- unitDropItemSlot(owner, handle, slot)
145
+ unitAddItemToSlot(owner, handle, slot)
75
146
  if isPowerup then
76
147
  setItemBooleanField(handle, ITEM_BF_USE_AUTOMATICALLY_WHEN_ACQUIRED, true)
77
148
  end
149
+ if not isAlreadyIgnoredInEvents then
150
+ ignoreEventsItems[handle] = nil
151
+ end
78
152
  return result
79
153
  end
80
154
  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);
@@ -78,9 +79,9 @@ export declare class Item extends Handle<jitem> {
78
79
  hasAbility(abilityTypeId: AbilityTypeId): boolean;
79
80
  getAbility(abilityTypeId: AbilityTypeId): ItemAbility | undefined;
80
81
  get abilities(): readonly ItemAbility[];
81
- static getInRange(pos: Vec2, range: number): Item[];
82
+ static getInRange(x: number, y: number, range: number): Item[];
82
83
  static getInRect(rect: ReadonlyRect): Item[];
83
84
  static get onCreate(): Event<[Item]>;
84
- static get onDestroy(): Event<[Item]>;
85
+ static get destroyEvent(): Event<[Item]>;
85
86
  }
86
87
  export {};
@@ -15,6 +15,12 @@ local ____ability = require("engine.internal.ability")
15
15
  local ItemAbility = ____ability.ItemAbility
16
16
  local ____ability = require("engine.internal.item.ability")
17
17
  local doAbilityAction = ____ability.doAbilityAction
18
+ local ____dummy_2Ditem = require("engine.internal.object-data.dummy-item")
19
+ local DUMMY_ITEM_ID = ____dummy_2Ditem.DUMMY_ITEM_ID
20
+ local ____add_2Ditem_2Dto_2Dslot = require("engine.internal.unit.add-item-to-slot")
21
+ local SLOT_FILLER_ITEM_TYPE_ID = ____add_2Ditem_2Dto_2Dslot.SLOT_FILLER_ITEM_TYPE_ID
22
+ local ____vec2 = require("math.vec2")
23
+ local distance = ____vec2.distance
18
24
  local itemAddAbility = BlzItemAddAbility
19
25
  local itemRemoveAbility = BlzItemRemoveAbility
20
26
  local getItemAbility = BlzGetItemAbility
@@ -24,6 +30,12 @@ local getAbilityId = BlzGetAbilityId
24
30
  local getWidgetLife = GetWidgetLife
25
31
  local removeItem = RemoveItem
26
32
  local getHandleId = GetHandleId
33
+ local setRect = SetRect
34
+ local enumItemsInRect = EnumItemsInRect
35
+ local getEnumItem = GetEnumItem
36
+ local getItemTypeId = GetItemTypeId
37
+ local getItemX = GetItemX
38
+ local getItemY = GetItemY
27
39
  local getItemIntegerField = BlzGetItemIntegerField
28
40
  local setItemBooleanField = BlzSetItemBooleanField
29
41
  local getItemBooleanField = BlzGetItemBooleanField
@@ -53,6 +65,32 @@ local function getItemAbilities(handle, item)
53
65
  end
54
66
  return abilities
55
67
  end
68
+ local targetCollection
69
+ local targetCollectionNextIndex
70
+ local centerX
71
+ local centerY
72
+ local enumRange
73
+ local function collectIntoTarget()
74
+ local item = getEnumItem()
75
+ local typeId = getItemTypeId(item)
76
+ if typeId ~= DUMMY_ITEM_ID and typeId ~= SLOT_FILLER_ITEM_TYPE_ID then
77
+ targetCollection[targetCollectionNextIndex] = ____exports.Item:of(item)
78
+ targetCollectionNextIndex = targetCollectionNextIndex + 1
79
+ end
80
+ end
81
+ local function collectIntoTargetRange()
82
+ local item = getEnumItem()
83
+ local typeId = getItemTypeId(item)
84
+ if distance(
85
+ getItemX(item),
86
+ getItemY(item),
87
+ centerX,
88
+ centerY
89
+ ) <= enumRange and typeId ~= DUMMY_ITEM_ID and typeId ~= SLOT_FILLER_ITEM_TYPE_ID then
90
+ targetCollection[targetCollectionNextIndex] = ____exports.Item:of(item)
91
+ targetCollectionNextIndex = targetCollectionNextIndex + 1
92
+ end
93
+ end
56
94
  ____exports.Item = __TS__Class()
57
95
  local Item = ____exports.Item
58
96
  Item.name = "Item"
@@ -111,34 +149,27 @@ function Item.prototype.getAbility(self, abilityTypeId)
111
149
  local ability = self[101][abilityTypeId] ~= nil and doAbilityAction(self.handle, getItemAbility, abilityTypeId)
112
150
  return ability and ItemAbility:of(ability, abilityTypeId, self) or nil
113
151
  end
114
- function Item.getInRange(self, pos, range)
115
- local collection = {}
116
- SetRect(
152
+ function Item.getInRange(self, x, y, range)
153
+ targetCollection = {}
154
+ targetCollectionNextIndex = 1
155
+ centerX = x
156
+ centerY = y
157
+ enumRange = range
158
+ setRect(
117
159
  enumRect,
118
- pos.x - range,
119
- pos.y - range,
120
- pos.x + range,
121
- pos.y + range
160
+ x - range,
161
+ y - range,
162
+ x + range,
163
+ y + range
122
164
  )
123
- EnumItemsInRect(
124
- enumRect,
125
- nil,
126
- function()
127
- collection[#collection + 1] = self:of(GetEnumItem())
128
- end
129
- )
130
- return collection
165
+ enumItemsInRect(enumRect, nil, collectIntoTargetRange)
166
+ return targetCollection
131
167
  end
132
168
  function Item.getInRect(self, rect)
133
- local collection = {}
134
- EnumItemsInRect(
135
- rect.handle,
136
- nil,
137
- function()
138
- collection[#collection + 1] = self:of(GetEnumItem())
139
- end
140
- )
141
- return collection
169
+ targetCollection = {}
170
+ targetCollectionNextIndex = 1
171
+ enumItemsInRect(rect.handle, nil, collectIntoTarget)
172
+ return targetCollection
142
173
  end
143
174
  __TS__SetDescriptor(
144
175
  Item.prototype,
@@ -551,7 +582,7 @@ __TS__ObjectDefineProperty(
551
582
  )
552
583
  __TS__ObjectDefineProperty(
553
584
  Item,
554
- "onDestroy",
585
+ "destroyEvent",
555
586
  {get = function(self)
556
587
  return self.onDestroyEvent
557
588
  end}
@@ -8,6 +8,6 @@ local DURATION_NORMAL_ABILITY_FLOAT_LEVEL_FIELD = ____ability.DURATION_NORMAL_AB
8
8
  -- @internal For use by internal systems only.
9
9
  ____exports.getAbilityDuration = function(ability, target)
10
10
  local level = ability.level
11
- return target ~= nil and target:hasClassification(UnitClassification.RESISTANT) and DURATION_HERO_ABILITY_FLOAT_LEVEL_FIELD:getValue(ability, level) or DURATION_NORMAL_ABILITY_FLOAT_LEVEL_FIELD:getValue(ability, level)
11
+ return target ~= nil and (target.isHero or target:getField(UNIT_IF_LEVEL) >= 6 or target:hasClassification(UnitClassification.RESISTANT)) and DURATION_HERO_ABILITY_FLOAT_LEVEL_FIELD:getValue(ability, level) or DURATION_NORMAL_ABILITY_FLOAT_LEVEL_FIELD:getValue(ability, level)
12
12
  end
13
13
  return ____exports
@@ -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,2 +1,2 @@
1
1
  /** @noSelfInFile */
2
- export declare const AUTO_ATTACK_SPEED_INCREASE_FACTOR_ABILITY_FIELD: jabilityreallevelfield;
2
+ export {};
@@ -10,5 +10,7 @@ ____exports.AUTO_ATTACK_SPEED_INCREASE_DUMMY_ABILITY_TYPE_ID = compiletime(funct
10
10
  abilityType.autoAttackSpeedIncreaseFactor = 0
11
11
  return abilityType.id
12
12
  end)
13
+ ---
14
+ -- @internal For use by internal systems.
13
15
  ____exports.AUTO_ATTACK_SPEED_INCREASE_FACTOR_ABILITY_FIELD = ABILITY_RLF_ATTACK_SPEED_INCREASE_ISX1
14
16
  return ____exports
@@ -0,0 +1,2 @@
1
+ /** @noSelfInFile */
2
+ export {};
@@ -0,0 +1,16 @@
1
+ local ____exports = {}
2
+ local ____evasion = require("engine.object-data.entry.ability-type.evasion")
3
+ local EvasionAbilityType = ____evasion.EvasionAbilityType
4
+ ---
5
+ -- @internal For use by internal systems.
6
+ ____exports.EVASION_PROBABILITY_DUMMY_ABILITY_TYPE_ID = compiletime(function()
7
+ local abilityType = EvasionAbilityType:create()
8
+ abilityType.isInternal = true
9
+ abilityType.isButtonVisible = false
10
+ abilityType.evasionProbability = 0
11
+ return abilityType.id
12
+ end)
13
+ ---
14
+ -- @internal For use by internal systems.
15
+ ____exports.EVASION_PROBABILITY_ABILITY_FIELD = ABILITY_RLF_CHANCE_TO_EVADE_EEV1
16
+ return ____exports
@@ -0,0 +1,2 @@
1
+ /** @noSelfInFile */
2
+ export {};
@@ -0,0 +1,23 @@
1
+ local ____exports = {}
2
+ local ____unit = require("engine.internal.unit")
3
+ local Unit = ____unit.Unit
4
+ local ____add_2Ditem_2Dto_2Dslot = require("engine.internal.unit.add-item-to-slot")
5
+ local fillerItems = ____add_2Ditem_2Dto_2Dslot.fillerItems
6
+ local unitsWithFillerItems = ____add_2Ditem_2Dto_2Dslot.unitsWithFillerItems
7
+ local setItemVisible = SetItemVisible
8
+ local unitRemoveItem = UnitRemoveItem
9
+ Unit.itemPickedUpEvent:addListener(
10
+ 4,
11
+ function(unit)
12
+ local handle = unit.handle
13
+ if unitsWithFillerItems[handle] ~= nil then
14
+ for previousSlot = 1, 6 do
15
+ local fillerItem = fillerItems[previousSlot]
16
+ unitRemoveItem(handle, fillerItem)
17
+ setItemVisible(fillerItem, false)
18
+ end
19
+ unitsWithFillerItems[handle] = nil
20
+ end
21
+ end
22
+ )
23
+ return ____exports
@@ -0,0 +1,2 @@
1
+ /** @noSelfInFile */
2
+ export {};
@@ -0,0 +1,52 @@
1
+ local ____exports = {}
2
+ local ____blank = require("engine.object-data.entry.item-type.blank")
3
+ local BlankItemType = ____blank.BlankItemType
4
+ local ____arrays = require("utility.arrays")
5
+ local array = ____arrays.array
6
+ local ____ignore_2Devents_2Ditems = require("engine.internal.unit.ignore-events-items")
7
+ local ignoreEventsItems = ____ignore_2Devents_2Ditems.ignoreEventsItems
8
+ local setItemVisible = SetItemVisible
9
+ local unitAddItem = UnitAddItem
10
+ local unitItemInSlot = UnitItemInSlot
11
+ local unitRemoveItem = UnitRemoveItem
12
+ ---
13
+ -- @internal For use by internal systems only.
14
+ ____exports.SLOT_FILLER_ITEM_TYPE_ID = compiletime(function()
15
+ local itemType = BlankItemType:create()
16
+ itemType.name = "[Warscript/Dummy] Slot Filler"
17
+ return itemType.id
18
+ end)
19
+ ---
20
+ -- @internal For use by internal systems only.
21
+ ____exports.fillerItems = array(
22
+ 6,
23
+ function()
24
+ local item = CreateItem(____exports.SLOT_FILLER_ITEM_TYPE_ID, 0, 0)
25
+ setItemVisible(item, false)
26
+ ignoreEventsItems[item] = true
27
+ return item
28
+ end
29
+ )
30
+ ---
31
+ -- @internal For use by internal systems only.
32
+ ____exports.unitsWithFillerItems = {}
33
+ ---
34
+ -- @internal For use by internal systems only.
35
+ ____exports.unitAddItemToSlot = function(unit, item, slot)
36
+ for previousSlot = 0, slot - 1 do
37
+ if unitItemInSlot(unit, previousSlot) == nil then
38
+ unitAddItem(unit, ____exports.fillerItems[previousSlot + 1])
39
+ ____exports.unitsWithFillerItems[unit] = true
40
+ end
41
+ end
42
+ unitAddItem(unit, item)
43
+ if ____exports.unitsWithFillerItems[unit] ~= nil then
44
+ for previousSlot = 0, slot - 1 do
45
+ local fillerItem = ____exports.fillerItems[previousSlot + 1]
46
+ unitRemoveItem(unit, fillerItem)
47
+ setItemVisible(fillerItem, false)
48
+ end
49
+ ____exports.unitsWithFillerItems[unit] = nil
50
+ end
51
+ end
52
+ return ____exports
@@ -11,6 +11,7 @@ export type UnitMovementSpeedFactorBonusId = UnitBonusId<"movementSpeedFactor">;
11
11
  export type UnitAutoAttackDamageBonusId = UnitBonusId<"autoAttackDamage">;
12
12
  export type UnitDamageFactorBonusId = UnitBonusId<"damageFactor">;
13
13
  export type UnitReceivedDamageFactorBonusId = UnitBonusId<"receivedDamageFactor">;
14
+ export type UnitEvasionProbabilityBonusId = UnitBonusId<"evasionProbability">;
14
15
  export type UnitBonusType<Id extends UnitBonusId = UnitBonusId> = ({
15
16
  abilityTypeId: AbilityTypeId;
16
17
  field: jabilityintegerlevelfield;
@@ -34,6 +35,7 @@ export declare namespace UnitBonusType {
34
35
  const AUTO_ATTACK_DAMAGE: UnitBonusType<UnitAutoAttackDamageBonusId>;
35
36
  const DAMAGE_FACTOR: UnitBonusType<UnitReceivedDamageFactorBonusId>;
36
37
  const RECEIVED_DAMAGE_FACTOR: UnitBonusType<UnitReceivedDamageFactorBonusId>;
38
+ const EVASION_PROBABILITY: UnitBonusType<UnitEvasionProbabilityBonusId>;
37
39
  }
38
40
  export declare const addUnitBonus: <Id extends UnitBonusId>(unit: Unit, bonusType: UnitBonusType<Id>, value: number) => Id;
39
41
  export declare const removeUnitBonus: <Id extends UnitBonusId>(unit: Unit, bonusType: UnitBonusType<Id>, id: Id) => boolean;
@@ -21,8 +21,18 @@ local AUTO_ATTACK_DAMAGE_INCREASE_DUMMY_ABILITY_TYPE_ID = ____auto_2Dattack_2Dda
21
21
  local ____movement_2Dspeed_2Dincrease_2Dfactor = require("engine.internal.object-data.movement-speed-increase-factor")
22
22
  local MOVEMENT_SPEED_INCREASE_FACTOR_ABILITY_FIELD = ____movement_2Dspeed_2Dincrease_2Dfactor.MOVEMENT_SPEED_INCREASE_FACTOR_ABILITY_FIELD
23
23
  local MOVEMENT_SPEED_INCREASE_FACTOR_DUMMY_ABILITY_TYPE_ID = ____movement_2Dspeed_2Dincrease_2Dfactor.MOVEMENT_SPEED_INCREASE_FACTOR_DUMMY_ABILITY_TYPE_ID
24
+ local ____evasion_2Dprobability = require("engine.internal.object-data.evasion-probability")
25
+ local EVASION_PROBABILITY_ABILITY_FIELD = ____evasion_2Dprobability.EVASION_PROBABILITY_ABILITY_FIELD
26
+ local EVASION_PROBABILITY_DUMMY_ABILITY_TYPE_ID = ____evasion_2Dprobability.EVASION_PROBABILITY_DUMMY_ABILITY_TYPE_ID
24
27
  local damageFactorByUnit = {}
25
28
  local receivedDamageFactorByUnit = {}
29
+ local function atLeastOnceProbability(array)
30
+ local oppositeEventProbability = 1
31
+ for i = 1, #array do
32
+ oppositeEventProbability = oppositeEventProbability * (1 - array[i])
33
+ end
34
+ return 1 - oppositeEventProbability
35
+ end
26
36
  ____exports.UnitBonusType = {}
27
37
  local UnitBonusType = ____exports.UnitBonusType
28
38
  do
@@ -56,6 +66,13 @@ do
56
66
  }
57
67
  UnitBonusType.DAMAGE_FACTOR = {reduce = product, valueByUnit = damageFactorByUnit, initialValue = 1}
58
68
  UnitBonusType.RECEIVED_DAMAGE_FACTOR = {reduce = product, valueByUnit = receivedDamageFactorByUnit, initialValue = 1}
69
+ UnitBonusType.EVASION_PROBABILITY = {
70
+ abilityTypeId = EVASION_PROBABILITY_DUMMY_ABILITY_TYPE_ID,
71
+ field = EVASION_PROBABILITY_ABILITY_FIELD,
72
+ integer = false,
73
+ reduce = atLeastOnceProbability,
74
+ initialValue = 0
75
+ }
59
76
  end
60
77
  local bonusesByUnitByBonusType = {}
61
78
  local nextId = 1
@@ -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.ignoreEventsItems = {}
5
+ return ____exports
@@ -9,12 +9,12 @@ local ____unit = require("engine.internal.unit")
9
9
  local Unit = ____unit.Unit
10
10
  local ____utility = require("engine.internal.utility")
11
11
  local findUnitItemSlot = ____utility.findUnitItemSlot
12
+ local ____add_2Ditem_2Dto_2Dslot = require("engine.internal.unit.add-item-to-slot")
13
+ local unitAddItemToSlot = ____add_2Ditem_2Dto_2Dslot.unitAddItemToSlot
12
14
  local rawset = _G.rawset
13
15
  local ____type = _G.type
14
16
  local isItemPowerup = IsItemPowerup
15
17
  local setItemBooleanField = BlzSetItemBooleanField
16
- local unitAddItem = UnitAddItem
17
- local unitDropItemSlot = UnitDropItemSlot
18
18
  local unitInventorySize = UnitInventorySize
19
19
  local unitItemInSlot = UnitItemInSlot
20
20
  local unitRemoveItemFromSlot = UnitRemoveItemFromSlot
@@ -47,8 +47,7 @@ function UnitItems.prototype.__newindex(self, slot, item)
47
47
  if isPowerup then
48
48
  setItemBooleanField(itemHandle, ITEM_BF_USE_AUTOMATICALLY_WHEN_ACQUIRED, false)
49
49
  end
50
- unitAddItem(handle, itemHandle)
51
- unitDropItemSlot(handle, itemHandle, slot - 1)
50
+ unitAddItemToSlot(handle, itemHandle, slot - 1)
52
51
  if isPowerup then
53
52
  setItemBooleanField(itemHandle, ITEM_BF_USE_AUTOMATICALLY_WHEN_ACQUIRED, true)
54
53
  end
@@ -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
  }