180 lines
5.5 KiB
Go
180 lines
5.5 KiB
Go
package hero
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
"go_dreamfactory/utils"
|
|
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) ResonanceCheck(session comm.IUserSession, req *pb.HeroResonanceReq) (code pb.ErrorCode) {
|
|
if req.HeroObjID == "" || len(req.CostObjID) == 0 {
|
|
code = pb.ErrorCode_ReqParameterError
|
|
return
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
/// 英雄共鸣
|
|
func (this *apiComp) Resonance(session comm.IUserSession, req *pb.HeroResonanceReq) (code pb.ErrorCode, data proto.Message) {
|
|
var (
|
|
szCostHero map[string]int32 // k 卡牌配置id v 数量
|
|
_hero *pb.DBHero
|
|
ChangeList []*pb.DBHero // 变化的英雄数据
|
|
_costMaphero map[string]*pb.DBHero
|
|
count int32 // 共鸣升级次数
|
|
)
|
|
ChangeList = make([]*pb.DBHero, 0)
|
|
szCostHero = make(map[string]int32, 0)
|
|
_costMaphero = make(map[string]*pb.DBHero, 0)
|
|
code = this.ResonanceCheck(session, req) // check
|
|
if code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
|
|
_hero, code = this.module.GetHeroByObjID(session.GetUserId(), req.HeroObjID) // 查询目标卡是否存在
|
|
if code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
//获取原始星级
|
|
conf := this.module.configure.GetHeroConfig(_hero.HeroID)
|
|
if conf == nil {
|
|
code = pb.ErrorCode_ConfigNoFound
|
|
return
|
|
}
|
|
// 共鸣次数判断
|
|
resonConfig := this.module.configure.GetHeroResonanceConfig(_hero.HeroID, conf.Star)
|
|
if resonConfig == nil {
|
|
code = pb.ErrorCode_ConfigNoFound
|
|
return
|
|
}
|
|
|
|
for _, k := range req.CostObjID {
|
|
_costHero, c := this.module.GetHeroByObjID(session.GetUserId(), k) // 查询消耗卡是否存在
|
|
if c != pb.ErrorCode_Success {
|
|
code = c // 英雄被锁不能消耗
|
|
return
|
|
}
|
|
if _costHero.Block {
|
|
code = pb.ErrorCode_HeroIsLock
|
|
}
|
|
_costMaphero[k] = _costHero
|
|
szCostHero[_costHero.HeroID] += 1
|
|
}
|
|
// 一次升级多级
|
|
for _, v := range resonConfig.Heroneed {
|
|
for k, v1 := range szCostHero {
|
|
if k == v.T {
|
|
if v1%v.N == 0 {
|
|
if count == 0 {
|
|
count = v1 / v.N
|
|
}
|
|
if count != v1/v.N {
|
|
code = pb.ErrorCode_ReqParameterError
|
|
return
|
|
}
|
|
} else {
|
|
code = pb.ErrorCode_ReqParameterError
|
|
return
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if count == 0 {
|
|
code = pb.ErrorCode_ReqParameterError
|
|
return
|
|
}
|
|
if resonConfig.Maxnum < _hero.ResonateNum+count {
|
|
code = pb.ErrorCode_HeroMaxResonate // 共鸣次数已满
|
|
return
|
|
}
|
|
for k, v := range _costMaphero {
|
|
code = this.module.DelCard(session.GetUserId(), v, szCostHero[v.HeroID])
|
|
if code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
ChangeList = append(ChangeList, _costMaphero[k])
|
|
}
|
|
sz := make([]*cfg.Gameatn, 0) // 计算升级多次的消耗
|
|
for _, v := range resonConfig.Need {
|
|
sz = append(sz, &cfg.Gameatn{
|
|
A: v.A,
|
|
T: v.T,
|
|
N: v.N * count,
|
|
})
|
|
}
|
|
code = this.module.ConsumeRes(session, sz, true)
|
|
if code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
|
|
for k := range _costMaphero {
|
|
if k == _hero.Id {
|
|
_hero.SameCount = _costMaphero[k].SameCount
|
|
break
|
|
}
|
|
}
|
|
if _hero.SameCount == 0 {
|
|
code = pb.ErrorCode_ReqParameterError
|
|
return
|
|
}
|
|
if _hero.SameCount > 1 {
|
|
_hero.SameCount -= 1
|
|
newHero := this.module.modelHero.CloneNewHero(_hero)
|
|
ChangeList = append(ChangeList, newHero)
|
|
}
|
|
_hero.SameCount = 1
|
|
_hero.ResonateNum += count
|
|
_hero.DistributionResonate += resonConfig.Energy * count
|
|
_hero.IsOverlying = false
|
|
_heroMap := map[string]interface{}{
|
|
"resonateNum": _hero.ResonateNum,
|
|
"distributionResonate": _hero.DistributionResonate,
|
|
"isOverlying": false,
|
|
"sameCount": 1,
|
|
}
|
|
err := this.module.modelHero.ChangeList(session.GetUserId(), req.HeroObjID, _heroMap) // 修改英雄信息
|
|
if err != nil {
|
|
this.module.Errorf("update hero skill failed:%v", err)
|
|
code = pb.ErrorCode_DBError
|
|
return
|
|
}
|
|
// 返还对应初始星级的卡
|
|
ChangeList = append(ChangeList, _hero)
|
|
session.SendMsg(string(this.module.GetType()), "change", &pb.HeroChangePush{List: ChangeList})
|
|
this.module.DispenseRes(session, resonConfig.Prize, true)
|
|
session.SendMsg(string(this.module.GetType()), Resonance, &pb.HeroResonanceResp{Hero: _hero})
|
|
|
|
//英雄共鸣 【玩家名称】已将【英雄名称】共鸣至满级!
|
|
if user := this.module.ModuleUser.GetUser(session.GetUserId()); user != nil {
|
|
this.chat.SendSysChatToWorld(comm.ChatSystem10, nil, _hero.ResonateNum, 0, user.Name, _hero.HeroID)
|
|
} else {
|
|
this.module.Errorf("no found userdata uid:%s", session.GetUserId())
|
|
}
|
|
// 任务相关
|
|
this.module.ModuleRtask.SendToRtask(session, comm.Rtype39, 1)
|
|
this.module.ModuleRtask.SendToRtask(session, comm.Rtype127, _hero.Star, utils.ToInt32(_hero.HeroID), _hero.ResonateNum) //A星英雄共鸣N级
|
|
this.module.ModuleRtask.SendToRtask(session, comm.Rtype40, 1, 1)
|
|
cfg := this.module.configure.GetHeroConfig(_hero.HeroID)
|
|
if cfg != nil {
|
|
this.module.ModuleRtask.SendToRtask(session, comm.Rtype126, cfg.Race, _hero.ResonateNum)
|
|
this.module.ModuleRtask.SendToRtask(session, comm.Rtype36, 1, cfg.Color, cfg.Job, cfg.Race, _hero.ResonateNum)
|
|
//xx英雄满级、共鸣、觉醒至最高状态
|
|
nextAwaken := this.module.configure.GetHeroAwakenConfig(_hero.HeroID, _hero.JuexingLv+1)
|
|
if nextAwaken == nil { // 达到满级觉醒
|
|
resonConfig := this.module.configure.GetHeroResonanceConfig(_hero.HeroID, cfg.Star)
|
|
if resonConfig != nil && resonConfig.Maxnum == _hero.ResonateNum { // 共鸣满
|
|
if _hero.Lv == _hero.Star*comm.HeroStarLvRatio {
|
|
this.module.ModuleRtask.SendToRtask(session, comm.Rtype37, 1, cfg.Color)
|
|
this.module.ModuleRtask.SendToRtask(session, comm.Rtype38, 1)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return
|
|
}
|