Law is such a mistery he seems very smart and calm headed so he wouldtn do things out of randomness he knows something behind the will of D i think thats why he saved luffy because luffy is one
of the carriers of the will of D and law must know that D's always cause trouble in the world or change and he wants to witness it plus he does want the competion to waste each other so he can
take the thrown at the last minute.
I doubt Law met Roger since Law is younger than Ace and when Roger dies, Ace wasn't even born yet AND Roger was never seen wearing the SH when he was the captain (only in his flashback). The hat was passed down to Shanks when he was a trainee on Roger's ship. Roger must have seen the potential in Shanks and was passing down his will to him, just like Shanks did to Luffy. Law is more lenient character towards SH while all the other supernovas kinda hate him for bringing an admiral to SA. It definitely would be a good alliance.
Law saved Luffy because he saw his potential at Sabaody. Luffy hit the celestial dragon without hesitation and then proved how strong he was when fought alongside himself and Kidd. Luffy also mentioned, "I'll be the one to find One Piece." That statement ticked Kidd off but Law smiled when he heard that and maybe he wanted a friendly relationship between Heart pirates and SH pirate.