442 lines
12 KiB
C#
442 lines
12 KiB
C#
![]() |
// ***********************************************************************
|
|||
|
// Assembly : Game
|
|||
|
// Author : Kimch
|
|||
|
// Created : 2021-01-08
|
|||
|
// Description :
|
|||
|
// Last Modified By :
|
|||
|
// Last Modified On :
|
|||
|
// ***********************************************************************
|
|||
|
// <copyright file= "FunctionProxy" company="Kunpo"></copyright>
|
|||
|
// <summary></summary>
|
|||
|
// ***********************************************************************
|
|||
|
|
|||
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using UnityEngine;
|
|||
|
|
|||
|
namespace G
|
|||
|
{
|
|||
|
using CodeStage.AntiCheat.ObscuredTypes;
|
|||
|
/// <summary>
|
|||
|
/// 功能
|
|||
|
/// </summary>
|
|||
|
public class FunctionProxy : F.GameProxy
|
|||
|
{
|
|||
|
#region 解锁系统
|
|||
|
|
|||
|
public enum FunctionId : byte
|
|||
|
{
|
|||
|
kNone = 0,
|
|||
|
Cha,
|
|||
|
Shop,
|
|||
|
Kungfu,
|
|||
|
Jianghu,
|
|||
|
Jingjie = 5,
|
|||
|
Pet = 6,
|
|||
|
Beauty = 7,
|
|||
|
解锁客栈功能 = 8,
|
|||
|
解锁侠客令功能 = 9,
|
|||
|
解锁武林大会功能 = 10,
|
|||
|
Vip = 11,
|
|||
|
产业 = 12,
|
|||
|
强化 = 13,
|
|||
|
重铸 = 14,
|
|||
|
Pet_Rank = 15,
|
|||
|
Battle_Rank = 16,
|
|||
|
文学 = 17,
|
|||
|
红颜养成系统 = 18,
|
|||
|
宠物洗练 = 19,
|
|||
|
穴位养成 = 20,
|
|||
|
好友 = 21,
|
|||
|
任务 = 22,
|
|||
|
召集令 = 23,
|
|||
|
福袋 = 24,
|
|||
|
礼包入口 =25,
|
|||
|
特权入口 =26,
|
|||
|
活动入口 =27,
|
|||
|
七日签到 =28,
|
|||
|
kMax,
|
|||
|
}
|
|||
|
|
|||
|
public enum FunctionState : byte
|
|||
|
{
|
|||
|
fNone = 0,
|
|||
|
fLock = 1,
|
|||
|
fUnlock = 2,
|
|||
|
}
|
|||
|
|
|||
|
public enum FunctionCondition
|
|||
|
{
|
|||
|
kNone = 0,
|
|||
|
kGrade = 1,
|
|||
|
kLevel = 2,
|
|||
|
kMission = 3,
|
|||
|
}
|
|||
|
|
|||
|
public class Function
|
|||
|
{
|
|||
|
public readonly ItemFunction item;
|
|||
|
public FunctionState state;
|
|||
|
|
|||
|
public FunctionId id => (FunctionId)item.id;
|
|||
|
public int condition => item.condition;
|
|||
|
public string name => item.name;
|
|||
|
public string[] icon => item.icon;
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public bool showUnlockTips => item.tips == 1;
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 排序
|
|||
|
/// </summary>
|
|||
|
public int sort => item.sort;
|
|||
|
|
|||
|
public string lockText
|
|||
|
{
|
|||
|
get => item.lockText;
|
|||
|
}
|
|||
|
|
|||
|
public string lockTips
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
var mission = MissionProxy.Instance.GetMission(condition);
|
|||
|
if (mission != null)
|
|||
|
return mission.description + item.lockText;
|
|||
|
return item.lockText;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public bool showPreview
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
var mission = MissionProxy.Instance.GetMission(item.preview);
|
|||
|
return mission == null || mission.isCompleted;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public Function(ItemFunction functionItem)
|
|||
|
{
|
|||
|
this.item = functionItem;
|
|||
|
rewardInfos = Item.ItemInfo.FromArray(functionItem.rewards);
|
|||
|
LoadActivity();
|
|||
|
}
|
|||
|
|
|||
|
public void Lock(bool force = false)
|
|||
|
{
|
|||
|
state = FunctionState.fUnlock;
|
|||
|
}
|
|||
|
|
|||
|
public void Unlock(bool force = false)
|
|||
|
{
|
|||
|
state = FunctionState.fUnlock;
|
|||
|
}
|
|||
|
|
|||
|
public bool IsUnlock()
|
|||
|
{
|
|||
|
if (state == FunctionState.fUnlock)
|
|||
|
{
|
|||
|
return true;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
var mission = MissionProxy.Instance.GetMission(condition);
|
|||
|
var result = mission == null || mission.isCompleted;
|
|||
|
//if (result)
|
|||
|
// state = FunctionState.fUnlock;
|
|||
|
return result;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public bool CheckNew()
|
|||
|
{
|
|||
|
if (state != FunctionState.fUnlock)
|
|||
|
{
|
|||
|
var mission = MissionProxy.Instance.GetMission(condition);
|
|||
|
var result = mission == null || mission.isCompleted;
|
|||
|
if (result)
|
|||
|
{
|
|||
|
state = FunctionState.fUnlock;
|
|||
|
return true;
|
|||
|
}
|
|||
|
}
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 是新解锁的
|
|||
|
/// </summary>
|
|||
|
public bool isNew
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
return !PlayerPrefs.HasKey(id.ToString());
|
|||
|
}
|
|||
|
set
|
|||
|
{
|
|||
|
if (!value)
|
|||
|
{
|
|||
|
PlayerPrefs.SetInt(id.ToString(), 1);
|
|||
|
PlayerPrefs.Save();
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
PlayerPrefs.DeleteKey(id.ToString());
|
|||
|
PlayerPrefs.Save();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 奖励
|
|||
|
/// </summary>
|
|||
|
public readonly Item.ItemInfo[] rewardInfos;
|
|||
|
ObscuredInt _curStatus = 0;
|
|||
|
/// <summary>
|
|||
|
/// 奖励状态:0.未完成;1.已完成;2.已领取
|
|||
|
/// </summary>
|
|||
|
public int status
|
|||
|
{
|
|||
|
get { return _curStatus; }
|
|||
|
set
|
|||
|
{
|
|||
|
_curStatus = value;
|
|||
|
SaveLocal();
|
|||
|
}
|
|||
|
}
|
|||
|
public bool isStatus
|
|||
|
{
|
|||
|
get { return _curStatus == 1; }
|
|||
|
}
|
|||
|
|
|||
|
public const string FUNCYION_KEY_V = "function_";
|
|||
|
private void SaveLocal()
|
|||
|
{
|
|||
|
var dataList = ArchiveProxy.Instance.GetIntList(FUNCYION_KEY_V + item.id);
|
|||
|
if (dataList != null)
|
|||
|
{
|
|||
|
dataList.Clear();
|
|||
|
dataList.Add(status);
|
|||
|
ArchiveProxy.Instance.SetIntList(FUNCYION_KEY_V + item.id, dataList);
|
|||
|
}
|
|||
|
}
|
|||
|
private void LoadActivity()
|
|||
|
{
|
|||
|
var dataList = ArchiveProxy.Instance.GetIntList(FUNCYION_KEY_V + item.id);
|
|||
|
if (dataList != null && dataList.Count>0)
|
|||
|
{
|
|||
|
status = dataList[0];
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
private static Function[] _Functions = new Function[(int)FunctionId.kMax];
|
|||
|
List<Function> _SortFunction = new List<Function>();
|
|||
|
/// <summary>
|
|||
|
/// 解锁状态(true 解锁)
|
|||
|
/// </summary>
|
|||
|
/// <param name="system"></param>
|
|||
|
/// <returns></returns>
|
|||
|
public bool GetFunctionUnlock(FunctionId id)
|
|||
|
{
|
|||
|
return GetFunction(id).IsUnlock();
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
/// <param name="id"></param>
|
|||
|
/// <returns></returns>
|
|||
|
public Function GetFunction(FunctionId id)
|
|||
|
{
|
|||
|
int index = (int)id;
|
|||
|
if (index > 0 && index < _Functions.Length)
|
|||
|
return _Functions[index];
|
|||
|
return null;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 一下个解锁功能
|
|||
|
/// </summary>
|
|||
|
/// <returns></returns>
|
|||
|
public Function GetNextFunction()
|
|||
|
{
|
|||
|
for (int i = 1; i < _Functions.Length; i++)
|
|||
|
{
|
|||
|
if (_Functions[i] != null)
|
|||
|
{
|
|||
|
var sortFunc = GetFunction((FunctionId)_Functions[i].sort);
|
|||
|
if (sortFunc != null && !sortFunc.IsUnlock())
|
|||
|
return sortFunc;
|
|||
|
}
|
|||
|
}
|
|||
|
return null;
|
|||
|
}
|
|||
|
|
|||
|
public void RecoverFunction()
|
|||
|
{
|
|||
|
for (int i = _Functions.Length - 1; i >= 0; i--)
|
|||
|
{
|
|||
|
var func = _Functions[i];
|
|||
|
if (func != null)
|
|||
|
{
|
|||
|
func.state = FunctionState.fNone;
|
|||
|
}
|
|||
|
}
|
|||
|
this.UpdateFunction();
|
|||
|
}
|
|||
|
|
|||
|
public void UnlockFunction(FunctionId type, bool force)
|
|||
|
{
|
|||
|
var func = _Functions[(int)type];
|
|||
|
if (func != null)
|
|||
|
{
|
|||
|
func.Unlock(force);
|
|||
|
}
|
|||
|
this.UpdateFunction();
|
|||
|
}
|
|||
|
|
|||
|
public void LockFunction(FunctionId type, bool force)
|
|||
|
{
|
|||
|
var func = _Functions[(int)type];
|
|||
|
if (func != null)
|
|||
|
{
|
|||
|
func.Lock(force);
|
|||
|
}
|
|||
|
this.UpdateFunction();
|
|||
|
}
|
|||
|
|
|||
|
public void UpdateFunction()
|
|||
|
{
|
|||
|
for (int i = _Functions.Length - 1; i >= 0; i--)
|
|||
|
{
|
|||
|
var function = _Functions[i];
|
|||
|
if (function != null && !function.IsUnlock())
|
|||
|
{
|
|||
|
var mission = MissionProxy.Instance.GetMission(function.condition);
|
|||
|
if (mission.isCompleted)
|
|||
|
{
|
|||
|
function.Unlock();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public Function CheckNew()
|
|||
|
{
|
|||
|
foreach (var function in _Functions)
|
|||
|
{
|
|||
|
if (function != null && function.showUnlockTips && function.CheckNew())
|
|||
|
{
|
|||
|
KStatistics.Instance.ReportEvent_UnlockSystem("mission", 0, function.name);
|
|||
|
return function;
|
|||
|
}
|
|||
|
}
|
|||
|
return default;
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 领取任务奖励
|
|||
|
/// </summary>
|
|||
|
/// <param name="function"></param>
|
|||
|
public void GetRewards(Function function)
|
|||
|
{
|
|||
|
if (function.status <2)
|
|||
|
{
|
|||
|
RewardProxy.Instance.GetRewardsWithUI(function.rewardInfos, (error, message) =>
|
|||
|
{
|
|||
|
PostNotification(GlobalDefine.EVENT_MONEY_CHANGED);
|
|||
|
});
|
|||
|
function.status = 2;
|
|||
|
}
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 需排序的解锁功能
|
|||
|
/// </summary>
|
|||
|
/// <returns></returns>
|
|||
|
public IList<Function> Functions
|
|||
|
{
|
|||
|
get { return _SortFunction; }
|
|||
|
}
|
|||
|
private int FunctionSort(Function x,Function y)//排序
|
|||
|
{
|
|||
|
return x.condition<y.condition?-1:1;
|
|||
|
}
|
|||
|
|
|||
|
public int GetRedPoint()
|
|||
|
{
|
|||
|
if (_SortFunction != null)
|
|||
|
{
|
|||
|
foreach (var item in _SortFunction)
|
|||
|
{
|
|||
|
if (item.IsUnlock() && item.status < 2)
|
|||
|
{
|
|||
|
return 1;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
return 0;
|
|||
|
}
|
|||
|
|
|||
|
public Function GetRewarfdFunction() //检查是否有待领取奖励的功能
|
|||
|
{
|
|||
|
if (_SortFunction != null)
|
|||
|
{
|
|||
|
foreach (var item in _SortFunction)
|
|||
|
{
|
|||
|
if (item.IsUnlock() && item.status <2)
|
|||
|
{
|
|||
|
return item;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
return null;
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Field
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Method
|
|||
|
|
|||
|
public override void ReadArchive()
|
|||
|
{
|
|||
|
var functions = ItemProxy.Instance.GetStaticItems<ItemFunction>();
|
|||
|
foreach (var function in functions)
|
|||
|
{
|
|||
|
if (function != null)
|
|||
|
{
|
|||
|
_Functions[function.id] = new Function(function);
|
|||
|
_Functions[function.id].CheckNew();
|
|||
|
}
|
|||
|
}
|
|||
|
_SortFunction.Clear();
|
|||
|
foreach (var function in _Functions)
|
|||
|
{
|
|||
|
if (function != null && function.item.read == 1)
|
|||
|
{
|
|||
|
_SortFunction.Add(function);
|
|||
|
}
|
|||
|
}
|
|||
|
_SortFunction.Sort(FunctionSort);
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Unity
|
|||
|
|
|||
|
public static FunctionProxy Instance;
|
|||
|
// Use this for initialization
|
|||
|
private void Awake()
|
|||
|
{
|
|||
|
Instance = this;
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|