// ***********************************************************************
// Assembly : Game
// Author : Kimch
// Created : 2021-01-08
// Description :
// Last Modified By :
// Last Modified On :
// ***********************************************************************
//
//
// ***********************************************************************
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace G
{
using CodeStage.AntiCheat.ObscuredTypes;
///
/// 功能
///
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;
///
///
///
public bool showUnlockTips => item.tips == 1;
///
/// 排序
///
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;
}
///
/// 是新解锁的
///
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();
}
}
}
///
/// 奖励
///
public readonly Item.ItemInfo[] rewardInfos;
ObscuredInt _curStatus = 0;
///
/// 奖励状态:0.未完成;1.已完成;2.已领取
///
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];
}
}
}
///
///
///
private static Function[] _Functions = new Function[(int)FunctionId.kMax];
List _SortFunction = new List();
///
/// 解锁状态(true 解锁)
///
///
///
public bool GetFunctionUnlock(FunctionId id)
{
return GetFunction(id).IsUnlock();
}
///
///
///
///
///
public Function GetFunction(FunctionId id)
{
int index = (int)id;
if (index > 0 && index < _Functions.Length)
return _Functions[index];
return null;
}
///
/// 一下个解锁功能
///
///
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;
}
///
/// 领取任务奖励
///
///
public void GetRewards(Function function)
{
if (function.status <2)
{
RewardProxy.Instance.GetRewardsWithUI(function.rewardInfos, (error, message) =>
{
PostNotification(GlobalDefine.EVENT_MONEY_CHANGED);
});
function.status = 2;
}
}
///
/// 需排序的解锁功能
///
///
public IList Functions
{
get { return _SortFunction; }
}
private int FunctionSort(Function x,Function y)//排序
{
return x.condition();
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
}
}