Skip to content

Commit 306fc33

Browse files
committed
change logic to be best on last charges change instead of last attack
1 parent 3e08280 commit 306fc33

10 files changed

Lines changed: 155 additions & 153 deletions

Zero-K.info/Controllers/PlanetwarsAdminController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ public ActionResult StartGalaxy(int galaxyID)
370370
db.Accounts.Where(x => x.FactionID != null).Update(x => new Account()
371371
{
372372
PwAttackCharges = maxCharges,
373-
PwLastAttackTurn = null,
373+
PwLastChargeChangeTurn = null,
374374
});
375375
}
376376

ZkData/Ef/Account.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public static double AdjustEloWeight(double currentWeight, double sumWeight, int
154154
public double PwWarpUsed { get; set; }
155155
public double PwAttackPoints { get; set; }
156156
public int PwAttackCharges { get; set; }
157-
public int? PwLastAttackTurn { get; set; }
157+
public int? PwLastChargeChangeTurn { get; set; }
158158
public bool HasVpnException { get; set; }
159159
public bool HasKudos { get; set; }
160160
public int ForumTotalUpvotes { get; set; }
@@ -535,13 +535,15 @@ public void ResetQuotas()
535535
public void SpendPwAttackCharge(int currentTurn)
536536
{
537537
if (PwAttackCharges > 0) PwAttackCharges--;
538-
PwLastAttackTurn = currentTurn;
538+
PwLastChargeChangeTurn = currentTurn;
539539
}
540540

541-
public void GrantPwAttackCharge(int maxCharges)
541+
public void GrantPwAttackCharge(int maxCharges, int currentTurn)
542542
{
543543
if (maxCharges <= 0) return;
544-
if (PwAttackCharges < maxCharges) PwAttackCharges++;
544+
if (PwAttackCharges >= maxCharges) return;
545+
PwAttackCharges++;
546+
PwLastChargeChangeTurn = currentTurn;
545547
}
546548

547549

ZkData/Ef/DynamicConfig.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ public class DynamicConfig
4646
[Description("PlanetWars: maximum attack charges a player can hold. 0 disables the charge system.")]
4747
public int PwAttackChargesMax { get; set; } = 2;
4848

49-
[Description("PlanetWars: turns of cooldown after an attack before the player starts regaining charges (1 per subsequent turn, up to max).")]
50-
public int PwAttackChargesCooldownTurns { get; set; } = 3;
49+
[Description("PlanetWars: turns a player must be idle (no spend/gain) before their next +1 passive charge, up to max. Every charge gain or loss resets this clock, so the average regen rate is at most 1 charge per this many turns.")]
50+
public int PwAttackChargesCooldownTurns { get; set; } = 4;
5151

5252
[Description("PlanetWars: fraction of enemy bomber IP damage also applied to the bomber's own faction. 0 disables self-damage.")]
5353
public double PwBomberSelfIpRate { get; set; } = 0.5;

ZkData/Migrations/202604232250090_AddPwAttackCharges.resx

Lines changed: 0 additions & 126 deletions
This file was deleted.

ZkData/Migrations/202604232250090_AddPwAttackCharges.Designer.cs renamed to ZkData/Migrations/202604241242120_AddPwAttackCharges.Designer.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ZkData/Migrations/202604232250090_AddPwAttackCharges.cs renamed to ZkData/Migrations/202604241242120_AddPwAttackCharges.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ public partial class AddPwAttackCharges : DbMigration
88
public override void Up()
99
{
1010
AddColumn("dbo.Accounts", "PwAttackCharges", c => c.Int(nullable: false, defaultValue: 2));
11-
AddColumn("dbo.Accounts", "PwLastAttackTurn", c => c.Int());
12-
AddColumn("dbo.DynamicConfigs", "PwAttackChargesCooldownTurns", c => c.Int(nullable: false, defaultValue: 3));
11+
AddColumn("dbo.Accounts", "PwLastChargeChangeTurn", c => c.Int());
12+
AddColumn("dbo.DynamicConfigs", "PwAttackChargesCooldownTurns", c => c.Int(nullable: false, defaultValue: 4));
1313
DropColumn("dbo.DynamicConfigs", "PwAttackChargesRechargeMinutes");
1414
}
1515

1616
public override void Down()
1717
{
1818
AddColumn("dbo.DynamicConfigs", "PwAttackChargesRechargeMinutes", c => c.Int(nullable: false, defaultValue: 60));
1919
DropColumn("dbo.DynamicConfigs", "PwAttackChargesCooldownTurns");
20-
DropColumn("dbo.Accounts", "PwLastAttackTurn");
20+
DropColumn("dbo.Accounts", "PwLastChargeChangeTurn");
2121
DropColumn("dbo.Accounts", "PwAttackCharges");
2222
}
2323
}

ZkData/Migrations/202604241242120_AddPwAttackCharges.resx

Lines changed: 126 additions & 0 deletions
Large diffs are not rendered by default.

