Says the Rambam [Shabbos 2-23]:
עוֹבְדֵי כּוֹכָבִים וּמַזָּלוֹת שֶׁצָּרוּ עַל עֲיָרוֹת יִשְׂרָאֵל אִם בָּאוּ עַל עִסְקֵי מָמוֹן אֵין מְחַלְּלִין עֲלֵיהֶן אֶת הַשַּׁבָּת וְאֵין עוֹשִׂין עִמָּהֶן מִלְחָמָה. וּבְעִיר הַסְּמוּכָה לַסְּפָר אֲפִלּוּ לֹא בָּאוּ אֶלָּא עַל עִסְקֵי תֶּבֶן וְקַשׁ יוֹצְאִין עֲלֵיהֶן בִּכְלֵי זַיִן וּמְחַלְּלִין עֲלֵיהֶן אֶת הַשַּׁבָּת. וּבְכָל מָקוֹם אִם בָּאוּ עַל עִסְקֵי נְפָשׁוֹת אוֹ שֶׁעָרְכוּ מִלְחָמָה אוֹ שֶׁצָּרוּ סְתָם יוֹצְאִין עֲלֵיהֶן בִּכְלֵי זַיִן וּמְחַלְּלִין עֲלֵיהֶן אֶת הַשַּׁבָּת.
[The following rules apply] when gentiles lay siege to Jewish cities If their intent was financial gain, the Shabbos laws should not be violated because of them, nor are we allowed to wage war against them. If a city is located near the border, however, we should march against them with weapons and wage war against them even when they are demanding hay or straw.
In any location, if the gentiles' intent was Jewish lives, or if they engaged in battle with a city or laid siege to it without stating a specific intention, we must wage war against them, and the Shabbos laws should be violated because of them.
I don't get it! The Rambam says that if they came על עסקי נפשות then you are מחלל שבת. But then he says או שערכו מלחמה. What does that mean?! If they are going to try to kill us he already said that. And if the מלחמה was not about נפשות but about money he already said that we are NOT מחלל שבת. So what is the case about??