Example #1
0
        private static VariableObject SetMonth(CommandType ct, string index, string setMonthName, string setMonthDays)
        {
            VariableObject vo = new VariableObject();

            if (Support.CheckForceScriptSettings(ref vo, "Custom Months"))
            {
                return vo;
            }

            if (Data.DataFileInUse)
            {
                vo.Success = false;
                vo.Message = Data.DataFileInUseMessage;

                return vo;
            }

            if (Data.MonthsArray.Count == 0)
            {
                if (ct != CommandType.Add)
                {
                    vo.Success = false;
                    vo.Message = "There are no custom months!";

                    return vo;
                }
            }

            if (Support.CheckAlreadyExistsInArray(ref vo, Data.MonthsArray, setMonthName))
            {
                return vo;
            }

            lock (Data.MonthsArray)
            {
                int monthIndex = 0;

                int newMonthDays = 0;

                bool success = false;
                string message = null;

                if (ct != CommandType.Add) // If not adding, check index number.
                {
                    object o = Support.GetValue(index);

                    if (Config.CheckVariable(o, "Number", 1, Data.MonthsArray.Count, typeof(int), ref success, ref message))
                    {
                        int value = (int)o;

                        monthIndex = value - 1;
                    }
                }
                else // Adding, so increment index by 1.
                {
                    success = true;

                    index = (Data.MonthsArray.Count + 1).ToString();
                }

                if (success) // Check month days.
                {
                    object o = Support.GetValue(setMonthDays);

                    if (Config.CheckVariable(o, "Days", 1, int.MaxValue, typeof(int), ref success, ref message))
                    {
                        int value = (int)o;

                        newMonthDays = value;
                    }
                }

                if (success) // If successful then finalize.
                {
                    MonthPropsObject mpo = new MonthPropsObject(setMonthName, newMonthDays);

                    switch (ct)
                    {
                        case CommandType.Add:
                            {
                                Data.MonthsArray.Add(mpo);

                                message = String.Format("Month #{0} '{1}' has been added with '{2}' day{3}.", index, setMonthName, newMonthDays, newMonthDays == 1 ? "" : "s");

                                break;
                            }
                        case CommandType.Insert:
                            {
                                Data.MonthsArray.Insert(monthIndex, mpo);

                                message = String.Format("Month #{0} '{1}' has been inserted with '{2}' day{3}.  All succeeding months indexes have moved down.", index, setMonthName, newMonthDays, newMonthDays == 1 ? "" : "s");

                                break;
                            }
                        case CommandType.Set:
                            {
                                Data.MonthsArray[monthIndex] = mpo;

                                message = String.Format("Month #{0} '{1}' has been set with '{2}' day{3}.", index, setMonthName, newMonthDays, newMonthDays == 1 ? "" : "s");

                                break;
                            }
                    }

                    Engine.Restart();
                }

                vo.Success = success;
                vo.Message = message;
            }

            return vo;
        }
