final start/reset touches

This commit is contained in:
shoopea
2021-12-04 13:39:15 +08:00
parent 84579af511
commit acf58c99ef
4 changed files with 17 additions and 19 deletions

14
bot.go
View File

@@ -284,6 +284,12 @@ func botActuallyReset(m *tb.Message) {
bot.SendChat(m.Chat.ID, "Request expired.")
} else {
cfg.Game.Started = false
for _, cc := range cfg.Clients {
cc.Ready = false
cc.CompanyID = 255
cc.Online = false
cc.TimeLeft = 0
}
bot.SendChat(m.Chat.ID, "Game resetted.")
}
delete(botActionMap, ref)
@@ -350,6 +356,7 @@ func botActuallyStart(m *tb.Message) {
cfg.Game.StartDate = time.Now()
for _, cc := range cfg.Clients {
cc.Ready = true
cc.TimeLeft = cfg.Game.StartingAllotment
}
bot.SendChat(m.Chat.ID, "Game started !")
}
@@ -745,6 +752,7 @@ func botRegister(m *tb.Message) {
Username: m.Sender.Username,
CompanyID: 255,
TimeLeft: 0,
Ready: cfg.Game.Started,
}
cfg.Clients[m.Sender.ID] = cc
} else {
@@ -809,11 +817,13 @@ func botRegister(m *tb.Message) {
if len(coList) == 1 {
for id, _ := range coList {
cc.CompanyID = id
if cc.TimeLeft == 0 {
if cc.TimeLeft == 0 && cfg.Game.Started {
days := int(time.Now().Sub(cfg.Game.StartDate).Hours() / 24)
cc.TimeLeft = cfg.Game.StartingAllotment + cfg.Game.DailyAllotment*time.Duration(days)
bot.SendChat(m.Chat.ID, fmt.Sprintf("@%s registered %s (with %s playable)", cc.Username, srv.Status.Companies[cc.CompanyID].Name, cc.TimeLeft.Round(time.Second)))
} else {
bot.SendChat(m.Chat.ID, fmt.Sprintf("@%s registered %s", cc.Username, srv.Status.Companies[cc.CompanyID].Name))
}
bot.SendChat(m.Chat.ID, fmt.Sprintf("@%s registered %s (with %s playable)", cc.Username, srv.Status.Companies[cc.CompanyID].Name, cc.TimeLeft.Round(time.Second)))
return
}
}