更新随机任务战斗任务

This commit is contained in:
wh_zcy 2022-09-14 19:14:24 +08:00
parent 05fff27c2f
commit 6c8c6fba73
17 changed files with 369 additions and 75 deletions

View File

@ -0,0 +1,44 @@
package formview
import (
"go_dreamfactory/cmd/v2/model"
"go_dreamfactory/cmd/v2/service"
"go_dreamfactory/pb"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/widget"
"github.com/sirupsen/logrus"
"github.com/spf13/cast"
)
type HeroZhaomuView struct {
BaseformView
}
func (this *HeroZhaomuView) CreateView(t *model.TestCase) fyne.CanvasObject {
var ckType, ckCount string
// 抽卡类型 0 1 2 3 4
ckTypeSelect := widget.NewSelect([]string{"0", "1", "2", "3", "4"}, func(s string) {
ckType = s
})
//数量
ckCountSelect := widget.NewSelect([]string{"1", "10"}, func(s string) {
ckCount = s
})
this.form.AppendItem(widget.NewFormItem("抽卡类型", ckTypeSelect))
this.form.AppendItem(widget.NewFormItem("数量", ckCountSelect))
this.form.OnSubmit = func() {
if err := service.GetPttService().SendToClient(t.MainType, t.SubType,
&pb.HeroDrawCardReq{
DrawType: cast.ToInt32(ckType),
DrawCount: cast.ToInt32(ckCount),
}); err != nil {
logrus.Error(err)
}
}
return this.form
}

View File

@ -0,0 +1,33 @@
package formview
import (
"go_dreamfactory/cmd/v2/model"
"go_dreamfactory/cmd/v2/service"
"go_dreamfactory/pb"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/widget"
"github.com/sirupsen/logrus"
"github.com/spf13/cast"
)
type RtaskBattleFinishView struct {
BaseformView
}
func (this *RtaskBattleFinishView) CreateView(t *model.TestCase) fyne.CanvasObject {
taskId := widget.NewEntry()
this.form.AppendItem(widget.NewFormItem("任务ID", taskId))
this.form.OnSubmit = func() {
if err := service.GetPttService().SendToClient(t.MainType, t.SubType,
&pb.RtaskBattleFinishReq{
RtaskId: cast.ToInt32(taskId.Text),
}); err != nil {
logrus.Error(err)
}
}
return this.form
}

View File

@ -0,0 +1,43 @@
package formview
import (
"go_dreamfactory/cmd/v2/model"
"go_dreamfactory/cmd/v2/service"
"go_dreamfactory/pb"
"strings"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/widget"
"github.com/sirupsen/logrus"
"github.com/spf13/cast"
)
type RtaskBattlestartView struct {
BaseformView
}
func (this *RtaskBattlestartView) CreateView(t *model.TestCase) fyne.CanvasObject {
confId := widget.NewEntry()
leadpos := widget.NewEntry()
teamIds := widget.NewEntry()
teamIds.PlaceHolder = ",号分隔"
this.form.AppendItem(widget.NewFormItem("关卡ID", confId))
this.form.AppendItem(widget.NewFormItem("队长位置", leadpos))
this.form.AppendItem(widget.NewFormItem("阵容信息", teamIds))
this.form.OnSubmit = func() {
if err := service.GetPttService().SendToClient(t.MainType, t.SubType,
&pb.RtaskBattleStartReq{
BattleConfId: cast.ToInt32(confId.Text),
Leadpos: cast.ToInt32(leadpos.Text),
Teamids: strings.Split(teamIds.Text, ","),
}); err != nil {
logrus.Error(err)
}
}
return this.form
}

View File

