From d7b48a63d18d9ea6e9f32b69ec0481a702398a41 Mon Sep 17 00:00:00 2001 From: a Date: Wed, 22 Mar 2023 17:01:39 -0500 Subject: [PATCH] ok --- src/lib/actions.ts | 6 ++---- src/lib/game.ts | 19 ++++++++++++------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/lib/actions.ts b/src/lib/actions.ts index 09faed8..0022990 100644 --- a/src/lib/actions.ts +++ b/src/lib/actions.ts @@ -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) }, } diff --git a/src/lib/game.ts b/src/lib/game.ts index decc2a0..5c0a38f 100644 --- a/src/lib/game.ts +++ b/src/lib/game.ts @@ -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 + Play?(game:Game):Promise + After?(game:Game):Promise } 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