From: Daniel H. <wik...@us...> - 2006-08-29 13:26:35
|
Update of /cvsroot/arianne/stendhal/src/games/stendhal/server/entity/npc In directory sc8-pr-cvs11.sourceforge.net:/tmp/cvs-serv26084/src/games/stendhal/server/entity/npc Modified Files: ProducerBehaviour.java Log Message: made it possible to say "cast 5" so that not all available resources are used up. "cast" still works as before. give more feedback to the player docu Index: ProducerBehaviour.java =================================================================== RCS file: /cvsroot/arianne/stendhal/src/games/stendhal/server/entity/npc/ProducerBehaviour.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ProducerBehaviour.java 29 Aug 2006 01:06:07 -0000 1.1 --- ProducerBehaviour.java 29 Aug 2006 13:26:33 -0000 1.2 *************** *** 10,38 **** import java.util.Set; public class ProducerBehaviour { /** * This slot can have three states: * <ul> ! * <li>unset: if the player has never asked Xoderos to cast iron.</li> * <li>done: if the player's last order has been processed.</li> * <li>number;time: if the player has given an order and has not ! * yet retrieved the iron. number is ! * the number of iron that the player will get, and time is the ! * time when the order was given.</li> * </ul> */ private String questSlot; private String productionActivity; private String productUnit; private String productName; private Map<String, Integer> requiredResources; private int productionTimePerItem; public ProducerBehaviour(String questSlot, String productionActivity, String productUnit, String productName, --- 10,84 ---- import java.util.Set; + /** + * The behaviour of an NPC who is able to produce something for a player + * if the player brings the required resources. Production takes time, + * depending on the amount of ordered products. + * + * @author daniel + */ public class ProducerBehaviour { /** + * To store the current status of a production order, each + * ProducerBehaviour needs to have an exclusive quest slot. + * * This slot can have three states: * <ul> ! * <li>unset: if the player has never asked the NPC to produce ! * anything.</li> * <li>done: if the player's last order has been processed.</li> * <li>number;time: if the player has given an order and has not ! * yet retrieved the product. number is the amount of products ! * that the player will get, and time is the time when the order ! * was given, in milliseconds since the epoch.</li> * </ul> */ private String questSlot; + /** + * The name of the activity, e.g. "build", "forge", "bake" + */ private String productionActivity; + /** + * The unit in which the product is counted, e.g. "bags", "pieces", + * "pounds" + */ private String productUnit; + /** + * The name of the product, e.g. "plate_armor". It must be a valid item + * name. + */ private String productName; + /** + * A mapping which maps the name of each required resource + * (e.g. "iron_ore") to the amount of this resource that is + * required for one unit of the product. + */ private Map<String, Integer> requiredResources; + /** + * The number of seconds required to produce one unit of the product. + */ private int productionTimePerItem; + /** + * Creates a new ProducerBehaviour. + * @param questSlot the slot that is used to store the status + * @param productionActivity the name of the activity, e.g. "build", + * "forge", "bake" + * @param productUnit the unit in which the product is counted, e.g. + * "bags", "pieces", "pounds" + * @param productName the name of the product, e.g. "plate_armor". It + * must be a valid item name. + * @param requiredResources a mapping which maps the name of each required + * resource (e.g. "iron_ore") to the amount of + * this resource that is required for one + * unit of the product. + * @param productionTimePerItem the number of seconds required to produce + * one unit of the product. + */ public ProducerBehaviour(String questSlot, String productionActivity, String productUnit, String productName, *************** *** 67,81 **** } private String getRequiredResourceNamesWithHashes() { - Set<String> requiredResources = getRequiredResources().keySet(); Set<String> requiredResourcesWithHashes = new HashSet<String>(); ! for (String resource: requiredResources) { ! requiredResourcesWithHashes.add("#" + resource); } return SpeakerNPC.enumerateCollection(requiredResourcesWithHashes); } ! public void giveResources(Player player, SpeakerNPC npc) { ! int numberOfProductItems = Integer.MAX_VALUE; for (Map.Entry<String, Integer> entry: getRequiredResources().entrySet()) { int limitationByThisResource = player.getNumberOfEquipped(entry.getKey()) / entry.getValue(); --- 113,139 ---- } + /** + * Gets a nicely formulated string that describes the amounts and names + * of the resources that are required to produce one unit of the product, + * with hashes before the resource names in order to highlight them, + * e.g. "4 #wood, 1 #iron, and 2 #leather". + * @return A string describing the required resources. + */ private String getRequiredResourceNamesWithHashes() { Set<String> requiredResourcesWithHashes = new HashSet<String>(); ! for (Map.Entry<String, Integer> entry: getRequiredResources().entrySet()) { ! requiredResourcesWithHashes.add(entry.getValue() + " #" + entry.getKey()); } return SpeakerNPC.enumerateCollection(requiredResourcesWithHashes); } ! /** ! * ! * @param player ! * @param npc ! * @param maxAmount ! */ ! public void giveResources(Player player, SpeakerNPC npc, int maxAmount) { ! int numberOfProductItems = maxAmount; for (Map.Entry<String, Integer> entry: getRequiredResources().entrySet()) { int limitationByThisResource = player.getNumberOfEquipped(entry.getKey()) / entry.getValue(); *************** *** 87,104 **** + " " + getProductName() ! + " if you bring me " + getRequiredResourceNamesWithHashes() + "."); } else { for (Map.Entry<String, Integer> entry: getRequiredResources().entrySet()) { ! player.drop(entry.getKey(), numberOfProductItems * entry.getValue()); } long timeNow = new Date().getTime(); player.setQuest(questSlot, numberOfProductItems + ";" + timeNow); ! npc.say("OK, but that will take some time. Come back later."); } } ! public void takeProduct(Player player, SpeakerNPC npc) { String orderString = player.getQuest(questSlot); String[] order = orderString.split(";"); --- 145,181 ---- + " " + getProductName() ! + " if you bring me at least " + getRequiredResourceNamesWithHashes() + "."); } else { + Set<String> droppedResources = new HashSet<String>(); for (Map.Entry<String, Integer> entry: getRequiredResources().entrySet()) { ! int amountToDrop = numberOfProductItems * entry.getValue(); ! player.drop(entry.getKey(), amountToDrop); ! droppedResources.add(amountToDrop + " " + entry.getKey()); } long timeNow = new Date().getTime(); player.setQuest(questSlot, numberOfProductItems + ";" + timeNow); ! npc.say("OK, I will " ! + getProductionActivity() ! + " " ! + numberOfProductItems ! + " " ! + getProductName() ! + " from the " ! + SpeakerNPC.enumerateCollection(droppedResources) ! + " that you gave me, but that will take some time. Come back later."); } } ! /** ! * This method is called when the player returns to pick up the finished ! * product. It checks if the NPC is already done with the order. If that ! * is the case, the player is given the product. Otherwise, the NPC ! * asks the player to come back later. ! * @param player The player who wants to fetch the product ! * @param npc The producing NPC ! */ ! public void fetchProduct(Player player, SpeakerNPC npc) { String orderString = player.getQuest(questSlot); String[] order = orderString.split(";"); |