You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

73 lines
1.8 KiB

  1. using System;
  2. using System.Diagnostics;
  3. using CIGEnums;
  4. using SUISS.Core;
  5. using SUISSEngine;
  6. using UnityEngine;
  7. namespace CIG
  8. {
  9. public class IAPShopProductConsumer : IProductConsumer
  10. {
  11. //[DebuggerBrowsable(DebuggerBrowsableState.Never)]
  12. public event IAPShopProductConsumer.ProductConsumedEventHandler ProductConsumedEvent;
  13. public bool ConsumeProduct(CIG3StoreProduct product)
  14. {
  15. switch (product.Category)
  16. {
  17. case StoreProductCategory.Shop:
  18. case StoreProductCategory.ShopSale:
  19. {
  20. Currencies currencies = product.Currencies;
  21. CIGGameState instance = SingletonMonobehaviour<CIGGameState>.Instance;
  22. if (!(instance != null))
  23. {
  24. return false;
  25. }
  26. instance.GiveCurrencies(currencies);
  27. instance.CountBoughtGoldPackageIfApplicable(currencies);
  28. break;
  29. }
  30. case StoreProductCategory.Packs:
  31. {
  32. IAPPack iappack = IAPPackManager.Instance.CreatePack(product.GameProductName);
  33. if (iappack == null)
  34. {
  35. return false;
  36. }
  37. iappack.ApplyEffects();
  38. break;
  39. }
  40. case StoreProductCategory.Cranes:
  41. {
  42. CIGBuilderManager instanceIfAvailable = SingletonMonobehaviour<CIGBuilderManager>.InstanceIfAvailable;
  43. if (!(instanceIfAvailable != null))
  44. {
  45. return false;
  46. }
  47. instanceIfAvailable.AddCrane(true);
  48. break;
  49. }
  50. default:
  51. UnityEngine.Debug.LogErrorFormat("Missing product consumer for product category '{0}'", new object[]
  52. {
  53. product.Category
  54. });
  55. return false;
  56. }
  57. return true;
  58. }
  59. public void FireProductConsumedEvent(CIG3StoreProduct product)
  60. {
  61. if (this.ProductConsumedEvent != null)
  62. {
  63. this.ProductConsumedEvent(product);
  64. }
  65. }
  66. public delegate void ProductConsumedEventHandler(CIG3StoreProduct product);
  67. }
  68. }