package equipment import ( "fmt" "go_dreamfactory/comm" "go_dreamfactory/pb" cfg "go_dreamfactory/sys/configure/structs" ) //参数校验 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 confUpsells []*cfg.GameEquipUpsellData sale [][]*cfg.Gameatn reward []*pb.UserAtno ) 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)) confUpsells = make([]*cfg.GameEquipUpsellData, 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 } if confUpsells[i], err = this.module.configure.getGameEquipUpsellData(confs[i].InitLv, v.Lv); err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ConfigNoFound, Title: pb.ErrorCode_ConfigNoFound.ToString(), Message: err.Error(), } return } sale[i] = make([]*cfg.Gameatn, 0) for _, s := range confs[i].Sale { _s := &cfg.Gameatn{ A: s.A, T: s.T, N: s.N, } sale[i] = append(sale[i], _s) } for _, s := range confUpsells[i].Suittype { _s := &cfg.Gameatn{ A: s.A, T: s.T, N: s.N, } sale[i] = append(sale[i], _s) } } sales := make([]*cfg.Gameatn, 0) for _, v := range sale { sales = append(sales, v...) } if errdata, reward = this.module.DispenseAtno(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, Reward: reward}) return }