备份CatanBuilding瘦身独立工程
This commit is contained in:
37
Assets/Scripts/EventGatherCore/EventGatherCoreAct.cs
Normal file
37
Assets/Scripts/EventGatherCore/EventGatherCoreAct.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using GameCore;
|
||||
using asap.core;
|
||||
using System.Threading.Tasks;
|
||||
// using UnityEngine.UI;
|
||||
// using DG.Tweening;
|
||||
// using UnityEngine;
|
||||
|
||||
public class EventGatherCoreAct : AGameAct
|
||||
{
|
||||
public static EventGatherCoreTableContext Ctx;
|
||||
private IDeferredRewardStashService _rewardStashService;
|
||||
private IEventAggregator _eventAggregator;
|
||||
public static readonly string ActAddressable = "EventGatherCoreAct";
|
||||
// private CanvasScaler _canvasScaler;
|
||||
// private readonly float normalScale = 0.75f, actScale = 1.0f, duration = 0.75f;
|
||||
// private readonly Vector2 targetResolution = new Vector2(1080, 2340);
|
||||
// private Vector2 originalResolution;
|
||||
|
||||
public override async Task<bool> StartAsync()
|
||||
{
|
||||
_rewardStashService = GContext.container.Resolve<IDeferredRewardStashService>();
|
||||
_rewardStashService.Reset();
|
||||
_eventAggregator = new EventAggregator();
|
||||
// _canvasScaler = UIManager.Instance.GetComponent<CanvasScaler>();
|
||||
// originalResolution = _canvasScaler.referenceResolution;
|
||||
// DOTween.To(() => _canvasScaler.referenceResolution, v => _canvasScaler.referenceResolution = v, targetResolution, duration).SetEase(Ease.OutQuad);
|
||||
var panelGo = await UIManager.Instance.ShowUILoad(UITypes.EventGatherCorePanel);
|
||||
panelGo.GetComponent<EventGatherCorePanel>().Init(_eventAggregator);
|
||||
return await base.StartAsync();
|
||||
}
|
||||
|
||||
protected override void OnDestroy()
|
||||
{
|
||||
// DOTween.To(() => _canvasScaler.referenceResolution, v => _canvasScaler.referenceResolution = v, originalResolution, duration).SetEase(Ease.OutQuad);
|
||||
UIManager.Instance.DestroyUI(UITypes.EventGatherCorePanel);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/EventGatherCore/EventGatherCoreAct.cs.meta
Normal file
11
Assets/Scripts/EventGatherCore/EventGatherCoreAct.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dd6b6660b1f62dd419ee77a128dbd4ed
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
327
Assets/Scripts/EventGatherCore/EventGatherCoreData.cs
Normal file
327
Assets/Scripts/EventGatherCore/EventGatherCoreData.cs
Normal file
@@ -0,0 +1,327 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using GameCore;
|
||||
using asap.core;
|
||||
using System.Linq;
|
||||
|
||||
public class EventGatherCoreData : IHasChainPack
|
||||
{
|
||||
/// <summary>
|
||||
/// How many stages has been played.
|
||||
/// </summary>
|
||||
private int _ticketCount, _stageCount, _eventId, _chainProgress;
|
||||
public int StageCount => _stageCount;
|
||||
public int TicketCount => _ticketCount;
|
||||
public int EventId => _eventId;
|
||||
public EventGatherCoreStageData StageData;
|
||||
public EventGatherCoreData() { }
|
||||
|
||||
public static EventGatherCoreData CreateNew(cfg.FishingEvent e)
|
||||
{
|
||||
var res = new EventGatherCoreData();
|
||||
res._stageCount = 0;
|
||||
res.StageData = EventGatherCoreStageData.CreateNew();
|
||||
res._eventId = e.ID;
|
||||
return res;
|
||||
}
|
||||
|
||||
public void InitNew(int eventId)
|
||||
{
|
||||
_stageCount = 0;
|
||||
_ticketCount = EventGatherCoreAct.Ctx.GetWelcomeGift();
|
||||
_eventId = eventId;
|
||||
StageData = EventGatherCoreStageData.CreateNew();
|
||||
StageData.MoveToStage(0);
|
||||
_chainProgress = 0;
|
||||
}
|
||||
|
||||
public void LoadData(EventGatherCorePlayfabData data)
|
||||
{
|
||||
_eventId = data.EventId;
|
||||
_ticketCount = data.TicketCount;
|
||||
_stageCount = data.StageCount;
|
||||
StageData = EventGatherCoreStageData.CreateNew();
|
||||
StageData.Init(data.StageCount, data.RewardClaimStateFlag, data.TriggerItemStateFlag);
|
||||
_chainProgress = data.ChainProgress;
|
||||
}
|
||||
|
||||
public void MoveToNextStage()
|
||||
{
|
||||
_stageCount++;
|
||||
StageData.MoveToStage(StageCount);
|
||||
ToPlayfabData().Save();
|
||||
}
|
||||
|
||||
public void AddTicket(int n)
|
||||
{
|
||||
_ticketCount += n;
|
||||
if (_ticketCount < 0)
|
||||
{
|
||||
_ticketCount -= n;
|
||||
}
|
||||
ToPlayfabData().Save();
|
||||
GContext.container.Resolve<FishingEventData>().SaveTransitionData(_eventId, _ticketCount);
|
||||
GContext.Publish(new EventTicketUpdate());
|
||||
}
|
||||
|
||||
public EventGatherCorePlayfabData ToPlayfabData()
|
||||
{
|
||||
var res = new EventGatherCorePlayfabData
|
||||
{
|
||||
EventId = _eventId,
|
||||
TicketCount = _ticketCount,
|
||||
StageCount = _stageCount,
|
||||
RewardClaimStateFlag = StageData.RewardClaimStateFlag,
|
||||
TriggerItemStateFlag = StageData.TriggerItemStateFlag,
|
||||
ChainProgress = _chainProgress
|
||||
};
|
||||
return res;
|
||||
}
|
||||
|
||||
public EventBingoEntranceData ToEntranceData()
|
||||
{
|
||||
var res = new EventBingoEntranceData();
|
||||
var ctx = EventGatherCoreAct.Ctx;
|
||||
var t = ctx.GetEventStartTimeAndEndTime();
|
||||
res.StartTime = t.Item1;
|
||||
res.ExpiryTime = t.Item2;
|
||||
res.Icon = ctx.GetEntranceIcon();
|
||||
res.NeedRedPoint = GContext.container.Resolve<EventGatherCoreData>().TicketCount >= ctx.GetRedPointThreshold();
|
||||
return res;
|
||||
}
|
||||
|
||||
#region ChainPack
|
||||
public void SetChainProgress(int p)
|
||||
{
|
||||
_chainProgress = p;
|
||||
}
|
||||
|
||||
public int GetChainProgress()
|
||||
{
|
||||
return _chainProgress;
|
||||
}
|
||||
|
||||
public void Save()
|
||||
{
|
||||
ToPlayfabData().Save();
|
||||
}
|
||||
public GenericChainPackData<EventGatherCoreData> ToChainPackData()
|
||||
{
|
||||
return GenericChainPackData<EventGatherCoreData>.Create(this, EventGatherCoreAct.Ctx.GetChainPackInfo());
|
||||
}
|
||||
#endregion
|
||||
|
||||
public TimerContext ToTimerContext(System.Action onExpire)
|
||||
{
|
||||
var ctx = EventGatherCoreAct.Ctx;
|
||||
var t = ctx.GetEventStartTimeAndEndTime();
|
||||
var res = new TimerContext
|
||||
{
|
||||
ExpiryTime = t.Item2,
|
||||
StartTime = t.Item1,
|
||||
OnExpire = onExpire
|
||||
};
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
public class EventGatherCoreStageData
|
||||
{
|
||||
public List<int> RewardIdList = new List<int>();
|
||||
public long RewardClaimStateFlag, TriggerItemStateFlag;
|
||||
public int StageId;
|
||||
// public int CoreItemReceivedCount => RewardIdList.Count((id, idx) => EventGatherCoreTableContext.CoreItemIndicator == id && IsRewardClaimed(idx));
|
||||
public int CoreItemReceivedCount
|
||||
{
|
||||
get
|
||||
{
|
||||
int result = 0;
|
||||
if (RewardIdList == null)
|
||||
return result;
|
||||
result = RewardIdList.Where((id, idx) => EventGatherCoreAct.Ctx.IsCoreItem(id) && IsRewardClaimed(idx)).Count();
|
||||
// Debug.Log($"[EventGatherCore] CoreItemReceivedCount: {result}");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
private EventGatherCoreStageData() { }
|
||||
|
||||
public static EventGatherCoreStageData CreateNew()
|
||||
{
|
||||
var res = new EventGatherCoreStageData();
|
||||
res.MoveToStage(0);
|
||||
return res;
|
||||
}
|
||||
|
||||
public int PlayCount
|
||||
{
|
||||
get
|
||||
{
|
||||
int res = 0;
|
||||
long flag = RewardClaimStateFlag;
|
||||
while (flag > 0)
|
||||
{
|
||||
if ((flag & 1) != 0)
|
||||
{
|
||||
res++;
|
||||
}
|
||||
flag >>= 1;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
public void Init(int roundCount, long rewardClaimStateFlag = 0L, long triggerItemStateFlag = 0L)
|
||||
{
|
||||
// Debug.Log($"[EventGatherCore]Move to stage {roundCount}");
|
||||
RewardClaimStateFlag = rewardClaimStateFlag;
|
||||
TriggerItemStateFlag = triggerItemStateFlag;
|
||||
StageId = EventGatherCoreAct.Ctx.GetStageId(roundCount);
|
||||
RewardIdList = EventGatherCoreAct.Ctx.GetRewardIdList(StageId);
|
||||
}
|
||||
|
||||
public void MoveToStage(int roundCount)
|
||||
{
|
||||
// Debug.Log($"[EventGatherCore]Move to stage {roundCount}");
|
||||
var ctx = EventGatherCoreAct.Ctx;
|
||||
StageId = ctx.GetStageId(roundCount);
|
||||
RewardIdList = ctx.GetStageInfo(StageId);
|
||||
RewardClaimStateFlag = 0L;
|
||||
TriggerItemStateFlag = 0L;
|
||||
}
|
||||
|
||||
public bool IsRewardClaimed(int rewardIdx)
|
||||
{
|
||||
return (RewardClaimStateFlag & (1L << rewardIdx)) != 0;
|
||||
}
|
||||
|
||||
public bool IsTriggerUsed(int triggerIdx)
|
||||
{
|
||||
return (TriggerItemStateFlag & (1L << triggerIdx)) != 0;
|
||||
}
|
||||
|
||||
public bool IsEarlyTry(EventGatherCoreTableContext ctx)
|
||||
{
|
||||
return PlayCount < ctx.GetStageMinAttemptCount(StageId) - 1;
|
||||
}
|
||||
|
||||
public bool IsCloseToFinish(EventGatherCoreTableContext ctx)
|
||||
{
|
||||
return CoreItemReceivedCount == ctx.GetCoreItemTargetCount(StageId) - 1;
|
||||
}
|
||||
|
||||
public void SetRewardClaimed(int rewardIdx)
|
||||
{
|
||||
RewardClaimStateFlag |= 1L << rewardIdx;
|
||||
}
|
||||
|
||||
public void SetTriggerUsed(int triggerIdx)
|
||||
{
|
||||
TriggerItemStateFlag |= 1L << triggerIdx;
|
||||
}
|
||||
// public void AddCoreItem(int num = 1)
|
||||
// {
|
||||
// CoreItemReceivedCount += num;
|
||||
// }
|
||||
|
||||
public bool IsStageCleared(EventGatherCoreTableContext ctx)
|
||||
{
|
||||
long fullFlag = (1L << ctx.GetStageInfo(StageId).Count) - 1;
|
||||
return CoreItemReceivedCount >= ctx.GetCoreItemTargetCount(StageId) || (RewardClaimStateFlag & fullFlag) == fullFlag;
|
||||
}
|
||||
|
||||
public List<int> GetRemainingRewardIds()
|
||||
{
|
||||
return RewardIdList.Where((id, idx) => ((1 << idx) & RewardClaimStateFlag) == 0).ToList();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class EventGatherCoreTriggerTaken
|
||||
{
|
||||
public bool Succeeded;
|
||||
public int RewardIdx;
|
||||
public int RewardId;
|
||||
public Vector2 Position;
|
||||
}
|
||||
|
||||
public class EventGatherCoreRewardInfo
|
||||
{
|
||||
public int Idx;
|
||||
public ItemData ItemData;
|
||||
public bool IsSpecial = false;
|
||||
public bool IsClaimed;
|
||||
}
|
||||
|
||||
public class EventGatherCorePlayfabData
|
||||
{
|
||||
public int EventId { get; set; }
|
||||
public int TicketCount { get; set; }
|
||||
public int StageCount { get; set; }
|
||||
public long RewardClaimStateFlag { get; set; }
|
||||
public long TriggerItemStateFlag { get; set; }
|
||||
public int ChainProgress { get; set; }
|
||||
public static readonly string Key = "EventGatherCoreData";
|
||||
private readonly char Splitter = '|';
|
||||
private readonly int TokenCount = 6;
|
||||
|
||||
private string Serialize()
|
||||
{
|
||||
var sb = new System.Text.StringBuilder();
|
||||
sb.Append(EventId).Append(Splitter);
|
||||
sb.Append(TicketCount).Append(Splitter);
|
||||
sb.Append(StageCount).Append(Splitter);
|
||||
sb.Append(RewardClaimStateFlag).Append(Splitter);
|
||||
sb.Append(TriggerItemStateFlag).Append(Splitter);
|
||||
sb.Append(ChainProgress);
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
private void Deserialize(string data)
|
||||
{
|
||||
var tokens = data.Trim(Splitter).Split(Splitter);
|
||||
if (tokens.Length != TokenCount)
|
||||
throw new System.Exception($"[EventGatherCore]Wrong amount of parameters. Expect {TokenCount}, but got {tokens.Length} in \"{data}\".");
|
||||
EventId = int.Parse(tokens[0]);
|
||||
TicketCount = int.Parse(tokens[1]);
|
||||
StageCount = int.Parse(tokens[2]);
|
||||
RewardClaimStateFlag = long.Parse(tokens[3]);
|
||||
TriggerItemStateFlag = long.Parse(tokens[4]);
|
||||
ChainProgress = int.Parse(tokens[5]);
|
||||
}
|
||||
|
||||
public void Save()
|
||||
{
|
||||
PlayFabMgr.Instance.UpdateUserDataValue(Key, Serialize());
|
||||
}
|
||||
|
||||
public static EventGatherCorePlayfabData Load()
|
||||
{
|
||||
var s = PlayFabMgr.Instance.GetLocalData(Key);
|
||||
var res = new EventGatherCorePlayfabData();
|
||||
try
|
||||
{
|
||||
res.Deserialize(s);
|
||||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
Debug.LogWarning($"[EventGatherCore]Error when deserializing EventGatherCoreData: {e}");
|
||||
return null;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class EventGatherCoreUiData
|
||||
{
|
||||
public string MainPanelUrl { get; set; }
|
||||
public string InfoPanelUrl { get; set; }
|
||||
public string ChainPackPanelUrl { get; set; }
|
||||
public string NormalPackPanelUrl { get; set; }
|
||||
public string RewardPopupPanelUrl { get; set; }
|
||||
}
|
||||
|
||||
public class EventGatherCoreRewardPopupPanelClose
|
||||
{
|
||||
public ItemData Reward{ get; set; }
|
||||
}
|
||||
11
Assets/Scripts/EventGatherCore/EventGatherCoreData.cs.meta
Normal file
11
Assets/Scripts/EventGatherCore/EventGatherCoreData.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4d2b930ffccb8c34b8e227e32ba067bd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
78
Assets/Scripts/EventGatherCore/EventGatherCoreEntranceBtn.cs
Normal file
78
Assets/Scripts/EventGatherCore/EventGatherCoreEntranceBtn.cs
Normal file
@@ -0,0 +1,78 @@
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using UnityEngine.UI;
|
||||
using UniRx;
|
||||
using asap.core;
|
||||
using game;
|
||||
using GameCore;
|
||||
|
||||
public class EventGatherCoreEntranceBtn : EventButtonResource
|
||||
{
|
||||
[SerializeField] private TMP_Text textTimer;
|
||||
[SerializeField] private Button button;
|
||||
[SerializeField] private Image icon;
|
||||
private ILoadResourceService _loadResourceService;
|
||||
private EventBingoEntranceData _data;
|
||||
private TimeSpan RemainingTime => _data.ExpiryTime - ZZTimeHelper.UtcNow();
|
||||
private bool IsActive => _data.ExpiryTime > ZZTimeHelper.UtcNow() && ZZTimeHelper.UtcNow() > _data.StartTime;
|
||||
private const string RedPointKey = "event_gather_core.entrance";
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
var model = GContext.container.Resolve<EventGatherCoreData>();
|
||||
if (model == null)
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
return;
|
||||
}
|
||||
_data = model.ToEntranceData();
|
||||
UpdateTimer();
|
||||
Observable.Interval(TimeSpan.FromSeconds(1f)).Subscribe(UpdateTimer).AddTo(this);
|
||||
_loadResourceService = GContext.container.Resolve<ILoadResourceService>();
|
||||
button.onClick.AddListener(EnterActAsync);
|
||||
RedPointManager.Instance.SetRedPointState(RedPointKey, _data.NeedRedPoint);
|
||||
CheckResource(new List<string>() { UITypes.EventGatherCorePanel.Path, EventBingoAct.ActAddressable, _data.Icon });
|
||||
}
|
||||
|
||||
private void UpdateTimer(long _ = 0L)
|
||||
{
|
||||
textTimer.text = ConvertTools.ConvertTime2(RemainingTime);
|
||||
if (!IsActive)
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
private async void EnterActAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
bool isReady = await _loadResourceService.Loads(
|
||||
new List<string>() { UITypes.EventGatherCorePanel.Path, EventBingoAct.ActAddressable });
|
||||
if (isReady)
|
||||
{
|
||||
GContext.Publish(new UnloadActToNextAct { actId = EventGatherCoreAct.ActAddressable, TransitionPanel = UITypes.CloudTransitionPanel });
|
||||
}
|
||||
else
|
||||
{
|
||||
var panel = await UIManager.Instance.ShowUI(UITypes.CloudTransitionPanel);
|
||||
panel.GetComponent<CloudTransitionPanel>()
|
||||
.SetBtn(true, () => GContext.Publish(new UnloadActToNextAct(EventBingoAct.ActAddressable)));
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.Log($"<color=#22a6f2>[EventGatherCore] EnterActError: {e.Message}\n{e.StackTrace}</color>");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnLoadEventResource()
|
||||
{
|
||||
if (IsActive)
|
||||
{
|
||||
GContext.container.Resolve<IUIService>().SetImageSprite(icon, _data.Icon);
|
||||
gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c7c0d016b709b8d4bbe3eb7609dfc768
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
113
Assets/Scripts/EventGatherCore/EventGatherCoreFingerTipCtrl.cs
Normal file
113
Assets/Scripts/EventGatherCore/EventGatherCoreFingerTipCtrl.cs
Normal file
@@ -0,0 +1,113 @@
|
||||
using System.Threading.Tasks;
|
||||
using asap.core;
|
||||
using UnityEngine;
|
||||
|
||||
public class EventGatherCoreFingerTipCtrl : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Animation ani;
|
||||
[SerializeField] private GameObject icon;
|
||||
private EEventCanFingerTipState _state = EEventCanFingerTipState.Init;
|
||||
private float _delay, _countDown;
|
||||
private const string AniLoop = "finger_loop", AniShow = "finger_show", AniEnd = "finger_end";
|
||||
private IEventAggregator _eventAggregator;
|
||||
|
||||
public void Init(float delay, IEventAggregator ea)
|
||||
{
|
||||
_delay = delay;
|
||||
_countDown = 0;
|
||||
_eventAggregator = ea;
|
||||
Hide();
|
||||
_state = EEventCanFingerTipState.Wait;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (_state == EEventCanFingerTipState.Init)
|
||||
return;
|
||||
if (Input.GetMouseButtonDown(0))
|
||||
{
|
||||
switch (_state)
|
||||
{
|
||||
case EEventCanFingerTipState.Wait:
|
||||
_state = EEventCanFingerTipState.Pause;
|
||||
_countDown = 0;
|
||||
break;
|
||||
case EEventCanFingerTipState.Show:
|
||||
Hide();
|
||||
_state = EEventCanFingerTipState.Pause;
|
||||
_countDown = 0;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (Input.GetMouseButtonUp(0))
|
||||
{
|
||||
switch (_state)
|
||||
{
|
||||
case EEventCanFingerTipState.Pause:
|
||||
_state = EEventCanFingerTipState.Wait;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (_state)
|
||||
{
|
||||
case EEventCanFingerTipState.Wait:
|
||||
_countDown += Time.deltaTime;
|
||||
if (_countDown >= _delay)
|
||||
{
|
||||
_state = EEventCanFingerTipState.Show;
|
||||
_eventAggregator.Publish(new EventCatherCoreFingerTipShow());
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum EEventCanFingerTipState
|
||||
{
|
||||
Wait,
|
||||
Pause,
|
||||
Show,
|
||||
Init,
|
||||
}
|
||||
|
||||
public async void Show(MonoBehaviour target)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (target == null)
|
||||
return;
|
||||
transform.position = target.transform.position;
|
||||
ani.Play(AniShow);
|
||||
await Awaiters.NextFrame;
|
||||
ani.Play(AniLoop);
|
||||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
Debug.LogError(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void Hide()
|
||||
{
|
||||
ani.Play(AniEnd);
|
||||
}
|
||||
|
||||
public void HardReset()
|
||||
{
|
||||
if (_state == EEventCanFingerTipState.Show)
|
||||
Hide();
|
||||
_state = EEventCanFingerTipState.Wait;
|
||||
_countDown = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public class EventCatherCoreFingerTipShow { }
|
||||
// public class EventCatherCoreFingerTipHide { }
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 233033fece9908e40b1e572fd87d0505
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,25 @@
|
||||
using UnityEngine;
|
||||
using System.Linq;
|
||||
|
||||
public class EventGatherCoreInfoPanelDummyRewardView : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private RewardItemNew[] rewards;
|
||||
|
||||
public void Awake()
|
||||
{
|
||||
var firstStageId = EventGatherCoreAct.Ctx.GetStageId(0);
|
||||
var rewardDic = EventGatherCoreAct.Ctx.GetRewardViewInfo(firstStageId);
|
||||
for (int i = 0; i < rewards.Length; i++)
|
||||
{
|
||||
if (rewardDic.Keys.Contains(i))
|
||||
{
|
||||
var rewardItem = EventGatherCoreAct.Ctx.GetReward(rewardDic[i].RewardId, out _);
|
||||
rewards[i].SetData(rewardItem);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning($"[EventGatherCore] Reward index mismatch: \"{i}\" not found in dictionary keys.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d23e0bad4145b8b4a85efd03c48b8eb8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
265
Assets/Scripts/EventGatherCore/EventGatherCorePanel.cs
Normal file
265
Assets/Scripts/EventGatherCore/EventGatherCorePanel.cs
Normal file
@@ -0,0 +1,265 @@
|
||||
using System.Linq;
|
||||
using asap.core;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using game;
|
||||
using UniRx;
|
||||
using TMPro;
|
||||
using GameCore;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using System;
|
||||
using Game;
|
||||
|
||||
public class EventGatherCorePanel : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Button btnClose, btnInfo, btnTicket;
|
||||
[SerializeField] private EventGatherCoreTriggerView[] triggers;
|
||||
[SerializeField] private EventGatherCoreRewardView[] rewards;
|
||||
[SerializeField] private EventGatherCoreTaskView task;
|
||||
[SerializeField] private TMP_Text textTicketCount;
|
||||
[SerializeField] private EventGatherCoreTriggerItemFly fly;
|
||||
[SerializeField] private BingoTimer timer;
|
||||
[SerializeField] private GameObject clickMask;
|
||||
[SerializeField] private DeferredRewardStashButton rewardStashButton;
|
||||
[SerializeField] private GameObject fxStageShift;
|
||||
[SerializeField] private float triggerItemShakeDuration, triggerItemKickDuration, triggerItemFlyDuration, triggerItemHitDuration, fingerTipDelay = 3f;
|
||||
[SerializeField] private EventGatherCoreFingerTipCtrl _fingerTipCtrl;
|
||||
private IEventAggregator _eventAggregator;
|
||||
private readonly string SfxHit = "audio_ui_gathercorefootball_reward_hit";
|
||||
|
||||
private void Start()
|
||||
{
|
||||
GContext.container.Resolve<GuideDataCenter>().InspectTriggerGuide("EventGatherCoreFootballPanel");
|
||||
}
|
||||
|
||||
public void Init(IEventAggregator eventAggregator)
|
||||
{
|
||||
var data = GContext.container.Resolve<EventGatherCoreData>();
|
||||
btnClose.onClick.AddListener(OnClickClose);
|
||||
btnInfo.onClick.AddListener(OnClickInfo);
|
||||
btnTicket.onClick.AddListener(OnClickPack);
|
||||
_eventAggregator = eventAggregator;
|
||||
InitPanel();
|
||||
_eventAggregator.GetEvent<EventGatherCoreTriggerTaken>().Subscribe(OnTrigger).AddTo(this);
|
||||
_eventAggregator.GetEvent<EventGatherCoreRewardPopupPanelClose>().Subscribe(OnRewardPopupPanelClose).AddTo(this);
|
||||
GContext.OnEvent<ResAddEvent>().Subscribe(OnTicketUpdata).AddTo(this);
|
||||
GContext.OnEvent<EventTicketUpdate>().Subscribe(_ => UpdateTicketCount()).AddTo(this);
|
||||
var chainPackData = data.ToChainPackData();
|
||||
RedPointManager.Instance.SetRedPointState(chainPackData.RedPointKey, chainPackData.DoNeedPackRedPoint);
|
||||
_fingerTipCtrl.Init(fingerTipDelay, _eventAggregator);
|
||||
_eventAggregator.GetEvent<EventCatherCoreFingerTipShow>().Subscribe(e => _fingerTipCtrl.Show(GetRandomActiveTriggerView())).AddTo(this);
|
||||
}
|
||||
|
||||
private void OnClickClose()
|
||||
{
|
||||
GContext.Publish(new UnloadActToNextAct());
|
||||
}
|
||||
|
||||
private void InitPanel()
|
||||
{
|
||||
var data = GContext.container.Resolve<EventGatherCoreData>();
|
||||
var stageData = data.StageData;
|
||||
if (stageData.IsStageCleared(EventGatherCoreAct.Ctx))
|
||||
data.MoveToNextStage();
|
||||
for (int i = 0; i < triggers.Length; i++)
|
||||
triggers[i].Init(i, stageData.IsTriggerUsed(i), fly.showDuration, _eventAggregator);
|
||||
var rewardDic = EventGatherCoreAct.Ctx.GetRewardViewInfo(stageData.StageId);
|
||||
for (int i = 0; i < rewards.Length; i++)
|
||||
{
|
||||
var rewardDisplayInfo = new EventGatherCoreRewardInfo();
|
||||
if (rewardDic.Keys.Contains(i))
|
||||
rewardDisplayInfo.ItemData = EventGatherCoreAct.Ctx.GetReward(rewardDic[i].RewardId, out rewardDisplayInfo.IsSpecial);
|
||||
else
|
||||
rewardDisplayInfo.ItemData = null;
|
||||
rewardDisplayInfo.Idx = rewardDic[i].RewardIndex;
|
||||
rewardDisplayInfo.IsClaimed = stageData.IsRewardClaimed(rewardDic[i].RewardIndex);
|
||||
rewards[i].Init(rewardDisplayInfo, fly, SfxHit);
|
||||
}
|
||||
task.Init(stageData.CoreItemReceivedCount,
|
||||
EventGatherCoreAct.Ctx.GetCoreItemCollectionReward(stageData.StageId));
|
||||
UpdateTicketCount();
|
||||
var timerData = data.ToTimerContext(OnClickClose);
|
||||
timer.Init(timerData);
|
||||
fxStageShift.SetActive(false);
|
||||
}
|
||||
|
||||
private async void OnTrigger(EventGatherCoreTriggerTaken e)
|
||||
{
|
||||
if (!e.Succeeded)
|
||||
{
|
||||
OnClickPack();
|
||||
return;
|
||||
}
|
||||
BlockInput();
|
||||
UpdateTicketCount();
|
||||
var data = GContext.container.Resolve<EventGatherCoreData>();
|
||||
var stageData = data.StageData;
|
||||
var ctx = EventGatherCoreAct.Ctx;
|
||||
var rewardView = rewards.FirstOrDefault(x => x.RewardIndex == e.RewardIdx);
|
||||
var reward = ctx.GetReward(e.RewardId, out _);
|
||||
await rewardView.OnTriggerAsync(e.Position, triggerItemShakeDuration, triggerItemKickDuration, triggerItemFlyDuration, triggerItemHitDuration);
|
||||
if (ctx.IsCoreItem(e.RewardId))
|
||||
{
|
||||
_fingerTipCtrl.HardReset();
|
||||
await task.OnTriggerAsync(reward.id, rewardView.RewardIcon.rect.width, rewardView.RewardIcon.position);
|
||||
if (!stageData.IsStageCleared(EventGatherCoreAct.Ctx))
|
||||
{
|
||||
UnblockInput();
|
||||
return;
|
||||
}
|
||||
EventGatherCoreSystem.GrantTaskReward(
|
||||
EventGatherCoreAct.Ctx.GetCoreItemCollectionRewardDropId(data.StageData.StageId),
|
||||
stageData.GetRemainingRewardIds());
|
||||
var tcs = new TaskCompletionSource<bool>();
|
||||
var panel = (await UIManager.Instance.ShowUINotLoading(UITypes.EventGatherCoreRewardPopupPanel)).GetComponent<EventGatherCoreRewardPopupPanel>();
|
||||
panel.Init(ctx.GetCoreItemCollectionReward(stageData.StageId), _eventAggregator, tcs);
|
||||
await tcs.Task;
|
||||
await CollectRemainingRewards();
|
||||
data.MoveToNextStage();
|
||||
if (data.StageData.StageId == ctx.GetStageId(0))
|
||||
OnClickClose();
|
||||
else
|
||||
RefreshPanel();
|
||||
_fingerTipCtrl.HardReset();
|
||||
}
|
||||
else
|
||||
{
|
||||
GContext.Publish(new EventRewardFlyStashRequest(reward, rewardView.RewardIcon, true, rewardView.Text));
|
||||
}
|
||||
UnblockInput();
|
||||
}
|
||||
|
||||
private async void RefreshPanel()
|
||||
{
|
||||
var data = GContext.container.Resolve<EventGatherCoreData>();
|
||||
var stageData = data.StageData;
|
||||
UpdateTicketCount();
|
||||
var transitionPanel = await UIManager.Instance.ShowUI(UITypes.CloudTransitionPanel);
|
||||
await Task.Delay(TimeSpan.FromSeconds(0.8f));
|
||||
transitionPanel.GetComponent<CloudTransitionPanel>().EndTransition(new EndTransition());
|
||||
fxStageShift.SetActive(false);
|
||||
fxStageShift.SetActive(true);
|
||||
for (int i = 0; i < triggers.Length; i++)
|
||||
triggers[i].Set(stageData.IsTriggerUsed(i));
|
||||
var rewardDic = EventGatherCoreAct.Ctx.GetRewardViewInfo(stageData.StageId);
|
||||
for (int i = 0; i < rewards.Length; i++)
|
||||
{
|
||||
var rewardDisplayInfo = new EventGatherCoreRewardInfo();
|
||||
if (rewardDic.Keys.Contains(i))
|
||||
rewardDisplayInfo.ItemData = EventGatherCoreAct.Ctx.GetReward(rewardDic[i].RewardId, out rewardDisplayInfo.IsSpecial);
|
||||
else
|
||||
rewardDisplayInfo.ItemData = null;
|
||||
rewardDisplayInfo.Idx = rewardDic[i].RewardIndex;
|
||||
rewardDisplayInfo.IsClaimed = stageData.IsRewardClaimed(i);
|
||||
rewards[i].Set(rewardDisplayInfo);
|
||||
}
|
||||
task.RefreshView(EventGatherCoreAct.Ctx.GetCoreItemCollectionReward(stageData.StageId));
|
||||
}
|
||||
|
||||
private void UpdateTicketCount()
|
||||
{
|
||||
var n = GContext.container.Resolve<EventGatherCoreData>().TicketCount;
|
||||
textTicketCount.text = n.ToString();
|
||||
textTicketCount.color = n > 0 ? Color.white : Color.red;
|
||||
}
|
||||
|
||||
private async void OnClickInfo()
|
||||
{
|
||||
try
|
||||
{
|
||||
await UIManager.Instance.ShowUINotLoading(UITypes.EventGatherCoreInfoPanel);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.Log($"[EventGatherCore]{e.Message}\n{e.StackTrace}");
|
||||
}
|
||||
}
|
||||
|
||||
private async Task CollectRemainingRewards()
|
||||
{
|
||||
try
|
||||
{
|
||||
var tasks = new List<Task>();
|
||||
var stageId = GContext.container.Resolve<EventGatherCoreData>().StageData.StageId;
|
||||
var targetViewList = new List<EventGatherCoreRewardView>();
|
||||
GContext.Publish(new EventUISound(SfxHit));
|
||||
foreach (var rewardView in rewards.Where(x => !x.IsClaimed))
|
||||
{
|
||||
rewardView.SetReceived();
|
||||
targetViewList.Add(rewardView);
|
||||
}
|
||||
if (targetViewList.Count <= 0)
|
||||
return;
|
||||
await Task.Delay(TimeSpan.FromSeconds(triggerItemHitDuration));
|
||||
foreach (var rewardView in targetViewList)
|
||||
{
|
||||
var item = EventGatherCoreAct.Ctx.GetRewardByIndex(rewardView.RewardIndex, stageId);
|
||||
tasks.Add(rewardStashButton.OnRewardFlyRequestAsync(
|
||||
new EventRewardFlyStashRequest(item, rewardView.RewardIcon)));
|
||||
}
|
||||
await Task.WhenAll(tasks);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.Log($"[EventGatherCore]{e.Message}\n{e.StackTrace}");
|
||||
}
|
||||
}
|
||||
|
||||
private async void OnClickPack()
|
||||
{
|
||||
var chainData = GContext.container.Resolve<EventGatherCoreData>().ToChainPackData();
|
||||
if (chainData.IsChainPackDepleted)
|
||||
{
|
||||
var normalPanel = (await UIManager.Instance.ShowUINotLoading(UITypes.EventGatherCoreNormalPackPanel))
|
||||
.GetComponent<GeneralEventNormalPackPanel>();
|
||||
normalPanel.Init(EventGatherCoreAct.Ctx.GetNormalPackInfo());
|
||||
}
|
||||
else
|
||||
{
|
||||
var chainPanel = (await UIManager.Instance.ShowUINotLoading(UITypes.EventGatherCoreChainPackPanel))
|
||||
.GetComponent<ChainPackPanel>();
|
||||
chainPanel.Init(chainData);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTicketUpdata(ResAddEvent e)
|
||||
{
|
||||
if (e.id != EventGatherCoreAct.Ctx.GetTicketItemId())
|
||||
return;
|
||||
UpdateTicketCount();
|
||||
}
|
||||
|
||||
public /* async */ void BlockInput()
|
||||
{
|
||||
try
|
||||
{
|
||||
clickMask.SetActive(true);
|
||||
// Debug.Log($"[EventGatherCore] Block.");
|
||||
// await Task.Delay(TimeSpan.FromSeconds(15f));
|
||||
// UnblockInput();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.Log($"[EventGatherCore] Block error.");
|
||||
Debug.LogError(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void UnblockInput()
|
||||
{
|
||||
clickMask.SetActive(false);
|
||||
// Debug.Log($"[EventGatherCore] Unblock.");
|
||||
}
|
||||
|
||||
public void OnRewardPopupPanelClose(EventGatherCoreRewardPopupPanelClose e)
|
||||
{
|
||||
// RefreshPanel();
|
||||
}
|
||||
|
||||
public EventGatherCoreTriggerView GetRandomActiveTriggerView()
|
||||
{
|
||||
var activeList = triggers.Where(x => x.gameObject.activeSelf).ToList();
|
||||
return activeList.Count > 0 ? activeList[UnityEngine.Random.Range(0, activeList.Count)] : null;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/EventGatherCore/EventGatherCorePanel.cs.meta
Normal file
11
Assets/Scripts/EventGatherCore/EventGatherCorePanel.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 06672a178c7b66f48a955fa97fc28fb4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,54 @@
|
||||
using GameCore;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using asap.core;
|
||||
using System.Threading.Tasks;
|
||||
using System;
|
||||
|
||||
public class EventGatherCoreRewardPopupPanel : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Button btnClose;
|
||||
[SerializeField] private RewardItemNew[] rewardDisplayList;
|
||||
private IEventAggregator _eventAggregator;
|
||||
private ItemData _reward;
|
||||
private TaskCompletionSource<bool> _tcs;
|
||||
private const float RewardFlyDuration = 1.4f;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
btnClose.onClick.AddListener(OnClickClose);
|
||||
}
|
||||
|
||||
public void Init(ItemData rewards, IEventAggregator eventAggregator, TaskCompletionSource<bool> tcs )
|
||||
{
|
||||
_eventAggregator = eventAggregator;
|
||||
int i;
|
||||
rewardDisplayList[0].SetData(rewards);
|
||||
rewardDisplayList[0].gameObject.SetActive(true);
|
||||
for (i = 1; i < rewardDisplayList.Length; i++)
|
||||
{
|
||||
rewardDisplayList[i].gameObject.SetActive(false);
|
||||
i++;
|
||||
}
|
||||
_reward = rewards;
|
||||
_tcs = tcs;
|
||||
}
|
||||
|
||||
private async void OnClickClose()
|
||||
{
|
||||
try
|
||||
{
|
||||
btnClose.gameObject.SetActive(false);
|
||||
_ = rewardDisplayList[0].ParticleAttractor();
|
||||
await Task.Delay(TimeSpan.FromSeconds(RewardFlyDuration));
|
||||
_eventAggregator.Publish(new EventGatherCoreRewardPopupPanelClose() { Reward = _reward });
|
||||
_tcs.SetResult(true);
|
||||
UIManager.Instance.DestroyUI(UITypes.EventGatherCoreRewardPopupPanel);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogError("[EventGatherCore] reward panel error.");
|
||||
Debug.LogError(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e8e44839e60d0fa49bacf3114a94105a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
82
Assets/Scripts/EventGatherCore/EventGatherCoreRewardView.cs
Normal file
82
Assets/Scripts/EventGatherCore/EventGatherCoreRewardView.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
using asap.core;
|
||||
using Game;
|
||||
using UnityEngine;
|
||||
|
||||
public class EventGatherCoreRewardView : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private RewardItemNew reward;
|
||||
[SerializeField] private GameObject backgroundNormal, backgroundSpecial, fxHit;
|
||||
public RectTransform RewardIcon => reward.icon.rectTransform;
|
||||
public RectTransform Text => reward.text_num.rectTransform;
|
||||
private EventGatherCoreTriggerItemFly _flyingTrigger;
|
||||
private int _idx;
|
||||
public int RewardIndex => _idx;
|
||||
private int _id;
|
||||
public int RewardId => _id;
|
||||
public bool IsClaimed => reward.received.activeSelf;
|
||||
private string _sfxHit;
|
||||
|
||||
public void Init(EventGatherCoreRewardInfo info, EventGatherCoreTriggerItemFly fly, string audioUrl)
|
||||
{
|
||||
_idx = info.Idx;
|
||||
if (info.ItemData != null)
|
||||
reward.SetData(info.ItemData);
|
||||
else
|
||||
reward.gameObject.SetActive(false);
|
||||
backgroundSpecial.SetActive(info.IsSpecial);
|
||||
backgroundNormal.SetActive(!info.IsSpecial);
|
||||
reward.SetReceived(info.IsClaimed);
|
||||
_flyingTrigger = fly;
|
||||
fxHit.SetActive(false);
|
||||
_sfxHit = audioUrl;
|
||||
}
|
||||
|
||||
public void Set(EventGatherCoreRewardInfo info)
|
||||
{
|
||||
_idx = info.Idx;
|
||||
if (info.ItemData != null)
|
||||
reward.SetData(info.ItemData);
|
||||
else
|
||||
reward.gameObject.SetActive(false);
|
||||
backgroundSpecial.SetActive(info.IsSpecial);
|
||||
backgroundNormal.SetActive(!info.IsSpecial);
|
||||
reward.gameObject.SetActive(!info.IsClaimed);
|
||||
fxHit.SetActive(false);
|
||||
}
|
||||
|
||||
public async System.Threading.Tasks.Task OnTriggerAsync(Vector2 position, float triggerItemShakeDuration,
|
||||
float triggerItemKickDuration, float triggerItemFlyDuration, float triggerItemHitDuration)
|
||||
{
|
||||
var itemFly = new CollectionItemFly
|
||||
{
|
||||
iconName = "sp_football_ball",
|
||||
numStr = "",
|
||||
targetIconSize = reward.icon.rectTransform.rect.width,
|
||||
sourcePos = position,
|
||||
destPos = reward.icon.transform.position,
|
||||
isPlayOpen = false,
|
||||
isPlayClose = false,
|
||||
};
|
||||
var flyingItem = Instantiate(_flyingTrigger.gameObject, transform.parent).GetComponent<EventGatherCoreTriggerItemFly>();
|
||||
flyingItem.gameObject.SetActive(true);
|
||||
// Debug.Log("[EventGatherCore] 1: shake.");
|
||||
await System.Threading.Tasks.Task.Delay(System.TimeSpan.FromSeconds(triggerItemShakeDuration));
|
||||
// Debug.Log("[EventGatherCore] 2: kick.");
|
||||
flyingItem.showDuration = triggerItemKickDuration;
|
||||
flyingItem.flyDuration = triggerItemFlyDuration;
|
||||
await flyingItem.ShowAsync(itemFly);
|
||||
Destroy(flyingItem.gameObject);
|
||||
fxHit.SetActive(true);
|
||||
GContext.Publish(new EventUISound(_sfxHit));
|
||||
// Debug.Log("[EventGatherCore] 4: Hit.");
|
||||
await System.Threading.Tasks.Task.Delay(System.TimeSpan.FromSeconds(triggerItemHitDuration));
|
||||
// Debug.Log("[EventGatherCore] 5: Reward.");
|
||||
reward.SetReceived(true);
|
||||
}
|
||||
|
||||
public void SetReceived()
|
||||
{
|
||||
fxHit.SetActive(true);
|
||||
reward.SetReceived(true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4fb6848ad92fc8944bd8874a739f34c6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
99
Assets/Scripts/EventGatherCore/EventGatherCoreSystem.cs
Normal file
99
Assets/Scripts/EventGatherCore/EventGatherCoreSystem.cs
Normal file
@@ -0,0 +1,99 @@
|
||||
using System.Linq;
|
||||
using asap.core;
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
using GameCore;
|
||||
|
||||
public static class EventGatherCoreSystem
|
||||
{
|
||||
public readonly static int Cost = 1;
|
||||
public static int PickRandomRewardIdx()
|
||||
{
|
||||
var stage = GContext.container.Resolve<EventGatherCoreData>().StageData;
|
||||
var ctx = EventGatherCoreAct.Ctx;
|
||||
var rewardIds = stage.RewardIdList;
|
||||
var weightList = rewardIds
|
||||
.Select((id, idx) =>
|
||||
!stage.IsRewardClaimed(idx) &&
|
||||
!IsDoomed(id) &&
|
||||
ctx.TryGetRewardWeight(id, out var weight) ? weight : 0)
|
||||
.ToList();
|
||||
var idx = FtMathUtils.GetRandomIdxFromWeightList(weightList);
|
||||
return idx;
|
||||
}
|
||||
|
||||
private static bool IsDoomed(int rewardId)
|
||||
{
|
||||
var stage = GContext.container.Resolve<EventGatherCoreData>().StageData;
|
||||
var ctx = EventGatherCoreAct.Ctx;
|
||||
return stage.IsEarlyTry(ctx) && stage.IsCloseToFinish(ctx) && ctx.IsCoreItem(rewardId);
|
||||
}
|
||||
|
||||
public static void GrantRewards(int rewardId)
|
||||
{
|
||||
var rewardItem = EventGatherCoreAct.Ctx.GetReward(rewardId, out _);
|
||||
if (rewardItem == null)
|
||||
return;
|
||||
if (!EventGatherCoreAct.Ctx.IsCoreItem(rewardId))
|
||||
GContext.Publish(new DeferredRewardStashService.EventStashItem { Item = rewardItem });
|
||||
}
|
||||
|
||||
public static void GrantTaskReward(int taskDropId, List<int> remainingRewardIds)
|
||||
{
|
||||
GContext.Publish(new DeferredRewardStashService.EventStashDrop { DropId = taskDropId});
|
||||
if (remainingRewardIds != null)
|
||||
foreach (var rewardId in remainingRewardIds)
|
||||
GrantRewards(rewardId);
|
||||
}
|
||||
|
||||
public static bool Draw(int triggerIdx, out int rewardIdx, out int rewardId)
|
||||
{
|
||||
int evRoundCount, evStageCount, evPlayCount, evRewardId, evRewardCount, evEndOfStage, evCombineId;
|
||||
rewardId = 0;
|
||||
rewardIdx = 0;
|
||||
var data = GContext.container.Resolve<EventGatherCoreData>();
|
||||
if (data.TicketCount <= 0)
|
||||
{
|
||||
Debug.Log("[EventGatherCore]Insufficient tickets");
|
||||
return false;
|
||||
}
|
||||
data.AddTicket(-Cost);
|
||||
rewardIdx = PickRandomRewardIdx();
|
||||
data.StageData.SetTriggerUsed(triggerIdx);
|
||||
data.StageData.SetRewardClaimed(rewardIdx);
|
||||
var ctx = EventGatherCoreAct.Ctx;
|
||||
data.Save();
|
||||
evRoundCount = data.StageCount / ctx.GetTotalStageCount() + 1;
|
||||
evStageCount = data.StageCount % ctx.GetTotalStageCount() + 1;
|
||||
evPlayCount = data.StageData.PlayCount;
|
||||
rewardId = data.StageData.RewardIdList[rewardIdx];
|
||||
var rewardItem = EventGatherCoreAct.Ctx.GetReward(rewardId, out _);
|
||||
GrantRewards(rewardId);
|
||||
evRewardId = rewardItem.id;
|
||||
evRewardCount = rewardItem.count;
|
||||
evEndOfStage = data.StageData.IsStageCleared(ctx)? 1 : 0;
|
||||
evCombineId = evRoundCount * 10000 + evStageCount * 100 + evPlayCount;
|
||||
// Debug.Log($"<color=red>[EventGatherCore] -------------------Event Tracking---------------------</color>");
|
||||
// Debug.Log($"[EventGatherCore] round: {evRoundCount}");
|
||||
// Debug.Log($"[EventGatherCore] stage: {evStageCount}");
|
||||
// Debug.Log($"[EventGatherCore] count: {evPlayCount}");
|
||||
// Debug.Log($"[EventGatherCore] item_id: {evRewardId}");
|
||||
// Debug.Log($"[EventGatherCore] item_count: {evRewardCount}");
|
||||
// Debug.Log($"[EventGatherCore] is_done: {evEndOfStage}");
|
||||
// Debug.Log($"[EventGatherCore] combine_id: {evCombineId}");
|
||||
// Debug.Log($"[EventGatherCore] -------------------End of Event Tracking---------------------");
|
||||
#if AGG
|
||||
using (var e = GEvent.GameEvent("event_gathercore"))
|
||||
{
|
||||
e.AddContent("round", evRoundCount)
|
||||
.AddContent("stage", evStageCount)
|
||||
.AddContent("count", evPlayCount)
|
||||
.AddContent("item_id", evRewardId)
|
||||
.AddContent("item_count", evRewardCount)
|
||||
.AddContent("is_done", evEndOfStage)
|
||||
.AddContent("combine_id", evCombineId);
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/EventGatherCore/EventGatherCoreSystem.cs.meta
Normal file
11
Assets/Scripts/EventGatherCore/EventGatherCoreSystem.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3bc996ec087d7154d90d69136aaa95ee
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
339
Assets/Scripts/EventGatherCore/EventGatherCoreTableContext.cs
Normal file
339
Assets/Scripts/EventGatherCore/EventGatherCoreTableContext.cs
Normal file
@@ -0,0 +1,339 @@
|
||||
using cfg;
|
||||
using asap.core;
|
||||
using GameCore;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System.Linq;
|
||||
using UnityEngine.Assertions;
|
||||
using System;
|
||||
|
||||
public class EventGatherCoreTableContext
|
||||
{
|
||||
private FishingEvent _tableEvent;
|
||||
private EventGatherCoreMain _tableMain;
|
||||
private PlayerItemData _playerItemData;
|
||||
private FishingEventCycleItem2 _tableCycle;
|
||||
private TbEventGatherCoreStage _tableStages;
|
||||
private TbEventGatherCoreReward _tableRewards;
|
||||
public const int CoreItemIndicator = -1;
|
||||
|
||||
public static EventGatherCoreTableContext ReadTables(int eventId)
|
||||
{
|
||||
var ctx = new EventGatherCoreTableContext();
|
||||
var tables = GContext.container.Resolve<Tables>();
|
||||
var redirectId = tables.TbFishingEvent[eventId].RedirectID;
|
||||
var cycleId = tables.TbFishingEventCycleItem2[redirectId].RedirectID;
|
||||
ctx._tableEvent = tables.TbFishingEvent[eventId];
|
||||
ctx._tableMain = tables.TbEventGatherCoreMain[cycleId];
|
||||
ctx._tableCycle = tables.TbFishingEventCycleItem2[cycleId];
|
||||
ctx._playerItemData = GContext.container.Resolve<PlayerItemData>();
|
||||
ctx._tableStages = tables.TbEventGatherCoreStage;
|
||||
ctx._tableRewards = tables.TbEventGatherCoreReward;
|
||||
return ctx;
|
||||
}
|
||||
|
||||
public static EventGatherCoreTableContext GetTestSample()
|
||||
{
|
||||
var ctx = new EventGatherCoreTableContext();
|
||||
var tables = GContext.container.Resolve<Tables>();
|
||||
// var redirectId = 70101;
|
||||
// var cycleId = tables.TbFishingEventCycleItem3[redirectId].RedirectID;
|
||||
var cycleId = 70501;
|
||||
ctx._tableEvent = null;
|
||||
ctx._tableMain = tables.TbEventGatherCoreMain[cycleId];
|
||||
ctx._tableCycle = tables.TbFishingEventCycleItem2[cycleId];
|
||||
ctx._playerItemData = GContext.container.Resolve<PlayerItemData>();
|
||||
ctx._tableStages = tables.TbEventGatherCoreStage;
|
||||
ctx._tableRewards = tables.TbEventGatherCoreReward;
|
||||
return ctx;
|
||||
}
|
||||
|
||||
public List<ItemData> GetRewardDataList(int stageId)
|
||||
{
|
||||
if (!_tableStages.DataMap.TryGetValue(stageId, out var stage))
|
||||
{
|
||||
Debug.Log($"[EventGatherCore]Stage id {stageId} not found.");
|
||||
return new List<ItemData>();
|
||||
}
|
||||
return stage.RewardList.Select(x =>
|
||||
{
|
||||
if (!_tableRewards.DataMap.TryGetValue(x, out var reward))
|
||||
{
|
||||
Debug.Log($"[EventGatherCore]Reward id {x} not found.");
|
||||
return null;
|
||||
}
|
||||
return GetReward(reward.Item, reward.Number);
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
public List<int> GetRewardIdList(int stageId)
|
||||
{
|
||||
if (!_tableStages.DataMap.TryGetValue(stageId, out var stage))
|
||||
{
|
||||
Debug.Log($"[EventGatherCore]Stage id {stageId} not found.");
|
||||
return new List<int>();
|
||||
}
|
||||
return stage.RewardList;
|
||||
}
|
||||
|
||||
private ItemData GetReward(int id, int count)
|
||||
{
|
||||
if (id == CoreItemIndicator)
|
||||
id = _tableMain.CoreItem;
|
||||
if (id == 0 || count == 0)
|
||||
return null;
|
||||
return new ItemData(id, count);
|
||||
}
|
||||
|
||||
public ItemData GetReward(int rewardId, out bool isSpecial)
|
||||
{
|
||||
isSpecial = false;
|
||||
if (!_tableRewards.DataMap.TryGetValue(rewardId, out var reward))
|
||||
{
|
||||
Debug.Log($"[EventGatherCore] No table data found for reward id {rewardId}");
|
||||
return null;
|
||||
}
|
||||
isSpecial = reward.IsSpecial == 1;
|
||||
var id = reward.Item;
|
||||
var count = reward.Number;
|
||||
return GetReward(id, count);
|
||||
}
|
||||
|
||||
public ItemData GetRewardByIndex(int rewardIdx, int stageId)
|
||||
{
|
||||
var rewardIdList = GetRewardIdList(stageId);
|
||||
var id = rewardIdList[rewardIdx];
|
||||
return GetReward(id, out _);
|
||||
}
|
||||
|
||||
public int GetCoreItemTargetCount(int stageId)
|
||||
{
|
||||
var stage = _tableStages[stageId];
|
||||
// return Mathf.Min(stage.RewardList.Where(x => IsCoreItem(x)).Count(), stage.CoreItemNum);
|
||||
return stage.CoreItemNum;
|
||||
}
|
||||
|
||||
public bool IsCoreItem(int rewardId)
|
||||
{
|
||||
return _tableRewards.DataMap.TryGetValue(rewardId, out var reward) && reward.Item == CoreItemIndicator;
|
||||
}
|
||||
|
||||
public bool TryGetRewardWeight(int rewardId, out int weight)
|
||||
{
|
||||
var res = _tableRewards.DataMap.TryGetValue(rewardId, out var reward);
|
||||
weight = res ? reward.Weight : 0;
|
||||
if (!res)
|
||||
Debug.Log($"[EventGatherCore] No table data found for reward id {rewardId}");
|
||||
return res;
|
||||
}
|
||||
|
||||
public List<int> GetStageInfo(int stageId)
|
||||
{
|
||||
if (!_tableStages.DataMap.TryGetValue(stageId, out var stage))
|
||||
{
|
||||
Debug.Log($"[EventGatherCore] No table data found for stage id {stageId}");
|
||||
return new List<int>();
|
||||
}
|
||||
return stage.RewardList;
|
||||
}
|
||||
|
||||
public int GetStageId(int roundCount)
|
||||
{
|
||||
var idx = roundCount % _tableMain.StageList.Count;
|
||||
var stageId = _tableMain.StageList[idx];
|
||||
return stageId;
|
||||
}
|
||||
|
||||
public int GetStageMinAttemptCount(int stageId)
|
||||
{
|
||||
if (!_tableStages.DataMap.TryGetValue(stageId, out var stage))
|
||||
{
|
||||
Debug.Log($"[EventGatherCore] No table data found for stage id {stageId}");
|
||||
return 0;
|
||||
}
|
||||
return stage.MinAttempts;
|
||||
}
|
||||
|
||||
public Dictionary<int, (int RewardId, int RewardIndex)> GetRewardViewInfo(int stageId)
|
||||
{
|
||||
if (!_tableStages.DataMap.TryGetValue(stageId, out var stage))
|
||||
{
|
||||
Debug.Log($"[EventGatherCore] No table data found for stage id {stageId}");
|
||||
return new Dictionary<int, (int, int)>();
|
||||
}
|
||||
|
||||
var rng = new System.Random(0);
|
||||
var res = new Dictionary<int, (int RewardId, int RewardIndex)>();
|
||||
var rewardIdList = stage.RewardList;
|
||||
var displayTileList = stage.TileList;
|
||||
var specialTileList = stage.SpecialTile.OrderBy(x => rng.Next()).ToList();
|
||||
var normalTileList = displayTileList.Where(x => !specialTileList.Contains(x)).OrderBy(x => rng.Next()).ToList();
|
||||
// foreach (var id in displayTileList)
|
||||
// {
|
||||
// Debug.Log($"[EventGatherCore] Display Reward id {id}.");
|
||||
// }
|
||||
// foreach (var id in specialTileList)
|
||||
// {
|
||||
// Debug.Log($"[EventGatherCore] Special Reward id {id}.");
|
||||
// }
|
||||
// foreach (var id in normalTileList)
|
||||
// {
|
||||
// Debug.Log($"[EventGatherCore] Normal Reward id {id}.");
|
||||
// }
|
||||
Assert.IsTrue(rewardIdList.Count == displayTileList.Count,
|
||||
$"[EventGatherCore] Reward list count does not match tile list count for stage id {stageId}.");
|
||||
Assert.IsTrue(rewardIdList.Where(x => IsRewardIdSpecial(x)).Count() == specialTileList.Count,
|
||||
$"[EventGatherCore] Special Reward list count does not match special tile list count for stage id {stageId}.");
|
||||
|
||||
for (int i = 0; i < stage.RewardList.Count; i++)
|
||||
{
|
||||
var id = rewardIdList[i];
|
||||
int specialTile = 0;
|
||||
int normalTile = 0;
|
||||
if (specialTileList.Count > 0)
|
||||
specialTile = specialTileList.Last();
|
||||
if (normalTileList.Count > 0)
|
||||
normalTile = normalTileList.Last();
|
||||
(int, int) tp = (id, i);
|
||||
if (IsRewardIdSpecial(id))
|
||||
{
|
||||
// Debug.Log($"[EventGatherCore] special: {id}.");
|
||||
res.Add(specialTile - 1, tp);
|
||||
specialTileList.RemoveAt(specialTileList.Count - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Debug.Log($"[EventGatherCore] normal: {id}.");
|
||||
res.Add(normalTile - 1, tp);
|
||||
normalTileList.RemoveAt(normalTileList.Count - 1);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public ItemData GetCoreItemCollectionReward(int stageId)
|
||||
{
|
||||
if (!_tableStages.DataMap.TryGetValue(stageId, out var stage))
|
||||
{
|
||||
Debug.Log($"[EventGatherCore] No table data found for stage id {stageId}");
|
||||
return null;
|
||||
}
|
||||
var dropId = stage.CoreReward;
|
||||
return _playerItemData.GetItemDataByDropId(dropId)[0];
|
||||
}
|
||||
|
||||
public int GetCoreItemCollectionRewardDropId(int stageId)
|
||||
{
|
||||
if (!_tableStages.DataMap.TryGetValue(stageId, out var stage))
|
||||
{
|
||||
Debug.Log($"[EventGatherCore] No table data found for stage id {stageId}");
|
||||
return 0;
|
||||
}
|
||||
return stage.CoreReward;
|
||||
}
|
||||
|
||||
public int GetWelcomeGift()
|
||||
{
|
||||
return _tableCycle.WelcomeGift;
|
||||
}
|
||||
|
||||
public Tuple<DateTime, DateTime> GetEventStartTimeAndEndTime()
|
||||
{
|
||||
try
|
||||
{
|
||||
var et = DateTime.Parse((_tableEvent.TimeDefinition as LimitedTime).EndTime);
|
||||
var st = DateTime.Parse((_tableEvent.TimeDefinition as LimitedTime).StartTime);
|
||||
return new Tuple<DateTime, DateTime>(st, et);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogError(e);
|
||||
return new Tuple<DateTime, DateTime>(DateTime.MinValue, DateTime.MinValue);
|
||||
}
|
||||
}
|
||||
public string GetEntranceIcon()
|
||||
{
|
||||
return _tableMain.IconEvent;
|
||||
}
|
||||
|
||||
public int GetRedPointThreshold()
|
||||
{
|
||||
return _tableCycle.RedDot;
|
||||
}
|
||||
|
||||
public EventChainPackInfo GetChainPackInfo()
|
||||
{
|
||||
var _tables = GContext.container.Resolve<Tables>();
|
||||
var chainList = _tables.TbEventPackManager[_tableMain.PackId].VIPPackList[0];
|
||||
var expireTime = new DateTime();
|
||||
try
|
||||
{
|
||||
expireTime = DateTime.Parse((_tableEvent.TimeDefinition as LimitedTime).EndTime);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.Log($"[EventGatherCore] {e.Message}\n{e.StackTrace}");
|
||||
return null;
|
||||
}
|
||||
var chainListIdSet = chainList.ToHashSet();
|
||||
var packs = _tables.TbPack.DataList.Where(p => chainListIdSet.Contains(p.ID)).ToArray();//?
|
||||
return new EventChainPackInfo()
|
||||
{
|
||||
ChainList = chainList,
|
||||
ExpireTime = expireTime,
|
||||
Packs = packs,
|
||||
RedPointKey = "event_gather_core.pack"
|
||||
};
|
||||
}
|
||||
|
||||
public GeneralEventNormalPackInfo GetNormalPackInfo()
|
||||
{
|
||||
var expireTime = new DateTime();
|
||||
var _tables = GContext.container.Resolve<Tables>();
|
||||
try
|
||||
{
|
||||
expireTime = DateTime.Parse((_tableEvent.TimeDefinition as LimitedTime).EndTime);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.Log($"[EventGatherCore] {e.Message}\n{e.StackTrace}");
|
||||
return null;
|
||||
}
|
||||
var packList = _tables.TbEventPackManager[_tableMain.PackId2].VIPPackList[0];
|
||||
return new GeneralEventNormalPackInfo
|
||||
{
|
||||
EventId = _tableEvent.ID,
|
||||
PackLeft = _tables.TbPack[packList[0]],
|
||||
PackRight = _tables.TbPack[packList[1]],
|
||||
ExpireTime = expireTime,
|
||||
};
|
||||
}
|
||||
|
||||
public int GetTicketItemId()
|
||||
{
|
||||
return _tableCycle.ItemId;
|
||||
}
|
||||
|
||||
public EventGatherCoreUiData GetUiData()
|
||||
{
|
||||
var uiData = new EventGatherCoreUiData
|
||||
{
|
||||
MainPanelUrl = _tableMain.EventPanel,
|
||||
InfoPanelUrl = _tableMain.InfoPanel,
|
||||
ChainPackPanelUrl = _tableMain.ChainPackPanel,
|
||||
NormalPackPanelUrl = _tableMain.PackPanel,
|
||||
RewardPopupPanelUrl = _tableMain.EventRewardPanel
|
||||
};
|
||||
return uiData;
|
||||
}
|
||||
|
||||
public bool IsRewardIdSpecial(int rewardId)
|
||||
{
|
||||
return _tableRewards.DataMap.TryGetValue(rewardId, out var reward) && reward.IsSpecial == 1;
|
||||
}
|
||||
|
||||
public int GetTotalStageCount()
|
||||
{
|
||||
return _tableMain.StageList.Count;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 22de526602bfb0b4d846f2ff1f522b64
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
75
Assets/Scripts/EventGatherCore/EventGatherCoreTaskView.cs
Normal file
75
Assets/Scripts/EventGatherCore/EventGatherCoreTaskView.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
using UnityEngine;
|
||||
using GameCore;
|
||||
using System.Threading.Tasks;
|
||||
using asap.core;
|
||||
using System;
|
||||
using Castle.Components.DictionaryAdapter.Xml;
|
||||
|
||||
public class EventGatherCoreTaskView : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private GameObject[] targetItems, fxReceivedList;
|
||||
[SerializeField] private RewardItemNew reward;
|
||||
[SerializeField] private RewardFlyBatchController _rewardFlyBatchController;
|
||||
[SerializeField] private Animation ani;
|
||||
// private GameObject CurrentEmptyTarget => targetItems.FirstOrDefault(x => !x.activeSelf);
|
||||
private int CurrentEmptyTargetIdx
|
||||
{
|
||||
get
|
||||
{
|
||||
int i = 0;
|
||||
for (i = 0; i < targetItems.Length; i++)
|
||||
{
|
||||
if (!targetItems[i].activeSelf)
|
||||
return i;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
private GameObject CurrentEmptyTarget => targetItems[CurrentEmptyTargetIdx];
|
||||
private GameObject CurrentReceiveFx => fxReceivedList[CurrentEmptyTargetIdx];
|
||||
private readonly string _full = "target_full", _normal = "target_normal";
|
||||
|
||||
public void Init(int coreItemCount, ItemData rewardItemData)
|
||||
{
|
||||
for (int i = 0; i < targetItems.Length; i++)
|
||||
{
|
||||
targetItems[i].SetActive(i < coreItemCount);
|
||||
fxReceivedList[i].SetActive(false);
|
||||
}
|
||||
reward.SetData(rewardItemData);
|
||||
// _eventAggregator.GetEvent<EventGatherCoreTriggerTaken>()
|
||||
// .Subscribe(OnTrigger).AddTo(this);
|
||||
}
|
||||
|
||||
public async Task OnTriggerAsync(int rewardItemId, float rewardIconSize, Vector3 position)
|
||||
{
|
||||
var request = new BatchedRewardFlyRequest
|
||||
{
|
||||
itemID = rewardItemId,
|
||||
// sourceIconSize = rewardIconSize,
|
||||
// targetIconSize = (CurrentEmptyTarget.transform as RectTransform).rect.width,
|
||||
// sourcePos = position,
|
||||
// destPos = CurrentEmptyTarget.transform.position,
|
||||
StartPoint = new BatchedRewardFlyPoint(position),
|
||||
EndPoint = new BatchedRewardFlyPoint(CurrentEmptyTarget.GetComponent<RectTransform>()),
|
||||
isDestinationRewardStash = false,
|
||||
AnimationParamIndex = 0,
|
||||
sourceTextRt = reward.transform.Find("text_num") as RectTransform
|
||||
};
|
||||
await _rewardFlyBatchController.OnRewardFlyRequestAsync(request);
|
||||
CurrentReceiveFx.SetActive(true);
|
||||
CurrentEmptyTarget.SetActive(true);
|
||||
if (GContext.container.Resolve<EventGatherCoreData>().StageData.IsStageCleared(EventGatherCoreAct.Ctx))
|
||||
{
|
||||
ani.Play(_full);
|
||||
await Task.Delay(TimeSpan.FromSeconds(ani.GetClip(_full).length));
|
||||
}
|
||||
}
|
||||
|
||||
public void RefreshView(ItemData rewardItemData)
|
||||
{
|
||||
for (int i = 0; i < targetItems.Length; i++)
|
||||
targetItems[i].SetActive(false);
|
||||
reward.SetData(rewardItemData);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2ee221e19e6d3e849a3250f9d1ffaea2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
85
Assets/Scripts/EventGatherCore/EventGatherCoreTest.cs
Normal file
85
Assets/Scripts/EventGatherCore/EventGatherCoreTest.cs
Normal file
@@ -0,0 +1,85 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
public class EventGatherCoreTest : MonoBehaviour
|
||||
{
|
||||
/* [SerializeField] private int TotalTestCount = 5000;
|
||||
[SerializeField] private float Interval = 0.0002f;
|
||||
private EventGatherCoreData _data;
|
||||
private EventGatherCoreTableContext _ctx;
|
||||
private void Start()
|
||||
{
|
||||
_data = EventGatherCoreData.CreateNew();
|
||||
_ctx = EventGatherCoreTableContext.GetTestSample();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.T))
|
||||
RunSingleTest();
|
||||
if (Input.GetKeyDown(KeyCode.S))
|
||||
StartCoroutine(RunStatisticTest());
|
||||
}
|
||||
|
||||
private bool RunSingleTest()
|
||||
{
|
||||
var rewardIdx = EventGatherCoreSystem.PickRandomRewardIdx();
|
||||
// Debug.Log($"[EventGatherCore] Draw Reward Idx: {rewardIdx}, Reward Id: {_data.StageData.RewardIdList[rewardIdx]}");
|
||||
_data.StageData.SetRewardClaimed(rewardIdx);
|
||||
var rewardId = _data.StageData.RewardIdList[rewardIdx];
|
||||
if (_ctx.IsCoreItem(rewardId))
|
||||
{
|
||||
// Debug.Log($"[EventGatherCore] {rewardId} is core Item.");
|
||||
_data.StageData.AddCoreItem();
|
||||
}
|
||||
// Debug.Log($"[EventGatherCore] CoreItemCount: {_data.StageData.CoreItemReceivedCount}.");
|
||||
if (_data.StageData.IsStageCleared(_ctx, _data.RoundCount))
|
||||
{
|
||||
Debug.Log($"[EventGatherCore] Stage Cleared.");
|
||||
_data.MoveToNextStage();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private IEnumerator RunStatisticTest()
|
||||
{
|
||||
int i = 0;
|
||||
Dictionary<int, Dictionary<int, int>> res = new Dictionary<int, Dictionary<int, int>>();
|
||||
res[0] = new Dictionary<int, int>();
|
||||
res[1] = new Dictionary<int, int>();
|
||||
res[2] = new Dictionary<int, int>();
|
||||
res[3] = new Dictionary<int, int>();
|
||||
res[4] = new Dictionary<int, int>();
|
||||
Debug.Log($"[EventGatherCore] Running like hell...");
|
||||
yield return new WaitForSeconds(Interval);
|
||||
while (i < TotalTestCount)
|
||||
{
|
||||
var playTimeCount = 1;
|
||||
while (RunSingleTest() == false)
|
||||
{
|
||||
playTimeCount++;
|
||||
}
|
||||
if (res[i % 5].ContainsKey(playTimeCount))
|
||||
res[i % 5][playTimeCount]++;
|
||||
else
|
||||
res[i % 5].Add(playTimeCount, 1);
|
||||
i++;
|
||||
yield return new WaitForSeconds(Interval);
|
||||
}
|
||||
int sum;
|
||||
foreach (var kv in res.OrderBy(x => x.Key))
|
||||
{
|
||||
sum = 0;
|
||||
Debug.Log($"<color=yellow>[EventGatherCore] Stage{kv.Key + 1}: </color>");
|
||||
foreach (var kv2 in kv.Value.OrderBy(x => x.Key))
|
||||
{
|
||||
Debug.Log($"[EventGatherCore] Play Count {kv2.Key}: {kv2.Value}");
|
||||
sum += kv2.Value * kv2.Key;
|
||||
}
|
||||
Debug.Log($"[EventGatherCore] Average: {sum / (float)TotalTestCount * 5}");
|
||||
}
|
||||
}
|
||||
*/}
|
||||
11
Assets/Scripts/EventGatherCore/EventGatherCoreTest.cs.meta
Normal file
11
Assets/Scripts/EventGatherCore/EventGatherCoreTest.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 43e11760a3d56de4c95f9b1aafda1a13
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,68 @@
|
||||
using UnityEngine;
|
||||
using System.Threading.Tasks;
|
||||
using DG.Tweening;
|
||||
|
||||
public class EventGatherCoreTriggerItemFly : RewardFly
|
||||
{
|
||||
public override async Task ShowAsync(CollectionItemFly itemFly)
|
||||
{
|
||||
SetText(itemFly.numStr);
|
||||
if (itemFly.sourceIconSize != 0.0f)
|
||||
{
|
||||
var sourceScale = GetTransitionScale(itemFly.sourceIconSize);
|
||||
iconRoot.transform.localScale = new Vector3(sourceScale, sourceScale, 1f);
|
||||
}
|
||||
if (itemFly.icon != null)
|
||||
{
|
||||
SetData(itemFly.icon);
|
||||
}
|
||||
else if (string.IsNullOrEmpty(itemFly.iconName))
|
||||
{
|
||||
SetData(itemFly.itemID);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetData(itemFly.iconName);
|
||||
}
|
||||
// transform.localScale = itemFly.scale;
|
||||
transform.position = itemFly.sourcePos;
|
||||
fxTrace.SetActive(false);
|
||||
CloseFxRoot();
|
||||
OpenFxRoot();
|
||||
await Awaiters.Seconds(showDuration);
|
||||
SetText("");
|
||||
ShowTrace();
|
||||
transform.DOMoveX(itemFly.destPos.x, flyDuration).SetEase(curveX);
|
||||
transform.DOMoveY(itemFly.destPos.y, flyDuration).SetEase(curveY);
|
||||
var targetScale = GetTransitionScale(itemFly.targetIconSize);
|
||||
iconRoot.transform.DOScale(targetScale, flyDuration).SetEase(curveScale);
|
||||
// Debug.Log("[EventGatherCore] 3: fly.");
|
||||
await Awaiters.Seconds(flyDuration);
|
||||
if (!itemFly.isPlayClose)
|
||||
return;
|
||||
if (itemFly.isDestinationRewardStash)
|
||||
{
|
||||
ani.Play(OUT_STASH);
|
||||
await Awaiters.Seconds(closeAnimationDurationStash);
|
||||
}
|
||||
else
|
||||
{
|
||||
ani.Play(OUT);
|
||||
await Awaiters.Seconds(closeAnimationDuration);
|
||||
}
|
||||
// ShowTrace();
|
||||
}
|
||||
|
||||
private void OpenFxRoot()
|
||||
{
|
||||
if (transform.position.x < 0f)
|
||||
fxRoot.transform.rotation = Quaternion.Euler(180, 0, 180);
|
||||
else
|
||||
fxRoot.transform.rotation = Quaternion.identity;
|
||||
fxRoot.SetActive(true);
|
||||
}
|
||||
private void CloseFxRoot()
|
||||
{
|
||||
fxRoot.SetActive(false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4bc7657f0045dba4e9a1090f041a1730
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
64
Assets/Scripts/EventGatherCore/EventGatherCoreTriggerView.cs
Normal file
64
Assets/Scripts/EventGatherCore/EventGatherCoreTriggerView.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using asap.core;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class EventGatherCoreTriggerView : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Button btn;
|
||||
[SerializeField] private Animation ani;
|
||||
private IEventAggregator _eventAggregator;
|
||||
private int _idx;
|
||||
private float _showDuration;
|
||||
private readonly string AnimationShow = "football_show";
|
||||
|
||||
private void Start()
|
||||
{
|
||||
btn.onClick.AddListener(OnClick);
|
||||
}
|
||||
|
||||
public void Init(int index, bool isUsed, float showDuration, IEventAggregator eventAggregator)
|
||||
{
|
||||
// Debug.Log($"[EventGatherCore] Init: {isUsed}]", this);
|
||||
Set(isUsed);
|
||||
_eventAggregator = eventAggregator;
|
||||
_idx = index;
|
||||
_showDuration = showDuration;
|
||||
}
|
||||
|
||||
public void Set(bool isUsed)
|
||||
{
|
||||
if (!isUsed && !gameObject.activeSelf)
|
||||
{
|
||||
ani.Play(AnimationShow);
|
||||
}
|
||||
gameObject.SetActive(!isUsed);
|
||||
}
|
||||
|
||||
private async void OnClick()
|
||||
{
|
||||
try
|
||||
{
|
||||
var res = EventGatherCoreSystem.Draw(_idx, out int rewardIdx, out int rewardId);
|
||||
_eventAggregator.Publish(
|
||||
new EventGatherCoreTriggerTaken()
|
||||
{
|
||||
Succeeded = res,
|
||||
RewardIdx = rewardIdx,
|
||||
Position = btn.transform.position,
|
||||
RewardId = rewardId,
|
||||
});
|
||||
// Debug.Log($"[EventGatherCore] Trigger Click: {_showDuration}", this);
|
||||
if (!res)
|
||||
{
|
||||
return;
|
||||
}
|
||||
await System.Threading.Tasks.Task.Delay(TimeSpan.FromSeconds(_showDuration));
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.Log($"[EventGatherCore] Trigger Click Error:{e.Message}\n{e.StackTrace}", this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e0855a364f515f74c8e849b4d98b89fe
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user