备份CatanBuilding瘦身独立工程
This commit is contained in:
286
Assets/Scripts/EventStrikeLucky/EventLuckMagicTableContext.cs
Normal file
286
Assets/Scripts/EventStrikeLucky/EventLuckMagicTableContext.cs
Normal file
@@ -0,0 +1,286 @@
|
||||
using cfg;
|
||||
using asap.core;
|
||||
using System.Linq;
|
||||
using GameCore;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
|
||||
/// <summary>
|
||||
/// Utility to get table data. Can only be used when event is active.
|
||||
/// </summary>
|
||||
public class EventLuckMagicTableContext
|
||||
{
|
||||
private FishingEvent _tableEvent;
|
||||
private EventLuckMagic _tableMain;
|
||||
private EventLuckMagicDrop[] _tableBlockDrops;
|
||||
private TbEventLuckMagicLevel _tableRings;
|
||||
private HashSet<int> _roadSignIds;
|
||||
private PlayerItemData _playerItemData;
|
||||
private FishingEventCycleItem3 _tableCycle;
|
||||
private EventPackManager _packData;
|
||||
private Tables _tables;
|
||||
|
||||
private EventLuckMagicTableContext() { }
|
||||
|
||||
public static EventLuckMagicTableContext ReadTables(int eventId)
|
||||
{
|
||||
var ctx = new EventLuckMagicTableContext();
|
||||
ctx._tables = GContext.container.Resolve<Tables>();
|
||||
var tables = ctx._tables;
|
||||
var redirectId = tables.TbFishingEvent[eventId].RedirectID;
|
||||
var cycleId = tables.TbFishingEventCycleItem3[redirectId].RedirectID;
|
||||
ctx._tableEvent = tables.TbFishingEvent[eventId];
|
||||
ctx._tableMain = tables.TbEventLuckMagic[cycleId];
|
||||
ctx._tableCycle = tables.TbFishingEventCycleItem3[cycleId];
|
||||
ctx._tableRings = tables.TbEventLuckMagicLevel;
|
||||
ctx._roadSignIds = ctx._tableRings.DataList.Select(x => x.TurnItem).ToHashSet();
|
||||
ctx._tableBlockDrops = tables.TbEventLuckMagicDrop.DataList.OrderBy(x => x.ID).ToArray();
|
||||
ctx._playerItemData = GContext.container.Resolve<PlayerItemData>();
|
||||
ctx._packData = tables.TbEventPackManager[ctx._tableMain.PackId];
|
||||
return ctx;
|
||||
}
|
||||
|
||||
public void GetBlocksInfo(out List<EventLuckMagicBlockInfo> infos)
|
||||
{
|
||||
infos = new List<EventLuckMagicBlockInfo>();
|
||||
foreach (var bd in _tableBlockDrops)
|
||||
{
|
||||
var info = new EventLuckMagicBlockInfo();
|
||||
info.RingType = (EEventLuckMagicRingType)(bd.ID / 100 % 10 /* - 1 */);
|
||||
info.Reward = new ItemData(bd.Item, bd.Count);
|
||||
_playerItemData.ItemTransition(info.Reward);
|
||||
info.Weight = bd.Weight;
|
||||
info.TableId = bd.ID;
|
||||
infos.Add(info);
|
||||
}
|
||||
}
|
||||
|
||||
public void GetRingsInfo(out int[] costs, out int[] roadSignIds)
|
||||
{
|
||||
costs = _tableRings.DataList.Select(x => x.CostNumber).ToArray();
|
||||
roadSignIds = _tableRings.DataList.Select(x => x.TurnItem).ToArray();
|
||||
}
|
||||
|
||||
public bool IsRewardRoadSign(EEventLuckMagicRingType ringType, int rewardId)
|
||||
{
|
||||
if (!_tableRings.DataMap.TryGetValue((int)ringType, out var ring))
|
||||
{
|
||||
Debug.Log($"[EventLuckMagic] No table data found for ring type {ringType}");
|
||||
return false;
|
||||
}
|
||||
return ring.TurnItem == rewardId;
|
||||
}
|
||||
|
||||
public bool IsRewardRoadSign(int rewardId, out int expireDuration, out int drop, out int[] weightConfig)
|
||||
{
|
||||
var res = _roadSignIds.Contains(rewardId);
|
||||
// Debug.Log($"[EventLuckMagic] {res}: {rewardId} is road sign?");
|
||||
if (res)
|
||||
{
|
||||
var line = _tableRings.DataList.Where(x => x.TurnItem == rewardId).First();
|
||||
expireDuration = line.TurnTime;
|
||||
drop = line.TurnDrop;
|
||||
weightConfig = line.TurnConfig.ToArray();
|
||||
}
|
||||
else
|
||||
{
|
||||
expireDuration = 0;
|
||||
drop = 0;
|
||||
weightConfig = null;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public bool IsRewardProgressItem(int rewardId, int roundCount, out int drop)
|
||||
{
|
||||
var idSeven = _tableMain.TargetRewardItem1;
|
||||
var idHeart = _tableMain.TargetRewardItem2;
|
||||
if (rewardId == idSeven)
|
||||
{
|
||||
drop = GetTaskRewardDropId(roundCount, true);
|
||||
return true;
|
||||
}
|
||||
else if (rewardId == idHeart)
|
||||
{
|
||||
drop = GetTaskRewardDropId(roundCount, false);
|
||||
return true;
|
||||
}
|
||||
drop = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
public EEventLuckMagicItemType JudgeItemId(int rewardId)
|
||||
{
|
||||
if (rewardId == _tableMain.TargetRewardItem1)
|
||||
{
|
||||
return EEventLuckMagicItemType.UpperTaskItem;
|
||||
}
|
||||
else if (rewardId == _tableMain.TargetRewardItem2)
|
||||
{
|
||||
return EEventLuckMagicItemType.LowerTaskItem;
|
||||
}
|
||||
return EEventLuckMagicItemType.None;
|
||||
}
|
||||
|
||||
public bool IsRewardSpecial(int rewardId)
|
||||
{
|
||||
return IsRewardRoadSign(rewardId, out _, out _, out _) || IsRewardProgressItem(rewardId, 0, out _);
|
||||
}
|
||||
|
||||
public Dictionary<int, ItemData> GetTaskInfo(int roundCount)
|
||||
{
|
||||
return new Dictionary<int, ItemData>()
|
||||
{
|
||||
{
|
||||
_tableMain.TargetRewardItem1,
|
||||
_playerItemData.GetItemDataByDropId(_tableMain.TargetRewardDrop1[roundCount < _tableMain.TargetRewardDrop1.Count ? roundCount : _tableMain.TargetRewardDrop1.Count - 1])[0]
|
||||
},
|
||||
{
|
||||
_tableMain.TargetRewardItem2,
|
||||
_playerItemData.GetItemDataByDropId(_tableMain.TargetRewardDrop2[roundCount < _tableMain.TargetRewardDrop2.Count ? roundCount : _tableMain.TargetRewardDrop2.Count - 1])[0]
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
public int GetTicketRedPointThreshold()
|
||||
{
|
||||
return _tableCycle.RedDot;
|
||||
}
|
||||
|
||||
public Tuple<DateTime, DateTime> GetEventStartTimeAndEndTime()
|
||||
{
|
||||
try
|
||||
{
|
||||
var et = System.DateTime.Parse((_tableEvent.TimeDefinition as LimitedTime).EndTime);
|
||||
var st = System.DateTime.Parse((_tableEvent.TimeDefinition as LimitedTime).StartTime);
|
||||
return new Tuple<DateTime, DateTime>(st, et);
|
||||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
Debug.LogError(e);
|
||||
return new Tuple<DateTime, DateTime>(System.DateTime.MinValue, System.DateTime.MinValue);
|
||||
}
|
||||
}
|
||||
|
||||
public EventChainPackInfo GetChainPackInfo()
|
||||
{
|
||||
var chianList = GContext.container.Resolve<Tables>().TbEventPackManager[_tableMain.PackId].VIPPackList[0];
|
||||
var expireTime = new System.DateTime();
|
||||
try
|
||||
{
|
||||
expireTime = System.DateTime.Parse((_tableEvent.TimeDefinition as LimitedTime).EndTime);
|
||||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
Debug.Log($"[EventLuckMagic] {e.Message}\n{e.StackTrace}");
|
||||
return null;
|
||||
}
|
||||
var chainListIdSet = chianList.ToHashSet();
|
||||
var packs = GContext.container.Resolve<Tables>().TbPack.DataList.Where(p => chainListIdSet.Contains(p.ID)).ToArray();//?
|
||||
return new EventChainPackInfo()
|
||||
{
|
||||
ChainList = chianList,
|
||||
ExpireTime = expireTime,
|
||||
Packs = packs,
|
||||
RedPointKey = "eventluckmagic.pack"
|
||||
};
|
||||
}
|
||||
|
||||
public int GetWelcomeGift()
|
||||
{
|
||||
return _tableCycle.WelcomeGift;
|
||||
}
|
||||
|
||||
public LackOfCommonItemPopupPanelInfo GetLackOfTicketPanelInfo()
|
||||
{
|
||||
var res = new LackOfCommonItemPopupPanelInfo();
|
||||
res.reward = new ItemData(_tableMain.Item, _tableMain.BuyCount);
|
||||
res.Cost = _tableMain.Price;
|
||||
res.CurrencyId = 1005;
|
||||
return res;
|
||||
}
|
||||
|
||||
public EventLuckMagicInfo GetInfoPanelInfo()
|
||||
{
|
||||
var res = new EventLuckMagicInfo();
|
||||
GetBlocksInfo(out var list);
|
||||
res.Blocks = list
|
||||
.Where(b => b.RingType == EEventLuckMagicRingType.InnerRing)
|
||||
.Select(b => b.Reward)
|
||||
.ToArray();
|
||||
res.TaskRewardUpper = _playerItemData.GetItemDataByDropId(GetTaskRewardDropId(0, true))[0];
|
||||
res.TaskRewardLower = _playerItemData.GetItemDataByDropId(GetTaskRewardDropId(0, false))[0];
|
||||
res.TicketNameKey = GContext.container.Resolve<Tables>().TbItem[_tableMain.Item].Name_l10n_key;
|
||||
return res;
|
||||
}
|
||||
|
||||
public string GetIcon()
|
||||
{
|
||||
return _tableMain.Icon;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the right reward drop Id for the right task in the right round
|
||||
/// </summary>
|
||||
/// <param name="roundCount">Starts at 0</param>
|
||||
/// <param name="isUpperTask">Upper or Lower task</param>
|
||||
/// <returns> the drop id</returns>
|
||||
public int GetTaskRewardDropId(int roundCount, bool isUpperTask)
|
||||
{
|
||||
List<int> rewardDropIdList;
|
||||
rewardDropIdList = isUpperTask ? _tableMain.TargetRewardDrop1 : _tableMain.TargetRewardDrop2;
|
||||
return rewardDropIdList[roundCount < rewardDropIdList.Count ? roundCount : rewardDropIdList.Count - 1];
|
||||
}
|
||||
|
||||
public ItemData GetTaskReward(int roundCount, bool isUpperTask)
|
||||
{
|
||||
return _playerItemData.GetItemDataByDropId(GetTaskRewardDropId(roundCount, isUpperTask))[0];
|
||||
}
|
||||
|
||||
public List<int> GetFirstLuckyTaskIdList()
|
||||
{
|
||||
return _tableMain.TaskRound1;
|
||||
}
|
||||
|
||||
public List<int> GetLastLuckyTaskIdList()
|
||||
{
|
||||
return _tableMain.TaskRound2;
|
||||
}
|
||||
|
||||
public int GetPackId()
|
||||
{
|
||||
return _tableMain.PackId;
|
||||
}
|
||||
|
||||
public int EventId => _tableEvent.ID;
|
||||
public int PackId => _tableMain.PackId;
|
||||
|
||||
public EventLuckMagicPanelUrlData GetUiPanelUrls()
|
||||
{
|
||||
var res = new EventLuckMagicPanelUrlData();
|
||||
res.TriplePackPanelUrl = _packData.Panel;
|
||||
return res;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class EventLuckMagicBlockInfo
|
||||
{
|
||||
public EEventLuckMagicRingType RingType { get; set; }
|
||||
public ItemData Reward { get; set; }
|
||||
public int Weight { get; set; }
|
||||
public int TableId { get; set; }
|
||||
}
|
||||
|
||||
public enum EEventLuckMagicItemType
|
||||
{
|
||||
UpperTaskItem,
|
||||
LowerTaskItem,
|
||||
None
|
||||
}
|
||||
|
||||
public class EventLuckMagicPanelUrlData
|
||||
{
|
||||
public string TriplePackPanelUrl{ get; set; }
|
||||
}
|
||||
Reference in New Issue
Block a user