warscript 0.0.1-dev.cdcfbc9 → 0.0.1-dev.ce2be36

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.
@@ -62,6 +62,8 @@ local ____attributes = require("attributes")
62
62
  local isAttribute = ____attributes.isAttribute
63
63
  local ____ability = require("engine.internal.item.ability")
64
64
  local doUnitAbilityAction = ____ability.doUnitAbilityAction
65
+ local ____synchronization = require("engine.synchronization")
66
+ local synchronizer = ____synchronization.synchronizer
65
67
  local match = string.match
66
68
  local ____tostring = _G.tostring
67
69
  local setUnitAnimation = SetUnitAnimation
@@ -410,6 +412,19 @@ function UnitWeapon.prototype.____constructor(self, unit, index)
410
412
  self.unit = unit
411
413
  self.index = index
412
414
  end
415
+ __TS__SetDescriptor(
416
+ UnitWeapon.prototype,
417
+ "isEnabled",
418
+ {
419
+ get = function(self)
420
+ return BlzGetUnitWeaponBooleanField(self.unit.handle, UNIT_WEAPON_BF_ATTACKS_ENABLED, self.index)
421
+ end,
422
+ set = function(self, isEnabled)
423
+ BlzSetUnitWeaponBooleanField(self.unit.handle, UNIT_WEAPON_BF_ATTACKS_ENABLED, self.index, isEnabled)
424
+ end
425
+ },
426
+ true
427
+ )
413
428
  __TS__SetDescriptor(
414
429
  UnitWeapon.prototype,
415
430
  "cooldown",
@@ -644,15 +659,15 @@ for ____, player in ipairs(Player.all) do
644
659
  dummies[player] = dummy
645
660
  end
646
661
  local function delayHealthChecksCallback(unit)
647
- local counter = (unit[103] or 0) - 1
662
+ local counter = (unit[104] or 0) - 1
648
663
  if counter ~= 0 then
649
- unit[103] = counter
664
+ unit[104] = counter
650
665
  return
651
666
  end
652
- unit[103] = nil
653
- local healthBonus = unit[104]
667
+ unit[104] = nil
668
+ local healthBonus = unit[105]
654
669
  if healthBonus ~= nil then
655
- unit[104] = nil
670
+ unit[105] = nil
656
671
  local handle = unit.handle
657
672
  BlzSetUnitMaxHP(
658
673
  handle,
@@ -712,8 +727,8 @@ function Unit.prototype.getEvent(self, event, collector)
712
727
  end
713
728
  function Unit.prototype.onDestroy(self)
714
729
  local handle = self.handle
715
- self[107] = getUnitX(handle)
716
- self[108] = getUnitY(handle)
730
+ self[108] = getUnitX(handle)
731
+ self[109] = getUnitY(handle)
717
732
  if not self._owner then
718
733
  self._owner = Player:of(getOwningPlayer(handle))
719
734
  end
@@ -836,16 +851,18 @@ function Unit.prototype.queueAnimation(self, animation)
836
851
  QueueUnitAnimation(self.handle, animation)
837
852
  end
838
853
  function Unit.prototype.chooseWeapon(self, target)
839
- if target:isAllowedTarget(self, self.firstWeapon.allowedTargetCombatClassifications) then
840
- return self.firstWeapon
854
+ local firstWeapon = self.firstWeapon
855
+ if firstWeapon.isEnabled and target:isAllowedTarget(self, firstWeapon.allowedTargetCombatClassifications) then
856
+ return firstWeapon
841
857
  end
842
- if target:isAllowedTarget(target, self.secondWeapon.allowedTargetCombatClassifications) then
843
- return self.secondWeapon
858
+ local secondWeapon = self.secondWeapon
859
+ if secondWeapon.isEnabled and target:isAllowedTarget(target, secondWeapon.allowedTargetCombatClassifications) then
860
+ return secondWeapon
844
861
  end
845
862
  return nil
846
863
  end
847
864
  function Unit.prototype.delayHealthChecks(self)
848
- self[103] = (self[103] or 0) + 1
865
+ self[104] = (self[104] or 0) + 1
849
866
  Timer:run(delayHealthChecksCallback, self)
850
867
  end
851
868
  function Unit.prototype.setPosition(self, x, y)
@@ -1051,18 +1068,44 @@ function Unit.prototype.unpauseEx(self)
1051
1068
  end
1052
1069
  function Unit.prototype.incrementStunCounter(self)
1053
1070
  local stunCounter = self[102] or 0
1054
- if not self[101] or stunCounter >= 0 then
1071
+ if not self[101] and (self[103] or 0) <= 0 or stunCounter >= 0 then
1055
1072
  BlzPauseUnitEx(self.handle, true)
1056
1073
  end
1057
1074
  self[102] = stunCounter + 1
1058
1075
  end
1059
1076
  function Unit.prototype.decrementStunCounter(self)
1060
1077
  local stunCounter = self[102] or 0
1061
- if not self[101] or stunCounter >= 1 then
1078
+ if not self[101] and (self[103] or 0) <= 0 or stunCounter >= 1 then
1062
1079
  BlzPauseUnitEx(self.handle, false)
1063
1080
  end
1064
1081
  self[102] = stunCounter - 1
1065
1082
  end
1083
+ function Unit.prototype.incrementForceStunCounter(self)
1084
+ local forceStunCounter = self[103] or 0
1085
+ if forceStunCounter == 0 then
1086
+ local handle = self.handle
1087
+ if not self[101] then
1088
+ for _ = self[102] or 0, -1 do
1089
+ BlzPauseUnitEx(handle, true)
1090
+ end
1091
+ end
1092
+ BlzPauseUnitEx(handle, true)
1093
+ end
1094
+ self[103] = forceStunCounter + 1
1095
+ end
1096
+ function Unit.prototype.decrementForceStunCounter(self)
1097
+ local forceStunCounter = self[103] or 0
1098
+ if forceStunCounter == 1 then
1099
+ local handle = self.handle
1100
+ if not self[101] then
1101
+ for _ = self[102] or 0, -1 do
1102
+ BlzPauseUnitEx(handle, false)
1103
+ end
1104
+ end
1105
+ BlzPauseUnitEx(handle, false)
1106
+ end
1107
+ self[103] = forceStunCounter - 1
1108
+ end
1066
1109
  function Unit.create(self, owner, id, x, y, facing, skinId)
1067
1110
  local handle = skinId and BlzCreateUnitWithSkin(
1068
1111
  owner.handle,
@@ -1470,7 +1513,7 @@ __TS__SetDescriptor(
1470
1513
  "isTeamGlowVisible",
1471
1514
  {
1472
1515
  get = function(self)
1473
- return not self[106]
1516
+ return not self[107]
1474
1517
  end,
1475
1518
  set = function(self, isTeamGlowVisible)
1476
1519
  BlzShowUnitTeamGlow(self.handle, isTeamGlowVisible)
@@ -1480,7 +1523,7 @@ __TS__SetDescriptor(
1480
1523
  else
1481
1524
  ____temp_7 = nil
1482
1525
  end
1483
- self[106] = ____temp_7
1526
+ self[107] = ____temp_7
1484
1527
  end
1485
1528
  },
1486
1529
  true
@@ -1490,7 +1533,7 @@ __TS__SetDescriptor(
1490
1533
  "color",
1491
1534
  {set = function(self, color)
1492
1535
  SetUnitColor(self.handle, color.handle)
1493
- if self[106] then
1536
+ if self[107] then
1494
1537
  BlzShowUnitTeamGlow(self.handle, false)
1495
1538
  end
1496
1539
  end},
@@ -1514,14 +1557,14 @@ __TS__SetDescriptor(
1514
1557
  "maxHealth",
1515
1558
  {
1516
1559
  get = function(self)
1517
- return BlzGetUnitMaxHP(self.handle) - (self[104] or 0) - (self[105] or 0)
1560
+ return BlzGetUnitMaxHP(self.handle) - (self[105] or 0) - (self[106] or 0)
1518
1561
  end,
1519
1562
  set = function(self, maxHealth)
1520
- if maxHealth < 1 and self[103] ~= nil then
1521
- self[104] = (self[104] or 0) + (1 - maxHealth)
1563
+ if maxHealth < 1 and self[104] ~= nil then
1564
+ self[105] = (self[105] or 0) + (1 - maxHealth)
1522
1565
  maxHealth = 1
1523
1566
  end
1524
- BlzSetUnitMaxHP(self.handle, maxHealth + (self[105] or 0))
1567
+ BlzSetUnitMaxHP(self.handle, maxHealth + (self[106] or 0))
1525
1568
  end
1526
1569
  },
1527
1570
  true
@@ -1563,10 +1606,10 @@ __TS__SetDescriptor(
1563
1606
  "health",
1564
1607
  {
1565
1608
  get = function(self)
1566
- return GetWidgetLife(self.handle) - (self[105] or 0)
1609
+ return GetWidgetLife(self.handle) - (self[106] or 0)
1567
1610
  end,
1568
1611
  set = function(self, health)
1569
- SetWidgetLife(self.handle, health + (self[105] or 0))
1612
+ SetWidgetLife(self.handle, health + (self[106] or 0))
1570
1613
  end
1571
1614
  },
1572
1615
  true
@@ -1660,7 +1703,7 @@ __TS__SetDescriptor(
1660
1703
  "x",
1661
1704
  {
1662
1705
  get = function(self)
1663
- return self[107] or getUnitX(self.handle)
1706
+ return self[108] or getUnitX(self.handle)
1664
1707
  end,
1665
1708
  set = function(self, v)
1666
1709
  SetUnitX(self.handle, v)
@@ -1673,7 +1716,7 @@ __TS__SetDescriptor(
1673
1716
  "y",
1674
1717
  {
1675
1718
  get = function(self)
1676
- return self[108] or getUnitY(self.handle)
1719
+ return self[109] or getUnitY(self.handle)
1677
1720
  end,
1678
1721
  set = function(self, v)
1679
1722
  SetUnitY(self.handle, v)
@@ -1778,14 +1821,18 @@ __TS__SetDescriptor(
1778
1821
  local handle = self.handle
1779
1822
  if isPaused and not IsUnitPaused(handle) then
1780
1823
  self[101] = true
1781
- for _ = self[102] or 0, -1 do
1782
- BlzPauseUnitEx(handle, true)
1824
+ if (self[103] or 0) <= 0 then
1825
+ for _ = self[102] or 0, -1 do
1826
+ BlzPauseUnitEx(handle, true)
1827
+ end
1783
1828
  end
1784
1829
  PauseUnit(handle, true)
1785
1830
  elseif not isPaused and IsUnitPaused(handle) then
1786
1831
  PauseUnit(handle, false)
1787
- for _ = self[102] or 0, -1 do
1788
- BlzPauseUnitEx(handle, false)
1832
+ if (self[103] or 0) <= 0 then
1833
+ for _ = self[102] or 0, -1 do
1834
+ BlzPauseUnitEx(handle, false)
1835
+ end
1789
1836
  end
1790
1837
  self[101] = nil
1791
1838
  end
@@ -2468,12 +2515,7 @@ Unit.onDamaging = (function()
2468
2515
  preventRetaliation = damagingEventPreventRetaliation
2469
2516
  }
2470
2517
  if data.isAttack and source then
2471
- 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
2472
- if weapon == -1 then
2473
- local targetsAllowed = BlzGetUnitWeaponIntegerField(source.handle, UNIT_WEAPON_IF_ATTACK_TARGETS_ALLOWED, 0)
2474
- weapon = 0
2475
- end
2476
- data.weapon = assert(source.weapons[weapon + 1])
2518
+ data.weapon = source:chooseWeapon(target)
2477
2519
  end
2478
2520
  if not data.isAttack or not source or not source._attackHandlers then
2479
2521
  invoke(
@@ -2618,7 +2660,7 @@ Unit.onDamage = __TS__New(
2618
2660
  invoke(event, source, target, evData)
2619
2661
  if evData[0] ~= nil and target.health - evData.amount < 0.405 then
2620
2662
  local bonusHealth = math.ceil(evData.amount)
2621
- target[105] = (target[105] or 0) + bonusHealth
2663
+ target[106] = (target[106] or 0) + bonusHealth
2622
2664
  BlzSetUnitMaxHP(
2623
2665
  target.handle,
2624
2666
  BlzGetUnitMaxHP(target.handle) + bonusHealth
@@ -2632,7 +2674,7 @@ Unit.onDamage = __TS__New(
2632
2674
  evData[0],
2633
2675
  table.unpack(evData, 1 + 1, 1 + (evData[1] or 0))
2634
2676
  )
2635
- target[105] = (target[105] or 0) - bonusHealth
2677
+ target[106] = (target[106] or 0) - bonusHealth
2636
2678
  SetWidgetLife(
2637
2679
  target.handle,
2638
2680
  GetWidgetLife(target.handle) - bonusHealth
@@ -2782,6 +2824,10 @@ __TS__ObjectDefineProperty(
2782
2824
  rawset(self, "destroyEvent", destroyEvent)
2783
2825
  return destroyEvent
2784
2826
  end}
2827
+ )
2828
+ Unit.synchronize = synchronizer(
2829
+ function(unit) return unit.syncId end,
2830
+ function(syncId) return unitBySyncId[syncId] end
2785
2831
  );
2786
2832
  (function(self)
2787
2833
  local leaveAbilityIds = postcompile(function()
@@ -3,6 +3,7 @@ import { Unit } from "../core/types/unit";
3
3
  import { Async } from "../core/types/async";
4
4
  import { Event, TriggerEvent } from "../event";
5
5
  import { GraphicsMode } from "./index";
6
+ import { Color } from "../core/types/color";
6
7
  export declare class LocalClient {
7
8
  private constructor();
8
9
  static readonly locale: string;
@@ -11,6 +12,7 @@ export declare class LocalClient {
11
12
  static get isHD(): boolean;
12
13
  static get graphicsMode(): GraphicsMode;
13
14
  static get isActive(): boolean;
15
+ static pingMinimap(x: number, y: number, duration: number, ...parameters: [] | [red: number, green: number, blue: number, extraEffects?: boolean] | [color: Color, extraEffects?: boolean]): void;
14
16
  static get mouseFocusUnit(): Async<Unit> | undefined;
15
17
  static get mainSelectedUnit(): Async<Unit> | undefined;
16
18
  static get mainSelectedUnitChangeEvent(): Event<[
@@ -1,6 +1,7 @@
1
1
  local ____lualib = require("lualib_bundle")
2
2
  local __TS__ArrayMap = ____lualib.__TS__ArrayMap
3
3
  local __TS__Class = ____lualib.__TS__Class
4
+ local __TS__InstanceOf = ____lualib.__TS__InstanceOf
4
5
  local __TS__ObjectDefineProperty = ____lualib.__TS__ObjectDefineProperty
5
6
  local __TS__New = ____lualib.__TS__New
6
7
  local ____exports = {}
@@ -15,6 +16,8 @@ local ____player = require("core.types.player")
15
16
  local Player = ____player.Player
16
17
  local ____timer = require("core.types.timer")
17
18
  local Timer = ____timer.Timer
19
+ local ____color = require("core.types.color")
20
+ local Color = ____color.Color
18
21
  local loadTOCFile = BlzLoadTOCFile
19
22
  local getLocalClientWidth = BlzGetLocalClientWidth
20
23
  local getLocalClientHeight = BlzGetLocalClientHeight
@@ -25,6 +28,8 @@ local getMouseFocusUnit = BlzGetMouseFocusUnit
25
28
  local getUnitRealField = BlzGetUnitRealField
26
29
  local getUnitTypeId = GetUnitTypeId
27
30
  local getLocale = BlzGetLocale
31
+ local pingMinimap = PingMinimap
32
+ local pingMinimapEx = PingMinimapEx
28
33
  local tableSort = table.sort
29
34
  local tocPath = "_warscript\\IsHD.toc"
30
35
  compiletime(function()
@@ -62,6 +67,31 @@ local LocalClient = ____exports.LocalClient
62
67
  LocalClient.name = "LocalClient"
63
68
  function LocalClient.prototype.____constructor(self)
64
69
  end
70
+ function LocalClient.pingMinimap(self, x, y, duration, redOrColor, greenOrExtraEffects, blue, extraEffects)
71
+ if redOrColor == nil then
72
+ pingMinimap(x, y, duration)
73
+ elseif __TS__InstanceOf(redOrColor, Color) then
74
+ pingMinimapEx(
75
+ x,
76
+ y,
77
+ duration,
78
+ redOrColor.r,
79
+ redOrColor.g,
80
+ redOrColor.b,
81
+ greenOrExtraEffects or false
82
+ )
83
+ else
84
+ pingMinimapEx(
85
+ x,
86
+ y,
87
+ duration,
88
+ redOrColor,
89
+ greenOrExtraEffects,
90
+ blue,
91
+ extraEffects or false
92
+ )
93
+ end
94
+ end
65
95
  LocalClient.locale = getLocale()
66
96
  __TS__ObjectDefineProperty(
67
97
  LocalClient,
@@ -36,7 +36,8 @@ export type ObjectFieldValueChangeEvent<T extends ObjectField<any, any, any, any
36
36
  ]> : never;
37
37
  export type ReadonlyObjectFieldType<T extends ObjectField<any, any, any, any>> = Omit<T, "setValue" | "removeValue" | "trySetValue">;
38
38
  type ReadonlyObjectFieldConstructor<T extends ObjectField> = OmitConstructor<typeof ObjectField> & (abstract new (...args: any[]) => ReadonlyObjectFieldType<T>);
39
- type ObjectFieldModifier<InstanceType extends AnyNotNil, ValueType extends number | string | boolean> = (instance: InstanceType, currentValue: ValueType, originalValue: ValueType) => ValueType;
39
+ export type ObjectFieldModifier<InstanceType extends AnyNotNil, ValueType extends number | string | boolean> = (instance: InstanceType, currentValue: ValueType, originalValue: ValueType) => ValueType;
40
+ export type ObjectLevelFieldModifier<InstanceType extends AnyNotNil, ValueType extends number | string | boolean> = (instance: InstanceType, level: number, currentValue: ValueType, originalValue: ValueType) => ValueType;
40
41
  export declare abstract class ObjectField<ObjectDataEntryType extends ObjectDataEntry = ObjectDataEntry, InstanceType extends AnyNotNil = AnyNotNil, ValueType extends number | string | boolean = number | string | boolean, NativeFieldType = unknown> extends ObjectFieldBase<ObjectDataEntryType, InstanceType, ValueType, NativeFieldType> {
41
42
  protected abstract readonly defaultValue: ValueType;
42
43
  protected abstract getNativeFieldValue(instance: InstanceType): ValueType;
@@ -88,7 +89,12 @@ export declare abstract class ObjectLevelField<ObjectDataEntryType extends Objec
88
89
  protected abstract getLevelCount(entry: ObjectDataEntryType | InstanceType): number;
89
90
  getValue<LevelType extends [number] | []>(entry: ObjectDataEntryType | InstanceType, ...[level]: LevelType): LevelType extends [number] ? ValueType : ValueType[];
90
91
  setValue(entry: ObjectDataEntryType | InstanceType, ...[levelOrValue, value]: [value: ObjectDataEntryLevelFieldValueSupplier<InputValueType, ValueType>] | [level: number, value: InputValueType]): boolean;
92
+ applyModifier(instance: InstanceType, modifier: ObjectLevelFieldModifier<InstanceType, ValueType>): void;
93
+ removeModifier(instance: InstanceType, modifier: ObjectLevelFieldModifier<InstanceType, ValueType>): boolean;
91
94
  trySetValue(entry: ObjectDataEntryType | InstanceType, levelOrValue: number | unknown, value?: unknown): boolean;
95
+ private getActualValue;
96
+ private setActualValue;
97
+ private calculateActualValue;
92
98
  private invokeValueChangeEvent;
93
99
  private invokeValueChangeEventRecursive;
94
100
  protected static getOrCreateValueChangeEvent<T extends ObjectLevelField, R extends ReadonlyObjectLevelFieldType<T>>(this: ReadonlyObjectLevelFieldConstructor<T>): ObjectLevelFieldValueChangeEvent<R>;