447 lines
14 KiB
C#
447 lines
14 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using asap.core;
|
|
using cfg;
|
|
using game;
|
|
using LitJson;
|
|
|
|
namespace GameCore
|
|
{
|
|
public class AlbumData
|
|
{
|
|
private cfg.Tables _tables;
|
|
public AlbumData(cfg.Tables tables)
|
|
{
|
|
this._tables = tables;
|
|
}
|
|
public Theme theme;
|
|
public int eventId = 0;
|
|
public List<Album> albumList = new List<Album>();
|
|
public Dictionary<int, int> fishAlbumData = new Dictionary<int, int>();
|
|
public List<int> newAlbum = new List<int>();
|
|
public Dictionary<int, int> PhotoRequestCountByDay = new Dictionary<int, int>();
|
|
List<int> pictureList = new List<int>();
|
|
public Dictionary<int, double> exchangeCD = new Dictionary<int, double>();
|
|
public int TipforUnlocked;
|
|
|
|
public void InitGiftToFriendsDay(Dictionary<string, int> _photoRequestCountByDay)
|
|
{
|
|
if (_photoRequestCountByDay.ContainsKey("-1"))
|
|
{
|
|
int dayOfYear = _photoRequestCountByDay["-1"];
|
|
if (dayOfYear == ZZTimeHelper.UtcNow().UtcNowOffset().DayOfYear)
|
|
{
|
|
PhotoRequestCountByDay = _photoRequestCountByDay.ToDictionary(i => int.Parse(i.Key), i => i.Value);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void GMAddAll()
|
|
{
|
|
foreach (var i in pictureList)
|
|
{
|
|
if (fishAlbumData.ContainsKey(i))
|
|
{
|
|
fishAlbumData[i] += 1;
|
|
}
|
|
else
|
|
{
|
|
fishAlbumData[i] = 1;
|
|
newAlbum.Add(i);
|
|
}
|
|
}
|
|
|
|
SaveNewAlbumData();
|
|
GetAllAlbumReward();
|
|
SavePictureProgress();
|
|
SetExchangeRed();
|
|
}
|
|
public void SetAlbumEvent(FishingEvent t)
|
|
{
|
|
theme = _tables.TbTheme.GetOrDefault(t.RedirectID);
|
|
if (theme != null)
|
|
{
|
|
eventId = t.ID;
|
|
if (GContext.container.Resolve<PlayerData>().seasonId != t.RedirectID)
|
|
{
|
|
GContext.container.Resolve<PlayerData>().seasonId = t.RedirectID;
|
|
SetAlubmRed(RedPointName.Home_Album_ID, true);
|
|
PlayFabMgr.Instance.UpdateUserDataValue("SeasonId", theme.ID.ToString());
|
|
Init();
|
|
}
|
|
}
|
|
}
|
|
public void Init()
|
|
{
|
|
if (theme == null)
|
|
{
|
|
return;
|
|
}
|
|
List<int> fishAlbumDataRoot = new List<int> { theme.ID };
|
|
foreach (var t in theme.AlbumList)
|
|
{
|
|
Album album = _tables.TbAlbum[t];
|
|
albumList.Add(album);
|
|
pictureList.AddRange(album.PictureList);
|
|
if (fishAlbumData.ContainsKey(album.ID))
|
|
{
|
|
fishAlbumDataRoot.Add(album.ID);
|
|
}
|
|
}
|
|
|
|
var newAlbumData = fishAlbumData.Where(i => pictureList.Contains(i.Key) || fishAlbumDataRoot.Contains(i.Key)).ToDictionary(i => i.Key, i => i.Value);
|
|
|
|
fishAlbumData = newAlbumData;
|
|
SetAlubmRed(RedPointName.Home_Album_New, newAlbum.Count > 0);
|
|
SetExchangeRed();
|
|
}
|
|
|
|
public bool IsEventStart()
|
|
{
|
|
return theme != null;
|
|
}
|
|
|
|
public void SetExchangeCd(int index, float cd)
|
|
{
|
|
exchangeCD[index] = (ZZTimeHelper.UtcNow().UtcNowOffset().AddSeconds(cd) - new DateTime(1970, 1, 1, 0, 0, 0, 0)).TotalSeconds;
|
|
SetExchangeRed();
|
|
//保存exchangeCD
|
|
PlayFabMgr.Instance.UpdateUserDataValue("PictureExchangeCD", JsonMapper.ToJson(exchangeCD));
|
|
}
|
|
|
|
public void RemoveExchangeCd(int index)
|
|
{
|
|
if (exchangeCD.ContainsKey(index))
|
|
{
|
|
exchangeCD.Remove(index);
|
|
}
|
|
SetExchangeRed();
|
|
}
|
|
|
|
public float GetExchangeCd(int index)
|
|
{
|
|
if (exchangeCD.TryGetValue(index, out var cd))
|
|
{
|
|
float endCd = (float)(cd - (ZZTimeHelper.UtcNow().UtcNowOffset() - new DateTime(1970, 1, 1, 0, 0, 0, 0)).TotalSeconds);
|
|
if (endCd <= 0.001)
|
|
{
|
|
RemoveExchangeCd(index);
|
|
}
|
|
return endCd;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
public int GetAlbumProgress(List<int> ids)
|
|
{
|
|
int count = 0;
|
|
foreach (var id in ids)
|
|
{
|
|
if (GetPictureProgress(id) > 0)
|
|
{
|
|
count++;
|
|
}
|
|
}
|
|
|
|
return count;
|
|
}
|
|
void SetExchangeRed()
|
|
{
|
|
bool isRed = false;
|
|
if (theme != null)
|
|
{
|
|
List<int> exchangeIdList = theme.ExchangeList;
|
|
int count = exchangeIdList.Count;
|
|
int allCount = GetPictureRepeatCount();
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
AlbumExchange albumExchange = _tables.GetAlbumExchange(exchangeIdList[i]);
|
|
if (GetExchangeCd(i) <= 0.001 && albumExchange.PictureRequired <= GetPictureRepeatCount())
|
|
{
|
|
isRed = true;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
SetAlubmRed(RedPointName.Home_Album_Exchange, isRed);
|
|
}
|
|
public void AddPictureProgress(int id, int progress)
|
|
{
|
|
if (fishAlbumData.ContainsKey(id))
|
|
{
|
|
fishAlbumData[id] += progress;
|
|
}
|
|
else
|
|
{
|
|
fishAlbumData[id] = progress;
|
|
newAlbum.Add(id);
|
|
SaveNewAlbumData();
|
|
}
|
|
SetExchangeRed();
|
|
GetAlbumReward(id);
|
|
GetAllAlbumReward();
|
|
SavePictureProgress();
|
|
}
|
|
public void AddPictureProgress(List<int> pictureIDs)
|
|
{
|
|
int id;
|
|
for (int i = 0; i < pictureIDs.Count; i++)
|
|
{
|
|
id = pictureIDs[i];
|
|
if (fishAlbumData.ContainsKey(id))
|
|
{
|
|
fishAlbumData[id]++;
|
|
}
|
|
else
|
|
{
|
|
fishAlbumData[id] = 1;
|
|
newAlbum.Add(id);
|
|
}
|
|
GetAlbumReward(id);
|
|
}
|
|
SaveNewAlbumData();
|
|
SetExchangeRed();
|
|
GetAllAlbumReward();
|
|
SavePictureProgress();
|
|
}
|
|
public bool IsNewPicture(int id)
|
|
{
|
|
return newAlbum.Contains(id);
|
|
}
|
|
public void RemoveNewPicture(int id)
|
|
{
|
|
if (newAlbum.Contains(id))
|
|
{
|
|
newAlbum.Remove(id);
|
|
SaveNewAlbumData();
|
|
}
|
|
SetExchangeRed();
|
|
}
|
|
//集齐相册奖励
|
|
void GetAlbumReward(int id)
|
|
{
|
|
int count = albumList.Count;
|
|
if (count == 0)
|
|
{
|
|
//GContext.container.Resolve<FishingEventData>().GetEventAndInit(3, 1);
|
|
count = albumList.Count;
|
|
}
|
|
if (theme == null)
|
|
{
|
|
return;
|
|
}
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
if (albumList[i].PictureList.Contains(id))
|
|
{
|
|
if (GetPictureProgress(albumList[i].ID) == 0)
|
|
{
|
|
int fishPictureProgress = 0;
|
|
foreach (var t in albumList[i].PictureList)
|
|
{
|
|
if (GetPictureProgress(t) > 0)
|
|
{
|
|
fishPictureProgress++;
|
|
}
|
|
}
|
|
|
|
if (fishPictureProgress >= albumList[i].PictureList.Count)
|
|
{
|
|
//领取全部奖励
|
|
fishAlbumData[albumList[i].ID] = 1;
|
|
List<ItemData> itemDataList = GContext.container.Resolve<PlayerItemData>().GetItemDataByDropIdAndType(albumList[i].CollectionReward);
|
|
GContext.container.Resolve<PlayerItemData>().AddItem(itemDataList);
|
|
GContext.Publish(new ShowData(itemDataList, RewardType.CollectionAlbum, albumList[i].ID));
|
|
}
|
|
}
|
|
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
//全部集齐图鉴奖励
|
|
void GetAllAlbumReward()
|
|
{
|
|
int count = albumList.Count;
|
|
if (count == 0)
|
|
{
|
|
//GContext.container.Resolve<FishingEventData>().GetEventAndInit(3, 1);
|
|
count = albumList.Count;
|
|
}
|
|
if (theme == null)
|
|
{
|
|
return;
|
|
}
|
|
//当收集完成的时候获得全部奖励
|
|
if (GetPictureProgress(theme.ID) == 0 && count > 0)
|
|
{
|
|
int fishAlbumProgress = 0;
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
if (GetAlbumProgress(albumList[i].PictureList) >= albumList[i].PictureList.Count)
|
|
{
|
|
fishAlbumProgress++;
|
|
}
|
|
}
|
|
|
|
if (fishAlbumProgress >= count)
|
|
{
|
|
//领取全部奖励
|
|
fishAlbumData[theme.ID] = 1;
|
|
//全部图鉴收集完成
|
|
List<ItemData> itemDataList = GContext.container.Resolve<PlayerItemData>().GetItemDataByDropIdAndType(theme.CollectionReward);
|
|
GContext.container.Resolve<PlayerItemData>().AddItem(itemDataList);
|
|
GContext.Publish(new ShowData(itemDataList, RewardType.CollectionAlbum));
|
|
}
|
|
}
|
|
}
|
|
|
|
public void RemovePictureProgress(int id, int progress)
|
|
{
|
|
if (fishAlbumData.ContainsKey(id))
|
|
{
|
|
fishAlbumData[id] -= progress;
|
|
}
|
|
else
|
|
{
|
|
fishAlbumData[id] = 0;
|
|
}
|
|
|
|
SavePictureProgress();
|
|
}
|
|
|
|
public void RemovePictureProgress(Dictionary<int, int> selectPicture)
|
|
{
|
|
foreach (var i in selectPicture)
|
|
{
|
|
if (fishAlbumData.ContainsKey(i.Value) && fishAlbumData[i.Value] > 0)
|
|
{
|
|
fishAlbumData[i.Value]--;
|
|
}
|
|
else
|
|
{
|
|
fishAlbumData[i.Key] = 0;
|
|
}
|
|
}
|
|
|
|
SavePictureProgress();
|
|
}
|
|
|
|
public int GetPictureProgress(int id)
|
|
{
|
|
if (fishAlbumData.ContainsKey(id))
|
|
{
|
|
return fishAlbumData[id];
|
|
}
|
|
else
|
|
{
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
//重复卡片数量
|
|
public int GetPictureRepeatCount()
|
|
{
|
|
cfg.Picture picture;
|
|
int allCount = 0;
|
|
foreach (var i in fishAlbumData)
|
|
{
|
|
if (i.Value > 1)
|
|
{
|
|
picture = _tables.TbPicture[i.Key];
|
|
if (picture.IsTradable)
|
|
{
|
|
allCount += i.Value - 1;
|
|
}
|
|
}
|
|
}
|
|
|
|
return allCount;
|
|
}
|
|
|
|
public List<cfg.Picture> GetPictureRepeatList()
|
|
{
|
|
cfg.Picture picture;
|
|
List<cfg.Picture> pictureList = new List<cfg.Picture>();
|
|
foreach (var i in fishAlbumData)
|
|
{
|
|
if (i.Value > 1)
|
|
{
|
|
picture = _tables.TbPicture[i.Key];
|
|
if (picture.IsTradable)
|
|
{
|
|
pictureList.Add(picture);
|
|
}
|
|
}
|
|
}
|
|
|
|
return pictureList;
|
|
}
|
|
public int SetPhotoRequestCountByDay(int id = 0)
|
|
{
|
|
int dayOfYear = ZZTimeHelper.UtcNow().UtcNowOffset().DayOfYear;
|
|
if (PhotoRequestCountByDay.TryGetValue(-1, out int day))
|
|
{
|
|
if (day != dayOfYear)
|
|
{
|
|
PhotoRequestCountByDay.Clear();
|
|
}
|
|
}
|
|
PhotoRequestCountByDay[-1] = dayOfYear;
|
|
if (!PhotoRequestCountByDay.ContainsKey(id))
|
|
{
|
|
PhotoRequestCountByDay[id] = 1;
|
|
}
|
|
else
|
|
{
|
|
PhotoRequestCountByDay[id]++;
|
|
}
|
|
UpdatePlayerStatistics();
|
|
return PhotoRequestCountByDay[id];
|
|
}
|
|
public int GetPhotoRequestCountByDay(int id = 0)
|
|
{
|
|
if (PhotoRequestCountByDay.TryGetValue(id, out int count))
|
|
{
|
|
int dayOfYear = ZZTimeHelper.UtcNow().UtcNowOffset().DayOfYear;
|
|
if (PhotoRequestCountByDay.TryGetValue(-1, out int day))
|
|
{
|
|
if (day != dayOfYear)
|
|
{
|
|
PhotoRequestCountByDay.Clear();
|
|
PhotoRequestCountByDay[-1] = dayOfYear;
|
|
UpdatePlayerStatistics();
|
|
count = 0;
|
|
}
|
|
}
|
|
}
|
|
return count;
|
|
}
|
|
public void UpdatePlayerStatistics()
|
|
{
|
|
PlayFabMgr.Instance.UpdateUserDataValue("PhotoRequestCountByDay", JsonMapper.ToJson(PhotoRequestCountByDay));
|
|
}
|
|
|
|
public void SavePictureProgress()
|
|
{
|
|
PlayFabMgr.Instance.UpdateUserDataValue("Picture", JsonMapper.ToJson(fishAlbumData));
|
|
}
|
|
void SaveNewAlbumData()
|
|
{
|
|
SetAlubmRed(RedPointName.Home_Album_New, newAlbum.Count > 0);
|
|
PlayFabMgr.Instance.UpdateUserDataValue("NewAlbum", JsonMapper.ToJson(newAlbum));
|
|
}
|
|
public void SetAlubmRed(string key, bool value)
|
|
{
|
|
RedPointManager.Instance.SetRedPointState(key, value && theme != null);
|
|
RedPointManager.Instance.SetRedPointState(RedPointName.Home_Album, (newAlbum.Count > 0 || RedPointManager.Instance.GetRedPointState(RedPointName.Home_Album_Exchange)) && theme != null);
|
|
}
|
|
public DateTime GetAlbumEndTime()
|
|
{
|
|
return GContext.container.Resolve<FishingEventData>().GetEventEndTime(eventId);
|
|
}
|
|
}
|
|
} |