Example #1
0
        private static void _DoWindKnockdown(NWObject oCreature)
        {
            LoggingService.Trace(TraceComponent.Weather, "Checking whether " + _.GetName(oCreature) + " is blown over");
            int nDC         = (_.GetHitDice(oCreature) / 2) + 10;
            int nDiscipline = _.GetSkillRank(_.SKILL_DISCIPLINE, oCreature);
            int nReflexSave = _.GetReflexSavingThrow(oCreature);
            int nSuccess;

            if (nDiscipline > nReflexSave)
            {
                nSuccess = _.GetIsSkillSuccessful(oCreature, _.SKILL_DISCIPLINE, nDC);
            }
            else
            {
                nSuccess = _.ReflexSave(oCreature, nDC);
            }

            if (nSuccess == 0)
            {
                _.ApplyEffectToObject(_.DURATION_TYPE_TEMPORARY,
                                      _.EffectKnockdown(),
                                      oCreature,
                                      6.0f);
                _.FloatingTextStringOnCreature("*is unbalanced by a strong gust*", oCreature);
            }
        }
Example #2
0
        private static void _DoWindKnockdown(NWObject oCreature)
        {
            LoggingService.Trace(TraceComponent.Weather, "Checking whether " + GetName(oCreature) + " is blown over");
            int nDC         = (GetHitDice(oCreature) / 2) + 10;
            int nDiscipline = GetSkillRank(Skill.Discipline, oCreature);
            int nReflexSave = GetReflexSavingThrow(oCreature);
            int nSuccess;

            if (nDiscipline > nReflexSave)
            {
                nSuccess = GetIsSkillSuccessful(oCreature, Skill.Discipline, nDC) ? 1 : 0;
            }
            else
            {
                nSuccess = ReflexSave(oCreature, nDC) == SaveReturn.Success ? 1 : 0;
            }

            if (nSuccess == 0)
            {
                ApplyEffectToObject(DurationType.Temporary,
                                    AbilityService.EffectKnockdown(oCreature, 6.0f),
                                    oCreature,
                                    6.0f);
                FloatingTextStringOnCreature("*is unbalanced by a strong gust*", oCreature);
            }
        }
Example #3
0
        private static void OnModuleApplyDamage()
        {
            DamageEventData data = NWNXDamage.GetDamageEventData();

            NWPlayer   player = data.Damager.Object;
            NWCreature target = NWGameObject.OBJECT_SELF;

            int attackType = target.GetLocalInt(AbilityService.LAST_ATTACK + player.GlobalID);

            LoggingService.Trace(TraceComponent.LastAttack, "Last attack from " + player.GlobalID + " on " + _.GetName(target) + " was type " + attackType);

            if (attackType == AbilityService.ATTACK_PHYSICAL)
            {
                // Only apply bonus damage from physical attacks.
                HandleWeaponStatBonuses();
                HandleEvadeOrDeflectBlasterFire();
                HandleApplySneakAttackDamage();
            }

            HandleDamageImmunity();
            HandleAbsorptionFieldEffect();
            HandleRecoveryBlast();
            HandleTranquilizerEffect();
            HandleStances();
        }
Example #4
0
        private static void OnHitCastSpell()
        {
            NWPlayer oPC = Object.OBJECT_SELF;

            if (!oPC.IsValid)
            {
                return;
            }

            NWObject oTarget = _.GetSpellTargetObject();
            NWItem   oItem   = _.GetSpellCastItem();

            // If this method was triggered by our own armor (from getting hit), return.
            if (oItem.BaseItemType == BASE_ITEM_ARMOR)
            {
                return;
            }

            // Flag this attack as physical so that the damage scripts treat it properly.
            LoggingService.Trace(TraceComponent.LastAttack, "Setting attack type from " + oPC.GlobalID + " against " + _.GetName(oTarget) + " to physical (" + ATTACK_PHYSICAL.ToString() + ")");
            oTarget.SetLocalInt(LAST_ATTACK + oPC.GlobalID, ATTACK_PHYSICAL);

            HandleGrenadeProficiency(oPC, oTarget);
            HandlePlasmaCellPerk(oPC, oTarget);
            int activeWeaponSkillID = oPC.GetLocalInt("ACTIVE_WEAPON_SKILL");

            if (activeWeaponSkillID <= 0)
            {
                return;
            }
            int activeWeaponSkillFeatID = oPC.GetLocalInt("ACTIVE_WEAPON_SKILL_FEAT_ID");

            if (activeWeaponSkillFeatID < 0)
            {
                activeWeaponSkillFeatID = -1;
            }

            PCPerk entity  = DataService.GetAll <PCPerk>().Single(x => x.PlayerID == oPC.GlobalID && x.PerkID == activeWeaponSkillID);
            var    perk    = DataService.Get <Data.Entity.Perk>(entity.PerkID);
            var    handler = PerkService.GetPerkHandler(activeWeaponSkillID);

            if (handler.CanCastSpell(oPC, oTarget))
            {
                handler.OnImpact(oPC, oTarget, entity.PerkLevel, activeWeaponSkillFeatID);

                if (oTarget.IsNPC)
                {
                    ApplyEnmity(oPC, oTarget.Object, perk);
                }
            }
            else
            {
                oPC.SendMessage(handler.CannotCastSpellMessage(oPC, oTarget) ?? "That ability cannot be used at this time.");
            }

            oPC.DeleteLocalString("ACTIVE_WEAPON_SKILL_UUID");
            oPC.DeleteLocalInt("ACTIVE_WEAPON_SKILL");
            oPC.DeleteLocalInt("ACTIVE_WEAPON_SKILL_FEAT_ID");
        }
