162 lines
4.3 KiB
Go
162 lines
4.3 KiB
Go
package hero
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) StrengthenUpStarCheck(session comm.IUserSession, req *pb.HeroStrengthenUpStarReq) (result map[string]interface{}, code comm.ErrorCode) {
|
|
if req.HeroObjID == "" {
|
|
code.Code = pb.ErrorCode_ReqParameterError
|
|
return
|
|
}
|
|
var (
|
|
curLv int32
|
|
target *cfg.Game_heroStarupData // 配置表目标升星英雄信息
|
|
raceHero *pb.DBHero // 消耗的阵容英雄
|
|
costRaceCount int32
|
|
curGold int32
|
|
)
|
|
tagHero, err := this.moduleHero.GetHero(session.GetUserId(), req.HeroObjID)
|
|
if err != 0 {
|
|
code.Code = pb.ErrorCode_HeroNoExist
|
|
return
|
|
}
|
|
curLv = tagHero.Lv
|
|
log.Debugf("curLv:%d", curLv)
|
|
// 校验指定英雄
|
|
tagHeroConfig, err1 := this.moduleHero.configure.GetHeroStarupConfig()
|
|
if err1 != nil {
|
|
code.Code = pb.ErrorCode_ReqParameterError
|
|
return
|
|
}
|
|
|
|
for _, value := range tagHeroConfig.GetDataList() {
|
|
if tagHero.HeroID == value.Id && tagHero.Star == value.Star && tagHero.Lv == value.Maxlevel { // 找到了 满足升星条件
|
|
target = value
|
|
break
|
|
}
|
|
}
|
|
// 指定英雄消耗校验
|
|
for _, v := range req.Hero {
|
|
if tagHero, err := this.moduleHero.GetHero(session.GetUserId(), v.CostCardObj); err != 0 {
|
|
code.Code = pb.ErrorCode_ReqParameterError
|
|
return
|
|
} else {
|
|
if tagHero.SameCount < v.Amount { // 校验数量
|
|
code.Code = pb.ErrorCode_ReqParameterError
|
|
return
|
|
}
|
|
// 校验ID
|
|
if tagHero.HeroID != target.Needhero && tagHero.Star != target.Needherostar && tagHero.SameCount < target.Needheronum {
|
|
code.Code = pb.ErrorCode_ReqParameterError
|
|
return
|
|
}
|
|
}
|
|
}
|
|
// 校验阵容英雄消耗
|
|
for _, v := range req.HeroRace {
|
|
if raceHero, err = this.moduleHero.GetHero(session.GetUserId(), v.CostCardObj); err != 0 {
|
|
code.Code = pb.ErrorCode_ReqParameterError
|
|
return
|
|
} else {
|
|
// 校验阵容信息
|
|
if raceHero.Star != target.Needracestar {
|
|
code.Code = pb.ErrorCode_ReqParameterError
|
|
return
|
|
}
|
|
bFind := false
|
|
for _, value := range target.Needrace { // 阵营校验
|
|
if raceHero.Formation == value {
|
|
bFind = true
|
|
break
|
|
}
|
|
}
|
|
if !bFind {
|
|
code.Code = pb.ErrorCode_ReqParameterError
|
|
return
|
|
}
|
|
}
|
|
|
|
costRaceCount += v.Amount
|
|
}
|
|
if costRaceCount != target.Needracenum { // 数量不匹配
|
|
code.Code = pb.ErrorCode_ReqParameterError
|
|
return
|
|
}
|
|
// 金币消耗判断
|
|
curGold = this.user.QueryAttributeValue(session.GetUserId(), "gold")
|
|
if curGold < target.Gold { // 金币不足
|
|
code.Code = pb.ErrorCode_GoldNoEnough
|
|
return
|
|
}
|
|
|
|
result = map[string]interface{}{
|
|
"costGold": target.Gold,
|
|
"heroObj": tagHero,
|
|
"curGold": curGold,
|
|
}
|
|
return
|
|
}
|
|
|
|
/// 英雄升星
|
|
func (this *apiComp) StrengthenUpStar(session comm.IUserSession, agrs map[string]interface{}, req *pb.HeroStrengthenUpStarReq) (code pb.ErrorCode) {
|
|
|
|
costGold := agrs["costGold"].(int32)
|
|
_hero := agrs["heroObj"].(*pb.DBHero)
|
|
curGold := agrs["curGold"].(int32)
|
|
if _hero == nil {
|
|
code = pb.ErrorCode_HeroNoExist
|
|
return
|
|
}
|
|
defer func() {
|
|
if code == pb.ErrorCode_Success {
|
|
session.SendMsg(string(this.moduleHero.GetType()), StrengthenUpStar, &pb.HeroStrengthenUpStarResp{Hero: _hero})
|
|
}
|
|
}()
|
|
|
|
// 消耗道具
|
|
code = this.user.AddAttributeValue(session.GetUserId(), "gold", curGold-costGold) // 减少金币
|
|
if code != pb.ErrorCode_Success {
|
|
log.Errorf("cost gold failed ,count = %d", costGold)
|
|
code = pb.ErrorCode_GoldNoEnough
|
|
return
|
|
}
|
|
// 消耗指定英雄
|
|
for _, v := range req.Hero {
|
|
code = this.moduleHero.DelCard(v.CostCardObj, v.Amount)
|
|
if code != 0 {
|
|
code = pb.ErrorCode_DBError
|
|
log.Errorf("del hero err card:%s,count = %d", v.CostCardObj, v.Amount)
|
|
return
|
|
}
|
|
}
|
|
|
|
//消耗种族英雄
|
|
for _, v := range req.HeroRace {
|
|
code = this.moduleHero.DelCard(v.CostCardObj, v.Amount)
|
|
if code != 0 {
|
|
code = pb.ErrorCode_DBError
|
|
return
|
|
}
|
|
}
|
|
_hero.Star += 1
|
|
_heroMap := map[string]interface{}{
|
|
"star": _hero.Star,
|
|
}
|
|
// 保存数据
|
|
err := this.moduleHero.hero.modifyHeroData(session.GetUserId(), req.HeroObjID, _heroMap)
|
|
if err != nil {
|
|
code = pb.ErrorCode_DBError
|
|
log.Errorf("update hero skill failed:%v", err)
|
|
}
|
|
err = this.moduleHero.hero.PushHeroProperty(session, _hero.Id) // 推送属性变化
|
|
if err != nil {
|
|
log.Errorf("PushHeroProperty err!")
|
|
}
|
|
return
|
|
}
|