Hello men!
This is your capx-source.
I hope that it will be easy for you to understand all its mechanics.
There are some comments inside, but if you want more - write me a personal message or post your questions right here! I'll give you all support on my capx-source.
Attached image shows array structure.
X-axis means monsters, Y-axis means heroes. Each index is a proper instance of monster/hero.
Value on (X,Y) coordinates means == hero with (IID = Y) deal Value damage to monster with (IID = X)
After monster death we search for maximum Value in a column with number equal to this monster IID.
Y coordinate of this Value will be IID of hero who dealt max damage.
Enjoy!