This commit is contained in:
meixiongfeng 2023-03-24 18:28:45 +08:00
commit cf59f160d4
4 changed files with 112 additions and 77 deletions

View File

@ -46,8 +46,8 @@ func (this *configureComp) getDispatchLvConf(lv int32) (data *cfg.GameDispatch_L
return
}
//任务配置
func(this *configureComp) getDispatchTaskConf(taskId int32) (data *cfg.GameDispatch_TaskData,err error) {
// 任务配置
func (this *configureComp) getDispatchTaskConf(taskId int32) (data *cfg.GameDispatch_TaskData, err error) {
var v interface{}
if v, err = this.GetConfigure(gameDispatchTask); err != nil {
@ -82,3 +82,25 @@ func (this *configureComp) getDispatchListConf() (list []*cfg.GameDispatch_TaskD
}
return
}
func (this *configureComp) getDispatchTaskConfByType(typeId int32) (list []*cfg.GameDispatch_TaskData, err error) {
var v interface{}
if v, err = this.GetConfigure(gameDispatchTask); err != nil {
err = fmt.Errorf("%T no is *cfg.GameDispatchTask", v)
return
} else {
d, ok := v.(*cfg.GameDispatch_Task)
if !ok {
err = fmt.Errorf("%T is not *cfg.GameDispatchTask", v)
return
}
for _, v := range d.GetDataList() {
if v.Type == typeId {
list = append(list, v)
}
}
}
return
}

View File

@ -79,7 +79,7 @@ func (this *modelDispatch) getDBDispatch(uid string) (dis *pb.DBDispatch) {
}
// 获取任务权重数据
func (this *modelDispatch) getTasksWeight(uid string, noticeLv int32) []int32 {
func (this *modelDispatch) getTasksWeight(uid string, d *pb.DBDispatch) []int32 {
dispatch := this.getDBDispatch(uid)
if dispatch == nil {
return []int32{}
@ -89,7 +89,7 @@ func (this *modelDispatch) getTasksWeight(uid string, noticeLv int32) []int32 {
return []int32{}
}
conf, err := this.module.configure.getDispatchLvConf(noticeLv)
conf, err := this.module.configure.getDispatchLvConf(d.Nb.Lv)
if err != nil || conf == nil {
this.module.Error("配置不存在", log.Field{Key: "error", Value: err})
return []int32{}
@ -101,19 +101,33 @@ func (this *modelDispatch) getTasksWeight(uid string, noticeLv int32) []int32 {
}
wr := comm.NewWeightedRandom(items)
//任务类型
//根据权重选出任务类型
var taskType int
if c := wr.Pick(); c != nil {
taskType = c.Id.(int)
}
confList := this.module.configure.getDispatchListConf()
confList, err := this.module.configure.getDispatchTaskConfByType(int32(taskType))
var tIds []int32
if len(d.Nb.Tasks) == 0 {
for _, v := range confList {
if int(v.Type) == taskType {
tIds = append(tIds, v.Id)
}
}
} else {
var existIds []int32
for _, v := range d.Nb.Tasks {
existIds = append(existIds, v.TaskId)
}
for _, v := range confList {
if int(v.Type) == taskType {
if _, ok := utils.Findx(existIds, v.Id); !ok {
tIds = append(tIds, v.Id)
}
}
}
}
return tIds
}
@ -124,29 +138,33 @@ func (this *modelDispatch) taskRandom(uid string, dispatch *pb.DBDispatch) (task
dispatch.Nb.Lv = 1
}
conf, err := this.module.configure.getDispatchLvConf(dispatch.Nb.Lv)
if err != nil || conf == nil {
return nil, err
}
// conf, err := this.module.configure.getDispatchLvConf(dispatch.Nb.Lv)
// if err != nil || conf == nil {
// return nil, err
// }
var items []*comm.WeightItem
for i, v := range conf.Probability {
items = append(items, &comm.WeightItem{Id: (i + 1), Weight: int(v)})
}
// var items []*comm.WeightItem
// for i, v := range conf.Probability {
// items = append(items, &comm.WeightItem{Id: (i + 1), Weight: int(v)})
// }
wr := comm.NewWeightedRandom(items)
//任务类型
var taskType int
if c := wr.Pick(); c != nil {
taskType = c.Id.(int)
}
// wr := comm.NewWeightedRandom(items)
// //任务类型
// var taskType int
// if c := wr.Pick(); c != nil {
// taskType = c.Id.(int)
// }
confList := this.module.configure.getDispatchListConf()
var tIds []int32
for _, v := range confList {
if int(v.Type) == taskType {
tIds = append(tIds, v.Id)
}
// confList := this.module.configure.getDispatchListConf()
// var tIds []int32
// for _, v := range confList {
// if int(v.Type) == taskType {
// tIds = append(tIds, v.Id)
// }
// }
tIds := this.getTasksWeight(uid, dispatch)
if len(tIds) == 0 {
return
}
//判断随机数量
@ -181,40 +199,44 @@ func (this *modelDispatch) taskRandom(uid string, dispatch *pb.DBDispatch) (task
}
}
//追加随机
for i := 0; i < randCount; i++ {
task := this.addRandomTask(uid, dispatch)
if task != nil {
tasks = append(tasks, task)
}
}
tasks = this.addRandomTask(uid, dispatch, randCount)
}
return
}
func (this *modelDispatch) addRandomTask(uid string, dispatch *pb.DBDispatch) *pb.DispatchTask {
randomTaskIds := this.getTasksWeight(uid, dispatch.Nb.Lv)
func (this *modelDispatch) addRandomTask(uid string, dispatch *pb.DBDispatch, n int) (tasks []*pb.DispatchTask) {
if n <= 0 {
tasks = dispatch.Nb.Tasks
return
}
randomTaskIds := this.getTasksWeight(uid, dispatch)
if len(randomTaskIds) == 0 {
return nil
}
//追加一条随机任务
ids := utils.RandomNumbers(1, len(randomTaskIds), 1)
//追加n条随机任务
ids := utils.RandomNumbers(1, len(randomTaskIds), n)
if len(ids) <= 0 {
return nil
}
taskId := ids[0]
taskConf, err := this.module.configure.getDispatchTaskConf(int32(taskId))
for _, id := range ids {
taskConf, err := this.module.configure.getDispatchTaskConf(int32(id))
if err != nil {
return nil
}
//公告持续截至时间
duration := configure.Now().Unix() + int64(taskConf.Taskcd)
return &pb.DispatchTask{
TaskId: int32(taskId),
dt := &pb.DispatchTask{
TaskId: int32(id),
Duration: duration,
}
tasks = append(tasks, dt)
}
return
}
// 替换指定的已完成任务
@ -235,12 +257,9 @@ func (this *modelDispatch) replaceTask(uid string, taskId int32, dispatch *pb.DB
break
}
}
if randCount > 0 {
task := this.addRandomTask(uid, dispatch)
if task != nil {
tasks = append(tasks, task)
}
}
tasks = this.addRandomTask(uid, dispatch, randCount)
return
}
@ -261,12 +280,7 @@ func (this *modelDispatch) replaceFinishedTask(uid string, dispatch *pb.DBDispat
}
}
for i := 0; i < randCount; i++ {
task := this.addRandomTask(uid, dispatch)
if task != nil {
tasks = append(tasks, task)
}
}
tasks = this.addRandomTask(uid, dispatch, randCount)
return
}
@ -433,12 +447,8 @@ func (this *modelDispatch) updateNotice(uid string, dispatch *pb.DBDispatch) err
if count < 6 {
randCount = 6 - count
}
for i := 0; i < randCount; i++ {
task := this.addRandomTask(uid, dispatch)
if task != nil {
dispatch.Nb.Tasks = append(dispatch.Nb.Tasks, task)
}
}
dispatch.Nb.Tasks = this.addRandomTask(uid, dispatch, randCount)
//判断是否有下一等级
nextConf, err := this.module.configure.getDispatchLvConf(dispatch.Nb.Lv + 1)

View File

@ -330,8 +330,7 @@ func (this *Agent) messageDistribution(msg *pb.UserMessage) (err error) {
}
stime := time.Now()
// this.gateway.Debugf("----------3 agent:%s uId:%s MainType:%s SubType:%s ", this.sessionId, this.uId, msg.MainType, msg.SubType)
// ctx, _ := context.WithTimeout(context.Background(), time.Second*5)
ctx:=context.Background()
ctx, _ := context.WithTimeout(context.Background(), time.Second*5)
if len(serviceTag) == 0 {
// this.gateway.Debugf("----------4 agent:%s uId:%s MainType:%s SubType:%s ", this.sessionId, this.uId, msg.MainType, msg.SubType)
if err = this.gateway.Service().RpcCall(ctx, servicePath, string(comm.Rpc_GatewayRoute), req, reply); err != nil {

View File

@ -2,6 +2,7 @@ package practice
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/pb"
"go_dreamfactory/sys/configure"
cfg "go_dreamfactory/sys/configure/structs"
@ -101,18 +102,19 @@ func (this *apiComp) Receive(session comm.IUserSession, req *pb.PracticeReceiveR
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, code := this.module.ModuleHero.GetHeroByObjID(session.GetUserId(), pillar.Hero); code == pb.ErrorCode_Success {
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))) * 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})
}
}
}
@ -126,6 +128,7 @@ func (this *apiComp) Receive(session comm.IUserSession, req *pb.PracticeReceiveR
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)
@ -167,6 +170,7 @@ func (this *apiComp) Receive(session comm.IUserSession, req *pb.PracticeReceiveR
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)
@ -205,7 +209,7 @@ func (this *apiComp) Receive(session comm.IUserSession, req *pb.PracticeReceiveR
}
}
}
this.module.Debug("最终经验加成", log.Field{Key: "exp", Value: exp}, log.Field{Key: "exp1", Value: exp1})
if _, code = this.module.ModuleHero.AddHeroExp(session, pillar.Hero, exp1); code != pb.ErrorCode_Success {
return
}