备份CatanBuilding瘦身独立工程
This commit is contained in:
116
Assets/Scripts/DataCenter/AchievementDataManager.cs
Normal file
116
Assets/Scripts/DataCenter/AchievementDataManager.cs
Normal file
@@ -0,0 +1,116 @@
|
||||
using asap.core;
|
||||
using cfg;
|
||||
using GameCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UniRx;
|
||||
public class AchievementData
|
||||
{
|
||||
public int Id;
|
||||
public ulong Target;
|
||||
public int day;
|
||||
}
|
||||
public class AchievementDataManager : IDisposable
|
||||
{
|
||||
Tables _tables;
|
||||
//待释放
|
||||
IDisposable disposable;
|
||||
public bool IsOpen;
|
||||
Dictionary<ConditionType, AchievementData> _achievementDatas = new Dictionary<ConditionType, AchievementData>();
|
||||
public AchievementDataManager(Tables tables)
|
||||
{
|
||||
_tables = tables;
|
||||
}
|
||||
public void LoadAchievementData(string value)
|
||||
{
|
||||
_achievementDatas = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<ConditionType, AchievementData>>(value);
|
||||
}
|
||||
public void Init()
|
||||
{
|
||||
if (disposable == null)
|
||||
{
|
||||
disposable = GContext.OnEvent<ConditionTypeEvent>().Subscribe(UpdateData);
|
||||
}
|
||||
}
|
||||
public ulong GetAchievementDatas(ConditionType type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case ConditionType.AllRodLevel:
|
||||
return (ulong)(GContext.container.Resolve<PlayerFishData>().GetRoodAllLevel() + GContext.container.Resolve<PlayerFishData>().GetRodAllCount());
|
||||
case ConditionType.AllFishCardLevel:
|
||||
return (ulong)GContext.container.Resolve<PlayerFishData>().GetAllLevel();
|
||||
default:
|
||||
if (_achievementDatas.ContainsKey(type))
|
||||
{
|
||||
return _achievementDatas[type].Target;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateData(ConditionTypeEvent condition)
|
||||
{
|
||||
//GetFishWeight
|
||||
ConditionType type = condition.type;
|
||||
List<Statistics> stats = _tables.TbStatistics.DataList;
|
||||
foreach (var item in stats)
|
||||
{
|
||||
if (type == item.ConditionType)
|
||||
{
|
||||
int day = ZZTimeHelper.UtcNow().UtcNowOffset().DayOfYear;
|
||||
|
||||
ulong count = (ulong)condition.count;
|
||||
if (_achievementDatas.ContainsKey(type))
|
||||
{
|
||||
if (type == ConditionType.LoginDays && _achievementDatas[type].day == day)
|
||||
{
|
||||
return;
|
||||
}
|
||||
switch (type)
|
||||
{
|
||||
case ConditionType.LoginDays:
|
||||
if (_achievementDatas[type].day == day)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
_achievementDatas[type].Target++;
|
||||
}
|
||||
break;
|
||||
case ConditionType.MaxCashFromFishing:
|
||||
case ConditionType.MaxCashFromBomb:
|
||||
case ConditionType.MaxCashFromHeist:
|
||||
case ConditionType.AllRodLevel:
|
||||
case ConditionType.AllFishCardLevel:
|
||||
if (count > _achievementDatas[type].Target)
|
||||
{
|
||||
_achievementDatas[type].Target = count;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
_achievementDatas[type].Target += count;
|
||||
break;
|
||||
}
|
||||
_achievementDatas[type].day = day;
|
||||
}
|
||||
else
|
||||
{
|
||||
_achievementDatas[type] = new AchievementData() { day = day, Id = item.Id, Target = count };
|
||||
}
|
||||
PlayFabMgr.Instance.UpdateUserDataValue("AchievementData", Newtonsoft.Json.JsonConvert.SerializeObject(_achievementDatas));
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
public void Dispose()
|
||||
{
|
||||
disposable?.Dispose();
|
||||
disposable = null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user