89 lines
2.5 KiB
Go
89 lines
2.5 KiB
Go
package hero
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/utils"
|
|
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) FusionCheck(session comm.IUserSession, req *pb.HeroFusionReq) (code pb.ErrorCode) {
|
|
if req.HeroId == "" {
|
|
code = pb.ErrorCode_ReqParameterError
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *apiComp) Fusion(session comm.IUserSession, req *pb.HeroFusionReq) (code pb.ErrorCode, data proto.Message) {
|
|
var (
|
|
totalCount int32
|
|
mapHero map[string]int32
|
|
_costMaphero map[string]*pb.DBHero
|
|
ChangeList []*pb.DBHero // 变化的英雄数据
|
|
)
|
|
ChangeList = make([]*pb.DBHero, 0)
|
|
_costMaphero = make(map[string]*pb.DBHero, 0)
|
|
mapHero = make(map[string]int32)
|
|
if code = this.FusionCheck(session, req); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
conf := this.module.configure.GetHeroFucionConfig(req.HeroId)
|
|
if conf == nil {
|
|
code = pb.ErrorCode_ConfigNoFound // 配置没找到
|
|
return
|
|
}
|
|
for _, v := range req.Heros {
|
|
totalCount += v
|
|
}
|
|
if totalCount != int32(len(conf.Pointhero)) { // 校验数量
|
|
code = pb.ErrorCode_ReqParameterError
|
|
return
|
|
}
|
|
for k, v := range req.Heros {
|
|
// 校验英雄是否存在
|
|
_obj, c := this.module.GetHeroByObjID(session.GetUserId(), k)
|
|
if c != pb.ErrorCode_Success || _obj.SameCount < v {
|
|
code = pb.ErrorCode_HeroNoExist
|
|
}
|
|
mapHero[_obj.HeroID] = v
|
|
_costMaphero[k] = _obj
|
|
}
|
|
for _, v := range conf.Pointhero {
|
|
if _, ok := mapHero[v]; ok {
|
|
mapHero[v] -= 1
|
|
} else {
|
|
code = pb.ErrorCode_ReqParameterError
|
|
return
|
|
}
|
|
}
|
|
for _, v := range mapHero {
|
|
if v != 0 {
|
|
code = pb.ErrorCode_ReqParameterError
|
|
return
|
|
}
|
|
}
|
|
for k, v := range req.Heros {
|
|
//mapHero[_costMaphero[k].HeroID]
|
|
code = this.module.DelCard(session.GetUserId(), _costMaphero[k], v)
|
|
if code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
ChangeList = append(ChangeList, _costMaphero[k])
|
|
}
|
|
|
|
// 获得新卡
|
|
if newHero, err := this.module.CreateRepeatHero(session, conf.Hero, 1, false); err == pb.ErrorCode_Success {
|
|
ChangeList = append(ChangeList, newHero)
|
|
session.SendMsg(string(this.module.GetType()), "change", &pb.HeroChangePush{List: ChangeList})
|
|
} else {
|
|
this.module.Errorf("err:%v,create hero:%s,uid,%ss", err, conf.Hero, session.GetUserId())
|
|
code = pb.ErrorCode_HeroCreate // 创建新英雄失败
|
|
}
|
|
session.SendMsg(string(this.module.GetType()), HeroFusionResp, &pb.HeroFusionResp{Heroid: conf.Hero})
|
|
// 通过融合获得指定英雄
|
|
this.module.ModuleRtask.SendToRtask(session, comm.Rtype139, utils.ToInt32(conf.Hero))
|
|
return
|
|
}
|