public void CopyVariables(NWObject oSource, NWObject oCopy)
        {
            int variableCount = _nwnxObject.GetLocalVariableCount(oSource);

            for (int variableIndex = 0; variableIndex < variableCount - 1; variableIndex++)
            {
                LocalVariable stCurVar = _nwnxObject.GetLocalVariable(oSource, variableIndex);

                switch (stCurVar.Type)
                {
                case LocalVariableType.Int:
                    oCopy.SetLocalInt(stCurVar.Key, oSource.GetLocalInt(stCurVar.Key));
                    break;

                case LocalVariableType.Float:
                    oCopy.SetLocalFloat(stCurVar.Key, oSource.GetLocalFloat(stCurVar.Key));
                    break;

                case LocalVariableType.String:
                    oCopy.SetLocalString(stCurVar.Key, oSource.GetLocalString(stCurVar.Key));
                    break;

                case LocalVariableType.Object:
                    oCopy.SetLocalObject(stCurVar.Key, oSource.GetLocalObject(stCurVar.Key));
                    break;

                case LocalVariableType.Location:
                    oCopy.SetLocalLocation(stCurVar.Key, oSource.GetLocalLocation(stCurVar.Key));
                    break;
                }
            }
        }
Exemple #2
0
        public void ApplyEffects(NWCreature user, NWItem item, NWObject target, Location targetLocation, CustomData customData)
        {
            NWPlayer        player     = user.Object;
            ResourceQuality quality    = (ResourceQuality)target.GetLocalInt("RESOURCE_QUALITY");
            int             tier       = target.GetLocalInt("RESOURCE_TIER");
            int             remaining  = target.GetLocalInt("RESOURCE_COUNT") - 1;
            string          itemResref = target.GetLocalString("RESOURCE_RESREF");
            int             gemChance  = ResourceService.CalculateChanceForComponentBonus(player, tier, quality);
            int             roll       = RandomService.Random(1, 100);
            int             rank       = SkillService.GetPCSkillRank(player, SkillType.Harvesting);

            if (item.RecommendedLevel < rank)
            {
                rank = item.RecommendedLevel;
            }

            int difficulty = (tier - 1) * 10 + ResourceService.GetDifficultyAdjustment(quality);
            int delta      = difficulty - rank;

            int baseXP = 0;

            if (delta >= 6)
            {
                baseXP = 400;
            }
            else if (delta == 5)
            {
                baseXP = 350;
            }
            else if (delta == 4)
            {
                baseXP = 325;
            }
            else if (delta == 3)
            {
                baseXP = 300;
            }
            else if (delta == 2)
            {
                baseXP = 250;
            }
            else if (delta == 1)
            {
                baseXP = 225;
            }
            else if (delta == 0)
            {
                baseXP = 200;
            }
            else if (delta == -1)
            {
                baseXP = 150;
            }
            else if (delta == -2)
            {
                baseXP = 100;
            }
            else if (delta == -3)
            {
                baseXP = 50;
            }
            else if (delta == -4)
            {
                baseXP = 25;
            }

            int itemHarvestBonus = item.HarvestingBonus;
            int scanningBonus    = user.GetLocalInt(target.GlobalID.ToString());

            gemChance += itemHarvestBonus * 2 + scanningBonus * 2;

            baseXP = baseXP + scanningBonus * 5;

            // Spawn the normal resource.
            NWItem resource = CreateItemOnObject(itemResref, player);

            user.SendMessage("You harvest " + resource.Name + ".");

            // If player meets the chance to acquire a gem, create one and modify its properties.
            if (quality > ResourceQuality.Low && roll <= gemChance)
            {
                // Gemstone quality is determined by the quality of the vein.
                switch (quality)
                {
                case ResourceQuality.Normal:
                    resource = CreateItemOnObject("flawed_gemstone", player);
                    break;

                case ResourceQuality.High:
                    resource = CreateItemOnObject("gemstone", player);
                    break;

                case ResourceQuality.VeryHigh:
                    resource = CreateItemOnObject("perfect_gemstone", player);
                    break;
                }

                var ip = ResourceService.GetRandomComponentBonusIP(quality);
                BiowareXP2.IPSafeAddItemProperty(resource, ip.Item1, 0.0f, AddItemPropertyPolicy.IgnoreExisting, true, true);

                switch (ip.Item2)
                {
                case 0:
                    resource.Name = ColorTokenService.Green(resource.Name);
                    break;

                case 1:
                    resource.Name = ColorTokenService.Blue(resource.Name);
                    break;

                case 2:
                    resource.Name = ColorTokenService.Purple(resource.Name);
                    break;

                case 3:
                    resource.Name = ColorTokenService.Orange(resource.Name);
                    break;

                case 4:
                    resource.Name = ColorTokenService.LightPurple(resource.Name);
                    break;

                case 5:
                    resource.Name = ColorTokenService.Yellow(resource.Name);
                    break;

                case 6:
                    resource.Name = ColorTokenService.Red(resource.Name);
                    break;

                case 7:
                    resource.Name = ColorTokenService.Cyan(resource.Name);
                    break;
                }

                user.SendMessage("You harvest " + resource.Name + ".");
            }

            float decayMinimum = 0.03f;
            float decayMaximum = 0.07f;

            if (delta > 0)
            {
                decayMinimum += delta * 0.1f;
                decayMaximum += delta * 0.1f;
            }

            DurabilityService.RunItemDecay(player, item, RandomService.RandomFloat(decayMinimum, decayMaximum));
            int xp = baseXP;

            SkillService.GiveSkillXP(player, SkillType.Harvesting, xp);

            if (remaining <= 0)
            {
                NWPlaceable prop = target.GetLocalObject("RESOURCE_PROP_OBJ");

                if (prop.IsValid)
                {
                    prop.Destroy();
                }

                target.Destroy();
                user.DeleteLocalInt(target.GlobalID.ToString());
            }
            else
            {
                target.SetLocalInt("RESOURCE_COUNT", remaining);
            }

            ApplyEffectAtLocation(DurationType.Instant, EffectVisualEffect(VisualEffect.Vfx_Fnf_Summon_Monster_3), target.Location);
        }
