342 lines
13 KiB
C#
342 lines
13 KiB
C#
using asap.core;
|
|
using cfg;
|
|
using System.Linq;
|
|
using System.Collections.Generic;
|
|
using GameCore;
|
|
using UnityEngine;
|
|
namespace Assets.Scripts.UI.SocialRush
|
|
{
|
|
public class TableContext : IHasFishRaidAndBombTipView
|
|
{
|
|
private int _eventId, _redirectId;
|
|
private Tables _tables;
|
|
private EventRush _tbEventRush;
|
|
private TbEventRushTask _tbEventRushTask;
|
|
public int EventId => _eventId;
|
|
|
|
public TableContext() { }
|
|
|
|
public TableContext(int eventId)
|
|
{
|
|
_eventId = eventId;
|
|
_tables = GContext.container.Resolve<Tables>();
|
|
_redirectId = _tables.TbFishingEvent[eventId].RedirectID;
|
|
_tbEventRush = _tables.TbEventRush[_redirectId];
|
|
_tbEventRushTask = _tables.TbEventRushTask;
|
|
}
|
|
|
|
public static TableContext CreateTest(int eventId)
|
|
{
|
|
var res = new TableContext();
|
|
res._eventId = eventId;
|
|
res._redirectId = 110101;
|
|
res._tables = GContext.container.Resolve<Tables>();
|
|
res._tbEventRushTask = res._tables.TbEventRushTask;
|
|
res._tbEventRush = res._tables.TbEventRush[res._redirectId];
|
|
return res;
|
|
}
|
|
|
|
public int GetFishRaidProgress()
|
|
{
|
|
return _tbEventRush.RushParam[0];
|
|
}
|
|
|
|
public int GetBombProgress()
|
|
{
|
|
return _tbEventRush.RushParam[1];
|
|
}
|
|
|
|
public int[] GetTicketRewardArray()
|
|
{
|
|
return _tbEventRush.RushParam.ToArray();
|
|
}
|
|
|
|
public int GetProgressItemId()
|
|
{
|
|
return _tbEventRush.RushItem;
|
|
}
|
|
|
|
public List<int> GetTaskIdList()
|
|
{
|
|
return _tbEventRush.TaskList;
|
|
}
|
|
|
|
public List<EventRushTask> GetTaskList()
|
|
{
|
|
return _tbEventRush.TaskList.Select(t => _tbEventRushTask[t]).ToList();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get current active task info from progress. Will return null if all task are completed.
|
|
/// </summary>
|
|
/// <param name="progress">The progress.</param>
|
|
/// <returns>Current active task that waits to be finished. Null if all tasks are completed.</returns>
|
|
public (int idx, EventRushTask rushTask) GetTaskFromProgress(int progress)
|
|
{
|
|
var taskList = _tbEventRush.TaskList.Select(t => _tbEventRushTask[t]).ToList();
|
|
var tmpProgress = progress;
|
|
int idx = 0;
|
|
while (tmpProgress > 0 && idx < taskList.Count && tmpProgress >= taskList[idx].TaskParam)
|
|
{
|
|
tmpProgress -= taskList[idx].TaskParam;
|
|
idx++;
|
|
}
|
|
return idx >= taskList.Count ? (-1, null) : (idx, taskList[idx]);
|
|
}
|
|
|
|
public EventRushTask GetTaskFromId(int taskId)
|
|
{
|
|
return _tbEventRushTask[taskId];
|
|
}
|
|
|
|
public bool IsActive()
|
|
{
|
|
(var startTime, var endTime) = FtUtils.GetEventTimeLimit(_eventId);
|
|
var now = ZZTimeHelper.UtcNow();
|
|
return startTime <= now && now <= endTime;
|
|
}
|
|
|
|
public List<string> GetAddressableUrls()
|
|
{
|
|
var res = new List<string>
|
|
{
|
|
_tbEventRush.RushIcon,
|
|
_tbEventRush.RushPrefab
|
|
};
|
|
return res;
|
|
}
|
|
|
|
public SocialRushEntranceData GetEntranceData()
|
|
{
|
|
var data = new SocialRushEntranceData();
|
|
data.IconUrl = _tbEventRush.RushIcon;
|
|
(var startTime, var endTime) = FtUtils.GetEventTimeLimit(EventId);
|
|
data.TimerData = new TimerContext
|
|
{
|
|
StartTime = startTime,
|
|
ExpiryTime = endTime
|
|
};
|
|
return data;
|
|
}
|
|
|
|
public (float percentage, string textProgress) GetProgressInfo(int progress)
|
|
{
|
|
var taskList = _tbEventRush.TaskList.Select(t => _tbEventRushTask[t]).ToList();
|
|
var tmpProgress = progress;
|
|
int idx = 0;
|
|
string textProgress;
|
|
float percentage;
|
|
while (tmpProgress > 0 && idx < taskList.Count && tmpProgress >= taskList[idx].TaskParam)
|
|
{
|
|
tmpProgress -= taskList[idx].TaskParam;
|
|
idx++;
|
|
}
|
|
if (idx >= taskList.Count)
|
|
{
|
|
textProgress = LocalizationMgr.GetText("UI_FishingRodPanel_18");
|
|
percentage = 1.0f;
|
|
return (percentage, textProgress);
|
|
}
|
|
if (tmpProgress < 0)
|
|
tmpProgress = 0;
|
|
textProgress = $"{tmpProgress}/{taskList[idx].TaskParam}";
|
|
percentage = (float)tmpProgress / taskList[idx].TaskParam;
|
|
return (percentage, textProgress);
|
|
}
|
|
|
|
public SocialRushTaskViewData GetTaskViewData(int progress, float inflationRate)
|
|
{
|
|
var taskList = GetTaskList();
|
|
var tmpProgress = progress;
|
|
int idx = 0;
|
|
string textProgress;
|
|
float percentage;
|
|
ItemData rewardItem;
|
|
ITimerContext timerData;
|
|
try
|
|
{
|
|
timerData = new TimerContext
|
|
{
|
|
StartTime = FtUtils.GetEventTimeLimit(EventId).startTime,
|
|
ExpiryTime = FtUtils.GetEventTimeLimit(EventId).endTime
|
|
};
|
|
}
|
|
catch (System.Exception e)
|
|
{
|
|
Debug.LogException(e);
|
|
timerData = new TimerContext
|
|
{
|
|
StartTime = ZZTimeHelper.UtcNow(),
|
|
ExpiryTime = ZZTimeHelper.UtcNow().AddDays(1),
|
|
};
|
|
}
|
|
while (tmpProgress > 0 && idx < taskList.Count && tmpProgress >= taskList[idx].TaskParam)
|
|
{
|
|
tmpProgress -= taskList[idx].TaskParam;
|
|
idx++;
|
|
}
|
|
|
|
if (idx >= taskList.Count)
|
|
{
|
|
textProgress = LocalizationMgr.GetText("UI_FishingRodPanel_18");
|
|
percentage = 1.0f;
|
|
idx = taskList.Count - 1;
|
|
rewardItem = GContext.container.Resolve<PlayerItemData>()
|
|
.GetItemDataByDropIdLureInflation(inflationRate, taskList[idx].DropId)[0];
|
|
return new SocialRushTaskViewData
|
|
{
|
|
ProgressText = textProgress,
|
|
Percentage = percentage,
|
|
Item = rewardItem,
|
|
TimerData = timerData,
|
|
CurrentProgressWithinStage = taskList[idx].TaskParam
|
|
};
|
|
}
|
|
|
|
if (tmpProgress < 0)
|
|
tmpProgress = 0;
|
|
|
|
textProgress = $"{tmpProgress}/{taskList[idx].TaskParam}";
|
|
percentage = (float)tmpProgress / taskList[idx].TaskParam;
|
|
rewardItem = GContext.container.Resolve<PlayerItemData>()
|
|
.GetItemDataByDropIdLureInflation(inflationRate, taskList[idx].DropId)[0];
|
|
return new SocialRushTaskViewData
|
|
{
|
|
ProgressText = textProgress,
|
|
Percentage = percentage,
|
|
Item = rewardItem,
|
|
TimerData = timerData,
|
|
CurrentProgressWithinStage = tmpProgress
|
|
};
|
|
}
|
|
|
|
public (List<SocialRushRewardItemViewData> dataList, SocialRushRewardItemViewData finalData) GetRewardViewData(int progress, float inflationRate)
|
|
{
|
|
var playerItemData = GContext.container.Resolve<PlayerItemData>();
|
|
var dataList = new List<SocialRushRewardItemViewData>();
|
|
var taskList = GetTaskList();
|
|
|
|
var finalData = new SocialRushRewardItemViewData
|
|
{
|
|
Type = SocialRushRewardItemViewType.Final,
|
|
IsDone = false,
|
|
Reward = playerItemData.GetItemDataByDropIdLureInflation(inflationRate, taskList[^1].DropId)[0],
|
|
};
|
|
|
|
(var idx, _) = GetTaskFromProgress(progress);
|
|
|
|
if (idx == -1)
|
|
return (dataList, finalData);
|
|
|
|
for (int i = idx; i < taskList.Count && i < idx + 6; i++)
|
|
{
|
|
dataList.Add(new SocialRushRewardItemViewData
|
|
{
|
|
Type = (i - idx) % 2 == 0 ? SocialRushRewardItemViewType.LeftSide : SocialRushRewardItemViewType.RightSide,
|
|
IsDone = false,
|
|
Reward = playerItemData.GetItemDataByDropIdLureInflation(inflationRate, taskList[i].DropId)[0],
|
|
});
|
|
}
|
|
if (dataList.Count > 0)
|
|
dataList[^1].Type = SocialRushRewardItemViewType.Final;
|
|
return (dataList, finalData);
|
|
}
|
|
|
|
public SocialRushGrantRewardProcessData GetGrantRewardProcessData(int progressDisplay, int progressActual, in int rewardSlotCount, in float inflationRate)
|
|
{
|
|
var playerItemData = GContext.container.Resolve<PlayerItemData>();
|
|
var res = new SocialRushGrantRewardProcessData();
|
|
var taskList = GetTaskList();
|
|
(var idxStart, var taskStart) = GetTaskFromProgress(progressDisplay);
|
|
(var idxEnd, var taskEnd) = GetTaskFromProgress(progressActual);
|
|
if (idxStart == -1)
|
|
idxStart = taskList.Count - 1;
|
|
if (idxEnd == -1)
|
|
idxEnd = taskList.Count - 1;
|
|
var roadMapIdxEnd = idxStart;
|
|
while (roadMapIdxEnd <= idxEnd)
|
|
{
|
|
roadMapIdxEnd += rewardSlotCount;
|
|
}
|
|
roadMapIdxEnd = Mathf.Min(roadMapIdxEnd, taskList.Count);
|
|
|
|
res.RoadMapRewardList = new List<ItemData>();
|
|
var idx = idxStart;
|
|
while (idx < roadMapIdxEnd && idx < taskList.Count)
|
|
{
|
|
var item = playerItemData.GetItemDataByDropIdAndTypeLureInflation(inflationRate, taskList[idx].DropId)[0];
|
|
res.RoadMapRewardList.Add(item);
|
|
idx++;
|
|
}
|
|
|
|
res.TaskRewardList = new List<ItemData>();
|
|
res.EndProgressList = new List<int>();
|
|
idx = idxStart;
|
|
while (idx <= idxEnd)
|
|
{
|
|
res.EndProgressList.Add(taskList[idx].TaskParam);
|
|
res.TaskRewardList.Add(playerItemData.GetItemDataByDropIdAndTypeLureInflation(inflationRate, taskList[idx].DropId)[0]);
|
|
idx++;
|
|
}
|
|
|
|
res.RewardsToGive = GetScopedRewards(progressDisplay, progressActual, inflationRate);
|
|
|
|
res.LastPartialProgress = progressActual;
|
|
idx = 0;
|
|
while (idx < taskList.Count - 1 && res.LastPartialProgress >= taskList[idx].TaskParam)
|
|
{
|
|
res.LastPartialProgress -= taskList[idx].TaskParam;
|
|
idx++;
|
|
}
|
|
res.LastPartialProgress = Mathf.Min(res.LastPartialProgress, taskList[^1].TaskParam);
|
|
|
|
return res;
|
|
}
|
|
|
|
public bool HasUnclaimedReward(int progressDisplay, int progressActual, out int displayTaskIdx, out int actualTaskIdx)
|
|
{
|
|
EventRushTask taskDisplay, taskActual;
|
|
(displayTaskIdx, taskDisplay) = GetTaskFromProgress(progressDisplay);
|
|
(actualTaskIdx, taskActual) = GetTaskFromProgress(progressActual);
|
|
if (taskDisplay == null)
|
|
return false;
|
|
if (taskActual == null)
|
|
return true;
|
|
return displayTaskIdx < actualTaskIdx;
|
|
}
|
|
|
|
public List<ItemData> GetScopedRewards(int progressDisplay, int progressActual, float inflationRate)
|
|
{
|
|
var taskIdList = GetTaskIdList();
|
|
var taskList = GetTaskList();
|
|
var dropIdList = new List<int>();
|
|
if (progressDisplay >= progressActual)
|
|
return new List<ItemData>();
|
|
var displayTaskIdx = GetTaskFromProgress(progressDisplay).idx;
|
|
if (displayTaskIdx == -1)
|
|
{
|
|
Debug.LogError("[SocialRush]DisplayTaskId is -1, meaning that all rewards are taken, which is impossible in this stage.");
|
|
return new List<ItemData>();
|
|
}
|
|
var actualTaskIdx = GetTaskFromProgress(progressActual).idx;
|
|
|
|
if (actualTaskIdx == -1)
|
|
actualTaskIdx = taskIdList.Count - 1;
|
|
if (progressActual >= taskList.Sum(x => x.TaskParam))
|
|
actualTaskIdx++;
|
|
|
|
for (int i = displayTaskIdx; i < actualTaskIdx; i++)
|
|
{
|
|
var taskId = taskIdList[i];
|
|
var task = GetTaskFromId(taskId);
|
|
dropIdList.Add(task.DropId);
|
|
}
|
|
var res = GContext.container.Resolve<PlayerItemData>().GetItemDataListFromListOfSingleDropId(dropIdList);
|
|
GContext.container.Resolve<PlayerItemData>().LureInflation(res, inflationRate);
|
|
return res;
|
|
}
|
|
|
|
}
|
|
}
|
|
|