备份CatanBuilding瘦身独立工程
This commit is contained in:
250
Assets/Scripts/DataCenter/BargainPackData.cs
Normal file
250
Assets/Scripts/DataCenter/BargainPackData.cs
Normal file
@@ -0,0 +1,250 @@
|
||||
using asap.core;
|
||||
using cfg;
|
||||
using GameCore;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using game;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class BargainPackData
|
||||
{
|
||||
private readonly Tables _tables = GContext.container.Resolve<Tables>();
|
||||
private readonly TbEventPackManager _epm = GContext.container.Resolve<Tables>().TbEventPackManager;
|
||||
private readonly TbSpecialPack _spp = GContext.container.Resolve<Tables>().TbSpecialPack;
|
||||
private GeneralEventPackData _data;
|
||||
|
||||
public int CurrentEventID => _data.currentEventID;
|
||||
|
||||
public FishingEvent CurrentEvent => _tables.TbFishingEvent[_data.currentEventID];
|
||||
|
||||
public TimeSpan RemainingTime =>
|
||||
DateTime.Parse((_tables.TbFishingEvent[_data.currentEventID].TimeDefinition as LimitedTime).EndTime) -
|
||||
ZZTimeHelper.UtcNow();
|
||||
|
||||
public bool IsWithinEventTime
|
||||
{
|
||||
get
|
||||
{
|
||||
if (CurrentEventID == 0) 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
|
||||
{
|
||||
bool res = _tables.TbFishingEvent.DataMap.ContainsKey(_data.currentEventID)
|
||||
&& _epm.DataMap.ContainsKey(_data.redirectID)
|
||||
&& _epm[_data.redirectID].PackType == 3
|
||||
&& IsWithinEventTime
|
||||
&& _data.isTriggered
|
||||
&& _data.purchaseCount < _epm[_data.redirectID].MaxCount;
|
||||
//Debug.Log(_tables.TbFishingEvent.DataMap.ContainsKey(_data.currentEventID));
|
||||
//Debug.Log(_epm.DataMap.ContainsKey(_data.redirectID));
|
||||
//Debug.Log(_epm[_data.redirectID].PackType == 3);
|
||||
//Debug.Log(IsWithinEventTime);
|
||||
//Debug.Log(_data.isTriggered);
|
||||
//Debug.Log(_data.purchaseCount < _epm[_data.redirectID].MaxCount);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
public int RedirectID => _data.redirectID;
|
||||
public bool DoNeedTrigger => _data.doNeedTrigger;
|
||||
public int PackID => _epm[_data.redirectID].VIPPackList[_data.VIPLvlWhenEventActivate][0];
|
||||
public int DiscountLvlCount => _spp[PackID].IAPID.Count;
|
||||
public int DiscountLvl => _data.discountLvl;
|
||||
public int PurchaseCount => _data.purchaseCount;
|
||||
public int Progress => _data.savingProgress;
|
||||
public int VIPLvlWhenEventActivated => _data.VIPLvlWhenEventActivate;
|
||||
public int ActivateItemId => _spp[PackID].ActivateItemId;
|
||||
public string ActiveItemImg => _spp[PackID].ActiveItemImg;
|
||||
public int EventItemId => IsPackActivated ? _spp[PackID].EventItemId : 0;
|
||||
public int RewardDropID => _spp[PackID].DropID[0];
|
||||
public int MaxCount => _epm[_data.redirectID].MaxCount;
|
||||
|
||||
public int NextTarget
|
||||
{
|
||||
get
|
||||
{
|
||||
int lvl = _data.discountLvl >= DiscountLvlCount - 1 ? DiscountLvlCount - 1 : _data.discountLvl + 1;
|
||||
return _spp[PackID].EventItemRequire[lvl];
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsFull => _data.discountLvl >= DiscountLvlCount - 1 && _data.savingProgress >= NextTarget;
|
||||
public int IAPID => _spp[PackID].IAPID[DiscountLvl];
|
||||
public List<int> FishingScoreList => _spp[PackID].EventItemGet;
|
||||
public int NextDiscount
|
||||
{
|
||||
get
|
||||
{
|
||||
int lvl = _data.discountLvl >= DiscountLvlCount - 1 ? DiscountLvlCount - 1 : _data.discountLvl + 1;
|
||||
return _spp[PackID].DiscountList[lvl];
|
||||
}
|
||||
}
|
||||
public int VisualProgress => _data.visualProgress;
|
||||
public int VisualDiscountLvl => _data.visualDiscountLvl;
|
||||
public int NextVisualTarget
|
||||
{
|
||||
get
|
||||
{
|
||||
int lvl = _data.visualDiscountLvl >= DiscountLvlCount - 1
|
||||
? DiscountLvlCount - 1
|
||||
: _data.visualDiscountLvl + 1;
|
||||
return _spp[PackID].EventItemRequire[lvl];
|
||||
}
|
||||
}
|
||||
|
||||
public int NextVisualDiscount
|
||||
{
|
||||
get
|
||||
{
|
||||
int lvl = _data.visualDiscountLvl >= DiscountLvlCount - 1
|
||||
? DiscountLvlCount - 1
|
||||
: _data.visualDiscountLvl + 1;
|
||||
return _spp[PackID].DiscountList[lvl];
|
||||
}
|
||||
}
|
||||
|
||||
public void SaveData()
|
||||
{
|
||||
//Debug.LogError("Testing, data not saved for debug purpose.");
|
||||
PlayFabMgr.Instance.UpdateUserDataValue("GeneralEventPackData",
|
||||
Newtonsoft.Json.JsonConvert.SerializeObject(_data));
|
||||
}
|
||||
|
||||
public void LoadData(GeneralEventPackData data)
|
||||
{
|
||||
_data = data;
|
||||
if (IsPackActivated && IsFull)
|
||||
{
|
||||
GContext.container.Resolve<IFaceUIService>().AddGiftFaceUI(_data.currentEventID,
|
||||
UITypes.GiftBargainPopupPanel, _epm[RedirectID].PackType, true);
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateData(FishingEvent e)
|
||||
{
|
||||
if (_epm[_tables.TbFishingEvent[e.ID].RedirectID].PackType != 3)
|
||||
{
|
||||
Debug.LogError($"Fishing event ID {e.ID} is not a Bargain back event");
|
||||
return;
|
||||
}
|
||||
|
||||
if (_data.currentEventID != e.ID)
|
||||
{
|
||||
_data = new GeneralEventPackData(
|
||||
eventID: e.ID,
|
||||
vip: GContext.container.Resolve<PlayerData>().PriceLv,
|
||||
redirectID: e.RedirectID,
|
||||
savingProgress: 0,
|
||||
discountLvl: 0,
|
||||
isTriggered: false,
|
||||
doNeedTrigger: true,
|
||||
visualProgress: 0,
|
||||
visualDiscountLvl: 0,
|
||||
purchaseCount: 0);
|
||||
}
|
||||
|
||||
SaveData();
|
||||
}
|
||||
|
||||
public void TriggerPack()
|
||||
{
|
||||
_data.doNeedTrigger = false;
|
||||
_data.isTriggered = true;
|
||||
//_data.savingProgress += _spp[PackID].EventItemCountFirst;
|
||||
AddProgress(_spp[PackID].EventItemCountFirst);
|
||||
SaveData();
|
||||
}
|
||||
|
||||
public void AddProgress(int progress)
|
||||
{
|
||||
if (progress <= 0 || IsFull)
|
||||
return;
|
||||
_data.savingProgress += progress;
|
||||
while (_data.savingProgress >= NextTarget)
|
||||
{
|
||||
//DoUICut = true;
|
||||
_data.savingProgress -= NextTarget;
|
||||
_data.discountLvl++;
|
||||
if (_data.discountLvl >= DiscountLvlCount - 1)
|
||||
{
|
||||
_data.savingProgress = NextTarget;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
SaveData();
|
||||
return;
|
||||
}
|
||||
|
||||
public void AddProgress(int fishTier, int magnification)
|
||||
{
|
||||
if (!IsPackActivated || fishTier < 1 || fishTier > 5)
|
||||
{
|
||||
//Debug.LogError($"Fish Tier {fishTier} not defined in TbSpedialPack");
|
||||
return;
|
||||
}
|
||||
|
||||
int progress = _spp[PackID].EventItemGet[fishTier - 1] * magnification;
|
||||
if (progress <= 0 || IsFull)
|
||||
return;
|
||||
|
||||
int curProgress = _data.savingProgress;
|
||||
_data.savingProgress += progress;
|
||||
GContext.Publish(new TargetAddData(EventItemId, curProgress, progress));
|
||||
while (_data.savingProgress >= NextTarget)
|
||||
{
|
||||
//DoUICut = true;
|
||||
_data.savingProgress -= NextTarget;
|
||||
_data.discountLvl++;
|
||||
if (_data.discountLvl >= DiscountLvlCount - 1)
|
||||
{
|
||||
GContext.container.Resolve<IFaceUIService>()
|
||||
.AddGiftFaceUI(CurrentEventID, UITypes.GiftBargainPopupPanel, 0, true);
|
||||
_data.savingProgress = NextTarget;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
SaveData();
|
||||
return;
|
||||
}
|
||||
|
||||
public void AddPurchase()
|
||||
{
|
||||
_data.purchaseCount++;
|
||||
SaveData();
|
||||
}
|
||||
|
||||
public void RefreshVisualData()
|
||||
{
|
||||
_data.visualDiscountLvl = _data.discountLvl;
|
||||
_data.visualProgress = _data.savingProgress;
|
||||
SaveData();
|
||||
}
|
||||
|
||||
public int GetNextDiscountTarget(int l)
|
||||
{
|
||||
int lvl = l >= DiscountLvlCount - 1 ? DiscountLvlCount - 1 : l + 1;
|
||||
return _spp[PackID].EventItemRequire[lvl];
|
||||
}
|
||||
|
||||
public int GetNextDiscount(int l)
|
||||
{
|
||||
int lvl = l >= DiscountLvlCount - 1 ? DiscountLvlCount - 1 : l + 1;
|
||||
return _spp[PackID].DiscountList[lvl];
|
||||
}
|
||||
}
|
||||
|
||||
public class BargainPackProgressEvent
|
||||
{
|
||||
public int type; //0: 初始化 1:增加动画
|
||||
public int addProgress;
|
||||
}
|
||||
Reference in New Issue
Block a user