128 lines
3.8 KiB
Go
128 lines
3.8 KiB
Go
package gm
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
"go_dreamfactory/utils"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
/*
|
|
模块名:GM工具模块
|
|
描述:处理客户端发过来的gm命令
|
|
开发:梅雄风
|
|
*/
|
|
func NewModule() core.IModule {
|
|
m := new(GM)
|
|
return m
|
|
}
|
|
|
|
type GM struct {
|
|
modules.ModuleBase
|
|
api_comp *apiComp
|
|
service core.IService
|
|
configure *configureComp
|
|
}
|
|
|
|
//模块名
|
|
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)
|
|
this.configure = this.RegisterComp(new(configureComp)).(*configureComp)
|
|
}
|
|
|
|
//bingo:Iamyoudad
|
|
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})
|
|
}
|
|
this.Debug("使用bingo命令", log.Field{"uid", session.GetUserId()}, log.Field{"A", datas[0]}, log.Field{"T", datas[1]}, log.Field{"N", int32(num)})
|
|
} 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))
|
|
|
|
this.Debug("使用bingo命令", log.Field{"uid", session.GetUserId()}, log.Field{"0", datas[0]}, log.Field{"N", 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))
|
|
this.Debug("使用bingo命令:uid = %s ", log.Field{"uid", session.GetUserId()}, log.Field{"0", datas[0]}, log.Field{"N", int32(num)})
|
|
} else if len(datas) == 1 && (datas[0] == "Iamyoudad" || datas[0] == "iamyoudad") {
|
|
var (
|
|
res []*cfg.Gameatn
|
|
)
|
|
if val, err := this.configure.GetYouDaddyConf(); err == nil {
|
|
for _, v := range val.GetDataList() {
|
|
res = append(res, v.Var...)
|
|
|
|
}
|
|
code = this.DispenseRes(session, res, true)
|
|
if code != pb.ErrorCode_Success {
|
|
this.Errorf("资源发放失败,%v", code)
|
|
}
|
|
}
|
|
this.Debugf("使用bingo命令", log.Field{"uid", session.GetUserId()}, datas[0], res)
|
|
} else if len(datas) == 3 && (datas[0] == "rtask") {
|
|
err := this.ModuleRtask.BingoRtask(session, utils.ToInt32(datas[1]), utils.ToInt32(datas[2]))
|
|
if err != nil {
|
|
this.Errorf("bingo rdTask Failed ,Parameter :%s,%s %v", datas[1], datas[2], err)
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
return
|
|
}
|