上传门票道具下发
This commit is contained in:
parent
852f9056d3
commit
ff5e45cea8
@ -20,7 +20,7 @@ func (this *apiComp) BuyCheck(session comm.IUserSession, req *pb.ArenaBuyReq) (c
|
||||
///获取自己的排行榜信息
|
||||
func (this *apiComp) Buy(session comm.IUserSession, req *pb.ArenaBuyReq) (code pb.ErrorCode, data proto.Message) {
|
||||
var (
|
||||
global *cfg.GameGlobalData
|
||||
// global *cfg.GameGlobalData
|
||||
info *pb.DBArenaUser
|
||||
challenge *cfg.GameArenaBuyChallengeData
|
||||
need []*cfg.Gameatn
|
||||
@ -33,12 +33,12 @@ func (this *apiComp) Buy(session comm.IUserSession, req *pb.ArenaBuyReq) (code p
|
||||
code = pb.ErrorCode_CacheReadError
|
||||
return
|
||||
}
|
||||
this.module.modelArena.recoverTicket(info)
|
||||
global = this.module.configure.GetGlobalConf()
|
||||
if info.Ticket+req.BuyNum > global.ArenaTicketMax {
|
||||
code = pb.ErrorCode_ArenaTicketBuyUp
|
||||
return
|
||||
}
|
||||
this.module.modelArena.recoverTicket(session, info)
|
||||
// global = this.module.configure.GetGlobalConf()
|
||||
// if info.Ticket+req.BuyNum > global.ArenaTicketMax {
|
||||
// code = pb.ErrorCode_ArenaTicketBuyUp
|
||||
// return
|
||||
// }
|
||||
need = make([]*cfg.Gameatn, 0)
|
||||
for i := int32(0); i < req.BuyNum; i++ {
|
||||
if challenge, err = this.module.configure.GetchallengeData(info.Buynum + i + 1); err != nil {
|
||||
@ -56,11 +56,14 @@ func (this *apiComp) Buy(session comm.IUserSession, req *pb.ArenaBuyReq) (code p
|
||||
return
|
||||
}
|
||||
info.Buynum += req.BuyNum
|
||||
info.Ticket += req.BuyNum
|
||||
if code = this.module.DispenseRes(session, []*cfg.Gameatn{{A: comm.ItemType, T: comm.ArenaTicket, N: req.BuyNum}}, true); code != pb.ErrorCode_Success {
|
||||
return
|
||||
}
|
||||
// info.Ticket += req.BuyNum
|
||||
if err = this.module.modelArena.updateArenaUserInfo(info); err != nil {
|
||||
code = pb.ErrorCode_DBError
|
||||
return
|
||||
}
|
||||
session.SendMsg(string(this.module.GetType()), "buy", &pb.MoonfantasyBuyResp{Issucc: true, BattleNum: info.Ticket})
|
||||
session.SendMsg(string(this.module.GetType()), "buy", &pb.MoonfantasyBuyResp{Issucc: true, BattleNum: info.Buynum})
|
||||
return
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package arena
|
||||
import (
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/pb"
|
||||
cfg "go_dreamfactory/sys/configure/structs"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
@ -50,13 +51,16 @@ func (this *apiComp) Challenge(session comm.IUserSession, req *pb.ArenaChallenge
|
||||
cd = pb.ErrorCode_DBError
|
||||
return
|
||||
}
|
||||
this.module.modelArena.recoverTicket(red)
|
||||
if red.Ticket > this.module.configure.GetGlobalConf().ArenaTicketCos {
|
||||
red.Ticket -= this.module.configure.GetGlobalConf().ArenaTicketCos
|
||||
} else {
|
||||
code = pb.ErrorCode_ArenaTicketNotEnough
|
||||
this.module.modelArena.recoverTicket(session, red)
|
||||
if cd = this.module.ConsumeRes(session, []*cfg.Gameatn{this.module.configure.GetGlobalConf().ArenaTicketCos}, true); cd != pb.ErrorCode_Success {
|
||||
return
|
||||
}
|
||||
// if red.Ticket > this.module.configure.GetGlobalConf().ArenaTicketCos {
|
||||
// red.Ticket -= this.module.configure.GetGlobalConf().ArenaTicketCos
|
||||
// } else {
|
||||
// code = pb.ErrorCode_ArenaTicketNotEnough
|
||||
// return
|
||||
// }
|
||||
|
||||
if red.Attack != nil {
|
||||
for i, v := range req.Battle.Format {
|
||||
|
@ -47,10 +47,10 @@ func (this *apiComp) Info(session comm.IUserSession, req *pb.ArenaInfoReq) (code
|
||||
return
|
||||
}
|
||||
info = &pb.DBArenaUser{
|
||||
Uid: session.GetUserId(),
|
||||
Name: user.Name,
|
||||
Integral: global.ArenaInitiaIntegral,
|
||||
Ticket: global.ArenaTicketMax,
|
||||
Uid: session.GetUserId(),
|
||||
Name: user.Name,
|
||||
Integral: global.ArenaInitiaIntegral,
|
||||
// Ticket: global.ArenaTicketMax,
|
||||
Streak: 0,
|
||||
Record: make([]*pb.DBArenaBattleRecord, 0),
|
||||
Lastrtickettime: 0,
|
||||
@ -65,7 +65,7 @@ func (this *apiComp) Info(session comm.IUserSession, req *pb.ArenaInfoReq) (code
|
||||
this.module.Errorln(err)
|
||||
}
|
||||
} else {
|
||||
this.module.modelArena.recoverTicket(info)
|
||||
this.module.modelArena.recoverTicket(session, info)
|
||||
if err = this.module.modelArena.updateArenaUserInfo(info); err != nil {
|
||||
code = pb.ErrorCode_DBError
|
||||
return
|
||||
|
@ -57,13 +57,16 @@ func (this *apiComp) Plot(session comm.IUserSession, req *pb.ArenaPlotReq) (code
|
||||
cd = pb.ErrorCode_DBError
|
||||
return
|
||||
}
|
||||
this.module.modelArena.recoverTicket(info)
|
||||
if info.Ticket > this.module.configure.GetGlobalConf().ArenaTicketCos {
|
||||
info.Ticket -= this.module.configure.GetGlobalConf().ArenaTicketCos
|
||||
} else {
|
||||
code = pb.ErrorCode_ArenaTicketNotEnough
|
||||
this.module.modelArena.recoverTicket(session, info)
|
||||
if cd = this.module.ConsumeRes(session, []*cfg.Gameatn{this.module.configure.GetGlobalConf().ArenaTicketCos}, true); cd != pb.ErrorCode_Success {
|
||||
return
|
||||
}
|
||||
// if info.Ticket > this.module.configure.GetGlobalConf().ArenaTicketCos {
|
||||
// info.Ticket -= this.module.configure.GetGlobalConf().ArenaTicketCos
|
||||
// } else {
|
||||
// code = pb.ErrorCode_ArenaTicketNotEnough
|
||||
// return
|
||||
// }
|
||||
if info.Npc[req.Pid] != nil {
|
||||
ndata := info.Npc[req.Pid]
|
||||
if !configure.Now().After(time.Unix(ndata.Cd, 0)) { //已经过了cd时间
|
||||
|
@ -111,10 +111,10 @@ func (this *modelArena) updateArenaUserInfo(info *pb.DBArenaUser) (err error) {
|
||||
return
|
||||
}
|
||||
this.Change(info.Uid, map[string]interface{}{
|
||||
"integral": info.Integral,
|
||||
"dan": dan,
|
||||
"rank": info.Rank,
|
||||
"ticket": info.Ticket,
|
||||
"integral": info.Integral,
|
||||
"dan": dan,
|
||||
"rank": info.Rank,
|
||||
// "ticket": info.Ticket,
|
||||
"buynum": info.Buynum,
|
||||
"lastrtickettime": info.Lastrtickettime,
|
||||
"attack": info.Attack,
|
||||
@ -365,20 +365,26 @@ func (this *modelArena) integralCompute(red, bule *pb.ArenaPlayer, iswin bool) {
|
||||
}
|
||||
}
|
||||
|
||||
func (this *modelArena) recoverTicket(info *pb.DBArenaUser) {
|
||||
func (this *modelArena) recoverTicket(session comm.IUserSession, info *pb.DBArenaUser) {
|
||||
var (
|
||||
duration time.Duration
|
||||
ticket int32
|
||||
ticketNum int32
|
||||
)
|
||||
global := this.module.configure.GetGlobalConf()
|
||||
if info.Ticket < global.ArenaTicketMax && info.Lastrtickettime > 0 {
|
||||
ticket = int32(this.module.ModuleItems.QueryItemAmount(info.Uid, comm.ArenaTicket))
|
||||
if ticket < global.ArenaTicketMax && info.Lastrtickettime > 0 {
|
||||
duration = configure.Now().Sub(time.Unix(info.Lastrtickettime, 0))
|
||||
ticketNum = int32(math.Floor(duration.Minutes() / float64(global.ArenaTicketRecoveryTime)))
|
||||
if ticketNum > 0 {
|
||||
info.Ticket += ticketNum
|
||||
if info.Ticket > global.ArenaTicketMax {
|
||||
info.Ticket = global.ArenaTicketMax
|
||||
if ticketNum+ticket > global.ArenaTicketMax {
|
||||
ticketNum = global.ArenaTicketMax - ticket
|
||||
}
|
||||
this.module.DispenseRes(session, []*cfg.Gameatn{&cfg.Gameatn{A: comm.ItemType, T: comm.ArenaTicket, N: ticketNum}}, true)
|
||||
// info.Ticket += ticketNum
|
||||
// if info.Ticket > global.ArenaTicketMax {
|
||||
// info.Ticket = global.ArenaTicketMax
|
||||
// }
|
||||
info.Lastrtickettime = time.Unix(info.Lastrtickettime, 0).Add(time.Duration(ticketNum) * time.Minute).Unix()
|
||||
}
|
||||
}
|
||||
@ -394,12 +400,13 @@ func (this *modelArena) reddot(session comm.IUserSession) bool {
|
||||
}
|
||||
if err == mgo.MongodbNil {
|
||||
global := this.module.configure.GetGlobalConf()
|
||||
if global.ArenaTicketMax >= global.ArenaTicketCos {
|
||||
if global.ArenaTicketMax >= global.ArenaTicketCos.N {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
if info.Ticket > this.module.configure.GetGlobalConf().ArenaTicketCos {
|
||||
ticket := int32(this.module.ModuleItems.QueryItemAmount(info.Uid, comm.ArenaTicket))
|
||||
if ticket > this.module.configure.GetGlobalConf().ArenaTicketCos.N {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
|
@ -16,20 +16,20 @@ func (this *apiComp) BattleCheck(session comm.IUserSession, req *pb.MoonfantasyB
|
||||
///挑战怪物请求
|
||||
func (this *apiComp) Battle(session comm.IUserSession, req *pb.MoonfantasyBattleReq) (code pb.ErrorCode, data proto.Message) {
|
||||
var (
|
||||
boss *cfg.GameDreamlandBoosData
|
||||
umfantasy *pb.DBUserMFantasy
|
||||
mdata *pb.DBMoonFantasy
|
||||
record *pb.DBBattleRecord
|
||||
cd pb.ErrorCode
|
||||
isjoin bool
|
||||
err error
|
||||
boss *cfg.GameDreamlandBoosData
|
||||
// umfantasy *pb.DBUserMFantasy
|
||||
mdata *pb.DBMoonFantasy
|
||||
record *pb.DBBattleRecord
|
||||
cd pb.ErrorCode
|
||||
isjoin bool
|
||||
err error
|
||||
)
|
||||
|
||||
defer func() {
|
||||
if cd == pb.ErrorCode_Success {
|
||||
this.module.modelUserMF.Change(session.GetUserId(), map[string]interface{}{
|
||||
"ticket": umfantasy.Ticket,
|
||||
})
|
||||
// this.module.modelUserMF.Change(session.GetUserId(), map[string]interface{}{
|
||||
// "ticket": umfantasy.Ticket,
|
||||
// })
|
||||
this.module.modelDream.ChangeList("", mdata.Id, map[string]interface{}{
|
||||
"record": mdata.Record,
|
||||
})
|
||||
@ -78,17 +78,20 @@ func (this *apiComp) Battle(session comm.IUserSession, req *pb.MoonfantasyBattle
|
||||
cd = pb.ErrorCode_MoonfantasyNoJoin
|
||||
return
|
||||
}
|
||||
if umfantasy, err = this.module.modelUserMF.queryUsermfantasy(session.GetUserId()); err != nil {
|
||||
cd = pb.ErrorCode_CacheReadError
|
||||
}
|
||||
if umfantasy.Ticket < this.module.configure.GetGlobalConf().DreamlandCos {
|
||||
cd = pb.ErrorCode_MoonfantasyNotEnoughbattles
|
||||
}
|
||||
umfantasy.Ticket -= this.module.configure.GetGlobalConf().DreamlandCos
|
||||
if boss, err = this.module.configure.GetMonsterById(mdata.Monster); err != nil {
|
||||
cd = pb.ErrorCode_ConfigNoFound
|
||||
// if umfantasy, err = this.module.modelUserMF.queryUsermfantasy(session.GetUserId()); err != nil {
|
||||
// cd = pb.ErrorCode_CacheReadError
|
||||
// }
|
||||
if cd = this.module.ConsumeRes(session, []*cfg.Gameatn{this.module.configure.GetGlobalConf().DreamlandCos}, true); cd != pb.ErrorCode_Success {
|
||||
return
|
||||
}
|
||||
// if umfantasy.Ticket < this.module.configure.GetGlobalConf().DreamlandCos {
|
||||
// cd = pb.ErrorCode_MoonfantasyNotEnoughbattles
|
||||
// }
|
||||
// umfantasy.Ticket -= this.module.configure.GetGlobalConf().DreamlandCos
|
||||
// if boss, err = this.module.configure.GetMonsterById(mdata.Monster); err != nil {
|
||||
// cd = pb.ErrorCode_ConfigNoFound
|
||||
// return
|
||||
// }
|
||||
|
||||
if len(mdata.Join) >= int(mdata.Numup) {
|
||||
cd = pb.ErrorCode_MoonfantasyJoinUp
|
||||
|
@ -32,7 +32,7 @@ func (this *apiComp) Buy(session comm.IUserSession, req *pb.MoonfantasyBuyReq) (
|
||||
code = pb.ErrorCode_CacheReadError
|
||||
return
|
||||
}
|
||||
this.module.modelUserMF.recoverTicket(info)
|
||||
this.module.modelUserMF.recoverTicket(session,info)
|
||||
need = make([]*cfg.Gameatn, 0)
|
||||
for i := int32(0); i < req.BuyNum; i++ {
|
||||
if challengeD, err = this.module.configure.GetchallengeData(info.BuyNum + i + 1); err != nil {
|
||||
@ -50,11 +50,14 @@ func (this *apiComp) Buy(session comm.IUserSession, req *pb.MoonfantasyBuyReq) (
|
||||
return
|
||||
}
|
||||
info.BuyNum += req.BuyNum
|
||||
info.Ticket += req.BuyNum
|
||||
// info.Ticket += req.BuyNum
|
||||
if code = this.module.DispenseRes(session, []*cfg.Gameatn{{A: comm.ItemType, T: comm.MoonFantasyTicket, N: req.BuyNum}}, true); code != pb.ErrorCode_Success {
|
||||
return
|
||||
}
|
||||
this.module.modelUserMF.Change(session.GetUserId(), map[string]interface{}{
|
||||
"buyNum": info.BuyNum,
|
||||
"ticket": info.Ticket,
|
||||
// "ticket": info.Ticket,
|
||||
})
|
||||
session.SendMsg(string(this.module.GetType()), "buy", &pb.MoonfantasyBuyResp{Issucc: true, BattleNum: info.Ticket})
|
||||
session.SendMsg(string(this.module.GetType()), "buy", &pb.MoonfantasyBuyResp{Issucc: true, BattleNum: req.BuyNum})
|
||||
return
|
||||
}
|
||||
|
@ -25,14 +25,14 @@ func (this *apiComp) Getlist(session comm.IUserSession, req *pb.MoonfantasyGetLi
|
||||
code = pb.ErrorCode_CacheReadError
|
||||
return
|
||||
}
|
||||
this.module.modelUserMF.recoverTicket(info)
|
||||
this.module.modelUserMF.recoverTicket(session, info)
|
||||
if err = this.module.modelUserMF.updateUserInfo(info); err != nil {
|
||||
code = pb.ErrorCode_DBError
|
||||
return
|
||||
}
|
||||
mfantasys, err = this.module.modelDream.querymfantasys(session.GetUserId())
|
||||
session.SendMsg(string(this.module.GetType()), "getlist", &pb.MoonfantasyGetListResp{
|
||||
BattleNum: info.Ticket,
|
||||
// BattleNum: info.Ticket,
|
||||
BuyNum: info.BuyNum,
|
||||
Dfantasys: mfantasys,
|
||||
})
|
||||
|
@ -100,7 +100,7 @@ func (this *modelDreamComp) trigger(session comm.IUserSession) {
|
||||
if umfantasy, err = this.module.modelUserMF.queryUsermfantasy(session.GetUserId()); err != nil {
|
||||
return
|
||||
}
|
||||
this.module.modelUserMF.recoverTicket(umfantasy)
|
||||
this.module.modelUserMF.recoverTicket(session, umfantasy)
|
||||
if umfantasy.TriggerNum >= globalconf.DreamlandTriggernum {
|
||||
return
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
"go_dreamfactory/modules"
|
||||
"go_dreamfactory/pb"
|
||||
"go_dreamfactory/sys/configure"
|
||||
cfg "go_dreamfactory/sys/configure/structs"
|
||||
"math"
|
||||
"time"
|
||||
|
||||
@ -42,12 +43,12 @@ func (this *modelUserMF) queryUsermfantasy(uId string) (info *pb.DBUserMFantasy,
|
||||
if err == mgo.MongodbNil {
|
||||
global := this.module.configure.GetGlobalConf()
|
||||
info = &pb.DBUserMFantasy{
|
||||
Id: primitive.NewObjectID().Hex(),
|
||||
Uid: uId,
|
||||
TriggerNum: 0,
|
||||
LastTrigger: 0,
|
||||
BuyNum: global.DreamlandFightnum,
|
||||
Ticket: global.DreamlandFightnum,
|
||||
Id: primitive.NewObjectID().Hex(),
|
||||
Uid: uId,
|
||||
TriggerNum: 0,
|
||||
LastTrigger: 0,
|
||||
BuyNum: global.DreamlandFightnum,
|
||||
// Ticket: global.DreamlandFightnum,
|
||||
Lastrtickettime: configure.Now().Unix(),
|
||||
}
|
||||
if err = this.Add(uId, info); err != nil {
|
||||
@ -62,8 +63,8 @@ func (this *modelUserMF) queryUsermfantasy(uId string) (info *pb.DBUserMFantasy,
|
||||
///保存用户竞技场信息
|
||||
func (this *modelUserMF) updateUserInfo(info *pb.DBUserMFantasy) (err error) {
|
||||
this.Change(info.Uid, map[string]interface{}{
|
||||
"triggerNum": info.TriggerNum,
|
||||
"ticket": info.Ticket,
|
||||
"triggerNum": info.TriggerNum,
|
||||
// "ticket": info.Ticket,
|
||||
"buyNum": info.BuyNum,
|
||||
"lastTrigger": info.LastTrigger,
|
||||
"lastrtickettime": info.Lastrtickettime,
|
||||
@ -71,9 +72,10 @@ func (this *modelUserMF) updateUserInfo(info *pb.DBUserMFantasy) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (this *modelUserMF) recoverTicket(info *pb.DBUserMFantasy) {
|
||||
func (this *modelUserMF) recoverTicket(session comm.IUserSession, info *pb.DBUserMFantasy) {
|
||||
var (
|
||||
duration time.Duration
|
||||
ticket int32
|
||||
ticketNum int32
|
||||
)
|
||||
if time.Unix(info.LastTrigger, 0).Day() < configure.Now().Day() {
|
||||
@ -82,14 +84,15 @@ func (this *modelUserMF) recoverTicket(info *pb.DBUserMFantasy) {
|
||||
info.BuyNum = 0
|
||||
}
|
||||
global := this.module.configure.GetGlobalConf()
|
||||
if info.Ticket < global.DreamlandFightnum && info.Lastrtickettime > 0 {
|
||||
ticket = int32(this.module.ModuleItems.QueryItemAmount(info.Uid, comm.MoonFantasyTicket))
|
||||
if ticket < global.DreamlandFightnum && info.Lastrtickettime > 0 {
|
||||
duration = configure.Now().Sub(time.Unix(info.Lastrtickettime, 0))
|
||||
ticketNum = int32(math.Floor(duration.Minutes() / float64(global.ArenaTicketRecoveryTime)))
|
||||
if ticketNum > 0 {
|
||||
info.Ticket += ticketNum
|
||||
if info.Ticket > global.ArenaTicketMax {
|
||||
info.Ticket = global.ArenaTicketMax
|
||||
if ticketNum+ticket > global.ArenaTicketMax {
|
||||
ticketNum = global.ArenaTicketMax - ticket
|
||||
}
|
||||
this.module.DispenseRes(session, []*cfg.Gameatn{&cfg.Gameatn{A: comm.ItemType, T: comm.MoonFantasyTicket, N: ticketNum}}, true)
|
||||
info.Lastrtickettime = time.Unix(info.Lastrtickettime, 0).Add(time.Duration(ticketNum) * time.Minute).Unix()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user