From 7d990f06c5fbeb273ea4651a4ebbeacf8165fd37 Mon Sep 17 00:00:00 2001 From: wh_zcy Date: Tue, 31 Jan 2023 15:04:58 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=9F=E8=83=BD=E5=BC=80=E5=8F=91=E6=9D=A1?= =?UTF-8?q?=E4=BB=B6=E6=94=AF=E6=8C=81=E5=A4=9A=E6=9D=A1=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/json/game_opencond.json | 338 ++++++++++----------- comm/imodule.go | 2 + modules/sys/api_func.go | 19 +- modules/sys/model_sys.go | 44 ++- modules/sys/module.go | 5 + modules/user/comp_configure.go | 16 +- modules/user/model_user.go | 15 +- sys/configure/structs/Game.OpencondType.go | 16 + sys/configure/structs/Game.OpenedCond.go | 4 +- 9 files changed, 267 insertions(+), 192 deletions(-) create mode 100644 sys/configure/structs/Game.OpencondType.go diff --git a/bin/json/game_opencond.json b/bin/json/game_opencond.json index cce4953ff..19d7d8a83 100644 --- a/bin/json/game_opencond.json +++ b/bin/json/game_opencond.json @@ -7,11 +7,11 @@ }, "main": [ { - "key": "platlv", + "key": 1, "param": 1 }, { - "key": "maxmapid", + "key": 2, "param": 1 } ], @@ -33,11 +33,11 @@ }, "main": [ { - "key": "platlv", - "param": 5 + "key": 1, + "param": 1 }, { - "key": "maxmapid", + "key": 2, "param": 1 } ], @@ -59,11 +59,11 @@ }, "main": [ { - "key": "platlv", + "key": 1, "param": 1 }, { - "key": "maxmapid", + "key": 2, "param": 1 } ], @@ -85,11 +85,11 @@ }, "main": [ { - "key": "platlv", - "param": 3 + "key": 1, + "param": 1 }, { - "key": "maxmapid", + "key": 2, "param": 1 } ], @@ -111,11 +111,11 @@ }, "main": [ { - "key": "platlv", - "param": 999 + "key": 1, + "param": 1 }, { - "key": "maxmapid", + "key": 2, "param": 1 } ], @@ -137,11 +137,11 @@ }, "main": [ { - "key": "platlv", - "param": 3 + "key": 1, + "param": 1 }, { - "key": "maxmapid", + "key": 2, "param": 1 } ], @@ -163,11 +163,11 @@ }, "main": [ { - "key": "platlv", + "key": 1, "param": 1 }, { - "key": "maxmapid", + "key": 2, "param": 1 } ], @@ -189,11 +189,11 @@ }, "main": [ { - "key": "platlv", + "key": 1, "param": 1 }, { - "key": "maxmapid", + "key": 2, "param": 1 } ], @@ -215,11 +215,11 @@ }, "main": [ { - "key": "platlv", - "param": 10 + "key": 1, + "param": 1 }, { - "key": "maxmapid", + "key": 2, "param": 1 } ], @@ -241,11 +241,11 @@ }, "main": [ { - "key": "platlv", - "param": 2 + "key": 1, + "param": 1 }, { - "key": "maxmapid", + "key": 2, "param": 1 } ], @@ -267,11 +267,11 @@ }, "main": [ { - "key": "platlv", + "key": 1, "param": 1 }, { - "key": "maxmapid", + "key": 2, "param": 1 } ], @@ -293,11 +293,11 @@ }, "main": [ { - "key": "platlv", - "param": 999 + "key": 1, + "param": 1 }, { - "key": "maxmapid", + "key": 2, "param": 1 } ], @@ -319,11 +319,11 @@ }, "main": [ { - "key": "platlv", - "param": 10 + "key": 1, + "param": 1 }, { - "key": "maxmapid", + "key": 2, "param": 1 } ], @@ -345,11 +345,11 @@ }, "main": [ { - "key": "platlv", - "param": 999 + "key": 1, + "param": 1 }, { - "key": "maxmapid", + "key": 2, "param": 1 } ], @@ -371,11 +371,11 @@ }, "main": [ { - "key": "platlv", - "param": 999 + "key": 1, + "param": 1 }, { - "key": "maxmapid", + "key": 2, "param": 1 } ], @@ -397,11 +397,11 @@ }, "main": [ { - "key": "platlv", - "param": 3 + "key": 1, + "param": 1 }, { - "key": "maxmapid", + "key": 2, "param": 1 } ], @@ -423,11 +423,11 @@ }, "main": [ { - "key": "platlv", - "param": 3 + "key": 1, + "param": 1 }, { - "key": "maxmapid", + "key": 2, "param": 1 } ], @@ -449,11 +449,11 @@ }, "main": [ { - "key": "platlv", - "param": 3 + "key": 1, + "param": 1 }, { - "key": "maxmapid", + "key": 2, "param": 1 } ], @@ -475,11 +475,11 @@ }, "main": [ { - "key": "platlv", - "param": 3 + "key": 1, + "param": 1 }, { - "key": "maxmapid", + "key": 2, "param": 1 } ], @@ -501,11 +501,11 @@ }, "main": [ { - "key": "platlv", - "param": 999 + "key": 1, + "param": 1 }, { - "key": "maxmapid", + "key": 2, "param": 1 } ], @@ -527,11 +527,11 @@ }, "main": [ { - "key": "platlv", - "param": 999 + "key": 1, + "param": 1 }, { - "key": "maxmapid", + "key": 2, "param": 1 } ], @@ -553,11 +553,11 @@ }, "main": [ { - "key": "platlv", - "param": 999 + "key": 1, + "param": 1 }, { - "key": "maxmapid", + "key": 2, "param": 1 } ], @@ -579,11 +579,11 @@ }, "main": [ { - "key": "platlv", - "param": 999 + "key": 1, + "param": 1 }, { - "key": "maxmapid", + "key": 2, "param": 1 } ], @@ -605,11 +605,11 @@ }, "main": [ { - "key": "platlv", - "param": 999 + "key": 1, + "param": 1 }, { - "key": "maxmapid", + "key": 2, "param": 1 } ], @@ -631,11 +631,11 @@ }, "main": [ { - "key": "platlv", - "param": 999 + "key": 1, + "param": 1 }, { - "key": "maxmapid", + "key": 2, "param": 1 } ], @@ -657,11 +657,11 @@ }, "main": [ { - "key": "platlv", - "param": 999 + "key": 1, + "param": 1 }, { - "key": "maxmapid", + "key": 2, "param": 1 } ], @@ -683,11 +683,11 @@ }, "main": [ { - "key": "platlv", - "param": 10 + "key": 1, + "param": 1 }, { - "key": "maxmapid", + "key": 2, "param": 1 } ], @@ -709,11 +709,11 @@ }, "main": [ { - "key": "platlv", - "param": 10 + "key": 1, + "param": 1 }, { - "key": "maxmapid", + "key": 2, "param": 1 } ], @@ -735,7 +735,7 @@ }, "main": [ { - "key": "platlv", + "key": 1, "param": 1 } ], @@ -757,11 +757,11 @@ }, "main": [ { - "key": "platlv", - "param": 999 + "key": 1, + "param": 1 }, { - "key": "maxmapid", + "key": 2, "param": 1 } ], @@ -783,11 +783,11 @@ }, "main": [ { - "key": "platlv", + "key": 1, "param": 1 }, { - "key": "maxmapid", + "key": 2, "param": 1 } ], @@ -809,11 +809,11 @@ }, "main": [ { - "key": "platlv", + "key": 1, "param": 1 }, { - "key": "maxmapid", + "key": 2, "param": 1 } ], @@ -835,11 +835,11 @@ }, "main": [ { - "key": "platlv", + "key": 1, "param": 1 }, { - "key": "maxmapid", + "key": 2, "param": 1 } ], @@ -861,11 +861,11 @@ }, "main": [ { - "key": "platlv", + "key": 1, "param": 1 }, { - "key": "maxmapid", + "key": 2, "param": 1 } ], @@ -887,11 +887,11 @@ }, "main": [ { - "key": "platlv", + "key": 1, "param": 1 }, { - "key": "maxmapid", + "key": 2, "param": 1 } ], @@ -913,11 +913,11 @@ }, "main": [ { - "key": "platlv", + "key": 1, "param": 1 }, { - "key": "maxmapid", + "key": 2, "param": 1 } ], @@ -939,11 +939,11 @@ }, "main": [ { - "key": "platlv", - "param": 3 + "key": 1, + "param": 1 }, { - "key": "maxmapid", + "key": 2, "param": 1 } ], @@ -965,11 +965,11 @@ }, "main": [ { - "key": "platlv", - "param": 3 + "key": 1, + "param": 1 }, { - "key": "maxmapid", + "key": 2, "param": 1 } ], @@ -991,11 +991,11 @@ }, "main": [ { - "key": "platlv", - "param": 999 + "key": 1, + "param": 1 }, { - "key": "maxmapid", + "key": 2, "param": 1 } ], @@ -1017,11 +1017,11 @@ }, "main": [ { - "key": "platlv", - "param": 3 + "key": 1, + "param": 1 }, { - "key": "maxmapid", + "key": 2, "param": 1 } ], @@ -1043,11 +1043,11 @@ }, "main": [ { - "key": "platlv", - "param": 3 + "key": 1, + "param": 1 }, { - "key": "maxmapid", + "key": 2, "param": 1 } ], @@ -1069,11 +1069,11 @@ }, "main": [ { - "key": "platlv", - "param": 3 + "key": 1, + "param": 1 }, { - "key": "maxmapid", + "key": 2, "param": 1 } ], @@ -1095,11 +1095,11 @@ }, "main": [ { - "key": "platlv", - "param": 3 + "key": 1, + "param": 1 }, { - "key": "maxmapid", + "key": 2, "param": 1 } ], @@ -1121,11 +1121,11 @@ }, "main": [ { - "key": "platlv", - "param": 20 + "key": 1, + "param": 1 }, { - "key": "maxmapid", + "key": 2, "param": 1 } ], @@ -1147,11 +1147,11 @@ }, "main": [ { - "key": "platlv", - "param": 3 + "key": 1, + "param": 1 }, { - "key": "maxmapid", + "key": 2, "param": 1 } ], @@ -1173,11 +1173,11 @@ }, "main": [ { - "key": "platlv", - "param": 13 + "key": 1, + "param": 1 }, { - "key": "maxmapid", + "key": 2, "param": 1 } ], @@ -1199,11 +1199,11 @@ }, "main": [ { - "key": "platlv", - "param": 10 + "key": 1, + "param": 1 }, { - "key": "maxmapid", + "key": 2, "param": 1 } ], @@ -1225,7 +1225,7 @@ }, "main": [ { - "key": "platlv", + "key": 1, "param": 1 } ], @@ -1247,7 +1247,7 @@ }, "main": [ { - "key": "platlv", + "key": 1, "param": 1 } ], @@ -1269,7 +1269,7 @@ }, "main": [ { - "key": "platlv", + "key": 1, "param": 1 } ], @@ -1291,11 +1291,11 @@ }, "main": [ { - "key": "platlv", - "param": 5 + "key": 1, + "param": 1 }, { - "key": "maxmapid", + "key": 2, "param": 1 } ], @@ -1317,11 +1317,11 @@ }, "main": [ { - "key": "platlv", - "param": 4 + "key": 1, + "param": 1 }, { - "key": "maxmapid", + "key": 2, "param": 1 } ], @@ -1343,11 +1343,11 @@ }, "main": [ { - "key": "platlv", - "param": 5 + "key": 1, + "param": 1 }, { - "key": "maxmapid", + "key": 2, "param": 1 } ], @@ -1369,11 +1369,11 @@ }, "main": [ { - "key": "platlv", - "param": 5 + "key": 1, + "param": 1 }, { - "key": "maxmapid", + "key": 2, "param": 1 } ], @@ -1395,11 +1395,11 @@ }, "main": [ { - "key": "platlv", - "param": 5 + "key": 1, + "param": 1 }, { - "key": "maxmapid", + "key": 2, "param": 1 } ], @@ -1421,11 +1421,11 @@ }, "main": [ { - "key": "platlv", - "param": 10 + "key": 1, + "param": 1 }, { - "key": "maxmapid", + "key": 2, "param": 1 } ], @@ -1447,11 +1447,11 @@ }, "main": [ { - "key": "platlv", + "key": 1, "param": 1 }, { - "key": "maxmapid", + "key": 2, "param": 1 } ], @@ -1473,11 +1473,11 @@ }, "main": [ { - "key": "platlv", - "param": 10 + "key": 1, + "param": 1 }, { - "key": "maxmapid", + "key": 2, "param": 1 } ], @@ -1499,11 +1499,11 @@ }, "main": [ { - "key": "platlv", - "param": 10 + "key": 1, + "param": 1 }, { - "key": "maxmapid", + "key": 2, "param": 1 } ], @@ -1525,11 +1525,11 @@ }, "main": [ { - "key": "platlv", - "param": 10 + "key": 1, + "param": 1 }, { - "key": "maxmapid", + "key": 2, "param": 1 } ], @@ -1551,11 +1551,11 @@ }, "main": [ { - "key": "platlv", - "param": 30 + "key": 1, + "param": 1 }, { - "key": "maxmapid", + "key": 2, "param": 1 } ], @@ -1577,8 +1577,8 @@ }, "main": [ { - "key": "worldtaskid", - "param": 20050 + "key": 3, + "param": 20010 } ], "optional": "", @@ -1599,8 +1599,8 @@ }, "main": [ { - "key": "worldtaskid", - "param": 20050 + "key": 3, + "param": 20010 } ], "optional": "", @@ -1621,8 +1621,8 @@ }, "main": [ { - "key": "worldtaskid", - "param": 20050 + "key": 3, + "param": 20010 } ], "optional": "", diff --git a/comm/imodule.go b/comm/imodule.go index 4471cea98..2b745176b 100644 --- a/comm/imodule.go +++ b/comm/imodule.go @@ -2,6 +2,7 @@ package comm import ( "go_dreamfactory/pb" + cfg "go_dreamfactory/sys/configure/structs" ) type ( @@ -17,6 +18,7 @@ type ( type ( ISys interface { IsAccess(funcName string, uid string) (code pb.ErrorCode) + ValidCond(uid string, conf *cfg.GameOpencondData) string } //邮件业务模块对外接口定义 提供给其他模块使用的 diff --git a/modules/sys/api_func.go b/modules/sys/api_func.go index 2522634f1..3aa6be614 100644 --- a/modules/sys/api_func.go +++ b/modules/sys/api_func.go @@ -25,13 +25,9 @@ func (this *apiComp) Funclist(session comm.IUserSession, req *pb.SysFuncListReq) if len(req.Keys) == 0 { confList := this.moduleSys.configure.getOpencondList() for _, v := range confList { - // 返回未开启的功能列表 - for _, conf := range v.Main { - // 校验玩家等级 - if conf.Key == "platlv" && user.Lv >= conf.Param { - funcList = append(funcList, v.Id) - continue - } + id := this.moduleSys.modelSys.validCond(session.GetUserId(), v) + if id != "" { + funcList = append(funcList, id) } } } else { @@ -41,12 +37,9 @@ func (this *apiComp) Funclist(session comm.IUserSession, req *pb.SysFuncListReq) continue } if conf, ok := opencfg.GetDataMap()[key]; ok { - for _, main := range conf.Main { - // 校验玩家等级 - if main.Key == "platlv" && user.Lv >= main.Param { - funcList = append(funcList, key) - continue - } + id := this.moduleSys.modelSys.validCond(session.GetUserId(), conf) + if id != "" { + funcList = append(funcList, id) } } } diff --git a/modules/sys/model_sys.go b/modules/sys/model_sys.go index 3cef80442..39be355be 100644 --- a/modules/sys/model_sys.go +++ b/modules/sys/model_sys.go @@ -5,6 +5,7 @@ import ( "go_dreamfactory/lego/core" "go_dreamfactory/modules" "go_dreamfactory/pb" + cfg "go_dreamfactory/sys/configure/structs" ) type ModelSys struct { @@ -27,14 +28,45 @@ func (this *ModelSys) IsAccess(funName string, uid string) (code pb.ErrorCode) { if user != nil { conf := this.moduleSys.configure.getFuncCfg(funName) if conf != nil { - for _, v := range conf.Main { - if v.Key == "platlv" && user.Lv < v.Param { - code = pb.ErrorCode_NoOpened - return - } - } + this.validCond(uid, conf) } } return } + +func (this *ModelSys) validCond(uid string, condData *cfg.GameOpencondData) string { + var flag bool + for _, conf := range condData.Main { + switch conf.Key { + case 1: //等级 + iuser := this.moduleSys.ModuleUser + user := iuser.GetUser(uid) + if user == nil { + return "" + } + if user.Lv >= conf.Param { + flag = true + } + case 2: //关卡ID + flag = true + + case 3: //世界任务ID + module, err := this.service.GetModule(comm.ModuleWorldtask) + if err != nil { + this.moduleSys.Debugln(err) + return "" + } + if i, ok := module.(comm.IWorldtask); ok { + d := i.GetMyWorldtask(uid) + if _, ok := d.LastTaskIds[conf.Param]; ok { + flag = true + } + } + } + if flag { + return condData.Id + } + } + return "" +} diff --git a/modules/sys/module.go b/modules/sys/module.go index a8174cf58..23c5be9e2 100644 --- a/modules/sys/module.go +++ b/modules/sys/module.go @@ -5,6 +5,7 @@ import ( "go_dreamfactory/lego/core" "go_dreamfactory/modules" "go_dreamfactory/pb" + cfg "go_dreamfactory/sys/configure/structs" ) var _ comm.ISys = (*ModuleSys)(nil) @@ -40,3 +41,7 @@ func (this *ModuleSys) GetType() core.M_Modules { func (this *ModuleSys) IsAccess(funcName string, userId string) (code pb.ErrorCode) { return this.modelSys.IsAccess(funcName, userId) } + +func (this *ModuleSys) ValidCond(uid string, conf *cfg.GameOpencondData) string { + return this.modelSys.validCond(uid, conf) +} diff --git a/modules/user/comp_configure.go b/modules/user/comp_configure.go index a3acca4ac..e0a48c412 100644 --- a/modules/user/comp_configure.go +++ b/modules/user/comp_configure.go @@ -68,6 +68,20 @@ func (this *configureComp) LoadSignData() { return } +func (this *configureComp) GetOpenCondList() []*cfg.GameOpencondData { + if v, err := this.GetConfigure(gameOpencond); err != nil { + return nil + } else { + data, ok := v.(*cfg.GameOpencond) + if !ok { + err = fmt.Errorf("%T no is *cfg.GameOpencond", v) + return nil + } + return data.GetDataList() + } + return nil +} + func (this *configureComp) FindFunc(lv int32) (funcIds []string) { if v, err := this.GetConfigure(gameOpencond); err != nil { return nil @@ -79,7 +93,7 @@ func (this *configureComp) FindFunc(lv int32) (funcIds []string) { } for _, d := range data.GetDataList() { for _, v := range d.Main { - if v.Key == "platlv" && v.Param == lv { + if v.Key == 1 && v.Param == lv { funcIds = append(funcIds, d.Id) continue } diff --git a/modules/user/model_user.go b/modules/user/model_user.go index f4dee732f..b52d56b5d 100644 --- a/modules/user/model_user.go +++ b/modules/user/model_user.go @@ -273,7 +273,20 @@ func (this *ModelUser) ChangeLevel(event interface{}, next func(event interface{ ) return } - et.TriggerEvent(comm.EventOpenCond, ul.session.GetUserId(), this.module.configure.FindFunc(curLv)) + module, err2 := this.module.service.GetModule(comm.ModuleSys) + if err2 == nil { + if isys, ok := module.(comm.ISys); ok { + var funcList []string + for _, conf := range this.module.configure.GetOpenCondList() { + id := isys.ValidCond(ul.session.GetUserId(), conf) + if id != "" { + funcList = append(funcList, id) + } + } + + et.TriggerEvent(comm.EventOpenCond, ul.session.GetUserId(), funcList) + } + } if err := ul.session.SendMsg(string(this.module.GetType()), UserSubTypeLvChangedPush, &pb.UserLvChangedPush{Uid: ul.session.GetUserId(), Exp: curExp, Lv: curLv}); err != nil { this.module.Error("玩家等级变化 UserSubTypeLvChangedPush推送失败", diff --git a/sys/configure/structs/Game.OpencondType.go b/sys/configure/structs/Game.OpencondType.go new file mode 100644 index 000000000..01706bec6 --- /dev/null +++ b/sys/configure/structs/Game.OpencondType.go @@ -0,0 +1,16 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +package cfg + +const ( + GameOpencondType_None = 0 + GameOpencondType_Platlv = 1 + GameOpencondType_Maxmapid = 2 + GameOpencondType_Worldtaskid = 3 +) diff --git a/sys/configure/structs/Game.OpenedCond.go b/sys/configure/structs/Game.OpenedCond.go index ed98c2e01..63eaaf150 100644 --- a/sys/configure/structs/Game.OpenedCond.go +++ b/sys/configure/structs/Game.OpenedCond.go @@ -11,7 +11,7 @@ package cfg import "errors" type GameOpenedCond struct { - Key string + Key int32 Param int32 } @@ -22,7 +22,7 @@ func (*GameOpenedCond) GetTypeId() int32 { } func (_v *GameOpenedCond)Deserialize(_buf map[string]interface{}) (err error) { - { var _ok_ bool; if _v.Key, _ok_ = _buf["key"].(string); !_ok_ { err = errors.New("key error"); return } } + { var _ok_ bool; var _tempNum_ float64; if _tempNum_, _ok_ = _buf["key"].(float64); !_ok_ { err = errors.New("key error"); return }; _v.Key = int32(_tempNum_) } { var _ok_ bool; var _tempNum_ float64; if _tempNum_, _ok_ = _buf["param"].(float64); !_ok_ { err = errors.New("param error"); return }; _v.Param = int32(_tempNum_) } return }