上传补杨大赛代码优化

This commit is contained in:
liwei 2023-07-07 14:39:02 +08:00
parent 1bdaa38367
commit 38a0f0249f
3 changed files with 27 additions and 23 deletions

View File

@ -2,6 +2,7 @@ package parkour
import ( import (
"fmt" "fmt"
"go_dreamfactory/comm"
"go_dreamfactory/lego/core" "go_dreamfactory/lego/core"
"go_dreamfactory/modules" "go_dreamfactory/modules"
"go_dreamfactory/sys/configure" "go_dreamfactory/sys/configure"
@ -16,13 +17,13 @@ const (
game_buzkashireward = "game_buzkashireward.json" game_buzkashireward = "game_buzkashireward.json"
) )
///背包配置管理组件 // /背包配置管理组件
type configureComp struct { type configureComp struct {
modules.MCompConfigure modules.MCompConfigure
module *Parkour module *Parkour
} }
//组件初始化接口 // 组件初始化接口
func (this *configureComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { func (this *configureComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
this.MCompConfigure.Init(service, module, comp, options) this.MCompConfigure.Init(service, module, comp, options)
this.module = module.(*Parkour) this.module = module.(*Parkour)
@ -34,7 +35,7 @@ func (this *configureComp) Init(service core.IService, module core.IModule, comp
return return
} }
//查询开启表 // 查询开启表
func (this *configureComp) isopen() (open bool) { func (this *configureComp) isopen() (open bool) {
var ( var (
v interface{} v interface{}
@ -62,7 +63,7 @@ func (this *configureComp) isopen() (open bool) {
return return
} }
//查询坐骑表 // 查询坐骑表
func (this *configureComp) getGameBuzkashiMount(id string) (configure *cfg.GameBuzkashiMountData, err error) { func (this *configureComp) getGameBuzkashiMount(id string) (configure *cfg.GameBuzkashiMountData, err error) {
var ( var (
v interface{} v interface{}
@ -73,7 +74,7 @@ func (this *configureComp) getGameBuzkashiMount(id string) (configure *cfg.GameB
return return
} else { } else {
if configure, ok = v.(*cfg.GameBuzkashiMount).GetDataMap()[id]; !ok { if configure, ok = v.(*cfg.GameBuzkashiMount).GetDataMap()[id]; !ok {
err = fmt.Errorf("not found:%s ", id) err = comm.NewNotFoundConfErr(moduleName, game_buzkashimount, id)
this.module.Errorln(err) this.module.Errorln(err)
return return
} }

View File

@ -23,7 +23,7 @@ import (
"go.mongodb.org/mongo-driver/x/bsonx" "go.mongodb.org/mongo-driver/x/bsonx"
) )
///竞速数据模块 // /竞速数据模块
type ModelParkourComp struct { type ModelParkourComp struct {
modules.MCompModel modules.MCompModel
module *Parkour module *Parkour
@ -32,7 +32,7 @@ type ModelParkourComp struct {
users []*Recommend //推荐用户信息 users []*Recommend //推荐用户信息
} }
//组件初始化接口 // 组件初始化接口
func (this *ModelParkourComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, opt core.IModuleOptions) (err error) { func (this *ModelParkourComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, opt core.IModuleOptions) (err error) {
this.TableName = comm.TableParkour this.TableName = comm.TableParkour
this.MCompModel.Init(service, module, comp, opt) this.MCompModel.Init(service, module, comp, opt)
@ -50,7 +50,7 @@ func (this *ModelParkourComp) Start() (err error) {
return return
} }
//获取推荐用户 // 获取推荐用户
func (this *ModelParkourComp) getrusers(uid string) (recommend []*pb.DBRaceMember, err error) { func (this *ModelParkourComp) getrusers(uid string) (recommend []*pb.DBRaceMember, err error) {
var ( var (
users []*Recommend users []*Recommend
@ -85,6 +85,7 @@ func (this *ModelParkourComp) getrusers(uid string) (recommend []*pb.DBRaceMembe
continue continue
} }
if mount, err = this.module.configure.getGameBuzkashiMount(users[v].parkour.Dfmount); err != nil { if mount, err = this.module.configure.getGameBuzkashiMount(users[v].parkour.Dfmount); err != nil {
err = nil
continue continue
} }
users[v].member = &pb.DBRaceMember{ users[v].member = &pb.DBRaceMember{
@ -102,7 +103,7 @@ func (this *ModelParkourComp) getrusers(uid string) (recommend []*pb.DBRaceMembe
return return
} }
//刷新推荐列表 // 刷新推荐列表
func (this *ModelParkourComp) refreshlist() { func (this *ModelParkourComp) refreshlist() {
var ( var (
users []*Recommend users []*Recommend
@ -205,7 +206,7 @@ func (this *ModelParkourComp) queryinfos(uids []string) (results []*pb.DBParkour
return return
} }
//更新用户的背包信息 // 更新用户的背包信息
func (this *ModelParkourComp) addUserMounts(uid string, mounts map[string]int32) (result *pb.DBParkour, err error) { func (this *ModelParkourComp) addUserMounts(uid string, mounts map[string]int32) (result *pb.DBParkour, err error) {
var ( var (
model *db.DBModel model *db.DBModel

View File

@ -23,6 +23,8 @@ import (
开发:李伟 开发:李伟
*/ */
const moduleName = "补羊大赛"
var _ comm.IParkour = (*Parkour)(nil) var _ comm.IParkour = (*Parkour)(nil)
func NewModule() core.IModule { func NewModule() core.IModule {
@ -42,12 +44,12 @@ type Parkour struct {
battles map[string]*RaceItem battles map[string]*RaceItem
} }
//模块名 // 模块名
func (this *Parkour) GetType() core.M_Modules { func (this *Parkour) GetType() core.M_Modules {
return comm.ModuleParkour return comm.ModuleParkour
} }
//模块初始化 // 模块初始化
func (this *Parkour) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) { func (this *Parkour) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) {
err = this.ModuleBase.Init(service, module, options) err = this.ModuleBase.Init(service, module, options)
this.service = service.(base.IRPCXService) this.service = service.(base.IRPCXService)
@ -62,7 +64,7 @@ func (this *Parkour) Start() (err error) {
return return
} }
//装备组件 // 装备组件
func (this *Parkour) OnInstallComp() { func (this *Parkour) OnInstallComp() {
this.ModuleBase.OnInstallComp() this.ModuleBase.OnInstallComp()
this.api = this.RegisterComp(new(apiComp)).(*apiComp) this.api = this.RegisterComp(new(apiComp)).(*apiComp)
@ -72,7 +74,7 @@ func (this *Parkour) OnInstallComp() {
this.raceComp = this.RegisterComp(new(ModelRaceComp)).(*ModelRaceComp) this.raceComp = this.RegisterComp(new(ModelRaceComp)).(*ModelRaceComp)
} }
//添加坐骑资源 // 添加坐骑资源
func (this *Parkour) AddMounts(session comm.IUserSession, mounts map[string]int32, bPush bool) (errdata *pb.ErrorData) { func (this *Parkour) AddMounts(session comm.IUserSession, mounts map[string]int32, bPush bool) (errdata *pb.ErrorData) {
var ( var (
result *pb.DBParkour result *pb.DBParkour
@ -92,7 +94,7 @@ func (this *Parkour) AddMounts(session comm.IUserSession, mounts map[string]int3
return return
} }
//匹配 // 匹配
func (this *Parkour) match(team *pb.DBParkour) (err error) { func (this *Parkour) match(team *pb.DBParkour) (err error) {
ctx, _ := context.WithTimeout(context.Background(), time.Second*5) ctx, _ := context.WithTimeout(context.Background(), time.Second*5)
err = this.service.RpcCall( err = this.service.RpcCall(
@ -108,7 +110,7 @@ func (this *Parkour) match(team *pb.DBParkour) (err error) {
return return
} }
//匹配成功 创建战斗 // 匹配成功 创建战斗
func (this *Parkour) createbattle(ctx context.Context, req *pb.RPCParkourMatchSuccReq, resp *pb.RPCParkourMatchSuccResp) (err error) { func (this *Parkour) createbattle(ctx context.Context, req *pb.RPCParkourMatchSuccReq, resp *pb.RPCParkourMatchSuccResp) (err error) {
var ( var (
race *pb.DBRace race *pb.DBRace
@ -214,7 +216,7 @@ func (this *Parkour) startbattle(id string) {
} }
} }
//射门 // 射门
func (this *Parkour) shot(id string, uid string) { func (this *Parkour) shot(id string, uid string) {
this.Debug("shot", log.Field{Key: "id", Value: id}) this.Debug("shot", log.Field{Key: "id", Value: id})
var ( var (
@ -262,7 +264,7 @@ func (this *Parkour) shot(id string, uid string) {
} }
} }
//躲避障碍物 // 躲避障碍物
func (this *Parkour) avoid(id string, uid string, dis float32) { func (this *Parkour) avoid(id string, uid string, dis float32) {
this.Debug("shot", log.Field{Key: "id", Value: id}) this.Debug("shot", log.Field{Key: "id", Value: id})
var ( var (
@ -332,7 +334,7 @@ func (this *Parkour) avoid(id string, uid string, dis float32) {
} }
} }
//恢复hp值 // 恢复hp值
func (this *Parkour) recoverhp(id string, hp int32, uids ...string) { func (this *Parkour) recoverhp(id string, hp int32, uids ...string) {
this.Debug("recoverhp", log.Field{Key: "id", Value: id}, log.Field{Key: "hp", Value: hp}, log.Field{Key: "uids", Value: uids}) this.Debug("recoverhp", log.Field{Key: "id", Value: id}, log.Field{Key: "hp", Value: hp}, log.Field{Key: "uids", Value: uids})
var ( var (
@ -383,7 +385,7 @@ func (this *Parkour) recoverhp(id string, hp int32, uids ...string) {
} }
//战斗结束 // 战斗结束
func (this *Parkour) overtimer(task *timewheel.Task, args ...interface{}) { func (this *Parkour) overtimer(task *timewheel.Task, args ...interface{}) {
this.Debug("shot", log.Field{Key: "id", Value: args}) this.Debug("shot", log.Field{Key: "id", Value: args})
var ( var (
@ -449,7 +451,7 @@ func (this *Parkour) overtimer(task *timewheel.Task, args ...interface{}) {
} }
} }
//用户离线处理 // 用户离线处理
func (this *Parkour) useroffline(uid, sessionid string) { func (this *Parkour) useroffline(uid, sessionid string) {
var ( var (
info *pb.DBParkour info *pb.DBParkour
@ -625,7 +627,7 @@ func (this *Parkour) useroffline(uid, sessionid string) {
} }
} }
//托管 // 托管
func (this *Parkour) trusteeship(ctx context.Context, req *pb.RPC_ParkourTrusteeshipReq, resp *pb.RPC_ParkourTrusteeshipResp) (err error) { func (this *Parkour) trusteeship(ctx context.Context, req *pb.RPC_ParkourTrusteeshipReq, resp *pb.RPC_ParkourTrusteeshipResp) (err error) {
var ( var (
battle *RaceItem battle *RaceItem
@ -653,7 +655,7 @@ func (this *Parkour) trusteeship(ctx context.Context, req *pb.RPC_ParkourTrustee
return return
} }
//定时复活 // 定时复活
func (this *Parkour) resurrectiontimer(task *timewheel.Task, args ...interface{}) { func (this *Parkour) resurrectiontimer(task *timewheel.Task, args ...interface{}) {
var ( var (
battleid string battleid string