移除丢弃的任务条件api和配置

This commit is contained in:
wh_zcy 2022-12-05 10:23:21 +08:00
parent 735aef83dd
commit 8323ea13ca
9 changed files with 0 additions and 627 deletions

View File

@ -167,12 +167,8 @@ type (
ChangeCondi(uid string, data map[int32]*pb.RtaskData) error
//任务触发
SendToRtask(session IUserSession, rtaskType TaskType, params ...int32) (code pb.ErrorCode)
// 初始化条件数据
InitCondiData(uid string) error
// 获取任务条件记录
GetCondiData(uid string) *pb.DBRtaskRecord
// bingo任务
BingoRtask(session IUserSession, groupId, rtaskId int32) error
}
//好友

View File

@ -1,98 +0,0 @@
package rtask
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/pb"
"go_dreamfactory/utils"
"google.golang.org/protobuf/proto"
)
// 做任务
func (this *apiComp) ApplyCheck(session comm.IUserSession, req *pb.RtaskApplyReq) (code pb.ErrorCode) {
if req.RtaskId == 0 || req.RtaskSubId == 0 {
code = pb.ErrorCode_ReqParameterError
}
return
}
func (this *apiComp) Apply(session comm.IUserSession, req *pb.RtaskApplyReq) (code pb.ErrorCode, data proto.Message) {
if code = this.ApplyCheck(session, req); code != pb.ErrorCode_Success {
return
}
// 获取当前玩家任务
rtask := this.moduleRtask.modelRtask.GetRtask(session.GetUserId())
if rtask == nil {
code = pb.ErrorCode_RtaskNoRtask
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{}
}
//验证该任务是否已完成
if _, ok := utils.Findx(frtaskArr.RtaskIds, req.RtaskId); ok {
code = pb.ErrorCode_RtaskFinished
return
}
sideConf := this.moduleRtask.configure.getRtaskSidById(req.RtaskSubId)
if sideConf == nil {
code = pb.ErrorCode_ConfigNoFound
log.Errorf("rdtask_side %v no found", req.RtaskSubId)
return
}
if len(sideConf.EndTid) == 0 {
code = pb.ErrorCode_ConfigurationException
return
}
// 没有设置选项,表示任务完成
if sideConf.EndTid[0] == -1 && len(sideConf.ChooseId) == 0 {
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 := this.moduleRtask.modelRtask.updateUserRtaskId(session.GetUserId(), req.RtaskId); err != nil {
this.moduleRtask.Errorf("update rtaskId err: %v", err)
}
}
if err := session.SendMsg(string(this.moduleRtask.GetType()), RtaskSubTypeApply, &pb.RtaskApplyResp{
RtaskId: req.RtaskId,
}); err != nil {
code = pb.ErrorCode_SystemError
}
return
}

View File

