package base

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

	serverproto "mongo.games.com/game/protocol/server"
)

func init() {
	// 邀请机器人
	netlib.Register(int(serverproto.SSPacketID_PACKET_WR_INVITEROBOT), serverproto.WRInviteRobot{}, WRInviteRobot)

	//GameFree数据同步
	netlib.Register(int(serverproto.SSPacketID_PACKET_GR_GameFreeData), serverproto.GRGameFreeData{}, func(s *netlib.Session, packetId int, data interface{}) error {
		logger.Logger.Trace("GRGameFreeData ", data)
		if msg, ok := data.(*serverproto.GRGameFreeData); ok {
			roomId := msg.GetRoomId()
			dbGameFree := msg.GetDBGameFree()
			SceneMgrSingleton.UpdateSceneDBGameFree(roomId, dbGameFree)
		}
		return nil
	})

	//房间销毁
	netlib.Register(int(serverproto.SSPacketID_PACKET_GR_DESTROYSCENE), serverproto.GRDestroyScene{}, func(s *netlib.Session, packetId int, data interface{}) error {
		logger.Logger.Trace("GRDestroyScene ", data)
		if msg, ok := data.(*serverproto.GRDestroyScene); ok {
			sceneId := msg.GetSceneId()
			SceneMgrSingleton.DelScene(sceneId)
		}
		return nil
	})
}

func WRInviteRobot(s *netlib.Session, packetId int, data interface{}) error {
	logger.Logger.Trace("WRInviteRobot ", data)

	PlayerMgrSingleton.ProcessCheckRobotNum()

	if msg, ok := data.(*serverproto.WRInviteRobot); ok {
		roomId := msg.GetRoomId()
		gamefreeId := msg.GetMatchId()
		cnt := msg.GetCnt()
		platform := msg.GetPlatform()
		PlayerMgrSingleton.ProcessInvite(roomId, gamefreeId, cnt, platform, msg.IsMatch)
	}
	return nil
}
