Results 1 to 4 of 4
  1. #1
    toby2449's Avatar
    Join Date
    Jan 2015
    Gender
    male
    Location
    The Ocean
    Posts
    281
    Reputation
    10
    Thanks
    21
    My Mood
    Inspired

    RandomTransition

    I made a Random timed transition. When I spawn the enemy, it picks the same number every time like it was already picked when it was spawned and it would never re pick the number. How would I make it pick a different number every time? Btw the states are strings with an integer within the quotes.

     
    Code:
    #region
    
    using wServer.realm;
    using System;
    
    #endregion
    
    namespace wServer.logic.transitions
    {
        public class RandomTimedTransition : Transition
        {
            //State storage: cooldown timer
    
            private readonly bool randomized;
            private readonly int time;
    
            public RandomTimedTransition(int time, int min, int max, bool randomized = false)
                : base(new Random().Next(min, max).ToString())
            {
                this.time = time;
                this.randomized = randomized;
            }
    
            protected override bool TickCore(Entity host, RealmTime time, ref object state)
            {
                int cool;
                if (state == null) cool = randomized ? Random.Next(this.time) : this.time;
                else cool = (int) state;
    
                bool ret = false;
                if (cool <= 0)
                {
                    ret = true;
                    cool = this.time;
                }
                else
                    cool -= time.thisTickTimes;
    
                state = cool;
                return ret;
            }
        }
    }

  2. #2

  3. #3
    toby2449's Avatar
    Join Date
    Jan 2015
    Gender
    male
    Location
    The Ocean
    Posts
    281
    Reputation
    10
    Thanks
    21
    My Mood
    Inspired
    Quote Originally Posted by cxydsaewq View Post
    As far as I can see you only use the int time and not min / max value?
    The min max are the range of states. If i had 4 states with the string as a number i would put 1-4. The problem is that it decides when wServer initializes. I need it to produce a new number everytime its used.

  4. #4
    toby2449's Avatar
    Join Date
    Jan 2015
    Gender
    male
    Location
    The Ocean
    Posts
    281
    Reputation
    10
    Thanks
    21
    My Mood
    Inspired
    Bump......