93 lines
2.4 KiB
Go
93 lines
2.4 KiB
Go
package hero
|
||
|
||
import (
|
||
"go_dreamfactory/comm"
|
||
"go_dreamfactory/pb"
|
||
cfg "go_dreamfactory/sys/configure/structs"
|
||
|
||
"google.golang.org/protobuf/proto"
|
||
)
|
||
|
||
//参数校验
|
||
func (this *apiComp) StrengthenUplvCheck(session comm.IUserSession, req *pb.HeroStrengthenUplvReq) (code pb.ErrorCode) {
|
||
if req.HeroObjID == "" || len(req.Item) == 0 {
|
||
code = pb.ErrorCode_ReqParameterError
|
||
return
|
||
}
|
||
|
||
return
|
||
}
|
||
|
||
/// 英雄升级
|
||
func (this *apiComp) StrengthenUplv(session comm.IUserSession, req *pb.HeroStrengthenUplvReq) (code pb.ErrorCode, data proto.Message) {
|
||
|
||
var (
|
||
addExp int32 // 需要增加的经验
|
||
costGold int32 // 需要消耗的资源
|
||
_hero *pb.DBHero // 目标英雄
|
||
cost []*cfg.Gameatn // 消耗的道具
|
||
)
|
||
code = this.StrengthenUplvCheck(session, req) // check
|
||
if code != pb.ErrorCode_Success {
|
||
return
|
||
}
|
||
|
||
_hero, code = this.module.GetHeroByObjID(session.GetUserId(), req.HeroObjID)
|
||
if code != pb.ErrorCode_Success {
|
||
return
|
||
}
|
||
for k, v := range req.Item {
|
||
if v == 0 {
|
||
continue
|
||
}
|
||
cost = append(cost, &cfg.Gameatn{
|
||
A: "item",
|
||
T: k,
|
||
N: v,
|
||
})
|
||
// 查询 本次消耗会获得多少经验
|
||
if expConf := this.module.configure.GetHeroExp(k); expConf != nil {
|
||
addExp += expConf.Exp * v
|
||
costGold += expConf.Needgold * v
|
||
}
|
||
}
|
||
cost = append(cost, &cfg.Gameatn{
|
||
A: "attr",
|
||
T: "gold",
|
||
N: costGold,
|
||
})
|
||
// 金币消耗判断
|
||
if code = this.module.CheckRes(session, cost); code != pb.ErrorCode_Success {
|
||
return
|
||
}
|
||
|
||
if addExp == 0 {
|
||
code = pb.ErrorCode_HeroExpTypeErr
|
||
return
|
||
}
|
||
// 校验当前能不能升级
|
||
if _hero.Lv >= this.module.configure.GetHeroMaxLv(_hero.Star) { // 达到最大等级
|
||
code = pb.ErrorCode_HeroMaxLv
|
||
return
|
||
}
|
||
// 执行升级逻辑
|
||
_, code = this.module.modelHero.AddCardExp(session, _hero, addExp, nil) // 加经验
|
||
if code != pb.ErrorCode_Success {
|
||
return
|
||
}
|
||
// 消耗金币
|
||
if code = this.module.ConsumeRes(session, cost, true); code != pb.ErrorCode_Success { //道具扣除
|
||
code = pb.ErrorCode_ItemsNoEnough
|
||
return
|
||
}
|
||
|
||
//英雄升级 【玩家名称】已将【英雄名称】培养至60级!
|
||
if user := this.module.ModuleUser.GetUser(session.GetUserId()); user != nil {
|
||
this.chat.SendSysChatToWorld(comm.ChatSystem7, nil, _hero.Lv, 0, user.Name, _hero.HeroID)
|
||
} else {
|
||
this.module.Errorf("no found userdata uid:%s", session.GetUserId())
|
||
}
|
||
session.SendMsg(string(this.module.GetType()), StrengthenUplv, &pb.HeroStrengthenUplvResp{Hero: _hero})
|
||
return
|
||
}
|