warscript 0.0.1-dev.ceab398 → 0.0.1-dev.d09c685

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 (74) hide show
  1. package/attributes.d.ts +1 -0
  2. package/attributes.lua +9 -0
  3. package/core/types/frame.lua +24 -21
  4. package/core/types/player.d.ts +14 -0
  5. package/core/types/player.lua +23 -1
  6. package/core/types/playerCamera.d.ts +2 -0
  7. package/core/types/playerCamera.lua +123 -5
  8. package/core/types/tileCell.d.ts +9 -0
  9. package/core/types/tileCell.lua +92 -0
  10. package/core/types/timer.d.ts +3 -1
  11. package/core/types/timer.lua +27 -2
  12. package/decl/native.d.ts +6 -4
  13. package/engine/behavior.d.ts +3 -0
  14. package/engine/behavior.lua +53 -0
  15. package/engine/behaviour/ability/remove-buffs.d.ts +9 -0
  16. package/engine/behaviour/ability/remove-buffs.lua +21 -0
  17. package/engine/behaviour/ability/restore-mana.d.ts +1 -1
  18. package/engine/behaviour/ability/restore-mana.lua +6 -6
  19. package/engine/behaviour/unit/stun-immunity.d.ts +2 -0
  20. package/engine/behaviour/unit/stun-immunity.lua +11 -2
  21. package/engine/behaviour/unit.d.ts +8 -2
  22. package/engine/behaviour/unit.lua +29 -2
  23. package/engine/buff.d.ts +0 -3
  24. package/engine/buff.lua +59 -80
  25. package/engine/internal/ability.d.ts +3 -1
  26. package/engine/internal/ability.lua +26 -9
  27. package/engine/internal/item+owner.lua +12 -6
  28. package/engine/internal/item.d.ts +13 -15
  29. package/engine/internal/item.lua +63 -49
  30. package/engine/internal/misc/frame-coordinates.d.ts +2 -0
  31. package/engine/internal/misc/frame-coordinates.lua +21 -0
  32. package/engine/internal/misc/get-terrain-z.d.ts +2 -0
  33. package/engine/internal/misc/get-terrain-z.lua +11 -0
  34. package/engine/internal/misc/player-local-handle.d.ts +2 -0
  35. package/engine/internal/misc/player-local-handle.lua +5 -0
  36. package/engine/internal/unit/ability.d.ts +14 -14
  37. package/engine/internal/unit/ability.lua +72 -45
  38. package/engine/internal/unit/main-selected.lua +12 -27
  39. package/engine/internal/unit+ability.lua +10 -1
  40. package/engine/internal/unit-missile-launch.lua +42 -14
  41. package/engine/internal/unit.d.ts +6 -5
  42. package/engine/internal/unit.lua +39 -27
  43. package/engine/object-data/auxiliary/armor-type.d.ts +11 -0
  44. package/engine/object-data/auxiliary/armor-type.lua +46 -0
  45. package/engine/object-data/entry/ability-type.lua +5 -4
  46. package/engine/object-data/entry/unit-type.d.ts +11 -2
  47. package/engine/object-data/entry/unit-type.lua +59 -1
  48. package/engine/object-field/ability.d.ts +3 -3
  49. package/engine/object-field/ability.lua +7 -6
  50. package/engine/object-field.d.ts +2 -2
  51. package/engine/object-field.lua +8 -6
  52. package/engine/random.d.ts +9 -0
  53. package/engine/random.lua +13 -0
  54. package/engine/synchronization.d.ts +11 -0
  55. package/engine/synchronization.lua +77 -0
  56. package/engine/text-tag.d.ts +1 -1
  57. package/engine/text-tag.lua +91 -17
  58. package/net/socket.lua +1 -1
  59. package/objutil/buff.lua +1 -1
  60. package/package.json +2 -2
  61. package/patch-lualib.lua +1 -1
  62. package/utility/arrays.d.ts +1 -0
  63. package/utility/arrays.lua +8 -0
  64. package/utility/callback-array.d.ts +17 -0
  65. package/utility/callback-array.lua +61 -0
  66. package/utility/functions.d.ts +2 -0
  67. package/utility/functions.lua +7 -0
  68. package/utility/linked-set.d.ts +1 -0
  69. package/utility/linked-set.lua +19 -1
  70. package/utility/lua-maps.d.ts +11 -2
  71. package/utility/lua-maps.lua +33 -2
  72. package/utility/lua-sets.d.ts +1 -0
  73. package/utility/lua-sets.lua +4 -0
  74. package/utility/types.d.ts +3 -0
@@ -9,9 +9,16 @@ local ____timer = require("core.types.timer")
9
9
  local Timer = ____timer.Timer
10
10
  local ____lua_2Dsets = require("utility.lua-sets")
11
11
  local luaSetOf = ____lua_2Dsets.luaSetOf
12
+ local ____attributes = require("attributes")
13
+ local attribute = ____attributes.attribute
14
+ local ____linked_2Dset = require("utility.linked-set")
15
+ local LinkedSet = ____linked_2Dset.LinkedSet
12
16
  local autoAttackFinishEvent = __TS__New(Event)
