叠加英雄处理

This commit is contained in:
zhaocy 2022-07-18 17:10:29 +08:00
parent 76dfb1651f
commit 62703c4cde
12 changed files with 101 additions and 75 deletions

View File

@ -24,7 +24,7 @@ var (
fmt.Printf("%d- %v\n", (i + 1), v) fmt.Printf("%d- %v\n", (i + 1), v)
} }
}, },
enabled: true, // enabled: true,
next: func(robot *Robot, rsp proto.Message) { next: func(robot *Robot, rsp proto.Message) {
tcs := []*TestCase{} tcs := []*TestCase{}
if r, ok := rsp.(*pb.HeroListResp); ok { if r, ok := rsp.(*pb.HeroListResp); ok {
@ -119,7 +119,7 @@ var (
HeroObjID: heroId, HeroObjID: heroId,
}, },
rsp: &pb.HeroAwakenResp{}, rsp: &pb.HeroAwakenResp{},
//enabled: true, enabled: true,
} }
tcs = append(tcs, tc3) tcs = append(tcs, tc3)
} }

View File

@ -35,16 +35,16 @@ var user_builders = []*TestCase{
{ {
desc: "添加资源", desc: "添加资源",
mainType: string(comm.ModuleUser), mainType: string(comm.ModuleUser),
subType: "addres", subType: user.UserSubTypeAddRes,
req: &pb.UserAddResReq{ req: &pb.UserAddResReq{
Res: &pb.UserAssets{ Res: &pb.UserAssets{
A: "item", A: "hero",
T: "10001", T: "25001",
N: 1, N: 1,
}, },
}, },
rsp: &pb.UserAddResResp{}, rsp: &pb.UserAddResResp{},
//enabled: true, enabled: true,
}, },
} }

View File

@ -36,8 +36,9 @@ type (
//查询用户卡片数量 //查询用户卡片数量
QueryHeroAmount(uId string, heroCfgId int32) (amount uint32) QueryHeroAmount(uId string, heroCfgId int32) (amount uint32)
//创建新英雄 //创建新英雄
CreateHero(uid string, bPush bool, heroCfgId ...int32) error CreateHeroes(uid string, heroCfgId ...int32) error
//创建指定数量
CreateRepeatHero(uid string, heroCfgId, num int32) (*pb.DBHero, error)
// 获取英雄 // 获取英雄
// heroId 英雄ID // heroId 英雄ID
GetHero(uid, heroId string) (*pb.DBHero, pb.ErrorCode) GetHero(uid, heroId string) (*pb.DBHero, pb.ErrorCode)

View File

@ -27,7 +27,7 @@ func (this *apiComp) Chouka(session comm.IUserSession, req *pb.HeroChoukaReq) (c
}() }()
heroCfgIds := req.HeroIds heroCfgIds := req.HeroIds
if err := this.module.modelHero.createMultiHero(session.GetUserId(), false, heroCfgIds...); err != nil { if err := this.module.modelHero.createMultiHero(session.GetUserId(), heroCfgIds...); err != nil {
code = pb.ErrorCode_HeroCreate code = pb.ErrorCode_HeroCreate
return return
} }

View File

@ -118,7 +118,7 @@ func (this *apiComp) Resonance(session comm.IUserSession, req *pb.HeroResonanceR
return return
} }
for i := 0; i < int(v.N); i++ { // 有多少张加多少次 for i := 0; i < int(v.N); i++ { // 有多少张加多少次
this.module.modelHero.createOneHero(session.GetUserId(), int32(value), true) this.module.modelHero.createOneHero(session.GetUserId(), int32(value))
} }
} }
} }

View File

