271 lines
7.1 KiB
Go
271 lines
7.1 KiB
Go
package main
|
|
|
|
import (
|
|
"math"
|
|
|
|
"mongo.games.com/goserver/core/logger"
|
|
|
|
"mongo.games.com/game/common"
|
|
"mongo.games.com/game/model"
|
|
hallproto "mongo.games.com/game/protocol/gamehall"
|
|
"mongo.games.com/game/protocol/webapi"
|
|
"mongo.games.com/game/protocol/welfare"
|
|
)
|
|
|
|
type ScenePolicyData struct {
|
|
GameName string
|
|
GameId int32
|
|
GameMode []int32
|
|
DefaultPlayerCnt int32
|
|
EnterAfterStart bool
|
|
BetState int32
|
|
BaseScore int
|
|
}
|
|
|
|
func (spd *ScenePolicyData) Init() bool {
|
|
return true
|
|
}
|
|
|
|
func (spd *ScenePolicyData) GetPlayerNum() int {
|
|
return int(spd.DefaultPlayerCnt)
|
|
}
|
|
|
|
func (spd *ScenePolicyData) GetBaseScore() int {
|
|
return int(spd.BaseScore)
|
|
}
|
|
|
|
func (spd *ScenePolicyData) OnStart(s *Scene) {
|
|
s.NotifyPrivateRoom(common.ListAdd)
|
|
}
|
|
|
|
func (spd *ScenePolicyData) OnStop(s *Scene) {
|
|
s.NotifyPrivateRoom(common.ListDel)
|
|
//// 房主付费,房间没有玩就解散了,返还房主建房费用
|
|
//if s.IsCustom() && s.CustomParam.GetCostType() == 2 && s.currRound == 0 {
|
|
// s.sp.GiveCostPayment(s, s.creator)
|
|
//}
|
|
// 系统房间解散后自动创建
|
|
if s.RoomConfigSystem != nil {
|
|
CustomRoomMgrSingle.Release(s.platform.IdStr, s.RoomConfigSystem.GetId())
|
|
CustomRoomMgrSingle.UpdateCreate(s.platform.IdStr, s.RoomConfigSystem.GetId(), false)
|
|
}
|
|
}
|
|
|
|
func (spd *ScenePolicyData) OnTick(s *Scene) {
|
|
|
|
}
|
|
|
|
func (spd *ScenePolicyData) OnPlayerEnter(s *Scene, snid int32) {
|
|
s.NotifyPrivateRoom(common.ListModify)
|
|
if s.IsCustom() {
|
|
if s.CustomParam.GetCostType() == 1 { // AA
|
|
spd.CostPayment(s, snid)
|
|
}
|
|
}
|
|
}
|
|
|
|
func (spd *ScenePolicyData) OnPlayerLeave(s *Scene, snid int32) {
|
|
s.NotifyPrivateRoom(common.ListModify)
|
|
p := PlayerMgrSington.GetPlayerBySnId(snid)
|
|
if p != nil {
|
|
if p.LotteryCode != nil {
|
|
pack := p.LotteryCode
|
|
p.LotteryCode = nil
|
|
p.SendToClient(int(welfare.SPacketID_PACKET_NotifyLotteryCode), pack)
|
|
logger.Logger.Tracef("NotifyLotteryCode: %v", pack)
|
|
}
|
|
}
|
|
}
|
|
|
|
func (spd *ScenePolicyData) OnSceneState(s *Scene, state int) {
|
|
s.SceneState = int32(state)
|
|
switch state {
|
|
case common.SceneStateWaite:
|
|
s.NotifyPrivateRoom(common.ListModify)
|
|
|
|
case common.SceneStateStart:
|
|
s.NotifyPrivateRoom(common.ListModify)
|
|
if s.IsCustom() {
|
|
//if s.CustomParam.GetCostType() == 1 {
|
|
// for _, v := range s.players {
|
|
// spd.CostPayment(s, v.SnId)
|
|
// }
|
|
//}
|
|
//if s.CustomParam.GetCostType() == 2 { // 房主付费
|
|
// n := 0
|
|
// cfg := PlatformMgrSingleton.GetConfig(s.platform.IdStr).RoomConfig[s.CustomParam.GetRoomConfigId()]
|
|
// for _, v := range cfg.GetCost() {
|
|
// if v != nil && v.GetItemId() == common.ItemIDRoomCard {
|
|
// n += int(v.GetItemNum())
|
|
// }
|
|
// }
|
|
// LotteryMgrInst.AddCostRoomCard(s.platform.IdStr, s.creator, int64(n))
|
|
//}
|
|
s.IsRecruit = false
|
|
s.RecruitTimes = 0
|
|
}
|
|
|
|
case common.SceneStateEnd:
|
|
s.NotifyPrivateRoom(common.ListModify)
|
|
}
|
|
}
|
|
|
|
func (spd *ScenePolicyData) CanEnter(s *Scene, snid int32) int {
|
|
if !spd.EnterAfterStart {
|
|
if s.starting {
|
|
return int(hallproto.OpResultCode_Game_OPRC_GameStarting_Game)
|
|
}
|
|
}
|
|
return 0
|
|
}
|
|
|
|
func (spd *ScenePolicyData) costEnough(costType, playerNum int, roomConfig *webapi.RoomConfig, snid int32, f func(items []*model.Item)) bool {
|
|
isEnough := true
|
|
var items []*model.Item
|
|
if costType == 2 {
|
|
// 房主
|
|
for _, v := range roomConfig.GetCost() {
|
|
if item := BagMgrSingleton.GetItem(snid, v.GetItemId()); item == nil || item.ItemNum < v.GetItemNum() {
|
|
isEnough = false
|
|
break
|
|
} else {
|
|
items = append(items, &model.Item{
|
|
ItemId: v.GetItemId(),
|
|
ItemNum: v.GetItemNum(),
|
|
})
|
|
}
|
|
}
|
|
} else {
|
|
// AA
|
|
for _, v := range roomConfig.GetCost() {
|
|
n := int64(math.Ceil(float64(v.GetItemNum()) / float64(playerNum)))
|
|
if item := BagMgrSingleton.GetItem(snid, v.GetItemId()); item == nil || item.ItemNum < n {
|
|
isEnough = false
|
|
break
|
|
} else {
|
|
items = append(items, &model.Item{
|
|
ItemId: v.GetItemId(),
|
|
ItemNum: n,
|
|
})
|
|
}
|
|
}
|
|
}
|
|
if isEnough {
|
|
f(items)
|
|
}
|
|
return isEnough
|
|
}
|
|
|
|
func (spd *ScenePolicyData) CostEnough(costType, playerNum int, roomConfig *webapi.RoomConfig, snid int32) bool {
|
|
if roomConfig == nil {
|
|
return false
|
|
}
|
|
return spd.costEnough(costType, playerNum, roomConfig, snid, func(items []*model.Item) {})
|
|
}
|
|
|
|
func (spd *ScenePolicyData) CostPayment(s *Scene, snid int32) bool {
|
|
p := PlayerMgrSington.GetPlayerBySnId(snid)
|
|
if p == nil {
|
|
return false
|
|
}
|
|
roomConfig := PlatformMgrSingleton.GetConfig(p.Platform).RoomConfig[s.CustomParam.GetRoomConfigId()]
|
|
if roomConfig == nil {
|
|
return false
|
|
}
|
|
return spd.costEnough(int(s.CustomParam.GetCostType()), s.playerNum, roomConfig, p.SnId, func(items []*model.Item) {
|
|
n := 0
|
|
for _, v := range items {
|
|
if v.ItemId == common.ItemIDRoomCard {
|
|
n += int(v.ItemNum)
|
|
}
|
|
v.ItemNum = -v.ItemNum
|
|
}
|
|
BagMgrSingleton.AddItems(&model.AddItemParam{
|
|
Platform: p.Platform,
|
|
SnId: p.SnId,
|
|
Change: items,
|
|
GainWay: common.GainWayRoomCost,
|
|
Operator: "system",
|
|
Remark: "竞技馆进房费用",
|
|
GameId: int64(s.gameId),
|
|
GameFreeId: int64(s.dbGameFree.GetId()),
|
|
RoomConfigId: roomConfig.GetId(),
|
|
})
|
|
//if s.CustomParam.GetCostType() == 1 { // AA 是在游戏开始后扣的
|
|
LotteryMgrInst.AddCostRoomCard(p.Platform, p.SnId, int64(n))
|
|
//}
|
|
})
|
|
}
|
|
|
|
func (spd *ScenePolicyData) GiveCostPayment(s *Scene, snid int32) bool {
|
|
roomConfig := PlatformMgrSingleton.GetConfig(s.platform.IdStr).RoomConfig[s.CustomParam.GetRoomConfigId()]
|
|
if roomConfig == nil {
|
|
return false
|
|
}
|
|
|
|
if s.CustomParam.GetCostType() != 2 { // 只有房主付费才有返还
|
|
return false
|
|
}
|
|
|
|
var items []*model.Item
|
|
for _, v := range roomConfig.GetCost() {
|
|
items = append(items, &model.Item{
|
|
ItemId: v.GetItemId(),
|
|
ItemNum: v.GetItemNum(),
|
|
})
|
|
}
|
|
|
|
p := PlayerMgrSington.GetPlayerBySnId(snid)
|
|
if p != nil {
|
|
BagMgrSingleton.AddItems(&model.AddItemParam{
|
|
Platform: p.Platform,
|
|
SnId: p.SnId,
|
|
Change: items,
|
|
GainWay: common.GainWayRoomCost,
|
|
Operator: "system",
|
|
Remark: "竞技场房间费用返还",
|
|
GameId: int64(s.gameId),
|
|
GameFreeId: int64(s.dbGameFree.GetId()),
|
|
RoomConfigId: roomConfig.GetId(),
|
|
})
|
|
} else {
|
|
BagMgrSingleton.AddItemsOffline(&model.AddItemParam{
|
|
Platform: s.platform.IdStr,
|
|
SnId: snid,
|
|
Change: items,
|
|
GainWay: common.GainWayRoomCost,
|
|
Operator: "system",
|
|
Remark: "竞技场房间费用返还",
|
|
GameId: int64(s.gameId),
|
|
GameFreeId: int64(s.dbGameFree.GetId()),
|
|
RoomConfigId: roomConfig.GetId(),
|
|
}, func(err error) {
|
|
logger.Logger.Errorf("竞技场房间费用返还失败, err: %v", err)
|
|
})
|
|
}
|
|
return false
|
|
}
|
|
|
|
func (spd *ScenePolicyData) NeedRoomCardCost(costType, playerNum int, roomConfig *webapi.RoomConfig) []*ItemCost {
|
|
var ret []*ItemCost
|
|
if costType == 2 {
|
|
// 房主
|
|
for _, v := range roomConfig.GetCost() {
|
|
ret = append(ret, &ItemCost{
|
|
ItemID: v.GetItemId(),
|
|
Count: v.GetItemNum(),
|
|
})
|
|
}
|
|
} else {
|
|
// AA
|
|
for _, v := range roomConfig.GetCost() {
|
|
n := int64(math.Ceil(float64(v.GetItemNum()) / float64(playerNum)))
|
|
ret = append(ret, &ItemCost{
|
|
ItemID: v.GetItemId(),
|
|
Count: n,
|
|
})
|
|
}
|
|
}
|
|
return ret
|
|
}
|