Exemple #3
0
        public void ApplyEffects(NWCreature user, NWItem item, NWObject target, Location targetLocation, CustomData customData)
        {
            NWPlayer        player        = user.Object;
            ResourceQuality quality       = (ResourceQuality)target.GetLocalInt("RESOURCE_QUALITY");
            int             tier          = target.GetLocalInt("RESOURCE_TIER");
            int             remaining     = target.GetLocalInt("RESOURCE_COUNT") - 1;
            string          itemResref    = target.GetLocalString("RESOURCE_RESREF");
            int             ipBonusChance = _resource.CalculateChanceForComponentBonus(player, tier, quality);
            int             roll          = _random.Random(1, 100);
            int             rank          = _skill.GetPCSkillRank(player, SkillType.Harvesting);

            if (item.RecommendedLevel < rank)
            {
                rank = item.RecommendedLevel;
            }

            int difficulty = (tier - 1) * 10 + _resource.GetDifficultyAdjustment(quality);
            int delta      = difficulty - rank;

            int baseXP = 0;

            if (delta >= 6)
            {
                baseXP = 400;
            }
            else if (delta == 5)
            {
                baseXP = 350;
            }
            else if (delta == 4)
            {
                baseXP = 325;
            }
            else if (delta == 3)
            {
                baseXP = 300;
            }
            else if (delta == 2)
            {
                baseXP = 250;
            }
            else if (delta == 1)
            {
                baseXP = 225;
            }
            else if (delta == 0)
            {
                baseXP = 200;
            }
            else if (delta == -1)
            {
                baseXP = 150;
            }
            else if (delta == -2)
            {
                baseXP = 100;
            }
            else if (delta == -3)
            {
                baseXP = 50;
            }
            else if (delta == -4)
            {
                baseXP = 25;
            }

            int itemHarvestBonus = item.HarvestingBonus;
            int scanningBonus    = user.GetLocalInt(target.GlobalID.ToString());

            ipBonusChance += itemHarvestBonus * 2 + scanningBonus * 2;

            baseXP = baseXP + scanningBonus * 5;

            NWItem resource = _.CreateItemOnObject(itemResref, player.Object);

            if (roll <= ipBonusChance)
            {
                var ip = _resource.GetRandomComponentBonusIP(quality);
                _biowareXP2.IPSafeAddItemProperty(resource, ip.Item1, 0.0f, AddItemPropertyPolicy.IgnoreExisting, true, true);

                switch (ip.Item2)
                {
                case 0:
                    resource.Name = _color.Green(resource.Name);
                    break;

                case 1:
                    resource.Name = _color.Blue(resource.Name);
                    break;

                case 2:
                    resource.Name = _color.Purple(resource.Name);
                    break;

                case 3:
                    resource.Name = _color.Orange(resource.Name);
                    break;
                }
            }

            float decayMinimum = 0.03f;
            float decayMaximum = 0.07f;

            if (delta > 0)
            {
                decayMinimum += delta * 0.1f;
                decayMaximum += delta * 0.1f;
            }

            user.SendMessage("You harvest " + resource.Name + ".");
            _durability.RunItemDecay(player, item, _random.RandomFloat(decayMinimum, decayMaximum));
            int xp = baseXP;

            _skill.GiveSkillXP(player, SkillType.Harvesting, xp);

            if (remaining <= 0)
            {
                NWPlaceable prop = target.GetLocalObject("RESOURCE_PROP_OBJ");

                if (prop.IsValid)
                {
                    prop.Destroy();
                }

                target.Destroy();
                user.DeleteLocalInt(target.GlobalID.ToString());
            }
            else
            {
                target.SetLocalInt("RESOURCE_COUNT", remaining);
            }

            _.ApplyEffectAtLocation(DURATION_TYPE_INSTANT, _.EffectVisualEffect(VFX_FNF_SUMMON_MONSTER_3), target.Location);
        }
