This commit is contained in:
parent
1ac87d8c59
commit
d7b48a63d1
|
@ -3,7 +3,7 @@ import {Action} from "./game"
|
||||||
import { render } from "./template"
|
import { render } from "./template"
|
||||||
|
|
||||||
export const ActionAnnounceNewGame: Action = {
|
export const ActionAnnounceNewGame: Action = {
|
||||||
Before(game) {
|
async Before(game) {
|
||||||
const msg:MessageCreateOptions = {
|
const msg:MessageCreateOptions = {
|
||||||
content: render(
|
content: render(
|
||||||
`new game. players ({{playercount}})
|
`new game. players ({{playercount}})
|
||||||
|
@ -14,8 +14,6 @@ export const ActionAnnounceNewGame: Action = {
|
||||||
players: Object.values(game.players),
|
players: Object.values(game.players),
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
return [
|
game.sink.SendMessage(msg)
|
||||||
msg
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,22 +29,23 @@ export interface ActionFactory {
|
||||||
|
|
||||||
// an action is in charge of the entire state transition
|
// an action is in charge of the entire state transition
|
||||||
export interface Action {
|
export interface Action {
|
||||||
Before?(game:Game):MessageCreateOptions[]
|
Before?(game:Game):Promise<void>
|
||||||
Play?(game:Game):MessageCreateOptions[]
|
Play?(game:Game):Promise<void>
|
||||||
After?(game:Game):MessageCreateOptions[]
|
After?(game:Game):Promise<void>
|
||||||
}
|
}
|
||||||
|
|
||||||
export const PlayActions = async (game:Game, actions:Action[]) => {
|
export const PlayActions = async (game:Game, actions:Action[]) => {
|
||||||
for(let i = 0; i < actions.length; i++) {
|
for(let i = 0; i < actions.length; i++) {
|
||||||
const a = actions[i];
|
const a = actions[i];
|
||||||
|
try {
|
||||||
[a.Before,a.Play,a.After].forEach(async (x)=>{
|
[a.Before,a.Play,a.After].forEach(async (x)=>{
|
||||||
if(x){
|
if(x){
|
||||||
const msgs = x(game)
|
await x(game)
|
||||||
msgs.forEach(async (msg)=>{
|
|
||||||
await game.sink.SendMessage(msg).catch(console.log)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} 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
|
// chance you will win your next combat
|
||||||
power: number
|
power: number
|
||||||
|
|
||||||
|
// custom fields for actions to use
|
||||||
|
stats: {[index:string]:any}
|
||||||
|
|
||||||
constructor(name:string) {
|
constructor(name:string) {
|
||||||
this.health = 100
|
this.health = 100
|
||||||
this.visibility = 50
|
this.visibility = 50
|
||||||
this.power = 50
|
this.power = 50
|
||||||
this.name = name
|
this.name = name
|
||||||
|
this.stats = {}
|
||||||
}
|
}
|
||||||
|
|
||||||
// bool is whether or not player is dead after damage
|
// bool is whether or not player is dead after damage
|
||||||
|
|
Loading…
Reference in New Issue