warscript 0.0.1-dev.008d8ef → 0.0.1-dev.062a781

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.
@@ -25,11 +25,13 @@ export declare class Frame extends Handle<jframehandle> {
25
25
  static readonly GAME_UI: Frame;
26
26
  static readonly CONSOLE_UI: Frame;
27
27
  static readonly CONSOLE_UI_BACKDROP: Frame;
28
+ private static readonly CONSOLE_UI_BACKDROP_UI_SCALE_HELPER_CHILD;
28
29
  static readonly CONSOLE_TOP_BAR: Frame;
29
30
  static readonly CONSOLE_BOTTOM_BAR: Frame;
30
31
  static readonly WORLD: Frame;
31
32
  static readonly CHAT: Frame;
32
33
  static readonly TIME_OF_DAY_CLOCK: Frame;
34
+ static get uiScale(): number;
33
35
  static get leftBorder(): Frame;
34
36
  static get rightBorder(): Frame;
35
37
  static get minX(): number;
@@ -62,8 +62,10 @@ local function updateBorders()
62
62
  local width4by3 = (w - h / 600 * 800) / 2
63
63
  local pxtodpi = 0.6 / h
64
64
  BlzFrameSetAbsPoint(leftBorder, FRAMEPOINT_TOPLEFT, -width4by3 * pxtodpi, 0.6)
65
+ BlzFrameSetScale(leftBorder, 1)
65
66
  BlzFrameSetSize(leftBorder, 0.001, 0.6)
66
67
  BlzFrameSetAbsPoint(rightBorder, FRAMEPOINT_TOPRIGHT, (-width4by3 + w) * pxtodpi, 0.6)
68
+ BlzFrameSetScale(rightBorder, 1)
67
69
  BlzFrameSetSize(rightBorder, 0.001, 0.6)
68
70
  end
69
71
  local worldFrame = BlzGetOriginFrame(ORIGIN_FRAME_WORLD_FRAME, 0)
@@ -267,7 +269,16 @@ function Frame.createSimple(self, name, parent, createContext)
267
269
  ))
268
270
  end
269
271
  function Frame.create(self, name, parent, priority, createContext)
270
- return self:of(BlzCreateFrame(name, parent.handle, priority or 0, createContext or 0))
272
+ if parent == ____exports.Frame.CONSOLE_UI_BACKDROP then
273
+ local helper = ____exports.Frame.CONSOLE_UI_BACKDROP_UI_SCALE_HELPER_CHILD.handle
274
+ BlzFrameSetScale(helper, 1)
275
+ local frame = BlzCreateFrame(name, helper, priority or 0, createContext or 0)
276
+ BlzFrameSetScale(helper, ____exports.Frame.uiScale)
277
+ BlzFrameSetParent(frame, ____exports.Frame.CONSOLE_UI_BACKDROP.handle)
278
+ return self:of(frame)
279
+ else
280
+ return self:of(BlzCreateFrame(name, parent.handle, priority or 0, createContext or 0))
281
+ end
271
282
  end
272
283
  function Frame.createByType(self, typeName, name, parent, inherits, createContext)
273
284
  return self:of(BlzCreateFrameByType(
@@ -293,11 +304,19 @@ end
293
304
  Frame.GAME_UI = ____exports.Frame:byOrigin(ORIGIN_FRAME_GAME_UI)
294
305
  Frame.CONSOLE_UI = ____exports.Frame:byOrigin(ORIGIN_FRAME_SIMPLE_UI_PARENT)
295
306
  Frame.CONSOLE_UI_BACKDROP = ____exports.Frame:byName("ConsoleUIBackdrop")
307
+ Frame.CONSOLE_UI_BACKDROP_UI_SCALE_HELPER_CHILD = ____exports.Frame:createByType("FRAME", "ConsoleUIBackdropUIScaleHelperChild", ____exports.Frame.CONSOLE_UI_BACKDROP)
296
308
  Frame.CONSOLE_TOP_BAR = ____exports.Frame:byName("ConsoleTopBar")
297
309
  Frame.CONSOLE_BOTTOM_BAR = ____exports.Frame:byName("ConsoleBottomBar")
298
310
  Frame.WORLD = ____exports.Frame:byOrigin(ORIGIN_FRAME_WORLD_FRAME)
299
311
  Frame.CHAT = ____exports.Frame:byOrigin(ORIGIN_FRAME_CHAT_MSG)
300
312
  Frame.TIME_OF_DAY_CLOCK = ____exports.Frame.GAME_UI:getChild(5):getChild(0)
313
+ __TS__ObjectDefineProperty(
314
+ Frame,
315
+ "uiScale",
316
+ {get = function(self)
317
+ return ____exports.Frame.CONSOLE_BOTTOM_BAR.width / 0.8
318
+ end}
319
+ )
301
320
  __TS__ObjectDefineProperty(
302
321
  Frame,
303
322
  "leftBorder",
@@ -1,11 +1,9 @@
1
1
  /** @noSelfInFile */
2
2
  import { AbilityBehavior } from "../ability";
3
3
  import { Ability } from "../../internal/ability";
4
- import { Buff, BuffConstructor, BuffParameters, BuffTypeIdSelectionPolicy } from "../../buff";
4
+ import { Buff, BuffConstructor, BuffParameters, BuffPolarityParameterType, BuffResistanceTypeParameterType, BuffTypeIdSelectionPolicy } from "../../buff";
5
5
  import { Unit } from "../../internal/unit";
6
6
  import { ApplicableBuffTypeId } from "../../object-data/entry/buff-type/applicable";
7
- import { BuffResistanceType } from "../../object-data/auxiliary/buff-resistance-type";
8
- import { BuffPolarity } from "../../object-data/auxiliary/buff-polarity";
9
7
  import { Widget } from "../../../core/types/widget";
10
8
  type BuffParametersType<T extends BuffConstructor> = BuffParameters & Omit<BuffAdditionalParametersType<T>, keyof BuffParameters>;
11
9
  type BuffAdditionalParametersType<T extends BuffConstructor> = T extends BuffConstructor<Buff<infer AdditionalParameters>> ? AdditionalParameters : never;
@@ -17,8 +15,8 @@ export declare abstract class ApplyBuffAbilityBehavior<T extends BuffConstructor
17
15
  typeIds: [ApplicableBuffTypeId, ...ApplicableBuffTypeId[]],
18
16
  typeIdSelectionPolicy: BuffTypeIdSelectionPolicy
19
17
  ],
20
- polarity: BuffPolarity,
21
- resistanceType: BuffResistanceType,
18
+ polarity: BuffPolarityParameterType,
19
+ resistanceType: BuffResistanceTypeParameterType,
22
20
  parameters?: BuffParametersType<T>
23
21
  ]);
24
22
  }
package/engine/buff.d.ts CHANGED
@@ -5,16 +5,19 @@ import { Ability } from "./internal/ability";
5
5
  import { AbilityTypeId } from "./object-data/entry/ability-type";
6
6
  import { BuffPolarity } from "./object-data/auxiliary/buff-polarity";
7
7
  import { BuffResistanceType } from "./object-data/auxiliary/buff-resistance-type";
8
- import { AbilityBooleanField, AbilityBooleanLevelField, AbilityCombatClassificationsLevelField, AbilityDependentValue, AbilityIntegerField, AbilityIntegerLevelField, AbilityNumberField, AbilityNumberLevelField } from "./object-field/ability";
8
+ import { AbilityBooleanField, AbilityBooleanLevelField, AbilityCombatClassificationsLevelField, AbilityDependentValue, AbilityEnumLevelField, AbilityIntegerField, AbilityIntegerLevelField, AbilityNumberField, AbilityNumberLevelField } from "./object-field/ability";
9
9
  import { CombatClassifications } from "./object-data/auxiliary/combat-classification";
