Ejemplo n.º 1
0
        public override void Entry(params object[] objects)
        {
            ModConfig = new RngConfig().InitializeConfig(BaseConfigPath);

            RandomFloats = new float[256];
            Twister      = new MersenneTwister();

            //Destroys the game's built-in random number generator for Twister.
            Game1.random = Twister;

            //Just fills the buffer with junk so that we know everything is good and random.
            RandomFloats.FillFloats();

            //Define base randoms
            OneToTen = new List <WeightedGeneric <int> >()
            {
                WeightedGeneric <int> .Create(75, 1), WeightedGeneric <int> .Create(50, 2), WeightedGeneric <int> .Create(25, 3), WeightedGeneric <int> .Create(15, 4), WeightedGeneric <int> .Create(11, 5), WeightedGeneric <int> .Create(9, 6), WeightedGeneric <int> .Create(7, 7), WeightedGeneric <int> .Create(5, 8), WeightedGeneric <int> .Create(3, 9), WeightedGeneric <int> .Create(1, 10)
            };
            Weather = new List <WeightedGeneric <int> >()
            {
                WeightedGeneric <int> .Create(ModConfig.SunnyChance, 0), WeightedGeneric <int> .Create(ModConfig.CloudySnowyChance, 2), WeightedGeneric <int> .Create(ModConfig.RainyChance, 1), WeightedGeneric <int> .Create(ModConfig.StormyChance, 3), WeightedGeneric <int> .Create(ModConfig.HarshSnowyChance, 5)
            };

            /*
             * //Debugging for my randoms
             * while (true)
             * {
             *  List<int> got = new List<int>();
             *  int v = 0;
             *  int gen = 1024;
             *  float genf = gen;
             *  for (int i = 0; i < gen; i++)
             *  {
             *      v = Weighted.ChooseRange(OneToTen, 1, 5).TValue;
             *      got.Add(v);
             *
             *      if (gen <= 1024)
             *          Console.Write(v + ", ");
             *  }
             *  Console.Write("\n");
             *  Console.WriteLine("Generated {0} Randoms", got.Count);
             *  Console.WriteLine("1: {0} | 2: {1} | 3: {2} | 4: {3} | 5: {4} | 6: {5} | 7: {6} | 8: {7} | 9: {8} | 10: {9} | ?: {10}", got.Count(x => x == 1), got.Count(x => x == 2), got.Count(x => x == 3), got.Count(x => x == 4), got.Count(x => x == 5), got.Count(x => x == 6), got.Count(x => x == 7), got.Count(x => x == 8), got.Count(x => x == 9), got.Count(x => x == 10), got.Count(x => x > 10));
             *  Console.WriteLine("{0} | {1} | {2} | {3} | {4} | {5} | {6} | {7} | {8} | {9}", got.Count(x => x == 1) / genf * 100 + "%", got.Count(x => x == 2) / genf * 100 + "%", got.Count(x => x == 3) / genf * 100 + "%", got.Count(x => x == 4) / genf * 100 + "%", got.Count(x => x == 5) / genf * 100 + "%", got.Count(x => x == 6) / genf * 100 + "%", got.Count(x => x == 7) / genf * 100 + "%", got.Count(x => x == 8) / genf * 100 + "%", got.Count(x => x == 9) / genf * 100 + "%", got.Count(x => x == 10) / genf * 100 + "%");
             *
             *  //Console.WriteLine(OneToTen.ChooseRange(0, 10).TValue);
             *
             *  Console.ReadKey();
             * }
             */

            //Determine base RNG to get everything up and running.
            DetermineRng();

            PlayerEvents.FarmerChanged += PlayerEvents_FarmerChanged;
            GameEvents.UpdateTick      += GameEvents_UpdateTick;
            PlayerEvents.LoadedGame    += PlayerEvents_LoadedGame;
            ControlEvents.KeyPressed   += ControlEvents_KeyPressed;

            Log.Info(GetType().Name + " by Zoryn => Initialized (Press F5 To Reload Config)");
        }
