/
area/
classes/net/sourceforge/pain/logic/
classes/net/sourceforge/pain/logic/event/
classes/net/sourceforge/pain/logic/fn/util/
classes/net/sourceforge/pain/network/console/
classes/net/sourceforge/pain/plugin/
classes/net/sourceforge/pain/plugin/reset/
classes/net/sourceforge/pain/plugin/shutdown/
classes/net/sourceforge/pain/plugin/social/
classest/net/sourceforge/pain/db/data/
doc/
doc/paindb/resources/
src/net/sourceforge/pain/logic/
src/net/sourceforge/pain/logic/event/
src/net/sourceforge/pain/logic/fn/util/
src/net/sourceforge/pain/network/console/
src/net/sourceforge/pain/network/console/telnet/
src/net/sourceforge/pain/plugin/
src/net/sourceforge/pain/plugin/command/
src/net/sourceforge/pain/plugin/reset/
src/net/sourceforge/pain/plugin/shutdown/
src/net/sourceforge/pain/plugin/social/
src/net/sourceforge/pain/util/
tests/
tests/net/sourceforge/pain/db/data/
package net.sourceforge.pain.logic.event.console.command.builder;

import net.sourceforge.pain.network.console.*;
import net.sourceforge.pain.data.prototype.*;
import net.sourceforge.pain.data.type.*;
import net.sourceforge.pain.logic.fn.*;
import net.sourceforge.pain.logic.fn.util.*;
import net.sourceforge.pain.*;
import net.sourceforge.pain.util.rom.*;
import net.sourceforge.pain.util.*;

/**
 * PAiN  Date: 05.06.2003  Time: 1:40:02
 */
public final class BC_Spacestat extends BuilderCommand {

	public void processBuilderCommand(BuilderShell p, String args) throws Exception {
		final Console console = p.console;
		final IndexedSpace is;
		final Space space;
		if (args != null) {
			is = Core.getWorld().getIndexedSpacesRegistry().getSpace(args);
			if (is == null) {
				MessageOutFn.outln(p.console, "No indexed space found:" + args);
				return;
			}
			space = is.asSpace();
		} else {
			Located l = console.getPlayer().asLocated();
			space = l.getLocation();
			is = (IndexedSpace) space.getRole(IndexedSpace.class);
		}
		MessageOutFn.outln(console, "Space Id:{W" + (is == null ? " NONE" : is.getSpaceUniqueId()) + "{x");
		MessageOutFn.outln(console, "Space :{Y" + space.getName() + "{x");
		MessageOutFn.outln(console, "Detailed desc:{C<<{x" + space.getDesc() + "{C>>{x");
		MessageOutFn.outln(console, "Capacity:{C" + space.getCapacity() + "{x");
		// exits
		LinkedSpace link = (LinkedSpace) space.getRole(LinkedSpace.class);
		if (link != null) {
			MessageOutFn.outln(console, "Exits info:");
			int nExists = 0;
			for (int i = LinkedSpace.FIRST_DIR; i <= LinkedSpace.LAST_DIR; i++) {
				Exit exit = link.getExit(i);
				if (exit != null) {
					nExists++;
					Space targetSpace = exit.getTargetSpace();
					if (targetSpace == null) {
						MessageOutFn.outln(console, "{R BUG:exit has no target space:" + LangUtil.exitName[i] + "{x");
					} else {
						MessageOutFn.outln(console, LangUtil.exitName[i] + ":" + targetSpace.getName());
					}
				}
			}
			if (nExists == 0) {
				MessageOutFn.outln(console, "No exists found");
			}

		} else {
			MessageOutFn.outln(console, "Space has not exits");
		}
		// in space:
		MessageOutFn.outln(console, "Content:");
		for (Located obj = space.getFirstInSpace(); obj != null; obj = obj.getNextInSpace()) {
			if (obj.is(Physical.class)) {
				final Interactive inter = ((Interactive) obj.getRole(Interactive.class));
				MessageOutFn.outln(console, "\tPhysical:" + inter.getName() + " target list:"+ TargetList.string(inter.getTargetList()));
			} else if (obj.is(Interactive.class)) {
				Interactive inter = (Interactive) obj.getRole(Interactive.class);
				MessageOutFn.outln(console, "\tInteractive:" + inter.getName() + " target list:"+ TargetList.string(inter.getTargetList()));
			} else if (obj.is(SpaceReset.class)) {
				PrototypeInfo proto = ((Reset) obj.getRole(Reset.class)).getResettedPrototype();
				if (proto != null) {
					MessageOutFn.outln(console, "\tResetted prototype:" + proto.getVnum() + " name:" + proto.getName());
				} else {
					MessageOutFn.outln(console, "{\t{R WARN:{x reset with no prototype!");
				}
			} else {
				MessageOutFn.outln(console, "\t" + obj.getOid());//todo
			}
		}

	}

	public void showHelp(Console console) {
		MessageOutFn.outln(console, "Builder command STAT shows various stats of the current space");
		MessageOutFn.outln(console, "Usage: stat");
	}

}