package chess

import (
	chesstitiansApi "mongo.games.com/game/api3th/smart/chesstitians"
	"mongo.games.com/game/proto"
	proto_chesstitians "mongo.games.com/game/protocol/chesstitians"
	"mongo.games.com/game/robot/base"
)

var ChesstitiansNilPlayer *ChesstitiansPlayer = nil

type ChesstitiansPlayer struct {
	base.BasePlayer
	*proto_chesstitians.ChesstitiansPlayerData
	data *chesstitiansApi.PredictRequest
}

func NewChesstitiansPlayer(data *proto_chesstitians.ChesstitiansPlayerData) *ChesstitiansPlayer {
	p := &ChesstitiansPlayer{ChesstitiansPlayerData: data}
	p.Init()
	return p
}

func (p *ChesstitiansPlayer) Init() {
	p.Clear()
}

func (p *ChesstitiansPlayer) Clear() {

}

func (p *ChesstitiansPlayer) MarkFlag(flag int32) {
	myFlag := p.GetFlag()
	myFlag |= flag
	p.Flag = proto.Int32(myFlag)
}

func (p *ChesstitiansPlayer) UnmarkFlag(flag int32) {
	myFlag := p.GetFlag()
	myFlag &= ^flag
	p.Flag = proto.Int32(myFlag)
}

func (p *ChesstitiansPlayer) IsMarkFlag(flag int32) bool {
	if (p.GetFlag() & flag) != 0 {
		return true
	}
	return false
}

func (p *ChesstitiansPlayer) IsOnLine() bool {
	return p.IsMarkFlag(base.PlayerState_Online)
}

func (p *ChesstitiansPlayer) IsReady() bool {
	return true
}

func (p *ChesstitiansPlayer) IsSceneOwner() bool {
	return false
}

func (p *ChesstitiansPlayer) CanOp() bool {
	return true
}

func (p *ChesstitiansPlayer) IsRobot() bool {
	player := base.PlayerMgrSingleton.GetPlayer(p.GetSnId())
	return player != nil
}

func (p *ChesstitiansPlayer) SetFlag(flag int32) {
	p.Flag = proto.Int32(flag)
}

func (p *ChesstitiansPlayer) GetLastOp() int32 {
	return 0
}

func (p *ChesstitiansPlayer) SetLastOp(op int32) {
}

func (p *ChesstitiansPlayer) UpdateCards(cards []int32) {
}
