Esempio n. 1
0
        void choosePattern()
        {
            float weightSum = 0;
            List <SpawnPattern> patterns = new List <SpawnPattern>();

            double totalHours = sapi.World.Calendar.TotalHours;

            for (int i = 0; i < config.Patterns.Length; i++)
            {
                SpawnPattern pattern = config.Patterns[i];
                if (pattern.StartTotalHours < totalHours)
                {
                    patterns.Add(pattern);
                    weightSum += pattern.Chance;
                }
            }

            float val = (float)sapi.World.Rand.NextDouble() * weightSum;

            foreach (var pattern in patterns)
            {
                val -= pattern.Chance;
                if (val <= 0)
                {
                    double untiltotalHours = totalHours + pattern.DurationHours.nextFloat(1, sapi.World.Rand);
                    curPattern = new CurrentPattern()
                    {
                        Code = pattern.Code, UntilTotalHours = untiltotalHours
                    };
                    sapi.Network.GetChannel("riftWeather").BroadcastPacket(new SpawnPatternPacket()
                    {
                        Pattern = curPattern
                    });
                    return;
                }
            }

            var patt = patterns[patterns.Count - 1];

            curPattern = new CurrentPattern()
            {
                Code = patt.Code, UntilTotalHours = totalHours + patt.DurationHours.nextFloat(1, sapi.World.Rand)
            };

            sapi.Network.GetChannel("riftWeather").BroadcastPacket(new SpawnPatternPacket()
            {
                Pattern = curPattern
            });
        }
Esempio n. 2
0
        private void Event_SaveGameLoaded()
        {
            try
            {
                byte[] data = sapi.WorldManager.SaveGame.GetData("riftweather");
                if (data == null)
                {
                    choosePattern();
                    return;
                }

                curPattern = SerializerUtil.Deserialize <CurrentPattern>(data);
            }
            catch {
                choosePattern();
            }

            if (curPattern.Code == null)
            {
                choosePattern();
            }
        }
Esempio n. 3
0
 private void onPacket(SpawnPatternPacket msg)
 {
     curPattern = msg.Pattern;
 }