拍卖结算
This commit is contained in:
parent
222dbaae19
commit
2dab0dffbc
@ -1,13 +1,17 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"roserver/baseserver/model"
|
||||
model2 "roserver/game/model"
|
||||
"roserver/serverproto"
|
||||
)
|
||||
|
||||
type LiveBidRoom struct {
|
||||
LiveRoom
|
||||
currBidCfg *serverproto.LiveRoomBidCfg
|
||||
currBidInfo *BidInfo
|
||||
currBidCfg *serverproto.LiveRoomBidCfg
|
||||
currBidInfo *BidInfo
|
||||
lastBidPrice uint32
|
||||
}
|
||||
|
||||
type BidInfo struct {
|
||||
@ -17,7 +21,8 @@ type BidInfo struct {
|
||||
|
||||
func newLiveBidRoom(roomId uint32, tickInterval uint32) *LiveBidRoom {
|
||||
room := &LiveBidRoom{
|
||||
LiveRoom: newLiveRoom(roomId, LIVEROOM_TYPE_BID, tickInterval),
|
||||
LiveRoom: newLiveRoom(roomId, LIVEROOM_TYPE_BID, tickInterval),
|
||||
lastBidPrice: 0,
|
||||
}
|
||||
room.SetVF()
|
||||
return room
|
||||
@ -42,7 +47,10 @@ func (self *LiveBidRoom) SetVF() {
|
||||
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() {
|
||||
@ -55,6 +63,22 @@ func (self *LiveBidRoom) CheckIfShowEnd() bool {
|
||||
|
||||
// 结算阶段:给玩家背包里添加东西
|
||||
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 {
|
||||
@ -84,6 +108,13 @@ func (self *LiveBidRoom) GetCMDPlayDataList(readyUidList []uint64, uid uint64, c
|
||||
// 返回客户端显示秒杀成功的玩家信息
|
||||
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
|
||||
}
|
||||
|
||||
@ -97,13 +128,14 @@ func (self *LiveBidRoom) HasShowData() bool {
|
||||
|
||||
func (self *LiveBidRoom) GetShowData(readyUidList []uint64, uid uint64) []*serverproto.KeyValueType64 {
|
||||
submitResult := make([]*serverproto.KeyValueType64, 0)
|
||||
if self.currBidInfo != nil {
|
||||
if self.currBidInfo != nil && self.currBidInfo.bidPrice > self.lastBidPrice {
|
||||
player := RoomMgr.GetPlayer(self.currBidInfo.uid)
|
||||
submitResult = append(submitResult, &serverproto.KeyValueType64{
|
||||
Key: uint64(0),
|
||||
Key: uint64(self.currBidCfg.Id),
|
||||
Value: int32(self.currBidInfo.bidPrice),
|
||||
StrVal: player.Name,
|
||||
StrVal: fmt.Sprintf("head:%s;name:%s", player.HeadId, player.Name),
|
||||
})
|
||||
self.lastBidPrice = self.currBidInfo.bidPrice
|
||||
}
|
||||
return submitResult
|
||||
}
|
||||
@ -111,18 +143,28 @@ func (self *LiveBidRoom) GetShowData(readyUidList []uint64, uid uint64) []*serve
|
||||
// 玩家抢购秒杀
|
||||
func (self *LiveBidRoom) HandleShowSubmit(uid uint64, data []*serverproto.KeyValueType64) []*serverproto.KeyValueType64 {
|
||||
submitResult := make([]*serverproto.KeyValueType64, 0)
|
||||
// 1.先检查玩家是否拥有报价那么多的金币
|
||||
// 2.再检查报价是否比上一轮报价高
|
||||
|
||||
if len(data) > 0 {
|
||||
player := RoomMgr.GetPlayer(uid)
|
||||
bidPrice := uint32(data[0].Value)
|
||||
if (self.currBidInfo != nil && bidPrice > self.currBidInfo.bidPrice) || self.currBidInfo == nil {
|
||||
self.currBidInfo = &BidInfo{uid: uid, bidPrice: uint32(bidPrice)}
|
||||
// 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
|
||||
}
|
||||
player := RoomMgr.GetPlayer(self.currBidInfo.uid)
|
||||
maxPricePlayer := RoomMgr.GetPlayer(self.currBidInfo.uid)
|
||||
submitResult = append(submitResult, &serverproto.KeyValueType64{
|
||||
Key: uint64(bidPrice),
|
||||
Key: uint64(self.currBidCfg.Id),
|
||||
Value: int32(self.currBidInfo.bidPrice),
|
||||
StrVal: player.Name,
|
||||
Value2: int32(bidPrice),
|
||||
StrVal: fmt.Sprintf("head:%s;name:%s", maxPricePlayer.HeadId, maxPricePlayer.Name),
|
||||
})
|
||||
}
|
||||
return submitResult
|
||||
@ -132,9 +174,9 @@ func (self *LiveBidRoom) GetStageEnterParams(stage uint32) string {
|
||||
stageEnterParams := ""
|
||||
switch stage {
|
||||
case LIVEROOM_STAGE_READY:
|
||||
stageEnterParams = string(self.currBidCfg.Id)
|
||||
stageEnterParams = fmt.Sprintf("bidCfgId:%d", self.currBidCfg.Id)
|
||||
case LIVEROOM_STAGE_SHOW:
|
||||
stageEnterParams = string(self.currBidCfg.Id)
|
||||
stageEnterParams = fmt.Sprintf("bidCfgId:%d", self.currBidCfg.Id)
|
||||
}
|
||||
return stageEnterParams
|
||||
}
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"roserver/baseserver/model"
|
||||
model2 "roserver/game/model"
|
||||
"roserver/serverproto"
|
||||
@ -45,7 +46,7 @@ func (self *LiveSellRoom) SetVF() {
|
||||
func (self *LiveSellRoom) ReadyStart() {
|
||||
liveRoomSellCfg := serverproto.LiveRoomSellCfgLoader
|
||||
self.currSellIds = RandomKeys(liveRoomSellCfg, 1)
|
||||
self.roomStateData["sellId"] = string(self.currSellIds[0])
|
||||
self.roomStateData["sellId"] = fmt.Sprintf("%d", self.currSellIds[0])
|
||||
self.currSellInfos = make([]*SellInfo, 0)
|
||||
for _, sellId := range self.currSellIds {
|
||||
self.currSellInfos = append(self.currSellInfos, &SellInfo{
|
||||
@ -153,7 +154,7 @@ func (self *LiveSellRoom) GetStageEnterParams(stage uint32) string {
|
||||
stageEnterParams := ""
|
||||
switch stage {
|
||||
case LIVEROOM_STAGE_READY:
|
||||
stageEnterParams = JoinSlice(self.currSellIds, ":")
|
||||
stageEnterParams = fmt.Sprintf("sellId:%d", self.currSellIds[0])
|
||||
}
|
||||
return stageEnterParams
|
||||
}
|
||||
|
||||
@ -156,6 +156,10 @@ func init() {
|
||||
player.Level = msg.PlayerInfo.Level
|
||||
player.CoinNum = msg.CoinNum
|
||||
player.GameChipNum = msg.GameChipNum
|
||||
oldRoom, _ := model2.RoomMgr.GetLiveRoomByUid(msg.Uid)
|
||||
if oldRoom != nil {
|
||||
oldRoom.Leave(msg.Uid)
|
||||
}
|
||||
liveRoom, err := model2.RoomMgr.FindLiveRoom(msg.Uid, msg.RoomType)
|
||||
if err != nil {
|
||||
ackMsg := &serverproto.SCLiveRoomJoinAck{
|
||||
|
||||
@ -104,6 +104,8 @@ const (
|
||||
AddFrom_LiveRoom_Card
|
||||
AddFrom_LiveRoom_Answer
|
||||
AddFrom_LiveRoom_Gift
|
||||
AddFrom_LiveRoom_Sell
|
||||
AddFrom_LiveRoom_Bid
|
||||
)
|
||||
|
||||
type RoleBag struct {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user