This commit is contained in:
liwei1dao 2022-11-03 10:13:32 +08:00
commit 7f9b134067
31 changed files with 635 additions and 195 deletions

View File

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

View File

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

View File

@ -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"),
},
}
)
@ -362,8 +368,8 @@ var (
Enabled: true,
},
ff(comm.ModuleMail, "getlist"): {
NavLabel: "邮件列表",
Desc: "邮件列表",
NavLabel: "我的邮件",
Desc: "我的邮件",
MainType: string(comm.ModuleMail),
SubType: "getlist",
Enabled: true,
@ -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,
},
}
)

View File

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

View File

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

View File

@ -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() {

View File

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

View File

@ -24,8 +24,6 @@ const (
const (
RDS_SESSION = "online"
RDS_SOCIATY = "all"
RDS_SOCIATYRANK = "rank"
)
//ERR
@ -414,6 +412,8 @@ const (
const (
TrollBuyCount int32 = iota + 1 // 单日最大交易次数
TrollAIBuyCount //离线最多交易次数
TrollItemCount //货物最大存储上限
TrollGridCount //背包格子

View File

@ -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)
// 初始化条件数据

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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置空

View File

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

View File

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

View File

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

View File

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

View File

@ -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) {
@ -71,7 +67,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 +82,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 +111,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 +148,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 +270,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 +288,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
}
@ -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
}
@ -554,6 +664,7 @@ func (this *ModelSociaty) updateMemberContribution(uid string, val int32, sociat
for _, m := range sociaty.Members {
if m.Uid == uid {
m.Contribution += val
break
}
}
@ -581,27 +692,30 @@ 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
}
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(comm.RDS_SOCIATYRANK, data.sociatyId, newRank)
this.AddList("", data.sociaty.Id, newRank)
}
} else {
this.AddList(comm.RDS_SOCIATYRANK, data.sociatyId, newRank)
if err := this.GetList(comm.RDS_SOCIATYRANK, &list); err != nil {
this.AddList("", data.sociaty.Id, newRank)
if err := this.GetList("", &list); err != nil {
log.Errorf("sociaty list err:%v", err)
return
}
@ -614,14 +728,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
}
@ -677,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
@ -698,3 +816,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
}

View File

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

View File

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

View File

@ -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
}
@ -55,7 +56,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 +148,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

View File

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

View File

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

View File

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

View File

@ -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"` //会长弹劾时间

View File

@ -11,7 +11,8 @@ import (
func newDBConn(lg log.ILogger, conf DBConfig) (conn *DBConn, err error) {
conn = &DBConn{
log: lg,
log: lg,
data: make(map[string]*ModelDataExpired),
}
if conf.RedisIsCluster {
conn.Redis, err = lgredis.NewSys(

View File

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

View File

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