示例#1
0
    //=====================================================

    public static ChestReward GetChestReward(eChestType type,
                                             eTradingCardClassification cardClassification,
                                             eTradingCardRarity cardRarity,
                                             eTradingCardCondition cardCondition)
    {
        var reward = new ChestReward();

        var rewardCard = (type == eChestType.LARGE &&
                          cardClassification != eTradingCardClassification.NULL &&
                          cardRarity != eTradingCardRarity.NULL);

        // 50% chance of awarding a card or gem
        if (rewardCard == false && Random.Range(0, 99) % 2 == 0)
        {
            rewardCard = true;
        }

        if (rewardCard == true)
        {
            reward.Card          = TradingCardItemsManager.GetCard(type, cardClassification, cardRarity, cardCondition);
            reward.CardCondition = cardCondition;
            //Debug.Log( "SceneManager: Reward card" );
        }
        else
        {
            // Small, medium or large number of gems
            var maxGems = Convert.ToInt32(SettingsManager.GetSettingsItem("AWARD_GEMS_CHEST_" + type, -1));

            reward.Gems = Random.Range(maxGems / 2, maxGems);
            //Debug.Log( "SceneManager: Reward gems" );
        }

        return(reward);
    }
示例#2
0
    //=============================================================================

    public void ShowPanel(bool bActive, List <TradingCardHeldItem> CardsInPack = null)
    {
        if (bActive)
        {
            m_bButtonPressed = false;
            m_MainPanel.SetActive(true);

            // Add card previews
            int   NumCards = CardsInPack.Count;
            float fWidth   = 17.0f + ((NumCards - 1) * 300.0f) + 240.0f + 17.0f;
            for (int Idx = 0; Idx < NumCards; Idx++)
            {
                GameObject NewCard = Instantiate(m_pfbCardFrame, new Vector3((float)Idx * 300.0f, 15.0f, 0.0f), Quaternion.identity) as GameObject;
                NewCard.transform.parent        = m_PreviewPanel.transform;
                NewCard.transform.localPosition = new Vector3(17.0f + ((float)Idx * 300.0f), -170.0f, 0.0f);

                // Setup card sprite image
                TradingCardSpreadsheetItem CurSpreadsheetCard = TradingCardItemsManager.GetTradingCardItem(CardsInPack[Idx].id);
                UnityEngine.UI.Image       RenderCardImage    = NewCard.transform.GetChild(0).gameObject.GetComponent(typeof(UnityEngine.UI.Image)) as UnityEngine.UI.Image;
                Sprite RenderSprite = (Sprite)Resources.Load("Cards/LargeGUITextures/" + CurSpreadsheetCard.largeGuiTexture2D, typeof(Sprite));

                RenderCardImage.sprite = RenderSprite;
            }

            //Rect NewRect = new Rect( m_PreviewPanel.GetComponent<RectTransform>().rect );
            //NewRect.width = fWidth;
            //m_PreviewPanel.GetComponent<RectTransform>().rect = NewRect;
            m_PreviewPanel.GetComponent <RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, fWidth);
        }
        else
        {
            // Delete all child objects of preview panel
            for (int i = m_PreviewPanel.transform.childCount - 1; i >= 0; --i)
            {
                GameObject child = m_PreviewPanel.transform.GetChild(i).gameObject;
                Destroy(child);
            }

            m_MainPanel.SetActive(false);
        }
    }
示例#3
0
    //=====================================================

    private IEnumerator ShowPopup(float delay)
    {
        yield return(new WaitForSeconds(delay));

        // Setup card GUI texture
        var CurSpreadsheetCard = TradingCardItemsManager.GetTradingCardItem(_currentCard.id);
        var RenderSprite       = (Sprite)Resources.Load("Cards/SmallGUITextures/" + CurSpreadsheetCard.smallGuiTexture2D, typeof(Sprite));

        m_RenderCardImage.sprite  = RenderSprite;
        m_RenderCardPosition.text = (CurSpreadsheetCard.globalPosition + 1).ToString();

        if (_currentCard.condition == eTradingCardCondition.MINT)
        {
            m_RenderCardOverlayImage.enabled = false;
        }
        else
        {
            m_RenderCardOverlayImage.enabled = true;
        }

        m_GUICamera.SetActive(true);
    }
