上传战斗计时结束
This commit is contained in:
parent
ee83d78681
commit
a05275d234
@ -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 //准备倒计时定时器
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user