Skip to content

Commit 4698591

Browse files
authored
remove attacker faction from pw, add cancel
Removing faction attacker concept from planetwars
2 parents 958ed30 + 32b02dd commit 4698591

10 files changed

Lines changed: 573 additions & 296 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: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,11 @@ public enum ModeType
674674
Defend = 2
675675
}
676676

677-
public string AttackerFaction { get; set; }
677+
/// <summary>
678+
/// Distinct attacker faction shortcuts across all <see cref="Options"/>. In parallel-turn PW every
679+
/// faction can be attacking simultaneously; each option also carries its own <see cref="VoteOption.AttackerFaction"/>.
680+
/// </summary>
681+
public List<string> AttackerFactions { get; set; }
678682

679683
public DateTime Deadline { get; set; }
680684

@@ -690,6 +694,7 @@ public PwMatchCommand(ModeType mode)
690694
Mode = mode;
691695
Options = new List<VoteOption>();
692696
DefenderFactions = new List<string>();
697+
AttackerFactions = new List<string>();
693698
}
694699

695700
public class VoteOption
@@ -705,32 +710,60 @@ public class VoteOption
705710
public bool CanSelectForBattle { get; set; }
706711
public bool PlayerIsAttacker { get; set; }
707712
public bool PlayerIsDefender { get; set; }
713+
/// <summary>
714+
/// Faction shortcut of the attacker. Together with <see cref="PlanetID"/> forms the (planet, attacker)
715+
/// key that identifies this attack slot. Clients must echo it back in <see cref="PwJoinPlanet"/>.
716+
/// </summary>
717+
public string AttackerFaction { get; set; }
718+
/// <summary>Average PW-WHR of the projected attacker squad (top-TeamSize volunteers). 0 when none.</summary>
719+
public int AttackerAvgWhr { get; set; }
720+
/// <summary>Average PW-WHR of the projected defender squad. Null in AttackCollect phase or when no volunteers.</summary>
721+
public int? DefenderAvgWhr { get; set; }
722+
/// <summary>Attacker win chance 0-100 derived from WHR delta. Null when either side is empty.</summary>
723+
public int? WinChance { get; set; }
708724
}
709725
}
710726

711727
[Message(Origin.Client)]
712728
public class PwJoinPlanet
713729
{
714730
public int PlanetID { get; set; }
731+
/// <summary>
732+
/// Which attack slot the player is interacting with. Required — a planet can be attacked by multiple
733+
/// factions simultaneously, each a separate slot. For an attacker this should equal the user's own
734+
/// faction; for a defender it identifies which incoming attack to defend against.
735+
/// </summary>
736+
public string AttackerFaction { get; set; }
737+
}
738+
739+
/// <summary>
740+
/// Client → server: cancel the player's current attack or defense commitment for the cycle.
741+
/// </summary>
742+
[Message(Origin.Client)]
743+
public class PwCancel
744+
{
715745
}
716746

717747
[Message(Origin.Server)]
718748
public class PwRequestJoinPlanet
719749
{
720750
public int PlanetID { get; set; }
751+
public string AttackerFaction { get; set; }
721752
}
722753

723754

724755
[Message(Origin.Server)]
725756
public class PwJoinPlanetSuccess
726757
{
727758
public int PlanetID { get; set; }
759+
public string AttackerFaction { get; set; }
728760
}
729761

730762
[Message(Origin.Server)]
731763
public class PwAttackingPlanet
732764
{
733765
public int PlanetID { get; set; }
766+
public string AttackerFaction { get; set; }
734767
}
735768

736769
[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>

ZeroKLobby/Notifications/PwBar.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Linq;
34
using System.Windows.Forms;
45
using LobbyClient;
@@ -59,9 +60,11 @@ void UpdateGui()
5960
deadline = DateTime.Now.AddSeconds(pw.DeadlineSeconds);
6061
timerLabel.Text = PlasmaShared.Utils.PrintTimeRemaining(pw.DeadlineSeconds);
6162

63+
var attackerFactionsText = string.Join(",", pw.AttackerFactions ?? new List<string>());
64+
6265
if (pw.Mode == PwMatchCommand.ModeType.Attack)
6366
{
64-
headerLabel.Text = string.Format("{0} picks a planet to attack", pw.AttackerFaction);
67+
headerLabel.Text = string.Format("{0} picks a planet to attack", attackerFactionsText);
6568

6669
foreach (Button c in pnl.Controls.OfType<Button>().ToList()) pnl.Controls.Remove(c);
6770

@@ -72,7 +75,7 @@ void UpdateGui()
7275
var but = new Button { Text = string.Format("{0} [{1}/{2}]", opt.PlanetName, opt.Count, opt.Needed), AutoSize = true };
7376
Program.ToolTip.SetMap(but, opt.Map);
7477

75-
if (pw.AttackerFaction == tas.MyUser.Faction) // NOTE this is for cases where nightwatch self faction info is delayed
78+
if (pw.AttackerFactions != null && pw.AttackerFactions.Contains(tas.MyUser.Faction))
7679
{
7780
AddButtonClick(opt, but);
7881
}
@@ -83,7 +86,7 @@ void UpdateGui()
8386
else if (pw.Mode == PwMatchCommand.ModeType.Defend)
8487
{
8588
headerLabel.Text = string.Format("{0} attacks, {1} defends",
86-
pw.AttackerFaction,
89+
attackerFactionsText,
8790
string.Join(",", pw.DefenderFactions));
8891

8992
foreach (Button c in pnl.Controls.OfType<Button>().ToList()) pnl.Controls.Remove(c);

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)