This commit is contained in:
liwei1dao 2022-10-27 15:48:11 +08:00
commit da347d68fe
5 changed files with 47 additions and 69 deletions

View File

@ -34,8 +34,7 @@ type (
IHero interface {
//查询用户卡片数量
QueryHeroAmount(uId string, heroCfgId string) (amount uint32)
//创建新英雄
CreateHeroes(uid string, heroCfgId ...string) error
//创建指定数量
CreateRepeatHero(session IUserSession, heroCfgId string, num int32, bPush bool) (code pb.ErrorCode)
// 批量创建英雄

View File

@ -47,7 +47,6 @@ func (this *apiComp) GetRandUser(session comm.IUserSession, req *pb.GourmetGetRa
if v.Uid == session.GetUserId() || v.Uid == "" { // 过滤自己信息
continue
}
mapUser[v.Uid] = struct{}{}
szUid = append(szUid, v.Uid)
}
// 随机在线玩家信息

View File

@ -9,6 +9,7 @@ import (
"go_dreamfactory/modules"
"go_dreamfactory/pb"
cfg "go_dreamfactory/sys/configure/structs"
"go_dreamfactory/sys/db"
"go_dreamfactory/utils"
"math"
"math/big"
@ -126,91 +127,77 @@ 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) {
var (
model *db.DBModel
)
hero = this.InitHero(uid, heroCfgId)
if hero != nil {
hero.SameCount = count
if err = this.AddList(uid, hero.Id, hero); err != nil {
this.moduleHero.Errorf("%v", err)
return
if this.moduleHero.IsCross() {
if model, err = this.moduleHero.GetDBNoduleByUid(uid, this.TableName, this.Expired); err != nil {
this.moduleHero.Errorln(err)
} else {
if err = model.AddLists(uid, hero); err != nil {
this.moduleHero.Errorf("err:%v", err)
}
}
} else {
if err = this.AddLists(uid, hero); err != nil {
this.moduleHero.Errorln(err)
}
}
}
return
}
// 该方法适用创建初始英雄 叠加英雄 count叠加数量
func (this *ModelHero) createHeroOverlying(uid string, heroCfgId string, count int32) (hero *pb.DBHero, err error) {
heroes := this.getHeroList(uid)
if len(heroes) == 0 {
return this.initHeroOverlying(uid, heroCfgId, count)
heros := make([]*pb.DBHero, 0)
if this.moduleHero.IsCross() {
if dbModel, err := this.moduleHero.GetDBNoduleByUid(uid, this.TableName, this.Expired); err != nil {
this.moduleHero.Errorln(err)
} else {
var isExist bool
for _, h := range heroes {
if err = dbModel.GetList(uid, &heros); err != nil {
this.moduleHero.Errorf("err:%v", err)
}
}
} else {
if err = this.GetList(uid, &heros); err != nil {
this.moduleHero.Errorf("err:%v", err)
}
}
if len(heros) >= 0 {
for _, h := range heros {
if h.HeroID == heroCfgId &&
h.IsOverlying {
isExist = true
h.SameCount += count
data := map[string]interface{}{
"sameCount": h.SameCount, //叠加数
}
hero = h
if this.moduleHero.IsCross() {
if model, err := this.moduleHero.GetDBNoduleByUid(uid, this.TableName, this.Expired); err != nil {
this.moduleHero.Errorln(err)
} else {
if err := model.ChangeList(uid, h.Id, data); err != nil {
return nil, err
}
}
} else {
if err := this.ChangeList(uid, h.Id, data); err != nil {
return nil, err
}
}
}
if !isExist {
return this.initHeroOverlying(uid, heroCfgId, count)
}
}
return
}
//创建多个指定的英雄 heroCfgIds可填入多个英雄ID
func (this *ModelHero) createMultiHero(uid string, heroCfgIds ...string) error {
heroes := this.getHeroList(uid)
if len(heroes) == 0 {
for _, v := range heroCfgIds {
if _, err := this.createOneHero(uid, v); err != nil {
return err
}
}
} else {
findHero := func(heroId string) (*pb.DBHero, bool) {
for _, h := range heroes {
if h.HeroID == heroId {
return h, true
}
}
return nil, false
}
for _, v := range heroCfgIds {
if h, ok := findHero(v); ok {
//允许叠加
if h.IsOverlying {
h.SameCount++
data := map[string]interface{}{
"sameCount": h.SameCount, //叠加数
}
if err := this.ChangeList(uid, h.Id, data); err != nil {
return err
}
} else {
if _, err := this.createOneHero(uid, v); err != nil {
return err
}
}
} else {
if _, err := this.createOneHero(uid, v); err != nil {
return err
}
}
}
}
return nil
return this.initHeroOverlying(uid, heroCfgId, count)
}
//获取一个英雄(参数唯一objID)

View File

@ -61,11 +61,6 @@ func (this *Hero) Start() (err error) {
return
}
//创建新英雄
func (this *Hero) CreateHeroes(uid string, heroCfgId ...string) error {
return this.modelHero.createMultiHero(uid, heroCfgId...)
}
//创建单个叠加英雄
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)
@ -343,7 +338,6 @@ func (this *Hero) CreateMonster(heroCid string, star, lv int32) (hero *pb.DBHero
// 只通过唯一id 查询英雄信息
func (this *Hero) QueryCrossHeroinfo(oid string) (hero *pb.DBHero, err error) {
if this.IsCross() {
for _, tag := range db.GetServerTags() {
conn, err1 := db.ServerDBConn(tag) // 遍历连接对象
@ -361,7 +355,7 @@ func (this *Hero) QueryCrossHeroinfo(oid string) (hero *pb.DBHero, err error) {
this.modelHero.moduleHero.Errorf("find hero error: %v", err)
}
}
} else { // 不是跨服就查本服
} else { // 不是跨服就查本服 注意 这个接口是给跨服玩法调用 理论上这个分支是不会执行的
if res := this.modelHero.DB.FindOne(comm.TableHero, bson.M{
"_id": oid,
}); res == nil {

View File

@ -47,7 +47,6 @@ func (this *apiComp) GetRandUser(session comm.IUserSession, req *pb.SmithyGetRan
if v.Uid == session.GetUserId() || v.Uid == "" { // 过滤自己信息
continue
}
mapUser[v.Uid] = struct{}{}
szUid = append(szUid, v.Uid)
}
// 随机在线玩家信息