141 lines
4.2 KiB
Go
141 lines
4.2 KiB
Go
package hero
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
"go_dreamfactory/utils"
|
|
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) StrengthenUpSkillCheck(session comm.IUserSession, req *pb.HeroStrengthenUpSkillReq) (code pb.ErrorCode) {
|
|
if req.HeroObjID == "" || len(req.Item) == 0 {
|
|
code = pb.ErrorCode_ReqParameterError
|
|
return
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
/// 英雄技能升级
|
|
func (this *apiComp) StrengthenUpSkill(session comm.IUserSession, req *pb.HeroStrengthenUpSkillReq) (code pb.ErrorCode, data proto.Message) {
|
|
var (
|
|
upSkillPos int32 // 升级的技能位置
|
|
_hero *pb.DBHero // 操作的英雄
|
|
cost []*cfg.Gameatn // 技能升级消耗
|
|
lvUpCount int32 // 技能升级的次数
|
|
)
|
|
|
|
code = this.StrengthenUpSkillCheck(session, req) // check
|
|
if code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
_hero, code = this.module.GetHeroByObjID(session.GetUserId(), req.HeroObjID) // 查询目标卡是否存在
|
|
if code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
// 查询配置表 找出原始品质
|
|
heroCfg := this.module.configure.GetHeroConfig(_hero.HeroID)
|
|
if heroCfg == nil {
|
|
code = pb.ErrorCode_HeroNoExist
|
|
return
|
|
}
|
|
for _, v1 := range req.Item {
|
|
bFind := false
|
|
for _, v := range heroCfg.Heroskillup {
|
|
if v == v1 {
|
|
bFind = true
|
|
lvUpCount++ // 升级次数
|
|
break
|
|
}
|
|
}
|
|
if !bFind {
|
|
code = pb.ErrorCode_ReqParameterError
|
|
return
|
|
}
|
|
cost = append(cost, &cfg.Gameatn{
|
|
A: "item",
|
|
T: v1,
|
|
N: 1,
|
|
})
|
|
}
|
|
// 消耗获取
|
|
for i := 0; i < int(lvUpCount); i++ {
|
|
if atn := this.module.configure.GetHeroSkillCost(heroCfg.Star); len(atn) > 0 {
|
|
cost = append(cost, atn...)
|
|
}
|
|
}
|
|
|
|
// 检查消耗
|
|
if code = this.module.CheckRes(session, cost); code != pb.ErrorCode_Success {
|
|
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 := this.module.configure.GetHeroSkillUpConfig(skill.SkillID)
|
|
if skillData == nil {
|
|
code = pb.ErrorCode_ConfigNoFound
|
|
return
|
|
}
|
|
sz = append(sz, skillData.Probability[skill.SkillLv])
|
|
szIndex = append(szIndex, int32(index))
|
|
}
|
|
}
|
|
if len(sz) == 0 {
|
|
code = pb.ErrorCode_HeroMaxSkillLv
|
|
this.module.Errorf("技能升级失败:uid:%s,oid:%s", session.GetUserId(), _hero.Id)
|
|
return
|
|
}
|
|
upSkillPos = comm.GetRandW(sz)
|
|
_hero.NormalSkill[szIndex[upSkillPos]].SkillLv += 1
|
|
}
|
|
|
|
if code = this.module.ConsumeRes(session, cost, true); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
|
|
_heroMap := map[string]interface{}{
|
|
"normalSkill": _hero.NormalSkill,
|
|
}
|
|
err1 := this.module.modelHero.ChangeList(session.GetUserId(), req.HeroObjID, _heroMap) // 修改英雄信息
|
|
if err1 != nil {
|
|
this.module.Errorf("update hero skill failed:%v", err1)
|
|
code = pb.ErrorCode_DBError
|
|
return
|
|
}
|
|
session.SendMsg(string(this.module.GetType()), StrengthenUpSkill, &pb.HeroStrengthenUpSkillResp{Hero: _hero})
|
|
//英雄技能培养 【玩家名称】已将【英雄名称】技能培养至满级!
|
|
if user := this.module.ModuleUser.GetUser(session.GetUserId()); user != nil {
|
|
this.chat.SendSysChatToWorld(comm.ChatSystem9, nil, _hero.Lv, 0, user.Name, _hero.HeroID)
|
|
} else {
|
|
this.module.Errorf("no found userdata uid:%s", session.GetUserId())
|
|
}
|
|
this.module.ModuleRtask.SendToRtask(session, comm.Rtype52, utils.ToInt32(_hero.HeroID), 1)
|
|
this.module.ModuleRtask.SendToRtask(session, 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
|
|
}
|
|
}
|
|
if maxLv {
|
|
|
|
this.module.ModuleRtask.SendToRtask(session, comm.Rtype54, 1)
|
|
this.module.ModuleRtask.SendToRtask(session, comm.Rtype57, 1)
|
|
}
|
|
cfg := this.module.configure.GetHeroConfig(_hero.HeroID)
|
|
if cfg != nil {
|
|
this.module.ModuleRtask.SendToRtask(session, comm.Rtype55, cfg.Color, 1)
|
|
this.module.ModuleRtask.SendToRtask(session, comm.Rtype56, 1, 1, cfg.Job)
|
|
}
|
|
return
|
|
}
|