130 lines
3.3 KiB
Go
130 lines
3.3 KiB
Go
package user
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
"strings"
|
|
)
|
|
|
|
func (this *apiComp) CreateCheck(session comm.IUserSession, req *pb.UserCreateReq) (code pb.ErrorCode) {
|
|
name := strings.TrimSpace(req.NickName)
|
|
if name == "" || len(name) > 30 {
|
|
code = pb.ErrorCode_UserNickNameEmpty
|
|
this.module.Error("参数错误",
|
|
log.Field{Key: "uid", Value: session.GetUserId()},
|
|
log.Field{Key: "params", Value: req.String()},
|
|
)
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
// 创角
|
|
func (this *apiComp) Create(session comm.IUserSession, req *pb.UserCreateReq) (code pb.ErrorCode, edata *pb.ErrorData) {
|
|
if code = this.CreateCheck(session, req); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
|
|
// resp := &pb.UserCreateResp{}
|
|
uid := session.GetUserId()
|
|
//获取用户
|
|
self := this.module.modelUser.GetUser(session.GetUserId())
|
|
if self == nil {
|
|
code = pb.ErrorCode_UserSessionNobeing
|
|
return
|
|
}
|
|
|
|
//已否已创角
|
|
if self.Created {
|
|
code = pb.ErrorCode_RoleCreated
|
|
return
|
|
}
|
|
|
|
//查询昵称是否重复
|
|
if ok := this.module.modelUser.NickNameIsExist(req.NickName); !ok {
|
|
code = pb.ErrorCode_UserNickNameExist
|
|
// this.sendMsg(session, UserSubTypeCreate, resp)
|
|
return
|
|
}
|
|
|
|
//初始体力
|
|
var ps int32
|
|
gpd := this.module.configure.GetPlayerlvConf(self.Lv)
|
|
if gpd != nil {
|
|
ps = gpd.PsCeiling
|
|
}
|
|
|
|
update := map[string]interface{}{
|
|
"name": req.NickName, //设置昵称
|
|
"created": true, //创角标识
|
|
"figure": req.Figure, //设置形象
|
|
"gender": req.Gender, //设置性别
|
|
"ps": ps, //设置初始体力
|
|
}
|
|
|
|
globalConf := this.module.globalConf
|
|
if req.Gender == 0 {
|
|
update["avatar"] = globalConf.BoyHeadPortrait
|
|
} else if req.Gender == 1 {
|
|
update["avatar"] = globalConf.GirlHeadPortrait
|
|
}
|
|
|
|
if err := this.module.modelUser.Change(uid, update); err != nil {
|
|
code = pb.ErrorCode_DBError
|
|
this.module.Error("创角",
|
|
log.Field{Key: "uid", Value: uid},
|
|
log.Field{Key: "params", Value: update},
|
|
log.Field{Key: "err", Value: err.Error()},
|
|
)
|
|
return
|
|
}
|
|
|
|
var (
|
|
res []*cfg.Gameatn
|
|
)
|
|
|
|
//初始化创角资源
|
|
if val, err := this.module.configure.GetGlobalInitConf(); err == nil {
|
|
for _, v := range val.GetDataList() {
|
|
res = append(res, v.Var...)
|
|
}
|
|
_ = this.module.DispenseRes(session, res, true)
|
|
}
|
|
|
|
//初始化用户设置
|
|
// this.module.modelSetting.InitSetting(session.GetUserId())
|
|
|
|
// go func() {
|
|
// //初始化公会 date3.10
|
|
// sociaty := this.module.CrossCreateSociaty(uid, req.NickName)
|
|
// if sociaty == nil {
|
|
// return
|
|
// }
|
|
// this.module.Debugf("公会ID:%v", sociaty.Id)
|
|
// exUpdate := map[string]interface{}{
|
|
// "sociatyId": sociaty.Id,
|
|
// }
|
|
|
|
// if err := this.module.ModuleUser.ChangeUserExpand(uid, exUpdate); err != nil {
|
|
// code = pb.ErrorCode_DBError
|
|
// this.module.Error("更新玩家公会ID",
|
|
// log.Field{Key: "uid", Value: uid},
|
|
// log.Field{Key: "sociatyId", Value: sociaty.Id},
|
|
// log.Field{Key: "err", Value: err.Error()},
|
|
// )
|
|
// return
|
|
// }
|
|
|
|
// }()
|
|
// resp.IsSucc = true
|
|
// this.sendMsg(session, UserSubTypeCreate, resp)
|
|
session.SendMsg(string(this.module.GetType()), UserSubTypeCreate, &pb.UserCreateResp{})
|
|
if req.Figure != 0 {
|
|
go this.module.ModuleRtask.TriggerTask(uid, comm.GettaskParam(comm.Rtype72, 1))
|
|
}
|
|
this.mail.SendMailByCid(session, comm.Welcomemail, nil)
|
|
return
|
|
}
|