From: Hendrik B. <nh...@us...> - 2011-11-25 22:47:33
|
Update of /cvsroot/arianne/stendhal/src/games/stendhal/server/maps/quests In directory vz-cvs-4.sog:/tmp/cvs-serv7991/src/games/stendhal/server/maps/quests Modified Files: Tag: VERSION_00_RELEASE_98 GuessKills.java Log Message: backported fixes of GuessKills quest by filinep Index: GuessKills.java =================================================================== RCS file: /cvsroot/arianne/stendhal/src/games/stendhal/server/maps/quests/GuessKills.java,v retrieving revision 1.1 retrieving revision 1.1.2.1 diff -C2 -d -r1.1 -r1.1.2.1 *** GuessKills.java 17 Nov 2011 20:51:22 -0000 1.1 --- GuessKills.java 25 Nov 2011 22:47:31 -0000 1.1.2.1 *************** *** 14,17 **** --- 14,18 ---- import games.stendhal.common.MathHelper; import games.stendhal.common.Rand; + import games.stendhal.common.grammar.Grammar; import games.stendhal.common.parser.Expression; import games.stendhal.common.parser.Sentence; *************** *** 20,30 **** import games.stendhal.server.entity.Entity; import games.stendhal.server.entity.creature.Creature; ! import games.stendhal.server.entity.npc.*; import games.stendhal.server.entity.npc.action.IncreaseXPAction; import games.stendhal.server.entity.npc.action.MultipleActions; import games.stendhal.server.entity.npc.action.SetQuestAction; import games.stendhal.server.entity.npc.action.SetQuestToTimeStampAction; ! import games.stendhal.server.entity.npc.condition.*; ! import games.stendhal.server.entity.player.*; import java.util.ArrayList; --- 21,46 ---- import games.stendhal.server.entity.Entity; import games.stendhal.server.entity.creature.Creature; ! import games.stendhal.server.entity.npc.ChatAction; ! import games.stendhal.server.entity.npc.ChatCondition; ! import games.stendhal.server.entity.npc.ConversationPhrases; ! import games.stendhal.server.entity.npc.ConversationStates; ! import games.stendhal.server.entity.npc.EventRaiser; ! import games.stendhal.server.entity.npc.SpeakerNPC; import games.stendhal.server.entity.npc.action.IncreaseXPAction; import games.stendhal.server.entity.npc.action.MultipleActions; + import games.stendhal.server.entity.npc.action.SayTimeRemainingAction; import games.stendhal.server.entity.npc.action.SetQuestAction; import games.stendhal.server.entity.npc.action.SetQuestToTimeStampAction; ! import games.stendhal.server.entity.npc.condition.AndCondition; ! import games.stendhal.server.entity.npc.condition.MinTotalCreaturesKilledCondition; ! import games.stendhal.server.entity.npc.condition.NotCondition; ! import games.stendhal.server.entity.npc.condition.OrCondition; ! import games.stendhal.server.entity.npc.condition.QuestInStateCondition; ! import games.stendhal.server.entity.npc.condition.TextHasNumberCondition; ! import games.stendhal.server.entity.npc.condition.TimePassedCondition; ! import games.stendhal.server.entity.npc.condition.TriggerInListCondition; ! import games.stendhal.server.entity.player.Player; ! import games.stendhal.server.maps.Region; ! import games.stendhal.server.util.TimeUtil; import java.util.ArrayList; *************** *** 51,55 **** * SLOTS: (subtract from list index to get slot index) * <ol> ! * <li>Quest state: done, guess1, guess2 or guess3</li> * <li>Timestamp: last time quest was completed</li> * <li>Creature: the creature that was asked about if quest was not completed</li> --- 67,71 ---- * SLOTS: (subtract from list index to get slot index) * <ol> ! * <li>Quest state: done, 1, 2 or 3 (where 1, 2 and 3 represent what guess the player is on)</li> * <li>Timestamp: last time quest was completed</li> * <li>Creature: the creature that was asked about if quest was not completed</li> *************** *** 71,78 **** public static final String QUEST_SLOT = "guess_kills"; ! private final int MIN_KILLS_REQUIRED = 1000; ! private final double ACCURACY = 0.02; ! private final int EXACT_REWARD = 150; ! private final int CLOSE_REWARD = 90; private String CREATURE = "rat"; --- 87,96 ---- public static final String QUEST_SLOT = "guess_kills"; ! private static final double ACCURACY = 0.02; ! private static final int MIN_KILLS_REQUIRED = 1000; ! private static final int EXACT_REWARD = 150; ! private static final int CLOSE_REWARD = 90; ! private static final int INTERVAL_BETWEEN_TRIES = MathHelper.MINUTES_IN_ONE_WEEK; ! private String CREATURE = "rat"; *************** *** 80,97 **** public void addToWorld() { super.addToWorld(); prepareQuestStep(); } public String getSlotName() { return QUEST_SLOT; } public String getName() { return "GuessKills"; } public List<String> getHistory(final Player player) { ! final List<String> res = new ArrayList<String>(); ! return res; } --- 98,161 ---- public void addToWorld() { super.addToWorld(); + fillQuestInfo( + "The guessing game", + "Crearid plays a game where you guess how many creatures you have killed.", + true); prepareQuestStep(); } + + @Override + public String getRegion() { + return Region.NALWOR_CITY; + } + + @Override + public boolean isRepeatable(final Player player) { + return true; + } + @Override public String getSlotName() { return QUEST_SLOT; } + @Override public String getName() { return "GuessKills"; } + @Override public List<String> getHistory(final Player player) { ! final List<String> res = new ArrayList<String>(); ! ! if (!player.hasQuest(QUEST_SLOT)) { ! return res; ! } ! ! final String state = player.getQuest(QUEST_SLOT, 0); ! final String time = player.getQuest(QUEST_SLOT, 1); ! final String creature = player.getQuest(QUEST_SLOT, 2); ! ! res.add("I have met Crearid. She is an old lady in Nalwor city."); ! res.add("She asked me to guess how many " + Grammar.plural(creature) + " I have killed."); ! ! if ("1".equals(state)) { ! res.add("I have three guesses left."); ! } else if ("2".equals(state)) { ! res.add("I have two guesses left."); ! } else if ("3".equals(state)) { ! res.add("I have one guess left."); ! } else if ("done".equals(state)) { ! final long timeRemaining = (MathHelper.parseLong(time) + INTERVAL_BETWEEN_TRIES * MathHelper.MILLISECONDS_IN_ONE_MINUTE) ! - System.currentTimeMillis(); ! ! if (timeRemaining > 0) { ! res.add("I can go see Crearid for another quiz in about " + TimeUtil.approxTimeUntil((int) (timeRemaining / 1000L))); ! } else { ! res.add("I can go see Crearid for another quiz now."); ! } ! } ! ! return res; } *************** *** 100,117 **** */ public void prepareQuestStep() { ! SpeakerNPC npc = npcs.get("Crearid"); final DefaultEntityManager manager = (DefaultEntityManager) SingletonRepository.getEntityManager(); ! ChatCondition requirement = new MinTotalCreaturesKilledCondition(MIN_KILLS_REQUIRED); ! ChatCondition isNumber = new TextHasNumberCondition(Integer.MIN_VALUE, Integer.MAX_VALUE); ! ChatCondition enoughTimePassed = new TimePassedCondition(QUEST_SLOT, 1, MathHelper.MINUTES_IN_ONE_WEEK); ! ChatCondition wrongAndNotBye = new AndCondition(new NotCondition(isNumber), new NotCondition(new TriggerInListCondition(ConversationPhrases.GOODBYE_MESSAGES))); ! ChatCondition questNotDone = new OrCondition(new QuestInStateCondition(QUEST_SLOT, 0, "guess1"), ! new QuestInStateCondition(QUEST_SLOT, 0, "guess2"), ! new QuestInStateCondition(QUEST_SLOT, 0, "guess3")); //checks if guess is exact answer ! ChatCondition exact = new ChatCondition() { public boolean fire(final Player player, final Sentence sentence, final Entity entity) { final Expression number = sentence.getNumeral(); --- 164,181 ---- */ public void prepareQuestStep() { ! final SpeakerNPC npc = npcs.get("Crearid"); final DefaultEntityManager manager = (DefaultEntityManager) SingletonRepository.getEntityManager(); ! final ChatCondition requirement = new MinTotalCreaturesKilledCondition(MIN_KILLS_REQUIRED); ! final ChatCondition isNumber = new TextHasNumberCondition(Integer.MIN_VALUE, Integer.MAX_VALUE); ! final ChatCondition enoughTimePassed = new TimePassedCondition(QUEST_SLOT, 1, INTERVAL_BETWEEN_TRIES); ! final ChatCondition wrongAndNotBye = new AndCondition(new NotCondition(isNumber), new NotCondition(new TriggerInListCondition(ConversationPhrases.GOODBYE_MESSAGES))); ! final ChatCondition questNotDone = new OrCondition(new QuestInStateCondition(QUEST_SLOT, 0, "1"), ! new QuestInStateCondition(QUEST_SLOT, 0, "2"), ! new QuestInStateCondition(QUEST_SLOT, 0, "3")); //checks if guess is exact answer ! final ChatCondition exact = new ChatCondition() { public boolean fire(final Player player, final Sentence sentence, final Entity entity) { final Expression number = sentence.getNumeral(); *************** *** 129,133 **** //checks if guess is close to actual answer ! ChatCondition close = new ChatCondition() { public boolean fire(final Player player, final Sentence sentence, final Entity entity) { final Expression number = sentence.getNumeral(); --- 193,197 ---- //checks if guess is close to actual answer ! final ChatCondition close = new ChatCondition() { public boolean fire(final Player player, final Sentence sentence, final Entity entity) { final Expression number = sentence.getNumeral(); *************** *** 144,166 **** }; ! ConversationStates[] tries = {ConversationStates.QUESTION_1, ! ConversationStates.QUESTION_2, ! ConversationStates.QUESTION_3}; //gets the creature from unfinished quest ! ChatAction getSavedCreature = new ChatAction() { public void fire(Player player, Sentence sentence, EventRaiser npc) { CREATURE = player.getQuest(QUEST_SLOT, 2); ! String state = player.getQuest(QUEST_SLOT, 0); ! int guesses = 4 - Integer.parseInt(state.substring(state.length() - 1)); ! npc.say("Let me see... you have " + guesses + " guess" + (guesses != 1 ? "es" : "") + " left... and if I recall correctly I asked you..." + ! " how many " + CREATURE + "s do think you have killed?"); } }; ! String[] triggers = {"game", "games", "play", "play game", "play games"}; //if quest not finished and came back --- 208,229 ---- }; ! final ConversationStates[] tries = {ConversationStates.QUESTION_1, ! ConversationStates.QUESTION_2, ! ConversationStates.QUESTION_3}; //gets the creature from unfinished quest ! final ChatAction getSavedCreature = new ChatAction() { public void fire(Player player, Sentence sentence, EventRaiser npc) { CREATURE = player.getQuest(QUEST_SLOT, 2); ! int guesses = 4 - MathHelper.parseIntDefault(player.getQuest(QUEST_SLOT, 0), 1); ! npc.say("Let me see... you have " + Grammar.quantityplnoun(guesses, "guess") + " left... and if I recall correctly I asked you..." + ! " how many " + Grammar.plural(CREATURE) + " do think you have killed?"); } }; ! final String[] triggers = {"game", "games", "play", "play game", "play games"}; //if quest not finished and came back *************** *** 175,191 **** npc.add(ConversationStates.QUEST_STARTED, ConversationPhrases.YES_MESSAGES, ! new QuestInStateCondition(QUEST_SLOT, 0, "guess1"), ConversationStates.QUESTION_1, null, getSavedCreature); npc.add(ConversationStates.QUEST_STARTED, ConversationPhrases.YES_MESSAGES, ! new QuestInStateCondition(QUEST_SLOT, 0, "guess2"), ConversationStates.QUESTION_2, null, getSavedCreature); npc.add(ConversationStates.QUEST_STARTED, ConversationPhrases.YES_MESSAGES, ! new QuestInStateCondition(QUEST_SLOT, 0, "guess3"), ConversationStates.QUESTION_3, null, --- 238,256 ---- npc.add(ConversationStates.QUEST_STARTED, ConversationPhrases.YES_MESSAGES, ! new QuestInStateCondition(QUEST_SLOT, 0, "1"), ConversationStates.QUESTION_1, null, getSavedCreature); + npc.add(ConversationStates.QUEST_STARTED, ConversationPhrases.YES_MESSAGES, ! new QuestInStateCondition(QUEST_SLOT, 0, "2"), ConversationStates.QUESTION_2, null, getSavedCreature); + npc.add(ConversationStates.QUEST_STARTED, ConversationPhrases.YES_MESSAGES, ! new QuestInStateCondition(QUEST_SLOT, 0, "3"), ConversationStates.QUESTION_3, null, *************** *** 222,227 **** new AndCondition(requirement, new NotCondition(enoughTimePassed), new NotCondition(questNotDone)), ConversationStates.ATTENDING, ! "I've had plenty of fun for now, thanks. Come back some other time.", ! null); //ask quest question if quest accepted, also gets the creature type to ask about --- 287,292 ---- new AndCondition(requirement, new NotCondition(enoughTimePassed), new NotCondition(questNotDone)), ConversationStates.ATTENDING, ! null, ! new SayTimeRemainingAction(QUEST_SLOT, 1, INTERVAL_BETWEEN_TRIES, "I've had plenty of fun for now, thanks. Come back in, lets say")); //ask quest question if quest accepted, also gets the creature type to ask about *************** *** 242,250 **** npc.say("I've been counting how many creatures you have killed, now tell me, how many " + ! CREATURE + "s do you think you've killed? You have three guesses and I'll accept " + "guesses that are close to the correct answer."); } }, ! new SetQuestAction(QUEST_SLOT, 0, "guess1"))); //if quest rejected --- 307,315 ---- npc.say("I've been counting how many creatures you have killed, now tell me, how many " + ! Grammar.plural(CREATURE) + " do you think you've killed? You have three guesses and I'll accept " + "guesses that are close to the correct answer."); } }, ! new SetQuestAction(QUEST_SLOT, 0, "1"))); //if quest rejected *************** *** 263,266 **** --- 328,332 ---- "How could that possibly be an answer? Give me a proper number.", null); + npc.add(ConversationStates.QUESTION_2, "", *************** *** 269,272 **** --- 335,339 ---- "Is that even possible? Give me a valid answer.", null); + npc.add(ConversationStates.QUESTION_3, "", *************** *** 291,297 **** "Stupendous! That is the exact number! Either you're very lucky or you really pay attention.", new MultipleActions( ! new SetQuestAction(QUEST_SLOT, 0, "done"), ! new SetQuestToTimeStampAction(QUEST_SLOT, 1), ! new IncreaseXPAction(EXACT_REWARD))); //if close answer --- 358,364 ---- "Stupendous! That is the exact number! Either you're very lucky or you really pay attention.", new MultipleActions( ! new SetQuestAction(QUEST_SLOT, 0, "done"), ! new SetQuestToTimeStampAction(QUEST_SLOT, 1), ! new IncreaseXPAction(EXACT_REWARD))); //if close answer *************** *** 302,308 **** "Wow, that was pretty close. Well done!", new MultipleActions( ! new SetQuestAction(QUEST_SLOT, 0, "done"), ! new SetQuestToTimeStampAction(QUEST_SLOT, 1), ! new IncreaseXPAction(CLOSE_REWARD))); //if incorrect answer --- 369,375 ---- "Wow, that was pretty close. Well done!", new MultipleActions( ! new SetQuestAction(QUEST_SLOT, 0, "done"), ! new SetQuestToTimeStampAction(QUEST_SLOT, 1), ! new IncreaseXPAction(CLOSE_REWARD))); //if incorrect answer *************** *** 312,316 **** ConversationStates.QUESTION_2, "Nope, that is not even close. Try again.", ! new SetQuestAction(QUEST_SLOT, 0, "guess2")); npc.add(ConversationStates.QUESTION_2, "", --- 379,384 ---- ConversationStates.QUESTION_2, "Nope, that is not even close. Try again.", ! new SetQuestAction(QUEST_SLOT, 0, "2")); ! npc.add(ConversationStates.QUESTION_2, "", *************** *** 318,322 **** ConversationStates.QUESTION_3, "Wrong again. You have one more try.", ! new SetQuestAction(QUEST_SLOT, 0, "guess3")); npc.add(ConversationStates.QUESTION_3, "", --- 386,391 ---- ConversationStates.QUESTION_3, "Wrong again. You have one more try.", ! new SetQuestAction(QUEST_SLOT, 0, "3")); ! npc.add(ConversationStates.QUESTION_3, "", *************** *** 325,339 **** null, new MultipleActions( ! new ChatAction() { ! public void fire(Player player, Sentence sentence, EventRaiser npc) { ! int exactNumber = (player.getSoloKill(CREATURE) + player.getSharedKill(CREATURE)); ! npc.say("Unfortunately that is incorrect. The correct answer is in the region of " ! + (int) Math.max(Math.floor(exactNumber - Math.max(exactNumber * 0.2, 10) + exactNumber * 0.1 * Rand.rand()), 0) ! + " and " + Math.round(exactNumber + Math.max(exactNumber * 0.2, 10) - exactNumber * 0.1 * Rand.rand()) ! + ". Good effort though."); ! } ! }, ! new SetQuestAction(QUEST_SLOT, 0, "done"), ! new SetQuestToTimeStampAction(QUEST_SLOT, 1))); } --- 394,408 ---- null, new MultipleActions( ! new ChatAction() { ! public void fire(Player player, Sentence sentence, EventRaiser npc) { ! int exactNumber = (player.getSoloKill(CREATURE) + player.getSharedKill(CREATURE)); ! npc.say("Unfortunately that is incorrect. The correct answer is in the region of " ! + (int) Math.max(Math.floor(exactNumber - Math.max(exactNumber * 0.2, 10) + exactNumber * 0.1 * Rand.rand()), 0) ! + " and " + Math.round(exactNumber + Math.max(exactNumber * 0.2, 10) - exactNumber * 0.1 * Rand.rand()) ! + ". Good effort though."); ! } ! }, ! new SetQuestAction(QUEST_SLOT, 0, "done"), ! new SetQuestToTimeStampAction(QUEST_SLOT, 1))); } |