nomicness / a-whole-new-world

2 stars 7 forks source link

Nomic-Bot: Allocate Command #78

Closed ArchmageInc closed 8 years ago

ArchmageInc commented 8 years ago

Nomic-Bot needs to be able to allocate a player's population to endeavors, such as farming.

jimmyhmiller commented 8 years ago

I was thinking that we might be able to make this incredibly generic. What if we add a command that can do things like this:

/update-village Friesland
village.population.general -= 10
village.population.farming += 10

You can not only allocate, but update any stats by issuing a command. If we expand this idea out, we could make it easy to edit the players file without ever having to do so manually, ensuring it never gets into the wrong format.

ArchmageInc commented 8 years ago

While this is quite flexible, it does introduce the ability for people to modify things they shouldn't. By restricting modifications to specific commands, it helps enforce the rules.

rythompson commented 8 years ago

yay

jimmyhmiller commented 8 years ago

That's definitely true. But so far, people following the rules hasn't been that much of a problem. We will also have a log of every change (and could make them provide a reason if we wanted). I just know that as we keep adding rules, more and more scenarios like this will come up. I'd rather have a nice generic one first so that way for any new rule we can rely on it.

After the generic one is implemented we can definitely add convenience methods. In fact, I'm thinking about a way to do templated commands, for example:

/alias allocate :village :specialty :amount
/update-village :village
village.population.general -= :amount
village.population.:specialty += :amount

Now you could call this as so:

/allocate Friesland farming 10

I think having both the flexible option and the rule enforcing option can be useful.

jimmyhmiller commented 8 years ago

So I do like the idea above, but I've also just been thinking about how to author commands for our bot. I'd love to make it really easy to write one. Here is an example of how I'd like to write the allocate command. I have some fairly good ideas on how to make this work. Wanted to get feedback.

@ArchmageInc I might try adding a new section to the bot soon to start developing these sorts of commands if the feedback is good.

/* 
    /allocate 3 logging
    /allocate 3 farmers from logging
*/

const allocate = ({args: [amount, job, _, from="general"]}, { player }) => {
    player.village.population[job] = player.village.population[job] || 0;
    player.village.population[job] += Number(amount);
    player.village.population[from] = player.village.population[from] || 0;
    player.village.population[from] -= Number(amount);
    if (player.village.population[from] < 0) {
        return [createComment(`You do not have enough ${from} population to allocate ${amount} ${jobs}, ${player.name}`)]
    }
    return [
        updatePlayer(player), 
        createComment(`Allocated ${amount} ${job} from ${from}, ${player.name}`)
    ] 
}

Do you think the captures the essence of allocate? What things should not be there? What things are missing?