class UR_PlayerController extends UTPlayerController;

enum PlayerClass
{
	eSurfer,
	eStealth,
	eAkimbo
};

enum PlayerWeapon
{
	eSniper,
	eLink,
	eRox,
	eHammer
};

enum PlayerKit
{
	eSlowField,
	eShield,
	eLandMine,
	eSkyMine
};

var Material StealthMaterial, SpeedOverlay;


reliable client function ShowClassMenu()
{
    DynamicOpenMenu("LP_UR_Assets.ClassMenu");
}

simulated function DynamicOpenMenu( string MenuPath, optional int PlayerIndex=INDEX_NONE )
{
	local UIScene Scene;
	local GameUISceneClient GS;

	GS = UTGameUISceneClient(class'UIRoot'.static.GetSceneClient());

    Scene = UIScene(DynamicLoadObject(MenuPath, class'UIScene'));
	UR_ClassMenu(Scene).PC = self;

	if ( !GS.OpenScene(Scene) )
	{
		`Log("Failed to load menu '" $ MenuPath $"'");
	}
}

reliable server function ServerForceRestartPlayer()
{
    super.ServerRestartPlayer();

    if(WorldInfo.NetMode != NM_Client)
	     WorldInfo.Game.RestartPlayer(self);
}

// class call back
simulated function changeClass(PlayerClass PC)
{
 serverChangeClass(PC);
}

reliable server function serverChangeClass(PlayerClass PC)
{
  local UR_PlayerReplicationInfo UR_PRI;
  UR_PRI = UR_PlayerReplicationInfo(PlayerReplicationInfo);
  UR_PRI.iClass = int(PC);
}

// Weapon call back
simulated function changeWeapon(PlayerWeapon PW)
{
 serverChangeWeapon(PW);
}

reliable server function serverChangeWeapon(PlayerWeapon PW)
{
  local UR_PlayerReplicationInfo UR_PRI;
  UR_PRI = UR_PlayerReplicationInfo(PlayerReplicationInfo);
  UR_PRI.iWeapon = int(PW);
}

//Kit call back
simulated function changeKit(PlayerKit PK)
{
 serverChangeKit(PK);
}

reliable server function serverChangeKit(PlayerKit PK)
{
  local UR_PlayerReplicationInfo UR_PRI;
  UR_PRI = UR_PlayerReplicationInfo(PlayerReplicationInfo);
  UR_PRI.iKit = int(PK);
}

//Shield call back
simulated function changeShield(int ArmourRatio)
{
 serverChangeShield(ArmourRatio);
}

reliable server function serverChangeShield(int ArRatio)
{
  local UR_PlayerReplicationInfo UR_PRI;
  UR_PRI = UR_PlayerReplicationInfo(PlayerReplicationInfo);
  UR_PRI.ArmourRatio = ArRatio;
}

//player effect
simulated function changePlayerEffect(int colour, LinearColor effect)
{
 serverChangeEffect(colour, effect);
}

reliable server function serverChangeEffect(int colour, LinearColor effect)
{
  local UR_PlayerReplicationInfo UR_PRI;
  UR_PRI = UR_PlayerReplicationInfo(PlayerReplicationInfo);
  UR_PRI.ColourData = colour;
  UR_PRI.EffectsColour = effect;
}

function PlayerClass getClass()
{
  local UR_PlayerReplicationInfo UR_PRI;
  UR_PRI = UR_PlayerReplicationInfo(PlayerReplicationInfo);
  switch(UR_PRI.iClass)
  {
    case UR_PRI.iSurfer :
       return eSurfer;

    case UR_PRI.iStealth :
       return eStealth;

    case UR_PRI.iAkimbo :
       return eAkimbo;
  }
  return eAkimbo;
}

function PlayerWeapon getWeapon()
{
  local UR_PlayerReplicationInfo UR_PRI;
  UR_PRI = UR_PlayerReplicationInfo(PlayerReplicationInfo);
  switch(UR_PRI.iWeapon)
  {
    case UR_PRI.iSniper:
       return eSniper;

    case UR_PRI.iLink:
       return eLink;

    case UR_PRI.iRox:
       return eRox;

    case UR_PRI.iHammer :
       return eHammer;
  }
  return eLink;
}

function PlayerKit getKit()
{
  local UR_PlayerReplicationInfo UR_PRI;
  UR_PRI = UR_PlayerReplicationInfo(PlayerReplicationInfo);
  switch(UR_PRI.iKit)
  {
    case UR_PRI.iSlowField:
       return eSlowField;

    case UR_PRI.iShield:
       return eShield;

    case UR_PRI.iLandMine:
       return eLandMine;

    case UR_PRI.iSkyMine:
       return eSkyMine;
  }
  return eSlowField;
}

state Dead
{
	exec function StartFire( optional byte FireModeNum )
	{
		if ( bFrozen )
		{
			if ( !IsTimerActive() || GetTimerCount() > MinRespawnDelay )
			{
				bFrozen = false;
			}
			return;
		}


        if (FireModeNum == 1 && (role < role_authority || WorldInfo.NetMode == NM_Standalone))
		{
			ShowClassMenu();
		}
	}
}

reliable client function PlayStartupMessage(byte StartupStage)
{
	if ( StartupStage == 7 )
	{
		ReceiveLocalizedMessage( class'UTTimerMessage', 17, PlayerReplicationInfo );
	}
	else
	{
		ReceiveLocalizedMessage( class'UR_StartupMessage', StartupStage, PlayerReplicationInfo );
	}
}

DefaultProperties
{
//	PlayerSelection = (PlayerClass = eAkimbo, PlayerWeapon = eLink, PlayerKit = eShield, ArmourRatio = 2, EffectsColour = (R=255,G=0,B=0,A=255) )
	StealthMaterial = Material'PICKUPS.Invis.M_Invis_01'
	SpeedOverlay = Material'PICKUPS.Invulnerability.M_Invulnerability_Overlay'
}