69 lines
1.4 KiB
Go
69 lines
1.4 KiB
Go
package user
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) SellResCheck(session comm.IUserSession, req *pb.UserSellResReq) (code pb.ErrorCode) {
|
|
if len(req.Atno) == 0 {
|
|
code = pb.ErrorCode_ReqParameterError
|
|
}
|
|
return
|
|
}
|
|
|
|
//分解道具
|
|
func (this *apiComp) SellRes(session comm.IUserSession, req *pb.UserSellResReq) (code pb.ErrorCode, data *pb.ErrorData) {
|
|
var (
|
|
equip []string // 出售的装备
|
|
sale []*pb.UserAssets
|
|
mapitem map[string]int32
|
|
)
|
|
mapitem = map[string]int32{}
|
|
if code = this.SellResCheck(session, req); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
for _, v := range req.Atno {
|
|
if v.A == "item" {
|
|
mapitem[v.O] += v.N
|
|
} else if v.A == "equi" {
|
|
equip = append(equip, v.O)
|
|
}
|
|
}
|
|
if len(mapitem) > 0 {
|
|
if c, d := this.module.ModuleItems.SellItem(session, mapitem, true); c != pb.ErrorCode_Success {
|
|
for _, v := range d {
|
|
sale = append(sale, &pb.UserAssets{
|
|
A: v.A,
|
|
T: v.T,
|
|
N: v.N,
|
|
})
|
|
}
|
|
} else {
|
|
code = c
|
|
return
|
|
}
|
|
}
|
|
if len(equip) > 0 {
|
|
if c, d := this.module.ModuleEquipment.SellEquipments(session, equip); c != pb.ErrorCode_Success {
|
|
for _, v := range d {
|
|
sale = append(sale, &pb.UserAssets{
|
|
A: v.A,
|
|
T: v.T,
|
|
N: v.N,
|
|
})
|
|
}
|
|
} else {
|
|
code = c
|
|
return
|
|
}
|
|
}
|
|
|
|
session.SendMsg(string(this.module.GetType()), "sellres", &pb.UserSellResResp{
|
|
Atn: sale,
|
|
IsSucc: true,
|
|
})
|
|
return
|
|
}
|