183 lines
5.7 KiB
Go
183 lines
5.7 KiB
Go
package model
|
|
|
|
import (
|
|
"fmt"
|
|
"roserver/baseserver/model"
|
|
model2 "roserver/game/model"
|
|
"roserver/serverproto"
|
|
)
|
|
|
|
type LiveBidRoom struct {
|
|
LiveRoom
|
|
currBidCfg *serverproto.LiveRoomBidCfg
|
|
currBidInfo *BidInfo
|
|
lastBidPrice uint32
|
|
}
|
|
|
|
type BidInfo struct {
|
|
uid uint64
|
|
bidPrice uint32
|
|
}
|
|
|
|
func newLiveBidRoom(roomId uint32, tickInterval uint32) *LiveBidRoom {
|
|
room := &LiveBidRoom{
|
|
LiveRoom: newLiveRoom(roomId, LIVEROOM_TYPE_BID, tickInterval),
|
|
lastBidPrice: 0,
|
|
}
|
|
room.SetVF()
|
|
return room
|
|
}
|
|
|
|
func (self *LiveBidRoom) SetVF() {
|
|
self.VF_GetMaxReadyNum = self.GetMaxReadyNum
|
|
self.VF_GetCMDPlayDataList = self.GetCMDPlayDataList
|
|
self.VF_GetShowResultList = self.GetShowResultList
|
|
self.VF_GetShowRewardList = self.GetShowRewardList
|
|
self.VF_HasShowData = self.HasShowData
|
|
self.VF_GetShowData = self.GetShowData
|
|
self.VF_HandleShowSubmit = self.HandleShowSubmit
|
|
self.VF_GetStageEnterParams = self.GetStageEnterParams
|
|
self.VF_ReadyStart = self.ReadyStart
|
|
self.VF_ShowStart = self.ShowStart
|
|
self.VF_CheckIfShowEnd = self.CheckIfShowEnd
|
|
self.VF_ShowEnd = self.ShowEnd
|
|
self.VF_HandlePlayCMD = self.HandlePlayCMD
|
|
}
|
|
|
|
func (self *LiveBidRoom) ReadyStart() {
|
|
liveRoomBidCfg := serverproto.LiveRoomBidCfgLoader
|
|
bidIds := RandomKeys(liveRoomBidCfg, 1)
|
|
self.currBidInfo = nil
|
|
self.lastBidPrice = 0
|
|
self.currBidCfg = liveRoomBidCfg[bidIds[0]]
|
|
self.roomStateData["bidCfgId"] = fmt.Sprintf("%d", self.currBidCfg.Id)
|
|
}
|
|
|
|
func (self *LiveBidRoom) ShowStart() {
|
|
|
|
}
|
|
|
|
func (self *LiveBidRoom) CheckIfShowEnd() bool {
|
|
return false
|
|
}
|
|
|
|
// 结算阶段:给玩家背包里添加东西
|
|
func (self *LiveBidRoom) ShowEnd() {
|
|
uid := self.currBidInfo.uid
|
|
costItems := make([]*serverproto.KeyValueType, 0)
|
|
costItems = append(costItems, &serverproto.KeyValueType{
|
|
Key: int32(serverproto.ResType_Res_Rmb),
|
|
Value: int32(self.currBidInfo.bidPrice),
|
|
})
|
|
self.DeleteItemList(uid, costItems, int32(model2.AddFrom_LiveRoom_Bid), false)
|
|
addItems := make([]*serverproto.KeyValueType, 0)
|
|
for _, itemInfo := range self.currBidCfg.Items {
|
|
itemId, itemNum := model.Str2Res(itemInfo)
|
|
addItems = append(addItems, &serverproto.KeyValueType{
|
|
Key: itemId,
|
|
Value: itemNum,
|
|
})
|
|
}
|
|
self.AddItemList(uid, addItems, int32(model2.AddFrom_LiveRoom_Bid), true)
|
|
}
|
|
|
|
func (self *LiveBidRoom) GetMaxReadyNum(roomType uint32) int {
|
|
return LIVEROOM_BID_MAX_READY_NUM
|
|
}
|
|
|
|
func (self *LiveBidRoom) HandlePlayCMD(cfg *serverproto.LiveRoomTalkCfg) {}
|
|
|
|
// 返回客户端显示拍卖的商品信息
|
|
func (self *LiveBidRoom) GetCMDPlayDataList(readyUidList []uint64, uid uint64, cfg *serverproto.LiveRoomTalkCfg) []*serverproto.KeyValueType64 {
|
|
dataList := make([]*serverproto.KeyValueType64, 0)
|
|
//if len(cfg.Params1) > 0 {
|
|
// playParam := cfg.Params1[0]
|
|
// switch playParam {
|
|
// case LIVEROOM_CMD_PLAY_PARAM_BidPreview:
|
|
// dataList = append(dataList, &serverproto.KeyValueType64{
|
|
// Key: uint64(self.currBidCfg.Id),
|
|
// StrVal: "",
|
|
// })
|
|
// case LIVEROOM_CMD_PLAY_PARAM_Bid:
|
|
// // 每轮开始出价,显示上一轮的竞拍结果
|
|
// }
|
|
//}
|
|
return dataList
|
|
}
|
|
|
|
// 返回客户端显示秒杀成功的玩家信息
|
|
func (self *LiveBidRoom) GetShowResultList(readyUidList []uint64, uid uint64) []*serverproto.LiveRoomPlayerInfo {
|
|
playerResults := make([]*serverproto.LiveRoomPlayerInfo, 0)
|
|
player := RoomMgr.GetPlayer(self.currBidInfo.uid)
|
|
playerResults = append(playerResults, &serverproto.LiveRoomPlayerInfo{
|
|
Uid: player.Uid,
|
|
Nickname: player.Name,
|
|
HeadId: player.HeadId,
|
|
Data: fmt.Sprintf("bidPrice:%d;bidCfgId:%d", self.currBidInfo.bidPrice, self.currBidCfg.Id),
|
|
})
|
|
return playerResults
|
|
}
|
|
|
|
func (self *LiveBidRoom) GetShowRewardList(readyUidList []uint64, uid uint64) []*serverproto.KeyValueType64 {
|
|
return nil
|
|
}
|
|
|
|
func (self *LiveBidRoom) HasShowData() bool {
|
|
return true
|
|
}
|
|
|
|
func (self *LiveBidRoom) GetShowData(readyUidList []uint64, uid uint64) []*serverproto.KeyValueType64 {
|
|
submitResult := make([]*serverproto.KeyValueType64, 0)
|
|
if self.currBidInfo != nil && self.currBidInfo.bidPrice > self.lastBidPrice {
|
|
player := RoomMgr.GetPlayer(self.currBidInfo.uid)
|
|
submitResult = append(submitResult, &serverproto.KeyValueType64{
|
|
Key: uint64(self.currBidCfg.Id),
|
|
Value: int32(self.currBidInfo.bidPrice),
|
|
StrVal: fmt.Sprintf("head:%s;name:%s", player.HeadId, player.Name),
|
|
})
|
|
self.lastBidPrice = self.currBidInfo.bidPrice
|
|
}
|
|
return submitResult
|
|
}
|
|
|
|
// 玩家抢购秒杀
|
|
func (self *LiveBidRoom) HandleShowSubmit(uid uint64, data []*serverproto.KeyValueType64) []*serverproto.KeyValueType64 {
|
|
submitResult := make([]*serverproto.KeyValueType64, 0)
|
|
|
|
if len(data) > 0 {
|
|
player := RoomMgr.GetPlayer(uid)
|
|
bidPrice := uint32(data[0].Value)
|
|
// 1.先检查玩家是否拥有报价那么多的金币
|
|
if player.CoinNum >= bidPrice {
|
|
if self.currBidInfo == nil {
|
|
self.currBidInfo = &BidInfo{uid: uid, bidPrice: uint32(bidPrice)}
|
|
} else if self.currBidInfo != nil && bidPrice > self.currBidInfo.bidPrice {
|
|
self.currBidInfo.bidPrice = bidPrice
|
|
self.currBidInfo.uid = uid
|
|
}
|
|
} else {
|
|
// 2.再检查报价是否比上一轮报价高
|
|
return submitResult
|
|
}
|
|
maxPricePlayer := RoomMgr.GetPlayer(self.currBidInfo.uid)
|
|
submitResult = append(submitResult, &serverproto.KeyValueType64{
|
|
Key: uint64(self.currBidCfg.Id),
|
|
Value: int32(self.currBidInfo.bidPrice),
|
|
Value2: int32(bidPrice),
|
|
StrVal: fmt.Sprintf("head:%s;name:%s", maxPricePlayer.HeadId, maxPricePlayer.Name),
|
|
})
|
|
}
|
|
return submitResult
|
|
}
|
|
|
|
func (self *LiveBidRoom) GetStageEnterParams(stage uint32) string {
|
|
stageEnterParams := ""
|
|
switch stage {
|
|
case LIVEROOM_STAGE_READY:
|
|
stageEnterParams = fmt.Sprintf("bidCfgId:%d", self.currBidCfg.Id)
|
|
case LIVEROOM_STAGE_SHOW:
|
|
stageEnterParams = fmt.Sprintf("bidCfgId:%d", self.currBidCfg.Id)
|
|
}
|
|
return stageEnterParams
|
|
}
|