import * as utils from "../../utils/index";
export class AutotameComponent extends utils.ActorComponent {
    get Owner() {
        if (!this.actor.isValid())
            return;
        if (this.owner)
            return this.owner;
        if (this.OwnerID) {
            const owner = utils.getAllPlayersSafe().find(player => player.id === this.OwnerID);
            this.owner = owner;
            return owner;
        }
    }
    get OwnerID() {
        const tame = this.actor.getComponent("tameable");
        return tame === null || tame === void 0 ? void 0 : tame.tamedToPlayerId;
    }
    onComponentAdded() {
        this.actor.subscribe("spawned_from_egg", () => {
            this.tame(this.actor.SpawnEggEvent.source);
        });
    }
    tame(player) {
        const tameable = this.actor.getComponent("tameable");
        if (tameable) {
            tameable.tame(player);
        }
    }
}
