178 lines
5.3 KiB
Go
178 lines
5.3 KiB
Go
package dragon
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/sys/configure"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
"go_dreamfactory/utils"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) TrainCheck(session comm.IUserSession, req *pb.DragonTrainReq) (errdata *pb.ErrorData) {
|
|
if len(req.Oid) == 0 || req.Ttype == 0 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *apiComp) Train(session comm.IUserSession, req *pb.DragonTrainReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
err error
|
|
dragon *pb.DBDragon
|
|
playConf *cfg.GameDragonPlayData
|
|
update map[string]interface{}
|
|
preType int32
|
|
curType int32 // 当前阶段
|
|
reward []*cfg.Gameatn
|
|
preLv int32 // 升级之前的等级
|
|
curLv int32 // 升级之后的等级
|
|
atno []*pb.UserAtno
|
|
speed int32
|
|
chanegList []*pb.DBDragon
|
|
)
|
|
update = make(map[string]interface{})
|
|
rsp := &pb.DragonTrainResp{}
|
|
if errdata = this.TrainCheck(session, req); errdata != nil {
|
|
return
|
|
}
|
|
|
|
if dragon, err = this.module.modelDragon.GetDragonByOid(session.GetUserId(), req.Oid); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
if _, ok := dragon.Play[req.Ttype]; !ok {
|
|
dragon.Play[req.Ttype] = &pb.PlayData{
|
|
Count: 0,
|
|
Cdendtime: 0,
|
|
}
|
|
}
|
|
if dragon.Play[req.Ttype].Cdendtime > configure.Now().Unix() { // cd时间冷却中
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DragonTrainCding,
|
|
Title: pb.ErrorCode_DragonTrainCding.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
if conf, err := this.module.configure.GetDragonConfById(dragon.Dragonid, dragon.Lv); err == nil {
|
|
if playConf, err = this.module.configure.GetDragonPlayConfById(dragon.Dragonid, conf.Type, req.Ttype); err == nil {
|
|
if playConf.Cd > 0 {
|
|
dragon.Play[req.Ttype].Cdendtime = configure.Now().Unix() + int64(playConf.Cd)
|
|
}
|
|
// 校验训练次数
|
|
if dragon.Play[req.Ttype].Count >= playConf.Time {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DragonTrainMaxCount,
|
|
Title: pb.ErrorCode_DragonTrainMaxCount.ToString(),
|
|
}
|
|
return
|
|
}
|
|
// 校验消耗
|
|
if errdata = this.module.CheckRes(session, playConf.Deplete); errdata != nil {
|
|
return
|
|
}
|
|
} else {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
preLv = dragon.Lv
|
|
preType = conf.Type
|
|
dragon.Exp += playConf.Exp // 加经验
|
|
for {
|
|
var addexp int32
|
|
if dragon.Exp >= conf.Exp {
|
|
dragon.Lv += 1
|
|
dragon.Exp -= conf.Exp
|
|
addexp = conf.Exp
|
|
if len(conf.Reward) > 0 {
|
|
reward = append(reward, conf.Reward...)
|
|
}
|
|
speed = conf.Etime
|
|
if conf, err = this.module.configure.GetDragonConfById(dragon.Dragonid, dragon.Lv); err != nil {
|
|
dragon.Lv -= 1
|
|
dragon.Exp += addexp
|
|
break
|
|
}
|
|
} else {
|
|
break
|
|
}
|
|
}
|
|
update["exp"] = dragon.Exp
|
|
update["lv"] = dragon.Lv
|
|
curType = conf.Type
|
|
curLv = dragon.Lv
|
|
} else {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
dragon.Play[req.Ttype].Count += 1 // 次数+1
|
|
update["play"] = dragon.Play
|
|
|
|
if errdata = this.module.ConsumeRes(session, playConf.Deplete, true); errdata != nil {
|
|
return
|
|
}
|
|
if curLv > preLv && len(reward) > 0 { // 看看有没有升级奖励
|
|
if errdata, atno = this.module.DispenseAtno(session, reward, true); errdata != nil {
|
|
return
|
|
}
|
|
rsp.Reward = atno
|
|
}
|
|
if curType != preType { // 坐骑升阶 增加属性
|
|
if c, err := this.module.configure.GetDragonMount(dragon.Dragonid, curType); err != nil {
|
|
dragon.Property = make(map[string]int32)
|
|
dragon.Property["stime"] = c.Stime
|
|
dragon.Property["etime"] = c.Etime
|
|
dragon.Property["hp"] = c.Hp
|
|
dragon.Property["moderate"] = c.Moderate
|
|
dragon.Property["sprint"] = c.Sprint
|
|
dragon.Property["acceleration"] = c.Acceleration
|
|
dragon.Property["deceleration"] = c.Deceleration
|
|
dragon.Property["energyrecover"] = c.Energyrecover
|
|
dragon.Property["caddtime"] = c.Caddtime
|
|
dragon.Property["csubtime"] = c.Csubtime
|
|
update["property"] = dragon.Property // 更新属性
|
|
}
|
|
// 升阶后重置养成属性次数
|
|
dragon.Play = make(map[int32]*pb.PlayData)
|
|
update["play"] = dragon.Play
|
|
|
|
}
|
|
if speed > dragon.Property["etime"] { // 更新最大速度
|
|
dragon.Property["etime"] = speed
|
|
update["property"] = dragon.Property
|
|
}
|
|
rsp.Dragons = dragon
|
|
this.module.modelDragon.UpdateDragonData(session.GetUserId(), dragon.Id, update)
|
|
|
|
chanegList = append(chanegList, dragon)
|
|
session.SendMsg(string(this.module.GetType()), "change", &pb.DragonChangePush{
|
|
Dragons: chanegList,
|
|
})
|
|
session.SendMsg(string(this.module.GetType()), "train", rsp)
|
|
if curLv > preLv { // 升级后统计任务
|
|
go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
|
|
this.module.ModuleBuried.TriggerBuried(session, comm.GetBuriedParam(comm.Rtype235, dragon.Lv, utils.ToInt32(dragon.Dragonid)))
|
|
this.module.WriteUserLog(session.GetUserId(), comm.GMResAddType, "DragonTrainReq", atno)
|
|
})
|
|
}
|
|
return
|
|
}
|