Example #5
0
        public static int GetWeather(NWObject oArea)
        {
            LoggingService.Trace(TraceComponent.Weather, "Getting current weather for area: " + _.GetName(oArea));

            if (_.GetIsAreaInterior(oArea) == 1 || _.GetIsAreaAboveGround(oArea) == 0)
            {
                return(_.WEATHER_INVALID);
            }

            int nHeat     = GetHeatIndex(oArea);
            int nHumidity = GetHumidity(oArea);
            int nWind     = GetWindStrength(oArea);

            if (nHumidity > 7 && nHeat > 3 && nHeat < 6 && nWind < 3)
            {
                return(WEATHER_FOGGY);
            }

            // Rather unfortunately, the default method is also called GetWeather.
            return(_.GetWeather(oArea));
        }
Example #6
0
        public static Weather GetWeather(NWObject oArea)
        {
            LoggingService.Trace(TraceComponent.Weather, "Getting current weather for area: " + GetName(oArea));

            if (GetIsAreaInterior(oArea) == true || GetIsAreaAboveGround(oArea) == false)
            {
                return(Weather.Invalid);
            }

            int nHeat     = GetHeatIndex(oArea);
            int nHumidity = GetHumidity(oArea);
            int nWind     = GetWindStrength(oArea);

            if (nHumidity > 7 && nHeat > 3 && nHeat < 6 && nWind < 3)
            {
                return(Weather.Foggy);
            }

            // Rather unfortunately, the default method is also called GetWeather.
            return(_.GetWeather(oArea));
        }
Example #7
0
        private static void OnAreaEnter()
        {
            SetWeather();

            LoggingService.Trace(TraceComponent.Weather, "Applying weather to creature: " + _.GetName(_.GetEnteringObject()));

            DoWeatherEffects(_.GetEnteringObject());

            NWArea oArea     = (Object.OBJECT_SELF);
            int    nHour     = _.GetTimeHour();
            int    nLastHour = oArea.GetLocalInt("WEATHER_LAST_HOUR");

            if (nHour != nLastHour)
            {
                LoggingService.Trace(TraceComponent.Weather, "Cleaning up old weather");

                // Clean up any old weather placeables.
                foreach (NWObject oPlaceable in oArea.Objects)
                {
                    if (oPlaceable.ObjectType == _.OBJECT_TYPE_PLACEABLE &&
                        oPlaceable.GetLocalInt("WEATHER") == 1)
                    {
                        _.DestroyObject(oPlaceable);
                    }
                }

                // Create new ones depending on the current weather.
                int nWeather = GetWeather();
                LoggingService.Trace(TraceComponent.Weather, "Current weather: " + nWeather.ToString());

                if (nWeather == WEATHER_FOGGY)
                {
                    // Get the size in tiles.
                    int nSizeX = _.GetAreaSize(_.AREA_WIDTH, oArea);
                    int nSizeY = _.GetAreaSize(_.AREA_HEIGHT, oArea);

                    // We want one placeable per 8 tiles.
                    int nMax = (nSizeX * nSizeY) / 8;
                    LoggingService.Trace(TraceComponent.Weather, "Creating up to " + nMax.ToString() + " mist objects.");

                    for (int nCount = _.d6(); nCount < nMax; nCount++)
                    {
                        Vector vPosition = _.GetPosition(_.GetEnteringObject());

                        // Vectors are in meters - 10 meters to a tile.
                        vPosition.m_X = _.IntToFloat(_.Random(nSizeX * 10));
                        vPosition.m_Y = _.IntToFloat(_.Random(nSizeY * 10));

                        float fFacing = _.IntToFloat(_.Random(360));

                        string sResRef = "x3_plc_mist";

                        NWObject oPlaceable = _.CreateObject(_.OBJECT_TYPE_PLACEABLE, sResRef, _.Location(oArea, vPosition, fFacing));
                        _.SetObjectVisualTransform(oPlaceable, _.OBJECT_VISUAL_TRANSFORM_SCALE, _.IntToFloat(200 + _.Random(200)) / 100.0f);
                        oPlaceable.SetLocalInt("WEATHER", 1);
                    }
                }

                oArea.SetLocalInt("WEATHER_LAST_HOUR", nHour);
            }
        }
