Example #1
0
        public static bool RegisterUltimate(IUltimate079 ultimate079)
        {
            if (!Pro079.Singleton.Config.EnableUltimates || Ultimates.Contains(ultimate079))
            {
                return(false);
            }

            Ultimates.Add(ultimate079);
            return(true);
        }
Example #2
0
        public void OnCallCommand(PlayerCallCommandEvent ev)
        {
            if (ev.Command.StartsWith("079"))
            {
                if (!plugin.enable)
                {
                    return;
                }
                if (ev.Player.TeamRole.Role != SMRole.SCP_079)
                {
                    ev.ReturnMessage = plugin.notscp079;
                    return;
                }

                ev.ReturnMessage = plugin.error;
                // this block is pasted from PlayerPrefs https://github.com/probe4aiur/PlayerPreferences/
                MatchCollection collection = new Regex("[^\\s\"\']+|\"([^\"]*)\"|\'([^\']*)\'").Matches(ev.Command);
                string[]        args       = new string[collection.Count - 1];

                for (int i = 1; i < collection.Count; i++)
                {
                    if (collection[i].Value[0] == '\"' && collection[i].Value[collection[i].Value.Length - 1] == '\"')
                    {
                        args[i - 1] = collection[i].Value.Substring(1, collection[i].Value.Length - 2);
                    }
                    else
                    {
                        args[i - 1] = collection[i].Value;
                    }
                }
                // end of the paste thx

                if (args.Length == 0)
                {
                    ev.ReturnMessage = "<color=\"white\">" + Pro079Logic.GetHelp() + "</color>";
                }
                else if (args.Length >= 1)
                {
                    if (args[0] == plugin.tipscmd)
                    {
                        if (!plugin.tips)
                        {
                            ev.ReturnMessage = plugin.disabled;
                            return;
                        }
                        ev.Player.SendConsoleMessage(plugin.tipsMsg.Replace("\\n", "\n"), "white");
                        ev.ReturnMessage = "<Made by RogerFK#3679>";
                        return;
                    }
                    else if (args[0] == plugin.suicidecmd)
                    {
                        if (!plugin.suicide)
                        {
                            ev.ReturnMessage = plugin.disabled;
                            return;
                        }
                        List <Player> PCplayers = PluginManager.Manager.Server.GetPlayers(SMRole.SCP_079);
                        int           pcs       = PCplayers.Count;
                        if (PluginManager.Manager.Server.Round.Stats.SCPAlive + PluginManager.Manager.Server.Round.Stats.Zombies - pcs != 0)
                        {
                            ev.ReturnMessage = plugin.cantsuicide;
                            return;
                        }
                        MEC.Timing.RunCoroutine(Pro079Logic.SixthGen(ev.Player), MEC.Segment.FixedUpdate);
                        return;
                    }
                    if (args[0] == plugin.ultcmd)
                    {
                        if (args.Length == 1)
                        {
                            ev.ReturnMessage = "<color=\"white\">" + Pro079Logic.GetUltimates() + "</color>";
                            return;
                        }
                        if (Pro079.Manager.UltimateCooldown > 0)
                        {
                            plugin.ultdown.Replace("$cd", Pro079.Manager.UltimateCooldown.ToString());
                            return;
                        }
                        IUltimate079 ultimate = Pro079.Manager.GetUltimate(string.Join(" ", args.Skip(1).ToArray()));
                        if (ultimate == null)
                        {
                            ev.ReturnMessage = plugin.ulterror;
                            return;
                        }
                        if (!ev.Player.BypassMode)
                        {
                            if (ev.Player.Scp079Data.Level + 1 < plugin.ultLevel)
                            {
                                ev.ReturnMessage = Pro079.Configs.LowLevel(plugin.ultLevel);
                                return;
                            }
                            if (ev.Player.Scp079Data.AP < ultimate.Cost)
                            {
                                ev.ReturnMessage = Pro079.Configs.LowAP(ultimate.Cost);
                                return;
                            }
                            Pro079.Manager.DrainAP(ev.Player, ultimate.Cost);

                            Pro079.Manager.UltimateCooldown += ultimate.Cooldown;
                        }
                        ev.ReturnMessage = ultimate.TriggerUltimate(args.Skip(1).ToArray(), ev.Player);
                        return;
                    }

                    // When everything else wasn't caught, search for external commands //
                    if (!Pro079.Manager.Commands.TryGetValue(args[0], out ICommand079 CommandHandler))
                    {
                        ev.ReturnMessage = plugin.unknowncmd;
                        return;
                    }
                    if (!ev.Player.BypassMode)
                    {
                        if (ev.Player.Scp079Data.Level + 1 < CommandHandler.MinLevel)
                        {
                            ev.ReturnMessage = Pro079.Configs.LowLevel(CommandHandler.MinLevel);
                            return;
                        }
                        else if (ev.Player.Scp079Data.AP < CommandHandler.APCost)
                        {
                            ev.ReturnMessage = Pro079.Configs.LowAP(CommandHandler.APCost);
                            return;
                        }
                        int cooldown = CommandHandler.CurrentCooldown - PluginManager.Manager.Server.Round.Duration;
                        if (cooldown > 0)
                        {
                            ev.ReturnMessage = Pro079.Configs.CmdOnCooldown(cooldown);
                            return;
                        }
                        if (CommandHandler.Cassie)
                        {
                            if (Pro079.Manager.CassieCooldown > 0)
                            {
                                ev.ReturnMessage = plugin.cassieOnCooldown.Replace("$cd", Pro079.Manager.CassieCooldown.ToString()).Replace("$(cd)", Pro079.Manager.CassieCooldown.ToString());
                                return;
                            }
                        }
                    }
                    // A try-catch statement in case any command malfunctions.
                    try
                    {
                        CommandOutput output = new CommandOutput(true, true, true, false);
                        ev.ReturnMessage = CommandHandler.CallCommand(args.Skip(1).ToArray(), ev.Player, output);
                        // Drains the AP and sets it on cooldown if the command wasn't set on cooldown before (a.k.a. if you didn't do it manually)
                        // You should only change the value of Success if your command needs more argument the user didn't insert. If there's any bug, it's your fault.
                        if (!ev.Player.BypassMode && output.Success)
                        {
                            if (output.DrainAp)
                            {
                                Pro079.Manager.DrainAP(ev.Player, CommandHandler.APCost);
                            }

                            if (CommandHandler.CurrentCooldown < PluginManager.Manager.Server.Round.Duration)
                            {
                                Pro079.Manager.SetOnCooldown(CommandHandler);
                            }

                            if (CommandHandler.Cassie && output.CassieCooldown)
                            {
                                Pro079.Manager.CassieCooldown = plugin.cassieCooldown;
                                if (!string.IsNullOrEmpty(plugin.cassieready))
                                {
                                    int p = (int)System.Environment.OSVersion.Platform;
                                    if ((p == 4) || (p == 6) || (p == 128))
                                    {
                                        MEC.Timing.RunCoroutine(Pro079Logic.CooldownCassie(plugin.cassieCooldown), MEC.Segment.Update);
                                    }
                                    else
                                    {
                                        MEC.Timing.RunCoroutine(Pro079Logic.CooldownCassie(plugin.cassieCooldown), 1);
                                    }
                                }
                            }
                        }
                        if (!output.CustomReturnColor)
                        {
                            ev.ReturnMessage = $"<color=\"{(output.Success ? "#30e330" : "red")}\">" + ev.ReturnMessage + "</color>";
                        }
                    }
                    catch (Exception e)
                    {
                        plugin.Error($"Error with command \"{args[0]}\" and literally not my problem:\n" + e.ToString());
                        ev.ReturnMessage = plugin.error + ": " + e.Message;
                    }
                }
            }
        }
