warscript 0.0.1-dev.6745db1 → 0.0.1-dev.68702bb

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 (42) hide show
  1. package/core/types/frame.lua +14 -9
  2. package/core/types/playerCamera.lua +44 -0
  3. package/core/types/tileCell.d.ts +9 -0
  4. package/core/types/tileCell.lua +92 -0
  5. package/core/types/timer.d.ts +3 -2
  6. package/core/types/timer.lua +22 -2
  7. package/decl/native.d.ts +2 -2
  8. package/engine/behavior.d.ts +3 -0
  9. package/engine/behavior.lua +53 -0
  10. package/engine/behaviour/unit/stun-immunity.d.ts +2 -0
  11. package/engine/behaviour/unit/stun-immunity.lua +11 -2
  12. package/engine/behaviour/unit.d.ts +8 -2
  13. package/engine/behaviour/unit.lua +29 -2
  14. package/engine/buff.d.ts +0 -3
  15. package/engine/buff.lua +59 -80
  16. package/engine/internal/ability.d.ts +3 -1
  17. package/engine/internal/ability.lua +26 -9
  18. package/engine/internal/item.d.ts +13 -15
  19. package/engine/internal/item.lua +58 -49
  20. package/engine/internal/unit/ability.d.ts +14 -14
  21. package/engine/internal/unit/ability.lua +72 -45
  22. package/engine/internal/unit-missile-launch.lua +16 -10
  23. package/engine/internal/unit.d.ts +2 -2
  24. package/engine/internal/unit.lua +10 -12
  25. package/engine/object-data/entry/ability-type.lua +4 -1
  26. package/engine/object-field/ability.d.ts +3 -3
  27. package/engine/object-field/ability.lua +7 -6
  28. package/engine/object-field.d.ts +2 -2
  29. package/engine/object-field.lua +8 -6
  30. package/engine/random.d.ts +9 -0
  31. package/engine/random.lua +13 -0
  32. package/engine/text-tag.lua +1 -1
  33. package/objutil/buff.lua +1 -1
  34. package/package.json +2 -2
  35. package/patch-lualib.lua +1 -1
  36. package/utility/arrays.d.ts +1 -0
  37. package/utility/arrays.lua +8 -0
  38. package/utility/callback-array.d.ts +17 -0
  39. package/utility/callback-array.lua +61 -0
  40. package/utility/lua-maps.d.ts +11 -2
  41. package/utility/lua-maps.lua +33 -2
  42. package/utility/types.d.ts +3 -0
package/engine/buff.lua CHANGED
@@ -28,9 +28,6 @@ local ____math = require("math")
28
28
  local max = ____math.max
29
29
  local min = ____math.min
30
30
  local ____bonus = require("engine.internal.unit.bonus")
31
- local addOrUpdateOrRemoveUnitBonus = ____bonus.addOrUpdateOrRemoveUnitBonus
32
- local getUnitBonus = ____bonus.getUnitBonus
33
- local removeUnitBonus = ____bonus.removeUnitBonus
34
31
  local UnitBonusType = ____bonus.UnitBonusType
35
32
  local ____area_2Ddamage = require("engine.internal.mechanics.area-damage")
36
33
  local damageArea = ____area_2Ddamage.damageArea
