import misc.Separators; import string.StrUtil; import util.nice.NiceEnumeration; class ShopCreature extends Creature { private Shop theShop = null; ShopCreature(CreatureProto cr) { super(cr); } void bindShop(Shop sh) { theShop = sh; } Shop getShop() { return theShop; } static String oneLine(int ind, int count, Item it, Shop sh) { String c = sh.producesItem(it.getId()) ? StrUtil.rightPad("Ilimitada", 10) : StrUtil.formatNumber(count, 10); return Separators.NL + StrUtil.formatNumber(ind, 6) + " " + c + " " + StrUtil.rightPad(it.getName(), 54) + " " + StrUtil.formatNumber(it.getPrice(sh.getSellTax()), 5); } String getShopList() { String list = ""; NiceEnumeration itEnum = theItems.elements(); if (!itEnum.hasMoreElements()) return list; Shop sh = getShop(); int ind = 1; Item next = null; Item it = (Item) itEnum.nextElement(); do { next = itEnum.hasMoreElements() ? (Item) itEnum.nextElement() : null; int count = 1; while (it.isCloneOf(next)) { ++count; it = next; next = itEnum.hasMoreElements() ? (Item) itEnum.nextElement() : null; } list += oneLine(ind, count, it, sh); ++ind; it = next; } while (it != null); return list; } public String getSheet() { return super.getSheet() + "(Vendedor)"; } }