184 lines
5.1 KiB
Go
184 lines
5.1 KiB
Go
package equipment
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/lego/sys/event"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
|
|
"github.com/go-redis/redis/v8"
|
|
)
|
|
|
|
/*
|
|
模块名:装备
|
|
描述:用户装备管理以及装备升级强化相关
|
|
开发:李伟
|
|
*/
|
|
func NewModule() core.IModule {
|
|
m := new(Equipment)
|
|
return m
|
|
}
|
|
|
|
type Equipment struct {
|
|
modules.ModuleBase
|
|
service core.IService
|
|
chat comm.IChat
|
|
api *apiComp
|
|
configure *configureComp
|
|
modelEquipment *modelEquipmentComp
|
|
}
|
|
|
|
//模块名
|
|
func (this *Equipment) GetType() core.M_Modules {
|
|
return comm.ModuleEquipment
|
|
}
|
|
|
|
//模块初始化接口 注册用户创建角色事件
|
|
func (this *Equipment) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) {
|
|
err = this.ModuleBase.Init(service, module, options)
|
|
this.service = service
|
|
return
|
|
}
|
|
|
|
//模块启动接口
|
|
//模块启动
|
|
func (this *Equipment) Start() (err error) {
|
|
err = this.ModuleBase.Start()
|
|
var module core.IModule
|
|
if module, err = this.service.GetModule(comm.ModuleChat); err != nil {
|
|
return
|
|
}
|
|
this.chat = module.(comm.IChat)
|
|
event.RegisterGO(comm.EventUserOffline, this.EventUserOffline)
|
|
return
|
|
}
|
|
|
|
//装备组件
|
|
func (this *Equipment) OnInstallComp() {
|
|
this.ModuleBase.OnInstallComp()
|
|
this.api = this.RegisterComp(new(apiComp)).(*apiComp)
|
|
this.modelEquipment = this.RegisterComp(new(modelEquipmentComp)).(*modelEquipmentComp)
|
|
this.configure = this.RegisterComp(new(configureComp)).(*configureComp)
|
|
}
|
|
|
|
//Event------------------------------------------------------------------------------------------------------------
|
|
func (this *Equipment) EventUserOffline(session comm.IUserSession) {
|
|
err := this.modelEquipment.BatchDelLists(session.GetUserId())
|
|
this.Debugf("EventUserOffline:%s err:%v", session, err)
|
|
}
|
|
|
|
//IEquipment-------------------------------------------------------------------------------------------------------------------------------
|
|
//查询武器信息
|
|
func (this *Equipment) QueryEquipment(uid string, id string) (equipment *pb.DB_Equipment, code pb.ErrorCode) {
|
|
var err error
|
|
if uid == "" || id == "" {
|
|
this.Errorf("请求参数错误 uid:%s Id:%s", uid, id)
|
|
code = pb.ErrorCode_ReqParameterError
|
|
return
|
|
}
|
|
if equipment, err = this.modelEquipment.QueryUserEquipmentsById(uid, id); err != nil {
|
|
if err == redis.Nil {
|
|
code = pb.ErrorCode_EquipmentOnFoundEquipment
|
|
} else {
|
|
code = pb.ErrorCode_SystemError
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
//查询卡片数量
|
|
func (this *Equipment) QueryEquipmentAmount(uid string, equipmentId string) (amount uint32) {
|
|
amount = this.modelEquipment.QueryEquipmentAmount(uid, equipmentId)
|
|
return
|
|
}
|
|
|
|
//添加武器
|
|
func (this *Equipment) AddNewEquipments(session comm.IUserSession, cIds map[string]uint32, bPush bool) (change []*pb.DB_Equipment, code pb.ErrorCode) {
|
|
var (
|
|
err error
|
|
)
|
|
if change, err = this.modelEquipment.AddEquipments(session, cIds); err != nil {
|
|
this.Errorf("err%v", err)
|
|
code = pb.ErrorCode_SystemError
|
|
return
|
|
}
|
|
if len(change) > 0 && bPush {
|
|
this.equipmentsChangePush(session, change)
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *Equipment) AddAllEquipments(session comm.IUserSession) (code pb.ErrorCode) {
|
|
var (
|
|
configure *cfg.GameEquip
|
|
cIds map[string]uint32
|
|
err error
|
|
)
|
|
if configure, err = this.configure.GetEquipmentConfigure(); err != nil {
|
|
code = pb.ErrorCode_ConfigNoFound
|
|
return
|
|
}
|
|
cIds = make(map[string]uint32)
|
|
for _, v := range configure.GetDataList() {
|
|
cIds[v.Id] = 1
|
|
}
|
|
_, code = this.AddNewEquipments(session, cIds, true)
|
|
return
|
|
}
|
|
|
|
//删除武器
|
|
func (this *Equipment) DelEquipments(session comm.IUserSession, equipIds []string, bPush bool) (code pb.ErrorCode) {
|
|
var (
|
|
err error
|
|
change []*pb.DB_Equipment
|
|
)
|
|
if change, err = this.modelEquipment.DelEquipments(session.GetUserId(), equipIds); err != nil {
|
|
this.Errorf("err%v", err)
|
|
code = pb.ErrorCode_SystemError
|
|
return
|
|
}
|
|
if len(change) > 0 && bPush {
|
|
this.equipmentsChangePush(session, change)
|
|
}
|
|
return
|
|
}
|
|
|
|
//创建新的装备
|
|
func (this *Equipment) NewEquipment(uid, cid string) (code pb.ErrorCode, equip *pb.DB_Equipment) {
|
|
var (
|
|
conf *cfg.GameEquipData
|
|
err error
|
|
)
|
|
if conf, err = this.configure.GetEquipmentConfigureById(cid); err != nil {
|
|
code = pb.ErrorCode_ConfigNoFound
|
|
return
|
|
}
|
|
if equip, err = this.modelEquipment.newEquipment(uid, conf); err != nil {
|
|
code = pb.ErrorCode_ConfigNoFound
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
//创建新的装备
|
|
func (this *Equipment) AddEquipment(session comm.IUserSession, equip *pb.DB_Equipment) (code pb.ErrorCode) {
|
|
var (
|
|
err error
|
|
)
|
|
if err = this.modelEquipment.addEquipment(equip); err != nil {
|
|
code = pb.ErrorCode_DBError
|
|
return
|
|
}
|
|
this.equipmentsChangePush(session, []*pb.DB_Equipment{equip})
|
|
return
|
|
}
|
|
|
|
//Evens--------------------------------------------------------------------------------------------------------------------------------
|
|
//推送道具变化消息
|
|
func (this *Equipment) equipmentsChangePush(session comm.IUserSession, items []*pb.DB_Equipment) (err error) {
|
|
session.SendMsg(string(this.GetType()), "change", &pb.EquipmentChangePush{Equipments: items})
|
|
return
|
|
}
|