Skip to content

Commit 348e5bb

Browse files
committed
experimental nuke attacker, breaks merge of battles/defenses
1 parent cb3be6f commit 348e5bb

9 files changed

Lines changed: 533 additions & 341 deletions

File tree

Fixer/Program.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,6 @@ private static void TestPwMatchMaker()
431431
{
432432
var server = new global::ZkLobbyServer.ZkLobbyServer("", new PlanetwarsEventCreator());
433433
var mm = server.PlanetWarsMatchMaker;
434-
mm.AttackerSideCounter = 1;
435434
mm.GenerateLobbyCommand();
436435

437436
// simulate defend phase with a formed squad

Shared/LobbyClient/Protocol/Messages.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,32 +705,60 @@ public class VoteOption
705705
public bool CanSelectForBattle { get; set; }
706706
public bool PlayerIsAttacker { get; set; }
707707
public bool PlayerIsDefender { get; set; }
708+
/// <summary>
709+
/// Faction shortcut of the attacker. Together with <see cref="PlanetID"/> forms the (planet, attacker)
710+
/// key that identifies this attack slot. Clients must echo it back in <see cref="PwJoinPlanet"/>.
711+
/// </summary>
712+
public string AttackerFaction { get; set; }
713+
/// <summary>Average PW-WHR of the projected attacker squad (top-TeamSize volunteers). 0 when none.</summary>
714+
public int AttackerAvgWhr { get; set; }
715+
/// <summary>Average PW-WHR of the projected defender squad. Null in AttackCollect phase or when no volunteers.</summary>
716+
public int? DefenderAvgWhr { get; set; }
717+
/// <summary>Attacker win chance 0-100 derived from WHR delta. Null when either side is empty.</summary>
718+
public int? WinChance { get; set; }
708719
}
709720
}
710721

711722
[Message(Origin.Client)]
712723
public class PwJoinPlanet
713724
{
714725
public int PlanetID { get; set; }
726+
/// <summary>
727+
/// Which attack slot the player is interacting with. Required — a planet can be attacked by multiple
728+
/// factions simultaneously, each a separate slot. For an attacker this should equal the user's own
729+
/// faction; for a defender it identifies which incoming attack to defend against.
730+
/// </summary>
731+
public string AttackerFaction { get; set; }
732+
}
733+
734+
/// <summary>
735+
/// Client → server: cancel the player's current attack or defense commitment for the cycle.
736+
/// </summary>
737+
[Message(Origin.Client)]
738+
public class PwCancel
739+
{
715740
}
716741

717742
[Message(Origin.Server)]
718743
public class PwRequestJoinPlanet
719744
{
720745
public int PlanetID { get; set; }
746+
public string AttackerFaction { get; set; }
721747
}
722748

723749

724750
[Message(Origin.Server)]
725751
public class PwJoinPlanetSuccess
726752
{
727753
public int PlanetID { get; set; }
754+
public string AttackerFaction { get; set; }
728755
}
729756

730757
[Message(Origin.Server)]
731758
public class PwAttackingPlanet
732759
{
733760
public int PlanetID { get; set; }
761+
public string AttackerFaction { get; set; }
734762
}
735763

736764
[Message(Origin.Client)]

Zero-K.info/Controllers/PlanetwarsController.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -797,10 +797,11 @@ public ActionResult MatchMakerAttack(int planetID)
797797
{
798798
var db = new ZkDataContext();
799799
var planet = db.Planets.Single(x => x.PlanetID == planetID);
800-
if (Global.IsAccountAuthorized && Global.Account.CanPlayerPlanetWars() && planet.CanMatchMakerPlay(db.CurrentAccount().Faction))
800+
var account = db.CurrentAccount();
801+
if (Global.IsAccountAuthorized && Global.Account.CanPlayerPlanetWars() && account?.FactionID != null && planet.CanMatchMakerPlay(account.Faction))
801802
{
802-
Global.Server.PlanetWarsMatchMaker.AddAttackOption(planet);
803-
Global.Server.RequestJoinPlanet(Global.Account.Name, planet.PlanetID);
803+
Global.Server.PlanetWarsMatchMaker.AddAttackOption(planet, account.FactionID.Value);
804+
Global.Server.RequestJoinPlanet(Global.Account.Name, planet.PlanetID, account.Faction.Shortcut);
804805
}
805806
return RedirectToAction("Planet", new { id = planetID });
806807
}
@@ -812,16 +813,17 @@ public ActionResult MatchMaker()
812813
var pwm = Global.Server.PlanetWarsMatchMaker;
813814
if (pwm != null)
814815
{
815-
var state = Global.Server.PlanetWarsMatchMaker.GenerateLobbyCommand();
816+
// admin view gets a per-viewer command so per-option flags render correctly
817+
var state = Global.Server.PlanetWarsMatchMaker.GenerateLobbyCommand(Global.Account?.Name, Global.Account?.Faction?.Shortcut);
816818
if (state != null) return View("PwMatchMaker", state);
817819
}
818820
return Content("Match maker offline");
819821
}
820822

