From 5d0e95b6278af68fef1178c3a05760dfdbf15d8a Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Sun, 9 Oct 2022 18:33:45 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8B=B1=E9=9B=84=E7=BE=81=E7=BB=8A=E9=A2=86?= =?UTF-8?q?=E5=A5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- comm/imodule.go | 6 +-- modules/hero/api_drawCard.go | 2 +- modules/hero/module.go | 9 ++-- modules/library/api_getstoryreward.go | 54 +++++++++++++++-------- modules/library/module.go | 62 ++++++++++++++++++++++----- pb/library_db.pb.go | 18 ++++---- pb/library_msg.pb.go | 34 +++++++++------ 7 files changed, 128 insertions(+), 57 deletions(-) diff --git a/comm/imodule.go b/comm/imodule.go index d3536e89a..c2d66dc08 100644 --- a/comm/imodule.go +++ b/comm/imodule.go @@ -170,8 +170,8 @@ type ( IHeroFetter interface { ModifyHeroFetterData(uid string, obj string, data map[string]interface{}) (code pb.ErrorCode) // 修改羁绊信息 - QueryHeroFetter(session IUserSession) (data []*pb.DBHeroFetter) // 查询所有的羁绊信息 - QueryOneHeroFetter(session IUserSession, cid string) *pb.DBHeroFetter // 通过英雄配置id 查询羁绊信息 - AddHeroFetterData(session IUserSession, heroConfId string) // 创建一条羁绊信息 + QueryHeroFetter(uid string) (data []*pb.DBHeroFetter) // 查询所有的羁绊信息 + QueryOneHeroFetter(uid string, cid string) *pb.DBHeroFetter // 通过英雄配置id 查询羁绊信息 + AddHeroFetterData(uid string, heroConfId string) // 创建一条羁绊信息 } ) diff --git a/modules/hero/api_drawCard.go b/modules/hero/api_drawCard.go index d6a737aef..040053c54 100644 --- a/modules/hero/api_drawCard.go +++ b/modules/hero/api_drawCard.go @@ -225,7 +225,7 @@ func (this *apiComp) DrawCard(session comm.IUserSession, req *pb.HeroDrawCardReq for _, star := range szStar { sz[star]++ } - for k, _ := range sz { + for k := range sz { this.module.ModuleRtask.SendToRtask(session, comm.Rtype17, 1, k) } } diff --git a/modules/hero/module.go b/modules/hero/module.go index b74f4976d..d0f25d27f 100644 --- a/modules/hero/module.go +++ b/modules/hero/module.go @@ -69,10 +69,10 @@ func (this *Hero) CreateRepeatHero(session comm.IUserSession, heroCfgId string, if err == nil { go func(uid string, heroCfgId string) { // 携程处理 图鉴数据 - _data := this.moduleFetter.QueryOneHeroFetter(session, heroCfgId) // 查询获得英雄是否存在羁绊信息 + _data := this.moduleFetter.QueryOneHeroFetter(uid, heroCfgId) // 查询获得英雄是否存在羁绊信息 this.Debugf("%v", _data) if _data == nil { - this.moduleFetter.AddHeroFetterData(session, heroCfgId) // 创建一个新的羁绊数据 + this.moduleFetter.AddHeroFetterData(uid, heroCfgId) // 创建一个新的羁绊数据 } if result, err1 := this.ModuleUser.GetUserExpand(uid); err1 == nil { @@ -272,10 +272,11 @@ func (this *Hero) CreateRepeatHeros(session comm.IUserSession, heros map[string] sz = make(map[string]int32, 0) } for k := range heros { - _data := this.moduleFetter.QueryOneHeroFetter(session, k) // 查询获得英雄是否存在羁绊信息 + _data := this.moduleFetter.QueryOneHeroFetter(uid, k) // 查询获得英雄是否存在羁绊信息 this.Debugf("%v", _data) if _data == nil { - this.moduleFetter.AddHeroFetterData(session, k) // 创建一个新的羁绊数据 + this.moduleFetter.AddHeroFetterData(uid, k) // 创建一个新的羁绊数据 + // 写羁绊数据 } if _, ok := result.GetTujian()[k]; !ok { diff --git a/modules/library/api_getstoryreward.go b/modules/library/api_getstoryreward.go index 21ec7d4eb..1663bbac1 100644 --- a/modules/library/api_getstoryreward.go +++ b/modules/library/api_getstoryreward.go @@ -7,13 +7,15 @@ package library import ( "go_dreamfactory/comm" "go_dreamfactory/pb" + "go_dreamfactory/utils" + "strconv" "google.golang.org/protobuf/proto" ) //参数校验 func (this *apiComp) GetStoryRewardCheck(session comm.IUserSession, req *pb.LibraryGetStoryRewardReq) (code pb.ErrorCode) { - if req.Hid == "" || req.StoryId == 0 { + if req.Hid == "" { code = pb.ErrorCode_ReqParameterError } return @@ -25,28 +27,46 @@ func (this *apiComp) GetStoryReward(session comm.IUserSession, req *pb.LibraryGe if code != pb.ErrorCode_Success { return // 参数校验失败直接返回 } - expand, err := this.module.ModuleUser.GetUserExpand(session.GetUserId()) - if err != nil { - code = pb.ErrorCode_DBError + _heroFetter := this.module.modelFetter.getOneHeroFetter(session.GetUserId(), req.Hid) + if _heroFetter == nil { + code = pb.ErrorCode_ReqParameterError return } conf := this.module.configure.GetLibraryHero(req.Hid) - for k, v := range expand.Tujian { - if k == req.Hid && conf.Rightend == v { - code = this.module.DispenseRes(session, conf.Stroyprize, true) - // 修改storyID - - sz := make(map[string]interface{}, 0) - for k, v := range expand.Tujian { - sz[k] = v + if req.History != 0 { + for index, v := range conf.History { + if utils.ToInt32(v) == req.History && conf.Favorlv[index] >= _heroFetter.Favorlv { + for _, v1 := range _heroFetter.History { + if v1 == req.History { + code = pb.ErrorCode_ReqParameterError + return + } + } } - sz[req.Hid] = conf.Rightend - - this.module.ModuleUser.ChangeUserExpand(session.GetUserId(), sz) - - break + _heroFetter.History = append(_heroFetter.History, req.History) + // 发奖 + historyConf := this.configure.GetLibraryHistory(strconv.Itoa(int(req.History))) + if historyConf != nil { + this.module.DispenseRes(session, historyConf.Prize, true) + } + mapData := make(map[string]interface{}, 0) + mapData["history"] = _heroFetter.History + this.module.modelFetter.modifyHeroFetterDataByObjId(session.GetUserId(), _heroFetter.Id, mapData) + } + } else if req.Rightend != 0 { // 剧情奖励 + if req.Rightend == conf.Rightend && _heroFetter.Stroyprize != conf.Rightend { + _heroFetter.Stroyprize = conf.Rightend + // 发奖 + code = this.module.DispenseRes(session, conf.Stroyprize, true) + if code != pb.ErrorCode_Success { + this.module.Errorf("GetStoryReward err:add item : %v", conf.Stroyprize) + } + mapData := make(map[string]interface{}, 0) + mapData["stroyprize"] = _heroFetter.Stroyprize + this.module.modelFetter.modifyHeroFetterDataByObjId(session.GetUserId(), _heroFetter.Id, mapData) } } + return } diff --git a/modules/library/module.go b/modules/library/module.go index d7be329c3..c6039e0c8 100644 --- a/modules/library/module.go +++ b/modules/library/module.go @@ -54,6 +54,17 @@ func (this *Library) GetLibraryList(uid string) []*pb.DBLibrary { return this.modelLibrary.getLibraryList(uid) } +// 通过羁绊id 来查询羁绊信息 +func (this *Library) GetLibraryListByFid(uid string, fid int32) *pb.DBLibrary { + list := this.modelLibrary.getLibraryList(uid) + for _, v := range list { + if v.Fid == fid { + return v + } + } + return nil +} + //通过羁绊id 创建多个羁绊信息 func (this *Library) CreateLibrary(uid string, fids []int32, heroConfId string) (code pb.ErrorCode, objLibrary []*pb.DBLibrary) { for _, fid := range fids { @@ -69,9 +80,9 @@ func (this *Library) CreateLibrary(uid string, fids []int32, heroConfId string) conf := this.configure.GetLibraryFetter(fid, 1) if conf == nil { for _, v := range conf.Hid { - obj.Hero[v] = 0 + obj.Hero[v] = 0 // 默认值 if v == heroConfId { - obj.Hero[heroConfId] = 1 + obj.Hero[heroConfId] = 1 // 获得的英雄好感度等级为1级 } } if err := this.modelLibrary.createLibrary(uid, obj); err != nil { @@ -102,8 +113,8 @@ func (this *Library) createHeroFetter(uid string, heroConfId string) (code pb.Er Id: primitive.NewObjectID().Hex(), Uid: uid, Heroid: heroConfId, - History: 0, - Favorlv: 1, // 所有好感度默认1级 + History: make([]int32, 0), + Favorlv: 1, Stroyprize: 0, } if err := this.modelFetter.createHeroFetter(uid, obj); err != nil { @@ -112,13 +123,13 @@ func (this *Library) createHeroFetter(uid string, heroConfId string) (code pb.Er return } -func (this *Library) QueryHeroFetter(session comm.IUserSession) (data []*pb.DBHeroFetter) { - data = this.GetHeroFetterList(session.GetUserId()) +func (this *Library) QueryHeroFetter(uid string) (data []*pb.DBHeroFetter) { + data = this.GetHeroFetterList(uid) return } -func (this *Library) QueryOneHeroFetter(session comm.IUserSession, cid string) *pb.DBHeroFetter { - _data := this.GetHeroFetterList(session.GetUserId()) +func (this *Library) QueryOneHeroFetter(uid string, cid string) *pb.DBHeroFetter { + _data := this.GetHeroFetterList(uid) for _, v := range _data { if v.Heroid == cid { return v @@ -128,8 +139,37 @@ func (this *Library) QueryOneHeroFetter(session comm.IUserSession, cid string) * } // 创建一条羁绊信息 -func (this *Library) AddHeroFetterData(session comm.IUserSession, heroConfId string) { - this.createHeroFetter(session.GetUserId(), heroConfId) - +func (this *Library) AddHeroFetterData(uid string, heroConfId string) { + this.createHeroFetter(uid, heroConfId) + _conf := this.configure.GetLibraryHero(heroConfId) + if _conf != nil { + szFid := _conf.Fid + for _, fid := range szFid { + // 查询是否存在这个羁绊对象 + obj := this.GetLibraryListByFid(uid, fid) + if obj == nil { // 没有羁绊信息 + this.createHeroFetter(uid, heroConfId) + } else { // 羁绊信息中没有这个heroid 也需要加进来 + for k, v := range obj.Hero { + if v == 0 && k == heroConfId { + v = 1 + } + } + // 重新计算最低等级 + var minLv int32 + for _, v := range obj.Hero { + if minLv < v { + minLv = v + } + } + obj.Fetterlv = minLv + // 同步数据 + mapData := make(map[string]interface{}, 0) + mapData["hero"] = obj.Hero + mapData["fetterlv"] = obj.Fetterlv + this.modelLibrary.modifyLibraryDataByObjId(uid, obj.Id, mapData) + } + } + } return } diff --git a/pb/library_db.pb.go b/pb/library_db.pb.go index 747f07efe..ad850e6dc 100644 --- a/pb/library_db.pb.go +++ b/pb/library_db.pb.go @@ -121,12 +121,12 @@ type DBHeroFetter struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id" bson:"_id"` //ID - Uid string `protobuf:"bytes,2,opt,name=uid,proto3" json:"uid" bson:"uid"` //用户ID - Heroid string `protobuf:"bytes,3,opt,name=heroid,proto3" json:"heroid"` // 英雄配置表id - History int32 `protobuf:"varint,4,opt,name=history,proto3" json:"history"` // 传记往事ID - Favorlv int32 `protobuf:"varint,5,opt,name=favorlv,proto3" json:"favorlv"` // 好感度等级 - Stroyprize int32 `protobuf:"varint,6,opt,name=stroyprize,proto3" json:"stroyprize"` // 剧情奖励 + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id" bson:"_id"` //ID + Uid string `protobuf:"bytes,2,opt,name=uid,proto3" json:"uid" bson:"uid"` //用户ID + Heroid string `protobuf:"bytes,3,opt,name=heroid,proto3" json:"heroid"` // 英雄配置表id + History []int32 `protobuf:"varint,4,rep,packed,name=history,proto3" json:"history"` // 传记往事ID + Favorlv int32 `protobuf:"varint,5,opt,name=favorlv,proto3" json:"favorlv"` // 好感度等级 + Stroyprize int32 `protobuf:"varint,6,opt,name=stroyprize,proto3" json:"stroyprize"` // 剧情奖励 } func (x *DBHeroFetter) Reset() { @@ -182,11 +182,11 @@ func (x *DBHeroFetter) GetHeroid() string { return "" } -func (x *DBHeroFetter) GetHistory() int32 { +func (x *DBHeroFetter) GetHistory() []int32 { if x != nil { return x.History } - return 0 + return nil } func (x *DBHeroFetter) GetFavorlv() int32 { @@ -233,7 +233,7 @@ var file_library_library_db_proto_rawDesc = []byte{ 0x03, 0x75, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x69, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x68, 0x65, 0x72, 0x6f, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x68, 0x65, 0x72, 0x6f, 0x69, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x68, 0x69, 0x73, 0x74, 0x6f, - 0x72, 0x79, 0x18, 0x04, 0x20, 0x01, 0x28, 0x05, 0x52, 0x07, 0x68, 0x69, 0x73, 0x74, 0x6f, 0x72, + 0x72, 0x79, 0x18, 0x04, 0x20, 0x03, 0x28, 0x05, 0x52, 0x07, 0x68, 0x69, 0x73, 0x74, 0x6f, 0x72, 0x79, 0x12, 0x18, 0x0a, 0x07, 0x66, 0x61, 0x76, 0x6f, 0x72, 0x6c, 0x76, 0x18, 0x05, 0x20, 0x01, 0x28, 0x05, 0x52, 0x07, 0x66, 0x61, 0x76, 0x6f, 0x72, 0x6c, 0x76, 0x12, 0x1e, 0x0a, 0x0a, 0x73, 0x74, 0x72, 0x6f, 0x79, 0x70, 0x72, 0x69, 0x7a, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x05, 0x52, diff --git a/pb/library_msg.pb.go b/pb/library_msg.pb.go index 1a204b93b..95f30cbc2 100644 --- a/pb/library_msg.pb.go +++ b/pb/library_msg.pb.go @@ -207,8 +207,9 @@ type LibraryGetStoryRewardReq struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Hid string `protobuf:"bytes,1,opt,name=hid,proto3" json:"hid"` // 英雄ID - StoryId int32 `protobuf:"varint,2,opt,name=storyId,proto3" json:"storyId"` // 故事剧情id + Hid string `protobuf:"bytes,1,opt,name=hid,proto3" json:"hid"` // 英雄ID + History int32 `protobuf:"varint,2,opt,name=history,proto3" json:"history"` // 传记往事id + Rightend int32 `protobuf:"varint,3,opt,name=rightend,proto3" json:"rightend"` // 对应配置表 rightend } func (x *LibraryGetStoryRewardReq) Reset() { @@ -250,9 +251,16 @@ func (x *LibraryGetStoryRewardReq) GetHid() string { return "" } -func (x *LibraryGetStoryRewardReq) GetStoryId() int32 { +func (x *LibraryGetStoryRewardReq) GetHistory() int32 { if x != nil { - return x.StoryId + return x.History + } + return 0 +} + +func (x *LibraryGetStoryRewardReq) GetRightend() int32 { + if x != nil { + return x.Rightend } return 0 } @@ -321,16 +329,18 @@ var file_library_library_msg_proto_rawDesc = []byte{ 0x14, 0x4c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x47, 0x65, 0x74, 0x52, 0x65, 0x77, 0x61, 0x72, 0x64, 0x52, 0x65, 0x73, 0x70, 0x12, 0x1e, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0a, 0x2e, 0x44, 0x42, 0x4c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x52, - 0x04, 0x64, 0x61, 0x74, 0x61, 0x22, 0x46, 0x0a, 0x18, 0x4c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, + 0x04, 0x64, 0x61, 0x74, 0x61, 0x22, 0x62, 0x0a, 0x18, 0x4c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x47, 0x65, 0x74, 0x53, 0x74, 0x6f, 0x72, 0x79, 0x52, 0x65, 0x77, 0x61, 0x72, 0x64, 0x52, 0x65, 0x71, 0x12, 0x10, 0x0a, 0x03, 0x68, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, - 0x68, 0x69, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x74, 0x6f, 0x72, 0x79, 0x49, 0x64, 0x18, 0x02, - 0x20, 0x01, 0x28, 0x05, 0x52, 0x07, 0x73, 0x74, 0x6f, 0x72, 0x79, 0x49, 0x64, 0x22, 0x3b, 0x0a, - 0x19, 0x4c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x47, 0x65, 0x74, 0x53, 0x74, 0x6f, 0x72, 0x79, - 0x52, 0x65, 0x77, 0x61, 0x72, 0x64, 0x52, 0x65, 0x73, 0x70, 0x12, 0x1e, 0x0a, 0x04, 0x64, 0x61, - 0x74, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0a, 0x2e, 0x44, 0x42, 0x4c, 0x69, 0x62, - 0x72, 0x61, 0x72, 0x79, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, - 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x68, 0x69, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x68, 0x69, 0x73, 0x74, 0x6f, 0x72, 0x79, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x05, 0x52, 0x07, 0x68, 0x69, 0x73, 0x74, 0x6f, 0x72, 0x79, 0x12, 0x1a, 0x0a, + 0x08, 0x72, 0x69, 0x67, 0x68, 0x74, 0x65, 0x6e, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, + 0x08, 0x72, 0x69, 0x67, 0x68, 0x74, 0x65, 0x6e, 0x64, 0x22, 0x3b, 0x0a, 0x19, 0x4c, 0x69, 0x62, + 0x72, 0x61, 0x72, 0x79, 0x47, 0x65, 0x74, 0x53, 0x74, 0x6f, 0x72, 0x79, 0x52, 0x65, 0x77, 0x61, + 0x72, 0x64, 0x52, 0x65, 0x73, 0x70, 0x12, 0x1e, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0a, 0x2e, 0x44, 0x42, 0x4c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, + 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var (