jmud-0.11/
jmud-0.11/bin/
jmud-0.11/doc/
jmud-0.11/rec/
jmud-0.11/rec/mun/
jmud-0.11/rec/mun/grecia/
jmud-0.11/rec/mun/gunnar/
jmud-0.11/rec/qua/
jmud-0.11/src/bool/
jmud-0.11/src/clone/
jmud-0.11/src/integer/
jmud-0.11/src/misc/
jmud-0.11/src/string/
jmud-0.11/src/util/bit/
jmud-0.11/src/util/color/
jmud-0.11/src/util/file/
jmud-0.11/src/util/jgp/adaptor/
jmud-0.11/src/util/jgp/algorithm/
jmud-0.11/src/util/jgp/container/
jmud-0.11/src/util/jgp/functor/
jmud-0.11/src/util/jgp/interfaces/
jmud-0.11/src/util/jgp/predicate/
jmud-0.11/src/util/log/
jmud-0.11/src/util/state/
jmud-0.11/trash/
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) {
	return Separators.NL + StrUtil.formatNumber(ind, 6) + " " + (count == -1 ? StrUtil.rightPad("Ilimitada", 10) : StrUtil.formatNumber(count, 10)) + " " + StrUtil.rightPad(it.getName(), 54) + " " + StrUtil.formatNumber(it.getValue(), 5);
    }

    String getShopList() {
	String list = "";

	NiceEnumeration itEnum = theItems.elements();
	if (!itEnum.hasMoreElements())
	    return list;

	Item prev = (Item) itEnum.nextElement();
	Item it = null;
	int count = /* getShop().producesItem(prev.getId()) ? -1 : */ 1;
	int ind = 1;

	while (itEnum.hasMoreElements()) {
	    it = (Item) itEnum.nextElement();

	    while (getShop().producesItem(prev.getId())) {
		list += oneLine(ind, -1, prev);
		prev = it;
		it = (Item) itEnum.nextElement();
	    }

	    /*
	    if (getShop().producesItem(it.getId())) 
		count = -1;
	    */

	    if (it.isCloneOf(prev))
		++count;
	    else {
		list += oneLine(ind, count, prev);
		count = 1;
		++ind;
	    }

	    prev = it;
	}

	list += oneLine(ind, count, prev);
	
	return list;
    }

    public String getSheet() {
	return super.getSheet() + "(Vendedor)";
    }
}