package module

import (
	cfacade "github.com/mhaya/facade"
	"github.com/mhaya/game/game_cluster/internal/mdb/models"
	"github.com/mhaya/net/parser/simple"
)

type (
	// ActorDBs 玩家总管理actor
	ActorDBs struct {
		simple.ActorBase
	}
)

func (p *ActorDBs) AliasID() string {
	return "dbs"
}

func (p *ActorDBs) OnInit() {
	playerIdMap = make(map[string]*models.Player)
	accountIdMap = make(map[string]*models.Account)
}

func (p *ActorDBs) OnFindChild(msg *cfacade.Message) (cfacade.IActor, bool) {
	// 动态创建 player child actor
	childID := msg.TargetPath().ChildID
	childActor, err := p.Child().Create(childID, &ActorDBChild{})

	if err != nil {
		return nil, false
	}

	return childActor, true
}
