@zerospacegg/iolin
Version:
Pure TypeScript implementation of ZeroSpace game data processing (PKL-free)
221 lines • 6.15 kB
JavaScript
/**
* Building - Base building class with type hierarchy and constructing-form support
* Extended from Entity with building-specific properties and construction mechanics
*/
import { Entity } from "./entity.js";
/**
* Base Building class for all structures
* Usage: new Building("Name", (building) => { building.buildingType = "production"; }, import.meta.filename)
*/
export class Building extends Entity {
constructor() {
super(...arguments);
// Economic properties
this.providesBiomass = undefined;
this.gathersFlux = undefined;
this.gathersRichFlux = undefined;
// Building capabilities
this.creates = undefined; // Building slugs this building can create
this.unlocks = undefined; // Building/unit slugs this building unlocks
// Building-specific defaults
this.armorType = "building";
// Static defaults - overridable for flexibility
this.speed = 0; // Most buildings don't move, but some can fly or be mobile!
this.vision = 1500; // Can be upgraded
this.armor = 1; // Can be upgraded
}
get type() {
return "building";
}
// Starting HP during construction - calculated as 40% of HP (PKL formula)
get hpInitial() {
return this.hp ? Math.floor(this.hp * 0.4) : undefined;
}
// Building defaults
get subtype() {
return this.buildingType;
}
toJSON() {
return {
...super.toJSON(),
buildingType: this.buildingType,
buildTime: this.buildTime,
hpInitial: this.hpInitial,
providesBiomass: this.providesBiomass,
gathersFlux: this.gathersFlux,
gathersRichFlux: this.gathersRichFlux,
creates: this.creates,
unlocks: this.unlocks,
produces: this.produces,
};
}
}
/**
* Base Building - Main faction base/headquarters
* Usage: new BaseBuilding("Root Colony", (base) => { base.tier = "T1"; })
*/
export class BaseBuilding extends Building {
constructor() {
super();
}
get buildingType() {
return "base";
}
get subtype() {
return "base";
}
}
/**
* Extractor Building - Resource gathering structures
* Universal base class for all faction extractors with common defaults
*/
export class ExtractorBuilding extends Building {
constructor() {
super();
// Universal extractor defaults (same across all factions)
this.tier = "T0";
this.buildTime = 35;
this.buildCount = 1;
this.gathersHexite = 1.4;
this.gathersEmptyHexite = 0.35;
// Universal extractor stats (Patch 19202990: +25 HP, armor type light→building)
this.hp = 250;
this.armor = 0; // Extractors have no armor
this.armorType = "building"; // Changed from "light" in patch
this.speed = 0;
this.vision = 1500;
}
get buildingType() {
return "extractor";
}
get subtype() {
return "extractor";
}
}
/**
* Supply Building - Provides supply/housing
* Usage: new SupplyBuilding("Cultivator", (supply) => { supply.providesSupply = 10; })
*/
export class SupplyBuilding extends Building {
constructor() {
super();
this.providesSupply = 12;
}
get buildingType() {
return "supply";
}
get subtype() {
return "supply";
}
toJSON() {
return {
...super.toJSON(),
providesSupply: this.providesSupply,
};
}
}
/**
* Production Building - Creates units
* Usage: new ProductionBuilding("Incubator", (prod) => { prod.tier = "T1"; })
*/
export class ProductionBuilding extends Building {
constructor() {
super();
}
get buildingType() {
return "production";
}
get subtype() {
return "production";
}
}
/**
* Tech Building - Research and upgrades
* Usage: new TechBuilding("Augmentation Pool", (tech) => { tech.tier = "T2"; })
*/
export class TechBuilding extends Building {
constructor() {
super();
}
get buildingType() {
return "tech";
}
get subtype() {
return "tech";
}
toJSON() {
return {
...super.toJSON(),
researches: this.researches,
};
}
}
/**
* Special Building - Unique faction abilities
* Usage: new SpecialBuilding("Skrelling Nest", (special) => { special.tier = "T2"; })
*/
export class SpecialBuilding extends Building {
constructor() {
super();
}
get buildingType() {
return "special";
}
get subtype() {
return "special";
}
}
/**
* Constructing-Form Building - Buildings that transform into units
* Used for Terror Tank, Dreadnought, and similar units that have building phases
* Usage: new ConstructingFormBuilding("Terror Tank (Constructing)", (form) => { form.transformsInto = "terror-tank"; })
*/
export class ConstructingFormBuilding extends Building {
constructor() {
super();
}
get buildingType() {
return "constructing-unit";
}
get subtype() {
return "constructing-form";
}
toJSON() {
return {
...super.toJSON(),
transformsInto: this.transformsInto,
constructionTime: this.constructionTime,
};
}
}
/**
* Mercenary Outpost Building - Neutral mercenary structures
* Usage: new MercenaryOutpostBuilding("Mercenary Outpost", (merc) => { merc.tier = "T1"; })
*/
export class MercenaryOutpostBuilding extends Building {
constructor() {
super();
}
get buildingType() {
return "merc-outpost";
}
get subtype() {
return "merc-outpost";
}
}
/**
* Ultimate Building - End-game superstructures
* Usage: new UltimateBuilding("Supreme Command", (ultimate) => { ultimate.tier = "T4"; })
*/
export class UltimateBuilding extends Building {
constructor() {
super();
}
get buildingType() {
return "ultimate";
}
get subtype() {
return "ultimate";
}
}
//# sourceMappingURL=building.js.map