Example #8
0
        public static void SetWeather(NWObject oArea)
        {
            if (oArea.GetLocalInt(VAR_INITIALIZED) == 0)
            {
                if (_.GetIsAreaInterior(oArea) == 1 ||
                    _.GetIsAreaAboveGround(oArea) == 0)
                {
                    return;
                }
                oArea.SetLocalInt(VAR_SKYBOX, _.GetSkyBox(oArea));
                oArea.SetLocalInt(VAR_FOG_SUN, _.GetFogAmount(_.FOG_TYPE_SUN, oArea));
                oArea.SetLocalInt(VAR_FOG_MOON, _.GetFogAmount(_.FOG_TYPE_MOON, oArea));
                oArea.SetLocalInt(VAR_FOG_C_SUN, _.GetFogColor(_.FOG_TYPE_SUN, oArea));
                oArea.SetLocalInt(VAR_FOG_C_MOON, _.GetFogColor(_.FOG_TYPE_MOON, oArea));
                oArea.SetLocalInt(VAR_INITIALIZED, 1);
            }

            int  nHeat      = GetHeatIndex(oArea);
            int  nHumidity  = GetHumidity(oArea);
            int  nWind      = GetWindStrength(oArea);
            bool bStormy    = _.GetSkyBox(oArea) == _.SKYBOX_GRASS_STORM;
            bool bDustStorm = (oArea.GetLocalInt("DUST_STORM") == 1);
            bool bSandStorm = (oArea.GetLocalInt("SAND_STORM") == 1);

            //--------------------------------------------------------------------------
            // Process weather rules for this area.
            //--------------------------------------------------------------------------
            if (nHumidity > 7 && nHeat > 3)
            {
                if (nHeat < 6 && nWind < 3)
                {
                    _.SetWeather(oArea, _.WEATHER_CLEAR);
                }
                else
                {
                    _.SetWeather(oArea, _.WEATHER_RAIN);
                }
            }
            else if (nHumidity > 7)
            {
                _.SetWeather(oArea, _.WEATHER_SNOW);
            }
            else
            {
                _.SetWeather(oArea, _.WEATHER_CLEAR);
            }

            //--------------------------------------------------------------------------
            // Stormy if heat is greater than 4 only; if already stormy then 2 in 3
            // chance of storm clearing, otherwise x in 20 chance of storm starting,
            // where x is the wind level.
            //--------------------------------------------------------------------------
            if (nHeat > 4 && nHumidity > 7 &&
                ((bStormy && _.d20() - nWind < 1) || (bStormy && _.d3() == 1)))
            {
                LoggingService.Trace(TraceComponent.Weather, "A thunderstorm is now raging in " + _.GetName(oArea));
                _.SetSkyBox(_.SKYBOX_GRASS_STORM, oArea);
                Thunderstorm(oArea);
                oArea.SetLocalInt("GS_AM_SKY_OVERRIDE", 1);
                bStormy = true;
            }
            else
            {
                _.SetSkyBox(oArea.GetLocalInt(VAR_SKYBOX), oArea);
                oArea.DeleteLocalInt("GS_AM_SKY_OVERRIDE");
                bStormy = false;
            }

            // Does this area suffer from dust or sand storms?
            if (!bStormy && nWind >= 9 && _.d3() == 1)
            {
                // Dust storm - low visibility but no damage.
                if (_GetClimate(oArea).Dust_Storm)
                {
                    _.SetFogColor(_.FOG_TYPE_SUN, _.FOG_COLOR_BROWN, oArea);
                    _.SetFogColor(_.FOG_TYPE_MOON, _.FOG_COLOR_BROWN, oArea);
                    _.SetFogAmount(_.FOG_TYPE_SUN, 80, oArea);
                    _.SetFogAmount(_.FOG_TYPE_MOON, 80, oArea);

                    oArea.SetLocalInt("DUST_STORM", 1);
                    bDustStorm = true;
                }
                else if (_GetClimate(oArea).Sand_Storm)
                {
                    _.SetFogColor(_.FOG_TYPE_SUN, _.FOG_COLOR_ORANGE_DARK, oArea);
                    _.SetFogColor(_.FOG_TYPE_MOON, _.FOG_COLOR_ORANGE_DARK, oArea);
                    _.SetFogAmount(_.FOG_TYPE_SUN, 80, oArea);
                    _.SetFogAmount(_.FOG_TYPE_MOON, 80, oArea);

                    oArea.SetLocalInt("SAND_STORM", 1);
                    bSandStorm = true;
                }
            }
            else if (bDustStorm || bSandStorm)
            {
                // End the storm.
                oArea.DeleteLocalInt("DUST_STORM");
                oArea.DeleteLocalInt("SAND_STORM");

                _.SetFogColor(_.FOG_TYPE_SUN, oArea.GetLocalInt(VAR_FOG_C_SUN), oArea);
                _.SetFogColor(_.FOG_TYPE_MOON, oArea.GetLocalInt(VAR_FOG_C_MOON), oArea);
                _.SetFogAmount(_.FOG_TYPE_SUN, oArea.GetLocalInt(VAR_FOG_SUN), oArea);
                _.SetFogAmount(_.FOG_TYPE_MOON, oArea.GetLocalInt(VAR_FOG_MOON), oArea);
                bSandStorm = false;
                bDustStorm = false;
            }

            LoggingService.Trace(TraceComponent.Weather, "Area weather settings for area: " + _.GetName(oArea) +
                                 ", heat - " + _.IntToString(nHeat) +
                                 ", humidity - " + _.IntToString(nHumidity) +
                                 ", wind - " + _.IntToString(nWind) +
                                 ", thunderstorm - " + bStormy.ToString() +
                                 ", sand storm - " + bSandStorm.ToString() +
                                 ", dust storm - " + bDustStorm.ToString());
        }
