1363 lines
52 KiB
C#
1363 lines
52 KiB
C#
using asap.core;
|
||
using cfg;
|
||
using game;
|
||
using LitJson;
|
||
using Newtonsoft.Json;
|
||
using Newtonsoft.Json.Linq;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Threading.Tasks;
|
||
using UniRx;
|
||
using UnityEngine;
|
||
|
||
namespace GameCore
|
||
{
|
||
public class SKUDetailDataEvent
|
||
{
|
||
public SKUDetailDataEvent(IAPItemList iap)
|
||
{
|
||
this.iap = iap;
|
||
}
|
||
public IAPItemList iap;
|
||
public string price;
|
||
public float prodPrice;
|
||
}
|
||
public enum ShopBuyType
|
||
{
|
||
None = 0,
|
||
ShopToken = 1,
|
||
ShopPackDailyBuy = 2,
|
||
EventPack = 3,
|
||
TriggerPack = 4,
|
||
}
|
||
public class ShopBuyTypeData
|
||
{
|
||
public ShopBuyType type = ShopBuyType.ShopToken;
|
||
/// <summary>
|
||
/// ShopToken = ID 记录是否买过(首次有赠送) 获取IAPID
|
||
/// EventPack = Event活动ID,具体数据处理 FishingEventData.OnBuyEventPack
|
||
/// TriggerPack = TriggerPackManager.ID,购买删除礼包
|
||
/// ShopPack = ShopPackManager.ID 根据类型处理 type = 3 礼包链增加次数
|
||
/// </summary>
|
||
public int ID;
|
||
/// <summary>
|
||
/// 每日礼包记录key
|
||
/// </summary>
|
||
public string key;//自定义数据
|
||
/// <summary>
|
||
/// 非Event礼包的结束时间,以天为单位
|
||
/// </summary>
|
||
public int endDay;//自定义数据
|
||
public JObject extraPurcheData;
|
||
public bool IsHide;//不自动塞入 ShowData 展示队列
|
||
[NonSerialized]
|
||
public bool NoShow;//不自动展示 ShowData 展示队列
|
||
}
|
||
public class ReplenishmentData
|
||
{
|
||
public ShopBuyTypeData BuyType;
|
||
public int IAPID;
|
||
public List<ItemData> ItemData;
|
||
public RewardType ShowType;
|
||
//以下是打点信息
|
||
public string CONTENT_ID;
|
||
public float PRICE;
|
||
public string CURRENCY;
|
||
public float ProdPrice;
|
||
public JObject extraPurcheData;
|
||
public string orderId;
|
||
public string time;
|
||
}
|
||
public partial class PlayerShopData : IDisposable
|
||
{
|
||
[Inject]
|
||
public cfg.Tables _tables { get; set; }
|
||
[Inject]
|
||
public IIAPService IAPService { get; set; }
|
||
public const int freeRefreshTime = 8;
|
||
|
||
IList<SKUDetail> SKUDetails;
|
||
Dictionary<string, SKUDetail> SKUDetailDataMap = new Dictionary<string, SKUDetail>();
|
||
Dictionary<int, ShopPackManager> PackManagerMap = new Dictionary<int, ShopPackManager>();
|
||
List<ShopPackManager> PackManagerataList = new List<ShopPackManager>();
|
||
List<float> buyData = new List<float>();
|
||
|
||
//ShopPack每日购买次数
|
||
public Dictionary<string, int> shopPackDailyBuyCount = new Dictionary<string, int>();
|
||
// Pack全部购买次数
|
||
public Dictionary<int, int> shopAllPackBuyCount = new Dictionary<int, int>();
|
||
// 金币鱼饵礼包购买次数
|
||
public Dictionary<int, int> shopGiftBuyCount = new Dictionary<int, int>();
|
||
public int shopTipforUnlocked;
|
||
public int vipTipforUnlocked;
|
||
public EventPackManager chainPackM;
|
||
public DailySignEvent ChainPackData;
|
||
// public AdvertData VIPAdPackData;
|
||
public int Voucher { get; private set; }
|
||
// public bool IsShopOpen = false;
|
||
public bool IsShopTopOpen = false;
|
||
public bool IsVIPOpen = false;
|
||
DateTime CreateTime;
|
||
//待释放
|
||
CompositeDisposable disposables = null;
|
||
List<ReplenishmentData> ReplenishmentDatas = new List<ReplenishmentData>();
|
||
Dictionary<string, string> replenishmentDataStrs = new Dictionary<string, string>();
|
||
|
||
//const string ReplenishmentDataKey = "ReplenishmentDataStr";
|
||
//const string OldReplenishmentDataKey = "OldReplenishmentDataKey";
|
||
|
||
public readonly BlackFridayCouponData CouponData = new BlackFridayCouponData();
|
||
|
||
#region Diamond Shop
|
||
//Diamond Shop
|
||
public bool IsShopOpen = false;
|
||
private Dictionary<int, ItemShopRecord> _diamondShopItemRecords = new();
|
||
private int _diamondShopRefreshCount;
|
||
private DateTime _diamondShopRefreshTime;
|
||
|
||
#endregion
|
||
|
||
#region 广告次数
|
||
/// <summary>
|
||
/// -2 广告券数量 -1 数据所属天数 0 总广告次数
|
||
/// </summary>
|
||
Dictionary<int, int> advertCount = new Dictionary<int, int>();
|
||
#endregion
|
||
|
||
public void InitData(Dictionary<string, string> userDatas)
|
||
{
|
||
if (userDatas == null || userDatas.Count < 1)
|
||
{
|
||
return;
|
||
}
|
||
string data_value;
|
||
if (userDatas.TryGetValue("ShopPackBuyCount", out data_value))
|
||
{
|
||
shopPackDailyBuyCount = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, int>>(data_value);
|
||
}
|
||
|
||
if (userDatas.TryGetValue("ShopAllPackBuyCount", out data_value))
|
||
{
|
||
shopAllPackBuyCount = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<int, int>>(data_value);
|
||
}
|
||
|
||
if (userDatas.TryGetValue("ShopGiftBuyCount", out data_value))
|
||
{
|
||
shopGiftBuyCount = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<int, int>>(data_value);
|
||
}
|
||
|
||
|
||
if (userDatas.TryGetValue("Voucher", out data_value))
|
||
{
|
||
InitVoucher(GlobalUtils.TryParseInt(data_value));
|
||
}
|
||
if (userDatas.TryGetValue("ChainPackDataNew", out data_value))
|
||
{
|
||
SetChainPackData(Newtonsoft.Json.JsonConvert.DeserializeObject<DailySignEvent>(data_value));
|
||
}
|
||
if (userDatas.TryGetValue("VIPAdPackData", out data_value))
|
||
{
|
||
// SetVIPAdPackData(Newtonsoft.Json.JsonConvert.DeserializeObject<AdvertData>(data_value));
|
||
}
|
||
if (userDatas.TryGetValue("TurntableAdData", out data_value))
|
||
{
|
||
TurntableAdData = Newtonsoft.Json.JsonConvert.DeserializeObject<DailySignEvent>(data_value);
|
||
}
|
||
//if (userDatas.TryGetValue("FishCardPackData", out data_value))
|
||
//{
|
||
// SetFishCardPackData(data_value);
|
||
//}
|
||
|
||
if (userDatas.TryGetValue("BuyData", out data_value))
|
||
{
|
||
buyData = Newtonsoft.Json.JsonConvert.DeserializeObject<List<float>>(data_value);
|
||
}
|
||
|
||
if (userDatas.TryGetValue("AdvertAllCount", out data_value))
|
||
{
|
||
InitAdvertCount(data_value);
|
||
}
|
||
|
||
if (userDatas.TryGetValue("DiamondShopRefreshCount", out data_value))
|
||
{
|
||
_diamondShopRefreshCount = (int.Parse(data_value));
|
||
}
|
||
if (userDatas.TryGetValue("DiamondShopRefreshTime", out data_value))
|
||
{
|
||
_diamondShopRefreshTime = DateTime.Parse(data_value);
|
||
}
|
||
if (userDatas.TryGetValue("DiamondShopItemRecords", out data_value))
|
||
{
|
||
_diamondShopItemRecords = JsonConvert.DeserializeObject<Dictionary<int, ItemShopRecord>>(data_value);
|
||
}
|
||
|
||
if (userDatas.TryGetValue(BlackFridayCouponData.PlayFabDataKey, out data_value))
|
||
{
|
||
// Debug.Log($"<color=#23aaf2>Black Friday load data!!</color>");
|
||
CouponData.LoadData(data_value);
|
||
}
|
||
}
|
||
|
||
public float GetBuyPaymentAmount()
|
||
{
|
||
if (buyData.Count > 0)
|
||
{
|
||
return buyData[0];
|
||
}
|
||
return 0;
|
||
}
|
||
|
||
public void AddVoucher(int value)
|
||
{
|
||
Voucher = Voucher + value;
|
||
PlayFabMgr.Instance.UpdateUserDataValue("Voucher", Voucher.ToString());
|
||
}
|
||
public void Init()
|
||
{
|
||
PackManagerMap = _tables.TbShopPackManager.DataMap;
|
||
PackManagerataList = _tables.TbShopPackManager.DataList;
|
||
|
||
CreateTime = GContext.container.Resolve<IUserService>().CreateTime;
|
||
InitShopPackData();
|
||
ClearAdvertCount();
|
||
if (disposables == null)
|
||
{
|
||
disposables = new CompositeDisposable();
|
||
GContext.OnEvent<SKUDetailDataEvent>().Subscribe(GetIAPPrice).AddTo(disposables);
|
||
}
|
||
GetSKUs();
|
||
}
|
||
|
||
private static System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(@"^[A-Z]+");
|
||
private string RemoveCurrencyCode(string price)
|
||
{
|
||
return regex.Replace(price, string.Empty);
|
||
}
|
||
|
||
public async void GetSKUs()
|
||
{
|
||
Debug.Log("[DataCenter.PlayerData] GetSKUList fetch");
|
||
SKUDetails = await IAPService.GetSKUs();
|
||
SKUDetailDataMap.Clear();
|
||
if (SKUDetails != null && SKUDetails.Count > 0)
|
||
{
|
||
for (int i = 0; i < SKUDetails.Count; i++)
|
||
{
|
||
if (SKUDetails[i].ProdKey != null && !SKUDetailDataMap.ContainsKey(SKUDetails[i].ProdKey))
|
||
{
|
||
#if UNITY_ANDROID || UNITY_EDITOR
|
||
var price = SKUDetails[i].price;
|
||
SKUDetails[i].price = RemoveCurrencyCode(price);
|
||
#endif
|
||
SKUDetailDataMap.Add(SKUDetails[i].ProdKey, SKUDetails[i]);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 与 SKUDetailDataEvent.prodPrice 一致:有商店价则用本地货币数值,否则回退 PaymentAmount(编辑器下与商店 SKU 一致时用 PaymentAmount)。
|
||
/// </summary>
|
||
float ResolveLocalProdPrice(IAPItemList iap)
|
||
{
|
||
if (iap == null)
|
||
return 0f;
|
||
if (SKUDetailDataMap.TryGetValue(iap.ProductId1, out var v))
|
||
{
|
||
#if UNITY_EDITOR
|
||
return iap.PaymentAmount;
|
||
#else
|
||
return v.ProdPrice;
|
||
#endif
|
||
}
|
||
return iap.PaymentAmount;
|
||
}
|
||
|
||
/// <summary>
|
||
/// RechargeAmount 任务进度:本地货币价格 ×100 取整,与配置 IAP 的目标量纲一致。
|
||
/// </summary>
|
||
public int GetRechargeAmountProgressValue(IAPItemList iap)
|
||
{
|
||
return Mathf.RoundToInt(ResolveLocalProdPrice(iap) * 100f);
|
||
}
|
||
|
||
void GetIAPPrice(SKUDetailDataEvent data)
|
||
{
|
||
if (data.iap != null)
|
||
{
|
||
data.prodPrice = ResolveLocalProdPrice(data.iap);
|
||
if (SKUDetailDataMap.TryGetValue(data.iap.ProductId1, out var v))
|
||
{
|
||
|
||
#if UNITY_ANDROID || UNITY_EDITOR
|
||
data.price = v.ProdPriceStr;
|
||
#else
|
||
data.price =$"{v.localeCurrencySymbol}{v.price}";
|
||
#endif
|
||
}
|
||
else
|
||
{
|
||
data.price = $"US${data.iap.PaymentAmount}";
|
||
}
|
||
}
|
||
else
|
||
{
|
||
data.price = LocalizationMgr.GetText("UI_TurntableInfoPopupPanel_10");
|
||
}
|
||
}
|
||
public ShopPackManager TbPackManagerGetOrDefault(int id)
|
||
{
|
||
return PackManagerMap.TryGetValue(id, out var v) ? v : null;
|
||
}
|
||
|
||
|
||
public void InitVoucher(int value)
|
||
{
|
||
Voucher = value;
|
||
}
|
||
|
||
private JObject GenExtraPurcheData(int dropID, IAPItemList iAPItemList, List<ItemData> itemDataGift)
|
||
{
|
||
int buyDataCount = buyData.Count;
|
||
var extraPurcheData = new JObject();
|
||
extraPurcheData["purchase_count"] = buyDataCount == 0 ? 1 : buyDataCount;
|
||
extraPurcheData["trade_name"] = iAPItemList.TradeName;
|
||
extraPurcheData["trade_type"] = iAPItemList.TradeType;
|
||
extraPurcheData["usd_price"] = iAPItemList.PaymentAmount;
|
||
extraPurcheData["iap_id"] = iAPItemList.ID;
|
||
extraPurcheData["drop_id"] = dropID;
|
||
extraPurcheData["trade_group"] = iAPItemList.TradeGroup;
|
||
|
||
if (itemDataGift != null)
|
||
{
|
||
for (int i = 0; i < itemDataGift.Count; i++)
|
||
{
|
||
extraPurcheData[$"item_{itemDataGift[i].id}"] = itemDataGift[i].count;
|
||
}
|
||
}
|
||
|
||
return extraPurcheData;
|
||
}
|
||
|
||
public async Task<bool> OnBuy(int dropID, ShopBuyTypeData buyType, IAPItemList iAPItemList, List<ItemData> itemDataGift, RewardType rewardShowType = RewardType.Normal)
|
||
{
|
||
if (iAPItemList == null)
|
||
{
|
||
return false;
|
||
}
|
||
if (Voucher >= iAPItemList.CostToken)
|
||
{
|
||
Voucher = Voucher - iAPItemList.CostToken;
|
||
PlayFabMgr.Instance.UpdateUserDataValue("Voucher", Voucher.ToString());
|
||
//二次弹窗
|
||
//回调
|
||
PlayFabMgr.Instance.UpdateUserDataValue("LastPaymentTime", $"{ZZTimeHelper.UtcNow()}__{0}");
|
||
BuySuccess(buyType, iAPItemList, itemDataGift, rewardShowType, true);
|
||
// OrderManager.OrderManager.OnOrderSuccess(buyType, iAPItemList, itemDataGift, rewardShowType, true);
|
||
if (!buyType.NoShow)
|
||
{
|
||
GContext.Publish(new ShowData());
|
||
}
|
||
return true;
|
||
}
|
||
else if (SKUDetailDataMap.TryGetValue(iAPItemList.ProductId1, out SKUDetail sku))
|
||
{
|
||
//充值购买平台
|
||
GameDebug.Log($"IAP_ID:{iAPItemList.ID}Price:${iAPItemList.PaymentAmount}");
|
||
|
||
var extraPurcheData = GenExtraPurcheData(dropID, iAPItemList, itemDataGift);
|
||
#if !UNITY_EDITOR
|
||
if (iAPItemList.PaymentAmount <= 0.5f || sku.ProdPrice <= 0.5f)
|
||
return false;
|
||
#endif
|
||
|
||
//在这里存补单数据
|
||
ReplenishmentData replenishmentData = new ReplenishmentData()
|
||
{
|
||
BuyType = buyType,
|
||
ItemData = itemDataGift,
|
||
IAPID = iAPItemList.ID,
|
||
ShowType = rewardShowType,
|
||
CONTENT_ID = sku.ProdID,
|
||
CURRENCY = sku.price_currency_code,
|
||
#if !UNITY_EDITOR
|
||
ProdPrice = sku.ProdPrice,
|
||
#endif
|
||
PRICE = iAPItemList.PaymentAmount,
|
||
extraPurcheData = extraPurcheData,
|
||
//orderId = orderId;
|
||
time = ZZTimeHelper.UtcNow().ToString()
|
||
};
|
||
|
||
string replenishmentDataStr = JsonConvert.SerializeObject(replenishmentData);
|
||
|
||
//付费成功的回调,可能购买成功之后也会调用一次
|
||
Action<string> OnSuccessFromSdk = (orderId) =>
|
||
{
|
||
switch (buyType.type)
|
||
{
|
||
case ShopBuyType.ShopToken:
|
||
//商店首次购买记录
|
||
OnShopTokenSuccess(buyType.ID, true);
|
||
break;
|
||
}
|
||
};
|
||
|
||
PaymentInfo result = await IAPService.Pay(OnSuccessFromSdk, replenishmentDataStr,
|
||
sku, 1, iAPItemList.PaymentAmount, extraPurcheData);
|
||
|
||
if (result.isSuccess)
|
||
{
|
||
PlayFabMgr.Instance.UpdateUserDataValue("LastPaymentTime", $"{ZZTimeHelper.UtcNow()}__{sku.price}");
|
||
BuySuccess(buyType, iAPItemList, itemDataGift, rewardShowType);
|
||
// OrderManager.OrderManager.OnOrderSuccess(buyType, iAPItemList, itemDataGift, rewardShowType);
|
||
if (!buyType.NoShow)
|
||
{
|
||
GContext.Publish(new ShowData());
|
||
}
|
||
return true;
|
||
}
|
||
else
|
||
{
|
||
if (result.isSuccessFromSdk || result.code == "10000")
|
||
{
|
||
GameObject go = await UIManager.Instance.ShowUI(UITypes.NoticeConfirmPopupPanel);
|
||
var NoticeConfirmPopupPanel = go.GetComponent<NoticeConfirmPopupPanel>();
|
||
string info = LocalizationMgr.GetText("UI_ToastPanel_ErrCode_1");
|
||
string title = LocalizationMgr.GetText("UI_FishingShopPanel_25");
|
||
NoticeConfirmPopupPanel.Init(1, title, info);
|
||
}
|
||
else
|
||
{
|
||
switch (result.code)
|
||
{
|
||
case "10001":
|
||
{
|
||
GameObject go = await UIManager.Instance.ShowUI(UITypes.NoticeConfirmPopupPanel);
|
||
var NoticeConfirmPopupPanel = go.GetComponent<NoticeConfirmPopupPanel>();
|
||
string info = LocalizationMgr.GetText("UI_FishingShopPanel_28");
|
||
string title = LocalizationMgr.GetText("UI_FishingShopPanel_27");
|
||
NoticeConfirmPopupPanel.Init(1, title, info);
|
||
}
|
||
break;
|
||
case "10002":
|
||
{
|
||
GameObject go = await UIManager.Instance.ShowUI(UITypes.NoticeConfirmPopupPanel);
|
||
var NoticeConfirmPopupPanel = go.GetComponent<NoticeConfirmPopupPanel>();
|
||
string info = LocalizationMgr.GetText("UI_ToastPanel_ErrCode_1");
|
||
string title = LocalizationMgr.GetText("UI_FishingShopPanel_25");
|
||
NoticeConfirmPopupPanel.Init(1, title, info);
|
||
}
|
||
break;
|
||
default:
|
||
ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_2"));
|
||
break;
|
||
}
|
||
}
|
||
return false;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_28"));
|
||
return false;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 商店购买记录
|
||
/// </summary>
|
||
/// <param name="id"></param>
|
||
/// <param name="isFromSdk"> 是付费成功 还是验证成功 </param>
|
||
void OnShopTokenSuccess(int id, bool isFromSdk)
|
||
{
|
||
var shopToken = _tables.TbShopToken.GetOrDefault(id);
|
||
if (shopToken != null)
|
||
{
|
||
if (isFromSdk)
|
||
{
|
||
//商店物品购买付费成功的回调记录 ShopTokenID
|
||
AddShopGiftBuyCount(id);
|
||
}
|
||
else
|
||
{
|
||
//商店物品购买付费成功并验证通过的回调记录 IAPItemListID
|
||
AddShopGiftBuyCount(shopToken.IAPID);
|
||
|
||
if (shopToken.Type == 3)
|
||
{
|
||
//钻石付费成功 或者购买成功
|
||
if (CouponData.IsActive)
|
||
{
|
||
CouponData.SetStateBought();
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|
||
}
|
||
public async System.Threading.Tasks.Task GetReplenishmentData()
|
||
{
|
||
//补单信息从服务器拿
|
||
replenishmentDataStrs = await IAPService.GetOrderUnreceived();
|
||
}
|
||
|
||
public async System.Threading.Tasks.Task ReleaseReplenishment()
|
||
{
|
||
ReplenishmentDatas.Clear();
|
||
if (replenishmentDataStrs == null || replenishmentDataStrs.Count == 0)
|
||
{
|
||
return;
|
||
}
|
||
List<string> orderIDList = new List<string>();
|
||
foreach (var item in replenishmentDataStrs)
|
||
{
|
||
//服务器判断是否支付
|
||
ReplenishmentData replenishment = JsonConvert.DeserializeObject<ReplenishmentData>(item.Value);
|
||
replenishment.orderId = item.Key;
|
||
ReplenishmentDatas.Add(replenishment);
|
||
orderIDList.Add(item.Key);
|
||
}
|
||
bool result = await IAPService.ConfirmOrders(orderIDList);
|
||
if (!result)
|
||
{
|
||
//服务器返回错误
|
||
ReplenishmentDatas.Clear();
|
||
}
|
||
}
|
||
|
||
public void ReleaseReplenishmentData()
|
||
{
|
||
if (ReplenishmentDatas.Count > 0)
|
||
{
|
||
//确认补单 删除订单
|
||
for (int i = 0; i < ReplenishmentDatas.Count; i++)
|
||
{
|
||
try
|
||
{
|
||
Replenishment(ReplenishmentDatas[i]);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
Debug.LogError($"Replenishment Exception:{ex}");
|
||
}
|
||
}
|
||
replenishmentDataStrs.Clear();
|
||
ReplenishmentDatas.Clear();
|
||
}
|
||
}
|
||
|
||
private string payment => ChannelManager.IsRustoreStore ? "rustore" : "google";
|
||
void Replenishment(ReplenishmentData data)
|
||
{
|
||
IAPItemList iAPItemList = _tables.TbIAPItemList.GetOrDefault(data.IAPID);
|
||
data.ShowType = RewardType.NormalRestore;
|
||
var itemDataGift = data.ItemData;
|
||
|
||
var config = GContext.container.Resolve<IConfig>();
|
||
var s2s = config.Get("AFS2S", "Off").ToLower() == "on";
|
||
using (var e = GEvent.RevenueEvent(s2s))
|
||
{
|
||
e.AddContent("af_content_id", data.CONTENT_ID)
|
||
.AddContent("af_price", data.PRICE)
|
||
.AddContent("af_currency", data.CURRENCY)
|
||
#if UNITY_ANDROID
|
||
.AddContent("payment", payment)
|
||
#else
|
||
.AddContent("payment", "apple")
|
||
#endif
|
||
.AddContent("af_quantity", 1)
|
||
.AddContent("order_id", data.orderId)
|
||
.AddContent("payment_state", "finish")
|
||
.AddContent("restore", true)
|
||
.AddContent("af_revenue", data.ProdPrice);
|
||
|
||
int buyDataCount = buyData.Count;
|
||
data.extraPurcheData["purchase_count"] = buyDataCount == 0 ? 1 : buyDataCount;
|
||
|
||
if (null != data.extraPurcheData)
|
||
{
|
||
foreach (var item in data.extraPurcheData)
|
||
{
|
||
e.AddContent(item.Key, item.Value);
|
||
}
|
||
}
|
||
}
|
||
PlayFabMgr.Instance.UpdateUserDataValue("LastPaymentTime", $"{ZZTimeHelper.UtcNow()}__{data.ProdPrice}");
|
||
BuySuccess(data.BuyType, iAPItemList, itemDataGift, data.ShowType);
|
||
if (data.BuyType.extraPurcheData != null)
|
||
{
|
||
// OrderManager.OrderManager.OnReplenish(data.BuyType, iAPItemList, itemDataGift, data.ShowType);
|
||
}
|
||
}
|
||
public float GetBuyData()
|
||
{
|
||
return buyData.Count > 0 ? buyData[0] : 0;
|
||
}
|
||
void BuySuccess(ShopBuyTypeData buyType, IAPItemList iAPItemList, List<ItemData> itemDataGift, RewardType rewardShowType, bool Voucher = false)
|
||
{
|
||
if (!Voucher)
|
||
{
|
||
if (buyData.Count == 0)
|
||
{
|
||
buyData.Add(iAPItemList.PaymentAmount);
|
||
}
|
||
else
|
||
{
|
||
buyData[0] += iAPItemList.PaymentAmount;
|
||
}
|
||
buyData.Add(iAPItemList.ID);
|
||
PlayFabMgr.Instance.UpdateUserDataValue("BuyData", JsonMapper.ToJson(buyData));
|
||
#if AGG
|
||
GEvent.SetUserProp("Total_consumption", buyData[0]);
|
||
#endif
|
||
}
|
||
// new TotalRechargeManager().AddProgress(iAPItemList.VIPPoint);
|
||
GContext.Publish(new ConditionTypeEvent(ConditionType.RechargeAmount, GetRechargeAmountProgressValue(iAPItemList)));
|
||
ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_3"));
|
||
if (!buyType.IsHide && itemDataGift != null && itemDataGift.Count > 0)
|
||
{
|
||
var newItemData = itemDataGift.Where(x => x.id != 3002).ToList();
|
||
GContext.Publish(new ShowData(newItemData, rewardShowType));
|
||
}
|
||
|
||
GContext.container.Resolve<PlayerData>().AddVIPScore(iAPItemList.VIPPoint, true);
|
||
if (itemDataGift != null && itemDataGift.Count > 0)
|
||
{
|
||
GContext.container.Resolve<PlayerItemData>().AddItem(itemDataGift, null);
|
||
}
|
||
int curEnd = ZZTimeHelper.UtcNow().UtcNowOffset().Day;
|
||
switch (buyType.type)
|
||
{
|
||
case ShopBuyType.None:
|
||
break;
|
||
case ShopBuyType.ShopToken:
|
||
//商店首次购买记录
|
||
OnShopTokenSuccess(buyType.ID, false);
|
||
break;
|
||
case ShopBuyType.ShopPackDailyBuy:
|
||
if (buyType.endDay == curEnd)
|
||
{
|
||
//每日更新礼包
|
||
AddShopPackDailyBuyCount(buyType.key, 1);
|
||
}
|
||
break;
|
||
case ShopBuyType.EventPack:
|
||
//Event 礼包
|
||
GContext.container.Resolve<FishingEventData>().OnBuyEventPack(buyType.ID);
|
||
break;
|
||
case ShopBuyType.TriggerPack:
|
||
//触发礼包
|
||
// if (buyType.ID == 4000002)
|
||
// GContext.container.Resolve<IEventOfferJourneyData>()?.OnBuySuccess();
|
||
// else
|
||
// GContext.container.Resolve<TriggerPackData>().AddTriggerPackCount(buyType.ID);
|
||
break;
|
||
|
||
}
|
||
GContext.Publish(new ConditionTypeEvent(ConditionType.MakeInAppPurchase, 1));
|
||
}
|
||
/// <summary>
|
||
/// 一个统一的跨天刷新节点
|
||
/// </summary>
|
||
public void InitShopPackData()
|
||
{
|
||
int dayOfYear = shopPackDailyBuyCount.GetValueOrDefault("0");
|
||
//if (shopPackDailyBuyCount.TryGetValue("0", out int dayOfYear))
|
||
//{
|
||
if (dayOfYear != ZZTimeHelper.UtcNow().UtcNowOffset().DayOfYear)
|
||
{
|
||
shopPackDailyBuyCount.Clear();
|
||
GContext.container.Resolve<FishingEventData>().AllRefresh();
|
||
// if (VIPAdPackData != null)
|
||
// {
|
||
// VIPAdPackData.day = ZZTimeHelper.UtcNow().UtcNowOffset().DayOfYear;
|
||
// VIPAdPackData.index = 0;
|
||
// VIPAdPackData.cdTime = null;
|
||
// SetAdvRedPoint();
|
||
// }
|
||
TurntableAdData = null;
|
||
shopPackDailyBuyCount["0"] = ZZTimeHelper.UtcNow().UtcNowOffset().DayOfYear;
|
||
PlayFabMgr.Instance.UpdateUserDataValue("ShopPackBuyCount", JsonMapper.ToJson(shopPackDailyBuyCount));
|
||
}
|
||
//}
|
||
}
|
||
|
||
//每日购买(ID)次数(触发(Type)),每日重置
|
||
public void AddShopPackDailyBuyCount(int id, int count, bool addAll = true)
|
||
{
|
||
string idStr = id.ToString();
|
||
AddShopPackDailyBuyCount(idStr, count);
|
||
if (addAll)
|
||
{
|
||
AddAllPackCount(id, count);
|
||
}
|
||
}
|
||
//需要每日清空的数据 懒得改名
|
||
public void AddShopPackDailyBuyCount(string idStr, int count = 1)
|
||
{
|
||
if (shopPackDailyBuyCount.ContainsKey(idStr))
|
||
{
|
||
shopPackDailyBuyCount[idStr] += count;
|
||
}
|
||
else
|
||
{
|
||
shopPackDailyBuyCount.Add(idStr, count);
|
||
}
|
||
if (!shopPackDailyBuyCount.ContainsKey("0"))
|
||
{
|
||
shopPackDailyBuyCount["0"] = ZZTimeHelper.UtcNow().UtcNowOffset().DayOfYear;
|
||
}
|
||
PlayFabMgr.Instance.UpdateUserDataValue("ShopPackBuyCount", JsonMapper.ToJson(shopPackDailyBuyCount));
|
||
}
|
||
public int GetShopPackBuyCount(int id)
|
||
{
|
||
string idStr = id.ToString();
|
||
return GetShopPackBuyCount(idStr);
|
||
}
|
||
public int GetShopPackBuyCount(string id)
|
||
{
|
||
if (shopPackDailyBuyCount.ContainsKey(id))
|
||
{
|
||
return shopPackDailyBuyCount[id];
|
||
}
|
||
return 0;
|
||
}
|
||
|
||
public void SetAdvRedPoint()
|
||
{
|
||
bool isRed = false;
|
||
var DailyGiftPackList = GContext.container.Resolve<PlayerData>().priceLevel.DailyGiftPackList;
|
||
int id;
|
||
Daily daily;
|
||
DateTime now = ZZTimeHelper.UtcNow().UtcNowOffset();
|
||
ShopPackManager dailyGiftPackM = null;
|
||
for (int i = 0; i < DailyGiftPackList.Count; i++)
|
||
{
|
||
id = DailyGiftPackList[i];
|
||
dailyGiftPackM = TbPackManagerGetOrDefault(id);
|
||
if (dailyGiftPackM == null) continue;
|
||
daily = dailyGiftPackM.TimeDefinition as Daily;
|
||
if (TimeSpan.FromSeconds(daily.StartTime) <= now.TimeOfDay && TimeSpan.FromSeconds(daily.EndTime) > now.TimeOfDay)
|
||
{
|
||
break;
|
||
}
|
||
}
|
||
if (dailyGiftPackM != null)
|
||
{
|
||
isRed = GetShopPackBuyCount(dailyGiftPackM.ID) < 1;
|
||
}
|
||
RedPointManager.Instance.SetRedPointState(HomeBtnAdvert.redKey, isRed && IsOpenAdPack());
|
||
}
|
||
|
||
/// <summary>
|
||
/// 作为首次购买的依据 ShopTokenID 或 IAPItemListID有次数都不是首充
|
||
/// </summary>
|
||
/// <param name="id"></param>
|
||
/// <param name="count"></param>
|
||
public void AddShopGiftBuyCount(int id, int count = 1)
|
||
{
|
||
if (shopGiftBuyCount.ContainsKey(id))
|
||
{
|
||
shopGiftBuyCount[id] += count;
|
||
}
|
||
else
|
||
{
|
||
shopGiftBuyCount.Add(id, count);
|
||
}
|
||
PlayFabMgr.Instance.UpdateUserDataValue("ShopGiftBuyCount", JsonMapper.ToJson(shopGiftBuyCount));
|
||
}
|
||
|
||
/// <summary>
|
||
/// 作为首次购买的依据 ShopTokenID 或 IAPItemListID有次数都不是首充
|
||
/// </summary>
|
||
/// <param name="id"></param>
|
||
public int GiftBuyCount(int id)
|
||
{
|
||
shopGiftBuyCount.TryGetValue(id, out int buyCount);
|
||
return buyCount;
|
||
}
|
||
//=====================================礼包=====================================
|
||
#region =================礼包=========================
|
||
#region 链式礼包
|
||
public void SetChainPackData(DailySignEvent chainPackData)
|
||
{
|
||
ChainPackData = chainPackData;
|
||
}
|
||
void SetChainPackRed()
|
||
{
|
||
bool isRed = false;
|
||
if (chainPackM != null)
|
||
{
|
||
if (chainPackM.VIPPackList[ChainPackData.lastID].Count > ChainPackData.index)
|
||
{
|
||
var pack = _tables.TbPack.GetOrDefault(chainPackM.VIPPackList[ChainPackData.lastID][ChainPackData.index]);
|
||
isRed = _tables.TbIAPItemList.GetOrDefault(pack.IAPID) == null;
|
||
}
|
||
}
|
||
RedPointManager.Instance.SetRedPointState(RedPointName.Home_Gift2, isRed);
|
||
}
|
||
|
||
public void AddChainPack(FishingEvent t)
|
||
{
|
||
if (ChainPackData == null || ChainPackData.ID != t.ID)
|
||
{
|
||
|
||
DateTime dateTime = ZZTimeHelper.UtcNow().UtcNowOffset();
|
||
var time = dateTime.AddDays(10).Date;
|
||
if (t.TimeDefinition is Weekly)
|
||
{
|
||
Weekly weekly = (Weekly)t.TimeDefinition;
|
||
int offfset = (int)dateTime.DayOfWeek - weekly.StartTime;
|
||
|
||
if (offfset < 0)
|
||
{
|
||
offfset = -offfset;
|
||
}
|
||
else
|
||
{
|
||
offfset = 7 - offfset;
|
||
}
|
||
time = dateTime.AddDays(offfset).Date;
|
||
}
|
||
else if (t.TimeDefinition is LimitedTime)
|
||
{
|
||
LimitedTime limitedTime = (LimitedTime)t.TimeDefinition;
|
||
time = GlobalUtils.TryParseDateTime(limitedTime.EndTime, ZZTimeHelper.UtcNow()).UtcNowOffset();
|
||
}
|
||
|
||
|
||
ChainPackData = new DailySignEvent()
|
||
{
|
||
ID = t.ID,
|
||
lastID = GContext.container.Resolve<PlayerData>().PriceLv,//VIP等级,礼包连该新,尽量少改代码
|
||
index = 0,
|
||
time = time.ToString()
|
||
};
|
||
PlayFabMgr.Instance.UpdateUserDataValue("ChainPackDataNew", JsonMapper.ToJson(ChainPackData));
|
||
chainPackM = null;
|
||
}
|
||
if (chainPackM == null)
|
||
{
|
||
chainPackM = _tables.TbEventPackManager.GetOrDefault(t.RedirectID);
|
||
UITypes.GiftChainCommon_SubmarinePanel.SetType(chainPackM.Panel);
|
||
GContext.container.Resolve<IFaceUIService>().AddGiftFaceUI(chainPackM.ID, UITypes.GiftChainCommon_SubmarinePanel, chainPackM.PackType);
|
||
SetChainPackRed();
|
||
GContext.Publish(new TargetEvent(chainPackM.ID, 3, 10));
|
||
ILoadResourceService loadResourceService = GContext.container.Resolve<ILoadResourceService>();
|
||
loadResourceService.EnqueueBundleSilently(new List<string>() { chainPackM.Panel });
|
||
}
|
||
}
|
||
|
||
public bool IsOpenChainGiftPack()
|
||
{
|
||
bool isOpen = false;
|
||
if (chainPackM != null)
|
||
{
|
||
if (chainPackM.VIPPackList[ChainPackData.lastID].Count > ChainPackData.index)
|
||
{
|
||
var endTime = GetChainEndTime();
|
||
TimeSpan now = endTime - ZZTimeHelper.UtcNow().UtcNowOffset();
|
||
double seconds = now.TotalSeconds;
|
||
isOpen = seconds > 0;
|
||
}
|
||
}
|
||
return isOpen;
|
||
}
|
||
public void AddOpenChainGifIndex()
|
||
{
|
||
if (chainPackM == null || ChainPackData == null)
|
||
{
|
||
return;
|
||
}
|
||
ChainPackData.index++;
|
||
SetChainPackRed();
|
||
if (chainPackM.VIPPackList[ChainPackData.lastID].Count <= ChainPackData.index)
|
||
{
|
||
AddAllPackCount(chainPackM.ID, 1);
|
||
}
|
||
PlayFabMgr.Instance.UpdateUserDataValue("ChainPackDataNew", JsonMapper.ToJson(ChainPackData));
|
||
//链式礼包 特殊处理
|
||
GContext.Publish(new TargetEvent(chainPackM.ID, 3, 10));
|
||
}
|
||
|
||
public DateTime GetChainEndTime()
|
||
{
|
||
return GlobalUtils.TryParseDateTime(ChainPackData.time, ZZTimeHelper.UtcNow().UtcNowOffset());
|
||
}
|
||
#endregion
|
||
public int GetAllPackCount(int id)
|
||
{
|
||
if (shopAllPackBuyCount.ContainsKey(id))
|
||
{
|
||
return shopAllPackBuyCount[id];
|
||
}
|
||
return 0;
|
||
}
|
||
//总购买次数
|
||
public void AddAllPackCount(int id, int count)
|
||
{
|
||
if (shopAllPackBuyCount.ContainsKey(id))
|
||
{
|
||
shopAllPackBuyCount[id] += count;
|
||
}
|
||
else
|
||
{
|
||
shopAllPackBuyCount.Add(id, count);
|
||
}
|
||
GContext.Publish(new ConditionTypeEvent(ConditionType.BuyPack, count));
|
||
PlayFabMgr.Instance.UpdateUserDataValue("ShopAllPackBuyCount", JsonMapper.ToJson(shopAllPackBuyCount));
|
||
}
|
||
#endregion
|
||
//========================================礼包========================================
|
||
#region 广告次数
|
||
public void InitAdvertCount(string data)
|
||
{
|
||
if (string.IsNullOrEmpty(data) == false)
|
||
{
|
||
advertCount = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<int, int>>(data);
|
||
}
|
||
}
|
||
public void AddAdticket(int count)
|
||
{
|
||
if (advertCount.ContainsKey(-2))
|
||
{
|
||
advertCount[-2] += count;
|
||
}
|
||
else
|
||
{
|
||
advertCount[-2] = count;
|
||
}
|
||
if (advertCount[-2] < 0)
|
||
{
|
||
advertCount[-2] = 0;
|
||
}
|
||
#if AGG
|
||
if (count < 0)
|
||
{
|
||
|
||
using (var e = GEvent.GameEvent("item_change", gaSend: true))
|
||
{
|
||
e.AddContent("item_id", 1006)
|
||
.AddContent("state_info", "cost")
|
||
.AddContent("change_num", count);
|
||
}
|
||
}
|
||
#endif
|
||
PlayFabMgr.Instance.UpdateUserDataValue("AdvertAllCount", JsonMapper.ToJson(advertCount));
|
||
GContext.Publish(new ResAddEvent(1006));
|
||
}
|
||
public int GetAdticketCount()
|
||
{
|
||
return advertCount.GetValueOrDefault(-2);
|
||
}
|
||
public int AddAdvertCount(int id)
|
||
{
|
||
ClearAdvertCount();
|
||
if (advertCount.ContainsKey(0))
|
||
{
|
||
advertCount[0]++;
|
||
}
|
||
else
|
||
{
|
||
advertCount[0] = 1;
|
||
}
|
||
if (advertCount.ContainsKey(id))
|
||
{
|
||
advertCount[id] += 1;
|
||
}
|
||
else
|
||
{
|
||
advertCount.Add(id, 1);
|
||
}
|
||
PlayFabMgr.Instance.UpdateUserDataValue("AdvertAllCount", JsonMapper.ToJson(advertCount));
|
||
return advertCount[id];
|
||
}
|
||
public void ClearAdvertCount()
|
||
{
|
||
int allCount = advertCount.GetValueOrDefault(0);
|
||
int ticket = advertCount.GetValueOrDefault(-2);
|
||
if (advertCount.TryGetValue(-1, out int day))
|
||
{
|
||
if (day != ZZTimeHelper.UtcNow().UtcNowOffset().DayOfYear)
|
||
{
|
||
advertCount.Clear();
|
||
advertCount[-1] = ZZTimeHelper.UtcNow().UtcNowOffset().DayOfYear;
|
||
advertCount[0] = allCount;
|
||
advertCount[-2] = ticket;
|
||
PlayFabMgr.Instance.UpdateUserDataValue("AdvertAllCount", JsonMapper.ToJson(advertCount));
|
||
}
|
||
}
|
||
else
|
||
{
|
||
advertCount[-1] = ZZTimeHelper.UtcNow().UtcNowOffset().DayOfYear;
|
||
}
|
||
}
|
||
public int GetAdvertCount(int id)
|
||
{
|
||
if (advertCount.ContainsKey(id))
|
||
{
|
||
return advertCount[id];
|
||
}
|
||
return 0;
|
||
}
|
||
#endregion
|
||
|
||
#region 主界面VIP礼包
|
||
// public void SetVIPAdPackData(AdvertData vipAdPackData)
|
||
// {
|
||
// int dayOfYear = ZZTimeHelper.UtcNow().UtcNowOffset().DayOfYear;
|
||
// if (vipAdPackData != null && vipAdPackData.day != dayOfYear)
|
||
// {
|
||
// vipAdPackData = null;
|
||
// }
|
||
// VIPAdPackData = vipAdPackData;
|
||
// }
|
||
// public void SetVIPPackNext()
|
||
// {
|
||
// List<AdConfig> adConfigs = _tables.TbAdConfig.DataList;
|
||
// if (VIPAdPackData == null)
|
||
// {
|
||
// VIPAdPackData = new AdvertData();
|
||
// VIPAdPackData.day = ZZTimeHelper.UtcNow().UtcNowOffset().DayOfYear;
|
||
// }
|
||
// VIPAdPackData.index++;
|
||
// if (VIPAdPackData.index < adConfigs.Count)
|
||
// {
|
||
// AdConfig adConfig = adConfigs[VIPAdPackData.index];
|
||
// VIPAdPackData.ID = adConfig.ID;
|
||
// AdConfig adConfig1 = adConfigs[VIPAdPackData.index - 1];
|
||
// VIPAdPackData.cdTime = ZZTimeHelper.UtcNow().UtcNowOffset().AddSeconds(adConfig1.Interval).ToString();
|
||
// }
|
||
// PlayFabMgr.Instance.UpdateUserDataValue("VIPAdPackData", JsonMapper.ToJson(VIPAdPackData));
|
||
// //GContext.Publish(new VIPAdPackDataEvent());
|
||
// }
|
||
// public DateTime GetVIPAdPackTime()
|
||
// {
|
||
// if (VIPAdPackData != null)
|
||
// {
|
||
// return GlobalUtils.TryParseDateTime(VIPAdPackData.cdTime, ZZTimeHelper.UtcNow().UtcNowOffset());
|
||
// }
|
||
// else
|
||
// {
|
||
// return ZZTimeHelper.UtcNow().UtcNowOffset();
|
||
// }
|
||
// }
|
||
//public AdConfig GetVIPAdPackConfig()
|
||
//{
|
||
// if (VIPAdPackData == null)
|
||
// {
|
||
// VIPAdPackData = new AdvertData();
|
||
// VIPAdPackData.day = ZZTimeHelper.UtcNow().UtcNowOffset().DayOfYear;
|
||
// }
|
||
// return _tables.TbAdConfig.DataList[VIPAdPackData.index];
|
||
//}
|
||
public void OpenAdPack()
|
||
{
|
||
// if (VIPAdPackData != null && VIPAdPackData.isOpen)
|
||
// {
|
||
// return;
|
||
// }
|
||
// VIPAdPackData = new AdvertData();
|
||
// VIPAdPackData.day = ZZTimeHelper.UtcNow().UtcNowOffset().DayOfYear;
|
||
// VIPAdPackData.isOpen = true;
|
||
// PlayFabMgr.Instance.UpdateUserDataValue("VIPAdPackData", JsonMapper.ToJson(VIPAdPackData));
|
||
}
|
||
public bool IsOpenAdPack()
|
||
{
|
||
//if (GContext.container.Resolve<MMTestService>().ABAdOpen
|
||
// && GContext.container.Resolve<PlayerData>().lv < 40)
|
||
//{
|
||
// return false;
|
||
//}
|
||
// return VIPAdPackData != null && VIPAdPackData.isOpen;
|
||
return false;
|
||
}
|
||
public bool IsShowVIPAdTimer()
|
||
{
|
||
// List<AdConfig> adConfigs = _tables.TbAdConfig.DataList;
|
||
// return VIPAdPackData.index >= adConfigs.Count;
|
||
return false;
|
||
}
|
||
#endregion
|
||
|
||
#region TurntableAd
|
||
public DailySignEvent TurntableAdData;
|
||
/*
|
||
About TurntableAdData:
|
||
lastID: the day this ad is activated
|
||
ID: ID of the current ad
|
||
time: The end time of coolDown for the current Ad
|
||
*/
|
||
public WheelAd GetTurntableAdCofig()
|
||
{
|
||
if (TurntableAdData == null)
|
||
{
|
||
TurntableAdData = new DailySignEvent();
|
||
TurntableAdData.index = 1;
|
||
TurntableAdData.lastID = ZZTimeHelper.UtcNow().UtcNowOffset().DayOfYear;
|
||
}
|
||
return _tables.TbWheelAd[TurntableAdData.index];
|
||
}
|
||
public void UpdateTurntableAd()
|
||
{
|
||
var adConfigs = _tables.TbWheelAd;
|
||
if (TurntableAdData == null)
|
||
{
|
||
TurntableAdData = new DailySignEvent();
|
||
TurntableAdData.index = 1;
|
||
TurntableAdData.lastID = ZZTimeHelper.UtcNow().UtcNowOffset().DayOfYear;
|
||
}
|
||
TurntableAdData.index++;
|
||
if (TurntableAdData.index <= adConfigs.DataList.Count)
|
||
{
|
||
TurntableAdData.ID = adConfigs[TurntableAdData.index].ID;
|
||
TurntableAdData.time = ZZTimeHelper.UtcNow().UtcNowOffset()
|
||
.AddSeconds(adConfigs[TurntableAdData.index - 1].Interval).ToString();
|
||
// isOverForToday = false;
|
||
// }
|
||
// else
|
||
// {
|
||
// isOverForToday = true;
|
||
}
|
||
PlayFabMgr.Instance.UpdateUserDataValue("TurntableAdData", Newtonsoft.Json.JsonConvert.SerializeObject(TurntableAdData));
|
||
// GContext.Publish(new VIPAdPackDataEvent());
|
||
}
|
||
public bool IsTurntableAdMaxOut()
|
||
{
|
||
if (TurntableAdData == null)
|
||
{
|
||
TurntableAdData = new DailySignEvent();
|
||
TurntableAdData.index = 1;
|
||
TurntableAdData.lastID = ZZTimeHelper.UtcNow().UtcNowOffset().DayOfYear;
|
||
}
|
||
return TurntableAdData.index > _tables.TbWheelAd.DataList.Count;
|
||
}
|
||
public DateTime GetTurnTableNextAdTime()
|
||
{
|
||
if (TurntableAdData == null)
|
||
{
|
||
return ZZTimeHelper.UtcNow().UtcNowOffset();
|
||
}
|
||
return GlobalUtils.TryParseDateTime(TurntableAdData.time, ZZTimeHelper.UtcNow().UtcNowOffset());
|
||
}
|
||
#endregion
|
||
#region Diamond Shop
|
||
public class ItemShopData
|
||
{
|
||
public int ItemShopID;
|
||
public ItemShopRecord Record;
|
||
// public int SortID;
|
||
public int Count;
|
||
public int DiamondCost;
|
||
|
||
public int GetDiscountDiamondCost()
|
||
{
|
||
return Mathf.RoundToInt(DiamondCost * Record.Discount);
|
||
}
|
||
}
|
||
public List<ItemShopData> GetItemShopData()
|
||
{
|
||
if (CheckIfRefreshItemShop())
|
||
{
|
||
AutoRefreshDiamonShop();
|
||
}
|
||
var itemShopDatas = new List<ItemShopData>();
|
||
var diamondStoreData = _tables.TbItemStore.DataMap;
|
||
foreach (var record in _diamondShopItemRecords)
|
||
{
|
||
if (!diamondStoreData.ContainsKey(record.Key))
|
||
continue;
|
||
|
||
var itemShopData = diamondStoreData[record.Key];
|
||
var count = itemShopData.ItemNumber;
|
||
var diamondCost = itemShopData.TokenNumber;
|
||
// var sortID = itemShopData.SortId;
|
||
itemShopDatas.Add(new ItemShopData
|
||
{
|
||
ItemShopID = record.Key,
|
||
// SortID = sortID,
|
||
Record = record.Value,
|
||
Count = count,
|
||
DiamondCost = diamondCost,
|
||
});
|
||
}
|
||
|
||
return itemShopDatas.ToList();
|
||
}
|
||
|
||
public TimeSpan GetDiamondShopRefreshTime()
|
||
{
|
||
var now = ZZTimeHelper.UtcNow().UtcNowOffset();
|
||
return _diamondShopRefreshTime - now;
|
||
}
|
||
public int GetDiamondShopRefreshCost()
|
||
{
|
||
var refreshCost = _tables.TbStoreConfig.Get(1).RefreshPrice;
|
||
if (_diamondShopRefreshCount >= refreshCost.Count)
|
||
{
|
||
//Test
|
||
// Debug.LogError("[PlayerShopData::GetDiamondShopRefreshCost]Can not refresh!");
|
||
return refreshCost[refreshCost.Count - 1];
|
||
|
||
}
|
||
return refreshCost[_diamondShopRefreshCount];
|
||
}
|
||
public (int refresh, int maxRefresh) GetDiamondShopRefreshInfo()
|
||
{
|
||
var maxRefresh = _tables.TbStoreConfig.Get(1).RefreshTimes;
|
||
return (maxRefresh - _diamondShopRefreshCount, maxRefresh);
|
||
}
|
||
|
||
|
||
public void SetItemShopSlotBought(int itemShopId)
|
||
{
|
||
_diamondShopItemRecords[itemShopId].hasBought = 1;
|
||
SetItemShopRedPoint();
|
||
PlayFabMgr.Instance.UpdateUserDataValue("DiamondShopItemRecords", JsonConvert.SerializeObject(_diamondShopItemRecords));
|
||
}
|
||
|
||
|
||
private bool CheckIfRefreshItemShop()
|
||
{
|
||
return _diamondShopRefreshTime <= ZZTimeHelper.UtcNow().UtcNowOffset();
|
||
}
|
||
|
||
public void RefreshDiamondShop()
|
||
{
|
||
if (_diamondShopRefreshCount < _tables.TbStoreConfig.Get(1).RefreshTimes)
|
||
{
|
||
RefreshItemShop();
|
||
_diamondShopRefreshCount++;
|
||
PlayFabMgr.Instance.UpdateUserDataValue("DiamondShopRefreshCount", _diamondShopRefreshCount.ToString());
|
||
}
|
||
}
|
||
|
||
public void OnHonePanelLoaded()
|
||
{
|
||
if (CheckIfRefreshItemShop())
|
||
{
|
||
|
||
AutoRefreshDiamonShop();
|
||
}
|
||
SetItemShopRedPoint();
|
||
}
|
||
|
||
private void SetItemShopRedPoint()
|
||
{
|
||
var diamondSotre = _tables.TbItemStore.DataMap;
|
||
foreach (var record in _diamondShopItemRecords)
|
||
{
|
||
if (record.Value.hasBought == 0 && diamondSotre[record.Key].TokenNumber == 0)
|
||
{
|
||
RedPointManager.Instance.SetRedPointState(RedPointName.Home_Shop_Item, true);
|
||
return;
|
||
}
|
||
}
|
||
RedPointManager.Instance.SetRedPointState(RedPointName.Home_Shop_Item, false);
|
||
|
||
}
|
||
|
||
public void AutoRefreshDiamonShop()
|
||
{
|
||
Debug.Log("[PlayerShopData::GetItemSHopData] Refresh itemShop Data!");
|
||
//明天这个时候刷新
|
||
var now = ZZTimeHelper.UtcNow().UtcNowOffset();
|
||
var timeList = _tables.TbStoreConfig.Get(1).AutoRefresh.Split(':');
|
||
var hour = int.Parse(timeList[0]) == 24 ? 0 : int.Parse(timeList[0]);
|
||
var timeSpan = new TimeSpan(hour, int.Parse(timeList[1]), int.Parse(timeList[2]));
|
||
_diamondShopRefreshTime = new DateTime(now.Year, now.Month, now.Day).AddDays(1) + timeSpan;
|
||
|
||
_diamondShopRefreshCount = 0;
|
||
PlayFabMgr.Instance.UpdateUserDataValue("DiamondShopRefreshCount", _diamondShopRefreshCount.ToString());
|
||
PlayFabMgr.Instance.UpdateUserDataValue("DiamondShopRefreshTime", _diamondShopRefreshTime.ToString());
|
||
RefreshItemShop();
|
||
}
|
||
private void RefreshItemShop()
|
||
{
|
||
_diamondShopItemRecords.Clear();
|
||
var diamondStoreData = _tables.TbItemStore.DataMap;
|
||
|
||
//格子数量增加时修改调整
|
||
var totalCell = 6;
|
||
for (int i = 1; i <= totalCell; i++)
|
||
{
|
||
var datas = diamondStoreData.Values.Where(x => x.CellId == i).ToList();
|
||
var totalWeight = 0;
|
||
datas.ForEach(x => totalWeight += x.Weight);
|
||
var randomWeight = UnityEngine.Random.Range(1, totalWeight);
|
||
var curWeight = 0;
|
||
var itemID = -1;
|
||
foreach (var data in datas)
|
||
{
|
||
curWeight += data.Weight;
|
||
if (curWeight >= randomWeight)
|
||
{
|
||
itemID = data.ItemId;
|
||
if (data.ItemType == 1)
|
||
{
|
||
//随机鱼竿
|
||
var dropID = _tables.TbItem.DataMap[data.ItemId].RedirectID;
|
||
itemID = GContext.container.Resolve<PlayerItemData>().GetItemDataByDropIdAndType(dropID)[0].id;
|
||
}
|
||
else if (data.ItemType == 9)
|
||
{
|
||
//随机鱼卡
|
||
var mapDatas = _tables.TbMapData.DataList;
|
||
var lastMapID = GContext.container.Resolve<PlayerData>().lastMapId;
|
||
var mapIDs = new List<int>();
|
||
foreach (var map in mapDatas)
|
||
{
|
||
if (map.ID <= lastMapID)
|
||
{
|
||
mapIDs.Add(map.ID);
|
||
}
|
||
else
|
||
{
|
||
break;
|
||
}
|
||
}
|
||
var mapID = mapIDs[UnityEngine.Random.Range(0, mapIDs.Count)];
|
||
var mapData = _tables.TbMapData.GetOrDefault(mapID);
|
||
if (mapData != null)
|
||
{
|
||
itemID = mapData.FishCardItemList[itemID];
|
||
}
|
||
}
|
||
|
||
//Get disCount
|
||
var discount = 1.0f;
|
||
var allWeight = 0;
|
||
data.DiscountWeight.ForEach(weight => allWeight += weight);
|
||
var curWeight1 = UnityEngine.Random.Range(0, allWeight);
|
||
for (int j = 0; j < data.DiscountWeight.Count; j++)
|
||
{
|
||
curWeight1 -= data.DiscountWeight[j];
|
||
if (curWeight1 <= 0)
|
||
{
|
||
discount = data.Discount[j];
|
||
break;
|
||
}
|
||
}
|
||
_diamondShopItemRecords.Add(data.Id, new ItemShopRecord(itemID, discount, 0));
|
||
break;
|
||
}
|
||
}
|
||
|
||
}
|
||
PlayFabMgr.Instance.UpdateUserDataValue("DiamondShopItemRecords", JsonConvert.SerializeObject(_diamondShopItemRecords));
|
||
SetItemShopRedPoint();
|
||
}
|
||
#endregion
|
||
|
||
public void Dispose()
|
||
{
|
||
disposables?.Dispose();
|
||
disposables = null;
|
||
}
|
||
}
|
||
}
|
||
|