Beispiel #1
0
        static void BotHandler(Player player, Command cmd)
        {
            if (!player.ClassiCube || !Heartbeat.ClassiCube())
            {
                player.Message("Bots can only be used on ClassiCube servers and clients!");
                return;
            }
            string option = cmd.Next(); //take in the option arg
            if (string.IsNullOrEmpty(option)) //empty? return, otherwise continue
            {
                CdBot.PrintUsage(player);
                return;
            }

            //certain options that take in specific params are in here, the rest are in the switch-case
            if (option.ToLower() == "list")
            {
                player.Message("_Bots on {0}_", ConfigKey.ServerName.GetString());
                foreach (Bot botCheck in Server.Bots)
                {
                    player.Message(botCheck.Name + " on " + botCheck.World.Name);
                }
                return;
            }
            else if (option.ToLower() == "removeall")
            {
                Server.Bots.ForEach(botToRemove =>
                {
                    botToRemove.removeBot();
                });
                player.Message("All bots removed from the server.");
                return;
            }
            else if (option.ToLower() == "move")
            {
                string targetBot = cmd.Next();
                if (string.IsNullOrEmpty(targetBot))
                {
                    CdBot.PrintUsage(player);
                    return;
                }
                string targetPlayer = cmd.Next();
                if (string.IsNullOrEmpty(targetPlayer))
                {
                    CdBot.PrintUsage(player);
                    return;
                }

                Bot targetB = player.World.FindBot(targetBot);
                Player targetP = player.World.FindPlayerExact(targetPlayer);

                if (targetP == null)
                {
                    player.Message("Could not find {0} on {1}! Please make sure you spelled their name correctly.", targetPlayer, player.World);
                    return;
                }
                if (targetB == null)
                {
                    player.Message("Could not find {0} on {1}! Please make sure you spelled their name correctly.", targetBot, player.World);
                    return;
                }

                player.Message("{0} is now moving!", targetB.Name);
                targetB.isMoving = true;
                targetB.NewPosition = targetP.Position;
                targetB.OldPosition = targetB.Position;
                targetB.timeCheck.Start();
                return;
            }
            else if (option.ToLower() == "follow")
            {
                string targetBot = cmd.Next();
                if (string.IsNullOrEmpty(targetBot))
                {
                    CdBot.PrintUsage(player);
                    return;
                }
                string targetPlayer = cmd.Next();
                if (string.IsNullOrEmpty(targetPlayer))
                {
                    CdBot.PrintUsage(player);
                    return;
                }

                Bot targetB = player.World.FindBot(targetBot);
                Player targetP = player.World.FindPlayerExact(targetPlayer);

                if (targetP == null)
                {
                    player.Message("Could not find {0} on {1}! Please make sure you spelled their name correctly.", targetPlayer, player.World);
                    return;
                }
                if (targetB == null)
                {
                    player.Message("Could not find {0} on {1}! Please make sure you spelled their name correctly.", targetBot, player.World);
                    return;
                }

                player.Message("{0} is now following {1}!", targetB.Name, targetP.Name);
                targetB.isMoving = true;
                targetB.followTarget = targetP;
                targetB.OldPosition = targetB.Position;
                targetB.timeCheck.Start();
                return;
            }

            //finally away from the special cases
            string botName = cmd.Next(); //take in bot name arg
            if (string.IsNullOrEmpty(botName)) //null check
            {
                CdBot.PrintUsage(player);
                return;
            }

            Bot bot = new Bot();
            if (option != "create")//since the bot wouldn't exist for "create", we must check the bot for all cases other than "create"
            {
                bot = Server.FindBot(botName.ToLower()); //Find the bot and assign to bot var

                if (bot == null) //If null, return and yell at user
                {
                    player.Message("Could not find {0}! Please make sure you spelled the bot's name correctly. To view all the bots, type /Bot list.", botName);
                    return;
                }
            }

            //now to the cases - additional args should be taken in at the individual cases
            switch (option.ToLower())
            {
                case "create":
                    string requestedModel = cmd.Next();
                    if (string.IsNullOrEmpty(requestedModel))
                    {
                        player.Message("Usage is /Bot create <bot name> <bot model>. Valid models are chicken, creeper, croc, human, pig, printer, sheep, skeleton, spider, or zombie.");
                        return;
                    }

                    if (!validEntities.Contains(requestedModel))
                    {
                        player.Message("That wasn't a valid bot model! Valid models are chicken, creeper, croc, human, pig, printer, sheep, skeleton, spider, or zombie.");
                        return;
                    }

                    //if a botname has already been chosen, ask player for a new name
                    var matchingNames = from b in Server.Bots
                                   where b.Name.ToLower() == botName.ToLower()
                                   select b;

                    if (matchingNames.Count() > 0)
                    {
                        player.Message("A bot with that name already exists! To view all bots, type /bot list.");
                        return;
                    }

                    player.Message("Successfully created a bot.");
                    Bot botCreate = new Bot();
                    botCreate.setBot(botName, player.World, player.Position, LegendCraft.getNewID());
                    botCreate.createBot();
                    botCreate.changeBotModel(requestedModel);
                    break;
                case "remove":
                    player.Message("{0} was removed from the server.", bot.Name);
                    bot.removeBot();
                    break;
                case "fly":

                    if (bot.isFlying)
                    {
                        player.Message("{0} can no longer fly.", bot.Name);
                        bot.isFlying = false;
                        break;
                    }

                    player.Message("{0} can now fly!", bot.Name);
                    bot.isFlying = true;
                    break;
                case "model":

                    if (bot.Skin != "steve")
                    {
                        player.Message("Bots cannot change model with a skin! Use '/bot clone' to reset a bot's skin.");
                        return;
                    }

                    string model = cmd.Next();
                    if (string.IsNullOrEmpty(model))
                    {
                        player.Message("Usage is /Bot model <bot> <model>. Valid models are chicken, creeper, croc, human, pig, printer, sheep, skeleton, spider, or zombie.");
                        break;
                    }

                    if(model == "human")//lazy parse
                    {
                        model = "humanoid";
                    }
                    if (!validEntities.Contains(model))
                    {
                        player.Message("Please use a valid model name! Valid models are chicken, creeper, croc, human, pig, printer, sheep, skeleton, spider, or zombie.");
                        break;
                    }

                    player.Message("Changed bot model to {0}.", model);
                    bot.changeBotModel(model);

                    break;
                case "clone":

                    if (bot.Model != "humanoid")
                    {
                        player.Message("A bot must be a human in order to have a skin. Use '/bot model <bot> <model>' to change a bot's model.");
                        return;
                    }

                    string playerToClone = cmd.Next();
                    if (string.IsNullOrEmpty(playerToClone))
                    {
                        player.Message("{0}'s skin was reset!", bot.Name);
                        bot.Clone("steve");
                        break;
                    }
                    PlayerInfo targetPlayer = PlayerDB.FindPlayerInfoExact(playerToClone);
                    if (targetPlayer == null)
                    {
                        player.Message("That player doesn't exists! Please use a valid playername for the skin of the bot.");
                        break;
                    }

                    player.Message("{0}'s skin was updated!", bot.Name);
                    bot.Clone(playerToClone);
                    break;
                case "explode":

                    Server.Message("{0} exploded!", bot.Name);
                    bot.explodeBot(player);
                    break;
                case "summon":

                    if (player.World != bot.World)
                    {
                        bot.tempRemoveBot(); //remove the entity
                        bot.World = player.World; //update variables
                        bot.Position = player.Position;
                        bot.updateBotPosition(); //replace the entity
                    }
                    else
                    {
                        bot.Position = player.Position;
                        bot.teleportBot(player.Position);
                    }

                    if (bot.Model != "human")
                    {
                        bot.changeBotModel(bot.Model); //replace the model, if the model is set
                    }
                    if (bot.Skin != "steve")
                    {
                        bot.Clone(bot.Skin); //replace the skin, if a skin is set
                    }
                    break;
                case "stop":

                    player.Message("{0} is no longer moving.", bot.Name);
                    bot.isMoving = false;
                    bot.timeCheck.Stop();
                    bot.timeCheck.Reset();
                    bot.followTarget = null;
                    break;
                default:
                    CdBot.PrintUsage(player);
                    break;
            }
        }