@@ -137,14 +137,12 @@ local function IsPhaseUrgent()
137137 return timeRemaining and timeRemaining < URGENT_ATTACK_TIME
138138end
139139
140- local function FindMyAttackPhasePlanet (lobby , planets )
141- local planetID = lobby .planetwarsData .attackPhasePlanet
140+ local function FindMatchingPlanet (planetID , planetAttacker , planets )
142141 if not planetID then
143142 return false
144143 end
145- local faction = lobby :GetMyFaction ()
146144 for i = 1 , # planets do
147- if planets [i ].PlanetID == planetID and planets [i ].AttackerFaction == faction then
145+ if planets [i ].PlanetID == planetID and planets [i ].AttackerFaction == planetAttacker then
148146 return planets [i ]
149147 end
150148 end
@@ -155,24 +153,23 @@ local function GetActivityToPrompt(lobby, attackerFactions, defenderFactions, cu
155153 if not (planets and planets [1 ]) then
156154 return false
157155 end
158-
159- if lobby .planetwarsData .attackingPlanet and planets then
160- local myPlanet = FindMyAttackPhasePlanet (lobby , planets )
156+ local activePlanet = lobby .planetwarsData .attackingPlanet or lobby .planetwarsData .defendingPlanet
157+ local activePlanetAttacker = lobby .planetwarsData .attackingPlanetAttacker or lobby .planetwarsData .defendingPlanetAttacker
158+ Spring .Echo (" MODEMODEMODE" , activePlanet , activePlanetAttacker , currentMode , lobby .PW_ATTACK )
159+ if currentMode == lobby .PW_ATTACK and activePlanet then
160+ local myPlanet = FindMatchingPlanet (activePlanet , activePlanetAttacker , planets )
161+ Spring .Echo (" myPlanetmyPlanetmyPlanet" , myPlanet )
161162 if myPlanet then
162163 return myPlanet , true , true , false
163164 end
164165 return false
165166 end
166- local attackPhase , defendPhase = GetAttackingOrDefending (lobby , attackerFactions , defenderFactions )
167- if lobby .planetwarsData .joinPlanet and planets then
168- local planetID = lobby .planetwarsData .joinPlanet
169- local attacker = lobby .planetwarsData .joinPlanetAttacker
170- for i = 1 , # planets do
171- if planets [i ].PlanetID == planetID and planets [i ].AttackerFaction == attacker then
172- return planets [i ], attackPhase , true , true
173- end
167+ local attackPhase = (currentMode == lobby .PW_ATTACK )
168+ if currentMode == lobby .PW_DEFEND and activePlanet then
169+ local myPlanet = FindMatchingPlanet (activePlanet , activePlanetAttacker , planets )
170+ if myPlanet then
171+ return myPlanet , attackPhase , true , true
174172 end
175- return false
176173 end
177174
178175 if IsPhaseUrgent () then
@@ -1356,15 +1353,26 @@ local function InitializeControls(window)
13561353 local myFaction = lobby :GetMyFaction ()
13571354 planetStatusData .myAttackers = 0
13581355 planetStatusData .myIncoming = 0
1359- planetStatusData .neutralDefense = 0
1356+ planetStatusData .neutralIncoming = 0
1357+ planetStatusData .myDefend = 0
1358+ planetStatusData .myDefendMax = 0
1359+ planetStatusData .neutralDefend = 0
1360+ planetStatusData .neutralDefendMax = 0
13601361 for i = 1 , # planets do
13611362 local planet = planets [i ]
13621363 if planet .AttackerFaction == myFaction then
13631364 planetStatusData .myAttackers = planetStatusData .myAttackers + planet .Count
13641365 elseif planet .OwnerFaction == myFaction then
13651366 planetStatusData .myIncoming = planetStatusData .myIncoming + planet .Count
13661367 elseif not planet .OwnerFaction then
1367- planetStatusData .neutralDefense = planetStatusData .neutralDefense + planet .Count
1368+ planetStatusData .neutralIncoming = planetStatusData .neutralIncoming + planet .Count
1369+ end
1370+ if planet .DefenderFaction == myFaction then
1371+ planetStatusData .myDefend = planetStatusData .myDefend + planet .Count
1372+ planetStatusData .myDefendMax = planetStatusData .myDefendMax + planet .Needed
1373+ elseif not planet .OwnerFaction then
1374+ planetStatusData .neutralDefend = planetStatusData .neutralDefend + planet .Count
1375+ planetStatusData .neutralDefendMax = planetStatusData .neutralDefendMax + planet .Needed
13681376 end
13691377 end
13701378 end
@@ -1378,13 +1386,13 @@ local function InitializeControls(window)
13781386 if charges == 0 then
13791387 statusText :SetText (" You are out of attack charges. Regain charges by defending or waiting for the recharge timer." )
13801388 else
1381- statusText :SetText (" Select a planet to attack, it will launch when the timer runs out if enough allies join you ." )
1389+ statusText :SetText (" Select a planet to attack, it will launch when the timer runs out if enough allies join." )
13821390 end
13831391 if planets then
13841392 UpdatePlanetStatusData (attackPhase , planets )
13851393 planetStatusText .attackers :SetText (" Fellow attackers: " .. planetStatusData .myAttackers )
13861394 planetStatusText .incoming :SetText (" To defend: " .. planetStatusData .myIncoming )
1387- planetStatusText .neutral :SetText (" Neutrals to defend: " .. planetStatusData .neutralDefense )
1395+ planetStatusText .neutral :SetText (" Neutrals to defend: " .. planetStatusData .neutralIncoming )
13881396 for i = 1 , # planetStatusNames do
13891397 planetStatusText [planetStatusNames [i ]]:SetVisibility (true )
13901398 end
@@ -1397,8 +1405,13 @@ local function InitializeControls(window)
13971405 statusText :SetText (" Join planets that need defenders. Participating in defense generates an attack charge charge." )
13981406 end
13991407
1400- for i = 1 , # planetStatusNames do
1401- planetStatusText [planetStatusNames [i ]]:SetVisibility (false )
1408+ if planets then
1409+ UpdatePlanetStatusData (attackPhase , planets )
1410+ planetStatusText .attackers :SetText (" Defenders: " .. planetStatusData .myDefend .. " / " .. planetStatusData .myDefendMax )
1411+ planetStatusText .incoming :SetText (" Neutral Defenders: " .. planetStatusData .neutralDefend .. " / " .. planetStatusData .neutralDefendMax )
1412+ planetStatusText .attackers :SetVisibility (true )
1413+ planetStatusText .incoming :SetVisibility (true )
1414+ planetStatusText .neutral :SetVisibility (false )
14021415 end
14031416 else
14041417 statusText :SetText (" Error fetching Planetwars state. Try logging out then in again." )
0 commit comments