From 10c021ffb9cefedf761a17e64b84b4cc45fbd91b Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Tue, 27 Dec 2022 17:23:14 +0800 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E6=88=98=E6=96=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- comm/const.go | 1 + comm/imodule.go | 8 +- modules/auto/api.go | 21 +--- modules/auto/api_autochallenge.go | 76 +++++++++++++++ modules/auto/api_autoover.go | 58 +++++++++++ modules/auto/api_challenge.go | 23 ----- modules/auto/api_challengeover.go | 23 ----- modules/auto/model_auto.go | 35 +++++-- modules/auto/module.go | 14 ++- modules/hero/api_drawCard.go | 2 +- modules/hero/module.go | 4 +- modules/modulebase.go | 92 +++++++++++++++++- modules/viking/api_challengeover.go | 40 ++++---- modules/viking/module.go | 143 ++++++++++++++++++++++++++++ pb/auto_db.pb.go | 39 ++++++-- pb/errorcode.pb.go | 16 +++- 16 files changed, 481 insertions(+), 114 deletions(-) create mode 100644 modules/auto/api_autochallenge.go create mode 100644 modules/auto/api_autoover.go delete mode 100644 modules/auto/api_challenge.go delete mode 100644 modules/auto/api_challengeover.go diff --git a/comm/const.go b/comm/const.go index e94e39501..165a19d41 100644 --- a/comm/const.go +++ b/comm/const.go @@ -76,6 +76,7 @@ const ( ModuleReddot core.M_Modules = "reddot" //红点 ModuleCombat core.M_Modules = "combat" //关卡编辑 ModuleEnchant core.M_Modules = "enchant" //附魔 + ModuleAutoBattle core.M_Modules = "autobattle" //自动战斗 ) //数据表名定义处 diff --git a/comm/imodule.go b/comm/imodule.go index 9c59739bb..5648fd7b3 100644 --- a/comm/imodule.go +++ b/comm/imodule.go @@ -45,7 +45,7 @@ type ( //创建指定数量 CreateRepeatHero(session IUserSession, heroCfgId string, num int32, bPush bool) (hero *pb.DBHero, code pb.ErrorCode) // 批量创建英雄 - CreateRepeatHeros(session IUserSession, heros map[string]int32, bPush bool) (code pb.ErrorCode) + CreateRepeatHeros(session IUserSession, heros map[string]int32, bPush bool) (hero *pb.DBHero, code pb.ErrorCode) // 获取英雄 // heroId 英雄ID GetHeroByObjID(uid, heroId string) (*pb.DBHero, pb.ErrorCode) @@ -249,6 +249,12 @@ type ( CompleteAllLevel(session IUserSession) (code pb.ErrorCode) CheckUserBaseVikingInfo(uid string) (data []*pb.DBVikingRank) // 查询玩家最佳通关记录 IReddot + // 自动购买门票 + AutoBuyTicket(session IUserSession) (code pb.ErrorCode) + // 自动战斗 战斗信息 + AutoBattleInfo(session IUserSession, Leadpos int32, format []string, bossId, difficulty int32) (code pb.ErrorCode, battleInfo *pb.BattleInfo) + AutoBattleOver(session IUserSession, bossId int32, difficulty int32, Report *pb.BattleReport, autoBattle *pb.DBAutoBattle) (code pb.ErrorCode, atno []*pb.UserAtno) + CheckBattelParameter(session IUserSession, teamids []string, bossid, difficulty, leadpos int32) (code pb.ErrorCode) } IHunting interface { CompleteAllLevel(session IUserSession) (code pb.ErrorCode) diff --git a/modules/auto/api.go b/modules/auto/api.go index 4d2a9625e..cee59459b 100644 --- a/modules/auto/api.go +++ b/modules/auto/api.go @@ -6,23 +6,14 @@ import ( "go_dreamfactory/modules" ) -const ( - HuntingGetListResp = "getlist" - HuntingChallengeResp = "challenge" - HuntingChallengeOverResp = "challengeover" - HuntingSkillLvResp = "skilllv" - HuntingGetRewardResp = "getreward" - HuntingBuyResp = "buy" - HuntingRankListResp = "ranklist" -) +const () type apiComp struct { modules.MCompGate service core.IService configure *configureComp module *AutoBattle - friend comm.IFriend - chat comm.IChat + viking comm.IViking } //组件初始化接口 @@ -37,13 +28,9 @@ func (this *apiComp) Init(service core.IService, module core.IModule, comp core. func (this *apiComp) Start() (err error) { err = this.MCompGate.Start() var module core.IModule - if module, err = this.service.GetModule(comm.ModuleFriend); err != nil { + if module, err = this.service.GetModule(comm.ModuleViking); err != nil { return } - this.friend = module.(comm.IFriend) - if module, err = this.service.GetModule(comm.ModuleChat); err != nil { - return - } - this.chat = module.(comm.IChat) + this.viking = module.(comm.IViking) return } diff --git a/modules/auto/api_autochallenge.go b/modules/auto/api_autochallenge.go new file mode 100644 index 000000000..d67a9ecc7 --- /dev/null +++ b/modules/auto/api_autochallenge.go @@ -0,0 +1,76 @@ +package autoBattle + +import ( + "go_dreamfactory/comm" + "go_dreamfactory/pb" + + "go.mongodb.org/mongo-driver/bson/primitive" + "google.golang.org/protobuf/proto" +) + +//参数校验 +func (this *apiComp) AutoChallengeCheck(session comm.IUserSession, req *pb.BattleAutoChallengeReq) (code pb.ErrorCode) { + if req.BossId <= 0 || req.Difficulty <= 0 { + code = pb.ErrorCode_ReqParameterError + return + } + return +} + +func (this *apiComp) AutoChallenge(session comm.IUserSession, req *pb.BattleAutoChallengeReq) (code pb.ErrorCode, data proto.Message) { + var ( + battleInfo *pb.BattleInfo + ) + if code = this.AutoChallengeCheck(session, req); code != pb.ErrorCode_Success { + return + } + list, err := this.module.modelAutoBattle.getAutoBattleList(session.GetUserId()) + if err != nil { + code = pb.ErrorCode_DBError + return + } + for _, v := range list { + if v.Ptype == req.Ptype { // 有正在自动战斗的数据 + code = pb.ErrorCode_AutoBattleStatesErr + return + } + } + // 写入数据 + battle := make(map[string]interface{}, 0) + _d := &pb.DBAutoBattle{ + Id: primitive.NewObjectID().Hex(), + Uid: session.GetUserId(), + AutoWin: req.AutoWin, + MaxExp: req.MaxExp, + AutoBuy: req.AutoBuy, + AutoSell: req.AutoSell, + Ptype: req.Ptype, + BossId: req.BossId, + Difficulty: req.Difficulty, + } + battle[_d.Id] = _d + if err = this.module.modelAutoBattle.AddListByObjId(session.GetUserId(), battle); err != nil { + code = pb.ErrorCode_DBError + return + } + + // 优先判断门票够不够 + if req.Ptype == pb.PlayType_viking { + if req.AutoBuy { + this.viking.AutoBuyTicket(session) + code = this.viking.CheckBattelParameter(session, req.Teamids, req.BossId, req.Difficulty, req.Leadpos) + if code == pb.ErrorCode_Success { + session.SendMsg(string(this.module.GetType()), "autochallenge", &pb.BattleAutoChallengeResp{ + Info: battleInfo, + }) + } + code, battleInfo = this.viking.AutoBattleInfo(session, req.Leadpos, req.Teamids, req.BossId, req.Difficulty) + if code == pb.ErrorCode_Success { + session.SendMsg(string(this.module.GetType()), "autochallenge", &pb.BattleAutoChallengeResp{ + Info: battleInfo, + }) + } + } + } + return +} diff --git a/modules/auto/api_autoover.go b/modules/auto/api_autoover.go new file mode 100644 index 000000000..16102ca40 --- /dev/null +++ b/modules/auto/api_autoover.go @@ -0,0 +1,58 @@ +package autoBattle + +import ( + "go_dreamfactory/comm" + "go_dreamfactory/pb" + + "google.golang.org/protobuf/proto" +) + +//参数校验 +func (this *apiComp) AutoOverCheck(session comm.IUserSession, req *pb.BattleAutoOverReq) (code pb.ErrorCode) { + if req.Ptype == pb.PlayType_null || req.Report == nil { + code = pb.ErrorCode_ReqParameterError + return + } + if req.Report.Info == nil { + code = pb.ErrorCode_ReqParameterError + return + } + return +} + +func (this *apiComp) AutoOver(session comm.IUserSession, req *pb.BattleAutoOverReq) (code pb.ErrorCode, data proto.Message) { + var ( + autoBattle *pb.DBAutoBattle + atno []*pb.UserAtno + ) + if code = this.AutoOverCheck(session, req); code != pb.ErrorCode_Success { + return + } + list, err := this.module.modelAutoBattle.getAutoBattleList(session.GetUserId()) + if err != nil { + code = pb.ErrorCode_DBError + return + } + for _, v := range list { + if v.Ptype == req.Ptype { // 有正在自动战斗的数据 + autoBattle = v + } + } + if autoBattle == nil { + code = pb.ErrorCode_AutoBattleNoData + return + } + // 分析战报 数据 + if req.Ptype == pb.PlayType_viking { + if code, atno = this.viking.AutoBattleOver(session, autoBattle.BossId, autoBattle.Difficulty, req.Report, autoBattle); code != pb.ErrorCode_Success { + session.SendMsg(string(this.module.GetType()), "autoover", &pb.BattleAutoOverPush{ + Success: false, + }) + return + } + } + session.SendMsg(string(this.module.GetType()), "autoover", &pb.BattleAutoOverResp{ + Asset: atno, + }) + return +} diff --git a/modules/auto/api_challenge.go b/modules/auto/api_challenge.go deleted file mode 100644 index 5f0367f0b..000000000 --- a/modules/auto/api_challenge.go +++ /dev/null @@ -1,23 +0,0 @@ -package autoBattle - -import ( - "go_dreamfactory/comm" - "go_dreamfactory/pb" - - "google.golang.org/protobuf/proto" -) - -//参数校验 -func (this *apiComp) ChallengeCheck(session comm.IUserSession, req *pb.HuntingChallengeReq) (code pb.ErrorCode) { - if req.BossType <= 0 && req.Difficulty > 0 { - code = pb.ErrorCode_ReqParameterError - return - } - return -} - -///挑战主线关卡 -func (this *apiComp) Challenge(session comm.IUserSession, req *pb.HuntingChallengeReq) (code pb.ErrorCode, data proto.Message) { - - return -} diff --git a/modules/auto/api_challengeover.go b/modules/auto/api_challengeover.go deleted file mode 100644 index baefb5dc7..000000000 --- a/modules/auto/api_challengeover.go +++ /dev/null @@ -1,23 +0,0 @@ -package autoBattle - -import ( - "go_dreamfactory/comm" - "go_dreamfactory/pb" - - "google.golang.org/protobuf/proto" -) - -//参数校验 -func (this *apiComp) ChallengeOverCheck(session comm.IUserSession, req *pb.HuntingChallengeOverReq) (code pb.ErrorCode) { - if req.BossType <= 0 && req.Difficulty > 0 { - code = pb.ErrorCode_ReqParameterError - return - } - return -} - -///挑战主线关卡 -func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.HuntingChallengeOverReq) (code pb.ErrorCode, data proto.Message) { - - return -} diff --git a/modules/auto/model_auto.go b/modules/auto/model_auto.go index 8f5ad8c59..4af9ffb66 100644 --- a/modules/auto/model_auto.go +++ b/modules/auto/model_auto.go @@ -3,6 +3,7 @@ package autoBattle import ( "go_dreamfactory/comm" "go_dreamfactory/lego/core" + "go_dreamfactory/lego/sys/mgo" "go_dreamfactory/modules" "go_dreamfactory/pb" @@ -26,18 +27,36 @@ func (this *modelAutoBattle) Init(service core.IService, module core.IModule, co return } -func (this *modelAutoBattle) modifyAutoBattleDataByObjId(uid string, id string, data map[string]interface{}) error { +// 修改列表信息 +func (this *modelAutoBattle) ChangeListByObjId(uid string, id string, data map[string]interface{}) error { err := this.ChangeList(uid, id, data) return err } -// 获取列表信息 -func (this *modelAutoBattle) getAutoBattleList(uid string) (result *pb.DBAutoBattle, err error) { - result = &pb.DBAutoBattle{} - if err = this.Get(uid, result); err != nil { - return - } +// 删除自动战斗信息 +func (this *modelAutoBattle) DelListByObjId(uid string, id string, data map[string]interface{}) error { + err := this.DelListByObjId(uid, id, data) + return err +} - err = nil +// 删除自动战斗信息 +func (this *modelAutoBattle) AddListByObjId(uid string, data map[string]interface{}) error { + err := this.AddLists(uid, data) + return err +} + +// 获取列表信息 +func (this *modelAutoBattle) getAutoBattleList(uid string) (result []*pb.DBAutoBattle, err error) { + result = make([]*pb.DBAutoBattle, 0) + err = this.GetList(uid, &result) + if err == mgo.MongodbNil { + err = nil + } return result, err } + +// 玩家离线清除自动战斗数据 +func (this *modelAutoBattle) RemoveUserInfo(session comm.IUserSession) (err error) { + this.BatchDelLists(session.GetUserId()) + return err +} diff --git a/modules/auto/module.go b/modules/auto/module.go index 558a0f5fa..3c995d8a9 100644 --- a/modules/auto/module.go +++ b/modules/auto/module.go @@ -3,6 +3,7 @@ package autoBattle import ( "go_dreamfactory/comm" "go_dreamfactory/lego/core" + "go_dreamfactory/lego/sys/event" "go_dreamfactory/modules" "go_dreamfactory/pb" ) @@ -21,7 +22,7 @@ func NewModule() core.IModule { } func (this *AutoBattle) GetType() core.M_Modules { - return comm.ModuleHunting + return comm.ModuleAutoBattle } func (this *AutoBattle) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) { @@ -38,6 +39,8 @@ func (this *AutoBattle) Start() (err error) { } this.battle = module.(comm.IBattle) + + event.RegisterGO(comm.EventUserOffline, this.EventUserOffline) return } @@ -50,14 +53,15 @@ func (this *AutoBattle) OnInstallComp() { // 接口信息 func (this *AutoBattle) ModifyAutoData(uid string, id string, data map[string]interface{}) (code pb.ErrorCode) { - err := this.modelAutoBattle.modifyAutoBattleDataByObjId(uid, id, data) + err := this.modelAutoBattle.ChangeListByObjId(uid, id, data) if err != nil { code = pb.ErrorCode_DBError } return } -func (this *AutoBattle) CheckUserBaseHuntingInfo(uid string) (data []*pb.DBHuntingRank) { - - return +//Event-------------------------------------------------------------------------------------------------玩家离线 +func (this *AutoBattle) EventUserOffline(session comm.IUserSession) { + err := this.modelAutoBattle.RemoveUserInfo(session) + this.Debugf("EventUserOffline:%s err:%v", session.ToString(), err) } diff --git a/modules/hero/api_drawCard.go b/modules/hero/api_drawCard.go index 08a5db2c8..889140706 100644 --- a/modules/hero/api_drawCard.go +++ b/modules/hero/api_drawCard.go @@ -228,7 +228,7 @@ func (this *apiComp) DrawCard(session comm.IUserSession, req *pb.HeroDrawCardReq _mapAddHero[heroId]++ } - code = this.module.CreateRepeatHeros(session, _mapAddHero, true) + _, code = this.module.CreateRepeatHeros(session, _mapAddHero, true) ///英雄招募 【玩家名称】在招募中获得了【英雄名称】! for hid := range _mapAddHero { diff --git a/modules/hero/module.go b/modules/hero/module.go index b98e0772b..a46bc6d6c 100644 --- a/modules/hero/module.go +++ b/modules/hero/module.go @@ -277,12 +277,12 @@ func (this *Hero) EventUserOffline(session comm.IUserSession) { } // 批量创建多个英雄 -func (this *Hero) CreateRepeatHeros(session comm.IUserSession, heros map[string]int32, bPush bool) (code pb.ErrorCode) { +func (this *Hero) CreateRepeatHeros(session comm.IUserSession, heros map[string]int32, bPush bool) (hero *pb.DBHero, code pb.ErrorCode) { for heroCfgId, num := range heros { if num == 0 { // 数量为0 不做处理 continue } - if _, code = this.CreateRepeatHero(session, heroCfgId, num, bPush); code != pb.ErrorCode_Success { + if hero, code = this.CreateRepeatHero(session, heroCfgId, num, bPush); code != pb.ErrorCode_Success { this.Errorf("create hero %s failed", heroCfgId) } } diff --git a/modules/modulebase.go b/modules/modulebase.go index d65afb8a9..79aea3105 100644 --- a/modules/modulebase.go +++ b/modules/modulebase.go @@ -360,7 +360,7 @@ func (this *ModuleBase) DispenseRes(session comm.IUserSession, res []*cfg.Gameat this.Debugf("发放道具资源: %v [%v]", items, code) } if len(heros) > 0 { //卡片资源 - code = this.ModuleHero.CreateRepeatHeros(session, heros, bPush) + _, code = this.ModuleHero.CreateRepeatHeros(session, heros, bPush) this.Debugf("发放英雄资源: %v [%v]", heros, code) } if len(equips) > 0 { @@ -503,3 +503,93 @@ func (this *ModuleBase) FatalWithField(msg string, fields ...log.Field) { func (this *ModuleBase) PanicWithField(msg string, fields ...log.Field) { } + +//发放资源 +func (this *ModuleBase) DispenseAtno(session comm.IUserSession, res []*cfg.Gameatn, bPush bool) (code pb.ErrorCode, atno []*pb.UserAtno) { + var ( + items map[string]int32 // 道具背包 批量处理 + heros map[string]int32 // 英雄 + attrs map[string]int32 // 属性 + equips map[string]uint32 // 装备 + vip map[string]int32 // vip + ) + items = make(map[string]int32, 0) + heros = make(map[string]int32, 0) + attrs = make(map[string]int32, 0) + equips = make(map[string]uint32, 0) + vip = make(map[string]int32, 0) + + for _, v := range res { + switch v.A { + case comm.AttrType: + attrs[v.T] += v.N + case comm.ItemType: + items[v.T] += v.N + case comm.HeroType: + heros[v.T] += v.N + case comm.EquipmentType: + if v.N > 0 { // 不允许减少装备 + equips[v.T] += uint32(v.N) + } + case comm.VipType: + vip[v.T] += v.N + default: + this.Errorf("not found res type") // 找不到资源类型 + } + } + + if len(attrs) > 0 { //用户属性资源 + code = this.ModuleUser.AddAttributeValues(session, attrs, bPush) + this.Debugf("发放用户资源: %v [%v]", attrs, code) + for k, v := range attrs { + atno = append(atno, &pb.UserAtno{ + A: "attr", + T: k, + N: v, + O: "", + }) + } + } + if len(items) > 0 { //道具资源 + addItems, code := this.ModuleItems.AddItems(session, items, bPush) + this.Debugf("发放道具资源: %v [%v]", items, code) + for _, v := range addItems { + atno = append(atno, &pb.UserAtno{ + A: "item", + T: v.ItemId, + N: int32(len(items)), + O: v.GridId, + }) + } + } + if len(heros) > 0 { //卡片资源 + hero, code := this.ModuleHero.CreateRepeatHeros(session, heros, bPush) + this.Debugf("发放英雄资源: %v [%v]", heros, code) + atno = append(atno, &pb.UserAtno{ + A: "hero", + T: hero.HeroID, + N: int32(len(heros)), + O: hero.Id, + }) + } + if len(equips) > 0 { + change, code := this.ModuleEquipment.AddNewEquipments(session, equips, bPush) + this.Debugf("发放装备资源: %v [%v]", equips, code) + for _, v := range change { + atno = append(atno, &pb.UserAtno{ + A: "equi", + T: v.CId, + N: int32(len(equips)), + O: v.Id, + }) + } + } + if len(vip) > 0 { //卡片资源 + for k := range vip { + code, _ = this.ModulePrivilege.Delivery(session, k) + this.Debugf("发放月卡资源: %v [%v]", k, code) + } + + } + return +} diff --git a/modules/viking/api_challengeover.go b/modules/viking/api_challengeover.go index d88f0c34a..9827d8de2 100644 --- a/modules/viking/api_challengeover.go +++ b/modules/viking/api_challengeover.go @@ -41,10 +41,6 @@ func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.VikingChal return } - // if viking.ChallengeCount > this.module.configure.GetGlobalConf().VikingNum+viking.BuyCount { - // code = pb.ErrorCode_VikingMaxChallengeCount - // return - // } vikingCfg := this.module.configure.GetVikingBossConfigData(req.BossId, req.Difficulty) if vikingCfg == nil { code = pb.ErrorCode_ConfigNoFound @@ -78,16 +74,21 @@ func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.VikingChal if code = this.module.ConsumeRes(session, []*cfg.Gameatn{costRes}, true); code != pb.ErrorCode_Success { return } - code, bWin = this.module.battle.CheckBattleReport(session, req.Report) amount := int32(this.module.ModuleItems.QueryItemAmount(session.GetUserId(), costRes.T)) // 获取当前数量 conf := this.module.configure.GetGlobalConf() if conf != nil { - if amount < conf.VikingNum { + if amount < conf.VikingNum && viking.RecoveryTime == 0 { viking.RecoveryTime = configure.Now().Unix() mapData["recoveryTime"] = viking.RecoveryTime + code = this.module.ModifyVikingData(session.GetUserId(), mapData) } } + code, bWin = this.module.battle.CheckBattleReport(session, req.Report) + if !bWin { // 战斗失败了 直接返回 + code = pb.ErrorCode_BattleNoWin + return + } key := strconv.Itoa(int(req.BossId)) + "_" + strconv.Itoa(int(req.Difficulty)) if viking.BossTime[key] == 0 { // 新关卡挑战通过 发放首通奖励 viking.Boss[req.BossId]++ @@ -103,24 +104,23 @@ func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.VikingChal }) } } - if bWin { - this.module.CheckRank(session.GetUserId(), req.BossId, req.Difficulty, viking, req.Report) - reward = this.module.configure.GetDropReward(vikingCfg.Drop) // 获取掉落奖励 - if code = this.module.DispenseRes(session, reward, true); code != pb.ErrorCode_Success { - return - } - for _, v := range reward { - asset = append(asset, &pb.UserAssets{ - A: v.A, - T: v.T, - N: v.N, - }) - } + + this.module.CheckRank(session.GetUserId(), req.BossId, req.Difficulty, viking, req.Report) + reward = this.module.configure.GetDropReward(vikingCfg.Drop) // 获取掉落奖励 + if code = this.module.DispenseRes(session, reward, true); code != pb.ErrorCode_Success { + return } + for _, v := range reward { + asset = append(asset, &pb.UserAssets{ + A: v.A, + T: v.T, + N: v.N, + }) + } + mapData["bossTime"] = viking.BossTime // 更新时间 code = this.module.ModifyVikingData(session.GetUserId(), mapData) - // 发放通关随机奖励 session.SendMsg(string(this.module.GetType()), VikingChallengeOverResp, &pb.VikingChallengeOverResp{ Data: viking, Asset: asset, diff --git a/modules/viking/module.go b/modules/viking/module.go index a1a52d707..d2ffc2ada 100644 --- a/modules/viking/module.go +++ b/modules/viking/module.go @@ -10,6 +10,8 @@ import ( "go_dreamfactory/lego/core" "go_dreamfactory/modules" "go_dreamfactory/pb" + "go_dreamfactory/sys/configure" + cfg "go_dreamfactory/sys/configure/structs" "go_dreamfactory/sys/db" "strconv" "time" @@ -182,3 +184,144 @@ func (this *Viking) CompleteAllLevel(session comm.IUserSession) (code pb.ErrorCo session.SendMsg(string(this.GetType()), VikingGetListResp, &pb.VikingGetListResp{Data: list}) return } + +func (this *Viking) AutoBuyTicket(session comm.IUserSession) (code pb.ErrorCode) { + conf := this.configure.GetGlobalConf() + if conf == nil { + code = pb.ErrorCode_ConfigNoFound + return + } + costRes := conf.VikingExpeditionCos + if costRes == nil { + code = pb.ErrorCode_ConfigNoFound + return + } + amount := int32(this.ModuleItems.QueryItemAmount(session.GetUserId(), costRes.T)) // 获取当前数量 + if amount == 0 { // 数量不足直接购买 + code, _ = this.api.Buy(session, &pb.VikingBuyReq{ + Count: 1, + }) + } + return +} + +func (this *Viking) AutoBattleInfo(session comm.IUserSession, Leadpos int32, format []string, bossId, difficulty int32) (code pb.ErrorCode, battleInfo *pb.BattleInfo) { + + cfgData := this.configure.GetVikingBossConfigData(bossId, difficulty) + if cfgData == nil { + code = pb.ErrorCode_ConfigNoFound + return + } + code, record := this.battle.CreatePveBattle(session, &pb.BattlePVEReq{ + Ptype: pb.PlayType_viking, + Title: "", + Format: &pb.BattleFormation{ + Leadpos: Leadpos, + Format: format, + }, + Mformat: cfgData.Boss, + }) + if code == pb.ErrorCode_Success { + battleInfo = &pb.BattleInfo{Id: record.Id, Title: record.Title, Btype: record.Btype, Ptype: record.Ptype, RedCompId: record.RedCompId, Redflist: record.Redflist, BlueCompId: record.BlueCompId, Buleflist: record.Buleflist} + } + + return +} + +// 自动战斗完成 +func (this *Viking) AutoBattleOver(session comm.IUserSession, bossId int32, difficulty int32, Report *pb.BattleReport, autoBattle *pb.DBAutoBattle) (code pb.ErrorCode, atno []*pb.UserAtno) { + atno = make([]*pb.UserAtno, 0) + costRes := this.configure.GetGlobalConf().VikingExpeditionCos + if costRes == nil { + code = pb.ErrorCode_ConfigNoFound + return + } + if code = this.ConsumeRes(session, []*cfg.Gameatn{costRes}, true); code != pb.ErrorCode_Success { + return + } + amount := int32(this.ModuleItems.QueryItemAmount(session.GetUserId(), costRes.T)) // 获取当前数量 + viking, err := this.modelViking.getVikingList(session.GetUserId()) + if err != nil { + code = pb.ErrorCode_VikingBoosType + return + } + conf := this.configure.GetGlobalConf() + if conf != nil { + + if amount < conf.VikingNum && viking.RecoveryTime == 0 { + mapData := make(map[string]interface{}, 0) + viking.RecoveryTime = configure.Now().Unix() + mapData["recoveryTime"] = viking.RecoveryTime + code = this.ModifyVikingData(session.GetUserId(), mapData) + } + } + code, bWin := this.battle.CheckBattleReport(session, Report) + if !bWin { // 战斗失败了 直接返回 + code = pb.ErrorCode_BattleNoWin + return + } + if autoBattle != nil { + if autoBattle.AutoBuy { + code = this.AutoBuyTicket(session) + } + } + mapData := make(map[string]interface{}, 0) + vikingCfg := this.configure.GetVikingBossConfigData(bossId, difficulty) + if vikingCfg == nil { + code = pb.ErrorCode_ConfigNoFound + return + } + key := strconv.Itoa(int(bossId)) + "_" + strconv.Itoa(int(difficulty)) + if viking.BossTime[key] == 0 { // 新关卡挑战通过 发放首通奖励 + viking.Boss[bossId]++ + mapData["boss"] = viking.Boss + if c, res1 := this.DispenseAtno(session, vikingCfg.Firstprize, true); c == pb.ErrorCode_Success { + atno = append(atno, res1...) + } else { + code = c + return + } + } + + this.CheckRank(session.GetUserId(), bossId, difficulty, viking, Report) + reward := this.configure.GetDropReward(vikingCfg.Drop) // 获取掉落奖励 + if c, res1 := this.DispenseAtno(session, reward, true); c == pb.ErrorCode_Success { + atno = append(atno, res1...) + } else { + code = c + return + } + + mapData["bossTime"] = viking.BossTime // 更新时间 + + code = this.ModifyVikingData(session.GetUserId(), mapData) + + if user := this.ModuleUser.GetUser(session.GetUserId()); user != nil { + if module, err := this.service.GetModule(comm.ModuleChat); err == nil { + module.(comm.IChat).SendSysChatToWorld(comm.ChatSystem14, nil, bossId, difficulty, user.Name) + } + } + // 随机任务统计 + this.ModuleRtask.SendToRtask(session, comm.Rtype73, difficulty, bossId, 1) + this.ModuleRtask.SendToRtask(session, comm.Rtype74, difficulty, bossId) + this.ModuleRtask.SendToRtask(session, comm.Rtype78, difficulty, bossId, Report.Costtime) + if Report != nil && Report.Info != nil && len(Report.Info.Redflist) > 0 { + for _, v := range Report.Info.Redflist[0].Team { + if v.Ishelp { // 判断是否有助战 + this.ModuleRtask.SendToRtask(session, comm.Rtype79, difficulty, bossId) + break + } + } + } + return +} + +func (this *Viking) CheckBattelParameter(session comm.IUserSession, teamids []string, bossid, difficulty, leadpos int32) (code pb.ErrorCode) { + code, _ = this.api.Challenge(session, &pb.VikingChallengeReq{ + BossId: bossid, + Difficulty: difficulty, + Leadpos: leadpos, + Teamids: teamids, + }) + return +} diff --git a/pb/auto_db.pb.go b/pb/auto_db.pb.go index c1d68256f..c2a925226 100644 --- a/pb/auto_db.pb.go +++ b/pb/auto_db.pb.go @@ -26,13 +26,15 @@ type DBAutoBattle struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id" bson:"_id"` //ID - Uid string `protobuf:"bytes,2,opt,name=uid,proto3" json:"uid" bson:"uid"` //用户ID - AutoWin bool `protobuf:"varint,3,opt,name=autoWin,proto3" json:"autoWin"` // 失败自动停止 - MaxExp bool `protobuf:"varint,4,opt,name=maxExp,proto3" json:"maxExp"` //雄达到满级则停止连续战斗 - AutoBuy bool `protobuf:"varint,5,opt,name=autoBuy,proto3" json:"autoBuy"` // 自动购买 - AutoSell int32 `protobuf:"varint,6,opt,name=autoSell,proto3" json:"autoSell"` // 自动出售星级装备 - Ptype PlayType `protobuf:"varint,7,opt,name=ptype,proto3,enum=PlayType" json:"ptype"` // 类型 + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id" bson:"_id"` //ID + Uid string `protobuf:"bytes,2,opt,name=uid,proto3" json:"uid" bson:"uid"` //用户ID + AutoWin bool `protobuf:"varint,3,opt,name=autoWin,proto3" json:"autoWin" bson:"autoWin"` //失败自动停止 + MaxExp bool `protobuf:"varint,4,opt,name=maxExp,proto3" json:"maxExp"` //@go_tags(`bson:"maxExp"`)雄达到满级则停止连续战斗 + AutoBuy bool `protobuf:"varint,5,opt,name=autoBuy,proto3" json:"autoBuy" bson:"autoBuy"` //自动购买 + AutoSell int32 `protobuf:"varint,6,opt,name=autoSell,proto3" json:"autoSell" bson:"autoSell"` //自动出售星级装备 + Ptype PlayType `protobuf:"varint,7,opt,name=ptype,proto3,enum=PlayType" json:"ptype"` // 类型 + BossId int32 `protobuf:"varint,8,opt,name=bossId,proto3" json:"bossId" bson:"bossId"` + Difficulty int32 `protobuf:"varint,9,opt,name=difficulty,proto3" json:"difficulty"` } func (x *DBAutoBattle) Reset() { @@ -116,12 +118,26 @@ func (x *DBAutoBattle) GetPtype() PlayType { return PlayType_null } +func (x *DBAutoBattle) GetBossId() int32 { + if x != nil { + return x.BossId + } + return 0 +} + +func (x *DBAutoBattle) GetDifficulty() int32 { + if x != nil { + return x.Difficulty + } + return 0 +} + var File_auto_auto_db_proto protoreflect.FileDescriptor var file_auto_auto_db_proto_rawDesc = []byte{ 0x0a, 0x12, 0x61, 0x75, 0x74, 0x6f, 0x2f, 0x61, 0x75, 0x74, 0x6f, 0x5f, 0x64, 0x62, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x16, 0x62, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x2f, 0x62, 0x61, 0x74, - 0x74, 0x6c, 0x65, 0x5f, 0x64, 0x62, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xb9, 0x01, 0x0a, + 0x74, 0x6c, 0x65, 0x5f, 0x64, 0x62, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xf1, 0x01, 0x0a, 0x0c, 0x44, 0x42, 0x41, 0x75, 0x74, 0x6f, 0x42, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x69, 0x64, 0x12, @@ -133,8 +149,11 @@ var file_auto_auto_db_proto_rawDesc = []byte{ 0x75, 0x74, 0x6f, 0x53, 0x65, 0x6c, 0x6c, 0x18, 0x06, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x61, 0x75, 0x74, 0x6f, 0x53, 0x65, 0x6c, 0x6c, 0x12, 0x1f, 0x0a, 0x05, 0x70, 0x74, 0x79, 0x70, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x09, 0x2e, 0x50, 0x6c, 0x61, 0x79, 0x54, 0x79, 0x70, - 0x65, 0x52, 0x05, 0x70, 0x74, 0x79, 0x70, 0x65, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, - 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x65, 0x52, 0x05, 0x70, 0x74, 0x79, 0x70, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x62, 0x6f, 0x73, 0x73, + 0x49, 0x64, 0x18, 0x08, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x62, 0x6f, 0x73, 0x73, 0x49, 0x64, + 0x12, 0x1e, 0x0a, 0x0a, 0x64, 0x69, 0x66, 0x66, 0x69, 0x63, 0x75, 0x6c, 0x74, 0x79, 0x18, 0x09, + 0x20, 0x01, 0x28, 0x05, 0x52, 0x0a, 0x64, 0x69, 0x66, 0x66, 0x69, 0x63, 0x75, 0x6c, 0x74, 0x79, + 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/pb/errorcode.pb.go b/pb/errorcode.pb.go index f50391fde..bc3bfc37e 100644 --- a/pb/errorcode.pb.go +++ b/pb/errorcode.pb.go @@ -288,6 +288,9 @@ const ( ErrorCode_WorldtaskLastUnFinished ErrorCode = 3806 //上个任务未完成 // academy ErrorCode_AcademyTaskNoCompleteTask ErrorCode = 3901 //未完成任务 + // AutoBattle + ErrorCode_AutoBattleNoData ErrorCode = 4001 //没有正在自动战斗的数据 + ErrorCode_AutoBattleStatesErr ErrorCode = 4002 // 自动战斗状态错误 ) // Enum value maps for ErrorCode. @@ -528,6 +531,8 @@ var ( 3805: "WorldtaskFinihed", 3806: "WorldtaskLastUnFinished", 3901: "AcademyTaskNoCompleteTask", + 4001: "AutoBattleNoData", + 4002: "AutoBattleStatesErr", } ErrorCode_value = map[string]int32{ "Success": 0, @@ -765,6 +770,8 @@ var ( "WorldtaskFinihed": 3805, "WorldtaskLastUnFinished": 3806, "AcademyTaskNoCompleteTask": 3901, + "AutoBattleNoData": 4001, + "AutoBattleStatesErr": 4002, } ) @@ -799,7 +806,7 @@ var File_errorcode_proto protoreflect.FileDescriptor var file_errorcode_proto_rawDesc = []byte{ 0x0a, 0x0f, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x63, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x2a, 0x88, 0x2a, 0x0a, 0x09, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x12, + 0x6f, 0x2a, 0xb9, 0x2a, 0x0a, 0x09, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x0b, 0x0a, 0x07, 0x53, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x10, 0x00, 0x12, 0x11, 0x0a, 0x0d, 0x4e, 0x6f, 0x46, 0x69, 0x6e, 0x64, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x10, 0x0a, 0x12, 0x1b, 0x0a, 0x17, 0x4e, 0x6f, 0x46, 0x69, 0x6e, 0x64, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, @@ -1135,8 +1142,11 @@ var file_errorcode_proto_rawDesc = []byte{ 0x0a, 0x17, 0x57, 0x6f, 0x72, 0x6c, 0x64, 0x74, 0x61, 0x73, 0x6b, 0x4c, 0x61, 0x73, 0x74, 0x55, 0x6e, 0x46, 0x69, 0x6e, 0x69, 0x73, 0x68, 0x65, 0x64, 0x10, 0xde, 0x1d, 0x12, 0x1e, 0x0a, 0x19, 0x41, 0x63, 0x61, 0x64, 0x65, 0x6d, 0x79, 0x54, 0x61, 0x73, 0x6b, 0x4e, 0x6f, 0x43, 0x6f, 0x6d, - 0x70, 0x6c, 0x65, 0x74, 0x65, 0x54, 0x61, 0x73, 0x6b, 0x10, 0xbd, 0x1e, 0x42, 0x06, 0x5a, 0x04, - 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x70, 0x6c, 0x65, 0x74, 0x65, 0x54, 0x61, 0x73, 0x6b, 0x10, 0xbd, 0x1e, 0x12, 0x15, 0x0a, 0x10, + 0x41, 0x75, 0x74, 0x6f, 0x42, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x4e, 0x6f, 0x44, 0x61, 0x74, 0x61, + 0x10, 0xa1, 0x1f, 0x12, 0x18, 0x0a, 0x13, 0x41, 0x75, 0x74, 0x6f, 0x42, 0x61, 0x74, 0x74, 0x6c, + 0x65, 0x53, 0x74, 0x61, 0x74, 0x65, 0x73, 0x45, 0x72, 0x72, 0x10, 0xa2, 0x1f, 0x42, 0x06, 0x5a, + 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var (