284 lines
8.5 KiB
Go
284 lines
8.5 KiB
Go
package practice
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/sys/configure"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
"math"
|
|
"math/rand"
|
|
"time"
|
|
)
|
|
|
|
// 参数校验
|
|
func (this *apiComp) ReceiveCheck(session comm.IUserSession, req *pb.PracticeReceiveReq) (errdata *pb.ErrorData) {
|
|
|
|
return
|
|
}
|
|
|
|
// /练功请求 奖励
|
|
func (this *apiComp) Receive(session comm.IUserSession, req *pb.PracticeReceiveReq) (errdata *pb.ErrorData) {
|
|
|
|
var (
|
|
err error
|
|
room *pb.DBPracticeRoom
|
|
froom *pb.DBPracticeRoom
|
|
pillar *pb.DBPracticePillar
|
|
pillarconfigure *cfg.GamePandamasMzData
|
|
tconfigure *cfg.GamePandamasJxData
|
|
pconfigure *cfg.GamePandamasJxData
|
|
minutes int32
|
|
filed string
|
|
exp int32
|
|
exp1 int32
|
|
ants1 []*cfg.Gameatn
|
|
ants2 []*cfg.Gameatn
|
|
)
|
|
if req.Friend != "" {
|
|
if froom, err = this.module.modelPandata.queryUserMartialhall(req.Friend); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
pillar = froom.Pillarf
|
|
filed = "pillarf"
|
|
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
|
|
}
|
|
} else {
|
|
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
|
|
}
|
|
switch req.Index {
|
|
case 1:
|
|
pillar = room.Pillar1
|
|
filed = "pillar1"
|
|
break
|
|
case 2:
|
|
pillar = room.Pillar2
|
|
filed = "pillar2"
|
|
break
|
|
case 3:
|
|
pillar = room.Pillar3
|
|
filed = "pillar3"
|
|
break
|
|
}
|
|
}
|
|
if pillar == nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
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 errdata = this.module.ModuleHero.KungFuHero(session, pillar.Hero, false, ""); errdata != nil {
|
|
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
|
|
this.module.Debug("基础经验加成", log.Field{Key: "minutes", Value: minutes}, log.Field{Key: "minExp", Value: pillarconfigure.MinExp}, log.Field{Key: "exp1", Value: exp1})
|
|
//满级英雄加成
|
|
for k, v := range room.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, err := this.module.ModuleHero.QueryCrossHeroinfo(pillar.Hero); err == 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 += int32(math.Floor(float64(v/conf.Register) * float64(conf.ExpBonus) / float64(100) * float64(exp)))
|
|
exp1 += minutes * int32(math.Floor(float64(v/conf.Register)*float64(conf.ExpBonus)))
|
|
this.module.Debug("满级英雄加成", log.Field{Key: "num", Value: v}, log.Field{Key: "Register", Value: conf.Register}, log.Field{Key: "exp1", Value: exp1})
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
//是否可以获得额外收益
|
|
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))))
|
|
this.module.Debug("教习经验加成", log.Field{Key: "exp", Value: exp}, log.Field{Key: "tcExp", Value: tconfigure.Exp}, log.Field{Key: "exp1", Value: exp1})
|
|
}
|
|
if len(tconfigure.Ants) > 0 { //额外道具加成
|
|
ants1 = make([]*cfg.Gameatn, 0)
|
|
r := rand.New(rand.NewSource(time.Now().Unix()))
|
|
interval := tconfigure.Num[1] - tconfigure.Num[0]
|
|
num := tconfigure.Num[0]
|
|
if interval > 0 {
|
|
num = r.Int31n(interval) + 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))))
|
|
this.module.Debug("道具经验加成", log.Field{Key: "exp", Value: exp}, log.Field{Key: "tcExp", Value: pconfigure.Exp}, log.Field{Key: "exp1", Value: exp1})
|
|
}
|
|
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++
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
this.module.Debug("最终经验加成", log.Field{Key: "exp", Value: exp}, log.Field{Key: "exp1", Value: exp1})
|
|
if _, errdata = this.module.ModuleHero.AddHeroExp(session, pillar.Hero, exp1); errdata != nil {
|
|
return
|
|
}
|
|
if errdata = this.module.DispenseRes(session, append(ants1, ants2...), true); errdata != nil {
|
|
return
|
|
}
|
|
room.Knapsack[pillar.Teacher].State = 0
|
|
room.Knapsack[pillar.Prop].State = 0
|
|
pillar.Hero = ""
|
|
pillar.Teacher = ""
|
|
pillar.Prop = ""
|
|
pillar.Start = 0
|
|
pillar.End = 0
|
|
pillar.Expend = 0
|
|
if req.Friend == "" {
|
|
this.module.modelPandata.Change(session.GetUserId(), map[string]interface{}{
|
|
"knapsack": room.Knapsack,
|
|
filed: pillar,
|
|
})
|
|
} else {
|
|
this.module.modelPandata.Change(session.GetUserId(), map[string]interface{}{
|
|
"knapsack": room.Knapsack,
|
|
})
|
|
this.module.modelPandata.Change(req.Friend, map[string]interface{}{
|
|
filed: pillar,
|
|
})
|
|
|
|
if _session, ok := this.module.GetUserSession(req.Friend); ok {
|
|
_session.SendMsg(string(this.module.GetType()), "rommchange", &pb.PracticeRommChangePush{Info: froom})
|
|
|
|
if err = _session.Push(); err != nil {
|
|
this.module.Errorln(err)
|
|
}
|
|
this.module.PutUserSession(_session)
|
|
} else {
|
|
this.module.PutUserSession(_session)
|
|
}
|
|
}
|
|
go this.module.ModuleBuried.TriggerBuried(session.GetUserId(), comm.GetBuriedParam(comm.Rtype135, minutes))
|
|
session.SendMsg(string(this.module.GetType()), "receive", &pb.PracticeReceiveResp{Pillar: pillar, Knapsack: room.Knapsack})
|
|
return
|
|
}
|