Example #2
0
        public static bool Load()
        {
            if (!Support.CheckDataPath())
            {
                Support.ConsoleWriteLine(String.Format("Time System: \"{0}\" not found!  Creating a new file using the current settings.", DataFileName));

                Config.SetDefaults(true);

                Engine.Restart();

                Save();

                return false;
            }
            else
            {
                using (BinaryReader reader = new BinaryReader(File.Open(DataFile, FileMode.Open)))
                {
                    try
                    {
                        m_DataFileInUse = true;

                        Support.WipeAllArrays();

                        Config.SetDefaultSettings(true);

                        int version = reader.ReadInt32();

                        if (version < 3)
                        {
                            return LegacySupport.Load(reader, version);
                        }

                        switch (version)
                        {
                            case 6:
                                {
                                    m_UseNonRedMageAI = reader.ReadBoolean();

                                    m_UseCantTellTime = reader.ReadBoolean();

                                    goto case 5;
                                }
                            case 5:
                                {
                                    m_LightsEngineTimerSpeed = reader.ReadDouble();

                                    m_UseEvilSpawners = reader.ReadBoolean();

                                    goto case 4;
                                }
                            case 4:
                                {
                                    m_Logging = reader.ReadBoolean();

                                    m_UseLightLevelOverride = reader.ReadBoolean();

                                    m_UseMurdererDarkestHourBonus = reader.ReadBoolean();

                                    goto case 3;
                                }
                            case 3:
                                {
                                    m_Enabled = reader.ReadBoolean();

                                    m_TimerSpeed = reader.ReadDouble();
                                    m_MinutesPerTick = reader.ReadInt32();

                                    m_UpdateInterval = reader.ReadInt32();

                                    m_DayLevel = reader.ReadInt32();
                                    m_NightLevel = reader.ReadInt32();
                                    m_DarkestHourLevel = reader.ReadInt32();
                                    m_LightsOnLevel = reader.ReadInt32();
                                    m_MoonLevelAdjust = reader.ReadInt32();

                                    m_MinutesPerHour = reader.ReadInt32();
                                    m_HoursPerDay = reader.ReadInt32();

                                    m_NightStartHour = reader.ReadInt32();
                                    m_NightStartMinute = reader.ReadInt32();
                                    m_DayStartHour = reader.ReadInt32();
                                    m_DayStartMinute = reader.ReadInt32();
                                    m_ScaleTimeMinutes = reader.ReadInt32();

                                    m_Minute = reader.ReadInt32();
                                    m_Hour = reader.ReadInt32();
                                    m_Day = reader.ReadInt32();
                                    m_Month = reader.ReadInt32();
                                    m_Year = reader.ReadInt32();

                                    m_UseDarkestHour = reader.ReadBoolean();
                                    m_DarkestHourMinutesAfterNight = reader.ReadInt32();
                                    m_DarkestHourScaleTimeMinutes = reader.ReadInt32();
                                    m_DarkestHourLength = reader.ReadInt32();

                                    m_UseRealTime = reader.ReadBoolean();

                                    m_UseTimeZones = reader.ReadBoolean();
                                    m_TimeZoneXDivisor = reader.ReadInt32();
                                    m_TimeZoneScaleMinutes = reader.ReadInt32();

                                    m_UseAutoLighting = reader.ReadBoolean();
                                    m_UseRandomLightOutage = reader.ReadBoolean();

                                    if (version < 5)
                                    {
                                        reader.ReadInt32();
                                    }

                                    m_UseSeasons = reader.ReadBoolean();

                                    m_UseNightSightDarkestHourOverride = reader.ReadBoolean();

                                    m_UseNightSightOverride = reader.ReadBoolean();

                                    m_TimeFormat = reader.ReadString();
                                    m_ClockTimeFormat = reader.ReadString();
                                    m_SpyglassFormat = reader.ReadString();

                                    // Custom Months

                                    lock (m_MonthsArray)
                                    {
                                        int recordCount = reader.ReadInt32();

                                        for (int i = 0; i < recordCount; i++)
                                        {
                                            MonthPropsObject mpo = new MonthPropsObject();

                                            mpo.Name = reader.ReadString();
                                            mpo.TotalDays = reader.ReadInt32();

                                            m_MonthsArray.Add(mpo);
                                        }
                                    }

                                    // Custom Moons

                                    lock (m_MoonsArray)
                                    {
                                        int recordCount = reader.ReadInt32();

                                        for (int i = 0; i < recordCount; i++)
                                        {
                                            MoonPropsObject mpo = new MoonPropsObject();

                                            mpo.Name = reader.ReadString();

                                            mpo.TotalDays = reader.ReadInt32();
                                            mpo.CurrentDay = reader.ReadInt32();

                                            mpo.LastUpdateDay = reader.ReadInt32();

                                            m_MoonsArray.Add(mpo);
                                        }
                                    }

                                    // Facet Adjustments

                                    lock (m_FacetArray)
                                    {
                                        int recordCount = reader.ReadInt32();

                                        for (int i = 0; i < recordCount; i++)
                                        {
                                            FacetPropsObject fpo = new FacetPropsObject();

                                            fpo.Map = Support.GetMapFromName(reader.ReadString(), false);

                                            fpo.Adjustment = reader.ReadInt32();

                                            Data.FacetArray.Add(fpo);
                                        }
                                    }

                                    // Effects Maps

                                    lock (m_EffectsMapArray)
                                    {
                                        int recordCount = reader.ReadInt32();

                                        for (int i = 0; i < recordCount; i++)
                                        {
                                            int priority = reader.ReadInt32();

                                            Map map = Support.GetMapFromName(reader.ReadString(), false);

                                            int x1 = reader.ReadInt32();
                                            int y1 = reader.ReadInt32();
                                            int x2 = reader.ReadInt32();
                                            int y2 = reader.ReadInt32();

                                            EffectsMapObject emo = Config.SetDefaultEffectsValues(new EffectsMapObject(map, x1, y1, x2, y2));

                                            emo.Priority = priority;

                                            if (version > 4)
                                            {
                                                emo.Index = reader.ReadInt32();

                                                emo.Enabled = reader.ReadBoolean();
                                            }

                                            emo.UseLatitude = reader.ReadBoolean();

                                            emo.OuterLatitudePercent = reader.ReadDouble();
                                            emo.InnerLatitudePercent = reader.ReadDouble();

                                            if (version < 5)
                                            {
                                                emo.Index = reader.ReadInt32();
                                            }

                                            emo.UseSeasons = reader.ReadBoolean();

                                            emo.StaticSeason = (Season)reader.ReadInt32();

                                            emo.SpringDate.Month = reader.ReadInt32();
                                            emo.SpringDate.Day = reader.ReadInt32();

                                            emo.SummerDate.Month = reader.ReadInt32();
                                            emo.SummerDate.Day = reader.ReadInt32();

                                            emo.FallDate.Month = reader.ReadInt32();
                                            emo.FallDate.Day = reader.ReadInt32();

                                            emo.WinterDate.Month = reader.ReadInt32();
                                            emo.WinterDate.Day = reader.ReadInt32();

                                            if (version > 4)
                                            {
                                                emo.UseDarkestHour = reader.ReadBoolean();

                                                emo.UseAutoLighting = reader.ReadBoolean();
                                                emo.UseRandomLightOutage = reader.ReadBoolean();
                                                emo.LightOutageChancePerTick = reader.ReadInt32();
                                            }

                                            emo.UseNightSightDarkestHourOverride = reader.ReadBoolean();

                                            if (version > 3)
                                            {
                                                emo.NightSightDarkestHourReduction = reader.ReadInt32();
                                            }

                                            emo.UseNightSightOverride = reader.ReadBoolean();
                                            emo.NightSightLevelReduction = reader.ReadInt32();

                                            if (version > 3)
                                            {
                                                emo.UseLightLevelOverride = reader.ReadBoolean();
                                                emo.LightLevelOverrideAdjust = reader.ReadInt32();

                                                emo.UseMurdererDarkestHourBonus = reader.ReadBoolean();
                                                emo.MurdererDarkestHourLevelBonus = reader.ReadInt32();
                                            }

                                            if (version > 4)
                                            {
                                                emo.UseEvilSpawners = reader.ReadBoolean();
                                            }

                                            if (version > 5)
                                            {
                                                emo.UseNonRedMageAI = reader.ReadBoolean();

                                                emo.UseCantTellTime = reader.ReadBoolean();
                                            }

                                            Data.EffectsMapArray.Add(emo);
                                        }
                                    }

                                    // Effects Exclusion Maps

                                    lock (m_EffectsExclusionMapArray)
                                    {
                                        int recordCount = reader.ReadInt32();

                                        for (int i = 0; i < recordCount; i++)
                                        {
                                            int priority = reader.ReadInt32();

                                            Map map = Support.GetMapFromName(reader.ReadString(), false);

                                            int x1 = reader.ReadInt32();
                                            int y1 = reader.ReadInt32();
                                            int x2 = reader.ReadInt32();
                                            int y2 = reader.ReadInt32();

                                            EffectsExclusionMapObject eemo = Config.SetDefaultEffectsExclusionValues(new EffectsExclusionMapObject(map, x1, y1, x2, y2));

                                            eemo.Priority = priority;

                                            if (version > 4)
                                            {
                                                eemo.Index = reader.ReadInt32();

                                                eemo.Enabled = reader.ReadBoolean();
                                            }

                                            if (version < 4)
                                            {
                                                reader.ReadBoolean();

                                                reader.ReadDouble();
                                                reader.ReadDouble();
                                            }

                                            if (version < 5)
                                            {
                                                eemo.Index = reader.ReadInt32();
                                            }

                                            Data.EffectsExclusionMapArray.Add(eemo);
                                        }
                                    }

                                    break;
                                }
                        }

                        reader.Close();

                        Support.ConsoleWriteLine("Time System: Loading complete.");

                        m_DataFileInUse = false;

                        Support.ReIndexArray(EffectsMapArray);
                        Support.ReIndexArray(EffectsExclusionMapArray);

                        return true;
                    }
                    catch (EndOfStreamException e)
                    {
                        m_DataFileInUse = false;

                        reader.Close();

                        Support.ConsoleWriteLine(String.Format("Time System: \"{0}\" is corrupt!  Creating a new file using the current settings.\r\n\r\nException:\r\n\r\n{1}\r\n", DataFileName, e.ToString()));

                        Config.SetDefaults(true);

                        Engine.Restart();

                        Save();

                        string goAwayWarning = e.ToString(); // Stop compile warning.

                        return false;
                    }
                    catch (Exception e)
                    {
                        m_DataFileInUse = false;

                        reader.Close();

                        Support.ConsoleWriteLine(String.Format("Time System: Unable to load data from file \"{0}\"!  Creating a new file using the current settings.\r\n\r\nException:\r\n\r\n{1}\r\n", DataFileName, e.ToString()));

                        Config.SetDefaults(true);

                        Engine.Restart();

                        Save();

                        return false;
                    }
                }
            }
        }
