Beispiel #1
0
    //=====================================================

    public FairyData Copy()
    {
        var obj = new FairyData
        {
            Fairy        = Fairy,
            Outfit       = Outfit,
            Level        = Level,
            OutfitsOwned = OutfitsOwned
        };

        return(obj);
    }
    //=====================================================

    public void OnOutfitSelected(int Index)
    {
        // Move into 'buy?' overlay mode
        // Only allow outfits to be selected on bought fairies
        FairyData CurFairy = GameDataManager.Instance.GetFairyData((eFairy)m_CurrentFairyIndex);

        if (CurFairy != null)
        {
            List <ClothingItemData> CurClothingList = ClothingItemsManager.GetClothingItems((eFairy)m_CurrentFairyIndex);
            m_BuyOutfit = CurClothingList[Index];

            // If we own this outfit just wear it, otherwise show the 'buy' overlay
            if (CurFairy.OutfitOwned(m_BuyOutfit.id))
            {
                // Twirl anim
                bool bDoTwirl = false;
                if (CurFairy.Outfit != m_BuyOutfit.id)
                {
                    bDoTwirl = true;
                }

                // Wear
                CurFairy.Outfit    = m_BuyOutfit.id;
                m_bBuyOutfitActive = false;
                UpdateSelectedFairy();
                GameDataManager.Instance.SaveGameData();

                // Analytics event
                Dictionary <string, object> EventDictionary = new Dictionary <string, object>();
                EventDictionary["outfitID"] = m_BuyOutfit.id;
                Analytics.CustomEvent("WearOutfit", EventDictionary);

                if (bDoTwirl)
                {
                    m_InspectOufitTimer = UnityEngine.Random.Range(3.0f, 6.0f);
                    m_CurrentFairyObj.GetComponent <Animator>().SetTrigger("IsChangingOutfit");
                }
            }
            else
            {
                // Buy - show preview of outfit
                UpdateSelectedFairy(m_BuyOutfit.id);
                m_bBuyOutfitActive = true;
            }
        }
        else
        {
            // Fairy not owned, allow outfits to be tested anyway
            List <ClothingItemData> CurClothingList = ClothingItemsManager.GetClothingItems((eFairy)m_CurrentFairyIndex);
            m_BuyOutfit = CurClothingList[Index];
            UpdateSelectedFairy(m_BuyOutfit.id);
        }
    }
    //=====================================================

    void OnDisable()
    {
        if (Application.isPlaying == false)
        {
            return;
        }

        if (_isAppQuiting == true)
        {
            return;
        }

        GameManager.Instance.CommonRoomEvent -= OnCommonRoomEvent;
        ScreenManager.FadeOutCompleteEvent   -= OnFadeOutCompleteEvent;

        // If we own the currently selected fairy then make that the 'current fairy'
        FairyData CurFairy = GameDataManager.Instance.GetFairyData((eFairy)m_CurrentFairyIndex);

        if (CurFairy != null)
        {
            GameDataManager.Instance.PlayerCurrentFairy = m_CurrentFairyIndex;
        }
    }