Exemple #4
0
        private void BuildSideDeck(NWObject player)
        {
            NWItem     collection  = player.GetLocalObject("ACTIVE_COLLECTION");
            List <int> deckToBuild = new List <int>(4);
            List <int> playerDeck  = new List <int>(10);

            int random;

            if (collection.IsValid)
            {
                // We have a player with a real deck.  Build the list and select 4 random cards from it.
                for (int ii = 1; ii <= 10; ii++)
                {
                    playerDeck.Add(PazaakService.GetCardInCollection(PazaakService.GetCardInDeck(ii, collection), collection));
                }
            }
            else
            {
                // This is an NPC.  Give them a deck with 6 random + cards, 3-4 random - cards and 0-1 random wild card.
                // See PazaakCard.cs for values.
                if (RandomService.D6(1) == 6)
                {
                    playerDeck.Add(RandomService.D6(1));
                    playerDeck.Add(RandomService.D6(1));
                    playerDeck.Add(RandomService.D6(1));
                    playerDeck.Add(RandomService.D6(1));
                    playerDeck.Add(RandomService.D6(1));
                    playerDeck.Add(RandomService.D6(1));

                    playerDeck.Add(RandomService.D6(1) * -1);
                    playerDeck.Add(RandomService.D6(1) * -1);
                    playerDeck.Add(RandomService.D6(1) * -1);

                    playerDeck.Add(RandomService.D6(1) + 100);
                }
                else
                {
                    playerDeck.Add(RandomService.D6(1));
                    playerDeck.Add(RandomService.D6(1));
                    playerDeck.Add(RandomService.D6(1));
                    playerDeck.Add(RandomService.D6(1));
                    playerDeck.Add(RandomService.D6(1));
                    playerDeck.Add(RandomService.D6(1));

                    playerDeck.Add(RandomService.D6(1) * -1);
                    playerDeck.Add(RandomService.D6(1) * -1);
                    playerDeck.Add(RandomService.D6(1) * -1);
                    playerDeck.Add(RandomService.D6(1) * -1);
                }
            }

            random = RandomService.Random(10);
            deckToBuild.Add(playerDeck[random]);
            playerDeck.Remove(random);

            random = RandomService.Random(9);
            deckToBuild.Add(playerDeck[random]);
            playerDeck.Remove(random);

            random = RandomService.Random(8);
            deckToBuild.Add(playerDeck[random]);
            playerDeck.Remove(random);

            random = RandomService.Random(7);
            deckToBuild.Add(playerDeck[random]);
            playerDeck.Remove(random);

            if (player1 == player)
            {
                player1SideDeck = deckToBuild;
            }
            else
            {
                player2SideDeck = deckToBuild;
            }
        }
Exemple #5
0
 public static NWPlayer GetHoloGramOwner(NWObject hologram)
 {
     return(hologram.GetLocalObject("HOLOGRAM_OWNER"));
 }
Exemple #6
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");
                }
            }
        }
