Пример #1
0
 public override bool processCommand(IStringPrinter printer, string[] options)
 {
     if (options.Length == 0)
     {
         printer.println("Commands: ");
         foreach (Command c in commands)
         {
             printer.println("  " + c.name + " - " + c.getHelp());
         }
         return(true);
     }
     else if (options.Length == 1)
     {
         foreach (Command c in commands)
         {
             if (c.name.Equals(options[0]))
             {
                 printer.println(c.getUsage() + " - " + c.getHelp());
                 return(true);
             }
         }
         throw new NoSuchCommandException(options[0]);
     }
     else
     {
         throw new InvalidNumberOfArgumentsException(options.Length);
     }
 }
Пример #2
0
        public override bool processCommand(IStringPrinter printer, string[] options)
        {
            if (options.Length == 2 || options.Length == 3) {

                if (options[0].Equals("save") || options[0].Equals("s") || options[0].Equals("load") || options[0].Equals("l")) {

                    options[0] = options[0].ToLower();

                    bool forceOverride = false;

                    if (options.Length == 3) {
                        options[2] = options[2].ToLower();
                        if (options[2].Equals("overwrite") || options[2].Equals("o")) {
                            forceOverride = true;
                        } else {
                            throw new InvalidArgumentException(options[2], " \"overwrite\" or \"o\".");
                        }

                    }

                    if(options[0].Equals("save") || options[0].Equals("s")){
                        if (World.save(Game.instance.currentWorld, options[1], forceOverride)) {
                            printer.println((forceOverride ? "World overwritten: " : "World saved as: ") + options[1] + "." + Game.saveExtention);
                        } else {
                            printer.println("Save already exists: \"" + options[1] + "\" please use: /world save " + options[1] + " overwrite");
                        }
                    } else if (options[0].Equals("load") || options[0].Equals("l")) {
                        Game.instance.currentWorld = null;
                        Game.instance.currentWorld = World.load(options[1]);
                        printer.println("World loaded: " + options[1] + "." + Game.saveExtention);
                    }
                } else if (options[0].Equals("new") || options[0].Equals("n")) {
                    int type = toInt(options[1]);
                    int seed = new Random().Next();
                    if(options.Length==3){
                        seed = toInt(options[2]);
                    }
                    Game.instance.currentWorld = null;
                    Game.instance.currentWorld = new World(World.defaultSize, "World");
                    WorldGenerator.Generate(Game.instance.currentWorld, type, seed);
                    Game.instance.currentWorld.player = new EntityPlayer((Game.instance.currentWorld.sizeInTiles.X * World.tileSizeInPixels) / 2, 10);
                    Game.instance.currentWorld.EntityList.Add(Game.instance.currentWorld.player);
                    Game.instance.currentWorld.calculateTileFrames(Game.instance);
                }

                Game.instance.resetUserInputList();

                return true;
            } else {
                throw new InvalidNumberOfArgumentsException(options.Length);
            }
        }
Пример #3
0
        public override bool processCommand(IStringPrinter printer, string[] options)
        {
            if (options.Length == 1 || options.Length == 2 || options.Length == 3) {
                int id = 0;
                int count = 1;
                int data = 0;

                try {
                    id = toInt(options[0]);
                } catch (NumberInvalidException e) {
                    foreach(Item item in Item.ItemList){
                        if(item != null){
                            if (equalsIgnoreCase(item.name, e.s)) {
                                id = item.index;
                                break;
                            }
                        }
                    }
                    if(id == 0){
                        throw new NoSuchItemException(e.s);
                    }
                }

                if(options.Length >= 2){
                    count = toInt(options[1]);
                }

                if (options.Length == 3) {
                    try {
                        data = toInt(options[2]);
                    } catch (NumberInvalidException e) {
                        if (id == Item.itemTile.index) {
                            foreach (Tile tile in Tile.TileList) {
                                if (tile != null) {
                                    if (equalsIgnoreCase(tile.name, e.s)) {
                                        data = tile.index;
                                        break;
                                    }
                                }
                            }
                            if (data == 0) {
                                throw new NoSuchTileException(e.s);
                            }
                        } else {
                            throw e;
                        }
                    }
                }

                if(id != Item.itemEmpty.index){
                    ItemStack stack = new ItemStack(Item.ItemList[id], count, data);
                    printer.println("Gave you "+stack.getDisplayName(false));
                    Game.instance.inventory.pickUp(stack);
                }

                return true;
            } else {
                throw new InvalidNumberOfArgumentsException(options.Length);
            }
        }