示例#4
0
    //=====================================================
    // Returns common card from randomly selected card classification
    public static TradingCardSpreadsheetItem GetNPCReward()
    {
        var classification = (eTradingCardClassification)Random.Range(1, (int)eTradingCardClassification.NUM_ITEMS);

        return(TradingCardItemsManager.GetCard(eChestType.SMALL, classification, eTradingCardRarity.COMMON, eTradingCardCondition.MINT));
    }
示例#5
0
    //=====================================================

    public void OnButtonPressed_TypeStandard()
    {
        BookManager.instance.TurnToPage(TradingCardItemsManager.GetPageOffset(eTradingCardClassification.STANDARD));
    }
示例#6
0
    //=====================================================

    public void OnButtonPressed_TypeWinx()
    {
        BookManager.instance.TurnToPage(TradingCardItemsManager.GetPageOffset(eTradingCardClassification.WINX));
    }
示例#7
0
    //=====================================================

    void UpdateViewingBook()
    {
        // Update sprite that shows which page type we're on
        eTradingCardClassification VisibleClassification = TradingCardItemsManager.GetPageClassification(BookManager.instance.GetCurrentPage());

        foreach (GameObject sprClassification in m_sprPageTypes)
        {
            if (sprClassification != null)
            {
                sprClassification.SetActive(false);
            }
        }
        m_sprPageTypes[(int)VisibleClassification].SetActive(true);

        // Set the page shortcuts for this classification (prev/next)
        int PrevCategory = (int)VisibleClassification - 1;
        int NextCategory = (int)VisibleClassification + 1;

        // Skip 'story' class
        if (VisibleClassification == eTradingCardClassification.STANDARD)
        {
            PrevCategory--;
        }
        if (VisibleClassification == eTradingCardClassification.WILD)
        {
            NextCategory++;
        }

        //m_txtCategoryPrev.text = GetCategoryText( (eTradingCardClassification)PrevCategory );
        //m_txtCategoryNext.text = GetCategoryText( (eTradingCardClassification)NextCategory );

        // Check for swiping
        if (BookManager.instance.IsPageTurning())
        {
            return;
        }

        // Update area scrolling list position
        if (m_bSwiping)
        {
            m_SwipeTime      += Time.deltaTime;
            m_SwipeTimeAccum += Time.deltaTime;
            Vector3 WorldPos = m_BookCamera.ScreenToViewportPoint(Input.mousePosition);
            WorldPos *= 384.0f;
            float SwipingDeltaX = WorldPos.x - m_SwipingStartX;

            m_SwipingAccel = (WorldPos - m_LastWorldPos[3]).x;

            if (m_SwipeTimeAccum > (1.0f / 60.0f))
            {
                for (int MIdx = 3; MIdx > 0; MIdx--)
                {
                    m_LastWorldPos[MIdx] = m_LastWorldPos[MIdx - 1];
                }
                m_LastWorldPos[0] = WorldPos;
                m_SwipeTimeAccum -= (1.0f / 60.0f);
            }

            if (Input.GetMouseButtonUp(0))
            {
                m_bSwiping = false;

                m_SwipingAccel = Mathf.Clamp(m_SwipingAccel, -12.0f, 12.0f);

                bool bMinimumDistTravelled = true;

                if (Mathf.Abs(SwipingDeltaX) < 28.0f)
                {
                    bMinimumDistTravelled = false;
                }

                //Debug.Log( m_SwipingAccel + " " + bMinimumDistTravelled );
                if ((Mathf.Abs(m_SwipingAccel) < 7.0f) || (bMinimumDistTravelled == false))
                {
                    // No swipe - selection of a card?
                    m_SwipingAccel = 0.0f;
                    if ((m_SwipeTime < 0.25f) && (bMinimumDistTravelled == false))
                    {
                        // Selected card - check collision
                        int CurrentPage     = BookManager.instance.GetCurrentPage();
                        int CurrentPosition = BookManager.instance.GetPositionAtMouse();

                        // For first and last pages don't allow card selection
                        if (BookManager.instance.IsValidPage() == false)
                        {
                            CurrentPosition = -1;
                        }

                        if (CurrentPosition != -1)
                        {
                            // Valid card?
                            bool bValidCard = true;
                            TradingCardSpreadsheetItem CurSpreadsheetCard = TradingCardItemsManager.GetTradingCardItem(CurrentPage, CurrentPosition);
                            if (CurSpreadsheetCard == null)
                            {
                                bValidCard = false;
                            }

                            if (bValidCard)
                            {
                                // Set buy/sell mode based on whether we have the card or not
                                int NumMint    = 0;
                                int NumScuffed = 0;
                                TradingCardHeldItem CurHeldCard = GameDataManager.Instance.GetHeldTradingCard(CurSpreadsheetCard.id, ref NumMint, ref NumScuffed);

                                if (CurHeldCard != null)
                                {
                                    m_SelectedCardMode = eSelectedCardMode.Selling;
                                }
                                else
                                {
                                    m_SelectedCardMode = eSelectedCardMode.Buying;
                                }

                                // Show selected card panel
                                SelectedCardManager.instance.SetupPanel(m_SelectedCardMode, CurSpreadsheetCard, CurrentPosition, NumMint, NumScuffed);
                                SelectedCardManager.instance.ShowPanel(true);
                                SetRoomMode(eRoomMode.SelectedCard);

                                SoundFXManager.instance.PlaySound("CardSelect");


                                // Hide this card on the book so we can zoom into it
                                BookManager.instance.HideCard(CurrentPage, CurrentPosition);
                            }
                        }
                    }
                }
                else
                {
                    // Quick Swipe
                    if (m_SwipingAccel < 0.0f)
                    {
                        BookManager.instance.TurnPage(1);
                        SoundFXManager.instance.PlaySound("PageTurn");
                    }
                    else
                    {
                        BookManager.instance.TurnPage(-1);
                        SoundFXManager.instance.PlaySound("PageTurn");
                    }

                    m_SwipingAccel = 0.0f;
                }
            }
        }
        else
        {
            // Not swiping
            Vector3 WorldPos = m_BookCamera.ScreenToViewportPoint(Input.mousePosition);
            WorldPos *= 384.0f;
            for (int MIdx = 3; MIdx > 0; MIdx--)
            {
                m_LastWorldPos[MIdx] = WorldPos;
            }

            m_SwipingStartX  = WorldPos.x;
            m_SwipeTimeAccum = 0.0f;

            // Make sure pause menu or shop menu isn't active
            if ((PopupPause.Instance.IsActive == false) && (ShopManager.instance == false))
            {
                if (Input.GetMouseButtonDown(0))
                {
                    if ((WorldPos.y > 48.0f) && (WorldPos.y < 323.0f))
                    {
                        m_bSwiping     = true;
                        m_SwipingAccel = 0.0f;
                        m_SwipeTime    = 0.0f;
                    }
                }
            }
        }
    }
