147 lines
4.0 KiB
Go
147 lines
4.0 KiB
Go
package hero
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) StrengthenUpStarCheck(session comm.IUserSession, req *pb.HeroStrengthenUpStarReq) (code pb.ErrorCode) {
|
|
if req.HeroObjID == "" || len(req.Hero) == 0 || len(req.HeroRace) == 0 {
|
|
code = pb.ErrorCode_ReqParameterError
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
/// 英雄升星
|
|
func (this *apiComp) StrengthenUpStar(session comm.IUserSession, req *pb.HeroStrengthenUpStarReq) (code pb.ErrorCode, data proto.Message) {
|
|
var (
|
|
target *cfg.Game_heroStarupData // 配置表目标升星英雄信息
|
|
costRaceCount int32
|
|
_hero *pb.DBHero // 目标英雄
|
|
raceHero *pb.DBHero // 消耗阵容的英雄
|
|
tagHero *pb.DBHero // 消耗指定英雄
|
|
)
|
|
code = this.StrengthenUpStarCheck(session, req) // check
|
|
if code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
_hero, code = this.module.GetHero(session.GetUserId(), req.HeroObjID)
|
|
if code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
|
|
// 校验指定英雄
|
|
tagHeroConfig, err1 := this.module.configure.GetHeroStarupConfig()
|
|
if err1 != nil {
|
|
code = pb.ErrorCode_ReqParameterError
|
|
return
|
|
}
|
|
|
|
for _, value := range tagHeroConfig.GetDataList() {
|
|
if _hero.HeroID == value.Id && _hero.Star == value.Star && _hero.Lv == value.Maxlevel { // 找到了 满足升星条件
|
|
target = value
|
|
break
|
|
}
|
|
}
|
|
if target == nil {
|
|
code = pb.ErrorCode_ReqParameterError
|
|
return
|
|
}
|
|
// 指定英雄消耗校验
|
|
for _, v := range req.Hero {
|
|
if tagHero, code = this.module.GetHero(session.GetUserId(), v.CostCardObj); code != pb.ErrorCode_Success {
|
|
return
|
|
} else {
|
|
if tagHero.Block { // 锁定的卡不允许被消耗
|
|
code = pb.ErrorCode_HeroIsLock
|
|
return
|
|
}
|
|
if tagHero.SameCount < v.Amount { // 校验数量
|
|
code = pb.ErrorCode_ReqParameterError
|
|
return
|
|
}
|
|
// 校验ID
|
|
if tagHero.HeroID != target.Needhero && tagHero.Star != target.Needherostar && tagHero.SameCount < target.Needheronum {
|
|
code = pb.ErrorCode_ReqParameterError
|
|
return
|
|
}
|
|
}
|
|
}
|
|
// 校验阵容英雄消耗
|
|
for _, v := range req.HeroRace {
|
|
if raceHero, code = this.module.GetHero(session.GetUserId(), v.CostCardObj); code != pb.ErrorCode_Success {
|
|
return
|
|
} else {
|
|
if raceHero.Block { // 锁定的卡不允许被消耗
|
|
code = pb.ErrorCode_HeroIsLock
|
|
return
|
|
}
|
|
// 校验阵容信息
|
|
if raceHero.Star != target.Needracestar {
|
|
code = pb.ErrorCode_ReqParameterError
|
|
return
|
|
}
|
|
bFind := false
|
|
for _, value := range target.Needrace { // 阵营校验
|
|
if raceHero.Formation == value {
|
|
bFind = true
|
|
break
|
|
}
|
|
}
|
|
if !bFind {
|
|
code = pb.ErrorCode_ReqParameterError
|
|
return
|
|
}
|
|
}
|
|
|
|
costRaceCount += v.Amount
|
|
}
|
|
if costRaceCount != target.Needracenum { // 数量不匹配
|
|
code = pb.ErrorCode_ReqParameterError
|
|
return
|
|
}
|
|
// 金币消耗判断
|
|
curGold := this.module.ModuleUser.QueryAttributeValue(session.GetUserId(), "gold")
|
|
if curGold < target.Gold { // 金币不足
|
|
code = pb.ErrorCode_GoldNoEnough
|
|
return
|
|
}
|
|
|
|
// 消耗道具
|
|
code = this.module.ModuleUser.AddAttributeValue(session.GetUserId(), "gold", -target.Gold) // 减少金币
|
|
if code != pb.ErrorCode_Success {
|
|
this.module.Errorf("cost gold failed ,count = %d", target.Gold)
|
|
code = pb.ErrorCode_GoldNoEnough
|
|
return
|
|
}
|
|
// 消耗指定英雄
|
|
for _, v := range req.Hero {
|
|
code = this.module.DelCard(session.GetUserId(), v.CostCardObj, v.Amount)
|
|
if code != pb.ErrorCode_Success {
|
|
code = pb.ErrorCode_DBError
|
|
this.module.Errorf("del hero err card:%s,count = %d", v.CostCardObj, v.Amount)
|
|
return
|
|
}
|
|
}
|
|
|
|
//消耗种族英雄
|
|
for _, v := range req.HeroRace {
|
|
code = this.module.DelCard(session.GetUserId(), v.CostCardObj, v.Amount)
|
|
if code != pb.ErrorCode_Success {
|
|
code = pb.ErrorCode_DBError
|
|
return
|
|
}
|
|
}
|
|
code = this.module.modelHero.HeroStarUp(session, _hero) // 执行升星操作
|
|
if code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
session.SendMsg(string(this.module.GetType()), StrengthenUpStar, &pb.HeroStrengthenUpStarResp{Hero: _hero})
|
|
return
|
|
}
|