From a05275d23438000afc1831724270ec341c5eacfc Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Tue, 18 Apr 2023 21:09:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=88=98=E6=96=97=E8=AE=A1?= =?UTF-8?q?=E6=97=B6=E7=BB=93=E6=9D=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/parkour/core.go | 2 ++ modules/parkour/model_race.go | 8 ++++++++ modules/parkour/module.go | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+) diff --git a/modules/parkour/core.go b/modules/parkour/core.go index 82ca83426..ee7f9d908 100644 --- a/modules/parkour/core.go +++ b/modules/parkour/core.go @@ -2,6 +2,7 @@ package parkour import ( "go_dreamfactory/comm" + "go_dreamfactory/lego/sys/timewheel" "go_dreamfactory/pb" "sync" ) @@ -14,4 +15,5 @@ type RaceItem struct { RedSession []comm.IUserSession //红方会话 BuleMember []*pb.DBRaceMember //蓝方成员 BuleSession []comm.IUserSession //蓝方会话 + overtimer *timewheel.Task //准备倒计时定时器 } diff --git a/modules/parkour/model_race.go b/modules/parkour/model_race.go index 69939206c..03354fcde 100644 --- a/modules/parkour/model_race.go +++ b/modules/parkour/model_race.go @@ -29,3 +29,11 @@ func (this *ModelRaceComp) addrace(race *pb.DBRace) (err error) { } return } + +//移除战斗记录 +func (this *ModelRaceComp) delrace(id string) (err error) { + if err = this.DelListlds("", []string{id}, db.SetDBMgoLog(false)); err != nil { + this.module.Errorln(err) + } + return +} diff --git a/modules/parkour/module.go b/modules/parkour/module.go index 699c3c7c6..a9b5a81c5 100644 --- a/modules/parkour/module.go +++ b/modules/parkour/module.go @@ -7,9 +7,11 @@ import ( "go_dreamfactory/lego/base" "go_dreamfactory/lego/core" "go_dreamfactory/lego/sys/log" + "go_dreamfactory/lego/sys/timewheel" "go_dreamfactory/modules" "go_dreamfactory/pb" "sync" + "time" "go.mongodb.org/mongo-driver/bson/primitive" ) @@ -116,6 +118,7 @@ func (this *Parkour) createbattle(ctx context.Context, req *pb.RPCParkourMatchSu Id: race.Id, RedSession: make([]comm.IUserSession, 0), BuleSession: make([]comm.IUserSession, 0), + overtimer: timewheel.Add(time.Minute*3, this.overtimer, race.Id), } for _, v := range req.Red { @@ -221,3 +224,34 @@ func (this *Parkour) avoid(id string, uid string, dis int32) { } } } + +//战斗结束 +func (this *Parkour) overtimer(task *timewheel.Task, args ...interface{}) { + this.Debug("shot", log.Field{Key: "id", Value: args}) + var ( + battle *RaceItem + ok bool + sessions []comm.IUserSession = make([]comm.IUserSession, 0) + err error + ) + id := args[0].(string) + this.lock.RLock() + battle, ok = this.battles[id] + this.lock.RUnlock() + if ok { + this.lock.Lock() + delete(this.battles, id) + this.lock.Unlock() + this.raceComp.delrace(id) + sessions = append(sessions, battle.RedSession...) + sessions = append(sessions, battle.BuleSession...) + if err = this.SendMsgToSession(string(comm.ModulePvp), "finish", &pb.ParkourRaceOverPush{ + Race: &pb.DBRace{ + Id: battle.Id, + }, + }, sessions...); err != nil { + this.Errorln(err) + return + } + } +}