204 lines
5.1 KiB
C#
204 lines
5.1 KiB
C#
using cfg.ActorCfg;
|
|
using cfg.ChargeCfg;
|
|
using Framework;
|
|
using Gameplay;
|
|
using Gameplay.Net;
|
|
using NLDPB;
|
|
using PhxhSDK;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using static Gameplay.CommonUtils;
|
|
|
|
public class MonthlyPassManager : Singlenton<MonthlyPassManager>,IInitable
|
|
{
|
|
class MonthlyPassService
|
|
{
|
|
public bool IsPassUnlock { get; private set; }
|
|
|
|
public int RemainingDays { get; private set; }
|
|
|
|
public bool TodayHasClaimed { get; private set; }
|
|
|
|
public MonthlyPassService()
|
|
{
|
|
IsPassUnlock = false;
|
|
RemainingDays = 0;
|
|
TodayHasClaimed = false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 数据同步
|
|
/// </summary>
|
|
public void Refresh()
|
|
{
|
|
//TODO
|
|
//IsPassUnlock = Actor.Instance.Logic.GetCount((uint)LogicID.MonthlyPassUnlock) > 0;
|
|
//RemainingDays = (int)Actor.Instance.Logic.GetCount();
|
|
//TodayHasClaimed=
|
|
}
|
|
}
|
|
|
|
private MonthlyPassService PassService;
|
|
private DataMonthlyPass CurrentPass = null;
|
|
|
|
public void Init()
|
|
{
|
|
var time = CommonUtils.GetCurTime(E_TimeType.Server);
|
|
var year = time.Year;
|
|
var month = time.Month;
|
|
string date = year + "-" + month;
|
|
Debug.Log("MonthlyPass init, Today: " + date);
|
|
|
|
PassService = new MonthlyPassService();
|
|
DebugUtil.Log("MonthlyPass status: " + PassService.RemainingDays + " days left, today has claimed: " + PassService.TodayHasClaimed);
|
|
}
|
|
|
|
public void UpdatePassService(int PassID)
|
|
{
|
|
var table = TableManager.Instance.Tables.MonthlyPass;
|
|
if (table.DataMap.TryGetValue(PassID, out DataMonthlyPass data))
|
|
{
|
|
CurrentPass = data;
|
|
}
|
|
else
|
|
{
|
|
CurrentPass = null;
|
|
DebugUtil.LogError("MonthlyPassManager UpdatePassService Error: {0} not found", PassID);
|
|
}
|
|
}
|
|
public void Release()
|
|
{
|
|
//throw new System.NotImplementedException();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 可领取状态
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public bool TodayCanClaim()
|
|
{
|
|
return !PassService.TodayHasClaimed && PassService.IsPassUnlock && PassService.RemainingDays > 0;
|
|
}
|
|
|
|
#region 交互
|
|
/// <summary>
|
|
/// 购买月卡请求
|
|
/// </summary>
|
|
public void Purchase()
|
|
{
|
|
var currencyData = TableManager.Instance.Tables.CurrencyShopCfg.DataMap;
|
|
|
|
var currencyID = 0;//TODO: 月卡商品ID
|
|
|
|
if (!currencyData.TryGetValue(currencyID, out var dataCurrencyShopCfg))
|
|
{
|
|
DebugUtil.LogError("CurrencyShopCfg 没有 {0} 配置的内购商品", currencyID);
|
|
return;
|
|
}
|
|
|
|
OnPurchase(dataCurrencyShopCfg);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 支付成功回调
|
|
/// </summary>
|
|
public void UnlockPass()
|
|
{
|
|
PassService.Refresh();
|
|
|
|
Claim();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 领取月卡奖励服务器请求
|
|
/// </summary>
|
|
public void Claim()
|
|
{
|
|
if (TodayCanClaim())
|
|
{
|
|
DebugUtil.Log("Claimed");
|
|
//send message to server
|
|
//NetHelper.
|
|
}
|
|
else
|
|
{
|
|
DebugUtil.Log("Cannot claim today");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 每日奖励领取弹窗
|
|
/// </summary>
|
|
public void GetPassReward()
|
|
{
|
|
//TODO: Add rewards, show rewards popup
|
|
|
|
//UI_GetItemWindowController.Open()
|
|
//PassService.TodayHasClaimed = true;
|
|
}
|
|
#endregion
|
|
|
|
#region 界面
|
|
/// <summary>
|
|
/// 获取当前月卡图片路径
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public string GetPassPicPath()
|
|
{
|
|
var defaultPath = "";
|
|
if (CurrentPass != null)
|
|
{
|
|
return CurrentPass.ProductPath;
|
|
}
|
|
else
|
|
{
|
|
DebugUtil.LogError("MonthlyPassManager GetPassPicPath Error: CurrentPass is null");
|
|
}
|
|
return defaultPath;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取月卡描述
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public string GetPassDesc()
|
|
{
|
|
var defaultDesc = "";
|
|
if (CurrentPass != null)
|
|
{
|
|
var key = CurrentPass.ProductDescription;
|
|
return CommonUtils.GetLocalizeText(key);
|
|
}
|
|
else
|
|
{
|
|
DebugUtil.LogError("MonthlyPassManager GetPassDesc Error: CurrentPass is null");
|
|
}
|
|
return GetLocalizeText(defaultDesc);
|
|
}
|
|
#endregion
|
|
|
|
|
|
private async void OnPurchase(DataCurrencyShopCfg cfg)
|
|
{
|
|
try
|
|
{
|
|
#if UNITY_IOS
|
|
// ios 只走苹果内购
|
|
IAPManager.Instance.SetCurrentPayChannel(IAPManager.PayChannel.Apple);
|
|
IAPManager.Instance.CheckAndBuyGoods(cfg.Id);
|
|
#elif SDK_BILIBILI
|
|
IAPManager.Instance.SetCurrentPayChannel(IAPManager.PayChannel.Bilibili);
|
|
IAPManager.Instance.IAPBuyGoods(cfg.Id);
|
|
#else
|
|
await UI_PayWindowController.Open(cfg);
|
|
#endif
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
DebugUtil.LogError("MonthlyPass OnPurchase Error: {0}", e);
|
|
}
|
|
}
|
|
}
|