예제 #1
0
        /*********
        ** Command Methods
        *********/
        public void SpawnEntity(string command, string[] args)
        {
            if (args.Length == 0 || args[0].Equals("help"))
            {
                Monitor.Log($"Usage: monster_spawn \"Monster Name\" [posX] [posY] [amount]" +
                            $"\n\nUses Farmer's coordinates if none or '{config.FarmerPositionCharacter}' was given." +
                            $"\n\nExample: monster_spawn \"Green Slime\" 32 23 4" +
                            $"\nspawns four Green Slimes at coordinates 32|23" +
                            $"\nuse monster_list for a list of available monster names.", LogLevel.Info);
                return;
            }

            //We need a world to spawn monsters in, duh
            if (Context.IsWorldReady)
            {
                if (args.Length == 0)
                {
                    Monitor.Log("You need to provide at least a Monster name!", LogLevel.Info);
                    return;
                }
                MonsterData.Monster m        = MonsterData.ForName(args[0]);
                Vector2             location = Game1.player.getTileLocation();

                if (m.Equals((MonsterData.Monster)(-1)))
                {
                    Monitor.Log($"There is no Monster with the name {args[0]}", LogLevel.Info);
                    return;
                }


                int amount = 1;

                try {
                    //Determine X tile
                    if (args.Length >= 2)
                    {
                        location.X = int.Parse(args[1].Replace(config.FarmerPositionCharacter.ToString(), location.X.ToString()));
                    }

                    //Determine Y tile
                    if (args.Length >= 3)
                    {
                        location.Y = int.Parse(args[2].Replace(config.FarmerPositionCharacter.ToString(), location.Y.ToString()));
                    }

                    if (args.Length >= 4)
                    {
                        amount = int.Parse(args[3]);
                    }
                } catch (Exception e) {
                    Console.Error.WriteLine(e.Message);
                    Monitor.Log("Invalid Arguments! Type \"monster_spawn help\" for usage help.", LogLevel.Info);
                    return;
                }

                if (m != MonsterData.Monster.Duggy && m != MonsterData.Monster.WildernessGolem)
                {
                    location.X *= Game1.tileSize;
                    location.Y *= Game1.tileSize;
                }

                Spawner.GetInstance().SpawnMonster(m, location, amount);
            }
            else
            {
                Monitor.Log("Load a save first!");
            }
        }