From 67cce21c5e8250c471fc6e37e291e3c1ec3f1cd1 Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Mon, 30 Oct 2023 15:58:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E5=A4=B4=E5=83=8F=E6=A1=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/island/api_Info.go | 22 ++++- modules/island/api_battle.go | 76 +++++++++++++++ modules/island/api_complete.go | 155 +++++++++++++++++++++++++++++++ modules/island/modelhero.go | 11 +-- modules/island/module.go | 17 +++- modules/user/api_switchdefper.go | 13 ++- 6 files changed, 277 insertions(+), 17 deletions(-) create mode 100644 modules/island/api_battle.go create mode 100644 modules/island/api_complete.go diff --git a/modules/island/api_Info.go b/modules/island/api_Info.go index 26a36c47b..2e80dba47 100644 --- a/modules/island/api_Info.go +++ b/modules/island/api_Info.go @@ -13,11 +13,29 @@ func (this *apiComp) InfoCheck(session comm.IUserSession, req *pb.IsLandInfoReq) // /获取自己的排行榜信息 func (this *apiComp) Info(session comm.IUserSession, req *pb.IsLandInfoReq) (errdata *pb.ErrorData) { - var () + var ( + info *pb.DBIsland + heros []*pb.DBHero + err error + ) if errdata = this.InfoCheck(session, req); errdata != nil { return } - session.SendMsg(string(this.module.GetType()), "info", &pb.IsLandInfoResp{}) + if info, err = this.module.model.getmodel(session.GetUserId()); err != nil { + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_DBError, + Message: err.Error(), + } + return + } + if heros, err = this.module.modelhero.getHeroList(session.GetUserId()); err != nil { + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_DBError, + Message: err.Error(), + } + return + } + session.SendMsg(string(this.module.GetType()), "info", &pb.IsLandInfoResp{Info: info, Heros: heros}) return } diff --git a/modules/island/api_battle.go b/modules/island/api_battle.go new file mode 100644 index 000000000..8df5ac3e6 --- /dev/null +++ b/modules/island/api_battle.go @@ -0,0 +1,76 @@ +package island + +import ( + "go_dreamfactory/comm" + "go_dreamfactory/lego/sys/log" + "go_dreamfactory/pb" + cfg "go_dreamfactory/sys/configure/structs" +) + +// 参数校验 +func (this *apiComp) BattleCheck(session comm.IUserSession, req *pb.IsLandBattleReq) (errdata *pb.ErrorData) { + if req.Level == 0 || req.Battle == nil { + this.module.Error("战斗开始参数错误", + log.Field{Key: "uid", Value: session.GetUserId()}, + log.Field{Key: "params", Value: req.String()}, + ) + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_ReqParameterError, + Title: pb.ErrorCode_ReqParameterError.ToString(), + Message: "BattleConfId is 0", + } + } + return +} + +// /获取系统公告 +func (this *apiComp) Battle(session comm.IUserSession, req *pb.IsLandBattleReq) (errdata *pb.ErrorData) { + var ( + conf *cfg.GameHeroupstoryChapterData + bconf *cfg.GameHeroupstoryBattleData + record *pb.DBBattleRecord + err error + ) + if errdata = this.BattleCheck(session, req); errdata != nil { + return + } + if conf, err = this.module.configure.getGameHeroupstoryChapter(req.Level); err != nil { + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_DBError, + Title: pb.ErrorCode_DBError.ToString(), + Message: err.Error(), + } + return + } + if bconf, err = this.module.configure.getGameHeroupstoryBattle(conf.Battle); err != nil { + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_DBError, + Title: pb.ErrorCode_DBError.ToString(), + Message: err.Error(), + } + return + } + if errdata, record = this.module.battle.CreatePveBattle(session, &pb.BattlePVEReq{ + Rulesid: bconf.BattleReadyID, + Ptype: pb.PlayType_rtask, + Format: req.Battle, + Mformat: bconf.FormatList, + }); err != nil { + return + } + session.SendMsg(string(this.module.GetType()), "battle", &pb.StorylineBattleResp{ + Level: req.Level, + Info: &pb.BattleInfo{ + Id: record.Id, + Rulesid: bconf.BattleReadyID, + Btype: record.Btype, + Ptype: record.Ptype, + RedCompId: record.RedCompId, + Redflist: record.Redflist, + BlueCompId: record.BlueCompId, + Buleflist: record.Buleflist, + Tasks: record.Tasks, + }, + }) + return +} diff --git a/modules/island/api_complete.go b/modules/island/api_complete.go new file mode 100644 index 000000000..7ab386d0a --- /dev/null +++ b/modules/island/api_complete.go @@ -0,0 +1,155 @@ +package island + +import ( + "fmt" + "go_dreamfactory/comm" + "go_dreamfactory/pb" + "go_dreamfactory/sys/configure" +) + +// 参数校验 +func (this *apiComp) CompleteCheck(session comm.IUserSession, req *pb.IsLandCompleteReq) (errdata *pb.ErrorData) { + + return +} + +// /获取自己的排行榜信息 +func (this *apiComp) Complete(session comm.IUserSession, req *pb.IsLandCompleteReq) (errdata *pb.ErrorData) { + var ( + info *pb.DBIsland + item *pb.DBIslandItem + award []*pb.UserAtno + ok bool + iswin bool + isfish bool + err error + ) + if errdata = this.CompleteCheck(session, req); errdata != nil { + return + } + + if conf, err = this.module.configure.getGameHeroupstoryChapter(req.Level); err != nil { + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_DBError, + Title: pb.ErrorCode_DBError.ToString(), + Message: err.Error(), + } + return + } + + if info, err = this.module.model.getmodel(session.GetUserId()); err != nil { + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_DBError, + Title: pb.ErrorCode_DBError.ToString(), + Message: err.Error(), + } + return + } + + if item, ok = info.Item[conf.Hero]; !ok { + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_ReqParameterError, + Title: pb.ErrorCode_ReqParameterError.ToString(), + Message: fmt.Sprintf("no activation hero:%d", conf.Hero), + } + return + } + //前置判断 + if conf.Onlevel != 0 && item.Level[conf.Onlevel] == 0 { + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_ReqParameterError, + Title: pb.ErrorCode_ReqParameterError.ToString(), + Message: fmt.Sprintf("%d onlevel no Complete", req.Level), + } + return + } + + //前置判断 + if len(conf.Onlevelstory) == 2 && item.Level[conf.Onlevelstory[0]] == conf.Onlevelstory[1] { + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_ReqParameterError, + Title: pb.ErrorCode_ReqParameterError.ToString(), + Message: fmt.Sprintf("%d onlevel no Complete", req.Level), + } + return + } + + if conf.Leveltype != 1 && item.Level[req.Level] != 0 { + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_ReqParameterError, + Title: pb.ErrorCode_ReqParameterError.ToString(), + Message: fmt.Sprintf("%d received", req.Level), + } + return + } + + if item.Level[req.Level] != 0 { + isfish = true + } + + if chapterconf, err = this.module.configure.getGameHeroupstoryChaptertxt(conf.Chapter); err != nil { + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_ConfigNoFound, + Title: pb.ErrorCode_ConfigNoFound.ToString(), + Message: err.Error(), + } + return + } + + if conf.Leveltype == 1 { //剧情关卡 + item.Level[req.Level] = req.Story + } else if conf.Leveltype == 2 { //战斗管卡 + if errdata, iswin = this.module.battle.CheckBattleReport(session, req.Report); errdata != nil { + return + } + if !iswin { + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_ReqParameterError, + Title: pb.ErrorCode_ReqParameterError.ToString(), + Message: "battle no win!", + } + return + } + item.Level[req.Level] = 1 + } else if conf.Leveltype == 4 { + item.Level[req.Level] = 1 + item.Chapter[conf.Chapter] = configure.Now().Unix() + } else if conf.Leveltype == 5 { + if req.Report != nil { + if errdata, iswin = this.module.battle.CheckBattleReport(session, req.Report); errdata != nil { + return + } + if !iswin { + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_ReqParameterError, + Title: pb.ErrorCode_ReqParameterError.ToString(), + Message: "battle no win!", + } + return + } + } + item.Level[req.Level] = 1 + } else { + item.Level[req.Level] = 1 + } + + if !isfish { + if errdata = this.module.DispenseRes(session, conf.Reward, true); errdata != nil { + return + } + award = make([]*pb.UserAssets, 0) + for _, v := range conf.Reward { + award = append(award, &pb.UserAssets{ + A: v.A, + T: v.T, + N: v.N, + }) + } + } + + this.module.model.Change(session.GetUserId(), map[string]interface{}{ + "islands": info.Islands, + }) + session.SendMsg(string(this.module.GetType()), "complete", &pb.StorylineCompleteResp{Level: req.Level, Story: req.Story, Award: award}) + return +} diff --git a/modules/island/modelhero.go b/modules/island/modelhero.go index 69de240af..1d09ff6d2 100644 --- a/modules/island/modelhero.go +++ b/modules/island/modelhero.go @@ -27,11 +27,8 @@ func (this *modelHeroComp) Init(service core.IService, module core.IModule, comp // 读取数据 // 获取玩家的英雄列表 -func (this *modelHeroComp) getHeroList(uid string) []*pb.DBHero { - heroes := make([]*pb.DBHero, 0) - err := this.GetList(uid, &heroes) - if err != nil { - return nil - } - return heroes +func (this *modelHeroComp) getHeroList(uid string) (heros []*pb.DBHero, err error) { + heros = make([]*pb.DBHero, 0) + err = this.GetList(uid, &heros) + return } diff --git a/modules/island/module.go b/modules/island/module.go index 3509f2a15..cba5fc0f8 100644 --- a/modules/island/module.go +++ b/modules/island/module.go @@ -20,9 +20,10 @@ func NewModule() core.IModule { type IsLand struct { modules.ModuleBase service base.IRPCXService - privilege comm.IPrivilege + battle comm.IBattle api *apiComp model *modelComp + modelhero *modelHeroComp configure *ConfigureComp } @@ -42,4 +43,18 @@ func (this *IsLand) OnInstallComp() { this.ModuleBase.OnInstallComp() this.api = this.RegisterComp(new(apiComp)).(*apiComp) this.model = this.RegisterComp(new(modelComp)).(*modelComp) + this.modelhero = this.RegisterComp(new(modelHeroComp)).(*modelHeroComp) + this.configure = this.RegisterComp(new(ConfigureComp)).(*ConfigureComp) +} + +func (this *IsLand) Start() (err error) { + if err = this.ModuleBase.Start(); err != nil { + return + } + var module core.IModule + if module, err = this.service.GetModule(comm.ModuleBattle); err != nil { + return + } + this.battle = module.(comm.IBattle) + return } diff --git a/modules/user/api_switchdefper.go b/modules/user/api_switchdefper.go index 3d22f9bf7..59ca74c4c 100644 --- a/modules/user/api_switchdefper.go +++ b/modules/user/api_switchdefper.go @@ -97,10 +97,9 @@ func (this *apiComp) SwitchDefPer(session comm.IUserSession, req *pb.UserSwitchD } return } - user.CurAction = req.CurAction - change["curAction"] = req.CurAction } - + user.CurAction = req.CurAction + change["curAction"] = req.CurAction if req.CurBg != "" { if conf, err = this.module.configure.GetPlayerOverview(req.CurBg, user.Gender); err != nil { errdata = &pb.ErrorData{ @@ -129,9 +128,9 @@ func (this *apiComp) SwitchDefPer(session comm.IUserSession, req *pb.UserSwitchD } return } - user.CurBg = req.CurBg - change["curBg"] = req.CurBg } + user.CurBg = req.CurBg + change["curBg"] = req.CurBg if req.CurAframe != "" { if conf, err = this.module.configure.GetPlayerOverview(req.CurAframe, 0); err != nil { errdata = &pb.ErrorData{ @@ -160,9 +159,9 @@ func (this *apiComp) SwitchDefPer(session comm.IUserSession, req *pb.UserSwitchD } return } - user.Curaframe = req.CurAframe - change["curaframe"] = req.CurAframe } + user.Curaframe = req.CurAframe + change["curaframe"] = req.CurAframe if err = this.module.modelUser.Change(session.GetUserId(), change); err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_DBError,