@ -1,123 +0,0 @@
package rtask
import (
"go_dreamfactory/comm"
"go_dreamfactory/pb"
"go_dreamfactory/utils"
"google.golang.org/protobuf/proto"
)
func (this *apiComp) BattleFinishCheck(session comm.IUserSession, req *pb.RtaskBattleFinishReq) (code pb.ErrorCode) {
if req.RtaskId == 0 || req.RtaskSubId == 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
}
this.moduleRtask.Debugf("随机任务请求 rtaskID:%v 完成 subtaskID:%v chooseID:%v", req.RtaskId, req.RtaskSubId, req.ChooseId)
// 获取当前任务配置
conf := this.moduleRtask.configure.getRtaskById(req.RtaskId)
if conf == nil {
code = pb.ErrorCode_ConfigNoFound
return
}
// 获取支线任务配置
sideConf := this.moduleRtask.configure.getRtaskSidById(req.RtaskSubId)
if sideConf == nil {
code = pb.ErrorCode_ConfigNoFound
return
}
// 获取玩家的任务
rtask := &pb.DBRtask{}
if err := this.moduleRtask.modelRtask.Get(session.GetUserId(), rtask); err != nil {
return
}
var (
frtaskArr *pb.FrtaskIds //完成的任务
ok bool
)
// 查找任务组
if frtaskArr, ok = rtask.FrtaskIds[conf.Group]; !ok {
frtaskArr = &pb.FrtaskIds{}
}
//验证该任务是否已完成
if _, ok := utils.Findx(frtaskArr.RtaskIds, req.RtaskId); ok {
code = pb.ErrorCode_RtaskFinished
return
}
// 校验完成条件
var checkCondi bool
for _, v := range sideConf.EndTid {
if err, ok := this.moduleRtask.modelRtask.checkCondi(session.GetUserId(), v); !ok {
if err != nil {
this.moduleRtask.Errorln(err.Error())
}
this.moduleRtask.Debugf("条件未达成 condiID:%v rtaskId:%v subRtaskId:%v chooseID:%v", v, req.RtaskId, req.RtaskSubId, req.ChooseId)
break
}
checkCondi = true
}
if !checkCondi {
code = pb.ErrorCode_RtaskCondiNoReach
return
}
// 更新完成的任务
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
}
// userexpand update
if err := this.moduleRtask.modelRtask.updateUserRtaskId(session.GetUserId(), req.RtaskId); err != nil {
this.moduleRtask.Errorf("update user rtaskId err %v", err)
}
// 发奖
for _, v := range sideConf.Reward {
if v.ChooseId == req.ChooseId {
this.moduleRtask.DispenseRes(session, v.Reward, true)
}
}
if err := session.SendMsg(string(this.moduleRtask.GetType()), RtaskSubTypeBattleFinish,
&pb.RtaskBattleFinishResp{
RtaskId: req.RtaskId,
RtaskSubId: req.RtaskSubId,
}); err != nil {
code = pb.ErrorCode_SystemError
}
rsp := &pb.RtaskFinishPush{
RtaskId: req.RtaskId,
}
if err := session.SendMsg(string(this.moduleRtask.GetType()), "finish", rsp); err != nil {
code = pb.ErrorCode_SystemError
}
this.moduleRtask.Debugf("随机任务完成 rtaskID:%v subtaskID:%v chooseID:%v", req.RtaskId, req.RtaskSubId, req.ChooseId)
return
}

View File

