private void HandleRecoveryBlast()
        {
            DamageData data     = _nwnxDamage.GetDamageEventData();
            NWObject   damager  = data.Damager;
            bool       isActive = damager.GetLocalInt("RECOVERY_BLAST_ACTIVE") == TRUE;

            damager.DeleteLocalInt("RECOVERY_BLAST_ACTIVE");
            NWItem weapon = _.GetLastWeaponUsed(damager.Object);

            if (!isActive || weapon.CustomItemType != CustomItemType.BlasterRifle)
            {
                return;
            }

            data.Bludgeoning = 0;
            data.Pierce      = 0;
            data.Slash       = 0;
            data.Magical     = 0;
            data.Acid        = 0;
            data.Cold        = 0;
            data.Divine      = 0;
            data.Electrical  = 0;
            data.Fire        = 0;
            data.Negative    = 0;
            data.Positive    = 0;
            data.Sonic       = 0;
            data.Base        = 0;

            _nwnxDamage.SetDamageEventData(data);
        }
        private void HandleTranquilizerEffect()
        {
            DamageData data = _nwnxDamage.GetDamageEventData();

            if (data.Total <= 0)
            {
                return;
            }
            NWObject self = Object.OBJECT_SELF;

            // Ignore the first damage because it occurred during the application of the effect.
            if (self.GetLocalInt("TRANQUILIZER_EFFECT_FIRST_RUN") > 0)
            {
                self.DeleteLocalInt("TRANQUILIZER_EFFECT_FIRST_RUN");
                return;
            }

            for (Effect effect = _.GetFirstEffect(self.Object); _.GetIsEffectValid(effect) == TRUE; effect = _.GetNextEffect(self.Object))
            {
                if (_.GetEffectTag(effect) == "TRANQUILIZER_EFFECT")
                {
                    _.RemoveEffect(self, effect);
                }
            }
        }
Exemple #3
0
        private bool CheckEndRound(NWObject table, float delay = 0.0f)
        {
            // SpeakString("DEBUG: Checking end round.  Player 1 standing? " + game.player1Standing + " Player 2 standing? " + game.player2Standing + " Scores: " + game.player1Score + "/" + game.player2Score);
            // If the game is already over, skip the rest.
            if (table.GetLocalInt("IN_GAME") == 0)
            {
                return(true);
            }

            if (game.player1Score > 20 || game.player2Score > 20 || (game.player1Standing && game.player2Standing))
            {
                game.EndRound();

                if (game.player1Sets == 3)
                {
                    DelayCommand(0.5f + delay, () =>
                    {
                        SpeakString(GetName(game.player1) + " wins, 3 sets to " + game.player2Sets + "!");
                    });
                    PazaakService.EndGame(table, game);
                    table.DeleteLocalInt("IN_GAME");
                }
                else if (game.player2Sets == 3)
                {
                    DelayCommand(1.5f + delay, () =>
                    {
                        SpeakString(GetName(game.player2) + " wins, 3 sets to " + game.player1Sets + "!");
                    });
                    PazaakService.EndGame(table, game);
                    table.DeleteLocalInt("IN_GAME");
                }
                else
                {
                    DelayCommand(1.5f + delay, () =>
                    {
                        SpeakString("New set beginning.  " + GetName(game.player1) + " has won " + game.player1Sets + " sets, " +
                                    GetName(game.player2) + " has won " + game.player2Sets + " sets. " + GetName(game.nextTurn) + " to play.");
                    });
                }

                return(true);
            }

            return(false);
        }
Exemple #4
0
 public static void SetActiveLanguage(NWObject obj, SkillType language)
 {
     if (language == SkillType.Basic)
     {
         obj.DeleteLocalInt("ACTIVE_LANGUAGE");
     }
     else
     {
         obj.SetLocalInt("ACTIVE_LANGUAGE", (int)language);
     }
 }
Exemple #5
0
        private static void HandleApplySneakAttackDamage()
        {
            DamageEventData data = NWNXDamage.GetDamageEventData();

            if (data.Total <= 0)
            {
                return;
            }
            NWObject damager         = data.Damager;
            int      sneakAttackType = damager.GetLocalInt("SNEAK_ATTACK_ACTIVE");

            if (damager.IsPlayer && sneakAttackType > 0)
            {
                NWPlayer   player    = damager.Object;
                NWCreature target    = _.OBJECT_SELF;
                var        pcPerk    = PerkService.GetPCPerkByID(damager.GlobalID, (int)PerkType.SneakAttack);
                int        perkRank  = pcPerk?.PerkLevel ?? 0;
                int        perkBonus = 1;

                // Rank 4 increases damage bonus by 2x (total: 3x)
                if (perkRank == 4)
                {
                    perkBonus = 2;
                }

                float perkRate;
                if (sneakAttackType == 1) // Player is behind target.
                {
                    perkRate = 1.0f * perkBonus;
                }
                else // Player is anywhere else.
                {
                    perkRate = 0.5f * perkBonus;
                }

                var   effectiveStats = PlayerStatService.GetPlayerItemEffectiveStats(player);
                float damageRate     = 1.0f + perkRate + effectiveStats.SneakAttack * 0.05f;
                data.Base = (int)(data.Base * damageRate);

                if (target.IsNPC)
                {
                    EnmityService.AdjustEnmity(target, player, 5 * data.Base);
                }

                NWNXDamage.SetDamageEventData(data);
            }

            damager.DeleteLocalInt("SNEAK_ATTACK_ACTIVE");
        }
