示例#1
0
        /*
         * Responds to event called by client when they click UIButton:SaveBtn OR answering in the affirmitive on any UIAlert while this evaluation is true:
         * (UIGameCompDrawACardPluginEODStates:State == UIGameCompDrawACardPluginEODStates.EditSingleCard)
         * @param evt:String containing the name of the event
         * @param cardText:String containing the desired updated text of the card at Game.CurrentCardIndex
         * @note: Due to the MaxChars limit of 256 of the UITextEdit:EditCardTextEdit, cardText:String must not have a length greater than 256.
         * @note: No callback function is needed, which means the client's ability to interact with the UI is unaffected and not dependent on this handler.
         */
        void EditCurrentCardHandler(string evt, byte[] cardTextArray, VMEODClient client)
        {
            // client has to be the object owner
            bool isOwner = (((VMTSOObjectState)Server.Object.TSOState).OwnerID == UserClient.Avatar.PersistID);

            // validate the data
            bool   isValid  = false;
            string cardText = null;
            var    strings  = VMEODGameCompDrawACardData.DeserializeStrings(cardTextArray);

            if (strings != null)
            {
                cardText = strings[0];
            }
            if ((cardText != null) && (cardText.Length < 257))
            {
                isValid = true;
            }

            // If the user would like this card to be blank, replace the blank string with the name of the enum entry for custom.
            if (cardText.Length == 0)
            {
                cardText = VMEODGameCompDrawACardTypes.VMEODGameCompDrawACardCustom.ToString();
            }
            if ((isOwner) && (isValid))
            {
                if (!Game.CurrentCardText.Equals(cardText))
                {
                    DeckHasChanged = true;
                    Game.EditCurrentCard(cardText);
                    UserClient.Send("DrawCard_Update_Deck", GetDeckListBoxData());
                }
            }
        }
示例#2
0
        /// <summary>
        ///
        /// Note: Always called within locked PlayerConfigLock and ConnectedContestants.
        /// </summary>
        private void SendContestantRoster()
        {
            bool   atLeastOnePlayer = false;
            string evt = "Buzzer_Host_Roster";

            if (BuzzerEnabled)
            {
                evt = "Buzzer_Host_Live_Roster";
            }
            var data = new List <string>();

            for (int index = 0; index < 4; index++)
            {
                var player = ConnectedContestants[index];
                if (player != null && player.EODType.Equals(VMEODGameshowBuzzerPluginType.Player) && player.MyClient.Avatar != null)
                {
                    atLeastOnePlayer = true;
                    data.Add(player.MyClient.Avatar.ObjectID + "");
                    data.Add(player.MyScore + "");
                    data.Add((player.MyBuzzerEnabled ? "1" : "0"));
                }
                else
                {
                    data.AddRange(new string[] { "0", "0", "0" });
                }
            }
            // send to host UI
            MyClient.Send(evt, VMEODGameCompDrawACardData.SerializeStrings(data.ToArray()));
            // sent to object via Simantics
            Controller.SendOBJEvent(new Model.VMEODEvent((short)VMEODGameshowHostPluginEvents.Update_Players_Connected, (short)(atLeastOnePlayer ? 1 : 0)));
        }
示例#3
0
 private byte[] GetCurrentCardData()
 {
     if ((Game.CurrentCardText == null) || (Game.CurrentCardText == ""))
     {
         return(null);
     }
     else
     {
         return(VMEODGameCompDrawACardData.SerializeStrings(Game.CurrentCardText, Game.CurrentCardFrequency + ""));
     }
 }
示例#4
0
        /*
         * Called on Event:"eod_close" ?
         * @param evt:String containing the name of the event
         * @param newCardTextAndFrequency:String containing the desired new name and description to be set as Game.GameTitle and Game.Description
         */
        void EditGameHandler(string evt, byte[] gameTitleAndDescriptionByteArray, VMEODClient client)
        {
            if (gameTitleAndDescriptionByteArray == null)
            {
                return;
            }

            // client has to be the object owner
            bool isOwner = (((VMTSOObjectState)Server.Object.TSOState).OwnerID == UserClient.Avatar.PersistID);

            // validate the data
            bool isValid = false;

            string[] gameInfo = VMEODGameCompDrawACardData.DeserializeStrings(gameTitleAndDescriptionByteArray);
            if (gameInfo.Length > 1)
            {
                if ((gameInfo[0].Length < 53) && (gameInfo[1].Length < 257))
                {
                    isValid = true;
                    // If the user would like the game title to be blank, replace the blank string with the name of the enum entry for custom.
                    if (gameInfo[0].Length == 0)
                    {
                        gameInfo[0] = VMEODGameCompDrawACardTypes.VMEODGameCompDrawACardCustom.ToString();
                    }
                    // If the user would like the game description to be blank, replace the blank string with the name of the enum entry for custom.
                    if (gameInfo[1].Length == 0)
                    {
                        gameInfo[1] = VMEODGameCompDrawACardTypes.VMEODGameCompDrawACardCustom.ToString();
                    }
                }
            }
            if ((isOwner) && (isValid))
            {
                if (!Game.GameTitle.Equals(gameInfo[0]))
                {
                    DeckHasChanged = true;
                    Game.GameTitle = gameInfo[0];
                }
                if (!Game.GameDescription.Equals(gameInfo[1]))
                {
                    DeckHasChanged       = true;
                    Game.GameDescription = gameInfo[1];
                }
            }
        }
