package equipment import ( "go_dreamfactory/comm" "go_dreamfactory/pb" "go_dreamfactory/sys/configure" cfg "go_dreamfactory/sys/configure/structs" "math/rand" "google.golang.org/protobuf/proto" ) //参数校验 func (this *apiComp) WashCheck(session comm.IUserSession, req *pb.EquipmentWashReq) (code pb.ErrorCode) { if req.Eid == "" { code = pb.ErrorCode_ReqParameterError } return } //锻造 func (this *apiComp) Wash(session comm.IUserSession, req *pb.EquipmentWashReq) (code pb.ErrorCode, data proto.Message) { var ( equip *pb.DB_Equipment conf *cfg.GameEquipData attrlibrarys []*cfg.GameEquipAttrlibraryData adverbEntry []*pb.EquipmentAttributeEntry err error ) if code = this.WashCheck(session, req); code != pb.ErrorCode_Success { return } if equip, err = this.module.modelEquipment.QueryUserEquipmentsById(session.GetUserId(), req.Eid); err != nil { this.module.Errorf("Equip reader uid:%s equipment:%s err:%v", session.GetUserId(), req.Eid, err) code = pb.ErrorCode_SystemError return } if conf, err = this.module.configure.GetEquipmentConfigureById(equip.CId); err != nil { this.module.Errorf("Equip_Check err:%v", err) code = pb.ErrorCode_ConfigNoFound return } gole := this.module.configure.GetGlobalConf().EquipmentConsumption[conf.Color-1] if code = this.module.ConsumeRes(session, []*cfg.Gameatn{{A: comm.AttrType, T: comm.ResGold, N: gole}}, true); code != pb.ErrorCode_Success { return } if attrlibrarys, err = this.module.configure.GetEquipmentAttrlibraryConfigureById(conf.Addlibrary); err != nil || len(attrlibrarys) == 0 { this.module.Errorf("升级服务错误 读取副词条配置错误!") return } for i, v := range attrlibrarys { //移除主属性 if v.Attrkey == equip.MainEntry.AttrName { attrlibrarys = append(attrlibrarys[0:i], attrlibrarys[i+1:]...) break } } adverbEntry = make([]*pb.EquipmentAttributeEntry, len(equip.AdverbEntry)) r := rand.New(rand.NewSource(configure.Now().Unix())) for i, v := range r.Perm(len(equip.AdverbEntry)) { adverbEntry[i] = &pb.EquipmentAttributeEntry{ Id: attrlibrarys[v].Key, Libraryid: attrlibrarys[v].Libraryid, Lv: equip.AdverbEntry[i].Lv, AttrName: attrlibrarys[v].Attrkey, BaseValue: attrlibrarys[v].Attrvar, Value: attrlibrarys[v].Attrvar + int32(float64(attrlibrarys[v].Addition[equip.AdverbEntry[i].Lv-1])/1000.0*float64(attrlibrarys[v].AttrvarCorrect)), } } // this.module.ModuleRtask.SendToRtask(session, comm.Rtype95, 1) go this.module.ModuleRtask.TriggerTask(session.GetUserId(), comm.GettaskParam(comm.Rtype95, 1)) session.SendMsg(string(this.module.GetType()), "wash", &pb.EquipmentWashResp{Eid: req.Eid, AdverbEntry: adverbEntry}) return }