252 lines
5.3 KiB
Go
252 lines
5.3 KiB
Go
package clawdoll
|
|
|
|
import (
|
|
"mongo.games.com/game/common"
|
|
"mongo.games.com/game/gamesrv/base"
|
|
"mongo.games.com/game/model"
|
|
"mongo.games.com/game/srvdata"
|
|
"mongo.games.com/goserver/core/logger"
|
|
|
|
"mongo.games.com/game/proto"
|
|
"mongo.games.com/game/protocol/clawdoll"
|
|
)
|
|
|
|
type PlayerEx struct {
|
|
*base.Player //玩家信息
|
|
|
|
clawDollState int32 // 抓娃娃状态
|
|
IsWin bool // 是否抓到娃娃
|
|
gainCoin int64 // 本局赢的金币
|
|
taxCoin int64 //本局税收
|
|
}
|
|
|
|
func (this *PlayerEx) Clear(baseScore int32) {
|
|
this.UnmarkFlag(base.PlayerState_WaitNext)
|
|
this.UnmarkFlag(base.PlayerState_GameBreak)
|
|
this.MarkFlag(base.PlayerState_Ready)
|
|
|
|
this.gainCoin = 0
|
|
this.IsWin = false
|
|
}
|
|
|
|
func (this *PlayerEx) CanOp(sceneEx *SceneEx) bool {
|
|
if !this.IsGameing() {
|
|
logger.Logger.Trace("(this *PlayerEx) CanOp return false ", this.SnId)
|
|
return false
|
|
}
|
|
return true
|
|
}
|
|
|
|
// 能否投币
|
|
func (this *PlayerEx) CanPayCoin() bool {
|
|
|
|
itemID := int32(common.ItemIDClawdoll)
|
|
itemData := srvdata.GameItemMgr.Get(this.Platform, itemID)
|
|
if itemData == nil {
|
|
return false
|
|
}
|
|
|
|
s := this.GetScene()
|
|
if s == nil {
|
|
logger.Logger.Warn("CostPlayCoin p.scene == nil")
|
|
return false
|
|
}
|
|
|
|
machineId := s.GetDBGameFree().GetId() % 6080000
|
|
machineInfo := s.GetMachineServerInfo(machineId, this.Platform)
|
|
if machineInfo == nil {
|
|
return false
|
|
}
|
|
|
|
itemCount := this.GetItemCount(itemID)
|
|
if itemCount < int64(machineInfo.CostItemNum) {
|
|
return false
|
|
}
|
|
|
|
num, ok := this.Items[itemID]
|
|
if !ok || num < int64(machineInfo.CostItemNum) {
|
|
return false
|
|
}
|
|
|
|
return true
|
|
}
|
|
|
|
// 投币消耗
|
|
func (this *PlayerEx) CostPlayCoin() bool {
|
|
|
|
if !this.CanPayCoin() {
|
|
return false
|
|
}
|
|
|
|
s := this.GetScene()
|
|
if s == nil {
|
|
logger.Logger.Warn("CostPlayCoin p.scene == nil")
|
|
return false
|
|
}
|
|
|
|
sceneEx, ok := s.ExtraData.(*SceneEx)
|
|
if !ok {
|
|
return false
|
|
}
|
|
|
|
machineId := s.GetDBGameFree().GetId() % 6080000
|
|
machineInfo := s.GetMachineServerInfo(machineId, this.Platform)
|
|
if machineInfo == nil {
|
|
return false
|
|
}
|
|
|
|
var items []*model.Item
|
|
itemData := srvdata.GameItemMgr.Get(this.Platform, common.ItemIDClawdoll)
|
|
if itemData != nil {
|
|
items = append(items, &model.Item{
|
|
ItemId: common.ItemIDClawdoll,
|
|
ItemNum: int64(-machineInfo.CostItemNum),
|
|
})
|
|
}
|
|
|
|
this.AddItems(&model.AddItemParam{
|
|
Platform: this.Platform,
|
|
SnId: this.SnId,
|
|
Change: items,
|
|
GainWay: common.GainWayClawdollCostItem,
|
|
Operator: "system",
|
|
Remark: "娃娃机上分扣除道具",
|
|
GameId: int64(sceneEx.GameId),
|
|
GameFreeId: int64(sceneEx.GetGameFreeId()),
|
|
})
|
|
|
|
logger.Logger.Tracef("Clawdoll (*PlayerEx) CostPlayCoin, items = %v", items)
|
|
return true
|
|
}
|
|
|
|
// 抓取到娃娃获得娃娃
|
|
func (this *PlayerEx) CatchCardClawdoll() bool {
|
|
|
|
s := this.GetScene()
|
|
if s == nil {
|
|
logger.Logger.Warn("CatchCardClawdoll p.scene == nil")
|
|
return false
|
|
}
|
|
|
|
machineId := s.GetDBGameFree().GetId() % 6080000
|
|
machineInfo := s.GetMachineServerInfo(machineId, this.Platform)
|
|
if machineInfo == nil {
|
|
return false
|
|
}
|
|
|
|
sceneEx, ok := s.ExtraData.(*SceneEx)
|
|
if !ok {
|
|
return false
|
|
}
|
|
|
|
var items []*model.Item
|
|
itemData := srvdata.GameItemMgr.Get(this.Platform, machineInfo.ItemId)
|
|
if itemData != nil {
|
|
items = append(items, &model.Item{
|
|
ItemId: machineInfo.ItemId,
|
|
ItemNum: int64(machineInfo.ItemNum),
|
|
})
|
|
}
|
|
|
|
this.AddItems(&model.AddItemParam{
|
|
Platform: this.Platform,
|
|
SnId: this.SnId,
|
|
Change: items,
|
|
GainWay: common.GainWayClawdollCatch,
|
|
Operator: "system",
|
|
Remark: "娃娃机抓取到娃娃获得娃娃卡",
|
|
GameId: int64(sceneEx.GameId),
|
|
GameFreeId: int64(sceneEx.GetGameFreeId()),
|
|
})
|
|
|
|
logger.Logger.Tracef("Clawdoll (*PlayerEx) CatchCardClawdoll, items = %v", items)
|
|
return true
|
|
}
|
|
|
|
// 能否移动
|
|
func (this *PlayerEx) CanMove() bool {
|
|
|
|
s := this.GetScene()
|
|
if sceneEx, ok := s.ExtraData.(*SceneEx); ok {
|
|
if !sceneEx.Gaming {
|
|
return false
|
|
}
|
|
}
|
|
|
|
return true
|
|
}
|
|
|
|
// 能否下抓
|
|
func (this *PlayerEx) CanGrab() bool {
|
|
|
|
s := this.GetScene()
|
|
if sceneEx, ok := s.ExtraData.(*SceneEx); ok {
|
|
if !sceneEx.Gaming {
|
|
return false
|
|
}
|
|
}
|
|
|
|
return true
|
|
}
|
|
|
|
// 游戏新一局 设置数据
|
|
func (this *PlayerEx) ReStartGame() {
|
|
|
|
this.UnmarkFlag(base.PlayerState_WaitNext)
|
|
this.UnmarkFlag(base.PlayerState_GameBreak)
|
|
this.MarkFlag(base.PlayerState_Ready)
|
|
|
|
this.gainCoin = 0
|
|
this.IsWin = false
|
|
}
|
|
|
|
// 能否退出游戏
|
|
func (this *PlayerEx) CanLeaveScene(sceneState int) bool {
|
|
|
|
return true
|
|
}
|
|
|
|
// 获取状态
|
|
func (this *PlayerEx) GetClawState() int32 {
|
|
return this.clawDollState
|
|
}
|
|
|
|
// 设置状态
|
|
func (this *PlayerEx) SetClawState(state int32) {
|
|
this.clawDollState = state
|
|
}
|
|
|
|
func (this *PlayerEx) GetItemCount(itemID int32) int64 {
|
|
itemData := srvdata.GameItemMgr.Get(this.Platform, itemID)
|
|
if itemData != nil {
|
|
v, ok := this.Items[itemID]
|
|
if ok {
|
|
return v
|
|
} else {
|
|
return 0
|
|
}
|
|
}
|
|
return 0
|
|
}
|
|
|
|
func (this *PlayerEx) SendPlayerGameBilled(RoundId int32) {
|
|
if this != nil {
|
|
|
|
result := 0
|
|
if this.IsWin {
|
|
result = 1
|
|
}
|
|
pack := &clawdoll.SCCLAWDOLLRoundGameBilled{
|
|
RoundId: proto.Int32(RoundId),
|
|
ClowResult: proto.Int32(int32(result)),
|
|
Award: proto.Int64(this.gainCoin),
|
|
Balance: proto.Int64(this.Coin),
|
|
}
|
|
|
|
logger.Logger.Trace("Clawdoor -StateWaitPayCoin is pack: ", pack)
|
|
proto.SetDefaults(pack)
|
|
|
|
this.SendToClient(int(clawdoll.CLAWDOLLPacketID_PACKET_SC_GAMEBILLED), pack)
|
|
}
|
|
}
|