坐骑资源分发

This commit is contained in:
meixiongfeng 2023-08-31 18:04:28 +08:00
parent 7d9f3f1e2a
commit d581c883d8
5 changed files with 116 additions and 36 deletions

View File

@ -106,6 +106,7 @@ const (
ModulePuzzle core.M_Modules = "uigame" //小游戏
ModuleRobot core.M_Modules = "robot" //压测机器人
ModuleBattleRecord core.M_Modules = "battlerecord" //战斗记录
ModuleDragon core.M_Modules = "dragon" //坐骑
)
// 数据表名定义处

View File

@ -649,6 +649,8 @@ type (
}
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)
}
)

View File

@ -1,11 +1,11 @@
package dragon
import (
"errors"
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
"go_dreamfactory/sys/db"
"go.mongodb.org/mongo-driver/bson/primitive"
"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)
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 dbModel, err1 := this.module.GetDBModelByUid(uid, this.TableName); err1 == nil {
if err = dbModel.GetList(uid, &dragonList); err != nil {
this.module.Errorf("err:%v", err)
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
}
} else {
this.module.Errorln(err) // 获取跨服对象失败
}
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 {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_DBError, // 配置没找到
Title: pb.ErrorCode_DBError.ToString(),
Message: err.Error(),
}
this.module.Errorf("err:%v", err)
return
}
} else {
if err = this.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)
}
}
for _, obj := range dragonList {
if obj.Dragonid == dragonCfgId { // 重复获得 直接返回
return
}
}
bFound := false
for _, obj := range dragonList {
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 {
dragon = &pb.DBDragon{
Id: primitive.NewObjectID().Hex(),
Uid: uid,
Dragonid: dragonCfgId,
Lv: 1,
Lv: lv,
Exp: 0,
Property: map[int32]int32{},
}
if this.module.IsCross() {
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)
}
}
}
return
}
@ -95,3 +138,22 @@ func (this *ModelDragon) GetDragonList(uid string) (dragon []*pb.DBDragon, err e
}
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
}

View File

@ -49,3 +49,8 @@ func (this *Dragon) Start() (err error) {
func (this *Dragon) GetDragonList(uid string) (list []*pb.DBDragon, err error) {
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)
}

View File

@ -36,7 +36,7 @@ type ModuleBase struct {
ModuleFriend comm.IFriend //好友
ModuleSociaty comm.ISociaty //公会
ModulePrivilege comm.IPrivilege // 月卡
ModuleSmithy comm.ISmithy //铁建普
ModuleSmithy comm.ISmithy //铁匠铺
ModulePractice comm.IPractice //练功房
ModuleParkour comm.IParkour //捕羊大赛
ModuleTools comm.ITools //工具类 获取一些通用配置
@ -44,6 +44,7 @@ type ModuleBase struct {
ModuleMail comm.Imail //邮件
ModuleActivity comm.IActivity //活动模块
ModuleUiGame comm.IUiGame //
ModuleDragon comm.IDragon //
}
// 重构模块配置对象
@ -151,6 +152,11 @@ func (this *ModuleBase) Start() (err error) {
return
}
this.ModuleUiGame = module.(comm.IUiGame)
if module, err = this.service.GetModule(comm.ModuleDragon); err != nil {
return
}
this.ModuleDragon = module.(comm.IDragon)
return
}
@ -504,7 +510,10 @@ func (this *ModuleBase) DispenseRes(session comm.IUserSession, res []*cfg.Gameat
this.Debugf("发放武馆资源: %v errdata: %v", panda, errdata)
}
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)
}
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)
}
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
}
for k, v := range mts {