diff --git a/comm/const.go b/comm/const.go index 621090655..f4a72d29e 100644 --- a/comm/const.go +++ b/comm/const.go @@ -88,6 +88,7 @@ const ( ModuleBuried core.M_Modules = "buried" //埋点中心 ModuleActivity core.M_Modules = "acrivity" //活动 ModuleGuidance core.M_Modules = "guidance" //引导 + ModuleWtask core.M_Modules = "wtask" //世界任务 ) // 数据表名定义处 diff --git a/comm/imodule.go b/comm/imodule.go index 879103b25..cd375bd0a 100644 --- a/comm/imodule.go +++ b/comm/imodule.go @@ -533,4 +533,9 @@ type ( //推送红点 PushReddot(session IUserSession, reddot ...*pb.ReddotItem) (errdata *pb.ErrorData) } + //练功房 + IPasson interface { + //英雄升级 + HeroUpLv(session IUserSession, heroid string, lv int32) + } ) diff --git a/modules/passon/api_inroom.go b/modules/passon/api_inroom.go index b6309b114..c310a1fa7 100644 --- a/modules/passon/api_inroom.go +++ b/modules/passon/api_inroom.go @@ -50,7 +50,7 @@ func (this *apiComp) InRoom(session comm.IUserSession, req *pb.PassonInRoomReq) errdata = &pb.ErrorData{ Code: pb.ErrorCode_ReqParameterError, Title: pb.ErrorCode_ReqParameterError.ToString(), - Message: fmt.Sprintf("no found hero:%d", req.Heroid), + Message: fmt.Sprintf("no found hero:%s", req.Heroid), } return } @@ -82,7 +82,9 @@ func (this *apiComp) InRoom(session comm.IUserSession, req *pb.PassonInRoomReq) return } hero.Ispasson = true - - session.SendMsg(string(this.module.GetType()), "getlist", &pb.PassonInRoomResp{Heroid: req.Heroid}) + if errdata = this.module.ModuleHero.PassonHero(session, map[string]bool{hero.Id: true}); errdata != nil { + return + } + session.SendMsg(string(this.module.GetType()), "inroom", &pb.PassonInRoomResp{Heroid: req.Heroid}) return } diff --git a/modules/passon/core.go b/modules/passon/core.go new file mode 100644 index 000000000..9dda408b0 --- /dev/null +++ b/modules/passon/core.go @@ -0,0 +1,21 @@ +package passon + +import "go_dreamfactory/pb" + +type SliceHero []*pb.DBHero + +// 实现sort.Interface接口的方法 +// 获取数组长度 +func (this SliceHero) Len() int { + return len(this) +} + +// 比较元素大小 +func (this SliceHero) Less(i, j int) bool { + return this[i].Lv < this[j].Lv +} + +// 交换元素位置 +func (this SliceHero) Swap(i, j int) { + this[i], this[j] = this[j], this[i] +} diff --git a/modules/passon/module.go b/modules/passon/module.go index db0e7622f..c35c4429a 100644 --- a/modules/passon/module.go +++ b/modules/passon/module.go @@ -4,6 +4,7 @@ import ( "go_dreamfactory/comm" "go_dreamfactory/modules" "go_dreamfactory/pb" + "sort" "go_dreamfactory/lego/base" "go_dreamfactory/lego/core" @@ -53,6 +54,7 @@ func (this *Passon) Start() (err error) { func (this *Passon) HeroUpLv(session comm.IUserSession, heroid string, lv int32) { var ( passon *pb.DBPasson + heros []*pb.DBHero err error ) if passon, err = this.modelPasson.getUserPasson(session.GetUserId()); err != nil { @@ -69,4 +71,15 @@ func (this *Passon) HeroUpLv(session comm.IUserSession, heroid string, lv int32) } } + heros = this.ModuleHero.GetHeroList(session.GetUserId()) + + if len(heros) < 5 { + return + } + + // 使用sort.Slice进行排序 + sort.Slice(heros, func(i, j int) bool { + return heros[i].Lv < heros[j].Lv + }) + } diff --git a/modules/worldtask/module.go b/modules/worldtask/module.go index a5bddc023..f504a982e 100644 --- a/modules/worldtask/module.go +++ b/modules/worldtask/module.go @@ -5,6 +5,7 @@ import ( "go_dreamfactory/comm" "go_dreamfactory/lego/base" "go_dreamfactory/lego/core" + "go_dreamfactory/lego/sys/event" "go_dreamfactory/lego/sys/log" "go_dreamfactory/modules" "go_dreamfactory/pb" @@ -36,7 +37,7 @@ func (this *Worldtask) Init(service core.IService, module core.IModule, options func (this *Worldtask) OnInstallComp() { this.ModuleBase.OnInstallComp() - // event.Register(comm.EventBuriedComplete, this.TCondFinishNotify) + event.Register(comm.EventBuriedComplete, this.TCondFinishNotify) this.api = this.RegisterComp(new(apiComp)).(*apiComp) this.modelWorldtask = this.RegisterComp(new(ModelWorldtask)).(*ModelWorldtask) this.configure = this.RegisterComp(new(configureComp)).(*configureComp) diff --git a/modules/wtask/module.go b/modules/wtask/module.go index c4c599b4c..f2465fd00 100644 --- a/modules/wtask/module.go +++ b/modules/wtask/module.go @@ -28,7 +28,7 @@ func NewModule() core.IModule { } func (this *WTask) GetType() core.M_Modules { - return comm.ModuleWorldtask + return comm.ModuleWtask } func (this *WTask) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) { diff --git a/services/worker/main.go b/services/worker/main.go index 8727a43bd..831d7440f 100644 --- a/services/worker/main.go +++ b/services/worker/main.go @@ -49,6 +49,7 @@ import ( "go_dreamfactory/modules/user" "go_dreamfactory/modules/viking" "go_dreamfactory/modules/worldtask" + "go_dreamfactory/modules/wtask" "go_dreamfactory/services" "go_dreamfactory/sys/db" "go_dreamfactory/sys/wordfilter" @@ -126,6 +127,7 @@ func main() { buried.NewModule(), activity.NewModule(), guidance.NewModule(), + wtask.NewModule(), ) }