Ejemplo n.º 2
0
 private void ControlEvents_KeyPressed(object sender, EventArgsKeyPressed e)
 {
     if (e.KeyPressed == Keys.F5)
     {
         this.Config = this.Helper.ReadConfig <RngConfig>();
         this.Monitor.Log("Config reloaded", LogLevel.Info);
     }
 }
Ejemplo n.º 3
0
        /*********
        ** Public methods
        *********/
        /// <summary>The mod entry point, called after the mod is first loaded.</summary>
        /// <param name="helper">Provides simplified APIs for writing mods.</param>
        public override void Entry(IModHelper helper)
        {
            this.Config = helper.ReadConfig <RngConfig>();

            this.RandomFloats = new float[256];
            BetterRng.Twister = new MersenneTwister();

            //Destroys the game's built-in random number generator for Twister.
            Game1.random = BetterRng.Twister;

            //Just fills the buffer with junk so that we know everything is good and random.
            this.RandomFloats.FillFloats();

            //Define base randoms
            this.Weather = new[]
            {
                WeightedGeneric <int> .Create(this.Config.SunnyChance, 0),
                WeightedGeneric <int> .Create(this.Config.CloudySnowyChance, 2),
                WeightedGeneric <int> .Create(this.Config.RainyChance, 1),
                WeightedGeneric <int> .Create(this.Config.StormyChance, 3),
                WeightedGeneric <int> .Create(this.Config.HarshSnowyChance, 5)
            };

            /*
             * //Debugging for my randoms
             * while (true)
             * {
             *  List<int> got = new List<int>();
             *  int v = 0;
             *  int gen = 1024;
             *  float genf = gen;
             *  for (int i = 0; i < gen; i++)
             *  {
             *      v = Weighted.ChooseRange(OneToTen, 1, 5).TValue;
             *      got.Add(v);
             *
             *      if (gen <= 1024)
             *          Console.Write(v + ", ");
             *  }
             *  Console.Write("\n");
             *  Console.WriteLine("Generated {0} Randoms", got.Count);
             *  Console.WriteLine("1: {0} | 2: {1} | 3: {2} | 4: {3} | 5: {4} | 6: {5} | 7: {6} | 8: {7} | 9: {8} | 10: {9} | ?: {10}", got.Count(x => x == 1), got.Count(x => x == 2), got.Count(x => x == 3), got.Count(x => x == 4), got.Count(x => x == 5), got.Count(x => x == 6), got.Count(x => x == 7), got.Count(x => x == 8), got.Count(x => x == 9), got.Count(x => x == 10), got.Count(x => x > 10));
             *  Console.WriteLine("{0} | {1} | {2} | {3} | {4} | {5} | {6} | {7} | {8} | {9}", got.Count(x => x == 1) / genf * 100 + "%", got.Count(x => x == 2) / genf * 100 + "%", got.Count(x => x == 3) / genf * 100 + "%", got.Count(x => x == 4) / genf * 100 + "%", got.Count(x => x == 5) / genf * 100 + "%", got.Count(x => x == 6) / genf * 100 + "%", got.Count(x => x == 7) / genf * 100 + "%", got.Count(x => x == 8) / genf * 100 + "%", got.Count(x => x == 9) / genf * 100 + "%", got.Count(x => x == 10) / genf * 100 + "%");
             *
             *  //Console.WriteLine(OneToTen.ChooseRange(0, 10).TValue);
             *
             *  Console.ReadKey();
             * }
             */

            //Determine base RNG to get everything up and running.
            this.DetermineRng();

            SaveEvents.AfterLoad     += this.SaveEvents_AfterLoad;
            ControlEvents.KeyPressed += this.ControlEvents_KeyPressed;

            this.Monitor.Log("Initialized (press F5 to reload config)");
        }