private void MainPageInit(DialogPage page)
        {
            var player              = GetPC();
            var playerId            = GetObjectUUID(player);
            var dbPlayerTripleTriad = DB.Get <PlayerTripleTriad>(playerId) ?? new PlayerTripleTriad();
            var model = GetDataModel <Model>();

            page.Header = "Which deck would you like to use?";

            page.AddResponse(ColorToken.Green("View Cards"), () => SwitchConversation(nameof(TripleTriadPlayerDialog)));

            foreach (var(_, deck) in dbPlayerTripleTriad.Decks)
            {
                if (deck.Card1 != CardType.Invalid &&
                    deck.Card2 != CardType.Invalid &&
                    deck.Card3 != CardType.Invalid &&
                    deck.Card4 != CardType.Invalid &&
                    deck.Card5 != CardType.Invalid)
                {
                    page.AddResponse($"Choose Deck: {deck.Name}", () =>
                    {
                        TripleTriad.StartGame(player, deck, OBJECT_SELF, model.NPCDeck);
                        EndConversation();
                    });
                }
            }
        }
        /// <summary>
        /// Draws a single card at a location on the player's screen.
        /// </summary>
        /// <param name="player">The player to draw for.</param>
        /// <param name="cardType">The type of card to draw on screen.</param>
        /// <param name="x">The X coordinate to draw at.</param>
        /// <param name="y">The Y coordinate to draw at.</param>
        /// <param name="deckSlot">The deck card slot to draw at (between 1 and 5)</param>
        private static void DrawCard(uint player, CardType cardType, int x, int y, int deckSlot)
        {
            var card           = TripleTriad.GetCardByType(cardType);
            var elementTexture = TripleTriad.GetElementTexture(card.Element);

            var startId     = _idReservation.StartId + (deckSlot * CardParts);
            var topPower    = card.TopPower > 9 ? "A" : card.TopPower.ToString();
            var bottomPower = card.BottomPower > 9 ? "A" : card.BottomPower.ToString();
            var leftPower   = card.LeftPower > 9 ? "A" : card.LeftPower.ToString();
            var rightPower  = card.RightPower > 9 ? "A" : card.RightPower.ToString();

            // Display the power ranks if all of them are greater than zero.
            if (card.TopPower > 0 && card.BottomPower > 0 && card.LeftPower > 0 && card.RightPower > 0)
            {
                PostString(player, topPower, x + 3, y + 1, ScreenAnchor.TopLeft, 1.1f, Gui.ColorWhite, Gui.ColorWhite, startId, Gui.TextName);
                PostString(player, leftPower + " " + rightPower, x + 2, y + 2, ScreenAnchor.TopLeft, 1.1f, Gui.ColorWhite, Gui.ColorWhite, startId + 1, Gui.TextName);
                PostString(player, bottomPower, x + 3, y + 3, ScreenAnchor.TopLeft, 1.1f, Gui.ColorWhite, Gui.ColorWhite, startId + 2, Gui.TextName);
            }
            // Otherwise assume a card isn't selected. Only display the card deck slot in this case.
            else
            {
                PostString(player, $"Card #{deckSlot}", x + 3, y + 1, ScreenAnchor.TopLeft, 1.1f, Gui.ColorWhite, Gui.ColorWhite, startId, Gui.TextName);
            }

            PostString(player, TextureGlyph, x + 10, y + 1, ScreenAnchor.TopLeft, 1.1f, Gui.ColorWhite, Gui.ColorWhite, startId + 3, elementTexture);
            PostString(player, TextureGlyph, x, y, ScreenAnchor.TopLeft, 1.1f, Gui.ColorWhite, Gui.ColorWhite, startId + 4, card.Texture);
            PostString(player, TextureGlyph, x, y, ScreenAnchor.TopLeft, 1.1f, Gui.ColorWhite, Gui.ColorWhite, startId + 5, "fnt_card_back");
        }
        /// <summary>
        /// Handles the card list logic.
        /// </summary>
        /// <param name="page">The page to build</param>
        private void ViewCardsPageInit(DialogPage page)
        {
            var model               = GetDataModel <Model>();
            var player              = GetPC();
            var playerId            = GetObjectUUID(player);
            var dbPlayerTripleTriad = DB.Get <PlayerTripleTriad>(playerId) ?? new PlayerTripleTriad();
            var availableCards      = TripleTriad.GetAllCardsAtLevel(model.SelectedCardLevel);

            page.Header = $"{ColorToken.Green("Level: ")} {model.SelectedCardLevel}\n\n" +
                          $"The following is the list of cards available at this level. Cards in {ColorToken.Green("GREEN")} have been acquired. Those in {ColorToken.Red("RED")} have not. Only one card per type can be collected.\n\n" +
                          "Please select a card.";

            foreach (var(type, card) in availableCards)
            {
                if (!card.IsVisibleInMenu)
                {
                    continue;
                }

                var option = dbPlayerTripleTriad.AvailableCards.ContainsKey(type)
                    ? ColorToken.Green(card.Name)
                    : ColorToken.Red(card.Name);

                page.AddResponse(option, () =>
                {
                    model.SelectedCardType = type;
                    SetLocalInt(player, "CARD_MENU_SELECTED_CARD_ID", (int)model.SelectedCardType);
                    ChangePage(ViewCardDetailsPageId);
                });
            }
        }
