UNPKG

warscript

Version:

A typescript library for Warcraft III using Warpack.

313 lines (312 loc) 13.8 kB
/// <reference types="@typescript-to-lua/language-extensions" /> /** @noSelfInFile */ import { Handle, HandleDestructor } from "../../core/types/handle"; import { Player } from "../../core/types/player"; import { ReadonlyRect } from "../../core/types/rect"; import { Event, IgnoreEvent, InitializingEvent, TriggerEvent } from "../../event"; import { Color } from "../../core/types/color"; import { PlayerColor } from "../../core/types/playerColor"; import { Item } from "./item"; import { Destructable } from "../../core/types/destructable"; import { Ability, UnitAbility } from "./ability"; import { Widget } from "../../core/types/widget"; import type { UnitTypeId } from "../object-data/entry/unit-type"; import { CombatClassification, CombatClassifications } from "../object-data/auxiliary/combat-classification"; export type UnitClassification = junittype; export declare namespace UnitClassification { const STRUCTURE: junittype; const UNDEAD: junittype; const AIR: junittype; const GROUND: junittype; const SUMMONED: junittype; const MECHANICAL: junittype; const ANCIENT: junittype; const SUICIDAL: junittype; const TAUREN: junittype; const RESISTANT: junittype; } type UnitCollector<T extends any[]> = () => LuaMultiReturn<[Unit, ...T]> | LuaMultiReturn<[IgnoreEvent]>; export declare class UnitTriggerEvent<T extends any[] = []> extends TriggerEvent<[Unit, ...T]> { constructor(eventType: jplayerunitevent, c: UnitCollector<T>); } type DispatcherTable<T extends any[]> = { readonly [id: number]: Event<T>; }; type EventDispatcher<T extends any[], S extends any[]> = Event<T> & DispatcherTable<S>; type AbilityDispatcherTable<T extends any[] = []> = { readonly [id: number]: Event<[Unit, Ability, ...T]>; }; type AbilityEventDispatcher<T extends any[] = []> = Event<[Unit, Ability, ...T]> & AbilityDispatcherTable<T>; export interface DamagingEvent { amount: number; attackType: jattacktype; damageType: jdamagetype; weaponType: jweapontype; readonly isAttack: boolean; } export type DamageEvent = DamagingEvent & { preventDeath<P extends any[]>(this: DamageEvent, callback: (this: void, ...parameters: P) => any, ...parameters: P): void; }; export type AttackDamageEvent = DamagingEvent & { readonly isAttack: true; readonly weapon: UnitWeapon; }; export type AttackHandlerCondition = (source: Unit, target: Unit, event: Readonly<AttackDamageEvent>) => boolean; export type AttackHandlerAction = (source: Unit, target: Unit, event: AttackDamageEvent & { fire(this: void): void; }) => void; export type AttackHandler = [AttackHandlerCondition, AttackHandlerAction]; export declare const enum Operator { LESS_THAN = 0, LESS_THAN_OR_EQUAL = 1, EQUAL = 2, GREATER_THAN_OR_EQUAL = 3, GREATER_THAN = 4, NOT_EQUAL = 5 } declare const modifiers: { speed: (unit: junit, value: number) => void; armor: (unit: junit, value: number) => void; }; interface UnitWeapon { readonly index: 0 | 1; cooldown: number; projectileArc: number; projectileArt: string; projectileSpeed: number; attackPoint: number; } declare const enum UnitPropertyKey { IS_PAUSED = 100, STUN_COUNTER = 101, PREVENT_DEATH_HEALTH_BONUS = 102, IS_TEAM_GLOW_HIDDEN = 103 } export declare class Unit extends Handle<junit> { private [UnitPropertyKey.IS_PAUSED]?; private [UnitPropertyKey.STUN_COUNTER]?; private [UnitPropertyKey.PREVENT_DEATH_HEALTH_BONUS]?; private [UnitPropertyKey.IS_TEAM_GLOW_HIDDEN]?; private _owner?; private _timeScale?; private events?; private _attackHandlers?; private _eventsToDestroy?; private _fields?; private getEvent; constructor(handle: junit); protected onDestroy(): HandleDestructor; addAttackHandler(condition: AttackHandlerCondition, action: AttackHandlerAction): AttackHandler; removeAttackHandler(handler: AttackHandler): boolean; private get _deltas(); addModifier(property: keyof typeof modifiers, modifier: (value: number) => number): Destroyable; get skinId(): number; set skinId(v: number); get typeId(): UnitTypeId; get isHero(): boolean; get isAlive(): boolean; get isDead(): boolean; get isIllusion(): boolean; get combatClassifications(): CombatClassifications; set combatClassifications(combatClassifications: CombatClassifications); hasCombatClassification(combatClassification: CombatClassification): boolean; addClassification(classification: UnitClassification): boolean; removeClassification(classification: UnitClassification): boolean; hasClassification(classification: UnitClassification): boolean; isVisibleTo(player: Player): boolean; isInvisibleTo(player: Player): boolean; isInRangeOf(x: number, y: number, range: number): boolean; isInRangeOf(unit: Unit, range: number): boolean; isAllyOf(unit: Unit): boolean; isEnemyOf(unit: Unit): boolean; playAnimation(animation: string, rarity?: jraritycontrol): void; playAnimation(animation: number): void; queueAnimation(animation: string): void; get weapons(): [UnitWeapon, UnitWeapon]; get level(): number; set level(v: number); get xp(): number; set xp(v: number); get strengthBase(): number; set strengthBase(strengthBase: number); get strengthBonus(): number; get strength(): number; get agilityBase(): number; set agilityBase(agilityBase: number); get agilityBonus(): number; get agility(): number; get intelligenceBase(): number; set intelligenceBase(intelligenceBase: number); get intelligenceBonus(): number; get intelligence(): number; get name(): string; set name(v: string); get properName(): string; set properName(v: string); get isTeamGlowVisible(): boolean; set isTeamGlowVisible(isTeamGlowVisible: boolean); set color(color: PlayerColor); get acquisitionRange(): number; set acquisitionRange(v: number); get maxHealth(): number; set maxHealth(maxHealth: number); get healthRegenerationRate(): number; set healthRegenerationRate(healthRegenerationRate: number); get maxMana(): number; set maxMana(maxMana: number); get health(): number; set health(health: number); get mana(): number; set mana(mana: number); get manaRegenerationRate(): number; set manaRegenerationRate(manaRegenerationRate: number); get armor(): number; set armor(armor: number); get facing(): number; set facing(v: number); get speed(): number; set speed(v: number); get flyHeight(): number; set flyHeight(v: number); get x(): number; set x(v: number); get y(): number; set y(v: number); get z(): number; set xy(v: Vec2); setPosition(x: number, y: number): void; get position(): Vec2; set position(v: Vec2); get owner(): Player; set owner(v: Player); get goldCost(): number; get lumberCost(): number; /** The amount of gold left in the gold mine. */ get gold(): number; set gold(gold: number); get isPaused(): boolean; set isPaused(isPaused: boolean); get hidden(): boolean; set hidden(v: boolean); get isInvulnerable(): boolean; get vertexColor(): Color; set vertexColor(v: Color); get scale(): number; set scale(v: number); get timeScale(): number; set timeScale(v: number); get collisionSize(): number; get pathingCollisionRange(): number; set pathing(v: boolean); isSelected(player: Player): boolean; explode(): void; kill(): void; revive(pos: Vec2, doEffect: boolean): void; healTarget(target: Widget, amount: number): void; useItem(item: Item): boolean; issueImmediateOrder(order: number): boolean; issuePointOrder(order: number, x: number, y: number): boolean; issueTargetOrder(order: number, target: Destructable | Item | Unit): boolean; queueImmediateOrder(order: number): boolean; queuePointOrder(order: number, x: number, y: number): boolean; queueTargetOrder(order: number, target: Destructable | Item | Unit): boolean; addItem(item: Item): boolean; dropItemTarget(item: Item, target: Widget): boolean; dropItemSlot(item: Item, slot: number): boolean; itemInSlot(slot: number): Item | null; addAbility(abilityId: number): UnitAbility | null; makeAbilityPermanent(abilityId: number, permanent: true): boolean; setAbilityLevel(abilityId: number, level: number): number; getAbilityLevel(abilityId: number): number; hasAbility(abilityId: number): boolean; getAbilityById(abilityId: number): UnitAbility | undefined; removeAbility(abilityId: number): boolean; hideAbility(abilityId: number, flag: boolean): void; startAbilityCooldown(abilityId: number, cooldown: number): void; endAbilityCooldown(abilityId: number): void; interruptAttack(): void; interruptCast(abilityId: number): void; getDistanceTo(target: Unit | Vec2): number; getCollisionDistanceTo(...target: [Unit] | [targetX: number, targetY: number]): number; get buffIds(): number[]; resetCooldown(): void; incrementDisableAutoAttackCounter(): void; decrementDisableAutoAttackCounter(): void; /** @deprecated Use incrementStunCounter. */ pauseEx(): void; /** @deprecated Use decrementStunCounter. */ unpauseEx(): void; incrementStunCounter(): void; decrementStunCounter(): void; set waygateActive(v: boolean); get waygateActive(): boolean; set waygateDestination(v: Vec2); get waygateDestination(): Vec2; get abilities(): ReadonlyArray<UnitAbility>; get onUnitInRange(): Record<number, Event<[Unit]>>; get onManaEqual(): Record<number, Event<[Unit, number]>>; get manaEvent(): Record<Operator, Record<number, Event<[Unit]>>>; get onSelect(): Event; get onDeselect(): Event; get onImmediateOrder(): Event<[number]>; get onPointOrder(): Event<[number]>; get onTargetOrder(): Event<[number, Unit | Item | Destructable]>; get onSpellEffect(): Event<[number]>; static create<T extends Unit>(this: typeof Unit & (new (handle: junit) => T), owner: Player, id: number, x: number, y: number, facing: number, skinId?: number): T | null; static forAll(consumer: (unit: Unit) => any): void; static getAll(predicate?: (unit: Unit) => boolean): Unit[]; static getOwnedBy(player: Player, predicate?: (unit: Unit) => boolean): Unit[]; static getInRect(rect: ReadonlyRect, predicate?: (unit: Unit) => boolean): Unit[]; static getInRange(x: number, y: number, range: number, predicate?: (unit: Unit) => boolean): Unit[]; static getInCollisionRange(x: number, y: number, range: number, predicate?: (unit: Unit) => boolean): Unit[]; static getInSector(pos: Vec2, range: number, offsetAngle: number, centralAngle: number): Unit[]; static getSelectionOf(player: Player): Unit[]; static readonly deathEvent: UnitTriggerEvent<[Unit]>; static readonly onDecay: UnitTriggerEvent<[]>; static readonly onResurrect: InitializingEvent<[Unit], void>; static readonly morphEvent: InitializingEvent<[Unit], void>; static readonly onOwnerChange: UnitTriggerEvent<[Player]>; static readonly onSelect: UnitTriggerEvent<[Player]>; static readonly onDeselect: UnitTriggerEvent<[Player]>; static readonly constructionStartEvent: UnitTriggerEvent<[]>; static readonly onUpgradeFinish: UnitTriggerEvent<[]>; static readonly onSpellEffect: EventDispatcher<[Unit, number], [Unit]>; static readonly onTargetCast: EventDispatcher<[Unit, number, Item | Unit | Destructable], [Unit, Item | Unit | Destructable]>; static readonly onCastPrepare: AbilityEventDispatcher<[]>; static readonly onCast: AbilityEventDispatcher<[]>; static readonly onPointCastPrepare: AbilityEventDispatcher<[number, number]>; static readonly onUnitTargetCastPrepare: AbilityEventDispatcher<[Unit]>; static readonly onUnitTargetCast: AbilityEventDispatcher<[Unit]>; static readonly onPointCast: AbilityEventDispatcher<[number, number]>; static readonly onCastStart: AbilityEventDispatcher<[]>; static readonly onUnitTargetCastStart: AbilityEventDispatcher<[Unit]>; static readonly onCastFinish: AbilityEventDispatcher<[]>; static readonly onCastStop: AbilityEventDispatcher<[]>; static readonly onImmediateOrder: EventDispatcher<[Unit, number], [Unit]>; static readonly onTargetOrder: EventDispatcher<[ Unit, number, Unit | Destructable | Item ], [ Unit, Unit | Destructable | Item ]>; static readonly onPointOrder: EventDispatcher<[Unit, number, number, number], [Unit, number, number]>; static readonly autoAttackStartEvent: UnitTriggerEvent<[Unit]>; static readonly onDamaging: Event<[source: Unit | undefined, target: Unit, event: DamagingEvent]>; static readonly onDamage: InitializingEvent<[source: Unit | undefined, target: Unit, event: DamageEvent], jtrigger>; static onItemDrop: UnitTriggerEvent<[Item]>; static onItemPickup: UnitTriggerEvent<[Item]>; static onItemUse: UnitTriggerEvent<[Item]>; static get onCreate(): EventDispatcher<[Unit], [Unit]>; static get destroyEvent(): EventDispatcher<[Unit], [Unit]>; getField(field: junitintegerfield | junitrealfield): number; getField(field: junitbooleanfield): boolean; getField(field: junitstringfield): string; setField(field: junitintegerfield, value: number): boolean; setField(field: junitrealfield, value: number): boolean; setField(field: junitbooleanfield, value: boolean): boolean; setField(field: junitstringfield, value: string): boolean; toString(): string; } export {};