@ -25,7 +25,7 @@ func (this *apiComp) GetSpecified(session comm.IUserSession, req *pb.HeroGetSpec
if code != pb.ErrorCode_Success { if code != pb.ErrorCode_Success {
return return
} }
hero, err := this.module.modelHero.createOneHeroObj(session.GetUserId(), req.HeroCoinfigID, false) hero, err := this.module.modelHero.createOneHero(session.GetUserId(), req.HeroCoinfigID)
if err != nil { if err != nil {
hero.Lv = req.Lv hero.Lv = req.Lv
hero.Star = req.Star hero.Star = req.Star

View File

@ -85,26 +85,7 @@ func (this *ModelHero) initHeroSkill(hero *pb.DBHero) []*pb.SkillData {
} }
//创建一个指定的英雄 //创建一个指定的英雄
func (this *ModelHero) createOneHero(uid string, heroCfgId int32, bPush bool) (err error) { func (this *ModelHero) createOneHero(uid string, heroCfgId int32) (hero *pb.DBHero, err error) {
hero := this.initHero(uid, heroCfgId)
if hero != nil {
if err = this.moduleHero.modelHero.AddList(uid, hero.Id, hero); err != nil {
this.moduleHero.Errorf("%v", err)
return
}
}
// 创建英雄成功 向客户端推送数据
if bPush {
if session, ok := this.moduleHero.GetUserSession(uid); ok {
session.SendMsg(string(this.moduleHero.GetType()), "addhero", &pb.AddNewHeroPush{Hero: hero})
err = session.Push()
}
}
return nil
}
func (this *ModelHero) createOneHeroObj(uid string, heroCfgId int32, bPush bool) (hero *pb.DBHero, err error) {
hero = this.initHero(uid, heroCfgId) hero = this.initHero(uid, heroCfgId)
if hero != nil { if hero != nil {
if err = this.moduleHero.modelHero.AddList(uid, hero.Id, hero); err != nil { if err = this.moduleHero.modelHero.AddList(uid, hero.Id, hero); err != nil {
@ -112,11 +93,33 @@ func (this *ModelHero) createOneHeroObj(uid string, heroCfgId int32, bPush bool)
return return
} }
} }
// 创建英雄成功 向客户端推送数据 return
if bPush { }
if session, ok := this.moduleHero.GetUserSession(uid); ok {
session.SendMsg(string(this.moduleHero.GetType()), "addhero", &pb.AddNewHeroPush{Hero: hero}) //叠加英雄 count叠加数量
err = session.Push() func (this *ModelHero) createHeroOverlying(uid string, heroCfgId, count int32) (hero *pb.DBHero, err error) {
heroes := this.moduleHero.modelHero.getHeroList(uid)
if len(heroes) == 0 {
hero = this.initHero(uid, heroCfgId)
if hero != nil {
hero.SameCount = count
if err = this.moduleHero.modelHero.AddList(uid, hero.Id, hero); err != nil {
this.moduleHero.Errorf("%v", err)
return
}
}
} else {
for _, h := range heroes {
if h.HeroID == heroCfgId &&
h.IsOverlying {
h.SameCount++
data := map[string]interface{}{
"sameCount": h.SameCount, //叠加数
}
if err := this.modifyHeroData(uid, h.Id, data); err != nil {
return nil, err
}
}
} }
} }
@ -124,12 +127,12 @@ func (this *ModelHero) createOneHeroObj(uid string, heroCfgId int32, bPush bool)
} }
//创建多个指定的英雄 heroCfgIds可填入多个英雄ID //创建多个指定的英雄 heroCfgIds可填入多个英雄ID
func (this *ModelHero) createMultiHero(uid string, bPush bool, heroCfgIds ...int32) error { func (this *ModelHero) createMultiHero(uid string, heroCfgIds ...int32) error {
heroes := this.moduleHero.modelHero.getHeroList(uid) heroes := this.moduleHero.modelHero.getHeroList(uid)
if len(heroes) == 0 { if len(heroes) == 0 {
for _, v := range heroCfgIds { for _, v := range heroCfgIds {
if err := this.createOneHero(uid, v, bPush); err != nil { if _, err := this.createOneHero(uid, v); err != nil {
return err return err
} }
} }
@ -154,13 +157,13 @@ func (this *ModelHero) createMultiHero(uid string, bPush bool, heroCfgIds ...int
return err return err
} }
} else { } else {
if err := this.createOneHero(uid, v, bPush); err != nil { if _, err := this.createOneHero(uid, v); err != nil {
return err return err
} }
} }
} else { } else {
if err := this.createOneHero(uid, v, bPush); err != nil { if _, err := this.createOneHero(uid, v); err != nil {
return err return err
} }
} }

View File

@ -39,8 +39,13 @@ func (this *Hero) OnInstallComp() {
} }
//创建新英雄 //创建新英雄
func (this *Hero) CreateHero(uid string, bPush bool, heroCfgId ...int32) error { func (this *Hero) CreateHeroes(uid string, heroCfgId ...int32) error {
return this.modelHero.createMultiHero(uid, bPush, heroCfgId...) return this.modelHero.createMultiHero(uid, heroCfgId...)
}
//创建叠加英雄
func (this *Hero) CreateRepeatHero(uid string, heroCfgId, num int32) (*pb.DBHero, error) {
return this.modelHero.createHeroOverlying(uid, heroCfgId, num)
} }
//获取英雄 //获取英雄

View File

