diff --git a/cmd/robot/task.go b/cmd/robot/task.go index 82fec5e7f..39984cb1c 100644 --- a/cmd/robot/task.go +++ b/cmd/robot/task.go @@ -17,9 +17,10 @@ var ( subType: task.TaskSubTypeList, req: &pb.TaskListReq{ //设置任务类型 - TaskTag: int32(comm.TASK_DAILY), //每天任务 + // TaskTag: int32(comm.TASK_DAILY), //每天任务 // TaskTag: int32(comm.TASK_WEEKLY), //周任务 // TaskTag: int32(comm.TASK_ACHIEVE), + TaskTag: int32(comm.TASK_STRATEGY), }, rsp: &pb.TaskListResp{}, print: func(rsp proto.Message) { @@ -28,7 +29,7 @@ var ( fmt.Printf("%v \n", v) } }, - // enabled: true, + enabled: true, next: func(robot *Robot, rsp proto.Message) { tcs := []*TestCase{} if v, ok := rsp.(*pb.TaskListResp); ok { @@ -41,8 +42,8 @@ var ( TaskTag: int32(comm.TASK_DAILY), Id: tt.Id, }, - rsp: &pb.TaskReceiveResp{}, - enabled: true, + rsp: &pb.TaskReceiveResp{}, + // enabled: true, } tcs = append(tcs, tc) } diff --git a/cmd/robot/user.go b/cmd/robot/user.go index 99c0c83f6..852b83905 100644 --- a/cmd/robot/user.go +++ b/cmd/robot/user.go @@ -44,7 +44,7 @@ var user_builders = []*TestCase{ }, }, rsp: &pb.UserAddResResp{}, - enabled: true, + // enabled: true, }, } diff --git a/modules/hero/api_strengthen.go b/modules/hero/api_strengthen.go index c4be1d1dc..a51764a51 100644 --- a/modules/hero/api_strengthen.go +++ b/modules/hero/api_strengthen.go @@ -160,7 +160,7 @@ func (this *apiComp) StrengthenUplv(session comm.IUserSession, req *pb.HeroStren // 删除经验卡 for k, v := range req.ExpCards { - err1 := this.module.modelHero.consumeOneHeroCard(session.GetUserId(), k, v) + err1 := this.module.modelHero.consumeHeroCard(session.GetUserId(), k, v) if err1 != nil { code = pb.ErrorCode_HeroNoEnough this.module.Errorf("delete err failed err:%T!", err1) diff --git a/modules/hero/model_hero.go b/modules/hero/model_hero.go index 90a8f841f..ae475f5f6 100644 --- a/modules/hero/model_hero.go +++ b/modules/hero/model_hero.go @@ -1,6 +1,7 @@ package hero import ( + "errors" "fmt" "go_dreamfactory/comm" "go_dreamfactory/lego/core" @@ -193,15 +194,32 @@ func (this *ModelHero) getOneHero(uid, heroId string) *pb.DBHero { return hero } -//消耗一张英雄卡 -func (this *ModelHero) consumeOneHeroCard(uid, heroId string, count int32) (err error) { - for i := 0; i < int(count); i++ { +//消耗英雄卡 +func (this *ModelHero) consumeHeroCard(uid, heroId string, count int32) (err error) { + if count == 0 { + return + } + + hero := this.getOneHero(uid, heroId) + if hero == nil { + return errors.New("hero no exist") + } + + if hero.SameCount < count { + return errors.New("hero card no enough") + } + + if hero.SameCount-count == 0 { if err := this.moduleHero.modelHero.DelListlds(uid, heroId); err != nil { this.moduleHero.Errorf("%v", err) - break } - this.moduleHero.Debugf("删除一张卡牌uid:%s,卡牌ID:%s", uid, heroId) + } else { + update := map[string]interface{}{ + "sameCount": hero.SameCount - count, + } + err = this.modifyHeroData(uid, heroId, update) } + this.moduleHero.Debugf("删除一张卡牌uid:%s,卡牌ID:%s", uid, heroId) return } @@ -225,6 +243,9 @@ func (this *ModelHero) getHeroList(uid string) []*pb.DBHero { //更新装备 func (this *ModelHero) setEquipment(uid, heroId string, equipIds []string) error { + if len(equipIds) == 0 { + return nil + } update := map[string]interface{}{ "equipID": equipIds, } diff --git a/modules/hero/module.go b/modules/hero/module.go index 913777383..ea47442c1 100644 --- a/modules/hero/module.go +++ b/modules/hero/module.go @@ -178,7 +178,7 @@ func (this *Hero) AddCardExp(uid string, heroId string, exp int32) (code pb.Erro // 删除指定卡牌 func (this *Hero) DelCard(udi string, cardid string, amount int32) (code pb.ErrorCode) { - err := this.modelHero.consumeOneHeroCard(udi, cardid, amount) + err := this.modelHero.consumeHeroCard(udi, cardid, amount) if err != nil { return pb.ErrorCode_DBError } diff --git a/modules/task/model_task.go b/modules/task/model_task.go index b2a3724d1..5fbd16fb9 100644 --- a/modules/task/model_task.go +++ b/modules/task/model_task.go @@ -176,3 +176,13 @@ func (this *ModelTask) clearTask(uid string, taskTag comm.TaskTag) error { } return nil } + +//初始化攻略任务 +// func (this *ModelTask) initStrategyTask(uid string, taskTag comm.TaskTag) error { +// ids, err := this.Redis.HGetAllToMapString(fmt.Sprintf("task:%v_%v", uid, comm.TASK_STRATEGY)) +// if err != nil { +// return err +// } + + +// } diff --git a/modules/task/module.go b/modules/task/module.go index 30af4972b..aa79d7533 100644 --- a/modules/task/module.go +++ b/modules/task/module.go @@ -1,6 +1,7 @@ package task import ( + "fmt" "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/lego/sys/log" @@ -82,3 +83,13 @@ func (this *ModuleTask) SendToTask(uid string, taskType comm.TaskType, taskPram } return } + +//创建玩家攻略任务 +func (this *ModuleTask) CreateTaskForStrategy(uid string, heroCfgId int32) { + // + ids := make(map[string]string) + ids, _ = this.modelTask.Redis.HGetAllToMapString(fmt.Sprintf("task:%v_%v", uid, comm.TASK_STRATEGY)) + fmt.Println(ids) + // + +}