-
Notifications
You must be signed in to change notification settings - Fork 3
modify: change map cooldown behaviour #221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -264,12 +264,13 @@ private void OnClientPutInServer(int slot) | |
| private void OnMapStart(string mapName) | ||
| { | ||
| ExtendCount = 0; | ||
|
|
||
| DecrementAllMapCooldown(CurrentMap); | ||
|
|
||
| CurrentMap = NextMap; | ||
| NextMap = null; | ||
|
|
||
| DecrementAllMapCooldown(CurrentMap); | ||
| ApplyCooldownToCurrentMap(CurrentMap); | ||
|
|
||
| Server.NextFrame(ExecuteMapLimitConfig); | ||
|
|
||
| // Wait for first people joined | ||
|
|
@@ -323,22 +324,24 @@ private void DecrementAllMapCooldown(IMapConfig? previousMap) | |
| if (value.MapCooldown.CurrentCooldown > 0) | ||
| value.MapCooldown.CurrentCooldown--; | ||
| } | ||
|
|
||
| // Set previous map cooldown if defined in config | ||
| if (previousMap != null) | ||
| { | ||
| _mcsDatabaseProvider.MapInfoRepository.UpsertMapCooldownAsync(previousMap.MapName, previousMap.MapCooldown.MapConfigCooldown).ConfigureAwait(false); | ||
| previousMap.MapCooldown.CurrentCooldown = previousMap.MapCooldown.MapConfigCooldown; | ||
| } | ||
|
|
||
| private void ApplyCooldownToCurrentMap(IMapConfig? currentMap) | ||
| { | ||
| if (currentMap == null) | ||
| return; | ||
|
|
||
| foreach (IMapGroupSettings setting in previousMap.GroupSettings) | ||
| { | ||
| _mcsDatabaseProvider.GroupInfoRepository.UpsertGroupCooldownAsync(setting.GroupName, setting.GroupCooldown.MapConfigCooldown).ConfigureAwait(false); | ||
| setting.GroupCooldown.CurrentCooldown = setting.GroupCooldown.MapConfigCooldown; | ||
| } | ||
| _mcsDatabaseProvider.MapInfoRepository.UpsertMapCooldownAsync(currentMap.MapName, currentMap.MapCooldown.MapConfigCooldown).ConfigureAwait(false); | ||
| currentMap.MapCooldown.CurrentCooldown = currentMap.MapCooldown.MapConfigCooldown; | ||
|
|
||
| foreach (IMapGroupSettings setting in currentMap.GroupSettings) | ||
| { | ||
| _mcsDatabaseProvider.GroupInfoRepository.UpsertGroupCooldownAsync(setting.GroupName, setting.GroupCooldown.MapConfigCooldown).ConfigureAwait(false); | ||
| setting.GroupCooldown.CurrentCooldown = setting.GroupCooldown.MapConfigCooldown; | ||
| } | ||
| } | ||
|
||
|
|
||
|
|
||
|
|
||
| private HookResult OnRoundEnd(EventRoundEnd @event, GameEventInfo info) | ||
| { | ||
| if (!_isMapStarted) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a logical error in the reordered operations. The cooldown is now being applied to the map that is starting (
NextMap), not the map that just finished (the oldCurrentMap).With this change,
CurrentMapis updated toNextMapbefore the cooldown logic is executed. This meansApplyCooldownToCurrentMapis called with the new map, putting it on cooldown immediately, while the map that just ended doesn't get its cooldown applied.To fix this, the cooldown logic should be executed before
CurrentMapis updated. Note thatApplyCooldownToCurrentMapshould be made asynchronous as suggested in a separate comment, so you will need toawaitit and markOnMapStartasasync void.