go_dreamfactory/modules/gm/api_cmd.go

87 lines
2.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package gm
import (
"go_dreamfactory/comm"
"go_dreamfactory/pb"
cfg "go_dreamfactory/sys/configure/structs"
"strconv"
"strings"
"google.golang.org/protobuf/proto"
)
/* GM 在控制台输入的字符串类型
//bingo:item,10001,1
//bingo:attr,gold,1000000
2、修改主线关卡进度bingo:mapid,102102代表关卡位置
3、修改心魔塔进度bingo:pataid,1010代表层数
4、修改玩家经验值bingo:exp,10001000代表新增的经验值 //
*/
//参数校验
func (this *apiComp) CmdCheck(session comm.IUserSession, req *pb.GMCmdReq) (code pb.ErrorCode) {
if len(req.Cmod) == 0 {
code = pb.ErrorCode_ReqParameterError
}
return
}
///解析GM 指令
func (this *apiComp) Cmd(session comm.IUserSession, req *pb.GMCmdReq) (code pb.ErrorCode, data proto.Message) {
if code = this.CmdCheck(session, req); code != pb.ErrorCode_Success {
return
}
keys := strings.Split(req.Cmod, ":")
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.module.DispenseRes(session, []*cfg.Gameatn{ // 添加资源
{
A: datas[0],
T: datas[1],
N: int32(num),
},
}, true)
if code == pb.ErrorCode_Success { // 成功直接返回
session.SendMsg(string(this.module.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))
}
}
}
//this.module.ModuleHero.GetSpecifiedHero(session.GetUserId(), heroid, star, lv)
session.SendMsg(string(this.module.GetType()), "cmd", &pb.GMCmdResp{IsSucc: false})
return
}