ZkData/ZkData.csproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -507,9 +507,9 @@
507507
<Compile Include="Migrations\202604231826040_AddPwBomberNerfConfigs.Designer.cs">
508508
<DependentUpon>202604231826040_AddPwBomberNerfConfigs.cs</DependentUpon>
509509
</Compile>
510-
<Compile Include="Migrations\202604232250090_AddPwAttackCharges.cs" />
511-
<Compile Include="Migrations\202604232250090_AddPwAttackCharges.Designer.cs">
512-
<DependentUpon>202604232250090_AddPwAttackCharges.cs</DependentUpon>
510+
<Compile Include="Migrations\202604241242120_AddPwAttackCharges.cs" />
511+
<Compile Include="Migrations\202604241242120_AddPwAttackCharges.Designer.cs">
512+
<DependentUpon>202604241242120_AddPwAttackCharges.cs</DependentUpon>
513513
</Compile>
514514
<Compile Include="SpringFilesUnitsyncAttempt.cs" />
515515
<Compile Include="SteamWebApi.cs" />
@@ -971,8 +971,8 @@
971971
<EmbeddedResource Include="Migrations\202604231826040_AddPwBomberNerfConfigs.resx">
972972
<DependentUpon>202604231826040_AddPwBomberNerfConfigs.cs</DependentUpon>
973973
</EmbeddedResource>
974-
<EmbeddedResource Include="Migrations\202604232250090_AddPwAttackCharges.resx">
975-
<DependentUpon>202604232250090_AddPwAttackCharges.cs</DependentUpon>
974+
<EmbeddedResource Include="Migrations\202604241242120_AddPwAttackCharges.resx">
975+
<DependentUpon>202604241242120_AddPwAttackCharges.cs</DependentUpon>
976976
</EmbeddedResource>
977977
<EmbeddedResource Include="ZkDataResources.resx">
978978
<Generator>ResXFileCodeGenerator</Generator>

ZkLobbyServer/SpringieInterface/PlanetWarsMatchMaker.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -986,8 +986,8 @@ public static PwAttackCharges BuildPwAttackCharges(Account account)
986986
{
987987
var max = DynamicConfig.Instance.PwAttackChargesMax;
988988
int? nextRechargeTurn = null;
989-
if (max > 0 && account.PwAttackCharges < max && account.PwLastAttackTurn != null)
990-
nextRechargeTurn = account.PwLastAttackTurn.Value + DynamicConfig.Instance.PwAttackChargesCooldownTurns;
989+
if (max > 0 && account.PwAttackCharges < max && account.PwLastChargeChangeTurn != null)
990+
nextRechargeTurn = account.PwLastChargeChangeTurn.Value + DynamicConfig.Instance.PwAttackChargesCooldownTurns;
991991
return new PwAttackCharges
992992
{
993993
Current = account.PwAttackCharges,
@@ -1026,18 +1026,18 @@ private async Task ApplyTurnEndChargeBump()
10261026
using (var db = new ZkDataContext())
10271027
{
10281028
var turn = db.Galaxies.First(g => g.IsDefault).Turn;
1029-
var query = db.Accounts.Where(a =>
1029+
bumped = db.Accounts.Where(a =>
10301030
a.FactionID != null &&
10311031
a.PwAttackCharges < max &&
1032-
(a.PwLastAttackTurn == null || turn - a.PwLastAttackTurn >= cooldown));
1032+
(a.PwLastChargeChangeTurn == null || turn - a.PwLastChargeChangeTurn >= cooldown)).ToList();
10331033

1034-
bumped = query.Select(a => new { a.Name, a.PwAttackCharges, a.PwLastAttackTurn })
1035-
.AsEnumerable()
1036-
.Select(x => new Account { Name = x.Name, PwAttackCharges = x.PwAttackCharges + 1, PwLastAttackTurn = x.PwLastAttackTurn })
1037-
.ToList();
1034+
foreach (var acc in bumped)
1035+
{
1036+
acc.PwAttackCharges++;
1037+
acc.PwLastChargeChangeTurn = turn;
1038+
}
10381039

1039-
if (bumped.Count > 0)
1040-
query.Update(a => new Account { PwAttackCharges = a.PwAttackCharges + 1 });
1040+
if (bumped.Count > 0) db.SaveChanges();
10411041
}
10421042

10431043
await Task.WhenAll(bumped.Select(a => SendPwAttackCharges(server, a.Name, a)));

ZkLobbyServer/SpringieInterface/PlanetWarsTurnHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public static void ProcessBattleResult(string mapName, List<string> extraData, Z
180180
{
181181
foreach (Account w in defenders)
182182
{
183-
w.GrantPwAttackCharge(maxCharges);
183+
w.GrantPwAttackCharge(maxCharges, gal.Turn);
184184
_ = ZeroKWeb.PlanetWarsMatchMaker.SendPwAttackCharges(server, w.Name, w);
185185
}
186186
}

0 commit comments

Comments
 (0)