Пример #4
0
 public override bool processCommand(IStringPrinter printer, string[] options)
 {
     if (options.Length == 0) {
         printer.println("Commands: ");
         foreach(Command c in commands){
             printer.println("  " + c.name + " - " + c.getHelp());
         }
         return true;
     } else if (options.Length == 1) {
         foreach (Command c in commands) {
             if (c.name.Equals(options[0])) {
                 printer.println(c.getUsage() + " - " + c.getHelp());
                 return true;
             }
         }
         throw new NoSuchCommandException(options[0]);
     } else {
         throw new InvalidNumberOfArgumentsException(options.Length);
     }
 }
Пример #5
0
        public override bool processCommand(IStringPrinter printer, string[] options)
        {
            if (options.Length == 2 || options.Length == 3)
            {
                if (options[0].Equals("save") || options[0].Equals("s") || options[0].Equals("load") || options[0].Equals("l"))
                {
                    options[0] = options[0].ToLower();

                    bool forceOverride = false;

                    if (options.Length == 3)
                    {
                        options[2] = options[2].ToLower();
                        if (options[2].Equals("overwrite") || options[2].Equals("o"))
                        {
                            forceOverride = true;
                        }
                        else
                        {
                            throw new InvalidArgumentException(options[2], " \"overwrite\" or \"o\".");
                        }
                    }

                    if (options[0].Equals("save") || options[0].Equals("s"))
                    {
                        if (World.save(Game.instance.currentWorld, options[1], forceOverride))
                        {
                            printer.println((forceOverride ? "World overwritten: " : "World saved as: ") + options[1] + "." + Game.saveExtention);
                        }
                        else
                        {
                            printer.println("Save already exists: \"" + options[1] + "\" please use: /world save " + options[1] + " overwrite");
                        }
                    }
                    else if (options[0].Equals("load") || options[0].Equals("l"))
                    {
                        Game.instance.currentWorld = null;
                        Game.instance.currentWorld = World.load(options[1]);
                        printer.println("World loaded: " + options[1] + "." + Game.saveExtention);
                    }
                }
                else if (options[0].Equals("new") || options[0].Equals("n"))
                {
                    int type = toInt(options[1]);
                    int seed = new Random().Next();
                    if (options.Length == 3)
                    {
                        seed = toInt(options[2]);
                    }
                    Game.instance.currentWorld = null;
                    Game.instance.currentWorld = new World(World.defaultSize, "World");
                    WorldGenerator.Generate(Game.instance.currentWorld, type, seed);
                    Game.instance.currentWorld.player = new EntityPlayer((Game.instance.currentWorld.sizeInTiles.X * World.tileSizeInPixels) / 2, 10);
                    Game.instance.currentWorld.EntityList.Add(Game.instance.currentWorld.player);
                    Game.instance.currentWorld.calculateTileFrames(Game.instance);
                }

                Game.instance.resetUserInputList();

                return(true);
            }
            else
            {
                throw new InvalidNumberOfArgumentsException(options.Length);
            }
        }
Пример #6
0
        public override bool processCommand(IStringPrinter printer, string[] options)
        {
            if (options.Length == 1 || options.Length == 2 || options.Length == 3)
            {
                int id    = 0;
                int count = 1;
                int data  = 0;

                try {
                    id = toInt(options[0]);
                } catch (NumberInvalidException e) {
                    foreach (Item item in Item.ItemList)
                    {
                        if (item != null)
                        {
                            if (equalsIgnoreCase(item.name, e.s))
                            {
                                id = item.index;
                                break;
                            }
                        }
                    }
                    if (id == 0)
                    {
                        throw new NoSuchItemException(e.s);
                    }
                }

                if (options.Length >= 2)
                {
                    count = toInt(options[1]);
                }

                if (options.Length == 3)
                {
                    try {
                        data = toInt(options[2]);
                    } catch (NumberInvalidException e) {
                        if (id == Item.itemTile.index)
                        {
                            foreach (Tile tile in Tile.TileList)
                            {
                                if (tile != null)
                                {
                                    if (equalsIgnoreCase(tile.name, e.s))
                                    {
                                        data = tile.index;
                                        break;
                                    }
                                }
                            }
                            if (data == 0)
                            {
                                throw new NoSuchTileException(e.s);
                            }
                        }
                        else
                        {
                            throw e;
                        }
                    }
                }

                if (id != Item.itemEmpty.index)
                {
                    ItemStack stack = new ItemStack(Item.ItemList[id], count, data);
                    printer.println("Gave you " + stack.getDisplayName(false));
                    Game.instance.inventory.pickUp(stack);
                }

                return(true);
            }
            else
            {
                throw new InvalidNumberOfArgumentsException(options.Length);
            }
        }