diff --git a/comm/const.go b/comm/const.go index 8a25513fe..80d73af99 100644 --- a/comm/const.go +++ b/comm/const.go @@ -114,6 +114,7 @@ const ( ModuleJielong core.M_Modules = "jielong" //接龙 ModuleEntertainment core.M_Modules = "entertain" //消消乐 ModuleDcolor core.M_Modules = "dcolor" //猜颜色 + ModuleMaincity core.M_Modules = "maincity" //主城同屏 ) // 数据表名定义处 diff --git a/lego/sys/timewheel/timewheel.go b/lego/sys/timewheel/timewheel.go index e9677e47e..6f327d3a4 100644 --- a/lego/sys/timewheel/timewheel.go +++ b/lego/sys/timewheel/timewheel.go @@ -106,7 +106,7 @@ func (this *TimeWheel) Add(delay time.Duration, handler func(*Task, ...interface // AddCron add interval task func (this *TimeWheel) AddCron(delay time.Duration, handler func(*Task, ...interface{}), args ...interface{}) *Task { - return this.addAny(delay, modeIsCircle, modeIsAsync, handler, args...) + return this.addAny(delay, true, modeIsAsync, handler, args...) } func (this *TimeWheel) Remove(task *Task) error { diff --git a/modules/dcolor/api_singleover.go b/modules/dcolor/api_singleover.go index e23385fe9..9d33c1784 100644 --- a/modules/dcolor/api_singleover.go +++ b/modules/dcolor/api_singleover.go @@ -31,17 +31,19 @@ func (this *apiComp) SingleOver(session comm.IUserSession, req *pb.DColorSingleO } return } - if conf, err = this.module.configure.getGameGColorGetfractionData(int32(req.Difficulty), req.Repeat, len(req.Handles)); err != nil { + if conf, err = this.module.configure.getGameGColorGetfractionData(int32(req.Difficulty)+1, req.Repeat, len(req.Handles)-1); err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ConfigNoFound, Message: err.Error(), } + return } if tconf, err = this.module.configure.getGameGColortTmedecayData(req.Time); err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ConfigNoFound, Message: err.Error(), } + return } info.Integral += int32(math.Floor(float64(conf.Fraction) * float64(tconf.Pro) / float64(1000))) diff --git a/modules/dcolor/configure.go b/modules/dcolor/configure.go index 8763180eb..75bf3ab4e 100644 --- a/modules/dcolor/configure.go +++ b/modules/dcolor/configure.go @@ -84,7 +84,7 @@ func (this *configureComp) getGameGColorGetfractionData(dif int32, repeat bool, } if _, ok = confs[dif]; ok { - if len(confs[dif]) < index { + if len(confs[dif]) > index { conf = confs[dif][index] return } diff --git a/modules/dcolor/core.go b/modules/dcolor/core.go index 775a92d4b..9554940ff 100644 --- a/modules/dcolor/core.go +++ b/modules/dcolor/core.go @@ -12,29 +12,26 @@ func RandomColor(difficulty pb.DBDColorDifficulty, Repeat bool) (temcolors []int colorNum int colors []int32 = []int32{1, 2, 3, 4, 5, 6, 7, 8} ) - + temcolors = make([]int32, 4) switch difficulty { case pb.DBDColorDifficulty_Simple: colorNum = 4 - temcolors = make([]int32, 4) break case pb.DBDColorDifficulty_Difficulty: colorNum = 6 - temcolors = make([]int32, 6) break case pb.DBDColorDifficulty_Hell: colorNum = 8 - temcolors = make([]int32, 7) break } if Repeat { - for i := 0; i < colorNum; i++ { + for i := 0; i < 4; i++ { n, _ := rand.Int(rand.Reader, big.NewInt(int64(colorNum))) temcolors[i] = colors[n.Int64()] } } else { colors = colors[0:colorNum] - for i := 0; i < colorNum; i++ { + for i := 0; i < 4; i++ { n, _ := rand.Int(rand.Reader, big.NewInt(int64(len(colors)))) index := n.Int64() temcolors[i] = colors[index] diff --git a/modules/dcolor/module.go b/modules/dcolor/module.go index fd33b4599..48f9327ee 100644 --- a/modules/dcolor/module.go +++ b/modules/dcolor/module.go @@ -38,6 +38,7 @@ func (this *DColor) Init(service core.IService, module core.IModule, options cor func (this *DColor) OnInstallComp() { this.ModuleBase.OnInstallComp() this.api = this.RegisterComp(new(apiComp)).(*apiComp) + this.configure = this.RegisterComp(new(configureComp)).(*configureComp) this.model = this.RegisterComp(new(modelComp)).(*modelComp) this.modelQiecuo = this.RegisterComp(new(modelQiecuoComp)).(*modelQiecuoComp) this.rooms = this.RegisterComp(new(roomsComp)).(*roomsComp) diff --git a/modules/maincity/model.go b/modules/maincity/model.go index e0148a7ae..929507202 100644 --- a/modules/maincity/model.go +++ b/modules/maincity/model.go @@ -22,7 +22,7 @@ func (this *modelComp) Init(service core.IService, module core.IModule, comp cor err = this.MCompModel.Init(service, module, comp, options) this.TableName = comm.Tablekftask this.module = module.(*MainCity) - + this.onlines = make(map[string][]*pb.BaseUserInfo) this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{ Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}}, }) diff --git a/modules/maincity/module.go b/modules/maincity/module.go index 5f32bce8d..137301bab 100644 --- a/modules/maincity/module.go +++ b/modules/maincity/module.go @@ -28,7 +28,7 @@ func NewModule() core.IModule { } func (this *MainCity) GetType() core.M_Modules { - return comm.ModuleKFTask + return comm.ModuleMaincity } func (this *MainCity) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) { @@ -92,8 +92,8 @@ func (this *MainCity) EventUserLogin(session comm.IUserSession) { } // 用户登录 -func (this *MainCity) EventUserOffline(session comm.IUserSession) { - this.model.removelayerPos(session.GetUserId()) +func (this *MainCity) EventUserOffline(uid string, sessionid string) { + this.model.removelayerPos(uid) } // 向多个用户发送消息 diff --git a/modules/parkour/ai.go b/modules/parkour/ai.go index 8ea844621..504f2c95c 100644 --- a/modules/parkour/ai.go +++ b/modules/parkour/ai.go @@ -5,11 +5,10 @@ import ( "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/lego/core/cbase" - "go_dreamfactory/lego/sys/timewheel" + "go_dreamfactory/lego/sys/cron" "go_dreamfactory/pb" cfg "go_dreamfactory/sys/configure/structs" "sync" - "time" ) /* @@ -42,7 +41,8 @@ func (this *aiComp) Start() (err error) { if this.shotConf, err = this.module.configure.getGameBuzkashiQteLvs(); err != nil { return } - timewheel.AddCron(time.Second, this.run) + cron.AddFunc("*/1 * * * * ?", this.run) + // timewheel.AddCron(time.Second, this.run) return } @@ -86,7 +86,7 @@ func (this *aiComp) removeAi(battleid string) { this.lock.Unlock() } -func (this *aiComp) run(task *timewheel.Task, args ...interface{}) { +func (this *aiComp) run() { var ( ais []*AI ) @@ -121,7 +121,7 @@ func (this *aiComp) ExceAi(_ai *AI) { } } - if len(handle) > 0 { + if len(handle) == 0 { return } diff --git a/modules/parkour/api_changemts.go b/modules/parkour/api_changemts.go index 4add2d02d..75937b653 100644 --- a/modules/parkour/api_changemts.go +++ b/modules/parkour/api_changemts.go @@ -37,8 +37,14 @@ func (this *apiComp) ChangeMts(session comm.IUserSession, req *pb.ParkourChangeM return } info.Defmts = dragon.Id + info.Property = dragon.Property + info.Mount = dragon.Dragonid + info.Mlv = dragon.Lv if err = this.module.parkourComp.Change(session.GetUserId(), map[string]interface{}{ - "defmts": info.Defmts, + "defmts": info.Defmts, + "property": info.Property, + "mount": info.Mount, + "mlv": info.Mlv, }); err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_DBError, diff --git a/modules/parkour/api_racematch.go b/modules/parkour/api_racematch.go index f1c2aab0a..a5dcc6b30 100644 --- a/modules/parkour/api_racematch.go +++ b/modules/parkour/api_racematch.go @@ -42,10 +42,22 @@ func (this *apiComp) RaceMatch(session comm.IUserSession, req *pb.ParkourRaceMat } return } - if team.Captainid == "" { //为组队情况 - team.Captainid = team.Uid - team.State = pb.RaceTeamState_teaming - team.Member = append(team.Member, &pb.DBRaceMember{ + // if team.Captainid == "" { //为组队情况 + team.Captainid = team.Uid + team.State = pb.RaceTeamState_teaming + // team.Member = append(team.Member, &pb.DBRaceMember{ + // Uid: team.Uid, + // Name: team.Name, + // Skin: team.Skin, + // Sex: team.Sex, + // Lv: team.Lv, + // Dan: team.Dan, + // Mount: team.Mount, + // Property: team.Property, + // Currhp: team.Property[comm.Dhp], + // }) + team.Member = []*pb.DBRaceMember{ + { Uid: team.Uid, Name: team.Name, Skin: team.Skin, @@ -55,20 +67,21 @@ func (this *apiComp) RaceMatch(session comm.IUserSession, req *pb.ParkourRaceMat Mount: team.Mount, Property: team.Property, Currhp: team.Property[comm.Dhp], - }) - if err = this.module.parkourComp.Change(team.Captainid, map[string]interface{}{ - "state": team.State, - "captainid": team.Captainid, - "member": team.Member, - }); err != nil { - errdata = &pb.ErrorData{ - Code: pb.ErrorCode_DBError, - Title: pb.ErrorCode_DBError.ToString(), - Message: err.Error(), - } - return - } + }, } + if err = this.module.parkourComp.Change(team.Captainid, map[string]interface{}{ + "state": team.State, + "captainid": team.Captainid, + "member": team.Member, + }); err != nil { + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_DBError, + Title: pb.ErrorCode_DBError.ToString(), + Message: err.Error(), + } + return + } + // } if ais, err = this.module.parkourComp.matcheAI(team.Dan, 5); err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_DBError, diff --git a/services/worker/main.go b/services/worker/main.go index 953c7f660..c5da3abef 100644 --- a/services/worker/main.go +++ b/services/worker/main.go @@ -80,6 +80,7 @@ import ( "go_dreamfactory/lego" "go_dreamfactory/lego/base/rpcx" "go_dreamfactory/lego/core" + "go_dreamfactory/lego/sys/cron" "go_dreamfactory/lego/sys/log" "go_dreamfactory/lego/sys/timewheel" ) @@ -196,6 +197,12 @@ func (this *Service) InitSys() { log.Infof("init sys.wordfilter success!") } //定时系统 秒级时间轮 + if err := cron.OnInit(nil); err != nil { + panic(fmt.Sprintf("init sys.cron err: %s", err.Error())) + } else { + log.Infof("init sys.cron success!") + } + //定时系统 秒级时间轮 if err := timewheel.OnInit(nil, timewheel.SetTick(time.Second)); err != nil { panic(fmt.Sprintf("init sys.timewheel err: %s", err.Error())) } else {