113 lines
2.7 KiB
Go
113 lines
2.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
|
|
}
|
|
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
|
|
}
|
|
defer func() {
|
|
if code == pb.ErrorCode_Success {
|
|
session.SendMsg(string(this.module.GetType()), StrengthenUplv, &pb.HeroAwakenResp{Hero: _hero})
|
|
}
|
|
}()
|
|
|
|
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
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
err1 = this.module.hero.PushHeroProperty(session, _hero.Id) // 推送属性变化
|
|
if err1 != nil {
|
|
log.Errorf("PushHeroProperty err!")
|
|
}
|
|
return
|
|
}
|