import { EEnemySize, EProjectileEffectType } from "../../GameData/index.js";
export class SimEnemy {
    _index;
    _routeIdx;
    _startHex;
    _endHex;
    _path;
    _position;
    _direction;
    _currentPathIndex;
    _currentPathStep;
    _currentPathPosition;
    _dead = false;
    _simLevel;
    _gdEnemy;
    _hitPonts;
    _size;
    _speed;
    _gain;
    _gdRoot;
    constructor(gdRoot, wave, routeIdx, level) {
        const gdLevel = level.gdLevel;
        const route = gdLevel.enemyRoutes[routeIdx];
        this._gdRoot = gdRoot;
        this._index = wave.enemy;
        this._simLevel = level;
        this._hitPonts = wave.hitpoints;
        this._size = wave.size;
        this._gain = wave.gain;
        this._startHex = gdLevel.enemySpawns[route[0]];
        this._endHex = gdLevel.enemyTargets[route[1]];
        this._gdEnemy = this._gdRoot.enemies[this._index];
        this._currentPathIndex = 0;
        this._currentPathStep = level.currentStep;
        this._dead = false;
        this._routeIdx = routeIdx;
        this._path = level.simCells[level.getCellIndex(this._startHex)].pathsToTarget[routeIdx];
        this._position = level.simCells[this._path[0]].hex.toWorld();
        this._direction = level.simCells[this._path[1]].hex.toWorld().subtract(this._position).normalized();
        this._currentPathPosition = this._position;
        this._speed = this._gdEnemy.speed;
        switch (wave.size) {
            case EEnemySize.Tiny:
                this._speed *= 2;
                break;
            case EEnemySize.Huge:
                this._speed *= 0.5;
                break;
        }
    }
    get path() {
        return this._path;
    }
    set path(value) {
        this._path = value;
    }
    get position() {
        return this._position;
    }
    set position(value) {
        this._position = value;
    }
    get direction() {
        return this._direction;
    }
    get endHex() {
        return this._endHex;
    }
    get currentPathIndex() {
        return this._currentPathIndex;
    }
    set currentPathIndex(value) {
        this._currentPathIndex = value;
    }
    get currentPathStep() {
        return this._currentPathStep;
    }
    set currentPathStep(value) {
        this._currentPathStep = value;
    }
    get currentPathPosition() {
        return this._currentPathPosition;
    }
    get dead() {
        return this._dead;
    }
    set dead(value) {
        this._dead = value;
    }
    get speed() {
        return this._speed;
    }
    get size() {
        return this._size;
    }
    get index() {
        return this._index;
    }
    suffer = (effect) => {
        switch (effect.type) {
            case EProjectileEffectType.Damage:
                {
                    this._hitPonts -= effect.amount;
                    if (this._hitPonts <= 0) {
                        this._simLevel.currency += this._gain;
                        this._dead = true;
                    }
                    break;
                }
        }
    };
    onPathUpdated = () => {
        const myPos = this._position;
        this._currentPathPosition = myPos;
        if (this._path == null) {
            return;
        }
        const current = this._path[this._currentPathIndex];
        const next = this._path[this._currentPathIndex + 1];
        if (!next) {
            return;
        }
        const cells = this._simLevel.simCells;
        const pos1 = cells[current].hex.toWorld();
        const pos2 = cells[next].hex.toWorld();
        const myDir = pos2.subtract(myPos);
        const myLen = myDir.magnitude();
        const hexDir = pos2.subtract(pos1);
        const hexLen = hexDir.magnitude();
        if (myLen > hexLen) {
            this._path.unshift(this._path[0]);
        }
        this._direction = myDir.multiplyScalar(1 / myLen);
    };
}
//# sourceMappingURL=SimEnemy.js.map