import * as utils from "../../utils/index";
import * as comp from "../components/index";
// amount of max fuel the bots should start with
export const INIT_FUEL_PERCENT = 0.15;
// lore description for spawn eggs
export const loreLine = "Fuel Percentage: ";
export const lineColor = '§7';
export const botThatDoesntUseFuel = "Does not require fuel";
export class FuelOnSpawnComponent extends utils.ActorComponent {
    onComponentAdded() {
        this.actor.subscribe("spawned_from_egg", () => this.onUseItem(this.actor.SpawnEggEvent));
    }
    onUseItem(event) {
        var _a, _b;
        // read stored fuel from lore
        const lore = event.itemStack.getLore();
        // if item has stored fuel set bot fuel to it, otherwise set max
        // if initialFuel is passed -1, sets fuel to max
        if (lore[1] && lore[1].includes(lineColor)) {
            const storedFuel = Number(lore[1].replace(lineColor, '').split(' ')[0]);
            (_a = this.actor.getActorComponent(comp.BotFuelComponent)) === null || _a === void 0 ? void 0 : _a.initialFuel(storedFuel);
        }
        else {
            (_b = this.actor.getActorComponent(comp.BotFuelComponent)) === null || _b === void 0 ? void 0 : _b.initialFuel(-1);
        }
    }
}
