封装金币操作,用于兼容俱乐部币等其它资源

This commit is contained in:
liuxiaobo 2025-06-08 00:14:42 +08:00
parent 890a893344
commit bea141f772
3 changed files with 21 additions and 0 deletions

View File

@ -10,6 +10,8 @@ type ColorPlayer struct {
*user.UserResources *user.UserResources
gateTopicName string gateTopicName string
roomId int roomId int
costGold int64 // 本局消耗金币
} }
func NewColorPlayer(gateTopicName string, roomId int, u *user.User, res *user.UserResources) *ColorPlayer { func NewColorPlayer(gateTopicName string, roomId int, u *user.User, res *user.UserResources) *ColorPlayer {

View File

@ -31,3 +31,17 @@ func (rm *ColorRoom) OnInit() {
}) })
return return
} }
// 当前拥有金币
func (rm *ColorRoom) GetGold(user *ColorPlayer) int64 {
return user.Gold - user.costGold
}
// 加减金币
func (rm *ColorRoom) AddGold(user *ColorPlayer, add int64) (int64, bool) {
if user.Gold-user.costGold+add < 0 {
return user.Gold - user.costGold, false
}
user.costGold += add
return user.Gold - user.costGold, false
}

View File

@ -5,6 +5,11 @@ import (
"github.com/fox/fox/ipb" "github.com/fox/fox/ipb"
) )
func (rm *ColorRoom) checkEnterRoom(user *ColorPlayer, iMsg *ipb.InternalMsg, req *pb.C2SMatchRoom) {
return
}
func (rm *ColorRoom) OnEnterRoom(user *ColorPlayer, iMsg *ipb.InternalMsg, req *pb.C2SMatchRoom) { func (rm *ColorRoom) OnEnterRoom(user *ColorPlayer, iMsg *ipb.InternalMsg, req *pb.C2SMatchRoom) {
return return