There are plenty of rpg's that include a player-defined "alignment", allegiance, or personality, which the GM then adjudicates. Examples: World of Darkness, Spycraft, Burning Wheel, Toon, etc.
I don't think D&D has traditional had a roleplay mechanic in the vein of these games, and I'm not sure...