go_dreamfactory/modules/moonfantasy/api_battle.go
2023-04-28 21:20:04 +08:00

127 lines
3.4 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) (code pb.ErrorCode) {
return
}
///挑战怪物请求
func (this *apiComp) Battle(session comm.IUserSession, req *pb.MoonfantasyBattleReq) (code pb.ErrorCode, data *pb.ErrorData) {
var (
boss *cfg.GameDreamlandBoosData
// umfantasy *pb.DBUserMFantasy
mdata *pb.DBMoonFantasy
record *pb.DBBattleRecord
cd pb.ErrorCode
isjoin bool
err error
)
defer func() {
if cd == pb.ErrorCode_Success {
// this.module.modelUserMF.Change(session.GetUserId(), map[string]interface{}{
// "ticket": umfantasy.Ticket,
// })
this.module.modelDream.ChangeList("", mdata.Id, map[string]interface{}{
"record": mdata.Record,
})
session.SendMsg(string(this.module.GetType()), "battle", &pb.MoonfantasyBattleResp{
Code: cd,
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,
},
})
// this.module.ModuleRtask.SendToRtask(session, comm.Rtype88, 1)
this.module.ModuleRtask.TriggerTask(session.GetUserId(), comm.GettaskParam(comm.Rtype88, 1))
} 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
}
if this.module.modelDream.checkMFantasyExpiration(mdata) { //已过期
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 umfantasy, err = this.module.modelUserMF.queryUsermfantasy(session.GetUserId()); err != nil {
// cd = pb.ErrorCode_CacheReadError
// }
// if umfantasy.Ticket < this.module.ModuleTools.GetGlobalConf().DreamlandCos {
// cd = pb.ErrorCode_MoonfantasyNotEnoughbattles
// }
// umfantasy.Ticket -= this.module.ModuleTools.GetGlobalConf().DreamlandCos
if boss, err = this.module.configure.GetMonsterById(mdata.Monster); err != nil {
cd = pb.ErrorCode_ConfigNoFound
return
}
if cd = this.module.ModuleItems.RecoverTicket(session); cd != pb.ErrorCode_Success {
return
}
if cd = this.module.CheckRes(session, boss.PsConsume); cd != pb.ErrorCode_Success {
return
}
if len(mdata.Join) >= int(mdata.Numup) {
cd = pb.ErrorCode_MoonfantasyJoinUp
return
}
if this.module.modelDream.checkMFantasyExpiration(mdata) { //已过期
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.CreatePveBattle(session, &pb.BattlePVEReq{
Ptype: pb.PlayType_moonfantasy,
Format: req.Battle,
Mformat: boss.Monsterformatid,
})
return
}