抽卡优化
This commit is contained in:
parent
a58a7ddb0c
commit
0a559e13ab
@ -274,43 +274,45 @@ func (this *apiComp) DrawCard(session comm.IUserSession, req *pb.HeroDrawCardReq
|
||||
heroId = heroRecord.LimitHero // 替换成心愿英雄
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if req.DrawType == 1 {
|
||||
if _, atno, err = this.module.modelHero.imitateHero(session, heroId); err == nil {
|
||||
rsp.Data = append(rsp.Data, &pb.AtnoData{Atno: atno})
|
||||
} else {
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_HeroNoExist,
|
||||
Title: pb.ErrorCode_HeroNoExist.ToString(),
|
||||
Message: err.Error(),
|
||||
}
|
||||
return
|
||||
}
|
||||
} else {
|
||||
hero := &pb.DBHero{}
|
||||
if hero, atno, errdata = this.module.CreateOneHero(session, heroId); errdata == nil {
|
||||
for _, v := range atno {
|
||||
if v.A == "hero" && v.T == heroId && v.N == 1 {
|
||||
if user, err := this.module.ModuleUser.GetUser(session.GetUserId()); err == nil { // 广播 首次获得英雄
|
||||
this.chat.SendSysChatToWorld(comm.ChatSystem13, hero, HeroConf.Star, 0, user.Name, v.T)
|
||||
}
|
||||
var (
|
||||
res [][]*cfg.Gameatn
|
||||
add []*pb.DBHero
|
||||
allres []*cfg.Gameatn
|
||||
)
|
||||
if res, add, err = this.module.modelHero.ImitateHeros(session, szCards); err == nil {
|
||||
for _, v := range res {
|
||||
var atno []*pb.UserAtno
|
||||
for _, v1 := range v {
|
||||
if v1.A != "hero" { // 不发英雄
|
||||
allres = append(allres, v1)
|
||||
}
|
||||
atno = append(atno, &pb.UserAtno{
|
||||
A: v1.A,
|
||||
T: v1.T,
|
||||
N: v1.N,
|
||||
})
|
||||
}
|
||||
rsp.Data = append(rsp.Data, &pb.AtnoData{Atno: atno})
|
||||
}
|
||||
}
|
||||
}
|
||||
// if req.DrawType != 1 {
|
||||
// if _, rsp.Data, errdata = this.module.DrawCardHero(session, szCards); errdata != nil {
|
||||
// return
|
||||
// }
|
||||
// }
|
||||
|
||||
if req.DrawType == 1 {
|
||||
heroRecord.Selectcount += 1 // 抽卡次数+1
|
||||
heroRecord.Cur = szCards
|
||||
update["selectcount"] = heroRecord.Selectcount
|
||||
update["cur"] = heroRecord.Cur
|
||||
} else { // 非模拟抽不发奖
|
||||
var szHero []*pb.DBHero
|
||||
for _, hero := range add { // 奖励一次性发放
|
||||
if user, err := this.module.ModuleUser.GetUser(session.GetUserId()); err == nil { // 广播 首次获得英雄
|
||||
HeroConf, _ := this.module.configure.GetHeroConfig(hero.HeroID)
|
||||
this.chat.SendSysChatToWorld(comm.ChatSystem13, hero, HeroConf.Star, 0, user.Name, hero.HeroID)
|
||||
}
|
||||
szHero = append(szHero, hero)
|
||||
}
|
||||
this.module.HeroLibrary(session, szCards, szHero)
|
||||
this.module.DispenseAtno(session, allres, true)
|
||||
}
|
||||
this.module.modelRecord.ChangeHeroRecord(session.GetUserId(), update)
|
||||
|
||||
|
@ -14,8 +14,13 @@ func (this *apiComp) DrawCardFloorCheck(session comm.IUserSession, req *pb.HeroD
|
||||
func (this *apiComp) DrawCardFloor(session comm.IUserSession, req *pb.HeroDrawCardFloorReq) (errdata *pb.ErrorData) {
|
||||
var err error
|
||||
rsp := &pb.HeroDrawCardFloorResp{}
|
||||
if rsp.Record, err = this.module.modelRecord.GetHeroRecord(session.GetUserId()); err == nil {
|
||||
|
||||
if rsp.Record, err = this.module.modelRecord.GetHeroRecord(session.GetUserId()); err != nil {
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_DBError,
|
||||
Title: pb.ErrorCode_DBError.ToString(),
|
||||
Message: err.Error(),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
session.SendMsg(string(this.module.GetType()), DrawCardFloor, rsp)
|
||||
|
@ -55,32 +55,38 @@ func (this *apiComp) SelectCard(session comm.IUserSession, req *pb.HeroSelectCar
|
||||
}
|
||||
return
|
||||
}
|
||||
for _, heroId := range curSzCard {
|
||||
var (
|
||||
hero *pb.DBHero
|
||||
HeroConf *cfg.GameHeroData
|
||||
res [][]*cfg.Gameatn
|
||||
add []*pb.DBHero
|
||||
allres []*cfg.Gameatn
|
||||
)
|
||||
if HeroConf, err = this.module.configure.GetHeroConfig(heroId); err != nil {
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_ConfigNoFound,
|
||||
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
||||
Message: err.Error(),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if res, add, err = this.module.modelHero.ImitateHeros(session, curSzCard); err == nil {
|
||||
for _, v := range res {
|
||||
var atno []*pb.UserAtno
|
||||
if hero, atno, errdata = this.module.CreateOneHero(session, heroId); errdata == nil {
|
||||
for _, v := range atno {
|
||||
if v.A == "hero" && v.T == heroId && v.N == 1 {
|
||||
if user, err := this.module.ModuleUser.GetUser(session.GetUserId()); err == nil { // 广播 首次获得英雄
|
||||
this.chat.SendSysChatToWorld(comm.ChatSystem13, hero, HeroConf.Star, 0, user.Name, v.T)
|
||||
}
|
||||
for _, v1 := range v {
|
||||
if v1.A != "hero" { // 不发英雄
|
||||
allres = append(allres, v1)
|
||||
}
|
||||
atno = append(atno, &pb.UserAtno{
|
||||
A: v1.A,
|
||||
T: v1.T,
|
||||
N: v1.N,
|
||||
})
|
||||
}
|
||||
szAtno = append(szAtno, &pb.AtnoData{Atno: atno})
|
||||
}
|
||||
}
|
||||
var szHero []*pb.DBHero
|
||||
for _, hero := range add { // 奖励一次性发放
|
||||
if user, err := this.module.ModuleUser.GetUser(session.GetUserId()); err == nil { // 广播 首次获得英雄
|
||||
HeroConf, _ := this.module.configure.GetHeroConfig(hero.HeroID)
|
||||
this.chat.SendSysChatToWorld(comm.ChatSystem13, hero, HeroConf.Star, 0, user.Name, hero.HeroID)
|
||||
}
|
||||
szHero = append(szHero, hero)
|
||||
}
|
||||
this.module.HeroLibrary(session, curSzCard, szHero)
|
||||
this.module.DispenseAtno(session, allres, true)
|
||||
this.module.DispenseAtno(session, allres, true)
|
||||
|
||||
heroRecord.Newcomplete = true
|
||||
heroRecord.Cur = []string{} // 清空数据
|
||||
|
@ -1115,3 +1115,114 @@ func (this *ModelHero) drawcardcreateHero(session comm.IUserSession, ids []strin
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// 模拟获得英雄
|
||||
func (this *ModelHero) ImitateHeros(session comm.IUserSession, cids []string) (addres [][]*cfg.Gameatn, add []*pb.DBHero, err error) {
|
||||
|
||||
heros := make([]*pb.DBHero, 0)
|
||||
uid := session.GetUserId()
|
||||
list := this.module.ModuleTools.GetGlobalConf().Moonshopmoney
|
||||
if list == nil {
|
||||
return
|
||||
}
|
||||
rst, err := this.module.ModuleUser.GetUserExpand(session.GetUserId())
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if rst.Expitem == nil {
|
||||
rst.Expitem = make(map[string]int32)
|
||||
}
|
||||
if rst.Herofrag == nil {
|
||||
rst.Herofrag = make(map[string]int32)
|
||||
}
|
||||
if err = this.GetList(uid, &heros); err != nil {
|
||||
this.module.Errorf("err:%v", err)
|
||||
}
|
||||
for _, heroCfgId := range cids {
|
||||
var (
|
||||
res []*cfg.Gameatn
|
||||
)
|
||||
var hero *pb.DBHero
|
||||
heroCfg, _ := this.module.configure.GetHeroConfig(heroCfgId)
|
||||
bFirst := true
|
||||
if heroCfg == nil {
|
||||
err = errors.New("not found hero configID")
|
||||
this.module.Errorf("not found hero configID:%s", heroCfgId)
|
||||
return
|
||||
}
|
||||
|
||||
for _, obj := range heros {
|
||||
if obj.HeroID == heroCfgId {
|
||||
hero = obj
|
||||
bFirst = false
|
||||
res = append(res, &cfg.Gameatn{
|
||||
A: "hero",
|
||||
T: hero.HeroID,
|
||||
N: 0,
|
||||
})
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if bFirst { // 没有当前英雄
|
||||
hero, err = this.initHeroOverlying(uid, heroCfgId, 1)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
res = append(res, &cfg.Gameatn{
|
||||
A: "hero",
|
||||
T: hero.HeroID,
|
||||
N: 1,
|
||||
})
|
||||
heros = append(heros, hero)
|
||||
add = append(add, hero)
|
||||
}
|
||||
|
||||
// 转碎片处理
|
||||
bAdd := false
|
||||
//守护之星 获得
|
||||
if heroCfg.Herofragnum > 0 {
|
||||
if v, ok := rst.Herofrag[hero.HeroID]; !ok {
|
||||
rst.Herofrag[hero.HeroID] = 1
|
||||
bAdd = true
|
||||
} else if heroCfg.Herofragnum > v {
|
||||
rst.Herofrag[hero.HeroID] += 1
|
||||
bAdd = true
|
||||
}
|
||||
}
|
||||
if bAdd {
|
||||
res = append(res, heroCfg.Herofrag...)
|
||||
} else {
|
||||
for pos, v := range list {
|
||||
if int32(pos)+3 == heroCfg.Star && v > 0 {
|
||||
|
||||
res = append(res, &cfg.Gameatn{
|
||||
A: "attr",
|
||||
T: "moongold",
|
||||
N: v,
|
||||
})
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
bAdd = false // 初始化
|
||||
// expitem 获得
|
||||
if heroCfg.Expitemnum > 0 {
|
||||
if v, ok := rst.Expitem[hero.HeroID]; ok {
|
||||
if heroCfg.Expitemnum > v {
|
||||
rst.Expitem[hero.HeroID] += 1
|
||||
bAdd = true
|
||||
}
|
||||
} else {
|
||||
rst.Expitem[hero.HeroID] = 1
|
||||
bAdd = true
|
||||
}
|
||||
}
|
||||
if bAdd {
|
||||
res = append(res, heroCfg.Expitem...)
|
||||
}
|
||||
addres = append(addres, res)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
@ -1062,3 +1062,31 @@ func (this *Hero) DrawCardHero(session comm.IUserSession, heroCfgId []string) (h
|
||||
|
||||
return
|
||||
}
|
||||
func (this *Hero) HeroLibrary(session comm.IUserSession, cids []string, addHero []*pb.DBHero) {
|
||||
var (
|
||||
tasks []*pb.BuriedParam
|
||||
add []string
|
||||
)
|
||||
for _, heroCfgId := range cids {
|
||||
tasks = append(tasks, comm.GetBuriedParam(comm.Rtype1, 1, utils.ToInt32(heroCfgId)))
|
||||
cfg, _ := this.configure.GetHeroConfig(heroCfgId)
|
||||
tasks = append(tasks, comm.GetBuriedParam2(comm.Rtype30, heroCfgId, cfg.Color))
|
||||
tasks = append(tasks, comm.GetBuriedParam(comm.Rtype31, 1, cfg.Color))
|
||||
}
|
||||
for _, v := range addHero {
|
||||
add = append(add, v.HeroID)
|
||||
}
|
||||
if db.IsCross() {
|
||||
go this.moduleFetter.SendRpcAddHero(session.GetUserId(), add, session.GetServiecTag())
|
||||
} else {
|
||||
go this.moduleFetter.AddHerosFetterData(session.GetUserId(), add) // 异步调用
|
||||
}
|
||||
|
||||
go this.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
|
||||
this.ModuleBuried.TriggerBuried(session, tasks...)
|
||||
})
|
||||
if len(addHero) > 0 {
|
||||
session.SendMsg("hero", "change", &pb.HeroChangePush{List: addHero})
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -503,7 +503,9 @@ func (this *ModuleBase) DispenseRes(session comm.IUserSession, res []*cfg.Gameat
|
||||
case comm.ItemType:
|
||||
items[v.T] += v.N
|
||||
case comm.HeroType:
|
||||
if v.N > 0 {
|
||||
heros[v.T] += v.N
|
||||
}
|
||||
case comm.EquipmentType:
|
||||
if v.N > 0 { // 不允许减少装备
|
||||
equips[v.T] += uint32(v.N)
|
||||
@ -741,7 +743,9 @@ func (this *ModuleBase) DispenseAtno(session comm.IUserSession, res []*cfg.Gamea
|
||||
case comm.ItemType:
|
||||
items[v.T] += v.N
|
||||
case comm.HeroType:
|
||||
if v.N > 0 {
|
||||
heros[v.T] += v.N
|
||||
}
|
||||
case comm.EquipmentType:
|
||||
if v.N > 0 { // 不允许减少装备
|
||||
equips[v.T] += uint32(v.N)
|
||||
|
@ -77,7 +77,7 @@ func (this *ModuleRobot_Hero) DoTask(robot IRobot, taskconf *cfg.GameWorldTaskDa
|
||||
)
|
||||
switch comm.TaskType(condconf.Type) {
|
||||
case comm.Rtype14:
|
||||
if _, errdata = robot.SendTaskMessage(taskconf.Key, condconf.Id, "hero", "drawcard", &pb.HeroDrawCardReq{DrawType: 2, DrawCount: 1, Consume: 0}); errdata != nil {
|
||||
if _, errdata = robot.SendTaskMessage(taskconf.Key, condconf.Id, "hero", "drawcard", &pb.HeroDrawCardReq{DrawType: 2, DrawCount: 1, Consume: 1}); errdata != nil {
|
||||
err = errors.New(fmt.Sprintf("code:%d message:%s", errdata.Code, errdata.Message))
|
||||
return
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user