Example #9
0
        public static bool AdjustWeather()
        {
            LoggingService.Trace(TraceComponent.Weather, "Adjusting module weather");
            NWObject oMod = _.GetModule();

            //--------------------------------------------------------------------------
            // Always change the weather the very first time
            //--------------------------------------------------------------------------
            if (oMod.GetLocalInt(VAR_INITIALIZED) == 0)
            {
                oMod.SetLocalInt(VAR_INITIALIZED, 1);
                _SetHumidity(_.Random(10) + 1);
            }
            else if (_.GetTimeHour() != oMod.GetLocalInt(VAR_WEATHER_CHANGE))
            {
                LoggingService.Trace(TraceComponent.Weather, "No change needed... yet.");
                return(false);
            }

            //--------------------------------------------------------------------------
            // Adjust the indices.  Only humidity is affected by the current values.
            //--------------------------------------------------------------------------
            int nHeat     = GetHeatIndex();
            int nHumidity = GetHumidity();
            int nWind     = GetWindStrength();

            //--------------------------------------------------------------------------
            // Heat is affected by time of year.
            //--------------------------------------------------------------------------
            nHeat = _.Random(5) + (6 - _.abs(_.GetCalendarMonth() - 6)); // (0-4 + 0-6)
            if (nHeat < 1)
            {
                nHeat = 1;
            }

            //--------------------------------------------------------------------------
            // Humidity is random but moves slowly.
            //--------------------------------------------------------------------------
            nHumidity = nHumidity + (_.Random(2 * nWind + 1) - nWind);
            if (nHumidity > 10)
            {
                nHumidity = 20 - nHumidity;
            }
            if (nHumidity < 1)
            {
                nHumidity = 1 - nHumidity;
            }

            //--------------------------------------------------------------------------
            // Wind is more likely to be calm, but can change quickly.
            //--------------------------------------------------------------------------
            nWind = _.d10(2) - 10;
            if (nWind < 1)
            {
                nWind = 1 - nWind;
            }

            LoggingService.Trace(TraceComponent.Weather, "New weather settings: heat - " + _.IntToString(nHeat) +
                                 ", humidity - " + _.IntToString(nHumidity) +
                                 ", wind - " + _.IntToString(nWind));

            _SetHeatIndex(nHeat);
            _SetHumidity(nHumidity);
            _SetWindStrength(nWind);

            //--------------------------------------------------------------------------
            // Work out when to next change the weather.
            //--------------------------------------------------------------------------
            int nNextChange = _.GetTimeHour() + (11 - nWind);

            if (nNextChange > 23)
            {
                nNextChange -= 24;
            }
            LoggingService.Trace(TraceComponent.Weather, "Change the weather next at hour " + _.IntToString(nNextChange));
            oMod.SetLocalInt(VAR_WEATHER_CHANGE, nNextChange);

            // Update all occupied areas with the new settings.
            NWObject oPC = _.GetFirstPC();

            while (_.GetIsObjectValid(oPC) == 1)
            {
                SetWeather(_.GetArea(oPC));
                oPC = _.GetNextPC();
            }

            return(true);
        }
