97 lines
2.8 KiB
Go
97 lines
2.8 KiB
Go
package hero
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) ResonanceResetCheck(session comm.IUserSession, req *pb.HeroResonanceResetReq) (result map[string]interface{}, code comm.ErrorCode) {
|
|
if req.HeroObjID == "" {
|
|
code.Code = pb.ErrorCode_ReqParameterError
|
|
return
|
|
}
|
|
_hero, err := this.moduleHero.GetHero(session.GetUserId(), req.HeroObjID) // 查询目标卡是否存在
|
|
if err != 0 {
|
|
code.Code = pb.ErrorCode_HeroNoExist
|
|
return
|
|
}
|
|
if _hero.ResonateNum <= 0 { // 没有共鸣 不允许重置
|
|
code.Code = pb.ErrorCode_HeroNoResonate
|
|
return
|
|
}
|
|
|
|
// 共鸣次数判断
|
|
resonConfig, errr := this.moduleHero.configure.GetHeroResonanceConfig(_hero.HeroID)
|
|
if errr != nil {
|
|
code.Code = pb.ErrorCode_ConfigNoFound
|
|
return
|
|
}
|
|
|
|
if _hero.ResonateNum*resonConfig.Energy >= _hero.DistributionResonate {
|
|
code.Code = pb.ErrorCode_HeroNotNeedResonate // 已经是重置状态
|
|
return
|
|
}
|
|
|
|
_costConfig, err1 := this.moduleHero.configure.GetHeroResonanceRestConfig()
|
|
if err1 != nil {
|
|
code.Code = pb.ErrorCode_ConfigNoFound // 没找到配置消耗
|
|
return
|
|
}
|
|
for _, v := range _costConfig.Var {
|
|
if v.A == "attr" {
|
|
value := this.moduleHero.api.user.QueryAttributeValue(session.GetUserId(), v.T)
|
|
if value < v.N {
|
|
code.Code = pb.ErrorCode_ResNoEnough // 资源不足
|
|
return
|
|
}
|
|
}
|
|
}
|
|
result = map[string]interface{}{
|
|
"resonateNum": _hero.ResonateNum * resonConfig.Energy,
|
|
"heroObj": _hero,
|
|
"_costConfig": _costConfig,
|
|
}
|
|
return
|
|
}
|
|
|
|
/// 英雄共鸣
|
|
func (this *apiComp) ResonanceReset(session comm.IUserSession, agrs map[string]interface{}, req *pb.HeroResonanceResetReq) (code pb.ErrorCode) {
|
|
|
|
restResonance := agrs["resonateNum"].(int32)
|
|
_hero := agrs["heroObj"].(*pb.DBHero)
|
|
_costConfig := agrs["heroObj"].(cfg.Game_comAtnData)
|
|
|
|
defer func() {
|
|
if code == pb.ErrorCode_Success {
|
|
session.SendMsg(string(this.moduleHero.GetType()), ResonanceReset, &pb.HeroResonanceResetResp{Hero: _hero, Energy: _hero.ResonateNum})
|
|
}
|
|
}()
|
|
|
|
for _, v := range _costConfig.Var {
|
|
if v.A == "attr" {
|
|
code = this.moduleHero.api.user.AddAttributeValue(session.GetUserId(), v.T, -v.N) // 扣资源
|
|
}
|
|
}
|
|
|
|
for k := range _hero.Energy { // 清除玩家选择的共鸣属性
|
|
delete(_hero.Energy, k)
|
|
}
|
|
_heroMap := map[string]interface{}{
|
|
"DistributionResonate": restResonance,
|
|
"Energy": _hero.Energy,
|
|
}
|
|
|
|
err := this.moduleHero.modelHero.modifyHero(session.GetUserId(), req.HeroObjID, _heroMap) // 修改英雄信息
|
|
if err != nil {
|
|
log.Errorf("update hero skill failed:%v", err)
|
|
}
|
|
err = this.moduleHero.modelHero.PushHeroProperty(session, _hero.Id) // 推送属性变化
|
|
if err != nil {
|
|
log.Errorf("PushHeroProperty err!")
|
|
}
|
|
return
|
|
}
|