package gm import ( "context" "errors" "fmt" "go_dreamfactory/comm" "go_dreamfactory/lego/base" "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 base.IRPCXService 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.(base.IRPCXService) return } //模块初始化接口 注册用户创建角色事件 func (this *GM) Start() (err error) { err = this.ModuleBase.Start() this.service.RegisterFunctionName(string(comm.Rpc_ModuleGMCreateCmd), this.Rpc_ModuleGMCreateCmd) 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 cmd = strings.Replace(cmd, " ", "", -1) // 去空格 keys := strings.Split(cmd, ":") if len(keys) == 2 { if keys[0] == "bingo" { this.Debugf("create CMD :%s", cmd) // 打印个日志方便查询 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 || datas[0] == comm.VipType) { 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.Fields{"uid": session.GetUserId(), "A": datas[0], "T": datas[1], "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.Fields{"uid": session.GetUserId(), "0": datas[0], "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.Fields{"uid": session.GetUserId(), "0": datas[0], "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...) } data := this.configure.GetHeroConfigData() for _, v := range data { if v.Handbook != -1 { res = append(res, &cfg.Gameatn{ A: "hero", T: v.Hid, N: 1, }) } } code = this.DispenseRes(session, res, true) if code != pb.ErrorCode_Success { this.Errorf("资源发放失败,%v", code) } } this.Debug("使用bingo命令", log.Fields{"uid": session.GetUserId(), "param": datas[0], "res": res}) } else if len(datas) == 3 && (datas[0] == "worldtask") { module, err := this.service.GetModule(comm.ModuleWorldtask) if err != nil { return } if wt, ok := module.(comm.IWorldtask); ok { if err = wt.BingoJumpTask(session, utils.ToInt32(datas[1]), utils.ToInt32(datas[2])); err != nil { this.Error("bingo 世界任务", log.Fields{"params": datas, "err": err.Error()}) } } } else if len(datas) == 1 && (datas[0] == "manhero") { // 获取满星、等级、觉醒、共鸣技能 module1, err := this.service.GetModule(comm.ModuleHero) if err != nil { return } code = module1.(comm.IHero).GetAllMaxHero(session) this.Debug("使用bingo命令:uid = %s ", log.Fields{"uid": session.GetUserId(), "0": datas[1]}) } else if len(datas) == 2 && (datas[0] == "season") { // 赛季塔跳转 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).ModifySeasonPagodaFloor(session, int32(num)) this.Debug("使用bingo命令:uid = %s ", log.Fields{"uid": session.GetUserId(), "0": datas[0], "N": int32(num)}) } else if len(datas) == 1 && (datas[0] == "viking") { // 解锁远征所有难度 module1, err := this.service.GetModule(comm.ModuleViking) if err != nil { return } code = module1.(comm.IViking).CompleteAllLevel(session) this.Debug("使用bingo命令:uid = %s ", log.Fields{"uid": session.GetUserId()}) } else if len(datas) == 1 && (datas[0] == "hunting") { // 解锁狩猎所有难度 module1, err := this.service.GetModule(comm.ModuleHunting) if err != nil { return } code = module1.(comm.IHunting).CompleteAllLevel(session) this.Debug("使用bingo命令:uid = %s ", log.Fields{"uid": session.GetUserId(), "0": datas[1]}) } else if len(datas) == 3 && (datas[0] == "mainline") { module1, err := this.service.GetModule(comm.ModuleMainline) if err != nil { return } num1, err := strconv.Atoi(datas[1]) if err != nil { code = pb.ErrorCode_ReqParameterError return } num2, err := strconv.Atoi(datas[2]) if err != nil { code = pb.ErrorCode_ReqParameterError return } code = module1.(comm.IMainline).ModifyMainlineDataByNanduID(session.GetUserId(), int32(num1), int32(num2)) this.Debug("使用bingo命令", log.Fields{"uid": session.GetUserId(), "key:": keys[1]}) } else if len(datas) == 2 && (datas[0] == "moon") { // 触发月之秘境 module1, err := this.service.GetModule(comm.ModuleMoonfantasy) if err != nil { return } module1.(comm.IMoonFantasy).TriggerMF(session, datas[1]) this.Debug("使用bingo命令:uid = %s ", log.Fields{"uid": session.GetUserId(), "0": datas[1]}) } else if len(datas) == 2 && (datas[0] == "arena") { // 设置竞技场用户积分 module1, err := this.service.GetModule(comm.ModuleArena) if err != nil { return } num, err := strconv.Atoi(datas[1]) if err != nil { code = pb.ErrorCode_ReqParameterError return } module1.(comm.IArena).SetUserIntegral(session, int32(num)) this.Debug("使用bingo命令:uid = %s ", log.Fields{"uid": session.GetUserId(), "0": datas[1]}) } else if len(datas) == 2 && (datas[0] == "sociatyexp") { // 设置工会经验 module1, err := this.service.GetModule(comm.ModuleSociaty) if err != nil { return } num, err := strconv.Atoi(datas[1]) if err != nil { code = pb.ErrorCode_ReqParameterError return } module1.(comm.ISociaty).BingoSetExp(session, int32(num)) this.Debug("使用bingo命令:uid = %s ", log.Fields{"uid": session.GetUserId(), "0": datas[1]}) } else if len(datas) == 2 && (datas[0] == "sociatyactivity") { // 设置工会活跃度 module1, err := this.service.GetModule(comm.ModuleSociaty) if err != nil { return } num, err := strconv.Atoi(datas[1]) if err != nil { code = pb.ErrorCode_ReqParameterError return } module1.(comm.ISociaty).BingoSetActivity(session, int32(num)) this.Debug("使用bingo命令:uid = %s ", log.Fields{"uid": session.GetUserId(), "0": datas[1]}) } else if len(datas) == 1 && (datas[0] == "alltask") { // 设置工会活跃度 module, err := this.service.GetModule(comm.ModuleWorldtask) if err != nil { return } if wt, ok := module.(comm.IWorldtask); ok { if err = wt.BingoAllTask(session); err != nil { this.Error("bingo 世界任务", log.Fields{"params": datas, "err": err.Error()}) } } } } } return } func (this *GM) Rpc_ModuleGMCreateCmd(ctx context.Context, args *pb.RPCGeneralReqA2, reply *pb.EmptyResp) (err error) { this.Debug("Rpc_ModuleGMCreateCmd", log.Fields{"args": args.String()}) if args.Param1 == "" || args.Param2 == "" { err = errors.New("请求参数错误") } if session, ok := this.GetUserSession(args.Param1); !ok { err = fmt.Errorf("目标用户:%s 不在线", args.Param1) return } else { this.CreateCmd(session, args.Param2) session.Push() } return }