diff --git a/modules/dispatch/api_refresh.go b/modules/dispatch/api_refresh.go index 76cd6c367..d7561cc34 100644 --- a/modules/dispatch/api_refresh.go +++ b/modules/dispatch/api_refresh.go @@ -9,14 +9,17 @@ import ( ) // 刷新 -func (a *apiComp) RefreshCheck(session comm.IUserSession, req *pb.DispatchRefreshReq) (errdata *pb.ErrorData) { +func (this *apiComp) RefreshCheck(session comm.IUserSession, req *pb.DispatchRefreshReq) (errdata *pb.ErrorData) { return } -func (a *apiComp) Refresh(session comm.IUserSession, req *pb.DispatchRefreshReq) (errdata *pb.ErrorData) { - - d := a.module.modelDispatch.getDBDispatch(session.GetUserId()) - if d == nil { +func (this *apiComp) Refresh(session comm.IUserSession, req *pb.DispatchRefreshReq) (errdata *pb.ErrorData) { + var ( + info *pb.DBDispatch + need []*cfg.Gameatn + ) + info = this.module.modelDispatch.getDBDispatch(session.GetUserId()) + if info == nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_DataNotFound, Title: pb.ErrorCode_DataNotFound.ToString(), @@ -24,10 +27,10 @@ func (a *apiComp) Refresh(session comm.IUserSession, req *pb.DispatchRefreshReq) return } - if d.Nb != nil { - if d.Nb.FreeCount > 0 { + if info.Nb != nil { + if info.Nb.FreeCount > 0 { //更新刷新次数 - if err := a.module.modelDispatch.updateFreeCount(session.GetUserId(), d.Nb); err != nil { + if err := this.module.modelDispatch.updateFreeCount(session.GetUserId(), info.Nb); err != nil { var customer = new(comm.CustomError) var code pb.ErrorCode if errors.As(err, &customer) { @@ -47,24 +50,28 @@ func (a *apiComp) Refresh(session comm.IUserSession, req *pb.DispatchRefreshReq) return } } else { - refreshCount := a.module.ModuleTools.GetGlobalConf().DispatchRefreshtimes - if d.Nb.RefreshCount >= refreshCount { + refreshCount := this.module.ModuleTools.GetGlobalConf().DispatchRefreshtimes + if info.Nb.RefreshCount >= refreshCount { errdata = &pb.ErrorData{ - Code: pb.ErrorCode_DispatchRefreshMax, - Title: pb.ErrorCode_DispatchRefreshMax.ToString(), + Code: pb.ErrorCode_DispatchRefreshMax, + Title: pb.ErrorCode_DispatchRefreshMax.ToString(), } return } - //消耗金币 - money := a.module.ModuleTools.GetGlobalConf().DispatchCheckmoney - if errdata = a.module.CheckRes(session, []*cfg.Gameatn{money}); errdata != nil { - return - } + need = make([]*cfg.Gameatn, 0) + money := this.module.ModuleTools.GetGlobalConf().DispatchCheckmoney - if errdata = a.module.ConsumeRes(session, []*cfg.Gameatn{money}, true); errdata != nil { + need = append(need, &cfg.Gameatn{ + A: money.A, + T: money.T, + N: money.N * (info.Nb.RefreshCount + 1), + }) + //消耗金币 + + if errdata = this.module.ConsumeRes(session, need, true); errdata != nil { return } - if err := a.module.modelDispatch.updateRefreshCount(session.GetUserId(), d.Nb); err != nil { + if err := this.module.modelDispatch.updateRefreshCount(session.GetUserId(), info.Nb); err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_DBError, Title: pb.ErrorCode_DBError.ToString(), @@ -76,22 +83,22 @@ func (a *apiComp) Refresh(session comm.IUserSession, req *pb.DispatchRefreshReq) } //刷新公告(随机新的任务 包括未领取和正在进行的任务) - tasks, err := a.module.modelDispatch.taskRandom(session.GetUserId(), d) + tasks, err := this.module.modelDispatch.taskRandom(session.GetUserId(), info) if err != nil { return } //更新公告任务 - if err := a.module.modelDispatch.updateTasks(session.GetUserId(), d.Nb, tasks); err != nil { - a.module.Debug("更新公告失败", log.Field{Key: "uid", Value: session.GetUserId()}) + if err := this.module.modelDispatch.updateTasks(session.GetUserId(), info.Nb, tasks); err != nil { + this.module.Debug("更新公告失败", log.Field{Key: "uid", Value: session.GetUserId()}) return } rsp := &pb.DispatchRefreshResp{ - FreeCount: d.Nb.FreeCount, - RefreshCount: d.Nb.RefreshCount, + FreeCount: info.Nb.FreeCount, + RefreshCount: info.Nb.RefreshCount, } - session.SendMsg(string(a.module.GetType()), "refresh", rsp) + session.SendMsg(string(this.module.GetType()), "refresh", rsp) return } diff --git a/modules/uniongve/api_challengefinish.go b/modules/uniongve/api_challengefinish.go index 40d5dd697..6b062d2b6 100644 --- a/modules/uniongve/api_challengefinish.go +++ b/modules/uniongve/api_challengefinish.go @@ -1,8 +1,11 @@ package uniongve import ( + "fmt" "go_dreamfactory/comm" + "go_dreamfactory/lego/sys/log" "go_dreamfactory/pb" + cfg "go_dreamfactory/sys/configure/structs" ) // 参数校验 @@ -13,14 +16,91 @@ func (this *apiComp) ChallengeFinishCheck(session comm.IUserSession, req *pb.Uni // 获取工会boos战信息 func (this *apiComp) ChallengeFinish(session comm.IUserSession, req *pb.UniongveChallengeFinishRep) (errdata *pb.ErrorData) { - + var ( + conf *cfg.GameGuildBossData + score *cfg.GameGuildBossScoreData + info *pb.DBUnionGve + prop []*cfg.Gameatn + ok bool + err error + ) if errdata = this.ChallengeFinishCheck(session, req); errdata != nil { return } - if errdata, _ = this.module.battle.CheckBattleReport(session, req.Report); errdata != nil { + + if conf, err = this.module.configure.getguildbossByid(req.Boosid); err != nil { + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_ConfigNoFound, + Title: pb.ErrorCode_ConfigNoFound.ToString(), + Message: err.Error(), + } return } + if errdata, _ = this.module.battle.CheckBattleReport(session, req.Report); errdata != nil { + return + } + if score, err = this.module.configure.getguildbossscore(conf.Group, req.Report.Harm); err != nil { + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_ConfigNoFound, + Title: pb.ErrorCode_ConfigNoFound.ToString(), + Message: err.Error(), + } + } + + if errdata = this.module.DispenseRes(session, prop, true); errdata != nil { + return + } + + lock, _ := this.module.modelUniongve.userlock(req.Unionid) + err = lock.Lock() + if err != nil { + this.module.Error("公会战分布式锁 err!", log.Field{Key: "Unionid", Value: req.Unionid}, log.Field{Key: "err", Value: err.Error()}) + return + } + defer lock.Unlock() + if info, err = this.module.modelUniongve.getUnionGve(req.Unionid); err != nil { + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_DBError, + Title: pb.ErrorCode_DBError.ToString(), + Message: err.Error(), + } + return + } + + for _, v := range info.Boos { + if v.Boosid == req.Boosid { + if v.Hp > 0 { + ok = true + v.Hp -= score.Hp + if v.Hp < 0 { + v.Hp = 0 + this.module.modelUniongve.booskill(req.Unionid, req.Boosid, info) + } + } + break + } + } + + if ok { + user := this.module.ModuleUser.GetUser(session.GetUserId()) + if prop = this.module.ModuleTools.GetGroupDataByLottery(score.Drop, user.Vip, user.Lv); len(prop) == 0 { + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_ConfigNoFound, + Title: pb.ErrorCode_ConfigNoFound.ToString(), + Message: fmt.Sprintf("掉落组未找到:%d", score.Drop), + } + return + } + } + if err = this.module.modelUniongve.updateUnionGve(info); err != nil { + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_DBError, + Title: pb.ErrorCode_DBError.ToString(), + Message: err.Error(), + } + return + } session.SendMsg(string(this.module.GetType()), "challengefinish", &pb.UniongveChallengeFinishResp{}) return } diff --git a/modules/uniongve/comp_configure.go b/modules/uniongve/comp_configure.go index 94f26f32a..2815e2b32 100644 --- a/modules/uniongve/comp_configure.go +++ b/modules/uniongve/comp_configure.go @@ -77,3 +77,24 @@ func (this *MCompConfigure) getguildbossByid(id int32) (results *cfg.GameGuildBo } return } + +// 获取伤害对应的评分组 +func (this *MCompConfigure) getguildbossscore(group int32, harm int32) (results *cfg.GameGuildBossScoreData, err error) { + var ( + v interface{} + ) + + if v, err = this.GetConfigure(game_guildbossscore); err != nil { + return + } else { + for _, v := range v.(*cfg.GameGuildBossScore).GetDataList() { + if harm >= v.RankLow && (harm <= v.RankUp || v.RankUp == -1) { + results = v + return + } + } + err = comm.NewNotFoundConfErr(string(this.module.GetType()), game_guildbossscore, fmt.Sprintf("group:%d harm%d", group, harm)) + this.module.Errorf("err:%v", err) + } + return +} diff --git a/modules/uniongve/modelUniongve.go b/modules/uniongve/modelUniongve.go index 394604d37..efd6e7585 100644 --- a/modules/uniongve/modelUniongve.go +++ b/modules/uniongve/modelUniongve.go @@ -5,6 +5,7 @@ import ( "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/lego/sys/event" + "go_dreamfactory/lego/sys/log" "go_dreamfactory/lego/sys/mgo" "go_dreamfactory/lego/sys/redis" "go_dreamfactory/modules" @@ -76,6 +77,20 @@ func (this *ModelUniongve) getUnionGve(unionid string) (results *pb.DBUnionGve, return } +func (this *ModelUniongve) updateUnionGve(data *pb.DBUnionGve) (err error) { + if err = this.Change(data.Unionid, map[string]interface{}{ + "fire": data.Fire, + "notice": data.Notice, + "currstage": data.Currstage, + "rtime": data.Rtime, + "boos": data.Boos, + }); err != nil { + this.module.Error("更新用户任务数据 错误!", log.Field{Key: "err", Value: err.Error()}) + return + } + return +} + // 刷新全局配置 func (this *ModelUniongve) loadGlobalBoos() (err error) { var ( @@ -144,3 +159,8 @@ func (this *ModelUniongve) refreshGlobalBoos() (conf *pb.DBUnionGveBossConf, err func (this *ModelUniongve) userlock(id string) (result *redis.RedisMutex, err error) { return this.DBModel.Redis.NewRedisMutex(fmt.Sprintf("uniongve:%s", id)) } + +// 击杀boos +func (this *ModelUniongve) booskill(unionid string, boosid int32, info *pb.DBUnionGve) { + +} diff --git a/pb/uniongve_msg.pb.go b/pb/uniongve_msg.pb.go index e05f50fb6..1dc3d0f8b 100644 --- a/pb/uniongve_msg.pb.go +++ b/pb/uniongve_msg.pb.go @@ -663,9 +663,10 @@ type UniongveChallengeFinishResp struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Unionid string `protobuf:"bytes,1,opt,name=unionid,proto3" json:"unionid"` - Boosid int32 `protobuf:"varint,2,opt,name=boosid,proto3" json:"boosid"` - Award []*UserAssets `protobuf:"bytes,3,rep,name=award,proto3" json:"award"` //奖励 + Unionid string `protobuf:"bytes,1,opt,name=unionid,proto3" json:"unionid"` + Boosid int32 `protobuf:"varint,2,opt,name=boosid,proto3" json:"boosid"` + Award []*UserAssets `protobuf:"bytes,3,rep,name=award,proto3" json:"award"` //奖励 + Efficient bool `protobuf:"varint,4,opt,name=efficient,proto3" json:"efficient"` //是否有效 } func (x *UniongveChallengeFinishResp) Reset() { @@ -721,6 +722,13 @@ func (x *UniongveChallengeFinishResp) GetAward() []*UserAssets { return nil } +func (x *UniongveChallengeFinishResp) GetEfficient() bool { + if x != nil { + return x.Efficient + } + return false +} + //工会战 信息变化 type UniongveInfoChangePush struct { state protoimpl.MessageState @@ -964,29 +972,30 @@ var file_uniongve_uniongve_msg_proto_rawDesc = []byte{ 0x0a, 0x06, 0x62, 0x6f, 0x6f, 0x73, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x62, 0x6f, 0x6f, 0x73, 0x69, 0x64, 0x12, 0x25, 0x0a, 0x06, 0x72, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0d, 0x2e, 0x42, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x52, - 0x65, 0x70, 0x6f, 0x72, 0x74, 0x52, 0x06, 0x72, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x22, 0x72, 0x0a, - 0x1b, 0x55, 0x6e, 0x69, 0x6f, 0x6e, 0x67, 0x76, 0x65, 0x43, 0x68, 0x61, 0x6c, 0x6c, 0x65, 0x6e, - 0x67, 0x65, 0x46, 0x69, 0x6e, 0x69, 0x73, 0x68, 0x52, 0x65, 0x73, 0x70, 0x12, 0x18, 0x0a, 0x07, - 0x75, 0x6e, 0x69, 0x6f, 0x6e, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x75, - 0x6e, 0x69, 0x6f, 0x6e, 0x69, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x62, 0x6f, 0x6f, 0x73, 0x69, 0x64, - 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x62, 0x6f, 0x6f, 0x73, 0x69, 0x64, 0x12, 0x21, - 0x0a, 0x05, 0x61, 0x77, 0x61, 0x72, 0x64, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0b, 0x2e, - 0x55, 0x73, 0x65, 0x72, 0x41, 0x73, 0x73, 0x65, 0x74, 0x73, 0x52, 0x05, 0x61, 0x77, 0x61, 0x72, - 0x64, 0x22, 0x39, 0x0a, 0x16, 0x55, 0x6e, 0x69, 0x6f, 0x6e, 0x67, 0x76, 0x65, 0x49, 0x6e, 0x66, - 0x6f, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x75, 0x73, 0x68, 0x12, 0x1f, 0x0a, 0x04, 0x69, - 0x6e, 0x66, 0x6f, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x44, 0x42, 0x55, 0x6e, - 0x69, 0x6f, 0x6e, 0x47, 0x76, 0x65, 0x52, 0x04, 0x69, 0x6e, 0x66, 0x6f, 0x22, 0x3a, 0x0a, 0x17, - 0x55, 0x6e, 0x69, 0x6f, 0x6e, 0x67, 0x76, 0x65, 0x53, 0x74, 0x61, 0x67, 0x65, 0x43, 0x68, 0x61, - 0x6e, 0x67, 0x65, 0x50, 0x75, 0x73, 0x68, 0x12, 0x1f, 0x0a, 0x04, 0x69, 0x6e, 0x66, 0x6f, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x44, 0x42, 0x55, 0x6e, 0x69, 0x6f, 0x6e, 0x47, - 0x76, 0x65, 0x52, 0x04, 0x69, 0x6e, 0x66, 0x6f, 0x22, 0x39, 0x0a, 0x16, 0x55, 0x6e, 0x69, 0x6f, - 0x6e, 0x67, 0x76, 0x65, 0x42, 0x6f, 0x6f, 0x73, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x75, - 0x73, 0x68, 0x12, 0x1f, 0x0a, 0x04, 0x69, 0x6e, 0x66, 0x6f, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, - 0x32, 0x0b, 0x2e, 0x44, 0x42, 0x55, 0x6e, 0x69, 0x6f, 0x6e, 0x47, 0x76, 0x65, 0x52, 0x04, 0x69, - 0x6e, 0x66, 0x6f, 0x22, 0x1c, 0x0a, 0x1a, 0x55, 0x6e, 0x69, 0x6f, 0x6e, 0x67, 0x76, 0x65, 0x52, - 0x6f, 0x75, 0x6c, 0x65, 0x74, 0x74, 0x65, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x75, 0x73, - 0x68, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x33, + 0x65, 0x70, 0x6f, 0x72, 0x74, 0x52, 0x06, 0x72, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x22, 0x90, 0x01, + 0x0a, 0x1b, 0x55, 0x6e, 0x69, 0x6f, 0x6e, 0x67, 0x76, 0x65, 0x43, 0x68, 0x61, 0x6c, 0x6c, 0x65, + 0x6e, 0x67, 0x65, 0x46, 0x69, 0x6e, 0x69, 0x73, 0x68, 0x52, 0x65, 0x73, 0x70, 0x12, 0x18, 0x0a, + 0x07, 0x75, 0x6e, 0x69, 0x6f, 0x6e, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, + 0x75, 0x6e, 0x69, 0x6f, 0x6e, 0x69, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x62, 0x6f, 0x6f, 0x73, 0x69, + 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x62, 0x6f, 0x6f, 0x73, 0x69, 0x64, 0x12, + 0x21, 0x0a, 0x05, 0x61, 0x77, 0x61, 0x72, 0x64, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0b, + 0x2e, 0x55, 0x73, 0x65, 0x72, 0x41, 0x73, 0x73, 0x65, 0x74, 0x73, 0x52, 0x05, 0x61, 0x77, 0x61, + 0x72, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x65, 0x66, 0x66, 0x69, 0x63, 0x69, 0x65, 0x6e, 0x74, 0x18, + 0x04, 0x20, 0x01, 0x28, 0x08, 0x52, 0x09, 0x65, 0x66, 0x66, 0x69, 0x63, 0x69, 0x65, 0x6e, 0x74, + 0x22, 0x39, 0x0a, 0x16, 0x55, 0x6e, 0x69, 0x6f, 0x6e, 0x67, 0x76, 0x65, 0x49, 0x6e, 0x66, 0x6f, + 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x75, 0x73, 0x68, 0x12, 0x1f, 0x0a, 0x04, 0x69, 0x6e, + 0x66, 0x6f, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x44, 0x42, 0x55, 0x6e, 0x69, + 0x6f, 0x6e, 0x47, 0x76, 0x65, 0x52, 0x04, 0x69, 0x6e, 0x66, 0x6f, 0x22, 0x3a, 0x0a, 0x17, 0x55, + 0x6e, 0x69, 0x6f, 0x6e, 0x67, 0x76, 0x65, 0x53, 0x74, 0x61, 0x67, 0x65, 0x43, 0x68, 0x61, 0x6e, + 0x67, 0x65, 0x50, 0x75, 0x73, 0x68, 0x12, 0x1f, 0x0a, 0x04, 0x69, 0x6e, 0x66, 0x6f, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x44, 0x42, 0x55, 0x6e, 0x69, 0x6f, 0x6e, 0x47, 0x76, + 0x65, 0x52, 0x04, 0x69, 0x6e, 0x66, 0x6f, 0x22, 0x39, 0x0a, 0x16, 0x55, 0x6e, 0x69, 0x6f, 0x6e, + 0x67, 0x76, 0x65, 0x42, 0x6f, 0x6f, 0x73, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x75, 0x73, + 0x68, 0x12, 0x1f, 0x0a, 0x04, 0x69, 0x6e, 0x66, 0x6f, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, + 0x0b, 0x2e, 0x44, 0x42, 0x55, 0x6e, 0x69, 0x6f, 0x6e, 0x47, 0x76, 0x65, 0x52, 0x04, 0x69, 0x6e, + 0x66, 0x6f, 0x22, 0x1c, 0x0a, 0x1a, 0x55, 0x6e, 0x69, 0x6f, 0x6e, 0x67, 0x76, 0x65, 0x52, 0x6f, + 0x75, 0x6c, 0x65, 0x74, 0x74, 0x65, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x75, 0x73, 0x68, + 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var (