@zerospacegg/iolin
Version:
Pure TypeScript implementation of ZeroSpace game data processing (PKL-free)
310 lines • 11.1 kB
TypeScript
/**
* Transformation Engine - Adapted from black-hole for iolin entity system
* Clean, idiomatic TypeScript transformation system for ZeroSpace entities
*/
import type { Ability, Upgrade as AbilityUpgrade, Attack, FactionTalent, Heal, Spell, Topbar } from "./ability.js";
import type { BaseBuilding, Building, ConstructingFormBuilding, ExtractorBuilding, MercenaryOutpostBuilding, ProductionBuilding, SpecialBuilding, SupplyBuilding, TechBuilding, UltimateBuilding } from "./building.js";
import type { Faction, MainFaction, MercFaction, NonPlayerFaction } from "./faction.js";
import type { Map, Map1p, Map1v1, Map2v2, MapFFA } from "./map.js";
import type { ArmyUnit, BuilderUnit, CoopCommanderUnit, HarvesterUnit, HeroUnit, MercTopbarUnit, MercUnit, MobileMercOutpostUnit, SpecialUnit, UltimateUnit, Unit } from "./unit.js";
/**
* Union type of all concrete entity types for polymorphic transformations
* Transformations can take any entity type and return any entity type
*/
export type AnyEntity = Unit | ArmyUnit | BuilderUnit | HarvesterUnit | HeroUnit | CoopCommanderUnit | SpecialUnit | UltimateUnit | MercUnit | MercTopbarUnit | MobileMercOutpostUnit | Building | BaseBuilding | ExtractorBuilding | SupplyBuilding | ProductionBuilding | TechBuilding | SpecialBuilding | ConstructingFormBuilding | MercenaryOutpostBuilding | UltimateBuilding | Map | Map1v1 | Map2v2 | MapFFA | Map1p | Ability | Attack | Heal | Spell | AbilityUpgrade | FactionTalent | Topbar | Faction | MainFaction | MercFaction | NonPlayerFaction;
/**
* Base transformation interface - all transformations implement this
*/
export interface Transformation {
/** Unique identifier for this transformation type */
type: string;
/** Human-readable name for display */
name: string;
/** Whether this transformation can stack multiple times */
canStack?: boolean;
/** Maximum number of times this transformation can be applied (0 = unlimited) */
maxStacks?: number;
/** Tags that must be present on the entity for this transformation to apply */
requiredTags?: string[];
/** Tags that prevent this transformation from being applied */
excludedTags?: string[];
/** Conditions that must be met (e.g., "on-biomass", "on-kill") */
conditions?: string[];
}
/**
* Stat transformation - modifies numeric entity properties
*/
export interface StatTransformation extends Transformation {
type: "stat";
hpMultiplier?: number;
hpAddition?: number;
hpOverride?: number;
damageMultiplier?: number;
damageAddition?: number;
damageOverride?: number;
speedMultiplier?: number;
speedAddition?: number;
speedOverride?: number;
attackSpeedMultiplier?: number;
attackSpeedAddition?: number;
attackSpeedOverride?: number;
armorMultiplier?: number;
armorAddition?: number;
armorOverride?: number;
shieldsMultiplier?: number;
shieldsAddition?: number;
shieldsOverride?: number;
visionMultiplier?: number;
visionAddition?: number;
visionOverride?: number;
rangeMultiplier?: number;
rangeAddition?: number;
rangeOverride?: number;
cooldownMultiplier?: number;
cooldownAddition?: number;
cooldownOverride?: number;
energyMultiplier?: number;
energyAddition?: number;
energyOverride?: number;
appliesTo?: "self" | "target" | "area";
effectDuration?: number;
affectedAbilities?: string[];
appliesStatus?: string[];
armorBonus?: number;
hpBonus?: number;
shieldsBonus?: number;
supplyBonus?: number;
visionRange?: number;
}
/**
* Tag transformation - adds or removes tags from entities
*/
export interface TagTransformation extends Transformation {
type: "tag";
/** Tags to add to the entity */
addTags?: string[];
/** Tags to remove from the entity */
removeTags?: string[];
}
/**
* Ability transformation - modifies or adds abilities
*/
export interface AbilityTransformation extends Transformation {
type: "ability";
/** New abilities to add */
addAbilities?: Record<string, any>;
/** Existing abilities to modify */
modifyAbilities?: Record<string, AbilityModification>;
/** Abilities to remove */
removeAbilities?: string[];
/** Passive effects for abilities */
passiveEffect?: Record<string, any>;
/** Which companion this ability affects */
affectsCompanion?: string;
}
/**
* Ability modification specification
*/
export interface AbilityModification {
damageMultiplier?: number;
damageAddition?: number;
damageOverride?: number;
rangeMultiplier?: number;
rangeAddition?: number;
rangeOverride?: number;
cooldownMultiplier?: number;
cooldownAddition?: number;
cooldownOverride?: number;
energyCostMultiplier?: number;
energyCostAddition?: number;
energyCostOverride?: number;
addTargets?: string[];
removeTargets?: string[];
appliesStatus?: string[];
appliesStatusTo?: "self" | "target" | "area";
unlocked?: boolean;
areaEffect?: boolean;
radius?: number;
charges?: number;
explosionDamage?: number;
explosionRadius?: number;
healRadius?: number;
lightningTargets?: number;
maxStacks?: number;
projectileSpeedMultiplier?: number;
areaMultiplier?: number;
damageBonus?: number;
rangeBonus?: number;
onHit?: {
effect?: string;
value?: number;
duration?: number;
attackSpeedBonus?: number;
movementSpeedBonus?: number;
affectsSelf?: boolean;
affectsCompanion?: boolean;
damageBonus?: number;
healAmount?: number;
shieldAmount?: number;
};
affectsAllies?: boolean;
bonusMultiplier?: number;
bonusVsAir?: number;
channelTime?: number;
groundFire?: boolean;
healRate?: number;
volleysBonus?: number;
fireDuration?: number;
}
/**
* Custom transformation - for complex logic
*/
export interface CustomTransformation extends Transformation {
type: "custom";
/** Custom transformation function */
apply: (entity: any) => any;
}
/**
* Union type of all transformation types
*/
export type AnyTransformation = StatTransformation | TagTransformation | AbilityTransformation | CustomTransformation;
/**
* Upgrade definition - research upgrades that apply transformations
*/
export interface Upgrade {
/** Unique slug for this upgrade */
slug?: string;
/** Display name */
name: string;
/** Description of what this upgrade does */
description: string;
/** Tier (e.g., "T1.5", "T2.5", "T3.5") */
tier: string;
/** Flux cost to research */
fluxCost: number;
/** Time to research in seconds */
researchTime: number;
/** Transformations to apply when researched */
transformations: AnyTransformation[];
/** Prerequisites (other upgrades that must be researched first) */
prerequisites?: string[];
/** Buildings required to research this upgrade */
requiredBuildings?: string[];
}
/**
* Transformable entity interface - simple interface for transformation support
*/
export interface TransformableEntity {
/** Current transformation stacks */
transformationStacks?: Record<string, number>;
/** Applied tag transformations */
appliedTagTransformations?: TagTransformation[];
/** Entity-specific transformation overrides */
transformationOverrides?: Record<string, TransformationOverride>;
}
/**
* Transformation override for entity-specific behavior
*/
export interface TransformationOverride {
transformationType: string;
name?: string;
description?: string;
statOverrides?: StatOverrides;
stackableOverride?: boolean;
maxStacksOverride?: number;
notes?: string;
}
/**
* Stat overrides for transformation overrides
*/
export interface StatOverrides {
hp?: number;
damage?: number;
speed?: number;
cooldown?: number;
armor?: number;
energy?: number;
domain?: "air" | "ground";
}
/**
* Transformation result - what happens when transformations are applied
*/
export interface TransformationResult {
/** The transformed entity - can be different type than input */
transformedEntity: any;
/** List of transformations that were successfully applied */
appliedTransformations: AnyTransformation[];
/** List of transformations that were skipped (conditions not met) */
skippedTransformations: AnyTransformation[];
/** Any errors that occurred during transformation */
errors?: string[];
}
/**
* Transformation Engine - applies transformations to entities
*/
export declare class TransformationEngine {
/**
* Apply a list of transformations to an entity
* Can convert entity types through polymorphic transformations
*/
static applyTransformations(entity: any, transformations: AnyTransformation[]): TransformationResult;
/**
* Check if a transformation can be applied to an entity
*/
private static canApplyTransformation;
/**
* Apply a single transformation to an entity
* Can return different entity type for polymorphic transformations
*/
private static applyTransformation;
/**
* Apply stat transformation
*/
private static applyStatTransformation;
/**
* Apply tag transformation
*/
private static applyTagTransformation;
/**
* Apply ability transformation
*/
private static applyAbilityTransformation;
/**
* Apply ability modification
*/
private static applyAbilityModification;
/**
* Get current number of stacks for a transformation type
*/
static getCurrentTransformationStacks(entity: any, transformationType: string): number;
/**
* Check if entity has specific transformation applied
*/
static hasTransformation(entity: any, transformationType: string): boolean;
/**
* Get all active transformations on an entity
*/
static getActiveTransformations(entity: any): Record<string, number>;
}
/**
* Helper function to create stat transformations easily
*/
export declare function createStatTransformation(name: string, modifications: Partial<StatTransformation>): StatTransformation;
/**
* Helper function to create tag transformations easily
*/
export declare function createTagTransformation(name: string, addTags?: string[], removeTags?: string[]): TagTransformation;
/**
* Helper function to create ability transformations easily
*/
export declare function createAbilityTransformation(name: string, modifications: Partial<AbilityTransformation>): AbilityTransformation;
/**
* Helper function to create upgrades easily
*/
export declare function createUpgrade(name: string, description: string, transformations: AnyTransformation[], tier?: string, fluxCost?: number, researchTime?: number): Upgrade;
/**
* Create special Seedling transformation override
* Seedling undergoes complete metamorphosis when infused - becomes aerial constructor
*/
export declare function createSeedlingInfuseOverride(): StatTransformation;
//# sourceMappingURL=transformation.d.ts.map