I have a problem understanding the actual math behind kin selection.

So I have read the selfish gene and thought that I understand kin selection.

But then someone made this argument to me:

"Kin selection is nonsense, because a human should sacrifice his children to save the life of 10 fruit flies, (as a fruit fly shares around 50% of genes with a human), or some amount X of fruit flies, or maybe 5 chimpanzees (who share 98% of genes with a human)"

And while this seems ridiculous to me... I couldn't debunk it.

The math must be more complicated than simply adding up the gene copies, because if you just add up the amount of copies there would always be some amount X of fruit flies that you should prefer over your own children.

So I was thinking... it makes no sense, because some genes don't exist in fruit flies even if you have a trillion fruit flies.

So my question is: what is the actual math behind kin selection? how does it work? how do you actually calculate the value of an individual of any species?

I would also appreciate book recommendations that explain the math behind it in more detail than the selfish gene.