Example #10
0
        private static PlanetaryClimate _GetClimate(NWObject oArea)
        {
            PlanetaryClimate climate = new PlanetaryClimate();

            //--------------------------------------------------------------------------
            // This line depends on the naming scheme PlanetName - AreaName.  Change it
            // if the area naming scheme changes!
            //--------------------------------------------------------------------------
            int index = _.GetName(oArea).IndexOf("-");

            if (index <= 0)
            {
                return(climate);
            }
            string planetName = _.GetName(oArea).Substring(0, index - 1);

            if (planetName == "Viscara")
            {
                LoggingService.Trace(TraceComponent.Weather, "Planet is Viscara.");
                climate.Heat_Modifier     = -2;
                climate.Humidity_Modifier = +2;
            }
            else if (planetName == "Tatooine")
            {
                LoggingService.Trace(TraceComponent.Weather, "Planet is Tatooine.");
                climate.Heat_Modifier     = +5;
                climate.Humidity_Modifier = -8;

                climate.Sand_Storm = true;

                climate.special_cloudy      = "A dusty wind sweeps through the desert; sparse clouds speed overhead.";
                climate.special_mild        = "The sun shines brilliantly, but not oppressively, over the desert; the sky is clear.";
                climate.special_mild_night  = "A clear night sky casts the desert in pale hues.";
                climate.special_warm_cloudy = "The shade of an overcast sky provides only minor relief to the sweltering temperatures.";
                climate.special_scorching   = "The desert is baked with pervasive, inescapable heat; a haze blurs the horizon.";
                climate.special_warm_windy  = "The hot wind wears at your face like a sandblaster.  A sand storm seems likely.";
                climate.special_windy       = "A scouring wind sweeps across the desert, a sand storm cannot be far away.";
            }
            else if (planetName == "Mon Cala")
            {
                LoggingService.Trace(TraceComponent.Weather, "Planet is Mon Cala.");
                climate.Humidity_Modifier = 0;
                climate.Wind_Modifier     = +1;
                climate.Heat_Modifier     = +1;

                climate.special_cloudy      = "Clouds build over the ocean, and the wind starts to pick up.  A storm could be brewing.";
                climate.special_cold_cloudy = "Thick clouds fill the sky, and a keen wind blows in off the ocean, exciting the waves.";
                climate.special_cold_mild   = "It is cool, but calm.  The ocean is calm and beautiful.";
                climate.special_freezing    = "A wave of cold air rolls in, stinging exposed flesh.";
                climate.special_mild        = "The sea is calm, a faint breeze rippling through the trees.";
                climate.special_mild_night  = "The sea is calm, and the sky towards the Galactic Core is full of stars.  In other directions, you see only a deep, unending black.";
                climate.special_mist        = "A mist has blown in off the sea, moisture hanging heavy in the air.";
                climate.special_warm_cloudy = "The sea is choppy and the wind has picked up. An array of clouds marshals on the horizon, ready to sweep over you.";
                climate.special_warm_mild   = "It is a beautiful day, warm and calm, though quite humid.";
                climate.special_rain_normal = "The ocean, affronted by the existence of patches of non-ocean on the surface of the planet, is attempting to reclaim the land by air drop.  In other words, it's raining.";
                climate.special_rain_warm   = "A heavy rain shower is passing over, but is doing little to dispel the humidity in the air.";
                climate.special_snow        = "It's snowing!  The local flora seems most surprised at this turn of events.";
                climate.special_storm       = "A storm rips in off the sea, filling the sky with dramatic flashes.";
                climate.special_scorching   = "The sun bakes the sand, making it extremely uncomfortable to those without insulated boots.";
                climate.special_cold_windy  = "A chill wind sweeps over the isles, the moisture in the air cutting to the bone.";
                climate.special_warm_windy  = "The wind is picking up, a warm front rolling over.  There could be a storm soon.";
                climate.special_windy       = "A strong wind sweeps in.  The sea is choppy, waves crashing onto the beach.";
            }

            return(climate);
        }
Example #11
0
        private static void OnHitCastSpell()
        {
            NWPlayer oPC = _.OBJECT_SELF;

            if (!oPC.IsValid)
            {
                return;
            }

            NWObject oTarget = _.GetSpellTargetObject();
            NWItem   oItem   = _.GetSpellCastItem();

            // If this method was triggered by our own armor (from getting hit), return.
            if (oItem.BaseItemType == BaseItem.Armor)
            {
                return;
            }

            // Flag this attack as physical so that the damage scripts treat it properly.
            LoggingService.Trace(TraceComponent.LastAttack, "Setting attack type from " + oPC.GlobalID + " against " + _.GetName(oTarget) + " to physical (" + ATTACK_PHYSICAL.ToString() + ")");
            oTarget.SetLocalInt(LAST_ATTACK + oPC.GlobalID, ATTACK_PHYSICAL);

            HandleGrenadeProficiency(oPC, oTarget);
            HandlePlasmaCellPerk(oPC, oTarget);
            int activeWeaponSkillID = oPC.GetLocalInt("ACTIVE_WEAPON_SKILL");

            if (activeWeaponSkillID <= 0)
            {
                return;
            }
            int activeWeaponSkillFeatID = oPC.GetLocalInt("ACTIVE_WEAPON_SKILL_FEAT_ID");

            if (activeWeaponSkillFeatID < 0)
            {
                activeWeaponSkillFeatID = -1;
            }

            PCPerk entity   = DataService.PCPerk.GetByPlayerAndPerkID(oPC.GlobalID, activeWeaponSkillID);
            var    perk     = DataService.Perk.GetByID(entity.PerkID);
            var    perkFeat = DataService.PerkFeat.GetByFeatID(activeWeaponSkillFeatID);
            var    handler  = PerkService.GetPerkHandler(activeWeaponSkillID);

            string canCast = handler.CanCastSpell(oPC, oTarget, perkFeat.PerkLevelUnlocked);

            if (string.IsNullOrWhiteSpace(canCast))
            {
                handler.OnImpact(oPC, oTarget, entity.PerkLevel, perkFeat.PerkLevelUnlocked);

                if (oTarget.IsNPC)
                {
                    ApplyEnmity(oPC, oTarget.Object, perk);
                }
            }
            else
            {
                oPC.SendMessage(canCast);
            }

            oPC.DeleteLocalString("ACTIVE_WEAPON_SKILL_UUID");
            oPC.DeleteLocalInt("ACTIVE_WEAPON_SKILL");
            oPC.DeleteLocalInt("ACTIVE_WEAPON_SKILL_FEAT_ID");
        }
