From 88d612e041691268d97ab1ae01a2c1d8c7db5fe7 Mon Sep 17 00:00:00 2001 From: alex Date: Fri, 16 Nov 2018 01:01:29 +0000 Subject: [PATCH] CanAct func, used in Riot and Lift --- wat/db.go | 1 + wat/game.go | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/wat/db.go b/wat/db.go index 1233e84..53876c3 100644 --- a/wat/db.go +++ b/wat/db.go @@ -87,6 +87,7 @@ const ( Action_Mine ActionType = 1 Action_Rest ActionType = 2 Action_Lift ActionType = 3 + Action_Riot ActionType = 4 ) type ActionType int diff --git a/wat/game.go b/wat/game.go index 735cd45..920658b 100644 --- a/wat/game.go +++ b/wat/game.go @@ -364,12 +364,20 @@ func (g *WatGame) Rest(player *Player, fields []string) string { return ret } +func (g *WatGame) CanAct(player *Player, action ActionType, minTime int64) bool { + delta := g.db.LastActed(player, action) + if minTime != 0 && delta != 0 && time.Now().Unix()-delta < minTime { + return false + } + return true +} + func (g *WatGame) Bench(player *Player, fields []string) string { - delta := g.db.LastActed(player, Action_Lift) minTime := int64(2400) - if delta != 0 && delta-time.Now().Unix() < minTime { + if !g.CanAct(player, Action_Lift, minTime) { return "you're tired. no more lifting for now." } + return "ok" weight := g.RandInt(370) + 50 reps := g.RandInt(10) value := int64(0) @@ -393,6 +401,9 @@ func (g *WatGame) Bench(player *Player, fields []string) string { } func (g *WatGame) Riot(player *Player, fields []string) string { + if !g.CanAct(player, Action_Riot, int64((48 * time.Hour).Seconds())) { + return "Planning a riot takes time and the right circumstances. Be prepared. (nothing happens)" + } r := g.RandInt(100) reply := "" if r > 30 { @@ -402,6 +413,7 @@ func (g *WatGame) Riot(player *Player, fields []string) string { player.Health -= 3 reply = fmt.Sprintf("The proletariat have been hunted down by the secret police and had their faces smashed in! Your rebellion fails and you lose 3HP.") } + g.db.Act(player, Action_Riot) g.db.Update(player) return reply }