59 lines
1.4 KiB
Go
59 lines
1.4 KiB
Go
package entertainment
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) MatchCheck(session comm.IUserSession, req *pb.EntertainMatchReq) (errdata *pb.ErrorData) {
|
|
if req.Idcard == "" {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
func (this *apiComp) Match(session comm.IUserSession, req *pb.EntertainMatchReq) (errdata *pb.ErrorData) {
|
|
|
|
var (
|
|
//bMatch bool
|
|
s2 comm.IUserSession
|
|
p1 *pb.PlayerData // 玩家1
|
|
p2 *pb.PlayerData // 玩家2
|
|
roomid string
|
|
)
|
|
// 暂时只做机器人
|
|
if robots, err := this.module.ModuleTools.RandRobotConfig(1); err == nil {
|
|
if len(robots) > 0 {
|
|
p2 = &pb.PlayerData{
|
|
Uid: "999", // AI uid 暂定
|
|
Name: robots[0].Name,
|
|
Score: 0,
|
|
Ps: 0,
|
|
Cardid: "27000001", // 机器人临时数据
|
|
}
|
|
}
|
|
}
|
|
if u, err := this.module.ModuleUser.GetUser(session.GetUserId()); err == nil {
|
|
p1 = &pb.PlayerData{
|
|
Uid: session.GetUserId(), // AI uid 暂定
|
|
Name: u.Name,
|
|
Score: 0,
|
|
Ps: 0,
|
|
Cardid: "27000001", // 机器人临时数据
|
|
}
|
|
}
|
|
|
|
roomid = this.module.gameMgr.CreateRoom(session, s2, p1, p2)
|
|
session.SendMsg(string(this.module.GetType()), "match", &pb.EntertainMatchResp{
|
|
Maych: true,
|
|
Player: p2,
|
|
Roomid: roomid,
|
|
})
|
|
return
|
|
}
|