Example #12
0
        private static void OnAreaEnter()
        {
            using (new Profiler("WeatherService.OnAreaEnter"))
            {
                SetWeather();

                LoggingService.Trace(TraceComponent.Weather, "Applying weather to creature: " + GetName(GetEnteringObject()));

                DoWeatherEffects(GetEnteringObject());

                NWArea oArea     = (OBJECT_SELF);
                int    nHour     = GetTimeHour();
                int    nLastHour = oArea.GetLocalInt("WEATHER_LAST_HOUR");

                if (nHour != nLastHour)
                {
                    if (!oArea.Data.ContainsKey("WEATHER_OBJECTS"))
                    {
                        oArea.Data["WEATHER_OBJECTS"] = new List <NWPlaceable>();
                    }
                    List <NWPlaceable> weatherObjects = oArea.Data["WEATHER_OBJECTS"];

                    LoggingService.Trace(TraceComponent.Weather, "Cleaning up old weather");

                    // Clean up any old weather placeables.
                    for (int x = weatherObjects.Count - 1; x >= 0; x--)
                    {
                        var placeable = weatherObjects.ElementAt(x);
                        placeable.Destroy();
                        weatherObjects.RemoveAt(x);
                    }

                    // Create new ones depending on the current weather.
                    var nWeather = GetWeather();
                    LoggingService.Trace(TraceComponent.Weather, "Current weather: " + nWeather.ToString());

                    if (nWeather == Weather.Foggy)
                    {
                        // Get the size in tiles.
                        int nSizeX = GetAreaSize(Dimension.Width, oArea);
                        int nSizeY = GetAreaSize(Dimension.Height, oArea);

                        // We want one placeable per 8 tiles.
                        int nMax = (nSizeX * nSizeY) / 8;
                        LoggingService.Trace(TraceComponent.Weather, "Creating up to " + nMax.ToString() + " mist objects.");

                        for (int nCount = d6(); nCount < nMax; nCount++)
                        {
                            Vector3 vPosition = GetPosition(GetEnteringObject());

                            // Vectors are in meters - 10 meters to a tile.
                            vPosition.X = IntToFloat(Random(nSizeX * 10));
                            vPosition.Y = IntToFloat(Random(nSizeY * 10));

                            float fFacing = IntToFloat(Random(360));

                            string sResRef = "x3_plc_mist";

                            NWPlaceable oPlaceable = CreateObject(ObjectType.Placeable, sResRef, Location(oArea, vPosition, fFacing));
                            SetObjectVisualTransform(oPlaceable, ObjectVisualTransform.Scale, IntToFloat(200 + Random(200)) / 100.0f);

                            weatherObjects.Add(oPlaceable);
                        }
                    }

                    oArea.Data["WEATHER_OBJECTS"] = weatherObjects;
                    oArea.SetLocalInt("WEATHER_LAST_HOUR", nHour);
                }
            }
        }
