package logic import ( "ecs/proto/pb" "github.com/oylshe1314/framework/util" ) type PlayerHeroBook struct { HeroId uint32 `json:"hero_id" key:"1"` Items []*util.Pair[uint32, bool] `bson:"items"` } func (this *PlayerHeroBook) BuildMsgHeroBook() *pb.HeroBook { var list []*pb.HeroBookItem for _, item := range this.Items { list = append(list, &pb.HeroBookItem{BookId: item.Key, Active: item.Value}) } return &pb.HeroBook{HeroId: this.HeroId, ItemList: list} } func (this *Player) addHeroBook(heroId uint32) { if _, ok := this.HeroBook[heroId]; ok { return } var items []*util.Pair[uint32, bool] var heroBookTables = this.manager.tables.HeroBook.Find2(int(heroId)) for _, heroBookTable := range heroBookTables { items = append(items, util.NewPair(uint32(heroBookTable.Id), false)) } var heroBook = &PlayerHeroBook{ HeroId: heroId, Items: items, } this.HeroBook[heroBook.HeroId] = heroBook this.SaveModel(heroBook) _ = this.Send(uint16(pb.ModId_ModuleHero), uint16(pb.MsgId_ModHeroBookChange), &pb.HeroBookChangeAck{ ChangeType: pb.ChangeType_Changed, HeroBook: heroBook.BuildMsgHeroBook(), }) } func (this *Player) BuildMsgHeroBookListAck() *pb.HeroBookListAck { var list []*pb.HeroBook for _, heroBook := range this.HeroBook { list = append(list, heroBook.BuildMsgHeroBook()) } return &pb.HeroBookListAck{BookList: list} }