94 lines
2.6 KiB
Go
94 lines
2.6 KiB
Go
package equipment
|
|
|
|
import (
|
|
"fmt"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
"math"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) SellCheck(session comm.IUserSession, req *pb.EquipmentSellReq) (errdata *pb.ErrorData) {
|
|
if req.EquipIds == nil || len(req.EquipIds) == 0 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
//出售
|
|
func (this *apiComp) Sell(session comm.IUserSession, req *pb.EquipmentSellReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
err error
|
|
equipments []*pb.DB_Equipment
|
|
confs []*cfg.GameEquipData
|
|
sale [][]*cfg.Gameatn
|
|
)
|
|
if errdata = this.SellCheck(session, req); errdata != nil {
|
|
return
|
|
}
|
|
if equipments, err = this.module.modelEquipment.QueryUserEquipmentsByIds(session.GetUserId(), req.EquipIds); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
confs = make([]*cfg.GameEquipData, len(equipments))
|
|
sale = make([][]*cfg.Gameatn, len(equipments))
|
|
for i, v := range equipments {
|
|
if v.HeroId != "" || v.Islock {
|
|
this.module.Errorf("NoCanSell %v", v)
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_EquipmentNoCanSell,
|
|
Title: pb.ErrorCode_EquipmentNoCanSell.ToString(),
|
|
Message: fmt.Sprintf("装备已锁定! 装备id:%s", v),
|
|
}
|
|
return
|
|
}
|
|
if confs[i], err = this.module.configure.GetEquipmentConfigureById(v.CId); err != nil {
|
|
this.module.Errorln(err)
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_EquipmentOnFoundEquipment,
|
|
Title: pb.ErrorCode_EquipmentOnFoundEquipment.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
if confs[i].Sale == nil || len(confs[i].Sale) == 0 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_EquipmentNoCanSell,
|
|
Title: pb.ErrorCode_EquipmentNoCanSell.ToString(),
|
|
Message: fmt.Sprintf("装备出售配置为空! 装备id:%s", confs[i].Id),
|
|
}
|
|
return
|
|
}
|
|
sale[i] = make([]*cfg.Gameatn, len(confs[i].Sale))
|
|
for n, s := range confs[i].Sale {
|
|
_s := &cfg.Gameatn{
|
|
A: s.A,
|
|
T: s.T,
|
|
N: s.N + int32(math.Floor(float64(s.N*(v.Lv-1))*float64(confs[i].Salecoef))),
|
|
}
|
|
sale[i][n] = _s
|
|
}
|
|
}
|
|
|
|
sales := make([]*cfg.Gameatn, 0)
|
|
for _, v := range sale {
|
|
sales = append(sales, v...)
|
|
}
|
|
if errdata = this.module.DispenseRes(session, sales, true); errdata != nil {
|
|
return
|
|
}
|
|
if errdata = this.module.DelEquipments(session, req.EquipIds, true); errdata != nil {
|
|
return
|
|
}
|
|
session.SendMsg(string(this.module.GetType()), "sell", &pb.EquipmentSellResp{IsSucc: true})
|
|
return
|
|
}
|