示例#5
0
        byte[] GetDeckListBoxData()
        {
            if (Game.UniqueCardCount == 0)
            {
                return new byte[] { 0 }
            }
            ;
            List <String> deckListBoxList = new List <string>();

            foreach (var card in Game.Deck)
            {
                // truncate each string to fit in the UIListBox but retain any possible Default strings in the enum below
                if (card.Text.Length > 40)
                {
                    deckListBoxList.Add(card.Text.Substring(0, 40));
                }
                else
                {
                    deckListBoxList.Add(card.Text);
                }
            }
            return(VMEODGameCompDrawACardData.SerializeStrings(deckListBoxList.ToArray()));
        }

        byte[] GetCurrentCardData()
        {
            if ((Game.CurrentCardText == null) || (Game.CurrentCardText == ""))
            {
                return(null);
            }
            else
            {
                return(VMEODGameCompDrawACardData.SerializeStrings(Game.CurrentCardText, Game.CurrentCardFrequency + ""));
            }
        }

        byte[] GetGameInfoMessage()
        {
            return(VMEODGameCompDrawACardData.SerializeStrings(Game.GameTitle, Game.GameDescription));
        }
    }
示例#6
0
        /*
         * Responds to event called by client when they click UIButton:SaveBtn OR answering in the affirmitive on any UIAlert while this evaluation is true:
         * (UIGameCompDrawACardPluginEODStates:State == UIGameCompDrawACardPluginEODStates.EditSingleCard)
         * @param evt:String containing the name of the event
         * @param newCardTextAndFrequency:String containing the desired text and frequency of the card to be added to Game
         * @callbackEvent:"DrawCard_Update_Deck" updates the client UI's variable of UIListBox:SelectCardList - background
         * @callbackEvent:"DrawCard_Update_Card" updates the client UI's variable of String:CurrentCardText - re-enables user interactions with the UI
         * @callbackEvent:"DrawCard_Update_Deck_Numbers" updates the client UI's variables of int:TotalUniqueCards and int:GrandTotalCards - background
         * @note: Due to the MaxChars limit of 256 of the UITextEdit:NewCardTextEdit, split[0] must not have a length greater than 256.
         * @note: split[1] contains a string that represents the new frequency that the card at Game.CurrentIndex should be set to in order to affect
         * its chances of being drawn. It must be greater than 0 and less than 100. This plugin does not support the preserving of cards with 0 frequency, and
         * due to the 2 character limit of the UITextEdit:NumDrawChancesTextEdit from which the value is taken, (int)split[1] cannot be greater than 100.
         */
        void PushNewCardHandler(string evt, byte[] newCardTextAndFrequencyArray, VMEODClient client)
        {
            if (newCardTextAndFrequencyArray == null)
            {
                return;
            }

            // client has to be the object owner
            bool isOwner = (((VMTSOObjectState)Server.Object.TSOState).OwnerID == UserClient.Avatar.PersistID);

            // validate the data
            bool isValid   = false;
            var  split     = VMEODGameCompDrawACardData.DeserializeStrings(newCardTextAndFrequencyArray);
            byte frequency = 100;

            if ((split.Length > 1) && (split[0].Length < 257))
            {
                if (Byte.TryParse(split[1], out frequency))
                {
                    isValid = true;
                }
                else
                {
                    frequency = 1;
                    isValid   = true;
                }
                // If the user would like this card to be blank, replace the blank string with the name of the enum entry for custom.
                if (split[0].Length == 0)
                {
                    split[0] = VMEODGameCompDrawACardTypes.VMEODGameCompDrawACardCustom.ToString();
                }
            }
            if ((isOwner) && (isValid) && (Game.UniqueCardCount < MAXIMUM_UNIQUE_CARDS))
            {
                DeckHasChanged = true;
                Game.PushNewCard(split[0], frequency);
                UserClient.Send("DrawCard_Update_Deck", GetDeckListBoxData());
                UserClient.Send("DrawCard_Update_Deck_Numbers", GetCardNumberData());
            }
            UserClient.Send("DrawCard_Update_Card", GetCurrentCardData());
        }
