From 3a4b21311b3e1b82169b4b3c8385347a703c1846 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Tue, 16 Jan 2024 17:30:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A0=E5=A4=BA=E6=95=B0=E6=8D=AE=E7=BB=93?= =?UTF-8?q?=E6=9E=84=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/plunder/api_getlist.go | 2 +- modules/plunder/model_land.go | 33 +++++++++++++++++++------------- modules/plunder/model_plunder.go | 15 ++++++++++++--- modules/plunder/module.go | 17 +++++++++++----- 4 files changed, 45 insertions(+), 22 deletions(-) diff --git a/modules/plunder/api_getlist.go b/modules/plunder/api_getlist.go index c15db55f4..9543e93d6 100644 --- a/modules/plunder/api_getlist.go +++ b/modules/plunder/api_getlist.go @@ -19,7 +19,7 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.PlunderGetListRe return } - if list, err = this.module.model.getPlunderData(session.GetUserId()); err != nil { + if list, err = this.module.modelPlunder.getPlunderData(session.GetUserId()); err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_DBError, Message: err.Error(), diff --git a/modules/plunder/model_land.go b/modules/plunder/model_land.go index c508784a3..825cb2f44 100644 --- a/modules/plunder/model_land.go +++ b/modules/plunder/model_land.go @@ -6,6 +6,8 @@ import ( "go_dreamfactory/lego/sys/mgo" "go_dreamfactory/modules" "go_dreamfactory/pb" + "go_dreamfactory/sys/configure" + "go_dreamfactory/utils" "go.mongodb.org/mongo-driver/bson/primitive" ) @@ -23,26 +25,31 @@ func (this *modelLand) Init(service core.IService, module core.IModule, comp cor } // 获取岛基本数据 -func (this *modelLand) getPlunderLandData(uid string) (info *pb.DBPlunderLand, err error) { +func (this *modelLand) getPlunderLandData(id string) (info *pb.DBPlunderLand, err error) { info = &pb.DBPlunderLand{} - if err = this.Get(uid, info); err != nil && err != mgo.MongodbNil { + if err = this.GetListObj(comm.RDS_EMPTY, id, info); err != nil && err != mgo.MongodbNil { this.module.Errorln(err) return } - if err == mgo.MongodbNil { - info = &pb.DBPlunderLand{ - Id: primitive.NewObjectID().Hex(), - Uinfo: map[string]*pb.BaseUserInfo{}, - Ship: map[string]*pb.ShipData{}, - Etime: 0, - } - err = this.Add(uid, info) - } + return } // 修改岛信息 -func (this *modelLand) changePlunderLandData(uid string, update map[string]interface{}) (err error) { - err = this.Change(uid, update) +func (this *modelLand) changePlunderLandData(id string, update map[string]interface{}) (err error) { + err = this.ChangeList(comm.RDS_EMPTY, id, update) + return +} + +func (this *modelLand) createPlunderLandData(uid string) (land *pb.DBPlunderLand, err error) { + + land = &pb.DBPlunderLand{ + Id: primitive.NewObjectID().Hex(), + Uinfo: map[string]*pb.BaseUserInfo{}, + Ship: map[string]*pb.ShipData{}, + Etime: utils.GetTodayZeroTime(configure.Now().Unix()) + 48*3600, // 临时处理 后面走配置 + } + err = this.AddList(comm.RDS_EMPTY, land.Id, land) + return } diff --git a/modules/plunder/model_plunder.go b/modules/plunder/model_plunder.go index 875dfa879..e52761d9a 100644 --- a/modules/plunder/model_plunder.go +++ b/modules/plunder/model_plunder.go @@ -6,6 +6,7 @@ import ( "go_dreamfactory/lego/sys/mgo" "go_dreamfactory/modules" "go_dreamfactory/pb" + "go_dreamfactory/sys/configure" "go.mongodb.org/mongo-driver/bson/primitive" "go.mongodb.org/mongo-driver/mongo" @@ -26,7 +27,7 @@ func (this *modelPlunder) Init(service core.IService, module core.IModule, comp return } -// 获取猴拳基本数据 +// 获取基本数据 func (this *modelPlunder) getPlunderData(uid string) (info *pb.DBPlunder, err error) { info = &pb.DBPlunder{} if err = this.Get(uid, info); err != nil && err != mgo.MongodbNil { @@ -35,9 +36,17 @@ func (this *modelPlunder) getPlunderData(uid string) (info *pb.DBPlunder, err er } if err == mgo.MongodbNil { info = &pb.DBPlunder{ - Id: primitive.NewObjectID().Hex(), - Uid: uid, + Id: primitive.NewObjectID().Hex(), + Uid: uid, + Ctime: configure.Now().Unix(), } + + for i := 0; i < 3; i++ { // 队列固定三条 + info.Line = append(info.Line, &pb.PlunderLine{}) + } + info.Line = append(info.Line, &pb.PlunderLine{ + Closetime: -1, // 需要手动解锁 + }) err = this.Add(uid, info) } return diff --git a/modules/plunder/module.go b/modules/plunder/module.go index 20f360b36..950f5611d 100644 --- a/modules/plunder/module.go +++ b/modules/plunder/module.go @@ -4,6 +4,7 @@ import ( "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/modules" + "go_dreamfactory/pb" ) func NewModule() core.IModule { @@ -16,10 +17,11 @@ func NewModule() core.IModule { */ type Plunder struct { modules.ModuleBase - service comm.IService - api *apiComp - configure *configureComp - model *modelPlunder + service comm.IService + api *apiComp + configure *configureComp + modelPlunder *modelPlunder + modelLand *modelLand } // 模块名 @@ -46,5 +48,10 @@ func (this *Plunder) OnInstallComp() { this.ModuleBase.OnInstallComp() this.api = this.RegisterComp(new(apiComp)).(*apiComp) this.configure = this.RegisterComp(new(configureComp)).(*configureComp) - this.model = this.RegisterComp(new(modelPlunder)).(*modelPlunder) + this.modelPlunder = this.RegisterComp(new(modelPlunder)).(*modelPlunder) + this.modelLand = this.RegisterComp(new(modelLand)).(*modelLand) +} + +func (this *Plunder) CreatePlunderLand(uid string) (land *pb.DBPlunderLand, err error) { + return this.modelLand.createPlunderLandData(uid) }