From a33fc8fe6f765d539d9065fa9bd37c560e2453ca Mon Sep 17 00:00:00 2001 From: liwei Date: Mon, 7 Nov 2022 21:38:52 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E6=8E=A8=E9=80=81=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/json/game_chatsystem.json | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/bin/json/game_chatsystem.json b/bin/json/game_chatsystem.json index 812bd8558..bb4bc43e8 100644 --- a/bin/json/game_chatsystem.json +++ b/bin/json/game_chatsystem.json @@ -1,6 +1,7 @@ [ { "key": 10001, + "display": false, "type": 1, "text": { "key": "chat_text_10001", @@ -21,6 +22,7 @@ }, { "key": 10002, + "display": false, "type": 1, "text": { "key": "chat_text_10002", @@ -39,6 +41,7 @@ }, { "key": 10003, + "display": false, "type": 1, "text": { "key": "chat_text_10003", @@ -57,6 +60,7 @@ }, { "key": 20001, + "display": false, "type": 2, "text": { "key": "chat_text_20001", @@ -69,6 +73,7 @@ }, { "key": 30002, + "display": true, "type": 3, "text": { "key": "chat_text_30002", @@ -81,6 +86,7 @@ }, { "key": 30003, + "display": true, "type": 3, "text": { "key": "chat_text_30003", @@ -93,6 +99,7 @@ }, { "key": 30004, + "display": true, "type": 3, "text": { "key": "chat_text_30004", @@ -105,6 +112,7 @@ }, { "key": 40001, + "display": false, "type": 4, "text": { "key": "chat_text_40001", From 1ce78945f408867dc8a92a2d8ead99e8ddc7d87a Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Mon, 7 Nov 2022 21:55:08 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=AF=8F=E6=97=A5=E7=AD=BE=E5=88=B0?= =?UTF-8?q?=E6=A3=80=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/troll/api_getReward.go | 2 +- modules/troll/module.go | 7 ++- modules/user/api_login.go | 3 ++ modules/user/comp_configure.go | 66 ++++++++++++++++++++++++++++ modules/user/model_sign.go | 79 ++++++++++++++++++++++++++++------ modules/user/module.go | 4 +- 6 files changed, 146 insertions(+), 15 deletions(-) create mode 100644 modules/user/comp_configure.go diff --git a/modules/troll/api_getReward.go b/modules/troll/api_getReward.go index c7982e102..1a68eccad 100644 --- a/modules/troll/api_getReward.go +++ b/modules/troll/api_getReward.go @@ -24,7 +24,7 @@ func (this *apiComp) GetReward(session comm.IUserSession, req *pb.TrollNpcReward code = pb.ErrorCode_DBError return } - conf := this.configure.GetTrollLv(req.RewardId) + conf := this.module.configure.GetTrollLv(req.RewardId) if conf == nil { code = pb.ErrorCode_ReqParameterError } diff --git a/modules/troll/module.go b/modules/troll/module.go index 8cf6afffa..bd016bb00 100644 --- a/modules/troll/module.go +++ b/modules/troll/module.go @@ -160,7 +160,12 @@ func (this *Troll) TrollAI(session comm.IUserSession, troll *pb.DBTrollTrain) (c update["aiCount"] = troll.AiCount update["gridNum"] = troll.GridNum update["totalEarn"] = troll.TotalEarn - + if confLv := this.configure.GetTrollLv(troll.GetNpcLv() + 1); confLv != nil { + if troll.TotalEarn >= int64(confLv.Money) { + troll.NpcLv += 1 // npc levelUp + update["npcLv"] = troll.NpcLv + } + } this.ModifyTrollData(session.GetUserId(), update) return } diff --git a/modules/user/api_login.go b/modules/user/api_login.go index e8b59b647..d189e838c 100644 --- a/modules/user/api_login.go +++ b/modules/user/api_login.go @@ -142,6 +142,9 @@ func (this *apiComp) Login(session comm.IUserSession, req *pb.UserLoginReq) (cod // 日常登录任务 this.module.ModuleRtask.SendToRtask(session, comm.Rtype7, 1) + // 每日签到检测 + this.module.modelSign.checkResetSignData(session) + //推送登录公告 this.chat.SendSysChatToUser(session, comm.UserLoginNotice, 0) mail := &pb.DBMailData{ diff --git a/modules/user/comp_configure.go b/modules/user/comp_configure.go new file mode 100644 index 000000000..f9d611ee0 --- /dev/null +++ b/modules/user/comp_configure.go @@ -0,0 +1,66 @@ +package user + +import ( + "go_dreamfactory/lego/core" + "go_dreamfactory/lego/sys/log" + "go_dreamfactory/modules" + "go_dreamfactory/sys/configure" + cfg "go_dreamfactory/sys/configure/structs" + "sync" +) + +const ( + game_signreset = "game_signreset.json" + game_sign = "game_sign.json" +) + +///配置管理基础组件 +type configureComp struct { + hlock sync.RWMutex + modules.MCompConfigure + _sign map[int32]*cfg.GameSignData +} + +//组件初始化接口 +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) + + this._sign = make(map[int32]*cfg.GameSignData, 0) + configure.RegisterConfigure(game_sign, cfg.NewGameSign, this.LoadSignData) + return +} + +// 获取签到信息 +func (this *configureComp) GetSignConf(day, group int32) *cfg.GameSignData { + if v, ok := this._sign[day<<8+group]; ok { + return v + } + return nil +} + +// 获取组id +func (this *configureComp) GetSignResetConf(id int32) int32 { + if v, err := this.GetConfigure(game_signreset); err == nil { + if configure, ok := v.(*cfg.GameSignReset); ok { + if configure != nil { + return configure.Get(id).Groups + } + } + } + return -1 +} +func (this *configureComp) LoadSignData() { + if v, err := this.GetConfigure(game_sign); err == nil { + if configure, ok := v.(*cfg.GameSign); ok { + this.hlock.Lock() + defer this.hlock.Unlock() + for _, value := range configure.GetDataList() { + this._sign[value.Day<<8+value.Group] = value + } + return + } + } else { + log.Errorf("get game_sign conf err:%v", err) + } + return +} diff --git a/modules/user/model_sign.go b/modules/user/model_sign.go index 6d0d36f79..4d2c4dacc 100644 --- a/modules/user/model_sign.go +++ b/modules/user/model_sign.go @@ -1,6 +1,7 @@ package user import ( + "errors" "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/modules" @@ -8,6 +9,7 @@ import ( "go_dreamfactory/utils" "time" + "go.mongodb.org/mongo-driver/bson/primitive" "go.mongodb.org/mongo-driver/mongo" ) @@ -26,7 +28,27 @@ func (this *ModelSign) Init(service core.IService, module core.IModule, comp cor func (this *ModelSign) GetUserSign(uid string) (result *pb.DBSign, err error) { result = &pb.DBSign{} - if err = this.module.modelSign.Get(uid, result); err != nil && mongo.ErrNoDocuments != err { + if err = this.module.modelSign.Get(uid, result); err != nil { + if mongo.ErrNoDocuments == err { // 创建一条新的数据 + _data := this.module.configure.GetSignConf(1, 1) + if _data != nil { + result = &pb.DBSign{ + Id: primitive.NewObjectID().Hex(), + Uid: uid, + SignTime: 0, + SignCount: 0, + Group: _data.Group, + Cid: 0, + RTime: 0, + } + this.Add(uid, result) + } else { + err = errors.New("conf err") + return nil, err + } + + } + err = nil return } err = nil @@ -55,17 +77,50 @@ func (this *ModelSign) updateSignData(uid string, sign *pb.DBSign) (err error) { return } -// 重置签到数据 -func (this *ModelSign) resetSignData(uid string, sign *pb.DBSign) (err error) { - start, _ := utils.GetMonthStartEnd() - if sign.RTime < start { // 重置 - sign.RTime = time.Now().Unix() - sign.SignTime = sign.RTime - sign.SignCount = 1 - } - - if this.module.configure.GetSignResetConf(sign.Cid+1) != -1 { // 获取当前的组id - sign.Cid += 1 +// 检测是否达到重置日期 +func (this *ModelSign) checkResetSignData(session comm.IUserSession) { + var ( + update map[string]interface{} + bReward bool + ) + update = make(map[string]interface{}, 0) + if sign, err := this.module.modelSign.GetUserSign(session.GetUserId()); err == nil { + start, _ := utils.GetMonthStartEnd() + if sign.RTime < start { // 重置 + sign.RTime = time.Now().Unix() + sign.SignTime = sign.RTime + sign.SignCount = 1 + if newGroup := this.module.configure.GetSignResetConf(sign.Cid + 1); newGroup != -1 { // 获取当前的组id + sign.Cid += 1 + sign.Group = newGroup + update["cid"] = sign.Cid + update["group"] = sign.Group + } + update["rTime"] = sign.RTime + update["signTime"] = sign.SignTime + update["signCount"] = sign.SignCount + this.Change(session.GetUserId(), update) + bReward = true + } else { + if !utils.IsToday(sign.SignTime) { + sign.SignCount += 1 + update["signCount"] = sign.SignCount + sign.SignTime = time.Now().Unix() + update["signTime"] = sign.SignTime + sign.RTime = sign.SignTime + update["rTime"] = sign.RTime + this.Change(session.GetUserId(), update) + bReward = true + } + } + _data := this.module.configure.GetSignConf(sign.Cid, sign.Group) + if bReward && _data != nil { // 发奖 + this.module.DispenseRes(session, _data.Loopgift, true) + } + session.SendMsg(string(this.module.GetType()), "sign", &pb.UserSignPush{ + Data: sign, + Reward: bReward, + }) } return diff --git a/modules/user/module.go b/modules/user/module.go index 89986270d..c24c00083 100644 --- a/modules/user/module.go +++ b/modules/user/module.go @@ -45,8 +45,8 @@ type User struct { modelSession *ModelSession modelSetting *ModelSetting modelExpand *ModelExpand - configure *modules.MCompConfigure service base.IRPCXService + configure *configureComp modelSign *ModelSign // 签到 } @@ -77,6 +77,8 @@ func (this *User) OnInstallComp() { this.modelSession = this.RegisterComp(new(ModelSession)).(*ModelSession) this.modelSetting = this.RegisterComp(new(ModelSetting)).(*ModelSetting) this.modelExpand = this.RegisterComp(new(ModelExpand)).(*ModelExpand) + this.modelSign = this.RegisterComp(new(ModelSign)).(*ModelSign) + this.configure = this.RegisterComp(new(configureComp)).(*configureComp) } //获取用户数据 From 45317f13fc8737381e29bb504a5bf500fe772e6c Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Mon, 7 Nov 2022 22:06:12 +0800 Subject: [PATCH 3/3] =?UTF-8?q?json=20=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/json/game_trolllv.json | 12 ++++++------ bin/json/game_trolltrain.json | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/bin/json/game_trolllv.json b/bin/json/game_trolllv.json index a91cdac12..e7b422b15 100644 --- a/bin/json/game_trolllv.json +++ b/bin/json/game_trolllv.json @@ -1,7 +1,7 @@ [ { "lv": 1, - "money": 10000, + "money": 1000, "reword": [ { "a": "attr", @@ -22,7 +22,7 @@ }, { "lv": 2, - "money": 20000, + "money": 2000, "reword": [ { "a": "attr", @@ -43,7 +43,7 @@ }, { "lv": 3, - "money": 30000, + "money": 3000, "reword": [ { "a": "attr", @@ -64,7 +64,7 @@ }, { "lv": 4, - "money": 40000, + "money": 4000, "reword": [ { "a": "attr", @@ -85,7 +85,7 @@ }, { "lv": 5, - "money": 50000, + "money": 5000, "reword": [ { "a": "attr", @@ -106,7 +106,7 @@ }, { "lv": 6, - "money": 60000, + "money": 6000, "reword": [ { "a": "attr", diff --git a/bin/json/game_trolltrain.json b/bin/json/game_trolltrain.json index f0b1873b5..2b7764f19 100644 --- a/bin/json/game_trolltrain.json +++ b/bin/json/game_trolltrain.json @@ -4,20 +4,20 @@ "name": "右屏商人", "information": "这是一位熊猫商人", "ico": "action_11001", - "time": 300 + "time": 20 }, { "id": 2, "name": "上屏商人", "information": "这是一位波比商人再此", "ico": "action_11003", - "time": 300 + "time": 20 }, { "id": 3, "name": "左屏商人", "information": "这是一位滑板鞋王子", "ico": "ytx_js_14007", - "time": 300 + "time": 20 } ] \ No newline at end of file