package player

import (
	"blazing/modules/blazing/model"
	"time"
)

// NewPlayer 使用 Options 模式创建 Player 实例
func NewPlayer(opts ...PlayerOption) *Player {
	p := &Player{
		loginChan:   make(chan struct{}),
		HavePVPinfo: make([]*Player, 0),
		baseplayer:  newbaseplayer(),
	}
	p.monsters = generateThreeUniqueNumbers()

	p.StopChan = make(chan struct{})

	// 启动刷怪协程
	go func(stopChan chan struct{}) {

		ticker := time.NewTicker(10 * time.Second)
		defer ticker.Stop()

		for {
			select {
			case <-stopChan:
				// 收到停止信号，退出协程
				return
			case <-ticker.C:
				// 刷新当前地图的怪物
				if p.Canmon && p.FightC == nil { //已经进入地图或者没在战斗中，就可以刷新怪
					p.SpawnMonsters()
				}

			}
		}
	}(p.StopChan)
	for _, opt := range opts {
		opt(p)
	}
	return p
}

func NewAI_player(i *model.PlayerInfo) *AI_player {
	ret := &AI_player{
		baseplayer: newbaseplayer(),
	}

	ret.Info = i
	//ret.Info.Nick = xmlres.PetMAP[int(m.ID)].DefName
	return ret

}
