/// <summary> /// Buys the purchasable virtual item. /// Implementation in subclasses will be according to specific type of purchase. /// </summary> /// <param name="payload">a string you want to be assigned to the purchase. This string /// is saved in a static variable and will be given bacl to you when the /// purchase is completed.</param> /// <exception cref="Soomla.Store.InsufficientFundsException">throws InsufficientFundsException</exception> public override void Buy(string payload) { SoomlaUtils.LogDebug("SOOMLA PurchaseWithVirtualItem", "Trying to buy a " + AssociatedItem.Name + " with " + Amount + " pieces of " + TargetItemId); VirtualItem item = getTargetVirtualItem(); if (item == null) { return; } JSONObject eventJSON = new JSONObject(); eventJSON.AddField("itemId", AssociatedItem.ItemId); StoreEvents.Instance.onItemPurchaseStarted(eventJSON.print(), true); if (!checkTargetBalance(item)) { throw new InsufficientFundsException(TargetItemId); } item.Take(Amount); AssociatedItem.Give(1); // We have to make sure the ItemPurchased event will be fired AFTER the balance/currency-changed events. StoreEvents.Instance.RunLater(() => { eventJSON = new JSONObject(); eventJSON.AddField("itemId", AssociatedItem.ItemId); eventJSON.AddField("payload", payload); StoreEvents.Instance.onItemPurchased(eventJSON.print(), true); }); }
public virtual ProductAssociation ToModel(ProductAssociation association) { if (association == null) { throw new ArgumentNullException(nameof(association)); } association.Id = Id; association.OuterId = OuterId; association.Type = AssociationType; association.Priority = Priority; association.AssociatedObjectId = AssociatedItemId ?? AssociatedCategoryId; association.Quantity = Quantity; association.ItemId = ItemId; if (AssociatedCategory != null) { association.AssociatedObject = AssociatedCategory.ToModel(AbstractTypeFactory <Category> .TryCreateInstance()); association.AssociatedObjectType = "category"; } if (AssociatedItem != null) { association.AssociatedObject = AssociatedItem.ToModel(AbstractTypeFactory <CatalogProduct> .TryCreateInstance(), false, false); association.AssociatedObjectType = "product"; } if (!Tags.IsNullOrEmpty()) { association.Tags = Tags.Split(';'); } return(association); }
protected override void WriteDataXML(XElement ele, ElderScrollsPlugin master) { XElement subEle; ele.TryPathTo("Flags", true, out subEle); subEle.Value = MagicEffectFlags.ToString(); ele.TryPathTo("BaseCost", true, out subEle); subEle.Value = BaseCost.ToString("G15"); ele.TryPathTo("AssociatedItem", true, out subEle); AssociatedItem.WriteXML(subEle, master); ele.TryPathTo("MagicSchool", true, out subEle); subEle.Value = MagicSchool.ToString(); ele.TryPathTo("ResistanceType", true, out subEle); subEle.Value = ResistanceType.ToString(); ele.TryPathTo("Unknown", true, out subEle); subEle.Value = Unknown.ToString(); WriteUnusedXML(ele, master); ele.TryPathTo("Light", true, out subEle); Light.WriteXML(subEle, master); ele.TryPathTo("ProjectileSpeed", true, out subEle); subEle.Value = ProjectileSpeed.ToString("G15"); ele.TryPathTo("EffectShader", true, out subEle); EffectShader.WriteXML(subEle, master); ele.TryPathTo("ObjectDisplayShader", true, out subEle); ObjectDisplayShader.WriteXML(subEle, master); ele.TryPathTo("EffectSound", true, out subEle); EffectSound.WriteXML(subEle, master); ele.TryPathTo("BoltSound", true, out subEle); BoltSound.WriteXML(subEle, master); ele.TryPathTo("HitSound", true, out subEle); HitSound.WriteXML(subEle, master); ele.TryPathTo("AreaSound", true, out subEle); AreaSound.WriteXML(subEle, master); ele.TryPathTo("ConstantEffectEnchantmentFactor", true, out subEle); subEle.Value = ConstantEffectEnchantmentFactor.ToString("G15"); ele.TryPathTo("ConstantEffectBarterFactor", true, out subEle); subEle.Value = ConstantEffectBarterFactor.ToString("G15"); ele.TryPathTo("Archetype", true, out subEle); subEle.Value = Archetype.ToString(); ele.TryPathTo("ActorValue", true, out subEle); subEle.Value = ActorValue.ToString(); }
protected override void WriteData(ESPWriter writer) { writer.Write((UInt32)MagicEffectFlags); writer.Write(BaseCost); AssociatedItem.WriteBinary(writer); writer.Write((Int32)MagicSchool); writer.Write((Int32)ResistanceType); writer.Write(Unknown); if (Unused == null) { writer.Write(new byte[2]); } else { writer.Write(Unused); } Light.WriteBinary(writer); writer.Write(ProjectileSpeed); EffectShader.WriteBinary(writer); ObjectDisplayShader.WriteBinary(writer); EffectSound.WriteBinary(writer); BoltSound.WriteBinary(writer); HitSound.WriteBinary(writer); AreaSound.WriteBinary(writer); writer.Write(ConstantEffectEnchantmentFactor); writer.Write(ConstantEffectBarterFactor); writer.Write((UInt32)Archetype); writer.Write((Int32)ActorValue); }
protected override void ReadData(ESPReader reader) { using (MemoryStream stream = new MemoryStream(reader.ReadBytes(size))) using (ESPReader subReader = new ESPReader(stream, reader.Plugin)) { try { MagicEffectFlags = subReader.ReadEnum <MagicEffectFlags>(); BaseCost = subReader.ReadSingle(); AssociatedItem.ReadBinary(subReader); MagicSchool = subReader.ReadEnum <MagicSchool>(); ResistanceType = subReader.ReadEnum <ActorValues>(); Unknown = subReader.ReadUInt16(); Unused = subReader.ReadBytes(2); Light.ReadBinary(subReader); ProjectileSpeed = subReader.ReadSingle(); EffectShader.ReadBinary(subReader); ObjectDisplayShader.ReadBinary(subReader); EffectSound.ReadBinary(subReader); BoltSound.ReadBinary(subReader); HitSound.ReadBinary(subReader); AreaSound.ReadBinary(subReader); ConstantEffectEnchantmentFactor = subReader.ReadSingle(); ConstantEffectBarterFactor = subReader.ReadSingle(); Archetype = subReader.ReadEnum <MagicEffectArchetype>(); ActorValue = subReader.ReadEnum <ActorValues>(); } catch { return; } } }
/// <summary> /// Buys the purchasable virtual item. /// Implementation in subclasses will be according to specific type of purchase. /// </summary> /// <param name="payload">a string you want to be assigned to the purchase. This string /// is saved in a static variable and will be given bacl to you when the /// purchase is completed.</param> /// <exception cref="Soomla.Store.InsufficientFundsException">throws InsufficientFundsException</exception> public override void Buy(string payload) { SoomlaUtils.LogDebug("SOOMLA PurchaseWithVirtualItem", "Trying to buy a " + AssociatedItem.Name + " with " + Amount + " pieces of " + TargetItemId); VirtualItem item = null; try { item = StoreInfo.GetItemByItemId(TargetItemId); } catch (VirtualItemNotFoundException) { SoomlaUtils.LogError(TAG, "Target virtual item doesn't exist !"); return; } JSONObject eventJSON = new JSONObject(); eventJSON.AddField("itemId", AssociatedItem.ItemId); StoreEvents.Instance.onItemPurchaseStarted(eventJSON.print()); int balance = item.GetBalance(); if (item is VirtualCurrency) { balance = VirtualCurrencyStorage.GetBalance(item); } else { balance = VirtualGoodsStorage.GetBalance(item); } if (balance < Amount) { throw new InsufficientFundsException(TargetItemId); } item.Take(Amount); AssociatedItem.Give(1); eventJSON = new JSONObject(); eventJSON.AddField("itemId", AssociatedItem.ItemId); eventJSON.AddField("payload", payload); StoreEvents.Instance.onItemPurchased(eventJSON.print()); }
/// <summary> /// Buys the purchasable virtual item. /// Implementation in subclasses will be according to specific type of purchase. /// </summary> /// <param name="payload">a string you want to be assigned to the purchase. This string /// is saved in a static variable and will be given bacl to you when the /// purchase is completed.</param> /// <exception cref="Soomla.Store.InsufficientFundsException">throws InsufficientFundsException</exception> public override void Buy(string payload) { SoomlaUtils.LogDebug("SOOMLA PurchaseWithVirtualItem", "Trying to buy a " + AssociatedItem.Name + " with " + Amount + " pieces of " + TargetItemId); VirtualItem item = null; try { item = StoreInfo.GetItemByItemId(TargetItemId); } catch (VirtualItemNotFoundException) { SoomlaUtils.LogError(TAG, "Target virtual item doesn't exist !"); return; } JSONObject eventJSON = new JSONObject(); eventJSON.AddField("itemId", AssociatedItem.ItemId); StoreEvents.Instance.onItemPurchaseStarted(eventJSON.print(), true); int balance = item.GetBalance(); if (balance < Amount) { throw new InsufficientFundsException(TargetItemId); } item.Take(Amount); AssociatedItem.Give(1); // We have to make sure the ItemPurchased event will be fired AFTER the balance/currency-changed events. StoreEvents.Instance.RunLater(() => { eventJSON = new JSONObject(); eventJSON.AddField("itemId", AssociatedItem.ItemId); eventJSON.AddField("payload", payload); StoreEvents.Instance.onItemPurchased(eventJSON.print(), true); }); }
public override int GetHashCode() { return(AssociatedItem.GetHashCode()); }
protected override void ReadDataXML(XElement ele, ElderScrollsPlugin master) { XElement subEle; if (ele.TryPathTo("Flags", false, out subEle)) { MagicEffectFlags = subEle.ToEnum <MagicEffectFlags>(); } if (ele.TryPathTo("BaseCost", false, out subEle)) { BaseCost = subEle.ToSingle(); } if (ele.TryPathTo("AssociatedItem", false, out subEle)) { AssociatedItem.ReadXML(subEle, master); } if (ele.TryPathTo("MagicSchool", false, out subEle)) { MagicSchool = subEle.ToEnum <MagicSchool>(); } if (ele.TryPathTo("ResistanceType", false, out subEle)) { ResistanceType = subEle.ToEnum <ActorValues>(); } if (ele.TryPathTo("Unknown", false, out subEle)) { Unknown = subEle.ToUInt16(); } ReadUnusedXML(ele, master); if (ele.TryPathTo("Light", false, out subEle)) { Light.ReadXML(subEle, master); } if (ele.TryPathTo("ProjectileSpeed", false, out subEle)) { ProjectileSpeed = subEle.ToSingle(); } if (ele.TryPathTo("EffectShader", false, out subEle)) { EffectShader.ReadXML(subEle, master); } if (ele.TryPathTo("ObjectDisplayShader", false, out subEle)) { ObjectDisplayShader.ReadXML(subEle, master); } if (ele.TryPathTo("EffectSound", false, out subEle)) { EffectSound.ReadXML(subEle, master); } if (ele.TryPathTo("BoltSound", false, out subEle)) { BoltSound.ReadXML(subEle, master); } if (ele.TryPathTo("HitSound", false, out subEle)) { HitSound.ReadXML(subEle, master); } if (ele.TryPathTo("AreaSound", false, out subEle)) { AreaSound.ReadXML(subEle, master); } if (ele.TryPathTo("ConstantEffectEnchantmentFactor", false, out subEle)) { ConstantEffectEnchantmentFactor = subEle.ToSingle(); } if (ele.TryPathTo("ConstantEffectBarterFactor", false, out subEle)) { ConstantEffectBarterFactor = subEle.ToSingle(); } if (ele.TryPathTo("Archetype", false, out subEle)) { Archetype = subEle.ToEnum <MagicEffectArchetype>(); } if (ele.TryPathTo("ActorValue", false, out subEle)) { ActorValue = subEle.ToEnum <ActorValues>(); } }