diff --git a/comm/imodule.go b/comm/imodule.go index 662fa508c..3ab6a3bdd 100644 --- a/comm/imodule.go +++ b/comm/imodule.go @@ -453,6 +453,9 @@ type ( AddItems(session IUserSession, items map[string]int32, bPush bool) (code pb.ErrorCode) //pvp切磋结果通知 ChallengeResults(bid, red, bule string, winSide int32) + + // 清除玩家踢馆状态 + CleanUpNpc(uid string) } ITools interface { diff --git a/modules/comp_configure.go b/modules/comp_configure.go index adfae337b..86e0e1355 100644 --- a/modules/comp_configure.go +++ b/modules/comp_configure.go @@ -12,8 +12,6 @@ import ( ) const ( - game_global = "game_global.json" //全局配置表 - game_initial = "game_initial.json" //初始化表 game_gamecolor = "game_gamecolor.json" //颜色表 game_playerlv = "game_playerlv.json" //玩家等级 game_facemod = "game_facemod.json" //形象配置表 @@ -28,7 +26,6 @@ const ( game_equip = "game_equip.json" //装备信息表 - game_lottery = "game_lottery.json" ) ///配置管理基础组件 @@ -37,27 +34,11 @@ type MCompConfigure struct { hlock sync.RWMutex _dropMap map[int32][]*cfg.GameDropData // 掉落表 key 是DiropId _sign map[int32]*cfg.GameSignData - - _group map[int64][]int32 // key 小组ID value cid - - // 类型为1 的数据 该大组中的小组为权重掉落,必定从N个小组中随机出1个小组 - _lotteryType1 map[int32][]int32 // key 大组ID value cid - // 类型为2 的数据 有多个小组ID - _lotteryType2 map[int32][]int32 // key 大组ID value 小组ID - // 小组类型为1 - _groupType1 map[int64][]int32 //value cid - // 小组类型为2 - _groupType2 map[int64][]int32 //value cid - Btype map[int32]int32 - Stype map[int64]int32 // subtype - SNum map[int64]int32 // 小组产出数量 } //组件初始化接口 func (this *MCompConfigure) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { err = this.ModuleCompBase.Init(service, module, comp, options) - err = this.LoadConfigure(game_global, cfg.NewGameGlobal) - err = this.LoadConfigure(game_initial, cfg.NewGameInitial) err = this.LoadConfigure(game_gamecolor, cfg.NewGameGameColor) err = this.LoadConfigure(new_hero, cfg.NewGameHero) err = this.LoadConfigure(game_playerlv, cfg.NewGamePlayerlv) @@ -67,211 +48,11 @@ func (this *MCompConfigure) Init(service core.IService, module core.IModule, com //err = this.LoadConfigure(game_sign, cfg.NewGameSign) err = this.LoadConfigure(game_item, cfg.NewGameItem) err = this.LoadConfigure(game_vip, cfg.NewGameVip) - err = this.LoadConfigure(game_lottery, cfg.NewGameLottery) this._dropMap = make(map[int32][]*cfg.GameDropData, 0) this._sign = make(map[int32]*cfg.GameSignData, 0) configure.RegisterConfigure(game_drop, cfg.NewGameDrop, this.LoadDropData) configure.RegisterConfigure(game_sign, cfg.NewGameSign, this.LoadSignData) - this._group = make(map[int64][]int32, 0) - this._lotteryType1 = make(map[int32][]int32, 0) - this._lotteryType2 = make(map[int32][]int32, 0) - this._groupType1 = make(map[int64][]int32, 0) - this._groupType2 = make(map[int64][]int32, 0) - this.Btype = make(map[int32]int32, 0) - this.Stype = make(map[int64]int32, 0) - this.SNum = make(map[int64]int32, 0) - configure.RegisterConfigure(game_lottery, cfg.NewGameLottery, this.LoadGroupData) - - return -} - -func (this *MCompConfigure) LoadGroupData() { - if v, err := this.GetConfigure(game_lottery); err == nil { - if configure, ok := v.(*cfg.GameLottery); ok { - this.hlock.Lock() - defer this.hlock.Unlock() - this._group = make(map[int64][]int32, 0) - this._lotteryType1 = make(map[int32][]int32, 0) - this._lotteryType2 = make(map[int32][]int32, 0) - this._groupType1 = make(map[int64][]int32, 0) - this._groupType2 = make(map[int64][]int32, 0) - this.Btype = make(map[int32]int32, 0) - this.Stype = make(map[int64]int32, 0) - this.SNum = make(map[int64]int32, 0) - for _, value := range configure.GetDataList() { - key := int64(value.Lotteryid)<<31 + int64(value.Groupid) - this._group[key] = append(this._group[key], value.Id) - - if _, ok := this.Btype[value.Lotteryid]; !ok { - this.Btype[value.Lotteryid] = value.Type - } - - if _, ok := this.Stype[key]; !ok { - this.Stype[key] = value.Subtype - } - if _, ok := this.SNum[key]; !ok { - this.SNum[key] = value.Groupnum - } - if this.Btype[value.Lotteryid] == 1 { - this._lotteryType1[value.Lotteryid] = append(this._lotteryType1[value.Lotteryid], value.Id) - } else if this.Btype[value.Lotteryid] == 2 { - this._lotteryType2[value.Lotteryid] = append(this._lotteryType2[value.Lotteryid], value.Id) - } - - if this.Stype[key] == 1 { // 小组ID为1 - this._groupType1[key] = append(this._groupType1[key], value.Id) - } else if this.Stype[key] == 2 { - this._groupType2[key] = append(this._groupType2[key], value.Id) - } - } - return - } - } else { - log.Errorf("get LoadGroupData conf err:%v", err) - } - return -} - -// 实际掉落逻辑 (传入 掉落组ID vip等级 玩家等级 返回获得的道具) -func (this *MCompConfigure) GetGroupDataByLottery(lotteryId int32, vipLv int32, lv int32) (items []*cfg.Gameatn) { - - if _, ok := this._lotteryType1[lotteryId]; !ok { - if _, ok := this._lotteryType2[lotteryId]; !ok { - fmt.Printf("not found config lotterId:%d", lotteryId) - return - } - } - // 优先校验大组ID 的类型 - if this.Btype[lotteryId] == 1 { // 该大组中的小组为权重掉落,必定从N个小组中随机出1个小组 - var ( - szW []int32 // 权重数组 - szID []int32 // 小组ID 数组 - groupID int32 - gourp map[int32]int32 // key 小组ID value 权重 - ) - - gourp = make(map[int32]int32, 0) - // 随机小组id - for _, v := range this._lotteryType1[lotteryId] { - if _data := this.GetLotterConfById(v); _data != nil { - if (_data.Playerlvmax == 0 || _data.Playerlvmin <= lv && lv <= _data.Playerlvmax) && (_data.VIPmax == 0 || _data.VIPmin <= vipLv && vipLv <= _data.VIPmax) { // 过滤等级等条件 - if _, ok := gourp[_data.Groupid]; !ok { - gourp[_data.Groupid] = _data.Groupwt // 小组ID 权重赋值 - szW = append(szW, _data.Groupwt) - szID = append(szID, _data.Groupid) - } - } - } - } - - groupID = szID[comm.GetRandW(szW)] // 获得小组ID - fmt.Printf("大组类型为1的,获得小组ID :%d,dropID:%d", groupID, lotteryId) - key := int64(lotteryId)<<31 + int64(groupID) - // 小组ID 类型判断 - if this.Stype[key] == 1 { // 该小组的道具为权重掉落,必定从N个道具中随机出1个道具 - for i := 0; i < int(this.SNum[key]); i++ { - szW = make([]int32, 0) - szID = make([]int32, 0) - gourp = make(map[int32]int32, 0) - for _, v := range this._groupType1[key] { - if _data := this.GetLotterConfById(v); _data != nil { // 权重赋值 - if _, ok := gourp[_data.Groupid]; !ok { - szW = append(szW, _data.Itemwt) - szID = append(szID, _data.Id) - } - } - } - index := comm.GetRandW(szW) - _data := this.GetLotterConfById(szID[index]) - fmt.Printf("获得最终的道具 :%d", _data.Id) - count := comm.GetRandNum(_data.Min, _data.Max) - // 随机获得的数量 - items = append(items, &cfg.Gameatn{ - A: _data.Itemid.A, - T: _data.Itemid.T, - N: _data.Itemid.N * count, - }) - } - return - } else if this.Stype[key] == 2 { // 该小组中的道具为概率掉落,每个道具都会随机一次是否会掉落(单位为千分比) - for _, v := range this._groupType2[key] { - if _data := this.GetLotterConfById(v); _data != nil { // 权重赋值 - fmt.Printf("大组类型1小组类型2获得道具 :%v, 该道具Cid:%d", _data.Itemid, v) - if _data.Itemwt >= comm.GetRandNum(1, 1000) { // 命中 - count := comm.GetRandNum(_data.Min, _data.Max) - items = append(items, &cfg.Gameatn{ - A: _data.Itemid.A, - T: _data.Itemid.T, - N: _data.Itemid.N * count, // 小组产出数量 - }) - } - } - } - return - } - } else if this.Btype[lotteryId] == 2 { // 该大组中的小组为概率掉落,每个小组都会随机一次是否会掉落(单位为千分比) - // 每个小组id 都随机取一次 - var szGroupID []int32 // 获得的权重数组 - gourp := make(map[int32]*cfg.GameLotteryData, 0) // key 小组ID value 权重 - for _, v := range this._lotteryType2[lotteryId] { - if _data := this.GetLotterConfById(v); _data != nil { - if (_data.Playerlvmax == 0 || _data.Playerlvmin <= lv && lv <= _data.Playerlvmax) && (_data.VIPmax == 0 || _data.VIPmin <= vipLv && vipLv <= _data.VIPmax) { // 过滤等级等条件 - if _, ok := gourp[_data.Groupid]; !ok { - gourp[_data.Groupid] = _data // 小组ID 权重赋值 - } - } - } - } - - // 类型为2 可能会同时获得多个组id - for k, v := range gourp { - fmt.Printf("大组类型为2的,获得小组ID :%d,dropID:%d", k, v.Id) - if v.Itemwt >= comm.GetRandNum(0, 1000) { // 命中 - szGroupID = append(szGroupID, k) - key := int64(lotteryId)<<31 + int64(k) - if this.Stype[key] == 1 { // 随机一组数据 - for i := 0; i < int(this.SNum[key]); i++ { - szW := make([]int32, 0) - szID := make([]int32, 0) - gourp := make(map[int32]int32, 0) - for _, v := range this._groupType1[key] { - if _data := this.GetLotterConfById(v); _data != nil { // 权重赋值 - if _, ok := gourp[_data.Groupid]; !ok { - szW = append(szW, _data.Itemwt) - szID = append(szID, _data.Id) - } - } - } - index := comm.GetRandW(szW) - _data := this.GetLotterConfById(szID[index]) - fmt.Printf("获得最终的道具 :%d", _data.Id) - count := comm.GetRandNum(_data.Min, _data.Max) - // 随机获得的数量 - items = append(items, &cfg.Gameatn{ - A: _data.Itemid.A, - T: _data.Itemid.T, - N: _data.Itemid.N * count, - }) - } - } else if this.Stype[key] == 2 { - for _, v := range this._groupType2[key] { - if _data := this.GetLotterConfById(v); _data != nil { // 权重赋值 - fmt.Printf("大组类型2小组类型2获得道具 :%v,该道具Cid:%d", _data.Itemid, v) - if _data.Itemwt >= comm.GetRandNum(1, 1000) { // 命中 - count := comm.GetRandNum(_data.Min, _data.Max) - items = append(items, &cfg.Gameatn{ - A: _data.Itemid.A, - T: _data.Itemid.T, - N: _data.Itemid.N * count, // 小组产出数量 - }) - } - } - } - } - } - } - } return } @@ -323,38 +104,6 @@ func (this *MCompConfigure) GetConfigure(name string) (v interface{}, err error) return configure.GetConfigure(name) } -//全局配置 -// func (this *MCompConfigure) GetGlobalConf() *cfg.GameGlobalData { -// var ( -// configure *cfg.GameGlobal -// ok bool -// ) -// if v, err := this.GetConfigure(game_global); err != nil { -// log.Errorf("get global conf err:%v", err) -// return nil -// } else { -// if configure, ok = v.(*cfg.GameGlobal); !ok { -// log.Errorf("%T no is *cfg.Game_global", v) -// return nil -// } -// } -// return configure.GetDataList()[0] // 返回对象信息 -// } - -func (this *MCompConfigure) GetGlobalInitConf() (configure *cfg.GameInitial, err error) { - var ( - v interface{} - ok bool - ) - if v, err = this.GetConfigure(game_initial); err == nil { - if configure, ok = v.(*cfg.GameInitial); !ok { - err = fmt.Errorf("%T no is *cfg.Game_comInitial", v) - return - } - } - return -} - // 主角等级经验配置列表 func (this *MCompConfigure) GetPlayerlvConfList() (list []*cfg.GamePlayerlvData) { if v, err := this.GetConfigure(game_playerlv); err != nil { @@ -578,12 +327,3 @@ func (this *MCompConfigure) GetAllEquipmentConfigure() (configure []*cfg.GameEqu } return } - -func (this *MCompConfigure) GetLotterConfById(id int32) (data *cfg.GameLotteryData) { - if v, err := this.GetConfigure(game_lottery); err == nil { - if configure, ok := v.(*cfg.GameLottery); ok { - return configure.Get(id) - } - } - return -} diff --git a/modules/gm/api_cmd.go b/modules/gm/api_cmd.go index e04b85013..a5056ecc0 100644 --- a/modules/gm/api_cmd.go +++ b/modules/gm/api_cmd.go @@ -37,6 +37,7 @@ import ( 21、bingo:chat,1 22、bingo:itemtype,1,1 // 获取某种类型所有道具(道具类型,数量) 23、bingo:viplv,50 +24、bingo:cleannpc */ //参数校验 func (this *apiComp) CmdCheck(session comm.IUserSession, req *pb.GMCmdReq) (code pb.ErrorCode) { diff --git a/modules/gm/module.go b/modules/gm/module.go index 28b301e72..1301d8231 100644 --- a/modules/gm/module.go +++ b/modules/gm/module.go @@ -463,6 +463,18 @@ func (this *GM) CreateCmd(session comm.IUserSession, cmd string) (code pb.ErrorC log.Field{Key: "0", Value: datas[0]}, log.Field{Key: "N", Value: int32(num)}, ) + } else if len(datas) == 1 && (datas[0] == "cleannpc") { // 充值次数 + module1, err := this.service.GetModule(comm.ModulePractice) + if err != nil { + return + } + + module1.(comm.IPractice).CleanUpNpc(session.GetUserId()) + + this.Debug("使用bingo命令:uid = %s ", + log.Field{Key: "uid", Value: session.GetUserId()}, + log.Field{Key: "0", Value: datas[0]}, + ) } } } diff --git a/modules/practice/api_npcbattklefinish.go b/modules/practice/api_npcbattklefinish.go index 3891fb8ef..831ba607b 100644 --- a/modules/practice/api_npcbattklefinish.go +++ b/modules/practice/api_npcbattklefinish.go @@ -34,7 +34,7 @@ func (this *apiComp) NPCBattkleFinish(session comm.IUserSession, req *pb.Practic } if req.Report.WinSide == 1 { - room.Npcstate = 2 + room.Npcstate = 2 //稍后 状态改成3。让客户端先处理协议 if conf, err = this.module.configure.getDispatchBattleData(room.Currnpc); err != nil { code = pb.ErrorCode_ConfigNoFound return @@ -42,8 +42,10 @@ func (this *apiComp) NPCBattkleFinish(session comm.IUserSession, req *pb.Practic if code = this.module.DispenseRes(session, conf.Award, true); code != pb.ErrorCode_Success { return } + room.Refresh = configure.Now().Unix() this.module.modelPandata.Change(session.GetUserId(), map[string]interface{}{ "npcstate": room.Npcstate, + "refresh": room.Refresh, }) } else { room.Npcstate = 1 diff --git a/modules/practice/module.go b/modules/practice/module.go index 70b8acb85..71767bd3a 100644 --- a/modules/practice/module.go +++ b/modules/practice/module.go @@ -402,3 +402,19 @@ func (this *Practice) RPC_ModulePracticeUnLockPillar(ctx context.Context, args * // } return } + +// 一键踢馆 (跨服) +func (this *Practice) CleanUpNpc(uid string) { + conn_, _ := db.Cross() // 获取跨服数据库对象 + model := db.NewDBModel(comm.TablePandata, time.Hour, conn_) + result := &pb.DBPracticeRoom{} + if err := model.Get(uid, result); err != nil && err != mgo.MongodbNil { + return + } + + result.Refresh = configure.Now().Unix() + this.modelPandata.Change(uid, map[string]interface{}{ // 同步状态即可 + "npcstate": 3, + "refresh": result.Refresh, + }) +} diff --git a/modules/user/comp_configure.go b/modules/user/comp_configure.go index ef1d45dba..9033d2ba5 100644 --- a/modules/user/comp_configure.go +++ b/modules/user/comp_configure.go @@ -15,6 +15,7 @@ const ( game_sign = "game_sign.json" gameOpencond = "game_opencond.json" game_SignExtra = "game_signextra.json" + game_initial = "game_initial.json" //初始化表 ) ///配置管理基础组件 @@ -28,7 +29,7 @@ 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.LoadConfigure(game_initial, cfg.NewGameInitial) this._sign = make(map[int32]*cfg.GameSignData, 0) configure.RegisterConfigure(game_sign, cfg.NewGameSign, this.LoadSignData) this.LoadConfigure(gameOpencond, cfg.NewGameOpencond) @@ -130,3 +131,17 @@ func (this *configureComp) GetSignExtarConf(day, group int32) *cfg.GameSignExtra } return nil } + +func (this *configureComp) GetGlobalInitConf() (configure *cfg.GameInitial, err error) { + var ( + v interface{} + ok bool + ) + if v, err = this.GetConfigure(game_initial); err == nil { + if configure, ok = v.(*cfg.GameInitial); !ok { + err = fmt.Errorf("%T no is *cfg.Game_comInitial", v) + return + } + } + return +}