示例#8
0
    //=====================================================

    void UpdateBuyPackConfirm()
    {
        if (BuyPackConfirmManager.instance.WasButtonPressed())
        {
            switch (BuyPackConfirmManager.instance.GetButtonPressed())
            {
            case 0:
                // OK
                BuyPackConfirmManager.instance.ShowPanel(false, 0);
                SetRoomMode(eRoomMode.BoosterPacks);

                // Buy card pack
                int PackType         = BuyPackConfirmManager.instance.GetPackType();
                int NumCardsInPack   = (PackType + 1) * 5;
                int DiamondsRequired = (PackType + 1) * 50;

                // Deduct diamonds
                GameDataManager.Instance.AddPlayerDiamonds(-DiamondsRequired);
                GameDataManager.Instance.BroadcastGuiData();

                // Analytics event
                Dictionary <string, object> EventDictionary = new Dictionary <string, object>();
                EventDictionary["cardsInPack"] = NumCardsInPack;
                Analytics.CustomEvent("BuyBoosterPack", EventDictionary);

                List <TradingCardHeldItem> CardsInPack = new List <TradingCardHeldItem>();
                for (int Idx = 0; Idx < NumCardsInPack; Idx++)
                {
                    TradingCardSpreadsheetItem RandomCard = new TradingCardSpreadsheetItem();

                    switch (UnityEngine.Random.Range(0, 3))
                    {
                    case 0:
                        // Return common card
                        //RandomCard = TradingCardItemsManager.GetRandomCard( eTradingCardRarity.COMMON , 30.0f , eTradingCardRarity.VERYCOMMON , 70.0f );
                        RandomCard = TradingCardItemsManager.GetRandomCard(eTradingCardRarity.COMMON, 30.0f, eTradingCardRarity.COMMON, 70.0f);
                        break;

                    case 1:
                        // Return common or uncommon card
                        RandomCard = TradingCardItemsManager.GetRandomCard(eTradingCardRarity.RARE, 100.0f, eTradingCardRarity.NULL, 0.0f);
                        break;

                    case 2:
                        // Return uncmmon or rare card
                        //RandomCard = TradingCardItemsManager.GetRandomCard( eTradingCardRarity.VERYRARE , 80.0f , eTradingCardRarity.UNIQUE , 20.0f );
                        RandomCard = TradingCardItemsManager.GetRandomCard(eTradingCardRarity.VERYRARE, 80.0f, eTradingCardRarity.VERYRARE, 20.0f);
                        break;
                    }

                    eTradingCardCondition CurCardCondition = eTradingCardCondition.MINT;
                    if (UnityEngine.Random.Range(0.0f, 100.0f) < 50.0f)
                    {
                        CurCardCondition = eTradingCardCondition.SCUFFED;
                    }

                    bool bSaveData = false;
                    if (Idx == (NumCardsInPack - 1))
                    {
                        bSaveData = true;
                    }

                    TradingCardHeldItem BoughtCard = GameDataManager.Instance.AddTradingCard(RandomCard.id, CurCardCondition, bSaveData);
                    BoughtCard.notifyTimer = UnityEngine.Random.Range(4.5f, 5.5f);

                    // If this is a teacher card unlock any NPC
                    UnlockNPC(RandomCard.id);

                    CardsInPack.Add(BoughtCard);
                }

                // Dismiss booster pack panel
                BoosterPacksManager.instance.ShowPanel(false);
                //BoosterPacksManager.instance.OnButtonPressed_Cancel();
                BookManager.instance.MarkDirty();

                // Show preview of cards
                BoosterPacksPreviewManager.instance.ShowPanel(true, CardsInPack);
                SetRoomMode(eRoomMode.BoosterPacksPreview);
                break;

            case 1:
                // Cancel
                BuyPackConfirmManager.instance.ShowPanel(false, 0);
                SetRoomMode(eRoomMode.BoosterPacks);
                break;
            }
        }
    }
