137 lines
3.5 KiB
Go
137 lines
3.5 KiB
Go
package moonfantasy
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) BattleCheck(session comm.IUserSession, req *pb.MoonfantasyBattleReq) (errdata *pb.ErrorData) {
|
|
return
|
|
}
|
|
|
|
///挑战怪物请求
|
|
func (this *apiComp) Battle(session comm.IUserSession, req *pb.MoonfantasyBattleReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
boss *cfg.GameDreamlandBoosData
|
|
mdata *pb.DBMoonFantasy
|
|
record *pb.DBBattleRecord
|
|
isjoin bool
|
|
err error
|
|
)
|
|
|
|
if errdata = this.BattleCheck(session, req); errdata != nil {
|
|
return
|
|
}
|
|
if mdata, err = this.module.modelDream.querymfantasy(req.Mid); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
if mdata == nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_MoonfantasyHasExpired,
|
|
Title: pb.ErrorCode_MoonfantasyHasExpired.ToString(),
|
|
}
|
|
return
|
|
}
|
|
if this.module.modelDream.checkMFantasyExpiration(mdata) { //已过期
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_MoonfantasyHasExpired,
|
|
Title: pb.ErrorCode_MoonfantasyHasExpired.ToString(),
|
|
}
|
|
return
|
|
}
|
|
for _, v := range mdata.Join {
|
|
if v.Uid == session.GetUserId() {
|
|
isjoin = true
|
|
}
|
|
}
|
|
if !isjoin {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_MoonfantasyNoJoin,
|
|
Title: pb.ErrorCode_MoonfantasyNoJoin.ToString(),
|
|
}
|
|
return
|
|
}
|
|
|
|
if boss, err = this.module.configure.GetMonsterById(mdata.Monster); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
if errdata = this.module.ModuleItems.RecoverTicket(session); errdata != nil {
|
|
return
|
|
}
|
|
if errdata = this.module.CheckRes(session, boss.PsConsume); errdata != nil {
|
|
return
|
|
}
|
|
|
|
if len(mdata.Join) >= int(mdata.Numup) {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_MoonfantasyJoinUp,
|
|
Title: pb.ErrorCode_MoonfantasyJoinUp.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
if this.module.modelDream.checkMFantasyExpiration(mdata) { //已过期
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_MoonfantasyHasExpired,
|
|
Title: pb.ErrorCode_MoonfantasyHasExpired.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
if v, ok := mdata.Record[session.GetUserId()]; ok {
|
|
if v >= mdata.Unitmup {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_MoonfantasyDareUp,
|
|
Title: pb.ErrorCode_MoonfantasyDareUp.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
} else {
|
|
mdata.Record[session.GetUserId()]++
|
|
}
|
|
} else {
|
|
mdata.Record[session.GetUserId()] = 1
|
|
}
|
|
|
|
if errdata, record = this.module.battle.CreatePveBattle(session, &pb.BattlePVEReq{
|
|
Ptype: pb.PlayType_moonfantasy,
|
|
Format: req.Battle,
|
|
Mformat: boss.Monsterformatid,
|
|
}); err != nil {
|
|
return
|
|
}
|
|
|
|
this.module.modelDream.ChangeList("", mdata.Id, map[string]interface{}{
|
|
"record": mdata.Record,
|
|
})
|
|
session.SendMsg(string(this.module.GetType()), "battle", &pb.MoonfantasyBattleResp{
|
|
Mid: mdata.Monster,
|
|
Info: &pb.BattleInfo{
|
|
Id: record.Id,
|
|
Title: record.Title,
|
|
Rulesid: boss.BattleReadyID,
|
|
Btype: record.Btype,
|
|
Ptype: record.Ptype,
|
|
RedCompId: record.RedCompId,
|
|
Redflist: record.Redflist,
|
|
BlueCompId: record.BlueCompId,
|
|
Buleflist: record.Buleflist,
|
|
},
|
|
})
|
|
go this.module.ModuleBuried.TriggerBuried(session.GetUserId(), comm.GetBuriedParam(comm.Rtype88, 1))
|
|
return
|
|
}
|