Shpigford / society-fail

Browser-based incremental post-apocalyptic clicker game
https://society.fail
MIT License
30 stars 5 forks source link

Generate survivor function is missing which is causing error #2

Closed BhawaniSingh closed 2 months ago

BhawaniSingh commented 2 months ago

generateSurvivor() function is called here https://github.com/Shpigford/society-fail/blob/main/javascript/game.js#L955, but the function is not defined, and because of that watchtower missions never succeed. To fix this, I added the following method and it fixed the issue:

function generateSurvivor() {
    let availableNames = [...names];
    const randomIndex = Math.floor(Math.random() * availableNames.length);
    const name = availableNames[randomIndex];
    return {
        name: name,
        health: 100,
        hunger: 0,
        thirst: 0,
        energy: 100,
        traits: {
            hungerRate: getRandomTrait('hungerRate'),
            thirstRate: getRandomTrait('thirstRate'),
            energyRate: getRandomTrait('energyRate'),
            maxEnergy: Math.round(getRandomTrait('maxEnergy')),
            energyRecoveryRate: getRandomTrait('energyRecoveryRate')
        }
    };
}

This resolves the issue, but it should also check for existing names so that duplicate names(survivor or players) are not generated

Shpigford commented 2 months ago

@BhawaniSingh Thank you so much for this! I actually just rebuilt the whole thing from scratch, so hopefully the two issues you opened have been resolved with it.