Beispiel #1
0
        private bool CanRun(AutoCommand command)
        {
            switch (command.CommandTrigger)
            {
            case Trigger.Disabled:
                return(false);

            case Trigger.OnStart:
                var a = Math.Max(TimeSpan.Parse(command.Interval).TotalSeconds, 60);
                var b = ((ITorchServer)TorchBase.Instance).ElapsedPlayTime;
                if ((a - b.TotalSeconds) <= 1 && (a - b.TotalSeconds > 0))
                {
                    command.RunNow();
                }
                break;

            case Trigger.Vote:
                break;

            case Trigger.Timed:
                return(true);

            case Trigger.Scheduled:
                return(true);

            case Trigger.GridCount:
                return(Tree.Grids.Count >= command.TriggerCount);

            case Trigger.PlayerCount:
                return(MySession.Static.Players.GetOnlinePlayerCount() >= command.TriggerCount);

            case Trigger.SimSpeed:
                return(Math.Min(Sync.ServerSimulationRatio, 1) <= command.TriggerRatio);

            default:
                throw new Exception("f**k it");
            }

            return(false);
        }
Beispiel #2
0
        private bool CanRun(AutoCommand command)
        {
            switch (command.CommandTrigger)
            {
            case Trigger.Disabled:
                return(false);

            case Trigger.OnStart:
                if (command.Completed || MySession.Static?.Ready == false)
                {
                    break;
                }
                command.Completed = true;
                command.RunNow();

                break;

            case Trigger.Vote:
                break;

            case Trigger.Timed:
                return(true);

            case Trigger.Scheduled:
                return(true);

            case Trigger.GridCount:
                var gridCount = MyEntities.GetEntities().OfType <IMyCubeGrid>().Count();
                switch (command.Compare)
                {
                case GreaterThan:
                    return(gridCount > command.TriggerCount);

                case LessThan:
                    return(gridCount < command.TriggerCount);

                case Equal:
                    return(Math.Abs(gridCount - command.TriggerCount) < 1);

                default:
                    throw new Exception("meh");
                }

            case Trigger.PlayerCount:

                if (command.Compare == GreaterThan)
                {
                    return(MySession.Static.Players.GetOnlinePlayerCount() > command.TriggerCount);
                }
                else if (command.Compare == LessThan)
                {
                    return(MySession.Static.Players.GetOnlinePlayerCount() < command.TriggerCount);
                }
                break;

            case Trigger.SimSpeed:
                var commandActive = _simSpeedCheck.TryGetValue(command, out var time);
                switch (command.Compare)
                {
                case GreaterThan:
                    if (commandActive)
                    {
                        if ((DateTime.Now - time).TotalSeconds < command.TriggerCount)
                        {
                            break;
                        }
                        _simSpeedCheck.Remove(command);
                        return(Math.Min(Sync.ServerSimulationRatio, 1) > command.TriggerRatio);
                    }

                    if (Math.Min(Sync.ServerSimulationRatio, 1) < command.TriggerRatio)
                    {
                        break;
                    }
                    _simSpeedCheck.Add(command, DateTime.Now);
                    break;

                case LessThan:
                    if (commandActive)
                    {
                        if ((DateTime.Now - time).TotalSeconds < command.TriggerCount)
                        {
                            break;
                        }
                        _simSpeedCheck.Remove(command);
                        return(Math.Min(Sync.ServerSimulationRatio, 1) < command.TriggerRatio);
                    }

                    if (Math.Min(Sync.ServerSimulationRatio, 1) > command.TriggerRatio)
                    {
                        break;
                    }
                    _simSpeedCheck.Add(command, DateTime.Now);
                    break;

                case Equal:
                    if (commandActive)
                    {
                        if ((DateTime.Now - time).TotalSeconds < command.TriggerCount)
                        {
                            break;
                        }
                        _simSpeedCheck.Remove(command);
                        return(Math.Abs(Sync.ServerSimulationRatio - command.TriggerRatio) <= 0);
                    }

                    if (Math.Abs(Sync.ServerSimulationRatio - command.TriggerRatio) > 0)
                    {
                        break;
                    }
                    _simSpeedCheck.Add(command, DateTime.Now);
                    break;
                }
                break;

            default:
                throw new Exception("f**k it");
            }

            return(false);
        }
Beispiel #3
0
        private bool CanRun(AutoCommand command)
        {
            switch (command.CommandTrigger)
            {
            case Trigger.Disabled:
                return(false);

            case Trigger.OnStart:
                var a = Math.Max(TimeSpan.Parse(command.Interval).TotalSeconds, 60);
                var b = ((ITorchServer)TorchBase.Instance).ElapsedPlayTime;
                if ((a - b.TotalSeconds) <= 1 && (a - b.TotalSeconds > 0))
                {
                    command.RunNow();
                }
                break;

            case Trigger.Vote:
                break;

            case Trigger.Timed:
                return(true);

            case Trigger.Scheduled:
                return(true);

            case Trigger.GridCount:
                var gridCount = MyEntities.GetEntities().OfType <IMyCubeGrid>().Count();
                switch (command.Compare)
                {
                case GreaterThan:
                    return(gridCount > command.TriggerCount);

                case LessThan:
                    return(gridCount < command.TriggerCount);

                case Equal:
                    return(Math.Abs(gridCount - command.TriggerCount) < 1);

                default:
                    throw new Exception("meh");
                }

            case Trigger.PlayerCount:
                switch (command.Compare)
                {
                case GreaterThan:
                    return(MySession.Static.Players.GetOnlinePlayerCount() >= command.TriggerCount);

                case LessThan:
                    return(MySession.Static.Players.GetOnlinePlayerCount() <= command.TriggerCount);

                default:
                    throw new Exception("meh");
                }

            case Trigger.SimSpeed:
                var commandActive = _simSpeedCheck.TryGetValue(command, out var time);
                switch (command.Compare)
                {
                case GreaterThan:
                    if (commandActive)
                    {
                        if ((DateTime.Now - time).TotalSeconds < command.TriggerCount)
                        {
                            break;
                        }
                        _simSpeedCheck.Remove(command);
                        return(Math.Min(Sync.ServerSimulationRatio, 1) > command.TriggerRatio);
                    }

                    if (Math.Min(Sync.ServerSimulationRatio, 1) < command.TriggerRatio)
                    {
                        break;
                    }
                    _simSpeedCheck.Add(command, DateTime.Now);
                    break;

                case LessThan:
                    if (commandActive)
                    {
                        if ((DateTime.Now - time).TotalSeconds < command.TriggerCount)
                        {
                            break;
                        }
                        _simSpeedCheck.Remove(command);
                        return(Math.Min(Sync.ServerSimulationRatio, 1) < command.TriggerRatio);
                    }

                    if (Math.Min(Sync.ServerSimulationRatio, 1) > command.TriggerRatio)
                    {
                        break;
                    }
                    _simSpeedCheck.Add(command, DateTime.Now);
                    break;

                case Equal:
                    if (commandActive)
                    {
                        if ((DateTime.Now - time).TotalSeconds < command.TriggerCount)
                        {
                            break;
                        }
                        _simSpeedCheck.Remove(command);
                        return(Math.Abs(Sync.ServerSimulationRatio - command.TriggerRatio) <= 0);
                    }

                    if (Math.Abs(Sync.ServerSimulationRatio - command.TriggerRatio) > 0)
                    {
                        break;
                    }
                    _simSpeedCheck.Add(command, DateTime.Now);
                    break;
                }
                break;

            default:
                throw new Exception("f**k it");
            }

            return(false);
        }