Merge branch 'dev' of http://git.legu.cc/liwei_3d/go_dreamfactory into dev
This commit is contained in:
commit
d40ff3c239
@ -38,11 +38,13 @@ type Room struct {
|
||||
RoomType int32 // 房间类型 1 是好友创房 0对战 2 AI 对战
|
||||
MaxTime int32 // 操作时间
|
||||
Playtype int32 //当前房间玩法
|
||||
|
||||
}
|
||||
|
||||
func (this *Room) CloseRoomTimeOut(task *timewheel.Task, args ...interface{}) {
|
||||
fmt.Printf("解散房间超时+++++%d\n", time.Now().Unix()) //倒计时结束还没结束基本是游戏异常 直接清理房间
|
||||
this.ModifyUserRoomInfoData(false)
|
||||
this.Status = 2 // 游戏解散
|
||||
this.ModifyUserRoomInfoData()
|
||||
}
|
||||
|
||||
// 随机一个玩法
|
||||
@ -172,7 +174,7 @@ func (this *Room) AiOperator() {
|
||||
return
|
||||
}
|
||||
this.curPower = this.NexPower
|
||||
if len(this.szSession) == 1 && this.curPower == this.player2.Userinfo.Uid {
|
||||
if this.RoomType == 2 && this.curPower == this.player2.Userinfo.Uid {
|
||||
this.AiOperator()
|
||||
}
|
||||
}
|
||||
@ -414,7 +416,7 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr
|
||||
this.curPower = this.player1.Userinfo.Uid
|
||||
this.player1.Ps = MaxPs
|
||||
this.player2.Ps = 0
|
||||
if len(this.szSession) == 1 { // AI对战的话直接开始游戏
|
||||
if this.RoomType == 2 { // AI对战的话直接开始游戏
|
||||
bStartGame = true
|
||||
} else {
|
||||
if this.player1.Userinfo.Uid == session.GetUserId() {
|
||||
@ -438,7 +440,7 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr
|
||||
}
|
||||
if bStartGame {
|
||||
// 初始化规则相关
|
||||
if len(this.szSession) == 1 {
|
||||
if this.RoomType == 2 {
|
||||
this.MaxTime = this.module.ModuleTools.GetGlobalConf().ConsumePveTime
|
||||
} else {
|
||||
this.MaxTime = this.module.ModuleTools.GetGlobalConf().ConsumePvpTime
|
||||
@ -458,7 +460,7 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr
|
||||
}, this.szSession...); err != nil {
|
||||
this.module.Errorln(err)
|
||||
}
|
||||
this.ModifyUserRoomInfoData(true)
|
||||
this.ModifyUserRoomInfoData()
|
||||
// 游戏开始开启一个定时器 1小时如果还不结束 自动清理
|
||||
this.closeRoomTimer = timewheel.Add(time.Hour, this.CloseRoomTimeOut)
|
||||
}
|
||||
@ -500,7 +502,8 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr
|
||||
}, this.szSession...); err != nil {
|
||||
this.module.Errorln(err)
|
||||
}
|
||||
this.ModifyUserRoomInfoData(false)
|
||||
this.Status = 2
|
||||
this.ModifyUserRoomInfoData()
|
||||
case "operatorover": // 操作完成 开启一个定时器
|
||||
|
||||
if this.player1.Userinfo.Uid == session.GetUserId() {
|
||||
@ -508,7 +511,7 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr
|
||||
} else if this.player2.Userinfo.Uid == session.GetUserId() {
|
||||
this.rd2 = true
|
||||
}
|
||||
if len(this.szSession) == 1 {
|
||||
if this.RoomType == 2 {
|
||||
if err := this.module.SendMsgSyncToSession(string(this.module.GetType()), "startimer", &pb.EntertainStarTimerPush{
|
||||
Time: this.MaxTime,
|
||||
Power: this.curPower,
|
||||
@ -535,7 +538,8 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr
|
||||
req := msg.(*pb.RPCGeneralReqA2)
|
||||
fmt.Printf("useroffline: %v\n", req)
|
||||
if this.RoomType == 2 { // AI 对战直接结束
|
||||
this.ModifyUserRoomInfoData(false)
|
||||
this.Status = 2 // 解散
|
||||
this.ModifyUserRoomInfoData()
|
||||
return
|
||||
}
|
||||
|
||||
@ -559,7 +563,7 @@ func (this *Room) GameOver() (errdata *pb.ErrorData) {
|
||||
if this.player1.Score < this.player2.Score {
|
||||
winner = this.player2
|
||||
winindex = 1
|
||||
if len(this.szSession) == 1 { // 赢家是AI 的话不发奖
|
||||
if this.RoomType == 2 { // 赢家是AI 的话不发奖
|
||||
bReward = false
|
||||
}
|
||||
}
|
||||
@ -630,6 +634,7 @@ func (this *Room) GameOver() (errdata *pb.ErrorData) {
|
||||
|
||||
// 修改房间状态
|
||||
this.Status = 2
|
||||
this.module.Debugf("=====三消 gameover")
|
||||
this.module.SendMsgSyncToSession(string(this.module.GetType()), "gameover", &pb.EntertainGameOverPush{
|
||||
User1: this.player1,
|
||||
User2: this.player2,
|
||||
@ -642,7 +647,7 @@ func (this *Room) GameOver() (errdata *pb.ErrorData) {
|
||||
Reward: atno,
|
||||
Box: box,
|
||||
}, this.szSession...)
|
||||
this.ModifyUserRoomInfoData(false)
|
||||
this.ModifyUserRoomInfoData()
|
||||
if this.closeRoomTimer != nil { // 游戏结束 清理定时器
|
||||
timewheel.Remove(this.closeRoomTimer)
|
||||
this.closeRoomTimer = nil
|
||||
@ -696,12 +701,12 @@ func (this *Room) JoinRoom(module *Entertainment, p *pb.PlayerData) (room *Room,
|
||||
}
|
||||
|
||||
// 修改玩家的房间信息
|
||||
func (this *Room) ModifyUserRoomInfoData(bStart bool) {
|
||||
func (this *Room) ModifyUserRoomInfoData() {
|
||||
var (
|
||||
roomid string
|
||||
path string
|
||||
)
|
||||
if bStart {
|
||||
if this.Status == 1 {
|
||||
roomid = this.Id
|
||||
path = fmt.Sprintf("%s/%s", this.module.service.GetType(), this.module.service.GetId())
|
||||
} else {
|
||||
|
@ -346,7 +346,7 @@ func (this *ModuleBase) SendMsgSyncToSession(mainType, subType string, msg proto
|
||||
MainType: mainType,
|
||||
SubType: subType,
|
||||
Data: data,
|
||||
}, nil); err != nil {
|
||||
}, &pb.RPCMessageReply{}); err != nil { // 同步消息
|
||||
log.Errorf("SendMsgToUsers:%s.%s->%s.%s err:%v", k1, k, mainType, subType, err)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user