143 lines
4.5 KiB
Go
143 lines
4.5 KiB
Go
package hero
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
"go_dreamfactory/utils"
|
|
"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.GameHeroAwakenData
|
|
_hero *pb.DBHero
|
|
chanegCard []*pb.DBHero // change
|
|
_heroMap map[string]interface{}
|
|
)
|
|
_heroMap = make(map[string]interface{}, 0)
|
|
chanegCard = make([]*pb.DBHero, 0)
|
|
code = this.AwakenCheck(session, req) // check
|
|
if code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
_hero, code = this.module.GetHeroByObjID(session.GetUserId(), req.HeroObjID)
|
|
if code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
|
|
awakenData = this.module.configure.GetHeroAwakenConfig(_hero.HeroID, _hero.JuexingLv+1)
|
|
if awakenData == nil {
|
|
code = pb.ErrorCode_ConfigNoFound
|
|
return
|
|
}
|
|
if len(awakenData.Phasebonus) < 2 { // 配置校验
|
|
code = pb.ErrorCode_ConfigNoFound
|
|
return
|
|
}
|
|
|
|
//条件判断
|
|
if awakenData.Condition > _hero.Lv {
|
|
code = pb.ErrorCode_HeroLvNoEnough
|
|
return
|
|
}
|
|
// 消耗校验
|
|
code = this.module.ConsumeRes(session, awakenData.Phaseneed, true)
|
|
if code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
if _hero.SameCount > 1 { //有堆叠的情况
|
|
// 克隆一个新的
|
|
_hero.SameCount -= 1
|
|
_hero.JuexProperty = map[string]int32{}
|
|
|
|
newHero := this.module.modelHero.CloneNewHero(_hero)
|
|
_hero.JuexProperty = map[string]int32{}
|
|
chanegCard = append(chanegCard, newHero)
|
|
_heroMap["isOverlying"] = false
|
|
_heroMap["sameCount"] = 1
|
|
}
|
|
_hero.SameCount = 1
|
|
_hero.IsOverlying = false
|
|
// 加属性 awakenData
|
|
if len(awakenData.Phasebonus) != 2 {
|
|
code = pb.ErrorCode_ConfigNoFound
|
|
return
|
|
}
|
|
_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["normalSkill"] = _hero.NormalSkill
|
|
} else { // 加属性
|
|
value, err := strconv.Atoi(awakenData.Phasebonus[1])
|
|
if err == nil {
|
|
if value > 0 {
|
|
this.module.modelHero.setJuexingProperty(_hero, awakenData.Phasebonus[0], int32(value))
|
|
_heroMap["juexProperty"] = _hero.JuexProperty
|
|
}
|
|
}
|
|
}
|
|
_hero.JuexingLv += 1
|
|
_heroMap["juexingLv"] = _hero.JuexingLv
|
|
// 保存数据
|
|
err := this.module.modelHero.ChangeList(session.GetUserId(), _hero.Id, _heroMap)
|
|
if err != nil {
|
|
code = pb.ErrorCode_DBError
|
|
this.module.Errorf("update hero skill failed:%v", err)
|
|
return
|
|
}
|
|
|
|
chanegCard = append(chanegCard, _hero)
|
|
session.SendMsg(string(this.module.GetType()), "change", &pb.HeroChangePush{List: chanegCard})
|
|
session.SendMsg(string(this.module.GetType()), Awaken, &pb.HeroAwakenResp{Hero: _hero})
|
|
|
|
//英雄觉醒 【玩家名称】已将【英雄名称】觉醒至满级!
|
|
if user := this.module.ModuleUser.GetUser(session.GetUserId()); user != nil {
|
|
this.chat.SendSysChatToWorld(comm.ChatSystem11, nil, _hero.JuexingLv, 0, user.Name, _hero.HeroID)
|
|
} else {
|
|
this.module.Errorf("no found userdata uid:%s", session.GetUserId())
|
|
}
|
|
|
|
//任务相关
|
|
this.module.ModuleRtask.SendToRtask(session, comm.Rtype34, 1, _hero.JuexingLv)
|
|
this.module.ModuleRtask.SendToRtask(session, comm.Rtype119, _hero.JuexingLv)
|
|
this.module.ModuleRtask.SendToRtask(session, comm.Rtype35, _hero.JuexingLv, utils.ToInt32(_hero.HeroID))
|
|
cfg := this.module.configure.GetHeroConfig(_hero.HeroID)
|
|
if cfg != nil {
|
|
this.module.ModuleRtask.SendToRtask(session, comm.Rtype121, cfg.Race, utils.ToInt32(_hero.HeroID), _hero.JuexingLv)
|
|
this.module.ModuleRtask.SendToRtask(session, comm.Rtype36, 1, cfg.Color, cfg.Job, cfg.Race, _hero.JuexingLv)
|
|
//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
|
|
}
|