update
This commit is contained in:
parent
86111c04ea
commit
36a37c8c7c
@ -38,6 +38,15 @@ func (this *apiComp) Match(session comm.IUserSession, req *pb.EntertainMatchReq)
|
||||
}
|
||||
}
|
||||
}
|
||||
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", // 机器人临时数据
|
||||
}
|
||||
}
|
||||
|
||||
// if users, err := this.module.ModuleUser.UserOnlineList(); err == nil {
|
||||
// if len(users) > 0 {
|
||||
|
@ -18,7 +18,10 @@ func (this *apiComp) OperatorCheck(session comm.IUserSession, req *pb.EntertainO
|
||||
|
||||
func (this *apiComp) Operator(session comm.IUserSession, req *pb.EntertainOperatorReq) (errdata *pb.ErrorData) {
|
||||
|
||||
this.module.gameMgr.RoomDistribute(req.Roomid, session, "opertor", req)
|
||||
|
||||
this.module.gameMgr.RoomDistribute(req.Roomid, session, "operator", req)
|
||||
// 操作消息返回
|
||||
session.SendMsg(string(this.module.GetType()), "operator", &pb.EntertainOperatorResp{
|
||||
Success: true,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
@ -19,6 +19,8 @@ func (this *apiComp) ReadyCheck(session comm.IUserSession, req *pb.EntertainRead
|
||||
func (this *apiComp) Ready(session comm.IUserSession, req *pb.EntertainReadyReq) (errdata *pb.ErrorData) {
|
||||
|
||||
this.module.gameMgr.RoomDistribute(req.Roomid, session, "ready", req)
|
||||
|
||||
session.SendMsg(string(this.module.GetType()), "ready", &pb.EntertainReadyResp{
|
||||
Ready: true,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ import (
|
||||
const (
|
||||
MaxPs = 2 // 最大体力
|
||||
MaxRound = 7 // 最大回合数
|
||||
MaxTime = 180 // 游戏操作时间
|
||||
)
|
||||
|
||||
//游戏房间
|
||||
@ -47,17 +48,31 @@ func (this *Room) operateTimeOut(task *timewheel.Task, args ...interface{}) {
|
||||
if this.round > MaxRound*2 { // 游戏结束
|
||||
this.GameOver()
|
||||
}
|
||||
this.operatetimer = timewheel.Add(time.Second*8, this.operateTimeOut) // 开启新的定时器
|
||||
this.operatetimer = timewheel.Add(time.Second*MaxTime, this.operateTimeOut) // 开启新的定时器
|
||||
var szMap []*pb.MapData
|
||||
szMap = append(szMap, &pb.MapData{
|
||||
Data: this.chessboard.Plat,
|
||||
})
|
||||
//this.module.Debugf("超时%d", configure.Now().Unix())
|
||||
if err := this.SendMsgToSession(string(this.module.GetType()), "operatorrst", &pb.EntertainOperatorRstPush{
|
||||
Mpadata: szMap,
|
||||
Power: this.power,
|
||||
Score: 0,
|
||||
Round: this.round,
|
||||
User1: this.player1,
|
||||
User2: this.player2,
|
||||
}, this.szSession...); err != nil {
|
||||
this.Errorln(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (this *Room) InitRoom(module *Entertainment, s1 comm.IUserSession, s2 comm.IUserSession, p1 *pb.PlayerData, p2 *pb.PlayerData) *Room {
|
||||
this.chessboard = new(MapData)
|
||||
this.chessboard.InitMap() // 初始化棋盘
|
||||
|
||||
this.szSession = append(this.szSession, s1)
|
||||
this.szSession = append(this.szSession, s1.Clone())
|
||||
if p2.Uid != "999" { // 是否是机器人
|
||||
this.szSession = append(this.szSession, s2)
|
||||
this.szSession = append(this.szSession, s2.Clone())
|
||||
}
|
||||
|
||||
return &Room{
|
||||
@ -69,6 +84,7 @@ func (this *Room) InitRoom(module *Entertainment, s1 comm.IUserSession, s2 comm.
|
||||
module: module,
|
||||
power: s1.GetUserId(),
|
||||
round: 1,
|
||||
szSession: this.szSession,
|
||||
}
|
||||
}
|
||||
|
||||
@ -105,7 +121,7 @@ func (this *Room) AiTimeOut(task *timewheel.Task, args ...interface{}) {
|
||||
if this.operatetimer != nil {
|
||||
timewheel.Remove(this.operatetimer)
|
||||
}
|
||||
this.operatetimer = timewheel.Add(time.Second*8, this.operateTimeOut) // 开启新的定时器
|
||||
this.operatetimer = timewheel.Add(time.Second*MaxTime, this.operateTimeOut) // 开启新的定时器
|
||||
// 广播消息
|
||||
if err := this.SendMsgToSession(string(this.module.GetType()), "operatorrst", &pb.EntertainOperatorRstPush{
|
||||
Mpadata: szMap,
|
||||
@ -121,7 +137,7 @@ func (this *Room) AiTimeOut(task *timewheel.Task, args ...interface{}) {
|
||||
|
||||
func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg proto.Message) (errdata *pb.ErrorData) {
|
||||
switch stype {
|
||||
case "opertor": // 操作消息
|
||||
case "operator": // 操作消息
|
||||
var (
|
||||
curScore int32
|
||||
)
|
||||
@ -148,11 +164,8 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr
|
||||
if this.operatetimer != nil {
|
||||
timewheel.Remove(this.operatetimer)
|
||||
}
|
||||
this.operatetimer = timewheel.Add(time.Second*8, this.operateTimeOut) // 开启新的定时器
|
||||
// 操作消息返回
|
||||
session.SendMsg(string(this.module.GetType()), "operator", &pb.EntertainOperatorResp{
|
||||
Success: true,
|
||||
})
|
||||
this.operatetimer = timewheel.Add(time.Second*MaxTime, this.operateTimeOut) // 开启新的定时器
|
||||
|
||||
if this.power == this.player1.Uid { //权限校验
|
||||
this.player1.Score += curScore
|
||||
this.player1.Ps--
|
||||
@ -164,7 +177,7 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr
|
||||
if this.aiTimer != nil {
|
||||
timewheel.Remove(this.aiTimer)
|
||||
}
|
||||
this.aiTimer = timewheel.Add(time.Second*3, this.AiTimeOut)
|
||||
this.aiTimer = timewheel.Add(time.Second*MaxTime, this.AiTimeOut)
|
||||
}
|
||||
this.round++
|
||||
}
|
||||
@ -180,6 +193,7 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr
|
||||
} else { // err 未知权限
|
||||
return
|
||||
}
|
||||
|
||||
// 广播消息
|
||||
if err := this.SendMsgToSession(string(this.module.GetType()), "operatorrst", &pb.EntertainOperatorRstPush{
|
||||
Mpadata: szMap,
|
||||
@ -193,7 +207,8 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr
|
||||
}
|
||||
case "ready":
|
||||
this.StartGame()
|
||||
this.operatetimer = timewheel.Add(time.Second*8, this.operateTimeOut)
|
||||
|
||||
this.operatetimer = timewheel.Add(time.Second*MaxTime, this.operateTimeOut)
|
||||
}
|
||||
|
||||
return
|
||||
|
Loading…
Reference in New Issue
Block a user