10
- import { IsExactlyAny, NonEmptyArray, Prohibit } from "../utility/types";
10
+ import { IsExactlyAny, Prohibit, ReadonlyNonEmptyArray } from "../utility/types";
11
11
  import { UnitBehavior } from "./behaviour/unit";
12
12
  import type { Widget } from "../core/types/widget";
13
13
  import { Destructor } from "../destroyable";
14
14
  export type BuffConstructor<T extends Buff<any> = Buff<any>, Args extends any[] = any> = OmitConstructor<typeof Buff<any>> & (new (...args: Args) => T);
15
+ type EnumParameterValueType<T extends number> = T | AbilityEnumLevelField<T>;
15
16
  type NumberParameterValueType = number | AbilityNumberField | AbilityNumberLevelField;
16
17
  type IntegerParameterValueType = number | AbilityIntegerField | AbilityIntegerLevelField;
17
18
  type BooleanParameterValueType = boolean | AbilityBooleanField | AbilityBooleanLevelField;
19
+ export type BuffPolarityParameterType = EnumParameterValueType<BuffPolarity>;
20
+ export type BuffResistanceTypeParameterType = EnumParameterValueType<BuffResistanceType>;
18
21
  export declare class BuffUniqueGroup {
19
22
  }
20
23
  export type BuffParameters<T extends Buff<any> = Buff> = Buff extends T ? {
@@ -51,6 +54,7 @@ export type BuffParameters<T extends Buff<any> = Buff> = Buff extends T ? {
51
54
  armorIncreaseFactor?: NumberParameterValueType;
52
55
  attackSpeedIncreaseFactor?: NumberParameterValueType;
53
56
  movementSpeedIncreaseFactor?: NumberParameterValueType;
57
+ damageFactor?: NumberParameterValueType;
54
58
  receivedDamageFactor?: NumberParameterValueType;
55
59
  receivedMagicDamageFactor?: NumberParameterValueType;
56
60
  durationIncreaseOnAutoAttack?: NumberParameterValueType;
@@ -64,6 +68,12 @@ export type BuffParameters<T extends Buff<any> = Buff> = Buff extends T ? {
64
68
  disablesAutoAttack?: BooleanParameterValueType;
65
69
  destroysOnDamage?: BooleanParameterValueType;
66
70
  maximumAutoAttackCount?: IntegerParameterValueType;
71
+ maximumDamageDealtEventCount?: IntegerParameterValueType;
72
+ maximumDamageReceivedEventCount?: IntegerParameterValueType;
73
+ damageOnExpiration?: NumberParameterValueType;
74
+ healingOnExpiration?: NumberParameterValueType;
75
+ killsOnExpiration?: BooleanParameterValueType;
76
+ explodesOnExpiration?: BooleanParameterValueType;
67
77
  uniqueGroup?: BuffUniqueGroup;
68
78
  } : BuffParameters & (T extends Buff<infer AdditionalParameters> ? AdditionalParameters : object);
69
79
  declare const enum BuffPropertyKey {
@@ -86,19 +96,27 @@ declare const enum BuffPropertyKey {
86
96
  HEALING_INTERVAL = 116,
87
97
  REMAINING_HEALING_OVER_DURATION = 117,
88
98
  HEALING_INTERVAL_TIMER = 118,
89
- DAMAGE_UPON_DEATH_ALLOWED_TARGET_CLASSIFICATIONS = 119,
90
- DAMAGE_UPON_DEATH = 120,
91
- DAMAGE_UPON_DEATH_RANGE = 121,
92
- MEDIUM_DAMAGE_UPON_DEATH = 122,
93
- MEDIUM_DAMAGE_UPON_DEATH_RANGE = 123,
94
- SMALL_DAMAGE_UPON_DEATH = 124,
95
- SMALL_DAMAGE_UPON_DEATH_RANGE = 125,
96
- AUTO_ATTACK_COUNT = 126,
97
- MAXIMUM_AUTO_ATTACK_COUNT = 127,
98
- STUNS = 128,
99
- IGNORES_STUN_IMMUNITY = 129,
100
- DISABLES_AUTO_ATTACK = 130,
101
- PROVIDES_INVULNERABILITY = 131
99
+ DAMAGE_ON_EXPIRATION = 119,
100
+ HEALING_ON_EXPIRATION = 120,
101
+ DAMAGE_UPON_DEATH_ALLOWED_TARGET_CLASSIFICATIONS = 121,
102
+ DAMAGE_UPON_DEATH = 122,
103
+ DAMAGE_UPON_DEATH_RANGE = 123,
104
+ MEDIUM_DAMAGE_UPON_DEATH = 124,
105
+ MEDIUM_DAMAGE_UPON_DEATH_RANGE = 125,
106
+ SMALL_DAMAGE_UPON_DEATH = 126,
107
+ SMALL_DAMAGE_UPON_DEATH_RANGE = 127,
108
+ AUTO_ATTACK_COUNT = 128,
109
+ MAXIMUM_AUTO_ATTACK_COUNT = 129,
110
+ DAMAGE_DEALT_EVENT_COUNT = 130,
111
+ MAXIMUM_DAMAGE_DEALT_EVENT_COUNT = 131,
112
+ DAMAGE_RECEIVED_EVENT_COUNT = 132,
113
+ MAXIMUM_DAMAGE_RECEIVED_EVENT_COUNT = 133,
114
+ STUNS = 134,
115
+ IGNORES_STUN_IMMUNITY = 135,
116
+ DISABLES_AUTO_ATTACK = 136,
117
+ PROVIDES_INVULNERABILITY = 137,
118
+ KILLS_ON_EXPIRATION = 138,
119
+ EXPLODES_ON_EXPIRATION = 139
102
120
  }
103
121
  export declare const enum BuffTypeIdSelectionPolicy {
104
122
  LEAST_DURATION = 0
@@ -106,11 +124,11 @@ export declare const enum BuffTypeIdSelectionPolicy {
106
124
  export type BuffAdditionalParameters = Prohibit<Record<string, any>, keyof BuffParameters>;
107
125
  export type BuffConstructorParameters<AdditionalParameters extends BuffAdditionalParameters> = [
108
126
  ...typeId: [ApplicableBuffTypeId] | [
109
- typeIds: NonEmptyArray<ApplicableBuffTypeId>,
127
+ typeIds: ReadonlyNonEmptyArray<ApplicableBuffTypeId>,
110
128
  typeIdSelectionPolicy: BuffTypeIdSelectionPolicy
111
129
  ],
112
- polarity: BuffPolarity,
113
- resistanceType: BuffResistanceType,
130
+ polarity: BuffPolarityParameterType,
131
+ resistanceType: BuffResistanceTypeParameterType,
114
132
  ...abilityOrParameters: [
115
133
  ability: Ability,
116
134
  parameters?: BuffParameters & Omit<AdditionalParameters, keyof BuffParameters>
@@ -138,6 +156,8 @@ export declare class Buff<AdditionalParameters extends Prohibit<Record<string, a
138
156
  private [BuffPropertyKey.HEALING_INTERVAL]?;
139
157
  private [BuffPropertyKey.REMAINING_HEALING_OVER_DURATION]?;
140
158
  private [BuffPropertyKey.HEALING_INTERVAL_TIMER]?;
159
+ private [BuffPropertyKey.DAMAGE_ON_EXPIRATION]?;
160
+ private [BuffPropertyKey.HEALING_ON_EXPIRATION]?;
141
161
  private [BuffPropertyKey.DAMAGE_UPON_DEATH_ALLOWED_TARGET_CLASSIFICATIONS]?;
142
162
  private [BuffPropertyKey.DAMAGE_UPON_DEATH]?;
143
163
  private [BuffPropertyKey.DAMAGE_UPON_DEATH_RANGE]?;
@@ -147,10 +167,16 @@ export declare class Buff<AdditionalParameters extends Prohibit<Record<string, a
147
167
  private [BuffPropertyKey.SMALL_DAMAGE_UPON_DEATH_RANGE]?;
148
168
  private [BuffPropertyKey.MAXIMUM_AUTO_ATTACK_COUNT]?;
149
169
  private [BuffPropertyKey.AUTO_ATTACK_COUNT]?;
170
+ private [BuffPropertyKey.MAXIMUM_DAMAGE_DEALT_EVENT_COUNT]?;
171
+ private [BuffPropertyKey.DAMAGE_DEALT_EVENT_COUNT]?;
172
+ private [BuffPropertyKey.MAXIMUM_DAMAGE_RECEIVED_EVENT_COUNT]?;
173
+ private [BuffPropertyKey.DAMAGE_RECEIVED_EVENT_COUNT]?;
150
174
  private [BuffPropertyKey.STUNS]?;
151
175
  private [BuffPropertyKey.IGNORES_STUN_IMMUNITY]?;
152
176
  private [BuffPropertyKey.DISABLES_AUTO_ATTACK]?;
153
177
  private [BuffPropertyKey.PROVIDES_INVULNERABILITY]?;
178
+ private [BuffPropertyKey.KILLS_ON_EXPIRATION]?;
179
+ private [BuffPropertyKey.EXPLODES_ON_EXPIRATION]?;
154
180
  protected static readonly defaultParameters: BuffParameters;
155
181
  get source(): Unit;
156
182
  readonly typeId: ApplicableBuffTypeId;
@@ -187,6 +213,12 @@ export declare class Buff<AdditionalParameters extends Prohibit<Record<string, a
187
213
  set healingPerInterval(healingPerInterval: number);
188
214
  get healingInterval(): number;
189
215
  set healingInterval(healingInterval: number);
216
+ get damageOnExpiration(): number;
217
+ set damageOnExpiration(damageOnExpiration: number);
218
+ get healingOnExpiration(): number;
219
+ set healingOnExpiration(healingOnExpiration: number);
220
+ get damageFactor(): number;
221
+ set damageFactor(damageFactor: number);
190
222
  get receivedDamageFactor(): number;
191
223
  set receivedDamageFactor(receivedDamageFactor: number);
192
224
  get armorIncrease(): number;
@@ -199,6 +231,14 @@ export declare class Buff<AdditionalParameters extends Prohibit<Record<string, a
199
231
  set disablesAutoAttack(disablesAutoAttack: boolean);
200
232
  get providesInvulnerability(): boolean;
201
233
  set providesInvulnerability(providesInvulnerability: boolean);
234
+ get killsOnExpiration(): boolean;
235
+ set killsOnExpiration(killsOnExpiration: boolean);
236
+ get explodesOnExpiration(): boolean;
237
+ set explodesOnExpiration(killsOnExpiration: boolean);
238
+ get maximumDamageDealtEventCount(): number;
239
+ set maximumDamageDealtEventCount(maximumDamageDealtEventCount: number);
240
+ get maximumDamageReceivedEventCount(): number;
241
+ set maximumDamageReceivedEventCount(maximumDamageReceivedEventCount: number);
202
242
  get maximumAutoAttackCount(): number;
203
243
  set maximumAutoAttackCount(maximumAutoAttackCount: number);
204
244
  get durationIncreaseOnAutoAttack(): number;
@@ -215,7 +255,9 @@ export declare class Buff<AdditionalParameters extends Prohibit<Record<string, a
215
255
  protected onDestroy(): Destructor;
216
256
  static apply<T extends Buff<any>, Args extends any[]>(this: BuffConstructor<T, Args>, ...args: Args): T | undefined;
217
257
  static getByTypeId<T extends Buff<any>, Args extends any[]>(this: BuffConstructor<T, Args>, unit: Unit, typeId: ApplicableBuffTypeId): T | undefined;
258
+ onExpiration(): void;
218
259
  onDeath(source: Unit | undefined): void;
219
260
  onDamageDealt(target: Unit, event: DamageEvent): void;
261
+ onDamageReceived(source: Unit | undefined, event: DamageEvent): void;
220
262
  }
221
263
  export {};
package/engine/buff.lua CHANGED
@@ -94,6 +94,7 @@ local buffParametersKeys = {
94
94
  armorIncreaseFactor = true,
95
95
  attackSpeedIncreaseFactor = true,
96
96
  movementSpeedIncreaseFactor = true,
97
+ damageFactor = true,
97
98
  receivedDamageFactor = true,
98
99
  receivedMagicDamageFactor = true,
99
100
  durationIncreaseOnAutoAttack = true,
@@ -107,8 +108,26 @@ local buffParametersKeys = {
107
108
  disablesAutoAttack = true,
108
109
  destroysOnDamage = true,
109
110
  maximumAutoAttackCount = true,
110
- uniqueGroup = true
111
+ maximumDamageDealtEventCount = true,
112
+ maximumDamageReceivedEventCount = true,
113
+ uniqueGroup = true,
114
+ damageOnExpiration = true,
115
+ healingOnExpiration = true,
116
+ killsOnExpiration = true,
117
+ explodesOnExpiration = true
111
118
  }
119
+ local function resolveEnumValue(ability, level, value)
120
+ if value == nil or type(value) == "number" then
121
+ return value
122
+ end
123
+ if ability == nil then
124
+ error(
125
+ __TS__New(IllegalArgumentException),
126
+ 0
127
+ )
128
+ end
129
+ return value:getValue(ability, level or ability.level)
130
+ end
112
131
  local function resolveNumberValue(ability, level, value)
113
132
  if value == nil or type(value) == "number" then
114
133
  return value
@@ -145,20 +164,32 @@ local function resolveAndSetNumberValue(buff, property, ability, level, value, d
145
164
  buff[property] = resolvedValue
146
165
  end
147
166
  end
148
- local buffBooleanParameters = {"stuns", "ignoresStunImmunity", "disablesAutoAttack", "providesInvulnerability"}
167
+ local buffBooleanParameters = {
168
+ "stuns",
169
+ "ignoresStunImmunity",
170
+ "disablesAutoAttack",
171
+ "providesInvulnerability",
172
+ "killsOnExpiration",
173
+ "explodesOnExpiration"
174
+ }
149
175
  local buffNumberParameters = {
150
176
  "durationIncreaseOnAutoAttack",
151
177
  "attackSpeedIncreaseFactor",
152
178
  "movementSpeedIncreaseFactor",
153
179
  "armorIncrease",
180
+ "damageFactor",
154
181
  "receivedDamageFactor",
155
182
  "maximumAutoAttackCount",
183
+ "maximumDamageDealtEventCount",
184
+ "maximumDamageReceivedEventCount",
156
185
  "damageInterval",
157
186
  "damagePerInterval",
158
187
  "damageOverDuration",
159
188
  "healingInterval",
160
189
  "healingPerInterval",
161
- "healingOverDuration"
190
+ "healingOverDuration",
191
+ "damageOnExpiration",
192
+ "healingOnExpiration"
162
193
  }
163
194
  local unsuccessfulApplicationMarker = {}
164
195
  local function selectBuffTypeIdWithLeastDuration(buffTypeIds, unit)
@@ -207,6 +238,7 @@ local function expireBuff(buff)
207
238
  end
208
239
  end
209
240
  Timer:run(destroyBuff, buff)
241
+ buff:onExpiration()
210
242
  end
211
243
  local function buffDamageIntervalInitialTimerCallback(buff)
212
244
  buffDamageIntervalTimerCallback(buff)
@@ -296,8 +328,6 @@ function Buff.prototype.____constructor(self, _unit, typeIdOrTypeIds, polarityOr
296
328
  end
297
329
  end
298
330
  self.typeId = typeId
299
- self.polarity = polarity
300
- self.resistanceType = resistanceType
301
331
  if not __TS__InstanceOf(ability, Ability) then
302
332
  parameters = ability
303
333
  ability = nil
@@ -324,6 +354,8 @@ function Buff.prototype.____constructor(self, _unit, typeIdOrTypeIds, polarityOr
324
354
  learnLevelMinimum = learnLevelMinimum or ability:getField(ABILITY_IF_REQUIRED_LEVEL)
325
355
  duration = duration or getAbilityDuration(ability, _unit)
326
356
  end
357
+ self.polarity = resolveEnumValue(ability, level, polarity)
358
+ self.resistanceType = resolveEnumValue(ability, level, resistanceType)
327
359
  local buffByTypeId = buffByTypeIdByUnit[_unit]
328
360
  if buffByTypeId == nil then
329
361
  buffByTypeId = {}
@@ -340,8 +372,8 @@ function Buff.prototype.____constructor(self, _unit, typeIdOrTypeIds, polarityOr
340
372
  if not internalApplyBuff(
341
373
  _unit,
342
374
  typeId,
343
- polarity,
344
- resistanceType,
375
+ self.polarity,
376
+ self.resistanceType,
345
377
  level,
346
378
  duration,
347
379
  spellStealPriority,
@@ -530,11 +562,11 @@ function Buff.prototype.onDestroy(self)
530
562
  behavior:destroy()
531
563
  end
532
564
  end
533
- if self[130] then
565
+ if self[136] then
534
566
  unit:decrementDisableAutoAttackCounter()
535
567
  end
536
- if self[128] then
537
- if self[129] then
568
+ if self[134] then
569
+ if self[135] then
538
570
  unit:decrementStunCounter()
539
571
  end
540
572
  unit:decrementStunCounter()
@@ -583,20 +615,34 @@ function Buff.getByTypeId(self, unit, typeId)
583
615
  end
584
616
  return nil
585
617
  end
586
- function Buff.prototype.onDeath(self, source)
618
+ function Buff.prototype.onExpiration(self)
587
619
  local unit = self.unit
588
620
  if self[119] ~= nil then
621
+ (self[101] or unit):damageTarget(unit, self[119] or 0)
622
+ end
623
+ if self[120] ~= nil then
624
+ (self[101] or unit):healTarget(unit, self[119] or 0)
625
+ end
626
+ if self[139] then
627
+ unit:explode()
628
+ elseif self[138] then
629
+ unit:kill()
630
+ end
631
+ end
632
+ function Buff.prototype.onDeath(self, source)
633
+ local unit = self.unit
634
+ if self[121] ~= nil then
589
635
  damageArea(
590
636
  self[101] or unit,
591
- self[119],
637
+ self[121],
592
638
  unit.x,
593
639
  unit.y,
594
- self[121] or 0,
595
- self[120] or 0,
596
640
  self[123] or 0,
597
641
  self[122] or 0,
598
642
  self[125] or 0,
599
- self[124] or 0
643
+ self[124] or 0,
644
+ self[127] or 0,
645
+ self[126] or 0
600
646
  )
601
647
  end
602
648
  end
@@ -618,9 +664,25 @@ function Buff.prototype.onDamageDealt(self, target, event)
618
664
  end
619
665
  self.remainingDuration = remainingDuration
620
666
  end
621
- local autoAttackCount = (self[126] or 0) + 1
622
- self[126] = autoAttackCount
623
- if autoAttackCount == self[127] then
667
+ local autoAttackCount = (self[128] or 0) + 1
668
+ self[128] = autoAttackCount
669
+ if autoAttackCount == self[129] then
670
+ self:destroy()
671
+ end
672
+ end
673
+ if event.originalAmount ~= 0 then
674
+ local damageDealtEventCount = (self[130] or 0) + 1
675
+ self[130] = damageDealtEventCount
676
+ if damageDealtEventCount == self[131] then
677
+ self:destroy()
678
+ end
679
+ end
680
+ end
681
+ function Buff.prototype.onDamageReceived(self, source, event)
682
+ if event.originalAmount ~= 0 then
683
+ local damageReceivedEventCount = (self[132] or 0) + 1
684
+ self[132] = damageReceivedEventCount
685
+ if damageReceivedEventCount == self[133] then
624
686
  self:destroy()
625
687
  end
626
688
  end
@@ -802,6 +864,45 @@ __TS__SetDescriptor(
802
864
  },
803
865
  true
804
866
  )
867
+ __TS__SetDescriptor(
868
+ Buff.prototype,
869
+ "damageOnExpiration",
870
+ {
871
+ get = function(self)
872
+ return self[119] or 0
873
+ end,
874
+ set = function(self, damageOnExpiration)
875
+ self[119] = damageOnExpiration ~= 0 and damageOnExpiration or nil
876
+ end
877
+ },
878
+ true
879
+ )
880
+ __TS__SetDescriptor(
881
+ Buff.prototype,
882
+ "healingOnExpiration",
883
+ {
884
+ get = function(self)
885
+ return self[120] or 0
886
+ end,
887
+ set = function(self, healingOnExpiration)
888
+ self[120] = healingOnExpiration ~= 0 and healingOnExpiration or nil
889
+ end
890
+ },
891
+ true
892
+ )
893
+ __TS__SetDescriptor(
894
+ Buff.prototype,
895
+ "damageFactor",
896
+ {
897
+ get = function(self)
898
+ return self:getUnitBonus(UnitBonusType.DAMAGE_FACTOR)
899
+ end,
900
+ set = function(self, damageFactor)
901
+ self:addOrUpdateOrRemoveUnitBonus(UnitBonusType.DAMAGE_FACTOR, damageFactor)
902
+ end
903
+ },
904
+ true
905
+ )
805
906
  __TS__SetDescriptor(
806
907
  Buff.prototype,
807
908
  "receivedDamageFactor",
@@ -833,25 +934,25 @@ __TS__SetDescriptor(
833
934
  "stuns",
834
935
  {
835
936
  get = function(self)
836
- local ____self__128_52 = self[128]
837
- if ____self__128_52 == nil then
838
- ____self__128_52 = false
937
+ local ____self__134_52 = self[134]
938
+ if ____self__134_52 == nil then
939
+ ____self__134_52 = false
839
940
  end
840
- return ____self__128_52
941
+ return ____self__134_52
841
942
  end,
842
943
  set = function(self, stuns)
843
- if not stuns and self[128] then
844
- if self[129] then
944
+ if not stuns and self[134] then
945
+ if self[135] then
845
946
  self.object:decrementStunCounter()
846
947
  end
847
948
  self.object:decrementStunCounter()
848
- self[128] = nil
849
- elseif stuns and not self[128] then
850
- if self[129] then
949
+ self[134] = nil
950
+ elseif stuns and not self[134] then
951
+ if self[135] then
851
952
  self.object:incrementStunCounter()
852
953
  end
853
954
  self.object:incrementStunCounter()
854
- self[128] = true
955
+ self[134] = true
855
956
  end
856
957
  end
857
958
  },
@@ -862,23 +963,23 @@ __TS__SetDescriptor(
862
963
  "ignoresStunImmunity",
863
964
  {
864
965
  get = function(self)
865
- local ____self__129_53 = self[129]
866
- if ____self__129_53 == nil then
867
- ____self__129_53 = false
966
+ local ____self__135_53 = self[135]
967
+ if ____self__135_53 == nil then
968
+ ____self__135_53 = false
868
969
  end
869
- return ____self__129_53
970
+ return ____self__135_53
870
971
  end,
871
972
  set = function(self, ignoresStunImmunity)
872
- if not ignoresStunImmunity and self[129] then
873
- if self[128] then
973
+ if not ignoresStunImmunity and self[135] then
974
+ if self[134] then
874
975
  self.object:decrementStunCounter()
875
976
  end
876
- self[129] = nil
877
- elseif ignoresStunImmunity and not self[129] then
878
- if self[128] then
977
+ self[135] = nil
978
+ elseif ignoresStunImmunity and not self[135] then
979
+ if self[134] then
879
980
  self.object:incrementStunCounter()
880
981
  end
881
- self[129] = true
982
+ self[135] = true
882
983
  end
883
984
  end
884
985
  },
@@ -889,19 +990,19 @@ __TS__SetDescriptor(
889
990
  "disablesAutoAttack",
890
991
  {
891
992
  get = function(self)
892
- local ____self__130_54 = self[130]
893
- if ____self__130_54 == nil then
894
- ____self__130_54 = false
993
+ local ____self__136_54 = self[136]
994
+ if ____self__136_54 == nil then
995
+ ____self__136_54 = false
895
996
  end
896
- return ____self__130_54
997
+ return ____self__136_54
897
998
  end,
898
999
  set = function(self, disablesAutoAttack)
899
- if not disablesAutoAttack and self[130] then
1000
+ if not disablesAutoAttack and self[136] then
900
1001
  self.object:decrementDisableAutoAttackCounter()
901
- self[130] = nil
902
- elseif disablesAutoAttack and not self[130] then
1002
+ self[136] = nil
1003
+ elseif disablesAutoAttack and not self[136] then
903
1004
  self.object:incrementDisableAutoAttackCounter()
904
- self[130] = true
1005
+ self[136] = true
905
1006
  end
906
1007
  end
907
1008
  },
@@ -912,19 +1013,95 @@ __TS__SetDescriptor(
912
1013
  "providesInvulnerability",
913
1014
  {
914
1015
  get = function(self)
915
- local ____self__131_55 = self[131]
916
- if ____self__131_55 == nil then
917
- ____self__131_55 = false
1016
+ local ____self__137_55 = self[137]
1017
+ if ____self__137_55 == nil then
1018
+ ____self__137_55 = false
918
1019
  end
919
- return ____self__131_55
1020
+ return ____self__137_55
920
1021
  end,
921
1022
  set = function(self, providesInvulnerability)
922
- if not providesInvulnerability and self[131] then
1023
+ if not providesInvulnerability and self[137] then
923
1024
  self.object:decrementInvulnerabilityCounter()
924
- self[131] = nil
925
- elseif providesInvulnerability and not self[131] then
1025
+ self[137] = nil
1026
+ elseif providesInvulnerability and not self[137] then
926
1027
  self.object:incrementInvulnerabilityCounter()
927
- self[131] = true
1028
+ self[137] = true
1029
+ end
1030
+ end
1031
+ },
1032
+ true
1033
+ )
1034
+ __TS__SetDescriptor(
1035
+ Buff.prototype,
1036
+ "killsOnExpiration",
1037
+ {
1038
+ get = function(self)
1039
+ local ____self__138_56 = self[138]
1040
+ if ____self__138_56 == nil then
1041
+ ____self__138_56 = false
1042
+ end
1043
+ return ____self__138_56
1044
+ end,
1045
+ set = function(self, killsOnExpiration)
1046
+ if not killsOnExpiration and self[138] then
1047
+ self[138] = nil
1048
+ elseif killsOnExpiration and not self[138] then
1049
+ self[138] = true
1050
+ end
1051
+ end
1052
+ },
1053
+ true
1054
+ )
1055
+ __TS__SetDescriptor(
1056
+ Buff.prototype,
1057
+ "explodesOnExpiration",
1058
+ {
1059
+ get = function(self)
1060
+ local ____self__139_57 = self[139]
1061
+ if ____self__139_57 == nil then
1062
+ ____self__139_57 = false
1063
+ end
1064
+ return ____self__139_57
1065
+ end,
1066
+ set = function(self, killsOnExpiration)
1067
+ if not killsOnExpiration and self[139] then
1068
+ self[139] = nil
1069
+ elseif killsOnExpiration and not self[139] then
1070
+ self[139] = true
1071
+ end
1072
+ end
1073
+ },
1074
+ true
1075
+ )
1076
+ __TS__SetDescriptor(
1077
+ Buff.prototype,
1078
+ "maximumDamageDealtEventCount",
1079
+ {
1080
+ get = function(self)
1081
+ return self[131] or 0
1082
+ end,
1083
+ set = function(self, maximumDamageDealtEventCount)
1084
+ if maximumDamageDealtEventCount == 0 then
1085
+ self[131] = nil
1086
+ else
1087
+ self[131] = maximumDamageDealtEventCount
1088
+ end
1089
+ end
1090
+ },
1091
+ true
1092
+ )
1093
+ __TS__SetDescriptor(
1094
+ Buff.prototype,
1095
+ "maximumDamageReceivedEventCount",
1096
+ {
1097
+ get = function(self)
1098
+ return self[133] or 0
1099
+ end,
1100
+ set = function(self, maximumDamageReceivedEventCount)
1101
+ if maximumDamageReceivedEventCount == 0 then
1102
+ self[133] = nil
1103
+ else
1104
+ self[133] = maximumDamageReceivedEventCount
928
1105
  end
929
1106
  end
930
1107
  },
@@ -935,13 +1112,13 @@ __TS__SetDescriptor(
935
1112
  "maximumAutoAttackCount",
936
1113
  {
937
1114
  get = function(self)
938
- return self[127] or 0
1115
+ return self[129] or 0
939
1116
  end,
940
1117
  set = function(self, maximumAutoAttackCount)
941
1118
  if maximumAutoAttackCount == 0 then
942
- self[127] = nil
1119
+ self[129] = nil
943
1120
  else
944
- self[127] = maximumAutoAttackCount
1121
+ self[129] = maximumAutoAttackCount
945
1122
  end
946
1123
  end
947
1124
  },
@@ -999,13 +1176,13 @@ __TS__SetDescriptor(
999
1176
  "remainingDuration",
1000
1177
  {
1001
1178
  get = function(self)
1002
- local ____opt_56 = self._timer
1003
- return ____opt_56 and ____opt_56.remaining or 0
1179
+ local ____opt_58 = self._timer
1180
+ return ____opt_58 and ____opt_58.remaining or 0
1004
1181
  end,
1005
1182
  set = function(self, remainingDuration)
1006
- local ____remainingDuration_60 = remainingDuration
1007
- local ____opt_58 = self._timer
1008
- local remainingDurationDelta = ____remainingDuration_60 - (____opt_58 and ____opt_58.remaining or 0)
1183
+ local ____remainingDuration_62 = remainingDuration
1184
+ local ____opt_60 = self._timer
1185
+ local remainingDurationDelta = ____remainingDuration_62 - (____opt_60 and ____opt_60.remaining or 0)
1009
1186
  if remainingDurationDelta ~= 0 then
1010
1187
  self[102] = self[102] + remainingDurationDelta
1011
1188
  if remainingDuration <= 0 then
@@ -8,7 +8,8 @@ export type UnitBonusId<Brand extends string = any> = number & {
8
8
  export type UnitArmorBonusId = UnitBonusId<"armor">;
9
9
  export type UnitAttackSpeedFactorBonusId = UnitBonusId<"attackSpeedFactor">;
10
10
  export type UnitMovementSpeedFactorBonusId = UnitBonusId<"movementSpeedFactor">;
11
- export type UnitDamageBonusId = UnitBonusId<"damage">;
11
+ export type UnitAutoAttackDamageBonusId = UnitBonusId<"autoAttackDamage">;
12
+ export type UnitDamageFactorBonusId = UnitBonusId<"damageFactor">;
12
13
  export type UnitReceivedDamageFactorBonusId = UnitBonusId<"receivedDamageFactor">;
13
14
  export type UnitBonusType<Id extends UnitBonusId = UnitBonusId> = ({
14
15
  abilityTypeId: AbilityTypeId;
@@ -30,7 +31,8 @@ export declare namespace UnitBonusType {
30
31
  const ARMOR: UnitBonusType<UnitArmorBonusId>;
31
32
  const ATTACK_SPEED_FACTOR: UnitBonusType<UnitAttackSpeedFactorBonusId>;
32
33
  const MOVEMENT_SPEED_FACTOR: UnitBonusType<UnitAttackSpeedFactorBonusId>;
33
- const DAMAGE: UnitBonusType<UnitDamageBonusId>;
34
+ const AUTO_ATTACK_DAMAGE: UnitBonusType<UnitAutoAttackDamageBonusId>;
35
+ const DAMAGE_FACTOR: UnitBonusType<UnitReceivedDamageFactorBonusId>;
34
36
  const RECEIVED_DAMAGE_FACTOR: UnitBonusType<UnitReceivedDamageFactorBonusId>;
35
37
  }
36
38
  export declare const addUnitBonus: <Id extends UnitBonusId>(unit: Unit, bonusType: UnitBonusType<Id>, value: number) => Id;
@@ -21,6 +21,7 @@ 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 damageFactorByUnit = {}
24
25
  local receivedDamageFactorByUnit = {}
25
26
  ____exports.UnitBonusType = {}
26
27
  local UnitBonusType = ____exports.UnitBonusType
@@ -46,13 +47,14 @@ do
46
47
  reduce = sum,
47
48
  initialValue = 0
48
49
  }
49
- UnitBonusType.DAMAGE = {
50
+ UnitBonusType.AUTO_ATTACK_DAMAGE = {
50
51
  abilityTypeId = AUTO_ATTACK_DAMAGE_INCREASE_DUMMY_ABILITY_TYPE_ID,
51
52
  field = AUTO_ATTACK_DAMAGE_INCREASE_ABILITY_FIELD,
52
53
  integer = false,
53
54
  reduce = sum,
54
55
  initialValue = 0
55
56
  }
57
+ UnitBonusType.DAMAGE_FACTOR = {reduce = product, valueByUnit = damageFactorByUnit, initialValue = 1}
56
58
  UnitBonusType.RECEIVED_DAMAGE_FACTOR = {reduce = product, valueByUnit = receivedDamageFactorByUnit, initialValue = 1}
57
59
  end
58
60
  local bonusesByUnitByBonusType = {}
@@ -180,6 +182,9 @@ end
180
182
  Unit.onDamage:addListener(
181
183
  4,
182
184
  function(source, target, event)
185
+ if source ~= nil and damageFactorByUnit[source] ~= nil then
186
+ event.amount = event.amount * damageFactorByUnit[source]
187
+ end
183
188
  if receivedDamageFactorByUnit[target] ~= nil then
184
189
  event.amount = event.amount * receivedDamageFactorByUnit[target]
185
190
  end
@@ -42,6 +42,7 @@ export interface DamagingEvent {
42
42
  damageType: jdamagetype;
43
43
  weaponType: jweapontype;
44
44
  readonly isAttack: boolean;
45
+ readonly originalAmount: number;
45
46
  }
46
47
  export type DamageEvent = DamagingEvent & {
47
48
  preventDeath<P extends any[]>(this: DamageEvent, callback: (this: void, ...parameters: P) => any, ...parameters: P): void;
@@ -2452,6 +2452,7 @@ Unit.onDamage = __TS__New(
2452
2452
  damageType = BlzGetEventDamageType(),
2453
2453
  weaponType = BlzGetEventWeaponType(),
2454
2454
  isAttack = BlzGetEventIsAttack(),
2455
+ originalAmount = GetEventDamage(),
2455
2456
  preventDeath = damageEventPreventDeath
2456
2457
  }
2457
2458
  local evData = setmetatable(
@@ -6,6 +6,9 @@ import { ObjectDataEntryId } from "../object-data/entry";
6
6
  import { LightningTypeId } from "../object-data/entry/lightning-type";
7
7
  import { CombatClassifications } from "../object-data/auxiliary/combat-classification";
8
8
  import { UnitTypeId } from "../object-data/entry/unit-type";
9
+ import { BuffResistanceType } from "../object-data/auxiliary/buff-resistance-type";
10
+ import { BuffPolarity } from "../object-data/auxiliary/buff-polarity";
11
+ import { ReadonlyNonEmptyLinkedSet } from "../../utility/linked-set";
9
12
  export declare abstract class AbilityField<ValueType extends number | string | boolean = number | string | boolean, NativeFieldType extends jabilityfield = jabilityfield> extends ObjectField<AbilityType, Ability, ValueType, NativeFieldType> {
10
13
  protected get instanceClass(): typeof Ability;
11
14
  protected getObjectDataEntryId(instance: Ability): AbilityTypeId;
@@ -107,6 +110,20 @@ export declare class AbilityAbilityTypeIdLevelField extends AbilityObjectDataEnt
107
110
  }
108
111
  export declare class AbilityUnitTypeIdLevelField extends AbilityObjectDataEntryIdLevelField<UnitTypeId> {
109
112
  }
113
+ export declare abstract class AbilityEnumLevelField<T extends number> extends AbilityLevelField<T, T, jabilityintegerlevelfield> {
114
+ protected abstract values: ReadonlyNonEmptyLinkedSet<T>;
115
+ protected get defaultValue(): T;
116
+ protected getNativeFieldById(id: number): jabilityintegerlevelfield;
117
+ protected getNativeFieldValue(instance: Ability, level: number): T;
118
+ protected setNativeFieldValue(instance: Ability, level: number, value: T): boolean;
119
+ static get valueChangeEvent(): ObjectLevelFieldValueChangeEvent<AbilityBooleanLevelField>;
120
+ }
121
+ export declare class AbilityBuffPolarityLevelField extends AbilityEnumLevelField<BuffPolarity> {
122
+ protected values: ReadonlyNonEmptyLinkedSet<BuffPolarity>;
123
+ }
124
+ export declare class AbilityBuffResistanceTypeLevelField extends AbilityEnumLevelField<BuffResistanceType> {
125
+ protected values: ReadonlyNonEmptyLinkedSet<BuffResistanceType>;
126
+ }
110
127
  export declare class AbilityCombatClassificationsLevelField extends AbilityLevelField<CombatClassifications, CombatClassifications, jabilityintegerlevelfield> {
111
128
  protected get defaultValue(): CombatClassifications;
112
129
  protected getNativeFieldById(id: number): jabilityintegerlevelfield;
@@ -13,6 +13,8 @@ local ObjectField = ____object_2Dfield.ObjectField
13
13
  local ObjectLevelField = ____object_2Dfield.ObjectLevelField
14
14
  local ____ability_2Dtype = require("engine.object-data.entry.ability-type")
15
15
  local AbilityType = ____ability_2Dtype.AbilityType
16
+ local ____linked_2Dset = require("utility.linked-set")
17
+ local nonEmptyLinkedSetOf = ____linked_2Dset.nonEmptyLinkedSetOf
16
18
  local convertAbilityBooleanField = _G.ConvertAbilityBooleanField
17
19
  local convertAbilityIntegerField = _G.ConvertAbilityIntegerField
18
20
  local convertAbilityRealField = _G.ConvertAbilityRealField
@@ -431,6 +433,54 @@ ____exports.AbilityUnitTypeIdLevelField = __TS__Class()
431
433
  local AbilityUnitTypeIdLevelField = ____exports.AbilityUnitTypeIdLevelField
432
434
  AbilityUnitTypeIdLevelField.name = "AbilityUnitTypeIdLevelField"
433
435
  __TS__ClassExtends(AbilityUnitTypeIdLevelField, ____exports.AbilityObjectDataEntryIdLevelField)
436
+ ____exports.AbilityEnumLevelField = __TS__Class()
437
+ local AbilityEnumLevelField = ____exports.AbilityEnumLevelField
438
+ AbilityEnumLevelField.name = "AbilityEnumLevelField"
439
+ __TS__ClassExtends(AbilityEnumLevelField, ____exports.AbilityLevelField)
440
+ function AbilityEnumLevelField.prototype.getNativeFieldById(self, id)
441
+ return convertAbilityIntegerLevelField(id)
442
+ end
443
+ function AbilityEnumLevelField.prototype.getNativeFieldValue(self, instance, level)
444
+ local value = instance:getField(self.nativeField, level)
445
+ if self.values:contains(value) then
446
+ return value
447
+ end
448
+ return self.values:first()
449
+ end
450
+ function AbilityEnumLevelField.prototype.setNativeFieldValue(self, instance, level, value)
451
+ return instance:setField(self.nativeField, level, value)
452
+ end
453
+ __TS__SetDescriptor(
454
+ AbilityEnumLevelField.prototype,
455
+ "defaultValue",
456
+ {get = function(self)
457
+ return self.values:first()
458
+ end},
459
+ true
460
+ )
461
+ __TS__ObjectDefineProperty(
462
+ AbilityEnumLevelField,
463
+ "valueChangeEvent",
464
+ {get = function(self)
465
+ return self:getOrCreateValueChangeEvent()
466
+ end}
467
+ )
468
+ ____exports.AbilityBuffPolarityLevelField = __TS__Class()
469
+ local AbilityBuffPolarityLevelField = ____exports.AbilityBuffPolarityLevelField
470
+ AbilityBuffPolarityLevelField.name = "AbilityBuffPolarityLevelField"
471
+ __TS__ClassExtends(AbilityBuffPolarityLevelField, ____exports.AbilityEnumLevelField)
472
+ function AbilityBuffPolarityLevelField.prototype.____constructor(self, ...)
473
+ AbilityBuffPolarityLevelField.____super.prototype.____constructor(self, ...)
474
+ self.values = nonEmptyLinkedSetOf(0, 1, 2)
475
+ end
476
+ ____exports.AbilityBuffResistanceTypeLevelField = __TS__Class()
477
+ local AbilityBuffResistanceTypeLevelField = ____exports.AbilityBuffResistanceTypeLevelField
478
+ AbilityBuffResistanceTypeLevelField.name = "AbilityBuffResistanceTypeLevelField"
479
+ __TS__ClassExtends(AbilityBuffResistanceTypeLevelField, ____exports.AbilityEnumLevelField)
480
+ function AbilityBuffResistanceTypeLevelField.prototype.____constructor(self, ...)
481
+ AbilityBuffResistanceTypeLevelField.____super.prototype.____constructor(self, ...)
482
+ self.values = nonEmptyLinkedSetOf(1, 2, 3)
483
+ end
434
484
  local allowedTargetCombatClassificationsByLevelByAbilityTypeId = postcompile(function()
435
485
  local allowedTargetCombatClassificationsByLevelByAbilityTypeId = {}
436
486
  for ____, abilityType in ipairs(AbilityType:getAll()) do
package/net/socket.d.ts CHANGED
@@ -1,9 +1,15 @@
1
1
  /** @noSelfInFile */
2
2
  import { Event } from "../event";
3
3
  import { Player } from "../core/types/player";
4
+ declare const enum SocketPropertyKey {
5
+ ID = 0,
6
+ CHUNK_ID = 1
7
+ }
4
8
  export declare class Socket {
5
- private readonly id;
9
+ private readonly [SocketPropertyKey.ID];
10
+ private readonly [SocketPropertyKey.CHUNK_ID];
6
11
  readonly onMessage: Event<[Player, string]>;
7
12
  constructor();
8
13
  send(data: string): void;
9
14
  }
15
+ export {};
package/net/socket.lua CHANGED
@@ -1,12 +1,16 @@
1
1
  local ____lualib = require("lualib_bundle")
2
2
  local __TS__Class = ____lualib.__TS__Class
3
3
  local __TS__New = ____lualib.__TS__New
4
+ local __TS__StringSubstring = ____lualib.__TS__StringSubstring
4
5
  local ____exports = {}
5
6
  local ____event = require("event")
6
7
  local Event = ____event.Event
7
8
  local ____network = require("network")
8
9
  local send = ____network.send
9
10
  local onReceive = ____network.onReceive
11
+ local MAX_PAYLOAD_LENGTH = ____network.MAX_PAYLOAD_LENGTH
12
+ local ____math = require("math")
13
+ local ceil = ____math.ceil
10
14
  local nextId = 0
11
15
  ____exports.Socket = __TS__Class()
12
16
  local Socket = ____exports.Socket
@@ -14,13 +18,49 @@ Socket.name = "Socket"
14
18
  function Socket.prototype.____constructor(self)
15
19
  local ____tostring_0 = tostring
16
20
  nextId = nextId + 1
17
- self.id = ____tostring_0(nextId)
21
+ self[0] = ____tostring_0(nextId)
22
+ local ____tostring_1 = tostring
23
+ nextId = nextId + 1
24
+ self[1] = ____tostring_1(nextId)
18
25
  self.onMessage = __TS__New(Event)
19
- onReceive[self.id]:addListener(function(sender, data)
20
- Event.invoke(self.onMessage, sender, data)
26
+ local chunksByPlayer = {}
27
+ onReceive[self[0]]:addListener(function(sender, data)
28
+ local chunks = chunksByPlayer[sender]
29
+ if chunks ~= nil then
30
+ chunks[#chunks + 1] = data
31
+ Event.invoke(
32
+ self.onMessage,
33
+ sender,
34
+ table.concat(chunks, ",")
35
+ )
36
+ chunksByPlayer[sender] = nil
37
+ else
38
+ Event.invoke(self.onMessage, sender, data)
39
+ end
40
+ end)
41
+ onReceive[self[1]]:addListener(function(sender, data)
42
+ local chunks = chunksByPlayer[sender]
43
+ if chunks == nil then
44
+ chunks = {}
45
+ chunksByPlayer[sender] = chunks
46
+ end
47
+ chunks[#chunks + 1] = data
21
48
  end)
22
49
  end
23
50
  function Socket.prototype.send(self, data)
24
- send(self.id, data)
51
+ local chunks = ceil(#data / MAX_PAYLOAD_LENGTH) - 1
52
+ local offset = 0
53
+ for _ = 0, chunks - 1 do
54
+ local nextOffset = offset + MAX_PAYLOAD_LENGTH
55
+ send(
56
+ self[1],
57
+ __TS__StringSubstring(data, offset, nextOffset)
58
+ )
59
+ offset = nextOffset
60
+ end
61
+ send(
62
+ self[0],
63
+ __TS__StringSubstring(data, offset)
64
+ )
25
65
  end
26
66
  return ____exports
package/network.d.ts CHANGED
@@ -2,6 +2,7 @@
2
2
  import { Event } from "./event";
3
3
  import { Player } from "./core/types/player";
4
4
  import { Operation, OperationContinue, OperationMonitor } from "./operation";
5
+ export declare const MAX_PAYLOAD_LENGTH = 255;
5
6
  export declare const onReceive: {
6
7
  [prefix: string]: Event<[Player, string]>;
7
8
  } & {
package/network.lua CHANGED
@@ -25,6 +25,7 @@ local concat = table.concat
25
25
  local pack = string.pack
26
26
  local sub = string.sub
27
27
  local ____unpack = string.unpack
28
+ ____exports.MAX_PAYLOAD_LENGTH = 255
28
29
  ____exports.onReceive = setmetatable(
29
30
  {},
30
31
  {__index = function(self, prefix)
@@ -42,11 +43,11 @@ ____exports.onReceive = setmetatable(
42
43
  end}
43
44
  )
44
45
  function ____exports.send(id, payload)
45
- if #payload > 255 then
46
+ if #payload > ____exports.MAX_PAYLOAD_LENGTH then
46
47
  error(
47
48
  __TS__New(
48
49
  IllegalArgumentException,
49
- "payload length must be <= 256, but was " .. tostring(#payload)
50
+ (("payload length must be <= " .. tostring(____exports.MAX_PAYLOAD_LENGTH)) .. ", but was ") .. tostring(#payload)
50
51
  ),
51
52
  0
52
53
  )
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "warscript",
4
- "version": "0.0.1-dev.008d8ef",
4
+ "version": "0.0.1-dev.062a781",
5
5
  "description": "A typescript library for Warcraft III using Warpack.",
6
6
  "keywords": [
7
7
  "warcraft",
@@ -24,7 +24,7 @@
24
24
  "@warscript/language-extensions": "^0.0.1",
25
25
  "@warscript/tstl-plugin": "^0.0.4",
26
26
  "lua-types": "^2.13.1",
27
- "warpack": "0.0.1-dev.2c4e71e"
27
+ "warpack": "0.0.1-dev.880fc91"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@typescript-eslint/eslint-plugin": "^8.13.0",
@@ -1,4 +1,5 @@
1
1
  /** @noSelfInFile */
2
+ import { NonEmptyArray, ReadonlyNonEmptyArray } from "./types";
2
3
  type IteratorState<T extends AnyNotNil> = {
3
4
  t: LuaMap<T, T>;
4
5
  n?: T;
@@ -18,6 +19,11 @@ export interface ReadonlyLinkedSet<T extends AnyNotNil> extends LuaPairsKeyItera
18
19
  toArray(): T[];
19
20
  sumOf(selector: ((value: T) => number) | KeysOfType<T, number>): number;
20
21
  }
22
+ export interface ReadonlyNonEmptyLinkedSet<T extends AnyNotNil> extends ReadonlyLinkedSet<T> {
23
+ first(): T;
24
+ last(): T;
25
+ toArray(): NonEmptyArray<T>;
26
+ }
21
27
  export interface LinkedSet<T extends AnyNotNil> extends LuaPairsKeyIterable<T> {
22
28
  readonly __linkedSet: unique symbol;
23
29
  }
@@ -44,6 +50,9 @@ export declare class LinkedSet<T extends AnyNotNil> implements ReadonlyLinkedSet
44
50
  protected __pairs(this: LinkedSet<T>): LuaIterator<T | undefined, IteratorState<T>>;
45
51
  }
46
52
  export declare const emptyLinkedSet: <T extends AnyNotNil>() => ReadonlyLinkedSet<T>;
47
- export declare const linkedSetOf: <T extends AnyNotNil>(...elements: readonly T[]) => LinkedSet<T>;
48
- export declare const linkedSetOfNotNull: <T extends AnyNotNil>(...elements: readonly (T | undefined | null)[]) => LinkedSet<T>;
53
+ export declare const mutableLinkedSetOf: <T extends AnyNotNil>(...elements: ReadonlyArray<T>) => LinkedSet<T>;
54
+ export declare const mutableLinkedSetOfNotNull: <T extends AnyNotNil>(...elements: readonly (T | undefined | null)[]) => LinkedSet<T>;
55
+ export declare const linkedSetOf: <T extends AnyNotNil>(...elements: ReadonlyArray<T>) => ReadonlyLinkedSet<T>;
56
+ export declare const linkedSetOfNotNull: <T extends AnyNotNil>(...elements: ReadonlyArray<T>) => ReadonlyLinkedSet<T>;
57
+ export declare const nonEmptyLinkedSetOf: <T extends AnyNotNil>(...elements: ReadonlyNonEmptyArray<T>) => ReadonlyNonEmptyLinkedSet<T>;
49
58
  export {};
@@ -177,14 +177,14 @@ local EMPTY_LINKED_SET = __TS__New(EmptyLinkedSet)
177
177
  ____exports.emptyLinkedSet = function()
178
178
  return EMPTY_LINKED_SET
179
179
  end
180
- ____exports.linkedSetOf = function(...)
180
+ ____exports.mutableLinkedSetOf = function(...)
181
181
  local linkedSet = __TS__New(____exports.LinkedSet)
182
182
  for i = 1, select("#", ...) do
183
183
  linkedSet:add((select(i, ...)))
184
184
  end
185
185
  return linkedSet
186
186
  end
187
- ____exports.linkedSetOfNotNull = function(...)
187
+ ____exports.mutableLinkedSetOfNotNull = function(...)
188
188
  local linkedSet = __TS__New(____exports.LinkedSet)
189
189
  for i = 1, select("#", ...) do
190
190
  local element = (select(i, ...))
@@ -194,4 +194,7 @@ ____exports.linkedSetOfNotNull = function(...)
194
194
  end
195
195
  return linkedSet
196
196
  end
197
+ ____exports.linkedSetOf = function(...) return ____exports.mutableLinkedSetOf(...) end
198
+ ____exports.linkedSetOfNotNull = function(...) return ____exports.mutableLinkedSetOfNotNull(...) end
199
+ ____exports.nonEmptyLinkedSetOf = function(...) return ____exports.linkedSetOf(...) end
197
200
  return ____exports
@@ -2,6 +2,7 @@
2
2
  export type AnyNonNullable = {};
3
3
  export type IsExactlyAny<T> = boolean extends (T extends never ? true : false) ? true : false;
4
4
  export type NonEmptyArray<T> = [T, ...T[]];
5
+ export type ReadonlyNonEmptyArray<T> = readonly [T, ...T[]];
5
6
  export type InvertRecordType<T extends Record<PropertyKey, PropertyKey | null | undefined>> = {
6
7
  [P in keyof T as NonNullable<T[P]>]: P;
7
8
  };