From 1412579c6c72c457c16e170cb685c50bcb608565 Mon Sep 17 00:00:00 2001 From: Marc Di Luzio Date: Tue, 7 Jul 2020 18:37:59 +0100 Subject: [PATCH] Only charge during the day --- pkg/game/world.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pkg/game/world.go b/pkg/game/world.go index 2792511..a4a70af 100644 --- a/pkg/game/world.go +++ b/pkg/game/world.go @@ -152,6 +152,11 @@ func (w *World) RoverRecharge(rover string) (int, error) { return 0, fmt.Errorf("Failed to find rover with name: %s", rover) } + // We can only recharge during the day + if !w.Daytime() { + return i.Charge, nil + } + // Add one charge if i.Charge < i.MaximumCharge { i.Charge++ @@ -489,6 +494,13 @@ func (w *World) ExecuteCommand(c *Command, rover string) (err error) { return } +// Daytime returns if it's currently daytime +// for simplicity this uses the 1st half of the day as daytime, the 2nd half as nighttime +func (w *World) Daytime() bool { + tickInDay := w.CurrentTicks % w.TicksPerDay + return tickInDay < w.TicksPerDay/2 +} + // RLock read locks the world func (w *World) RLock() { w.worldMutex.RLock()