Merge pull request #1942 from magefree/rating-system

Rating system
This commit is contained in:
LevelX2 2016-05-18 16:29:25 +02:00
commit d4d486458f
23 changed files with 935 additions and 61 deletions

View file

@ -431,7 +431,8 @@ public abstract class MatchImpl implements Match {
if (getDraws() > 0) {
sb.append(" Draws: ").append(getDraws()).append("<br/>");
}
sb.append("<br/>").append("You have to win ").append(this.getWinsNeeded()).append(this.getWinsNeeded() == 1 ? " game" : " games").append(" to win the complete match<br/>");
sb.append("<br/>").append("Match is ").append(this.getOptions().isRated() ? "" : "not ").append("rated<br/>");
sb.append("You have to win ").append(this.getWinsNeeded()).append(this.getWinsNeeded() == 1 ? " game" : " games").append(" to win the complete match<br/>");
sb.append("<br/>Game has started<br/><br/>");
return sb.toString();
}
@ -497,7 +498,9 @@ public abstract class MatchImpl implements Match {
.setGameType(this.getOptions().getGameType())
.setDeckType(this.getOptions().getDeckType())
.setGames(this.getNumGames())
.setDraws(this.getDraws());
.setDraws(this.getDraws())
.setMatchOptions(this.getOptions().toProto())
.setEndTimeMs((this.getEndTime() != null ? this.getEndTime() : new Date()).getTime());
for (MatchPlayer matchPlayer : this.getPlayers()) {
MatchQuitStatus status = !matchPlayer.hasQuit() ? MatchQuitStatus.NO_MATCH_QUIT :
matchPlayer.getPlayer().hasTimerTimeout() ? MatchQuitStatus.TIMER_TIMEOUT :
@ -505,6 +508,7 @@ public abstract class MatchImpl implements Match {
MatchQuitStatus.QUIT;
builder.addPlayersBuilder()
.setName(matchPlayer.getName())
.setHuman(matchPlayer.getPlayer().isHuman())
.setQuit(status)
.setWins(matchPlayer.getWins());
}

View file

@ -35,6 +35,7 @@ import mage.constants.MatchTimeLimit;
import mage.constants.MultiplayerAttackOption;
import mage.constants.RangeOfInfluence;
import mage.constants.SkillLevel;
import mage.game.result.ResultProtos;
/**
*
@ -55,6 +56,7 @@ public class MatchOptions implements Serializable {
protected SkillLevel skillLevel;
protected boolean rollbackTurnsAllowed;
protected int quitRatio;
protected boolean rated;
/**
* Time each player has during the game to play using his\her priority.
@ -177,4 +179,36 @@ public class MatchOptions implements Serializable {
public void setQuitRatio(int quitRatio) {
this.quitRatio = quitRatio;
}
public boolean isRated() {
return rated;
}
public void setRated(boolean rated) {
this.rated = rated;
}
public ResultProtos.MatchOptionsProto toProto() {
ResultProtos.MatchOptionsProto.Builder builder = ResultProtos.MatchOptionsProto.newBuilder()
.setName(this.getName())
.setLimited(this.isLimited())
.setRated(this.isRated())
.setWinsNeeded(this.getWinsNeeded());
ResultProtos.SkillLevel skillLevel = ResultProtos.SkillLevel.BEGINNER;
switch (this.getSkillLevel()) {
case BEGINNER:
skillLevel = ResultProtos.SkillLevel.BEGINNER;
break;
case CASUAL:
skillLevel = ResultProtos.SkillLevel.CASUAL;
break;
case SERIOUS:
skillLevel = ResultProtos.SkillLevel.SERIOUS;
break;
}
builder.setSkillLevel(skillLevel);
return builder.build();
}
}

View file

@ -584,7 +584,9 @@ public abstract class TournamentImpl implements Tournament {
.setGames(match.getNumGames())
.setDraws(match.getDraws())
.addPlayers(matchToProto(match, pair.getPlayer1()))
.addPlayers(matchToProto(match, pair.getPlayer2()));
.addPlayers(matchToProto(match, pair.getPlayer2()))
.setMatchOptions(match.getOptions().toProto())
.setEndTimeMs((match.getEndTime() != null ? match.getEndTime() : new Date()).getTime());
}
}
for (TournamentPlayer tp : round.getPlayerByes()) {
@ -602,6 +604,7 @@ public abstract class TournamentImpl implements Tournament {
MatchQuitStatus.QUIT;
return MatchPlayerProto.newBuilder()
.setName(player.getPlayer().getName())
.setHuman(player.getPlayer().isHuman())
.setWins(matchPlayer.getWins())
.setQuit(quit)
.build();

View file

@ -29,6 +29,10 @@ public class UserData implements Serializable {
protected String tourneyHistory;
protected int tourneyQuitRatio;
private int generalRating;
private int constructedRating;
private int limitedRating;
public UserData(UserGroup userGroup, int avatarId, boolean showAbilityPickerForced,
boolean allowRequestShowHandCards, boolean confirmEmptyManaPool, UserSkipPrioritySteps userSkipPrioritySteps,
String flagName, boolean askMoveToGraveOrder, boolean manaPoolAutomatic, boolean manaPoolAutomaticRestricted,
@ -68,6 +72,7 @@ public class UserData implements Serializable {
this.passPriorityActivation = userData.passPriorityActivation;
this.autoOrderTrigger = userData.autoOrderTrigger;
this.useFirstManaAbility = userData.useFirstManaAbility;
// todo: why we don't copy user stats here?
}
public static UserData getDefaultUserDataView() {
@ -190,7 +195,10 @@ public class UserData implements Serializable {
if (UserGroup.COMPUTER.equals(this.groupId)) {
return "";
}
return "Matches: " + this.matchHistory + " (" + this.matchQuitRatio + "%) Tourneys: " + this.tourneyHistory + " (" + this.tourneyQuitRatio + "%)";
// todo: add preference to hide rating?
return "Matches: " + this.matchHistory + " (" + this.matchQuitRatio + "%), Tourneys: " + this.tourneyHistory + " (" + this.tourneyQuitRatio + "%)"
+ ", Constructed Rating: " + getConstructedRating()
+ ", Limited Rating: " + getLimitedRating();
}
public void setMatchHistory(String history) {
@ -225,8 +233,31 @@ public class UserData implements Serializable {
return tourneyQuitRatio;
}
public int getGeneralRating() {
return generalRating;
}
public void setGeneralRating(int generalRating) {
this.generalRating = generalRating;
}
public int getConstructedRating() {
return constructedRating;
}
public void setConstructedRating(int constructedRating) {
this.constructedRating = constructedRating;
}
public int getLimitedRating() {
return limitedRating;
}
public void setLimitedRating(int limitedRating) {
this.limitedRating = limitedRating;
}
public static String getDefaultFlagName() {
return "world.png";
}
}