34 changed files with 494 additions and 53 deletions
@ -0,0 +1,83 @@ |
|||
package game |
|||
|
|||
import ( |
|||
"base/log" |
|||
"strconv" |
|||
"time" |
|||
"xgame/game/DZ/app/core/protocol" |
|||
"xgame/game/DZ/app/route" |
|||
) |
|||
|
|||
func (rr *Room) OnUserTableTake(uid int64, msg interface{}) { // 带入金币
|
|||
message := msg.(*protocol.TableTakeReq) |
|||
TableTakeRes := &protocol.TableTakeRes{} |
|||
|
|||
ChairId := int32(-1) |
|||
for _, player := range rr.PlayerMap { |
|||
if player.Uid == uid { |
|||
ChairId = player.ChairId |
|||
break |
|||
} |
|||
} |
|||
|
|||
if ChairId == -1 { |
|||
log.Debug(" 桌子号", rr.RId, " ChairId == -1") |
|||
return |
|||
} |
|||
|
|||
player := rr.PlayerMap[ChairId] |
|||
|
|||
//判断用户带入的钱是否超过自身持有
|
|||
if !player.IsRobot && message.Score > player.Gold.IntPart() { |
|||
log.Debug(" 桌子号", rr.RId, " 玩家", ChairId, "带入金额超过自身持有 想带入", message.Score, " 实际持有", player.Gold.IntPart()) |
|||
TableTakeRes.Code = protocol.ErrorTableTakeNotEnoughScore |
|||
TableTakeRes.CodeMsg = "带入金额超过自身持有 你只有 " + strconv.Itoa(int(player.Gold.IntPart())) |
|||
rr.Send(rr.PlayerMap[ChairId], route.TableTakeRes, TableTakeRes) |
|||
return |
|||
} |
|||
|
|||
//判断用户带入的钱是否符合规则
|
|||
if message.Score+player.TableScore > rr.Opt.MaxTableTake || message.Score+player.TableScore < rr.Opt.MinTableTake { |
|||
log.Debug(" 桌子号", rr.RId, " 玩家", ChairId, "带入金额不符合带入限制 想带入", message.Score, " 实际最小限制", rr.Opt.MinTableTake, " 最大限制", rr.Opt.MaxTableTake) |
|||
TableTakeRes.Code = protocol.ErrorTableTakeNotLimitScore |
|||
TableTakeRes.CodeMsg = "带入金额不符合带入限制" |
|||
rr.Send(rr.PlayerMap[ChairId], route.TableTakeRes, TableTakeRes) |
|||
return |
|||
} |
|||
|
|||
player.TableScore += message.Score |
|||
delete(rr.NeedOutPlayer, player.ChairId) |
|||
|
|||
rr.Send(player, route.TableTakeRes, TableTakeRes) |
|||
|
|||
// 通知其它人谁入金了
|
|||
for _, player2 := range rr.PlayerMap { |
|||
if player2.IsRobot { |
|||
continue |
|||
} |
|||
|
|||
NotifyTableTake := &protocol.NotifyTableTake{ |
|||
ChairID: player.ChairId, |
|||
Score: player.TableScore, |
|||
} |
|||
rr.Send(player2, route.NotifyWhoTableTake, NotifyTableTake) |
|||
} |
|||
|
|||
//判断开场
|
|||
if rr.State < EN_TABLE_STATE_PLAYING && rr.GetRoomCanPlayPlayerCount() > 2 { |
|||
rr.State = EN_TABLE_STATE_PLAYING |
|||
milliseconds := time.Now().UnixMilli() |
|||
rr.CurrentGameState = protocol.STATE_GET_BANKER |
|||
rr.CurrentOperationTimer = milliseconds + rr.TimeOutGetBanker |
|||
rr.RepeatRoomUser() |
|||
|
|||
log.Debug(" 桌子号", rr.RId, " 开始游戏 抢庄倒计时 ", rr.TimeOutGetBanker) |
|||
|
|||
rr.SendAllMessage(route.NotifyStateTime, &protocol.NotifyStateTime{ |
|||
NextState: protocol.STATE_GET_BANKER, |
|||
NextTimestamp: rr.CurrentOperationTimer, |
|||
}) |
|||
// 抢庄做了加一秒的容错判断
|
|||
rr.CurrentOperationTimer += 1000 |
|||
} |
|||
} |
Loading…
Reference in new issue