From: Kimmo R. <ki...@us...> - 2012-09-02 18:44:20
|
Update of /cvsroot/arianne/stendhal/src/games/stendhal/server/entity In directory vz-cvs-4.sog:/tmp/cvs-serv24539/src/games/stendhal/server/entity Modified Files: RPEntity.java Log Message: Take in account items within items in isEquipped() getNumberOfEquipped() and getTotalNumberOf() Index: RPEntity.java =================================================================== RCS file: /cvsroot/arianne/stendhal/src/games/stendhal/server/entity/RPEntity.java,v retrieving revision 1.390 retrieving revision 1.391 diff -C2 -d -r1.390 -r1.391 *** RPEntity.java 29 Aug 2012 21:59:40 -0000 1.390 --- RPEntity.java 2 Sep 2012 18:44:18 -0000 1.391 *************** *** 1848,1860 **** } ! final Item item = (Item) object; ! final String itemName = item.getName(); ! ! if (itemName.equals(name)) { ! found += item.getQuantity(); ! ! if (found >= amount) { ! return true; ! } } } --- 1848,1854 ---- } ! found += getItemCount(name, (Item) object); ! if (found >= amount) { ! return true; } } *************** *** 1892,1899 **** for (final RPObject object : slot) { if (object instanceof Item) { ! final Item item = (Item) object; ! if (item.getName().equals(name)) { ! result += item.getQuantity(); ! } } } --- 1886,1890 ---- for (final RPObject object : slot) { if (object instanceof Item) { ! result += getItemCount(name, (Item) object); } } *************** *** 1903,1906 **** --- 1894,1921 ---- } + /** + * Get count of items of a given name, including items in the slots of + * items. The count is started from topItem, and topItem is included in the + * count, if applicable. + * + * @param name name of items to be counted + * @param topItem item where to start the recursive count + * @return count of items of the given name + */ + private int getItemCount(String name, Item topItem) { + int count = 0; + if (topItem.getName().equals(name)) { + count += topItem.getQuantity(); + } + for (RPSlot slot : topItem.slots()) { + for (RPObject obj : slot) { + if (obj instanceof Item) { + count += getItemCount(name, (Item) obj); + } + } + } + + return count; + } /** *************** *** 1918,1925 **** for (final RPObject object : slot) { if (object instanceof Item) { ! final Item item = (Item) object; ! if (item.getName().equals(name)) { ! result += item.getQuantity(); ! } } } --- 1933,1937 ---- for (final RPObject object : slot) { if (object instanceof Item) { ! result += getItemCount(name, (Item) object); } } |