package player

import (
	cfacade "github.com/mhaya/facade"
	"github.com/mhaya/game/game_cluster/nodes/game/module/online"
	clog "github.com/mhaya/logger"
	"github.com/mhaya/net/parser/pomelo"
	"time"
)

type (
	// ActorAvatars 玩家头像总管理actor
	ActorAvatars struct {
		pomelo.ActorBase
		Name          string
		childExitTime time.Duration
	}
)

func (p *ActorAvatars) AliasID() string {
	return "avatar" + p.Name
}

func (p *ActorAvatars) OnInit() {
	clog.Debugf("[ActorAvatars] path = %s init!", p.PathString())
}

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

	if err != nil {
		return nil, false
	}

	return childActor, true
}

func (p *ActorAvatars) OnStop() {
	clog.Infof("onlineCount = %d", online.Count())
}
