匹配校验卡数量

This commit is contained in:
meixiongfeng 2023-10-27 19:24:20 +08:00
parent c8c9fec17d
commit 90d05da98f
5 changed files with 80 additions and 7 deletions

View File

@ -3,6 +3,7 @@ package entertainment
import (
"go_dreamfactory/comm"
"go_dreamfactory/pb"
cfg "go_dreamfactory/sys/configure/structs"
)
//参数校验
@ -21,11 +22,41 @@ func (this *apiComp) Match(session comm.IUserSession, req *pb.EntertainMatchReq)
var (
user *pb.DBUser
err error
conf *cfg.GameConsumeHeroData
)
user, err = this.module.ModuleUser.GetUser(session.GetUserId())
if err != nil {
return
}
if conf, err = this.module.configure.GetGameConsumeHero(req.Idcard); err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_ConfigNoFound,
Title: pb.ErrorCode_ConfigNoFound.ToString(),
Message: err.Error(),
}
return
}
if conf.Type != 1 { // 校验数量够不够
if list, err := this.module.model.getEntertainmList(session.GetUserId()); err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_DBError,
Title: pb.ErrorCode_DBError.ToString(),
Message: err.Error(),
}
return
} else {
if list.Card[req.Idcard] <= 0 { // 需要购买
if errdata = this.module.ConsumeRes(session, conf.Consume, true); errdata != nil {
return
}
list.Card[req.Idcard] += 1
this.module.model.modifyEntertainmList(session.GetUserId(), map[string]interface{}{
"card": list.Card,
})
}
}
}
this.module.match.MatchReq(&pb.DBXXLMatch{
Userinfo: &pb.BaseUserInfo{
Uid: user.Uid,

View File

@ -149,3 +149,19 @@ func (this *configureComp) GetGameConsumeintegralReward(key int32) (conf *cfg.Ga
err = comm.NewNotFoundConfErr(moduleName, game_integral, key)
return
}
func (this *configureComp) GetInitGameConsumeHero() (cardid []string) {
if v, err := this.GetConfigure(game_consumehero); err == nil {
if configure, ok := v.(*cfg.GameConsumeHero); ok {
for _, v := range configure.GetDataList() {
if v.Type == 1 {
cardid = append(cardid, v.Key)
}
}
}
}
return
}

View File

@ -60,6 +60,10 @@ func (this *modelComp) getEntertainmList(uid string) (result *pb.DBXXLData, err
result.Reward = make(map[int32]int32)
result.Card = make(map[string]int32, 0)
}
// 初始化默认获得类型为1的卡片
for _, v := range this.module.configure.GetInitGameConsumeHero() {
result.Card[v] = 1
}
}
err = nil
return result, err

View File

@ -84,7 +84,7 @@ func (this *Entertainment) AddXxlCard(session comm.IUserSession, cards map[strin
})
if bPush {
session.SendMsg(string(this.GetType()), "titlelist", &pb.EntertainChangePush{
session.SendMsg(string(this.GetType()), "change", &pb.EntertainChangePush{
Card: result.Card,
})
}

View File

@ -474,15 +474,16 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr
// 游戏结束
func (this *Room) GameOver() (errdata *pb.ErrorData) {
var (
atno []*pb.UserAtno
winindex int32
bReward bool
res []*cfg.Gameatn
atno []*pb.UserAtno
winindex int32
bReward bool
res []*cfg.Gameatn
winner string
lostPlayer *pb.PlayerData // 输的玩家
)
if this.operatetimer != nil {
timewheel.Remove(this.operatetimer)
}
var winner string
winner = this.player1.Userinfo.Uid
bReward = true
if this.player1.Score < this.player2.Score {
@ -492,6 +493,7 @@ func (this *Room) GameOver() (errdata *pb.ErrorData) {
bReward = false
}
}
if bReward { // 发奖
if user, err := this.module.ModuleUser.GetUser(winner); err == nil {
if conf, err := this.module.configure.GetGameConsumeintegral(user.Consumeexp); err == nil {
@ -505,6 +507,26 @@ func (this *Room) GameOver() (errdata *pb.ErrorData) {
}
}
// 失败的一方扣除卡
if this.player1.Userinfo.Uid != winner {
lostPlayer = this.player1
} else {
lostPlayer = this.player2
}
// 失败卡类型
if conf, err := this.module.configure.GetGameConsumeHero(lostPlayer.Cardid); err == nil && lostPlayer.Userinfo.Uid != "999" {
if conf.Type != 1 { //卡片类型不为1
if list, err := this.module.model.getEntertainmList(lostPlayer.Userinfo.Uid); err == nil {
if list.Card[lostPlayer.Cardid] > 1 {
list.Card[lostPlayer.Cardid] -= 1
this.module.model.modifyEntertainmList(lostPlayer.Userinfo.Uid, map[string]interface{}{
"card": list.Card,
})
}
}
}
}
this.module.SendMsgSyncToSession(string(this.module.GetType()), "gameover", &pb.EntertainGameOverPush{
User1: this.player1,
User2: this.player2,