备份CatanBuilding瘦身独立工程
This commit is contained in:
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user