Exemplo n.º 1
0
    // TODO: modifiers is returning null - does this not get translated from the xml?
    public void testGetShopItem()
    {
        //returns null on no data from server
        Assert.IsNull(shop.GetShopItem("shop_item_ikey_1"));

        mockFetch(shopList, null);

        //returns Hashtable of property if exists
        Roar.DomainObjects.ShopEntry    shopItem = shop.GetShopItem("shop_item_ikey_1");
        IList <Roar.DomainObjects.Cost> costs    = shopItem.costs;

        Roar.DomainObjects.Costs.Stat costA = costs[0] as Roar.DomainObjects.Costs.Stat;
        Roar.DomainObjects.Costs.Stat costB = costs[1] as Roar.DomainObjects.Costs.Stat;
        StringAssert.IsMatch("cash", costA.ikey);
        StringAssert.IsMatch("premium_currency", costB.ikey);
        Assert.AreEqual(false, costA.ok);
        Assert.AreEqual(true, costB.ok);

        IList <Roar.DomainObjects.Modifier> modifiers = shopItem.modifiers;

        Roar.DomainObjects.Modifiers.GrantItem modifier = modifiers[0] as Roar.DomainObjects.Modifiers.GrantItem;
        StringAssert.IsMatch("item_ikey_1", modifier.ikey);

        //returns null on property not existing
        Assert.IsNull(shop.GetShopItem("doesnotexist"));
    }
Exemplo n.º 2
0
 public override string OnCostStat(Roar.DomainObjects.Costs.Stat stat)
 {
     return(" Stat : " + stat.ikey + " : " + stat.value);
 }
Exemplo n.º 3
0
    protected override void DrawGUI(int windowId)
    {
        if (shop == null || !IsLoggedIn)
        {
            return;
        }
        if (isFetching)
        {
            GUI.Label(new Rect(0, 0, ContentWidth, ContentHeight), "Fetching shop data...", "StatusNormal");
        }

        GUI.Box(new Rect(0, 0, contentBounds.width, divideHeight), new GUIContent(""), "DefaultSeparationBar");

        GUI.Label(new Rect(interColumnSeparators, 0, priceColumnWidth, divideHeight), "ITEM", "DefaultSeparationBarText");

        GUI.Label(new Rect(contentBounds.width - interColumnSeparators * 2 - buyButtonWidth - priceColumnWidth, 0, priceColumnWidth, divideHeight), "COST", "DefaultSeparationBarText");


        float heightSoFar = divideHeight;

        if (shopEntries != null)
        {
            foreach (ShopEntry item in shopEntries)
            {
                Vector2 descSize = GUI.skin.FindStyle(shopItemDescriptionStyle).CalcSize(new GUIContent(item.description));
                Vector2 labSize  = GUI.skin.FindStyle(shopItemLabelStyle).CalcSize(new GUIContent(item.label));
                float   height   = descSize.y + labSize.y + topSeparation;

                GUI.Box(new Rect(0, heightSoFar, contentBounds.width, height), new GUIContent(""), "DefaultHorizontalSection");
                float ySoFar = heightSoFar + topSeparation;

                GUI.Box(new Rect(interColumnSeparators, ySoFar, labSize.x, labSize.y), item.label, shopItemLabelStyle);
                ySoFar += labSize.y;

                GUI.Box(new Rect(interColumnSeparators, ySoFar, descSize.x, descSize.y), item.description, shopItemDescriptionStyle);

                if (item.costs.Count == 1)
                {
                    Roar.DomainObjects.Costs.Stat stat_cost = item.costs[0] as Roar.DomainObjects.Costs.Stat;
                    if (stat_cost != null)
                    {
                        //TODO: This is not rendering in the right place.
                        GUI.Label(new Rect(contentBounds.width - buyButtonWidth - priceColumnWidth - 2 * interColumnSeparators, heightSoFar, priceColumnWidth, labSize.y), stat_cost.value.ToString(), shopItemCostStyle);

                        GUI.Label(new Rect(contentBounds.width - buyButtonWidth - priceColumnWidth - 2 * interColumnSeparators, heightSoFar + labSize.y, priceColumnWidth, labSize.y), stat_cost.ikey, shopItemDescriptionStyle);
                    }
                }
                //For now only check the costs
                bool can_buy = true;
                foreach (Roar.DomainObjects.Cost cost in item.costs)
                {
                    // If its a stat cost we should check against the current value of the players stat rather than trusting the
                    // cached value from the shop.
                    Roar.DomainObjects.Costs.Stat stat_cost = cost as Roar.DomainObjects.Costs.Stat;
                    if (stat_cost != null)
                    {
                        string v = roar.Properties.GetValue(stat_cost.ikey);
                        int    vv;
                        //If we can't get the info we need, we'll need to rely on the value from the shop.
                        if (v != null && System.Int32.TryParse(v, out vv))
                        {
                            if (vv < stat_cost.value)
                            {
                                can_buy = false; break;
                            }
                            continue;
                        }
                    }
                    if (!cost.ok)
                    {
                        can_buy = false; break;
                    }
                }

                GUI.enabled = can_buy && !isBuying;

                if (GUI.Button(new Rect(contentBounds.width - interColumnSeparators - buyButtonWidth, heightSoFar + (labSize.y + descSize.y + topSeparation) / 2 - buyButtonHeight / 2, buyButtonWidth, buyButtonHeight), "Buy", shopItemBuyButtonStyle))
                {
                    if (Debug.isDebugBuild)
                    {
                        Debug.Log(string.Format("buy request: {0}", item.ikey));
                    }
                    if (OnItemBuyRequest != null)
                    {
                        OnItemBuyRequest(item);
                    }
                    isBuying = true;
                    networkActionInProgress = true;
                    shop.Buy(item.ikey, OnBuyComplete);
                }
                GUI.enabled = true;

                heightSoFar += labSize.y + descSize.y + topSeparation;
            }
        }
    }
Exemplo n.º 4
0
 public abstract T OnCostStat(Roar.DomainObjects.Costs.Stat stat);