77 lines
2.1 KiB
Go
77 lines
2.1 KiB
Go
package autoBattle
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) AutoChallengeCheck(session comm.IUserSession, req *pb.AutoBattleChallengeReq) (code pb.ErrorCode) {
|
|
if req.BossId <= 0 || req.Difficulty <= 0 {
|
|
code = pb.ErrorCode_ReqParameterError
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *apiComp) AutoChallenge(session comm.IUserSession, req *pb.AutoBattleChallengeReq) (code pb.ErrorCode, data proto.Message) {
|
|
var (
|
|
battleInfo *pb.BattleInfo
|
|
)
|
|
if code = this.AutoChallengeCheck(session, req); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
list, err := this.module.modelAutoBattle.getAutoBattleList(session.GetUserId())
|
|
if err != nil {
|
|
code = pb.ErrorCode_DBError
|
|
return
|
|
}
|
|
for _, v := range list {
|
|
if v.Ptype == req.Ptype { // 有正在自动战斗的数据
|
|
code = pb.ErrorCode_AutoBattleStatesErr
|
|
return
|
|
}
|
|
}
|
|
// 写入数据
|
|
battle := make(map[string]interface{}, 0)
|
|
_d := &pb.DBAutoBattle{
|
|
Id: primitive.NewObjectID().Hex(),
|
|
Uid: session.GetUserId(),
|
|
AutoWin: req.AutoWin,
|
|
MaxExp: req.MaxExp,
|
|
AutoBuy: req.AutoBuy,
|
|
AutoSell: req.AutoSell,
|
|
Ptype: req.Ptype,
|
|
BossId: req.BossId,
|
|
Difficulty: req.Difficulty,
|
|
}
|
|
battle[_d.Id] = _d
|
|
if err = this.module.modelAutoBattle.AddListByObjId(session.GetUserId(), battle); err != nil {
|
|
code = pb.ErrorCode_DBError
|
|
return
|
|
}
|
|
|
|
// 优先判断门票够不够
|
|
if req.Ptype == pb.PlayType_viking {
|
|
if req.AutoBuy {
|
|
this.viking.AutoBuyTicket(session)
|
|
code = this.viking.CheckBattelParameter(session, req.Battle, req.BossId, req.Difficulty)
|
|
if code == pb.ErrorCode_Success {
|
|
session.SendMsg(string(this.module.GetType()), "challenge", &pb.AutoBattleChallengeResp{
|
|
Info: battleInfo,
|
|
})
|
|
}
|
|
code, battleInfo = this.viking.AutoBattleInfo(session, req.Battle, req.BossId, req.Difficulty)
|
|
if code == pb.ErrorCode_Success {
|
|
session.SendMsg(string(this.module.GetType()), "challenge", &pb.AutoBattleChallengeResp{
|
|
Info: battleInfo,
|
|
})
|
|
}
|
|
}
|
|
}
|
|
return
|
|
}
|