166 lines
5.3 KiB
Go
166 lines
5.3 KiB
Go
package hero
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
"go_dreamfactory/utils"
|
|
)
|
|
|
|
// 参数校验
|
|
func (this *apiComp) StrengthenUpSkillCheck(session comm.IUserSession, req *pb.HeroStrengthenUpSkillReq) (errdata *pb.ErrorData) {
|
|
if req.HeroObjID == "" || len(req.Item) == 0 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
return
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
// / 英雄技能升级
|
|
func (this *apiComp) StrengthenUpSkill(session comm.IUserSession, req *pb.HeroStrengthenUpSkillReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
upSkillPos int32 // 升级的技能位置
|
|
_hero *pb.DBHero // 操作的英雄
|
|
cost []*cfg.Gameatn // 技能升级消耗
|
|
lvUpCount int32 // 技能升级的次数
|
|
//skillValue int32 // 战斗力
|
|
)
|
|
if errdata = this.StrengthenUpSkillCheck(session, req); errdata != nil {
|
|
return
|
|
}
|
|
if _hero, errdata = this.module.GetHeroByObjID(session.GetUserId(), req.HeroObjID); errdata != nil { // 查询目标卡是否存在
|
|
return
|
|
}
|
|
// 查询配置表 找出原始品质
|
|
heroCfg, err := this.module.configure.GetHeroConfig(_hero.HeroID)
|
|
if err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
|
|
return
|
|
}
|
|
for _, v := range heroCfg.Heroskillup {
|
|
if v1, ok := req.Item[v]; ok {
|
|
lvUpCount += v1 // 升级次数
|
|
cost = append(cost, &cfg.Gameatn{
|
|
A: "item",
|
|
T: v,
|
|
N: v1,
|
|
})
|
|
}
|
|
}
|
|
// 消耗获取
|
|
atn := this.module.configure.GetHeroSkillCost(heroCfg.Star)
|
|
for _, v := range atn {
|
|
res := &cfg.Gameatn{
|
|
A: v.A,
|
|
T: v.T,
|
|
N: v.N * lvUpCount,
|
|
}
|
|
cost = append(cost, res)
|
|
}
|
|
|
|
// 检查消耗
|
|
if errdata = this.module.CheckRes(session, cost); errdata != nil {
|
|
return
|
|
}
|
|
for i := 0; i < int(lvUpCount); i++ { // 升级技能
|
|
szIndex := make([]int32, 0)
|
|
sz := make([]int32, 0)
|
|
for index, skill := range _hero.NormalSkill {
|
|
skillMaxLv := this.module.configure.GetHeroSkillMaxLvConfig(uint32(skill.SkillID))
|
|
if skill.SkillLv < skillMaxLv { // 找到没有满级的技能id
|
|
skillData, err := this.module.configure.GetHeroSkillUpConfig(skill.SkillID)
|
|
if err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
|
|
return
|
|
}
|
|
sz = append(sz, skillData.Probability[skill.SkillLv])
|
|
szIndex = append(szIndex, int32(index))
|
|
}
|
|
}
|
|
if len(sz) == 0 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_HeroMaxSkillLv,
|
|
Title: pb.ErrorCode_HeroMaxSkillLv.ToString(),
|
|
}
|
|
this.module.Errorf("技能升级失败:uid:%s,oid:%s", session.GetUserId(), _hero.Id)
|
|
return
|
|
}
|
|
upSkillPos = comm.GetRandW(sz)
|
|
_hero.NormalSkill[szIndex[upSkillPos]].SkillLv += 1
|
|
}
|
|
|
|
if errdata = this.module.ConsumeRes(session, cost, true); errdata != nil {
|
|
return
|
|
}
|
|
this.module.modelHero.calFigthValue(_hero)
|
|
_heroMap := map[string]interface{}{
|
|
"normalSkill": _hero.NormalSkill,
|
|
"fightvalue": _hero.Fightvalue,
|
|
}
|
|
err = this.module.modelHero.ChangeList(session.GetUserId(), req.HeroObjID, _heroMap) // 修改英雄信息
|
|
if err != nil {
|
|
this.module.Errorf("update hero skill failed:%v", err)
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
session.SendMsg(string(this.module.GetType()), StrengthenUpSkill, &pb.HeroStrengthenUpSkillResp{Hero: _hero})
|
|
|
|
// 推送 世界任务消息
|
|
var tasks []*pb.BuriedParam
|
|
tasks = append(tasks, comm.GetBuriedParam(comm.Rtype52, 1, utils.ToInt32(_hero.HeroID)))
|
|
tasks = append(tasks, comm.GetBuriedParam(comm.Rtype53, 1))
|
|
|
|
// 检查是不是满级技能
|
|
maxLv := true
|
|
for _, skill := range _hero.NormalSkill {
|
|
skillMaxLv := this.module.configure.GetHeroSkillMaxLvConfig(uint32(skill.SkillID))
|
|
if skill.SkillLv < skillMaxLv { // 找到没有满级的技能id
|
|
maxLv = false
|
|
break
|
|
}
|
|
}
|
|
if maxLv {
|
|
tasks = append(tasks, comm.GetBuriedParam2(comm.Rtype54, _hero.HeroID))
|
|
//szTask = append(szTask, comm.GetBuriedParam(comm.Rtype57, 1))
|
|
tasks = append(tasks, comm.GetBuriedParam(comm.Rtype174, 1, _hero.Star))
|
|
}
|
|
|
|
if cfg, err := this.module.configure.GetHeroConfig(_hero.HeroID); err == nil {
|
|
tasks = append(tasks, comm.GetBuriedParam(comm.Rtype55, 1, cfg.Color))
|
|
tasks = append(tasks, comm.GetBuriedParam(comm.Rtype56, 1, 1, cfg.Job))
|
|
tasks = append(tasks, comm.GetBuriedParam(comm.Rtype116, lvUpCount, cfg.Race))
|
|
}
|
|
tasks = append(tasks, comm.GetBuriedParam(comm.Rtype117, lvUpCount, utils.ToInt32(_hero.HeroID)))
|
|
go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
|
|
//英雄技能培养 【玩家名称】已将【英雄名称】技能培养至满级!
|
|
if maxLv { // 满级星级参数
|
|
if user, err := this.module.GetUserForSession(session); err == nil {
|
|
this.chat.SendSysChatToWorld(session, comm.ChatSystem9, _hero, _hero.Star, 0, user.Name, _hero.HeroID)
|
|
} else {
|
|
this.module.Errorf("no found userdata uid:%s", session.GetUserId())
|
|
}
|
|
}
|
|
this.module.ModuleBuried.TriggerBuried(session, tasks...)
|
|
this.module.WriteUserLog(session.GetUserId(), req, comm.GMResDelType, "HeroStrengthenUpSkillReq", cost)
|
|
})
|
|
return
|
|
}
|