@ -232,10 +232,19 @@ func (this *ModuleBase) DispenseRes(uid string, res []*cfg.Game_atn, bPush bool)
code = this.ModuleItems.AddItem(source, uid, int32(resID), v.N, bPush) code = this.ModuleItems.AddItem(source, uid, int32(resID), v.N, bPush)
} else if v.A == comm.HeroType { //卡片资源 } else if v.A == comm.HeroType { //卡片资源
resID, _ = strconv.Atoi(v.T) resID, _ = strconv.Atoi(v.T)
err := this.ModuleHero.CreateHero(uid, bPush, int32(resID)) hero, err := this.ModuleHero.CreateRepeatHero(uid, int32(resID), v.N)
if err != nil { if err != nil {
code = pb.ErrorCode_HeroMaxCount code = pb.ErrorCode_HeroMaxCount
} }
// 创建英雄成功 向客户端推送数据
if bPush {
if session, ok := this.GetUserSession(uid); ok {
session.SendMsg("push", "addhero", &pb.AddNewHeroPush{Hero: hero, Count: v.N})
err = session.Push()
}
}
} else if v.A == comm.EquipmentType { } else if v.A == comm.EquipmentType {
resID, _ = strconv.Atoi(v.T) resID, _ = strconv.Atoi(v.T)
code = this.ModuleEquipment.AddNewEquipments(source, uid, map[int32]uint32{int32(resID): uint32(v.N)}, bPush) code = this.ModuleEquipment.AddNewEquipments(source, uid, map[int32]uint32{int32(resID): uint32(v.N)}, bPush)

View File

@ -69,7 +69,7 @@ func (this *apiComp) Create(session comm.IUserSession, req *pb.UserCreateReq) (c
//初始化英雄卡 //初始化英雄卡
if val := this.module.configure.GetGlobalConf("init_hero"); val != "" { if val := this.module.configure.GetGlobalConf("init_hero"); val != "" {
defaultHero := utils.TrInt32(val) defaultHero := utils.TrInt32(val)
err = this.hero.CreateHero(session.GetUserId(), true, defaultHero...) err = this.hero.CreateHeroes(session.GetUserId(), defaultHero...)
if err != nil { if err != nil {
code = pb.ErrorCode_HeroInitCreat code = pb.ErrorCode_HeroInitCreat
return return

View File

@ -1322,6 +1322,7 @@ type AddNewHeroPush struct {
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
Hero *DBHero `protobuf:"bytes,1,opt,name=hero,proto3" json:"hero"` // 英雄对象 Hero *DBHero `protobuf:"bytes,1,opt,name=hero,proto3" json:"hero"` // 英雄对象
Count int32 `protobuf:"varint,2,opt,name=count,proto3" json:"count"` //数量
} }
func (x *AddNewHeroPush) Reset() { func (x *AddNewHeroPush) Reset() {
@ -1363,6 +1364,13 @@ func (x *AddNewHeroPush) GetHero() *DBHero {
return nil return nil
} }
func (x *AddNewHeroPush) GetCount() int32 {
if x != nil {
return x.Count
}
return 0
}
// 测试用(获取指定星级等级的英雄) // 测试用(获取指定星级等级的英雄)
type HeroGetSpecifiedReq struct { type HeroGetSpecifiedReq struct {
state protoimpl.MessageState state protoimpl.MessageState
@ -1607,22 +1615,23 @@ var file_hero_hero_msg_proto_rawDesc = []byte{
0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x68, 0x65, 0x72, 0x6f, 0x69, 0x64, 0x22, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x68, 0x65, 0x72, 0x6f, 0x69, 0x64, 0x22,
0x2b, 0x0a, 0x0c, 0x48, 0x65, 0x72, 0x6f, 0x4c, 0x6f, 0x63, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x12, 0x2b, 0x0a, 0x0c, 0x48, 0x65, 0x72, 0x6f, 0x4c, 0x6f, 0x63, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x12,
0x1b, 0x0a, 0x04, 0x68, 0x65, 0x72, 0x6f, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x07, 0x2e, 0x1b, 0x0a, 0x04, 0x68, 0x65, 0x72, 0x6f, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x07, 0x2e,
0x44, 0x42, 0x48, 0x65, 0x72, 0x6f, 0x52, 0x04, 0x68, 0x65, 0x72, 0x6f, 0x22, 0x2d, 0x0a, 0x0e, 0x44, 0x42, 0x48, 0x65, 0x72, 0x6f, 0x52, 0x04, 0x68, 0x65, 0x72, 0x6f, 0x22, 0x43, 0x0a, 0x0e,
0x41, 0x64, 0x64, 0x4e, 0x65, 0x77, 0x48, 0x65, 0x72, 0x6f, 0x50, 0x75, 0x73, 0x68, 0x12, 0x1b, 0x41, 0x64, 0x64, 0x4e, 0x65, 0x77, 0x48, 0x65, 0x72, 0x6f, 0x50, 0x75, 0x73, 0x68, 0x12, 0x1b,
0x0a, 0x04, 0x68, 0x65, 0x72, 0x6f, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x07, 0x2e, 0x44, 0x0a, 0x04, 0x68, 0x65, 0x72, 0x6f, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x07, 0x2e, 0x44,
0x42, 0x48, 0x65, 0x72, 0x6f, 0x52, 0x04, 0x68, 0x65, 0x72, 0x6f, 0x22, 0x77, 0x0a, 0x13, 0x48, 0x42, 0x48, 0x65, 0x72, 0x6f, 0x52, 0x04, 0x68, 0x65, 0x72, 0x6f, 0x12, 0x14, 0x0a, 0x05, 0x63,
0x65, 0x72, 0x6f, 0x47, 0x65, 0x74, 0x53, 0x70, 0x65, 0x63, 0x69, 0x66, 0x69, 0x65, 0x64, 0x52, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x63, 0x6f, 0x75, 0x6e,
0x65, 0x71, 0x12, 0x24, 0x0a, 0x0d, 0x68, 0x65, 0x72, 0x6f, 0x43, 0x6f, 0x69, 0x6e, 0x66, 0x69, 0x74, 0x22, 0x77, 0x0a, 0x13, 0x48, 0x65, 0x72, 0x6f, 0x47, 0x65, 0x74, 0x53, 0x70, 0x65, 0x63,
0x67, 0x49, 0x44, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0d, 0x68, 0x65, 0x72, 0x6f, 0x43, 0x69, 0x66, 0x69, 0x65, 0x64, 0x52, 0x65, 0x71, 0x12, 0x24, 0x0a, 0x0d, 0x68, 0x65, 0x72, 0x6f,
0x6f, 0x69, 0x6e, 0x66, 0x69, 0x67, 0x49, 0x44, 0x12, 0x16, 0x0a, 0x06, 0x41, 0x6d, 0x6f, 0x75, 0x43, 0x6f, 0x69, 0x6e, 0x66, 0x69, 0x67, 0x49, 0x44, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52,
0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x41, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x0d, 0x68, 0x65, 0x72, 0x6f, 0x43, 0x6f, 0x69, 0x6e, 0x66, 0x69, 0x67, 0x49, 0x44, 0x12, 0x16,
0x12, 0x12, 0x0a, 0x04, 0x73, 0x74, 0x61, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x0a, 0x06, 0x41, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06,
0x73, 0x74, 0x61, 0x72, 0x12, 0x0e, 0x0a, 0x02, 0x6c, 0x76, 0x18, 0x04, 0x20, 0x01, 0x28, 0x05, 0x41, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x73, 0x74, 0x61, 0x72, 0x18, 0x03,
0x52, 0x02, 0x6c, 0x76, 0x22, 0x33, 0x0a, 0x14, 0x48, 0x65, 0x72, 0x6f, 0x47, 0x65, 0x74, 0x53, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x73, 0x74, 0x61, 0x72, 0x12, 0x0e, 0x0a, 0x02, 0x6c, 0x76,
0x70, 0x65, 0x63, 0x69, 0x66, 0x69, 0x65, 0x64, 0x52, 0x65, 0x73, 0x70, 0x12, 0x1b, 0x0a, 0x04, 0x18, 0x04, 0x20, 0x01, 0x28, 0x05, 0x52, 0x02, 0x6c, 0x76, 0x22, 0x33, 0x0a, 0x14, 0x48, 0x65,
0x68, 0x65, 0x72, 0x6f, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x07, 0x2e, 0x44, 0x42, 0x48, 0x72, 0x6f, 0x47, 0x65, 0x74, 0x53, 0x70, 0x65, 0x63, 0x69, 0x66, 0x69, 0x65, 0x64, 0x52, 0x65,
0x65, 0x72, 0x6f, 0x52, 0x04, 0x68, 0x65, 0x72, 0x6f, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x73, 0x70, 0x12, 0x1b, 0x0a, 0x04, 0x68, 0x65, 0x72, 0x6f, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b,
0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, 0x32, 0x07, 0x2e, 0x44, 0x42, 0x48, 0x65, 0x72, 0x6f, 0x52, 0x04, 0x68, 0x65, 0x72, 0x6f, 0x42,
0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
} }
var ( var (

View File

@ -116,9 +116,7 @@ message HeroProperty {
} }
// //
message HeroLockReq{ message HeroLockReq { string heroid = 1; }
string heroid = 1;
}
// //
message HeroLockResp { message HeroLockResp {
@ -128,6 +126,7 @@ message HeroLockResp{
// //
message AddNewHeroPush { message AddNewHeroPush {
DBHero hero = 1; // DBHero hero = 1; //
int32 count = 2; //
} }
// //