This commit is contained in:
a 2023-03-22 17:01:39 -05:00
parent 1ac87d8c59
commit d7b48a63d1
2 changed files with 14 additions and 11 deletions

View File

@ -3,7 +3,7 @@ import {Action} from "./game"
import { render } from "./template"
export const ActionAnnounceNewGame: Action = {
Before(game) {
async Before(game) {
const msg:MessageCreateOptions = {
content: render(
`new game. players ({{playercount}})
@ -14,8 +14,6 @@ export const ActionAnnounceNewGame: Action = {
players: Object.values(game.players),
}),
}
return [
msg
]
game.sink.SendMessage(msg)
},
}

View File

@ -29,22 +29,23 @@ export interface ActionFactory {
// an action is in charge of the entire state transition
export interface Action {
Before?(game:Game):MessageCreateOptions[]
Play?(game:Game):MessageCreateOptions[]
After?(game:Game):MessageCreateOptions[]
Before?(game:Game):Promise<void>
Play?(game:Game):Promise<void>
After?(game:Game):Promise<void>
}
export const PlayActions = async (game:Game, actions:Action[]) => {
for(let i = 0; i < actions.length; i++) {
const a = actions[i];
try {
[a.Before,a.Play,a.After].forEach(async (x)=>{
if(x){
const msgs = x(game)
msgs.forEach(async (msg)=>{
await game.sink.SendMessage(msg).catch(console.log)
})
await x(game)
}
});
} catch(e) {
// we stop running on the first error, aka is play fails, after is not run
}
}
}
@ -75,11 +76,15 @@ export class Player {
// chance you will win your next combat
power: number
// custom fields for actions to use
stats: {[index:string]:any}
constructor(name:string) {
this.health = 100
this.visibility = 50
this.power = 50
this.name = name
this.stats = {}
}
// bool is whether or not player is dead after damage