Ejemplo n.º 4
0
            public TripleTriad Clone()
            {
                TripleTriad tt = (TripleTriad)MemberwiseClone();

                tt.cards = new OrderedDictionary <Cards.ID, TTCardInfo>(cards.Count);
                foreach (KeyValuePair <Cards.ID, TTCardInfo> i in cards)
                {
                    tt.cards.TryAdd(i.Key, i.Value.Clone());
                }
                tt.cards_rare = (byte[])cards_rare.Clone();
                return(tt);
            }
        /// <summary>
        /// Handles the card details logic.
        /// </summary>
        /// <param name="page">The page to build</param>
        private void ViewCardDetailsPageInit(DialogPage page)
        {
            var player              = GetPC();
            var playerId            = GetObjectUUID(player);
            var dbPlayerTripleTriad = DB.Get <PlayerTripleTriad>(playerId);
            var model        = GetDataModel <Model>();
            var card         = TripleTriad.GetCardByType(model.SelectedCardType);
            var dateAcquired = dbPlayerTripleTriad.AvailableCards.ContainsKey(model.SelectedCardType)
                ? dbPlayerTripleTriad.AvailableCards[model.SelectedCardType].ToString("yyyy-MM-dd hh:mm:ss")
                : ColorToken.Red("Unacquired");

            page.Header = $"{ColorToken.Green("Name: ")} {card.Name}\n" +
                          $"{ColorToken.Green("Level: ")} {card.Level}\n" +
                          $"{ColorToken.Green("Date Acquired: ")} {dateAcquired}";
        }
Ejemplo n.º 6
0
 public Data()
 {
     //Define Containers
     _gfs         = new Dictionary <GFs, GFData>(16);
     _characters  = new Dictionary <Characters, CharacterData>(8);
     _shops       = new List <Shop>(20);
     Items        = new List <Item>(198);
     TimePlayed   = new TimeSpan();
     CoordinateX  = new short[3];
     CoordinateY  = new short[3];
     TriangleID   = new ushort[3];
     FieldVars    = new FieldVars();    //0x0D70 http://wiki.ffrtt.ru/index.php/FF8/Variables
     WorldMap     = new Worldmap();     //br.ReadBytes(128);//0x1270
     TripleTriad  = new TripleTriad();  //br.ReadBytes(128);//0x12F0
     ChocoboWorld = new ChocoboWorld(); //br.ReadBytes(64);//0x1370
 }
        /// <summary>
        /// Handles the card selection logic for deck building.
        /// This differs from the card viewer in that cards show based on which cards the player owns.
        /// </summary>
        /// <param name="page">The page to build.</param>
        private void DeckCardSelectionListPageInit(DialogPage page)
        {
            var player              = GetPC();
            var playerId            = GetObjectUUID(player);
            var dbPlayerTripleTriad = DB.Get <PlayerTripleTriad>(playerId);
            var model        = GetDataModel <Model>();
            var cardsAtLevel = TripleTriad.GetAllCardsAtLevel(model.SelectedCardLevel);

            page.Header = $"{ColorToken.Green("Level: ")} {model.SelectedCardLevel}\n\n" +
                          "Please select cards to add to this deck.";

            if (model.CurrentCardNumber > 1)
            {
                page.AddResponse(ColorToken.Red("Remove Card"), RemoveTopMostCard);
            }

            foreach (var(cardType, card) in cardsAtLevel)
            {
                if (!card.IsVisibleInMenu)
                {
                    continue;
                }

                // Only one of each card type can be added to decks.
                if (IsInActiveDeck(cardType))
                {
                    continue;
                }

                if (dbPlayerTripleTriad.AvailableCards.ContainsKey(cardType))
                {
                    page.AddResponse($"Add: {card.Name}", () =>
                    {
                        SetLocalInt(player, $"CARD_MENU_DECK_CARD_{model.CurrentCardNumber}", (int)cardType);
                        model.CurrentCardNumber++;

                        // This was the last card.
                        if (model.CurrentCardNumber > 5)
                        {
                            ChangePage(DeckCardSelectionConfirmDeckPageId);
                        }
                    });
                }
            }
        }
