fix одновременное принятие дуэли

This commit is contained in:
Smile Rex
2025-03-11 00:04:19 +03:00
parent 34315fef68
commit 65a99e6ab9
2 changed files with 13 additions and 5 deletions

View File

@@ -11,7 +11,7 @@ import (
) )
// ////////////////////// // //////////////////////
var isTest bool = false var isTest bool = true
//////////////////////// ////////////////////////

View File

@@ -24,10 +24,11 @@ type DuelController struct {
FName string FName string
} }
Summ int Summ int
Inited bool Inited bool
Bot *tele.Bot MatchAccepted bool
DC *DataController Bot *tele.Bot
DC *DataController
} }
// Controller Init // Controller Init
@@ -81,6 +82,10 @@ func (s *DuelController) StartMatch(c tele.Context) error {
// Accept Match // Accept Match
func (s *DuelController) AcceptMatch(c tele.Context) error { func (s *DuelController) AcceptMatch(c tele.Context) error {
if s.MatchAccepted {
return c.Send("Дождитесь окончания дуэли.")
}
if !s.Inited { if !s.Inited {
return c.Send("Дуэль еще не началась! Дождитесь старта матча или начните новую дуель с помощью /duel <сумма>") return c.Send("Дуэль еще не началась! Дождитесь старта матча или начните новую дуель с помощью /duel <сумма>")
} }
@@ -101,6 +106,8 @@ func (s *DuelController) AcceptMatch(c tele.Context) error {
s.Summ *= 2 s.Summ *= 2
go s.gameProccess(c.Chat()) go s.gameProccess(c.Chat())
s.MatchAccepted = true
return c.Send(fmt.Sprintf("%s принимает участие в дуэли.", s.PlayerTwo.FName)) return c.Send(fmt.Sprintf("%s принимает участие в дуэли.", s.PlayerTwo.FName))
} }
@@ -190,4 +197,5 @@ func (s *DuelController) CheckWin(msg *tele.Message) {
s.PlayerTwo.Counter = 0 s.PlayerTwo.Counter = 0
s.Summ = 0 s.Summ = 0
s.Inited = false s.Inited = false
s.MatchAccepted = false
} }