任务模块

This commit is contained in:
zhaocy 2022-07-05 12:00:35 +08:00
parent d841560c25
commit 0e77e182f8
7 changed files with 114 additions and 2 deletions

View File

@ -40,6 +40,7 @@ const (
ModuleForum core.M_Modules = "forum" //论坛模块
ModuleItems core.M_Modules = "items" //道具模块
ModuleShop core.M_Modules = "shop" //商店模块
ModuleTask core.M_Modules = "task" //任务模块
)
//RPC服务接口定义处

View File

@ -3,6 +3,7 @@ package hero
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
)
@ -46,6 +47,11 @@ func (this *Hero) CreateHero(uid string, heroCfgId ...int32) error {
//消耗英雄卡
func (this *Hero) ConsumeCard(uId string, heroCfgId int32, count int32) (code pb.ErrorCode) {
if count <= 0 {
log.Errorf("attr no changed,uid: %s heroCfgId: %s count: %d", uId, heroCfgId, count)
code = pb.ErrorCode_ReqParameterError
return
}
heroes := this.GetHeroList(uId)
var curList []*pb.DBHero
for _, v := range heroes {

11
modules/task/api.go Normal file
View File

@ -0,0 +1,11 @@
package task
import (
"go_dreamfactory/lego/base"
"go_dreamfactory/modules"
)
type apiComp struct {
modules.MCompGate
service base.IRPCXService
}

View File

@ -0,0 +1,20 @@
package task
import (
"go_dreamfactory/lego/core"
"go_dreamfactory/modules"
)
const ( //Redis
TableTask core.SqlTable = "task" //任务表
)
type ModelTask struct {
modules.MCompModel
}
func (this *ModelTask) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
err = this.MCompModel.Init(service, module, comp, options)
this.TableName = string(TableTask)
return
}

48
modules/task/module.go Normal file
View File

@ -0,0 +1,48 @@
package task
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/modules"
"time"
)
type TaskModule struct {
modules.ModuleBase
modelTask *ModelTask
api *apiComp
}
func NewModule() core.IModule {
return &TaskModule{}
}
func (this *TaskModule) GetType() core.M_Modules {
return comm.ModuleTask
}
func (this *TaskModule) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) {
err = this.ModuleBase.Init(service, module, options)
go func() {
tickC := time.NewTicker(time.Second * 1)
for {
select {
case tc := <-tickC.C:
this.update(tc)
}
}
}()
return
}
func (this *TaskModule) OnInstallComp() {
this.ModuleBase.OnInstallComp()
this.api = this.RegisterComp(new(apiComp)).(*apiComp)
this.modelTask = this.RegisterComp(new(ModelTask)).(*ModelTask)
}
func (this *TaskModule) update(t time.Time) {
}

View File

@ -6,6 +6,7 @@ import (
"go_dreamfactory/pb"
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/log"
)
func NewModule() core.IModule {
@ -74,12 +75,35 @@ func (this *User) QueryAttributeValue(uid string, attr string) (value int32) {
//用户资源
func (this *User) AddAttributeValue(uid string, attr string, add int32) (code pb.ErrorCode) {
if add == 0 {
log.Errorf("attr no changed,uid: %s attr: %s add: %d", uid, attr, add)
code = pb.ErrorCode_ReqParameterError
return
}
user := this.GetUser(uid)
if user == nil {
code = pb.ErrorCode_UserSessionNobeing
return
}
update := make(map[string]interface{})
switch attr {
case comm.ResGold:
update[comm.ResGold] = add
if add < 0 {
if user.Gold+add < 0 {
code = pb.ErrorCode_GoldNoEnough
return
}
}
update[comm.ResGold] = user.Gold + add
case comm.ResExp:
update[comm.ResExp] = add
if add < 0 {
if user.Exp+add < 0 {
code = pb.ErrorCode_ResNoEnough
return
}
}
update[comm.ResExp] = user.Gold + add
}
if err := this.modelUser.updateUserAttr(uid, update); err != nil {

View File

@ -8,6 +8,7 @@ import (
"go_dreamfactory/modules/hero"
"go_dreamfactory/modules/items"
"go_dreamfactory/modules/mail"
"go_dreamfactory/modules/task"
"go_dreamfactory/modules/user"
"go_dreamfactory/services"
"go_dreamfactory/sys/cache"
@ -44,6 +45,7 @@ func main() {
friend.NewModule(),
hero.NewModule(),
equipment.NewModule(),
task.NewModule(),
)
}