예제 #1
0
        /// <summary>
        /// Possibly broken, hasn't been tested, don't consider reliable. Creates a linear weight pick emitted from a weight value, for example, a weight of 4 between 1 and 10 would mean you are most likely to get 4, and the chances lowering going in either direction of the number line.
        /// </summary>
        /// <param name="min"></param>
        /// <param name="max"></param>
        /// <param name="weight">The weight emitter</param>
        /// <returns></returns>
        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
        /// <summary>
        /// Broken do not use
        /// </summary>
        /// <param name="min"></param>
        /// <param name="max"></param>
        /// <param name="weight"></param>
        /// <param name="increment"></param>
        /// <returns></returns>
        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);
            }
        }
예제 #3
0
 private void DoSteal()
 {
     if (Player.inst.PlayerLandmassOwner.Gold > stealAmount)
     {
         Player.inst.PlayerLandmassOwner.Gold -= stealAmount;
         AmountStolen += stealAmount;
     }
     else
     {
         AmountStolen += Player.inst.PlayerLandmassOwner.Gold;
         Player.inst.PlayerLandmassOwner.Gold = 0;
     }
     DebugExt.Log("Thief has stolen " + stealAmount.ToString() + " from a treasury. ", false, KingdomLog.LogStatus.Neutral, target.transform.position);
 }
예제 #4
0
        public override void Run()
        {
            base.Run();

            if (!tornadoRunning)
            {
                tornadoRunning = true;
                DebugExt.Log("creating tornado");
                int     landmass = SRand.Range(0, World.inst.NumLandMasses);
                Vector3 pos      = World.inst.cellsToLandmass[landmass].RandomElement().Center;

                tornado = SpawnFreeRoamTornado(pos);
            }
        }