Example #3
0
        public bool Execute(ArraySegment <string> arguments, ICommandSender sender, out string response)
        {
            Player ply = Player.Get((sender as CommandSender)?.SenderId);

            if (!ply.IsScp079())
            {
                response = Pro079.Singleton.Translations.NotScp079;
                return(false);
            }

            response = Methods.GetHelp();
            if (arguments.Count == 0)
            {
                return(false);
            }

            ICommand079 command = Methods.GetCommand(arguments.At(0));

            if (command != null)
            {
                if (Pro079.Singleton.Config.EnableCassieCooldown && ply.OnCassieCooldown())
                {
                    response = Pro079.Singleton.Translations.CassieOnCooldown;
                    return(false);
                }

                if (ply.OnCommandCooldown(command))
                {
                    response = Pro079.Singleton.Translations.Cooldown;
                    return(false);
                }

                if (!ply.IsBypassModeEnabled)
                {
                    if (command.Cost > ply.Energy)
                    {
                        response = Pro079.Singleton.Translations.LowEnergy;
                        return(false);
                    }

                    if (command.MinLevel > ply.Level)
                    {
                        response = Pro079.Singleton.Translations.LowLevel;
                        return(false);
                    }
                }

                bool success = command.Execute(arguments, sender, out response);
                if (!success)
                {
                    return(false);
                }

                Manager.CoroutineHandles.Add(Timing.RunCoroutine(Manager.SetOnCooldown(ply, command)));
                if (Pro079.Singleton.Config.EnableCassieCooldown)
                {
                    Manager.CassieCooldowns[ply] =
                        DateTime.Now + TimeSpan.FromSeconds(Pro079.Singleton.Config.CassieCooldown);
                }
                if (!ply.IsBypassModeEnabled)
                {
                    ply.Energy -= command.Cost;
                }

                return(true);
            }

            if (arguments.At(0) == Pro079.Singleton.Translations.UltCmd)
            {
                if (arguments.Count < 2)
                {
                    response = Methods.FormatUltimates();
                    return(true);
                }

                IUltimate079 ultimate = Methods.GetUltimate(arguments.At(1));
                if (ultimate == null)
                {
                    return(true);
                }

                if (ply.OnUltimateCooldown())
                {
                    response = Pro079.Singleton.Translations.Cooldown;
                    return(false);
                }

                if (!ply.IsBypassModeEnabled)
                {
                    if (ply.Energy < ultimate.Cost)
                    {
                        response = Pro079.Singleton.Translations.LowEnergy;
                        return(false);
                    }

                    if (ply.Level < Pro079.Singleton.Config.UltimateLevel)
                    {
                        response = Pro079.Singleton.Translations.LowLevel;
                        return(false);
                    }
                }

                bool success = ultimate.Execute(arguments, sender, out response);

                if (!success)
                {
                    return(false);
                }

                Manager.UltimateCooldowns[ply] = DateTime.Now + TimeSpan.FromSeconds(ultimate.Cooldown);
                if (!ply.IsBypassModeEnabled)
                {
                    ply.Energy -= ultimate.Cost;
                }

                return(true);
            }

            return(true);
        }