CanAct func, used in Riot and Lift
This commit is contained in:
parent
7f72f6e3ec
commit
88d612e041
@ -87,6 +87,7 @@ const (
|
|||||||
Action_Mine ActionType = 1
|
Action_Mine ActionType = 1
|
||||||
Action_Rest ActionType = 2
|
Action_Rest ActionType = 2
|
||||||
Action_Lift ActionType = 3
|
Action_Lift ActionType = 3
|
||||||
|
Action_Riot ActionType = 4
|
||||||
)
|
)
|
||||||
|
|
||||||
type ActionType int
|
type ActionType int
|
||||||
|
16
wat/game.go
16
wat/game.go
@ -364,12 +364,20 @@ func (g *WatGame) Rest(player *Player, fields []string) string {
|
|||||||
return ret
|
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 {
|
func (g *WatGame) Bench(player *Player, fields []string) string {
|
||||||
delta := g.db.LastActed(player, Action_Lift)
|
|
||||||
minTime := int64(2400)
|
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 "you're tired. no more lifting for now."
|
||||||
}
|
}
|
||||||
|
return "ok"
|
||||||
weight := g.RandInt(370) + 50
|
weight := g.RandInt(370) + 50
|
||||||
reps := g.RandInt(10)
|
reps := g.RandInt(10)
|
||||||
value := int64(0)
|
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 {
|
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)
|
r := g.RandInt(100)
|
||||||
reply := ""
|
reply := ""
|
||||||
if r > 30 {
|
if r > 30 {
|
||||||
@ -402,6 +413,7 @@ func (g *WatGame) Riot(player *Player, fields []string) string {
|
|||||||
player.Health -= 3
|
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.")
|
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)
|
g.db.Update(player)
|
||||||
return reply
|
return reply
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user