95 lines
2.8 KiB
Go
95 lines
2.8 KiB
Go
package items
|
|
|
|
import (
|
|
"fmt"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) DecomposeCheck(session comm.IUserSession, req *pb.ItemsDecomposeReq) (errdata *pb.ErrorData) {
|
|
if req.GridId == "" || req.Amount <= 0 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
//分解道具
|
|
func (this *apiComp) Decompose(session comm.IUserSession, req *pb.ItemsDecomposeReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
err error
|
|
item *pb.DB_UserItemData
|
|
itemcf *cfg.GameItemData
|
|
sale []*cfg.Gameatn
|
|
atno []*pb.UserAtno
|
|
)
|
|
if errdata = this.DecomposeCheck(session, req); errdata != nil {
|
|
return
|
|
}
|
|
if item, err = this.module.modelItems.QueryUserPackByGridId(session.GetUserId(), req.GridId); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
if itemcf, err = this.module.configure.GetItemConfigure(item.ItemId); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigurationException,
|
|
Title: pb.ErrorCode_ConfigurationException.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
if itemcf.DecomposeDeplete == nil || len(itemcf.DecomposeDeplete) == 0 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ItemsUseNoCanSell,
|
|
Title: pb.ErrorCode_ItemsUseNoCanSell.ToString(),
|
|
Message: fmt.Sprintf("道具分解配置未配置! 道具id:%s", itemcf.Id),
|
|
}
|
|
return
|
|
}
|
|
// sale = make([]*cfg.Gameatn, 0, len(itemcf.DecomposeDeplete))
|
|
// for _, v := range itemcf.DecomposeDeplete {
|
|
// sale = append(sale, &cfg.Gameatn{
|
|
// A: v.A,
|
|
// T: v.T,
|
|
// N: v.N * int32(req.Amount),
|
|
// })
|
|
// }
|
|
// if errdata = this.module.ConsumeRes(session, sale, true); errdata != nil {
|
|
// return
|
|
// }
|
|
|
|
if req.Amount > item.Amount {
|
|
this.module.Errorf("SellItemCheck over all amount:[%d:%d]", req.Amount, item.Amount)
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
Message: fmt.Sprintf("道具数量不足! 道具数量:%d", item.Amount),
|
|
}
|
|
return
|
|
}
|
|
sale = make([]*cfg.Gameatn, len(itemcf.Sale))
|
|
for i, v := range itemcf.Sale {
|
|
temp := *v
|
|
sale[i] = &temp
|
|
sale[i].N = v.N * int32(req.Amount)
|
|
}
|
|
if errdata, atno = this.module.DispenseAtno(session, sale, true); errdata != nil {
|
|
return
|
|
}
|
|
item.Amount = item.Amount - req.Amount
|
|
if errdata = this.module.AddItemforGrid(session, req.GridId, -1*int32(req.Amount), true); errdata != nil {
|
|
return
|
|
}
|
|
session.SendMsg(string(this.module.GetType()), "decompose", &pb.ItemsDecomposeResp{GridId: req.GridId, Amount: req.Amount, Issucc: true, Asets: atno})
|
|
return
|
|
}
|