Ejemplo n.º 8
0
            /// <summary>
            /// preforms a Shadow Copy. Then does deep copy on any required objects.
            /// </summary>
            /// <returns></returns>
            public Data Clone()
            {
                Memory.Log.WriteLine($"{nameof(Saves)} :: {nameof(Data)} :: {nameof(Clone)} ");
                //shadow copy
                Data d = (Data)MemberwiseClone();

                //deep copy anything that needs it here.

                d._characters            = _characters.ToDictionary(x => x.Key, x => (CharacterData)x.Value.Clone());
                d._gfs                   = _gfs.ToDictionary(x => x.Key, x => (GFData)x.Value.Clone());
                d.ChocoboWorld           = ChocoboWorld.Clone();
                d.FieldVars              = FieldVars.Clone();
                d.WorldMap               = WorldMap.Clone();
                d.TripleTriad            = TripleTriad.Clone();
                d.LimitBreakAngeloPoints = LimitBreakAngeloPoints.ToDictionary(x => x.Key, x => x.Value);
                d._shops                 = _shops.Select(x => x.Clone()).ToList();
                d.Items                  = Items.Select(x => x.Clone()).ToList();
                return(d);
            }
        /// <summary>
        /// Handles the card selection level logic for deck building.
        /// This differs from the card viewer in that levels show based on which cards the player owns.
        /// </summary>
        /// <param name="page">The page to build.</param>
        private void DeckCardSelectionLevelsPageInit(DialogPage page)
        {
            var player              = GetPC();
            var playerId            = GetObjectUUID(player);
            var dbPlayerTripleTriad = DB.Get <PlayerTripleTriad>(playerId);
            var model  = GetDataModel <Model>();
            var levels = new HashSet <int>();

            page.Header = "Please select cards to add to this deck.";

            if (model.CurrentCardNumber > 1)
            {
                page.AddResponse(ColorToken.Red("Remove Card"), RemoveTopMostCard);
            }

            foreach (var(cardType, _) in dbPlayerTripleTriad.AvailableCards)
            {
                var card = TripleTriad.GetCardByType(cardType);

                if (!card.IsVisibleInMenu)
                {
                    continue;
                }

                if (!levels.Contains(card.Level))
                {
                    levels.Add(card.Level);
                }
            }

            page.Header = $"{ColorToken.Green("Select card #")} {model.CurrentCardNumber}";

            foreach (var level in levels)
            {
                page.AddResponse($"Level {level}", () =>
                {
                    model.SelectedCardLevel = level;
                    ChangePage(DeckCardSelectionListPageId);
                });
            }
        }
        public static void UseCard()
        {
            var player = GetLastUsedBy();

            if (!GetIsPC(player) || GetIsDM(player))
            {
                return;
            }

            var playerId            = GetObjectUUID(player);
            var dbPlayerTripleTriad = DB.Get <PlayerTripleTriad>(playerId) ?? new PlayerTripleTriad();

            foreach (var(cardType, card) in TripleTriad.GetAllAvailableCards())
            {
                dbPlayerTripleTriad.AvailableCards[cardType] = DateTime.UtcNow;
            }

            DB.Set(playerId, dbPlayerTripleTriad);

            SendMessageToPC(player, "All Triple Triad cards received! OMGZ");
        }
