上传补杨大赛代码优化

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 (
"fmt"
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/modules"
"go_dreamfactory/sys/configure"
@ -16,13 +17,13 @@ const (
game_buzkashireward = "game_buzkashireward.json"
)
///背包配置管理组件
// /背包配置管理组件
type configureComp struct {
modules.MCompConfigure
module *Parkour
}
//组件初始化接口
// 组件初始化接口
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.module = module.(*Parkour)
@ -34,7 +35,7 @@ func (this *configureComp) Init(service core.IService, module core.IModule, comp
return
}
//查询开启表
// 查询开启表
func (this *configureComp) isopen() (open bool) {
var (
v interface{}
@ -62,7 +63,7 @@ func (this *configureComp) isopen() (open bool) {
return
}
//查询坐骑表
// 查询坐骑表
func (this *configureComp) getGameBuzkashiMount(id string) (configure *cfg.GameBuzkashiMountData, err error) {
var (
v interface{}
@ -73,7 +74,7 @@ func (this *configureComp) getGameBuzkashiMount(id string) (configure *cfg.GameB
return
} else {
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)
return
}

View File

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

View File

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