2025-12-05 20:15:55 +08:00
|
|
|
package model
|
|
|
|
|
|
2025-12-09 17:49:29 +08:00
|
|
|
import (
|
|
|
|
|
"roserver/serverproto"
|
|
|
|
|
"sort"
|
|
|
|
|
"strconv"
|
|
|
|
|
)
|
2025-12-05 20:15:55 +08:00
|
|
|
|
|
|
|
|
type LiveGameRoom struct {
|
|
|
|
|
LiveRoom
|
2025-12-09 17:49:29 +08:00
|
|
|
scoreRank []*serverproto.KeyValueType64
|
2025-12-05 20:15:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func newLiveGameRoom(roomId uint32, tickInterval uint32) *LiveGameRoom {
|
|
|
|
|
room := &LiveGameRoom{
|
|
|
|
|
LiveRoom: newLiveRoom(roomId, LIVEROOM_TYPE_GAME, tickInterval),
|
|
|
|
|
}
|
|
|
|
|
return room
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-09 17:49:29 +08:00
|
|
|
func (self *LiveGameRoom) ShowStart() {
|
|
|
|
|
self.scoreRank = make([]*serverproto.KeyValueType64, 0)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 对游戏进行结算
|
|
|
|
|
func (self *LiveGameRoom) ShowEnd() {}
|
|
|
|
|
|
2025-12-05 20:15:55 +08:00
|
|
|
func (self *LiveGameRoom) GetMaxReadyNum(roomType uint32) int {
|
|
|
|
|
return LIVEROOM_GAME_MAX_READY_NUM
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-12 19:20:10 +08:00
|
|
|
func (self *LiveGameRoom) GetPlayDataList(readyUidList []uint64, uid uint64, cfg *serverproto.LiveRoomTalkCfg) []*serverproto.KeyValueType64 {
|
2025-12-05 20:15:55 +08:00
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-09 17:49:29 +08:00
|
|
|
// 返回玩家分数排名
|
|
|
|
|
func (self *LiveGameRoom) GetShowResultList(readyUidList []uint64, uid uint64) []*serverproto.LiveRoomPlayerInfo {
|
|
|
|
|
playerResults := make([]*serverproto.LiveRoomPlayerInfo, 0)
|
|
|
|
|
maxResultNum := 10
|
|
|
|
|
// 首先检查自己的排名
|
|
|
|
|
for _, v := range self.scoreRank {
|
|
|
|
|
if v.Key == uid {
|
|
|
|
|
currPlayerInfo := MakeLiveRoomPlayerInfo(uid)
|
|
|
|
|
currPlayerInfo.Data = string(v.Value)
|
|
|
|
|
playerResults = append(playerResults, currPlayerInfo)
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for _, v := range self.scoreRank {
|
|
|
|
|
if v.Key != uid && len(playerResults) < maxResultNum {
|
|
|
|
|
currPlayerInfo := MakeLiveRoomPlayerInfo(v.Key)
|
|
|
|
|
currPlayerInfo.Data = string(v.Value)
|
|
|
|
|
playerResults = append(playerResults, currPlayerInfo)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
sort.Slice(playerResults, func(i, j int) bool {
|
|
|
|
|
val1, _ := strconv.Atoi(playerResults[i].Data)
|
|
|
|
|
val2, _ := strconv.Atoi(playerResults[j].Data)
|
|
|
|
|
return val1 > val2
|
|
|
|
|
})
|
|
|
|
|
return playerResults
|
2025-12-05 20:15:55 +08:00
|
|
|
}
|
|
|
|
|
|
2025-12-09 17:49:29 +08:00
|
|
|
// 返回玩家玩游戏得到的奖励
|
|
|
|
|
func (self *LiveGameRoom) GetShowRewardList(readyUidList []uint64, uid uint64) []*serverproto.KeyValueType64 {
|
2025-12-05 20:15:55 +08:00
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-09 17:49:29 +08:00
|
|
|
func (self *LiveGameRoom) HasShowData() bool {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 返回游戏过程中的状态数据
|
|
|
|
|
func (self *LiveGameRoom) GetShowData(readyUidList []uint64, uid uint64) []*serverproto.KeyValueType64 {
|
|
|
|
|
submitResult := make([]*serverproto.KeyValueType64, 0)
|
|
|
|
|
return submitResult
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 处理玩家在游戏过程中提交的输入,比如玩家的得分;返回自己的排名
|
|
|
|
|
func (self *LiveGameRoom) HandleShowSubmit(uid uint64, data []*serverproto.KeyValueType64) []*serverproto.KeyValueType64 {
|
|
|
|
|
submitResult := make([]*serverproto.KeyValueType64, 0)
|
|
|
|
|
for _, v := range data {
|
|
|
|
|
k_uid := v.Key
|
|
|
|
|
v_score := v.Value
|
|
|
|
|
isFind := false
|
|
|
|
|
for _, scoreKV := range self.scoreRank {
|
|
|
|
|
if scoreKV.Key == k_uid {
|
|
|
|
|
scoreKV.Value = v_score
|
|
|
|
|
isFind = true
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if isFind == false {
|
|
|
|
|
self.scoreRank = append(self.scoreRank, &serverproto.KeyValueType64{
|
|
|
|
|
Key: k_uid,
|
|
|
|
|
Value: v_score,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
sort.Slice(self.scoreRank, func(i, j int) bool {
|
|
|
|
|
return self.scoreRank[i].Value > self.scoreRank[j].Value
|
|
|
|
|
})
|
|
|
|
|
rankNo := 0
|
|
|
|
|
for i, v := range self.scoreRank {
|
|
|
|
|
if v.Key == uid {
|
|
|
|
|
rankNo = i + 1
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
submitResult = append(submitResult, &serverproto.KeyValueType64{
|
|
|
|
|
Key: uid,
|
|
|
|
|
Value: int32(rankNo),
|
|
|
|
|
})
|
|
|
|
|
return submitResult
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 返回进入游戏阶段的一些初始化配置数据
|
|
|
|
|
func (self *LiveGameRoom) GetStageEnterParams(stage uint32) string {
|
|
|
|
|
stageEnterParams := ""
|
|
|
|
|
switch stage {
|
|
|
|
|
case LIVEROOM_STAGE_SHOW:
|
|
|
|
|
stageEnterParams = "flip_bird"
|
|
|
|
|
}
|
|
|
|
|
return stageEnterParams
|
2025-12-05 20:15:55 +08:00
|
|
|
}
|