go_dreamfactory/modules/gm/module.go
2022-09-21 19:40:56 +08:00

100 lines
2.4 KiB
Go

package gm
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
cfg "go_dreamfactory/sys/configure/structs"
"strconv"
"strings"
)
/*
模块名:GM工具模块
描述:处理客户端发过来的gm命令
开发:梅雄风
*/
func NewModule() core.IModule {
m := new(GM)
return m
}
type GM struct {
modules.ModuleBase
api_comp *apiComp
service core.IService
}
//模块名
func (this *GM) GetType() core.M_Modules {
return comm.ModuleGM
}
//模块初始化接口 注册用户创建角色事件
func (this *GM) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) {
err = this.ModuleBase.Init(service, module, options)
this.service = service
return
}
//装备组件
func (this *GM) OnInstallComp() {
this.ModuleBase.OnInstallComp()
this.api_comp = this.RegisterComp(new(apiComp)).(*apiComp)
}
func (this *GM) CreateCmd(session comm.IUserSession, cmd string) (code pb.ErrorCode) {
code = pb.ErrorCode_ReqParameterError
keys := strings.Split(cmd, ":")
if len(keys) == 2 {
if keys[0] == "bingo" {
datas := strings.Split(keys[1], ",")
if len(datas) == 3 && (datas[0] == comm.AttrType || datas[0] == comm.ItemType ||
datas[0] == comm.HeroType || datas[0] == comm.EquipmentType) {
num, err := strconv.Atoi(datas[2])
if err != nil {
code = pb.ErrorCode_ReqParameterError
return
}
code = this.DispenseRes(session, []*cfg.Gameatn{ // 添加资源
{
A: datas[0],
T: datas[1],
N: int32(num),
},
}, true)
if code == pb.ErrorCode_Success { // 成功直接返回
session.SendMsg(string(this.GetType()), "cmd", &pb.GMCmdResp{IsSucc: true})
return
}
} else if len(datas) == 2 && (datas[0] == "mapid") {
module1, err := this.service.GetModule(comm.ModuleMainline)
if err != nil {
return
}
num, err := strconv.Atoi(datas[1])
if err != nil {
code = pb.ErrorCode_ReqParameterError
return
}
code = module1.(comm.IMainline).ModifyMainlineData(session.GetUserId(), int32(num))
} else if len(datas) == 2 && (datas[0] == "pataid") {
module1, err := this.service.GetModule(comm.ModulePagoda)
if err != nil {
return
}
num, err := strconv.Atoi(datas[1])
if err != nil {
code = pb.ErrorCode_ReqParameterError
return
}
code = module1.(comm.IPagoda).ModifyPagodaFloor(session, int32(num))
}
}
}
return
}