diff --git a/comm/const.go b/comm/const.go index 9cc2a61a5..aa04c2736 100644 --- a/comm/const.go +++ b/comm/const.go @@ -65,7 +65,15 @@ const ( ) const ( - PropertyHp = 1 //生命 - PropertyAtk = 2 //攻击 - PropertyDef = 3 //防御 + PropertyHp int32 = 1 //生命 + PropertyAtk int32 = 2 //攻击 + PropertyDef int32 = 3 //防御 +) + +const ( + CardTypeHero int32 = 1 //英雄卡 + CardTypeStar int32 = 2 //升星卡 + CardTypeLevel int32 = 3 //升级卡 + CardTypeSkill int32 = 4 //技能升级卡 + CardTypeMonster int32 = 5 //怪物卡 ) diff --git a/comm/imodule.go b/comm/imodule.go index 731be8541..7a00bc57c 100644 --- a/comm/imodule.go +++ b/comm/imodule.go @@ -34,11 +34,11 @@ type ( //英雄 IHero interface { //查询用户卡片数量 - QueryCardAmount(uId string, cardId int32) (amount uint32) - //添加/减少卡片 - AddCard(uId string, cardId int32, add int32) (code pb.ErrorCode) + QueryHeroAmount(uId string, heroCfgId int32) (amount uint32) + //消耗卡片 + ChangeCard(uId string, heroCfgId int32, count int32) (code pb.ErrorCode) //创建新英雄 - CreatMultiHero(uid string, heroCfgId ...int32) error + CreatHero(uid string, heroCfgId ...int32) error // 获取英雄 // heroId 英雄ID diff --git a/lego/core/core.go b/lego/core/core.go index f9f25c1fb..a225f1301 100644 --- a/lego/core/core.go +++ b/lego/core/core.go @@ -1,14 +1,14 @@ package core -type S_Category string //服务类别 例如 网关服务 游戏服务 业务服务 主要用于服务功能分类 -type M_Modules string //模块类型 -type S_Comps string //服务器组件类型 -type ErrorCode int32 //错误码 -type Event_Key string //事件Key -type Rpc_Key string //RPC -type Redis_Key string //Redis缓存 -type SqlTable string //数据库表定义 -type CustomRoute uint8 //自定义网关 +type S_Category string //服务类别 例如 网关服务 游戏服务 业务服务 主要用于服务功能分类 +type M_Modules string //模块类型 +type S_Comps string //服务器组件类型 +type ErrorCode int32 //错误码 +type Event_Key string //事件Key +type Rpc_Key string //RPC +type Redis_Key string //Redis缓存 +type SqlTable string //数据库表定义 +type CustomRoute uint8 //自定义网关 const ( AutoIp = "0.0.0.0" //自动ip 可以匹配任意ip地址 diff --git a/modules/hero/api.go b/modules/hero/api.go index b8759bf0c..4b4cf9898 100644 --- a/modules/hero/api.go +++ b/modules/hero/api.go @@ -7,8 +7,8 @@ import ( type Api_Comp struct { modules.MComp_GateComp - service core.IService - module *Hero + service core.IService + moduleHero *Hero } const ( //消息回复的头名称 @@ -20,7 +20,7 @@ const ( //消息回复的头名称 //组件初始化接口 func (this *Api_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { this.MComp_GateComp.Init(service, module, comp, options) - this.module = module.(*Hero) + this.moduleHero = module.(*Hero) this.service = service return } diff --git a/modules/hero/api_heroStrengthen.go b/modules/hero/api_heroStrengthen.go index 1528ef679..590e1a0a6 100644 --- a/modules/hero/api_heroStrengthen.go +++ b/modules/hero/api_heroStrengthen.go @@ -11,12 +11,12 @@ func (this *Api_Comp) StrengthenUplv_Check(session comm.IUserSession, req *pb.He code.Code = pb.ErrorCode_ReqParameterError return } - _hero, err := this.module.model_hero.moduleHero.GetHeroInfoByObjID(req.HeroObjID) // 校验升级的对象是否存在 + _hero, err := this.moduleHero.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) // 校验需要消耗经验卡牌的对象是否存在 + _expHero, err := this.moduleHero.model_hero.moduleHero.GetHeroInfoByObjID(req.ExpCardID) // 校验需要消耗经验卡牌的对象是否存在 if err != 0 { code.Code = pb.ErrorCode_HeroNoExist return @@ -30,7 +30,7 @@ func (this *Api_Comp) StrengthenUplv_Check(session comm.IUserSession, req *pb.He var costGold int32 // 当前需要消耗金币的数量 var addExp int32 // 需要增加的经验 // 查询 本次消耗会获得多少经验 - expConf := this.module.configure_comp.GetHeroExp(_expHero.HeroID) + expConf := this.moduleHero.configure_comp.GetHeroExp(_expHero.HeroID) if expConf != nil { addExp = expConf.Heroexp * req.Amount } @@ -44,7 +44,7 @@ func (this *Api_Comp) StrengthenUplv_Check(session comm.IUserSession, req *pb.He code.Code = pb.ErrorCode_HeroMaxLv return } - if _data := this.module.configure_comp.GetHeroLv(curLv); _data != nil { + if _data := this.moduleHero.configure_comp.GetHeroLv(curLv); _data != nil { costGold += _data.Gold[0].N curExp += addExp // 先把经验加上 // 当前升级需要消耗的经验 @@ -53,7 +53,7 @@ func (this *Api_Comp) StrengthenUplv_Check(session comm.IUserSession, req *pb.He curExp = _data.Heroexp[0].N if curExp >= 0 { // 大于下一级经验 curLv += 1 // 经验够了 那么等级+1 - if _data := this.module.configure_comp.GetHeroLv(curLv); _data != nil { + if _data := this.moduleHero.configure_comp.GetHeroLv(curLv); _data != nil { if _data.Heroexp[0].N > curExp { // 经验不足则 直接返回 break } @@ -83,7 +83,7 @@ func (this *Api_Comp) StrengthenUplv(session comm.IUserSession, agrs map[string] defer func() { if code == pb.ErrorCode_Success { - session.SendMsg(string(this.module.GetType()), StrengthenUplv, &pb.Hero_StrengthenUplv_Resp{}) + session.SendMsg(string(this.moduleHero.GetType()), StrengthenUplv, &pb.Hero_StrengthenUplv_Resp{}) } }() diff --git a/modules/hero/api_info.go b/modules/hero/api_info.go index 67075eddf..484f51e52 100644 --- a/modules/hero/api_info.go +++ b/modules/hero/api_info.go @@ -8,7 +8,7 @@ import ( //参数校验 func (this *Api_Comp) Info_Check(session comm.IUserSession, req *pb.Hero_Info_Req) (result map[string]interface{}, code comm.ErrorCode) { result = map[string]interface{}{} - hero := this.module.model_hero.getOneHero(session.GetUserId(), req.HeroId) + hero := this.moduleHero.model_hero.getOneHero(session.GetUserId(), req.HeroId) if hero == nil { code = comm.ErrorCode{Code: pb.ErrorCode_HeroNoExist} } @@ -19,7 +19,7 @@ func (this *Api_Comp) Info_Check(session comm.IUserSession, req *pb.Hero_Info_Re func (this *Api_Comp) Info(session comm.IUserSession, result map[string]interface{}, req *pb.Hero_Info_Req) (code pb.ErrorCode) { rsp := &pb.Hero_Info_Rsp{} defer func() { - err := session.SendMsg(string(this.module.GetType()), Hero_SubType_Info, rsp) + err := session.SendMsg(string(this.moduleHero.GetType()), Hero_SubType_Info, rsp) if err != nil { code = pb.ErrorCode_SystemError return diff --git a/modules/hero/api_list.go b/modules/hero/api_list.go index 5a5fd5b98..ec4cdaa65 100644 --- a/modules/hero/api_list.go +++ b/modules/hero/api_list.go @@ -14,13 +14,13 @@ func (this *Api_Comp) List(session comm.IUserSession, result map[string]interfac rsp := &pb.Hero_List_Rsp{} defer func() { - err := session.SendMsg(this.module.api_comp.service.GetType(), Hero_SubType_List, rsp) + err := session.SendMsg(this.moduleHero.api_comp.service.GetType(), Hero_SubType_List, rsp) if err != nil { code = pb.ErrorCode_SystemError } }() - list, err := this.module.model_hero.getHeroList(session.GetUserId()) + list, err := this.moduleHero.model_hero.getHeroList(session.GetUserId()) if err != nil { code = pb.ErrorCode_DBError return diff --git a/modules/hero/model_hero.go b/modules/hero/model_hero.go index 2e9ae8819..aa6e654d9 100644 --- a/modules/hero/model_hero.go +++ b/modules/hero/model_hero.go @@ -37,11 +37,12 @@ func (this *ModelHero) initHero(uid string, heroCfgId int32) *pb.DB_HeroData { Id: objId, Uid: uid, HeroID: heroCfg.Hid, - Star: heroCfg.Star, - Lv: 1, //初始等级 - NormalSkill: []*pb.SkillData{}, + Star: heroCfg.Star, //初始星级 + Lv: 1, //初始等级 + NormalSkill: []*pb.SkillData{}, //初始技能 + Skins: []int32{}, - EquipID: make([]string, 6), + EquipID: make([]string, 6), //初始装备 AddProperty: make(map[int32]int32), Energy: make(map[int32]int32), Property: make(map[int32]int32), @@ -58,10 +59,10 @@ func (this *ModelHero) createOneHero(uid string, heroCfgId int32) error { return nil } -//创建多个指定的英雄 -func (this *ModelHero) createMultiHero(uid string, heroCfgId ...int32) error { +//创建多个指定的英雄 heroCfgIds可填入多个英雄ID +func (this *ModelHero) createMultiHero(uid string, heroCfgIds ...int32) error { data := make(map[string]interface{}) - for _, v := range heroCfgId { + for _, v := range heroCfgIds { hero := this.initHero(uid, v) if hero != nil { data[hero.Id] = hero @@ -80,6 +81,16 @@ func (this *ModelHero) getOneHero(uid, heroId string) *pb.DB_HeroData { return hero } +//消耗一张英雄卡 +func (this *ModelHero) consumeOneHeroCard(uid, heroId string) error { + return this.moduleHero.model_hero.DelListlds(uid, heroId) +} + +func (this *Hero) ModifyHero(heroId *pb.DB_HeroData) (*pb.DB_HeroData, pb.ErrorCode) { + + return nil, pb.ErrorCode_HeroNoExist +} + //获取玩家的英雄列表 func (this *ModelHero) getHeroList(uid string) ([]*pb.DB_HeroData, error) { herokeys := make(map[string]string) diff --git a/modules/hero/module.go b/modules/hero/module.go index b0115b709..1c719f731 100644 --- a/modules/hero/module.go +++ b/modules/hero/module.go @@ -45,10 +45,33 @@ func (this *Hero) GetHeroInfoByObjID(id string) (*pb.DB_HeroData, pb.ErrorCode) } //创建新英雄 -func (this *Hero) CreatMultiHero(uid string, heroCfgId ...int32) error { +func (this *Hero) CreatHero(uid string, heroCfgId ...int32) error { return this.model_hero.createMultiHero(uid, heroCfgId...) } +//消耗英雄卡 +func (this *Hero) ChangeCard(uId string, heroCfgId int32, count int32) (code pb.ErrorCode) { + heroes := this.GetHeroList(uId) + var curList []*pb.DB_HeroData + for _, v := range heroes { + if heroCfgId == v.HeroID { + curList = append(curList, v) + } + } + if int32(len(curList)) < count { + return pb.ErrorCode_HeroNoEnough + } + + for _, v := range curList { + err := this.model_hero.consumeOneHeroCard(uId, v.Id) + if err != nil { + return pb.ErrorCode_DBError + } + } + + return pb.ErrorCode_Success +} + //获取英雄 func (this *Hero) GetHero(uid, heroId string) (*pb.DB_HeroData, pb.ErrorCode) { hero := this.model_hero.getOneHero(uid, heroId) @@ -58,11 +81,6 @@ func (this *Hero) GetHero(uid, heroId string) (*pb.DB_HeroData, pb.ErrorCode) { return hero, pb.ErrorCode_Success } -func (this *Hero) ModifyHero(heroId *pb.DB_HeroData) (*pb.DB_HeroData, pb.ErrorCode) { - - return nil, pb.ErrorCode_HeroNoExist -} - //佩戴装备 func (this *Hero) UpdateEquipment(hero *pb.DB_HeroData, equip []*pb.DB_Equipment) (code pb.ErrorCode) { equipIds := make([]string, 4) @@ -81,12 +99,13 @@ func (this *Hero) GetHeroList(uid string) []*pb.DB_HeroData { return list } -func (this *Hero) AddCard(uId string, cardId int32, add int32) (code pb.ErrorCode) { - return +//查询英雄数量 +func (this *Hero) QueryHeroAmount(uId string, heroCfgId int32) (amount uint32) { + heroes := this.GetHeroList(uId) + for _, v := range heroes { + if v.HeroID == heroCfgId { + amount++ + } + } + return amount } - -func (this *Hero) QueryCardAmount(uId string, cardId int32) (amount uint32) { - return 0 -} - - diff --git a/modules/modulebase.go b/modules/modulebase.go index 8c22c5f66..fc878538a 100644 --- a/modules/modulebase.go +++ b/modules/modulebase.go @@ -131,7 +131,7 @@ func (this *ModuleBase) CheckConsumeRes(uid string, res []*cfg.Game_atn) (code p code = pb.ErrorCode_ConfigurationException return } - if amount = int32(hero.QueryCardAmount(uid, int32(resID))); amount < v.N { + if amount = int32(hero.QueryHeroAmount(uid, int32(resID))); amount < v.N { code = pb.ErrorCode_ResNoEnough return } @@ -155,7 +155,7 @@ func (this *ModuleBase) CheckConsumeRes(uid string, res []*cfg.Game_atn) (code p items.AddItem(source, uid, int32(resID), -1*v.N) } else if v.A == comm.CardType { //卡片资源 resID, _ = strconv.Atoi(v.T) - hero.AddCard(uid, int32(resID), -1*v.N) + hero.ChangeCard(uid, int32(resID), -1*v.N) } else if v.A == comm.EquipmentType { resID, _ = strconv.Atoi(v.T) equipment.AddNewEquipments(source, uid, resID, -1*v.N) diff --git a/modules/user/api_create.go b/modules/user/api_create.go index 0d3c08d3f..18aaf68a6 100644 --- a/modules/user/api_create.go +++ b/modules/user/api_create.go @@ -39,8 +39,13 @@ func (this *Api_Comp) Create(session comm.IUserSession, result map[string]interf return } - //初始化英雄 - // this.hero. + //初始化英雄卡 + defaultHero := []int32{15001, 25001} //TODO 从配置中读取 + err = this.hero.CreatHero(session.GetUserId(), defaultHero...) + if err != nil { + code = pb.ErrorCode_HeroInitCreat + return + } return } diff --git a/pb/errorcode.pb.go b/pb/errorcode.pb.go index dd2fe4dbc..7f19da7fd 100644 --- a/pb/errorcode.pb.go +++ b/pb/errorcode.pb.go @@ -65,9 +65,10 @@ const ( ErrorCode_ItemsGridNumUpper ErrorCode = 1202 //背包格子数量已达上限 ErrorCode_ItemsGirdAmountUpper ErrorCode = 1203 //背包格子容量已达上限 // hero - ErrorCode_HeroNoExist ErrorCode = 1300 //英雄不存在 - ErrorCode_HeroNoEnough ErrorCode = 1301 //英雄数量不足 - ErrorCode_HeroMaxLv ErrorCode = 1302 //英雄达到最大等级 + ErrorCode_HeroNoExist ErrorCode = 1300 //英雄不存在 + ErrorCode_HeroNoEnough ErrorCode = 1301 //英雄数量不足 + ErrorCode_HeroMaxLv ErrorCode = 1302 //英雄达到最大等级 + ErrorCode_HeroInitCreat ErrorCode = 1303 //初始化英雄 // equipment ErrorCode_EquipmentOnFoundEquipment ErrorCode = 1400 // 未找到武器 ErrorCode_EquipmentLvlimitReached ErrorCode = 1401 // 武器等级已达上限 @@ -117,6 +118,7 @@ var ( 1300: "HeroNoExist", 1301: "HeroNoEnough", 1302: "HeroMaxLv", + 1303: "HeroInitCreat", 1400: "EquipmentOnFoundEquipment", 1401: "EquipmentLvlimitReached", } @@ -162,6 +164,7 @@ var ( "HeroNoExist": 1300, "HeroNoEnough": 1301, "HeroMaxLv": 1302, + "HeroInitCreat": 1303, "EquipmentOnFoundEquipment": 1400, "EquipmentLvlimitReached": 1401, } @@ -198,7 +201,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, 0x92, 0x07, 0x0a, 0x09, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x12, + 0x6f, 0x2a, 0xa6, 0x07, 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, @@ -251,12 +254,13 @@ var file_errorcode_proto_rawDesc = []byte{ 0x10, 0xb3, 0x09, 0x12, 0x10, 0x0a, 0x0b, 0x48, 0x65, 0x72, 0x6f, 0x4e, 0x6f, 0x45, 0x78, 0x69, 0x73, 0x74, 0x10, 0x94, 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, + 0x4d, 0x61, 0x78, 0x4c, 0x76, 0x10, 0x96, 0x0a, 0x12, 0x12, 0x0a, 0x0d, 0x48, 0x65, 0x72, 0x6f, + 0x49, 0x6e, 0x69, 0x74, 0x43, 0x72, 0x65, 0x61, 0x74, 0x10, 0x97, 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/proto/errorcode.proto b/pb/proto/errorcode.proto index cc4387390..9c0f0aa45 100644 --- a/pb/proto/errorcode.proto +++ b/pb/proto/errorcode.proto @@ -48,10 +48,11 @@ enum ErrorCode { ItemsGirdAmountUpper = 1203; //背包格子容量已达上限 // hero - HeroNoExist = 1300; //英雄不存在 - HeroNoEnough = 1301; //英雄数量不足 - HeroMaxLv = 1302; //英雄达到最大等级 + HeroNoExist = 1300; //英雄不存在 + HeroNoEnough = 1301; //英雄数量不足 + HeroMaxLv = 1302; //英雄达到最大等级 + HeroInitCreat = 1303; //初始化英雄 // equipment EquipmentOnFoundEquipment = 1400; // 未找到武器 - EquipmentLvlimitReached = 1401; // 武器等级已达上限 + EquipmentLvlimitReached = 1401; // 武器等级已达上限 } \ No newline at end of file diff --git a/sys/configure/structs/game.atn.go b/sys/configure/structs/game.atn.go index 67a89b5b5..2a9b45be8 100644 --- a/sys/configure/structs/game.atn.go +++ b/sys/configure/structs/game.atn.go @@ -1,4 +1,3 @@ - //------------------------------------------------------------------------------ // // This code was generated by a tool. @@ -11,19 +10,39 @@ package cfg import "errors" type Game_atn struct { - A string - T string - N int32 + A string //资源类型 + T string //资源名称 + N int32 //数量 } func (Game_atn) GetTypeId() int { - return -1770297697 + return -1770297697 } func NewGame_atn(_buf map[string]interface{}) (_v *Game_atn, err error) { - _v = &Game_atn{} - { var _ok_ bool; if _v.A, _ok_ = _buf["a"].(string); !_ok_ { err = errors.New("a error"); return } } - { var _ok_ bool; if _v.T, _ok_ = _buf["t"].(string); !_ok_ { err = errors.New("t error"); return } } - { var _ok_ bool; var _tempNum_ float64; if _tempNum_, _ok_ = _buf["n"].(float64); !_ok_ { err = errors.New("n error"); return }; _v.N = int32(_tempNum_) } - return + _v = &Game_atn{} + { + var _ok_ bool + if _v.A, _ok_ = _buf["a"].(string); !_ok_ { + err = errors.New("a error") + return + } + } + { + var _ok_ bool + if _v.T, _ok_ = _buf["t"].(string); !_ok_ { + err = errors.New("t error") + return + } + } + { + var _ok_ bool + var _tempNum_ float64 + if _tempNum_, _ok_ = _buf["n"].(float64); !_ok_ { + err = errors.New("n error") + return + } + _v.N = int32(_tempNum_) + } + return }