Esempio n. 1
0
        private static WaitRandom _getOrCacheFSMWaitRandom(string stateName, string fsmName, GameObject go, int index)
        {
            WaitRandom   outVal = null;
            PlayMakerFSM myFsm  = _getOrCacheFSM(fsmName, go);

            if (index < 0)
            {
                FsmState myState;
                if (myFsm != null)
                {
                    myState = myFsm.GetState(stateName);
                }
                else
                {
                    return(null);
                }
                if (myState != null)
                {
                    outVal = (WaitRandom)myState.Actions.FirstOrDefault(wRand => wRand is WaitRandom);
                }

                return(outVal);
            }
            else
            {
                return(FsmUtil.GetAction <WaitRandom>(myFsm, stateName, index));
            }
        }
Esempio n. 2
0
 public override bool Initialise()
 {
     Input.RegisterKey(Settings.StartCraftingButton.Value);
     _waitRandom = new WaitRandom(Settings.MinDelay, Settings.MaxDelay);
     Settings.MinDelay.OnValueChanged += (sender, newValue) => _waitRandom = new WaitRandom(newValue, Settings.MaxDelay);
     Settings.MaxDelay.OnValueChanged += (sender, newValue) => _waitRandom = new WaitRandom(Settings.MinDelay, newValue);
     return(true);
 }
Esempio n. 3
0
        public Coroutine(Action action, IYieldBase condition, IPlugin owner, string name = null, bool infinity = true,
                         bool autoStart = true) : this(name, owner)
        {
            Running          = autoStart;
            Started          = DateTime.Now;
            Owner            = owner;
            TimeoutForAction = condition switch
            {
                WaitTime time => time.Milliseconds.ToString(),
                WaitRender render => render.HowManyRenderCountWait.ToString(),
                WaitRandom random => random.Timeout,
                WaitFunction _ => "Function -1",
                         _ => TimeoutForAction
            };

            Action    = action;
            Condition = condition;

            if (infinity)
            {
                IEnumerator CoroutineAction(Action a)
                {
                    yield return(YieldBase.RealWork);

                    while (true)
                    {
                        try
                        {
                            a?.Invoke();
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine($"Coroutine {Name} in {OwnerName} error -> {e}");
                        }

                        Ticks++;
                        yield return(Condition.GetEnumerator());
                    }
                }

                _enumerator = CoroutineAction(action);
            }
            else
            {
                IEnumerator CoroutineAction(Action a)
                {
                    yield return(Condition.GetEnumerator());

                    a?.Invoke();
                    Ticks++;
                }

                _enumerator = CoroutineAction(action);
            }
        }
Esempio n. 4
0
 public WaitRandomData(float waitTimeInverseFactor, WaitRandom cachedWaitRandom)
 {
     WaitTimeInverseFactor = waitTimeInverseFactor;
     this.cachedWaitRandom = cachedWaitRandom;
     CustomGameObject      = cachedWaitRandom.Owner;
     FSMName        = cachedWaitRandom.Fsm.Name;
     FSMStateName   = cachedWaitRandom.State.Name;
     ElementIndex   = -1;
     defaultMaximum = 0;
     defaultMinimum = 0;
 }
Esempio n. 5
0
 public WaitRandomData(float waitTimeInverseFactor, string fsmName, string fsmStateName, int elementIndex = -1,
                       GameObject customGameObject = null)
 {
     CustomGameObject      = customGameObject;
     FSMName               = fsmName;
     FSMStateName          = fsmStateName;
     WaitTimeInverseFactor = waitTimeInverseFactor;
     this.cachedWaitRandom = null;
     this.ElementIndex     = elementIndex;
     defaultMaximum        = 0;
     defaultMinimum        = 0;
 }