Пример #1
0
        private static bool IsControllable(BaseLight baseLight, EffectsObject eo)
        {
            if (!Data.UseAutoLighting || eo == null || eo.EffectsMap == null || !eo.EffectsMap.UseAutoLighting || (baseLight is TSBaseLight && !((TSBaseLight)baseLight).UseAutoLighting))
            {
                return false;
            }

            return true;
        }
Пример #2
0
        private static bool IsDarkestHour(int minute, int hour, EffectsObject eo)
        {
            if (!Data.UseDarkestHour || eo == null || eo.EffectsMap == null || !eo.EffectsMap.UseDarkestHour)
            {
                return false;
            }

            return IsDarkestHour(minute, hour);
        }
Пример #3
0
        public static EffectsObject GetEffects(Map map, int x, int y, bool getSeason)
        {
            EffectsObject eo = new EffectsObject();

            eo.EffectsMap = null;
            eo.EffectsExclusionMap = null;

            List<EffectsMapObject> emoArray = GetEffectsMapArray(map, x, y, false);

            if (emoArray.Count > 0)
            {
                eo.EffectsMap = emoArray[0];
            }

            List<EffectsExclusionMapObject> eemoArray = GetEffectsExclusionMapArray(map, x, y, false);

            if (eemoArray.Count > 0)
            {
                eo.EffectsExclusionMap = eemoArray[0];
            }

            EffectsMapObject emoParentSeason = null;

            for (int i = 0; i < emoArray.Count; i++)
            {
                EffectsMapObject emo = emoArray[i];

                if (emo.UseSeasons)
                {
                    emoParentSeason = emo;

                    break;
                }
            }

            if (eo.EffectsMap != null && eo.EffectsExclusionMap != null && eo.EffectsExclusionMap.Priority >= eo.EffectsMap.Priority)
            {
                eo.EffectsMap = null;

                return eo;
            }

            if (eo.EffectsMap != null)
            {
                eo.EffectsExclusionMap = null;

                if (getSeason && emoParentSeason != null)
                {
                    eo.LateralSeason = emoParentSeason.GetLateralSeason(map, x, y);
                    eo.Season = emoParentSeason.GetSeason(map, x, y);
                }
            }

            return eo;
        }
Пример #4
0
        public static bool IsDarkestHour(object o, EffectsObject eo)
        {
            if (!Data.UseDarkestHour || eo == null || eo.EffectsMap == null || !eo.EffectsMap.UseDarkestHour)
            {
                return false;
            }

            int x = Support.GetXAxis(o);

            int minute, hour;

            GetTimeMinHour(o, x, out minute, out hour);

            return IsDarkestHour(minute, hour);
        }
Пример #5
0
        public static void CalculateLightOutage(BaseLight baseLight, EffectsObject eo)
        {
            if (!Data.UseRandomLightOutage || IsDefraggable(baseLight) || !IsControllable(baseLight, eo) || !eo.EffectsMap.UseRandomLightOutage || (baseLight is TSBaseLight && !((TSBaseLight)baseLight).UseRandomLightOutage))
            {
                return;
            }

            int lowNumber = Support.GetRandom(0, (100 - eo.EffectsMap.LightOutageChancePerTick));
            int highNumber = lowNumber + eo.EffectsMap.LightOutageChancePerTick;

            int randomChance = Support.GetRandom(0, 100);

            if (randomChance >= lowNumber && randomChance <= highNumber)
            {
                if (baseLight.Burning)
                {
                    baseLight.Douse();
                }
                else
                {
                    baseLight.Ignite();
                }
            }
        }
