diff --git a/comm/const.go b/comm/const.go index 5b3b6c90e..146dadf1d 100644 --- a/comm/const.go +++ b/comm/const.go @@ -265,6 +265,9 @@ const ( // 活动列表 TableHdList = "huodong" + + //世界任务 + TableWtask = "wtask" ) // RPC服务接口定义处 diff --git a/modules/wtask/api.go b/modules/wtask/api.go new file mode 100644 index 000000000..10fffb023 --- /dev/null +++ b/modules/wtask/api.go @@ -0,0 +1,20 @@ +package wtask + +import ( + "go_dreamfactory/lego/base" + "go_dreamfactory/lego/core" + "go_dreamfactory/modules" +) + +type apiComp struct { + modules.MCompGate + service base.IRPCXService + module *WTask +} + +func (this *apiComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { + _ = this.MCompGate.Init(service, module, comp, options) + this.service = service.(base.IRPCXService) + this.module = module.(*WTask) + return +} diff --git a/modules/wtask/configure.go b/modules/wtask/configure.go new file mode 100644 index 000000000..2cf0a41b5 --- /dev/null +++ b/modules/wtask/configure.go @@ -0,0 +1,156 @@ +package wtask + +import ( + "fmt" + "go_dreamfactory/comm" + "go_dreamfactory/lego/core" + "go_dreamfactory/modules" + "go_dreamfactory/sys/configure" + cfg "go_dreamfactory/sys/configure/structs" + "sync" +) + +const ( + gameWorldTask = "game_worldtask.json" + gameWorldtaskBattle = "game_worldbattle.json" + gameWorldAll = "game_worldall.json" + gameburiedCond = "game_buriedcondi.json" + gamerdtasknpc = "game_rdtasknpc.json" +) + +type configureComp struct { + modules.MCompConfigure + lock sync.RWMutex + worldtaskConf map[int32]*cfg.GameWorldTaskData //key 条件ID +} + +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{}{ + gameWorldTask: cfg.NewGameWorldTask, + gameWorldtaskBattle: cfg.NewGameWorldBattle, + gameWorldAll: cfg.NewGameWorldAll, + gameburiedCond: cfg.NewGameBuriedCondi, + gamerdtasknpc: cfg.NewGameRdtaskNpc, + }) + this.worldtaskConf = make(map[int32]*cfg.GameWorldTaskData) + configure.RegisterConfigure(gameWorldTask, cfg.NewGameBuriedCondi, this.updateconfigure) + return +} + +func (this *configureComp) getWorldtaskCfg() (data *cfg.GameWorldTask, err error) { + var ( + v interface{} + ok bool + ) + if v, err = this.GetConfigure(gameWorldTask); err != nil { + return + } else { + if data, ok = v.(*cfg.GameWorldTask); !ok { + err = fmt.Errorf("%T is *cfg.GameWorldTask", v) + return + } + } + return +} + +func (this *configureComp) updateconfigure() { + gwt, err := this.getWorldtaskCfg() + if err != nil { + return + } + + this.lock.Lock() + this.worldtaskConf = gwt.GetDataMap() + this.lock.Unlock() +} + +func (this *configureComp) getWorldAllCfg() (data *cfg.GameWorldAll, err error) { + var ( + v interface{} + ok bool + ) + if v, err = this.GetConfigure(gameWorldAll); err != nil { + return + } else { + if data, ok = v.(*cfg.GameWorldAll); !ok { + err = fmt.Errorf("%T is *cfg.GameWorldAll", v) + return + } + } + return +} + +func (this *configureComp) getWorldtaskById(taskId int32) (*cfg.GameWorldTaskData, error) { + gwt, err := this.getWorldtaskCfg() + if err != nil { + return nil, err + } + if data, ok := gwt.GetDataMap()[taskId]; ok { + return data, nil + } + return nil, comm.NewNotFoundConfErr(modulename, gameWorldTask, taskId) +} + +func (this *configureComp) getNPCById(npcId int32) (npc *cfg.GameRdtaskNpcData, err error) { + var ( + v interface{} + ) + if v, err = this.GetConfigure(gamerdtasknpc); err != nil { + return + } else { + data, ok := v.(*cfg.GameRdtaskNpc) + if !ok { + err = fmt.Errorf("%T is *cfg.GameRdtaskNpc", v) + return + } + if npc, ok = data.GetDataMap()[npcId]; ok { + return + } + err = comm.NewNotFoundConfErr(modulename, gamerdtasknpc, npc) + } + return +} + +func (this *configureComp) getWorldtaskBattleCfg() (data *cfg.GameWorldBattle, err error) { + var ( + v interface{} + ok bool + ) + if v, err = this.GetConfigure(gameWorldtaskBattle); err != nil { + return + } else { + if data, ok = v.(*cfg.GameWorldBattle); !ok { + err = fmt.Errorf("%T is *cfg.GameWorldBattle", v) + return + } + } + return +} + +func (this *configureComp) getWorldtaskBattleById(confId int32) (*cfg.GameWorldBattleData, error) { + gwt, err := this.getWorldtaskBattleCfg() + if err != nil { + return nil, err + } + if data, ok := gwt.GetDataMap()[confId]; ok { + return data, nil + } + return nil, fmt.Errorf("GameWorldBattleData config id:%v not found", confId) +} + +func (this *configureComp) getBuriedCondCfg() (data *cfg.GameBuriedCondi, err error) { + var ( + v interface{} + ok bool + ) + if v, err = this.GetConfigure(gameburiedCond); err != nil { + return + } else { + if data, ok = v.(*cfg.GameBuriedCondi); !ok { + err = fmt.Errorf("%T is *cfg.GameWorldAll", v) + return + } + } + return +} diff --git a/modules/wtask/modelWTask.go b/modules/wtask/modelWTask.go new file mode 100644 index 000000000..2bffdaf06 --- /dev/null +++ b/modules/wtask/modelWTask.go @@ -0,0 +1,25 @@ +package wtask + +import ( + "go_dreamfactory/comm" + "go_dreamfactory/lego/core" + "go_dreamfactory/modules" + + "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/x/bsonx" +) + +type ModelWTask struct { + modules.MCompModel + module *WTask +} + +func (this *ModelWTask) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { + err = this.MCompModel.Init(service, module, comp, options) + this.TableName = comm.TableWtask + this.module = module.(*WTask) + this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{ + Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}}, + }) + return +} diff --git a/modules/wtask/module.go b/modules/wtask/module.go new file mode 100644 index 000000000..61a84ab59 --- /dev/null +++ b/modules/wtask/module.go @@ -0,0 +1,37 @@ +package wtask + +import ( + "go_dreamfactory/comm" + "go_dreamfactory/lego/core" + "go_dreamfactory/modules" +) + +const modulename = "世界任务" + +type WTask struct { + modules.ModuleBase + api *apiComp + configure *configureComp + modelwtask *ModelWTask +} + +func NewModule() core.IModule { + return &WTask{} +} + +func (this *WTask) GetType() core.M_Modules { + return comm.ModuleWorldtask +} + +func (this *WTask) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) { + err = this.ModuleBase.Init(service, module, options) + return +} + +func (this *WTask) OnInstallComp() { + this.ModuleBase.OnInstallComp() + this.api = this.RegisterComp(new(apiComp)).(*apiComp) + this.modelwtask = this.RegisterComp(new(ModelWTask)).(*ModelWTask) + this.configure = this.RegisterComp(new(configureComp)).(*configureComp) + +}