From 25bfde35330bed102ff24a5b0ee1980cae73974a Mon Sep 17 00:00:00 2001 From: wh_zcy Date: Wed, 2 Nov 2022 15:51:06 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E5=85=AC=E4=BC=9A=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/v2/FyneApp.toml | 4 +- cmd/v2/ui/protocol.go | 19 ++++ cmd/v2/ui/views/sociaty_mine.go | 95 +++++++++++++++++++- cmd/v2/ui/views/sociaty_tasklist.go | 46 ++-------- cmd/v2/ui/views/troll_getlist.go | 26 ++++++ comm/const.go | 2 - comm/imodule.go | 2 + modules/rtask/module.go | 28 +++++- modules/sociaty/api_cross_activityreceive.go | 3 +- modules/sociaty/api_cross_receive.go | 18 ++-- modules/sociaty/config.go | 19 ++++ modules/sociaty/model_sociaty.go | 55 +++++++++--- modules/sociaty/model_sociatytask.go | 1 + sys/db/dbconn.go | 6 +- 14 files changed, 256 insertions(+), 68 deletions(-) create mode 100644 cmd/v2/ui/views/troll_getlist.go diff --git a/cmd/v2/FyneApp.toml b/cmd/v2/FyneApp.toml index 5e4358de2..b3007e4b6 100644 --- a/cmd/v2/FyneApp.toml +++ b/cmd/v2/FyneApp.toml @@ -4,5 +4,5 @@ Website = "http://legu.cc" Icon = "app.png" Name = "RobotGUI" ID = "cc.legu.app" - Version = "1.0.18" - Build = 21 + Version = "1.0.19" + Build = 22 diff --git a/cmd/v2/ui/protocol.go b/cmd/v2/ui/protocol.go index 56bfe61b1..a192c1921 100644 --- a/cmd/v2/ui/protocol.go +++ b/cmd/v2/ui/protocol.go @@ -115,6 +115,8 @@ var ( ff(comm.ModuleSociaty, sociaty.SociatySubTypeMine): &formview.SociatyMineView{}, ff(comm.ModuleSociaty, sociaty.SociatySubTypeTasklist): &formview.SociatyTasklistView{}, ff(comm.ModuleSociaty, sociaty.SociatySubTypeRank): &formview.SociatyRankView{}, + // troll + ff(comm.ModuleTroll, "getlist"): &formview.TrollGetlistView{}, } ) @@ -138,6 +140,7 @@ var ( string(comm.ModuleLinestory), string(comm.ModuleGourmet), string(comm.ModuleSociaty), + string(comm.ModuleTroll), }, "gm": {ff(comm.ModuleGM, "cmd")}, "sys": { @@ -232,6 +235,9 @@ var ( ff(comm.ModuleSociaty, sociaty.SociatySubTypeTasklist), ff(comm.ModuleSociaty, sociaty.SociatySubTypeRank), }, + "troll": { + ff(comm.ModuleTroll, "getlist"), + }, } ) @@ -856,6 +862,19 @@ var ( SubType: sociaty.SociatySubTypeRank, Enabled: true, }, + //troll + string(comm.ModuleTroll): { + NavLabel: "巨兽", + MainType: string(comm.ModuleTroll), + Enabled: true, + }, + ff(comm.ModuleTroll, "getlist"): { + NavLabel: "列表", + Desc: "巨兽列表", + MainType: string(comm.ModuleTroll), + SubType: "getlist", + Enabled: true, + }, } ) diff --git a/cmd/v2/ui/views/sociaty_mine.go b/cmd/v2/ui/views/sociaty_mine.go index a9c90dd5a..e033423ce 100644 --- a/cmd/v2/ui/views/sociaty_mine.go +++ b/cmd/v2/ui/views/sociaty_mine.go @@ -134,6 +134,9 @@ func (this *SociatyMineView) CreateView(t *model.TestCase) fyne.CanvasObject { // 日志 logBtn := widget.NewButton("日志", this.showLogWin) + // 活跃度 + activityBtn := widget.NewButton("活跃度", this.showActivityWin) + defer func() { this.loadSociaty() time.Sleep(time.Millisecond * 30) //必须要延迟,否则职位获取不到 @@ -155,6 +158,7 @@ func (this *SociatyMineView) CreateView(t *model.TestCase) fyne.CanvasObject { } btns.Add(logBtn) + btns.Add(activityBtn) this.sociatyRender(item) this.form.Refresh() }() @@ -203,7 +207,6 @@ func (this *SociatyMineView) sociatyRender(item *entryItem) { item.isApplyCheck.Checked = this.sociaty.IsApplyCheck item.applyLv.Text = cast.ToString(this.sociaty.ApplyLv) } - } func (this *SociatyMineView) dataListener(item *entryItem) { @@ -446,10 +449,43 @@ func (this *SociatyMineView) showSociatyMemberWin() { // this.memberList.DeleteItem(selId) }) + // 设置职位 + setJobSel := widget.NewSelect([]string{"设置职位", "副会长", "管理", "普通成员"}, func(s string) { + selId := this.memberList.SelItemId + if selId == "" { + common.ShowTip("请选择项目") + return + } + var job pb.SociatyJob + switch s { + case "副会长": + job = pb.SociatyJob_VICEPRESIDENT + case "管理": + job = pb.SociatyJob_ADMIN + case "普通成员": + job = pb.SociatyJob_MEMBER + default: + job = pb.SociatyJob_NOJOB + } + if err := service.GetPttService().SendToClient( + string(comm.ModuleSociaty), + sociaty.SociatySubTypeSettingJob, + &pb.SociatySettingJobReq{ + TargetId: selId, + Job: job, + }, + ); err != nil { + logrus.Error(err) + return + } + }) + setJobSel.Selected = "设置职位" + btns := container.NewHBox(refreshBtn) // 会长 if this.job == pb.SociatyJob_PRESIDENT { + btns.Add(setJobSel) btns.Add(tirenBtn) btns.Add(zhuanrangBtn) } @@ -595,3 +631,60 @@ func (this *SociatyMineView) logListListen() { }) this.flag_log = true } + +// 活跃度 +func (this *SociatyMineView) showActivityWin() { + itemList := this.activityList() + + //活跃度领取 + activityBtn := widget.NewButton("活跃度领取", func() { + selId := itemList.SelItemId + if err := service.GetPttService().SendToClient( + string(comm.ModuleSociaty), + sociaty.SociatySubTypeActivityReceive, + &pb.SociatyActivityReceiveReq{ + Id: cast.ToInt32(selId), + }); err != nil { + logrus.Error(err) + } + }) + + var activityVal int32 + if this.sociaty != nil { + activityVal = this.sociaty.Activity + } + + aVal := canvas.NewText(cast.ToString(activityVal), nil) + aVal.TextSize = 46 + aLayout := container.NewVBox(container.NewCenter(aVal), activityBtn) + + c := container.NewBorder(aLayout, nil, nil, nil, itemList.ItemList) + dconf := dialog.NewCustom("活跃度", "关闭", c, this.w) + dconf.Resize(fyne.NewSize(800, 500)) + dconf.Show() +} + +func (this *SociatyMineView) activityList() *common.ItemList { + // 活跃度列表 + activityItemList := common.NewItemList() + activityItemList.ItemList = activityItemList.CreateList() + + n := map[int32]int32{ + 1: 1000, + 2: 2000, + 3: 3000, + 4: 4000, + 5: 5000, + } + + var nn int + for k, v := range n { + nn++ + item := common.Item{ + Id: cast.ToString(k), + Text: fmt.Sprintf("%d - Id:%v 活跃度:%d ", nn, k, v), + } + activityItemList.AddItem(item) + } + return activityItemList +} diff --git a/cmd/v2/ui/views/sociaty_tasklist.go b/cmd/v2/ui/views/sociaty_tasklist.go index 07276959b..d1c1fc8af 100644 --- a/cmd/v2/ui/views/sociaty_tasklist.go +++ b/cmd/v2/ui/views/sociaty_tasklist.go @@ -11,7 +11,6 @@ import ( "go_dreamfactory/pb" "fyne.io/fyne/v2" - "fyne.io/fyne/v2/canvas" "fyne.io/fyne/v2/container" "fyne.io/fyne/v2/theme" "fyne.io/fyne/v2/widget" @@ -64,51 +63,16 @@ func (this *SociatyTasklistView) CreateView(t *model.TestCase) fyne.CanvasObject } }) - //活跃度领取 - activityBtn := widget.NewButton("活跃度领取", func() { - if err := service.GetPttService().SendToClient( - string(comm.ModuleSociaty), - sociaty.SociatySubTypeActivityReceive, - &pb.SociatyActivityReceiveReq{ - Id: 1, - }); err != nil { - logrus.Error(err) - } - }) + - // 活跃度列表 - this.activityItemList = common.NewItemList() - this.activityItemList.ItemList = this.activityItemList.CreateList() - this.activityList() - - activityVal := canvas.NewText("0", nil) + // activityVal := canvas.NewText("0", nil) buttonBar := container.NewHBox(refreshBtn, receiveBtn) c1 := container.NewBorder(buttonBar, nil, nil, nil, this.itemList.ItemList) - c2 := container.NewBorder(container.NewVBox(container.NewCenter(activityVal), activityBtn), nil, nil, nil, this.activityItemList.ItemList) - cols := container.NewGridWithColumns(2, c1, c2) + // c2 := container.NewBorder(container.NewVBox(container.NewCenter(activityVal), activityBtn), nil, nil, nil, this.activityItemList.ItemList) + // cols := container.NewGridWithColumns(2, c1, c2) this.dataListener() - return cols -} - -func (this *SociatyTasklistView) activityList() { - n := map[int32]int32{ - 1: 1000, - 2: 2000, - 3: 3000, - 4: 4000, - 5: 5000, - } - - var nn int - for k, v := range n { - nn++ - item := common.Item{ - Id: cast.ToString(k), - Text: fmt.Sprintf("%d - Id:%v 活跃度:%d ", nn, k, v), - } - this.activityItemList.AddItem(item) - } + return c1 } func (this *SociatyTasklistView) dataListener() { diff --git a/cmd/v2/ui/views/troll_getlist.go b/cmd/v2/ui/views/troll_getlist.go new file mode 100644 index 000000000..09b35a75d --- /dev/null +++ b/cmd/v2/ui/views/troll_getlist.go @@ -0,0 +1,26 @@ +package formview + +import ( + "go_dreamfactory/cmd/v2/model" + "go_dreamfactory/cmd/v2/service" + "go_dreamfactory/pb" + + "fyne.io/fyne/v2" + "github.com/sirupsen/logrus" +) + +type TrollGetlistView struct { + BaseformView +} + +func (this *TrollGetlistView) CreateView(t *model.TestCase) fyne.CanvasObject { + this.form.OnSubmit = func() { + if err := service.GetPttService().SendToClient( + t.MainType, + t.SubType, + &pb.TrollGetListReq{}); err != nil { + logrus.Error(err) + } + } + return this.form +} diff --git a/comm/const.go b/comm/const.go index 8580e79b4..3d3759861 100644 --- a/comm/const.go +++ b/comm/const.go @@ -24,8 +24,6 @@ const ( const ( RDS_SESSION = "online" - RDS_SOCIATY = "all" - RDS_SOCIATYRANK = "rank" ) //ERR diff --git a/comm/imodule.go b/comm/imodule.go index 62ee6ac67..ab3b6ca78 100644 --- a/comm/imodule.go +++ b/comm/imodule.go @@ -135,6 +135,8 @@ type ( IRtask interface { // 条件校验 CheckCondi(uid string, condiId int32) (code pb.ErrorCode) + // 远程条件校验 + RemoteCheckCondi(uid string, condiId int32, rsp *pb.DBRtaskRecord) error //任务触发 SendToRtask(session IUserSession, rtaskType TaskType, params ...int32) (code pb.ErrorCode) // 初始化条件数据 diff --git a/modules/rtask/module.go b/modules/rtask/module.go index 133bfda0a..1e9ce1e98 100644 --- a/modules/rtask/module.go +++ b/modules/rtask/module.go @@ -11,6 +11,7 @@ import ( "go_dreamfactory/modules" "go_dreamfactory/pb" cfg "go_dreamfactory/sys/configure/structs" + "go_dreamfactory/sys/db" "go_dreamfactory/utils" "sort" @@ -216,7 +217,7 @@ func (this *ModuleRtask) SendToRtask(session comm.IUserSession, rtaskType comm.T session.GetServiecTag(), comm.Service_Worker, string(comm.Rpc_ModuleRtaskSendTask), - pb.RPCRTaskReq{Uid: session.GetUserId(), TaskType: int32(rtaskType),}, + pb.RPCRTaskReq{Uid: session.GetUserId(), TaskType: int32(rtaskType)}, nil); err != nil { this.Errorln(err) } @@ -284,6 +285,7 @@ func (this *ModuleRtask) GetCondiData(uid string) *pb.DBRtaskRecord { return this.modelRtaskRecord.getRecord(uid) } +// Bingo命令更新随机任务 func (this *ModuleRtask) BingoRtask(session comm.IUserSession, groupId, rtaskId int32) error { rtask := &pb.DBRtask{} if err := this.modelRtask.Get(session.GetUserId(), rtask); err != nil { @@ -341,6 +343,28 @@ func (this *ModuleRtask) BingoRtask(session comm.IUserSession, groupId, rtaskId return nil } +// 远程条件校验 +func (this *ModuleRtask) RemoteCheckCondi(uid string, condiId int32, rsp *pb.DBRtaskRecord) error { + if rsp == nil { + return errors.New("pb.DBRtaskRecord is not instance") + } + sid, _, ok := utils.UIdSplit(uid) + if !ok { + return errors.New("sid split error") + } + conn, err := db.ServerDBConn(sid) + if err != nil { + return err + } + model := db.NewDBModel(comm.TableRtaskRecord, 0, conn) + + if err := model.Get(uid, rsp); err != nil { + return err + } + + return nil +} + //接收区服worker发起的秘境事件 func (this *ModuleRtask) Rpc_ModuleRtaskSendTask(ctx context.Context, args *pb.RPCRTaskReq, reply *pb.EmptyResp) (err error) { this.Debug("Rpc_ModuleRtaskSendTask", log.Field{Key: "args", Value: args.String()}) @@ -358,7 +382,7 @@ func (this *ModuleRtask) Rpc_ModuleRtaskSendTask(ctx context.Context, args *pb.R err = fmt.Errorf("未查询到用户:%s在线信息!", args.Uid) return } else { - this.SendToRtask(session, comm.TaskType(args.TaskType),) + this.SendToRtask(session, comm.TaskType(args.TaskType)) session.Push() } return diff --git a/modules/sociaty/api_cross_activityreceive.go b/modules/sociaty/api_cross_activityreceive.go index b25f97550..232af1ccd 100644 --- a/modules/sociaty/api_cross_activityreceive.go +++ b/modules/sociaty/api_cross_activityreceive.go @@ -40,7 +40,8 @@ func (this *apiComp) Activityreceive(session comm.IUserSession, req *pb.SociatyA //是否满足领取条件 if sociaty.Activity < conf.Activity { - this.module.Errorf("弹劾失败:%v", err) + code = pb.ErrorCode_SociatyActivityNoEnough + this.module.Errorf("活跃度不足 sociatyId:%s uid:%s activity:%d", sociaty.Id, uid, sociaty.Activity) return } diff --git a/modules/sociaty/api_cross_receive.go b/modules/sociaty/api_cross_receive.go index 69d00df73..47f59c9a6 100644 --- a/modules/sociaty/api_cross_receive.go +++ b/modules/sociaty/api_cross_receive.go @@ -31,16 +31,24 @@ func (this *apiComp) Receive(session comm.IUserSession, req *pb.SociatyReceiveRe // 判断奖励是否已领 sociatyTask := this.module.modelSociaty.getUserTaskList(uid, sociaty.Id) for _, v := range sociatyTask.List { - if v.TaskId == req.TaskId && v.Status == 1 { - code = pb.ErrorCode_SociatyRewardReceived - return + if v.TaskId == req.TaskId { + if v.Status == 1 { + code = pb.ErrorCode_SociatyRewardReceived + return + } + break } } - //TODO 验证任务是否完成 + // 验证任务是否完成 + if err, ok := this.module.modelSociaty.validTask(uid, req.TaskId); err != nil || !ok { + code = pb.ErrorCode_SociatyTaskValidation + this.module.Errorf("任务 taskId:%v 验证未通过", req.TaskId) + return + } // 领取 - if err := this.module.modelSociatyTask.receive(req.TaskId, uid, sociaty.Id); err != nil { + if err := this.module.modelSociatyTask.receive(req.TaskId, sociaty.Id, uid); err != nil { code = pb.ErrorCode_SociatyRewardReceive this.module.Errorf("领取任务奖励 err:%v", err) return diff --git a/modules/sociaty/config.go b/modules/sociaty/config.go index 5a88b0b73..a9d1f9b1e 100644 --- a/modules/sociaty/config.go +++ b/modules/sociaty/config.go @@ -12,6 +12,7 @@ const ( gameSociatyTask = "game_guildtask.json" gameSociatySign = "game_guildsign.json" gameSociatyActivity = "game_guildactivity.json" + gameRdtaskCondi = "game_rdtaskcondi.json" ) type configureComp struct { @@ -25,6 +26,7 @@ func (this *configureComp) Init(service core.IService, module core.IModule, comp gameSociatyTask: cfg.NewGameGuildTask, gameSociatySign: cfg.NewGameGuildSign, gameSociatyActivity: cfg.NewGameGuildActivity, + gameRdtaskCondi: cfg.NewGameRdtaskCondi, }) return } @@ -96,3 +98,20 @@ func (this *configureComp) getSociatyActivityCfg() (data *cfg.GameGuildActivity, } return } + +// 任务 +func (this *configureComp) getRtaskCondiCfg() (data *cfg.GameRdtaskCondi, err error) { + var ( + v interface{} + ok bool + ) + if v, err = this.GetConfigure(gameRdtaskCondi); err != nil { + return + } else { + if data, ok = v.(*cfg.GameRdtaskCondi); !ok { + err = fmt.Errorf("%T no is *cfg.GameRdtaskCondi", v) + return + } + } + return +} diff --git a/modules/sociaty/model_sociaty.go b/modules/sociaty/model_sociaty.go index 4b1ecfd58..6d2ed8108 100644 --- a/modules/sociaty/model_sociaty.go +++ b/modules/sociaty/model_sociaty.go @@ -71,7 +71,7 @@ func (this *ModelSociaty) create(sociaty *pb.DBSociaty) error { if sociaty.ApplyLv == 0 { sociaty.ApplyLv = 1 //默认玩家入会等级 } - return this.AddList(comm.RDS_SOCIATY, sociaty.Id, sociaty) + return this.AddList("", sociaty.Id, sociaty) } // 公会列表 @@ -86,13 +86,13 @@ func (this *ModelSociaty) list(uid string, filter pb.SociatyListFilter) (list [] switch filter { case pb.SociatyListFilter_ALL: //所有 - if err := this.GetList(comm.RDS_SOCIATY, &list); err != nil { + if err := this.GetList("", &list); err != nil { log.Errorf("sociaty list err:%v", err) return } case pb.SociatyListFilter_CONDI: //满足条件 //玩家等级大于等于公会的申请等级限制 - if err := this.GetList(comm.RDS_SOCIATY, &list); err != nil { + if err := this.GetList("", &list); err != nil { log.Errorf("sociaty list err:%v", err) return } @@ -115,7 +115,7 @@ func (this *ModelSociaty) list(uid string, filter pb.SociatyListFilter) (list [] } } case pb.SociatyListFilter_APPLYING: //申请中 - if err := this.GetList(comm.RDS_SOCIATY, &list); err != nil { + if err := this.GetList("", &list); err != nil { log.Errorf("sociaty list err:%v", err) return } @@ -152,7 +152,7 @@ func (this *ModelSociaty) findByName(name string) *pb.DBSociaty { // 获取公会 func (this *ModelSociaty) getSociaty(sociatyId string) (sociaty *pb.DBSociaty) { sociaty = &pb.DBSociaty{} - if err := this.GetListObj(comm.RDS_SOCIATY, sociatyId, sociaty); err != nil { + if err := this.GetListObj("", sociatyId, sociaty); err != nil { this.moduleSociaty.Errorf("sociaty [%s] found err:%v", sociatyId, err) return } @@ -274,7 +274,7 @@ func (this *ModelSociaty) isRight(uid string, sociaty *pb.DBSociaty, jobs ...pb. // 更新公会 func (this *ModelSociaty) updateSociaty(sociatyId string, update map[string]interface{}) error { - return this.ChangeList(comm.RDS_SOCIATY, sociatyId, update) + return this.ChangeList("", sociatyId, update) } // 退出公会 @@ -292,7 +292,7 @@ func (this *ModelSociaty) quit(uid string, sociaty *pb.DBSociaty) error { // 解散公会 func (this *ModelSociaty) dismiss(sociaty *pb.DBSociaty) error { - err := this.DelListlds(comm.RDS_SOCIATY, sociaty.Id) + err := this.DelListlds("", sociaty.Id) return err } @@ -554,6 +554,7 @@ func (this *ModelSociaty) updateMemberContribution(uid string, val int32, sociat for _, m := range sociaty.Members { if m.Uid == uid { m.Contribution += val + break } } @@ -581,7 +582,7 @@ func (this *ModelSociaty) sort(list []*pb.DBSociatyRank) []*pb.DBSociatyRank { // 更新排行榜 func (this *ModelSociaty) rankDataChanged(event interface{}, next func(event interface{})) { var list []*pb.DBSociatyRank - if err := this.GetList(comm.RDS_SOCIATYRANK, &list); err != nil { + if err := this.GetList("", &list); err != nil { log.Errorf("sociaty list err:%v", err) return } @@ -597,11 +598,11 @@ func (this *ModelSociaty) rankDataChanged(event interface{}, next func(event int } if len(list) == 0 || len(list) > 0 && len(list) < 20 { if data != nil { - this.AddList(comm.RDS_SOCIATYRANK, data.sociatyId, newRank) + this.AddList("", data.sociatyId, newRank) } } else { - this.AddList(comm.RDS_SOCIATYRANK, data.sociatyId, newRank) - if err := this.GetList(comm.RDS_SOCIATYRANK, &list); err != nil { + this.AddList("", data.sociatyId, newRank) + if err := this.GetList("", &list); err != nil { log.Errorf("sociaty list err:%v", err) return } @@ -614,14 +615,14 @@ func (this *ModelSociaty) rankDataChanged(event interface{}, next func(event int for _, v := range lastData { delIds = append(delIds, v.SociatyId) } - this.DelListlds(comm.RDS_SOCIATYRANK, delIds...) + this.DelListlds("", delIds...) } } // 排行榜 func (this *ModelSociaty) rank() (rank []*pb.DBSociatyRank) { var list []*pb.DBSociaty - if err := this.GetList(comm.RDS_SOCIATYRANK, &list); err != nil { + if err := this.GetList("", &list); err != nil { log.Errorf("sociaty list err:%v", err) return nil } @@ -698,3 +699,31 @@ func (this *ModelSociaty) getMemberMax(sociaty *pb.DBSociaty) int32 { } return 0 } + +// 校验任务完成状态 +func (this *ModelSociaty) validTask(uid string, taskId int32) (err error, ok bool) { + rsp := &pb.DBRtaskRecord{} + if err = this.moduleSociaty.ModuleRtask.RemoteCheckCondi(uid, taskId, rsp); err != nil { + return + } + + grc, err := this.moduleSociaty.configure.getRtaskCondiCfg() + if err != nil { + return + } + if grc == nil { + return errors.New("RtaskCondiCfg is nil"), false + } + + // 遍历玩家任务数据 + if data, ok := rsp.Vals[taskId]; ok { + //查找表配置 + conf, ok := grc.GetDataMap()[taskId] + if ok { + if data.Rtype == conf.Type && data.Data[0] >= conf.Data1 { + return nil, true + } + } + } + return +} diff --git a/modules/sociaty/model_sociatytask.go b/modules/sociaty/model_sociatytask.go index fd9f41be3..5e61ebb9f 100644 --- a/modules/sociaty/model_sociatytask.go +++ b/modules/sociaty/model_sociatytask.go @@ -75,6 +75,7 @@ func (this *ModelSociatyTask) receive(taskId int32, sociatyId, uid string) error for _, t := range sociatyTask.List { if t.TaskId == taskId { t.Status = 1 //领取 + break } } update := map[string]interface{}{ diff --git a/sys/db/dbconn.go b/sys/db/dbconn.go index fcb65a97d..6743ab848 100644 --- a/sys/db/dbconn.go +++ b/sys/db/dbconn.go @@ -309,7 +309,11 @@ func (this *DBModel) ChangeList(uid string, _id string, data map[string]interfac option := newDBOption(opt...) if option.IsMgoLog { - err = this.UpdateModelLogs(this.TableName, uid, bson.M{"_id": _id, "uid": uid}, data) + if uid == "" { + err = this.UpdateModelLogs(this.TableName, uid, bson.M{"_id": _id}, data) + } else { + err = this.UpdateModelLogs(this.TableName, uid, bson.M{"_id": _id, "uid": uid}, data) + } } if this.Expired > 0 { UpDateModelExpired(this.ukey(uid), nil, this.Expired) From 3c3310dd9d6ce34753524fb486939777d77a67ac Mon Sep 17 00:00:00 2001 From: wh_zcy Date: Wed, 2 Nov 2022 19:53:32 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E4=BC=9A=E9=95=BF=E9=80=89=E4=B8=BE?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/v2/ui/protocol.go | 4 +- cmd/v2/ui/views/mail_list.go | 62 ++++++++++- modules/friend/api_cross_randlist.go | 2 +- modules/gourmet/api_getranduser.go | 2 +- modules/hero/hero_test.go | 2 +- modules/smithy/api_getranduser.go | 2 +- modules/sociaty/api_cross_discharge.go | 4 + modules/sociaty/api_cross_dismiss.go | 8 ++ modules/sociaty/api_cross_mine.go | 7 ++ modules/sociaty/model_sociaty.go | 145 ++++++++++++++++++++++--- modules/sociaty/model_sociatylog.go | 16 ++- modules/sociaty/model_sociatytask.go | 2 +- pb/sociaty_db.pb.go | 2 +- utils/random.go | 2 +- utils/utils_test.go | 4 +- 15 files changed, 235 insertions(+), 29 deletions(-) diff --git a/cmd/v2/ui/protocol.go b/cmd/v2/ui/protocol.go index a192c1921..536c11bf9 100644 --- a/cmd/v2/ui/protocol.go +++ b/cmd/v2/ui/protocol.go @@ -368,8 +368,8 @@ var ( Enabled: true, }, ff(comm.ModuleMail, "getlist"): { - NavLabel: "邮件列表", - Desc: "邮件列表", + NavLabel: "我的邮件", + Desc: "我的邮件", MainType: string(comm.ModuleMail), SubType: "getlist", Enabled: true, diff --git a/cmd/v2/ui/views/mail_list.go b/cmd/v2/ui/views/mail_list.go index 3539a94ac..3fce720f6 100644 --- a/cmd/v2/ui/views/mail_list.go +++ b/cmd/v2/ui/views/mail_list.go @@ -1,23 +1,79 @@ package formview import ( + "fmt" + "go_dreamfactory/cmd/v2/lib/common" "go_dreamfactory/cmd/v2/model" "go_dreamfactory/cmd/v2/service" + "go_dreamfactory/cmd/v2/service/observer" + "go_dreamfactory/comm" "go_dreamfactory/pb" "fyne.io/fyne/v2" + "fyne.io/fyne/v2/container" + "fyne.io/fyne/v2/theme" + "fyne.io/fyne/v2/widget" "github.com/sirupsen/logrus" ) type MailListView struct { BaseformView + mailList func() + itemList *common.ItemList + flag bool } func (this *MailListView) CreateView(t *model.TestCase) fyne.CanvasObject { - this.form.OnSubmit = func() { - if err := service.GetPttService().SendToClient(t.MainType, t.SubType, &pb.MailGetListReq{}); err != nil { + this.itemList = common.NewItemList() + + this.itemList.ItemList = this.itemList.CreateDefaultCheckList() + + this.mailList = func() { + if err := service.GetPttService().SendToClient( + t.MainType, + t.SubType, + &pb.MailGetListReq{}); err != nil { logrus.Error(err) } } - return this.form + + defer this.mailList() + + refreshBtn := widget.NewButtonWithIcon("", theme.ViewRefreshIcon(), func() { + this.itemList.Reset() + this.mailList() + }) + buttonBar := container.NewHBox(refreshBtn) + c := container.NewBorder(buttonBar, nil, nil, nil, this.itemList.ItemList) + + return c +} + +func (this *MailListView) dataListener() { + if this.flag { + return + } + this.obs.AddListener(observer.EVENT_REQ_RSP, observer.Listener{ + OnNotify: func(d interface{}, args ...interface{}) { + data := d.(*pb.UserMessage) + if !(data.MainType == string(comm.ModuleMail) && + data.SubType == "getlist") { + return + } + rsp := &pb.MailGetListResp{} + if !comm.ProtoUnmarshal(data, rsp) { + logrus.Error("MailGetListResp unmarshal err") + return + } + + for i, v := range rsp.Mails { + item := common.Item{ + Id: v.ObjId, + Text: fmt.Sprintf("%d-%s %s", i+1, v.Title, v.Contex), + } + this.itemList.AddItem(item) + } + }, + }) + this.flag = true } diff --git a/modules/friend/api_cross_randlist.go b/modules/friend/api_cross_randlist.go index 3922a178f..a1defd252 100644 --- a/modules/friend/api_cross_randlist.go +++ b/modules/friend/api_cross_randlist.go @@ -52,7 +52,7 @@ func (this *apiComp) Randlist(session comm.IUserSession, req *pb.FriendRandlistR var randOnlineUsers []string if len(newList) > recommend { - randArr := utils.Numbers(0, len(newList), recommend) + randArr := utils.RandomNumbers(0, len(newList), recommend) for _, v := range randArr { if newList[v] != nil { randOnlineUsers = append(randOnlineUsers, newList[v].Uid) diff --git a/modules/gourmet/api_getranduser.go b/modules/gourmet/api_getranduser.go index 1708762ba..57d1eed04 100644 --- a/modules/gourmet/api_getranduser.go +++ b/modules/gourmet/api_getranduser.go @@ -51,7 +51,7 @@ func (this *apiComp) GetRandUser(session comm.IUserSession, req *pb.GourmetGetRa } // 随机在线玩家信息 if len(szUid) > int(req.People) { - randArr := utils.Numbers(0, len(szUid), int(req.People)) + randArr := utils.RandomNumbers(0, len(szUid), int(req.People)) for _, v := range randArr { if szUid[v] != "" { mapUser[szUid[v]] = struct{}{} diff --git a/modules/hero/hero_test.go b/modules/hero/hero_test.go index a1f4cfb39..4baf294a9 100644 --- a/modules/hero/hero_test.go +++ b/modules/hero/hero_test.go @@ -61,7 +61,7 @@ func (this *TestService) InitSys() { func Test_Main(t *testing.T) { - ids := utils.Numbers(0, 10, 5) + ids := utils.RandomNumbers(0, 10, 5) for _, v := range ids { fmt.Printf("%d", v) } diff --git a/modules/smithy/api_getranduser.go b/modules/smithy/api_getranduser.go index 10acf8f10..a545de272 100644 --- a/modules/smithy/api_getranduser.go +++ b/modules/smithy/api_getranduser.go @@ -51,7 +51,7 @@ func (this *apiComp) GetRandUser(session comm.IUserSession, req *pb.SmithyGetRan } // 随机在线玩家信息 if len(szUid) > int(req.People) { - randArr := utils.Numbers(0, len(szUid), int(req.People)) + randArr := utils.RandomNumbers(0, len(szUid), int(req.People)) for _, v := range randArr { if szUid[v] != "" { mapUser[szUid[v]] = struct{}{} diff --git a/modules/sociaty/api_cross_discharge.go b/modules/sociaty/api_cross_discharge.go index 681f471c7..edeb45e58 100644 --- a/modules/sociaty/api_cross_discharge.go +++ b/modules/sociaty/api_cross_discharge.go @@ -42,6 +42,10 @@ func (this *apiComp) Discharge(session comm.IUserSession, req *pb.SociatyDischar return } + // 发邮件 + receiver := this.module.modelSociaty.getMemberIds(sociaty) + this.module.modelSociaty.sendMail(receiver) + //清除玩家sociatyId update := map[string]interface{}{ "sociatyId": "", //公会ID置空 diff --git a/modules/sociaty/api_cross_dismiss.go b/modules/sociaty/api_cross_dismiss.go index 74f018232..8661e4dcc 100644 --- a/modules/sociaty/api_cross_dismiss.go +++ b/modules/sociaty/api_cross_dismiss.go @@ -28,7 +28,10 @@ func (this *apiComp) Dismiss(session comm.IUserSession, req *pb.SociatyDismissRe return } + // 邮件接收人 + var receiver []string for _, m := range sociaty.Members { + receiver = append(receiver, m.Uid) //清除成员任务 if err := this.module.modelSociatyTask.deleTask(sociaty.Id, m.Uid); err != nil { this.module.Errorf("删除玩家 uid:%s 公会 sociatyId:%s err:%v", m.Uid, sociaty.Id, err) @@ -57,6 +60,11 @@ func (this *apiComp) Dismiss(session comm.IUserSession, req *pb.SociatyDismissRe return } + //发送邮件 + if err := this.module.modelSociaty.sendMail(receiver); err != nil { + this.module.Errorf("邮件发送失败 sociatyId: %s err:%v", sociaty.Id, err) + } + rsp := &pb.SociatyDismissResp{ Uid: session.GetUserId(), SociatyId: sociaty.Id, diff --git a/modules/sociaty/api_cross_mine.go b/modules/sociaty/api_cross_mine.go index c8c8103cd..23862e5d0 100644 --- a/modules/sociaty/api_cross_mine.go +++ b/modules/sociaty/api_cross_mine.go @@ -31,7 +31,14 @@ func (this *apiComp) Mine(session comm.IUserSession, req *pb.SociatyMineReq) (co return } + // 获取会长 master := this.module.modelSociaty.getMasterInfo(sociaty) + if master != nil { + //判断当前玩家是否是会长 + if master.Uid == uid { //会长 + this.module.modelSociaty.extendJob(uid, sociaty) + } + } rsp.Sociaty = sociaty rsp.Master = master } diff --git a/modules/sociaty/model_sociaty.go b/modules/sociaty/model_sociaty.go index 6d2ed8108..c75895f5a 100644 --- a/modules/sociaty/model_sociaty.go +++ b/modules/sociaty/model_sociaty.go @@ -39,11 +39,7 @@ type ModelSociaty struct { type SociatyListen struct { event_v2.App - sociatyId string - name string - lv int32 - activity int32 - ctime int64 + sociaty *pb.DBSociaty } func (this *ModelSociaty) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { @@ -334,10 +330,23 @@ func (this *ModelSociaty) addMember(uid string, sociaty *pb.DBSociaty) error { return err } + // 发邮件 + this.sendMail(this.getMemberIds(sociaty)) + // 记录日志 this.moduleSociaty.modelSociatyLog.addLog(Log_Add, sociaty.Id, uid) return nil } +// 发邮件给公会成员 +func (this *ModelSociaty) sendMail(receiver []string) error { + if module, err := this.moduleSociaty.service.GetModule(comm.ModuleMail); err == nil { + if mail, ok := module.(comm.Imail); ok { + mail.SendNewMail(&pb.DBMailData{}, receiver...) + } + } + return nil +} + // 成员列表 func (this *ModelSociaty) members(sociaty *pb.DBSociaty) (list []*pb.SociatyMemberInfo) { for _, m := range sociaty.Members { @@ -357,6 +366,14 @@ func (this *ModelSociaty) members(sociaty *pb.DBSociaty) (list []*pb.SociatyMemb return } +// 成员IDs +func (this *ModelSociaty) getMemberIds(sociaty *pb.DBSociaty) (ids []string) { + for _, m := range sociaty.Members { + ids = append(ids, m.Uid) + } + return +} + // 同意 func (this *ModelSociaty) agree(uid string, sociaty *pb.DBSociaty) error { if this.isMember(uid, sociaty) { @@ -480,10 +497,103 @@ func (this *ModelSociaty) accuse(sociaty *pb.DBSociaty) error { //会长离线时间 now := time.Now().Unix() left := now - user.Offlinetime - if left < 7*3600 || user.Offlinetime == 0 { + if left < 72*3600 || user.Offlinetime == 0 { return errors.New("会长很称职,无需弹劾") + } else { + //更新会长的弹劾时间 + update := map[string]interface{}{ + "accuseTime": time.Now().Unix(), + } + return this.updateSociaty(sociaty.Id, update) + } +} + +// 弹劾倒计时判断 +// srcMasterId 原会长ID +func (this *ModelSociaty) extendJob(srcMasterId string, sociaty *pb.DBSociaty) error { + if sociaty.AccuseTime != 0 { + now := time.Now().Unix() + //48小时内终止弹劾 + if now-sociaty.AccuseTime < 48*3600 { + update := map[string]interface{}{ + "accuseTime": 0, + } + return this.updateSociaty(sociaty.Id, update) + } else { + //会长降为普通成员 + if err := this.settingJob(srcMasterId, pb.SociatyJob_MEMBER, sociaty); err != nil { + return err + } + //选举新会长 + if err := this.electNewMaster(srcMasterId, sociaty); err != nil { + return err + } + } + } + return nil +} + +//选举新会长 +func (this *ModelSociaty) electNewMaster(srcMasterId string, sociaty *pb.DBSociaty) error { + vpIds := []*pb.SociatyMember{} // 副会长 + aIds := []*pb.SociatyMember{} //管理员 + mIds := []*pb.SociatyMember{} //普通成员 + + for _, m := range sociaty.Members { + if m.Uid != srcMasterId { + if m.Job == pb.SociatyJob_VICEPRESIDENT { + vpIds = append(vpIds, m) + } else if m.Job == pb.SociatyJob_ADMIN { + aIds = append(aIds, m) + } else { + mIds = append(mIds, m) + } + } } + elect := func(data []*pb.SociatyMember) error { + if len(data) == 1 { + return this.settingJob(data[0].Uid, pb.SociatyJob_PRESIDENT, sociaty) + } else if len(data) > 1 { + //从数组中找到最大的贡献值,并标识数量 + maxNum := data[0] + maxCount := 0 //最大的贡献值数量 + maxIndex := 0 //最大贡献值的索引 + + for i := 1; i < len(data); i++ { + if data[i].Contribution > maxNum.Contribution { + maxNum = data[i] + maxIndex = i + } else if data[i].Contribution == maxNum.Contribution { + maxCount++ + } + } + if maxCount >= 1 { //有两个以上的最大值 + //比较时间 升序 + sort.SliceStable(data, func(i, j int) bool { + return data[i].Ctime < data[j].Ctime + }) + //取第一个值 + return this.settingJob(data[0].Uid, pb.SociatyJob_PRESIDENT, sociaty) + } else { + return this.settingJob(data[maxIndex].Uid, pb.SociatyJob_PRESIDENT, sociaty) + } + } + return nil + } + + // 以下按照职位大小依次调用 + if len(vpIds) > 0 { + return elect(vpIds) + } + + if len(aIds) > 0 { + return elect(aIds) + } + + if len(mIds) > 0 { + return elect(aIds) + } return nil } @@ -588,20 +698,23 @@ func (this *ModelSociaty) rankDataChanged(event interface{}, next func(event int } data := event.(*SociatyListen) + if data.sociaty == nil { + return + } newRank := &pb.DBSociatyRank{ - SociatyId: data.sociatyId, - Name: data.name, - Lv: data.lv, - Activity: data.activity, - Ctime: data.ctime, + SociatyId: data.sociaty.Id, + Name: data.sociaty.Name, + Lv: data.sociaty.Lv, + Activity: data.sociaty.Activity, + Ctime: data.sociaty.Ctime, } if len(list) == 0 || len(list) > 0 && len(list) < 20 { if data != nil { - this.AddList("", data.sociatyId, newRank) + this.AddList("", data.sociaty.Id, newRank) } } else { - this.AddList("", data.sociatyId, newRank) + this.AddList("", data.sociaty.Id, newRank) if err := this.GetList("", &list); err != nil { log.Errorf("sociaty list err:%v", err) return @@ -619,7 +732,7 @@ func (this *ModelSociaty) rankDataChanged(event interface{}, next func(event int } } -// 排行榜 +// 排行榜列表 func (this *ModelSociaty) rank() (rank []*pb.DBSociatyRank) { var list []*pb.DBSociaty if err := this.GetList("", &list); err != nil { @@ -678,6 +791,10 @@ func (this *ModelSociaty) changeLv(sociaty *pb.DBSociaty) error { if err = this.updateSociaty(sociaty.Id, update); err != nil { return err } + // 更新排行榜 + this.EventApp.Dispatch(comm.EventSociatyRankChanged, &SociatyListen{ + sociaty: sociaty, + }) } return nil diff --git a/modules/sociaty/model_sociatylog.go b/modules/sociaty/model_sociatylog.go index e762dfaca..084409381 100644 --- a/modules/sociaty/model_sociatylog.go +++ b/modules/sociaty/model_sociatylog.go @@ -139,7 +139,21 @@ func (this *ModelSociatyLog) addLog(tag Tag, sociatyId string, params ...string) "sociatyId": sociatyId, "list": log.List, } - return this.Change(sociatyId, update) + if err := this.Change(sociatyId, update); err != nil { + return err + } + + // 发消息到公会聊天 + if module, err := this.moduleSociaty.service.GetModule(comm.ModuleChat); err == nil { + if chat, ok := module.(comm.IChat); ok { + chat.SendUnionChat(&pb.DBChat{ + Channel: pb.ChatChannel_Union, + Ctype: pb.ChatType_Text, + UnionId: sociatyId, + Content: content, + }) + } + } } return nil } diff --git a/modules/sociaty/model_sociatytask.go b/modules/sociaty/model_sociatytask.go index 5e61ebb9f..0d96b6ec7 100644 --- a/modules/sociaty/model_sociatytask.go +++ b/modules/sociaty/model_sociatytask.go @@ -39,7 +39,7 @@ func (this *ModelSociatyTask) initSociatyTask(uid, sociatyId string) error { // 大于4条配置 if len(list) > 4 { //随机4条任务 - randInts := utils.Numbers(0, len(list)-1, 4) + randInts := utils.RandomNumbers(0, len(list)-1, 4) for _, v := range randInts { taskList = append(taskList, &pb.SociatyTask{ TaskId: list[v].Id, diff --git a/pb/sociaty_db.pb.go b/pb/sociaty_db.pb.go index cfda5257e..bb19e48fe 100644 --- a/pb/sociaty_db.pb.go +++ b/pb/sociaty_db.pb.go @@ -91,7 +91,7 @@ type DBSociaty struct { IsApplyCheck bool `protobuf:"varint,8,opt,name=isApplyCheck,proto3" json:"isApplyCheck" bson:"isApplyCheck"` //是否必须审批 ApplyLv int32 `protobuf:"varint,9,opt,name=applyLv,proto3" json:"applyLv" bson:"applyLv"` // 等级限制 Ctime int64 `protobuf:"varint,10,opt,name=ctime,proto3" json:"ctime" bson:"ctime"` //创建时间 - ApplyRecord []*ApplyRecord `protobuf:"bytes,11,rep,name=applyRecord,proto3" json:"applyRecord" bson:"applyRecord"` //收到的玩家入会申请 + ApplyRecord []*ApplyRecord `protobuf:"bytes,11,rep,name=applyRecord,proto3" json:"applyRecord" bson:"applyRecord"` //入会申请 Members []*SociatyMember `protobuf:"bytes,12,rep,name=members,proto3" json:"members"` //@go_tags(`bson:"members"`) 公会成员 Activity int32 `protobuf:"varint,13,opt,name=activity,proto3" json:"activity" bson:"activity"` //活跃度 AccuseTime int64 `protobuf:"varint,14,opt,name=accuseTime,proto3" json:"accuseTime" bson:"accuseTime"` //会长弹劾时间 diff --git a/utils/random.go b/utils/random.go index 9564f9319..d2b9f7a42 100644 --- a/utils/random.go +++ b/utils/random.go @@ -23,7 +23,7 @@ func GenValidateCode(width int) string { // 随机一组随机数 // number >= start and < end num 随机数个数 -func Numbers(start, end, num int) []int { +func RandomNumbers(start, end, num int) []int { if end-start < 0 || num > (end-start) { return nil } diff --git a/utils/utils_test.go b/utils/utils_test.go index e227c398c..1857fd9be 100644 --- a/utils/utils_test.go +++ b/utils/utils_test.go @@ -35,7 +35,7 @@ func TestRandom(t *testing.T) { func TestNumber(t *testing.T) { for i := 0; i < 100; i++ { - fmt.Println(utils.Numbers(0, 99, 10)) + fmt.Println(utils.RandomNumbers(0, 99, 10)) } } @@ -45,7 +45,7 @@ func BenchmarkNumber(b *testing.B) { b.ReportAllocs() for i := 0; i < b.N; i++ { - utils.Numbers(0, 1000, 10) + utils.RandomNumbers(0, 1000, 10) } } From 195e8c8c1d61a237d33a538d7c21ca6c2b254471 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Wed, 2 Nov 2022 21:31:07 +0800 Subject: [PATCH 3/4] =?UTF-8?q?ai=E7=8E=A9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/json/game_trollrule.json | 14 ++- comm/const.go | 2 + modules/troll/api_buyorsell.go | 5 +- modules/troll/api_getlist.go | 22 ++-- modules/troll/comp_configure.go | 4 +- modules/troll/module.go | 199 ++++++++++++++++++-------------- 6 files changed, 147 insertions(+), 99 deletions(-) diff --git a/bin/json/game_trollrule.json b/bin/json/game_trollrule.json index fe006461c..40f7d611f 100644 --- a/bin/json/game_trollrule.json +++ b/bin/json/game_trollrule.json @@ -1,11 +1,11 @@ [ { "id": 1, - "quantity": 5 + "quantity": 8 }, { "id": 2, - "quantity": 20 + "quantity": 10 }, { "id": 3, @@ -13,18 +13,22 @@ }, { "id": 4, - "quantity": 1020 + "quantity": 20 }, { "id": 5, - "quantity": 980 + "quantity": 1020 }, { "id": 6, - "quantity": 5 + "quantity": 980 }, { "id": 7, + "quantity": 5 + }, + { + "id": 8, "quantity": 1500 } ] \ No newline at end of file diff --git a/comm/const.go b/comm/const.go index 8580e79b4..76d1f78ca 100644 --- a/comm/const.go +++ b/comm/const.go @@ -414,6 +414,8 @@ const ( const ( TrollBuyCount int32 = iota + 1 // 单日最大交易次数 + TrollAIBuyCount //离线最多交易次数 + TrollItemCount //货物最大存储上限 TrollGridCount //背包格子 diff --git a/modules/troll/api_buyorsell.go b/modules/troll/api_buyorsell.go index 84adc803f..c214f8572 100644 --- a/modules/troll/api_buyorsell.go +++ b/modules/troll/api_buyorsell.go @@ -55,7 +55,9 @@ func (this *apiComp) BuyOrSell(session comm.IUserSession, req *pb.TrollBuyOrSell trolltrain.Items[k] += v } if _, ok := trolltrain.Shop[k]; !ok { - trolltrain.Shop[k] = v + if v > 0 { + trolltrain.Shop[k] = v // 限购 + } } else { if v > 0 { trolltrain.Shop[k] += v // 限购 @@ -145,6 +147,7 @@ func (this *apiComp) BuyOrSell(session comm.IUserSession, req *pb.TrollBuyOrSell update["totalEarn"] = trolltrain.TotalEarn update["gridNum"] = trolltrain.GridNum + update["shop"] = trolltrain.Shop this.module.ModifyTrollData(session.GetUserId(), update) session.SendMsg(string(this.module.GetType()), TrollBuyOrSellResp, &pb.TrollBuyOrSellResp{Data: trolltrain}) return diff --git a/modules/troll/api_getlist.go b/modules/troll/api_getlist.go index d34e74e16..ce4afe507 100644 --- a/modules/troll/api_getlist.go +++ b/modules/troll/api_getlist.go @@ -38,9 +38,12 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.TrollGetListReq) return } - // 测试代码===================== - //this.module.TrollAI(session, trolltrain) - //=========================== + aiCount := this.configure.GetTrollRule(comm.TrollAIBuyCount) + if trolltrain.AiCount <= aiCount { // 小于离线挂机次数可执行 + this.module.TrollAI(session, trolltrain, aiCount) + update["aiCount"] = trolltrain.AiCount + } + maxCoefficient = this.configure.GetTrollMaxCoefficientNux() // 增长幅度的最大值 if maxCoefficient == 0 { code = pb.ErrorCode_ConfigNoFound @@ -49,7 +52,9 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.TrollGetListReq) // 跨天 则清除 每日交易次数 if !utils.IsToday(trolltrain.RefreshTime) { trolltrain.SellCount = 0 - update["sellCount"] = trolltrain.SellCount + update["sellCount"] = trolltrain.SellCount // 重置每日交易次数 + trolltrain.AiCount = 0 + update["aiCount"] = trolltrain.AiCount // 重置ai 交易次数 this.module.ModifyTrollData(session.GetUserId(), update) } @@ -90,14 +95,17 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.TrollGetListReq) trolltrain.RangeId += index trolltrain.RangeId = (trolltrain.RangeId % maxCoefficient) + 1 trolltrain.TarinPos = (trolltrain.TarinPos % trainNum) + 1 - update["refreshTime"] = trolltrain.RefreshTime - update["tarinPos"] = trolltrain.TarinPos - update["rangeId"] = trolltrain.RangeId break } index += 1 leftTime -= v } + update["refreshTime"] = trolltrain.RefreshTime + update["tarinPos"] = trolltrain.TarinPos + update["rangeId"] = trolltrain.RangeId + update["shop"] = trolltrain.Shop + update["items"] = trolltrain.Items + update["price"] = trolltrain.Price this.module.ModifyTrollData(session.GetUserId(), update) session.SendMsg(string(this.module.GetType()), TrollGetListResp, &pb.TrollGetListResp{Data: trolltrain}) return diff --git a/modules/troll/comp_configure.go b/modules/troll/comp_configure.go index bb669e495..bff1b384d 100644 --- a/modules/troll/comp_configure.go +++ b/modules/troll/comp_configure.go @@ -115,10 +115,12 @@ func (this *configureComp) GetTrollLv(id int32) (data *cfg.GameTrollLvData) { } func (this *configureComp) GetTrollAllTrain() (data []int32) { + data = make([]int32, 0) if v, err := this.GetConfigure(game_trolltrain); err == nil { if configure, ok := v.(*cfg.GameTrollTrain); ok { for _, v := range configure.GetDataList() { - data = append(data, v.Time) + time := v.Time + data = append(data, time) } return } diff --git a/modules/troll/module.go b/modules/troll/module.go index d92b8273b..01920e33f 100644 --- a/modules/troll/module.go +++ b/modules/troll/module.go @@ -50,105 +50,134 @@ func (this *Troll) ModifyTrollData(uid string, data map[string]interface{}) (cod return } -// AI 玩法 -func (this *Troll) TrollAI(session comm.IUserSession, troll *pb.DBTrollTrain) (code pb.ErrorCode) { +func (this *Troll) TrollAI(session comm.IUserSession, troll *pb.DBTrollTrain, aiCount int32) (code pb.ErrorCode) { var ( - trainCount int32 // 车站数量 - fTime []int32 //每个车站货物刷新的时间 - index int32 // 当前位置索引 - crossTime int32 // 经过的时间 - girdNum int32 // 格子数量 - leftGirdNum int32 // 购买后剩余格子数量 - // 购买的货物 - bugItem map[int32]int32 // 购买的数据 - bugItemPrice map[int32]int32 - constGold int32 - curRangeId int32 + t int64 // 上一次刷新的时间 + sellPrice map[int32]int32 // 出售货物价格 + totalGold int32 + pos int32 ) if troll.Buy != 0 && troll.Sell != 0 { return } - bugItem = make(map[int32]int32, 0) - bugItemPrice = make(map[int32]int32, 0) - troll.Buy = 840 - girdNum = troll.GridNum - maxGirdNum := this.configure.GetTrollRule(comm.TrollGridCount) // 获取背包最大格子数量 - maxgoods := this.configure.GetTrollRule(comm.TrollItemCount) // 获取单个物品最大上限 - trainCount = this.configure.GetTrollMaxTraintNum() - leftGirdNum = maxGirdNum - girdNum - fTime = make([]int32, trainCount) - for i := 0; i < int(trainCount); i++ { - if conf := this.configure.GetTrollTrain(int32(i) + 1); conf != nil { - fTime[i] = conf.Time - } - } - curRangeId = troll.RangeId - // 计算时间差 - crossTime = int32(time.Now().Unix() - troll.RefreshTime) - if crossTime < 10 { + sellPrice = make(map[int32]int32) + t = troll.RefreshTime + now := time.Now().Unix() + trainNum := this.configure.GetTrollMaxTraintNum() + maxCoefficient := this.configure.GetTrollMaxCoefficientNux() // 增长幅度的最大值 + if maxCoefficient == 0 { + code = pb.ErrorCode_ConfigNoFound return } - MaxRangeId := this.configure.GetTrollMaxCoefficientNux() // 随机增幅最大值 - for i := 0; ; i++ { - index = (int32(i) % trainCount) - if crossTime > fTime[index] { // 获取 - crossTime -= fTime[index] - if crossTime < 0 { - break + goods := this.configure.GetTrollAllGoods() + for _, v := range goods { + sellPrice[v.Id] = v.Goodsprice + } + sz := this.configure.GetTrollAllTrain() + if len(sz) == 0 { + return + } + iCount := this.configure.GetTrollRule(comm.TrollSurprise) + for { + pos++ + if pos > iCount { + break + } + index := int32(pos) % trainNum + if int32(len(sz)) <= index { + break + } + t += int64(sz[index]) + if now < t { + troll.RangeId++ + troll.TarinPos++ + troll.RangeId = (troll.RangeId % maxCoefficient) + 1 + troll.TarinPos = (troll.TarinPos % trainNum) + 1 + coefficient := this.configure.GetTrollCoefficient(troll.RangeId) + if coefficient == nil { + return } - curRangeId += 1 - curRangeId = curRangeId%int32(MaxRangeId) + 1 - if _d := this.configure.GetTrollCoefficient(curRangeId); _d != nil { - if troll.Buy <= int32(_d.Coefficient) { // 可以购买 那就尽最大的数量去买 - goods := this.configure.GetTrollAllGoods() // 获取所有的货物信息 - for _, v := range goods { - if leftGirdNum > 0 { // 剩余可购买格子数量 - bugItemPrice[v.Id] = v.Goodsprice * _d.Coefficient / 1000 // 货物买入的价格 - if troll.Items[v.Id] < v.Max { // 还可以购买的数量 - // 先把这个格子填满 - rd := troll.Items[v.Id] % maxgoods - buyN := v.Max - troll.Items[v.Id] - if buyN >= rd && rd != 0 { // 只能买这么多 那就全买了 - troll.Items[v.Id] += rd - buyN -= rd - bugItem[v.Id] += rd - } - for { - if buyN >= maxgoods { - leftGirdNum -= 1 - troll.Items[v.Id] += maxgoods - bugItem[v.Id] += maxgoods - if troll.Items[v.Id] >= v.Max { - break - } - } - if leftGirdNum <= 0 { - break - } - } - } - } else { // 补齐没有满的货物 - rd := troll.Items[v.Id] % maxgoods - if rd != 0 { - troll.Items[v.Id] += (maxgoods - rd) - } + if troll.Sell >= coefficient.Coefficient { // 可以出售 + for _, v := range goods { + sellPrice[v.Id] = v.Goodsprice * coefficient.Coefficient + } - } - } + totalGold += this.SellAllItem(troll, sellPrice) + troll.AiCount++ + if troll.AiCount > aiCount { //达到最大交易次数 + troll.RefreshTime = t // 设置上次刷新的时间 break } } + if troll.Buy >= coefficient.Coefficient { // 可以购买 + for _, v := range goods { + sellPrice[v.Id] = v.Goodsprice * coefficient.Coefficient + } + troll.Shop = make(map[int32]int32) // 买之前清除购买上限 + totalGold += this.BuyAllItem(session.GetUserId(), troll, sellPrice) + } + } else { // 超过当前时间 + troll.RefreshTime = t + break } } - for k, v := range bugItem { - constGold += bugItemPrice[k] * v - } - code = this.ModuleUser.AddAttributeValue(session, comm.ResGold, -int32(constGold), true) - if code != pb.ErrorCode_Success { // 金币不足 - code = pb.ErrorCode_GoldNoEnough - return - } + this.ModuleUser.AddAttributeValue(session, comm.ResGold, totalGold, true) - // 计算价格 + return +} + +// 出售所有货物 +func (this *Troll) SellAllItem(troll *pb.DBTrollTrain, price map[int32]int32) (gold int32) { + for k, v := range troll.Items { + if _, ok := price[k]; ok { + gold += price[k] * v + } + delete(troll.Items, k) // 清除数据 + } + return +} + +// 可以购买商品 +func (this *Troll) BuyAllItem(uid string, troll *pb.DBTrollTrain, price map[int32]int32) (gold int32) { + var ( + box map[int32]int32 // 盒子 存放可购买的物品 + leftGirdNum int32 // 剩余可购买格子数量 + costGold int32 + ) + + maxGirdNum := this.configure.GetTrollRule(comm.TrollGridCount) // 获取背包最大格子数量 + maxgoods := this.configure.GetTrollRule(comm.TrollItemCount) // 获取单个物品最大上限 20个 + + leftGirdNum = maxGirdNum - troll.GridNum + box = make(map[int32]int32, 0) + goods := this.configure.GetTrollAllGoods() + for _, v := range goods { + if leftGirdNum > 0 && troll.Shop[v.Id] < v.Max { + leftGirdNum-- + troll.Items[v.Id] += maxgoods + troll.Shop[v.Id] += maxgoods + box[v.Id] += maxgoods // 加入篮子 + } + // 检查该位置的格子没有补满 + full := (troll.Items[v.Id] + box[v.Id]) % maxgoods + if full != 0 { + box[v.Id] += (maxgoods - full) // 格子补满 + } + } + // 通过金币来校验哪些物品可以买 + curGold := this.ModuleUser.QueryAttributeValue(uid, comm.ResGold) + for k, v := range box { + for i := 0; i < int(v); i++ { //0 1 2 3 + curGold -= int64(price[k]) + costGold -= price[k] + if curGold < 0 { + box[k] = int32(i) + costGold += price[k] // 返还之前扣的 + break + } + } + } + troll.Items = box + gold = costGold return } From f641886c6e0d8c75216fd73c7787317781fd61a9 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Wed, 2 Nov 2022 21:42:36 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E5=BD=93=E6=97=A5=E6=9C=80=E5=A4=A7?= =?UTF-8?q?=E4=BA=A4=E6=98=93=E6=AC=A1=E6=95=B0=E8=B5=B0=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/troll/api_buyorsell.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/troll/api_buyorsell.go b/modules/troll/api_buyorsell.go index c214f8572..efaca41f2 100644 --- a/modules/troll/api_buyorsell.go +++ b/modules/troll/api_buyorsell.go @@ -34,6 +34,7 @@ func (this *apiComp) BuyOrSell(session comm.IUserSession, req *pb.TrollBuyOrSell code = pb.ErrorCode_DBError return } + dayMaxCount := this.configure.GetTrollRule(comm.TrollBuyCount) for k, v := range req.Items { if v == 0 { // 过滤数量为0 的消息 continue @@ -42,7 +43,7 @@ func (this *apiComp) BuyOrSell(session comm.IUserSession, req *pb.TrollBuyOrSell if !bSell { bSell = true trolltrain.SellCount += 1 // 交易次数+1 - if trolltrain.SellCount > 5 { + if trolltrain.SellCount > dayMaxCount { code = pb.ErrorCode_TrollMaxSellCount // 达到最大交易次数 直接返回 return }