564 lines
18 KiB
C#
564 lines
18 KiB
C#
![]() |
// ***********************************************************************
|
|||
|
// Assembly : Game
|
|||
|
// Author : Kimch
|
|||
|
// Created : 2021-04-24
|
|||
|
// Description :
|
|||
|
// Last Modified By :
|
|||
|
// Last Modified On :
|
|||
|
// ***********************************************************************
|
|||
|
// <copyright file= "VipProxy" company="Kunpo"></copyright>
|
|||
|
// <summary></summary>
|
|||
|
// ***********************************************************************
|
|||
|
|
|||
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using CodeStage.AntiCheat.ObscuredTypes;
|
|||
|
using UnityEngine;
|
|||
|
|
|||
|
namespace G
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// Vip
|
|||
|
/// </summary>
|
|||
|
public class VipProxy : F.GameProxy
|
|||
|
{
|
|||
|
public const int 变更次数 = 300;
|
|||
|
public const int 增加次数 = 301;
|
|||
|
|
|||
|
public const int 角色体力上限 = 303;
|
|||
|
public const int 角色体力上限增加 = 304;
|
|||
|
|
|||
|
public const int 局内战斗加速 = 307;
|
|||
|
public const int 穴位升级爆率提升 = 308;
|
|||
|
public const int 局内道具属性增加 = 309;
|
|||
|
public const int 道具出售增加 = 310;
|
|||
|
public const int 自动战斗 = 311;
|
|||
|
public const int 扫荡次数 = 312;
|
|||
|
public const int 角色活力上限 = 313;
|
|||
|
public const int 角色活力上限增加 = 314;
|
|||
|
public const int 免费复活 = 317;
|
|||
|
public const int 免广告 = 318;
|
|||
|
|
|||
|
public class VipInfo
|
|||
|
{
|
|||
|
public readonly ItemVip item;
|
|||
|
public int id => item.id;
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 两种用途
|
|||
|
/// </summary>
|
|||
|
private ObscuredInt _status;
|
|||
|
|
|||
|
public int remainDay
|
|||
|
{
|
|||
|
get { return _status > 0 ? (_status - Launch.Timestamp) / 86400 : 0; }
|
|||
|
set
|
|||
|
{
|
|||
|
_status = Launch.Timestamp + value * 86400;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public bool isValid => _status >= Launch.Timestamp;
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public int adGiftBoxId
|
|||
|
{
|
|||
|
get { return item.adGiftBox; }
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public int freeGiftBoxId
|
|||
|
{
|
|||
|
get { return item.freeGiftBox; }
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 免费永久一次
|
|||
|
/// </summary>
|
|||
|
public bool canBuyFreeGiftBox
|
|||
|
{
|
|||
|
get { return _status == 0; }
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 内部
|
|||
|
/// </summary>
|
|||
|
internal int status
|
|||
|
{
|
|||
|
get { return _status; }
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
/// <param name="value"></param>
|
|||
|
public void SetValidTimestamp(int value)
|
|||
|
{
|
|||
|
_status = value;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 内部调用
|
|||
|
/// </summary>
|
|||
|
public void SetBuyStateInternal(int value)
|
|||
|
{
|
|||
|
_status = value;
|
|||
|
}
|
|||
|
|
|||
|
public VipInfo(ItemVip vipItem)
|
|||
|
{
|
|||
|
this.item = vipItem;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
#region Field
|
|||
|
|
|||
|
private readonly List<VipInfo> _vipList = new List<VipInfo>(12);
|
|||
|
private readonly List<VipInfo> _extraVipList = new List<VipInfo>();
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Property
|
|||
|
|
|||
|
private int _curVip
|
|||
|
{
|
|||
|
get => ArchiveProxy.Instance.GetInt(GlobalDefine.KEY_VIP, minVip);
|
|||
|
set => ArchiveProxy.Instance.SetInt(GlobalDefine.KEY_VIP, value);
|
|||
|
}
|
|||
|
|
|||
|
public int curVip
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
var result = _curVip;
|
|||
|
if (CheckVip(result))
|
|||
|
return result + 1;
|
|||
|
return result;
|
|||
|
}
|
|||
|
set
|
|||
|
{
|
|||
|
_curVip = Mathf.Clamp(value, minVip, maxVip);
|
|||
|
ApplyAllVip(true);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public VipInfo curVipInfo
|
|||
|
{
|
|||
|
get { return _vipList[curVip - 1]; }
|
|||
|
}
|
|||
|
|
|||
|
public int maxVip
|
|||
|
{
|
|||
|
get;
|
|||
|
private set;
|
|||
|
}
|
|||
|
|
|||
|
public int minVip
|
|||
|
{
|
|||
|
get { return 1; }
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Method
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
/// <param name="id"></param>
|
|||
|
/// <returns></returns>
|
|||
|
public VipInfo GetVipInfo(int id)
|
|||
|
{
|
|||
|
if (id > 0 && id <= _vipList.Count)
|
|||
|
return _vipList[id - 1];
|
|||
|
return null;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 获取权益信息
|
|||
|
/// </summary>
|
|||
|
/// <param name="rights"></param>
|
|||
|
/// <param name="rightName"></param>
|
|||
|
/// <param name="rightValue"></param>
|
|||
|
public void GetRightsInfo(int[] rights, out string rightName, out string rightValue)
|
|||
|
{
|
|||
|
rightName = null;
|
|||
|
rightValue = null;
|
|||
|
if (rights == null || rights.Length < 2)
|
|||
|
return;
|
|||
|
|
|||
|
int id = rights[0];
|
|||
|
if (id == VipProxy.变更次数 || id == 增加次数)
|
|||
|
{
|
|||
|
var timeItem = ItemProxy.Instance.GetStaticItem<ItemTime>(rights[1]);
|
|||
|
if (timeItem != null)
|
|||
|
rightName = timeItem.description;
|
|||
|
if (rights.Length >= 3)
|
|||
|
rightValue = id == 变更次数 ? rights[2].ToString() : "+" + rights[2].ToString();
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
rightName = KLocalization.GetLocalString(id);
|
|||
|
switch (id)
|
|||
|
{
|
|||
|
case VipProxy.局内战斗加速:
|
|||
|
var battleSpeed = rights[1];
|
|||
|
if (battleSpeed >= 175f)
|
|||
|
rightValue = "x3倍";
|
|||
|
else if (battleSpeed >= 150f)
|
|||
|
rightValue = "x2倍";
|
|||
|
else if (battleSpeed >= 120f)
|
|||
|
rightValue = "x1倍";
|
|||
|
else
|
|||
|
rightValue = "";
|
|||
|
break;
|
|||
|
case VipProxy.穴位升级爆率提升:
|
|||
|
case VipProxy.局内道具属性增加:
|
|||
|
case VipProxy.道具出售增加:
|
|||
|
rightValue = $"{rights[1]}%";
|
|||
|
break;
|
|||
|
case VipProxy.自动战斗:
|
|||
|
rightValue = "开启";
|
|||
|
break;
|
|||
|
case VipProxy.免费复活:
|
|||
|
rightValue = "免费";
|
|||
|
break;
|
|||
|
case 免广告:
|
|||
|
break;
|
|||
|
default:
|
|||
|
rightValue = rights[1].ToString();
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
/// <returns></returns>
|
|||
|
public bool CheckDailyAdRewards()
|
|||
|
{
|
|||
|
return TimeProxy.Instance.CheckTimes(506);
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 检查贵族界面今日点击次数
|
|||
|
/// </summary>
|
|||
|
/// <returns></returns>
|
|||
|
public bool CheckDailyClickTime()
|
|||
|
{
|
|||
|
return TimeProxy.Instance.CheckTimes(507);
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
/// <param name="callback"></param>
|
|||
|
public void GetDailyAdRewards(Callback2 callback)
|
|||
|
{
|
|||
|
if (TimeProxy.Instance.CheckTimes(506))
|
|||
|
AdProxy.Instance.PlayAdChange("vip", "vip_ad_daily", (error, message) =>
|
|||
|
{
|
|||
|
if (error == 0)
|
|||
|
{
|
|||
|
TimeProxy.Instance.CostTimes(506);
|
|||
|
var vipInfo = GetVipInfo(curVip);
|
|||
|
var giftBoxInfo = RmbShopProxy.Instance.GetGiftBoxInfo(vipInfo.adGiftBoxId);
|
|||
|
RewardProxy.Instance.GetRewardsWithUI(giftBoxInfo.exchanges, callback);
|
|||
|
}
|
|||
|
});
|
|||
|
else
|
|||
|
callback?.Invoke(ErrorCode.AD_TIMES_NOT_ENOUGH, ErrorMessage.AD_TIMES_NOT_ENOUGH);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
/// <param name="vipId"></param>
|
|||
|
/// <param name="callback"></param>
|
|||
|
public void GetFreeRewards(int vipId, Callback2 callback)
|
|||
|
{
|
|||
|
if (vipId <= curVip)
|
|||
|
{
|
|||
|
var vipInfo = GetVipInfo(vipId);
|
|||
|
if (vipInfo.canBuyFreeGiftBox)
|
|||
|
{
|
|||
|
var giftBoxInfo = RmbShopProxy.Instance.GetGiftBoxInfo(vipInfo.freeGiftBoxId);
|
|||
|
vipInfo.SetBuyStateInternal(1);
|
|||
|
SaveVip();
|
|||
|
RewardProxy.Instance.GetRewardsWithUI(giftBoxInfo.exchanges, callback);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
callback?.Invoke(1, "");
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
callback?.Invoke(1, "");
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public static int[] GetUnlockMissions(ItemVip vipItem)
|
|||
|
{
|
|||
|
if (KPlatform.Instance.QueryPay())
|
|||
|
{
|
|||
|
return vipItem.unlockB;
|
|||
|
}
|
|||
|
return vipItem.unlockA;
|
|||
|
}
|
|||
|
|
|||
|
public int GetRedPoint()
|
|||
|
{
|
|||
|
if (CheckDailyClickTime())
|
|||
|
return 1;
|
|||
|
int curVipId = this.curVip;
|
|||
|
for (int i = 0; i < curVipId; i++)
|
|||
|
{
|
|||
|
if (_vipList[i].canBuyFreeGiftBox)
|
|||
|
return 1;
|
|||
|
}
|
|||
|
return 0;
|
|||
|
}
|
|||
|
|
|||
|
public bool isFreeGift()
|
|||
|
{
|
|||
|
int curVipId = this.curVip;
|
|||
|
for (int i = 0; i < curVipId; i++)
|
|||
|
{
|
|||
|
if (_vipList[i].canBuyFreeGiftBox)
|
|||
|
return true;
|
|||
|
}
|
|||
|
return false;
|
|||
|
}
|
|||
|
public bool CheckVip(int vip)
|
|||
|
{
|
|||
|
if (vip < maxVip)
|
|||
|
{
|
|||
|
var vipItem = ItemProxy.Instance.GetStaticItem<ItemVip>(vip);
|
|||
|
if (vipItem != null)
|
|||
|
{
|
|||
|
var unlockMissions = GetUnlockMissions(vipItem);
|
|||
|
if (unlockMissions != null)
|
|||
|
for (int i = 0; i < unlockMissions.Length; i++)
|
|||
|
{
|
|||
|
var mission = MissionProxy.Instance.GetMission(unlockMissions[i]);
|
|||
|
if (mission == null || !mission.isCompleted)
|
|||
|
{
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
_curVip = vip + 1;
|
|||
|
ApplyAllVip(true);
|
|||
|
SaveVip();
|
|||
|
PostNotification(GlobalDefine.EVENT_VIP_CHANGED);
|
|||
|
KStatistics.Instance.ReportEventLevelUp(2, vip, vip + 1, "mission", 0);
|
|||
|
return true;
|
|||
|
}
|
|||
|
}
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
/// <param name="id"></param>
|
|||
|
/// <param name="validityDay"></param>
|
|||
|
public void AddExtraVip(int id, int validityDay)
|
|||
|
{
|
|||
|
var vipItem = ItemProxy.Instance.GetStaticItem<ItemVip>(id);
|
|||
|
var vipInfo = new VipInfo(vipItem)
|
|||
|
{
|
|||
|
remainDay = validityDay
|
|||
|
};
|
|||
|
_extraVipList.Add(vipInfo);
|
|||
|
SaveVip();
|
|||
|
ApplyVip(vipItem);
|
|||
|
}
|
|||
|
|
|||
|
private void ApplyAllVip(bool applyChange = false)
|
|||
|
{
|
|||
|
if (applyChange)
|
|||
|
{
|
|||
|
ResetRights();
|
|||
|
}
|
|||
|
|
|||
|
ApplyVip(ItemProxy.Instance.GetStaticItem<ItemVip>(_curVip));
|
|||
|
foreach (var vipInfo in _extraVipList)
|
|||
|
{
|
|||
|
if (vipInfo.isValid)
|
|||
|
ApplyVip(vipInfo.item);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void ApplyVip(ItemVip vipItem)
|
|||
|
{
|
|||
|
if (vipItem != null)
|
|||
|
{
|
|||
|
var rights = vipItem.rights;
|
|||
|
if (rights != null)
|
|||
|
{
|
|||
|
for (int i = 0; i < rights.Length; i++)
|
|||
|
{
|
|||
|
var right = rights[i];
|
|||
|
if (right != null && right.Length > 0)
|
|||
|
{
|
|||
|
int rId = right[0];
|
|||
|
int rArg1 = right[1];
|
|||
|
switch (rId)
|
|||
|
{
|
|||
|
case 变更次数:
|
|||
|
{
|
|||
|
int rArg2 = right[2];
|
|||
|
TimeProxy.Instance.SetMaxTimes(rArg1, rArg2, false);
|
|||
|
break;
|
|||
|
}
|
|||
|
case 增加次数:
|
|||
|
{
|
|||
|
int rArg2 = right[2];
|
|||
|
TimeProxy.Instance.AddMaxTimes(rArg1, rArg2, false);
|
|||
|
break;
|
|||
|
}
|
|||
|
case 角色体力上限:
|
|||
|
PlayerProxy.Instance.energyMax = rArg1;
|
|||
|
break;
|
|||
|
case 角色体力上限增加:
|
|||
|
PlayerProxy.Instance.energyMax += rArg1;
|
|||
|
break;
|
|||
|
case 角色活力上限:
|
|||
|
PlayerProxy.Instance.motilityMax = rArg1;
|
|||
|
break;
|
|||
|
case 角色活力上限增加:
|
|||
|
PlayerProxy.Instance.motilityMax += rArg1;
|
|||
|
break;
|
|||
|
case 局内战斗加速:
|
|||
|
GlobalVar.BattleSpeed = Mathf.Max(1f, rArg1 * 0.01f);
|
|||
|
break;
|
|||
|
case 穴位升级爆率提升:
|
|||
|
GlobalVar.TitleStudyDouble = 1f - rArg1 * 0.01f;
|
|||
|
break;
|
|||
|
case 局内道具属性增加:
|
|||
|
GlobalVar.BuffAddition = rArg1;
|
|||
|
break;
|
|||
|
case 道具出售增加:
|
|||
|
GlobalVar.PropSellAddition = rArg1 * 0.01f;
|
|||
|
break;
|
|||
|
case 免广告:
|
|||
|
//GlobalVar.RemoveAd = true;
|
|||
|
break;
|
|||
|
default:
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
const string ARCHIVE_KEY_V1 = "vip_v1";
|
|||
|
private void LoadVip()
|
|||
|
{
|
|||
|
_extraVipList.Clear();
|
|||
|
|
|||
|
var dataList = ArchiveProxy.Instance.GetIntList(ARCHIVE_KEY_V1);
|
|||
|
if (dataList != null && dataList.Count > 0)
|
|||
|
{
|
|||
|
int maxIndex = dataList.Count - 1;
|
|||
|
for (int i = 0; i < maxIndex; i += 2)
|
|||
|
{
|
|||
|
int id = dataList[i];
|
|||
|
int status = dataList[i + 1];
|
|||
|
|
|||
|
var vipItem = ItemProxy.Instance.GetStaticItem<ItemVip>(id);
|
|||
|
if (vipItem != null)
|
|||
|
{
|
|||
|
if (vipItem.type == 1)
|
|||
|
{
|
|||
|
_vipList[id - 1].SetBuyStateInternal(status);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
var vipInfo = new VipInfo(vipItem);
|
|||
|
vipInfo.SetValidTimestamp(status);
|
|||
|
_extraVipList.Add(vipInfo);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
ApplyAllVip(true);
|
|||
|
}
|
|||
|
|
|||
|
public void SaveVip()
|
|||
|
{
|
|||
|
var dataList = ArchiveProxy.Instance.GetIntList(ARCHIVE_KEY_V1);
|
|||
|
if (dataList != null)
|
|||
|
{
|
|||
|
dataList.Clear();
|
|||
|
|
|||
|
foreach (var item in _vipList)
|
|||
|
{
|
|||
|
dataList.Add(item.id);
|
|||
|
dataList.Add(item.status);
|
|||
|
}
|
|||
|
|
|||
|
foreach (var item in _extraVipList)
|
|||
|
{
|
|||
|
if (item.isValid)
|
|||
|
{
|
|||
|
dataList.Add(item.id);
|
|||
|
dataList.Add(item.status);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
ArchiveProxy.Instance.SetIntList(ARCHIVE_KEY_V1, dataList);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public void ResetRights()
|
|||
|
{
|
|||
|
PlayerProxy.Instance.energyMax = 0;
|
|||
|
PlayerProxy.Instance.motilityMax = 0;
|
|||
|
GlobalVar.Reset();
|
|||
|
TimeProxy.Instance.ResetAllMaxTimes();
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Proxy
|
|||
|
|
|||
|
//public override int priority => 996;
|
|||
|
|
|||
|
public static VipProxy Instance => GetInstance<VipProxy>();
|
|||
|
|
|||
|
public override void LoadCompleted()
|
|||
|
{
|
|||
|
var vipItems = ItemProxy.Instance.GetStaticItems<ItemVip>();
|
|||
|
int max = 0;
|
|||
|
foreach (var item in vipItems)
|
|||
|
{
|
|||
|
if (item.type == 1)
|
|||
|
{
|
|||
|
_vipList.Add(new VipInfo(item));
|
|||
|
max++;
|
|||
|
}
|
|||
|
}
|
|||
|
this.maxVip = max;
|
|||
|
Debug.Log(_vipList.Count);
|
|||
|
}
|
|||
|
|
|||
|
public override void ReadArchive()
|
|||
|
{
|
|||
|
LoadVip();
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|