42 lines
1.0 KiB
Go
42 lines
1.0 KiB
Go
package logic
|
|
|
|
import (
|
|
"ecs/proto/pb"
|
|
"sort"
|
|
)
|
|
|
|
type PlayerLineup struct {
|
|
Uid uint64 `json:"uid" key:"1"`
|
|
Name string `bson:"name"`
|
|
Active bool `bson:"active"`
|
|
Heroes [8]*PlayerLineupHero `bson:"heroes"`
|
|
Helper [8]uint64 `bson:"helper"`
|
|
}
|
|
|
|
func (this *PlayerLineup) BuildMsgLineup() *pb.Lineup {
|
|
var msg = &pb.Lineup{Uid: this.Uid, Name: this.Name, Active: this.Active}
|
|
if this.Active {
|
|
msg.HeroList = make([]*pb.LineupHero, 8)
|
|
for i, hero := range this.Heroes {
|
|
if hero != nil {
|
|
msg.HeroList[i] = hero.BuildMsgLineupHero(uint32(i))
|
|
}
|
|
}
|
|
for _, helper := range this.Helper {
|
|
msg.HelpList = append(msg.HelpList, helper)
|
|
}
|
|
}
|
|
return msg
|
|
}
|
|
|
|
func (this *Player) BuildMsgLineupListAck() *pb.LineupListAck {
|
|
var list []*pb.Lineup
|
|
for _, lineup := range this.Lineup {
|
|
list = append(list, lineup.BuildMsgLineup())
|
|
}
|
|
sort.Slice(list, func(i, j int) bool {
|
|
return list[i].Uid < list[j].Uid
|
|
})
|
|
return &pb.LineupListAck{LineupList: list}
|
|
}
|