From: Kimmo R. <ki...@us...> - 2009-11-18 14:55:47
|
Update of /cvsroot/arianne/stendhal/src/games/stendhal/server/maps/semos/tavern/market In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv30487/src/games/stendhal/server/maps/semos/tavern/market Modified Files: PrepareOfferChatAction.java Log Message: Enhanced handling of mallformed selling sentences. fixes [2896838] "[Stendhal trading] Exception when no price specified" Index: PrepareOfferChatAction.java =================================================================== RCS file: /cvsroot/arianne/stendhal/src/games/stendhal/server/maps/semos/tavern/market/PrepareOfferChatAction.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** PrepareOfferChatAction.java 18 Nov 2009 12:32:06 -0000 1.5 --- PrepareOfferChatAction.java 18 Nov 2009 14:55:37 -0000 1.6 *************** *** 28,54 **** private void handleSentence(Player player, Sentence sentence, SpeakerNPC npc) { ! try { ! if(TradingUtility.isPlayerWithinOfferLimit(player)) { ! String itemName = determineItemName(sentence); ! int price = determinePrice(sentence); ! Integer fee = Integer.valueOf(TradingUtility.calculateFee(player, price).intValue()); ! if(TradingUtility.canPlayerAffordTradingFee(player, price)) { ! if (createOffer(player, itemName, price)) { ! TradingUtility.substractTradingFee(player, price); ! npc.say("I added your offer to the trading center and took the fee of "+fee.toString()+"."); ! npc.setCurrentState(ConversationStates.ATTENDING); ! return; ! } ! // Needs some feedback for the player return; } ! npc.say("You cannot afford the trading fee of "+fee.toString()); return; } ! npc.say("You may not place more than "+Integer.valueOf(TradingUtility.MAX_NUMBER_OFF_OFFERS).toString()+" offers."); ! } catch (NumberFormatException e) { ! npc.say("I did not understand you. Please say \"sell item price\"."); ! npc.setCurrentState(ConversationStates.ATTENDING); } } --- 28,54 ---- private void handleSentence(Player player, Sentence sentence, SpeakerNPC npc) { ! if(TradingUtility.isPlayerWithinOfferLimit(player)) { ! if (sentence.getExpressions().size() < 3 || sentence.getNumeralCount() != 1) { ! npc.say("I did not understand you. Please say \"sell item price\"."); ! npc.setCurrentState(ConversationStates.ATTENDING); ! return; ! } ! String itemName = determineItemName(sentence); ! int price = determinePrice(sentence); ! Integer fee = Integer.valueOf(TradingUtility.calculateFee(player, price).intValue()); ! if(TradingUtility.canPlayerAffordTradingFee(player, price)) { ! if (createOffer(player, itemName, price)) { ! TradingUtility.substractTradingFee(player, price); ! npc.say("I added your offer to the trading center and took the fee of "+fee.toString()+"."); ! npc.setCurrentState(ConversationStates.ATTENDING); return; } ! // Needs some feedback for the player return; } ! npc.say("You cannot afford the trading fee of "+fee.toString()); ! return; } + npc.say("You may not place more than "+Integer.valueOf(TradingUtility.MAX_NUMBER_OFF_OFFERS).toString()+" offers."); } *************** *** 88,95 **** private int determinePrice(Sentence sentence) { ! Expression expression = sentence.getExpression(2,""); ! String number = expression.getNormalized(); ! return Integer.parseInt(number); } - } --- 88,92 ---- private int determinePrice(Sentence sentence) { ! return sentence.getNumeral().getAmount(); } } |