926 lines
29 KiB
C#
926 lines
29 KiB
C#
![]() |
// ***********************************************************************
|
|||
|
// Assembly : Game
|
|||
|
// Author : Kimch
|
|||
|
// Created : 2020-12-08
|
|||
|
// Description :
|
|||
|
// Last Modified By :
|
|||
|
// Last Modified On :
|
|||
|
// ***********************************************************************
|
|||
|
// <copyright file= "RmbShopProxy" company="Kunpo"></copyright>
|
|||
|
// <summary></summary>
|
|||
|
// ***********************************************************************
|
|||
|
|
|||
|
using CodeStage.AntiCheat.ObscuredTypes;
|
|||
|
using F;
|
|||
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using UnityEngine;
|
|||
|
|
|||
|
namespace G
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// 商城
|
|||
|
/// </summary>
|
|||
|
public class RmbShopProxy : F.GameProxy
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// 充值
|
|||
|
/// </summary>
|
|||
|
public class ChargeInfo
|
|||
|
{
|
|||
|
public readonly ItemShopCharge item;
|
|||
|
public int id => item.id;
|
|||
|
|
|||
|
private readonly ObscuredInt _rmbPrice;
|
|||
|
/// <summary>
|
|||
|
/// 加密过的
|
|||
|
/// </summary>
|
|||
|
public int rmbPrice => _rmbPrice;
|
|||
|
|
|||
|
private ObscuredInt _chargeCount;
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public int chargeCount => _chargeCount;
|
|||
|
|
|||
|
public readonly Item.ItemInfo _exchange;
|
|||
|
/// <summary>
|
|||
|
/// 兑换元宝
|
|||
|
/// </summary>
|
|||
|
public Item.ItemInfo exchange
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
var result = _exchange;
|
|||
|
//if (_chargeCount == 0)
|
|||
|
// _exchange.Apply(2);
|
|||
|
return result;
|
|||
|
}
|
|||
|
}
|
|||
|
public Item.ItemInfo exchange2
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
var result = _exchange;
|
|||
|
//if (_chargeCount == 0)
|
|||
|
result.Apply(2);
|
|||
|
return result;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 保存数据
|
|||
|
/// </summary>
|
|||
|
public int status
|
|||
|
{
|
|||
|
get => _chargeCount;
|
|||
|
set => _chargeCount = value;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public int remainTimes
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
if (item.timeId > 0)
|
|||
|
return TimeProxy.Instance.GetTimes(item.timeId);
|
|||
|
return int.MaxValue;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public ChargeInfo(ItemShopCharge chargeItem)
|
|||
|
{
|
|||
|
this.item = chargeItem;
|
|||
|
|
|||
|
_rmbPrice = item.price;
|
|||
|
_exchange = Item.ItemInfo.Convert(item.exchange);
|
|||
|
}
|
|||
|
|
|||
|
public void Charge()
|
|||
|
{
|
|||
|
_chargeCount++;
|
|||
|
if (item.timeId > 0)
|
|||
|
{
|
|||
|
TimeProxy.Instance.CostTimes(item.timeId);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 特权
|
|||
|
/// </summary>
|
|||
|
public class SpecialInfo
|
|||
|
{
|
|||
|
public readonly ItemShopSpecial item;
|
|||
|
public int id => item.id;
|
|||
|
|
|||
|
private readonly ObscuredInt _obPrice;
|
|||
|
/// <summary>
|
|||
|
/// 加密过的
|
|||
|
/// </summary>
|
|||
|
public int rmbPrice => _obPrice;
|
|||
|
|
|||
|
public int validityDay => item.validity;
|
|||
|
|
|||
|
private ObscuredInt _remainRewardDay;
|
|||
|
/// <summary>
|
|||
|
/// 剩余天数
|
|||
|
/// </summary>
|
|||
|
public int remainRewardDay
|
|||
|
{
|
|||
|
get { return _remainRewardDay; }
|
|||
|
set
|
|||
|
{
|
|||
|
_remainRewardDay = Mathf.Max(0, value);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private ObscuredInt _activeTimestamp;
|
|||
|
public int activeTimestamp
|
|||
|
{
|
|||
|
get => _activeTimestamp;
|
|||
|
set
|
|||
|
{
|
|||
|
if (value >= 0)
|
|||
|
{
|
|||
|
_activeTimestamp = value;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public int remainDay
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
if (_activeTimestamp > 0)
|
|||
|
{
|
|||
|
if (item.validity > 0)
|
|||
|
{
|
|||
|
return item.validity - ((Launch.Timestamp - _activeTimestamp) / 86400);
|
|||
|
}
|
|||
|
return int.MaxValue;
|
|||
|
}
|
|||
|
return 0;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public string remainDayText
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
if (item.validity > 0)
|
|||
|
{
|
|||
|
int remainSeconds = item.validity * 86400 + _activeTimestamp - Launch.Timestamp - 1;
|
|||
|
if (remainSeconds > 86400)
|
|||
|
return $"有效时间:{remainSeconds / 86400}天";
|
|||
|
else if (remainSeconds > 0)
|
|||
|
return $"有效时间:{F.Utils.Time.ToTimeString(remainSeconds)}";
|
|||
|
else
|
|||
|
return "";
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
return "永久激活";
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 领取次数
|
|||
|
/// </summary>
|
|||
|
public int rewardTimes
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
if (item.timeId > 0)
|
|||
|
return TimeProxy.Instance.GetTimes(item.timeId);
|
|||
|
return 0;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 每次
|
|||
|
/// </summary>
|
|||
|
public readonly Item.ItemInfo exchange;
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public readonly Item.ItemInfo[] dailyExchange;
|
|||
|
public int status
|
|||
|
{
|
|||
|
get => _remainRewardDay;
|
|||
|
set
|
|||
|
{
|
|||
|
_remainRewardDay = value;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public SpecialInfo(ItemShopSpecial specialItem)
|
|||
|
{
|
|||
|
this.item = specialItem;
|
|||
|
|
|||
|
_obPrice = item.price;
|
|||
|
exchange = Item.ItemInfo.Convert(item.exchange);
|
|||
|
dailyExchange = Item.ItemInfo.FromArray(item.dailyExchange);
|
|||
|
}
|
|||
|
|
|||
|
public void Buy()
|
|||
|
{
|
|||
|
if (item.validity > 0)
|
|||
|
{
|
|||
|
_remainRewardDay = item.validity;
|
|||
|
_activeTimestamp = Launch.Timestamp;
|
|||
|
|
|||
|
CheckValidity();
|
|||
|
|
|||
|
if (item.vip > 0)
|
|||
|
{
|
|||
|
VipProxy.Instance.AddExtraVip(item.vip, item.validity);
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
_remainRewardDay = int.MaxValue;
|
|||
|
_activeTimestamp = Launch.Timestamp;
|
|||
|
|
|||
|
if (item.vip > 0)
|
|||
|
{
|
|||
|
VipProxy.Instance.AddExtraVip(item.vip, int.MaxValue);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public bool CheckValidity()
|
|||
|
{
|
|||
|
if (_activeTimestamp > 0)
|
|||
|
{
|
|||
|
int passDay = (Launch.Timestamp - _activeTimestamp) / 86400;
|
|||
|
if (item.validity > 0 && passDay >= 0)
|
|||
|
{
|
|||
|
_remainRewardDay = Mathf.Min(_remainRewardDay, item.validity);
|
|||
|
|
|||
|
int remainDay = Mathf.Max(0, item.validity - passDay);
|
|||
|
if (remainDay == 0)
|
|||
|
{
|
|||
|
_activeTimestamp = 0;
|
|||
|
}
|
|||
|
|
|||
|
passDay = (Launch.Timestamp - _activeTimestamp + Launch.TodayRemainSeconds) / 86400;
|
|||
|
int remainRewadDay = Mathf.Max(0, item.validity - passDay);
|
|||
|
while (_remainRewardDay > 0 && _remainRewardDay >= remainRewadDay)
|
|||
|
{
|
|||
|
if (item.rewardMailId > 0 && _remainRewardDay > 0)
|
|||
|
MailProxy.Instance.PostLocalMail(0, item.rewardMailId, 1);
|
|||
|
_remainRewardDay -= 1;
|
|||
|
}
|
|||
|
return true;
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
//兼容老版本
|
|||
|
if (_remainRewardDay > 9999)
|
|||
|
{
|
|||
|
_remainRewardDay = int.MaxValue;
|
|||
|
_activeTimestamp = Launch.Timestamp;
|
|||
|
return true;
|
|||
|
}
|
|||
|
}
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
public bool GetDaily()
|
|||
|
{
|
|||
|
if (item.timeId > 0 && _remainRewardDay > 0)
|
|||
|
{
|
|||
|
_remainRewardDay -= 1;
|
|||
|
return TimeProxy.Instance.CostTimes(item.timeId);
|
|||
|
}
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 礼包
|
|||
|
/// </summary>
|
|||
|
public class GiftBoxInfo
|
|||
|
{
|
|||
|
public readonly ItemShopGift item;
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public int id => item.id;
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public int type => item.type;
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public string name => item.name;
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public string description => item.name;
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public int remainTimes
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
if (item.timeId > 0)
|
|||
|
return TimeProxy.Instance.GetTimes(item.timeId);
|
|||
|
return int.MaxValue;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 可以购买
|
|||
|
/// </summary>
|
|||
|
public bool isValid
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
bool parentValid = false;
|
|||
|
if (item.prev > 0)
|
|||
|
{
|
|||
|
var prevGB = RmbShopProxy.Instance.GetGiftBoxInfo(item.prev);
|
|||
|
parentValid = prevGB.isValid;
|
|||
|
int loopCount = 0;
|
|||
|
while (!parentValid && prevGB.item.prev > 0 && loopCount++ < 10)
|
|||
|
{
|
|||
|
prevGB = RmbShopProxy.Instance.GetGiftBoxInfo(prevGB.item.prev);
|
|||
|
parentValid = prevGB.isValid;
|
|||
|
}
|
|||
|
#if UNITY_EDITOR
|
|||
|
if (loopCount >= 10)
|
|||
|
Debug.Log("礼包配置表错误");
|
|||
|
#endif
|
|||
|
}
|
|||
|
return !parentValid && remainTimes > 0;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public Item.ItemInfo price;
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public readonly Item.ItemInfo[] exchanges;
|
|||
|
|
|||
|
public int rmbPrice
|
|||
|
{
|
|||
|
get => price.count;
|
|||
|
}
|
|||
|
|
|||
|
public GiftBoxInfo(ItemShopGift giftItem)
|
|||
|
{
|
|||
|
this.item = giftItem;
|
|||
|
|
|||
|
price = Item.ItemInfo.Convert(item.price);
|
|||
|
exchanges = Item.ItemInfo.FromArray(item.exchange);
|
|||
|
}
|
|||
|
|
|||
|
public void Buy()
|
|||
|
{
|
|||
|
if (item.timeId > 0)
|
|||
|
{
|
|||
|
TimeProxy.Instance.CostTimes(item.timeId);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
#region Field
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
Dictionary<int, ChargeInfo> _chargeInfos;
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
Dictionary<int, SpecialInfo> _specialInfos;
|
|||
|
/// <summary>
|
|||
|
/// 礼包
|
|||
|
/// </summary>
|
|||
|
Dictionary<int, GiftBoxInfo> _giftBoxInfos;
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Method
|
|||
|
|
|||
|
public bool IsRemoveAd()
|
|||
|
{
|
|||
|
if (_specialInfos.TryGetValue(3, out var specialInfo))
|
|||
|
{
|
|||
|
if (specialInfo.remainDay > 0)
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
if (_specialInfos.TryGetValue(4, out var specialInfo2))
|
|||
|
{
|
|||
|
if (specialInfo2.remainDay > 0)
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
public int IsActivitionCard()
|
|||
|
{
|
|||
|
if (_specialInfos.TryGetValue(3, out var specialInfo))
|
|||
|
{
|
|||
|
if (specialInfo.remainDay > 0)
|
|||
|
return 3;
|
|||
|
}
|
|||
|
if (_specialInfos.TryGetValue(4, out var specialInfo2))
|
|||
|
{
|
|||
|
if (specialInfo2.remainDay > 0)
|
|||
|
return 4;
|
|||
|
}
|
|||
|
return 0;
|
|||
|
}
|
|||
|
public void CheckSpecialReward()
|
|||
|
{
|
|||
|
bool save = false;
|
|||
|
foreach (var specialInfo in _specialInfos.Values)
|
|||
|
{
|
|||
|
if (specialInfo.CheckValidity())
|
|||
|
{
|
|||
|
save = true;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if (save)
|
|||
|
{
|
|||
|
SaveShop();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 获取充值信息
|
|||
|
/// </summary>
|
|||
|
/// <returns></returns>
|
|||
|
public IReadOnlyCollection<ChargeInfo> GetChargeInfos()
|
|||
|
{
|
|||
|
return _chargeInfos.Values;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 特权信息
|
|||
|
/// </summary>
|
|||
|
/// <returns></returns>
|
|||
|
public IReadOnlyCollection<SpecialInfo> GetSpecialInfos()
|
|||
|
{
|
|||
|
return _specialInfos.Values;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 获取礼包信息
|
|||
|
/// </summary>
|
|||
|
/// <returns></returns>
|
|||
|
public IReadOnlyCollection<GiftBoxInfo> GetGiftBoxInfos()
|
|||
|
{
|
|||
|
return _giftBoxInfos.Values;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
/// <param name="id"></param>
|
|||
|
/// <returns></returns>
|
|||
|
public GiftBoxInfo GetGiftBoxInfo(int id)
|
|||
|
{
|
|||
|
_giftBoxInfos.TryGetValue(id, out var result);
|
|||
|
return result;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
/// <param name="chargeInfo"></param>
|
|||
|
/// <param name="callback"></param>
|
|||
|
/// <returns></returns>
|
|||
|
public void Recharge(int id, Callback2 callback)
|
|||
|
{
|
|||
|
_payCallback = callback;
|
|||
|
|
|||
|
if (_chargeInfos.TryGetValue(id, out var chargeInfo))
|
|||
|
{
|
|||
|
if (chargeInfo.remainTimes <= 0)
|
|||
|
{
|
|||
|
callback?.Invoke(1, "不能重复购买");
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
var payInfo = new PayProxy.PayInfo
|
|||
|
{
|
|||
|
payId = chargeInfo.id,
|
|||
|
rmbPrice = chargeInfo.rmbPrice,
|
|||
|
buyAmount = chargeInfo.rmbPrice * 10,
|
|||
|
payName = chargeInfo.item.name,
|
|||
|
payType = "ShopCharge"
|
|||
|
};
|
|||
|
|
|||
|
if (chargeInfo.rmbPrice <= 0)
|
|||
|
{
|
|||
|
chargeInfo.Charge();
|
|||
|
SaveShop();
|
|||
|
RewardProxy.Instance.GetRewardWithUI(chargeInfo.exchange, callback);
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
PayProxy.Instance.Pay(payInfo, (error, message) =>
|
|||
|
{
|
|||
|
if (error == ErrorCode.SUCCESS)
|
|||
|
{
|
|||
|
chargeInfo.Charge();
|
|||
|
SaveShop();
|
|||
|
|
|||
|
MissionProxy.Instance.OnEvent(MissionProxy.累计充值, payInfo.rmbPrice);
|
|||
|
MissionProxy.Instance.OnClampEvent2(MissionProxy.单笔充值, payInfo.rmbPrice);
|
|||
|
|
|||
|
RewardProxy.Instance.GetRewardWithUI(chargeInfo.exchange2, callback);
|
|||
|
PostNotification(GlobalDefine.EVENT_MONEY_CHANGED);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
callback?.Invoke(error, message);
|
|||
|
}
|
|||
|
});
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
void RechargeIndirect(int id, int amount, Callback2 callback)
|
|||
|
{
|
|||
|
if (amount > 0 && _chargeInfos.TryGetValue(id, out var chargeInfo))
|
|||
|
{
|
|||
|
for (int i = 0; i < amount; i++)
|
|||
|
{
|
|||
|
chargeInfo.Charge();
|
|||
|
}
|
|||
|
SaveShop();
|
|||
|
|
|||
|
RewardProxy.Instance.GetRewardWithUI(chargeInfo.exchange2, _payCallback);
|
|||
|
|
|||
|
MissionProxy.Instance.OnEvent(MissionProxy.累计充值, chargeInfo.rmbPrice * amount);
|
|||
|
MissionProxy.Instance.OnClampEvent2(MissionProxy.单笔充值, chargeInfo.rmbPrice);
|
|||
|
PostNotification(GlobalDefine.EVENT_MONEY_CHANGED);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
/// <param name="special"></param>
|
|||
|
/// <param name="callback"></param>
|
|||
|
/// <returns></returns>
|
|||
|
public void BuySpecial(int id, Callback2 callback)
|
|||
|
{
|
|||
|
_payCallback = callback;
|
|||
|
|
|||
|
if (_specialInfos.TryGetValue(id, out var specialInfo))
|
|||
|
{
|
|||
|
if (specialInfo.remainDay > 0)
|
|||
|
{
|
|||
|
callback?.Invoke(1, "不能重复购买");
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
var payInfo = new PayProxy.PayInfo
|
|||
|
{
|
|||
|
payId = specialInfo.id,
|
|||
|
rmbPrice = specialInfo.rmbPrice,
|
|||
|
buyAmount = specialInfo.rmbPrice * 10,
|
|||
|
payName = specialInfo.item.name,
|
|||
|
payType = "ShopSpecial"
|
|||
|
};
|
|||
|
|
|||
|
PayProxy.Instance.Pay(payInfo, (error, message) =>
|
|||
|
{
|
|||
|
if (error == ErrorCode.SUCCESS)
|
|||
|
{
|
|||
|
specialInfo.Buy();
|
|||
|
SaveShop();
|
|||
|
MissionProxy.Instance.OnEvent(MissionProxy.累计充值, payInfo.rmbPrice);
|
|||
|
MissionProxy.Instance.OnClampEvent2(MissionProxy.单笔充值, payInfo.rmbPrice);
|
|||
|
|
|||
|
RewardProxy.Instance.GetRewardWithUI(specialInfo.exchange, callback);
|
|||
|
|
|||
|
PostNotification(GlobalDefine.EVENT_MONEY_CHANGED);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
callback?.Invoke(error, message);
|
|||
|
}
|
|||
|
});
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
void BuySpecialIndirect(int id, int amount, Callback2 callback)
|
|||
|
{
|
|||
|
if (amount > 0 && _specialInfos.TryGetValue(id, out var specialInfo))
|
|||
|
{
|
|||
|
if (specialInfo.remainDay > 0)
|
|||
|
{
|
|||
|
_payCallback?.Invoke(1, "不能重复购买");
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
specialInfo.Buy();
|
|||
|
SaveShop();
|
|||
|
|
|||
|
RewardProxy.Instance.GetRewardWithUI(specialInfo.exchange, _payCallback);
|
|||
|
|
|||
|
MissionProxy.Instance.OnEvent(MissionProxy.累计充值, specialInfo.rmbPrice);
|
|||
|
MissionProxy.Instance.OnClampEvent2(MissionProxy.单笔充值, specialInfo.rmbPrice);
|
|||
|
|
|||
|
PostNotification(GlobalDefine.EVENT_MONEY_CHANGED);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
/// <param name="id"></param>
|
|||
|
/// <param name="callback"></param>
|
|||
|
/// <returns></returns>
|
|||
|
public void DailyGetSpecial(int id, Callback2 callback)
|
|||
|
{
|
|||
|
if (_specialInfos.TryGetValue(id, out var specialInfo))
|
|||
|
{
|
|||
|
if (specialInfo.GetDaily())
|
|||
|
{
|
|||
|
SaveShop();
|
|||
|
RewardProxy.Instance.GetRewardsWithUI(specialInfo.dailyExchange, callback);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
callback?.Invoke(1, "不能重复领取");
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private Callback2 _payCallback;
|
|||
|
/// <summary>
|
|||
|
/// 购买礼包
|
|||
|
/// </summary>
|
|||
|
/// <param name="id"></param>
|
|||
|
/// <param name="callback"></param>
|
|||
|
public void BuyGiftBox(int id, Callback2 callback)
|
|||
|
{
|
|||
|
_payCallback = callback;
|
|||
|
|
|||
|
if (_giftBoxInfos.TryGetValue(id, out var giftBoxInfo))
|
|||
|
{
|
|||
|
if (giftBoxInfo.remainTimes <= 0)
|
|||
|
{
|
|||
|
callback?.Invoke(1, "不能重复购买");
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
if (giftBoxInfo.rmbPrice <= 0)
|
|||
|
{
|
|||
|
giftBoxInfo.Buy();
|
|||
|
SaveShop();
|
|||
|
RewardProxy.Instance.GetRewardsWithUI(giftBoxInfo.exchanges, callback);
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
var payInfo = new PayProxy.PayInfo
|
|||
|
{
|
|||
|
payId = giftBoxInfo.id,
|
|||
|
rmbPrice = giftBoxInfo.rmbPrice,
|
|||
|
buyAmount = giftBoxInfo.rmbPrice * 10,
|
|||
|
payName = giftBoxInfo.item.name,
|
|||
|
payType = "ShopGift"
|
|||
|
};
|
|||
|
|
|||
|
PayProxy.Instance.Pay(payInfo, (error, message) =>
|
|||
|
{
|
|||
|
if (error == ErrorCode.SUCCESS)
|
|||
|
{
|
|||
|
giftBoxInfo.Buy();
|
|||
|
SaveShop();
|
|||
|
|
|||
|
MissionProxy.Instance.OnEvent(MissionProxy.累计充值, payInfo.rmbPrice);
|
|||
|
MissionProxy.Instance.OnClampEvent2(MissionProxy.单笔充值, payInfo.rmbPrice);
|
|||
|
RewardProxy.Instance.GetRewardsWithUI(giftBoxInfo.exchanges, callback);
|
|||
|
|
|||
|
PostNotification(GlobalDefine.EVENT_MONEY_CHANGED);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
callback?.Invoke(error, message);
|
|||
|
}
|
|||
|
});
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
void BuyGiftBoxIndirect(int id, int amount, Callback2 callback)
|
|||
|
{
|
|||
|
if (amount > 0 && _giftBoxInfos.TryGetValue(id, out var giftBoxInfo))
|
|||
|
{
|
|||
|
if (giftBoxInfo.remainTimes <= 0)
|
|||
|
{
|
|||
|
_payCallback?.Invoke(1, "不能重复购买");
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
if (giftBoxInfo.rmbPrice <= 0)
|
|||
|
{
|
|||
|
giftBoxInfo.Buy();
|
|||
|
SaveShop();
|
|||
|
RewardProxy.Instance.GetRewardsWithUI(giftBoxInfo.exchanges, callback);
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
giftBoxInfo.Buy();
|
|||
|
SaveShop();
|
|||
|
|
|||
|
MissionProxy.Instance.OnEvent(MissionProxy.累计充值, giftBoxInfo.rmbPrice);
|
|||
|
MissionProxy.Instance.OnClampEvent2(MissionProxy.单笔充值, giftBoxInfo.rmbPrice);
|
|||
|
|
|||
|
RewardProxy.Instance.GetRewardsWithUI(giftBoxInfo.exchanges, _payCallback);
|
|||
|
|
|||
|
PostNotification(GlobalDefine.EVENT_MONEY_CHANGED);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 重新购买
|
|||
|
/// </summary>
|
|||
|
/// <param name="callback"></param>
|
|||
|
public void IndirectBuy(Dictionary<string, int> result, Callback2 callback)
|
|||
|
{
|
|||
|
foreach (var item in result)
|
|||
|
{
|
|||
|
var payKey = item.Key;
|
|||
|
var payCount = item.Value;
|
|||
|
|
|||
|
if (payKey.StartsWith("ShopCharge"))
|
|||
|
{
|
|||
|
if (int.TryParse(payKey.Substring(10), out var payId))
|
|||
|
{
|
|||
|
RechargeIndirect(payId, payCount, callback);
|
|||
|
}
|
|||
|
}
|
|||
|
else if (payKey.StartsWith("ShopSpecial"))
|
|||
|
{
|
|||
|
if (int.TryParse(payKey.Substring(11), out var payId))
|
|||
|
{
|
|||
|
BuySpecialIndirect(payId, payCount, callback);
|
|||
|
}
|
|||
|
}
|
|||
|
else if (payKey.StartsWith("ShopGift"))
|
|||
|
{
|
|||
|
if (int.TryParse(payKey.Substring(8), out var payId))
|
|||
|
{
|
|||
|
BuyGiftBoxIndirect(payId, payCount, callback);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void InitShop()
|
|||
|
{
|
|||
|
var chargeItems = ItemProxy.Instance.GetStaticItems<ItemShopCharge>();
|
|||
|
_chargeInfos = new Dictionary<int, ChargeInfo>(chargeItems.Count);
|
|||
|
foreach (var item in chargeItems)
|
|||
|
{
|
|||
|
_chargeInfos.Add(item.id, new ChargeInfo(item));
|
|||
|
}
|
|||
|
|
|||
|
var specialItems = ItemProxy.Instance.GetStaticItems<ItemShopSpecial>();
|
|||
|
_specialInfos = new Dictionary<int, SpecialInfo>(specialItems.Count);
|
|||
|
foreach (var item in specialItems)
|
|||
|
{
|
|||
|
_specialInfos.Add(item.id, new SpecialInfo(item));
|
|||
|
}
|
|||
|
|
|||
|
var giftItems = ItemProxy.Instance.GetStaticItems<ItemShopGift>();
|
|||
|
_giftBoxInfos = new Dictionary<int, GiftBoxInfo>(giftItems.Count);
|
|||
|
foreach (var item in giftItems)
|
|||
|
{
|
|||
|
_giftBoxInfos.Add(item.id, new GiftBoxInfo(item));
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
const string ARCHIVE_KEY_V1 = "rmb_shop_v1";
|
|||
|
const string ARCHIVE_KEY_V2 = "rmb_shop_v2";
|
|||
|
|
|||
|
private void LoadShop()
|
|||
|
{
|
|||
|
var dataList = ArchiveProxy.Instance.GetIntList(ARCHIVE_KEY_V2);
|
|||
|
if (dataList != null && dataList.Count > 0)
|
|||
|
{
|
|||
|
int index = 0;
|
|||
|
int chargeCount = dataList.SafeGet(index++);
|
|||
|
for (int i = 0; i < chargeCount && index < dataList.Count; i++)
|
|||
|
{
|
|||
|
int id = dataList.SafeGet(index++);
|
|||
|
int status = dataList.SafeGet(index++);
|
|||
|
if (_chargeInfos.TryGetValue(id, out var chargeInfo))
|
|||
|
chargeInfo.status = status;
|
|||
|
}
|
|||
|
|
|||
|
int specialCount = dataList.SafeGet(index++);
|
|||
|
for (int i = 0; i < specialCount && index < dataList.Count; i++)
|
|||
|
{
|
|||
|
int id = dataList.SafeGet(index++);
|
|||
|
int remainDay = dataList.SafeGet(index++);
|
|||
|
int activeTimestamp = dataList.SafeGet(index++);
|
|||
|
if (_specialInfos.TryGetValue(id, out var specialInfo))
|
|||
|
{
|
|||
|
specialInfo.remainRewardDay = remainDay;
|
|||
|
specialInfo.activeTimestamp = activeTimestamp;
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
dataList = ArchiveProxy.Instance.GetIntList(ARCHIVE_KEY_V1);
|
|||
|
if (dataList != null && dataList.Count > 0)
|
|||
|
{
|
|||
|
int index = 0;
|
|||
|
int chargeCount = dataList.SafeGet(index++);
|
|||
|
for (int i = 0; i < chargeCount && index < dataList.Count; i++)
|
|||
|
{
|
|||
|
int id = dataList.SafeGet(index++);
|
|||
|
int status = dataList.SafeGet(index++);
|
|||
|
if (_chargeInfos.TryGetValue(id, out var chargeInfo))
|
|||
|
chargeInfo.status = status;
|
|||
|
}
|
|||
|
|
|||
|
int specialCount = dataList.SafeGet(index++);
|
|||
|
for (int i = 0; i < specialCount && index < dataList.Count; i++)
|
|||
|
{
|
|||
|
int id = dataList.SafeGet(index++);
|
|||
|
int status = dataList.SafeGet(index++);
|
|||
|
if (_specialInfos.TryGetValue(id, out var specialInfo))
|
|||
|
specialInfo.status = status;
|
|||
|
}
|
|||
|
}
|
|||
|
ArchiveProxy.Instance.RemoveIntList(ARCHIVE_KEY_V1);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void SaveShop()
|
|||
|
{
|
|||
|
var dataList = ArchiveProxy.Instance.GetIntList(ARCHIVE_KEY_V2);
|
|||
|
if (dataList != null)
|
|||
|
{
|
|||
|
dataList.Clear();
|
|||
|
dataList.Add(_chargeInfos.Count);
|
|||
|
foreach (var kv in _chargeInfos)
|
|||
|
{
|
|||
|
dataList.Add(kv.Key);
|
|||
|
dataList.Add(kv.Value.status);
|
|||
|
}
|
|||
|
|
|||
|
dataList.Add(_specialInfos.Count);
|
|||
|
foreach (var kv in _specialInfos)
|
|||
|
{
|
|||
|
dataList.Add(kv.Key);
|
|||
|
dataList.Add(kv.Value.remainRewardDay);
|
|||
|
dataList.Add(kv.Value.activeTimestamp);
|
|||
|
}
|
|||
|
|
|||
|
ArchiveProxy.Instance.SetIntList(ARCHIVE_KEY_V2, dataList);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Unity & PROXY
|
|||
|
|
|||
|
public override int priority => 19;
|
|||
|
|
|||
|
public static RmbShopProxy Instance;
|
|||
|
// Use this for initialization
|
|||
|
private void Awake()
|
|||
|
{
|
|||
|
Instance = this;
|
|||
|
}
|
|||
|
|
|||
|
public override void ReadArchive()
|
|||
|
{
|
|||
|
InitShop();
|
|||
|
LoadShop();
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|