75 lines
2.4 KiB
Go
75 lines
2.4 KiB
Go
package pack
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/sys/cache"
|
|
"go_dreamfactory/sys/db"
|
|
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/lego/sys/event"
|
|
"go_dreamfactory/lego/sys/log"
|
|
)
|
|
|
|
/*
|
|
模块名:Pack
|
|
描述:背包系统模块
|
|
开发:李伟
|
|
*/
|
|
func NewModule() core.IModule {
|
|
m := new(Pack)
|
|
return m
|
|
}
|
|
|
|
type Pack struct {
|
|
modules.ModuleBase
|
|
api_comp *Api_Comp //背包模块 协议处理组件
|
|
configure_comp *Configure_Comp //背包模块 配置相关接口封装组件
|
|
}
|
|
|
|
//模块名称
|
|
func (this *Pack) GetType() core.M_Modules {
|
|
return comm.SM_PackModule
|
|
}
|
|
|
|
//模块初始化接口 注册用户创建角色事件
|
|
func (this *Pack) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) {
|
|
err = this.ModuleBase.Init(service, module, options)
|
|
event.RegisterGO(comm.Event_CreateUser, this.event_CreateUser)
|
|
return
|
|
}
|
|
|
|
//装备组件
|
|
func (this *Pack) OnInstallComp() {
|
|
this.ModuleBase.OnInstallComp()
|
|
this.api_comp = this.RegisterComp(new(Api_Comp)).(*Api_Comp)
|
|
this.configure_comp = this.RegisterComp(new(Configure_Comp)).(*Configure_Comp)
|
|
}
|
|
|
|
//IPack-------------------------------------------------------------------------------------------------------------------------------
|
|
///添加单个物品到背包 (可以加物品和减物品)
|
|
func (this *Pack) AddItemToUserPack(uId string, itemid, addnum int32) (err error) {
|
|
defer log.Debugf("给用户添加物品 uId:%s itemid:%d addnum:%d issucc:%v", uId, itemid, addnum, err == nil)
|
|
if err = cache.Defsys.Pack_AddItemToUserPack(uId, itemid, addnum); err != nil {
|
|
log.Errorf("给用户添加物品 uId:%s itemid:%d addnum:%d err:%v", uId, itemid, addnum, err)
|
|
}
|
|
return
|
|
}
|
|
|
|
///添加多个物品到背包 (可以加物品和减物品)
|
|
func (this *Pack) AddItemsToUserPack(uId string, items map[int32]int32) (err error) {
|
|
defer log.Debugf("给用户添加物品 uId:%s items:%d items:%v", uId, items, err == nil)
|
|
if err = cache.Defsys.Pack_AddItemsToUserPack(uId, items); err != nil {
|
|
log.Errorf("给用户添加物品 uId:%s items:%d err:%v", uId, items, err)
|
|
}
|
|
return
|
|
}
|
|
|
|
//Evens--------------------------------------------------------------------------------------------------------------------------------
|
|
//接收玩家创建角色事件
|
|
func (this *Pack) event_CreateUser(uid string) {
|
|
if _, err := db.Defsys.Pack_InitUserPack(uid); err != nil {
|
|
log.Errorf("event_CreateUser err:%v", err)
|
|
}
|
|
}
|