예제 #1
0
파일: Util.cs 프로젝트: DaDevFox/KCMods
        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);
            }
        }
예제 #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);
        }
예제 #3
0
파일: Util.cs 프로젝트: DaDevFox/KCMods
        //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);
            }
        }
예제 #4
0
파일: Tornado.cs 프로젝트: DaDevFox/KCMods
 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();
 }
예제 #5
0
파일: Tornado.cs 프로젝트: DaDevFox/KCMods
 protected void UpdateParticles()
 {
     if (active)
     {
         //DebugExt.Log("Active", true);
         if (!tornadoParticles.isPlaying)
         {
             DebugExt.Log("Playing particles");
             tornadoParticles.Play();
         }
     }
     else
     {
         if (!tornadoParticles.isStopped)
         {
             tornadoParticles.Stop();
         }
     }
 }
예제 #6
0
파일: Tornado.cs 프로젝트: DaDevFox/KCMods
 protected void BeginDeath()
 {
     active = false;
     DebugExt.Log("Tornado ded", true, KingdomLog.LogStatus.Neutral, transform.position);
     Events.TornadoEvent.OnTornadoDeath(gameObject);
 }