From: Miguel A. B. L. <ari...@us...> - 2005-10-22 17:45:22
|
Update of /cvsroot/arianne/stendhal/src/games/stendhal/server/entity/npc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3978/src/games/stendhal/server/entity/npc Modified Files: WeaponSellerNPC.java Log Message: Fixed some bugs and implemented some requested features. Index: WeaponSellerNPC.java =================================================================== RCS file: /cvsroot/arianne/stendhal/src/games/stendhal/server/entity/npc/WeaponSellerNPC.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** WeaponSellerNPC.java 11 Sep 2005 11:18:44 -0000 1.6 --- WeaponSellerNPC.java 22 Oct 2005 17:45:13 -0000 1.7 *************** *** 14,22 **** import games.stendhal.server.entity.Player; - import games.stendhal.server.entity.item.Item; import games.stendhal.server.rule.defaultruleset.DefaultItem; import marauroa.common.Log4J; - import marauroa.common.game.AttributeNotFoundException; - import marauroa.common.game.IRPZone; import org.apache.log4j.Logger; --- 14,22 ---- import games.stendhal.server.entity.Player; import games.stendhal.server.rule.defaultruleset.DefaultItem; + import games.stendhal.server.entity.item.*; + import marauroa.common.game.*; + import java.util.*; import marauroa.common.Log4J; import org.apache.log4j.Logger; *************** *** 43,96 **** } private boolean sell(Player player, String itemName) ! { // find item in stock list SellableItem[] items = SellableItem.values(); String uppercaseItemName = itemName.toUpperCase(); for (SellableItem itemEnum : items) - { - if (itemEnum.name().equals(uppercaseItemName)) { // found it Item item = itemEnum.getItem(); ! // has the player already one of these items? ! if (!player.hasItem(item.getPossibleSlots(), item.getItemClass())) ! { ! if (player.getXP() < itemEnum.getPrice()) { ! say("A real pity! You don't have enough XP!"); ! return false; } - logger.debug("Selling a "+itemName+" to player "+player.getName()); - - Item theItem = (Item) item; - theItem.put("zoneid",player.get("zoneid")); - IRPZone zone=world.getRPZone(getID()); - zone.assignRPObjectID(theItem); ! if (player.equip(item)) { ! player.setXP(player.getXP()-itemEnum.getPrice()); ! world.modify(player); ! say("Congratulations! Here is your "+itemName+"!"); ! return true; } ! else { ! say("Sorry, but you cannot equip the "+itemName+"."); } ! } ! else ! { ! say("you already have a "+item.getItemClass()+". One is enough for you."); ! } // item found, but player cannot equip the item return false; } - } // item not found return false; ! } public boolean chat(Player player) throws AttributeNotFoundException --- 43,143 ---- } + private int playermoney(Player player) + { + int money=0; + + Iterator<RPSlot> it=player.slotsIterator(); + while(it.hasNext()) + { + RPSlot slot=(RPSlot)it.next(); + for(RPObject object: slot) + { + if(object instanceof Money) + { + money+=((Money)object).getQuantity(); + } + } + } + + return money; + } + + private boolean chargePlayer(Player player, int amount) + { + int left=amount; + + Iterator<RPSlot> it=player.slotsIterator(); + while(it.hasNext() && left!=0) + { + RPSlot slot=(RPSlot)it.next(); + for(RPObject object: slot) + { + if(object instanceof Money) + { + int quantity=((Money)object).getQuantity(); + if(left>=quantity) + { + slot.remove(object.getID()); + left-=quantity; + } + else + { + ((Money)object).setQuantity(quantity-left); + left=0; + break; + } + } + } + } + + world.modify(player); + + return left==0; + } + private boolean sell(Player player, String itemName) ! { // find item in stock list SellableItem[] items = SellableItem.values(); String uppercaseItemName = itemName.toUpperCase(); for (SellableItem itemEnum : items) { + if (itemEnum.name().equals(uppercaseItemName)) + { // found it Item item = itemEnum.getItem(); ! ! if (playermoney(player) < itemEnum.getSellPrice()) { ! say("A real pity! You don't have enough money!"); ! return false; } ! logger.debug("Selling a "+itemName+" to player "+player.getName()); ! ! Item theItem = (Item) item; ! theItem.put("zoneid",player.get("zoneid")); ! IRPZone zone=world.getRPZone(getID()); ! zone.assignRPObjectID(theItem); ! ! if(player.equip(item)) { ! chargePlayer(player,itemEnum.getSellPrice()); ! say("Congratulations! Here is your "+itemName+"!"); ! return true; } ! else { ! say("Sorry, but you cannot equip the "+itemName+"."); } ! // item found, but player cannot equip the item return false; + } } // item not found return false; ! } public boolean chat(Player player) throws AttributeNotFoundException *************** *** 99,103 **** if(text.contains("offer")) { ! say("You pay equipment with XP points: a club(1000), an armor(5000), a shield(10000) and a sword(20000)."); return true; } --- 146,159 ---- if(text.contains("offer")) { ! // Build the offer dinamically ! StringBuffer st=new StringBuffer("I can offer you: "); ! ! for(SellableItem item: SellableItem.values()) ! { ! st.append("a "+item); ! st.append("("+item.getSellPrice()+"),"); ! } ! ! say(st.toString()); return true; } *************** *** 154,174 **** private enum SellableItem { ! CLUB (1000 ,DefaultItem.CLUB.getItem()), ! ARMOR (5000 ,DefaultItem.ARMOR.getItem()), ! SHIELD(10000,DefaultItem.SHIELD.getItem()), ! SWORD (20000,DefaultItem.SWORD.getItem()); ! private int price; private Item item; ! private SellableItem(int price, Item item) { ! this.price = price; this.item = item; } ! public int getPrice() { ! return price; } --- 210,238 ---- private enum SellableItem { ! ! CLUB (10 ,3 ,DefaultItem.CLUB.getItem()), ! ARMOR (50 ,15 ,DefaultItem.ARMOR.getItem()), ! SHIELD(100,30 ,DefaultItem.SHIELD.getItem()), ! SWORD (200,60 ,DefaultItem.SWORD.getItem()); ! private int sellPrice; ! private int buyPrice; private Item item; ! private SellableItem(int sellPrice, int buyPrice, Item item) { ! this.sellPrice = sellPrice; ! this.buyPrice = buyPrice; this.item = item; } ! public int getSellPrice() { ! return sellPrice; ! } ! ! public int getBuyPrice() ! { ! return buyPrice; } |