示例#9
0
    //=====================================================

    void LoadLiveUpdate()
    {
        string DocPath  = PreHelpers.GetFileFolderPath();
        string FilePath = DocPath + "wfs2.zip";

        if (System.IO.File.Exists(FilePath) == false)
        {
            return;
        }

        // Read file
        FileStream fs = null;

        try
        {
            fs = new FileStream(FilePath, FileMode.Open);
        }
        catch
        {
            Debug.Log("GameData file open exception: " + FilePath);
        }

        if (fs != null)
        {
            try
            {
                // Read zip file
                ZipFile zf       = new ZipFile(fs);
                int     numFiles = 0;

                if (zf.TestArchive(true) == false)
                {
                    Debug.Log("Zip file failed integrity check!");
                    zf.IsStreamOwner = false;
                    zf.Close();
                    fs.Close();
                }
                else
                {
                    foreach (ZipEntry zipEntry in zf)
                    {
                        // Ignore directories
                        if (!zipEntry.IsFile)
                        {
                            continue;
                        }

                        String entryFileName = zipEntry.Name;

                        // Skip .DS_Store files
                        if (entryFileName.Contains("DS_Store"))
                        {
                            continue;
                        }

                        Debug.Log("Unpacking zip file entry: " + entryFileName);

                        byte[] buffer    = new byte[4096];                            // 4K is optimum
                        Stream zipStream = zf.GetInputStream(zipEntry);

                        // Manipulate the output filename here as desired.
                        string fullZipToPath = PreHelpers.GetFileFolderPath() + Path.GetFileName(entryFileName);

                        // Unzip file in buffered chunks. This is just as fast as unpacking to a buffer the full size
                        // of the file, but does not waste memory.
                        // The "using" will close the stream even if an exception occurs.
                        using (FileStream streamWriter = System.IO.File.Create(fullZipToPath))
                        {
                            StreamUtils.Copy(zipStream, streamWriter, buffer);
                        }
                        numFiles++;
                    }

                    zf.IsStreamOwner = false;
                    zf.Close();
                    fs.Close();

                    // If we've unpacked the local files (at least 13) then start using local spreadsheets data
                    Debug.Log("Zip updated with " + numFiles + " files (needs 13)");
                    if (numFiles >= 13)
                    {
                        PlayerPrefs.SetInt(PreHelpers.GetLiveDataVersionString(), 1);
                    }

                    // Reload managers
                    TextManager.Reload();
                    SettingsManager.Reload();
                    TradingCardItemsManager.Reload();
                    ClothingItemsManager.Reload();
                    FairyItemsManager.Reload();
                    WildMagicItemsManager.Reload();
                    NPCItemsManager.Reload();
                }
            }
            catch
            {
                Debug.Log("Zip file error!");
            }

            // Remove zip file
            Debug.Log("Removing zip file");
            System.IO.File.Delete(FilePath);
        }
    }
