235 lines
6.8 KiB
C#
235 lines
6.8 KiB
C#
// ***********************************************************************
|
|
// Assembly : Unity
|
|
// Author : Kimch
|
|
// Created : 2017-11-14
|
|
//
|
|
// Last Modified By : Kimch
|
|
// Last Modified On :
|
|
// ***********************************************************************
|
|
// <copyright file= "ActivityProxy" company=""></copyright>
|
|
// <summary></summary>
|
|
// ***********************************************************************
|
|
namespace G
|
|
{
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public class ActivityProxy : F.GameProxy
|
|
{
|
|
#region FIELD
|
|
|
|
private readonly Dictionary<int, ActivityInfo> _activities = new Dictionary<int, ActivityInfo>();
|
|
|
|
#endregion
|
|
|
|
#region PROPERTY
|
|
|
|
/// <summary>
|
|
/// 七日签到活动
|
|
/// </summary>
|
|
public readonly SevenSignActivity sevenSignActivity = new SevenSignActivity();
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public readonly FreeEnergyActivity freeEnergyActivity = new FreeEnergyActivity();
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public readonly WomenActivity womenActivity = new WomenActivity();
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public readonly QingMingActivity qingMingActivity = new QingMingActivity();
|
|
|
|
#endregion
|
|
|
|
#region METHOD
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public IReadOnlyCollection<ActivityInfo> GetActivities()
|
|
{
|
|
return _activities.Values;
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
public ActivityInfo GetActivity(int id)
|
|
{
|
|
if (TimeProxy.Instance.TryTimeKey(TimeProxy.每日活动))
|
|
{
|
|
foreach (var item in _activities.Values)
|
|
{
|
|
if (item.type == 4)
|
|
{
|
|
item.Reset();
|
|
}
|
|
}
|
|
SaveLocal();
|
|
}
|
|
|
|
if (!_activities.TryGetValue(id, out var activity))
|
|
{
|
|
UnityEngine.Debug.Log($"活动Id{id}错误");
|
|
}
|
|
return activity;
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="activityInfo"></param>
|
|
public void SaveActivity(ActivityInfo activityInfo)
|
|
{
|
|
SaveLocal();
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
public void ResetActivity(int id)
|
|
{
|
|
if (_activities.TryGetValue(id, out var activity))
|
|
{
|
|
activity.Reset();
|
|
SaveLocal();
|
|
}
|
|
}
|
|
|
|
public void GetRewards(int id, int subIndex, Callback2 callback)
|
|
{
|
|
var activity = GetActivity(id);
|
|
if (activity != null)
|
|
{
|
|
if (subIndex > 0 && activity.subInfos != null && subIndex <= activity.subInfos.Length)
|
|
{
|
|
activity.subInfos[subIndex - 1].status = 2;
|
|
callback?.Invoke(0, "");
|
|
}
|
|
else
|
|
{
|
|
activity.status = 2;
|
|
callback?.Invoke(0, "");
|
|
}
|
|
SaveLocal();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// FreeEnergy
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public int GetRedPoint1()
|
|
{
|
|
return freeEnergyActivity.GetRedPoint();
|
|
}
|
|
|
|
/// <summary>
|
|
/// SevenSign
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public int GetRedPoint2()
|
|
{
|
|
return sevenSignActivity.GetRedPoint();
|
|
}
|
|
|
|
public const string ARCHIVE_KEY_V1 = "activities";
|
|
private void LoadActivity()
|
|
{
|
|
var dataList = ArchiveProxy.Instance.GetIntList(ARCHIVE_KEY_V1);
|
|
if (dataList != null && dataList.Count > 0)
|
|
{
|
|
int index = 0;
|
|
Label:
|
|
var id = dataList.SafeGet(index++);
|
|
int save = dataList.SafeGet(index++);
|
|
|
|
if (_activities.TryGetValue(id, out var activity))
|
|
{
|
|
GlobalUtils.SplitNumber824(save, out int status, out int value);
|
|
activity.status = status;
|
|
activity.curValue = value;
|
|
|
|
if (activity.subInfos != null)
|
|
for (int i = 0; i < activity.subInfos.Length; i++)
|
|
{
|
|
var subInfo = activity.subInfos[i];
|
|
GlobalUtils.SplitNumber824(dataList.SafeGet(index++), out int subStatus, out int subValue);
|
|
subInfo.status = subStatus;
|
|
subInfo.curValue = subValue;
|
|
}
|
|
}
|
|
if (index < dataList.Count)
|
|
goto Label;
|
|
}
|
|
|
|
//
|
|
sevenSignActivity.Load();
|
|
womenActivity.Load();
|
|
qingMingActivity.Load();
|
|
}
|
|
|
|
private void SaveLocal()
|
|
{
|
|
var dataList = ArchiveProxy.Instance.GetIntList(ARCHIVE_KEY_V1);
|
|
if (dataList != null)
|
|
{
|
|
dataList.Clear();
|
|
|
|
foreach (var activity in _activities.Values)
|
|
{
|
|
dataList.Add(activity.id);
|
|
dataList.Add(GlobalUtils.CombineNumber824(activity.status, activity.curValue));
|
|
if (activity.subInfos != null)
|
|
for (int i = 0; i < activity.subInfos.Length; i++)
|
|
{
|
|
var subInfo = activity.subInfos[i];
|
|
dataList.Add(GlobalUtils.CombineNumber824(subInfo.status, subInfo.curValue));
|
|
}
|
|
}
|
|
|
|
ArchiveProxy.Instance.SetIntList(ARCHIVE_KEY_V1, dataList);
|
|
}
|
|
}
|
|
|
|
private void InitActivity()
|
|
{
|
|
_activities.Clear();
|
|
var activityItems = ItemProxy.Instance.GetStaticItems<ItemActivity>();
|
|
foreach (var item in activityItems)
|
|
{
|
|
var activity = new ActivityInfo(item);
|
|
_activities.Add(activity.id, activity);
|
|
}
|
|
|
|
//
|
|
sevenSignActivity.Init();
|
|
//womenActivity.Init();
|
|
qingMingActivity.Init();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Proxy
|
|
|
|
public static ActivityProxy Instance => GetInstance<ActivityProxy>();
|
|
|
|
public override void ReadArchive()
|
|
{
|
|
InitActivity();
|
|
LoadActivity();
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|