package smithy import ( "go_dreamfactory/comm" "go_dreamfactory/pb" "go_dreamfactory/sys/configure" cfg "go_dreamfactory/sys/configure/structs" "strconv" "google.golang.org/protobuf/proto" ) //参数校验 func (this *apiComp) ForgeEquipCheck(session comm.IUserSession, req *pb.SmithyForgeEquipReq) (code pb.ErrorCode) { if req.ReelId == 0 || req.Lava < 0 || req.Quality < 0 { code = pb.ErrorCode_ReqParameterError return } return } // 打造装备 func (this *apiComp) ForgeEquip(session comm.IUserSession, req *pb.SmithyForgeEquipReq) (code pb.ErrorCode, data proto.Message) { var ( stove *pb.DBStove err error update map[string]interface{} costRes []*cfg.Gameatn customLv int32 // 定制装备的等级 rsp *pb.SmithyForgeEquipResp ) rsp = &pb.SmithyForgeEquipResp{} update = make(map[string]interface{}) code = this.ForgeEquipCheck(session, req) if code != pb.ErrorCode_Success { return // 参数校验失败直接返回 } stove, err = this.module.modelStove.getSmithyStoveList(session.GetUserId()) if err != nil { code = pb.ErrorCode_DBError return } reelcfg := this.module.configure.GetSmithyReelConfigData(req.ReelId) if reelcfg == nil { code = pb.ErrorCode_ReqParameterError // 没有找到该类型的图纸信息 return } // 校验图纸是否激活 if _, ok := stove.Data[req.ReelId]; !ok { // 是不是首次打造 if !this.module.configure.CheckSmithyFirstReelConfigData(reelcfg.Type, req.ReelId) { // 没有激活图纸 code = pb.ErrorCode_SmithyNoReel return } stove.Data[req.ReelId] = &pb.Mastery{ Lv: 1, Value: 0, } } stove.Data[req.ReelId].Value += 1 stove.Forge[req.ReelId] += 1 // 是否是精益打造 if req.Quality > 0 { costRes = append(costRes, reelcfg.RefineCos) } // 校验是不是装备定制打造 if req.SuiteId != 0 { // 检查消耗 if code = this.module.CheckRes(session, []*cfg.Gameatn{reelcfg.CustomizedCos1}); code != pb.ErrorCode_Success { return } costRes = append(costRes, reelcfg.CustomizedCos1) if req.Position == -1 { if code = this.module.CheckRes(session, []*cfg.Gameatn{reelcfg.CustomizedCos2}); code != pb.ErrorCode_Success { return } costRes = append(costRes, reelcfg.CustomizedCos2) } // 随机权重 获取等级 index := this.module.modelStove.GetRandEquipLv(reelcfg.CustomizedLvDistribution) if int32(len(reelcfg.CustomizedLv)) > index { customLv = reelcfg.CustomizedLv[index] } } // 是否是熔岩打造 if req.Lava > 0 { // 预计消耗温度 exemption := this.module.configure.GetGlobalConf().ExemptionTemperatureCos if len(exemption) != 2 { code = pb.ErrorCode_ConfigNoFound return } if reelcfg.TemperatureCos > req.Lava*exemption[1] { code = pb.ErrorCode_SmithyLackLava // 缺少熔岩 return } // 检查消耗 lavaCost := &cfg.Gameatn{ A: "item", T: strconv.Itoa(int(exemption[0])), N: req.Lava, } if code = this.module.CheckRes(session, []*cfg.Gameatn{lavaCost}); code != pb.ErrorCode_Success { return } costRes = append(costRes, lavaCost) } else { // 熟练度减少的温度 t := this.module.modelStove.CheckTemperature(req.ReelId, stove.Data[req.ReelId].Lv) // 检查炉温 是否够 if stove.Temperature < reelcfg.TemperatureCos-t { code = pb.ErrorCode_SmithyNoTemperature // 炉温不够 直接返回 return } stove.Temperature -= (reelcfg.TemperatureCos - t) // 消耗温度 update["temperature"] = stove.Temperature } costRes = append(costRes, reelcfg.BasicCos...) subAtn := this.module.modelStove.CheckForgeConsume(req.ReelId, stove.Data[req.ReelId].Lv) costRes = append(costRes, subAtn...) if code = this.module.CheckRes(session, costRes); code != pb.ErrorCode_Success { return } // 检查是否提升了熟练度等级 nextProficiency := this.module.configure.GetSmithyProficileData(req.ReelId, stove.Data[req.ReelId].Lv+1) if nextProficiency != nil && nextProficiency.Proficiency >= stove.Data[req.ReelId].Value { // 提升熟练度 stove.Data[req.ReelId].Lv += 1 stove.Data[req.ReelId].Value = 0 // 校验是否解锁了新的图纸 if nextProficiency.Type == comm.SmithyReelType3 { stove.Data[nextProficiency.Value1] = &pb.Mastery{ Lv: 1, Value: 0, } } // 是否解锁新套装 if nextProficiency.Type == comm.SmithyReelType4 { if rst, err := this.module.ModuleUser.GetUserExpand(session.GetUserId()); err == nil { rst.SuiteId = append(rst.SuiteId, nextProficiency.Value1) update := make(map[string]interface{}, 0) update["suiteId"] = rst.SuiteId this.module.ModuleUser.ChangeUserExpand(session.GetUserId(), update) } } } if code = this.module.ConsumeRes(session, costRes, true); code != pb.ErrorCode_Success { return } // 装备资源分发 if customLv > 0 { // sz := make([]int32, 4) // 最高 4个品质 // 获得极品权重 sz[3] = this.module.modelStove.StoveToolsQualityProbability(stove) if equip, code1 := this.module.ModuleEquipment.GetForgeEquip(session, req.SuiteId, req.Position, customLv, sz); code1 != pb.ErrorCode_Success { rsp.Equip = append(rsp.Equip, equip) return } } else { res := this.module.configure.GetDropReward(reelcfg.BasicDrop) if err, atno := this.module.DispenseAtno(session, res, true); err == pb.ErrorCode_Success { for _, v := range atno { if eq, err1 := this.module.ModuleEquipment.QueryEquipment(session.GetUserId(), v.O); err1 == pb.ErrorCode_Success { rsp.Equip = append(rsp.Equip, eq) } } } } stove.RecoveTime = configure.Now().Unix() update["data"] = stove.Data update["recoveTime"] = stove.RecoveTime update["forge"] = stove.Forge // 打造次数 this.module.modelStove.updateSmithyStove(session.GetUserId(), update) rsp.Data = stove session.SendMsg(string(this.module.GetType()), "forgeequip", rsp) return }