-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement time penalties for switching
Signed-off-by: Pablo Herrera <[email protected]>
- Loading branch information
1 parent
852bf3d
commit 4ae0486
Showing
12 changed files
with
170 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
core/src/main/java/tc/oc/pgm/spawns/ParticipationData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package tc.oc.pgm.spawns; | ||
|
||
import java.time.Duration; | ||
import tc.oc.pgm.api.Config.TimePenalty; | ||
import tc.oc.pgm.api.PGM; | ||
import tc.oc.pgm.api.match.Match; | ||
import tc.oc.pgm.api.party.Competitor; | ||
import tc.oc.pgm.teams.Team; | ||
import tc.oc.pgm.util.TimeUtils; | ||
|
||
class ParticipationData { | ||
private Team lastTeam; | ||
private long lastLeaveTick; | ||
private boolean wasFull; | ||
private boolean wasStacked; | ||
private int rejoins; | ||
|
||
public void trackLeave(Match match, Competitor competitor) { | ||
if (competitor instanceof Team team) { | ||
if (lastTeam == team) rejoins++; | ||
lastTeam = team; | ||
wasFull = team.getSize() >= team.getMaxPlayers() - 1; | ||
wasStacked = team.isStacked(); | ||
} else { | ||
lastTeam = null; | ||
wasFull = match.getParticipants().size() >= match.getMaxPlayers(); | ||
wasStacked = false; | ||
} | ||
lastLeaveTick = match.getTick().tick; | ||
} | ||
|
||
public long getJoinTick(Team newTeam) { | ||
TimePenalty penalty = getPenalty(newTeam); | ||
Duration timeOff = getDuration(penalty); | ||
if (penalty == TimePenalty.REJOIN_MULTIPLIER) { | ||
timeOff = TimeUtils.min(timeOff.multipliedBy(rejoins), getDuration(TimePenalty.REJOIN_MAX)); | ||
} | ||
return lastLeaveTick + TimeUtils.toTicks(timeOff); | ||
} | ||
|
||
static Duration getDuration(TimePenalty penalty) { | ||
return penalty == null ? Duration.ZERO : PGM.get().getConfiguration().getTimePenalty(penalty); | ||
} | ||
|
||
private TimePenalty getPenalty(Team newTeam) { | ||
if (lastTeam == null || newTeam == null) { // FFA | ||
return wasFull ? TimePenalty.FFA_FULL_REJOIN : null; | ||
} | ||
// Left and rejoined to get the team stacked | ||
if (newTeam.isStacked()) return TimePenalty.STACKED; | ||
|
||
if (lastTeam == newTeam) { // Team rejoin | ||
// Making space for someone else to join | ||
if (wasFull && newTeam.getSize() >= newTeam.getMaxPlayers()) return TimePenalty.FULL_REJOIN; | ||
// Rejoin spam for resources | ||
return TimePenalty.REJOIN_MULTIPLIER; | ||
} else { | ||
// Explicitly forgive switching to un-stack | ||
if (wasStacked && !newTeam.isStacked()) return null; | ||
|
||
return TimePenalty.STACKED; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters