importonly abstract class gameIPlayerSystem extends IGameSystem
{
}

importonly abstract class gamePlayerSystem extends gameIPlayerSystem
{
	public import function PlayerEnteredCombat( playerEnteredCombat : Bool );
}

import final class PlayerSystem extends gamePlayerSystem
{
	public import const function GetGameInstance() : GameInstance;
	public import const function GetLocalPlayerMainGameObject() : GameObject;
	public import const function GetLocalPlayerControlledGameObject() : GameObject;
	public import function LocalPlayerControlExistingObject( entityID : EntityID );
	public import function RegisterPlayerPuppetAttachedCallback( object : IScriptable, func : CName ) : Uint32;
	public import function UnregisterPlayerPuppetAttachedCallback( callbackID : Uint32 );
	public import function RegisterPlayerPuppetDetachedCallback( object : IScriptable, func : CName ) : Uint32;
	public import function UnregisterPlayerPuppetDetachedCallback( callbackID : Uint32 );
	public import function FindPlayerControlledObjects( position : Vector4, radius : Float, includeLocalPlayers : Bool, includeRemotePlayers : Bool, out outPlayerGameObjects : array< GameObject > ) : Uint32;
	public import function IsInFreeCamera() : Bool;
	public import function SetFreeCameraTransform( newTransform : Transform );
	public import function IsCPOControlSchemeForced() : Bool;

	public constexpr const function GetPossessedByJohnnyFactName() : String
	{
		return "isPlayerPossessedByJohnny";
	}

	protected event OnGameRestored()
	{
		if( GameInstance.GetQuestsSystem( GetGameInstance() ).GetFactStr( GetPossessedByJohnnyFactName() ) )
		{
			OnLocalPlayerPossesionChanged( gamedataPlayerPossesion.Johnny );
		}
		else
		{
			OnLocalPlayerPossesionChanged( gamedataPlayerPossesion.Default );
		}
		return true;
	}

	protected event OnShutdown()
	{
		OnLocalPlayerPossesionChanged( gamedataPlayerPossesion.Default );
		return true;
	}

	protected event OnLocalPlayerChanged( controlledObject : weak< GameObject > )
	{
		var controlledPuppet : gamePuppetBase;
		var controlledPuppetRecordID : TweakDBID;
		var playerStatsBB : IBlackboard;
		controlledPuppet = ( ( gamePuppetBase )( controlledObject ) );
		if( controlledPuppet == NULL )
		{
			return false;
		}
		playerStatsBB = GameInstance.GetBlackboardSystem( GetGameInstance() ).Get( GetAllBlackboardDefs().UI_PlayerStats );
		controlledPuppetRecordID = controlledPuppet.GetRecordID();
		if( controlledPuppetRecordID == T"Character.Player_Puppet_Base" )
		{
			playerStatsBB.SetBool( GetAllBlackboardDefs().UI_PlayerStats.isReplacer, false, true );
		}
		else if( controlledPuppetRecordID == T"Character.johnny_replacer" )
		{
			playerStatsBB.SetBool( GetAllBlackboardDefs().UI_PlayerStats.isReplacer, true, true );
		}
		else if( controlledPuppetRecordID == T"Character.kurt_replacer" )
		{
			playerStatsBB.SetBool( GetAllBlackboardDefs().UI_PlayerStats.isReplacer, true, true );
		}
		else
		{
			playerStatsBB.SetBool( GetAllBlackboardDefs().UI_PlayerStats.isReplacer, true, true );
		}
		return true;
	}

	protected event OnLocalPlayerPossesionChanged( playerPossesion : gamedataPlayerPossesion )
	{
		var uiSystem : UISystem;
		uiSystem = GameInstance.GetUISystem( GetGameInstance() );
		if( playerPossesion == gamedataPlayerPossesion.Default )
		{
			if( uiSystem )
			{
				uiSystem.ClearGlobalThemeOverride();
			}
		}
		else if( playerPossesion == gamedataPlayerPossesion.Johnny )
		{
			if( uiSystem )
			{
				uiSystem.SetGlobalThemeOverride( 'Possessed' );
			}
		}
		return true;
	}

}