Example #13
0
        public static void SetWeather(NWObject oArea)
        {
            if (oArea.GetLocalInt(VAR_INITIALIZED) == 0)
            {
                if (GetIsAreaInterior(oArea) == true ||
                    GetIsAreaAboveGround(oArea) == false)
                {
                    return;
                }
                oArea.SetLocalInt(VAR_SKYBOX, (int)GetSkyBox(oArea));
                oArea.SetLocalInt(VAR_FOG_SUN, GetFogAmount(FogType.Sun, oArea));
                oArea.SetLocalInt(VAR_FOG_MOON, GetFogAmount(FogType.Moon, oArea));
                oArea.SetLocalInt(VAR_FOG_C_SUN, (int)GetFogColor(FogType.Sun, oArea));
                oArea.SetLocalInt(VAR_FOG_C_MOON, (int)GetFogColor(FogType.Moon, oArea));
                oArea.SetLocalInt(VAR_INITIALIZED, 1);
            }

            int  nHeat      = GetHeatIndex(oArea);
            int  nHumidity  = GetHumidity(oArea);
            int  nWind      = GetWindStrength(oArea);
            bool bStormy    = GetSkyBox(oArea) == Skybox.GrassStorm;
            bool bDustStorm = (oArea.GetLocalInt("DUST_STORM") == 1);
            bool bSandStorm = (oArea.GetLocalInt("SAND_STORM") == 1);
            bool bSnowStorm = (oArea.GetLocalInt("SNOW_STORM") == 1);

            //--------------------------------------------------------------------------
            // Process weather rules for this area.
            //--------------------------------------------------------------------------
            if (nHumidity > 7 && nHeat > 3)
            {
                if (nHeat < 6 && nWind < 3)
                {
                    _.SetWeather(oArea, WeatherType.Clear);
                }
                else
                {
                    _.SetWeather(oArea, WeatherType.Rain);
                }
            }
            else if (nHumidity > 7)
            {
                _.SetWeather(oArea, WeatherType.Snow);
            }
            else
            {
                _.SetWeather(oArea, WeatherType.Clear);
            }

            //--------------------------------------------------------------------------
            // Stormy if heat is greater than 4 only; if already stormy then 2 in 3
            // chance of storm clearing, otherwise x in 20 chance of storm starting,
            // where x is the wind level.
            //--------------------------------------------------------------------------
            if (nHeat > 4 && nHumidity > 7 &&
                ((bStormy && d20() - nWind < 1) || (bStormy && d3() == 1)))
            {
                LoggingService.Trace(TraceComponent.Weather, "A thunderstorm is now raging in " + GetName(oArea));
                SetSkyBox(Skybox.GrassStorm, oArea);
                Thunderstorm(oArea);
                oArea.SetLocalInt("GS_AM_SKY_OVERRIDE", 1);
                bStormy = true;
            }
            else
            {
                SetSkyBox((Skybox)oArea.GetLocalInt(VAR_SKYBOX), oArea);
                oArea.DeleteLocalInt("GS_AM_SKY_OVERRIDE");
                bStormy = false;
            }

            // Does this area suffer from dust or sand storms?
            if (!bStormy && nWind >= 9 && d3() == 1)
            {
                // Dust storm - low visibility but no damage.
                if (_GetClimate(oArea).Sand_Storm)
                {
                    SetFogColor(FogType.Sun, FogColor.OrangeDark, oArea);
                    SetFogColor(FogType.Moon, FogColor.OrangeDark, oArea);
                    SetFogAmount(FogType.Sun, 80, oArea);
                    SetFogAmount(FogType.Moon, 80, oArea);

                    oArea.SetLocalInt("SAND_STORM", 1);
                    bSandStorm = true;
                }
                else if (_GetClimate(oArea).Snow_Storm)
                {
                    SetFogColor(FogType.Sun, FogColor.White, oArea);
                    SetFogColor(FogType.Moon, FogColor.White, oArea);
                    SetFogAmount(FogType.Sun, 80, oArea);
                    SetFogAmount(FogType.Moon, 80, oArea);

                    oArea.SetLocalInt("SNOW_STORM", 1);
                    bSnowStorm = true;
                }
            }
            else if (bDustStorm || bSandStorm || bSnowStorm)
            {
                // End the storm.
                oArea.DeleteLocalInt("DUST_STORM");
                oArea.DeleteLocalInt("SAND_STORM");
                oArea.DeleteLocalInt("SNOW_STORM");

                SetFogColor(FogType.Sun, (FogColor)oArea.GetLocalInt(VAR_FOG_C_SUN), oArea);
                SetFogColor(FogType.Moon, (FogColor)oArea.GetLocalInt(VAR_FOG_C_MOON), oArea);
                SetFogAmount(FogType.Sun, oArea.GetLocalInt(VAR_FOG_SUN), oArea);
                SetFogAmount(FogType.Moon, oArea.GetLocalInt(VAR_FOG_MOON), oArea);
                bSandStorm = false;
                bDustStorm = false;
                bSnowStorm = false;
            }

            LoggingService.Trace(TraceComponent.Weather, "Area weather settings for area: " + GetName(oArea) +
                                 ", heat - " + IntToString(nHeat) +
                                 ", humidity - " + IntToString(nHumidity) +
                                 ", wind - " + IntToString(nWind) +
                                 ", thunderstorm - " + bStormy.ToString() +
                                 ", sand storm - " + bSandStorm.ToString() +
                                 ", snow storm - " + bSnowStorm.ToString() +
                                 ", dust storm - " + bDustStorm.ToString());
        }
