95 lines
2.0 KiB
Go
95 lines
2.0 KiB
Go
package user
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/utils"
|
|
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
// 主角形象设置
|
|
|
|
func (this *apiComp) FigureCheck(session comm.IUserSession, req *pb.UserFigureReq) (code pb.ErrorCode) {
|
|
if req.Preinstall < 1 || req.Preinstall > 5 || req.Action < 0 ||
|
|
req.Hair == nil || req.Eyes == nil || req.Mouth == nil || req.Body == nil || req.Complexion == nil {
|
|
code = pb.ErrorCode_ReqParameterError
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *apiComp) Figure(session comm.IUserSession, req *pb.UserFigureReq) (code pb.ErrorCode, data proto.Message) {
|
|
if code = this.FigureCheck(session, req); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
|
|
expand, err := this.module.modelExpand.GetUserExpand(session.GetUserId())
|
|
if err != nil {
|
|
code = pb.ErrorCode_DBError
|
|
return
|
|
}
|
|
|
|
//当前形象
|
|
var curFigure *pb.Figure
|
|
if v, ok := expand.Preinstall[req.Preinstall]; ok {
|
|
curFigure = v
|
|
} else {
|
|
//TODO 设置默认形象
|
|
curFigure = &pb.Figure{}
|
|
return
|
|
}
|
|
|
|
rsp := &pb.UserFigureResp{
|
|
Uid: session.GetUserId(),
|
|
Action: req.Action,
|
|
}
|
|
|
|
if req.Action == 0 {
|
|
//直接返回预设形象
|
|
rsp.Figure = curFigure
|
|
} else {
|
|
update := make(map[string]interface{})
|
|
switch req.Action {
|
|
// 头发
|
|
case 1:
|
|
if req.Hair != nil {
|
|
curFigure.Hair = req.Hair
|
|
}
|
|
// 眼睛
|
|
case 2:
|
|
if req.Eyes != nil {
|
|
curFigure.Eyes = req.Eyes
|
|
}
|
|
// 嘴巴
|
|
case 3:
|
|
if req.Mouth != nil {
|
|
curFigure.Mouth = req.Mouth
|
|
}
|
|
// 体型
|
|
case 4:
|
|
if req.Body != nil {
|
|
curFigure.Body = req.Body
|
|
}
|
|
// 肤色
|
|
case 5:
|
|
if req.Complexion != nil {
|
|
curFigure.Complexion = req.Complexion
|
|
}
|
|
default:
|
|
code = pb.ErrorCode_ReqParameterError
|
|
return
|
|
}
|
|
|
|
update = utils.StructToMap(curFigure)
|
|
|
|
this.module.modelExpand.ChangeUserExpand(session.GetUserId(), update)
|
|
}
|
|
|
|
if err := session.SendMsg(string(this.module.GetType()), UserSubTypeFigure, rsp); err != nil {
|
|
code = pb.ErrorCode_SystemError
|
|
return
|
|
}
|
|
|
|
return
|
|
}
|