warscript 0.0.1-dev.6f480d0 → 0.0.1-dev.a45bc10

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.
@@ -3,14 +3,13 @@ import { AbilityBehavior } from "../ability";
3
3
  import { Ability } from "../../internal/ability";
4
4
  import { UnitBehavior } from "../unit";
5
5
  import { Unit } from "../../internal/unit";
6
- import { MutableKeys } from "../../../utility/types";
7
6
  import { AbilityDependentValue } from "../../object-field/ability";
8
7
  export declare class ApplyUnitBehaviorAbilityBehavior<T extends UnitBehavior> extends AbilityBehavior {
9
8
  private readonly unitBehaviorConstructor;
10
9
  private readonly parameters?;
11
10
  private readonly keys?;
12
11
  private unitBehavior?;
13
- constructor(ability: Ability, unitBehaviorConstructor: new (unit: Unit) => T, parameters?: Partial<{ [K in MutableKeys<T> & KeysOfType<T, string | number | boolean>]: T[K] extends string | number | boolean ? AbilityDependentValue<T[K]> : never; }> | undefined);
12
+ constructor(ability: Ability, unitBehaviorConstructor: new (unit: Unit) => T, parameters?: Partial<{ [K in keyof T & { [P in keyof T]-?: (<T_1>() => T_1 extends { [Q in P]: T[P]; } ? 1 : 2) extends <T_2>() => T_2 extends { -readonly [Q_1 in P]: T[P]; } ? 1 : 2 ? P : never; }[keyof T] & KeysOfType<T, string | number | boolean>]: T[K] extends string | number | boolean ? AbilityDependentValue<T[K]> : never; }> | undefined);
14
13
  update(): void;
15
14
  onUnitGainAbility(unit: Unit): void;
16
15
  onUnitLoseAbility(): void;
@@ -1,4 +1,2 @@
1
1
  /** @noSelfInFile */
2
- import { Ability } from "../ability";
3
- import { Unit } from "../unit";
4
- export declare const getAbilityDuration: (ability: Ability, target?: Unit) => number;
2
+ export {};
@@ -4,6 +4,8 @@ local UnitClassification = ____unit.UnitClassification
4
4
  local ____ability = require("engine.standard.fields.ability")
5
5
  local DURATION_HERO_ABILITY_FLOAT_LEVEL_FIELD = ____ability.DURATION_HERO_ABILITY_FLOAT_LEVEL_FIELD
6
6
  local DURATION_NORMAL_ABILITY_FLOAT_LEVEL_FIELD = ____ability.DURATION_NORMAL_ABILITY_FLOAT_LEVEL_FIELD
7
+ ---
8
+ -- @internal For use by internal systems only.
7
9
  ____exports.getAbilityDuration = function(ability, target)
8
10
  local level = ability.level
9
11
  return target ~= nil and target:hasClassification(UnitClassification.RESISTANT) and DURATION_HERO_ABILITY_FLOAT_LEVEL_FIELD:getValue(ability, level) or DURATION_NORMAL_ABILITY_FLOAT_LEVEL_FIELD:getValue(ability, level)
@@ -0,0 +1,2 @@
1
+ /** @noSelfInFile */
2
+ export {};
@@ -0,0 +1,86 @@
1
+ local ____exports = {}
2
+ local ____ability_2Dtype = require("engine.object-data.entry.ability-type")
3
+ local AbilityType = ____ability_2Dtype.AbilityType
4
+ local ____dummy_2Ditem = require("engine.internal.object-data.dummy-item")
5
+ local DUMMY_ITEM_ID = ____dummy_2Ditem.DUMMY_ITEM_ID
6
+ local ____dummy_2Dunits = require("engine.internal.misc.dummy-units")
7
+ local INVENTORY_DUMMY_NATIVE_UNIT = ____dummy_2Dunits.INVENTORY_DUMMY_NATIVE_UNIT
8
+ local ____preconditions = require("utility.preconditions")
9
+ local checkNotNull = ____preconditions.checkNotNull
10
+ local ____dummy_2Dinventory = require("engine.internal.object-data.dummy-inventory")
11
+ local INVENTORY_ABILITY_TYPE_ID = ____dummy_2Dinventory.INVENTORY_ABILITY_TYPE_ID
12
+ local ____arrays = require("utility.arrays")
13
+ local map = ____arrays.map
14
+ local toLuaSet = ____arrays.toLuaSet
15
+ local createItem = CreateItem
16
+ local getAbilityId = BlzGetAbilityId
17
+ local getItemAbility = BlzGetItemAbility
18
+ local getUnitAbilityByIndex = BlzGetUnitAbilityByIndex
19
+ local itemAddAbility = BlzItemAddAbility
20
+ local setItemBooleanField = BlzSetItemBooleanField
21
+ local removeItem = RemoveItem
22
+ local unitAddAbility = UnitAddAbility
23
+ local unitAddItem = UnitAddItem
24
+ local unitDropItemSlot = UnitDropItemSlot
25
+ local unitInventorySize = UnitInventorySize
26
+ local unitRemoveAbility = UnitRemoveAbility
27
+ local unitRemoveItemFromSlot = UnitRemoveItemFromSlot
28
+ local INVENTORY_ABILITY_TYPE_IDS = postcompile(function()
29
+ return toLuaSet(AbilityType:getAllIdsByBaseIds(map({
30
+ "AInv",
31
+ "Aihn",
32
+ "Aien",
33
+ "Aion",
34
+ "Aiun"
35
+ }, fourCC)))
36
+ end)
37
+ ---
38
+ -- @internal For use by internal systems only.
39
+ ____exports.castAbility = function(nativeUnit, abilityTypeId, prepareAbility, ...)
40
+ local nativeItem = createItem(DUMMY_ITEM_ID, 0, 0)
41
+ unitAddItem(INVENTORY_DUMMY_NATIVE_UNIT, nativeItem)
42
+ itemAddAbility(nativeItem, abilityTypeId)
43
+ local nativeAbility = checkNotNull(getItemAbility(nativeItem, abilityTypeId))
44
+ if prepareAbility ~= nil then
45
+ prepareAbility(nativeAbility, ...)
46
+ end
47
+ setItemBooleanField(nativeItem, ITEM_BF_ACTIVELY_USED, true)
48
+ setItemBooleanField(nativeItem, ITEM_BF_USE_AUTOMATICALLY_WHEN_ACQUIRED, true)
49
+ local success
50
+ if unitAddItem(nativeUnit, nativeItem) then
51
+ success = true
52
+ else
53
+ local latestInventoryAbilityTypeId = 0
54
+ local nativeItemBySlot = {}
55
+ local inventorySize = unitInventorySize(nativeUnit)
56
+ if inventorySize ~= 0 then
57
+ for slot = 0, inventorySize - 1 do
58
+ nativeItemBySlot[slot] = unitRemoveItemFromSlot(nativeUnit, slot)
59
+ end
60
+ local unitNativeAbility = getUnitAbilityByIndex(nativeUnit, 0)
61
+ local i = 1
62
+ while unitNativeAbility ~= nil do
63
+ local abilityTypeId = getAbilityId(unitNativeAbility)
64
+ if INVENTORY_ABILITY_TYPE_IDS[abilityTypeId] ~= nil then
65
+ latestInventoryAbilityTypeId = abilityTypeId
66
+ end
67
+ unitNativeAbility = getUnitAbilityByIndex(nativeUnit, i)
68
+ i = i + 1
69
+ end
70
+ unitRemoveAbility(nativeUnit, latestInventoryAbilityTypeId)
71
+ end
72
+ unitAddAbility(nativeUnit, INVENTORY_ABILITY_TYPE_ID)
73
+ success = unitAddItem(nativeUnit, nativeItem)
74
+ unitRemoveAbility(nativeUnit, INVENTORY_ABILITY_TYPE_ID)
75
+ if latestInventoryAbilityTypeId ~= 0 then
76
+ unitAddAbility(nativeUnit, latestInventoryAbilityTypeId)
77
+ for slot, nativeItem in pairs(nativeItemBySlot) do
78
+ unitAddItem(nativeUnit, nativeItem)
79
+ unitDropItemSlot(nativeUnit, nativeItem, slot)
80
+ end
81
+ end
82
+ end
83
+ removeItem(nativeItem)
84
+ return success
85
+ end
86
+ return ____exports
@@ -0,0 +1,7 @@
1
+ /** @noSelfInFile */
2
+ declare module "../unit" {
3
+ interface Unit {
4
+ detachMissiles(this: Unit): void;
5
+ }
6
+ }
7
+ export {};
@@ -0,0 +1,30 @@
1
+ local ____exports = {}
2
+ local ____unit = require("engine.internal.unit")
3
+ local Unit = ____unit.Unit
4
+ local ____cast_2Dability = require("engine.internal.mechanics.cast-ability")
5
+ local castAbility = ____cast_2Dability.castAbility
6
+ local ____blink = require("engine.object-data.entry.ability-type.blink")
7
+ local BlinkAbilityType = ____blink.BlinkAbilityType
8
+ local ____math = require("math")
9
+ local MAXIMUM_INTEGER = ____math.MAXIMUM_INTEGER
10
+ local getUnitX = GetUnitX
11
+ local getUnitY = GetUnitY
12
+ local setUnitX = SetUnitX
13
+ local setUnitY = SetUnitY
14
+ local BLINK_ABILITY_TYPE_ID = compiletime(function()
15
+ local abilityType = BlinkAbilityType:create()
16
+ abilityType.minimumRange = 0
17
+ abilityType.maximumRange = MAXIMUM_INTEGER
18
+ abilityType.manaCost = 0
19
+ abilityType.cooldown = 0
20
+ return abilityType.id
21
+ end)
22
+ Unit.prototype.detachMissiles = function(self)
23
+ local nativeUnit = self.handle
24
+ local x = getUnitX(nativeUnit)
25
+ local y = getUnitY(nativeUnit)
26
+ castAbility(nativeUnit, BLINK_ABILITY_TYPE_ID)
27
+ setUnitX(nativeUnit, x)
28
+ setUnitY(nativeUnit, y)
29
+ end
30
+ return ____exports
@@ -0,0 +1,10 @@
1
+ /** @noSelfInFile */
2
+ import { AbilityType, AbilityTypeId } from "../ability-type";
3
+ import { ObjectDataEntryLevelFieldValueSupplier } from "../../entry";
4
+ export declare class BlinkAbilityType extends AbilityType {
5
+ static readonly BASE_ID: AbilityTypeId;
6
+ get maximumRange(): number[];
7
+ set maximumRange(maximumRange: ObjectDataEntryLevelFieldValueSupplier<number>);
8
+ get minimumRange(): number[];
9
+ set minimumRange(minimumRange: ObjectDataEntryLevelFieldValueSupplier<number>);
10
+ }
@@ -0,0 +1,39 @@
1
+ local ____lualib = require("lualib_bundle")
2
+ local __TS__Class = ____lualib.__TS__Class
3
+ local __TS__ClassExtends = ____lualib.__TS__ClassExtends
4
+ local __TS__SetDescriptor = ____lualib.__TS__SetDescriptor
5
+ local ____exports = {}
6
+ local ____ability_2Dtype = require("engine.object-data.entry.ability-type")
7
+ local AbilityType = ____ability_2Dtype.AbilityType
8
+ ____exports.BlinkAbilityType = __TS__Class()
9
+ local BlinkAbilityType = ____exports.BlinkAbilityType
10
+ BlinkAbilityType.name = "BlinkAbilityType"
11
+ __TS__ClassExtends(BlinkAbilityType, AbilityType)
12
+ BlinkAbilityType.BASE_ID = fourCC("AEbl")
13
+ __TS__SetDescriptor(
14
+ BlinkAbilityType.prototype,
15
+ "maximumRange",
16
+ {
17
+ get = function(self)
18
+ return self:getNumberLevelField("Ebl1")
19
+ end,
20
+ set = function(self, maximumRange)
21
+ self:setNumberLevelField("Ebl1", maximumRange)
22
+ end
23
+ },
24
+ true
25
+ )
26
+ __TS__SetDescriptor(
27
+ BlinkAbilityType.prototype,
28
+ "minimumRange",
29
+ {
30
+ get = function(self)
31
+ return self:getNumberLevelField("Ebl2")
32
+ end,
33
+ set = function(self, minimumRange)
34
+ self:setNumberLevelField("Ebl2", minimumRange)
35
+ end
36
+ },
37
+ true
38
+ )
39
+ return ____exports
@@ -7,6 +7,7 @@ local __TS__SparseArrayNew = ____lualib.__TS__SparseArrayNew
7
7
  local __TS__SparseArrayPush = ____lualib.__TS__SparseArrayPush
8
8
  local __TS__SparseArraySpread = ____lualib.__TS__SparseArraySpread
9
9
  local ____exports = {}
10
+ local preparePhysicalPositiveApplicatorAbility
10
11
  local ____ability_2Dtype = require("engine.object-data.entry.ability-type")
11
12
  local AbilityType = ____ability_2Dtype.AbilityType
12
13
  local ____cripple = require("engine.object-data.entry.ability-type.cripple")
@@ -34,20 +35,14 @@ local ____blood_2Dlust = require("engine.object-data.entry.ability-type.blood-lu
34
35
  local BloodLustAbilityType = ____blood_2Dlust.BloodLustAbilityType
35
36
  local ____berserk = require("engine.object-data.entry.ability-type.berserk")
36
37
  local BerserkAbilityType = ____berserk.BerserkAbilityType
37
- local ____dummy_2Ditem = require("engine.internal.object-data.dummy-item")
38
- local DUMMY_ITEM_ID = ____dummy_2Ditem.DUMMY_ITEM_ID
39
- local ____dummy_2Dinventory = require("engine.internal.object-data.dummy-inventory")
40
- local INVENTORY_ABILITY_TYPE_ID = ____dummy_2Dinventory.INVENTORY_ABILITY_TYPE_ID
41
38
  local ____blank = require("engine.object-data.entry.upgrade.blank")
42
39
  local BlankUpgrade = ____blank.BlankUpgrade
43
- local ____dummy_2Dunits = require("engine.internal.misc.dummy-units")
44
- local INVENTORY_DUMMY_NATIVE_UNIT = ____dummy_2Dunits.INVENTORY_DUMMY_NATIVE_UNIT
45
- local ____preconditions = require("utility.preconditions")
46
- local checkNotNull = ____preconditions.checkNotNull
47
40
  local ____unit_2Dtype = require("engine.object-data.entry.unit-type")
48
41
  local UnitType = ____unit_2Dtype.UnitType
49
42
  local ____permanent_2Dimmolation = require("engine.object-data.entry.ability-type.permanent-immolation")
50
43
  local PermanentImmolationAbilityType = ____permanent_2Dimmolation.PermanentImmolationAbilityType
44
+ local ____cast_2Dability = require("engine.internal.mechanics.cast-ability")
45
+ local castAbility = ____cast_2Dability.castAbility
51
46
  local createItem = CreateItem
52
47
  local getAbilityId = BlzGetAbilityId
53
48
  local getItemAbility = BlzGetItemAbility
@@ -260,75 +255,25 @@ ____exports.internalApplyBuff = function(unit, applicableBuffTypeId, polarity, r
260
255
  return unitAddAbility(unit.handle, applicatorAbilityTypeId)
261
256
  end
262
257
  if applicatorType == 852100 then
263
- local success
264
- local nativeUnit = unit.handle
265
- local nativeItem = createItem(DUMMY_ITEM_ID, 0, 0)
266
- unitAddItem(INVENTORY_DUMMY_NATIVE_UNIT, nativeItem)
267
- itemAddAbility(nativeItem, applicatorAbilityTypeId)
268
- local applicatorAbility = checkNotNull(getItemAbility(nativeItem, applicatorAbilityTypeId))
269
- if level == nil then
270
- level = 0
271
- setAbilityIntegerField(applicatorAbility, ABILITY_IF_LEVELS, 1)
272
- end
273
- setAbilityRealLevelField(applicatorAbility, ABILITY_RLF_DURATION_NORMAL, level, duration or 0)
274
- setAbilityRealLevelField(applicatorAbility, ABILITY_RLF_DURATION_HERO, level, duration or 0)
275
- if movementSpeedIncreaseFactor ~= nil then
276
- setAbilityRealLevelField(applicatorAbility, ABILITY_RLF_MOVEMENT_SPEED_INCREASE_BSK1, level, movementSpeedIncreaseFactor)
277
- end
278
- setItemBooleanField(nativeItem, ITEM_BF_ACTIVELY_USED, true)
279
- setItemBooleanField(nativeItem, ITEM_BF_USE_AUTOMATICALLY_WHEN_ACQUIRED, true)
280
- if level > 0 then
258
+ local nativePlayer = unit.owner.handle
259
+ if level ~= nil and level > 0 then
281
260
  local upgradeId = applicatorUpgradeIdByApplicatorAbilityTypeId[applicatorAbilityTypeId]
282
261
  if upgradeId ~= nil then
283
- setPlayerTechResearched(
284
- getOwningPlayer(nativeUnit),
285
- upgradeId,
286
- level
287
- )
288
- end
289
- end
290
- if not unitAddItem(nativeUnit, nativeItem) then
291
- local latestInventoryAbilityTypeId = 0
292
- local nativeItemBySlot = {}
293
- local inventorySize = unitInventorySize(nativeUnit)
294
- if inventorySize ~= 0 then
295
- for slot = 0, inventorySize - 1 do
296
- nativeItemBySlot[slot] = UnitRemoveItemFromSlot(nativeUnit, slot)
297
- end
298
- local unitNativeAbility = getUnitAbilityByIndex(nativeUnit, 0)
299
- local i = 1
300
- while unitNativeAbility ~= nil do
301
- local abilityTypeId = getAbilityId(unitNativeAbility)
302
- if INVENTORY_ABILITY_TYPE_IDS[abilityTypeId] ~= nil then
303
- latestInventoryAbilityTypeId = abilityTypeId
304
- end
305
- unitNativeAbility = getUnitAbilityByIndex(nativeUnit, i)
306
- i = i + 1
307
- end
308
- unitRemoveAbility(nativeUnit, latestInventoryAbilityTypeId)
262
+ setPlayerTechResearched(nativePlayer, upgradeId, level)
309
263
  end
310
- unitAddAbility(nativeUnit, INVENTORY_ABILITY_TYPE_ID)
311
- success = unitAddItem(nativeUnit, nativeItem)
312
- unitRemoveAbility(nativeUnit, INVENTORY_ABILITY_TYPE_ID)
313
- if latestInventoryAbilityTypeId ~= 0 then
314
- unitAddAbility(nativeUnit, latestInventoryAbilityTypeId)
315
- for slot, nativeItem in pairs(nativeItemBySlot) do
316
- unitAddItem(nativeUnit, nativeItem)
317
- unitDropItemSlot(nativeUnit, nativeItem, slot)
318
- end
319
- end
320
- else
321
- success = true
322
264
  end
323
- removeItem(nativeItem)
324
- if level ~= nil and level > 1 then
265
+ local success = castAbility(
266
+ unit.handle,
267
+ applicatorAbilityTypeId,
268
+ preparePhysicalPositiveApplicatorAbility,
269
+ level,
270
+ duration or 0,
271
+ movementSpeedIncreaseFactor
272
+ )
273
+ if level ~= nil and level > 0 then
325
274
  local upgradeId = applicatorUpgradeIdByApplicatorAbilityTypeId[applicatorAbilityTypeId]
326
275
  if upgradeId ~= nil then
327
- setPlayerTechResearched(
328
- getOwningPlayer(nativeUnit),
329
- upgradeId,
330
- 0
331
- )
276
+ setPlayerTechResearched(nativePlayer, upgradeId, 0)
332
277
  end
333
278
  end
334
279
  return success
@@ -364,6 +309,17 @@ ____exports.internalApplyBuff = function(unit, applicableBuffTypeId, polarity, r
364
309
  end
365
310
  return success
366
311
  end
312
+ preparePhysicalPositiveApplicatorAbility = function(ability, level, duration, movementSpeedIncreaseFactor)
313
+ if level == nil then
314
+ setAbilityIntegerField(ability, ABILITY_IF_LEVELS, 1)
315
+ level = 1
316
+ end
317
+ setAbilityRealLevelField(ability, ABILITY_RLF_DURATION_NORMAL, level, duration)
318
+ setAbilityRealLevelField(ability, ABILITY_RLF_DURATION_HERO, level, duration)
319
+ if movementSpeedIncreaseFactor ~= nil then
320
+ setAbilityRealLevelField(ability, ABILITY_RLF_MOVEMENT_SPEED_INCREASE_BSK1, level, movementSpeedIncreaseFactor)
321
+ end
322
+ end
367
323
  ---
368
324
  -- @internal For use by internal systems only.
369
325
  ____exports.removeBuff = function(unit, applicableBuffTypeId)
package/engine/unit.d.ts CHANGED
@@ -14,6 +14,7 @@ import "./internal/unit/missile";
14
14
  import "./internal/unit-missile-launch";
15
15
  import "./internal/unit/ghost-counter";
16
16
  import "./internal/unit/invulnerability-counter";
17
+ import "./internal/unit/detach-missiles";
17
18
  import "./internal/unit/band-aids/ancestral-spirit-cannibalize";
18
19
  export { Unit, DamagingEvent, DamageEvent } from "./internal/unit";
19
20
  export * from "./internal/unit+damage";
package/engine/unit.lua CHANGED
@@ -14,6 +14,7 @@ require("engine.internal.unit.missile")
14
14
  require("engine.internal.unit-missile-launch")
15
15
  require("engine.internal.unit.ghost-counter")
16
16
  require("engine.internal.unit.invulnerability-counter")
17
+ require("engine.internal.unit.detach-missiles")
17
18
  require("engine.internal.unit.band-aids.ancestral-spirit-cannibalize")
18
19
  do
19
20
  local ____unit = require("engine.internal.unit")
package/global/vec2.lua CHANGED
@@ -15,6 +15,7 @@ local abs = math.abs
15
15
 
16
16
  local location = Location and Location(0, 0)
17
17
  local moveLocation = MoveLocation
18
+ local getLocationZ = GetLocationZ
18
19
 
19
20
  local vec2 = {}
20
21
 
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.6f480d0",
4
+ "version": "0.0.1-dev.a45bc10",
5
5
  "description": "A typescript library for Warcraft III using Warpack.",
6
6
  "keywords": [
7
7
  "warcraft",
@@ -12,14 +12,14 @@ export type ValueOf<T> = T[keyof T];
12
12
  export type EntryOf<T> = ValueOf<{
13
13
  [K in keyof T]: [K, T[K]];
14
14
  }>;
15
- export type MutableKeys<T extends object> = {
15
+ export type MutableKeys<T extends object> = keyof T & {
16
16
  [P in keyof T]-?: IfEquals<{
17
17
  [Q in P]: T[P];
18
18
  }, {
19
19
  -readonly [Q in P]: T[P];
20
20
  }, P>;
21
21
  }[keyof T];
22
- export type ReadonlyKeys<T extends object> = {
22
+ export type ReadonlyKeys<T extends object> = keyof T & {
23
23
  [P in keyof T]-?: IfEquals<{
24
24
  [Q in P]: T[P];
25
25
  }, {