Skip to content

Commit

Permalink
Generating achievement and test
Browse files Browse the repository at this point in the history
  • Loading branch information
softwaremagico committed Apr 25, 2024
1 parent 085ae78 commit f6b3818
Show file tree
Hide file tree
Showing 7 changed files with 518 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[![GitHub commit activity](https://img.shields.io/github/commit-activity/y/softwaremagico/KendoTournamentManager)](https://github.com/softwaremagico/KendoTournamentManager)
[![GitHub last commit](https://img.shields.io/github/last-commit/softwaremagico/KendoTournamentManager)](https://github.com/softwaremagico/KendoTournamentManager)
[![CircleCI](https://circleci.com/gh/softwaremagico/KendoTournamentManager.svg?style=shield)](https://circleci.com/gh/softwaremagico/KendoTournamentManager)
[![Time](https://img.shields.io/badge/development-597.5h-blueviolet.svg)]()
[![Time](https://img.shields.io/badge/development-599h-blueviolet.svg)]()

[![Powered by](https://img.shields.io/badge/powered%20by%20java-orange.svg?logo=OpenJDK&logoColor=white)]()
[![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=kendo-tournament-backend&metric=vulnerabilities)](https://sonarcloud.io/summary/new_code?id=kendo-tournament-backend)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ public class AchievementController extends BasicInsertableController<Achievement
private static final int MINIMUM_ROLES_BAMBOO_SILVER = 4;
private static final int MINIMUM_ROLES_BAMBOO_GOLD = 5;

private static final int MINIMUM_LOST_SITH_NORMAL = 2;

private static final int MINIMUM_LOST_SITH_BRONZE = 3;
private static final int MINIMUM_LOST_SITH_SILVER = 4;

private static final int PARTICIPANT_YEARS = 5;
private static final int PARTICIPANT_YEARS_BRONZE = 10;
private static final int PARTICIPANT_YEARS_SILVER = 15;
Expand Down Expand Up @@ -331,6 +336,10 @@ public List<AchievementDTO> getAchievements(TournamentDTO tournamentDTO, Achieve
return convertAll(getProvider().get(tournamentConverter.reverse(tournamentDTO), achievementType));
}

public List<AchievementDTO> getAchievements(TournamentDTO tournamentDTO) {
return convertAll(getProvider().get(tournamentConverter.reverse(tournamentDTO)));
}

public List<AchievementDTO> getAchievements(TournamentDTO tournamentDTO, AchievementType achievementType, AchievementGrade achievementGrade) {
return convertAll(getProvider().get(tournamentConverter.reverse(tournamentDTO), achievementType, achievementGrade));
}
Expand Down Expand Up @@ -1981,14 +1990,57 @@ private List<Achievement> generateVendettaAchievement(Tournament tournament) {
participants, tournament);
}

/**
* Somebody wins a fight against other participant that is always winning him.
*
* @param tournament
* @return
*/
private List<Achievement> generateSithApprenticesAlwaysKillTheirMasterAchievement(Tournament tournament) {
getFightsFromTournament().forEach(fight -> fight.getDuels().forEach(duel -> {
if (duel.getWinner() < 0) {

} else if (duel.getWinner() > 0) {
final List<Achievement> achievements = new ArrayList<>();
getFightsFromTournament().forEach(fight -> {
for (Duel duel : fight.getDuels()) {
final List<Duel> previousDuels = duelProvider.getWhenBothAreInvolved(duel.getCompetitor1(), duel.getCompetitor2());
boolean isApprentice = true;
int numberOfPreviousDuels = 0;
for (Duel previousDuel : previousDuels) {
if (previousDuel.getCreatedAt().isBefore(tournament.getCreatedAt())) {
numberOfPreviousDuels++;
//Check if he has already won vs the master
if (Objects.equals(duel.getCompetitorWinner(), previousDuel.getCompetitorWinner()) || previousDuel.getWinner() == 0) {
isApprentice = false;
break;
}
}
}
if (isApprentice) {
//Generate achievement depending on the number of fights.
switch (numberOfPreviousDuels) {
case 0:
case 1:
//At least, the other participant must have won you two times.
break;
case MINIMUM_LOST_SITH_NORMAL:
achievements.add(new Achievement(duel.getCompetitorWinner(), tournament, AchievementType.SITH_APPRENTICES_ALWAYS_KILL_THEIR_MASTER,
AchievementGrade.NORMAL));
break;
case MINIMUM_LOST_SITH_BRONZE:
achievements.add(new Achievement(duel.getCompetitorWinner(), tournament, AchievementType.SITH_APPRENTICES_ALWAYS_KILL_THEIR_MASTER,
AchievementGrade.BRONZE));
break;
case MINIMUM_LOST_SITH_SILVER:
achievements.add(new Achievement(duel.getCompetitorWinner(), tournament, AchievementType.SITH_APPRENTICES_ALWAYS_KILL_THEIR_MASTER,
AchievementGrade.SILVER));
break;
default:
achievements.add(new Achievement(duel.getCompetitorWinner(), tournament, AchievementType.SITH_APPRENTICES_ALWAYS_KILL_THEIR_MASTER,
AchievementGrade.GOLD));
}

}
}
}
});
return achievementProvider.saveAll(achievements);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ public List<Duel> get(Participant participant) {
return getRepository().findByParticipant(participant);
}

public List<Duel> getWhenBothAreInvolved(Participant participant1, Participant participant2) {
return getRepository().findByParticipants(participant1, participant2);
}

public List<Duel> get(Tournament tournament) {
return getRepository().findByTournament(tournament);
}
Expand Down
Loading

0 comments on commit f6b3818

Please sign in to comment.