示例#7
0
        public CarducopiaDrawACardGame(VMEODGameCompDrawACardData data)
        {
            m_GameTitle       = data.GameTitle;
            m_GameDescription = data.GameDescription;
            Deck = new List <CarducopiaCard>();

            // data.CardText.Count SHOULD == data.EachCardsCount.Count, but just in case:
            int dataLimit = Math.Min(data.CardText.Count, data.EachCardsCount.Count);

            for (var index = 0; index < dataLimit; index++)
            {
                Deck.Add(new CarducopiaCard(data.CardText[index], data.EachCardsCount[index]));
            }
            m_UniqueCardCount = Deck.Count;
            CalculateGrandTotal();
            CurrentCardIndex = data.LastIndex;
            if (CurrentCardIndex > m_UniqueCardCount - 1)
            {
                CurrentCardIndex = 0;
            }
            UpdateCurrentCard();
        }
示例#8
0
        private byte[] GetDeckListBoxData()
        {
            if (Game.UniqueCardCount == 0)
            {
                return new byte[] { 0 }
            }
            ;
            List <String> deckListBoxList = new List <string>();

            foreach (var card in Game.Deck)
            {
                // truncate each string to fit in the UIListBox but retain any possible Default strings in the enum below
                if (card.Text.Length > 40)
                {
                    deckListBoxList.Add(card.Text.Substring(0, 40));
                }
                else
                {
                    deckListBoxList.Add(card.Text);
                }
            }
            return(VMEODGameCompDrawACardData.SerializeStrings(deckListBoxList.ToArray()));
        }
示例#9
0
 byte[] GetCardNumberData()
 {
     return(VMEODGameCompDrawACardData.SerializeStrings(Game.UniqueCardCount + "", Game.GrandTotalCardsCount + ""));
 }
示例#10
0
        public VMEODGameCompDrawACardPlugin(VMEODServer server) : base(server)
        {
            // create a default deck until data is retrieved from the server
            Game = new CarducopiaDrawACardGame();

            // Initialize Mode to the unused mode of the plugin
            Mode = VMEODGameCompDrawACardModes.CopyDeck;

            // event listeners & handlers
            BinaryHandlers["DrawCard_Delete_Card"]    = DeleteCurrentCardHandler;
            BinaryHandlers["DrawCard_Edit_Frequency"] = SetCardFrequencyHandler;
            BinaryHandlers["DrawCard_Goto_Card"]      = GotoCardHandler;
            BinaryHandlers["DrawCard_Edit_Card"]      = EditCurrentCardHandler;
            BinaryHandlers["DrawCard_Add_Card"]       = PushNewCardHandler;
            BinaryHandlers["DrawCard_Edit_Game"]      = EditGameHandler;
            PlaintextHandlers["DrawCard_Close"]       = CloseHandler;

            // try to get the data from the server
            server.vm.GlobalLink.LoadPluginPersist(server.vm, server.Object.PersistID, server.PluginID, (byte[] data) =>
            {
                lock (this)
                {
                    if (data == null)
                    {
                        Data = new VMEODGameCompDrawACardData();
                        ResponseFromServer = true;
                    }
                    else
                    {
                        Data = new VMEODGameCompDrawACardData(data);
                        // make a new game based on the received data
                        Game = new CarducopiaDrawACardGame(Data);
                        // update the UI
                        ResponseFromServer = true;
                    }
                }
                if (!UIInitialized)
                {
                    switch (Mode)
                    {
                    case VMEODGameCompDrawACardModes.Manage:
                        {
                            UIInitialized = true;
                            UserClient.Send("DrawCard_Update_Deck", GetDeckListBoxData());
                            UserClient.Send("DrawCard_Update_Deck_Numbers", GetCardNumberData());
                            UserClient.Send("DrawCard_Manage", GetGameInfoMessage());
                            break;
                        }

                    case VMEODGameCompDrawACardModes.ViewCurrent:
                        {
                            UIInitialized = true;
                            // send the card matching the last index
                            UserClient.Send("DrawCard_Drawn", GetCurrentCardData());
                            break;
                        }

                    case VMEODGameCompDrawACardModes.ViewDeck:
                        {
                            UIInitialized = true;
                            UserClient.Send("DrawCard_Update_Deck_Numbers", GetCardNumberData());
                            UserClient.Send("DrawCard_Info", GetGameInfoMessage());
                            break;
                        }

                    case VMEODGameCompDrawACardModes.Draw:
                        {
                            UIInitialized = true;
                            // randomly draw a card
                            int index = DrawCard.Next(0, Game.UniqueCardCount);
                            Game.GotoCard(index);
                            DeckHasChanged = true;

                            // send new card text to UI
                            UserClient.Send("DrawCard_Drawn", GetCurrentCardData());
                            break;
                        }
                    }
                }
            });
        }
示例#11
0
 private byte[] GetGameInfoMessage()
 {
     return(VMEODGameCompDrawACardData.SerializeStrings(Game.GameTitle, Game.GameDescription));
 }