88 lines
1.9 KiB
Go
88 lines
1.9 KiB
Go
package whackamole
|
|
|
|
import (
|
|
"fmt"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
)
|
|
|
|
func (this *apiComp) AwakeCheck(session comm.IUserSession, req *pb.WhackamoleAwakeReq) (errdata *pb.ErrorData) {
|
|
|
|
return
|
|
}
|
|
|
|
//觉醒
|
|
func (this *apiComp) Awake(session comm.IUserSession, req *pb.WhackamoleAwakeReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
info *pb.DBWhackamole
|
|
hero *pb.DBWHHero
|
|
conf *cfg.GameTDHeroData
|
|
err error
|
|
)
|
|
|
|
if errdata = this.AwakeCheck(session, req); errdata != nil {
|
|
return
|
|
}
|
|
|
|
if info, err = this.module.model.getModel(session.GetUserId()); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
if info.Fields[req.Index].Hid == "" {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Message: "Fields on hero",
|
|
}
|
|
return
|
|
}
|
|
for _, v := range info.Heros {
|
|
if v.Id == info.Fields[req.Index].Hid {
|
|
hero = v
|
|
break
|
|
}
|
|
}
|
|
if hero == nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Message: fmt.Sprintf("on hero:%s", info.Fields[req.Index].Hid),
|
|
}
|
|
return
|
|
}
|
|
|
|
if conf, err = this.module.configure.getGameTDHeroData(hero.Cid); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
if conf.Needlv > info.Fields[req.Index].Lv {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Message: "field lv notenough",
|
|
}
|
|
return
|
|
}
|
|
|
|
if errdata = this.module.ConsumeRes(session, conf.Needawake, true); errdata != nil {
|
|
return
|
|
}
|
|
|
|
hero.Wake = true
|
|
if err = this.module.model.Change(session.GetUserId(), map[string]interface{}{"heros": info.Heros}); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
session.SendMsg(string(this.module.GetType()), "superior", &pb.WhackamoleSuperiorResp{})
|
|
return
|
|
}
|