107 lines
2.5 KiB
Go
107 lines
2.5 KiB
Go
package moonfantasy
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
"time"
|
|
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) BattleCheck(session comm.IUserSession, req *pb.MoonfantasyBattleReq) (code pb.ErrorCode) {
|
|
return
|
|
}
|
|
|
|
///挑战怪物请求
|
|
func (this *apiComp) Battle(session comm.IUserSession, req *pb.MoonfantasyBattleReq) (code pb.ErrorCode, data proto.Message) {
|
|
var (
|
|
globalconf *cfg.GameGlobalData
|
|
boss *cfg.GameDreamlandBoosData
|
|
mdata *pb.DBMoonFantasy
|
|
record *pb.DBBattleRecord
|
|
cd pb.ErrorCode
|
|
isjoin bool
|
|
err error
|
|
)
|
|
|
|
defer func() {
|
|
if cd == pb.ErrorCode_Success {
|
|
session.SendMsg(string(this.module.GetType()), "battle", &pb.MoonfantasyBattleResp{
|
|
Code: cd,
|
|
Mid: mdata.Monster,
|
|
Info: &pb.BattleInfo{
|
|
Id: record.Id,
|
|
Title: record.Title,
|
|
Btype: record.Btype,
|
|
Ptype: record.Ptype,
|
|
RedCompId: record.RedCompId,
|
|
Redflist: record.Redflist,
|
|
BlueCompId: record.BlueCompId,
|
|
Buleflist: record.Buleflist,
|
|
},
|
|
})
|
|
} else {
|
|
session.SendMsg(string(this.module.GetType()), "battle", &pb.MoonfantasyBattleResp{Code: cd})
|
|
}
|
|
|
|
}()
|
|
|
|
if cd = this.BattleCheck(session, req); cd != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
if mdata, err = this.module.modelDream.querymfantasy(req.Mid); err != nil {
|
|
cd = pb.ErrorCode_DBError
|
|
return
|
|
}
|
|
if mdata == nil {
|
|
cd = pb.ErrorCode_MoonfantasyHasExpired
|
|
return
|
|
}
|
|
|
|
for _, v := range mdata.Join {
|
|
if v.Uid == session.GetUserId() {
|
|
isjoin = true
|
|
}
|
|
}
|
|
if !isjoin {
|
|
cd = pb.ErrorCode_MoonfantasyNoJoin
|
|
return
|
|
}
|
|
|
|
if boss, err = this.module.configure.GetMonsterById(mdata.Monster); err != nil {
|
|
cd = pb.ErrorCode_ConfigNoFound
|
|
return
|
|
}
|
|
|
|
if len(mdata.Join) >= int(mdata.Numup) {
|
|
cd = pb.ErrorCode_MoonfantasyJoinUp
|
|
return
|
|
}
|
|
|
|
globalconf = this.module.configure.GetGlobalConf()
|
|
|
|
if time.Now().Sub(time.Unix(mdata.Ctime, 0)).Seconds() >= float64(globalconf.DreamlandLimit) {
|
|
cd = pb.ErrorCode_MoonfantasyHasExpired
|
|
return
|
|
}
|
|
if v, ok := mdata.Record[session.GetUserId()]; ok {
|
|
if v >= mdata.Unitmup {
|
|
cd = pb.ErrorCode_MoonfantasyDareUp
|
|
return
|
|
} else {
|
|
mdata.Record[session.GetUserId()]++
|
|
}
|
|
} else {
|
|
mdata.Record[session.GetUserId()] = 1
|
|
}
|
|
cd, record = this.module.battle.CreatePvbBattle(session, &pb.BattlePVEReq{
|
|
Ptype: pb.PlayType_moonfantasy,
|
|
Leadpos: req.Leadpos,
|
|
Teamids: req.Teamids,
|
|
Mformat: []int32{boss.Monsterformatid},
|
|
})
|
|
return
|
|
}
|