@@ -509,63 +506,50 @@ function Buff.prototype.____constructor(self, _unit, typeIdOrTypeIds, polarityOr
509
506
  self[100] = 1
510
507
  Event.invoke(buffCreatedEvent, self)
511
508
  end
512
- function Buff.prototype.getUnitBonus(self, bonusType)
513
- local ____opt_38 = self._bonusIdByBonusType
514
- local bonusId = ____opt_38 and ____opt_38[bonusType]
515
- return bonusId == nil and 0 or getUnitBonus(self._unit, bonusType, bonusId)
516
- end
517
- function Buff.prototype.addOrUpdateOrRemoveUnitBonus(self, bonusType, value)
518
- local bonusIdByBonusType = self._bonusIdByBonusType
519
- if bonusIdByBonusType == nil then
520
- bonusIdByBonusType = {}
521
- self._bonusIdByBonusType = bonusIdByBonusType
522
- end
523
- bonusIdByBonusType[bonusType] = addOrUpdateOrRemoveUnitBonus(self._unit, bonusType, bonusIdByBonusType[bonusType], value)
524
- end
525
509
  function Buff.prototype.flashEffect(self, widgetOrXOrParametersOrDuration, yOrParametersOrDuration, parametersOrDuration)
526
510
  if type(widgetOrXOrParametersOrDuration) == "number" and type(yOrParametersOrDuration) == "number" then
527
511
  Effect:flash(self[105], widgetOrXOrParametersOrDuration, yOrParametersOrDuration, parametersOrDuration)
528
512
  else
529
513
  local isWidgetProvided = __TS__InstanceOf(widgetOrXOrParametersOrDuration, Unit) or __TS__InstanceOf(widgetOrXOrParametersOrDuration, Item) or __TS__InstanceOf(widgetOrXOrParametersOrDuration, Destructable)
530
- local ____Effect_42 = Effect
531
- local ____Effect_flash_43 = Effect.flash
532
- local ____array_41 = __TS__SparseArrayNew(
514
+ local ____Effect_40 = Effect
515
+ local ____Effect_flash_41 = Effect.flash
516
+ local ____array_39 = __TS__SparseArrayNew(
533
517
  self[105],
534
518
  isWidgetProvided and widgetOrXOrParametersOrDuration or self._unit,
535
519
  stringValueByBuffTypeIdByFieldId[fourCC("feft")][self.typeId] or "origin"
536
520
  )
537
- local ____isWidgetProvided_40
521
+ local ____isWidgetProvided_38
538
522
  if isWidgetProvided then
539
- ____isWidgetProvided_40 = yOrParametersOrDuration
523
+ ____isWidgetProvided_38 = yOrParametersOrDuration
540
524
  else
541
- ____isWidgetProvided_40 = widgetOrXOrParametersOrDuration
525
+ ____isWidgetProvided_38 = widgetOrXOrParametersOrDuration
542
526
  end
543
- __TS__SparseArrayPush(____array_41, ____isWidgetProvided_40)
544
- ____Effect_flash_43(
545
- ____Effect_42,
546
- __TS__SparseArraySpread(____array_41)
527
+ __TS__SparseArrayPush(____array_39, ____isWidgetProvided_38)
528
+ ____Effect_flash_41(
529
+ ____Effect_40,
530
+ __TS__SparseArraySpread(____array_39)
547
531
  )
548
532
  end
549
533
  end
550
534
  function Buff.prototype.flashSpecialEffect(self, widgetOrDuration, duration)
551
535
  local isWidgetProvided = type(widgetOrDuration) == "table"
552
- local ____Effect_46 = Effect
553
- local ____Effect_flash_47 = Effect.flash
554
- local ____array_45 = __TS__SparseArrayNew(
536
+ local ____Effect_44 = Effect
537
+ local ____Effect_flash_45 = Effect.flash
538
+ local ____array_43 = __TS__SparseArrayNew(
555
539
  self[106],
556
540
  isWidgetProvided and widgetOrDuration or self._unit,
557
541
  stringValueByBuffTypeIdByFieldId[fourCC("fspt")][self.typeId] or "origin"
558
542
  )
559
- local ____isWidgetProvided_44
543
+ local ____isWidgetProvided_42
560
544
  if isWidgetProvided then
561
- ____isWidgetProvided_44 = duration
545
+ ____isWidgetProvided_42 = duration
562
546
  else
563
- ____isWidgetProvided_44 = widgetOrDuration
547
+ ____isWidgetProvided_42 = widgetOrDuration
564
548
  end
565
- __TS__SparseArrayPush(____array_45, ____isWidgetProvided_44)
566
- ____Effect_flash_47(
567
- ____Effect_46,
568
- __TS__SparseArraySpread(____array_45)
549
+ __TS__SparseArrayPush(____array_43, ____isWidgetProvided_42)
550
+ ____Effect_flash_45(
551
+ ____Effect_44,
552
+ __TS__SparseArraySpread(____array_43)
569
553
  )
570
554
  end
571
555
  function Buff.prototype.onCreate(self)
@@ -616,11 +600,6 @@ function Buff.prototype.onDestroy(self)
616
600
  unit:removeAbility(abilityTypeId)
617
601
  end
618
602
  end
619
- if self._bonusIdByBonusType ~= nil then
620
- for bonusType, bonusId in pairs(self._bonusIdByBonusType) do
621
- removeUnitBonus(unit, bonusType, bonusId)
622
- end
623
- end
624
603
  Event.invoke(buffBeingDestroyedEvent, self)
625
604
  self[100] = 3
626
605
  return UnitBehavior.prototype.onDestroy(self)
@@ -650,8 +629,8 @@ function Buff.apply(self, ...)
650
629
  end
651
630
  end
652
631
  function Buff.getByTypeId(self, unit, typeId)
653
- local ____opt_48 = buffByTypeIdByUnit[unit]
654
- local buff = ____opt_48 and ____opt_48[typeId]
632
+ local ____opt_46 = buffByTypeIdByUnit[unit]
633
+ local buff = ____opt_46 and ____opt_46[typeId]
655
634
  if __TS__InstanceOf(buff, self) then
656
635
  return buff
657
636
  end
@@ -809,8 +788,8 @@ __TS__SetDescriptor(
809
788
  return
810
789
  end
811
790
  self[112] = damageInterval
812
- local ____opt_50 = self._timer
813
- local elapsed = ____opt_50 and ____opt_50.elapsed or 0
791
+ local ____opt_48 = self._timer
792
+ local elapsed = ____opt_48 and ____opt_48.elapsed or 0
814
793
  local timer = self[114]
815
794
  if timer == nil then
816
795
  timer = Timer:create()
@@ -889,8 +868,8 @@ __TS__SetDescriptor(
889
868
  return
890
869
  end
891
870
  self[117] = healingInterval
892
- local ____opt_52 = self._timer
893
- local elapsed = ____opt_52 and ____opt_52.elapsed or 0
871
+ local ____opt_50 = self._timer
872
+ local elapsed = ____opt_50 and ____opt_50.elapsed or 0
894
873
  local timer = self[119]
895
874
  if timer == nil then
896
875
  timer = Timer:create()
@@ -976,11 +955,11 @@ __TS__SetDescriptor(
976
955
  "turnsIntoGhost",
977
956
  {
978
957
  get = function(self)
979
- local ____self__135_54 = self[135]
980
- if ____self__135_54 == nil then
981
- ____self__135_54 = false
958
+ local ____self__135_52 = self[135]
959
+ if ____self__135_52 == nil then
960
+ ____self__135_52 = false
982
961
  end
983
- return ____self__135_54
962
+ return ____self__135_52
984
963
  end,
985
964
  set = function(self, turnsIntoGhost)
986
965
  if not turnsIntoGhost and self[135] then
@@ -999,11 +978,11 @@ __TS__SetDescriptor(
999
978
  "stuns",
1000
979
  {
1001
980
  get = function(self)
1002
- local ____self__136_55 = self[136]
1003
- if ____self__136_55 == nil then
1004
- ____self__136_55 = false
981
+ local ____self__136_53 = self[136]
982
+ if ____self__136_53 == nil then
983
+ ____self__136_53 = false
1005
984
  end
1006
- return ____self__136_55
985
+ return ____self__136_53
1007
986
  end,
1008
987
  set = function(self, stuns)
1009
988
  if not stuns and self[136] then
@@ -1028,11 +1007,11 @@ __TS__SetDescriptor(
1028
1007
  "ignoresStunImmunity",
1029
1008
  {
1030
1009
  get = function(self)
1031
- local ____self__137_56 = self[137]
1032
- if ____self__137_56 == nil then
1033
- ____self__137_56 = false
1010
+ local ____self__137_54 = self[137]
1011
+ if ____self__137_54 == nil then
1012
+ ____self__137_54 = false
1034
1013
  end
1035
- return ____self__137_56
1014
+ return ____self__137_54
1036
1015
  end,
1037
1016
  set = function(self, ignoresStunImmunity)
1038
1017
  if not ignoresStunImmunity and self[137] then
@@ -1055,11 +1034,11 @@ __TS__SetDescriptor(
1055
1034
  "disablesAutoAttack",
1056
1035
  {
1057
1036
  get = function(self)
1058
- local ____self__138_57 = self[138]
1059
- if ____self__138_57 == nil then
1060
- ____self__138_57 = false
1037
+ local ____self__138_55 = self[138]
1038
+ if ____self__138_55 == nil then
1039
+ ____self__138_55 = false
1061
1040
  end
1062
- return ____self__138_57
1041
+ return ____self__138_55
1063
1042
  end,
1064
1043
  set = function(self, disablesAutoAttack)
1065
1044
  if not disablesAutoAttack and self[138] then
@@ -1078,11 +1057,11 @@ __TS__SetDescriptor(
1078
1057
  "providesInvulnerability",
1079
1058
  {
1080
1059
  get = function(self)
1081
- local ____self__139_58 = self[139]
1082
- if ____self__139_58 == nil then
1083
- ____self__139_58 = false
1060
+ local ____self__139_56 = self[139]
1061
+ if ____self__139_56 == nil then
1062
+ ____self__139_56 = false
1084
1063
  end
1085
- return ____self__139_58
1064
+ return ____self__139_56
1086
1065
  end,
1087
1066
  set = function(self, providesInvulnerability)
1088
1067
  if not providesInvulnerability and self[139] then
@@ -1101,11 +1080,11 @@ __TS__SetDescriptor(
1101
1080
  "killsOnExpiration",
1102
1081
  {
1103
1082
  get = function(self)
1104
- local ____self__140_59 = self[140]
1105
- if ____self__140_59 == nil then
1106
- ____self__140_59 = false
1083
+ local ____self__140_57 = self[140]
1084
+ if ____self__140_57 == nil then
1085
+ ____self__140_57 = false
1107
1086
  end
1108
- return ____self__140_59
1087
+ return ____self__140_57
1109
1088
  end,
1110
1089
  set = function(self, killsOnExpiration)
1111
1090
  if not killsOnExpiration and self[140] then
@@ -1122,11 +1101,11 @@ __TS__SetDescriptor(
1122
1101
  "explodesOnExpiration",
1123
1102
  {
1124
1103
  get = function(self)
1125
- local ____self__141_60 = self[141]
1126
- if ____self__141_60 == nil then
1127
- ____self__141_60 = false
1104
+ local ____self__141_58 = self[141]
1105
+ if ____self__141_58 == nil then
1106
+ ____self__141_58 = false
1128
1107
  end
1129
- return ____self__141_60
1108
+ return ____self__141_58
1130
1109
  end,
1131
1110
  set = function(self, killsOnExpiration)
1132
1111
  if not killsOnExpiration and self[141] then
@@ -1254,13 +1233,13 @@ __TS__SetDescriptor(
1254
1233
  "remainingDuration",
1255
1234
  {
1256
1235
  get = function(self)
1257
- local ____opt_61 = self._timer
1258
- return ____opt_61 and ____opt_61.remaining or 0
1236
+ local ____opt_59 = self._timer
1237
+ return ____opt_59 and ____opt_59.remaining or 0
1259
1238
  end,
1260
1239
  set = function(self, remainingDuration)
1261
- local ____remainingDuration_65 = remainingDuration
1262
- local ____opt_63 = self._timer
1263
- local remainingDurationDelta = ____remainingDuration_65 - (____opt_63 and ____opt_63.remaining or 0)
1240
+ local ____remainingDuration_63 = remainingDuration
1241
+ local ____opt_61 = self._timer
1242
+ local remainingDurationDelta = ____remainingDuration_63 - (____opt_61 and ____opt_61.remaining or 0)
1264
1243
  if remainingDurationDelta ~= 0 then
1265
1244
  self[103] = self[103] + remainingDurationDelta
1266
1245
  if remainingDuration <= 0 then
@@ -1,5 +1,5 @@
1
1
  /** @noSelfInFile */
2
- import { Handle } from "../../core/types/handle";
2
+ import { Handle, HandleDestructor } from "../../core/types/handle";
3
3
  import { Event } from "../../event";
4
4
  import type { Item } from "../../core/types/item";
5
5
  import type { Unit } from "./unit";
@@ -67,6 +67,7 @@ export declare class UnitAbility extends Ability {
67
67
  get cooldownRemaining(): number;
68
68
  set cooldownRemaining(cooldownRemaining: number);
69
69
  interruptCast(): void;
70
+ protected onDestroy(): HandleDestructor;
70
71
  static get onCreate(): Event<[UnitAbility]>;
71
72
  static get onDestroy(): Event<[UnitAbility]>;
72
73
  }
@@ -93,6 +94,7 @@ export declare class ItemAbility extends Ability {
93
94
  get cooldownRemaining(): number;
94
95
  set cooldownRemaining(cooldownRemaining: number);
95
96
  interruptCast(): void;
97
+ protected onDestroy(): HandleDestructor;
96
98
  static get onCreate(): Event<[ItemAbility]>;
97
99
  static get onDestroy(): Event<[ItemAbility]>;
98
100
  }
@@ -232,6 +232,19 @@ ____exports.getOrderIdByAbilityTypeId = function(abilityTypeId)
232
232
  local parentTypeId = availableFields[abilityTypeId]
233
233
  return order2orderId(orders[____type(parentTypeId) == "number" and parentTypeId or abilityTypeId] or "")
234
234
  end
235
+ ---
236
+ -- @internal For use by internal systems only.
237
+ ____exports.abilityTypeHasField = function(abilityTypeId, field)
238
+ field = ____type(field) == "number" and field or getHandleId(field)
239
+ if commonFields[field] then
240
+ return true
241
+ end
242
+ local id = availableFields[abilityTypeId]
243
+ if ____type(id) == "number" then
244
+ id = availableFields[id]
245
+ end
246
+ return not not (id and id[field])
247
+ end
235
248
  ____exports.Ability = __TS__Class()
236
249
  local Ability = ____exports.Ability
237
250
  Ability.name = "Ability"
@@ -247,15 +260,7 @@ function Ability.prototype.getSnapshot(self)
247
260
  return nil
248
261
  end
249
262
  function Ability.prototype.hasField(self, field)
250
- field = ____type(field) == "number" and field or getHandleId(field)
251
- if commonFields[field] then
252
- return true
253
- end
254
- local id = availableFields[self.typeId]
255
- if ____type(id) == "number" then
256
- id = availableFields[id]
257
- end
258
- return not not (id and id[field])
263
+ return ____exports.abilityTypeHasField(self.typeId, field)
259
264
  end
260
265
  function Ability.prototype.getField(self, field, level)
261
266
  local fieldType = match(
@@ -420,6 +425,12 @@ end
420
425
  function UnitAbility.prototype.interruptCast(self)
421
426
  self.owner:interruptCast(self.typeId)
422
427
  end
428
+ function UnitAbility.prototype.onDestroy(self)
429
+ if self.owner.state ~= 2 then
430
+ self.owner:removeAbility(self.typeId)
431
+ end
432
+ return UnitAbility.____super.prototype.onDestroy(self)
433
+ end
423
434
  __TS__SetDescriptor(
424
435
  UnitAbility.prototype,
425
436
  "isDisabled",
@@ -512,6 +523,12 @@ function ItemAbility.prototype.interruptCast(self)
512
523
  setItemBooleanField(handle, ITEM_BF_ACTIVELY_USED, true)
513
524
  end
514
525
  end
526
+ function ItemAbility.prototype.onDestroy(self)
527
+ if self.owner.state ~= 2 then
528
+ self.owner:removeAbility(self.typeId)
529
+ end
530
+ return ItemAbility.____super.prototype.onDestroy(self)
531
+ end
515
532
  __TS__SetDescriptor(
516
533
  ItemAbility.prototype,
517
534
  "level",
@@ -8,12 +8,10 @@ import { AbilityTypeId } from "../object-data/entry/ability-type";
8
8
  import type { ItemTypeId } from "../object-data/entry/item-type";
9
9
  type DefenseType = 0 | 1 | 2 | 3 | 4 | 5;
10
10
  declare const enum ItemPropertyKey {
11
- ABILITIES = 100,
12
- LUA_INDEX_BY_ABILITY_TYPE_ID = 101
11
+ ABILITIES = 100
13
12
  }
14
13
  export declare class Item extends Handle<jitem> {
15
14
  private readonly [ItemPropertyKey.ABILITIES];
16
- private readonly [ItemPropertyKey.LUA_INDEX_BY_ABILITY_TYPE_ID];
17
15
  constructor(handle: jitem);
18
16
  protected onDestroy(): HandleDestructor;
19
17
  static create<T extends Item>(this: typeof Item & (new (handle: jitem) => T), id: number, x: number, y: number, skinId?: number): T;
@@ -30,22 +28,22 @@ export declare class Item extends Handle<jitem> {
30
28
  get extendedTooltip(): string;
31
29
  set iconPath(v: string);
32
30
  get iconPath(): string;
33
- set dropOnDeath(v: boolean);
34
- get dropOnDeath(): boolean;
35
- set droppable(v: boolean);
36
- get droppable(): boolean;
37
- set pawnable(v: boolean);
38
- get pawnable(): boolean;
39
- set perishable(v: boolean);
40
- get perishable(): boolean;
41
- set powerup(v: boolean);
42
- get powerup(): boolean;
31
+ set dropsOnDeath(dropsOnDeath: boolean);
32
+ get dropsOnDeath(): boolean;
33
+ set canBeDropped(canBeDropped: boolean);
34
+ get canBeDropped(): boolean;
35
+ set canBeSold(canBeSold: boolean);
36
+ get canBeSold(): boolean;
37
+ set perishes(perishes: boolean);
38
+ get perishes(): boolean;
39
+ set isPowerUp(isPowerUp: boolean);
40
+ get isPowerUp(): boolean;
43
41
  get isAlive(): boolean;
44
42
  get isDead(): boolean;
45
43
  set isInvulnerable(isInvulnerable: boolean);
46
44
  get isInvulnerable(): boolean;
47
- set usable(v: boolean);
48
- get usable(): boolean;
45
+ set isActivelyUsed(isActivelyUsed: boolean);
46
+ get isActivelyUsed(): boolean;
49
47
  set visible(v: boolean);
50
48
  get visible(): boolean;
51
49
  set level(v: number);
@@ -50,6 +50,14 @@ local unitRemoveItem = UnitRemoveItem
50
50
  local unitUseItem = UnitUseItem
51
51
  local unitUseItemPoint = UnitUseItemPoint
52
52
  local unitUseItemTarget = UnitUseItemTarget
53
+ local setItemDropOnDeath = SetItemDropOnDeath
54
+ local setItemDroppable = SetItemDroppable
55
+ local setItemPawnable = SetItemPawnable
56
+ local isItemPawnable = IsItemPawnable
57
+ local getItemIntegerField = BlzGetItemIntegerField
58
+ local setItemBooleanField = BlzSetItemBooleanField
59
+ local getItemBooleanField = BlzGetItemBooleanField
60
+ local tableRemove = table.remove
53
61
  _G.SetItemCharges = function(whichItem, charges)
54
62
  setItemCharges(whichItem, charges)
55
63
  invoke(
@@ -57,9 +65,6 @@ _G.SetItemCharges = function(whichItem, charges)
57
65
  ____exports.Item:of(whichItem)
58
66
  )
59
67
  end
60
- local getItemIntegerField = BlzGetItemIntegerField
61
- local setItemBooleanField = BlzSetItemBooleanField
62
- local getItemBooleanField = BlzGetItemBooleanField
63
68
  invoke = Event.invoke
64
69
  local enumRect = Rect:create(0, 0, 0, 0).handle
65
70
  ---
@@ -138,13 +143,7 @@ Item.name = "Item"
138
143
  __TS__ClassExtends(Item, Handle)
139
144
  function Item.prototype.____constructor(self, handle)
140
145
  Handle.prototype.____constructor(self, handle)
141
- local abilities = doAbilityAction(handle, getItemAbilities, self)
142
- self[100] = abilities
143
- local luaIndexByAbilityTypeId = {}
144
- for i = 1, #abilities do
145
- luaIndexByAbilityTypeId[abilities[i].typeId] = i
146
- end
147
- self[101] = luaIndexByAbilityTypeId
146
+ self[100] = doAbilityAction(handle, getItemAbilities, self)
148
147
  end
149
148
  function Item.prototype.onDestroy(self)
150
149
  local owner = self.owner
@@ -196,33 +195,32 @@ function Item.prototype.addAbility(self, abilityTypeId)
196
195
  if nativeAbility ~= nil then
197
196
  local ability = ItemAbility:of(nativeAbility, abilityTypeId, self)
198
197
  local abilities = self[100]
199
- local luaIndex = #abilities + 1
200
- abilities[luaIndex] = ability
201
- self[101][abilityTypeId] = luaIndex
198
+ abilities[#abilities + 1] = ability
202
199
  return ability
203
200
  end
204
201
  return nil
205
202
  end
206
203
  function Item.prototype.removeAbility(self, abilityTypeId)
207
- local luaIndexByAbilityTypeId = self[101]
208
- local luaIndex = luaIndexByAbilityTypeId[abilityTypeId]
209
- if luaIndex ~= nil and doAbilityAction(self.handle, itemRemoveAbility, abilityTypeId) then
210
- luaIndexByAbilityTypeId[abilityTypeId] = nil
211
- local abilities = self[100]
212
- abilities[luaIndex]:destroy()
213
- local abilityTypeIdsLength = #abilities
214
- for j = luaIndex, abilityTypeIdsLength do
215
- abilities[j] = abilities[j + 1]
204
+ local abilities = self[100]
205
+ for i = 1, #abilities do
206
+ if abilities[i].typeId == abilityTypeId then
207
+ local ability = abilities[i]
208
+ tableRemove(abilities, i)
209
+ ability:destroy()
210
+ return true
216
211
  end
217
212
  end
218
- return false
213
+ return doAbilityAction(self.handle, itemRemoveAbility, abilityTypeId)
219
214
  end
220
215
  function Item.prototype.hasAbility(self, abilityTypeId)
221
- return self[101][abilityTypeId] ~= nil
216
+ return doAbilityAction(self.handle, getItemAbility, abilityTypeId) ~= nil
222
217
  end
223
218
  function Item.prototype.getAbility(self, abilityTypeId)
224
- local ability = self[101][abilityTypeId] ~= nil and doAbilityAction(self.handle, getItemAbility, abilityTypeId)
225
- return ability and ItemAbility:of(ability, abilityTypeId, self) or nil
219
+ return ItemAbility:of(
220
+ doAbilityAction(self.handle, getItemAbility, abilityTypeId),
221
+ abilityTypeId,
222
+ self
223
+ )
226
224
  end
227
225
  function Item.getInRange(self, x, y, range)
228
226
  targetCollection = {}
@@ -334,65 +332,68 @@ __TS__SetDescriptor(
334
332
  )
335
333
  __TS__SetDescriptor(
336
334
  Item.prototype,
337
- "dropOnDeath",
335
+ "dropsOnDeath",
338
336
  {
339
337
  get = function(self)
340
- return BlzGetItemBooleanField(self.handle, ITEM_BF_DROPPED_WHEN_CARRIER_DIES)
338
+ return getItemBooleanField(self.handle, ITEM_BF_DROPPED_WHEN_CARRIER_DIES)
341
339
  end,
342
- set = function(self, v)
343
- SetItemDropOnDeath(self.handle, v)
340
+ set = function(self, dropsOnDeath)
341
+ setItemDropOnDeath(self.handle, dropsOnDeath)
344
342
  end
345
343
  },
346
344
  true
347
345
  )
348
346
  __TS__SetDescriptor(
349
347
  Item.prototype,
350
- "droppable",
348
+ "canBeDropped",
351
349
  {
352
350
  get = function(self)
353
- return BlzGetItemBooleanField(self.handle, ITEM_BF_CAN_BE_DROPPED)
351
+ return getItemBooleanField(self.handle, ITEM_BF_CAN_BE_DROPPED)
354
352
  end,
355
- set = function(self, v)
356
- SetItemDroppable(self.handle, v)
353
+ set = function(self, canBeDropped)
354
+ setItemDroppable(self.handle, canBeDropped)
357
355
  end
358
356
  },
359
357
  true
360
358
  )
361
359
  __TS__SetDescriptor(
362
360
  Item.prototype,
363
- "pawnable",
361
+ "canBeSold",
364
362
  {
365
363
  get = function(self)
366
- return IsItemPawnable(self.handle)
364
+ return isItemPawnable(self.handle)
367
365
  end,
368
- set = function(self, v)
369
- SetItemPawnable(self.handle, v)
366
+ set = function(self, canBeSold)
367
+ setItemPawnable(self.handle, canBeSold)
370
368
  end
371
369
  },
372
370
  true
373
371
  )
374
372
  __TS__SetDescriptor(
375
373
  Item.prototype,
376
- "perishable",
374
+ "perishes",
377
375
  {
378
376
  get = function(self)
379
377
  return getItemBooleanField(self.handle, ITEM_BF_PERISHABLE)
380
378
  end,
381
- set = function(self, v)
382
- BlzSetItemBooleanField(self.handle, ITEM_BF_PERISHABLE, v)
379
+ set = function(self, perishes)
380
+ local handle = self.handle
381
+ local powerUp = isItemPowerup(handle)
382
+ setItemBooleanField(handle, ITEM_BF_PERISHABLE, perishes)
383
+ setItemBooleanField(handle, ITEM_BF_USE_AUTOMATICALLY_WHEN_ACQUIRED, powerUp)
383
384
  end
384
385
  },
385
386
  true
386
387
  )
387
388
  __TS__SetDescriptor(
388
389
  Item.prototype,
389
- "powerup",
390
+ "isPowerUp",
390
391
  {
391
392
  get = function(self)
392
393
  return isItemPowerup(self.handle)
393
394
  end,
394
- set = function(self, v)
395
- setItemBooleanField(self.handle, ITEM_BF_USE_AUTOMATICALLY_WHEN_ACQUIRED, v)
395
+ set = function(self, isPowerUp)
396
+ setItemBooleanField(self.handle, ITEM_BF_USE_AUTOMATICALLY_WHEN_ACQUIRED, isPowerUp)
396
397
  end
397
398
  },
398
399
  true
@@ -428,16 +429,24 @@ __TS__SetDescriptor(
428
429
  )
429
430
  __TS__SetDescriptor(
430
431
  Item.prototype,
431
- "usable",
432
+ "isActivelyUsed",
432
433
  {
433
434
  get = function(self)
434
435
  return getItemBooleanField(self.handle, ITEM_BF_ACTIVELY_USED)
435
436
  end,
436
- set = function(self, v)
437
+ set = function(self, isActivelyUsed)
437
438
  local handle = self.handle
438
- local powerup = isItemPowerup(handle)
439
- setItemBooleanField(handle, ITEM_BF_ACTIVELY_USED, v)
440
- setItemBooleanField(handle, ITEM_BF_USE_AUTOMATICALLY_WHEN_ACQUIRED, powerup)
439
+ local powerUp = isItemPowerup(handle)
440
+ local perishes = getItemBooleanField(handle, ITEM_BF_PERISHABLE)
441
+ local dropsOnDeath = getItemBooleanField(handle, ITEM_BF_DROPPED_WHEN_CARRIER_DIES)
442
+ local canBeDropped = getItemBooleanField(handle, ITEM_BF_CAN_BE_DROPPED)
443
+ local canBeSold = isItemPawnable(handle)
444
+ setItemBooleanField(handle, ITEM_BF_ACTIVELY_USED, isActivelyUsed)
445
+ setItemPawnable(handle, canBeSold)
446
+ setItemDroppable(handle, canBeDropped)
447
+ setItemDropOnDeath(handle, dropsOnDeath)
448
+ setItemBooleanField(handle, ITEM_BF_PERISHABLE, perishes)
449
+ setItemBooleanField(handle, ITEM_BF_USE_AUTOMATICALLY_WHEN_ACQUIRED, powerUp)
441
450
  end
442
451
  },
443
452
  true
@@ -133,55 +133,55 @@ declare module "../unit" {
133
133
  }
134
134
  declare module "../unit" {
135
135
  namespace Unit {
136
- const abilityImpactEvent: DispatchingEvent<[Unit, Ability]>;
136
+ const abilityChannelingFinishEvent: DispatchingEvent<[Unit, Ability]>;
137
137
  }
138
138
  }
139
139
  declare module "../unit" {
140
140
  namespace Unit {
141
- const abilityWidgetTargetImpactEvent: DispatchingEvent<[Unit, Ability, Widget]>;
141
+ const abilityStopEvent: DispatchingEvent<[Unit, Ability]>;
142
142
  }
143
143
  }
144
144
  declare module "../unit" {
145
145
  namespace Unit {
146
- const abilityUnitTargetImpactEvent: DispatchingEvent<[Unit, Ability, Unit]>;
146
+ const abilityCommandEvent: {
147
+ readonly [abilityTypeId: number]: {
148
+ readonly [orderTypeStringId: string]: Event<[Unit, Ability, string]>;
149
+ };
150
+ };
147
151
  }
148
152
  }
149
153
  declare module "../unit" {
150
154
  namespace Unit {
151
- const abilityItemTargetImpactEvent: DispatchingEvent<[Unit, Ability, Item]>;
155
+ const abilityImpactEvent: DispatchingEvent<[Unit, Ability]>;
152
156
  }
153
157
  }
154
158
  declare module "../unit" {
155
159
  namespace Unit {
156
- const abilityDestructibleTargetImpactEvent: DispatchingEvent<[Unit, Ability, Destructable]>;
160
+ const abilityWidgetTargetImpactEvent: DispatchingEvent<[Unit, Ability, Widget]>;
157
161
  }
158
162
  }
159
163
  declare module "../unit" {
160
164
  namespace Unit {
161
- const abilityPointTargetImpactEvent: DispatchingEvent<[Unit, Ability, number, number]>;
165
+ const abilityUnitTargetImpactEvent: DispatchingEvent<[Unit, Ability, Unit]>;
162
166
  }
163
167
  }
164
168
  declare module "../unit" {
165
169
  namespace Unit {
166
- const abilityNoTargetImpactEvent: DispatchingEvent<[Unit, Ability]>;
170
+ const abilityItemTargetImpactEvent: DispatchingEvent<[Unit, Ability, Item]>;
167
171
  }
168
172
  }
169
173
  declare module "../unit" {
170
174
  namespace Unit {
171
- const abilityChannelingFinishEvent: DispatchingEvent<[Unit, Ability]>;
175
+ const abilityDestructibleTargetImpactEvent: DispatchingEvent<[Unit, Ability, Destructable]>;
172
176
  }
173
177
  }
174
178
  declare module "../unit" {
175
179
  namespace Unit {
176
- const abilityStopEvent: DispatchingEvent<[Unit, Ability]>;
180
+ const abilityPointTargetImpactEvent: DispatchingEvent<[Unit, Ability, number, number]>;
177
181
  }
178
182
  }
179
183
  declare module "../unit" {
180
184
  namespace Unit {
181
- const abilityCommandEvent: {
182
- readonly [abilityTypeId: number]: {
183
- readonly [orderTypeStringId: string]: Event<[Unit, Ability, string]>;
184
- };
185
- };
185
+ const abilityNoTargetImpactEvent: DispatchingEvent<[Unit, Ability]>;
186
186
  }
187
187
  }