package main

import (
	"mongo.games.com/goserver/core/logger"

	"mongo.games.com/game/common"
)

// 象棋特殊匹配实现

func init() {
	RegisterCoinScenePool(common.GameId_ChesstitiansCambodian, new(CoinScenePoolChess))
	RegisterCoinScenePool(common.GameId_ChesstitiansCambodianRobot, new(CoinScenePoolChess))
}

type CoinScenePoolChess struct {
	BaseCoinScenePool
}

func (this *CoinScenePoolChess) New() interface{} {
	return &ChessMatchPool{
		IdItem: make(map[int32]*ChessMatchItem),
	}
}

func (this *CoinScenePoolChess) OnPlayerEnter(pool *CoinScenePool, p *Player, scene *Scene) {
	var cmp *ChessMatchPool
	var ok bool
	if pool != nil && pool.extraData != nil {
		cmp, ok = pool.extraData.(*ChessMatchPool)
	}
	if !ok || cmp == nil {
		logger.Logger.Errorf("(this *CoinScenePoolChess) OnPlayerEnter not found ChessMatchPool")
		return
	}

	if scene.IsFull() {
		for k := range scene.players {
			cmp.Del(k)
		}
	} else {
		cmp.Add(p.SnId, p.ChessGrade, scene.sceneId)
	}
}

func (this *CoinScenePoolChess) OnPlayerLeave(pool *CoinScenePool, s *Scene, p *Player) {
	var cmp *ChessMatchPool
	var ok bool
	if pool != nil && pool.extraData != nil {
		cmp, ok = pool.extraData.(*ChessMatchPool)
	}
	if !ok || cmp == nil {
		logger.Logger.Errorf("(this *CoinScenePoolChess) OnPlayerLeave not found ChessMatchPool")
		return
	}
	cmp.Del(p.SnId)
}
