import type { VillageState } from "../village";

export default function startQuest(V: VillageState, questId: number, heroId: number) {
    const quest = V.quests.find(q => q.id === questId);
    if (!quest) {
        return false;
    }

    const hero = V.heroes.find(h => h.id === heroId);
    if (!hero) {
        return false;
    }

    // Make sure the hero is not already on a quest.
    if (V.quests.some(q => q.hero === heroId)) {
        return false;
    }

    quest.started = true;
    quest.hero = heroId;
    quest.remainingTime = quest.duration * 1000;

    return true;
}