Example #14
0
        public static void SaveLocation(NWPlayer player)
        {
            if (!player.IsPlayer)
            {
                return;
            }
            if (player.GetLocalInt("IS_SHIP") == 1)
            {
                return;
            }
            if (player.GetLocalInt("IS_GUNNER") == 1)
            {
                return;
            }

            NWArea area = player.Area;

            if (area.IsValid && area.Tag != "ooc_area" && area.Tag != "tutorial" && !area.IsInstance)
            {
                LoggingService.Trace(TraceComponent.Space, "Saving location in area " + GetName(area));
                Player entity = GetPlayerEntity(player.GlobalID);
                entity.LocationAreaResref  = area.Resref;
                entity.LocationX           = player.Position.X;
                entity.LocationY           = player.Position.Y;
                entity.LocationZ           = player.Position.Z;
                entity.LocationOrientation = (player.Facing);
                entity.LocationInstanceID  = null;

                if (string.IsNullOrWhiteSpace(entity.RespawnAreaResref))
                {
                    NWObject waypoint = GetWaypointByTag("DTH_DEFAULT_RESPAWN_POINT");
                    entity.RespawnAreaResref          = waypoint.Area.Resref;
                    entity.RespawnLocationOrientation = waypoint.Facing;
                    entity.RespawnLocationX           = waypoint.Position.X;
                    entity.RespawnLocationY           = waypoint.Position.Y;
                    entity.RespawnLocationZ           = waypoint.Position.Z;
                }

                DataService.SubmitDataChange(entity, DatabaseActionType.Update);
            }
            else if (area.IsInstance)
            {
                LoggingService.Trace(TraceComponent.Space, "Saving location in instance area " + GetName(area));
                string instanceID = area.GetLocalString("PC_BASE_STRUCTURE_ID");
                if (string.IsNullOrWhiteSpace(instanceID))
                {
                    instanceID = area.GetLocalString("PC_BASE_ID");
                }

                LoggingService.Trace(TraceComponent.Space, "Saving character in instance ID: " + instanceID);

                if (!string.IsNullOrWhiteSpace(instanceID))
                {
                    Player entity = GetPlayerEntity(player.GlobalID);
                    entity.LocationAreaResref  = area.Resref;
                    entity.LocationX           = player.Position.X;
                    entity.LocationY           = player.Position.Y;
                    entity.LocationZ           = player.Position.Z;
                    entity.LocationOrientation = (player.Facing);
                    entity.LocationInstanceID  = new Guid(instanceID);

                    DataService.SubmitDataChange(entity, DatabaseActionType.Update);
                }
            }
        }
Example #15
0
        private static void OnAreaEnter()
        {
            using (new Profiler("WeatherService.OnAreaEnter"))
            {
                SetWeather();

                LoggingService.Trace(TraceComponent.Weather, "Applying weather to creature: " + _.GetName(_.GetEnteringObject()));

                DoWeatherEffects(_.GetEnteringObject());

                NWArea oArea     = (NWGameObject.OBJECT_SELF);
                int    nHour     = _.GetTimeHour();
                int    nLastHour = oArea.GetLocalInt("WEATHER_LAST_HOUR");

                if (nHour != nLastHour)
                {
                    if (!oArea.Data.ContainsKey("WEATHER_OBJECTS"))
                    {
                        oArea.Data["WEATHER_OBJECTS"] = new List <NWPlaceable>();
                    }
                    List <NWPlaceable> weatherObjects = oArea.Data["WEATHER_OBJECTS"];

                    LoggingService.Trace(TraceComponent.Weather, "Cleaning up old weather");

                    // Clean up any old weather placeables.
                    for (int x = weatherObjects.Count - 1; x >= 0; x--)
                    {
                        var placeable = weatherObjects.ElementAt(x);
                        placeable.Destroy();
                        weatherObjects.RemoveAt(x);
                    }

                    // Create new ones depending on the current weather.
                    int nWeather = GetWeather();
                    LoggingService.Trace(TraceComponent.Weather, "Current weather: " + nWeather.ToString());

                    if (nWeather == WEATHER_FOGGY)
                    {
                        // Get the size in tiles.
                        int nSizeX = _.GetAreaSize(_.AREA_WIDTH, oArea);
                        int nSizeY = _.GetAreaSize(_.AREA_HEIGHT, oArea);

                        // We want one placeable per 8 tiles.
                        int nMax = (nSizeX * nSizeY) / 8;
                        LoggingService.Trace(TraceComponent.Weather, "Creating up to " + nMax.ToString() + " mist objects.");

                        for (int nCount = _.d6(); nCount < nMax; nCount++)
                        {
                            Vector vPosition = _.GetPosition(_.GetEnteringObject());

                            // Vectors are in meters - 10 meters to a tile.
                            vPosition.m_X = _.IntToFloat(_.Random(nSizeX * 10));
                            vPosition.m_Y = _.IntToFloat(_.Random(nSizeY * 10));

                            float fFacing = _.IntToFloat(_.Random(360));

                            string sResRef = "x3_plc_mist";

                            NWPlaceable oPlaceable = _.CreateObject(_.OBJECT_TYPE_PLACEABLE, sResRef, _.Location(oArea, vPosition, fFacing));
                            _.SetObjectVisualTransform(oPlaceable, _.OBJECT_VISUAL_TRANSFORM_SCALE, _.IntToFloat(200 + _.Random(200)) / 100.0f);

                            weatherObjects.Add(oPlaceable);
                        }
                    }

                    oArea.Data["WEATHER_OBJECTS"] = weatherObjects;
                    oArea.SetLocalInt("WEATHER_LAST_HOUR", nHour);
                }
            }
        }