I don't think it's illegal to rob directly, because robbing a lifebuoy and using it with others to save people will endanger their lives. For the matter of sacrificing yourself, you can only ask yourself and not force others, so the law will not stipulate this, and you can only accept moral condemnation.