创建单个英雄接口调整

This commit is contained in:
meixiongfeng 2022-08-11 19:45:16 +08:00
parent da4f77d8e9
commit 0e0c88c29a
4 changed files with 70 additions and 41 deletions

View File

@ -38,7 +38,7 @@ type (
//创建新英雄
CreateHeroes(uid string, heroCfgId ...string) error
//创建指定数量
CreateRepeatHero(uid string, heroCfgId string, num int32) (*pb.DBHero, error)
CreateRepeatHero(session IUserSession, heroCfgId string, num int32, bPush bool) (code pb.ErrorCode)
// 批量创建英雄
CreateRepeatHeros(session IUserSession, heros map[string]int32, bPush bool) (code pb.ErrorCode)
// 获取英雄

View File

@ -42,20 +42,22 @@ func (this *ModelHero) initHero(uid string, heroCfgId string) *pb.DBHero {
}
objId := primitive.NewObjectID().Hex()
newHero := &pb.DBHero{
Id: objId,
Uid: uid,
HeroID: heroCfg.Hid,
Star: heroCfg.Star, //初始星级
Lv: 1, //初始等级
IsOverlying: true, //是否允许叠加,
Block: false, //未锁定
CardType: heroCfg.Type, //卡片类型
Skins: []int32{},
EquipID: make([]string, 6), //初始装备
SameCount: 1, //默认叠加数量
AddProperty: make(map[string]int32),
Energy: make(map[string]int32),
Property: make(map[string]int32),
Id: objId,
Uid: uid,
HeroID: heroCfg.Hid,
Star: heroCfg.Star, //初始星级
Lv: 1, //初始等级
IsOverlying: true, //是否允许叠加,
Block: false, //未锁定
CardType: heroCfg.Type, //卡片类型
Skins: []int32{},
EquipID: make([]string, 6), //初始装备
SameCount: 1, //默认叠加数量
AddProperty: make(map[string]int32),
Energy: make(map[string]int32),
Property: make(map[string]int32),
EnergyProperty: make(map[string]int32),
JuexProperty: make(map[string]int32),
}
this.PropertyCompute(newHero)
this.initHeroSkill(newHero)
@ -113,24 +115,6 @@ func (this *ModelHero) CloneNewHero(hero *pb.DBHero) (newHero *pb.DBHero) {
func (this *ModelHero) initHeroOverlying(uid string, heroCfgId string, count int32) (hero *pb.DBHero, err error) {
hero = this.initHero(uid, heroCfgId)
if hero != nil {
// 添加图鉴
go func(uid, heroCfgId string) { // 携程处理 图鉴数据
if result, err1 := this.moduleHero.ModuleUser.GetUserExpand(uid); err1 == nil {
if _, ok := result.GetTujian()[heroCfgId]; !ok {
sz := result.GetTujian()
if len(sz) == 0 {
sz = make(map[string]bool, 0)
}
sz[heroCfgId] = true
initUpdate := map[string]interface{}{
"tujian": sz,
}
this.moduleHero.ModuleUser.ChangeUserExpand(uid, initUpdate)
}
}
}(uid, heroCfgId)
hero.SameCount = count
if err = this.AddList(uid, hero.Id, hero); err != nil {

View File

@ -53,9 +53,35 @@ func (this *Hero) CreateHeroes(uid string, heroCfgId ...string) error {
return this.modelHero.createMultiHero(uid, heroCfgId...)
}
//创建叠加英雄
func (this *Hero) CreateRepeatHero(uid string, heroCfgId string, num int32) (*pb.DBHero, error) {
return this.modelHero.createHeroOverlying(uid, heroCfgId, num)
//创建单个叠加英雄
func (this *Hero) CreateRepeatHero(session comm.IUserSession, heroCfgId string, num int32, bPush bool) (code pb.ErrorCode) {
_hero, err := this.modelHero.createHeroOverlying(session.GetUserId(), heroCfgId, num)
if err == nil {
go func(uid string, heroCfgId string) { // 携程处理 图鉴数据
if result, err1 := this.ModuleUser.GetUserExpand(uid); err1 == nil {
initUpdate := map[string]interface{}{}
sz := result.GetTujian()
if len(sz) == 0 {
sz = make(map[string]bool, 0)
}
if _, ok := result.GetTujian()[heroCfgId]; !ok {
sz[heroCfgId] = true
initUpdate["tujian"] = sz
}
if len(initUpdate) != 0 {
this.ModuleUser.ChangeUserExpand(uid, initUpdate)
}
}
}(session.GetUserId(), heroCfgId)
if bPush { //推送
session.SendMsg("hero", "change", &pb.HeroChangePush{List: []*pb.DBHero{_hero}})
}
return
}
code = pb.ErrorCode_HeroCreate
return
}
//获取英雄
@ -168,11 +194,30 @@ func (this *Hero) CreateRepeatHeros(session comm.IUserSession, heros map[string]
hero, err := this.modelHero.createHeroOverlying(session.GetUserId(), heroCfgId, num)
if err != nil {
code = pb.ErrorCode_HeroCreate
return
continue
}
changeHero = append(changeHero, hero)
}
// 添加图鉴
go func(uid string, heros map[string]int32) { // 携程处理 图鉴数据
if result, err1 := this.ModuleUser.GetUserExpand(uid); err1 == nil {
initUpdate := map[string]interface{}{}
sz := result.GetTujian()
if len(sz) == 0 {
sz = make(map[string]bool, 0)
}
for k := range heros {
if _, ok := result.GetTujian()[k]; !ok {
sz[k] = true
initUpdate["tujian"] = sz
}
}
if len(initUpdate) != 0 {
this.ModuleUser.ChangeUserExpand(uid, initUpdate)
}
}
}(session.GetUserId(), heros)
if bPush && len(changeHero) > 0 { //推送
session.SendMsg("hero", "change", &pb.HeroChangePush{List: changeHero})
}

View File

@ -104,7 +104,7 @@ type DBHero struct {
SuiteExtId int32 `protobuf:"varint,22,opt,name=suiteExtId,proto3" json:"suiteExtId"` // go_tags(`bson:"suiteExtId"`) 扩展套装Id
IsOverlying bool `protobuf:"varint,23,opt,name=isOverlying,proto3" json:"isOverlying"` // go_tags(`bson:"isOverlying"`) 是否允许叠加 默认true
EnergyProperty map[string]int32 `protobuf:"bytes,24,rep,name=energyProperty,proto3" json:"energyProperty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3" bson:"energyProperty"` //
JuexProperty map[string]int32 `protobuf:"bytes,25,rep,name=JuexProperty,proto3" json:"JuexProperty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3" bson:"energyProperty"` ////hp
JuexProperty map[string]int32 `protobuf:"bytes,25,rep,name=juexProperty,proto3" json:"juexProperty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3" bson:"juexProperty"` ////hp
}
func (x *DBHero) Reset() {
@ -547,10 +547,10 @@ var file_hero_hero_db_proto_rawDesc = []byte{
0x32, 0x1b, 0x2e, 0x44, 0x42, 0x48, 0x65, 0x72, 0x6f, 0x2e, 0x45, 0x6e, 0x65, 0x72, 0x67, 0x79,
0x50, 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, 0x79, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x0e, 0x65,
0x6e, 0x65, 0x72, 0x67, 0x79, 0x50, 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, 0x79, 0x12, 0x3d, 0x0a,
0x0c, 0x4a, 0x75, 0x65, 0x78, 0x50, 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, 0x79, 0x18, 0x19, 0x20,
0x0c, 0x6a, 0x75, 0x65, 0x78, 0x50, 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, 0x79, 0x18, 0x19, 0x20,
0x03, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x44, 0x42, 0x48, 0x65, 0x72, 0x6f, 0x2e, 0x4a, 0x75, 0x65,
0x78, 0x50, 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, 0x79, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x0c,
0x4a, 0x75, 0x65, 0x78, 0x50, 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, 0x79, 0x1a, 0x3b, 0x0a, 0x0d,
0x6a, 0x75, 0x65, 0x78, 0x50, 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, 0x79, 0x1a, 0x3b, 0x0a, 0x0d,
0x50, 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, 0x79, 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,
@ -624,7 +624,7 @@ var file_hero_hero_db_proto_depIdxs = []int32{
5, // 2: DBHero.addProperty:type_name -> DBHero.AddPropertyEntry
6, // 3: DBHero.energy:type_name -> DBHero.EnergyEntry
7, // 4: DBHero.energyProperty:type_name -> DBHero.EnergyPropertyEntry
8, // 5: DBHero.JuexProperty:type_name -> DBHero.JuexPropertyEntry
8, // 5: DBHero.juexProperty:type_name -> DBHero.JuexPropertyEntry
2, // 6: DBHeroRecord.race0:type_name -> Floor
2, // 7: DBHeroRecord.race1:type_name -> Floor
2, // 8: DBHeroRecord.race2:type_name -> Floor