Ejemplo n.º 1
0
        private EffectPattern GetEffectPattern()
        {
            var random = new Random();

            if (_currentPlayingEffect == null)
            {
                _currentPlayingEffect = EffectPatterns.ElementAt(0);
                return(_currentPlayingEffect);
            }

            if (_effectCursor == 0 && IsScanModeEnabled)
            {
                if (_playbackCount > 3 && random.Next(0, 2) == 1)
                {
                    _playbackCount        = 0;
                    _currentPlayingEffect = EffectPatterns.ElementAt(random.Next(0, EffectPatterns.Count));
                }
                else
                {
                    _playbackCount++;
                }
            }

            return(_currentPlayingEffect);
        }
Ejemplo n.º 2
0
        public void TriggerEntityEffectPatternRaw(string patternName, Vector3 initPos, Vector3 initDir, Vector3 initScale, BaseMonoEntity entity, out List <MonoEffect> effects)
        {
            MonoEffectOverride component = entity.GetComponent <MonoEffectOverride>();

            if ((component != null) && component.effectOverrides.ContainsKey(patternName))
            {
                patternName = component.effectOverrides[patternName];
            }
            EffectPattern effectPattern = EffectData.GetEffectPattern(patternName);

            effects = new List <MonoEffect>();
            if (effectPattern.randomOneFromSubs)
            {
                int[] list = new int[effectPattern.subEffects.Length];
                for (int i = 0; i < list.Length; i++)
                {
                    list[i] = i;
                }
                list.Shuffle <int>();
                for (int j = 0; j < list.Length; j++)
                {
                    if (((component == null) || string.IsNullOrEmpty(effectPattern.subEffects[j].predicate)) || component.effectPredicates.Contains(effectPattern.subEffects[j].predicate))
                    {
                        BaseMonoEffect effect = this.CreateEffectInstanceBySubEffectConfig(effectPattern.subEffects[j], initPos, initDir, initScale, entity);
                        if ((effect != null) && (effect is MonoEffect))
                        {
                            effects.Add((MonoEffect)effect);
                            break;
                        }
                    }
                }
            }
            else if (effectPattern.subEffects.Length == 1)
            {
                BaseMonoEffect effect2 = this.CreateEffectInstanceBySubEffectConfig(effectPattern.subEffects[0], initPos, initDir, initScale, entity);
                if ((effect2 != null) && (effect2 is MonoEffect))
                {
                    effects.Add((MonoEffect)effect2);
                }
            }
            else
            {
                for (int k = 0; k < effectPattern.subEffects.Length; k++)
                {
                    if (((component == null) || string.IsNullOrEmpty(effectPattern.subEffects[k].predicate)) || component.effectPredicates.Contains(effectPattern.subEffects[k].predicate))
                    {
                        BaseMonoEffect effect3 = this.CreateEffectInstanceBySubEffectConfig(effectPattern.subEffects[k], initPos, initDir, initScale, entity);
                        if ((effect3 != null) && (effect3 is MonoEffect))
                        {
                            effects.Add((MonoEffect)effect3);
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        /// <inheritdoc />
        public void Play(string vehicleName, EffectPattern effectPattern)
        {
            if (IsDisabled)
            {
                return;
            }

            if (IsThreadAlive())
            {
                KillRunningThread();
            }

            IsPlaying = true;
            Logger.Trace("Playing effect on " + this);
            _colorManager.VehicleName = vehicleName;
            _effectThread             = new Thread(() =>
            {
                try
                {
                    while (IsPlaying)
                    {
                        var pattern    = effectPattern ?? GetEffectPattern();
                        var patternRow = GetPatternRow(pattern);
                        _delay         = CalculateDelay(patternRow);
                        OnEffectTick(patternRow);
                        UpdateEffectCursor(pattern);
                        Thread.Sleep(_delay);
                    }

                    // Fix for multithreading issue "Unknown (1168)" by running the stop effect in the same thread
                    // https://gitter.im/CoraleStudios/Colore/archives/2015/12/02
                    Logger.Trace("Calling OnEffectStop for " + this);
                    OnEffectStop();
                    Logger.Trace("Exited playback loop gracefully");
                }
                catch (ThreadAbortException ex)
                {
                    Logger.Warn("Device thread is being aborted, " + ex.Message, ex);
                }
                catch (ThreadInterruptedException ex)
                {
                    Logger.Warn("Device thread is being interrupted, " + ex.Message, ex);
                }
                catch (Exception ex)
                {
                    Logger.Error("Device thread has stopped working with error: " + ex.Message, ex);
                    _rage.DisplayPluginNotification("~r~plugin thread stopped responding");
                }
            })
            {
                IsBackground = true
            };
            _effectThread.Start();
        }
Ejemplo n.º 4
0
 private void UpdateEffectCursor(EffectPattern pattern)
 {
     if (_effectCursor < pattern.TotalPlaybackRows - 1)
     {
         _effectCursor++;
     }
     else
     {
         _effectCursor = 0;
     }
 }
Ejemplo n.º 5
0
 public static void ReloadFromFile()
 {
     _effectPatternDict = new Dictionary <string, EffectPattern>();
     _effectGroupDict   = new Dictionary <string, EffectPattern[]>();
     string[] effectPatternPathes = GlobalDataManager.metaConfig.effectPatternPathes;
     for (int i = 0; i < effectPatternPathes.Length; i++)
     {
         ConfigEffectPattern pattern = ConfigUtil.LoadConfig <ConfigEffectPattern>(effectPatternPathes[i]);
         if (pattern.patterns != null)
         {
             _effectGroupDict.Add(pattern.groupName, pattern.patterns);
             for (int j = 0; j < pattern.patterns.Length; j++)
             {
                 EffectPattern pattern2 = pattern.patterns[j];
                 _effectPatternDict.Add(pattern2.name, pattern2);
             }
         }
     }
 }
Ejemplo n.º 6
0
        public void Play(string vehicleName, EffectPattern effectPattern)
        {
            var device = GetDevice(effectPattern.SupportedDevice);

            device.Play(vehicleName, effectPattern);
        }
Ejemplo n.º 7
0
 private PatternRow GetPatternRow(EffectPattern effectPattern)
 {
     return(effectPattern.PatternRows.ElementAt(_effectCursor));
 }