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

Quest Scoring for Hall of Fame #705

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from
4 changes: 3 additions & 1 deletion src/games/stendhal/common/Level.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* $Id$ */
/***************************************************************************
* (C) Copyright 2003 - Marauroa *
* (C) Copyright 2003-2024 - Marauroa *
***************************************************************************
***************************************************************************
* *
Expand All @@ -24,6 +24,8 @@ public class Level {
// Max Level is LEVELS - 1.
// xp formula overflows for level = 599.
public static final int LEVELS = 598;
/** Maximum level which players can attain (597). */
public static final int MAX = Level.LEVELS-1;

private static int[] xp;

Expand Down
13 changes: 7 additions & 6 deletions src/games/stendhal/server/core/engine/db/AchievementDAO.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/***************************************************************************
* (C) Copyright 2003-2020 - Stendhal *
* (C) Copyright 2003-2024 - Stendhal *
***************************************************************************
***************************************************************************
* *
Expand All @@ -22,14 +22,15 @@
import games.stendhal.server.core.rp.achievement.Achievement;
import marauroa.server.db.DBTransaction;
import marauroa.server.db.TransactionPool;


/**
* DAO to handle achievements for the stendhal website
* @author madmetzger
* DAO to handle achievements for the Stendhal website.
*
* @author madmetzger
*/
public class AchievementDAO {


/**
* logs a reached achievement into the database
*
Expand Down Expand Up @@ -87,7 +88,7 @@ public int insertAchievement(DBTransaction transaction, Achievement achievement)
parameters.put("title", achievement.getTitle());
parameters.put("category", achievement.getCategory().toString());
parameters.put("description", achievement.getDescription());
parameters.put("base_score", achievement.getBaseScore());
parameters.put("base_score", achievement.getBaseScoreValue());
parameters.put("active", achievement.isActive() ? 1 : 0);
transaction.execute(query, parameters);
achievementId = transaction.getLastInsertId("achievement", "id");
Expand Down Expand Up @@ -129,7 +130,7 @@ public void updateAchievement(DBTransaction transaction, Integer id, Achievement
parameters.put("title", achievement.getTitle());
parameters.put("category", achievement.getCategory().toString());
parameters.put("description", achievement.getDescription());
parameters.put("base_score", achievement.getBaseScore());
parameters.put("base_score", achievement.getBaseScoreValue());
parameters.put("active", achievement.isActive() ? 1 : 0);
parameters.put("id", id);
transaction.execute(query, parameters);
Expand Down
44 changes: 44 additions & 0 deletions src/games/stendhal/server/core/rp/HOFScore.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/***************************************************************************
* Copyright © 2024 - Faiumoni e. V. *
***************************************************************************
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
package games.stendhal.server.core.rp;


/**
* Scoring values for Hall of Fame.
*/
public class HOFScore {

/** Standard score awarding no points. */
public static final HOFScore NONE = new HOFScore(0);
/** Standard score awarding 1 point. */
public static final HOFScore EASY = new HOFScore(1);
/** Standard score awarding 2 points. */
public static final HOFScore MEDIUM = new HOFScore(2);
/** Standard score awarding 5 points. */
public static final HOFScore HARD = new HOFScore(5);
/** Standard score awarding 7 points. */
public static final HOFScore EXTREME = new HOFScore(7);

/** Points value of this scoring tier. */
public final int value;


/**
* Creates a new Hall of Fame score.
*
* @param value
* Points value of this scoring tier.
*/
public HOFScore(final int value) {
this.value = value;
}
}
16 changes: 16 additions & 0 deletions src/games/stendhal/server/core/rp/StendhalQuestSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,22 @@ private Collection<IQuest> findCompletedQuests(final Player player) {
return findCompletedQuests(player, false);
}

/**
* Retrieves points total for completed quests to apply to Hall of Fame.
*
* @param player
* Player to whom points are being attributed.
* @return
* Total score for completed quests.
*/
public int getTotalHOFScore(final Player player) {
int score = 0;
for (final IQuest quest: findCompletedQuests(player, true)) {
score += quest.getHOFScore(player).value;
}
return score;
}

/**
* gets the description of a quest
*
Expand Down
41 changes: 23 additions & 18 deletions src/games/stendhal/server/core/rp/achievement/Achievement.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* $Id$ */
/***************************************************************************
* (C) Copyright 2003-2023 - Stendhal *
* (C) Copyright 2003-2024 - Stendhal *
***************************************************************************
***************************************************************************
* *
Expand All @@ -12,28 +12,20 @@
***************************************************************************/
package games.stendhal.server.core.rp.achievement;

import games.stendhal.server.core.rp.HOFScore;
import games.stendhal.server.entity.npc.ChatCondition;
import games.stendhal.server.entity.player.Player;


/**
* An Achievement a player can reach while playing the game.
*
* Achievements are given for example for doing a certain number of quests or killing a number of special creatures
*
* @author madmetzger
*/
public class Achievement {

/** base score for easy achievements */
public static final int EASY_BASE_SCORE = 1;

/** base score for achievements of medium difficulty */
public static final int MEDIUM_BASE_SCORE = 2;

/** base score for difficult achievements */
public static final int HARD_BASE_SCORE = 5;

/** base score for extreme achievement */
public static final int EXTREME_BASE_SCORE = 7;

private final String identifier;

private final String title;
Expand All @@ -42,15 +34,14 @@ public class Achievement {

private final String description;

private final int baseScore;
private final HOFScore baseScore;

/** is this achievement visible? */
private final boolean active;

private final ChatCondition condition;



/**
* create a new achievement
*
Expand All @@ -62,7 +53,7 @@ public class Achievement {
* @param active
* @param condition
*/
public Achievement(String identifier, String title, Category category, String description, int baseScore, boolean active, ChatCondition condition) {
public Achievement(String identifier, String title, Category category, String description, HOFScore baseScore, boolean active, ChatCondition condition) {
this.identifier = identifier;
this.title = title;
this.category = category;
Expand Down Expand Up @@ -101,12 +92,25 @@ public String getDescription() {
}

/**
* @return the base score for this achievement
* Retrieves base score of this achievement.
*
* @return
* Achievement base score.
*/
public int getBaseScore() {
public HOFScore getBaseScore() {
return this.baseScore;
}

/**
* Retrieves base score of this achievement.
*
* @return
* Achievement base score integer value.
*/
public int getBaseScoreValue() {
return this.baseScore.value;
}

/**
* @return true if the achievement is visible, false otherwise
*/
Expand All @@ -116,6 +120,7 @@ public boolean isActive() {

/**
* Check if a player has fulfilled this achievement
*
* @param p the player to check
* @return true iff this achievement's condition evaluates to true
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.LinkedList;
import java.util.List;

import games.stendhal.server.core.rp.HOFScore;
import games.stendhal.server.core.rp.achievement.Achievement;
import games.stendhal.server.core.rp.achievement.Category;
import games.stendhal.server.entity.npc.ChatCondition;
Expand Down Expand Up @@ -50,7 +51,7 @@ public abstract class AbstractAchievementFactory {
* @param condition
* @return the new Achievement
*/
protected Achievement createAchievement(String identifier, String title, String description, int score, boolean active, ChatCondition condition) {
protected Achievement createAchievement(String identifier, String title, String description, HOFScore score, boolean active, ChatCondition condition) {
return new Achievement(identifier, title, getCategory(), description, score, active, condition);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/***************************************************************************
* (C) Copyright 2003-2023 - Stendhal *
* (C) Copyright 2003-2024 - Stendhal *
***************************************************************************
***************************************************************************
* *
Expand All @@ -14,6 +14,7 @@
import java.util.Collection;
import java.util.LinkedList;

import games.stendhal.server.core.rp.HOFScore;
import games.stendhal.server.core.rp.achievement.Achievement;
import games.stendhal.server.core.rp.achievement.Category;
import games.stendhal.server.entity.npc.condition.QuestStateGreaterThanCondition;
Expand Down Expand Up @@ -46,37 +47,37 @@ public Collection<Achievement> createAchievements() {
achievements.add(createAchievement(
ID_SUPPORTER, "Ados's Supporter",
"Finish daily item quest 10 times",
Achievement.EASY_BASE_SCORE, true,
HOFScore.EASY, true,
new QuestStateGreaterThanCondition("daily_item", 2, 9)));

achievements.add(createAchievement(
ID_PROVIDER, "Ados's Provider",
"Finish daily item quest 50 times",
Achievement.EASY_BASE_SCORE, true,
HOFScore.EASY, true,
new QuestStateGreaterThanCondition("daily_item", 2, 49)));

achievements.add(createAchievement(
ID_SUPPLIER, "Ados's Supplier",
"Finish daily item quest 100 times",
Achievement.MEDIUM_BASE_SCORE, true,
HOFScore.MEDIUM, true,
new QuestStateGreaterThanCondition("daily_item", 2, 99)));

achievements.add(createAchievement(
ID_STOCKPILER, "Ados's Stockpiler",
"Finish daily item quest 250 times",
Achievement.MEDIUM_BASE_SCORE, true,
HOFScore.MEDIUM, true,
new QuestStateGreaterThanCondition("daily_item", 2, 249)));

achievements.add(createAchievement(
ID_HOARDER, "Ados's Hoarder",
"Finish daily item quest 500 times",
Achievement.HARD_BASE_SCORE, true,
HOFScore.HARD, true,
new QuestStateGreaterThanCondition("daily_item", 2, 499)));

achievements.add(createAchievement(
ID_LIFEBLOOD, "Ados's Lifeblood",
"Finish daily item quest 1,000 times",
Achievement.EXTREME_BASE_SCORE, true,
HOFScore.EXTREME, true,
new QuestStateGreaterThanCondition("daily_item", 2, 999)));

return achievements;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import games.stendhal.common.parser.Sentence;
import games.stendhal.server.core.engine.SingletonRepository;
import games.stendhal.server.core.rp.HOFScore;
import games.stendhal.server.core.rp.achievement.Achievement;
import games.stendhal.server.core.rp.achievement.Category;
import games.stendhal.server.core.rp.achievement.condition.BoughtNumberOfCondition;
Expand Down Expand Up @@ -106,19 +107,19 @@ public Collection<Achievement> createAchievements() {
achievements.add(createAchievement(
ID_HAPPY_HOUR, "It's Happy Hour Somewhere",
"Purchase 100 bottles of beer & 100 glasses of wine",
Achievement.EASY_BASE_SCORE, true,
HOFScore.EASY, true,
new BoughtNumberOfCondition(100, Arrays.asList("beer", "wine"))));

achievements.add(createAchievement(
ID_SELL_20K, "Traveling Peddler",
"Make 20000 money in sales to NPCs",
Achievement.EASY_BASE_SCORE, true,
HOFScore.EASY, true,
new HasEarnedTotalMoneyCondition(20000)));

achievements.add(createAchievement(
ID_BUY_ALL, "Community Supporter",
"Spend money around the world",
Achievement.MEDIUM_BASE_SCORE, true,
HOFScore.MEDIUM, true,
new HasSpentMoneyCondition(TRADE_ALL_AMOUNTS)));


Expand Down
Loading
Loading