2025-06-05 17:48:23 +08:00
|
|
|
package logic
|
|
|
|
|
|
|
|
import (
|
|
|
|
"ecs/proto/pb"
|
|
|
|
)
|
|
|
|
|
|
|
|
type PlayerHeroBook struct {
|
2025-06-06 18:31:44 +08:00
|
|
|
HeroId uint32 `json:"hero_id" key:"1"`
|
|
|
|
Items [][2]uint32 `bson:"items"`
|
2025-06-05 17:48:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (this *PlayerHeroBook) BuildMsgHeroBook() *pb.HeroBook {
|
|
|
|
var list []*pb.HeroBookItem
|
|
|
|
for _, item := range this.Items {
|
2025-06-06 18:31:44 +08:00
|
|
|
list = append(list, &pb.HeroBookItem{BookId: item[0], Status: pb.AbleStatus(item[1])})
|
2025-06-05 17:48:23 +08:00
|
|
|
}
|
|
|
|
return &pb.HeroBook{HeroId: this.HeroId, ItemList: list}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (this *Player) addHeroBook(heroId uint32) {
|
|
|
|
if _, ok := this.HeroBook[heroId]; ok {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2025-06-06 18:31:44 +08:00
|
|
|
var items [][2]uint32
|
2025-06-05 17:48:23 +08:00
|
|
|
var heroBookTables = this.manager.tables.HeroBook.Find2(int(heroId))
|
|
|
|
for _, heroBookTable := range heroBookTables {
|
2025-06-06 18:31:44 +08:00
|
|
|
var status = pb.AbleStatus_Able
|
|
|
|
for _, needHeroId := range heroBookTable.NeedHeroes {
|
|
|
|
if _, ok := this.HeroBook[uint32(needHeroId)]; !ok {
|
|
|
|
status = pb.AbleStatus_Unable
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
items = append(items, [2]uint32{uint32(heroBookTable.Id), uint32(status)})
|
2025-06-05 17:48:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
var heroBook = &PlayerHeroBook{
|
|
|
|
HeroId: heroId,
|
|
|
|
Items: items,
|
|
|
|
}
|
|
|
|
|
|
|
|
this.HeroBook[heroBook.HeroId] = heroBook
|
|
|
|
this.SaveModel(heroBook)
|
|
|
|
|
2025-06-20 15:34:46 +08:00
|
|
|
_ = this.Send(pb.ModId_ModuleHero, pb.MsgId_ModHeroBookChange, &pb.HeroBookListAck{
|
2025-06-06 18:31:44 +08:00
|
|
|
BookList: append(this.refreshHeroBook(heroBook.HeroId), heroBook.BuildMsgHeroBook()),
|
2025-06-05 17:48:23 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2025-06-06 18:31:44 +08:00
|
|
|
func (this *Player) refreshHeroBook(heroId uint32) (changeList []*pb.HeroBook) {
|
|
|
|
for _, heroBook := range this.HeroBook {
|
|
|
|
if heroBook.HeroId == heroId {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
var dirty = false
|
|
|
|
itemsLoop:
|
|
|
|
for _, item := range heroBook.Items {
|
|
|
|
if pb.AbleStatus(item[1]) >= pb.AbleStatus_Able {
|
|
|
|
continue itemsLoop
|
|
|
|
}
|
|
|
|
|
|
|
|
var heroBookTable = this.manager.tables.HeroBook.Find1(int(item[0]))
|
|
|
|
if heroBookTable == nil {
|
|
|
|
this.manager.logger.Error("Find hero book table failed, bookId: ", item[0])
|
|
|
|
continue itemsLoop
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, needHeroId := range heroBookTable.NeedHeroes {
|
|
|
|
if _, ok := this.HeroBook[uint32(needHeroId)]; !ok {
|
|
|
|
continue itemsLoop
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
item[1] = uint32(pb.AbleStatus_Able)
|
|
|
|
dirty = true
|
|
|
|
}
|
|
|
|
if dirty {
|
|
|
|
this.SaveModel(heroBook)
|
|
|
|
|
|
|
|
changeList = append(changeList, heroBook.BuildMsgHeroBook())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2025-06-05 17:48:23 +08:00
|
|
|
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}
|
|
|
|
}
|