From 7a85b1bd7d6633d8e06e0be03c80d326e70d5a01 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Fri, 14 Oct 2022 19:03:12 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=A1=E7=89=8C=E5=90=88=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/hero/api_fusion.go | 81 ++++++++++++++ modules/hero/configure_comp.go | 19 ++++ pb/hero_msg.pb.go | 186 ++++++++++++++++++++++++++++----- 3 files changed, 259 insertions(+), 27 deletions(-) create mode 100644 modules/hero/api_fusion.go diff --git a/modules/hero/api_fusion.go b/modules/hero/api_fusion.go new file mode 100644 index 000000000..e1b36edf1 --- /dev/null +++ b/modules/hero/api_fusion.go @@ -0,0 +1,81 @@ +package hero + +import ( + "go_dreamfactory/comm" + "go_dreamfactory/pb" + "strconv" + + "google.golang.org/protobuf/proto" +) + +//参数校验 +func (this *apiComp) FusionCheck(session comm.IUserSession, req *pb.HeroFusionReq) (code pb.ErrorCode) { + if req.FuionId <= 0 { + code = pb.ErrorCode_ReqParameterError + } + return +} + +func (this *apiComp) Fusion(session comm.IUserSession, req *pb.HeroFusionReq) (code pb.ErrorCode, data proto.Message) { + var ( + totalCount int32 + mapHero map[string]int32 + _costMaphero map[string]*pb.DBHero + ChangeList []*pb.DBHero // 变化的英雄数据 + ) + ChangeList = make([]*pb.DBHero, 0) + _costMaphero = make(map[string]*pb.DBHero, 0) + mapHero = make(map[string]int32) + if code = this.FusionCheck(session, req); code != pb.ErrorCode_Success { + return + } + conf := this.module.configure.GetHeroFucionConfig(req.FuionId) + if conf == nil { + code = pb.ErrorCode_ConfigNoFound // 配置没找到 + return + } + for _, v := range req.Heros { + totalCount += v + } + if totalCount != int32(len(conf.Pointhero)) { // 校验数量 + code = pb.ErrorCode_ReqParameterError + return + } + for k, v := range req.Heros { + // 校验英雄是否存在 + _obj, c := this.module.GetHeroByObjID(session.GetUserId(), k) + if c != pb.ErrorCode_Success || _obj.SameCount < v { + code = pb.ErrorCode_HeroNoExist + } + mapHero[_obj.HeroID] = v + _costMaphero[k] = _obj + } + for _, v := range conf.Pointhero { + if v1, ok := mapHero[strconv.Itoa(int(v))]; !ok { + v1 -= v + } else { + code = pb.ErrorCode_ReqParameterError + return + } + } + for _, v := range mapHero { + if v != 0 { + code = pb.ErrorCode_ReqParameterError + return + } + } + for k, v := range _costMaphero { + code = this.module.DelCard(session.GetUserId(), v, mapHero[k]) + if code != pb.ErrorCode_Success { + return + } + ChangeList = append(ChangeList, _costMaphero[k]) + } + // 获得新卡 + newHero, err := this.module.modelHero.createHeroOverlying(session.GetUserId(), strconv.Itoa(int(conf.Hero)), 1) + if err != nil { + ChangeList = append(ChangeList, newHero) + } + session.SendMsg(string(this.module.GetType()), "change", &pb.HeroChangePush{List: ChangeList}) + return +} diff --git a/modules/hero/configure_comp.go b/modules/hero/configure_comp.go index 925c785c9..dfa58f484 100644 --- a/modules/hero/configure_comp.go +++ b/modules/hero/configure_comp.go @@ -25,6 +25,7 @@ const ( hero_drawcard = "game_drawcard.json" // 抽卡 hero_drawupdraw = "game_drawupdraw.json" // 抽卡概率调整 hero_drawcost = "game_drawcost.json" // 抽卡消耗 + hero_fusion = "game_herofusion.json" // 卡牌融合 ) ///配置管理组件 @@ -53,6 +54,7 @@ func (this *configureComp) Init(service core.IService, module core.IModule, comp game_skillatk: cfg.NewGameSkillAtk, hero_comatn: cfg.NewGameComAtn, hero_drawcard: cfg.NewGameDrawCard, + hero_fusion: cfg.NewGameHerofusion, }) this.drawCardCfg = make(map[string]map[int32][]*cfg.GameDrawCardData, 0) @@ -380,3 +382,20 @@ func (this *configureComp) GetHeroResonanceRestConfig() (data *cfg.GameComAtnDat return } + +// 获取卡牌合成配置 +func (this *configureComp) GetHeroFucionConfig(id int32) (data *cfg.GameHerofusionData) { + + if v, err := this.GetConfigure(hero_fusion); err == nil { + if configure, ok := v.(*cfg.GameHerofusion); !ok { + err = fmt.Errorf("%T no is *cfg.GameHerofusionData", v) + return + } else { + data = configure.Get(id) + } + } else { + err = fmt.Errorf("%T no is *cfg.GameHerofusionData", v) + } + + return +} diff --git a/pb/hero_msg.pb.go b/pb/hero_msg.pb.go index 066a55286..459625d3b 100644 --- a/pb/hero_msg.pb.go +++ b/pb/hero_msg.pb.go @@ -1686,6 +1686,100 @@ func (x *HeroDrawCardFloorResp) GetStar5() int32 { return 0 } +// 英雄融合 +type HeroFusionReq struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + FuionId int32 `protobuf:"varint,1,opt,name=fuionId,proto3" json:"fuionId"` + Heros map[string]int32 `protobuf:"bytes,2,rep,name=heros,proto3" json:"heros" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` // key heroObjID value 数量 +} + +func (x *HeroFusionReq) Reset() { + *x = HeroFusionReq{} + if protoimpl.UnsafeEnabled { + mi := &file_hero_hero_msg_proto_msgTypes[32] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *HeroFusionReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*HeroFusionReq) ProtoMessage() {} + +func (x *HeroFusionReq) ProtoReflect() protoreflect.Message { + mi := &file_hero_hero_msg_proto_msgTypes[32] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use HeroFusionReq.ProtoReflect.Descriptor instead. +func (*HeroFusionReq) Descriptor() ([]byte, []int) { + return file_hero_hero_msg_proto_rawDescGZIP(), []int{32} +} + +func (x *HeroFusionReq) GetFuionId() int32 { + if x != nil { + return x.FuionId + } + return 0 +} + +func (x *HeroFusionReq) GetHeros() map[string]int32 { + if x != nil { + return x.Heros + } + return nil +} + +type HeroFusionResp struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *HeroFusionResp) Reset() { + *x = HeroFusionResp{} + if protoimpl.UnsafeEnabled { + mi := &file_hero_hero_msg_proto_msgTypes[33] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *HeroFusionResp) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*HeroFusionResp) ProtoMessage() {} + +func (x *HeroFusionResp) ProtoReflect() protoreflect.Message { + mi := &file_hero_hero_msg_proto_msgTypes[33] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use HeroFusionResp.ProtoReflect.Descriptor instead. +func (*HeroFusionResp) Descriptor() ([]byte, []int) { + return file_hero_hero_msg_proto_rawDescGZIP(), []int{33} +} + var File_hero_hero_msg_proto protoreflect.FileDescriptor var file_hero_hero_msg_proto_rawDesc = []byte{ @@ -1835,8 +1929,18 @@ var file_hero_hero_msg_proto_rawDesc = []byte{ 0x72, 0x64, 0x46, 0x6c, 0x6f, 0x6f, 0x72, 0x52, 0x65, 0x73, 0x70, 0x12, 0x14, 0x0a, 0x05, 0x73, 0x74, 0x61, 0x72, 0x34, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x73, 0x74, 0x61, 0x72, 0x34, 0x12, 0x14, 0x0a, 0x05, 0x73, 0x74, 0x61, 0x72, 0x35, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, - 0x52, 0x05, 0x73, 0x74, 0x61, 0x72, 0x35, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, - 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x52, 0x05, 0x73, 0x74, 0x61, 0x72, 0x35, 0x22, 0x94, 0x01, 0x0a, 0x0d, 0x48, 0x65, 0x72, 0x6f, + 0x46, 0x75, 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x12, 0x18, 0x0a, 0x07, 0x66, 0x75, 0x69, + 0x6f, 0x6e, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x07, 0x66, 0x75, 0x69, 0x6f, + 0x6e, 0x49, 0x64, 0x12, 0x2f, 0x0a, 0x05, 0x68, 0x65, 0x72, 0x6f, 0x73, 0x18, 0x02, 0x20, 0x03, + 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x48, 0x65, 0x72, 0x6f, 0x46, 0x75, 0x73, 0x69, 0x6f, 0x6e, 0x52, + 0x65, 0x71, 0x2e, 0x48, 0x65, 0x72, 0x6f, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x05, 0x68, + 0x65, 0x72, 0x6f, 0x73, 0x1a, 0x38, 0x0a, 0x0a, 0x48, 0x65, 0x72, 0x6f, 0x73, 0x45, 0x6e, 0x74, + 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x05, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x10, + 0x0a, 0x0e, 0x48, 0x65, 0x72, 0x6f, 0x46, 0x75, 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, + 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -1851,7 +1955,7 @@ func file_hero_hero_msg_proto_rawDescGZIP() []byte { return file_hero_hero_msg_proto_rawDescData } -var file_hero_hero_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 34) +var file_hero_hero_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 37) var file_hero_hero_msg_proto_goTypes = []interface{}{ (*HeroInfoReq)(nil), // 0: HeroInfoReq (*HeroInfoResp)(nil), // 1: HeroInfoResp @@ -1885,35 +1989,39 @@ var file_hero_hero_msg_proto_goTypes = []interface{}{ (*HeroChangePush)(nil), // 29: HeroChangePush (*HeroDrawCardFloorReq)(nil), // 30: HeroDrawCardFloorReq (*HeroDrawCardFloorResp)(nil), // 31: HeroDrawCardFloorResp - nil, // 32: HeroPropertyPush.PropertyEntry - nil, // 33: HeroPropertyPush.AddPropertyEntry - (*DBHero)(nil), // 34: DBHero + (*HeroFusionReq)(nil), // 32: HeroFusionReq + (*HeroFusionResp)(nil), // 33: HeroFusionResp + nil, // 34: HeroPropertyPush.PropertyEntry + nil, // 35: HeroPropertyPush.AddPropertyEntry + nil, // 36: HeroFusionReq.HerosEntry + (*DBHero)(nil), // 37: DBHero } var file_hero_hero_msg_proto_depIdxs = []int32{ - 34, // 0: HeroInfoResp.base:type_name -> DBHero - 34, // 1: HeroListResp.list:type_name -> DBHero + 37, // 0: HeroInfoResp.base:type_name -> DBHero + 37, // 1: HeroListResp.list:type_name -> DBHero 5, // 2: HeroStrengthenUplvReq.expCards:type_name -> MapStringInt32 - 34, // 3: HeroStrengthenUplvResp.hero:type_name -> DBHero + 37, // 3: HeroStrengthenUplvResp.hero:type_name -> DBHero 8, // 4: HeroStrengthenUpStarReq.hero:type_name -> CostCardData 8, // 5: HeroStrengthenUpStarReq.heroRace:type_name -> CostCardData - 34, // 6: HeroStrengthenUpStarResp.hero:type_name -> DBHero - 34, // 7: HeroStrengthenUpSkillResp.hero:type_name -> DBHero - 34, // 8: HeroResonanceResp.hero:type_name -> DBHero - 34, // 9: HeroResonanceResp.upStarCard:type_name -> DBHero - 34, // 10: HeroResonanceResetResp.hero:type_name -> DBHero + 37, // 6: HeroStrengthenUpStarResp.hero:type_name -> DBHero + 37, // 7: HeroStrengthenUpSkillResp.hero:type_name -> DBHero + 37, // 8: HeroResonanceResp.hero:type_name -> DBHero + 37, // 9: HeroResonanceResp.upStarCard:type_name -> DBHero + 37, // 10: HeroResonanceResetResp.hero:type_name -> DBHero 17, // 11: HeroResonanceUseEnergyReq.energy:type_name -> EnergyData - 34, // 12: HeroResonanceUseEnergyResp.hero:type_name -> DBHero - 34, // 13: HeroAwakenResp.hero:type_name -> DBHero - 32, // 14: HeroPropertyPush.property:type_name -> HeroPropertyPush.PropertyEntry - 33, // 15: HeroPropertyPush.addProperty:type_name -> HeroPropertyPush.AddPropertyEntry - 34, // 16: HeroLockResp.hero:type_name -> DBHero - 34, // 17: HeroGetSpecifiedResp.hero:type_name -> DBHero - 34, // 18: HeroChangePush.list:type_name -> DBHero - 19, // [19:19] is the sub-list for method output_type - 19, // [19:19] is the sub-list for method input_type - 19, // [19:19] is the sub-list for extension type_name - 19, // [19:19] is the sub-list for extension extendee - 0, // [0:19] is the sub-list for field type_name + 37, // 12: HeroResonanceUseEnergyResp.hero:type_name -> DBHero + 37, // 13: HeroAwakenResp.hero:type_name -> DBHero + 34, // 14: HeroPropertyPush.property:type_name -> HeroPropertyPush.PropertyEntry + 35, // 15: HeroPropertyPush.addProperty:type_name -> HeroPropertyPush.AddPropertyEntry + 37, // 16: HeroLockResp.hero:type_name -> DBHero + 37, // 17: HeroGetSpecifiedResp.hero:type_name -> DBHero + 37, // 18: HeroChangePush.list:type_name -> DBHero + 36, // 19: HeroFusionReq.heros:type_name -> HeroFusionReq.HerosEntry + 20, // [20:20] is the sub-list for method output_type + 20, // [20:20] is the sub-list for method input_type + 20, // [20:20] is the sub-list for extension type_name + 20, // [20:20] is the sub-list for extension extendee + 0, // [0:20] is the sub-list for field type_name } func init() { file_hero_hero_msg_proto_init() } @@ -2307,6 +2415,30 @@ func file_hero_hero_msg_proto_init() { return nil } } + file_hero_hero_msg_proto_msgTypes[32].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*HeroFusionReq); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_hero_hero_msg_proto_msgTypes[33].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*HeroFusionResp); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } type x struct{} out := protoimpl.TypeBuilder{ @@ -2314,7 +2446,7 @@ func file_hero_hero_msg_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_hero_hero_msg_proto_rawDesc, NumEnums: 0, - NumMessages: 34, + NumMessages: 37, NumExtensions: 0, NumServices: 0, },