示例#10
0
    //=====================================================

    public void Update()
    {
        /*
         * // Randomly move cards around to show it's rendering
         * m_Angle += Time.deltaTime * 90.0f;
         *
         * int Idx = 0;
         * foreach( GameObject Obj in m_Cards )
         * {
         *      float Angle = m_Angle + ( Idx * 40 );
         *      float XOff = Mathf.Sin( Angle * Mathf.Deg2Rad ) * 30.0f;
         *      float YOff = Mathf.Cos( Angle * Mathf.Deg2Rad ) * 30.0f;
         *
         *      Vector3 NewVec = m_CardStartPositions[ Idx ];
         *      NewVec.x += XOff;
         *      NewVec.y += YOff;
         *      //Obj.transform.localPosition = NewVec;
         *      Idx++;
         * }
         */

        // Find out which page we're on and render the appropriate cards on that page
        int CurrentPage = m_CurrentBook.GetCurrentPage();

        //Debug.Log( m_CurrentBook.GetCurrentPage() );

        // Retrieve cards
        //int NumCards = GameDataManager.Instance.TradingCardDataList.Count;

        // Render if page has changed
        bool bUpdateResources = false;

        if (CurrentPage != m_LastPageRendered)
        {
            bUpdateResources = true;
        }

        {
            m_LastPageRendered = CurrentPage;

            for (int RenderTexturePage = 0; RenderTexturePage < 2; RenderTexturePage++)
            {
                int CurRenderTexturePage = RenderTexturePage;
                if ((CurrentPage & 1) == 1)
                {
                    CurRenderTexturePage++;
                }

                if (CurRenderTexturePage > 1)
                {
                    CurRenderTexturePage = 0;
                }

                // Setup cards for this render texture page
                for (int CurCardOffset = 0; CurCardOffset < m_CardsPerPage; CurCardOffset++)
                {
                    int ListCardOffset = CurCardOffset;
                    ListCardOffset += RenderTexturePage * m_CardsPerPage;
                    ListCardOffset += CurrentPage * m_CardsPerPage;

                    // Valid card?
                    bool bValidCard = true;
                    TradingCardSpreadsheetItem CurSpreadsheetCard = TradingCardItemsManager.GetTradingCardItem(CurrentPage + RenderTexturePage, CurCardOffset);
                    if (CurSpreadsheetCard == null)
                    {
                        bValidCard = false;
                    }

                    GameObject           RenderCard = m_Cards[CurCardOffset + (CurRenderTexturePage * m_CardsPerPage)];
                    GameObject           RenderCardScuffedOverlay      = RenderCard.transform.parent.gameObject.transform.GetChild(1).gameObject;
                    UnityEngine.UI.Image RenderCardImage               = RenderCard.GetComponent(typeof(UnityEngine.UI.Image)) as UnityEngine.UI.Image;
                    UnityEngine.UI.Image RenderCardScuffedOverlayImage = RenderCardScuffedOverlay.GetComponent(typeof(UnityEngine.UI.Image)) as UnityEngine.UI.Image;

                    if (bValidCard)
                    {
                        //Debug.Log( CurSpreadsheetCard.page + " " + CurSpreadsheetCard.position );
                        RenderCard.transform.parent.gameObject.SetActive(true);

                        //TradingCardHeldItem CurHeldCard = GameDataManager.Instance.TradingCardDataList[ ListCardOffset ];
                        //TradingCardSpreadsheetItem CurSpreadsheetCard = TradingCardItemsManager.GetTradingCardItem( CurHeldCard.id );

                        // Does the player have this card?
                        TradingCardHeldItem CurHeldCard = null;

                        int NumMint    = 0;
                        int NumScuffed = 0;

                        if (GameDataManager.Instance != null)
                        {
                            CurHeldCard = GameDataManager.Instance.GetHeldTradingCard(CurSpreadsheetCard.id, ref NumMint, ref NumScuffed);
                        }

                        if (CurHeldCard != null)
                        {
                            CurHeldCard.notifyTimer -= Time.deltaTime;
                            CurHeldCard.notifyTimer  = Mathf.Clamp(CurHeldCard.notifyTimer, 0.0f, 100.0f);

                            float fScale = (Mathf.Sin(CurHeldCard.notifyTimer * 5.0256f) * 0.1f) + 1.0f;
                            RenderCardImage.gameObject.transform.localScale = new Vector3(fScale, fScale, 1.0f);
                            RenderCardScuffedOverlayImage.gameObject.transform.localScale = new Vector3(fScale, fScale, 1.0f);

                            if (bUpdateResources)
                            {
                                Sprite RenderSprite = (Sprite)Resources.Load("Cards/SmallGUITextures/" + CurSpreadsheetCard.smallGuiTexture2D, typeof(Sprite));
                                RenderCardImage.sprite  = RenderSprite;
                                RenderCardImage.enabled = true;
                                RenderCardScuffedOverlayImage.enabled = true;
                            }
                        }
                        else
                        {
                            RenderCardImage.sprite = m_HiddenCardImage;
                            if (bUpdateResources)
                            {
                                RenderCardImage.enabled = true;
                                RenderCardScuffedOverlayImage.enabled = true;
                            }
                        }

                        // Show/hide number of cards
                        GameObject sprNumCards       = RenderCard.transform.parent.gameObject.transform.GetChild(2).gameObject;
                        GameObject sprScuffedOverlay = RenderCard.transform.parent.gameObject.transform.GetChild(1).gameObject;
                        GameObject sprNumCardsText   = sprNumCards.transform.GetChild(0).gameObject;
                        Text       txtNumCards       = sprNumCardsText.GetComponent(typeof(Text)) as Text;

                        int TotalCards = NumMint + NumScuffed;

                        // For now use the card number instead of 'number of cards'
                        TotalCards = CurSpreadsheetCard.globalPosition + 1; //( ListCardOffset + 1 );

                        if (1 == 1)                                         //TotalCards > 1 )
                        {
                            sprNumCardsText.SetActive(true);
                            txtNumCards.text = TotalCards.ToString();
                        }
                        else
                        {
                            sprNumCardsText.SetActive(false);
                        }

                        // Show scuffed overlay?
                        if ((NumMint <= 0) && (NumScuffed > 0))
                        {
                            sprScuffedOverlay.SetActive(true);
                        }
                        else
                        {
                            sprScuffedOverlay.SetActive(false);
                        }
                    }
                    else
                    {
                        RenderCard.transform.parent.gameObject.SetActive(false);
                        //RenderCardImage.enabled = false;
                    }
                }
            }
        }
    }