diff --git a/modules/stonehenge/api_bookaward.go b/modules/stonehenge/api_bookaward.go index 1fc1f9848..5760d25b9 100644 --- a/modules/stonehenge/api_bookaward.go +++ b/modules/stonehenge/api_bookaward.go @@ -3,6 +3,7 @@ package stonehenge import ( "go_dreamfactory/comm" "go_dreamfactory/pb" + cfg "go_dreamfactory/sys/configure/structs" ) //参数校验 @@ -13,8 +14,13 @@ func (this *apiComp) BookAwardCheck(session comm.IUserSession, req *pb.Stoneheng func (this *apiComp) BookAward(session comm.IUserSession, req *pb.StonehengeBookAwardReq) (errdata *pb.ErrorData) { var ( - info *pb.DBStonehengeBook - err error + info *pb.DBStonehengeBook + confs []*cfg.GameStoneIllustratedData + bookAward *pb.DBStonehengeBookAward + conf *cfg.GameStoneIllustratedData + award []*pb.UserAssets + ok bool + err error ) if errdata = this.BookAwardCheck(session, req); errdata != nil { return @@ -27,6 +33,65 @@ func (this *apiComp) BookAward(session comm.IUserSession, req *pb.StonehengeBook } return } - session.SendMsg(string(this.module.GetType()), "bookinfo", &pb.StonehengeBookInfoResp{Info: info}) + + if confs, err = this.module.configure.getGameStoneIllustratedDatas(); err != nil { + for _, v := range confs { + if v.Type == req.Btype && v.ColltectionNum == req.Stage { + conf = v + } + } + } + + if conf == nil { + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_DBError, + Title: pb.ErrorCode_DBError.String(), + Message: "no found stage", + } + return + } + + if bookAward, ok = info.Award[req.Btype]; !ok { + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_ReqParameterError, + Title: pb.ErrorCode_ReqParameterError.String(), + Message: "book is emtry", + } + return + } + + if len(bookAward.Books) < int(conf.ColltectionNum) { + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_ReqParameterError, + Title: pb.ErrorCode_ReqParameterError.String(), + Message: "book is not enough", + } + return + } + bookAward.Stage[conf.ColltectionNum] = true + + 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, + }) + } + + if err = this.module.modelStonehengeBook.Change(session.GetUserId(), map[string]interface{}{ + "award": info.Award, + }); err != nil { + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_DBError, + Title: pb.ErrorCode_DBError.String(), + Message: err.Error(), + } + } + + session.SendMsg(string(this.module.GetType()), "bookaward", &pb.StonehengeBookAwardResp{Btype: req.Btype, Stage: req.Stage, Award: award}) return } diff --git a/modules/stonehenge/modelStonehengeBook.go b/modules/stonehenge/modelStonehengeBook.go index ac890c146..90b727e36 100644 --- a/modules/stonehenge/modelStonehengeBook.go +++ b/modules/stonehenge/modelStonehengeBook.go @@ -41,7 +41,6 @@ func (this *ModelStonehengeBook) getStonehengeBook(uid string) (info *pb.DBStone info = &pb.DBStonehengeBook{ Id: primitive.NewObjectID().Hex(), Uid: uid, - Books: make([]int32, 0), Award: make(map[int32]*pb.DBStonehengeBookAward), } err = this.Add(uid, info) diff --git a/pb/stonehenge_db.pb.go b/pb/stonehenge_db.pb.go index d808ed48b..83086c7bf 100644 --- a/pb/stonehenge_db.pb.go +++ b/pb/stonehenge_db.pb.go @@ -470,7 +470,6 @@ type DBStonehengeBook struct { 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"` - Books []int32 `protobuf:"varint,3,rep,packed,name=books,proto3" json:"books"` Award map[int32]*DBStonehengeBookAward `protobuf:"bytes,4,rep,name=award,proto3" json:"award" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` } @@ -520,13 +519,6 @@ func (x *DBStonehengeBook) GetUid() string { return "" } -func (x *DBStonehengeBook) GetBooks() []int32 { - if x != nil { - return x.Books - } - return nil -} - func (x *DBStonehengeBook) GetAward() map[int32]*DBStonehengeBookAward { if x != nil { return x.Award @@ -541,7 +533,8 @@ type DBStonehengeBookAward struct { unknownFields protoimpl.UnknownFields Btype int32 `protobuf:"varint,1,opt,name=btype,proto3" json:"btype"` - Stage map[int32]bool `protobuf:"bytes,2,rep,name=stage,proto3" json:"stage" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` + Books []int32 `protobuf:"varint,2,rep,packed,name=books,proto3" json:"books"` + Stage map[int32]bool `protobuf:"bytes,3,rep,name=stage,proto3" json:"stage" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` } func (x *DBStonehengeBookAward) Reset() { @@ -583,6 +576,13 @@ func (x *DBStonehengeBookAward) GetBtype() int32 { return 0 } +func (x *DBStonehengeBookAward) GetBooks() []int32 { + if x != nil { + return x.Books + } + return nil +} + func (x *DBStonehengeBookAward) GetStage() map[int32]bool { if x != nil { return x.Stage @@ -705,24 +705,24 @@ var file_stonehenge_stonehenge_db_proto_rawDesc = []byte{ 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x20, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0a, 0x2e, 0x53, 0x74, 0x61, 0x67, 0x65, 0x44, 0x61, 0x74, 0x61, 0x52, - 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0xd0, 0x01, 0x0a, 0x10, 0x44, + 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0xba, 0x01, 0x0a, 0x10, 0x44, 0x42, 0x53, 0x74, 0x6f, 0x6e, 0x65, 0x68, 0x65, 0x6e, 0x67, 0x65, 0x42, 0x6f, 0x6f, 0x6b, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x69, - 0x64, 0x12, 0x14, 0x0a, 0x05, 0x62, 0x6f, 0x6f, 0x6b, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x05, - 0x52, 0x05, 0x62, 0x6f, 0x6f, 0x6b, 0x73, 0x12, 0x32, 0x0a, 0x05, 0x61, 0x77, 0x61, 0x72, 0x64, - 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1c, 0x2e, 0x44, 0x42, 0x53, 0x74, 0x6f, 0x6e, 0x65, - 0x68, 0x65, 0x6e, 0x67, 0x65, 0x42, 0x6f, 0x6f, 0x6b, 0x2e, 0x41, 0x77, 0x61, 0x72, 0x64, 0x45, - 0x6e, 0x74, 0x72, 0x79, 0x52, 0x05, 0x61, 0x77, 0x61, 0x72, 0x64, 0x1a, 0x50, 0x0a, 0x0a, 0x41, - 0x77, 0x61, 0x72, 0x64, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x2c, 0x0a, 0x05, 0x76, - 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x16, 0x2e, 0x44, 0x42, 0x53, - 0x74, 0x6f, 0x6e, 0x65, 0x68, 0x65, 0x6e, 0x67, 0x65, 0x42, 0x6f, 0x6f, 0x6b, 0x41, 0x77, 0x61, - 0x72, 0x64, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0xa0, 0x01, - 0x0a, 0x15, 0x44, 0x42, 0x53, 0x74, 0x6f, 0x6e, 0x65, 0x68, 0x65, 0x6e, 0x67, 0x65, 0x42, 0x6f, - 0x6f, 0x6b, 0x41, 0x77, 0x61, 0x72, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x62, 0x74, 0x79, 0x70, 0x65, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x62, 0x74, 0x79, 0x70, 0x65, 0x12, 0x37, 0x0a, - 0x05, 0x73, 0x74, 0x61, 0x67, 0x65, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x21, 0x2e, 0x44, + 0x64, 0x12, 0x32, 0x0a, 0x05, 0x61, 0x77, 0x61, 0x72, 0x64, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b, + 0x32, 0x1c, 0x2e, 0x44, 0x42, 0x53, 0x74, 0x6f, 0x6e, 0x65, 0x68, 0x65, 0x6e, 0x67, 0x65, 0x42, + 0x6f, 0x6f, 0x6b, 0x2e, 0x41, 0x77, 0x61, 0x72, 0x64, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x05, + 0x61, 0x77, 0x61, 0x72, 0x64, 0x1a, 0x50, 0x0a, 0x0a, 0x41, 0x77, 0x61, 0x72, 0x64, 0x45, 0x6e, + 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, + 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x2c, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x0b, 0x32, 0x16, 0x2e, 0x44, 0x42, 0x53, 0x74, 0x6f, 0x6e, 0x65, 0x68, 0x65, + 0x6e, 0x67, 0x65, 0x42, 0x6f, 0x6f, 0x6b, 0x41, 0x77, 0x61, 0x72, 0x64, 0x52, 0x05, 0x76, 0x61, + 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0xb6, 0x01, 0x0a, 0x15, 0x44, 0x42, 0x53, 0x74, + 0x6f, 0x6e, 0x65, 0x68, 0x65, 0x6e, 0x67, 0x65, 0x42, 0x6f, 0x6f, 0x6b, 0x41, 0x77, 0x61, 0x72, + 0x64, 0x12, 0x14, 0x0a, 0x05, 0x62, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, + 0x52, 0x05, 0x62, 0x74, 0x79, 0x70, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x62, 0x6f, 0x6f, 0x6b, 0x73, + 0x18, 0x02, 0x20, 0x03, 0x28, 0x05, 0x52, 0x05, 0x62, 0x6f, 0x6f, 0x6b, 0x73, 0x12, 0x37, 0x0a, + 0x05, 0x73, 0x74, 0x61, 0x67, 0x65, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x21, 0x2e, 0x44, 0x42, 0x53, 0x74, 0x6f, 0x6e, 0x65, 0x68, 0x65, 0x6e, 0x67, 0x65, 0x42, 0x6f, 0x6f, 0x6b, 0x41, 0x77, 0x61, 0x72, 0x64, 0x2e, 0x53, 0x74, 0x61, 0x67, 0x65, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x05, 0x73, 0x74, 0x61, 0x67, 0x65, 0x1a, 0x38, 0x0a, 0x0a, 0x53, 0x74, 0x61, 0x67, 0x65, 0x45,