13
17
  rawset(Unit, "autoAttackFinishEvent", autoAttackFinishEvent)
14
- local eventTimerByUnit = {}
18
+ local units = __TS__New(LinkedSet)
19
+ local targetAttribute = attribute()
20
+ local impactDelayAttribute = attribute()
21
+ local passedTimeAttribute = attribute()
15
22
  local instantOrderIds = luaSetOf(
16
23
  orderId("avatar"),
17
24
  orderId("berserk"),
@@ -28,24 +35,45 @@ local instantOrderIds = luaSetOf(
28
35
  orderId("unimmolation")
29
36
  )
30
37
  local function reset(source, orderId)
31
- if not (instantOrderIds[orderId] ~= nil) then
32
- local eventTimer = eventTimerByUnit[source]
33
- if eventTimer then
34
- eventTimer:destroy()
35
- eventTimerByUnit[source] = nil
36
- end
38
+ if not (instantOrderIds[orderId] ~= nil) and units:remove(source) then
39
+ source[targetAttribute] = nil
40
+ source[impactDelayAttribute] = nil
41
+ source[passedTimeAttribute] = nil
37
42
  end
38
43
  end
39
44
  Unit.onImmediateOrder:addListener(reset)
40
45
  Unit.onPointOrder:addListener(reset)
41
46
  Unit.onTargetOrder:addListener(reset)
42
- local function timerCallback(source, target)
43
- eventTimerByUnit[source] = nil
44
- Event.invoke(autoAttackFinishEvent, source, target)
47
+ local timerPeriod = 1 / 64
48
+ local function invokeEvent(unit)
49
+ units:remove(unit)
50
+ local target = unit[targetAttribute]
51
+ unit[targetAttribute] = nil
52
+ unit[impactDelayAttribute] = nil
53
+ unit[passedTimeAttribute] = nil
54
+ Event.invoke(autoAttackFinishEvent, unit, target)
55
+ end
56
+ local function checkUnit(unit)
57
+ local passedTime = unit[passedTimeAttribute] + timerPeriod
58
+ if passedTime >= unit[impactDelayAttribute] then
59
+ invokeEvent(unit)
60
+ else
61
+ unit[passedTimeAttribute] = passedTime
62
+ end
45
63
  end
46
- Unit.autoAttackStartEvent:addListener(function(source, target)
47
- local attackPoint = (source:chooseWeapon(target) or source.firstWeapon).impactDelay
48
- local timer = Timer:simple(attackPoint, timerCallback, source, target)
49
- eventTimerByUnit[source] = timer
64
+ Timer.onPeriod[timerPeriod]:addListener(function()
65
+ units:forEach(checkUnit)
50
66
  end)
67
+ Unit.autoAttackStartEvent:addListener(
68
+ 999999,
69
+ function(source, target)
70
+ if source[targetAttribute] ~= nil then
71
+ invokeEvent(source)
72
+ end
73
+ source[targetAttribute] = target
74
+ source[impactDelayAttribute] = (source:chooseWeapon(target) or source.firstWeapon).impactDelay
75
+ source[passedTimeAttribute] = -timerPeriod
76
+ units:add(source)
77
+ end
78
+ )
51
79
  return ____exports
@@ -80,6 +80,8 @@ export declare class UnitWeapon {
80
80
  readonly unit: Unit;
81
81
  readonly index: 0 | 1;
82
82
  constructor(unit: Unit, index: 0 | 1);
83
+ get isEnabled(): boolean;
84
+ set isEnabled(isEnabled: boolean);
83
85
  get cooldown(): number;
84
86
  set cooldown(cooldown: number);
85
87
  get damage(): [minimumDamage: number, maximumDamage: number];
@@ -160,8 +162,7 @@ export declare class Unit extends Handle<junit> {
160
162
  isInRangeOf(unit: Unit, range: number): boolean;
161
163
  isAllyOf(unit: Unit): boolean;
162
164
  isEnemyOf(unit: Unit): boolean;
163
- playAnimation(animation: string, rarity?: jraritycontrol): void;
164
- playAnimation(animation: number): void;
165
+ playAnimation(...parameters: [animation: number] | [animation: string, rarity?: jraritycontrol]): void;
165
166
  resetAnimation(): void;
166
167
  queueAnimation(animation: string): void;
167
168
  get weapons(): [UnitWeapon, UnitWeapon];
@@ -272,8 +273,8 @@ export declare class Unit extends Handle<junit> {
272
273
  setAbilityLevel(abilityId: number, level: number): number;
273
274
  getAbilityLevel(abilityId: number): number;
274
275
  hasAbility(abilityId: number): boolean;
275
- getAbilityById(abilityId: number): UnitAbility | undefined;
276
- removeAbility(abilityId: number): boolean;
276
+ getAbility(abilityId: number): UnitAbility | undefined;
277
+ removeAbility(abilityTypeId: number): boolean;
277
278
  hideAbility(abilityId: number, flag: boolean): void;
278
279
  getAbilityRemainingCooldown(abilityId: number): number;
279
280
  startAbilityCooldown(abilityId: number, cooldown: number): void;
@@ -354,7 +355,7 @@ export declare class Unit extends Handle<junit> {
354
355
  static itemDroppedEvent: UnitTriggerEvent<[Item]>;
355
356
  static itemPickedUpEvent: UnitTriggerEvent<[Item]>;
356
357
  static itemUsedEvent: UnitTriggerEvent<[Item]>;
357
- static itemStackedEvent: UnitTriggerEvent<[Item]>;
358
+ static itemStackedEvent: UnitTriggerEvent<[target: Item, source: Item]>;
358
359
  static get itemChargesChangedEvent(): Event<[unit: Unit, item: Item]>;
359
360
  static get itemUseOrderEvent(): Event<[unit: Unit, item: Item]>;
360
361
  static get itemMoveOrderEvent(): Event<[
@@ -410,6 +410,19 @@ function UnitWeapon.prototype.____constructor(self, unit, index)
410
410
  self.unit = unit
411
411
  self.index = index
412
412
  end
413
+ __TS__SetDescriptor(
414
+ UnitWeapon.prototype,
415
+ "isEnabled",
416
+ {
417
+ get = function(self)
418
+ return BlzGetUnitWeaponBooleanField(self.unit.handle, UNIT_WEAPON_BF_ATTACKS_ENABLED, self.index)
419
+ end,
420
+ set = function(self, isEnabled)
421
+ BlzSetUnitWeaponBooleanField(self.unit.handle, UNIT_WEAPON_BF_ATTACKS_ENABLED, self.index, isEnabled)
422
+ end
423
+ },
424
+ true
425
+ )
413
426
  __TS__SetDescriptor(
414
427
  UnitWeapon.prototype,
415
428
  "cooldown",
@@ -836,11 +849,13 @@ function Unit.prototype.queueAnimation(self, animation)
836
849
  QueueUnitAnimation(self.handle, animation)
837
850
  end
838
851
  function Unit.prototype.chooseWeapon(self, target)
839
- if target:isAllowedTarget(self, self.firstWeapon.allowedTargetCombatClassifications) then
840
- return self.firstWeapon
852
+ local firstWeapon = self.firstWeapon
853
+ if firstWeapon.isEnabled and target:isAllowedTarget(self, firstWeapon.allowedTargetCombatClassifications) then
854
+ return firstWeapon
841
855
  end
842
- if target:isAllowedTarget(target, self.secondWeapon.allowedTargetCombatClassifications) then
843
- return self.secondWeapon
856
+ local secondWeapon = self.secondWeapon
857
+ if secondWeapon.isEnabled and target:isAllowedTarget(target, secondWeapon.allowedTargetCombatClassifications) then
858
+ return secondWeapon
844
859
  end
845
860
  return nil
846
861
  end
@@ -935,23 +950,21 @@ end
935
950
  function Unit.prototype.hasAbility(self, abilityId)
936
951
  return getUnitAbilityLevel(self.handle, abilityId) > 0
937
952
  end
938
- function Unit.prototype.getAbilityById(self, abilityId)
953
+ function Unit.prototype.getAbility(self, abilityId)
939
954
  local ability = doUnitAbilityAction(self.handle, abilityId, getUnitAbility, abilityId)
940
955
  return UnitAbility:of(ability, abilityId, self)
941
956
  end
942
- function Unit.prototype.removeAbility(self, abilityId)
943
- if doUnitAbilityAction(self.handle, abilityId, unitRemoveAbility, abilityId) then
944
- local abilities = self.abilities
945
- for i = 1, #abilities do
946
- if abilities[i].typeId == abilityId then
947
- abilities[i]:destroy()
948
- tremove(abilities, i)
949
- return true
950
- end
957
+ function Unit.prototype.removeAbility(self, abilityTypeId)
958
+ local abilities = self.abilities
959
+ for i = 1, #abilities do
960
+ if abilities[i].typeId == abilityTypeId then
961
+ local ability = abilities[i]
962
+ tremove(abilities, i)
963
+ ability:destroy()
964
+ return true
951
965
  end
952
- return true
953
966
  end
954
- return false
967
+ return doUnitAbilityAction(self.handle, abilityTypeId, unitRemoveAbility, abilityTypeId)
955
968
  end
956
969
  function Unit.prototype.hideAbility(self, abilityId, flag)
957
970
  BlzUnitHideAbility(self.handle, abilityId, flag)
@@ -2470,12 +2483,7 @@ Unit.onDamaging = (function()
2470
2483
  preventRetaliation = damagingEventPreventRetaliation
2471
2484
  }
2472
2485
  if data.isAttack and source then
2473
- 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
2474
- if weapon == -1 then
2475
- local targetsAllowed = BlzGetUnitWeaponIntegerField(source.handle, UNIT_WEAPON_IF_ATTACK_TARGETS_ALLOWED, 0)
2476
- weapon = 0
2477
- end
2478
- data.weapon = assert(source.weapons[weapon + 1])
2486
+ data.weapon = source:chooseWeapon(target)
2479
2487
  end
2480
2488
  if not data.isAttack or not source or not source._attackHandlers then
2481
2489
  invoke(
@@ -2670,10 +2678,14 @@ Unit.itemPickedUpEvent = __TS__New(
2670
2678
  ____exports.UnitTriggerEvent,
2671
2679
  EVENT_PLAYER_UNIT_PICKUP_ITEM,
2672
2680
  function()
2673
- local unit = getTriggerUnit()
2674
- local item = getManipulatedItem()
2675
- if getUnitTypeId(unit) ~= dummyUnitId and not (ignoreEventsItems[item] ~= nil) then
2676
- return ____exports.Unit:of(unit), Item:of(item)
2681
+ local unitHandle = getTriggerUnit()
2682
+ local itemHandle = getManipulatedItem()
2683
+ if getUnitTypeId(unitHandle) ~= dummyUnitId and not (ignoreEventsItems[itemHandle] ~= nil) then
2684
+ local unit = ____exports.Unit:of(unitHandle)
2685
+ local item = Item:of(itemHandle)
2686
+ if item.owner ~= unit then
2687
+ return unit, item
2688
+ end
2677
2689
  end
2678
2690
  return IgnoreEvent
2679
2691
  end
@@ -2693,7 +2705,7 @@ Unit.itemUsedEvent = __TS__New(
2693
2705
  Unit.itemStackedEvent = __TS__New(
2694
2706
  ____exports.UnitTriggerEvent,
2695
2707
  EVENT_PLAYER_UNIT_STACK_ITEM,
2696
- function() return ____exports.Unit:of(getTriggerUnit()), Item:of(getManipulatedItem()) end
2708
+ function() return ____exports.Unit:of(getTriggerUnit()), Item:of(BlzGetStackingItemTarget()), Item:of(BlzGetStackingItemSource()) end
2697
2709
  )
2698
2710
  __TS__ObjectDefineProperty(
2699
2711
  Unit,
@@ -0,0 +1,11 @@
1
+ /** @noSelfInFile */
2
+ export declare const enum ArmorType {
3
+ LIGHT = 0,
4
+ MEDIUM = 1,
5
+ HEAVY = 2,
6
+ FORTIFIED = 3,
7
+ NORMAL = 4,
8
+ HERO = 5,
9
+ DIVINE = 6,
10
+ UNARMORED = 7
11
+ }
@@ -0,0 +1,46 @@
1
+ local ____exports = {}
2
+ local ____records = require("utility.records")
3
+ local invertRecord = ____records.invertRecord
4
+ local stringByArmorType = {
5
+ [0] = "small",
6
+ [1] = "medium",
7
+ [2] = "large",
8
+ [3] = "fort",
9
+ [4] = "normal",
10
+ [5] = "hero",
11
+ [6] = "divine",
12
+ [7] = "none"
13
+ }
14
+ local armorTypeByString = invertRecord(stringByArmorType)
15
+ local nativeByArmorType = {
16
+ [0] = DEFENSE_TYPE_LIGHT,
17
+ [1] = DEFENSE_TYPE_MEDIUM,
18
+ [2] = DEFENSE_TYPE_LARGE,
19
+ [3] = DEFENSE_TYPE_FORT,
20
+ [4] = DEFENSE_TYPE_NORMAL,
21
+ [5] = DEFENSE_TYPE_HERO,
22
+ [6] = DEFENSE_TYPE_DIVINE,
23
+ [7] = DEFENSE_TYPE_NONE
24
+ }
25
+ local armorTypeByNative = invertRecord(nativeByArmorType)
26
+ ---
27
+ -- @internal For use by internal systems only.
28
+ ____exports.armorTypeToString = function(armorType)
29
+ return stringByArmorType[armorType]
30
+ end
31
+ ---
32
+ -- @internal For use by internal systems only.
33
+ ____exports.stringToArmorType = function(____string)
34
+ return armorTypeByString[____string] or 7
35
+ end
36
+ ---
37
+ -- @internal For use by internal systems only.
38
+ ____exports.armorTypeToNative = function(armorType)
39
+ return nativeByArmorType[armorType]
40
+ end
41
+ ---
42
+ -- @internal For use by internal systems only.
43
+ ____exports.nativeToArmorType = function(armorType)
44
+ return armorTypeByNative[armorType]
45
+ end
46
+ return ____exports
@@ -38,6 +38,8 @@ local ____sound = require("core.types.sound")
38
38
  local isSoundLabelCustom = ____sound.isSoundLabelCustom
39
39
  local Sound3D = ____sound.Sound3D
40
40
  local SoundSettings = ____sound.SoundSettings
41
+ local ____lua_2Dsets = require("utility.lua-sets")
42
+ local luaSetOf = ____lua_2Dsets.luaSetOf
41
43
  local castAnimationFQNByAbilityTypeId = {}
42
44
  local isButtonVisibleFalseAbilityTypes = {}
43
45
  local casterCastingEffectPresetsByAbilityTypeId = {}
@@ -979,9 +981,7 @@ for abilityTypeId, animationFQN in pairs(postcompile(function() return castAnima
979
981
  4,
980
982
  function(caster, ability)
981
983
  if ability:getField(ABILITY_RLF_CASTING_TIME) ~= 0 then
982
- Timer:run(function()
983
- caster:playAnimation(animationFQN)
984
- end)
984
+ Timer:run(caster, "playAnimation", animationFQN)
985
985
  end
986
986
  end
987
987
  )
@@ -1006,9 +1006,10 @@ for abilityTypeId, soundPresetId in pairs(postcompile(function() return targetEf
1006
1006
  )
1007
1007
  end
1008
1008
  end
1009
+ local unsupportedEffectSoundAbilityTypeIds = luaSetOf(fourCC("AAns"))
1009
1010
  Unit.abilityChannelingStartEvent:addListener(function(caster, ability)
1010
1011
  local soundPresetId = ability:getField(ABILITY_SF_EFFECT_SOUND)
1011
- if isSoundLabelCustom(soundPresetId) then
1012
+ if isSoundLabelCustom(soundPresetId) or soundPresetId ~= "" and unsupportedEffectSoundAbilityTypeIds[ability.parentTypeId] ~= nil then
1012
1013
  Sound3D:playFromLabel(soundPresetId, SoundSettings.Ability, caster)
1013
1014
  end
1014
1015
  end)
@@ -13,6 +13,7 @@ import type { AbilityTypeId } from "./ability-type";
13
13
  import type { UpgradeId } from "./upgrade";
14
14
  import { AnimationQualifier } from "../auxiliary/animation-qualifier";
15
15
  import { AttackType } from "../auxiliary/attack-type";
16
+ import { ArmorType } from "../auxiliary/armor-type";
16
17
  export type UnitTypeId = ObjectDataEntryId & number & {
17
18
  readonly __unitTypeId: unique symbol;
18
19
  };
@@ -144,6 +145,8 @@ export declare abstract class UnitType<Id extends UnitTypeId = UnitTypeId> exten
144
145
  set runSpeedSD(runSpeedSD: number);
145
146
  get runSpeedHD(): number;
146
147
  set runSpeedHD(runSpeedHD: number);
148
+ get selectionCircleHeight(): number;
149
+ set selectionCircleHeight(height: number);
147
150
  get selectionCircleScale(): number;
148
151
  set selectionCircleScale(selectionCircleScale: number);
149
152
  get selectionCircleScaleSD(): number;
@@ -182,16 +185,20 @@ export declare abstract class UnitType<Id extends UnitTypeId = UnitTypeId> exten
182
185
  set walkSpeedSD(walkSpeedSD: number);
183
186
  get walkSpeedHD(): number;
184
187
  set walkSpeedHD(walkSpeedHD: number);
188
+ get armor(): number;
189
+ set armor(armor: number);
185
190
  get armorSoundType(): ArmorSoundType;
186
191
  set armorSoundType(armorSoundType: ArmorSoundType);
187
192
  get armorSoundTypeSD(): ArmorSoundType;
188
193
  set armorSoundTypeSD(armorSoundTypeSD: ArmorSoundType);
189
194
  get armorSoundTypeHD(): ArmorSoundType;
190
195
  set armorSoundTypeHD(armorSoundTypeHD: ArmorSoundType);
196
+ get armorType(): ArmorType;
197
+ set armorType(armorType: ArmorType);
191
198
  get combatClassifications(): CombatClassifications;
192
199
  set combatClassifications(combatClassifications: CombatClassifications);
193
- get unitClassifications(): UnitClassifications;
194
- set unitClassifications(unitClassifications: UnitClassifications);
200
+ get classifications(): UnitClassifications;
201
+ set classifications(unitClassifications: UnitClassifications);
195
202
  get weapons(): TupleOf<UnitTypeWeapon, 2>;
196
203
  get firstWeapon(): UnitTypeWeapon;
197
204
  get secondWeapon(): UnitTypeWeapon;
@@ -225,6 +232,8 @@ export declare abstract class UnitType<Id extends UnitTypeId = UnitTypeId> exten
225
232
  set goldCost(goldCost: number);
226
233
  get healthRegenerationRate(): number;
227
234
  set healthRegenerationRate(healthRegenerationRate: number);
235
+ get level(): number;
236
+ set level(level: number);
228
237
  get manaRegenerationRate(): number;
229
238
  set manaRegenerationRate(manaRegenerationRate: number);
230
239
  get maximumHealth(): number;
@@ -27,6 +27,9 @@ local attackTypeToString = ____attack_2Dtype.attackTypeToString
27
27
  local stringToAttackType = ____attack_2Dtype.stringToAttackType
28
28
  local ____config = require("config")
29
29
  local WarscriptConfig = ____config.WarscriptConfig
30
+ local ____armor_2Dtype = require("engine.object-data.auxiliary.armor-type")
31
+ local armorTypeToString = ____armor_2Dtype.armorTypeToString
32
+ local stringToArmorType = ____armor_2Dtype.stringToArmorType
30
33
  local getOrCreateUnitTypeWeapons
31
34
  ____exports.UnitTypeWeapon = __TS__Class()
32
35
  local UnitTypeWeapon = ____exports.UnitTypeWeapon
@@ -936,6 +939,19 @@ __TS__SetDescriptor(
936
939
  },
937
940
  true
938
941
  )
942
+ __TS__SetDescriptor(
943
+ UnitType.prototype,
944
+ "selectionCircleHeight",
945
+ {
946
+ get = function(self)
947
+ return self:getNumberField("uslz")
948
+ end,
949
+ set = function(self, height)
950
+ self:setNumberField("uslz", height)
951
+ end
952
+ },
953
+ true
954
+ )
939
955
  __TS__SetDescriptor(
940
956
  UnitType.prototype,
941
957
  "selectionCircleScale",
@@ -1183,6 +1199,19 @@ __TS__SetDescriptor(
1183
1199
  },
1184
1200
  true
1185
1201
  )
1202
+ __TS__SetDescriptor(
1203
+ UnitType.prototype,
1204
+ "armor",
1205
+ {
1206
+ get = function(self)
1207
+ return self:getNumberField("udef")
1208
+ end,
1209
+ set = function(self, armor)
1210
+ self:setNumberField("udef", armor)
1211
+ end
1212
+ },
1213
+ true
1214
+ )
1186
1215
  __TS__SetDescriptor(
1187
1216
  UnitType.prototype,
1188
1217
  "armorSoundType",
@@ -1222,6 +1251,22 @@ __TS__SetDescriptor(
1222
1251
  },
1223
1252
  true
1224
1253
  )
1254
+ __TS__SetDescriptor(
1255
+ UnitType.prototype,
1256
+ "armorType",
1257
+ {
1258
+ get = function(self)
1259
+ return stringToArmorType(self:getStringField("udty"))
1260
+ end,
1261
+ set = function(self, armorType)
1262
+ self:setStringField(
1263
+ "udty",
1264
+ armorTypeToString(armorType)
1265
+ )
1266
+ end
1267
+ },
1268
+ true
1269
+ )
1225
1270
  __TS__SetDescriptor(
1226
1271
  UnitType.prototype,
1227
1272
  "combatClassifications",
@@ -1240,7 +1285,7 @@ __TS__SetDescriptor(
1240
1285
  )
1241
1286
  __TS__SetDescriptor(
1242
1287
  UnitType.prototype,
1243
- "unitClassifications",
1288
+ "classifications",
1244
1289
  {
1245
1290
  get = function(self)
1246
1291
  return stringArrayToUnitClassifications(self:getStringsField("utyp"))
@@ -1476,6 +1521,19 @@ __TS__SetDescriptor(
1476
1521
  },
1477
1522
  true
1478
1523
  )
1524
+ __TS__SetDescriptor(
1525
+ UnitType.prototype,
1526
+ "level",
1527
+ {
1528
+ get = function(self)
1529
+ return self:getNumberField("ulev")
1530
+ end,
1531
+ set = function(self, level)
1532
+ self:setNumberField("ulev", level)
1533
+ end
1534
+ },
1535
+ true
1536
+ )
1479
1537
  __TS__SetDescriptor(
1480
1538
  UnitType.prototype,
1481
1539
  "manaRegenerationRate",
@@ -12,7 +12,7 @@ import { ReadonlyNonEmptyLinkedSet } from "../../utility/linked-set";
12
12
  export declare abstract class AbilityField<ValueType extends number | string | boolean = number | string | boolean, NativeFieldType extends jabilityfield = jabilityfield> extends ObjectField<AbilityType, Ability, ValueType, NativeFieldType> {
13
13
  protected get instanceClass(): typeof Ability;
14
14
  protected getObjectDataEntryId(instance: Ability): AbilityTypeId;
15
- protected hasNativeFieldValue(instance: Ability): boolean;
15
+ protected hasNativeFieldValue(abilityTypeId: AbilityTypeId): boolean;
16
16
  static get valueChangeEvent(): ObjectFieldValueChangeEvent<ReadonlyObjectFieldType<AbilityField>>;
17
17
  }
18
18
  export declare class AbilityBooleanField extends AbilityField<boolean, jabilitybooleanfield> {
@@ -48,7 +48,7 @@ export declare class AbilityStringField extends AbilityField<string, jabilitystr
48
48
  export declare abstract class AbilityArrayField<ValueType extends number | string | boolean = number | string | boolean, NativeFieldType extends jabilityfield = jabilityfield> extends ObjectArrayField<AbilityType, Ability, ValueType, NativeFieldType> {
49
49
  protected get instanceClass(): typeof Ability;
50
50
  protected getObjectDataEntryId(instance: Ability): AbilityTypeId;
51
- protected hasNativeFieldValue(instance: Ability): boolean;
51
+ protected hasNativeFieldValue(abilityTypeId: AbilityTypeId): boolean;
52
52
  }
53
53
  export declare class AbilityStringArrayField extends AbilityArrayField<string, jabilitystringlevelfield> {
54
54
  protected get defaultValue(): string;
@@ -68,7 +68,7 @@ export declare abstract class AbilityLevelField<ValueType extends number | strin
68
68
  protected get instanceClass(): typeof Ability;
69
69
  protected getLevelCount(entry: AbilityType | Ability): number;
70
70
  protected getObjectDataEntryId(instance: Ability): AbilityTypeId;
71
- protected hasNativeFieldValue(instance: Ability): boolean;
71
+ protected hasNativeFieldValue(abilityTypeId: AbilityTypeId): boolean;
72
72
  static get valueChangeEvent(): ObjectLevelFieldValueChangeEvent<ReadonlyObjectLevelFieldType<AbilityLevelField>>;
73
73
  }
74
74
  export declare class AbilityBooleanLevelField extends AbilityLevelField<boolean, boolean, jabilityintegerlevelfield> {
@@ -7,6 +7,7 @@ local __TS__InstanceOf = ____lualib.__TS__InstanceOf
7
7
  local ____exports = {}
8
8
  local ____ability = require("engine.internal.ability")
9
9
  local Ability = ____ability.Ability
10
+ local abilityTypeHasField = ____ability.abilityTypeHasField
10
11
  local ____object_2Dfield = require("engine.object-field")
11
12
  local ObjectArrayField = ____object_2Dfield.ObjectArrayField
12
13
  local ObjectField = ____object_2Dfield.ObjectField
@@ -29,8 +30,8 @@ __TS__ClassExtends(AbilityField, ObjectField)
29
30
  function AbilityField.prototype.getObjectDataEntryId(self, instance)
30
31
  return instance.typeId
31
32
  end
32
- function AbilityField.prototype.hasNativeFieldValue(self, instance)
33
- return instance:hasField(self.nativeField)
33
+ function AbilityField.prototype.hasNativeFieldValue(self, abilityTypeId)
34
+ return abilityTypeHasField(abilityTypeId, self.nativeField)
34
35
  end
35
36
  __TS__SetDescriptor(
36
37
  AbilityField.prototype,
@@ -197,8 +198,8 @@ __TS__ClassExtends(AbilityArrayField, ObjectArrayField)
197
198
  function AbilityArrayField.prototype.getObjectDataEntryId(self, instance)
198
199
  return instance.typeId
199
200
  end
200
- function AbilityArrayField.prototype.hasNativeFieldValue(self, instance)
201
- return instance:hasField(self.nativeField)
201
+ function AbilityArrayField.prototype.hasNativeFieldValue(self, abilityTypeId)
202
+ return abilityTypeHasField(abilityTypeId, self.nativeField)
202
203
  end
203
204
  __TS__SetDescriptor(
204
205
  AbilityArrayField.prototype,
@@ -269,8 +270,8 @@ end
269
270
  function AbilityLevelField.prototype.getObjectDataEntryId(self, instance)
270
271
  return instance.typeId
271
272
  end
272
- function AbilityLevelField.prototype.hasNativeFieldValue(self, instance)
273
- return instance:hasField(self.nativeField)
273
+ function AbilityLevelField.prototype.hasNativeFieldValue(self, abilityTypeId)
274
+ return abilityTypeHasField(abilityTypeId, self.nativeField)
274
275
  end
275
276
  __TS__SetDescriptor(
276
277
  AbilityLevelField.prototype,
@@ -17,8 +17,8 @@ declare abstract class ObjectFieldBase<ObjectDataEntryType extends ObjectDataEnt
17
17
  readonly id: ObjectFieldId;
18
18
  protected abstract getNativeFieldById(id: number): NativeFieldType;
19
19
  protected abstract getObjectDataEntryId(instance: InstanceType): ObjectDataEntryIdType<ObjectDataEntryType>;
20
- protected abstract hasNativeFieldValue(instance: InstanceType): boolean;
21
- hasValue(instance: InstanceType): boolean;
20
+ protected abstract hasNativeFieldValue(objectDataEntryId: ObjectDataEntryIdType<ObjectDataEntryType>): boolean;
21
+ hasValue(objectDataEntryId: ObjectDataEntryIdType<ObjectDataEntryType>): boolean;
22
22
  constructor(id: number, isGlobal?: boolean);
23
23
  static create<T extends ObjectFieldBase<any, any, any, any>>(this: ObjectFieldConstructor<T>, id?: number, isGlobal?: boolean): T & symbol;
24
24
  static of<T extends ObjectFieldBase<any, any, any, any>>(this: ObjectFieldAbstractConstructor<T>, id: number): T | undefined;
@@ -58,9 +58,9 @@ end
58
58
  function ObjectFieldBase.prototype.supports(self, instance)
59
59
  return __TS__InstanceOf(instance, self.instanceClass)
60
60
  end
61
- function ObjectFieldBase.prototype.hasValue(self, instance)
61
+ function ObjectFieldBase.prototype.hasValue(self, objectDataEntryId)
62
62
  local defaultValueByObjectDataEntryId = defaultValueByObjectDataEntryIdByObjectFieldId[self.id]
63
- return self.isGlobal or defaultValueByObjectDataEntryId ~= nil and defaultValueByObjectDataEntryId[self:getObjectDataEntryId(instance)] ~= nil or self:hasNativeFieldValue(instance)
63
+ return self.isGlobal or defaultValueByObjectDataEntryId ~= nil and defaultValueByObjectDataEntryId[objectDataEntryId] ~= nil or self:hasNativeFieldValue(objectDataEntryId)
64
64
  end
65
65
  function ObjectFieldBase.create(self, id, isGlobal)
66
66
  return __TS__New(
@@ -215,8 +215,9 @@ function ObjectField.prototype.getActualValue(self, instance)
215
215
  end
216
216
  function ObjectField.prototype.setActualValue(self, instance, value)
217
217
  local defaultValueByObjectDataEntryId = defaultValueByObjectDataEntryIdByObjectFieldId[self.id]
218
+ local objectDataEntryId = self:getObjectDataEntryId(instance)
218
219
  if defaultValueByObjectDataEntryId ~= nil or self.isGlobal then
219
- local defaultValue = (defaultValueByObjectDataEntryId or emptyLuaMap())[self:getObjectDataEntryId(instance)]
220
+ local defaultValue = (defaultValueByObjectDataEntryId or emptyLuaMap())[objectDataEntryId]
220
221
  if defaultValue ~= nil or self.isGlobal then
221
222
  local ____self_valueByInstance_instance_3 = self.valueByInstance[instance]
222
223
  if ____self_valueByInstance_instance_3 == nil then
@@ -234,7 +235,7 @@ function ObjectField.prototype.setActualValue(self, instance, value)
234
235
  return true
235
236
  end
236
237
  end
237
- if not self:hasNativeFieldValue(instance) then
238
+ if not self:hasNativeFieldValue(objectDataEntryId) then
238
239
  return false
239
240
  end
240
241
  local previousValue = self:getNativeFieldValue(instance)
@@ -460,8 +461,9 @@ function ObjectLevelField.prototype.setValue(self, entry, levelOrValue, value)
460
461
  return true
461
462
  end
462
463
  local defaultValueByObjectDataEntryId = defaultValueByObjectDataEntryIdByObjectFieldId[self.id]
464
+ local objectDataEntryId = self:getObjectDataEntryId(entry)
463
465
  if defaultValueByObjectDataEntryId ~= nil or self.isGlobal then
464
- local defaultValueByLevel = (defaultValueByObjectDataEntryId or emptyLuaMap())[self:getObjectDataEntryId(entry)]
466
+ local defaultValueByLevel = (defaultValueByObjectDataEntryId or emptyLuaMap())[objectDataEntryId]
465
467
  if defaultValueByLevel ~= nil or self.isGlobal then
466
468
  local valueByLevel = self.valueByInstance[entry]
467
469
  if valueByLevel == nil then
@@ -490,7 +492,7 @@ function ObjectLevelField.prototype.setValue(self, entry, levelOrValue, value)
490
492
  return true
491
493
  end
492
494
  end
493
- if not self:hasNativeFieldValue(entry) then
495
+ if not self:hasNativeFieldValue(objectDataEntryId) then
494
496
  return false
495
497
  end
496
498
  local previousValue = self:getNativeFieldValue(entry, level)
@@ -1,4 +1,5 @@
1
1
  /** @noSelfInFile */
2
+ import { ReadonlyNonEmptyArray } from "../utility/types";
2
3
  export declare const randomAngle: () => number;
3
4
  export declare const randomInteger: {
4
5
  (upperBound?: number): number;
@@ -9,3 +10,11 @@ export declare const randomFloat: {
9
10
  (lowerBound: number, upperBound: number): number;
10
11
  };
11
12
  export declare const randomXY: (centerX: number, centerY: number, range: number) => LuaMultiReturn<[x: number, y: number]>;
13
+ export declare const randomElement: {
14
+ <T>(array: ReadonlyNonEmptyArray<T>): T;
15
+ <T>(array: ReadonlyArray<T>): T | undefined;
16
+ };
17
+ export declare const random: {
18
+ <T>(element: T, ...elements: T[]): T;
19
+ <T>(...elements: T[]): T | undefined;
20
+ };
package/engine/random.lua CHANGED
@@ -4,6 +4,7 @@ local MAXIMUM_INTEGER = ____math.MAXIMUM_INTEGER
4
4
  local PI = ____math.PI
5
5
  local getRandomInt = GetRandomInt
6
6
  local getRandomReal = GetRandomReal
7
+ local select = _G.select
7
8
  local cos = math.cos
8
9
  local sin = math.sin
9
10
  local sqrt = math.sqrt
@@ -15,4 +16,16 @@ ____exports.randomXY = function(centerX, centerY, range)
15
16
  local t = getRandomReal(0, 1) * 2 * PI
16
17
  return centerX + r * cos(t), centerY + r * sin(t)
17
18
  end
19
+ ____exports.randomElement = function(array)
20
+ return array[getRandomInt(1, #array)]
21
+ end
22
+ ____exports.random = function(...)
23
+ return (select(
24
+ getRandomInt(
25
+ 1,
26
+ select("#", ...)
27
+ ),
28
+ ...
29
+ ))
30
+ end
18
31
  return ____exports
@@ -0,0 +1,11 @@
1
+ /** @noSelfInFile */
2
+ import { Player } from "../core/types/player";
3
+ import { Event } from "../event";
4
+ export declare const synchronizer: <T, K extends number>(getSyncId: (object: T) => K, getObject: (syncId: K) => T | undefined) => ((player: Player, object: T | undefined) => Promise<T | undefined>);
5
+ export declare class ObjectBus<T, K extends number> {
6
+ private readonly getSyncId;
7
+ readonly event: Event<[Player, T | undefined]>;
8
+ private readonly syncSlider;
9
+ constructor(getSyncId: (object: T) => K, getObject: (syncId: K) => T | undefined);
10
+ send(object: T | undefined): void;
11
+ }