From 726dcccf8882c82d2465a5a5aba1062693b5e357 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Mon, 27 Jun 2022 19:12:46 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8B=B1=E9=9B=84=E5=8D=87=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- comm/core.go | 4 ++ modules/hero/api_heroStrengthen.go | 66 ++++++++++++++++++- modules/hero/configure_comp.go | 42 ++++++++++-- modules/hero/module.go | 5 ++ pb/errorcode.pb.go | 23 +++++-- pb/hero_msg.pb.go | 12 ++-- pb/proto/errorcode.proto | 3 +- pb/proto/hero/hero_msg.proto | 2 +- sys/configure/structs/game.heroLevelupData.go | 32 ++++++++- 9 files changed, 164 insertions(+), 25 deletions(-) diff --git a/comm/core.go b/comm/core.go index cfed1b7a6..425174c94 100644 --- a/comm/core.go +++ b/comm/core.go @@ -88,6 +88,10 @@ const ( LogHandleType_Delete LogHandleType = "delete" ) +const ( + HeroStarLvRatio int32 = 10 // 卡牌等级上限系数(星级*10) +) + //Api Check 错误返回结构 type ErrorCode struct { Code pb.ErrorCode diff --git a/modules/hero/api_heroStrengthen.go b/modules/hero/api_heroStrengthen.go index ba3d24f36..8d71f9d43 100644 --- a/modules/hero/api_heroStrengthen.go +++ b/modules/hero/api_heroStrengthen.go @@ -10,8 +10,72 @@ import ( func (this *Api_Comp) StrengthenUplv_Check(session comm.IUserSession, req *pb.Hero_StrengthenUplv_Req) (result map[string]interface{}, code comm.ErrorCode) { if req.HeroObjID == "" { code.Code = pb.ErrorCode_ReqParameterError + return + } + _hero, err := this.module.model_hero.moduleHero.GetHeroInfoByObjID(req.HeroObjID) // 校验升级的对象是否存在 + if err != 0 { + code.Code = pb.ErrorCode_HeroNoExist + return + } + _expHero, err := this.module.model_hero.moduleHero.GetHeroInfoByObjID(req.ExpCardID) // 校验需要消耗经验卡牌的对象是否存在 + if err != 0 { + code.Code = pb.ErrorCode_HeroNoExist + return + } + if req.Amount <= 0 { // 消耗数量校验 + code.Code = pb.ErrorCode_HeroNoExist + return + } + curLv := _hero.Lv + curExp := _hero.Exp // 当前英雄的经验 + var costGold int32 // 当前需要消耗金币的数量 + var addExp int32 // 需要增加的经验 + // 查询 本次消耗会获得多少经验 + expConf, err1 := this.module.configure_comp.GetHeroExpConByHeroid(_expHero.HeroID) + if err1 != nil { + addExp = expConf.Heroexp * req.Amount + } + if _expHero.Count <= req.Amount { // 消耗经验卡片数量不足 + code.Code = pb.ErrorCode_HeroNoEnough + return + } + // 校验当前能不能升级 + + if _hero.Lv >= _hero.Star*comm.HeroStarLvRatio { // 达到最大等级 + code.Code = pb.ErrorCode_HeroMaxLv + return + } + if _data, err1 := this.module.configure_comp.GetHeroLevelUpByLv(curLv); err1 == nil { + costGold += _data.Gold[0].N + curExp += addExp // 先把经验加上 + // 当前升级需要消耗的经验 + for { // 死循环判断一键升级 + if _data.Heroexp[0].N <= curExp { // 升级操作 + curExp = _data.Heroexp[0].N + if curExp >= 0 { // 大于下一级经验 + curLv += 1 // 经验够了 那么等级+1 + if _data, err1 := this.module.configure_comp.GetHeroLevelUpByLv(curLv); err1 == nil { + if _data.Heroexp[0].N > curExp { // 经验不足则 直接返回 + break + } + costGold += _data.Gold[0].N + } else { + break + } + } + } else { + break + } + } + + } + + // 校验金币消耗 + result = map[string]interface{}{ + "costGold": costGold, + "curExp": curExp, + "curLv": curLv, } - //this.module.model_hero.moduleHero.GetHeroInfoByObjID() return } diff --git a/modules/hero/configure_comp.go b/modules/hero/configure_comp.go index d6eab6892..cb46637b1 100644 --- a/modules/hero/configure_comp.go +++ b/modules/hero/configure_comp.go @@ -31,13 +31,6 @@ func (this *Configure_Comp) Init(service core.IService, module core.IModule, com this.LoadConfigure(game_heroStarup, cfg.NewGame_heroStarup) this.LoadConfigure(game_heroLevelup, cfg.NewGame_heroLevelup) this.LoadConfigure(game_heroExp, cfg.NewGame_heroExp) - - // this.GetHeroConfigure() - // this.GetHeroStargrowCon() - // this.GetHeroLevelgrowCon() - // this.GetHeroStarupCon() - // this.GetHeroLevelUpCon() - // this.GetHeroExpCon() return } @@ -125,6 +118,23 @@ func (this *Configure_Comp) GetHeroLevelUpCon() (configure *cfg.Game_heroLevelup return } +// 获取英雄升级相关配置数据 +func (this *Configure_Comp) GetHeroLevelUpByLv(lv int32) (data *cfg.Game_heroLevelupData, err error) { + + if v, err1 := this.GetConfigure(game_heroLevelup); err1 == nil { + if configure, ok := v.(*cfg.Game_heroLevelup); !ok { + err = fmt.Errorf("%T no is *cfg.Game_heroLevelup", v) + return + + } else { + data = configure.Get(lv) + } + } else { + err = fmt.Errorf("%T no is *cfg.Game_heroLevelup", v) + } + return +} + func (this *Configure_Comp) GetHeroExpCon() (configure *cfg.Game_heroExp, err error) { var ( v interface{} @@ -140,3 +150,21 @@ func (this *Configure_Comp) GetHeroExpCon() (configure *cfg.Game_heroExp, err er } return } + +func (this *Configure_Comp) GetHeroExpConByHeroid(hid int32) (data *cfg.Game_heroExpData, err error) { + var ( + v interface{} + ) + if v, err = this.GetConfigure(game_heroExp); err == nil { + if configure, ok := v.(*cfg.Game_heroExp); !ok { + err = fmt.Errorf("%T no is *cfg.Game_heroExp", v) + + return + } else { + data = configure.Get(hid) + } + } else { + err = fmt.Errorf("%T no is *cfg.Game_heroExp", v) + } + return +} diff --git a/modules/hero/module.go b/modules/hero/module.go index 6a2191026..a96e8a470 100644 --- a/modules/hero/module.go +++ b/modules/hero/module.go @@ -50,6 +50,11 @@ func (this *Hero) GetHero(heroId int32) (*pb.DB_HeroData, pb.ErrorCode) { return nil, pb.ErrorCode_HeroNoExist } +func (this *Hero) ModifyHero(heroId *pb.DB_HeroData) (*pb.DB_HeroData, pb.ErrorCode) { + + return nil, pb.ErrorCode_HeroNoExist +} + //佩戴装备 func (this *Hero) InstallEquip(heroId, equipId string) pb.ErrorCode { return pb.ErrorCode_Success diff --git a/pb/errorcode.pb.go b/pb/errorcode.pb.go index 11ab43e0d..a6d651b98 100644 --- a/pb/errorcode.pb.go +++ b/pb/errorcode.pb.go @@ -62,7 +62,9 @@ const ( ErrorCode_PackGridNumUpper ErrorCode = 1202 //背包格子数量已达上限 ErrorCode_PackGirdAmountUpper ErrorCode = 1203 //背包格子容量已达上限 // hero - ErrorCode_HeroNoExist ErrorCode = 1300 //英雄不存在 + ErrorCode_HeroNoExist ErrorCode = 1300 //英雄不存在 + ErrorCode_HeroNoEnough ErrorCode = 1301 //英雄数量不足 + ErrorCode_HeroMaxLv ErrorCode = 1302 //英雄达到最大等级 //equipment ErrorCode_EquipmentOnFoundEquipment ErrorCode = 1400 // 未找到武器 ErrorCode_EquipmentLvlimitReached ErrorCode = 1401 // 武器等级已达上限 @@ -107,6 +109,8 @@ var ( 1202: "PackGridNumUpper", 1203: "PackGirdAmountUpper", 1300: "HeroNoExist", + 1301: "HeroNoEnough", + 1302: "HeroMaxLv", 1400: "EquipmentOnFoundEquipment", 1401: "EquipmentLvlimitReached", } @@ -147,6 +151,8 @@ var ( "PackGridNumUpper": 1202, "PackGirdAmountUpper": 1203, "HeroNoExist": 1300, + "HeroNoEnough": 1301, + "HeroMaxLv": 1302, "EquipmentOnFoundEquipment": 1400, "EquipmentLvlimitReached": 1401, } @@ -183,7 +189,7 @@ var File_errorcode_proto protoreflect.FileDescriptor var file_errorcode_proto_rawDesc = []byte{ 0x0a, 0x0f, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x63, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x2a, 0xab, 0x06, 0x0a, 0x09, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x12, + 0x6f, 0x2a, 0xce, 0x06, 0x0a, 0x09, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x0b, 0x0a, 0x07, 0x53, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x10, 0x00, 0x12, 0x11, 0x0a, 0x0d, 0x4e, 0x6f, 0x46, 0x69, 0x6e, 0x64, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x10, 0x0a, 0x12, 0x1b, 0x0a, 0x17, 0x4e, 0x6f, 0x46, 0x69, 0x6e, 0x64, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, @@ -230,11 +236,14 @@ var file_errorcode_proto_rawDesc = []byte{ 0x65, 0x72, 0x10, 0xb2, 0x09, 0x12, 0x18, 0x0a, 0x13, 0x50, 0x61, 0x63, 0x6b, 0x47, 0x69, 0x72, 0x64, 0x41, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x55, 0x70, 0x70, 0x65, 0x72, 0x10, 0xb3, 0x09, 0x12, 0x10, 0x0a, 0x0b, 0x48, 0x65, 0x72, 0x6f, 0x4e, 0x6f, 0x45, 0x78, 0x69, 0x73, 0x74, 0x10, 0x94, - 0x0a, 0x12, 0x1e, 0x0a, 0x19, 0x45, 0x71, 0x75, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x4f, 0x6e, - 0x46, 0x6f, 0x75, 0x6e, 0x64, 0x45, 0x71, 0x75, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x10, 0xf8, - 0x0a, 0x12, 0x1c, 0x0a, 0x17, 0x45, 0x71, 0x75, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x4c, 0x76, - 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x52, 0x65, 0x61, 0x63, 0x68, 0x65, 0x64, 0x10, 0xf9, 0x0a, 0x42, - 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x0a, 0x12, 0x11, 0x0a, 0x0c, 0x48, 0x65, 0x72, 0x6f, 0x4e, 0x6f, 0x45, 0x6e, 0x6f, 0x75, 0x67, + 0x68, 0x10, 0x95, 0x0a, 0x12, 0x0e, 0x0a, 0x09, 0x48, 0x65, 0x72, 0x6f, 0x4d, 0x61, 0x78, 0x4c, + 0x76, 0x10, 0x96, 0x0a, 0x12, 0x1e, 0x0a, 0x19, 0x45, 0x71, 0x75, 0x69, 0x70, 0x6d, 0x65, 0x6e, + 0x74, 0x4f, 0x6e, 0x46, 0x6f, 0x75, 0x6e, 0x64, 0x45, 0x71, 0x75, 0x69, 0x70, 0x6d, 0x65, 0x6e, + 0x74, 0x10, 0xf8, 0x0a, 0x12, 0x1c, 0x0a, 0x17, 0x45, 0x71, 0x75, 0x69, 0x70, 0x6d, 0x65, 0x6e, + 0x74, 0x4c, 0x76, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x52, 0x65, 0x61, 0x63, 0x68, 0x65, 0x64, 0x10, + 0xf9, 0x0a, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x33, } var ( diff --git a/pb/hero_msg.pb.go b/pb/hero_msg.pb.go index 2b690c9c4..090ea7fd7 100644 --- a/pb/hero_msg.pb.go +++ b/pb/hero_msg.pb.go @@ -81,9 +81,9 @@ type Hero_StrengthenUplv_Req struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - HeroObjID string `protobuf:"bytes,1,opt,name=heroObjID,proto3" json:"heroObjID"` // 英雄对象ID - ExpCardID []string `protobuf:"bytes,2,rep,name=expCardID,proto3" json:"expCardID"` // 经验卡对象ID - Amount int32 `protobuf:"varint,3,opt,name=amount,proto3" json:"amount"` // 消耗经验卡数量 + HeroObjID string `protobuf:"bytes,1,opt,name=heroObjID,proto3" json:"heroObjID"` // 英雄对象ID + ExpCardID string `protobuf:"bytes,2,opt,name=expCardID,proto3" json:"expCardID"` // 经验卡对象ID + Amount int32 `protobuf:"varint,3,opt,name=amount,proto3" json:"amount"` // 消耗经验卡数量 } func (x *Hero_StrengthenUplv_Req) Reset() { @@ -125,11 +125,11 @@ func (x *Hero_StrengthenUplv_Req) GetHeroObjID() string { return "" } -func (x *Hero_StrengthenUplv_Req) GetExpCardID() []string { +func (x *Hero_StrengthenUplv_Req) GetExpCardID() string { if x != nil { return x.ExpCardID } - return nil + return "" } func (x *Hero_StrengthenUplv_Req) GetAmount() int32 { @@ -908,7 +908,7 @@ var file_hero_hero_msg_proto_rawDesc = []byte{ 0x72, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x65, 0x6e, 0x55, 0x70, 0x6c, 0x76, 0x5f, 0x52, 0x65, 0x71, 0x12, 0x1c, 0x0a, 0x09, 0x68, 0x65, 0x72, 0x6f, 0x4f, 0x62, 0x6a, 0x49, 0x44, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x68, 0x65, 0x72, 0x6f, 0x4f, 0x62, 0x6a, 0x49, 0x44, 0x12, 0x1c, - 0x0a, 0x09, 0x65, 0x78, 0x70, 0x43, 0x61, 0x72, 0x64, 0x49, 0x44, 0x18, 0x02, 0x20, 0x03, 0x28, + 0x0a, 0x09, 0x65, 0x78, 0x70, 0x43, 0x61, 0x72, 0x64, 0x49, 0x44, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x65, 0x78, 0x70, 0x43, 0x61, 0x72, 0x64, 0x49, 0x44, 0x12, 0x16, 0x0a, 0x06, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0x3c, 0x0a, 0x18, 0x48, 0x65, 0x72, 0x6f, 0x5f, 0x53, 0x74, 0x72, diff --git a/pb/proto/errorcode.proto b/pb/proto/errorcode.proto index 730c67362..f003f02ed 100644 --- a/pb/proto/errorcode.proto +++ b/pb/proto/errorcode.proto @@ -46,7 +46,8 @@ enum ErrorCode { // hero HeroNoExist = 1300; //英雄不存在 - + HeroNoEnough = 1301; //英雄数量不足 + HeroMaxLv = 1302; //英雄达到最大等级 //equipment EquipmentOnFoundEquipment = 1400; // 未找到武器 EquipmentLvlimitReached = 1401; // 武器等级已达上限 diff --git a/pb/proto/hero/hero_msg.proto b/pb/proto/hero/hero_msg.proto index 361ce6c00..b8ca87406 100644 --- a/pb/proto/hero/hero_msg.proto +++ b/pb/proto/hero/hero_msg.proto @@ -14,7 +14,7 @@ message ItemData{ // 卡牌升级 message Hero_StrengthenUplv_Req { string heroObjID = 1; // 英雄对象ID - repeated string expCardID = 2; // 经验卡对象ID + string expCardID = 2; // 经验卡对象ID int32 amount = 3; // 消耗经验卡数量 } diff --git a/sys/configure/structs/game.heroLevelupData.go b/sys/configure/structs/game.heroLevelupData.go index eb0971988..bb6c7eb65 100644 --- a/sys/configure/structs/game.heroLevelupData.go +++ b/sys/configure/structs/game.heroLevelupData.go @@ -12,7 +12,8 @@ import "errors" type Game_heroLevelupData struct { Level int32 - Heroexp int32 + Heroexp []*Game_atn + Gold []*Game_atn Hp float32 Atk float32 Def float32 @@ -25,7 +26,34 @@ func (Game_heroLevelupData) GetTypeId() int { func NewGame_heroLevelupData(_buf map[string]interface{}) (_v *Game_heroLevelupData, err error) { _v = &Game_heroLevelupData{} { var _ok_ bool; var _tempNum_ float64; if _tempNum_, _ok_ = _buf["level"].(float64); !_ok_ { err = errors.New("level error"); return }; _v.Level = int32(_tempNum_) } - { var _ok_ bool; var _tempNum_ float64; if _tempNum_, _ok_ = _buf["heroexp"].(float64); !_ok_ { err = errors.New("heroexp error"); return }; _v.Heroexp = int32(_tempNum_) } + { + var _arr_ []interface{} + var _ok_ bool + if _arr_, _ok_ = _buf["heroexp"].([]interface{}); !_ok_ { err = errors.New("heroexp error"); return } + + _v.Heroexp = make([]*Game_atn, 0, len(_arr_)) + + for _, _e_ := range _arr_ { + var _list_v_ *Game_atn + { var _ok_ bool; var _x_ map[string]interface{}; if _x_, _ok_ = _e_.(map[string]interface{}); !_ok_ { err = errors.New("_list_v_ error"); return }; if _list_v_, err = NewGame_atn(_x_); err != nil { return } } + _v.Heroexp = append(_v.Heroexp, _list_v_) + } + } + + { + var _arr_ []interface{} + var _ok_ bool + if _arr_, _ok_ = _buf["gold"].([]interface{}); !_ok_ { err = errors.New("gold error"); return } + + _v.Gold = make([]*Game_atn, 0, len(_arr_)) + + for _, _e_ := range _arr_ { + var _list_v_ *Game_atn + { var _ok_ bool; var _x_ map[string]interface{}; if _x_, _ok_ = _e_.(map[string]interface{}); !_ok_ { err = errors.New("_list_v_ error"); return }; if _list_v_, err = NewGame_atn(_x_); err != nil { return } } + _v.Gold = append(_v.Gold, _list_v_) + } + } + { var _ok_ bool; var _tempNum_ float64; if _tempNum_, _ok_ = _buf["hp"].(float64); !_ok_ { err = errors.New("hp error"); return }; _v.Hp = float32(_tempNum_) } { var _ok_ bool; var _tempNum_ float64; if _tempNum_, _ok_ = _buf["atk"].(float64); !_ok_ { err = errors.New("atk error"); return }; _v.Atk = float32(_tempNum_) } { var _ok_ bool; var _tempNum_ float64; if _tempNum_, _ok_ = _buf["def"].(float64); !_ok_ { err = errors.New("def error"); return }; _v.Def = float32(_tempNum_) }