193 lines
6.7 KiB
C#
193 lines
6.7 KiB
C#
using asap.core;
|
||
using GameCore;
|
||
using cfg;
|
||
using UnityEngine;
|
||
using System.Collections.Generic;
|
||
using System;
|
||
using game;
|
||
using System.Linq;
|
||
public class PiggyBankPackData
|
||
{
|
||
private readonly Tables _tables = GContext.container.Resolve<Tables>();
|
||
private readonly TbEventPackManager _epm
|
||
= GContext.container.Resolve<Tables>().TbEventPackManager;
|
||
private struct Data
|
||
{
|
||
public int currentEventID;
|
||
public int purchaseCount;
|
||
public int VIPLvlWhenEventActivate;
|
||
public bool doNeedTrigger;
|
||
public bool isTriggered;
|
||
public int savingProgress;
|
||
public int redirectID;
|
||
public Data(int eventID = 0, int v = 0, bool b = false, int rid = 0)
|
||
{
|
||
currentEventID = eventID;
|
||
purchaseCount = 0;
|
||
VIPLvlWhenEventActivate = v;
|
||
doNeedTrigger = b;
|
||
savingProgress = 0;
|
||
isTriggered = false;
|
||
redirectID = rid;
|
||
}
|
||
}
|
||
private Data _data;
|
||
public bool IsWithinEventTime
|
||
{
|
||
get
|
||
{
|
||
if (!_tables.TbFishingEvent.DataMap.Keys.Contains(_data.currentEventID))
|
||
return false;
|
||
var et = DateTime.Parse((_tables.TbFishingEvent[_data.currentEventID].TimeDefinition as LimitedTime).EndTime);
|
||
var st = DateTime.Parse((_tables.TbFishingEvent[_data.currentEventID].TimeDefinition as LimitedTime).StartTime);
|
||
return ZZTimeHelper.UtcNow() >= st && ZZTimeHelper.UtcNow() < et;
|
||
}
|
||
}
|
||
public bool IsPackActivated { get => _data.isTriggered && _tables.TbFishingEvent.DataMap.Keys.Contains(_data.currentEventID) && IsWithinEventTime && _data.purchaseCount < _epm[RedirectID].MaxCount; }
|
||
public bool DoNeedUpdate { get => _data.doNeedTrigger; set => _data.doNeedTrigger = value; }
|
||
public int CurrentEventID { get => _data.currentEventID; }
|
||
public int PurchaseCount { get => _data.purchaseCount; }
|
||
public int VIPLvlWhenEventActivated { get => _data.VIPLvlWhenEventActivate; }
|
||
public int Progress { get => _data.savingProgress; }
|
||
public bool IsFull { get => _data.savingProgress >= Target; }
|
||
public int ActivateItemId
|
||
{
|
||
get => _tables.TbSpecialPack[_epm[RedirectID]
|
||
.VIPPackList[_data.VIPLvlWhenEventActivate][0]]
|
||
.ActivateItemId;
|
||
}
|
||
public string ActiveItemImg { get => _tables.TbSpecialPack[_epm[RedirectID]
|
||
.VIPPackList[_data.VIPLvlWhenEventActivate][0]].ActiveItemImg; }
|
||
|
||
public int EventItemId
|
||
{
|
||
get
|
||
{
|
||
SpecialPack specialPack = GetSpecialPack();
|
||
if (specialPack != null)
|
||
{
|
||
return specialPack.EventItemId;
|
||
}
|
||
return 0;
|
||
}
|
||
}
|
||
SpecialPack GetSpecialPack()
|
||
{
|
||
var TbEventPackManager = _tables.TbEventPackManager.GetOrDefault(_data.redirectID);
|
||
if (TbEventPackManager == null)
|
||
{
|
||
return null;
|
||
}
|
||
return _tables.TbSpecialPack.GetOrDefault(TbEventPackManager.VIPPackList[_data.VIPLvlWhenEventActivate][0]);
|
||
}
|
||
public int Target
|
||
{
|
||
get => _tables.TbSpecialPack[_epm[RedirectID]
|
||
.VIPPackList[_data.VIPLvlWhenEventActivate][0]]
|
||
.EventItemRequire[0];
|
||
}
|
||
public int CanBuyCount
|
||
{
|
||
get => _tables.TbSpecialPack[_epm[RedirectID]
|
||
.VIPPackList[_data.VIPLvlWhenEventActivate][0]]
|
||
.CanBuyCount;
|
||
}
|
||
//public int RedirectID { get => _tables.TbFishingEvent[_data.currentEventID].RedirectID; }
|
||
public int RedirectID { get => _data.redirectID; }
|
||
public int RewardDropID
|
||
{
|
||
get => _tables.TbSpecialPack[_epm[RedirectID]
|
||
.VIPPackList[_data.VIPLvlWhenEventActivate][0]]
|
||
.DropID[0];
|
||
}
|
||
public List<int> FishingScoreList
|
||
{
|
||
get => _tables.TbSpecialPack[_epm[RedirectID].VIPPackList[_data.VIPLvlWhenEventActivate][0]]
|
||
.EventItemGet;
|
||
}
|
||
public TimeSpan RemainingTime
|
||
{
|
||
get
|
||
{
|
||
return DateTime.Parse((_tables.TbFishingEvent[_data.currentEventID].TimeDefinition as LimitedTime).EndTime)
|
||
- ZZTimeHelper.UtcNow();
|
||
}
|
||
}
|
||
public int MaxCount { get => _epm[RedirectID].MaxCount; }
|
||
public void LoadData(string s)
|
||
{
|
||
_data = Newtonsoft.Json.JsonConvert.DeserializeObject<Data>(s);
|
||
|
||
//_data.redirectID = 0;
|
||
if (_data.redirectID == 0)
|
||
{
|
||
_data.redirectID = 4055001;
|
||
}
|
||
}
|
||
public void UpdateData(cfg.FishingEvent e)
|
||
{
|
||
if (_epm[_tables.TbFishingEvent[e.ID].RedirectID].PackType != 2)
|
||
{
|
||
Debug.LogError($"Fishing event ID {e.ID} is not a piggyBank event.");
|
||
return;
|
||
}
|
||
if (_data.currentEventID != e.ID)
|
||
_data = new Data(e.ID, GContext.container.Resolve<PlayerData>().PriceLv, true, e.RedirectID);
|
||
if (_data.redirectID != e.RedirectID)
|
||
{
|
||
_data.redirectID = e.RedirectID;
|
||
Debug.Log("working!!!!!!!!!!");
|
||
}
|
||
SaveData();
|
||
}
|
||
public void SaveData()
|
||
{
|
||
PlayFabMgr.Instance.UpdateUserDataValue("PiggyBankPackData",
|
||
Newtonsoft.Json.JsonConvert.SerializeObject(_data));
|
||
}
|
||
public bool AddProgress(int fishTier, int magnification)
|
||
{
|
||
if (!IsPackActivated || fishTier < 1 || fishTier > 5)
|
||
{
|
||
//Debug.LogError($"Fish Tier {fishTier} not defined in TbSpedialPack");
|
||
return false;
|
||
}
|
||
var TbSpecialPack = _tables.TbSpecialPack[_epm[RedirectID].VIPPackList[_data.VIPLvlWhenEventActivate][0]];
|
||
int progress = TbSpecialPack.EventItemGet[fishTier - 1] * magnification;
|
||
if (progress > 0 && _data.savingProgress < Target)
|
||
{
|
||
int curProgress = _data.savingProgress;
|
||
_data.savingProgress += progress;
|
||
GContext.Publish(new TargetAddData(TbSpecialPack.EventItemId, curProgress, progress));
|
||
if (_data.savingProgress >= Target)
|
||
{
|
||
GContext.container.Resolve<IFaceUIService>().AddGiftFaceUI(_data.currentEventID, UITypes.GiftPiggyBankPopupPanel, 0, true);
|
||
_data.savingProgress = Target;
|
||
SaveData();
|
||
return true;
|
||
}
|
||
SaveData();
|
||
}
|
||
return false;
|
||
}
|
||
public void AddPurchase()
|
||
{
|
||
_data.purchaseCount++;
|
||
SaveData();
|
||
}
|
||
public void TriggerPack()
|
||
{
|
||
DoNeedUpdate = false;
|
||
_data.isTriggered = true;
|
||
_data.savingProgress += _tables.TbSpecialPack[_epm[RedirectID]
|
||
.VIPPackList[_data.VIPLvlWhenEventActivate][0]].EventItemCountFirst;
|
||
SaveData();
|
||
}
|
||
}
|
||
public class PiggyBankProgressEvent
|
||
{
|
||
public int type;//0: 初始化 1:增加动画
|
||
public int addProgress;
|
||
}
|
||
|