This commit is contained in:
wh_zcy 2022-11-07 22:24:14 +08:00
commit 46c7dd0e32
9 changed files with 163 additions and 24 deletions

View File

@ -1,6 +1,7 @@
[ [
{ {
"key": 10001, "key": 10001,
"display": false,
"type": 1, "type": 1,
"text": { "text": {
"key": "chat_text_10001", "key": "chat_text_10001",
@ -21,6 +22,7 @@
}, },
{ {
"key": 10002, "key": 10002,
"display": false,
"type": 1, "type": 1,
"text": { "text": {
"key": "chat_text_10002", "key": "chat_text_10002",
@ -39,6 +41,7 @@
}, },
{ {
"key": 10003, "key": 10003,
"display": false,
"type": 1, "type": 1,
"text": { "text": {
"key": "chat_text_10003", "key": "chat_text_10003",
@ -57,6 +60,7 @@
}, },
{ {
"key": 20001, "key": 20001,
"display": false,
"type": 2, "type": 2,
"text": { "text": {
"key": "chat_text_20001", "key": "chat_text_20001",
@ -69,6 +73,7 @@
}, },
{ {
"key": 30002, "key": 30002,
"display": true,
"type": 3, "type": 3,
"text": { "text": {
"key": "chat_text_30002", "key": "chat_text_30002",
@ -81,6 +86,7 @@
}, },
{ {
"key": 30003, "key": 30003,
"display": true,
"type": 3, "type": 3,
"text": { "text": {
"key": "chat_text_30003", "key": "chat_text_30003",
@ -93,6 +99,7 @@
}, },
{ {
"key": 30004, "key": 30004,
"display": true,
"type": 3, "type": 3,
"text": { "text": {
"key": "chat_text_30004", "key": "chat_text_30004",
@ -105,6 +112,7 @@
}, },
{ {
"key": 40001, "key": 40001,
"display": false,
"type": 4, "type": 4,
"text": { "text": {
"key": "chat_text_40001", "key": "chat_text_40001",

View File

@ -1,7 +1,7 @@
[ [
{ {
"lv": 1, "lv": 1,
"money": 10000, "money": 1000,
"reword": [ "reword": [
{ {
"a": "attr", "a": "attr",
@ -22,7 +22,7 @@
}, },
{ {
"lv": 2, "lv": 2,
"money": 20000, "money": 2000,
"reword": [ "reword": [
{ {
"a": "attr", "a": "attr",
@ -43,7 +43,7 @@
}, },
{ {
"lv": 3, "lv": 3,
"money": 30000, "money": 3000,
"reword": [ "reword": [
{ {
"a": "attr", "a": "attr",
@ -64,7 +64,7 @@
}, },
{ {
"lv": 4, "lv": 4,
"money": 40000, "money": 4000,
"reword": [ "reword": [
{ {
"a": "attr", "a": "attr",
@ -85,7 +85,7 @@
}, },
{ {
"lv": 5, "lv": 5,
"money": 50000, "money": 5000,
"reword": [ "reword": [
{ {
"a": "attr", "a": "attr",
@ -106,7 +106,7 @@
}, },
{ {
"lv": 6, "lv": 6,
"money": 60000, "money": 6000,
"reword": [ "reword": [
{ {
"a": "attr", "a": "attr",

View File

@ -4,20 +4,20 @@
"name": "右屏商人", "name": "右屏商人",
"information": "这是一位熊猫商人", "information": "这是一位熊猫商人",
"ico": "action_11001", "ico": "action_11001",
"time": 300 "time": 20
}, },
{ {
"id": 2, "id": 2,
"name": "上屏商人", "name": "上屏商人",
"information": "这是一位波比商人再此", "information": "这是一位波比商人再此",
"ico": "action_11003", "ico": "action_11003",
"time": 300 "time": 20
}, },
{ {
"id": 3, "id": 3,
"name": "左屏商人", "name": "左屏商人",
"information": "这是一位滑板鞋王子", "information": "这是一位滑板鞋王子",
"ico": "ytx_js_14007", "ico": "ytx_js_14007",
"time": 300 "time": 20
} }
] ]

View File

@ -24,7 +24,7 @@ func (this *apiComp) GetReward(session comm.IUserSession, req *pb.TrollNpcReward
code = pb.ErrorCode_DBError code = pb.ErrorCode_DBError
return return
} }
conf := this.configure.GetTrollLv(req.RewardId) conf := this.module.configure.GetTrollLv(req.RewardId)
if conf == nil { if conf == nil {
code = pb.ErrorCode_ReqParameterError code = pb.ErrorCode_ReqParameterError
} }

View File

@ -160,7 +160,12 @@ func (this *Troll) TrollAI(session comm.IUserSession, troll *pb.DBTrollTrain) (c
update["aiCount"] = troll.AiCount update["aiCount"] = troll.AiCount
update["gridNum"] = troll.GridNum update["gridNum"] = troll.GridNum
update["totalEarn"] = troll.TotalEarn 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) this.ModifyTrollData(session.GetUserId(), update)
return return
} }

View File

@ -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.ModuleRtask.SendToRtask(session, comm.Rtype7, 1)
// 每日签到检测
this.module.modelSign.checkResetSignData(session)
//推送登录公告 //推送登录公告
this.chat.SendSysChatToUser(session, comm.UserLoginNotice, 0) this.chat.SendSysChatToUser(session, comm.UserLoginNotice, 0)
mail := &pb.DBMailData{ mail := &pb.DBMailData{

View File

@ -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
}

View File

@ -1,6 +1,7 @@
package user package user
import ( import (
"errors"
"go_dreamfactory/comm" "go_dreamfactory/comm"
"go_dreamfactory/lego/core" "go_dreamfactory/lego/core"
"go_dreamfactory/modules" "go_dreamfactory/modules"
@ -8,6 +9,7 @@ import (
"go_dreamfactory/utils" "go_dreamfactory/utils"
"time" "time"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo" "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) { func (this *ModelSign) GetUserSign(uid string) (result *pb.DBSign, err error) {
result = &pb.DBSign{} 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 return
} }
err = nil err = nil
@ -55,17 +77,50 @@ func (this *ModelSign) updateSignData(uid string, sign *pb.DBSign) (err error) {
return return
} }
// 重置签到数据 // 检测是否达到重置日期
func (this *ModelSign) resetSignData(uid string, sign *pb.DBSign) (err error) { func (this *ModelSign) checkResetSignData(session comm.IUserSession) {
start, _ := utils.GetMonthStartEnd() var (
if sign.RTime < start { // 重置 update map[string]interface{}
sign.RTime = time.Now().Unix() bReward bool
sign.SignTime = sign.RTime )
sign.SignCount = 1 update = make(map[string]interface{}, 0)
} if sign, err := this.module.modelSign.GetUserSign(session.GetUserId()); err == nil {
start, _ := utils.GetMonthStartEnd()
if this.module.configure.GetSignResetConf(sign.Cid+1) != -1 { // 获取当前的组id if sign.RTime < start { // 重置
sign.Cid += 1 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 return

View File

@ -45,8 +45,8 @@ type User struct {
modelSession *ModelSession modelSession *ModelSession
modelSetting *ModelSetting modelSetting *ModelSetting
modelExpand *ModelExpand modelExpand *ModelExpand
configure *modules.MCompConfigure
service base.IRPCXService service base.IRPCXService
configure *configureComp
modelSign *ModelSign // 签到 modelSign *ModelSign // 签到
} }
@ -77,6 +77,8 @@ func (this *User) OnInstallComp() {
this.modelSession = this.RegisterComp(new(ModelSession)).(*ModelSession) this.modelSession = this.RegisterComp(new(ModelSession)).(*ModelSession)
this.modelSetting = this.RegisterComp(new(ModelSetting)).(*ModelSetting) this.modelSetting = this.RegisterComp(new(ModelSetting)).(*ModelSetting)
this.modelExpand = this.RegisterComp(new(ModelExpand)).(*ModelExpand) this.modelExpand = this.RegisterComp(new(ModelExpand)).(*ModelExpand)
this.modelSign = this.RegisterComp(new(ModelSign)).(*ModelSign)
this.configure = this.RegisterComp(new(configureComp)).(*configureComp)
} }
//获取用户数据 //获取用户数据