Actually there are two places which are difficult to tackle. The first is the modification of the original shape script. This is not really recommended (I can't talk much about copyright and such stuff...) but you have all resources at hand. The script is stored in the original MDG, coded as base64 in one attribute of the element and then the decoded data is a zip which contains the script. Now if you do the reverse you have your own script instead of the original one. Try this first, it's quite tricky. And don't count on any support from Sparx.
Second is the add-in. You need to write your own add-in that will do the relations-count-magic and return it as a string you can use to encode the color. This might turn out to get cumbersome as shape script has very, very limited algorithmic capabilities. So you will likely need to limit the colors to a handful of hard coded values and not a "dynamical" color. I.e. you need to codeif hasproperty('addin:myRelations', '1') { ... }
for each level (the '1' might tell the add-in to look for 1-3 connectors, a '2' for 4-6 and so on)
You might want to look at Geert's EA-Matic for the add-in stuff.
q.