Finished Custom Rewards API

This commit is contained in:
Blackvein 2014-01-09 13:17:56 -08:00
parent f33786a746
commit 4a8a64b26b
3 changed files with 72 additions and 47 deletions

View File

@ -1037,7 +1037,8 @@ public class QuestFactory implements ConversationAbandonedListener, ColorUtil {
LinkedList<String> heroesClassRews = null; LinkedList<String> heroesClassRews = null;
LinkedList<Double> heroesExpRews = null; LinkedList<Double> heroesExpRews = null;
LinkedList<String> phatLootRews = null; LinkedList<String> phatLootRews = null;
LinkedList<String> customRews = null;
LinkedList<Map<String, Object>> customRewsData = null;
if (cc.getSessionData(CK.Q_REDO_DELAY) != null) { if (cc.getSessionData(CK.Q_REDO_DELAY) != null) {
redo = (Long) cc.getSessionData(CK.Q_REDO_DELAY); redo = (Long) cc.getSessionData(CK.Q_REDO_DELAY);
@ -1158,6 +1159,11 @@ public class QuestFactory implements ConversationAbandonedListener, ColorUtil {
phatLootRews = (LinkedList<String>) cc.getSessionData(CK.REW_PHAT_LOOTS); phatLootRews = (LinkedList<String>) cc.getSessionData(CK.REW_PHAT_LOOTS);
} }
if (cc.getSessionData(CK.REW_CUSTOM) != null) {
customRews = (LinkedList<String>) cc.getSessionData(CK.REW_CUSTOM);
customRewsData = (LinkedList<Map<String, Object>>) cc.getSessionData(CK.REW_CUSTOM_DATA);
}
cs.set("name", name); cs.set("name", name);
cs.set("npc-giver-id", npcStart); cs.set("npc-giver-id", npcStart);
cs.set("block-start", blockStart); cs.set("block-start", blockStart);
@ -1522,7 +1528,7 @@ public class QuestFactory implements ConversationAbandonedListener, ColorUtil {
} }
if (moneyRew != null || questPointsRew != null || itemRews != null && itemRews.isEmpty() == false || permRews != null && permRews.isEmpty() == false || expRew != null || commandRews != null && commandRews.isEmpty() == false || mcMMOSkillRews != null || RPGItemRews != null || heroesClassRews != null && heroesClassRews.isEmpty() == false || phatLootRews != null && phatLootRews.isEmpty() == false) { if (moneyRew != null || questPointsRew != null || itemRews != null && itemRews.isEmpty() == false || permRews != null && permRews.isEmpty() == false || expRew != null || commandRews != null && commandRews.isEmpty() == false || mcMMOSkillRews != null || RPGItemRews != null || heroesClassRews != null && heroesClassRews.isEmpty() == false || phatLootRews != null && phatLootRews.isEmpty() == false || customRews != null && customRews.isEmpty() == false) {
ConfigurationSection rews = cs.createSection("rewards"); ConfigurationSection rews = cs.createSection("rewards");
@ -1540,6 +1546,15 @@ public class QuestFactory implements ConversationAbandonedListener, ColorUtil {
rews.set("heroes-exp-amounts", heroesExpRews); rews.set("heroes-exp-amounts", heroesExpRews);
rews.set("phat-loots", phatLootRews); rews.set("phat-loots", phatLootRews);
if(customRews != null){
ConfigurationSection customRewsSec = rews.createSection("custom-rewards");
for(int i = 0; i < customRews.size(); i++){
ConfigurationSection customRewSec = customRewsSec.createSection("req" + (i + 1));
customRewSec.set("name", customRews.get(i));
customRewSec.set("data", customRewsData.get(i));
}
}
} else { } else {
cs.set("rewards", null); cs.set("rewards", null);
} }
@ -1682,6 +1697,10 @@ public class QuestFactory implements ConversationAbandonedListener, ColorUtil {
if(q.phatLootRewards.isEmpty() == false) { if(q.phatLootRewards.isEmpty() == false) {
cc.setSessionData(CK.REW_PHAT_LOOTS, q.phatLootRewards); cc.setSessionData(CK.REW_PHAT_LOOTS, q.phatLootRewards);
} }
if(q.customRewards.isEmpty() == false) {
cc.setSessionData(CK.REW_CUSTOM, q.customRewards);
}
// //
//Stages //Stages

View File

@ -620,6 +620,7 @@ public class RequirementsPrompt extends FixedSetPrompt implements ColorUtil {
} else if (input.equalsIgnoreCase("clear")) { } else if (input.equalsIgnoreCase("clear")) {
context.setSessionData(CK.REQ_CUSTOM, null); context.setSessionData(CK.REQ_CUSTOM, null);
context.setSessionData(CK.REQ_CUSTOM_DATA, null); context.setSessionData(CK.REQ_CUSTOM_DATA, null);
context.setSessionData(CK.REQ_CUSTOM_DATA_TEMP, null);
context.getForWhom().sendRawMessage(YELLOW + "Custom requirements cleared."); context.getForWhom().sendRawMessage(YELLOW + "Custom requirements cleared.");
} }

View File

@ -7,6 +7,8 @@ import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map;
import me.blackvein.quests.CustomReward;
import me.blackvein.quests.util.ColorUtil; import me.blackvein.quests.util.ColorUtil;
import me.blackvein.quests.QuestFactory; import me.blackvein.quests.QuestFactory;
import me.blackvein.quests.Quester; import me.blackvein.quests.Quester;
@ -181,7 +183,7 @@ public class RewardsPrompt extends FixedSetPrompt implements ColorUtil {
} }
if (context.getSessionData(CK.REW_CUSTOM) == null) {a if (context.getSessionData(CK.REW_CUSTOM) == null) {
text += BLUE + "" + BOLD + "11 - " + RESET + ITALIC + PURPLE + "Custom Rewards (None set)\n"; text += BLUE + "" + BOLD + "11 - " + RESET + ITALIC + PURPLE + "Custom Rewards (None set)\n";
} else { } else {
text += BLUE + "" + BOLD + "11 - " + RESET + ITALIC + PURPLE + "Custom Rewards\n"; text += BLUE + "" + BOLD + "11 - " + RESET + ITALIC + PURPLE + "Custom Rewards\n";
@ -238,7 +240,9 @@ public class RewardsPrompt extends FixedSetPrompt implements ColorUtil {
} else { } else {
return new RewardsPrompt(quests, factory); return new RewardsPrompt(quests, factory);
} }
} else if (input.equalsIgnoreCase("11")) { }else if(input.equalsIgnoreCase("11")){
return new CustomRewardsPrompt();
}else if (input.equalsIgnoreCase("12")) {
return factory.returnToMenu(); return factory.returnToMenu();
} }
return null; return null;
@ -1119,19 +1123,19 @@ public class RewardsPrompt extends FixedSetPrompt implements ColorUtil {
} }
} }
private class CustomRequirementsPrompt extends StringPrompt { private class CustomRewardsPrompt extends StringPrompt {
@Override @Override
public String getPromptText(ConversationContext context) { public String getPromptText(ConversationContext context) {
String text = PINK + "- Custom Requirements -\n"; String text = PINK + "- Custom Rewards -\n";
if(quests.customRequirements.isEmpty()){ if(quests.customRewards.isEmpty()){
text += BOLD + "" + PURPLE + "(No modules loaded)"; text += BOLD + "" + PURPLE + "(No modules loaded)";
}else { }else {
for(CustomRequirement cr : quests.customRequirements) for(CustomReward cr : quests.customRewards)
text += PURPLE + " - " + cr.getName() + "\n"; text += PURPLE + " - " + cr.getName() + "\n";
} }
return text + YELLOW + "Enter the name of a custom requirement to add, or enter \'clear\' to clear all custom requirements, or \'cancel\' to return."; return text + YELLOW + "Enter the name of a custom reward to add, or enter \'clear\' to clear all custom rewards, or \'cancel\' to return.";
} }
@Override @Override
@ -1139,8 +1143,8 @@ public class RewardsPrompt extends FixedSetPrompt implements ColorUtil {
if (input.equalsIgnoreCase("cancel") == false && input.equalsIgnoreCase("clear") == false) { if (input.equalsIgnoreCase("cancel") == false && input.equalsIgnoreCase("clear") == false) {
CustomRequirement found = null; CustomReward found = null;
for(CustomRequirement cr : quests.customRequirements){ for(CustomReward cr : quests.customRewards){
if(cr.getName().equalsIgnoreCase(input)){ if(cr.getName().equalsIgnoreCase(input)){
found = cr; found = cr;
break; break;
@ -1148,7 +1152,7 @@ public class RewardsPrompt extends FixedSetPrompt implements ColorUtil {
} }
if(found == null){ if(found == null){
for(CustomRequirement cr : quests.customRequirements){ for(CustomReward cr : quests.customRewards){
if(cr.getName().toLowerCase().contains(input.toLowerCase())){ if(cr.getName().toLowerCase().contains(input.toLowerCase())){
found = cr; found = cr;
break; break;
@ -1158,64 +1162,65 @@ public class RewardsPrompt extends FixedSetPrompt implements ColorUtil {
if(found != null){ if(found != null){
if(context.getSessionData(CK.REQ_CUSTOM) != null){ if(context.getSessionData(CK.REW_CUSTOM) != null){
LinkedList<String> list = (LinkedList<String>) context.getSessionData(CK.REQ_CUSTOM); LinkedList<String> list = (LinkedList<String>) context.getSessionData(CK.REW_CUSTOM);
LinkedList<Map<String, Object>> datamapList = (LinkedList<Map<String, Object>>) context.getSessionData(CK.REQ_CUSTOM_DATA); LinkedList<Map<String, Object>> datamapList = (LinkedList<Map<String, Object>>) context.getSessionData(CK.REW_CUSTOM_DATA);
if(list.contains(found.getName()) == false){ if(list.contains(found.getName()) == false){
list.add(found.getName()); list.add(found.getName());
datamapList.add(found.datamap); datamapList.add(found.datamap);
}else{ }else{
context.getForWhom().sendRawMessage(YELLOW + "That custom requirement has already been added!"); context.getForWhom().sendRawMessage(YELLOW + "That custom reward has already been added!");
return new CustomRequirementsPrompt(); return new CustomRewardsPrompt();
} }
}else{ }else{
LinkedList<Map<String, Object>> datamapList = new LinkedList<Map<String, Object>>(); LinkedList<Map<String, Object>> datamapList = new LinkedList<Map<String, Object>>();
datamapList.add(found.datamap); datamapList.add(found.datamap);
LinkedList<String> list = new LinkedList<String>(); LinkedList<String> list = new LinkedList<String>();
list.add(found.getName()); list.add(found.getName());
context.setSessionData(CK.REQ_CUSTOM, list); context.setSessionData(CK.REW_CUSTOM, list);
context.setSessionData(CK.REQ_CUSTOM_DATA, datamapList); context.setSessionData(CK.REW_CUSTOM_DATA, datamapList);
} }
//Send user to the custom data prompt if there is any needed //Send user to the custom data prompt if there is any needed
if(found.datamap.isEmpty() == false){ if(found.datamap.isEmpty() == false){
context.setSessionData(CK.REQ_CUSTOM_DATA_DESCRIPTIONS, found.descriptions); context.setSessionData(CK.REW_CUSTOM_DATA_DESCRIPTIONS, found.descriptions);
return new RequirementCustomDataListPrompt(); return new RewardCustomDataListPrompt();
} }
// //
}else{ }else{
context.getForWhom().sendRawMessage(YELLOW + "Custom requirement module not found."); context.getForWhom().sendRawMessage(YELLOW + "Custom reward module not found.");
return new CustomRequirementsPrompt(); return new CustomRewardsPrompt();
} }
} else if (input.equalsIgnoreCase("clear")) { } else if (input.equalsIgnoreCase("clear")) {
context.setSessionData(CK.REQ_CUSTOM, null); context.setSessionData(CK.REW_CUSTOM, null);
context.setSessionData(CK.REQ_CUSTOM_DATA, null); context.setSessionData(CK.REW_CUSTOM_DATA, null);
context.getForWhom().sendRawMessage(YELLOW + "Custom requirements cleared."); context.setSessionData(CK.REW_CUSTOM_DATA_TEMP, null);
context.getForWhom().sendRawMessage(YELLOW + "Custom rewards cleared.");
} }
return new RequirementsPrompt(quests, factory); return new RewardsPrompt(quests, factory);
} }
} }
private class RequirementCustomDataListPrompt extends StringPrompt { private class RewardCustomDataListPrompt extends StringPrompt {
@Override @Override
public String getPromptText(ConversationContext context) { public String getPromptText(ConversationContext context) {
String text = BOLD + "" + AQUA + "- "; String text = BOLD + "" + AQUA + "- ";
LinkedList<String> list = (LinkedList<String>) context.getSessionData(CK.REQ_CUSTOM); LinkedList<String> list = (LinkedList<String>) context.getSessionData(CK.REW_CUSTOM);
LinkedList<Map<String, Object>> datamapList = (LinkedList<Map<String, Object>>) context.getSessionData(CK.REQ_CUSTOM_DATA); LinkedList<Map<String, Object>> datamapList = (LinkedList<Map<String, Object>>) context.getSessionData(CK.REW_CUSTOM_DATA);
String reqName = list.getLast(); String rewName = list.getLast();
Map<String, Object> datamap = datamapList.getLast(); Map<String, Object> datamap = datamapList.getLast();
text += reqName + " -\n"; text += rewName + " -\n";
int index = 1; int index = 1;
LinkedList<String> datamapKeys = new LinkedList<String>(); LinkedList<String> datamapKeys = new LinkedList<String>();
@ -1243,7 +1248,7 @@ public class RewardsPrompt extends FixedSetPrompt implements ColorUtil {
@Override @Override
public Prompt acceptInput(ConversationContext context, String input) { public Prompt acceptInput(ConversationContext context, String input) {
LinkedList<Map<String, Object>> datamapList = (LinkedList<Map<String, Object>>) context.getSessionData(CK.REQ_CUSTOM_DATA); LinkedList<Map<String, Object>> datamapList = (LinkedList<Map<String, Object>>) context.getSessionData(CK.REW_CUSTOM_DATA);
Map<String, Object> datamap = datamapList.getLast(); Map<String, Object> datamap = datamapList.getLast();
int numInput; int numInput;
@ -1251,11 +1256,11 @@ public class RewardsPrompt extends FixedSetPrompt implements ColorUtil {
try{ try{
numInput = Integer.parseInt(input); numInput = Integer.parseInt(input);
}catch(NumberFormatException nfe){ }catch(NumberFormatException nfe){
return new RequirementCustomDataListPrompt(); return new RewardCustomDataListPrompt();
} }
if(numInput < 1 || numInput > datamap.size() + 1) if(numInput < 1 || numInput > datamap.size() + 1)
return new RequirementCustomDataListPrompt(); return new RewardCustomDataListPrompt();
if(numInput < datamap.size() + 1){ if(numInput < datamap.size() + 1){
@ -1265,16 +1270,16 @@ public class RewardsPrompt extends FixedSetPrompt implements ColorUtil {
Collections.sort(datamapKeys); Collections.sort(datamapKeys);
String selectedKey = datamapKeys.get(numInput - 1); String selectedKey = datamapKeys.get(numInput - 1);
context.setSessionData(CK.REQ_CUSTOM_DATA_TEMP, selectedKey); context.setSessionData(CK.REW_CUSTOM_DATA_TEMP, selectedKey);
return new RequirementCustomDataPrompt(); return new RewardCustomDataPrompt();
}else{ }else{
if(datamap.containsValue(null)){ if(datamap.containsValue(null)){
return new RequirementCustomDataListPrompt(); return new RewardCustomDataListPrompt();
}else{ }else{
context.setSessionData(CK.REQ_CUSTOM_DATA_DESCRIPTIONS, null); context.setSessionData(CK.REW_CUSTOM_DATA_DESCRIPTIONS, null);
return new RequirementsPrompt(quests, factory); return new RewardsPrompt(quests, factory);
} }
} }
@ -1283,13 +1288,13 @@ public class RewardsPrompt extends FixedSetPrompt implements ColorUtil {
} }
private class RequirementCustomDataPrompt extends StringPrompt { private class RewardCustomDataPrompt extends StringPrompt {
@Override @Override
public String getPromptText(ConversationContext context) { public String getPromptText(ConversationContext context) {
String text = ""; String text = "";
String temp = (String)context.getSessionData(CK.REQ_CUSTOM_DATA_TEMP); String temp = (String)context.getSessionData(CK.REW_CUSTOM_DATA_TEMP);
Map<String, String> descriptions = (Map<String, String>) context.getSessionData(CK.REQ_CUSTOM_DATA_DESCRIPTIONS); Map<String, String> descriptions = (Map<String, String>) context.getSessionData(CK.REW_CUSTOM_DATA_DESCRIPTIONS);
if(descriptions.get(temp) != null) if(descriptions.get(temp) != null)
text += GOLD + descriptions.get(temp) + "\n"; text += GOLD + descriptions.get(temp) + "\n";
@ -1300,11 +1305,11 @@ public class RewardsPrompt extends FixedSetPrompt implements ColorUtil {
@Override @Override
public Prompt acceptInput(ConversationContext context, String input) { public Prompt acceptInput(ConversationContext context, String input) {
LinkedList<Map<String, Object>> datamapList = (LinkedList<Map<String, Object>>) context.getSessionData(CK.REQ_CUSTOM_DATA); LinkedList<Map<String, Object>> datamapList = (LinkedList<Map<String, Object>>) context.getSessionData(CK.REW_CUSTOM_DATA);
Map<String, Object> datamap = datamapList.getLast(); Map<String, Object> datamap = datamapList.getLast();
datamap.put((String)context.getSessionData(CK.REQ_CUSTOM_DATA_TEMP), input); datamap.put((String)context.getSessionData(CK.REW_CUSTOM_DATA_TEMP), input);
context.setSessionData(CK.REQ_CUSTOM_DATA_TEMP, null); context.setSessionData(CK.REW_CUSTOM_DATA_TEMP, null);
return new RequirementCustomDataListPrompt(); return new RewardCustomDataListPrompt();
} }
} }