坐骑资源分发
This commit is contained in:
parent
7d9f3f1e2a
commit
d581c883d8
@ -106,6 +106,7 @@ const (
|
|||||||
ModulePuzzle core.M_Modules = "uigame" //小游戏
|
ModulePuzzle core.M_Modules = "uigame" //小游戏
|
||||||
ModuleRobot core.M_Modules = "robot" //压测机器人
|
ModuleRobot core.M_Modules = "robot" //压测机器人
|
||||||
ModuleBattleRecord core.M_Modules = "battlerecord" //战斗记录
|
ModuleBattleRecord core.M_Modules = "battlerecord" //战斗记录
|
||||||
|
ModuleDragon core.M_Modules = "dragon" //坐骑
|
||||||
)
|
)
|
||||||
|
|
||||||
// 数据表名定义处
|
// 数据表名定义处
|
||||||
|
@ -649,6 +649,8 @@ type (
|
|||||||
}
|
}
|
||||||
IDragon interface {
|
IDragon interface {
|
||||||
//获取玩家坐骑列表
|
//获取玩家坐骑列表
|
||||||
GetDragonList(uid string) []*pb.DBDragon
|
GetDragonList(uid string) (dragon []*pb.DBDragon, err error)
|
||||||
|
// 创建坐骑
|
||||||
|
CreateDragon(session IUserSession, dragons map[string]int32, bPush bool) (errdata *pb.ErrorData)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
package dragon
|
package dragon
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"go_dreamfactory/comm"
|
"go_dreamfactory/comm"
|
||||||
"go_dreamfactory/lego/core"
|
"go_dreamfactory/lego/core"
|
||||||
"go_dreamfactory/modules"
|
"go_dreamfactory/modules"
|
||||||
"go_dreamfactory/pb"
|
"go_dreamfactory/pb"
|
||||||
|
"go_dreamfactory/sys/db"
|
||||||
|
|
||||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||||
"go.mongodb.org/mongo-driver/mongo"
|
"go.mongodb.org/mongo-driver/mongo"
|
||||||
@ -29,50 +29,93 @@ func (this *ModelDragon) Init(service core.IService, module core.IModule, comp c
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 获取一个新的坐骑
|
// 获取一个新的坐骑
|
||||||
func (this *ModelDragon) AddDragon(session comm.IUserSession, dragonCfgId string) (dragon *pb.DBDragon, err error) {
|
func (this *ModelDragon) CreateDragon(session comm.IUserSession, dragons map[string]int32) (errdata *pb.ErrorData) {
|
||||||
|
var (
|
||||||
|
dbModel *db.DBModel
|
||||||
|
err error
|
||||||
|
dragon *pb.DBDragon
|
||||||
|
)
|
||||||
dragonList := make([]*pb.DBDragon, 0)
|
dragonList := make([]*pb.DBDragon, 0)
|
||||||
uid := session.GetUserId()
|
uid := session.GetUserId()
|
||||||
if _, err = this.module.configure.GetDragonConfById(dragonCfgId, 1); err != nil {
|
|
||||||
err = errors.New("not found dragon dragonCfgId")
|
|
||||||
this.module.Errorf("not found dragon dragonCfgId:%s", dragonCfgId)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if this.module.IsCross() {
|
if this.module.IsCross() {
|
||||||
if dbModel, err1 := this.module.GetDBModelByUid(uid, this.TableName); err1 == nil {
|
if dbModel, err = this.module.GetDBModelByUid(uid, this.TableName); err != nil {
|
||||||
|
errdata = &pb.ErrorData{
|
||||||
|
Code: pb.ErrorCode_DBError,
|
||||||
|
Title: pb.ErrorCode_DBError.ToString(),
|
||||||
|
Message: err.Error(),
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for dragonCfgId, lv := range dragons {
|
||||||
|
if lv <= 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if _, err = this.module.configure.GetDragonConfById(dragonCfgId, 1); err != nil {
|
||||||
|
errdata = &pb.ErrorData{
|
||||||
|
Code: pb.ErrorCode_ConfigNoFound, // 配置没找到
|
||||||
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
||||||
|
Message: err.Error(),
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if dbModel != nil {
|
||||||
if err = dbModel.GetList(uid, &dragonList); err != nil {
|
if err = dbModel.GetList(uid, &dragonList); err != nil {
|
||||||
|
errdata = &pb.ErrorData{
|
||||||
|
Code: pb.ErrorCode_DBError, // 配置没找到
|
||||||
|
Title: pb.ErrorCode_DBError.ToString(),
|
||||||
|
Message: err.Error(),
|
||||||
|
}
|
||||||
this.module.Errorf("err:%v", err)
|
this.module.Errorf("err:%v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.module.Errorln(err) // 获取跨服对象失败
|
if err = this.GetList(uid, &dragonList); err != nil {
|
||||||
return
|
errdata = &pb.ErrorData{
|
||||||
|
Code: pb.ErrorCode_DBError, // 配置没找到
|
||||||
|
Title: pb.ErrorCode_DBError.ToString(),
|
||||||
|
Message: err.Error(),
|
||||||
|
}
|
||||||
|
this.module.Errorf("err:%v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
bFound := false
|
||||||
if err = this.GetList(uid, &dragonList); err != nil {
|
for _, obj := range dragonList {
|
||||||
this.module.Errorf("err:%v", err)
|
if obj.Dragonid == dragonCfgId { // 重复获得 直接返回
|
||||||
|
bFound = true
|
||||||
|
update := make(map[string]interface{}, 0)
|
||||||
|
update["lv"] = lv // 更新等级
|
||||||
|
if err = this.UpdateDragonData(session.GetUserId(), obj.Id, update); err != nil {
|
||||||
|
errdata = &pb.ErrorData{
|
||||||
|
Code: pb.ErrorCode_DBError, // 配置没找到
|
||||||
|
Title: pb.ErrorCode_DBError.ToString(),
|
||||||
|
Message: err.Error(),
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
if !bFound {
|
||||||
for _, obj := range dragonList {
|
dragon = &pb.DBDragon{
|
||||||
if obj.Dragonid == dragonCfgId { // 重复获得 直接返回
|
Id: primitive.NewObjectID().Hex(),
|
||||||
return
|
Uid: uid,
|
||||||
|
Dragonid: dragonCfgId,
|
||||||
|
Lv: lv,
|
||||||
|
Exp: 0,
|
||||||
|
Property: map[int32]int32{},
|
||||||
|
}
|
||||||
|
if dbModel != nil {
|
||||||
|
if dbModel, err1 := this.module.GetDBModelByUid(uid, this.TableName); err1 == nil {
|
||||||
|
err = dbModel.AddList(uid, dragonCfgId, dragon)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
err = this.AddList(uid, dragonCfgId, dragon)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dragon = &pb.DBDragon{
|
|
||||||
Id: primitive.NewObjectID().Hex(),
|
|
||||||
Uid: uid,
|
|
||||||
Dragonid: dragonCfgId,
|
|
||||||
Lv: 1,
|
|
||||||
Exp: 0,
|
|
||||||
Property: map[int32]int32{},
|
|
||||||
}
|
|
||||||
|
|
||||||
if this.module.IsCross() {
|
|
||||||
if dbModel, err1 := this.module.GetDBModelByUid(uid, this.TableName); err1 == nil {
|
|
||||||
err = dbModel.AddList(uid, dragonCfgId, dragon)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
err = this.AddList(uid, dragonCfgId, dragon)
|
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,3 +138,22 @@ func (this *ModelDragon) GetDragonList(uid string) (dragon []*pb.DBDragon, err e
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *ModelDragon) UpdateDragonData(uid string, oid string, data map[string]interface{}) (err error) {
|
||||||
|
if this.module.IsCross() {
|
||||||
|
if dbModel, err1 := this.module.GetDBModelByUid(uid, this.TableName); err1 == nil {
|
||||||
|
if err = dbModel.ChangeList(uid, oid, data); err != nil {
|
||||||
|
this.module.Errorf("err:%v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.module.Errorln(err) // 获取跨服对象失败
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if err = this.ChangeList(uid, oid, data); err != nil {
|
||||||
|
this.module.Errorf("err:%v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
@ -49,3 +49,8 @@ func (this *Dragon) Start() (err error) {
|
|||||||
func (this *Dragon) GetDragonList(uid string) (list []*pb.DBDragon, err error) {
|
func (this *Dragon) GetDragonList(uid string) (list []*pb.DBDragon, err error) {
|
||||||
return this.modelDragon.GetDragonList(uid)
|
return this.modelDragon.GetDragonList(uid)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 创建坐骑
|
||||||
|
func (this *Dragon) CreateDragon(session comm.IUserSession, dragons map[string]int32, bPush bool) (errdata *pb.ErrorData) {
|
||||||
|
return this.modelDragon.CreateDragon(session, dragons)
|
||||||
|
}
|
||||||
|
@ -36,7 +36,7 @@ type ModuleBase struct {
|
|||||||
ModuleFriend comm.IFriend //好友
|
ModuleFriend comm.IFriend //好友
|
||||||
ModuleSociaty comm.ISociaty //公会
|
ModuleSociaty comm.ISociaty //公会
|
||||||
ModulePrivilege comm.IPrivilege // 月卡
|
ModulePrivilege comm.IPrivilege // 月卡
|
||||||
ModuleSmithy comm.ISmithy //铁建普
|
ModuleSmithy comm.ISmithy //铁匠铺
|
||||||
ModulePractice comm.IPractice //练功房
|
ModulePractice comm.IPractice //练功房
|
||||||
ModuleParkour comm.IParkour //捕羊大赛
|
ModuleParkour comm.IParkour //捕羊大赛
|
||||||
ModuleTools comm.ITools //工具类 获取一些通用配置
|
ModuleTools comm.ITools //工具类 获取一些通用配置
|
||||||
@ -44,6 +44,7 @@ type ModuleBase struct {
|
|||||||
ModuleMail comm.Imail //邮件
|
ModuleMail comm.Imail //邮件
|
||||||
ModuleActivity comm.IActivity //活动模块
|
ModuleActivity comm.IActivity //活动模块
|
||||||
ModuleUiGame comm.IUiGame //
|
ModuleUiGame comm.IUiGame //
|
||||||
|
ModuleDragon comm.IDragon //
|
||||||
}
|
}
|
||||||
|
|
||||||
// 重构模块配置对象
|
// 重构模块配置对象
|
||||||
@ -151,6 +152,11 @@ func (this *ModuleBase) Start() (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.ModuleUiGame = module.(comm.IUiGame)
|
this.ModuleUiGame = module.(comm.IUiGame)
|
||||||
|
|
||||||
|
if module, err = this.service.GetModule(comm.ModuleDragon); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.ModuleDragon = module.(comm.IDragon)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -504,7 +510,10 @@ func (this *ModuleBase) DispenseRes(session comm.IUserSession, res []*cfg.Gameat
|
|||||||
this.Debugf("发放武馆资源: %v errdata: %v", panda, errdata)
|
this.Debugf("发放武馆资源: %v errdata: %v", panda, errdata)
|
||||||
}
|
}
|
||||||
if len(mts) > 0 {
|
if len(mts) > 0 {
|
||||||
errdata = this.ModuleParkour.AddMounts(session, mts, bPush)
|
if errdata = this.ModuleDragon.CreateDragon(session, per, bPush); errdata != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
//errdata = this.ModuleParkour.AddMounts(session, mts, bPush)
|
||||||
this.Debugf("发放捕羊大赛资源: %v errdata: %v", mts, errdata)
|
this.Debugf("发放捕羊大赛资源: %v errdata: %v", mts, errdata)
|
||||||
}
|
}
|
||||||
if len(per) > 0 {
|
if len(per) > 0 {
|
||||||
@ -772,7 +781,8 @@ func (this *ModuleBase) DispenseAtno(session comm.IUserSession, res []*cfg.Gamea
|
|||||||
this.Debugf("发放武馆资源: %v errdata: %v", panda, errdata)
|
this.Debugf("发放武馆资源: %v errdata: %v", panda, errdata)
|
||||||
}
|
}
|
||||||
if len(mts) > 0 {
|
if len(mts) > 0 {
|
||||||
if errdata = this.ModuleParkour.AddMounts(session, mts, bPush); errdata != nil {
|
//errdata = this.ModuleParkour.AddMounts(session, mts, bPush)
|
||||||
|
if errdata = this.ModuleDragon.CreateDragon(session, per, bPush); errdata != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for k, v := range mts {
|
for k, v := range mts {
|
||||||
|
Loading…
Reference in New Issue
Block a user