Beispiel #4
0
    //=====================================================

    public void Reset(bool buyDefaultFairy = true)
    {
        if (FairyData == null)
        {
            FairyData = new List <FairyData>((int)eFairy.NUM_FAIRIES);
        }
        else
        {
            FairyData.Clear();
        }

        for (var i = 0; i < (int)eFairy.NUM_FAIRIES; i++)
        {
            FairyData.Add(new FairyData());
        }

        // Set default fairy (BLOOM) owned
        CurrentFairy          = (int)eFairy.BLOOM;
        Lives                 = 0;
        Health                = 0;
        Gems                  = 0;
        RedGems               = 0;
        Diamonds              = 0;
        Population            = 0;
        HighestEverPopulation = 0;
        LowestPopulationCap   = 0;
        WildMagicRate         = 0.0f;
        BossLevel             = 1;

        // NPCs: NPC_STUDENT (index: 0) is always unlocked (value: 1)
        NPCs = new[] { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

        if (buyDefaultFairy == true)
        {
            GameDataManager.Instance.BuyFairy(eFairy.BLOOM, true);
        }
    }
    //=====================================================

    void UpdateFairyRequirements()
    {
        int PlayerGems = GameDataManager.Instance.PlayerGems;

        if (UpgradeFairyManager.instance.WasButtonPressed())
        {
            switch (UpgradeFairyManager.instance.GetButtonPressed())
            {
            case 0:
                // Upgrade fairy level if we have enough diamonds
                bool bCanUpgradeFairy     = true;
                bool bRequirementsWereMet = true;
                int  UpgradeGemCost       = 0;

                FairyItemData CurFairyInfo = FairyItemsManager.GetFairyItem((eFairy)m_CurrentFairyIndex);
                FairyData     CurFairy     = GameDataManager.Instance.GetFairyData((eFairy)m_CurrentFairyIndex);
                if (CurFairy != null)
                {
                    UpgradeGemCost = CurFairyInfo.GemsRequired[CurFairy.Level + 1];

                    if (UpgradeGemCost > PlayerGems)
                    {
                        bCanUpgradeFairy = false;
                    }

                    if (GameDataManager.Instance.PlayerPopulation < CurFairyInfo.PopulationRequired[CurFairy.Level + 1])
                    {
                        bRequirementsWereMet = false;
                        bCanUpgradeFairy     = false;
                    }

                    if (GameDataManager.Instance.GetNumKeysCollected() < CurFairyInfo.KeysRequired[CurFairy.Level + 1])
                    {
                        bRequirementsWereMet = false;
                        bCanUpgradeFairy     = false;
                    }
                }
                else
                {
                    bCanUpgradeFairy = false;
                }

                if (bCanUpgradeFairy)
                {
                    CurFairy.Level++;
                    GameDataManager.Instance.SaveGameData();
                    GameDataManager.Instance.AddPlayerGems(-UpgradeGemCost);
                    GameDataManager.Instance.BroadcastGuiData();
                    UpgradeFairyManager.instance.ShowPanel(false);
                    SetRoomMode(eRoomMode.ViewingOutfits);

                    // Analytics event
                    Dictionary <string, object> EventDictionary = new Dictionary <string, object>();
                    EventDictionary["fairyID"]    = ((eFairy)m_CurrentFairyIndex).ToString();
                    EventDictionary["fairyLevel"] = CurFairy.Level;
                    Analytics.CustomEvent("UpgradeFairy", EventDictionary);
                }
                else
                {
                    UpgradeFairyManager.instance.Reset();

                    // Not enough money, show shop popup (if requirements are met)
                    if (bRequirementsWereMet)
                    {
                        Instantiate(m_pfbShopPopup);
                        ShopManager.instance.OnButtonPressed_ChangeType(0);
                    }
                }
                break;

            case 1:
                // Cancel
                UpgradeFairyManager.instance.ShowPanel(false);
                SetRoomMode(eRoomMode.ViewingOutfits);
                break;
            }
        }
    }
    //=====================================================

    void UpdateBuyingOutfitFairy()
    {
        // Twirl anim
        bool bDoTwirl = false;

        if (ConfirmPurchaseManager.instance.WasButtonPressed())
        {
            switch (ConfirmPurchaseManager.instance.GetButtonPressed())
            {
            case 0:
                // Buy outfit/fairy
                if (m_bBuyOutfitActive)
                {
                    // Outfit
                    FairyData CurFairy = GameDataManager.Instance.GetFairyData((eFairy)m_CurrentFairyIndex);
                    if (CurFairy != null)
                    {
                        CurFairy.BuyOutfit(m_BuyOutfit.id);
                        CurFairy.Outfit = m_BuyOutfit.id;
                        GameDataManager.Instance.SaveGameData();

                        // Use diamonds
                        GameDataManager.Instance.AddPlayerDiamonds(-m_BuyOutfit.cost);
                        GameDataManager.Instance.BroadcastGuiData();

                        // Analytics event
                        Dictionary <string, object> EventDictionary = new Dictionary <string, object>();
                        EventDictionary["outfitID"] = m_BuyOutfit.id;
                        Analytics.CustomEvent("BuyOutfit", EventDictionary);

                        bDoTwirl = true;
                    }
                }
                else
                {
                    // Fairy
                    GameDataManager.Instance.BuyFairy((eFairy)m_CurrentFairyIndex, true);

                    // Use gems
                    FairyItemData CurFairyInfo = FairyItemsManager.GetFairyItem((eFairy)m_CurrentFairyIndex);
                    GameDataManager.Instance.AddPlayerGems(-CurFairyInfo.GemsRequired[0]);
                    GameDataManager.Instance.BroadcastGuiData();

                    // Analytics event
                    Dictionary <string, object> EventDictionary = new Dictionary <string, object>();
                    EventDictionary["fairyID"] = ((eFairy)m_CurrentFairyIndex).ToString();
                    Analytics.CustomEvent("BuyFairy", EventDictionary);

                    bDoTwirl = true;
                }
                UpdateSelectedFairy();
                ConfirmPurchaseManager.instance.ShowPanel(false);
                SetRoomMode(eRoomMode.ViewingOutfits);
                m_bBuyOutfitActive = false;

                if (bDoTwirl)
                {
                    m_InspectOufitTimer = UnityEngine.Random.Range(3.0f, 6.0f);
                    m_CurrentFairyObj.GetComponent <Animator>().SetTrigger("IsChangingOutfit");
                }
                break;

            case 1:
                // Cancel
                ConfirmPurchaseManager.instance.ShowPanel(false);
                SetRoomMode(eRoomMode.ViewingOutfits);
                m_bBuyOutfitActive = false;
                break;
            }
        }
    }
    //=====================================================

    void UpdateSelectedFairy(string PreviewOutfitID = null)
    {
        if (m_CurrentFairyObj != null)
        {
            GameObject.Destroy(m_CurrentFairyObj);
            m_CurrentFairyObj = null;
        }

        string path = "Fairies/";

        switch ((eFairy)m_CurrentFairyIndex)
        {
        case eFairy.BLOOM:
            path += "Bloom/Prefabs/";
            break;

        case eFairy.STELLA:
            path += "Stella/Prefabs/";
            break;

        case eFairy.FLORA:
            path += "Flora/Prefabs/";
            break;

        case eFairy.MUSA:
            path += "Musa/Prefabs/";
            break;

        case eFairy.TECNA:
            path += "Tecna/Prefabs/";
            break;

        case eFairy.AISHA:
            path += "Aisha/Prefabs/";
            break;
        }

        // Fairy owned?
        eFairy CurFairyType = (eFairy)m_CurrentFairyIndex;

        RackScroller.instance.SetCurrentFairy(CurFairyType);
        RackRenderer.instance.SetCurrentFairy(CurFairyType);
        RackRenderer.instance.MarkDirty();

        FairyData CurFairy = GameDataManager.Instance.GetFairyData(CurFairyType);

        if (CurFairy == null)
        {
            // Not owned, show default outfit (unless we have an override)
            string DefaultItem = ClothingItemsManager.GetClothingDefaultItem((eFairy)m_CurrentFairyIndex);

            if (PreviewOutfitID != null)
            {
                DefaultItem = PreviewOutfitID;
            }

            if (!String.IsNullOrEmpty(DefaultItem))
            {
                path += ClothingItemsManager.GetClothingItem(DefaultItem).prefabName;
            }
        }
        else
        {
            // Owned, show current outfit
            string CurrentOutfit = CurFairy.Outfit;
            if (PreviewOutfitID != null)
            {
                CurrentOutfit = PreviewOutfitID;
            }

            if (!String.IsNullOrEmpty(CurrentOutfit))
            {
                ClothingItemData itemData = ClothingItemsManager.GetClothingItem(CurrentOutfit);
                if (itemData == null)
                {
                    // Not owned, show default outfit (unless we have an override)
                    string DefaultItem = ClothingItemsManager.GetClothingDefaultItem((eFairy)m_CurrentFairyIndex);

                    if (PreviewOutfitID != null)
                    {
                        DefaultItem = PreviewOutfitID;
                    }

                    if (!String.IsNullOrEmpty(DefaultItem))
                    {
                        path += ClothingItemsManager.GetClothingItem(DefaultItem).prefabName;
                    }
                }
                else
                {
                    path += itemData.prefabName;
                }
            }
        }

        // Load prefab
        GameObject prefab = Resources.Load(path.ToString()) as GameObject;

        if (prefab == null)
        {
        }

        if (prefab != null)
        {
            m_CurrentFairyObj = Instantiate(prefab) as GameObject;
            m_CurrentFairyObj.transform.parent           = m_FairyPosition.transform;
            m_CurrentFairyObj.transform.localPosition    = new Vector3(0.0f, 0.0f, 0.0f);
            m_CurrentFairyObj.transform.localEulerAngles = new Vector3(0.0f, 0.0f, 0.0f);
        }
    }
    //=====================================================

    void UpdateViewingOutfits()
    {
        // Show selected fairy name and fairy level information/buttons
        {
            if (m_CurrentFairyIndex <= 0)
            {
                m_btnPrevFairy.SetActive(false);
            }
            else
            {
                m_btnPrevFairy.SetActive(true);
            }

            if (m_CurrentFairyIndex >= 5)
            {
                m_btnNextFairy.SetActive(false);
            }
            else
            {
                m_btnNextFairy.SetActive(true);
            }

            m_txtCurrentFairyName.text = TextManager.GetText("FAIRYNAME_" + ((eFairy)m_CurrentFairyIndex).ToString());

            // Fairy owned?
            FairyData CurFairy = GameDataManager.Instance.GetFairyData((eFairy)m_CurrentFairyIndex);
            if (CurFairy == null)
            {
                // Not owned, do we meet the requirements to buy this fairy?
                FairyItemData CurFairyInfo     = FairyItemsManager.GetFairyItem((eFairy)m_CurrentFairyIndex);
                bool          bRequirementsMet = AreRequirementsMet(CurFairyInfo);

                string txtPurchaseCost = TextManager.GetText("BOUTIQUE_PURCHASE");
                txtPurchaseCost                = txtPurchaseCost.Replace("(Cost)", CurFairyInfo.GemsRequired[0].ToString());
                m_txtPurchaseCostGems.text     = txtPurchaseCost;
                m_txtPurchaseCostDiamonds.text = txtPurchaseCost;

                if (bRequirementsMet)
                {
                    // Requirements met, show purchase button
                    m_sprPurchaseOverlayGems.SetActive(true);
                    m_sprPurchaseOverlayDiamonds.SetActive(false);

                    FairyLockedManager.instance.ShowPanel(false, CurFairyInfo);
                }
                else
                {
                    // Requirements not met, show requirements panel
                    m_sprPurchaseOverlayGems.SetActive(false);
                    m_sprPurchaseOverlayDiamonds.SetActive(false);

                    FairyLockedManager.instance.ShowPanel(true, CurFairyInfo);
                }

                // Hide all fairy levels
                foreach (GameObject Obj in m_sprFairyLevels)
                {
                    Obj.SetActive(false);
                }
                foreach (GameObject Obj in m_sprFairyLevelsLocked)
                {
                    Obj.SetActive(false);
                }
            }
            else
            {
                // Owned, show current fairy level
                m_sprPurchaseOverlayGems.SetActive(false);
                m_sprPurchaseOverlayDiamonds.SetActive(false);
                FairyLockedManager.instance.ShowPanel(false);

                int FairyLevel = CurFairy.Level;

                int Idx = 1;
                foreach (GameObject Obj in m_sprFairyLevels)
                {
                    Obj.SetActive(Idx <= FairyLevel ? true : false);
                    Idx++;
                }

                Idx = 1;
                foreach (GameObject Obj in m_sprFairyLevelsLocked)
                {
                    Obj.SetActive(Idx == (FairyLevel + 1) ? true : false);
                    Idx++;
                }

                // Buying outfit button active?
                if (m_bBuyOutfitActive)
                {
                    m_sprPurchaseOverlayGems.SetActive(false);
                    m_sprPurchaseOverlayDiamonds.SetActive(true);

                    string txtPurchaseCost = TextManager.GetText("BOUTIQUE_PURCHASE");
                    txtPurchaseCost                = txtPurchaseCost.Replace("(Cost)", m_BuyOutfit.cost.ToString());
                    m_txtPurchaseCostGems.text     = txtPurchaseCost;
                    m_txtPurchaseCostDiamonds.text = txtPurchaseCost;
                }
            }
        }

        // Random outfit inspection anim
        m_InspectOufitTimer -= Time.deltaTime;
        if (m_InspectOufitTimer < 0.0f)
        {
            m_InspectOufitTimer = UnityEngine.Random.Range(3.0f, 6.0f);
            m_CurrentFairyObj.GetComponent <Animator>().SetTrigger("IsInspectingOutfit");
        }
    }
Beispiel #9
0
        private void LoadDB()
        {
            string strConn = "Data Source=" + Application.StartupPath + "\\data.db";

            if (!System.IO.File.Exists("data.db"))
            {
                MessageBox.Show("데이터베이스 파일 \"data.db\"를 찾을 수 없습니다.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Application.Exit();
                return;
            }
            var              conn   = new SQLiteConnection(strConn).OpenAndReturn();
            string           sql    = "SELECT * FROM dolls";
            SQLiteCommand    cmd    = new SQLiteCommand(sql, conn);
            SQLiteDataReader reader = null;

            try
            {
                reader = cmd.ExecuteReader();
            }
            catch (SQLiteException)
            {
                MessageBox.Show("데이터베이스 파일 \"data.db\"가 유효하지 않습니다.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Application.Exit();
                return;
            }
            while (reader.Read())
            {
                DollData.Add(new Doll
                {
                    Name    = (string)reader["name"],
                    Grade   = (int)reader["grade"],
                    Time    = (string)reader["time"],
                    Type    = (string)reader["type"],
                    IsHeavy = (bool)reader["isHeavy"]
                });
            }
            reader.Close();
            sql    = "SELECT * FROM equipments";
            cmd    = new SQLiteCommand(sql, conn);
            reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                EquipmentData.Add(new Equipment
                {
                    Name  = (string)reader["name"],
                    Grade = (int)reader["grade"],
                    Time  = (string)reader["time"],
                    Type  = (string)reader["type"],
                });
            }
            reader.Close();
            sql    = "SELECT * FROM fairies";
            cmd    = new SQLiteCommand(sql, conn);
            reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                FairyData.Add(new Fairy
                {
                    Name = (string)reader["name"],
                    Time = (string)reader["time"],
                    Type = (string)reader["type"],
                });
            }
            conn.Close();
        }