Merge branch 'feature/quests' of github.com:Mineplex-LLC/Minecraft-PC into feature/quests

This commit is contained in:
Sarah 2017-05-31 21:51:25 +02:00
commit c355015041
5 changed files with 29 additions and 7 deletions

View File

@ -9,11 +9,13 @@ public class BaseQuest implements Quest
private final int _uniqueId;
private final String _name;
private final QuestRarity _rarity;
private final int _cost;
public BaseQuest(int uniqueId, String name, QuestRarity rarity)
public BaseQuest(int uniqueId, String name, int cost, QuestRarity rarity)
{
_uniqueId = uniqueId;
_name = name;
_cost = cost;
_rarity = rarity;
}
@ -41,4 +43,10 @@ public class BaseQuest implements Quest
return _uniqueId + "";
}
@Override
public boolean shouldRotate()
{
return _cost != -1;
}
}

View File

@ -1,5 +1,6 @@
package mineplex.quest.common;
import mineplex.quest.daemon.QuestManager;
import mineplex.serverdata.data.Data;
import mineplex.serverdata.data.DataRepository;
@ -40,4 +41,13 @@ public interface Quest extends Data
*/
@Override
String getDataId();
/**
* Checks whether this quest should be selected by the {@link QuestManager} daemon process.
* Quests with a cost of -1 should not ever be selected as active quests by the daemon.
*
* @return <code>true</code> if this quest should be selected as an active quest, or
* <code>false</code> otherwise.
*/
boolean shouldRotate();
}

View File

@ -24,6 +24,7 @@ public class Quests
private static final int UNIQUE_ID_COLUMN = 0;
private static final int NAME_COLUMN = 1;
private static final int COST_COLUMN = 4;
private static final int RARITY_COLUMN = 9;
public static final Set<Quest> QUESTS;
@ -46,9 +47,10 @@ public class Quests
{
int uniqueId = Integer.parseInt(row.get(UNIQUE_ID_COLUMN));
String name = row.get(NAME_COLUMN);
int cost = Integer.parseInt(row.get(COST_COLUMN));
QuestRarity rarity = QuestRarity.valueOf(row.get(RARITY_COLUMN).toUpperCase());
Quest quest = new BaseQuest(uniqueId, name, rarity);
Quest quest = new BaseQuest(uniqueId, name, cost, rarity);
builder.add(quest);
}

View File

@ -16,8 +16,6 @@ import com.google.gson.JsonParser;
/**
* Provides utility methods for deserializing google sheets json files.
* @author Kenny
*
*/
public class UtilGoogleSheet
{

View File

@ -151,6 +151,9 @@ public class QuestManager extends Thread
{
while (_alive)
{
// purge recently selected quests repo of expired entries
_recentlySelectedQuestsRepo.clean();
LocalDate now = LocalDate.now(EST_TIMEZONE);
// check if date has changed; if so we need to choose new quests
if (_currentDate.isBefore(now) || _activeQuests.isEmpty())
@ -226,7 +229,8 @@ public class QuestManager extends Thread
public void clearRecentlyActiveQuests()
{
_recentlySelectedQuestsRepo.clean();
_recentlySelectedQuestsRepo.getElements()
.forEach(_recentlySelectedQuestsRepo::removeElement);
}
private void selectRandomQuests()
@ -240,8 +244,8 @@ public class QuestManager extends Thread
{
Quest q = _quests.next();
// select random weighted quest, ignore those recently selected
if (_activeQuests.contains(q)
|| _recentlySelectedQuestsRepo.elementExists(q.getDataId()))
if (!q.shouldRotate() || _activeQuests.contains(q)
|| _recentlySelectedQuestsRepo.elementExists(q.getDataId()))
{
// quest is already active or it's been active recently
continue;