Пример #6
0
        public static void CheckEffects(MobileObject mo, EffectsObject eo, bool checkSeason, bool checkNightSight)
        {
            Mobile mobile = mo.Mobile;

            if (eo != null && eo.EffectsMap != null)
            {
                if (checkSeason && Data.UseSeasons && eo.EffectsMap.UseSeasons)
                {
                    if (mo.Season != eo.Season)
                    {
                        mo.Season = eo.Season;

                        if (eo.Season == Season.Winter)
                        {
                            mobile.Send(new SeasonChange(4)); // Send Desolation packet for Winter instead of Winter due to Winter adding blocky snow tiles which don't look right.
                        }
                        else
                        {
                            mobile.Send(new SeasonChange((int)eo.Season - 1));
                        }

                        Support.SendLightLevelUpdate(mo);
                    }
                }

                if (checkNightSight)
                {
                    if (mo.IsNightSightOn)
                    {
                        if (Data.UseNightSightDarkestHourOverride && eo.EffectsMap.UseNightSightDarkestHourOverride)
                        {
                            if (mo.IsDarkestHour)
                            {
                                if (eo.EffectsMap.NightSightDarkestHourReduction < 100)
                                {
                                    int adjustment = (int)((double)mo.OldLightLevel * ((double)(100 - eo.EffectsMap.NightSightDarkestHourReduction) / 100));

                                    if (adjustment >= 0 && mobile.LightLevel != adjustment)
                                    {
                                        mobile.LightLevel = adjustment;
                                    }
                                }
                                else
                                {
                                    mobile.EndAction(typeof(LightCycle));
                                    mobile.LightLevel = 0;
                                    BuffInfo.RemoveBuff(mobile, BuffIcon.NightSight);

                                    SetNightSightOff(mo);

                                    mobile.SendMessage("The evil in the air draws energy from your nightsight effect!");
                                }
                            }
                        }

                        if (Data.UseNightSightOverride && !mo.IsDarkestHour && mo.IsNightSightOn)
                        {
                            if (eo.EffectsMap.UseNightSightOverride)
                            {
                                if (eo.EffectsMap.NightSightLevelReduction < 100)
                                {
                                    int adjustment = (int)((double)mo.OldLightLevel * ((double)(100 - eo.EffectsMap.NightSightLevelReduction) / 100));

                                    if (adjustment >= 0 && mobile.LightLevel != adjustment)
                                    {
                                        mobile.LightLevel = adjustment;
                                    }
                                }
                                else
                                {
                                    mobile.EndAction(typeof(LightCycle));
                                    mobile.LightLevel = 0;
                                    BuffInfo.RemoveBuff(mobile, BuffIcon.NightSight);

                                    SetNightSightOff(mo);

                                    mobile.SendMessage("An unknown magical disturbance has consumed your nightsight effect!");
                                }
                            }
                            else
                            {
                                if (mobile.LightLevel < mo.OldLightLevel)
                                {
                                    mobile.LightLevel = mo.OldLightLevel;
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                if (checkNightSight && mo.IsNightSightOn && mobile.LightLevel != mo.OldLightLevel)
                {
                    mobile.LightLevel = mo.OldLightLevel;
                }
            }
        }
Пример #7
0
        public static int CalculateLightLevel(object o, EffectsObject eo)
        {
            if (!Data.Enabled)
            {
                return Data.DayLevel;
            }

            MobileObject mo = null;

            if (o is Mobile)
            {
                mo = Support.GetMobileObject((Mobile)o);

                if (mo != null)
                {
                    if (DateTime.Now - mo.UpdateTimeStamp < TimeSpan.FromMilliseconds(Data.UpdateInterval))
                    {
                        return mo.LightLevel;
                    }

                    mo.IsDarkestHour = false;
                }
                else
                {
                    return Data.DayLevel;
                }
            }

            if (o != null && eo == null)
            {
                eo = EffectsEngine.GetEffects(o, false);
            }

            int currentLevel = Data.BaseLightLevel;

            if (Data.UseLightLevelOverride && eo != null && eo.EffectsMap != null && eo.EffectsMap.UseLightLevelOverride)
            {
                currentLevel = eo.EffectsMap.LightLevelOverrideAdjust;
            }
            else
            {
                int nightLevelAdjust = MoonEngine.GetNightLevelAdjust();

                int x = Support.GetXAxis(o);

                int minute = Data.Minute + GetAdjustments(o, o is Mobile ? false : Data.UseTimeZones);
                int hour = Data.Hour;
                int day = Data.Day;
                int month = Data.Month;
                int year = Data.Year;

                if (o != null)
                {
                    CheckTime(ref minute, ref hour, ref day, ref month, ref year, false);
                }

                if (IsNightTime(minute, hour)) // Night time.
                {
                    bool isDarkestHour = IsDarkestHour(minute, hour, eo);

                    if (mo != null)
                    {
                        mo.IsDarkestHour = isDarkestHour;
                    }

                    int minutesAfterNight = GetMinutesAfterNight(minute, hour);

                    if (Data.ScaleTimeMinutes - minutesAfterNight >= 0)
                    {
                        currentLevel = (int)(nightLevelAdjust * ((double)minutesAfterNight / (double)Data.ScaleTimeMinutes));
                    }
                    else if (isDarkestHour)
                    {
                        if (o is BaseLight)
                        {
                            LightsEngine.CalculateLightOutage((BaseLight)o, eo);
                        }

                        int bonus = 0;

                        if (mo != null && eo != null && eo.EffectsMap != null)
                        {
                            if (Data.UseMurdererDarkestHourBonus && eo.EffectsMap.UseMurdererDarkestHourBonus && mo.IsMurderer)
                            {
                                bonus = eo.EffectsMap.MurdererDarkestHourLevelBonus;
                            }
                        }

                        int minutesAfterDarkestHour = minutesAfterNight - Data.DarkestHourStartMinutes;

                        if (minutesAfterDarkestHour <= Data.DarkestHourScaleTimeMinutes)
                        {
                            currentLevel = (int)(nightLevelAdjust + ((Data.DarkestHourLevel - bonus - nightLevelAdjust) * ((double)minutesAfterDarkestHour / (double)Data.DarkestHourScaleTimeMinutes)));
                        }
                        else if (minutesAfterDarkestHour > Data.DarkestHourScaleTimeMinutes && minutesAfterDarkestHour <= (Data.DarkestHourLength + Data.DarkestHourScaleTimeMinutes))
                        {
                            currentLevel = Data.DarkestHourLevel - bonus;
                        }
                        else if (minutesAfterDarkestHour > (Data.DarkestHourLength + Data.DarkestHourScaleTimeMinutes) && minutesAfterDarkestHour <= Data.DarkestHourTotalMinutes)
                        {
                            currentLevel = (int)(nightLevelAdjust + ((Data.DarkestHourLevel - bonus - nightLevelAdjust) * ((double)(Data.DarkestHourTotalMinutes - minutesAfterDarkestHour) / (double)Data.DarkestHourScaleTimeMinutes)));
                        }
                    }
                    else
                    {
                        currentLevel = nightLevelAdjust;
                    }

                    if (o is BaseLight && !isDarkestHour)
                    {
                        LightsEngine.UpdateManagedLight((BaseLight)o, currentLevel);
                    }
                }
                else // Day time.
                {
                    int minutesAfterDay = GetMinutesAfterDay(minute, hour);

                    if (Data.ScaleTimeMinutes - minutesAfterDay >= 0)
                    {
                        currentLevel = (int)((nightLevelAdjust - Data.DayLevel) - ((nightLevelAdjust - Data.DayLevel) * ((double)minutesAfterDay / (double)Data.ScaleTimeMinutes)));
                    }
                    else
                    {
                        currentLevel = Data.DayLevel;
                    }

                    if (o is BaseLight)
                    {
                        LightsEngine.UpdateManagedLight((BaseLight)o, currentLevel);
                    }
                }
            }

            if(currentLevel > Data.MaxLightLevel)
            {
                currentLevel = Data.MaxLightLevel;
            }
            else if(currentLevel < Data.MinLightLevel)
            {
                currentLevel = Data.MinLightLevel;
            }

            if (o == null)
            {
                Data.BaseLightLevel = currentLevel;
            }
            else if (o is Mobile)
            {
                if (mo != null)
                {
                    mo.UpdateTimeStamp = DateTime.Now;

                    mo.LightLevel = currentLevel;

                    EffectsEngine.CheckEffects(mo, eo, true, true);
                }
            }

            return currentLevel;
        }