Skip to content
This repository has been archived by the owner on Oct 21, 2023. It is now read-only.

Commit

Permalink
mod: detach upkeep duration from reward duration (#1217)
Browse files Browse the repository at this point in the history
  • Loading branch information
Muparadzi committed Aug 7, 2023
1 parent 8a06b58 commit b7bbbfe
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/Module.Server/Modes/Dtv/CrpgDtvServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ internal class CrpgDtvServer : MissionMultiplayerGameModeBase
private bool _waveStarted;
private MissionTimer? _waveStartTimer;
private MissionTimer? _endGameTimer;
private MissionTime _currentRoundStartTime;

public CrpgDtvServer(CrpgRewardServer rewardServer)
{
Expand Down Expand Up @@ -173,6 +174,7 @@ private void StartNextRound()
_currentWave = -1;
SpawningBehavior.RequestSpawnSessionForRoundStart(firstRound: _currentRound == 0);
SendDataToPeers(new CrpgDtvRoundStartMessage { Round = _currentRound });
_currentRoundStartTime = MissionTime.Now;
_waveStartTimer = new MissionTimer(15f);
_waveStarted = false;
}
Expand All @@ -191,11 +193,13 @@ private void CheckForWaveEnd()
{
bool viscountDead = !Mission.DefenderTeam.HasBots;
bool defendersDepleted = Mission.DefenderTeam.ActiveAgents.Count == (viscountDead ? 0 : 1);
float roundDuration = _currentRoundStartTime.ElapsedSeconds;
if (viscountDead || defendersDepleted)
{
SendDataToPeers(new CrpgDtvGameEnd { ViscountDead = viscountDead });
_ = _rewardServer.UpdateCrpgUsersAsync(
durationRewarded: ComputeRoundReward(CurrentRoundData, wavesWon: _currentWave),
durationUpkeep: roundDuration,
updateUserStats: false,
constantMultiplier: RewardMultiplier);
EndGame(Mission.AttackerTeam);
Expand All @@ -216,6 +220,7 @@ private void CheckForWaveEnd()

_ = _rewardServer.UpdateCrpgUsersAsync(
durationRewarded: ComputeRoundReward(CurrentRoundData, wavesWon: _currentWave + 1),
durationUpkeep: roundDuration,
updateUserStats: false,
constantMultiplier: RewardMultiplier);

Expand Down
8 changes: 5 additions & 3 deletions src/Module.Server/Rewards/CrpgRewardServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,15 @@ public override void OnScoreHit(
/// Update rating and statistics from the last time this method was called and also give rewards.
/// </summary>
/// <param name="durationRewarded">Duration for which the users should be rewarded.</param>
/// <param name="durationUpkeep">Duration for which the users will pay for their equipment.</param>
/// <param name="defenderMultiplierGain">Multiplier to add to the defenders. Can be negative.</param>
/// <param name="attackerMultiplierGain">Multiplier to add to the attackers. Can be negative.</param>
/// <param name="valourTeamSide">Team to give valour to.</param>
/// <param name="constantMultiplier">Multiplier that should be given to everyone disregarding any other parameters.</param>
/// <param name="updateUserStats">True if score and rating should be saved.</param>
public async Task UpdateCrpgUsersAsync(
float durationRewarded,
float? durationUpkeep = null,
int defenderMultiplierGain = 0,
int attackerMultiplierGain = 0,
BattleSideEnum? valourTeamSide = null,
Expand Down Expand Up @@ -157,7 +159,7 @@ public async Task UpdateCrpgUsersAsync(

Dictionary<int, CrpgPeer> crpgPeerByCrpgUserId = new();
List<CrpgUserUpdate> userUpdates = new();
Dictionary<int, IList<CrpgUserDamagedItem>> brokenItems = lowPopulationServer ? new() : GetBrokenItemsByCrpgUserId(networkPeers, durationRewarded);
Dictionary<int, IList<CrpgUserDamagedItem>> brokenItems = lowPopulationServer ? new() : GetBrokenItemsByCrpgUserId(networkPeers, durationUpkeep ?? durationRewarded);

var compensationByCrpgUserId = _isTeamHitCompensationsEnabled ? CalculateCompensationByCrpgUserId(brokenItems) : new();
foreach (NetworkCommunicator networkPeer in networkPeers)
Expand Down Expand Up @@ -245,7 +247,7 @@ public async Task UpdateCrpgUsersAsync(
}
}

private Dictionary<int, IList<CrpgUserDamagedItem>> GetBrokenItemsByCrpgUserId(NetworkCommunicator[] networkPeers, float durationRewarded)
private Dictionary<int, IList<CrpgUserDamagedItem>> GetBrokenItemsByCrpgUserId(NetworkCommunicator[] networkPeers, float duration)
{
Dictionary<int, IList<CrpgUserDamagedItem>> brokenItems = new();
foreach (NetworkCommunicator networkPeer in networkPeers)
Expand All @@ -260,7 +262,7 @@ private Dictionary<int, IList<CrpgUserDamagedItem>> GetBrokenItemsByCrpgUserId(N
if (crpgPeer.LastSpawnInfo != null)
{
int crpgUserId = crpgPeer.User.Id;
var crpgUserDamagedItems = BreakItems(crpgPeer, durationRewarded);
var crpgUserDamagedItems = BreakItems(crpgPeer, duration);
brokenItems[crpgUserId] = crpgUserDamagedItems;
}
}
Expand Down

0 comments on commit b7bbbfe

Please sign in to comment.