匹配校验卡数量
This commit is contained in:
parent
c8c9fec17d
commit
90d05da98f
@ -3,6 +3,7 @@ package entertainment
|
|||||||
import (
|
import (
|
||||||
"go_dreamfactory/comm"
|
"go_dreamfactory/comm"
|
||||||
"go_dreamfactory/pb"
|
"go_dreamfactory/pb"
|
||||||
|
cfg "go_dreamfactory/sys/configure/structs"
|
||||||
)
|
)
|
||||||
|
|
||||||
//参数校验
|
//参数校验
|
||||||
@ -21,11 +22,41 @@ func (this *apiComp) Match(session comm.IUserSession, req *pb.EntertainMatchReq)
|
|||||||
var (
|
var (
|
||||||
user *pb.DBUser
|
user *pb.DBUser
|
||||||
err error
|
err error
|
||||||
|
conf *cfg.GameConsumeHeroData
|
||||||
)
|
)
|
||||||
user, err = this.module.ModuleUser.GetUser(session.GetUserId())
|
user, err = this.module.ModuleUser.GetUser(session.GetUserId())
|
||||||
if err != nil {
|
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{
|
this.module.match.MatchReq(&pb.DBXXLMatch{
|
||||||
Userinfo: &pb.BaseUserInfo{
|
Userinfo: &pb.BaseUserInfo{
|
||||||
Uid: user.Uid,
|
Uid: user.Uid,
|
||||||
|
@ -149,3 +149,19 @@ func (this *configureComp) GetGameConsumeintegralReward(key int32) (conf *cfg.Ga
|
|||||||
err = comm.NewNotFoundConfErr(moduleName, game_integral, key)
|
err = comm.NewNotFoundConfErr(moduleName, game_integral, key)
|
||||||
return
|
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
|
||||||
|
}
|
||||||
|
@ -60,6 +60,10 @@ func (this *modelComp) getEntertainmList(uid string) (result *pb.DBXXLData, err
|
|||||||
result.Reward = make(map[int32]int32)
|
result.Reward = make(map[int32]int32)
|
||||||
result.Card = make(map[string]int32, 0)
|
result.Card = make(map[string]int32, 0)
|
||||||
}
|
}
|
||||||
|
// 初始化默认获得类型为1的卡片
|
||||||
|
for _, v := range this.module.configure.GetInitGameConsumeHero() {
|
||||||
|
result.Card[v] = 1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
err = nil
|
err = nil
|
||||||
return result, err
|
return result, err
|
||||||
|
@ -84,7 +84,7 @@ func (this *Entertainment) AddXxlCard(session comm.IUserSession, cards map[strin
|
|||||||
})
|
})
|
||||||
|
|
||||||
if bPush {
|
if bPush {
|
||||||
session.SendMsg(string(this.GetType()), "titlelist", &pb.EntertainChangePush{
|
session.SendMsg(string(this.GetType()), "change", &pb.EntertainChangePush{
|
||||||
Card: result.Card,
|
Card: result.Card,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -478,11 +478,12 @@ func (this *Room) GameOver() (errdata *pb.ErrorData) {
|
|||||||
winindex int32
|
winindex int32
|
||||||
bReward bool
|
bReward bool
|
||||||
res []*cfg.Gameatn
|
res []*cfg.Gameatn
|
||||||
|
winner string
|
||||||
|
lostPlayer *pb.PlayerData // 输的玩家
|
||||||
)
|
)
|
||||||
if this.operatetimer != nil {
|
if this.operatetimer != nil {
|
||||||
timewheel.Remove(this.operatetimer)
|
timewheel.Remove(this.operatetimer)
|
||||||
}
|
}
|
||||||
var winner string
|
|
||||||
winner = this.player1.Userinfo.Uid
|
winner = this.player1.Userinfo.Uid
|
||||||
bReward = true
|
bReward = true
|
||||||
if this.player1.Score < this.player2.Score {
|
if this.player1.Score < this.player2.Score {
|
||||||
@ -492,6 +493,7 @@ func (this *Room) GameOver() (errdata *pb.ErrorData) {
|
|||||||
bReward = false
|
bReward = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if bReward { // 发奖
|
if bReward { // 发奖
|
||||||
if user, err := this.module.ModuleUser.GetUser(winner); err == nil {
|
if user, err := this.module.ModuleUser.GetUser(winner); err == nil {
|
||||||
if conf, err := this.module.configure.GetGameConsumeintegral(user.Consumeexp); 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{
|
this.module.SendMsgSyncToSession(string(this.module.GetType()), "gameover", &pb.EntertainGameOverPush{
|
||||||
User1: this.player1,
|
User1: this.player1,
|
||||||
User2: this.player2,
|
User2: this.player2,
|
||||||
|
Loading…
Reference in New Issue
Block a user