package practice import ( "go_dreamfactory/comm" "go_dreamfactory/pb" "go_dreamfactory/sys/configure" cfg "go_dreamfactory/sys/configure/structs" "math" "math/rand" "time" ) // 参数校验 func (this *apiComp) ExpulsionCheck(session comm.IUserSession, req *pb.PracticeExpulsionReq) (errdata *pb.ErrorData) { return } // /练功请求 驱逐 func (this *apiComp) Expulsion(session comm.IUserSession, req *pb.PracticeExpulsionReq) (errdata *pb.ErrorData) { var ( err error ok bool room *pb.DBPracticeRoom froom *pb.DBPracticeRoom pillar *pb.DBPracticePillar pillarconfigure *cfg.GamePandamasMzData tconfigure *cfg.GamePandamasJxData pconfigure *cfg.GamePandamasJxData _session comm.IUserSession minutes int32 filed string exp int32 exp1 int32 ants1 []*cfg.Gameatn ants2 []*cfg.Gameatn ) if room, err = this.module.modelPandata.queryUserMartialhall(session.GetUserId()); err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_DBError, Title: pb.ErrorCode_DBError.ToString(), Message: err.Error(), } return } pillar = room.Pillarf filed = "pillarf" if froom, err = this.module.modelPandata.queryUserMartialhall(pillar.Uid); err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_DBError, Title: pb.ErrorCode_DBError.ToString(), Message: err.Error(), } return } if pillarconfigure, err = this.module.configure.getGamePandamasMz(pillar.Lv); err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ConfigNoFound, Title: pb.ErrorCode_ConfigNoFound.ToString(), Message: err.Error(), } return } if pillar.Teacher != "" { if tconfigure, err = this.module.configure.getGamePandamasJx(pillar.Teacher); err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ConfigNoFound, Title: pb.ErrorCode_ConfigNoFound.ToString(), Message: err.Error(), } return } } if pillar.Prop != "" { if pconfigure, err = this.module.configure.getGamePandamasJx(pillar.Prop); err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ConfigNoFound, Title: pb.ErrorCode_ConfigNoFound.ToString(), Message: err.Error(), } return } } //计算经验收益 if configure.Now().After(time.Unix(pillar.Expend, 0)) { minutes = int32(time.Unix(pillar.Expend, 0).Sub(time.Unix(pillar.Start, 0)).Minutes()) exp = minutes * pillarconfigure.MinExp } else { minutes = int32(configure.Now().Sub(time.Unix(pillar.Start, 0)).Minutes()) exp = minutes * pillarconfigure.MinExp } exp1 += exp //满级英雄加成 for k, v := range froom.Full { if v > 0 { if conf, err := this.module.configure.getGamePandamasYxjx(k); err != nil { this.module.Errorln(err) } else if v/conf.Register > 0 { if hero, errdata := this.module.ModuleHero.GetHeroByObjID(session.GetUserId(), pillar.Hero); errdata == nil { if heroconf, _ := this.module.configure.GetHeroConfig(hero.HeroID); heroconf != nil { if (conf.Camp == 0 || (conf.Camp != 0 && heroconf.Race == conf.Camp)) && (conf.Occupation == 0 || (conf.Occupation != 0 && heroconf.Job == conf.Occupation)) { exp1 += minutes * int32(math.Floor(float64(v/conf.Register)*float64(conf.ExpBonus))) * exp } } } } } } //是否可以获得额外收益 if configure.Now().After(time.Unix(pillar.End, 0)) { if tconfigure != nil { if tconfigure.Exp > 0 { //经验加成 exp1 += int32(math.Floor(float64(exp) * (float64(tconfigure.Exp) / float64(100)))) } if len(tconfigure.Ants) > 0 { //额外道具加成 ants1 = make([]*cfg.Gameatn, 0) r := rand.New(rand.NewSource(time.Now().Unix())) num := r.Int31n(tconfigure.Num[1]-tconfigure.Num[0]) + tconfigure.Num[0] if r.Int31n(100) < tconfigure.Probability { //随机一个道具 total := 0 for _, v := range tconfigure.Wget { total += int(v) } n := rand.Intn(total) for i, v := range tconfigure.Wget { if int32(n) <= v { ants1 = append(ants1, &cfg.Gameatn{ A: tconfigure.Ants[i].A, T: tconfigure.Ants[i].T, N: num, }) break } } } else { //全部要 for _, v := range tconfigure.Ants { ants1 = append(ants1, &cfg.Gameatn{ A: v.A, T: v.T, N: 0, }) } for i := int32(0); i < num; i++ { index := i % int32(len(ants1)) ants1[index].N++ } } } } if pconfigure != nil { if pconfigure.Exp > 0 { //经验加成 exp1 += int32(math.Floor(float64(exp) * (float64(pconfigure.Exp) / float64(100)))) } if len(pconfigure.Ants) > 0 { //额外道具加成 ants2 = make([]*cfg.Gameatn, 0) r := rand.New(rand.NewSource(time.Now().Unix())) num := r.Int31n(pconfigure.Num[1]-pconfigure.Num[0]) + pconfigure.Num[0] if r.Int31n(100) < pconfigure.Probability { //随机一个道具 total := 0 for _, v := range pconfigure.Wget { total += int(v) } n := rand.Intn(total) for i, v := range pconfigure.Wget { if int32(n) <= v { ants2 = append(ants2, &cfg.Gameatn{ A: pconfigure.Ants[i].A, T: pconfigure.Ants[i].T, N: num, }) break } } } else { //全部要 for _, v := range pconfigure.Ants { ants2 = append(ants2, &cfg.Gameatn{ A: v.A, T: v.T, N: 0, }) } for i := int32(0); i < num; i++ { index := i % int32(len(ants2)) ants2[index].N++ } } } } } _session, ok = this.module.GetUserSession(pillar.Uid) if _, errdata = this.module.ModuleHero.AddHeroExp(_session, []string{pillar.Hero}, exp); errdata != nil { return } if errdata = this.module.ModuleHero.KungFuHero(_session, pillar.Hero, false, ""); errdata != nil { return } res := make([]*pb.UserAssets, 0) for _, v := range ants1 { res = append(res, &pb.UserAssets{ A: v.A, T: v.T, N: v.N, }) } for _, v := range ants2 { res = append(res, &pb.UserAssets{ A: v.A, T: v.T, N: v.N, }) } this.module.mail.SendNewMail(&pb.DBMailData{ Cid: "Drivethemail", CreateTime: uint64(configure.Now().Unix()), Items: res, }, pillar.Uid) // } froom.Knapsack[pillar.Teacher].State = 0 froom.Knapsack[pillar.Prop].State = 0 pillar.Hero = "" pillar.Teacher = "" pillar.Prop = "" pillar.Start = 0 pillar.End = 0 pillar.Expend = 0 this.module.modelPandata.Change(session.GetUserId(), map[string]interface{}{ filed: pillar, }) this.module.modelPandata.Change(pillar.Uid, map[string]interface{}{ "knapsack": froom.Knapsack, }) if ok { //在线直接推送消息 _session.SendMsg(string(this.module.GetType()), "beexpulsion", &pb.PracticeBeExpulsionPush{Fuid: session.GetUserId(), Pillar: pillar, Knapsack: froom.Knapsack}) if err = _session.Push(); err != nil { this.module.Errorln(err) } this.module.PutUserSession(_session) } session.SendMsg(string(this.module.GetType()), "expulsion", &pb.PracticeExpulsionResp{Pillar: pillar, Knapsack: froom.Knapsack}) return }