go_dreamfactory/modules/practice/api_expulsion.go
2023-03-31 20:13:29 +08:00

239 lines
6.7 KiB
Go

package practice
import (
"go_dreamfactory/comm"
"go_dreamfactory/pb"
"go_dreamfactory/sys/configure"
cfg "go_dreamfactory/sys/configure/structs"
"math"
"math/rand"
"time"
"google.golang.org/protobuf/proto"
)
//参数校验
func (this *apiComp) ExpulsionCheck(session comm.IUserSession, req *pb.PracticeExpulsionReq) (code pb.ErrorCode) {
return
}
///练功请求 驱逐
func (this *apiComp) Expulsion(session comm.IUserSession, req *pb.PracticeExpulsionReq) (code pb.ErrorCode, data proto.Message) {
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 {
code = pb.ErrorCode_DBError
return
}
pillar = room.Pillarf
filed = "pillarf"
if froom, err = this.module.modelPandata.queryUserMartialhall(pillar.Uid); err != nil {
code = pb.ErrorCode_DBError
return
}
if pillarconfigure, err = this.module.configure.getGamePandamasMz(pillar.Lv); err != nil {
code = pb.ErrorCode_ConfigNoFound
return
}
if pillar.Teacher != "" {
if tconfigure, err = this.module.configure.getGamePandamasJx(pillar.Teacher); err != nil {
code = pb.ErrorCode_ConfigNoFound
return
}
}
if pillar.Prop != "" {
if pconfigure, err = this.module.configure.getGamePandamasJx(pillar.Prop); err != nil {
code = pb.ErrorCode_ConfigNoFound
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, code := this.module.ModuleHero.GetHeroByObjID(session.GetUserId(), pillar.Hero); code == pb.ErrorCode_Success {
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++
}
}
}
}
}
defer func() {
this.module.PutUserSession(_session)
}()
// if _session, ok = this.module.GetUserSession(pillar.Uid); ok {
// if _, code = this.module.ModuleHero.AddHeroExp(_session, pillar.Hero, exp); code != pb.ErrorCode_Success {
// return
// }
// if code = this.module.DispenseRes(_session, append(ants1, ants2...), true); code != pb.ErrorCode_Success {
// return
// }
// if code = this.module.ModuleHero.KungFuHero(_session, pillar.Hero, false, ""); code != pb.ErrorCode_Success {
// return
// }
// } else {
if _, code = this.module.ModuleHero.AddHeroExp(_session, pillar.Hero, exp); code != pb.ErrorCode_Success {
return
}
if code = this.module.ModuleHero.KungFuHero(_session, pillar.Hero, false, ""); code != pb.ErrorCode_Success {
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] = 0
froom.Knapsack[pillar.Prop] = 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,
})
session.SendMsg(string(this.module.GetType()), "expulsion", &pb.PracticeExpulsionResp{Pillar: pillar, Knapsack: froom.Knapsack})
return
}