Compare commits
3 Commits
a0a0c0ff5e
...
72918c3b8d
| Author | SHA1 | Date | |
|---|---|---|---|
| 72918c3b8d | |||
| 79fee6bc06 | |||
| 546a176a9f |
@@ -256,6 +256,12 @@ func (cl *CardLogic) CanPlay(cards []models.Card, lastPlay *models.PlayRecord) b
|
||||
|
||||
if cardType == models.CardTypeBomb {
|
||||
if lastPlay.CardType == models.CardTypeBomb {
|
||||
// 先比张数,张数多的赢;张数相同再比牌值
|
||||
myCount := cl.getBombCount(cards)
|
||||
lastCount := cl.getBombCount(lastPlay.Cards)
|
||||
if myCount != lastCount {
|
||||
return myCount > lastCount
|
||||
}
|
||||
return cl.getMainValue(cards) > cl.getMainValue(lastPlay.Cards)
|
||||
}
|
||||
if lastPlay.CardType == models.CardTypeRocket {
|
||||
@@ -310,6 +316,17 @@ func (cl *CardLogic) getMainValue(cards []models.Card) int {
|
||||
}
|
||||
}
|
||||
return maxValue
|
||||
return maxValue
|
||||
}
|
||||
|
||||
func (cl *CardLogic) getBombCount(cards []models.Card) int {
|
||||
counts := cl.getValueCounts(cards)
|
||||
for _, c := range counts {
|
||||
if c >= 3 {
|
||||
return c
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
type GameManager struct {
|
||||
@@ -437,18 +454,20 @@ func (gm *GameManager) LeaveRoomWithTTL(roomID, playerID string) error {
|
||||
func (gm *GameManager) MarkPlayerOnline(roomID, playerID string) {
|
||||
gm.mu.Lock()
|
||||
defer gm.mu.Unlock()
|
||||
|
||||
ctx := context.Background()
|
||||
room, err := gm.loadRoom(ctx, roomID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
for _, p := range room.Players {
|
||||
if p.ID == playerID {
|
||||
p.IsOnline = true
|
||||
gm.saveRoom(ctx, room)
|
||||
gm.rdb.Delete(ctx, redis.PlayerTTLKey(playerID))
|
||||
// 刷新用户-房间关联的TTL
|
||||
if p.UserID != "" {
|
||||
gm.rdb.Set(ctx, redis.UserRoomKey(p.UserID), roomID, redis.RoomTTL)
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -627,6 +646,10 @@ func (gm *GameManager) PlayCards(roomID, playerID string, cards []models.Card) e
|
||||
}
|
||||
|
||||
gm.saveRoom(ctx, room)
|
||||
// 刷新用户-房间关联的TTL
|
||||
if player.UserID != "" {
|
||||
gm.rdb.Set(ctx, redis.UserRoomKey(player.UserID), roomID, redis.RoomTTL)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -667,6 +690,13 @@ func (gm *GameManager) Pass(roomID, playerID string) error {
|
||||
}
|
||||
|
||||
gm.saveRoom(ctx, room)
|
||||
// 刷新用户-房间关联的TTL
|
||||
for _, p := range room.Players {
|
||||
if p.ID == playerID && p.UserID != "" {
|
||||
gm.rdb.Set(ctx, redis.UserRoomKey(p.UserID), roomID, redis.RoomTTL)
|
||||
break
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -514,9 +514,14 @@ function canPlay(cards, lastPlay) {
|
||||
if (cardType === 9) return true;
|
||||
if (cardType === 8) {
|
||||
if (lastPlay.cardType === 8) {
|
||||
var myMain = 0, lastMain = 0;
|
||||
// 先比张数,张数多的赢;张数相同再比牌值
|
||||
var myCounts = getValueCounts(cards);
|
||||
var lastCounts = getValueCounts(lastPlay.cards);
|
||||
var myCount = 0, lastCount = 0;
|
||||
for (var k in myCounts) { if (myCounts[k] >= 3) myCount = myCounts[k]; }
|
||||
for (var k in lastCounts) { if (lastCounts[k] >= 3) lastCount = lastCounts[k]; }
|
||||
if (myCount !== lastCount) return myCount > lastCount;
|
||||
var myMain = 0, lastMain = 0;
|
||||
for (var k in myCounts) { if (myCounts[k] >= 3 && parseInt(k) > myMain) myMain = parseInt(k); }
|
||||
for (var k in lastCounts) { if (lastCounts[k] >= 3 && parseInt(k) > lastMain) lastMain = parseInt(k); }
|
||||
return myMain > lastMain;
|
||||
|
||||
Reference in New Issue
Block a user