78 lines
2.4 KiB
Go
78 lines
2.4 KiB
Go
package hero
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
"math"
|
|
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) ResonanceUseEnergyCheck(session comm.IUserSession, req *pb.HeroResonanceUseEnergyReq) (code pb.ErrorCode) {
|
|
if len(req.HeroObjID) == 0 || req.UseEnergy <= 0 || req.UseType < 0 || req.UseType > 3 {
|
|
code = pb.ErrorCode_ReqParameterError
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
func (this *apiComp) ResonanceUseEnergy(session comm.IUserSession, req *pb.HeroResonanceUseEnergyReq) (code pb.ErrorCode, data proto.Message) {
|
|
var (
|
|
_hero *pb.DBHero
|
|
)
|
|
code = this.ResonanceUseEnergyCheck(session, req) // check
|
|
if code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
|
|
_hero, code = this.module.GetHeroByObjID(session.GetUserId(), req.HeroObjID) // 查询目标卡是否存在
|
|
if code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
if _hero.DistributionResonate < req.UseEnergy { // 能量点数不够
|
|
code = pb.ErrorCode_HeroNoEnergy
|
|
return
|
|
}
|
|
|
|
_hero.Energy[req.UseType] += req.UseEnergy
|
|
|
|
_heroMap := map[string]interface{}{
|
|
"DistributionResonate": _hero.ResonateNum - req.UseEnergy, // 减没有分配的能量
|
|
"Energy": _hero.Energy,
|
|
"isOverlying": false,
|
|
}
|
|
|
|
err1 := this.module.modelHero.ChangeList(session.GetUserId(), req.HeroObjID, _heroMap) // 修改英雄信息
|
|
if err1 != nil {
|
|
code = pb.ErrorCode_DBError
|
|
this.module.Errorf("update hero skill failed:%v", err1)
|
|
return
|
|
}
|
|
// 计算属性
|
|
resonConfig, errr := this.module.configure.GetHeroResonanceConfig(_hero.HeroID)
|
|
if errr != nil {
|
|
code = pb.ErrorCode_ConfigNoFound
|
|
return
|
|
}
|
|
// 修改玩家属性
|
|
property := make(map[string]int32, 0)
|
|
switch req.UseType {
|
|
case 1:
|
|
property[comm.Hp] = int32(math.Floor((1.0 + float64(resonConfig.Hppro*req.UseEnergy)/1000) * float64(_hero.Property[comm.Hp])))
|
|
case 2:
|
|
property[comm.Atk] = int32(math.Floor((1.0 + float64(resonConfig.Atkpro*req.UseEnergy)/1000) * float64(_hero.Property[comm.Atk])))
|
|
case 3:
|
|
property[comm.Def] = int32(math.Floor((1.0 + float64(resonConfig.Defpro*req.UseEnergy)/1000) * float64(_hero.Property[comm.Def])))
|
|
}
|
|
this.module.modelHero.mergeMainProperty(session.GetUserId(), _hero, property)
|
|
|
|
m, err1 := this.module.modelHero.PushHeroProperty(session, _hero.Id) // 推送属性变化
|
|
if err1 != nil {
|
|
this.module.Errorf("PushHeroProperty err!")
|
|
}
|
|
_hero.Property = m
|
|
session.SendMsg(string(this.module.GetType()), ResonanceUseEnergy, &pb.HeroResonanceUseEnergyResp{Hero: _hero})
|
|
return
|
|
}
|