Skip to content
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

Should adjust healing based on freshness #409

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@
<property name="allowMissingParamTags" value="true"/>
<property name="allowMissingThrowsTags" value="true"/>
<property name="allowMissingReturnTag" value="true"/>
<property name="minLineCount" value="2"/>
<property name="minLineCount" value="8"/>
<property name="allowedAnnotations" value="Override, Test"/>
<property name="allowThrowsTagsForSubclasses" value="true"/>
</module>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.mafagafogigante.dungeon.achievements;

import org.mafagafogigante.dungeon.date.Date;
import org.mafagafogigante.dungeon.game.DungeonString;
import org.mafagafogigante.dungeon.game.Id;
import org.mafagafogigante.dungeon.game.RichStringSequence;
import org.mafagafogigante.dungeon.io.Version;
import org.mafagafogigante.dungeon.io.Writer;
import org.mafagafogigante.dungeon.logging.DungeonLogger;
Expand Down Expand Up @@ -34,7 +34,7 @@ public AchievementTracker(@NotNull Statistics statistics) {
/**
* Writes an achievement unlocked message with some information about the unlocked achievement.
*/
private static void writeAchievementUnlock(Achievement achievement, DungeonString builder) {
private static void writeAchievementUnlock(Achievement achievement, RichStringSequence builder) {
String format = "You unlocked the achievement %s because you %s.";
builder.append(String.format(format, achievement.getName(), achievement.getText()));
}
Expand All @@ -53,7 +53,7 @@ int getUnlockedCount() {
*
* @param achievement the Achievement to be unlocked.
*/
private void unlock(Achievement achievement, Date date, DungeonString builder) {
private void unlock(Achievement achievement, Date date, RichStringSequence builder) {
if (hasNotBeenUnlocked(achievement)) {
unlockedAchievements.put(achievement.getId(), new UnlockedAchievement(achievement, date));
writeAchievementUnlock(achievement, builder);
Expand Down Expand Up @@ -98,20 +98,20 @@ public boolean hasNotBeenUnlocked(@NotNull Achievement achievement) {
* <p>Before writing the first achievement unlock message, if there is one, a new line is written.
*/
public void update(AchievementStore achievementStore, Date date) {
DungeonString dungeonString = new DungeonString();
RichStringSequence richStringSequence = new RichStringSequence();
boolean wroteNewLine = false; // If we are going to write anything at all, we must start with a blank line.
for (Achievement achievement : achievementStore.getAchievements()) {
if (hasNotBeenUnlocked(achievement) && achievement.isFulfilled(statistics)) {
if (!wroteNewLine) {
dungeonString.append("\n");
richStringSequence.append("\n");
wroteNewLine = true;
}
unlock(achievement, date, dungeonString);
dungeonString.append("\n");
unlock(achievement, date, richStringSequence);
richStringSequence.append("\n");
}
}
if (dungeonString.getLength() != 0) {
Writer.write(dungeonString);
if (richStringSequence.getLength() != 0) {
Writer.getDefaultWriter().write(richStringSequence);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import org.mafagafogigante.dungeon.achievements.comparators.UnlockedAchievementComparators;
import org.mafagafogigante.dungeon.date.Date;
import org.mafagafogigante.dungeon.date.Duration;
import org.mafagafogigante.dungeon.game.DungeonString;
import org.mafagafogigante.dungeon.game.Game;
import org.mafagafogigante.dungeon.game.RichStringSequence;
import org.mafagafogigante.dungeon.io.Writer;

import java.awt.Color;
Expand Down Expand Up @@ -57,7 +57,7 @@ private static Comparator<UnlockedAchievement> getComparator(String[] arguments)
private static void writeAchievementTracker(AchievementTracker tracker, Comparator<UnlockedAchievement> comparator) {
List<UnlockedAchievement> unlockedAchievements = tracker.getUnlockedAchievements(comparator);
Date now = Game.getGameState().getWorld().getWorldDate();
DungeonString string = new DungeonString();
RichStringSequence string = new RichStringSequence();
for (UnlockedAchievement unlockedAchievement : unlockedAchievements) {
Duration sinceUnlock = new Duration(unlockedAchievement.getDate(), now);
string.setColor(Color.ORANGE);
Expand All @@ -68,16 +68,16 @@ private static void writeAchievementTracker(AchievementTracker tracker, Comparat
int total = AchievementStoreFactory.getDefaultStore().getAchievements().size();
string.setColor(Color.CYAN);
string.append(String.format("Progress: %d/%d", tracker.getUnlockedCount(), total));
Writer.write(string);
Writer.getDefaultWriter().write(string);
}

/**
* Writes a listing of valid UnlockedAchievement orderings to the screen.
*/
private static void writeValidOrderings() {
Writer.write("Valid orderings:");
Writer.getDefaultWriter().write("Valid orderings:");
for (String comparatorName : UnlockedAchievementComparators.getComparatorMap().keySet()) {
Writer.write(" " + comparatorName);
Writer.getDefaultWriter().write(" " + comparatorName);
}
}

Expand Down
23 changes: 12 additions & 11 deletions src/main/java/org/mafagafogigante/dungeon/commands/CommandSet.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.mafagafogigante.dungeon.commands;

import org.mafagafogigante.dungeon.game.DungeonString;
import org.mafagafogigante.dungeon.game.RichStringSequence;
import org.mafagafogigante.dungeon.io.Writer;

import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -34,28 +34,29 @@ static CommandSet emptyCommandSet() {
public void execute(@NotNull String[] arguments) {
String filter = arguments.length == 0 ? null : arguments[0];
List<CommandDescription> descriptions = commandSet.getCommandDescriptions();
DungeonString dungeonString = new DungeonString();
RichStringSequence richStringSequence = new RichStringSequence();
int count = 0;
for (CommandDescription description : descriptions) {
if (filter == null || StringUtils.startsWithIgnoreCase(description.getName(), filter)) {
count++;
dungeonString.append(StringUtils.rightPad(description.getName(), COMMAND_NAME_COLUMN_WIDTH));
dungeonString.append(description.getInfo());
dungeonString.append("\n");
richStringSequence.append(StringUtils.rightPad(description.getName(), COMMAND_NAME_COLUMN_WIDTH));
richStringSequence.append(description.getInfo());
richStringSequence.append("\n");
}
}
if (count == 0 && filter != null) {
Writer.write("No command starts with '" + filter + "'.");
Writer.getDefaultWriter().write("No command starts with '" + filter + "'.");
} else {
if (count > 1) {
dungeonString.append("\nListed ");
dungeonString.append(String.valueOf(count));
dungeonString.append(" commands.");
richStringSequence.append("\nListed ");
richStringSequence.append(String.valueOf(count));
richStringSequence.append(" commands.");
if (filter == null) {
dungeonString.append("\nYou can filter the output of this command by typing the beginning of a command.");
String string = "\nYou can filter the output of this command by typing the beginning of a command.";
richStringSequence.append(string);
}
}
Writer.write(dungeonString);
Writer.getDefaultWriter().write(richStringSequence);
}
}
});
Expand Down
Loading