Ejemplo n.º 11
0
        public static void StartCardGame(uint player, string[] args)
        {
            var npc    = OBJECT_SELF;
            var levels = new List <int>();

            foreach (var arg in args)
            {
                if (int.TryParse(arg, out var level))
                {
                    if (level >= 1 && level <= 10)
                    {
                        levels.Add(level);
                    }
                }
            }

            if (levels.Count <= 0)
            {
                SpeakString("ERROR: Deck levels were not defined! Notify an admin that this conversation is broken.");
                return;
            }

            // Build a random NPC deck out of the levels assigned.
            var firstLevel = levels[0];

            levels.RemoveAt(0);
            var npcDeck = TripleTriad.BuildRandomDeck(firstLevel, levels.ToArray());

            SetLocalInt(npc, "NPC_DECK_CARD_1", (int)npcDeck.Card1);
            SetLocalInt(npc, "NPC_DECK_CARD_2", (int)npcDeck.Card2);
            SetLocalInt(npc, "NPC_DECK_CARD_3", (int)npcDeck.Card3);
            SetLocalInt(npc, "NPC_DECK_CARD_4", (int)npcDeck.Card4);
            SetLocalInt(npc, "NPC_DECK_CARD_5", (int)npcDeck.Card5);

            DelayCommand(0.1f, () =>
            {
                Dialog.StartConversation(player, npc, nameof(TripleTriadVersusDialog));
            });
        }
        public static void StartCardGame(uint player, string[] args)
        {
            var npc    = OBJECT_SELF;
            var levels = new List <int>();

            foreach (var arg in args)
            {
                if (int.TryParse(arg, out var level))
                {
                    if (level >= 1 && level <= 10)
                    {
                        levels.Add(level);
                    }
                }
            }

            if (levels.Count <= 0)
            {
                Log.Write(LogGroup.Error, $"{GetName(player)} tried to start card game with {GetName(OBJECT_SELF)} but no levels were defined.", true);
                return;
            }

            // Build a random NPC deck out of the levels assigned.
            var firstLevel = levels[0];

            levels.RemoveAt(0);
            var npcDeck = TripleTriad.BuildRandomDeck(firstLevel, levels.ToArray());

            SetLocalInt(npc, "NPC_DECK_CARD_1", (int)npcDeck.Card1);
            SetLocalInt(npc, "NPC_DECK_CARD_2", (int)npcDeck.Card2);
            SetLocalInt(npc, "NPC_DECK_CARD_3", (int)npcDeck.Card3);
            SetLocalInt(npc, "NPC_DECK_CARD_4", (int)npcDeck.Card4);
            SetLocalInt(npc, "NPC_DECK_CARD_5", (int)npcDeck.Card5);

            DelayCommand(0.1f, () =>
            {
                Dialog.StartConversation(player, npc, nameof(TripleTriadVersusDialog));
            });
        }
        /// <summary>
        /// Handles main page logic.
        /// </summary>
        /// <param name="page">The page to build</param>
        private void MainPageInit(DialogPage page)
        {
            var player = GetPC();

            page.Header = ColorToken.Green("Triple Triad Menu");

            page.AddResponse("View Cards", () =>
            {
                SetLocalInt(player, "CARD_MENU_CURRENT_MODE", (int)Mode.CardViewer);
                ChangePage(ViewCardLevelsPageId);
            });
            page.AddResponse("Manage Decks", () =>
            {
                if (TripleTriad.DoesPlayerHavePendingGame(player))
                {
                    FloatingTextStringOnCreature("Decks cannot be managed while you have a game reservation pending. Cancel the reservation to manage your decks.", player, false);
                    return;
                }

                ChangePage(DeckListPageId);
            });
        }
        public static void SimulateTripleTriad()
        {
            var player1 = GetFirstPC();
            var player2 = GetNextPC();

            // Single player mode
            if (!GetIsObjectValid(player2))
            {
                var player = GetLastUsedBy();
                var deck1  = TripleTriad.BuildRandomDeck(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
                var deck2  = TripleTriad.BuildRandomDeck(10, 9, 8, 7);

                TripleTriad.StartGame(player, deck1, player, deck2);
            }

            // Two player mode
            else
            {
                var deck1 = TripleTriad.BuildRandomDeck(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
                var deck2 = TripleTriad.BuildRandomDeck(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);

                TripleTriad.StartGame(player1, deck1, player2, deck2);
            }
        }
        private void MainPageInit(DialogPage page)
        {
            var player              = GetPC();
            var playerId            = GetObjectUUID(player);
            var dbPlayerTripleTriad = DB.Get <PlayerTripleTriad>(playerId);
            var model        = GetDataModel <Model>();
            var deckSelected = ColorToken.Yellow("[NO DECK SELECTED]");

            if (model.SelectedDeckId > 0)
            {
                var deck = dbPlayerTripleTriad.Decks[model.SelectedDeckId];
                deckSelected = string.IsNullOrWhiteSpace(deck.Name)
                    ? $"Deck #{model.SelectedDeckId}"
                    : deck.Name;
            }

            page.Header = "You can create or join Triple Triad games here. You can customize your decks and view your cards from the rest menu (press 'R') or by clicking 'View Cards' here.\n\n" +
                          ColorToken.Green("Deck: ") + deckSelected;

            page.AddResponse(ColorToken.Green("Refresh"), () => { });
            page.AddResponse("View Cards", () => SwitchConversation(nameof(TripleTriadPlayerDialog)));

            // Player has a game reservation. Give them the option to close it.
            if (TripleTriad.DoesPlayerHavePendingGame(player))
            {
                if (model.IsConfirming)
                {
                    page.AddResponse("CONFIRM CANCEL RESERVATION", () =>
                    {
                        model.IsConfirming = false;

                        if (TripleTriad.DoesPlayerHavePendingGame(player))
                        {
                            TripleTriad.RemovePlayerPendingGame(player);
                        }

                        FloatingTextStringOnCreature("Game reservation has been cancelled.", player, false);
                    });
                }
                else
                {
                    page.AddResponse("Cancel Game Reservation", () =>
                    {
                        model.IsConfirming = true;
                    });
                }
            }
            // Otherwise let them create a new game or join someone else's game.
            else
            {
                page.AddResponse("Select Deck", () =>
                {
                    ChangePage(SelectDeckPageId);
                });

                if (model.SelectedDeckId > 0)
                {
                    var deck = dbPlayerTripleTriad.Decks[model.SelectedDeckId];
                    page.AddResponse("Create New Game", () =>
                    {
                        TripleTriad.CreatePendingGame(player, new CardPendingGame
                        {
                            Player1Deck = deck
                        });

                        EndConversation();
                        FloatingTextStringOnCreature("Game has been created. Please wait for another player to join. Leaving the area or server will remove your game reservation.", player, false);
                    });

                    foreach (var(gameOwner, pendingGame) in TripleTriad.GetAllPendingGames())
                    {
                        page.AddResponse($"Join Game: {GetName(gameOwner)}", () =>
                        {
                            if (!TripleTriad.DoesPlayerHavePendingGame(gameOwner) || // Game no longer exists
                                !GetIsObjectValid(gameOwner) ||                      // Game owner is no longer valid
                                GetTag(GetArea(gameOwner)) == "tt_arena")            // Game owner has entered a game
                            {
                                FloatingTextStringOnCreature("This game is no longer available.", player, false);
                                return;
                            }

                            EndConversation();
                            TripleTriad.StartGame(gameOwner, pendingGame.Player1Deck, player, deck); // todo: rule config
                        });
                    }
                }
            }
        }
        public static void ClearPendingGameOnExit()
        {
            var player = GetExitingObject();

            TripleTriad.RemovePlayerPendingGame(player);
        }