go_dreamfactory/modules/hero/module.go
2022-06-27 20:27:49 +08:00

87 lines
2.1 KiB
Go

package hero
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
)
func NewModule() core.IModule {
m := new(Hero)
return m
}
type Hero struct {
modules.ModuleBase
api_comp *Api_Comp
configure_comp *Configure_Comp
model_hero *ModelHero
}
//模块名
func (this *Hero) GetType() core.M_Modules {
return comm.SM_HeroModule
}
//模块初始化接口 注册用户创建角色事件
func (this *Hero) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) {
err = this.ModuleBase.Init(service, module, options)
return
}
//装备组件
func (this *Hero) OnInstallComp() {
this.ModuleBase.OnInstallComp()
this.api_comp = this.RegisterComp(new(Api_Comp)).(*Api_Comp)
this.model_hero = this.RegisterComp(new(ModelHero)).(*ModelHero)
this.configure_comp = this.RegisterComp(new(Configure_Comp)).(*Configure_Comp)
}
//通过唯一对象获取英雄信息
func (this *Hero) GetHeroInfoByObjID(id string) (*pb.DB_HeroData, pb.ErrorCode) {
return nil, pb.ErrorCode_HeroNoExist
}
//创建新英雄
func (this *Hero) CreatMultiHero(uid string, heroCfgId ...int32) error {
return this.model_hero.createMultiHero(uid, heroCfgId...)
}
//获取英雄
func (this *Hero) GetHero(uid, heroId string) (*pb.DB_HeroData, pb.ErrorCode) {
hero := this.model_hero.getOneHero(uid, heroId)
if hero == nil {
return nil, pb.ErrorCode_HeroNoExist
}
return hero, pb.ErrorCode_Success
}
func (this *Hero) ModifyHero(heroId *pb.DB_HeroData) (*pb.DB_HeroData, pb.ErrorCode) {
return nil, pb.ErrorCode_HeroNoExist
}
//佩戴装备
func (this *Hero) UpdateEquipment(hero *pb.DB_HeroData, equip []*pb.DB_Equipment) (code pb.ErrorCode) {
equipIds := make([]string, 4)
for _, v := range equip {
equipIds = append(equipIds, v.Id)
}
return this.model_hero.setEquipment(hero.Uid, hero.Id, equipIds)
}
//英雄列表
func (this *Hero) GetHeroList(uid string) []*pb.DB_HeroData {
list, err := this.model_hero.getHeroList(uid)
if err != nil {
return nil
}
return list
}
func (this *Hero) AddCard(uId string, cardId int32, add int32) (code pb.ErrorCode) {
return
}