Exemple #6
0
        private void HandleApplySneakAttackDamage()
        {
            DamageData data            = _nwnxDamage.GetDamageEventData();
            NWObject   damager         = data.Damager;
            int        sneakAttackType = damager.GetLocalInt("SNEAK_ATTACK_ACTIVE");

            if (damager.IsPlayer && sneakAttackType > 0)
            {
                NWPlayer   player    = (damager.Object);
                NWCreature target    = (Object.OBJECT_SELF);
                int        perkRank  = _perk.GetPCPerkByID(damager.GlobalID, (int)PerkType.SneakAttack).PerkLevel;
                int        perkBonus = 1;

                // Rank 4 increases damage bonus by 2x (total: 3x)
                if (perkRank == 4)
                {
                    perkBonus = 2;
                }

                float perkRate;
                if (sneakAttackType == 1) // Player is behind target.
                {
                    perkRate = 1.0f * perkBonus;
                }
                else // Player is anywhere else.
                {
                    perkRate = 0.5f * perkBonus;
                }

                var   effectiveStats = _playerStat.GetPlayerItemEffectiveStats(player);
                float damageRate     = 1.0f + perkRate + (effectiveStats.SneakAttack * 0.05f);
                data.Base = (int)(data.Base * damageRate);

                if (target.IsNPC)
                {
                    _enmity.AdjustEnmity(target, player, 5 * data.Base);
                }

                _nwnxDamage.SetDamageEventData(data);
            }

            damager.DeleteLocalInt("SNEAK_ATTACK_ACTIVE");
        }
Exemple #7
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());
        }
Exemple #8
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());
        }
Exemple #9
0
        private void LoadMainPage()
        {
            NWObject table = _.OBJECT_SELF;
            NWPlayer pc    = GetPC();

            game = PazaakService.GetCurrentGame(table);

            if (game == null && table.GetLocalInt("IN_GAME") == 2)
            {
                // Belt and bracers clean up code.
                table.DeleteLocalInt("IN_GAME");
            }

            // Check whether we have a game, or whether we should create one.
            if (table.GetLocalInt("IN_GAME") == 2)
            {
                CheckEndRound(table);

                if (game.nextTurn == pc)
                {
                    // Our turn.
                    BuildTurnOptions(pc);
                }
                else if (game.player2.IsNPC)
                {
                    // NPC turn.  Handle some
                    DoNPCTurn(game);
                    CheckEndRound(table);
                    if (game.nextTurn == game.player2)
                    {
                        DoNPCTurn(game);
                    }
                    BuildTurnOptions(pc);
                }
                else
                {
                    // Other player turn.
                    SetPageHeader("MainPage", "It is not currently your turn.");
                    ClearPageResponses("MainPage");
                }
            }
            // Table is open for a second player.
            else if (table.GetLocalInt("IN_GAME") == 1)
            {
                NWObject collection = pc.GetLocalObject("ACTIVE_COLLECTION");

                if (GetName(table.GetLocalObject("PLAYER_1")) == pc.Name)
                {
                    SetPageHeader("MainPage", "You are waiting for an opponent here.  Or play against the host.");
                    ClearPageResponses("MainPage");
                    AddResponseToPage("MainPage", "Table host (NPC)");
                }
                // Check that the player has an active Pazaak deck.
                else if (collection.IsValid)
                {
                    SetPageHeader("MainPage", GetName(table.GetLocalObject("PLAYER_1")) + " is waiting for an opponent.  Join game?");
                    ClearPageResponses("MainPage");
                    AddResponseToPage("MainPage", "Join game");
                }
                else
                {
                    SetPageHeader("MainPage", "Use your Pazaak Collection on this table to join the game.");
                    ClearPageResponses("MainPage");
                }
            }
            // Create a game.  Offer the PC a choice of vs NPC or vs Player.
            else
            {
                NWObject collection = pc.GetLocalObject("ACTIVE_COLLECTION");
                // Check that the player has an active Pazaak deck.
                if (collection.IsValid)
                {
                    table.SetLocalInt("IN_GAME", 1);
                    table.SetLocalObject("PLAYER_1", pc);
                    table.DeleteLocalObject("PLAYER_2");

                    SetPageHeader("MainPage", "Game created.  Will this be against another player, or the table owner?");
                    ClearPageResponses("MainPage");
                    AddResponseToPage("MainPage", "A player");
                    AddResponseToPage("MainPage", "Table host (NPC)");
                }
                else
                {
                    SetPageHeader("MainPage", "Use your Pazaak Collection on this table to join the game.");
                    ClearPageResponses("MainPage");
                }
            }
        }