@ -290,6 +290,7 @@ const (
Rtype67 TaskType = 67 //商店购物消耗xx货币xx个 Rtype67 TaskType = 67 //商店购物消耗xx货币xx个
Rtype68 TaskType = 68 //任意渠道消耗xx金币 Rtype68 TaskType = 68 //任意渠道消耗xx金币
Rtype69 TaskType = 69 //与其他玩家切磋xx次 Rtype69 TaskType = 69 //与其他玩家切磋xx次
Rtype70 TaskType = 70 //通关随机任务XX关卡
) )
const ( const (

View File

@ -202,11 +202,11 @@ func (this *apiComp) DrawCard(session comm.IUserSession, req *pb.HeroDrawCardReq
this.module.ModuleRtask.SendToRtask(session, comm.Rtype17, k, v) this.module.ModuleRtask.SendToRtask(session, comm.Rtype17, k, v)
} }
} }
this.module.ModuleRtask.SendToRtask(session, comm.Rtype14, drawCount) this.module.ModuleRtask.SendToRtask(session, comm.Rtype14, req.DrawCount)
this.module.ModuleRtask.SendToRtask(session, comm.Rtype18, drawCount) this.module.ModuleRtask.SendToRtask(session, comm.Rtype18, req.DrawCount)
} else { // 阵营招募 } else { // 阵营招募
this.module.ModuleRtask.SendToRtask(session, comm.Rtype15, drawCount) this.module.ModuleRtask.SendToRtask(session, comm.Rtype15, req.DrawCount)
this.module.ModuleRtask.SendToRtask(session, comm.Rtype19, drawCount) this.module.ModuleRtask.SendToRtask(session, comm.Rtype19, req.DrawCount)
} }
for _, star := range szStar { for _, star := range szStar {
this.module.ModuleRtask.SendToRtask(session, comm.Rtype16, star, 1) this.module.ModuleRtask.SendToRtask(session, comm.Rtype16, star, 1)

View File

@ -10,6 +10,8 @@ const (
RtaskSubTypeList = "list" //随机任务列表 RtaskSubTypeList = "list" //随机任务列表
RtaskSubTypeApply = "apply" //做任务 RtaskSubTypeApply = "apply" //做任务
RtaskSubTypeReward = "getreward" //奖励 RtaskSubTypeReward = "getreward" //奖励
RtaskSubTypeBattleStart = "battlestart" //战斗开始
RtaskSubTypeBattleFinish = "battlefinish" //战斗完成
) )
type apiComp struct { type apiComp struct {

View File

@ -0,0 +1,85 @@
package rtask
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/pb"
"google.golang.org/protobuf/proto"
)
func (this *apiComp) BattleFinishCheck(session comm.IUserSession, req *pb.RtaskBattleFinishReq) (code pb.ErrorCode) {
if req.RtaskId == 0 {
code = pb.ErrorCode_ReqParameterError
}
return
}
func (this *apiComp) BattleFinish(session comm.IUserSession, req *pb.RtaskBattleFinishReq) (code pb.ErrorCode, data proto.Message) {
if code = this.BattleFinishCheck(session, req); code != pb.ErrorCode_Success {
return
}
//校验战斗结果
iBattle, err := this.moduleRtask.modelRtask.service.GetModule(comm.ModuleBattle)
if err != nil {
code = pb.ErrorCode_SystemError
return
}
var isWin bool
if b, y := iBattle.(comm.IBattle); y {
if code, isWin = b.CheckBattleReport(session, req.Report); code != pb.ErrorCode_Success {
return
}
if isWin {
// 获取玩家的任务
rtask := &pb.DBRtask{}
if err := this.moduleRtask.modelRtask.Get(session.GetUserId(), rtask); err != nil {
return
}
// 获取当前任务配置
conf := this.moduleRtask.configure.getRtaskById(req.RtaskId)
if conf == nil {
code = pb.ErrorCode_ConfigNoFound
log.Errorf("rdtask %v no found", req.RtaskId)
return
}
var (
frtaskArr *pb.FrtaskIds //完成的任务
ok bool
)
if frtaskArr, ok = rtask.FrtaskIds[conf.Group]; !ok {
frtaskArr = &pb.FrtaskIds{}
}
// 更新完成的任务
frtaskArr.RtaskIds = append(frtaskArr.RtaskIds, req.RtaskId)
if rtask.FrtaskIds == nil {
rtask.FrtaskIds = make(map[int32]*pb.FrtaskIds)
}
rtask.FrtaskIds[conf.Group] = frtaskArr
update := map[string]interface{}{
"frtaskIds": rtask.FrtaskIds,
}
if err := this.moduleRtask.modelRtask.Change(session.GetUserId(), update); err != nil {
code = pb.ErrorCode_SystemError
return
}
}
}
if err := session.SendMsg(string(this.moduleRtask.GetType()), RtaskSubTypeBattleFinish,
&pb.RtaskBattleFinishResp{
RtaskId: req.RtaskId,
IsWin: isWin,
}); err != nil {
code = pb.ErrorCode_SystemError
}
return
}

View File

@ -0,0 +1,71 @@
package rtask
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/pb"
"google.golang.org/protobuf/proto"
)
func (this *apiComp) BattleStartCheck(session comm.IUserSession, req *pb.RtaskBattleStartReq) (code pb.ErrorCode) {
if req.BattleConfId == 0 {
code = pb.ErrorCode_ReqParameterError
}
return
}
func (this *apiComp) BattleStart(session comm.IUserSession, req *pb.RtaskBattleStartReq) (code pb.ErrorCode, data proto.Message) {
if code = this.BattleStartCheck(session, req); code != pb.ErrorCode_Success {
return
}
battleConf := this.moduleRtask.configure.getRtaskBattleById(req.BattleConfId)
if battleConf == nil {
code = pb.ErrorCode_ConfigNoFound
log.Errorf("rdtask_battle %v no found", req.BattleConfId)
return
}
iBattle, err := this.moduleRtask.modelRtask.service.GetModule(comm.ModuleBattle)
if err != nil {
code = pb.ErrorCode_SystemError
return
}
if b, y := iBattle.(comm.IBattle); y {
var (
record *pb.DBBattleRecord
resp *pb.RtaskBattleStartResp
)
code, record = b.CreatePveBattle(session, &pb.BattlePVEReq{
Ptype: pb.PlayType_mainline,
Leadpos: req.Leadpos,
Teamids: req.Teamids,
Mformat: battleConf.FormatList,
})
if code != pb.ErrorCode_Success {
return
}
if record != nil {
resp = &pb.RtaskBattleStartResp{
Info: &pb.BattleInfo{
Id: record.Id,
Btype: record.Btype,
Ptype: record.Ptype,
RedCompId: record.RedCompId,
Redflist: record.Redflist,
BlueCompId: record.BlueCompId,
Buleflist: record.Buleflist,
},
}
}
if err := session.SendMsg(string(this.moduleRtask.GetType()), RtaskSubTypeBattleStart, resp); err != nil {
code = pb.ErrorCode_SystemError
}
}
return
}

View File

@ -2,6 +2,7 @@ package rtask
import ( import (
"go_dreamfactory/comm" "go_dreamfactory/comm"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/pb" "go_dreamfactory/pb"
"go_dreamfactory/utils" "go_dreamfactory/utils"
@ -20,6 +21,7 @@ func (this *apiComp) Choose(session comm.IUserSession, req *pb.RtaskChooseReq) (
return return
} }
// 获取玩家的任务
rtask := &pb.DBRtask{} rtask := &pb.DBRtask{}
if err := this.moduleRtask.modelRtask.Get(session.GetUserId(), rtask); err != nil { if err := this.moduleRtask.modelRtask.Get(session.GetUserId(), rtask); err != nil {
return return
@ -29,6 +31,7 @@ func (this *apiComp) Choose(session comm.IUserSession, req *pb.RtaskChooseReq) (
conf := this.moduleRtask.configure.getRtaskById(req.RtaskId) conf := this.moduleRtask.configure.getRtaskById(req.RtaskId)
if conf == nil { if conf == nil {
code = pb.ErrorCode_ConfigNoFound code = pb.ErrorCode_ConfigNoFound
log.Errorf("rdtask %v no found", req.RtaskId)
return return
} }
@ -36,6 +39,7 @@ func (this *apiComp) Choose(session comm.IUserSession, req *pb.RtaskChooseReq) (
sideConf := this.moduleRtask.configure.getRtaskSidById(req.RtaskSubId) sideConf := this.moduleRtask.configure.getRtaskSidById(req.RtaskSubId)
if sideConf == nil { if sideConf == nil {
code = pb.ErrorCode_ConfigNoFound code = pb.ErrorCode_ConfigNoFound
log.Errorf("rdtask_side %v no found", req.RtaskSubId)
return return
} }
@ -43,6 +47,7 @@ func (this *apiComp) Choose(session comm.IUserSession, req *pb.RtaskChooseReq) (
chooseCnf := this.moduleRtask.configure.getRtaskChooseCfg(req.ChooseId) chooseCnf := this.moduleRtask.configure.getRtaskChooseCfg(req.ChooseId)
if chooseCnf == nil { if chooseCnf == nil {
code = pb.ErrorCode_ConfigNoFound code = pb.ErrorCode_ConfigNoFound
log.Errorf("rdtask_choose %v no found", req.ChooseId)
return return
} }
@ -54,7 +59,7 @@ func (this *apiComp) Choose(session comm.IUserSession, req *pb.RtaskChooseReq) (
} }
var ( var (
frtaskArr *pb.FrtaskIds frtaskArr *pb.FrtaskIds //完成的任务
ok bool ok bool
) )
@ -68,6 +73,7 @@ func (this *apiComp) Choose(session comm.IUserSession, req *pb.RtaskChooseReq) (
return return
} }
if chooseCnf.GotoLevel == "" {
// 更新完成的任务 // 更新完成的任务
frtaskArr.RtaskIds = append(frtaskArr.RtaskIds, req.RtaskId) frtaskArr.RtaskIds = append(frtaskArr.RtaskIds, req.RtaskId)
if rtask.FrtaskIds == nil { if rtask.FrtaskIds == nil {
@ -79,6 +85,8 @@ func (this *apiComp) Choose(session comm.IUserSession, req *pb.RtaskChooseReq) (
} }
if err := this.moduleRtask.modelRtask.Change(session.GetUserId(), update); err != nil { if err := this.moduleRtask.modelRtask.Change(session.GetUserId(), update); err != nil {
code = pb.ErrorCode_SystemError code = pb.ErrorCode_SystemError
return
}
} }
rsp := &pb.RtaskChooseResp{ rsp := &pb.RtaskChooseResp{

View File

@ -2,6 +2,7 @@ package rtask
import ( import (
"go_dreamfactory/comm" "go_dreamfactory/comm"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/pb" "go_dreamfactory/pb"
"go_dreamfactory/utils" "go_dreamfactory/utils"
@ -30,6 +31,7 @@ func (this *apiComp) Apply(session comm.IUserSession, req *pb.RtaskApplyReq) (co
conf := this.moduleRtask.configure.getRtaskById(req.RtaskId) conf := this.moduleRtask.configure.getRtaskById(req.RtaskId)
if conf == nil { if conf == nil {
code = pb.ErrorCode_ConfigNoFound code = pb.ErrorCode_ConfigNoFound
log.Errorf("rdtask %v no found", req.RtaskId)
return return
} }
@ -60,6 +62,7 @@ func (this *apiComp) Apply(session comm.IUserSession, req *pb.RtaskApplyReq) (co
sideConf := this.moduleRtask.configure.getRtaskSidById(req.RtaskSubId) sideConf := this.moduleRtask.configure.getRtaskSidById(req.RtaskSubId)
if sideConf == nil { if sideConf == nil {
code = pb.ErrorCode_ConfigNoFound code = pb.ErrorCode_ConfigNoFound
log.Errorf("rdtask_side %v no found", req.RtaskSubId)
return return
} }

View File

@ -1,24 +0,0 @@
package rtask
import (
"go_dreamfactory/comm"
"go_dreamfactory/pb"
"google.golang.org/protobuf/proto"
)
func (this *apiComp) BattleFinishCheck(session comm.IUserSession, req *pb.RtaskBattleFinishReq) (code pb.ErrorCode) {
if req.Result == 0 {
code = pb.ErrorCode_ReqParameterError
}
return
}
func (this *apiComp) BattleFinish(session comm.IUserSession, req *pb.RtaskBattleFinishReq) (code pb.ErrorCode, data proto.Message) {
if code = this.BattleFinishCheck(session, req); code != pb.ErrorCode_Success {
return
}
return
}

View File

@ -2,6 +2,7 @@ package rtask
import ( import (
"go_dreamfactory/comm" "go_dreamfactory/comm"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/pb" "go_dreamfactory/pb"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
@ -18,16 +19,12 @@ func (this *apiComp) GetReward(session comm.IUserSession, req *pb.RtaskGetReward
if code = this.GetRewardCheck(session, req); code != pb.ErrorCode_Success { if code = this.GetRewardCheck(session, req); code != pb.ErrorCode_Success {
return return
} }
// conf := this.moduleRtask.configure.getRtaskById(req.RtaskId)
// if conf == nil {
// code = pb.ErrorCode_ConfigNoFound
// return
// }
// 获取支线任务配置 // 获取支线任务配置
sideConf := this.moduleRtask.configure.getRtaskSidById(req.RtaskSubId) sideConf := this.moduleRtask.configure.getRtaskSidById(req.RtaskSubId)
if sideConf == nil { if sideConf == nil {
code = pb.ErrorCode_ConfigNoFound code = pb.ErrorCode_ConfigNoFound
log.Errorf("rdtask_side %v no found", req.RtaskSubId)
return return
} }

View File

@ -124,5 +124,4 @@ func (this *ModelRtaskRecord) lessThanParams(cfg *cfg.GameRdtaskCondiData, vals
condiId = cfg.Id condiId = cfg.Id
return return
return
} }

View File

@ -149,16 +149,16 @@ func (this *ModuleRtask) initRtaskVerifyHandle() {
case comm.Rtype14: case comm.Rtype14:
this.registerVerifyHandle(v.Id, &rtaskCondi{ this.registerVerifyHandle(v.Id, &rtaskCondi{
cfg: typeCfg, cfg: typeCfg,
find: this.modelRtaskRecord.equalParams, find: this.modelRtaskRecord.lessThanParams,
verify: this.modelRtaskRecord.verifyFromDb, verify: this.modelRtaskRecord.verifyFromDb,
update: this.modelRtaskRecord.overrideUpdate, update: this.modelRtaskRecord.addUpdate,
}) })
case comm.Rtype15: case comm.Rtype15:
this.registerVerifyHandle(v.Id, &rtaskCondi{ this.registerVerifyHandle(v.Id, &rtaskCondi{
cfg: typeCfg, cfg: typeCfg,
find: this.modelRtaskRecord.equalParams, find: this.modelRtaskRecord.lessThanParams,
verify: this.modelRtaskRecord.verifyFromDb, verify: this.modelRtaskRecord.verifyFromDb,
update: this.modelRtaskRecord.overrideUpdate, update: this.modelRtaskRecord.addUpdate,
}) })
case comm.Rtype16: case comm.Rtype16:
this.registerVerifyHandle(v.Id, &rtaskCondi{ this.registerVerifyHandle(v.Id, &rtaskCondi{
@ -177,7 +177,7 @@ func (this *ModuleRtask) initRtaskVerifyHandle() {
case comm.Rtype18: case comm.Rtype18:
this.registerVerifyHandle(v.Id, &rtaskCondi{ this.registerVerifyHandle(v.Id, &rtaskCondi{
cfg: typeCfg, cfg: typeCfg,
find: this.modelRtaskRecord.equalParams, find: this.modelRtaskRecord.lessThanParams,
verify: this.modelRtaskRecord.verifyFromDb, verify: this.modelRtaskRecord.verifyFromDb,
update: this.modelRtaskRecord.overrideUpdate, update: this.modelRtaskRecord.overrideUpdate,
}) })
@ -534,7 +534,13 @@ func (this *ModuleRtask) initRtaskVerifyHandle() {
verify: this.modelRtaskRecord.verifyFromDb, verify: this.modelRtaskRecord.verifyFromDb,
update: this.modelRtaskRecord.overrideUpdate, update: this.modelRtaskRecord.overrideUpdate,
}) })
case comm.Rtype70:
this.registerVerifyHandle(v.Id, &rtaskCondi{
cfg: typeCfg,
find: this.modelRtaskRecord.equalParams,
verify: this.modelRtaskRecord.verifyFromDb,
update: this.modelRtaskRecord.overrideUpdate,
})
default: default:
log.Warnf("rtaskType[%v] not register", typeCfg.Type) log.Warnf("rtaskType[%v] not register", typeCfg.Type)
} }

View File

@ -85,6 +85,8 @@ func (this *ModelRtaskRecord) addUpdate(uid string, cfg *cfg.GameRdtaskCondiData
if record.Vals == nil { if record.Vals == nil {
data := &pb.RtaskData{ data := &pb.RtaskData{
Data: toMap(vals...), Data: toMap(vals...),
Rtype: cfg.Type,
Timestamp: time.Now().Unix(),
} }
record.Vals = map[int32]*pb.RtaskData{ record.Vals = map[int32]*pb.RtaskData{
@ -94,30 +96,34 @@ func (this *ModelRtaskRecord) addUpdate(uid string, cfg *cfg.GameRdtaskCondiData
return errors.Wrapf(err, "添加玩家任务记录 err: %v rtype[%v]", uid, cfg.Id) return errors.Wrapf(err, "添加玩家任务记录 err: %v rtype[%v]", uid, cfg.Id)
} }
} else { } else {
data := make(map[int32]int32)
//查找任务数据 //查找任务数据
if v, ok := record.Vals[cfg.Id]; ok { if v, ok := record.Vals[cfg.Id]; ok {
// 只有第一个参数为累加数值
if paramLen == 1 { if paramLen == 1 {
data[0] += v.Data[0] v.Data[0] += vals[0]
} else if paramLen == 2 { v.Timestamp = time.Now().Unix()
//第一个参数为累加,后续参数为判断条件
if data[1] == cfg.Data2 {
data[1] += v.Data[1]
} }
} else if paramLen == 3 {
if data[1] == cfg.Data2 && data[2] == cfg.Data3 {
data[2] += v.Data[2]
}
}
if len(data) > 0 {
update := map[string]interface{}{ update := map[string]interface{}{
"vals": data, "vals": record.Vals,
}
err = this.Change(uid, update)
} else {
data := map[int32]int32{
0: vals[0],
}
record.Vals[cfg.Id] = &pb.RtaskData{
Data: data,
Rtype: cfg.Type,
Timestamp: time.Now().Unix(),
}
update := map[string]interface{}{
"vals": record.Vals,
} }
err = this.Change(uid, update) err = this.Change(uid, update)
} }
}
} }
return return
} }

View File

@ -3,6 +3,7 @@ package user
import ( import (
"go_dreamfactory/comm" "go_dreamfactory/comm"
"go_dreamfactory/lego/core" "go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/modules" "go_dreamfactory/modules"
"go_dreamfactory/pb" "go_dreamfactory/pb"
) )
@ -17,6 +18,7 @@ func (this *ModelSession) Init(service core.IService, module core.IModule, comp
this.module = module.(*User) this.module = module.(*User)
this.TableName = comm.TableSession this.TableName = comm.TableSession
this.Expired = 0 //不自动过期 this.Expired = 0 //不自动过期
this.clean()
return return
} }
@ -29,3 +31,18 @@ func (this *ModelSession) getUserSession(uid string) (user *pb.CacheUser) {
} }
return user return user
} }
// 启动时清理session
func (this *ModelSession) clean() {
keys, err := this.Redis.Keys("session:*")
if err != nil {
log.Errorf("redis keys err:%v", err)
return
}
for _, k := range keys {
if err := this.Redis.Delete(k); err != nil {
log.Errorf("redis delete key err:%v", err)
}
}
}

View File

@ -33,8 +33,11 @@ func OnInit(config map[string]interface{}, option ...Option) (err error) {
return return
} }
defsys, err = newSys(options) defsys, err = newSys(options)
<<<<<<< HEAD
// defsys.Local().Redis.GetClient().FlushAll(context.TODO()) // defsys.Local().Redis.GetClient().FlushAll(context.TODO())
=======
>>>>>>> 5774dd3b (更新随机任务战斗任务)
return return
} }