150 lines
3.7 KiB
Go
150 lines
3.7 KiB
Go
package hero
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
"strconv"
|
|
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) AwakenCheck(session comm.IUserSession, req *pb.HeroAwakenReq) (code pb.ErrorCode) {
|
|
if req.HeroObjID == "" {
|
|
code = pb.ErrorCode_ReqParameterError
|
|
return
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
/// 英雄觉醒
|
|
func (this *apiComp) Awaken(session comm.IUserSession, req *pb.HeroAwakenReq) (code pb.ErrorCode, data proto.Message) {
|
|
var (
|
|
awakenData *cfg.Game_heroAwakenData
|
|
bCheckOk bool
|
|
costRes map[string]int32
|
|
)
|
|
costRes = make(map[string]int32, 0)
|
|
bCheckOk = true
|
|
_hero, err := this.module.GetHero(session.GetUserId(), req.HeroObjID)
|
|
|
|
if err != pb.ErrorCode_Success {
|
|
code = pb.ErrorCode_HeroNoExist
|
|
return
|
|
}
|
|
defer func() {
|
|
if code == pb.ErrorCode_Success {
|
|
session.SendMsg(string(this.module.GetType()), StrengthenUplv, &pb.HeroAwakenResp{Hero: _hero})
|
|
}
|
|
}()
|
|
code = this.AwakenCheck(session, req) // check
|
|
if code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
AwakenConfig, err1 := this.module.configure.GetHeroAwakenConfig()
|
|
if err1 != nil {
|
|
code = pb.ErrorCode_ConfigNoFound
|
|
return
|
|
}
|
|
for _, v := range AwakenConfig.GetDataMap() {
|
|
if v.Hid == _hero.HeroID && v.Phase == _hero.JuexingLv+1 {
|
|
awakenData = v
|
|
break
|
|
}
|
|
}
|
|
if awakenData == nil {
|
|
code = pb.ErrorCode_ConfigNoFound
|
|
return
|
|
}
|
|
// 参数校验
|
|
for _, v := range awakenData.Phaseneed {
|
|
if v.A == "attr" { // 消耗玩家身上资源
|
|
curGold := this.module.ModuleUser.QueryAttributeValue(session.GetUserId(), v.T)
|
|
if curGold < v.N {
|
|
bCheckOk = false
|
|
break
|
|
}
|
|
costRes[v.T] = v.N
|
|
} else if v.A == "item" { //消耗道具
|
|
itemid, err := strconv.Atoi(v.T)
|
|
if err != nil {
|
|
curCount := this.module.items.QueryItemAmount(nil, session.GetUserId(), int32(itemid))
|
|
if curCount < uint32(v.N) {
|
|
bCheckOk = false
|
|
break
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if !bCheckOk {
|
|
code = pb.ErrorCode_GoldNoEnough
|
|
return
|
|
}
|
|
if _hero == nil || awakenData == nil {
|
|
code = pb.ErrorCode_HeroNoExist
|
|
return
|
|
}
|
|
|
|
for _, v := range awakenData.Phaseneed {
|
|
if v.A == "attr" { // 消耗玩家身上资源
|
|
if _data, ok := costRes[v.T]; ok {
|
|
code = this.module.ModuleUser.AddAttributeValue(session.GetUserId(), v.T, _data)
|
|
if code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
}
|
|
|
|
} else if v.A == "item" { //消耗道具
|
|
itemid, err := strconv.Atoi(v.T)
|
|
if err != nil {
|
|
code = this.module.items.AddItem(nil, session.GetUserId(), int32(itemid), -v.N)
|
|
if code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if len(awakenData.Phasebonus) < 2 {
|
|
code = pb.ErrorCode_ConfigNoFound
|
|
return
|
|
}
|
|
// 加属性 awakenData
|
|
_value, ok := strconv.Atoi(awakenData.Phasebonus[0])
|
|
if ok == nil { // 升级技能
|
|
for pos, v := range _hero.NormalSkill {
|
|
value, err := strconv.Atoi(awakenData.Phasebonus[1])
|
|
if err == nil {
|
|
if pos == value {
|
|
v.SkillID = int32(_value)
|
|
}
|
|
}
|
|
}
|
|
_heroMap := map[string]interface{}{
|
|
"normalSkill": _hero.NormalSkill,
|
|
}
|
|
// 保存数据
|
|
err1 = this.module.modelHero.modifyHeroData(session.GetUserId(), _hero.Id, _heroMap)
|
|
if err1 != nil {
|
|
code = pb.ErrorCode_DBError
|
|
log.Errorf("update hero skill failed:%v", err1)
|
|
}
|
|
} else { // 加属性
|
|
property := make(map[string]int32, 0)
|
|
value, err := strconv.Atoi(awakenData.Phasebonus[1])
|
|
if err == nil {
|
|
property[awakenData.Phasebonus[0]] += int32(value)
|
|
}
|
|
this.module.modelHero.mergeMainProperty(session.GetUserId(), _hero.Id, property)
|
|
}
|
|
|
|
err1 = this.module.modelHero.PushHeroProperty(session, _hero.Id) // 推送属性变化
|
|
if err1 != nil {
|
|
log.Errorf("PushHeroProperty err!")
|
|
}
|
|
|
|
return
|
|
}
|