Beispiel #1
0
    // USERGUIDEACTION INTERFACE

    protected override bool OnExecute()
    {
        if (base.OnExecute() == false)
        {
            return(false);
        }

        if (GuideData.ShowOffers == false)
        {
            return(false);
        }

        var ppi = GuideData.LocalPPI;

        if (ppi == null)
        {
            return(false);
        }

        // get offer
        object data;

        GuiPopupOffer.E_Type type = DeduceOffer(ppi, GuideData.LastRoundResult, out data);
        if (type == GuiPopupOffer.E_Type.None)
        {
            return(false);
        }

#if UNITY_STANDALONE
        if (type == GuiPopupOffer.E_Type.FreeGold)
        {
            return(false);
        }
#endif
        // display popup
        ShowPopup().SetData(type, data);

        // done
        return(true);
    }
Beispiel #2
0
    // PRIVATE METHODS

    GuiPopupOffer.E_Type DeduceOffer(PlayerPersistantInfo ppi, RoundFinalResult results, out object data)
    {
        data = null;

        // Do not display these offers for experienced premium players
        if (ppi.IsPremiumAccountActive && (ppi.Rank >= 35))
        {
            return(GuiPopupOffer.E_Type.None);
        }

        short earnedMoney   = results != null ? results.Money : (short)0;
        short earnedGold    = results != null ? results.Gold : (short)0;
        bool  hasNewRank    = results != null ? results.NewRank : false;
        int   preferredRank = hasNewRank == true ? ppi.Rank : 0;
        bool  showNonItem   = Random.Range(0, 100) < 10 ? true : false;

        GuiPopupOffer.E_Type type = GuiPopupOffer.E_Type.None;

        // try get any item to offer
        if ((hasNewRank == true || showNonItem == false) && (earnedMoney > 0 || earnedGold > 0 || Random.Range(0, 100) < 20))
        {
            if (type == GuiPopupOffer.E_Type.None && Random.Range(0, 100) < 10)
            {
                List <HatDesc> hats = CollectHats(ppi, results);
                if (hats.Count > 0)
                {
                    hats.Sort(SortHats);

                    string lastId = RestoreString("LastOfferedHat", null);
                    string newId  = null;

                    data = ChooseHat(ref hats, lastId, ppi.Gold, out newId);

                    StoreString("LastOfferedHat", newId);

                    if (data != null)
                    {
                        // display hat offer
                        type = GuiPopupOffer.E_Type.Hat;
                    }
                }
            }

            if (type == GuiPopupOffer.E_Type.None && Random.Range(0, 100) < 40)
            {
                List <ItemDesc> items = CollectItems(ppi, results);
                if (items.Count > 0)
                {
                    items.Sort(SortItems);

                    string lastId = RestoreString("LastOfferedItem", null);
                    string newId  = null;

                    data = ChooseItem(ref items, lastId, ppi.Money, preferredRank, out newId);

                    StoreString("LastOfferedItem", newId);

                    if (data != null)
                    {
                        // display item offer
                        type = GuiPopupOffer.E_Type.Item;
                    }
                }
            }

            if (type == GuiPopupOffer.E_Type.None)
            {
                List <ConsumableDesc> consumables = CollectConsumables(ppi, results);
                if (consumables.Count > 0)
                {
                    string lastId = RestoreString("LastOfferedConsumable", null);
                    string newId  = null;

                    data = ChooseConsumable(ref consumables, lastId, ppi.Gold, out newId);

                    StoreString("LastOfferedConsumable", newId);

                    if (data != null)
                    {
                        // display consumable offer
                        type = GuiPopupOffer.E_Type.Consumable;
                    }
                }
            }

            if (type == GuiPopupOffer.E_Type.None)
            {
                // increase the chance to display any non-item offer
                showNonItem = Random.Range(0, 100) < 10 ? true : false;
            }
        }

        // deduce non-item offer if needed
        if (showNonItem == true && type == GuiPopupOffer.E_Type.None)
        {
            GuiPopupOffer.E_Type[] types = new GuiPopupOffer.E_Type[]
            {
                GuiPopupOffer.E_Type.PremiumAcct,
                GuiPopupOffer.E_Type.MoreApps,
                GuiPopupOffer.E_Type.FreeGold
            };

            type = types[Random.Range(0, types.Length)];
            if (type == GuiPopupOffer.E_Type.PremiumAcct)
            {
                if (ppi.Gold == 0)
                {
                    // wo do not have any gold so offer free gold instead
                    type = GuiPopupOffer.E_Type.FreeGold;
                }
                else if ((CloudUser.instance.GetPremiumAccountEndDateTime() - CloudDateTime.UtcNow).TotalDays > 7)
                {
                    // user has enough time left, skip this offer for now
                    type = GuiPopupOffer.E_Type.None;
                }
            }
        }

        // done
        return(type);
    }