public void onGoodUpgrade(string message, bool alsoPush) { SoomlaUtils.LogDebug(TAG, "SOOMLA/UNITY onGoodUpgrade:" + message); var eventJSON = new JSONObject(message); VirtualGood vg = (VirtualGood)StoreInfo.GetItemByItemId(eventJSON["itemId"].str); UpgradeVG vgu = null; if (eventJSON.HasField("upgradeItemId") && !string.IsNullOrEmpty(eventJSON["upgradeItemId"].str)) { vgu = (UpgradeVG)StoreInfo.GetItemByItemId(eventJSON["upgradeItemId"].str); } StoreInventory.RefreshOnGoodUpgrade(vg, vgu); StoreEvents.OnGoodUpgrade(vg, vgu); if (alsoPush) { #if (UNITY_ANDROID || UNITY_IOS) && !UNITY_EDITOR sep.PushEventOnGoodUpgrade(vg, vgu); #endif } }
/// <summary> /// Assigns a specific upgrade to the given virtual good. /// </summary> /// <param name="good">the virtual good to upgrade.</param> /// <param name="upgradeVG">the upgrade to assign.</param> /// <param name="notify">true will also post event.</param> public static void AssignCurrentUpgrade(VirtualGood good, UpgradeVG upgradeVG, bool notify) { SoomlaUtils.LogDebug(TAG, "Assigning upgrade " + upgradeVG.ItemId + " to virtual good: " + good.ItemId); instance._assignCurrentUpgrade(good, upgradeVG, notify); }
/// <summary> /// Retrieves the upgrade level of the virtual good with the given <c>goodItemId</c>. /// For Example: /// Let's say there's a strength attribute to one of the characters in your game and you provide /// your users with the ability to upgrade that strength on a scale of 1-3. /// This is what you've created: /// 1. <c>SingleUseVG</c> for "strength". /// 2. <c>UpgradeVG</c> for strength 'level 1'. /// 3. <c>UpgradeVG</c> for strength 'level 2'. /// 4. <c>UpgradeVG</c> for strength 'level 3'. /// In the example, this function will retrieve the upgrade level for "strength" (1, 2, or 3). /// </summary> /// <param name="goodItemId">Good item identifier.</param> /// <returns>The good upgrade level.</returns> /// <exception cref="VirtualItemNotFoundException">Thrown if the item is not found.</exception> public static int GetGoodUpgradeLevel(string goodItemId) { SoomlaUtils.LogDebug(TAG, "Checking " + goodItemId + " upgrade level"); VirtualGood good = (VirtualGood)StoreInfo.GetItemByItemId(goodItemId); if (good == null) { SoomlaUtils.LogError(TAG, "You tried to get the level of a non-existant virtual good."); return(0); } UpgradeVG upgradeVG = VirtualGoodsStorage.GetCurrentUpgrade(good); if (upgradeVG == null) { return(0); //no upgrade } UpgradeVG first = StoreInfo.GetFirstUpgradeForVirtualGood(goodItemId); int level = 1; while (first.ItemId != upgradeVG.ItemId) { first = (UpgradeVG)StoreInfo.GetItemByItemId(first.NextItemId); level++; } return(level); }
/// <summary> /// Upgrades the virtual good with the given <c>goodItemId</c> by doing the following: /// 1. Checks if the good is currently upgraded or if this is the first time being upgraded. /// 2. If the good is currently upgraded, upgrades to the next upgrade in the series. /// In case there are no more upgrades available(meaning the current upgrade is the last available), /// the function returns. /// 3. If the good has never been upgraded before, the function upgrades it to the first /// available upgrade with the first upgrade of the series. /// </summary> /// <param name="goodItemId">Good item identifier.</param> /// <exception cref="VirtualItemNotFoundException">Thrown if the item is not found.</exception> public static void UpgradeGood(string goodItemId) { SoomlaUtils.LogDebug(TAG, "SOOMLA/UNITY Calling UpgradeGood with: " + goodItemId); VirtualGood good = (VirtualGood)StoreInfo.GetItemByItemId(goodItemId); UpgradeVG upgradeVG = VirtualGoodsStorage.GetCurrentUpgrade(good); if (upgradeVG != null) { String nextItemId = upgradeVG.NextItemId; if (string.IsNullOrEmpty(nextItemId)) { return; } UpgradeVG vgu = (UpgradeVG)StoreInfo.GetItemByItemId(nextItemId); vgu.Buy(""); } else { UpgradeVG first = StoreInfo.GetFirstUpgradeForVirtualGood(goodItemId); if (first != null) { first.Buy(""); } } }
/// <summary> /// This function refreshes a local set of objects that will hold your user's balances in memory for quick /// and more efficient fetching for your game UI. /// This way, we save many JNI or static calls to native platforms. /// /// NOTE: You don't need to call this function as it's automatically called when the game initializes. /// NOTE: This is less useful when you work in editor. /// </summary> public static void RefreshLocalInventory() { SoomlaUtils.LogDebug(TAG, "Refreshing local inventory"); localItemBalances = new Dictionary <string, int> (); localUpgrades = new Dictionary <string, LocalUpgrade>(); localEquippedGoods = new HashSet <string>(); foreach (VirtualCurrency item in StoreInfo.Currencies) { localItemBalances[item.ItemId] = VirtualCurrencyStorage.GetBalance(item); } foreach (VirtualGood item in StoreInfo.Goods) { localItemBalances[item.ItemId] = VirtualGoodsStorage.GetBalance(item); UpgradeVG upgrade = VirtualGoodsStorage.GetCurrentUpgrade(item); if (upgrade != null) { int upgradeLevel = GetGoodUpgradeLevel(item.ItemId); localUpgrades.AddOrUpdate(item.ItemId, new LocalUpgrade { itemId = upgrade.ItemId, level = upgradeLevel }); } if (item is EquippableVG) { if (VirtualGoodsStorage.IsEquipped((EquippableVG)item)) { localEquippedGoods.Add(item.ItemId); } } } }
protected override void _assignCurrentUpgrade(VirtualGood good, UpgradeVG upgradeVG, bool notify) { AndroidJNI.PushLocalFrame(100); using(AndroidJavaClass jniStorageManager = new AndroidJavaClass("com.soomla.store.data.StorageManager")) { using(AndroidJavaObject jniVGStorage = jniStorageManager.CallStatic<AndroidJavaObject>("getVirtualGoodsStorage")) { jniVGStorage.Call("assignCurrentUpgrade", good.ItemId, upgradeVG.ItemId, notify); } } AndroidJNI.PopLocalFrame(IntPtr.Zero); }
public void PushEventOnGoodUpgrade(VirtualGood good, UpgradeVG upgrade) { var eventJSON = new JSONObject(); eventJSON.AddField("itemId", good.ItemId); eventJSON.AddField("upgradeItemId", (upgrade == null ? null : upgrade.ItemId)); _pushEventGoodUpgrade(eventJSON.print()); }
protected override void _assignCurrentUpgrade(VirtualGood good, UpgradeVG upgradeVG, bool notify) { AndroidJNI.PushLocalFrame(100); using (AndroidJavaClass jniStorageManager = new AndroidJavaClass("com.soomla.store.data.StorageManager")) { using (AndroidJavaObject jniVGStorage = jniStorageManager.CallStatic <AndroidJavaObject>("getVirtualGoodsStorage")) { jniVGStorage.Call("assignCurrentUpgrade", good.ItemId, upgradeVG.ItemId, notify); } } AndroidJNI.PopLocalFrame(IntPtr.Zero); }
/// <summary> /// Gets the first upgrade for virtual good with the given <c>goodItemId</c>. /// </summary> /// <param name="goodItemId">Item id.</param> /// <returns>The first upgrade for virtual good with the given id.</returns> protected override UpgradeVG _getFirstUpgradeForVirtualGood(string goodItemId) { UpgradeVG vgu = null; AndroidJNI.PushLocalFrame(100); using(AndroidJavaObject jniUpgradeVG = AndroidJNIHandler.CallStatic<AndroidJavaObject>( new AndroidJavaClass("com.soomla.store.data.StoreInfo"),"getGoodFirstUpgrade", goodItemId)) { vgu = new UpgradeVG(jniUpgradeVG); } AndroidJNI.PopLocalFrame(IntPtr.Zero); return vgu; }
/// <summary> /// Gets the last upgrade for the virtual good with the given <c>goodItemId</c>. /// </summary> /// <param name="goodItemId">item id</param> /// <returns>last upgrade for virtual good with the given id</returns> override protected UpgradeVG _getLastUpgradeForVirtualGood(string goodItemId) { UpgradeVG vgu = null; AndroidJNI.PushLocalFrame(100); using (AndroidJavaObject jniUpgradeVG = AndroidJNIHandler.CallStatic <AndroidJavaObject>( new AndroidJavaClass("com.soomla.store.data.StoreInfo"), "getGoodLastUpgrade", goodItemId)) { vgu = new UpgradeVG(jniUpgradeVG); } AndroidJNI.PopLocalFrame(IntPtr.Zero); return(vgu); }
/// <summary> /// Retrieves the current upgrade of the good with the given id. /// </summary> /// <param name="goodItemId">Id of the good whose upgrade we want to fetch. </param> /// <returns>The good's current upgrade.</returns> /// <exception cref="VirtualItemNotFoundException">Thrown if the item is not found.</exception> public static string GetGoodCurrentUpgrade(string goodItemId) { SoomlaUtils.LogDebug(TAG, "Checking " + goodItemId + " current upgrade"); VirtualGood good = (VirtualGood)StoreInfo.GetItemByItemId(goodItemId); UpgradeVG upgradeVG = VirtualGoodsStorage.GetCurrentUpgrade(good); if (upgradeVG == null) { return(""); } return(upgradeVG.ItemId); }
/// <summary> /// Takes upgrade from the user, or in other words DOWNGRADES the associated /// <code>VirtualGood</code> (mGood). /// Checks if the current Upgrade is really associated with the <code>VirtualGood</code> and: /// </summary> /// <param name="amount">NOT USED HERE!.</param> /// <param name="notify">see parent.</param> public override int Take(int amount, bool notify) { VirtualGood good = null; try { good = (VirtualGood)StoreInfo.GetItemByItemId(GoodItemId); } catch (VirtualItemNotFoundException) { SoomlaUtils.LogError(TAG, "VirtualGood with itemId: " + GoodItemId + " doesn't exist! Can't downgrade."); return(0); } UpgradeVG upgradeVG = VirtualGoodsStorage.GetCurrentUpgrade(good); // Case: Upgrade is not assigned to this Virtual Good if (upgradeVG != this) { SoomlaUtils.LogError(TAG, "You can't take an upgrade that's not currently assigned." + "The UpgradeVG " + Name + " is not assigned to " + "the VirtualGood: " + good.Name); return(0); } if (!string.IsNullOrEmpty(PrevItemId)) { UpgradeVG prevUpgradeVG = null; // Case: downgrade is not possible because previous upgrade does not exist try { prevUpgradeVG = (UpgradeVG)StoreInfo.GetItemByItemId(PrevItemId); } catch (VirtualItemNotFoundException) { SoomlaUtils.LogError(TAG, "Previous UpgradeVG with itemId: " + PrevItemId + " doesn't exist! Can't downgrade."); return(0); } // Case: downgrade is successful! SoomlaUtils.LogDebug(TAG, "Downgrading " + good.Name + " to: " + prevUpgradeVG.Name); VirtualGoodsStorage.AssignCurrentUpgrade(good, prevUpgradeVG, notify); } // Case: first Upgrade in the series - so we downgrade to NO upgrade. else { SoomlaUtils.LogDebug(TAG, "Downgrading " + good.Name + " to NO-UPGRADE"); VirtualGoodsStorage.RemoveUpgrades(good, notify); } return(base.Take(amount, notify)); }
void bought(VirtualGood arg1, UpgradeVG arg2) { if (upgrades) { int upgdLevel = StoreInventory.GetGoodUpgradeLevel (id); if(upgdLevel==5){ el_desc.text = LanguageManager.current.getText(LanguageNode.FullUpgraded); buy.gameObject.SetActive(false); el_upgradeMeter.fillAmount = 1f; }else{ el_upgradeMeter.fillAmount = upgdLevel / 5f; el_price.text = AnimineStoreAssets.UPGRADE_PRICE [upgdLevel]+""; } } }
/// <summary> /// Handles an <c>onGoodUpgrade</c> event, which is fired when a specific <c>UpgradeVG</c> has /// been upgraded/downgraded. /// </summary> /// <param name="message">Message that contains information about the good that has been /// upgraded/downgraded.</param> public void onGoodUpgrade(string message) { SoomlaUtils.LogDebug(TAG, "SOOMLA/UNITY onGoodUpgrade:" + message); string[] vars = Regex.Split(message, "#SOOM#"); VirtualGood vg = (VirtualGood)StoreInfo.GetItemByItemId(vars[0]); UpgradeVG vgu = null; if (vars.Length > 1) { vgu = (UpgradeVG)StoreInfo.GetItemByItemId(vars[1]); } StoreEvents.OnGoodUpgrade(vg, vgu); }
/// <summary> /// Determines if the user is in a state that allows him/her to buy an <code>UpgradeVG</code> /// This method enforces allowing/rejecting of upgrades here so users won't buy them when /// they are not supposed to. /// If you want to give your users free upgrades, use the <code>give</code> function. /// </summary> /// <returns><c>true</c>, if can buy, <c>false</c> otherwise.</returns> protected override bool canBuy() { VirtualGood good = null; try { good = (VirtualGood)StoreInfo.GetItemByItemId(GoodItemId); } catch (VirtualItemNotFoundException) { SoomlaUtils.LogError(TAG, "VirtualGood with itemId: " + GoodItemId + " doesn't exist! Returning NO (can't buy)."); return(false); } UpgradeVG upgradeVG = VirtualGoodsStorage.GetCurrentUpgrade(good); return(((upgradeVG == null && string.IsNullOrEmpty(PrevItemId)) || (upgradeVG != null && ((upgradeVG.NextItemId == this.ItemId) || (upgradeVG.PrevItemId == this.ItemId)))) && base.canBuy()); }
public static void onGoodUpgrade(GoodUpgradeEvent _Event, bool alsoPush) { SoomlaWpStore.domain.virtualGoods.VirtualGood good = _Event.GetGood(); SoomlaWpStore.domain.virtualGoods.UpgradeVG upgradeVG = _Event.GetUpgradeVG(); SoomlaUtils.LogDebug(TAG, "SOOMLA/UNITY onGoodUpgrade:" + good.getItemId() + " " + upgradeVG.getItemId()); VirtualGood vg = (VirtualGood)StoreInfo.GetItemByItemId(good.getItemId()); UpgradeVG vgu = null; if (upgradeVG != null) { vgu = (UpgradeVG)StoreInfo.GetItemByItemId(upgradeVG.getItemId()); } StoreInventory.RefreshOnGoodUpgrade(vg, vgu); StoreEvents.OnGoodUpgrade(vg, vgu); if (alsoPush) { sep.PushEventOnGoodUpgrade(_Event); } }
/** A set of private functions to refresh the local inventory whenever there are changes on runtime. **/ public static void RefreshOnGoodUpgrade(VirtualGood vg, UpgradeVG uvg) { if (uvg == null) { localUpgrades.Remove(vg.ItemId); } else { int upgradeLevel = GetGoodUpgradeLevel(vg.ItemId); LocalUpgrade upgrade; if (localUpgrades.TryGetValue(vg.ItemId, out upgrade)) { upgrade.itemId = uvg.ItemId; upgrade.level = upgradeLevel; } else { localUpgrades.Add(vg.ItemId, new LocalUpgrade { itemId = uvg.ItemId, level = upgradeLevel }); } } }
protected virtual void _assignCurrentUpgrade(VirtualGood good, UpgradeVG upgradeVG, bool notify) { #if UNITY_EDITOR UpgradeVG upgrade = GetCurrentUpgrade(good); if (upgrade != null && upgrade.ItemId == upgradeVG.ItemId) { return; } string itemId = good.ItemId; string key = keyGoodUpgrade(itemId); string upItemId = upgradeVG.ItemId; PlayerPrefs.SetString(key, upItemId); if (notify) { var eventJSON = new JSONObject(); eventJSON.AddField("itemId", good.ItemId); eventJSON.AddField("upgradeItemId", upgradeVG.ItemId); StoreEvents.Instance.onGoodUpgrade(eventJSON.print()); } #endif }
/// <summary> /// Assigns a specific upgrade to the given virtual good. /// </summary> /// <param name="good">the virtual good to upgrade.</param> /// <param name="upgradeVG">the upgrade to assign.</param> public static void AssignCurrentUpgrade(VirtualGood good, UpgradeVG upgradeVG) { AssignCurrentUpgrade(good, upgradeVG, true); }
public GoodUpgradeEvent (VirtualGood item , UpgradeVG upgradeVGItem ) : this(item , upgradeVGItem , null) { }
/// <summary> /// Assigns a specific upgrade to the given virtual good. /// </summary> /// <param name="good">the virtual good to upgrade.</param> /// <param name="upgradeVG">the upgrade to assign.</param> /// <param name="notify">true will also post event.</param> public static void AssignCurrentUpgrade(VirtualGood good, UpgradeVG upgradeVG, bool notify){ SoomlaUtils.LogDebug(TAG, "Assigning upgrade " + upgradeVG.ItemId + " to virtual good: " + good.ItemId); instance._assignCurrentUpgrade(good, upgradeVG, notify); }
protected override void _assignCurrentUpgrade(VirtualGood good, UpgradeVG upgradeVG, bool notify) { SoomlaWpStore.domain.virtualGoods.VirtualGood vg = (SoomlaWpStore.domain.virtualGoods.VirtualGood)SoomlaWpStore.data.StoreInfo.getVirtualItem(good.ItemId); SoomlaWpStore.domain.virtualGoods.UpgradeVG uvg = (SoomlaWpStore.domain.virtualGoods.UpgradeVG)SoomlaWpStore.data.StoreInfo.getVirtualItem(upgradeVG.ItemId); SoomlaWpStore.data.StorageManager.getVirtualGoodsStorage().assignCurrentUpgrade(vg, uvg, notify); }
/// <summary> /// Handles a good upgraded event. /// </summary> /// <param name="good">Virtual good that is being upgraded.</param> /// <param name="currentUpgrade">The current upgrade that the given virtual /// good is being upgraded to.</param> public void onGoodUpgrade(VirtualGood good, UpgradeVG currentUpgrade) { }
/// <summary> /// Assigns a specific upgrade to the given virtual good. /// </summary> /// <param name="good">the virtual good to upgrade.</param> /// <param name="upgradeVG">the upgrade to assign.</param> public static void AssignCurrentUpgrade(VirtualGood good, UpgradeVG upgradeVG){ AssignCurrentUpgrade(good, upgradeVG, true); }
protected override void _assignCurrentUpgrade(VirtualGood good, UpgradeVG upgradeVG, bool notify) { int err = vgStorage_AssignCurrentUpgrade(good.ItemId, upgradeVG.ItemId, notify); IOS_ErrorCodes.CheckAndThrowException(err); }
/** A set of private functions to refresh the local inventory whenever there are changes on runtime. **/ public static void RefreshOnGoodUpgrade(VirtualGood vg, UpgradeVG uvg) { if (uvg == null) { localUpgrades.Remove(vg.ItemId); } else { int upgradeLevel = GetGoodUpgradeLevel(vg.ItemId); LocalUpgrade upgrade; if (localUpgrades.TryGetValue(vg.ItemId, out upgrade)) { upgrade.itemId = uvg.ItemId; upgrade.level = upgradeLevel; } else { localUpgrades.Add(vg.ItemId, new LocalUpgrade { itemId = uvg.ItemId, level = upgradeLevel }); } } }
public GoodUpgradeEvent (VirtualGood item , UpgradeVG upgradeVGItem , Object sender) : base(sender) { mItem = item ; mCurrentUpgradeItem = upgradeVGItem ; }
/// <summary> /// Handles a good upgraded event. /// </summary> /// <param name="good">Virtual good that is being upgraded.</param> /// <param name="currentUpgrade">The current upgrade that the given virtual /// good is being upgraded to.</param> public void onGoodUpgrade(VirtualGood good, UpgradeVG currentUpgrade) { }
protected override void _assignCurrentUpgrade(VirtualGood good, UpgradeVG upgradeVG, bool notify) { int err = vgStorage_AssignCurrentUpgrade(good.ItemId, upgradeVG.ItemId, notify); IOS_ErrorCodes.CheckAndThrowException(err); }
public void PushEventOnGoodUpgrade(VirtualGood good, UpgradeVG upgrade) { var eventJSON = new JSONObject(); eventJSON.AddField("itemId", good.ItemId); eventJSON.AddField("upgradeItemId", (upgrade==null ? null : upgrade.ItemId)); _pushEventGoodUpgrade(eventJSON.print()); }
protected override void _assignCurrentUpgrade(VirtualGood good, UpgradeVG upgradeVG, bool notify) { SoomlaWpStore.domain.virtualGoods.VirtualGood vg = (SoomlaWpStore.domain.virtualGoods.VirtualGood)SoomlaWpStore.data.StoreInfo.getVirtualItem(good.ItemId); SoomlaWpStore.domain.virtualGoods.UpgradeVG uvg = (SoomlaWpStore.domain.virtualGoods.UpgradeVG)SoomlaWpStore.data.StoreInfo.getVirtualItem(upgradeVG.ItemId); SoomlaWpStore.data.StorageManager.getVirtualGoodsStorage().assignCurrentUpgrade(vg, uvg, notify); }
public GoodUpgradeEvent(VirtualGood item, UpgradeVG upgradeVGItem, Object sender) : base(sender) { mItem = item; mCurrentUpgradeItem = upgradeVGItem; }
protected virtual void _assignCurrentUpgrade(VirtualGood good, UpgradeVG upgradeVG, bool notify) { #if UNITY_EDITOR UpgradeVG upgrade = GetCurrentUpgrade(good); if (upgrade != null && upgrade.ItemId == upgradeVG.ItemId) { return; } string itemId = good.ItemId; string key = keyGoodUpgrade(itemId); string upItemId = upgradeVG.ItemId; PlayerPrefs.SetString(key, upItemId); if (notify) { var eventJSON = new JSONObject(); eventJSON.AddField("itemId", good.ItemId); eventJSON.AddField("upgradeItemId", upgradeVG.ItemId); StoreEvents.Instance.onGoodUpgrade(eventJSON.print()); } #endif }
private void OnGoodUpgrade(VirtualGood good, UpgradeVG currentUpgrade) { Debug.Log(string.Format("GNOME: GoodUpgrade - ItemId: {0}", good.ItemId)); }
public GoodUpgradeEvent(VirtualGood item, UpgradeVG upgradeVGItem) : this(item, upgradeVGItem, null) { }