@ -1,73 +0,0 @@
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_rtask,
Format: &pb.BattleFormation{
Leadpos: req.Leadpos,
Format: 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

@ -1,31 +0,0 @@
package rtask
import (
"go_dreamfactory/comm"
"go_dreamfactory/pb"
"google.golang.org/protobuf/proto"
)
func (this *apiComp) ChooseCheck(session comm.IUserSession, req *pb.RtaskChooseReq) (code pb.ErrorCode) {
if req.ChooseId == 0 || req.RtaskId == 0 {
code = pb.ErrorCode_ReqParameterError
}
return
}
// Deprecated: Use
func (this *apiComp) Choose(session comm.IUserSession, req *pb.RtaskChooseReq) (code pb.ErrorCode, data proto.Message) {
if code = this.ChooseCheck(session, req); code != pb.ErrorCode_Success {
return
}
rsp := &pb.RtaskChooseResp{
RtaskId: req.RtaskId,
ChooseId: req.ChooseId,
}
if err := session.SendMsg(string(this.moduleRtask.GetType()), RtaskSubTypeChoose, rsp); err != nil {
code = pb.ErrorCode_SystemError
}
return
}

View File

@ -1,39 +0,0 @@
package rtask
import (
"go_dreamfactory/comm"
"go_dreamfactory/pb"
"google.golang.org/protobuf/proto"
)
func (this *apiComp) ListCheck(session comm.IUserSession, req *pb.RtasklistReq) (code pb.ErrorCode) {
return
}
func (this *apiComp) List(session comm.IUserSession, req *pb.RtasklistReq) (code pb.ErrorCode, data proto.Message) {
// 获取当前玩家随机任务
rtask := this.moduleRtask.modelRtask.GetRtask(session.GetUserId())
if rtask == nil {
code = pb.ErrorCode_RtaskNoRtask
return
}
ids := make([]int32, 0)
// 查询分组ID对应的任务
if v, ok := rtask.FrtaskIds[req.GroupId]; ok {
ids = v.RtaskIds
}
rsp := &pb.RtasklistResp{
RtaskIds: ids,
GroupId: req.GroupId,
}
if err := session.SendMsg(string(this.moduleRtask.GetType()), RtaskSubTypeList, rsp); err != nil {
code = pb.ErrorCode_SystemError
}
return
}

View File

@ -1,71 +0,0 @@
package rtask
import (
"go_dreamfactory/comm"
"go_dreamfactory/pb"
"google.golang.org/protobuf/proto"
)
func (this *apiComp) GetRewardCheck(session comm.IUserSession, req *pb.RtaskGetRewardReq) (code pb.ErrorCode) {
if req.RtaskId == 0 {
code = pb.ErrorCode_ReqParameterError
}
return
}
func (this *apiComp) GetReward(session comm.IUserSession, req *pb.RtaskGetRewardReq) (code pb.ErrorCode, data proto.Message) {
if code = this.GetRewardCheck(session, req); code != pb.ErrorCode_Success {
return
}
// 获取支线任务配置
sideConf := this.moduleRtask.configure.getRtaskSidById(req.RtaskSubId)
if sideConf == nil {
code = pb.ErrorCode_ConfigNoFound
this.moduleRtask.Errorf("uid:%v rdtask_side:%v config no found", session.GetUserId(), req.RtaskSubId)
return
}
//校验是否最后一个任务
if sideConf.NextTid != 0 {
code = pb.ErrorCode_RtaskNoLastOne
return
}
// 获取当前玩家
rtask := this.moduleRtask.modelRtask.GetRtask(session.GetUserId())
if rtask == nil {
code = pb.ErrorCode_RtaskNoRtask
return
}
// 是否已领取奖励
if rtask.IsReward {
code = pb.ErrorCode_RtaskRewarded
return
}
//发奖励
for _, v := range sideConf.Reward {
code = this.moduleRtask.DispenseRes(session, v.Reward, true)
this.moduleRtask.Infof("uid:%v 发奖励:%v code:%v", session.GetUserId(), v.Reward, code)
}
// 更新奖励领取状态
update := map[string]interface{}{
"isReward": true,
}
if err := this.moduleRtask.modelRtask.Change(session.GetUserId(), update); err != nil {
code = pb.ErrorCode_SystemError
return
}
rsp := &pb.RtaskGetRewardResp{
RtaskId: req.RtaskId,
}
if err := session.SendMsg(string(this.moduleRtask.GetType()), RtaskSubTypeReward, rsp); err != nil {
code = pb.ErrorCode_SystemError
}
return
}

View File

@ -8,11 +8,7 @@ import (
)
const (
gameRtask = "game_rdtask.json"
gameRtaskChoose = "game_rdtaskchoose.json"
gameTaskCond = "game_rdtaskcondi.json"
gameRtaskSide = "game_rdtaskside.json"
gameRtaskBattle = "game_rdtaskbattle.json"
)
type configureComp struct {
@ -22,31 +18,11 @@ type configureComp struct {
func (this *configureComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
err = this.MCompConfigure.Init(service, module, comp, options)
err = this.LoadMultiConfigure(map[string]interface{}{
gameRtask: cfg.NewGameRdtask,
gameRtaskChoose: cfg.NewGameRdtaskChoose,
gameTaskCond: cfg.NewGameRdtaskCondi,
gameRtaskSide: cfg.NewGameRdtaskSide,
gameRtaskBattle: cfg.NewGameRdtaskBattle,
})
return
}
func (this *configureComp) getRtaskCfg() (data *cfg.GameRdtask, err error) {
var (
v interface{}
ok bool
)
if v, err = this.GetConfigure(gameRtask); err != nil {
return
} else {
if data, ok = v.(*cfg.GameRdtask); !ok {
err = fmt.Errorf("%T no is *cfg.GameRdtaskAll", v)
return
}
}
return
}
func (this *configureComp) getRtaskCondiCfg() (data *cfg.GameRdtaskCondi, err error) {
var (
v interface{}
@ -63,78 +39,6 @@ func (this *configureComp) getRtaskCondiCfg() (data *cfg.GameRdtaskCondi, err er
return
}
func (this *configureComp) getRtaskChoose() (data *cfg.GameRdtaskChoose, err error) {
var (
v interface{}
ok bool
)
if v, err = this.GetConfigure(gameRtaskChoose); err != nil {
return
} else {
if data, ok = v.(*cfg.GameRdtaskChoose); !ok {
err = fmt.Errorf("%T is *cfg.getRtaskChoose", v)
return
}
}
return
}
func (this *configureComp) getRtaskSide() (data *cfg.GameRdtaskSide, err error) {
var (
v interface{}
ok bool
)
if v, err = this.GetConfigure(gameRtaskSide); err != nil {
return
} else {
if data, ok = v.(*cfg.GameRdtaskSide); !ok {
err = fmt.Errorf("%T is *cfg.GameRdtaskSide", v)
return
}
}
return
}
func (this *configureComp) getRtaskBattle() (data *cfg.GameRdtaskBattle, err error) {
var (
v interface{}
ok bool
)
if v, err = this.GetConfigure(gameRtaskBattle); err != nil {
return
} else {
if data, ok = v.(*cfg.GameRdtaskBattle); !ok {
err = fmt.Errorf("%T is *cfg.GameRdtaskBattle", v)
return
}
}
return
}
// 获取选项配置
func (this *configureComp) getRtaskChooseCfg(id int32) *cfg.GameRdtaskChooseData {
cfg, err := this.getRtaskChoose()
if err != nil {
return nil
}
if data, ok := cfg.GetDataMap()[id]; ok {
return data
}
return nil
}
func (this *configureComp) getRtaskSidById(id int32) *cfg.GameRdtaskSideData {
cfg, err := this.getRtaskSide()
if err != nil {
return nil
}
if data, ok := cfg.GetDataMap()[id]; ok {
return data
}
return nil
}
// 查询任务类型
func (this *configureComp) getRtaskTypeById(typeId int32) (data *cfg.GameRdtaskCondiData, err error) {
@ -165,30 +69,3 @@ func (this *configureComp) getRtaskCondis(typeId int32) (list []*cfg.GameRdtaskC
return
}
// 任务
func (this *configureComp) getRtaskById(taskId int32) (data *cfg.GameRdtaskData) {
cfg, err := this.getRtaskCfg()
if err != nil {
return
}
if cfg != nil {
if data, ok := cfg.GetDataMap()[taskId]; ok {
return data
}
}
return nil
}
// 战斗配置
func (this *configureComp) getRtaskBattleById(id int32) (data *cfg.GameRdtaskBattleData) {
cfg, err := this.getRtaskBattle()
if err != nil {
return
}
if cfg != nil {
if data, ok := cfg.GetDataMap()[id]; ok {
return data
}
}
return nil
}

View File

@ -15,7 +15,6 @@ import (
cfg "go_dreamfactory/sys/configure/structs"
"go_dreamfactory/sys/db"
"go_dreamfactory/utils"
"sort"
"github.com/pkg/errors"
)
@ -335,75 +334,11 @@ func (this *ModuleRtask) RemoveCondi(uid string, condiId int32) (err error) {
return
}
// 初始化任务条件数据
// Deprecated
func (this *ModuleRtask) InitCondiData(uid string) error {
return this.modelRtaskRecord.initCondiData(uid)
}
// 获取玩家任务条件记录
func (this *ModuleRtask) GetCondiData(uid string) *pb.DBRtaskRecord {
return this.modelRtaskRecord.getRecord(uid)
}
// Bingo命令更新随机任务
func (this *ModuleRtask) BingoRtask(session comm.IUserSession, groupId, rtaskId int32) error {
rtask := &pb.DBRtask{}
if err := this.modelRtask.Get(session.GetUserId(), rtask); err != nil {
return err
}
var (
frtaskArr *pb.FrtaskIds //完成的任务
ok bool
)
// 查找任务组
if frtaskArr, ok = rtask.FrtaskIds[groupId]; !ok {
frtaskArr = &pb.FrtaskIds{}
}
gr, err := this.configure.getRtaskCfg()
if err != nil {
return err
}
var rgs []*cfg.GameRdtaskData
for _, v := range gr.GetDataList() {
if v.Group == groupId {
rgs = append(rgs, v)
}
}
sort.SliceStable(rgs, func(i, j int) bool {
return rgs[i].Id < rgs[j].Id
})
for _, v := range rgs {
if v.Id <= rtaskId {
if _, ok := utils.Findx(frtaskArr.RtaskIds, v.Id); !ok {
frtaskArr.RtaskIds = append(frtaskArr.RtaskIds, v.Id)
}
}
}
if rtask.FrtaskIds == nil {
rtask.FrtaskIds = make(map[int32]*pb.FrtaskIds)
}
rtask.FrtaskIds[groupId] = frtaskArr
update := map[string]interface{}{
"frtaskIds": rtask.FrtaskIds,
}
if err := this.modelRtask.Change(session.GetUserId(), update); err != nil {
return err
}
if err := session.SendMsg(string(this.GetType()), "finishids",
&pb.RtaskFinishIdsPush{RtaskId: frtaskArr.RtaskIds, GroupId: groupId}); err != nil {
return err
}
return nil
}
// 远程条件校验
func (this *ModuleRtask) RemoteCheckCondi(uid string, condiId int32, rsp *pb.DBRtaskRecord) error {
if rsp == nil {