123 lines
3.0 KiB
Go
123 lines
3.0 KiB
Go
package island
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
)
|
|
|
|
// 参数校验
|
|
func (this *apiComp) BuyCheck(session comm.IUserSession, req *pb.IsLandBuyReq) (errdata *pb.ErrorData) {
|
|
|
|
return
|
|
}
|
|
|
|
// /获取自己的排行榜信息
|
|
func (this *apiComp) Buy(session comm.IUserSession, req *pb.IsLandBuyReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
conf *cfg.GameHeroData
|
|
coinconf *cfg.GamePuggsyRecruitData
|
|
info *pb.DBIsland
|
|
heros []*pb.DBHero
|
|
hero *pb.DBHero
|
|
buynum int32
|
|
ok bool
|
|
err error
|
|
)
|
|
if errdata = this.BuyCheck(session, req); errdata != nil {
|
|
return
|
|
}
|
|
|
|
if conf, err = this.module.ModuleTools.GetHeroConfig(req.Cids); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
if coinconf, err = this.module.configure.getGamePuggsyRecruit(conf.Star); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
if info, err = this.module.model.getmodel(session.GetUserId()); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
if errdata = this.module.ConsumeRes(session, coinconf.Need, true); errdata != nil {
|
|
return
|
|
}
|
|
|
|
if buynum, ok = info.Heroshop[req.Cids]; ok && buynum > 0 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Message: "Purchased !",
|
|
}
|
|
return
|
|
}
|
|
info.Heroshop[req.Cids] = 1
|
|
if heros, err = this.module.modelhero.getHeroList(session.GetUserId()); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
for _, v := range heros {
|
|
if v.HeroID == req.Cids {
|
|
hero = v
|
|
if hero.Star <= 6 {
|
|
hero.Star++
|
|
hero.Lv = hero.Star * 10
|
|
} else {
|
|
hero.JuexingLv++
|
|
}
|
|
if hero.JuexingLv > 6 { //已满级不能购买
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Message: "max lv!",
|
|
}
|
|
return
|
|
}
|
|
}
|
|
}
|
|
if hero == nil {
|
|
hero = &pb.DBHero{
|
|
Id: primitive.NewObjectID().Hex(),
|
|
Uid: session.GetUserId(),
|
|
HeroID: conf.Hid,
|
|
Star: conf.Star,
|
|
Lv: conf.Star * 10,
|
|
Property: make(map[string]int32),
|
|
AddProperty: make(map[string]int32),
|
|
JuexProperty: make(map[string]int32),
|
|
}
|
|
this.module.hero.GetVirtualHero(hero, hero.Lv)
|
|
this.module.modelhero.addheros(session.GetUserId(), hero)
|
|
} else {
|
|
this.module.hero.GetVirtualHero(hero, hero.Lv)
|
|
this.module.modelhero.updateHeroProperty(session.GetUserId(), hero)
|
|
}
|
|
|
|
this.module.model.Change(session.GetUserId(), map[string]interface{}{
|
|
"heroshop": info.Heroshop,
|
|
})
|
|
session.SendMsg(string(this.module.GetType()), "buy", &pb.IsLandBuyResp{Hero: hero})
|
|
|
|
go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
|
|
this.module.WriteUserLog(session.GetUserId(), comm.GMResDelType, "IsLandBuyReq", coinconf.Need)
|
|
})
|
|
return
|
|
}
|