先修复一下,错误的场景 删除不必要的钓场资产 修复into场景 update:更新meta文件,修复报错 update:修复资源 修复第一章节建造 修复建造第三章 update:删除多余内容 update:更新README.md update:还原图标 update:更新README update:更新配置
187 lines
6.2 KiB
C#
187 lines
6.2 KiB
C#
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 override string ToString()
|
|
{
|
|
return $"{Id}|{Target}|{day}";
|
|
}
|
|
public void ToObject(string[] arr)
|
|
{
|
|
Id = int.Parse(arr[0]);
|
|
Target = ulong.Parse(arr[1]);
|
|
day = int.Parse(arr[2]);
|
|
}
|
|
}
|
|
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 LoadAchievementDataToObject(string value)
|
|
{
|
|
var dic = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<ConditionType, string>>(value);
|
|
foreach (var item in dic)
|
|
{
|
|
string[] Value = item.Value.Split('|');
|
|
if (Value.Length == 3)
|
|
{
|
|
AchievementData achievementData = new AchievementData();
|
|
achievementData.ToObject(Value);
|
|
_achievementDatas[item.Key] = achievementData;
|
|
}
|
|
}
|
|
}
|
|
public void LoadAchievementDataToObjectNew(string value)
|
|
{
|
|
try
|
|
{
|
|
string[] strings = value.Split(';');
|
|
foreach (var item in strings)
|
|
{
|
|
string[] keyValue = item.Split(':');
|
|
if (keyValue.Length == 2)
|
|
{
|
|
ConditionType type = (ConditionType)Enum.Parse(typeof(ConditionType), keyValue[0]);
|
|
string[] Value = keyValue[1].Split('|');
|
|
if (Value.Length == 3)
|
|
{
|
|
AchievementData achievementData = new AchievementData();
|
|
achievementData.ToObject(Value);
|
|
_achievementDatas[type] = achievementData;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
UnityEngine.Debug.LogError($"LoadAchievementDataToObjectNew Error:{e}");
|
|
}
|
|
}
|
|
public string AchievementDataToJson()
|
|
{
|
|
try
|
|
{
|
|
Dictionary<ConditionType, string> keyValuePairs = new Dictionary<ConditionType, string>();
|
|
List<string> strings = new List<string>();
|
|
foreach (var item in _achievementDatas)
|
|
{
|
|
strings.Add($"{(int)item.Key}:{item.Value.ToString()}");
|
|
}
|
|
string result = string.Join(";", strings);
|
|
return result;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
UnityEngine.Debug.LogError($"LoadAchievementDataToObjectNew Error:{e}");
|
|
return "";
|
|
}
|
|
}
|
|
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.MaxCashFromRaid:
|
|
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;
|
|
}
|
|
}
|