package equipment import ( "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/lego/sys/event" "go_dreamfactory/modules" "go_dreamfactory/pb" "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(source *comm.ModuleCallSource, 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(source *comm.ModuleCallSource, uid string, equipmentId string) (amount uint32) { amount = this.modelEquipment.QueryEquipmentAmount(uid, equipmentId) return } //添加武器 func (this *Equipment) AddNewEquipments(source *comm.ModuleCallSource, session comm.IUserSession, cIds map[string]uint32, bPush bool) (code pb.ErrorCode) { var ( err error change []*pb.DB_Equipment ) 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) 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 } //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 }