Exemple #7
0
        private void MainPageResponses(int responseID)
        {
            var      response = GetResponseByID("MainPage", responseID);
            NWObject table    = _.OBJECT_SELF;
            NWPlayer pc       = GetPC();

            game = PazaakService.GetCurrentGame(table);

            if (response.Text == "A player")
            {
                // Leave table open for PC to join.
                EndConversation();
            }
            else if (response.Text == "Table host (NPC)")
            {
                NWCreature NPC = GetNearestCreature(CreatureType.IsAlive, 1, pc.Object, 1, (int)CreatureType.PlayerCharacter, 0);

                if (NPC.IsValid)
                {
                    AssignCommand(NPC, () => { ActionMoveToObject(table); });
                    game = PazaakService.StartGame(table, pc, NPC);
                    table.SetLocalInt("IN_GAME", 2);

                    if (game.nextTurn == game.player2)
                    {
                        DelayCommand(2.0f, () => { DoNPCTurn(game); });
                    }
                }
                else
                {
                    pc.SendMessage("Sorry, this table has no host.");
                }

                EndConversation();
            }
            else if (response.Text == "Join game")
            {
                NWObject p1 = table.GetLocalObject("PLAYER_1");
                PazaakService.StartGame(table, p1, pc);
                table.SetLocalInt("IN_GAME", 2);

                EndConversation();
            }
            else if (response.Text.StartsWith("Play card from side deck"))
            {
                // Get the card value and modify the score.  Then rebuild the options.
                int    card     = Convert.ToInt32(GetResponseByID("MainPage", responseID).CustomData.ToString());
                string cardText = "You play a " + PazaakService.Display(card);

                if (pc == game.player1)
                {
                    game.player1SideDeck.Remove(card);
                }
                else
                {
                    game.player2SideDeck.Remove(card);
                }

                if (card > 100 && card < 107)
                {
                    // Make it a 1-6 number.
                    card -= 100;

                    if (response.Text.EndsWith("negative"))
                    {
                        // Played as negative, so flip the sign.
                        card *= -1;
                    }
                }

                if (card > 200)
                {
                    switch (card)
                    {
                    case 201:     // Flip
                    {
                        card = (pc == game.player1 ? game.player1HandCardsPlayedThisSet : game.player2HandCardsPlayedThisSet) * -2;
                        break;
                    }

                    case 202:     // Double
                    {
                        card = game.lastCardPlayed;
                        break;
                    }

                    case 203:     // Tiebreaker
                    {
                        card = 1;
                        if (response.Text.EndsWith("negative"))
                        {
                            // Played as negative, so flip the sign.
                            card *= -1;
                        }
                        game.tiebreaker = pc;
                        break;
                    }
                    }
                }

                int score;
                if (pc == game.player1)
                {
                    game.player1Score += card;
                    game.player1HandCardsPlayedThisSet += card;
                    score = game.player1Score;
                }
                else
                {
                    game.player2Score += card;
                    game.player2HandCardsPlayedThisSet += card;
                    score = game.player2Score;
                }

                pc.FloatingText(cardText + ". Your score is now " + score);
                SpeakString(pc.Name + " plays a " + cardText + ", taking their score to " + score);

                // Since we're having a turn, we can't be the one standing...
                bool bStand = game.player1Standing || game.player2Standing;

                string header = "Your score is at " + score + ". " + (bStand ? "The other player is standing. " : "") +
                                "What do you want to do?";

                SetPageHeader("MainPage", header);
                ClearPageResponses("MainPage");
                AddResponseToPage("MainPage", "End Turn", score < 21);
                AddResponseToPage("MainPage", "Stand");
            }
            else if (response.Text == "End Turn" || response.Text == "Stand")
            {
                // Whatever happens, end the dialog.
                EndConversation();

                // Process end turn responses, then do NPC turn if it's an NPC game.
                if (response.Text == "Stand")
                {
                    if (pc == game.player1)
                    {
                        game.player1Standing = true;
                    }
                    else
                    {
                        game.player2Standing = true;
                    }
                }

                // Record that it is time for the next player to take their turn, unless they are standing.
                if (pc == game.player1 && !game.player2Standing)
                {
                    game.nextTurn = game.player2;
                }
                else if (pc == game.player2 && !game.player1Standing)
                {
                    game.nextTurn = game.player1;
                }

                // If both players are PCs, we shouldn't have to do anything more now.  But if we're playing with an NPC, now the NPC needs
                // to take their turn.
                float delay = 1.0f;

                if (!CheckEndRound(table) && game.player2.IsNPC && !game.player2Standing)
                {
                    game = DoNPCTurn(game);

                    while (game.player2.IsNPC && game.player1Standing && !game.player2Standing && !CheckEndRound(table, delay))
                    {
                        // PC is standing, so keep playing NPC turns until the round ends.
                        game   = DoNPCTurn(game, delay);
                        delay += 1.0f;
                    }
                }

                CheckEndRound(table, delay);
            }
        }