Example #3
0
        public static VariableObject SetMonthProps(string index, string setMonthDays)
        {
            VariableObject vo = new VariableObject();

            if (Support.CheckForceScriptSettings(ref vo, "Custom Months"))
            {
                return vo;
            }

            if (Data.MonthsArray.Count == 0)
            {
                vo.Success = false;
                vo.Message = "There are no custom months!";

                return vo;
            }

            lock (Data.MonthsArray)
            {
                int monthIndex = 0;

                string monthName = null;
                int newMonthDays = 0;

                bool success = false;
                string message = null;

                {
                    object o = Support.GetValue(index);

                    if (o is string)
                    {
                        for (int i = 0; i < Data.MonthsArray.Count; i++)
                        {
                            MonthPropsObject mpo = Data.MonthsArray[i];

                            if (mpo.Name.ToLower() == index.ToLower())
                            {
                                o = Support.GetValue((i + 1).ToString());

                                break;
                            }
                        }
                    }

                    if (Config.CheckVariable(o, "Number", 1, Data.MonthsArray.Count, typeof(int), ref success, ref message))
                    {
                        int value = (int)o;

                        monthIndex = value - 1;

                        index = value.ToString();

                        MonthPropsObject mpo = Data.MonthsArray[monthIndex];

                        monthName = mpo.Name;
                    }
                    else
                    {
                        StringBuilder sb = new StringBuilder();

                        sb.Append(message);
                        sb.Append("\r\nYou may also specify the month name instead of the number.");

                        message = sb.ToString();
                    }
                }

                if (success)
                {
                    object o = Support.GetValue(setMonthDays);

                    if (Config.CheckVariable(o, "Days", 1, int.MaxValue, typeof(int), ref success, ref message))
                    {
                        int value = (int)o;

                        newMonthDays = value;
                    }
                }

                if (success)
                {
                    MonthPropsObject mpo = new MonthPropsObject(monthName, newMonthDays);

                    Data.MonthsArray[monthIndex] = mpo;

                    message = String.Format("Month #{0} '{1}' has been set with '{2}' day{3}.", index, monthName, newMonthDays, newMonthDays == 1 ? "" : "s");

                    Engine.Restart();
                }

                vo.Success = success;
                vo.Message = message;
            }

            return vo;
        }