821823
[Auth]
822-
public ActionResult MatchMakerJoin(int planetID)
824+
public ActionResult MatchMakerJoin(int planetID, string attackerFaction)
823825
{
824-
Global.Server.RequestJoinPlanet(Global.Account.Name, planetID);
826+
Global.Server.RequestJoinPlanet(Global.Account.Name, planetID, attackerFaction);
825827
return MatchMaker();
826828
}
827829

Zero-K.info/Views/Planetwars/Planet.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
</tr>
3939
</table>
4040

41-
@if (Global.IsAccountAuthorized && db.CurrentAccount().CanPlayerPlanetWars() && (Global.Server.PlanetWarsMatchMaker != null && Global.Server?.PlanetWarsMatchMaker?.AttackingFaction?.FactionID == Global.FactionID) && Model.CanMatchMakerPlay(db.CurrentAccount().Faction))
41+
@if (Global.IsAccountAuthorized && db.CurrentAccount().CanPlayerPlanetWars() && Global.Server.PlanetWarsMatchMaker != null && Global.Server.PlanetWarsMatchMaker.Phase == ZeroKWeb.PwPhase.AttackCollect && Model.OwnerFactionID != Global.FactionID && Model.CanMatchMakerPlay(db.CurrentAccount().Faction))
4242
{
4343
<a href="@Url.Action("MatchMakerAttack", "Planetwars", new { planetID = Model.PlanetID })">ATTACK PLANET</a>
4444
}
Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
1-
@using LobbyClient
1+
@using LobbyClient
22
@using PlasmaShared
33
@using ZeroKWeb
44
@using ZkData
55
@model LobbyClient.PwMatchCommand
66
@{
77
PwMatchCommand pw = Model;
8-
string text = "";
8+
string text;
99
var db = new ZkDataContext();
1010
if (pw.Mode == PwMatchCommand.ModeType.Attack)
1111
{
12-
text = string.Format("{0} picks a planet to attack", pw.AttackerFaction);
12+
text = "Pick a planet to attack";
1313
}
1414
else
1515
{
16-
var planetNames = string.Join(", ", pw.Options.Select(o => o.PlanetName));
17-
text = string.Format("{0} attacks {2}, {1} defends", pw.AttackerFaction, string.Join(",", pw.DefenderFactions), planetNames);
16+
var planetNames = string.Join(", ", pw.Options.Select(o => o.PlanetName + " (" + (o.AttackerFaction ?? "?") + ")"));
17+
text = string.Format("Defend options: {0}", planetNames);
1818
}
19-
20-
bool canClick = (pw.Mode == PwMatchCommand.ModeType.Attack && pw.AttackerFaction == Global.Account.Faction.Shortcut) || (pw.Mode == PwMatchCommand.ModeType.Defend && pw.DefenderFactions.Contains(Global.Account.Faction.Shortcut));
2119
}
2220

2321
<div id="matchMaker">
@@ -30,14 +28,23 @@
3028
foreach (PwMatchCommand.VoteOption opt in pw.Options)
3129
{
3230
<span style="border: 1px solid cyan;">
33-
@if (canClick)
31+
@if (opt.CanSelectForBattle)
3432
{
35-
@Ajax.ActionLink("Join", "MatchMakerJoin", new { planetID = opt.PlanetID }, new AjaxOptions { UpdateTargetId = "matchMaker", InsertionMode = InsertionMode.Replace })
33+
@Ajax.ActionLink("Join", "MatchMakerJoin", new { planetID = opt.PlanetID, attackerFaction = opt.AttackerFaction }, new AjaxOptions { UpdateTargetId = "matchMaker", InsertionMode = InsertionMode.Replace })
3634
}
3735
@Html.PrintPlanet(db.Planets.First(x => x.PlanetID == opt.PlanetID))
36+
<span>[@opt.AttackerFaction]</span>
3837
<span>[@opt.Count/@opt.Needed]</span>
38+
@if (opt.WinChance != null)
39+
{
40+
<span>(WHR A:@opt.AttackerAvgWhr D:@opt.DefenderAvgWhr, @opt.WinChance% attacker)</span>
41+
}
42+
else if (opt.AttackerAvgWhr > 0)
43+
{
44+
<span>(WHR @opt.AttackerAvgWhr)</span>
45+
}
3946
</span>
4047
<text>&nbsp; &nbsp;&nbsp;</text>
4148
}
4249
}
43-
</div>
50+
</div>

ZkLobbyServer/ConnectedUser.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ public async Task Process(PwJoinPlanet args)
112112
await server.PlanetWarsMatchMaker.OnJoinPlanet(this, args);
113113
}
114114

115+
public async Task Process(PwCancel args)
116+
{
117+
await server.PlanetWarsMatchMaker.OnCancel(this);
118+
}
119+
115120

116121
public async Task Process(KickFromBattle batKick)
117122
{

0 commit comments

Comments
 (0)