check that perm is valid before associating trigger/static with it, fixes issue with Sosuke
move trigger to before logic checking target as IfDamageWouldBeDealt trigger may change target, fixes Pariah
replace priority number with priority constant in MagicIfDamageWouldBeDealtTrigger
Captain of the Mists should tap/untap target permanent not target creature
correct script of Syncopate not using X from its mana cost in the counter event

fixes issue 399