package items import ( "go_dreamfactory/comm" "go_dreamfactory/pb" cfg "go_dreamfactory/sys/configure/structs" ) //参数校验 func (this *apiComp) PotionSynthesisCheck(session comm.IUserSession, req *pb.ItemsPotionSynthesisReq) (errdata *pb.ErrorData) { return } //魔药合成 func (this *apiComp) PotionSynthesis(session comm.IUserSession, req *pb.ItemsPotionSynthesisReq) (errdata *pb.ErrorData) { var ( configure *cfg.GamePotionsData need []*cfg.Gameatn give []*cfg.Gameatn err error ) if configure, err = this.module.configure.GetMaterialConfigure(req.Id); err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ConfigNoFound, Title: pb.ErrorCode_ConfigNoFound.ToString(), Message: err.Error(), } return } need = make([]*cfg.Gameatn, len(configure.Material)) for i, v := range configure.Material { need[i] = &cfg.Gameatn{ A: v.A, T: v.T, N: v.N * req.Num, } } if errdata = this.module.ConsumeRes(session, need, true); errdata != nil { return } give = make([]*cfg.Gameatn, 0) if req.Succnum <= configure.NormalScore { for _, v := range configure.LowYield { give = append(give, &cfg.Gameatn{ A: v.A, T: v.T, N: v.N * req.Num, }) } } else if req.Succnum < configure.HighScore { for _, v := range configure.StandardYield { give = append(give, &cfg.Gameatn{ A: v.A, T: v.T, N: v.N * req.Num, }) } } else { for _, v := range configure.HighYield { give = append(give, &cfg.Gameatn{ A: v.A, T: v.T, N: v.N * req.Num, }) } } if errdata = this.module.DispenseRes(session, give, true); errdata != nil { return } session.SendMsg(string(this.module.GetType()), "potionsynthesis", &pb.ItemsPotionSynthesisResp{Succ: true, Id: req.Id, Num: req.Num}) go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) { this.module.WriteUserLog(session.GetUserId(), req, comm.GMResAddType, "ItemsPotionSynthesisReq", give) }) return }