package player import ( nameActor "f1-game/internal/name/actor" cstring "github.com/cherry-game/cherry/extend/string" cfacade "github.com/cherry-game/cherry/facade" "github.com/cherry-game/cherry/net/parser/pomelo" ) type ( actor struct { pomelo.ActorBase workerSize int } ) func NewActor(workerSize int) *actor { if workerSize < 1 { workerSize = 1 } return &actor{ workerSize: workerSize, } } func (p *actor) AliasID() string { return nameActor.CenterPlayer } func (p *actor) OnInit() { for i := range p.workerSize { childID := cstring.ToString(i) childActor := &actorUID{} p.Child().Create(childID, childActor) } } // OnRemoteReceived 转发到actorUID func (p *actor) OnRemoteReceived(m *cfacade.Message) (next bool, invoke bool) { if m.TargetPath().IsParent() { return true, false } hashID, ok := cstring.ToInt(m.TargetPath().ChildID, 0) if !ok || hashID < 1 { return true, false } childID := cstring.ToString(hashID % p.workerSize) if child, found := p.Child().Get(childID); found { child.PostRemote(m) } return false, false }