Ejemplo n.º 1
0
        public static int WeightedRandom(int min, int max, int weight = 0)
        {
            List <int> options = new List <int>();

            bool valid = max > min;

            if (valid)
            {
                for (int i = min; i < max; i++)
                {
                    for (int k = 0; k < Math.Abs(i - weight); k++)
                    {
                        options.Add(i);
                    }
                }

                DebugExt.Log(options.ToString(), true);

                return(SRand.Range(0, options.Count));
            }
            else
            {
                return(min);
            }
        }
Ejemplo n.º 2
0
        private void TryRandomTarget()
        {
            Vector3 pos = World.inst.cellsToLandmass[landmass].RandomElement().Center;

            base.target = pos;
            base.UpdateDirectionalVelocity();
            DebugExt.Log("Target: " + target.ToString(), true, KingdomLog.LogStatus.Neutral, target);
        }
Ejemplo n.º 3
0
        //BROKEN
        public static float WeightedRandom(float min, float max, float weight = 0f, float increment = 1f)
        {
            List <float> options = new List <float>();

            bool valid = max > min;


            if (valid)
            {
                DebugExt.Log("1", true);

                float total  = Util.RoundToFactor(max - min, increment);
                int   _break = (int)total + 1;


                for (float i = min; i < max; i += increment)
                {
                    float num = Util.RoundToFactor(-Math.Abs(weight - i) + total, increment);

                    DebugExt.Log("1-2: " + total, true);
                    DebugExt.Log("1-2: " + i, true);
                    DebugExt.Log("1-2: " + -Math.Abs(weight - i), true);

                    int counter = 0;

                    if (num != 0 && num != increment)
                    {
                        for (float k = 0; k < num; k += increment)
                        {
                            options.Add(Util.RoundToFactor(i, increment));
                            counter++;
                            if (counter > _break)
                            {
                                options.Add(Util.RoundToFactor(i, increment));
                                break;
                            }
                        }
                    }
                    else
                    {
                        options.Add(Util.RoundToFactor(i, increment));
                    }

                    DebugExt.Log("1-3: " + num, true);
                }

                DebugExt.Log(options.ToString(), true);

                return(SRand.Range(0, options.Count));
            }
            else
            {
                DebugExt.Log("Invalid arguments: " + min.ToString() + ", " + max.ToString() + ", " + weight.ToString() + ", " + increment.ToString());
                return(min);
            }
        }
Ejemplo n.º 4
0
 public void Start()
 {
     spawnPos = transform.position;
     DebugExt.Log("Tornado Spawn", true, KingdomLog.LogStatus.Neutral, gameObject);
     originalRotationSpeed = rotationSpeed;
     if (gameObject.transform.Find("Base") != null)
     {
         tornadoParticles = gameObject.transform.Find("Base").GetComponent <ParticleSystem>();
     }
     TryRandomDirectionalVelocity();
     UpdateParticles();
 }
Ejemplo n.º 5
0
 protected void UpdateParticles()
 {
     if (active)
     {
         //DebugExt.Log("Active", true);
         if (!tornadoParticles.isPlaying)
         {
             DebugExt.Log("Playing particles");
             tornadoParticles.Play();
         }
     }
     else
     {
         if (!tornadoParticles.isStopped)
         {
             tornadoParticles.Stop();
         }
     }
 }
Ejemplo n.º 6
0
 protected void BeginDeath()
 {
     active = false;
     DebugExt.Log("Tornado ded", true, KingdomLog.LogStatus.Neutral, transform.position);
     Events.TornadoEvent.OnTornadoDeath(gameObject);
 }